aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLarry Finger <Larry.Finger@lwfinger.net>2011-04-08 21:33:25 -0400
committerLarry Finger <Larry.Finger@lwfinger.net>2011-04-08 21:33:25 -0400
commitfefecc6989b4b24276797270c0e229c07be02ad3 (patch)
tree7c03f0f798ab84e5cf0c14a6648c991efd37c160
parent0c3efe54d0165cecf0698b468e253577b555dde6 (diff)
staging: rt2860sta and rt2870sta: Remove drivers replaced in net/wireless
The staging driver rt2860sta is replaced by mainline driver rt2800pci, and rt2870sta is replaced by rt2800usb. As a result, the staging drivers are deleted. Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net> ---
-rw-r--r--drivers/staging/Kconfig4
-rw-r--r--drivers/staging/Makefile2
-rw-r--r--drivers/staging/rt2860/Kconfig10
-rw-r--r--drivers/staging/rt2860/Makefile52
-rw-r--r--drivers/staging/rt2860/TODO16
-rw-r--r--drivers/staging/rt2860/ap.h68
-rw-r--r--drivers/staging/rt2860/chip/mac_pci.h355
-rw-r--r--drivers/staging/rt2860/chip/mac_usb.h345
-rw-r--r--drivers/staging/rt2860/chip/rt2860.h54
-rw-r--r--drivers/staging/rt2860/chip/rt2870.h46
-rw-r--r--drivers/staging/rt2860/chip/rt3070.h67
-rw-r--r--drivers/staging/rt2860/chip/rt3090.h72
-rw-r--r--drivers/staging/rt2860/chip/rt30xx.h47
-rw-r--r--drivers/staging/rt2860/chip/rtmp_mac.h1308
-rw-r--r--drivers/staging/rt2860/chip/rtmp_phy.h516
-rw-r--r--drivers/staging/rt2860/chips/rt3070.c169
-rw-r--r--drivers/staging/rt2860/chips/rt3090.c121
-rw-r--r--drivers/staging/rt2860/chips/rt30xx.c516
-rw-r--r--drivers/staging/rt2860/chlist.h113
-rw-r--r--drivers/staging/rt2860/common/action.c606
-rw-r--r--drivers/staging/rt2860/common/action.h56
-rw-r--r--drivers/staging/rt2860/common/ba_action.c1650
-rw-r--r--drivers/staging/rt2860/common/cmm_aes.c1311
-rw-r--r--drivers/staging/rt2860/common/cmm_asic.c2565
-rw-r--r--drivers/staging/rt2860/common/cmm_cfg.c258
-rw-r--r--drivers/staging/rt2860/common/cmm_data.c2361
-rw-r--r--drivers/staging/rt2860/common/cmm_data_pci.c1096
-rw-r--r--drivers/staging/rt2860/common/cmm_data_usb.c951
-rw-r--r--drivers/staging/rt2860/common/cmm_info.c955
-rw-r--r--drivers/staging/rt2860/common/cmm_mac_pci.c1661
-rw-r--r--drivers/staging/rt2860/common/cmm_mac_usb.c1162
-rw-r--r--drivers/staging/rt2860/common/cmm_sanity.c1205
-rw-r--r--drivers/staging/rt2860/common/cmm_sync.c718
-rw-r--r--drivers/staging/rt2860/common/cmm_tkip.c833
-rw-r--r--drivers/staging/rt2860/common/cmm_wep.c473
-rw-r--r--drivers/staging/rt2860/common/cmm_wpa.c3010
-rw-r--r--drivers/staging/rt2860/common/crypt_hmac.c187
-rw-r--r--drivers/staging/rt2860/common/crypt_md5.c339
-rw-r--r--drivers/staging/rt2860/common/crypt_sha2.c269
-rw-r--r--drivers/staging/rt2860/common/dfs.c68
-rw-r--r--drivers/staging/rt2860/common/ee_efuse.c351
-rw-r--r--drivers/staging/rt2860/common/ee_prom.c197
-rw-r--r--drivers/staging/rt2860/common/eeprom.c91
-rw-r--r--drivers/staging/rt2860/common/mlme.c6068
-rw-r--r--drivers/staging/rt2860/common/rt_channel.c1705
-rw-r--r--drivers/staging/rt2860/common/rt_rf.c187
-rw-r--r--drivers/staging/rt2860/common/rtmp_init.c3536
-rw-r--r--drivers/staging/rt2860/common/rtmp_mcu.c336
-rw-r--r--drivers/staging/rt2860/common/rtmp_timer.c302
-rw-r--r--drivers/staging/rt2860/common/spectrum.c2205
-rw-r--r--drivers/staging/rt2860/crypt_hmac.h65
-rw-r--r--drivers/staging/rt2860/crypt_md5.h73
-rw-r--r--drivers/staging/rt2860/crypt_sha2.h73
-rw-r--r--drivers/staging/rt2860/dfs.h39
-rw-r--r--drivers/staging/rt2860/eeprom.h67
-rw-r--r--drivers/staging/rt2860/iface/rtmp_pci.h80
-rw-r--r--drivers/staging/rt2860/iface/rtmp_usb.h196
-rw-r--r--drivers/staging/rt2860/mlme.h1050
-rw-r--r--drivers/staging/rt2860/oid.h779
-rw-r--r--drivers/staging/rt2860/pci_main_dev.c1192
-rw-r--r--drivers/staging/rt2860/rt_config.h71
-rw-r--r--drivers/staging/rt2860/rt_linux.c1367
-rw-r--r--drivers/staging/rt2860/rt_linux.h835
-rw-r--r--drivers/staging/rt2860/rt_main_dev.c736
-rw-r--r--drivers/staging/rt2860/rt_pci_rbus.c837
-rw-r--r--drivers/staging/rt2860/rt_usb.c794
-rw-r--r--drivers/staging/rt2860/rtmp.h4332
-rw-r--r--drivers/staging/rt2860/rtmp_chip.h258
-rw-r--r--drivers/staging/rt2860/rtmp_ckipmic.h63
-rw-r--r--drivers/staging/rt2860/rtmp_def.h1427
-rw-r--r--drivers/staging/rt2860/rtmp_dot11.h100
-rw-r--r--drivers/staging/rt2860/rtmp_iface.h75
-rw-r--r--drivers/staging/rt2860/rtmp_mcu.h49
-rw-r--r--drivers/staging/rt2860/rtmp_os.h90
-rw-r--r--drivers/staging/rt2860/rtmp_timer.h148
-rw-r--r--drivers/staging/rt2860/rtmp_type.h89
-rw-r--r--drivers/staging/rt2860/rtusb_io.h185
-rw-r--r--drivers/staging/rt2860/spectrum.h189
-rw-r--r--drivers/staging/rt2860/spectrum_def.h202
-rw-r--r--drivers/staging/rt2860/sta/assoc.c1602
-rw-r--r--drivers/staging/rt2860/sta/auth.c517
-rw-r--r--drivers/staging/rt2860/sta/auth_rsp.c142
-rw-r--r--drivers/staging/rt2860/sta/connect.c2613
-rw-r--r--drivers/staging/rt2860/sta/rtmp_data.c2552
-rw-r--r--drivers/staging/rt2860/sta/sanity.c362
-rw-r--r--drivers/staging/rt2860/sta/sync.c1968
-rw-r--r--drivers/staging/rt2860/sta/wpa.c374
-rw-r--r--drivers/staging/rt2860/sta_ioctl.c2912
-rw-r--r--drivers/staging/rt2860/usb_main_dev.c927
-rw-r--r--drivers/staging/rt2860/wpa.h390
-rw-r--r--drivers/staging/rt2870/Kconfig9
-rw-r--r--drivers/staging/rt2870/Makefile55
-rw-r--r--drivers/staging/rt2870/TODO17
-rw-r--r--drivers/staging/rt2870/aironet.h1
-rw-r--r--drivers/staging/rt2870/ap.h1
-rw-r--r--drivers/staging/rt2870/chips/rt3070.c1
-rw-r--r--drivers/staging/rt2870/chips/rt30xx.c1
-rw-r--r--drivers/staging/rt2870/chlist.h1
-rw-r--r--drivers/staging/rt2870/common/acction.c1
-rw-r--r--drivers/staging/rt2870/common/action.c1
-rw-r--r--drivers/staging/rt2870/common/action.h1
-rw-r--r--drivers/staging/rt2870/common/ba_action.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_aes.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_asic.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_cfg.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_data.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_data_usb.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_info.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_mac_usb.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_profile.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_sanity.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_sync.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_tkip.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_wep.c1
-rw-r--r--drivers/staging/rt2870/common/cmm_wpa.c1
-rw-r--r--drivers/staging/rt2870/common/crypt_hmac.c1
-rw-r--r--drivers/staging/rt2870/common/crypt_md5.c1
-rw-r--r--drivers/staging/rt2870/common/crypt_sha2.c1
-rw-r--r--drivers/staging/rt2870/common/dfs.c1
-rw-r--r--drivers/staging/rt2870/common/ee_efuse.c1
-rw-r--r--drivers/staging/rt2870/common/eeprom.c1
-rw-r--r--drivers/staging/rt2870/common/md5.c1
-rw-r--r--drivers/staging/rt2870/common/mlme.c1
-rw-r--r--drivers/staging/rt2870/common/rt_channel.c1
-rw-r--r--drivers/staging/rt2870/common/rt_rf.c1
-rw-r--r--drivers/staging/rt2870/common/rtmp_init.c1
-rw-r--r--drivers/staging/rt2870/common/rtmp_mcu.c1
-rw-r--r--drivers/staging/rt2870/common/rtmp_timer.c1
-rw-r--r--drivers/staging/rt2870/common/rtmp_tkip.c1
-rw-r--r--drivers/staging/rt2870/common/rtmp_wep.c1
-rw-r--r--drivers/staging/rt2870/common/rtusb_bulk.c1232
-rw-r--r--drivers/staging/rt2870/common/rtusb_data.c262
-rw-r--r--drivers/staging/rt2870/common/rtusb_io.c2104
-rw-r--r--drivers/staging/rt2870/common/spectrum.c1
-rw-r--r--drivers/staging/rt2870/dfs.h1
-rw-r--r--drivers/staging/rt2870/md5.h1
-rw-r--r--drivers/staging/rt2870/mlme.h1
-rw-r--r--drivers/staging/rt2870/oid.h1
-rw-r--r--drivers/staging/rt2870/rt28xx.h1
-rw-r--r--drivers/staging/rt2870/rt_config.h1
-rw-r--r--drivers/staging/rt2870/rt_linux.c1
-rw-r--r--drivers/staging/rt2870/rt_linux.h1
-rw-r--r--drivers/staging/rt2870/rt_main_dev.c1
-rw-r--r--drivers/staging/rt2870/rt_profile.c1
-rw-r--r--drivers/staging/rt2870/rt_usb.c1
-rw-r--r--drivers/staging/rt2870/rtmp.h1
-rw-r--r--drivers/staging/rt2870/rtmp_ckipmic.h1
-rw-r--r--drivers/staging/rt2870/rtmp_def.h1
-rw-r--r--drivers/staging/rt2870/rtmp_type.h1
-rw-r--r--drivers/staging/rt2870/spectrum.h1
-rw-r--r--drivers/staging/rt2870/spectrum_def.h1
-rw-r--r--drivers/staging/rt2870/sta/aironet.c1
-rw-r--r--drivers/staging/rt2870/sta/assoc.c1
-rw-r--r--drivers/staging/rt2870/sta/auth.c1
-rw-r--r--drivers/staging/rt2870/sta/auth_rsp.c1
-rw-r--r--drivers/staging/rt2870/sta/connect.c1
-rw-r--r--drivers/staging/rt2870/sta/rtmp_data.c1
-rw-r--r--drivers/staging/rt2870/sta/sanity.c1
-rw-r--r--drivers/staging/rt2870/sta/sync.c1
-rw-r--r--drivers/staging/rt2870/sta/wpa.c1
-rw-r--r--drivers/staging/rt2870/sta_ioctl.c1
-rw-r--r--drivers/staging/rt2870/usb_main_dev.c1
-rw-r--r--drivers/staging/rt2870/wpa.h1
163 files changed, 0 insertions, 74159 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index dca4a0bb6ca..e9254f509e8 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -67,10 +67,6 @@ source "drivers/staging/echo/Kconfig"
67 67
68source "drivers/staging/brcm80211/Kconfig" 68source "drivers/staging/brcm80211/Kconfig"
69 69
70source "drivers/staging/rt2860/Kconfig"
71
72source "drivers/staging/rt2870/Kconfig"
73
74source "drivers/staging/comedi/Kconfig" 70source "drivers/staging/comedi/Kconfig"
75 71
76source "drivers/staging/olpc_dcon/Kconfig" 72source "drivers/staging/olpc_dcon/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index eb93012b6f5..dc642ab5974 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -17,8 +17,6 @@ obj-$(CONFIG_W35UND) += winbond/
17obj-$(CONFIG_PRISM2_USB) += wlan-ng/ 17obj-$(CONFIG_PRISM2_USB) += wlan-ng/
18obj-$(CONFIG_ECHO) += echo/ 18obj-$(CONFIG_ECHO) += echo/
19obj-$(CONFIG_BRCM80211) += brcm80211/ 19obj-$(CONFIG_BRCM80211) += brcm80211/
20obj-$(CONFIG_RT2860) += rt2860/
21obj-$(CONFIG_RT2870) += rt2870/
22obj-$(CONFIG_COMEDI) += comedi/ 20obj-$(CONFIG_COMEDI) += comedi/
23obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/ 21obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/
24obj-$(CONFIG_ASUS_OLED) += asus_oled/ 22obj-$(CONFIG_ASUS_OLED) += asus_oled/
diff --git a/drivers/staging/rt2860/Kconfig b/drivers/staging/rt2860/Kconfig
deleted file mode 100644
index f3a7e47df5e..00000000000
--- a/drivers/staging/rt2860/Kconfig
+++ /dev/null
@@ -1,10 +0,0 @@
1config RT2860
2 tristate "Ralink 2860/3090 wireless support"
3 depends on PCI && X86 && WLAN
4 select WIRELESS_EXT
5 select WEXT_PRIV
6 select CRC_CCITT
7 select FW_LOADER
8 ---help---
9 This is an experimental driver for the Ralink 2860 and 3090
10 wireless chips.
diff --git a/drivers/staging/rt2860/Makefile b/drivers/staging/rt2860/Makefile
deleted file mode 100644
index 6dd0aa5d079..00000000000
--- a/drivers/staging/rt2860/Makefile
+++ /dev/null
@@ -1,52 +0,0 @@
1obj-$(CONFIG_RT2860) += rt2860sta.o
2
3# TODO: all of these should be removed
4ccflags-y := -DLINUX -DAGGREGATION_SUPPORT -DPIGGYBACK_SUPPORT -DWMM_SUPPORT
5ccflags-y += -DRTMP_MAC_PCI -DRTMP_PCI_SUPPORT -DRT2860
6ccflags-y += -DRTMP_RF_RW_SUPPORT -DRTMP_EFUSE_SUPPORT -DRT30xx -DRT3090
7ccflags-y += -DDBG
8
9rt2860sta-y := \
10 common/crypt_md5.o \
11 common/crypt_sha2.o \
12 common/crypt_hmac.o \
13 common/mlme.o \
14 common/cmm_wep.o \
15 common/action.o \
16 common/cmm_data.o \
17 common/rtmp_init.o \
18 common/cmm_tkip.o \
19 common/cmm_aes.o \
20 common/cmm_sync.o \
21 common/eeprom.o \
22 common/cmm_sanity.o \
23 common/cmm_info.o \
24 common/cmm_cfg.o \
25 common/cmm_wpa.o \
26 common/dfs.o \
27 common/spectrum.o \
28 common/rtmp_timer.o \
29 common/rt_channel.o \
30 common/cmm_asic.o \
31 sta/assoc.o \
32 sta/auth.o \
33 sta/auth_rsp.o \
34 sta/sync.o \
35 sta/sanity.o \
36 sta/rtmp_data.o \
37 sta/connect.o \
38 sta/wpa.o \
39 rt_linux.o \
40 rt_main_dev.o \
41 sta_ioctl.o \
42 common/ba_action.o \
43 pci_main_dev.o \
44 rt_pci_rbus.o \
45 common/cmm_mac_pci.o \
46 common/cmm_data_pci.o \
47 common/ee_prom.o \
48 common/rtmp_mcu.o \
49 common/ee_efuse.o \
50 chips/rt30xx.o \
51 common/rt_rf.o \
52 chips/rt3090.o
diff --git a/drivers/staging/rt2860/TODO b/drivers/staging/rt2860/TODO
deleted file mode 100644
index 8e2f6ee0a2b..00000000000
--- a/drivers/staging/rt2860/TODO
+++ /dev/null
@@ -1,16 +0,0 @@
1I'm hesitant to add a TODO file here, as the wireless developers would
2really have people help them out on the "clean" rt2860 driver that can
3be found at the http://rt2x00.serialmonkey.com/ site.
4
5But, if you wish to clean up this driver instead, here's a short list of
6things that need to be done to get it into a more mergable shape:
7
8TODO:
9 - checkpatch.pl clean
10 - sparse clean
11 - port to in-kernel 80211 stack and common rt2x00 infrastructure
12 - review by the wireless developer community
13
14Please send any patches or complaints about this driver to Greg
15Kroah-Hartman <greg@kroah.com> and don't bother the upstream wireless
16kernel developers about it, they want nothing to do with it.
diff --git a/drivers/staging/rt2860/ap.h b/drivers/staging/rt2860/ap.h
deleted file mode 100644
index 2737c0c022f..00000000000
--- a/drivers/staging/rt2860/ap.h
+++ /dev/null
@@ -1,68 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27Module Name:
28ap.h
29
30Abstract:
31Miniport generic portion header file
32
33Revision History:
34Who When What
35-------- ---------- ----------------------------------------------
36Paul Lin 08-01-2002 created
37James Tan 09-06-2002 modified (Revise NTCRegTable)
38John Chang 12-22-2004 modified for RT2561/2661. merge with STA driver
39*/
40#ifndef __AP_H__
41#define __AP_H__
42
43/* ap_wpa.c */
44void WpaStateMachineInit(struct rt_rtmp_adapter *pAd,
45 struct rt_state_machine *Sm,
46 OUT STATE_MACHINE_FUNC Trans[]);
47
48#ifdef RTMP_MAC_USB
49void BeaconUpdateExec(void *SystemSpecific1,
50 void *FunctionContext,
51 void *SystemSpecific2, void *SystemSpecific3);
52#endif /* RTMP_MAC_USB // */
53
54void RTMPSetPiggyBack(struct rt_rtmp_adapter *pAd, IN BOOLEAN bPiggyBack);
55
56void MacTableReset(struct rt_rtmp_adapter *pAd);
57
58struct rt_mac_table_entry *MacTableInsertEntry(struct rt_rtmp_adapter *pAd,
59 u8 *pAddr,
60 u8 apidx, IN BOOLEAN CleanAll);
61
62BOOLEAN MacTableDeleteEntry(struct rt_rtmp_adapter *pAd,
63 u16 wcid, u8 *pAddr);
64
65struct rt_mac_table_entry *MacTableLookup(struct rt_rtmp_adapter *pAd,
66 u8 *pAddr);
67
68#endif /* __AP_H__ */
diff --git a/drivers/staging/rt2860/chip/mac_pci.h b/drivers/staging/rt2860/chip/mac_pci.h
deleted file mode 100644
index b8868a5b9e0..00000000000
--- a/drivers/staging/rt2860/chip/mac_pci.h
+++ /dev/null
@@ -1,355 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 mac_pci.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 Justin P. Mattock 11/07/2010 Fix some typos
35 --------- ---------- ----------------------------------------------
36 */
37
38#ifndef __MAC_PCI_H__
39#define __MAC_PCI_H__
40
41#include "../rtmp_type.h"
42#include "rtmp_mac.h"
43#include "rtmp_phy.h"
44#include "../rtmp_iface.h"
45#include "../rtmp_dot11.h"
46
47/* */
48/* Device ID & Vendor ID related definitions, */
49/* NOTE: you should not add the new VendorID/DeviceID here unless you know for sure what chip it belongs too. */
50/* */
51#define NIC_PCI_VENDOR_ID 0x1814
52#define PCIBUS_INTEL_VENDOR 0x8086
53
54#if !defined(PCI_CAP_ID_EXP)
55#define PCI_CAP_ID_EXP 0x10
56#endif
57#if !defined(PCI_EXP_LNKCTL)
58#define PCI_EXP_LNKCTL 0x10
59#endif
60#if !defined(PCI_CLASS_BRIDGE_PCI)
61#define PCI_CLASS_BRIDGE_PCI 0x0604
62#endif
63
64#define TXINFO_SIZE 0
65#define RTMP_PKT_TAIL_PADDING 0
66#define fRTMP_ADAPTER_NEED_STOP_TX 0
67
68#define AUX_CTRL 0x10c
69
70/* */
71/* TX descriptor format, Tx ring, Mgmt Ring */
72/* */
73struct PACKED rt_txd {
74 /* Word 0 */
75 u32 SDPtr0;
76 /* Word 1 */
77 u32 SDLen1:14;
78 u32 LastSec1:1;
79 u32 Burst:1;
80 u32 SDLen0:14;
81 u32 LastSec0:1;
82 u32 DMADONE:1;
83 /*Word2 */
84 u32 SDPtr1;
85 /*Word3 */
86 u32 rsv2:24;
87 u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correct position */
88 u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */
89 u32 rsv:2;
90 u32 TCO:1; /* */
91 u32 UCO:1; /* */
92 u32 ICO:1; /* */
93};
94
95/* */
96/* Rx descriptor format, Rx Ring */
97/* */
98typedef struct PACKED rt_rxd {
99 /* Word 0 */
100 u32 SDP0;
101 /* Word 1 */
102 u32 SDL1:14;
103 u32 Rsv:2;
104 u32 SDL0:14;
105 u32 LS0:1;
106 u32 DDONE:1;
107 /* Word 2 */
108 u32 SDP1;
109 /* Word 3 */
110 u32 BA:1;
111 u32 DATA:1;
112 u32 NULLDATA:1;
113 u32 FRAG:1;
114 u32 U2M:1; /* 1: this RX frame is unicast to me */
115 u32 Mcast:1; /* 1: this is a multicast frame */
116 u32 Bcast:1; /* 1: this is a broadcast frame */
117 u32 MyBss:1; /* 1: this frame belongs to the same BSSID */
118 u32 Crc:1; /* 1: CRC error */
119 u32 CipherErr:2; /* 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid */
120 u32 AMSDU:1; /* rx with 802.3 header, not 802.11 header. */
121 u32 HTC:1;
122 u32 RSSI:1;
123 u32 L2PAD:1;
124 u32 AMPDU:1;
125 u32 Decrypted:1; /* this frame is being decrypted. */
126 u32 PlcpSignal:1; /* To be moved */
127 u32 PlcpRssil:1; /* To be moved */
128 u32 Rsv1:13;
129} RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
130
131typedef union _TX_ATTENUATION_CTRL_STRUC {
132 struct {
133 unsigned long RF_ISOLATION_ENABLE:1;
134 unsigned long Reserve2:7;
135 unsigned long PCIE_PHY_TX_ATTEN_VALUE:3;
136 unsigned long PCIE_PHY_TX_ATTEN_EN:1;
137 unsigned long Reserve1:20;
138 } field;
139
140 unsigned long word;
141} TX_ATTENUATION_CTRL_STRUC, *PTX_ATTENUATION_CTRL_STRUC;
142
143/* ----------------- EEPROM Related MACRO ----------------- */
144
145/* 8051 firmware image for RT2860 - base address = 0x4000 */
146#define FIRMWARE_IMAGE_BASE 0x2000
147#define MAX_FIRMWARE_IMAGE_SIZE 0x2000 /* 8kbyte */
148
149/* ----------------- Frimware Related MACRO ----------------- */
150#define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \
151 do { \
152 unsigned long _i, _firm; \
153 RTMP_IO_WRITE32(_pAd, PBF_SYS_CTRL, 0x10000); \
154 \
155 for (_i = 0; _i < _FwLen; _i += 4) { \
156 _firm = _pFwImage[_i] + \
157 (_pFwImage[_i+3] << 24) + \
158 (_pFwImage[_i+2] << 16) + \
159 (_pFwImage[_i+1] << 8); \
160 RTMP_IO_WRITE32(_pAd, FIRMWARE_IMAGE_BASE + _i, _firm); \
161 } \
162 RTMP_IO_WRITE32(_pAd, PBF_SYS_CTRL, 0x00000); \
163 RTMP_IO_WRITE32(_pAd, PBF_SYS_CTRL, 0x00001); \
164 \
165 /* initialize BBP R/W access agent */ \
166 RTMP_IO_WRITE32(_pAd, H2M_BBP_AGENT, 0); \
167 RTMP_IO_WRITE32(_pAd, H2M_MAILBOX_CSR, 0); \
168 } while (0)
169
170/* ----------------- TX Related MACRO ----------------- */
171#define RTMP_START_DEQUEUE(pAd, QueIdx, irqFlags) do {} while (0)
172#define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags) do {} while (0)
173
174#define RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
175 ((freeNum) >= (unsigned long)(pTxBlk->TotalFragNum + RTMP_GET_PACKET_FRAGMENTS(pPacket) + 3)) /* rough estimate we will use 3 more descriptor. */
176#define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx) do {} while (0)
177
178#define NEED_QUEUE_BACK_FOR_AGG(pAd, QueIdx, freeNum, _TxFrameType) \
179 (((freeNum != (TX_RING_SIZE-1)) && \
180 (pAd->TxSwQueue[QueIdx].Number == 0)) || (freeNum < 3))
181
182#define HAL_KickOutMgmtTx(_pAd, _QueIdx, _pPacket, _pSrcBufVA, _SrcBufLen) \
183 RtmpPCIMgmtKickOut(_pAd, _QueIdx, _pPacket, _pSrcBufVA, _SrcBufLen)
184
185#define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
186 /* RtmpPCI_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) */
187
188#define HAL_WriteTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
189 RtmpPCI_WriteSingleTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
190
191#define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
192 RtmpPCI_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
193
194#define HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber) \
195 RtmpPCI_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber)
196
197#define HAL_FinalWriteTxResource(_pAd, _pTxBlk, _TotalMPDUSize, _FirstTxIdx) \
198 RtmpPCI_FinalWriteTxResource(_pAd, _pTxBlk, _TotalMPDUSize, _FirstTxIdx)
199
200#define HAL_LastTxIdx(_pAd, _QueIdx, _LastTxIdx) \
201 /*RtmpPCIDataLastTxIdx(_pAd, _QueIdx,_LastTxIdx) */
202
203#define HAL_KickOutTx(_pAd, _pTxBlk, _QueIdx) \
204 RTMP_IO_WRITE32((_pAd), TX_CTX_IDX0+((_QueIdx)*0x10), (_pAd)->TxRing[(_QueIdx)].TxCpuIdx)
205/* RtmpPCIDataKickOut(_pAd, _pTxBlk, _QueIdx)*/
206
207#define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \
208 MiniportMMRequest(_pAd, _QueIdx, _pNullFrame, _frameLen)
209
210#define GET_TXRING_FREENO(_pAd, _QueIdx) \
211 (_pAd->TxRing[_QueIdx].TxSwFreeIdx > _pAd->TxRing[_QueIdx].TxCpuIdx) ? \
212 (_pAd->TxRing[_QueIdx].TxSwFreeIdx - _pAd->TxRing[_QueIdx].TxCpuIdx - 1) \
213 : \
214 (_pAd->TxRing[_QueIdx].TxSwFreeIdx + TX_RING_SIZE - _pAd->TxRing[_QueIdx].TxCpuIdx - 1);
215
216#define GET_MGMTRING_FREENO(_pAd) \
217 (_pAd->MgmtRing.TxSwFreeIdx > _pAd->MgmtRing.TxCpuIdx) ? \
218 (_pAd->MgmtRing.TxSwFreeIdx - _pAd->MgmtRing.TxCpuIdx - 1) \
219 : \
220 (_pAd->MgmtRing.TxSwFreeIdx + MGMT_RING_SIZE - _pAd->MgmtRing.TxCpuIdx - 1);
221
222/* ----------------- RX Related MACRO ----------------- */
223
224/* ----------------- ASIC Related MACRO ----------------- */
225/* reset MAC of a station entry to 0x000000000000 */
226#define RTMP_STA_ENTRY_MAC_RESET(pAd, Wcid) \
227 AsicDelWcidTab(pAd, Wcid);
228
229/* add this entry into ASIC RX WCID search table */
230#define RTMP_STA_ENTRY_ADD(pAd, pEntry) \
231 AsicUpdateRxWCIDTable(pAd, pEntry->Aid, pEntry->Addr);
232
233/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */
234/* Set MAC register value according operation mode */
235#define RTMP_UPDATE_PROTECT(pAd) \
236 AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT), TRUE, 0);
237/* end johnli */
238
239/* remove Pair-wise key material from ASIC */
240#define RTMP_STA_ENTRY_KEY_DEL(pAd, BssIdx, Wcid) \
241 AsicRemovePairwiseKeyEntry(pAd, BssIdx, (u8)Wcid);
242
243/* add Client security information into ASIC WCID table and IVEIV table */
244#define RTMP_STA_SECURITY_INFO_ADD(pAd, apidx, KeyID, pEntry) \
245 RTMPAddWcidAttributeEntry(pAd, apidx, KeyID, \
246 pAd->SharedKey[apidx][KeyID].CipherAlg, pEntry);
247
248#define RTMP_SECURITY_KEY_ADD(pAd, apidx, KeyID, pEntry) \
249 { /* update pairwise key information to ASIC Shared Key Table */ \
250 AsicAddSharedKeyEntry(pAd, apidx, KeyID, \
251 pAd->SharedKey[apidx][KeyID].CipherAlg, \
252 pAd->SharedKey[apidx][KeyID].Key, \
253 pAd->SharedKey[apidx][KeyID].TxMic, \
254 pAd->SharedKey[apidx][KeyID].RxMic); \
255 /* update ASIC WCID attribute table and IVEIV table */ \
256 RTMPAddWcidAttributeEntry(pAd, apidx, KeyID, \
257 pAd->SharedKey[apidx][KeyID].CipherAlg, \
258 pEntry); }
259
260/* Insert the BA bitmap to ASIC for the Wcid entry */
261#define RTMP_ADD_BA_SESSION_TO_ASIC(_pAd, _Aid, _TID) \
262 do { \
263 u32 _Value = 0, _Offset; \
264 _Offset = MAC_WCID_BASE + (_Aid) * HW_WCID_ENTRY_SIZE + 4; \
265 RTMP_IO_READ32((_pAd), _Offset, &_Value);\
266 _Value |= (0x10000<<(_TID)); \
267 RTMP_IO_WRITE32((_pAd), _Offset, _Value);\
268 } while (0)
269
270/* Remove the BA bitmap from ASIC for the Wcid entry */
271/* bitmap field starts at 0x10000 in ASIC WCID table */
272#define RTMP_DEL_BA_SESSION_FROM_ASIC(_pAd, _Wcid, _TID) \
273 do { \
274 u32 _Value = 0, _Offset; \
275 _Offset = MAC_WCID_BASE + (_Wcid) * HW_WCID_ENTRY_SIZE + 4; \
276 RTMP_IO_READ32((_pAd), _Offset, &_Value); \
277 _Value &= (~(0x10000 << (_TID))); \
278 RTMP_IO_WRITE32((_pAd), _Offset, _Value); \
279 } while (0)
280
281/* ----------------- Interface Related MACRO ----------------- */
282
283/* */
284/* Enable & Disable NIC interrupt via writing interrupt mask register */
285/* Since it use ADAPTER structure, it have to be put after structure definition. */
286/* */
287#define RTMP_ASIC_INTERRUPT_DISABLE(_pAd) \
288 do { \
289 RTMP_IO_WRITE32((_pAd), INT_MASK_CSR, 0x0); /* 0: disable */ \
290 RTMP_CLEAR_FLAG((_pAd), fRTMP_ADAPTER_INTERRUPT_ACTIVE); \
291 } while (0)
292
293#define RTMP_ASIC_INTERRUPT_ENABLE(_pAd)\
294 do { \
295 RTMP_IO_WRITE32((_pAd), INT_MASK_CSR, (_pAd)->int_enable_reg /*DELAYINTMASK*/); /* 1:enable */ \
296 RTMP_SET_FLAG((_pAd), fRTMP_ADAPTER_INTERRUPT_ACTIVE); \
297 } while (0)
298
299#define RTMP_IRQ_INIT(pAd) \
300 { pAd->int_enable_reg = ((DELAYINTMASK) | \
301 (RxINT|TxDataInt|TxMgmtInt)) & ~(0x03); \
302 pAd->int_disable_mask = 0; \
303 pAd->int_pending = 0; }
304
305#define RTMP_IRQ_ENABLE(pAd) \
306 { /* clear garbage ints */ \
307 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, 0xffffffff);\
308 RTMP_ASIC_INTERRUPT_ENABLE(pAd); }
309
310/* ----------------- MLME Related MACRO ----------------- */
311#define RTMP_MLME_HANDLER(pAd) MlmeHandler(pAd)
312
313#define RTMP_MLME_PRE_SANITY_CHECK(pAd)
314
315#define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \
316 RTMPSetTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, 100);
317
318#define RTMP_MLME_RESET_STATE_MACHINE(pAd) \
319 MlmeRestartStateMachine(pAd)
320
321#define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry)\
322 HandleCounterMeasure(_pAd, _pEntry)
323
324/* ----------------- Power Save Related MACRO ----------------- */
325#define RTMP_PS_POLL_ENQUEUE(pAd) EnqueuePsPoll(pAd)
326
327/* For RTMPPCIePowerLinkCtrlRestore () function */
328#define RESTORE_HALT 1
329#define RESTORE_WAKEUP 2
330#define RESTORE_CLOSE 3
331
332#define PowerSafeCID 1
333#define PowerRadioOffCID 2
334#define PowerWakeCID 3
335#define CID0MASK 0x000000ff
336#define CID1MASK 0x0000ff00
337#define CID2MASK 0x00ff0000
338#define CID3MASK 0xff000000
339
340#define RTMP_STA_FORCE_WAKEUP(pAd, bFromTx) \
341 RT28xxPciStaAsicForceWakeup(pAd, bFromTx);
342
343#define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
344 RT28xxPciStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
345
346#define RTMP_SET_PSM_BIT(_pAd, _val) \
347 MlmeSetPsmBit(_pAd, _val);
348
349#define RTMP_MLME_RADIO_ON(pAd) \
350 RT28xxPciMlmeRadioOn(pAd);
351
352#define RTMP_MLME_RADIO_OFF(pAd) \
353 RT28xxPciMlmeRadioOFF(pAd);
354
355#endif /*__MAC_PCI_H__ // */
diff --git a/drivers/staging/rt2860/chip/mac_usb.h b/drivers/staging/rt2860/chip/mac_usb.h
deleted file mode 100644
index e8158fb5864..00000000000
--- a/drivers/staging/rt2860/chip/mac_usb.h
+++ /dev/null
@@ -1,345 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 mac_usb.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 Justin P. Mattock 11/07/2010 Fix a typo
35 --------- ---------- ----------------------------------------------
36 */
37
38#ifndef __MAC_USB_H__
39#define __MAC_USB_H__
40
41#include "../rtmp_type.h"
42#include "rtmp_mac.h"
43#include "rtmp_phy.h"
44#include "../rtmp_iface.h"
45#include "../rtmp_dot11.h"
46
47#define USB_CYC_CFG 0x02a4
48
49#define BEACON_RING_SIZE 2
50#define MGMTPIPEIDX 0 /* EP6 is highest priority */
51
52#define RTMP_PKT_TAIL_PADDING 11 /* 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding) */
53
54#define fRTMP_ADAPTER_NEED_STOP_TX \
55 (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
56 fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \
57 fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
58
59/* */
60/* RXINFO appends at the end of each rx packet. */
61/* */
62#define RXINFO_SIZE 4
63#define RT2870_RXDMALEN_FIELD_SIZE 4
64
65typedef struct PACKED rt_rxinfo {
66 u32 BA:1;
67 u32 DATA:1;
68 u32 NULLDATA:1;
69 u32 FRAG:1;
70 u32 U2M:1; /* 1: this RX frame is unicast to me */
71 u32 Mcast:1; /* 1: this is a multicast frame */
72 u32 Bcast:1; /* 1: this is a broadcast frame */
73 u32 MyBss:1; /* 1: this frame belongs to the same BSSID */
74 u32 Crc:1; /* 1: CRC error */
75 u32 CipherErr:2; /* 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid */
76 u32 AMSDU:1; /* rx with 802.3 header, not 802.11 header. */
77 u32 HTC:1;
78 u32 RSSI:1;
79 u32 L2PAD:1;
80 u32 AMPDU:1; /* To be moved */
81 u32 Decrypted:1;
82 u32 PlcpRssil:1;
83 u32 CipherAlg:1;
84 u32 LastAMSDU:1;
85 u32 PlcpSignal:12;
86} RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
87
88/* */
89/* TXINFO */
90/* */
91#define TXINFO_SIZE 4
92
93struct rt_txinfo {
94 /* Word 0 */
95 u32 USBDMATxPktLen:16; /*used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame. */
96 u32 rsv:8;
97 u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correct position */
98 u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */
99 u32 SwUseLastRound:1; /* Software use. */
100 u32 rsv2:2; /* Software use. */
101 u32 USBDMANextVLD:1; /*used ONLY in USB bulk Aggregation, NextValid */
102 u32 USBDMATxburst:1; /*used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint */
103};
104
105/* */
106/* Management ring buffer format */
107/* */
108struct rt_mgmt {
109 BOOLEAN Valid;
110 u8 *pBuffer;
111 unsigned long Length;
112};
113
114/*////////////////////////////////////////////////////////////////////////// */
115/* The struct rt_tx_buffer structure forms the transmitted USB packet to the device */
116/*////////////////////////////////////////////////////////////////////////// */
117struct rt_tx_buffer {
118 union {
119 u8 WirelessPacket[TX_BUFFER_NORMSIZE];
120 struct rt_header_802_11 NullFrame;
121 struct rt_pspoll_frame PsPollPacket;
122 struct rt_rts_frame RTSFrame;
123 } field;
124 u8 Aggregation[4]; /*Buffer for save Aggregation size. */
125};
126
127struct rt_httx_buffer {
128 union {
129 u8 WirelessPacket[MAX_TXBULK_SIZE];
130 struct rt_header_802_11 NullFrame;
131 struct rt_pspoll_frame PsPollPacket;
132 struct rt_rts_frame RTSFrame;
133 } field;
134 u8 Aggregation[4]; /*Buffer for save Aggregation size. */
135};
136
137/* used to track driver-generated write irps */
138struct rt_tx_context {
139 void *pAd; /*Initialized in MiniportInitialize */
140 PURB pUrb; /*Initialized in MiniportInitialize */
141 PIRP pIrp; /*used to cancel pending bulk out. */
142 /*Initialized in MiniportInitialize */
143 struct rt_tx_buffer *TransferBuffer; /*Initialized in MiniportInitialize */
144 unsigned long BulkOutSize;
145 u8 BulkOutPipeId;
146 u8 SelfIdx;
147 BOOLEAN InUse;
148 BOOLEAN bWaitingBulkOut; /* at least one packet is in this TxContext, ready for making IRP anytime. */
149 BOOLEAN bFullForBulkOut; /* all tx buffer are full , so waiting for tx bulkout. */
150 BOOLEAN IRPPending;
151 BOOLEAN LastOne;
152 BOOLEAN bAggregatible;
153 u8 Header_802_3[LENGTH_802_3];
154 u8 Rsv[2];
155 unsigned long DataOffset;
156 u32 TxRate;
157 dma_addr_t data_dma; /* urb dma on linux */
158
159};
160
161/* used to track driver-generated write irps */
162struct rt_ht_tx_context {
163 void *pAd; /*Initialized in MiniportInitialize */
164 PURB pUrb; /*Initialized in MiniportInitialize */
165 PIRP pIrp; /*used to cancel pending bulk out. */
166 /*Initialized in MiniportInitialize */
167 struct rt_httx_buffer *TransferBuffer; /*Initialized in MiniportInitialize */
168 unsigned long BulkOutSize; /* Indicate the total bulk-out size in bytes in one bulk-transmission */
169 u8 BulkOutPipeId;
170 BOOLEAN IRPPending;
171 BOOLEAN LastOne;
172 BOOLEAN bCurWriting;
173 BOOLEAN bRingEmpty;
174 BOOLEAN bCopySavePad;
175 u8 SavedPad[8];
176 u8 Header_802_3[LENGTH_802_3];
177 unsigned long CurWritePosition; /* Indicate the buffer offset which packet will be inserted start from. */
178 unsigned long CurWriteRealPos; /* Indicate the buffer offset which packet now are writing to. */
179 unsigned long NextBulkOutPosition; /* Indicate the buffer start offset of a bulk-transmission */
180 unsigned long ENextBulkOutPosition; /* Indicate the buffer end offset of a bulk-transmission */
181 u32 TxRate;
182 dma_addr_t data_dma; /* urb dma on linux */
183};
184
185/* */
186/* Structure to keep track of receive packets and buffers to indicate */
187/* receive data to the protocol. */
188/* */
189struct rt_rx_context {
190 u8 *TransferBuffer;
191 void *pAd;
192 PIRP pIrp; /*used to cancel pending bulk in. */
193 PURB pUrb;
194 /*These 2 Boolean shouldn't both be 1 at the same time. */
195 unsigned long BulkInOffset; /* number of packets waiting for reordering . */
196/* BOOLEAN ReorderInUse; // At least one packet in this buffer are in reordering buffer and wait for receive indication */
197 BOOLEAN bRxHandling; /* Notify this packet is being process now. */
198 BOOLEAN InUse; /* USB Hardware Occupied. Wait for USB HW to put packet. */
199 BOOLEAN Readable; /* Receive Complete back. OK for driver to indicate receiving packet. */
200 BOOLEAN IRPPending; /* TODO: To be removed */
201 atomic_t IrpLock;
202 spinlock_t RxContextLock;
203 dma_addr_t data_dma; /* urb dma on linux */
204};
205
206/******************************************************************************
207
208 USB Frimware Related MACRO
209
210******************************************************************************/
211/* 8051 firmware image for usb - use last-half base address = 0x3000 */
212#define FIRMWARE_IMAGE_BASE 0x3000
213#define MAX_FIRMWARE_IMAGE_SIZE 0x1000 /* 4kbyte */
214
215#define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \
216 RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
217
218/******************************************************************************
219
220 USB TX Related MACRO
221
222******************************************************************************/
223#define RTMP_START_DEQUEUE(pAd, QueIdx, irqFlags) \
224 do { \
225 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
226 if (pAd->DeQueueRunning[QueIdx]) { \
227 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
228 DBGPRINT(RT_DEBUG_OFF, ("DeQueueRunning[%d]= TRUE!\n", QueIdx)); \
229 continue; \
230 } else { \
231 pAd->DeQueueRunning[QueIdx] = TRUE; \
232 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
233 } \
234 } while (0)
235
236#define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags) \
237 do { \
238 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
239 pAd->DeQueueRunning[QueIdx] = FALSE; \
240 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
241 } while (0)
242
243#define RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
244 (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
245
246#define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx) \
247 do {} while (0)
248
249#define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType) \
250 ((_TxFrameType == TX_RALINK_FRAME) && \
251 (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
252
253#define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
254 RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
255
256#define HAL_WriteTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
257 RtmpUSB_WriteSingleTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
258
259#define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
260 RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
261
262#define HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber) \
263 RtmpUSB_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber)
264
265#define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx) \
266 RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
267
268#define HAL_LastTxIdx(pAd, QueIdx, TxIdx) \
269 /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx) */
270
271#define HAL_KickOutTx(pAd, pTxBlk, QueIdx) \
272 RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
273
274#define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen) \
275 RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
276
277#define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \
278 RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
279
280#define GET_TXRING_FREENO(_pAd, _QueIdx) (_QueIdx) /*(_pAd->TxRing[_QueIdx].TxSwFreeIdx) */
281#define GET_MGMTRING_FREENO(_pAd) (_pAd->MgmtRing.TxSwFreeIdx)
282
283/* ----------------- RX Related MACRO ----------------- */
284
285/*
286 * Device Hardware Interface Related MACRO
287 */
288#define RTMP_IRQ_INIT(pAd) do {} while (0)
289#define RTMP_IRQ_ENABLE(pAd) do {} while (0)
290
291/*
292 * MLME Related MACRO
293 */
294#define RTMP_MLME_HANDLER(pAd) RTUSBMlmeUp(pAd)
295
296#define RTMP_MLME_PRE_SANITY_CHECK(pAd) \
297 { if ((pAd->CommonCfg.bHardwareRadio == TRUE) && \
298 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && \
299 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { \
300 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
301
302#define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \
303 { RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0); \
304 RTUSBMlmeUp(pAd); }
305
306#define RTMP_MLME_RESET_STATE_MACHINE(pAd) \
307 { MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL); \
308 RTUSBMlmeUp(pAd); }
309
310#define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry) \
311 { RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(struct rt_mac_table_entry)); \
312 RTUSBMlmeUp(_pAd); \
313 }
314
315/*
316 * Power Save Related MACRO
317 */
318#define RTMP_PS_POLL_ENQUEUE(pAd) \
319 { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); \
320 RTUSBKickBulkOut(pAd); }
321
322#define RTMP_STA_FORCE_WAKEUP(_pAd, bFromTx) \
323 RT28xxUsbStaAsicForceWakeup(_pAd, bFromTx);
324
325#define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
326 RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
327
328#define RTMP_SET_PSM_BIT(_pAd, _val) \
329 {\
330 if ((_pAd)->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP) \
331 MlmeSetPsmBit(_pAd, _val);\
332 else { \
333 u16 _psm_val; \
334 _psm_val = _val; \
335 RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_SET_PSM_BIT, &(_psm_val), sizeof(u16)); \
336 } \
337 }
338
339#define RTMP_MLME_RADIO_ON(pAd) \
340 RT28xxUsbMlmeRadioOn(pAd);
341
342#define RTMP_MLME_RADIO_OFF(pAd) \
343 RT28xxUsbMlmeRadioOFF(pAd);
344
345#endif /*__MAC_USB_H__ // */
diff --git a/drivers/staging/rt2860/chip/rt2860.h b/drivers/staging/rt2860/chip/rt2860.h
deleted file mode 100644
index f30b80820b9..00000000000
--- a/drivers/staging/rt2860/chip/rt2860.h
+++ /dev/null
@@ -1,54 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28#ifndef __RT2860_H__
29#define __RT2860_H__
30
31#include "mac_pci.h"
32
33#ifndef RTMP_PCI_SUPPORT
34#error "For RT2860, you should define the compile flag -DRTMP_PCI_SUPPORT"
35#endif
36
37#ifndef RTMP_MAC_PCI
38#error "For RT2880, you should define the compile flag -DRTMP_MAC_PCI"
39#endif
40
41/* */
42/* Device ID & Vendor ID, these values should match EEPROM value */
43/* */
44#define NIC2860_PCI_DEVICE_ID 0x0601
45#define NIC2860_PCIe_DEVICE_ID 0x0681
46#define NIC2760_PCI_DEVICE_ID 0x0701 /* 1T/2R Cardbus ??? */
47#define NIC2790_PCIe_DEVICE_ID 0x0781 /* 1T/2R miniCard */
48
49#define VEN_AWT_PCIe_DEVICE_ID 0x1059
50#define VEN_AWT_PCI_VENDOR_ID 0x1A3B
51
52#define EDIMAX_PCI_VENDOR_ID 0x1432
53
54#endif /*__RT2860_H__ // */
diff --git a/drivers/staging/rt2860/chip/rt2870.h b/drivers/staging/rt2860/chip/rt2870.h
deleted file mode 100644
index 8263f1baefa..00000000000
--- a/drivers/staging/rt2860/chip/rt2870.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27#ifndef __RT2870_H__
28#define __RT2870_H__
29
30#ifdef RT2870
31
32#ifndef RTMP_USB_SUPPORT
33#error "For RT2870, you should define the compile flag -DRTMP_USB_SUPPORT"
34#endif
35
36#ifndef RTMP_MAC_USB
37#error "For RT2870, you should define the compile flag -DRTMP_MAC_USB"
38#endif
39
40#include "../rtmp_type.h"
41#include "mac_usb.h"
42
43/*#define RTMP_CHIP_NAME "RT2870" */
44
45#endif /* RT2870 // */
46#endif /*__RT2870_H__ // */
diff --git a/drivers/staging/rt2860/chip/rt3070.h b/drivers/staging/rt2860/chip/rt3070.h
deleted file mode 100644
index 172ce705423..00000000000
--- a/drivers/staging/rt2860/chip/rt3070.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt3070.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 --------- ---------- ----------------------------------------------
35 */
36
37#ifndef __RT3070_H__
38#define __RT3070_H__
39
40#ifdef RT3070
41
42#ifndef RTMP_USB_SUPPORT
43#error "For RT3070, you should define the compile flag -DRTMP_USB_SUPPORT"
44#endif
45
46#ifndef RTMP_MAC_USB
47#error "For RT3070, you should define the compile flag -DRTMP_MAC_USB"
48#endif
49
50#ifndef RTMP_RF_RW_SUPPORT
51#error "For RT3070, you should define the compile flag -DRTMP_RF_RW_SUPPORT"
52#endif
53
54#ifndef RT30xx
55#error "For RT3070, you should define the compile flag -DRT30xx"
56#endif
57
58#include "mac_usb.h"
59#include "rt30xx.h"
60
61/* */
62/* Device ID & Vendor ID, these values should match EEPROM value */
63/* */
64
65#endif /* RT3070 // */
66
67#endif /*__RT3070_H__ // */
diff --git a/drivers/staging/rt2860/chip/rt3090.h b/drivers/staging/rt2860/chip/rt3090.h
deleted file mode 100644
index 102b938e74b..00000000000
--- a/drivers/staging/rt2860/chip/rt3090.h
+++ /dev/null
@@ -1,72 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt3090.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 --------- ---------- ----------------------------------------------
35 */
36
37#ifndef __RT3090_H__
38#define __RT3090_H__
39
40#ifdef RT3090
41
42#ifndef RTMP_PCI_SUPPORT
43#error "For RT3090, you should define the compile flag -DRTMP_PCI_SUPPORT"
44#endif
45
46#ifndef RTMP_MAC_PCI
47#error "For RT3090, you should define the compile flag -DRTMP_MAC_PCI"
48#endif
49
50#ifndef RTMP_RF_RW_SUPPORT
51#error "For RT3090, you should define the compile flag -DRTMP_RF_RW_SUPPORT"
52#endif
53
54#ifndef RT30xx
55#error "For RT3090, you should define the compile flag -DRT30xx"
56#endif
57
58#define PCIE_PS_SUPPORT
59
60#include "mac_pci.h"
61#include "rt30xx.h"
62
63/* */
64/* Device ID & Vendor ID, these values should match EEPROM value */
65/* */
66#define NIC3090_PCIe_DEVICE_ID 0x3090 /* 1T/1R miniCard */
67#define NIC3091_PCIe_DEVICE_ID 0x3091 /* 1T/2R miniCard */
68#define NIC3092_PCIe_DEVICE_ID 0x3092 /* 2T/2R miniCard */
69
70#endif /* RT3090 // */
71
72#endif /*__RT3090_H__ // */
diff --git a/drivers/staging/rt2860/chip/rt30xx.h b/drivers/staging/rt2860/chip/rt30xx.h
deleted file mode 100644
index 02e1d728fb4..00000000000
--- a/drivers/staging/rt2860/chip/rt30xx.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt30xx.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 --------- ---------- ----------------------------------------------
35 */
36
37#ifndef __RT30XX_H__
38#define __RT30XX_H__
39
40#ifdef RT30xx
41
42extern struct rt_reg_pair RT30xx_RFRegTable[];
43extern u8 NUM_RF_REG_PARMS;
44
45#endif /* RT30xx // */
46
47#endif /*__RT30XX_H__ // */
diff --git a/drivers/staging/rt2860/chip/rtmp_mac.h b/drivers/staging/rt2860/chip/rtmp_mac.h
deleted file mode 100644
index 3d1e4915b95..00000000000
--- a/drivers/staging/rt2860/chip/rtmp_mac.h
+++ /dev/null
@@ -1,1308 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_mac.h
29
30 Abstract:
31 Ralink Wireless Chip MAC related definition & structures
32
33 Revision History:
34 Who When What
35 Justin P. Mattock 11/07/2010 Fix a comments, and typos
36 -------- ---------- ----------------------------------------------
37*/
38
39#ifndef __RTMP_MAC_H__
40#define __RTMP_MAC_H__
41
42/* ================================================================================= */
43/* TX / RX ring descriptor format */
44/* ================================================================================= */
45
46/* the first 24-byte in TXD is called TXINFO and will be DMAed to MAC block through TXFIFO. */
47/* MAC block uses this TXINFO to control the transmission behavior of this frame. */
48#define FIFO_MGMT 0
49#define FIFO_HCCA 1
50#define FIFO_EDCA 2
51
52/* */
53/* TXD Wireless Information format for Tx ring and Mgmt Ring */
54/* */
55/*txop : for txop mode */
56/* 0:txop for the MPDU frame will be handles by ASIC by register */
57/* 1/2/3:the MPDU frame is send after PIFS/backoff/SIFS */
58struct PACKED rt_txwi {
59 /* Word 0 */
60 /* ex: 00 03 00 40 means txop = 3, PHYMODE = 1 */
61 u32 FRAG:1; /* 1 to inform TKIP engine this is a fragment. */
62 u32 MIMOps:1; /* the remote peer is in dynamic MIMO-PS mode */
63 u32 CFACK:1;
64 u32 TS:1;
65
66 u32 AMPDU:1;
67 u32 MpduDensity:3;
68 u32 txop:2; /*FOR "THIS" frame. 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs only when previous frame exchange is successful. */
69 u32 rsv:6;
70
71 u32 MCS:7;
72 u32 BW:1; /*channel bandwidth 20MHz or 40 MHz */
73 u32 ShortGI:1;
74 u32 STBC:2; /* 1: STBC support MCS =0-7, 2,3 : RESERVE */
75 u32 Ifs:1; /* */
76/* u32 rsv2:2; //channel bandwidth 20MHz or 40 MHz */
77 u32 rsv2:1;
78 u32 TxBF:1; /* 3*3 */
79 u32 PHYMODE:2;
80 /* Word1 */
81 /* ex: 1c ff 38 00 means ACK=0, BAWinSize=7, MPDUtotalByteCount = 0x38 */
82 u32 ACK:1;
83 u32 NSEQ:1;
84 u32 BAWinSize:6;
85 u32 WirelessCliID:8;
86 u32 MPDUtotalByteCount:12;
87 u32 PacketId:4;
88 /*Word2 */
89 u32 IV;
90 /*Word3 */
91 u32 EIV;
92};
93
94/* */
95/* RXWI wireless information format, in PBF. invisible in driver. */
96/* */
97struct PACKED rt_rxwi {
98 /* Word 0 */
99 u32 WirelessCliID:8;
100 u32 KeyIndex:2;
101 u32 BSSID:3;
102 u32 UDF:3;
103 u32 MPDUtotalByteCount:12;
104 u32 TID:4;
105 /* Word 1 */
106 u32 FRAG:4;
107 u32 SEQUENCE:12;
108 u32 MCS:7;
109 u32 BW:1;
110 u32 ShortGI:1;
111 u32 STBC:2;
112 u32 rsv:3;
113 u32 PHYMODE:2; /* 1: this RX frame is unicast to me */
114 /*Word2 */
115 u32 RSSI0:8;
116 u32 RSSI1:8;
117 u32 RSSI2:8;
118 u32 rsv1:8;
119 /*Word3 */
120 u32 SNR0:8;
121 u32 SNR1:8;
122 u32 FOFFSET:8; /* RT35xx */
123 u32 rsv2:8;
124 /*u32 rsv2:16; */
125};
126
127/* ================================================================================= */
128/* Register format */
129/* ================================================================================= */
130
131/* */
132/* SCH/DMA registers - base address 0x0200 */
133/* */
134/* INT_SOURCE_CSR: Interrupt source register. Write one to clear corresponding bit */
135/* */
136#define DMA_CSR0 0x200
137#define INT_SOURCE_CSR 0x200
138typedef union _INT_SOURCE_CSR_STRUC {
139 struct {
140 u32 RxDelayINT:1;
141 u32 TxDelayINT:1;
142 u32 RxDone:1;
143 u32 Ac0DmaDone:1; /*4 */
144 u32 Ac1DmaDone:1;
145 u32 Ac2DmaDone:1;
146 u32 Ac3DmaDone:1;
147 u32 HccaDmaDone:1; /* bit7 */
148 u32 MgmtDmaDone:1;
149 u32 MCUCommandINT:1; /*bit 9 */
150 u32 RxTxCoherent:1;
151 u32 TBTTInt:1;
152 u32 PreTBTT:1;
153 u32 TXFifoStatusInt:1; /*FIFO Statistics is full, sw should read 0x171c */
154 u32 AutoWakeup:1; /*bit14 */
155 u32 GPTimer:1;
156 u32 RxCoherent:1; /*bit16 */
157 u32 TxCoherent:1;
158 u32: 14;
159 } field;
160 u32 word;
161} INT_SOURCE_CSR_STRUC, *PINT_SOURCE_CSR_STRUC;
162
163/* */
164/* INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF */
165/* */
166#define INT_MASK_CSR 0x204
167typedef union _INT_MASK_CSR_STRUC {
168 struct {
169 u32 RXDelay_INT_MSK:1;
170 u32 TxDelay:1;
171 u32 RxDone:1;
172 u32 Ac0DmaDone:1;
173 u32 Ac1DmaDone:1;
174 u32 Ac2DmaDone:1;
175 u32 Ac3DmaDone:1;
176 u32 HccaDmaDone:1;
177 u32 MgmtDmaDone:1;
178 u32 MCUCommandINT:1;
179 u32: 20;
180 u32 RxCoherent:1;
181 u32 TxCoherent:1;
182 } field;
183 u32 word;
184} INT_MASK_CSR_STRUC, *PINT_MASK_CSR_STRUC;
185
186#define WPDMA_GLO_CFG 0x208
187typedef union _WPDMA_GLO_CFG_STRUC {
188 struct {
189 u32 EnableTxDMA:1;
190 u32 TxDMABusy:1;
191 u32 EnableRxDMA:1;
192 u32 RxDMABusy:1;
193 u32 WPDMABurstSIZE:2;
194 u32 EnTXWriteBackDDONE:1;
195 u32 BigEndian:1;
196 u32 RXHdrScater:8;
197 u32 HDR_SEG_LEN:16;
198 } field;
199 u32 word;
200} WPDMA_GLO_CFG_STRUC, *PWPDMA_GLO_CFG_STRUC;
201
202#define WPDMA_RST_IDX 0x20c
203typedef union _WPDMA_RST_IDX_STRUC {
204 struct {
205 u32 RST_DTX_IDX0:1;
206 u32 RST_DTX_IDX1:1;
207 u32 RST_DTX_IDX2:1;
208 u32 RST_DTX_IDX3:1;
209 u32 RST_DTX_IDX4:1;
210 u32 RST_DTX_IDX5:1;
211 u32 rsv:10;
212 u32 RST_DRX_IDX0:1;
213 u32: 15;
214 } field;
215 u32 word;
216} WPDMA_RST_IDX_STRUC, *PWPDMA_RST_IDX_STRUC;
217#define DELAY_INT_CFG 0x0210
218typedef union _DELAY_INT_CFG_STRUC {
219 struct {
220 u32 RXMAX_PTIME:8;
221 u32 RXMAX_PINT:7;
222 u32 RXDLY_INT_EN:1;
223 u32 TXMAX_PTIME:8;
224 u32 TXMAX_PINT:7;
225 u32 TXDLY_INT_EN:1;
226 } field;
227 u32 word;
228} DELAY_INT_CFG_STRUC, *PDELAY_INT_CFG_STRUC;
229#define WMM_AIFSN_CFG 0x0214
230typedef union _AIFSN_CSR_STRUC {
231 struct {
232 u32 Aifsn0:4; /* for AC_BE */
233 u32 Aifsn1:4; /* for AC_BK */
234 u32 Aifsn2:4; /* for AC_VI */
235 u32 Aifsn3:4; /* for AC_VO */
236 u32 Rsv:16;
237 } field;
238 u32 word;
239} AIFSN_CSR_STRUC, *PAIFSN_CSR_STRUC;
240/* */
241/* CWMIN_CSR: CWmin for each EDCA AC */
242/* */
243#define WMM_CWMIN_CFG 0x0218
244typedef union _CWMIN_CSR_STRUC {
245 struct {
246 u32 Cwmin0:4; /* for AC_BE */
247 u32 Cwmin1:4; /* for AC_BK */
248 u32 Cwmin2:4; /* for AC_VI */
249 u32 Cwmin3:4; /* for AC_VO */
250 u32 Rsv:16;
251 } field;
252 u32 word;
253} CWMIN_CSR_STRUC, *PCWMIN_CSR_STRUC;
254
255/* */
256/* CWMAX_CSR: CWmin for each EDCA AC */
257/* */
258#define WMM_CWMAX_CFG 0x021c
259typedef union _CWMAX_CSR_STRUC {
260 struct {
261 u32 Cwmax0:4; /* for AC_BE */
262 u32 Cwmax1:4; /* for AC_BK */
263 u32 Cwmax2:4; /* for AC_VI */
264 u32 Cwmax3:4; /* for AC_VO */
265 u32 Rsv:16;
266 } field;
267 u32 word;
268} CWMAX_CSR_STRUC, *PCWMAX_CSR_STRUC;
269
270/* */
271/* AC_TXOP_CSR0: AC_BK/AC_BE TXOP register */
272/* */
273#define WMM_TXOP0_CFG 0x0220
274typedef union _AC_TXOP_CSR0_STRUC {
275 struct {
276 u16 Ac0Txop; /* for AC_BK, in unit of 32us */
277 u16 Ac1Txop; /* for AC_BE, in unit of 32us */
278 } field;
279 u32 word;
280} AC_TXOP_CSR0_STRUC, *PAC_TXOP_CSR0_STRUC;
281
282/* */
283/* AC_TXOP_CSR1: AC_VO/AC_VI TXOP register */
284/* */
285#define WMM_TXOP1_CFG 0x0224
286typedef union _AC_TXOP_CSR1_STRUC {
287 struct {
288 u16 Ac2Txop; /* for AC_VI, in unit of 32us */
289 u16 Ac3Txop; /* for AC_VO, in unit of 32us */
290 } field;
291 u32 word;
292} AC_TXOP_CSR1_STRUC, *PAC_TXOP_CSR1_STRUC;
293
294#define RINGREG_DIFF 0x10
295#define GPIO_CTRL_CFG 0x0228 /*MAC_CSR13 */
296#define MCU_CMD_CFG 0x022c
297#define TX_BASE_PTR0 0x0230 /*AC_BK base address */
298#define TX_MAX_CNT0 0x0234
299#define TX_CTX_IDX0 0x0238
300#define TX_DTX_IDX0 0x023c
301#define TX_BASE_PTR1 0x0240 /*AC_BE base address */
302#define TX_MAX_CNT1 0x0244
303#define TX_CTX_IDX1 0x0248
304#define TX_DTX_IDX1 0x024c
305#define TX_BASE_PTR2 0x0250 /*AC_VI base address */
306#define TX_MAX_CNT2 0x0254
307#define TX_CTX_IDX2 0x0258
308#define TX_DTX_IDX2 0x025c
309#define TX_BASE_PTR3 0x0260 /*AC_VO base address */
310#define TX_MAX_CNT3 0x0264
311#define TX_CTX_IDX3 0x0268
312#define TX_DTX_IDX3 0x026c
313#define TX_BASE_PTR4 0x0270 /*HCCA base address */
314#define TX_MAX_CNT4 0x0274
315#define TX_CTX_IDX4 0x0278
316#define TX_DTX_IDX4 0x027c
317#define TX_BASE_PTR5 0x0280 /*MGMT base address */
318#define TX_MAX_CNT5 0x0284
319#define TX_CTX_IDX5 0x0288
320#define TX_DTX_IDX5 0x028c
321#define TX_MGMTMAX_CNT TX_MAX_CNT5
322#define TX_MGMTCTX_IDX TX_CTX_IDX5
323#define TX_MGMTDTX_IDX TX_DTX_IDX5
324#define RX_BASE_PTR 0x0290 /*RX base address */
325#define RX_MAX_CNT 0x0294
326#define RX_CRX_IDX 0x0298
327#define RX_DRX_IDX 0x029c
328
329#define USB_DMA_CFG 0x02a0
330typedef union _USB_DMA_CFG_STRUC {
331 struct {
332 u32 RxBulkAggTOut:8; /*Rx Bulk Aggregation TimeOut in unit of 33ns */
333 u32 RxBulkAggLmt:8; /*Rx Bulk Aggregation Limit in unit of 256 bytes */
334 u32 phyclear:1; /*phy watch dog enable. write 1 */
335 u32 rsv:2;
336 u32 TxClear:1; /*Clear USB DMA TX path */
337 u32 TxopHalt:1; /*Halt TXOP count down when TX buffer is full. */
338 u32 RxBulkAggEn:1; /*Enable Rx Bulk Aggregation */
339 u32 RxBulkEn:1; /*Enable USB DMA Rx */
340 u32 TxBulkEn:1; /*Enable USB DMA Tx */
341 u32 EpoutValid:6; /*OUT endpoint data valid */
342 u32 RxBusy:1; /*USB DMA RX FSM busy */
343 u32 TxBusy:1; /*USB DMA TX FSM busy */
344 } field;
345 u32 word;
346} USB_DMA_CFG_STRUC, *PUSB_DMA_CFG_STRUC;
347
348/* */
349/* 3 PBF registers */
350/* */
351/* */
352/* Most are for debug. Driver doesn't touch PBF register. */
353#define PBF_SYS_CTRL 0x0400
354#define PBF_CFG 0x0408
355#define PBF_MAX_PCNT 0x040C
356#define PBF_CTRL 0x0410
357#define PBF_INT_STA 0x0414
358#define PBF_INT_ENA 0x0418
359#define TXRXQ_PCNT 0x0438
360#define PBF_DBG 0x043c
361#define PBF_CAP_CTRL 0x0440
362
363#ifdef RT30xx
364#ifdef RTMP_EFUSE_SUPPORT
365/* eFuse registers */
366#define EFUSE_CTRL 0x0580
367#define EFUSE_DATA0 0x0590
368#define EFUSE_DATA1 0x0594
369#define EFUSE_DATA2 0x0598
370#define EFUSE_DATA3 0x059c
371#endif /* RTMP_EFUSE_SUPPORT // */
372#endif /* RT30xx // */
373
374#define OSC_CTRL 0x5a4
375#define PCIE_PHY_TX_ATTENUATION_CTRL 0x05C8
376#define LDO_CFG0 0x05d4
377#define GPIO_SWITCH 0x05dc
378
379/* */
380/* 4 MAC registers */
381/* */
382/* */
383/* 4.1 MAC SYSTEM configuration registers (offset:0x1000) */
384/* */
385#define MAC_CSR0 0x1000
386typedef union _ASIC_VER_ID_STRUC {
387 struct {
388 u16 ASICRev; /* reversion : 0 */
389 u16 ASICVer; /* version : 2860 */
390 } field;
391 u32 word;
392} ASIC_VER_ID_STRUC, *PASIC_VER_ID_STRUC;
393#define MAC_SYS_CTRL 0x1004 /*MAC_CSR1 */
394#define MAC_ADDR_DW0 0x1008 /* MAC ADDR DW0 */
395#define MAC_ADDR_DW1 0x100c /* MAC ADDR DW1 */
396/* */
397/* MAC_CSR2: STA MAC register 0 */
398/* */
399typedef union _MAC_DW0_STRUC {
400 struct {
401 u8 Byte0; /* MAC address byte 0 */
402 u8 Byte1; /* MAC address byte 1 */
403 u8 Byte2; /* MAC address byte 2 */
404 u8 Byte3; /* MAC address byte 3 */
405 } field;
406 u32 word;
407} MAC_DW0_STRUC, *PMAC_DW0_STRUC;
408
409/* */
410/* MAC_CSR3: STA MAC register 1 */
411/* */
412typedef union _MAC_DW1_STRUC {
413 struct {
414 u8 Byte4; /* MAC address byte 4 */
415 u8 Byte5; /* MAC address byte 5 */
416 u8 U2MeMask;
417 u8 Rsvd1;
418 } field;
419 u32 word;
420} MAC_DW1_STRUC, *PMAC_DW1_STRUC;
421
422#define MAC_BSSID_DW0 0x1010 /* MAC BSSID DW0 */
423#define MAC_BSSID_DW1 0x1014 /* MAC BSSID DW1 */
424
425/* */
426/* MAC_CSR5: BSSID register 1 */
427/* */
428typedef union _MAC_CSR5_STRUC {
429 struct {
430 u8 Byte4; /* BSSID byte 4 */
431 u8 Byte5; /* BSSID byte 5 */
432 u16 BssIdMask:2; /* 0: one BSSID, 10: 4 BSSID, 01: 2 BSSID , 11: 8BSSID */
433 u16 MBssBcnNum:3;
434 u16 Rsvd:11;
435 } field;
436 u32 word;
437} MAC_CSR5_STRUC, *PMAC_CSR5_STRUC;
438
439#define MAX_LEN_CFG 0x1018 /* rt2860b max 16k bytes. bit12:13 Maximum PSDU length (power factor) 0:2^13, 1:2^14, 2:2^15, 3:2^16 */
440#define BBP_CSR_CFG 0x101c /* */
441/* */
442/* BBP_CSR_CFG: BBP serial control register */
443/* */
444typedef union _BBP_CSR_CFG_STRUC {
445 struct {
446 u32 Value:8; /* Register value to program into BBP */
447 u32 RegNum:8; /* Selected BBP register */
448 u32 fRead:1; /* 0: Write BBP, 1: Read BBP */
449 u32 Busy:1; /* 1: ASIC is busy execute BBP programming. */
450 u32 BBP_PAR_DUR:1; /* 0: 4 MAC clock cycles 1: 8 MAC clock cycles */
451 u32 BBP_RW_MODE:1; /* 0: use serial mode 1:parallel */
452 u32: 12;
453 } field;
454 u32 word;
455} BBP_CSR_CFG_STRUC, *PBBP_CSR_CFG_STRUC;
456#define RF_CSR_CFG0 0x1020
457/* */
458/* RF_CSR_CFG: RF control register */
459/* */
460typedef union _RF_CSR_CFG0_STRUC {
461 struct {
462 u32 RegIdAndContent:24; /* Register value to program into BBP */
463 u32 bitwidth:5; /* Selected BBP register */
464 u32 StandbyMode:1; /* 0: high when stand by 1: low when standby */
465 u32 Sel:1; /* 0:RF_LE0 activate 1:RF_LE1 activate */
466 u32 Busy:1; /* 0: idle 1: 8busy */
467 } field;
468 u32 word;
469} RF_CSR_CFG0_STRUC, *PRF_CSR_CFG0_STRUC;
470#define RF_CSR_CFG1 0x1024
471typedef union _RF_CSR_CFG1_STRUC {
472 struct {
473 u32 RegIdAndContent:24; /* Register value to program into BBP */
474 u32 RFGap:5; /* Gap between BB_CONTROL_RF and RF_LE. 0: 3 system clock cycle (37.5usec) 1: 5 system clock cycle (62.5usec) */
475 u32 rsv:7; /* 0: idle 1: 8busy */
476 } field;
477 u32 word;
478} RF_CSR_CFG1_STRUC, *PRF_CSR_CFG1_STRUC;
479#define RF_CSR_CFG2 0x1028 /* */
480typedef union _RF_CSR_CFG2_STRUC {
481 struct {
482 u32 RegIdAndContent:24; /* Register value to program into BBP */
483 u32 rsv:8; /* 0: idle 1: 8busy */
484 } field;
485 u32 word;
486} RF_CSR_CFG2_STRUC, *PRF_CSR_CFG2_STRUC;
487#define LED_CFG 0x102c /* MAC_CSR14 */
488typedef union _LED_CFG_STRUC {
489 struct {
490 u32 OnPeriod:8; /* blinking on period unit 1ms */
491 u32 OffPeriod:8; /* blinking off period unit 1ms */
492 u32 SlowBlinkPeriod:6; /* slow blinking period. unit:1ms */
493 u32 rsv:2;
494 u32 RLedMode:2; /* red Led Mode 0: off1: blinking upon TX2: periodic slow blinking3: always on */
495 u32 GLedMode:2; /* green Led Mode */
496 u32 YLedMode:2; /* yellow Led Mode */
497 u32 LedPolar:1; /* Led Polarity. 0: active low1: active high */
498 u32: 1;
499 } field;
500 u32 word;
501} LED_CFG_STRUC, *PLED_CFG_STRUC;
502/* */
503/* 4.2 MAC TIMING configuration registers (offset:0x1100) */
504/* */
505#define XIFS_TIME_CFG 0x1100 /* MAC_CSR8 MAC_CSR9 */
506typedef union _IFS_SLOT_CFG_STRUC {
507 struct {
508 u32 CckmSifsTime:8; /* unit 1us. Applied after CCK RX/TX */
509 u32 OfdmSifsTime:8; /* unit 1us. Applied after OFDM RX/TX */
510 u32 OfdmXifsTime:4; /*OFDM SIFS. unit 1us. Applied after OFDM RX when MAC doesn't reference BBP signal BBRXEND */
511 u32 EIFS:9; /* unit 1us */
512 u32 BBRxendEnable:1; /* reference RXEND signal to begin XIFS defer */
513 u32 rsv:2;
514 } field;
515 u32 word;
516} IFS_SLOT_CFG_STRUC, *PIFS_SLOT_CFG_STRUC;
517
518#define BKOFF_SLOT_CFG 0x1104 /* mac_csr9 last 8 bits */
519#define NAV_TIME_CFG 0x1108 /* NAV (MAC_CSR15) */
520#define CH_TIME_CFG 0x110C /* Count as channel busy */
521#define PBF_LIFE_TIMER 0x1110 /*TX/RX MPDU timestamp timer (free run)Unit: 1us */
522#define BCN_TIME_CFG 0x1114 /* TXRX_CSR9 */
523
524#define BCN_OFFSET0 0x042C
525#define BCN_OFFSET1 0x0430
526
527/* */
528/* BCN_TIME_CFG : Synchronization control register */
529/* */
530typedef union _BCN_TIME_CFG_STRUC {
531 struct {
532 u32 BeaconInterval:16; /* in unit of 1/16 TU */
533 u32 bTsfTicking:1; /* Enable TSF auto counting */
534 u32 TsfSyncMode:2; /* Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode */
535 u32 bTBTTEnable:1;
536 u32 bBeaconGen:1; /* Enable beacon generator */
537 u32: 3;
538 u32 TxTimestampCompensate:8;
539 } field;
540 u32 word;
541} BCN_TIME_CFG_STRUC, *PBCN_TIME_CFG_STRUC;
542#define TBTT_SYNC_CFG 0x1118 /* txrx_csr10 */
543#define TSF_TIMER_DW0 0x111C /* Local TSF timer lsb 32 bits. Read-only */
544#define TSF_TIMER_DW1 0x1120 /* msb 32 bits. Read-only. */
545#define TBTT_TIMER 0x1124 /* TImer remains till next TBTT. Read-only. TXRX_CSR14 */
546#define INT_TIMER_CFG 0x1128 /* */
547#define INT_TIMER_EN 0x112c /* GP-timer and pre-tbtt Int enable */
548#define CH_IDLE_STA 0x1130 /* channel idle time */
549#define CH_BUSY_STA 0x1134 /* channle busy time */
550/* */
551/* 4.2 MAC POWER configuration registers (offset:0x1200) */
552/* */
553#define MAC_STATUS_CFG 0x1200 /* old MAC_CSR12 */
554#define PWR_PIN_CFG 0x1204 /* old MAC_CSR12 */
555#define AUTO_WAKEUP_CFG 0x1208 /* old MAC_CSR10 */
556/* */
557/* AUTO_WAKEUP_CFG: Manual power control / status register */
558/* */
559typedef union _AUTO_WAKEUP_STRUC {
560 struct {
561 u32 AutoLeadTime:8;
562 u32 NumofSleepingTbtt:7; /* ForceWake has high privilege than PutToSleep when both set */
563 u32 EnableAutoWakeup:1; /* 0:sleep, 1:awake */
564 u32: 16;
565 } field;
566 u32 word;
567} AUTO_WAKEUP_STRUC, *PAUTO_WAKEUP_STRUC;
568/* */
569/* 4.3 MAC TX configuration registers (offset:0x1300) */
570/* */
571
572#define EDCA_AC0_CFG 0x1300 /*AC_TXOP_CSR0 0x3474 */
573#define EDCA_AC1_CFG 0x1304
574#define EDCA_AC2_CFG 0x1308
575#define EDCA_AC3_CFG 0x130c
576typedef union _EDCA_AC_CFG_STRUC {
577 struct {
578 u32 AcTxop:8; /* in unit of 32us */
579 u32 Aifsn:4; /* # of slot time */
580 u32 Cwmin:4; /* */
581 u32 Cwmax:4; /*unit power of 2 */
582 u32: 12; /* */
583 } field;
584 u32 word;
585} EDCA_AC_CFG_STRUC, *PEDCA_AC_CFG_STRUC;
586
587#define EDCA_TID_AC_MAP 0x1310
588#define TX_PWR_CFG_0 0x1314
589#define TX_PWR_CFG_1 0x1318
590#define TX_PWR_CFG_2 0x131C
591#define TX_PWR_CFG_3 0x1320
592#define TX_PWR_CFG_4 0x1324
593#define TX_PIN_CFG 0x1328
594#define TX_BAND_CFG 0x132c /* 0x1 use upper 20MHz. 0 juse lower 20MHz */
595#define TX_SW_CFG0 0x1330
596#define TX_SW_CFG1 0x1334
597#define TX_SW_CFG2 0x1338
598#define TXOP_THRES_CFG 0x133c
599#define TXOP_CTRL_CFG 0x1340
600#define TX_RTS_CFG 0x1344
601
602typedef union _TX_RTS_CFG_STRUC {
603 struct {
604 u32 AutoRtsRetryLimit:8;
605 u32 RtsThres:16; /* unit:byte */
606 u32 RtsFbkEn:1; /* enable rts rate fallback */
607 u32 rsv:7; /* 1: HT non-STBC control frame enable */
608 } field;
609 u32 word;
610} TX_RTS_CFG_STRUC, *PTX_RTS_CFG_STRUC;
611#define TX_TIMEOUT_CFG 0x1348
612typedef union _TX_TIMEOUT_CFG_STRUC {
613 struct {
614 u32 rsv:4;
615 u32 MpduLifeTime:4; /* expiration time = 2^(9+MPDU LIFE TIME) us */
616 u32 RxAckTimeout:8; /* unit:slot. Used for TX precedure */
617 u32 TxopTimeout:8; /*TXOP timeout value for TXOP truncation. It is recommended that (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT) */
618 u32 rsv2:8; /* 1: HT non-STBC control frame enable */
619 } field;
620 u32 word;
621} TX_TIMEOUT_CFG_STRUC, *PTX_TIMEOUT_CFG_STRUC;
622#define TX_RTY_CFG 0x134c
623typedef union PACKED _TX_RTY_CFG_STRUC {
624 struct {
625 u32 ShortRtyLimit:8; /* short retry limit */
626 u32 LongRtyLimit:8; /* long retry limit */
627 u32 LongRtyThre:12; /* Long retry threshold */
628 u32 NonAggRtyMode:1; /* Non-Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer */
629 u32 AggRtyMode:1; /* Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer */
630 u32 TxautoFBEnable:1; /* Tx retry PHY rate auto fallback enable */
631 u32 rsv:1; /* 1: HT non-STBC control frame enable */
632 } field;
633 u32 word;
634} TX_RTY_CFG_STRUC, *PTX_RTY_CFG_STRUC;
635#define TX_LINK_CFG 0x1350
636typedef union PACKED _TX_LINK_CFG_STRUC {
637 struct PACKED {
638 u32 RemoteMFBLifeTime:8; /*remote MFB life time. unit : 32us */
639 u32 MFBEnable:1; /* TX apply remote MFB 1:enable */
640 u32 RemoteUMFSEnable:1; /* remote unsolicit MFB enable. 0: not apply remote remote unsolicit (MFS=7) */
641 u32 TxMRQEn:1; /* MCS request TX enable */
642 u32 TxRDGEn:1; /* RDG TX enable */
643 u32 TxCFAckEn:1; /* Piggyback CF-ACK enable */
644 u32 rsv:3; /* */
645 u32 RemotMFB:8; /* remote MCS feedback */
646 u32 RemotMFS:8; /*remote MCS feedback sequence number */
647 } field;
648 u32 word;
649} TX_LINK_CFG_STRUC, *PTX_LINK_CFG_STRUC;
650#define HT_FBK_CFG0 0x1354
651typedef union PACKED _HT_FBK_CFG0_STRUC {
652 struct {
653 u32 HTMCS0FBK:4;
654 u32 HTMCS1FBK:4;
655 u32 HTMCS2FBK:4;
656 u32 HTMCS3FBK:4;
657 u32 HTMCS4FBK:4;
658 u32 HTMCS5FBK:4;
659 u32 HTMCS6FBK:4;
660 u32 HTMCS7FBK:4;
661 } field;
662 u32 word;
663} HT_FBK_CFG0_STRUC, *PHT_FBK_CFG0_STRUC;
664#define HT_FBK_CFG1 0x1358
665typedef union _HT_FBK_CFG1_STRUC {
666 struct {
667 u32 HTMCS8FBK:4;
668 u32 HTMCS9FBK:4;
669 u32 HTMCS10FBK:4;
670 u32 HTMCS11FBK:4;
671 u32 HTMCS12FBK:4;
672 u32 HTMCS13FBK:4;
673 u32 HTMCS14FBK:4;
674 u32 HTMCS15FBK:4;
675 } field;
676 u32 word;
677} HT_FBK_CFG1_STRUC, *PHT_FBK_CFG1_STRUC;
678#define LG_FBK_CFG0 0x135c
679typedef union _LG_FBK_CFG0_STRUC {
680 struct {
681 u32 OFDMMCS0FBK:4; /*initial value is 0 */
682 u32 OFDMMCS1FBK:4; /*initial value is 0 */
683 u32 OFDMMCS2FBK:4; /*initial value is 1 */
684 u32 OFDMMCS3FBK:4; /*initial value is 2 */
685 u32 OFDMMCS4FBK:4; /*initial value is 3 */
686 u32 OFDMMCS5FBK:4; /*initial value is 4 */
687 u32 OFDMMCS6FBK:4; /*initial value is 5 */
688 u32 OFDMMCS7FBK:4; /*initial value is 6 */
689 } field;
690 u32 word;
691} LG_FBK_CFG0_STRUC, *PLG_FBK_CFG0_STRUC;
692#define LG_FBK_CFG1 0x1360
693typedef union _LG_FBK_CFG1_STRUC {
694 struct {
695 u32 CCKMCS0FBK:4; /*initial value is 0 */
696 u32 CCKMCS1FBK:4; /*initial value is 0 */
697 u32 CCKMCS2FBK:4; /*initial value is 1 */
698 u32 CCKMCS3FBK:4; /*initial value is 2 */
699 u32 rsv:16;
700 } field;
701 u32 word;
702} LG_FBK_CFG1_STRUC, *PLG_FBK_CFG1_STRUC;
703
704/*======================================================= */
705/*================ Protection Paramater================================ */
706/*======================================================= */
707#define CCK_PROT_CFG 0x1364 /*CCK Protection */
708#define ASIC_SHORTNAV 1
709#define ASIC_longNAV 2
710#define ASIC_RTS 1
711#define ASIC_CTS 2
712typedef union _PROT_CFG_STRUC {
713 struct {
714 u32 ProtectRate:16; /*Protection control frame rate for CCK TX(RTS/CTS/CFEnd). */
715 u32 ProtectCtrl:2; /*Protection control frame type for CCK TX. 1:RTS/CTS, 2:CTS-to-self, 0:None, 3:rsv */
716 u32 ProtectNav:2; /*TXOP protection type for CCK TX. 0:None, 1:ShortNAVprotect, 2:LongNAVProtect, 3:rsv */
717 u32 TxopAllowCck:1; /*CCK TXOP allowance.0:disallow. */
718 u32 TxopAllowOfdm:1; /*CCK TXOP allowance.0:disallow. */
719 u32 TxopAllowMM20:1; /*CCK TXOP allowance. 0:disallow. */
720 u32 TxopAllowMM40:1; /*CCK TXOP allowance.0:disallow. */
721 u32 TxopAllowGF20:1; /*CCK TXOP allowance.0:disallow. */
722 u32 TxopAllowGF40:1; /*CCK TXOP allowance.0:disallow. */
723 u32 RTSThEn:1; /*RTS threshold enable on CCK TX */
724 u32 rsv:5;
725 } field;
726 u32 word;
727} PROT_CFG_STRUC, *PPROT_CFG_STRUC;
728
729#define OFDM_PROT_CFG 0x1368 /*OFDM Protection */
730#define MM20_PROT_CFG 0x136C /*MM20 Protection */
731#define MM40_PROT_CFG 0x1370 /*MM40 Protection */
732#define GF20_PROT_CFG 0x1374 /*GF20 Protection */
733#define GF40_PROT_CFG 0x1378 /*GR40 Protection */
734#define EXP_CTS_TIME 0x137C /* */
735#define EXP_ACK_TIME 0x1380 /* */
736
737/* */
738/* 4.4 MAC RX configuration registers (offset:0x1400) */
739/* */
740#define RX_FILTR_CFG 0x1400 /*TXRX_CSR0 */
741#define AUTO_RSP_CFG 0x1404 /*TXRX_CSR4 */
742/* */
743/* TXRX_CSR4: Auto-Responder/ */
744/* */
745typedef union _AUTO_RSP_CFG_STRUC {
746 struct {
747 u32 AutoResponderEnable:1;
748 u32 BACAckPolicyEnable:1; /* 0:long, 1:short preamble */
749 u32 CTS40MMode:1; /* Response CTS 40MHz duplicate mode */
750 u32 CTS40MRef:1; /* Response CTS 40MHz duplicate mode */
751 u32 AutoResponderPreamble:1; /* 0:long, 1:short preamble */
752 u32 rsv:1; /* Power bit value in conrtrol frame */
753 u32 DualCTSEn:1; /* Power bit value in conrtrol frame */
754 u32 AckCtsPsmBit:1; /* Power bit value in conrtrol frame */
755 u32: 24;
756 } field;
757 u32 word;
758} AUTO_RSP_CFG_STRUC, *PAUTO_RSP_CFG_STRUC;
759
760#define LEGACY_BASIC_RATE 0x1408 /* TXRX_CSR5 0x3054 */
761#define HT_BASIC_RATE 0x140c
762#define HT_CTRL_CFG 0x1410
763#define SIFS_COST_CFG 0x1414
764#define RX_PARSER_CFG 0x1418 /*Set NAV for all received frames */
765
766/* */
767/* 4.5 MAC Security configuration (offset:0x1500) */
768/* */
769#define TX_SEC_CNT0 0x1500 /* */
770#define RX_SEC_CNT0 0x1504 /* */
771#define CCMP_FC_MUTE 0x1508 /* */
772/* */
773/* 4.6 HCCA/PSMP (offset:0x1600) */
774/* */
775#define TXOP_HLDR_ADDR0 0x1600
776#define TXOP_HLDR_ADDR1 0x1604
777#define TXOP_HLDR_ET 0x1608
778#define QOS_CFPOLL_RA_DW0 0x160c
779#define QOS_CFPOLL_A1_DW1 0x1610
780#define QOS_CFPOLL_QC 0x1614
781/* */
782/* 4.7 MAC Statistis registers (offset:0x1700) */
783/* */
784#define RX_STA_CNT0 0x1700 /* */
785#define RX_STA_CNT1 0x1704 /* */
786#define RX_STA_CNT2 0x1708 /* */
787
788/* */
789/* RX_STA_CNT0_STRUC: RX PLCP error count & RX CRC error count */
790/* */
791typedef union _RX_STA_CNT0_STRUC {
792 struct {
793 u16 CrcErr;
794 u16 PhyErr;
795 } field;
796 u32 word;
797} RX_STA_CNT0_STRUC, *PRX_STA_CNT0_STRUC;
798
799/* */
800/* RX_STA_CNT1_STRUC: RX False CCA count & RX long frame count */
801/* */
802typedef union _RX_STA_CNT1_STRUC {
803 struct {
804 u16 FalseCca;
805 u16 PlcpErr;
806 } field;
807 u32 word;
808} RX_STA_CNT1_STRUC, *PRX_STA_CNT1_STRUC;
809
810/* */
811/* RX_STA_CNT2_STRUC: */
812/* */
813typedef union _RX_STA_CNT2_STRUC {
814 struct {
815 u16 RxDupliCount;
816 u16 RxFifoOverflowCount;
817 } field;
818 u32 word;
819} RX_STA_CNT2_STRUC, *PRX_STA_CNT2_STRUC;
820#define TX_STA_CNT0 0x170C /* */
821/* */
822/* STA_CSR3: TX Beacon count */
823/* */
824typedef union _TX_STA_CNT0_STRUC {
825 struct {
826 u16 TxFailCount;
827 u16 TxBeaconCount;
828 } field;
829 u32 word;
830} TX_STA_CNT0_STRUC, *PTX_STA_CNT0_STRUC;
831#define TX_STA_CNT1 0x1710 /* */
832/* */
833/* TX_STA_CNT1: TX tx count */
834/* */
835typedef union _TX_STA_CNT1_STRUC {
836 struct {
837 u16 TxSuccess;
838 u16 TxRetransmit;
839 } field;
840 u32 word;
841} TX_STA_CNT1_STRUC, *PTX_STA_CNT1_STRUC;
842#define TX_STA_CNT2 0x1714 /* */
843/* */
844/* TX_STA_CNT2: TX tx count */
845/* */
846typedef union _TX_STA_CNT2_STRUC {
847 struct {
848 u16 TxZeroLenCount;
849 u16 TxUnderFlowCount;
850 } field;
851 u32 word;
852} TX_STA_CNT2_STRUC, *PTX_STA_CNT2_STRUC;
853#define TX_STA_FIFO 0x1718 /* */
854/* */
855/* TX_STA_FIFO_STRUC: TX Result for specific PID status fifo register */
856/* */
857typedef union PACKED _TX_STA_FIFO_STRUC {
858 struct {
859 u32 bValid:1; /* 1:This register contains a valid TX result */
860 u32 PidType:4;
861 u32 TxSuccess:1; /* Tx No retry success */
862 u32 TxAggre:1; /* Tx Retry Success */
863 u32 TxAckRequired:1; /* Tx fail */
864 u32 wcid:8; /*wireless client index */
865/* u32 SuccessRate:16; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16. */
866 u32 SuccessRate:13; /*include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16. */
867 u32 TxBF:1;
868 u32 Reserve:2;
869 } field;
870 u32 word;
871} TX_STA_FIFO_STRUC, *PTX_STA_FIFO_STRUC;
872/* Debug counter */
873#define TX_AGG_CNT 0x171c
874typedef union _TX_AGG_CNT_STRUC {
875 struct {
876 u16 NonAggTxCount;
877 u16 AggTxCount;
878 } field;
879 u32 word;
880} TX_AGG_CNT_STRUC, *PTX_AGG_CNT_STRUC;
881/* Debug counter */
882#define TX_AGG_CNT0 0x1720
883typedef union _TX_AGG_CNT0_STRUC {
884 struct {
885 u16 AggSize1Count;
886 u16 AggSize2Count;
887 } field;
888 u32 word;
889} TX_AGG_CNT0_STRUC, *PTX_AGG_CNT0_STRUC;
890/* Debug counter */
891#define TX_AGG_CNT1 0x1724
892typedef union _TX_AGG_CNT1_STRUC {
893 struct {
894 u16 AggSize3Count;
895 u16 AggSize4Count;
896 } field;
897 u32 word;
898} TX_AGG_CNT1_STRUC, *PTX_AGG_CNT1_STRUC;
899#define TX_AGG_CNT2 0x1728
900typedef union _TX_AGG_CNT2_STRUC {
901 struct {
902 u16 AggSize5Count;
903 u16 AggSize6Count;
904 } field;
905 u32 word;
906} TX_AGG_CNT2_STRUC, *PTX_AGG_CNT2_STRUC;
907/* Debug counter */
908#define TX_AGG_CNT3 0x172c
909typedef union _TX_AGG_CNT3_STRUC {
910 struct {
911 u16 AggSize7Count;
912 u16 AggSize8Count;
913 } field;
914 u32 word;
915} TX_AGG_CNT3_STRUC, *PTX_AGG_CNT3_STRUC;
916/* Debug counter */
917#define TX_AGG_CNT4 0x1730
918typedef union _TX_AGG_CNT4_STRUC {
919 struct {
920 u16 AggSize9Count;
921 u16 AggSize10Count;
922 } field;
923 u32 word;
924} TX_AGG_CNT4_STRUC, *PTX_AGG_CNT4_STRUC;
925#define TX_AGG_CNT5 0x1734
926typedef union _TX_AGG_CNT5_STRUC {
927 struct {
928 u16 AggSize11Count;
929 u16 AggSize12Count;
930 } field;
931 u32 word;
932} TX_AGG_CNT5_STRUC, *PTX_AGG_CNT5_STRUC;
933#define TX_AGG_CNT6 0x1738
934typedef union _TX_AGG_CNT6_STRUC {
935 struct {
936 u16 AggSize13Count;
937 u16 AggSize14Count;
938 } field;
939 u32 word;
940} TX_AGG_CNT6_STRUC, *PTX_AGG_CNT6_STRUC;
941#define TX_AGG_CNT7 0x173c
942typedef union _TX_AGG_CNT7_STRUC {
943 struct {
944 u16 AggSize15Count;
945 u16 AggSize16Count;
946 } field;
947 u32 word;
948} TX_AGG_CNT7_STRUC, *PTX_AGG_CNT7_STRUC;
949#define MPDU_DENSITY_CNT 0x1740
950typedef union _MPDU_DEN_CNT_STRUC {
951 struct {
952 u16 TXZeroDelCount; /*TX zero length delimiter count */
953 u16 RXZeroDelCount; /*RX zero length delimiter count */
954 } field;
955 u32 word;
956} MPDU_DEN_CNT_STRUC, *PMPDU_DEN_CNT_STRUC;
957/* */
958/* TXRX control registers - base address 0x3000 */
959/* */
960/* rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first.. */
961#define TXRX_CSR1 0x77d0
962
963/* */
964/* Security key table memory, base address = 0x1000 */
965/* */
966#define MAC_WCID_BASE 0x1800 /*8-bytes(use only 6-bytes) * 256 entry = */
967#define HW_WCID_ENTRY_SIZE 8
968#define PAIRWISE_KEY_TABLE_BASE 0x4000 /* 32-byte * 256-entry = -byte */
969#define HW_KEY_ENTRY_SIZE 0x20
970#define PAIRWISE_IVEIV_TABLE_BASE 0x6000 /* 8-byte * 256-entry = -byte */
971#define MAC_IVEIV_TABLE_BASE 0x6000 /* 8-byte * 256-entry = -byte */
972#define HW_IVEIV_ENTRY_SIZE 8
973#define MAC_WCID_ATTRIBUTE_BASE 0x6800 /* 4-byte * 256-entry = -byte */
974#define HW_WCID_ATTRI_SIZE 4
975#define WCID_RESERVED 0x6bfc
976#define SHARED_KEY_TABLE_BASE 0x6c00 /* 32-byte * 16-entry = 512-byte */
977#define SHARED_KEY_MODE_BASE 0x7000 /* 32-byte * 16-entry = 512-byte */
978#define HW_SHARED_KEY_MODE_SIZE 4
979#define SHAREDKEYTABLE 0
980#define PAIRWISEKEYTABLE 1
981
982typedef union _SHAREDKEY_MODE_STRUC {
983 struct {
984 u32 Bss0Key0CipherAlg:3;
985 u32: 1;
986 u32 Bss0Key1CipherAlg:3;
987 u32: 1;
988 u32 Bss0Key2CipherAlg:3;
989 u32: 1;
990 u32 Bss0Key3CipherAlg:3;
991 u32: 1;
992 u32 Bss1Key0CipherAlg:3;
993 u32: 1;
994 u32 Bss1Key1CipherAlg:3;
995 u32: 1;
996 u32 Bss1Key2CipherAlg:3;
997 u32: 1;
998 u32 Bss1Key3CipherAlg:3;
999 u32: 1;
1000 } field;
1001 u32 word;
1002} SHAREDKEY_MODE_STRUC, *PSHAREDKEY_MODE_STRUC;
1003
1004/* 8-byte per entry, 64-entry for pairwise key table */
1005struct rt_hw_wcid_entry {
1006 u8 Address[6];
1007 u8 Rsv[2];
1008};
1009
1010/* ================================================================================= */
1011/* WCID format */
1012/* ================================================================================= */
1013/*7.1 WCID ENTRY format : 8bytes */
1014struct rt_wcid_entry {
1015 u8 RXBABitmap7; /* bit0 for TID8, bit7 for TID 15 */
1016 u8 RXBABitmap0; /* bit0 for TID0, bit7 for TID 7 */
1017 u8 MAC[6]; /* 0 for shared key table. 1 for pairwise key table */
1018};
1019
1020/*8.1.1 SECURITY KEY format : 8DW */
1021/* 32-byte per entry, total 16-entry for shared key table, 64-entry for pairwise key table */
1022struct rt_hw_key_entry {
1023 u8 Key[16];
1024 u8 TxMic[8];
1025 u8 RxMic[8];
1026};
1027
1028/*8.1.2 IV/EIV format : 2DW */
1029
1030/*8.1.3 RX attribute entry format : 1DW */
1031struct rt_mac_attribute {
1032 u32 KeyTab:1; /* 0 for shared key table. 1 for pairwise key table */
1033 u32 PairKeyMode:3;
1034 u32 BSSIDIdx:3; /*multipleBSS index for the WCID */
1035 u32 RXWIUDF:3;
1036 u32 rsv:22;
1037};
1038
1039/* ================================================================================= */
1040/* HOST-MCU communication data structure */
1041/* ================================================================================= */
1042
1043/* */
1044/* H2M_MAILBOX_CSR: Host-to-MCU Mailbox */
1045/* */
1046typedef union _H2M_MAILBOX_STRUC {
1047 struct {
1048 u32 LowByte:8;
1049 u32 HighByte:8;
1050 u32 CmdToken:8;
1051 u32 Owner:8;
1052 } field;
1053 u32 word;
1054} H2M_MAILBOX_STRUC, *PH2M_MAILBOX_STRUC;
1055
1056/* */
1057/* M2H_CMD_DONE_CSR: MCU-to-Host command complete indication */
1058/* */
1059typedef union _M2H_CMD_DONE_STRUC {
1060 struct {
1061 u32 CmdToken0;
1062 u32 CmdToken1;
1063 u32 CmdToken2;
1064 u32 CmdToken3;
1065 } field;
1066 u32 word;
1067} M2H_CMD_DONE_STRUC, *PM2H_CMD_DONE_STRUC;
1068
1069/*NAV_TIME_CFG :NAV */
1070typedef union _NAV_TIME_CFG_STRUC {
1071 struct {
1072 u8 Sifs; /* in unit of 1-us */
1073 u8 SlotTime; /* in unit of 1-us */
1074 u16 Eifs:9; /* in unit of 1-us */
1075 u16 ZeroSifs:1; /* Applied zero SIFS timer after OFDM RX 0: disable */
1076 u16 rsv:6;
1077 } field;
1078 u32 word;
1079} NAV_TIME_CFG_STRUC, *PNAV_TIME_CFG_STRUC;
1080
1081/* */
1082/* RX_FILTR_CFG: /RX configuration register */
1083/* */
1084typedef union _RX_FILTR_CFG_STRUC {
1085 struct {
1086 u32 DropCRCErr:1; /* Drop CRC error */
1087 u32 DropPhyErr:1; /* Drop physical error */
1088 u32 DropNotToMe:1; /* Drop not to me unicast frame */
1089 u32 DropNotMyBSSID:1; /* Drop fram ToDs bit is true */
1090
1091 u32 DropVerErr:1; /* Drop version error frame */
1092 u32 DropMcast:1; /* Drop multicast frames */
1093 u32 DropBcast:1; /* Drop broadcast frames */
1094 u32 DropDuplicate:1; /* Drop duplicate frame */
1095
1096 u32 DropCFEndAck:1; /* Drop Ps-Poll */
1097 u32 DropCFEnd:1; /* Drop Ps-Poll */
1098 u32 DropAck:1; /* Drop Ps-Poll */
1099 u32 DropCts:1; /* Drop Ps-Poll */
1100
1101 u32 DropRts:1; /* Drop Ps-Poll */
1102 u32 DropPsPoll:1; /* Drop Ps-Poll */
1103 u32 DropBA:1; /* */
1104 u32 DropBAR:1; /* */
1105
1106 u32 DropRsvCntlType:1;
1107 u32: 15;
1108 } field;
1109 u32 word;
1110} RX_FILTR_CFG_STRUC, *PRX_FILTR_CFG_STRUC;
1111
1112/* */
1113/* PHY_CSR4: RF serial control register */
1114/* */
1115typedef union _PHY_CSR4_STRUC {
1116 struct {
1117 u32 RFRegValue:24; /* Register value (include register id) serial out to RF/IF chip. */
1118 u32 NumberOfBits:5; /* Number of bits used in RFRegValue (I:20, RFMD:22) */
1119 u32 IFSelect:1; /* 1: select IF to program, 0: select RF to program */
1120 u32 PLL_LD:1; /* RF PLL_LD status */
1121 u32 Busy:1; /* 1: ASIC is busy execute RF programming. */
1122 } field;
1123 u32 word;
1124} PHY_CSR4_STRUC, *PPHY_CSR4_STRUC;
1125
1126/* */
1127/* SEC_CSR5: shared key table security mode register */
1128/* */
1129typedef union _SEC_CSR5_STRUC {
1130 struct {
1131 u32 Bss2Key0CipherAlg:3;
1132 u32: 1;
1133 u32 Bss2Key1CipherAlg:3;
1134 u32: 1;
1135 u32 Bss2Key2CipherAlg:3;
1136 u32: 1;
1137 u32 Bss2Key3CipherAlg:3;
1138 u32: 1;
1139 u32 Bss3Key0CipherAlg:3;
1140 u32: 1;
1141 u32 Bss3Key1CipherAlg:3;
1142 u32: 1;
1143 u32 Bss3Key2CipherAlg:3;
1144 u32: 1;
1145 u32 Bss3Key3CipherAlg:3;
1146 u32: 1;
1147 } field;
1148 u32 word;
1149} SEC_CSR5_STRUC, *PSEC_CSR5_STRUC;
1150
1151/* */
1152/* HOST_CMD_CSR: For HOST to interrupt embedded processor */
1153/* */
1154typedef union _HOST_CMD_CSR_STRUC {
1155 struct {
1156 u32 HostCommand:8;
1157 u32 Rsv:24;
1158 } field;
1159 u32 word;
1160} HOST_CMD_CSR_STRUC, *PHOST_CMD_CSR_STRUC;
1161
1162/* */
1163/* AIFSN_CSR: AIFSN for each EDCA AC */
1164/* */
1165
1166/* */
1167/* E2PROM_CSR: EEPROM control register */
1168/* */
1169typedef union _E2PROM_CSR_STRUC {
1170 struct {
1171 u32 Reload:1; /* Reload EEPROM content, write one to reload, self-cleared. */
1172 u32 EepromSK:1;
1173 u32 EepromCS:1;
1174 u32 EepromDI:1;
1175 u32 EepromDO:1;
1176 u32 Type:1; /* 1: 93C46, 0:93C66 */
1177 u32 LoadStatus:1; /* 1:loading, 0:done */
1178 u32 Rsvd:25;
1179 } field;
1180 u32 word;
1181} E2PROM_CSR_STRUC, *PE2PROM_CSR_STRUC;
1182
1183/* */
1184/* QOS_CSR0: TXOP holder address0 register */
1185/* */
1186typedef union _QOS_CSR0_STRUC {
1187 struct {
1188 u8 Byte0; /* MAC address byte 0 */
1189 u8 Byte1; /* MAC address byte 1 */
1190 u8 Byte2; /* MAC address byte 2 */
1191 u8 Byte3; /* MAC address byte 3 */
1192 } field;
1193 u32 word;
1194} QOS_CSR0_STRUC, *PQOS_CSR0_STRUC;
1195
1196/* */
1197/* QOS_CSR1: TXOP holder address1 register */
1198/* */
1199typedef union _QOS_CSR1_STRUC {
1200 struct {
1201 u8 Byte4; /* MAC address byte 4 */
1202 u8 Byte5; /* MAC address byte 5 */
1203 u8 Rsvd0;
1204 u8 Rsvd1;
1205 } field;
1206 u32 word;
1207} QOS_CSR1_STRUC, *PQOS_CSR1_STRUC;
1208
1209#define RF_CSR_CFG 0x500
1210typedef union _RF_CSR_CFG_STRUC {
1211 struct {
1212 u32 RF_CSR_DATA:8; /* DATA */
1213 u32 TESTCSR_RFACC_REGNUM:5; /* RF register ID */
1214 u32 Rsvd2:3; /* Reserved */
1215 u32 RF_CSR_WR:1; /* 0: read 1: write */
1216 u32 RF_CSR_KICK:1; /* kick RF register read/write */
1217 u32 Rsvd1:14; /* Reserved */
1218 } field;
1219 u32 word;
1220} RF_CSR_CFG_STRUC, *PRF_CSR_CFG_STRUC;
1221
1222/* */
1223/* Other on-chip shared memory space, base = 0x2000 */
1224/* */
1225
1226/* CIS space - base address = 0x2000 */
1227#define HW_CIS_BASE 0x2000
1228
1229/* Carrier-sense CTS frame base address. It's where mac stores carrier-sense frame for carrier-sense function. */
1230#define HW_CS_CTS_BASE 0x7700
1231/* DFS CTS frame base address. It's where mac stores CTS frame for DFS. */
1232#define HW_DFS_CTS_BASE 0x7780
1233#define HW_CTS_FRAME_SIZE 0x80
1234
1235/* 2004-11-08 john - since NULL frame won't be that long (256 byte). We steal 16 tail bytes */
1236/* to save debugging settings */
1237#define HW_DEBUG_SETTING_BASE 0x77f0 /* 0x77f0~0x77ff total 16 bytes */
1238#define HW_DEBUG_SETTING_BASE2 0x7770 /* 0x77f0~0x77ff total 16 bytes */
1239
1240/* In order to support maximum 8 MBSS and its maximum length is 512 for each beacon */
1241/* Three section discontinue memory segments will be used. */
1242/* 1. The original region for BCN 0~3 */
1243/* 2. Extract memory from FCE table for BCN 4~5 */
1244/* 3. Extract memory from Pair-wise key table for BCN 6~7 */
1245/* It occupied those memory of wcid 238~253 for BCN 6 */
1246/* and wcid 222~237 for BCN 7 */
1247#define HW_BEACON_MAX_SIZE 0x1000 /* unit: byte */
1248#define HW_BEACON_BASE0 0x7800
1249#define HW_BEACON_BASE1 0x7A00
1250#define HW_BEACON_BASE2 0x7C00
1251#define HW_BEACON_BASE3 0x7E00
1252#define HW_BEACON_BASE4 0x7200
1253#define HW_BEACON_BASE5 0x7400
1254#define HW_BEACON_BASE6 0x5DC0
1255#define HW_BEACON_BASE7 0x5BC0
1256
1257#define HW_BEACON_MAX_COUNT 8
1258#define HW_BEACON_OFFSET 0x0200
1259#define HW_BEACON_CONTENT_LEN (HW_BEACON_OFFSET - TXWI_SIZE)
1260
1261/* HOST-MCU shared memory - base address = 0x2100 */
1262#define HOST_CMD_CSR 0x404
1263#define H2M_MAILBOX_CSR 0x7010
1264#define H2M_MAILBOX_CID 0x7014
1265#define H2M_MAILBOX_STATUS 0x701c
1266#define H2M_INT_SRC 0x7024
1267#define H2M_BBP_AGENT 0x7028
1268#define M2H_CMD_DONE_CSR 0x000c
1269#define MCU_TXOP_ARRAY_BASE 0x000c /* TODO: to be provided by Albert */
1270#define MCU_TXOP_ENTRY_SIZE 32 /* TODO: to be provided by Albert */
1271#define MAX_NUM_OF_TXOP_ENTRY 16 /* TODO: must be same with 8051 firmware */
1272#define MCU_MBOX_VERSION 0x01 /* TODO: to be confirmed by Albert */
1273#define MCU_MBOX_VERSION_OFFSET 5 /* TODO: to be provided by Albert */
1274
1275/* */
1276/* Host DMA registers - base address 0x200 . TX0-3=EDCAQid0-3, TX4=HCCA, TX5=MGMT, */
1277/* */
1278/* */
1279/* DMA RING DESCRIPTOR */
1280/* */
1281#define E2PROM_CSR 0x0004
1282#define IO_CNTL_CSR 0x77d0
1283
1284/* ================================================================ */
1285/* Tx / Rx / Mgmt ring descriptor definition */
1286/* ================================================================ */
1287
1288/* the following PID values are used to mark outgoing frame type in TXD->PID so that */
1289/* proper TX statistics can be collected based on these categories */
1290/* b3-2 of PID field - */
1291#define PID_MGMT 0x05
1292#define PID_BEACON 0x0c
1293#define PID_DATA_NORMALUCAST 0x02
1294#define PID_DATA_AMPDU 0x04
1295#define PID_DATA_NO_ACK 0x08
1296#define PID_DATA_NOT_NORM_ACK 0x03
1297/* value domain of pTxD->HostQId (4-bit: 0~15) */
1298#define QID_AC_BK 1 /* meet ACI definition in 802.11e */
1299#define QID_AC_BE 0 /* meet ACI definition in 802.11e */
1300#define QID_AC_VI 2
1301#define QID_AC_VO 3
1302#define QID_HCCA 4
1303#define NUM_OF_TX_RING 4
1304#define QID_MGMT 13
1305#define QID_RX 14
1306#define QID_OTHER 15
1307
1308#endif /* __RTMP_MAC_H__ // */
diff --git a/drivers/staging/rt2860/chip/rtmp_phy.h b/drivers/staging/rt2860/chip/rtmp_phy.h
deleted file mode 100644
index a52221f1294..00000000000
--- a/drivers/staging/rt2860/chip/rtmp_phy.h
+++ /dev/null
@@ -1,516 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_phy.h
29
30 Abstract:
31 Ralink Wireless Chip PHY(BBP/RF) related definition & structures
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#ifndef __RTMP_PHY_H__
39#define __RTMP_PHY_H__
40
41/*
42 RF sections
43*/
44#define RF_R00 0
45#define RF_R01 1
46#define RF_R02 2
47#define RF_R03 3
48#define RF_R04 4
49#define RF_R05 5
50#define RF_R06 6
51#define RF_R07 7
52#define RF_R08 8
53#define RF_R09 9
54#define RF_R10 10
55#define RF_R11 11
56#define RF_R12 12
57#define RF_R13 13
58#define RF_R14 14
59#define RF_R15 15
60#define RF_R16 16
61#define RF_R17 17
62#define RF_R18 18
63#define RF_R19 19
64#define RF_R20 20
65#define RF_R21 21
66#define RF_R22 22
67#define RF_R23 23
68#define RF_R24 24
69#define RF_R25 25
70#define RF_R26 26
71#define RF_R27 27
72#define RF_R28 28
73#define RF_R29 29
74#define RF_R30 30
75#define RF_R31 31
76
77/* value domain of pAd->RfIcType */
78#define RFIC_2820 1 /* 2.4G 2T3R */
79#define RFIC_2850 2 /* 2.4G/5G 2T3R */
80#define RFIC_2720 3 /* 2.4G 1T2R */
81#define RFIC_2750 4 /* 2.4G/5G 1T2R */
82#define RFIC_3020 5 /* 2.4G 1T1R */
83#define RFIC_2020 6 /* 2.4G B/G */
84#define RFIC_3021 7 /* 2.4G 1T2R */
85#define RFIC_3022 8 /* 2.4G 2T2R */
86#define RFIC_3052 9 /* 2.4G/5G 2T2R */
87
88/*
89 BBP sections
90*/
91#define BBP_R0 0 /* version */
92#define BBP_R1 1 /* TSSI */
93#define BBP_R2 2 /* TX configure */
94#define BBP_R3 3
95#define BBP_R4 4
96#define BBP_R5 5
97#define BBP_R6 6
98#define BBP_R14 14 /* RX configure */
99#define BBP_R16 16
100#define BBP_R17 17 /* RX sensibility */
101#define BBP_R18 18
102#define BBP_R21 21
103#define BBP_R22 22
104#define BBP_R24 24
105#define BBP_R25 25
106#define BBP_R26 26
107#define BBP_R27 27
108#define BBP_R31 31
109#define BBP_R49 49 /*TSSI */
110#define BBP_R50 50
111#define BBP_R51 51
112#define BBP_R52 52
113#define BBP_R55 55
114#define BBP_R62 62 /* Rx SQ0 Threshold HIGH */
115#define BBP_R63 63
116#define BBP_R64 64
117#define BBP_R65 65
118#define BBP_R66 66
119#define BBP_R67 67
120#define BBP_R68 68
121#define BBP_R69 69
122#define BBP_R70 70 /* Rx AGC SQ CCK Xcorr threshold */
123#define BBP_R73 73
124#define BBP_R75 75
125#define BBP_R77 77
126#define BBP_R78 78
127#define BBP_R79 79
128#define BBP_R80 80
129#define BBP_R81 81
130#define BBP_R82 82
131#define BBP_R83 83
132#define BBP_R84 84
133#define BBP_R86 86
134#define BBP_R91 91
135#define BBP_R92 92
136#define BBP_R94 94 /* Tx Gain Control */
137#define BBP_R103 103
138#define BBP_R105 105
139#define BBP_R106 106
140#define BBP_R113 113
141#define BBP_R114 114
142#define BBP_R115 115
143#define BBP_R116 116
144#define BBP_R117 117
145#define BBP_R118 118
146#define BBP_R119 119
147#define BBP_R120 120
148#define BBP_R121 121
149#define BBP_R122 122
150#define BBP_R123 123
151#ifdef RT30xx
152#define BBP_R138 138 /* add by johnli, RF power sequence setup, ADC dynamic on/off control */
153#endif /* RT30xx // */
154
155#define BBPR94_DEFAULT 0x06 /* Add 1 value will gain 1db */
156
157/* */
158/* BBP & RF are using indirect access. Before write any value into it. */
159/* We have to make sure there is no outstanding command pending via checking busy bit. */
160/* */
161#define MAX_BUSY_COUNT 100 /* Number of retry before failing access BBP & RF indirect register */
162
163/*#define PHY_TR_SWITCH_TIME 5 // usec */
164
165/*#define BBP_R17_LOW_SENSIBILITY 0x50 */
166/*#define BBP_R17_MID_SENSIBILITY 0x41 */
167/*#define BBP_R17_DYNAMIC_UP_BOUND 0x40 */
168
169#define RSSI_FOR_VERY_LOW_SENSIBILITY -35
170#define RSSI_FOR_LOW_SENSIBILITY -58
171#define RSSI_FOR_MID_LOW_SENSIBILITY -80
172#define RSSI_FOR_MID_SENSIBILITY -90
173
174/*****************************************************************************
175 RF register Read/Write marco definition
176 *****************************************************************************/
177#ifdef RTMP_MAC_PCI
178#define RTMP_RF_IO_WRITE32(_A, _V) \
179{ \
180 if ((_A)->bPCIclkOff == FALSE) { \
181 PHY_CSR4_STRUC _value; \
182 unsigned long _busyCnt = 0; \
183 \
184 do { \
185 RTMP_IO_READ32((_A), RF_CSR_CFG0, &_value.word); \
186 if (_value.field.Busy == IDLE) \
187 break; \
188 _busyCnt++; \
189 } while (_busyCnt < MAX_BUSY_COUNT); \
190 if (_busyCnt < MAX_BUSY_COUNT) { \
191 RTMP_IO_WRITE32((_A), RF_CSR_CFG0, (_V)); \
192 } \
193 } \
194}
195#endif /* RTMP_MAC_PCI // */
196#ifdef RTMP_MAC_USB
197#define RTMP_RF_IO_WRITE32(_A, _V) RTUSBWriteRFRegister(_A, _V)
198#endif /* RTMP_MAC_USB // */
199
200#ifdef RT30xx
201#define RTMP_RF_IO_READ8_BY_REG_ID(_A, _I, _pV) RT30xxReadRFRegister(_A, _I, _pV)
202#define RTMP_RF_IO_WRITE8_BY_REG_ID(_A, _I, _V) RT30xxWriteRFRegister(_A, _I, _V)
203#endif /* RT30xx // */
204
205/*****************************************************************************
206 BBP register Read/Write marco definitions.
207 we read/write the bbp value by register's ID.
208 Generate PER to test BA
209 *****************************************************************************/
210#ifdef RTMP_MAC_PCI
211/*
212 basic marco for BBP read operation.
213 _pAd: the data structure pointer of struct rt_rtmp_adapter
214 _bbpID : the bbp register ID
215 _pV: data pointer used to save the value of queried bbp register.
216 _bViaMCU: if we need access the bbp via the MCU.
217*/
218#define RTMP_BBP_IO_READ8(_pAd, _bbpID, _pV, _bViaMCU) \
219 do { \
220 BBP_CSR_CFG_STRUC BbpCsr; \
221 int _busyCnt, _secCnt, _regID; \
222 \
223 _regID = ((_bViaMCU) == TRUE ? H2M_BBP_AGENT : BBP_CSR_CFG); \
224 for (_busyCnt = 0; _busyCnt < MAX_BUSY_COUNT; _busyCnt++) { \
225 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \
226 if (BbpCsr.field.Busy == BUSY) \
227 continue; \
228 BbpCsr.word = 0; \
229 BbpCsr.field.fRead = 1; \
230 BbpCsr.field.BBP_RW_MODE = 1; \
231 BbpCsr.field.Busy = 1; \
232 BbpCsr.field.RegNum = _bbpID; \
233 RTMP_IO_WRITE32(_pAd, _regID, BbpCsr.word); \
234 if ((_bViaMCU) == TRUE) { \
235 AsicSendCommandToMcu(_pAd, 0x80, 0xff, 0x0, 0x0); \
236 RTMPusecDelay(1000); \
237 } \
238 for (_secCnt = 0; _secCnt < MAX_BUSY_COUNT; _secCnt++) { \
239 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \
240 if (BbpCsr.field.Busy == IDLE) \
241 break; \
242 } \
243 if ((BbpCsr.field.Busy == IDLE) && \
244 (BbpCsr.field.RegNum == _bbpID)) { \
245 *(_pV) = (u8)BbpCsr.field.Value; \
246 break; \
247 } \
248 } \
249 if (BbpCsr.field.Busy == BUSY) { \
250 DBGPRINT_ERR("BBP(viaMCU=%d) read R%d fail\n", (_bViaMCU), _bbpID); \
251 *(_pV) = (_pAd)->BbpWriteLatch[_bbpID]; \
252 if ((_bViaMCU) == TRUE) { \
253 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \
254 BbpCsr.field.Busy = 0; \
255 RTMP_IO_WRITE32(_pAd, _regID, BbpCsr.word); \
256 } \
257 } \
258 } while (0)
259
260/*
261 This marco used for the BBP read operation which didn't need via MCU.
262*/
263#define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) \
264 RTMP_BBP_IO_READ8((_A), (_I), (_pV), FALSE)
265
266/*
267 This marco used for the BBP read operation which need via MCU.
268 But for some chipset which didn't have mcu (e.g., RBUS based chipset), we
269 will use this function too and didn't access the bbp register via the MCU.
270*/
271/* Read BBP register by register's ID. Generate PER to test BA */
272#define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) \
273{ \
274 BBP_CSR_CFG_STRUC BbpCsr; \
275 int i, k; \
276 BOOLEAN brc; \
277 BbpCsr.field.Busy = IDLE; \
278 if ((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) \
279 && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \
280 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE) \
281 && ((_A)->bPCIclkOff == FALSE) \
282 && ((_A)->brt30xxBanMcuCmd == FALSE)) { \
283 for (i = 0; i < MAX_BUSY_COUNT; i++) { \
284 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
285 if (BbpCsr.field.Busy == BUSY) { \
286 continue; \
287 } \
288 BbpCsr.word = 0; \
289 BbpCsr.field.fRead = 1; \
290 BbpCsr.field.BBP_RW_MODE = 1; \
291 BbpCsr.field.Busy = 1; \
292 BbpCsr.field.RegNum = _I; \
293 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
294 brc = AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \
295 if (brc == TRUE) { \
296 for (k = 0; k < MAX_BUSY_COUNT; k++) { \
297 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
298 if (BbpCsr.field.Busy == IDLE) \
299 break; \
300 } \
301 if ((BbpCsr.field.Busy == IDLE) && \
302 (BbpCsr.field.RegNum == _I)) { \
303 *(_pV) = (u8)BbpCsr.field.Value; \
304 break; \
305 } \
306 } else { \
307 BbpCsr.field.Busy = 0; \
308 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
309 } \
310 } \
311 } \
312 else if (!((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \
313 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE)) \
314 && ((_A)->bPCIclkOff == FALSE)) { \
315 for (i = 0; i < MAX_BUSY_COUNT; i++) { \
316 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
317 if (BbpCsr.field.Busy == BUSY) { \
318 continue; \
319 } \
320 BbpCsr.word = 0; \
321 BbpCsr.field.fRead = 1; \
322 BbpCsr.field.BBP_RW_MODE = 1; \
323 BbpCsr.field.Busy = 1; \
324 BbpCsr.field.RegNum = _I; \
325 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
326 AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \
327 for (k = 0; k < MAX_BUSY_COUNT; k++) { \
328 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
329 if (BbpCsr.field.Busy == IDLE) \
330 break; \
331 } \
332 if ((BbpCsr.field.Busy == IDLE) && \
333 (BbpCsr.field.RegNum == _I)) { \
334 *(_pV) = (u8)BbpCsr.field.Value; \
335 break; \
336 } \
337 } \
338 } else { \
339 DBGPRINT_ERR(" , brt30xxBanMcuCmd = %d, Read BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I)); \
340 *(_pV) = (_A)->BbpWriteLatch[_I]; \
341 } \
342 if ((BbpCsr.field.Busy == BUSY) || ((_A)->bPCIclkOff == TRUE)) { \
343 DBGPRINT_ERR("BBP read R%d=0x%x fail\n", _I, BbpCsr.word); \
344 *(_pV) = (_A)->BbpWriteLatch[_I]; \
345 } \
346}
347
348/*
349 basic marco for BBP write operation.
350 _pAd: the data structure pointer of struct rt_rtmp_adapter
351 _bbpID : the bbp register ID
352 _pV: data used to save the value of queried bbp register.
353 _bViaMCU: if we need access the bbp via the MCU.
354*/
355#define RTMP_BBP_IO_WRITE8(_pAd, _bbpID, _pV, _bViaMCU) \
356 do { \
357 BBP_CSR_CFG_STRUC BbpCsr; \
358 int _busyCnt, _regID; \
359 \
360 _regID = ((_bViaMCU) == TRUE ? H2M_BBP_AGENT : BBP_CSR_CFG); \
361 for (_busyCnt = 0; _busyCnt < MAX_BUSY_COUNT; _busyCnt++) { \
362 RTMP_IO_READ32((_pAd), BBP_CSR_CFG, &BbpCsr.word); \
363 if (BbpCsr.field.Busy == BUSY) \
364 continue; \
365 BbpCsr.word = 0; \
366 BbpCsr.field.fRead = 0; \
367 BbpCsr.field.BBP_RW_MODE = 1; \
368 BbpCsr.field.Busy = 1; \
369 BbpCsr.field.Value = _pV; \
370 BbpCsr.field.RegNum = _bbpID; \
371 RTMP_IO_WRITE32((_pAd), BBP_CSR_CFG, BbpCsr.word); \
372 if ((_bViaMCU) == TRUE) { \
373 AsicSendCommandToMcu(_pAd, 0x80, 0xff, 0x0, 0x0); \
374 if ((_pAd)->OpMode == OPMODE_AP) \
375 RTMPusecDelay(1000); \
376 } \
377 (_pAd)->BbpWriteLatch[_bbpID] = _pV; \
378 break; \
379 } \
380 if (_busyCnt == MAX_BUSY_COUNT) { \
381 DBGPRINT_ERR("BBP write R%d fail\n", _bbpID); \
382 if ((_bViaMCU) == TRUE) { \
383 RTMP_IO_READ32(_pAd, H2M_BBP_AGENT, &BbpCsr.word); \
384 BbpCsr.field.Busy = 0; \
385 RTMP_IO_WRITE32(_pAd, H2M_BBP_AGENT, BbpCsr.word); \
386 } \
387 } \
388 } while (0)
389
390/*
391 This marco used for the BBP write operation which didn't need via MCU.
392*/
393#define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _pV) \
394 RTMP_BBP_IO_WRITE8((_A), (_I), (_pV), FALSE)
395
396/*
397 This marco used for the BBP write operation which need via MCU.
398 But for some chipset which didn't have mcu (e.g., RBUS based chipset), we
399 will use this function too and didn't access the bbp register via the MCU.
400*/
401/* Write BBP register by register's ID & value */
402#define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) \
403{ \
404 BBP_CSR_CFG_STRUC BbpCsr; \
405 int BusyCnt = 0; \
406 BOOLEAN brc; \
407 if (_I < MAX_NUM_OF_BBP_LATCH) { \
408 if ((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) \
409 && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \
410 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE) \
411 && ((_A)->bPCIclkOff == FALSE) \
412 && ((_A)->brt30xxBanMcuCmd == FALSE)) { \
413 if (_A->AccessBBPFailCount > 20) { \
414 AsicResetBBPAgent(_A); \
415 _A->AccessBBPFailCount = 0; \
416 } \
417 for (BusyCnt = 0; BusyCnt < MAX_BUSY_COUNT; BusyCnt++) { \
418 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
419 if (BbpCsr.field.Busy == BUSY) \
420 continue; \
421 BbpCsr.word = 0; \
422 BbpCsr.field.fRead = 0; \
423 BbpCsr.field.BBP_RW_MODE = 1; \
424 BbpCsr.field.Busy = 1; \
425 BbpCsr.field.Value = _V; \
426 BbpCsr.field.RegNum = _I; \
427 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
428 brc = AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \
429 if (brc == TRUE) { \
430 (_A)->BbpWriteLatch[_I] = _V; \
431 } else { \
432 BbpCsr.field.Busy = 0; \
433 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
434 } \
435 break; \
436 } \
437 } \
438 else if (!((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) \
439 && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \
440 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE)) \
441 && ((_A)->bPCIclkOff == FALSE)) { \
442 if (_A->AccessBBPFailCount > 20) { \
443 AsicResetBBPAgent(_A); \
444 _A->AccessBBPFailCount = 0; \
445 } \
446 for (BusyCnt = 0; BusyCnt < MAX_BUSY_COUNT; BusyCnt++) { \
447 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
448 if (BbpCsr.field.Busy == BUSY) \
449 continue; \
450 BbpCsr.word = 0; \
451 BbpCsr.field.fRead = 0; \
452 BbpCsr.field.BBP_RW_MODE = 1; \
453 BbpCsr.field.Busy = 1; \
454 BbpCsr.field.Value = _V; \
455 BbpCsr.field.RegNum = _I; \
456 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
457 AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \
458 (_A)->BbpWriteLatch[_I] = _V; \
459 break; \
460 } \
461 } else { \
462 DBGPRINT_ERR(" brt30xxBanMcuCmd = %d. Write BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I)); \
463 } \
464 if ((BusyCnt == MAX_BUSY_COUNT) || ((_A)->bPCIclkOff == TRUE)) { \
465 if (BusyCnt == MAX_BUSY_COUNT) \
466 (_A)->AccessBBPFailCount++; \
467 DBGPRINT_ERR("BBP write R%d=0x%x fail. BusyCnt= %d.bPCIclkOff = %d. \n", _I, BbpCsr.word, BusyCnt, (_A)->bPCIclkOff); \
468 } \
469 } else { \
470 DBGPRINT_ERR("****** BBP_Write_Latch Buffer exceeds max boundary ****** \n"); \
471 } \
472}
473#endif /* RTMP_MAC_PCI // */
474
475#ifdef RTMP_MAC_USB
476#define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV)
477#define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V)
478
479#define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V)
480#define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV)
481#endif /* RTMP_MAC_USB // */
482
483#ifdef RT30xx
484#define RTMP_ASIC_MMPS_DISABLE(_pAd) \
485 do { \
486 u32 _macData; \
487 u8 _bbpData = 0; \
488 /* disable MMPS BBP control register */ \
489 RTMP_BBP_IO_READ8_BY_REG_ID(_pAd, BBP_R3, &_bbpData); \
490 _bbpData &= ~(0x04); /*bit 2*/ \
491 RTMP_BBP_IO_WRITE8_BY_REG_ID(_pAd, BBP_R3, _bbpData); \
492 \
493 /* disable MMPS MAC control register */ \
494 RTMP_IO_READ32(_pAd, 0x1210, &_macData); \
495 _macData &= ~(0x09); /*bit 0, 3*/ \
496 RTMP_IO_WRITE32(_pAd, 0x1210, _macData); \
497 } while (0)
498
499#define RTMP_ASIC_MMPS_ENABLE(_pAd) \
500 do { \
501 u32 _macData; \
502 u8 _bbpData = 0; \
503 /* enable MMPS BBP control register */ \
504 RTMP_BBP_IO_READ8_BY_REG_ID(_pAd, BBP_R3, &_bbpData); \
505 _bbpData |= (0x04); /*bit 2*/ \
506 RTMP_BBP_IO_WRITE8_BY_REG_ID(_pAd, BBP_R3, _bbpData); \
507 \
508 /* enable MMPS MAC control register */ \
509 RTMP_IO_READ32(_pAd, 0x1210, &_macData); \
510 _macData |= (0x09); /*bit 0, 3*/ \
511 RTMP_IO_WRITE32(_pAd, 0x1210, _macData); \
512 } while (0)
513
514#endif /* RT30xx // */
515
516#endif /* __RTMP_PHY_H__ // */
diff --git a/drivers/staging/rt2860/chips/rt3070.c b/drivers/staging/rt2860/chips/rt3070.c
deleted file mode 100644
index 3a17fd10ec1..00000000000
--- a/drivers/staging/rt2860/chips/rt3070.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt3070.c
29
30 Abstract:
31 Specific funcitons and variables for RT3070
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#ifdef RT3070
39
40#include "../rt_config.h"
41
42#ifndef RTMP_RF_RW_SUPPORT
43#error "You Should Enable compile flag RTMP_RF_RW_SUPPORT for this chip"
44#endif /* RTMP_RF_RW_SUPPORT // */
45
46void NICInitRT3070RFRegisters(struct rt_rtmp_adapter *pAd)
47{
48 int i;
49 u8 RFValue;
50
51 /* Driver must read EEPROM to get RfIcType before initial RF registers */
52 /* Initialize RF register to default value */
53 if (IS_RT3070(pAd) || IS_RT3071(pAd)) {
54 /* Init RF calibration */
55 /* Driver should toggle RF R30 bit7 before init RF registers */
56 u32 RfReg = 0;
57 u32 data;
58
59 RT30xxReadRFRegister(pAd, RF_R30, (u8 *)&RfReg);
60 RfReg |= 0x80;
61 RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg);
62 RTMPusecDelay(1000);
63 RfReg &= 0x7F;
64 RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg);
65
66 /* Initialize RF register to default value */
67 for (i = 0; i < NUM_RF_REG_PARMS; i++) {
68 RT30xxWriteRFRegister(pAd,
69 RT30xx_RFRegTable[i].Register,
70 RT30xx_RFRegTable[i].Value);
71 }
72
73 /* add by johnli */
74 if (IS_RT3070(pAd)) {
75 /* */
76 /* The DAC issue(LDO_CFG0) has been fixed in RT3070(F). */
77 /* The voltage raising patch is no longer needed for RT3070(F) */
78 /* */
79 if ((pAd->MACVersion & 0xffff) < 0x0201) {
80 /* Update MAC 0x05D4 from 01xxxxxx to 0Dxxxxxx (voltage 1.2V to 1.35V) for RT3070 to improve yield rate */
81 RTUSBReadMACRegister(pAd, LDO_CFG0, &data);
82 data = ((data & 0xF0FFFFFF) | 0x0D000000);
83 RTUSBWriteMACRegister(pAd, LDO_CFG0, data);
84 }
85 } else if (IS_RT3071(pAd)) {
86 /* Driver should set RF R6 bit6 on before init RF registers */
87 RT30xxReadRFRegister(pAd, RF_R06, (u8 *)&RfReg);
88 RfReg |= 0x40;
89 RT30xxWriteRFRegister(pAd, RF_R06, (u8)RfReg);
90
91 /* init R31 */
92 RT30xxWriteRFRegister(pAd, RF_R31, 0x14);
93
94 /* RT3071 version E has fixed this issue */
95 if ((pAd->NicConfig2.field.DACTestBit == 1)
96 && ((pAd->MACVersion & 0xffff) < 0x0211)) {
97 /* patch tx EVM issue temporarily */
98 RTUSBReadMACRegister(pAd, LDO_CFG0, &data);
99 data = ((data & 0xE0FFFFFF) | 0x0D000000);
100 RTUSBWriteMACRegister(pAd, LDO_CFG0, data);
101 } else {
102 RTMP_IO_READ32(pAd, LDO_CFG0, &data);
103 data = ((data & 0xE0FFFFFF) | 0x01000000);
104 RTMP_IO_WRITE32(pAd, LDO_CFG0, data);
105 }
106
107 /* patch LNA_PE_G1 failed issue */
108 RTUSBReadMACRegister(pAd, GPIO_SWITCH, &data);
109 data &= ~(0x20);
110 RTUSBWriteMACRegister(pAd, GPIO_SWITCH, data);
111 }
112 /*For RF filter Calibration */
113 RTMPFilterCalibration(pAd);
114
115 /* Initialize RF R27 register, set RF R27 must be behind RTMPFilterCalibration() */
116 /* */
117 /* TX to RX IQ glitch(RF_R27) has been fixed in RT3070(F). */
118 /* Raising RF voltage is no longer needed for RT3070(F) */
119 /* */
120 if ((IS_RT3070(pAd)) && ((pAd->MACVersion & 0xffff) < 0x0201)) {
121 RT30xxWriteRFRegister(pAd, RF_R27, 0x3);
122 } else if ((IS_RT3071(pAd))
123 && ((pAd->MACVersion & 0xffff) < 0x0211)) {
124 RT30xxWriteRFRegister(pAd, RF_R27, 0x3);
125 }
126 /* set led open drain enable */
127 RTUSBReadMACRegister(pAd, OPT_14, &data);
128 data |= 0x01;
129 RTUSBWriteMACRegister(pAd, OPT_14, data);
130
131 /* move from RT30xxLoadRFNormalModeSetup because it's needed for both RT3070 and RT3071 */
132 /* TX_LO1_en, RF R17 register Bit 3 to 0 */
133 RT30xxReadRFRegister(pAd, RF_R17, &RFValue);
134 RFValue &= (~0x08);
135 /* to fix rx long range issue */
136 if (pAd->NicConfig2.field.ExternalLNAForG == 0) {
137 if ((IS_RT3071(pAd)
138 && ((pAd->MACVersion & 0xffff) >= 0x0211))
139 || IS_RT3070(pAd)) {
140 RFValue |= 0x20;
141 }
142 }
143 /* set RF_R17_bit[2:0] equal to EEPROM setting at 0x48h */
144 if (pAd->TxMixerGain24G >= 1) {
145 RFValue &= (~0x7); /* clean bit [2:0] */
146 RFValue |= pAd->TxMixerGain24G;
147 }
148 RT30xxWriteRFRegister(pAd, RF_R17, RFValue);
149
150 if (IS_RT3071(pAd)) {
151 /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */
152 RT30xxLoadRFNormalModeSetup(pAd);
153 } else if (IS_RT3070(pAd)) {
154 /* add by johnli, reset RF_R27 when interface down & up to fix throughput problem */
155 /* LDORF_VC, RF R27 register Bit 2 to 0 */
156 RT30xxReadRFRegister(pAd, RF_R27, &RFValue);
157 /* TX to RX IQ glitch(RF_R27) has been fixed in RT3070(F). */
158 /* Raising RF voltage is no longer needed for RT3070(F) */
159 if ((pAd->MACVersion & 0xffff) < 0x0201)
160 RFValue = (RFValue & (~0x77)) | 0x3;
161 else
162 RFValue = (RFValue & (~0x77));
163 RT30xxWriteRFRegister(pAd, RF_R27, RFValue);
164 /* end johnli */
165 }
166 }
167
168}
169#endif /* RT3070 // */
diff --git a/drivers/staging/rt2860/chips/rt3090.c b/drivers/staging/rt2860/chips/rt3090.c
deleted file mode 100644
index 334720ee134..00000000000
--- a/drivers/staging/rt2860/chips/rt3090.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt3090.c
29
30 Abstract:
31 Specific functions and variables for RT3070
32
33 Revision History:
34 Who When What
35 Justin P. Mattock 11/07/2010 Fix a typo
36 -------- ---------- ----------------------------------------------
37*/
38
39#ifdef RT3090
40
41#include "../rt_config.h"
42
43#ifndef RTMP_RF_RW_SUPPORT
44#error "You Should Enable compile flag RTMP_RF_RW_SUPPORT for this chip"
45#endif /* RTMP_RF_RW_SUPPORT // */
46
47void NICInitRT3090RFRegisters(struct rt_rtmp_adapter *pAd)
48{
49 int i;
50 /* Driver must read EEPROM to get RfIcType before initial RF registers */
51 /* Initialize RF register to default value */
52 if (IS_RT3090(pAd)) {
53 /* Init RF calibration */
54 /* Driver should toggle RF R30 bit7 before init RF registers */
55 u8 RfReg;
56 u32 data;
57
58 RT30xxReadRFRegister(pAd, RF_R30, (u8 *)&RfReg);
59 RfReg |= 0x80;
60 RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg);
61 RTMPusecDelay(1000);
62 RfReg &= 0x7F;
63 RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg);
64
65 /* init R24, R31 */
66 RT30xxWriteRFRegister(pAd, RF_R24, 0x0F);
67 RT30xxWriteRFRegister(pAd, RF_R31, 0x0F);
68
69 /* RT309x version E has fixed this issue */
70 if ((pAd->NicConfig2.field.DACTestBit == 1)
71 && ((pAd->MACVersion & 0xffff) < 0x0211)) {
72 /* patch tx EVM issue temporarily */
73 RTMP_IO_READ32(pAd, LDO_CFG0, &data);
74 data = ((data & 0xE0FFFFFF) | 0x0D000000);
75 RTMP_IO_WRITE32(pAd, LDO_CFG0, data);
76 } else {
77 RTMP_IO_READ32(pAd, LDO_CFG0, &data);
78 data = ((data & 0xE0FFFFFF) | 0x01000000);
79 RTMP_IO_WRITE32(pAd, LDO_CFG0, data);
80 }
81
82 /* patch LNA_PE_G1 failed issue */
83 RTMP_IO_READ32(pAd, GPIO_SWITCH, &data);
84 data &= ~(0x20);
85 RTMP_IO_WRITE32(pAd, GPIO_SWITCH, data);
86
87 /* Initialize RF register to default value */
88 for (i = 0; i < NUM_RF_REG_PARMS; i++) {
89 RT30xxWriteRFRegister(pAd,
90 RT30xx_RFRegTable[i].Register,
91 RT30xx_RFRegTable[i].Value);
92 }
93
94 /* Driver should set RF R6 bit6 on before calibration */
95 RT30xxReadRFRegister(pAd, RF_R06, (u8 *)&RfReg);
96 RfReg |= 0x40;
97 RT30xxWriteRFRegister(pAd, RF_R06, (u8)RfReg);
98
99 /*For RF filter Calibration */
100 RTMPFilterCalibration(pAd);
101
102 /* Initialize RF R27 register, set RF R27 must be behind RTMPFilterCalibration() */
103 if ((pAd->MACVersion & 0xffff) < 0x0211)
104 RT30xxWriteRFRegister(pAd, RF_R27, 0x3);
105
106 /* set led open drain enable */
107 RTMP_IO_READ32(pAd, OPT_14, &data);
108 data |= 0x01;
109 RTMP_IO_WRITE32(pAd, OPT_14, data);
110
111 /* set default antenna as main */
112 if (pAd->RfIcType == RFIC_3020)
113 AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
114
115 /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */
116 RT30xxLoadRFNormalModeSetup(pAd);
117 }
118
119}
120
121#endif /* RT3090 // */
diff --git a/drivers/staging/rt2860/chips/rt30xx.c b/drivers/staging/rt2860/chips/rt30xx.c
deleted file mode 100644
index 354debfe147..00000000000
--- a/drivers/staging/rt2860/chips/rt30xx.c
+++ /dev/null
@@ -1,516 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt30xx.c
29
30 Abstract:
31 Specific functions and variables for RT30xx.
32
33 Revision History:
34 Who When What
35 Justin P. Mattock 11/07/2010 Fix some typos
36 -------- ---------- ----------------------------------------------
37*/
38
39#ifdef RT30xx
40
41#ifndef RTMP_RF_RW_SUPPORT
42#error "You Should Enable compile flag RTMP_RF_RW_SUPPORT for this chip"
43#endif /* RTMP_RF_RW_SUPPORT // */
44
45#include "../rt_config.h"
46
47/* */
48/* RF register initialization set */
49/* */
50struct rt_reg_pair RT30xx_RFRegTable[] = {
51 {RF_R04, 0x40}
52 ,
53 {RF_R05, 0x03}
54 ,
55 {RF_R06, 0x02}
56 ,
57 {RF_R07, 0x60}
58 ,
59 {RF_R09, 0x0F}
60 ,
61 {RF_R10, 0x41}
62 ,
63 {RF_R11, 0x21}
64 ,
65 {RF_R12, 0x7B}
66 ,
67 {RF_R14, 0x90}
68 ,
69 {RF_R15, 0x58}
70 ,
71 {RF_R16, 0xB3}
72 ,
73 {RF_R17, 0x92}
74 ,
75 {RF_R18, 0x2C}
76 ,
77 {RF_R19, 0x02}
78 ,
79 {RF_R20, 0xBA}
80 ,
81 {RF_R21, 0xDB}
82 ,
83 {RF_R24, 0x16}
84 ,
85 {RF_R25, 0x01}
86 ,
87 {RF_R29, 0x1F}
88 ,
89};
90
91u8 NUM_RF_REG_PARMS = (sizeof(RT30xx_RFRegTable) / sizeof(struct rt_reg_pair));
92
93/* Antenna diversity use GPIO3 and EESK pin for control */
94/* Antenna and EEPROM access are both using EESK pin, */
95/* Therefor we should avoid accessing EESK at the same time */
96/* Then restore antenna after EEPROM access */
97/* The original name of this function is AsicSetRxAnt(), now change to */
98/*void AsicSetRxAnt( */
99void RT30xxSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant)
100{
101 u32 Value;
102#ifdef RTMP_MAC_PCI
103 u32 x;
104#endif
105
106 if ((pAd->EepromAccess) ||
107 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) ||
108 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) ||
109 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) ||
110 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
111 return;
112 }
113 /* the antenna selection is through firmware and MAC register(GPIO3) */
114 if (Ant == 0) {
115 /* Main antenna */
116#ifdef RTMP_MAC_PCI
117 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
118 x |= (EESK);
119 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
120#else
121 AsicSendCommandToMcu(pAd, 0x73, 0xFF, 0x1, 0x0);
122#endif /* RTMP_MAC_PCI // */
123
124 RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value);
125 Value &= ~(0x0808);
126 RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value);
127 DBGPRINT_RAW(RT_DEBUG_TRACE,
128 ("AsicSetRxAnt, switch to main antenna\n"));
129 } else {
130 /* Aux antenna */
131#ifdef RTMP_MAC_PCI
132 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
133 x &= ~(EESK);
134 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
135#else
136 AsicSendCommandToMcu(pAd, 0x73, 0xFF, 0x0, 0x0);
137#endif /* RTMP_MAC_PCI // */
138 RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value);
139 Value &= ~(0x0808);
140 Value |= 0x08;
141 RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value);
142 DBGPRINT_RAW(RT_DEBUG_TRACE,
143 ("AsicSetRxAnt, switch to aux antenna\n"));
144 }
145}
146
147/*
148 ========================================================================
149
150 Routine Description:
151 For RF filter calibration purpose
152
153 Arguments:
154 pAd Pointer to our adapter
155
156 Return Value:
157 None
158
159 IRQL = PASSIVE_LEVEL
160
161 ========================================================================
162*/
163void RTMPFilterCalibration(struct rt_rtmp_adapter *pAd)
164{
165 u8 R55x = 0, value, FilterTarget = 0x1E, BBPValue = 0;
166 u32 loop = 0, count = 0, loopcnt = 0, ReTry = 0;
167 u8 RF_R24_Value = 0;
168
169 /* Give bbp filter initial value */
170 pAd->Mlme.CaliBW20RfR24 = 0x1F;
171 pAd->Mlme.CaliBW40RfR24 = 0x2F; /*Bit[5] must be 1 for BW 40 */
172
173 do {
174 if (loop == 1) { /*BandWidth = 40 MHz */
175 /* Write 0x27 to RF_R24 to program filter */
176 RF_R24_Value = 0x27;
177 RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
178 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
179 FilterTarget = 0x15;
180 else
181 FilterTarget = 0x19;
182
183 /* when calibrate BW40, BBP mask must set to BW40. */
184 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
185 BBPValue &= (~0x18);
186 BBPValue |= (0x10);
187 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
188
189 /* set to BW40 */
190 RT30xxReadRFRegister(pAd, RF_R31, &value);
191 value |= 0x20;
192 RT30xxWriteRFRegister(pAd, RF_R31, value);
193 } else { /*BandWidth = 20 MHz */
194 /* Write 0x07 to RF_R24 to program filter */
195 RF_R24_Value = 0x07;
196 RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
197 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
198 FilterTarget = 0x13;
199 else
200 FilterTarget = 0x16;
201
202 /* set to BW20 */
203 RT30xxReadRFRegister(pAd, RF_R31, &value);
204 value &= (~0x20);
205 RT30xxWriteRFRegister(pAd, RF_R31, value);
206 }
207
208 /* Write 0x01 to RF_R22 to enable baseband loopback mode */
209 RT30xxReadRFRegister(pAd, RF_R22, &value);
210 value |= 0x01;
211 RT30xxWriteRFRegister(pAd, RF_R22, value);
212
213 /* Write 0x00 to BBP_R24 to set power & frequency of passband test tone */
214 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0);
215
216 do {
217 /* Write 0x90 to BBP_R25 to transmit test tone */
218 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R25, 0x90);
219
220 RTMPusecDelay(1000);
221 /* Read BBP_R55[6:0] for received power, set R55x = BBP_R55[6:0] */
222 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R55, &value);
223 R55x = value & 0xFF;
224
225 } while ((ReTry++ < 100) && (R55x == 0));
226
227 /* Write 0x06 to BBP_R24 to set power & frequency of stopband test tone */
228 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0x06);
229
230 while (TRUE) {
231 /* Write 0x90 to BBP_R25 to transmit test tone */
232 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R25, 0x90);
233
234 /*We need to wait for calibration */
235 RTMPusecDelay(1000);
236 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R55, &value);
237 value &= 0xFF;
238 if ((R55x - value) < FilterTarget) {
239 RF_R24_Value++;
240 } else if ((R55x - value) == FilterTarget) {
241 RF_R24_Value++;
242 count++;
243 } else {
244 break;
245 }
246
247 /* prevent infinite loop; causes driver hang. */
248 if (loopcnt++ > 100) {
249 DBGPRINT(RT_DEBUG_ERROR,
250 ("RTMPFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating",
251 loopcnt));
252 break;
253 }
254 /* Write RF_R24 to program filter */
255 RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
256 }
257
258 if (count > 0) {
259 RF_R24_Value = RF_R24_Value - ((count) ? (1) : (0));
260 }
261 /* Store for future usage */
262 if (loopcnt < 100) {
263 if (loop++ == 0) {
264 /*BandWidth = 20 MHz */
265 pAd->Mlme.CaliBW20RfR24 = (u8)RF_R24_Value;
266 } else {
267 /*BandWidth = 40 MHz */
268 pAd->Mlme.CaliBW40RfR24 = (u8)RF_R24_Value;
269 break;
270 }
271 } else
272 break;
273
274 RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value);
275
276 /* reset count */
277 count = 0;
278 } while (TRUE);
279
280 /* */
281 /* Set back to initial state */
282 /* */
283 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0);
284
285 RT30xxReadRFRegister(pAd, RF_R22, &value);
286 value &= ~(0x01);
287 RT30xxWriteRFRegister(pAd, RF_R22, value);
288
289 /* set BBP back to BW20 */
290 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
291 BBPValue &= (~0x18);
292 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
293
294 DBGPRINT(RT_DEBUG_TRACE,
295 ("RTMPFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n",
296 pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24));
297}
298
299/* add by johnli, RF power sequence setup */
300/*
301 ==========================================================================
302 Description:
303
304 Load RF normal operation-mode setup
305
306 ==========================================================================
307 */
308void RT30xxLoadRFNormalModeSetup(struct rt_rtmp_adapter *pAd)
309{
310 u8 RFValue;
311
312 /* RX0_PD & TX0_PD, RF R1 register Bit 2 & Bit 3 to 0 and RF_BLOCK_en,RX1_PD & TX1_PD, Bit0, Bit 4 & Bit5 to 1 */
313 RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
314 RFValue = (RFValue & (~0x0C)) | 0x31;
315 RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
316
317 /* TX_LO2_en, RF R15 register Bit 3 to 0 */
318 RT30xxReadRFRegister(pAd, RF_R15, &RFValue);
319 RFValue &= (~0x08);
320 RT30xxWriteRFRegister(pAd, RF_R15, RFValue);
321
322 /* move to NICInitRT30xxRFRegisters
323 // TX_LO1_en, RF R17 register Bit 3 to 0
324 RT30xxReadRFRegister(pAd, RF_R17, &RFValue);
325 RFValue &= (~0x08);
326 // to fix rx long range issue
327 if (((pAd->MACVersion & 0xffff) >= 0x0211) && (pAd->NicConfig2.field.ExternalLNAForG == 0))
328 {
329 RFValue |= 0x20;
330 }
331 // set RF_R17_bit[2:0] equal to EEPROM setting at 0x48h
332 if (pAd->TxMixerGain24G >= 2)
333 {
334 RFValue &= (~0x7); // clean bit [2:0]
335 RFValue |= pAd->TxMixerGain24G;
336 }
337 RT30xxWriteRFRegister(pAd, RF_R17, RFValue);
338 */
339
340 /* RX_LO1_en, RF R20 register Bit 3 to 0 */
341 RT30xxReadRFRegister(pAd, RF_R20, &RFValue);
342 RFValue &= (~0x08);
343 RT30xxWriteRFRegister(pAd, RF_R20, RFValue);
344
345 /* RX_LO2_en, RF R21 register Bit 3 to 0 */
346 RT30xxReadRFRegister(pAd, RF_R21, &RFValue);
347 RFValue &= (~0x08);
348 RT30xxWriteRFRegister(pAd, RF_R21, RFValue);
349
350 /* add by johnli, reset RF_R27 when interface down & up to fix throughput problem */
351 /* LDORF_VC, RF R27 register Bit 2 to 0 */
352 RT30xxReadRFRegister(pAd, RF_R27, &RFValue);
353 /* TX to RX IQ glitch(RF_R27) has been fixed in RT3070(F). */
354 /* Raising RF voltage is no longer needed for RT3070(F) */
355 if (IS_RT3090(pAd)) { /* RT309x and RT3071/72 */
356 if ((pAd->MACVersion & 0xffff) < 0x0211)
357 RFValue = (RFValue & (~0x77)) | 0x3;
358 else
359 RFValue = (RFValue & (~0x77));
360 RT30xxWriteRFRegister(pAd, RF_R27, RFValue);
361 }
362 /* end johnli */
363}
364
365/*
366 ==========================================================================
367 Description:
368
369 Load RF sleep-mode setup
370
371 ==========================================================================
372 */
373void RT30xxLoadRFSleepModeSetup(struct rt_rtmp_adapter *pAd)
374{
375 u8 RFValue;
376 u32 MACValue;
377
378#ifdef RTMP_MAC_USB
379 if (!IS_RT3572(pAd))
380#endif /* RTMP_MAC_USB // */
381 {
382 /* RF_BLOCK_en. RF R1 register Bit 0 to 0 */
383 RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
384 RFValue &= (~0x01);
385 RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
386
387 /* VCO_IC, RF R7 register Bit 4 & Bit 5 to 0 */
388 RT30xxReadRFRegister(pAd, RF_R07, &RFValue);
389 RFValue &= (~0x30);
390 RT30xxWriteRFRegister(pAd, RF_R07, RFValue);
391
392 /* Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 0 */
393 RT30xxReadRFRegister(pAd, RF_R09, &RFValue);
394 RFValue &= (~0x0E);
395 RT30xxWriteRFRegister(pAd, RF_R09, RFValue);
396
397 /* RX_CTB_en, RF R21 register Bit 7 to 0 */
398 RT30xxReadRFRegister(pAd, RF_R21, &RFValue);
399 RFValue &= (~0x80);
400 RT30xxWriteRFRegister(pAd, RF_R21, RFValue);
401 }
402
403 if (IS_RT3090(pAd) || /* IS_RT3090 including RT309x and RT3071/72 */
404 IS_RT3572(pAd) ||
405 (IS_RT3070(pAd) && ((pAd->MACVersion & 0xffff) < 0x0201))) {
406#ifdef RTMP_MAC_USB
407 if (!IS_RT3572(pAd))
408#endif /* RTMP_MAC_USB // */
409 {
410 RT30xxReadRFRegister(pAd, RF_R27, &RFValue);
411 RFValue |= 0x77;
412 RT30xxWriteRFRegister(pAd, RF_R27, RFValue);
413 }
414
415 RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue);
416 MACValue |= 0x1D000000;
417 RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue);
418 }
419}
420
421/*
422 ==========================================================================
423 Description:
424
425 Reverse RF sleep-mode setup
426
427 ==========================================================================
428 */
429void RT30xxReverseRFSleepModeSetup(struct rt_rtmp_adapter *pAd)
430{
431 u8 RFValue;
432 u32 MACValue;
433
434#ifdef RTMP_MAC_USB
435 if (!IS_RT3572(pAd))
436#endif /* RTMP_MAC_USB // */
437 {
438 /* RF_BLOCK_en, RF R1 register Bit 0 to 1 */
439 RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
440 RFValue |= 0x01;
441 RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
442
443 /* VCO_IC, RF R7 register Bit 4 & Bit 5 to 1 */
444 RT30xxReadRFRegister(pAd, RF_R07, &RFValue);
445 RFValue |= 0x20;
446 RT30xxWriteRFRegister(pAd, RF_R07, RFValue);
447
448 /* Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 1 */
449 RT30xxReadRFRegister(pAd, RF_R09, &RFValue);
450 RFValue |= 0x0E;
451 RT30xxWriteRFRegister(pAd, RF_R09, RFValue);
452
453 /* RX_CTB_en, RF R21 register Bit 7 to 1 */
454 RT30xxReadRFRegister(pAd, RF_R21, &RFValue);
455 RFValue |= 0x80;
456 RT30xxWriteRFRegister(pAd, RF_R21, RFValue);
457 }
458
459 if (IS_RT3090(pAd) || /* IS_RT3090 including RT309x and RT3071/72 */
460 IS_RT3572(pAd) ||
461 IS_RT3390(pAd) ||
462 (IS_RT3070(pAd) && ((pAd->MACVersion & 0xffff) < 0x0201))) {
463#ifdef RTMP_MAC_USB
464 if (!IS_RT3572(pAd))
465#endif /* RTMP_MAC_USB // */
466 {
467 RT30xxReadRFRegister(pAd, RF_R27, &RFValue);
468 if ((pAd->MACVersion & 0xffff) < 0x0211)
469 RFValue = (RFValue & (~0x77)) | 0x3;
470 else
471 RFValue = (RFValue & (~0x77));
472 RT30xxWriteRFRegister(pAd, RF_R27, RFValue);
473 }
474 /* RT3071 version E has fixed this issue */
475 if ((pAd->NicConfig2.field.DACTestBit == 1)
476 && ((pAd->MACVersion & 0xffff) < 0x0211)) {
477 /* patch tx EVM issue temporarily */
478 RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue);
479 MACValue = ((MACValue & 0xE0FFFFFF) | 0x0D000000);
480 RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue);
481 } else {
482 RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue);
483 MACValue = ((MACValue & 0xE0FFFFFF) | 0x01000000);
484 RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue);
485 }
486 }
487
488 if (IS_RT3572(pAd))
489 RT30xxWriteRFRegister(pAd, RF_R08, 0x80);
490}
491
492/* end johnli */
493
494void RT30xxHaltAction(struct rt_rtmp_adapter *pAd)
495{
496 u32 TxPinCfg = 0x00050F0F;
497
498 /* */
499 /* Turn off LNA_PE or TRSW_POL */
500 /* */
501 if (IS_RT3070(pAd) || IS_RT3071(pAd) || IS_RT3572(pAd)) {
502 if ((IS_RT3071(pAd) || IS_RT3572(pAd))
503#ifdef RTMP_EFUSE_SUPPORT
504 && (pAd->bUseEfuse)
505#endif /* RTMP_EFUSE_SUPPORT // */
506 ) {
507 TxPinCfg &= 0xFFFBF0F0; /* bit18 off */
508 } else {
509 TxPinCfg &= 0xFFFFF0F0;
510 }
511
512 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
513 }
514}
515
516#endif /* RT30xx // */
diff --git a/drivers/staging/rt2860/chlist.h b/drivers/staging/rt2860/chlist.h
deleted file mode 100644
index 1231e69d518..00000000000
--- a/drivers/staging/rt2860/chlist.h
+++ /dev/null
@@ -1,113 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 chlist.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Fonchi Wu 2007-12-19 created
36*/
37
38#ifndef __CHLIST_H__
39#define __CHLIST_H__
40
41#include "rtmp_type.h"
42#include "rtmp_def.h"
43
44#define ODOR 0
45#define IDOR 1
46#define BOTH 2
47
48#define BAND_5G 0
49#define BAND_24G 1
50#define BAND_BOTH 2
51
52struct rt_ch_desp {
53 u8 FirstChannel;
54 u8 NumOfCh;
55 char MaxTxPwr; /* dBm */
56 u8 Geography; /* 0:out door, 1:in door, 2:both */
57 BOOLEAN DfsReq; /* Dfs require, 0: No, 1: yes. */
58};
59
60struct rt_ch_region {
61 u8 CountReg[3];
62 u8 DfsType; /* 0: CE, 1: FCC, 2: JAP, 3:JAP_W53, JAP_W56 */
63 struct rt_ch_desp ChDesp[10];
64};
65
66extern struct rt_ch_region ChRegion[];
67
68struct rt_ch_freq_map {
69 u16 channel;
70 u16 freqKHz;
71};
72
73extern struct rt_ch_freq_map CH_HZ_ID_MAP[];
74extern int CH_HZ_ID_MAP_NUM;
75
76#define MAP_CHANNEL_ID_TO_KHZ(_ch, _khz) \
77 do { \
78 int _chIdx; \
79 for (_chIdx = 0; _chIdx < CH_HZ_ID_MAP_NUM; _chIdx++) {\
80 if ((_ch) == CH_HZ_ID_MAP[_chIdx].channel) { \
81 (_khz) = CH_HZ_ID_MAP[_chIdx].freqKHz * 1000;\
82 break; \
83 } \
84 } \
85 if (_chIdx == CH_HZ_ID_MAP_NUM) \
86 (_khz) = 2412000; \
87 } while (0)
88
89#define MAP_KHZ_TO_CHANNEL_ID(_khz, _ch) \
90 do { \
91 int _chIdx; \
92 for (_chIdx = 0; _chIdx < CH_HZ_ID_MAP_NUM; _chIdx++) {\
93 if ((_khz) == CH_HZ_ID_MAP[_chIdx].freqKHz) {\
94 (_ch) = CH_HZ_ID_MAP[_chIdx].channel; \
95 break; \
96 } \
97 } \
98 if (_chIdx == CH_HZ_ID_MAP_NUM) \
99 (_ch) = 1; \
100 } while (0)
101
102void BuildChannelListEx(struct rt_rtmp_adapter *pAd);
103
104void BuildBeaconChList(struct rt_rtmp_adapter *pAd,
105 u8 *pBuf, unsigned long *pBufLen);
106
107void N_ChannelCheck(struct rt_rtmp_adapter *pAd);
108
109void N_SetCenCh(struct rt_rtmp_adapter *pAd);
110
111u8 GetCuntryMaxTxPwr(struct rt_rtmp_adapter *pAd, u8 channel);
112
113#endif /* __CHLIST_H__ */
diff --git a/drivers/staging/rt2860/common/action.c b/drivers/staging/rt2860/common/action.c
deleted file mode 100644
index 56ad236e114..00000000000
--- a/drivers/staging/rt2860/common/action.c
+++ /dev/null
@@ -1,606 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 action.c
29
30 Abstract:
31 Handle association related requests either from WSTA or from local MLME
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Jan Lee 2006 created for rt2860
37 */
38
39#include "../rt_config.h"
40#include "action.h"
41
42static void ReservedAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
43
44/*
45 ==========================================================================
46 Description:
47 association state machine init, including state transition and timer init
48 Parameters:
49 S - pointer to the association state machine
50 Note:
51 The state machine looks like the following
52
53 ASSOC_IDLE
54 MT2_MLME_DISASSOC_REQ mlme_disassoc_req_action
55 MT2_PEER_DISASSOC_REQ peer_disassoc_action
56 MT2_PEER_ASSOC_REQ drop
57 MT2_PEER_REASSOC_REQ drop
58 MT2_CLS3ERR cls3err_action
59 ==========================================================================
60 */
61void ActionStateMachineInit(struct rt_rtmp_adapter *pAd,
62 struct rt_state_machine *S,
63 OUT STATE_MACHINE_FUNC Trans[])
64{
65 StateMachineInit(S, (STATE_MACHINE_FUNC *) Trans, MAX_ACT_STATE,
66 MAX_ACT_MSG, (STATE_MACHINE_FUNC) Drop, ACT_IDLE,
67 ACT_MACHINE_BASE);
68
69 StateMachineSetAction(S, ACT_IDLE, MT2_PEER_SPECTRUM_CATE,
70 (STATE_MACHINE_FUNC) PeerSpectrumAction);
71 StateMachineSetAction(S, ACT_IDLE, MT2_PEER_QOS_CATE,
72 (STATE_MACHINE_FUNC) PeerQOSAction);
73
74 StateMachineSetAction(S, ACT_IDLE, MT2_PEER_DLS_CATE,
75 (STATE_MACHINE_FUNC) ReservedAction);
76
77 StateMachineSetAction(S, ACT_IDLE, MT2_PEER_BA_CATE,
78 (STATE_MACHINE_FUNC) PeerBAAction);
79 StateMachineSetAction(S, ACT_IDLE, MT2_PEER_HT_CATE,
80 (STATE_MACHINE_FUNC) PeerHTAction);
81 StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ADD_BA_CATE,
82 (STATE_MACHINE_FUNC) MlmeADDBAAction);
83 StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ORI_DELBA_CATE,
84 (STATE_MACHINE_FUNC) MlmeDELBAAction);
85 StateMachineSetAction(S, ACT_IDLE, MT2_MLME_REC_DELBA_CATE,
86 (STATE_MACHINE_FUNC) MlmeDELBAAction);
87
88 StateMachineSetAction(S, ACT_IDLE, MT2_PEER_PUBLIC_CATE,
89 (STATE_MACHINE_FUNC) PeerPublicAction);
90 StateMachineSetAction(S, ACT_IDLE, MT2_PEER_RM_CATE,
91 (STATE_MACHINE_FUNC) PeerRMAction);
92
93 StateMachineSetAction(S, ACT_IDLE, MT2_MLME_QOS_CATE,
94 (STATE_MACHINE_FUNC) MlmeQOSAction);
95 StateMachineSetAction(S, ACT_IDLE, MT2_MLME_DLS_CATE,
96 (STATE_MACHINE_FUNC) MlmeDLSAction);
97 StateMachineSetAction(S, ACT_IDLE, MT2_ACT_INVALID,
98 (STATE_MACHINE_FUNC) MlmeInvalidAction);
99}
100
101void MlmeADDBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
102{
103 struct rt_mlme_addba_req *pInfo;
104 u8 Addr[6];
105 u8 *pOutBuffer = NULL;
106 int NStatus;
107 unsigned long Idx;
108 struct rt_frame_addba_req Frame;
109 unsigned long FrameLen;
110 struct rt_ba_ori_entry *pBAEntry = NULL;
111
112 pInfo = (struct rt_mlme_addba_req *)Elem->Msg;
113 NdisZeroMemory(&Frame, sizeof(struct rt_frame_addba_req));
114
115 if (MlmeAddBAReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr)) {
116 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
117 if (NStatus != NDIS_STATUS_SUCCESS) {
118 DBGPRINT(RT_DEBUG_TRACE,
119 ("BA - MlmeADDBAAction() allocate memory failed \n"));
120 return;
121 }
122 /* 1. find entry */
123 Idx =
124 pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID];
125 if (Idx == 0) {
126 MlmeFreeMemory(pAd, pOutBuffer);
127 DBGPRINT(RT_DEBUG_ERROR,
128 ("BA - MlmeADDBAAction() can't find BAOriEntry \n"));
129 return;
130 } else {
131 pBAEntry = &pAd->BATable.BAOriEntry[Idx];
132 }
133
134 {
135 if (ADHOC_ON(pAd))
136 ActHeaderInit(pAd, &Frame.Hdr, pInfo->pAddr,
137 pAd->CurrentAddress,
138 pAd->CommonCfg.Bssid);
139 else
140 ActHeaderInit(pAd, &Frame.Hdr,
141 pAd->CommonCfg.Bssid,
142 pAd->CurrentAddress,
143 pInfo->pAddr);
144 }
145
146 Frame.Category = CATEGORY_BA;
147 Frame.Action = ADDBA_REQ;
148 Frame.BaParm.AMSDUSupported = 0;
149 Frame.BaParm.BAPolicy = IMMED_BA;
150 Frame.BaParm.TID = pInfo->TID;
151 Frame.BaParm.BufSize = pInfo->BaBufSize;
152 Frame.Token = pInfo->Token;
153 Frame.TimeOutValue = pInfo->TimeOutValue;
154 Frame.BaStartSeq.field.FragNum = 0;
155 Frame.BaStartSeq.field.StartSeq =
156 pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID];
157
158 *(u16 *) (&Frame.BaParm) =
159 cpu2le16(*(u16 *) (&Frame.BaParm));
160 Frame.TimeOutValue = cpu2le16(Frame.TimeOutValue);
161 Frame.BaStartSeq.word = cpu2le16(Frame.BaStartSeq.word);
162
163 MakeOutgoingFrame(pOutBuffer, &FrameLen,
164 sizeof(struct rt_frame_addba_req), &Frame, END_OF_ARGS);
165
166 MiniportMMRequest(pAd,
167 (MGMT_USE_QUEUE_FLAG |
168 MapUserPriorityToAccessCategory[pInfo->TID]),
169 pOutBuffer, FrameLen);
170
171 MlmeFreeMemory(pAd, pOutBuffer);
172
173 DBGPRINT(RT_DEBUG_TRACE,
174 ("BA - Send ADDBA request. StartSeq = %x, FrameLen = %ld. BufSize = %d\n",
175 Frame.BaStartSeq.field.StartSeq, FrameLen,
176 Frame.BaParm.BufSize));
177 }
178}
179
180/*
181 ==========================================================================
182 Description:
183 send DELBA and delete BaEntry if any
184 Parametrs:
185 Elem - MLME message struct rt_mlme_delba_req
186
187 IRQL = DISPATCH_LEVEL
188
189 ==========================================================================
190 */
191void MlmeDELBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
192{
193 struct rt_mlme_delba_req *pInfo;
194 u8 *pOutBuffer = NULL;
195 u8 *pOutBuffer2 = NULL;
196 int NStatus;
197 unsigned long Idx;
198 struct rt_frame_delba_req Frame;
199 unsigned long FrameLen;
200 struct rt_frame_bar FrameBar;
201
202 pInfo = (struct rt_mlme_delba_req *)Elem->Msg;
203 /* must send back DELBA */
204 NdisZeroMemory(&Frame, sizeof(struct rt_frame_delba_req));
205 DBGPRINT(RT_DEBUG_TRACE,
206 ("==> MlmeDELBAAction(), Initiator(%d) \n", pInfo->Initiator));
207
208 if (MlmeDelBAReqSanity(pAd, Elem->Msg, Elem->MsgLen)) {
209 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
210 if (NStatus != NDIS_STATUS_SUCCESS) {
211 DBGPRINT(RT_DEBUG_ERROR,
212 ("BA - MlmeDELBAAction() allocate memory failed 1. \n"));
213 return;
214 }
215
216 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); /*Get an unused nonpaged memory */
217 if (NStatus != NDIS_STATUS_SUCCESS) {
218 MlmeFreeMemory(pAd, pOutBuffer);
219 DBGPRINT(RT_DEBUG_ERROR,
220 ("BA - MlmeDELBAAction() allocate memory failed 2. \n"));
221 return;
222 }
223 /* SEND BAR (Send BAR to refresh peer reordering buffer.) */
224 Idx =
225 pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID];
226
227 BarHeaderInit(pAd, &FrameBar,
228 pAd->MacTab.Content[pInfo->Wcid].Addr,
229 pAd->CurrentAddress);
230
231 FrameBar.StartingSeq.field.FragNum = 0; /* make sure sequence not clear in DEL funciton. */
232 FrameBar.StartingSeq.field.StartSeq = pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID]; /* make sure sequence not clear in DEL funciton. */
233 FrameBar.BarControl.TID = pInfo->TID; /* make sure sequence not clear in DEL funciton. */
234 FrameBar.BarControl.ACKPolicy = IMMED_BA; /* make sure sequence not clear in DEL funciton. */
235 FrameBar.BarControl.Compressed = 1; /* make sure sequence not clear in DEL funciton. */
236 FrameBar.BarControl.MTID = 0; /* make sure sequence not clear in DEL funciton. */
237
238 MakeOutgoingFrame(pOutBuffer2, &FrameLen,
239 sizeof(struct rt_frame_bar), &FrameBar, END_OF_ARGS);
240 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen);
241 MlmeFreeMemory(pAd, pOutBuffer2);
242 DBGPRINT(RT_DEBUG_TRACE,
243 ("BA - MlmeDELBAAction() . Send BAR to refresh peer reordering buffer \n"));
244
245 /* SEND DELBA FRAME */
246 FrameLen = 0;
247
248 {
249 if (ADHOC_ON(pAd))
250 ActHeaderInit(pAd, &Frame.Hdr,
251 pAd->MacTab.Content[pInfo->Wcid].
252 Addr, pAd->CurrentAddress,
253 pAd->CommonCfg.Bssid);
254 else
255 ActHeaderInit(pAd, &Frame.Hdr,
256 pAd->CommonCfg.Bssid,
257 pAd->CurrentAddress,
258 pAd->MacTab.Content[pInfo->Wcid].
259 Addr);
260 }
261
262 Frame.Category = CATEGORY_BA;
263 Frame.Action = DELBA;
264 Frame.DelbaParm.Initiator = pInfo->Initiator;
265 Frame.DelbaParm.TID = pInfo->TID;
266 Frame.ReasonCode = 39; /* Time Out */
267 *(u16 *) (&Frame.DelbaParm) =
268 cpu2le16(*(u16 *) (&Frame.DelbaParm));
269 Frame.ReasonCode = cpu2le16(Frame.ReasonCode);
270
271 MakeOutgoingFrame(pOutBuffer, &FrameLen,
272 sizeof(struct rt_frame_delba_req), &Frame, END_OF_ARGS);
273 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
274 MlmeFreeMemory(pAd, pOutBuffer);
275 DBGPRINT(RT_DEBUG_TRACE,
276 ("BA - MlmeDELBAAction() . 3 DELBA sent. Initiator(%d)\n",
277 pInfo->Initiator));
278 }
279}
280
281void MlmeQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
282{
283}
284
285void MlmeDLSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
286{
287}
288
289void MlmeInvalidAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
290{
291 /*u8 * pOutBuffer = NULL; */
292 /*Return the receiving frame except the MSB of category filed set to 1. 7.3.1.11 */
293}
294
295void PeerQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
296{
297}
298
299void PeerBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
300{
301 u8 Action = Elem->Msg[LENGTH_802_11 + 1];
302
303 switch (Action) {
304 case ADDBA_REQ:
305 PeerAddBAReqAction(pAd, Elem);
306 break;
307 case ADDBA_RESP:
308 PeerAddBARspAction(pAd, Elem);
309 break;
310 case DELBA:
311 PeerDelBAAction(pAd, Elem);
312 break;
313 }
314}
315
316void PeerPublicAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
317{
318 if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
319 return;
320}
321
322static void ReservedAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
323{
324 u8 Category;
325
326 if (Elem->MsgLen <= LENGTH_802_11) {
327 return;
328 }
329
330 Category = Elem->Msg[LENGTH_802_11];
331 DBGPRINT(RT_DEBUG_TRACE,
332 ("Rcv reserved category(%d) Action Frame\n", Category));
333 hex_dump("Reserved Action Frame", &Elem->Msg[0], Elem->MsgLen);
334}
335
336void PeerRMAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
337{
338 return;
339}
340
341static void respond_ht_information_exchange_action(struct rt_rtmp_adapter *pAd,
342 struct rt_mlme_queue_elem *Elem)
343{
344 u8 *pOutBuffer = NULL;
345 int NStatus;
346 unsigned long FrameLen;
347 struct rt_frame_ht_info HTINFOframe, *pFrame;
348 u8 *pAddr;
349
350 /* 2. Always send back ADDBA Response */
351 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
352
353 if (NStatus != NDIS_STATUS_SUCCESS) {
354 DBGPRINT(RT_DEBUG_TRACE,
355 ("ACTION - respond_ht_information_exchange_action() allocate memory failed \n"));
356 return;
357 }
358 /* get RA */
359 pFrame = (struct rt_frame_ht_info *) & Elem->Msg[0];
360 pAddr = pFrame->Hdr.Addr2;
361
362 NdisZeroMemory(&HTINFOframe, sizeof(struct rt_frame_ht_info));
363 /* 2-1. Prepare ADDBA Response frame. */
364 {
365 if (ADHOC_ON(pAd))
366 ActHeaderInit(pAd, &HTINFOframe.Hdr, pAddr,
367 pAd->CurrentAddress,
368 pAd->CommonCfg.Bssid);
369 else
370 ActHeaderInit(pAd, &HTINFOframe.Hdr,
371 pAd->CommonCfg.Bssid, pAd->CurrentAddress,
372 pAddr);
373 }
374
375 HTINFOframe.Category = CATEGORY_HT;
376 HTINFOframe.Action = HT_INFO_EXCHANGE;
377 HTINFOframe.HT_Info.Request = 0;
378 HTINFOframe.HT_Info.Forty_MHz_Intolerant =
379 pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant;
380 HTINFOframe.HT_Info.STA_Channel_Width =
381 pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth;
382
383 MakeOutgoingFrame(pOutBuffer, &FrameLen,
384 sizeof(struct rt_frame_ht_info), &HTINFOframe, END_OF_ARGS);
385
386 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
387 MlmeFreeMemory(pAd, pOutBuffer);
388}
389
390void PeerHTAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
391{
392 u8 Action = Elem->Msg[LENGTH_802_11 + 1];
393
394 if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
395 return;
396
397 switch (Action) {
398 case NOTIFY_BW_ACTION:
399 DBGPRINT(RT_DEBUG_TRACE,
400 ("ACTION - HT Notify Channel bandwidth action----> \n"));
401
402 if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) {
403 /* Note, this is to patch DIR-1353 AP. When the AP set to Wep, it will use legacy mode. But AP still keeps */
404 /* sending BW_Notify Action frame, and cause us to linkup and linkdown. */
405 /* In legacy mode, don't need to parse HT action frame. */
406 DBGPRINT(RT_DEBUG_TRACE,
407 ("ACTION -Ignore HT Notify Channel BW when link as legacy mode. BW = %d---> \n",
408 Elem->Msg[LENGTH_802_11 + 2]));
409 break;
410 }
411
412 if (Elem->Msg[LENGTH_802_11 + 2] == 0) /* 7.4.8.2. if value is 1, keep the same as supported channel bandwidth. */
413 pAd->MacTab.Content[Elem->Wcid].HTPhyMode.field.BW = 0;
414
415 break;
416 case SMPS_ACTION:
417 /* 7.3.1.25 */
418 DBGPRINT(RT_DEBUG_TRACE, ("ACTION - SMPS action----> \n"));
419 if (((Elem->Msg[LENGTH_802_11 + 2] & 0x1) == 0)) {
420 pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_ENABLE;
421 } else if (((Elem->Msg[LENGTH_802_11 + 2] & 0x2) == 0)) {
422 pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_STATIC;
423 } else {
424 pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_DYNAMIC;
425 }
426
427 DBGPRINT(RT_DEBUG_TRACE,
428 ("Aid(%d) MIMO PS = %d\n", Elem->Wcid,
429 pAd->MacTab.Content[Elem->Wcid].MmpsMode));
430 /* rt2860c : add something for smps change. */
431 break;
432
433 case SETPCO_ACTION:
434 break;
435 case MIMO_CHA_MEASURE_ACTION:
436 break;
437 case HT_INFO_EXCHANGE:
438 {
439 struct rt_ht_information_octet *pHT_info;
440
441 pHT_info =
442 (struct rt_ht_information_octet *) & Elem->Msg[LENGTH_802_11 +
443 2];
444 /* 7.4.8.10 */
445 DBGPRINT(RT_DEBUG_TRACE,
446 ("ACTION - HT Information Exchange action----> \n"));
447 if (pHT_info->Request) {
448 respond_ht_information_exchange_action(pAd,
449 Elem);
450 }
451 }
452 break;
453 }
454}
455
456/*
457 ==========================================================================
458 Description:
459 Retry sending ADDBA Reqest.
460
461 IRQL = DISPATCH_LEVEL
462
463 Parametrs:
464 p8023Header: if this is already 802.3 format, p8023Header is NULL
465
466 Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
467 FALSE , then continue indicaterx at this moment.
468 ==========================================================================
469 */
470void ORIBATimerTimeout(struct rt_rtmp_adapter *pAd)
471{
472 struct rt_mac_table_entry *pEntry;
473 int i, total;
474 u8 TID;
475
476 total = pAd->MacTab.Size * NUM_OF_TID;
477
478 for (i = 1; ((i < MAX_LEN_OF_BA_ORI_TABLE) && (total > 0)); i++) {
479 if (pAd->BATable.BAOriEntry[i].ORI_BA_Status == Originator_Done) {
480 pEntry =
481 &pAd->MacTab.Content[pAd->BATable.BAOriEntry[i].
482 Wcid];
483 TID = pAd->BATable.BAOriEntry[i].TID;
484
485 ASSERT(pAd->BATable.BAOriEntry[i].Wcid <
486 MAX_LEN_OF_MAC_TABLE);
487 }
488 total--;
489 }
490}
491
492void SendRefreshBAR(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry)
493{
494 struct rt_frame_bar FrameBar;
495 unsigned long FrameLen;
496 int NStatus;
497 u8 *pOutBuffer = NULL;
498 u16 Sequence;
499 u8 i, TID;
500 u16 idx;
501 struct rt_ba_ori_entry *pBAEntry;
502
503 for (i = 0; i < NUM_OF_TID; i++) {
504 idx = pEntry->BAOriWcidArray[i];
505 if (idx == 0) {
506 continue;
507 }
508 pBAEntry = &pAd->BATable.BAOriEntry[idx];
509
510 if (pBAEntry->ORI_BA_Status == Originator_Done) {
511 TID = pBAEntry->TID;
512
513 ASSERT(pBAEntry->Wcid < MAX_LEN_OF_MAC_TABLE);
514
515 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
516 if (NStatus != NDIS_STATUS_SUCCESS) {
517 DBGPRINT(RT_DEBUG_ERROR,
518 ("BA - MlmeADDBAAction() allocate memory failed \n"));
519 return;
520 }
521
522 Sequence = pEntry->TxSeq[TID];
523
524 BarHeaderInit(pAd, &FrameBar, pEntry->Addr,
525 pAd->CurrentAddress);
526
527 FrameBar.StartingSeq.field.FragNum = 0; /* make sure sequence not clear in DEL function. */
528 FrameBar.StartingSeq.field.StartSeq = Sequence; /* make sure sequence not clear in DEL funciton. */
529 FrameBar.BarControl.TID = TID; /* make sure sequence not clear in DEL funciton. */
530
531 MakeOutgoingFrame(pOutBuffer, &FrameLen,
532 sizeof(struct rt_frame_bar), &FrameBar,
533 END_OF_ARGS);
534 /*if (!(CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_RALINK_CHIPSET))) */
535 if (1) /* Now we always send BAR. */
536 {
537 /*MiniportMMRequestUnlock(pAd, 0, pOutBuffer, FrameLen); */
538 MiniportMMRequest(pAd,
539 (MGMT_USE_QUEUE_FLAG |
540 MapUserPriorityToAccessCategory
541 [TID]), pOutBuffer,
542 FrameLen);
543
544 }
545 MlmeFreeMemory(pAd, pOutBuffer);
546 }
547 }
548}
549
550void ActHeaderInit(struct rt_rtmp_adapter *pAd,
551 struct rt_header_802_11 * pHdr80211,
552 u8 *Addr1, u8 *Addr2, u8 *Addr3)
553{
554 NdisZeroMemory(pHdr80211, sizeof(struct rt_header_802_11));
555 pHdr80211->FC.Type = BTYPE_MGMT;
556 pHdr80211->FC.SubType = SUBTYPE_ACTION;
557
558 COPY_MAC_ADDR(pHdr80211->Addr1, Addr1);
559 COPY_MAC_ADDR(pHdr80211->Addr2, Addr2);
560 COPY_MAC_ADDR(pHdr80211->Addr3, Addr3);
561}
562
563void BarHeaderInit(struct rt_rtmp_adapter *pAd,
564 struct rt_frame_bar * pCntlBar, u8 *pDA, u8 *pSA)
565{
566 NdisZeroMemory(pCntlBar, sizeof(struct rt_frame_bar));
567 pCntlBar->FC.Type = BTYPE_CNTL;
568 pCntlBar->FC.SubType = SUBTYPE_BLOCK_ACK_REQ;
569 pCntlBar->BarControl.MTID = 0;
570 pCntlBar->BarControl.Compressed = 1;
571 pCntlBar->BarControl.ACKPolicy = 0;
572
573 pCntlBar->Duration =
574 16 + RTMPCalcDuration(pAd, RATE_1, sizeof(struct rt_frame_ba));
575
576 COPY_MAC_ADDR(pCntlBar->Addr1, pDA);
577 COPY_MAC_ADDR(pCntlBar->Addr2, pSA);
578}
579
580/*
581 ==========================================================================
582 Description:
583 Insert Category and action code into the action frame.
584
585 Parametrs:
586 1. frame buffer pointer.
587 2. frame length.
588 3. category code of the frame.
589 4. action code of the frame.
590
591 Return : None.
592 ==========================================================================
593 */
594void InsertActField(struct rt_rtmp_adapter *pAd,
595 u8 *pFrameBuf,
596 unsigned long *pFrameLen, u8 Category, u8 ActCode)
597{
598 unsigned long TempLen;
599
600 MakeOutgoingFrame(pFrameBuf, &TempLen,
601 1, &Category, 1, &ActCode, END_OF_ARGS);
602
603 *pFrameLen = *pFrameLen + TempLen;
604
605 return;
606}
diff --git a/drivers/staging/rt2860/common/action.h b/drivers/staging/rt2860/common/action.h
deleted file mode 100644
index 974f8b84039..00000000000
--- a/drivers/staging/rt2860/common/action.h
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 aironet.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Paul Lin 04-06-15 Initial
37*/
38
39#ifndef __ACTION_H__
40#define __ACTION_H__
41
42struct PACKED rt_ht_information_octet {
43 u8 Request:1;
44 u8 Forty_MHz_Intolerant:1;
45 u8 STA_Channel_Width:1;
46 u8 Reserved:5;
47};
48
49struct PACKED rt_frame_ht_info {
50 struct rt_header_802_11 Hdr;
51 u8 Category;
52 u8 Action;
53 struct rt_ht_information_octet HT_Info;
54};
55
56#endif /* __ACTION_H__ */
diff --git a/drivers/staging/rt2860/common/ba_action.c b/drivers/staging/rt2860/common/ba_action.c
deleted file mode 100644
index 133bc1b87d2..00000000000
--- a/drivers/staging/rt2860/common/ba_action.c
+++ /dev/null
@@ -1,1650 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28#include "../rt_config.h"
29#include <linux/kernel.h>
30
31#define BA_ORI_INIT_SEQ (pEntry->TxSeq[TID]) /*1 // initial sequence number of BA session */
32
33#define ORI_SESSION_MAX_RETRY 8
34#define ORI_BA_SESSION_TIMEOUT (2000) /* ms */
35#define REC_BA_SESSION_IDLE_TIMEOUT (1000) /* ms */
36
37#define REORDERING_PACKET_TIMEOUT ((100 * OS_HZ)/1000) /* system ticks -- 100 ms */
38#define MAX_REORDERING_PACKET_TIMEOUT ((3000 * OS_HZ)/1000) /* system ticks -- 100 ms */
39
40#define RESET_RCV_SEQ (0xFFFF)
41
42static void ba_mpdu_blk_free(struct rt_rtmp_adapter *pAd,
43 struct reordering_mpdu *mpdu_blk);
44
45struct rt_ba_ori_entry *BATableAllocOriEntry(struct rt_rtmp_adapter *pAd, u16 * Idx);
46
47struct rt_ba_rec_entry *BATableAllocRecEntry(struct rt_rtmp_adapter *pAd, u16 * Idx);
48
49void BAOriSessionSetupTimeout(void *SystemSpecific1,
50 void *FunctionContext,
51 void *SystemSpecific2,
52 void *SystemSpecific3);
53
54void BARecSessionIdleTimeout(void *SystemSpecific1,
55 void *FunctionContext,
56 void *SystemSpecific2,
57 void *SystemSpecific3);
58
59BUILD_TIMER_FUNCTION(BAOriSessionSetupTimeout);
60BUILD_TIMER_FUNCTION(BARecSessionIdleTimeout);
61
62#define ANNOUNCE_REORDERING_PACKET(_pAd, _mpdu_blk) \
63 Announce_Reordering_Packet(_pAd, _mpdu_blk);
64
65void BA_MaxWinSizeReasign(struct rt_rtmp_adapter *pAd,
66 struct rt_mac_table_entry *pEntryPeer, u8 * pWinSize)
67{
68 u8 MaxSize;
69
70 if (pAd->MACVersion >= RALINK_2883_VERSION) /* 3*3 */
71 {
72 if (pAd->MACVersion >= RALINK_3070_VERSION) {
73 if (pEntryPeer->WepStatus !=
74 Ndis802_11EncryptionDisabled)
75 MaxSize = 7; /* for non-open mode */
76 else
77 MaxSize = 13;
78 } else
79 MaxSize = 31;
80 } else if (pAd->MACVersion >= RALINK_2880E_VERSION) /* 2880 e */
81 {
82 if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled)
83 MaxSize = 7; /* for non-open mode */
84 else
85 MaxSize = 13;
86 } else
87 MaxSize = 7;
88
89 DBGPRINT(RT_DEBUG_TRACE, ("ba> Win Size = %d, Max Size = %d\n",
90 *pWinSize, MaxSize));
91
92 if ((*pWinSize) > MaxSize) {
93 DBGPRINT(RT_DEBUG_TRACE,
94 ("ba> reassign max win size from %d to %d\n",
95 *pWinSize, MaxSize));
96
97 *pWinSize = MaxSize;
98 }
99}
100
101void Announce_Reordering_Packet(struct rt_rtmp_adapter *pAd,
102 IN struct reordering_mpdu *mpdu)
103{
104 void *pPacket;
105
106 pPacket = mpdu->pPacket;
107
108 if (mpdu->bAMSDU) {
109 ASSERT(0);
110 BA_Reorder_AMSDU_Announce(pAd, pPacket);
111 } else {
112 /* */
113 /* pass this 802.3 packet to upper layer or forward this packet to WM directly */
114 /* */
115
116 ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket,
117 RTMP_GET_PACKET_IF(pPacket));
118 }
119}
120
121/*
122 * Insert a reordering mpdu into sorted linked list by sequence no.
123 */
124BOOLEAN ba_reordering_mpdu_insertsorted(struct reordering_list *list,
125 struct reordering_mpdu *mpdu)
126{
127
128 struct reordering_mpdu **ppScan = &list->next;
129
130 while (*ppScan != NULL) {
131 if (SEQ_SMALLER((*ppScan)->Sequence, mpdu->Sequence, MAXSEQ)) {
132 ppScan = &(*ppScan)->next;
133 } else if ((*ppScan)->Sequence == mpdu->Sequence) {
134 /* give up this duplicated frame */
135 return (FALSE);
136 } else {
137 /* find position */
138 break;
139 }
140 }
141
142 mpdu->next = *ppScan;
143 *ppScan = mpdu;
144 list->qlen++;
145 return TRUE;
146}
147
148/*
149 * caller lock critical section if necessary
150 */
151static inline void ba_enqueue(struct reordering_list *list,
152 struct reordering_mpdu *mpdu_blk)
153{
154 list->qlen++;
155 mpdu_blk->next = list->next;
156 list->next = mpdu_blk;
157}
158
159/*
160 * caller lock critical section if necessary
161 */
162static inline struct reordering_mpdu *ba_dequeue(struct reordering_list *list)
163{
164 struct reordering_mpdu *mpdu_blk = NULL;
165
166 ASSERT(list);
167
168 if (list->qlen) {
169 list->qlen--;
170 mpdu_blk = list->next;
171 if (mpdu_blk) {
172 list->next = mpdu_blk->next;
173 mpdu_blk->next = NULL;
174 }
175 }
176 return mpdu_blk;
177}
178
179static inline struct reordering_mpdu *ba_reordering_mpdu_dequeue(struct
180 reordering_list
181 *list)
182{
183 return (ba_dequeue(list));
184}
185
186static inline struct reordering_mpdu *ba_reordering_mpdu_probe(struct
187 reordering_list
188 *list)
189{
190 ASSERT(list);
191
192 return (list->next);
193}
194
195/*
196 * free all resource for reordering mechanism
197 */
198void ba_reordering_resource_release(struct rt_rtmp_adapter *pAd)
199{
200 struct rt_ba_table *Tab;
201 struct rt_ba_rec_entry *pBAEntry;
202 struct reordering_mpdu *mpdu_blk;
203 int i;
204
205 Tab = &pAd->BATable;
206
207 /* I. release all pending reordering packet */
208 NdisAcquireSpinLock(&pAd->BATabLock);
209 for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++) {
210 pBAEntry = &Tab->BARecEntry[i];
211 if (pBAEntry->REC_BA_Status != Recipient_NONE) {
212 while ((mpdu_blk =
213 ba_reordering_mpdu_dequeue(&pBAEntry->list))) {
214 ASSERT(mpdu_blk->pPacket);
215 RELEASE_NDIS_PACKET(pAd, mpdu_blk->pPacket,
216 NDIS_STATUS_FAILURE);
217 ba_mpdu_blk_free(pAd, mpdu_blk);
218 }
219 }
220 }
221 NdisReleaseSpinLock(&pAd->BATabLock);
222
223 ASSERT(pBAEntry->list.qlen == 0);
224 /* II. free memory of reordering mpdu table */
225 NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
226 os_free_mem(pAd, pAd->mpdu_blk_pool.mem);
227 NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
228}
229
230/*
231 * Allocate all resource for reordering mechanism
232 */
233BOOLEAN ba_reordering_resource_init(struct rt_rtmp_adapter *pAd, int num)
234{
235 int i;
236 u8 *mem;
237 struct reordering_mpdu *mpdu_blk;
238 struct reordering_list *freelist;
239
240 /* allocate spinlock */
241 NdisAllocateSpinLock(&pAd->mpdu_blk_pool.lock);
242
243 /* initialize freelist */
244 freelist = &pAd->mpdu_blk_pool.freelist;
245 freelist->next = NULL;
246 freelist->qlen = 0;
247
248 DBGPRINT(RT_DEBUG_TRACE,
249 ("Allocate %d memory for BA reordering\n",
250 (u32)(num * sizeof(struct reordering_mpdu))));
251
252 /* allocate number of mpdu_blk memory */
253 os_alloc_mem(pAd, (u8 **) & mem,
254 (num * sizeof(struct reordering_mpdu)));
255
256 pAd->mpdu_blk_pool.mem = mem;
257
258 if (mem == NULL) {
259 DBGPRINT(RT_DEBUG_ERROR,
260 ("Can't Allocate Memory for BA Reordering\n"));
261 return (FALSE);
262 }
263
264 /* build mpdu_blk free list */
265 for (i = 0; i < num; i++) {
266 /* get mpdu_blk */
267 mpdu_blk = (struct reordering_mpdu *)mem;
268 /* initial mpdu_blk */
269 NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu));
270 /* next mpdu_blk */
271 mem += sizeof(struct reordering_mpdu);
272 /* insert mpdu_blk into freelist */
273 ba_enqueue(freelist, mpdu_blk);
274 }
275
276 return (TRUE);
277}
278
279/*static int blk_count=0; // sample take off, no use */
280
281static struct reordering_mpdu *ba_mpdu_blk_alloc(struct rt_rtmp_adapter *pAd)
282{
283 struct reordering_mpdu *mpdu_blk;
284
285 NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
286 mpdu_blk = ba_dequeue(&pAd->mpdu_blk_pool.freelist);
287 if (mpdu_blk) {
288/* blk_count++; */
289 /* reset mpdu_blk */
290 NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu));
291 }
292 NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
293 return mpdu_blk;
294}
295
296static void ba_mpdu_blk_free(struct rt_rtmp_adapter *pAd,
297 struct reordering_mpdu *mpdu_blk)
298{
299 ASSERT(mpdu_blk);
300
301 NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock);
302/* blk_count--; */
303 ba_enqueue(&pAd->mpdu_blk_pool.freelist, mpdu_blk);
304 NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock);
305}
306
307static u16 ba_indicate_reordering_mpdus_in_order(struct rt_rtmp_adapter *pAd,
308 struct rt_ba_rec_entry *pBAEntry,
309 u16 StartSeq)
310{
311 struct reordering_mpdu *mpdu_blk;
312 u16 LastIndSeq = RESET_RCV_SEQ;
313
314 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
315
316 while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list))) {
317 /* find in-order frame */
318 if (!SEQ_STEPONE(mpdu_blk->Sequence, StartSeq, MAXSEQ)) {
319 break;
320 }
321 /* dequeue in-order frame from reodering list */
322 mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list);
323 /* pass this frame up */
324 ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
325 /* move to next sequence */
326 StartSeq = mpdu_blk->Sequence;
327 LastIndSeq = StartSeq;
328 /* free mpdu_blk */
329 ba_mpdu_blk_free(pAd, mpdu_blk);
330 }
331
332 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
333
334 /* update last indicated sequence */
335 return LastIndSeq;
336}
337
338static void ba_indicate_reordering_mpdus_le_seq(struct rt_rtmp_adapter *pAd,
339 struct rt_ba_rec_entry *pBAEntry,
340 u16 Sequence)
341{
342 struct reordering_mpdu *mpdu_blk;
343
344 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
345 while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list))) {
346 /* find in-order frame */
347 if ((mpdu_blk->Sequence == Sequence)
348 || SEQ_SMALLER(mpdu_blk->Sequence, Sequence, MAXSEQ)) {
349 /* dequeue in-order frame from reodering list */
350 mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list);
351 /* pass this frame up */
352 ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
353 /* free mpdu_blk */
354 ba_mpdu_blk_free(pAd, mpdu_blk);
355 } else {
356 break;
357 }
358 }
359 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
360}
361
362static void ba_refresh_reordering_mpdus(struct rt_rtmp_adapter *pAd,
363 struct rt_ba_rec_entry *pBAEntry)
364{
365 struct reordering_mpdu *mpdu_blk;
366
367 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
368
369 /* dequeue in-order frame from reodering list */
370 while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list))) {
371 /* pass this frame up */
372 ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk);
373
374 pBAEntry->LastIndSeq = mpdu_blk->Sequence;
375 ba_mpdu_blk_free(pAd, mpdu_blk);
376
377 /* update last indicated sequence */
378 }
379 ASSERT(pBAEntry->list.qlen == 0);
380 pBAEntry->LastIndSeq = RESET_RCV_SEQ;
381 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
382}
383
384/*static */
385void ba_flush_reordering_timeout_mpdus(struct rt_rtmp_adapter *pAd,
386 struct rt_ba_rec_entry *pBAEntry,
387 unsigned long Now32)
388{
389 u16 Sequence;
390
391/* if ((RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+REORDERING_PACKET_TIMEOUT)) && */
392/* (pBAEntry->list.qlen > ((pBAEntry->BAWinSize*7)/8))) //|| */
393/* (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(10*REORDERING_PACKET_TIMEOUT))) && */
394/* (pBAEntry->list.qlen > (pBAEntry->BAWinSize/8))) */
395 if (RTMP_TIME_AFTER
396 ((unsigned long)Now32,
397 (unsigned long)(pBAEntry->LastIndSeqAtTimer +
398 (MAX_REORDERING_PACKET_TIMEOUT / 6)))
399 && (pBAEntry->list.qlen > 1)
400 ) {
401 DBGPRINT(RT_DEBUG_TRACE,
402 ("timeout[%d] (%08lx-%08lx = %d > %d): %x, flush all!\n ",
403 pBAEntry->list.qlen, Now32,
404 (pBAEntry->LastIndSeqAtTimer),
405 (int)((long)Now32 -
406 (long)(pBAEntry->LastIndSeqAtTimer)),
407 MAX_REORDERING_PACKET_TIMEOUT, pBAEntry->LastIndSeq));
408 ba_refresh_reordering_mpdus(pAd, pBAEntry);
409 pBAEntry->LastIndSeqAtTimer = Now32;
410 } else
411 if (RTMP_TIME_AFTER
412 ((unsigned long)Now32,
413 (unsigned long)(pBAEntry->LastIndSeqAtTimer +
414 (REORDERING_PACKET_TIMEOUT)))
415 && (pBAEntry->list.qlen > 0)
416 ) {
417 /* */
418 /* force LastIndSeq to shift to LastIndSeq+1 */
419 /* */
420 Sequence = (pBAEntry->LastIndSeq + 1) & MAXSEQ;
421 ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence);
422 pBAEntry->LastIndSeqAtTimer = Now32;
423 pBAEntry->LastIndSeq = Sequence;
424 /* */
425 /* indicate in-order mpdus */
426 /* */
427 Sequence =
428 ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry,
429 Sequence);
430 if (Sequence != RESET_RCV_SEQ) {
431 pBAEntry->LastIndSeq = Sequence;
432 }
433
434 DBGPRINT(RT_DEBUG_OFF,
435 ("%x, flush one!\n", pBAEntry->LastIndSeq));
436
437 }
438}
439
440/*
441 * generate ADDBA request to
442 * set up BA agreement
443 */
444void BAOriSessionSetUp(struct rt_rtmp_adapter *pAd,
445 struct rt_mac_table_entry *pEntry,
446 u8 TID,
447 u16 TimeOut,
448 unsigned long DelayTime, IN BOOLEAN isForced)
449{
450 /*struct rt_mlme_addba_req AddbaReq; */
451 struct rt_ba_ori_entry *pBAEntry = NULL;
452 u16 Idx;
453 BOOLEAN Cancelled;
454
455 if ((pAd->CommonCfg.BACapability.field.AutoBA != TRUE)
456 && (isForced == FALSE))
457 return;
458
459 /* if this entry is limited to use legacy tx mode, it doesn't generate BA. */
460 if (RTMPStaFixedTxMode(pAd, pEntry) != FIXED_TXMODE_HT)
461 return;
462
463 if ((pEntry->BADeclineBitmap & (1 << TID)) && (isForced == FALSE)) {
464 /* try again after 3 secs */
465 DelayTime = 3000;
466/* DBGPRINT(RT_DEBUG_TRACE, ("DeCline BA from Peer\n")); */
467/* return; */
468 }
469
470 Idx = pEntry->BAOriWcidArray[TID];
471 if (Idx == 0) {
472 /* allocate a BA session */
473 pBAEntry = BATableAllocOriEntry(pAd, &Idx);
474 if (pBAEntry == NULL) {
475 DBGPRINT(RT_DEBUG_TRACE,
476 ("ADDBA - MlmeADDBAAction() allocate BA session failed \n"));
477 return;
478 }
479 } else {
480 pBAEntry = &pAd->BATable.BAOriEntry[Idx];
481 }
482
483 if (pBAEntry->ORI_BA_Status >= Originator_WaitRes) {
484 return;
485 }
486
487 pEntry->BAOriWcidArray[TID] = Idx;
488
489 /* Initialize BA session */
490 pBAEntry->ORI_BA_Status = Originator_WaitRes;
491 pBAEntry->Wcid = pEntry->Aid;
492 pBAEntry->BAWinSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit;
493 pBAEntry->Sequence = BA_ORI_INIT_SEQ;
494 pBAEntry->Token = 1; /* (2008-01-21) Jan Lee recommends it - this token can't be 0 */
495 pBAEntry->TID = TID;
496 pBAEntry->TimeOutValue = TimeOut;
497 pBAEntry->pAdapter = pAd;
498
499 if (!(pEntry->TXBAbitmap & (1 << TID))) {
500 RTMPInitTimer(pAd, &pBAEntry->ORIBATimer,
501 GET_TIMER_FUNCTION(BAOriSessionSetupTimeout),
502 pBAEntry, FALSE);
503 } else
504 RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
505
506 /* set timer to send ADDBA request */
507 RTMPSetTimer(&pBAEntry->ORIBATimer, DelayTime);
508}
509
510void BAOriSessionAdd(struct rt_rtmp_adapter *pAd,
511 struct rt_mac_table_entry *pEntry, struct rt_frame_addba_rsp * pFrame)
512{
513 struct rt_ba_ori_entry *pBAEntry = NULL;
514 BOOLEAN Cancelled;
515 u8 TID;
516 u16 Idx;
517 u8 *pOutBuffer2 = NULL;
518 int NStatus;
519 unsigned long FrameLen;
520 struct rt_frame_bar FrameBar;
521
522 TID = pFrame->BaParm.TID;
523 Idx = pEntry->BAOriWcidArray[TID];
524 pBAEntry = &pAd->BATable.BAOriEntry[Idx];
525
526 /* Start fill in parameters. */
527 if ((Idx != 0) && (pBAEntry->TID == TID)
528 && (pBAEntry->ORI_BA_Status == Originator_WaitRes)) {
529 pBAEntry->BAWinSize =
530 min(pBAEntry->BAWinSize, ((u8)pFrame->BaParm.BufSize));
531 BA_MaxWinSizeReasign(pAd, pEntry, &pBAEntry->BAWinSize);
532
533 pBAEntry->TimeOutValue = pFrame->TimeOutValue;
534 pBAEntry->ORI_BA_Status = Originator_Done;
535 pAd->BATable.numDoneOriginator++;
536
537 /* reset sequence number */
538 pBAEntry->Sequence = BA_ORI_INIT_SEQ;
539 /* Set Bitmap flag. */
540 pEntry->TXBAbitmap |= (1 << TID);
541 RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
542
543 pBAEntry->ORIBATimer.TimerValue = 0; /*pFrame->TimeOutValue; */
544
545 DBGPRINT(RT_DEBUG_TRACE,
546 ("%s : TXBAbitmap = %x, BAWinSize = %d, TimeOut = %ld\n",
547 __func__, pEntry->TXBAbitmap, pBAEntry->BAWinSize,
548 pBAEntry->ORIBATimer.TimerValue));
549
550 /* SEND BAR ; */
551 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); /*Get an unused nonpaged memory */
552 if (NStatus != NDIS_STATUS_SUCCESS) {
553 DBGPRINT(RT_DEBUG_TRACE,
554 ("BA - BAOriSessionAdd() allocate memory failed \n"));
555 return;
556 }
557
558 BarHeaderInit(pAd, &FrameBar,
559 pAd->MacTab.Content[pBAEntry->Wcid].Addr,
560 pAd->CurrentAddress);
561
562 FrameBar.StartingSeq.field.FragNum = 0; /* make sure sequence not clear in DEL function. */
563 FrameBar.StartingSeq.field.StartSeq = pBAEntry->Sequence; /* make sure sequence not clear in DEL funciton. */
564 FrameBar.BarControl.TID = pBAEntry->TID; /* make sure sequence not clear in DEL funciton. */
565 MakeOutgoingFrame(pOutBuffer2, &FrameLen,
566 sizeof(struct rt_frame_bar), &FrameBar, END_OF_ARGS);
567 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen);
568 MlmeFreeMemory(pAd, pOutBuffer2);
569
570 if (pBAEntry->ORIBATimer.TimerValue)
571 RTMPSetTimer(&pBAEntry->ORIBATimer, pBAEntry->ORIBATimer.TimerValue); /* in mSec */
572 }
573}
574
575BOOLEAN BARecSessionAdd(struct rt_rtmp_adapter *pAd,
576 struct rt_mac_table_entry *pEntry, struct rt_frame_addba_req * pFrame)
577{
578 struct rt_ba_rec_entry *pBAEntry = NULL;
579 BOOLEAN Status = TRUE;
580 BOOLEAN Cancelled;
581 u16 Idx;
582 u8 TID;
583 u8 BAWinSize;
584 /*u32 Value; */
585 /*u32 offset; */
586
587 ASSERT(pEntry);
588
589 /* find TID */
590 TID = pFrame->BaParm.TID;
591
592 BAWinSize =
593 min(((u8)pFrame->BaParm.BufSize),
594 (u8)pAd->CommonCfg.BACapability.field.RxBAWinLimit);
595
596 /* Intel patch */
597 if (BAWinSize == 0) {
598 BAWinSize = 64;
599 }
600
601 Idx = pEntry->BARecWcidArray[TID];
602
603 if (Idx == 0) {
604 pBAEntry = BATableAllocRecEntry(pAd, &Idx);
605 } else {
606 pBAEntry = &pAd->BATable.BARecEntry[Idx];
607 /* flush all pending reordering mpdus */
608 ba_refresh_reordering_mpdus(pAd, pBAEntry);
609 }
610
611 DBGPRINT(RT_DEBUG_TRACE,
612 ("%s(%ld): Idx = %d, BAWinSize(req %d) = %d\n", __func__,
613 pAd->BATable.numAsRecipient, Idx, pFrame->BaParm.BufSize,
614 BAWinSize));
615
616 /* Start fill in parameters. */
617 if (pBAEntry != NULL) {
618 ASSERT(pBAEntry->list.qlen == 0);
619
620 pBAEntry->REC_BA_Status = Recipient_HandleRes;
621 pBAEntry->BAWinSize = BAWinSize;
622 pBAEntry->Wcid = pEntry->Aid;
623 pBAEntry->TID = TID;
624 pBAEntry->TimeOutValue = pFrame->TimeOutValue;
625 pBAEntry->REC_BA_Status = Recipient_Accept;
626 /* initial sequence number */
627 pBAEntry->LastIndSeq = RESET_RCV_SEQ; /*pFrame->BaStartSeq.field.StartSeq; */
628
629 DBGPRINT(RT_DEBUG_OFF,
630 ("Start Seq = %08x\n",
631 pFrame->BaStartSeq.field.StartSeq));
632
633 if (pEntry->RXBAbitmap & (1 << TID)) {
634 RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled);
635 } else {
636 RTMPInitTimer(pAd, &pBAEntry->RECBATimer,
637 GET_TIMER_FUNCTION
638 (BARecSessionIdleTimeout), pBAEntry,
639 TRUE);
640 }
641
642 /* Set Bitmap flag. */
643 pEntry->RXBAbitmap |= (1 << TID);
644 pEntry->BARecWcidArray[TID] = Idx;
645
646 pEntry->BADeclineBitmap &= ~(1 << TID);
647
648 /* Set BA session mask in WCID table. */
649 RTMP_ADD_BA_SESSION_TO_ASIC(pAd, pEntry->Aid, TID);
650
651 DBGPRINT(RT_DEBUG_TRACE,
652 ("MACEntry[%d]RXBAbitmap = 0x%x. BARecWcidArray=%d\n",
653 pEntry->Aid, pEntry->RXBAbitmap,
654 pEntry->BARecWcidArray[TID]));
655 } else {
656 Status = FALSE;
657 DBGPRINT(RT_DEBUG_TRACE,
658 ("Can't Accept ADDBA for %pM TID = %d\n",
659 pEntry->Addr, TID));
660 }
661 return (Status);
662}
663
664struct rt_ba_rec_entry *BATableAllocRecEntry(struct rt_rtmp_adapter *pAd, u16 * Idx)
665{
666 int i;
667 struct rt_ba_rec_entry *pBAEntry = NULL;
668
669 NdisAcquireSpinLock(&pAd->BATabLock);
670
671 if (pAd->BATable.numAsRecipient >= MAX_BARECI_SESSION) {
672 DBGPRINT(RT_DEBUG_OFF, ("BA Recipeint Session (%ld) > %d\n",
673 pAd->BATable.numAsRecipient,
674 MAX_BARECI_SESSION));
675 goto done;
676 }
677 /* reserve idx 0 to identify BAWcidArray[TID] as empty */
678 for (i = 1; i < MAX_LEN_OF_BA_REC_TABLE; i++) {
679 pBAEntry = &pAd->BATable.BARecEntry[i];
680 if ((pBAEntry->REC_BA_Status == Recipient_NONE)) {
681 /* get one */
682 pAd->BATable.numAsRecipient++;
683 pBAEntry->REC_BA_Status = Recipient_USED;
684 *Idx = i;
685 break;
686 }
687 }
688
689done:
690 NdisReleaseSpinLock(&pAd->BATabLock);
691 return pBAEntry;
692}
693
694struct rt_ba_ori_entry *BATableAllocOriEntry(struct rt_rtmp_adapter *pAd, u16 * Idx)
695{
696 int i;
697 struct rt_ba_ori_entry *pBAEntry = NULL;
698
699 NdisAcquireSpinLock(&pAd->BATabLock);
700
701 if (pAd->BATable.numAsOriginator >= (MAX_LEN_OF_BA_ORI_TABLE)) {
702 goto done;
703 }
704 /* reserve idx 0 to identify BAWcidArray[TID] as empty */
705 for (i = 1; i < MAX_LEN_OF_BA_ORI_TABLE; i++) {
706 pBAEntry = &pAd->BATable.BAOriEntry[i];
707 if ((pBAEntry->ORI_BA_Status == Originator_NONE)) {
708 /* get one */
709 pAd->BATable.numAsOriginator++;
710 pBAEntry->ORI_BA_Status = Originator_USED;
711 pBAEntry->pAdapter = pAd;
712 *Idx = i;
713 break;
714 }
715 }
716
717done:
718 NdisReleaseSpinLock(&pAd->BATabLock);
719 return pBAEntry;
720}
721
722void BATableFreeOriEntry(struct rt_rtmp_adapter *pAd, unsigned long Idx)
723{
724 struct rt_ba_ori_entry *pBAEntry = NULL;
725 struct rt_mac_table_entry *pEntry;
726
727 if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE))
728 return;
729
730 pBAEntry = &pAd->BATable.BAOriEntry[Idx];
731
732 if (pBAEntry->ORI_BA_Status != Originator_NONE) {
733 pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
734 pEntry->BAOriWcidArray[pBAEntry->TID] = 0;
735
736 NdisAcquireSpinLock(&pAd->BATabLock);
737 if (pBAEntry->ORI_BA_Status == Originator_Done) {
738 pAd->BATable.numDoneOriginator -= 1;
739 pEntry->TXBAbitmap &= (~(1 << (pBAEntry->TID)));
740 DBGPRINT(RT_DEBUG_TRACE,
741 ("BATableFreeOriEntry numAsOriginator= %ld\n",
742 pAd->BATable.numAsRecipient));
743 /* Erase Bitmap flag. */
744 }
745
746 ASSERT(pAd->BATable.numAsOriginator != 0);
747
748 pAd->BATable.numAsOriginator -= 1;
749
750 pBAEntry->ORI_BA_Status = Originator_NONE;
751 pBAEntry->Token = 0;
752 NdisReleaseSpinLock(&pAd->BATabLock);
753 }
754}
755
756void BATableFreeRecEntry(struct rt_rtmp_adapter *pAd, unsigned long Idx)
757{
758 struct rt_ba_rec_entry *pBAEntry = NULL;
759 struct rt_mac_table_entry *pEntry;
760
761 if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_REC_TABLE))
762 return;
763
764 pBAEntry = &pAd->BATable.BARecEntry[Idx];
765
766 if (pBAEntry->REC_BA_Status != Recipient_NONE) {
767 pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
768 pEntry->BARecWcidArray[pBAEntry->TID] = 0;
769
770 NdisAcquireSpinLock(&pAd->BATabLock);
771
772 ASSERT(pAd->BATable.numAsRecipient != 0);
773
774 pAd->BATable.numAsRecipient -= 1;
775
776 pBAEntry->REC_BA_Status = Recipient_NONE;
777 NdisReleaseSpinLock(&pAd->BATabLock);
778 }
779}
780
781void BAOriSessionTearDown(struct rt_rtmp_adapter *pAd,
782 u8 Wcid,
783 u8 TID,
784 IN BOOLEAN bPassive, IN BOOLEAN bForceSend)
785{
786 unsigned long Idx = 0;
787 struct rt_ba_ori_entry *pBAEntry;
788 BOOLEAN Cancelled;
789
790 if (Wcid >= MAX_LEN_OF_MAC_TABLE) {
791 return;
792 }
793 /* */
794 /* Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID). */
795 /* */
796 Idx = pAd->MacTab.Content[Wcid].BAOriWcidArray[TID];
797 if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE)) {
798 if (bForceSend == TRUE) {
799 /* force send specified TID DelBA */
800 struct rt_mlme_delba_req DelbaReq;
801 struct rt_mlme_queue_elem *Elem =
802 kmalloc(sizeof(struct rt_mlme_queue_elem),
803 MEM_ALLOC_FLAG);
804 if (Elem != NULL) {
805 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
806 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem));
807
808 COPY_MAC_ADDR(DelbaReq.Addr,
809 pAd->MacTab.Content[Wcid].Addr);
810 DelbaReq.Wcid = Wcid;
811 DelbaReq.TID = TID;
812 DelbaReq.Initiator = ORIGINATOR;
813 Elem->MsgLen = sizeof(DelbaReq);
814 NdisMoveMemory(Elem->Msg, &DelbaReq,
815 sizeof(DelbaReq));
816 MlmeDELBAAction(pAd, Elem);
817 kfree(Elem);
818 } else {
819 DBGPRINT(RT_DEBUG_ERROR,
820 ("%s(bForceSend):alloc memory failed!\n",
821 __func__));
822 }
823 }
824
825 return;
826 }
827
828 DBGPRINT(RT_DEBUG_TRACE,
829 ("%s===>Wcid=%d.TID=%d \n", __func__, Wcid, TID));
830
831 pBAEntry = &pAd->BATable.BAOriEntry[Idx];
832 DBGPRINT(RT_DEBUG_TRACE,
833 ("\t===>Idx = %ld, Wcid=%d.TID=%d, ORI_BA_Status = %d \n", Idx,
834 Wcid, TID, pBAEntry->ORI_BA_Status));
835 /* */
836 /* Prepare DelBA action frame and send to the peer. */
837 /* */
838 if ((bPassive == FALSE) && (TID == pBAEntry->TID)
839 && (pBAEntry->ORI_BA_Status == Originator_Done)) {
840 struct rt_mlme_delba_req DelbaReq;
841 struct rt_mlme_queue_elem *Elem =
842 kmalloc(sizeof(struct rt_mlme_queue_elem),
843 MEM_ALLOC_FLAG);
844 if (Elem != NULL) {
845 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
846 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem));
847
848 COPY_MAC_ADDR(DelbaReq.Addr,
849 pAd->MacTab.Content[Wcid].Addr);
850 DelbaReq.Wcid = Wcid;
851 DelbaReq.TID = pBAEntry->TID;
852 DelbaReq.Initiator = ORIGINATOR;
853 Elem->MsgLen = sizeof(DelbaReq);
854 NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq));
855 MlmeDELBAAction(pAd, Elem);
856 kfree(Elem);
857 } else {
858 DBGPRINT(RT_DEBUG_ERROR,
859 ("%s():alloc memory failed!\n", __func__));
860 return;
861 }
862 }
863 RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled);
864 BATableFreeOriEntry(pAd, Idx);
865
866 if (bPassive) {
867 /*BAOriSessionSetUp(pAd, &pAd->MacTab.Content[Wcid], TID, 0, 10000, TRUE); */
868 }
869}
870
871void BARecSessionTearDown(struct rt_rtmp_adapter *pAd,
872 u8 Wcid, u8 TID, IN BOOLEAN bPassive)
873{
874 unsigned long Idx = 0;
875 struct rt_ba_rec_entry *pBAEntry;
876
877 if (Wcid >= MAX_LEN_OF_MAC_TABLE) {
878 return;
879 }
880 /* */
881 /* Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID). */
882 /* */
883 Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
884 if (Idx == 0)
885 return;
886
887 DBGPRINT(RT_DEBUG_TRACE,
888 ("%s===>Wcid=%d.TID=%d \n", __func__, Wcid, TID));
889
890 pBAEntry = &pAd->BATable.BARecEntry[Idx];
891 DBGPRINT(RT_DEBUG_TRACE,
892 ("\t===>Idx = %ld, Wcid=%d.TID=%d, REC_BA_Status = %d \n", Idx,
893 Wcid, TID, pBAEntry->REC_BA_Status));
894 /* */
895 /* Prepare DelBA action frame and send to the peer. */
896 /* */
897 if ((TID == pBAEntry->TID)
898 && (pBAEntry->REC_BA_Status == Recipient_Accept)) {
899 struct rt_mlme_delba_req DelbaReq;
900 BOOLEAN Cancelled;
901 /*unsigned long offset; */
902 /*u32 VALUE; */
903
904 RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled);
905
906 /* */
907 /* 1. Send DELBA Action Frame */
908 /* */
909 if (bPassive == FALSE) {
910 struct rt_mlme_queue_elem *Elem =
911 kmalloc(sizeof(struct rt_mlme_queue_elem),
912 MEM_ALLOC_FLAG);
913 if (Elem != NULL) {
914 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
915 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem));
916
917 COPY_MAC_ADDR(DelbaReq.Addr,
918 pAd->MacTab.Content[Wcid].Addr);
919 DelbaReq.Wcid = Wcid;
920 DelbaReq.TID = TID;
921 DelbaReq.Initiator = RECIPIENT;
922 Elem->MsgLen = sizeof(DelbaReq);
923 NdisMoveMemory(Elem->Msg, &DelbaReq,
924 sizeof(DelbaReq));
925 MlmeDELBAAction(pAd, Elem);
926 kfree(Elem);
927 } else {
928 DBGPRINT(RT_DEBUG_ERROR,
929 ("%s():alloc memory failed!\n",
930 __func__));
931 return;
932 }
933 }
934
935 /* */
936 /* 2. Free resource of BA session */
937 /* */
938 /* flush all pending reordering mpdus */
939 ba_refresh_reordering_mpdus(pAd, pBAEntry);
940
941 NdisAcquireSpinLock(&pAd->BATabLock);
942
943 /* Erase Bitmap flag. */
944 pBAEntry->LastIndSeq = RESET_RCV_SEQ;
945 pBAEntry->BAWinSize = 0;
946 /* Erase Bitmap flag at software mactable */
947 pAd->MacTab.Content[Wcid].RXBAbitmap &=
948 (~(1 << (pBAEntry->TID)));
949 pAd->MacTab.Content[Wcid].BARecWcidArray[TID] = 0;
950
951 RTMP_DEL_BA_SESSION_FROM_ASIC(pAd, Wcid, TID);
952
953 NdisReleaseSpinLock(&pAd->BATabLock);
954
955 }
956
957 BATableFreeRecEntry(pAd, Idx);
958}
959
960void BASessionTearDownALL(struct rt_rtmp_adapter *pAd, u8 Wcid)
961{
962 int i;
963
964 for (i = 0; i < NUM_OF_TID; i++) {
965 BAOriSessionTearDown(pAd, Wcid, i, FALSE, FALSE);
966 BARecSessionTearDown(pAd, Wcid, i, FALSE);
967 }
968}
969
970/*
971 ==========================================================================
972 Description:
973 Retry sending ADDBA Reqest.
974
975 IRQL = DISPATCH_LEVEL
976
977 Parametrs:
978 p8023Header: if this is already 802.3 format, p8023Header is NULL
979
980 Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
981 FALSE , then continue indicaterx at this moment.
982 ==========================================================================
983 */
984void BAOriSessionSetupTimeout(void *SystemSpecific1,
985 void *FunctionContext,
986 void *SystemSpecific2,
987 void *SystemSpecific3)
988{
989 struct rt_ba_ori_entry *pBAEntry = (struct rt_ba_ori_entry *)FunctionContext;
990 struct rt_mac_table_entry *pEntry;
991 struct rt_rtmp_adapter *pAd;
992
993 if (pBAEntry == NULL)
994 return;
995
996 pAd = pBAEntry->pAdapter;
997
998 {
999 /* Do nothing if monitor mode is on */
1000 if (MONITOR_ON(pAd))
1001 return;
1002 }
1003
1004 pEntry = &pAd->MacTab.Content[pBAEntry->Wcid];
1005
1006 if ((pBAEntry->ORI_BA_Status == Originator_WaitRes)
1007 && (pBAEntry->Token < ORI_SESSION_MAX_RETRY)) {
1008 struct rt_mlme_addba_req AddbaReq;
1009
1010 NdisZeroMemory(&AddbaReq, sizeof(AddbaReq));
1011 COPY_MAC_ADDR(AddbaReq.pAddr, pEntry->Addr);
1012 AddbaReq.Wcid = (u8)(pEntry->Aid);
1013 AddbaReq.TID = pBAEntry->TID;
1014 AddbaReq.BaBufSize =
1015 pAd->CommonCfg.BACapability.field.RxBAWinLimit;
1016 AddbaReq.TimeOutValue = 0;
1017 AddbaReq.Token = pBAEntry->Token;
1018 MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ADD_BA_CATE,
1019 sizeof(struct rt_mlme_addba_req), (void *)& AddbaReq);
1020 RTMP_MLME_HANDLER(pAd);
1021 DBGPRINT(RT_DEBUG_TRACE,
1022 ("BA Ori Session Timeout(%d) : Send ADD BA again\n",
1023 pBAEntry->Token));
1024
1025 pBAEntry->Token++;
1026 RTMPSetTimer(&pBAEntry->ORIBATimer, ORI_BA_SESSION_TIMEOUT);
1027 } else {
1028 BATableFreeOriEntry(pAd, pEntry->BAOriWcidArray[pBAEntry->TID]);
1029 }
1030}
1031
1032/*
1033 ==========================================================================
1034 Description:
1035 Retry sending ADDBA Reqest.
1036
1037 IRQL = DISPATCH_LEVEL
1038
1039 Parametrs:
1040 p8023Header: if this is already 802.3 format, p8023Header is NULL
1041
1042 Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere.
1043 FALSE , then continue indicaterx at this moment.
1044 ==========================================================================
1045 */
1046void BARecSessionIdleTimeout(void *SystemSpecific1,
1047 void *FunctionContext,
1048 void *SystemSpecific2, void *SystemSpecific3)
1049{
1050
1051 struct rt_ba_rec_entry *pBAEntry = (struct rt_ba_rec_entry *)FunctionContext;
1052 struct rt_rtmp_adapter *pAd;
1053 unsigned long Now32;
1054
1055 if (pBAEntry == NULL)
1056 return;
1057
1058 if ((pBAEntry->REC_BA_Status == Recipient_Accept)) {
1059 NdisGetSystemUpTime(&Now32);
1060
1061 if (RTMP_TIME_AFTER
1062 ((unsigned long)Now32,
1063 (unsigned long)(pBAEntry->LastIndSeqAtTimer +
1064 REC_BA_SESSION_IDLE_TIMEOUT))) {
1065 pAd = pBAEntry->pAdapter;
1066 /* flush all pending reordering mpdus */
1067 ba_refresh_reordering_mpdus(pAd, pBAEntry);
1068 DBGPRINT(RT_DEBUG_OFF,
1069 ("%ld: REC BA session Timeout\n", Now32));
1070 }
1071 }
1072}
1073
1074void PeerAddBAReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1075{
1076 /* 7.4.4.1 */
1077 /*unsigned long Idx; */
1078 u8 Status = 1;
1079 u8 pAddr[6];
1080 struct rt_frame_addba_rsp ADDframe;
1081 u8 *pOutBuffer = NULL;
1082 int NStatus;
1083 struct rt_frame_addba_req * pAddreqFrame = NULL;
1084 /*u8 BufSize; */
1085 unsigned long FrameLen;
1086 unsigned long *ptemp;
1087 struct rt_mac_table_entry *pMacEntry;
1088
1089 DBGPRINT(RT_DEBUG_TRACE,
1090 ("%s ==> (Wcid = %d)\n", __func__, Elem->Wcid));
1091
1092 /*hex_dump("AddBAReq", Elem->Msg, Elem->MsgLen); */
1093
1094 /*ADDBA Request from unknown peer, ignore this. */
1095 if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
1096 return;
1097
1098 pMacEntry = &pAd->MacTab.Content[Elem->Wcid];
1099 DBGPRINT(RT_DEBUG_TRACE, ("BA - PeerAddBAReqAction----> \n"));
1100 ptemp = (unsigned long *)Elem->Msg;
1101 /*DBGPRINT_RAW(RT_DEBUG_EMU, ("%08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x\n", *(ptemp), *(ptemp+1), *(ptemp+2), *(ptemp+3), *(ptemp+4), *(ptemp+5), *(ptemp+6), *(ptemp+7), *(ptemp+8))); */
1102
1103 if (PeerAddBAReqActionSanity(pAd, Elem->Msg, Elem->MsgLen, pAddr)) {
1104
1105 if ((pAd->CommonCfg.bBADecline == FALSE)
1106 && IS_HT_STA(pMacEntry)) {
1107 pAddreqFrame = (struct rt_frame_addba_req *) (&Elem->Msg[0]);
1108 DBGPRINT(RT_DEBUG_OFF,
1109 ("Rcv Wcid(%d) AddBAReq\n", Elem->Wcid));
1110 if (BARecSessionAdd
1111 (pAd, &pAd->MacTab.Content[Elem->Wcid],
1112 pAddreqFrame))
1113 Status = 0;
1114 else
1115 Status = 38; /* more parameters have invalid values */
1116 } else {
1117 Status = 37; /* the request has been declined. */
1118 }
1119 }
1120
1121 if (pAd->MacTab.Content[Elem->Wcid].ValidAsCLI)
1122 ASSERT(pAd->MacTab.Content[Elem->Wcid].Sst == SST_ASSOC);
1123
1124 pAddreqFrame = (struct rt_frame_addba_req *) (&Elem->Msg[0]);
1125 /* 2. Always send back ADDBA Response */
1126 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
1127 if (NStatus != NDIS_STATUS_SUCCESS) {
1128 DBGPRINT(RT_DEBUG_TRACE,
1129 ("ACTION - PeerBAAction() allocate memory failed \n"));
1130 return;
1131 }
1132
1133 NdisZeroMemory(&ADDframe, sizeof(struct rt_frame_addba_rsp));
1134
1135 /* 2-1. Prepare ADDBA Response frame. */
1136 {
1137 if (ADHOC_ON(pAd))
1138 ActHeaderInit(pAd, &ADDframe.Hdr, pAddr,
1139 pAd->CurrentAddress,
1140 pAd->CommonCfg.Bssid);
1141 else
1142 ActHeaderInit(pAd, &ADDframe.Hdr, pAd->CommonCfg.Bssid,
1143 pAd->CurrentAddress, pAddr);
1144 }
1145
1146 ADDframe.Category = CATEGORY_BA;
1147 ADDframe.Action = ADDBA_RESP;
1148 ADDframe.Token = pAddreqFrame->Token;
1149 /* What is the Status code?? need to check. */
1150 ADDframe.StatusCode = Status;
1151 ADDframe.BaParm.BAPolicy = IMMED_BA;
1152 ADDframe.BaParm.AMSDUSupported = 0;
1153 ADDframe.BaParm.TID = pAddreqFrame->BaParm.TID;
1154 ADDframe.BaParm.BufSize =
1155 min(((u8)pAddreqFrame->BaParm.BufSize),
1156 (u8)pAd->CommonCfg.BACapability.field.RxBAWinLimit);
1157 if (ADDframe.BaParm.BufSize == 0) {
1158 ADDframe.BaParm.BufSize = 64;
1159 }
1160 ADDframe.TimeOutValue = 0; /*pAddreqFrame->TimeOutValue; */
1161
1162 *(u16 *) (&ADDframe.BaParm) =
1163 cpu2le16(*(u16 *) (&ADDframe.BaParm));
1164 ADDframe.StatusCode = cpu2le16(ADDframe.StatusCode);
1165 ADDframe.TimeOutValue = cpu2le16(ADDframe.TimeOutValue);
1166
1167 MakeOutgoingFrame(pOutBuffer, &FrameLen,
1168 sizeof(struct rt_frame_addba_rsp), &ADDframe, END_OF_ARGS);
1169 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
1170 MlmeFreeMemory(pAd, pOutBuffer);
1171
1172 DBGPRINT(RT_DEBUG_TRACE,
1173 ("%s(%d): TID(%d), BufSize(%d) <== \n", __func__, Elem->Wcid,
1174 ADDframe.BaParm.TID, ADDframe.BaParm.BufSize));
1175}
1176
1177void PeerAddBARspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1178{
1179 /*u8 Idx, i; */
1180 /*u8 * pOutBuffer = NULL; */
1181 struct rt_frame_addba_rsp * pFrame = NULL;
1182 /*struct rt_ba_ori_entry *pBAEntry; */
1183
1184 /*ADDBA Response from unknown peer, ignore this. */
1185 if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE)
1186 return;
1187
1188 DBGPRINT(RT_DEBUG_TRACE, ("%s ==> Wcid(%d)\n", __func__, Elem->Wcid));
1189
1190 /*hex_dump("PeerAddBARspAction()", Elem->Msg, Elem->MsgLen); */
1191
1192 if (PeerAddBARspActionSanity(pAd, Elem->Msg, Elem->MsgLen)) {
1193 pFrame = (struct rt_frame_addba_rsp *) (&Elem->Msg[0]);
1194
1195 DBGPRINT(RT_DEBUG_TRACE,
1196 ("\t\t StatusCode = %d\n", pFrame->StatusCode));
1197 switch (pFrame->StatusCode) {
1198 case 0:
1199 /* I want a BAsession with this peer as an originator. */
1200 BAOriSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid],
1201 pFrame);
1202 break;
1203 default:
1204 /* check status == USED ??? */
1205 BAOriSessionTearDown(pAd, Elem->Wcid,
1206 pFrame->BaParm.TID, TRUE, FALSE);
1207 break;
1208 }
1209 /* Rcv Decline StatusCode */
1210 if ((pFrame->StatusCode == 37)
1211 || ((pAd->OpMode == OPMODE_STA) && STA_TGN_WIFI_ON(pAd)
1212 && (pFrame->StatusCode != 0))
1213 ) {
1214 pAd->MacTab.Content[Elem->Wcid].BADeclineBitmap |=
1215 1 << pFrame->BaParm.TID;
1216 }
1217 }
1218}
1219
1220void PeerDelBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1221{
1222 /*u8 Idx; */
1223 /*u8 * pOutBuffer = NULL; */
1224 struct rt_frame_delba_req * pDelFrame = NULL;
1225
1226 DBGPRINT(RT_DEBUG_TRACE, ("%s ==>\n", __func__));
1227 /*DELBA Request from unknown peer, ignore this. */
1228 if (PeerDelBAActionSanity(pAd, Elem->Wcid, Elem->Msg, Elem->MsgLen)) {
1229 pDelFrame = (struct rt_frame_delba_req *) (&Elem->Msg[0]);
1230 if (pDelFrame->DelbaParm.Initiator == ORIGINATOR) {
1231 DBGPRINT(RT_DEBUG_TRACE,
1232 ("BA - PeerDelBAAction----> ORIGINATOR\n"));
1233 BARecSessionTearDown(pAd, Elem->Wcid,
1234 pDelFrame->DelbaParm.TID, TRUE);
1235 } else {
1236 DBGPRINT(RT_DEBUG_TRACE,
1237 ("BA - PeerDelBAAction----> RECIPIENT, Reason = %d\n",
1238 pDelFrame->ReasonCode));
1239 /*hex_dump("DelBA Frame", pDelFrame, Elem->MsgLen); */
1240 BAOriSessionTearDown(pAd, Elem->Wcid,
1241 pDelFrame->DelbaParm.TID, TRUE,
1242 FALSE);
1243 }
1244 }
1245}
1246
1247BOOLEAN CntlEnqueueForRecv(struct rt_rtmp_adapter *pAd,
1248 unsigned long Wcid,
1249 unsigned long MsgLen, struct rt_frame_ba_req * pMsg)
1250{
1251 struct rt_frame_ba_req * pFrame = pMsg;
1252 /*PRTMP_REORDERBUF pBuffer; */
1253 /*PRTMP_REORDERBUF pDmaBuf; */
1254 struct rt_ba_rec_entry *pBAEntry;
1255 /*BOOLEAN Result; */
1256 unsigned long Idx;
1257 /*u8 NumRxPkt; */
1258 u8 TID; /*, i; */
1259
1260 TID = (u8)pFrame->BARControl.TID;
1261
1262 DBGPRINT(RT_DEBUG_TRACE,
1263 ("%s(): BAR-Wcid(%ld), Tid (%d)\n", __func__, Wcid, TID));
1264 /*hex_dump("BAR", (char *)pFrame, MsgLen); */
1265 /* Do nothing if the driver is starting halt state. */
1266 /* This might happen when timer already been fired before cancel timer with mlmehalt */
1267 if (RTMP_TEST_FLAG
1268 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
1269 return FALSE;
1270
1271 /* First check the size, it MUST not exceed the mlme queue size */
1272 if (MsgLen > MGMT_DMA_BUFFER_SIZE) {
1273 DBGPRINT_ERR("CntlEnqueueForRecv: frame too large, size = %ld \n", MsgLen);
1274 return FALSE;
1275 } else if (MsgLen != sizeof(struct rt_frame_ba_req)) {
1276 DBGPRINT_ERR("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen);
1277 return FALSE;
1278 } else if (MsgLen != sizeof(struct rt_frame_ba_req)) {
1279 DBGPRINT_ERR("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen);
1280 return FALSE;
1281 }
1282
1283 if ((Wcid < MAX_LEN_OF_MAC_TABLE) && (TID < 8)) {
1284 /* if this receiving packet is from SA that is in our OriEntry. Since WCID <9 has direct mapping. no need search. */
1285 Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
1286 pBAEntry = &pAd->BATable.BARecEntry[Idx];
1287 } else {
1288 return FALSE;
1289 }
1290
1291 DBGPRINT(RT_DEBUG_TRACE,
1292 ("BAR(%ld) : Tid (%d) - %04x:%04x\n", Wcid, TID,
1293 pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq));
1294
1295 if (SEQ_SMALLER
1296 (pBAEntry->LastIndSeq, pFrame->BAStartingSeq.field.StartSeq,
1297 MAXSEQ)) {
1298 /*DBGPRINT(RT_DEBUG_TRACE, ("BAR Seq = %x, LastIndSeq = %x\n", pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq)); */
1299 ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry,
1300 pFrame->BAStartingSeq.field.
1301 StartSeq);
1302 pBAEntry->LastIndSeq =
1303 (pFrame->BAStartingSeq.field.StartSeq ==
1304 0) ? MAXSEQ : (pFrame->BAStartingSeq.field.StartSeq - 1);
1305 }
1306 /*ba_refresh_reordering_mpdus(pAd, pBAEntry); */
1307 return TRUE;
1308}
1309
1310/*
1311Description : Send PSMP Action frame If PSMP mode switches.
1312*/
1313void SendPSMPAction(struct rt_rtmp_adapter *pAd, u8 Wcid, u8 Psmp)
1314{
1315 u8 *pOutBuffer = NULL;
1316 int NStatus;
1317 /*unsigned long Idx; */
1318 struct rt_frame_psmp_action Frame;
1319 unsigned long FrameLen;
1320
1321 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
1322 if (NStatus != NDIS_STATUS_SUCCESS) {
1323 DBGPRINT(RT_DEBUG_ERROR,
1324 ("BA - MlmeADDBAAction() allocate memory failed \n"));
1325 return;
1326 }
1327
1328 ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid,
1329 pAd->CurrentAddress, pAd->MacTab.Content[Wcid].Addr);
1330
1331 Frame.Category = CATEGORY_HT;
1332 Frame.Action = SMPS_ACTION;
1333 switch (Psmp) {
1334 case MMPS_ENABLE:
1335#ifdef RT30xx
1336 if (IS_RT30xx(pAd)
1337 && (pAd->Antenna.field.RxPath > 1
1338 || pAd->Antenna.field.TxPath > 1)) {
1339 RTMP_ASIC_MMPS_DISABLE(pAd);
1340 }
1341#endif /* RT30xx // */
1342 Frame.Psmp = 0;
1343 break;
1344 case MMPS_DYNAMIC:
1345 Frame.Psmp = 3;
1346 break;
1347 case MMPS_STATIC:
1348#ifdef RT30xx
1349 if (IS_RT30xx(pAd)
1350 && (pAd->Antenna.field.RxPath > 1
1351 || pAd->Antenna.field.TxPath > 1)) {
1352 RTMP_ASIC_MMPS_ENABLE(pAd);
1353 }
1354#endif /* RT30xx // */
1355 Frame.Psmp = 1;
1356 break;
1357 }
1358 MakeOutgoingFrame(pOutBuffer, &FrameLen,
1359 sizeof(struct rt_frame_psmp_action), &Frame, END_OF_ARGS);
1360 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
1361 MlmeFreeMemory(pAd, pOutBuffer);
1362 DBGPRINT(RT_DEBUG_ERROR, ("HT - SendPSMPAction( %d ) \n", Frame.Psmp));
1363}
1364
1365#define RADIO_MEASUREMENT_REQUEST_ACTION 0
1366
1367struct PACKED rt_beacon_request {
1368 u8 RegulatoryClass;
1369 u8 ChannelNumber;
1370 u16 RandomInterval;
1371 u16 MeasurementDuration;
1372 u8 MeasurementMode;
1373 u8 BSSID[MAC_ADDR_LEN];
1374 u8 ReportingCondition;
1375 u8 Threshold;
1376 u8 SSIDIE[2]; /* 2 byte */
1377};
1378
1379struct PACKED rt_measurement_req {
1380 u8 ID;
1381 u8 Length;
1382 u8 Token;
1383 u8 RequestMode;
1384 u8 Type;
1385};
1386
1387void convert_reordering_packet_to_preAMSDU_or_802_3_packet(struct rt_rtmp_adapter *pAd,
1388 struct rt_rx_blk *pRxBlk,
1389 u8
1390 FromWhichBSSID)
1391{
1392 void *pRxPkt;
1393 u8 Header802_3[LENGTH_802_3];
1394
1395 /* 1. get 802.3 Header */
1396 /* 2. remove LLC */
1397 /* a. pointer pRxBlk->pData to payload */
1398 /* b. modify pRxBlk->DataSize */
1399
1400 RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
1401
1402 ASSERT(pRxBlk->pRxPacket);
1403 pRxPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
1404
1405 SET_OS_PKT_NETDEV(pRxPkt, get_netdev_from_bssid(pAd, FromWhichBSSID));
1406 SET_OS_PKT_DATAPTR(pRxPkt, pRxBlk->pData);
1407 SET_OS_PKT_LEN(pRxPkt, pRxBlk->DataSize);
1408 SET_OS_PKT_DATATAIL(pRxPkt, pRxBlk->pData, pRxBlk->DataSize);
1409
1410 /* */
1411 /* copy 802.3 header, if necessary */
1412 /* */
1413 if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU)) {
1414 {
1415#ifdef LINUX
1416 NdisMoveMemory(skb_push(pRxPkt, LENGTH_802_3),
1417 Header802_3, LENGTH_802_3);
1418#endif
1419 }
1420 }
1421}
1422
1423#define INDICATE_LEGACY_OR_AMSDU(_pAd, _pRxBlk, _fromWhichBSSID) \
1424 do \
1425 { \
1426 if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_AMSDU)) \
1427 { \
1428 Indicate_AMSDU_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
1429 } \
1430 else if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_EAP)) \
1431 { \
1432 Indicate_EAPOL_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
1433 } \
1434 else \
1435 { \
1436 Indicate_Legacy_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \
1437 } \
1438 } while (0);
1439
1440static void ba_enqueue_reordering_packet(struct rt_rtmp_adapter *pAd,
1441 struct rt_ba_rec_entry *pBAEntry,
1442 struct rt_rx_blk *pRxBlk,
1443 u8 FromWhichBSSID)
1444{
1445 struct reordering_mpdu *mpdu_blk;
1446 u16 Sequence = (u16)pRxBlk->pHeader->Sequence;
1447
1448 mpdu_blk = ba_mpdu_blk_alloc(pAd);
1449 if ((mpdu_blk != NULL) && (!RX_BLK_TEST_FLAG(pRxBlk, fRX_EAP))) {
1450 /* Write RxD buffer address & allocated buffer length */
1451 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
1452
1453 mpdu_blk->Sequence = Sequence;
1454
1455 mpdu_blk->bAMSDU = RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU);
1456
1457 convert_reordering_packet_to_preAMSDU_or_802_3_packet(pAd,
1458 pRxBlk,
1459 FromWhichBSSID);
1460
1461 STATS_INC_RX_PACKETS(pAd, FromWhichBSSID);
1462
1463 /* */
1464 /* it is necessary for reordering packet to record */
1465 /* which BSS it come from */
1466 /* */
1467 RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID);
1468
1469 mpdu_blk->pPacket = pRxBlk->pRxPacket;
1470
1471 if (ba_reordering_mpdu_insertsorted(&pBAEntry->list, mpdu_blk)
1472 == FALSE) {
1473 /* had been already within reordering list */
1474 /* don't indicate */
1475 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
1476 NDIS_STATUS_SUCCESS);
1477 ba_mpdu_blk_free(pAd, mpdu_blk);
1478 }
1479
1480 ASSERT((0 <= pBAEntry->list.qlen)
1481 && (pBAEntry->list.qlen <= pBAEntry->BAWinSize));
1482 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
1483 } else {
1484 DBGPRINT(RT_DEBUG_ERROR,
1485 (" (%d) Can't allocate reordering mpdu blk\n",
1486 pBAEntry->list.qlen));
1487
1488 /*
1489 * flush all pending reordering mpdus
1490 * and receiving mpdu to upper layer
1491 * make tcp/ip to take care reordering mechanism
1492 */
1493 /*ba_refresh_reordering_mpdus(pAd, pBAEntry); */
1494 ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence);
1495
1496 pBAEntry->LastIndSeq = Sequence;
1497 INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
1498 }
1499}
1500
1501/*
1502 ==========================================================================
1503 Description:
1504 Indicate this packet to upper layer or put it into reordering buffer
1505
1506 Parametrs:
1507 pRxBlk : carry necessary packet info 802.11 format
1508 FromWhichBSSID : the packet received from which BSS
1509
1510 Return :
1511 none
1512
1513 Note :
1514 the packet queued into reordering buffer need to cover to 802.3 format
1515 or pre_AMSDU format
1516 ==========================================================================
1517 */
1518
1519void Indicate_AMPDU_Packet(struct rt_rtmp_adapter *pAd,
1520 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
1521{
1522 u16 Idx;
1523 struct rt_ba_rec_entry *pBAEntry = NULL;
1524 u16 Sequence = pRxBlk->pHeader->Sequence;
1525 unsigned long Now32;
1526 u8 Wcid = pRxBlk->pRxWI->WirelessCliID;
1527 u8 TID = pRxBlk->pRxWI->TID;
1528
1529 if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU)
1530 && (pRxBlk->DataSize > MAX_RX_PKT_LEN)) {
1531 /* release packet */
1532 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
1533 NDIS_STATUS_FAILURE);
1534 return;
1535 }
1536
1537 if (Wcid < MAX_LEN_OF_MAC_TABLE) {
1538 Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
1539 if (Idx == 0) {
1540 /* Rec BA Session had been torn down */
1541 INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
1542 return;
1543 }
1544 pBAEntry = &pAd->BATable.BARecEntry[Idx];
1545 } else {
1546 /* impossible ! */
1547 ASSERT(0);
1548 /* release packet */
1549 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
1550 NDIS_STATUS_FAILURE);
1551 return;
1552 }
1553
1554 ASSERT(pBAEntry);
1555
1556 /* update last rx time */
1557 NdisGetSystemUpTime(&Now32);
1558
1559 pBAEntry->rcvSeq = Sequence;
1560
1561 ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32);
1562 pBAEntry->LastIndSeqAtTimer = Now32;
1563
1564 /* */
1565 /* Reset Last Indicate Sequence */
1566 /* */
1567 if (pBAEntry->LastIndSeq == RESET_RCV_SEQ) {
1568 ASSERT((pBAEntry->list.qlen == 0)
1569 && (pBAEntry->list.next == NULL));
1570
1571 /* reset rcv sequence of BA session */
1572 pBAEntry->LastIndSeq = Sequence;
1573 pBAEntry->LastIndSeqAtTimer = Now32;
1574 INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
1575 return;
1576 }
1577
1578 /* */
1579 /* I. Check if in order. */
1580 /* */
1581 if (SEQ_STEPONE(Sequence, pBAEntry->LastIndSeq, MAXSEQ)) {
1582 u16 LastIndSeq;
1583
1584 pBAEntry->LastIndSeq = Sequence;
1585 INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID);
1586 LastIndSeq =
1587 ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry,
1588 pBAEntry->LastIndSeq);
1589 if (LastIndSeq != RESET_RCV_SEQ) {
1590 pBAEntry->LastIndSeq = LastIndSeq;
1591 }
1592 pBAEntry->LastIndSeqAtTimer = Now32;
1593 }
1594 /* */
1595 /* II. Drop Duplicated Packet */
1596 /* */
1597 else if (Sequence == pBAEntry->LastIndSeq) {
1598
1599 /* drop and release packet */
1600 pBAEntry->nDropPacket++;
1601 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
1602 NDIS_STATUS_FAILURE);
1603 }
1604 /* */
1605 /* III. Drop Old Received Packet */
1606 /* */
1607 else if (SEQ_SMALLER(Sequence, pBAEntry->LastIndSeq, MAXSEQ)) {
1608
1609 /* drop and release packet */
1610 pBAEntry->nDropPacket++;
1611 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
1612 NDIS_STATUS_FAILURE);
1613 }
1614 /* */
1615 /* IV. Receive Sequence within Window Size */
1616 /* */
1617 else if (SEQ_SMALLER
1618 (Sequence,
1619 (((pBAEntry->LastIndSeq + pBAEntry->BAWinSize + 1)) & MAXSEQ),
1620 MAXSEQ)) {
1621 ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk,
1622 FromWhichBSSID);
1623 }
1624 /* */
1625 /* V. Receive seq surpasses Win(lastseq + nMSDU). So refresh all reorder buffer */
1626 /* */
1627 else {
1628 long WinStartSeq, TmpSeq;
1629
1630 TmpSeq = Sequence - (pBAEntry->BAWinSize) - 1;
1631 if (TmpSeq < 0) {
1632 TmpSeq = (MAXSEQ + 1) + TmpSeq;
1633 }
1634 WinStartSeq = (TmpSeq + 1) & MAXSEQ;
1635 ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, WinStartSeq);
1636 pBAEntry->LastIndSeq = WinStartSeq; /*TmpSeq; */
1637
1638 pBAEntry->LastIndSeqAtTimer = Now32;
1639
1640 ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk,
1641 FromWhichBSSID);
1642
1643 TmpSeq =
1644 ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry,
1645 pBAEntry->LastIndSeq);
1646 if (TmpSeq != RESET_RCV_SEQ) {
1647 pBAEntry->LastIndSeq = TmpSeq;
1648 }
1649 }
1650}
diff --git a/drivers/staging/rt2860/common/cmm_aes.c b/drivers/staging/rt2860/common/cmm_aes.c
deleted file mode 100644
index d70d229a6e5..00000000000
--- a/drivers/staging/rt2860/common/cmm_aes.c
+++ /dev/null
@@ -1,1311 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 cmm_aes.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Paul Wu 02-25-02 Initial
36*/
37
38#include "../rt_config.h"
39
40struct aes_context {
41 u32 erk[64]; /* encryption round keys */
42 u32 drk[64]; /* decryption round keys */
43 int nr; /* number of rounds */
44};
45
46/*****************************/
47/******** SBOX Table *********/
48/*****************************/
49
50u8 SboxTable[256] = {
51 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
52 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
53 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
54 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
55 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
56 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
57 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
58 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
59 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
60 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
61 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
62 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
63 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
64 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
65 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
66 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
67 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
68 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
69 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
70 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
71 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
72 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
73 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
74 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
75 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
76 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
77 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
78 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
79 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
80 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
81 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
82 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
83};
84
85void xor_32(u8 *a, u8 *b, u8 *out)
86{
87 int i;
88
89 for (i = 0; i < 4; i++) {
90 out[i] = a[i] ^ b[i];
91 }
92}
93
94void xor_128(u8 *a, u8 *b, u8 *out)
95{
96 int i;
97
98 for (i = 0; i < 16; i++) {
99 out[i] = a[i] ^ b[i];
100 }
101}
102
103u8 RTMPCkipSbox(u8 a)
104{
105 return SboxTable[(int)a];
106}
107
108void next_key(u8 *key, int round)
109{
110 u8 rcon;
111 u8 sbox_key[4];
112 u8 rcon_table[12] = {
113 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
114 0x1b, 0x36, 0x36, 0x36
115 };
116
117 sbox_key[0] = RTMPCkipSbox(key[13]);
118 sbox_key[1] = RTMPCkipSbox(key[14]);
119 sbox_key[2] = RTMPCkipSbox(key[15]);
120 sbox_key[3] = RTMPCkipSbox(key[12]);
121
122 rcon = rcon_table[round];
123
124 xor_32(&key[0], sbox_key, &key[0]);
125 key[0] = key[0] ^ rcon;
126
127 xor_32(&key[4], &key[0], &key[4]);
128 xor_32(&key[8], &key[4], &key[8]);
129 xor_32(&key[12], &key[8], &key[12]);
130}
131
132void byte_sub(u8 *in, u8 *out)
133{
134 int i;
135
136 for (i = 0; i < 16; i++) {
137 out[i] = RTMPCkipSbox(in[i]);
138 }
139}
140
141/************************************/
142/* bitwise_xor() */
143/* A 128 bit, bitwise exclusive or */
144/************************************/
145
146void bitwise_xor(unsigned char *ina, unsigned char *inb, unsigned char *out)
147{
148 int i;
149 for (i = 0; i < 16; i++) {
150 out[i] = ina[i] ^ inb[i];
151 }
152}
153
154void shift_row(u8 *in, u8 *out)
155{
156 out[0] = in[0];
157 out[1] = in[5];
158 out[2] = in[10];
159 out[3] = in[15];
160 out[4] = in[4];
161 out[5] = in[9];
162 out[6] = in[14];
163 out[7] = in[3];
164 out[8] = in[8];
165 out[9] = in[13];
166 out[10] = in[2];
167 out[11] = in[7];
168 out[12] = in[12];
169 out[13] = in[1];
170 out[14] = in[6];
171 out[15] = in[11];
172}
173
174void mix_column(u8 *in, u8 *out)
175{
176 int i;
177 u8 add1b[4];
178 u8 add1bf7[4];
179 u8 rotl[4];
180 u8 swap_halfs[4];
181 u8 andf7[4];
182 u8 rotr[4];
183 u8 temp[4];
184 u8 tempb[4];
185
186 for (i = 0; i < 4; i++) {
187 if ((in[i] & 0x80) == 0x80)
188 add1b[i] = 0x1b;
189 else
190 add1b[i] = 0x00;
191 }
192
193 swap_halfs[0] = in[2]; /* Swap halfs */
194 swap_halfs[1] = in[3];
195 swap_halfs[2] = in[0];
196 swap_halfs[3] = in[1];
197
198 rotl[0] = in[3]; /* Rotate left 8 bits */
199 rotl[1] = in[0];
200 rotl[2] = in[1];
201 rotl[3] = in[2];
202
203 andf7[0] = in[0] & 0x7f;
204 andf7[1] = in[1] & 0x7f;
205 andf7[2] = in[2] & 0x7f;
206 andf7[3] = in[3] & 0x7f;
207
208 for (i = 3; i > 0; i--) { /* logical shift left 1 bit */
209 andf7[i] = andf7[i] << 1;
210 if ((andf7[i - 1] & 0x80) == 0x80) {
211 andf7[i] = (andf7[i] | 0x01);
212 }
213 }
214 andf7[0] = andf7[0] << 1;
215 andf7[0] = andf7[0] & 0xfe;
216
217 xor_32(add1b, andf7, add1bf7);
218
219 xor_32(in, add1bf7, rotr);
220
221 temp[0] = rotr[0]; /* Rotate right 8 bits */
222 rotr[0] = rotr[1];
223 rotr[1] = rotr[2];
224 rotr[2] = rotr[3];
225 rotr[3] = temp[0];
226
227 xor_32(add1bf7, rotr, temp);
228 xor_32(swap_halfs, rotl, tempb);
229 xor_32(temp, tempb, out);
230}
231
232/************************************************/
233/* construct_mic_header1() */
234/* Builds the first MIC header block from */
235/* header fields. */
236/************************************************/
237
238void construct_mic_header1(unsigned char *mic_header1,
239 int header_length, unsigned char *mpdu)
240{
241 mic_header1[0] = (unsigned char)((header_length - 2) / 256);
242 mic_header1[1] = (unsigned char)((header_length - 2) % 256);
243 mic_header1[2] = mpdu[0] & 0xcf; /* Mute CF poll & CF ack bits */
244 mic_header1[3] = mpdu[1] & 0xc7; /* Mute retry, more data and pwr mgt bits */
245 mic_header1[4] = mpdu[4]; /* A1 */
246 mic_header1[5] = mpdu[5];
247 mic_header1[6] = mpdu[6];
248 mic_header1[7] = mpdu[7];
249 mic_header1[8] = mpdu[8];
250 mic_header1[9] = mpdu[9];
251 mic_header1[10] = mpdu[10]; /* A2 */
252 mic_header1[11] = mpdu[11];
253 mic_header1[12] = mpdu[12];
254 mic_header1[13] = mpdu[13];
255 mic_header1[14] = mpdu[14];
256 mic_header1[15] = mpdu[15];
257}
258
259/************************************************/
260/* construct_mic_header2() */
261/* Builds the last MIC header block from */
262/* header fields. */
263/************************************************/
264
265void construct_mic_header2(unsigned char *mic_header2,
266 unsigned char *mpdu, int a4_exists, int qc_exists)
267{
268 int i;
269
270 for (i = 0; i < 16; i++)
271 mic_header2[i] = 0x00;
272
273 mic_header2[0] = mpdu[16]; /* A3 */
274 mic_header2[1] = mpdu[17];
275 mic_header2[2] = mpdu[18];
276 mic_header2[3] = mpdu[19];
277 mic_header2[4] = mpdu[20];
278 mic_header2[5] = mpdu[21];
279
280 /* In Sequence Control field, mute sequence numer bits (12-bit) */
281 mic_header2[6] = mpdu[22] & 0x0f; /* SC */
282 mic_header2[7] = 0x00; /* mpdu[23]; */
283
284 if ((!qc_exists) && a4_exists) {
285 for (i = 0; i < 6; i++)
286 mic_header2[8 + i] = mpdu[24 + i]; /* A4 */
287
288 }
289
290 if (qc_exists && (!a4_exists)) {
291 mic_header2[8] = mpdu[24] & 0x0f; /* mute bits 15 - 4 */
292 mic_header2[9] = mpdu[25] & 0x00;
293 }
294
295 if (qc_exists && a4_exists) {
296 for (i = 0; i < 6; i++)
297 mic_header2[8 + i] = mpdu[24 + i]; /* A4 */
298
299 mic_header2[14] = mpdu[30] & 0x0f;
300 mic_header2[15] = mpdu[31] & 0x00;
301 }
302}
303
304/************************************************/
305/* construct_mic_iv() */
306/* Builds the MIC IV from header fields and PN */
307/************************************************/
308
309void construct_mic_iv(unsigned char *mic_iv,
310 int qc_exists,
311 int a4_exists,
312 unsigned char *mpdu,
313 unsigned int payload_length, unsigned char *pn_vector)
314{
315 int i;
316
317 mic_iv[0] = 0x59;
318 if (qc_exists && a4_exists)
319 mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */
320 if (qc_exists && !a4_exists)
321 mic_iv[1] = mpdu[24] & 0x0f; /* mute bits 7-4 */
322 if (!qc_exists)
323 mic_iv[1] = 0x00;
324 for (i = 2; i < 8; i++)
325 mic_iv[i] = mpdu[i + 8]; /* mic_iv[2:7] = A2[0:5] = mpdu[10:15] */
326#ifdef CONSISTENT_PN_ORDER
327 for (i = 8; i < 14; i++)
328 mic_iv[i] = pn_vector[i - 8]; /* mic_iv[8:13] = PN[0:5] */
329#else
330 for (i = 8; i < 14; i++)
331 mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */
332#endif
333 mic_iv[14] = (unsigned char)(payload_length / 256);
334 mic_iv[15] = (unsigned char)(payload_length % 256);
335
336}
337
338/****************************************/
339/* aes128k128d() */
340/* Performs a 128 bit AES encrypt with */
341/* 128 bit data. */
342/****************************************/
343void aes128k128d(unsigned char *key, unsigned char *data,
344 unsigned char *ciphertext)
345{
346 int round;
347 int i;
348 unsigned char intermediatea[16];
349 unsigned char intermediateb[16];
350 unsigned char round_key[16];
351
352 for (i = 0; i < 16; i++)
353 round_key[i] = key[i];
354
355 for (round = 0; round < 11; round++) {
356 if (round == 0) {
357 xor_128(round_key, data, ciphertext);
358 next_key(round_key, round);
359 } else if (round == 10) {
360 byte_sub(ciphertext, intermediatea);
361 shift_row(intermediatea, intermediateb);
362 xor_128(intermediateb, round_key, ciphertext);
363 } else { /* 1 - 9 */
364
365 byte_sub(ciphertext, intermediatea);
366 shift_row(intermediatea, intermediateb);
367 mix_column(&intermediateb[0], &intermediatea[0]);
368 mix_column(&intermediateb[4], &intermediatea[4]);
369 mix_column(&intermediateb[8], &intermediatea[8]);
370 mix_column(&intermediateb[12], &intermediatea[12]);
371 xor_128(intermediatea, round_key, ciphertext);
372 next_key(round_key, round);
373 }
374 }
375
376}
377
378void construct_ctr_preload(unsigned char *ctr_preload,
379 int a4_exists,
380 int qc_exists,
381 unsigned char *mpdu, unsigned char *pn_vector, int c)
382{
383
384 int i = 0;
385 for (i = 0; i < 16; i++)
386 ctr_preload[i] = 0x00;
387 i = 0;
388
389 ctr_preload[0] = 0x01; /* flag */
390 if (qc_exists && a4_exists)
391 ctr_preload[1] = mpdu[30] & 0x0f; /* QoC_Control */
392 if (qc_exists && !a4_exists)
393 ctr_preload[1] = mpdu[24] & 0x0f;
394
395 for (i = 2; i < 8; i++)
396 ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */
397#ifdef CONSISTENT_PN_ORDER
398 for (i = 8; i < 14; i++)
399 ctr_preload[i] = pn_vector[i - 8]; /* ctr_preload[8:13] = PN[0:5] */
400#else
401 for (i = 8; i < 14; i++)
402 ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */
403#endif
404 ctr_preload[14] = (unsigned char)(c / 256); /* Ctr */
405 ctr_preload[15] = (unsigned char)(c % 256);
406
407}
408
409BOOLEAN RTMPSoftDecryptAES(struct rt_rtmp_adapter *pAd,
410 u8 *pData,
411 unsigned long DataByteCnt, struct rt_cipher_key *pWpaKey)
412{
413 u8 KeyID;
414 u32 HeaderLen;
415 u8 PN[6];
416 u32 payload_len;
417 u32 num_blocks;
418 u32 payload_remainder;
419 u16 fc;
420 u8 fc0;
421 u8 fc1;
422 u32 frame_type;
423 u32 frame_subtype;
424 u32 from_ds;
425 u32 to_ds;
426 int a4_exists;
427 int qc_exists;
428 u8 aes_out[16];
429 int payload_index;
430 u32 i;
431 u8 ctr_preload[16];
432 u8 chain_buffer[16];
433 u8 padded_buffer[16];
434 u8 mic_iv[16];
435 u8 mic_header1[16];
436 u8 mic_header2[16];
437 u8 MIC[8];
438 u8 TrailMIC[8];
439
440 fc0 = *pData;
441 fc1 = *(pData + 1);
442
443 fc = *((u16 *)pData);
444
445 frame_type = ((fc0 >> 2) & 0x03);
446 frame_subtype = ((fc0 >> 4) & 0x0f);
447
448 from_ds = (fc1 & 0x2) >> 1;
449 to_ds = (fc1 & 0x1);
450
451 a4_exists = (from_ds & to_ds);
452 qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */
453 (frame_subtype == 0x09) || /* Likely to change. */
454 (frame_subtype == 0x0a) || (frame_subtype == 0x0b)
455 );
456
457 HeaderLen = 24;
458 if (a4_exists)
459 HeaderLen += 6;
460
461 KeyID = *((u8 *)(pData + HeaderLen + 3));
462 KeyID = KeyID >> 6;
463
464 if (pWpaKey[KeyID].KeyLen == 0) {
465 DBGPRINT(RT_DEBUG_TRACE,
466 ("RTMPSoftDecryptAES failed!(KeyID[%d] Length can not be 0)\n",
467 KeyID));
468 return FALSE;
469 }
470
471 PN[0] = *(pData + HeaderLen);
472 PN[1] = *(pData + HeaderLen + 1);
473 PN[2] = *(pData + HeaderLen + 4);
474 PN[3] = *(pData + HeaderLen + 5);
475 PN[4] = *(pData + HeaderLen + 6);
476 PN[5] = *(pData + HeaderLen + 7);
477
478 payload_len = DataByteCnt - HeaderLen - 8 - 8; /* 8 bytes for CCMP header , 8 bytes for MIC */
479 payload_remainder = (payload_len) % 16;
480 num_blocks = (payload_len) / 16;
481
482 /* Find start of payload */
483 payload_index = HeaderLen + 8; /*IV+EIV */
484
485 for (i = 0; i < num_blocks; i++) {
486 construct_ctr_preload(ctr_preload,
487 a4_exists, qc_exists, pData, PN, i + 1);
488
489 aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
490
491 bitwise_xor(aes_out, pData + payload_index, chain_buffer);
492 NdisMoveMemory(pData + payload_index - 8, chain_buffer, 16);
493 payload_index += 16;
494 }
495
496 /* */
497 /* If there is a short final block, then pad it */
498 /* encrypt it and copy the unpadded part back */
499 /* */
500 if (payload_remainder > 0) {
501 construct_ctr_preload(ctr_preload,
502 a4_exists,
503 qc_exists, pData, PN, num_blocks + 1);
504
505 NdisZeroMemory(padded_buffer, 16);
506 NdisMoveMemory(padded_buffer, pData + payload_index,
507 payload_remainder);
508
509 aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
510
511 bitwise_xor(aes_out, padded_buffer, chain_buffer);
512 NdisMoveMemory(pData + payload_index - 8, chain_buffer,
513 payload_remainder);
514 payload_index += payload_remainder;
515 }
516 /* */
517 /* Descrypt the MIC */
518 /* */
519 construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pData, PN, 0);
520 NdisZeroMemory(padded_buffer, 16);
521 NdisMoveMemory(padded_buffer, pData + payload_index, 8);
522
523 aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out);
524
525 bitwise_xor(aes_out, padded_buffer, chain_buffer);
526
527 NdisMoveMemory(TrailMIC, chain_buffer, 8);
528
529 /* */
530 /* Calculate MIC */
531 /* */
532
533 /*Force the protected frame bit on */
534 *(pData + 1) = *(pData + 1) | 0x40;
535
536 /* Find start of payload */
537 /* Because the CCMP header has been removed */
538 payload_index = HeaderLen;
539
540 construct_mic_iv(mic_iv, qc_exists, a4_exists, pData, payload_len, PN);
541
542 construct_mic_header1(mic_header1, HeaderLen, pData);
543
544 construct_mic_header2(mic_header2, pData, a4_exists, qc_exists);
545
546 aes128k128d(pWpaKey[KeyID].Key, mic_iv, aes_out);
547 bitwise_xor(aes_out, mic_header1, chain_buffer);
548 aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
549 bitwise_xor(aes_out, mic_header2, chain_buffer);
550 aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
551
552 /* iterate through each 16 byte payload block */
553 for (i = 0; i < num_blocks; i++) {
554 bitwise_xor(aes_out, pData + payload_index, chain_buffer);
555 payload_index += 16;
556 aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
557 }
558
559 /* Add on the final payload block if it needs padding */
560 if (payload_remainder > 0) {
561 NdisZeroMemory(padded_buffer, 16);
562 NdisMoveMemory(padded_buffer, pData + payload_index,
563 payload_remainder);
564
565 bitwise_xor(aes_out, padded_buffer, chain_buffer);
566 aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out);
567 }
568 /* aes_out contains padded mic, discard most significant */
569 /* 8 bytes to generate 64 bit MIC */
570 for (i = 0; i < 8; i++)
571 MIC[i] = aes_out[i];
572
573 if (!NdisEqualMemory(MIC, TrailMIC, 8)) {
574 DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptAES, MIC Error !\n")); /*MIC error. */
575 return FALSE;
576 }
577
578 return TRUE;
579}
580
581/* ========================= AES En/Decryption ========================== */
582#ifndef uint8
583#define uint8 unsigned char
584#endif
585
586#ifndef uint32
587#define uint32 unsigned int
588#endif
589
590/* forward S-box */
591static uint32 FSb[256] = {
592 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
593 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
594 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
595 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
596 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
597 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
598 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
599 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
600 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
601 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
602 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
603 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
604 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
605 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
606 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
607 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
608 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
609 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
610 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
611 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
612 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
613 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
614 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
615 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
616 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
617 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
618 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
619 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
620 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
621 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
622 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
623 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
624};
625
626/* forward table */
627#define FT \
628\
629 V(C6,63,63,A5), V(F8,7C,7C,84), V(EE,77,77,99), V(F6,7B,7B,8D), \
630 V(FF,F2,F2,0D), V(D6,6B,6B,BD), V(DE,6F,6F,B1), V(91,C5,C5,54), \
631 V(60,30,30,50), V(02,01,01,03), V(CE,67,67,A9), V(56,2B,2B,7D), \
632 V(E7,FE,FE,19), V(B5,D7,D7,62), V(4D,AB,AB,E6), V(EC,76,76,9A), \
633 V(8F,CA,CA,45), V(1F,82,82,9D), V(89,C9,C9,40), V(FA,7D,7D,87), \
634 V(EF,FA,FA,15), V(B2,59,59,EB), V(8E,47,47,C9), V(FB,F0,F0,0B), \
635 V(41,AD,AD,EC), V(B3,D4,D4,67), V(5F,A2,A2,FD), V(45,AF,AF,EA), \
636 V(23,9C,9C,BF), V(53,A4,A4,F7), V(E4,72,72,96), V(9B,C0,C0,5B), \
637 V(75,B7,B7,C2), V(E1,FD,FD,1C), V(3D,93,93,AE), V(4C,26,26,6A), \
638 V(6C,36,36,5A), V(7E,3F,3F,41), V(F5,F7,F7,02), V(83,CC,CC,4F), \
639 V(68,34,34,5C), V(51,A5,A5,F4), V(D1,E5,E5,34), V(F9,F1,F1,08), \
640 V(E2,71,71,93), V(AB,D8,D8,73), V(62,31,31,53), V(2A,15,15,3F), \
641 V(08,04,04,0C), V(95,C7,C7,52), V(46,23,23,65), V(9D,C3,C3,5E), \
642 V(30,18,18,28), V(37,96,96,A1), V(0A,05,05,0F), V(2F,9A,9A,B5), \
643 V(0E,07,07,09), V(24,12,12,36), V(1B,80,80,9B), V(DF,E2,E2,3D), \
644 V(CD,EB,EB,26), V(4E,27,27,69), V(7F,B2,B2,CD), V(EA,75,75,9F), \
645 V(12,09,09,1B), V(1D,83,83,9E), V(58,2C,2C,74), V(34,1A,1A,2E), \
646 V(36,1B,1B,2D), V(DC,6E,6E,B2), V(B4,5A,5A,EE), V(5B,A0,A0,FB), \
647 V(A4,52,52,F6), V(76,3B,3B,4D), V(B7,D6,D6,61), V(7D,B3,B3,CE), \
648 V(52,29,29,7B), V(DD,E3,E3,3E), V(5E,2F,2F,71), V(13,84,84,97), \
649 V(A6,53,53,F5), V(B9,D1,D1,68), V(00,00,00,00), V(C1,ED,ED,2C), \
650 V(40,20,20,60), V(E3,FC,FC,1F), V(79,B1,B1,C8), V(B6,5B,5B,ED), \
651 V(D4,6A,6A,BE), V(8D,CB,CB,46), V(67,BE,BE,D9), V(72,39,39,4B), \
652 V(94,4A,4A,DE), V(98,4C,4C,D4), V(B0,58,58,E8), V(85,CF,CF,4A), \
653 V(BB,D0,D0,6B), V(C5,EF,EF,2A), V(4F,AA,AA,E5), V(ED,FB,FB,16), \
654 V(86,43,43,C5), V(9A,4D,4D,D7), V(66,33,33,55), V(11,85,85,94), \
655 V(8A,45,45,CF), V(E9,F9,F9,10), V(04,02,02,06), V(FE,7F,7F,81), \
656 V(A0,50,50,F0), V(78,3C,3C,44), V(25,9F,9F,BA), V(4B,A8,A8,E3), \
657 V(A2,51,51,F3), V(5D,A3,A3,FE), V(80,40,40,C0), V(05,8F,8F,8A), \
658 V(3F,92,92,AD), V(21,9D,9D,BC), V(70,38,38,48), V(F1,F5,F5,04), \
659 V(63,BC,BC,DF), V(77,B6,B6,C1), V(AF,DA,DA,75), V(42,21,21,63), \
660 V(20,10,10,30), V(E5,FF,FF,1A), V(FD,F3,F3,0E), V(BF,D2,D2,6D), \
661 V(81,CD,CD,4C), V(18,0C,0C,14), V(26,13,13,35), V(C3,EC,EC,2F), \
662 V(BE,5F,5F,E1), V(35,97,97,A2), V(88,44,44,CC), V(2E,17,17,39), \
663 V(93,C4,C4,57), V(55,A7,A7,F2), V(FC,7E,7E,82), V(7A,3D,3D,47), \
664 V(C8,64,64,AC), V(BA,5D,5D,E7), V(32,19,19,2B), V(E6,73,73,95), \
665 V(C0,60,60,A0), V(19,81,81,98), V(9E,4F,4F,D1), V(A3,DC,DC,7F), \
666 V(44,22,22,66), V(54,2A,2A,7E), V(3B,90,90,AB), V(0B,88,88,83), \
667 V(8C,46,46,CA), V(C7,EE,EE,29), V(6B,B8,B8,D3), V(28,14,14,3C), \
668 V(A7,DE,DE,79), V(BC,5E,5E,E2), V(16,0B,0B,1D), V(AD,DB,DB,76), \
669 V(DB,E0,E0,3B), V(64,32,32,56), V(74,3A,3A,4E), V(14,0A,0A,1E), \
670 V(92,49,49,DB), V(0C,06,06,0A), V(48,24,24,6C), V(B8,5C,5C,E4), \
671 V(9F,C2,C2,5D), V(BD,D3,D3,6E), V(43,AC,AC,EF), V(C4,62,62,A6), \
672 V(39,91,91,A8), V(31,95,95,A4), V(D3,E4,E4,37), V(F2,79,79,8B), \
673 V(D5,E7,E7,32), V(8B,C8,C8,43), V(6E,37,37,59), V(DA,6D,6D,B7), \
674 V(01,8D,8D,8C), V(B1,D5,D5,64), V(9C,4E,4E,D2), V(49,A9,A9,E0), \
675 V(D8,6C,6C,B4), V(AC,56,56,FA), V(F3,F4,F4,07), V(CF,EA,EA,25), \
676 V(CA,65,65,AF), V(F4,7A,7A,8E), V(47,AE,AE,E9), V(10,08,08,18), \
677 V(6F,BA,BA,D5), V(F0,78,78,88), V(4A,25,25,6F), V(5C,2E,2E,72), \
678 V(38,1C,1C,24), V(57,A6,A6,F1), V(73,B4,B4,C7), V(97,C6,C6,51), \
679 V(CB,E8,E8,23), V(A1,DD,DD,7C), V(E8,74,74,9C), V(3E,1F,1F,21), \
680 V(96,4B,4B,DD), V(61,BD,BD,DC), V(0D,8B,8B,86), V(0F,8A,8A,85), \
681 V(E0,70,70,90), V(7C,3E,3E,42), V(71,B5,B5,C4), V(CC,66,66,AA), \
682 V(90,48,48,D8), V(06,03,03,05), V(F7,F6,F6,01), V(1C,0E,0E,12), \
683 V(C2,61,61,A3), V(6A,35,35,5F), V(AE,57,57,F9), V(69,B9,B9,D0), \
684 V(17,86,86,91), V(99,C1,C1,58), V(3A,1D,1D,27), V(27,9E,9E,B9), \
685 V(D9,E1,E1,38), V(EB,F8,F8,13), V(2B,98,98,B3), V(22,11,11,33), \
686 V(D2,69,69,BB), V(A9,D9,D9,70), V(07,8E,8E,89), V(33,94,94,A7), \
687 V(2D,9B,9B,B6), V(3C,1E,1E,22), V(15,87,87,92), V(C9,E9,E9,20), \
688 V(87,CE,CE,49), V(AA,55,55,FF), V(50,28,28,78), V(A5,DF,DF,7A), \
689 V(03,8C,8C,8F), V(59,A1,A1,F8), V(09,89,89,80), V(1A,0D,0D,17), \
690 V(65,BF,BF,DA), V(D7,E6,E6,31), V(84,42,42,C6), V(D0,68,68,B8), \
691 V(82,41,41,C3), V(29,99,99,B0), V(5A,2D,2D,77), V(1E,0F,0F,11), \
692 V(7B,B0,B0,CB), V(A8,54,54,FC), V(6D,BB,BB,D6), V(2C,16,16,3A)
693
694#define V(a,b,c,d) 0x##a##b##c##d
695static uint32 FT0[256] = { FT };
696
697#undef V
698
699#define V(a,b,c,d) 0x##d##a##b##c
700static uint32 FT1[256] = { FT };
701
702#undef V
703
704#define V(a,b,c,d) 0x##c##d##a##b
705static uint32 FT2[256] = { FT };
706
707#undef V
708
709#define V(a,b,c,d) 0x##b##c##d##a
710static uint32 FT3[256] = { FT };
711
712#undef V
713
714#undef FT
715
716/* reverse S-box */
717
718static uint32 RSb[256] = {
719 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
720 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
721 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
722 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
723 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
724 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
725 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
726 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
727 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
728 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
729 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
730 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
731 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
732 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
733 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
734 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
735 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
736 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
737 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
738 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
739 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
740 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
741 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
742 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
743 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
744 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
745 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
746 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
747 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
748 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
749 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
750 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
751};
752
753/* reverse table */
754
755#define RT \
756\
757 V(51,F4,A7,50), V(7E,41,65,53), V(1A,17,A4,C3), V(3A,27,5E,96), \
758 V(3B,AB,6B,CB), V(1F,9D,45,F1), V(AC,FA,58,AB), V(4B,E3,03,93), \
759 V(20,30,FA,55), V(AD,76,6D,F6), V(88,CC,76,91), V(F5,02,4C,25), \
760 V(4F,E5,D7,FC), V(C5,2A,CB,D7), V(26,35,44,80), V(B5,62,A3,8F), \
761 V(DE,B1,5A,49), V(25,BA,1B,67), V(45,EA,0E,98), V(5D,FE,C0,E1), \
762 V(C3,2F,75,02), V(81,4C,F0,12), V(8D,46,97,A3), V(6B,D3,F9,C6), \
763 V(03,8F,5F,E7), V(15,92,9C,95), V(BF,6D,7A,EB), V(95,52,59,DA), \
764 V(D4,BE,83,2D), V(58,74,21,D3), V(49,E0,69,29), V(8E,C9,C8,44), \
765 V(75,C2,89,6A), V(F4,8E,79,78), V(99,58,3E,6B), V(27,B9,71,DD), \
766 V(BE,E1,4F,B6), V(F0,88,AD,17), V(C9,20,AC,66), V(7D,CE,3A,B4), \
767 V(63,DF,4A,18), V(E5,1A,31,82), V(97,51,33,60), V(62,53,7F,45), \
768 V(B1,64,77,E0), V(BB,6B,AE,84), V(FE,81,A0,1C), V(F9,08,2B,94), \
769 V(70,48,68,58), V(8F,45,FD,19), V(94,DE,6C,87), V(52,7B,F8,B7), \
770 V(AB,73,D3,23), V(72,4B,02,E2), V(E3,1F,8F,57), V(66,55,AB,2A), \
771 V(B2,EB,28,07), V(2F,B5,C2,03), V(86,C5,7B,9A), V(D3,37,08,A5), \
772 V(30,28,87,F2), V(23,BF,A5,B2), V(02,03,6A,BA), V(ED,16,82,5C), \
773 V(8A,CF,1C,2B), V(A7,79,B4,92), V(F3,07,F2,F0), V(4E,69,E2,A1), \
774 V(65,DA,F4,CD), V(06,05,BE,D5), V(D1,34,62,1F), V(C4,A6,FE,8A), \
775 V(34,2E,53,9D), V(A2,F3,55,A0), V(05,8A,E1,32), V(A4,F6,EB,75), \
776 V(0B,83,EC,39), V(40,60,EF,AA), V(5E,71,9F,06), V(BD,6E,10,51), \
777 V(3E,21,8A,F9), V(96,DD,06,3D), V(DD,3E,05,AE), V(4D,E6,BD,46), \
778 V(91,54,8D,B5), V(71,C4,5D,05), V(04,06,D4,6F), V(60,50,15,FF), \
779 V(19,98,FB,24), V(D6,BD,E9,97), V(89,40,43,CC), V(67,D9,9E,77), \
780 V(B0,E8,42,BD), V(07,89,8B,88), V(E7,19,5B,38), V(79,C8,EE,DB), \
781 V(A1,7C,0A,47), V(7C,42,0F,E9), V(F8,84,1E,C9), V(00,00,00,00), \
782 V(09,80,86,83), V(32,2B,ED,48), V(1E,11,70,AC), V(6C,5A,72,4E), \
783 V(FD,0E,FF,FB), V(0F,85,38,56), V(3D,AE,D5,1E), V(36,2D,39,27), \
784 V(0A,0F,D9,64), V(68,5C,A6,21), V(9B,5B,54,D1), V(24,36,2E,3A), \
785 V(0C,0A,67,B1), V(93,57,E7,0F), V(B4,EE,96,D2), V(1B,9B,91,9E), \
786 V(80,C0,C5,4F), V(61,DC,20,A2), V(5A,77,4B,69), V(1C,12,1A,16), \
787 V(E2,93,BA,0A), V(C0,A0,2A,E5), V(3C,22,E0,43), V(12,1B,17,1D), \
788 V(0E,09,0D,0B), V(F2,8B,C7,AD), V(2D,B6,A8,B9), V(14,1E,A9,C8), \
789 V(57,F1,19,85), V(AF,75,07,4C), V(EE,99,DD,BB), V(A3,7F,60,FD), \
790 V(F7,01,26,9F), V(5C,72,F5,BC), V(44,66,3B,C5), V(5B,FB,7E,34), \
791 V(8B,43,29,76), V(CB,23,C6,DC), V(B6,ED,FC,68), V(B8,E4,F1,63), \
792 V(D7,31,DC,CA), V(42,63,85,10), V(13,97,22,40), V(84,C6,11,20), \
793 V(85,4A,24,7D), V(D2,BB,3D,F8), V(AE,F9,32,11), V(C7,29,A1,6D), \
794 V(1D,9E,2F,4B), V(DC,B2,30,F3), V(0D,86,52,EC), V(77,C1,E3,D0), \
795 V(2B,B3,16,6C), V(A9,70,B9,99), V(11,94,48,FA), V(47,E9,64,22), \
796 V(A8,FC,8C,C4), V(A0,F0,3F,1A), V(56,7D,2C,D8), V(22,33,90,EF), \
797 V(87,49,4E,C7), V(D9,38,D1,C1), V(8C,CA,A2,FE), V(98,D4,0B,36), \
798 V(A6,F5,81,CF), V(A5,7A,DE,28), V(DA,B7,8E,26), V(3F,AD,BF,A4), \
799 V(2C,3A,9D,E4), V(50,78,92,0D), V(6A,5F,CC,9B), V(54,7E,46,62), \
800 V(F6,8D,13,C2), V(90,D8,B8,E8), V(2E,39,F7,5E), V(82,C3,AF,F5), \
801 V(9F,5D,80,BE), V(69,D0,93,7C), V(6F,D5,2D,A9), V(CF,25,12,B3), \
802 V(C8,AC,99,3B), V(10,18,7D,A7), V(E8,9C,63,6E), V(DB,3B,BB,7B), \
803 V(CD,26,78,09), V(6E,59,18,F4), V(EC,9A,B7,01), V(83,4F,9A,A8), \
804 V(E6,95,6E,65), V(AA,FF,E6,7E), V(21,BC,CF,08), V(EF,15,E8,E6), \
805 V(BA,E7,9B,D9), V(4A,6F,36,CE), V(EA,9F,09,D4), V(29,B0,7C,D6), \
806 V(31,A4,B2,AF), V(2A,3F,23,31), V(C6,A5,94,30), V(35,A2,66,C0), \
807 V(74,4E,BC,37), V(FC,82,CA,A6), V(E0,90,D0,B0), V(33,A7,D8,15), \
808 V(F1,04,98,4A), V(41,EC,DA,F7), V(7F,CD,50,0E), V(17,91,F6,2F), \
809 V(76,4D,D6,8D), V(43,EF,B0,4D), V(CC,AA,4D,54), V(E4,96,04,DF), \
810 V(9E,D1,B5,E3), V(4C,6A,88,1B), V(C1,2C,1F,B8), V(46,65,51,7F), \
811 V(9D,5E,EA,04), V(01,8C,35,5D), V(FA,87,74,73), V(FB,0B,41,2E), \
812 V(B3,67,1D,5A), V(92,DB,D2,52), V(E9,10,56,33), V(6D,D6,47,13), \
813 V(9A,D7,61,8C), V(37,A1,0C,7A), V(59,F8,14,8E), V(EB,13,3C,89), \
814 V(CE,A9,27,EE), V(B7,61,C9,35), V(E1,1C,E5,ED), V(7A,47,B1,3C), \
815 V(9C,D2,DF,59), V(55,F2,73,3F), V(18,14,CE,79), V(73,C7,37,BF), \
816 V(53,F7,CD,EA), V(5F,FD,AA,5B), V(DF,3D,6F,14), V(78,44,DB,86), \
817 V(CA,AF,F3,81), V(B9,68,C4,3E), V(38,24,34,2C), V(C2,A3,40,5F), \
818 V(16,1D,C3,72), V(BC,E2,25,0C), V(28,3C,49,8B), V(FF,0D,95,41), \
819 V(39,A8,01,71), V(08,0C,B3,DE), V(D8,B4,E4,9C), V(64,56,C1,90), \
820 V(7B,CB,84,61), V(D5,32,B6,70), V(48,6C,5C,74), V(D0,B8,57,42)
821
822#define V(a,b,c,d) 0x##a##b##c##d
823static uint32 RT0[256] = { RT };
824
825#undef V
826
827#define V(a,b,c,d) 0x##d##a##b##c
828static uint32 RT1[256] = { RT };
829
830#undef V
831
832#define V(a,b,c,d) 0x##c##d##a##b
833static uint32 RT2[256] = { RT };
834
835#undef V
836
837#define V(a,b,c,d) 0x##b##c##d##a
838static uint32 RT3[256] = { RT };
839
840#undef V
841
842#undef RT
843
844/* round constants */
845
846static uint32 RCON[10] = {
847 0x01000000, 0x02000000, 0x04000000, 0x08000000,
848 0x10000000, 0x20000000, 0x40000000, 0x80000000,
849 0x1B000000, 0x36000000
850};
851
852/* key schedule tables */
853
854static int KT_init = 1;
855
856static uint32 KT0[256];
857static uint32 KT1[256];
858static uint32 KT2[256];
859static uint32 KT3[256];
860
861/* platform-independent 32-bit integer manipulation macros */
862
863#define GET_UINT32(n,b,i) \
864{ \
865 (n) = ( (uint32) (b)[(i) ] << 24 ) \
866 | ( (uint32) (b)[(i) + 1] << 16 ) \
867 | ( (uint32) (b)[(i) + 2] << 8 ) \
868 | ( (uint32) (b)[(i) + 3] ); \
869}
870
871#define PUT_UINT32(n,b,i) \
872{ \
873 (b)[(i) ] = (uint8) ( (n) >> 24 ); \
874 (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
875 (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
876 (b)[(i) + 3] = (uint8) ( (n) ); \
877}
878
879int rt_aes_set_key(struct aes_context * ctx, uint8 * key, int nbits)
880{
881 int i;
882 uint32 *RK, *SK;
883
884 switch (nbits) {
885 case 128:
886 ctx->nr = 10;
887 break;
888 case 192:
889 ctx->nr = 12;
890 break;
891 case 256:
892 ctx->nr = 14;
893 break;
894 default:
895 return (1);
896 }
897
898 RK = (uint32 *) ctx->erk;
899
900 for (i = 0; i < (nbits >> 5); i++) {
901 GET_UINT32(RK[i], key, i * 4);
902 }
903
904 /* setup encryption round keys */
905
906 switch (nbits) {
907 case 128:
908
909 for (i = 0; i < 10; i++, RK += 4) {
910 RK[4] = RK[0] ^ RCON[i] ^
911 (FSb[(uint8) (RK[3] >> 16)] << 24) ^
912 (FSb[(uint8) (RK[3] >> 8)] << 16) ^
913 (FSb[(uint8) (RK[3])] << 8) ^
914 (FSb[(uint8) (RK[3] >> 24)]);
915
916 RK[5] = RK[1] ^ RK[4];
917 RK[6] = RK[2] ^ RK[5];
918 RK[7] = RK[3] ^ RK[6];
919 }
920 break;
921
922 case 192:
923
924 for (i = 0; i < 8; i++, RK += 6) {
925 RK[6] = RK[0] ^ RCON[i] ^
926 (FSb[(uint8) (RK[5] >> 16)] << 24) ^
927 (FSb[(uint8) (RK[5] >> 8)] << 16) ^
928 (FSb[(uint8) (RK[5])] << 8) ^
929 (FSb[(uint8) (RK[5] >> 24)]);
930
931 RK[7] = RK[1] ^ RK[6];
932 RK[8] = RK[2] ^ RK[7];
933 RK[9] = RK[3] ^ RK[8];
934 RK[10] = RK[4] ^ RK[9];
935 RK[11] = RK[5] ^ RK[10];
936 }
937 break;
938
939 case 256:
940
941 for (i = 0; i < 7; i++, RK += 8) {
942 RK[8] = RK[0] ^ RCON[i] ^
943 (FSb[(uint8) (RK[7] >> 16)] << 24) ^
944 (FSb[(uint8) (RK[7] >> 8)] << 16) ^
945 (FSb[(uint8) (RK[7])] << 8) ^
946 (FSb[(uint8) (RK[7] >> 24)]);
947
948 RK[9] = RK[1] ^ RK[8];
949 RK[10] = RK[2] ^ RK[9];
950 RK[11] = RK[3] ^ RK[10];
951
952 RK[12] = RK[4] ^
953 (FSb[(uint8) (RK[11] >> 24)] << 24) ^
954 (FSb[(uint8) (RK[11] >> 16)] << 16) ^
955 (FSb[(uint8) (RK[11] >> 8)] << 8) ^
956 (FSb[(uint8) (RK[11])]);
957
958 RK[13] = RK[5] ^ RK[12];
959 RK[14] = RK[6] ^ RK[13];
960 RK[15] = RK[7] ^ RK[14];
961 }
962 break;
963 }
964
965 /* setup decryption round keys */
966
967 if (KT_init) {
968 for (i = 0; i < 256; i++) {
969 KT0[i] = RT0[FSb[i]];
970 KT1[i] = RT1[FSb[i]];
971 KT2[i] = RT2[FSb[i]];
972 KT3[i] = RT3[FSb[i]];
973 }
974
975 KT_init = 0;
976 }
977
978 SK = (uint32 *) ctx->drk;
979
980 *SK++ = *RK++;
981 *SK++ = *RK++;
982 *SK++ = *RK++;
983 *SK++ = *RK++;
984
985 for (i = 1; i < ctx->nr; i++) {
986 RK -= 8;
987
988 *SK++ = KT0[(uint8) (*RK >> 24)] ^
989 KT1[(uint8) (*RK >> 16)] ^
990 KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)];
991 RK++;
992
993 *SK++ = KT0[(uint8) (*RK >> 24)] ^
994 KT1[(uint8) (*RK >> 16)] ^
995 KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)];
996 RK++;
997
998 *SK++ = KT0[(uint8) (*RK >> 24)] ^
999 KT1[(uint8) (*RK >> 16)] ^
1000 KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)];
1001 RK++;
1002
1003 *SK++ = KT0[(uint8) (*RK >> 24)] ^
1004 KT1[(uint8) (*RK >> 16)] ^
1005 KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)];
1006 RK++;
1007 }
1008
1009 RK -= 8;
1010
1011 *SK++ = *RK++;
1012 *SK++ = *RK++;
1013 *SK++ = *RK++;
1014 *SK++ = *RK++;
1015
1016 return (0);
1017}
1018
1019/* AES 128-bit block encryption routine */
1020
1021void rt_aes_encrypt(struct aes_context * ctx, uint8 input[16], uint8 output[16])
1022{
1023 uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
1024
1025 RK = (uint32 *) ctx->erk;
1026 GET_UINT32(X0, input, 0);
1027 X0 ^= RK[0];
1028 GET_UINT32(X1, input, 4);
1029 X1 ^= RK[1];
1030 GET_UINT32(X2, input, 8);
1031 X2 ^= RK[2];
1032 GET_UINT32(X3, input, 12);
1033 X3 ^= RK[3];
1034
1035#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
1036{ \
1037 RK += 4; \
1038 \
1039 X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^ \
1040 FT1[ (uint8) ( Y1 >> 16 ) ] ^ \
1041 FT2[ (uint8) ( Y2 >> 8 ) ] ^ \
1042 FT3[ (uint8) ( Y3 ) ]; \
1043 \
1044 X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^ \
1045 FT1[ (uint8) ( Y2 >> 16 ) ] ^ \
1046 FT2[ (uint8) ( Y3 >> 8 ) ] ^ \
1047 FT3[ (uint8) ( Y0 ) ]; \
1048 \
1049 X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^ \
1050 FT1[ (uint8) ( Y3 >> 16 ) ] ^ \
1051 FT2[ (uint8) ( Y0 >> 8 ) ] ^ \
1052 FT3[ (uint8) ( Y1 ) ]; \
1053 \
1054 X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^ \
1055 FT1[ (uint8) ( Y0 >> 16 ) ] ^ \
1056 FT2[ (uint8) ( Y1 >> 8 ) ] ^ \
1057 FT3[ (uint8) ( Y2 ) ]; \
1058}
1059
1060 AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 1 */
1061 AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 2 */
1062 AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 3 */
1063 AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 4 */
1064 AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 5 */
1065 AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 6 */
1066 AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 7 */
1067 AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 8 */
1068 AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 9 */
1069
1070 if (ctx->nr > 10) {
1071 AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 10 */
1072 AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 11 */
1073 }
1074
1075 if (ctx->nr > 12) {
1076 AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 12 */
1077 AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 13 */
1078 }
1079
1080 /* last round */
1081
1082 RK += 4;
1083
1084 X0 = RK[0] ^ (FSb[(uint8) (Y0 >> 24)] << 24) ^
1085 (FSb[(uint8) (Y1 >> 16)] << 16) ^
1086 (FSb[(uint8) (Y2 >> 8)] << 8) ^ (FSb[(uint8) (Y3)]);
1087
1088 X1 = RK[1] ^ (FSb[(uint8) (Y1 >> 24)] << 24) ^
1089 (FSb[(uint8) (Y2 >> 16)] << 16) ^
1090 (FSb[(uint8) (Y3 >> 8)] << 8) ^ (FSb[(uint8) (Y0)]);
1091
1092 X2 = RK[2] ^ (FSb[(uint8) (Y2 >> 24)] << 24) ^
1093 (FSb[(uint8) (Y3 >> 16)] << 16) ^
1094 (FSb[(uint8) (Y0 >> 8)] << 8) ^ (FSb[(uint8) (Y1)]);
1095
1096 X3 = RK[3] ^ (FSb[(uint8) (Y3 >> 24)] << 24) ^
1097 (FSb[(uint8) (Y0 >> 16)] << 16) ^
1098 (FSb[(uint8) (Y1 >> 8)] << 8) ^ (FSb[(uint8) (Y2)]);
1099
1100 PUT_UINT32(X0, output, 0);
1101 PUT_UINT32(X1, output, 4);
1102 PUT_UINT32(X2, output, 8);
1103 PUT_UINT32(X3, output, 12);
1104}
1105
1106/* AES 128-bit block decryption routine */
1107
1108void rt_aes_decrypt(struct aes_context * ctx, uint8 input[16], uint8 output[16])
1109{
1110 uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
1111
1112 RK = (uint32 *) ctx->drk;
1113
1114 GET_UINT32(X0, input, 0);
1115 X0 ^= RK[0];
1116 GET_UINT32(X1, input, 4);
1117 X1 ^= RK[1];
1118 GET_UINT32(X2, input, 8);
1119 X2 ^= RK[2];
1120 GET_UINT32(X3, input, 12);
1121 X3 ^= RK[3];
1122
1123#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
1124{ \
1125 RK += 4; \
1126 \
1127 X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^ \
1128 RT1[ (uint8) ( Y3 >> 16 ) ] ^ \
1129 RT2[ (uint8) ( Y2 >> 8 ) ] ^ \
1130 RT3[ (uint8) ( Y1 ) ]; \
1131 \
1132 X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^ \
1133 RT1[ (uint8) ( Y0 >> 16 ) ] ^ \
1134 RT2[ (uint8) ( Y3 >> 8 ) ] ^ \
1135 RT3[ (uint8) ( Y2 ) ]; \
1136 \
1137 X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^ \
1138 RT1[ (uint8) ( Y1 >> 16 ) ] ^ \
1139 RT2[ (uint8) ( Y0 >> 8 ) ] ^ \
1140 RT3[ (uint8) ( Y3 ) ]; \
1141 \
1142 X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^ \
1143 RT1[ (uint8) ( Y2 >> 16 ) ] ^ \
1144 RT2[ (uint8) ( Y1 >> 8 ) ] ^ \
1145 RT3[ (uint8) ( Y0 ) ]; \
1146}
1147
1148 AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 1 */
1149 AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 2 */
1150 AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 3 */
1151 AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 4 */
1152 AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 5 */
1153 AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 6 */
1154 AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 7 */
1155 AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 8 */
1156 AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 9 */
1157
1158 if (ctx->nr > 10) {
1159 AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 10 */
1160 AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 11 */
1161 }
1162
1163 if (ctx->nr > 12) {
1164 AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 12 */
1165 AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 13 */
1166 }
1167
1168 /* last round */
1169
1170 RK += 4;
1171
1172 X0 = RK[0] ^ (RSb[(uint8) (Y0 >> 24)] << 24) ^
1173 (RSb[(uint8) (Y3 >> 16)] << 16) ^
1174 (RSb[(uint8) (Y2 >> 8)] << 8) ^ (RSb[(uint8) (Y1)]);
1175
1176 X1 = RK[1] ^ (RSb[(uint8) (Y1 >> 24)] << 24) ^
1177 (RSb[(uint8) (Y0 >> 16)] << 16) ^
1178 (RSb[(uint8) (Y3 >> 8)] << 8) ^ (RSb[(uint8) (Y2)]);
1179
1180 X2 = RK[2] ^ (RSb[(uint8) (Y2 >> 24)] << 24) ^
1181 (RSb[(uint8) (Y1 >> 16)] << 16) ^
1182 (RSb[(uint8) (Y0 >> 8)] << 8) ^ (RSb[(uint8) (Y3)]);
1183
1184 X3 = RK[3] ^ (RSb[(uint8) (Y3 >> 24)] << 24) ^
1185 (RSb[(uint8) (Y2 >> 16)] << 16) ^
1186 (RSb[(uint8) (Y1 >> 8)] << 8) ^ (RSb[(uint8) (Y0)]);
1187
1188 PUT_UINT32(X0, output, 0);
1189 PUT_UINT32(X1, output, 4);
1190 PUT_UINT32(X2, output, 8);
1191 PUT_UINT32(X3, output, 12);
1192}
1193
1194/*
1195 ==========================================================================
1196 Description:
1197 ENCRYPT AES GTK before sending in EAPOL frame.
1198 AES GTK length = 128 bit, so fix blocks for aes-key-wrap as 2 in this function.
1199 This function references to RFC 3394 for aes key wrap algorithm.
1200 Return:
1201 ==========================================================================
1202*/
1203void AES_GTK_KEY_WRAP(u8 * key,
1204 u8 * plaintext,
1205 u32 p_len, u8 * ciphertext)
1206{
1207 u8 A[8], BIN[16], BOUT[16];
1208 u8 R[512];
1209 int num_blocks = p_len / 8; /* unit:64bits */
1210 int i, j;
1211 struct aes_context aesctx;
1212 u8 xor;
1213
1214 rt_aes_set_key(&aesctx, key, 128);
1215
1216 /* Init IA */
1217 for (i = 0; i < 8; i++)
1218 A[i] = 0xa6;
1219
1220 /*Input plaintext */
1221 for (i = 0; i < num_blocks; i++) {
1222 for (j = 0; j < 8; j++)
1223 R[8 * (i + 1) + j] = plaintext[8 * i + j];
1224 }
1225
1226 /* Key Mix */
1227 for (j = 0; j < 6; j++) {
1228 for (i = 1; i <= num_blocks; i++) {
1229 /*phase 1 */
1230 NdisMoveMemory(BIN, A, 8);
1231 NdisMoveMemory(&BIN[8], &R[8 * i], 8);
1232 rt_aes_encrypt(&aesctx, BIN, BOUT);
1233
1234 NdisMoveMemory(A, &BOUT[0], 8);
1235 xor = num_blocks * j + i;
1236 A[7] = BOUT[7] ^ xor;
1237 NdisMoveMemory(&R[8 * i], &BOUT[8], 8);
1238 }
1239 }
1240
1241 /* Output ciphertext */
1242 NdisMoveMemory(ciphertext, A, 8);
1243
1244 for (i = 1; i <= num_blocks; i++) {
1245 for (j = 0; j < 8; j++)
1246 ciphertext[8 * i + j] = R[8 * i + j];
1247 }
1248}
1249
1250/*
1251 ========================================================================
1252
1253 Routine Description:
1254 Misc function to decrypt AES body
1255
1256 Arguments:
1257
1258 Return Value:
1259
1260 Note:
1261 This function references to RFC 3394 for aes key unwrap algorithm.
1262
1263 ========================================================================
1264*/
1265void AES_GTK_KEY_UNWRAP(u8 * key,
1266 u8 * plaintext,
1267 u32 c_len, u8 * ciphertext)
1268{
1269 u8 A[8], BIN[16], BOUT[16];
1270 u8 xor;
1271 int i, j;
1272 struct aes_context aesctx;
1273 u8 *R;
1274 int num_blocks = c_len / 8; /* unit:64bits */
1275
1276 os_alloc_mem(NULL, (u8 **) & R, 512);
1277
1278 if (R == NULL) {
1279 DBGPRINT(RT_DEBUG_ERROR,
1280 ("AES_GTK_KEY_UNWRAP: no memory!\n"));
1281 return;
1282 }
1283 /* End of if */
1284 /* Initialize */
1285 NdisMoveMemory(A, ciphertext, 8);
1286 /*Input plaintext */
1287 for (i = 0; i < (c_len - 8); i++) {
1288 R[i] = ciphertext[i + 8];
1289 }
1290
1291 rt_aes_set_key(&aesctx, key, 128);
1292
1293 for (j = 5; j >= 0; j--) {
1294 for (i = (num_blocks - 1); i > 0; i--) {
1295 xor = (num_blocks - 1) * j + i;
1296 NdisMoveMemory(BIN, A, 8);
1297 BIN[7] = A[7] ^ xor;
1298 NdisMoveMemory(&BIN[8], &R[(i - 1) * 8], 8);
1299 rt_aes_decrypt(&aesctx, BIN, BOUT);
1300 NdisMoveMemory(A, &BOUT[0], 8);
1301 NdisMoveMemory(&R[(i - 1) * 8], &BOUT[8], 8);
1302 }
1303 }
1304
1305 /* OUTPUT */
1306 for (i = 0; i < c_len; i++) {
1307 plaintext[i] = R[i];
1308 }
1309
1310 os_free_mem(NULL, R);
1311}
diff --git a/drivers/staging/rt2860/common/cmm_asic.c b/drivers/staging/rt2860/common/cmm_asic.c
deleted file mode 100644
index 4d77e83eb41..00000000000
--- a/drivers/staging/rt2860/common/cmm_asic.c
+++ /dev/null
@@ -1,2565 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 cmm_asic.c
29
30 Abstract:
31 Functions used to communicate with ASIC
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#include "../rt_config.h"
39
40/* Reset the RFIC setting to new series */
41struct rt_rtmp_rf_regs RF2850RegTable[] = {
42/* ch R1 R2 R3(TX0~4=0) R4 */
43 {1, 0x98402ecc, 0x984c0786, 0x9816b455, 0x9800510b}
44 ,
45 {2, 0x98402ecc, 0x984c0786, 0x98168a55, 0x9800519f}
46 ,
47 {3, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800518b}
48 ,
49 {4, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800519f}
50 ,
51 {5, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800518b}
52 ,
53 {6, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800519f}
54 ,
55 {7, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800518b}
56 ,
57 {8, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800519f}
58 ,
59 {9, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800518b}
60 ,
61 {10, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800519f}
62 ,
63 {11, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800518b}
64 ,
65 {12, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800519f}
66 ,
67 {13, 0x98402ecc, 0x984c079e, 0x98168a55, 0x9800518b}
68 ,
69 {14, 0x98402ecc, 0x984c07a2, 0x98168a55, 0x98005193}
70 ,
71
72 /* 802.11 UNI / HyperLan 2 */
73 {36, 0x98402ecc, 0x984c099a, 0x98158a55, 0x980ed1a3}
74 ,
75 {38, 0x98402ecc, 0x984c099e, 0x98158a55, 0x980ed193}
76 ,
77 {40, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed183}
78 ,
79 {44, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed1a3}
80 ,
81 {46, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed18b}
82 ,
83 {48, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed19b}
84 ,
85 {52, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed193}
86 ,
87 {54, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed1a3}
88 ,
89 {56, 0x98402ec8, 0x984c068e, 0x98158a55, 0x980ed18b}
90 ,
91 {60, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed183}
92 ,
93 {62, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed193}
94 ,
95 {64, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed1a3}
96 , /* Plugfest#4, Day4, change RFR3 left4th 9->5. */
97
98 /* 802.11 HyperLan 2 */
99 {100, 0x98402ec8, 0x984c06b2, 0x98178a55, 0x980ed783}
100 ,
101
102 /* 2008.04.30 modified */
103 /* The system team has AN to improve the EVM value */
104 /* for channel 102 to 108 for the RT2850/RT2750 dual band solution. */
105 {102, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed793}
106 ,
107 {104, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed1a3}
108 ,
109 {108, 0x98402ecc, 0x985c0a32, 0x98578a55, 0x980ed193}
110 ,
111
112 {110, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed183}
113 ,
114 {112, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed19b}
115 ,
116 {116, 0x98402ecc, 0x984c0a3a, 0x98178a55, 0x980ed1a3}
117 ,
118 {118, 0x98402ecc, 0x984c0a3e, 0x98178a55, 0x980ed193}
119 ,
120 {120, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed183}
121 ,
122 {124, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed193}
123 ,
124 {126, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed15b}
125 , /* 0x980ed1bb->0x980ed15b required by Rory 20070927 */
126 {128, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed1a3}
127 ,
128 {132, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed18b}
129 ,
130 {134, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed193}
131 ,
132 {136, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed19b}
133 ,
134 {140, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed183}
135 ,
136
137 /* 802.11 UNII */
138 {149, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed1a7}
139 ,
140 {151, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed187}
141 ,
142 {153, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed18f}
143 ,
144 {157, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed19f}
145 ,
146 {159, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed1a7}
147 ,
148 {161, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed187}
149 ,
150 {165, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed197}
151 ,
152 {167, 0x98402ec4, 0x984c03d2, 0x98179855, 0x9815531f}
153 ,
154 {169, 0x98402ec4, 0x984c03d2, 0x98179855, 0x98155327}
155 ,
156 {171, 0x98402ec4, 0x984c03d6, 0x98179855, 0x98155307}
157 ,
158 {173, 0x98402ec4, 0x984c03d6, 0x98179855, 0x9815530f}
159 ,
160
161 /* Japan */
162 {184, 0x95002ccc, 0x9500491e, 0x9509be55, 0x950c0a0b}
163 ,
164 {188, 0x95002ccc, 0x95004922, 0x9509be55, 0x950c0a13}
165 ,
166 {192, 0x95002ccc, 0x95004926, 0x9509be55, 0x950c0a1b}
167 ,
168 {196, 0x95002ccc, 0x9500492a, 0x9509be55, 0x950c0a23}
169 ,
170 {208, 0x95002ccc, 0x9500493a, 0x9509be55, 0x950c0a13}
171 ,
172 {212, 0x95002ccc, 0x9500493e, 0x9509be55, 0x950c0a1b}
173 ,
174 {216, 0x95002ccc, 0x95004982, 0x9509be55, 0x950c0a23}
175 ,
176
177 /* still lack of MMAC(Japan) ch 34,38,42,46 */
178};
179
180u8 NUM_OF_2850_CHNL = (sizeof(RF2850RegTable) / sizeof(struct rt_rtmp_rf_regs));
181
182struct rt_frequency_item FreqItems3020[] = {
183 /**************************************************/
184 /* ISM : 2.4 to 2.483 GHz // */
185 /**************************************************/
186 /* 11g */
187 /**************************************************/
188 /*-CH---N-------R---K----------- */
189 {1, 241, 2, 2}
190 ,
191 {2, 241, 2, 7}
192 ,
193 {3, 242, 2, 2}
194 ,
195 {4, 242, 2, 7}
196 ,
197 {5, 243, 2, 2}
198 ,
199 {6, 243, 2, 7}
200 ,
201 {7, 244, 2, 2}
202 ,
203 {8, 244, 2, 7}
204 ,
205 {9, 245, 2, 2}
206 ,
207 {10, 245, 2, 7}
208 ,
209 {11, 246, 2, 2}
210 ,
211 {12, 246, 2, 7}
212 ,
213 {13, 247, 2, 2}
214 ,
215 {14, 248, 2, 4}
216 ,
217};
218
219u8 NUM_OF_3020_CHNL = (sizeof(FreqItems3020) / sizeof(struct rt_frequency_item));
220
221void AsicUpdateAutoFallBackTable(struct rt_rtmp_adapter *pAd, u8 *pRateTable)
222{
223 u8 i;
224 HT_FBK_CFG0_STRUC HtCfg0;
225 HT_FBK_CFG1_STRUC HtCfg1;
226 LG_FBK_CFG0_STRUC LgCfg0;
227 LG_FBK_CFG1_STRUC LgCfg1;
228 struct rt_rtmp_tx_rate_switch *pCurrTxRate, *pNextTxRate;
229
230 /* set to initial value */
231 HtCfg0.word = 0x65432100;
232 HtCfg1.word = 0xedcba988;
233 LgCfg0.word = 0xedcba988;
234 LgCfg1.word = 0x00002100;
235
236 pNextTxRate = (struct rt_rtmp_tx_rate_switch *) pRateTable + 1;
237 for (i = 1; i < *((u8 *)pRateTable); i++) {
238 pCurrTxRate = (struct rt_rtmp_tx_rate_switch *) pRateTable + 1 + i;
239 switch (pCurrTxRate->Mode) {
240 case 0: /*CCK */
241 break;
242 case 1: /*OFDM */
243 {
244 switch (pCurrTxRate->CurrMCS) {
245 case 0:
246 LgCfg0.field.OFDMMCS0FBK =
247 (pNextTxRate->Mode ==
248 MODE_OFDM) ? (pNextTxRate->
249 CurrMCS +
250 8) : pNextTxRate->
251 CurrMCS;
252 break;
253 case 1:
254 LgCfg0.field.OFDMMCS1FBK =
255 (pNextTxRate->Mode ==
256 MODE_OFDM) ? (pNextTxRate->
257 CurrMCS +
258 8) : pNextTxRate->
259 CurrMCS;
260 break;
261 case 2:
262 LgCfg0.field.OFDMMCS2FBK =
263 (pNextTxRate->Mode ==
264 MODE_OFDM) ? (pNextTxRate->
265 CurrMCS +
266 8) : pNextTxRate->
267 CurrMCS;
268 break;
269 case 3:
270 LgCfg0.field.OFDMMCS3FBK =
271 (pNextTxRate->Mode ==
272 MODE_OFDM) ? (pNextTxRate->
273 CurrMCS +
274 8) : pNextTxRate->
275 CurrMCS;
276 break;
277 case 4:
278 LgCfg0.field.OFDMMCS4FBK =
279 (pNextTxRate->Mode ==
280 MODE_OFDM) ? (pNextTxRate->
281 CurrMCS +
282 8) : pNextTxRate->
283 CurrMCS;
284 break;
285 case 5:
286 LgCfg0.field.OFDMMCS5FBK =
287 (pNextTxRate->Mode ==
288 MODE_OFDM) ? (pNextTxRate->
289 CurrMCS +
290 8) : pNextTxRate->
291 CurrMCS;
292 break;
293 case 6:
294 LgCfg0.field.OFDMMCS6FBK =
295 (pNextTxRate->Mode ==
296 MODE_OFDM) ? (pNextTxRate->
297 CurrMCS +
298 8) : pNextTxRate->
299 CurrMCS;
300 break;
301 case 7:
302 LgCfg0.field.OFDMMCS7FBK =
303 (pNextTxRate->Mode ==
304 MODE_OFDM) ? (pNextTxRate->
305 CurrMCS +
306 8) : pNextTxRate->
307 CurrMCS;
308 break;
309 }
310 }
311 break;
312 case 2: /*HT-MIX */
313 case 3: /*HT-GF */
314 {
315 if ((pNextTxRate->Mode >= MODE_HTMIX)
316 && (pCurrTxRate->CurrMCS !=
317 pNextTxRate->CurrMCS)) {
318 switch (pCurrTxRate->CurrMCS) {
319 case 0:
320 HtCfg0.field.HTMCS0FBK =
321 pNextTxRate->CurrMCS;
322 break;
323 case 1:
324 HtCfg0.field.HTMCS1FBK =
325 pNextTxRate->CurrMCS;
326 break;
327 case 2:
328 HtCfg0.field.HTMCS2FBK =
329 pNextTxRate->CurrMCS;
330 break;
331 case 3:
332 HtCfg0.field.HTMCS3FBK =
333 pNextTxRate->CurrMCS;
334 break;
335 case 4:
336 HtCfg0.field.HTMCS4FBK =
337 pNextTxRate->CurrMCS;
338 break;
339 case 5:
340 HtCfg0.field.HTMCS5FBK =
341 pNextTxRate->CurrMCS;
342 break;
343 case 6:
344 HtCfg0.field.HTMCS6FBK =
345 pNextTxRate->CurrMCS;
346 break;
347 case 7:
348 HtCfg0.field.HTMCS7FBK =
349 pNextTxRate->CurrMCS;
350 break;
351 case 8:
352 HtCfg1.field.HTMCS8FBK =
353 pNextTxRate->CurrMCS;
354 break;
355 case 9:
356 HtCfg1.field.HTMCS9FBK =
357 pNextTxRate->CurrMCS;
358 break;
359 case 10:
360 HtCfg1.field.HTMCS10FBK =
361 pNextTxRate->CurrMCS;
362 break;
363 case 11:
364 HtCfg1.field.HTMCS11FBK =
365 pNextTxRate->CurrMCS;
366 break;
367 case 12:
368 HtCfg1.field.HTMCS12FBK =
369 pNextTxRate->CurrMCS;
370 break;
371 case 13:
372 HtCfg1.field.HTMCS13FBK =
373 pNextTxRate->CurrMCS;
374 break;
375 case 14:
376 HtCfg1.field.HTMCS14FBK =
377 pNextTxRate->CurrMCS;
378 break;
379 case 15:
380 HtCfg1.field.HTMCS15FBK =
381 pNextTxRate->CurrMCS;
382 break;
383 default:
384 DBGPRINT(RT_DEBUG_ERROR,
385 ("AsicUpdateAutoFallBackTable: not support CurrMCS=%d\n",
386 pCurrTxRate->
387 CurrMCS));
388 }
389 }
390 }
391 break;
392 }
393
394 pNextTxRate = pCurrTxRate;
395 }
396
397 RTMP_IO_WRITE32(pAd, HT_FBK_CFG0, HtCfg0.word);
398 RTMP_IO_WRITE32(pAd, HT_FBK_CFG1, HtCfg1.word);
399 RTMP_IO_WRITE32(pAd, LG_FBK_CFG0, LgCfg0.word);
400 RTMP_IO_WRITE32(pAd, LG_FBK_CFG1, LgCfg1.word);
401}
402
403/*
404 ========================================================================
405
406 Routine Description:
407 Set MAC register value according operation mode.
408 OperationMode AND bNonGFExist are for MM and GF Proteciton.
409 If MM or GF mask is not set, those passing argument doesn't not take effect.
410
411 Operation mode meaning:
412 = 0 : Pure HT, no preotection.
413 = 0x01; there may be non-HT devices in both the control and extension channel, protection is optional in BSS.
414 = 0x10: No Transmission in 40M is protected.
415 = 0x11: Transmission in both 40M and 20M shall be protected
416 if (bNonGFExist)
417 we should choose not to use GF. But still set correct ASIC registers.
418 ========================================================================
419*/
420void AsicUpdateProtect(struct rt_rtmp_adapter *pAd,
421 u16 OperationMode,
422 u8 SetMask,
423 IN BOOLEAN bDisableBGProtect, IN BOOLEAN bNonGFExist)
424{
425 PROT_CFG_STRUC ProtCfg, ProtCfg4;
426 u32 Protect[6];
427 u16 offset;
428 u8 i;
429 u32 MacReg = 0;
430
431 if (!(pAd->CommonCfg.bHTProtect) && (OperationMode != 8)) {
432 return;
433 }
434
435 if (pAd->BATable.numDoneOriginator) {
436 /* */
437 /* enable the RTS/CTS to avoid channel collision */
438 /* */
439 SetMask = ALLN_SETPROTECT;
440 OperationMode = 8;
441 }
442 /* Config ASIC RTS threshold register */
443 RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg);
444 MacReg &= 0xFF0000FF;
445 /* If the user want disable RtsThreshold and enable Amsdu/Ralink-Aggregation, set the RtsThreshold as 4096 */
446 if (((pAd->CommonCfg.BACapability.field.AmsduEnable) ||
447 (pAd->CommonCfg.bAggregationCapable == TRUE))
448 && pAd->CommonCfg.RtsThreshold == MAX_RTS_THRESHOLD) {
449 MacReg |= (0x1000 << 8);
450 } else {
451 MacReg |= (pAd->CommonCfg.RtsThreshold << 8);
452 }
453
454 RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg);
455
456 /* Initial common protection settings */
457 RTMPZeroMemory(Protect, sizeof(Protect));
458 ProtCfg4.word = 0;
459 ProtCfg.word = 0;
460 ProtCfg.field.TxopAllowGF40 = 1;
461 ProtCfg.field.TxopAllowGF20 = 1;
462 ProtCfg.field.TxopAllowMM40 = 1;
463 ProtCfg.field.TxopAllowMM20 = 1;
464 ProtCfg.field.TxopAllowOfdm = 1;
465 ProtCfg.field.TxopAllowCck = 1;
466 ProtCfg.field.RTSThEn = 1;
467 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
468
469 /* update PHY mode and rate */
470 if (pAd->CommonCfg.Channel > 14)
471 ProtCfg.field.ProtectRate = 0x4000;
472 ProtCfg.field.ProtectRate |= pAd->CommonCfg.RtsRate;
473
474 /* Handle legacy(B/G) protection */
475 if (bDisableBGProtect) {
476 /*ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate; */
477 ProtCfg.field.ProtectCtrl = 0;
478 Protect[0] = ProtCfg.word;
479 Protect[1] = ProtCfg.word;
480 pAd->FlgCtsEnabled = 0; /* CTS-self is not used */
481 } else {
482 /*ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate; */
483 ProtCfg.field.ProtectCtrl = 0; /* CCK do not need to be protected */
484 Protect[0] = ProtCfg.word;
485 ProtCfg.field.ProtectCtrl = ASIC_CTS; /* OFDM needs using CCK to protect */
486 Protect[1] = ProtCfg.word;
487 pAd->FlgCtsEnabled = 1; /* CTS-self is used */
488 }
489
490 /* Decide HT frame protection. */
491 if ((SetMask & ALLN_SETPROTECT) != 0) {
492 switch (OperationMode) {
493 case 0x0:
494 /* NO PROTECT */
495 /* 1.All STAs in the BSS are 20/40 MHz HT */
496 /* 2. in ai 20/40MHz BSS */
497 /* 3. all STAs are 20MHz in a 20MHz BSS */
498 /* Pure HT. no protection. */
499
500 /* MM20_PROT_CFG */
501 /* Reserved (31:27) */
502 /* PROT_TXOP(25:20) -- 010111 */
503 /* PROT_NAV(19:18) -- 01 (Short NAV protection) */
504 /* PROT_CTRL(17:16) -- 00 (None) */
505 /* PROT_RATE(15:0) -- 0x4004 (OFDM 24M) */
506 Protect[2] = 0x01744004;
507
508 /* MM40_PROT_CFG */
509 /* Reserved (31:27) */
510 /* PROT_TXOP(25:20) -- 111111 */
511 /* PROT_NAV(19:18) -- 01 (Short NAV protection) */
512 /* PROT_CTRL(17:16) -- 00 (None) */
513 /* PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M) */
514 Protect[3] = 0x03f44084;
515
516 /* CF20_PROT_CFG */
517 /* Reserved (31:27) */
518 /* PROT_TXOP(25:20) -- 010111 */
519 /* PROT_NAV(19:18) -- 01 (Short NAV protection) */
520 /* PROT_CTRL(17:16) -- 00 (None) */
521 /* PROT_RATE(15:0) -- 0x4004 (OFDM 24M) */
522 Protect[4] = 0x01744004;
523
524 /* CF40_PROT_CFG */
525 /* Reserved (31:27) */
526 /* PROT_TXOP(25:20) -- 111111 */
527 /* PROT_NAV(19:18) -- 01 (Short NAV protection) */
528 /* PROT_CTRL(17:16) -- 00 (None) */
529 /* PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M) */
530 Protect[5] = 0x03f44084;
531
532 if (bNonGFExist) {
533 /* PROT_NAV(19:18) -- 01 (Short NAV protectiion) */
534 /* PROT_CTRL(17:16) -- 01 (RTS/CTS) */
535 Protect[4] = 0x01754004;
536 Protect[5] = 0x03f54084;
537 }
538 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
539 break;
540
541 case 1:
542 /* This is "HT non-member protection mode." */
543 /* If there may be non-HT STAs my BSS */
544 ProtCfg.word = 0x01744004; /* PROT_CTRL(17:16) : 0 (None) */
545 ProtCfg4.word = 0x03f44084; /* duplicaet legacy 24M. BW set 1. */
546 if (OPSTATUS_TEST_FLAG
547 (pAd, fOP_STATUS_BG_PROTECTION_INUSED)) {
548 ProtCfg.word = 0x01740003; /*ERP use Protection bit is set, use protection rate at Clause 18.. */
549 ProtCfg4.word = 0x03f40003; /* Don't duplicate RTS/CTS in CCK mode. 0x03f40083; */
550 }
551 /*Assign Protection method for 20&40 MHz packets */
552 ProtCfg.field.ProtectCtrl = ASIC_RTS;
553 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
554 ProtCfg4.field.ProtectCtrl = ASIC_RTS;
555 ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
556 Protect[2] = ProtCfg.word;
557 Protect[3] = ProtCfg4.word;
558 Protect[4] = ProtCfg.word;
559 Protect[5] = ProtCfg4.word;
560 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
561 break;
562
563 case 2:
564 /* If only HT STAs are in BSS. at least one is 20MHz. Only protect 40MHz packets */
565 ProtCfg.word = 0x01744004; /* PROT_CTRL(17:16) : 0 (None) */
566 ProtCfg4.word = 0x03f44084; /* duplicaet legacy 24M. BW set 1. */
567
568 /*Assign Protection method for 40MHz packets */
569 ProtCfg4.field.ProtectCtrl = ASIC_RTS;
570 ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
571 Protect[2] = ProtCfg.word;
572 Protect[3] = ProtCfg4.word;
573 if (bNonGFExist) {
574 ProtCfg.field.ProtectCtrl = ASIC_RTS;
575 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
576 }
577 Protect[4] = ProtCfg.word;
578 Protect[5] = ProtCfg4.word;
579
580 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE;
581 break;
582
583 case 3:
584 /* HT mixed mode. PROTECT ALL! */
585 /* Assign Rate */
586 ProtCfg.word = 0x01744004; /*duplicaet legacy 24M. BW set 1. */
587 ProtCfg4.word = 0x03f44084;
588 /* both 20MHz and 40MHz are protected. Whether use RTS or CTS-to-self depends on the */
589 if (OPSTATUS_TEST_FLAG
590 (pAd, fOP_STATUS_BG_PROTECTION_INUSED)) {
591 ProtCfg.word = 0x01740003; /*ERP use Protection bit is set, use protection rate at Clause 18.. */
592 ProtCfg4.word = 0x03f40003; /* Don't duplicate RTS/CTS in CCK mode. 0x03f40083 */
593 }
594 /*Assign Protection method for 20&40 MHz packets */
595 ProtCfg.field.ProtectCtrl = ASIC_RTS;
596 ProtCfg.field.ProtectNav = ASIC_SHORTNAV;
597 ProtCfg4.field.ProtectCtrl = ASIC_RTS;
598 ProtCfg4.field.ProtectNav = ASIC_SHORTNAV;
599 Protect[2] = ProtCfg.word;
600 Protect[3] = ProtCfg4.word;
601 Protect[4] = ProtCfg.word;
602 Protect[5] = ProtCfg4.word;
603 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
604 break;
605
606 case 8:
607 /* Special on for Atheros problem n chip. */
608 Protect[2] = 0x01754004;
609 Protect[3] = 0x03f54084;
610 Protect[4] = 0x01754004;
611 Protect[5] = 0x03f54084;
612 pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE;
613 break;
614 }
615 }
616
617 offset = CCK_PROT_CFG;
618 for (i = 0; i < 6; i++) {
619 if ((SetMask & (1 << i))) {
620 RTMP_IO_WRITE32(pAd, offset + i * 4, Protect[i]);
621 }
622 }
623}
624
625/*
626 ==========================================================================
627 Description:
628
629 IRQL = PASSIVE_LEVEL
630 IRQL = DISPATCH_LEVEL
631
632 ==========================================================================
633 */
634void AsicSwitchChannel(struct rt_rtmp_adapter *pAd, u8 Channel, IN BOOLEAN bScan)
635{
636 unsigned long R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0;
637 char TxPwer = 0, TxPwer2 = DEFAULT_RF_TX_POWER; /*Bbp94 = BBPR94_DEFAULT, TxPwer2 = DEFAULT_RF_TX_POWER; */
638 u8 index;
639 u32 Value = 0; /*BbpReg, Value; */
640 struct rt_rtmp_rf_regs *RFRegTable;
641 u8 RFValue;
642
643 RFValue = 0;
644 /* Search Tx power value */
645 /* We can't use ChannelList to search channel, since some central channl's txpowr doesn't list */
646 /* in ChannelList, so use TxPower array instead. */
647 /* */
648 for (index = 0; index < MAX_NUM_OF_CHANNELS; index++) {
649 if (Channel == pAd->TxPower[index].Channel) {
650 TxPwer = pAd->TxPower[index].Power;
651 TxPwer2 = pAd->TxPower[index].Power2;
652 break;
653 }
654 }
655
656 if (index == MAX_NUM_OF_CHANNELS) {
657 DBGPRINT(RT_DEBUG_ERROR,
658 ("AsicSwitchChannel: Can't find the Channel#%d \n",
659 Channel));
660 }
661#ifdef RT30xx
662 /* The RF programming sequence is difference between 3xxx and 2xxx */
663 if ((IS_RT3070(pAd) || IS_RT3090(pAd) || IS_RT3390(pAd))
664 && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020)
665 || (pAd->RfIcType == RFIC_3021)
666 || (pAd->RfIcType == RFIC_3022))) {
667 /* modify by WY for Read RF Reg. error */
668
669 for (index = 0; index < NUM_OF_3020_CHNL; index++) {
670 if (Channel == FreqItems3020[index].Channel) {
671 /* Programming channel parameters */
672 RT30xxWriteRFRegister(pAd, RF_R02,
673 FreqItems3020[index].N);
674 RT30xxWriteRFRegister(pAd, RF_R03,
675 FreqItems3020[index].K);
676 RT30xxReadRFRegister(pAd, RF_R06, &RFValue);
677 RFValue =
678 (RFValue & 0xFC) | FreqItems3020[index].R;
679 RT30xxWriteRFRegister(pAd, RF_R06, RFValue);
680
681 /* Set Tx0 Power */
682 RT30xxReadRFRegister(pAd, RF_R12, &RFValue);
683 RFValue = (RFValue & 0xE0) | TxPwer;
684 RT30xxWriteRFRegister(pAd, RF_R12, RFValue);
685
686 /* Set Tx1 Power */
687 RT30xxReadRFRegister(pAd, RF_R13, &RFValue);
688 RFValue = (RFValue & 0xE0) | TxPwer2;
689 RT30xxWriteRFRegister(pAd, RF_R13, RFValue);
690
691 /* Tx/Rx Stream setting */
692 RT30xxReadRFRegister(pAd, RF_R01, &RFValue);
693 /*if (IS_RT3090(pAd)) */
694 /* RFValue |= 0x01; // Enable RF block. */
695 RFValue &= 0x03; /*clear bit[7~2] */
696 if (pAd->Antenna.field.TxPath == 1)
697 RFValue |= 0xA0;
698 else if (pAd->Antenna.field.TxPath == 2)
699 RFValue |= 0x80;
700 if (pAd->Antenna.field.RxPath == 1)
701 RFValue |= 0x50;
702 else if (pAd->Antenna.field.RxPath == 2)
703 RFValue |= 0x40;
704 RT30xxWriteRFRegister(pAd, RF_R01, RFValue);
705
706 /* Set RF offset */
707 RT30xxReadRFRegister(pAd, RF_R23, &RFValue);
708 RFValue = (RFValue & 0x80) | pAd->RfFreqOffset;
709 RT30xxWriteRFRegister(pAd, RF_R23, RFValue);
710
711 /* Set BW */
712 if (!bScan
713 && (pAd->CommonCfg.BBPCurrentBW == BW_40)) {
714 RFValue = pAd->Mlme.CaliBW40RfR24;
715 /*DISABLE_11N_CHECK(pAd); */
716 } else {
717 RFValue = pAd->Mlme.CaliBW20RfR24;
718 }
719 RT30xxWriteRFRegister(pAd, RF_R24, RFValue);
720 RT30xxWriteRFRegister(pAd, RF_R31, RFValue);
721
722 /* Enable RF tuning */
723 RT30xxReadRFRegister(pAd, RF_R07, &RFValue);
724 RFValue = RFValue | 0x1;
725 RT30xxWriteRFRegister(pAd, RF_R07, RFValue);
726
727 /* latch channel for future usage. */
728 pAd->LatchRfRegs.Channel = Channel;
729
730 DBGPRINT(RT_DEBUG_TRACE,
731 ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n",
732 Channel, pAd->RfIcType, TxPwer,
733 TxPwer2, pAd->Antenna.field.TxPath,
734 FreqItems3020[index].N,
735 FreqItems3020[index].K,
736 FreqItems3020[index].R));
737
738 break;
739 }
740 }
741 } else
742#endif /* RT30xx // */
743 {
744 RFRegTable = RF2850RegTable;
745 switch (pAd->RfIcType) {
746 case RFIC_2820:
747 case RFIC_2850:
748 case RFIC_2720:
749 case RFIC_2750:
750
751 for (index = 0; index < NUM_OF_2850_CHNL; index++) {
752 if (Channel == RFRegTable[index].Channel) {
753 R2 = RFRegTable[index].R2;
754 if (pAd->Antenna.field.TxPath == 1) {
755 R2 |= 0x4000; /* If TXpath is 1, bit 14 = 1; */
756 }
757
758 if (pAd->Antenna.field.RxPath == 2) {
759 R2 |= 0x40; /* write 1 to off Rxpath. */
760 } else if (pAd->Antenna.field.RxPath ==
761 1) {
762 R2 |= 0x20040; /* write 1 to off RxPath */
763 }
764
765 if (Channel > 14) {
766 /* initialize R3, R4 */
767 R3 = (RFRegTable[index].
768 R3 & 0xffffc1ff);
769 R4 = (RFRegTable[index].
770 R4 & (~0x001f87c0)) |
771 (pAd->RfFreqOffset << 15);
772
773 /* 5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB */
774 /* R3 */
775 if ((TxPwer >= -7)
776 && (TxPwer < 0)) {
777 TxPwer = (7 + TxPwer);
778 TxPwer =
779 (TxPwer >
780 0xF) ? (0xF)
781 : (TxPwer);
782 R3 |= (TxPwer << 10);
783 DBGPRINT(RT_DEBUG_ERROR,
784 ("AsicSwitchChannel: TxPwer=%d \n",
785 TxPwer));
786 } else {
787 TxPwer =
788 (TxPwer >
789 0xF) ? (0xF)
790 : (TxPwer);
791 R3 |=
792 (TxPwer << 10) | (1
793 <<
794 9);
795 }
796
797 /* R4 */
798 if ((TxPwer2 >= -7)
799 && (TxPwer2 < 0)) {
800 TxPwer2 = (7 + TxPwer2);
801 TxPwer2 =
802 (TxPwer2 >
803 0xF) ? (0xF)
804 : (TxPwer2);
805 R4 |= (TxPwer2 << 7);
806 DBGPRINT(RT_DEBUG_ERROR,
807 ("AsicSwitchChannel: TxPwer2=%d \n",
808 TxPwer2));
809 } else {
810 TxPwer2 =
811 (TxPwer2 >
812 0xF) ? (0xF)
813 : (TxPwer2);
814 R4 |=
815 (TxPwer2 << 7) | (1
816 <<
817 6);
818 }
819 } else {
820 R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); /* set TX power0 */
821 R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15) | (TxPwer2 << 6); /* Set freq Offset & TxPwr1 */
822 }
823
824 /* Based on BBP current mode before changing RF channel. */
825 if (!bScan
826 && (pAd->CommonCfg.BBPCurrentBW ==
827 BW_40)) {
828 R4 |= 0x200000;
829 }
830 /* Update variables */
831 pAd->LatchRfRegs.Channel = Channel;
832 pAd->LatchRfRegs.R1 =
833 RFRegTable[index].R1;
834 pAd->LatchRfRegs.R2 = R2;
835 pAd->LatchRfRegs.R3 = R3;
836 pAd->LatchRfRegs.R4 = R4;
837
838 /* Set RF value 1's set R3[bit2] = [0] */
839 RTMP_RF_IO_WRITE32(pAd,
840 pAd->LatchRfRegs.R1);
841 RTMP_RF_IO_WRITE32(pAd,
842 pAd->LatchRfRegs.R2);
843 RTMP_RF_IO_WRITE32(pAd,
844 (pAd->LatchRfRegs.
845 R3 & (~0x04)));
846 RTMP_RF_IO_WRITE32(pAd,
847 pAd->LatchRfRegs.R4);
848
849 RTMPusecDelay(200);
850
851 /* Set RF value 2's set R3[bit2] = [1] */
852 RTMP_RF_IO_WRITE32(pAd,
853 pAd->LatchRfRegs.R1);
854 RTMP_RF_IO_WRITE32(pAd,
855 pAd->LatchRfRegs.R2);
856 RTMP_RF_IO_WRITE32(pAd,
857 (pAd->LatchRfRegs.
858 R3 | 0x04));
859 RTMP_RF_IO_WRITE32(pAd,
860 pAd->LatchRfRegs.R4);
861
862 RTMPusecDelay(200);
863
864 /* Set RF value 3's set R3[bit2] = [0] */
865 RTMP_RF_IO_WRITE32(pAd,
866 pAd->LatchRfRegs.R1);
867 RTMP_RF_IO_WRITE32(pAd,
868 pAd->LatchRfRegs.R2);
869 RTMP_RF_IO_WRITE32(pAd,
870 (pAd->LatchRfRegs.
871 R3 & (~0x04)));
872 RTMP_RF_IO_WRITE32(pAd,
873 pAd->LatchRfRegs.R4);
874
875 break;
876 }
877 }
878 break;
879
880 default:
881 break;
882 }
883
884 DBGPRINT(RT_DEBUG_TRACE,
885 ("SwitchChannel#%d(RF=%d, Pwr0=%lu, Pwr1=%lu, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n",
886 Channel, pAd->RfIcType, (R3 & 0x00003e00) >> 9,
887 (R4 & 0x000007c0) >> 6, pAd->Antenna.field.TxPath,
888 pAd->LatchRfRegs.R1, pAd->LatchRfRegs.R2,
889 pAd->LatchRfRegs.R3, pAd->LatchRfRegs.R4));
890 }
891
892 /* Change BBP setting during siwtch from a->g, g->a */
893 if (Channel <= 14) {
894 unsigned long TxPinCfg = 0x00050F0A; /*Gary 2007/08/09 0x050A0A */
895
896 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62,
897 (0x37 - GET_LNA_GAIN(pAd)));
898 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63,
899 (0x37 - GET_LNA_GAIN(pAd)));
900 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64,
901 (0x37 - GET_LNA_GAIN(pAd)));
902 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0); /*(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue. */
903 /*RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62); */
904
905 /* Rx High power VGA offset for LNA select */
906 if (pAd->NicConfig2.field.ExternalLNAForG) {
907 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62);
908 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46);
909 } else {
910 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84);
911 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50);
912 }
913
914 /* 5G band selection PIN, bit1 and bit2 are complement */
915 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
916 Value &= (~0x6);
917 Value |= (0x04);
918 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
919
920 /* Turn off unused PA or LNA when only 1T or 1R */
921 if (pAd->Antenna.field.TxPath == 1) {
922 TxPinCfg &= 0xFFFFFFF3;
923 }
924 if (pAd->Antenna.field.RxPath == 1) {
925 TxPinCfg &= 0xFFFFF3FF;
926 }
927
928 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
929
930#if defined(RT3090) || defined(RT3390)
931 /* PCIe PHY Transmit attenuation adjustment */
932 if (IS_RT3090A(pAd) || IS_RT3390(pAd)) {
933 TX_ATTENUATION_CTRL_STRUC TxAttenuationCtrl = {
934 .word = 0};
935
936 RTMP_IO_READ32(pAd, PCIE_PHY_TX_ATTENUATION_CTRL,
937 &TxAttenuationCtrl.word);
938
939 if (Channel == 14) /* Channel #14 */
940 {
941 TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_EN = 1; /* Enable PCIe PHY Tx attenuation */
942 TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_VALUE = 4; /* 9/16 full drive level */
943 } else /* Channel #1~#13 */
944 {
945 TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_EN = 0; /* Disable PCIe PHY Tx attenuation */
946 TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_VALUE = 0; /* n/a */
947 }
948
949 RTMP_IO_WRITE32(pAd, PCIE_PHY_TX_ATTENUATION_CTRL,
950 TxAttenuationCtrl.word);
951 }
952#endif
953 } else {
954 unsigned long TxPinCfg = 0x00050F05; /*Gary 2007/8/9 0x050505 */
955
956 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62,
957 (0x37 - GET_LNA_GAIN(pAd)));
958 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63,
959 (0x37 - GET_LNA_GAIN(pAd)));
960 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64,
961 (0x37 - GET_LNA_GAIN(pAd)));
962 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0); /*(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue. */
963 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2);
964
965 /* Rx High power VGA offset for LNA select */
966 if (pAd->NicConfig2.field.ExternalLNAForA) {
967 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46);
968 } else {
969 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50);
970 }
971
972 /* 5G band selection PIN, bit1 and bit2 are complement */
973 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
974 Value &= (~0x6);
975 Value |= (0x02);
976 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
977
978 /* Turn off unused PA or LNA when only 1T or 1R */
979 if (pAd->Antenna.field.TxPath == 1) {
980 TxPinCfg &= 0xFFFFFFF3;
981 }
982 if (pAd->Antenna.field.RxPath == 1) {
983 TxPinCfg &= 0xFFFFF3FF;
984 }
985
986 RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg);
987
988 }
989
990 /* R66 should be set according to Channel and use 20MHz when scanning */
991 /*RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x2E + GET_LNA_GAIN(pAd))); */
992 if (bScan)
993 RTMPSetAGCInitValue(pAd, BW_20);
994 else
995 RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
996
997 /* */
998 /* On 11A, We should delay and wait RF/BBP to be stable */
999 /* and the appropriate time should be 1000 micro seconds */
1000 /* 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL. */
1001 /* */
1002 RTMPusecDelay(1000);
1003}
1004
1005void AsicResetBBPAgent(struct rt_rtmp_adapter *pAd)
1006{
1007 BBP_CSR_CFG_STRUC BbpCsr;
1008 DBGPRINT(RT_DEBUG_ERROR, ("Reset BBP Agent busy bit!\n"));
1009 /* Still need to find why BBP agent keeps busy, but in fact, hardware still function ok. Now clear busy first. */
1010 RTMP_IO_READ32(pAd, H2M_BBP_AGENT, &BbpCsr.word);
1011 BbpCsr.field.Busy = 0;
1012 RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, BbpCsr.word);
1013}
1014
1015/*
1016 ==========================================================================
1017 Description:
1018 This function is required for 2421 only, and should not be used during
1019 site survey. It's only required after NIC decided to stay at a channel
1020 for a longer period.
1021 When this function is called, it's always after AsicSwitchChannel().
1022
1023 IRQL = PASSIVE_LEVEL
1024 IRQL = DISPATCH_LEVEL
1025
1026 ==========================================================================
1027 */
1028void AsicLockChannel(struct rt_rtmp_adapter *pAd, u8 Channel)
1029{
1030}
1031
1032void AsicRfTuningExec(void *SystemSpecific1,
1033 void *FunctionContext,
1034 void *SystemSpecific2, void *SystemSpecific3)
1035{
1036}
1037
1038/*
1039 ==========================================================================
1040 Description:
1041 Gives CCK TX rate 2 more dB TX power.
1042 This routine works only in LINK UP in INFRASTRUCTURE mode.
1043
1044 calculate desired Tx power in RF R3.Tx0~5, should consider -
1045 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment)
1046 1. TxPowerPercentage
1047 2. auto calibration based on TSSI feedback
1048 3. extra 2 db for CCK
1049 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP
1050
1051 NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment),
1052 it should be called AFTER MlmeDynamicTxRatSwitching()
1053 ==========================================================================
1054 */
1055void AsicAdjustTxPower(struct rt_rtmp_adapter *pAd)
1056{
1057 int i, j;
1058 char DeltaPwr = 0;
1059 BOOLEAN bAutoTxAgc = FALSE;
1060 u8 TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep;
1061 u8 BbpR1 = 0, BbpR49 = 0, idx;
1062 char *pTxAgcCompensate;
1063 unsigned long TxPwr[5];
1064 char Value;
1065 char Rssi = -127;
1066
1067 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) ||
1068#ifdef RTMP_MAC_PCI
1069 (pAd->bPCIclkOff == TRUE) ||
1070#endif /* RTMP_MAC_PCI // */
1071 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF) ||
1072 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1073 return;
1074
1075 Rssi = RTMPMaxRssi(pAd,
1076 pAd->StaCfg.RssiSample.AvgRssi0,
1077 pAd->StaCfg.RssiSample.AvgRssi1,
1078 pAd->StaCfg.RssiSample.AvgRssi2);
1079
1080 if (pAd->CommonCfg.BBPCurrentBW == BW_40) {
1081 if (pAd->CommonCfg.CentralChannel > 14) {
1082 TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
1083 TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
1084 TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
1085 TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
1086 TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
1087 } else {
1088 TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
1089 TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
1090 TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
1091 TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
1092 TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
1093 }
1094 } else {
1095 if (pAd->CommonCfg.Channel > 14) {
1096 TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
1097 TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
1098 TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
1099 TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
1100 TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
1101 } else {
1102 TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
1103 TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
1104 TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
1105 TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
1106 TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
1107 }
1108 }
1109
1110 /* TX power compensation for temperature variation based on TSSI. try every 4 second */
1111 if (pAd->Mlme.OneSecPeriodicRound % 4 == 0) {
1112 if (pAd->CommonCfg.Channel <= 14) {
1113 /* bg channel */
1114 bAutoTxAgc = pAd->bAutoTxAgcG;
1115 TssiRef = pAd->TssiRefG;
1116 pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0];
1117 pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0];
1118 TxAgcStep = pAd->TxAgcStepG;
1119 pTxAgcCompensate = &pAd->TxAgcCompensateG;
1120 } else {
1121 /* a channel */
1122 bAutoTxAgc = pAd->bAutoTxAgcA;
1123 TssiRef = pAd->TssiRefA;
1124 pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0];
1125 pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0];
1126 TxAgcStep = pAd->TxAgcStepA;
1127 pTxAgcCompensate = &pAd->TxAgcCompensateA;
1128 }
1129
1130 if (bAutoTxAgc) {
1131 /* BbpR1 is unsigned char */
1132 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49);
1133
1134 /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */
1135 /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */
1136 /* step value is defined in pAd->TxAgcStepG for tx power value */
1137
1138 /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */
1139 /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
1140 above value are examined in mass factory production */
1141 /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */
1142
1143 /* plus (+) is 0x00 ~ 0x45, minus (-) is 0xa0 ~ 0xf0 */
1144 /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */
1145 /* if value is 0xa5, tx power will be -= TxAgcStep*(2-1) */
1146
1147 if (BbpR49 > pTssiMinusBoundary[1]) {
1148 /* Reading is larger than the reference value */
1149 /* check for how large we need to decrease the Tx power */
1150 for (idx = 1; idx < 5; idx++) {
1151 if (BbpR49 <= pTssiMinusBoundary[idx]) /* Found the range */
1152 break;
1153 }
1154 /* The index is the step we should decrease, idx = 0 means there is nothing to compensate */
1155/* if (R3 > (unsigned long)(TxAgcStep * (idx-1))) */
1156 *pTxAgcCompensate = -(TxAgcStep * (idx - 1));
1157/* else */
1158/* *pTxAgcCompensate = -((u8)R3); */
1159
1160 DeltaPwr += (*pTxAgcCompensate);
1161 DBGPRINT(RT_DEBUG_TRACE,
1162 ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n",
1163 BbpR49, TssiRef, TxAgcStep, idx - 1));
1164 } else if (BbpR49 < pTssiPlusBoundary[1]) {
1165 /* Reading is smaller than the reference value */
1166 /* check for how large we need to increase the Tx power */
1167 for (idx = 1; idx < 5; idx++) {
1168 if (BbpR49 >= pTssiPlusBoundary[idx]) /* Found the range */
1169 break;
1170 }
1171 /* The index is the step we should increase, idx = 0 means there is nothing to compensate */
1172 *pTxAgcCompensate = TxAgcStep * (idx - 1);
1173 DeltaPwr += (*pTxAgcCompensate);
1174 DBGPRINT(RT_DEBUG_TRACE,
1175 ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
1176 BbpR49, TssiRef, TxAgcStep, idx - 1));
1177 } else {
1178 *pTxAgcCompensate = 0;
1179 DBGPRINT(RT_DEBUG_TRACE,
1180 (" Tx Power, BBP R49=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n",
1181 BbpR49, TssiRef, TxAgcStep, 0));
1182 }
1183 }
1184 } else {
1185 if (pAd->CommonCfg.Channel <= 14) {
1186 bAutoTxAgc = pAd->bAutoTxAgcG;
1187 pTxAgcCompensate = &pAd->TxAgcCompensateG;
1188 } else {
1189 bAutoTxAgc = pAd->bAutoTxAgcA;
1190 pTxAgcCompensate = &pAd->TxAgcCompensateA;
1191 }
1192
1193 if (bAutoTxAgc)
1194 DeltaPwr += (*pTxAgcCompensate);
1195 }
1196
1197 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpR1);
1198 BbpR1 &= 0xFC;
1199
1200 /* calculate delta power based on the percentage specified from UI */
1201 /* E2PROM setting is calibrated for maximum TX power (i.e. 100%) */
1202 /* We lower TX power here according to the percentage specified from UI */
1203 if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) /* AUTO TX POWER control */
1204 {
1205 {
1206 /* to patch high power issue with some APs, like Belkin N1. */
1207 if (Rssi > -35) {
1208 BbpR1 |= 0x02; /* DeltaPwr -= 12; */
1209 } else if (Rssi > -40) {
1210 BbpR1 |= 0x01; /* DeltaPwr -= 6; */
1211 } else;
1212 }
1213 } else if (pAd->CommonCfg.TxPowerPercentage > 90) /* 91 ~ 100% & AUTO, treat as 100% in terms of mW */
1214 ;
1215 else if (pAd->CommonCfg.TxPowerPercentage > 60) /* 61 ~ 90%, treat as 75% in terms of mW // DeltaPwr -= 1; */
1216 {
1217 DeltaPwr -= 1;
1218 } else if (pAd->CommonCfg.TxPowerPercentage > 30) /* 31 ~ 60%, treat as 50% in terms of mW // DeltaPwr -= 3; */
1219 {
1220 DeltaPwr -= 3;
1221 } else if (pAd->CommonCfg.TxPowerPercentage > 15) /* 16 ~ 30%, treat as 25% in terms of mW // DeltaPwr -= 6; */
1222 {
1223 BbpR1 |= 0x01;
1224 } else if (pAd->CommonCfg.TxPowerPercentage > 9) /* 10 ~ 15%, treat as 12.5% in terms of mW // DeltaPwr -= 9; */
1225 {
1226 BbpR1 |= 0x01;
1227 DeltaPwr -= 3;
1228 } else /* 0 ~ 9 %, treat as MIN(~3%) in terms of mW // DeltaPwr -= 12; */
1229 {
1230 BbpR1 |= 0x02;
1231 }
1232
1233 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpR1);
1234
1235 /* reset different new tx power for different TX rate */
1236 for (i = 0; i < 5; i++) {
1237 if (TxPwr[i] != 0xffffffff) {
1238 for (j = 0; j < 8; j++) {
1239 Value = (char)((TxPwr[i] >> j * 4) & 0x0F); /* 0 ~ 15 */
1240
1241 if ((Value + DeltaPwr) < 0) {
1242 Value = 0; /* min */
1243 } else if ((Value + DeltaPwr) > 0xF) {
1244 Value = 0xF; /* max */
1245 } else {
1246 Value += DeltaPwr; /* temperature compensation */
1247 }
1248
1249 /* fill new value to CSR offset */
1250 TxPwr[i] =
1251 (TxPwr[i] & ~(0x0000000F << j * 4)) | (Value
1252 << j
1253 * 4);
1254 }
1255
1256 /* write tx power value to CSR */
1257 /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M
1258 TX power for OFDM 6M/9M
1259 TX power for CCK5.5M/11M
1260 TX power for CCK1M/2M */
1261 /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */
1262 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i * 4, TxPwr[i]);
1263 }
1264 }
1265
1266}
1267
1268/*
1269 ==========================================================================
1270 Description:
1271 put PHY to sleep here, and set next wakeup timer. PHY doesn't not wakeup
1272 automatically. Instead, MCU will issue a TwakeUpInterrupt to host after
1273 the wakeup timer timeout. Driver has to issue a separate command to wake
1274 PHY up.
1275
1276 IRQL = DISPATCH_LEVEL
1277
1278 ==========================================================================
1279 */
1280void AsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
1281 u16 TbttNumToNextWakeUp)
1282{
1283 RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp);
1284}
1285
1286/*
1287 ==========================================================================
1288 Description:
1289 AsicForceWakeup() is used whenever manual wakeup is required
1290 AsicForceSleep() should only be used when not in INFRA BSS. When
1291 in INFRA BSS, we should use AsicSleepThenAutoWakeup() instead.
1292 ==========================================================================
1293 */
1294void AsicForceSleep(struct rt_rtmp_adapter *pAd)
1295{
1296
1297}
1298
1299/*
1300 ==========================================================================
1301 Description:
1302 AsicForceWakeup() is used whenever Twakeup timer (set via AsicSleepThenAutoWakeup)
1303 expired.
1304
1305 IRQL = PASSIVE_LEVEL
1306 IRQL = DISPATCH_LEVEL
1307 ==========================================================================
1308 */
1309void AsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx)
1310{
1311 DBGPRINT(RT_DEBUG_INFO, ("--> AsicForceWakeup \n"));
1312 RTMP_STA_FORCE_WAKEUP(pAd, bFromTx);
1313}
1314
1315/*
1316 ==========================================================================
1317 Description:
1318 Set My BSSID
1319
1320 IRQL = DISPATCH_LEVEL
1321
1322 ==========================================================================
1323 */
1324void AsicSetBssid(struct rt_rtmp_adapter *pAd, u8 *pBssid)
1325{
1326 unsigned long Addr4;
1327 DBGPRINT(RT_DEBUG_TRACE,
1328 ("==============> AsicSetBssid %x:%x:%x:%x:%x:%x\n", pBssid[0],
1329 pBssid[1], pBssid[2], pBssid[3], pBssid[4], pBssid[5]));
1330
1331 Addr4 = (unsigned long)(pBssid[0]) |
1332 (unsigned long)(pBssid[1] << 8) |
1333 (unsigned long)(pBssid[2] << 16) | (unsigned long)(pBssid[3] << 24);
1334 RTMP_IO_WRITE32(pAd, MAC_BSSID_DW0, Addr4);
1335
1336 Addr4 = 0;
1337 /* always one BSSID in STA mode */
1338 Addr4 = (unsigned long)(pBssid[4]) | (unsigned long)(pBssid[5] << 8);
1339
1340 RTMP_IO_WRITE32(pAd, MAC_BSSID_DW1, Addr4);
1341}
1342
1343void AsicSetMcastWC(struct rt_rtmp_adapter *pAd)
1344{
1345 struct rt_mac_table_entry *pEntry = &pAd->MacTab.Content[MCAST_WCID];
1346 u16 offset;
1347
1348 pEntry->Sst = SST_ASSOC;
1349 pEntry->Aid = MCAST_WCID; /* Softap supports 1 BSSID and use WCID=0 as multicast Wcid index */
1350 pEntry->PsMode = PWR_ACTIVE;
1351 pEntry->CurrTxRate = pAd->CommonCfg.MlmeRate;
1352 offset = MAC_WCID_BASE + BSS0Mcast_WCID * HW_WCID_ENTRY_SIZE;
1353}
1354
1355/*
1356 ==========================================================================
1357 Description:
1358
1359 IRQL = DISPATCH_LEVEL
1360
1361 ==========================================================================
1362 */
1363void AsicDelWcidTab(struct rt_rtmp_adapter *pAd, u8 Wcid)
1364{
1365 unsigned long Addr0 = 0x0, Addr1 = 0x0;
1366 unsigned long offset;
1367
1368 DBGPRINT(RT_DEBUG_TRACE, ("AsicDelWcidTab==>Wcid = 0x%x\n", Wcid));
1369 offset = MAC_WCID_BASE + Wcid * HW_WCID_ENTRY_SIZE;
1370 RTMP_IO_WRITE32(pAd, offset, Addr0);
1371 offset += 4;
1372 RTMP_IO_WRITE32(pAd, offset, Addr1);
1373}
1374
1375/*
1376 ==========================================================================
1377 Description:
1378
1379 IRQL = DISPATCH_LEVEL
1380
1381 ==========================================================================
1382 */
1383void AsicEnableRDG(struct rt_rtmp_adapter *pAd)
1384{
1385 TX_LINK_CFG_STRUC TxLinkCfg;
1386 u32 Data = 0;
1387
1388 RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
1389 TxLinkCfg.field.TxRDGEn = 1;
1390 RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
1391
1392 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1393 Data &= 0xFFFFFF00;
1394 Data |= 0x80;
1395 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1396
1397 /*OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED); */
1398}
1399
1400/*
1401 ==========================================================================
1402 Description:
1403
1404 IRQL = DISPATCH_LEVEL
1405
1406 ==========================================================================
1407 */
1408void AsicDisableRDG(struct rt_rtmp_adapter *pAd)
1409{
1410 TX_LINK_CFG_STRUC TxLinkCfg;
1411 u32 Data = 0;
1412
1413 RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
1414 TxLinkCfg.field.TxRDGEn = 0;
1415 RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
1416
1417 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1418
1419 Data &= 0xFFFFFF00;
1420 /*Data |= 0x20; */
1421#ifndef WIFI_TEST
1422 /*if ( pAd->CommonCfg.bEnableTxBurst ) */
1423 /* Data |= 0x60; // for performance issue not set the TXOP to 0 */
1424#endif
1425 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE)
1426 && (pAd->MacTab.fAnyStationMIMOPSDynamic == FALSE)
1427 ) {
1428 /* For CWC test, change txop from 0x30 to 0x20 in TxBurst mode */
1429 if (pAd->CommonCfg.bEnableTxBurst)
1430 Data |= 0x20;
1431 }
1432 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1433}
1434
1435/*
1436 ==========================================================================
1437 Description:
1438
1439 IRQL = PASSIVE_LEVEL
1440 IRQL = DISPATCH_LEVEL
1441
1442 ==========================================================================
1443 */
1444void AsicDisableSync(struct rt_rtmp_adapter *pAd)
1445{
1446 BCN_TIME_CFG_STRUC csr;
1447
1448 DBGPRINT(RT_DEBUG_TRACE, ("--->Disable TSF synchronization\n"));
1449
1450 /* 2003-12-20 disable TSF and TBTT while NIC in power-saving have side effect */
1451 /* that NIC will never wakes up because TSF stops and no more */
1452 /* TBTT interrupts */
1453 pAd->TbttTickCount = 0;
1454 RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
1455 csr.field.bBeaconGen = 0;
1456 csr.field.bTBTTEnable = 0;
1457 csr.field.TsfSyncMode = 0;
1458 csr.field.bTsfTicking = 0;
1459 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
1460
1461}
1462
1463/*
1464 ==========================================================================
1465 Description:
1466
1467 IRQL = DISPATCH_LEVEL
1468
1469 ==========================================================================
1470 */
1471void AsicEnableBssSync(struct rt_rtmp_adapter *pAd)
1472{
1473 BCN_TIME_CFG_STRUC csr;
1474
1475 DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableBssSync(INFRA mode)\n"));
1476
1477 RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
1478/* RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, 0x00000000); */
1479 {
1480 csr.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; /* ASIC register in units of 1/16 TU */
1481 csr.field.bTsfTicking = 1;
1482 csr.field.TsfSyncMode = 1; /* sync TSF in INFRASTRUCTURE mode */
1483 csr.field.bBeaconGen = 0; /* do NOT generate BEACON */
1484 csr.field.bTBTTEnable = 1;
1485 }
1486 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
1487}
1488
1489/*
1490 ==========================================================================
1491 Description:
1492 Note:
1493 BEACON frame in shared memory should be built ok before this routine
1494 can be called. Otherwise, a garbage frame maybe transmitted out every
1495 Beacon period.
1496
1497 IRQL = DISPATCH_LEVEL
1498
1499 ==========================================================================
1500 */
1501void AsicEnableIbssSync(struct rt_rtmp_adapter *pAd)
1502{
1503 BCN_TIME_CFG_STRUC csr9;
1504 u8 *ptr;
1505 u32 i;
1506
1507 DBGPRINT(RT_DEBUG_TRACE,
1508 ("--->AsicEnableIbssSync(ADHOC mode. MPDUtotalByteCount = %d)\n",
1509 pAd->BeaconTxWI.MPDUtotalByteCount));
1510
1511 RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr9.word);
1512 csr9.field.bBeaconGen = 0;
1513 csr9.field.bTBTTEnable = 0;
1514 csr9.field.bTsfTicking = 0;
1515 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word);
1516
1517#ifdef RTMP_MAC_PCI
1518 /* move BEACON TXD and frame content to on-chip memory */
1519 ptr = (u8 *)& pAd->BeaconTxWI;
1520 for (i = 0; i < TXWI_SIZE; i += 4) /* 16-byte TXWI field */
1521 {
1522 u32 longptr =
1523 *ptr + (*(ptr + 1) << 8) + (*(ptr + 2) << 16) +
1524 (*(ptr + 3) << 24);
1525 RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + i, longptr);
1526 ptr += 4;
1527 }
1528
1529 /* start right after the 16-byte TXWI field */
1530 ptr = pAd->BeaconBuf;
1531 for (i = 0; i < pAd->BeaconTxWI.MPDUtotalByteCount; i += 4) {
1532 u32 longptr =
1533 *ptr + (*(ptr + 1) << 8) + (*(ptr + 2) << 16) +
1534 (*(ptr + 3) << 24);
1535 RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr);
1536 ptr += 4;
1537 }
1538#endif /* RTMP_MAC_PCI // */
1539#ifdef RTMP_MAC_USB
1540 /* move BEACON TXD and frame content to on-chip memory */
1541 ptr = (u8 *)& pAd->BeaconTxWI;
1542 for (i = 0; i < TXWI_SIZE; i += 2) /* 16-byte TXWI field */
1543 {
1544 /*u32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24); */
1545 /*RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + i, longptr); */
1546 RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + i, ptr, 2);
1547 ptr += 2;
1548 }
1549
1550 /* start right after the 16-byte TXWI field */
1551 ptr = pAd->BeaconBuf;
1552 for (i = 0; i < pAd->BeaconTxWI.MPDUtotalByteCount; i += 2) {
1553 /*u32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24); */
1554 /*RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr); */
1555 RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, ptr, 2);
1556 ptr += 2;
1557 }
1558#endif /* RTMP_MAC_USB // */
1559
1560 /* */
1561 /* For Wi-Fi faily generated beacons between participating stations. */
1562 /* Set TBTT phase adaptive adjustment step to 8us (default 16us) */
1563 /* don't change settings 2006-5- by Jerry */
1564 /*RTMP_IO_WRITE32(pAd, TBTT_SYNC_CFG, 0x00001010); */
1565
1566 /* start sending BEACON */
1567 csr9.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; /* ASIC register in units of 1/16 TU */
1568 csr9.field.bTsfTicking = 1;
1569 csr9.field.TsfSyncMode = 2; /* sync TSF in IBSS mode */
1570 csr9.field.bTBTTEnable = 1;
1571 csr9.field.bBeaconGen = 1;
1572 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word);
1573}
1574
1575/*
1576 ==========================================================================
1577 Description:
1578
1579 IRQL = PASSIVE_LEVEL
1580 IRQL = DISPATCH_LEVEL
1581
1582 ==========================================================================
1583 */
1584void AsicSetEdcaParm(struct rt_rtmp_adapter *pAd, struct rt_edca_parm *pEdcaParm)
1585{
1586 EDCA_AC_CFG_STRUC Ac0Cfg, Ac1Cfg, Ac2Cfg, Ac3Cfg;
1587 AC_TXOP_CSR0_STRUC csr0;
1588 AC_TXOP_CSR1_STRUC csr1;
1589 AIFSN_CSR_STRUC AifsnCsr;
1590 CWMIN_CSR_STRUC CwminCsr;
1591 CWMAX_CSR_STRUC CwmaxCsr;
1592 int i;
1593
1594 Ac0Cfg.word = 0;
1595 Ac1Cfg.word = 0;
1596 Ac2Cfg.word = 0;
1597 Ac3Cfg.word = 0;
1598 if ((pEdcaParm == NULL) || (pEdcaParm->bValid == FALSE)) {
1599 DBGPRINT(RT_DEBUG_TRACE, ("AsicSetEdcaParm\n"));
1600 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WMM_INUSED);
1601 for (i = 0; i < MAX_LEN_OF_MAC_TABLE; i++) {
1602 if (pAd->MacTab.Content[i].ValidAsCLI
1603 || pAd->MacTab.Content[i].ValidAsApCli)
1604 CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.
1605 Content[i],
1606 fCLIENT_STATUS_WMM_CAPABLE);
1607 }
1608
1609 /*======================================================== */
1610 /* MAC Register has a copy . */
1611 /*======================================================== */
1612/*#ifndef WIFI_TEST */
1613 if (pAd->CommonCfg.bEnableTxBurst) {
1614 /* For CWC test, change txop from 0x30 to 0x20 in TxBurst mode */
1615 Ac0Cfg.field.AcTxop = 0x20; /* Suggest by John for TxBurst in HT Mode */
1616 } else
1617 Ac0Cfg.field.AcTxop = 0; /* QID_AC_BE */
1618/*#else */
1619/* Ac0Cfg.field.AcTxop = 0; // QID_AC_BE */
1620/*#endif */
1621 Ac0Cfg.field.Cwmin = CW_MIN_IN_BITS;
1622 Ac0Cfg.field.Cwmax = CW_MAX_IN_BITS;
1623 Ac0Cfg.field.Aifsn = 2;
1624 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word);
1625
1626 Ac1Cfg.field.AcTxop = 0; /* QID_AC_BK */
1627 Ac1Cfg.field.Cwmin = CW_MIN_IN_BITS;
1628 Ac1Cfg.field.Cwmax = CW_MAX_IN_BITS;
1629 Ac1Cfg.field.Aifsn = 2;
1630 RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word);
1631
1632 if (pAd->CommonCfg.PhyMode == PHY_11B) {
1633 Ac2Cfg.field.AcTxop = 192; /* AC_VI: 192*32us ~= 6ms */
1634 Ac3Cfg.field.AcTxop = 96; /* AC_VO: 96*32us ~= 3ms */
1635 } else {
1636 Ac2Cfg.field.AcTxop = 96; /* AC_VI: 96*32us ~= 3ms */
1637 Ac3Cfg.field.AcTxop = 48; /* AC_VO: 48*32us ~= 1.5ms */
1638 }
1639 Ac2Cfg.field.Cwmin = CW_MIN_IN_BITS;
1640 Ac2Cfg.field.Cwmax = CW_MAX_IN_BITS;
1641 Ac2Cfg.field.Aifsn = 2;
1642 RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word);
1643 Ac3Cfg.field.Cwmin = CW_MIN_IN_BITS;
1644 Ac3Cfg.field.Cwmax = CW_MAX_IN_BITS;
1645 Ac3Cfg.field.Aifsn = 2;
1646 RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word);
1647
1648 /*======================================================== */
1649 /* DMA Register has a copy too. */
1650 /*======================================================== */
1651 csr0.field.Ac0Txop = 0; /* QID_AC_BE */
1652 csr0.field.Ac1Txop = 0; /* QID_AC_BK */
1653 RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
1654 if (pAd->CommonCfg.PhyMode == PHY_11B) {
1655 csr1.field.Ac2Txop = 192; /* AC_VI: 192*32us ~= 6ms */
1656 csr1.field.Ac3Txop = 96; /* AC_VO: 96*32us ~= 3ms */
1657 } else {
1658 csr1.field.Ac2Txop = 96; /* AC_VI: 96*32us ~= 3ms */
1659 csr1.field.Ac3Txop = 48; /* AC_VO: 48*32us ~= 1.5ms */
1660 }
1661 RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word);
1662
1663 CwminCsr.word = 0;
1664 CwminCsr.field.Cwmin0 = CW_MIN_IN_BITS;
1665 CwminCsr.field.Cwmin1 = CW_MIN_IN_BITS;
1666 CwminCsr.field.Cwmin2 = CW_MIN_IN_BITS;
1667 CwminCsr.field.Cwmin3 = CW_MIN_IN_BITS;
1668 RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word);
1669
1670 CwmaxCsr.word = 0;
1671 CwmaxCsr.field.Cwmax0 = CW_MAX_IN_BITS;
1672 CwmaxCsr.field.Cwmax1 = CW_MAX_IN_BITS;
1673 CwmaxCsr.field.Cwmax2 = CW_MAX_IN_BITS;
1674 CwmaxCsr.field.Cwmax3 = CW_MAX_IN_BITS;
1675 RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word);
1676
1677 RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, 0x00002222);
1678
1679 NdisZeroMemory(&pAd->CommonCfg.APEdcaParm, sizeof(struct rt_edca_parm));
1680 } else {
1681 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_WMM_INUSED);
1682 /*======================================================== */
1683 /* MAC Register has a copy. */
1684 /*======================================================== */
1685 /* */
1686 /* Modify Cwmin/Cwmax/Txop on queue[QID_AC_VI], Recommend by Jerry 2005/07/27 */
1687 /* To degrade our VIDO Queue's throughput for WiFi WMM S3T07 Issue. */
1688 /* */
1689 /*pEdcaParm->Txop[QID_AC_VI] = pEdcaParm->Txop[QID_AC_VI] * 7 / 10; // rt2860c need this */
1690
1691 Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE];
1692 Ac0Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BE];
1693 Ac0Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BE];
1694 Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]; /*+1; */
1695
1696 Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK];
1697 Ac1Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BK]; /*+2; */
1698 Ac1Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BK];
1699 Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK]; /*+1; */
1700
1701 Ac2Cfg.field.AcTxop = (pEdcaParm->Txop[QID_AC_VI] * 6) / 10;
1702 if (pAd->Antenna.field.TxPath == 1) {
1703 Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI] + 1;
1704 Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI] + 1;
1705 } else {
1706 Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI];
1707 Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI];
1708 }
1709 Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI] + 1;
1710#ifdef RTMP_MAC_USB
1711 Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI] + 3;
1712#endif /* RTMP_MAC_USB // */
1713
1714 {
1715 /* Tuning for Wi-Fi WMM S06 */
1716 if (pAd->CommonCfg.bWiFiTest &&
1717 pEdcaParm->Aifsn[QID_AC_VI] == 10)
1718 Ac2Cfg.field.Aifsn -= 1;
1719
1720 /* Tuning for TGn Wi-Fi 5.2.32 */
1721 /* STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta */
1722 if (STA_TGN_WIFI_ON(pAd) &&
1723 pEdcaParm->Aifsn[QID_AC_VI] == 10) {
1724 Ac0Cfg.field.Aifsn = 3;
1725 Ac2Cfg.field.AcTxop = 5;
1726 }
1727#ifdef RT30xx
1728 if (pAd->RfIcType == RFIC_3020
1729 || pAd->RfIcType == RFIC_2020) {
1730 /* Tuning for WiFi WMM S3-T07: connexant legacy sta ==> broadcom 11n sta. */
1731 Ac2Cfg.field.Aifsn = 5;
1732 }
1733#endif /* RT30xx // */
1734 }
1735
1736 Ac3Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VO];
1737 Ac3Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VO];
1738 Ac3Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VO];
1739 Ac3Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VO];
1740
1741/*#ifdef WIFI_TEST */
1742 if (pAd->CommonCfg.bWiFiTest) {
1743 if (Ac3Cfg.field.AcTxop == 102) {
1744 Ac0Cfg.field.AcTxop =
1745 pEdcaParm->Txop[QID_AC_BE] ? pEdcaParm->
1746 Txop[QID_AC_BE] : 10;
1747 Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE] - 1; /* AIFSN must >= 1 */
1748 Ac1Cfg.field.AcTxop =
1749 pEdcaParm->Txop[QID_AC_BK];
1750 Ac1Cfg.field.Aifsn =
1751 pEdcaParm->Aifsn[QID_AC_BK];
1752 Ac2Cfg.field.AcTxop =
1753 pEdcaParm->Txop[QID_AC_VI];
1754 } /* End of if */
1755 }
1756/*#endif // WIFI_TEST // */
1757
1758 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word);
1759 RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word);
1760 RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word);
1761 RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word);
1762
1763 /*======================================================== */
1764 /* DMA Register has a copy too. */
1765 /*======================================================== */
1766 csr0.field.Ac0Txop = Ac0Cfg.field.AcTxop;
1767 csr0.field.Ac1Txop = Ac1Cfg.field.AcTxop;
1768 RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
1769
1770 csr1.field.Ac2Txop = Ac2Cfg.field.AcTxop;
1771 csr1.field.Ac3Txop = Ac3Cfg.field.AcTxop;
1772 RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word);
1773
1774 CwminCsr.word = 0;
1775 CwminCsr.field.Cwmin0 = pEdcaParm->Cwmin[QID_AC_BE];
1776 CwminCsr.field.Cwmin1 = pEdcaParm->Cwmin[QID_AC_BK];
1777 CwminCsr.field.Cwmin2 = pEdcaParm->Cwmin[QID_AC_VI];
1778 CwminCsr.field.Cwmin3 = pEdcaParm->Cwmin[QID_AC_VO] - 1; /*for TGn wifi test */
1779 RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word);
1780
1781 CwmaxCsr.word = 0;
1782 CwmaxCsr.field.Cwmax0 = pEdcaParm->Cwmax[QID_AC_BE];
1783 CwmaxCsr.field.Cwmax1 = pEdcaParm->Cwmax[QID_AC_BK];
1784 CwmaxCsr.field.Cwmax2 = pEdcaParm->Cwmax[QID_AC_VI];
1785 CwmaxCsr.field.Cwmax3 = pEdcaParm->Cwmax[QID_AC_VO];
1786 RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word);
1787
1788 AifsnCsr.word = 0;
1789 AifsnCsr.field.Aifsn0 = Ac0Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_BE]; */
1790 AifsnCsr.field.Aifsn1 = Ac1Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_BK]; */
1791 AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_VI]; */
1792
1793 {
1794 /* Tuning for Wi-Fi WMM S06 */
1795 if (pAd->CommonCfg.bWiFiTest &&
1796 pEdcaParm->Aifsn[QID_AC_VI] == 10)
1797 AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn - 4;
1798
1799 /* Tuning for TGn Wi-Fi 5.2.32 */
1800 /* STA TestBed changes in this item: connexant legacy sta ==> broadcom 11n sta */
1801 if (STA_TGN_WIFI_ON(pAd) &&
1802 pEdcaParm->Aifsn[QID_AC_VI] == 10) {
1803 AifsnCsr.field.Aifsn0 = 3;
1804 AifsnCsr.field.Aifsn2 = 7;
1805 }
1806
1807 if (INFRA_ON(pAd))
1808 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.
1809 Content[BSSID_WCID],
1810 fCLIENT_STATUS_WMM_CAPABLE);
1811 }
1812
1813 {
1814 AifsnCsr.field.Aifsn3 = Ac3Cfg.field.Aifsn - 1; /*pEdcaParm->Aifsn[QID_AC_VO]; //for TGn wifi test */
1815#ifdef RT30xx
1816 /* TODO: Shiang, this modification also suitable for RT3052/RT3050 ??? */
1817 if (pAd->RfIcType == RFIC_3020
1818 || pAd->RfIcType == RFIC_2020) {
1819 AifsnCsr.field.Aifsn2 = 0x2; /*pEdcaParm->Aifsn[QID_AC_VI]; //for WiFi WMM S4-T04. */
1820 }
1821#endif /* RT30xx // */
1822 }
1823 RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, AifsnCsr.word);
1824
1825 NdisMoveMemory(&pAd->CommonCfg.APEdcaParm, pEdcaParm,
1826 sizeof(struct rt_edca_parm));
1827 if (!ADHOC_ON(pAd)) {
1828 DBGPRINT(RT_DEBUG_TRACE,
1829 ("EDCA [#%d]: AIFSN CWmin CWmax TXOP(us) ACM\n",
1830 pEdcaParm->EdcaUpdateCount));
1831 DBGPRINT(RT_DEBUG_TRACE,
1832 (" AC_BE %2d %2d %2d %4d %d\n",
1833 pEdcaParm->Aifsn[0], pEdcaParm->Cwmin[0],
1834 pEdcaParm->Cwmax[0], pEdcaParm->Txop[0] << 5,
1835 pEdcaParm->bACM[0]));
1836 DBGPRINT(RT_DEBUG_TRACE,
1837 (" AC_BK %2d %2d %2d %4d %d\n",
1838 pEdcaParm->Aifsn[1], pEdcaParm->Cwmin[1],
1839 pEdcaParm->Cwmax[1], pEdcaParm->Txop[1] << 5,
1840 pEdcaParm->bACM[1]));
1841 DBGPRINT(RT_DEBUG_TRACE,
1842 (" AC_VI %2d %2d %2d %4d %d\n",
1843 pEdcaParm->Aifsn[2], pEdcaParm->Cwmin[2],
1844 pEdcaParm->Cwmax[2], pEdcaParm->Txop[2] << 5,
1845 pEdcaParm->bACM[2]));
1846 DBGPRINT(RT_DEBUG_TRACE,
1847 (" AC_VO %2d %2d %2d %4d %d\n",
1848 pEdcaParm->Aifsn[3], pEdcaParm->Cwmin[3],
1849 pEdcaParm->Cwmax[3], pEdcaParm->Txop[3] << 5,
1850 pEdcaParm->bACM[3]));
1851 }
1852 }
1853
1854}
1855
1856/*
1857 ==========================================================================
1858 Description:
1859
1860 IRQL = PASSIVE_LEVEL
1861 IRQL = DISPATCH_LEVEL
1862
1863 ==========================================================================
1864 */
1865void AsicSetSlotTime(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUseShortSlotTime)
1866{
1867 unsigned long SlotTime;
1868 u32 RegValue = 0;
1869
1870 if (pAd->CommonCfg.Channel > 14)
1871 bUseShortSlotTime = TRUE;
1872
1873 if (bUseShortSlotTime
1874 && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED))
1875 return;
1876 else if ((!bUseShortSlotTime)
1877 && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED)))
1878 return;
1879
1880 if (bUseShortSlotTime)
1881 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
1882 else
1883 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
1884
1885 SlotTime = (bUseShortSlotTime) ? 9 : 20;
1886
1887 {
1888 /* force using short SLOT time for FAE to demo performance when TxBurst is ON */
1889 if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
1890 && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)))
1891 || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)
1892 && (pAd->CommonCfg.BACapability.field.Policy ==
1893 BA_NOTUSE))
1894 ) {
1895 /* In this case, we will think it is doing Wi-Fi test */
1896 /* And we will not set to short slot when bEnableTxBurst is TRUE. */
1897 } else if (pAd->CommonCfg.bEnableTxBurst) {
1898 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
1899 SlotTime = 9;
1900 }
1901 }
1902
1903 /* */
1904 /* For some reasons, always set it to short slot time. */
1905 /* */
1906 /* ToDo: Should consider capability with 11B */
1907 /* */
1908 {
1909 if (pAd->StaCfg.BssType == BSS_ADHOC) {
1910 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED);
1911 SlotTime = 20;
1912 }
1913 }
1914
1915 RTMP_IO_READ32(pAd, BKOFF_SLOT_CFG, &RegValue);
1916 RegValue = RegValue & 0xFFFFFF00;
1917
1918 RegValue |= SlotTime;
1919
1920 RTMP_IO_WRITE32(pAd, BKOFF_SLOT_CFG, RegValue);
1921}
1922
1923/*
1924 ========================================================================
1925 Description:
1926 Add Shared key information into ASIC.
1927 Update shared key, TxMic and RxMic to Asic Shared key table
1928 Update its cipherAlg to Asic Shared key Mode.
1929
1930 Return:
1931 ========================================================================
1932*/
1933void AsicAddSharedKeyEntry(struct rt_rtmp_adapter *pAd,
1934 u8 BssIndex,
1935 u8 KeyIdx,
1936 u8 CipherAlg,
1937 u8 *pKey, u8 *pTxMic, u8 *pRxMic)
1938{
1939 unsigned long offset; /*, csr0; */
1940 SHAREDKEY_MODE_STRUC csr1;
1941#ifdef RTMP_MAC_PCI
1942 int i;
1943#endif /* RTMP_MAC_PCI // */
1944
1945 DBGPRINT(RT_DEBUG_TRACE,
1946 ("AsicAddSharedKeyEntry BssIndex=%d, KeyIdx=%d\n", BssIndex,
1947 KeyIdx));
1948/*============================================================================================ */
1949
1950 DBGPRINT(RT_DEBUG_TRACE,
1951 ("AsicAddSharedKeyEntry: %s key #%d\n", CipherName[CipherAlg],
1952 BssIndex * 4 + KeyIdx));
1953 DBGPRINT_RAW(RT_DEBUG_TRACE,
1954 (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1955 pKey[0], pKey[1], pKey[2], pKey[3], pKey[4],
1956 pKey[5], pKey[6], pKey[7], pKey[8], pKey[9],
1957 pKey[10], pKey[11], pKey[12], pKey[13], pKey[14],
1958 pKey[15]));
1959 if (pRxMic) {
1960 DBGPRINT_RAW(RT_DEBUG_TRACE,
1961 (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1962 pRxMic[0], pRxMic[1], pRxMic[2], pRxMic[3],
1963 pRxMic[4], pRxMic[5], pRxMic[6], pRxMic[7]));
1964 }
1965 if (pTxMic) {
1966 DBGPRINT_RAW(RT_DEBUG_TRACE,
1967 (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
1968 pTxMic[0], pTxMic[1], pTxMic[2], pTxMic[3],
1969 pTxMic[4], pTxMic[5], pTxMic[6], pTxMic[7]));
1970 }
1971/*============================================================================================ */
1972 /* */
1973 /* fill key material - key + TX MIC + RX MIC */
1974 /* */
1975#ifdef RTMP_MAC_PCI
1976 offset =
1977 SHARED_KEY_TABLE_BASE + (4 * BssIndex + KeyIdx) * HW_KEY_ENTRY_SIZE;
1978 for (i = 0; i < MAX_LEN_OF_SHARE_KEY; i++) {
1979 RTMP_IO_WRITE8(pAd, offset + i, pKey[i]);
1980 }
1981
1982 offset += MAX_LEN_OF_SHARE_KEY;
1983 if (pTxMic) {
1984 for (i = 0; i < 8; i++) {
1985 RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]);
1986 }
1987 }
1988
1989 offset += 8;
1990 if (pRxMic) {
1991 for (i = 0; i < 8; i++) {
1992 RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]);
1993 }
1994 }
1995#endif /* RTMP_MAC_PCI // */
1996#ifdef RTMP_MAC_USB
1997 {
1998 offset =
1999 SHARED_KEY_TABLE_BASE + (4 * BssIndex +
2000 KeyIdx) * HW_KEY_ENTRY_SIZE;
2001 RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_SHARE_KEY);
2002
2003 offset += MAX_LEN_OF_SHARE_KEY;
2004 if (pTxMic) {
2005 RTUSBMultiWrite(pAd, offset, pTxMic, 8);
2006 }
2007
2008 offset += 8;
2009 if (pRxMic) {
2010 RTUSBMultiWrite(pAd, offset, pRxMic, 8);
2011 }
2012 }
2013#endif /* RTMP_MAC_USB // */
2014
2015 /* */
2016 /* Update cipher algorithm. WSTA always use BSS0 */
2017 /* */
2018 RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2019 &csr1.word);
2020 DBGPRINT(RT_DEBUG_TRACE,
2021 ("Read: SHARED_KEY_MODE_BASE at this Bss[%d] KeyIdx[%d]= 0x%x \n",
2022 BssIndex, KeyIdx, csr1.word));
2023 if ((BssIndex % 2) == 0) {
2024 if (KeyIdx == 0)
2025 csr1.field.Bss0Key0CipherAlg = CipherAlg;
2026 else if (KeyIdx == 1)
2027 csr1.field.Bss0Key1CipherAlg = CipherAlg;
2028 else if (KeyIdx == 2)
2029 csr1.field.Bss0Key2CipherAlg = CipherAlg;
2030 else
2031 csr1.field.Bss0Key3CipherAlg = CipherAlg;
2032 } else {
2033 if (KeyIdx == 0)
2034 csr1.field.Bss1Key0CipherAlg = CipherAlg;
2035 else if (KeyIdx == 1)
2036 csr1.field.Bss1Key1CipherAlg = CipherAlg;
2037 else if (KeyIdx == 2)
2038 csr1.field.Bss1Key2CipherAlg = CipherAlg;
2039 else
2040 csr1.field.Bss1Key3CipherAlg = CipherAlg;
2041 }
2042 DBGPRINT(RT_DEBUG_TRACE,
2043 ("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n",
2044 BssIndex, csr1.word));
2045 RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2046 csr1.word);
2047
2048}
2049
2050/* IRQL = DISPATCH_LEVEL */
2051void AsicRemoveSharedKeyEntry(struct rt_rtmp_adapter *pAd,
2052 u8 BssIndex, u8 KeyIdx)
2053{
2054 /*unsigned long SecCsr0; */
2055 SHAREDKEY_MODE_STRUC csr1;
2056
2057 DBGPRINT(RT_DEBUG_TRACE,
2058 ("AsicRemoveSharedKeyEntry: #%d \n", BssIndex * 4 + KeyIdx));
2059
2060 RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2061 &csr1.word);
2062 if ((BssIndex % 2) == 0) {
2063 if (KeyIdx == 0)
2064 csr1.field.Bss0Key0CipherAlg = 0;
2065 else if (KeyIdx == 1)
2066 csr1.field.Bss0Key1CipherAlg = 0;
2067 else if (KeyIdx == 2)
2068 csr1.field.Bss0Key2CipherAlg = 0;
2069 else
2070 csr1.field.Bss0Key3CipherAlg = 0;
2071 } else {
2072 if (KeyIdx == 0)
2073 csr1.field.Bss1Key0CipherAlg = 0;
2074 else if (KeyIdx == 1)
2075 csr1.field.Bss1Key1CipherAlg = 0;
2076 else if (KeyIdx == 2)
2077 csr1.field.Bss1Key2CipherAlg = 0;
2078 else
2079 csr1.field.Bss1Key3CipherAlg = 0;
2080 }
2081 DBGPRINT(RT_DEBUG_TRACE,
2082 ("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n",
2083 BssIndex, csr1.word));
2084 RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2085 csr1.word);
2086 ASSERT(BssIndex < 4);
2087 ASSERT(KeyIdx < 4);
2088
2089}
2090
2091void AsicUpdateWCIDAttribute(struct rt_rtmp_adapter *pAd,
2092 u16 WCID,
2093 u8 BssIndex,
2094 u8 CipherAlg,
2095 IN BOOLEAN bUsePairewiseKeyTable)
2096{
2097 unsigned long WCIDAttri = 0, offset;
2098
2099 /* */
2100 /* Update WCID attribute. */
2101 /* Only TxKey could update WCID attribute. */
2102 /* */
2103 offset = MAC_WCID_ATTRIBUTE_BASE + (WCID * HW_WCID_ATTRI_SIZE);
2104 WCIDAttri =
2105 (BssIndex << 4) | (CipherAlg << 1) | (bUsePairewiseKeyTable);
2106 RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
2107}
2108
2109void AsicUpdateWCIDIVEIV(struct rt_rtmp_adapter *pAd,
2110 u16 WCID, unsigned long uIV, unsigned long uEIV)
2111{
2112 unsigned long offset;
2113
2114 offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE);
2115
2116 RTMP_IO_WRITE32(pAd, offset, uIV);
2117 RTMP_IO_WRITE32(pAd, offset + 4, uEIV);
2118}
2119
2120void AsicUpdateRxWCIDTable(struct rt_rtmp_adapter *pAd,
2121 u16 WCID, u8 *pAddr)
2122{
2123 unsigned long offset;
2124 unsigned long Addr;
2125
2126 offset = MAC_WCID_BASE + (WCID * HW_WCID_ENTRY_SIZE);
2127 Addr = pAddr[0] + (pAddr[1] << 8) + (pAddr[2] << 16) + (pAddr[3] << 24);
2128 RTMP_IO_WRITE32(pAd, offset, Addr);
2129 Addr = pAddr[4] + (pAddr[5] << 8);
2130 RTMP_IO_WRITE32(pAd, offset + 4, Addr);
2131}
2132
2133/*
2134 ========================================================================
2135
2136 Routine Description:
2137 Set Cipher Key, Cipher algorithm, IV/EIV to Asic
2138
2139 Arguments:
2140 pAd Pointer to our adapter
2141 WCID WCID Entry number.
2142 BssIndex BSSID index, station or none multiple BSSID support
2143 this value should be 0.
2144 KeyIdx This KeyIdx will set to IV's KeyID if bTxKey enabled
2145 pCipherKey Pointer to Cipher Key.
2146 bUsePairewiseKeyTable TRUE means saved the key in SharedKey table,
2147 otherwise PairewiseKey table
2148 bTxKey This is the transmit key if enabled.
2149
2150 Return Value:
2151 None
2152
2153 Note:
2154 This routine will set the relative key stuff to Asic including WCID attribute,
2155 Cipher Key, Cipher algorithm and IV/EIV.
2156
2157 IV/EIV will be update if this CipherKey is the transmission key because
2158 ASIC will base on IV's KeyID value to select Cipher Key.
2159
2160 If bTxKey sets to FALSE, this is not the TX key, but it could be
2161 RX key
2162
2163 For AP mode bTxKey must be always set to TRUE.
2164 ========================================================================
2165*/
2166void AsicAddKeyEntry(struct rt_rtmp_adapter *pAd,
2167 u16 WCID,
2168 u8 BssIndex,
2169 u8 KeyIdx,
2170 struct rt_cipher_key *pCipherKey,
2171 IN BOOLEAN bUsePairewiseKeyTable, IN BOOLEAN bTxKey)
2172{
2173 unsigned long offset;
2174/* unsigned long WCIDAttri = 0; */
2175 u8 IV4 = 0;
2176 u8 *pKey = pCipherKey->Key;
2177/* unsigned long KeyLen = pCipherKey->KeyLen; */
2178 u8 *pTxMic = pCipherKey->TxMic;
2179 u8 *pRxMic = pCipherKey->RxMic;
2180 u8 *pTxtsc = pCipherKey->TxTsc;
2181 u8 CipherAlg = pCipherKey->CipherAlg;
2182 SHAREDKEY_MODE_STRUC csr1;
2183#ifdef RTMP_MAC_PCI
2184 u8 i;
2185#endif /* RTMP_MAC_PCI // */
2186
2187/* ASSERT(KeyLen <= MAX_LEN_OF_PEER_KEY); */
2188
2189 DBGPRINT(RT_DEBUG_TRACE, ("==> AsicAddKeyEntry\n"));
2190 /* */
2191 /* 1.) decide key table offset */
2192 /* */
2193 if (bUsePairewiseKeyTable)
2194 offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE);
2195 else
2196 offset =
2197 SHARED_KEY_TABLE_BASE + (4 * BssIndex +
2198 KeyIdx) * HW_KEY_ENTRY_SIZE;
2199
2200 /* */
2201 /* 2.) Set Key to Asic */
2202 /* */
2203 /*for (i = 0; i < KeyLen; i++) */
2204#ifdef RTMP_MAC_PCI
2205 for (i = 0; i < MAX_LEN_OF_PEER_KEY; i++) {
2206 RTMP_IO_WRITE8(pAd, offset + i, pKey[i]);
2207 }
2208 offset += MAX_LEN_OF_PEER_KEY;
2209
2210 /* */
2211 /* 3.) Set MIC key if available */
2212 /* */
2213 if (pTxMic) {
2214 for (i = 0; i < 8; i++) {
2215 RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]);
2216 }
2217 }
2218 offset += LEN_TKIP_TXMICK;
2219
2220 if (pRxMic) {
2221 for (i = 0; i < 8; i++) {
2222 RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]);
2223 }
2224 }
2225#endif /* RTMP_MAC_PCI // */
2226#ifdef RTMP_MAC_USB
2227 RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_PEER_KEY);
2228 offset += MAX_LEN_OF_PEER_KEY;
2229
2230 /* */
2231 /* 3.) Set MIC key if available */
2232 /* */
2233 if (pTxMic) {
2234 RTUSBMultiWrite(pAd, offset, pTxMic, 8);
2235 }
2236 offset += LEN_TKIP_TXMICK;
2237
2238 if (pRxMic) {
2239 RTUSBMultiWrite(pAd, offset, pRxMic, 8);
2240 }
2241#endif /* RTMP_MAC_USB // */
2242
2243 /* */
2244 /* 4.) Modify IV/EIV if needs */
2245 /* This will force Asic to use this key ID by setting IV. */
2246 /* */
2247 if (bTxKey) {
2248#ifdef RTMP_MAC_PCI
2249 offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE);
2250 /* */
2251 /* Write IV */
2252 /* */
2253 RTMP_IO_WRITE8(pAd, offset, pTxtsc[1]);
2254 RTMP_IO_WRITE8(pAd, offset + 1, ((pTxtsc[1] | 0x20) & 0x7f));
2255 RTMP_IO_WRITE8(pAd, offset + 2, pTxtsc[0]);
2256
2257 IV4 = (KeyIdx << 6);
2258 if ((CipherAlg == CIPHER_TKIP)
2259 || (CipherAlg == CIPHER_TKIP_NO_MIC)
2260 || (CipherAlg == CIPHER_AES))
2261 IV4 |= 0x20; /* turn on extension bit means EIV existence */
2262
2263 RTMP_IO_WRITE8(pAd, offset + 3, IV4);
2264
2265 /* */
2266 /* Write EIV */
2267 /* */
2268 offset += 4;
2269 for (i = 0; i < 4; i++) {
2270 RTMP_IO_WRITE8(pAd, offset + i, pTxtsc[i + 2]);
2271 }
2272#endif /* RTMP_MAC_PCI // */
2273#ifdef RTMP_MAC_USB
2274 u32 tmpVal;
2275
2276 /* */
2277 /* Write IV */
2278 /* */
2279 IV4 = (KeyIdx << 6);
2280 if ((CipherAlg == CIPHER_TKIP)
2281 || (CipherAlg == CIPHER_TKIP_NO_MIC)
2282 || (CipherAlg == CIPHER_AES))
2283 IV4 |= 0x20; /* turn on extension bit means EIV existence */
2284
2285 tmpVal =
2286 pTxtsc[1] + (((pTxtsc[1] | 0x20) & 0x7f) << 8) +
2287 (pTxtsc[0] << 16) + (IV4 << 24);
2288 RTMP_IO_WRITE32(pAd, offset, tmpVal);
2289
2290 /* */
2291 /* Write EIV */
2292 /* */
2293 offset += 4;
2294 RTMP_IO_WRITE32(pAd, offset, *(u32 *)& pCipherKey->TxTsc[2]);
2295#endif /* RTMP_MAC_USB // */
2296
2297 AsicUpdateWCIDAttribute(pAd, WCID, BssIndex, CipherAlg,
2298 bUsePairewiseKeyTable);
2299 }
2300
2301 if (!bUsePairewiseKeyTable) {
2302 /* */
2303 /* Only update the shared key security mode */
2304 /* */
2305 RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2306 &csr1.word);
2307 if ((BssIndex % 2) == 0) {
2308 if (KeyIdx == 0)
2309 csr1.field.Bss0Key0CipherAlg = CipherAlg;
2310 else if (KeyIdx == 1)
2311 csr1.field.Bss0Key1CipherAlg = CipherAlg;
2312 else if (KeyIdx == 2)
2313 csr1.field.Bss0Key2CipherAlg = CipherAlg;
2314 else
2315 csr1.field.Bss0Key3CipherAlg = CipherAlg;
2316 } else {
2317 if (KeyIdx == 0)
2318 csr1.field.Bss1Key0CipherAlg = CipherAlg;
2319 else if (KeyIdx == 1)
2320 csr1.field.Bss1Key1CipherAlg = CipherAlg;
2321 else if (KeyIdx == 2)
2322 csr1.field.Bss1Key2CipherAlg = CipherAlg;
2323 else
2324 csr1.field.Bss1Key3CipherAlg = CipherAlg;
2325 }
2326 RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2),
2327 csr1.word);
2328 }
2329
2330 DBGPRINT(RT_DEBUG_TRACE, ("<== AsicAddKeyEntry\n"));
2331}
2332
2333/*
2334 ========================================================================
2335 Description:
2336 Add Pair-wise key material into ASIC.
2337 Update pairwise key, TxMic and RxMic to Asic Pair-wise key table
2338
2339 Return:
2340 ========================================================================
2341*/
2342void AsicAddPairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2343 u8 *pAddr,
2344 u8 WCID, struct rt_cipher_key *pCipherKey)
2345{
2346 int i;
2347 unsigned long offset;
2348 u8 *pKey = pCipherKey->Key;
2349 u8 *pTxMic = pCipherKey->TxMic;
2350 u8 *pRxMic = pCipherKey->RxMic;
2351#ifdef DBG
2352 u8 CipherAlg = pCipherKey->CipherAlg;
2353#endif /* DBG // */
2354
2355 /* EKEY */
2356 offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE);
2357#ifdef RTMP_MAC_PCI
2358 for (i = 0; i < MAX_LEN_OF_PEER_KEY; i++) {
2359 RTMP_IO_WRITE8(pAd, offset + i, pKey[i]);
2360 }
2361#endif /* RTMP_MAC_PCI // */
2362#ifdef RTMP_MAC_USB
2363 RTUSBMultiWrite(pAd, offset, &pCipherKey->Key[0], MAX_LEN_OF_PEER_KEY);
2364#endif /* RTMP_MAC_USB // */
2365 for (i = 0; i < MAX_LEN_OF_PEER_KEY; i += 4) {
2366 u32 Value;
2367 RTMP_IO_READ32(pAd, offset + i, &Value);
2368 }
2369
2370 offset += MAX_LEN_OF_PEER_KEY;
2371
2372 /* MIC KEY */
2373 if (pTxMic) {
2374#ifdef RTMP_MAC_PCI
2375 for (i = 0; i < 8; i++) {
2376 RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]);
2377 }
2378#endif /* RTMP_MAC_PCI // */
2379#ifdef RTMP_MAC_USB
2380 RTUSBMultiWrite(pAd, offset, &pCipherKey->TxMic[0], 8);
2381#endif /* RTMP_MAC_USB // */
2382 }
2383 offset += 8;
2384 if (pRxMic) {
2385#ifdef RTMP_MAC_PCI
2386 for (i = 0; i < 8; i++) {
2387 RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]);
2388 }
2389#endif /* RTMP_MAC_PCI // */
2390#ifdef RTMP_MAC_USB
2391 RTUSBMultiWrite(pAd, offset, &pCipherKey->RxMic[0], 8);
2392#endif /* RTMP_MAC_USB // */
2393 }
2394
2395 DBGPRINT(RT_DEBUG_TRACE,
2396 ("AsicAddPairwiseKeyEntry: WCID #%d Alg=%s\n", WCID,
2397 CipherName[CipherAlg]));
2398 DBGPRINT(RT_DEBUG_TRACE,
2399 (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2400 pKey[0], pKey[1], pKey[2], pKey[3], pKey[4], pKey[5],
2401 pKey[6], pKey[7], pKey[8], pKey[9], pKey[10], pKey[11],
2402 pKey[12], pKey[13], pKey[14], pKey[15]));
2403 if (pRxMic) {
2404 DBGPRINT(RT_DEBUG_TRACE,
2405 (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2406 pRxMic[0], pRxMic[1], pRxMic[2], pRxMic[3],
2407 pRxMic[4], pRxMic[5], pRxMic[6], pRxMic[7]));
2408 }
2409 if (pTxMic) {
2410 DBGPRINT(RT_DEBUG_TRACE,
2411 (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2412 pTxMic[0], pTxMic[1], pTxMic[2], pTxMic[3],
2413 pTxMic[4], pTxMic[5], pTxMic[6], pTxMic[7]));
2414 }
2415}
2416
2417/*
2418 ========================================================================
2419 Description:
2420 Remove Pair-wise key material from ASIC.
2421
2422 Return:
2423 ========================================================================
2424*/
2425void AsicRemovePairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2426 u8 BssIdx, u8 Wcid)
2427{
2428 unsigned long WCIDAttri;
2429 u16 offset;
2430
2431 /* re-set the entry's WCID attribute as OPEN-NONE. */
2432 offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
2433 WCIDAttri = (BssIdx << 4) | PAIRWISEKEYTABLE;
2434 RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
2435}
2436
2437BOOLEAN AsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
2438 u8 Command,
2439 u8 Token, u8 Arg0, u8 Arg1)
2440{
2441
2442 if (pAd->chipOps.sendCommandToMcu)
2443 pAd->chipOps.sendCommandToMcu(pAd, Command, Token, Arg0, Arg1);
2444
2445 return TRUE;
2446}
2447
2448void AsicSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant)
2449{
2450#ifdef RT30xx
2451 /* RT3572 ATE need not to do this. */
2452 RT30xxSetRxAnt(pAd, Ant);
2453#endif /* RT30xx // */
2454}
2455
2456void AsicTurnOffRFClk(struct rt_rtmp_adapter *pAd, u8 Channel)
2457{
2458 if (pAd->chipOps.AsicRfTurnOff) {
2459 pAd->chipOps.AsicRfTurnOff(pAd);
2460 } else {
2461 /* RF R2 bit 18 = 0 */
2462 u32 R1 = 0, R2 = 0, R3 = 0;
2463 u8 index;
2464 struct rt_rtmp_rf_regs *RFRegTable;
2465
2466 RFRegTable = RF2850RegTable;
2467
2468 switch (pAd->RfIcType) {
2469 case RFIC_2820:
2470 case RFIC_2850:
2471 case RFIC_2720:
2472 case RFIC_2750:
2473
2474 for (index = 0; index < NUM_OF_2850_CHNL; index++) {
2475 if (Channel == RFRegTable[index].Channel) {
2476 R1 = RFRegTable[index].R1 & 0xffffdfff;
2477 R2 = RFRegTable[index].R2 & 0xfffbffff;
2478 R3 = RFRegTable[index].R3 & 0xfff3ffff;
2479
2480 RTMP_RF_IO_WRITE32(pAd, R1);
2481 RTMP_RF_IO_WRITE32(pAd, R2);
2482
2483 /* Program R1b13 to 1, R3/b18,19 to 0, R2b18 to 0. */
2484 /* Set RF R2 bit18=0, R3 bit[18:19]=0 */
2485 /*if (pAd->StaCfg.bRadio == FALSE) */
2486 if (1) {
2487 RTMP_RF_IO_WRITE32(pAd, R3);
2488
2489 DBGPRINT(RT_DEBUG_TRACE,
2490 ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x, R3 = 0x%08x \n",
2491 Channel,
2492 pAd->RfIcType, R2,
2493 R3));
2494 } else
2495 DBGPRINT(RT_DEBUG_TRACE,
2496 ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x \n",
2497 Channel,
2498 pAd->RfIcType, R2));
2499 break;
2500 }
2501 }
2502 break;
2503
2504 default:
2505 break;
2506 }
2507 }
2508}
2509
2510void AsicTurnOnRFClk(struct rt_rtmp_adapter *pAd, u8 Channel)
2511{
2512 /* RF R2 bit 18 = 0 */
2513 u32 R1 = 0, R2 = 0, R3 = 0;
2514 u8 index;
2515 struct rt_rtmp_rf_regs *RFRegTable;
2516
2517#ifdef PCIE_PS_SUPPORT
2518 /* The RF programming sequence is difference between 3xxx and 2xxx */
2519 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) {
2520 return;
2521 }
2522#endif /* PCIE_PS_SUPPORT // */
2523
2524 RFRegTable = RF2850RegTable;
2525
2526 switch (pAd->RfIcType) {
2527 case RFIC_2820:
2528 case RFIC_2850:
2529 case RFIC_2720:
2530 case RFIC_2750:
2531
2532 for (index = 0; index < NUM_OF_2850_CHNL; index++) {
2533 if (Channel == RFRegTable[index].Channel) {
2534 R3 = pAd->LatchRfRegs.R3;
2535 R3 &= 0xfff3ffff;
2536 R3 |= 0x00080000;
2537 RTMP_RF_IO_WRITE32(pAd, R3);
2538
2539 R1 = RFRegTable[index].R1;
2540 RTMP_RF_IO_WRITE32(pAd, R1);
2541
2542 R2 = RFRegTable[index].R2;
2543 if (pAd->Antenna.field.TxPath == 1) {
2544 R2 |= 0x4000; /* If TXpath is 1, bit 14 = 1; */
2545 }
2546
2547 if (pAd->Antenna.field.RxPath == 2) {
2548 R2 |= 0x40; /* write 1 to off Rxpath. */
2549 } else if (pAd->Antenna.field.RxPath == 1) {
2550 R2 |= 0x20040; /* write 1 to off RxPath */
2551 }
2552 RTMP_RF_IO_WRITE32(pAd, R2);
2553
2554 break;
2555 }
2556 }
2557 break;
2558
2559 default:
2560 break;
2561 }
2562
2563 DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOnRFClk#%d(RF=%d, ) , R2=0x%08x\n",
2564 Channel, pAd->RfIcType, R2));
2565}
diff --git a/drivers/staging/rt2860/common/cmm_cfg.c b/drivers/staging/rt2860/common/cmm_cfg.c
deleted file mode 100644
index 727f7992925..00000000000
--- a/drivers/staging/rt2860/common/cmm_cfg.c
+++ /dev/null
@@ -1,258 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 cmm_cfg.c
29
30 Abstract:
31 Ralink WiFi Driver configuration related subroutines
32
33 Revision History:
34 Who When What
35 --------- ---------- ----------------------------------------------
36*/
37
38#include "../rt_config.h"
39
40char *GetPhyMode(int Mode)
41{
42 switch (Mode) {
43 case MODE_CCK:
44 return "CCK";
45
46 case MODE_OFDM:
47 return "OFDM";
48 case MODE_HTMIX:
49 return "HTMIX";
50
51 case MODE_HTGREENFIELD:
52 return "GREEN";
53 default:
54 return "N/A";
55 }
56}
57
58char *GetBW(int BW)
59{
60 switch (BW) {
61 case BW_10:
62 return "10M";
63
64 case BW_20:
65 return "20M";
66 case BW_40:
67 return "40M";
68 default:
69 return "N/A";
70 }
71}
72
73/*
74 ==========================================================================
75 Description:
76 Set Country Region to pAd->CommonCfg.CountryRegion.
77 This command will not work, if the field of CountryRegion in eeprom is programmed.
78
79 Return:
80 TRUE if all parameters are OK, FALSE otherwise
81 ==========================================================================
82*/
83int RT_CfgSetCountryRegion(struct rt_rtmp_adapter *pAd, char *arg, int band)
84{
85 long region, regionMax;
86 u8 *pCountryRegion;
87
88 region = simple_strtol(arg, 0, 10);
89
90 if (band == BAND_24G) {
91 pCountryRegion = &pAd->CommonCfg.CountryRegion;
92 regionMax = REGION_MAXIMUM_BG_BAND;
93 } else {
94 pCountryRegion = &pAd->CommonCfg.CountryRegionForABand;
95 regionMax = REGION_MAXIMUM_A_BAND;
96 }
97
98 /* TODO: Is it neccesay for following check??? */
99 /* Country can be set only when EEPROM not programmed */
100 if (*pCountryRegion & 0x80) {
101 DBGPRINT(RT_DEBUG_ERROR,
102 ("CfgSetCountryRegion():CountryRegion in eeprom was programmed\n"));
103 return FALSE;
104 }
105
106 if ((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND)) {
107 *pCountryRegion = (u8)region;
108 } else if ((region == REGION_31_BG_BAND) && (band == BAND_24G)) {
109 *pCountryRegion = (u8)region;
110 } else {
111 DBGPRINT(RT_DEBUG_ERROR,
112 ("CfgSetCountryRegion():region(%ld) out of range!\n",
113 region));
114 return FALSE;
115 }
116
117 return TRUE;
118
119}
120
121/*
122 ==========================================================================
123 Description:
124 Set Wireless Mode
125 Return:
126 TRUE if all parameters are OK, FALSE otherwise
127 ==========================================================================
128*/
129int RT_CfgSetWirelessMode(struct rt_rtmp_adapter *pAd, char *arg)
130{
131 int MaxPhyMode = PHY_11G;
132 long WirelessMode;
133
134 MaxPhyMode = PHY_11N_5G;
135
136 WirelessMode = simple_strtol(arg, 0, 10);
137 if (WirelessMode <= MaxPhyMode) {
138 pAd->CommonCfg.PhyMode = WirelessMode;
139 return TRUE;
140 }
141
142 return FALSE;
143
144}
145
146int RT_CfgSetShortSlot(struct rt_rtmp_adapter *pAd, char *arg)
147{
148 long ShortSlot;
149
150 ShortSlot = simple_strtol(arg, 0, 10);
151
152 if (ShortSlot == 1)
153 pAd->CommonCfg.bUseShortSlotTime = TRUE;
154 else if (ShortSlot == 0)
155 pAd->CommonCfg.bUseShortSlotTime = FALSE;
156 else
157 return FALSE; /*Invalid argument */
158
159 return TRUE;
160}
161
162/*
163 ==========================================================================
164 Description:
165 Set WEP KEY base on KeyIdx
166 Return:
167 TRUE if all parameters are OK, FALSE otherwise
168 ==========================================================================
169*/
170int RT_CfgSetWepKey(struct rt_rtmp_adapter *pAd,
171 char *keyString,
172 struct rt_cipher_key *pSharedKey, int keyIdx)
173{
174 int KeyLen;
175 int i;
176 u8 CipherAlg = CIPHER_NONE;
177 BOOLEAN bKeyIsHex = FALSE;
178
179 /* TODO: Shall we do memset for the original key info?? */
180 memset(pSharedKey, 0, sizeof(struct rt_cipher_key));
181 KeyLen = strlen(keyString);
182 switch (KeyLen) {
183 case 5: /*wep 40 Ascii type */
184 case 13: /*wep 104 Ascii type */
185 bKeyIsHex = FALSE;
186 pSharedKey->KeyLen = KeyLen;
187 NdisMoveMemory(pSharedKey->Key, keyString, KeyLen);
188 break;
189
190 case 10: /*wep 40 Hex type */
191 case 26: /*wep 104 Hex type */
192 for (i = 0; i < KeyLen; i++) {
193 if (!isxdigit(*(keyString + i)))
194 return FALSE; /*Not Hex value; */
195 }
196 bKeyIsHex = TRUE;
197 pSharedKey->KeyLen = KeyLen / 2;
198 AtoH(keyString, pSharedKey->Key, pSharedKey->KeyLen);
199 break;
200
201 default: /*Invalid argument */
202 DBGPRINT(RT_DEBUG_TRACE,
203 ("RT_CfgSetWepKey(keyIdx=%d):Invalid argument (arg=%s)\n",
204 keyIdx, keyString));
205 return FALSE;
206 }
207
208 pSharedKey->CipherAlg = ((KeyLen % 5) ? CIPHER_WEP128 : CIPHER_WEP64);
209 DBGPRINT(RT_DEBUG_TRACE,
210 ("RT_CfgSetWepKey:(KeyIdx=%d,type=%s, Alg=%s)\n", keyIdx,
211 (bKeyIsHex == FALSE ? "Ascii" : "Hex"),
212 CipherName[CipherAlg]));
213
214 return TRUE;
215}
216
217/*
218 ==========================================================================
219 Description:
220 Set WPA PSK key
221
222 Arguments:
223 pAdapter Pointer to our adapter
224 keyString WPA pre-shared key string
225 pHashStr String used for password hash function
226 hashStrLen Length of the hash string
227 pPMKBuf Output buffer of WPAPSK key
228
229 Return:
230 TRUE if all parameters are OK, FALSE otherwise
231 ==========================================================================
232*/
233int RT_CfgSetWPAPSKKey(struct rt_rtmp_adapter *pAd,
234 char *keyString,
235 u8 * pHashStr,
236 int hashStrLen, u8 *pPMKBuf)
237{
238 int keyLen;
239 u8 keyMaterial[40];
240
241 keyLen = strlen(keyString);
242 if ((keyLen < 8) || (keyLen > 64)) {
243 DBGPRINT(RT_DEBUG_TRACE,
244 ("WPAPSK Key length(%d) error, required 8 ~ 64 characters!(keyStr=%s)\n",
245 keyLen, keyString));
246 return FALSE;
247 }
248
249 memset(pPMKBuf, 0, 32);
250 if (keyLen == 64) {
251 AtoH(keyString, pPMKBuf, 32);
252 } else {
253 PasswordHash(keyString, pHashStr, hashStrLen, keyMaterial);
254 NdisMoveMemory(pPMKBuf, keyMaterial, 32);
255 }
256
257 return TRUE;
258}
diff --git a/drivers/staging/rt2860/common/cmm_data.c b/drivers/staging/rt2860/common/cmm_data.c
deleted file mode 100644
index 33799e1449a..00000000000
--- a/drivers/staging/rt2860/common/cmm_data.c
+++ /dev/null
@@ -1,2361 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27
28#include "../rt_config.h"
29
30u8 SNAP_802_1H[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
31u8 SNAP_BRIDGE_TUNNEL[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
32
33/* Add Cisco Aironet SNAP heade for CCX2 support */
34u8 SNAP_AIRONET[] = { 0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x00 };
35u8 CKIP_LLC_SNAP[] = { 0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x02 };
36u8 EAPOL_LLC_SNAP[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
37u8 EAPOL[] = { 0x88, 0x8e };
38u8 TPID[] = { 0x81, 0x00 }; /* VLAN related */
39
40u8 IPX[] = { 0x81, 0x37 };
41u8 APPLE_TALK[] = { 0x80, 0xf3 };
42
43u8 RateIdToPlcpSignal[12] = {
44 0, /* RATE_1 */ 1, /* RATE_2 */ 2, /* RATE_5_5 */ 3, /* RATE_11 *//* see BBP spec */
45 11, /* RATE_6 */ 15, /* RATE_9 */ 10, /* RATE_12 */ 14, /* RATE_18 *//* see IEEE802.11a-1999 p.14 */
46 9, /* RATE_24 */ 13, /* RATE_36 */ 8, /* RATE_48 */ 12 /* RATE_54 */
47}; /* see IEEE802.11a-1999 p.14 */
48
49u8 OfdmSignalToRateId[16] = {
50 RATE_54, RATE_54, RATE_54, RATE_54, /* OFDM PLCP Signal = 0, 1, 2, 3 respectively */
51 RATE_54, RATE_54, RATE_54, RATE_54, /* OFDM PLCP Signal = 4, 5, 6, 7 respectively */
52 RATE_48, RATE_24, RATE_12, RATE_6, /* OFDM PLCP Signal = 8, 9, 10, 11 respectively */
53 RATE_54, RATE_36, RATE_18, RATE_9, /* OFDM PLCP Signal = 12, 13, 14, 15 respectively */
54};
55
56u8 OfdmRateToRxwiMCS[12] = {
57 0, 0, 0, 0,
58 0, 1, 2, 3, /* OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3 */
59 4, 5, 6, 7, /* OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7 */
60};
61
62u8 RxwiMCSToOfdmRate[12] = {
63 RATE_6, RATE_9, RATE_12, RATE_18,
64 RATE_24, RATE_36, RATE_48, RATE_54, /* OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3 */
65 4, 5, 6, 7, /* OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7 */
66};
67
68char *MCSToMbps[] =
69 { "1Mbps", "2Mbps", "5.5Mbps", "11Mbps", "06Mbps", "09Mbps", "12Mbps",
70"18Mbps", "24Mbps", "36Mbps", "48Mbps", "54Mbps", "MM-0", "MM-1", "MM-2", "MM-3",
71"MM-4", "MM-5", "MM-6", "MM-7", "MM-8", "MM-9", "MM-10", "MM-11", "MM-12", "MM-13",
72"MM-14", "MM-15", "MM-32", "ee1", "ee2", "ee3" };
73
74u8 default_cwmin[] =
75 { CW_MIN_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS - 1, CW_MIN_IN_BITS - 2 };
76/*u8 default_cwmax[]={CW_MAX_IN_BITS, CW_MAX_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS-1}; */
77u8 default_sta_aifsn[] = { 3, 7, 2, 2 };
78
79u8 MapUserPriorityToAccessCategory[8] =
80 { QID_AC_BE, QID_AC_BK, QID_AC_BK, QID_AC_BE, QID_AC_VI, QID_AC_VI,
81QID_AC_VO, QID_AC_VO };
82
83/*
84 ========================================================================
85
86 Routine Description:
87 API for MLME to transmit management frame to AP (BSS Mode)
88 or station (IBSS Mode)
89
90 Arguments:
91 pAd Pointer to our adapter
92 pData Pointer to the outgoing 802.11 frame
93 Length Size of outgoing management frame
94
95 Return Value:
96 NDIS_STATUS_FAILURE
97 NDIS_STATUS_PENDING
98 NDIS_STATUS_SUCCESS
99
100 IRQL = PASSIVE_LEVEL
101 IRQL = DISPATCH_LEVEL
102
103 Note:
104
105 ========================================================================
106*/
107int MiniportMMRequest(struct rt_rtmp_adapter *pAd,
108 u8 QueIdx, u8 *pData, u32 Length)
109{
110 void *pPacket;
111 int Status = NDIS_STATUS_SUCCESS;
112 unsigned long FreeNum;
113 u8 rtmpHwHdr[TXINFO_SIZE + TXWI_SIZE]; /*RTMP_HW_HDR_LEN]; */
114#ifdef RTMP_MAC_PCI
115 unsigned long IrqFlags = 0;
116 u8 IrqState;
117#endif /* RTMP_MAC_PCI // */
118 BOOLEAN bUseDataQ = FALSE;
119 int retryCnt = 0;
120
121 ASSERT(Length <= MGMT_DMA_BUFFER_SIZE);
122
123 if ((QueIdx & MGMT_USE_QUEUE_FLAG) == MGMT_USE_QUEUE_FLAG) {
124 bUseDataQ = TRUE;
125 QueIdx &= (~MGMT_USE_QUEUE_FLAG);
126 }
127#ifdef RTMP_MAC_PCI
128 /* 2860C use Tx Ring */
129 IrqState = pAd->irq_disabled;
130 if (pAd->MACVersion == 0x28600100) {
131 QueIdx = (bUseDataQ == TRUE ? QueIdx : 3);
132 bUseDataQ = TRUE;
133 }
134 if (bUseDataQ && (!IrqState))
135 RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
136#endif /* RTMP_MAC_PCI // */
137
138 do {
139 /* Reset is in progress, stop immediately */
140 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
141 RTMP_TEST_FLAG(pAd,
142 fRTMP_ADAPTER_HALT_IN_PROGRESS |
143 fRTMP_ADAPTER_NIC_NOT_EXIST)
144 || !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)) {
145 Status = NDIS_STATUS_FAILURE;
146 break;
147 }
148 /* Check Free priority queue */
149 /* Since we use PBF Queue2 for management frame. Its corresponding DMA ring should be using TxRing. */
150#ifdef RTMP_MAC_PCI
151 if (bUseDataQ) {
152 retryCnt = MAX_DATAMM_RETRY;
153 /* free Tx(QueIdx) resources */
154 RTMPFreeTXDUponTxDmaDone(pAd, QueIdx);
155 FreeNum = GET_TXRING_FREENO(pAd, QueIdx);
156 } else
157#endif /* RTMP_MAC_PCI // */
158 {
159 FreeNum = GET_MGMTRING_FREENO(pAd);
160 }
161
162 if ((FreeNum > 0)) {
163 /* We need to reserve space for rtmp hardware header. i.e., TxWI for RT2860 and TxInfo+TxWI for RT2870 */
164 NdisZeroMemory(&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE));
165 Status =
166 RTMPAllocateNdisPacket(pAd, &pPacket,
167 (u8 *)& rtmpHwHdr,
168 (TXINFO_SIZE + TXWI_SIZE),
169 pData, Length);
170 if (Status != NDIS_STATUS_SUCCESS) {
171 DBGPRINT(RT_DEBUG_WARN,
172 ("MiniportMMRequest (error:: can't allocate NDIS PACKET)\n"));
173 break;
174 }
175 /*pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; */
176 /*pAd->CommonCfg.MlmeRate = RATE_2; */
177
178#ifdef RTMP_MAC_PCI
179 if (bUseDataQ) {
180 Status =
181 MlmeDataHardTransmit(pAd, QueIdx, pPacket);
182 retryCnt--;
183 } else
184#endif /* RTMP_MAC_PCI // */
185 Status = MlmeHardTransmit(pAd, QueIdx, pPacket);
186 if (Status == NDIS_STATUS_SUCCESS)
187 retryCnt = 0;
188 else
189 RTMPFreeNdisPacket(pAd, pPacket);
190 } else {
191 pAd->RalinkCounters.MgmtRingFullCount++;
192#ifdef RTMP_MAC_PCI
193 if (bUseDataQ) {
194 retryCnt--;
195 DBGPRINT(RT_DEBUG_TRACE,
196 ("retryCnt %d\n", retryCnt));
197 if (retryCnt == 0) {
198 DBGPRINT(RT_DEBUG_ERROR,
199 ("Qidx(%d), not enough space in DataRing, MgmtRingFullCount=%ld!\n",
200 QueIdx,
201 pAd->RalinkCounters.
202 MgmtRingFullCount));
203 }
204 }
205#endif /* RTMP_MAC_PCI // */
206 DBGPRINT(RT_DEBUG_ERROR,
207 ("Qidx(%d), not enough space in MgmtRing, MgmtRingFullCount=%ld!\n",
208 QueIdx,
209 pAd->RalinkCounters.MgmtRingFullCount));
210 }
211 } while (retryCnt > 0);
212
213#ifdef RTMP_MAC_PCI
214 if (bUseDataQ && (!IrqState))
215 RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
216#endif /* RTMP_MAC_PCI // */
217
218 return Status;
219}
220
221/*
222 ========================================================================
223
224 Routine Description:
225 Copy frame from waiting queue into relative ring buffer and set
226 appropriate ASIC register to kick hardware transmit function
227
228 Arguments:
229 pAd Pointer to our adapter
230 pBuffer Pointer to memory of outgoing frame
231 Length Size of outgoing management frame
232
233 Return Value:
234 NDIS_STATUS_FAILURE
235 NDIS_STATUS_PENDING
236 NDIS_STATUS_SUCCESS
237
238 IRQL = PASSIVE_LEVEL
239 IRQL = DISPATCH_LEVEL
240
241 Note:
242
243 ========================================================================
244*/
245int MlmeHardTransmit(struct rt_rtmp_adapter *pAd,
246 u8 QueIdx, void *pPacket)
247{
248 struct rt_packet_info PacketInfo;
249 u8 *pSrcBufVA;
250 u32 SrcBufLen;
251 struct rt_header_802_11 * pHeader_802_11;
252
253 if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)
254 ) {
255 return NDIS_STATUS_FAILURE;
256 }
257
258 RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
259 if (pSrcBufVA == NULL)
260 return NDIS_STATUS_FAILURE;
261
262 pHeader_802_11 = (struct rt_header_802_11 *) (pSrcBufVA + TXINFO_SIZE + TXWI_SIZE);
263
264#ifdef RTMP_MAC_PCI
265 if (pAd->MACVersion == 0x28600100)
266 return MlmeHardTransmitTxRing(pAd, QueIdx, pPacket);
267 else
268#endif /* RTMP_MAC_PCI // */
269 return MlmeHardTransmitMgmtRing(pAd, QueIdx, pPacket);
270
271}
272
273int MlmeHardTransmitMgmtRing(struct rt_rtmp_adapter *pAd,
274 u8 QueIdx, void *pPacket)
275{
276 struct rt_packet_info PacketInfo;
277 u8 *pSrcBufVA;
278 u32 SrcBufLen;
279 struct rt_header_802_11 * pHeader_802_11;
280 BOOLEAN bAckRequired, bInsertTimestamp;
281 u8 MlmeRate;
282 struct rt_txwi * pFirstTxWI;
283 struct rt_mac_table_entry *pMacEntry = NULL;
284 u8 PID;
285
286 RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
287
288 /* Make sure MGMT ring resource won't be used by other threads */
289 RTMP_SEM_LOCK(&pAd->MgmtRingLock);
290 if (pSrcBufVA == NULL) {
291 /* The buffer shouldn't be NULL */
292 RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
293 return NDIS_STATUS_FAILURE;
294 }
295
296 {
297 /* outgoing frame always wakeup PHY to prevent frame lost */
298 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
299 AsicForceWakeup(pAd, TRUE);
300 }
301
302 pFirstTxWI = (struct rt_txwi *) (pSrcBufVA + TXINFO_SIZE);
303 pHeader_802_11 = (struct rt_header_802_11 *) (pSrcBufVA + TXINFO_SIZE + TXWI_SIZE); /*TXWI_SIZE); */
304
305 if (pHeader_802_11->Addr1[0] & 0x01) {
306 MlmeRate = pAd->CommonCfg.BasicMlmeRate;
307 } else {
308 MlmeRate = pAd->CommonCfg.MlmeRate;
309 }
310
311 /* Verify Mlme rate for a / g bands. */
312 if ((pAd->LatchRfRegs.Channel > 14) && (MlmeRate < RATE_6)) /* 11A band */
313 MlmeRate = RATE_6;
314
315 if ((pHeader_802_11->FC.Type == BTYPE_DATA) &&
316 (pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL)) {
317 pMacEntry = MacTableLookup(pAd, pHeader_802_11->Addr1);
318 }
319
320 {
321 /* Fixed W52 with Activity scan issue in ABG_MIXED and ABGN_MIXED mode. */
322 if (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED
323 || pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) {
324 if (pAd->LatchRfRegs.Channel > 14)
325 pAd->CommonCfg.MlmeTransmit.field.MODE = 1;
326 else
327 pAd->CommonCfg.MlmeTransmit.field.MODE = 0;
328 }
329 }
330
331 /* */
332 /* Should not be hard code to set PwrMgmt to 0 (PWR_ACTIVE) */
333 /* Snice it's been set to 0 while on MgtMacHeaderInit */
334 /* By the way this will cause frame to be send on PWR_SAVE failed. */
335 /* */
336 pHeader_802_11->FC.PwrMgmt = PWR_ACTIVE; /* (pAd->StaCfg.Psm == PWR_SAVE); */
337
338 /* */
339 /* In WMM-UAPSD, mlme frame should be set psm as power saving but probe request frame */
340 /* Data-Null packets also pass through MMRequest in RT2860, however, we hope control the psm bit to pass APSD */
341/* if ((pHeader_802_11->FC.Type != BTYPE_DATA) && (pHeader_802_11->FC.Type != BTYPE_CNTL)) */
342 {
343 if ((pHeader_802_11->FC.SubType == SUBTYPE_ACTION) ||
344 ((pHeader_802_11->FC.Type == BTYPE_DATA) &&
345 ((pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL) ||
346 (pHeader_802_11->FC.SubType == SUBTYPE_NULL_FUNC)))) {
347 if (pAd->StaCfg.Psm == PWR_SAVE)
348 pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
349 else
350 pHeader_802_11->FC.PwrMgmt =
351 pAd->CommonCfg.bAPSDForcePowerSave;
352 }
353 }
354
355 bInsertTimestamp = FALSE;
356 if (pHeader_802_11->FC.Type == BTYPE_CNTL) /* must be PS-POLL */
357 {
358 /*Set PM bit in ps-poll, to fix WLK 1.2 PowerSaveMode_ext failure issue. */
359 if ((pAd->OpMode == OPMODE_STA)
360 && (pHeader_802_11->FC.SubType == SUBTYPE_PS_POLL)) {
361 pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
362 }
363 bAckRequired = FALSE;
364 } else /* BTYPE_MGMT or BTYPE_DATA(must be NULL frame) */
365 {
366 /*pAd->Sequence++; */
367 /*pHeader_802_11->Sequence = pAd->Sequence; */
368
369 if (pHeader_802_11->Addr1[0] & 0x01) /* MULTICAST, BROADCAST */
370 {
371 bAckRequired = FALSE;
372 pHeader_802_11->Duration = 0;
373 } else {
374 bAckRequired = TRUE;
375 pHeader_802_11->Duration =
376 RTMPCalcDuration(pAd, MlmeRate, 14);
377 if ((pHeader_802_11->FC.SubType == SUBTYPE_PROBE_RSP)
378 && (pHeader_802_11->FC.Type == BTYPE_MGMT)) {
379 bInsertTimestamp = TRUE;
380 bAckRequired = FALSE; /* Disable ACK to prevent retry 0x1f for Probe Response */
381 } else
382 if ((pHeader_802_11->FC.SubType ==
383 SUBTYPE_PROBE_REQ)
384 && (pHeader_802_11->FC.Type == BTYPE_MGMT)) {
385 bAckRequired = FALSE; /* Disable ACK to prevent retry 0x1f for Probe Request */
386 }
387 }
388 }
389
390 pHeader_802_11->Sequence = pAd->Sequence++;
391 if (pAd->Sequence > 0xfff)
392 pAd->Sequence = 0;
393
394 /* Before radar detection done, mgmt frame can not be sent but probe req */
395 /* Because we need to use probe req to trigger driver to send probe req in passive scan */
396 if ((pHeader_802_11->FC.SubType != SUBTYPE_PROBE_REQ)
397 && (pAd->CommonCfg.bIEEE80211H == 1)
398 && (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)) {
399 DBGPRINT(RT_DEBUG_ERROR,
400 ("MlmeHardTransmit --> radar detect not in normal mode!\n"));
401/* if (!IrqState) */
402 RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
403 return (NDIS_STATUS_FAILURE);
404 }
405
406 /* */
407 /* fill scatter-and-gather buffer list into TXD. Internally created NDIS PACKET */
408 /* should always has only one physical buffer, and the whole frame size equals */
409 /* to the first scatter buffer size */
410 /* */
411
412 /* Initialize TX Descriptor */
413 /* For inter-frame gap, the number is for this frame and next frame */
414 /* For MLME rate, we will fix as 2Mb to match other vendor's implement */
415/* pAd->CommonCfg.MlmeTransmit.field.MODE = 1; */
416
417/* management frame doesn't need encryption. so use RESERVED_WCID no matter u are sending to specific wcid or not. */
418 PID = PID_MGMT;
419
420 if (pMacEntry == NULL) {
421 RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, bInsertTimestamp,
422 FALSE, bAckRequired, FALSE, 0, RESERVED_WCID,
423 (SrcBufLen - TXINFO_SIZE - TXWI_SIZE), PID, 0,
424 (u8)pAd->CommonCfg.MlmeTransmit.field.MCS,
425 IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
426 } else {
427 /* dont use low rate to send QoS Null data frame */
428 RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE,
429 bInsertTimestamp, FALSE, bAckRequired, FALSE,
430 0, pMacEntry->Aid,
431 (SrcBufLen - TXINFO_SIZE - TXWI_SIZE),
432 pMacEntry->MaxHTPhyMode.field.MCS, 0,
433 (u8)pMacEntry->MaxHTPhyMode.field.MCS,
434 IFS_BACKOFF, FALSE, &pMacEntry->MaxHTPhyMode);
435 }
436
437 /* Now do hardware-depened kick out. */
438 HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen);
439
440 /* Make sure to release MGMT ring resource */
441/* if (!IrqState) */
442 RTMP_SEM_UNLOCK(&pAd->MgmtRingLock);
443 return NDIS_STATUS_SUCCESS;
444}
445
446/********************************************************************************
447
448 New DeQueue Procedures.
449
450 ********************************************************************************/
451
452#define DEQUEUE_LOCK(lock, bIntContext, IrqFlags) \
453 do{ \
454 if (bIntContext == FALSE) \
455 RTMP_IRQ_LOCK((lock), IrqFlags); \
456 }while(0)
457
458#define DEQUEUE_UNLOCK(lock, bIntContext, IrqFlags) \
459 do{ \
460 if (bIntContext == FALSE) \
461 RTMP_IRQ_UNLOCK((lock), IrqFlags); \
462 }while(0)
463
464/*
465 ========================================================================
466 Tx Path design algorithm:
467 Basically, we divide the packets into four types, Broadcast/Multicast, 11N Rate(AMPDU, AMSDU, Normal), B/G Rate(ARALINK, Normal),
468 Specific Packet Type. Following show the classification rule and policy for each kinds of packets.
469 Classification Rule=>
470 Multicast: (*addr1 & 0x01) == 0x01
471 Specific : bDHCPFrame, bARPFrame, bEAPOLFrame, etc.
472 11N Rate : If peer support HT
473 (1).AMPDU -- If TXBA is negotiated.
474 (2).AMSDU -- If AMSDU is capable for both peer and ourself.
475 *). AMSDU can embedded in a AMPDU, but now we didn't support it.
476 (3).Normal -- Other packets which send as 11n rate.
477
478 B/G Rate : If peer is b/g only.
479 (1).ARALINK-- If both of peer/us supprot Ralink proprietary Aggregation and the TxRate is large than RATE_6
480 (2).Normal -- Other packets which send as b/g rate.
481 Fragment:
482 The packet must be unicast, NOT A-RALINK, NOT A-MSDU, NOT 11n, then can consider about fragment.
483
484 Classified Packet Handle Rule=>
485 Multicast:
486 No ACK, //pTxBlk->bAckRequired = FALSE;
487 No WMM, //pTxBlk->bWMM = FALSE;
488 No piggyback, //pTxBlk->bPiggyBack = FALSE;
489 Force LowRate, //pTxBlk->bForceLowRate = TRUE;
490 Specific : Basically, for specific packet, we should handle it specifically, but now all specific packets are use
491 the same policy to handle it.
492 Force LowRate, //pTxBlk->bForceLowRate = TRUE;
493
494 11N Rate :
495 No piggyback, //pTxBlk->bPiggyBack = FALSE;
496
497 (1).AMSDU
498 pTxBlk->bWMM = TRUE;
499 (2).AMPDU
500 pTxBlk->bWMM = TRUE;
501 (3).Normal
502
503 B/G Rate :
504 (1).ARALINK
505
506 (2).Normal
507 ========================================================================
508*/
509static u8 TxPktClassification(struct rt_rtmp_adapter *pAd, void *pPacket)
510{
511 u8 TxFrameType = TX_UNKOWN_FRAME;
512 u8 Wcid;
513 struct rt_mac_table_entry *pMacEntry = NULL;
514 BOOLEAN bHTRate = FALSE;
515
516 Wcid = RTMP_GET_PACKET_WCID(pPacket);
517 if (Wcid == MCAST_WCID) { /* Handle for RA is Broadcast/Multicast Address. */
518 return TX_MCAST_FRAME;
519 }
520 /* Handle for unicast packets */
521 pMacEntry = &pAd->MacTab.Content[Wcid];
522 if (RTMP_GET_PACKET_LOWRATE(pPacket)) { /* It's a specific packet need to force low rate, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame */
523 TxFrameType = TX_LEGACY_FRAME;
524 } else if (IS_HT_RATE(pMacEntry)) { /* it's a 11n capable packet */
525
526 /* Depends on HTPhyMode to check if the peer support the HTRate transmission. */
527 /* Currently didn't support A-MSDU embedded in A-MPDU */
528 bHTRate = TRUE;
529 if (RTMP_GET_PACKET_MOREDATA(pPacket)
530 || (pMacEntry->PsMode == PWR_SAVE))
531 TxFrameType = TX_LEGACY_FRAME;
532 else if ((pMacEntry->
533 TXBAbitmap & (1 << (RTMP_GET_PACKET_UP(pPacket)))) !=
534 0)
535 return TX_AMPDU_FRAME;
536 else if (CLIENT_STATUS_TEST_FLAG
537 (pMacEntry, fCLIENT_STATUS_AMSDU_INUSED))
538 return TX_AMSDU_FRAME;
539 else
540 TxFrameType = TX_LEGACY_FRAME;
541 } else { /* it's a legacy b/g packet. */
542 if ((CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE) && pAd->CommonCfg.bAggregationCapable) && (RTMP_GET_PACKET_TXRATE(pPacket) >= RATE_6) && (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)))) { /* if peer support Ralink Aggregation, we use it. */
543 TxFrameType = TX_RALINK_FRAME;
544 } else {
545 TxFrameType = TX_LEGACY_FRAME;
546 }
547 }
548
549 /* Currently, our fragment only support when a unicast packet send as NOT-ARALINK, NOT-AMSDU and NOT-AMPDU. */
550 if ((RTMP_GET_PACKET_FRAGMENTS(pPacket) > 1)
551 && (TxFrameType == TX_LEGACY_FRAME))
552 TxFrameType = TX_FRAG_FRAME;
553
554 return TxFrameType;
555}
556
557BOOLEAN RTMP_FillTxBlkInfo(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
558{
559 struct rt_packet_info PacketInfo;
560 void *pPacket;
561 struct rt_mac_table_entry *pMacEntry = NULL;
562
563 pPacket = pTxBlk->pPacket;
564 RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader,
565 &pTxBlk->SrcBufLen);
566
567 pTxBlk->Wcid = RTMP_GET_PACKET_WCID(pPacket);
568 pTxBlk->apidx = RTMP_GET_PACKET_IF(pPacket);
569 pTxBlk->UserPriority = RTMP_GET_PACKET_UP(pPacket);
570 pTxBlk->FrameGap = IFS_HTTXOP; /* ASIC determine Frame Gap */
571
572 if (RTMP_GET_PACKET_CLEAR_EAP_FRAME(pTxBlk->pPacket))
573 TX_BLK_SET_FLAG(pTxBlk, fTX_bClearEAPFrame);
574 else
575 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bClearEAPFrame);
576
577 /* Default to clear this flag */
578 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bForceNonQoS);
579
580 if (pTxBlk->Wcid == MCAST_WCID) {
581 pTxBlk->pMacEntry = NULL;
582 {
583 pTxBlk->pTransmit =
584 &pAd->MacTab.Content[MCAST_WCID].HTPhyMode;
585 }
586
587 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); /* AckRequired = FALSE, when broadcast packet in Adhoc mode. */
588 /*TX_BLK_SET_FLAG(pTxBlk, fTX_bForceLowRate); */
589 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAllowFrag);
590 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM);
591 if (RTMP_GET_PACKET_MOREDATA(pPacket)) {
592 TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData);
593 }
594
595 } else {
596 pTxBlk->pMacEntry = &pAd->MacTab.Content[pTxBlk->Wcid];
597 pTxBlk->pTransmit = &pTxBlk->pMacEntry->HTPhyMode;
598
599 pMacEntry = pTxBlk->pMacEntry;
600
601 /* For all unicast packets, need Ack unless the Ack Policy is not set as NORMAL_ACK. */
602 if (pAd->CommonCfg.AckPolicy[pTxBlk->QueIdx] != NORMAL_ACK)
603 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired);
604 else
605 TX_BLK_SET_FLAG(pTxBlk, fTX_bAckRequired);
606
607 if ((pAd->OpMode == OPMODE_STA) &&
608 (ADHOC_ON(pAd)) &&
609 (RX_FILTER_TEST_FLAG(pAd, fRX_FILTER_ACCEPT_PROMISCUOUS))) {
610 if (pAd->CommonCfg.PSPXlink)
611 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired);
612 }
613
614 {
615 {
616
617 /* If support WMM, enable it. */
618 if (OPSTATUS_TEST_FLAG
619 (pAd, fOP_STATUS_WMM_INUSED)
620 && CLIENT_STATUS_TEST_FLAG(pMacEntry,
621 fCLIENT_STATUS_WMM_CAPABLE))
622 TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM);
623
624/* if (pAd->StaCfg.bAutoTxRateSwitch) */
625/* TX_BLK_SET_FLAG(pTxBlk, fTX_AutoRateSwitch); */
626 }
627 }
628
629 if (pTxBlk->TxFrameType == TX_LEGACY_FRAME) {
630 if ((RTMP_GET_PACKET_LOWRATE(pPacket)) || ((pAd->OpMode == OPMODE_AP) && (pMacEntry->MaxHTPhyMode.field.MODE == MODE_CCK) && (pMacEntry->MaxHTPhyMode.field.MCS == RATE_1))) { /* Specific packet, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame, need force low rate. */
631 pTxBlk->pTransmit =
632 &pAd->MacTab.Content[MCAST_WCID].HTPhyMode;
633
634 /* Modify the WMM bit for ICV issue. If we have a packet with EOSP field need to set as 1, how to handle it??? */
635 if (IS_HT_STA(pTxBlk->pMacEntry) &&
636 (CLIENT_STATUS_TEST_FLAG
637 (pMacEntry, fCLIENT_STATUS_RALINK_CHIPSET))
638 && ((pAd->CommonCfg.bRdg == TRUE)
639 && CLIENT_STATUS_TEST_FLAG(pMacEntry,
640 fCLIENT_STATUS_RDG_CAPABLE)))
641 {
642 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM);
643 TX_BLK_SET_FLAG(pTxBlk,
644 fTX_bForceNonQoS);
645 }
646 }
647
648 if ((IS_HT_RATE(pMacEntry) == FALSE) && (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE))) { /* Currently piggy-back only support when peer is operate in b/g mode. */
649 TX_BLK_SET_FLAG(pTxBlk, fTX_bPiggyBack);
650 }
651
652 if (RTMP_GET_PACKET_MOREDATA(pPacket)) {
653 TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData);
654 }
655 } else if (pTxBlk->TxFrameType == TX_FRAG_FRAME) {
656 TX_BLK_SET_FLAG(pTxBlk, fTX_bAllowFrag);
657 }
658
659 pMacEntry->DebugTxCount++;
660 }
661
662 return TRUE;
663}
664
665BOOLEAN CanDoAggregateTransmit(struct rt_rtmp_adapter *pAd,
666 char * pPacket, struct rt_tx_blk *pTxBlk)
667{
668
669 /*DBGPRINT(RT_DEBUG_TRACE, ("Check if can do aggregation! TxFrameType=%d!\n", pTxBlk->TxFrameType)); */
670
671 if (RTMP_GET_PACKET_WCID(pPacket) == MCAST_WCID)
672 return FALSE;
673
674 if (RTMP_GET_PACKET_DHCP(pPacket) ||
675 RTMP_GET_PACKET_EAPOL(pPacket) || RTMP_GET_PACKET_WAI(pPacket))
676 return FALSE;
677
678 if ((pTxBlk->TxFrameType == TX_AMSDU_FRAME) && ((pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket)) > (RX_BUFFER_AGGRESIZE - 100))) { /* For AMSDU, allow the packets with total length < max-amsdu size */
679 return FALSE;
680 }
681
682 if ((pTxBlk->TxFrameType == TX_RALINK_FRAME) && (pTxBlk->TxPacketList.Number == 2)) { /* For RALINK-Aggregation, allow two frames in one batch. */
683 return FALSE;
684 }
685
686 if ((INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) /* must be unicast to AP */
687 return TRUE;
688 else
689 return FALSE;
690
691}
692
693/*
694 ========================================================================
695
696 Routine Description:
697 To do the enqueue operation and extract the first item of waiting
698 list. If a number of available shared memory segments could meet
699 the request of extracted item, the extracted item will be fragmented
700 into shared memory segments.
701
702 Arguments:
703 pAd Pointer to our adapter
704 pQueue Pointer to Waiting Queue
705
706 Return Value:
707 None
708
709 IRQL = DISPATCH_LEVEL
710
711 Note:
712
713 ========================================================================
714*/
715void RTMPDeQueuePacket(struct rt_rtmp_adapter *pAd, IN BOOLEAN bIntContext, u8 QIdx, /* BulkOutPipeId */
716 u8 Max_Tx_Packets)
717{
718 struct rt_queue_entry *pEntry = NULL;
719 void *pPacket;
720 int Status = NDIS_STATUS_SUCCESS;
721 u8 Count = 0;
722 struct rt_queue_header *pQueue;
723 unsigned long FreeNumber[NUM_OF_TX_RING];
724 u8 QueIdx, sQIdx, eQIdx;
725 unsigned long IrqFlags = 0;
726 BOOLEAN hasTxDesc = FALSE;
727 struct rt_tx_blk TxBlk;
728 struct rt_tx_blk *pTxBlk;
729
730 if (QIdx == NUM_OF_TX_RING) {
731 sQIdx = 0;
732 eQIdx = 3; /* 4 ACs, start from 0. */
733 } else {
734 sQIdx = eQIdx = QIdx;
735 }
736
737 for (QueIdx = sQIdx; QueIdx <= eQIdx; QueIdx++) {
738 Count = 0;
739
740 RTMP_START_DEQUEUE(pAd, QueIdx, IrqFlags);
741
742 while (1) {
743 if ((RTMP_TEST_FLAG
744 (pAd,
745 (fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS |
746 fRTMP_ADAPTER_RADIO_OFF |
747 fRTMP_ADAPTER_RESET_IN_PROGRESS |
748 fRTMP_ADAPTER_HALT_IN_PROGRESS |
749 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
750 RTMP_STOP_DEQUEUE(pAd, QueIdx, IrqFlags);
751 return;
752 }
753
754 if (Count >= Max_Tx_Packets)
755 break;
756
757 DEQUEUE_LOCK(&pAd->irq_lock, bIntContext, IrqFlags);
758 if (&pAd->TxSwQueue[QueIdx] == NULL) {
759 DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext,
760 IrqFlags);
761 break;
762 }
763#ifdef RTMP_MAC_PCI
764 FreeNumber[QueIdx] = GET_TXRING_FREENO(pAd, QueIdx);
765
766 if (FreeNumber[QueIdx] <= 5) {
767 /* free Tx(QueIdx) resources */
768 RTMPFreeTXDUponTxDmaDone(pAd, QueIdx);
769 FreeNumber[QueIdx] =
770 GET_TXRING_FREENO(pAd, QueIdx);
771 }
772#endif /* RTMP_MAC_PCI // */
773
774 /* probe the Queue Head */
775 pQueue = &pAd->TxSwQueue[QueIdx];
776 pEntry = pQueue->Head;
777 if (pEntry == NULL) {
778 DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext,
779 IrqFlags);
780 break;
781 }
782
783 pTxBlk = &TxBlk;
784 NdisZeroMemory((u8 *)pTxBlk, sizeof(struct rt_tx_blk));
785 /*InitializeQueueHeader(&pTxBlk->TxPacketList); // Didn't need it because we already memzero it. */
786 pTxBlk->QueIdx = QueIdx;
787
788 pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
789
790 /* Early check to make sure we have enoguh Tx Resource. */
791 hasTxDesc =
792 RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk,
793 FreeNumber[QueIdx],
794 pPacket);
795 if (!hasTxDesc) {
796 pAd->PrivateInfo.TxRingFullCnt++;
797
798 DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext,
799 IrqFlags);
800
801 break;
802 }
803
804 pTxBlk->TxFrameType = TxPktClassification(pAd, pPacket);
805 pEntry = RemoveHeadQueue(pQueue);
806 pTxBlk->TotalFrameNum++;
807 pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); /* The real fragment number maybe vary */
808 pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket);
809 pTxBlk->pPacket = pPacket;
810 InsertTailQueue(&pTxBlk->TxPacketList,
811 PACKET_TO_QUEUE_ENTRY(pPacket));
812
813 if (pTxBlk->TxFrameType == TX_RALINK_FRAME
814 || pTxBlk->TxFrameType == TX_AMSDU_FRAME) {
815 /* Enhance SW Aggregation Mechanism */
816 if (NEED_QUEUE_BACK_FOR_AGG
817 (pAd, QueIdx, FreeNumber[QueIdx],
818 pTxBlk->TxFrameType)) {
819 InsertHeadQueue(pQueue,
820 PACKET_TO_QUEUE_ENTRY
821 (pPacket));
822 DEQUEUE_UNLOCK(&pAd->irq_lock,
823 bIntContext, IrqFlags);
824 break;
825 }
826
827 do {
828 pEntry = pQueue->Head;
829 if (pEntry == NULL)
830 break;
831
832 /* For TX_AMSDU_FRAME/TX_RALINK_FRAME, Need to check if next pakcet can do aggregation. */
833 pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
834 FreeNumber[QueIdx] =
835 GET_TXRING_FREENO(pAd, QueIdx);
836 hasTxDesc =
837 RTMP_HAS_ENOUGH_FREE_DESC(pAd,
838 pTxBlk,
839 FreeNumber
840 [QueIdx],
841 pPacket);
842 if ((hasTxDesc == FALSE)
843 ||
844 (CanDoAggregateTransmit
845 (pAd, pPacket, pTxBlk) == FALSE))
846 break;
847
848 /*Remove the packet from the TxSwQueue and insert into pTxBlk */
849 pEntry = RemoveHeadQueue(pQueue);
850 ASSERT(pEntry);
851 pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
852 pTxBlk->TotalFrameNum++;
853 pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); /* The real fragment number maybe vary */
854 pTxBlk->TotalFrameLen +=
855 GET_OS_PKT_LEN(pPacket);
856 InsertTailQueue(&pTxBlk->TxPacketList,
857 PACKET_TO_QUEUE_ENTRY
858 (pPacket));
859 } while (1);
860
861 if (pTxBlk->TxPacketList.Number == 1)
862 pTxBlk->TxFrameType = TX_LEGACY_FRAME;
863 }
864#ifdef RTMP_MAC_USB
865 DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
866#endif /* RTMP_MAC_USB // */
867 Count += pTxBlk->TxPacketList.Number;
868
869 /* Do HardTransmit now. */
870 Status = STAHardTransmit(pAd, pTxBlk, QueIdx);
871
872#ifdef RTMP_MAC_PCI
873 DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags);
874 /* static rate also need NICUpdateFifoStaCounters() function. */
875 /*if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)) */
876 NICUpdateFifoStaCounters(pAd);
877#endif /* RTMP_MAC_PCI // */
878
879 }
880
881 RTMP_STOP_DEQUEUE(pAd, QueIdx, IrqFlags);
882
883#ifdef RTMP_MAC_USB
884 if (!hasTxDesc)
885 RTUSBKickBulkOut(pAd);
886#endif /* RTMP_MAC_USB // */
887 }
888
889}
890
891/*
892 ========================================================================
893
894 Routine Description:
895 Calculates the duration which is required to transmit out frames
896 with given size and specified rate.
897
898 Arguments:
899 pAd Pointer to our adapter
900 Rate Transmit rate
901 Size Frame size in units of byte
902
903 Return Value:
904 Duration number in units of usec
905
906 IRQL = PASSIVE_LEVEL
907 IRQL = DISPATCH_LEVEL
908
909 Note:
910
911 ========================================================================
912*/
913u16 RTMPCalcDuration(struct rt_rtmp_adapter *pAd, u8 Rate, unsigned long Size)
914{
915 unsigned long Duration = 0;
916
917 if (Rate < RATE_FIRST_OFDM_RATE) /* CCK */
918 {
919 if ((Rate > RATE_1)
920 && OPSTATUS_TEST_FLAG(pAd,
921 fOP_STATUS_SHORT_PREAMBLE_INUSED))
922 Duration = 96; /* 72+24 preamble+plcp */
923 else
924 Duration = 192; /* 144+48 preamble+plcp */
925
926 Duration += (u16)((Size << 4) / RateIdTo500Kbps[Rate]);
927 if ((Size << 4) % RateIdTo500Kbps[Rate])
928 Duration++;
929 } else if (Rate <= RATE_LAST_OFDM_RATE) /* OFDM rates */
930 {
931 Duration = 20 + 6; /* 16+4 preamble+plcp + Signal Extension */
932 Duration +=
933 4 * (u16)((11 + Size * 4) / RateIdTo500Kbps[Rate]);
934 if ((11 + Size * 4) % RateIdTo500Kbps[Rate])
935 Duration += 4;
936 } else /*mimo rate */
937 {
938 Duration = 20 + 6; /* 16+4 preamble+plcp + Signal Extension */
939 }
940
941 return (u16)Duration;
942}
943
944/*
945 ========================================================================
946
947 Routine Description:
948 Calculates the duration which is required to transmit out frames
949 with given size and specified rate.
950
951 Arguments:
952 pTxWI Pointer to head of each MPDU to HW.
953 Ack Setting for Ack requirement bit
954 Fragment Setting for Fragment bit
955 RetryMode Setting for retry mode
956 Ifs Setting for IFS gap
957 Rate Setting for transmit rate
958 Service Setting for service
959 Length Frame length
960 TxPreamble Short or Long preamble when using CCK rates
961 QueIdx - 0-3, according to 802.11e/d4.4 June/2003
962
963 Return Value:
964 None
965
966 IRQL = PASSIVE_LEVEL
967 IRQL = DISPATCH_LEVEL
968
969 See also : BASmartHardTransmit() !
970
971 ========================================================================
972*/
973void RTMPWriteTxWI(struct rt_rtmp_adapter *pAd, struct rt_txwi * pOutTxWI, IN BOOLEAN FRAG, IN BOOLEAN CFACK, IN BOOLEAN InsTimestamp, IN BOOLEAN AMPDU, IN BOOLEAN Ack, IN BOOLEAN NSeq, /* HW new a sequence. */
974 u8 BASize,
975 u8 WCID,
976 unsigned long Length,
977 u8 PID,
978 u8 TID,
979 u8 TxRate,
980 u8 Txopmode,
981 IN BOOLEAN CfAck, IN HTTRANSMIT_SETTING * pTransmit)
982{
983 struct rt_mac_table_entry *pMac = NULL;
984 struct rt_txwi TxWI;
985 struct rt_txwi * pTxWI;
986
987 if (WCID < MAX_LEN_OF_MAC_TABLE)
988 pMac = &pAd->MacTab.Content[WCID];
989
990 /* */
991 /* Always use Long preamble before verifiation short preamble functionality works well. */
992 /* Todo: remove the following line if short preamble functionality works */
993 /* */
994 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
995 NdisZeroMemory(&TxWI, TXWI_SIZE);
996 pTxWI = &TxWI;
997
998 pTxWI->FRAG = FRAG;
999
1000 pTxWI->CFACK = CFACK;
1001 pTxWI->TS = InsTimestamp;
1002 pTxWI->AMPDU = AMPDU;
1003 pTxWI->ACK = Ack;
1004 pTxWI->txop = Txopmode;
1005
1006 pTxWI->NSEQ = NSeq;
1007 /* John tune the performace with Intel Client in 20 MHz performance */
1008 BASize = pAd->CommonCfg.TxBASize;
1009 if (pAd->MACVersion == 0x28720200) {
1010 if (BASize > 13)
1011 BASize = 13;
1012 } else {
1013 if (BASize > 7)
1014 BASize = 7;
1015 }
1016 pTxWI->BAWinSize = BASize;
1017 pTxWI->ShortGI = pTransmit->field.ShortGI;
1018 pTxWI->STBC = pTransmit->field.STBC;
1019
1020 pTxWI->WirelessCliID = WCID;
1021 pTxWI->MPDUtotalByteCount = Length;
1022 pTxWI->PacketId = PID;
1023
1024 /* If CCK or OFDM, BW must be 20 */
1025 pTxWI->BW =
1026 (pTransmit->field.MODE <=
1027 MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
1028
1029 pTxWI->MCS = pTransmit->field.MCS;
1030 pTxWI->PHYMODE = pTransmit->field.MODE;
1031 pTxWI->CFACK = CfAck;
1032
1033 if (pMac) {
1034 if (pAd->CommonCfg.bMIMOPSEnable) {
1035 if ((pMac->MmpsMode == MMPS_DYNAMIC)
1036 && (pTransmit->field.MCS > 7)) {
1037 /* Dynamic MIMO Power Save Mode */
1038 pTxWI->MIMOps = 1;
1039 } else if (pMac->MmpsMode == MMPS_STATIC) {
1040 /* Static MIMO Power Save Mode */
1041 if (pTransmit->field.MODE >= MODE_HTMIX
1042 && pTransmit->field.MCS > 7) {
1043 pTxWI->MCS = 7;
1044 pTxWI->MIMOps = 0;
1045 }
1046 }
1047 }
1048 /*pTxWI->MIMOps = (pMac->PsMode == PWR_MMPS)? 1:0; */
1049 if (pMac->bIAmBadAtheros
1050 && (pMac->WepStatus != Ndis802_11WEPDisabled)) {
1051 pTxWI->MpduDensity = 7;
1052 } else {
1053 pTxWI->MpduDensity = pMac->MpduDensity;
1054 }
1055 }
1056
1057 pTxWI->PacketId = pTxWI->MCS;
1058 NdisMoveMemory(pOutTxWI, &TxWI, sizeof(struct rt_txwi));
1059}
1060
1061void RTMPWriteTxWI_Data(struct rt_rtmp_adapter *pAd,
1062 struct rt_txwi * pTxWI, struct rt_tx_blk *pTxBlk)
1063{
1064 HTTRANSMIT_SETTING *pTransmit;
1065 struct rt_mac_table_entry *pMacEntry;
1066 u8 BASize;
1067
1068 ASSERT(pTxWI);
1069
1070 pTransmit = pTxBlk->pTransmit;
1071 pMacEntry = pTxBlk->pMacEntry;
1072
1073 /* */
1074 /* Always use Long preamble before verifiation short preamble functionality works well. */
1075 /* Todo: remove the following line if short preamble functionality works */
1076 /* */
1077 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
1078 NdisZeroMemory(pTxWI, TXWI_SIZE);
1079
1080 pTxWI->FRAG = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag);
1081 pTxWI->ACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAckRequired);
1082 pTxWI->txop = pTxBlk->FrameGap;
1083
1084 pTxWI->WirelessCliID = pTxBlk->Wcid;
1085
1086 pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
1087 pTxWI->CFACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bPiggyBack);
1088
1089 /* If CCK or OFDM, BW must be 20 */
1090 pTxWI->BW =
1091 (pTransmit->field.MODE <=
1092 MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
1093 pTxWI->AMPDU = ((pTxBlk->TxFrameType == TX_AMPDU_FRAME) ? TRUE : FALSE);
1094
1095 /* John tune the performace with Intel Client in 20 MHz performance */
1096 BASize = pAd->CommonCfg.TxBASize;
1097 if ((pTxBlk->TxFrameType == TX_AMPDU_FRAME) && (pMacEntry)) {
1098 u8 RABAOriIdx = 0; /*The RA's BA Originator table index. */
1099
1100 RABAOriIdx =
1101 pTxBlk->pMacEntry->BAOriWcidArray[pTxBlk->UserPriority];
1102 BASize = pAd->BATable.BAOriEntry[RABAOriIdx].BAWinSize;
1103 }
1104
1105 pTxWI->TxBF = pTransmit->field.TxBF;
1106 pTxWI->BAWinSize = BASize;
1107 pTxWI->ShortGI = pTransmit->field.ShortGI;
1108 pTxWI->STBC = pTransmit->field.STBC;
1109
1110 pTxWI->MCS = pTransmit->field.MCS;
1111 pTxWI->PHYMODE = pTransmit->field.MODE;
1112
1113 if (pMacEntry) {
1114 if ((pMacEntry->MmpsMode == MMPS_DYNAMIC)
1115 && (pTransmit->field.MCS > 7)) {
1116 /* Dynamic MIMO Power Save Mode */
1117 pTxWI->MIMOps = 1;
1118 } else if (pMacEntry->MmpsMode == MMPS_STATIC) {
1119 /* Static MIMO Power Save Mode */
1120 if (pTransmit->field.MODE >= MODE_HTMIX
1121 && pTransmit->field.MCS > 7) {
1122 pTxWI->MCS = 7;
1123 pTxWI->MIMOps = 0;
1124 }
1125 }
1126
1127 if (pMacEntry->bIAmBadAtheros
1128 && (pMacEntry->WepStatus != Ndis802_11WEPDisabled)) {
1129 pTxWI->MpduDensity = 7;
1130 } else {
1131 pTxWI->MpduDensity = pMacEntry->MpduDensity;
1132 }
1133 }
1134
1135 /* for rate adapation */
1136 pTxWI->PacketId = pTxWI->MCS;
1137}
1138
1139void RTMPWriteTxWI_Cache(struct rt_rtmp_adapter *pAd,
1140 struct rt_txwi * pTxWI, struct rt_tx_blk *pTxBlk)
1141{
1142 PHTTRANSMIT_SETTING /*pTxHTPhyMode, */ pTransmit;
1143 struct rt_mac_table_entry *pMacEntry;
1144
1145 /* */
1146 /* update TXWI */
1147 /* */
1148 pMacEntry = pTxBlk->pMacEntry;
1149 pTransmit = pTxBlk->pTransmit;
1150
1151 /*if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)) */
1152 /*if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pMacEntry)) */
1153 /*if (TX_BLK_TEST_FLAG(pTxBlk, fTX_AutoRateSwitch)) */
1154 if (pMacEntry->bAutoTxRateSwitch) {
1155 pTxWI->txop = IFS_HTTXOP;
1156
1157 /* If CCK or OFDM, BW must be 20 */
1158 pTxWI->BW =
1159 (pTransmit->field.MODE <=
1160 MODE_OFDM) ? (BW_20) : (pTransmit->field.BW);
1161 pTxWI->ShortGI = pTransmit->field.ShortGI;
1162 pTxWI->STBC = pTransmit->field.STBC;
1163
1164 pTxWI->MCS = pTransmit->field.MCS;
1165 pTxWI->PHYMODE = pTransmit->field.MODE;
1166
1167 /* set PID for TxRateSwitching */
1168 pTxWI->PacketId = pTransmit->field.MCS;
1169 }
1170
1171 pTxWI->AMPDU = ((pMacEntry->NoBADataCountDown == 0) ? TRUE : FALSE);
1172 pTxWI->MIMOps = 0;
1173
1174 if (pAd->CommonCfg.bMIMOPSEnable) {
1175 /* MIMO Power Save Mode */
1176 if ((pMacEntry->MmpsMode == MMPS_DYNAMIC)
1177 && (pTransmit->field.MCS > 7)) {
1178 /* Dynamic MIMO Power Save Mode */
1179 pTxWI->MIMOps = 1;
1180 } else if (pMacEntry->MmpsMode == MMPS_STATIC) {
1181 /* Static MIMO Power Save Mode */
1182 if ((pTransmit->field.MODE >= MODE_HTMIX)
1183 && (pTransmit->field.MCS > 7)) {
1184 pTxWI->MCS = 7;
1185 pTxWI->MIMOps = 0;
1186 }
1187 }
1188 }
1189
1190 pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
1191
1192}
1193
1194/* should be called only when - */
1195/* 1. MEADIA_CONNECTED */
1196/* 2. AGGREGATION_IN_USED */
1197/* 3. Fragmentation not in used */
1198/* 4. either no previous frame (pPrevAddr1=NULL) .OR. previoud frame is aggregatible */
1199BOOLEAN TxFrameIsAggregatible(struct rt_rtmp_adapter *pAd,
1200 u8 *pPrevAddr1, u8 *p8023hdr)
1201{
1202
1203 /* can't aggregate EAPOL (802.1x) frame */
1204 if ((p8023hdr[12] == 0x88) && (p8023hdr[13] == 0x8e))
1205 return FALSE;
1206
1207 /* can't aggregate multicast/broadcast frame */
1208 if (p8023hdr[0] & 0x01)
1209 return FALSE;
1210
1211 if (INFRA_ON(pAd)) /* must be unicast to AP */
1212 return TRUE;
1213 else if ((pPrevAddr1 == NULL) || MAC_ADDR_EQUAL(pPrevAddr1, p8023hdr)) /* unicast to same STA */
1214 return TRUE;
1215 else
1216 return FALSE;
1217}
1218
1219/*
1220 ========================================================================
1221
1222 Routine Description:
1223 Check the MSDU Aggregation policy
1224 1.HT aggregation is A-MSDU
1225 2.legaacy rate aggregation is software aggregation by Ralink.
1226
1227 Arguments:
1228
1229 Return Value:
1230
1231 Note:
1232
1233 ========================================================================
1234*/
1235BOOLEAN PeerIsAggreOn(struct rt_rtmp_adapter *pAd,
1236 unsigned long TxRate, struct rt_mac_table_entry *pMacEntry)
1237{
1238 unsigned long AFlags =
1239 (fCLIENT_STATUS_AMSDU_INUSED | fCLIENT_STATUS_AGGREGATION_CAPABLE);
1240
1241 if (pMacEntry != NULL && CLIENT_STATUS_TEST_FLAG(pMacEntry, AFlags)) {
1242 if (pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX) {
1243 return TRUE;
1244 }
1245#ifdef AGGREGATION_SUPPORT
1246 if (TxRate >= RATE_6 && pAd->CommonCfg.bAggregationCapable && (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)))) { /* legacy Ralink Aggregation support */
1247 return TRUE;
1248 }
1249#endif /* AGGREGATION_SUPPORT // */
1250 }
1251
1252 return FALSE;
1253
1254}
1255
1256/*
1257 ========================================================================
1258
1259 Routine Description:
1260 Check and fine the packet waiting in SW queue with highest priority
1261
1262 Arguments:
1263 pAd Pointer to our adapter
1264
1265 Return Value:
1266 pQueue Pointer to Waiting Queue
1267
1268 IRQL = DISPATCH_LEVEL
1269
1270 Note:
1271
1272 ========================================================================
1273*/
1274struct rt_queue_header *RTMPCheckTxSwQueue(struct rt_rtmp_adapter *pAd, u8 *pQueIdx)
1275{
1276
1277 unsigned long Number;
1278 /* 2004-11-15 to be removed. test aggregation only */
1279/* if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)) && (*pNumber < 2)) */
1280/* return NULL; */
1281
1282 Number = pAd->TxSwQueue[QID_AC_BK].Number
1283 + pAd->TxSwQueue[QID_AC_BE].Number
1284 + pAd->TxSwQueue[QID_AC_VI].Number
1285 + pAd->TxSwQueue[QID_AC_VO].Number;
1286
1287 if (pAd->TxSwQueue[QID_AC_VO].Head != NULL) {
1288 *pQueIdx = QID_AC_VO;
1289 return (&pAd->TxSwQueue[QID_AC_VO]);
1290 } else if (pAd->TxSwQueue[QID_AC_VI].Head != NULL) {
1291 *pQueIdx = QID_AC_VI;
1292 return (&pAd->TxSwQueue[QID_AC_VI]);
1293 } else if (pAd->TxSwQueue[QID_AC_BE].Head != NULL) {
1294 *pQueIdx = QID_AC_BE;
1295 return (&pAd->TxSwQueue[QID_AC_BE]);
1296 } else if (pAd->TxSwQueue[QID_AC_BK].Head != NULL) {
1297 *pQueIdx = QID_AC_BK;
1298 return (&pAd->TxSwQueue[QID_AC_BK]);
1299 }
1300 /* No packet pending in Tx Sw queue */
1301 *pQueIdx = QID_AC_BK;
1302
1303 return (NULL);
1304}
1305
1306/*
1307 ========================================================================
1308
1309 Routine Description:
1310 Suspend MSDU transmission
1311
1312 Arguments:
1313 pAd Pointer to our adapter
1314
1315 Return Value:
1316 None
1317
1318 Note:
1319
1320 ========================================================================
1321*/
1322void RTMPSuspendMsduTransmission(struct rt_rtmp_adapter *pAd)
1323{
1324 DBGPRINT(RT_DEBUG_TRACE, ("SCANNING, suspend MSDU transmission ...\n"));
1325
1326 /* */
1327 /* Before BSS_SCAN_IN_PROGRESS, we need to keep Current R66 value and */
1328 /* use Lowbound as R66 value on ScanNextChannel(...) */
1329 /* */
1330 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66,
1331 &pAd->BbpTuning.R66CurrentValue);
1332
1333 /* set BBP_R66 to 0x30/0x40 when scanning (AsicSwitchChannel will set R66 according to channel when scanning) */
1334 /*RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x26 + GET_LNA_GAIN(pAd))); */
1335 RTMPSetAGCInitValue(pAd, BW_20);
1336
1337 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
1338 /*RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x000f0000); // abort all TX rings */
1339}
1340
1341/*
1342 ========================================================================
1343
1344 Routine Description:
1345 Resume MSDU transmission
1346
1347 Arguments:
1348 pAd Pointer to our adapter
1349
1350 Return Value:
1351 None
1352
1353 IRQL = DISPATCH_LEVEL
1354
1355 Note:
1356
1357 ========================================================================
1358*/
1359void RTMPResumeMsduTransmission(struct rt_rtmp_adapter *pAd)
1360{
1361/* u8 IrqState; */
1362
1363 DBGPRINT(RT_DEBUG_TRACE, ("SCAN done, resume MSDU transmission ...\n"));
1364
1365 /* After finish BSS_SCAN_IN_PROGRESS, we need to restore Current R66 value */
1366 /* R66 should not be 0 */
1367 if (pAd->BbpTuning.R66CurrentValue == 0) {
1368 pAd->BbpTuning.R66CurrentValue = 0x38;
1369 DBGPRINT_ERR("RTMPResumeMsduTransmission, R66CurrentValue=0...\n");
1370 }
1371
1372 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66,
1373 pAd->BbpTuning.R66CurrentValue);
1374
1375 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
1376/* sample, for IRQ LOCK to SEM LOCK */
1377/* IrqState = pAd->irq_disabled; */
1378/* if (IrqState) */
1379/* RTMPDeQueuePacket(pAd, TRUE, NUM_OF_TX_RING, MAX_TX_PROCESS); */
1380/* else */
1381 RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
1382}
1383
1384u32 deaggregate_AMSDU_announce(struct rt_rtmp_adapter *pAd,
1385 void *pPacket,
1386 u8 *pData, unsigned long DataSize)
1387{
1388 u16 PayloadSize;
1389 u16 SubFrameSize;
1390 struct rt_header_802_3 * pAMSDUsubheader;
1391 u32 nMSDU;
1392 u8 Header802_3[14];
1393
1394 u8 *pPayload, *pDA, *pSA, *pRemovedLLCSNAP;
1395 void *pClonePacket;
1396
1397 nMSDU = 0;
1398
1399 while (DataSize > LENGTH_802_3) {
1400
1401 nMSDU++;
1402
1403 /*hex_dump("subheader", pData, 64); */
1404 pAMSDUsubheader = (struct rt_header_802_3 *) pData;
1405 /*pData += LENGTH_802_3; */
1406 PayloadSize =
1407 pAMSDUsubheader->Octet[1] +
1408 (pAMSDUsubheader->Octet[0] << 8);
1409 SubFrameSize = PayloadSize + LENGTH_802_3;
1410
1411 if ((DataSize < SubFrameSize) || (PayloadSize > 1518)) {
1412 break;
1413 }
1414 /*DBGPRINT(RT_DEBUG_TRACE,("%d subframe: Size = %d\n", nMSDU, PayloadSize)); */
1415
1416 pPayload = pData + LENGTH_802_3;
1417 pDA = pData;
1418 pSA = pData + MAC_ADDR_LEN;
1419
1420 /* convert to 802.3 header */
1421 CONVERT_TO_802_3(Header802_3, pDA, pSA, pPayload, PayloadSize,
1422 pRemovedLLCSNAP);
1423
1424 if ((Header802_3[12] == 0x88) && (Header802_3[13] == 0x8E)) {
1425 /* avoid local heap overflow, use dyanamic allocation */
1426 struct rt_mlme_queue_elem *Elem =
1427 kmalloc(sizeof(struct rt_mlme_queue_elem),
1428 MEM_ALLOC_FLAG);
1429 if (Elem != NULL) {
1430 memmove(Elem->Msg +
1431 (LENGTH_802_11 + LENGTH_802_1_H),
1432 pPayload, PayloadSize);
1433 Elem->MsgLen =
1434 LENGTH_802_11 + LENGTH_802_1_H +
1435 PayloadSize;
1436 /*WpaEAPOLKeyAction(pAd, Elem); */
1437 REPORT_MGMT_FRAME_TO_MLME(pAd, BSSID_WCID,
1438 Elem->Msg,
1439 Elem->MsgLen, 0, 0, 0,
1440 0);
1441 kfree(Elem);
1442 }
1443 }
1444
1445 {
1446 if (pRemovedLLCSNAP) {
1447 pPayload -= LENGTH_802_3;
1448 PayloadSize += LENGTH_802_3;
1449 NdisMoveMemory(pPayload, &Header802_3[0],
1450 LENGTH_802_3);
1451 }
1452 }
1453
1454 pClonePacket = ClonePacket(pAd, pPacket, pPayload, PayloadSize);
1455 if (pClonePacket) {
1456 ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pClonePacket,
1457 RTMP_GET_PACKET_IF
1458 (pPacket));
1459 }
1460
1461 /* A-MSDU has padding to multiple of 4 including subframe header. */
1462 /* align SubFrameSize up to multiple of 4 */
1463 SubFrameSize = (SubFrameSize + 3) & (~0x3);
1464
1465 if (SubFrameSize > 1528 || SubFrameSize < 32) {
1466 break;
1467 }
1468
1469 if (DataSize > SubFrameSize) {
1470 pData += SubFrameSize;
1471 DataSize -= SubFrameSize;
1472 } else {
1473 /* end of A-MSDU */
1474 DataSize = 0;
1475 }
1476 }
1477
1478 /* finally release original rx packet */
1479 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
1480
1481 return nMSDU;
1482}
1483
1484u32 BA_Reorder_AMSDU_Announce(struct rt_rtmp_adapter *pAd, void *pPacket)
1485{
1486 u8 *pData;
1487 u16 DataSize;
1488 u32 nMSDU = 0;
1489
1490 pData = (u8 *)GET_OS_PKT_DATAPTR(pPacket);
1491 DataSize = (u16)GET_OS_PKT_LEN(pPacket);
1492
1493 nMSDU = deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize);
1494
1495 return nMSDU;
1496}
1497
1498/*
1499 ==========================================================================
1500 Description:
1501 Look up the MAC address in the MAC table. Return NULL if not found.
1502 Return:
1503 pEntry - pointer to the MAC entry; NULL is not found
1504 ==========================================================================
1505*/
1506struct rt_mac_table_entry *MacTableLookup(struct rt_rtmp_adapter *pAd, u8 *pAddr)
1507{
1508 unsigned long HashIdx;
1509 struct rt_mac_table_entry *pEntry = NULL;
1510
1511 HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
1512 pEntry = pAd->MacTab.Hash[HashIdx];
1513
1514 while (pEntry
1515 && (pEntry->ValidAsCLI || pEntry->ValidAsWDS
1516 || pEntry->ValidAsApCli || pEntry->ValidAsMesh)) {
1517 if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr)) {
1518 break;
1519 } else
1520 pEntry = pEntry->pNext;
1521 }
1522
1523 return pEntry;
1524}
1525
1526struct rt_mac_table_entry *MacTableInsertEntry(struct rt_rtmp_adapter *pAd,
1527 u8 *pAddr,
1528 u8 apidx, IN BOOLEAN CleanAll)
1529{
1530 u8 HashIdx;
1531 int i, FirstWcid;
1532 struct rt_mac_table_entry *pEntry = NULL, *pCurrEntry;
1533/* u16 offset; */
1534/* unsigned long addr; */
1535
1536 /* if FULL, return */
1537 if (pAd->MacTab.Size >= MAX_LEN_OF_MAC_TABLE)
1538 return NULL;
1539
1540 FirstWcid = 1;
1541
1542 if (pAd->StaCfg.BssType == BSS_INFRA)
1543 FirstWcid = 2;
1544
1545 /* allocate one MAC entry */
1546 NdisAcquireSpinLock(&pAd->MacTabLock);
1547 for (i = FirstWcid; i < MAX_LEN_OF_MAC_TABLE; i++) /* skip entry#0 so that "entry index == AID" for fast lookup */
1548 {
1549 /* pick up the first available vacancy */
1550 if ((pAd->MacTab.Content[i].ValidAsCLI == FALSE) &&
1551 (pAd->MacTab.Content[i].ValidAsWDS == FALSE) &&
1552 (pAd->MacTab.Content[i].ValidAsApCli == FALSE) &&
1553 (pAd->MacTab.Content[i].ValidAsMesh == FALSE)
1554 ) {
1555 pEntry = &pAd->MacTab.Content[i];
1556 if (CleanAll == TRUE) {
1557 pEntry->MaxSupportedRate = RATE_11;
1558 pEntry->CurrTxRate = RATE_11;
1559 NdisZeroMemory(pEntry, sizeof(struct rt_mac_table_entry));
1560 pEntry->PairwiseKey.KeyLen = 0;
1561 pEntry->PairwiseKey.CipherAlg = CIPHER_NONE;
1562 }
1563 {
1564 {
1565 pEntry->ValidAsCLI = TRUE;
1566 pEntry->ValidAsWDS = FALSE;
1567 pEntry->ValidAsApCli = FALSE;
1568 pEntry->ValidAsMesh = FALSE;
1569 pEntry->ValidAsDls = FALSE;
1570 }
1571 }
1572
1573 pEntry->bIAmBadAtheros = FALSE;
1574 pEntry->pAd = pAd;
1575 pEntry->CMTimerRunning = FALSE;
1576 pEntry->EnqueueEapolStartTimerRunning =
1577 EAPOL_START_DISABLE;
1578 pEntry->RSNIE_Len = 0;
1579 NdisZeroMemory(pEntry->R_Counter,
1580 sizeof(pEntry->R_Counter));
1581 pEntry->ReTryCounter = PEER_MSG1_RETRY_TIMER_CTR;
1582
1583 if (pEntry->ValidAsMesh)
1584 pEntry->apidx =
1585 (apidx - MIN_NET_DEVICE_FOR_MESH);
1586 else if (pEntry->ValidAsApCli)
1587 pEntry->apidx =
1588 (apidx - MIN_NET_DEVICE_FOR_APCLI);
1589 else if (pEntry->ValidAsWDS)
1590 pEntry->apidx =
1591 (apidx - MIN_NET_DEVICE_FOR_WDS);
1592 else
1593 pEntry->apidx = apidx;
1594
1595 {
1596 {
1597 pEntry->AuthMode = pAd->StaCfg.AuthMode;
1598 pEntry->WepStatus =
1599 pAd->StaCfg.WepStatus;
1600 pEntry->PrivacyFilter =
1601 Ndis802_11PrivFilterAcceptAll;
1602#ifdef RTMP_MAC_PCI
1603 AsicRemovePairwiseKeyEntry(pAd,
1604 pEntry->
1605 apidx,
1606 (u8)i);
1607#endif /* RTMP_MAC_PCI // */
1608 }
1609 }
1610
1611 pEntry->GTKState = REKEY_NEGOTIATING;
1612 pEntry->PairwiseKey.KeyLen = 0;
1613 pEntry->PairwiseKey.CipherAlg = CIPHER_NONE;
1614 pEntry->PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1615
1616 pEntry->PMKID_CacheIdx = ENTRY_NOT_FOUND;
1617 COPY_MAC_ADDR(pEntry->Addr, pAddr);
1618 pEntry->Sst = SST_NOT_AUTH;
1619 pEntry->AuthState = AS_NOT_AUTH;
1620 pEntry->Aid = (u16)i; /*0; */
1621 pEntry->CapabilityInfo = 0;
1622 pEntry->PsMode = PWR_ACTIVE;
1623 pEntry->PsQIdleCount = 0;
1624 pEntry->NoDataIdleCount = 0;
1625 pEntry->AssocDeadLine = MAC_TABLE_ASSOC_TIMEOUT;
1626 pEntry->ContinueTxFailCnt = 0;
1627 InitializeQueueHeader(&pEntry->PsQueue);
1628
1629 pAd->MacTab.Size++;
1630 /* Add this entry into ASIC RX WCID search table */
1631 RTMP_STA_ENTRY_ADD(pAd, pEntry);
1632
1633 DBGPRINT(RT_DEBUG_TRACE,
1634 ("MacTableInsertEntry - allocate entry #%d, Total= %d\n",
1635 i, pAd->MacTab.Size));
1636 break;
1637 }
1638 }
1639
1640 /* add this MAC entry into HASH table */
1641 if (pEntry) {
1642 HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
1643 if (pAd->MacTab.Hash[HashIdx] == NULL) {
1644 pAd->MacTab.Hash[HashIdx] = pEntry;
1645 } else {
1646 pCurrEntry = pAd->MacTab.Hash[HashIdx];
1647 while (pCurrEntry->pNext != NULL)
1648 pCurrEntry = pCurrEntry->pNext;
1649 pCurrEntry->pNext = pEntry;
1650 }
1651 }
1652
1653 NdisReleaseSpinLock(&pAd->MacTabLock);
1654 return pEntry;
1655}
1656
1657/*
1658 ==========================================================================
1659 Description:
1660 Delete a specified client from MAC table
1661 ==========================================================================
1662 */
1663BOOLEAN MacTableDeleteEntry(struct rt_rtmp_adapter *pAd,
1664 u16 wcid, u8 *pAddr)
1665{
1666 u16 HashIdx;
1667 struct rt_mac_table_entry *pEntry, *pPrevEntry, *pProbeEntry;
1668 BOOLEAN Cancelled;
1669 /*u16 offset; // unused variable */
1670 /*u8 j; // unused variable */
1671
1672 if (wcid >= MAX_LEN_OF_MAC_TABLE)
1673 return FALSE;
1674
1675 NdisAcquireSpinLock(&pAd->MacTabLock);
1676
1677 HashIdx = MAC_ADDR_HASH_INDEX(pAddr);
1678 /*pEntry = pAd->MacTab.Hash[HashIdx]; */
1679 pEntry = &pAd->MacTab.Content[wcid];
1680
1681 if (pEntry
1682 && (pEntry->ValidAsCLI || pEntry->ValidAsApCli || pEntry->ValidAsWDS
1683 || pEntry->ValidAsMesh)) {
1684 if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr)) {
1685
1686 /* Delete this entry from ASIC on-chip WCID Table */
1687 RTMP_STA_ENTRY_MAC_RESET(pAd, wcid);
1688
1689 /* free resources of BA */
1690 BASessionTearDownALL(pAd, pEntry->Aid);
1691
1692 pPrevEntry = NULL;
1693 pProbeEntry = pAd->MacTab.Hash[HashIdx];
1694 ASSERT(pProbeEntry);
1695
1696 /* update Hash list */
1697 do {
1698 if (pProbeEntry == pEntry) {
1699 if (pPrevEntry == NULL) {
1700 pAd->MacTab.Hash[HashIdx] =
1701 pEntry->pNext;
1702 } else {
1703 pPrevEntry->pNext =
1704 pEntry->pNext;
1705 }
1706 break;
1707 }
1708
1709 pPrevEntry = pProbeEntry;
1710 pProbeEntry = pProbeEntry->pNext;
1711 } while (pProbeEntry);
1712
1713 /* not found ! */
1714 ASSERT(pProbeEntry != NULL);
1715
1716 RTMP_STA_ENTRY_KEY_DEL(pAd, BSS0, wcid);
1717
1718 if (pEntry->EnqueueEapolStartTimerRunning !=
1719 EAPOL_START_DISABLE) {
1720 RTMPCancelTimer(&pEntry->
1721 EnqueueStartForPSKTimer,
1722 &Cancelled);
1723 pEntry->EnqueueEapolStartTimerRunning =
1724 EAPOL_START_DISABLE;
1725 }
1726
1727 NdisZeroMemory(pEntry, sizeof(struct rt_mac_table_entry));
1728 pAd->MacTab.Size--;
1729 DBGPRINT(RT_DEBUG_TRACE,
1730 ("MacTableDeleteEntry1 - Total= %d\n",
1731 pAd->MacTab.Size));
1732 } else {
1733 DBGPRINT(RT_DEBUG_OFF,
1734 ("\n%s: Impossible Wcid = %d !\n",
1735 __func__, wcid));
1736 }
1737 }
1738
1739 NdisReleaseSpinLock(&pAd->MacTabLock);
1740
1741 /*Reset operating mode when no Sta. */
1742 if (pAd->MacTab.Size == 0) {
1743 pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode = 0;
1744 RTMP_UPDATE_PROTECT(pAd); /* edit by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */
1745 }
1746
1747 return TRUE;
1748}
1749
1750/*
1751 ==========================================================================
1752 Description:
1753 This routine reset the entire MAC table. All packets pending in
1754 the power-saving queues are freed here.
1755 ==========================================================================
1756 */
1757void MacTableReset(struct rt_rtmp_adapter *pAd)
1758{
1759 int i;
1760
1761 DBGPRINT(RT_DEBUG_TRACE, ("MacTableReset\n"));
1762 /*NdisAcquireSpinLock(&pAd->MacTabLock); */
1763
1764 for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) {
1765#ifdef RTMP_MAC_PCI
1766 RTMP_STA_ENTRY_MAC_RESET(pAd, i);
1767#endif /* RTMP_MAC_PCI // */
1768 if (pAd->MacTab.Content[i].ValidAsCLI == TRUE) {
1769
1770 /* free resources of BA */
1771 BASessionTearDownALL(pAd, i);
1772
1773 pAd->MacTab.Content[i].ValidAsCLI = FALSE;
1774
1775#ifdef RTMP_MAC_USB
1776 NdisZeroMemory(pAd->MacTab.Content[i].Addr, 6);
1777 RTMP_STA_ENTRY_MAC_RESET(pAd, i);
1778#endif /* RTMP_MAC_USB // */
1779
1780 /*AsicDelWcidTab(pAd, i); */
1781 }
1782 }
1783
1784 return;
1785}
1786
1787/*
1788 ==========================================================================
1789 Description:
1790
1791 IRQL = DISPATCH_LEVEL
1792
1793 ==========================================================================
1794*/
1795void AssocParmFill(struct rt_rtmp_adapter *pAd,
1796 struct rt_mlme_assoc_req *AssocReq,
1797 u8 *pAddr,
1798 u16 CapabilityInfo,
1799 unsigned long Timeout, u16 ListenIntv)
1800{
1801 COPY_MAC_ADDR(AssocReq->Addr, pAddr);
1802 /* Add mask to support 802.11b mode only */
1803 AssocReq->CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO; /* not cf-pollable, not cf-poll-request */
1804 AssocReq->Timeout = Timeout;
1805 AssocReq->ListenIntv = ListenIntv;
1806}
1807
1808/*
1809 ==========================================================================
1810 Description:
1811
1812 IRQL = DISPATCH_LEVEL
1813
1814 ==========================================================================
1815*/
1816void DisassocParmFill(struct rt_rtmp_adapter *pAd,
1817 struct rt_mlme_disassoc_req *DisassocReq,
1818 u8 *pAddr, u16 Reason)
1819{
1820 COPY_MAC_ADDR(DisassocReq->Addr, pAddr);
1821 DisassocReq->Reason = Reason;
1822}
1823
1824/*
1825 ========================================================================
1826
1827 Routine Description:
1828 Check the out going frame, if this is an DHCP or ARP datagram
1829 will be duplicate another frame at low data rate transmit.
1830
1831 Arguments:
1832 pAd Pointer to our adapter
1833 pPacket Pointer to outgoing Ndis frame
1834
1835 Return Value:
1836 TRUE To be duplicate at Low data rate transmit. (1mb)
1837 FALSE Do nothing.
1838
1839 IRQL = DISPATCH_LEVEL
1840
1841 Note:
1842
1843 MAC header + IP Header + UDP Header
1844 14 Bytes 20 Bytes
1845
1846 UDP Header
1847 00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|
1848 Source Port
1849 16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|
1850 Destination Port
1851
1852 port 0x43 means Bootstrap Protocol, server.
1853 Port 0x44 means Bootstrap Protocol, client.
1854
1855 ========================================================================
1856*/
1857
1858BOOLEAN RTMPCheckDHCPFrame(struct rt_rtmp_adapter *pAd, void *pPacket)
1859{
1860 struct rt_packet_info PacketInfo;
1861 unsigned long NumberOfBytesRead = 0;
1862 unsigned long CurrentOffset = 0;
1863 void *pVirtualAddress = NULL;
1864 u32 NdisBufferLength;
1865 u8 *pSrc;
1866 u16 Protocol;
1867 u8 ByteOffset36 = 0;
1868 u8 ByteOffset38 = 0;
1869 BOOLEAN ReadFirstParm = TRUE;
1870
1871 RTMP_QueryPacketInfo(pPacket, &PacketInfo, (u8 **) & pVirtualAddress,
1872 &NdisBufferLength);
1873
1874 NumberOfBytesRead += NdisBufferLength;
1875 pSrc = (u8 *)pVirtualAddress;
1876 Protocol = *(pSrc + 12) * 256 + *(pSrc + 13);
1877
1878 /* */
1879 /* Check DHCP & BOOTP protocol */
1880 /* */
1881 while (NumberOfBytesRead <= PacketInfo.TotalPacketLength) {
1882 if ((NumberOfBytesRead >= 35) && (ReadFirstParm == TRUE)) {
1883 CurrentOffset =
1884 35 - (NumberOfBytesRead - NdisBufferLength);
1885 ByteOffset36 = *(pSrc + CurrentOffset);
1886 ReadFirstParm = FALSE;
1887 }
1888
1889 if (NumberOfBytesRead >= 37) {
1890 CurrentOffset =
1891 37 - (NumberOfBytesRead - NdisBufferLength);
1892 ByteOffset38 = *(pSrc + CurrentOffset);
1893 /*End of Read */
1894 break;
1895 }
1896 return FALSE;
1897 }
1898
1899 /* Check for DHCP & BOOTP protocol */
1900 if ((ByteOffset36 != 0x44) || (ByteOffset38 != 0x43)) {
1901 /* */
1902 /* 2054 (hex 0806) for ARP datagrams */
1903 /* if this packet is not ARP datagrams, then do nothing */
1904 /* ARP datagrams will also be duplicate at 1mb broadcast frames */
1905 /* */
1906 if (Protocol != 0x0806)
1907 return FALSE;
1908 }
1909
1910 return TRUE;
1911}
1912
1913BOOLEAN RTMPCheckEtherType(struct rt_rtmp_adapter *pAd, void *pPacket)
1914{
1915 u16 TypeLen;
1916 u8 Byte0, Byte1;
1917 u8 *pSrcBuf;
1918 u32 pktLen;
1919 u16 srcPort, dstPort;
1920 BOOLEAN status = TRUE;
1921
1922 pSrcBuf = GET_OS_PKT_DATAPTR(pPacket);
1923 pktLen = GET_OS_PKT_LEN(pPacket);
1924
1925 ASSERT(pSrcBuf);
1926
1927 RTMP_SET_PACKET_SPECIFIC(pPacket, 0);
1928
1929 /* get Ethernet protocol field */
1930 TypeLen = (pSrcBuf[12] << 8) | pSrcBuf[13];
1931
1932 pSrcBuf += LENGTH_802_3; /* Skip the Ethernet Header. */
1933
1934 if (TypeLen <= 1500) { /* 802.3, 802.3 LLC */
1935 /*
1936 DestMAC(6) + SrcMAC(6) + Length(2) +
1937 DSAP(1) + SSAP(1) + Control(1) +
1938 if the DSAP = 0xAA, SSAP=0xAA, Contorl = 0x03, it has a 5-bytes SNAP header.
1939 => + SNAP (5, OriginationID(3) + etherType(2))
1940 */
1941 if (pSrcBuf[0] == 0xAA && pSrcBuf[1] == 0xAA
1942 && pSrcBuf[2] == 0x03) {
1943 Sniff2BytesFromNdisBuffer((char *)pSrcBuf, 6,
1944 &Byte0, &Byte1);
1945 RTMP_SET_PACKET_LLCSNAP(pPacket, 1);
1946 TypeLen = (u16)((Byte0 << 8) + Byte1);
1947 pSrcBuf += 8; /* Skip this LLC/SNAP header */
1948 } else {
1949 /*It just has 3-byte LLC header, maybe a legacy ether type frame. we didn't handle it. */
1950 }
1951 }
1952 /* If it's a VLAN packet, get the real Type/Length field. */
1953 if (TypeLen == 0x8100) {
1954 /* 0x8100 means VLAN packets */
1955
1956 /* Dest. MAC Address (6-bytes) +
1957 Source MAC Address (6-bytes) +
1958 Length/Type = 802.1Q Tag Type (2-byte) +
1959 Tag Control Information (2-bytes) +
1960 Length / Type (2-bytes) +
1961 data payload (0-n bytes) +
1962 Pad (0-p bytes) +
1963 Frame Check Sequence (4-bytes) */
1964
1965 RTMP_SET_PACKET_VLAN(pPacket, 1);
1966 Sniff2BytesFromNdisBuffer((char *)pSrcBuf, 2, &Byte0,
1967 &Byte1);
1968 TypeLen = (u16)((Byte0 << 8) + Byte1);
1969
1970 pSrcBuf += 4; /* Skip the VLAN Header. */
1971 }
1972
1973 switch (TypeLen) {
1974 case 0x0800:
1975 {
1976 ASSERT((pktLen > 34));
1977 if (*(pSrcBuf + 9) == 0x11) { /* udp packet */
1978 ASSERT((pktLen > 34)); /* 14 for ethernet header, 20 for IP header */
1979
1980 pSrcBuf += 20; /* Skip the IP header */
1981 srcPort =
1982 OS_NTOHS(get_unaligned
1983 ((u16 *)(pSrcBuf)));
1984 dstPort =
1985 OS_NTOHS(get_unaligned
1986 ((u16 *)(pSrcBuf + 2)));
1987
1988 if ((srcPort == 0x44 && dstPort == 0x43) || (srcPort == 0x43 && dstPort == 0x44)) { /*It's a BOOTP/DHCP packet */
1989 RTMP_SET_PACKET_DHCP(pPacket, 1);
1990 }
1991 }
1992 }
1993 break;
1994 case 0x0806:
1995 {
1996 /*ARP Packet. */
1997 RTMP_SET_PACKET_DHCP(pPacket, 1);
1998 }
1999 break;
2000 case 0x888e:
2001 {
2002 /* EAPOL Packet. */
2003 RTMP_SET_PACKET_EAPOL(pPacket, 1);
2004 }
2005 break;
2006 default:
2007 status = FALSE;
2008 break;
2009 }
2010
2011 return status;
2012
2013}
2014
2015void Update_Rssi_Sample(struct rt_rtmp_adapter *pAd,
2016 struct rt_rssi_sample *pRssi, struct rt_rxwi * pRxWI)
2017{
2018 char rssi0 = pRxWI->RSSI0;
2019 char rssi1 = pRxWI->RSSI1;
2020 char rssi2 = pRxWI->RSSI2;
2021
2022 if (rssi0 != 0) {
2023 pRssi->LastRssi0 = ConvertToRssi(pAd, (char)rssi0, RSSI_0);
2024 pRssi->AvgRssi0X8 =
2025 (pRssi->AvgRssi0X8 - pRssi->AvgRssi0) + pRssi->LastRssi0;
2026 pRssi->AvgRssi0 = pRssi->AvgRssi0X8 >> 3;
2027 }
2028
2029 if (rssi1 != 0) {
2030 pRssi->LastRssi1 = ConvertToRssi(pAd, (char)rssi1, RSSI_1);
2031 pRssi->AvgRssi1X8 =
2032 (pRssi->AvgRssi1X8 - pRssi->AvgRssi1) + pRssi->LastRssi1;
2033 pRssi->AvgRssi1 = pRssi->AvgRssi1X8 >> 3;
2034 }
2035
2036 if (rssi2 != 0) {
2037 pRssi->LastRssi2 = ConvertToRssi(pAd, (char)rssi2, RSSI_2);
2038 pRssi->AvgRssi2X8 =
2039 (pRssi->AvgRssi2X8 - pRssi->AvgRssi2) + pRssi->LastRssi2;
2040 pRssi->AvgRssi2 = pRssi->AvgRssi2X8 >> 3;
2041 }
2042}
2043
2044/* Normal legacy Rx packet indication */
2045void Indicate_Legacy_Packet(struct rt_rtmp_adapter *pAd,
2046 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
2047{
2048 void *pRxPacket = pRxBlk->pRxPacket;
2049 u8 Header802_3[LENGTH_802_3];
2050
2051 /* 1. get 802.3 Header */
2052 /* 2. remove LLC */
2053 /* a. pointer pRxBlk->pData to payload */
2054 /* b. modify pRxBlk->DataSize */
2055 RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
2056
2057 if (pRxBlk->DataSize > MAX_RX_PKT_LEN) {
2058
2059 /* release packet */
2060 RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
2061 return;
2062 }
2063
2064 STATS_INC_RX_PACKETS(pAd, FromWhichBSSID);
2065
2066#ifdef RTMP_MAC_USB
2067 if (pAd->CommonCfg.bDisableReordering == 0) {
2068 struct rt_ba_rec_entry *pBAEntry;
2069 unsigned long Now32;
2070 u8 Wcid = pRxBlk->pRxWI->WirelessCliID;
2071 u8 TID = pRxBlk->pRxWI->TID;
2072 u16 Idx;
2073
2074#define REORDERING_PACKET_TIMEOUT ((100 * OS_HZ)/1000) /* system ticks -- 100 ms */
2075
2076 if (Wcid < MAX_LEN_OF_MAC_TABLE) {
2077 Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID];
2078 if (Idx != 0) {
2079 pBAEntry = &pAd->BATable.BARecEntry[Idx];
2080 /* update last rx time */
2081 NdisGetSystemUpTime(&Now32);
2082 if ((pBAEntry->list.qlen > 0) &&
2083 RTMP_TIME_AFTER((unsigned long)Now32,
2084 (unsigned long)(pBAEntry->
2085 LastIndSeqAtTimer
2086 +
2087 (REORDERING_PACKET_TIMEOUT)))
2088 ) {
2089 DBGPRINT(RT_DEBUG_OFF,
2090 ("Indicate_Legacy_Packet():flush reordering_timeout_mpdus! RxWI->Flags=%d, pRxWI.TID=%d, RxD->AMPDU=%d!\n",
2091 pRxBlk->Flags,
2092 pRxBlk->pRxWI->TID,
2093 pRxBlk->RxD.AMPDU));
2094 hex_dump("Dump the legacy Packet:",
2095 GET_OS_PKT_DATAPTR(pRxBlk->
2096 pRxPacket),
2097 64);
2098 ba_flush_reordering_timeout_mpdus(pAd,
2099 pBAEntry,
2100 Now32);
2101 }
2102 }
2103 }
2104 }
2105#endif /* RTMP_MAC_USB // */
2106
2107 wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID);
2108
2109 /* */
2110 /* pass this 802.3 packet to upper layer or forward this packet to WM directly */
2111 /* */
2112 ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxPacket, FromWhichBSSID);
2113}
2114
2115/* Normal, AMPDU or AMSDU */
2116void CmmRxnonRalinkFrameIndicate(struct rt_rtmp_adapter *pAd,
2117 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
2118{
2119 if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU)
2120 && (pAd->CommonCfg.bDisableReordering == 0)) {
2121 Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);
2122 } else {
2123 if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU)) {
2124 /* handle A-MSDU */
2125 Indicate_AMSDU_Packet(pAd, pRxBlk, FromWhichBSSID);
2126 } else {
2127 Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
2128 }
2129 }
2130}
2131
2132void CmmRxRalinkFrameIndicate(struct rt_rtmp_adapter *pAd,
2133 struct rt_mac_table_entry *pEntry,
2134 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
2135{
2136 u8 Header802_3[LENGTH_802_3];
2137 u16 Msdu2Size;
2138 u16 Payload1Size, Payload2Size;
2139 u8 *pData2;
2140 void *pPacket2 = NULL;
2141
2142 Msdu2Size = *(pRxBlk->pData) + (*(pRxBlk->pData + 1) << 8);
2143
2144 if ((Msdu2Size <= 1536) && (Msdu2Size < pRxBlk->DataSize)) {
2145 /* skip two byte MSDU2 len */
2146 pRxBlk->pData += 2;
2147 pRxBlk->DataSize -= 2;
2148 } else {
2149 /* release packet */
2150 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
2151 NDIS_STATUS_FAILURE);
2152 return;
2153 }
2154
2155 /* get 802.3 Header and remove LLC */
2156 RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3);
2157
2158 ASSERT(pRxBlk->pRxPacket);
2159
2160 /* Ralink Aggregation frame */
2161 pAd->RalinkCounters.OneSecRxAggregationCount++;
2162 Payload1Size = pRxBlk->DataSize - Msdu2Size;
2163 Payload2Size = Msdu2Size - LENGTH_802_3;
2164
2165 pData2 = pRxBlk->pData + Payload1Size + LENGTH_802_3;
2166
2167 pPacket2 =
2168 duplicate_pkt(pAd, (pData2 - LENGTH_802_3), LENGTH_802_3, pData2,
2169 Payload2Size, FromWhichBSSID);
2170
2171 if (!pPacket2) {
2172 /* release packet */
2173 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
2174 NDIS_STATUS_FAILURE);
2175 return;
2176 }
2177 /* update payload size of 1st packet */
2178 pRxBlk->DataSize = Payload1Size;
2179 wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID);
2180
2181 ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxBlk->pRxPacket,
2182 FromWhichBSSID);
2183
2184 if (pPacket2) {
2185 ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket2, FromWhichBSSID);
2186 }
2187}
2188
2189#define RESET_FRAGFRAME(_fragFrame) \
2190 { \
2191 _fragFrame.RxSize = 0; \
2192 _fragFrame.Sequence = 0; \
2193 _fragFrame.LastFrag = 0; \
2194 _fragFrame.Flags = 0; \
2195 }
2196
2197void *RTMPDeFragmentDataFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk)
2198{
2199 struct rt_header_802_11 * pHeader = pRxBlk->pHeader;
2200 void *pRxPacket = pRxBlk->pRxPacket;
2201 u8 *pData = pRxBlk->pData;
2202 u16 DataSize = pRxBlk->DataSize;
2203 void *pRetPacket = NULL;
2204 u8 *pFragBuffer = NULL;
2205 BOOLEAN bReassDone = FALSE;
2206 u8 HeaderRoom = 0;
2207
2208 ASSERT(pHeader);
2209
2210 HeaderRoom = pData - (u8 *) pHeader;
2211
2212 /* Re-assemble the fragmented packets */
2213 if (pHeader->Frag == 0) /* Frag. Number is 0 : First frag or only one pkt */
2214 {
2215 /* the first pkt of fragment, record it. */
2216 if (pHeader->FC.MoreFrag) {
2217 ASSERT(pAd->FragFrame.pFragPacket);
2218 pFragBuffer =
2219 GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket);
2220 pAd->FragFrame.RxSize = DataSize + HeaderRoom;
2221 NdisMoveMemory(pFragBuffer, pHeader,
2222 pAd->FragFrame.RxSize);
2223 pAd->FragFrame.Sequence = pHeader->Sequence;
2224 pAd->FragFrame.LastFrag = pHeader->Frag; /* Should be 0 */
2225 ASSERT(pAd->FragFrame.LastFrag == 0);
2226 goto done; /* end of processing this frame */
2227 }
2228 } else /*Middle & End of fragment */
2229 {
2230 if ((pHeader->Sequence != pAd->FragFrame.Sequence) ||
2231 (pHeader->Frag != (pAd->FragFrame.LastFrag + 1))) {
2232 /* Fragment is not the same sequence or out of fragment number order */
2233 /* Reset Fragment control blk */
2234 RESET_FRAGFRAME(pAd->FragFrame);
2235 DBGPRINT(RT_DEBUG_ERROR,
2236 ("Fragment is not the same sequence or out of fragment number order.\n"));
2237 goto done; /* give up this frame */
2238 } else if ((pAd->FragFrame.RxSize + DataSize) > MAX_FRAME_SIZE) {
2239 /* Fragment frame is too large, it exeeds the maximum frame size. */
2240 /* Reset Fragment control blk */
2241 RESET_FRAGFRAME(pAd->FragFrame);
2242 DBGPRINT(RT_DEBUG_ERROR,
2243 ("Fragment frame is too large, it exeeds the maximum frame size.\n"));
2244 goto done; /* give up this frame */
2245 }
2246 /* */
2247 /* Broadcom AP(BCM94704AGR) will send out LLC in fragment's packet, LLC only can accpet at first fragment. */
2248 /* In this case, we will dropt it. */
2249 /* */
2250 if (NdisEqualMemory(pData, SNAP_802_1H, sizeof(SNAP_802_1H))) {
2251 DBGPRINT(RT_DEBUG_ERROR,
2252 ("Find another LLC at Middle or End fragment(SN=%d, Frag=%d)\n",
2253 pHeader->Sequence, pHeader->Frag));
2254 goto done; /* give up this frame */
2255 }
2256
2257 pFragBuffer = GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket);
2258
2259 /* concatenate this fragment into the re-assembly buffer */
2260 NdisMoveMemory((pFragBuffer + pAd->FragFrame.RxSize), pData,
2261 DataSize);
2262 pAd->FragFrame.RxSize += DataSize;
2263 pAd->FragFrame.LastFrag = pHeader->Frag; /* Update fragment number */
2264
2265 /* Last fragment */
2266 if (pHeader->FC.MoreFrag == FALSE) {
2267 bReassDone = TRUE;
2268 }
2269 }
2270
2271done:
2272 /* always release rx fragmented packet */
2273 RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
2274
2275 /* return defragmented packet if packet is reassembled completely */
2276 /* otherwise return NULL */
2277 if (bReassDone) {
2278 void *pNewFragPacket;
2279
2280 /* allocate a new packet buffer for fragment */
2281 pNewFragPacket =
2282 RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE);
2283 if (pNewFragPacket) {
2284 /* update RxBlk */
2285 pRetPacket = pAd->FragFrame.pFragPacket;
2286 pAd->FragFrame.pFragPacket = pNewFragPacket;
2287 pRxBlk->pHeader =
2288 (struct rt_header_802_11 *) GET_OS_PKT_DATAPTR(pRetPacket);
2289 pRxBlk->pData = (u8 *) pRxBlk->pHeader + HeaderRoom;
2290 pRxBlk->DataSize = pAd->FragFrame.RxSize - HeaderRoom;
2291 pRxBlk->pRxPacket = pRetPacket;
2292 } else {
2293 RESET_FRAGFRAME(pAd->FragFrame);
2294 }
2295 }
2296
2297 return pRetPacket;
2298}
2299
2300void Indicate_AMSDU_Packet(struct rt_rtmp_adapter *pAd,
2301 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
2302{
2303 u32 nMSDU;
2304
2305 update_os_packet_info(pAd, pRxBlk, FromWhichBSSID);
2306 RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID);
2307 nMSDU =
2308 deaggregate_AMSDU_announce(pAd, pRxBlk->pRxPacket, pRxBlk->pData,
2309 pRxBlk->DataSize);
2310}
2311
2312void Indicate_EAPOL_Packet(struct rt_rtmp_adapter *pAd,
2313 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
2314{
2315 struct rt_mac_table_entry *pEntry = NULL;
2316
2317 {
2318 pEntry = &pAd->MacTab.Content[BSSID_WCID];
2319 STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID);
2320 return;
2321 }
2322
2323 if (pEntry == NULL) {
2324 DBGPRINT(RT_DEBUG_WARN,
2325 ("Indicate_EAPOL_Packet: drop and release the invalid packet.\n"));
2326 /* release packet */
2327 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
2328 NDIS_STATUS_FAILURE);
2329 return;
2330 }
2331}
2332
2333#define BCN_TBTT_OFFSET 64 /*defer 64 us */
2334void ReSyncBeaconTime(struct rt_rtmp_adapter *pAd)
2335{
2336
2337 u32 Offset;
2338
2339 Offset = (pAd->TbttTickCount) % (BCN_TBTT_OFFSET);
2340
2341 pAd->TbttTickCount++;
2342
2343 /* */
2344 /* The updated BeaconInterval Value will affect Beacon Interval after two TBTT */
2345 /* beacasue the original BeaconInterval had been loaded into next TBTT_TIMER */
2346 /* */
2347 if (Offset == (BCN_TBTT_OFFSET - 2)) {
2348 BCN_TIME_CFG_STRUC csr;
2349 RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
2350 csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod << 4) - 1; /* ASIC register in units of 1/16 TU = 64us */
2351 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
2352 } else {
2353 if (Offset == (BCN_TBTT_OFFSET - 1)) {
2354 BCN_TIME_CFG_STRUC csr;
2355
2356 RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word);
2357 csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod) << 4; /* ASIC register in units of 1/16 TU */
2358 RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word);
2359 }
2360 }
2361}
diff --git a/drivers/staging/rt2860/common/cmm_data_pci.c b/drivers/staging/rt2860/common/cmm_data_pci.c
deleted file mode 100644
index bef0bbd8cef..00000000000
--- a/drivers/staging/rt2860/common/cmm_data_pci.c
+++ /dev/null
@@ -1,1096 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28/*
29 All functions in this file must be PCI-depended, or you should out your function
30 in other files.
31
32*/
33#include "../rt_config.h"
34
35u16 RtmpPCI_WriteTxResource(struct rt_rtmp_adapter *pAd,
36 struct rt_tx_blk *pTxBlk,
37 IN BOOLEAN bIsLast, u16 * FreeNumber)
38{
39
40 u8 *pDMAHeaderBufVA;
41 u16 TxIdx, RetTxIdx;
42 struct rt_txd * pTxD;
43 u32 BufBasePaLow;
44 struct rt_rtmp_tx_ring *pTxRing;
45 u16 hwHeaderLen;
46
47 /* */
48 /* get Tx Ring Resource */
49 /* */
50 pTxRing = &pAd->TxRing[pTxBlk->QueIdx];
51 TxIdx = pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx;
52 pDMAHeaderBufVA = (u8 *)pTxRing->Cell[TxIdx].DmaBuf.AllocVa;
53 BufBasePaLow =
54 RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa);
55
56 /* copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */
57 if (pTxBlk->TxFrameType == TX_AMSDU_FRAME) {
58 /*hwHeaderLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD, 4)+LENGTH_AMSDU_SUBFRAMEHEAD; */
59 hwHeaderLen =
60 pTxBlk->MpduHeaderLen - LENGTH_AMSDU_SUBFRAMEHEAD +
61 pTxBlk->HdrPadLen + LENGTH_AMSDU_SUBFRAMEHEAD;
62 } else {
63 /*hwHeaderLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */
64 hwHeaderLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
65 }
66 NdisMoveMemory(pDMAHeaderBufVA, pTxBlk->HeaderBuf,
67 TXINFO_SIZE + TXWI_SIZE + hwHeaderLen);
68
69 pTxRing->Cell[TxIdx].pNdisPacket = pTxBlk->pPacket;
70 pTxRing->Cell[TxIdx].pNextNdisPacket = NULL;
71
72 /* */
73 /* build Tx Descriptor */
74 /* */
75
76 pTxD = (struct rt_txd *) pTxRing->Cell[TxIdx].AllocVa;
77 NdisZeroMemory(pTxD, TXD_SIZE);
78
79 pTxD->SDPtr0 = BufBasePaLow;
80 pTxD->SDLen0 = TXINFO_SIZE + TXWI_SIZE + hwHeaderLen; /* include padding */
81 pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE);
82 pTxD->SDLen1 = pTxBlk->SrcBufLen;
83 pTxD->LastSec0 = 0;
84 pTxD->LastSec1 = (bIsLast) ? 1 : 0;
85
86 RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA);
87
88 RetTxIdx = TxIdx;
89 /* */
90 /* Update Tx index */
91 /* */
92 INC_RING_INDEX(TxIdx, TX_RING_SIZE);
93 pTxRing->TxCpuIdx = TxIdx;
94
95 *FreeNumber -= 1;
96
97 return RetTxIdx;
98}
99
100u16 RtmpPCI_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
101 struct rt_tx_blk *pTxBlk,
102 IN BOOLEAN bIsLast,
103 u16 * FreeNumber)
104{
105
106 u8 *pDMAHeaderBufVA;
107 u16 TxIdx, RetTxIdx;
108 struct rt_txd * pTxD;
109 u32 BufBasePaLow;
110 struct rt_rtmp_tx_ring *pTxRing;
111 u16 hwHeaderLen;
112
113 /* */
114 /* get Tx Ring Resource */
115 /* */
116 pTxRing = &pAd->TxRing[pTxBlk->QueIdx];
117 TxIdx = pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx;
118 pDMAHeaderBufVA = (u8 *)pTxRing->Cell[TxIdx].DmaBuf.AllocVa;
119 BufBasePaLow =
120 RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa);
121
122 /* copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */
123 /*hwHeaderLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */
124 hwHeaderLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
125
126 NdisMoveMemory(pDMAHeaderBufVA, pTxBlk->HeaderBuf,
127 TXINFO_SIZE + TXWI_SIZE + hwHeaderLen);
128
129 pTxRing->Cell[TxIdx].pNdisPacket = pTxBlk->pPacket;
130 pTxRing->Cell[TxIdx].pNextNdisPacket = NULL;
131
132 /* */
133 /* build Tx Descriptor */
134 /* */
135 pTxD = (struct rt_txd *) pTxRing->Cell[TxIdx].AllocVa;
136 NdisZeroMemory(pTxD, TXD_SIZE);
137
138 pTxD->SDPtr0 = BufBasePaLow;
139 pTxD->SDLen0 = TXINFO_SIZE + TXWI_SIZE + hwHeaderLen; /* include padding */
140 pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE);
141 pTxD->SDLen1 = pTxBlk->SrcBufLen;
142 pTxD->LastSec0 = 0;
143 pTxD->LastSec1 = (bIsLast) ? 1 : 0;
144
145 RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA);
146
147 RetTxIdx = TxIdx;
148 /* */
149 /* Update Tx index */
150 /* */
151 INC_RING_INDEX(TxIdx, TX_RING_SIZE);
152 pTxRing->TxCpuIdx = TxIdx;
153
154 *FreeNumber -= 1;
155
156 return RetTxIdx;
157}
158
159u16 RtmpPCI_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
160 struct rt_tx_blk *pTxBlk,
161 u8 frameNum, u16 * FreeNumber)
162{
163 BOOLEAN bIsLast;
164 u8 *pDMAHeaderBufVA;
165 u16 TxIdx, RetTxIdx;
166 struct rt_txd * pTxD;
167 u32 BufBasePaLow;
168 struct rt_rtmp_tx_ring *pTxRing;
169 u16 hwHdrLen;
170 u32 firstDMALen;
171
172 bIsLast = ((frameNum == (pTxBlk->TotalFrameNum - 1)) ? 1 : 0);
173
174 /* */
175 /* get Tx Ring Resource */
176 /* */
177 pTxRing = &pAd->TxRing[pTxBlk->QueIdx];
178 TxIdx = pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx;
179 pDMAHeaderBufVA = (u8 *)pTxRing->Cell[TxIdx].DmaBuf.AllocVa;
180 BufBasePaLow =
181 RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa);
182
183 if (frameNum == 0) {
184 /* copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */
185 if (pTxBlk->TxFrameType == TX_AMSDU_FRAME)
186 /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD, 4)+LENGTH_AMSDU_SUBFRAMEHEAD; */
187 hwHdrLen =
188 pTxBlk->MpduHeaderLen - LENGTH_AMSDU_SUBFRAMEHEAD +
189 pTxBlk->HdrPadLen + LENGTH_AMSDU_SUBFRAMEHEAD;
190 else if (pTxBlk->TxFrameType == TX_RALINK_FRAME)
191 /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_ARALINK_HEADER_FIELD, 4)+LENGTH_ARALINK_HEADER_FIELD; */
192 hwHdrLen =
193 pTxBlk->MpduHeaderLen -
194 LENGTH_ARALINK_HEADER_FIELD + pTxBlk->HdrPadLen +
195 LENGTH_ARALINK_HEADER_FIELD;
196 else
197 /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */
198 hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
199
200 firstDMALen = TXINFO_SIZE + TXWI_SIZE + hwHdrLen;
201 } else {
202 firstDMALen = pTxBlk->MpduHeaderLen;
203 }
204
205 NdisMoveMemory(pDMAHeaderBufVA, pTxBlk->HeaderBuf, firstDMALen);
206
207 pTxRing->Cell[TxIdx].pNdisPacket = pTxBlk->pPacket;
208 pTxRing->Cell[TxIdx].pNextNdisPacket = NULL;
209
210 /* */
211 /* build Tx Descriptor */
212 /* */
213 pTxD = (struct rt_txd *) pTxRing->Cell[TxIdx].AllocVa;
214 NdisZeroMemory(pTxD, TXD_SIZE);
215
216 pTxD->SDPtr0 = BufBasePaLow;
217 pTxD->SDLen0 = firstDMALen; /* include padding */
218 pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE);
219 pTxD->SDLen1 = pTxBlk->SrcBufLen;
220 pTxD->LastSec0 = 0;
221 pTxD->LastSec1 = (bIsLast) ? 1 : 0;
222
223 RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA);
224
225 RetTxIdx = TxIdx;
226 /* */
227 /* Update Tx index */
228 /* */
229 INC_RING_INDEX(TxIdx, TX_RING_SIZE);
230 pTxRing->TxCpuIdx = TxIdx;
231
232 *FreeNumber -= 1;
233
234 return RetTxIdx;
235
236}
237
238void RtmpPCI_FinalWriteTxResource(struct rt_rtmp_adapter *pAd,
239 struct rt_tx_blk *pTxBlk,
240 u16 totalMPDUSize, u16 FirstTxIdx)
241{
242
243 struct rt_txwi * pTxWI;
244 struct rt_rtmp_tx_ring *pTxRing;
245
246 /* */
247 /* get Tx Ring Resource */
248 /* */
249 pTxRing = &pAd->TxRing[pTxBlk->QueIdx];
250 pTxWI = (struct rt_txwi *) pTxRing->Cell[FirstTxIdx].DmaBuf.AllocVa;
251 pTxWI->MPDUtotalByteCount = totalMPDUSize;
252
253}
254
255void RtmpPCIDataLastTxIdx(struct rt_rtmp_adapter *pAd,
256 u8 QueIdx, u16 LastTxIdx)
257{
258 struct rt_txd * pTxD;
259 struct rt_rtmp_tx_ring *pTxRing;
260
261 /* */
262 /* get Tx Ring Resource */
263 /* */
264 pTxRing = &pAd->TxRing[QueIdx];
265
266 /* */
267 /* build Tx Descriptor */
268 /* */
269 pTxD = (struct rt_txd *) pTxRing->Cell[LastTxIdx].AllocVa;
270
271 pTxD->LastSec1 = 1;
272
273}
274
275u16 RtmpPCI_WriteFragTxResource(struct rt_rtmp_adapter *pAd,
276 struct rt_tx_blk *pTxBlk,
277 u8 fragNum, u16 * FreeNumber)
278{
279 u8 *pDMAHeaderBufVA;
280 u16 TxIdx, RetTxIdx;
281 struct rt_txd * pTxD;
282 u32 BufBasePaLow;
283 struct rt_rtmp_tx_ring *pTxRing;
284 u16 hwHeaderLen;
285 u32 firstDMALen;
286
287 /* */
288 /* Get Tx Ring Resource */
289 /* */
290 pTxRing = &pAd->TxRing[pTxBlk->QueIdx];
291 TxIdx = pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx;
292 pDMAHeaderBufVA = (u8 *)pTxRing->Cell[TxIdx].DmaBuf.AllocVa;
293 BufBasePaLow =
294 RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa);
295
296 /* */
297 /* Copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */
298 /* */
299 /*hwHeaderLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */
300 hwHeaderLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
301
302 firstDMALen = TXINFO_SIZE + TXWI_SIZE + hwHeaderLen;
303 NdisMoveMemory(pDMAHeaderBufVA, pTxBlk->HeaderBuf, firstDMALen);
304
305 /* */
306 /* Build Tx Descriptor */
307 /* */
308 pTxD = (struct rt_txd *) pTxRing->Cell[TxIdx].AllocVa;
309 NdisZeroMemory(pTxD, TXD_SIZE);
310
311 if (fragNum == pTxBlk->TotalFragNum) {
312 pTxRing->Cell[TxIdx].pNdisPacket = pTxBlk->pPacket;
313 pTxRing->Cell[TxIdx].pNextNdisPacket = NULL;
314 }
315
316 pTxD->SDPtr0 = BufBasePaLow;
317 pTxD->SDLen0 = firstDMALen; /* include padding */
318 pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE);
319 pTxD->SDLen1 = pTxBlk->SrcBufLen;
320 pTxD->LastSec0 = 0;
321 pTxD->LastSec1 = 1;
322
323 RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA);
324
325 RetTxIdx = TxIdx;
326 pTxBlk->Priv += pTxBlk->SrcBufLen;
327
328 /* */
329 /* Update Tx index */
330 /* */
331 INC_RING_INDEX(TxIdx, TX_RING_SIZE);
332 pTxRing->TxCpuIdx = TxIdx;
333
334 *FreeNumber -= 1;
335
336 return RetTxIdx;
337
338}
339
340/*
341 Must be run in Interrupt context
342 This function handle PCI specific TxDesc and cpu index update and kick the packet out.
343 */
344int RtmpPCIMgmtKickOut(struct rt_rtmp_adapter *pAd,
345 u8 QueIdx,
346 void *pPacket,
347 u8 *pSrcBufVA, u32 SrcBufLen)
348{
349 struct rt_txd * pTxD;
350 unsigned long SwIdx = pAd->MgmtRing.TxCpuIdx;
351
352 pTxD = (struct rt_txd *) pAd->MgmtRing.Cell[SwIdx].AllocVa;
353
354 pAd->MgmtRing.Cell[SwIdx].pNdisPacket = pPacket;
355 pAd->MgmtRing.Cell[SwIdx].pNextNdisPacket = NULL;
356
357 RTMPWriteTxDescriptor(pAd, pTxD, TRUE, FIFO_MGMT);
358 pTxD->LastSec0 = 1;
359 pTxD->LastSec1 = 1;
360 pTxD->DMADONE = 0;
361 pTxD->SDLen1 = 0;
362 pTxD->SDPtr0 =
363 PCI_MAP_SINGLE(pAd, pSrcBufVA, SrcBufLen, 0, PCI_DMA_TODEVICE);
364 pTxD->SDLen0 = SrcBufLen;
365
366/*================================================================== */
367/* DBGPRINT_RAW(RT_DEBUG_TRACE, ("MLMEHardTransmit\n"));
368 for (i = 0; i < (TXWI_SIZE+24); i++)
369 {
370
371 DBGPRINT_RAW(RT_DEBUG_TRACE, ("%x:", *(pSrcBufVA+i)));
372 if ( i%4 == 3)
373 DBGPRINT_RAW(RT_DEBUG_TRACE, (" :: "));
374 if ( i%16 == 15)
375 DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n "));
376 }
377 DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n "));*/
378/*======================================================================= */
379
380 pAd->RalinkCounters.KickTxCount++;
381 pAd->RalinkCounters.OneSecTxDoneCount++;
382
383 /* Increase TX_CTX_IDX, but write to register later. */
384 INC_RING_INDEX(pAd->MgmtRing.TxCpuIdx, MGMT_RING_SIZE);
385
386 RTMP_IO_WRITE32(pAd, TX_MGMTCTX_IDX, pAd->MgmtRing.TxCpuIdx);
387
388 return 0;
389}
390
391/*
392 ========================================================================
393
394 Routine Description:
395 Check Rx descriptor, return NDIS_STATUS_FAILURE if any error dound
396
397 Arguments:
398 pRxD Pointer to the Rx descriptor
399
400 Return Value:
401 NDIS_STATUS_SUCCESS No err
402 NDIS_STATUS_FAILURE Error
403
404 Note:
405
406 ========================================================================
407*/
408int RTMPCheckRxError(struct rt_rtmp_adapter *pAd,
409 struct rt_header_802_11 * pHeader,
410 struct rt_rxwi * pRxWI, IN PRT28XX_RXD_STRUC pRxD)
411{
412 struct rt_cipher_key *pWpaKey;
413 int dBm;
414
415 /* Phy errors & CRC errors */
416 if ( /*(pRxD->PhyErr) || */ (pRxD->Crc)) {
417 /* Check RSSI for Noise Hist statistic collection. */
418 dBm = (int)(pRxWI->RSSI0) - pAd->BbpRssiToDbmDelta;
419 if (dBm <= -87)
420 pAd->StaCfg.RPIDensity[0] += 1;
421 else if (dBm <= -82)
422 pAd->StaCfg.RPIDensity[1] += 1;
423 else if (dBm <= -77)
424 pAd->StaCfg.RPIDensity[2] += 1;
425 else if (dBm <= -72)
426 pAd->StaCfg.RPIDensity[3] += 1;
427 else if (dBm <= -67)
428 pAd->StaCfg.RPIDensity[4] += 1;
429 else if (dBm <= -62)
430 pAd->StaCfg.RPIDensity[5] += 1;
431 else if (dBm <= -57)
432 pAd->StaCfg.RPIDensity[6] += 1;
433 else if (dBm > -57)
434 pAd->StaCfg.RPIDensity[7] += 1;
435
436 return (NDIS_STATUS_FAILURE);
437 }
438 /* Add Rx size to channel load counter, we should ignore error counts */
439 pAd->StaCfg.CLBusyBytes += (pRxD->SDL0 + 14);
440
441 /* Drop ToDs promiscuous frame, it is opened due to CCX 2 channel load statistics */
442 if (pHeader != NULL) {
443 if (pHeader->FC.ToDs) {
444 return (NDIS_STATUS_FAILURE);
445 }
446 }
447 /* Drop not U2M frames, can't's drop here because we will drop beacon in this case */
448 /* I am kind of doubting the U2M bit operation */
449 /* if (pRxD->U2M == 0) */
450 /* return(NDIS_STATUS_FAILURE); */
451
452 /* drop decyption fail frame */
453 if (pRxD->CipherErr) {
454 if (pRxD->CipherErr == 2) {
455 DBGPRINT_RAW(RT_DEBUG_TRACE,
456 ("pRxD ERROR: ICV ok but MICErr "));
457 } else if (pRxD->CipherErr == 1) {
458 DBGPRINT_RAW(RT_DEBUG_TRACE, ("pRxD ERROR: ICV Err "));
459 } else if (pRxD->CipherErr == 3)
460 DBGPRINT_RAW(RT_DEBUG_TRACE,
461 ("pRxD ERROR: Key not valid "));
462
463 if (((pRxD->CipherErr & 1) == 1)
464 && pAd->CommonCfg.bWirelessEvent && INFRA_ON(pAd))
465 RTMPSendWirelessEvent(pAd, IW_ICV_ERROR_EVENT_FLAG,
466 pAd->MacTab.Content[BSSID_WCID].
467 Addr, BSS0, 0);
468
469 DBGPRINT_RAW(RT_DEBUG_TRACE,
470 (" %d (len=%d, Mcast=%d, MyBss=%d, Wcid=%d, KeyId=%d)\n",
471 pRxD->CipherErr, pRxD->SDL0,
472 pRxD->Mcast | pRxD->Bcast, pRxD->MyBss,
473 pRxWI->WirelessCliID,
474/* CipherName[pRxD->CipherAlg], */
475 pRxWI->KeyIndex));
476
477 /* */
478 /* MIC Error */
479 /* */
480 if (pRxD->CipherErr == 2) {
481 pWpaKey = &pAd->SharedKey[BSS0][pRxWI->KeyIndex];
482 if (pAd->StaCfg.WpaSupplicantUP)
483 WpaSendMicFailureToWpaSupplicant(pAd,
484 (pWpaKey->
485 Type ==
486 PAIRWISEKEY) ?
487 TRUE : FALSE);
488 else
489 RTMPReportMicError(pAd, pWpaKey);
490
491 if (((pRxD->CipherErr & 2) == 2)
492 && pAd->CommonCfg.bWirelessEvent && INFRA_ON(pAd))
493 RTMPSendWirelessEvent(pAd,
494 IW_MIC_ERROR_EVENT_FLAG,
495 pAd->MacTab.
496 Content[BSSID_WCID].Addr,
497 BSS0, 0);
498
499 DBGPRINT_RAW(RT_DEBUG_ERROR, ("Rx MIC Value error\n"));
500 }
501
502 if (pHeader == NULL)
503 return (NDIS_STATUS_SUCCESS);
504 /*if ((pRxD->CipherAlg == CIPHER_AES) &&
505 (pHeader->Sequence == pAd->FragFrame.Sequence))
506 {
507 //
508 // Acceptable since the First FragFrame no CipherErr problem.
509 //
510 return(NDIS_STATUS_SUCCESS);
511 } */
512
513 return (NDIS_STATUS_FAILURE);
514 }
515
516 return (NDIS_STATUS_SUCCESS);
517}
518
519BOOLEAN RTMPFreeTXDUponTxDmaDone(struct rt_rtmp_adapter *pAd, u8 QueIdx)
520{
521 struct rt_rtmp_tx_ring *pTxRing;
522 struct rt_txd * pTxD;
523 void *pPacket;
524 u8 FREE = 0;
525 struct rt_txd TxD, *pOriTxD;
526 /*unsigned long IrqFlags; */
527 BOOLEAN bReschedule = FALSE;
528
529 ASSERT(QueIdx < NUM_OF_TX_RING);
530 pTxRing = &pAd->TxRing[QueIdx];
531
532 RTMP_IO_READ32(pAd, TX_DTX_IDX0 + QueIdx * RINGREG_DIFF,
533 &pTxRing->TxDmaIdx);
534 while (pTxRing->TxSwFreeIdx != pTxRing->TxDmaIdx) {
535/* RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); */
536
537 /* static rate also need NICUpdateFifoStaCounters() function. */
538 /*if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)) */
539 NICUpdateFifoStaCounters(pAd);
540
541 /* Note : If (pAd->ate.bQATxStart == TRUE), we will never reach here. */
542 FREE++;
543 pTxD =
544 (struct rt_txd *) (pTxRing->Cell[pTxRing->TxSwFreeIdx].AllocVa);
545 pOriTxD = pTxD;
546 NdisMoveMemory(&TxD, pTxD, sizeof(struct rt_txd));
547 pTxD = &TxD;
548
549 pTxD->DMADONE = 0;
550
551 {
552 pPacket =
553 pTxRing->Cell[pTxRing->TxSwFreeIdx].pNdisPacket;
554 if (pPacket) {
555 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1,
556 pTxD->SDLen1,
557 PCI_DMA_TODEVICE);
558 RELEASE_NDIS_PACKET(pAd, pPacket,
559 NDIS_STATUS_SUCCESS);
560 }
561 /*Always assign pNdisPacket as NULL after clear */
562 pTxRing->Cell[pTxRing->TxSwFreeIdx].pNdisPacket = NULL;
563
564 pPacket =
565 pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket;
566
567 ASSERT(pPacket == NULL);
568 if (pPacket) {
569 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1,
570 pTxD->SDLen1,
571 PCI_DMA_TODEVICE);
572 RELEASE_NDIS_PACKET(pAd, pPacket,
573 NDIS_STATUS_SUCCESS);
574 }
575 /*Always assign pNextNdisPacket as NULL after clear */
576 pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket =
577 NULL;
578 }
579
580 pAd->RalinkCounters.TransmittedByteCount +=
581 (pTxD->SDLen1 + pTxD->SDLen0);
582 pAd->RalinkCounters.OneSecDmaDoneCount[QueIdx]++;
583 INC_RING_INDEX(pTxRing->TxSwFreeIdx, TX_RING_SIZE);
584 /* get tx_tdx_idx again */
585 RTMP_IO_READ32(pAd, TX_DTX_IDX0 + QueIdx * RINGREG_DIFF,
586 &pTxRing->TxDmaIdx);
587 NdisMoveMemory(pOriTxD, pTxD, sizeof(struct rt_txd));
588
589/* RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); */
590 }
591
592 return bReschedule;
593
594}
595
596/*
597 ========================================================================
598
599 Routine Description:
600 Process TX Rings DMA Done interrupt, running in DPC level
601
602 Arguments:
603 Adapter Pointer to our adapter
604
605 Return Value:
606 None
607
608 IRQL = DISPATCH_LEVEL
609
610 ========================================================================
611*/
612BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd,
613 INT_SOURCE_CSR_STRUC TxRingBitmap)
614{
615/* u8 Count = 0; */
616 unsigned long IrqFlags;
617 BOOLEAN bReschedule = FALSE;
618
619 /* Make sure Tx ring resource won't be used by other threads */
620 /*NdisAcquireSpinLock(&pAd->TxRingLock); */
621
622 RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
623
624 if (TxRingBitmap.field.Ac0DmaDone)
625 bReschedule = RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BE);
626
627 if (TxRingBitmap.field.Ac3DmaDone)
628 bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VO);
629
630 if (TxRingBitmap.field.Ac2DmaDone)
631 bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VI);
632
633 if (TxRingBitmap.field.Ac1DmaDone)
634 bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BK);
635
636 /* Make sure to release Tx ring resource */
637 /*NdisReleaseSpinLock(&pAd->TxRingLock); */
638 RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
639
640 /* Dequeue outgoing frames from TxSwQueue[] and process it */
641 RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
642
643 return bReschedule;
644}
645
646/*
647 ========================================================================
648
649 Routine Description:
650 Process MGMT ring DMA done interrupt, running in DPC level
651
652 Arguments:
653 pAd Pointer to our adapter
654
655 Return Value:
656 None
657
658 IRQL = DISPATCH_LEVEL
659
660 Note:
661
662 ========================================================================
663*/
664void RTMPHandleMgmtRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd)
665{
666 struct rt_txd * pTxD;
667 void *pPacket;
668/* int i; */
669 u8 FREE = 0;
670 struct rt_rtmp_mgmt_ring *pMgmtRing = &pAd->MgmtRing;
671
672 NdisAcquireSpinLock(&pAd->MgmtRingLock);
673
674 RTMP_IO_READ32(pAd, TX_MGMTDTX_IDX, &pMgmtRing->TxDmaIdx);
675 while (pMgmtRing->TxSwFreeIdx != pMgmtRing->TxDmaIdx) {
676 FREE++;
677 pTxD =
678 (struct rt_txd *) (pMgmtRing->Cell[pAd->MgmtRing.TxSwFreeIdx].
679 AllocVa);
680 pTxD->DMADONE = 0;
681 pPacket = pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNdisPacket;
682
683 if (pPacket) {
684 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0,
685 PCI_DMA_TODEVICE);
686 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
687 }
688 pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNdisPacket = NULL;
689
690 pPacket =
691 pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNextNdisPacket;
692 if (pPacket) {
693 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1,
694 PCI_DMA_TODEVICE);
695 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);
696 }
697 pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNextNdisPacket = NULL;
698 INC_RING_INDEX(pMgmtRing->TxSwFreeIdx, MGMT_RING_SIZE);
699
700 }
701 NdisReleaseSpinLock(&pAd->MgmtRingLock);
702
703}
704
705/*
706 ========================================================================
707
708 Routine Description:
709 Arguments:
710 Adapter Pointer to our adapter. Dequeue all power safe delayed braodcast frames after beacon.
711
712 IRQL = DISPATCH_LEVEL
713
714 ========================================================================
715*/
716void RTMPHandleTBTTInterrupt(struct rt_rtmp_adapter *pAd)
717{
718 {
719 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) {
720 }
721 }
722}
723
724/*
725 ========================================================================
726
727 Routine Description:
728 Arguments:
729 pAd Pointer to our adapter. Rewrite beacon content before next send-out.
730
731 IRQL = DISPATCH_LEVEL
732
733 ========================================================================
734*/
735void RTMPHandlePreTBTTInterrupt(struct rt_rtmp_adapter *pAd)
736{
737 {
738 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) {
739 DBGPRINT(RT_DEBUG_TRACE,
740 ("RTMPHandlePreTBTTInterrupt...\n"));
741 }
742 }
743
744}
745
746void RTMPHandleRxCoherentInterrupt(struct rt_rtmp_adapter *pAd)
747{
748 WPDMA_GLO_CFG_STRUC GloCfg;
749
750 if (pAd == NULL) {
751 DBGPRINT(RT_DEBUG_TRACE, ("====> pAd is NULL, return.\n"));
752 return;
753 }
754
755 DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPHandleRxCoherentInterrupt \n"));
756
757 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
758
759 GloCfg.field.EnTXWriteBackDDONE = 0;
760 GloCfg.field.EnableRxDMA = 0;
761 GloCfg.field.EnableTxDMA = 0;
762 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
763
764 RTMPRingCleanUp(pAd, QID_AC_BE);
765 RTMPRingCleanUp(pAd, QID_AC_BK);
766 RTMPRingCleanUp(pAd, QID_AC_VI);
767 RTMPRingCleanUp(pAd, QID_AC_VO);
768 RTMPRingCleanUp(pAd, QID_MGMT);
769 RTMPRingCleanUp(pAd, QID_RX);
770
771 RTMPEnableRxTx(pAd);
772
773 DBGPRINT(RT_DEBUG_TRACE, ("<== RTMPHandleRxCoherentInterrupt \n"));
774}
775
776void *GetPacketFromRxRing(struct rt_rtmp_adapter *pAd,
777 OUT PRT28XX_RXD_STRUC pSaveRxD,
778 OUT BOOLEAN * pbReschedule,
779 IN u32 * pRxPending)
780{
781 struct rt_rxd * pRxD;
782 void *pRxPacket = NULL;
783 void *pNewPacket;
784 void *AllocVa;
785 dma_addr_t AllocPa;
786 BOOLEAN bReschedule = FALSE;
787 struct rt_rtmp_dmacb *pRxCell;
788
789 RTMP_SEM_LOCK(&pAd->RxRingLock);
790
791 if (*pRxPending == 0) {
792 /* Get how may packets had been received */
793 RTMP_IO_READ32(pAd, RX_DRX_IDX, &pAd->RxRing.RxDmaIdx);
794
795 if (pAd->RxRing.RxSwReadIdx == pAd->RxRing.RxDmaIdx) {
796 /* no more rx packets */
797 bReschedule = FALSE;
798 goto done;
799 }
800 /* get rx pending count */
801 if (pAd->RxRing.RxDmaIdx > pAd->RxRing.RxSwReadIdx)
802 *pRxPending =
803 pAd->RxRing.RxDmaIdx - pAd->RxRing.RxSwReadIdx;
804 else
805 *pRxPending =
806 pAd->RxRing.RxDmaIdx + RX_RING_SIZE -
807 pAd->RxRing.RxSwReadIdx;
808
809 }
810
811 pRxCell = &pAd->RxRing.Cell[pAd->RxRing.RxSwReadIdx];
812
813 /* Point to Rx indexed rx ring descriptor */
814 pRxD = (struct rt_rxd *) pRxCell->AllocVa;
815
816 if (pRxD->DDONE == 0) {
817 *pRxPending = 0;
818 /* DMAIndx had done but DDONE bit not ready */
819 bReschedule = TRUE;
820 goto done;
821 }
822
823 /* return rx descriptor */
824 NdisMoveMemory(pSaveRxD, pRxD, RXD_SIZE);
825
826 pNewPacket =
827 RTMP_AllocateRxPacketBuffer(pAd, RX_BUFFER_AGGRESIZE, FALSE,
828 &AllocVa, &AllocPa);
829
830 if (pNewPacket) {
831 /* unmap the rx buffer */
832 PCI_UNMAP_SINGLE(pAd, pRxCell->DmaBuf.AllocPa,
833 pRxCell->DmaBuf.AllocSize, PCI_DMA_FROMDEVICE);
834 pRxPacket = pRxCell->pNdisPacket;
835
836 pRxCell->DmaBuf.AllocSize = RX_BUFFER_AGGRESIZE;
837 pRxCell->pNdisPacket = (void *)pNewPacket;
838 pRxCell->DmaBuf.AllocVa = AllocVa;
839 pRxCell->DmaBuf.AllocPa = AllocPa;
840 /* update SDP0 to new buffer of rx packet */
841 pRxD->SDP0 = AllocPa;
842 } else {
843 /*DBGPRINT(RT_DEBUG_TRACE,("No Rx Buffer\n")); */
844 pRxPacket = NULL;
845 bReschedule = TRUE;
846 }
847
848 pRxD->DDONE = 0;
849
850 /* had handled one rx packet */
851 *pRxPending = *pRxPending - 1;
852
853 /* update rx descriptor and kick rx */
854 INC_RING_INDEX(pAd->RxRing.RxSwReadIdx, RX_RING_SIZE);
855
856 pAd->RxRing.RxCpuIdx =
857 (pAd->RxRing.RxSwReadIdx ==
858 0) ? (RX_RING_SIZE - 1) : (pAd->RxRing.RxSwReadIdx - 1);
859 RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx);
860
861done:
862 RTMP_SEM_UNLOCK(&pAd->RxRingLock);
863 *pbReschedule = bReschedule;
864 return pRxPacket;
865}
866
867int MlmeHardTransmitTxRing(struct rt_rtmp_adapter *pAd,
868 u8 QueIdx, void *pPacket)
869{
870 struct rt_packet_info PacketInfo;
871 u8 *pSrcBufVA;
872 u32 SrcBufLen;
873 struct rt_txd * pTxD;
874 struct rt_header_802_11 * pHeader_802_11;
875 BOOLEAN bAckRequired, bInsertTimestamp;
876 unsigned long SrcBufPA;
877 /*u8 TxBufIdx; */
878 u8 MlmeRate;
879 unsigned long SwIdx = pAd->TxRing[QueIdx].TxCpuIdx;
880 struct rt_txwi * pFirstTxWI;
881 /*unsigned long i; */
882 /*HTTRANSMIT_SETTING MlmeTransmit; //Rate for this MGMT frame. */
883 unsigned long FreeNum;
884 struct rt_mac_table_entry *pMacEntry = NULL;
885
886 RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
887
888 if (pSrcBufVA == NULL) {
889 /* The buffer shouldn't be NULL */
890 return NDIS_STATUS_FAILURE;
891 }
892 /* Make sure MGMT ring resource won't be used by other threads */
893 /*NdisAcquireSpinLock(&pAd->TxRingLock); */
894
895 FreeNum = GET_TXRING_FREENO(pAd, QueIdx);
896
897 if (FreeNum == 0) {
898 /*NdisReleaseSpinLock(&pAd->TxRingLock); */
899 return NDIS_STATUS_FAILURE;
900 }
901
902 SwIdx = pAd->TxRing[QueIdx].TxCpuIdx;
903
904 pTxD = (struct rt_txd *) pAd->TxRing[QueIdx].Cell[SwIdx].AllocVa;
905
906 if (pAd->TxRing[QueIdx].Cell[SwIdx].pNdisPacket) {
907 DBGPRINT(RT_DEBUG_OFF, ("MlmeHardTransmit Error\n"));
908 /*NdisReleaseSpinLock(&pAd->TxRingLock); */
909 return NDIS_STATUS_FAILURE;
910 }
911
912 {
913 /* outgoing frame always wakeup PHY to prevent frame lost */
914 /* if (pAd->StaCfg.Psm == PWR_SAVE) */
915 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
916 AsicForceWakeup(pAd, TRUE);
917 }
918 pFirstTxWI = (struct rt_txwi *) pSrcBufVA;
919
920 pHeader_802_11 = (struct rt_header_802_11 *) (pSrcBufVA + TXWI_SIZE);
921 if (pHeader_802_11->Addr1[0] & 0x01) {
922 MlmeRate = pAd->CommonCfg.BasicMlmeRate;
923 } else {
924 MlmeRate = pAd->CommonCfg.MlmeRate;
925 }
926
927 if ((pHeader_802_11->FC.Type == BTYPE_DATA) &&
928 (pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL)) {
929 pMacEntry = MacTableLookup(pAd, pHeader_802_11->Addr1);
930 }
931 /* Verify Mlme rate for a / g bands. */
932 if ((pAd->LatchRfRegs.Channel > 14) && (MlmeRate < RATE_6)) /* 11A band */
933 MlmeRate = RATE_6;
934
935 /* */
936 /* Should not be hard code to set PwrMgmt to 0 (PWR_ACTIVE) */
937 /* Snice it's been set to 0 while on MgtMacHeaderInit */
938 /* By the way this will cause frame to be send on PWR_SAVE failed. */
939 /* */
940 /* */
941 /* In WMM-UAPSD, mlme frame should be set psm as power saving but probe request frame */
942 /* Data-Null packets also pass through MMRequest in RT2860, however, we hope control the psm bit to pass APSD */
943 if (pHeader_802_11->FC.Type != BTYPE_DATA) {
944 if ((pHeader_802_11->FC.SubType == SUBTYPE_PROBE_REQ)
945 || !(pAd->CommonCfg.bAPSDCapable
946 && pAd->CommonCfg.APEdcaParm.bAPSDCapable)) {
947 pHeader_802_11->FC.PwrMgmt = PWR_ACTIVE;
948 } else {
949 pHeader_802_11->FC.PwrMgmt =
950 pAd->CommonCfg.bAPSDForcePowerSave;
951 }
952 }
953
954 bInsertTimestamp = FALSE;
955 if (pHeader_802_11->FC.Type == BTYPE_CNTL) /* must be PS-POLL */
956 {
957 bAckRequired = FALSE;
958 } else /* BTYPE_MGMT or BTYPE_DATA(must be NULL frame) */
959 {
960 if (pHeader_802_11->Addr1[0] & 0x01) /* MULTICAST, BROADCAST */
961 {
962 bAckRequired = FALSE;
963 pHeader_802_11->Duration = 0;
964 } else {
965 bAckRequired = TRUE;
966 pHeader_802_11->Duration =
967 RTMPCalcDuration(pAd, MlmeRate, 14);
968 if (pHeader_802_11->FC.SubType == SUBTYPE_PROBE_RSP) {
969 bInsertTimestamp = TRUE;
970 }
971 }
972 }
973 pHeader_802_11->Sequence = pAd->Sequence++;
974 if (pAd->Sequence > 0xfff)
975 pAd->Sequence = 0;
976 /* Before radar detection done, mgmt frame can not be sent but probe req */
977 /* Because we need to use probe req to trigger driver to send probe req in passive scan */
978 if ((pHeader_802_11->FC.SubType != SUBTYPE_PROBE_REQ)
979 && (pAd->CommonCfg.bIEEE80211H == 1)
980 && (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)) {
981 DBGPRINT(RT_DEBUG_ERROR,
982 ("MlmeHardTransmit --> radar detect not in normal mode!\n"));
983 /*NdisReleaseSpinLock(&pAd->TxRingLock); */
984 return (NDIS_STATUS_FAILURE);
985 }
986 /* */
987 /* fill scatter-and-gather buffer list into TXD. Internally created NDIS PACKET */
988 /* should always has only one ohysical buffer, and the whole frame size equals */
989 /* to the first scatter buffer size */
990 /* */
991
992 /* Initialize TX Descriptor */
993 /* For inter-frame gap, the number is for this frame and next frame */
994 /* For MLME rate, we will fix as 2Mb to match other vendor's implement */
995/* pAd->CommonCfg.MlmeTransmit.field.MODE = 1; */
996
997/* management frame doesn't need encryption. so use RESERVED_WCID no matter u are sending to specific wcid or not. */
998 /* Only beacon use Nseq=TRUE. So here we use Nseq=FALSE. */
999 if (pMacEntry == NULL) {
1000 RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, bInsertTimestamp,
1001 FALSE, bAckRequired, FALSE, 0, RESERVED_WCID,
1002 (SrcBufLen - TXWI_SIZE), PID_MGMT, 0,
1003 (u8)pAd->CommonCfg.MlmeTransmit.field.MCS,
1004 IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
1005 } else {
1006 RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE,
1007 bInsertTimestamp, FALSE, bAckRequired, FALSE,
1008 0, pMacEntry->Aid, (SrcBufLen - TXWI_SIZE),
1009 pMacEntry->MaxHTPhyMode.field.MCS, 0,
1010 (u8)pMacEntry->MaxHTPhyMode.field.MCS,
1011 IFS_BACKOFF, FALSE, &pMacEntry->MaxHTPhyMode);
1012 }
1013
1014 pAd->TxRing[QueIdx].Cell[SwIdx].pNdisPacket = pPacket;
1015 pAd->TxRing[QueIdx].Cell[SwIdx].pNextNdisPacket = NULL;
1016/* pFirstTxWI->MPDUtotalByteCount = SrcBufLen - TXWI_SIZE; */
1017 SrcBufPA =
1018 PCI_MAP_SINGLE(pAd, pSrcBufVA, SrcBufLen, 0, PCI_DMA_TODEVICE);
1019
1020 RTMPWriteTxDescriptor(pAd, pTxD, TRUE, FIFO_EDCA);
1021 pTxD->LastSec0 = 1;
1022 pTxD->LastSec1 = 1;
1023 pTxD->SDLen0 = SrcBufLen;
1024 pTxD->SDLen1 = 0;
1025 pTxD->SDPtr0 = SrcBufPA;
1026 pTxD->DMADONE = 0;
1027
1028 pAd->RalinkCounters.KickTxCount++;
1029 pAd->RalinkCounters.OneSecTxDoneCount++;
1030
1031 /* Increase TX_CTX_IDX, but write to register later. */
1032 INC_RING_INDEX(pAd->TxRing[QueIdx].TxCpuIdx, TX_RING_SIZE);
1033
1034 RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + QueIdx * 0x10,
1035 pAd->TxRing[QueIdx].TxCpuIdx);
1036
1037 /* Make sure to release MGMT ring resource */
1038/* NdisReleaseSpinLock(&pAd->TxRingLock); */
1039
1040 return NDIS_STATUS_SUCCESS;
1041}
1042
1043int MlmeDataHardTransmit(struct rt_rtmp_adapter *pAd,
1044 u8 QueIdx, void *pPacket)
1045{
1046 if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)
1047 ) {
1048 return NDIS_STATUS_FAILURE;
1049 }
1050
1051 return MlmeHardTransmitTxRing(pAd, QueIdx, pPacket);
1052}
1053
1054/*
1055 ========================================================================
1056
1057 Routine Description:
1058 Calculates the duration which is required to transmit out frames
1059 with given size and specified rate.
1060
1061 Arguments:
1062 pTxD Pointer to transmit descriptor
1063 Ack Setting for Ack requirement bit
1064 Fragment Setting for Fragment bit
1065 RetryMode Setting for retry mode
1066 Ifs Setting for IFS gap
1067 Rate Setting for transmit rate
1068 Service Setting for service
1069 Length Frame length
1070 TxPreamble Short or Long preamble when using CCK rates
1071 QueIdx - 0-3, according to 802.11e/d4.4 June/2003
1072
1073 Return Value:
1074 None
1075
1076 IRQL = PASSIVE_LEVEL
1077 IRQL = DISPATCH_LEVEL
1078
1079 ========================================================================
1080*/
1081void RTMPWriteTxDescriptor(struct rt_rtmp_adapter *pAd,
1082 struct rt_txd * pTxD,
1083 IN BOOLEAN bWIV, u8 QueueSEL)
1084{
1085 /* */
1086 /* Always use Long preamble before verifiation short preamble functionality works well. */
1087 /* Todo: remove the following line if short preamble functionality works */
1088 /* */
1089 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
1090
1091 pTxD->WIV = (bWIV) ? 1 : 0;
1092 pTxD->QSEL = (QueueSEL);
1093 /*RT2860c?? fixed using EDCA queue for test... We doubt Queue1 has problem. 2006-09-26 Jan */
1094 /*pTxD->QSEL= FIFO_EDCA; */
1095 pTxD->DMADONE = 0;
1096}
diff --git a/drivers/staging/rt2860/common/cmm_data_usb.c b/drivers/staging/rt2860/common/cmm_data_usb.c
deleted file mode 100644
index 5637857ae9e..00000000000
--- a/drivers/staging/rt2860/common/cmm_data_usb.c
+++ /dev/null
@@ -1,951 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27
28/*
29 All functions in this file must be USB-depended, or you should out your function
30 in other files.
31
32*/
33
34#ifdef RTMP_MAC_USB
35
36#include "../rt_config.h"
37
38/*
39 We can do copy the frame into pTxContext when match following conditions.
40 =>
41 =>
42 =>
43*/
44static inline int RtmpUSBCanDoWrite(struct rt_rtmp_adapter *pAd,
45 u8 QueIdx,
46 struct rt_ht_tx_context *pHTTXContext)
47{
48 int canWrite = NDIS_STATUS_RESOURCES;
49
50 if (((pHTTXContext->CurWritePosition) <
51 pHTTXContext->NextBulkOutPosition)
52 && (pHTTXContext->CurWritePosition + LOCAL_TXBUF_SIZE) >
53 pHTTXContext->NextBulkOutPosition) {
54 DBGPRINT(RT_DEBUG_ERROR, ("RtmpUSBCanDoWrite c1!\n"));
55 RTUSB_SET_BULK_FLAG(pAd,
56 (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
57 } else if ((pHTTXContext->CurWritePosition == 8)
58 && (pHTTXContext->NextBulkOutPosition < LOCAL_TXBUF_SIZE)) {
59 DBGPRINT(RT_DEBUG_ERROR, ("RtmpUSBCanDoWrite c2!\n"));
60 RTUSB_SET_BULK_FLAG(pAd,
61 (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
62 } else if (pHTTXContext->bCurWriting == TRUE) {
63 DBGPRINT(RT_DEBUG_ERROR, ("RtmpUSBCanDoWrite c3!\n"));
64 } else {
65 canWrite = NDIS_STATUS_SUCCESS;
66 }
67
68 return canWrite;
69}
70
71u16 RtmpUSB_WriteSubTxResource(struct rt_rtmp_adapter *pAd,
72 struct rt_tx_blk *pTxBlk,
73 IN BOOLEAN bIsLast, u16 * FreeNumber)
74{
75
76 /* Dummy function. Should be removed in the future. */
77 return 0;
78
79}
80
81u16 RtmpUSB_WriteFragTxResource(struct rt_rtmp_adapter *pAd,
82 struct rt_tx_blk *pTxBlk,
83 u8 fragNum, u16 * FreeNumber)
84{
85 struct rt_ht_tx_context *pHTTXContext;
86 u16 hwHdrLen; /* The hwHdrLen consist of 802.11 header length plus the header padding length. */
87 u32 fillOffset;
88 struct rt_txinfo *pTxInfo;
89 struct rt_txwi *pTxWI;
90 u8 *pWirelessPacket = NULL;
91 u8 QueIdx;
92 int Status;
93 unsigned long IrqFlags;
94 u32 USBDMApktLen = 0, DMAHdrLen, padding;
95 BOOLEAN TxQLastRound = FALSE;
96
97 /* */
98 /* get Tx Ring Resource & Dma Buffer address */
99 /* */
100 QueIdx = pTxBlk->QueIdx;
101 pHTTXContext = &pAd->TxContext[QueIdx];
102
103 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
104
105 pHTTXContext = &pAd->TxContext[QueIdx];
106 fillOffset = pHTTXContext->CurWritePosition;
107
108 if (fragNum == 0) {
109 /* Check if we have enough space for this bulk-out batch. */
110 Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
111 if (Status == NDIS_STATUS_SUCCESS) {
112 pHTTXContext->bCurWriting = TRUE;
113
114 /* Reserve space for 8 bytes padding. */
115 if ((pHTTXContext->ENextBulkOutPosition ==
116 pHTTXContext->CurWritePosition)) {
117 pHTTXContext->ENextBulkOutPosition += 8;
118 pHTTXContext->CurWritePosition += 8;
119 fillOffset += 8;
120 }
121 pTxBlk->Priv = 0;
122 pHTTXContext->CurWriteRealPos =
123 pHTTXContext->CurWritePosition;
124 } else {
125 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx],
126 IrqFlags);
127
128 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket,
129 NDIS_STATUS_FAILURE);
130 return (Status);
131 }
132 } else {
133 /* For sub-sequent frames of this bulk-out batch. Just copy it to our bulk-out buffer. */
134 Status =
135 ((pHTTXContext->bCurWriting ==
136 TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE);
137 if (Status == NDIS_STATUS_SUCCESS) {
138 fillOffset += pTxBlk->Priv;
139 } else {
140 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx],
141 IrqFlags);
142
143 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket,
144 NDIS_STATUS_FAILURE);
145 return (Status);
146 }
147 }
148
149 NdisZeroMemory((u8 *)(&pTxBlk->HeaderBuf[0]), TXINFO_SIZE);
150 pTxInfo = (struct rt_txinfo *)(&pTxBlk->HeaderBuf[0]);
151 pTxWI = (struct rt_txwi *) (&pTxBlk->HeaderBuf[TXINFO_SIZE]);
152
153 pWirelessPacket =
154 &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset];
155
156 /* copy TXWI + WLAN Header + LLC into DMA Header Buffer */
157 /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */
158 hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
159
160 /* Build our URB for USBD */
161 DMAHdrLen = TXWI_SIZE + hwHdrLen;
162 USBDMApktLen = DMAHdrLen + pTxBlk->SrcBufLen;
163 padding = (4 - (USBDMApktLen % 4)) & 0x03; /* round up to 4 byte alignment */
164 USBDMApktLen += padding;
165
166 pTxBlk->Priv += (TXINFO_SIZE + USBDMApktLen);
167
168 /* For TxInfo, the length of USBDMApktLen = TXWI_SIZE + 802.11 header + payload */
169 RTMPWriteTxInfo(pAd, pTxInfo, (u16)(USBDMApktLen), FALSE, FIFO_EDCA,
170 FALSE /*NextValid */ , FALSE);
171
172 if (fragNum == pTxBlk->TotalFragNum) {
173 pTxInfo->USBDMATxburst = 0;
174 if ((pHTTXContext->CurWritePosition + pTxBlk->Priv + 3906) >
175 MAX_TXBULK_LIMIT) {
176 pTxInfo->SwUseLastRound = 1;
177 TxQLastRound = TRUE;
178 }
179 } else {
180 pTxInfo->USBDMATxburst = 1;
181 }
182
183 NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf,
184 TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
185 pWirelessPacket += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
186 pHTTXContext->CurWriteRealPos += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
187
188 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
189
190 NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen);
191
192 /* Zero the last padding. */
193 pWirelessPacket += pTxBlk->SrcBufLen;
194 NdisZeroMemory(pWirelessPacket, padding + 8);
195
196 if (fragNum == pTxBlk->TotalFragNum) {
197 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
198
199 /* Update the pHTTXContext->CurWritePosition. 3906 used to prevent the NextBulkOut is a A-RALINK/A-MSDU Frame. */
200 pHTTXContext->CurWritePosition += pTxBlk->Priv;
201 if (TxQLastRound == TRUE)
202 pHTTXContext->CurWritePosition = 8;
203 pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
204
205 /* Finally, set bCurWriting as FALSE */
206 pHTTXContext->bCurWriting = FALSE;
207
208 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
209
210 /* succeed and release the skb buffer */
211 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
212 }
213
214 return (Status);
215
216}
217
218u16 RtmpUSB_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
219 struct rt_tx_blk *pTxBlk,
220 IN BOOLEAN bIsLast,
221 u16 * FreeNumber)
222{
223 struct rt_ht_tx_context *pHTTXContext;
224 u16 hwHdrLen;
225 u32 fillOffset;
226 struct rt_txinfo *pTxInfo;
227 struct rt_txwi *pTxWI;
228 u8 *pWirelessPacket;
229 u8 QueIdx;
230 unsigned long IrqFlags;
231 int Status;
232 u32 USBDMApktLen = 0, DMAHdrLen, padding;
233 BOOLEAN bTxQLastRound = FALSE;
234
235 /* For USB, didn't need PCI_MAP_SINGLE() */
236 /*SrcBufPA = PCI_MAP_SINGLE(pAd, (char *) pTxBlk->pSrcBufData, pTxBlk->SrcBufLen, PCI_DMA_TODEVICE); */
237
238 /* */
239 /* get Tx Ring Resource & Dma Buffer address */
240 /* */
241 QueIdx = pTxBlk->QueIdx;
242
243 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
244 pHTTXContext = &pAd->TxContext[QueIdx];
245 fillOffset = pHTTXContext->CurWritePosition;
246
247 /* Check ring full. */
248 Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
249 if (Status == NDIS_STATUS_SUCCESS) {
250 pHTTXContext->bCurWriting = TRUE;
251
252 pTxInfo = (struct rt_txinfo *)(&pTxBlk->HeaderBuf[0]);
253 pTxWI = (struct rt_txwi *) (&pTxBlk->HeaderBuf[TXINFO_SIZE]);
254
255 /* Reserve space for 8 bytes padding. */
256 if ((pHTTXContext->ENextBulkOutPosition ==
257 pHTTXContext->CurWritePosition)) {
258 pHTTXContext->ENextBulkOutPosition += 8;
259 pHTTXContext->CurWritePosition += 8;
260 fillOffset += 8;
261 }
262 pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
263
264 pWirelessPacket =
265 &pHTTXContext->TransferBuffer->field.
266 WirelessPacket[fillOffset];
267
268 /* copy TXWI + WLAN Header + LLC into DMA Header Buffer */
269 /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */
270 hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
271
272 /* Build our URB for USBD */
273 DMAHdrLen = TXWI_SIZE + hwHdrLen;
274 USBDMApktLen = DMAHdrLen + pTxBlk->SrcBufLen;
275 padding = (4 - (USBDMApktLen % 4)) & 0x03; /* round up to 4 byte alignment */
276 USBDMApktLen += padding;
277
278 pTxBlk->Priv = (TXINFO_SIZE + USBDMApktLen);
279
280 /* For TxInfo, the length of USBDMApktLen = TXWI_SIZE + 802.11 header + payload */
281 RTMPWriteTxInfo(pAd, pTxInfo, (u16)(USBDMApktLen), FALSE,
282 FIFO_EDCA, FALSE /*NextValid */ , FALSE);
283
284 if ((pHTTXContext->CurWritePosition + 3906 + pTxBlk->Priv) >
285 MAX_TXBULK_LIMIT) {
286 pTxInfo->SwUseLastRound = 1;
287 bTxQLastRound = TRUE;
288 }
289 NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf,
290 TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
291 pWirelessPacket += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
292
293 /* We unlock it here to prevent the first 8 bytes maybe over-writed issue. */
294 /* 1. First we got CurWritePosition but the first 8 bytes still not write to the pTxcontext. */
295 /* 2. An interrupt break our routine and handle bulk-out complete. */
296 /* 3. In the bulk-out compllete, it need to do another bulk-out, */
297 /* if the ENextBulkOutPosition is just the same as CurWritePosition, it will save the first 8 bytes from CurWritePosition, */
298 /* but the payload still not copyed. the pTxContext->SavedPad[] will save as allzero. and set the bCopyPad = TRUE. */
299 /* 4. Interrupt complete. */
300 /* 5. Our interrupted routine go back and fill the first 8 bytes to pTxContext. */
301 /* 6. Next time when do bulk-out, it found the bCopyPad==TRUE and will copy the SavedPad[] to pTxContext->NextBulkOutPosition. */
302 /* and the packet will wrong. */
303 pHTTXContext->CurWriteRealPos +=
304 (TXINFO_SIZE + TXWI_SIZE + hwHdrLen);
305 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
306
307 NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData,
308 pTxBlk->SrcBufLen);
309 pWirelessPacket += pTxBlk->SrcBufLen;
310 NdisZeroMemory(pWirelessPacket, padding + 8);
311
312 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
313
314 pHTTXContext->CurWritePosition += pTxBlk->Priv;
315 if (bTxQLastRound)
316 pHTTXContext->CurWritePosition = 8;
317 pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
318
319 pHTTXContext->bCurWriting = FALSE;
320 }
321
322 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
323
324 /* succeed and release the skb buffer */
325 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
326
327 return (Status);
328
329}
330
331u16 RtmpUSB_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
332 struct rt_tx_blk *pTxBlk,
333 u8 frameNum, u16 * FreeNumber)
334{
335 struct rt_ht_tx_context *pHTTXContext;
336 u16 hwHdrLen; /* The hwHdrLen consist of 802.11 header length plus the header padding length. */
337 u32 fillOffset;
338 struct rt_txinfo *pTxInfo;
339 struct rt_txwi *pTxWI;
340 u8 *pWirelessPacket = NULL;
341 u8 QueIdx;
342 int Status;
343 unsigned long IrqFlags;
344 /*u32 USBDMApktLen = 0, DMAHdrLen, padding; */
345
346 /* */
347 /* get Tx Ring Resource & Dma Buffer address */
348 /* */
349 QueIdx = pTxBlk->QueIdx;
350 pHTTXContext = &pAd->TxContext[QueIdx];
351
352 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
353
354 if (frameNum == 0) {
355 /* Check if we have enough space for this bulk-out batch. */
356 Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext);
357 if (Status == NDIS_STATUS_SUCCESS) {
358 pHTTXContext->bCurWriting = TRUE;
359
360 pTxInfo = (struct rt_txinfo *)(&pTxBlk->HeaderBuf[0]);
361 pTxWI = (struct rt_txwi *) (&pTxBlk->HeaderBuf[TXINFO_SIZE]);
362
363 /* Reserve space for 8 bytes padding. */
364 if ((pHTTXContext->ENextBulkOutPosition ==
365 pHTTXContext->CurWritePosition)) {
366
367 pHTTXContext->CurWritePosition += 8;
368 pHTTXContext->ENextBulkOutPosition += 8;
369 }
370 fillOffset = pHTTXContext->CurWritePosition;
371 pHTTXContext->CurWriteRealPos =
372 pHTTXContext->CurWritePosition;
373
374 pWirelessPacket =
375 &pHTTXContext->TransferBuffer->field.
376 WirelessPacket[fillOffset];
377
378 /* */
379 /* Copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */
380 /* */
381 if (pTxBlk->TxFrameType == TX_AMSDU_FRAME)
382 /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD, 4)+LENGTH_AMSDU_SUBFRAMEHEAD; */
383 hwHdrLen =
384 pTxBlk->MpduHeaderLen -
385 LENGTH_AMSDU_SUBFRAMEHEAD +
386 pTxBlk->HdrPadLen +
387 LENGTH_AMSDU_SUBFRAMEHEAD;
388 else if (pTxBlk->TxFrameType == TX_RALINK_FRAME)
389 /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_ARALINK_HEADER_FIELD, 4)+LENGTH_ARALINK_HEADER_FIELD; */
390 hwHdrLen =
391 pTxBlk->MpduHeaderLen -
392 LENGTH_ARALINK_HEADER_FIELD +
393 pTxBlk->HdrPadLen +
394 LENGTH_ARALINK_HEADER_FIELD;
395 else
396 /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */
397 hwHdrLen =
398 pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen;
399
400 /* Update the pTxBlk->Priv. */
401 pTxBlk->Priv = TXINFO_SIZE + TXWI_SIZE + hwHdrLen;
402
403 /* pTxInfo->USBDMApktLen now just a temp value and will to correct latter. */
404 RTMPWriteTxInfo(pAd, pTxInfo, (u16)(pTxBlk->Priv),
405 FALSE, FIFO_EDCA, FALSE /*NextValid */ ,
406 FALSE);
407
408 /* Copy it. */
409 NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf,
410 pTxBlk->Priv);
411 pHTTXContext->CurWriteRealPos += pTxBlk->Priv;
412 pWirelessPacket += pTxBlk->Priv;
413 }
414 } else { /* For sub-sequent frames of this bulk-out batch. Just copy it to our bulk-out buffer. */
415
416 Status =
417 ((pHTTXContext->bCurWriting ==
418 TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE);
419 if (Status == NDIS_STATUS_SUCCESS) {
420 fillOffset =
421 (pHTTXContext->CurWritePosition + pTxBlk->Priv);
422 pWirelessPacket =
423 &pHTTXContext->TransferBuffer->field.
424 WirelessPacket[fillOffset];
425
426 /*hwHdrLen = pTxBlk->MpduHeaderLen; */
427 NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf,
428 pTxBlk->MpduHeaderLen);
429 pWirelessPacket += (pTxBlk->MpduHeaderLen);
430 pTxBlk->Priv += pTxBlk->MpduHeaderLen;
431 } else { /* It should not happened now unless we are going to shutdown. */
432 DBGPRINT(RT_DEBUG_ERROR,
433 ("WriteMultiTxResource():bCurWriting is FALSE when handle sub-sequent frames.\n"));
434 Status = NDIS_STATUS_FAILURE;
435 }
436 }
437
438 /* We unlock it here to prevent the first 8 bytes maybe over-write issue. */
439 /* 1. First we got CurWritePosition but the first 8 bytes still not write to the pTxContext. */
440 /* 2. An interrupt break our routine and handle bulk-out complete. */
441 /* 3. In the bulk-out compllete, it need to do another bulk-out, */
442 /* if the ENextBulkOutPosition is just the same as CurWritePosition, it will save the first 8 bytes from CurWritePosition, */
443 /* but the payload still not copyed. the pTxContext->SavedPad[] will save as allzero. and set the bCopyPad = TRUE. */
444 /* 4. Interrupt complete. */
445 /* 5. Our interrupted routine go back and fill the first 8 bytes to pTxContext. */
446 /* 6. Next time when do bulk-out, it found the bCopyPad==TRUE and will copy the SavedPad[] to pTxContext->NextBulkOutPosition. */
447 /* and the packet will wrong. */
448 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
449
450 if (Status != NDIS_STATUS_SUCCESS) {
451 DBGPRINT(RT_DEBUG_ERROR,
452 ("WriteMultiTxResource: CWPos = %ld, NBOutPos = %ld.\n",
453 pHTTXContext->CurWritePosition,
454 pHTTXContext->NextBulkOutPosition));
455 goto done;
456 }
457 /* Copy the frame content into DMA buffer and update the pTxBlk->Priv */
458 NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen);
459 pWirelessPacket += pTxBlk->SrcBufLen;
460 pTxBlk->Priv += pTxBlk->SrcBufLen;
461
462done:
463 /* Release the skb buffer here */
464 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS);
465
466 return (Status);
467
468}
469
470void RtmpUSB_FinalWriteTxResource(struct rt_rtmp_adapter *pAd,
471 struct rt_tx_blk *pTxBlk,
472 u16 totalMPDUSize, u16 TxIdx)
473{
474 u8 QueIdx;
475 struct rt_ht_tx_context *pHTTXContext;
476 u32 fillOffset;
477 struct rt_txinfo *pTxInfo;
478 struct rt_txwi *pTxWI;
479 u32 USBDMApktLen, padding;
480 unsigned long IrqFlags;
481 u8 *pWirelessPacket;
482
483 QueIdx = pTxBlk->QueIdx;
484 pHTTXContext = &pAd->TxContext[QueIdx];
485
486 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
487
488 if (pHTTXContext->bCurWriting == TRUE) {
489 fillOffset = pHTTXContext->CurWritePosition;
490 if (((pHTTXContext->ENextBulkOutPosition ==
491 pHTTXContext->CurWritePosition)
492 || ((pHTTXContext->ENextBulkOutPosition - 8) ==
493 pHTTXContext->CurWritePosition))
494 && (pHTTXContext->bCopySavePad == TRUE))
495 pWirelessPacket = (u8 *)(&pHTTXContext->SavedPad[0]);
496 else
497 pWirelessPacket =
498 (u8 *)(&pHTTXContext->TransferBuffer->field.
499 WirelessPacket[fillOffset]);
500
501 /* */
502 /* Update TxInfo->USBDMApktLen , */
503 /* the length = TXWI_SIZE + 802.11_hdr + 802.11_hdr_pad + payload_of_all_batch_frames + Bulk-Out-padding */
504 /* */
505 pTxInfo = (struct rt_txinfo *)(pWirelessPacket);
506
507 /* Calculate the bulk-out padding */
508 USBDMApktLen = pTxBlk->Priv - TXINFO_SIZE;
509 padding = (4 - (USBDMApktLen % 4)) & 0x03; /* round up to 4 byte alignment */
510 USBDMApktLen += padding;
511
512 pTxInfo->USBDMATxPktLen = USBDMApktLen;
513
514 /* */
515 /* Update TXWI->MPDUtotalByteCount , */
516 /* the length = 802.11 header + payload_of_all_batch_frames */
517 pTxWI = (struct rt_txwi *) (pWirelessPacket + TXINFO_SIZE);
518 pTxWI->MPDUtotalByteCount = totalMPDUSize;
519
520 /* */
521 /* Update the pHTTXContext->CurWritePosition */
522 /* */
523 pHTTXContext->CurWritePosition += (TXINFO_SIZE + USBDMApktLen);
524 if ((pHTTXContext->CurWritePosition + 3906) > MAX_TXBULK_LIMIT) { /* Add 3906 for prevent the NextBulkOut packet size is a A-RALINK/A-MSDU Frame. */
525 pHTTXContext->CurWritePosition = 8;
526 pTxInfo->SwUseLastRound = 1;
527 }
528 pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition;
529
530 /* */
531 /* Zero the last padding. */
532 /* */
533 pWirelessPacket =
534 (&pHTTXContext->TransferBuffer->field.
535 WirelessPacket[fillOffset + pTxBlk->Priv]);
536 NdisZeroMemory(pWirelessPacket, padding + 8);
537
538 /* Finally, set bCurWriting as FALSE */
539 pHTTXContext->bCurWriting = FALSE;
540
541 } else { /* It should not happened now unless we are going to shutdown. */
542 DBGPRINT(RT_DEBUG_ERROR,
543 ("FinalWriteTxResource():bCurWriting is FALSE when handle last frames.\n"));
544 }
545
546 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags);
547
548}
549
550void RtmpUSBDataLastTxIdx(struct rt_rtmp_adapter *pAd,
551 u8 QueIdx, u16 TxIdx)
552{
553 /* DO nothing for USB. */
554}
555
556/*
557 When can do bulk-out:
558 1. TxSwFreeIdx < TX_RING_SIZE;
559 It means has at least one Ring entity is ready for bulk-out, kick it out.
560 2. If TxSwFreeIdx == TX_RING_SIZE
561 Check if the CurWriting flag is FALSE, if it's FALSE, we can do kick out.
562
563*/
564void RtmpUSBDataKickOut(struct rt_rtmp_adapter *pAd,
565 struct rt_tx_blk *pTxBlk, u8 QueIdx)
566{
567 RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx));
568 RTUSBKickBulkOut(pAd);
569
570}
571
572/*
573 Must be run in Interrupt context
574 This function handle RT2870 specific TxDesc and cpu index update and kick the packet out.
575 */
576int RtmpUSBMgmtKickOut(struct rt_rtmp_adapter *pAd,
577 u8 QueIdx,
578 void *pPacket,
579 u8 *pSrcBufVA, u32 SrcBufLen)
580{
581 struct rt_txinfo *pTxInfo;
582 unsigned long BulkOutSize;
583 u8 padLen;
584 u8 *pDest;
585 unsigned long SwIdx = pAd->MgmtRing.TxCpuIdx;
586 struct rt_tx_context *pMLMEContext =
587 (struct rt_tx_context *)pAd->MgmtRing.Cell[SwIdx].AllocVa;
588 unsigned long IrqFlags;
589
590 pTxInfo = (struct rt_txinfo *)(pSrcBufVA);
591
592 /* Build our URB for USBD */
593 BulkOutSize = SrcBufLen;
594 BulkOutSize = (BulkOutSize + 3) & (~3);
595 RTMPWriteTxInfo(pAd, pTxInfo, (u16)(BulkOutSize - TXINFO_SIZE),
596 TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
597
598 BulkOutSize += 4; /* Always add 4 extra bytes at every packet. */
599
600 /* If BulkOutSize is multiple of BulkOutMaxPacketSize, add extra 4 bytes again. */
601 if ((BulkOutSize % pAd->BulkOutMaxPacketSize) == 0)
602 BulkOutSize += 4;
603
604 padLen = BulkOutSize - SrcBufLen;
605 ASSERT((padLen <= RTMP_PKT_TAIL_PADDING));
606
607 /* Now memzero all extra padding bytes. */
608 pDest = (u8 *)(pSrcBufVA + SrcBufLen);
609 skb_put(GET_OS_PKT_TYPE(pPacket), padLen);
610 NdisZeroMemory(pDest, padLen);
611
612 RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags);
613
614 pAd->MgmtRing.Cell[pAd->MgmtRing.TxCpuIdx].pNdisPacket = pPacket;
615 pMLMEContext->TransferBuffer =
616 (struct rt_tx_buffer *)(GET_OS_PKT_DATAPTR(pPacket));
617
618 /* Length in TxInfo should be 8 less than bulkout size. */
619 pMLMEContext->BulkOutSize = BulkOutSize;
620 pMLMEContext->InUse = TRUE;
621 pMLMEContext->bWaitingBulkOut = TRUE;
622
623 /*for debug */
624 /*hex_dump("RtmpUSBMgmtKickOut", &pMLMEContext->TransferBuffer->field.WirelessPacket[0], (pMLMEContext->BulkOutSize > 16 ? 16 : pMLMEContext->BulkOutSize)); */
625
626 /*pAd->RalinkCounters.KickTxCount++; */
627 /*pAd->RalinkCounters.OneSecTxDoneCount++; */
628
629 /*if (pAd->MgmtRing.TxSwFreeIdx == MGMT_RING_SIZE) */
630 /* needKickOut = TRUE; */
631
632 /* Decrease the TxSwFreeIdx and Increase the TX_CTX_IDX */
633 pAd->MgmtRing.TxSwFreeIdx--;
634 INC_RING_INDEX(pAd->MgmtRing.TxCpuIdx, MGMT_RING_SIZE);
635
636 RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags);
637
638 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
639 /*if (needKickOut) */
640 RTUSBKickBulkOut(pAd);
641
642 return 0;
643}
644
645void RtmpUSBNullFrameKickOut(struct rt_rtmp_adapter *pAd,
646 u8 QueIdx,
647 u8 * pNullFrame, u32 frameLen)
648{
649 if (pAd->NullContext.InUse == FALSE) {
650 struct rt_tx_context *pNullContext;
651 struct rt_txinfo *pTxInfo;
652 struct rt_txwi * pTxWI;
653 u8 *pWirelessPkt;
654
655 pNullContext = &(pAd->NullContext);
656
657 /* Set the in use bit */
658 pNullContext->InUse = TRUE;
659 pWirelessPkt =
660 (u8 *)& pNullContext->TransferBuffer->field.
661 WirelessPacket[0];
662
663 RTMPZeroMemory(&pWirelessPkt[0], 100);
664 pTxInfo = (struct rt_txinfo *)& pWirelessPkt[0];
665 RTMPWriteTxInfo(pAd, pTxInfo,
666 (u16)(sizeof(struct rt_header_802_11) + TXWI_SIZE),
667 TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
668 pTxInfo->QSEL = FIFO_EDCA;
669 pTxWI = (struct rt_txwi *) & pWirelessPkt[TXINFO_SIZE];
670 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE,
671 FALSE, 0, BSSID_WCID, (sizeof(struct rt_header_802_11)), 0,
672 0, (u8)pAd->CommonCfg.MlmeTransmit.field.MCS,
673 IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit);
674
675 RTMPMoveMemory(&pWirelessPkt[TXWI_SIZE + TXINFO_SIZE],
676 &pAd->NullFrame, sizeof(struct rt_header_802_11));
677 pAd->NullContext.BulkOutSize =
678 TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
679
680 /* Fill out frame length information for global Bulk out arbitor */
681 /*pNullContext->BulkOutSize = TransferBufferLength; */
682 DBGPRINT(RT_DEBUG_TRACE,
683 ("SYNC - send NULL Frame @%d Mbps...\n",
684 RateIdToMbps[pAd->CommonCfg.TxRate]));
685 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL);
686
687 /* Kick bulk out */
688 RTUSBKickBulkOut(pAd);
689 }
690
691}
692
693/*
694========================================================================
695Routine Description:
696 Get a received packet.
697
698Arguments:
699 pAd device control block
700 pSaveRxD receive descriptor information
701 *pbReschedule need reschedule flag
702 *pRxPending pending received packet flag
703
704Return Value:
705 the received packet
706
707Note:
708========================================================================
709*/
710void *GetPacketFromRxRing(struct rt_rtmp_adapter *pAd,
711 OUT PRT28XX_RXD_STRUC pSaveRxD,
712 OUT BOOLEAN * pbReschedule,
713 IN u32 * pRxPending)
714{
715 struct rt_rx_context *pRxContext;
716 void *pSkb;
717 u8 *pData;
718 unsigned long ThisFrameLen;
719 unsigned long RxBufferLength;
720 struct rt_rxwi * pRxWI;
721
722 pRxContext = &pAd->RxContext[pAd->NextRxBulkInReadIndex];
723 if ((pRxContext->Readable == FALSE) || (pRxContext->InUse == TRUE))
724 return NULL;
725
726 RxBufferLength = pRxContext->BulkInOffset - pAd->ReadPosition;
727 if (RxBufferLength <
728 (RT2870_RXDMALEN_FIELD_SIZE + sizeof(struct rt_rxwi) +
729 sizeof(struct rt_rxinfo))) {
730 goto label_null;
731 }
732
733 pData = &pRxContext->TransferBuffer[pAd->ReadPosition]; /* 4KB */
734 /* The RXDMA field is 4 bytes, now just use the first 2 bytes. The Length including the (RXWI + MSDU + Padding) */
735 ThisFrameLen = *pData + (*(pData + 1) << 8);
736 if (ThisFrameLen == 0) {
737 DBGPRINT(RT_DEBUG_TRACE,
738 ("BIRIdx(%d): RXDMALen is zero.[%ld], BulkInBufLen = %ld)\n",
739 pAd->NextRxBulkInReadIndex, ThisFrameLen,
740 pRxContext->BulkInOffset));
741 goto label_null;
742 }
743 if ((ThisFrameLen & 0x3) != 0) {
744 DBGPRINT(RT_DEBUG_ERROR,
745 ("BIRIdx(%d): RXDMALen not multiple of 4.[%ld], BulkInBufLen = %ld)\n",
746 pAd->NextRxBulkInReadIndex, ThisFrameLen,
747 pRxContext->BulkInOffset));
748 goto label_null;
749 }
750
751 if ((ThisFrameLen + 8) > RxBufferLength) /* 8 for (RT2870_RXDMALEN_FIELD_SIZE + sizeof(struct rt_rxinfo)) */
752 {
753 DBGPRINT(RT_DEBUG_TRACE,
754 ("BIRIdx(%d):FrameLen(0x%lx) outranges. BulkInLen=0x%lx, remaining RxBufLen=0x%lx, ReadPos=0x%lx\n",
755 pAd->NextRxBulkInReadIndex, ThisFrameLen,
756 pRxContext->BulkInOffset, RxBufferLength,
757 pAd->ReadPosition));
758
759 /* error frame. finish this loop */
760 goto label_null;
761 }
762 /* skip USB frame length field */
763 pData += RT2870_RXDMALEN_FIELD_SIZE;
764 pRxWI = (struct rt_rxwi *) pData;
765 if (pRxWI->MPDUtotalByteCount > ThisFrameLen) {
766 DBGPRINT(RT_DEBUG_ERROR,
767 ("%s():pRxWIMPDUtotalByteCount(%d) large than RxDMALen(%ld)\n",
768 __FUNCTION__, pRxWI->MPDUtotalByteCount,
769 ThisFrameLen));
770 goto label_null;
771 }
772 /* allocate a rx packet */
773 pSkb = dev_alloc_skb(ThisFrameLen);
774 if (pSkb == NULL) {
775 DBGPRINT(RT_DEBUG_ERROR,
776 ("%s():Cannot Allocate sk buffer for this Bulk-In buffer!\n",
777 __FUNCTION__));
778 goto label_null;
779 }
780 /* copy the rx packet */
781 memcpy(skb_put(pSkb, ThisFrameLen), pData, ThisFrameLen);
782 RTPKT_TO_OSPKT(pSkb)->dev = get_netdev_from_bssid(pAd, BSS0);
783 RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pSkb), PKTSRC_NDIS);
784
785 /* copy RxD */
786 *pSaveRxD = *(struct rt_rxinfo *) (pData + ThisFrameLen);
787
788 /* update next packet read position. */
789 pAd->ReadPosition += (ThisFrameLen + RT2870_RXDMALEN_FIELD_SIZE + RXINFO_SIZE); /* 8 for (RT2870_RXDMALEN_FIELD_SIZE + sizeof(struct rt_rxinfo)) */
790
791 return pSkb;
792
793label_null:
794
795 return NULL;
796}
797
798/*
799 ========================================================================
800
801 Routine Description:
802 Check Rx descriptor, return NDIS_STATUS_FAILURE if any error dound
803
804 Arguments:
805 pRxD Pointer to the Rx descriptor
806
807 Return Value:
808 NDIS_STATUS_SUCCESS No err
809 NDIS_STATUS_FAILURE Error
810
811 Note:
812
813 ========================================================================
814*/
815int RTMPCheckRxError(struct rt_rtmp_adapter *pAd,
816 struct rt_header_802_11 * pHeader,
817 struct rt_rxwi * pRxWI, IN PRT28XX_RXD_STRUC pRxINFO)
818{
819 struct rt_cipher_key *pWpaKey;
820 int dBm;
821
822 if (pAd->bPromiscuous == TRUE)
823 return (NDIS_STATUS_SUCCESS);
824 if (pRxINFO == NULL)
825 return (NDIS_STATUS_FAILURE);
826
827 /* Phy errors & CRC errors */
828 if (pRxINFO->Crc) {
829 /* Check RSSI for Noise Hist statistic collection. */
830 dBm = (int)(pRxWI->RSSI0) - pAd->BbpRssiToDbmDelta;
831 if (dBm <= -87)
832 pAd->StaCfg.RPIDensity[0] += 1;
833 else if (dBm <= -82)
834 pAd->StaCfg.RPIDensity[1] += 1;
835 else if (dBm <= -77)
836 pAd->StaCfg.RPIDensity[2] += 1;
837 else if (dBm <= -72)
838 pAd->StaCfg.RPIDensity[3] += 1;
839 else if (dBm <= -67)
840 pAd->StaCfg.RPIDensity[4] += 1;
841 else if (dBm <= -62)
842 pAd->StaCfg.RPIDensity[5] += 1;
843 else if (dBm <= -57)
844 pAd->StaCfg.RPIDensity[6] += 1;
845 else if (dBm > -57)
846 pAd->StaCfg.RPIDensity[7] += 1;
847
848 return (NDIS_STATUS_FAILURE);
849 }
850 /* Add Rx size to channel load counter, we should ignore error counts */
851 pAd->StaCfg.CLBusyBytes += (pRxWI->MPDUtotalByteCount + 14);
852
853 /* Drop ToDs promiscuous frame, it is opened due to CCX 2 channel load statistics */
854 if (pHeader->FC.ToDs) {
855 DBGPRINT_RAW(RT_DEBUG_ERROR, ("Err;FC.ToDs\n"));
856 return NDIS_STATUS_FAILURE;
857 }
858 /* Paul 04-03 for OFDM Rx length issue */
859 if (pRxWI->MPDUtotalByteCount > MAX_AGGREGATION_SIZE) {
860 DBGPRINT_RAW(RT_DEBUG_ERROR, ("received packet too long\n"));
861 return NDIS_STATUS_FAILURE;
862 }
863 /* Drop not U2M frames, can't's drop here because we will drop beacon in this case */
864 /* I am kind of doubting the U2M bit operation */
865 /* if (pRxD->U2M == 0) */
866 /* return(NDIS_STATUS_FAILURE); */
867
868 /* drop decyption fail frame */
869 if (pRxINFO->Decrypted && pRxINFO->CipherErr) {
870
871 if (((pRxINFO->CipherErr & 1) == 1)
872 && pAd->CommonCfg.bWirelessEvent && INFRA_ON(pAd))
873 RTMPSendWirelessEvent(pAd, IW_ICV_ERROR_EVENT_FLAG,
874 pAd->MacTab.Content[BSSID_WCID].
875 Addr, BSS0, 0);
876
877 if (((pRxINFO->CipherErr & 2) == 2)
878 && pAd->CommonCfg.bWirelessEvent && INFRA_ON(pAd))
879 RTMPSendWirelessEvent(pAd, IW_MIC_ERROR_EVENT_FLAG,
880 pAd->MacTab.Content[BSSID_WCID].
881 Addr, BSS0, 0);
882 /* */
883 /* MIC Error */
884 /* */
885 if ((pRxINFO->CipherErr == 2) && pRxINFO->MyBss) {
886 pWpaKey = &pAd->SharedKey[BSS0][pRxWI->KeyIndex];
887 RTMPReportMicError(pAd, pWpaKey);
888 DBGPRINT_RAW(RT_DEBUG_ERROR, ("Rx MIC Value error\n"));
889 }
890
891 if (pRxINFO->Decrypted &&
892 (pAd->SharedKey[BSS0][pRxWI->KeyIndex].CipherAlg ==
893 CIPHER_AES)
894 && (pHeader->Sequence == pAd->FragFrame.Sequence)) {
895 /* */
896 /* Acceptable since the First FragFrame no CipherErr problem. */
897 /* */
898 return (NDIS_STATUS_SUCCESS);
899 }
900
901 return (NDIS_STATUS_FAILURE);
902 }
903
904 return (NDIS_STATUS_SUCCESS);
905}
906
907void RtmpUsbStaAsicForceWakeupTimeout(void *SystemSpecific1,
908 void *FunctionContext,
909 void *SystemSpecific2,
910 void *SystemSpecific3)
911{
912 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
913
914 if (pAd && pAd->Mlme.AutoWakeupTimerRunning) {
915 AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02);
916
917 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
918 pAd->Mlme.AutoWakeupTimerRunning = FALSE;
919 }
920}
921
922void RT28xxUsbStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx)
923{
924 BOOLEAN Canceled;
925
926 if (pAd->Mlme.AutoWakeupTimerRunning)
927 RTMPCancelTimer(&pAd->Mlme.AutoWakeupTimer, &Canceled);
928
929 AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02);
930
931 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
932}
933
934void RT28xxUsbStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
935 u16 TbttNumToNextWakeUp)
936{
937
938 /* we have decided to SLEEP, so at least do it for a BEACON period. */
939 if (TbttNumToNextWakeUp == 0)
940 TbttNumToNextWakeUp = 1;
941
942 RTMPSetTimer(&pAd->Mlme.AutoWakeupTimer, AUTO_WAKEUP_TIMEOUT);
943 pAd->Mlme.AutoWakeupTimerRunning = TRUE;
944
945 AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02); /* send POWER-SAVE command to MCU. Timeout 40us. */
946
947 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_DOZE);
948
949}
950
951#endif /* RTMP_MAC_USB // */
diff --git a/drivers/staging/rt2860/common/cmm_info.c b/drivers/staging/rt2860/common/cmm_info.c
deleted file mode 100644
index 25302e8363b..00000000000
--- a/drivers/staging/rt2860/common/cmm_info.c
+++ /dev/null
@@ -1,955 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28#include <linux/sched.h>
29#include "../rt_config.h"
30
31/*
32 ========================================================================
33
34 Routine Description:
35 Remove WPA Key process
36
37 Arguments:
38 pAd Pointer to our adapter
39 pBuf Pointer to the where the key stored
40
41 Return Value:
42 NDIS_SUCCESS Add key successfully
43
44 IRQL = DISPATCH_LEVEL
45
46 Note:
47
48 ========================================================================
49*/
50void RTMPSetDesiredRates(struct rt_rtmp_adapter *pAdapter, long Rates)
51{
52 NDIS_802_11_RATES aryRates;
53
54 memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
55 switch (pAdapter->CommonCfg.PhyMode) {
56 case PHY_11A: /* A only */
57 switch (Rates) {
58 case 6000000: /*6M */
59 aryRates[0] = 0x0c; /* 6M */
60 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
61 MCS_0;
62 break;
63 case 9000000: /*9M */
64 aryRates[0] = 0x12; /* 9M */
65 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
66 MCS_1;
67 break;
68 case 12000000: /*12M */
69 aryRates[0] = 0x18; /* 12M */
70 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
71 MCS_2;
72 break;
73 case 18000000: /*18M */
74 aryRates[0] = 0x24; /* 18M */
75 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
76 MCS_3;
77 break;
78 case 24000000: /*24M */
79 aryRates[0] = 0x30; /* 24M */
80 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
81 MCS_4;
82 break;
83 case 36000000: /*36M */
84 aryRates[0] = 0x48; /* 36M */
85 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
86 MCS_5;
87 break;
88 case 48000000: /*48M */
89 aryRates[0] = 0x60; /* 48M */
90 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
91 MCS_6;
92 break;
93 case 54000000: /*54M */
94 aryRates[0] = 0x6c; /* 54M */
95 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
96 MCS_7;
97 break;
98 case -1: /*Auto */
99 default:
100 aryRates[0] = 0x6c; /* 54Mbps */
101 aryRates[1] = 0x60; /* 48Mbps */
102 aryRates[2] = 0x48; /* 36Mbps */
103 aryRates[3] = 0x30; /* 24Mbps */
104 aryRates[4] = 0x24; /* 18M */
105 aryRates[5] = 0x18; /* 12M */
106 aryRates[6] = 0x12; /* 9M */
107 aryRates[7] = 0x0c; /* 6M */
108 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
109 MCS_AUTO;
110 break;
111 }
112 break;
113 case PHY_11BG_MIXED: /* B/G Mixed */
114 case PHY_11B: /* B only */
115 case PHY_11ABG_MIXED: /* A/B/G Mixed */
116 default:
117 switch (Rates) {
118 case 1000000: /*1M */
119 aryRates[0] = 0x02;
120 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
121 MCS_0;
122 break;
123 case 2000000: /*2M */
124 aryRates[0] = 0x04;
125 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
126 MCS_1;
127 break;
128 case 5000000: /*5.5M */
129 aryRates[0] = 0x0b; /* 5.5M */
130 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
131 MCS_2;
132 break;
133 case 11000000: /*11M */
134 aryRates[0] = 0x16; /* 11M */
135 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
136 MCS_3;
137 break;
138 case 6000000: /*6M */
139 aryRates[0] = 0x0c; /* 6M */
140 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
141 MCS_0;
142 break;
143 case 9000000: /*9M */
144 aryRates[0] = 0x12; /* 9M */
145 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
146 MCS_1;
147 break;
148 case 12000000: /*12M */
149 aryRates[0] = 0x18; /* 12M */
150 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
151 MCS_2;
152 break;
153 case 18000000: /*18M */
154 aryRates[0] = 0x24; /* 18M */
155 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
156 MCS_3;
157 break;
158 case 24000000: /*24M */
159 aryRates[0] = 0x30; /* 24M */
160 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
161 MCS_4;
162 break;
163 case 36000000: /*36M */
164 aryRates[0] = 0x48; /* 36M */
165 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
166 MCS_5;
167 break;
168 case 48000000: /*48M */
169 aryRates[0] = 0x60; /* 48M */
170 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
171 MCS_6;
172 break;
173 case 54000000: /*54M */
174 aryRates[0] = 0x6c; /* 54M */
175 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
176 MCS_7;
177 break;
178 case -1: /*Auto */
179 default:
180 if (pAdapter->CommonCfg.PhyMode == PHY_11B) { /*B Only */
181 aryRates[0] = 0x16; /* 11Mbps */
182 aryRates[1] = 0x0b; /* 5.5Mbps */
183 aryRates[2] = 0x04; /* 2Mbps */
184 aryRates[3] = 0x02; /* 1Mbps */
185 } else { /*(B/G) Mixed or (A/B/G) Mixed */
186 aryRates[0] = 0x6c; /* 54Mbps */
187 aryRates[1] = 0x60; /* 48Mbps */
188 aryRates[2] = 0x48; /* 36Mbps */
189 aryRates[3] = 0x30; /* 24Mbps */
190 aryRates[4] = 0x16; /* 11Mbps */
191 aryRates[5] = 0x0b; /* 5.5Mbps */
192 aryRates[6] = 0x04; /* 2Mbps */
193 aryRates[7] = 0x02; /* 1Mbps */
194 }
195 pAdapter->StaCfg.DesiredTransmitSetting.field.MCS =
196 MCS_AUTO;
197 break;
198 }
199 break;
200 }
201
202 NdisZeroMemory(pAdapter->CommonCfg.DesireRate,
203 MAX_LEN_OF_SUPPORTED_RATES);
204 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates,
205 sizeof(NDIS_802_11_RATES));
206 DBGPRINT(RT_DEBUG_TRACE,
207 (" RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
208 pAdapter->CommonCfg.DesireRate[0],
209 pAdapter->CommonCfg.DesireRate[1],
210 pAdapter->CommonCfg.DesireRate[2],
211 pAdapter->CommonCfg.DesireRate[3],
212 pAdapter->CommonCfg.DesireRate[4],
213 pAdapter->CommonCfg.DesireRate[5],
214 pAdapter->CommonCfg.DesireRate[6],
215 pAdapter->CommonCfg.DesireRate[7]));
216 /* Changing DesiredRate may affect the MAX TX rate we used to TX frames out */
217 MlmeUpdateTxRates(pAdapter, FALSE, 0);
218}
219
220/*
221 ========================================================================
222
223 Routine Description:
224 Remove All WPA Keys
225
226 Arguments:
227 pAd Pointer to our adapter
228
229 Return Value:
230 None
231
232 IRQL = DISPATCH_LEVEL
233
234 Note:
235
236 ========================================================================
237*/
238void RTMPWPARemoveAllKeys(struct rt_rtmp_adapter *pAd)
239{
240
241 u8 i;
242
243 DBGPRINT(RT_DEBUG_TRACE,
244 ("RTMPWPARemoveAllKeys(AuthMode=%d, WepStatus=%d)\n",
245 pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus));
246 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
247 /* For WEP/CKIP, there is no need to remove it, since WinXP won't set it again after */
248 /* Link up. And it will be replaced if user changed it. */
249 if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
250 return;
251
252 /* For WPA-None, there is no need to remove it, since WinXP won't set it again after */
253 /* Link up. And it will be replaced if user changed it. */
254 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
255 return;
256
257 /* set BSSID wcid entry of the Pair-wise Key table as no-security mode */
258 AsicRemovePairwiseKeyEntry(pAd, BSS0, BSSID_WCID);
259
260 /* set all shared key mode as no-security. */
261 for (i = 0; i < SHARE_KEY_NUM; i++) {
262 DBGPRINT(RT_DEBUG_TRACE,
263 ("remove %s key #%d\n",
264 CipherName[pAd->SharedKey[BSS0][i].CipherAlg], i));
265 NdisZeroMemory(&pAd->SharedKey[BSS0][i], sizeof(struct rt_cipher_key));
266
267 AsicRemoveSharedKeyEntry(pAd, BSS0, i);
268 }
269 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
270}
271
272/*
273 ========================================================================
274
275 Routine Description:
276 As STA's BSSID is a WC too, it uses shared key table.
277 This function write correct unicast TX key to ASIC WCID.
278 And we still make a copy in our MacTab.Content[BSSID_WCID].PairwiseKey.
279 Caller guarantee TKIP/AES always has keyidx = 0. (pairwise key)
280 Caller guarantee WEP calls this function when set Txkey, default key index=0~3.
281
282 Arguments:
283 pAd Pointer to our adapter
284 pKey Pointer to the where the key stored
285
286 Return Value:
287 NDIS_SUCCESS Add key successfully
288
289 IRQL = DISPATCH_LEVEL
290
291 Note:
292
293 ========================================================================
294*/
295/*
296 ========================================================================
297 Routine Description:
298 Change NIC PHY mode. Re-association may be necessary. possible settings
299 include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED
300
301 Arguments:
302 pAd - Pointer to our adapter
303 phymode -
304
305 IRQL = PASSIVE_LEVEL
306 IRQL = DISPATCH_LEVEL
307
308 ========================================================================
309*/
310void RTMPSetPhyMode(struct rt_rtmp_adapter *pAd, unsigned long phymode)
311{
312 int i;
313 /* the selected phymode must be supported by the RF IC encoded in E2PROM */
314
315 /* if no change, do nothing */
316 /* bug fix
317 if (pAd->CommonCfg.PhyMode == phymode)
318 return;
319 */
320 pAd->CommonCfg.PhyMode = (u8)phymode;
321
322 DBGPRINT(RT_DEBUG_TRACE,
323 ("RTMPSetPhyMode : PhyMode=%d, channel=%d \n",
324 pAd->CommonCfg.PhyMode, pAd->CommonCfg.Channel));
325
326 BuildChannelList(pAd);
327
328 /* sanity check user setting */
329 for (i = 0; i < pAd->ChannelListNum; i++) {
330 if (pAd->CommonCfg.Channel == pAd->ChannelList[i].Channel)
331 break;
332 }
333
334 if (i == pAd->ChannelListNum) {
335 pAd->CommonCfg.Channel = FirstChannel(pAd);
336 DBGPRINT(RT_DEBUG_ERROR,
337 ("RTMPSetPhyMode: channel is out of range, use first channel=%d \n",
338 pAd->CommonCfg.Channel));
339 }
340
341 NdisZeroMemory(pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
342 NdisZeroMemory(pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
343 NdisZeroMemory(pAd->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
344 switch (phymode) {
345 case PHY_11B:
346 pAd->CommonCfg.SupRate[0] = 0x82; /* 1 mbps, in units of 0.5 Mbps, basic rate */
347 pAd->CommonCfg.SupRate[1] = 0x84; /* 2 mbps, in units of 0.5 Mbps, basic rate */
348 pAd->CommonCfg.SupRate[2] = 0x8B; /* 5.5 mbps, in units of 0.5 Mbps, basic rate */
349 pAd->CommonCfg.SupRate[3] = 0x96; /* 11 mbps, in units of 0.5 Mbps, basic rate */
350 pAd->CommonCfg.SupRateLen = 4;
351 pAd->CommonCfg.ExtRateLen = 0;
352 pAd->CommonCfg.DesireRate[0] = 2; /* 1 mbps, in units of 0.5 Mbps */
353 pAd->CommonCfg.DesireRate[1] = 4; /* 2 mbps, in units of 0.5 Mbps */
354 pAd->CommonCfg.DesireRate[2] = 11; /* 5.5 mbps, in units of 0.5 Mbps */
355 pAd->CommonCfg.DesireRate[3] = 22; /* 11 mbps, in units of 0.5 Mbps */
356 /*pAd->CommonCfg.HTPhyMode.field.MODE = MODE_CCK; // This MODE is only FYI. not use */
357 break;
358
359 case PHY_11G:
360 case PHY_11BG_MIXED:
361 case PHY_11ABG_MIXED:
362 case PHY_11N_2_4G:
363 case PHY_11ABGN_MIXED:
364 case PHY_11BGN_MIXED:
365 case PHY_11GN_MIXED:
366 pAd->CommonCfg.SupRate[0] = 0x82; /* 1 mbps, in units of 0.5 Mbps, basic rate */
367 pAd->CommonCfg.SupRate[1] = 0x84; /* 2 mbps, in units of 0.5 Mbps, basic rate */
368 pAd->CommonCfg.SupRate[2] = 0x8B; /* 5.5 mbps, in units of 0.5 Mbps, basic rate */
369 pAd->CommonCfg.SupRate[3] = 0x96; /* 11 mbps, in units of 0.5 Mbps, basic rate */
370 pAd->CommonCfg.SupRate[4] = 0x12; /* 9 mbps, in units of 0.5 Mbps */
371 pAd->CommonCfg.SupRate[5] = 0x24; /* 18 mbps, in units of 0.5 Mbps */
372 pAd->CommonCfg.SupRate[6] = 0x48; /* 36 mbps, in units of 0.5 Mbps */
373 pAd->CommonCfg.SupRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */
374 pAd->CommonCfg.SupRateLen = 8;
375 pAd->CommonCfg.ExtRate[0] = 0x0C; /* 6 mbps, in units of 0.5 Mbps */
376 pAd->CommonCfg.ExtRate[1] = 0x18; /* 12 mbps, in units of 0.5 Mbps */
377 pAd->CommonCfg.ExtRate[2] = 0x30; /* 24 mbps, in units of 0.5 Mbps */
378 pAd->CommonCfg.ExtRate[3] = 0x60; /* 48 mbps, in units of 0.5 Mbps */
379 pAd->CommonCfg.ExtRateLen = 4;
380 pAd->CommonCfg.DesireRate[0] = 2; /* 1 mbps, in units of 0.5 Mbps */
381 pAd->CommonCfg.DesireRate[1] = 4; /* 2 mbps, in units of 0.5 Mbps */
382 pAd->CommonCfg.DesireRate[2] = 11; /* 5.5 mbps, in units of 0.5 Mbps */
383 pAd->CommonCfg.DesireRate[3] = 22; /* 11 mbps, in units of 0.5 Mbps */
384 pAd->CommonCfg.DesireRate[4] = 12; /* 6 mbps, in units of 0.5 Mbps */
385 pAd->CommonCfg.DesireRate[5] = 18; /* 9 mbps, in units of 0.5 Mbps */
386 pAd->CommonCfg.DesireRate[6] = 24; /* 12 mbps, in units of 0.5 Mbps */
387 pAd->CommonCfg.DesireRate[7] = 36; /* 18 mbps, in units of 0.5 Mbps */
388 pAd->CommonCfg.DesireRate[8] = 48; /* 24 mbps, in units of 0.5 Mbps */
389 pAd->CommonCfg.DesireRate[9] = 72; /* 36 mbps, in units of 0.5 Mbps */
390 pAd->CommonCfg.DesireRate[10] = 96; /* 48 mbps, in units of 0.5 Mbps */
391 pAd->CommonCfg.DesireRate[11] = 108; /* 54 mbps, in units of 0.5 Mbps */
392 break;
393
394 case PHY_11A:
395 case PHY_11AN_MIXED:
396 case PHY_11AGN_MIXED:
397 case PHY_11N_5G:
398 pAd->CommonCfg.SupRate[0] = 0x8C; /* 6 mbps, in units of 0.5 Mbps, basic rate */
399 pAd->CommonCfg.SupRate[1] = 0x12; /* 9 mbps, in units of 0.5 Mbps */
400 pAd->CommonCfg.SupRate[2] = 0x98; /* 12 mbps, in units of 0.5 Mbps, basic rate */
401 pAd->CommonCfg.SupRate[3] = 0x24; /* 18 mbps, in units of 0.5 Mbps */
402 pAd->CommonCfg.SupRate[4] = 0xb0; /* 24 mbps, in units of 0.5 Mbps, basic rate */
403 pAd->CommonCfg.SupRate[5] = 0x48; /* 36 mbps, in units of 0.5 Mbps */
404 pAd->CommonCfg.SupRate[6] = 0x60; /* 48 mbps, in units of 0.5 Mbps */
405 pAd->CommonCfg.SupRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */
406 pAd->CommonCfg.SupRateLen = 8;
407 pAd->CommonCfg.ExtRateLen = 0;
408 pAd->CommonCfg.DesireRate[0] = 12; /* 6 mbps, in units of 0.5 Mbps */
409 pAd->CommonCfg.DesireRate[1] = 18; /* 9 mbps, in units of 0.5 Mbps */
410 pAd->CommonCfg.DesireRate[2] = 24; /* 12 mbps, in units of 0.5 Mbps */
411 pAd->CommonCfg.DesireRate[3] = 36; /* 18 mbps, in units of 0.5 Mbps */
412 pAd->CommonCfg.DesireRate[4] = 48; /* 24 mbps, in units of 0.5 Mbps */
413 pAd->CommonCfg.DesireRate[5] = 72; /* 36 mbps, in units of 0.5 Mbps */
414 pAd->CommonCfg.DesireRate[6] = 96; /* 48 mbps, in units of 0.5 Mbps */
415 pAd->CommonCfg.DesireRate[7] = 108; /* 54 mbps, in units of 0.5 Mbps */
416 /*pAd->CommonCfg.HTPhyMode.field.MODE = MODE_OFDM; // This MODE is only FYI. not use */
417 break;
418
419 default:
420 break;
421 }
422
423 pAd->CommonCfg.BandState = UNKNOWN_BAND;
424}
425
426/*
427 ========================================================================
428 Routine Description:
429 Caller ensures we has 802.11n support.
430 Calls at setting HT from AP/STASetinformation
431
432 Arguments:
433 pAd - Pointer to our adapter
434 phymode -
435
436 ========================================================================
437*/
438void RTMPSetHT(struct rt_rtmp_adapter *pAd, struct rt_oid_set_ht_phymode *pHTPhyMode)
439{
440 /*unsigned long *pmcs; */
441 u32 Value = 0;
442 u8 BBPValue = 0;
443 u8 BBP3Value = 0;
444 u8 RxStream = pAd->CommonCfg.RxStream;
445
446 DBGPRINT(RT_DEBUG_TRACE,
447 ("RTMPSetHT : HT_mode(%d), ExtOffset(%d), MCS(%d), BW(%d), STBC(%d), SHORTGI(%d)\n",
448 pHTPhyMode->HtMode, pHTPhyMode->ExtOffset, pHTPhyMode->MCS,
449 pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
450
451 /* Don't zero supportedHyPhy structure. */
452 RTMPZeroMemory(&pAd->CommonCfg.HtCapability,
453 sizeof(pAd->CommonCfg.HtCapability));
454 RTMPZeroMemory(&pAd->CommonCfg.AddHTInfo,
455 sizeof(pAd->CommonCfg.AddHTInfo));
456 RTMPZeroMemory(&pAd->CommonCfg.NewExtChanOffset,
457 sizeof(pAd->CommonCfg.NewExtChanOffset));
458 RTMPZeroMemory(&pAd->CommonCfg.DesiredHtPhy,
459 sizeof(pAd->CommonCfg.DesiredHtPhy));
460
461 if (pAd->CommonCfg.bRdg) {
462 pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 1;
463 pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 1;
464 } else {
465 pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 0;
466 pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 0;
467 }
468
469 pAd->CommonCfg.HtCapability.HtCapParm.MaxRAmpduFactor = 3;
470 pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor = 3;
471
472 DBGPRINT(RT_DEBUG_TRACE,
473 ("RTMPSetHT : RxBAWinLimit = %d\n",
474 pAd->CommonCfg.BACapability.field.RxBAWinLimit));
475
476 /* Mimo power save, A-MSDU size, */
477 pAd->CommonCfg.DesiredHtPhy.AmsduEnable =
478 (u16)pAd->CommonCfg.BACapability.field.AmsduEnable;
479 pAd->CommonCfg.DesiredHtPhy.AmsduSize =
480 (u8)pAd->CommonCfg.BACapability.field.AmsduSize;
481 pAd->CommonCfg.DesiredHtPhy.MimoPs =
482 (u8)pAd->CommonCfg.BACapability.field.MMPSmode;
483 pAd->CommonCfg.DesiredHtPhy.MpduDensity =
484 (u8)pAd->CommonCfg.BACapability.field.MpduDensity;
485
486 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize =
487 (u16)pAd->CommonCfg.BACapability.field.AmsduSize;
488 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs =
489 (u16)pAd->CommonCfg.BACapability.field.MMPSmode;
490 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity =
491 (u8)pAd->CommonCfg.BACapability.field.MpduDensity;
492
493 DBGPRINT(RT_DEBUG_TRACE,
494 ("RTMPSetHT : AMsduSize = %d, MimoPs = %d, MpduDensity = %d, MaxRAmpduFactor = %d\n",
495 pAd->CommonCfg.DesiredHtPhy.AmsduSize,
496 pAd->CommonCfg.DesiredHtPhy.MimoPs,
497 pAd->CommonCfg.DesiredHtPhy.MpduDensity,
498 pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor));
499
500 if (pHTPhyMode->HtMode == HTMODE_GF) {
501 pAd->CommonCfg.HtCapability.HtCapInfo.GF = 1;
502 pAd->CommonCfg.DesiredHtPhy.GF = 1;
503 } else
504 pAd->CommonCfg.DesiredHtPhy.GF = 0;
505
506 /* Decide Rx MCSSet */
507 switch (RxStream) {
508 case 1:
509 pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
510 pAd->CommonCfg.HtCapability.MCSSet[1] = 0x00;
511 break;
512
513 case 2:
514 pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
515 pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff;
516 break;
517
518 case 3: /* 3*3 */
519 pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff;
520 pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff;
521 pAd->CommonCfg.HtCapability.MCSSet[2] = 0xff;
522 break;
523 }
524
525 if (pAd->CommonCfg.bForty_Mhz_Intolerant
526 && (pAd->CommonCfg.Channel <= 14) && (pHTPhyMode->BW == BW_40)) {
527 pHTPhyMode->BW = BW_20;
528 pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant = 1;
529 }
530
531 if (pHTPhyMode->BW == BW_40) {
532 pAd->CommonCfg.HtCapability.MCSSet[4] = 0x1; /* MCS 32 */
533 pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 1;
534 if (pAd->CommonCfg.Channel <= 14)
535 pAd->CommonCfg.HtCapability.HtCapInfo.CCKmodein40 = 1;
536
537 pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 1;
538 pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 1;
539 pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset =
540 (pHTPhyMode->ExtOffset ==
541 EXTCHA_BELOW) ? (EXTCHA_BELOW) : EXTCHA_ABOVE;
542 /* Set Regsiter for extension channel position. */
543 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
544 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBP3Value);
545 if ((pHTPhyMode->ExtOffset == EXTCHA_BELOW)) {
546 Value |= 0x1;
547 BBP3Value |= (0x20);
548 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
549 } else if ((pHTPhyMode->ExtOffset == EXTCHA_ABOVE)) {
550 Value &= 0xfe;
551 BBP3Value &= (~0x20);
552 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
553 }
554 /* Turn on BBP 40MHz mode now only as AP . */
555 /* Sta can turn on BBP 40MHz after connection with 40MHz AP. Sta only broadcast 40MHz capability before connection. */
556 if ((pAd->OpMode == OPMODE_AP) || INFRA_ON(pAd) || ADHOC_ON(pAd)
557 ) {
558 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
559 BBPValue &= (~0x18);
560 BBPValue |= 0x10;
561 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
562
563 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBP3Value);
564 pAd->CommonCfg.BBPCurrentBW = BW_40;
565 }
566 } else {
567 pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 0;
568 pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 0;
569 pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 0;
570 pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = EXTCHA_NONE;
571 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
572 /* Turn on BBP 20MHz mode by request here. */
573 {
574 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
575 BBPValue &= (~0x18);
576 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
577 pAd->CommonCfg.BBPCurrentBW = BW_20;
578 }
579 }
580
581 if (pHTPhyMode->STBC == STBC_USE) {
582 pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 1;
583 pAd->CommonCfg.DesiredHtPhy.TxSTBC = 1;
584 pAd->CommonCfg.HtCapability.HtCapInfo.RxSTBC = 1;
585 pAd->CommonCfg.DesiredHtPhy.RxSTBC = 1;
586 } else {
587 pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0;
588 pAd->CommonCfg.DesiredHtPhy.RxSTBC = 0;
589 }
590
591 if (pHTPhyMode->SHORTGI == GI_400) {
592 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 1;
593 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 1;
594 pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 1;
595 pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 1;
596 } else {
597 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 0;
598 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 0;
599 pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 0;
600 pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 0;
601 }
602
603 /* We support link adaptation for unsolicit MCS feedback, set to 2. */
604 pAd->CommonCfg.HtCapability.ExtHtCapInfo.MCSFeedback = MCSFBK_NONE; /*MCSFBK_UNSOLICIT; */
605 pAd->CommonCfg.AddHTInfo.ControlChan = pAd->CommonCfg.Channel;
606 /* 1, the extension channel above the control channel. */
607
608 /* EDCA parameters used for AP's own transmission */
609 if (pAd->CommonCfg.APEdcaParm.bValid == FALSE) {
610 pAd->CommonCfg.APEdcaParm.bValid = TRUE;
611 pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
612 pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
613 pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
614 pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
615
616 pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
617 pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
618 pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
619 pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
620
621 pAd->CommonCfg.APEdcaParm.Cwmax[0] = 6;
622 pAd->CommonCfg.APEdcaParm.Cwmax[1] = 10;
623 pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
624 pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
625
626 pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
627 pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
628 pAd->CommonCfg.APEdcaParm.Txop[2] = 94;
629 pAd->CommonCfg.APEdcaParm.Txop[3] = 47;
630 }
631 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
632
633 {
634 RTMPSetIndividualHT(pAd, 0);
635 }
636
637}
638
639/*
640 ========================================================================
641 Routine Description:
642 Caller ensures we has 802.11n support.
643 Calls at setting HT from AP/STASetinformation
644
645 Arguments:
646 pAd - Pointer to our adapter
647 phymode -
648
649 ========================================================================
650*/
651void RTMPSetIndividualHT(struct rt_rtmp_adapter *pAd, u8 apidx)
652{
653 struct rt_ht_phy_info *pDesired_ht_phy = NULL;
654 u8 TxStream = pAd->CommonCfg.TxStream;
655 u8 DesiredMcs = MCS_AUTO;
656
657 do {
658 {
659 pDesired_ht_phy = &pAd->StaCfg.DesiredHtPhyInfo;
660 DesiredMcs =
661 pAd->StaCfg.DesiredTransmitSetting.field.MCS;
662 /*pAd->StaCfg.bAutoTxRateSwitch = (DesiredMcs == MCS_AUTO) ? TRUE : FALSE; */
663 break;
664 }
665 } while (FALSE);
666
667 if (pDesired_ht_phy == NULL) {
668 DBGPRINT(RT_DEBUG_ERROR,
669 ("RTMPSetIndividualHT: invalid apidx(%d)\n", apidx));
670 return;
671 }
672 RTMPZeroMemory(pDesired_ht_phy, sizeof(struct rt_ht_phy_info));
673
674 DBGPRINT(RT_DEBUG_TRACE,
675 ("RTMPSetIndividualHT : Desired MCS = %d\n", DesiredMcs));
676 /* Check the validity of MCS */
677 if ((TxStream == 1)
678 && ((DesiredMcs >= MCS_8) && (DesiredMcs <= MCS_15))) {
679 DBGPRINT(RT_DEBUG_WARN,
680 ("RTMPSetIndividualHT: MCS(%d) is invalid in 1S, reset it as MCS_7\n",
681 DesiredMcs));
682 DesiredMcs = MCS_7;
683 }
684
685 if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_20)
686 && (DesiredMcs == MCS_32)) {
687 DBGPRINT(RT_DEBUG_WARN,
688 ("RTMPSetIndividualHT: MCS_32 is only supported in 40-MHz, reset it as MCS_0\n"));
689 DesiredMcs = MCS_0;
690 }
691
692 pDesired_ht_phy->bHtEnable = TRUE;
693
694 /* Decide desired Tx MCS */
695 switch (TxStream) {
696 case 1:
697 if (DesiredMcs == MCS_AUTO) {
698 pDesired_ht_phy->MCSSet[0] = 0xff;
699 pDesired_ht_phy->MCSSet[1] = 0x00;
700 } else if (DesiredMcs <= MCS_7) {
701 pDesired_ht_phy->MCSSet[0] = 1 << DesiredMcs;
702 pDesired_ht_phy->MCSSet[1] = 0x00;
703 }
704 break;
705
706 case 2:
707 if (DesiredMcs == MCS_AUTO) {
708 pDesired_ht_phy->MCSSet[0] = 0xff;
709 pDesired_ht_phy->MCSSet[1] = 0xff;
710 } else if (DesiredMcs <= MCS_15) {
711 unsigned long mode;
712
713 mode = DesiredMcs / 8;
714 if (mode < 2)
715 pDesired_ht_phy->MCSSet[mode] =
716 (1 << (DesiredMcs - mode * 8));
717 }
718 break;
719
720 case 3: /* 3*3 */
721 if (DesiredMcs == MCS_AUTO) {
722 /* MCS0 ~ MCS23, 3 bytes */
723 pDesired_ht_phy->MCSSet[0] = 0xff;
724 pDesired_ht_phy->MCSSet[1] = 0xff;
725 pDesired_ht_phy->MCSSet[2] = 0xff;
726 } else if (DesiredMcs <= MCS_23) {
727 unsigned long mode;
728
729 mode = DesiredMcs / 8;
730 if (mode < 3)
731 pDesired_ht_phy->MCSSet[mode] =
732 (1 << (DesiredMcs - mode * 8));
733 }
734 break;
735 }
736
737 if (pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_40) {
738 if (DesiredMcs == MCS_AUTO || DesiredMcs == MCS_32)
739 pDesired_ht_phy->MCSSet[4] = 0x1;
740 }
741 /* update HT Rate setting */
742 if (pAd->OpMode == OPMODE_STA)
743 MlmeUpdateHtTxRates(pAd, BSS0);
744 else
745 MlmeUpdateHtTxRates(pAd, apidx);
746}
747
748/*
749 ========================================================================
750 Routine Description:
751 Update HT IE from our capability.
752
753 Arguments:
754 Send all HT IE in beacon/probe rsp/assoc rsp/action frame.
755
756 ========================================================================
757*/
758void RTMPUpdateHTIE(struct rt_ht_capability *pRtHt,
759 u8 * pMcsSet,
760 struct rt_ht_capability_ie * pHtCapability,
761 struct rt_add_ht_info_ie * pAddHtInfo)
762{
763 RTMPZeroMemory(pHtCapability, sizeof(struct rt_ht_capability_ie));
764 RTMPZeroMemory(pAddHtInfo, sizeof(struct rt_add_ht_info_ie));
765
766 pHtCapability->HtCapInfo.ChannelWidth = pRtHt->ChannelWidth;
767 pHtCapability->HtCapInfo.MimoPs = pRtHt->MimoPs;
768 pHtCapability->HtCapInfo.GF = pRtHt->GF;
769 pHtCapability->HtCapInfo.ShortGIfor20 = pRtHt->ShortGIfor20;
770 pHtCapability->HtCapInfo.ShortGIfor40 = pRtHt->ShortGIfor40;
771 pHtCapability->HtCapInfo.TxSTBC = pRtHt->TxSTBC;
772 pHtCapability->HtCapInfo.RxSTBC = pRtHt->RxSTBC;
773 pHtCapability->HtCapInfo.AMsduSize = pRtHt->AmsduSize;
774 pHtCapability->HtCapParm.MaxRAmpduFactor = pRtHt->MaxRAmpduFactor;
775 pHtCapability->HtCapParm.MpduDensity = pRtHt->MpduDensity;
776
777 pAddHtInfo->AddHtInfo.ExtChanOffset = pRtHt->ExtChanOffset;
778 pAddHtInfo->AddHtInfo.RecomWidth = pRtHt->RecomWidth;
779 pAddHtInfo->AddHtInfo2.OperaionMode = pRtHt->OperaionMode;
780 pAddHtInfo->AddHtInfo2.NonGfPresent = pRtHt->NonGfPresent;
781 RTMPMoveMemory(pAddHtInfo->MCSSet, /*pRtHt->MCSSet */ pMcsSet, 4); /* rt2860 only support MCS max=32, no need to copy all 16 uchar. */
782
783 DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateHTIE <== \n"));
784}
785
786/*
787 ========================================================================
788 Description:
789 Add Client security information into ASIC WCID table and IVEIV table.
790 Return:
791 ========================================================================
792*/
793void RTMPAddWcidAttributeEntry(struct rt_rtmp_adapter *pAd,
794 u8 BssIdx,
795 u8 KeyIdx,
796 u8 CipherAlg, struct rt_mac_table_entry *pEntry)
797{
798 u32 WCIDAttri = 0;
799 u16 offset;
800 u8 IVEIV = 0;
801 u16 Wcid = 0;
802
803 {
804 {
805 if (BssIdx > BSS0) {
806 DBGPRINT(RT_DEBUG_ERROR,
807 ("RTMPAddWcidAttributeEntry: The BSS-index(%d) is out of range for Infra link. \n",
808 BssIdx));
809 return;
810 }
811 /* 1. In ADHOC mode, the AID is wcid number. And NO mesh link exists. */
812 /* 2. In Infra mode, the AID:1 MUST be wcid of infra STA. */
813 /* the AID:2~ assign to mesh link entry. */
814 if (pEntry)
815 Wcid = pEntry->Aid;
816 else
817 Wcid = MCAST_WCID;
818 }
819 }
820
821 /* Update WCID attribute table */
822 offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
823
824 {
825 if (pEntry && pEntry->ValidAsMesh)
826 WCIDAttri = (CipherAlg << 1) | PAIRWISEKEYTABLE;
827 else
828 WCIDAttri = (CipherAlg << 1) | SHAREDKEYTABLE;
829 }
830
831 RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
832
833 /* Update IV/EIV table */
834 offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE);
835
836 /* WPA mode */
837 if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC)
838 || (CipherAlg == CIPHER_AES)) {
839 /* Eiv bit on. keyid always is 0 for pairwise key */
840 IVEIV = (KeyIdx << 6) | 0x20;
841 } else {
842 /* WEP KeyIdx is default tx key. */
843 IVEIV = (KeyIdx << 6);
844 }
845
846 /* For key index and ext IV bit, so only need to update the position(offset+3). */
847#ifdef RTMP_MAC_PCI
848 RTMP_IO_WRITE8(pAd, offset + 3, IVEIV);
849#endif /* RTMP_MAC_PCI // */
850#ifdef RTMP_MAC_USB
851 RTUSBMultiWrite_OneByte(pAd, offset + 3, &IVEIV);
852#endif /* RTMP_MAC_USB // */
853
854 DBGPRINT(RT_DEBUG_TRACE,
855 ("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n",
856 Wcid, KeyIdx, CipherName[CipherAlg]));
857 DBGPRINT(RT_DEBUG_TRACE, (" WCIDAttri = 0x%x \n", WCIDAttri));
858
859}
860
861/*
862 ==========================================================================
863 Description:
864 Parse encryption type
865Arguments:
866 pAdapter Pointer to our adapter
867 wrq Pointer to the ioctl argument
868
869 Return Value:
870 None
871
872 Note:
873 ==========================================================================
874*/
875char *GetEncryptType(char enc)
876{
877 if (enc == Ndis802_11WEPDisabled)
878 return "NONE";
879 if (enc == Ndis802_11WEPEnabled)
880 return "WEP";
881 if (enc == Ndis802_11Encryption2Enabled)
882 return "TKIP";
883 if (enc == Ndis802_11Encryption3Enabled)
884 return "AES";
885 if (enc == Ndis802_11Encryption4Enabled)
886 return "TKIPAES";
887 else
888 return "UNKNOW";
889}
890
891char *GetAuthMode(char auth)
892{
893 if (auth == Ndis802_11AuthModeOpen)
894 return "OPEN";
895 if (auth == Ndis802_11AuthModeShared)
896 return "SHARED";
897 if (auth == Ndis802_11AuthModeAutoSwitch)
898 return "AUTOWEP";
899 if (auth == Ndis802_11AuthModeWPA)
900 return "WPA";
901 if (auth == Ndis802_11AuthModeWPAPSK)
902 return "WPAPSK";
903 if (auth == Ndis802_11AuthModeWPANone)
904 return "WPANONE";
905 if (auth == Ndis802_11AuthModeWPA2)
906 return "WPA2";
907 if (auth == Ndis802_11AuthModeWPA2PSK)
908 return "WPA2PSK";
909 if (auth == Ndis802_11AuthModeWPA1WPA2)
910 return "WPA1WPA2";
911 if (auth == Ndis802_11AuthModeWPA1PSKWPA2PSK)
912 return "WPA1PSKWPA2PSK";
913
914 return "UNKNOW";
915}
916
917int SetCommonHT(struct rt_rtmp_adapter *pAd)
918{
919 struct rt_oid_set_ht_phymode SetHT;
920
921 if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED)
922 return FALSE;
923
924 SetHT.PhyMode = pAd->CommonCfg.PhyMode;
925 SetHT.TransmitNo = ((u8)pAd->Antenna.field.TxPath);
926 SetHT.HtMode = (u8)pAd->CommonCfg.RegTransmitSetting.field.HTMODE;
927 SetHT.ExtOffset =
928 (u8)pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
929 SetHT.MCS = MCS_AUTO;
930 SetHT.BW = (u8)pAd->CommonCfg.RegTransmitSetting.field.BW;
931 SetHT.STBC = (u8)pAd->CommonCfg.RegTransmitSetting.field.STBC;
932 SetHT.SHORTGI = (u8)pAd->CommonCfg.RegTransmitSetting.field.ShortGI;
933
934 RTMPSetHT(pAd, &SetHT);
935
936 return TRUE;
937}
938
939char *RTMPGetRalinkEncryModeStr(u16 encryMode)
940{
941 switch (encryMode) {
942 case Ndis802_11WEPDisabled:
943 return "NONE";
944 case Ndis802_11WEPEnabled:
945 return "WEP";
946 case Ndis802_11Encryption2Enabled:
947 return "TKIP";
948 case Ndis802_11Encryption3Enabled:
949 return "AES";
950 case Ndis802_11Encryption4Enabled:
951 return "TKIPAES";
952 default:
953 return "UNKNOW";
954 }
955}
diff --git a/drivers/staging/rt2860/common/cmm_mac_pci.c b/drivers/staging/rt2860/common/cmm_mac_pci.c
deleted file mode 100644
index d06f0a6dc37..00000000000
--- a/drivers/staging/rt2860/common/cmm_mac_pci.c
+++ /dev/null
@@ -1,1661 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27
28#ifdef RTMP_MAC_PCI
29#include "../rt_config.h"
30
31/*
32 ========================================================================
33
34 Routine Description:
35 Allocate DMA memory blocks for send, receive
36
37 Arguments:
38 Adapter Pointer to our adapter
39
40 Return Value:
41 NDIS_STATUS_SUCCESS
42 NDIS_STATUS_FAILURE
43 NDIS_STATUS_RESOURCES
44
45 IRQL = PASSIVE_LEVEL
46
47 Note:
48
49 ========================================================================
50*/
51int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd)
52{
53 int Status = NDIS_STATUS_SUCCESS;
54 unsigned long RingBasePaHigh;
55 unsigned long RingBasePaLow;
56 void *RingBaseVa;
57 int index, num;
58 struct rt_txd * pTxD;
59 struct rt_rxd * pRxD;
60 unsigned long ErrorValue = 0;
61 struct rt_rtmp_tx_ring *pTxRing;
62 struct rt_rtmp_dmabuf *pDmaBuf;
63 void *pPacket;
64/* PRTMP_REORDERBUF pReorderBuf; */
65
66 DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocTxRxRingMemory\n"));
67 do {
68 /* */
69 /* Allocate all ring descriptors, include TxD, RxD, MgmtD. */
70 /* Although each size is different, to prevent cacheline and alignment */
71 /* issue, I intentional set them all to 64 bytes. */
72 /* */
73 for (num = 0; num < NUM_OF_TX_RING; num++) {
74 unsigned long BufBasePaHigh;
75 unsigned long BufBasePaLow;
76 void *BufBaseVa;
77
78 /* */
79 /* Allocate Tx ring descriptor's memory (5 TX rings = 4 ACs + 1 HCCA) */
80 /* */
81 pAd->TxDescRing[num].AllocSize =
82 TX_RING_SIZE * TXD_SIZE;
83 RTMP_AllocateTxDescMemory(pAd, num,
84 pAd->TxDescRing[num].
85 AllocSize, FALSE,
86 &pAd->TxDescRing[num].AllocVa,
87 &pAd->TxDescRing[num].
88 AllocPa);
89
90 if (pAd->TxDescRing[num].AllocVa == NULL) {
91 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
92 DBGPRINT_ERR("Failed to allocate a big buffer\n");
93 Status = NDIS_STATUS_RESOURCES;
94 break;
95 }
96 /* Zero init this memory block */
97 NdisZeroMemory(pAd->TxDescRing[num].AllocVa,
98 pAd->TxDescRing[num].AllocSize);
99
100 /* Save PA & VA for further operation */
101 RingBasePaHigh =
102 RTMP_GetPhysicalAddressHigh(pAd->TxDescRing[num].
103 AllocPa);
104 RingBasePaLow =
105 RTMP_GetPhysicalAddressLow(pAd->TxDescRing[num].
106 AllocPa);
107 RingBaseVa = pAd->TxDescRing[num].AllocVa;
108
109 /* */
110 /* Allocate all 1st TXBuf's memory for this TxRing */
111 /* */
112 pAd->TxBufSpace[num].AllocSize =
113 TX_RING_SIZE * TX_DMA_1ST_BUFFER_SIZE;
114 RTMP_AllocateFirstTxBuffer(pAd, num,
115 pAd->TxBufSpace[num].
116 AllocSize, FALSE,
117 &pAd->TxBufSpace[num].
118 AllocVa,
119 &pAd->TxBufSpace[num].
120 AllocPa);
121
122 if (pAd->TxBufSpace[num].AllocVa == NULL) {
123 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
124 DBGPRINT_ERR("Failed to allocate a big buffer\n");
125 Status = NDIS_STATUS_RESOURCES;
126 break;
127 }
128 /* Zero init this memory block */
129 NdisZeroMemory(pAd->TxBufSpace[num].AllocVa,
130 pAd->TxBufSpace[num].AllocSize);
131
132 /* Save PA & VA for further operation */
133 BufBasePaHigh =
134 RTMP_GetPhysicalAddressHigh(pAd->TxBufSpace[num].
135 AllocPa);
136 BufBasePaLow =
137 RTMP_GetPhysicalAddressLow(pAd->TxBufSpace[num].
138 AllocPa);
139 BufBaseVa = pAd->TxBufSpace[num].AllocVa;
140
141 /* */
142 /* Initialize Tx Ring Descriptor and associated buffer memory */
143 /* */
144 pTxRing = &pAd->TxRing[num];
145 for (index = 0; index < TX_RING_SIZE; index++) {
146 pTxRing->Cell[index].pNdisPacket = NULL;
147 pTxRing->Cell[index].pNextNdisPacket = NULL;
148 /* Init Tx Ring Size, Va, Pa variables */
149 pTxRing->Cell[index].AllocSize = TXD_SIZE;
150 pTxRing->Cell[index].AllocVa = RingBaseVa;
151 RTMP_SetPhysicalAddressHigh(pTxRing->
152 Cell[index].AllocPa,
153 RingBasePaHigh);
154 RTMP_SetPhysicalAddressLow(pTxRing->Cell[index].
155 AllocPa,
156 RingBasePaLow);
157
158 /* Setup Tx Buffer size & address. only 802.11 header will store in this space */
159 pDmaBuf = &pTxRing->Cell[index].DmaBuf;
160 pDmaBuf->AllocSize = TX_DMA_1ST_BUFFER_SIZE;
161 pDmaBuf->AllocVa = BufBaseVa;
162 RTMP_SetPhysicalAddressHigh(pDmaBuf->AllocPa,
163 BufBasePaHigh);
164 RTMP_SetPhysicalAddressLow(pDmaBuf->AllocPa,
165 BufBasePaLow);
166
167 /* link the pre-allocated TxBuf to TXD */
168 pTxD =
169 (struct rt_txd *) pTxRing->Cell[index].AllocVa;
170 pTxD->SDPtr0 = BufBasePaLow;
171 /* advance to next ring descriptor address */
172 pTxD->DMADONE = 1;
173 RingBasePaLow += TXD_SIZE;
174 RingBaseVa = (u8 *)RingBaseVa + TXD_SIZE;
175
176 /* advance to next TxBuf address */
177 BufBasePaLow += TX_DMA_1ST_BUFFER_SIZE;
178 BufBaseVa =
179 (u8 *)BufBaseVa + TX_DMA_1ST_BUFFER_SIZE;
180 }
181 DBGPRINT(RT_DEBUG_TRACE,
182 ("TxRing[%d]: total %d entry allocated\n", num,
183 index));
184 }
185 if (Status == NDIS_STATUS_RESOURCES)
186 break;
187
188 /* */
189 /* Allocate MGMT ring descriptor's memory except Tx ring which allocated eariler */
190 /* */
191 pAd->MgmtDescRing.AllocSize = MGMT_RING_SIZE * TXD_SIZE;
192 RTMP_AllocateMgmtDescMemory(pAd,
193 pAd->MgmtDescRing.AllocSize,
194 FALSE,
195 &pAd->MgmtDescRing.AllocVa,
196 &pAd->MgmtDescRing.AllocPa);
197
198 if (pAd->MgmtDescRing.AllocVa == NULL) {
199 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
200 DBGPRINT_ERR("Failed to allocate a big buffer\n");
201 Status = NDIS_STATUS_RESOURCES;
202 break;
203 }
204 /* Zero init this memory block */
205 NdisZeroMemory(pAd->MgmtDescRing.AllocVa,
206 pAd->MgmtDescRing.AllocSize);
207
208 /* Save PA & VA for further operation */
209 RingBasePaHigh =
210 RTMP_GetPhysicalAddressHigh(pAd->MgmtDescRing.AllocPa);
211 RingBasePaLow =
212 RTMP_GetPhysicalAddressLow(pAd->MgmtDescRing.AllocPa);
213 RingBaseVa = pAd->MgmtDescRing.AllocVa;
214
215 /* */
216 /* Initialize MGMT Ring and associated buffer memory */
217 /* */
218 for (index = 0; index < MGMT_RING_SIZE; index++) {
219 pAd->MgmtRing.Cell[index].pNdisPacket = NULL;
220 pAd->MgmtRing.Cell[index].pNextNdisPacket = NULL;
221 /* Init MGMT Ring Size, Va, Pa variables */
222 pAd->MgmtRing.Cell[index].AllocSize = TXD_SIZE;
223 pAd->MgmtRing.Cell[index].AllocVa = RingBaseVa;
224 RTMP_SetPhysicalAddressHigh(pAd->MgmtRing.Cell[index].
225 AllocPa, RingBasePaHigh);
226 RTMP_SetPhysicalAddressLow(pAd->MgmtRing.Cell[index].
227 AllocPa, RingBasePaLow);
228
229 /* Offset to next ring descriptor address */
230 RingBasePaLow += TXD_SIZE;
231 RingBaseVa = (u8 *)RingBaseVa + TXD_SIZE;
232
233 /* link the pre-allocated TxBuf to TXD */
234 pTxD = (struct rt_txd *) pAd->MgmtRing.Cell[index].AllocVa;
235 pTxD->DMADONE = 1;
236
237 /* no pre-allocated buffer required in MgmtRing for scatter-gather case */
238 }
239 DBGPRINT(RT_DEBUG_TRACE,
240 ("MGMT Ring: total %d entry allocated\n", index));
241
242 /* */
243 /* Allocate RX ring descriptor's memory except Tx ring which allocated eariler */
244 /* */
245 pAd->RxDescRing.AllocSize = RX_RING_SIZE * RXD_SIZE;
246 RTMP_AllocateRxDescMemory(pAd,
247 pAd->RxDescRing.AllocSize,
248 FALSE,
249 &pAd->RxDescRing.AllocVa,
250 &pAd->RxDescRing.AllocPa);
251
252 if (pAd->RxDescRing.AllocVa == NULL) {
253 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
254 DBGPRINT_ERR("Failed to allocate a big buffer\n");
255 Status = NDIS_STATUS_RESOURCES;
256 break;
257 }
258 /* Zero init this memory block */
259 NdisZeroMemory(pAd->RxDescRing.AllocVa,
260 pAd->RxDescRing.AllocSize);
261
262 DBGPRINT(RT_DEBUG_OFF,
263 ("RX DESC %p size = %ld\n", pAd->RxDescRing.AllocVa,
264 pAd->RxDescRing.AllocSize));
265
266 /* Save PA & VA for further operation */
267 RingBasePaHigh =
268 RTMP_GetPhysicalAddressHigh(pAd->RxDescRing.AllocPa);
269 RingBasePaLow =
270 RTMP_GetPhysicalAddressLow(pAd->RxDescRing.AllocPa);
271 RingBaseVa = pAd->RxDescRing.AllocVa;
272
273 /* */
274 /* Initialize Rx Ring and associated buffer memory */
275 /* */
276 for (index = 0; index < RX_RING_SIZE; index++) {
277 /* Init RX Ring Size, Va, Pa variables */
278 pAd->RxRing.Cell[index].AllocSize = RXD_SIZE;
279 pAd->RxRing.Cell[index].AllocVa = RingBaseVa;
280 RTMP_SetPhysicalAddressHigh(pAd->RxRing.Cell[index].
281 AllocPa, RingBasePaHigh);
282 RTMP_SetPhysicalAddressLow(pAd->RxRing.Cell[index].
283 AllocPa, RingBasePaLow);
284
285 /*NdisZeroMemory(RingBaseVa, RXD_SIZE); */
286
287 /* Offset to next ring descriptor address */
288 RingBasePaLow += RXD_SIZE;
289 RingBaseVa = (u8 *)RingBaseVa + RXD_SIZE;
290
291 /* Setup Rx associated Buffer size & allocate share memory */
292 pDmaBuf = &pAd->RxRing.Cell[index].DmaBuf;
293 pDmaBuf->AllocSize = RX_BUFFER_AGGRESIZE;
294 pPacket = RTMP_AllocateRxPacketBuffer(pAd,
295 pDmaBuf->
296 AllocSize, FALSE,
297 &pDmaBuf->AllocVa,
298 &pDmaBuf->
299 AllocPa);
300
301 /* keep allocated rx packet */
302 pAd->RxRing.Cell[index].pNdisPacket = pPacket;
303
304 /* Error handling */
305 if (pDmaBuf->AllocVa == NULL) {
306 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
307 DBGPRINT_ERR("Failed to allocate RxRing's 1st buffer\n");
308 Status = NDIS_STATUS_RESOURCES;
309 break;
310 }
311 /* Zero init this memory block */
312 NdisZeroMemory(pDmaBuf->AllocVa, pDmaBuf->AllocSize);
313
314 /* Write RxD buffer address & allocated buffer length */
315 pRxD = (struct rt_rxd *) pAd->RxRing.Cell[index].AllocVa;
316 pRxD->SDP0 =
317 RTMP_GetPhysicalAddressLow(pDmaBuf->AllocPa);
318 pRxD->DDONE = 0;
319
320 }
321
322 DBGPRINT(RT_DEBUG_TRACE,
323 ("Rx Ring: total %d entry allocated\n", index));
324
325 } while (FALSE);
326
327 NdisZeroMemory(&pAd->FragFrame, sizeof(struct rt_fragment_frame));
328 pAd->FragFrame.pFragPacket =
329 RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE);
330
331 if (pAd->FragFrame.pFragPacket == NULL) {
332 Status = NDIS_STATUS_RESOURCES;
333 }
334
335 if (Status != NDIS_STATUS_SUCCESS) {
336 /* Log error inforamtion */
337 NdisWriteErrorLogEntry(pAd->AdapterHandle,
338 NDIS_ERROR_CODE_OUT_OF_RESOURCES,
339 1, ErrorValue);
340 }
341 /* Following code segment get from original func:NICInitTxRxRingAndBacklogQueue(), now should integrate it to here. */
342 {
343 DBGPRINT(RT_DEBUG_TRACE,
344 ("--> NICInitTxRxRingAndBacklogQueue\n"));
345
346/*
347 // Disable DMA.
348 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
349 GloCfg.word &= 0xff0;
350 GloCfg.field.EnTXWriteBackDDONE =1;
351 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
352*/
353
354 /* Initialize all transmit related software queues */
355 for (index = 0; index < NUM_OF_TX_RING; index++) {
356 InitializeQueueHeader(&pAd->TxSwQueue[index]);
357 /* Init TX rings index pointer */
358 pAd->TxRing[index].TxSwFreeIdx = 0;
359 pAd->TxRing[index].TxCpuIdx = 0;
360 /*RTMP_IO_WRITE32(pAd, (TX_CTX_IDX0 + i * 0x10) , pAd->TxRing[i].TX_CTX_IDX); */
361 }
362
363 /* Init RX Ring index pointer */
364 pAd->RxRing.RxSwReadIdx = 0;
365 pAd->RxRing.RxCpuIdx = RX_RING_SIZE - 1;
366 /*RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RX_CRX_IDX0); */
367
368 /* init MGMT ring index pointer */
369 pAd->MgmtRing.TxSwFreeIdx = 0;
370 pAd->MgmtRing.TxCpuIdx = 0;
371
372 pAd->PrivateInfo.TxRingFullCnt = 0;
373
374 DBGPRINT(RT_DEBUG_TRACE,
375 ("<-- NICInitTxRxRingAndBacklogQueue\n"));
376 }
377
378 DBGPRINT_S(Status,
379 ("<-- RTMPAllocTxRxRingMemory, Status=%x\n", Status));
380 return Status;
381}
382
383/*
384 ========================================================================
385
386 Routine Description:
387 Reset NIC Asics. Call after rest DMA. So reset TX_CTX_IDX to zero.
388
389 Arguments:
390 Adapter Pointer to our adapter
391
392 Return Value:
393 None
394
395 IRQL = PASSIVE_LEVEL
396 IRQL = DISPATCH_LEVEL
397
398 Note:
399 Reset NIC to initial state AS IS system boot up time.
400
401 ========================================================================
402*/
403void RTMPRingCleanUp(struct rt_rtmp_adapter *pAd, u8 RingType)
404{
405 struct rt_txd * pTxD;
406 struct rt_rxd * pRxD;
407 struct rt_queue_entry *pEntry;
408 void *pPacket;
409 int i;
410 struct rt_rtmp_tx_ring *pTxRing;
411 unsigned long IrqFlags;
412 /*u32 RxSwReadIdx; */
413
414 DBGPRINT(RT_DEBUG_TRACE,
415 ("RTMPRingCleanUp(RingIdx=%d, Pending-NDIS=%ld)\n", RingType,
416 pAd->RalinkCounters.PendingNdisPacketCount));
417 switch (RingType) {
418 case QID_AC_BK:
419 case QID_AC_BE:
420 case QID_AC_VI:
421 case QID_AC_VO:
422
423 pTxRing = &pAd->TxRing[RingType];
424
425 RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
426 /* We have to clean all descriptors in case some error happened with reset */
427 for (i = 0; i < TX_RING_SIZE; i++) /* We have to scan all TX ring */
428 {
429 pTxD = (struct rt_txd *) pTxRing->Cell[i].AllocVa;
430
431 pPacket = (void *)pTxRing->Cell[i].pNdisPacket;
432 /* release scatter-and-gather char */
433 if (pPacket) {
434 RELEASE_NDIS_PACKET(pAd, pPacket,
435 NDIS_STATUS_FAILURE);
436 pTxRing->Cell[i].pNdisPacket = NULL;
437 }
438
439 pPacket =
440 (void *)pTxRing->Cell[i].pNextNdisPacket;
441 /* release scatter-and-gather char */
442 if (pPacket) {
443 RELEASE_NDIS_PACKET(pAd, pPacket,
444 NDIS_STATUS_FAILURE);
445 pTxRing->Cell[i].pNextNdisPacket = NULL;
446 }
447 }
448
449 RTMP_IO_READ32(pAd, TX_DTX_IDX0 + RingType * 0x10,
450 &pTxRing->TxDmaIdx);
451 pTxRing->TxSwFreeIdx = pTxRing->TxDmaIdx;
452 pTxRing->TxCpuIdx = pTxRing->TxDmaIdx;
453 RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + RingType * 0x10,
454 pTxRing->TxCpuIdx);
455
456 RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
457
458 RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
459 while (pAd->TxSwQueue[RingType].Head != NULL) {
460 pEntry = RemoveHeadQueue(&pAd->TxSwQueue[RingType]);
461 pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
462 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
463 DBGPRINT(RT_DEBUG_TRACE,
464 ("Release 1 NDIS packet from s/w backlog queue\n"));
465 }
466 RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
467 break;
468
469 case QID_MGMT:
470 /* We have to clean all descriptors in case some error happened with reset */
471 NdisAcquireSpinLock(&pAd->MgmtRingLock);
472
473 for (i = 0; i < MGMT_RING_SIZE; i++) {
474 pTxD = (struct rt_txd *) pAd->MgmtRing.Cell[i].AllocVa;
475
476 pPacket =
477 (void *)pAd->MgmtRing.Cell[i].pNdisPacket;
478 /* rlease scatter-and-gather char */
479 if (pPacket) {
480 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0,
481 pTxD->SDLen0,
482 PCI_DMA_TODEVICE);
483 RELEASE_NDIS_PACKET(pAd, pPacket,
484 NDIS_STATUS_FAILURE);
485 }
486 pAd->MgmtRing.Cell[i].pNdisPacket = NULL;
487
488 pPacket =
489 (void *)pAd->MgmtRing.Cell[i].
490 pNextNdisPacket;
491 /* release scatter-and-gather char */
492 if (pPacket) {
493 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1,
494 pTxD->SDLen1,
495 PCI_DMA_TODEVICE);
496 RELEASE_NDIS_PACKET(pAd, pPacket,
497 NDIS_STATUS_FAILURE);
498 }
499 pAd->MgmtRing.Cell[i].pNextNdisPacket = NULL;
500
501 }
502
503 RTMP_IO_READ32(pAd, TX_MGMTDTX_IDX, &pAd->MgmtRing.TxDmaIdx);
504 pAd->MgmtRing.TxSwFreeIdx = pAd->MgmtRing.TxDmaIdx;
505 pAd->MgmtRing.TxCpuIdx = pAd->MgmtRing.TxDmaIdx;
506 RTMP_IO_WRITE32(pAd, TX_MGMTCTX_IDX, pAd->MgmtRing.TxCpuIdx);
507
508 NdisReleaseSpinLock(&pAd->MgmtRingLock);
509 pAd->RalinkCounters.MgmtRingFullCount = 0;
510 break;
511
512 case QID_RX:
513 /* We have to clean all descriptors in case some error happened with reset */
514 NdisAcquireSpinLock(&pAd->RxRingLock);
515
516 for (i = 0; i < RX_RING_SIZE; i++) {
517 pRxD = (struct rt_rxd *) pAd->RxRing.Cell[i].AllocVa;
518 pRxD->DDONE = 0;
519 }
520
521 RTMP_IO_READ32(pAd, RX_DRX_IDX, &pAd->RxRing.RxDmaIdx);
522 pAd->RxRing.RxSwReadIdx = pAd->RxRing.RxDmaIdx;
523 pAd->RxRing.RxCpuIdx =
524 ((pAd->RxRing.RxDmaIdx ==
525 0) ? (RX_RING_SIZE - 1) : (pAd->RxRing.RxDmaIdx - 1));
526 RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx);
527
528 NdisReleaseSpinLock(&pAd->RxRingLock);
529 break;
530
531 default:
532 break;
533 }
534}
535
536void RTMPFreeTxRxRingMemory(struct rt_rtmp_adapter *pAd)
537{
538 int index, num, j;
539 struct rt_rtmp_tx_ring *pTxRing;
540 struct rt_txd * pTxD;
541 void *pPacket;
542 unsigned int IrqFlags;
543
544 /*struct os_cookie *pObj =(struct os_cookie *)pAd->OS_Cookie; */
545
546 DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPFreeTxRxRingMemory\n"));
547
548 /* Free TxSwQueue Packet */
549 for (index = 0; index < NUM_OF_TX_RING; index++) {
550 struct rt_queue_entry *pEntry;
551 void *pPacket;
552 struct rt_queue_header *pQueue;
553
554 RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
555 pQueue = &pAd->TxSwQueue[index];
556 while (pQueue->Head) {
557 pEntry = RemoveHeadQueue(pQueue);
558 pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
559 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
560 }
561 RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
562 }
563
564 /* Free Tx Ring Packet */
565 for (index = 0; index < NUM_OF_TX_RING; index++) {
566 pTxRing = &pAd->TxRing[index];
567
568 for (j = 0; j < TX_RING_SIZE; j++) {
569 pTxD = (struct rt_txd *) (pTxRing->Cell[j].AllocVa);
570 pPacket = pTxRing->Cell[j].pNdisPacket;
571
572 if (pPacket) {
573 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0,
574 pTxD->SDLen0,
575 PCI_DMA_TODEVICE);
576 RELEASE_NDIS_PACKET(pAd, pPacket,
577 NDIS_STATUS_SUCCESS);
578 }
579 /*Always assign pNdisPacket as NULL after clear */
580 pTxRing->Cell[j].pNdisPacket = NULL;
581
582 pPacket = pTxRing->Cell[j].pNextNdisPacket;
583
584 if (pPacket) {
585 PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1,
586 pTxD->SDLen1,
587 PCI_DMA_TODEVICE);
588 RELEASE_NDIS_PACKET(pAd, pPacket,
589 NDIS_STATUS_SUCCESS);
590 }
591 /*Always assign pNextNdisPacket as NULL after clear */
592 pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket =
593 NULL;
594
595 }
596 }
597
598 for (index = RX_RING_SIZE - 1; index >= 0; index--) {
599 if ((pAd->RxRing.Cell[index].DmaBuf.AllocVa)
600 && (pAd->RxRing.Cell[index].pNdisPacket)) {
601 PCI_UNMAP_SINGLE(pAd,
602 pAd->RxRing.Cell[index].DmaBuf.AllocPa,
603 pAd->RxRing.Cell[index].DmaBuf.
604 AllocSize, PCI_DMA_FROMDEVICE);
605 RELEASE_NDIS_PACKET(pAd,
606 pAd->RxRing.Cell[index].pNdisPacket,
607 NDIS_STATUS_SUCCESS);
608 }
609 }
610 NdisZeroMemory(pAd->RxRing.Cell, RX_RING_SIZE * sizeof(struct rt_rtmp_dmacb));
611
612 if (pAd->RxDescRing.AllocVa) {
613 RTMP_FreeDescMemory(pAd, pAd->RxDescRing.AllocSize,
614 pAd->RxDescRing.AllocVa,
615 pAd->RxDescRing.AllocPa);
616 }
617 NdisZeroMemory(&pAd->RxDescRing, sizeof(struct rt_rtmp_dmabuf));
618
619 if (pAd->MgmtDescRing.AllocVa) {
620 RTMP_FreeDescMemory(pAd, pAd->MgmtDescRing.AllocSize,
621 pAd->MgmtDescRing.AllocVa,
622 pAd->MgmtDescRing.AllocPa);
623 }
624 NdisZeroMemory(&pAd->MgmtDescRing, sizeof(struct rt_rtmp_dmabuf));
625
626 for (num = 0; num < NUM_OF_TX_RING; num++) {
627 if (pAd->TxBufSpace[num].AllocVa) {
628 RTMP_FreeFirstTxBuffer(pAd,
629 pAd->TxBufSpace[num].AllocSize,
630 FALSE,
631 pAd->TxBufSpace[num].AllocVa,
632 pAd->TxBufSpace[num].AllocPa);
633 }
634 NdisZeroMemory(&pAd->TxBufSpace[num], sizeof(struct rt_rtmp_dmabuf));
635
636 if (pAd->TxDescRing[num].AllocVa) {
637 RTMP_FreeDescMemory(pAd, pAd->TxDescRing[num].AllocSize,
638 pAd->TxDescRing[num].AllocVa,
639 pAd->TxDescRing[num].AllocPa);
640 }
641 NdisZeroMemory(&pAd->TxDescRing[num], sizeof(struct rt_rtmp_dmabuf));
642 }
643
644 if (pAd->FragFrame.pFragPacket)
645 RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket,
646 NDIS_STATUS_SUCCESS);
647
648 DBGPRINT(RT_DEBUG_TRACE, ("<-- RTMPFreeTxRxRingMemory\n"));
649}
650
651/***************************************************************************
652 *
653 * register related procedures.
654 *
655 **************************************************************************/
656/*
657========================================================================
658Routine Description:
659 Disable DMA.
660
661Arguments:
662 *pAd the raxx interface data pointer
663
664Return Value:
665 None
666
667Note:
668========================================================================
669*/
670void RT28XXDMADisable(struct rt_rtmp_adapter *pAd)
671{
672 WPDMA_GLO_CFG_STRUC GloCfg;
673
674 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
675 GloCfg.word &= 0xff0;
676 GloCfg.field.EnTXWriteBackDDONE = 1;
677 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
678}
679
680/*
681========================================================================
682Routine Description:
683 Enable DMA.
684
685Arguments:
686 *pAd the raxx interface data pointer
687
688Return Value:
689 None
690
691Note:
692========================================================================
693*/
694void RT28XXDMAEnable(struct rt_rtmp_adapter *pAd)
695{
696 WPDMA_GLO_CFG_STRUC GloCfg;
697 int i = 0;
698
699 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
700 do {
701 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
702 if ((GloCfg.field.TxDMABusy == 0)
703 && (GloCfg.field.RxDMABusy == 0))
704 break;
705
706 DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n"));
707 RTMPusecDelay(1000);
708 i++;
709 } while (i < 200);
710
711 RTMPusecDelay(50);
712
713 GloCfg.field.EnTXWriteBackDDONE = 1;
714 GloCfg.field.WPDMABurstSIZE = 2;
715 GloCfg.field.EnableRxDMA = 1;
716 GloCfg.field.EnableTxDMA = 1;
717
718 DBGPRINT(RT_DEBUG_TRACE,
719 ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
720 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
721
722}
723
724BOOLEAN AsicCheckCommanOk(struct rt_rtmp_adapter *pAd, u8 Command)
725{
726 u32 CmdStatus = 0, CID = 0, i;
727 u32 ThisCIDMask = 0;
728
729 i = 0;
730 do {
731 RTMP_IO_READ32(pAd, H2M_MAILBOX_CID, &CID);
732 /* Find where the command is. Because this is randomly specified by firmware. */
733 if ((CID & CID0MASK) == Command) {
734 ThisCIDMask = CID0MASK;
735 break;
736 } else if ((((CID & CID1MASK) >> 8) & 0xff) == Command) {
737 ThisCIDMask = CID1MASK;
738 break;
739 } else if ((((CID & CID2MASK) >> 16) & 0xff) == Command) {
740 ThisCIDMask = CID2MASK;
741 break;
742 } else if ((((CID & CID3MASK) >> 24) & 0xff) == Command) {
743 ThisCIDMask = CID3MASK;
744 break;
745 }
746
747 RTMPusecDelay(100);
748 i++;
749 } while (i < 200);
750
751 /* Get CommandStatus Value */
752 RTMP_IO_READ32(pAd, H2M_MAILBOX_STATUS, &CmdStatus);
753
754 /* This command's status is at the same position as command. So AND command position's bitmask to read status. */
755 if (i < 200) {
756 /* If Status is 1, the command is success. */
757 if (((CmdStatus & ThisCIDMask) == 0x1)
758 || ((CmdStatus & ThisCIDMask) == 0x100)
759 || ((CmdStatus & ThisCIDMask) == 0x10000)
760 || ((CmdStatus & ThisCIDMask) == 0x1000000)) {
761 DBGPRINT(RT_DEBUG_TRACE,
762 ("--> AsicCheckCommanOk CID = 0x%x, CmdStatus= 0x%x \n",
763 CID, CmdStatus));
764 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_STATUS, 0xffffffff);
765 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CID, 0xffffffff);
766 return TRUE;
767 }
768 DBGPRINT(RT_DEBUG_TRACE,
769 ("--> AsicCheckCommanFail1 CID = 0x%x, CmdStatus= 0x%x \n",
770 CID, CmdStatus));
771 } else {
772 DBGPRINT(RT_DEBUG_TRACE,
773 ("--> AsicCheckCommanFail2 Timeout Command = %d, CmdStatus= 0x%x \n",
774 Command, CmdStatus));
775 }
776 /* Clear Command and Status. */
777 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_STATUS, 0xffffffff);
778 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CID, 0xffffffff);
779
780 return FALSE;
781}
782
783/*
784========================================================================
785Routine Description:
786 Write Beacon buffer to Asic.
787
788Arguments:
789 *pAd the raxx interface data pointer
790
791Return Value:
792 None
793
794Note:
795========================================================================
796*/
797void RT28xx_UpdateBeaconToAsic(struct rt_rtmp_adapter *pAd,
798 int apidx,
799 unsigned long FrameLen, unsigned long UpdatePos)
800{
801 unsigned long CapInfoPos = 0;
802 u8 *ptr, *ptr_update, *ptr_capinfo;
803 u32 i;
804 BOOLEAN bBcnReq = FALSE;
805 u8 bcn_idx = 0;
806
807 {
808 DBGPRINT(RT_DEBUG_ERROR,
809 ("%s() : No valid Interface be found.\n", __func__));
810 return;
811 }
812
813 /*if ((pAd->WdsTab.Mode == WDS_BRIDGE_MODE) */
814 /* || ((pAd->ApCfg.MBSSID[apidx].MSSIDDev == NULL) */
815 /* || !(pAd->ApCfg.MBSSID[apidx].MSSIDDev->flags & IFF_UP)) */
816 /* ) */
817 if (bBcnReq == FALSE) {
818 /* when the ra interface is down, do not send its beacon frame */
819 /* clear all zero */
820 for (i = 0; i < TXWI_SIZE; i += 4)
821 RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i,
822 0x00);
823 } else {
824 ptr = (u8 *)& pAd->BeaconTxWI;
825 for (i = 0; i < TXWI_SIZE; i += 4) /* 16-byte TXWI field */
826 {
827 u32 longptr =
828 *ptr + (*(ptr + 1) << 8) + (*(ptr + 2) << 16) +
829 (*(ptr + 3) << 24);
830 RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i,
831 longptr);
832 ptr += 4;
833 }
834
835 /* Update CapabilityInfo in Beacon */
836 for (i = CapInfoPos; i < (CapInfoPos + 2); i++) {
837 RTMP_IO_WRITE8(pAd,
838 pAd->BeaconOffset[bcn_idx] + TXWI_SIZE +
839 i, *ptr_capinfo);
840 ptr_capinfo++;
841 }
842
843 if (FrameLen > UpdatePos) {
844 for (i = UpdatePos; i < (FrameLen); i++) {
845 RTMP_IO_WRITE8(pAd,
846 pAd->BeaconOffset[bcn_idx] +
847 TXWI_SIZE + i, *ptr_update);
848 ptr_update++;
849 }
850 }
851
852 }
853
854}
855
856void RT28xxPciStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx)
857{
858 AUTO_WAKEUP_STRUC AutoWakeupCfg;
859
860 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
861 return;
862
863 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WAKEUP_NOW)) {
864 DBGPRINT(RT_DEBUG_TRACE, ("waking up now!\n"));
865 return;
866 }
867
868 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_WAKEUP_NOW);
869
870 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
871
872 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)
873 && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) {
874 /* Support PCIe Advance Power Save */
875 if (bFromTx == TRUE && (pAd->Mlme.bPsPollTimerRunning == TRUE)) {
876 pAd->Mlme.bPsPollTimerRunning = FALSE;
877 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_WAKEUP);
878 RTMPusecDelay(3000);
879 DBGPRINT(RT_DEBUG_TRACE,
880 ("=======AsicForceWakeup===bFromTx\n"));
881 }
882
883 AutoWakeupCfg.word = 0;
884 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
885
886 if (RT28xxPciAsicRadioOn(pAd, DOT11POWERSAVE)) {
887#ifdef PCIE_PS_SUPPORT
888 /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */
889 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
890 && IS_VERSION_AFTER_F(pAd)) {
891 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
892
893 if (pChipOps->AsicReverseRfFromSleepMode)
894 pChipOps->
895 AsicReverseRfFromSleepMode(pAd);
896 } else
897#endif /* PCIE_PS_SUPPORT // */
898 {
899 /* end johnli */
900 /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again. */
901 if (INFRA_ON(pAd)
902 && (pAd->CommonCfg.CentralChannel !=
903 pAd->CommonCfg.Channel)
904 && (pAd->MlmeAux.HtCapability.HtCapInfo.
905 ChannelWidth == BW_40)) {
906 /* Must using 40MHz. */
907 AsicSwitchChannel(pAd,
908 pAd->CommonCfg.
909 CentralChannel,
910 FALSE);
911 AsicLockChannel(pAd,
912 pAd->CommonCfg.
913 CentralChannel);
914 } else {
915 /* Must using 20MHz. */
916 AsicSwitchChannel(pAd,
917 pAd->CommonCfg.
918 Channel, FALSE);
919 AsicLockChannel(pAd,
920 pAd->CommonCfg.Channel);
921 }
922 }
923 }
924#ifdef PCIE_PS_SUPPORT
925 /* 3090 MCU Wakeup command needs more time to be stable. */
926 /* Before stable, don't issue other MCU command to prevent from firmware error. */
927 if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
928 && IS_VERSION_AFTER_F(pAd)) && IS_VERSION_AFTER_F(pAd)
929 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
930 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
931 DBGPRINT(RT_DEBUG_TRACE,
932 ("<==RT28xxPciStaAsicForceWakeup::Release the MCU Lock(3090)\n"));
933 RTMP_SEM_LOCK(&pAd->McuCmdLock);
934 pAd->brt30xxBanMcuCmd = FALSE;
935 RTMP_SEM_UNLOCK(&pAd->McuCmdLock);
936 }
937#endif /* PCIE_PS_SUPPORT // */
938 } else {
939 /* PCI, 2860-PCIe */
940 DBGPRINT(RT_DEBUG_TRACE,
941 ("<==RT28xxPciStaAsicForceWakeup::Original PCI Power Saving\n"));
942 AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02);
943 AutoWakeupCfg.word = 0;
944 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
945 }
946
947 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
948 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WAKEUP_NOW);
949 DBGPRINT(RT_DEBUG_TRACE, ("<=======RT28xxPciStaAsicForceWakeup\n"));
950}
951
952void RT28xxPciStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
953 u16 TbttNumToNextWakeUp)
954{
955 BOOLEAN brc;
956
957 if (pAd->StaCfg.bRadio == FALSE) {
958 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
959 return;
960 }
961 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)
962 && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) {
963 unsigned long Now = 0;
964 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WAKEUP_NOW)) {
965 DBGPRINT(RT_DEBUG_TRACE, ("waking up now!\n"));
966 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
967 return;
968 }
969
970 NdisGetSystemUpTime(&Now);
971 /* If last send NULL fram time is too close to this receiving beacon (within 8ms), don't go to sleep for this DTM. */
972 /* Because Some AP can't queuing outgoing frames immediately. */
973 if (((pAd->Mlme.LastSendNULLpsmTime + 8) >= Now)
974 && (pAd->Mlme.LastSendNULLpsmTime <= Now)) {
975 DBGPRINT(RT_DEBUG_TRACE,
976 ("Now = %lu, LastSendNULLpsmTime=%lu : RxCountSinceLastNULL = %lu. \n",
977 Now, pAd->Mlme.LastSendNULLpsmTime,
978 pAd->RalinkCounters.RxCountSinceLastNULL));
979 return;
980 } else if ((pAd->RalinkCounters.RxCountSinceLastNULL > 0)
981 &&
982 ((pAd->Mlme.LastSendNULLpsmTime +
983 pAd->CommonCfg.BeaconPeriod) >= Now)) {
984 DBGPRINT(RT_DEBUG_TRACE,
985 ("Now = %lu, LastSendNULLpsmTime=%lu: RxCountSinceLastNULL = %lu > 0 \n",
986 Now, pAd->Mlme.LastSendNULLpsmTime,
987 pAd->RalinkCounters.RxCountSinceLastNULL));
988 return;
989 }
990
991 brc =
992 RT28xxPciAsicRadioOff(pAd, DOT11POWERSAVE,
993 TbttNumToNextWakeUp);
994 if (brc == TRUE)
995 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_DOZE);
996 } else {
997 AUTO_WAKEUP_STRUC AutoWakeupCfg;
998 /* we have decided to SLEEP, so at least do it for a BEACON period. */
999 if (TbttNumToNextWakeUp == 0)
1000 TbttNumToNextWakeUp = 1;
1001
1002 /*RTMP_IO_WRITE32(pAd, INT_MASK_CSR, AutoWakeupInt); */
1003
1004 AutoWakeupCfg.word = 0;
1005 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
1006 AutoWakeupCfg.field.NumofSleepingTbtt = TbttNumToNextWakeUp - 1;
1007 AutoWakeupCfg.field.EnableAutoWakeup = 1;
1008 AutoWakeupCfg.field.AutoLeadTime = 5;
1009 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
1010 AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x00); /* send POWER-SAVE command to MCU. Timeout 40us. */
1011 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_DOZE);
1012 DBGPRINT(RT_DEBUG_TRACE,
1013 ("<-- %s, TbttNumToNextWakeUp=%d \n", __func__,
1014 TbttNumToNextWakeUp));
1015 }
1016
1017}
1018
1019void PsPollWakeExec(void *SystemSpecific1,
1020 void *FunctionContext,
1021 void *SystemSpecific2, void *SystemSpecific3)
1022{
1023 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
1024 unsigned long flags;
1025
1026 DBGPRINT(RT_DEBUG_TRACE, ("-->PsPollWakeExec \n"));
1027 RTMP_INT_LOCK(&pAd->irq_lock, flags);
1028 if (pAd->Mlme.bPsPollTimerRunning) {
1029 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_WAKEUP);
1030 }
1031 pAd->Mlme.bPsPollTimerRunning = FALSE;
1032 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
1033#ifdef PCIE_PS_SUPPORT
1034 /* For rt30xx power solution 3, Use software timer to wake up in psm. So call */
1035 /* AsicForceWakeup here instead of handling twakeup interrupt. */
1036 if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
1037 && IS_VERSION_AFTER_F(pAd))
1038 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
1039 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
1040 DBGPRINT(RT_DEBUG_TRACE,
1041 ("<--PsPollWakeExec::3090 calls AsicForceWakeup(pAd, DOT11POWERSAVE) in advance \n"));
1042 AsicForceWakeup(pAd, DOT11POWERSAVE);
1043 }
1044#endif /* PCIE_PS_SUPPORT // */
1045}
1046
1047void RadioOnExec(void *SystemSpecific1,
1048 void *FunctionContext,
1049 void *SystemSpecific2, void *SystemSpecific3)
1050{
1051 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
1052 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
1053 WPDMA_GLO_CFG_STRUC DmaCfg;
1054 BOOLEAN Cancelled;
1055
1056 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) {
1057 DBGPRINT(RT_DEBUG_TRACE,
1058 ("-->RadioOnExec() return on fOP_STATUS_DOZE == TRUE; \n"));
1059/*KH Debug: Add the compile flag "RT2860 and condition */
1060#ifdef RTMP_PCI_SUPPORT
1061 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)
1062 && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)
1063 RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 10);
1064#endif /* RTMP_PCI_SUPPORT // */
1065 return;
1066 }
1067
1068 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) {
1069 DBGPRINT(RT_DEBUG_TRACE,
1070 ("-->RadioOnExec() return on SCAN_IN_PROGRESS; \n"));
1071#ifdef RTMP_PCI_SUPPORT
1072 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)
1073 && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)
1074 RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 10);
1075#endif /* RTMP_PCI_SUPPORT // */
1076 return;
1077 }
1078/*KH Debug: need to check. I add the compile flag "CONFIG_STA_SUPPORT" to enclose the following codes. */
1079#ifdef RTMP_PCI_SUPPORT
1080 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)
1081 && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) {
1082 pAd->Mlme.bPsPollTimerRunning = FALSE;
1083 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1084 }
1085#endif /* RTMP_PCI_SUPPORT // */
1086 if (pAd->StaCfg.bRadio == TRUE) {
1087 pAd->bPCIclkOff = FALSE;
1088 RTMPRingCleanUp(pAd, QID_AC_BK);
1089 RTMPRingCleanUp(pAd, QID_AC_BE);
1090 RTMPRingCleanUp(pAd, QID_AC_VI);
1091 RTMPRingCleanUp(pAd, QID_AC_VO);
1092 RTMPRingCleanUp(pAd, QID_MGMT);
1093 RTMPRingCleanUp(pAd, QID_RX);
1094
1095 /* 2. Send wake up command. */
1096 AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00, 0x02);
1097 /* 2-1. wait command ok. */
1098 AsicCheckCommanOk(pAd, PowerWakeCID);
1099
1100 /* When PCI clock is off, don't want to service interrupt. So when back to clock on, enable interrupt. */
1101 /*RTMP_IO_WRITE32(pAd, INT_MASK_CSR, (DELAYINTMASK|RxINT)); */
1102 RTMP_ASIC_INTERRUPT_ENABLE(pAd);
1103
1104 /* 3. Enable Tx DMA. */
1105 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &DmaCfg.word);
1106 DmaCfg.field.EnableTxDMA = 1;
1107 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, DmaCfg.word);
1108
1109 /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again. */
1110 if (INFRA_ON(pAd)
1111 && (pAd->CommonCfg.CentralChannel != pAd->CommonCfg.Channel)
1112 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth ==
1113 BW_40)) {
1114 /* Must using 40MHz. */
1115 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel,
1116 FALSE);
1117 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
1118 } else {
1119 /* Must using 20MHz. */
1120 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
1121 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
1122 }
1123
1124/*KH Debug:The following codes should be enclosed by RT3090 compile flag */
1125 if (pChipOps->AsicReverseRfFromSleepMode)
1126 pChipOps->AsicReverseRfFromSleepMode(pAd);
1127
1128#ifdef PCIE_PS_SUPPORT
1129/* 3090 MCU Wakeup command needs more time to be stable. */
1130/* Before stable, don't issue other MCU command to prevent from firmware error. */
1131 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
1132 && IS_VERSION_AFTER_F(pAd)
1133 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
1134 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
1135 RTMP_SEM_LOCK(&pAd->McuCmdLock);
1136 pAd->brt30xxBanMcuCmd = FALSE;
1137 RTMP_SEM_UNLOCK(&pAd->McuCmdLock);
1138 }
1139#endif /* PCIE_PS_SUPPORT // */
1140
1141 /* Clear Radio off flag */
1142 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1143
1144 /* Set LED */
1145 RTMPSetLED(pAd, LED_RADIO_ON);
1146
1147 if (pAd->StaCfg.Psm == PWR_ACTIVE) {
1148 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3,
1149 pAd->StaCfg.BBPR3);
1150 }
1151 } else {
1152 RT28xxPciAsicRadioOff(pAd, GUIRADIO_OFF, 0);
1153 }
1154}
1155
1156/*
1157 ==========================================================================
1158 Description:
1159 This routine sends command to firmware and turn our chip to wake up mode from power save mode.
1160 Both RadioOn and .11 power save function needs to call this routine.
1161 Input:
1162 Level = GUIRADIO_OFF : call this function is from Radio Off to Radio On. Need to restore PCI host value.
1163 Level = other value : normal wake up function.
1164
1165 ==========================================================================
1166 */
1167BOOLEAN RT28xxPciAsicRadioOn(struct rt_rtmp_adapter *pAd, u8 Level)
1168{
1169 /*WPDMA_GLO_CFG_STRUC DmaCfg; */
1170 BOOLEAN Cancelled;
1171 /*u32 MACValue; */
1172
1173 if (pAd->OpMode == OPMODE_AP && Level == DOT11POWERSAVE)
1174 return FALSE;
1175
1176 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
1177 if (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) {
1178 pAd->Mlme.bPsPollTimerRunning = FALSE;
1179 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1180 }
1181 if ((pAd->StaCfg.PSControl.field.EnableNewPS == TRUE &&
1182 (Level == GUIRADIO_OFF || Level == GUI_IDLE_POWER_SAVE)) ||
1183 RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND)) {
1184 /* Some chips don't need to delay 6ms, so copy RTMPPCIePowerLinkCtrlRestore */
1185 /* return condition here. */
1186 /*
1187 if (((pAd->MACVersion&0xffff0000) != 0x28600000)
1188 && ((pAd->DeviceID == NIC2860_PCIe_DEVICE_ID)
1189 ||(pAd->DeviceID == NIC2790_PCIe_DEVICE_ID)))
1190 */
1191 {
1192 DBGPRINT(RT_DEBUG_TRACE,
1193 ("RT28xxPciAsicRadioOn ()\n"));
1194 /* 1. Set PCI Link Control in Configuration Space. */
1195 RTMPPCIeLinkCtrlValueRestore(pAd,
1196 RESTORE_WAKEUP);
1197 RTMPusecDelay(6000);
1198 }
1199 }
1200 }
1201#ifdef PCIE_PS_SUPPORT
1202 if (!
1203 (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
1204 && IS_VERSION_AFTER_F(pAd)
1205 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
1206 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE))))
1207#endif /* PCIE_PS_SUPPORT // */
1208 {
1209 pAd->bPCIclkOff = FALSE;
1210 DBGPRINT(RT_DEBUG_TRACE,
1211 ("PSM :309xbPCIclkOff == %d\n", pAd->bPCIclkOff));
1212 }
1213 /* 2. Send wake up command. */
1214 AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00, 0x02);
1215 pAd->bPCIclkOff = FALSE;
1216 /* 2-1. wait command ok. */
1217 AsicCheckCommanOk(pAd, PowerWakeCID);
1218 RTMP_ASIC_INTERRUPT_ENABLE(pAd);
1219
1220 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF);
1221 if (Level == GUI_IDLE_POWER_SAVE) {
1222#ifdef PCIE_PS_SUPPORT
1223
1224 /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */
1225 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) {
1226 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
1227
1228 if (pChipOps->AsicReverseRfFromSleepMode)
1229 pChipOps->AsicReverseRfFromSleepMode(pAd);
1230 /* 3090 MCU Wakeup command needs more time to be stable. */
1231 /* Before stable, don't issue other MCU command to prevent from firmware error. */
1232 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
1233 && IS_VERSION_AFTER_F(pAd)
1234 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode ==
1235 3)
1236 && (pAd->StaCfg.PSControl.field.EnableNewPS ==
1237 TRUE)) {
1238 RTMP_SEM_LOCK(&pAd->McuCmdLock);
1239 pAd->brt30xxBanMcuCmd = FALSE;
1240 RTMP_SEM_UNLOCK(&pAd->McuCmdLock);
1241 }
1242 } else
1243 /* end johnli */
1244#endif /* PCIE_PS_SUPPORT // */
1245 {
1246 /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again. */
1247 {
1248 if (INFRA_ON(pAd)
1249 && (pAd->CommonCfg.CentralChannel !=
1250 pAd->CommonCfg.Channel)
1251 && (pAd->MlmeAux.HtCapability.HtCapInfo.
1252 ChannelWidth == BW_40)) {
1253 /* Must using 40MHz. */
1254 AsicSwitchChannel(pAd,
1255 pAd->CommonCfg.
1256 CentralChannel,
1257 FALSE);
1258 AsicLockChannel(pAd,
1259 pAd->CommonCfg.
1260 CentralChannel);
1261 } else {
1262 /* Must using 20MHz. */
1263 AsicSwitchChannel(pAd,
1264 pAd->CommonCfg.
1265 Channel, FALSE);
1266 AsicLockChannel(pAd,
1267 pAd->CommonCfg.Channel);
1268 }
1269 }
1270
1271 }
1272 }
1273 return TRUE;
1274
1275}
1276
1277/*
1278 ==========================================================================
1279 Description:
1280 This routine sends command to firmware and turn our chip to power save mode.
1281 Both RadioOff and .11 power save function needs to call this routine.
1282 Input:
1283 Level = GUIRADIO_OFF : GUI Radio Off mode
1284 Level = DOT11POWERSAVE : 802.11 power save mode
1285 Level = RTMP_HALT : When Disable device.
1286
1287 ==========================================================================
1288 */
1289BOOLEAN RT28xxPciAsicRadioOff(struct rt_rtmp_adapter *pAd,
1290 u8 Level, u16 TbttNumToNextWakeUp)
1291{
1292 WPDMA_GLO_CFG_STRUC DmaCfg;
1293 u8 i, tempBBP_R3 = 0;
1294 BOOLEAN brc = FALSE, Cancelled;
1295 u32 TbTTTime = 0;
1296 u32 PsPollTime = 0 /*, MACValue */ ;
1297 unsigned long BeaconPeriodTime;
1298 u32 RxDmaIdx, RxCpuIdx;
1299 DBGPRINT(RT_DEBUG_TRACE,
1300 ("AsicRadioOff ===> Lv= %d, TxCpuIdx = %d, TxDmaIdx = %d. RxCpuIdx = %d, RxDmaIdx = %d.\n",
1301 Level, pAd->TxRing[0].TxCpuIdx, pAd->TxRing[0].TxDmaIdx,
1302 pAd->RxRing.RxCpuIdx, pAd->RxRing.RxDmaIdx));
1303
1304 if (pAd->OpMode == OPMODE_AP && Level == DOT11POWERSAVE)
1305 return FALSE;
1306
1307 /* Check Rx DMA busy status, if more than half is occupied, give up this radio off. */
1308 RTMP_IO_READ32(pAd, RX_DRX_IDX, &RxDmaIdx);
1309 RTMP_IO_READ32(pAd, RX_CRX_IDX, &RxCpuIdx);
1310 if ((RxDmaIdx > RxCpuIdx) && ((RxDmaIdx - RxCpuIdx) > RX_RING_SIZE / 3)) {
1311 DBGPRINT(RT_DEBUG_TRACE,
1312 ("AsicRadioOff ===> return1. RxDmaIdx = %d , RxCpuIdx = %d. \n",
1313 RxDmaIdx, RxCpuIdx));
1314 return FALSE;
1315 } else if ((RxCpuIdx >= RxDmaIdx)
1316 && ((RxCpuIdx - RxDmaIdx) < RX_RING_SIZE / 3)) {
1317 DBGPRINT(RT_DEBUG_TRACE,
1318 ("AsicRadioOff ===> return2. RxCpuIdx = %d. RxDmaIdx = %d , \n",
1319 RxCpuIdx, RxDmaIdx));
1320 return FALSE;
1321 }
1322 /* Once go into this function, disable tx because don't want too many packets in queue to prevent HW stops. */
1323 /*pAd->bPCIclkOffDisableTx = TRUE; */
1324 RTMP_SET_PSFLAG(pAd, fRTMP_PS_DISABLE_TX);
1325 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)
1326 && pAd->OpMode == OPMODE_STA
1327 && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) {
1328 RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer, &Cancelled);
1329 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1330
1331 if (Level == DOT11POWERSAVE) {
1332 RTMP_IO_READ32(pAd, TBTT_TIMER, &TbTTTime);
1333 TbTTTime &= 0x1ffff;
1334 /* 00. check if need to do sleep in this DTIM period. If next beacon will arrive within 30ms , ...doesn't necessarily sleep. */
1335 /* TbTTTime uint = 64us, LEAD_TIME unit = 1024us, PsPollTime unit = 1ms */
1336 if (((64 * TbTTTime) < ((LEAD_TIME * 1024) + 40000))
1337 && (TbttNumToNextWakeUp == 0)) {
1338 DBGPRINT(RT_DEBUG_TRACE,
1339 ("TbTTTime = 0x%x , give up this sleep. \n",
1340 TbTTTime));
1341 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
1342 /*pAd->bPCIclkOffDisableTx = FALSE; */
1343 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_DISABLE_TX);
1344 return FALSE;
1345 } else {
1346 PsPollTime =
1347 (64 * TbTTTime - LEAD_TIME * 1024) / 1000;
1348#ifdef PCIE_PS_SUPPORT
1349 if ((IS_RT3090(pAd) || IS_RT3572(pAd)
1350 || IS_RT3390(pAd))
1351 && IS_VERSION_AFTER_F(pAd)
1352 && (pAd->StaCfg.PSControl.field.
1353 rt30xxPowerMode == 3)
1354 && (pAd->StaCfg.PSControl.field.
1355 EnableNewPS == TRUE)) {
1356 PsPollTime -= 5;
1357 } else
1358#endif /* PCIE_PS_SUPPORT // */
1359 PsPollTime -= 3;
1360
1361 BeaconPeriodTime =
1362 pAd->CommonCfg.BeaconPeriod * 102 / 100;
1363 if (TbttNumToNextWakeUp > 0)
1364 PsPollTime +=
1365 ((TbttNumToNextWakeUp -
1366 1) * BeaconPeriodTime);
1367
1368 pAd->Mlme.bPsPollTimerRunning = TRUE;
1369 RTMPSetTimer(&pAd->Mlme.PsPollTimer,
1370 PsPollTime);
1371 }
1372 }
1373 } else {
1374 DBGPRINT(RT_DEBUG_TRACE,
1375 ("RT28xxPciAsicRadioOff::Level!=DOT11POWERSAVE \n"));
1376 }
1377
1378 pAd->bPCIclkOffDisableTx = FALSE;
1379
1380 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF);
1381
1382 /* Set to 1R. */
1383 if (pAd->Antenna.field.RxPath > 1 && pAd->OpMode == OPMODE_STA) {
1384 tempBBP_R3 = (pAd->StaCfg.BBPR3 & 0xE7);
1385 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, tempBBP_R3);
1386 }
1387 /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again. */
1388 if ((INFRA_ON(pAd) || pAd->OpMode == OPMODE_AP)
1389 && (pAd->CommonCfg.CentralChannel != pAd->CommonCfg.Channel)
1390 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40)) {
1391 /* Must using 40MHz. */
1392 AsicTurnOffRFClk(pAd, pAd->CommonCfg.CentralChannel);
1393 } else {
1394 /* Must using 20MHz. */
1395 AsicTurnOffRFClk(pAd, pAd->CommonCfg.Channel);
1396 }
1397
1398 if (Level != RTMP_HALT) {
1399 /* Change Interrupt bitmask. */
1400 /* When PCI clock is off, don't want to service interrupt. */
1401 RTMP_IO_WRITE32(pAd, INT_MASK_CSR, AutoWakeupInt);
1402 } else {
1403 RTMP_ASIC_INTERRUPT_DISABLE(pAd);
1404 }
1405
1406 RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx);
1407 /* 2. Send Sleep command */
1408 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_STATUS, 0xffffffff);
1409 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CID, 0xffffffff);
1410 /* send POWER-SAVE command to MCU. high-byte = 1 save power as much as possible. high byte = 0 save less power */
1411 AsicSendCommandToMcu(pAd, 0x30, PowerSafeCID, 0xff, 0x1);
1412 /* 2-1. Wait command success */
1413 /* Status = 1 : success, Status = 2, already sleep, Status = 3, Maybe MAC is busy so can't finish this task. */
1414 brc = AsicCheckCommanOk(pAd, PowerSafeCID);
1415
1416 /* 3. After 0x30 command is ok, send radio off command. lowbyte = 0 for power safe. */
1417 /* If 0x30 command is not ok this time, we can ignore 0x35 command. It will make sure not cause firmware'r problem. */
1418 if ((Level == DOT11POWERSAVE) && (brc == TRUE)) {
1419 AsicSendCommandToMcu(pAd, 0x35, PowerRadioOffCID, 0, 0x00); /* lowbyte = 0 means to do power safe, NOT turn off radio. */
1420 /* 3-1. Wait command success */
1421 AsicCheckCommanOk(pAd, PowerRadioOffCID);
1422 } else if (brc == TRUE) {
1423 AsicSendCommandToMcu(pAd, 0x35, PowerRadioOffCID, 1, 0x00); /* lowbyte = 0 means to do power safe, NOT turn off radio. */
1424 /* 3-1. Wait command success */
1425 AsicCheckCommanOk(pAd, PowerRadioOffCID);
1426 }
1427 /* 1. Wait DMA not busy */
1428 i = 0;
1429 do {
1430 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &DmaCfg.word);
1431 if ((DmaCfg.field.RxDMABusy == 0)
1432 && (DmaCfg.field.TxDMABusy == 0))
1433 break;
1434 RTMPusecDelay(20);
1435 i++;
1436 } while (i < 50);
1437
1438 /*
1439 if (i >= 50)
1440 {
1441 pAd->CheckDmaBusyCount++;
1442 DBGPRINT(RT_DEBUG_TRACE, ("DMA Rx keeps busy. return on AsicRadioOff () CheckDmaBusyCount = %d \n", pAd->CheckDmaBusyCount));
1443 }
1444 else
1445 {
1446 pAd->CheckDmaBusyCount = 0;
1447 }
1448 */
1449/*KH Debug:My original codes have the following codes, but currecnt codes do not have it. */
1450/* Disable for stability. If PCIE Link Control is modified for advance power save, re-covery this code segment. */
1451 RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x1280);
1452/*OPSTATUS_SET_FLAG(pAd, fOP_STATUS_CLKSELECT_40MHZ); */
1453
1454#ifdef PCIE_PS_SUPPORT
1455 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
1456 && IS_VERSION_AFTER_F(pAd)
1457 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
1458 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
1459 DBGPRINT(RT_DEBUG_TRACE,
1460 ("RT28xxPciAsicRadioOff::3090 return to skip the following TbttNumToNextWakeUp setting for 279x\n"));
1461 pAd->bPCIclkOff = TRUE;
1462 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_DISABLE_TX);
1463 /* For this case, doesn't need to below actions, so return here. */
1464 return brc;
1465 }
1466#endif /* PCIE_PS_SUPPORT // */
1467
1468 if (Level == DOT11POWERSAVE) {
1469 AUTO_WAKEUP_STRUC AutoWakeupCfg;
1470 /*RTMPSetTimer(&pAd->Mlme.PsPollTimer, 90); */
1471
1472 /* we have decided to SLEEP, so at least do it for a BEACON period. */
1473 if (TbttNumToNextWakeUp == 0)
1474 TbttNumToNextWakeUp = 1;
1475
1476 AutoWakeupCfg.word = 0;
1477 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
1478
1479 /* 1. Set auto wake up timer. */
1480 AutoWakeupCfg.field.NumofSleepingTbtt = TbttNumToNextWakeUp - 1;
1481 AutoWakeupCfg.field.EnableAutoWakeup = 1;
1482 AutoWakeupCfg.field.AutoLeadTime = LEAD_TIME;
1483 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
1484 }
1485 /* 4-1. If it's to disable our device. Need to restore PCI Configuration Space to its original value. */
1486 if (Level == RTMP_HALT && pAd->OpMode == OPMODE_STA) {
1487 if ((brc == TRUE) && (i < 50))
1488 RTMPPCIeLinkCtrlSetting(pAd, 1);
1489 }
1490 /* 4. Set PCI configuration Space Link Comtrol fields. Only Radio Off needs to call this function */
1491 else if (pAd->OpMode == OPMODE_STA) {
1492 if ((brc == TRUE) && (i < 50))
1493 RTMPPCIeLinkCtrlSetting(pAd, 3);
1494 }
1495 /*pAd->bPCIclkOffDisableTx = FALSE; */
1496 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_DISABLE_TX);
1497 return TRUE;
1498}
1499
1500void RT28xxPciMlmeRadioOn(struct rt_rtmp_adapter *pAd)
1501{
1502 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
1503 return;
1504
1505 DBGPRINT(RT_DEBUG_TRACE, ("%s===>\n", __func__));
1506
1507 if ((pAd->OpMode == OPMODE_AP) || ((pAd->OpMode == OPMODE_STA)
1508 &&
1509 (!OPSTATUS_TEST_FLAG
1510 (pAd, fOP_STATUS_PCIE_DEVICE)
1511 || pAd->StaCfg.PSControl.field.
1512 EnableNewPS == FALSE))) {
1513 RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE);
1514 /*NICResetFromError(pAd); */
1515
1516 RTMPRingCleanUp(pAd, QID_AC_BK);
1517 RTMPRingCleanUp(pAd, QID_AC_BE);
1518 RTMPRingCleanUp(pAd, QID_AC_VI);
1519 RTMPRingCleanUp(pAd, QID_AC_VO);
1520 RTMPRingCleanUp(pAd, QID_MGMT);
1521 RTMPRingCleanUp(pAd, QID_RX);
1522
1523 /* Enable Tx/Rx */
1524 RTMPEnableRxTx(pAd);
1525
1526 /* Clear Radio off flag */
1527 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1528
1529 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF);
1530
1531 /* Set LED */
1532 RTMPSetLED(pAd, LED_RADIO_ON);
1533 }
1534
1535 if ((pAd->OpMode == OPMODE_STA) &&
1536 (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE))
1537 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
1538 BOOLEAN Cancelled;
1539
1540 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_WAKEUP);
1541
1542 pAd->Mlme.bPsPollTimerRunning = FALSE;
1543 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1544 RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer, &Cancelled);
1545 RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 40);
1546 }
1547}
1548
1549void RT28xxPciMlmeRadioOFF(struct rt_rtmp_adapter *pAd)
1550{
1551 BOOLEAN brc = TRUE;
1552
1553 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
1554 return;
1555
1556 /* Link down first if any association exists */
1557 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) {
1558 if (INFRA_ON(pAd) || ADHOC_ON(pAd)) {
1559 struct rt_mlme_disassoc_req DisReq;
1560 struct rt_mlme_queue_elem *pMsgElem =
1561 kmalloc(sizeof(struct rt_mlme_queue_elem),
1562 MEM_ALLOC_FLAG);
1563
1564 if (pMsgElem) {
1565 COPY_MAC_ADDR(&DisReq.Addr,
1566 pAd->CommonCfg.Bssid);
1567 DisReq.Reason = REASON_DISASSOC_STA_LEAVING;
1568
1569 pMsgElem->Machine = ASSOC_STATE_MACHINE;
1570 pMsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
1571 pMsgElem->MsgLen =
1572 sizeof(struct rt_mlme_disassoc_req);
1573 NdisMoveMemory(pMsgElem->Msg, &DisReq,
1574 sizeof
1575 (struct rt_mlme_disassoc_req));
1576
1577 MlmeDisassocReqAction(pAd, pMsgElem);
1578 kfree(pMsgElem);
1579
1580 RTMPusecDelay(1000);
1581 }
1582 }
1583 }
1584
1585 DBGPRINT(RT_DEBUG_TRACE, ("%s===>\n", __func__));
1586
1587 /* Set Radio off flag */
1588 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1589
1590 {
1591 BOOLEAN Cancelled;
1592 if (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) {
1593 if (RTMP_TEST_FLAG
1594 (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) {
1595 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer,
1596 &Cancelled);
1597 RTMP_CLEAR_FLAG(pAd,
1598 fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
1599 }
1600 /* If during power safe mode. */
1601 if (pAd->StaCfg.bRadio == TRUE) {
1602 DBGPRINT(RT_DEBUG_TRACE,
1603 ("-->MlmeRadioOff() return on bRadio == TRUE; \n"));
1604 return;
1605 }
1606 /* Always radio on since the NIC needs to set the MCU command (LED_RADIO_OFF). */
1607 if (IDLE_ON(pAd) &&
1608 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF)))
1609 {
1610 RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE);
1611 }
1612 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
1613 BOOLEAN Cancelled;
1614 pAd->Mlme.bPsPollTimerRunning = FALSE;
1615 RTMPCancelTimer(&pAd->Mlme.PsPollTimer,
1616 &Cancelled);
1617 RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer,
1618 &Cancelled);
1619 }
1620 }
1621 /* Link down first if any association exists */
1622 if (INFRA_ON(pAd) || ADHOC_ON(pAd))
1623 LinkDown(pAd, FALSE);
1624 RTMPusecDelay(10000);
1625 /*========================================== */
1626 /* Clean up old bss table */
1627 BssTableInit(&pAd->ScanTab);
1628
1629 /*
1630 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE))
1631 {
1632 RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 10);
1633 return;
1634 }
1635 */
1636 }
1637
1638 /* Set LED.Move to here for fixing LED bug. This flag must be called after LinkDown */
1639 RTMPSetLED(pAd, LED_RADIO_OFF);
1640
1641/*KH Debug:All PCIe devices need to use timer to execute radio off function, or the PCIe&&EnableNewPS needs. */
1642/*KH Ans:It is right, because only when the PCIe and EnableNewPs is true, we need to delay the RadioOffTimer */
1643/*to avoid the deadlock with PCIe Power saving function. */
1644 if (pAd->OpMode == OPMODE_STA &&
1645 OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) &&
1646 pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) {
1647 RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 10);
1648 } else {
1649 brc = RT28xxPciAsicRadioOff(pAd, GUIRADIO_OFF, 0);
1650
1651 if (brc == FALSE) {
1652 DBGPRINT(RT_DEBUG_ERROR,
1653 ("%s call RT28xxPciAsicRadioOff fail!\n",
1654 __func__));
1655 }
1656 }
1657/*
1658*/
1659}
1660
1661#endif /* RTMP_MAC_PCI // */
diff --git a/drivers/staging/rt2860/common/cmm_mac_usb.c b/drivers/staging/rt2860/common/cmm_mac_usb.c
deleted file mode 100644
index 64a65a460c2..00000000000
--- a/drivers/staging/rt2860/common/cmm_mac_usb.c
+++ /dev/null
@@ -1,1162 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27
28#ifdef RTMP_MAC_USB
29
30#include "../rt_config.h"
31
32/*
33========================================================================
34Routine Description:
35 Initialize receive data structures.
36
37Arguments:
38 pAd Pointer to our adapter
39
40Return Value:
41 NDIS_STATUS_SUCCESS
42 NDIS_STATUS_RESOURCES
43
44Note:
45 Initialize all receive releated private buffer, include those define
46 in struct rt_rtmp_adapter structure and all private data structures. The mahor
47 work is to allocate buffer for each packet and chain buffer to
48 NDIS packet descriptor.
49========================================================================
50*/
51int NICInitRecv(struct rt_rtmp_adapter *pAd)
52{
53 u8 i;
54 int Status = NDIS_STATUS_SUCCESS;
55 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
56
57 DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitRecv\n"));
58 pObj = pObj;
59
60 /*InterlockedExchange(&pAd->PendingRx, 0); */
61 pAd->PendingRx = 0;
62 pAd->NextRxBulkInReadIndex = 0; /* Next Rx Read index */
63 pAd->NextRxBulkInIndex = 0; /*RX_RING_SIZE -1; // Rx Bulk pointer */
64 pAd->NextRxBulkInPosition = 0;
65
66 for (i = 0; i < (RX_RING_SIZE); i++) {
67 struct rt_rx_context *pRxContext = &(pAd->RxContext[i]);
68
69 /*Allocate URB */
70 pRxContext->pUrb = RTUSB_ALLOC_URB(0);
71 if (pRxContext->pUrb == NULL) {
72 Status = NDIS_STATUS_RESOURCES;
73 goto out1;
74 }
75 /* Allocate transfer buffer */
76 pRxContext->TransferBuffer =
77 RTUSB_URB_ALLOC_BUFFER(pObj->pUsb_Dev, MAX_RXBULK_SIZE,
78 &pRxContext->data_dma);
79 if (pRxContext->TransferBuffer == NULL) {
80 Status = NDIS_STATUS_RESOURCES;
81 goto out1;
82 }
83
84 NdisZeroMemory(pRxContext->TransferBuffer, MAX_RXBULK_SIZE);
85
86 pRxContext->pAd = pAd;
87 pRxContext->pIrp = NULL;
88 pRxContext->InUse = FALSE;
89 pRxContext->IRPPending = FALSE;
90 pRxContext->Readable = FALSE;
91 /*pRxContext->ReorderInUse = FALSE; */
92 pRxContext->bRxHandling = FALSE;
93 pRxContext->BulkInOffset = 0;
94 }
95
96 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitRecv(Status=%d)\n", Status));
97 return Status;
98
99out1:
100 for (i = 0; i < (RX_RING_SIZE); i++) {
101 struct rt_rx_context *pRxContext = &(pAd->RxContext[i]);
102
103 if (NULL != pRxContext->TransferBuffer) {
104 RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, MAX_RXBULK_SIZE,
105 pRxContext->TransferBuffer,
106 pRxContext->data_dma);
107 pRxContext->TransferBuffer = NULL;
108 }
109
110 if (NULL != pRxContext->pUrb) {
111 RTUSB_UNLINK_URB(pRxContext->pUrb);
112 RTUSB_FREE_URB(pRxContext->pUrb);
113 pRxContext->pUrb = NULL;
114 }
115 }
116
117 return Status;
118}
119
120/*
121========================================================================
122Routine Description:
123 Initialize transmit data structures.
124
125Arguments:
126 pAd Pointer to our adapter
127
128Return Value:
129 NDIS_STATUS_SUCCESS
130 NDIS_STATUS_RESOURCES
131
132Note:
133========================================================================
134*/
135int NICInitTransmit(struct rt_rtmp_adapter *pAd)
136{
137#define LM_USB_ALLOC(pObj, Context, TB_Type, BufferSize, Status, msg1, err1, msg2, err2) \
138 Context->pUrb = RTUSB_ALLOC_URB(0); \
139 if (Context->pUrb == NULL) { \
140 DBGPRINT(RT_DEBUG_ERROR, msg1); \
141 Status = NDIS_STATUS_RESOURCES; \
142 goto err1; } \
143 \
144 Context->TransferBuffer = \
145 (TB_Type)RTUSB_URB_ALLOC_BUFFER(pObj->pUsb_Dev, BufferSize, &Context->data_dma); \
146 if (Context->TransferBuffer == NULL) { \
147 DBGPRINT(RT_DEBUG_ERROR, msg2); \
148 Status = NDIS_STATUS_RESOURCES; \
149 goto err2; }
150
151#define LM_URB_FREE(pObj, Context, BufferSize) \
152 if (NULL != Context->pUrb) { \
153 RTUSB_UNLINK_URB(Context->pUrb); \
154 RTUSB_FREE_URB(Context->pUrb); \
155 Context->pUrb = NULL; } \
156 if (NULL != Context->TransferBuffer) { \
157 RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \
158 Context->TransferBuffer, \
159 Context->data_dma); \
160 Context->TransferBuffer = NULL; }
161
162 u8 i, acidx;
163 int Status = NDIS_STATUS_SUCCESS;
164 struct rt_tx_context *pNullContext = &(pAd->NullContext);
165 struct rt_tx_context *pPsPollContext = &(pAd->PsPollContext);
166 struct rt_tx_context *pRTSContext = &(pAd->RTSContext);
167 struct rt_tx_context *pMLMEContext = NULL;
168/* struct rt_ht_tx_context *pHTTXContext = NULL; */
169 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
170 void *RingBaseVa;
171/* struct rt_rtmp_tx_ring *pTxRing; */
172 struct rt_rtmp_mgmt_ring *pMgmtRing;
173
174 DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitTransmit\n"));
175 pObj = pObj;
176
177 /* Init 4 set of Tx parameters */
178 for (acidx = 0; acidx < NUM_OF_TX_RING; acidx++) {
179 /* Initialize all Transmit releated queues */
180 InitializeQueueHeader(&pAd->TxSwQueue[acidx]);
181
182 /* Next Local tx ring pointer waiting for buck out */
183 pAd->NextBulkOutIndex[acidx] = acidx;
184 pAd->BulkOutPending[acidx] = FALSE; /* Buck Out control flag */
185 /*pAd->DataBulkDoneIdx[acidx] = 0; */
186 }
187
188 /*pAd->NextMLMEIndex = 0; */
189 /*pAd->PushMgmtIndex = 0; */
190 /*pAd->PopMgmtIndex = 0; */
191 /*InterlockedExchange(&pAd->MgmtQueueSize, 0); */
192 /*InterlockedExchange(&pAd->TxCount, 0); */
193
194 /*pAd->PrioRingFirstIndex = 0; */
195 /*pAd->PrioRingTxCnt = 0; */
196
197 do {
198 /* */
199 /* TX_RING_SIZE, 4 ACs */
200 /* */
201 for (acidx = 0; acidx < 4; acidx++) {
202 struct rt_ht_tx_context *pHTTXContext = &(pAd->TxContext[acidx]);
203
204 NdisZeroMemory(pHTTXContext, sizeof(struct rt_ht_tx_context));
205 /*Allocate URB */
206 LM_USB_ALLOC(pObj, pHTTXContext, struct rt_httx_buffer *,
207 sizeof(struct rt_httx_buffer), Status,
208 ("<-- ERROR in Alloc TX TxContext[%d] urb!\n",
209 acidx), done,
210 ("<-- ERROR in Alloc TX TxContext[%d] struct rt_httx_buffer!\n",
211 acidx), out1);
212
213 NdisZeroMemory(pHTTXContext->TransferBuffer->
214 Aggregation, 4);
215 pHTTXContext->pAd = pAd;
216 pHTTXContext->pIrp = NULL;
217 pHTTXContext->IRPPending = FALSE;
218 pHTTXContext->NextBulkOutPosition = 0;
219 pHTTXContext->ENextBulkOutPosition = 0;
220 pHTTXContext->CurWritePosition = 0;
221 pHTTXContext->CurWriteRealPos = 0;
222 pHTTXContext->BulkOutSize = 0;
223 pHTTXContext->BulkOutPipeId = acidx;
224 pHTTXContext->bRingEmpty = TRUE;
225 pHTTXContext->bCopySavePad = FALSE;
226 pAd->BulkOutPending[acidx] = FALSE;
227 }
228
229 /* */
230 /* MGMT_RING_SIZE */
231 /* */
232
233 /* Allocate MGMT ring descriptor's memory */
234 pAd->MgmtDescRing.AllocSize =
235 MGMT_RING_SIZE * sizeof(struct rt_tx_context);
236 os_alloc_mem(pAd, (u8 **) (&pAd->MgmtDescRing.AllocVa),
237 pAd->MgmtDescRing.AllocSize);
238 if (pAd->MgmtDescRing.AllocVa == NULL) {
239 DBGPRINT_ERR("Failed to allocate a big buffer for MgmtDescRing!\n");
240 Status = NDIS_STATUS_RESOURCES;
241 goto out1;
242 }
243 NdisZeroMemory(pAd->MgmtDescRing.AllocVa,
244 pAd->MgmtDescRing.AllocSize);
245 RingBaseVa = pAd->MgmtDescRing.AllocVa;
246
247 /* Initialize MGMT Ring and associated buffer memory */
248 pMgmtRing = &pAd->MgmtRing;
249 for (i = 0; i < MGMT_RING_SIZE; i++) {
250 /* link the pre-allocated Mgmt buffer to MgmtRing.Cell */
251 pMgmtRing->Cell[i].AllocSize = sizeof(struct rt_tx_context);
252 pMgmtRing->Cell[i].AllocVa = RingBaseVa;
253 pMgmtRing->Cell[i].pNdisPacket = NULL;
254 pMgmtRing->Cell[i].pNextNdisPacket = NULL;
255
256 /*Allocate URB for MLMEContext */
257 pMLMEContext =
258 (struct rt_tx_context *)pAd->MgmtRing.Cell[i].AllocVa;
259 pMLMEContext->pUrb = RTUSB_ALLOC_URB(0);
260 if (pMLMEContext->pUrb == NULL) {
261 DBGPRINT(RT_DEBUG_ERROR,
262 ("<-- ERROR in Alloc TX MLMEContext[%d] urb!\n",
263 i));
264 Status = NDIS_STATUS_RESOURCES;
265 goto out2;
266 }
267 pMLMEContext->pAd = pAd;
268 pMLMEContext->pIrp = NULL;
269 pMLMEContext->TransferBuffer = NULL;
270 pMLMEContext->InUse = FALSE;
271 pMLMEContext->IRPPending = FALSE;
272 pMLMEContext->bWaitingBulkOut = FALSE;
273 pMLMEContext->BulkOutSize = 0;
274 pMLMEContext->SelfIdx = i;
275
276 /* Offset to next ring descriptor address */
277 RingBaseVa = (u8 *)RingBaseVa + sizeof(struct rt_tx_context);
278 }
279 DBGPRINT(RT_DEBUG_TRACE,
280 ("MGMT Ring: total %d entry allocated\n", i));
281
282 /*pAd->MgmtRing.TxSwFreeIdx = (MGMT_RING_SIZE - 1); */
283 pAd->MgmtRing.TxSwFreeIdx = MGMT_RING_SIZE;
284 pAd->MgmtRing.TxCpuIdx = 0;
285 pAd->MgmtRing.TxDmaIdx = 0;
286
287 /* */
288 /* BEACON_RING_SIZE */
289 /* */
290 for (i = 0; i < BEACON_RING_SIZE; i++) /* 2 */
291 {
292 struct rt_tx_context *pBeaconContext = &(pAd->BeaconContext[i]);
293
294 NdisZeroMemory(pBeaconContext, sizeof(struct rt_tx_context));
295
296 /*Allocate URB */
297 LM_USB_ALLOC(pObj, pBeaconContext, struct rt_tx_buffer *,
298 sizeof(struct rt_tx_buffer), Status,
299 ("<-- ERROR in Alloc TX BeaconContext[%d] urb!\n",
300 i), out2,
301 ("<-- ERROR in Alloc TX BeaconContext[%d] struct rt_tx_buffer!\n",
302 i), out3);
303
304 pBeaconContext->pAd = pAd;
305 pBeaconContext->pIrp = NULL;
306 pBeaconContext->InUse = FALSE;
307 pBeaconContext->IRPPending = FALSE;
308 }
309
310 /* */
311 /* NullContext */
312 /* */
313 NdisZeroMemory(pNullContext, sizeof(struct rt_tx_context));
314
315 /*Allocate URB */
316 LM_USB_ALLOC(pObj, pNullContext, struct rt_tx_buffer *, sizeof(struct rt_tx_buffer),
317 Status,
318 ("<-- ERROR in Alloc TX NullContext urb!\n"),
319 out3,
320 ("<-- ERROR in Alloc TX NullContext struct rt_tx_buffer!\n"),
321 out4);
322
323 pNullContext->pAd = pAd;
324 pNullContext->pIrp = NULL;
325 pNullContext->InUse = FALSE;
326 pNullContext->IRPPending = FALSE;
327
328 /* */
329 /* RTSContext */
330 /* */
331 NdisZeroMemory(pRTSContext, sizeof(struct rt_tx_context));
332
333 /*Allocate URB */
334 LM_USB_ALLOC(pObj, pRTSContext, struct rt_tx_buffer *, sizeof(struct rt_tx_buffer),
335 Status,
336 ("<-- ERROR in Alloc TX RTSContext urb!\n"),
337 out4,
338 ("<-- ERROR in Alloc TX RTSContext struct rt_tx_buffer!\n"),
339 out5);
340
341 pRTSContext->pAd = pAd;
342 pRTSContext->pIrp = NULL;
343 pRTSContext->InUse = FALSE;
344 pRTSContext->IRPPending = FALSE;
345
346 /* */
347 /* PsPollContext */
348 /* */
349 /*NdisZeroMemory(pPsPollContext, sizeof(struct rt_tx_context)); */
350 /*Allocate URB */
351 LM_USB_ALLOC(pObj, pPsPollContext, struct rt_tx_buffer *,
352 sizeof(struct rt_tx_buffer), Status,
353 ("<-- ERROR in Alloc TX PsPollContext urb!\n"),
354 out5,
355 ("<-- ERROR in Alloc TX PsPollContext struct rt_tx_buffer!\n"),
356 out6);
357
358 pPsPollContext->pAd = pAd;
359 pPsPollContext->pIrp = NULL;
360 pPsPollContext->InUse = FALSE;
361 pPsPollContext->IRPPending = FALSE;
362 pPsPollContext->bAggregatible = FALSE;
363 pPsPollContext->LastOne = TRUE;
364
365 } while (FALSE);
366
367done:
368 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitTransmit(Status=%d)\n", Status));
369
370 return Status;
371
372 /* --------------------------- ERROR HANDLE --------------------------- */
373out6:
374 LM_URB_FREE(pObj, pPsPollContext, sizeof(struct rt_tx_buffer));
375
376out5:
377 LM_URB_FREE(pObj, pRTSContext, sizeof(struct rt_tx_buffer));
378
379out4:
380 LM_URB_FREE(pObj, pNullContext, sizeof(struct rt_tx_buffer));
381
382out3:
383 for (i = 0; i < BEACON_RING_SIZE; i++) {
384 struct rt_tx_context *pBeaconContext = &(pAd->BeaconContext[i]);
385 if (pBeaconContext)
386 LM_URB_FREE(pObj, pBeaconContext, sizeof(struct rt_tx_buffer));
387 }
388
389out2:
390 if (pAd->MgmtDescRing.AllocVa) {
391 pMgmtRing = &pAd->MgmtRing;
392 for (i = 0; i < MGMT_RING_SIZE; i++) {
393 pMLMEContext =
394 (struct rt_tx_context *)pAd->MgmtRing.Cell[i].AllocVa;
395 if (pMLMEContext)
396 LM_URB_FREE(pObj, pMLMEContext,
397 sizeof(struct rt_tx_buffer));
398 }
399 os_free_mem(pAd, pAd->MgmtDescRing.AllocVa);
400 pAd->MgmtDescRing.AllocVa = NULL;
401 }
402
403out1:
404 for (acidx = 0; acidx < 4; acidx++) {
405 struct rt_ht_tx_context *pTxContext = &(pAd->TxContext[acidx]);
406 if (pTxContext)
407 LM_URB_FREE(pObj, pTxContext, sizeof(struct rt_httx_buffer));
408 }
409
410 /* Here we didn't have any pre-allocated memory need to free. */
411
412 return Status;
413}
414
415/*
416========================================================================
417Routine Description:
418 Allocate DMA memory blocks for send, receive.
419
420Arguments:
421 pAd Pointer to our adapter
422
423Return Value:
424 NDIS_STATUS_SUCCESS
425 NDIS_STATUS_FAILURE
426 NDIS_STATUS_RESOURCES
427
428Note:
429========================================================================
430*/
431int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd)
432{
433/* struct rt_counter_802_11 pCounter = &pAd->WlanCounters; */
434 int Status;
435 int num;
436
437 DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocTxRxRingMemory\n"));
438
439 do {
440 /* Init the struct rt_cmdq and CmdQLock */
441 NdisAllocateSpinLock(&pAd->CmdQLock);
442 NdisAcquireSpinLock(&pAd->CmdQLock);
443 RTUSBInitializeCmdQ(&pAd->CmdQ);
444 NdisReleaseSpinLock(&pAd->CmdQLock);
445
446 NdisAllocateSpinLock(&pAd->MLMEBulkOutLock);
447 /*NdisAllocateSpinLock(&pAd->MLMEWaitQueueLock); */
448 NdisAllocateSpinLock(&pAd->BulkOutLock[0]);
449 NdisAllocateSpinLock(&pAd->BulkOutLock[1]);
450 NdisAllocateSpinLock(&pAd->BulkOutLock[2]);
451 NdisAllocateSpinLock(&pAd->BulkOutLock[3]);
452 NdisAllocateSpinLock(&pAd->BulkOutLock[4]);
453 NdisAllocateSpinLock(&pAd->BulkOutLock[5]);
454 NdisAllocateSpinLock(&pAd->BulkInLock);
455
456 for (num = 0; num < NUM_OF_TX_RING; num++) {
457 NdisAllocateSpinLock(&pAd->TxContextQueueLock[num]);
458 }
459
460/* NdisAllocateSpinLock(&pAd->MemLock); // Not used in RT28XX */
461
462/* NdisAllocateSpinLock(&pAd->MacTabLock); // init it in UserCfgInit() */
463/* NdisAllocateSpinLock(&pAd->BATabLock); // init it in BATableInit() */
464
465/* for(num=0; num<MAX_LEN_OF_BA_REC_TABLE; num++) */
466/* { */
467/* NdisAllocateSpinLock(&pAd->BATable.BARecEntry[num].RxReRingLock); */
468/* } */
469
470 /* */
471 /* Init Mac Table */
472 /* */
473/* MacTableInitialize(pAd); */
474
475 /* */
476 /* Init send data structures and related parameters */
477 /* */
478 Status = NICInitTransmit(pAd);
479 if (Status != NDIS_STATUS_SUCCESS)
480 break;
481
482 /* */
483 /* Init receive data structures and related parameters */
484 /* */
485 Status = NICInitRecv(pAd);
486 if (Status != NDIS_STATUS_SUCCESS)
487 break;
488
489 pAd->PendingIoCount = 1;
490
491 } while (FALSE);
492
493 NdisZeroMemory(&pAd->FragFrame, sizeof(struct rt_fragment_frame));
494 pAd->FragFrame.pFragPacket =
495 RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE);
496
497 if (pAd->FragFrame.pFragPacket == NULL) {
498 Status = NDIS_STATUS_RESOURCES;
499 }
500
501 DBGPRINT_S(Status,
502 ("<-- RTMPAllocTxRxRingMemory, Status=%x\n", Status));
503 return Status;
504}
505
506/*
507========================================================================
508Routine Description:
509 Calls USB_InterfaceStop and frees memory allocated for the URBs
510 calls NdisMDeregisterDevice and frees the memory
511 allocated in VNetInitialize for the Adapter Object
512
513Arguments:
514 *pAd the raxx interface data pointer
515
516Return Value:
517 None
518
519Note:
520========================================================================
521*/
522void RTMPFreeTxRxRingMemory(struct rt_rtmp_adapter *pAd)
523{
524#define LM_URB_FREE(pObj, Context, BufferSize) \
525 if (NULL != Context->pUrb) { \
526 RTUSB_UNLINK_URB(Context->pUrb); \
527 RTUSB_FREE_URB(Context->pUrb); \
528 Context->pUrb = NULL; } \
529 if (NULL != Context->TransferBuffer) { \
530 RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \
531 Context->TransferBuffer, \
532 Context->data_dma); \
533 Context->TransferBuffer = NULL; }
534
535 u32 i, acidx;
536 struct rt_tx_context *pNullContext = &pAd->NullContext;
537 struct rt_tx_context *pPsPollContext = &pAd->PsPollContext;
538 struct rt_tx_context *pRTSContext = &pAd->RTSContext;
539/* struct rt_ht_tx_context *pHTTXContext; */
540 /*PRTMP_REORDERBUF pReorderBuf; */
541 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
542/* struct rt_rtmp_tx_ring *pTxRing; */
543
544 DBGPRINT(RT_DEBUG_ERROR, ("---> RTMPFreeTxRxRingMemory\n"));
545 pObj = pObj;
546
547 /* Free all resources for the RECEIVE buffer queue. */
548 for (i = 0; i < (RX_RING_SIZE); i++) {
549 struct rt_rx_context *pRxContext = &(pAd->RxContext[i]);
550 if (pRxContext)
551 LM_URB_FREE(pObj, pRxContext, MAX_RXBULK_SIZE);
552 }
553
554 /* Free PsPoll frame resource */
555 LM_URB_FREE(pObj, pPsPollContext, sizeof(struct rt_tx_buffer));
556
557 /* Free NULL frame resource */
558 LM_URB_FREE(pObj, pNullContext, sizeof(struct rt_tx_buffer));
559
560 /* Free RTS frame resource */
561 LM_URB_FREE(pObj, pRTSContext, sizeof(struct rt_tx_buffer));
562
563 /* Free beacon frame resource */
564 for (i = 0; i < BEACON_RING_SIZE; i++) {
565 struct rt_tx_context *pBeaconContext = &(pAd->BeaconContext[i]);
566 if (pBeaconContext)
567 LM_URB_FREE(pObj, pBeaconContext, sizeof(struct rt_tx_buffer));
568 }
569
570 /* Free mgmt frame resource */
571 for (i = 0; i < MGMT_RING_SIZE; i++) {
572 struct rt_tx_context *pMLMEContext =
573 (struct rt_tx_context *)pAd->MgmtRing.Cell[i].AllocVa;
574 /*LM_URB_FREE(pObj, pMLMEContext, sizeof(struct rt_tx_buffer)); */
575 if (NULL != pAd->MgmtRing.Cell[i].pNdisPacket) {
576 RTMPFreeNdisPacket(pAd,
577 pAd->MgmtRing.Cell[i].pNdisPacket);
578 pAd->MgmtRing.Cell[i].pNdisPacket = NULL;
579 pMLMEContext->TransferBuffer = NULL;
580 }
581
582 if (pMLMEContext) {
583 if (NULL != pMLMEContext->pUrb) {
584 RTUSB_UNLINK_URB(pMLMEContext->pUrb);
585 RTUSB_FREE_URB(pMLMEContext->pUrb);
586 pMLMEContext->pUrb = NULL;
587 }
588 }
589 }
590 if (pAd->MgmtDescRing.AllocVa)
591 os_free_mem(pAd, pAd->MgmtDescRing.AllocVa);
592
593 /* Free Tx frame resource */
594 for (acidx = 0; acidx < 4; acidx++) {
595 struct rt_ht_tx_context *pHTTXContext = &(pAd->TxContext[acidx]);
596 if (pHTTXContext)
597 LM_URB_FREE(pObj, pHTTXContext, sizeof(struct rt_httx_buffer));
598 }
599
600 if (pAd->FragFrame.pFragPacket)
601 RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket,
602 NDIS_STATUS_SUCCESS);
603
604 for (i = 0; i < 6; i++) {
605 NdisFreeSpinLock(&pAd->BulkOutLock[i]);
606 }
607
608 NdisFreeSpinLock(&pAd->BulkInLock);
609 NdisFreeSpinLock(&pAd->MLMEBulkOutLock);
610
611 NdisFreeSpinLock(&pAd->CmdQLock);
612 /* Clear all pending bulk-out request flags. */
613 RTUSB_CLEAR_BULK_FLAG(pAd, 0xffffffff);
614
615/* NdisFreeSpinLock(&pAd->MacTabLock); */
616
617/* for(i=0; i<MAX_LEN_OF_BA_REC_TABLE; i++) */
618/* { */
619/* NdisFreeSpinLock(&pAd->BATable.BARecEntry[i].RxReRingLock); */
620/* } */
621
622 DBGPRINT(RT_DEBUG_ERROR, ("<--- RTMPFreeTxRxRingMemory\n"));
623}
624
625/*
626========================================================================
627Routine Description:
628 Write WLAN MAC address to USB 2870.
629
630Arguments:
631 pAd Pointer to our adapter
632
633Return Value:
634 NDIS_STATUS_SUCCESS
635
636Note:
637========================================================================
638*/
639int RTUSBWriteHWMACAddress(struct rt_rtmp_adapter *pAd)
640{
641 MAC_DW0_STRUC StaMacReg0;
642 MAC_DW1_STRUC StaMacReg1;
643 int Status = NDIS_STATUS_SUCCESS;
644 LARGE_INTEGER NOW;
645
646 /* initialize the random number generator */
647 RTMP_GetCurrentSystemTime(&NOW);
648
649 if (pAd->bLocalAdminMAC != TRUE) {
650 pAd->CurrentAddress[0] = pAd->PermanentAddress[0];
651 pAd->CurrentAddress[1] = pAd->PermanentAddress[1];
652 pAd->CurrentAddress[2] = pAd->PermanentAddress[2];
653 pAd->CurrentAddress[3] = pAd->PermanentAddress[3];
654 pAd->CurrentAddress[4] = pAd->PermanentAddress[4];
655 pAd->CurrentAddress[5] = pAd->PermanentAddress[5];
656 }
657 /* Write New MAC address to MAC_CSR2 & MAC_CSR3 & let ASIC know our new MAC */
658 StaMacReg0.field.Byte0 = pAd->CurrentAddress[0];
659 StaMacReg0.field.Byte1 = pAd->CurrentAddress[1];
660 StaMacReg0.field.Byte2 = pAd->CurrentAddress[2];
661 StaMacReg0.field.Byte3 = pAd->CurrentAddress[3];
662 StaMacReg1.field.Byte4 = pAd->CurrentAddress[4];
663 StaMacReg1.field.Byte5 = pAd->CurrentAddress[5];
664 StaMacReg1.field.U2MeMask = 0xff;
665 DBGPRINT_RAW(RT_DEBUG_TRACE,
666 ("Local MAC = %pM\n", pAd->CurrentAddress));
667
668 RTUSBWriteMACRegister(pAd, MAC_ADDR_DW0, StaMacReg0.word);
669 RTUSBWriteMACRegister(pAd, MAC_ADDR_DW1, StaMacReg1.word);
670 return Status;
671}
672
673/*
674========================================================================
675Routine Description:
676 Disable DMA.
677
678Arguments:
679 *pAd the raxx interface data pointer
680
681Return Value:
682 None
683
684Note:
685========================================================================
686*/
687void RT28XXDMADisable(struct rt_rtmp_adapter *pAd)
688{
689 /* no use */
690}
691
692/*
693========================================================================
694Routine Description:
695 Enable DMA.
696
697Arguments:
698 *pAd the raxx interface data pointer
699
700Return Value:
701 None
702
703Note:
704========================================================================
705*/
706void RT28XXDMAEnable(struct rt_rtmp_adapter *pAd)
707{
708 WPDMA_GLO_CFG_STRUC GloCfg;
709 USB_DMA_CFG_STRUC UsbCfg;
710 int i = 0;
711
712 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
713 do {
714 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
715 if ((GloCfg.field.TxDMABusy == 0)
716 && (GloCfg.field.RxDMABusy == 0))
717 break;
718
719 DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n"));
720 RTMPusecDelay(1000);
721 i++;
722 } while (i < 200);
723
724 RTMPusecDelay(50);
725 GloCfg.field.EnTXWriteBackDDONE = 1;
726 GloCfg.field.EnableRxDMA = 1;
727 GloCfg.field.EnableTxDMA = 1;
728 DBGPRINT(RT_DEBUG_TRACE,
729 ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
730 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
731
732 UsbCfg.word = 0;
733 UsbCfg.field.phyclear = 0;
734 /* usb version is 1.1,do not use bulk in aggregation */
735 if (pAd->BulkInMaxPacketSize == 512)
736 UsbCfg.field.RxBulkAggEn = 1;
737 /* for last packet, PBF might use more than limited, so minus 2 to prevent from error */
738 UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE / 1024) - 3;
739 UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */
740 UsbCfg.field.RxBulkEn = 1;
741 UsbCfg.field.TxBulkEn = 1;
742
743 RTUSBWriteMACRegister(pAd, USB_DMA_CFG, UsbCfg.word);
744
745}
746
747/********************************************************************
748 *
749 * 2870 Beacon Update Related functions.
750 *
751 ********************************************************************/
752
753/*
754========================================================================
755Routine Description:
756 Write Beacon buffer to Asic.
757
758Arguments:
759 *pAd the raxx interface data pointer
760
761Return Value:
762 None
763
764Note:
765========================================================================
766*/
767void RT28xx_UpdateBeaconToAsic(struct rt_rtmp_adapter *pAd,
768 int apidx,
769 unsigned long FrameLen, unsigned long UpdatePos)
770{
771 u8 *pBeaconFrame = NULL;
772 u8 *ptr;
773 u32 i, padding;
774 struct rt_beacon_sync *pBeaconSync = pAd->CommonCfg.pBeaconSync;
775 u32 longValue;
776/* u16 shortValue; */
777 BOOLEAN bBcnReq = FALSE;
778 u8 bcn_idx = 0;
779
780 if (pBeaconFrame == NULL) {
781 DBGPRINT(RT_DEBUG_ERROR, ("pBeaconFrame is NULL!\n"));
782 return;
783 }
784
785 if (pBeaconSync == NULL) {
786 DBGPRINT(RT_DEBUG_ERROR, ("pBeaconSync is NULL!\n"));
787 return;
788 }
789 /*if ((pAd->WdsTab.Mode == WDS_BRIDGE_MODE) || */
790 /* ((pAd->ApCfg.MBSSID[apidx].MSSIDDev == NULL) || !(pAd->ApCfg.MBSSID[apidx].MSSIDDev->flags & IFF_UP)) */
791 /* ) */
792 if (bBcnReq == FALSE) {
793 /* when the ra interface is down, do not send its beacon frame */
794 /* clear all zero */
795 for (i = 0; i < TXWI_SIZE; i += 4) {
796 RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i,
797 0x00);
798 }
799 pBeaconSync->BeaconBitMap &=
800 (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));
801 NdisZeroMemory(pBeaconSync->BeaconTxWI[bcn_idx], TXWI_SIZE);
802 } else {
803 ptr = (u8 *)& pAd->BeaconTxWI;
804 if (NdisEqualMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE) == FALSE) { /* If BeaconTxWI changed, we need to rewrite the TxWI for the Beacon frames. */
805 pBeaconSync->BeaconBitMap &=
806 (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));
807 NdisMoveMemory(pBeaconSync->BeaconTxWI[bcn_idx],
808 &pAd->BeaconTxWI, TXWI_SIZE);
809 }
810
811 if ((pBeaconSync->BeaconBitMap & (1 << bcn_idx)) !=
812 (1 << bcn_idx)) {
813 for (i = 0; i < TXWI_SIZE; i += 4) /* 16-byte TXWI field */
814 {
815 longValue =
816 *ptr + (*(ptr + 1) << 8) +
817 (*(ptr + 2) << 16) + (*(ptr + 3) << 24);
818 RTMP_IO_WRITE32(pAd,
819 pAd->BeaconOffset[bcn_idx] + i,
820 longValue);
821 ptr += 4;
822 }
823 }
824
825 ptr = pBeaconSync->BeaconBuf[bcn_idx];
826 padding = (FrameLen & 0x01);
827 NdisZeroMemory((u8 *)(pBeaconFrame + FrameLen), padding);
828 FrameLen += padding;
829 for (i = 0; i < FrameLen /*HW_BEACON_OFFSET */ ; i += 2) {
830 if (NdisEqualMemory(ptr, pBeaconFrame, 2) == FALSE) {
831 NdisMoveMemory(ptr, pBeaconFrame, 2);
832 /*shortValue = *ptr + (*(ptr+1)<<8); */
833 /*RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, shortValue); */
834 RTUSBMultiWrite(pAd,
835 pAd->BeaconOffset[bcn_idx] +
836 TXWI_SIZE + i, ptr, 2);
837 }
838 ptr += 2;
839 pBeaconFrame += 2;
840 }
841
842 pBeaconSync->BeaconBitMap |= (1 << bcn_idx);
843
844 /* For AP interface, set the DtimBitOn so that we can send Bcast/Mcast frame out after this beacon frame. */
845 }
846
847}
848
849void RTUSBBssBeaconStop(struct rt_rtmp_adapter *pAd)
850{
851 struct rt_beacon_sync *pBeaconSync;
852 int i, offset;
853 BOOLEAN Cancelled = TRUE;
854
855 pBeaconSync = pAd->CommonCfg.pBeaconSync;
856 if (pBeaconSync && pBeaconSync->EnableBeacon) {
857 int NumOfBcn;
858
859 {
860 NumOfBcn = MAX_MESH_NUM;
861 }
862
863 RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);
864
865 for (i = 0; i < NumOfBcn; i++) {
866 NdisZeroMemory(pBeaconSync->BeaconBuf[i],
867 HW_BEACON_OFFSET);
868 NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
869
870 for (offset = 0; offset < HW_BEACON_OFFSET; offset += 4)
871 RTMP_IO_WRITE32(pAd,
872 pAd->BeaconOffset[i] + offset,
873 0x00);
874
875 pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
876 pBeaconSync->TimIELocationInBeacon[i] = 0;
877 }
878 pBeaconSync->BeaconBitMap = 0;
879 pBeaconSync->DtimBitOn = 0;
880 }
881}
882
883void RTUSBBssBeaconStart(struct rt_rtmp_adapter *pAd)
884{
885 int apidx;
886 struct rt_beacon_sync *pBeaconSync;
887/* LARGE_INTEGER tsfTime, deltaTime; */
888
889 pBeaconSync = pAd->CommonCfg.pBeaconSync;
890 if (pBeaconSync && pBeaconSync->EnableBeacon) {
891 int NumOfBcn;
892
893 {
894 NumOfBcn = MAX_MESH_NUM;
895 }
896
897 for (apidx = 0; apidx < NumOfBcn; apidx++) {
898 u8 CapabilityInfoLocationInBeacon = 0;
899 u8 TimIELocationInBeacon = 0;
900
901 NdisZeroMemory(pBeaconSync->BeaconBuf[apidx],
902 HW_BEACON_OFFSET);
903 pBeaconSync->CapabilityInfoLocationInBeacon[apidx] =
904 CapabilityInfoLocationInBeacon;
905 pBeaconSync->TimIELocationInBeacon[apidx] =
906 TimIELocationInBeacon;
907 NdisZeroMemory(pBeaconSync->BeaconTxWI[apidx],
908 TXWI_SIZE);
909 }
910 pBeaconSync->BeaconBitMap = 0;
911 pBeaconSync->DtimBitOn = 0;
912 pAd->CommonCfg.BeaconUpdateTimer.Repeat = TRUE;
913
914 pAd->CommonCfg.BeaconAdjust = 0;
915 pAd->CommonCfg.BeaconFactor =
916 0xffffffff / (pAd->CommonCfg.BeaconPeriod << 10);
917 pAd->CommonCfg.BeaconRemain =
918 (0xffffffff % (pAd->CommonCfg.BeaconPeriod << 10)) + 1;
919 DBGPRINT(RT_DEBUG_TRACE,
920 ("RTUSBBssBeaconStart:BeaconFactor=%d, BeaconRemain=%d!\n",
921 pAd->CommonCfg.BeaconFactor,
922 pAd->CommonCfg.BeaconRemain));
923 RTMPSetTimer(&pAd->CommonCfg.BeaconUpdateTimer,
924 10 /*pAd->CommonCfg.BeaconPeriod */ );
925
926 }
927}
928
929void RTUSBBssBeaconInit(struct rt_rtmp_adapter *pAd)
930{
931 struct rt_beacon_sync *pBeaconSync;
932 int i;
933
934 os_alloc_mem(pAd, (u8 **) (&pAd->CommonCfg.pBeaconSync),
935 sizeof(struct rt_beacon_sync));
936 /*NdisAllocMemory(pAd->CommonCfg.pBeaconSync, sizeof(struct rt_beacon_sync), MEM_ALLOC_FLAG); */
937 if (pAd->CommonCfg.pBeaconSync) {
938 pBeaconSync = pAd->CommonCfg.pBeaconSync;
939 NdisZeroMemory(pBeaconSync, sizeof(struct rt_beacon_sync));
940 for (i = 0; i < HW_BEACON_MAX_COUNT; i++) {
941 NdisZeroMemory(pBeaconSync->BeaconBuf[i],
942 HW_BEACON_OFFSET);
943 pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
944 pBeaconSync->TimIELocationInBeacon[i] = 0;
945 NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
946 }
947 pBeaconSync->BeaconBitMap = 0;
948
949 /*RTMPInitTimer(pAd, &pAd->CommonCfg.BeaconUpdateTimer, GET_TIMER_FUNCTION(BeaconUpdateExec), pAd, TRUE); */
950 pBeaconSync->EnableBeacon = TRUE;
951 }
952}
953
954void RTUSBBssBeaconExit(struct rt_rtmp_adapter *pAd)
955{
956 struct rt_beacon_sync *pBeaconSync;
957 BOOLEAN Cancelled = TRUE;
958 int i;
959
960 if (pAd->CommonCfg.pBeaconSync) {
961 pBeaconSync = pAd->CommonCfg.pBeaconSync;
962 pBeaconSync->EnableBeacon = FALSE;
963 RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);
964 pBeaconSync->BeaconBitMap = 0;
965
966 for (i = 0; i < HW_BEACON_MAX_COUNT; i++) {
967 NdisZeroMemory(pBeaconSync->BeaconBuf[i],
968 HW_BEACON_OFFSET);
969 pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;
970 pBeaconSync->TimIELocationInBeacon[i] = 0;
971 NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);
972 }
973
974 os_free_mem(pAd, pAd->CommonCfg.pBeaconSync);
975 pAd->CommonCfg.pBeaconSync = NULL;
976 }
977}
978
979/*
980 ========================================================================
981 Routine Description:
982 For device work as AP mode but didn't have TBTT interrupt event, we need a mechanism
983 to update the beacon context in each Beacon interval. Here we use a periodical timer
984 to simulate the TBTT interrupt to handle the beacon context update.
985
986 Arguments:
987 SystemSpecific1 - Not used.
988 FunctionContext - Pointer to our Adapter context.
989 SystemSpecific2 - Not used.
990 SystemSpecific3 - Not used.
991
992 Return Value:
993 None
994
995 ========================================================================
996*/
997void BeaconUpdateExec(void *SystemSpecific1,
998 void *FunctionContext,
999 void *SystemSpecific2, void *SystemSpecific3)
1000{
1001 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
1002 LARGE_INTEGER tsfTime_a; /*, tsfTime_b, deltaTime_exp, deltaTime_ab; */
1003 u32 delta, delta2MS, period2US, remain, remain_low, remain_high;
1004/* BOOLEAN positive; */
1005
1006 if (pAd->CommonCfg.IsUpdateBeacon == TRUE) {
1007 ReSyncBeaconTime(pAd);
1008
1009 }
1010
1011 RTMP_IO_READ32(pAd, TSF_TIMER_DW0, &tsfTime_a.u.LowPart);
1012 RTMP_IO_READ32(pAd, TSF_TIMER_DW1, &tsfTime_a.u.HighPart);
1013
1014 /*positive=getDeltaTime(tsfTime_a, expectedTime, &deltaTime_exp); */
1015 period2US = (pAd->CommonCfg.BeaconPeriod << 10);
1016 remain_high = pAd->CommonCfg.BeaconRemain * tsfTime_a.u.HighPart;
1017 remain_low = tsfTime_a.u.LowPart % (pAd->CommonCfg.BeaconPeriod << 10);
1018 remain =
1019 (remain_high + remain_low) % (pAd->CommonCfg.BeaconPeriod << 10);
1020 delta = (pAd->CommonCfg.BeaconPeriod << 10) - remain;
1021
1022 delta2MS = (delta >> 10);
1023 if (delta2MS > 150) {
1024 pAd->CommonCfg.BeaconUpdateTimer.TimerValue = 100;
1025 pAd->CommonCfg.IsUpdateBeacon = FALSE;
1026 } else {
1027 pAd->CommonCfg.BeaconUpdateTimer.TimerValue = delta2MS + 10;
1028 pAd->CommonCfg.IsUpdateBeacon = TRUE;
1029 }
1030
1031}
1032
1033/********************************************************************
1034 *
1035 * 2870 Radio on/off Related functions.
1036 *
1037 ********************************************************************/
1038void RT28xxUsbMlmeRadioOn(struct rt_rtmp_adapter *pAd)
1039{
1040 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
1041
1042 DBGPRINT(RT_DEBUG_TRACE, ("RT28xxUsbMlmeRadioOn()\n"));
1043
1044 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
1045 return;
1046
1047 {
1048 AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02);
1049 RTMPusecDelay(10000);
1050 }
1051 /*NICResetFromError(pAd); */
1052
1053 /* Enable Tx/Rx */
1054 RTMPEnableRxTx(pAd);
1055
1056 if (pChipOps->AsicReverseRfFromSleepMode)
1057 pChipOps->AsicReverseRfFromSleepMode(pAd);
1058
1059 /* Clear Radio off flag */
1060 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1061
1062 RTUSBBulkReceive(pAd);
1063
1064 /* Set LED */
1065 RTMPSetLED(pAd, LED_RADIO_ON);
1066}
1067
1068void RT28xxUsbMlmeRadioOFF(struct rt_rtmp_adapter *pAd)
1069{
1070 WPDMA_GLO_CFG_STRUC GloCfg;
1071 u32 Value, i;
1072
1073 DBGPRINT(RT_DEBUG_TRACE, ("RT28xxUsbMlmeRadioOFF()\n"));
1074
1075 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
1076 return;
1077
1078 /* Clear PMKID cache. */
1079 pAd->StaCfg.SavedPMKNum = 0;
1080 RTMPZeroMemory(pAd->StaCfg.SavedPMK, (PMKID_NO * sizeof(struct rt_bssid_info)));
1081
1082 /* Link down first if any association exists */
1083 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) {
1084 if (INFRA_ON(pAd) || ADHOC_ON(pAd)) {
1085 struct rt_mlme_disassoc_req DisReq;
1086 struct rt_mlme_queue_elem *pMsgElem =
1087 kmalloc(sizeof(struct rt_mlme_queue_elem),
1088 MEM_ALLOC_FLAG);
1089
1090 if (pMsgElem) {
1091 COPY_MAC_ADDR(&DisReq.Addr,
1092 pAd->CommonCfg.Bssid);
1093 DisReq.Reason = REASON_DISASSOC_STA_LEAVING;
1094
1095 pMsgElem->Machine = ASSOC_STATE_MACHINE;
1096 pMsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
1097 pMsgElem->MsgLen =
1098 sizeof(struct rt_mlme_disassoc_req);
1099 NdisMoveMemory(pMsgElem->Msg, &DisReq,
1100 sizeof
1101 (struct rt_mlme_disassoc_req));
1102
1103 MlmeDisassocReqAction(pAd, pMsgElem);
1104 kfree(pMsgElem);
1105
1106 RTMPusecDelay(1000);
1107 }
1108 }
1109 }
1110 /* Set Radio off flag */
1111 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1112
1113 {
1114 /* Link down first if any association exists */
1115 if (INFRA_ON(pAd) || ADHOC_ON(pAd))
1116 LinkDown(pAd, FALSE);
1117 RTMPusecDelay(10000);
1118
1119 /*========================================== */
1120 /* Clean up old bss table */
1121 BssTableInit(&pAd->ScanTab);
1122 }
1123
1124 /* Set LED */
1125 RTMPSetLED(pAd, LED_RADIO_OFF);
1126
1127 if (pAd->CommonCfg.BBPCurrentBW == BW_40) {
1128 /* Must using 40MHz. */
1129 AsicTurnOffRFClk(pAd, pAd->CommonCfg.CentralChannel);
1130 } else {
1131 /* Must using 20MHz. */
1132 AsicTurnOffRFClk(pAd, pAd->CommonCfg.Channel);
1133 }
1134
1135 /* Disable Tx/Rx DMA */
1136 RTUSBReadMACRegister(pAd, WPDMA_GLO_CFG, &GloCfg.word); /* disable DMA */
1137 GloCfg.field.EnableTxDMA = 0;
1138 GloCfg.field.EnableRxDMA = 0;
1139 RTUSBWriteMACRegister(pAd, WPDMA_GLO_CFG, GloCfg.word); /* abort all TX rings */
1140
1141 /* Waiting for DMA idle */
1142 i = 0;
1143 do {
1144 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1145 if ((GloCfg.field.TxDMABusy == 0)
1146 && (GloCfg.field.RxDMABusy == 0))
1147 break;
1148
1149 RTMPusecDelay(1000);
1150 } while (i++ < 100);
1151
1152 /* Disable MAC Tx/Rx */
1153 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1154 Value &= (0xfffffff3);
1155 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1156
1157 {
1158 AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02);
1159 }
1160}
1161
1162#endif /* RTMP_MAC_USB // */
diff --git a/drivers/staging/rt2860/common/cmm_sanity.c b/drivers/staging/rt2860/common/cmm_sanity.c
deleted file mode 100644
index 3bfb4ad00c1..00000000000
--- a/drivers/staging/rt2860/common/cmm_sanity.c
+++ /dev/null
@@ -1,1205 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 sanity.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John Chang 2004-09-01 add WMM support
36*/
37#include "../rt_config.h"
38
39extern u8 CISCO_OUI[];
40
41extern u8 WPA_OUI[];
42extern u8 RSN_OUI[];
43extern u8 WME_INFO_ELEM[];
44extern u8 WME_PARM_ELEM[];
45extern u8 Ccx2QosInfo[];
46extern u8 RALINK_OUI[];
47extern u8 BROADCOM_OUI[];
48extern u8 WPS_OUI[];
49
50/*
51 ==========================================================================
52 Description:
53 MLME message sanity check
54 Return:
55 TRUE if all parameters are OK, FALSE otherwise
56
57 IRQL = DISPATCH_LEVEL
58
59 ==========================================================================
60 */
61BOOLEAN MlmeAddBAReqSanity(struct rt_rtmp_adapter *pAd,
62 void * Msg, unsigned long MsgLen, u8 *pAddr2)
63{
64 struct rt_mlme_addba_req *pInfo;
65
66 pInfo = (struct rt_mlme_addba_req *)Msg;
67
68 if ((MsgLen != sizeof(struct rt_mlme_addba_req))) {
69 DBGPRINT(RT_DEBUG_TRACE,
70 ("MlmeAddBAReqSanity fail - message length not correct.\n"));
71 return FALSE;
72 }
73
74 if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE)) {
75 DBGPRINT(RT_DEBUG_TRACE,
76 ("MlmeAddBAReqSanity fail - The peer Mac is not associated yet.\n"));
77 return FALSE;
78 }
79
80 if ((pInfo->pAddr[0] & 0x01) == 0x01) {
81 DBGPRINT(RT_DEBUG_TRACE,
82 ("MlmeAddBAReqSanity fail - broadcast address not support BA\n"));
83 return FALSE;
84 }
85
86 return TRUE;
87}
88
89/*
90 ==========================================================================
91 Description:
92 MLME message sanity check
93 Return:
94 TRUE if all parameters are OK, FALSE otherwise
95
96 IRQL = DISPATCH_LEVEL
97
98 ==========================================================================
99 */
100BOOLEAN MlmeDelBAReqSanity(struct rt_rtmp_adapter *pAd, void * Msg, unsigned long MsgLen)
101{
102 struct rt_mlme_delba_req *pInfo;
103 pInfo = (struct rt_mlme_delba_req *)Msg;
104
105 if ((MsgLen != sizeof(struct rt_mlme_delba_req))) {
106 DBGPRINT(RT_DEBUG_ERROR,
107 ("MlmeDelBAReqSanity fail - message length not correct.\n"));
108 return FALSE;
109 }
110
111 if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE)) {
112 DBGPRINT(RT_DEBUG_ERROR,
113 ("MlmeDelBAReqSanity fail - The peer Mac is not associated yet.\n"));
114 return FALSE;
115 }
116
117 if ((pInfo->TID & 0xf0)) {
118 DBGPRINT(RT_DEBUG_ERROR,
119 ("MlmeDelBAReqSanity fail - The peer TID is incorrect.\n"));
120 return FALSE;
121 }
122
123 if (NdisEqualMemory
124 (pAd->MacTab.Content[pInfo->Wcid].Addr, pInfo->Addr,
125 MAC_ADDR_LEN) == 0) {
126 DBGPRINT(RT_DEBUG_ERROR,
127 ("MlmeDelBAReqSanity fail - the peer addr dosen't exist.\n"));
128 return FALSE;
129 }
130
131 return TRUE;
132}
133
134BOOLEAN PeerAddBAReqActionSanity(struct rt_rtmp_adapter *pAd,
135 void * pMsg,
136 unsigned long MsgLen, u8 *pAddr2)
137{
138 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) pMsg;
139 struct rt_frame_addba_req * pAddFrame;
140 pAddFrame = (struct rt_frame_addba_req *) (pMsg);
141 if (MsgLen < (sizeof(struct rt_frame_addba_req))) {
142 DBGPRINT(RT_DEBUG_ERROR,
143 ("PeerAddBAReqActionSanity: ADDBA Request frame length size = %ld incorrect\n",
144 MsgLen));
145 return FALSE;
146 }
147 /* we support immediate BA. */
148 *(u16 *) (&pAddFrame->BaParm) =
149 cpu2le16(*(u16 *) (&pAddFrame->BaParm));
150 pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue);
151 pAddFrame->BaStartSeq.word = cpu2le16(pAddFrame->BaStartSeq.word);
152
153 if (pAddFrame->BaParm.BAPolicy != IMMED_BA) {
154 DBGPRINT(RT_DEBUG_ERROR,
155 ("PeerAddBAReqActionSanity: ADDBA Request Ba Policy[%d] not support\n",
156 pAddFrame->BaParm.BAPolicy));
157 DBGPRINT(RT_DEBUG_ERROR,
158 ("ADDBA Request. tid=%x, Bufsize=%x, AMSDUSupported=%x \n",
159 pAddFrame->BaParm.TID, pAddFrame->BaParm.BufSize,
160 pAddFrame->BaParm.AMSDUSupported));
161 return FALSE;
162 }
163 /* we support immediate BA. */
164 if (pAddFrame->BaParm.TID & 0xfff0) {
165 DBGPRINT(RT_DEBUG_ERROR,
166 ("PeerAddBAReqActionSanity: ADDBA Request incorrect TID = %d\n",
167 pAddFrame->BaParm.TID));
168 return FALSE;
169 }
170 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
171 return TRUE;
172}
173
174BOOLEAN PeerAddBARspActionSanity(struct rt_rtmp_adapter *pAd,
175 void * pMsg, unsigned long MsgLen)
176{
177 struct rt_frame_addba_rsp * pAddFrame;
178
179 pAddFrame = (struct rt_frame_addba_rsp *) (pMsg);
180 if (MsgLen < (sizeof(struct rt_frame_addba_rsp))) {
181 DBGPRINT(RT_DEBUG_ERROR,
182 ("PeerAddBARspActionSanity: ADDBA Response frame length size = %ld incorrect\n",
183 MsgLen));
184 return FALSE;
185 }
186 /* we support immediate BA. */
187 *(u16 *) (&pAddFrame->BaParm) =
188 cpu2le16(*(u16 *) (&pAddFrame->BaParm));
189 pAddFrame->StatusCode = cpu2le16(pAddFrame->StatusCode);
190 pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue);
191
192 if (pAddFrame->BaParm.BAPolicy != IMMED_BA) {
193 DBGPRINT(RT_DEBUG_ERROR,
194 ("PeerAddBAReqActionSanity: ADDBA Response Ba Policy[%d] not support\n",
195 pAddFrame->BaParm.BAPolicy));
196 return FALSE;
197 }
198 /* we support immediate BA. */
199 if (pAddFrame->BaParm.TID & 0xfff0) {
200 DBGPRINT(RT_DEBUG_ERROR,
201 ("PeerAddBARspActionSanity: ADDBA Response incorrect TID = %d\n",
202 pAddFrame->BaParm.TID));
203 return FALSE;
204 }
205 return TRUE;
206
207}
208
209BOOLEAN PeerDelBAActionSanity(struct rt_rtmp_adapter *pAd,
210 u8 Wcid, void * pMsg, unsigned long MsgLen)
211{
212 /*struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *)pMsg; */
213 struct rt_frame_delba_req * pDelFrame;
214 if (MsgLen != (sizeof(struct rt_frame_delba_req)))
215 return FALSE;
216
217 if (Wcid >= MAX_LEN_OF_MAC_TABLE)
218 return FALSE;
219
220 pDelFrame = (struct rt_frame_delba_req *) (pMsg);
221
222 *(u16 *) (&pDelFrame->DelbaParm) =
223 cpu2le16(*(u16 *) (&pDelFrame->DelbaParm));
224 pDelFrame->ReasonCode = cpu2le16(pDelFrame->ReasonCode);
225
226 if (pDelFrame->DelbaParm.TID & 0xfff0)
227 return FALSE;
228
229 return TRUE;
230}
231
232/*
233 ==========================================================================
234 Description:
235 MLME message sanity check
236 Return:
237 TRUE if all parameters are OK, FALSE otherwise
238
239 IRQL = DISPATCH_LEVEL
240
241 ==========================================================================
242 */
243BOOLEAN PeerBeaconAndProbeRspSanity(struct rt_rtmp_adapter *pAd, void * Msg, unsigned long MsgLen, u8 MsgChannel, u8 *pAddr2, u8 *pBssid, char Ssid[], u8 * pSsidLen, u8 * pBssType, u16 * pBeaconPeriod, u8 * pChannel, u8 * pNewChannel, OUT LARGE_INTEGER * pTimestamp, struct rt_cf_parm * pCfParm, u16 * pAtimWin, u16 * pCapabilityInfo, u8 * pErp, u8 * pDtimCount, u8 * pDtimPeriod, u8 * pBcastFlag, u8 * pMessageToMe, u8 SupRate[], u8 * pSupRateLen, u8 ExtRate[], u8 * pExtRateLen, u8 * pCkipFlag, u8 * pAironetCellPowerLimit, struct rt_edca_parm *pEdcaParm, struct rt_qbss_load_parm *pQbssLoad, struct rt_qos_capability_parm *pQosCapability, unsigned long * pRalinkIe, u8 * pHtCapabilityLen, u8 * pPreNHtCapabilityLen, struct rt_ht_capability_ie * pHtCapability, u8 * AddHtInfoLen, struct rt_add_ht_info_ie * AddHtInfo, u8 * NewExtChannelOffset, /* Ht extension channel offset(above or below) */
244 u16 * LengthVIE,
245 struct rt_ndis_802_11_variable_ies *pVIE)
246{
247 u8 *Ptr;
248 u8 TimLen;
249 struct rt_frame_802_11 * pFrame;
250 struct rt_eid * pEid;
251 u8 SubType;
252 u8 Sanity;
253 /*u8 ECWMin, ECWMax; */
254 /*MAC_CSR9_STRUC Csr9; */
255 unsigned long Length = 0;
256
257 /* For some 11a AP which didn't have DS_IE, we use two conditions to decide the channel */
258 /* 1. If the AP is 11n enabled, then check the control channel. */
259 /* 2. If the AP didn't have any info about channel, use the channel we received this frame as the channel. (May inaccuracy!) */
260 u8 CtrlChannel = 0;
261
262 /* Add for 3 necessary EID field check */
263 Sanity = 0;
264
265 *pAtimWin = 0;
266 *pErp = 0;
267 *pDtimCount = 0;
268 *pDtimPeriod = 0;
269 *pBcastFlag = 0;
270 *pMessageToMe = 0;
271 *pExtRateLen = 0;
272 *pCkipFlag = 0; /* Default of CkipFlag is 0 */
273 *pAironetCellPowerLimit = 0xFF; /* Default of AironetCellPowerLimit is 0xFF */
274 *LengthVIE = 0; /* Set the length of VIE to init value 0 */
275 *pHtCapabilityLen = 0; /* Set the length of VIE to init value 0 */
276 if (pAd->OpMode == OPMODE_STA)
277 *pPreNHtCapabilityLen = 0; /* Set the length of VIE to init value 0 */
278 *AddHtInfoLen = 0; /* Set the length of VIE to init value 0 */
279 *pRalinkIe = 0;
280 *pNewChannel = 0;
281 *NewExtChannelOffset = 0xff; /*Default 0xff means no such IE */
282 pCfParm->bValid = FALSE; /* default: no IE_CF found */
283 pQbssLoad->bValid = FALSE; /* default: no IE_QBSS_LOAD found */
284 pEdcaParm->bValid = FALSE; /* default: no IE_EDCA_PARAMETER found */
285 pQosCapability->bValid = FALSE; /* default: no IE_QOS_CAPABILITY found */
286
287 pFrame = (struct rt_frame_802_11 *) Msg;
288
289 /* get subtype from header */
290 SubType = (u8)pFrame->Hdr.FC.SubType;
291
292 /* get Addr2 and BSSID from header */
293 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
294 COPY_MAC_ADDR(pBssid, pFrame->Hdr.Addr3);
295
296 Ptr = pFrame->Octet;
297 Length += LENGTH_802_11;
298
299 /* get timestamp from payload and advance the pointer */
300 NdisMoveMemory(pTimestamp, Ptr, TIMESTAMP_LEN);
301
302 pTimestamp->u.LowPart = cpu2le32(pTimestamp->u.LowPart);
303 pTimestamp->u.HighPart = cpu2le32(pTimestamp->u.HighPart);
304
305 Ptr += TIMESTAMP_LEN;
306 Length += TIMESTAMP_LEN;
307
308 /* get beacon interval from payload and advance the pointer */
309 NdisMoveMemory(pBeaconPeriod, Ptr, 2);
310 Ptr += 2;
311 Length += 2;
312
313 /* get capability info from payload and advance the pointer */
314 NdisMoveMemory(pCapabilityInfo, Ptr, 2);
315 Ptr += 2;
316 Length += 2;
317
318 if (CAP_IS_ESS_ON(*pCapabilityInfo))
319 *pBssType = BSS_INFRA;
320 else
321 *pBssType = BSS_ADHOC;
322
323 pEid = (struct rt_eid *) Ptr;
324
325 /* get variable fields from payload and advance the pointer */
326 while ((Length + 2 + pEid->Len) <= MsgLen) {
327 /* */
328 /* Secure copy VIE to VarIE[MAX_VIE_LEN] didn't overflow. */
329 /* */
330 if ((*LengthVIE + pEid->Len + 2) >= MAX_VIE_LEN) {
331 DBGPRINT(RT_DEBUG_WARN,
332 ("PeerBeaconAndProbeRspSanity - Variable IEs out of resource [len(=%d) > MAX_VIE_LEN(=%d)]\n",
333 (*LengthVIE + pEid->Len + 2), MAX_VIE_LEN));
334 break;
335 }
336
337 switch (pEid->Eid) {
338 case IE_SSID:
339 /* Already has one SSID EID in this beacon, ignore the second one */
340 if (Sanity & 0x1)
341 break;
342 if (pEid->Len <= MAX_LEN_OF_SSID) {
343 NdisMoveMemory(Ssid, pEid->Octet, pEid->Len);
344 *pSsidLen = pEid->Len;
345 Sanity |= 0x1;
346 } else {
347 DBGPRINT(RT_DEBUG_TRACE,
348 ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n",
349 pEid->Len));
350 return FALSE;
351 }
352 break;
353
354 case IE_SUPP_RATES:
355 if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) {
356 Sanity |= 0x2;
357 NdisMoveMemory(SupRate, pEid->Octet, pEid->Len);
358 *pSupRateLen = pEid->Len;
359
360 /* TODO: 2004-09-14 not a good design here, cause it exclude extra rates */
361 /* from ScanTab. We should report as is. And filter out unsupported */
362 /* rates in MlmeAux. */
363 /* Check against the supported rates */
364 /* RTMPCheckRates(pAd, SupRate, pSupRateLen); */
365 } else {
366 DBGPRINT(RT_DEBUG_TRACE,
367 ("PeerBeaconAndProbeRspSanity - wrong IE_SUPP_RATES (len=%d)\n",
368 pEid->Len));
369 return FALSE;
370 }
371 break;
372
373 case IE_HT_CAP:
374 if (pEid->Len >= SIZE_HT_CAP_IE) /*Note: allow extension! */
375 {
376 NdisMoveMemory(pHtCapability, pEid->Octet,
377 sizeof(struct rt_ht_capability_ie));
378 *pHtCapabilityLen = SIZE_HT_CAP_IE; /* Nnow we only support 26 bytes. */
379
380 *(u16 *) (&pHtCapability->HtCapInfo) =
381 cpu2le16(*(u16 *)
382 (&pHtCapability->HtCapInfo));
383 *(u16 *) (&pHtCapability->ExtHtCapInfo) =
384 cpu2le16(*(u16 *)
385 (&pHtCapability->ExtHtCapInfo));
386
387 {
388 *pPreNHtCapabilityLen = 0; /* Nnow we only support 26 bytes. */
389
390 Ptr = (u8 *)pVIE;
391 NdisMoveMemory(Ptr + *LengthVIE,
392 &pEid->Eid,
393 pEid->Len + 2);
394 *LengthVIE += (pEid->Len + 2);
395 }
396 } else {
397 DBGPRINT(RT_DEBUG_WARN,
398 ("PeerBeaconAndProbeRspSanity - wrong IE_HT_CAP. pEid->Len = %d\n",
399 pEid->Len));
400 }
401
402 break;
403 case IE_ADD_HT:
404 if (pEid->Len >= sizeof(struct rt_add_ht_info_ie)) {
405 /* This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only */
406 /* copy first sizeof(struct rt_add_ht_info_ie) */
407 NdisMoveMemory(AddHtInfo, pEid->Octet,
408 sizeof(struct rt_add_ht_info_ie));
409 *AddHtInfoLen = SIZE_ADD_HT_INFO_IE;
410
411 CtrlChannel = AddHtInfo->ControlChan;
412
413 *(u16 *) (&AddHtInfo->AddHtInfo2) =
414 cpu2le16(*(u16 *)
415 (&AddHtInfo->AddHtInfo2));
416 *(u16 *) (&AddHtInfo->AddHtInfo3) =
417 cpu2le16(*(u16 *)
418 (&AddHtInfo->AddHtInfo3));
419
420 {
421 Ptr = (u8 *)pVIE;
422 NdisMoveMemory(Ptr + *LengthVIE,
423 &pEid->Eid,
424 pEid->Len + 2);
425 *LengthVIE += (pEid->Len + 2);
426 }
427 } else {
428 DBGPRINT(RT_DEBUG_WARN,
429 ("PeerBeaconAndProbeRspSanity - wrong IE_ADD_HT. \n"));
430 }
431
432 break;
433 case IE_SECONDARY_CH_OFFSET:
434 if (pEid->Len == 1) {
435 *NewExtChannelOffset = pEid->Octet[0];
436 } else {
437 DBGPRINT(RT_DEBUG_WARN,
438 ("PeerBeaconAndProbeRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));
439 }
440
441 break;
442 case IE_FH_PARM:
443 DBGPRINT(RT_DEBUG_TRACE,
444 ("PeerBeaconAndProbeRspSanity(IE_FH_PARM) \n"));
445 break;
446
447 case IE_DS_PARM:
448 if (pEid->Len == 1) {
449 *pChannel = *pEid->Octet;
450
451 {
452 if (ChannelSanity(pAd, *pChannel) == 0) {
453
454 return FALSE;
455 }
456 }
457
458 Sanity |= 0x4;
459 } else {
460 DBGPRINT(RT_DEBUG_TRACE,
461 ("PeerBeaconAndProbeRspSanity - wrong IE_DS_PARM (len=%d)\n",
462 pEid->Len));
463 return FALSE;
464 }
465 break;
466
467 case IE_CF_PARM:
468 if (pEid->Len == 6) {
469 pCfParm->bValid = TRUE;
470 pCfParm->CfpCount = pEid->Octet[0];
471 pCfParm->CfpPeriod = pEid->Octet[1];
472 pCfParm->CfpMaxDuration =
473 pEid->Octet[2] + 256 * pEid->Octet[3];
474 pCfParm->CfpDurRemaining =
475 pEid->Octet[4] + 256 * pEid->Octet[5];
476 } else {
477 DBGPRINT(RT_DEBUG_TRACE,
478 ("PeerBeaconAndProbeRspSanity - wrong IE_CF_PARM\n"));
479 return FALSE;
480 }
481 break;
482
483 case IE_IBSS_PARM:
484 if (pEid->Len == 2) {
485 NdisMoveMemory(pAtimWin, pEid->Octet,
486 pEid->Len);
487 } else {
488 DBGPRINT(RT_DEBUG_TRACE,
489 ("PeerBeaconAndProbeRspSanity - wrong IE_IBSS_PARM\n"));
490 return FALSE;
491 }
492 break;
493
494 case IE_TIM:
495 if (INFRA_ON(pAd) && SubType == SUBTYPE_BEACON) {
496 GetTimBit((char *)pEid, pAd->StaActive.Aid,
497 &TimLen, pBcastFlag, pDtimCount,
498 pDtimPeriod, pMessageToMe);
499 }
500 break;
501 case IE_CHANNEL_SWITCH_ANNOUNCEMENT:
502 if (pEid->Len == 3) {
503 *pNewChannel = pEid->Octet[1]; /*extract new channel number */
504 }
505 break;
506
507 /* New for WPA */
508 /* CCX v2 has the same IE, we need to parse that too */
509 /* Wifi WMM use the same IE vale, need to parse that too */
510 /* case IE_WPA: */
511 case IE_VENDOR_SPECIFIC:
512 /* Check Broadcom/Atheros 802.11n OUI version, for HT Capability IE. */
513 /* This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan. */
514 /*if (NdisEqualMemory(pEid->Octet, BROADCOM_OUI, 3) && (pEid->Len >= 4))
515 {
516 if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 30))
517 {
518 {
519 NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(struct rt_ht_capability_ie));
520 *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes.
521 }
522 }
523 if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 26))
524 {
525 {
526 NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(struct rt_add_ht_info_ie));
527 *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; // Nnow we only support 26 bytes.
528 }
529 }
530 }
531 */
532 /* Check the OUI version, filter out non-standard usage */
533 if (NdisEqualMemory(pEid->Octet, RALINK_OUI, 3)
534 && (pEid->Len == 7)) {
535 /**pRalinkIe = pEid->Octet[3]; */
536 if (pEid->Octet[3] != 0)
537 *pRalinkIe = pEid->Octet[3];
538 else
539 *pRalinkIe = 0xf0000000; /* Set to non-zero value (can't set bit0-2) to represent this is Ralink Chip. So at linkup, we will set ralinkchip flag. */
540 }
541 /* This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan. */
542
543 /* Other vendors had production before IE_HT_CAP value is assigned. To backward support those old-firmware AP, */
544 /* Check broadcom-defiend pre-802.11nD1.0 OUI for HT related IE, including HT Capatilities IE and HT Information IE */
545 else if ((*pHtCapabilityLen == 0)
546 && NdisEqualMemory(pEid->Octet, PRE_N_HT_OUI,
547 3) && (pEid->Len >= 4)
548 && (pAd->OpMode == OPMODE_STA)) {
549 if ((pEid->Octet[3] == OUI_PREN_HT_CAP)
550 && (pEid->Len >= 30)
551 && (*pHtCapabilityLen == 0)) {
552 NdisMoveMemory(pHtCapability,
553 &pEid->Octet[4],
554 sizeof
555 (struct rt_ht_capability_ie));
556 *pPreNHtCapabilityLen = SIZE_HT_CAP_IE;
557 }
558
559 if ((pEid->Octet[3] == OUI_PREN_ADD_HT)
560 && (pEid->Len >= 26)) {
561 NdisMoveMemory(AddHtInfo,
562 &pEid->Octet[4],
563 sizeof(struct rt_add_ht_info_ie));
564 *AddHtInfoLen = SIZE_ADD_HT_INFO_IE;
565 }
566 } else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)) {
567 /* Copy to pVIE which will report to microsoft bssid list. */
568 Ptr = (u8 *)pVIE;
569 NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid,
570 pEid->Len + 2);
571 *LengthVIE += (pEid->Len + 2);
572 } else
573 if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6)
574 && (pEid->Len == 24)) {
575 u8 *ptr;
576 int i;
577
578 /* parsing EDCA parameters */
579 pEdcaParm->bValid = TRUE;
580 pEdcaParm->bQAck = FALSE; /* pEid->Octet[0] & 0x10; */
581 pEdcaParm->bQueueRequest = FALSE; /* pEid->Octet[0] & 0x20; */
582 pEdcaParm->bTxopRequest = FALSE; /* pEid->Octet[0] & 0x40; */
583 pEdcaParm->EdcaUpdateCount =
584 pEid->Octet[6] & 0x0f;
585 pEdcaParm->bAPSDCapable =
586 (pEid->Octet[6] & 0x80) ? 1 : 0;
587 ptr = &pEid->Octet[8];
588 for (i = 0; i < 4; i++) {
589 u8 aci = (*ptr & 0x60) >> 5; /* b5~6 is AC INDEX */
590 pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); /* b5 is ACM */
591 pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; /* b0~3 is AIFSN */
592 pEdcaParm->Cwmin[aci] = *(ptr + 1) & 0x0f; /* b0~4 is Cwmin */
593 pEdcaParm->Cwmax[aci] = *(ptr + 1) >> 4; /* b5~8 is Cwmax */
594 pEdcaParm->Txop[aci] = *(ptr + 2) + 256 * (*(ptr + 3)); /* in unit of 32-us */
595 ptr += 4; /* point to next AC */
596 }
597 } else
598 if (NdisEqualMemory(pEid->Octet, WME_INFO_ELEM, 6)
599 && (pEid->Len == 7)) {
600 /* parsing EDCA parameters */
601 pEdcaParm->bValid = TRUE;
602 pEdcaParm->bQAck = FALSE; /* pEid->Octet[0] & 0x10; */
603 pEdcaParm->bQueueRequest = FALSE; /* pEid->Octet[0] & 0x20; */
604 pEdcaParm->bTxopRequest = FALSE; /* pEid->Octet[0] & 0x40; */
605 pEdcaParm->EdcaUpdateCount =
606 pEid->Octet[6] & 0x0f;
607 pEdcaParm->bAPSDCapable =
608 (pEid->Octet[6] & 0x80) ? 1 : 0;
609
610 /* use default EDCA parameter */
611 pEdcaParm->bACM[QID_AC_BE] = 0;
612 pEdcaParm->Aifsn[QID_AC_BE] = 3;
613 pEdcaParm->Cwmin[QID_AC_BE] = CW_MIN_IN_BITS;
614 pEdcaParm->Cwmax[QID_AC_BE] = CW_MAX_IN_BITS;
615 pEdcaParm->Txop[QID_AC_BE] = 0;
616
617 pEdcaParm->bACM[QID_AC_BK] = 0;
618 pEdcaParm->Aifsn[QID_AC_BK] = 7;
619 pEdcaParm->Cwmin[QID_AC_BK] = CW_MIN_IN_BITS;
620 pEdcaParm->Cwmax[QID_AC_BK] = CW_MAX_IN_BITS;
621 pEdcaParm->Txop[QID_AC_BK] = 0;
622
623 pEdcaParm->bACM[QID_AC_VI] = 0;
624 pEdcaParm->Aifsn[QID_AC_VI] = 2;
625 pEdcaParm->Cwmin[QID_AC_VI] =
626 CW_MIN_IN_BITS - 1;
627 pEdcaParm->Cwmax[QID_AC_VI] = CW_MAX_IN_BITS;
628 pEdcaParm->Txop[QID_AC_VI] = 96; /* AC_VI: 96*32us ~= 3ms */
629
630 pEdcaParm->bACM[QID_AC_VO] = 0;
631 pEdcaParm->Aifsn[QID_AC_VO] = 2;
632 pEdcaParm->Cwmin[QID_AC_VO] =
633 CW_MIN_IN_BITS - 2;
634 pEdcaParm->Cwmax[QID_AC_VO] =
635 CW_MAX_IN_BITS - 1;
636 pEdcaParm->Txop[QID_AC_VO] = 48; /* AC_VO: 48*32us ~= 1.5ms */
637 }
638
639 break;
640
641 case IE_EXT_SUPP_RATES:
642 if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) {
643 NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);
644 *pExtRateLen = pEid->Len;
645
646 /* TODO: 2004-09-14 not a good design here, cause it exclude extra rates */
647 /* from ScanTab. We should report as is. And filter out unsupported */
648 /* rates in MlmeAux. */
649 /* Check against the supported rates */
650 /* RTMPCheckRates(pAd, ExtRate, pExtRateLen); */
651 }
652 break;
653
654 case IE_ERP:
655 if (pEid->Len == 1) {
656 *pErp = (u8)pEid->Octet[0];
657 }
658 break;
659
660 case IE_AIRONET_CKIP:
661 /* 0. Check Aironet IE length, it must be larger or equal to 28 */
662 /* Cisco AP350 used length as 28 */
663 /* Cisco AP12XX used length as 30 */
664 if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2))
665 break;
666
667 /* 1. Copy CKIP flag byte to buffer for process */
668 *pCkipFlag = *(pEid->Octet + 8);
669 break;
670
671 case IE_AP_TX_POWER:
672 /* AP Control of Client Transmit Power */
673 /*0. Check Aironet IE length, it must be 6 */
674 if (pEid->Len != 0x06)
675 break;
676
677 /* Get cell power limit in dBm */
678 if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1)
679 *pAironetCellPowerLimit = *(pEid->Octet + 4);
680 break;
681
682 /* WPA2 & 802.11i RSN */
683 case IE_RSN:
684 /* There is no OUI for version anymore, check the group cipher OUI before copying */
685 if (RTMPEqualMemory(pEid->Octet + 2, RSN_OUI, 3)) {
686 /* Copy to pVIE which will report to microsoft bssid list. */
687 Ptr = (u8 *)pVIE;
688 NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid,
689 pEid->Len + 2);
690 *LengthVIE += (pEid->Len + 2);
691 }
692 break;
693
694 default:
695 break;
696 }
697
698 Length = Length + 2 + pEid->Len; /* Eid[1] + Len[1]+ content[Len] */
699 pEid = (struct rt_eid *) ((u8 *) pEid + 2 + pEid->Len);
700 }
701
702 /* For some 11a AP. it did not have the channel EID, patch here */
703 {
704 u8 LatchRfChannel = MsgChannel;
705 if ((pAd->LatchRfRegs.Channel > 14) && ((Sanity & 0x4) == 0)) {
706 if (CtrlChannel != 0)
707 *pChannel = CtrlChannel;
708 else
709 *pChannel = LatchRfChannel;
710 Sanity |= 0x4;
711 }
712 }
713
714 if (Sanity != 0x7) {
715 DBGPRINT(RT_DEBUG_LOUD,
716 ("PeerBeaconAndProbeRspSanity - missing field, Sanity=0x%02x\n",
717 Sanity));
718 return FALSE;
719 } else {
720 return TRUE;
721 }
722
723}
724
725/*
726 ==========================================================================
727 Description:
728 MLME message sanity check
729 Return:
730 TRUE if all parameters are OK, FALSE otherwise
731 ==========================================================================
732 */
733BOOLEAN MlmeScanReqSanity(struct rt_rtmp_adapter *pAd,
734 void * Msg,
735 unsigned long MsgLen,
736 u8 * pBssType,
737 char Ssid[],
738 u8 * pSsidLen, u8 * pScanType)
739{
740 struct rt_mlme_scan_req *Info;
741
742 Info = (struct rt_mlme_scan_req *)(Msg);
743 *pBssType = Info->BssType;
744 *pSsidLen = Info->SsidLen;
745 NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);
746 *pScanType = Info->ScanType;
747
748 if ((*pBssType == BSS_INFRA || *pBssType == BSS_ADHOC
749 || *pBssType == BSS_ANY)
750 && (*pScanType == SCAN_ACTIVE || *pScanType == SCAN_PASSIVE)) {
751 return TRUE;
752 } else {
753 DBGPRINT(RT_DEBUG_TRACE,
754 ("MlmeScanReqSanity fail - wrong BssType or ScanType\n"));
755 return FALSE;
756 }
757}
758
759/* IRQL = DISPATCH_LEVEL */
760u8 ChannelSanity(struct rt_rtmp_adapter *pAd, u8 channel)
761{
762 int i;
763
764 for (i = 0; i < pAd->ChannelListNum; i++) {
765 if (channel == pAd->ChannelList[i].Channel)
766 return 1;
767 }
768 return 0;
769}
770
771/*
772 ==========================================================================
773 Description:
774 MLME message sanity check
775 Return:
776 TRUE if all parameters are OK, FALSE otherwise
777
778 IRQL = DISPATCH_LEVEL
779
780 ==========================================================================
781 */
782BOOLEAN PeerDeauthSanity(struct rt_rtmp_adapter *pAd,
783 void * Msg,
784 unsigned long MsgLen,
785 u8 *pAddr2, u16 * pReason)
786{
787 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg;
788
789 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
790 NdisMoveMemory(pReason, &pFrame->Octet[0], 2);
791
792 return TRUE;
793}
794
795/*
796 ==========================================================================
797 Description:
798 MLME message sanity check
799 Return:
800 TRUE if all parameters are OK, FALSE otherwise
801
802 IRQL = DISPATCH_LEVEL
803
804 ==========================================================================
805 */
806BOOLEAN PeerAuthSanity(struct rt_rtmp_adapter *pAd,
807 void * Msg,
808 unsigned long MsgLen,
809 u8 *pAddr,
810 u16 * pAlg,
811 u16 * pSeq,
812 u16 * pStatus, char * pChlgText)
813{
814 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg;
815
816 COPY_MAC_ADDR(pAddr, pFrame->Hdr.Addr2);
817 NdisMoveMemory(pAlg, &pFrame->Octet[0], 2);
818 NdisMoveMemory(pSeq, &pFrame->Octet[2], 2);
819 NdisMoveMemory(pStatus, &pFrame->Octet[4], 2);
820
821 if (*pAlg == AUTH_MODE_OPEN) {
822 if (*pSeq == 1 || *pSeq == 2) {
823 return TRUE;
824 } else {
825 DBGPRINT(RT_DEBUG_TRACE,
826 ("PeerAuthSanity fail - wrong Seg#\n"));
827 return FALSE;
828 }
829 } else if (*pAlg == AUTH_MODE_KEY) {
830 if (*pSeq == 1 || *pSeq == 4) {
831 return TRUE;
832 } else if (*pSeq == 2 || *pSeq == 3) {
833 NdisMoveMemory(pChlgText, &pFrame->Octet[8],
834 CIPHER_TEXT_LEN);
835 return TRUE;
836 } else {
837 DBGPRINT(RT_DEBUG_TRACE,
838 ("PeerAuthSanity fail - wrong Seg#\n"));
839 return FALSE;
840 }
841 } else {
842 DBGPRINT(RT_DEBUG_TRACE,
843 ("PeerAuthSanity fail - wrong algorithm\n"));
844 return FALSE;
845 }
846}
847
848/*
849 ==========================================================================
850 Description:
851 MLME message sanity check
852 Return:
853 TRUE if all parameters are OK, FALSE otherwise
854 ==========================================================================
855 */
856BOOLEAN MlmeAuthReqSanity(struct rt_rtmp_adapter *pAd,
857 void * Msg,
858 unsigned long MsgLen,
859 u8 *pAddr,
860 unsigned long * pTimeout, u16 * pAlg)
861{
862 struct rt_mlme_auth_req *pInfo;
863
864 pInfo = (struct rt_mlme_auth_req *)Msg;
865 COPY_MAC_ADDR(pAddr, pInfo->Addr);
866 *pTimeout = pInfo->Timeout;
867 *pAlg = pInfo->Alg;
868
869 if (((*pAlg == AUTH_MODE_KEY) || (*pAlg == AUTH_MODE_OPEN)
870 ) && ((*pAddr & 0x01) == 0)) {
871 return TRUE;
872 } else {
873 DBGPRINT(RT_DEBUG_TRACE,
874 ("MlmeAuthReqSanity fail - wrong algorithm\n"));
875 return FALSE;
876 }
877}
878
879/*
880 ==========================================================================
881 Description:
882 MLME message sanity check
883 Return:
884 TRUE if all parameters are OK, FALSE otherwise
885
886 IRQL = DISPATCH_LEVEL
887
888 ==========================================================================
889 */
890BOOLEAN MlmeAssocReqSanity(struct rt_rtmp_adapter *pAd,
891 void * Msg,
892 unsigned long MsgLen,
893 u8 *pApAddr,
894 u16 * pCapabilityInfo,
895 unsigned long * pTimeout, u16 * pListenIntv)
896{
897 struct rt_mlme_assoc_req *pInfo;
898
899 pInfo = (struct rt_mlme_assoc_req *)Msg;
900 *pTimeout = pInfo->Timeout; /* timeout */
901 COPY_MAC_ADDR(pApAddr, pInfo->Addr); /* AP address */
902 *pCapabilityInfo = pInfo->CapabilityInfo; /* capability info */
903 *pListenIntv = pInfo->ListenIntv;
904
905 return TRUE;
906}
907
908/*
909 ==========================================================================
910 Description:
911 MLME message sanity check
912 Return:
913 TRUE if all parameters are OK, FALSE otherwise
914
915 IRQL = DISPATCH_LEVEL
916
917 ==========================================================================
918 */
919BOOLEAN PeerDisassocSanity(struct rt_rtmp_adapter *pAd,
920 void * Msg,
921 unsigned long MsgLen,
922 u8 *pAddr2, u16 * pReason)
923{
924 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg;
925
926 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
927 NdisMoveMemory(pReason, &pFrame->Octet[0], 2);
928
929 return TRUE;
930}
931
932/*
933 ========================================================================
934 Routine Description:
935 Sanity check NetworkType (11b, 11g or 11a)
936
937 Arguments:
938 pBss - Pointer to BSS table.
939
940 Return Value:
941 Ndis802_11DS .......(11b)
942 Ndis802_11OFDM24....(11g)
943 Ndis802_11OFDM5.....(11a)
944
945 IRQL = DISPATCH_LEVEL
946
947 ========================================================================
948*/
949NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(struct rt_bss_entry *pBss)
950{
951 NDIS_802_11_NETWORK_TYPE NetWorkType;
952 u8 rate, i;
953
954 NetWorkType = Ndis802_11DS;
955
956 if (pBss->Channel <= 14) {
957 /* */
958 /* First check support Rate. */
959 /* */
960 for (i = 0; i < pBss->SupRateLen; i++) {
961 rate = pBss->SupRate[i] & 0x7f; /* Mask out basic rate set bit */
962 if ((rate == 2) || (rate == 4) || (rate == 11)
963 || (rate == 22)) {
964 continue;
965 } else {
966 /* */
967 /* Otherwise (even rate > 108) means Ndis802_11OFDM24 */
968 /* */
969 NetWorkType = Ndis802_11OFDM24;
970 break;
971 }
972 }
973
974 /* */
975 /* Second check Extend Rate. */
976 /* */
977 if (NetWorkType != Ndis802_11OFDM24) {
978 for (i = 0; i < pBss->ExtRateLen; i++) {
979 rate = pBss->SupRate[i] & 0x7f; /* Mask out basic rate set bit */
980 if ((rate == 2) || (rate == 4) || (rate == 11)
981 || (rate == 22)) {
982 continue;
983 } else {
984 /* */
985 /* Otherwise (even rate > 108) means Ndis802_11OFDM24 */
986 /* */
987 NetWorkType = Ndis802_11OFDM24;
988 break;
989 }
990 }
991 }
992 } else {
993 NetWorkType = Ndis802_11OFDM5;
994 }
995
996 if (pBss->HtCapabilityLen != 0) {
997 if (NetWorkType == Ndis802_11OFDM5)
998 NetWorkType = Ndis802_11OFDM5_N;
999 else
1000 NetWorkType = Ndis802_11OFDM24_N;
1001 }
1002
1003 return NetWorkType;
1004}
1005
1006/*
1007 ==========================================================================
1008 Description:
1009 Check the validity of the received EAPoL frame
1010 Return:
1011 TRUE if all parameters are OK,
1012 FALSE otherwise
1013 ==========================================================================
1014 */
1015BOOLEAN PeerWpaMessageSanity(struct rt_rtmp_adapter *pAd,
1016 struct rt_eapol_packet * pMsg,
1017 unsigned long MsgLen,
1018 u8 MsgType, struct rt_mac_table_entry *pEntry)
1019{
1020 u8 mic[LEN_KEY_DESC_MIC], digest[80], KEYDATA[MAX_LEN_OF_RSNIE];
1021 BOOLEAN bReplayDiff = FALSE;
1022 BOOLEAN bWPA2 = FALSE;
1023 struct rt_key_info EapolKeyInfo;
1024 u8 GroupKeyIndex = 0;
1025
1026 NdisZeroMemory(mic, sizeof(mic));
1027 NdisZeroMemory(digest, sizeof(digest));
1028 NdisZeroMemory(KEYDATA, sizeof(KEYDATA));
1029 NdisZeroMemory((u8 *)& EapolKeyInfo, sizeof(EapolKeyInfo));
1030
1031 NdisMoveMemory((u8 *)& EapolKeyInfo,
1032 (u8 *)& pMsg->KeyDesc.KeyInfo, sizeof(struct rt_key_info));
1033
1034 *((u16 *) & EapolKeyInfo) = cpu2le16(*((u16 *) & EapolKeyInfo));
1035
1036 /* Choose WPA2 or not */
1037 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2)
1038 || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK))
1039 bWPA2 = TRUE;
1040
1041 /* 0. Check MsgType */
1042 if ((MsgType > EAPOL_GROUP_MSG_2) || (MsgType < EAPOL_PAIR_MSG_1)) {
1043 DBGPRINT(RT_DEBUG_ERROR,
1044 ("The message type is invalid(%d)! \n", MsgType));
1045 return FALSE;
1046 }
1047 /* 1. Replay counter check */
1048 if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1) /* For supplicant */
1049 {
1050 /* First validate replay counter, only accept message with larger replay counter. */
1051 /* Let equal pass, some AP start with all zero replay counter */
1052 u8 ZeroReplay[LEN_KEY_DESC_REPLAY];
1053
1054 NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY);
1055 if ((RTMPCompareMemory
1056 (pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter,
1057 LEN_KEY_DESC_REPLAY) != 1)
1058 &&
1059 (RTMPCompareMemory
1060 (pMsg->KeyDesc.ReplayCounter, ZeroReplay,
1061 LEN_KEY_DESC_REPLAY) != 0)) {
1062 bReplayDiff = TRUE;
1063 }
1064 } else if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2) /* For authenticator */
1065 {
1066 /* check Replay Counter coresponds to MSG from authenticator, otherwise discard */
1067 if (!NdisEqualMemory
1068 (pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter,
1069 LEN_KEY_DESC_REPLAY)) {
1070 bReplayDiff = TRUE;
1071 }
1072 }
1073 /* Replay Counter different condition */
1074 if (bReplayDiff) {
1075 /* send wireless event - for replay counter different */
1076 if (pAd->CommonCfg.bWirelessEvent)
1077 RTMPSendWirelessEvent(pAd,
1078 IW_REPLAY_COUNTER_DIFF_EVENT_FLAG,
1079 pEntry->Addr, pEntry->apidx, 0);
1080
1081 if (MsgType < EAPOL_GROUP_MSG_1) {
1082 DBGPRINT(RT_DEBUG_ERROR,
1083 ("Replay Counter Different in pairwise msg %d of 4-way handshake!\n",
1084 MsgType));
1085 } else {
1086 DBGPRINT(RT_DEBUG_ERROR,
1087 ("Replay Counter Different in group msg %d of 2-way handshake!\n",
1088 (MsgType - EAPOL_PAIR_MSG_4)));
1089 }
1090
1091 hex_dump("Receive replay counter ", pMsg->KeyDesc.ReplayCounter,
1092 LEN_KEY_DESC_REPLAY);
1093 hex_dump("Current replay counter ", pEntry->R_Counter,
1094 LEN_KEY_DESC_REPLAY);
1095 return FALSE;
1096 }
1097 /* 2. Verify MIC except Pairwise Msg1 */
1098 if (MsgType != EAPOL_PAIR_MSG_1) {
1099 u8 rcvd_mic[LEN_KEY_DESC_MIC];
1100
1101 /* Record the received MIC for check later */
1102 NdisMoveMemory(rcvd_mic, pMsg->KeyDesc.KeyMic,
1103 LEN_KEY_DESC_MIC);
1104 NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
1105
1106 if (EapolKeyInfo.KeyDescVer == DESC_TYPE_TKIP) /* TKIP */
1107 {
1108 HMAC_MD5(pEntry->PTK, LEN_EAP_MICK, (u8 *)pMsg,
1109 MsgLen, mic, MD5_DIGEST_SIZE);
1110 } else if (EapolKeyInfo.KeyDescVer == DESC_TYPE_AES) /* AES */
1111 {
1112 HMAC_SHA1(pEntry->PTK, LEN_EAP_MICK, (u8 *)pMsg,
1113 MsgLen, digest, SHA1_DIGEST_SIZE);
1114 NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC);
1115 }
1116
1117 if (!NdisEqualMemory(rcvd_mic, mic, LEN_KEY_DESC_MIC)) {
1118 /* send wireless event - for MIC different */
1119 if (pAd->CommonCfg.bWirelessEvent)
1120 RTMPSendWirelessEvent(pAd,
1121 IW_MIC_DIFF_EVENT_FLAG,
1122 pEntry->Addr,
1123 pEntry->apidx, 0);
1124
1125 if (MsgType < EAPOL_GROUP_MSG_1) {
1126 DBGPRINT(RT_DEBUG_ERROR,
1127 ("MIC Different in pairwise msg %d of 4-way handshake!\n",
1128 MsgType));
1129 } else {
1130 DBGPRINT(RT_DEBUG_ERROR,
1131 ("MIC Different in group msg %d of 2-way handshake!\n",
1132 (MsgType - EAPOL_PAIR_MSG_4)));
1133 }
1134
1135 hex_dump("Received MIC", rcvd_mic, LEN_KEY_DESC_MIC);
1136 hex_dump("Desired MIC", mic, LEN_KEY_DESC_MIC);
1137
1138 return FALSE;
1139 }
1140 }
1141 /* 1. Decrypt the Key Data field if GTK is included. */
1142 /* 2. Extract the context of the Key Data field if it exist. */
1143 /* The field in pairwise_msg_2_WPA1(WPA2) & pairwise_msg_3_WPA1 is clear. */
1144 /* The field in group_msg_1_WPA1(WPA2) & pairwise_msg_3_WPA2 is encrypted. */
1145 if (CONV_ARRARY_TO_u16(pMsg->KeyDesc.KeyDataLen) > 0) {
1146 /* Decrypt this field */
1147 if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2)
1148 || (MsgType == EAPOL_GROUP_MSG_1)) {
1149 if ((EapolKeyInfo.KeyDescVer == DESC_TYPE_AES)) {
1150 /* AES */
1151 AES_GTK_KEY_UNWRAP(&pEntry->PTK[16], KEYDATA,
1152 CONV_ARRARY_TO_u16(pMsg->
1153 KeyDesc.
1154 KeyDataLen),
1155 pMsg->KeyDesc.KeyData);
1156 } else {
1157 int i;
1158 u8 Key[32];
1159 /* Decrypt TKIP GTK */
1160 /* Construct 32 bytes RC4 Key */
1161 NdisMoveMemory(Key, pMsg->KeyDesc.KeyIv, 16);
1162 NdisMoveMemory(&Key[16], &pEntry->PTK[16], 16);
1163 ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key,
1164 32);
1165 /*discard first 256 bytes */
1166 for (i = 0; i < 256; i++)
1167 ARCFOUR_BYTE(&pAd->PrivateInfo.
1168 WEPCONTEXT);
1169 /* Decrypt GTK. Becareful, there is no ICV to check the result is correct or not */
1170 ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT,
1171 KEYDATA, pMsg->KeyDesc.KeyData,
1172 CONV_ARRARY_TO_u16(pMsg->
1173 KeyDesc.
1174 KeyDataLen));
1175 }
1176
1177 if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))
1178 GroupKeyIndex = EapolKeyInfo.KeyIndex;
1179
1180 } else if ((MsgType == EAPOL_PAIR_MSG_2)
1181 || (MsgType == EAPOL_PAIR_MSG_3 && !bWPA2)) {
1182 NdisMoveMemory(KEYDATA, pMsg->KeyDesc.KeyData,
1183 CONV_ARRARY_TO_u16(pMsg->KeyDesc.
1184 KeyDataLen));
1185 } else {
1186
1187 return TRUE;
1188 }
1189
1190 /* Parse Key Data field to */
1191 /* 1. verify RSN IE for pairwise_msg_2_WPA1(WPA2) ,pairwise_msg_3_WPA1(WPA2) */
1192 /* 2. verify KDE format for pairwise_msg_3_WPA2, group_msg_1_WPA2 */
1193 /* 3. update shared key for pairwise_msg_3_WPA2, group_msg_1_WPA1(WPA2) */
1194 if (!RTMPParseEapolKeyData(pAd, KEYDATA,
1195 CONV_ARRARY_TO_u16(pMsg->KeyDesc.
1196 KeyDataLen),
1197 GroupKeyIndex, MsgType, bWPA2,
1198 pEntry)) {
1199 return FALSE;
1200 }
1201 }
1202
1203 return TRUE;
1204
1205}
diff --git a/drivers/staging/rt2860/common/cmm_sync.c b/drivers/staging/rt2860/common/cmm_sync.c
deleted file mode 100644
index aefe1b77465..00000000000
--- a/drivers/staging/rt2860/common/cmm_sync.c
+++ /dev/null
@@ -1,718 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 cmm_sync.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John Chang 2004-09-01 modified for rt2561/2661
36*/
37#include "../rt_config.h"
38
39/* 2.4 Ghz channel plan index in the TxPower arrays. */
40#define BG_BAND_REGION_0_START 0 /* 1,2,3,4,5,6,7,8,9,10,11 */
41#define BG_BAND_REGION_0_SIZE 11
42#define BG_BAND_REGION_1_START 0 /* 1,2,3,4,5,6,7,8,9,10,11,12,13 */
43#define BG_BAND_REGION_1_SIZE 13
44#define BG_BAND_REGION_2_START 9 /* 10,11 */
45#define BG_BAND_REGION_2_SIZE 2
46#define BG_BAND_REGION_3_START 9 /* 10,11,12,13 */
47#define BG_BAND_REGION_3_SIZE 4
48#define BG_BAND_REGION_4_START 13 /* 14 */
49#define BG_BAND_REGION_4_SIZE 1
50#define BG_BAND_REGION_5_START 0 /* 1,2,3,4,5,6,7,8,9,10,11,12,13,14 */
51#define BG_BAND_REGION_5_SIZE 14
52#define BG_BAND_REGION_6_START 2 /* 3,4,5,6,7,8,9 */
53#define BG_BAND_REGION_6_SIZE 7
54#define BG_BAND_REGION_7_START 4 /* 5,6,7,8,9,10,11,12,13 */
55#define BG_BAND_REGION_7_SIZE 9
56#define BG_BAND_REGION_31_START 0 /* 1,2,3,4,5,6,7,8,9,10,11,12,13,14 */
57#define BG_BAND_REGION_31_SIZE 14
58
59/* 5 Ghz channel plan index in the TxPower arrays. */
60u8 A_BAND_REGION_0_CHANNEL_LIST[] =
61 { 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165 };
62u8 A_BAND_REGION_1_CHANNEL_LIST[] =
63 { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128,
64132, 136, 140 };
65u8 A_BAND_REGION_2_CHANNEL_LIST[] = { 36, 40, 44, 48, 52, 56, 60, 64 };
66u8 A_BAND_REGION_3_CHANNEL_LIST[] = { 52, 56, 60, 64, 149, 153, 157, 161 };
67u8 A_BAND_REGION_4_CHANNEL_LIST[] = { 149, 153, 157, 161, 165 };
68u8 A_BAND_REGION_5_CHANNEL_LIST[] = { 149, 153, 157, 161 };
69u8 A_BAND_REGION_6_CHANNEL_LIST[] = { 36, 40, 44, 48 };
70u8 A_BAND_REGION_7_CHANNEL_LIST[] =
71 { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128,
72132, 136, 140, 149, 153, 157, 161, 165, 169, 173 };
73u8 A_BAND_REGION_8_CHANNEL_LIST[] = { 52, 56, 60, 64 };
74u8 A_BAND_REGION_9_CHANNEL_LIST[] =
75 { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140,
76149, 153, 157, 161, 165 };
77u8 A_BAND_REGION_10_CHANNEL_LIST[] =
78 { 36, 40, 44, 48, 149, 153, 157, 161, 165 };
79u8 A_BAND_REGION_11_CHANNEL_LIST[] =
80 { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 149, 153,
81157, 161 };
82u8 A_BAND_REGION_12_CHANNEL_LIST[] =
83 { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128,
84132, 136, 140 };
85u8 A_BAND_REGION_13_CHANNEL_LIST[] =
86 { 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140,
87149, 153, 157, 161 };
88u8 A_BAND_REGION_14_CHANNEL_LIST[] =
89 { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 136, 140, 149,
90153, 157, 161, 165 };
91u8 A_BAND_REGION_15_CHANNEL_LIST[] = { 149, 153, 157, 161, 165, 169, 173 };
92
93/*BaSizeArray follows the 802.11n definition as MaxRxFactor. 2^(13+factor) bytes. When factor =0, it's about Ba buffer size =8. */
94u8 BaSizeArray[4] = { 8, 16, 32, 64 };
95
96/*
97 ==========================================================================
98 Description:
99 Update StaCfg->ChannelList[] according to 1) Country Region 2) RF IC type,
100 and 3) PHY-mode user selected.
101 The outcome is used by driver when doing site survey.
102
103 IRQL = PASSIVE_LEVEL
104 IRQL = DISPATCH_LEVEL
105
106 ==========================================================================
107 */
108void BuildChannelList(struct rt_rtmp_adapter *pAd)
109{
110 u8 i, j, index = 0, num = 0;
111 u8 *pChannelList = NULL;
112
113 NdisZeroMemory(pAd->ChannelList,
114 MAX_NUM_OF_CHANNELS * sizeof(struct rt_channel_tx_power));
115
116 /* if not 11a-only mode, channel list starts from 2.4Ghz band */
117 if ((pAd->CommonCfg.PhyMode != PHY_11A)
118 && (pAd->CommonCfg.PhyMode != PHY_11AN_MIXED)
119 && (pAd->CommonCfg.PhyMode != PHY_11N_5G)
120 ) {
121 switch (pAd->CommonCfg.CountryRegion & 0x7f) {
122 case REGION_0_BG_BAND: /* 1 -11 */
123 NdisMoveMemory(&pAd->ChannelList[index],
124 &pAd->TxPower[BG_BAND_REGION_0_START],
125 sizeof(struct rt_channel_tx_power) *
126 BG_BAND_REGION_0_SIZE);
127 index += BG_BAND_REGION_0_SIZE;
128 break;
129 case REGION_1_BG_BAND: /* 1 - 13 */
130 NdisMoveMemory(&pAd->ChannelList[index],
131 &pAd->TxPower[BG_BAND_REGION_1_START],
132 sizeof(struct rt_channel_tx_power) *
133 BG_BAND_REGION_1_SIZE);
134 index += BG_BAND_REGION_1_SIZE;
135 break;
136 case REGION_2_BG_BAND: /* 10 - 11 */
137 NdisMoveMemory(&pAd->ChannelList[index],
138 &pAd->TxPower[BG_BAND_REGION_2_START],
139 sizeof(struct rt_channel_tx_power) *
140 BG_BAND_REGION_2_SIZE);
141 index += BG_BAND_REGION_2_SIZE;
142 break;
143 case REGION_3_BG_BAND: /* 10 - 13 */
144 NdisMoveMemory(&pAd->ChannelList[index],
145 &pAd->TxPower[BG_BAND_REGION_3_START],
146 sizeof(struct rt_channel_tx_power) *
147 BG_BAND_REGION_3_SIZE);
148 index += BG_BAND_REGION_3_SIZE;
149 break;
150 case REGION_4_BG_BAND: /* 14 */
151 NdisMoveMemory(&pAd->ChannelList[index],
152 &pAd->TxPower[BG_BAND_REGION_4_START],
153 sizeof(struct rt_channel_tx_power) *
154 BG_BAND_REGION_4_SIZE);
155 index += BG_BAND_REGION_4_SIZE;
156 break;
157 case REGION_5_BG_BAND: /* 1 - 14 */
158 NdisMoveMemory(&pAd->ChannelList[index],
159 &pAd->TxPower[BG_BAND_REGION_5_START],
160 sizeof(struct rt_channel_tx_power) *
161 BG_BAND_REGION_5_SIZE);
162 index += BG_BAND_REGION_5_SIZE;
163 break;
164 case REGION_6_BG_BAND: /* 3 - 9 */
165 NdisMoveMemory(&pAd->ChannelList[index],
166 &pAd->TxPower[BG_BAND_REGION_6_START],
167 sizeof(struct rt_channel_tx_power) *
168 BG_BAND_REGION_6_SIZE);
169 index += BG_BAND_REGION_6_SIZE;
170 break;
171 case REGION_7_BG_BAND: /* 5 - 13 */
172 NdisMoveMemory(&pAd->ChannelList[index],
173 &pAd->TxPower[BG_BAND_REGION_7_START],
174 sizeof(struct rt_channel_tx_power) *
175 BG_BAND_REGION_7_SIZE);
176 index += BG_BAND_REGION_7_SIZE;
177 break;
178 case REGION_31_BG_BAND: /* 1 - 14 */
179 NdisMoveMemory(&pAd->ChannelList[index],
180 &pAd->TxPower[BG_BAND_REGION_31_START],
181 sizeof(struct rt_channel_tx_power) *
182 BG_BAND_REGION_31_SIZE);
183 index += BG_BAND_REGION_31_SIZE;
184 break;
185 default: /* Error. should never happen */
186 break;
187 }
188 for (i = 0; i < index; i++)
189 pAd->ChannelList[i].MaxTxPwr = 20;
190 }
191
192 if ((pAd->CommonCfg.PhyMode == PHY_11A)
193 || (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED)
194 || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED)
195 || (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED)
196 || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED)
197 || (pAd->CommonCfg.PhyMode == PHY_11N_5G)
198 ) {
199 switch (pAd->CommonCfg.CountryRegionForABand & 0x7f) {
200 case REGION_0_A_BAND:
201 num =
202 sizeof(A_BAND_REGION_0_CHANNEL_LIST) /
203 sizeof(u8);
204 pChannelList = A_BAND_REGION_0_CHANNEL_LIST;
205 break;
206 case REGION_1_A_BAND:
207 num =
208 sizeof(A_BAND_REGION_1_CHANNEL_LIST) /
209 sizeof(u8);
210 pChannelList = A_BAND_REGION_1_CHANNEL_LIST;
211 break;
212 case REGION_2_A_BAND:
213 num =
214 sizeof(A_BAND_REGION_2_CHANNEL_LIST) /
215 sizeof(u8);
216 pChannelList = A_BAND_REGION_2_CHANNEL_LIST;
217 break;
218 case REGION_3_A_BAND:
219 num =
220 sizeof(A_BAND_REGION_3_CHANNEL_LIST) /
221 sizeof(u8);
222 pChannelList = A_BAND_REGION_3_CHANNEL_LIST;
223 break;
224 case REGION_4_A_BAND:
225 num =
226 sizeof(A_BAND_REGION_4_CHANNEL_LIST) /
227 sizeof(u8);
228 pChannelList = A_BAND_REGION_4_CHANNEL_LIST;
229 break;
230 case REGION_5_A_BAND:
231 num =
232 sizeof(A_BAND_REGION_5_CHANNEL_LIST) /
233 sizeof(u8);
234 pChannelList = A_BAND_REGION_5_CHANNEL_LIST;
235 break;
236 case REGION_6_A_BAND:
237 num =
238 sizeof(A_BAND_REGION_6_CHANNEL_LIST) /
239 sizeof(u8);
240 pChannelList = A_BAND_REGION_6_CHANNEL_LIST;
241 break;
242 case REGION_7_A_BAND:
243 num =
244 sizeof(A_BAND_REGION_7_CHANNEL_LIST) /
245 sizeof(u8);
246 pChannelList = A_BAND_REGION_7_CHANNEL_LIST;
247 break;
248 case REGION_8_A_BAND:
249 num =
250 sizeof(A_BAND_REGION_8_CHANNEL_LIST) /
251 sizeof(u8);
252 pChannelList = A_BAND_REGION_8_CHANNEL_LIST;
253 break;
254 case REGION_9_A_BAND:
255 num =
256 sizeof(A_BAND_REGION_9_CHANNEL_LIST) /
257 sizeof(u8);
258 pChannelList = A_BAND_REGION_9_CHANNEL_LIST;
259 break;
260
261 case REGION_10_A_BAND:
262 num =
263 sizeof(A_BAND_REGION_10_CHANNEL_LIST) /
264 sizeof(u8);
265 pChannelList = A_BAND_REGION_10_CHANNEL_LIST;
266 break;
267
268 case REGION_11_A_BAND:
269 num =
270 sizeof(A_BAND_REGION_11_CHANNEL_LIST) /
271 sizeof(u8);
272 pChannelList = A_BAND_REGION_11_CHANNEL_LIST;
273 break;
274 case REGION_12_A_BAND:
275 num =
276 sizeof(A_BAND_REGION_12_CHANNEL_LIST) /
277 sizeof(u8);
278 pChannelList = A_BAND_REGION_12_CHANNEL_LIST;
279 break;
280 case REGION_13_A_BAND:
281 num =
282 sizeof(A_BAND_REGION_13_CHANNEL_LIST) /
283 sizeof(u8);
284 pChannelList = A_BAND_REGION_13_CHANNEL_LIST;
285 break;
286 case REGION_14_A_BAND:
287 num =
288 sizeof(A_BAND_REGION_14_CHANNEL_LIST) /
289 sizeof(u8);
290 pChannelList = A_BAND_REGION_14_CHANNEL_LIST;
291 break;
292 case REGION_15_A_BAND:
293 num =
294 sizeof(A_BAND_REGION_15_CHANNEL_LIST) /
295 sizeof(u8);
296 pChannelList = A_BAND_REGION_15_CHANNEL_LIST;
297 break;
298 default: /* Error. should never happen */
299 DBGPRINT(RT_DEBUG_WARN,
300 ("countryregion=%d not support",
301 pAd->CommonCfg.CountryRegionForABand));
302 break;
303 }
304
305 if (num != 0) {
306 u8 RadarCh[15] =
307 { 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124,
308 128, 132, 136, 140 };
309 for (i = 0; i < num; i++) {
310 for (j = 0; j < MAX_NUM_OF_CHANNELS; j++) {
311 if (pChannelList[i] ==
312 pAd->TxPower[j].Channel)
313 NdisMoveMemory(&pAd->
314 ChannelList[index
315 + i],
316 &pAd->TxPower[j],
317 sizeof
318 (struct rt_channel_tx_power));
319 }
320 for (j = 0; j < 15; j++) {
321 if (pChannelList[i] == RadarCh[j])
322 pAd->ChannelList[index +
323 i].DfsReq =
324 TRUE;
325 }
326 pAd->ChannelList[index + i].MaxTxPwr = 20;
327 }
328 index += num;
329 }
330 }
331
332 pAd->ChannelListNum = index;
333 DBGPRINT(RT_DEBUG_TRACE,
334 ("country code=%d/%d, RFIC=%d, PHY mode=%d, support %d channels\n",
335 pAd->CommonCfg.CountryRegion,
336 pAd->CommonCfg.CountryRegionForABand, pAd->RfIcType,
337 pAd->CommonCfg.PhyMode, pAd->ChannelListNum));
338#ifdef DBG
339 for (i = 0; i < pAd->ChannelListNum; i++) {
340 DBGPRINT_RAW(RT_DEBUG_TRACE,
341 ("BuildChannel # %d :: Pwr0 = %d, Pwr1 =%d, \n ",
342 pAd->ChannelList[i].Channel,
343 pAd->ChannelList[i].Power,
344 pAd->ChannelList[i].Power2));
345 }
346#endif
347}
348
349/*
350 ==========================================================================
351 Description:
352 This routine return the first channel number according to the country
353 code selection and RF IC selection (signal band or dual band). It is called
354 whenever driver need to start a site survey of all supported channels.
355 Return:
356 ch - the first channel number of current country code setting
357
358 IRQL = PASSIVE_LEVEL
359
360 ==========================================================================
361 */
362u8 FirstChannel(struct rt_rtmp_adapter *pAd)
363{
364 return pAd->ChannelList[0].Channel;
365}
366
367/*
368 ==========================================================================
369 Description:
370 This routine returns the next channel number. This routine is called
371 during driver need to start a site survey of all supported channels.
372 Return:
373 next_channel - the next channel number valid in current country code setting.
374 Note:
375 return 0 if no more next channel
376 ==========================================================================
377 */
378u8 NextChannel(struct rt_rtmp_adapter *pAd, u8 channel)
379{
380 int i;
381 u8 next_channel = 0;
382
383 for (i = 0; i < (pAd->ChannelListNum - 1); i++)
384 if (channel == pAd->ChannelList[i].Channel) {
385 next_channel = pAd->ChannelList[i + 1].Channel;
386 break;
387 }
388 return next_channel;
389}
390
391/*
392 ==========================================================================
393 Description:
394 This routine is for Cisco Compatible Extensions 2.X
395 Spec31. AP Control of Client Transmit Power
396 Return:
397 None
398 Note:
399 Required by Aironet dBm(mW)
400 0dBm(1mW), 1dBm(5mW), 13dBm(20mW), 15dBm(30mW),
401 17dBm(50mw), 20dBm(100mW)
402
403 We supported
404 3dBm(Lowest), 6dBm(10%), 9dBm(25%), 12dBm(50%),
405 14dBm(75%), 15dBm(100%)
406
407 The client station's actual transmit power shall be within +/- 5dB of
408 the minimum value or next lower value.
409 ==========================================================================
410 */
411void ChangeToCellPowerLimit(struct rt_rtmp_adapter *pAd,
412 u8 AironetCellPowerLimit)
413{
414 /*valud 0xFF means that hasn't found power limit information */
415 /*from the AP's Beacon/Probe response. */
416 if (AironetCellPowerLimit == 0xFF)
417 return;
418
419 if (AironetCellPowerLimit < 6) /*Used Lowest Power Percentage. */
420 pAd->CommonCfg.TxPowerPercentage = 6;
421 else if (AironetCellPowerLimit < 9)
422 pAd->CommonCfg.TxPowerPercentage = 10;
423 else if (AironetCellPowerLimit < 12)
424 pAd->CommonCfg.TxPowerPercentage = 25;
425 else if (AironetCellPowerLimit < 14)
426 pAd->CommonCfg.TxPowerPercentage = 50;
427 else if (AironetCellPowerLimit < 15)
428 pAd->CommonCfg.TxPowerPercentage = 75;
429 else
430 pAd->CommonCfg.TxPowerPercentage = 100; /*else used maximum */
431
432 if (pAd->CommonCfg.TxPowerPercentage > pAd->CommonCfg.TxPowerDefault)
433 pAd->CommonCfg.TxPowerPercentage =
434 pAd->CommonCfg.TxPowerDefault;
435
436}
437
438char ConvertToRssi(struct rt_rtmp_adapter *pAd, char Rssi, u8 RssiNumber)
439{
440 u8 RssiOffset, LNAGain;
441
442 /* Rssi equals to zero should be an invalid value */
443 if (Rssi == 0)
444 return -99;
445
446 LNAGain = GET_LNA_GAIN(pAd);
447 if (pAd->LatchRfRegs.Channel > 14) {
448 if (RssiNumber == 0)
449 RssiOffset = pAd->ARssiOffset0;
450 else if (RssiNumber == 1)
451 RssiOffset = pAd->ARssiOffset1;
452 else
453 RssiOffset = pAd->ARssiOffset2;
454 } else {
455 if (RssiNumber == 0)
456 RssiOffset = pAd->BGRssiOffset0;
457 else if (RssiNumber == 1)
458 RssiOffset = pAd->BGRssiOffset1;
459 else
460 RssiOffset = pAd->BGRssiOffset2;
461 }
462
463 return (-12 - RssiOffset - LNAGain - Rssi);
464}
465
466/*
467 ==========================================================================
468 Description:
469 Scan next channel
470 ==========================================================================
471 */
472void ScanNextChannel(struct rt_rtmp_adapter *pAd)
473{
474 struct rt_header_802_11 Hdr80211;
475 u8 *pOutBuffer = NULL;
476 int NStatus;
477 unsigned long FrameLen = 0;
478 u8 SsidLen = 0, ScanType = pAd->MlmeAux.ScanType, BBPValue = 0;
479 u16 Status;
480 struct rt_header_802_11 * pHdr80211;
481 u32 ScanTimeIn5gChannel = SHORT_CHANNEL_TIME;
482
483 {
484 if (MONITOR_ON(pAd))
485 return;
486 }
487
488 if (pAd->MlmeAux.Channel == 0) {
489 if ((pAd->CommonCfg.BBPCurrentBW == BW_40)
490 && (INFRA_ON(pAd)
491 || (pAd->OpMode == OPMODE_AP))
492 ) {
493 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel,
494 FALSE);
495 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
496 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
497 BBPValue &= (~0x18);
498 BBPValue |= 0x10;
499 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
500 DBGPRINT(RT_DEBUG_TRACE,
501 ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",
502 pAd->CommonCfg.CentralChannel,
503 pAd->ScanTab.BssNr));
504 } else {
505 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
506 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
507 DBGPRINT(RT_DEBUG_TRACE,
508 ("SYNC - End of SCAN, restore to channel %d, Total BSS[%02d]\n",
509 pAd->CommonCfg.Channel, pAd->ScanTab.BssNr));
510 }
511
512 {
513 /* */
514 /* To prevent data lost. */
515 /* Send an NULL data with turned PSM bit on to current associated AP before SCAN progress. */
516 /* Now, we need to send an NULL data with turned PSM bit off to AP, when scan progress done */
517 /* */
518 if (OPSTATUS_TEST_FLAG
519 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
520 && (INFRA_ON(pAd))) {
521 NStatus =
522 MlmeAllocateMemory(pAd,
523 (void *)& pOutBuffer);
524 if (NStatus == NDIS_STATUS_SUCCESS) {
525 pHdr80211 = (struct rt_header_802_11 *) pOutBuffer;
526 MgtMacHeaderInit(pAd, pHdr80211,
527 SUBTYPE_NULL_FUNC, 1,
528 pAd->CommonCfg.Bssid,
529 pAd->CommonCfg.Bssid);
530 pHdr80211->Duration = 0;
531 pHdr80211->FC.Type = BTYPE_DATA;
532 pHdr80211->FC.PwrMgmt =
533 (pAd->StaCfg.Psm == PWR_SAVE);
534
535 /* Send using priority queue */
536 MiniportMMRequest(pAd, 0, pOutBuffer,
537 sizeof
538 (struct rt_header_802_11));
539 DBGPRINT(RT_DEBUG_TRACE,
540 ("MlmeScanReqAction -- Send PSM Data frame\n"));
541 MlmeFreeMemory(pAd, pOutBuffer);
542 RTMPusecDelay(5000);
543 }
544 }
545
546 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
547 Status = MLME_SUCCESS;
548 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF,
549 2, &Status);
550 }
551
552 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
553 }
554#ifdef RTMP_MAC_USB
555 else if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)
556 && (pAd->OpMode == OPMODE_STA)) {
557 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
558 MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_FAIL_NO_RESOURCE);
559 }
560#endif /* RTMP_MAC_USB // */
561 else {
562 {
563 /* BBP and RF are not accessible in PS mode, we has to wake them up first */
564 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
565 AsicForceWakeup(pAd, TRUE);
566
567 /* leave PSM during scanning. otherwise we may lost ProbeRsp & BEACON */
568 if (pAd->StaCfg.Psm == PWR_SAVE)
569 RTMP_SET_PSM_BIT(pAd, PWR_ACTIVE);
570 }
571
572 AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, TRUE);
573 AsicLockChannel(pAd, pAd->MlmeAux.Channel);
574
575 {
576 if (pAd->MlmeAux.Channel > 14) {
577 if ((pAd->CommonCfg.bIEEE80211H == 1)
578 && RadarChannelCheck(pAd,
579 pAd->MlmeAux.
580 Channel)) {
581 ScanType = SCAN_PASSIVE;
582 ScanTimeIn5gChannel = MIN_CHANNEL_TIME;
583 }
584 }
585 }
586
587 /*Global country domain(ch1-11:active scan, ch12-14 passive scan) */
588 if ((pAd->MlmeAux.Channel <= 14) && (pAd->MlmeAux.Channel >= 12)
589 && ((pAd->CommonCfg.CountryRegion & 0x7f) ==
590 REGION_31_BG_BAND)) {
591 ScanType = SCAN_PASSIVE;
592 }
593 /* We need to shorten active scan time in order for WZC connect issue */
594 /* Chnage the channel scan time for CISCO stuff based on its IAPP announcement */
595 if (ScanType == FAST_SCAN_ACTIVE)
596 RTMPSetTimer(&pAd->MlmeAux.ScanTimer,
597 FAST_ACTIVE_SCAN_TIME);
598 else /* must be SCAN_PASSIVE or SCAN_ACTIVE */
599 {
600 if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED)
601 || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED)
602 || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED)
603 ) {
604 if (pAd->MlmeAux.Channel > 14)
605 RTMPSetTimer(&pAd->MlmeAux.ScanTimer,
606 ScanTimeIn5gChannel);
607 else
608 RTMPSetTimer(&pAd->MlmeAux.ScanTimer,
609 MIN_CHANNEL_TIME);
610 } else
611 RTMPSetTimer(&pAd->MlmeAux.ScanTimer,
612 MAX_CHANNEL_TIME);
613 }
614
615 if ((ScanType == SCAN_ACTIVE)
616 || (ScanType == FAST_SCAN_ACTIVE)
617 ) {
618 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
619 if (NStatus != NDIS_STATUS_SUCCESS) {
620 DBGPRINT(RT_DEBUG_TRACE,
621 ("SYNC - ScanNextChannel() allocate memory fail\n"));
622
623 {
624 pAd->Mlme.SyncMachine.CurrState =
625 SYNC_IDLE;
626 Status = MLME_FAIL_NO_RESOURCE;
627 MlmeEnqueue(pAd,
628 MLME_CNTL_STATE_MACHINE,
629 MT2_SCAN_CONF, 2, &Status);
630 }
631
632 return;
633 }
634 /* There is no need to send broadcast probe request if active scan is in effect. */
635 if ((ScanType == SCAN_ACTIVE)
636 || (ScanType == FAST_SCAN_ACTIVE)
637 )
638 SsidLen = pAd->MlmeAux.SsidLen;
639 else
640 SsidLen = 0;
641
642 MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0,
643 BROADCAST_ADDR, BROADCAST_ADDR);
644 MakeOutgoingFrame(pOutBuffer, &FrameLen,
645 sizeof(struct rt_header_802_11), &Hdr80211, 1,
646 &SsidIe, 1, &SsidLen, SsidLen,
647 pAd->MlmeAux.Ssid, 1, &SupRateIe, 1,
648 &pAd->CommonCfg.SupRateLen,
649 pAd->CommonCfg.SupRateLen,
650 pAd->CommonCfg.SupRate, END_OF_ARGS);
651
652 if (pAd->CommonCfg.ExtRateLen) {
653 unsigned long Tmp;
654 MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
655 1, &ExtRateIe,
656 1, &pAd->CommonCfg.ExtRateLen,
657 pAd->CommonCfg.ExtRateLen,
658 pAd->CommonCfg.ExtRate,
659 END_OF_ARGS);
660 FrameLen += Tmp;
661 }
662
663 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) {
664 unsigned long Tmp;
665 u8 HtLen;
666 u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 };
667
668 if (pAd->bBroadComHT == TRUE) {
669 HtLen =
670 pAd->MlmeAux.HtCapabilityLen + 4;
671
672 MakeOutgoingFrame(pOutBuffer + FrameLen,
673 &Tmp, 1, &WpaIe, 1,
674 &HtLen, 4,
675 &BROADCOM[0],
676 pAd->MlmeAux.
677 HtCapabilityLen,
678 &pAd->MlmeAux.
679 HtCapability,
680 END_OF_ARGS);
681 } else {
682 HtLen = pAd->MlmeAux.HtCapabilityLen;
683
684 MakeOutgoingFrame(pOutBuffer + FrameLen,
685 &Tmp, 1, &HtCapIe, 1,
686 &HtLen, HtLen,
687 &pAd->CommonCfg.
688 HtCapability,
689 END_OF_ARGS);
690 }
691 FrameLen += Tmp;
692 }
693
694 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
695 MlmeFreeMemory(pAd, pOutBuffer);
696 }
697 /* For SCAN_CISCO_PASSIVE, do nothing and silently wait for beacon or other probe response */
698
699 pAd->Mlme.SyncMachine.CurrState = SCAN_LISTEN;
700 }
701}
702
703void MgtProbReqMacHeaderInit(struct rt_rtmp_adapter *pAd,
704 struct rt_header_802_11 * pHdr80211,
705 u8 SubType,
706 u8 ToDs, u8 *pDA, u8 *pBssid)
707{
708 NdisZeroMemory(pHdr80211, sizeof(struct rt_header_802_11));
709
710 pHdr80211->FC.Type = BTYPE_MGMT;
711 pHdr80211->FC.SubType = SubType;
712 if (SubType == SUBTYPE_ACK)
713 pHdr80211->FC.Type = BTYPE_CNTL;
714 pHdr80211->FC.ToDs = ToDs;
715 COPY_MAC_ADDR(pHdr80211->Addr1, pDA);
716 COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);
717 COPY_MAC_ADDR(pHdr80211->Addr3, pBssid);
718}
diff --git a/drivers/staging/rt2860/common/cmm_tkip.c b/drivers/staging/rt2860/common/cmm_tkip.c
deleted file mode 100644
index 4881ef9ba02..00000000000
--- a/drivers/staging/rt2860/common/cmm_tkip.c
+++ /dev/null
@@ -1,833 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 cmm_tkip.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Paul Wu 02-25-02 Initial
36*/
37
38#include "../rt_config.h"
39
40/* Rotation functions on 32 bit values */
41#define ROL32( A, n ) \
42 ( ((A) << (n)) | ( ((A)>>(32-(n))) & ( (1UL << (n)) - 1 ) ) )
43#define ROR32( A, n ) ROL32( (A), 32-(n) )
44
45u32 Tkip_Sbox_Lower[256] = {
46 0xA5, 0x84, 0x99, 0x8D, 0x0D, 0xBD, 0xB1, 0x54,
47 0x50, 0x03, 0xA9, 0x7D, 0x19, 0x62, 0xE6, 0x9A,
48 0x45, 0x9D, 0x40, 0x87, 0x15, 0xEB, 0xC9, 0x0B,
49 0xEC, 0x67, 0xFD, 0xEA, 0xBF, 0xF7, 0x96, 0x5B,
50 0xC2, 0x1C, 0xAE, 0x6A, 0x5A, 0x41, 0x02, 0x4F,
51 0x5C, 0xF4, 0x34, 0x08, 0x93, 0x73, 0x53, 0x3F,
52 0x0C, 0x52, 0x65, 0x5E, 0x28, 0xA1, 0x0F, 0xB5,
53 0x09, 0x36, 0x9B, 0x3D, 0x26, 0x69, 0xCD, 0x9F,
54 0x1B, 0x9E, 0x74, 0x2E, 0x2D, 0xB2, 0xEE, 0xFB,
55 0xF6, 0x4D, 0x61, 0xCE, 0x7B, 0x3E, 0x71, 0x97,
56 0xF5, 0x68, 0x00, 0x2C, 0x60, 0x1F, 0xC8, 0xED,
57 0xBE, 0x46, 0xD9, 0x4B, 0xDE, 0xD4, 0xE8, 0x4A,
58 0x6B, 0x2A, 0xE5, 0x16, 0xC5, 0xD7, 0x55, 0x94,
59 0xCF, 0x10, 0x06, 0x81, 0xF0, 0x44, 0xBA, 0xE3,
60 0xF3, 0xFE, 0xC0, 0x8A, 0xAD, 0xBC, 0x48, 0x04,
61 0xDF, 0xC1, 0x75, 0x63, 0x30, 0x1A, 0x0E, 0x6D,
62 0x4C, 0x14, 0x35, 0x2F, 0xE1, 0xA2, 0xCC, 0x39,
63 0x57, 0xF2, 0x82, 0x47, 0xAC, 0xE7, 0x2B, 0x95,
64 0xA0, 0x98, 0xD1, 0x7F, 0x66, 0x7E, 0xAB, 0x83,
65 0xCA, 0x29, 0xD3, 0x3C, 0x79, 0xE2, 0x1D, 0x76,
66 0x3B, 0x56, 0x4E, 0x1E, 0xDB, 0x0A, 0x6C, 0xE4,
67 0x5D, 0x6E, 0xEF, 0xA6, 0xA8, 0xA4, 0x37, 0x8B,
68 0x32, 0x43, 0x59, 0xB7, 0x8C, 0x64, 0xD2, 0xE0,
69 0xB4, 0xFA, 0x07, 0x25, 0xAF, 0x8E, 0xE9, 0x18,
70 0xD5, 0x88, 0x6F, 0x72, 0x24, 0xF1, 0xC7, 0x51,
71 0x23, 0x7C, 0x9C, 0x21, 0xDD, 0xDC, 0x86, 0x85,
72 0x90, 0x42, 0xC4, 0xAA, 0xD8, 0x05, 0x01, 0x12,
73 0xA3, 0x5F, 0xF9, 0xD0, 0x91, 0x58, 0x27, 0xB9,
74 0x38, 0x13, 0xB3, 0x33, 0xBB, 0x70, 0x89, 0xA7,
75 0xB6, 0x22, 0x92, 0x20, 0x49, 0xFF, 0x78, 0x7A,
76 0x8F, 0xF8, 0x80, 0x17, 0xDA, 0x31, 0xC6, 0xB8,
77 0xC3, 0xB0, 0x77, 0x11, 0xCB, 0xFC, 0xD6, 0x3A
78};
79
80u32 Tkip_Sbox_Upper[256] = {
81 0xC6, 0xF8, 0xEE, 0xF6, 0xFF, 0xD6, 0xDE, 0x91,
82 0x60, 0x02, 0xCE, 0x56, 0xE7, 0xB5, 0x4D, 0xEC,
83 0x8F, 0x1F, 0x89, 0xFA, 0xEF, 0xB2, 0x8E, 0xFB,
84 0x41, 0xB3, 0x5F, 0x45, 0x23, 0x53, 0xE4, 0x9B,
85 0x75, 0xE1, 0x3D, 0x4C, 0x6C, 0x7E, 0xF5, 0x83,
86 0x68, 0x51, 0xD1, 0xF9, 0xE2, 0xAB, 0x62, 0x2A,
87 0x08, 0x95, 0x46, 0x9D, 0x30, 0x37, 0x0A, 0x2F,
88 0x0E, 0x24, 0x1B, 0xDF, 0xCD, 0x4E, 0x7F, 0xEA,
89 0x12, 0x1D, 0x58, 0x34, 0x36, 0xDC, 0xB4, 0x5B,
90 0xA4, 0x76, 0xB7, 0x7D, 0x52, 0xDD, 0x5E, 0x13,
91 0xA6, 0xB9, 0x00, 0xC1, 0x40, 0xE3, 0x79, 0xB6,
92 0xD4, 0x8D, 0x67, 0x72, 0x94, 0x98, 0xB0, 0x85,
93 0xBB, 0xC5, 0x4F, 0xED, 0x86, 0x9A, 0x66, 0x11,
94 0x8A, 0xE9, 0x04, 0xFE, 0xA0, 0x78, 0x25, 0x4B,
95 0xA2, 0x5D, 0x80, 0x05, 0x3F, 0x21, 0x70, 0xF1,
96 0x63, 0x77, 0xAF, 0x42, 0x20, 0xE5, 0xFD, 0xBF,
97 0x81, 0x18, 0x26, 0xC3, 0xBE, 0x35, 0x88, 0x2E,
98 0x93, 0x55, 0xFC, 0x7A, 0xC8, 0xBA, 0x32, 0xE6,
99 0xC0, 0x19, 0x9E, 0xA3, 0x44, 0x54, 0x3B, 0x0B,
100 0x8C, 0xC7, 0x6B, 0x28, 0xA7, 0xBC, 0x16, 0xAD,
101 0xDB, 0x64, 0x74, 0x14, 0x92, 0x0C, 0x48, 0xB8,
102 0x9F, 0xBD, 0x43, 0xC4, 0x39, 0x31, 0xD3, 0xF2,
103 0xD5, 0x8B, 0x6E, 0xDA, 0x01, 0xB1, 0x9C, 0x49,
104 0xD8, 0xAC, 0xF3, 0xCF, 0xCA, 0xF4, 0x47, 0x10,
105 0x6F, 0xF0, 0x4A, 0x5C, 0x38, 0x57, 0x73, 0x97,
106 0xCB, 0xA1, 0xE8, 0x3E, 0x96, 0x61, 0x0D, 0x0F,
107 0xE0, 0x7C, 0x71, 0xCC, 0x90, 0x06, 0xF7, 0x1C,
108 0xC2, 0x6A, 0xAE, 0x69, 0x17, 0x99, 0x3A, 0x27,
109 0xD9, 0xEB, 0x2B, 0x22, 0xD2, 0xA9, 0x07, 0x33,
110 0x2D, 0x3C, 0x15, 0xC9, 0x87, 0xAA, 0x50, 0xA5,
111 0x03, 0x59, 0x09, 0x1A, 0x65, 0xD7, 0x84, 0xD0,
112 0x82, 0x29, 0x5A, 0x1E, 0x7B, 0xA8, 0x6D, 0x2C
113};
114
115/* */
116/* Expanded IV for TKIP function. */
117/* */
118struct PACKED rt_tkip_iv {
119 union PACKED {
120 struct PACKED {
121 u8 rc0;
122 u8 rc1;
123 u8 rc2;
124
125 union PACKED {
126 struct PACKED {
127 u8 Rsvd:5;
128 u8 ExtIV:1;
129 u8 KeyID:2;
130 } field;
131 u8 Byte;
132 } CONTROL;
133 } field;
134
135 unsigned long word;
136 } IV16;
137
138 unsigned long IV32;
139};
140
141/*
142 ========================================================================
143
144 Routine Description:
145 Convert from u8[] to unsigned long in a portable way
146
147 Arguments:
148 pMICKey pointer to MIC Key
149
150 Return Value:
151 None
152
153 Note:
154
155 ========================================================================
156*/
157unsigned long RTMPTkipGetUInt32(u8 *pMICKey)
158{
159 unsigned long res = 0;
160 int i;
161
162 for (i = 0; i < 4; i++) {
163 res |= (*pMICKey++) << (8 * i);
164 }
165
166 return res;
167}
168
169/*
170 ========================================================================
171
172 Routine Description:
173 Convert from unsigned long to u8[] in a portable way
174
175 Arguments:
176 pDst pointer to destination for convert unsigned long to u8[]
177 val the value for convert
178
179 Return Value:
180 None
181
182 IRQL = DISPATCH_LEVEL
183
184 Note:
185
186 ========================================================================
187*/
188void RTMPTkipPutUInt32(IN u8 *pDst, unsigned long val)
189{
190 int i;
191
192 for (i = 0; i < 4; i++) {
193 *pDst++ = (u8)(val & 0xff);
194 val >>= 8;
195 }
196}
197
198/*
199 ========================================================================
200
201 Routine Description:
202 Set the MIC Key.
203
204 Arguments:
205 pAd Pointer to our adapter
206 pMICKey pointer to MIC Key
207
208 Return Value:
209 None
210
211 IRQL = DISPATCH_LEVEL
212
213 Note:
214
215 ========================================================================
216*/
217void RTMPTkipSetMICKey(struct rt_tkip_key_info *pTkip, u8 *pMICKey)
218{
219 /* Set the key */
220 pTkip->K0 = RTMPTkipGetUInt32(pMICKey);
221 pTkip->K1 = RTMPTkipGetUInt32(pMICKey + 4);
222 /* and reset the message */
223 pTkip->L = pTkip->K0;
224 pTkip->R = pTkip->K1;
225 pTkip->nBytesInM = 0;
226 pTkip->M = 0;
227}
228
229/*
230 ========================================================================
231
232 Routine Description:
233 Calculate the MIC Value.
234
235 Arguments:
236 pAd Pointer to our adapter
237 uChar Append this uChar
238
239 Return Value:
240 None
241
242 IRQL = DISPATCH_LEVEL
243
244 Note:
245
246 ========================================================================
247*/
248void RTMPTkipAppendByte(struct rt_tkip_key_info *pTkip, u8 uChar)
249{
250 /* Append the byte to our word-sized buffer */
251 pTkip->M |= (uChar << (8 * pTkip->nBytesInM));
252 pTkip->nBytesInM++;
253 /* Process the word if it is full. */
254 if (pTkip->nBytesInM >= 4) {
255 pTkip->L ^= pTkip->M;
256 pTkip->R ^= ROL32(pTkip->L, 17);
257 pTkip->L += pTkip->R;
258 pTkip->R ^=
259 ((pTkip->L & 0xff00ff00) >> 8) | ((pTkip->
260 L & 0x00ff00ff) << 8);
261 pTkip->L += pTkip->R;
262 pTkip->R ^= ROL32(pTkip->L, 3);
263 pTkip->L += pTkip->R;
264 pTkip->R ^= ROR32(pTkip->L, 2);
265 pTkip->L += pTkip->R;
266 /* Clear the buffer */
267 pTkip->M = 0;
268 pTkip->nBytesInM = 0;
269 }
270}
271
272/*
273 ========================================================================
274
275 Routine Description:
276 Calculate the MIC Value.
277
278 Arguments:
279 pAd Pointer to our adapter
280 pSrc Pointer to source data for Calculate MIC Value
281 Len Indicate the length of the source data
282
283 Return Value:
284 None
285
286 IRQL = DISPATCH_LEVEL
287
288 Note:
289
290 ========================================================================
291*/
292void RTMPTkipAppend(struct rt_tkip_key_info *pTkip, u8 *pSrc, u32 nBytes)
293{
294 /* This is simple */
295 while (nBytes > 0) {
296 RTMPTkipAppendByte(pTkip, *pSrc++);
297 nBytes--;
298 }
299}
300
301/*
302 ========================================================================
303
304 Routine Description:
305 Get the MIC Value.
306
307 Arguments:
308 pAd Pointer to our adapter
309
310 Return Value:
311 None
312
313 IRQL = DISPATCH_LEVEL
314
315 Note:
316 the MIC Value is store in pAd->PrivateInfo.MIC
317 ========================================================================
318*/
319void RTMPTkipGetMIC(struct rt_tkip_key_info *pTkip)
320{
321 /* Append the minimum padding */
322 RTMPTkipAppendByte(pTkip, 0x5a);
323 RTMPTkipAppendByte(pTkip, 0);
324 RTMPTkipAppendByte(pTkip, 0);
325 RTMPTkipAppendByte(pTkip, 0);
326 RTMPTkipAppendByte(pTkip, 0);
327 /* and then zeroes until the length is a multiple of 4 */
328 while (pTkip->nBytesInM != 0) {
329 RTMPTkipAppendByte(pTkip, 0);
330 }
331 /* The appendByte function has already computed the result. */
332 RTMPTkipPutUInt32(pTkip->MIC, pTkip->L);
333 RTMPTkipPutUInt32(pTkip->MIC + 4, pTkip->R);
334}
335
336/*
337 ========================================================================
338
339 Routine Description:
340 Init Tkip function.
341
342 Arguments:
343 pAd Pointer to our adapter
344 pTKey Pointer to the Temporal Key (TK), TK shall be 128bits.
345 KeyId TK Key ID
346 pTA Pointer to transmitter address
347 pMICKey pointer to MIC Key
348
349 Return Value:
350 None
351
352 IRQL = DISPATCH_LEVEL
353
354 Note:
355
356 ========================================================================
357*/
358void RTMPInitTkipEngine(struct rt_rtmp_adapter *pAd,
359 u8 *pKey,
360 u8 KeyId,
361 u8 *pTA,
362 u8 *pMICKey,
363 u8 *pTSC, unsigned long *pIV16, unsigned long *pIV32)
364{
365 struct rt_tkip_iv tkipIv;
366
367 /* Prepare 8 bytes TKIP encapsulation for MPDU */
368 NdisZeroMemory(&tkipIv, sizeof(struct rt_tkip_iv));
369 tkipIv.IV16.field.rc0 = *(pTSC + 1);
370 tkipIv.IV16.field.rc1 = (tkipIv.IV16.field.rc0 | 0x20) & 0x7f;
371 tkipIv.IV16.field.rc2 = *pTSC;
372 tkipIv.IV16.field.CONTROL.field.ExtIV = 1; /* 0: non-extended IV, 1: an extended IV */
373 tkipIv.IV16.field.CONTROL.field.KeyID = KeyId;
374/* tkipIv.IV32 = *(unsigned long *)(pTSC + 2); */
375 NdisMoveMemory(&tkipIv.IV32, (pTSC + 2), 4); /* Copy IV */
376
377 *pIV16 = tkipIv.IV16.word;
378 *pIV32 = tkipIv.IV32;
379}
380
381/*
382 ========================================================================
383
384 Routine Description:
385 Init MIC Value calculation function which include set MIC key &
386 calculate first 16 bytes (DA + SA + priority + 0)
387
388 Arguments:
389 pAd Pointer to our adapter
390 pTKey Pointer to the Temporal Key (TK), TK shall be 128bits.
391 pDA Pointer to DA address
392 pSA Pointer to SA address
393 pMICKey pointer to MIC Key
394
395 Return Value:
396 None
397
398 Note:
399
400 ========================================================================
401*/
402void RTMPInitMICEngine(struct rt_rtmp_adapter *pAd,
403 u8 *pKey,
404 u8 *pDA,
405 u8 *pSA, u8 UserPriority, u8 *pMICKey)
406{
407 unsigned long Priority = UserPriority;
408
409 /* Init MIC value calculation */
410 RTMPTkipSetMICKey(&pAd->PrivateInfo.Tx, pMICKey);
411 /* DA */
412 RTMPTkipAppend(&pAd->PrivateInfo.Tx, pDA, MAC_ADDR_LEN);
413 /* SA */
414 RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSA, MAC_ADDR_LEN);
415 /* Priority + 3 bytes of 0 */
416 RTMPTkipAppend(&pAd->PrivateInfo.Tx, (u8 *)& Priority, 4);
417}
418
419/*
420 ========================================================================
421
422 Routine Description:
423 Compare MIC value of received MSDU
424
425 Arguments:
426 pAd Pointer to our adapter
427 pSrc Pointer to the received Plain text data
428 pDA Pointer to DA address
429 pSA Pointer to SA address
430 pMICKey pointer to MIC Key
431 Len the length of the received plain text data exclude MIC value
432
433 Return Value:
434 TRUE MIC value matched
435 FALSE MIC value mismatched
436
437 IRQL = DISPATCH_LEVEL
438
439 Note:
440
441 ========================================================================
442*/
443BOOLEAN RTMPTkipCompareMICValue(struct rt_rtmp_adapter *pAd,
444 u8 *pSrc,
445 u8 *pDA,
446 u8 *pSA,
447 u8 *pMICKey,
448 u8 UserPriority, u32 Len)
449{
450 u8 OldMic[8];
451 unsigned long Priority = UserPriority;
452
453 /* Init MIC value calculation */
454 RTMPTkipSetMICKey(&pAd->PrivateInfo.Rx, pMICKey);
455 /* DA */
456 RTMPTkipAppend(&pAd->PrivateInfo.Rx, pDA, MAC_ADDR_LEN);
457 /* SA */
458 RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSA, MAC_ADDR_LEN);
459 /* Priority + 3 bytes of 0 */
460 RTMPTkipAppend(&pAd->PrivateInfo.Rx, (u8 *)& Priority, 4);
461
462 /* Calculate MIC value from plain text data */
463 RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSrc, Len);
464
465 /* Get MIC valude from received frame */
466 NdisMoveMemory(OldMic, pSrc + Len, 8);
467
468 /* Get MIC value from decrypted plain data */
469 RTMPTkipGetMIC(&pAd->PrivateInfo.Rx);
470
471 /* Move MIC value from MSDU, this steps should move to data path. */
472 /* Since the MIC value might cross MPDUs. */
473 if (!NdisEqualMemory(pAd->PrivateInfo.Rx.MIC, OldMic, 8)) {
474 DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTMPTkipCompareMICValue(): TKIP MIC Error !\n")); /*MIC error. */
475
476 return (FALSE);
477 }
478 return (TRUE);
479}
480
481/*
482 ========================================================================
483
484 Routine Description:
485 Copy frame from waiting queue into relative ring buffer and set
486 appropriate ASIC register to kick hardware transmit function
487
488 Arguments:
489 pAd Pointer to our adapter
490 void * Pointer to Ndis Packet for MIC calculation
491 pEncap Pointer to LLC encap data
492 LenEncap Total encap length, might be 0 which indicates no encap
493
494 Return Value:
495 None
496
497 IRQL = DISPATCH_LEVEL
498
499 Note:
500
501 ========================================================================
502*/
503void RTMPCalculateMICValue(struct rt_rtmp_adapter *pAd,
504 void *pPacket,
505 u8 *pEncap,
506 struct rt_cipher_key *pKey, u8 apidx)
507{
508 struct rt_packet_info PacketInfo;
509 u8 *pSrcBufVA;
510 u32 SrcBufLen;
511 u8 *pSrc;
512 u8 UserPriority;
513 u8 vlan_offset = 0;
514
515 RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
516
517 UserPriority = RTMP_GET_PACKET_UP(pPacket);
518 pSrc = pSrcBufVA;
519
520 /* determine if this is a vlan packet */
521 if (((*(pSrc + 12) << 8) + *(pSrc + 13)) == 0x8100)
522 vlan_offset = 4;
523
524 {
525 RTMPInitMICEngine(pAd,
526 pKey->Key,
527 pSrc, pSrc + 6, UserPriority, pKey->TxMic);
528 }
529
530 if (pEncap != NULL) {
531 /* LLC encapsulation */
532 RTMPTkipAppend(&pAd->PrivateInfo.Tx, pEncap, 6);
533 /* Protocol Type */
534 RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc + 12 + vlan_offset,
535 2);
536 }
537 SrcBufLen -= (14 + vlan_offset);
538 pSrc += (14 + vlan_offset);
539 do {
540 if (SrcBufLen > 0) {
541 RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc, SrcBufLen);
542 }
543
544 break; /* No need handle next packet */
545
546 } while (TRUE); /* End of copying payload */
547
548 /* Compute the final MIC Value */
549 RTMPTkipGetMIC(&pAd->PrivateInfo.Tx);
550}
551
552/************************************************************/
553/* tkip_sbox() */
554/* Returns a 16 bit value from a 64K entry table. The Table */
555/* is synthesized from two 256 entry byte wide tables. */
556/************************************************************/
557
558u32 tkip_sbox(u32 index)
559{
560 u32 index_low;
561 u32 index_high;
562 u32 left, right;
563
564 index_low = (index % 256);
565 index_high = ((index >> 8) % 256);
566
567 left = Tkip_Sbox_Lower[index_low] + (Tkip_Sbox_Upper[index_low] * 256);
568 right =
569 Tkip_Sbox_Upper[index_high] + (Tkip_Sbox_Lower[index_high] * 256);
570
571 return (left ^ right);
572}
573
574u32 rotr1(u32 a)
575{
576 unsigned int b;
577
578 if ((a & 0x01) == 0x01) {
579 b = (a >> 1) | 0x8000;
580 } else {
581 b = (a >> 1) & 0x7fff;
582 }
583 b = b % 65536;
584 return b;
585}
586
587void RTMPTkipMixKey(u8 * key, u8 * ta, unsigned long pnl, /* Least significant 16 bits of PN */
588 unsigned long pnh, /* Most significant 32 bits of PN */
589 u8 * rc4key, u32 * p1k)
590{
591
592 u32 tsc0;
593 u32 tsc1;
594 u32 tsc2;
595
596 u32 ppk0;
597 u32 ppk1;
598 u32 ppk2;
599 u32 ppk3;
600 u32 ppk4;
601 u32 ppk5;
602
603 int i;
604 int j;
605
606 tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
607 tsc1 = (unsigned int)(pnh % 65536);
608 tsc2 = (unsigned int)(pnl % 65536); /* lsb */
609
610 /* Phase 1, step 1 */
611 p1k[0] = tsc1;
612 p1k[1] = tsc0;
613 p1k[2] = (u32)(ta[0] + (ta[1] * 256));
614 p1k[3] = (u32)(ta[2] + (ta[3] * 256));
615 p1k[4] = (u32)(ta[4] + (ta[5] * 256));
616
617 /* Phase 1, step 2 */
618 for (i = 0; i < 8; i++) {
619 j = 2 * (i & 1);
620 p1k[0] =
621 (p1k[0] +
622 tkip_sbox((p1k[4] ^ ((256 * key[1 + j]) + key[j])) %
623 65536)) % 65536;
624 p1k[1] =
625 (p1k[1] +
626 tkip_sbox((p1k[0] ^ ((256 * key[5 + j]) + key[4 + j])) %
627 65536)) % 65536;
628 p1k[2] =
629 (p1k[2] +
630 tkip_sbox((p1k[1] ^ ((256 * key[9 + j]) + key[8 + j])) %
631 65536)) % 65536;
632 p1k[3] =
633 (p1k[3] +
634 tkip_sbox((p1k[2] ^ ((256 * key[13 + j]) + key[12 + j])) %
635 65536)) % 65536;
636 p1k[4] =
637 (p1k[4] +
638 tkip_sbox((p1k[3] ^ (((256 * key[1 + j]) + key[j]))) %
639 65536)) % 65536;
640 p1k[4] = (p1k[4] + i) % 65536;
641 }
642
643 /* Phase 2, Step 1 */
644 ppk0 = p1k[0];
645 ppk1 = p1k[1];
646 ppk2 = p1k[2];
647 ppk3 = p1k[3];
648 ppk4 = p1k[4];
649 ppk5 = (p1k[4] + tsc2) % 65536;
650
651 /* Phase2, Step 2 */
652 ppk0 = ppk0 + tkip_sbox((ppk5 ^ ((256 * key[1]) + key[0])) % 65536);
653 ppk1 = ppk1 + tkip_sbox((ppk0 ^ ((256 * key[3]) + key[2])) % 65536);
654 ppk2 = ppk2 + tkip_sbox((ppk1 ^ ((256 * key[5]) + key[4])) % 65536);
655 ppk3 = ppk3 + tkip_sbox((ppk2 ^ ((256 * key[7]) + key[6])) % 65536);
656 ppk4 = ppk4 + tkip_sbox((ppk3 ^ ((256 * key[9]) + key[8])) % 65536);
657 ppk5 = ppk5 + tkip_sbox((ppk4 ^ ((256 * key[11]) + key[10])) % 65536);
658
659 ppk0 = ppk0 + rotr1(ppk5 ^ ((256 * key[13]) + key[12]));
660 ppk1 = ppk1 + rotr1(ppk0 ^ ((256 * key[15]) + key[14]));
661 ppk2 = ppk2 + rotr1(ppk1);
662 ppk3 = ppk3 + rotr1(ppk2);
663 ppk4 = ppk4 + rotr1(ppk3);
664 ppk5 = ppk5 + rotr1(ppk4);
665
666 /* Phase 2, Step 3 */
667 /* Phase 2, Step 3 */
668
669 tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
670 tsc1 = (unsigned int)(pnh % 65536);
671 tsc2 = (unsigned int)(pnl % 65536); /* lsb */
672
673 rc4key[0] = (tsc2 >> 8) % 256;
674 rc4key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f;
675 rc4key[2] = tsc2 % 256;
676 rc4key[3] = ((ppk5 ^ ((256 * key[1]) + key[0])) >> 1) % 256;
677
678 rc4key[4] = ppk0 % 256;
679 rc4key[5] = (ppk0 >> 8) % 256;
680
681 rc4key[6] = ppk1 % 256;
682 rc4key[7] = (ppk1 >> 8) % 256;
683
684 rc4key[8] = ppk2 % 256;
685 rc4key[9] = (ppk2 >> 8) % 256;
686
687 rc4key[10] = ppk3 % 256;
688 rc4key[11] = (ppk3 >> 8) % 256;
689
690 rc4key[12] = ppk4 % 256;
691 rc4key[13] = (ppk4 >> 8) % 256;
692
693 rc4key[14] = ppk5 % 256;
694 rc4key[15] = (ppk5 >> 8) % 256;
695}
696
697/* */
698/* TRUE: Success! */
699/* FALSE: Decrypt Error! */
700/* */
701BOOLEAN RTMPSoftDecryptTKIP(struct rt_rtmp_adapter *pAd,
702 u8 *pData,
703 unsigned long DataByteCnt,
704 u8 UserPriority, struct rt_cipher_key *pWpaKey)
705{
706 u8 KeyID;
707 u32 HeaderLen;
708 u8 fc0;
709 u8 fc1;
710 u16 fc;
711 u32 frame_type;
712 u32 frame_subtype;
713 u32 from_ds;
714 u32 to_ds;
715 int a4_exists;
716 int qc_exists;
717 u16 duration;
718 u16 seq_control;
719 u16 qos_control;
720 u8 TA[MAC_ADDR_LEN];
721 u8 DA[MAC_ADDR_LEN];
722 u8 SA[MAC_ADDR_LEN];
723 u8 RC4Key[16];
724 u32 p1k[5]; /*for mix_key; */
725 unsigned long pnl; /* Least significant 16 bits of PN */
726 unsigned long pnh; /* Most significant 32 bits of PN */
727 u32 num_blocks;
728 u32 payload_remainder;
729 struct rt_arcfourcontext ArcFourContext;
730 u32 crc32 = 0;
731 u32 trailfcs = 0;
732 u8 MIC[8];
733 u8 TrailMIC[8];
734
735 fc0 = *pData;
736 fc1 = *(pData + 1);
737
738 fc = *((u16 *)pData);
739
740 frame_type = ((fc0 >> 2) & 0x03);
741 frame_subtype = ((fc0 >> 4) & 0x0f);
742
743 from_ds = (fc1 & 0x2) >> 1;
744 to_ds = (fc1 & 0x1);
745
746 a4_exists = (from_ds & to_ds);
747 qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */
748 (frame_subtype == 0x09) || /* Likely to change. */
749 (frame_subtype == 0x0a) || (frame_subtype == 0x0b)
750 );
751
752 HeaderLen = 24;
753 if (a4_exists)
754 HeaderLen += 6;
755
756 KeyID = *((u8 *)(pData + HeaderLen + 3));
757 KeyID = KeyID >> 6;
758
759 if (pWpaKey[KeyID].KeyLen == 0) {
760 DBGPRINT(RT_DEBUG_TRACE,
761 ("RTMPSoftDecryptTKIP failed!(KeyID[%d] Length can not be 0)\n",
762 KeyID));
763 return FALSE;
764 }
765
766 duration = *((u16 *)(pData + 2));
767
768 seq_control = *((u16 *)(pData + 22));
769
770 if (qc_exists) {
771 if (a4_exists) {
772 qos_control = *((u16 *)(pData + 30));
773 } else {
774 qos_control = *((u16 *)(pData + 24));
775 }
776 }
777
778 if (to_ds == 0 && from_ds == 1) {
779 NdisMoveMemory(DA, pData + 4, MAC_ADDR_LEN);
780 NdisMoveMemory(SA, pData + 16, MAC_ADDR_LEN);
781 NdisMoveMemory(TA, pData + 10, MAC_ADDR_LEN); /*BSSID */
782 } else if (to_ds == 0 && from_ds == 0) {
783 NdisMoveMemory(TA, pData + 10, MAC_ADDR_LEN);
784 NdisMoveMemory(DA, pData + 4, MAC_ADDR_LEN);
785 NdisMoveMemory(SA, pData + 10, MAC_ADDR_LEN);
786 } else if (to_ds == 1 && from_ds == 0) {
787 NdisMoveMemory(SA, pData + 10, MAC_ADDR_LEN);
788 NdisMoveMemory(TA, pData + 10, MAC_ADDR_LEN);
789 NdisMoveMemory(DA, pData + 16, MAC_ADDR_LEN);
790 } else if (to_ds == 1 && from_ds == 1) {
791 NdisMoveMemory(TA, pData + 10, MAC_ADDR_LEN);
792 NdisMoveMemory(DA, pData + 16, MAC_ADDR_LEN);
793 NdisMoveMemory(SA, pData + 22, MAC_ADDR_LEN);
794 }
795
796 num_blocks = (DataByteCnt - 16) / 16;
797 payload_remainder = (DataByteCnt - 16) % 16;
798
799 pnl = (*(pData + HeaderLen)) * 256 + *(pData + HeaderLen + 2);
800 pnh = *((unsigned long *)(pData + HeaderLen + 4));
801 pnh = cpu2le32(pnh);
802 RTMPTkipMixKey(pWpaKey[KeyID].Key, TA, pnl, pnh, RC4Key, p1k);
803
804 ARCFOUR_INIT(&ArcFourContext, RC4Key, 16);
805
806 ARCFOUR_DECRYPT(&ArcFourContext, pData + HeaderLen,
807 pData + HeaderLen + 8, DataByteCnt - HeaderLen - 8);
808 NdisMoveMemory(&trailfcs, pData + DataByteCnt - 8 - 4, 4);
809 crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pData + HeaderLen, DataByteCnt - HeaderLen - 8 - 4); /*Skip IV+EIV 8 bytes & Skip last 4 bytes(FCS). */
810 crc32 ^= 0xffffffff; /* complement */
811
812 if (crc32 != cpu2le32(trailfcs)) {
813 DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptTKIP, WEP Data ICV Error !\n")); /*ICV error. */
814
815 return (FALSE);
816 }
817
818 NdisMoveMemory(TrailMIC, pData + DataByteCnt - 8 - 8 - 4, 8);
819 RTMPInitMICEngine(pAd, pWpaKey[KeyID].Key, DA, SA, UserPriority,
820 pWpaKey[KeyID].RxMic);
821 RTMPTkipAppend(&pAd->PrivateInfo.Tx, pData + HeaderLen,
822 DataByteCnt - HeaderLen - 8 - 12);
823 RTMPTkipGetMIC(&pAd->PrivateInfo.Tx);
824 NdisMoveMemory(MIC, pAd->PrivateInfo.Tx.MIC, 8);
825
826 if (!NdisEqualMemory(MIC, TrailMIC, 8)) {
827 DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptTKIP, WEP Data MIC Error !\n")); /*MIC error. */
828 /*RTMPReportMicError(pAd, &pWpaKey[KeyID]); // marked by AlbertY @ 20060630 */
829 return (FALSE);
830 }
831 /*DBGPRINT(RT_DEBUG_TRACE, "RTMPSoftDecryptTKIP Decript done!\n"); */
832 return TRUE;
833}
diff --git a/drivers/staging/rt2860/common/cmm_wep.c b/drivers/staging/rt2860/common/cmm_wep.c
deleted file mode 100644
index 76f880cb39b..00000000000
--- a/drivers/staging/rt2860/common/cmm_wep.c
+++ /dev/null
@@ -1,473 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_wep.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Paul Wu 10-28-02 Initial
36*/
37
38#include "../rt_config.h"
39
40u32 FCSTAB_32[256] = {
41 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
42 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
43 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
44 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
45 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
46 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
47 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
48 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
49 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
50 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
51 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
52 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
53 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
54 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
55 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
56 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
57 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
58 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
59 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
60 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
61 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
62 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
63 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
64 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
65 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
66 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
67 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
68 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
69 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
70 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
71 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
72 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
73 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
74 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
75 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
76 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
77 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
78 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
79 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
80 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
81 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
82 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
83 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
84 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
85 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
86 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
87 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
88 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
89 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
90 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
91 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
92 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
93 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
94 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
95 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
96 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
97 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
98 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
99 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
100 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
101 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
102 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
103 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
104 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
105};
106
107/*
108u8 WEPKEY[] = {
109 //IV
110 0x00, 0x11, 0x22,
111 //WEP KEY
112 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC
113 };
114 */
115
116/*
117 ========================================================================
118
119 Routine Description:
120 Init WEP function.
121
122 Arguments:
123 pAd Pointer to our adapter
124 pKey Pointer to the WEP KEY
125 KeyId WEP Key ID
126 KeyLen the length of WEP KEY
127 pDest Pointer to the destination which Encryption data will store in.
128
129 Return Value:
130 None
131
132 IRQL = DISPATCH_LEVEL
133
134 Note:
135
136 ========================================================================
137*/
138void RTMPInitWepEngine(struct rt_rtmp_adapter *pAd,
139 u8 *pKey,
140 u8 KeyId, u8 KeyLen, IN u8 *pDest)
141{
142 u32 i;
143 u8 WEPKEY[] = {
144 /*IV */
145 0x00, 0x11, 0x22,
146 /*WEP KEY */
147 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
148 0xAA, 0xBB, 0xCC
149 };
150
151 pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; /*Init crc32. */
152
153 {
154 NdisMoveMemory(WEPKEY + 3, pKey, KeyLen);
155
156 for (i = 0; i < 3; i++)
157 WEPKEY[i] = RandomByte(pAd); /*Call mlme RandomByte() function. */
158 ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, KeyLen + 3); /*INIT SBOX, KEYLEN+3(IV) */
159
160 NdisMoveMemory(pDest, WEPKEY, 3); /*Append Init Vector */
161 }
162 *(pDest + 3) = (KeyId << 6); /*Append KEYID */
163
164}
165
166/*
167 ========================================================================
168
169 Routine Description:
170 Encrypt transimitted data
171
172 Arguments:
173 pAd Pointer to our adapter
174 pSrc Pointer to the transimitted source data that will be encrypt
175 pDest Pointer to the destination where entryption data will be store in.
176 Len Indicate the length of the source data
177
178 Return Value:
179 None
180
181 IRQL = DISPATCH_LEVEL
182
183 Note:
184
185 ========================================================================
186*/
187void RTMPEncryptData(struct rt_rtmp_adapter *pAd,
188 u8 *pSrc, u8 *pDest, u32 Len)
189{
190 pAd->PrivateInfo.FCSCRC32 =
191 RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, pSrc, Len);
192 ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, pSrc, Len);
193}
194
195/*
196 ========================================================================
197
198 Routine Description:
199 Decrypt received WEP data
200
201 Arguments:
202 pAdapter Pointer to our adapter
203 pSrc Pointer to the received data
204 Len the length of the received data
205
206 Return Value:
207 TRUE Decrypt WEP data success
208 FALSE Decrypt WEP data failed
209
210 Note:
211
212 ========================================================================
213*/
214BOOLEAN RTMPSoftDecryptWEP(struct rt_rtmp_adapter *pAd,
215 u8 *pData,
216 unsigned long DataByteCnt, struct rt_cipher_key *pGroupKey)
217{
218 u32 trailfcs;
219 u32 crc32;
220 u8 KeyIdx;
221 u8 WEPKEY[] = {
222 /*IV */
223 0x00, 0x11, 0x22,
224 /*WEP KEY */
225 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
226 0xAA, 0xBB, 0xCC
227 };
228 u8 *pPayload = (u8 *) pData + LENGTH_802_11;
229 unsigned long payload_len = DataByteCnt - LENGTH_802_11;
230
231 NdisMoveMemory(WEPKEY, pPayload, 3); /*Get WEP IV */
232
233 KeyIdx = (*(pPayload + 3) & 0xc0) >> 6;
234 if (pGroupKey[KeyIdx].KeyLen == 0)
235 return (FALSE);
236
237 NdisMoveMemory(WEPKEY + 3, pGroupKey[KeyIdx].Key,
238 pGroupKey[KeyIdx].KeyLen);
239 ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY,
240 pGroupKey[KeyIdx].KeyLen + 3);
241 ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, pPayload, pPayload + 4,
242 payload_len - 4);
243 NdisMoveMemory(&trailfcs, pPayload + payload_len - 8, 4);
244 crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pPayload, payload_len - 8); /*Skip last 4 bytes(FCS). */
245 crc32 ^= 0xffffffff; /* complement */
246
247 if (crc32 != cpu2le32(trailfcs)) {
248 DBGPRINT(RT_DEBUG_TRACE, ("WEP Data CRC Error!\n")); /*CRC error. */
249 return (FALSE);
250 }
251 return (TRUE);
252}
253
254/*
255 ========================================================================
256
257 Routine Description:
258 The Stream Cipher Encryption Algorithm "struct rt_arcfour" initialize
259
260 Arguments:
261 Ctx Pointer to struct rt_arcfour CONTEXT (SBOX)
262 pKey Pointer to the WEP KEY
263 KeyLen Indicate the length fo the WEP KEY
264
265 Return Value:
266 None
267
268 IRQL = DISPATCH_LEVEL
269
270 Note:
271
272 ========================================================================
273*/
274void ARCFOUR_INIT(struct rt_arcfourcontext *Ctx, u8 *pKey, u32 KeyLen)
275{
276 u8 t, u;
277 u32 keyindex;
278 u32 stateindex;
279 u8 *state;
280 u32 counter;
281
282 state = Ctx->STATE;
283 Ctx->X = 0;
284 Ctx->Y = 0;
285 for (counter = 0; counter < 256; counter++)
286 state[counter] = (u8)counter;
287 keyindex = 0;
288 stateindex = 0;
289 for (counter = 0; counter < 256; counter++) {
290 t = state[counter];
291 stateindex = (stateindex + pKey[keyindex] + t) & 0xff;
292 u = state[stateindex];
293 state[stateindex] = t;
294 state[counter] = u;
295 if (++keyindex >= KeyLen)
296 keyindex = 0;
297 }
298}
299
300/*
301 ========================================================================
302
303 Routine Description:
304 Get bytes from struct rt_arcfour CONTEXT (S-BOX)
305
306 Arguments:
307 Ctx Pointer to struct rt_arcfour CONTEXT (SBOX)
308
309 Return Value:
310 u8 - the value of the struct rt_arcfour CONTEXT (S-BOX)
311
312 Note:
313
314 ========================================================================
315*/
316u8 ARCFOUR_BYTE(struct rt_arcfourcontext *Ctx)
317{
318 u32 x;
319 u32 y;
320 u8 sx, sy;
321 u8 *state;
322
323 state = Ctx->STATE;
324 x = (Ctx->X + 1) & 0xff;
325 sx = state[x];
326 y = (sx + Ctx->Y) & 0xff;
327 sy = state[y];
328 Ctx->X = x;
329 Ctx->Y = y;
330 state[y] = sx;
331 state[x] = sy;
332
333 return (state[(sx + sy) & 0xff]);
334
335}
336
337/*
338 ========================================================================
339
340 Routine Description:
341 The Stream Cipher Decryption Algorithm
342
343 Arguments:
344 Ctx Pointer to struct rt_arcfour CONTEXT (SBOX)
345 pDest Pointer to the Destination
346 pSrc Pointer to the Source data
347 Len Indicate the length of the Source data
348
349 Return Value:
350 None
351
352 Note:
353
354 ========================================================================
355*/
356void ARCFOUR_DECRYPT(struct rt_arcfourcontext *Ctx,
357 u8 *pDest, u8 *pSrc, u32 Len)
358{
359 u32 i;
360
361 for (i = 0; i < Len; i++)
362 pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
363}
364
365/*
366 ========================================================================
367
368 Routine Description:
369 The Stream Cipher Encryption Algorithm
370
371 Arguments:
372 Ctx Pointer to struct rt_arcfour CONTEXT (SBOX)
373 pDest Pointer to the Destination
374 pSrc Pointer to the Source data
375 Len Indicate the length of the Source dta
376
377 Return Value:
378 None
379
380 IRQL = DISPATCH_LEVEL
381
382 Note:
383
384 ========================================================================
385*/
386void ARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx,
387 u8 *pDest, u8 *pSrc, u32 Len)
388{
389 u32 i;
390
391 for (i = 0; i < Len; i++)
392 pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
393}
394
395/*
396 ========================================================================
397
398 Routine Description:
399 The Stream Cipher Encryption Algorithm which conform to the special requirement to encrypt GTK.
400
401 Arguments:
402 Ctx Pointer to struct rt_arcfour CONTEXT (SBOX)
403 pDest Pointer to the Destination
404 pSrc Pointer to the Source data
405 Len Indicate the length of the Source dta
406
407 ========================================================================
408*/
409
410void WPAARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx,
411 u8 *pDest, u8 *pSrc, u32 Len)
412{
413 u32 i;
414 /*discard first 256 bytes */
415 for (i = 0; i < 256; i++)
416 ARCFOUR_BYTE(Ctx);
417
418 for (i = 0; i < Len; i++)
419 pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx);
420}
421
422/*
423 ========================================================================
424
425 Routine Description:
426 Calculate a new FCS given the current FCS and the new data.
427
428 Arguments:
429 Fcs the original FCS value
430 Cp pointer to the data which will be calculate the FCS
431 Len the length of the data
432
433 Return Value:
434 u32 - FCS 32 bits
435
436 IRQL = DISPATCH_LEVEL
437
438 Note:
439
440 ========================================================================
441*/
442u32 RTMP_CALC_FCS32(u32 Fcs, u8 *Cp, int Len)
443{
444 while (Len--)
445 Fcs = (((Fcs) >> 8) ^ FCSTAB_32[((Fcs) ^ (*Cp++)) & 0xff]);
446
447 return (Fcs);
448}
449
450/*
451 ========================================================================
452
453 Routine Description:
454 Get last FCS and encrypt it to the destination
455
456 Arguments:
457 pDest Pointer to the Destination
458
459 Return Value:
460 None
461
462 Note:
463
464 ========================================================================
465*/
466void RTMPSetICV(struct rt_rtmp_adapter *pAd, u8 *pDest)
467{
468 pAd->PrivateInfo.FCSCRC32 ^= 0xffffffff; /* complement */
469 pAd->PrivateInfo.FCSCRC32 = cpu2le32(pAd->PrivateInfo.FCSCRC32);
470
471 ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest,
472 (u8 *)& pAd->PrivateInfo.FCSCRC32, 4);
473}
diff --git a/drivers/staging/rt2860/common/cmm_wpa.c b/drivers/staging/rt2860/common/cmm_wpa.c
deleted file mode 100644
index 616ebec50c6..00000000000
--- a/drivers/staging/rt2860/common/cmm_wpa.c
+++ /dev/null
@@ -1,3010 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 wpa.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Jan Lee 03-07-22 Initial
36 Paul Lin 03-11-28 Modify for supplicant
37*/
38#include "../rt_config.h"
39/* WPA OUI */
40u8 OUI_WPA_NONE_AKM[4] = { 0x00, 0x50, 0xF2, 0x00 };
41u8 OUI_WPA_VERSION[4] = { 0x00, 0x50, 0xF2, 0x01 };
42u8 OUI_WPA_WEP40[4] = { 0x00, 0x50, 0xF2, 0x01 };
43u8 OUI_WPA_TKIP[4] = { 0x00, 0x50, 0xF2, 0x02 };
44u8 OUI_WPA_CCMP[4] = { 0x00, 0x50, 0xF2, 0x04 };
45u8 OUI_WPA_WEP104[4] = { 0x00, 0x50, 0xF2, 0x05 };
46u8 OUI_WPA_8021X_AKM[4] = { 0x00, 0x50, 0xF2, 0x01 };
47u8 OUI_WPA_PSK_AKM[4] = { 0x00, 0x50, 0xF2, 0x02 };
48
49/* WPA2 OUI */
50u8 OUI_WPA2_WEP40[4] = { 0x00, 0x0F, 0xAC, 0x01 };
51u8 OUI_WPA2_TKIP[4] = { 0x00, 0x0F, 0xAC, 0x02 };
52u8 OUI_WPA2_CCMP[4] = { 0x00, 0x0F, 0xAC, 0x04 };
53u8 OUI_WPA2_8021X_AKM[4] = { 0x00, 0x0F, 0xAC, 0x01 };
54u8 OUI_WPA2_PSK_AKM[4] = { 0x00, 0x0F, 0xAC, 0x02 };
55u8 OUI_WPA2_WEP104[4] = { 0x00, 0x0F, 0xAC, 0x05 };
56
57static void ConstructEapolKeyData(struct rt_mac_table_entry *pEntry,
58 u8 GroupKeyWepStatus,
59 u8 keyDescVer,
60 u8 MsgType,
61 u8 DefaultKeyIdx,
62 u8 * GTK,
63 u8 * RSNIE,
64 u8 RSNIE_LEN, struct rt_eapol_packet * pMsg);
65
66static void CalculateMIC(u8 KeyDescVer,
67 u8 * PTK, struct rt_eapol_packet * pMsg);
68
69static void WpaEAPPacketAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
70
71static void WpaEAPOLASFAlertAction(struct rt_rtmp_adapter *pAd,
72 struct rt_mlme_queue_elem *Elem);
73
74static void WpaEAPOLLogoffAction(struct rt_rtmp_adapter *pAd,
75 struct rt_mlme_queue_elem *Elem);
76
77static void WpaEAPOLStartAction(struct rt_rtmp_adapter *pAd,
78 struct rt_mlme_queue_elem *Elem);
79
80static void WpaEAPOLKeyAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
81
82/*
83 ==========================================================================
84 Description:
85 association state machine init, including state transition and timer init
86 Parameters:
87 S - pointer to the association state machine
88 ==========================================================================
89 */
90void WpaStateMachineInit(struct rt_rtmp_adapter *pAd,
91 struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[])
92{
93 StateMachineInit(S, (STATE_MACHINE_FUNC *) Trans, MAX_WPA_PTK_STATE,
94 MAX_WPA_MSG, (STATE_MACHINE_FUNC) Drop, WPA_PTK,
95 WPA_MACHINE_BASE);
96
97 StateMachineSetAction(S, WPA_PTK, MT2_EAPPacket,
98 (STATE_MACHINE_FUNC) WpaEAPPacketAction);
99 StateMachineSetAction(S, WPA_PTK, MT2_EAPOLStart,
100 (STATE_MACHINE_FUNC) WpaEAPOLStartAction);
101 StateMachineSetAction(S, WPA_PTK, MT2_EAPOLLogoff,
102 (STATE_MACHINE_FUNC) WpaEAPOLLogoffAction);
103 StateMachineSetAction(S, WPA_PTK, MT2_EAPOLKey,
104 (STATE_MACHINE_FUNC) WpaEAPOLKeyAction);
105 StateMachineSetAction(S, WPA_PTK, MT2_EAPOLASFAlert,
106 (STATE_MACHINE_FUNC) WpaEAPOLASFAlertAction);
107}
108
109/*
110 ==========================================================================
111 Description:
112 this is state machine function.
113 When receiving EAP packets which is for 802.1x authentication use.
114 Not use in PSK case
115 Return:
116 ==========================================================================
117*/
118void WpaEAPPacketAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
119{
120}
121
122void WpaEAPOLASFAlertAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
123{
124}
125
126void WpaEAPOLLogoffAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
127{
128}
129
130/*
131 ==========================================================================
132 Description:
133 Start 4-way HS when rcv EAPOL_START which may create by our driver in assoc.c
134 Return:
135 ==========================================================================
136*/
137void WpaEAPOLStartAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
138{
139 struct rt_mac_table_entry *pEntry;
140 struct rt_header_802_11 * pHeader;
141
142 DBGPRINT(RT_DEBUG_TRACE, ("WpaEAPOLStartAction ===> \n"));
143
144 pHeader = (struct rt_header_802_11 *) Elem->Msg;
145
146 /*For normaol PSK, we enqueue an EAPOL-Start command to trigger the process. */
147 if (Elem->MsgLen == 6)
148 pEntry = MacTableLookup(pAd, Elem->Msg);
149 else {
150 pEntry = MacTableLookup(pAd, pHeader->Addr2);
151 }
152
153 if (pEntry) {
154 DBGPRINT(RT_DEBUG_TRACE,
155 (" PortSecured(%d), WpaState(%d), AuthMode(%d), PMKID_CacheIdx(%d) \n",
156 pEntry->PortSecured, pEntry->WpaState,
157 pEntry->AuthMode, pEntry->PMKID_CacheIdx));
158
159 if ((pEntry->PortSecured == WPA_802_1X_PORT_NOT_SECURED)
160 && (pEntry->WpaState < AS_PTKSTART)
161 && ((pEntry->AuthMode == Ndis802_11AuthModeWPAPSK)
162 || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)
163 || ((pEntry->AuthMode == Ndis802_11AuthModeWPA2)
164 && (pEntry->PMKID_CacheIdx != ENTRY_NOT_FOUND)))) {
165 pEntry->PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
166 pEntry->WpaState = AS_INITPSK;
167 pEntry->PortSecured = WPA_802_1X_PORT_NOT_SECURED;
168 NdisZeroMemory(pEntry->R_Counter,
169 sizeof(pEntry->R_Counter));
170 pEntry->ReTryCounter = PEER_MSG1_RETRY_TIMER_CTR;
171
172 WPAStart4WayHS(pAd, pEntry, PEER_MSG1_RETRY_EXEC_INTV);
173 }
174 }
175}
176
177/*
178 ==========================================================================
179 Description:
180 This is state machine function.
181 When receiving EAPOL packets which is for 802.1x key management.
182 Use both in WPA, and WPAPSK case.
183 In this function, further dispatch to different functions according to the received packet. 3 categories are :
184 1. normal 4-way pairwisekey and 2-way groupkey handshake
185 2. MIC error (Countermeasures attack) report packet from STA.
186 3. Request for pairwise/group key update from STA
187 Return:
188 ==========================================================================
189*/
190void WpaEAPOLKeyAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
191{
192 struct rt_mac_table_entry *pEntry;
193 struct rt_header_802_11 * pHeader;
194 struct rt_eapol_packet * pEapol_packet;
195 struct rt_key_info peerKeyInfo;
196
197 DBGPRINT(RT_DEBUG_TRACE, ("WpaEAPOLKeyAction ===>\n"));
198
199 pHeader = (struct rt_header_802_11 *) Elem->Msg;
200 pEapol_packet =
201 (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
202
203 NdisZeroMemory((u8 *)& peerKeyInfo, sizeof(peerKeyInfo));
204 NdisMoveMemory((u8 *)& peerKeyInfo,
205 (u8 *)& pEapol_packet->KeyDesc.KeyInfo,
206 sizeof(struct rt_key_info));
207
208 hex_dump("Received Eapol frame", (unsigned char *)pEapol_packet,
209 (Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H));
210
211 *((u16 *) & peerKeyInfo) = cpu2le16(*((u16 *) & peerKeyInfo));
212
213 do {
214 pEntry = MacTableLookup(pAd, pHeader->Addr2);
215
216 if (!pEntry
217 || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli)))
218 break;
219
220 if (pEntry->AuthMode < Ndis802_11AuthModeWPA)
221 break;
222
223 DBGPRINT(RT_DEBUG_TRACE,
224 ("Receive EAPoL-Key frame from STA %pMF\n",
225 pEntry->Addr));
226
227 if (((pEapol_packet->ProVer != EAPOL_VER)
228 && (pEapol_packet->ProVer != EAPOL_VER2))
229 || ((pEapol_packet->KeyDesc.Type != WPA1_KEY_DESC)
230 && (pEapol_packet->KeyDesc.Type != WPA2_KEY_DESC))) {
231 DBGPRINT(RT_DEBUG_ERROR,
232 ("Key descripter does not match with WPA rule\n"));
233 break;
234 }
235 /* The value 1 shall be used for all EAPOL-Key frames to and from a STA when */
236 /* neither the group nor pairwise ciphers are CCMP for Key Descriptor 1. */
237 if ((pEntry->WepStatus == Ndis802_11Encryption2Enabled)
238 && (peerKeyInfo.KeyDescVer != DESC_TYPE_TKIP)) {
239 DBGPRINT(RT_DEBUG_ERROR,
240 ("Key descripter version not match(TKIP) \n"));
241 break;
242 }
243 /* The value 2 shall be used for all EAPOL-Key frames to and from a STA when */
244 /* either the pairwise or the group cipher is AES-CCMP for Key Descriptor 2. */
245 else if ((pEntry->WepStatus == Ndis802_11Encryption3Enabled)
246 && (peerKeyInfo.KeyDescVer != DESC_TYPE_AES)) {
247 DBGPRINT(RT_DEBUG_ERROR,
248 ("Key descripter version not match(AES) \n"));
249 break;
250 }
251 /* Check if this STA is in class 3 state and the WPA state is started */
252 if ((pEntry->Sst == SST_ASSOC)
253 && (pEntry->WpaState >= AS_INITPSK)) {
254 /* Check the Key Ack (bit 7) of the Key Information to determine the Authenticator */
255 /* or not. */
256 /* An EAPOL-Key frame that is sent by the Supplicant in response to an EAPOL- */
257 /* Key frame from the Authenticator must not have the Ack bit set. */
258 if (peerKeyInfo.KeyAck == 1) {
259 /* The frame is snet by Authenticator. */
260 /* So the Supplicant side shall handle this. */
261
262 if ((peerKeyInfo.Secure == 0)
263 && (peerKeyInfo.Request == 0)
264 && (peerKeyInfo.Error == 0)
265 && (peerKeyInfo.KeyType == PAIRWISEKEY)) {
266 /* Process 1. the message 1 of 4-way HS in WPA or WPA2 */
267 /* EAPOL-Key(0,0,1,0,P,0,0,ANonce,0,DataKD_M1) */
268 /* 2. the message 3 of 4-way HS in WPA */
269 /* EAPOL-Key(0,1,1,1,P,0,KeyRSC,ANonce,MIC,DataKD_M3) */
270 if (peerKeyInfo.KeyMic == 0)
271 PeerPairMsg1Action(pAd, pEntry,
272 Elem);
273 else
274 PeerPairMsg3Action(pAd, pEntry,
275 Elem);
276 } else if ((peerKeyInfo.Secure == 1)
277 && (peerKeyInfo.KeyMic == 1)
278 && (peerKeyInfo.Request == 0)
279 && (peerKeyInfo.Error == 0)) {
280 /* Process 1. the message 3 of 4-way HS in WPA2 */
281 /* EAPOL-Key(1,1,1,1,P,0,KeyRSC,ANonce,MIC,DataKD_M3) */
282 /* 2. the message 1 of group KS in WPA or WPA2 */
283 /* EAPOL-Key(1,1,1,0,G,0,Key RSC,0, MIC,GTK[N]) */
284 if (peerKeyInfo.KeyType == PAIRWISEKEY)
285 PeerPairMsg3Action(pAd, pEntry,
286 Elem);
287 else
288 PeerGroupMsg1Action(pAd, pEntry,
289 Elem);
290 }
291 } else {
292 /* The frame is snet by Supplicant. */
293 /* So the Authenticator side shall handle this. */
294 if ((peerKeyInfo.Request == 0) &&
295 (peerKeyInfo.Error == 0) &&
296 (peerKeyInfo.KeyMic == 1)) {
297 if (peerKeyInfo.Secure == 0
298 && peerKeyInfo.KeyType ==
299 PAIRWISEKEY) {
300 /* EAPOL-Key(0,1,0,0,P,0,0,SNonce,MIC,Data) */
301 /* Process 1. message 2 of 4-way HS in WPA or WPA2 */
302 /* 2. message 4 of 4-way HS in WPA */
303 if (CONV_ARRARY_TO_u16
304 (pEapol_packet->KeyDesc.
305 KeyDataLen) == 0) {
306 PeerPairMsg4Action(pAd,
307 pEntry,
308 Elem);
309 } else {
310 PeerPairMsg2Action(pAd,
311 pEntry,
312 Elem);
313 }
314 } else if (peerKeyInfo.Secure == 1
315 && peerKeyInfo.KeyType ==
316 PAIRWISEKEY) {
317 /* EAPOL-Key(1,1,0,0,P,0,0,0,MIC,0) */
318 /* Process message 4 of 4-way HS in WPA2 */
319 PeerPairMsg4Action(pAd, pEntry,
320 Elem);
321 } else if (peerKeyInfo.Secure == 1
322 && peerKeyInfo.KeyType ==
323 GROUPKEY) {
324 /* EAPOL-Key(1,1,0,0,G,0,0,0,MIC,0) */
325 /* Process message 2 of Group key HS in WPA or WPA2 */
326 PeerGroupMsg2Action(pAd, pEntry,
327 &Elem->
328 Msg
329 [LENGTH_802_11],
330 (Elem->
331 MsgLen -
332 LENGTH_802_11));
333 }
334 }
335 }
336 }
337 } while (FALSE);
338}
339
340/*
341 ========================================================================
342
343 Routine Description:
344 Copy frame from waiting queue into relative ring buffer and set
345 appropriate ASIC register to kick hardware encryption before really
346 sent out to air.
347
348 Arguments:
349 pAd Pointer to our adapter
350 void * Pointer to outgoing Ndis frame
351 NumberOfFrag Number of fragment required
352
353 Return Value:
354 None
355
356 Note:
357
358 ========================================================================
359*/
360void RTMPToWirelessSta(struct rt_rtmp_adapter *pAd,
361 struct rt_mac_table_entry *pEntry,
362 u8 *pHeader802_3,
363 u32 HdrLen,
364 u8 *pData, u32 DataLen, IN BOOLEAN bClearFrame)
365{
366 void *pPacket;
367 int Status;
368
369 if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli)))
370 return;
371
372 do {
373 /* build a NDIS packet */
374 Status =
375 RTMPAllocateNdisPacket(pAd, &pPacket, pHeader802_3, HdrLen,
376 pData, DataLen);
377 if (Status != NDIS_STATUS_SUCCESS)
378 break;
379
380 if (bClearFrame)
381 RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 1);
382 else
383 RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 0);
384 {
385 RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
386
387 RTMP_SET_PACKET_NET_DEVICE_MBSSID(pPacket, MAIN_MBSSID); /* set a default value */
388 if (pEntry->apidx != 0)
389 RTMP_SET_PACKET_NET_DEVICE_MBSSID(pPacket,
390 pEntry->
391 apidx);
392
393 RTMP_SET_PACKET_WCID(pPacket, (u8)pEntry->Aid);
394 RTMP_SET_PACKET_MOREDATA(pPacket, FALSE);
395 }
396
397 {
398 /* send out the packet */
399 Status = STASendPacket(pAd, pPacket);
400 if (Status == NDIS_STATUS_SUCCESS) {
401 u8 Index;
402
403 /* Dequeue one frame from TxSwQueue0..3 queue and process it */
404 /* There are three place calling dequeue for TX ring. */
405 /* 1. Here, right after queueing the frame. */
406 /* 2. At the end of TxRingTxDone service routine. */
407 /* 3. Upon NDIS call RTMPSendPackets */
408 if ((!RTMP_TEST_FLAG
409 (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
410 &&
411 (!RTMP_TEST_FLAG
412 (pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS))) {
413 for (Index = 0; Index < 5; Index++)
414 if (pAd->TxSwQueue[Index].
415 Number > 0)
416 RTMPDeQueuePacket(pAd,
417 FALSE,
418 Index,
419 MAX_TX_PROCESS);
420 }
421 }
422 }
423
424 } while (FALSE);
425}
426
427/*
428 ==========================================================================
429 Description:
430 This is a function to initialize 4-way handshake
431
432 Return:
433
434 ==========================================================================
435*/
436void WPAStart4WayHS(struct rt_rtmp_adapter *pAd,
437 struct rt_mac_table_entry *pEntry, unsigned long TimeInterval)
438{
439 u8 Header802_3[14];
440 struct rt_eapol_packet EAPOLPKT;
441 u8 *pBssid = NULL;
442 u8 group_cipher = Ndis802_11WEPDisabled;
443
444 DBGPRINT(RT_DEBUG_TRACE, ("===> WPAStart4WayHS\n"));
445
446 if (RTMP_TEST_FLAG
447 (pAd,
448 fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS))
449 {
450 DBGPRINT(RT_DEBUG_ERROR,
451 ("[ERROR]WPAStart4WayHS : The interface is closed...\n"));
452 return;
453 }
454
455 if (pBssid == NULL) {
456 DBGPRINT(RT_DEBUG_ERROR,
457 ("[ERROR]WPAStart4WayHS : No corresponding Authenticator.\n"));
458 return;
459 }
460 /* Check the status */
461 if ((pEntry->WpaState > AS_PTKSTART) || (pEntry->WpaState < AS_INITPMK)) {
462 DBGPRINT(RT_DEBUG_ERROR,
463 ("[ERROR]WPAStart4WayHS : Not expect calling\n"));
464 return;
465 }
466
467 /* Increment replay counter by 1 */
468 ADD_ONE_To_64BIT_VAR(pEntry->R_Counter);
469
470 /* Randomly generate ANonce */
471 GenRandom(pAd, (u8 *) pBssid, pEntry->ANonce);
472
473 /* Construct EAPoL message - Pairwise Msg 1 */
474 /* EAPOL-Key(0,0,1,0,P,0,0,ANonce,0,DataKD_M1) */
475 NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet));
476 ConstructEapolMsg(pEntry, group_cipher, EAPOL_PAIR_MSG_1, 0, /* Default key index */
477 pEntry->ANonce, NULL, /* TxRSC */
478 NULL, /* GTK */
479 NULL, /* RSNIE */
480 0, /* RSNIE length */
481 &EAPOLPKT);
482
483 /* Make outgoing frame */
484 MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pBssid, EAPOL);
485 RTMPToWirelessSta(pAd, pEntry, Header802_3,
486 LENGTH_802_3, (u8 *)& EAPOLPKT,
487 CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4,
488 (pEntry->PortSecured ==
489 WPA_802_1X_PORT_SECURED) ? FALSE : TRUE);
490
491 /* Trigger Retry Timer */
492 RTMPModTimer(&pEntry->RetryTimer, TimeInterval);
493
494 /* Update State */
495 pEntry->WpaState = AS_PTKSTART;
496
497 DBGPRINT(RT_DEBUG_TRACE,
498 ("<=== WPAStart4WayHS: send Msg1 of 4-way \n"));
499
500}
501
502/*
503 ========================================================================
504
505 Routine Description:
506 Process Pairwise key Msg-1 of 4-way handshaking and send Msg-2
507
508 Arguments:
509 pAd Pointer to our adapter
510 Elem Message body
511
512 Return Value:
513 None
514
515 Note:
516
517 ========================================================================
518*/
519void PeerPairMsg1Action(struct rt_rtmp_adapter *pAd,
520 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem)
521{
522 u8 PTK[80];
523 u8 Header802_3[14];
524 struct rt_eapol_packet * pMsg1;
525 u32 MsgLen;
526 struct rt_eapol_packet EAPOLPKT;
527 u8 *pCurrentAddr = NULL;
528 u8 *pmk_ptr = NULL;
529 u8 group_cipher = Ndis802_11WEPDisabled;
530 u8 *rsnie_ptr = NULL;
531 u8 rsnie_len = 0;
532
533 DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg1Action \n"));
534
535 if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli)))
536 return;
537
538 if (Elem->MsgLen <
539 (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H +
540 sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE - 2))
541 return;
542
543 {
544 pCurrentAddr = pAd->CurrentAddress;
545 pmk_ptr = pAd->StaCfg.PMK;
546 group_cipher = pAd->StaCfg.GroupCipher;
547 rsnie_ptr = pAd->StaCfg.RSN_IE;
548 rsnie_len = pAd->StaCfg.RSNIE_Len;
549 }
550
551 /* Store the received frame */
552 pMsg1 = (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
553 MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H;
554
555 /* Sanity Check peer Pairwise message 1 - Replay Counter */
556 if (PeerWpaMessageSanity(pAd, pMsg1, MsgLen, EAPOL_PAIR_MSG_1, pEntry)
557 == FALSE)
558 return;
559
560 /* Store Replay counter, it will use to verify message 3 and construct message 2 */
561 NdisMoveMemory(pEntry->R_Counter, pMsg1->KeyDesc.ReplayCounter,
562 LEN_KEY_DESC_REPLAY);
563
564 /* Store ANonce */
565 NdisMoveMemory(pEntry->ANonce, pMsg1->KeyDesc.KeyNonce,
566 LEN_KEY_DESC_NONCE);
567
568 /* Generate random SNonce */
569 GenRandom(pAd, (u8 *) pCurrentAddr, pEntry->SNonce);
570
571 {
572 /* Calculate PTK(ANonce, SNonce) */
573 WpaDerivePTK(pAd,
574 pmk_ptr,
575 pEntry->ANonce,
576 pEntry->Addr,
577 pEntry->SNonce, pCurrentAddr, PTK, LEN_PTK);
578
579 /* Save key to PTK entry */
580 NdisMoveMemory(pEntry->PTK, PTK, LEN_PTK);
581 }
582
583 /* Update WpaState */
584 pEntry->WpaState = AS_PTKINIT_NEGOTIATING;
585
586 /* Construct EAPoL message - Pairwise Msg 2 */
587 /* EAPOL-Key(0,1,0,0,P,0,0,SNonce,MIC,DataKD_M2) */
588 NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet));
589 ConstructEapolMsg(pEntry, group_cipher, EAPOL_PAIR_MSG_2, 0, /* DefaultKeyIdx */
590 pEntry->SNonce, NULL, /* TxRsc */
591 NULL, /* GTK */
592 (u8 *) rsnie_ptr, rsnie_len, &EAPOLPKT);
593
594 /* Make outgoing frame */
595 MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pCurrentAddr, EAPOL);
596
597 RTMPToWirelessSta(pAd, pEntry,
598 Header802_3, sizeof(Header802_3), (u8 *)& EAPOLPKT,
599 CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, TRUE);
600
601 DBGPRINT(RT_DEBUG_TRACE,
602 ("<=== PeerPairMsg1Action: send Msg2 of 4-way \n"));
603}
604
605/*
606 ==========================================================================
607 Description:
608 When receiving the second packet of 4-way pairwisekey handshake.
609 Return:
610 ==========================================================================
611*/
612void PeerPairMsg2Action(struct rt_rtmp_adapter *pAd,
613 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem)
614{
615 u8 PTK[80];
616 BOOLEAN Cancelled;
617 struct rt_header_802_11 * pHeader;
618 struct rt_eapol_packet EAPOLPKT;
619 struct rt_eapol_packet * pMsg2;
620 u32 MsgLen;
621 u8 Header802_3[LENGTH_802_3];
622 u8 TxTsc[6];
623 u8 *pBssid = NULL;
624 u8 *pmk_ptr = NULL;
625 u8 *gtk_ptr = NULL;
626 u8 default_key = 0;
627 u8 group_cipher = Ndis802_11WEPDisabled;
628 u8 *rsnie_ptr = NULL;
629 u8 rsnie_len = 0;
630
631 DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg2Action \n"));
632
633 if ((!pEntry) || (!pEntry->ValidAsCLI))
634 return;
635
636 if (Elem->MsgLen <
637 (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H +
638 sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE - 2))
639 return;
640
641 /* check Entry in valid State */
642 if (pEntry->WpaState < AS_PTKSTART)
643 return;
644
645 /* pointer to 802.11 header */
646 pHeader = (struct rt_header_802_11 *) Elem->Msg;
647
648 /* skip 802.11_header(24-byte) and LLC_header(8) */
649 pMsg2 = (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
650 MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H;
651
652 /* Store SNonce */
653 NdisMoveMemory(pEntry->SNonce, pMsg2->KeyDesc.KeyNonce,
654 LEN_KEY_DESC_NONCE);
655
656 {
657 /* Derive PTK */
658 WpaDerivePTK(pAd, (u8 *) pmk_ptr, pEntry->ANonce, /* ANONCE */
659 (u8 *) pBssid, pEntry->SNonce, /* SNONCE */
660 pEntry->Addr, PTK, LEN_PTK);
661
662 NdisMoveMemory(pEntry->PTK, PTK, LEN_PTK);
663 }
664
665 /* Sanity Check peer Pairwise message 2 - Replay Counter, MIC, RSNIE */
666 if (PeerWpaMessageSanity(pAd, pMsg2, MsgLen, EAPOL_PAIR_MSG_2, pEntry)
667 == FALSE)
668 return;
669
670 do {
671 /* delete retry timer */
672 RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled);
673
674 /* Change state */
675 pEntry->WpaState = AS_PTKINIT_NEGOTIATING;
676
677 /* Increment replay counter by 1 */
678 ADD_ONE_To_64BIT_VAR(pEntry->R_Counter);
679
680 /* Construct EAPoL message - Pairwise Msg 3 */
681 NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet));
682 ConstructEapolMsg(pEntry,
683 group_cipher,
684 EAPOL_PAIR_MSG_3,
685 default_key,
686 pEntry->ANonce,
687 TxTsc,
688 (u8 *) gtk_ptr,
689 (u8 *) rsnie_ptr, rsnie_len, &EAPOLPKT);
690
691 /* Make outgoing frame */
692 MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pBssid, EAPOL);
693 RTMPToWirelessSta(pAd, pEntry, Header802_3, LENGTH_802_3,
694 (u8 *)& EAPOLPKT,
695 CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4,
696 (pEntry->PortSecured ==
697 WPA_802_1X_PORT_SECURED) ? FALSE : TRUE);
698
699 pEntry->ReTryCounter = PEER_MSG3_RETRY_TIMER_CTR;
700 RTMPSetTimer(&pEntry->RetryTimer, PEER_MSG3_RETRY_EXEC_INTV);
701
702 /* Update State */
703 pEntry->WpaState = AS_PTKINIT_NEGOTIATING;
704 } while (FALSE);
705
706 DBGPRINT(RT_DEBUG_TRACE,
707 ("<=== PeerPairMsg2Action: send Msg3 of 4-way \n"));
708}
709
710/*
711 ========================================================================
712
713 Routine Description:
714 Process Pairwise key Msg 3 of 4-way handshaking and send Msg 4
715
716 Arguments:
717 pAd Pointer to our adapter
718 Elem Message body
719
720 Return Value:
721 None
722
723 Note:
724
725 ========================================================================
726*/
727void PeerPairMsg3Action(struct rt_rtmp_adapter *pAd,
728 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem)
729{
730 struct rt_header_802_11 * pHeader;
731 u8 Header802_3[14];
732 struct rt_eapol_packet EAPOLPKT;
733 struct rt_eapol_packet * pMsg3;
734 u32 MsgLen;
735 u8 *pCurrentAddr = NULL;
736 u8 group_cipher = Ndis802_11WEPDisabled;
737
738 DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg3Action \n"));
739
740 if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli)))
741 return;
742
743 if (Elem->MsgLen <
744 (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H +
745 sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE - 2))
746 return;
747
748 {
749 pCurrentAddr = pAd->CurrentAddress;
750 group_cipher = pAd->StaCfg.GroupCipher;
751
752 }
753
754 /* Record 802.11 header & the received EAPOL packet Msg3 */
755 pHeader = (struct rt_header_802_11 *) Elem->Msg;
756 pMsg3 = (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
757 MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H;
758
759 /* Sanity Check peer Pairwise message 3 - Replay Counter, MIC, RSNIE */
760 if (PeerWpaMessageSanity(pAd, pMsg3, MsgLen, EAPOL_PAIR_MSG_3, pEntry)
761 == FALSE)
762 return;
763
764 /* Save Replay counter, it will use construct message 4 */
765 NdisMoveMemory(pEntry->R_Counter, pMsg3->KeyDesc.ReplayCounter,
766 LEN_KEY_DESC_REPLAY);
767
768 /* Double check ANonce */
769 if (!NdisEqualMemory
770 (pEntry->ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE)) {
771 return;
772 }
773 /* Construct EAPoL message - Pairwise Msg 4 */
774 NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet));
775 ConstructEapolMsg(pEntry, group_cipher, EAPOL_PAIR_MSG_4, 0, /* group key index not used in message 4 */
776 NULL, /* Nonce not used in message 4 */
777 NULL, /* TxRSC not used in message 4 */
778 NULL, /* GTK not used in message 4 */
779 NULL, /* RSN IE not used in message 4 */
780 0, &EAPOLPKT);
781
782 /* Update WpaState */
783 pEntry->WpaState = AS_PTKINITDONE;
784
785 /* Update pairwise key */
786 {
787 struct rt_cipher_key *pSharedKey;
788
789 pSharedKey = &pAd->SharedKey[BSS0][0];
790
791 NdisMoveMemory(pAd->StaCfg.PTK, pEntry->PTK, LEN_PTK);
792
793 /* Prepare pair-wise key information into shared key table */
794 NdisZeroMemory(pSharedKey, sizeof(struct rt_cipher_key));
795 pSharedKey->KeyLen = LEN_TKIP_EK;
796 NdisMoveMemory(pSharedKey->Key, &pAd->StaCfg.PTK[32],
797 LEN_TKIP_EK);
798 NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.PTK[48],
799 LEN_TKIP_RXMICK);
800 NdisMoveMemory(pSharedKey->TxMic,
801 &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK],
802 LEN_TKIP_TXMICK);
803
804 /* Decide its ChiperAlg */
805 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
806 pSharedKey->CipherAlg = CIPHER_TKIP;
807 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
808 pSharedKey->CipherAlg = CIPHER_AES;
809 else
810 pSharedKey->CipherAlg = CIPHER_NONE;
811
812 /* Update these related information to struct rt_mac_table_entry */
813 pEntry = &pAd->MacTab.Content[BSSID_WCID];
814 NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32],
815 LEN_TKIP_EK);
816 NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48],
817 LEN_TKIP_RXMICK);
818 NdisMoveMemory(pEntry->PairwiseKey.TxMic,
819 &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK],
820 LEN_TKIP_TXMICK);
821 pEntry->PairwiseKey.CipherAlg = pSharedKey->CipherAlg;
822
823 /* Update pairwise key information to ASIC Shared Key Table */
824 AsicAddSharedKeyEntry(pAd,
825 BSS0,
826 0,
827 pSharedKey->CipherAlg,
828 pSharedKey->Key,
829 pSharedKey->TxMic, pSharedKey->RxMic);
830
831 /* Update ASIC WCID attribute table and IVEIV table */
832 RTMPAddWcidAttributeEntry(pAd,
833 BSS0,
834 0, pSharedKey->CipherAlg, pEntry);
835
836 }
837
838 /* open 802.1x port control and privacy filter */
839 if (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK ||
840 pEntry->AuthMode == Ndis802_11AuthModeWPA2) {
841 pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
842 pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
843
844 STA_PORT_SECURED(pAd);
845 /* Indicate Connected for GUI */
846 pAd->IndicateMediaState = NdisMediaStateConnected;
847 DBGPRINT(RT_DEBUG_TRACE,
848 ("PeerPairMsg3Action: AuthMode(%s) PairwiseCipher(%s) GroupCipher(%s) \n",
849 GetAuthMode(pEntry->AuthMode),
850 GetEncryptType(pEntry->WepStatus),
851 GetEncryptType(group_cipher)));
852 } else {
853 }
854
855 /* Init 802.3 header and send out */
856 MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pCurrentAddr, EAPOL);
857 RTMPToWirelessSta(pAd, pEntry,
858 Header802_3, sizeof(Header802_3),
859 (u8 *)& EAPOLPKT,
860 CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, TRUE);
861
862 DBGPRINT(RT_DEBUG_TRACE,
863 ("<=== PeerPairMsg3Action: send Msg4 of 4-way \n"));
864}
865
866/*
867 ==========================================================================
868 Description:
869 When receiving the last packet of 4-way pairwisekey handshake.
870 Initialize 2-way groupkey handshake following.
871 Return:
872 ==========================================================================
873*/
874void PeerPairMsg4Action(struct rt_rtmp_adapter *pAd,
875 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem)
876{
877 struct rt_eapol_packet * pMsg4;
878 struct rt_header_802_11 * pHeader;
879 u32 MsgLen;
880 BOOLEAN Cancelled;
881 u8 group_cipher = Ndis802_11WEPDisabled;
882
883 DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg4Action\n"));
884
885 do {
886 if ((!pEntry) || (!pEntry->ValidAsCLI))
887 break;
888
889 if (Elem->MsgLen <
890 (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H +
891 sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE - 2))
892 break;
893
894 if (pEntry->WpaState < AS_PTKINIT_NEGOTIATING)
895 break;
896
897 /* pointer to 802.11 header */
898 pHeader = (struct rt_header_802_11 *) Elem->Msg;
899
900 /* skip 802.11_header(24-byte) and LLC_header(8) */
901 pMsg4 =
902 (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
903 MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H;
904
905 /* Sanity Check peer Pairwise message 4 - Replay Counter, MIC */
906 if (PeerWpaMessageSanity
907 (pAd, pMsg4, MsgLen, EAPOL_PAIR_MSG_4, pEntry) == FALSE)
908 break;
909
910 /* 3. uses the MLME.SETKEYS.request to configure PTK into MAC */
911 NdisZeroMemory(&pEntry->PairwiseKey, sizeof(struct rt_cipher_key));
912
913 /* reset IVEIV in Asic */
914 AsicUpdateWCIDIVEIV(pAd, pEntry->Aid, 1, 0);
915
916 pEntry->PairwiseKey.KeyLen = LEN_TKIP_EK;
917 NdisMoveMemory(pEntry->PairwiseKey.Key, &pEntry->PTK[32],
918 LEN_TKIP_EK);
919 NdisMoveMemory(pEntry->PairwiseKey.RxMic,
920 &pEntry->PTK[TKIP_AP_RXMICK_OFFSET],
921 LEN_TKIP_RXMICK);
922 NdisMoveMemory(pEntry->PairwiseKey.TxMic,
923 &pEntry->PTK[TKIP_AP_TXMICK_OFFSET],
924 LEN_TKIP_TXMICK);
925
926 /* Set pairwise key to Asic */
927 {
928 pEntry->PairwiseKey.CipherAlg = CIPHER_NONE;
929 if (pEntry->WepStatus == Ndis802_11Encryption2Enabled)
930 pEntry->PairwiseKey.CipherAlg = CIPHER_TKIP;
931 else if (pEntry->WepStatus ==
932 Ndis802_11Encryption3Enabled)
933 pEntry->PairwiseKey.CipherAlg = CIPHER_AES;
934
935 /* Add Pair-wise key to Asic */
936 AsicAddPairwiseKeyEntry(pAd,
937 pEntry->Addr,
938 (u8)pEntry->Aid,
939 &pEntry->PairwiseKey);
940
941 /* update WCID attribute table and IVEIV table for this entry */
942 RTMPAddWcidAttributeEntry(pAd,
943 pEntry->apidx,
944 0,
945 pEntry->PairwiseKey.CipherAlg,
946 pEntry);
947 }
948
949 /* 4. upgrade state */
950 pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
951 pEntry->WpaState = AS_PTKINITDONE;
952 pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
953
954 if (pEntry->AuthMode == Ndis802_11AuthModeWPA2 ||
955 pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) {
956 pEntry->GTKState = REKEY_ESTABLISHED;
957 RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled);
958
959 /* send wireless event - for set key done WPA2 */
960 if (pAd->CommonCfg.bWirelessEvent)
961 RTMPSendWirelessEvent(pAd,
962 IW_SET_KEY_DONE_WPA2_EVENT_FLAG,
963 pEntry->Addr,
964 pEntry->apidx, 0);
965
966 DBGPRINT(RT_DEBUG_OFF,
967 ("AP SETKEYS DONE - WPA2, AuthMode(%d)=%s, WepStatus(%d)=%s, GroupWepStatus(%d)=%s\n\n",
968 pEntry->AuthMode,
969 GetAuthMode(pEntry->AuthMode),
970 pEntry->WepStatus,
971 GetEncryptType(pEntry->WepStatus),
972 group_cipher, GetEncryptType(group_cipher)));
973 } else {
974 /* 5. init Group 2-way handshake if necessary. */
975 WPAStart2WayGroupHS(pAd, pEntry);
976
977 pEntry->ReTryCounter = GROUP_MSG1_RETRY_TIMER_CTR;
978 RTMPModTimer(&pEntry->RetryTimer,
979 PEER_MSG3_RETRY_EXEC_INTV);
980 }
981 } while (FALSE);
982
983}
984
985/*
986 ==========================================================================
987 Description:
988 This is a function to send the first packet of 2-way groupkey handshake
989 Return:
990
991 ==========================================================================
992*/
993void WPAStart2WayGroupHS(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry)
994{
995 u8 Header802_3[14];
996 u8 TxTsc[6];
997 struct rt_eapol_packet EAPOLPKT;
998 u8 group_cipher = Ndis802_11WEPDisabled;
999 u8 default_key = 0;
1000 u8 *gnonce_ptr = NULL;
1001 u8 *gtk_ptr = NULL;
1002 u8 *pBssid = NULL;
1003
1004 DBGPRINT(RT_DEBUG_TRACE, ("===> WPAStart2WayGroupHS\n"));
1005
1006 if ((!pEntry) || (!pEntry->ValidAsCLI))
1007 return;
1008
1009 do {
1010 /* Increment replay counter by 1 */
1011 ADD_ONE_To_64BIT_VAR(pEntry->R_Counter);
1012
1013 /* Construct EAPoL message - Group Msg 1 */
1014 NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet));
1015 ConstructEapolMsg(pEntry,
1016 group_cipher,
1017 EAPOL_GROUP_MSG_1,
1018 default_key,
1019 (u8 *) gnonce_ptr,
1020 TxTsc, (u8 *) gtk_ptr, NULL, 0, &EAPOLPKT);
1021
1022 /* Make outgoing frame */
1023 MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pBssid, EAPOL);
1024 RTMPToWirelessSta(pAd, pEntry,
1025 Header802_3, LENGTH_802_3,
1026 (u8 *)& EAPOLPKT,
1027 CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4,
1028 FALSE);
1029
1030 } while (FALSE);
1031
1032 DBGPRINT(RT_DEBUG_TRACE,
1033 ("<=== WPAStart2WayGroupHS : send out Group Message 1 \n"));
1034
1035 return;
1036}
1037
1038/*
1039 ========================================================================
1040
1041 Routine Description:
1042 Process Group key 2-way handshaking
1043
1044 Arguments:
1045 pAd Pointer to our adapter
1046 Elem Message body
1047
1048 Return Value:
1049 None
1050
1051 Note:
1052
1053 ========================================================================
1054*/
1055void PeerGroupMsg1Action(struct rt_rtmp_adapter *pAd,
1056 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem)
1057{
1058 u8 Header802_3[14];
1059 struct rt_eapol_packet EAPOLPKT;
1060 struct rt_eapol_packet * pGroup;
1061 u32 MsgLen;
1062 BOOLEAN Cancelled;
1063 u8 default_key = 0;
1064 u8 group_cipher = Ndis802_11WEPDisabled;
1065 u8 *pCurrentAddr = NULL;
1066
1067 DBGPRINT(RT_DEBUG_TRACE, ("===> PeerGroupMsg1Action \n"));
1068
1069 if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli)))
1070 return;
1071
1072 {
1073 pCurrentAddr = pAd->CurrentAddress;
1074 group_cipher = pAd->StaCfg.GroupCipher;
1075 default_key = pAd->StaCfg.DefaultKeyId;
1076 }
1077
1078 /* Process Group Message 1 frame. skip 802.11 header(24) & LLC_SNAP header(8) */
1079 pGroup = (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];
1080 MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H;
1081
1082 /* Sanity Check peer group message 1 - Replay Counter, MIC, RSNIE */
1083 if (PeerWpaMessageSanity(pAd, pGroup, MsgLen, EAPOL_GROUP_MSG_1, pEntry)
1084 == FALSE)
1085 return;
1086
1087 /* delete retry timer */
1088 RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled);
1089
1090 /* Save Replay counter, it will use to construct message 2 */
1091 NdisMoveMemory(pEntry->R_Counter, pGroup->KeyDesc.ReplayCounter,
1092 LEN_KEY_DESC_REPLAY);
1093
1094 /* Construct EAPoL message - Group Msg 2 */
1095 NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet));
1096 ConstructEapolMsg(pEntry, group_cipher, EAPOL_GROUP_MSG_2, default_key, NULL, /* Nonce not used */
1097 NULL, /* TxRSC not used */
1098 NULL, /* GTK not used */
1099 NULL, /* RSN IE not used */
1100 0, &EAPOLPKT);
1101
1102 /* open 802.1x port control and privacy filter */
1103 pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
1104 pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
1105
1106 STA_PORT_SECURED(pAd);
1107 /* Indicate Connected for GUI */
1108 pAd->IndicateMediaState = NdisMediaStateConnected;
1109
1110 DBGPRINT(RT_DEBUG_TRACE,
1111 ("PeerGroupMsg1Action: AuthMode(%s) PairwiseCipher(%s) GroupCipher(%s) \n",
1112 GetAuthMode(pEntry->AuthMode),
1113 GetEncryptType(pEntry->WepStatus),
1114 GetEncryptType(group_cipher)));
1115
1116 /* init header and Fill Packet and send Msg 2 to authenticator */
1117 MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pCurrentAddr, EAPOL);
1118 RTMPToWirelessSta(pAd, pEntry,
1119 Header802_3, sizeof(Header802_3),
1120 (u8 *)& EAPOLPKT,
1121 CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, FALSE);
1122
1123 DBGPRINT(RT_DEBUG_TRACE,
1124 ("<=== PeerGroupMsg1Action: sned group message 2\n"));
1125}
1126
1127/*
1128 ==========================================================================
1129 Description:
1130 When receiving the last packet of 2-way groupkey handshake.
1131 Return:
1132 ==========================================================================
1133*/
1134void PeerGroupMsg2Action(struct rt_rtmp_adapter *pAd,
1135 struct rt_mac_table_entry *pEntry,
1136 void * Msg, u32 MsgLen)
1137{
1138 u32 Len;
1139 u8 *pData;
1140 BOOLEAN Cancelled;
1141 struct rt_eapol_packet * pMsg2;
1142 u8 group_cipher = Ndis802_11WEPDisabled;
1143
1144 DBGPRINT(RT_DEBUG_TRACE, ("===> PeerGroupMsg2Action \n"));
1145
1146 do {
1147 if ((!pEntry) || (!pEntry->ValidAsCLI))
1148 break;
1149
1150 if (MsgLen <
1151 (LENGTH_802_1_H + LENGTH_EAPOL_H + sizeof(struct rt_key_descripter) -
1152 MAX_LEN_OF_RSNIE - 2))
1153 break;
1154
1155 if (pEntry->WpaState != AS_PTKINITDONE)
1156 break;
1157
1158 pData = (u8 *)Msg;
1159 pMsg2 = (struct rt_eapol_packet *) (pData + LENGTH_802_1_H);
1160 Len = MsgLen - LENGTH_802_1_H;
1161
1162 /* Sanity Check peer group message 2 - Replay Counter, MIC */
1163 if (PeerWpaMessageSanity
1164 (pAd, pMsg2, Len, EAPOL_GROUP_MSG_2, pEntry) == FALSE)
1165 break;
1166
1167 /* 3. upgrade state */
1168
1169 RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled);
1170 pEntry->GTKState = REKEY_ESTABLISHED;
1171
1172 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2)
1173 || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)) {
1174 /* send wireless event - for set key done WPA2 */
1175 if (pAd->CommonCfg.bWirelessEvent)
1176 RTMPSendWirelessEvent(pAd,
1177 IW_SET_KEY_DONE_WPA2_EVENT_FLAG,
1178 pEntry->Addr,
1179 pEntry->apidx, 0);
1180
1181 DBGPRINT(RT_DEBUG_OFF,
1182 ("AP SETKEYS DONE - WPA2, AuthMode(%d)=%s, WepStatus(%d)=%s, GroupWepStatus(%d)=%s\n\n",
1183 pEntry->AuthMode,
1184 GetAuthMode(pEntry->AuthMode),
1185 pEntry->WepStatus,
1186 GetEncryptType(pEntry->WepStatus),
1187 group_cipher, GetEncryptType(group_cipher)));
1188 } else {
1189 /* send wireless event - for set key done WPA */
1190 if (pAd->CommonCfg.bWirelessEvent)
1191 RTMPSendWirelessEvent(pAd,
1192 IW_SET_KEY_DONE_WPA1_EVENT_FLAG,
1193 pEntry->Addr,
1194 pEntry->apidx, 0);
1195
1196 DBGPRINT(RT_DEBUG_OFF,
1197 ("AP SETKEYS DONE - WPA1, AuthMode(%d)=%s, WepStatus(%d)=%s, GroupWepStatus(%d)=%s\n\n",
1198 pEntry->AuthMode,
1199 GetAuthMode(pEntry->AuthMode),
1200 pEntry->WepStatus,
1201 GetEncryptType(pEntry->WepStatus),
1202 group_cipher, GetEncryptType(group_cipher)));
1203 }
1204 } while (FALSE);
1205}
1206
1207/*
1208 ========================================================================
1209
1210 Routine Description:
1211 Classify WPA EAP message type
1212
1213 Arguments:
1214 EAPType Value of EAP message type
1215 MsgType Internal Message definition for MLME state machine
1216
1217 Return Value:
1218 TRUE Found appropriate message type
1219 FALSE No appropriate message type
1220
1221 IRQL = DISPATCH_LEVEL
1222
1223 Note:
1224 All these constants are defined in wpa.h
1225 For supplicant, there is only EAPOL Key message available
1226
1227 ========================================================================
1228*/
1229BOOLEAN WpaMsgTypeSubst(u8 EAPType, int * MsgType)
1230{
1231 switch (EAPType) {
1232 case EAPPacket:
1233 *MsgType = MT2_EAPPacket;
1234 break;
1235 case EAPOLStart:
1236 *MsgType = MT2_EAPOLStart;
1237 break;
1238 case EAPOLLogoff:
1239 *MsgType = MT2_EAPOLLogoff;
1240 break;
1241 case EAPOLKey:
1242 *MsgType = MT2_EAPOLKey;
1243 break;
1244 case EAPOLASFAlert:
1245 *MsgType = MT2_EAPOLASFAlert;
1246 break;
1247 default:
1248 return FALSE;
1249 }
1250 return TRUE;
1251}
1252
1253/*
1254 ========================================================================
1255
1256 Routine Description:
1257 The pseudo-random function(PRF) that hashes various inputs to
1258 derive a pseudo-random value. To add liveness to the pseudo-random
1259 value, a nonce should be one of the inputs.
1260
1261 It is used to generate PTK, GTK or some specific random value.
1262
1263 Arguments:
1264 u8 *key, - the key material for HMAC_SHA1 use
1265 int key_len - the length of key
1266 u8 *prefix - a prefix label
1267 int prefix_len - the length of the label
1268 u8 *data - a specific data with variable length
1269 int data_len - the length of a specific data
1270 int len - the output length
1271
1272 Return Value:
1273 u8 *output - the calculated result
1274
1275 Note:
1276 802.11i-2004 Annex H.3
1277
1278 ========================================================================
1279*/
1280void PRF(u8 * key,
1281 int key_len,
1282 u8 * prefix,
1283 int prefix_len,
1284 u8 * data, int data_len, u8 * output, int len)
1285{
1286 int i;
1287 u8 *input;
1288 int currentindex = 0;
1289 int total_len;
1290
1291 /* Allocate memory for input */
1292 os_alloc_mem(NULL, (u8 **) & input, 1024);
1293
1294 if (input == NULL) {
1295 DBGPRINT(RT_DEBUG_ERROR, ("PRF: no memory!\n"));
1296 return;
1297 }
1298 /* Generate concatenation input */
1299 NdisMoveMemory(input, prefix, prefix_len);
1300
1301 /* Concatenate a single octet containing 0 */
1302 input[prefix_len] = 0;
1303
1304 /* Concatenate specific data */
1305 NdisMoveMemory(&input[prefix_len + 1], data, data_len);
1306 total_len = prefix_len + 1 + data_len;
1307
1308 /* Concatenate a single octet containing 0 */
1309 /* This octet shall be update later */
1310 input[total_len] = 0;
1311 total_len++;
1312
1313 /* Iterate to calculate the result by hmac-sha-1 */
1314 /* Then concatenate to last result */
1315 for (i = 0; i < (len + 19) / 20; i++) {
1316 HMAC_SHA1(key, key_len, input, total_len, &output[currentindex],
1317 SHA1_DIGEST_SIZE);
1318 currentindex += 20;
1319
1320 /* update the last octet */
1321 input[total_len - 1]++;
1322 }
1323 os_free_mem(NULL, input);
1324}
1325
1326/*
1327* F(P, S, c, i) = U1 xor U2 xor ... Uc
1328* U1 = PRF(P, S || Int(i))
1329* U2 = PRF(P, U1)
1330* Uc = PRF(P, Uc-1)
1331*/
1332
1333static void F(char *password, unsigned char *ssid, int ssidlength,
1334 int iterations, int count, unsigned char *output)
1335{
1336 unsigned char digest[36], digest1[SHA1_DIGEST_SIZE];
1337 int i, j;
1338
1339 /* U1 = PRF(P, S || int(i)) */
1340 memcpy(digest, ssid, ssidlength);
1341 digest[ssidlength] = (unsigned char)((count >> 24) & 0xff);
1342 digest[ssidlength + 1] = (unsigned char)((count >> 16) & 0xff);
1343 digest[ssidlength + 2] = (unsigned char)((count >> 8) & 0xff);
1344 digest[ssidlength + 3] = (unsigned char)(count & 0xff);
1345 HMAC_SHA1((unsigned char *)password, (int)strlen(password), digest, ssidlength + 4, digest1, SHA1_DIGEST_SIZE); /* for WPA update */
1346
1347 /* output = U1 */
1348 memcpy(output, digest1, SHA1_DIGEST_SIZE);
1349
1350 for (i = 1; i < iterations; i++) {
1351 /* Un = PRF(P, Un-1) */
1352 HMAC_SHA1((unsigned char *)password, (int)strlen(password), digest1, SHA1_DIGEST_SIZE, digest, SHA1_DIGEST_SIZE); /* for WPA update */
1353 memcpy(digest1, digest, SHA1_DIGEST_SIZE);
1354
1355 /* output = output xor Un */
1356 for (j = 0; j < SHA1_DIGEST_SIZE; j++) {
1357 output[j] ^= digest[j];
1358 }
1359 }
1360}
1361
1362/*
1363* password - ascii string up to 63 characters in length
1364* ssid - octet string up to 32 octets
1365* ssidlength - length of ssid in octets
1366* output must be 40 octets in length and outputs 256 bits of key
1367*/
1368int PasswordHash(char *password, u8 *ssid, int ssidlength, u8 *output)
1369{
1370 if ((strlen(password) > 63) || (ssidlength > 32))
1371 return 0;
1372
1373 F(password, ssid, ssidlength, 4096, 1, output);
1374 F(password, ssid, ssidlength, 4096, 2, &output[SHA1_DIGEST_SIZE]);
1375 return 1;
1376}
1377
1378/*
1379 ========================================================================
1380
1381 Routine Description:
1382 It utilizes PRF-384 or PRF-512 to derive session-specific keys from a PMK.
1383 It shall be called by 4-way handshake processing.
1384
1385 Arguments:
1386 pAd - pointer to our pAdapter context
1387 PMK - pointer to PMK
1388 ANonce - pointer to ANonce
1389 AA - pointer to Authenticator Address
1390 SNonce - pointer to SNonce
1391 SA - pointer to Supplicant Address
1392 len - indicate the length of PTK (octet)
1393
1394 Return Value:
1395 Output pointer to the PTK
1396
1397 Note:
1398 Refer to IEEE 802.11i-2004 8.5.1.2
1399
1400 ========================================================================
1401*/
1402void WpaDerivePTK(struct rt_rtmp_adapter *pAd,
1403 u8 * PMK,
1404 u8 * ANonce,
1405 u8 * AA,
1406 u8 * SNonce,
1407 u8 * SA, u8 * output, u32 len)
1408{
1409 u8 concatenation[76];
1410 u32 CurrPos = 0;
1411 u8 temp[32];
1412 u8 Prefix[] =
1413 { 'P', 'a', 'i', 'r', 'w', 'i', 's', 'e', ' ', 'k', 'e', 'y', ' ',
1414 'e', 'x', 'p', 'a', 'n', 's', 'i', 'o', 'n'
1415 };
1416
1417 /* initiate the concatenation input */
1418 NdisZeroMemory(temp, sizeof(temp));
1419 NdisZeroMemory(concatenation, 76);
1420
1421 /* Get smaller address */
1422 if (RTMPCompareMemory(SA, AA, 6) == 1)
1423 NdisMoveMemory(concatenation, AA, 6);
1424 else
1425 NdisMoveMemory(concatenation, SA, 6);
1426 CurrPos += 6;
1427
1428 /* Get larger address */
1429 if (RTMPCompareMemory(SA, AA, 6) == 1)
1430 NdisMoveMemory(&concatenation[CurrPos], SA, 6);
1431 else
1432 NdisMoveMemory(&concatenation[CurrPos], AA, 6);
1433
1434 /* store the larger mac address for backward compatible of */
1435 /* ralink proprietary STA-key issue */
1436 NdisMoveMemory(temp, &concatenation[CurrPos], MAC_ADDR_LEN);
1437 CurrPos += 6;
1438
1439 /* Get smaller Nonce */
1440 if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
1441 NdisMoveMemory(&concatenation[CurrPos], temp, 32); /* patch for ralink proprietary STA-key issue */
1442 else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
1443 NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
1444 else
1445 NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
1446 CurrPos += 32;
1447
1448 /* Get larger Nonce */
1449 if (RTMPCompareMemory(ANonce, SNonce, 32) == 0)
1450 NdisMoveMemory(&concatenation[CurrPos], temp, 32); /* patch for ralink proprietary STA-key issue */
1451 else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1)
1452 NdisMoveMemory(&concatenation[CurrPos], ANonce, 32);
1453 else
1454 NdisMoveMemory(&concatenation[CurrPos], SNonce, 32);
1455 CurrPos += 32;
1456
1457 hex_dump("concatenation=", concatenation, 76);
1458
1459 /* Use PRF to generate PTK */
1460 PRF(PMK, LEN_MASTER_KEY, Prefix, 22, concatenation, 76, output, len);
1461
1462}
1463
1464/*
1465 ========================================================================
1466
1467 Routine Description:
1468 Generate random number by software.
1469
1470 Arguments:
1471 pAd - pointer to our pAdapter context
1472 macAddr - pointer to local MAC address
1473
1474 Return Value:
1475
1476 Note:
1477 802.1ii-2004 Annex H.5
1478
1479 ========================================================================
1480*/
1481void GenRandom(struct rt_rtmp_adapter *pAd, u8 * macAddr, u8 * random)
1482{
1483 int i, curr;
1484 u8 local[80], KeyCounter[32];
1485 u8 result[80];
1486 unsigned long CurrentTime;
1487 u8 prefix[] =
1488 { 'I', 'n', 'i', 't', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r' };
1489
1490 /* Zero the related information */
1491 NdisZeroMemory(result, 80);
1492 NdisZeroMemory(local, 80);
1493 NdisZeroMemory(KeyCounter, 32);
1494
1495 for (i = 0; i < 32; i++) {
1496 /* copy the local MAC address */
1497 COPY_MAC_ADDR(local, macAddr);
1498 curr = MAC_ADDR_LEN;
1499
1500 /* concatenate the current time */
1501 NdisGetSystemUpTime(&CurrentTime);
1502 NdisMoveMemory(&local[curr], &CurrentTime, sizeof(CurrentTime));
1503 curr += sizeof(CurrentTime);
1504
1505 /* concatenate the last result */
1506 NdisMoveMemory(&local[curr], result, 32);
1507 curr += 32;
1508
1509 /* concatenate a variable */
1510 NdisMoveMemory(&local[curr], &i, 2);
1511 curr += 2;
1512
1513 /* calculate the result */
1514 PRF(KeyCounter, 32, prefix, 12, local, curr, result, 32);
1515 }
1516
1517 NdisMoveMemory(random, result, 32);
1518}
1519
1520/*
1521 ========================================================================
1522
1523 Routine Description:
1524 Build cipher suite in RSN-IE.
1525 It only shall be called by RTMPMakeRSNIE.
1526
1527 Arguments:
1528 pAd - pointer to our pAdapter context
1529 ElementID - indicate the WPA1 or WPA2
1530 WepStatus - indicate the encryption type
1531 bMixCipher - a boolean to indicate the pairwise cipher and group
1532 cipher are the same or not
1533
1534 Return Value:
1535
1536 Note:
1537
1538 ========================================================================
1539*/
1540static void RTMPMakeRsnIeCipher(struct rt_rtmp_adapter *pAd,
1541 u8 ElementID,
1542 u32 WepStatus,
1543 IN BOOLEAN bMixCipher,
1544 u8 FlexibleCipher,
1545 u8 *pRsnIe, u8 * rsn_len)
1546{
1547 u8 PairwiseCnt;
1548
1549 *rsn_len = 0;
1550
1551 /* decide WPA2 or WPA1 */
1552 if (ElementID == Wpa2Ie) {
1553 struct rt_rsnie2 *pRsnie_cipher = (struct rt_rsnie2 *)pRsnIe;
1554
1555 /* Assign the verson as 1 */
1556 pRsnie_cipher->version = 1;
1557
1558 switch (WepStatus) {
1559 /* TKIP mode */
1560 case Ndis802_11Encryption2Enabled:
1561 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
1562 pRsnie_cipher->ucount = 1;
1563 NdisMoveMemory(pRsnie_cipher->ucast[0].oui,
1564 OUI_WPA2_TKIP, 4);
1565 *rsn_len = sizeof(struct rt_rsnie2);
1566 break;
1567
1568 /* AES mode */
1569 case Ndis802_11Encryption3Enabled:
1570 if (bMixCipher)
1571 NdisMoveMemory(pRsnie_cipher->mcast,
1572 OUI_WPA2_TKIP, 4);
1573 else
1574 NdisMoveMemory(pRsnie_cipher->mcast,
1575 OUI_WPA2_CCMP, 4);
1576 pRsnie_cipher->ucount = 1;
1577 NdisMoveMemory(pRsnie_cipher->ucast[0].oui,
1578 OUI_WPA2_CCMP, 4);
1579 *rsn_len = sizeof(struct rt_rsnie2);
1580 break;
1581
1582 /* TKIP-AES mix mode */
1583 case Ndis802_11Encryption4Enabled:
1584 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4);
1585
1586 PairwiseCnt = 1;
1587 /* Insert WPA2 TKIP as the first pairwise cipher */
1588 if (MIX_CIPHER_WPA2_TKIP_ON(FlexibleCipher)) {
1589 NdisMoveMemory(pRsnie_cipher->ucast[0].oui,
1590 OUI_WPA2_TKIP, 4);
1591 /* Insert WPA2 AES as the secondary pairwise cipher */
1592 if (MIX_CIPHER_WPA2_AES_ON(FlexibleCipher)) {
1593 NdisMoveMemory(pRsnie_cipher->ucast[0].
1594 oui + 4, OUI_WPA2_CCMP,
1595 4);
1596 PairwiseCnt = 2;
1597 }
1598 } else {
1599 /* Insert WPA2 AES as the first pairwise cipher */
1600 NdisMoveMemory(pRsnie_cipher->ucast[0].oui,
1601 OUI_WPA2_CCMP, 4);
1602 }
1603
1604 pRsnie_cipher->ucount = PairwiseCnt;
1605 *rsn_len = sizeof(struct rt_rsnie2) + (4 * (PairwiseCnt - 1));
1606 break;
1607 }
1608
1609 if ((pAd->OpMode == OPMODE_STA) &&
1610 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) &&
1611 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled)) {
1612 u32 GroupCipher = pAd->StaCfg.GroupCipher;
1613 switch (GroupCipher) {
1614 case Ndis802_11GroupWEP40Enabled:
1615 NdisMoveMemory(pRsnie_cipher->mcast,
1616 OUI_WPA2_WEP40, 4);
1617 break;
1618 case Ndis802_11GroupWEP104Enabled:
1619 NdisMoveMemory(pRsnie_cipher->mcast,
1620 OUI_WPA2_WEP104, 4);
1621 break;
1622 }
1623 }
1624 /* swap for big-endian platform */
1625 pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
1626 pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
1627 } else {
1628 struct rt_rsnie *pRsnie_cipher = (struct rt_rsnie *)pRsnIe;
1629
1630 /* Assign OUI and version */
1631 NdisMoveMemory(pRsnie_cipher->oui, OUI_WPA_VERSION, 4);
1632 pRsnie_cipher->version = 1;
1633
1634 switch (WepStatus) {
1635 /* TKIP mode */
1636 case Ndis802_11Encryption2Enabled:
1637 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
1638 pRsnie_cipher->ucount = 1;
1639 NdisMoveMemory(pRsnie_cipher->ucast[0].oui,
1640 OUI_WPA_TKIP, 4);
1641 *rsn_len = sizeof(struct rt_rsnie);
1642 break;
1643
1644 /* AES mode */
1645 case Ndis802_11Encryption3Enabled:
1646 if (bMixCipher)
1647 NdisMoveMemory(pRsnie_cipher->mcast,
1648 OUI_WPA_TKIP, 4);
1649 else
1650 NdisMoveMemory(pRsnie_cipher->mcast,
1651 OUI_WPA_CCMP, 4);
1652 pRsnie_cipher->ucount = 1;
1653 NdisMoveMemory(pRsnie_cipher->ucast[0].oui,
1654 OUI_WPA_CCMP, 4);
1655 *rsn_len = sizeof(struct rt_rsnie);
1656 break;
1657
1658 /* TKIP-AES mix mode */
1659 case Ndis802_11Encryption4Enabled:
1660 NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4);
1661
1662 PairwiseCnt = 1;
1663 /* Insert WPA TKIP as the first pairwise cipher */
1664 if (MIX_CIPHER_WPA_TKIP_ON(FlexibleCipher)) {
1665 NdisMoveMemory(pRsnie_cipher->ucast[0].oui,
1666 OUI_WPA_TKIP, 4);
1667 /* Insert WPA AES as the secondary pairwise cipher */
1668 if (MIX_CIPHER_WPA_AES_ON(FlexibleCipher)) {
1669 NdisMoveMemory(pRsnie_cipher->ucast[0].
1670 oui + 4, OUI_WPA_CCMP,
1671 4);
1672 PairwiseCnt = 2;
1673 }
1674 } else {
1675 /* Insert WPA AES as the first pairwise cipher */
1676 NdisMoveMemory(pRsnie_cipher->ucast[0].oui,
1677 OUI_WPA_CCMP, 4);
1678 }
1679
1680 pRsnie_cipher->ucount = PairwiseCnt;
1681 *rsn_len = sizeof(struct rt_rsnie) + (4 * (PairwiseCnt - 1));
1682 break;
1683 }
1684
1685 if ((pAd->OpMode == OPMODE_STA) &&
1686 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) &&
1687 (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled)) {
1688 u32 GroupCipher = pAd->StaCfg.GroupCipher;
1689 switch (GroupCipher) {
1690 case Ndis802_11GroupWEP40Enabled:
1691 NdisMoveMemory(pRsnie_cipher->mcast,
1692 OUI_WPA_WEP40, 4);
1693 break;
1694 case Ndis802_11GroupWEP104Enabled:
1695 NdisMoveMemory(pRsnie_cipher->mcast,
1696 OUI_WPA_WEP104, 4);
1697 break;
1698 }
1699 }
1700 /* swap for big-endian platform */
1701 pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version);
1702 pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount);
1703 }
1704}
1705
1706/*
1707 ========================================================================
1708
1709 Routine Description:
1710 Build AKM suite in RSN-IE.
1711 It only shall be called by RTMPMakeRSNIE.
1712
1713 Arguments:
1714 pAd - pointer to our pAdapter context
1715 ElementID - indicate the WPA1 or WPA2
1716 AuthMode - indicate the authentication mode
1717 apidx - indicate the interface index
1718
1719 Return Value:
1720
1721 Note:
1722
1723 ========================================================================
1724*/
1725static void RTMPMakeRsnIeAKM(struct rt_rtmp_adapter *pAd,
1726 u8 ElementID,
1727 u32 AuthMode,
1728 u8 apidx,
1729 u8 *pRsnIe, u8 * rsn_len)
1730{
1731 struct rt_rsnie_auth *pRsnie_auth;
1732 u8 AkmCnt = 1; /* default as 1 */
1733
1734 pRsnie_auth = (struct rt_rsnie_auth *) (pRsnIe + (*rsn_len));
1735
1736 /* decide WPA2 or WPA1 */
1737 if (ElementID == Wpa2Ie) {
1738
1739 switch (AuthMode) {
1740 case Ndis802_11AuthModeWPA2:
1741 case Ndis802_11AuthModeWPA1WPA2:
1742 NdisMoveMemory(pRsnie_auth->auth[0].oui,
1743 OUI_WPA2_8021X_AKM, 4);
1744 break;
1745
1746 case Ndis802_11AuthModeWPA2PSK:
1747 case Ndis802_11AuthModeWPA1PSKWPA2PSK:
1748 NdisMoveMemory(pRsnie_auth->auth[0].oui,
1749 OUI_WPA2_PSK_AKM, 4);
1750 break;
1751 default:
1752 AkmCnt = 0;
1753 break;
1754
1755 }
1756 } else {
1757 switch (AuthMode) {
1758 case Ndis802_11AuthModeWPA:
1759 case Ndis802_11AuthModeWPA1WPA2:
1760 NdisMoveMemory(pRsnie_auth->auth[0].oui,
1761 OUI_WPA_8021X_AKM, 4);
1762 break;
1763
1764 case Ndis802_11AuthModeWPAPSK:
1765 case Ndis802_11AuthModeWPA1PSKWPA2PSK:
1766 NdisMoveMemory(pRsnie_auth->auth[0].oui,
1767 OUI_WPA_PSK_AKM, 4);
1768 break;
1769
1770 case Ndis802_11AuthModeWPANone:
1771 NdisMoveMemory(pRsnie_auth->auth[0].oui,
1772 OUI_WPA_NONE_AKM, 4);
1773 break;
1774 default:
1775 AkmCnt = 0;
1776 break;
1777 }
1778 }
1779
1780 pRsnie_auth->acount = AkmCnt;
1781 pRsnie_auth->acount = cpu2le16(pRsnie_auth->acount);
1782
1783 /* update current RSNIE length */
1784 (*rsn_len) += (sizeof(struct rt_rsnie_auth) + (4 * (AkmCnt - 1)));
1785
1786}
1787
1788/*
1789 ========================================================================
1790
1791 Routine Description:
1792 Build capability in RSN-IE.
1793 It only shall be called by RTMPMakeRSNIE.
1794
1795 Arguments:
1796 pAd - pointer to our pAdapter context
1797 ElementID - indicate the WPA1 or WPA2
1798 apidx - indicate the interface index
1799
1800 Return Value:
1801
1802 Note:
1803
1804 ========================================================================
1805*/
1806static void RTMPMakeRsnIeCap(struct rt_rtmp_adapter *pAd,
1807 u8 ElementID,
1808 u8 apidx,
1809 u8 *pRsnIe, u8 * rsn_len)
1810{
1811 RSN_CAPABILITIES *pRSN_Cap;
1812
1813 /* it could be ignored in WPA1 mode */
1814 if (ElementID == WpaIe)
1815 return;
1816
1817 pRSN_Cap = (RSN_CAPABILITIES *) (pRsnIe + (*rsn_len));
1818
1819 pRSN_Cap->word = cpu2le16(pRSN_Cap->word);
1820
1821 (*rsn_len) += sizeof(RSN_CAPABILITIES); /* update current RSNIE length */
1822
1823}
1824
1825/*
1826 ========================================================================
1827
1828 Routine Description:
1829 Build RSN IE context. It is not included element-ID and length.
1830
1831 Arguments:
1832 pAd - pointer to our pAdapter context
1833 AuthMode - indicate the authentication mode
1834 WepStatus - indicate the encryption type
1835 apidx - indicate the interface index
1836
1837 Return Value:
1838
1839 Note:
1840
1841 ========================================================================
1842*/
1843void RTMPMakeRSNIE(struct rt_rtmp_adapter *pAd,
1844 u32 AuthMode, u32 WepStatus, u8 apidx)
1845{
1846 u8 *pRsnIe = NULL; /* primary RSNIE */
1847 u8 *rsnielen_cur_p = 0; /* the length of the primary RSNIE */
1848 u8 *rsnielen_ex_cur_p = 0; /* the length of the secondary RSNIE */
1849 u8 PrimaryRsnie;
1850 BOOLEAN bMixCipher = FALSE; /* indicate the pairwise and group cipher are different */
1851 u8 p_offset;
1852 WPA_MIX_PAIR_CIPHER FlexibleCipher = WPA_TKIPAES_WPA2_TKIPAES; /* it provide the more flexible cipher combination in WPA-WPA2 and TKIPAES mode */
1853
1854 rsnielen_cur_p = NULL;
1855 rsnielen_ex_cur_p = NULL;
1856
1857 {
1858 {
1859 if (pAd->StaCfg.WpaSupplicantUP !=
1860 WPA_SUPPLICANT_DISABLE) {
1861 if (AuthMode < Ndis802_11AuthModeWPA)
1862 return;
1863 } else {
1864 /* Support WPAPSK or WPA2PSK in STA-Infra mode */
1865 /* Support WPANone in STA-Adhoc mode */
1866 if ((AuthMode != Ndis802_11AuthModeWPAPSK) &&
1867 (AuthMode != Ndis802_11AuthModeWPA2PSK) &&
1868 (AuthMode != Ndis802_11AuthModeWPANone)
1869 )
1870 return;
1871 }
1872
1873 DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPMakeRSNIE(STA)\n"));
1874
1875 /* Zero RSNIE context */
1876 pAd->StaCfg.RSNIE_Len = 0;
1877 NdisZeroMemory(pAd->StaCfg.RSN_IE, MAX_LEN_OF_RSNIE);
1878
1879 /* Pointer to RSNIE */
1880 rsnielen_cur_p = &pAd->StaCfg.RSNIE_Len;
1881 pRsnIe = pAd->StaCfg.RSN_IE;
1882
1883 bMixCipher = pAd->StaCfg.bMixCipher;
1884 }
1885 }
1886
1887 /* indicate primary RSNIE as WPA or WPA2 */
1888 if ((AuthMode == Ndis802_11AuthModeWPA) ||
1889 (AuthMode == Ndis802_11AuthModeWPAPSK) ||
1890 (AuthMode == Ndis802_11AuthModeWPANone) ||
1891 (AuthMode == Ndis802_11AuthModeWPA1WPA2) ||
1892 (AuthMode == Ndis802_11AuthModeWPA1PSKWPA2PSK))
1893 PrimaryRsnie = WpaIe;
1894 else
1895 PrimaryRsnie = Wpa2Ie;
1896
1897 {
1898 /* Build the primary RSNIE */
1899 /* 1. insert cipher suite */
1900 RTMPMakeRsnIeCipher(pAd, PrimaryRsnie, WepStatus, bMixCipher,
1901 FlexibleCipher, pRsnIe, &p_offset);
1902
1903 /* 2. insert AKM */
1904 RTMPMakeRsnIeAKM(pAd, PrimaryRsnie, AuthMode, apidx, pRsnIe,
1905 &p_offset);
1906
1907 /* 3. insert capability */
1908 RTMPMakeRsnIeCap(pAd, PrimaryRsnie, apidx, pRsnIe, &p_offset);
1909 }
1910
1911 /* 4. update the RSNIE length */
1912 *rsnielen_cur_p = p_offset;
1913
1914 hex_dump("The primary RSNIE", pRsnIe, (*rsnielen_cur_p));
1915
1916}
1917
1918/*
1919 ==========================================================================
1920 Description:
1921 Check whether the received frame is EAP frame.
1922
1923 Arguments:
1924 pAd - pointer to our pAdapter context
1925 pEntry - pointer to active entry
1926 pData - the received frame
1927 DataByteCount - the received frame's length
1928 FromWhichBSSID - indicate the interface index
1929
1930 Return:
1931 TRUE - This frame is EAP frame
1932 FALSE - otherwise
1933 ==========================================================================
1934*/
1935BOOLEAN RTMPCheckWPAframe(struct rt_rtmp_adapter *pAd,
1936 struct rt_mac_table_entry *pEntry,
1937 u8 *pData,
1938 unsigned long DataByteCount, u8 FromWhichBSSID)
1939{
1940 unsigned long Body_len;
1941 BOOLEAN Cancelled;
1942
1943 if (DataByteCount < (LENGTH_802_1_H + LENGTH_EAPOL_H))
1944 return FALSE;
1945
1946 /* Skip LLC header */
1947 if (NdisEqualMemory(SNAP_802_1H, pData, 6) ||
1948 /* Cisco 1200 AP may send packet with SNAP_BRIDGE_TUNNEL */
1949 NdisEqualMemory(SNAP_BRIDGE_TUNNEL, pData, 6)) {
1950 pData += 6;
1951 }
1952 /* Skip 2-bytes EAPoL type */
1953 if (NdisEqualMemory(EAPOL, pData, 2)) {
1954 pData += 2;
1955 } else
1956 return FALSE;
1957
1958 switch (*(pData + 1)) {
1959 case EAPPacket:
1960 Body_len = (*(pData + 2) << 8) | (*(pData + 3));
1961 DBGPRINT(RT_DEBUG_TRACE,
1962 ("Receive EAP-Packet frame, TYPE = 0, Length = %ld\n",
1963 Body_len));
1964 break;
1965 case EAPOLStart:
1966 DBGPRINT(RT_DEBUG_TRACE,
1967 ("Receive EAPOL-Start frame, TYPE = 1 \n"));
1968 if (pEntry->EnqueueEapolStartTimerRunning !=
1969 EAPOL_START_DISABLE) {
1970 DBGPRINT(RT_DEBUG_TRACE,
1971 ("Cancel the EnqueueEapolStartTimerRunning \n"));
1972 RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer,
1973 &Cancelled);
1974 pEntry->EnqueueEapolStartTimerRunning =
1975 EAPOL_START_DISABLE;
1976 }
1977 break;
1978 case EAPOLLogoff:
1979 DBGPRINT(RT_DEBUG_TRACE,
1980 ("Receive EAPOLLogoff frame, TYPE = 2 \n"));
1981 break;
1982 case EAPOLKey:
1983 Body_len = (*(pData + 2) << 8) | (*(pData + 3));
1984 DBGPRINT(RT_DEBUG_TRACE,
1985 ("Receive EAPOL-Key frame, TYPE = 3, Length = %ld\n",
1986 Body_len));
1987 break;
1988 case EAPOLASFAlert:
1989 DBGPRINT(RT_DEBUG_TRACE,
1990 ("Receive EAPOLASFAlert frame, TYPE = 4 \n"));
1991 break;
1992 default:
1993 return FALSE;
1994
1995 }
1996 return TRUE;
1997}
1998
1999/*
2000 ==========================================================================
2001 Description:
2002 Report the EAP message type
2003
2004 Arguments:
2005 msg - EAPOL_PAIR_MSG_1
2006 EAPOL_PAIR_MSG_2
2007 EAPOL_PAIR_MSG_3
2008 EAPOL_PAIR_MSG_4
2009 EAPOL_GROUP_MSG_1
2010 EAPOL_GROUP_MSG_2
2011
2012 Return:
2013 message type string
2014
2015 ==========================================================================
2016*/
2017char *GetEapolMsgType(char msg)
2018{
2019 if (msg == EAPOL_PAIR_MSG_1)
2020 return "Pairwise Message 1";
2021 else if (msg == EAPOL_PAIR_MSG_2)
2022 return "Pairwise Message 2";
2023 else if (msg == EAPOL_PAIR_MSG_3)
2024 return "Pairwise Message 3";
2025 else if (msg == EAPOL_PAIR_MSG_4)
2026 return "Pairwise Message 4";
2027 else if (msg == EAPOL_GROUP_MSG_1)
2028 return "Group Message 1";
2029 else if (msg == EAPOL_GROUP_MSG_2)
2030 return "Group Message 2";
2031 else
2032 return "Invalid Message";
2033}
2034
2035/*
2036 ========================================================================
2037
2038 Routine Description:
2039 Check Sanity RSN IE of EAPoL message
2040
2041 Arguments:
2042
2043 Return Value:
2044
2045 ========================================================================
2046*/
2047BOOLEAN RTMPCheckRSNIE(struct rt_rtmp_adapter *pAd,
2048 u8 *pData,
2049 u8 DataLen,
2050 struct rt_mac_table_entry *pEntry, u8 * Offset)
2051{
2052 u8 *pVIE;
2053 u8 len;
2054 struct rt_eid * pEid;
2055 BOOLEAN result = FALSE;
2056
2057 pVIE = pData;
2058 len = DataLen;
2059 *Offset = 0;
2060
2061 while (len > sizeof(struct rt_rsnie2)) {
2062 pEid = (struct rt_eid *) pVIE;
2063 /* WPA RSN IE */
2064 if ((pEid->Eid == IE_WPA)
2065 && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))) {
2066 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA
2067 || pEntry->AuthMode == Ndis802_11AuthModeWPAPSK)
2068 &&
2069 (NdisEqualMemory
2070 (pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len))
2071 && (pEntry->RSNIE_Len == (pEid->Len + 2))) {
2072 result = TRUE;
2073 }
2074
2075 *Offset += (pEid->Len + 2);
2076 }
2077 /* WPA2 RSN IE */
2078 else if ((pEid->Eid == IE_RSN)
2079 && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3))) {
2080 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2
2081 || pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)
2082 && (pEid->Eid == pEntry->RSN_IE[0])
2083 && ((pEid->Len + 2) >= pEntry->RSNIE_Len)
2084 &&
2085 (NdisEqualMemory
2086 (pEid->Octet, &pEntry->RSN_IE[2],
2087 pEntry->RSNIE_Len - 2))) {
2088
2089 result = TRUE;
2090 }
2091
2092 *Offset += (pEid->Len + 2);
2093 } else {
2094 break;
2095 }
2096
2097 pVIE += (pEid->Len + 2);
2098 len -= (pEid->Len + 2);
2099 }
2100
2101 return result;
2102
2103}
2104
2105/*
2106 ========================================================================
2107
2108 Routine Description:
2109 Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK.
2110 GTK is encaptulated in KDE format at p.83 802.11i D10
2111
2112 Arguments:
2113
2114 Return Value:
2115
2116 Note:
2117 802.11i D10
2118
2119 ========================================================================
2120*/
2121BOOLEAN RTMPParseEapolKeyData(struct rt_rtmp_adapter *pAd,
2122 u8 *pKeyData,
2123 u8 KeyDataLen,
2124 u8 GroupKeyIndex,
2125 u8 MsgType,
2126 IN BOOLEAN bWPA2, struct rt_mac_table_entry *pEntry)
2127{
2128 struct rt_kde_encap * pKDE = NULL;
2129 u8 *pMyKeyData = pKeyData;
2130 u8 KeyDataLength = KeyDataLen;
2131 u8 GTKLEN = 0;
2132 u8 DefaultIdx = 0;
2133 u8 skip_offset;
2134
2135 /* Verify The RSN IE contained in pairewise_msg_2 && pairewise_msg_3 and skip it */
2136 if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_3) {
2137 /* Check RSN IE whether it is WPA2/WPA2PSK */
2138 if (!RTMPCheckRSNIE
2139 (pAd, pKeyData, KeyDataLen, pEntry, &skip_offset)) {
2140 /* send wireless event - for RSN IE different */
2141 if (pAd->CommonCfg.bWirelessEvent)
2142 RTMPSendWirelessEvent(pAd,
2143 IW_RSNIE_DIFF_EVENT_FLAG,
2144 pEntry->Addr,
2145 pEntry->apidx, 0);
2146
2147 DBGPRINT(RT_DEBUG_ERROR,
2148 ("RSN_IE Different in msg %d of 4-way handshake!\n",
2149 MsgType));
2150 hex_dump("Receive RSN_IE ", pKeyData, KeyDataLen);
2151 hex_dump("Desired RSN_IE ", pEntry->RSN_IE,
2152 pEntry->RSNIE_Len);
2153
2154 return FALSE;
2155 } else {
2156 if (bWPA2 && MsgType == EAPOL_PAIR_MSG_3) {
2157 WpaShowAllsuite(pMyKeyData, skip_offset);
2158
2159 /* skip RSN IE */
2160 pMyKeyData += skip_offset;
2161 KeyDataLength -= skip_offset;
2162 DBGPRINT(RT_DEBUG_TRACE,
2163 ("RTMPParseEapolKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n",
2164 skip_offset));
2165 } else
2166 return TRUE;
2167 }
2168 }
2169
2170 DBGPRINT(RT_DEBUG_TRACE,
2171 ("RTMPParseEapolKeyData ==> KeyDataLength %d without RSN_IE \n",
2172 KeyDataLength));
2173 /*hex_dump("remain data", pMyKeyData, KeyDataLength); */
2174
2175 /* Parse EKD format in pairwise_msg_3_WPA2 && group_msg_1_WPA2 */
2176 if (bWPA2
2177 && (MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1)) {
2178 if (KeyDataLength >= 8) /* KDE format exclude GTK length */
2179 {
2180 pKDE = (struct rt_kde_encap *) pMyKeyData;
2181
2182 DefaultIdx = pKDE->GTKEncap.Kid;
2183
2184 /* Sanity check - KED length */
2185 if (KeyDataLength < (pKDE->Len + 2)) {
2186 DBGPRINT(RT_DEBUG_ERROR,
2187 ("ERROR: The len from KDE is too short \n"));
2188 return FALSE;
2189 }
2190 /* Get GTK length - refer to IEEE 802.11i-2004 p.82 */
2191 GTKLEN = pKDE->Len - 6;
2192 if (GTKLEN < LEN_AES_KEY) {
2193 DBGPRINT(RT_DEBUG_ERROR,
2194 ("ERROR: GTK Key length is too short (%d) \n",
2195 GTKLEN));
2196 return FALSE;
2197 }
2198
2199 } else {
2200 DBGPRINT(RT_DEBUG_ERROR,
2201 ("ERROR: KDE format length is too short \n"));
2202 return FALSE;
2203 }
2204
2205 DBGPRINT(RT_DEBUG_TRACE,
2206 ("GTK in KDE format ,DefaultKeyID=%d, KeyLen=%d \n",
2207 DefaultIdx, GTKLEN));
2208 /* skip it */
2209 pMyKeyData += 8;
2210 KeyDataLength -= 8;
2211
2212 } else if (!bWPA2 && MsgType == EAPOL_GROUP_MSG_1) {
2213 DefaultIdx = GroupKeyIndex;
2214 DBGPRINT(RT_DEBUG_TRACE,
2215 ("GTK DefaultKeyID=%d \n", DefaultIdx));
2216 }
2217 /* Sanity check - shared key index must be 1 ~ 3 */
2218 if (DefaultIdx < 1 || DefaultIdx > 3) {
2219 DBGPRINT(RT_DEBUG_ERROR,
2220 ("ERROR: GTK Key index(%d) is invalid in %s %s \n",
2221 DefaultIdx, ((bWPA2) ? "WPA2" : "WPA"),
2222 GetEapolMsgType(MsgType)));
2223 return FALSE;
2224 }
2225
2226 {
2227 struct rt_cipher_key *pSharedKey;
2228
2229 /* set key material, TxMic and RxMic */
2230 NdisMoveMemory(pAd->StaCfg.GTK, pMyKeyData, 32);
2231 pAd->StaCfg.DefaultKeyId = DefaultIdx;
2232
2233 pSharedKey = &pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId];
2234
2235 /* Prepare pair-wise key information into shared key table */
2236 NdisZeroMemory(pSharedKey, sizeof(struct rt_cipher_key));
2237 pSharedKey->KeyLen = LEN_TKIP_EK;
2238 NdisMoveMemory(pSharedKey->Key, pAd->StaCfg.GTK, LEN_TKIP_EK);
2239 NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.GTK[16],
2240 LEN_TKIP_RXMICK);
2241 NdisMoveMemory(pSharedKey->TxMic, &pAd->StaCfg.GTK[24],
2242 LEN_TKIP_TXMICK);
2243
2244 /* Update Shared Key CipherAlg */
2245 pSharedKey->CipherAlg = CIPHER_NONE;
2246 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
2247 pSharedKey->CipherAlg = CIPHER_TKIP;
2248 else if (pAd->StaCfg.GroupCipher ==
2249 Ndis802_11Encryption3Enabled)
2250 pSharedKey->CipherAlg = CIPHER_AES;
2251 else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled)
2252 pSharedKey->CipherAlg = CIPHER_WEP64;
2253 else if (pAd->StaCfg.GroupCipher ==
2254 Ndis802_11GroupWEP104Enabled)
2255 pSharedKey->CipherAlg = CIPHER_WEP128;
2256
2257 /* Update group key information to ASIC Shared Key Table */
2258 AsicAddSharedKeyEntry(pAd,
2259 BSS0,
2260 pAd->StaCfg.DefaultKeyId,
2261 pSharedKey->CipherAlg,
2262 pSharedKey->Key,
2263 pSharedKey->TxMic, pSharedKey->RxMic);
2264
2265 /* Update ASIC WCID attribute table and IVEIV table */
2266 RTMPAddWcidAttributeEntry(pAd,
2267 BSS0,
2268 pAd->StaCfg.DefaultKeyId,
2269 pSharedKey->CipherAlg, NULL);
2270 }
2271
2272 return TRUE;
2273
2274}
2275
2276/*
2277 ========================================================================
2278
2279 Routine Description:
2280 Construct EAPoL message for WPA handshaking
2281 Its format is below,
2282
2283 +--------------------+
2284 | Protocol Version | 1 octet
2285 +--------------------+
2286 | Protocol Type | 1 octet
2287 +--------------------+
2288 | Body Length | 2 octets
2289 +--------------------+
2290 | Descriptor Type | 1 octet
2291 +--------------------+
2292 | Key Information | 2 octets
2293 +--------------------+
2294 | Key Length | 1 octet
2295 +--------------------+
2296 | Key Repaly Counter | 8 octets
2297 +--------------------+
2298 | Key Nonce | 32 octets
2299 +--------------------+
2300 | Key IV | 16 octets
2301 +--------------------+
2302 | Key RSC | 8 octets
2303 +--------------------+
2304 | Key ID or Reserved | 8 octets
2305 +--------------------+
2306 | Key MIC | 16 octets
2307 +--------------------+
2308 | Key Data Length | 2 octets
2309 +--------------------+
2310 | Key Data | n octets
2311 +--------------------+
2312
2313 Arguments:
2314 pAd Pointer to our adapter
2315
2316 Return Value:
2317 None
2318
2319 Note:
2320
2321 ========================================================================
2322*/
2323void ConstructEapolMsg(struct rt_mac_table_entry *pEntry,
2324 u8 GroupKeyWepStatus,
2325 u8 MsgType,
2326 u8 DefaultKeyIdx,
2327 u8 * KeyNonce,
2328 u8 * TxRSC,
2329 u8 * GTK,
2330 u8 * RSNIE,
2331 u8 RSNIE_Len, struct rt_eapol_packet * pMsg)
2332{
2333 BOOLEAN bWPA2 = FALSE;
2334 u8 KeyDescVer;
2335
2336 /* Choose WPA2 or not */
2337 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) ||
2338 (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK))
2339 bWPA2 = TRUE;
2340
2341 /* Init Packet and Fill header */
2342 pMsg->ProVer = EAPOL_VER;
2343 pMsg->ProType = EAPOLKey;
2344
2345 /* Default 95 bytes, the EAPoL-Key descriptor exclude Key-data field */
2346 SET_u16_TO_ARRARY(pMsg->Body_Len, LEN_EAPOL_KEY_MSG);
2347
2348 /* Fill in EAPoL descriptor */
2349 if (bWPA2)
2350 pMsg->KeyDesc.Type = WPA2_KEY_DESC;
2351 else
2352 pMsg->KeyDesc.Type = WPA1_KEY_DESC;
2353
2354 /* Key Descriptor Version (bits 0-2) specifies the key descriptor version type */
2355 {
2356 /* Fill in Key information, refer to IEEE Std 802.11i-2004 page 78 */
2357 /* When either the pairwise or the group cipher is AES, the DESC_TYPE_AES(2) shall be used. */
2358 KeyDescVer =
2359 (((pEntry->WepStatus == Ndis802_11Encryption3Enabled)
2360 || (GroupKeyWepStatus ==
2361 Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES)
2362 : (DESC_TYPE_TKIP));
2363 }
2364
2365 pMsg->KeyDesc.KeyInfo.KeyDescVer = KeyDescVer;
2366
2367 /* Specify Key Type as Group(0) or Pairwise(1) */
2368 if (MsgType >= EAPOL_GROUP_MSG_1)
2369 pMsg->KeyDesc.KeyInfo.KeyType = GROUPKEY;
2370 else
2371 pMsg->KeyDesc.KeyInfo.KeyType = PAIRWISEKEY;
2372
2373 /* Specify Key Index, only group_msg1_WPA1 */
2374 if (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1))
2375 pMsg->KeyDesc.KeyInfo.KeyIndex = DefaultKeyIdx;
2376
2377 if (MsgType == EAPOL_PAIR_MSG_3)
2378 pMsg->KeyDesc.KeyInfo.Install = 1;
2379
2380 if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3)
2381 || (MsgType == EAPOL_GROUP_MSG_1))
2382 pMsg->KeyDesc.KeyInfo.KeyAck = 1;
2383
2384 if (MsgType != EAPOL_PAIR_MSG_1)
2385 pMsg->KeyDesc.KeyInfo.KeyMic = 1;
2386
2387 if ((bWPA2 && (MsgType >= EAPOL_PAIR_MSG_3)) ||
2388 (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1))) {
2389 pMsg->KeyDesc.KeyInfo.Secure = 1;
2390 }
2391
2392 if (bWPA2 && ((MsgType == EAPOL_PAIR_MSG_3) ||
2393 (MsgType == EAPOL_GROUP_MSG_1))) {
2394 pMsg->KeyDesc.KeyInfo.EKD_DL = 1;
2395 }
2396 /* key Information element has done. */
2397 *(u16 *) (&pMsg->KeyDesc.KeyInfo) =
2398 cpu2le16(*(u16 *) (&pMsg->KeyDesc.KeyInfo));
2399
2400 /* Fill in Key Length */
2401 {
2402 if (MsgType >= EAPOL_GROUP_MSG_1) {
2403 /* the length of group key cipher */
2404 pMsg->KeyDesc.KeyLength[1] =
2405 ((GroupKeyWepStatus ==
2406 Ndis802_11Encryption2Enabled) ? TKIP_GTK_LENGTH :
2407 LEN_AES_KEY);
2408 } else {
2409 /* the length of pairwise key cipher */
2410 pMsg->KeyDesc.KeyLength[1] =
2411 ((pEntry->WepStatus ==
2412 Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY :
2413 LEN_AES_KEY);
2414 }
2415 }
2416
2417 /* Fill in replay counter */
2418 NdisMoveMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter,
2419 LEN_KEY_DESC_REPLAY);
2420
2421 /* Fill Key Nonce field */
2422 /* ANonce : pairwise_msg1 & pairwise_msg3 */
2423 /* SNonce : pairwise_msg2 */
2424 /* GNonce : group_msg1_wpa1 */
2425 if ((MsgType <= EAPOL_PAIR_MSG_3)
2426 || ((!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1))))
2427 NdisMoveMemory(pMsg->KeyDesc.KeyNonce, KeyNonce,
2428 LEN_KEY_DESC_NONCE);
2429
2430 /* Fill key IV - WPA2 as 0, WPA1 as random */
2431 if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1)) {
2432 /* Suggest IV be random number plus some number, */
2433 NdisMoveMemory(pMsg->KeyDesc.KeyIv, &KeyNonce[16],
2434 LEN_KEY_DESC_IV);
2435 pMsg->KeyDesc.KeyIv[15] += 2;
2436 }
2437 /* Fill Key RSC field */
2438 /* It contains the RSC for the GTK being installed. */
2439 if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2)
2440 || (MsgType == EAPOL_GROUP_MSG_1)) {
2441 NdisMoveMemory(pMsg->KeyDesc.KeyRsc, TxRSC, 6);
2442 }
2443 /* Clear Key MIC field for MIC calculation later */
2444 NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC);
2445
2446 ConstructEapolKeyData(pEntry,
2447 GroupKeyWepStatus,
2448 KeyDescVer,
2449 MsgType,
2450 DefaultKeyIdx, GTK, RSNIE, RSNIE_Len, pMsg);
2451
2452 /* Calculate MIC and fill in KeyMic Field except Pairwise Msg 1. */
2453 if (MsgType != EAPOL_PAIR_MSG_1) {
2454 CalculateMIC(KeyDescVer, pEntry->PTK, pMsg);
2455 }
2456
2457 DBGPRINT(RT_DEBUG_TRACE,
2458 ("===> ConstructEapolMsg for %s %s\n",
2459 ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType)));
2460 DBGPRINT(RT_DEBUG_TRACE,
2461 (" Body length = %d \n",
2462 CONV_ARRARY_TO_u16(pMsg->Body_Len)));
2463 DBGPRINT(RT_DEBUG_TRACE,
2464 (" Key length = %d \n",
2465 CONV_ARRARY_TO_u16(pMsg->KeyDesc.KeyLength)));
2466
2467}
2468
2469/*
2470 ========================================================================
2471
2472 Routine Description:
2473 Construct the Key Data field of EAPoL message
2474
2475 Arguments:
2476 pAd Pointer to our adapter
2477 Elem Message body
2478
2479 Return Value:
2480 None
2481
2482 Note:
2483
2484 ========================================================================
2485*/
2486void ConstructEapolKeyData(struct rt_mac_table_entry *pEntry,
2487 u8 GroupKeyWepStatus,
2488 u8 keyDescVer,
2489 u8 MsgType,
2490 u8 DefaultKeyIdx,
2491 u8 * GTK,
2492 u8 * RSNIE,
2493 u8 RSNIE_LEN, struct rt_eapol_packet * pMsg)
2494{
2495 u8 *mpool, *Key_Data, *Rc4GTK;
2496 u8 ekey[(LEN_KEY_DESC_IV + LEN_EAP_EK)];
2497 unsigned long data_offset;
2498 BOOLEAN bWPA2Capable = FALSE;
2499 struct rt_rtmp_adapter *pAd = pEntry->pAd;
2500 BOOLEAN GTK_Included = FALSE;
2501
2502 /* Choose WPA2 or not */
2503 if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) ||
2504 (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK))
2505 bWPA2Capable = TRUE;
2506
2507 if (MsgType == EAPOL_PAIR_MSG_1 ||
2508 MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2)
2509 return;
2510
2511 /* allocate memory pool */
2512 os_alloc_mem(NULL, (u8 **) & mpool, 1500);
2513
2514 if (mpool == NULL)
2515 return;
2516
2517 /* Rc4GTK Len = 512 */
2518 Rc4GTK = (u8 *) ROUND_UP(mpool, 4);
2519 /* Key_Data Len = 512 */
2520 Key_Data = (u8 *) ROUND_UP(Rc4GTK + 512, 4);
2521
2522 NdisZeroMemory(Key_Data, 512);
2523 SET_u16_TO_ARRARY(pMsg->KeyDesc.KeyDataLen, 0);
2524 data_offset = 0;
2525
2526 /* Encapsulate RSNIE in pairwise_msg2 & pairwise_msg3 */
2527 if (RSNIE_LEN
2528 && ((MsgType == EAPOL_PAIR_MSG_2)
2529 || (MsgType == EAPOL_PAIR_MSG_3))) {
2530 u8 *pmkid_ptr = NULL;
2531 u8 pmkid_len = 0;
2532
2533 RTMPInsertRSNIE(&Key_Data[data_offset],
2534 &data_offset,
2535 RSNIE, RSNIE_LEN, pmkid_ptr, pmkid_len);
2536 }
2537
2538 /* Encapsulate KDE format in pairwise_msg3_WPA2 & group_msg1_WPA2 */
2539 if (bWPA2Capable
2540 && ((MsgType == EAPOL_PAIR_MSG_3)
2541 || (MsgType == EAPOL_GROUP_MSG_1))) {
2542 /* Key Data Encapsulation (KDE) format - 802.11i-2004 Figure-43w and Table-20h */
2543 Key_Data[data_offset + 0] = 0xDD;
2544
2545 if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled) {
2546 Key_Data[data_offset + 1] = 0x16; /* 4+2+16(OUI+DataType+DataField) */
2547 } else {
2548 Key_Data[data_offset + 1] = 0x26; /* 4+2+32(OUI+DataType+DataField) */
2549 }
2550
2551 Key_Data[data_offset + 2] = 0x00;
2552 Key_Data[data_offset + 3] = 0x0F;
2553 Key_Data[data_offset + 4] = 0xAC;
2554 Key_Data[data_offset + 5] = 0x01;
2555
2556 /* GTK KDE format - 802.11i-2004 Figure-43x */
2557 Key_Data[data_offset + 6] = (DefaultKeyIdx & 0x03);
2558 Key_Data[data_offset + 7] = 0x00; /* Reserved Byte */
2559
2560 data_offset += 8;
2561 }
2562
2563 /* Encapsulate GTK */
2564 /* Only for pairwise_msg3_WPA2 and group_msg1 */
2565 if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable)
2566 || (MsgType == EAPOL_GROUP_MSG_1)) {
2567 /* Fill in GTK */
2568 if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled) {
2569 NdisMoveMemory(&Key_Data[data_offset], GTK,
2570 LEN_AES_KEY);
2571 data_offset += LEN_AES_KEY;
2572 } else {
2573 NdisMoveMemory(&Key_Data[data_offset], GTK,
2574 TKIP_GTK_LENGTH);
2575 data_offset += TKIP_GTK_LENGTH;
2576 }
2577
2578 GTK_Included = TRUE;
2579 }
2580
2581 /* This whole key-data field shall be encrypted if a GTK is included. */
2582 /* Encrypt the data material in key data field with KEK */
2583 if (GTK_Included) {
2584 /*hex_dump("GTK_Included", Key_Data, data_offset); */
2585
2586 if ((keyDescVer == DESC_TYPE_AES)) {
2587 u8 remainder = 0;
2588 u8 pad_len = 0;
2589
2590 /* Key Descriptor Version 2 or 3: AES key wrap, defined in IETF RFC 3394, */
2591 /* shall be used to encrypt the Key Data field using the KEK field from */
2592 /* the derived PTK. */
2593
2594 /* If the Key Data field uses the NIST AES key wrap, then the Key Data field */
2595 /* shall be padded before encrypting if the key data length is less than 16 */
2596 /* octets or if it is not a multiple of 8. The padding consists of appending */
2597 /* a single octet 0xdd followed by zero or more 0x00 octets. */
2598 if ((remainder = data_offset & 0x07) != 0) {
2599 int i;
2600
2601 pad_len = (8 - remainder);
2602 Key_Data[data_offset] = 0xDD;
2603 for (i = 1; i < pad_len; i++)
2604 Key_Data[data_offset + i] = 0;
2605
2606 data_offset += pad_len;
2607 }
2608
2609 AES_GTK_KEY_WRAP(&pEntry->PTK[16], Key_Data,
2610 data_offset, Rc4GTK);
2611 /* AES wrap function will grow 8 bytes in length */
2612 data_offset += 8;
2613 } else {
2614 /* Key Descriptor Version 1: ARC4 is used to encrypt the Key Data field
2615 using the KEK field from the derived PTK. */
2616
2617 /* PREPARE Encrypted "Key DATA" field. (Encrypt GTK with RC4, usinf PTK[16]->[31] as Key, IV-field as IV) */
2618 /* put TxTsc in Key RSC field */
2619 pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; /*Init crc32. */
2620
2621 /* ekey is the contanetion of IV-field, and PTK[16]->PTK[31] */
2622 NdisMoveMemory(ekey, pMsg->KeyDesc.KeyIv,
2623 LEN_KEY_DESC_IV);
2624 NdisMoveMemory(&ekey[LEN_KEY_DESC_IV], &pEntry->PTK[16],
2625 LEN_EAP_EK);
2626 ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, ekey, sizeof(ekey)); /*INIT SBOX, KEYLEN+3(IV) */
2627 pAd->PrivateInfo.FCSCRC32 =
2628 RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, Key_Data,
2629 data_offset);
2630 WPAARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, Rc4GTK,
2631 Key_Data, data_offset);
2632 }
2633
2634 NdisMoveMemory(pMsg->KeyDesc.KeyData, Rc4GTK, data_offset);
2635 } else {
2636 NdisMoveMemory(pMsg->KeyDesc.KeyData, Key_Data, data_offset);
2637 }
2638
2639 /* Update key data length field and total body length */
2640 SET_u16_TO_ARRARY(pMsg->KeyDesc.KeyDataLen, data_offset);
2641 INC_u16_TO_ARRARY(pMsg->Body_Len, data_offset);
2642
2643 os_free_mem(NULL, mpool);
2644
2645}
2646
2647/*
2648 ========================================================================
2649
2650 Routine Description:
2651 Calcaulate MIC. It is used during 4-ways handsharking.
2652
2653 Arguments:
2654 pAd - pointer to our pAdapter context
2655 PeerWepStatus - indicate the encryption type
2656
2657 Return Value:
2658
2659 Note:
2660
2661 ========================================================================
2662*/
2663static void CalculateMIC(u8 KeyDescVer,
2664 u8 * PTK, struct rt_eapol_packet * pMsg)
2665{
2666 u8 *OutBuffer;
2667 unsigned long FrameLen = 0;
2668 u8 mic[LEN_KEY_DESC_MIC];
2669 u8 digest[80];
2670
2671 /* allocate memory for MIC calculation */
2672 os_alloc_mem(NULL, (u8 **) & OutBuffer, 512);
2673
2674 if (OutBuffer == NULL) {
2675 DBGPRINT(RT_DEBUG_ERROR, ("CalculateMIC: no memory!\n"));
2676 return;
2677 }
2678 /* make a frame for calculating MIC. */
2679 MakeOutgoingFrame(OutBuffer, &FrameLen,
2680 CONV_ARRARY_TO_u16(pMsg->Body_Len) + 4, pMsg,
2681 END_OF_ARGS);
2682
2683 NdisZeroMemory(mic, sizeof(mic));
2684
2685 /* Calculate MIC */
2686 if (KeyDescVer == DESC_TYPE_AES) {
2687 HMAC_SHA1(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, digest,
2688 SHA1_DIGEST_SIZE);
2689 NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC);
2690 } else {
2691 HMAC_MD5(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, mic,
2692 MD5_DIGEST_SIZE);
2693 }
2694
2695 /* store the calculated MIC */
2696 NdisMoveMemory(pMsg->KeyDesc.KeyMic, mic, LEN_KEY_DESC_MIC);
2697
2698 os_free_mem(NULL, OutBuffer);
2699}
2700
2701/*
2702 ========================================================================
2703
2704 Routine Description:
2705 Some received frames can't decrypt by Asic, so decrypt them by software.
2706
2707 Arguments:
2708 pAd - pointer to our pAdapter context
2709 PeerWepStatus - indicate the encryption type
2710
2711 Return Value:
2712 NDIS_STATUS_SUCCESS - decryption successful
2713 NDIS_STATUS_FAILURE - decryption failure
2714
2715 ========================================================================
2716*/
2717int RTMPSoftDecryptBroadCastData(struct rt_rtmp_adapter *pAd,
2718 struct rt_rx_blk *pRxBlk,
2719 IN NDIS_802_11_ENCRYPTION_STATUS
2720 GroupCipher, struct rt_cipher_key *pShard_key)
2721{
2722 struct rt_rxwi * pRxWI = pRxBlk->pRxWI;
2723
2724 /* handle WEP decryption */
2725 if (GroupCipher == Ndis802_11Encryption1Enabled) {
2726 if (RTMPSoftDecryptWEP
2727 (pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount,
2728 pShard_key)) {
2729
2730 /*Minus IV[4] & ICV[4] */
2731 pRxWI->MPDUtotalByteCount -= 8;
2732 } else {
2733 DBGPRINT(RT_DEBUG_ERROR,
2734 ("ERROR : Software decrypt WEP data fails.\n"));
2735 /* give up this frame */
2736 return NDIS_STATUS_FAILURE;
2737 }
2738 }
2739 /* handle TKIP decryption */
2740 else if (GroupCipher == Ndis802_11Encryption2Enabled) {
2741 if (RTMPSoftDecryptTKIP
2742 (pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, 0,
2743 pShard_key)) {
2744
2745 /*Minus 8 bytes MIC, 8 bytes IV/EIV, 4 bytes ICV */
2746 pRxWI->MPDUtotalByteCount -= 20;
2747 } else {
2748 DBGPRINT(RT_DEBUG_ERROR,
2749 ("ERROR : RTMPSoftDecryptTKIP Failed\n"));
2750 /* give up this frame */
2751 return NDIS_STATUS_FAILURE;
2752 }
2753 }
2754 /* handle AES decryption */
2755 else if (GroupCipher == Ndis802_11Encryption3Enabled) {
2756 if (RTMPSoftDecryptAES
2757 (pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount,
2758 pShard_key)) {
2759
2760 /*8 bytes MIC, 8 bytes IV/EIV (CCMP Header) */
2761 pRxWI->MPDUtotalByteCount -= 16;
2762 } else {
2763 DBGPRINT(RT_DEBUG_ERROR,
2764 ("ERROR : RTMPSoftDecryptAES Failed\n"));
2765 /* give up this frame */
2766 return NDIS_STATUS_FAILURE;
2767 }
2768 } else {
2769 /* give up this frame */
2770 return NDIS_STATUS_FAILURE;
2771 }
2772
2773 return NDIS_STATUS_SUCCESS;
2774
2775}
2776
2777u8 *GetSuiteFromRSNIE(u8 *rsnie,
2778 u32 rsnie_len, u8 type, u8 * count)
2779{
2780 struct rt_eid * pEid;
2781 int len;
2782 u8 *pBuf;
2783 int offset = 0;
2784 struct rt_rsnie_auth *pAkm;
2785 u16 acount;
2786 BOOLEAN isWPA2 = FALSE;
2787
2788 pEid = (struct rt_eid *) rsnie;
2789 len = rsnie_len - 2; /* exclude IE and length */
2790 pBuf = (u8 *)& pEid->Octet[0];
2791
2792 /* set default value */
2793 *count = 0;
2794
2795 /* Check length */
2796 if ((len <= 0) || (pEid->Len != len)) {
2797 DBGPRINT_ERR("%s : The length is invalid\n", __func__);
2798 return NULL;
2799 }
2800 /* Check WPA or WPA2 */
2801 if (pEid->Eid == IE_WPA) {
2802 struct rt_rsnie *pRsnie = (struct rt_rsnie *)pBuf;
2803 u16 ucount;
2804
2805 if (len < sizeof(struct rt_rsnie)) {
2806 DBGPRINT_ERR("%s : The length is too short for WPA\n", __func__);
2807 return NULL;
2808 }
2809 /* Get the count of pairwise cipher */
2810 ucount = cpu2le16(pRsnie->ucount);
2811 if (ucount > 2) {
2812 DBGPRINT_ERR("%s : The count(%d) of pairwise cipher is invlaid\n", __func__, ucount);
2813 return NULL;
2814 }
2815 /* Get the group cipher */
2816 if (type == GROUP_SUITE) {
2817 *count = 1;
2818 return pRsnie->mcast;
2819 }
2820 /* Get the pairwise cipher suite */
2821 else if (type == PAIRWISE_SUITE) {
2822 DBGPRINT(RT_DEBUG_TRACE,
2823 ("%s : The count of pairwise cipher is %d\n",
2824 __func__, ucount));
2825 *count = ucount;
2826 return pRsnie->ucast[0].oui;
2827 }
2828
2829 offset = sizeof(struct rt_rsnie) + (4 * (ucount - 1));
2830
2831 } else if (pEid->Eid == IE_RSN) {
2832 struct rt_rsnie2 *pRsnie = (struct rt_rsnie2 *)pBuf;
2833 u16 ucount;
2834
2835 isWPA2 = TRUE;
2836
2837 if (len < sizeof(struct rt_rsnie2)) {
2838 DBGPRINT_ERR("%s : The length is too short for WPA2\n", __func__);
2839 return NULL;
2840 }
2841 /* Get the count of pairwise cipher */
2842 ucount = cpu2le16(pRsnie->ucount);
2843 if (ucount > 2) {
2844 DBGPRINT_ERR("%s : The count(%d) of pairwise cipher is invlaid\n", __func__, ucount);
2845 return NULL;
2846 }
2847 /* Get the group cipher */
2848 if (type == GROUP_SUITE) {
2849 *count = 1;
2850 return pRsnie->mcast;
2851 }
2852 /* Get the pairwise cipher suite */
2853 else if (type == PAIRWISE_SUITE) {
2854 DBGPRINT(RT_DEBUG_TRACE,
2855 ("%s : The count of pairwise cipher is %d\n",
2856 __func__, ucount));
2857 *count = ucount;
2858 return pRsnie->ucast[0].oui;
2859 }
2860
2861 offset = sizeof(struct rt_rsnie2) + (4 * (ucount - 1));
2862
2863 } else {
2864 DBGPRINT_ERR("%s : Unknown IE (%d)\n", __func__, pEid->Eid);
2865 return NULL;
2866 }
2867
2868 /* skip group cipher and pairwise cipher suite */
2869 pBuf += offset;
2870 len -= offset;
2871
2872 if (len < sizeof(struct rt_rsnie_auth)) {
2873 DBGPRINT_ERR("%s : The length of RSNIE is too short\n", __func__);
2874 return NULL;
2875 }
2876 /* pointer to AKM count */
2877 pAkm = (struct rt_rsnie_auth *)pBuf;
2878
2879 /* Get the count of pairwise cipher */
2880 acount = cpu2le16(pAkm->acount);
2881 if (acount > 2) {
2882 DBGPRINT_ERR("%s : The count(%d) of AKM is invlaid\n", __func__, acount);
2883 return NULL;
2884 }
2885 /* Get the AKM suite */
2886 if (type == AKM_SUITE) {
2887 DBGPRINT(RT_DEBUG_TRACE, ("%s : The count of AKM is %d\n",
2888 __func__, acount));
2889 *count = acount;
2890 return pAkm->auth[0].oui;
2891 }
2892 offset = sizeof(struct rt_rsnie_auth) + (4 * (acount - 1));
2893
2894 pBuf += offset;
2895 len -= offset;
2896
2897 /* The remaining length must larger than (RSN-Capability(2) + PMKID-Count(2) + PMKID(16~)) */
2898 if (len >= (sizeof(RSN_CAPABILITIES) + 2 + LEN_PMKID)) {
2899 /* Skip RSN capability and PMKID-Count */
2900 pBuf += (sizeof(RSN_CAPABILITIES) + 2);
2901 len -= (sizeof(RSN_CAPABILITIES) + 2);
2902
2903 /* Get PMKID */
2904 if (type == PMKID_LIST) {
2905 *count = 1;
2906 return pBuf;
2907 }
2908 } else {
2909 DBGPRINT_ERR("%s : it can't get any more information beyond AKM \n", __func__);
2910 return NULL;
2911 }
2912
2913 *count = 0;
2914 /*DBGPRINT_ERR(("%s : The type(%d) doesn't support \n", __func__, type)); */
2915 return NULL;
2916
2917}
2918
2919void WpaShowAllsuite(u8 *rsnie, u32 rsnie_len)
2920{
2921 u8 *pSuite = NULL;
2922 u8 count;
2923
2924 hex_dump("RSNIE", rsnie, rsnie_len);
2925
2926 /* group cipher */
2927 pSuite = GetSuiteFromRSNIE(rsnie, rsnie_len, GROUP_SUITE, &count);
2928 if (pSuite != NULL) {
2929 hex_dump("group cipher", pSuite, 4 * count);
2930 }
2931 /* pairwise cipher */
2932 pSuite = GetSuiteFromRSNIE(rsnie, rsnie_len, PAIRWISE_SUITE, &count);
2933 if (pSuite != NULL) {
2934 hex_dump("pairwise cipher", pSuite, 4 * count);
2935 }
2936 /* AKM */
2937 pSuite = GetSuiteFromRSNIE(rsnie, rsnie_len, AKM_SUITE, &count);
2938 if (pSuite != NULL) {
2939 hex_dump("AKM suite", pSuite, 4 * count);
2940 }
2941 /* PMKID */
2942 pSuite = GetSuiteFromRSNIE(rsnie, rsnie_len, PMKID_LIST, &count);
2943 if (pSuite != NULL) {
2944 hex_dump("PMKID", pSuite, LEN_PMKID);
2945 }
2946
2947}
2948
2949void RTMPInsertRSNIE(u8 *pFrameBuf,
2950 unsigned long *pFrameLen,
2951 u8 *rsnie_ptr,
2952 u8 rsnie_len,
2953 u8 *pmkid_ptr, u8 pmkid_len)
2954{
2955 u8 *pTmpBuf;
2956 unsigned long TempLen = 0;
2957 u8 extra_len = 0;
2958 u16 pmk_count = 0;
2959 u8 ie_num;
2960 u8 total_len = 0;
2961 u8 WPA2_OUI[3] = { 0x00, 0x0F, 0xAC };
2962
2963 pTmpBuf = pFrameBuf;
2964
2965 /* PMKID-List Must larger than 0 and the multiple of 16. */
2966 if (pmkid_len > 0 && ((pmkid_len & 0x0f) == 0)) {
2967 extra_len = sizeof(u16)+ pmkid_len;
2968
2969 pmk_count = (pmkid_len >> 4);
2970 pmk_count = cpu2le16(pmk_count);
2971 } else {
2972 DBGPRINT(RT_DEBUG_WARN,
2973 ("%s : The length is PMKID-List is invalid (%d), so don't insert it.\n",
2974 __func__, pmkid_len));
2975 }
2976
2977 if (rsnie_len != 0) {
2978 ie_num = IE_WPA;
2979 total_len = rsnie_len;
2980
2981 if (NdisEqualMemory(rsnie_ptr + 2, WPA2_OUI, sizeof(WPA2_OUI))) {
2982 ie_num = IE_RSN;
2983 total_len += extra_len;
2984 }
2985
2986 /* construct RSNIE body */
2987 MakeOutgoingFrame(pTmpBuf, &TempLen,
2988 1, &ie_num,
2989 1, &total_len,
2990 rsnie_len, rsnie_ptr, END_OF_ARGS);
2991
2992 pTmpBuf += TempLen;
2993 *pFrameLen = *pFrameLen + TempLen;
2994
2995 if (ie_num == IE_RSN) {
2996 /* Insert PMKID-List field */
2997 if (extra_len > 0) {
2998 MakeOutgoingFrame(pTmpBuf, &TempLen,
2999 2, &pmk_count,
3000 pmkid_len, pmkid_ptr,
3001 END_OF_ARGS);
3002
3003 pTmpBuf += TempLen;
3004 *pFrameLen = *pFrameLen + TempLen;
3005 }
3006 }
3007 }
3008
3009 return;
3010}
diff --git a/drivers/staging/rt2860/common/crypt_hmac.c b/drivers/staging/rt2860/common/crypt_hmac.c
deleted file mode 100644
index d7ab08ec1a4..00000000000
--- a/drivers/staging/rt2860/common/crypt_hmac.c
+++ /dev/null
@@ -1,187 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************/
26
27#include "../crypt_hmac.h"
28
29#ifdef HMAC_SHA1_SUPPORT
30/*
31========================================================================
32Routine Description:
33 HMAC using SHA1 hash function
34
35Arguments:
36 key Secret key
37 key_len The length of the key in bytes
38 message Message context
39 message_len The length of message in bytes
40 macLen Request the length of message authentication code
41
42Return Value:
43 mac Message authentication code
44
45Note:
46 None
47========================================================================
48*/
49void HMAC_SHA1(IN const u8 Key[],
50 u32 KeyLen,
51 IN const u8 Message[],
52 u32 MessageLen, u8 MAC[], u32 MACLen)
53{
54 struct rt_sha1_ctx sha_ctx1;
55 struct rt_sha1_ctx sha_ctx2;
56 u8 K0[SHA1_BLOCK_SIZE];
57 u8 Digest[SHA1_DIGEST_SIZE];
58 u32 index;
59
60 NdisZeroMemory(&sha_ctx1, sizeof(struct rt_sha1_ctx));
61 NdisZeroMemory(&sha_ctx2, sizeof(struct rt_sha1_ctx));
62 /*
63 * If the length of K = B(Block size): K0 = K.
64 * If the length of K > B: hash K to obtain an L byte string,
65 * then append (B-L) zeros to create a B-byte string K0 (i.e., K0 = H(K) || 00...00).
66 * If the length of K < B: append zeros to the end of K to create a B-byte string K0
67 */
68 NdisZeroMemory(K0, SHA1_BLOCK_SIZE);
69 if (KeyLen <= SHA1_BLOCK_SIZE)
70 NdisMoveMemory(K0, Key, KeyLen);
71 else
72 RT_SHA1(Key, KeyLen, K0);
73 /* End of if */
74
75 /* Exclusive-Or K0 with ipad */
76 /* ipad: Inner pad; the byte x¡¦36¡¦ repeated B times. */
77 for (index = 0; index < SHA1_BLOCK_SIZE; index++)
78 K0[index] ^= 0x36;
79 /* End of for */
80
81 RT_SHA1_Init(&sha_ctx1);
82 /* H(K0^ipad) */
83 SHA1_Append(&sha_ctx1, K0, sizeof(K0));
84 /* H((K0^ipad)||text) */
85 SHA1_Append(&sha_ctx1, Message, MessageLen);
86 SHA1_End(&sha_ctx1, Digest);
87
88 /* Exclusive-Or K0 with opad and remove ipad */
89 /* opad: Outer pad; the byte x¡¦5c¡¦ repeated B times. */
90 for (index = 0; index < SHA1_BLOCK_SIZE; index++)
91 K0[index] ^= 0x36 ^ 0x5c;
92 /* End of for */
93
94 RT_SHA1_Init(&sha_ctx2);
95 /* H(K0^opad) */
96 SHA1_Append(&sha_ctx2, K0, sizeof(K0));
97 /* H( (K0^opad) || H((K0^ipad)||text) ) */
98 SHA1_Append(&sha_ctx2, Digest, SHA1_DIGEST_SIZE);
99 SHA1_End(&sha_ctx2, Digest);
100
101 if (MACLen > SHA1_DIGEST_SIZE)
102 NdisMoveMemory(MAC, Digest, SHA1_DIGEST_SIZE);
103 else
104 NdisMoveMemory(MAC, Digest, MACLen);
105} /* End of HMAC_SHA1 */
106#endif /* HMAC_SHA1_SUPPORT */
107
108#ifdef HMAC_MD5_SUPPORT
109/*
110========================================================================
111Routine Description:
112 HMAC using MD5 hash function
113
114Arguments:
115 key Secret key
116 key_len The length of the key in bytes
117 message Message context
118 message_len The length of message in bytes
119 macLen Request the length of message authentication code
120
121Return Value:
122 mac Message authentication code
123
124Note:
125 None
126========================================================================
127*/
128void HMAC_MD5(IN const u8 Key[],
129 u32 KeyLen,
130 IN const u8 Message[],
131 u32 MessageLen, u8 MAC[], u32 MACLen)
132{
133 struct rt_md5_ctx_struc md5_ctx1;
134 struct rt_md5_ctx_struc md5_ctx2;
135 u8 K0[MD5_BLOCK_SIZE];
136 u8 Digest[MD5_DIGEST_SIZE];
137 u32 index;
138
139 NdisZeroMemory(&md5_ctx1, sizeof(struct rt_md5_ctx_struc));
140 NdisZeroMemory(&md5_ctx2, sizeof(struct rt_md5_ctx_struc));
141 /*
142 * If the length of K = B(Block size): K0 = K.
143 * If the length of K > B: hash K to obtain an L byte string,
144 * then append (B-L) zeros to create a B-byte string K0 (i.e., K0 = H(K) || 00...00).
145 * If the length of K < B: append zeros to the end of K to create a B-byte string K0
146 */
147 NdisZeroMemory(K0, MD5_BLOCK_SIZE);
148 if (KeyLen <= MD5_BLOCK_SIZE) {
149 NdisMoveMemory(K0, Key, KeyLen);
150 } else {
151 RT_MD5(Key, KeyLen, K0);
152 }
153
154 /* Exclusive-Or K0 with ipad */
155 /* ipad: Inner pad; the byte x¡¦36¡¦ repeated B times. */
156 for (index = 0; index < MD5_BLOCK_SIZE; index++)
157 K0[index] ^= 0x36;
158 /* End of for */
159
160 MD5_Init(&md5_ctx1);
161 /* H(K0^ipad) */
162 MD5_Append(&md5_ctx1, K0, sizeof(K0));
163 /* H((K0^ipad)||text) */
164 MD5_Append(&md5_ctx1, Message, MessageLen);
165 MD5_End(&md5_ctx1, Digest);
166
167 /* Exclusive-Or K0 with opad and remove ipad */
168 /* opad: Outer pad; the byte x¡¦5c¡¦ repeated B times. */
169 for (index = 0; index < MD5_BLOCK_SIZE; index++)
170 K0[index] ^= 0x36 ^ 0x5c;
171 /* End of for */
172
173 MD5_Init(&md5_ctx2);
174 /* H(K0^opad) */
175 MD5_Append(&md5_ctx2, K0, sizeof(K0));
176 /* H( (K0^opad) || H((K0^ipad)||text) ) */
177 MD5_Append(&md5_ctx2, Digest, MD5_DIGEST_SIZE);
178 MD5_End(&md5_ctx2, Digest);
179
180 if (MACLen > MD5_DIGEST_SIZE)
181 NdisMoveMemory(MAC, Digest, MD5_DIGEST_SIZE);
182 else
183 NdisMoveMemory(MAC, Digest, MACLen);
184} /* End of HMAC_SHA256 */
185#endif /* HMAC_MD5_SUPPORT */
186
187/* End of crypt_hmac.c */
diff --git a/drivers/staging/rt2860/common/crypt_md5.c b/drivers/staging/rt2860/common/crypt_md5.c
deleted file mode 100644
index 6deab659c22..00000000000
--- a/drivers/staging/rt2860/common/crypt_md5.c
+++ /dev/null
@@ -1,339 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************/
26
27#include "../crypt_md5.h"
28
29#ifdef MD5_SUPPORT
30/*
31 * F, G, H and I are basic MD5 functions.
32 */
33#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
34#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
35#define H(x, y, z) ((x) ^ (y) ^ (z))
36#define I(x, y, z) ((y) ^ ((x) | (~z)))
37
38#define ROTL(x,n,w) ((x << n) | (x >> (w - n)))
39#define ROTL32(x,n) ROTL(x,n,32) /* 32 bits word */
40
41#define ROUND1(a, b, c, d, x, s, ac) { \
42 (a) += F((b),(c),(d)) + (x) + (u32)(ac); \
43 (a) = ROTL32((a),(s)); \
44 (a) += (b); \
45}
46#define ROUND2(a, b, c, d, x, s, ac) { \
47 (a) += G((b),(c),(d)) + (x) + (u32)(ac); \
48 (a) = ROTL32((a),(s)); \
49 (a) += (b); \
50}
51#define ROUND3(a, b, c, d, x, s, ac) { \
52 (a) += H((b),(c),(d)) + (x) + (u32)(ac); \
53 (a) = ROTL32((a),(s)); \
54 (a) += (b); \
55}
56#define ROUND4(a, b, c, d, x, s, ac) { \
57 (a) += I((b),(c),(d)) + (x) + (u32)(ac); \
58 (a) = ROTL32((a),(s)); \
59 (a) += (b); \
60}
61static const u32 MD5_DefaultHashValue[4] = {
62 0x67452301UL, 0xefcdab89UL, 0x98badcfeUL, 0x10325476UL
63};
64#endif /* MD5_SUPPORT */
65
66#ifdef MD5_SUPPORT
67/*
68========================================================================
69Routine Description:
70 Initial Md5_CTX_STRUC
71
72Arguments:
73 pMD5_CTX Pointer to Md5_CTX_STRUC
74
75Return Value:
76 None
77
78Note:
79 None
80========================================================================
81*/
82void MD5_Init(struct rt_md5_ctx_struc *pMD5_CTX)
83{
84 NdisMoveMemory(pMD5_CTX->HashValue, MD5_DefaultHashValue,
85 sizeof(MD5_DefaultHashValue));
86 NdisZeroMemory(pMD5_CTX->Block, MD5_BLOCK_SIZE);
87 pMD5_CTX->BlockLen = 0;
88 pMD5_CTX->MessageLen = 0;
89} /* End of MD5_Init */
90
91/*
92========================================================================
93Routine Description:
94 MD5 computation for one block (512 bits)
95
96Arguments:
97 pMD5_CTX Pointer to Md5_CTX_STRUC
98
99Return Value:
100 None
101
102Note:
103 T[i] := floor(abs(sin(i + 1)) * (2 pow 32)), i is number of round
104========================================================================
105*/
106void MD5_Hash(struct rt_md5_ctx_struc *pMD5_CTX)
107{
108 u32 X_i;
109 u32 X[16];
110 u32 a, b, c, d;
111
112 /* Prepare the message schedule, {X_i} */
113 NdisMoveMemory(X, pMD5_CTX->Block, MD5_BLOCK_SIZE);
114 for (X_i = 0; X_i < 16; X_i++)
115 X[X_i] = cpu2le32(X[X_i]); /* Endian Swap */
116 /* End of for */
117
118 /* MD5 hash computation */
119 /* Initialize the working variables */
120 a = pMD5_CTX->HashValue[0];
121 b = pMD5_CTX->HashValue[1];
122 c = pMD5_CTX->HashValue[2];
123 d = pMD5_CTX->HashValue[3];
124
125 /*
126 * Round 1
127 * Let [abcd k s i] denote the operation
128 * a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s)
129 */
130 ROUND1(a, b, c, d, X[0], 7, 0xd76aa478); /* 1 */
131 ROUND1(d, a, b, c, X[1], 12, 0xe8c7b756); /* 2 */
132 ROUND1(c, d, a, b, X[2], 17, 0x242070db); /* 3 */
133 ROUND1(b, c, d, a, X[3], 22, 0xc1bdceee); /* 4 */
134 ROUND1(a, b, c, d, X[4], 7, 0xf57c0faf); /* 5 */
135 ROUND1(d, a, b, c, X[5], 12, 0x4787c62a); /* 6 */
136 ROUND1(c, d, a, b, X[6], 17, 0xa8304613); /* 7 */
137 ROUND1(b, c, d, a, X[7], 22, 0xfd469501); /* 8 */
138 ROUND1(a, b, c, d, X[8], 7, 0x698098d8); /* 9 */
139 ROUND1(d, a, b, c, X[9], 12, 0x8b44f7af); /* 10 */
140 ROUND1(c, d, a, b, X[10], 17, 0xffff5bb1); /* 11 */
141 ROUND1(b, c, d, a, X[11], 22, 0x895cd7be); /* 12 */
142 ROUND1(a, b, c, d, X[12], 7, 0x6b901122); /* 13 */
143 ROUND1(d, a, b, c, X[13], 12, 0xfd987193); /* 14 */
144 ROUND1(c, d, a, b, X[14], 17, 0xa679438e); /* 15 */
145 ROUND1(b, c, d, a, X[15], 22, 0x49b40821); /* 16 */
146
147 /*
148 * Round 2
149 * Let [abcd k s i] denote the operation
150 * a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s)
151 */
152 ROUND2(a, b, c, d, X[1], 5, 0xf61e2562); /* 17 */
153 ROUND2(d, a, b, c, X[6], 9, 0xc040b340); /* 18 */
154 ROUND2(c, d, a, b, X[11], 14, 0x265e5a51); /* 19 */
155 ROUND2(b, c, d, a, X[0], 20, 0xe9b6c7aa); /* 20 */
156 ROUND2(a, b, c, d, X[5], 5, 0xd62f105d); /* 21 */
157 ROUND2(d, a, b, c, X[10], 9, 0x2441453); /* 22 */
158 ROUND2(c, d, a, b, X[15], 14, 0xd8a1e681); /* 23 */
159 ROUND2(b, c, d, a, X[4], 20, 0xe7d3fbc8); /* 24 */
160 ROUND2(a, b, c, d, X[9], 5, 0x21e1cde6); /* 25 */
161 ROUND2(d, a, b, c, X[14], 9, 0xc33707d6); /* 26 */
162 ROUND2(c, d, a, b, X[3], 14, 0xf4d50d87); /* 27 */
163 ROUND2(b, c, d, a, X[8], 20, 0x455a14ed); /* 28 */
164 ROUND2(a, b, c, d, X[13], 5, 0xa9e3e905); /* 29 */
165 ROUND2(d, a, b, c, X[2], 9, 0xfcefa3f8); /* 30 */
166 ROUND2(c, d, a, b, X[7], 14, 0x676f02d9); /* 31 */
167 ROUND2(b, c, d, a, X[12], 20, 0x8d2a4c8a); /* 32 */
168
169 /*
170 * Round 3
171 * Let [abcd k s t] denote the operation
172 * a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s)
173 */
174 ROUND3(a, b, c, d, X[5], 4, 0xfffa3942); /* 33 */
175 ROUND3(d, a, b, c, X[8], 11, 0x8771f681); /* 34 */
176 ROUND3(c, d, a, b, X[11], 16, 0x6d9d6122); /* 35 */
177 ROUND3(b, c, d, a, X[14], 23, 0xfde5380c); /* 36 */
178 ROUND3(a, b, c, d, X[1], 4, 0xa4beea44); /* 37 */
179 ROUND3(d, a, b, c, X[4], 11, 0x4bdecfa9); /* 38 */
180 ROUND3(c, d, a, b, X[7], 16, 0xf6bb4b60); /* 39 */
181 ROUND3(b, c, d, a, X[10], 23, 0xbebfbc70); /* 40 */
182 ROUND3(a, b, c, d, X[13], 4, 0x289b7ec6); /* 41 */
183 ROUND3(d, a, b, c, X[0], 11, 0xeaa127fa); /* 42 */
184 ROUND3(c, d, a, b, X[3], 16, 0xd4ef3085); /* 43 */
185 ROUND3(b, c, d, a, X[6], 23, 0x4881d05); /* 44 */
186 ROUND3(a, b, c, d, X[9], 4, 0xd9d4d039); /* 45 */
187 ROUND3(d, a, b, c, X[12], 11, 0xe6db99e5); /* 46 */
188 ROUND3(c, d, a, b, X[15], 16, 0x1fa27cf8); /* 47 */
189 ROUND3(b, c, d, a, X[2], 23, 0xc4ac5665); /* 48 */
190
191 /*
192 * Round 4
193 * Let [abcd k s t] denote the operation
194 * a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s)
195 */
196 ROUND4(a, b, c, d, X[0], 6, 0xf4292244); /* 49 */
197 ROUND4(d, a, b, c, X[7], 10, 0x432aff97); /* 50 */
198 ROUND4(c, d, a, b, X[14], 15, 0xab9423a7); /* 51 */
199 ROUND4(b, c, d, a, X[5], 21, 0xfc93a039); /* 52 */
200 ROUND4(a, b, c, d, X[12], 6, 0x655b59c3); /* 53 */
201 ROUND4(d, a, b, c, X[3], 10, 0x8f0ccc92); /* 54 */
202 ROUND4(c, d, a, b, X[10], 15, 0xffeff47d); /* 55 */
203 ROUND4(b, c, d, a, X[1], 21, 0x85845dd1); /* 56 */
204 ROUND4(a, b, c, d, X[8], 6, 0x6fa87e4f); /* 57 */
205 ROUND4(d, a, b, c, X[15], 10, 0xfe2ce6e0); /* 58 */
206 ROUND4(c, d, a, b, X[6], 15, 0xa3014314); /* 59 */
207 ROUND4(b, c, d, a, X[13], 21, 0x4e0811a1); /* 60 */
208 ROUND4(a, b, c, d, X[4], 6, 0xf7537e82); /* 61 */
209 ROUND4(d, a, b, c, X[11], 10, 0xbd3af235); /* 62 */
210 ROUND4(c, d, a, b, X[2], 15, 0x2ad7d2bb); /* 63 */
211 ROUND4(b, c, d, a, X[9], 21, 0xeb86d391); /* 64 */
212
213 /* Compute the i^th intermediate hash value H^(i) */
214 pMD5_CTX->HashValue[0] += a;
215 pMD5_CTX->HashValue[1] += b;
216 pMD5_CTX->HashValue[2] += c;
217 pMD5_CTX->HashValue[3] += d;
218
219 NdisZeroMemory(pMD5_CTX->Block, MD5_BLOCK_SIZE);
220 pMD5_CTX->BlockLen = 0;
221} /* End of MD5_Hash */
222
223/*
224========================================================================
225Routine Description:
226 The message is appended to block. If block size > 64 bytes, the MD5_Hash
227will be called.
228
229Arguments:
230 pMD5_CTX Pointer to struct rt_md5_ctx_struc
231 message Message context
232 messageLen The length of message in bytes
233
234Return Value:
235 None
236
237Note:
238 None
239========================================================================
240*/
241void MD5_Append(struct rt_md5_ctx_struc *pMD5_CTX,
242 IN const u8 Message[], u32 MessageLen)
243{
244 u32 appendLen = 0;
245 u32 diffLen = 0;
246
247 while (appendLen != MessageLen) {
248 diffLen = MessageLen - appendLen;
249 if ((pMD5_CTX->BlockLen + diffLen) < MD5_BLOCK_SIZE) {
250 NdisMoveMemory(pMD5_CTX->Block + pMD5_CTX->BlockLen,
251 Message + appendLen, diffLen);
252 pMD5_CTX->BlockLen += diffLen;
253 appendLen += diffLen;
254 } else {
255 NdisMoveMemory(pMD5_CTX->Block + pMD5_CTX->BlockLen,
256 Message + appendLen,
257 MD5_BLOCK_SIZE - pMD5_CTX->BlockLen);
258 appendLen += (MD5_BLOCK_SIZE - pMD5_CTX->BlockLen);
259 pMD5_CTX->BlockLen = MD5_BLOCK_SIZE;
260 MD5_Hash(pMD5_CTX);
261 } /* End of if */
262 } /* End of while */
263 pMD5_CTX->MessageLen += MessageLen;
264} /* End of MD5_Append */
265
266/*
267========================================================================
268Routine Description:
269 1. Append bit 1 to end of the message
270 2. Append the length of message in rightmost 64 bits
271 3. Transform the Hash Value to digest message
272
273Arguments:
274 pMD5_CTX Pointer to struct rt_md5_ctx_struc
275
276Return Value:
277 digestMessage Digest message
278
279Note:
280 None
281========================================================================
282*/
283void MD5_End(struct rt_md5_ctx_struc *pMD5_CTX, u8 DigestMessage[])
284{
285 u32 index;
286 u64 message_length_bits;
287
288 /* append 1 bits to end of the message */
289 NdisFillMemory(pMD5_CTX->Block + pMD5_CTX->BlockLen, 1, 0x80);
290
291 /* 55 = 64 - 8 - 1: append 1 bit(1 byte) and message length (8 bytes) */
292 if (pMD5_CTX->BlockLen > 55)
293 MD5_Hash(pMD5_CTX);
294 /* End of if */
295
296 /* Append the length of message in rightmost 64 bits */
297 message_length_bits = pMD5_CTX->MessageLen * 8;
298 message_length_bits = cpu2le64(message_length_bits);
299 NdisMoveMemory(&pMD5_CTX->Block[56], &message_length_bits, 8);
300 MD5_Hash(pMD5_CTX);
301
302 /* Return message digest, transform the u32 hash value to bytes */
303 for (index = 0; index < 4; index++)
304 pMD5_CTX->HashValue[index] =
305 cpu2le32(pMD5_CTX->HashValue[index]);
306 /* End of for */
307 NdisMoveMemory(DigestMessage, pMD5_CTX->HashValue, MD5_DIGEST_SIZE);
308} /* End of MD5_End */
309
310/*
311========================================================================
312Routine Description:
313 MD5 algorithm
314
315Arguments:
316 message Message context
317 messageLen The length of message in bytes
318
319Return Value:
320 digestMessage Digest message
321
322Note:
323 None
324========================================================================
325*/
326void RT_MD5(IN const u8 Message[],
327 u32 MessageLen, u8 DigestMessage[])
328{
329 struct rt_md5_ctx_struc md5_ctx;
330
331 NdisZeroMemory(&md5_ctx, sizeof(struct rt_md5_ctx_struc));
332 MD5_Init(&md5_ctx);
333 MD5_Append(&md5_ctx, Message, MessageLen);
334 MD5_End(&md5_ctx, DigestMessage);
335} /* End of RT_MD5 */
336
337#endif /* MD5_SUPPORT */
338
339/* End of crypt_md5.c */
diff --git a/drivers/staging/rt2860/common/crypt_sha2.c b/drivers/staging/rt2860/common/crypt_sha2.c
deleted file mode 100644
index fa83fb287fe..00000000000
--- a/drivers/staging/rt2860/common/crypt_sha2.c
+++ /dev/null
@@ -1,269 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************/
26
27#include "../crypt_sha2.h"
28
29/* Basic operations */
30#define SHR(x,n) (x >> n) /* SHR(x)^n, right shift n bits , x is w-bit word, 0 <= n <= w */
31#define ROTR(x,n,w) ((x >> n) | (x << (w - n))) /* ROTR(x)^n, circular right shift n bits , x is w-bit word, 0 <= n <= w */
32#define ROTL(x,n,w) ((x << n) | (x >> (w - n))) /* ROTL(x)^n, circular left shift n bits , x is w-bit word, 0 <= n <= w */
33#define ROTR32(x,n) ROTR(x,n,32) /* 32 bits word */
34#define ROTL32(x,n) ROTL(x,n,32) /* 32 bits word */
35
36/* Basic functions */
37#define Ch(x,y,z) ((x & y) ^ ((~x) & z))
38#define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z))
39#define Parity(x,y,z) (x ^ y ^ z)
40
41#ifdef SHA1_SUPPORT
42/* SHA1 constants */
43#define SHA1_MASK 0x0000000f
44static const u32 SHA1_K[4] = {
45 0x5a827999UL, 0x6ed9eba1UL, 0x8f1bbcdcUL, 0xca62c1d6UL
46};
47
48static const u32 SHA1_DefaultHashValue[5] = {
49 0x67452301UL, 0xefcdab89UL, 0x98badcfeUL, 0x10325476UL, 0xc3d2e1f0UL
50};
51
52/*
53========================================================================
54Routine Description:
55 Initial struct rt_sha1_ctx
56
57Arguments:
58 pSHA_CTX Pointer to struct rt_sha1_ctx
59
60Return Value:
61 None
62
63Note:
64 None
65========================================================================
66*/
67void RT_SHA1_Init(struct rt_sha1_ctx *pSHA_CTX)
68{
69 NdisMoveMemory(pSHA_CTX->HashValue, SHA1_DefaultHashValue,
70 sizeof(SHA1_DefaultHashValue));
71 NdisZeroMemory(pSHA_CTX->Block, SHA1_BLOCK_SIZE);
72 pSHA_CTX->MessageLen = 0;
73 pSHA_CTX->BlockLen = 0;
74} /* End of RT_SHA1_Init */
75
76/*
77========================================================================
78Routine Description:
79 SHA1 computation for one block (512 bits)
80
81Arguments:
82 pSHA_CTX Pointer to struct rt_sha1_ctx
83
84Return Value:
85 None
86
87Note:
88 None
89========================================================================
90*/
91void SHA1_Hash(struct rt_sha1_ctx *pSHA_CTX)
92{
93 u32 W_i, t, s;
94 u32 W[16];
95 u32 a, b, c, d, e, T, f_t = 0;
96
97 /* Prepare the message schedule, {W_i}, 0 < t < 15 */
98 NdisMoveMemory(W, pSHA_CTX->Block, SHA1_BLOCK_SIZE);
99 for (W_i = 0; W_i < 16; W_i++)
100 W[W_i] = cpu2be32(W[W_i]); /* Endian Swap */
101 /* End of for */
102
103 /* SHA256 hash computation */
104 /* Initialize the working variables */
105 a = pSHA_CTX->HashValue[0];
106 b = pSHA_CTX->HashValue[1];
107 c = pSHA_CTX->HashValue[2];
108 d = pSHA_CTX->HashValue[3];
109 e = pSHA_CTX->HashValue[4];
110
111 /* 80 rounds */
112 for (t = 0; t < 80; t++) {
113 s = t & SHA1_MASK;
114 if (t > 15) { /* Prepare the message schedule, {W_i}, 16 < t < 79 */
115 W[s] =
116 (W[(s + 13) & SHA1_MASK]) ^ (W[(s + 8) & SHA1_MASK])
117 ^ (W[(s + 2) & SHA1_MASK]) ^ W[s];
118 W[s] = ROTL32(W[s], 1);
119 } /* End of if */
120 switch (t / 20) {
121 case 0:
122 f_t = Ch(b, c, d);
123 break;
124 case 1:
125 f_t = Parity(b, c, d);
126 break;
127 case 2:
128 f_t = Maj(b, c, d);
129 break;
130 case 3:
131 f_t = Parity(b, c, d);
132 break;
133 } /* End of switch */
134 T = ROTL32(a, 5) + f_t + e + SHA1_K[t / 20] + W[s];
135 e = d;
136 d = c;
137 c = ROTL32(b, 30);
138 b = a;
139 a = T;
140 } /* End of for */
141
142 /* Compute the i^th intermediate hash value H^(i) */
143 pSHA_CTX->HashValue[0] += a;
144 pSHA_CTX->HashValue[1] += b;
145 pSHA_CTX->HashValue[2] += c;
146 pSHA_CTX->HashValue[3] += d;
147 pSHA_CTX->HashValue[4] += e;
148
149 NdisZeroMemory(pSHA_CTX->Block, SHA1_BLOCK_SIZE);
150 pSHA_CTX->BlockLen = 0;
151} /* End of SHA1_Hash */
152
153/*
154========================================================================
155Routine Description:
156 The message is appended to block. If block size > 64 bytes, the SHA1_Hash
157will be called.
158
159Arguments:
160 pSHA_CTX Pointer to struct rt_sha1_ctx
161 message Message context
162 messageLen The length of message in bytes
163
164Return Value:
165 None
166
167Note:
168 None
169========================================================================
170*/
171void SHA1_Append(struct rt_sha1_ctx *pSHA_CTX,
172 IN const u8 Message[], u32 MessageLen)
173{
174 u32 appendLen = 0;
175 u32 diffLen = 0;
176
177 while (appendLen != MessageLen) {
178 diffLen = MessageLen - appendLen;
179 if ((pSHA_CTX->BlockLen + diffLen) < SHA1_BLOCK_SIZE) {
180 NdisMoveMemory(pSHA_CTX->Block + pSHA_CTX->BlockLen,
181 Message + appendLen, diffLen);
182 pSHA_CTX->BlockLen += diffLen;
183 appendLen += diffLen;
184 } else {
185 NdisMoveMemory(pSHA_CTX->Block + pSHA_CTX->BlockLen,
186 Message + appendLen,
187 SHA1_BLOCK_SIZE - pSHA_CTX->BlockLen);
188 appendLen += (SHA1_BLOCK_SIZE - pSHA_CTX->BlockLen);
189 pSHA_CTX->BlockLen = SHA1_BLOCK_SIZE;
190 SHA1_Hash(pSHA_CTX);
191 } /* End of if */
192 } /* End of while */
193 pSHA_CTX->MessageLen += MessageLen;
194} /* End of SHA1_Append */
195
196/*
197========================================================================
198Routine Description:
199 1. Append bit 1 to end of the message
200 2. Append the length of message in rightmost 64 bits
201 3. Transform the Hash Value to digest message
202
203Arguments:
204 pSHA_CTX Pointer to struct rt_sha1_ctx
205
206Return Value:
207 digestMessage Digest message
208
209Note:
210 None
211========================================================================
212*/
213void SHA1_End(struct rt_sha1_ctx *pSHA_CTX, u8 DigestMessage[])
214{
215 u32 index;
216 u64 message_length_bits;
217
218 /* Append bit 1 to end of the message */
219 NdisFillMemory(pSHA_CTX->Block + pSHA_CTX->BlockLen, 1, 0x80);
220
221 /* 55 = 64 - 8 - 1: append 1 bit(1 byte) and message length (8 bytes) */
222 if (pSHA_CTX->BlockLen > 55)
223 SHA1_Hash(pSHA_CTX);
224 /* End of if */
225
226 /* Append the length of message in rightmost 64 bits */
227 message_length_bits = pSHA_CTX->MessageLen * 8;
228 message_length_bits = cpu2be64(message_length_bits);
229 NdisMoveMemory(&pSHA_CTX->Block[56], &message_length_bits, 8);
230 SHA1_Hash(pSHA_CTX);
231
232 /* Return message digest, transform the u32 hash value to bytes */
233 for (index = 0; index < 5; index++)
234 pSHA_CTX->HashValue[index] =
235 cpu2be32(pSHA_CTX->HashValue[index]);
236 /* End of for */
237 NdisMoveMemory(DigestMessage, pSHA_CTX->HashValue, SHA1_DIGEST_SIZE);
238} /* End of SHA1_End */
239
240/*
241========================================================================
242Routine Description:
243 SHA1 algorithm
244
245Arguments:
246 message Message context
247 messageLen The length of message in bytes
248
249Return Value:
250 digestMessage Digest message
251
252Note:
253 None
254========================================================================
255*/
256void RT_SHA1(IN const u8 Message[],
257 u32 MessageLen, u8 DigestMessage[])
258{
259
260 struct rt_sha1_ctx sha_ctx;
261
262 NdisZeroMemory(&sha_ctx, sizeof(struct rt_sha1_ctx));
263 RT_SHA1_Init(&sha_ctx);
264 SHA1_Append(&sha_ctx, Message, MessageLen);
265 SHA1_End(&sha_ctx, DigestMessage);
266} /* End of RT_SHA1 */
267#endif /* SHA1_SUPPORT */
268
269/* End of crypt_sha2.c */
diff --git a/drivers/staging/rt2860/common/dfs.c b/drivers/staging/rt2860/common/dfs.c
deleted file mode 100644
index 71cbb266524..00000000000
--- a/drivers/staging/rt2860/common/dfs.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 ap_dfs.c
29
30 Abstract:
31 Support DFS function.
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#include "../rt_config.h"
39
40/*
41 ========================================================================
42
43 Routine Description:
44 Radar channel check routine
45
46 Arguments:
47 pAd Pointer to our adapter
48
49 Return Value:
50 TRUE need to do radar detect
51 FALSE need not to do radar detect
52
53 ========================================================================
54*/
55BOOLEAN RadarChannelCheck(struct rt_rtmp_adapter *pAd, u8 Ch)
56{
57 int i;
58 BOOLEAN result = FALSE;
59
60 for (i = 0; i < pAd->ChannelListNum; i++) {
61 if (Ch == pAd->ChannelList[i].Channel) {
62 result = pAd->ChannelList[i].DfsReq;
63 break;
64 }
65 }
66
67 return result;
68}
diff --git a/drivers/staging/rt2860/common/ee_efuse.c b/drivers/staging/rt2860/common/ee_efuse.c
deleted file mode 100644
index fed0ba45227..00000000000
--- a/drivers/staging/rt2860/common/ee_efuse.c
+++ /dev/null
@@ -1,351 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 ee_efuse.c
29
30 Abstract:
31 Miniport generic portion header file
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#include "../rt_config.h"
39
40#define EFUSE_USAGE_MAP_START 0x2d0
41#define EFUSE_USAGE_MAP_END 0x2fc
42#define EFUSE_USAGE_MAP_SIZE 45
43
44#define EFUSE_EEPROM_DEFULT_FILE "RT30xxEEPROM.bin"
45#define MAX_EEPROM_BIN_FILE_SIZE 1024
46
47#define EFUSE_TAG 0x2fe
48
49typedef union _EFUSE_CTRL_STRUC {
50 struct {
51 u32 EFSROM_AOUT:6;
52 u32 EFSROM_MODE:2;
53 u32 EFSROM_LDO_OFF_TIME:6;
54 u32 EFSROM_LDO_ON_TIME:2;
55 u32 EFSROM_AIN:10;
56 u32 RESERVED:4;
57 u32 EFSROM_KICK:1;
58 u32 SEL_EFUSE:1;
59 } field;
60 u32 word;
61} EFUSE_CTRL_STRUC, *PEFUSE_CTRL_STRUC;
62
63/*
64========================================================================
65
66 Routine Description:
67
68 Arguments:
69
70 Return Value:
71
72 Note:
73
74========================================================================
75*/
76u8 eFuseReadRegisters(struct rt_rtmp_adapter *pAd,
77 u16 Offset, u16 Length, u16 * pData)
78{
79 EFUSE_CTRL_STRUC eFuseCtrlStruc;
80 int i;
81 u16 efuseDataOffset;
82 u32 data;
83
84 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
85
86 /*Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. */
87 /*Use the eeprom logical address and covert to address to block number */
88 eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
89
90 /*Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 0. */
91 eFuseCtrlStruc.field.EFSROM_MODE = 0;
92
93 /*Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure. */
94 eFuseCtrlStruc.field.EFSROM_KICK = 1;
95
96 NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
97 RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
98
99 /*Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. */
100 i = 0;
101 while (i < 500) {
102 /*rtmp.HwMemoryReadDword(EFUSE_CTRL, (DWORD *) &eFuseCtrlStruc, 4); */
103 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
104 if (eFuseCtrlStruc.field.EFSROM_KICK == 0) {
105 break;
106 }
107 RTMPusecDelay(2);
108 i++;
109 }
110
111 /*if EFSROM_AOUT is not found in physical address, write 0xffff */
112 if (eFuseCtrlStruc.field.EFSROM_AOUT == 0x3f) {
113 for (i = 0; i < Length / 2; i++)
114 *(pData + 2 * i) = 0xffff;
115 } else {
116 /*Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x590-0x59C) */
117 efuseDataOffset = EFUSE_DATA3 - (Offset & 0xC);
118 /*data hold 4 bytes data. */
119 /*In RTMP_IO_READ32 will automatically execute 32-bytes swapping */
120 RTMP_IO_READ32(pAd, efuseDataOffset, &data);
121 /*Decide the upper 2 bytes or the bottom 2 bytes. */
122 /* Little-endian S | S Big-endian */
123 /* addr 3 2 1 0 | 0 1 2 3 */
124 /* Ori-V D C B A | A B C D */
125 /*After swapping */
126 /* D C B A | D C B A */
127 /*Return 2-bytes */
128 /*The return byte statrs from S. Therefore, the little-endian will return BA, the Big-endian will return DC. */
129 /*For returning the bottom 2 bytes, the Big-endian should shift right 2-bytes. */
130 data = data >> (8 * (Offset & 0x3));
131
132 NdisMoveMemory(pData, &data, Length);
133 }
134
135 return (u8)eFuseCtrlStruc.field.EFSROM_AOUT;
136
137}
138
139/*
140========================================================================
141
142 Routine Description:
143
144 Arguments:
145
146 Return Value:
147
148 Note:
149
150========================================================================
151*/
152void eFusePhysicalReadRegisters(struct rt_rtmp_adapter *pAd,
153 u16 Offset,
154 u16 Length, u16 * pData)
155{
156 EFUSE_CTRL_STRUC eFuseCtrlStruc;
157 int i;
158 u16 efuseDataOffset;
159 u32 data;
160
161 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
162
163 /*Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. */
164 eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0;
165
166 /*Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 1. */
167 /*Read in physical view */
168 eFuseCtrlStruc.field.EFSROM_MODE = 1;
169
170 /*Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure. */
171 eFuseCtrlStruc.field.EFSROM_KICK = 1;
172
173 NdisMoveMemory(&data, &eFuseCtrlStruc, 4);
174 RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data);
175
176 /*Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. */
177 i = 0;
178 while (i < 500) {
179 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word);
180 if (eFuseCtrlStruc.field.EFSROM_KICK == 0)
181 break;
182 RTMPusecDelay(2);
183 i++;
184 }
185
186 /*Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590) */
187 /*Because the size of each EFUSE_DATA is 4 Bytes, the size of address of each is 2 bits. */
188 /*The previous 2 bits is the EFUSE_DATA number, the last 2 bits is used to decide which bytes */
189 /*Decide which EFUSE_DATA to read */
190 /*590:F E D C */
191 /*594:B A 9 8 */
192 /*598:7 6 5 4 */
193 /*59C:3 2 1 0 */
194 efuseDataOffset = EFUSE_DATA3 - (Offset & 0xC);
195
196 RTMP_IO_READ32(pAd, efuseDataOffset, &data);
197
198 data = data >> (8 * (Offset & 0x3));
199
200 NdisMoveMemory(pData, &data, Length);
201
202}
203
204/*
205========================================================================
206
207 Routine Description:
208
209 Arguments:
210
211 Return Value:
212
213 Note:
214
215========================================================================
216*/
217static void eFuseReadPhysical(struct rt_rtmp_adapter *pAd,
218 u16 *lpInBuffer,
219 unsigned long nInBufferSize,
220 u16 *lpOutBuffer, unsigned long nOutBufferSize)
221{
222 u16 *pInBuf = (u16 *) lpInBuffer;
223 u16 *pOutBuf = (u16 *) lpOutBuffer;
224
225 u16 Offset = pInBuf[0]; /*addr */
226 u16 Length = pInBuf[1]; /*length */
227 int i;
228
229 for (i = 0; i < Length; i += 2) {
230 eFusePhysicalReadRegisters(pAd, Offset + i, 2, &pOutBuf[i / 2]);
231 }
232}
233
234/*
235========================================================================
236
237 Routine Description:
238
239 Arguments:
240
241 Return Value:
242
243 Note:
244
245========================================================================
246*/
247int set_eFuseGetFreeBlockCount_Proc(struct rt_rtmp_adapter *pAd, char *arg)
248{
249 u16 i;
250 u16 LogicalAddress;
251 u16 efusefreenum = 0;
252 if (!pAd->bUseEfuse)
253 return FALSE;
254 for (i = EFUSE_USAGE_MAP_START; i <= EFUSE_USAGE_MAP_END; i += 2) {
255 eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
256 if ((LogicalAddress & 0xff) == 0) {
257 efusefreenum = (u8)(EFUSE_USAGE_MAP_END - i + 1);
258 break;
259 } else if (((LogicalAddress >> 8) & 0xff) == 0) {
260 efusefreenum = (u8)(EFUSE_USAGE_MAP_END - i);
261 break;
262 }
263
264 if (i == EFUSE_USAGE_MAP_END)
265 efusefreenum = 0;
266 }
267 printk(KERN_DEBUG "efuseFreeNumber is %d\n", efusefreenum);
268 return TRUE;
269}
270
271int set_eFusedump_Proc(struct rt_rtmp_adapter *pAd, char *arg)
272{
273 u16 InBuf[3];
274 int i = 0;
275 if (!pAd->bUseEfuse)
276 return FALSE;
277
278 printk(KERN_DEBUG "Block 0: ");
279
280 for (i = 0; i < EFUSE_USAGE_MAP_END / 2; i++) {
281 InBuf[0] = 2 * i;
282 InBuf[1] = 2;
283 InBuf[2] = 0x0;
284
285 eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
286 if (i && i % 4 == 0) {
287 printk(KERN_CONT "\n");
288 printk(KERN_DEBUG "Block %x:", i / 8);
289 }
290 printk(KERN_CONT "%04x ", InBuf[2]);
291 }
292 printk(KERN_CONT "\n");
293
294 return TRUE;
295}
296
297int rtmp_ee_efuse_read16(struct rt_rtmp_adapter *pAd,
298 u16 Offset, u16 * pValue)
299{
300 eFuseReadRegisters(pAd, Offset, 2, pValue);
301 return (*pValue);
302}
303
304int RtmpEfuseSupportCheck(struct rt_rtmp_adapter *pAd)
305{
306 u16 value;
307
308 if (IS_RT30xx(pAd)) {
309 eFusePhysicalReadRegisters(pAd, EFUSE_TAG, 2, &value);
310 pAd->EFuseTag = (value & 0xff);
311 }
312 return 0;
313}
314
315void eFuseGetFreeBlockCount(struct rt_rtmp_adapter *pAd, u32 *EfuseFreeBlock)
316{
317 u16 i;
318 u16 LogicalAddress;
319 if (!pAd->bUseEfuse) {
320 DBGPRINT(RT_DEBUG_TRACE,
321 ("eFuseGetFreeBlockCount Only supports efuse Mode\n"));
322 return;
323 }
324 for (i = EFUSE_USAGE_MAP_START; i <= EFUSE_USAGE_MAP_END; i += 2) {
325 eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress);
326 if ((LogicalAddress & 0xff) == 0) {
327 *EfuseFreeBlock = (u8)(EFUSE_USAGE_MAP_END - i + 1);
328 break;
329 } else if (((LogicalAddress >> 8) & 0xff) == 0) {
330 *EfuseFreeBlock = (u8)(EFUSE_USAGE_MAP_END - i);
331 break;
332 }
333
334 if (i == EFUSE_USAGE_MAP_END)
335 *EfuseFreeBlock = 0;
336 }
337 DBGPRINT(RT_DEBUG_TRACE,
338 ("eFuseGetFreeBlockCount is 0x%x\n", *EfuseFreeBlock));
339}
340
341int eFuse_init(struct rt_rtmp_adapter *pAd)
342{
343 u32 EfuseFreeBlock = 0;
344 DBGPRINT(RT_DEBUG_ERROR,
345 ("NVM is Efuse and its size =%x[%x-%x] \n",
346 EFUSE_USAGE_MAP_SIZE, EFUSE_USAGE_MAP_START,
347 EFUSE_USAGE_MAP_END));
348 eFuseGetFreeBlockCount(pAd, &EfuseFreeBlock);
349
350 return 0;
351}
diff --git a/drivers/staging/rt2860/common/ee_prom.c b/drivers/staging/rt2860/common/ee_prom.c
deleted file mode 100644
index 2083740a844..00000000000
--- a/drivers/staging/rt2860/common/ee_prom.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 ee_prom.c
29
30 Abstract:
31 Miniport generic portion header file
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#include "../rt_config.h"
39
40/* IRQL = PASSIVE_LEVEL */
41static inline void RaiseClock(struct rt_rtmp_adapter *pAd, u32 * x)
42{
43 *x = *x | EESK;
44 RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x);
45 RTMPusecDelay(1); /* Max frequency = 1MHz in Spec. definition */
46}
47
48/* IRQL = PASSIVE_LEVEL */
49static inline void LowerClock(struct rt_rtmp_adapter *pAd, u32 * x)
50{
51 *x = *x & ~EESK;
52 RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x);
53 RTMPusecDelay(1);
54}
55
56/* IRQL = PASSIVE_LEVEL */
57static inline u16 ShiftInBits(struct rt_rtmp_adapter *pAd)
58{
59 u32 x, i;
60 u16 data = 0;
61
62 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
63
64 x &= ~(EEDO | EEDI);
65
66 for (i = 0; i < 16; i++) {
67 data = data << 1;
68 RaiseClock(pAd, &x);
69
70 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
71 LowerClock(pAd, &x); /*prevent read failed */
72
73 x &= ~(EEDI);
74 if (x & EEDO)
75 data |= 1;
76 }
77
78 return data;
79}
80
81/* IRQL = PASSIVE_LEVEL */
82static inline void ShiftOutBits(struct rt_rtmp_adapter *pAd,
83 u16 data, u16 count)
84{
85 u32 x, mask;
86
87 mask = 0x01 << (count - 1);
88 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
89
90 x &= ~(EEDO | EEDI);
91
92 do {
93 x &= ~EEDI;
94 if (data & mask)
95 x |= EEDI;
96
97 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
98
99 RaiseClock(pAd, &x);
100 LowerClock(pAd, &x);
101
102 mask = mask >> 1;
103 } while (mask);
104
105 x &= ~EEDI;
106 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
107}
108
109/* IRQL = PASSIVE_LEVEL */
110static inline void EEpromCleanup(struct rt_rtmp_adapter *pAd)
111{
112 u32 x;
113
114 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
115
116 x &= ~(EECS | EEDI);
117 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
118
119 RaiseClock(pAd, &x);
120 LowerClock(pAd, &x);
121}
122
123static inline void EWEN(struct rt_rtmp_adapter *pAd)
124{
125 u32 x;
126
127 /* reset bits and set EECS */
128 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
129 x &= ~(EEDI | EEDO | EESK);
130 x |= EECS;
131 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
132
133 /* kick a pulse */
134 RaiseClock(pAd, &x);
135 LowerClock(pAd, &x);
136
137 /* output the read_opcode and six pulse in that order */
138 ShiftOutBits(pAd, EEPROM_EWEN_OPCODE, 5);
139 ShiftOutBits(pAd, 0, 6);
140
141 EEpromCleanup(pAd);
142}
143
144static inline void EWDS(struct rt_rtmp_adapter *pAd)
145{
146 u32 x;
147
148 /* reset bits and set EECS */
149 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
150 x &= ~(EEDI | EEDO | EESK);
151 x |= EECS;
152 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
153
154 /* kick a pulse */
155 RaiseClock(pAd, &x);
156 LowerClock(pAd, &x);
157
158 /* output the read_opcode and six pulse in that order */
159 ShiftOutBits(pAd, EEPROM_EWDS_OPCODE, 5);
160 ShiftOutBits(pAd, 0, 6);
161
162 EEpromCleanup(pAd);
163}
164
165/* IRQL = PASSIVE_LEVEL */
166int rtmp_ee_prom_read16(struct rt_rtmp_adapter *pAd,
167 u16 Offset, u16 * pValue)
168{
169 u32 x;
170 u16 data;
171
172 Offset /= 2;
173 /* reset bits and set EECS */
174 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
175 x &= ~(EEDI | EEDO | EESK);
176 x |= EECS;
177 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
178
179 /* patch can not access e-Fuse issue */
180 if (!(IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) {
181 /* kick a pulse */
182 RaiseClock(pAd, &x);
183 LowerClock(pAd, &x);
184 }
185 /* output the read_opcode and register number in that order */
186 ShiftOutBits(pAd, EEPROM_READ_OPCODE, 3);
187 ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
188
189 /* Now read the data (16 bits) in from the selected EEPROM word */
190 data = ShiftInBits(pAd);
191
192 EEpromCleanup(pAd);
193
194 *pValue = data;
195
196 return NDIS_STATUS_SUCCESS;
197}
diff --git a/drivers/staging/rt2860/common/eeprom.c b/drivers/staging/rt2860/common/eeprom.c
deleted file mode 100644
index 94670076d32..00000000000
--- a/drivers/staging/rt2860/common/eeprom.c
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 eeprom.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36*/
37#include "../rt_config.h"
38
39int RtmpChipOpsEepromHook(struct rt_rtmp_adapter *pAd, int infType)
40{
41 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
42#ifdef RT30xx
43#ifdef RTMP_EFUSE_SUPPORT
44 u32 eFuseCtrl, MacCsr0;
45 int index;
46
47 index = 0;
48 do {
49 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
50 pAd->MACVersion = MacCsr0;
51
52 if ((pAd->MACVersion != 0x00)
53 && (pAd->MACVersion != 0xFFFFFFFF))
54 break;
55
56 RTMPusecDelay(10);
57 } while (index++ < 100);
58
59 pAd->bUseEfuse = FALSE;
60 RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrl);
61 pAd->bUseEfuse = ((eFuseCtrl & 0x80000000) == 0x80000000) ? 1 : 0;
62 if (pAd->bUseEfuse) {
63 pChipOps->eeinit = eFuse_init;
64 pChipOps->eeread = rtmp_ee_efuse_read16;
65 return 0;
66 } else
67 DBGPRINT(RT_DEBUG_TRACE, ("NVM is EEPROM\n"));
68#endif /* RTMP_EFUSE_SUPPORT // */
69#endif /* RT30xx // */
70
71 switch (infType) {
72#ifdef RTMP_PCI_SUPPORT
73 case RTMP_DEV_INF_PCI:
74 pChipOps->eeinit = NULL;
75 pChipOps->eeread = rtmp_ee_prom_read16;
76 break;
77#endif /* RTMP_PCI_SUPPORT // */
78#ifdef RTMP_USB_SUPPORT
79 case RTMP_DEV_INF_USB:
80 pChipOps->eeinit = NULL;
81 pChipOps->eeread = RTUSBReadEEPROM16;
82 break;
83#endif /* RTMP_USB_SUPPORT // */
84
85 default:
86 DBGPRINT(RT_DEBUG_ERROR, ("RtmpChipOpsEepromHook() failed!\n"));
87 break;
88 }
89
90 return 0;
91}
diff --git a/drivers/staging/rt2860/common/mlme.c b/drivers/staging/rt2860/common/mlme.c
deleted file mode 100644
index e48eac0f3a2..00000000000
--- a/drivers/staging/rt2860/common/mlme.c
+++ /dev/null
@@ -1,6068 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 mlme.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John Chang 2004-08-25 Modify from RT2500 code base
36 John Chang 2004-09-06 modified for RT2600
37*/
38
39#include "../rt_config.h"
40#include <stdarg.h>
41#include <linux/kernel.h>
42
43u8 CISCO_OUI[] = { 0x00, 0x40, 0x96 };
44
45u8 WPA_OUI[] = { 0x00, 0x50, 0xf2, 0x01 };
46u8 RSN_OUI[] = { 0x00, 0x0f, 0xac };
47u8 WME_INFO_ELEM[] = { 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01 };
48u8 WME_PARM_ELEM[] = { 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01 };
49u8 Ccx2QosInfo[] = { 0x00, 0x40, 0x96, 0x04 };
50u8 RALINK_OUI[] = { 0x00, 0x0c, 0x43 };
51u8 BROADCOM_OUI[] = { 0x00, 0x90, 0x4c };
52u8 WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 };
53u8 PRE_N_HT_OUI[] = { 0x00, 0x90, 0x4c };
54
55u8 RateSwitchTable[] = {
56/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
57 0x11, 0x00, 0, 0, 0, /* Initial used item after association */
58 0x00, 0x00, 0, 40, 101,
59 0x01, 0x00, 1, 40, 50,
60 0x02, 0x00, 2, 35, 45,
61 0x03, 0x00, 3, 20, 45,
62 0x04, 0x21, 0, 30, 50,
63 0x05, 0x21, 1, 20, 50,
64 0x06, 0x21, 2, 20, 50,
65 0x07, 0x21, 3, 15, 50,
66 0x08, 0x21, 4, 15, 30,
67 0x09, 0x21, 5, 10, 25,
68 0x0a, 0x21, 6, 8, 25,
69 0x0b, 0x21, 7, 8, 25,
70 0x0c, 0x20, 12, 15, 30,
71 0x0d, 0x20, 13, 8, 20,
72 0x0e, 0x20, 14, 8, 20,
73 0x0f, 0x20, 15, 8, 25,
74 0x10, 0x22, 15, 8, 25,
75 0x11, 0x00, 0, 0, 0,
76 0x12, 0x00, 0, 0, 0,
77 0x13, 0x00, 0, 0, 0,
78 0x14, 0x00, 0, 0, 0,
79 0x15, 0x00, 0, 0, 0,
80 0x16, 0x00, 0, 0, 0,
81 0x17, 0x00, 0, 0, 0,
82 0x18, 0x00, 0, 0, 0,
83 0x19, 0x00, 0, 0, 0,
84 0x1a, 0x00, 0, 0, 0,
85 0x1b, 0x00, 0, 0, 0,
86 0x1c, 0x00, 0, 0, 0,
87 0x1d, 0x00, 0, 0, 0,
88 0x1e, 0x00, 0, 0, 0,
89 0x1f, 0x00, 0, 0, 0,
90};
91
92u8 RateSwitchTable11B[] = {
93/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
94 0x04, 0x03, 0, 0, 0, /* Initial used item after association */
95 0x00, 0x00, 0, 40, 101,
96 0x01, 0x00, 1, 40, 50,
97 0x02, 0x00, 2, 35, 45,
98 0x03, 0x00, 3, 20, 45,
99};
100
101u8 RateSwitchTable11BG[] = {
102/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
103 0x0a, 0x00, 0, 0, 0, /* Initial used item after association */
104 0x00, 0x00, 0, 40, 101,
105 0x01, 0x00, 1, 40, 50,
106 0x02, 0x00, 2, 35, 45,
107 0x03, 0x00, 3, 20, 45,
108 0x04, 0x10, 2, 20, 35,
109 0x05, 0x10, 3, 16, 35,
110 0x06, 0x10, 4, 10, 25,
111 0x07, 0x10, 5, 16, 25,
112 0x08, 0x10, 6, 10, 25,
113 0x09, 0x10, 7, 10, 13,
114};
115
116u8 RateSwitchTable11G[] = {
117/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
118 0x08, 0x00, 0, 0, 0, /* Initial used item after association */
119 0x00, 0x10, 0, 20, 101,
120 0x01, 0x10, 1, 20, 35,
121 0x02, 0x10, 2, 20, 35,
122 0x03, 0x10, 3, 16, 35,
123 0x04, 0x10, 4, 10, 25,
124 0x05, 0x10, 5, 16, 25,
125 0x06, 0x10, 6, 10, 25,
126 0x07, 0x10, 7, 10, 13,
127};
128
129u8 RateSwitchTable11N1S[] = {
130/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
131 0x0c, 0x0a, 0, 0, 0, /* Initial used item after association */
132 0x00, 0x00, 0, 40, 101,
133 0x01, 0x00, 1, 40, 50,
134 0x02, 0x00, 2, 25, 45,
135 0x03, 0x21, 0, 20, 35,
136 0x04, 0x21, 1, 20, 35,
137 0x05, 0x21, 2, 20, 35,
138 0x06, 0x21, 3, 15, 35,
139 0x07, 0x21, 4, 15, 30,
140 0x08, 0x21, 5, 10, 25,
141 0x09, 0x21, 6, 8, 14,
142 0x0a, 0x21, 7, 8, 14,
143 0x0b, 0x23, 7, 8, 14,
144};
145
146u8 RateSwitchTable11N2S[] = {
147/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
148 0x0e, 0x0c, 0, 0, 0, /* Initial used item after association */
149 0x00, 0x00, 0, 40, 101,
150 0x01, 0x00, 1, 40, 50,
151 0x02, 0x00, 2, 25, 45,
152 0x03, 0x21, 0, 20, 35,
153 0x04, 0x21, 1, 20, 35,
154 0x05, 0x21, 2, 20, 35,
155 0x06, 0x21, 3, 15, 35,
156 0x07, 0x21, 4, 15, 30,
157 0x08, 0x20, 11, 15, 30,
158 0x09, 0x20, 12, 15, 30,
159 0x0a, 0x20, 13, 8, 20,
160 0x0b, 0x20, 14, 8, 20,
161 0x0c, 0x20, 15, 8, 25,
162 0x0d, 0x22, 15, 8, 15,
163};
164
165u8 RateSwitchTable11N3S[] = {
166/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
167 0x0b, 0x00, 0, 0, 0, /* 0x0a, 0x00, 0, 0, 0, // Initial used item after association */
168 0x00, 0x21, 0, 30, 101,
169 0x01, 0x21, 1, 20, 50,
170 0x02, 0x21, 2, 20, 50,
171 0x03, 0x21, 3, 15, 50,
172 0x04, 0x21, 4, 15, 30,
173 0x05, 0x20, 11, 15, 30, /* Required by System-Alan @ 20080812 */
174 0x06, 0x20, 12, 15, 30, /* 0x05, 0x20, 12, 15, 30, */
175 0x07, 0x20, 13, 8, 20, /* 0x06, 0x20, 13, 8, 20, */
176 0x08, 0x20, 14, 8, 20, /* 0x07, 0x20, 14, 8, 20, */
177 0x09, 0x20, 15, 8, 25, /* 0x08, 0x20, 15, 8, 25, */
178 0x0a, 0x22, 15, 8, 25, /* 0x09, 0x22, 15, 8, 25, */
179};
180
181u8 RateSwitchTable11N2SForABand[] = {
182/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
183 0x0b, 0x09, 0, 0, 0, /* Initial used item after association */
184 0x00, 0x21, 0, 30, 101,
185 0x01, 0x21, 1, 20, 50,
186 0x02, 0x21, 2, 20, 50,
187 0x03, 0x21, 3, 15, 50,
188 0x04, 0x21, 4, 15, 30,
189 0x05, 0x21, 5, 15, 30,
190 0x06, 0x20, 12, 15, 30,
191 0x07, 0x20, 13, 8, 20,
192 0x08, 0x20, 14, 8, 20,
193 0x09, 0x20, 15, 8, 25,
194 0x0a, 0x22, 15, 8, 25,
195};
196
197u8 RateSwitchTable11N3SForABand[] = { /* 3*3 */
198/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
199 0x0b, 0x09, 0, 0, 0, /* Initial used item after association */
200 0x00, 0x21, 0, 30, 101,
201 0x01, 0x21, 1, 20, 50,
202 0x02, 0x21, 2, 20, 50,
203 0x03, 0x21, 3, 15, 50,
204 0x04, 0x21, 4, 15, 30,
205 0x05, 0x21, 5, 15, 30,
206 0x06, 0x20, 12, 15, 30,
207 0x07, 0x20, 13, 8, 20,
208 0x08, 0x20, 14, 8, 20,
209 0x09, 0x20, 15, 8, 25,
210 0x0a, 0x22, 15, 8, 25,
211};
212
213u8 RateSwitchTable11BGN1S[] = {
214/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
215 0x0c, 0x0a, 0, 0, 0, /* Initial used item after association */
216 0x00, 0x00, 0, 40, 101,
217 0x01, 0x00, 1, 40, 50,
218 0x02, 0x00, 2, 25, 45,
219 0x03, 0x21, 0, 20, 35,
220 0x04, 0x21, 1, 20, 35,
221 0x05, 0x21, 2, 20, 35,
222 0x06, 0x21, 3, 15, 35,
223 0x07, 0x21, 4, 15, 30,
224 0x08, 0x21, 5, 10, 25,
225 0x09, 0x21, 6, 8, 14,
226 0x0a, 0x21, 7, 8, 14,
227 0x0b, 0x23, 7, 8, 14,
228};
229
230u8 RateSwitchTable11BGN2S[] = {
231/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
232 0x0e, 0x0c, 0, 0, 0, /* Initial used item after association */
233 0x00, 0x00, 0, 40, 101,
234 0x01, 0x00, 1, 40, 50,
235 0x02, 0x00, 2, 25, 45,
236 0x03, 0x21, 0, 20, 35,
237 0x04, 0x21, 1, 20, 35,
238 0x05, 0x21, 2, 20, 35,
239 0x06, 0x21, 3, 15, 35,
240 0x07, 0x21, 4, 15, 30,
241 0x08, 0x20, 11, 15, 30,
242 0x09, 0x20, 12, 15, 30,
243 0x0a, 0x20, 13, 8, 20,
244 0x0b, 0x20, 14, 8, 20,
245 0x0c, 0x20, 15, 8, 25,
246 0x0d, 0x22, 15, 8, 15,
247};
248
249u8 RateSwitchTable11BGN3S[] = { /* 3*3 */
250/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
251 0x0a, 0x00, 0, 0, 0, /* Initial used item after association */
252 0x00, 0x21, 0, 30, 101, /*50 */
253 0x01, 0x21, 1, 20, 50,
254 0x02, 0x21, 2, 20, 50,
255 0x03, 0x21, 3, 20, 50,
256 0x04, 0x21, 4, 15, 50,
257 0x05, 0x20, 20, 15, 30,
258 0x06, 0x20, 21, 8, 20,
259 0x07, 0x20, 22, 8, 20,
260 0x08, 0x20, 23, 8, 25,
261 0x09, 0x22, 23, 8, 25,
262};
263
264u8 RateSwitchTable11BGN2SForABand[] = {
265/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
266 0x0b, 0x09, 0, 0, 0, /* Initial used item after association */
267 0x00, 0x21, 0, 30, 101, /*50 */
268 0x01, 0x21, 1, 20, 50,
269 0x02, 0x21, 2, 20, 50,
270 0x03, 0x21, 3, 15, 50,
271 0x04, 0x21, 4, 15, 30,
272 0x05, 0x21, 5, 15, 30,
273 0x06, 0x20, 12, 15, 30,
274 0x07, 0x20, 13, 8, 20,
275 0x08, 0x20, 14, 8, 20,
276 0x09, 0x20, 15, 8, 25,
277 0x0a, 0x22, 15, 8, 25,
278};
279
280u8 RateSwitchTable11BGN3SForABand[] = { /* 3*3 */
281/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */
282 0x0c, 0x09, 0, 0, 0, /* Initial used item after association */
283 0x00, 0x21, 0, 30, 101, /*50 */
284 0x01, 0x21, 1, 20, 50,
285 0x02, 0x21, 2, 20, 50,
286 0x03, 0x21, 3, 15, 50,
287 0x04, 0x21, 4, 15, 30,
288 0x05, 0x21, 5, 15, 30,
289 0x06, 0x21, 12, 15, 30,
290 0x07, 0x20, 20, 15, 30,
291 0x08, 0x20, 21, 8, 20,
292 0x09, 0x20, 22, 8, 20,
293 0x0a, 0x20, 23, 8, 25,
294 0x0b, 0x22, 23, 8, 25,
295};
296
297extern u8 OfdmRateToRxwiMCS[];
298/* since RT61 has better RX sensibility, we have to limit TX ACK rate not to exceed our normal data TX rate. */
299/* otherwise the WLAN peer may not be able to receive the ACK thus downgrade its data TX rate */
300unsigned long BasicRateMask[12] =
301 { 0xfffff001 /* 1-Mbps */ , 0xfffff003 /* 2 Mbps */ , 0xfffff007 /* 5.5 */ ,
3020xfffff00f /* 11 */ ,
303 0xfffff01f /* 6 */ , 0xfffff03f /* 9 */ , 0xfffff07f /* 12 */ ,
304 0xfffff0ff /* 18 */ ,
305 0xfffff1ff /* 24 */ , 0xfffff3ff /* 36 */ , 0xfffff7ff /* 48 */ ,
306 0xffffffff /* 54 */
307};
308
309u8 BROADCAST_ADDR[MAC_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
310u8 ZERO_MAC_ADDR[MAC_ADDR_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
311
312/* e.g. RssiSafeLevelForTxRate[RATE_36]" means if the current RSSI is greater than */
313/* this value, then it's quaranteed capable of operating in 36 mbps TX rate in */
314/* clean environment. */
315/* TxRate: 1 2 5.5 11 6 9 12 18 24 36 48 54 72 100 */
316char RssiSafeLevelForTxRate[] =
317 { -92, -91, -90, -87, -88, -86, -85, -83, -81, -78, -72, -71, -40, -40 };
318
319u8 RateIdToMbps[] = { 1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 72, 100 };
320u16 RateIdTo500Kbps[] =
321 { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 144, 200 };
322
323u8 SsidIe = IE_SSID;
324u8 SupRateIe = IE_SUPP_RATES;
325u8 ExtRateIe = IE_EXT_SUPP_RATES;
326u8 HtCapIe = IE_HT_CAP;
327u8 AddHtInfoIe = IE_ADD_HT;
328u8 NewExtChanIe = IE_SECONDARY_CH_OFFSET;
329u8 ErpIe = IE_ERP;
330u8 DsIe = IE_DS_PARM;
331u8 TimIe = IE_TIM;
332u8 WpaIe = IE_WPA;
333u8 Wpa2Ie = IE_WPA2;
334u8 IbssIe = IE_IBSS_PARM;
335
336extern u8 WPA_OUI[];
337
338u8 SES_OUI[] = { 0x00, 0x90, 0x4c };
339
340u8 ZeroSsid[32] =
341 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3420x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344 0x00, 0x00, 0x00, 0x00
345};
346
347/*
348 ==========================================================================
349 Description:
350 initialize the MLME task and its data structure (queue, spinlock,
351 timer, state machines).
352
353 IRQL = PASSIVE_LEVEL
354
355 Return:
356 always return NDIS_STATUS_SUCCESS
357
358 ==========================================================================
359*/
360int MlmeInit(struct rt_rtmp_adapter *pAd)
361{
362 int Status = NDIS_STATUS_SUCCESS;
363
364 DBGPRINT(RT_DEBUG_TRACE, ("--> MLME Initialize\n"));
365
366 do {
367 Status = MlmeQueueInit(&pAd->Mlme.Queue);
368 if (Status != NDIS_STATUS_SUCCESS)
369 break;
370
371 pAd->Mlme.bRunning = FALSE;
372 NdisAllocateSpinLock(&pAd->Mlme.TaskLock);
373
374 {
375 BssTableInit(&pAd->ScanTab);
376
377 /* init STA state machines */
378 AssocStateMachineInit(pAd, &pAd->Mlme.AssocMachine,
379 pAd->Mlme.AssocFunc);
380 AuthStateMachineInit(pAd, &pAd->Mlme.AuthMachine,
381 pAd->Mlme.AuthFunc);
382 AuthRspStateMachineInit(pAd, &pAd->Mlme.AuthRspMachine,
383 pAd->Mlme.AuthRspFunc);
384 SyncStateMachineInit(pAd, &pAd->Mlme.SyncMachine,
385 pAd->Mlme.SyncFunc);
386
387 /* Since we are using switch/case to implement it, the init is different from the above */
388 /* state machine init */
389 MlmeCntlInit(pAd, &pAd->Mlme.CntlMachine, NULL);
390 }
391
392 WpaStateMachineInit(pAd, &pAd->Mlme.WpaMachine,
393 pAd->Mlme.WpaFunc);
394
395 ActionStateMachineInit(pAd, &pAd->Mlme.ActMachine,
396 pAd->Mlme.ActFunc);
397
398 /* Init mlme periodic timer */
399 RTMPInitTimer(pAd, &pAd->Mlme.PeriodicTimer,
400 GET_TIMER_FUNCTION(MlmePeriodicExec), pAd, TRUE);
401
402 /* Set mlme periodic timer */
403 RTMPSetTimer(&pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
404
405 /* software-based RX Antenna diversity */
406 RTMPInitTimer(pAd, &pAd->Mlme.RxAntEvalTimer,
407 GET_TIMER_FUNCTION(AsicRxAntEvalTimeout), pAd,
408 FALSE);
409
410 {
411#ifdef RTMP_PCI_SUPPORT
412 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
413 /* only PCIe cards need these two timers */
414 RTMPInitTimer(pAd, &pAd->Mlme.PsPollTimer,
415 GET_TIMER_FUNCTION
416 (PsPollWakeExec), pAd, FALSE);
417 RTMPInitTimer(pAd, &pAd->Mlme.RadioOnOffTimer,
418 GET_TIMER_FUNCTION(RadioOnExec),
419 pAd, FALSE);
420 }
421#endif /* RTMP_PCI_SUPPORT // */
422
423 RTMPInitTimer(pAd, &pAd->Mlme.LinkDownTimer,
424 GET_TIMER_FUNCTION(LinkDownExec), pAd,
425 FALSE);
426
427#ifdef RTMP_MAC_USB
428 RTMPInitTimer(pAd, &pAd->Mlme.AutoWakeupTimer,
429 GET_TIMER_FUNCTION
430 (RtmpUsbStaAsicForceWakeupTimeout), pAd,
431 FALSE);
432 pAd->Mlme.AutoWakeupTimerRunning = FALSE;
433#endif /* RTMP_MAC_USB // */
434 }
435
436 } while (FALSE);
437
438 DBGPRINT(RT_DEBUG_TRACE, ("<-- MLME Initialize\n"));
439
440 return Status;
441}
442
443/*
444 ==========================================================================
445 Description:
446 main loop of the MLME
447 Pre:
448 Mlme has to be initialized, and there are something inside the queue
449 Note:
450 This function is invoked from MPSetInformation and MPReceive;
451 This task guarantee only one MlmeHandler will run.
452
453 IRQL = DISPATCH_LEVEL
454
455 ==========================================================================
456 */
457void MlmeHandler(struct rt_rtmp_adapter *pAd)
458{
459 struct rt_mlme_queue_elem *Elem = NULL;
460
461 /* Only accept MLME and Frame from peer side, no other (control/data) frame should */
462 /* get into this state machine */
463
464 NdisAcquireSpinLock(&pAd->Mlme.TaskLock);
465 if (pAd->Mlme.bRunning) {
466 NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
467 return;
468 } else {
469 pAd->Mlme.bRunning = TRUE;
470 }
471 NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
472
473 while (!MlmeQueueEmpty(&pAd->Mlme.Queue)) {
474 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS) ||
475 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) ||
476 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) {
477 DBGPRINT(RT_DEBUG_TRACE,
478 ("Device Halted or Removed or MlmeRest, exit MlmeHandler! (queue num = %ld)\n",
479 pAd->Mlme.Queue.Num));
480 break;
481 }
482 /*From message type, determine which state machine I should drive */
483 if (MlmeDequeue(&pAd->Mlme.Queue, &Elem)) {
484#ifdef RTMP_MAC_USB
485 if (Elem->MsgType == MT2_RESET_CONF) {
486 DBGPRINT_RAW(RT_DEBUG_TRACE,
487 ("reset MLME state machine!\n"));
488 MlmeRestartStateMachine(pAd);
489 Elem->Occupied = FALSE;
490 Elem->MsgLen = 0;
491 continue;
492 }
493#endif /* RTMP_MAC_USB // */
494
495 /* if dequeue success */
496 switch (Elem->Machine) {
497 /* STA state machines */
498 case ASSOC_STATE_MACHINE:
499 StateMachinePerformAction(pAd,
500 &pAd->Mlme.
501 AssocMachine, Elem);
502 break;
503 case AUTH_STATE_MACHINE:
504 StateMachinePerformAction(pAd,
505 &pAd->Mlme.
506 AuthMachine, Elem);
507 break;
508 case AUTH_RSP_STATE_MACHINE:
509 StateMachinePerformAction(pAd,
510 &pAd->Mlme.
511 AuthRspMachine, Elem);
512 break;
513 case SYNC_STATE_MACHINE:
514 StateMachinePerformAction(pAd,
515 &pAd->Mlme.
516 SyncMachine, Elem);
517 break;
518 case MLME_CNTL_STATE_MACHINE:
519 MlmeCntlMachinePerformAction(pAd,
520 &pAd->Mlme.
521 CntlMachine, Elem);
522 break;
523 case WPA_PSK_STATE_MACHINE:
524 StateMachinePerformAction(pAd,
525 &pAd->Mlme.
526 WpaPskMachine, Elem);
527 break;
528
529 case ACTION_STATE_MACHINE:
530 StateMachinePerformAction(pAd,
531 &pAd->Mlme.ActMachine,
532 Elem);
533 break;
534
535 case WPA_STATE_MACHINE:
536 StateMachinePerformAction(pAd,
537 &pAd->Mlme.WpaMachine,
538 Elem);
539 break;
540
541 default:
542 DBGPRINT(RT_DEBUG_TRACE,
543 ("ERROR: Illegal machine %ld in MlmeHandler()\n",
544 Elem->Machine));
545 break;
546 } /* end of switch */
547
548 /* free MLME element */
549 Elem->Occupied = FALSE;
550 Elem->MsgLen = 0;
551
552 } else {
553 DBGPRINT_ERR("MlmeHandler: MlmeQueue empty\n");
554 }
555 }
556
557 NdisAcquireSpinLock(&pAd->Mlme.TaskLock);
558 pAd->Mlme.bRunning = FALSE;
559 NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
560}
561
562/*
563 ==========================================================================
564 Description:
565 Destructor of MLME (Destroy queue, state machine, spin lock and timer)
566 Parameters:
567 Adapter - NIC Adapter pointer
568 Post:
569 The MLME task will no longer work properly
570
571 IRQL = PASSIVE_LEVEL
572
573 ==========================================================================
574 */
575void MlmeHalt(struct rt_rtmp_adapter *pAd)
576{
577 BOOLEAN Cancelled;
578
579 DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeHalt\n"));
580
581 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) {
582 /* disable BEACON generation and other BEACON related hardware timers */
583 AsicDisableSync(pAd);
584 }
585
586 {
587 /* Cancel pending timers */
588 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
589 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
590 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
591 RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
592 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
593 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
594
595#ifdef RTMP_MAC_PCI
596 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)
597 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
598 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
599 RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer, &Cancelled);
600 }
601#endif /* RTMP_MAC_PCI // */
602
603 RTMPCancelTimer(&pAd->Mlme.LinkDownTimer, &Cancelled);
604
605#ifdef RTMP_MAC_USB
606 RTMPCancelTimer(&pAd->Mlme.AutoWakeupTimer, &Cancelled);
607#endif /* RTMP_MAC_USB // */
608 }
609
610 RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled);
611 RTMPCancelTimer(&pAd->Mlme.RxAntEvalTimer, &Cancelled);
612
613 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) {
614 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
615
616 /* Set LED */
617 RTMPSetLED(pAd, LED_HALT);
618 RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, firmware is not done it. */
619#ifdef RTMP_MAC_USB
620 {
621 LED_CFG_STRUC LedCfg;
622 RTMP_IO_READ32(pAd, LED_CFG, &LedCfg.word);
623 LedCfg.field.LedPolar = 0;
624 LedCfg.field.RLedMode = 0;
625 LedCfg.field.GLedMode = 0;
626 LedCfg.field.YLedMode = 0;
627 RTMP_IO_WRITE32(pAd, LED_CFG, LedCfg.word);
628 }
629#endif /* RTMP_MAC_USB // */
630
631 if (pChipOps->AsicHaltAction)
632 pChipOps->AsicHaltAction(pAd);
633 }
634
635 RTMPusecDelay(5000); /* 5 msec to guarantee Ant Diversity timer canceled */
636
637 MlmeQueueDestroy(&pAd->Mlme.Queue);
638 NdisFreeSpinLock(&pAd->Mlme.TaskLock);
639
640 DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeHalt\n"));
641}
642
643void MlmeResetRalinkCounters(struct rt_rtmp_adapter *pAd)
644{
645 pAd->RalinkCounters.LastOneSecRxOkDataCnt =
646 pAd->RalinkCounters.OneSecRxOkDataCnt;
647 /* clear all OneSecxxx counters. */
648 pAd->RalinkCounters.OneSecBeaconSentCnt = 0;
649 pAd->RalinkCounters.OneSecFalseCCACnt = 0;
650 pAd->RalinkCounters.OneSecRxFcsErrCnt = 0;
651 pAd->RalinkCounters.OneSecRxOkCnt = 0;
652 pAd->RalinkCounters.OneSecTxFailCount = 0;
653 pAd->RalinkCounters.OneSecTxNoRetryOkCount = 0;
654 pAd->RalinkCounters.OneSecTxRetryOkCount = 0;
655 pAd->RalinkCounters.OneSecRxOkDataCnt = 0;
656 pAd->RalinkCounters.OneSecReceivedByteCount = 0;
657 pAd->RalinkCounters.OneSecTransmittedByteCount = 0;
658
659 /* TODO: for debug only. to be removed */
660 pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BE] = 0;
661 pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BK] = 0;
662 pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VI] = 0;
663 pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VO] = 0;
664 pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BE] = 0;
665 pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BK] = 0;
666 pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VI] = 0;
667 pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VO] = 0;
668 pAd->RalinkCounters.OneSecTxDoneCount = 0;
669 pAd->RalinkCounters.OneSecRxCount = 0;
670 pAd->RalinkCounters.OneSecTxAggregationCount = 0;
671 pAd->RalinkCounters.OneSecRxAggregationCount = 0;
672
673 return;
674}
675
676/*
677 ==========================================================================
678 Description:
679 This routine is executed periodically to -
680 1. Decide if it's a right time to turn on PwrMgmt bit of all
681 outgoiing frames
682 2. Calculate ChannelQuality based on statistics of the last
683 period, so that TX rate won't toggling very frequently between a
684 successful TX and a failed TX.
685 3. If the calculated ChannelQuality indicated current connection not
686 healthy, then a ROAMing attempt is tried here.
687
688 IRQL = DISPATCH_LEVEL
689
690 ==========================================================================
691 */
692#define ADHOC_BEACON_LOST_TIME (8*OS_HZ) /* 8 sec */
693void MlmePeriodicExec(void *SystemSpecific1,
694 void *FunctionContext,
695 void *SystemSpecific2, void *SystemSpecific3)
696{
697 unsigned long TxTotalCnt;
698 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
699
700#ifdef RTMP_MAC_PCI
701 {
702 /* If Hardware controlled Radio enabled, we have to check GPIO pin2 every 2 second. */
703 /* Move code to here, because following code will return when radio is off */
704 if ((pAd->Mlme.PeriodicRound % (MLME_TASK_EXEC_MULTIPLE * 2) ==
705 0) && (pAd->StaCfg.bHardwareRadio == TRUE)
706 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))
707 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
708 /*&&(pAd->bPCIclkOff == FALSE) */
709 ) {
710 u32 data = 0;
711
712 /* Read GPIO pin2 as Hardware controlled radio state */
713#ifndef RT3090
714 RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data);
715#endif /* RT3090 // */
716/*KH(PCIE PS):Added based on Jane<-- */
717#ifdef RT3090
718/* Read GPIO pin2 as Hardware controlled radio state */
719/* We need to Read GPIO if HW said so no mater what advance power saving */
720 if ((pAd->OpMode == OPMODE_STA) && (IDLE_ON(pAd))
721 &&
722 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))
723 && (pAd->StaCfg.PSControl.field.EnablePSinIdle ==
724 TRUE)) {
725 /* Want to make sure device goes to L0 state before reading register. */
726 RTMPPCIeLinkCtrlValueRestore(pAd, 0);
727 RTMP_IO_FORCE_READ32(pAd, GPIO_CTRL_CFG, &data);
728 RTMPPCIeLinkCtrlSetting(pAd, 3);
729 } else
730 RTMP_IO_FORCE_READ32(pAd, GPIO_CTRL_CFG, &data);
731#endif /* RT3090 // */
732/*KH(PCIE PS):Added based on Jane--> */
733
734 if (data & 0x04) {
735 pAd->StaCfg.bHwRadio = TRUE;
736 } else {
737 pAd->StaCfg.bHwRadio = FALSE;
738 }
739 if (pAd->StaCfg.bRadio !=
740 (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio)) {
741 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio
742 && pAd->StaCfg.bSwRadio);
743 if (pAd->StaCfg.bRadio == TRUE) {
744 MlmeRadioOn(pAd);
745 /* Update extra information */
746 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
747 } else {
748 MlmeRadioOff(pAd);
749 /* Update extra information */
750 pAd->ExtraInfo = HW_RADIO_OFF;
751 }
752 }
753 }
754 }
755#endif /* RTMP_MAC_PCI // */
756
757 /* Do nothing if the driver is starting halt state. */
758 /* This might happen when timer already been fired before cancel timer with mlmehalt */
759 if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_HALT_IN_PROGRESS |
760 fRTMP_ADAPTER_RADIO_OFF |
761 fRTMP_ADAPTER_RADIO_MEASUREMENT |
762 fRTMP_ADAPTER_RESET_IN_PROGRESS))))
763 return;
764
765 RTMP_MLME_PRE_SANITY_CHECK(pAd);
766
767 {
768 /* Do nothing if monitor mode is on */
769 if (MONITOR_ON(pAd))
770 return;
771
772 if (pAd->Mlme.PeriodicRound & 0x1) {
773 /* This is the fix for wifi 11n extension channel overlapping test case. for 2860D */
774 if (((pAd->MACVersion & 0xffff) == 0x0101) &&
775 (STA_TGN_WIFI_ON(pAd)) &&
776 (pAd->CommonCfg.IOTestParm.bToggle == FALSE))
777 {
778 RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x24Bf);
779 pAd->CommonCfg.IOTestParm.bToggle = TRUE;
780 } else if ((STA_TGN_WIFI_ON(pAd)) &&
781 ((pAd->MACVersion & 0xffff) == 0x0101)) {
782 RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x243f);
783 pAd->CommonCfg.IOTestParm.bToggle = FALSE;
784 }
785 }
786 }
787
788 pAd->bUpdateBcnCntDone = FALSE;
789
790/* RECBATimerTimeout(SystemSpecific1,FunctionContext,SystemSpecific2,SystemSpecific3); */
791 pAd->Mlme.PeriodicRound++;
792
793#ifdef RTMP_MAC_USB
794 /* execute every 100ms, update the Tx FIFO Cnt for update Tx Rate. */
795 NICUpdateFifoStaCounters(pAd);
796#endif /* RTMP_MAC_USB // */
797
798 /* execute every 500ms */
799 if ((pAd->Mlme.PeriodicRound % 5 == 0)
800 && RTMPAutoRateSwitchCheck(pAd)
801 /*(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)) */ )
802 {
803 /* perform dynamic tx rate switching based on past TX history */
804 {
805 if ((OPSTATUS_TEST_FLAG
806 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
807 )
808 && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)))
809 MlmeDynamicTxRateSwitching(pAd);
810 }
811 }
812 /* Normal 1 second Mlme PeriodicExec. */
813 if (pAd->Mlme.PeriodicRound % MLME_TASK_EXEC_MULTIPLE == 0) {
814 pAd->Mlme.OneSecPeriodicRound++;
815
816 /*ORIBATimerTimeout(pAd); */
817
818 /* Media status changed, report to NDIS */
819 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE)) {
820 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
821 if (OPSTATUS_TEST_FLAG
822 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
823 pAd->IndicateMediaState =
824 NdisMediaStateConnected;
825 RTMP_IndicateMediaState(pAd);
826
827 } else {
828 pAd->IndicateMediaState =
829 NdisMediaStateDisconnected;
830 RTMP_IndicateMediaState(pAd);
831 }
832 }
833
834 NdisGetSystemUpTime(&pAd->Mlme.Now32);
835
836 /* add the most up-to-date h/w raw counters into software variable, so that */
837 /* the dynamic tuning mechanism below are based on most up-to-date information */
838 NICUpdateRawCounters(pAd);
839
840#ifdef RTMP_MAC_USB
841 RTUSBWatchDog(pAd);
842#endif /* RTMP_MAC_USB // */
843
844 /* Need statistics after read counter. So put after NICUpdateRawCounters */
845 ORIBATimerTimeout(pAd);
846
847 /* if MGMT RING is full more than twice within 1 second, we consider there's */
848 /* a hardware problem stucking the TX path. In this case, try a hardware reset */
849 /* to recover the system */
850 /* if (pAd->RalinkCounters.MgmtRingFullCount >= 2) */
851 /* RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HARDWARE_ERROR); */
852 /* else */
853 /* pAd->RalinkCounters.MgmtRingFullCount = 0; */
854
855 /* The time period for checking antenna is according to traffic */
856 {
857 if (pAd->Mlme.bEnableAutoAntennaCheck) {
858 TxTotalCnt =
859 pAd->RalinkCounters.OneSecTxNoRetryOkCount +
860 pAd->RalinkCounters.OneSecTxRetryOkCount +
861 pAd->RalinkCounters.OneSecTxFailCount;
862
863 /* dynamic adjust antenna evaluation period according to the traffic */
864 if (TxTotalCnt > 50) {
865 if (pAd->Mlme.OneSecPeriodicRound %
866 10 == 0) {
867 AsicEvaluateRxAnt(pAd);
868 }
869 } else {
870 if (pAd->Mlme.OneSecPeriodicRound % 3 ==
871 0) {
872 AsicEvaluateRxAnt(pAd);
873 }
874 }
875 }
876 }
877
878 STAMlmePeriodicExec(pAd);
879
880 MlmeResetRalinkCounters(pAd);
881
882 {
883#ifdef RTMP_MAC_PCI
884 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)
885 && (pAd->bPCIclkOff == FALSE))
886#endif /* RTMP_MAC_PCI // */
887 {
888 /* When Adhoc beacon is enabled and RTS/CTS is enabled, there is a chance that hardware MAC FSM will run into a deadlock */
889 /* and sending CTS-to-self over and over. */
890 /* Software Patch Solution: */
891 /* 1. Polling debug state register 0x10F4 every one second. */
892 /* 2. If in 0x10F4 the ((bit29==1) && (bit7==1)) OR ((bit29==1) && (bit5==1)), it means the deadlock has occurred. */
893 /* 3. If the deadlock occurred, reset MAC/BBP by setting 0x1004 to 0x0001 for a while then setting it back to 0x000C again. */
894
895 u32 MacReg = 0;
896
897 RTMP_IO_READ32(pAd, 0x10F4, &MacReg);
898 if (((MacReg & 0x20000000) && (MacReg & 0x80))
899 || ((MacReg & 0x20000000)
900 && (MacReg & 0x20))) {
901 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
902 RTMPusecDelay(1);
903 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xC);
904
905 DBGPRINT(RT_DEBUG_WARN,
906 ("Warning, MAC specific condition occurs \n"));
907 }
908 }
909 }
910
911 RTMP_MLME_HANDLER(pAd);
912 }
913
914 pAd->bUpdateBcnCntDone = FALSE;
915}
916
917/*
918 ==========================================================================
919 Validate SSID for connection try and rescan purpose
920 Valid SSID will have visible chars only.
921 The valid length is from 0 to 32.
922 IRQL = DISPATCH_LEVEL
923 ==========================================================================
924 */
925BOOLEAN MlmeValidateSSID(u8 *pSsid, u8 SsidLen)
926{
927 int index;
928
929 if (SsidLen > MAX_LEN_OF_SSID)
930 return (FALSE);
931
932 /* Check each character value */
933 for (index = 0; index < SsidLen; index++) {
934 if (pSsid[index] < 0x20)
935 return (FALSE);
936 }
937
938 /* All checked */
939 return (TRUE);
940}
941
942void MlmeSelectTxRateTable(struct rt_rtmp_adapter *pAd,
943 struct rt_mac_table_entry *pEntry,
944 u8 ** ppTable,
945 u8 *pTableSize, u8 *pInitTxRateIdx)
946{
947 do {
948 /* decide the rate table for tuning */
949 if (pAd->CommonCfg.TxRateTableSize > 0) {
950 *ppTable = RateSwitchTable;
951 *pTableSize = RateSwitchTable[0];
952 *pInitTxRateIdx = RateSwitchTable[1];
953
954 break;
955 }
956
957 if ((pAd->OpMode == OPMODE_STA) && ADHOC_ON(pAd)) {
958 if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && (pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) { /* 11N 1S Adhoc */
959 *ppTable = RateSwitchTable11N1S;
960 *pTableSize = RateSwitchTable11N1S[0];
961 *pInitTxRateIdx = RateSwitchTable11N1S[1];
962
963 } else if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && (pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2)) { /* 11N 2S Adhoc */
964 if (pAd->LatchRfRegs.Channel <= 14) {
965 *ppTable = RateSwitchTable11N2S;
966 *pTableSize = RateSwitchTable11N2S[0];
967 *pInitTxRateIdx =
968 RateSwitchTable11N2S[1];
969 } else {
970 *ppTable = RateSwitchTable11N2SForABand;
971 *pTableSize =
972 RateSwitchTable11N2SForABand[0];
973 *pInitTxRateIdx =
974 RateSwitchTable11N2SForABand[1];
975 }
976
977 } else if ((pEntry->RateLen == 4)
978 && (pEntry->HTCapability.MCSSet[0] == 0)
979 && (pEntry->HTCapability.MCSSet[1] == 0)
980 ) {
981 *ppTable = RateSwitchTable11B;
982 *pTableSize = RateSwitchTable11B[0];
983 *pInitTxRateIdx = RateSwitchTable11B[1];
984
985 } else if (pAd->LatchRfRegs.Channel <= 14) {
986 *ppTable = RateSwitchTable11BG;
987 *pTableSize = RateSwitchTable11BG[0];
988 *pInitTxRateIdx = RateSwitchTable11BG[1];
989
990 } else {
991 *ppTable = RateSwitchTable11G;
992 *pTableSize = RateSwitchTable11G[0];
993 *pInitTxRateIdx = RateSwitchTable11G[1];
994
995 }
996 break;
997 }
998 /*if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 12) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && */
999 /* ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) */
1000 if (((pEntry->RateLen == 12) || (pAd->OpMode == OPMODE_STA)) && (pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1))) { /* 11BGN 1S AP */
1001 *ppTable = RateSwitchTable11BGN1S;
1002 *pTableSize = RateSwitchTable11BGN1S[0];
1003 *pInitTxRateIdx = RateSwitchTable11BGN1S[1];
1004
1005 break;
1006 }
1007 /*else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 12) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && */
1008 /* (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2)) */
1009 if (((pEntry->RateLen == 12) || (pAd->OpMode == OPMODE_STA)) && (pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2)) { /* 11BGN 2S AP */
1010 if (pAd->LatchRfRegs.Channel <= 14) {
1011 *ppTable = RateSwitchTable11BGN2S;
1012 *pTableSize = RateSwitchTable11BGN2S[0];
1013 *pInitTxRateIdx = RateSwitchTable11BGN2S[1];
1014
1015 } else {
1016 *ppTable = RateSwitchTable11BGN2SForABand;
1017 *pTableSize = RateSwitchTable11BGN2SForABand[0];
1018 *pInitTxRateIdx =
1019 RateSwitchTable11BGN2SForABand[1];
1020
1021 }
1022 break;
1023 }
1024 /*else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) */
1025 if ((pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1))) { /* 11N 1S AP */
1026 *ppTable = RateSwitchTable11N1S;
1027 *pTableSize = RateSwitchTable11N1S[0];
1028 *pInitTxRateIdx = RateSwitchTable11N1S[1];
1029
1030 break;
1031 }
1032 /*else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2)) */
1033 if ((pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2)) { /* 11N 2S AP */
1034 if (pAd->LatchRfRegs.Channel <= 14) {
1035 *ppTable = RateSwitchTable11N2S;
1036 *pTableSize = RateSwitchTable11N2S[0];
1037 *pInitTxRateIdx = RateSwitchTable11N2S[1];
1038 } else {
1039 *ppTable = RateSwitchTable11N2SForABand;
1040 *pTableSize = RateSwitchTable11N2SForABand[0];
1041 *pInitTxRateIdx =
1042 RateSwitchTable11N2SForABand[1];
1043 }
1044
1045 break;
1046 }
1047 /*else if ((pAd->StaActive.SupRateLen == 4) && (pAd->StaActive.ExtRateLen == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) */
1048 if ((pEntry->RateLen == 4 || pAd->CommonCfg.PhyMode == PHY_11B)
1049 /*Iverson mark for Adhoc b mode,sta will use rate 54 Mbps when connect with sta b/g/n mode */
1050 /* && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) */
1051 ) { /* B only AP */
1052 *ppTable = RateSwitchTable11B;
1053 *pTableSize = RateSwitchTable11B[0];
1054 *pInitTxRateIdx = RateSwitchTable11B[1];
1055
1056 break;
1057 }
1058 /*else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen > 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) */
1059 if ((pEntry->RateLen > 8)
1060 && (pEntry->HTCapability.MCSSet[0] == 0)
1061 && (pEntry->HTCapability.MCSSet[1] == 0)
1062 ) { /* B/G mixed AP */
1063 *ppTable = RateSwitchTable11BG;
1064 *pTableSize = RateSwitchTable11BG[0];
1065 *pInitTxRateIdx = RateSwitchTable11BG[1];
1066
1067 break;
1068 }
1069 /*else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) */
1070 if ((pEntry->RateLen == 8)
1071 && (pEntry->HTCapability.MCSSet[0] == 0)
1072 && (pEntry->HTCapability.MCSSet[1] == 0)
1073 ) { /* G only AP */
1074 *ppTable = RateSwitchTable11G;
1075 *pTableSize = RateSwitchTable11G[0];
1076 *pInitTxRateIdx = RateSwitchTable11G[1];
1077
1078 break;
1079 }
1080
1081 {
1082 /*else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) */
1083 if ((pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)) { /* Legacy mode */
1084 if (pAd->CommonCfg.MaxTxRate <= RATE_11) {
1085 *ppTable = RateSwitchTable11B;
1086 *pTableSize = RateSwitchTable11B[0];
1087 *pInitTxRateIdx = RateSwitchTable11B[1];
1088 } else if ((pAd->CommonCfg.MaxTxRate > RATE_11)
1089 && (pAd->CommonCfg.MinTxRate >
1090 RATE_11)) {
1091 *ppTable = RateSwitchTable11G;
1092 *pTableSize = RateSwitchTable11G[0];
1093 *pInitTxRateIdx = RateSwitchTable11G[1];
1094
1095 } else {
1096 *ppTable = RateSwitchTable11BG;
1097 *pTableSize = RateSwitchTable11BG[0];
1098 *pInitTxRateIdx =
1099 RateSwitchTable11BG[1];
1100 }
1101 break;
1102 }
1103 if (pAd->LatchRfRegs.Channel <= 14) {
1104 if (pAd->CommonCfg.TxStream == 1) {
1105 *ppTable = RateSwitchTable11N1S;
1106 *pTableSize = RateSwitchTable11N1S[0];
1107 *pInitTxRateIdx =
1108 RateSwitchTable11N1S[1];
1109 DBGPRINT_RAW(RT_DEBUG_ERROR,
1110 ("DRS: unknown mode,default use 11N 1S AP \n"));
1111 } else {
1112 *ppTable = RateSwitchTable11N2S;
1113 *pTableSize = RateSwitchTable11N2S[0];
1114 *pInitTxRateIdx =
1115 RateSwitchTable11N2S[1];
1116 DBGPRINT_RAW(RT_DEBUG_ERROR,
1117 ("DRS: unknown mode,default use 11N 2S AP \n"));
1118 }
1119 } else {
1120 if (pAd->CommonCfg.TxStream == 1) {
1121 *ppTable = RateSwitchTable11N1S;
1122 *pTableSize = RateSwitchTable11N1S[0];
1123 *pInitTxRateIdx =
1124 RateSwitchTable11N1S[1];
1125 DBGPRINT_RAW(RT_DEBUG_ERROR,
1126 ("DRS: unknown mode,default use 11N 1S AP \n"));
1127 } else {
1128 *ppTable = RateSwitchTable11N2SForABand;
1129 *pTableSize =
1130 RateSwitchTable11N2SForABand[0];
1131 *pInitTxRateIdx =
1132 RateSwitchTable11N2SForABand[1];
1133 DBGPRINT_RAW(RT_DEBUG_ERROR,
1134 ("DRS: unknown mode,default use 11N 2S AP \n"));
1135 }
1136 }
1137 DBGPRINT_RAW(RT_DEBUG_ERROR,
1138 ("DRS: unknown mode (SupRateLen=%d, ExtRateLen=%d, MCSSet[0]=0x%x, MCSSet[1]=0x%x)\n",
1139 pAd->StaActive.SupRateLen,
1140 pAd->StaActive.ExtRateLen,
1141 pAd->StaActive.SupportedPhyInfo.MCSSet[0],
1142 pAd->StaActive.SupportedPhyInfo.
1143 MCSSet[1]));
1144 }
1145 } while (FALSE);
1146}
1147
1148void STAMlmePeriodicExec(struct rt_rtmp_adapter *pAd)
1149{
1150 unsigned long TxTotalCnt;
1151 int i;
1152
1153 /*
1154 We return here in ATE mode, because the statistics
1155 that ATE need are not collected via this routine.
1156 */
1157#if defined(RT305x)||defined(RT3070)
1158 /* request by Gary, if Rssi0 > -42, BBP 82 need to be changed from 0x62 to 0x42, , bbp 67 need to be changed from 0x20 to 0x18 */
1159 if (!pAd->CommonCfg.HighPowerPatchDisabled) {
1160#ifdef RT3070
1161 if ((IS_RT3070(pAd) && ((pAd->MACVersion & 0xffff) < 0x0201)))
1162#endif /* RT3070 // */
1163 {
1164 if ((pAd->StaCfg.RssiSample.AvgRssi0 != 0)
1165 && (pAd->StaCfg.RssiSample.AvgRssi0 >
1166 (pAd->BbpRssiToDbmDelta - 35))) {
1167 RT30xxWriteRFRegister(pAd, RF_R27, 0x20);
1168 } else {
1169 RT30xxWriteRFRegister(pAd, RF_R27, 0x23);
1170 }
1171 }
1172 }
1173#endif
1174#ifdef PCIE_PS_SUPPORT
1175/* don't perform idle-power-save mechanism within 3 min after driver initialization. */
1176/* This can make rebooter test more robust */
1177 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
1178 if ((pAd->OpMode == OPMODE_STA) && (IDLE_ON(pAd))
1179 && (pAd->Mlme.SyncMachine.CurrState == SYNC_IDLE)
1180 && (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)
1181 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))) {
1182 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) {
1183 if (pAd->StaCfg.PSControl.field.EnableNewPS ==
1184 TRUE) {
1185 DBGPRINT(RT_DEBUG_TRACE,
1186 ("%s\n", __func__));
1187 RT28xxPciAsicRadioOff(pAd,
1188 GUI_IDLE_POWER_SAVE,
1189 0);
1190 } else {
1191 AsicSendCommandToMcu(pAd, 0x30,
1192 PowerSafeCID, 0xff,
1193 0x2);
1194 /* Wait command success */
1195 AsicCheckCommanOk(pAd, PowerSafeCID);
1196 RTMP_SET_FLAG(pAd,
1197 fRTMP_ADAPTER_IDLE_RADIO_OFF);
1198 DBGPRINT(RT_DEBUG_TRACE,
1199 ("PSM - rt30xx Issue Sleep command)\n"));
1200 }
1201 } else if (pAd->Mlme.OneSecPeriodicRound > 180) {
1202 if (pAd->StaCfg.PSControl.field.EnableNewPS ==
1203 TRUE) {
1204 DBGPRINT(RT_DEBUG_TRACE,
1205 ("%s\n", __func__));
1206 RT28xxPciAsicRadioOff(pAd,
1207 GUI_IDLE_POWER_SAVE,
1208 0);
1209 } else {
1210 AsicSendCommandToMcu(pAd, 0x30,
1211 PowerSafeCID, 0xff,
1212 0x02);
1213 /* Wait command success */
1214 AsicCheckCommanOk(pAd, PowerSafeCID);
1215 RTMP_SET_FLAG(pAd,
1216 fRTMP_ADAPTER_IDLE_RADIO_OFF);
1217 DBGPRINT(RT_DEBUG_TRACE,
1218 ("PSM - rt28xx Issue Sleep command)\n"));
1219 }
1220 }
1221 } else {
1222 DBGPRINT(RT_DEBUG_TRACE,
1223 ("STAMlmePeriodicExec MMCHK - CommonCfg.Ssid[%d]=%c%c%c%c... MlmeAux.Ssid[%d]=%c%c%c%c...\n",
1224 pAd->CommonCfg.SsidLen,
1225 pAd->CommonCfg.Ssid[0],
1226 pAd->CommonCfg.Ssid[1],
1227 pAd->CommonCfg.Ssid[2],
1228 pAd->CommonCfg.Ssid[3], pAd->MlmeAux.SsidLen,
1229 pAd->MlmeAux.Ssid[0], pAd->MlmeAux.Ssid[1],
1230 pAd->MlmeAux.Ssid[2], pAd->MlmeAux.Ssid[3]));
1231 }
1232 }
1233#endif /* PCIE_PS_SUPPORT // */
1234
1235 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE) {
1236 /* WPA MIC error should block association attempt for 60 seconds */
1237 if (pAd->StaCfg.bBlockAssoc &&
1238 RTMP_TIME_AFTER(pAd->Mlme.Now32,
1239 pAd->StaCfg.LastMicErrorTime +
1240 (60 * OS_HZ)))
1241 pAd->StaCfg.bBlockAssoc = FALSE;
1242 }
1243
1244 if ((pAd->PreMediaState != pAd->IndicateMediaState)
1245 && (pAd->CommonCfg.bWirelessEvent)) {
1246 if (pAd->IndicateMediaState == NdisMediaStateConnected) {
1247 RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG,
1248 pAd->MacTab.Content[BSSID_WCID].
1249 Addr, BSS0, 0);
1250 }
1251 pAd->PreMediaState = pAd->IndicateMediaState;
1252 }
1253
1254 if (pAd->CommonCfg.PSPXlink && ADHOC_ON(pAd)) {
1255 } else {
1256 AsicStaBbpTuning(pAd);
1257 }
1258
1259 TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount +
1260 pAd->RalinkCounters.OneSecTxRetryOkCount +
1261 pAd->RalinkCounters.OneSecTxFailCount;
1262
1263 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
1264 /* update channel quality for Roaming and UI LinkQuality display */
1265 MlmeCalculateChannelQuality(pAd, NULL, pAd->Mlme.Now32);
1266 }
1267 /* must be AFTER MlmeDynamicTxRateSwitching() because it needs to know if */
1268 /* Radio is currently in noisy environment */
1269 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1270 AsicAdjustTxPower(pAd);
1271
1272 if (INFRA_ON(pAd)) {
1273
1274 /* Is PSM bit consistent with user power management policy? */
1275 /* This is the only place that will set PSM bit ON. */
1276 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
1277 MlmeCheckPsmChange(pAd, pAd->Mlme.Now32);
1278
1279 pAd->RalinkCounters.LastOneSecTotalTxCount = TxTotalCnt;
1280
1281 if ((RTMP_TIME_AFTER
1282 (pAd->Mlme.Now32,
1283 pAd->StaCfg.LastBeaconRxTime + (1 * OS_HZ)))
1284 &&
1285 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1286 &&
1287 (((TxTotalCnt + pAd->RalinkCounters.OneSecRxOkCnt) <
1288 600))) {
1289 RTMPSetAGCInitValue(pAd, BW_20);
1290 DBGPRINT(RT_DEBUG_TRACE,
1291 ("MMCHK - No BEACON. restore R66 to the low bound(%d) \n",
1292 (0x2E + GET_LNA_GAIN(pAd))));
1293 }
1294 /*if ((pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) && */
1295 /* (pAd->RalinkCounters.OneSecTxRetryOkCount == 0)) */
1296 {
1297 if (pAd->CommonCfg.bAPSDCapable
1298 && pAd->CommonCfg.APEdcaParm.bAPSDCapable) {
1299 /* When APSD is enabled, the period changes as 20 sec */
1300 if ((pAd->Mlme.OneSecPeriodicRound % 20) == 8)
1301 RTMPSendNullFrame(pAd,
1302 pAd->CommonCfg.TxRate,
1303 TRUE);
1304 } else {
1305 /* Send out a NULL frame every 10 sec to inform AP that STA is still alive (Avoid being age out) */
1306 if ((pAd->Mlme.OneSecPeriodicRound % 10) == 8) {
1307 if (pAd->CommonCfg.bWmmCapable)
1308 RTMPSendNullFrame(pAd,
1309 pAd->
1310 CommonCfg.
1311 TxRate, TRUE);
1312 else
1313 RTMPSendNullFrame(pAd,
1314 pAd->
1315 CommonCfg.
1316 TxRate,
1317 FALSE);
1318 }
1319 }
1320 }
1321
1322 if (CQI_IS_DEAD(pAd->Mlme.ChannelQuality)) {
1323 DBGPRINT(RT_DEBUG_TRACE,
1324 ("MMCHK - No BEACON. Dead CQI. Auto Recovery attempt #%ld\n",
1325 pAd->RalinkCounters.BadCQIAutoRecoveryCount));
1326
1327 /* Lost AP, send disconnect & link down event */
1328 LinkDown(pAd, FALSE);
1329
1330 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL,
1331 0);
1332
1333 /* RTMPPatchMacBbpBug(pAd); */
1334 MlmeAutoReconnectLastSSID(pAd);
1335 } else if (CQI_IS_BAD(pAd->Mlme.ChannelQuality)) {
1336 pAd->RalinkCounters.BadCQIAutoRecoveryCount++;
1337 DBGPRINT(RT_DEBUG_TRACE,
1338 ("MMCHK - Bad CQI. Auto Recovery attempt #%ld\n",
1339 pAd->RalinkCounters.BadCQIAutoRecoveryCount));
1340 MlmeAutoReconnectLastSSID(pAd);
1341 }
1342
1343 if (pAd->StaCfg.bAutoRoaming) {
1344 BOOLEAN rv = FALSE;
1345 char dBmToRoam = pAd->StaCfg.dBmToRoam;
1346 char MaxRssi = RTMPMaxRssi(pAd,
1347 pAd->StaCfg.RssiSample.
1348 LastRssi0,
1349 pAd->StaCfg.RssiSample.
1350 LastRssi1,
1351 pAd->StaCfg.RssiSample.
1352 LastRssi2);
1353
1354 /* Scanning, ignore Roaming */
1355 if (!RTMP_TEST_FLAG
1356 (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)
1357 && (pAd->Mlme.SyncMachine.CurrState == SYNC_IDLE)
1358 && (MaxRssi <= dBmToRoam)) {
1359 DBGPRINT(RT_DEBUG_TRACE,
1360 ("Rssi=%d, dBmToRoam=%d\n", MaxRssi,
1361 (char)dBmToRoam));
1362
1363 /* Add auto seamless roaming */
1364 if (rv == FALSE)
1365 rv = MlmeCheckForFastRoaming(pAd);
1366
1367 if (rv == FALSE) {
1368 if ((pAd->StaCfg.LastScanTime +
1369 10 * OS_HZ) < pAd->Mlme.Now32) {
1370 DBGPRINT(RT_DEBUG_TRACE,
1371 ("MMCHK - Roaming, No eligible entry, try new scan!\n"));
1372 pAd->StaCfg.ScanCnt = 2;
1373 pAd->StaCfg.LastScanTime =
1374 pAd->Mlme.Now32;
1375 MlmeAutoScan(pAd);
1376 }
1377 }
1378 }
1379 }
1380 } else if (ADHOC_ON(pAd)) {
1381 /* If all peers leave, and this STA becomes the last one in this IBSS, then change MediaState */
1382 /* to DISCONNECTED. But still holding this IBSS (i.e. sending BEACON) so that other STAs can */
1383 /* join later. */
1384 if (RTMP_TIME_AFTER
1385 (pAd->Mlme.Now32,
1386 pAd->StaCfg.LastBeaconRxTime + ADHOC_BEACON_LOST_TIME)
1387 && OPSTATUS_TEST_FLAG(pAd,
1388 fOP_STATUS_MEDIA_STATE_CONNECTED)) {
1389 struct rt_mlme_start_req StartReq;
1390
1391 DBGPRINT(RT_DEBUG_TRACE,
1392 ("MMCHK - excessive BEACON lost, last STA in this IBSS, MediaState=Disconnected\n"));
1393 LinkDown(pAd, FALSE);
1394
1395 StartParmFill(pAd, &StartReq,
1396 (char *) pAd->MlmeAux.Ssid,
1397 pAd->MlmeAux.SsidLen);
1398 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ,
1399 sizeof(struct rt_mlme_start_req), &StartReq);
1400 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
1401 }
1402
1403 for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) {
1404 struct rt_mac_table_entry *pEntry = &pAd->MacTab.Content[i];
1405
1406 if (pEntry->ValidAsCLI == FALSE)
1407 continue;
1408
1409 if (RTMP_TIME_AFTER
1410 (pAd->Mlme.Now32,
1411 pEntry->LastBeaconRxTime + ADHOC_BEACON_LOST_TIME))
1412 MacTableDeleteEntry(pAd, pEntry->Aid,
1413 pEntry->Addr);
1414 }
1415 } else /* no INFRA nor ADHOC connection */
1416 {
1417
1418 if (pAd->StaCfg.bScanReqIsFromWebUI &&
1419 RTMP_TIME_BEFORE(pAd->Mlme.Now32,
1420 pAd->StaCfg.LastScanTime + (30 * OS_HZ)))
1421 goto SKIP_AUTO_SCAN_CONN;
1422 else
1423 pAd->StaCfg.bScanReqIsFromWebUI = FALSE;
1424
1425 if ((pAd->StaCfg.bAutoReconnect == TRUE)
1426 && RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)
1427 &&
1428 (MlmeValidateSSID
1429 (pAd->MlmeAux.AutoReconnectSsid,
1430 pAd->MlmeAux.AutoReconnectSsidLen) == TRUE)) {
1431 if ((pAd->ScanTab.BssNr == 0)
1432 && (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)) {
1433 struct rt_mlme_scan_req ScanReq;
1434
1435 if (RTMP_TIME_AFTER
1436 (pAd->Mlme.Now32,
1437 pAd->StaCfg.LastScanTime + (10 * OS_HZ))) {
1438 DBGPRINT(RT_DEBUG_TRACE,
1439 ("STAMlmePeriodicExec():CNTL - ScanTab.BssNr==0, start a new ACTIVE scan SSID[%s]\n",
1440 pAd->MlmeAux.
1441 AutoReconnectSsid));
1442 ScanParmFill(pAd, &ScanReq,
1443 (char *)pAd->MlmeAux.
1444 AutoReconnectSsid,
1445 pAd->MlmeAux.
1446 AutoReconnectSsidLen,
1447 BSS_ANY, SCAN_ACTIVE);
1448 MlmeEnqueue(pAd, SYNC_STATE_MACHINE,
1449 MT2_MLME_SCAN_REQ,
1450 sizeof
1451 (struct rt_mlme_scan_req),
1452 &ScanReq);
1453 pAd->Mlme.CntlMachine.CurrState =
1454 CNTL_WAIT_OID_LIST_SCAN;
1455 /* Reset Missed scan number */
1456 pAd->StaCfg.LastScanTime =
1457 pAd->Mlme.Now32;
1458 } else if (pAd->StaCfg.BssType == BSS_ADHOC) /* Quit the forever scan when in a very clean room */
1459 MlmeAutoReconnectLastSSID(pAd);
1460 } else if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) {
1461 if ((pAd->Mlme.OneSecPeriodicRound % 7) == 0) {
1462 MlmeAutoScan(pAd);
1463 pAd->StaCfg.LastScanTime =
1464 pAd->Mlme.Now32;
1465 } else {
1466 MlmeAutoReconnectLastSSID(pAd);
1467 }
1468 }
1469 }
1470 }
1471
1472SKIP_AUTO_SCAN_CONN:
1473
1474 if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap != 0)
1475 && (pAd->MacTab.fAnyBASession == FALSE)) {
1476 pAd->MacTab.fAnyBASession = TRUE;
1477 AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, FALSE,
1478 FALSE);
1479 } else if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap == 0)
1480 && (pAd->MacTab.fAnyBASession == TRUE)) {
1481 pAd->MacTab.fAnyBASession = FALSE;
1482 AsicUpdateProtect(pAd,
1483 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1484 OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
1485 }
1486
1487 return;
1488}
1489
1490/* Link down report */
1491void LinkDownExec(void *SystemSpecific1,
1492 void *FunctionContext,
1493 void *SystemSpecific2, void *SystemSpecific3)
1494{
1495 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
1496
1497 if (pAd != NULL) {
1498 struct rt_mlme_disassoc_req DisassocReq;
1499
1500 if ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED) &&
1501 (INFRA_ON(pAd))) {
1502 DBGPRINT(RT_DEBUG_TRACE,
1503 ("LinkDownExec(): disassociate with current AP...\n"));
1504 DisassocParmFill(pAd, &DisassocReq,
1505 pAd->CommonCfg.Bssid,
1506 REASON_DISASSOC_STA_LEAVING);
1507 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
1508 MT2_MLME_DISASSOC_REQ,
1509 sizeof(struct rt_mlme_disassoc_req),
1510 &DisassocReq);
1511 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
1512
1513 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1514 RTMP_IndicateMediaState(pAd);
1515 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1516 }
1517 }
1518}
1519
1520/* IRQL = DISPATCH_LEVEL */
1521void MlmeAutoScan(struct rt_rtmp_adapter *pAd)
1522{
1523 /* check CntlMachine.CurrState to avoid collision with NDIS SetOID request */
1524 if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) {
1525 DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Driver auto scan\n"));
1526 MlmeEnqueue(pAd,
1527 MLME_CNTL_STATE_MACHINE,
1528 OID_802_11_BSSID_LIST_SCAN,
1529 pAd->MlmeAux.AutoReconnectSsidLen,
1530 pAd->MlmeAux.AutoReconnectSsid);
1531 RTMP_MLME_HANDLER(pAd);
1532 }
1533}
1534
1535/* IRQL = DISPATCH_LEVEL */
1536void MlmeAutoReconnectLastSSID(struct rt_rtmp_adapter *pAd)
1537{
1538 if (pAd->StaCfg.bAutoConnectByBssid) {
1539 DBGPRINT(RT_DEBUG_TRACE,
1540 ("Driver auto reconnect to last OID_802_11_BSSID "
1541 "setting - %pM\n", pAd->MlmeAux.Bssid));
1542
1543 pAd->MlmeAux.Channel = pAd->CommonCfg.Channel;
1544 MlmeEnqueue(pAd,
1545 MLME_CNTL_STATE_MACHINE,
1546 OID_802_11_BSSID, MAC_ADDR_LEN, pAd->MlmeAux.Bssid);
1547
1548 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
1549
1550 RTMP_MLME_HANDLER(pAd);
1551 }
1552 /* check CntlMachine.CurrState to avoid collision with NDIS SetOID request */
1553 else if ((pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) &&
1554 (MlmeValidateSSID
1555 (pAd->MlmeAux.AutoReconnectSsid,
1556 pAd->MlmeAux.AutoReconnectSsidLen) == TRUE)) {
1557 struct rt_ndis_802_11_ssid OidSsid;
1558 OidSsid.SsidLength = pAd->MlmeAux.AutoReconnectSsidLen;
1559 NdisMoveMemory(OidSsid.Ssid, pAd->MlmeAux.AutoReconnectSsid,
1560 pAd->MlmeAux.AutoReconnectSsidLen);
1561
1562 DBGPRINT(RT_DEBUG_TRACE,
1563 ("Driver auto reconnect to last OID_802_11_SSID setting - %s, len - %d\n",
1564 pAd->MlmeAux.AutoReconnectSsid,
1565 pAd->MlmeAux.AutoReconnectSsidLen));
1566 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, OID_802_11_SSID,
1567 sizeof(struct rt_ndis_802_11_ssid), &OidSsid);
1568 RTMP_MLME_HANDLER(pAd);
1569 }
1570}
1571
1572/*
1573 ==========================================================================
1574 Description:
1575 This routine checks if there're other APs out there capable for
1576 roaming. Caller should call this routine only when Link up in INFRA mode
1577 and channel quality is below CQI_GOOD_THRESHOLD.
1578
1579 IRQL = DISPATCH_LEVEL
1580
1581 Output:
1582 ==========================================================================
1583 */
1584void MlmeCheckForRoaming(struct rt_rtmp_adapter *pAd, unsigned long Now32)
1585{
1586 u16 i;
1587 struct rt_bss_table *pRoamTab = &pAd->MlmeAux.RoamTab;
1588 struct rt_bss_entry *pBss;
1589
1590 DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForRoaming\n"));
1591 /* put all roaming candidates into RoamTab, and sort in RSSI order */
1592 BssTableInit(pRoamTab);
1593 for (i = 0; i < pAd->ScanTab.BssNr; i++) {
1594 pBss = &pAd->ScanTab.BssEntry[i];
1595
1596 if ((pBss->LastBeaconRxTime + pAd->StaCfg.BeaconLostTime) <
1597 Now32)
1598 continue; /* AP disappear */
1599 if (pBss->Rssi <= RSSI_THRESHOLD_FOR_ROAMING)
1600 continue; /* RSSI too weak. forget it. */
1601 if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid))
1602 continue; /* skip current AP */
1603 if (pBss->Rssi <
1604 (pAd->StaCfg.RssiSample.LastRssi0 + RSSI_DELTA))
1605 continue; /* only AP with stronger RSSI is eligible for roaming */
1606
1607 /* AP passing all above rules is put into roaming candidate table */
1608 NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss,
1609 sizeof(struct rt_bss_entry));
1610 pRoamTab->BssNr += 1;
1611 }
1612
1613 if (pRoamTab->BssNr > 0) {
1614 /* check CntlMachine.CurrState to avoid collision with NDIS SetOID request */
1615 if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) {
1616 pAd->RalinkCounters.PoorCQIRoamingCount++;
1617 DBGPRINT(RT_DEBUG_TRACE,
1618 ("MMCHK - Roaming attempt #%ld\n",
1619 pAd->RalinkCounters.PoorCQIRoamingCount));
1620 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
1621 MT2_MLME_ROAMING_REQ, 0, NULL);
1622 RTMP_MLME_HANDLER(pAd);
1623 }
1624 }
1625 DBGPRINT(RT_DEBUG_TRACE,
1626 ("<== MlmeCheckForRoaming(# of candidate= %d)\n",
1627 pRoamTab->BssNr));
1628}
1629
1630/*
1631 ==========================================================================
1632 Description:
1633 This routine checks if there're other APs out there capable for
1634 roaming. Caller should call this routine only when link up in INFRA mode
1635 and channel quality is below CQI_GOOD_THRESHOLD.
1636
1637 IRQL = DISPATCH_LEVEL
1638
1639 Output:
1640 ==========================================================================
1641 */
1642BOOLEAN MlmeCheckForFastRoaming(struct rt_rtmp_adapter *pAd)
1643{
1644 u16 i;
1645 struct rt_bss_table *pRoamTab = &pAd->MlmeAux.RoamTab;
1646 struct rt_bss_entry *pBss;
1647
1648 DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForFastRoaming\n"));
1649 /* put all roaming candidates into RoamTab, and sort in RSSI order */
1650 BssTableInit(pRoamTab);
1651 for (i = 0; i < pAd->ScanTab.BssNr; i++) {
1652 pBss = &pAd->ScanTab.BssEntry[i];
1653
1654 if ((pBss->Rssi <= -50)
1655 && (pBss->Channel == pAd->CommonCfg.Channel))
1656 continue; /* RSSI too weak. forget it. */
1657 if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid))
1658 continue; /* skip current AP */
1659 if (!SSID_EQUAL
1660 (pBss->Ssid, pBss->SsidLen, pAd->CommonCfg.Ssid,
1661 pAd->CommonCfg.SsidLen))
1662 continue; /* skip different SSID */
1663 if (pBss->Rssi <
1664 (RTMPMaxRssi
1665 (pAd, pAd->StaCfg.RssiSample.LastRssi0,
1666 pAd->StaCfg.RssiSample.LastRssi1,
1667 pAd->StaCfg.RssiSample.LastRssi2) + RSSI_DELTA))
1668 continue; /* skip AP without better RSSI */
1669
1670 DBGPRINT(RT_DEBUG_TRACE,
1671 ("LastRssi0 = %d, pBss->Rssi = %d\n",
1672 RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0,
1673 pAd->StaCfg.RssiSample.LastRssi1,
1674 pAd->StaCfg.RssiSample.LastRssi2),
1675 pBss->Rssi));
1676 /* AP passing all above rules is put into roaming candidate table */
1677 NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss,
1678 sizeof(struct rt_bss_entry));
1679 pRoamTab->BssNr += 1;
1680 }
1681
1682 DBGPRINT(RT_DEBUG_TRACE,
1683 ("<== MlmeCheckForFastRoaming (BssNr=%d)\n", pRoamTab->BssNr));
1684 if (pRoamTab->BssNr > 0) {
1685 /* check CntlMachine.CurrState to avoid collision with NDIS SetOID request */
1686 if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) {
1687 pAd->RalinkCounters.PoorCQIRoamingCount++;
1688 DBGPRINT(RT_DEBUG_TRACE,
1689 ("MMCHK - Roaming attempt #%ld\n",
1690 pAd->RalinkCounters.PoorCQIRoamingCount));
1691 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
1692 MT2_MLME_ROAMING_REQ, 0, NULL);
1693 RTMP_MLME_HANDLER(pAd);
1694 return TRUE;
1695 }
1696 }
1697
1698 return FALSE;
1699}
1700
1701void MlmeSetTxRate(struct rt_rtmp_adapter *pAd,
1702 struct rt_mac_table_entry *pEntry, struct rt_rtmp_tx_rate_switch * pTxRate)
1703{
1704 u8 MaxMode = MODE_OFDM;
1705
1706 MaxMode = MODE_HTGREENFIELD;
1707
1708 if (pTxRate->STBC && (pAd->StaCfg.MaxHTPhyMode.field.STBC)
1709 && (pAd->Antenna.field.TxPath == 2))
1710 pAd->StaCfg.HTPhyMode.field.STBC = STBC_USE;
1711 else
1712 pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE;
1713
1714 if (pTxRate->CurrMCS < MCS_AUTO)
1715 pAd->StaCfg.HTPhyMode.field.MCS = pTxRate->CurrMCS;
1716
1717 if (pAd->StaCfg.HTPhyMode.field.MCS > 7)
1718 pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE;
1719
1720 if (ADHOC_ON(pAd)) {
1721 /* If peer adhoc is b-only mode, we can't send 11g rate. */
1722 pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
1723 pEntry->HTPhyMode.field.STBC = STBC_NONE;
1724
1725 /* */
1726 /* For Adhoc MODE_CCK, driver will use AdhocBOnlyJoined flag to roll back to B only if necessary */
1727 /* */
1728 pEntry->HTPhyMode.field.MODE = pTxRate->Mode;
1729 pEntry->HTPhyMode.field.ShortGI =
1730 pAd->StaCfg.HTPhyMode.field.ShortGI;
1731 pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
1732
1733 /* Patch speed error in status page */
1734 pAd->StaCfg.HTPhyMode.field.MODE = pEntry->HTPhyMode.field.MODE;
1735 } else {
1736 if (pTxRate->Mode <= MaxMode)
1737 pAd->StaCfg.HTPhyMode.field.MODE = pTxRate->Mode;
1738
1739 if (pTxRate->ShortGI
1740 && (pAd->StaCfg.MaxHTPhyMode.field.ShortGI))
1741 pAd->StaCfg.HTPhyMode.field.ShortGI = GI_400;
1742 else
1743 pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
1744
1745 /* Reexam each bandwidth's SGI support. */
1746 if (pAd->StaCfg.HTPhyMode.field.ShortGI == GI_400) {
1747 if ((pEntry->HTPhyMode.field.BW == BW_20)
1748 &&
1749 (!CLIENT_STATUS_TEST_FLAG
1750 (pEntry, fCLIENT_STATUS_SGI20_CAPABLE)))
1751 pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
1752 if ((pEntry->HTPhyMode.field.BW == BW_40)
1753 &&
1754 (!CLIENT_STATUS_TEST_FLAG
1755 (pEntry, fCLIENT_STATUS_SGI40_CAPABLE)))
1756 pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800;
1757 }
1758 /* Turn RTS/CTS rate to 6Mbps. */
1759 if ((pEntry->HTPhyMode.field.MCS == 0)
1760 && (pAd->StaCfg.HTPhyMode.field.MCS != 0)) {
1761 pEntry->HTPhyMode.field.MCS =
1762 pAd->StaCfg.HTPhyMode.field.MCS;
1763 if (pAd->MacTab.fAnyBASession) {
1764 AsicUpdateProtect(pAd, HT_FORCERTSCTS,
1765 ALLN_SETPROTECT, TRUE,
1766 (BOOLEAN) pAd->MlmeAux.
1767 AddHtInfo.AddHtInfo2.
1768 NonGfPresent);
1769 } else {
1770 AsicUpdateProtect(pAd,
1771 pAd->MlmeAux.AddHtInfo.
1772 AddHtInfo2.OperaionMode,
1773 ALLN_SETPROTECT, TRUE,
1774 (BOOLEAN) pAd->MlmeAux.
1775 AddHtInfo.AddHtInfo2.
1776 NonGfPresent);
1777 }
1778 } else if ((pEntry->HTPhyMode.field.MCS == 8)
1779 && (pAd->StaCfg.HTPhyMode.field.MCS != 8)) {
1780 pEntry->HTPhyMode.field.MCS =
1781 pAd->StaCfg.HTPhyMode.field.MCS;
1782 if (pAd->MacTab.fAnyBASession) {
1783 AsicUpdateProtect(pAd, HT_FORCERTSCTS,
1784 ALLN_SETPROTECT, TRUE,
1785 (BOOLEAN) pAd->MlmeAux.
1786 AddHtInfo.AddHtInfo2.
1787 NonGfPresent);
1788 } else {
1789 AsicUpdateProtect(pAd,
1790 pAd->MlmeAux.AddHtInfo.
1791 AddHtInfo2.OperaionMode,
1792 ALLN_SETPROTECT, TRUE,
1793 (BOOLEAN) pAd->MlmeAux.
1794 AddHtInfo.AddHtInfo2.
1795 NonGfPresent);
1796 }
1797 } else if ((pEntry->HTPhyMode.field.MCS != 0)
1798 && (pAd->StaCfg.HTPhyMode.field.MCS == 0)) {
1799 AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT,
1800 TRUE,
1801 (BOOLEAN) pAd->MlmeAux.AddHtInfo.
1802 AddHtInfo2.NonGfPresent);
1803
1804 } else if ((pEntry->HTPhyMode.field.MCS != 8)
1805 && (pAd->StaCfg.HTPhyMode.field.MCS == 8)) {
1806 AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT,
1807 TRUE,
1808 (BOOLEAN) pAd->MlmeAux.AddHtInfo.
1809 AddHtInfo2.NonGfPresent);
1810 }
1811
1812 pEntry->HTPhyMode.field.STBC = pAd->StaCfg.HTPhyMode.field.STBC;
1813 pEntry->HTPhyMode.field.ShortGI =
1814 pAd->StaCfg.HTPhyMode.field.ShortGI;
1815 pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
1816 pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
1817 if ((pAd->StaCfg.MaxHTPhyMode.field.MODE == MODE_HTGREENFIELD)
1818 && pAd->WIFItestbed.bGreenField)
1819 pEntry->HTPhyMode.field.MODE = MODE_HTGREENFIELD;
1820 }
1821
1822 pAd->LastTxRate = (u16)(pEntry->HTPhyMode.word);
1823}
1824
1825/*
1826 ==========================================================================
1827 Description:
1828 This routine calculates the acumulated TxPER of eaxh TxRate. And
1829 according to the calculation result, change CommonCfg.TxRate which
1830 is the stable TX Rate we expect the Radio situation could sustained.
1831
1832 CommonCfg.TxRate will change dynamically within {RATE_1/RATE_6, MaxTxRate}
1833 Output:
1834 CommonCfg.TxRate -
1835
1836 IRQL = DISPATCH_LEVEL
1837
1838 NOTE:
1839 call this routine every second
1840 ==========================================================================
1841 */
1842void MlmeDynamicTxRateSwitching(struct rt_rtmp_adapter *pAd)
1843{
1844 u8 UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx;
1845 unsigned long i, AccuTxTotalCnt = 0, TxTotalCnt;
1846 unsigned long TxErrorRatio = 0;
1847 BOOLEAN bTxRateChanged = FALSE, bUpgradeQuality = FALSE;
1848 struct rt_rtmp_tx_rate_switch *pCurrTxRate, *pNextTxRate = NULL;
1849 u8 *pTable;
1850 u8 TableSize = 0;
1851 u8 InitTxRateIdx = 0, TrainUp, TrainDown;
1852 char Rssi, RssiOffset = 0;
1853 TX_STA_CNT1_STRUC StaTx1;
1854 TX_STA_CNT0_STRUC TxStaCnt0;
1855 unsigned long TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0;
1856 struct rt_mac_table_entry *pEntry;
1857 struct rt_rssi_sample *pRssi = &pAd->StaCfg.RssiSample;
1858
1859 /* */
1860 /* walk through MAC table, see if need to change AP's TX rate toward each entry */
1861 /* */
1862 for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) {
1863 pEntry = &pAd->MacTab.Content[i];
1864
1865 /* check if this entry need to switch rate automatically */
1866 if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE)
1867 continue;
1868
1869 if ((pAd->MacTab.Size == 1) || (pEntry->ValidAsDls)) {
1870 Rssi = RTMPMaxRssi(pAd,
1871 pRssi->AvgRssi0,
1872 pRssi->AvgRssi1, pRssi->AvgRssi2);
1873
1874 /* Update statistic counter */
1875 RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
1876 RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
1877 pAd->bUpdateBcnCntDone = TRUE;
1878 TxRetransmit = StaTx1.field.TxRetransmit;
1879 TxSuccess = StaTx1.field.TxSuccess;
1880 TxFailCount = TxStaCnt0.field.TxFailCount;
1881 TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount;
1882
1883 pAd->RalinkCounters.OneSecTxRetryOkCount +=
1884 StaTx1.field.TxRetransmit;
1885 pAd->RalinkCounters.OneSecTxNoRetryOkCount +=
1886 StaTx1.field.TxSuccess;
1887 pAd->RalinkCounters.OneSecTxFailCount +=
1888 TxStaCnt0.field.TxFailCount;
1889 pAd->WlanCounters.TransmittedFragmentCount.u.LowPart +=
1890 StaTx1.field.TxSuccess;
1891 pAd->WlanCounters.RetryCount.u.LowPart +=
1892 StaTx1.field.TxRetransmit;
1893 pAd->WlanCounters.FailedCount.u.LowPart +=
1894 TxStaCnt0.field.TxFailCount;
1895
1896 /* if no traffic in the past 1-sec period, don't change TX rate, */
1897 /* but clear all bad history. because the bad history may affect the next */
1898 /* Chariot throughput test */
1899 AccuTxTotalCnt =
1900 pAd->RalinkCounters.OneSecTxNoRetryOkCount +
1901 pAd->RalinkCounters.OneSecTxRetryOkCount +
1902 pAd->RalinkCounters.OneSecTxFailCount;
1903
1904 if (TxTotalCnt)
1905 TxErrorRatio =
1906 ((TxRetransmit +
1907 TxFailCount) * 100) / TxTotalCnt;
1908 } else {
1909 if (INFRA_ON(pAd) && (i == 1))
1910 Rssi = RTMPMaxRssi(pAd,
1911 pRssi->AvgRssi0,
1912 pRssi->AvgRssi1,
1913 pRssi->AvgRssi2);
1914 else
1915 Rssi = RTMPMaxRssi(pAd,
1916 pEntry->RssiSample.AvgRssi0,
1917 pEntry->RssiSample.AvgRssi1,
1918 pEntry->RssiSample.AvgRssi2);
1919
1920 TxTotalCnt = pEntry->OneSecTxNoRetryOkCount +
1921 pEntry->OneSecTxRetryOkCount +
1922 pEntry->OneSecTxFailCount;
1923
1924 if (TxTotalCnt)
1925 TxErrorRatio =
1926 ((pEntry->OneSecTxRetryOkCount +
1927 pEntry->OneSecTxFailCount) * 100) /
1928 TxTotalCnt;
1929 }
1930
1931 if (TxTotalCnt) {
1932 /*
1933 Three AdHoc connections can not work normally if one AdHoc connection is disappeared from a heavy traffic environment generated by ping tool
1934 We force to set LongRtyLimit and ShortRtyLimit to 0 to stop retransmitting packet, after a while, resoring original settings
1935 */
1936 if (TxErrorRatio == 100) {
1937 TX_RTY_CFG_STRUC TxRtyCfg, TxRtyCfgtmp;
1938 unsigned long Index;
1939 unsigned long MACValue;
1940
1941 RTMP_IO_READ32(pAd, TX_RTY_CFG, &TxRtyCfg.word);
1942 TxRtyCfgtmp.word = TxRtyCfg.word;
1943 TxRtyCfg.field.LongRtyLimit = 0x0;
1944 TxRtyCfg.field.ShortRtyLimit = 0x0;
1945 RTMP_IO_WRITE32(pAd, TX_RTY_CFG, TxRtyCfg.word);
1946
1947 RTMPusecDelay(1);
1948
1949 Index = 0;
1950 MACValue = 0;
1951 do {
1952 RTMP_IO_READ32(pAd, TXRXQ_PCNT,
1953 &MACValue);
1954 if ((MACValue & 0xffffff) == 0)
1955 break;
1956 Index++;
1957 RTMPusecDelay(1000);
1958 } while ((Index < 330)
1959 &&
1960 (!RTMP_TEST_FLAG
1961 (pAd,
1962 fRTMP_ADAPTER_HALT_IN_PROGRESS)));
1963
1964 RTMP_IO_READ32(pAd, TX_RTY_CFG, &TxRtyCfg.word);
1965 TxRtyCfg.field.LongRtyLimit =
1966 TxRtyCfgtmp.field.LongRtyLimit;
1967 TxRtyCfg.field.ShortRtyLimit =
1968 TxRtyCfgtmp.field.ShortRtyLimit;
1969 RTMP_IO_WRITE32(pAd, TX_RTY_CFG, TxRtyCfg.word);
1970 }
1971 }
1972
1973 CurrRateIdx = pEntry->CurrTxRateIndex;
1974
1975 MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize,
1976 &InitTxRateIdx);
1977
1978 if (CurrRateIdx >= TableSize) {
1979 CurrRateIdx = TableSize - 1;
1980 }
1981 /* When switch from Fixed rate -> auto rate, the REAL TX rate might be different from pAd->CommonCfg.TxRateIndex. */
1982 /* So need to sync here. */
1983 pCurrTxRate =
1984 (struct rt_rtmp_tx_rate_switch *) & pTable[(CurrRateIdx + 1) * 5];
1985 if ((pEntry->HTPhyMode.field.MCS != pCurrTxRate->CurrMCS)
1986 /*&& (pAd->StaCfg.bAutoTxRateSwitch == TRUE) */
1987 ) {
1988
1989 /* Need to sync Real Tx rate and our record. */
1990 /* Then return for next DRS. */
1991 pCurrTxRate =
1992 (struct rt_rtmp_tx_rate_switch *) & pTable[(InitTxRateIdx + 1)
1993 * 5];
1994 pEntry->CurrTxRateIndex = InitTxRateIdx;
1995 MlmeSetTxRate(pAd, pEntry, pCurrTxRate);
1996
1997 /* reset all OneSecTx counters */
1998 RESET_ONE_SEC_TX_CNT(pEntry);
1999 continue;
2000 }
2001 /* decide the next upgrade rate and downgrade rate, if any */
2002 if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1))) {
2003 UpRateIdx = CurrRateIdx + 1;
2004 DownRateIdx = CurrRateIdx - 1;
2005 } else if (CurrRateIdx == 0) {
2006 UpRateIdx = CurrRateIdx + 1;
2007 DownRateIdx = CurrRateIdx;
2008 } else if (CurrRateIdx == (TableSize - 1)) {
2009 UpRateIdx = CurrRateIdx;
2010 DownRateIdx = CurrRateIdx - 1;
2011 }
2012
2013 pCurrTxRate =
2014 (struct rt_rtmp_tx_rate_switch *) & pTable[(CurrRateIdx + 1) * 5];
2015
2016 if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX)) {
2017 TrainUp =
2018 (pCurrTxRate->TrainUp +
2019 (pCurrTxRate->TrainUp >> 1));
2020 TrainDown =
2021 (pCurrTxRate->TrainDown +
2022 (pCurrTxRate->TrainDown >> 1));
2023 } else {
2024 TrainUp = pCurrTxRate->TrainUp;
2025 TrainDown = pCurrTxRate->TrainDown;
2026 }
2027
2028 /*pAd->DrsCounters.LastTimeTxRateChangeAction = pAd->DrsCounters.LastSecTxRateChangeAction; */
2029
2030 /* */
2031 /* Keep the last time TxRateChangeAction status. */
2032 /* */
2033 pEntry->LastTimeTxRateChangeAction =
2034 pEntry->LastSecTxRateChangeAction;
2035
2036 /* */
2037 /* CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI */
2038 /* (criteria copied from RT2500 for Netopia case) */
2039 /* */
2040 if (TxTotalCnt <= 15) {
2041 char idx = 0;
2042 u8 TxRateIdx;
2043 u8 MCS0 = 0, MCS1 = 0, MCS2 = 0, MCS3 = 0, MCS4 =
2044 0, MCS5 = 0, MCS6 = 0, MCS7 = 0;
2045 u8 MCS12 = 0, MCS13 = 0, MCS14 = 0, MCS15 = 0;
2046 u8 MCS20 = 0, MCS21 = 0, MCS22 = 0, MCS23 = 0; /* 3*3 */
2047
2048 /* check the existence and index of each needed MCS */
2049 while (idx < pTable[0]) {
2050 pCurrTxRate =
2051 (struct rt_rtmp_tx_rate_switch *) & pTable[(idx + 1) *
2052 5];
2053
2054 if (pCurrTxRate->CurrMCS == MCS_0) {
2055 MCS0 = idx;
2056 } else if (pCurrTxRate->CurrMCS == MCS_1) {
2057 MCS1 = idx;
2058 } else if (pCurrTxRate->CurrMCS == MCS_2) {
2059 MCS2 = idx;
2060 } else if (pCurrTxRate->CurrMCS == MCS_3) {
2061 MCS3 = idx;
2062 } else if (pCurrTxRate->CurrMCS == MCS_4) {
2063 MCS4 = idx;
2064 } else if (pCurrTxRate->CurrMCS == MCS_5) {
2065 MCS5 = idx;
2066 } else if (pCurrTxRate->CurrMCS == MCS_6) {
2067 MCS6 = idx;
2068 }
2069 /*else if (pCurrTxRate->CurrMCS == MCS_7) */
2070 else if ((pCurrTxRate->CurrMCS == MCS_7) && (pCurrTxRate->ShortGI == GI_800)) /* prevent the highest MCS using short GI when 1T and low throughput */
2071 {
2072 MCS7 = idx;
2073 } else if (pCurrTxRate->CurrMCS == MCS_12) {
2074 MCS12 = idx;
2075 } else if (pCurrTxRate->CurrMCS == MCS_13) {
2076 MCS13 = idx;
2077 } else if (pCurrTxRate->CurrMCS == MCS_14) {
2078 MCS14 = idx;
2079 }
2080 else if ((pCurrTxRate->CurrMCS == MCS_15) && (pCurrTxRate->ShortGI == GI_800)) /*we hope to use ShortGI as initial rate, however Atheros's chip has bugs when short GI */
2081 {
2082 MCS15 = idx;
2083 } else if (pCurrTxRate->CurrMCS == MCS_20) /* 3*3 */
2084 {
2085 MCS20 = idx;
2086 } else if (pCurrTxRate->CurrMCS == MCS_21) {
2087 MCS21 = idx;
2088 } else if (pCurrTxRate->CurrMCS == MCS_22) {
2089 MCS22 = idx;
2090 } else if (pCurrTxRate->CurrMCS == MCS_23) {
2091 MCS23 = idx;
2092 }
2093 idx++;
2094 }
2095
2096 if (pAd->LatchRfRegs.Channel <= 14) {
2097 if (pAd->NicConfig2.field.ExternalLNAForG) {
2098 RssiOffset = 2;
2099 } else {
2100 RssiOffset = 5;
2101 }
2102 } else {
2103 if (pAd->NicConfig2.field.ExternalLNAForA) {
2104 RssiOffset = 5;
2105 } else {
2106 RssiOffset = 8;
2107 }
2108 }
2109
2110 /*if (MCS15) */
2111 if ((pTable == RateSwitchTable11BGN3S) || (pTable == RateSwitchTable11N3S) || (pTable == RateSwitchTable)) { /* N mode with 3 stream // 3*3 */
2112 if (MCS23 && (Rssi >= -70))
2113 TxRateIdx = MCS23;
2114 else if (MCS22 && (Rssi >= -72))
2115 TxRateIdx = MCS22;
2116 else if (MCS21 && (Rssi >= -76))
2117 TxRateIdx = MCS21;
2118 else if (MCS20 && (Rssi >= -78))
2119 TxRateIdx = MCS20;
2120 else if (MCS4 && (Rssi >= -82))
2121 TxRateIdx = MCS4;
2122 else if (MCS3 && (Rssi >= -84))
2123 TxRateIdx = MCS3;
2124 else if (MCS2 && (Rssi >= -86))
2125 TxRateIdx = MCS2;
2126 else if (MCS1 && (Rssi >= -88))
2127 TxRateIdx = MCS1;
2128 else
2129 TxRateIdx = MCS0;
2130 }
2131/* else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) ||(pTable == RateSwitchTable11N2S) ||(pTable == RateSwitchTable11N2SForABand) || (pTable == RateSwitchTable)) */
2132 else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) || (pTable == RateSwitchTable11N2S) || (pTable == RateSwitchTable11N2SForABand)) /* 3*3 */
2133 { /* N mode with 2 stream */
2134 if (MCS15 && (Rssi >= (-70 + RssiOffset)))
2135 TxRateIdx = MCS15;
2136 else if (MCS14 && (Rssi >= (-72 + RssiOffset)))
2137 TxRateIdx = MCS14;
2138 else if (MCS13 && (Rssi >= (-76 + RssiOffset)))
2139 TxRateIdx = MCS13;
2140 else if (MCS12 && (Rssi >= (-78 + RssiOffset)))
2141 TxRateIdx = MCS12;
2142 else if (MCS4 && (Rssi >= (-82 + RssiOffset)))
2143 TxRateIdx = MCS4;
2144 else if (MCS3 && (Rssi >= (-84 + RssiOffset)))
2145 TxRateIdx = MCS3;
2146 else if (MCS2 && (Rssi >= (-86 + RssiOffset)))
2147 TxRateIdx = MCS2;
2148 else if (MCS1 && (Rssi >= (-88 + RssiOffset)))
2149 TxRateIdx = MCS1;
2150 else
2151 TxRateIdx = MCS0;
2152 } else if ((pTable == RateSwitchTable11BGN1S) || (pTable == RateSwitchTable11N1S)) { /* N mode with 1 stream */
2153 if (MCS7 && (Rssi > (-72 + RssiOffset)))
2154 TxRateIdx = MCS7;
2155 else if (MCS6 && (Rssi > (-74 + RssiOffset)))
2156 TxRateIdx = MCS6;
2157 else if (MCS5 && (Rssi > (-77 + RssiOffset)))
2158 TxRateIdx = MCS5;
2159 else if (MCS4 && (Rssi > (-79 + RssiOffset)))
2160 TxRateIdx = MCS4;
2161 else if (MCS3 && (Rssi > (-81 + RssiOffset)))
2162 TxRateIdx = MCS3;
2163 else if (MCS2 && (Rssi > (-83 + RssiOffset)))
2164 TxRateIdx = MCS2;
2165 else if (MCS1 && (Rssi > (-86 + RssiOffset)))
2166 TxRateIdx = MCS1;
2167 else
2168 TxRateIdx = MCS0;
2169 } else { /* Legacy mode */
2170 if (MCS7 && (Rssi > -70))
2171 TxRateIdx = MCS7;
2172 else if (MCS6 && (Rssi > -74))
2173 TxRateIdx = MCS6;
2174 else if (MCS5 && (Rssi > -78))
2175 TxRateIdx = MCS5;
2176 else if (MCS4 && (Rssi > -82))
2177 TxRateIdx = MCS4;
2178 else if (MCS4 == 0) /* for B-only mode */
2179 TxRateIdx = MCS3;
2180 else if (MCS3 && (Rssi > -85))
2181 TxRateIdx = MCS3;
2182 else if (MCS2 && (Rssi > -87))
2183 TxRateIdx = MCS2;
2184 else if (MCS1 && (Rssi > -90))
2185 TxRateIdx = MCS1;
2186 else
2187 TxRateIdx = MCS0;
2188 }
2189
2190 /* if (TxRateIdx != pAd->CommonCfg.TxRateIndex) */
2191 {
2192 pEntry->CurrTxRateIndex = TxRateIdx;
2193 pNextTxRate =
2194 (struct rt_rtmp_tx_rate_switch *) &
2195 pTable[(pEntry->CurrTxRateIndex + 1) * 5];
2196 MlmeSetTxRate(pAd, pEntry, pNextTxRate);
2197 }
2198
2199 NdisZeroMemory(pEntry->TxQuality,
2200 sizeof(u16)*
2201 MAX_STEP_OF_TX_RATE_SWITCH);
2202 NdisZeroMemory(pEntry->PER,
2203 sizeof(u8)*
2204 MAX_STEP_OF_TX_RATE_SWITCH);
2205 pEntry->fLastSecAccordingRSSI = TRUE;
2206 /* reset all OneSecTx counters */
2207 RESET_ONE_SEC_TX_CNT(pEntry);
2208
2209 continue;
2210 }
2211
2212 if (pEntry->fLastSecAccordingRSSI == TRUE) {
2213 pEntry->fLastSecAccordingRSSI = FALSE;
2214 pEntry->LastSecTxRateChangeAction = 0;
2215 /* reset all OneSecTx counters */
2216 RESET_ONE_SEC_TX_CNT(pEntry);
2217
2218 continue;
2219 }
2220
2221 do {
2222 BOOLEAN bTrainUpDown = FALSE;
2223
2224 pEntry->CurrTxRateStableTime++;
2225
2226 /* downgrade TX quality if PER >= Rate-Down threshold */
2227 if (TxErrorRatio >= TrainDown) {
2228 bTrainUpDown = TRUE;
2229 pEntry->TxQuality[CurrRateIdx] =
2230 DRS_TX_QUALITY_WORST_BOUND;
2231 }
2232 /* upgrade TX quality if PER <= Rate-Up threshold */
2233 else if (TxErrorRatio <= TrainUp) {
2234 bTrainUpDown = TRUE;
2235 bUpgradeQuality = TRUE;
2236 if (pEntry->TxQuality[CurrRateIdx])
2237 pEntry->TxQuality[CurrRateIdx]--; /* quality very good in CurrRate */
2238
2239 if (pEntry->TxRateUpPenalty)
2240 pEntry->TxRateUpPenalty--;
2241 else if (pEntry->TxQuality[UpRateIdx])
2242 pEntry->TxQuality[UpRateIdx]--; /* may improve next UP rate's quality */
2243 }
2244
2245 pEntry->PER[CurrRateIdx] = (u8)TxErrorRatio;
2246
2247 if (bTrainUpDown) {
2248 /* perform DRS - consider TxRate Down first, then rate up. */
2249 if ((CurrRateIdx != DownRateIdx)
2250 && (pEntry->TxQuality[CurrRateIdx] >=
2251 DRS_TX_QUALITY_WORST_BOUND)) {
2252 pEntry->CurrTxRateIndex = DownRateIdx;
2253 } else if ((CurrRateIdx != UpRateIdx)
2254 && (pEntry->TxQuality[UpRateIdx] <=
2255 0)) {
2256 pEntry->CurrTxRateIndex = UpRateIdx;
2257 }
2258 }
2259 } while (FALSE);
2260
2261 /* if rate-up happen, clear all bad history of all TX rates */
2262 if (pEntry->CurrTxRateIndex > CurrRateIdx) {
2263 pEntry->CurrTxRateStableTime = 0;
2264 pEntry->TxRateUpPenalty = 0;
2265 pEntry->LastSecTxRateChangeAction = 1; /* rate UP */
2266 NdisZeroMemory(pEntry->TxQuality,
2267 sizeof(u16)*
2268 MAX_STEP_OF_TX_RATE_SWITCH);
2269 NdisZeroMemory(pEntry->PER,
2270 sizeof(u8)*
2271 MAX_STEP_OF_TX_RATE_SWITCH);
2272
2273 /* */
2274 /* For TxRate fast train up */
2275 /* */
2276 if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning) {
2277 RTMPSetTimer(&pAd->StaCfg.
2278 StaQuickResponeForRateUpTimer,
2279 100);
2280
2281 pAd->StaCfg.
2282 StaQuickResponeForRateUpTimerRunning = TRUE;
2283 }
2284 bTxRateChanged = TRUE;
2285 }
2286 /* if rate-down happen, only clear DownRate's bad history */
2287 else if (pEntry->CurrTxRateIndex < CurrRateIdx) {
2288 pEntry->CurrTxRateStableTime = 0;
2289 pEntry->TxRateUpPenalty = 0; /* no penalty */
2290 pEntry->LastSecTxRateChangeAction = 2; /* rate DOWN */
2291 pEntry->TxQuality[pEntry->CurrTxRateIndex] = 0;
2292 pEntry->PER[pEntry->CurrTxRateIndex] = 0;
2293
2294 /* */
2295 /* For TxRate fast train down */
2296 /* */
2297 if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning) {
2298 RTMPSetTimer(&pAd->StaCfg.
2299 StaQuickResponeForRateUpTimer,
2300 100);
2301
2302 pAd->StaCfg.
2303 StaQuickResponeForRateUpTimerRunning = TRUE;
2304 }
2305 bTxRateChanged = TRUE;
2306 } else {
2307 pEntry->LastSecTxRateChangeAction = 0; /* rate no change */
2308 bTxRateChanged = FALSE;
2309 }
2310
2311 pEntry->LastTxOkCount = TxSuccess;
2312 {
2313 u8 tmpTxRate;
2314
2315 /* to fix tcp ack issue */
2316 if (!bTxRateChanged
2317 && (pAd->RalinkCounters.OneSecReceivedByteCount >
2318 (pAd->RalinkCounters.
2319 OneSecTransmittedByteCount * 5))) {
2320 tmpTxRate = DownRateIdx;
2321 DBGPRINT_RAW(RT_DEBUG_TRACE,
2322 ("DRS: Rx(%d) is 5 times larger than Tx(%d), use low rate (curr=%d, tmp=%d)\n",
2323 pAd->RalinkCounters.
2324 OneSecReceivedByteCount,
2325 pAd->RalinkCounters.
2326 OneSecTransmittedByteCount,
2327 pEntry->CurrTxRateIndex,
2328 tmpTxRate));
2329 } else {
2330 tmpTxRate = pEntry->CurrTxRateIndex;
2331 }
2332
2333 pNextTxRate =
2334 (struct rt_rtmp_tx_rate_switch *) & pTable[(tmpTxRate + 1) *
2335 5];
2336 }
2337 if (bTxRateChanged && pNextTxRate) {
2338 MlmeSetTxRate(pAd, pEntry, pNextTxRate);
2339 }
2340 /* reset all OneSecTx counters */
2341 RESET_ONE_SEC_TX_CNT(pEntry);
2342 }
2343}
2344
2345/*
2346 ========================================================================
2347 Routine Description:
2348 Station side, Auto TxRate faster train up timer call back function.
2349
2350 Arguments:
2351 SystemSpecific1 - Not used.
2352 FunctionContext - Pointer to our Adapter context.
2353 SystemSpecific2 - Not used.
2354 SystemSpecific3 - Not used.
2355
2356 Return Value:
2357 None
2358
2359 ========================================================================
2360*/
2361void StaQuickResponeForRateUpExec(void *SystemSpecific1,
2362 void *FunctionContext,
2363 void *SystemSpecific2,
2364 void *SystemSpecific3)
2365{
2366 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
2367 u8 UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx = 0;
2368 unsigned long TxTotalCnt;
2369 unsigned long TxErrorRatio = 0;
2370 BOOLEAN bTxRateChanged; /*, bUpgradeQuality = FALSE; */
2371 struct rt_rtmp_tx_rate_switch *pCurrTxRate, *pNextTxRate = NULL;
2372 u8 *pTable;
2373 u8 TableSize = 0;
2374 u8 InitTxRateIdx = 0, TrainUp, TrainDown;
2375 TX_STA_CNT1_STRUC StaTx1;
2376 TX_STA_CNT0_STRUC TxStaCnt0;
2377 char Rssi, ratio;
2378 unsigned long TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0;
2379 struct rt_mac_table_entry *pEntry;
2380 unsigned long i;
2381
2382 pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE;
2383
2384 /* */
2385 /* walk through MAC table, see if need to change AP's TX rate toward each entry */
2386 /* */
2387 for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) {
2388 pEntry = &pAd->MacTab.Content[i];
2389
2390 /* check if this entry need to switch rate automatically */
2391 if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE)
2392 continue;
2393
2394 if (INFRA_ON(pAd) && (i == 1))
2395 Rssi = RTMPMaxRssi(pAd,
2396 pAd->StaCfg.RssiSample.AvgRssi0,
2397 pAd->StaCfg.RssiSample.AvgRssi1,
2398 pAd->StaCfg.RssiSample.AvgRssi2);
2399 else
2400 Rssi = RTMPMaxRssi(pAd,
2401 pEntry->RssiSample.AvgRssi0,
2402 pEntry->RssiSample.AvgRssi1,
2403 pEntry->RssiSample.AvgRssi2);
2404
2405 CurrRateIdx = pAd->CommonCfg.TxRateIndex;
2406
2407 MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize,
2408 &InitTxRateIdx);
2409
2410 /* decide the next upgrade rate and downgrade rate, if any */
2411 if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1))) {
2412 UpRateIdx = CurrRateIdx + 1;
2413 DownRateIdx = CurrRateIdx - 1;
2414 } else if (CurrRateIdx == 0) {
2415 UpRateIdx = CurrRateIdx + 1;
2416 DownRateIdx = CurrRateIdx;
2417 } else if (CurrRateIdx == (TableSize - 1)) {
2418 UpRateIdx = CurrRateIdx;
2419 DownRateIdx = CurrRateIdx - 1;
2420 }
2421
2422 pCurrTxRate =
2423 (struct rt_rtmp_tx_rate_switch *) & pTable[(CurrRateIdx + 1) * 5];
2424
2425 if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX)) {
2426 TrainUp =
2427 (pCurrTxRate->TrainUp +
2428 (pCurrTxRate->TrainUp >> 1));
2429 TrainDown =
2430 (pCurrTxRate->TrainDown +
2431 (pCurrTxRate->TrainDown >> 1));
2432 } else {
2433 TrainUp = pCurrTxRate->TrainUp;
2434 TrainDown = pCurrTxRate->TrainDown;
2435 }
2436
2437 if (pAd->MacTab.Size == 1) {
2438 /* Update statistic counter */
2439 RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
2440 RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
2441
2442 TxRetransmit = StaTx1.field.TxRetransmit;
2443 TxSuccess = StaTx1.field.TxSuccess;
2444 TxFailCount = TxStaCnt0.field.TxFailCount;
2445 TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount;
2446
2447 pAd->RalinkCounters.OneSecTxRetryOkCount +=
2448 StaTx1.field.TxRetransmit;
2449 pAd->RalinkCounters.OneSecTxNoRetryOkCount +=
2450 StaTx1.field.TxSuccess;
2451 pAd->RalinkCounters.OneSecTxFailCount +=
2452 TxStaCnt0.field.TxFailCount;
2453 pAd->WlanCounters.TransmittedFragmentCount.u.LowPart +=
2454 StaTx1.field.TxSuccess;
2455 pAd->WlanCounters.RetryCount.u.LowPart +=
2456 StaTx1.field.TxRetransmit;
2457 pAd->WlanCounters.FailedCount.u.LowPart +=
2458 TxStaCnt0.field.TxFailCount;
2459
2460 if (TxTotalCnt)
2461 TxErrorRatio =
2462 ((TxRetransmit +
2463 TxFailCount) * 100) / TxTotalCnt;
2464 } else {
2465 TxTotalCnt = pEntry->OneSecTxNoRetryOkCount +
2466 pEntry->OneSecTxRetryOkCount +
2467 pEntry->OneSecTxFailCount;
2468
2469 if (TxTotalCnt)
2470 TxErrorRatio =
2471 ((pEntry->OneSecTxRetryOkCount +
2472 pEntry->OneSecTxFailCount) * 100) /
2473 TxTotalCnt;
2474 }
2475
2476 /* */
2477 /* CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI */
2478 /* (criteria copied from RT2500 for Netopia case) */
2479 /* */
2480 if (TxTotalCnt <= 12) {
2481 NdisZeroMemory(pAd->DrsCounters.TxQuality,
2482 sizeof(u16)*
2483 MAX_STEP_OF_TX_RATE_SWITCH);
2484 NdisZeroMemory(pAd->DrsCounters.PER,
2485 sizeof(u8)*
2486 MAX_STEP_OF_TX_RATE_SWITCH);
2487
2488 if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1)
2489 && (CurrRateIdx != DownRateIdx)) {
2490 pAd->CommonCfg.TxRateIndex = DownRateIdx;
2491 pAd->DrsCounters.TxQuality[CurrRateIdx] =
2492 DRS_TX_QUALITY_WORST_BOUND;
2493 } else
2494 if ((pAd->DrsCounters.LastSecTxRateChangeAction ==
2495 2) && (CurrRateIdx != UpRateIdx)) {
2496 pAd->CommonCfg.TxRateIndex = UpRateIdx;
2497 }
2498
2499 DBGPRINT_RAW(RT_DEBUG_TRACE,
2500 ("QuickDRS: TxTotalCnt <= 15, train back to original rate \n"));
2501 return;
2502 }
2503
2504 do {
2505 unsigned long OneSecTxNoRetryOKRationCount;
2506
2507 if (pAd->DrsCounters.LastTimeTxRateChangeAction == 0)
2508 ratio = 5;
2509 else
2510 ratio = 4;
2511
2512 /* downgrade TX quality if PER >= Rate-Down threshold */
2513 if (TxErrorRatio >= TrainDown) {
2514 pAd->DrsCounters.TxQuality[CurrRateIdx] =
2515 DRS_TX_QUALITY_WORST_BOUND;
2516 }
2517
2518 pAd->DrsCounters.PER[CurrRateIdx] =
2519 (u8)TxErrorRatio;
2520
2521 OneSecTxNoRetryOKRationCount = (TxSuccess * ratio);
2522
2523 /* perform DRS - consider TxRate Down first, then rate up. */
2524 if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1)
2525 && (CurrRateIdx != DownRateIdx)) {
2526 if ((pAd->DrsCounters.LastTxOkCount + 2) >=
2527 OneSecTxNoRetryOKRationCount) {
2528 pAd->CommonCfg.TxRateIndex =
2529 DownRateIdx;
2530 pAd->DrsCounters.
2531 TxQuality[CurrRateIdx] =
2532 DRS_TX_QUALITY_WORST_BOUND;
2533
2534 }
2535
2536 } else
2537 if ((pAd->DrsCounters.LastSecTxRateChangeAction ==
2538 2) && (CurrRateIdx != UpRateIdx)) {
2539 if ((TxErrorRatio >= 50)
2540 || (TxErrorRatio >= TrainDown)) {
2541
2542 } else if ((pAd->DrsCounters.LastTxOkCount + 2)
2543 >= OneSecTxNoRetryOKRationCount) {
2544 pAd->CommonCfg.TxRateIndex = UpRateIdx;
2545 }
2546 }
2547 } while (FALSE);
2548
2549 /* if rate-up happen, clear all bad history of all TX rates */
2550 if (pAd->CommonCfg.TxRateIndex > CurrRateIdx) {
2551 pAd->DrsCounters.TxRateUpPenalty = 0;
2552 NdisZeroMemory(pAd->DrsCounters.TxQuality,
2553 sizeof(u16)*
2554 MAX_STEP_OF_TX_RATE_SWITCH);
2555 NdisZeroMemory(pAd->DrsCounters.PER,
2556 sizeof(u8)*
2557 MAX_STEP_OF_TX_RATE_SWITCH);
2558 bTxRateChanged = TRUE;
2559 }
2560 /* if rate-down happen, only clear DownRate's bad history */
2561 else if (pAd->CommonCfg.TxRateIndex < CurrRateIdx) {
2562 DBGPRINT_RAW(RT_DEBUG_TRACE,
2563 ("QuickDRS: --TX rate from %d to %d \n",
2564 CurrRateIdx, pAd->CommonCfg.TxRateIndex));
2565
2566 pAd->DrsCounters.TxRateUpPenalty = 0; /* no penalty */
2567 pAd->DrsCounters.TxQuality[pAd->CommonCfg.TxRateIndex] =
2568 0;
2569 pAd->DrsCounters.PER[pAd->CommonCfg.TxRateIndex] = 0;
2570 bTxRateChanged = TRUE;
2571 } else {
2572 bTxRateChanged = FALSE;
2573 }
2574
2575 pNextTxRate =
2576 (struct rt_rtmp_tx_rate_switch *) &
2577 pTable[(pAd->CommonCfg.TxRateIndex + 1) * 5];
2578 if (bTxRateChanged && pNextTxRate) {
2579 MlmeSetTxRate(pAd, pEntry, pNextTxRate);
2580 }
2581 }
2582}
2583
2584/*
2585 ==========================================================================
2586 Description:
2587 This routine is executed periodically inside MlmePeriodicExec() after
2588 association with an AP.
2589 It checks if StaCfg.Psm is consistent with user policy (recorded in
2590 StaCfg.WindowsPowerMode). If not, enforce user policy. However,
2591 there're some conditions to consider:
2592 1. we don't support power-saving in ADHOC mode, so Psm=PWR_ACTIVE all
2593 the time when Mibss==TRUE
2594 2. When link up in INFRA mode, Psm should not be switch to PWR_SAVE
2595 if outgoing traffic available in TxRing or MgmtRing.
2596 Output:
2597 1. change pAd->StaCfg.Psm to PWR_SAVE or leave it untouched
2598
2599 IRQL = DISPATCH_LEVEL
2600
2601 ==========================================================================
2602 */
2603void MlmeCheckPsmChange(struct rt_rtmp_adapter *pAd, unsigned long Now32)
2604{
2605 unsigned long PowerMode;
2606
2607 /* condition - */
2608 /* 1. Psm maybe ON only happen in INFRASTRUCTURE mode */
2609 /* 2. user wants either MAX_PSP or FAST_PSP */
2610 /* 3. but current psm is not in PWR_SAVE */
2611 /* 4. CNTL state machine is not doing SCANning */
2612 /* 5. no TX SUCCESS event for the past 1-sec period */
2613 PowerMode = pAd->StaCfg.WindowsPowerMode;
2614
2615 if (INFRA_ON(pAd) &&
2616 (PowerMode != Ndis802_11PowerModeCAM) &&
2617 (pAd->StaCfg.Psm == PWR_ACTIVE) &&
2618/* (! RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) */
2619 (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) &&
2620 RTMP_TEST_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP)
2621 /*&&
2622 (pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) &&
2623 (pAd->RalinkCounters.OneSecTxRetryOkCount == 0) */
2624 ) {
2625 NdisGetSystemUpTime(&pAd->Mlme.LastSendNULLpsmTime);
2626 pAd->RalinkCounters.RxCountSinceLastNULL = 0;
2627 RTMP_SET_PSM_BIT(pAd, PWR_SAVE);
2628 if (!
2629 (pAd->CommonCfg.bAPSDCapable
2630 && pAd->CommonCfg.APEdcaParm.bAPSDCapable)) {
2631 RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE);
2632 } else {
2633 RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
2634 }
2635 }
2636}
2637
2638/* IRQL = PASSIVE_LEVEL */
2639/* IRQL = DISPATCH_LEVEL */
2640void MlmeSetPsmBit(struct rt_rtmp_adapter *pAd, u16 psm)
2641{
2642 AUTO_RSP_CFG_STRUC csr4;
2643
2644 pAd->StaCfg.Psm = psm;
2645 RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word);
2646 csr4.field.AckCtsPsmBit = (psm == PWR_SAVE) ? 1 : 0;
2647 RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word);
2648
2649 DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetPsmBit = %d\n", psm));
2650}
2651
2652/*
2653 ==========================================================================
2654 Description:
2655 This routine calculates TxPER, RxPER of the past N-sec period. And
2656 according to the calculation result, ChannelQuality is calculated here
2657 to decide if current AP is still doing the job.
2658
2659 If ChannelQuality is not good, a ROAMing attempt may be tried later.
2660 Output:
2661 StaCfg.ChannelQuality - 0..100
2662
2663 IRQL = DISPATCH_LEVEL
2664
2665 NOTE: This routine decide channle quality based on RX CRC error ratio.
2666 Caller should make sure a function call to NICUpdateRawCounters(pAd)
2667 is performed right before this routine, so that this routine can decide
2668 channel quality based on the most up-to-date information
2669 ==========================================================================
2670 */
2671void MlmeCalculateChannelQuality(struct rt_rtmp_adapter *pAd,
2672 struct rt_mac_table_entry *pMacEntry, unsigned long Now32)
2673{
2674 unsigned long TxOkCnt, TxCnt, TxPER, TxPRR;
2675 unsigned long RxCnt, RxPER;
2676 u8 NorRssi;
2677 char MaxRssi;
2678 struct rt_rssi_sample *pRssiSample = NULL;
2679 u32 OneSecTxNoRetryOkCount = 0;
2680 u32 OneSecTxRetryOkCount = 0;
2681 u32 OneSecTxFailCount = 0;
2682 u32 OneSecRxOkCnt = 0;
2683 u32 OneSecRxFcsErrCnt = 0;
2684 unsigned long ChannelQuality = 0; /* 0..100, Channel Quality Indication for Roaming */
2685 unsigned long BeaconLostTime = pAd->StaCfg.BeaconLostTime;
2686
2687 if (pAd->OpMode == OPMODE_STA) {
2688 pRssiSample = &pAd->StaCfg.RssiSample;
2689 OneSecTxNoRetryOkCount =
2690 pAd->RalinkCounters.OneSecTxNoRetryOkCount;
2691 OneSecTxRetryOkCount = pAd->RalinkCounters.OneSecTxRetryOkCount;
2692 OneSecTxFailCount = pAd->RalinkCounters.OneSecTxFailCount;
2693 OneSecRxOkCnt = pAd->RalinkCounters.OneSecRxOkCnt;
2694 OneSecRxFcsErrCnt = pAd->RalinkCounters.OneSecRxFcsErrCnt;
2695 }
2696
2697 MaxRssi = RTMPMaxRssi(pAd, pRssiSample->LastRssi0,
2698 pRssiSample->LastRssi1, pRssiSample->LastRssi2);
2699
2700 /* */
2701 /* calculate TX packet error ratio and TX retry ratio - if too few TX samples, skip TX related statistics */
2702 /* */
2703 TxOkCnt = OneSecTxNoRetryOkCount + OneSecTxRetryOkCount;
2704 TxCnt = TxOkCnt + OneSecTxFailCount;
2705 if (TxCnt < 5) {
2706 TxPER = 0;
2707 TxPRR = 0;
2708 } else {
2709 TxPER = (OneSecTxFailCount * 100) / TxCnt;
2710 TxPRR = ((TxCnt - OneSecTxNoRetryOkCount) * 100) / TxCnt;
2711 }
2712
2713 /* */
2714 /* calculate RX PER - don't take RxPER into consideration if too few sample */
2715 /* */
2716 RxCnt = OneSecRxOkCnt + OneSecRxFcsErrCnt;
2717 if (RxCnt < 5)
2718 RxPER = 0;
2719 else
2720 RxPER = (OneSecRxFcsErrCnt * 100) / RxCnt;
2721
2722 /* */
2723 /* decide ChannelQuality based on: 1)last BEACON received time, 2)last RSSI, 3)TxPER, and 4)RxPER */
2724 /* */
2725 if ((pAd->OpMode == OPMODE_STA) && INFRA_ON(pAd) && (OneSecTxNoRetryOkCount < 2) && /* no heavy traffic */
2726 ((pAd->StaCfg.LastBeaconRxTime + BeaconLostTime) < Now32)) {
2727 DBGPRINT(RT_DEBUG_TRACE,
2728 ("BEACON lost > %ld msec with TxOkCnt=%ld -> CQI=0\n",
2729 BeaconLostTime, TxOkCnt));
2730 ChannelQuality = 0;
2731 } else {
2732 /* Normalize Rssi */
2733 if (MaxRssi > -40)
2734 NorRssi = 100;
2735 else if (MaxRssi < -90)
2736 NorRssi = 0;
2737 else
2738 NorRssi = (MaxRssi + 90) * 2;
2739
2740 /* ChannelQuality = W1*RSSI + W2*TxPRR + W3*RxPER (RSSI 0..100), (TxPER 100..0), (RxPER 100..0) */
2741 ChannelQuality = (RSSI_WEIGHTING * NorRssi +
2742 TX_WEIGHTING * (100 - TxPRR) +
2743 RX_WEIGHTING * (100 - RxPER)) / 100;
2744 }
2745
2746 if (pAd->OpMode == OPMODE_STA)
2747 pAd->Mlme.ChannelQuality =
2748 (ChannelQuality > 100) ? 100 : ChannelQuality;
2749
2750}
2751
2752/* IRQL = DISPATCH_LEVEL */
2753void MlmeSetTxPreamble(struct rt_rtmp_adapter *pAd, u16 TxPreamble)
2754{
2755 AUTO_RSP_CFG_STRUC csr4;
2756
2757 /* */
2758 /* Always use Long preamble before verifiation short preamble functionality works well. */
2759 /* Todo: remove the following line if short preamble functionality works */
2760 /* */
2761 /*TxPreamble = Rt802_11PreambleLong; */
2762
2763 RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word);
2764 if (TxPreamble == Rt802_11PreambleLong) {
2765 DBGPRINT(RT_DEBUG_TRACE,
2766 ("MlmeSetTxPreamble (= long PREAMBLE)\n"));
2767 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
2768 csr4.field.AutoResponderPreamble = 0;
2769 } else {
2770 /* NOTE: 1Mbps should always use long preamble */
2771 DBGPRINT(RT_DEBUG_TRACE,
2772 ("MlmeSetTxPreamble (= short PREAMBLE)\n"));
2773 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED);
2774 csr4.field.AutoResponderPreamble = 1;
2775 }
2776
2777 RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word);
2778}
2779
2780/*
2781 ==========================================================================
2782 Description:
2783 Update basic rate bitmap
2784 ==========================================================================
2785 */
2786
2787void UpdateBasicRateBitmap(struct rt_rtmp_adapter *pAdapter)
2788{
2789 int i, j;
2790 /* 1 2 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */
2791 u8 rate[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 };
2792 u8 *sup_p = pAdapter->CommonCfg.SupRate;
2793 u8 *ext_p = pAdapter->CommonCfg.ExtRate;
2794 unsigned long bitmap = pAdapter->CommonCfg.BasicRateBitmap;
2795
2796 /* if A mode, always use fix BasicRateBitMap */
2797 /*if (pAdapter->CommonCfg.Channel == PHY_11A) */
2798 if (pAdapter->CommonCfg.Channel > 14)
2799 pAdapter->CommonCfg.BasicRateBitmap = 0x150; /* 6, 12, 24M */
2800 /* End of if */
2801
2802 if (pAdapter->CommonCfg.BasicRateBitmap > 4095) {
2803 /* (2 ^ MAX_LEN_OF_SUPPORTED_RATES) -1 */
2804 return;
2805 }
2806 /* End of if */
2807 for (i = 0; i < MAX_LEN_OF_SUPPORTED_RATES; i++) {
2808 sup_p[i] &= 0x7f;
2809 ext_p[i] &= 0x7f;
2810 } /* End of for */
2811
2812 for (i = 0; i < MAX_LEN_OF_SUPPORTED_RATES; i++) {
2813 if (bitmap & (1 << i)) {
2814 for (j = 0; j < MAX_LEN_OF_SUPPORTED_RATES; j++) {
2815 if (sup_p[j] == rate[i])
2816 sup_p[j] |= 0x80;
2817 /* End of if */
2818 } /* End of for */
2819
2820 for (j = 0; j < MAX_LEN_OF_SUPPORTED_RATES; j++) {
2821 if (ext_p[j] == rate[i])
2822 ext_p[j] |= 0x80;
2823 /* End of if */
2824 } /* End of for */
2825 } /* End of if */
2826 } /* End of for */
2827} /* End of UpdateBasicRateBitmap */
2828
2829/* IRQL = PASSIVE_LEVEL */
2830/* IRQL = DISPATCH_LEVEL */
2831/* bLinkUp is to identify the initial link speed. */
2832/* TRUE indicates the rate update at linkup, we should not try to set the rate at 54Mbps. */
2833void MlmeUpdateTxRates(struct rt_rtmp_adapter *pAd, IN BOOLEAN bLinkUp, u8 apidx)
2834{
2835 int i, num;
2836 u8 Rate = RATE_6, MaxDesire = RATE_1, MaxSupport = RATE_1;
2837 u8 MinSupport = RATE_54;
2838 unsigned long BasicRateBitmap = 0;
2839 u8 CurrBasicRate = RATE_1;
2840 u8 *pSupRate, SupRateLen, *pExtRate, ExtRateLen;
2841 PHTTRANSMIT_SETTING pHtPhy = NULL;
2842 PHTTRANSMIT_SETTING pMaxHtPhy = NULL;
2843 PHTTRANSMIT_SETTING pMinHtPhy = NULL;
2844 BOOLEAN *auto_rate_cur_p;
2845 u8 HtMcs = MCS_AUTO;
2846
2847 /* find max desired rate */
2848 UpdateBasicRateBitmap(pAd);
2849
2850 num = 0;
2851 auto_rate_cur_p = NULL;
2852 for (i = 0; i < MAX_LEN_OF_SUPPORTED_RATES; i++) {
2853 switch (pAd->CommonCfg.DesireRate[i] & 0x7f) {
2854 case 2:
2855 Rate = RATE_1;
2856 num++;
2857 break;
2858 case 4:
2859 Rate = RATE_2;
2860 num++;
2861 break;
2862 case 11:
2863 Rate = RATE_5_5;
2864 num++;
2865 break;
2866 case 22:
2867 Rate = RATE_11;
2868 num++;
2869 break;
2870 case 12:
2871 Rate = RATE_6;
2872 num++;
2873 break;
2874 case 18:
2875 Rate = RATE_9;
2876 num++;
2877 break;
2878 case 24:
2879 Rate = RATE_12;
2880 num++;
2881 break;
2882 case 36:
2883 Rate = RATE_18;
2884 num++;
2885 break;
2886 case 48:
2887 Rate = RATE_24;
2888 num++;
2889 break;
2890 case 72:
2891 Rate = RATE_36;
2892 num++;
2893 break;
2894 case 96:
2895 Rate = RATE_48;
2896 num++;
2897 break;
2898 case 108:
2899 Rate = RATE_54;
2900 num++;
2901 break;
2902 /*default: Rate = RATE_1; break; */
2903 }
2904 if (MaxDesire < Rate)
2905 MaxDesire = Rate;
2906 }
2907
2908/*=========================================================================== */
2909/*=========================================================================== */
2910 {
2911 pHtPhy = &pAd->StaCfg.HTPhyMode;
2912 pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode;
2913 pMinHtPhy = &pAd->StaCfg.MinHTPhyMode;
2914
2915 auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch;
2916 HtMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS;
2917
2918 if ((pAd->StaCfg.BssType == BSS_ADHOC) &&
2919 (pAd->CommonCfg.PhyMode == PHY_11B) &&
2920 (MaxDesire > RATE_11)) {
2921 MaxDesire = RATE_11;
2922 }
2923 }
2924
2925 pAd->CommonCfg.MaxDesiredRate = MaxDesire;
2926 pMinHtPhy->word = 0;
2927 pMaxHtPhy->word = 0;
2928 pHtPhy->word = 0;
2929
2930 /* Auto rate switching is enabled only if more than one DESIRED RATES are */
2931 /* specified; otherwise disabled */
2932 if (num <= 1) {
2933 /*OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED); */
2934 /*pAd->CommonCfg.bAutoTxRateSwitch = FALSE; */
2935 *auto_rate_cur_p = FALSE;
2936 } else {
2937 /*OPSTATUS_SET_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED); */
2938 /*pAd->CommonCfg.bAutoTxRateSwitch = TRUE; */
2939 *auto_rate_cur_p = TRUE;
2940 }
2941
2942 if (HtMcs != MCS_AUTO) {
2943 /*OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED); */
2944 /*pAd->CommonCfg.bAutoTxRateSwitch = FALSE; */
2945 *auto_rate_cur_p = FALSE;
2946 } else {
2947 /*OPSTATUS_SET_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED); */
2948 /*pAd->CommonCfg.bAutoTxRateSwitch = TRUE; */
2949 *auto_rate_cur_p = TRUE;
2950 }
2951
2952 if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) {
2953 pSupRate = &pAd->StaActive.SupRate[0];
2954 pExtRate = &pAd->StaActive.ExtRate[0];
2955 SupRateLen = pAd->StaActive.SupRateLen;
2956 ExtRateLen = pAd->StaActive.ExtRateLen;
2957 } else {
2958 pSupRate = &pAd->CommonCfg.SupRate[0];
2959 pExtRate = &pAd->CommonCfg.ExtRate[0];
2960 SupRateLen = pAd->CommonCfg.SupRateLen;
2961 ExtRateLen = pAd->CommonCfg.ExtRateLen;
2962 }
2963
2964 /* find max supported rate */
2965 for (i = 0; i < SupRateLen; i++) {
2966 switch (pSupRate[i] & 0x7f) {
2967 case 2:
2968 Rate = RATE_1;
2969 if (pSupRate[i] & 0x80)
2970 BasicRateBitmap |= 0x0001;
2971 break;
2972 case 4:
2973 Rate = RATE_2;
2974 if (pSupRate[i] & 0x80)
2975 BasicRateBitmap |= 0x0002;
2976 break;
2977 case 11:
2978 Rate = RATE_5_5;
2979 if (pSupRate[i] & 0x80)
2980 BasicRateBitmap |= 0x0004;
2981 break;
2982 case 22:
2983 Rate = RATE_11;
2984 if (pSupRate[i] & 0x80)
2985 BasicRateBitmap |= 0x0008;
2986 break;
2987 case 12:
2988 Rate = RATE_6; /*if (pSupRate[i] & 0x80) */
2989 BasicRateBitmap |= 0x0010;
2990 break;
2991 case 18:
2992 Rate = RATE_9;
2993 if (pSupRate[i] & 0x80)
2994 BasicRateBitmap |= 0x0020;
2995 break;
2996 case 24:
2997 Rate = RATE_12; /*if (pSupRate[i] & 0x80) */
2998 BasicRateBitmap |= 0x0040;
2999 break;
3000 case 36:
3001 Rate = RATE_18;
3002 if (pSupRate[i] & 0x80)
3003 BasicRateBitmap |= 0x0080;
3004 break;
3005 case 48:
3006 Rate = RATE_24; /*if (pSupRate[i] & 0x80) */
3007 BasicRateBitmap |= 0x0100;
3008 break;
3009 case 72:
3010 Rate = RATE_36;
3011 if (pSupRate[i] & 0x80)
3012 BasicRateBitmap |= 0x0200;
3013 break;
3014 case 96:
3015 Rate = RATE_48;
3016 if (pSupRate[i] & 0x80)
3017 BasicRateBitmap |= 0x0400;
3018 break;
3019 case 108:
3020 Rate = RATE_54;
3021 if (pSupRate[i] & 0x80)
3022 BasicRateBitmap |= 0x0800;
3023 break;
3024 default:
3025 Rate = RATE_1;
3026 break;
3027 }
3028 if (MaxSupport < Rate)
3029 MaxSupport = Rate;
3030
3031 if (MinSupport > Rate)
3032 MinSupport = Rate;
3033 }
3034
3035 for (i = 0; i < ExtRateLen; i++) {
3036 switch (pExtRate[i] & 0x7f) {
3037 case 2:
3038 Rate = RATE_1;
3039 if (pExtRate[i] & 0x80)
3040 BasicRateBitmap |= 0x0001;
3041 break;
3042 case 4:
3043 Rate = RATE_2;
3044 if (pExtRate[i] & 0x80)
3045 BasicRateBitmap |= 0x0002;
3046 break;
3047 case 11:
3048 Rate = RATE_5_5;
3049 if (pExtRate[i] & 0x80)
3050 BasicRateBitmap |= 0x0004;
3051 break;
3052 case 22:
3053 Rate = RATE_11;
3054 if (pExtRate[i] & 0x80)
3055 BasicRateBitmap |= 0x0008;
3056 break;
3057 case 12:
3058 Rate = RATE_6; /*if (pExtRate[i] & 0x80) */
3059 BasicRateBitmap |= 0x0010;
3060 break;
3061 case 18:
3062 Rate = RATE_9;
3063 if (pExtRate[i] & 0x80)
3064 BasicRateBitmap |= 0x0020;
3065 break;
3066 case 24:
3067 Rate = RATE_12; /*if (pExtRate[i] & 0x80) */
3068 BasicRateBitmap |= 0x0040;
3069 break;
3070 case 36:
3071 Rate = RATE_18;
3072 if (pExtRate[i] & 0x80)
3073 BasicRateBitmap |= 0x0080;
3074 break;
3075 case 48:
3076 Rate = RATE_24; /*if (pExtRate[i] & 0x80) */
3077 BasicRateBitmap |= 0x0100;
3078 break;
3079 case 72:
3080 Rate = RATE_36;
3081 if (pExtRate[i] & 0x80)
3082 BasicRateBitmap |= 0x0200;
3083 break;
3084 case 96:
3085 Rate = RATE_48;
3086 if (pExtRate[i] & 0x80)
3087 BasicRateBitmap |= 0x0400;
3088 break;
3089 case 108:
3090 Rate = RATE_54;
3091 if (pExtRate[i] & 0x80)
3092 BasicRateBitmap |= 0x0800;
3093 break;
3094 default:
3095 Rate = RATE_1;
3096 break;
3097 }
3098 if (MaxSupport < Rate)
3099 MaxSupport = Rate;
3100
3101 if (MinSupport > Rate)
3102 MinSupport = Rate;
3103 }
3104
3105 RTMP_IO_WRITE32(pAd, LEGACY_BASIC_RATE, BasicRateBitmap);
3106
3107 /* bug fix */
3108 /* pAd->CommonCfg.BasicRateBitmap = BasicRateBitmap; */
3109
3110 /* calculate the exptected ACK rate for each TX rate. This info is used to caculate */
3111 /* the DURATION field of outgoing uniicast DATA/MGMT frame */
3112 for (i = 0; i < MAX_LEN_OF_SUPPORTED_RATES; i++) {
3113 if (BasicRateBitmap & (0x01 << i))
3114 CurrBasicRate = (u8)i;
3115 pAd->CommonCfg.ExpectedACKRate[i] = CurrBasicRate;
3116 }
3117
3118 DBGPRINT(RT_DEBUG_TRACE,
3119 ("MlmeUpdateTxRates[MaxSupport = %d] = MaxDesire %d Mbps\n",
3120 RateIdToMbps[MaxSupport], RateIdToMbps[MaxDesire]));
3121 /* max tx rate = min {max desire rate, max supported rate} */
3122 if (MaxSupport < MaxDesire)
3123 pAd->CommonCfg.MaxTxRate = MaxSupport;
3124 else
3125 pAd->CommonCfg.MaxTxRate = MaxDesire;
3126
3127 pAd->CommonCfg.MinTxRate = MinSupport;
3128 /* 2003-07-31 john - 2500 doesn't have good sensitivity at high OFDM rates. to increase the success */
3129 /* ratio of initial DHCP packet exchange, TX rate starts from a lower rate depending */
3130 /* on average RSSI */
3131 /* 1. RSSI >= -70db, start at 54 Mbps (short distance) */
3132 /* 2. -70 > RSSI >= -75, start at 24 Mbps (mid distance) */
3133 /* 3. -75 > RSSI, start at 11 Mbps (long distance) */
3134 if (*auto_rate_cur_p) {
3135 short dbm = 0;
3136
3137 dbm = pAd->StaCfg.RssiSample.AvgRssi0 - pAd->BbpRssiToDbmDelta;
3138
3139 if (bLinkUp == TRUE)
3140 pAd->CommonCfg.TxRate = RATE_24;
3141 else
3142 pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
3143
3144 if (dbm < -75)
3145 pAd->CommonCfg.TxRate = RATE_11;
3146 else if (dbm < -70)
3147 pAd->CommonCfg.TxRate = RATE_24;
3148
3149 /* should never exceed MaxTxRate (consider 11B-only mode) */
3150 if (pAd->CommonCfg.TxRate > pAd->CommonCfg.MaxTxRate)
3151 pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
3152
3153 pAd->CommonCfg.TxRateIndex = 0;
3154 } else {
3155 pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate;
3156 pHtPhy->field.MCS =
3157 (pAd->CommonCfg.MaxTxRate >
3158 3) ? (pAd->CommonCfg.MaxTxRate -
3159 4) : pAd->CommonCfg.MaxTxRate;
3160 pHtPhy->field.MODE =
3161 (pAd->CommonCfg.MaxTxRate > 3) ? MODE_OFDM : MODE_CCK;
3162
3163 pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC =
3164 pHtPhy->field.STBC;
3165 pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI =
3166 pHtPhy->field.ShortGI;
3167 pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS =
3168 pHtPhy->field.MCS;
3169 pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE =
3170 pHtPhy->field.MODE;
3171 }
3172
3173 if (pAd->CommonCfg.TxRate <= RATE_11) {
3174 pMaxHtPhy->field.MODE = MODE_CCK;
3175 pMaxHtPhy->field.MCS = pAd->CommonCfg.TxRate;
3176 pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate;
3177 } else {
3178 pMaxHtPhy->field.MODE = MODE_OFDM;
3179 pMaxHtPhy->field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.TxRate];
3180 if (pAd->CommonCfg.MinTxRate >= RATE_6
3181 && (pAd->CommonCfg.MinTxRate <= RATE_54)) {
3182 pMinHtPhy->field.MCS =
3183 OfdmRateToRxwiMCS[pAd->CommonCfg.MinTxRate];
3184 } else {
3185 pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate;
3186 }
3187 }
3188
3189 pHtPhy->word = (pMaxHtPhy->word);
3190 if (bLinkUp && (pAd->OpMode == OPMODE_STA)) {
3191 pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word = pHtPhy->word;
3192 pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word =
3193 pMaxHtPhy->word;
3194 pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word =
3195 pMinHtPhy->word;
3196 } else {
3197 switch (pAd->CommonCfg.PhyMode) {
3198 case PHY_11BG_MIXED:
3199 case PHY_11B:
3200 case PHY_11BGN_MIXED:
3201 pAd->CommonCfg.MlmeRate = RATE_1;
3202 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
3203 pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1;
3204
3205/*#ifdef WIFI_TEST */
3206 pAd->CommonCfg.RtsRate = RATE_11;
3207/*#else */
3208/* pAd->CommonCfg.RtsRate = RATE_1; */
3209/*#endif */
3210 break;
3211 case PHY_11G:
3212 case PHY_11A:
3213 case PHY_11AGN_MIXED:
3214 case PHY_11GN_MIXED:
3215 case PHY_11N_2_4G:
3216 case PHY_11AN_MIXED:
3217 case PHY_11N_5G:
3218 pAd->CommonCfg.MlmeRate = RATE_6;
3219 pAd->CommonCfg.RtsRate = RATE_6;
3220 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
3221 pAd->CommonCfg.MlmeTransmit.field.MCS =
3222 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
3223 break;
3224 case PHY_11ABG_MIXED:
3225 case PHY_11ABGN_MIXED:
3226 if (pAd->CommonCfg.Channel <= 14) {
3227 pAd->CommonCfg.MlmeRate = RATE_1;
3228 pAd->CommonCfg.RtsRate = RATE_1;
3229 pAd->CommonCfg.MlmeTransmit.field.MODE =
3230 MODE_CCK;
3231 pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1;
3232 } else {
3233 pAd->CommonCfg.MlmeRate = RATE_6;
3234 pAd->CommonCfg.RtsRate = RATE_6;
3235 pAd->CommonCfg.MlmeTransmit.field.MODE =
3236 MODE_OFDM;
3237 pAd->CommonCfg.MlmeTransmit.field.MCS =
3238 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
3239 }
3240 break;
3241 default: /* error */
3242 pAd->CommonCfg.MlmeRate = RATE_6;
3243 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
3244 pAd->CommonCfg.MlmeTransmit.field.MCS =
3245 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
3246 pAd->CommonCfg.RtsRate = RATE_1;
3247 break;
3248 }
3249 /* */
3250 /* Keep Basic Mlme Rate. */
3251 /* */
3252 pAd->MacTab.Content[MCAST_WCID].HTPhyMode.word =
3253 pAd->CommonCfg.MlmeTransmit.word;
3254 if (pAd->CommonCfg.MlmeTransmit.field.MODE == MODE_OFDM)
3255 pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS =
3256 OfdmRateToRxwiMCS[RATE_24];
3257 else
3258 pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS =
3259 RATE_1;
3260 pAd->CommonCfg.BasicMlmeRate = pAd->CommonCfg.MlmeRate;
3261 }
3262
3263 DBGPRINT(RT_DEBUG_TRACE,
3264 (" MlmeUpdateTxRates (MaxDesire=%d, MaxSupport=%d, MaxTxRate=%d, MinRate=%d, Rate Switching =%d)\n",
3265 RateIdToMbps[MaxDesire], RateIdToMbps[MaxSupport],
3266 RateIdToMbps[pAd->CommonCfg.MaxTxRate],
3267 RateIdToMbps[pAd->CommonCfg.MinTxRate],
3268 /*OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) */
3269 *auto_rate_cur_p));
3270 DBGPRINT(RT_DEBUG_TRACE,
3271 (" MlmeUpdateTxRates (TxRate=%d, RtsRate=%d, BasicRateBitmap=0x%04lx)\n",
3272 RateIdToMbps[pAd->CommonCfg.TxRate],
3273 RateIdToMbps[pAd->CommonCfg.RtsRate], BasicRateBitmap));
3274 DBGPRINT(RT_DEBUG_TRACE,
3275 ("MlmeUpdateTxRates (MlmeTransmit=0x%x, MinHTPhyMode=%x, MaxHTPhyMode=0x%x, HTPhyMode=0x%x)\n",
3276 pAd->CommonCfg.MlmeTransmit.word,
3277 pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word,
3278 pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word,
3279 pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word));
3280}
3281
3282/*
3283 ==========================================================================
3284 Description:
3285 This function update HT Rate setting.
3286 Input Wcid value is valid for 2 case :
3287 1. it's used for Station in infra mode that copy AP rate to Mactable.
3288 2. OR Station in adhoc mode to copy peer's HT rate to Mactable.
3289
3290 IRQL = DISPATCH_LEVEL
3291
3292 ==========================================================================
3293 */
3294void MlmeUpdateHtTxRates(struct rt_rtmp_adapter *pAd, u8 apidx)
3295{
3296 u8 StbcMcs; /*j, StbcMcs, bitmask; */
3297 char i; /* 3*3 */
3298 struct rt_ht_capability *pRtHtCap = NULL;
3299 struct rt_ht_phy_info *pActiveHtPhy = NULL;
3300 unsigned long BasicMCS;
3301 u8 j, bitmask;
3302 struct rt_ht_phy_info *pDesireHtPhy = NULL;
3303 PHTTRANSMIT_SETTING pHtPhy = NULL;
3304 PHTTRANSMIT_SETTING pMaxHtPhy = NULL;
3305 PHTTRANSMIT_SETTING pMinHtPhy = NULL;
3306 BOOLEAN *auto_rate_cur_p;
3307
3308 DBGPRINT(RT_DEBUG_TRACE, ("MlmeUpdateHtTxRates===> \n"));
3309
3310 auto_rate_cur_p = NULL;
3311
3312 {
3313 pDesireHtPhy = &pAd->StaCfg.DesiredHtPhyInfo;
3314 pActiveHtPhy = &pAd->StaCfg.DesiredHtPhyInfo;
3315 pHtPhy = &pAd->StaCfg.HTPhyMode;
3316 pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode;
3317 pMinHtPhy = &pAd->StaCfg.MinHTPhyMode;
3318
3319 auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch;
3320 }
3321
3322 if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) {
3323 if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
3324 return;
3325
3326 pRtHtCap = &pAd->StaActive.SupportedHtPhy;
3327 pActiveHtPhy = &pAd->StaActive.SupportedPhyInfo;
3328 StbcMcs = (u8)pAd->MlmeAux.AddHtInfo.AddHtInfo3.StbcMcs;
3329 BasicMCS =
3330 pAd->MlmeAux.AddHtInfo.MCSSet[0] +
3331 (pAd->MlmeAux.AddHtInfo.MCSSet[1] << 8) + (StbcMcs << 16);
3332 if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC)
3333 && (pAd->Antenna.field.TxPath == 2))
3334 pMaxHtPhy->field.STBC = STBC_USE;
3335 else
3336 pMaxHtPhy->field.STBC = STBC_NONE;
3337 } else {
3338 if (pDesireHtPhy->bHtEnable == FALSE)
3339 return;
3340
3341 pRtHtCap = &pAd->CommonCfg.DesiredHtPhy;
3342 StbcMcs = (u8)pAd->CommonCfg.AddHTInfo.AddHtInfo3.StbcMcs;
3343 BasicMCS =
3344 pAd->CommonCfg.AddHTInfo.MCSSet[0] +
3345 (pAd->CommonCfg.AddHTInfo.MCSSet[1] << 8) + (StbcMcs << 16);
3346 if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC)
3347 && (pAd->Antenna.field.TxPath == 2))
3348 pMaxHtPhy->field.STBC = STBC_USE;
3349 else
3350 pMaxHtPhy->field.STBC = STBC_NONE;
3351 }
3352
3353 /* Decide MAX ht rate. */
3354 if ((pRtHtCap->GF) && (pAd->CommonCfg.DesiredHtPhy.GF))
3355 pMaxHtPhy->field.MODE = MODE_HTGREENFIELD;
3356 else
3357 pMaxHtPhy->field.MODE = MODE_HTMIX;
3358
3359 if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth)
3360 && (pRtHtCap->ChannelWidth))
3361 pMaxHtPhy->field.BW = BW_40;
3362 else
3363 pMaxHtPhy->field.BW = BW_20;
3364
3365 if (pMaxHtPhy->field.BW == BW_20)
3366 pMaxHtPhy->field.ShortGI =
3367 (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 & pRtHtCap->
3368 ShortGIfor20);
3369 else
3370 pMaxHtPhy->field.ShortGI =
3371 (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 & pRtHtCap->
3372 ShortGIfor40);
3373
3374 if (pDesireHtPhy->MCSSet[4] != 0) {
3375 pMaxHtPhy->field.MCS = 32;
3376 }
3377
3378 for (i = 23; i >= 0; i--) /* 3*3 */
3379 {
3380 j = i / 8;
3381 bitmask = (1 << (i - (j * 8)));
3382
3383 if ((pActiveHtPhy->MCSSet[j] & bitmask)
3384 && (pDesireHtPhy->MCSSet[j] & bitmask)) {
3385 pMaxHtPhy->field.MCS = i;
3386 break;
3387 }
3388
3389 if (i == 0)
3390 break;
3391 }
3392
3393 /* Copy MIN ht rate. rt2860??? */
3394 pMinHtPhy->field.BW = BW_20;
3395 pMinHtPhy->field.MCS = 0;
3396 pMinHtPhy->field.STBC = 0;
3397 pMinHtPhy->field.ShortGI = 0;
3398 /*If STA assigns fixed rate. update to fixed here. */
3399 if ((pAd->OpMode == OPMODE_STA) && (pDesireHtPhy->MCSSet[0] != 0xff)) {
3400 if (pDesireHtPhy->MCSSet[4] != 0) {
3401 pMaxHtPhy->field.MCS = 32;
3402 pMinHtPhy->field.MCS = 32;
3403 DBGPRINT(RT_DEBUG_TRACE,
3404 ("MlmeUpdateHtTxRates<=== Use Fixed MCS = %d\n",
3405 pMinHtPhy->field.MCS));
3406 }
3407
3408 for (i = 23; (char)i >= 0; i--) /* 3*3 */
3409 {
3410 j = i / 8;
3411 bitmask = (1 << (i - (j * 8)));
3412 if ((pDesireHtPhy->MCSSet[j] & bitmask)
3413 && (pActiveHtPhy->MCSSet[j] & bitmask)) {
3414 pMaxHtPhy->field.MCS = i;
3415 pMinHtPhy->field.MCS = i;
3416 break;
3417 }
3418 if (i == 0)
3419 break;
3420 }
3421 }
3422
3423 /* Decide ht rate */
3424 pHtPhy->field.STBC = pMaxHtPhy->field.STBC;
3425 pHtPhy->field.BW = pMaxHtPhy->field.BW;
3426 pHtPhy->field.MODE = pMaxHtPhy->field.MODE;
3427 pHtPhy->field.MCS = pMaxHtPhy->field.MCS;
3428 pHtPhy->field.ShortGI = pMaxHtPhy->field.ShortGI;
3429
3430 /* use default now. rt2860 */
3431 if (pDesireHtPhy->MCSSet[0] != 0xff)
3432 *auto_rate_cur_p = FALSE;
3433 else
3434 *auto_rate_cur_p = TRUE;
3435
3436 DBGPRINT(RT_DEBUG_TRACE,
3437 (" MlmeUpdateHtTxRates<---.AMsduSize = %d \n",
3438 pAd->CommonCfg.DesiredHtPhy.AmsduSize));
3439 DBGPRINT(RT_DEBUG_TRACE,
3440 ("TX: MCS[0] = %x (choose %d), BW = %d, ShortGI = %d, MODE = %d, \n",
3441 pActiveHtPhy->MCSSet[0], pHtPhy->field.MCS, pHtPhy->field.BW,
3442 pHtPhy->field.ShortGI, pHtPhy->field.MODE));
3443 DBGPRINT(RT_DEBUG_TRACE, ("MlmeUpdateHtTxRates<=== \n"));
3444}
3445
3446void BATableInit(struct rt_rtmp_adapter *pAd, struct rt_ba_table *Tab)
3447{
3448 int i;
3449
3450 Tab->numAsOriginator = 0;
3451 Tab->numAsRecipient = 0;
3452 Tab->numDoneOriginator = 0;
3453 NdisAllocateSpinLock(&pAd->BATabLock);
3454 for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++) {
3455 Tab->BARecEntry[i].REC_BA_Status = Recipient_NONE;
3456 NdisAllocateSpinLock(&(Tab->BARecEntry[i].RxReRingLock));
3457 }
3458 for (i = 0; i < MAX_LEN_OF_BA_ORI_TABLE; i++) {
3459 Tab->BAOriEntry[i].ORI_BA_Status = Originator_NONE;
3460 }
3461}
3462
3463/* IRQL = DISPATCH_LEVEL */
3464void MlmeRadioOff(struct rt_rtmp_adapter *pAd)
3465{
3466 RTMP_MLME_RADIO_OFF(pAd);
3467}
3468
3469/* IRQL = DISPATCH_LEVEL */
3470void MlmeRadioOn(struct rt_rtmp_adapter *pAd)
3471{
3472 RTMP_MLME_RADIO_ON(pAd);
3473}
3474
3475/* =========================================================================================== */
3476/* bss_table.c */
3477/* =========================================================================================== */
3478
3479/*! \brief initialize BSS table
3480 * \param p_tab pointer to the table
3481 * \return none
3482 * \pre
3483 * \post
3484
3485 IRQL = PASSIVE_LEVEL
3486 IRQL = DISPATCH_LEVEL
3487
3488 */
3489void BssTableInit(struct rt_bss_table *Tab)
3490{
3491 int i;
3492
3493 Tab->BssNr = 0;
3494 Tab->BssOverlapNr = 0;
3495 for (i = 0; i < MAX_LEN_OF_BSS_TABLE; i++) {
3496 NdisZeroMemory(&Tab->BssEntry[i], sizeof(struct rt_bss_entry));
3497 Tab->BssEntry[i].Rssi = -127; /* initial the rssi as a minimum value */
3498 }
3499}
3500
3501/*! \brief search the BSS table by SSID
3502 * \param p_tab pointer to the bss table
3503 * \param ssid SSID string
3504 * \return index of the table, BSS_NOT_FOUND if not in the table
3505 * \pre
3506 * \post
3507 * \note search by sequential search
3508
3509 IRQL = DISPATCH_LEVEL
3510
3511 */
3512unsigned long BssTableSearch(struct rt_bss_table *Tab, u8 *pBssid, u8 Channel)
3513{
3514 u8 i;
3515
3516 for (i = 0; i < Tab->BssNr; i++) {
3517 /* */
3518 /* Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G. */
3519 /* We should distinguish this case. */
3520 /* */
3521 if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
3522 ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
3523 MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid)) {
3524 return i;
3525 }
3526 }
3527 return (unsigned long)BSS_NOT_FOUND;
3528}
3529
3530unsigned long BssSsidTableSearch(struct rt_bss_table *Tab,
3531 u8 *pBssid,
3532 u8 *pSsid, u8 SsidLen, u8 Channel)
3533{
3534 u8 i;
3535
3536 for (i = 0; i < Tab->BssNr; i++) {
3537 /* */
3538 /* Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G. */
3539 /* We should distinguish this case. */
3540 /* */
3541 if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
3542 ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
3543 MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid) &&
3544 SSID_EQUAL(pSsid, SsidLen, Tab->BssEntry[i].Ssid,
3545 Tab->BssEntry[i].SsidLen)) {
3546 return i;
3547 }
3548 }
3549 return (unsigned long)BSS_NOT_FOUND;
3550}
3551
3552unsigned long BssTableSearchWithSSID(struct rt_bss_table *Tab,
3553 u8 *Bssid,
3554 u8 *pSsid,
3555 u8 SsidLen, u8 Channel)
3556{
3557 u8 i;
3558
3559 for (i = 0; i < Tab->BssNr; i++) {
3560 if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) ||
3561 ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) &&
3562 MAC_ADDR_EQUAL(&(Tab->BssEntry[i].Bssid), Bssid) &&
3563 (SSID_EQUAL
3564 (pSsid, SsidLen, Tab->BssEntry[i].Ssid,
3565 Tab->BssEntry[i].SsidLen)
3566 || (NdisEqualMemory(pSsid, ZeroSsid, SsidLen))
3567 ||
3568 (NdisEqualMemory
3569 (Tab->BssEntry[i].Ssid, ZeroSsid,
3570 Tab->BssEntry[i].SsidLen)))) {
3571 return i;
3572 }
3573 }
3574 return (unsigned long)BSS_NOT_FOUND;
3575}
3576
3577unsigned long BssSsidTableSearchBySSID(struct rt_bss_table *Tab,
3578 u8 *pSsid, u8 SsidLen)
3579{
3580 u8 i;
3581
3582 for (i = 0; i < Tab->BssNr; i++) {
3583 if (SSID_EQUAL
3584 (pSsid, SsidLen, Tab->BssEntry[i].Ssid,
3585 Tab->BssEntry[i].SsidLen)) {
3586 return i;
3587 }
3588 }
3589 return (unsigned long)BSS_NOT_FOUND;
3590}
3591
3592/* IRQL = DISPATCH_LEVEL */
3593void BssTableDeleteEntry(struct rt_bss_table *Tab,
3594 u8 *pBssid, u8 Channel)
3595{
3596 u8 i, j;
3597
3598 for (i = 0; i < Tab->BssNr; i++) {
3599 if ((Tab->BssEntry[i].Channel == Channel) &&
3600 (MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid))) {
3601 for (j = i; j < Tab->BssNr - 1; j++) {
3602 NdisMoveMemory(&(Tab->BssEntry[j]),
3603 &(Tab->BssEntry[j + 1]),
3604 sizeof(struct rt_bss_entry));
3605 }
3606 NdisZeroMemory(&(Tab->BssEntry[Tab->BssNr - 1]),
3607 sizeof(struct rt_bss_entry));
3608 Tab->BssNr -= 1;
3609 return;
3610 }
3611 }
3612}
3613
3614/*
3615 ========================================================================
3616 Routine Description:
3617 Delete the Originator Entry in BAtable. Or decrease numAs Originator by 1 if needed.
3618
3619 Arguments:
3620 // IRQL = DISPATCH_LEVEL
3621 ========================================================================
3622*/
3623void BATableDeleteORIEntry(struct rt_rtmp_adapter *pAd,
3624 struct rt_ba_ori_entry *pBAORIEntry)
3625{
3626
3627 if (pBAORIEntry->ORI_BA_Status != Originator_NONE) {
3628 NdisAcquireSpinLock(&pAd->BATabLock);
3629 if (pBAORIEntry->ORI_BA_Status == Originator_Done) {
3630 pAd->BATable.numAsOriginator -= 1;
3631 DBGPRINT(RT_DEBUG_TRACE,
3632 ("BATableDeleteORIEntry numAsOriginator= %ld\n",
3633 pAd->BATable.numAsRecipient));
3634 /* Erase Bitmap flag. */
3635 }
3636 pAd->MacTab.Content[pBAORIEntry->Wcid].TXBAbitmap &= (~(1 << (pBAORIEntry->TID))); /* If STA mode, erase flag here */
3637 pAd->MacTab.Content[pBAORIEntry->Wcid].BAOriWcidArray[pBAORIEntry->TID] = 0; /* If STA mode, erase flag here */
3638 pBAORIEntry->ORI_BA_Status = Originator_NONE;
3639 pBAORIEntry->Token = 1;
3640 /* Not clear Sequence here. */
3641 NdisReleaseSpinLock(&pAd->BATabLock);
3642 }
3643}
3644
3645/*! \brief
3646 * \param
3647 * \return
3648 * \pre
3649 * \post
3650
3651 IRQL = DISPATCH_LEVEL
3652
3653 */
3654void BssEntrySet(struct rt_rtmp_adapter *pAd, struct rt_bss_entry *pBss, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * pCfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */
3655 u8 HtCapabilityLen,
3656 u8 AddHtInfoLen,
3657 u8 NewExtChanOffset,
3658 u8 Channel,
3659 char Rssi,
3660 IN LARGE_INTEGER TimeStamp,
3661 u8 CkipFlag,
3662 struct rt_edca_parm *pEdcaParm,
3663 struct rt_qos_capability_parm *pQosCapability,
3664 struct rt_qbss_load_parm *pQbssLoad,
3665 u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE)
3666{
3667 COPY_MAC_ADDR(pBss->Bssid, pBssid);
3668 /* Default Hidden SSID to be TRUE, it will be turned to FALSE after coping SSID */
3669 pBss->Hidden = 1;
3670 if (SsidLen > 0) {
3671 /* For hidden SSID AP, it might send beacon with SSID len equal to 0 */
3672 /* Or send beacon /probe response with SSID len matching real SSID length, */
3673 /* but SSID is all zero. such as "00-00-00-00" with length 4. */
3674 /* We have to prevent this case overwrite correct table */
3675 if (NdisEqualMemory(Ssid, ZeroSsid, SsidLen) == 0) {
3676 NdisZeroMemory(pBss->Ssid, MAX_LEN_OF_SSID);
3677 NdisMoveMemory(pBss->Ssid, Ssid, SsidLen);
3678 pBss->SsidLen = SsidLen;
3679 pBss->Hidden = 0;
3680 }
3681 } else
3682 pBss->SsidLen = 0;
3683 pBss->BssType = BssType;
3684 pBss->BeaconPeriod = BeaconPeriod;
3685 if (BssType == BSS_INFRA) {
3686 if (pCfParm->bValid) {
3687 pBss->CfpCount = pCfParm->CfpCount;
3688 pBss->CfpPeriod = pCfParm->CfpPeriod;
3689 pBss->CfpMaxDuration = pCfParm->CfpMaxDuration;
3690 pBss->CfpDurRemaining = pCfParm->CfpDurRemaining;
3691 }
3692 } else {
3693 pBss->AtimWin = AtimWin;
3694 }
3695
3696 pBss->CapabilityInfo = CapabilityInfo;
3697 /* The privacy bit indicate security is ON, it maight be WEP, TKIP or AES */
3698 /* Combine with AuthMode, they will decide the connection methods. */
3699 pBss->Privacy = CAP_IS_PRIVACY_ON(pBss->CapabilityInfo);
3700 ASSERT(SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES);
3701 if (SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES)
3702 NdisMoveMemory(pBss->SupRate, SupRate, SupRateLen);
3703 else
3704 NdisMoveMemory(pBss->SupRate, SupRate,
3705 MAX_LEN_OF_SUPPORTED_RATES);
3706 pBss->SupRateLen = SupRateLen;
3707 ASSERT(ExtRateLen <= MAX_LEN_OF_SUPPORTED_RATES);
3708 NdisMoveMemory(pBss->ExtRate, ExtRate, ExtRateLen);
3709 pBss->NewExtChanOffset = NewExtChanOffset;
3710 pBss->ExtRateLen = ExtRateLen;
3711 pBss->Channel = Channel;
3712 pBss->CentralChannel = Channel;
3713 pBss->Rssi = Rssi;
3714 /* Update CkipFlag. if not exists, the value is 0x0 */
3715 pBss->CkipFlag = CkipFlag;
3716
3717 /* New for microsoft Fixed IEs */
3718 NdisMoveMemory(pBss->FixIEs.Timestamp, &TimeStamp, 8);
3719 pBss->FixIEs.BeaconInterval = BeaconPeriod;
3720 pBss->FixIEs.Capabilities = CapabilityInfo;
3721
3722 /* New for microsoft Variable IEs */
3723 if (LengthVIE != 0) {
3724 pBss->VarIELen = LengthVIE;
3725 NdisMoveMemory(pBss->VarIEs, pVIE, pBss->VarIELen);
3726 } else {
3727 pBss->VarIELen = 0;
3728 }
3729
3730 pBss->AddHtInfoLen = 0;
3731 pBss->HtCapabilityLen = 0;
3732 if (HtCapabilityLen > 0) {
3733 pBss->HtCapabilityLen = HtCapabilityLen;
3734 NdisMoveMemory(&pBss->HtCapability, pHtCapability,
3735 HtCapabilityLen);
3736 if (AddHtInfoLen > 0) {
3737 pBss->AddHtInfoLen = AddHtInfoLen;
3738 NdisMoveMemory(&pBss->AddHtInfo, pAddHtInfo,
3739 AddHtInfoLen);
3740
3741 if ((pAddHtInfo->ControlChan > 2)
3742 && (pAddHtInfo->AddHtInfo.ExtChanOffset ==
3743 EXTCHA_BELOW)
3744 && (pHtCapability->HtCapInfo.ChannelWidth ==
3745 BW_40)) {
3746 pBss->CentralChannel =
3747 pAddHtInfo->ControlChan - 2;
3748 } else
3749 if ((pAddHtInfo->AddHtInfo.ExtChanOffset ==
3750 EXTCHA_ABOVE)
3751 && (pHtCapability->HtCapInfo.ChannelWidth ==
3752 BW_40)) {
3753 pBss->CentralChannel =
3754 pAddHtInfo->ControlChan + 2;
3755 }
3756 }
3757 }
3758
3759 BssCipherParse(pBss);
3760
3761 /* new for QOS */
3762 if (pEdcaParm)
3763 NdisMoveMemory(&pBss->EdcaParm, pEdcaParm, sizeof(struct rt_edca_parm));
3764 else
3765 pBss->EdcaParm.bValid = FALSE;
3766 if (pQosCapability)
3767 NdisMoveMemory(&pBss->QosCapability, pQosCapability,
3768 sizeof(struct rt_qos_capability_parm));
3769 else
3770 pBss->QosCapability.bValid = FALSE;
3771 if (pQbssLoad)
3772 NdisMoveMemory(&pBss->QbssLoad, pQbssLoad,
3773 sizeof(struct rt_qbss_load_parm));
3774 else
3775 pBss->QbssLoad.bValid = FALSE;
3776
3777 {
3778 struct rt_eid * pEid;
3779 u16 Length = 0;
3780
3781 NdisZeroMemory(&pBss->WpaIE.IE[0], MAX_CUSTOM_LEN);
3782 NdisZeroMemory(&pBss->RsnIE.IE[0], MAX_CUSTOM_LEN);
3783 pEid = (struct rt_eid *) pVIE;
3784 while ((Length + 2 + (u16)pEid->Len) <= LengthVIE) {
3785 switch (pEid->Eid) {
3786 case IE_WPA:
3787 if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)) {
3788 if ((pEid->Len + 2) > MAX_CUSTOM_LEN) {
3789 pBss->WpaIE.IELen = 0;
3790 break;
3791 }
3792 pBss->WpaIE.IELen = pEid->Len + 2;
3793 NdisMoveMemory(pBss->WpaIE.IE, pEid,
3794 pBss->WpaIE.IELen);
3795 }
3796 break;
3797 case IE_RSN:
3798 if (NdisEqualMemory
3799 (pEid->Octet + 2, RSN_OUI, 3)) {
3800 if ((pEid->Len + 2) > MAX_CUSTOM_LEN) {
3801 pBss->RsnIE.IELen = 0;
3802 break;
3803 }
3804 pBss->RsnIE.IELen = pEid->Len + 2;
3805 NdisMoveMemory(pBss->RsnIE.IE, pEid,
3806 pBss->RsnIE.IELen);
3807 }
3808 break;
3809 }
3810 Length = Length + 2 + (u16)pEid->Len; /* Eid[1] + Len[1]+ content[Len] */
3811 pEid = (struct rt_eid *) ((u8 *) pEid + 2 + pEid->Len);
3812 }
3813 }
3814}
3815
3816/*!
3817 * \brief insert an entry into the bss table
3818 * \param p_tab The BSS table
3819 * \param Bssid BSSID
3820 * \param ssid SSID
3821 * \param ssid_len Length of SSID
3822 * \param bss_type
3823 * \param beacon_period
3824 * \param timestamp
3825 * \param p_cf
3826 * \param atim_win
3827 * \param cap
3828 * \param rates
3829 * \param rates_len
3830 * \param channel_idx
3831 * \return none
3832 * \pre
3833 * \post
3834 * \note If SSID is identical, the old entry will be replaced by the new one
3835
3836 IRQL = DISPATCH_LEVEL
3837
3838 */
3839unsigned long BssTableSetEntry(struct rt_rtmp_adapter *pAd, struct rt_bss_table *Tab, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */
3840 u8 HtCapabilityLen,
3841 u8 AddHtInfoLen,
3842 u8 NewExtChanOffset,
3843 u8 ChannelNo,
3844 char Rssi,
3845 IN LARGE_INTEGER TimeStamp,
3846 u8 CkipFlag,
3847 struct rt_edca_parm *pEdcaParm,
3848 struct rt_qos_capability_parm *pQosCapability,
3849 struct rt_qbss_load_parm *pQbssLoad,
3850 u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE)
3851{
3852 unsigned long Idx;
3853
3854 Idx =
3855 BssTableSearchWithSSID(Tab, pBssid, (u8 *) Ssid, SsidLen,
3856 ChannelNo);
3857 if (Idx == BSS_NOT_FOUND) {
3858 if (Tab->BssNr >= MAX_LEN_OF_BSS_TABLE) {
3859 /* */
3860 /* It may happen when BSS Table was full. */
3861 /* The desired AP will not be added into BSS Table */
3862 /* In this case, if we found the desired AP then overwrite BSS Table. */
3863 /* */
3864 if (!OPSTATUS_TEST_FLAG
3865 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
3866 if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, pBssid)
3867 || SSID_EQUAL(pAd->MlmeAux.Ssid,
3868 pAd->MlmeAux.SsidLen, Ssid,
3869 SsidLen)) {
3870 Idx = Tab->BssOverlapNr;
3871 BssEntrySet(pAd, &Tab->BssEntry[Idx],
3872 pBssid, Ssid, SsidLen,
3873 BssType, BeaconPeriod,
3874 CfParm, AtimWin,
3875 CapabilityInfo, SupRate,
3876 SupRateLen, ExtRate,
3877 ExtRateLen, pHtCapability,
3878 pAddHtInfo, HtCapabilityLen,
3879 AddHtInfoLen,
3880 NewExtChanOffset, ChannelNo,
3881 Rssi, TimeStamp, CkipFlag,
3882 pEdcaParm, pQosCapability,
3883 pQbssLoad, LengthVIE, pVIE);
3884 Tab->BssOverlapNr =
3885 (Tab->BssOverlapNr++) %
3886 MAX_LEN_OF_BSS_TABLE;
3887 }
3888 return Idx;
3889 } else {
3890 return BSS_NOT_FOUND;
3891 }
3892 }
3893 Idx = Tab->BssNr;
3894 BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen,
3895 BssType, BeaconPeriod, CfParm, AtimWin,
3896 CapabilityInfo, SupRate, SupRateLen, ExtRate,
3897 ExtRateLen, pHtCapability, pAddHtInfo,
3898 HtCapabilityLen, AddHtInfoLen, NewExtChanOffset,
3899 ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm,
3900 pQosCapability, pQbssLoad, LengthVIE, pVIE);
3901 Tab->BssNr++;
3902 } else {
3903 /* avoid Hidden SSID form beacon to overwirite correct SSID from probe response */
3904 if ((SSID_EQUAL
3905 (Ssid, SsidLen, Tab->BssEntry[Idx].Ssid,
3906 Tab->BssEntry[Idx].SsidLen))
3907 ||
3908 (NdisEqualMemory
3909 (Tab->BssEntry[Idx].Ssid, ZeroSsid,
3910 Tab->BssEntry[Idx].SsidLen))) {
3911 BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid,
3912 SsidLen, BssType, BeaconPeriod, CfParm,
3913 AtimWin, CapabilityInfo, SupRate,
3914 SupRateLen, ExtRate, ExtRateLen,
3915 pHtCapability, pAddHtInfo, HtCapabilityLen,
3916 AddHtInfoLen, NewExtChanOffset, ChannelNo,
3917 Rssi, TimeStamp, CkipFlag, pEdcaParm,
3918 pQosCapability, pQbssLoad, LengthVIE, pVIE);
3919 }
3920 }
3921
3922 return Idx;
3923}
3924
3925/* IRQL = DISPATCH_LEVEL */
3926void BssTableSsidSort(struct rt_rtmp_adapter *pAd,
3927 struct rt_bss_table *OutTab, char Ssid[], u8 SsidLen)
3928{
3929 int i;
3930 BssTableInit(OutTab);
3931
3932 for (i = 0; i < pAd->ScanTab.BssNr; i++) {
3933 struct rt_bss_entry *pInBss = &pAd->ScanTab.BssEntry[i];
3934 BOOLEAN bIsHiddenApIncluded = FALSE;
3935
3936 if (((pAd->CommonCfg.bIEEE80211H == 1) &&
3937 (pAd->MlmeAux.Channel > 14) &&
3938 RadarChannelCheck(pAd, pInBss->Channel))
3939 ) {
3940 if (pInBss->Hidden)
3941 bIsHiddenApIncluded = TRUE;
3942 }
3943
3944 if ((pInBss->BssType == pAd->StaCfg.BssType) &&
3945 (SSID_EQUAL(Ssid, SsidLen, pInBss->Ssid, pInBss->SsidLen)
3946 || bIsHiddenApIncluded)) {
3947 struct rt_bss_entry *pOutBss = &OutTab->BssEntry[OutTab->BssNr];
3948
3949 /* 2.4G/5G N only mode */
3950 if ((pInBss->HtCapabilityLen == 0) &&
3951 ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G)
3952 || (pAd->CommonCfg.PhyMode == PHY_11N_5G))) {
3953 DBGPRINT(RT_DEBUG_TRACE,
3954 ("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n"));
3955 continue;
3956 }
3957 /* New for WPA2 */
3958 /* Check the Authmode first */
3959 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) {
3960 /* Check AuthMode and AuthModeAux for matching, in case AP support dual-mode */
3961 if ((pAd->StaCfg.AuthMode != pInBss->AuthMode)
3962 && (pAd->StaCfg.AuthMode !=
3963 pInBss->AuthModeAux))
3964 /* None matched */
3965 continue;
3966
3967 /* Check cipher suite, AP must have more secured cipher than station setting */
3968 if ((pAd->StaCfg.AuthMode ==
3969 Ndis802_11AuthModeWPA)
3970 || (pAd->StaCfg.AuthMode ==
3971 Ndis802_11AuthModeWPAPSK)) {
3972 /* If it's not mixed mode, we should only let BSS pass with the same encryption */
3973 if (pInBss->WPA.bMixMode == FALSE)
3974 if (pAd->StaCfg.WepStatus !=
3975 pInBss->WPA.GroupCipher)
3976 continue;
3977
3978 /* check group cipher */
3979 if ((pAd->StaCfg.WepStatus <
3980 pInBss->WPA.GroupCipher)
3981 && (pInBss->WPA.GroupCipher !=
3982 Ndis802_11GroupWEP40Enabled)
3983 && (pInBss->WPA.GroupCipher !=
3984 Ndis802_11GroupWEP104Enabled))
3985 continue;
3986
3987 /* check pairwise cipher, skip if none matched */
3988 /* If profile set to AES, let it pass without question. */
3989 /* If profile set to TKIP, we must find one mateched */
3990 if ((pAd->StaCfg.WepStatus ==
3991 Ndis802_11Encryption2Enabled)
3992 && (pAd->StaCfg.WepStatus !=
3993 pInBss->WPA.PairCipher)
3994 && (pAd->StaCfg.WepStatus !=
3995 pInBss->WPA.PairCipherAux))
3996 continue;
3997 } else
3998 if ((pAd->StaCfg.AuthMode ==
3999 Ndis802_11AuthModeWPA2)
4000 || (pAd->StaCfg.AuthMode ==
4001 Ndis802_11AuthModeWPA2PSK)) {
4002 /* If it's not mixed mode, we should only let BSS pass with the same encryption */
4003 if (pInBss->WPA2.bMixMode == FALSE)
4004 if (pAd->StaCfg.WepStatus !=
4005 pInBss->WPA2.GroupCipher)
4006 continue;
4007
4008 /* check group cipher */
4009 if ((pAd->StaCfg.WepStatus <
4010 pInBss->WPA.GroupCipher)
4011 && (pInBss->WPA2.GroupCipher !=
4012 Ndis802_11GroupWEP40Enabled)
4013 && (pInBss->WPA2.GroupCipher !=
4014 Ndis802_11GroupWEP104Enabled))
4015 continue;
4016
4017 /* check pairwise cipher, skip if none matched */
4018 /* If profile set to AES, let it pass without question. */
4019 /* If profile set to TKIP, we must find one mateched */
4020 if ((pAd->StaCfg.WepStatus ==
4021 Ndis802_11Encryption2Enabled)
4022 && (pAd->StaCfg.WepStatus !=
4023 pInBss->WPA2.PairCipher)
4024 && (pAd->StaCfg.WepStatus !=
4025 pInBss->WPA2.PairCipherAux))
4026 continue;
4027 }
4028 }
4029 /* Bss Type matched, SSID matched. */
4030 /* We will check wepstatus for qualification Bss */
4031 else if (pAd->StaCfg.WepStatus != pInBss->WepStatus) {
4032 DBGPRINT(RT_DEBUG_TRACE,
4033 ("StaCfg.WepStatus=%d, while pInBss->WepStatus=%d\n",
4034 pAd->StaCfg.WepStatus,
4035 pInBss->WepStatus));
4036 /* */
4037 /* For the SESv2 case, we will not qualify WepStatus. */
4038 /* */
4039 if (!pInBss->bSES)
4040 continue;
4041 }
4042 /* Since the AP is using hidden SSID, and we are trying to connect to ANY */
4043 /* It definitely will fail. So, skip it. */
4044 /* CCX also require not even try to connect it! */
4045 if (SsidLen == 0)
4046 continue;
4047
4048 /* If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region */
4049 /* If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead, */
4050 if ((pInBss->CentralChannel != pInBss->Channel) &&
4051 (pAd->CommonCfg.RegTransmitSetting.field.BW ==
4052 BW_40)) {
4053 if (RTMPCheckChannel
4054 (pAd, pInBss->CentralChannel,
4055 pInBss->Channel) == FALSE) {
4056 pAd->CommonCfg.RegTransmitSetting.field.
4057 BW = BW_20;
4058 SetCommonHT(pAd);
4059 pAd->CommonCfg.RegTransmitSetting.field.
4060 BW = BW_40;
4061 } else {
4062 if (pAd->CommonCfg.DesiredHtPhy.
4063 ChannelWidth == BAND_WIDTH_20) {
4064 SetCommonHT(pAd);
4065 }
4066 }
4067 }
4068 /* copy matching BSS from InTab to OutTab */
4069 NdisMoveMemory(pOutBss, pInBss, sizeof(struct rt_bss_entry));
4070
4071 OutTab->BssNr++;
4072 } else if ((pInBss->BssType == pAd->StaCfg.BssType)
4073 && (SsidLen == 0)) {
4074 struct rt_bss_entry *pOutBss = &OutTab->BssEntry[OutTab->BssNr];
4075
4076 /* 2.4G/5G N only mode */
4077 if ((pInBss->HtCapabilityLen == 0) &&
4078 ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G)
4079 || (pAd->CommonCfg.PhyMode == PHY_11N_5G))) {
4080 DBGPRINT(RT_DEBUG_TRACE,
4081 ("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n"));
4082 continue;
4083 }
4084 /* New for WPA2 */
4085 /* Check the Authmode first */
4086 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) {
4087 /* Check AuthMode and AuthModeAux for matching, in case AP support dual-mode */
4088 if ((pAd->StaCfg.AuthMode != pInBss->AuthMode)
4089 && (pAd->StaCfg.AuthMode !=
4090 pInBss->AuthModeAux))
4091 /* None matched */
4092 continue;
4093
4094 /* Check cipher suite, AP must have more secured cipher than station setting */
4095 if ((pAd->StaCfg.AuthMode ==
4096 Ndis802_11AuthModeWPA)
4097 || (pAd->StaCfg.AuthMode ==
4098 Ndis802_11AuthModeWPAPSK)) {
4099 /* If it's not mixed mode, we should only let BSS pass with the same encryption */
4100 if (pInBss->WPA.bMixMode == FALSE)
4101 if (pAd->StaCfg.WepStatus !=
4102 pInBss->WPA.GroupCipher)
4103 continue;
4104
4105 /* check group cipher */
4106 if (pAd->StaCfg.WepStatus <
4107 pInBss->WPA.GroupCipher)
4108 continue;
4109
4110 /* check pairwise cipher, skip if none matched */
4111 /* If profile set to AES, let it pass without question. */
4112 /* If profile set to TKIP, we must find one mateched */
4113 if ((pAd->StaCfg.WepStatus ==
4114 Ndis802_11Encryption2Enabled)
4115 && (pAd->StaCfg.WepStatus !=
4116 pInBss->WPA.PairCipher)
4117 && (pAd->StaCfg.WepStatus !=
4118 pInBss->WPA.PairCipherAux))
4119 continue;
4120 } else
4121 if ((pAd->StaCfg.AuthMode ==
4122 Ndis802_11AuthModeWPA2)
4123 || (pAd->StaCfg.AuthMode ==
4124 Ndis802_11AuthModeWPA2PSK)) {
4125 /* If it's not mixed mode, we should only let BSS pass with the same encryption */
4126 if (pInBss->WPA2.bMixMode == FALSE)
4127 if (pAd->StaCfg.WepStatus !=
4128 pInBss->WPA2.GroupCipher)
4129 continue;
4130
4131 /* check group cipher */
4132 if (pAd->StaCfg.WepStatus <
4133 pInBss->WPA2.GroupCipher)
4134 continue;
4135
4136 /* check pairwise cipher, skip if none matched */
4137 /* If profile set to AES, let it pass without question. */
4138 /* If profile set to TKIP, we must find one mateched */
4139 if ((pAd->StaCfg.WepStatus ==
4140 Ndis802_11Encryption2Enabled)
4141 && (pAd->StaCfg.WepStatus !=
4142 pInBss->WPA2.PairCipher)
4143 && (pAd->StaCfg.WepStatus !=
4144 pInBss->WPA2.PairCipherAux))
4145 continue;
4146 }
4147 }
4148 /* Bss Type matched, SSID matched. */
4149 /* We will check wepstatus for qualification Bss */
4150 else if (pAd->StaCfg.WepStatus != pInBss->WepStatus)
4151 continue;
4152
4153 /* If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region */
4154 /* If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead, */
4155 if ((pInBss->CentralChannel != pInBss->Channel) &&
4156 (pAd->CommonCfg.RegTransmitSetting.field.BW ==
4157 BW_40)) {
4158 if (RTMPCheckChannel
4159 (pAd, pInBss->CentralChannel,
4160 pInBss->Channel) == FALSE) {
4161 pAd->CommonCfg.RegTransmitSetting.field.
4162 BW = BW_20;
4163 SetCommonHT(pAd);
4164 pAd->CommonCfg.RegTransmitSetting.field.
4165 BW = BW_40;
4166 }
4167 }
4168 /* copy matching BSS from InTab to OutTab */
4169 NdisMoveMemory(pOutBss, pInBss, sizeof(struct rt_bss_entry));
4170
4171 OutTab->BssNr++;
4172 }
4173
4174 if (OutTab->BssNr >= MAX_LEN_OF_BSS_TABLE)
4175 break;
4176 }
4177
4178 BssTableSortByRssi(OutTab);
4179}
4180
4181/* IRQL = DISPATCH_LEVEL */
4182void BssTableSortByRssi(struct rt_bss_table *OutTab)
4183{
4184 int i, j;
4185 struct rt_bss_entry TmpBss;
4186
4187 for (i = 0; i < OutTab->BssNr - 1; i++) {
4188 for (j = i + 1; j < OutTab->BssNr; j++) {
4189 if (OutTab->BssEntry[j].Rssi > OutTab->BssEntry[i].Rssi) {
4190 NdisMoveMemory(&TmpBss, &OutTab->BssEntry[j],
4191 sizeof(struct rt_bss_entry));
4192 NdisMoveMemory(&OutTab->BssEntry[j],
4193 &OutTab->BssEntry[i],
4194 sizeof(struct rt_bss_entry));
4195 NdisMoveMemory(&OutTab->BssEntry[i], &TmpBss,
4196 sizeof(struct rt_bss_entry));
4197 }
4198 }
4199 }
4200}
4201
4202void BssCipherParse(struct rt_bss_entry *pBss)
4203{
4204 struct rt_eid * pEid;
4205 u8 *pTmp;
4206 struct rt_rsn_ie_header * pRsnHeader;
4207 struct rt_cipher_suite_struct * pCipher;
4208 struct rt_akm_suite * pAKM;
4209 u16 Count;
4210 int Length;
4211 NDIS_802_11_ENCRYPTION_STATUS TmpCipher;
4212
4213 /* */
4214 /* WepStatus will be reset later, if AP announce TKIP or AES on the beacon frame. */
4215 /* */
4216 if (pBss->Privacy) {
4217 pBss->WepStatus = Ndis802_11WEPEnabled;
4218 } else {
4219 pBss->WepStatus = Ndis802_11WEPDisabled;
4220 }
4221 /* Set default to disable & open authentication before parsing variable IE */
4222 pBss->AuthMode = Ndis802_11AuthModeOpen;
4223 pBss->AuthModeAux = Ndis802_11AuthModeOpen;
4224
4225 /* Init WPA setting */
4226 pBss->WPA.PairCipher = Ndis802_11WEPDisabled;
4227 pBss->WPA.PairCipherAux = Ndis802_11WEPDisabled;
4228 pBss->WPA.GroupCipher = Ndis802_11WEPDisabled;
4229 pBss->WPA.RsnCapability = 0;
4230 pBss->WPA.bMixMode = FALSE;
4231
4232 /* Init WPA2 setting */
4233 pBss->WPA2.PairCipher = Ndis802_11WEPDisabled;
4234 pBss->WPA2.PairCipherAux = Ndis802_11WEPDisabled;
4235 pBss->WPA2.GroupCipher = Ndis802_11WEPDisabled;
4236 pBss->WPA2.RsnCapability = 0;
4237 pBss->WPA2.bMixMode = FALSE;
4238
4239 Length = (int)pBss->VarIELen;
4240
4241 while (Length > 0) {
4242 /* Parse cipher suite base on WPA1 & WPA2, they should be parsed differently */
4243 pTmp = ((u8 *)pBss->VarIEs) + pBss->VarIELen - Length;
4244 pEid = (struct rt_eid *) pTmp;
4245 switch (pEid->Eid) {
4246 case IE_WPA:
4247 if (NdisEqualMemory(pEid->Octet, SES_OUI, 3)
4248 && (pEid->Len == 7)) {
4249 pBss->bSES = TRUE;
4250 break;
4251 } else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4) !=
4252 1) {
4253 /* if unsupported vendor specific IE */
4254 break;
4255 }
4256 /* Skip OUI, version, and multicast suite */
4257 /* This part should be improved in the future when AP supported multiple cipher suite. */
4258 /* For now, it's OK since almost all APs have fixed cipher suite supported. */
4259 /* pTmp = (u8 *)pEid->Octet; */
4260 pTmp += 11;
4261
4262 /* Cipher Suite Selectors from Spec P802.11i/D3.2 P26. */
4263 /* Value Meaning */
4264 /* 0 None */
4265 /* 1 WEP-40 */
4266 /* 2 Tkip */
4267 /* 3 WRAP */
4268 /* 4 AES */
4269 /* 5 WEP-104 */
4270 /* Parse group cipher */
4271 switch (*pTmp) {
4272 case 1:
4273 pBss->WPA.GroupCipher =
4274 Ndis802_11GroupWEP40Enabled;
4275 break;
4276 case 5:
4277 pBss->WPA.GroupCipher =
4278 Ndis802_11GroupWEP104Enabled;
4279 break;
4280 case 2:
4281 pBss->WPA.GroupCipher =
4282 Ndis802_11Encryption2Enabled;
4283 break;
4284 case 4:
4285 pBss->WPA.GroupCipher =
4286 Ndis802_11Encryption3Enabled;
4287 break;
4288 default:
4289 break;
4290 }
4291 /* number of unicast suite */
4292 pTmp += 1;
4293
4294 /* skip all unicast cipher suites */
4295 /*Count = *(u16 *)pTmp; */
4296 Count = (pTmp[1] << 8) + pTmp[0];
4297 pTmp += sizeof(u16);
4298
4299 /* Parsing all unicast cipher suite */
4300 while (Count > 0) {
4301 /* Skip OUI */
4302 pTmp += 3;
4303 TmpCipher = Ndis802_11WEPDisabled;
4304 switch (*pTmp) {
4305 case 1:
4306 case 5: /* Although WEP is not allowed in WPA related auth mode, we parse it anyway */
4307 TmpCipher =
4308 Ndis802_11Encryption1Enabled;
4309 break;
4310 case 2:
4311 TmpCipher =
4312 Ndis802_11Encryption2Enabled;
4313 break;
4314 case 4:
4315 TmpCipher =
4316 Ndis802_11Encryption3Enabled;
4317 break;
4318 default:
4319 break;
4320 }
4321 if (TmpCipher > pBss->WPA.PairCipher) {
4322 /* Move the lower cipher suite to PairCipherAux */
4323 pBss->WPA.PairCipherAux =
4324 pBss->WPA.PairCipher;
4325 pBss->WPA.PairCipher = TmpCipher;
4326 } else {
4327 pBss->WPA.PairCipherAux = TmpCipher;
4328 }
4329 pTmp++;
4330 Count--;
4331 }
4332
4333 /* 4. get AKM suite counts */
4334 /*Count = *(u16 *)pTmp; */
4335 Count = (pTmp[1] << 8) + pTmp[0];
4336 pTmp += sizeof(u16);
4337 pTmp += 3;
4338
4339 switch (*pTmp) {
4340 case 1:
4341 /* Set AP support WPA-enterprise mode */
4342 if (pBss->AuthMode == Ndis802_11AuthModeOpen)
4343 pBss->AuthMode = Ndis802_11AuthModeWPA;
4344 else
4345 pBss->AuthModeAux =
4346 Ndis802_11AuthModeWPA;
4347 break;
4348 case 2:
4349 /* Set AP support WPA-PSK mode */
4350 if (pBss->AuthMode == Ndis802_11AuthModeOpen)
4351 pBss->AuthMode =
4352 Ndis802_11AuthModeWPAPSK;
4353 else
4354 pBss->AuthModeAux =
4355 Ndis802_11AuthModeWPAPSK;
4356 break;
4357 default:
4358 break;
4359 }
4360 pTmp += 1;
4361
4362 /* Fixed for WPA-None */
4363 if (pBss->BssType == BSS_ADHOC) {
4364 pBss->AuthMode = Ndis802_11AuthModeWPANone;
4365 pBss->AuthModeAux = Ndis802_11AuthModeWPANone;
4366 pBss->WepStatus = pBss->WPA.GroupCipher;
4367 /* Patched bugs for old driver */
4368 if (pBss->WPA.PairCipherAux ==
4369 Ndis802_11WEPDisabled)
4370 pBss->WPA.PairCipherAux =
4371 pBss->WPA.GroupCipher;
4372 } else
4373 pBss->WepStatus = pBss->WPA.PairCipher;
4374
4375 /* Check the Pair & Group, if different, turn on mixed mode flag */
4376 if (pBss->WPA.GroupCipher != pBss->WPA.PairCipher)
4377 pBss->WPA.bMixMode = TRUE;
4378
4379 break;
4380
4381 case IE_RSN:
4382 pRsnHeader = (struct rt_rsn_ie_header *) pTmp;
4383
4384 /* 0. Version must be 1 */
4385 if (le2cpu16(pRsnHeader->Version) != 1)
4386 break;
4387 pTmp += sizeof(struct rt_rsn_ie_header);
4388
4389 /* 1. Check group cipher */
4390 pCipher = (struct rt_cipher_suite_struct *) pTmp;
4391 if (!RTMPEqualMemory(pTmp, RSN_OUI, 3))
4392 break;
4393
4394 /* Parse group cipher */
4395 switch (pCipher->Type) {
4396 case 1:
4397 pBss->WPA2.GroupCipher =
4398 Ndis802_11GroupWEP40Enabled;
4399 break;
4400 case 5:
4401 pBss->WPA2.GroupCipher =
4402 Ndis802_11GroupWEP104Enabled;
4403 break;
4404 case 2:
4405 pBss->WPA2.GroupCipher =
4406 Ndis802_11Encryption2Enabled;
4407 break;
4408 case 4:
4409 pBss->WPA2.GroupCipher =
4410 Ndis802_11Encryption3Enabled;
4411 break;
4412 default:
4413 break;
4414 }
4415 /* set to correct offset for next parsing */
4416 pTmp += sizeof(struct rt_cipher_suite_struct);
4417
4418 /* 2. Get pairwise cipher counts */
4419 /*Count = *(u16 *)pTmp; */
4420 Count = (pTmp[1] << 8) + pTmp[0];
4421 pTmp += sizeof(u16);
4422
4423 /* 3. Get pairwise cipher */
4424 /* Parsing all unicast cipher suite */
4425 while (Count > 0) {
4426 /* Skip OUI */
4427 pCipher = (struct rt_cipher_suite_struct *) pTmp;
4428 TmpCipher = Ndis802_11WEPDisabled;
4429 switch (pCipher->Type) {
4430 case 1:
4431 case 5: /* Although WEP is not allowed in WPA related auth mode, we parse it anyway */
4432 TmpCipher =
4433 Ndis802_11Encryption1Enabled;
4434 break;
4435 case 2:
4436 TmpCipher =
4437 Ndis802_11Encryption2Enabled;
4438 break;
4439 case 4:
4440 TmpCipher =
4441 Ndis802_11Encryption3Enabled;
4442 break;
4443 default:
4444 break;
4445 }
4446 if (TmpCipher > pBss->WPA2.PairCipher) {
4447 /* Move the lower cipher suite to PairCipherAux */
4448 pBss->WPA2.PairCipherAux =
4449 pBss->WPA2.PairCipher;
4450 pBss->WPA2.PairCipher = TmpCipher;
4451 } else {
4452 pBss->WPA2.PairCipherAux = TmpCipher;
4453 }
4454 pTmp += sizeof(struct rt_cipher_suite_struct);
4455 Count--;
4456 }
4457
4458 /* 4. get AKM suite counts */
4459 /*Count = *(u16 *)pTmp; */
4460 Count = (pTmp[1] << 8) + pTmp[0];
4461 pTmp += sizeof(u16);
4462
4463 /* 5. Get AKM ciphers */
4464 /* Parsing all AKM ciphers */
4465 while (Count > 0) {
4466 pAKM = (struct rt_akm_suite *) pTmp;
4467 if (!RTMPEqualMemory(pTmp, RSN_OUI, 3))
4468 break;
4469
4470 switch (pAKM->Type) {
4471 case 1:
4472 /* Set AP support WPA-enterprise mode */
4473 if (pBss->AuthMode ==
4474 Ndis802_11AuthModeOpen)
4475 pBss->AuthMode =
4476 Ndis802_11AuthModeWPA2;
4477 else
4478 pBss->AuthModeAux =
4479 Ndis802_11AuthModeWPA2;
4480 break;
4481 case 2:
4482 /* Set AP support WPA-PSK mode */
4483 if (pBss->AuthMode ==
4484 Ndis802_11AuthModeOpen)
4485 pBss->AuthMode =
4486 Ndis802_11AuthModeWPA2PSK;
4487 else
4488 pBss->AuthModeAux =
4489 Ndis802_11AuthModeWPA2PSK;
4490 break;
4491 default:
4492 if (pBss->AuthMode ==
4493 Ndis802_11AuthModeOpen)
4494 pBss->AuthMode =
4495 Ndis802_11AuthModeMax;
4496 else
4497 pBss->AuthModeAux =
4498 Ndis802_11AuthModeMax;
4499 break;
4500 }
4501 pTmp += (Count * sizeof(struct rt_akm_suite));
4502 Count--;
4503 }
4504
4505 /* Fixed for WPA-None */
4506 if (pBss->BssType == BSS_ADHOC) {
4507 pBss->AuthMode = Ndis802_11AuthModeWPANone;
4508 pBss->AuthModeAux = Ndis802_11AuthModeWPANone;
4509 pBss->WPA.PairCipherAux =
4510 pBss->WPA2.PairCipherAux;
4511 pBss->WPA.GroupCipher = pBss->WPA2.GroupCipher;
4512 pBss->WepStatus = pBss->WPA.GroupCipher;
4513 /* Patched bugs for old driver */
4514 if (pBss->WPA.PairCipherAux ==
4515 Ndis802_11WEPDisabled)
4516 pBss->WPA.PairCipherAux =
4517 pBss->WPA.GroupCipher;
4518 }
4519 pBss->WepStatus = pBss->WPA2.PairCipher;
4520
4521 /* 6. Get RSN capability */
4522 /*pBss->WPA2.RsnCapability = *(u16 *)pTmp; */
4523 pBss->WPA2.RsnCapability = (pTmp[1] << 8) + pTmp[0];
4524 pTmp += sizeof(u16);
4525
4526 /* Check the Pair & Group, if different, turn on mixed mode flag */
4527 if (pBss->WPA2.GroupCipher != pBss->WPA2.PairCipher)
4528 pBss->WPA2.bMixMode = TRUE;
4529
4530 break;
4531 default:
4532 break;
4533 }
4534 Length -= (pEid->Len + 2);
4535 }
4536}
4537
4538/* =========================================================================================== */
4539/* mac_table.c */
4540/* =========================================================================================== */
4541
4542/*! \brief generates a random mac address value for IBSS BSSID
4543 * \param Addr the bssid location
4544 * \return none
4545 * \pre
4546 * \post
4547 */
4548void MacAddrRandomBssid(struct rt_rtmp_adapter *pAd, u8 *pAddr)
4549{
4550 int i;
4551
4552 for (i = 0; i < MAC_ADDR_LEN; i++) {
4553 pAddr[i] = RandomByte(pAd);
4554 }
4555
4556 pAddr[0] = (pAddr[0] & 0xfe) | 0x02; /* the first 2 bits must be 01xxxxxxxx */
4557}
4558
4559/*! \brief init the management mac frame header
4560 * \param p_hdr mac header
4561 * \param subtype subtype of the frame
4562 * \param p_ds destination address, don't care if it is a broadcast address
4563 * \return none
4564 * \pre the station has the following information in the pAd->StaCfg
4565 * - bssid
4566 * - station address
4567 * \post
4568 * \note this function initializes the following field
4569
4570 IRQL = PASSIVE_LEVEL
4571 IRQL = DISPATCH_LEVEL
4572
4573 */
4574void MgtMacHeaderInit(struct rt_rtmp_adapter *pAd,
4575 struct rt_header_802_11 * pHdr80211,
4576 u8 SubType,
4577 u8 ToDs, u8 *pDA, u8 *pBssid)
4578{
4579 NdisZeroMemory(pHdr80211, sizeof(struct rt_header_802_11));
4580
4581 pHdr80211->FC.Type = BTYPE_MGMT;
4582 pHdr80211->FC.SubType = SubType;
4583/* if (SubType == SUBTYPE_ACK) // sample, no use, it will conflict with ACTION frame sub type */
4584/* pHdr80211->FC.Type = BTYPE_CNTL; */
4585 pHdr80211->FC.ToDs = ToDs;
4586 COPY_MAC_ADDR(pHdr80211->Addr1, pDA);
4587 COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress);
4588 COPY_MAC_ADDR(pHdr80211->Addr3, pBssid);
4589}
4590
4591/* =========================================================================================== */
4592/* mem_mgmt.c */
4593/* =========================================================================================== */
4594
4595/*!***************************************************************************
4596 * This routine build an outgoing frame, and fill all information specified
4597 * in argument list to the frame body. The actual frame size is the summation
4598 * of all arguments.
4599 * input params:
4600 * Buffer - pointer to a pre-allocated memory segment
4601 * args - a list of <int arg_size, arg> pairs.
4602 * NOTE NOTE NOTE! the last argument must be NULL, otherwise this
4603 * function will FAIL!
4604 * return:
4605 * Size of the buffer
4606 * usage:
4607 * MakeOutgoingFrame(Buffer, output_length, 2, &fc, 2, &dur, 6, p_addr1, 6,p_addr2, END_OF_ARGS);
4608
4609 IRQL = PASSIVE_LEVEL
4610 IRQL = DISPATCH_LEVEL
4611
4612 ****************************************************************************/
4613unsigned long MakeOutgoingFrame(u8 * Buffer, unsigned long * FrameLen, ...)
4614{
4615 u8 *p;
4616 int leng;
4617 unsigned long TotLeng;
4618 va_list Args;
4619
4620 /* calculates the total length */
4621 TotLeng = 0;
4622 va_start(Args, FrameLen);
4623 do {
4624 leng = va_arg(Args, int);
4625 if (leng == END_OF_ARGS) {
4626 break;
4627 }
4628 p = va_arg(Args, void *);
4629 NdisMoveMemory(&Buffer[TotLeng], p, leng);
4630 TotLeng = TotLeng + leng;
4631 } while (TRUE);
4632
4633 va_end(Args); /* clean up */
4634 *FrameLen = TotLeng;
4635 return TotLeng;
4636}
4637
4638/* =========================================================================================== */
4639/* mlme_queue.c */
4640/* =========================================================================================== */
4641
4642/*! \brief Initialize The MLME Queue, used by MLME Functions
4643 * \param *Queue The MLME Queue
4644 * \return Always Return NDIS_STATE_SUCCESS in this implementation
4645 * \pre
4646 * \post
4647 * \note Because this is done only once (at the init stage), no need to be locked
4648
4649 IRQL = PASSIVE_LEVEL
4650
4651 */
4652int MlmeQueueInit(struct rt_mlme_queue *Queue)
4653{
4654 int i;
4655
4656 NdisAllocateSpinLock(&Queue->Lock);
4657
4658 Queue->Num = 0;
4659 Queue->Head = 0;
4660 Queue->Tail = 0;
4661
4662 for (i = 0; i < MAX_LEN_OF_MLME_QUEUE; i++) {
4663 Queue->Entry[i].Occupied = FALSE;
4664 Queue->Entry[i].MsgLen = 0;
4665 NdisZeroMemory(Queue->Entry[i].Msg, MGMT_DMA_BUFFER_SIZE);
4666 }
4667
4668 return NDIS_STATUS_SUCCESS;
4669}
4670
4671/*! \brief Enqueue a message for other threads, if they want to send messages to MLME thread
4672 * \param *Queue The MLME Queue
4673 * \param Machine The State Machine Id
4674 * \param MsgType The Message Type
4675 * \param MsgLen The Message length
4676 * \param *Msg The message pointer
4677 * \return TRUE if enqueue is successful, FALSE if the queue is full
4678 * \pre
4679 * \post
4680 * \note The message has to be initialized
4681
4682 IRQL = PASSIVE_LEVEL
4683 IRQL = DISPATCH_LEVEL
4684
4685 */
4686BOOLEAN MlmeEnqueue(struct rt_rtmp_adapter *pAd,
4687 unsigned long Machine,
4688 unsigned long MsgType, unsigned long MsgLen, void * Msg)
4689{
4690 int Tail;
4691 struct rt_mlme_queue *Queue = (struct rt_mlme_queue *)& pAd->Mlme.Queue;
4692
4693 /* Do nothing if the driver is starting halt state. */
4694 /* This might happen when timer already been fired before cancel timer with mlmehalt */
4695 if (RTMP_TEST_FLAG
4696 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
4697 return FALSE;
4698
4699 /* First check the size, it MUST not exceed the mlme queue size */
4700 if (MsgLen > MGMT_DMA_BUFFER_SIZE) {
4701 DBGPRINT_ERR("MlmeEnqueue: msg too large, size = %ld \n", MsgLen);
4702 return FALSE;
4703 }
4704
4705 if (MlmeQueueFull(Queue)) {
4706 return FALSE;
4707 }
4708
4709 NdisAcquireSpinLock(&(Queue->Lock));
4710 Tail = Queue->Tail;
4711 Queue->Tail++;
4712 Queue->Num++;
4713 if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE) {
4714 Queue->Tail = 0;
4715 }
4716
4717 Queue->Entry[Tail].Wcid = RESERVED_WCID;
4718 Queue->Entry[Tail].Occupied = TRUE;
4719 Queue->Entry[Tail].Machine = Machine;
4720 Queue->Entry[Tail].MsgType = MsgType;
4721 Queue->Entry[Tail].MsgLen = MsgLen;
4722
4723 if (Msg != NULL) {
4724 NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen);
4725 }
4726
4727 NdisReleaseSpinLock(&(Queue->Lock));
4728 return TRUE;
4729}
4730
4731/*! \brief This function is used when Recv gets a MLME message
4732 * \param *Queue The MLME Queue
4733 * \param TimeStampHigh The upper 32 bit of timestamp
4734 * \param TimeStampLow The lower 32 bit of timestamp
4735 * \param Rssi The receiving RSSI strength
4736 * \param MsgLen The length of the message
4737 * \param *Msg The message pointer
4738 * \return TRUE if everything ok, FALSE otherwise (like Queue Full)
4739 * \pre
4740 * \post
4741
4742 IRQL = DISPATCH_LEVEL
4743
4744 */
4745BOOLEAN MlmeEnqueueForRecv(struct rt_rtmp_adapter *pAd,
4746 unsigned long Wcid,
4747 unsigned long TimeStampHigh,
4748 unsigned long TimeStampLow,
4749 u8 Rssi0,
4750 u8 Rssi1,
4751 u8 Rssi2,
4752 unsigned long MsgLen, void * Msg, u8 Signal)
4753{
4754 int Tail, Machine;
4755 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg;
4756 int MsgType;
4757 struct rt_mlme_queue *Queue = (struct rt_mlme_queue *)& pAd->Mlme.Queue;
4758
4759 /* Do nothing if the driver is starting halt state. */
4760 /* This might happen when timer already been fired before cancel timer with mlmehalt */
4761 if (RTMP_TEST_FLAG
4762 (pAd,
4763 fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) {
4764 DBGPRINT_ERR("MlmeEnqueueForRecv: fRTMP_ADAPTER_HALT_IN_PROGRESS\n");
4765 return FALSE;
4766 }
4767 /* First check the size, it MUST not exceed the mlme queue size */
4768 if (MsgLen > MGMT_DMA_BUFFER_SIZE) {
4769 DBGPRINT_ERR("MlmeEnqueueForRecv: frame too large, size = %ld \n", MsgLen);
4770 return FALSE;
4771 }
4772
4773 if (MlmeQueueFull(Queue)) {
4774 return FALSE;
4775 }
4776
4777 {
4778 if (!MsgTypeSubst(pAd, pFrame, &Machine, &MsgType)) {
4779 DBGPRINT_ERR("MlmeEnqueueForRecv: un-recongnized mgmt->subtype=%d\n", pFrame->Hdr.FC.SubType);
4780 return FALSE;
4781 }
4782 }
4783
4784 /* OK, we got all the informations, it is time to put things into queue */
4785 NdisAcquireSpinLock(&(Queue->Lock));
4786 Tail = Queue->Tail;
4787 Queue->Tail++;
4788 Queue->Num++;
4789 if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE) {
4790 Queue->Tail = 0;
4791 }
4792 Queue->Entry[Tail].Occupied = TRUE;
4793 Queue->Entry[Tail].Machine = Machine;
4794 Queue->Entry[Tail].MsgType = MsgType;
4795 Queue->Entry[Tail].MsgLen = MsgLen;
4796 Queue->Entry[Tail].TimeStamp.u.LowPart = TimeStampLow;
4797 Queue->Entry[Tail].TimeStamp.u.HighPart = TimeStampHigh;
4798 Queue->Entry[Tail].Rssi0 = Rssi0;
4799 Queue->Entry[Tail].Rssi1 = Rssi1;
4800 Queue->Entry[Tail].Rssi2 = Rssi2;
4801 Queue->Entry[Tail].Signal = Signal;
4802 Queue->Entry[Tail].Wcid = (u8)Wcid;
4803
4804 Queue->Entry[Tail].Channel = pAd->LatchRfRegs.Channel;
4805
4806 if (Msg != NULL) {
4807 NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen);
4808 }
4809
4810 NdisReleaseSpinLock(&(Queue->Lock));
4811
4812 RTMP_MLME_HANDLER(pAd);
4813
4814 return TRUE;
4815}
4816
4817/*! \brief Dequeue a message from the MLME Queue
4818 * \param *Queue The MLME Queue
4819 * \param *Elem The message dequeued from MLME Queue
4820 * \return TRUE if the Elem contains something, FALSE otherwise
4821 * \pre
4822 * \post
4823
4824 IRQL = DISPATCH_LEVEL
4825
4826 */
4827BOOLEAN MlmeDequeue(struct rt_mlme_queue *Queue, struct rt_mlme_queue_elem ** Elem)
4828{
4829 NdisAcquireSpinLock(&(Queue->Lock));
4830 *Elem = &(Queue->Entry[Queue->Head]);
4831 Queue->Num--;
4832 Queue->Head++;
4833 if (Queue->Head == MAX_LEN_OF_MLME_QUEUE) {
4834 Queue->Head = 0;
4835 }
4836 NdisReleaseSpinLock(&(Queue->Lock));
4837 return TRUE;
4838}
4839
4840/* IRQL = DISPATCH_LEVEL */
4841void MlmeRestartStateMachine(struct rt_rtmp_adapter *pAd)
4842{
4843#ifdef RTMP_MAC_PCI
4844 struct rt_mlme_queue_elem *Elem = NULL;
4845#endif /* RTMP_MAC_PCI // */
4846 BOOLEAN Cancelled;
4847
4848 DBGPRINT(RT_DEBUG_TRACE, ("MlmeRestartStateMachine \n"));
4849
4850#ifdef RTMP_MAC_PCI
4851 NdisAcquireSpinLock(&pAd->Mlme.TaskLock);
4852 if (pAd->Mlme.bRunning) {
4853 NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
4854 return;
4855 } else {
4856 pAd->Mlme.bRunning = TRUE;
4857 }
4858 NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
4859
4860 /* Remove all Mlme queues elements */
4861 while (!MlmeQueueEmpty(&pAd->Mlme.Queue)) {
4862 /*From message type, determine which state machine I should drive */
4863 if (MlmeDequeue(&pAd->Mlme.Queue, &Elem)) {
4864 /* free MLME element */
4865 Elem->Occupied = FALSE;
4866 Elem->MsgLen = 0;
4867
4868 } else {
4869 DBGPRINT_ERR("MlmeRestartStateMachine: MlmeQueue empty\n");
4870 }
4871 }
4872#endif /* RTMP_MAC_PCI // */
4873
4874 {
4875 /* Cancel all timer events */
4876 /* Be careful to cancel new added timer */
4877 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled);
4878 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled);
4879 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
4880 RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled);
4881 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled);
4882 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled);
4883
4884 }
4885
4886 /* Change back to original channel in case of doing scan */
4887 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
4888 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
4889
4890 /* Resume MSDU which is turned off durning scan */
4891 RTMPResumeMsduTransmission(pAd);
4892
4893 {
4894 /* Set all state machines back IDLE */
4895 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
4896 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4897 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
4898 pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE;
4899 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
4900 pAd->Mlme.ActMachine.CurrState = ACT_IDLE;
4901 }
4902
4903#ifdef RTMP_MAC_PCI
4904 /* Remove running state */
4905 NdisAcquireSpinLock(&pAd->Mlme.TaskLock);
4906 pAd->Mlme.bRunning = FALSE;
4907 NdisReleaseSpinLock(&pAd->Mlme.TaskLock);
4908#endif /* RTMP_MAC_PCI // */
4909}
4910
4911/*! \brief test if the MLME Queue is empty
4912 * \param *Queue The MLME Queue
4913 * \return TRUE if the Queue is empty, FALSE otherwise
4914 * \pre
4915 * \post
4916
4917 IRQL = DISPATCH_LEVEL
4918
4919 */
4920BOOLEAN MlmeQueueEmpty(struct rt_mlme_queue *Queue)
4921{
4922 BOOLEAN Ans;
4923
4924 NdisAcquireSpinLock(&(Queue->Lock));
4925 Ans = (Queue->Num == 0);
4926 NdisReleaseSpinLock(&(Queue->Lock));
4927
4928 return Ans;
4929}
4930
4931/*! \brief test if the MLME Queue is full
4932 * \param *Queue The MLME Queue
4933 * \return TRUE if the Queue is empty, FALSE otherwise
4934 * \pre
4935 * \post
4936
4937 IRQL = PASSIVE_LEVEL
4938 IRQL = DISPATCH_LEVEL
4939
4940 */
4941BOOLEAN MlmeQueueFull(struct rt_mlme_queue *Queue)
4942{
4943 BOOLEAN Ans;
4944
4945 NdisAcquireSpinLock(&(Queue->Lock));
4946 Ans = (Queue->Num == MAX_LEN_OF_MLME_QUEUE
4947 || Queue->Entry[Queue->Tail].Occupied);
4948 NdisReleaseSpinLock(&(Queue->Lock));
4949
4950 return Ans;
4951}
4952
4953/*! \brief The destructor of MLME Queue
4954 * \param
4955 * \return
4956 * \pre
4957 * \post
4958 * \note Clear Mlme Queue, Set Queue->Num to Zero.
4959
4960 IRQL = PASSIVE_LEVEL
4961
4962 */
4963void MlmeQueueDestroy(struct rt_mlme_queue *pQueue)
4964{
4965 NdisAcquireSpinLock(&(pQueue->Lock));
4966 pQueue->Num = 0;
4967 pQueue->Head = 0;
4968 pQueue->Tail = 0;
4969 NdisReleaseSpinLock(&(pQueue->Lock));
4970 NdisFreeSpinLock(&(pQueue->Lock));
4971}
4972
4973/*! \brief To substitute the message type if the message is coming from external
4974 * \param pFrame The frame received
4975 * \param *Machine The state machine
4976 * \param *MsgType the message type for the state machine
4977 * \return TRUE if the substitution is successful, FALSE otherwise
4978 * \pre
4979 * \post
4980
4981 IRQL = DISPATCH_LEVEL
4982
4983 */
4984BOOLEAN MsgTypeSubst(struct rt_rtmp_adapter *pAd,
4985 struct rt_frame_802_11 * pFrame,
4986 int * Machine, int * MsgType)
4987{
4988 u16 Seq, Alg;
4989 u8 EAPType;
4990 u8 *pData;
4991
4992 /* Pointer to start of data frames including SNAP header */
4993 pData = (u8 *)pFrame + LENGTH_802_11;
4994
4995 /* The only data type will pass to this function is EAPOL frame */
4996 if (pFrame->Hdr.FC.Type == BTYPE_DATA) {
4997 {
4998 *Machine = WPA_STATE_MACHINE;
4999 EAPType =
5000 *((u8 *) pFrame + LENGTH_802_11 +
5001 LENGTH_802_1_H + 1);
5002 return (WpaMsgTypeSubst(EAPType, (int *) MsgType));
5003 }
5004 }
5005
5006 switch (pFrame->Hdr.FC.SubType) {
5007 case SUBTYPE_ASSOC_REQ:
5008 *Machine = ASSOC_STATE_MACHINE;
5009 *MsgType = MT2_PEER_ASSOC_REQ;
5010 break;
5011 case SUBTYPE_ASSOC_RSP:
5012 *Machine = ASSOC_STATE_MACHINE;
5013 *MsgType = MT2_PEER_ASSOC_RSP;
5014 break;
5015 case SUBTYPE_REASSOC_REQ:
5016 *Machine = ASSOC_STATE_MACHINE;
5017 *MsgType = MT2_PEER_REASSOC_REQ;
5018 break;
5019 case SUBTYPE_REASSOC_RSP:
5020 *Machine = ASSOC_STATE_MACHINE;
5021 *MsgType = MT2_PEER_REASSOC_RSP;
5022 break;
5023 case SUBTYPE_PROBE_REQ:
5024 *Machine = SYNC_STATE_MACHINE;
5025 *MsgType = MT2_PEER_PROBE_REQ;
5026 break;
5027 case SUBTYPE_PROBE_RSP:
5028 *Machine = SYNC_STATE_MACHINE;
5029 *MsgType = MT2_PEER_PROBE_RSP;
5030 break;
5031 case SUBTYPE_BEACON:
5032 *Machine = SYNC_STATE_MACHINE;
5033 *MsgType = MT2_PEER_BEACON;
5034 break;
5035 case SUBTYPE_ATIM:
5036 *Machine = SYNC_STATE_MACHINE;
5037 *MsgType = MT2_PEER_ATIM;
5038 break;
5039 case SUBTYPE_DISASSOC:
5040 *Machine = ASSOC_STATE_MACHINE;
5041 *MsgType = MT2_PEER_DISASSOC_REQ;
5042 break;
5043 case SUBTYPE_AUTH:
5044 /* get the sequence number from payload 24 Mac Header + 2 bytes algorithm */
5045 NdisMoveMemory(&Seq, &pFrame->Octet[2], sizeof(u16));
5046 NdisMoveMemory(&Alg, &pFrame->Octet[0], sizeof(u16));
5047 if (Seq == 1 || Seq == 3) {
5048 *Machine = AUTH_RSP_STATE_MACHINE;
5049 *MsgType = MT2_PEER_AUTH_ODD;
5050 } else if (Seq == 2 || Seq == 4) {
5051 if (Alg == AUTH_MODE_OPEN || Alg == AUTH_MODE_KEY) {
5052 *Machine = AUTH_STATE_MACHINE;
5053 *MsgType = MT2_PEER_AUTH_EVEN;
5054 }
5055 } else {
5056 return FALSE;
5057 }
5058 break;
5059 case SUBTYPE_DEAUTH:
5060 *Machine = AUTH_RSP_STATE_MACHINE;
5061 *MsgType = MT2_PEER_DEAUTH;
5062 break;
5063 case SUBTYPE_ACTION:
5064 *Machine = ACTION_STATE_MACHINE;
5065 /* Sometimes Sta will return with category bytes with MSB = 1, if they receive catogory out of their support */
5066 if ((pFrame->Octet[0] & 0x7F) > MAX_PEER_CATE_MSG) {
5067 *MsgType = MT2_ACT_INVALID;
5068 } else {
5069 *MsgType = (pFrame->Octet[0] & 0x7F);
5070 }
5071 break;
5072 default:
5073 return FALSE;
5074 break;
5075 }
5076
5077 return TRUE;
5078}
5079
5080/* =========================================================================================== */
5081/* state_machine.c */
5082/* =========================================================================================== */
5083
5084/*! \brief Initialize the state machine.
5085 * \param *S pointer to the state machine
5086 * \param Trans State machine transition function
5087 * \param StNr number of states
5088 * \param MsgNr number of messages
5089 * \param DefFunc default function, when there is invalid state/message combination
5090 * \param InitState initial state of the state machine
5091 * \param Base StateMachine base, internal use only
5092 * \pre p_sm should be a legal pointer
5093 * \post
5094
5095 IRQL = PASSIVE_LEVEL
5096
5097 */
5098void StateMachineInit(struct rt_state_machine *S,
5099 IN STATE_MACHINE_FUNC Trans[],
5100 unsigned long StNr,
5101 unsigned long MsgNr,
5102 IN STATE_MACHINE_FUNC DefFunc,
5103 unsigned long InitState, unsigned long Base)
5104{
5105 unsigned long i, j;
5106
5107 /* set number of states and messages */
5108 S->NrState = StNr;
5109 S->NrMsg = MsgNr;
5110 S->Base = Base;
5111
5112 S->TransFunc = Trans;
5113
5114 /* init all state transition to default function */
5115 for (i = 0; i < StNr; i++) {
5116 for (j = 0; j < MsgNr; j++) {
5117 S->TransFunc[i * MsgNr + j] = DefFunc;
5118 }
5119 }
5120
5121 /* set the starting state */
5122 S->CurrState = InitState;
5123}
5124
5125/*! \brief This function fills in the function pointer into the cell in the state machine
5126 * \param *S pointer to the state machine
5127 * \param St state
5128 * \param Msg incoming message
5129 * \param f the function to be executed when (state, message) combination occurs at the state machine
5130 * \pre *S should be a legal pointer to the state machine, st, msg, should be all within the range, Base should be set in the initial state
5131 * \post
5132
5133 IRQL = PASSIVE_LEVEL
5134
5135 */
5136void StateMachineSetAction(struct rt_state_machine *S,
5137 unsigned long St,
5138 unsigned long Msg, IN STATE_MACHINE_FUNC Func)
5139{
5140 unsigned long MsgIdx;
5141
5142 MsgIdx = Msg - S->Base;
5143
5144 if (St < S->NrState && MsgIdx < S->NrMsg) {
5145 /* boundary checking before setting the action */
5146 S->TransFunc[St * S->NrMsg + MsgIdx] = Func;
5147 }
5148}
5149
5150/*! \brief This function does the state transition
5151 * \param *Adapter the NIC adapter pointer
5152 * \param *S the state machine
5153 * \param *Elem the message to be executed
5154 * \return None
5155
5156 IRQL = DISPATCH_LEVEL
5157
5158 */
5159void StateMachinePerformAction(struct rt_rtmp_adapter *pAd,
5160 struct rt_state_machine *S, struct rt_mlme_queue_elem *Elem)
5161{
5162 (*(S->TransFunc[S->CurrState * S->NrMsg + Elem->MsgType - S->Base]))
5163 (pAd, Elem);
5164}
5165
5166/*
5167 ==========================================================================
5168 Description:
5169 The drop function, when machine executes this, the message is simply
5170 ignored. This function does nothing, the message is freed in
5171 StateMachinePerformAction()
5172 ==========================================================================
5173 */
5174void Drop(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
5175{
5176}
5177
5178/* =========================================================================================== */
5179/* lfsr.c */
5180/* =========================================================================================== */
5181
5182/*
5183 ==========================================================================
5184 Description:
5185
5186 IRQL = PASSIVE_LEVEL
5187
5188 ==========================================================================
5189 */
5190void LfsrInit(struct rt_rtmp_adapter *pAd, unsigned long Seed)
5191{
5192 if (Seed == 0)
5193 pAd->Mlme.ShiftReg = 1;
5194 else
5195 pAd->Mlme.ShiftReg = Seed;
5196}
5197
5198/*
5199 ==========================================================================
5200 Description:
5201 ==========================================================================
5202 */
5203u8 RandomByte(struct rt_rtmp_adapter *pAd)
5204{
5205 unsigned long i;
5206 u8 R, Result;
5207
5208 R = 0;
5209
5210 if (pAd->Mlme.ShiftReg == 0)
5211 NdisGetSystemUpTime((unsigned long *) & pAd->Mlme.ShiftReg);
5212
5213 for (i = 0; i < 8; i++) {
5214 if (pAd->Mlme.ShiftReg & 0x00000001) {
5215 pAd->Mlme.ShiftReg =
5216 ((pAd->Mlme.
5217 ShiftReg ^ LFSR_MASK) >> 1) | 0x80000000;
5218 Result = 1;
5219 } else {
5220 pAd->Mlme.ShiftReg = pAd->Mlme.ShiftReg >> 1;
5221 Result = 0;
5222 }
5223 R = (R << 1) | Result;
5224 }
5225
5226 return R;
5227}
5228
5229/*
5230 ========================================================================
5231
5232 Routine Description:
5233 Verify the support rate for different PHY type
5234
5235 Arguments:
5236 pAd Pointer to our adapter
5237
5238 Return Value:
5239 None
5240
5241 IRQL = PASSIVE_LEVEL
5242
5243 ========================================================================
5244*/
5245void RTMPCheckRates(struct rt_rtmp_adapter *pAd,
5246 IN u8 SupRate[], IN u8 * SupRateLen)
5247{
5248 u8 RateIdx, i, j;
5249 u8 NewRate[12], NewRateLen;
5250
5251 NewRateLen = 0;
5252
5253 if (pAd->CommonCfg.PhyMode == PHY_11B)
5254 RateIdx = 4;
5255 else
5256 RateIdx = 12;
5257
5258 /* Check for support rates exclude basic rate bit */
5259 for (i = 0; i < *SupRateLen; i++)
5260 for (j = 0; j < RateIdx; j++)
5261 if ((SupRate[i] & 0x7f) == RateIdTo500Kbps[j])
5262 NewRate[NewRateLen++] = SupRate[i];
5263
5264 *SupRateLen = NewRateLen;
5265 NdisMoveMemory(SupRate, NewRate, NewRateLen);
5266}
5267
5268BOOLEAN RTMPCheckChannel(struct rt_rtmp_adapter *pAd,
5269 u8 CentralChannel, u8 Channel)
5270{
5271 u8 k;
5272 u8 UpperChannel = 0, LowerChannel = 0;
5273 u8 NoEffectChannelinList = 0;
5274
5275 /* Find upper and lower channel according to 40MHz current operation. */
5276 if (CentralChannel < Channel) {
5277 UpperChannel = Channel;
5278 if (CentralChannel > 2)
5279 LowerChannel = CentralChannel - 2;
5280 else
5281 return FALSE;
5282 } else if (CentralChannel > Channel) {
5283 UpperChannel = CentralChannel + 2;
5284 LowerChannel = Channel;
5285 }
5286
5287 for (k = 0; k < pAd->ChannelListNum; k++) {
5288 if (pAd->ChannelList[k].Channel == UpperChannel) {
5289 NoEffectChannelinList++;
5290 }
5291 if (pAd->ChannelList[k].Channel == LowerChannel) {
5292 NoEffectChannelinList++;
5293 }
5294 }
5295
5296 DBGPRINT(RT_DEBUG_TRACE,
5297 ("Total Channel in Channel List = [%d]\n",
5298 NoEffectChannelinList));
5299 if (NoEffectChannelinList == 2)
5300 return TRUE;
5301 else
5302 return FALSE;
5303}
5304
5305/*
5306 ========================================================================
5307
5308 Routine Description:
5309 Verify the support rate for HT phy type
5310
5311 Arguments:
5312 pAd Pointer to our adapter
5313
5314 Return Value:
5315 FALSE if pAd->CommonCfg.SupportedHtPhy doesn't accept the pHtCapability. (AP Mode)
5316
5317 IRQL = PASSIVE_LEVEL
5318
5319 ========================================================================
5320*/
5321BOOLEAN RTMPCheckHt(struct rt_rtmp_adapter *pAd,
5322 u8 Wcid,
5323 struct rt_ht_capability_ie * pHtCapability,
5324 struct rt_add_ht_info_ie * pAddHtInfo)
5325{
5326 if (Wcid >= MAX_LEN_OF_MAC_TABLE)
5327 return FALSE;
5328
5329 /* If use AMSDU, set flag. */
5330 if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable)
5331 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid],
5332 fCLIENT_STATUS_AMSDU_INUSED);
5333 /* Save Peer Capability */
5334 if (pHtCapability->HtCapInfo.ShortGIfor20)
5335 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid],
5336 fCLIENT_STATUS_SGI20_CAPABLE);
5337 if (pHtCapability->HtCapInfo.ShortGIfor40)
5338 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid],
5339 fCLIENT_STATUS_SGI40_CAPABLE);
5340 if (pHtCapability->HtCapInfo.TxSTBC)
5341 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid],
5342 fCLIENT_STATUS_TxSTBC_CAPABLE);
5343 if (pHtCapability->HtCapInfo.RxSTBC)
5344 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid],
5345 fCLIENT_STATUS_RxSTBC_CAPABLE);
5346 if (pAd->CommonCfg.bRdg && pHtCapability->ExtHtCapInfo.RDGSupport) {
5347 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid],
5348 fCLIENT_STATUS_RDG_CAPABLE);
5349 }
5350
5351 if (Wcid < MAX_LEN_OF_MAC_TABLE) {
5352 pAd->MacTab.Content[Wcid].MpduDensity =
5353 pHtCapability->HtCapParm.MpduDensity;
5354 }
5355 /* Will check ChannelWidth for MCSSet[4] below */
5356 pAd->MlmeAux.HtCapability.MCSSet[4] = 0x1;
5357 switch (pAd->CommonCfg.RxStream) {
5358 case 1:
5359 pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
5360 pAd->MlmeAux.HtCapability.MCSSet[1] = 0x00;
5361 pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00;
5362 pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
5363 break;
5364 case 2:
5365 pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
5366 pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff;
5367 pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00;
5368 pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
5369 break;
5370 case 3:
5371 pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff;
5372 pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff;
5373 pAd->MlmeAux.HtCapability.MCSSet[2] = 0xff;
5374 pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00;
5375 break;
5376 }
5377
5378 pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth =
5379 pAddHtInfo->AddHtInfo.RecomWidth & pAd->CommonCfg.DesiredHtPhy.
5380 ChannelWidth;
5381
5382 DBGPRINT(RT_DEBUG_TRACE,
5383 ("RTMPCheckHt:: HtCapInfo.ChannelWidth=%d, RecomWidth=%d, DesiredHtPhy.ChannelWidth=%d, BW40MAvailForA/G=%d/%d, PhyMode=%d \n",
5384 pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth,
5385 pAddHtInfo->AddHtInfo.RecomWidth,
5386 pAd->CommonCfg.DesiredHtPhy.ChannelWidth,
5387 pAd->NicConfig2.field.BW40MAvailForA,
5388 pAd->NicConfig2.field.BW40MAvailForG,
5389 pAd->CommonCfg.PhyMode));
5390
5391 pAd->MlmeAux.HtCapability.HtCapInfo.GF =
5392 pHtCapability->HtCapInfo.GF & pAd->CommonCfg.DesiredHtPhy.GF;
5393
5394 /* Send Assoc Req with my HT capability. */
5395 pAd->MlmeAux.HtCapability.HtCapInfo.AMsduSize =
5396 pAd->CommonCfg.DesiredHtPhy.AmsduSize;
5397 pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs =
5398 pAd->CommonCfg.DesiredHtPhy.MimoPs;
5399 pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20 =
5400 (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20) & (pHtCapability->
5401 HtCapInfo.
5402 ShortGIfor20);
5403 pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40 =
5404 (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40) & (pHtCapability->
5405 HtCapInfo.
5406 ShortGIfor40);
5407 pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC =
5408 (pAd->CommonCfg.DesiredHtPhy.TxSTBC) & (pHtCapability->HtCapInfo.
5409 RxSTBC);
5410 pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC =
5411 (pAd->CommonCfg.DesiredHtPhy.RxSTBC) & (pHtCapability->HtCapInfo.
5412 TxSTBC);
5413 pAd->MlmeAux.HtCapability.HtCapParm.MaxRAmpduFactor =
5414 pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor;
5415 pAd->MlmeAux.HtCapability.HtCapParm.MpduDensity =
5416 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity;
5417 pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC =
5418 pHtCapability->ExtHtCapInfo.PlusHTC;
5419 pAd->MacTab.Content[Wcid].HTCapability.ExtHtCapInfo.PlusHTC =
5420 pHtCapability->ExtHtCapInfo.PlusHTC;
5421 if (pAd->CommonCfg.bRdg) {
5422 pAd->MlmeAux.HtCapability.ExtHtCapInfo.RDGSupport =
5423 pHtCapability->ExtHtCapInfo.RDGSupport;
5424 pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = 1;
5425 }
5426
5427 if (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_20)
5428 pAd->MlmeAux.HtCapability.MCSSet[4] = 0x0; /* BW20 can't transmit MCS32 */
5429
5430 COPY_AP_HTSETTINGS_FROM_BEACON(pAd, pHtCapability);
5431 return TRUE;
5432}
5433
5434/*
5435 ========================================================================
5436
5437 Routine Description:
5438 Verify the support rate for different PHY type
5439
5440 Arguments:
5441 pAd Pointer to our adapter
5442
5443 Return Value:
5444 None
5445
5446 IRQL = PASSIVE_LEVEL
5447
5448 ========================================================================
5449*/
5450void RTMPUpdateMlmeRate(struct rt_rtmp_adapter *pAd)
5451{
5452 u8 MinimumRate;
5453 u8 ProperMlmeRate; /*= RATE_54; */
5454 u8 i, j, RateIdx = 12; /*1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */
5455 BOOLEAN bMatch = FALSE;
5456
5457 switch (pAd->CommonCfg.PhyMode) {
5458 case PHY_11B:
5459 ProperMlmeRate = RATE_11;
5460 MinimumRate = RATE_1;
5461 break;
5462 case PHY_11BG_MIXED:
5463 case PHY_11ABGN_MIXED:
5464 case PHY_11BGN_MIXED:
5465 if ((pAd->MlmeAux.SupRateLen == 4) &&
5466 (pAd->MlmeAux.ExtRateLen == 0))
5467 /* B only AP */
5468 ProperMlmeRate = RATE_11;
5469 else
5470 ProperMlmeRate = RATE_24;
5471
5472 if (pAd->MlmeAux.Channel <= 14)
5473 MinimumRate = RATE_1;
5474 else
5475 MinimumRate = RATE_6;
5476 break;
5477 case PHY_11A:
5478 case PHY_11N_2_4G: /* rt2860 need to check mlmerate for 802.11n */
5479 case PHY_11GN_MIXED:
5480 case PHY_11AGN_MIXED:
5481 case PHY_11AN_MIXED:
5482 case PHY_11N_5G:
5483 ProperMlmeRate = RATE_24;
5484 MinimumRate = RATE_6;
5485 break;
5486 case PHY_11ABG_MIXED:
5487 ProperMlmeRate = RATE_24;
5488 if (pAd->MlmeAux.Channel <= 14)
5489 MinimumRate = RATE_1;
5490 else
5491 MinimumRate = RATE_6;
5492 break;
5493 default: /* error */
5494 ProperMlmeRate = RATE_1;
5495 MinimumRate = RATE_1;
5496 break;
5497 }
5498
5499 for (i = 0; i < pAd->MlmeAux.SupRateLen; i++) {
5500 for (j = 0; j < RateIdx; j++) {
5501 if ((pAd->MlmeAux.SupRate[i] & 0x7f) ==
5502 RateIdTo500Kbps[j]) {
5503 if (j == ProperMlmeRate) {
5504 bMatch = TRUE;
5505 break;
5506 }
5507 }
5508 }
5509
5510 if (bMatch)
5511 break;
5512 }
5513
5514 if (bMatch == FALSE) {
5515 for (i = 0; i < pAd->MlmeAux.ExtRateLen; i++) {
5516 for (j = 0; j < RateIdx; j++) {
5517 if ((pAd->MlmeAux.ExtRate[i] & 0x7f) ==
5518 RateIdTo500Kbps[j]) {
5519 if (j == ProperMlmeRate) {
5520 bMatch = TRUE;
5521 break;
5522 }
5523 }
5524 }
5525
5526 if (bMatch)
5527 break;
5528 }
5529 }
5530
5531 if (bMatch == FALSE) {
5532 ProperMlmeRate = MinimumRate;
5533 }
5534
5535 pAd->CommonCfg.MlmeRate = MinimumRate;
5536 pAd->CommonCfg.RtsRate = ProperMlmeRate;
5537 if (pAd->CommonCfg.MlmeRate >= RATE_6) {
5538 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
5539 pAd->CommonCfg.MlmeTransmit.field.MCS =
5540 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
5541 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE =
5542 MODE_OFDM;
5543 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS =
5544 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
5545 } else {
5546 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK;
5547 pAd->CommonCfg.MlmeTransmit.field.MCS = pAd->CommonCfg.MlmeRate;
5548 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE =
5549 MODE_CCK;
5550 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS =
5551 pAd->CommonCfg.MlmeRate;
5552 }
5553
5554 DBGPRINT(RT_DEBUG_TRACE,
5555 ("RTMPUpdateMlmeRate ==> MlmeTransmit = 0x%x \n",
5556 pAd->CommonCfg.MlmeTransmit.word));
5557}
5558
5559char RTMPMaxRssi(struct rt_rtmp_adapter *pAd,
5560 char Rssi0, char Rssi1, char Rssi2)
5561{
5562 char larger = -127;
5563
5564 if ((pAd->Antenna.field.RxPath == 1) && (Rssi0 != 0)) {
5565 larger = Rssi0;
5566 }
5567
5568 if ((pAd->Antenna.field.RxPath >= 2) && (Rssi1 != 0)) {
5569 larger = max(Rssi0, Rssi1);
5570 }
5571
5572 if ((pAd->Antenna.field.RxPath == 3) && (Rssi2 != 0)) {
5573 larger = max(larger, Rssi2);
5574 }
5575
5576 if (larger == -127)
5577 larger = 0;
5578
5579 return larger;
5580}
5581
5582/*
5583 ========================================================================
5584 Routine Description:
5585 Periodic evaluate antenna link status
5586
5587 Arguments:
5588 pAd - Adapter pointer
5589
5590 Return Value:
5591 None
5592
5593 ========================================================================
5594*/
5595void AsicEvaluateRxAnt(struct rt_rtmp_adapter *pAd)
5596{
5597 u8 BBPR3 = 0;
5598
5599 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS |
5600 fRTMP_ADAPTER_HALT_IN_PROGRESS |
5601 fRTMP_ADAPTER_RADIO_OFF |
5602 fRTMP_ADAPTER_NIC_NOT_EXIST |
5603 fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS) ||
5604 OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)
5605#ifdef RT30xx
5606 || (pAd->EepromAccess)
5607#endif /* RT30xx // */
5608#ifdef RT3090
5609 || (pAd->bPCIclkOff == TRUE)
5610#endif /* RT3090 // */
5611 )
5612 return;
5613
5614 {
5615 /*if (pAd->StaCfg.Psm == PWR_SAVE) */
5616 /* return; */
5617
5618 {
5619
5620 if (pAd->StaCfg.Psm == PWR_SAVE)
5621 return;
5622
5623 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
5624 BBPR3 &= (~0x18);
5625 if (pAd->Antenna.field.RxPath == 3) {
5626 BBPR3 |= (0x10);
5627 } else if (pAd->Antenna.field.RxPath == 2) {
5628 BBPR3 |= (0x8);
5629 } else if (pAd->Antenna.field.RxPath == 1) {
5630 BBPR3 |= (0x0);
5631 }
5632 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
5633#ifdef RTMP_MAC_PCI
5634 pAd->StaCfg.BBPR3 = BBPR3;
5635#endif /* RTMP_MAC_PCI // */
5636 if (OPSTATUS_TEST_FLAG
5637 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
5638 ) {
5639 unsigned long TxTotalCnt =
5640 pAd->RalinkCounters.OneSecTxNoRetryOkCount +
5641 pAd->RalinkCounters.OneSecTxRetryOkCount +
5642 pAd->RalinkCounters.OneSecTxFailCount;
5643
5644 /* dynamic adjust antenna evaluation period according to the traffic */
5645 if (TxTotalCnt > 50) {
5646 RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer,
5647 20);
5648 pAd->Mlme.bLowThroughput = FALSE;
5649 } else {
5650 RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer,
5651 300);
5652 pAd->Mlme.bLowThroughput = TRUE;
5653 }
5654 }
5655 }
5656
5657 }
5658
5659}
5660
5661/*
5662 ========================================================================
5663 Routine Description:
5664 After evaluation, check antenna link status
5665
5666 Arguments:
5667 pAd - Adapter pointer
5668
5669 Return Value:
5670 None
5671
5672 ========================================================================
5673*/
5674void AsicRxAntEvalTimeout(void *SystemSpecific1,
5675 void *FunctionContext,
5676 void *SystemSpecific2, void *SystemSpecific3)
5677{
5678 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
5679 u8 BBPR3 = 0;
5680 char larger = -127, rssi0, rssi1, rssi2;
5681
5682 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS |
5683 fRTMP_ADAPTER_HALT_IN_PROGRESS |
5684 fRTMP_ADAPTER_RADIO_OFF |
5685 fRTMP_ADAPTER_NIC_NOT_EXIST) ||
5686 OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)
5687#ifdef RT30xx
5688 || (pAd->EepromAccess)
5689#endif /* RT30xx // */
5690#ifdef RT3090
5691 || (pAd->bPCIclkOff == TRUE)
5692#endif /* RT3090 // */
5693 )
5694 return;
5695
5696 {
5697 /*if (pAd->StaCfg.Psm == PWR_SAVE) */
5698 /* return; */
5699 {
5700 if (pAd->StaCfg.Psm == PWR_SAVE)
5701 return;
5702
5703 /* if the traffic is low, use average rssi as the criteria */
5704 if (pAd->Mlme.bLowThroughput == TRUE) {
5705 rssi0 = pAd->StaCfg.RssiSample.LastRssi0;
5706 rssi1 = pAd->StaCfg.RssiSample.LastRssi1;
5707 rssi2 = pAd->StaCfg.RssiSample.LastRssi2;
5708 } else {
5709 rssi0 = pAd->StaCfg.RssiSample.AvgRssi0;
5710 rssi1 = pAd->StaCfg.RssiSample.AvgRssi1;
5711 rssi2 = pAd->StaCfg.RssiSample.AvgRssi2;
5712 }
5713
5714 if (pAd->Antenna.field.RxPath == 3) {
5715 larger = max(rssi0, rssi1);
5716
5717 if (larger > (rssi2 + 20))
5718 pAd->Mlme.RealRxPath = 2;
5719 else
5720 pAd->Mlme.RealRxPath = 3;
5721 } else if (pAd->Antenna.field.RxPath == 2) {
5722 if (rssi0 > (rssi1 + 20))
5723 pAd->Mlme.RealRxPath = 1;
5724 else
5725 pAd->Mlme.RealRxPath = 2;
5726 }
5727
5728 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
5729 BBPR3 &= (~0x18);
5730 if (pAd->Mlme.RealRxPath == 3) {
5731 BBPR3 |= (0x10);
5732 } else if (pAd->Mlme.RealRxPath == 2) {
5733 BBPR3 |= (0x8);
5734 } else if (pAd->Mlme.RealRxPath == 1) {
5735 BBPR3 |= (0x0);
5736 }
5737 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
5738#ifdef RTMP_MAC_PCI
5739 pAd->StaCfg.BBPR3 = BBPR3;
5740#endif /* RTMP_MAC_PCI // */
5741 }
5742 }
5743
5744}
5745
5746void APSDPeriodicExec(void *SystemSpecific1,
5747 void *FunctionContext,
5748 void *SystemSpecific2, void *SystemSpecific3)
5749{
5750 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
5751
5752 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
5753 return;
5754
5755 pAd->CommonCfg.TriggerTimerCount++;
5756
5757/* Driver should not send trigger frame, it should be send by application layer */
5758/*
5759 if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable
5760 && (pAd->CommonCfg.bNeedSendTriggerFrame ||
5761 (((pAd->CommonCfg.TriggerTimerCount%20) == 19) && (!pAd->CommonCfg.bAPSDAC_BE || !pAd->CommonCfg.bAPSDAC_BK || !pAd->CommonCfg.bAPSDAC_VI || !pAd->CommonCfg.bAPSDAC_VO))))
5762 {
5763 DBGPRINT(RT_DEBUG_TRACE,("Sending trigger frame and enter service period when support APSD\n"));
5764 RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE);
5765 pAd->CommonCfg.bNeedSendTriggerFrame = FALSE;
5766 pAd->CommonCfg.TriggerTimerCount = 0;
5767 pAd->CommonCfg.bInServicePeriod = TRUE;
5768 }*/
5769}
5770
5771/*
5772 ========================================================================
5773 Routine Description:
5774 Set/reset MAC registers according to bPiggyBack parameter
5775
5776 Arguments:
5777 pAd - Adapter pointer
5778 bPiggyBack - Enable / Disable Piggy-Back
5779
5780 Return Value:
5781 None
5782
5783 ========================================================================
5784*/
5785void RTMPSetPiggyBack(struct rt_rtmp_adapter *pAd, IN BOOLEAN bPiggyBack)
5786{
5787 TX_LINK_CFG_STRUC TxLinkCfg;
5788
5789 RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word);
5790
5791 TxLinkCfg.field.TxCFAckEn = bPiggyBack;
5792 RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word);
5793}
5794
5795/*
5796 ========================================================================
5797 Routine Description:
5798 check if this entry need to switch rate automatically
5799
5800 Arguments:
5801 pAd
5802 pEntry
5803
5804 Return Value:
5805 TURE
5806 FALSE
5807
5808 ========================================================================
5809*/
5810BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(struct rt_rtmp_adapter *pAd,
5811 struct rt_mac_table_entry *pEntry)
5812{
5813 BOOLEAN result = TRUE;
5814
5815 {
5816 /* only associated STA counts */
5817 if (pEntry && (pEntry->ValidAsCLI)
5818 && (pEntry->Sst == SST_ASSOC)) {
5819 result = pAd->StaCfg.bAutoTxRateSwitch;
5820 } else
5821 result = FALSE;
5822 }
5823
5824 return result;
5825}
5826
5827BOOLEAN RTMPAutoRateSwitchCheck(struct rt_rtmp_adapter *pAd)
5828{
5829 {
5830 if (pAd->StaCfg.bAutoTxRateSwitch)
5831 return TRUE;
5832 }
5833 return FALSE;
5834}
5835
5836/*
5837 ========================================================================
5838 Routine Description:
5839 check if this entry need to fix tx legacy rate
5840
5841 Arguments:
5842 pAd
5843 pEntry
5844
5845 Return Value:
5846 TURE
5847 FALSE
5848
5849 ========================================================================
5850*/
5851u8 RTMPStaFixedTxMode(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry)
5852{
5853 u8 tx_mode = FIXED_TXMODE_HT;
5854
5855 {
5856 tx_mode =
5857 (u8)pAd->StaCfg.DesiredTransmitSetting.field.
5858 FixedTxMode;
5859 }
5860
5861 return tx_mode;
5862}
5863
5864/*
5865 ========================================================================
5866 Routine Description:
5867 Overwrite HT Tx Mode by Fixed Legency Tx Mode, if specified.
5868
5869 Arguments:
5870 pAd
5871 pEntry
5872
5873 Return Value:
5874 TURE
5875 FALSE
5876
5877 ========================================================================
5878*/
5879void RTMPUpdateLegacyTxSetting(u8 fixed_tx_mode, struct rt_mac_table_entry *pEntry)
5880{
5881 HTTRANSMIT_SETTING TransmitSetting;
5882
5883 if (fixed_tx_mode == FIXED_TXMODE_HT)
5884 return;
5885
5886 TransmitSetting.word = 0;
5887
5888 TransmitSetting.field.MODE = pEntry->HTPhyMode.field.MODE;
5889 TransmitSetting.field.MCS = pEntry->HTPhyMode.field.MCS;
5890
5891 if (fixed_tx_mode == FIXED_TXMODE_CCK) {
5892 TransmitSetting.field.MODE = MODE_CCK;
5893 /* CCK mode allow MCS 0~3 */
5894 if (TransmitSetting.field.MCS > MCS_3)
5895 TransmitSetting.field.MCS = MCS_3;
5896 } else {
5897 TransmitSetting.field.MODE = MODE_OFDM;
5898 /* OFDM mode allow MCS 0~7 */
5899 if (TransmitSetting.field.MCS > MCS_7)
5900 TransmitSetting.field.MCS = MCS_7;
5901 }
5902
5903 if (pEntry->HTPhyMode.field.MODE >= TransmitSetting.field.MODE) {
5904 pEntry->HTPhyMode.word = TransmitSetting.word;
5905 DBGPRINT(RT_DEBUG_TRACE,
5906 ("RTMPUpdateLegacyTxSetting : wcid-%d, MODE=%s, MCS=%d \n",
5907 pEntry->Aid, GetPhyMode(pEntry->HTPhyMode.field.MODE),
5908 pEntry->HTPhyMode.field.MCS));
5909 }
5910}
5911
5912/*
5913 ==========================================================================
5914 Description:
5915 dynamic tune BBP R66 to find a balance between sensibility and
5916 noise isolation
5917
5918 IRQL = DISPATCH_LEVEL
5919
5920 ==========================================================================
5921 */
5922void AsicStaBbpTuning(struct rt_rtmp_adapter *pAd)
5923{
5924 u8 OrigR66Value = 0, R66; /*, R66UpperBound = 0x30, R66LowerBound = 0x30; */
5925 char Rssi;
5926
5927 /* 2860C did not support Fase CCA, therefore can't tune */
5928 if (pAd->MACVersion == 0x28600100)
5929 return;
5930
5931 /* */
5932 /* work as a STA */
5933 /* */
5934 if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) /* no R66 tuning when SCANNING */
5935 return;
5936
5937 if ((pAd->OpMode == OPMODE_STA)
5938 && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
5939 )
5940 && !(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
5941#ifdef RTMP_MAC_PCI
5942 && (pAd->bPCIclkOff == FALSE)
5943#endif /* RTMP_MAC_PCI // */
5944 ) {
5945 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &OrigR66Value);
5946 R66 = OrigR66Value;
5947
5948 if (pAd->Antenna.field.RxPath > 1)
5949 Rssi =
5950 (pAd->StaCfg.RssiSample.AvgRssi0 +
5951 pAd->StaCfg.RssiSample.AvgRssi1) >> 1;
5952 else
5953 Rssi = pAd->StaCfg.RssiSample.AvgRssi0;
5954
5955 if (pAd->LatchRfRegs.Channel <= 14) { /*BG band */
5956#ifdef RT30xx
5957 /* RT3070 is a no LNA solution, it should have different control regarding to AGC gain control */
5958 /* Otherwise, it will have some throughput side effect when low RSSI */
5959
5960 if (IS_RT3070(pAd) || IS_RT3090(pAd) || IS_RT3572(pAd)
5961 || IS_RT3390(pAd)) {
5962 if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) {
5963 R66 =
5964 0x1C + 2 * GET_LNA_GAIN(pAd) + 0x20;
5965 if (OrigR66Value != R66) {
5966 RTMP_BBP_IO_WRITE8_BY_REG_ID
5967 (pAd, BBP_R66, R66);
5968 }
5969 } else {
5970 R66 = 0x1C + 2 * GET_LNA_GAIN(pAd);
5971 if (OrigR66Value != R66) {
5972 RTMP_BBP_IO_WRITE8_BY_REG_ID
5973 (pAd, BBP_R66, R66);
5974 }
5975 }
5976 } else
5977#endif /* RT30xx // */
5978 {
5979 if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) {
5980 R66 = (0x2E + GET_LNA_GAIN(pAd)) + 0x10;
5981 if (OrigR66Value != R66) {
5982 RTMP_BBP_IO_WRITE8_BY_REG_ID
5983 (pAd, BBP_R66, R66);
5984 }
5985 } else {
5986 R66 = 0x2E + GET_LNA_GAIN(pAd);
5987 if (OrigR66Value != R66) {
5988 RTMP_BBP_IO_WRITE8_BY_REG_ID
5989 (pAd, BBP_R66, R66);
5990 }
5991 }
5992 }
5993 } else { /*A band */
5994 if (pAd->CommonCfg.BBPCurrentBW == BW_20) {
5995 if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) {
5996 R66 =
5997 0x32 + (GET_LNA_GAIN(pAd) * 5) / 3 +
5998 0x10;
5999 if (OrigR66Value != R66) {
6000 RTMP_BBP_IO_WRITE8_BY_REG_ID
6001 (pAd, BBP_R66, R66);
6002 }
6003 } else {
6004 R66 =
6005 0x32 + (GET_LNA_GAIN(pAd) * 5) / 3;
6006 if (OrigR66Value != R66) {
6007 RTMP_BBP_IO_WRITE8_BY_REG_ID
6008 (pAd, BBP_R66, R66);
6009 }
6010 }
6011 } else {
6012 if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) {
6013 R66 =
6014 0x3A + (GET_LNA_GAIN(pAd) * 5) / 3 +
6015 0x10;
6016 if (OrigR66Value != R66) {
6017 RTMP_BBP_IO_WRITE8_BY_REG_ID
6018 (pAd, BBP_R66, R66);
6019 }
6020 } else {
6021 R66 =
6022 0x3A + (GET_LNA_GAIN(pAd) * 5) / 3;
6023 if (OrigR66Value != R66) {
6024 RTMP_BBP_IO_WRITE8_BY_REG_ID
6025 (pAd, BBP_R66, R66);
6026 }
6027 }
6028 }
6029 }
6030
6031 }
6032}
6033
6034void RTMPSetAGCInitValue(struct rt_rtmp_adapter *pAd, u8 BandWidth)
6035{
6036 u8 R66 = 0x30;
6037
6038 if (pAd->LatchRfRegs.Channel <= 14) { /* BG band */
6039#ifdef RT30xx
6040 /* Gary was verified Amazon AP and find that RT307x has BBP_R66 invalid default value */
6041
6042 if (IS_RT3070(pAd) || IS_RT3090(pAd) || IS_RT3572(pAd)
6043 || IS_RT3390(pAd)) {
6044 R66 = 0x1C + 2 * GET_LNA_GAIN(pAd);
6045 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
6046 } else
6047#endif /* RT30xx // */
6048 {
6049 R66 = 0x2E + GET_LNA_GAIN(pAd);
6050 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
6051 }
6052 } else { /*A band */
6053 {
6054 if (BandWidth == BW_20) {
6055 R66 =
6056 (u8)(0x32 +
6057 (GET_LNA_GAIN(pAd) * 5) / 3);
6058 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
6059 } else {
6060 R66 =
6061 (u8)(0x3A +
6062 (GET_LNA_GAIN(pAd) * 5) / 3);
6063 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66);
6064 }
6065 }
6066 }
6067
6068}
diff --git a/drivers/staging/rt2860/common/rt_channel.c b/drivers/staging/rt2860/common/rt_channel.c
deleted file mode 100644
index 53879898117..00000000000
--- a/drivers/staging/rt2860/common/rt_channel.c
+++ /dev/null
@@ -1,1705 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27#include "../rt_config.h"
28
29struct rt_ch_freq_map CH_HZ_ID_MAP[] = {
30 {1, 2412}
31 ,
32 {2, 2417}
33 ,
34 {3, 2422}
35 ,
36 {4, 2427}
37 ,
38 {5, 2432}
39 ,
40 {6, 2437}
41 ,
42 {7, 2442}
43 ,
44 {8, 2447}
45 ,
46 {9, 2452}
47 ,
48 {10, 2457}
49 ,
50 {11, 2462}
51 ,
52 {12, 2467}
53 ,
54 {13, 2472}
55 ,
56 {14, 2484}
57 ,
58
59 /* UNII */
60 {36, 5180}
61 ,
62 {40, 5200}
63 ,
64 {44, 5220}
65 ,
66 {48, 5240}
67 ,
68 {52, 5260}
69 ,
70 {56, 5280}
71 ,
72 {60, 5300}
73 ,
74 {64, 5320}
75 ,
76 {149, 5745}
77 ,
78 {153, 5765}
79 ,
80 {157, 5785}
81 ,
82 {161, 5805}
83 ,
84 {165, 5825}
85 ,
86 {167, 5835}
87 ,
88 {169, 5845}
89 ,
90 {171, 5855}
91 ,
92 {173, 5865}
93 ,
94
95 /* HiperLAN2 */
96 {100, 5500}
97 ,
98 {104, 5520}
99 ,
100 {108, 5540}
101 ,
102 {112, 5560}
103 ,
104 {116, 5580}
105 ,
106 {120, 5600}
107 ,
108 {124, 5620}
109 ,
110 {128, 5640}
111 ,
112 {132, 5660}
113 ,
114 {136, 5680}
115 ,
116 {140, 5700}
117 ,
118
119 /* Japan MMAC */
120 {34, 5170}
121 ,
122 {38, 5190}
123 ,
124 {42, 5210}
125 ,
126 {46, 5230}
127 ,
128
129 /* Japan */
130 {184, 4920}
131 ,
132 {188, 4940}
133 ,
134 {192, 4960}
135 ,
136 {196, 4980}
137 ,
138
139 {208, 5040}
140 , /* Japan, means J08 */
141 {212, 5060}
142 , /* Japan, means J12 */
143 {216, 5080}
144 , /* Japan, means J16 */
145};
146
147int CH_HZ_ID_MAP_NUM = (sizeof(CH_HZ_ID_MAP) / sizeof(struct rt_ch_freq_map));
148
149struct rt_ch_region ChRegion[] = {
150 { /* Antigua and Berbuda */
151 "AG",
152 CE,
153 {
154 {1, 13, 20, BOTH, FALSE}
155 , /* 2.4 G, ch 1~13 */
156 {36, 4, 23, BOTH, FALSE}
157 , /* 5G, ch 36~48 */
158 {52, 4, 23, BOTH, FALSE}
159 , /* 5G, ch 52~64 */
160 {100, 11, 30, BOTH, FALSE}
161 , /* 5G, ch 100~140 */
162 {0}
163 , /* end */
164 }
165 }
166 ,
167
168 { /* Argentina */
169 "AR",
170 CE,
171 {
172 {1, 13, 20, BOTH, FALSE}
173 , /* 2.4 G, ch 1~13 */
174 {52, 4, 24, BOTH, FALSE}
175 , /* 5G, ch 52~64 */
176 {149, 4, 30, BOTH, FALSE}
177 , /* 5G, ch 149~161 */
178 {0}
179 , /* end */
180 }
181 }
182 ,
183
184 { /* Aruba */
185 "AW",
186 CE,
187 {
188 {1, 13, 20, BOTH, FALSE}
189 , /* 2.4 G, ch 1~13 */
190 {36, 4, 23, BOTH, FALSE}
191 , /* 5G, ch 36~48 */
192 {52, 4, 23, BOTH, FALSE}
193 , /* 5G, ch 52~64 */
194 {100, 11, 30, BOTH, FALSE}
195 , /* 5G, ch 100~140 */
196 {0}
197 , /* end */
198 }
199 }
200 ,
201
202 { /* Australia */
203 "AU",
204 CE,
205 {
206 {1, 13, 20, BOTH, FALSE}
207 , /* 2.4 G, ch 1~13 */
208 {36, 4, 23, BOTH, FALSE}
209 , /* 5G, ch 36~48 */
210 {52, 4, 24, BOTH, FALSE}
211 , /* 5G, ch 52~64 */
212 {149, 5, 30, BOTH, FALSE}
213 , /* 5G, ch 149~165 */
214 {0}
215 , /* end */
216 }
217 }
218 ,
219
220 { /* Austria */
221 "AT",
222 CE,
223 {
224 {1, 13, 20, BOTH, FALSE}
225 , /* 2.4 G, ch 1~13 */
226 {36, 4, 23, IDOR, TRUE}
227 , /* 5G, ch 36~48 */
228 {52, 4, 23, IDOR, TRUE}
229 , /* 5G, ch 52~64 */
230 {100, 11, 30, BOTH, TRUE}
231 , /* 5G, ch 100~140 */
232 {0}
233 , /* end */
234 }
235 }
236 ,
237
238 { /* Bahamas */
239 "BS",
240 CE,
241 {
242 {1, 13, 20, BOTH, FALSE}
243 , /* 2.4 G, ch 1~13 */
244 {36, 4, 23, BOTH, FALSE}
245 , /* 5G, ch 36~48 */
246 {52, 4, 24, BOTH, FALSE}
247 , /* 5G, ch 52~64 */
248 {149, 5, 30, BOTH, FALSE}
249 , /* 5G, ch 149~165 */
250 {0}
251 , /* end */
252 }
253 }
254 ,
255
256 { /* Barbados */
257 "BB",
258 CE,
259 {
260 {1, 13, 20, BOTH, FALSE}
261 , /* 2.4 G, ch 1~13 */
262 {36, 4, 23, BOTH, FALSE}
263 , /* 5G, ch 36~48 */
264 {52, 4, 24, BOTH, FALSE}
265 , /* 5G, ch 52~64 */
266 {100, 11, 30, BOTH, FALSE}
267 , /* 5G, ch 100~140 */
268 {0}
269 , /* end */
270 }
271 }
272 ,
273
274 { /* Bermuda */
275 "BM",
276 CE,
277 {
278 {1, 13, 20, BOTH, FALSE}
279 , /* 2.4 G, ch 1~13 */
280 {36, 4, 23, BOTH, FALSE}
281 , /* 5G, ch 36~48 */
282 {52, 4, 24, BOTH, FALSE}
283 , /* 5G, ch 52~64 */
284 {100, 11, 30, BOTH, FALSE}
285 , /* 5G, ch 100~140 */
286 {0}
287 , /* end */
288 }
289 }
290 ,
291
292 { /* Brazil */
293 "BR",
294 CE,
295 {
296 {1, 13, 20, BOTH, FALSE}
297 , /* 2.4 G, ch 1~13 */
298 {36, 4, 23, BOTH, FALSE}
299 , /* 5G, ch 36~48 */
300 {52, 4, 24, BOTH, FALSE}
301 , /* 5G, ch 52~64 */
302 {100, 11, 24, BOTH, FALSE}
303 , /* 5G, ch 100~140 */
304 {149, 5, 30, BOTH, FALSE}
305 , /* 5G, ch 100~140 */
306 {0}
307 , /* end */
308 }
309 }
310 ,
311
312 { /* Belgium */
313 "BE",
314 CE,
315 {
316 {1, 13, 20, BOTH, FALSE}
317 , /* 2.4 G, ch 1~13 */
318 {36, 4, 18, IDOR, FALSE}
319 , /* 5G, ch 36~48 */
320 {52, 4, 18, IDOR, FALSE}
321 , /* 5G, ch 52~64 */
322 {0}
323 , /* end */
324 }
325 }
326 ,
327
328 { /* Bulgaria */
329 "BG",
330 CE,
331 {
332 {1, 13, 20, BOTH, FALSE}
333 , /* 2.4 G, ch 1~13 */
334 {36, 4, 23, IDOR, FALSE}
335 , /* 5G, ch 36~48 */
336 {52, 4, 23, IDOR, TRUE}
337 , /* 5G, ch 52~64 */
338 {100, 11, 30, ODOR, TRUE}
339 , /* 5G, ch 100~140 */
340 {0}
341 , /* end */
342 }
343 }
344 ,
345
346 { /* Canada */
347 "CA",
348 CE,
349 {
350 {1, 13, 20, BOTH, FALSE}
351 , /* 2.4 G, ch 1~13 */
352 {36, 4, 23, BOTH, FALSE}
353 , /* 5G, ch 36~48 */
354 {52, 4, 23, BOTH, FALSE}
355 , /* 5G, ch 52~64 */
356 {149, 5, 30, BOTH, FALSE}
357 , /* 5G, ch 149~165 */
358 {0}
359 , /* end */
360 }
361 }
362 ,
363
364 { /* Cayman IsLands */
365 "KY",
366 CE,
367 {
368 {1, 13, 20, BOTH, FALSE}
369 , /* 2.4 G, ch 1~13 */
370 {36, 4, 23, BOTH, FALSE}
371 , /* 5G, ch 36~48 */
372 {52, 4, 24, BOTH, FALSE}
373 , /* 5G, ch 52~64 */
374 {100, 11, 30, BOTH, FALSE}
375 , /* 5G, ch 100~140 */
376 {0}
377 , /* end */
378 }
379 }
380 ,
381
382 { /* Chile */
383 "CL",
384 CE,
385 {
386 {1, 13, 20, BOTH, FALSE}
387 , /* 2.4 G, ch 1~13 */
388 {36, 4, 20, BOTH, FALSE}
389 , /* 5G, ch 36~48 */
390 {52, 4, 20, BOTH, FALSE}
391 , /* 5G, ch 52~64 */
392 {149, 5, 20, BOTH, FALSE}
393 , /* 5G, ch 149~165 */
394 {0}
395 , /* end */
396 }
397 }
398 ,
399
400 { /* China */
401 "CN",
402 CE,
403 {
404 {1, 13, 20, BOTH, FALSE}
405 , /* 2.4 G, ch 1~13 */
406 {149, 4, 27, BOTH, FALSE}
407 , /* 5G, ch 149~161 */
408 {0}
409 , /* end */
410 }
411 }
412 ,
413
414 { /* Colombia */
415 "CO",
416 CE,
417 {
418 {1, 13, 20, BOTH, FALSE}
419 , /* 2.4 G, ch 1~13 */
420 {36, 4, 17, BOTH, FALSE}
421 , /* 5G, ch 36~48 */
422 {52, 4, 24, BOTH, FALSE}
423 , /* 5G, ch 52~64 */
424 {100, 11, 30, BOTH, FALSE}
425 , /* 5G, ch 100~140 */
426 {149, 5, 30, BOTH, FALSE}
427 , /* 5G, ch 149~165 */
428 {0}
429 , /* end */
430 }
431 }
432 ,
433
434 { /* Costa Rica */
435 "CR",
436 CE,
437 {
438 {1, 13, 20, BOTH, FALSE}
439 , /* 2.4 G, ch 1~13 */
440 {36, 4, 17, BOTH, FALSE}
441 , /* 5G, ch 36~48 */
442 {52, 4, 24, BOTH, FALSE}
443 , /* 5G, ch 52~64 */
444 {149, 4, 30, BOTH, FALSE}
445 , /* 5G, ch 149~161 */
446 {0}
447 , /* end */
448 }
449 }
450 ,
451
452 { /* Cyprus */
453 "CY",
454 CE,
455 {
456 {1, 13, 20, BOTH, FALSE}
457 , /* 2.4 G, ch 1~13 */
458 {36, 4, 23, IDOR, FALSE}
459 , /* 5G, ch 36~48 */
460 {52, 4, 24, IDOR, TRUE}
461 , /* 5G, ch 52~64 */
462 {100, 11, 30, BOTH, TRUE}
463 , /* 5G, ch 100~140 */
464 {0}
465 , /* end */
466 }
467 }
468 ,
469
470 { /* Czech_Republic */
471 "CZ",
472 CE,
473 {
474 {1, 13, 20, BOTH, FALSE}
475 , /* 2.4 G, ch 1~13 */
476 {36, 4, 23, IDOR, FALSE}
477 , /* 5G, ch 36~48 */
478 {52, 4, 23, IDOR, TRUE}
479 , /* 5G, ch 52~64 */
480 {0}
481 , /* end */
482 }
483 }
484 ,
485
486 { /* Denmark */
487 "DK",
488 CE,
489 {
490 {1, 13, 20, BOTH, FALSE}
491 , /* 2.4 G, ch 1~13 */
492 {36, 4, 23, IDOR, FALSE}
493 , /* 5G, ch 36~48 */
494 {52, 4, 23, IDOR, TRUE}
495 , /* 5G, ch 52~64 */
496 {100, 11, 30, BOTH, TRUE}
497 , /* 5G, ch 100~140 */
498 {0}
499 , /* end */
500 }
501 }
502 ,
503
504 { /* Dominican Republic */
505 "DO",
506 CE,
507 {
508 {1, 0, 20, BOTH, FALSE}
509 , /* 2.4 G, ch 0 */
510 {149, 4, 20, BOTH, FALSE}
511 , /* 5G, ch 149~161 */
512 {0}
513 , /* end */
514 }
515 }
516 ,
517
518 { /* Equador */
519 "EC",
520 CE,
521 {
522 {1, 13, 20, BOTH, FALSE}
523 , /* 2.4 G, ch 1~13 */
524 {100, 11, 27, BOTH, FALSE}
525 , /* 5G, ch 100~140 */
526 {0}
527 , /* end */
528 }
529 }
530 ,
531
532 { /* El Salvador */
533 "SV",
534 CE,
535 {
536 {1, 13, 20, BOTH, FALSE}
537 , /* 2.4 G, ch 1~13 */
538 {36, 4, 23, IDOR, FALSE}
539 , /* 5G, ch 36~48 */
540 {52, 4, 30, BOTH, TRUE}
541 , /* 5G, ch 52~64 */
542 {149, 4, 36, BOTH, TRUE}
543 , /* 5G, ch 149~165 */
544 {0}
545 , /* end */
546 }
547 }
548 ,
549
550 { /* Finland */
551 "FI",
552 CE,
553 {
554 {1, 13, 20, BOTH, FALSE}
555 , /* 2.4 G, ch 1~13 */
556 {36, 4, 23, IDOR, FALSE}
557 , /* 5G, ch 36~48 */
558 {52, 4, 23, IDOR, TRUE}
559 , /* 5G, ch 52~64 */
560 {100, 11, 30, BOTH, TRUE}
561 , /* 5G, ch 100~140 */
562 {0}
563 , /* end */
564 }
565 }
566 ,
567
568 { /* France */
569 "FR",
570 CE,
571 {
572 {1, 13, 20, BOTH, FALSE}
573 , /* 2.4 G, ch 1~13 */
574 {36, 4, 23, IDOR, FALSE}
575 , /* 5G, ch 36~48 */
576 {52, 4, 23, IDOR, TRUE}
577 , /* 5G, ch 52~64 */
578 {0}
579 , /* end */
580 }
581 }
582 ,
583
584 { /* Germany */
585 "DE",
586 CE,
587 {
588 {1, 13, 20, BOTH, FALSE}
589 , /* 2.4 G, ch 1~13 */
590 {36, 4, 23, IDOR, FALSE}
591 , /* 5G, ch 36~48 */
592 {52, 4, 23, IDOR, TRUE}
593 , /* 5G, ch 52~64 */
594 {100, 11, 30, BOTH, TRUE}
595 , /* 5G, ch 100~140 */
596 {0}
597 , /* end */
598 }
599 }
600 ,
601
602 { /* Greece */
603 "GR",
604 CE,
605 {
606 {1, 13, 20, BOTH, FALSE}
607 , /* 2.4 G, ch 1~13 */
608 {36, 4, 23, IDOR, FALSE}
609 , /* 5G, ch 36~48 */
610 {52, 4, 23, IDOR, TRUE}
611 , /* 5G, ch 52~64 */
612 {100, 11, 30, ODOR, TRUE}
613 , /* 5G, ch 100~140 */
614 {0}
615 , /* end */
616 }
617 }
618 ,
619
620 { /* Guam */
621 "GU",
622 CE,
623 {
624 {1, 11, 20, BOTH, FALSE}
625 , /* 2.4 G, ch 1~11 */
626 {36, 4, 17, BOTH, FALSE}
627 , /* 5G, ch 36~48 */
628 {52, 4, 24, BOTH, FALSE}
629 , /* 5G, ch 52~64 */
630 {100, 11, 30, BOTH, FALSE}
631 , /* 5G, ch 100~140 */
632 {149, 5, 30, BOTH, FALSE}
633 , /* 5G, ch 149~165 */
634 {0}
635 , /* end */
636 }
637 }
638 ,
639
640 { /* Guatemala */
641 "GT",
642 CE,
643 {
644 {1, 13, 20, BOTH, FALSE}
645 , /* 2.4 G, ch 1~13 */
646 {36, 4, 17, BOTH, FALSE}
647 , /* 5G, ch 36~48 */
648 {52, 4, 24, BOTH, FALSE}
649 , /* 5G, ch 52~64 */
650 {149, 4, 30, BOTH, FALSE}
651 , /* 5G, ch 149~161 */
652 {0}
653 , /* end */
654 }
655 }
656 ,
657
658 { /* Haiti */
659 "HT",
660 CE,
661 {
662 {1, 13, 20, BOTH, FALSE}
663 , /* 2.4 G, ch 1~13 */
664 {36, 4, 17, BOTH, FALSE}
665 , /* 5G, ch 36~48 */
666 {52, 4, 24, BOTH, FALSE}
667 , /* 5G, ch 52~64 */
668 {149, 4, 30, BOTH, FALSE}
669 , /* 5G, ch 149~161 */
670 {0}
671 , /* end */
672 }
673 }
674 ,
675
676 { /* Honduras */
677 "HN",
678 CE,
679 {
680 {1, 13, 20, BOTH, FALSE}
681 , /* 2.4 G, ch 1~13 */
682 {149, 4, 27, BOTH, FALSE}
683 , /* 5G, ch 149~161 */
684 {0}
685 , /* end */
686 }
687 }
688 ,
689
690 { /* Hong Kong */
691 "HK",
692 CE,
693 {
694 {1, 13, 20, BOTH, FALSE}
695 , /* 2.4 G, ch 1~13 */
696 {36, 4, 23, IDOR, FALSE}
697 , /* 5G, ch 36~48 */
698 {52, 4, 23, IDOR, FALSE}
699 , /* 5G, ch 52~64 */
700 {149, 4, 30, BOTH, FALSE}
701 , /* 5G, ch 149~161 */
702 {0}
703 , /* end */
704 }
705 }
706 ,
707
708 { /* Hungary */
709 "HU",
710 CE,
711 {
712 {1, 13, 20, BOTH, FALSE}
713 , /* 2.4 G, ch 1~13 */
714 {36, 4, 23, IDOR, FALSE}
715 , /* 5G, ch 36~48 */
716 {52, 4, 23, IDOR, TRUE}
717 , /* 5G, ch 52~64 */
718 {0}
719 , /* end */
720 }
721 }
722 ,
723
724 { /* Iceland */
725 "IS",
726 CE,
727 {
728 {1, 13, 20, BOTH, FALSE}
729 , /* 2.4 G, ch 1~13 */
730 {36, 4, 23, IDOR, FALSE}
731 , /* 5G, ch 36~48 */
732 {52, 4, 23, IDOR, TRUE}
733 , /* 5G, ch 52~64 */
734 {100, 11, 30, BOTH, TRUE}
735 , /* 5G, ch 100~140 */
736 {0}
737 , /* end */
738 }
739 }
740 ,
741
742 { /* India */
743 "IN",
744 CE,
745 {
746 {1, 13, 20, BOTH, FALSE}
747 , /* 2.4 G, ch 1~13 */
748 {149, 4, 24, IDOR, FALSE}
749 , /* 5G, ch 149~161 */
750 {0}
751 , /* end */
752 }
753 }
754 ,
755
756 { /* Indonesia */
757 "ID",
758 CE,
759 {
760 {1, 13, 20, BOTH, FALSE}
761 , /* 2.4 G, ch 1~13 */
762 {149, 4, 27, BOTH, FALSE}
763 , /* 5G, ch 149~161 */
764 {0}
765 , /* end */
766 }
767 }
768 ,
769
770 { /* Ireland */
771 "IE",
772 CE,
773 {
774 {1, 13, 20, BOTH, FALSE}
775 , /* 2.4 G, ch 1~13 */
776 {36, 4, 23, IDOR, FALSE}
777 , /* 5G, ch 36~48 */
778 {52, 4, 23, IDOR, TRUE}
779 , /* 5G, ch 52~64 */
780 {100, 11, 30, ODOR, TRUE}
781 , /* 5G, ch 100~140 */
782 {0}
783 , /* end */
784 }
785 }
786 ,
787
788 { /* Israel */
789 "IL",
790 CE,
791 {
792 {1, 3, 20, IDOR, FALSE}
793 , /* 2.4 G, ch 1~3 */
794 {4, 6, 20, BOTH, FALSE}
795 , /* 2.4 G, ch 4~9 */
796 {10, 4, 20, IDOR, FALSE}
797 , /* 2.4 G, ch 10~13 */
798 {0}
799 , /* end */
800 }
801 }
802 ,
803
804 { /* Italy */
805 "IT",
806 CE,
807 {
808 {1, 13, 20, BOTH, FALSE}
809 , /* 2.4 G, ch 1~13 */
810 {36, 4, 23, IDOR, FALSE}
811 , /* 5G, ch 36~48 */
812 {52, 4, 23, IDOR, TRUE}
813 , /* 5G, ch 52~64 */
814 {100, 11, 30, ODOR, TRUE}
815 , /* 5G, ch 100~140 */
816 {0}
817 , /* end */
818 }
819 }
820 ,
821
822 { /* Japan */
823 "JP",
824 JAP,
825 {
826 {1, 14, 20, BOTH, FALSE}
827 , /* 2.4 G, ch 1~14 */
828 {36, 4, 23, IDOR, FALSE}
829 , /* 5G, ch 36~48 */
830 {0}
831 , /* end */
832 }
833 }
834 ,
835
836 { /* Jordan */
837 "JO",
838 CE,
839 {
840 {1, 13, 20, IDOR, FALSE}
841 , /* 2.4 G, ch 1~13 */
842 {36, 4, 23, IDOR, FALSE}
843 , /* 5G, ch 36~48 */
844 {149, 4, 23, IDOR, FALSE}
845 , /* 5G, ch 149~161 */
846 {0}
847 , /* end */
848 }
849 }
850 ,
851
852 { /* Latvia */
853 "LV",
854 CE,
855 {
856 {1, 13, 20, BOTH, FALSE}
857 , /* 2.4 G, ch 1~13 */
858 {36, 4, 23, IDOR, FALSE}
859 , /* 5G, ch 36~48 */
860 {52, 4, 23, IDOR, TRUE}
861 , /* 5G, ch 52~64 */
862 {100, 11, 30, BOTH, TRUE}
863 , /* 5G, ch 100~140 */
864 {0}
865 , /* end */
866 }
867 }
868 ,
869
870 { /* Liechtenstein */
871 "LI",
872 CE,
873 {
874 {1, 13, 20, BOTH, FALSE}
875 , /* 2.4 G, ch 1~13 */
876 {52, 4, 23, IDOR, TRUE}
877 , /* 5G, ch 52~64 */
878 {100, 11, 30, BOTH, TRUE}
879 , /* 5G, ch 100~140 */
880 {0}
881 , /* end */
882 }
883 }
884 ,
885
886 { /* Lithuania */
887 "LT",
888 CE,
889 {
890 {1, 13, 20, BOTH, FALSE}
891 , /* 2.4 G, ch 1~13 */
892 {36, 4, 23, IDOR, FALSE}
893 , /* 5G, ch 36~48 */
894 {52, 4, 23, IDOR, TRUE}
895 , /* 5G, ch 52~64 */
896 {100, 11, 30, BOTH, TRUE}
897 , /* 5G, ch 100~140 */
898 {0}
899 , /* end */
900 }
901 }
902 ,
903
904 { /* Luxemburg */
905 "LU",
906 CE,
907 {
908 {1, 13, 20, BOTH, FALSE}
909 , /* 2.4 G, ch 1~13 */
910 {36, 4, 23, IDOR, FALSE}
911 , /* 5G, ch 36~48 */
912 {52, 4, 23, IDOR, TRUE}
913 , /* 5G, ch 52~64 */
914 {100, 11, 30, BOTH, TRUE}
915 , /* 5G, ch 100~140 */
916 {0}
917 , /* end */
918 }
919 }
920 ,
921
922 { /* Malaysia */
923 "MY",
924 CE,
925 {
926 {36, 4, 23, BOTH, FALSE}
927 , /* 5G, ch 36~48 */
928 {52, 4, 23, BOTH, FALSE}
929 , /* 5G, ch 52~64 */
930 {149, 5, 20, BOTH, FALSE}
931 , /* 5G, ch 149~165 */
932 {0}
933 , /* end */
934 }
935 }
936 ,
937
938 { /* Malta */
939 "MT",
940 CE,
941 {
942 {1, 13, 20, BOTH, FALSE}
943 , /* 2.4 G, ch 1~13 */
944 {36, 4, 23, IDOR, FALSE}
945 , /* 5G, ch 36~48 */
946 {52, 4, 23, IDOR, TRUE}
947 , /* 5G, ch 52~64 */
948 {100, 11, 30, BOTH, TRUE}
949 , /* 5G, ch 100~140 */
950 {0}
951 , /* end */
952 }
953 }
954 ,
955
956 { /* Marocco */
957 "MA",
958 CE,
959 {
960 {1, 13, 20, BOTH, FALSE}
961 , /* 2.4 G, ch 1~13 */
962 {36, 4, 24, IDOR, FALSE}
963 , /* 5G, ch 36~48 */
964 {0}
965 , /* end */
966 }
967 }
968 ,
969
970 { /* Mexico */
971 "MX",
972 CE,
973 {
974 {1, 13, 20, BOTH, FALSE}
975 , /* 2.4 G, ch 1~13 */
976 {36, 4, 23, BOTH, FALSE}
977 , /* 5G, ch 36~48 */
978 {52, 4, 24, BOTH, FALSE}
979 , /* 5G, ch 52~64 */
980 {149, 5, 30, IDOR, FALSE}
981 , /* 5G, ch 149~165 */
982 {0}
983 , /* end */
984 }
985 }
986 ,
987
988 { /* Netherlands */
989 "NL",
990 CE,
991 {
992 {1, 13, 20, BOTH, FALSE}
993 , /* 2.4 G, ch 1~13 */
994 {36, 4, 23, IDOR, FALSE}
995 , /* 5G, ch 36~48 */
996 {52, 4, 24, IDOR, TRUE}
997 , /* 5G, ch 52~64 */
998 {100, 11, 30, BOTH, TRUE}
999 , /* 5G, ch 100~140 */
1000 {0}
1001 , /* end */
1002 }
1003 }
1004 ,
1005
1006 { /* New Zealand */
1007 "NZ",
1008 CE,
1009 {
1010 {1, 13, 20, BOTH, FALSE}
1011 , /* 2.4 G, ch 1~13 */
1012 {36, 4, 24, BOTH, FALSE}
1013 , /* 5G, ch 36~48 */
1014 {52, 4, 24, BOTH, FALSE}
1015 , /* 5G, ch 52~64 */
1016 {149, 4, 30, BOTH, FALSE}
1017 , /* 5G, ch 149~161 */
1018 {0}
1019 , /* end */
1020 }
1021 }
1022 ,
1023
1024 { /* Norway */
1025 "NO",
1026 CE,
1027 {
1028 {1, 13, 20, BOTH, FALSE}
1029 , /* 2.4 G, ch 1~13 */
1030 {36, 4, 24, IDOR, FALSE}
1031 , /* 5G, ch 36~48 */
1032 {52, 4, 24, IDOR, TRUE}
1033 , /* 5G, ch 52~64 */
1034 {100, 11, 30, BOTH, TRUE}
1035 , /* 5G, ch 149~161 */
1036 {0}
1037 , /* end */
1038 }
1039 }
1040 ,
1041
1042 { /* Peru */
1043 "PE",
1044 CE,
1045 {
1046 {1, 13, 20, BOTH, FALSE}
1047 , /* 2.4 G, ch 1~13 */
1048 {149, 4, 27, BOTH, FALSE}
1049 , /* 5G, ch 149~161 */
1050 {0}
1051 , /* end */
1052 }
1053 }
1054 ,
1055
1056 { /* Portugal */
1057 "PT",
1058 CE,
1059 {
1060 {1, 13, 20, BOTH, FALSE}
1061 , /* 2.4 G, ch 1~13 */
1062 {36, 4, 23, IDOR, FALSE}
1063 , /* 5G, ch 36~48 */
1064 {52, 4, 23, IDOR, TRUE}
1065 , /* 5G, ch 52~64 */
1066 {100, 11, 30, BOTH, TRUE}
1067 , /* 5G, ch 100~140 */
1068 {0}
1069 , /* end */
1070 }
1071 }
1072 ,
1073
1074 { /* Poland */
1075 "PL",
1076 CE,
1077 {
1078 {1, 13, 20, BOTH, FALSE}
1079 , /* 2.4 G, ch 1~13 */
1080 {36, 4, 23, IDOR, FALSE}
1081 , /* 5G, ch 36~48 */
1082 {52, 4, 23, IDOR, TRUE}
1083 , /* 5G, ch 52~64 */
1084 {100, 11, 30, BOTH, TRUE}
1085 , /* 5G, ch 100~140 */
1086 {0}
1087 , /* end */
1088 }
1089 }
1090 ,
1091
1092 { /* Romania */
1093 "RO",
1094 CE,
1095 {
1096 {1, 13, 20, BOTH, FALSE}
1097 , /* 2.4 G, ch 1~13 */
1098 {36, 4, 23, IDOR, FALSE}
1099 , /* 5G, ch 36~48 */
1100 {52, 4, 23, IDOR, TRUE}
1101 , /* 5G, ch 52~64 */
1102 {100, 11, 30, BOTH, TRUE}
1103 , /* 5G, ch 100~140 */
1104 {0}
1105 , /* end */
1106 }
1107 }
1108 ,
1109
1110 { /* Russia */
1111 "RU",
1112 CE,
1113 {
1114 {1, 13, 20, BOTH, FALSE}
1115 , /* 2.4 G, ch 1~13 */
1116 {149, 4, 20, IDOR, FALSE}
1117 , /* 5G, ch 149~161 */
1118 {0}
1119 , /* end */
1120 }
1121 }
1122 ,
1123
1124 { /* Saudi Arabia */
1125 "SA",
1126 CE,
1127 {
1128 {1, 13, 20, BOTH, FALSE}
1129 , /* 2.4 G, ch 1~13 */
1130 {36, 4, 23, BOTH, FALSE}
1131 , /* 5G, ch 36~48 */
1132 {52, 4, 23, BOTH, FALSE}
1133 , /* 5G, ch 52~64 */
1134 {149, 4, 23, BOTH, FALSE}
1135 , /* 5G, ch 149~161 */
1136 {0}
1137 , /* end */
1138 }
1139 }
1140 ,
1141
1142 { /* Serbia_and_Montenegro */
1143 "CS",
1144 CE,
1145 {
1146 {1, 13, 20, BOTH, FALSE}
1147 , /* 2.4 G, ch 1~13 */
1148 {0}
1149 , /* end */
1150 }
1151 }
1152 ,
1153
1154 { /* Singapore */
1155 "SG",
1156 CE,
1157 {
1158 {1, 13, 20, BOTH, FALSE}
1159 , /* 2.4 G, ch 1~13 */
1160 {36, 4, 23, BOTH, FALSE}
1161 , /* 5G, ch 36~48 */
1162 {52, 4, 23, BOTH, FALSE}
1163 , /* 5G, ch 52~64 */
1164 {149, 4, 20, BOTH, FALSE}
1165 , /* 5G, ch 149~161 */
1166 {0}
1167 , /* end */
1168 }
1169 }
1170 ,
1171
1172 { /* Slovakia */
1173 "SK",
1174 CE,
1175 {
1176 {1, 13, 20, BOTH, FALSE}
1177 , /* 2.4 G, ch 1~13 */
1178 {36, 4, 23, IDOR, FALSE}
1179 , /* 5G, ch 36~48 */
1180 {52, 4, 23, IDOR, TRUE}
1181 , /* 5G, ch 52~64 */
1182 {100, 11, 30, BOTH, TRUE}
1183 , /* 5G, ch 100~140 */
1184 {0}
1185 , /* end */
1186 }
1187 }
1188 ,
1189
1190 { /* Slovenia */
1191 "SI",
1192 CE,
1193 {
1194 {1, 13, 20, BOTH, FALSE}
1195 , /* 2.4 G, ch 1~13 */
1196 {36, 4, 23, IDOR, FALSE}
1197 , /* 5G, ch 36~48 */
1198 {52, 4, 23, IDOR, TRUE}
1199 , /* 5G, ch 52~64 */
1200 {0}
1201 , /* end */
1202 }
1203 }
1204 ,
1205
1206 { /* South Africa */
1207 "ZA",
1208 CE,
1209 {
1210 {1, 13, 20, BOTH, FALSE}
1211 , /* 2.4 G, ch 1~13 */
1212 {36, 4, 23, BOTH, FALSE}
1213 , /* 5G, ch 36~48 */
1214 {52, 4, 23, IDOR, FALSE}
1215 , /* 5G, ch 52~64 */
1216 {100, 11, 30, BOTH, TRUE}
1217 , /* 5G, ch 100~140 */
1218 {149, 4, 30, BOTH, FALSE}
1219 , /* 5G, ch 149~161 */
1220 {0}
1221 , /* end */
1222 }
1223 }
1224 ,
1225
1226 { /* South Korea */
1227 "KR",
1228 CE,
1229 {
1230 {1, 13, 20, BOTH, FALSE}
1231 , /* 2.4 G, ch 1~13 */
1232 {36, 4, 20, BOTH, FALSE}
1233 , /* 5G, ch 36~48 */
1234 {52, 4, 20, BOTH, FALSE}
1235 , /* 5G, ch 52~64 */
1236 {100, 8, 20, BOTH, FALSE}
1237 , /* 5G, ch 100~128 */
1238 {149, 4, 20, BOTH, FALSE}
1239 , /* 5G, ch 149~161 */
1240 {0}
1241 , /* end */
1242 }
1243 }
1244 ,
1245
1246 { /* Spain */
1247 "ES",
1248 CE,
1249 {
1250 {1, 13, 20, BOTH, FALSE}
1251 , /* 2.4 G, ch 1~13 */
1252 {36, 4, 17, IDOR, FALSE}
1253 , /* 5G, ch 36~48 */
1254 {52, 4, 23, IDOR, TRUE}
1255 , /* 5G, ch 52~64 */
1256 {100, 11, 30, BOTH, TRUE}
1257 , /* 5G, ch 100~140 */
1258 {0}
1259 , /* end */
1260 }
1261 }
1262 ,
1263
1264 { /* Sweden */
1265 "SE",
1266 CE,
1267 {
1268 {1, 13, 20, BOTH, FALSE}
1269 , /* 2.4 G, ch 1~13 */
1270 {36, 4, 23, IDOR, FALSE}
1271 , /* 5G, ch 36~48 */
1272 {52, 4, 23, IDOR, TRUE}
1273 , /* 5G, ch 52~64 */
1274 {100, 11, 30, BOTH, TRUE}
1275 , /* 5G, ch 100~140 */
1276 {0}
1277 , /* end */
1278 }
1279 }
1280 ,
1281
1282 { /* Switzerland */
1283 "CH",
1284 CE,
1285 {
1286 {1, 13, 20, BOTH, FALSE}
1287 , /* 2.4 G, ch 1~13 */
1288 {36, 4, 23, IDOR, TRUE}
1289 , /* 5G, ch 36~48 */
1290 {52, 4, 23, IDOR, TRUE}
1291 , /* 5G, ch 52~64 */
1292 {0}
1293 , /* end */
1294 }
1295 }
1296 ,
1297
1298 { /* Taiwan */
1299 "TW",
1300 CE,
1301 {
1302 {1, 11, 30, BOTH, FALSE}
1303 , /* 2.4 G, ch 1~11 */
1304 {52, 4, 23, IDOR, FALSE}
1305 , /* 5G, ch 52~64 */
1306 {0}
1307 , /* end */
1308 }
1309 }
1310 ,
1311
1312 { /* Turkey */
1313 "TR",
1314 CE,
1315 {
1316 {1, 13, 20, BOTH, FALSE}
1317 , /* 2.4 G, ch 1~11 */
1318 {36, 4, 23, BOTH, FALSE}
1319 , /* 5G, ch 36~48 */
1320 {52, 4, 23, BOTH, FALSE}
1321 , /* 5G, ch 52~64 */
1322 {0}
1323 , /* end */
1324 }
1325 }
1326 ,
1327
1328 { /* UK */
1329 "GB",
1330 CE,
1331 {
1332 {1, 13, 20, BOTH, FALSE}
1333 , /* 2.4 G, ch 1~11 */
1334 {36, 4, 23, IDOR, FALSE}
1335 , /* 5G, ch 52~64 */
1336 {52, 4, 23, IDOR, TRUE}
1337 , /* 5G, ch 52~64 */
1338 {100, 11, 30, BOTH, TRUE}
1339 , /* 5G, ch 100~140 */
1340 {0}
1341 , /* end */
1342 }
1343 }
1344 ,
1345
1346 { /* Ukraine */
1347 "UA",
1348 CE,
1349 {
1350 {1, 13, 20, BOTH, FALSE}
1351 , /* 2.4 G, ch 1~11 */
1352 {0}
1353 , /* end */
1354 }
1355 }
1356 ,
1357
1358 { /* United_Arab_Emirates */
1359 "AE",
1360 CE,
1361 {
1362 {1, 13, 20, BOTH, FALSE}
1363 , /* 2.4 G, ch 1~11 */
1364 {0}
1365 , /* end */
1366 }
1367 }
1368 ,
1369
1370 { /* United_States */
1371 "US",
1372 CE,
1373 {
1374 {1, 11, 30, BOTH, FALSE}
1375 , /* 2.4 G, ch 1~11 */
1376 {36, 4, 17, IDOR, FALSE}
1377 , /* 5G, ch 52~64 */
1378 {52, 4, 24, BOTH, TRUE}
1379 , /* 5G, ch 52~64 */
1380 {100, 11, 30, BOTH, TRUE}
1381 , /* 5G, ch 100~140 */
1382 {149, 5, 30, BOTH, FALSE}
1383 , /* 5G, ch 149~165 */
1384 {0}
1385 , /* end */
1386 }
1387 }
1388 ,
1389
1390 { /* Venezuela */
1391 "VE",
1392 CE,
1393 {
1394 {1, 13, 20, BOTH, FALSE}
1395 , /* 2.4 G, ch 1~11 */
1396 {149, 4, 27, BOTH, FALSE}
1397 , /* 5G, ch 149~161 */
1398 {0}
1399 , /* end */
1400 }
1401 }
1402 ,
1403
1404 { /* Default */
1405 "",
1406 CE,
1407 {
1408 {1, 11, 20, BOTH, FALSE}
1409 , /* 2.4 G, ch 1~11 */
1410 {36, 4, 20, BOTH, FALSE}
1411 , /* 5G, ch 52~64 */
1412 {52, 4, 20, BOTH, FALSE}
1413 , /* 5G, ch 52~64 */
1414 {100, 11, 20, BOTH, FALSE}
1415 , /* 5G, ch 100~140 */
1416 {149, 5, 20, BOTH, FALSE}
1417 , /* 5G, ch 149~165 */
1418 {0}
1419 , /* end */
1420 }
1421 }
1422 ,
1423};
1424
1425static struct rt_ch_region *GetChRegion(u8 *CntryCode)
1426{
1427 int loop = 0;
1428 struct rt_ch_region *pChRegion = NULL;
1429
1430 while (strcmp((char *)ChRegion[loop].CountReg, "") != 0) {
1431 if (strncmp
1432 ((char *)ChRegion[loop].CountReg, (char *)CntryCode,
1433 2) == 0) {
1434 pChRegion = &ChRegion[loop];
1435 break;
1436 }
1437 loop++;
1438 }
1439
1440 if (pChRegion == NULL)
1441 pChRegion = &ChRegion[loop];
1442 return pChRegion;
1443}
1444
1445static void ChBandCheck(u8 PhyMode, u8 *pChType)
1446{
1447 switch (PhyMode) {
1448 case PHY_11A:
1449 case PHY_11AN_MIXED:
1450 *pChType = BAND_5G;
1451 break;
1452 case PHY_11ABG_MIXED:
1453 case PHY_11AGN_MIXED:
1454 case PHY_11ABGN_MIXED:
1455 *pChType = BAND_BOTH;
1456 break;
1457
1458 default:
1459 *pChType = BAND_24G;
1460 break;
1461 }
1462}
1463
1464static u8 FillChList(struct rt_rtmp_adapter *pAd,
1465 struct rt_ch_desp *pChDesp,
1466 u8 Offset, u8 increment)
1467{
1468 int i, j, l;
1469 u8 channel;
1470
1471 j = Offset;
1472 for (i = 0; i < pChDesp->NumOfCh; i++) {
1473 channel = pChDesp->FirstChannel + i * increment;
1474 for (l = 0; l < MAX_NUM_OF_CHANNELS; l++) {
1475 if (channel == pAd->TxPower[l].Channel) {
1476 pAd->ChannelList[j].Power =
1477 pAd->TxPower[l].Power;
1478 pAd->ChannelList[j].Power2 =
1479 pAd->TxPower[l].Power2;
1480 break;
1481 }
1482 }
1483 if (l == MAX_NUM_OF_CHANNELS)
1484 continue;
1485
1486 pAd->ChannelList[j].Channel =
1487 pChDesp->FirstChannel + i * increment;
1488 pAd->ChannelList[j].MaxTxPwr = pChDesp->MaxTxPwr;
1489 pAd->ChannelList[j].DfsReq = pChDesp->DfsReq;
1490 j++;
1491 }
1492 pAd->ChannelListNum = j;
1493
1494 return j;
1495}
1496
1497static inline void CreateChList(struct rt_rtmp_adapter *pAd,
1498 struct rt_ch_region *pChRegion, u8 Geography)
1499{
1500 int i;
1501 u8 offset = 0;
1502 struct rt_ch_desp *pChDesp;
1503 u8 ChType;
1504 u8 increment;
1505
1506 if (pChRegion == NULL)
1507 return;
1508
1509 ChBandCheck(pAd->CommonCfg.PhyMode, &ChType);
1510
1511 for (i = 0; i < 10; i++) {
1512 pChDesp = &pChRegion->ChDesp[i];
1513 if (pChDesp->FirstChannel == 0)
1514 break;
1515
1516 if (ChType == BAND_5G) {
1517 if (pChDesp->FirstChannel <= 14)
1518 continue;
1519 } else if (ChType == BAND_24G) {
1520 if (pChDesp->FirstChannel > 14)
1521 continue;
1522 }
1523
1524 if ((pChDesp->Geography == BOTH)
1525 || (pChDesp->Geography == Geography)) {
1526 if (pChDesp->FirstChannel > 14)
1527 increment = 4;
1528 else
1529 increment = 1;
1530 offset = FillChList(pAd, pChDesp, offset, increment);
1531 }
1532 }
1533}
1534
1535void BuildChannelListEx(struct rt_rtmp_adapter *pAd)
1536{
1537 struct rt_ch_region *pChReg;
1538
1539 pChReg = GetChRegion(pAd->CommonCfg.CountryCode);
1540 CreateChList(pAd, pChReg, pAd->CommonCfg.Geography);
1541}
1542
1543void BuildBeaconChList(struct rt_rtmp_adapter *pAd,
1544 u8 *pBuf, unsigned long *pBufLen)
1545{
1546 int i;
1547 unsigned long TmpLen;
1548 struct rt_ch_region *pChRegion;
1549 struct rt_ch_desp *pChDesp;
1550 u8 ChType;
1551
1552 pChRegion = GetChRegion(pAd->CommonCfg.CountryCode);
1553
1554 if (pChRegion == NULL)
1555 return;
1556
1557 ChBandCheck(pAd->CommonCfg.PhyMode, &ChType);
1558 *pBufLen = 0;
1559
1560 for (i = 0; i < 10; i++) {
1561 pChDesp = &pChRegion->ChDesp[i];
1562 if (pChDesp->FirstChannel == 0)
1563 break;
1564
1565 if (ChType == BAND_5G) {
1566 if (pChDesp->FirstChannel <= 14)
1567 continue;
1568 } else if (ChType == BAND_24G) {
1569 if (pChDesp->FirstChannel > 14)
1570 continue;
1571 }
1572
1573 if ((pChDesp->Geography == BOTH)
1574 || (pChDesp->Geography == pAd->CommonCfg.Geography)) {
1575 MakeOutgoingFrame(pBuf + *pBufLen, &TmpLen,
1576 1, &pChDesp->FirstChannel,
1577 1, &pChDesp->NumOfCh,
1578 1, &pChDesp->MaxTxPwr, END_OF_ARGS);
1579 *pBufLen += TmpLen;
1580 }
1581 }
1582}
1583
1584static BOOLEAN IsValidChannel(struct rt_rtmp_adapter *pAd, u8 channel)
1585{
1586 int i;
1587
1588 for (i = 0; i < pAd->ChannelListNum; i++) {
1589 if (pAd->ChannelList[i].Channel == channel)
1590 break;
1591 }
1592
1593 if (i == pAd->ChannelListNum)
1594 return FALSE;
1595 else
1596 return TRUE;
1597}
1598
1599static u8 GetExtCh(u8 Channel, u8 Direction)
1600{
1601 char ExtCh;
1602
1603 if (Direction == EXTCHA_ABOVE)
1604 ExtCh = Channel + 4;
1605 else
1606 ExtCh = (Channel - 4) > 0 ? (Channel - 4) : 0;
1607
1608 return ExtCh;
1609}
1610
1611void N_ChannelCheck(struct rt_rtmp_adapter *pAd)
1612{
1613 /*u8 ChannelNum = pAd->ChannelListNum; */
1614 u8 Channel = pAd->CommonCfg.Channel;
1615
1616 if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
1617 && (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)) {
1618 if (Channel > 14) {
1619 if ((Channel == 36) || (Channel == 44)
1620 || (Channel == 52) || (Channel == 60)
1621 || (Channel == 100) || (Channel == 108)
1622 || (Channel == 116) || (Channel == 124)
1623 || (Channel == 132) || (Channel == 149)
1624 || (Channel == 157)) {
1625 pAd->CommonCfg.RegTransmitSetting.field.EXTCHA =
1626 EXTCHA_ABOVE;
1627 } else if ((Channel == 40) || (Channel == 48)
1628 || (Channel == 56) || (Channel == 64)
1629 || (Channel == 104) || (Channel == 112)
1630 || (Channel == 120) || (Channel == 128)
1631 || (Channel == 136) || (Channel == 153)
1632 || (Channel == 161)) {
1633 pAd->CommonCfg.RegTransmitSetting.field.EXTCHA =
1634 EXTCHA_BELOW;
1635 } else {
1636 pAd->CommonCfg.RegTransmitSetting.field.BW =
1637 BW_20;
1638 }
1639 } else {
1640 do {
1641 u8 ExtCh;
1642 u8 Dir =
1643 pAd->CommonCfg.RegTransmitSetting.field.
1644 EXTCHA;
1645 ExtCh = GetExtCh(Channel, Dir);
1646 if (IsValidChannel(pAd, ExtCh))
1647 break;
1648
1649 Dir =
1650 (Dir ==
1651 EXTCHA_ABOVE) ? EXTCHA_BELOW :
1652 EXTCHA_ABOVE;
1653 ExtCh = GetExtCh(Channel, Dir);
1654 if (IsValidChannel(pAd, ExtCh)) {
1655 pAd->CommonCfg.RegTransmitSetting.field.
1656 EXTCHA = Dir;
1657 break;
1658 }
1659 pAd->CommonCfg.RegTransmitSetting.field.BW =
1660 BW_20;
1661 } while (FALSE);
1662
1663 if (Channel == 14) {
1664 pAd->CommonCfg.RegTransmitSetting.field.BW =
1665 BW_20;
1666 /*pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_NONE; // We didn't set the ExtCh as NONE due to it'll set in RTMPSetHT() */
1667 }
1668 }
1669 }
1670
1671}
1672
1673void N_SetCenCh(struct rt_rtmp_adapter *pAd)
1674{
1675 if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40) {
1676 if (pAd->CommonCfg.RegTransmitSetting.field.EXTCHA ==
1677 EXTCHA_ABOVE) {
1678 pAd->CommonCfg.CentralChannel =
1679 pAd->CommonCfg.Channel + 2;
1680 } else {
1681 if (pAd->CommonCfg.Channel == 14)
1682 pAd->CommonCfg.CentralChannel =
1683 pAd->CommonCfg.Channel - 1;
1684 else
1685 pAd->CommonCfg.CentralChannel =
1686 pAd->CommonCfg.Channel - 2;
1687 }
1688 } else {
1689 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
1690 }
1691}
1692
1693u8 GetCuntryMaxTxPwr(struct rt_rtmp_adapter *pAd, u8 channel)
1694{
1695 int i;
1696 for (i = 0; i < pAd->ChannelListNum; i++) {
1697 if (pAd->ChannelList[i].Channel == channel)
1698 break;
1699 }
1700
1701 if (i == pAd->ChannelListNum)
1702 return 0xff;
1703 else
1704 return pAd->ChannelList[i].MaxTxPwr;
1705}
diff --git a/drivers/staging/rt2860/common/rt_rf.c b/drivers/staging/rt2860/common/rt_rf.c
deleted file mode 100644
index 2895447ffc4..00000000000
--- a/drivers/staging/rt2860/common/rt_rf.c
+++ /dev/null
@@ -1,187 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt_rf.c
29
30 Abstract:
31 Ralink Wireless driver RF related functions
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#include "../rt_config.h"
39
40#ifdef RTMP_RF_RW_SUPPORT
41/*
42 ========================================================================
43
44 Routine Description: Write RT30xx RF register through MAC
45
46 Arguments:
47
48 Return Value:
49
50 IRQL =
51
52 Note:
53
54 ========================================================================
55*/
56int RT30xxWriteRFRegister(struct rt_rtmp_adapter *pAd,
57 u8 regID, u8 value)
58{
59 RF_CSR_CFG_STRUC rfcsr;
60 u32 i = 0;
61
62 do {
63 RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
64
65 if (!rfcsr.field.RF_CSR_KICK)
66 break;
67 i++;
68 }
69 while ((i < RETRY_LIMIT)
70 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
71
72 if ((i == RETRY_LIMIT)
73 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
74 DBGPRINT_RAW(RT_DEBUG_ERROR,
75 ("Retry count exhausted or device removed!\n"));
76 return STATUS_UNSUCCESSFUL;
77 }
78
79 rfcsr.field.RF_CSR_WR = 1;
80 rfcsr.field.RF_CSR_KICK = 1;
81 rfcsr.field.TESTCSR_RFACC_REGNUM = regID;
82 rfcsr.field.RF_CSR_DATA = value;
83
84 RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word);
85
86 return NDIS_STATUS_SUCCESS;
87}
88
89/*
90 ========================================================================
91
92 Routine Description: Read RT30xx RF register through MAC
93
94 Arguments:
95
96 Return Value:
97
98 IRQL =
99
100 Note:
101
102 ========================================================================
103*/
104int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd,
105 u8 regID, u8 *pValue)
106{
107 RF_CSR_CFG_STRUC rfcsr;
108 u32 i = 0, k = 0;
109
110 for (i = 0; i < MAX_BUSY_COUNT; i++) {
111 RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
112
113 if (rfcsr.field.RF_CSR_KICK == BUSY) {
114 continue;
115 }
116 rfcsr.word = 0;
117 rfcsr.field.RF_CSR_WR = 0;
118 rfcsr.field.RF_CSR_KICK = 1;
119 rfcsr.field.TESTCSR_RFACC_REGNUM = regID;
120 RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word);
121 for (k = 0; k < MAX_BUSY_COUNT; k++) {
122 RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
123
124 if (rfcsr.field.RF_CSR_KICK == IDLE)
125 break;
126 }
127 if ((rfcsr.field.RF_CSR_KICK == IDLE) &&
128 (rfcsr.field.TESTCSR_RFACC_REGNUM == regID)) {
129 *pValue = (u8)rfcsr.field.RF_CSR_DATA;
130 break;
131 }
132 }
133 if (rfcsr.field.RF_CSR_KICK == BUSY) {
134 DBGPRINT_ERR("RF read R%d=0x%x fail, i[%d], k[%d]\n", regID, rfcsr.word, i, k);
135 return STATUS_UNSUCCESSFUL;
136 }
137
138 return STATUS_SUCCESS;
139}
140
141void NICInitRFRegisters(struct rt_rtmp_adapter *pAd)
142{
143 if (pAd->chipOps.AsicRfInit)
144 pAd->chipOps.AsicRfInit(pAd);
145}
146
147void RtmpChipOpsRFHook(struct rt_rtmp_adapter *pAd)
148{
149 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
150
151 pChipOps->pRFRegTable = NULL;
152 pChipOps->AsicRfInit = NULL;
153 pChipOps->AsicRfTurnOn = NULL;
154 pChipOps->AsicRfTurnOff = NULL;
155 pChipOps->AsicReverseRfFromSleepMode = NULL;
156 pChipOps->AsicHaltAction = NULL;
157 /* We depends on RfICType and MACVersion to assign the corresponding operation callbacks. */
158
159#ifdef RT30xx
160 if (IS_RT30xx(pAd)) {
161 pChipOps->pRFRegTable = RT30xx_RFRegTable;
162 pChipOps->AsicHaltAction = RT30xxHaltAction;
163#ifdef RT3070
164 if ((IS_RT3070(pAd) || IS_RT3071(pAd))
165 && (pAd->infType == RTMP_DEV_INF_USB)) {
166 pChipOps->AsicRfInit = NICInitRT3070RFRegisters;
167 if (IS_RT3071(pAd)) {
168 pChipOps->AsicRfTurnOff =
169 RT30xxLoadRFSleepModeSetup;
170 pChipOps->AsicReverseRfFromSleepMode =
171 RT30xxReverseRFSleepModeSetup;
172 }
173 }
174#endif /* RT3070 // */
175#ifdef RT3090
176 if (IS_RT3090(pAd) && (pAd->infType == RTMP_DEV_INF_PCI)) {
177 pChipOps->AsicRfTurnOff = RT30xxLoadRFSleepModeSetup;
178 pChipOps->AsicRfInit = NICInitRT3090RFRegisters;
179 pChipOps->AsicReverseRfFromSleepMode =
180 RT30xxReverseRFSleepModeSetup;
181 }
182#endif /* RT3090 // */
183 }
184#endif /* RT30xx // */
185}
186
187#endif /* RTMP_RF_RW_SUPPORT // */
diff --git a/drivers/staging/rt2860/common/rtmp_init.c b/drivers/staging/rt2860/common/rtmp_init.c
deleted file mode 100644
index 5fa193eac0d..00000000000
--- a/drivers/staging/rt2860/common/rtmp_init.c
+++ /dev/null
@@ -1,3536 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_init.c
29
30 Abstract:
31 Miniport generic portion header file
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37#include "../rt_config.h"
38
39u8 BIT8[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
40char *CipherName[] =
41 { "none", "wep64", "wep128", "TKIP", "AES", "CKIP64", "CKIP128" };
42
43/* */
44/* BBP register initialization set */
45/* */
46struct rt_reg_pair BBPRegTable[] = {
47 {BBP_R65, 0x2C}, /* fix rssi issue */
48 {BBP_R66, 0x38}, /* Also set this default value to pAd->BbpTuning.R66CurrentValue at initial */
49 {BBP_R69, 0x12},
50 {BBP_R70, 0xa}, /* BBP_R70 will change to 0x8 in ApStartUp and LinkUp for rt2860C, otherwise value is 0xa */
51 {BBP_R73, 0x10},
52 {BBP_R81, 0x37},
53 {BBP_R82, 0x62},
54 {BBP_R83, 0x6A},
55 {BBP_R84, 0x99}, /* 0x19 is for rt2860E and after. This is for extension channel overlapping IOT. 0x99 is for rt2860D and before */
56 {BBP_R86, 0x00}, /* middle range issue, Rory @2008-01-28 */
57 {BBP_R91, 0x04}, /* middle range issue, Rory @2008-01-28 */
58 {BBP_R92, 0x00}, /* middle range issue, Rory @2008-01-28 */
59 {BBP_R103, 0x00}, /* near range high-power issue, requested from Gary @2008-0528 */
60 {BBP_R105, 0x05}, /* 0x05 is for rt2860E to turn on FEQ control. It is safe for rt2860D and before, because Bit 7:2 are reserved in rt2860D and before. */
61 {BBP_R106, 0x35}, /* for ShortGI throughput */
62};
63
64#define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(struct rt_reg_pair))
65
66/* */
67/* ASIC register initialization sets */
68/* */
69
70struct rt_rtmp_reg_pair MACRegTable[] = {
71#if defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x200)
72 {BCN_OFFSET0, 0xf8f0e8e0}, /* 0x3800(e0), 0x3A00(e8), 0x3C00(f0), 0x3E00(f8), 512B for each beacon */
73 {BCN_OFFSET1, 0x6f77d0c8}, /* 0x3200(c8), 0x3400(d0), 0x1DC0(77), 0x1BC0(6f), 512B for each beacon */
74#elif defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x100)
75 {BCN_OFFSET0, 0xece8e4e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
76 {BCN_OFFSET1, 0xfcf8f4f0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */
77#else
78#error You must re-calculate new value for BCN_OFFSET0 & BCN_OFFSET1 in MACRegTable[]!
79#endif /* HW_BEACON_OFFSET // */
80
81 {LEGACY_BASIC_RATE, 0x0000013f}, /* Basic rate set bitmap */
82 {HT_BASIC_RATE, 0x00008003}, /* Basic HT rate set , 20M, MCS=3, MM. Format is the same as in TXWI. */
83 {MAC_SYS_CTRL, 0x00}, /* 0x1004, , default Disable RX */
84 {RX_FILTR_CFG, 0x17f97}, /*0x1400 , RX filter control, */
85 {BKOFF_SLOT_CFG, 0x209}, /* default set short slot time, CC_DELAY_TIME should be 2 */
86 /*{TX_SW_CFG0, 0x40a06}, // Gary,2006-08-23 */
87 {TX_SW_CFG0, 0x0}, /* Gary,2008-05-21 for CWC test */
88 {TX_SW_CFG1, 0x80606}, /* Gary,2006-08-23 */
89 {TX_LINK_CFG, 0x1020}, /* Gary,2006-08-23 */
90 /*{TX_TIMEOUT_CFG, 0x00182090}, // CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT */
91 {TX_TIMEOUT_CFG, 0x000a2090}, /* CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT , Modify for 2860E ,2007-08-01 */
92 {MAX_LEN_CFG, MAX_AGGREGATION_SIZE | 0x00001000}, /* 0x3018, MAX frame length. Max PSDU = 16kbytes. */
93 {LED_CFG, 0x7f031e46}, /* Gary, 2006-08-23 */
94
95 {PBF_MAX_PCNT, 0x1F3FBF9F}, /*0x1F3f7f9f}, //Jan, 2006/04/20 */
96
97 {TX_RTY_CFG, 0x47d01f0f}, /* Jan, 2006/11/16, Set TxWI->ACK =0 in Probe Rsp Modify for 2860E ,2007-08-03 */
98
99 {AUTO_RSP_CFG, 0x00000013}, /* Initial Auto_Responder, because QA will turn off Auto-Responder */
100 {CCK_PROT_CFG, 0x05740003 /*0x01740003 */ }, /* Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. */
101 {OFDM_PROT_CFG, 0x05740003 /*0x01740003 */ }, /* Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. */
102#ifdef RTMP_MAC_USB
103 {PBF_CFG, 0xf40006}, /* Only enable Queue 2 */
104 {MM40_PROT_CFG, 0x3F44084}, /* Initial Auto_Responder, because QA will turn off Auto-Responder */
105 {WPDMA_GLO_CFG, 0x00000030},
106#endif /* RTMP_MAC_USB // */
107 {GF20_PROT_CFG, 0x01744004}, /* set 19:18 --> Short NAV for MIMO PS */
108 {GF40_PROT_CFG, 0x03F44084},
109 {MM20_PROT_CFG, 0x01744004},
110#ifdef RTMP_MAC_PCI
111 {MM40_PROT_CFG, 0x03F54084},
112#endif /* RTMP_MAC_PCI // */
113 {TXOP_CTRL_CFG, 0x0000583f, /*0x0000243f *//*0x000024bf */ }, /*Extension channel backoff. */
114 {TX_RTS_CFG, 0x00092b20},
115 {EXP_ACK_TIME, 0x002400ca}, /* default value */
116
117 {TXOP_HLDR_ET, 0x00000002},
118
119 /* Jerry comments 2008/01/16: we use SIFS = 10us in CCK defaultly, but it seems that 10us
120 is too small for INTEL 2200bg card, so in MBSS mode, the delta time between beacon0
121 and beacon1 is SIFS (10us), so if INTEL 2200bg card connects to BSS0, the ping
122 will always lost. So we change the SIFS of CCK from 10us to 16us. */
123 {XIFS_TIME_CFG, 0x33a41010},
124 {PWR_PIN_CFG, 0x00000003}, /* patch for 2880-E */
125};
126
127struct rt_rtmp_reg_pair STAMACRegTable[] = {
128 {WMM_AIFSN_CFG, 0x00002273},
129 {WMM_CWMIN_CFG, 0x00002344},
130 {WMM_CWMAX_CFG, 0x000034aa},
131};
132
133#define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(struct rt_rtmp_reg_pair))
134#define NUM_STA_MAC_REG_PARMS (sizeof(STAMACRegTable) / sizeof(struct rt_rtmp_reg_pair))
135
136/*
137 ========================================================================
138
139 Routine Description:
140 Allocate struct rt_rtmp_adapter data block and do some initialization
141
142 Arguments:
143 Adapter Pointer to our adapter
144
145 Return Value:
146 NDIS_STATUS_SUCCESS
147 NDIS_STATUS_FAILURE
148
149 IRQL = PASSIVE_LEVEL
150
151 Note:
152
153 ========================================================================
154*/
155int RTMPAllocAdapterBlock(void *handle,
156 struct rt_rtmp_adapter * * ppAdapter)
157{
158 struct rt_rtmp_adapter *pAd;
159 int Status;
160 int index;
161 u8 *pBeaconBuf = NULL;
162
163 DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocAdapterBlock\n"));
164
165 *ppAdapter = NULL;
166
167 do {
168 /* Allocate struct rt_rtmp_adapter memory block */
169 pBeaconBuf = kmalloc(MAX_BEACON_SIZE, MEM_ALLOC_FLAG);
170 if (pBeaconBuf == NULL) {
171 Status = NDIS_STATUS_FAILURE;
172 DBGPRINT_ERR("Failed to allocate memory - BeaconBuf!\n");
173 break;
174 }
175 NdisZeroMemory(pBeaconBuf, MAX_BEACON_SIZE);
176
177 Status = AdapterBlockAllocateMemory(handle, (void **) & pAd);
178 if (Status != NDIS_STATUS_SUCCESS) {
179 DBGPRINT_ERR("Failed to allocate memory - ADAPTER\n");
180 break;
181 }
182 pAd->BeaconBuf = pBeaconBuf;
183 DBGPRINT(RT_DEBUG_OFF,
184 ("=== pAd = %p, size = %d ===\n", pAd,
185 (u32)sizeof(struct rt_rtmp_adapter)));
186
187 /* Init spin locks */
188 NdisAllocateSpinLock(&pAd->MgmtRingLock);
189#ifdef RTMP_MAC_PCI
190 NdisAllocateSpinLock(&pAd->RxRingLock);
191#ifdef RT3090
192 NdisAllocateSpinLock(&pAd->McuCmdLock);
193#endif /* RT3090 // */
194#endif /* RTMP_MAC_PCI // */
195
196 for (index = 0; index < NUM_OF_TX_RING; index++) {
197 NdisAllocateSpinLock(&pAd->TxSwQueueLock[index]);
198 NdisAllocateSpinLock(&pAd->DeQueueLock[index]);
199 pAd->DeQueueRunning[index] = FALSE;
200 }
201
202 NdisAllocateSpinLock(&pAd->irq_lock);
203
204 } while (FALSE);
205
206 if ((Status != NDIS_STATUS_SUCCESS) && (pBeaconBuf))
207 kfree(pBeaconBuf);
208
209 *ppAdapter = pAd;
210
211 DBGPRINT_S(Status, ("<-- RTMPAllocAdapterBlock, Status=%x\n", Status));
212 return Status;
213}
214
215/*
216 ========================================================================
217
218 Routine Description:
219 Read initial Tx power per MCS and BW from EEPROM
220
221 Arguments:
222 Adapter Pointer to our adapter
223
224 Return Value:
225 None
226
227 IRQL = PASSIVE_LEVEL
228
229 Note:
230
231 ========================================================================
232*/
233void RTMPReadTxPwrPerRate(struct rt_rtmp_adapter *pAd)
234{
235 unsigned long data, Adata, Gdata;
236 u16 i, value, value2;
237 int Apwrdelta, Gpwrdelta;
238 u8 t1, t2, t3, t4;
239 BOOLEAN bApwrdeltaMinus = TRUE, bGpwrdeltaMinus = TRUE;
240
241 /* */
242 /* Get power delta for 20MHz and 40MHz. */
243 /* */
244 DBGPRINT(RT_DEBUG_TRACE, ("Txpower per Rate\n"));
245 RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_DELTA, value2);
246 Apwrdelta = 0;
247 Gpwrdelta = 0;
248
249 if ((value2 & 0xff) != 0xff) {
250 if ((value2 & 0x80))
251 Gpwrdelta = (value2 & 0xf);
252
253 if ((value2 & 0x40))
254 bGpwrdeltaMinus = FALSE;
255 else
256 bGpwrdeltaMinus = TRUE;
257 }
258 if ((value2 & 0xff00) != 0xff00) {
259 if ((value2 & 0x8000))
260 Apwrdelta = ((value2 & 0xf00) >> 8);
261
262 if ((value2 & 0x4000))
263 bApwrdeltaMinus = FALSE;
264 else
265 bApwrdeltaMinus = TRUE;
266 }
267 DBGPRINT(RT_DEBUG_TRACE,
268 ("Gpwrdelta = %x, Apwrdelta = %x .\n", Gpwrdelta, Apwrdelta));
269
270 /* */
271 /* Get Txpower per MCS for 20MHz in 2.4G. */
272 /* */
273 for (i = 0; i < 5; i++) {
274 RT28xx_EEPROM_READ16(pAd,
275 EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i * 4,
276 value);
277 data = value;
278 if (bApwrdeltaMinus == FALSE) {
279 t1 = (value & 0xf) + (Apwrdelta);
280 if (t1 > 0xf)
281 t1 = 0xf;
282 t2 = ((value & 0xf0) >> 4) + (Apwrdelta);
283 if (t2 > 0xf)
284 t2 = 0xf;
285 t3 = ((value & 0xf00) >> 8) + (Apwrdelta);
286 if (t3 > 0xf)
287 t3 = 0xf;
288 t4 = ((value & 0xf000) >> 12) + (Apwrdelta);
289 if (t4 > 0xf)
290 t4 = 0xf;
291 } else {
292 if ((value & 0xf) > Apwrdelta)
293 t1 = (value & 0xf) - (Apwrdelta);
294 else
295 t1 = 0;
296 if (((value & 0xf0) >> 4) > Apwrdelta)
297 t2 = ((value & 0xf0) >> 4) - (Apwrdelta);
298 else
299 t2 = 0;
300 if (((value & 0xf00) >> 8) > Apwrdelta)
301 t3 = ((value & 0xf00) >> 8) - (Apwrdelta);
302 else
303 t3 = 0;
304 if (((value & 0xf000) >> 12) > Apwrdelta)
305 t4 = ((value & 0xf000) >> 12) - (Apwrdelta);
306 else
307 t4 = 0;
308 }
309 Adata = t1 + (t2 << 4) + (t3 << 8) + (t4 << 12);
310 if (bGpwrdeltaMinus == FALSE) {
311 t1 = (value & 0xf) + (Gpwrdelta);
312 if (t1 > 0xf)
313 t1 = 0xf;
314 t2 = ((value & 0xf0) >> 4) + (Gpwrdelta);
315 if (t2 > 0xf)
316 t2 = 0xf;
317 t3 = ((value & 0xf00) >> 8) + (Gpwrdelta);
318 if (t3 > 0xf)
319 t3 = 0xf;
320 t4 = ((value & 0xf000) >> 12) + (Gpwrdelta);
321 if (t4 > 0xf)
322 t4 = 0xf;
323 } else {
324 if ((value & 0xf) > Gpwrdelta)
325 t1 = (value & 0xf) - (Gpwrdelta);
326 else
327 t1 = 0;
328 if (((value & 0xf0) >> 4) > Gpwrdelta)
329 t2 = ((value & 0xf0) >> 4) - (Gpwrdelta);
330 else
331 t2 = 0;
332 if (((value & 0xf00) >> 8) > Gpwrdelta)
333 t3 = ((value & 0xf00) >> 8) - (Gpwrdelta);
334 else
335 t3 = 0;
336 if (((value & 0xf000) >> 12) > Gpwrdelta)
337 t4 = ((value & 0xf000) >> 12) - (Gpwrdelta);
338 else
339 t4 = 0;
340 }
341 Gdata = t1 + (t2 << 4) + (t3 << 8) + (t4 << 12);
342
343 RT28xx_EEPROM_READ16(pAd,
344 EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i * 4 +
345 2, value);
346 if (bApwrdeltaMinus == FALSE) {
347 t1 = (value & 0xf) + (Apwrdelta);
348 if (t1 > 0xf)
349 t1 = 0xf;
350 t2 = ((value & 0xf0) >> 4) + (Apwrdelta);
351 if (t2 > 0xf)
352 t2 = 0xf;
353 t3 = ((value & 0xf00) >> 8) + (Apwrdelta);
354 if (t3 > 0xf)
355 t3 = 0xf;
356 t4 = ((value & 0xf000) >> 12) + (Apwrdelta);
357 if (t4 > 0xf)
358 t4 = 0xf;
359 } else {
360 if ((value & 0xf) > Apwrdelta)
361 t1 = (value & 0xf) - (Apwrdelta);
362 else
363 t1 = 0;
364 if (((value & 0xf0) >> 4) > Apwrdelta)
365 t2 = ((value & 0xf0) >> 4) - (Apwrdelta);
366 else
367 t2 = 0;
368 if (((value & 0xf00) >> 8) > Apwrdelta)
369 t3 = ((value & 0xf00) >> 8) - (Apwrdelta);
370 else
371 t3 = 0;
372 if (((value & 0xf000) >> 12) > Apwrdelta)
373 t4 = ((value & 0xf000) >> 12) - (Apwrdelta);
374 else
375 t4 = 0;
376 }
377 Adata |= ((t1 << 16) + (t2 << 20) + (t3 << 24) + (t4 << 28));
378 if (bGpwrdeltaMinus == FALSE) {
379 t1 = (value & 0xf) + (Gpwrdelta);
380 if (t1 > 0xf)
381 t1 = 0xf;
382 t2 = ((value & 0xf0) >> 4) + (Gpwrdelta);
383 if (t2 > 0xf)
384 t2 = 0xf;
385 t3 = ((value & 0xf00) >> 8) + (Gpwrdelta);
386 if (t3 > 0xf)
387 t3 = 0xf;
388 t4 = ((value & 0xf000) >> 12) + (Gpwrdelta);
389 if (t4 > 0xf)
390 t4 = 0xf;
391 } else {
392 if ((value & 0xf) > Gpwrdelta)
393 t1 = (value & 0xf) - (Gpwrdelta);
394 else
395 t1 = 0;
396 if (((value & 0xf0) >> 4) > Gpwrdelta)
397 t2 = ((value & 0xf0) >> 4) - (Gpwrdelta);
398 else
399 t2 = 0;
400 if (((value & 0xf00) >> 8) > Gpwrdelta)
401 t3 = ((value & 0xf00) >> 8) - (Gpwrdelta);
402 else
403 t3 = 0;
404 if (((value & 0xf000) >> 12) > Gpwrdelta)
405 t4 = ((value & 0xf000) >> 12) - (Gpwrdelta);
406 else
407 t4 = 0;
408 }
409 Gdata |= ((t1 << 16) + (t2 << 20) + (t3 << 24) + (t4 << 28));
410 data |= (value << 16);
411
412 /* For 20M/40M Power Delta issue */
413 pAd->Tx20MPwrCfgABand[i] = data;
414 pAd->Tx20MPwrCfgGBand[i] = data;
415 pAd->Tx40MPwrCfgABand[i] = Adata;
416 pAd->Tx40MPwrCfgGBand[i] = Gdata;
417
418 if (data != 0xffffffff)
419 RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i * 4, data);
420 DBGPRINT_RAW(RT_DEBUG_TRACE,
421 ("20MHz BW, 2.4G band-%lx, Adata = %lx, Gdata = %lx \n",
422 data, Adata, Gdata));
423 }
424}
425
426/*
427 ========================================================================
428
429 Routine Description:
430 Read initial channel power parameters from EEPROM
431
432 Arguments:
433 Adapter Pointer to our adapter
434
435 Return Value:
436 None
437
438 IRQL = PASSIVE_LEVEL
439
440 Note:
441
442 ========================================================================
443*/
444void RTMPReadChannelPwr(struct rt_rtmp_adapter *pAd)
445{
446 u8 i, choffset;
447 EEPROM_TX_PWR_STRUC Power;
448 EEPROM_TX_PWR_STRUC Power2;
449
450 /* Read Tx power value for all channels */
451 /* Value from 1 - 0x7f. Default value is 24. */
452 /* Power value : 2.4G 0x00 (0) ~ 0x1F (31) */
453 /* : 5.5G 0xF9 (-7) ~ 0x0F (15) */
454
455 /* 0. 11b/g, ch1 - ch 14 */
456 for (i = 0; i < 7; i++) {
457 RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2,
458 Power.word);
459 RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2,
460 Power2.word);
461 pAd->TxPower[i * 2].Channel = i * 2 + 1;
462 pAd->TxPower[i * 2 + 1].Channel = i * 2 + 2;
463
464 if ((Power.field.Byte0 > 31) || (Power.field.Byte0 < 0))
465 pAd->TxPower[i * 2].Power = DEFAULT_RF_TX_POWER;
466 else
467 pAd->TxPower[i * 2].Power = Power.field.Byte0;
468
469 if ((Power.field.Byte1 > 31) || (Power.field.Byte1 < 0))
470 pAd->TxPower[i * 2 + 1].Power = DEFAULT_RF_TX_POWER;
471 else
472 pAd->TxPower[i * 2 + 1].Power = Power.field.Byte1;
473
474 if ((Power2.field.Byte0 > 31) || (Power2.field.Byte0 < 0))
475 pAd->TxPower[i * 2].Power2 = DEFAULT_RF_TX_POWER;
476 else
477 pAd->TxPower[i * 2].Power2 = Power2.field.Byte0;
478
479 if ((Power2.field.Byte1 > 31) || (Power2.field.Byte1 < 0))
480 pAd->TxPower[i * 2 + 1].Power2 = DEFAULT_RF_TX_POWER;
481 else
482 pAd->TxPower[i * 2 + 1].Power2 = Power2.field.Byte1;
483 }
484
485 /* 1. U-NII lower/middle band: 36, 38, 40; 44, 46, 48; 52, 54, 56; 60, 62, 64 (including central frequency in BW 40MHz) */
486 /* 1.1 Fill up channel */
487 choffset = 14;
488 for (i = 0; i < 4; i++) {
489 pAd->TxPower[3 * i + choffset + 0].Channel = 36 + i * 8 + 0;
490 pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
491 pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
492
493 pAd->TxPower[3 * i + choffset + 1].Channel = 36 + i * 8 + 2;
494 pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
495 pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
496
497 pAd->TxPower[3 * i + choffset + 2].Channel = 36 + i * 8 + 4;
498 pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
499 pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
500 }
501
502 /* 1.2 Fill up power */
503 for (i = 0; i < 6; i++) {
504 RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2,
505 Power.word);
506 RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2,
507 Power2.word);
508
509 if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
510 pAd->TxPower[i * 2 + choffset + 0].Power =
511 Power.field.Byte0;
512
513 if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
514 pAd->TxPower[i * 2 + choffset + 1].Power =
515 Power.field.Byte1;
516
517 if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
518 pAd->TxPower[i * 2 + choffset + 0].Power2 =
519 Power2.field.Byte0;
520
521 if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
522 pAd->TxPower[i * 2 + choffset + 1].Power2 =
523 Power2.field.Byte1;
524 }
525
526 /* 2. HipperLAN 2 100, 102 ,104; 108, 110, 112; 116, 118, 120; 124, 126, 128; 132, 134, 136; 140 (including central frequency in BW 40MHz) */
527 /* 2.1 Fill up channel */
528 choffset = 14 + 12;
529 for (i = 0; i < 5; i++) {
530 pAd->TxPower[3 * i + choffset + 0].Channel = 100 + i * 8 + 0;
531 pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
532 pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
533
534 pAd->TxPower[3 * i + choffset + 1].Channel = 100 + i * 8 + 2;
535 pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
536 pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
537
538 pAd->TxPower[3 * i + choffset + 2].Channel = 100 + i * 8 + 4;
539 pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
540 pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
541 }
542 pAd->TxPower[3 * 5 + choffset + 0].Channel = 140;
543 pAd->TxPower[3 * 5 + choffset + 0].Power = DEFAULT_RF_TX_POWER;
544 pAd->TxPower[3 * 5 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
545
546 /* 2.2 Fill up power */
547 for (i = 0; i < 8; i++) {
548 RT28xx_EEPROM_READ16(pAd,
549 EEPROM_A_TX_PWR_OFFSET + (choffset - 14) +
550 i * 2, Power.word);
551 RT28xx_EEPROM_READ16(pAd,
552 EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) +
553 i * 2, Power2.word);
554
555 if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
556 pAd->TxPower[i * 2 + choffset + 0].Power =
557 Power.field.Byte0;
558
559 if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
560 pAd->TxPower[i * 2 + choffset + 1].Power =
561 Power.field.Byte1;
562
563 if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
564 pAd->TxPower[i * 2 + choffset + 0].Power2 =
565 Power2.field.Byte0;
566
567 if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
568 pAd->TxPower[i * 2 + choffset + 1].Power2 =
569 Power2.field.Byte1;
570 }
571
572 /* 3. U-NII upper band: 149, 151, 153; 157, 159, 161; 165, 167, 169; 171, 173 (including central frequency in BW 40MHz) */
573 /* 3.1 Fill up channel */
574 choffset = 14 + 12 + 16;
575 /*for (i = 0; i < 2; i++) */
576 for (i = 0; i < 3; i++) {
577 pAd->TxPower[3 * i + choffset + 0].Channel = 149 + i * 8 + 0;
578 pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER;
579 pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
580
581 pAd->TxPower[3 * i + choffset + 1].Channel = 149 + i * 8 + 2;
582 pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER;
583 pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
584
585 pAd->TxPower[3 * i + choffset + 2].Channel = 149 + i * 8 + 4;
586 pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER;
587 pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER;
588 }
589 pAd->TxPower[3 * 3 + choffset + 0].Channel = 171;
590 pAd->TxPower[3 * 3 + choffset + 0].Power = DEFAULT_RF_TX_POWER;
591 pAd->TxPower[3 * 3 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER;
592
593 pAd->TxPower[3 * 3 + choffset + 1].Channel = 173;
594 pAd->TxPower[3 * 3 + choffset + 1].Power = DEFAULT_RF_TX_POWER;
595 pAd->TxPower[3 * 3 + choffset + 1].Power2 = DEFAULT_RF_TX_POWER;
596
597 /* 3.2 Fill up power */
598 /*for (i = 0; i < 4; i++) */
599 for (i = 0; i < 6; i++) {
600 RT28xx_EEPROM_READ16(pAd,
601 EEPROM_A_TX_PWR_OFFSET + (choffset - 14) +
602 i * 2, Power.word);
603 RT28xx_EEPROM_READ16(pAd,
604 EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) +
605 i * 2, Power2.word);
606
607 if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7))
608 pAd->TxPower[i * 2 + choffset + 0].Power =
609 Power.field.Byte0;
610
611 if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7))
612 pAd->TxPower[i * 2 + choffset + 1].Power =
613 Power.field.Byte1;
614
615 if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7))
616 pAd->TxPower[i * 2 + choffset + 0].Power2 =
617 Power2.field.Byte0;
618
619 if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7))
620 pAd->TxPower[i * 2 + choffset + 1].Power2 =
621 Power2.field.Byte1;
622 }
623
624 /* 4. Print and Debug */
625 /*choffset = 14 + 12 + 16 + 7; */
626 choffset = 14 + 12 + 16 + 11;
627
628}
629
630/*
631 ========================================================================
632
633 Routine Description:
634 Read the following from the registry
635 1. All the parameters
636 2. NetworkAddres
637
638 Arguments:
639 Adapter Pointer to our adapter
640 WrapperConfigurationContext For use by NdisOpenConfiguration
641
642 Return Value:
643 NDIS_STATUS_SUCCESS
644 NDIS_STATUS_FAILURE
645 NDIS_STATUS_RESOURCES
646
647 IRQL = PASSIVE_LEVEL
648
649 Note:
650
651 ========================================================================
652*/
653int NICReadRegParameters(struct rt_rtmp_adapter *pAd,
654 void *WrapperConfigurationContext)
655{
656 int Status = NDIS_STATUS_SUCCESS;
657 DBGPRINT_S(Status, ("<-- NICReadRegParameters, Status=%x\n", Status));
658 return Status;
659}
660
661/*
662 ========================================================================
663
664 Routine Description:
665 Read initial parameters from EEPROM
666
667 Arguments:
668 Adapter Pointer to our adapter
669
670 Return Value:
671 None
672
673 IRQL = PASSIVE_LEVEL
674
675 Note:
676
677 ========================================================================
678*/
679void NICReadEEPROMParameters(struct rt_rtmp_adapter *pAd, u8 *mac_addr)
680{
681 u32 data = 0;
682 u16 i, value, value2;
683 u8 TmpPhy;
684 EEPROM_TX_PWR_STRUC Power;
685 EEPROM_VERSION_STRUC Version;
686 EEPROM_ANTENNA_STRUC Antenna;
687 EEPROM_NIC_CONFIG2_STRUC NicConfig2;
688
689 DBGPRINT(RT_DEBUG_TRACE, ("--> NICReadEEPROMParameters\n"));
690
691 if (pAd->chipOps.eeinit)
692 pAd->chipOps.eeinit(pAd);
693
694 /* Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8 */
695 RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
696 DBGPRINT(RT_DEBUG_TRACE, ("--> E2PROM_CSR = 0x%x\n", data));
697
698 if ((data & 0x30) == 0)
699 pAd->EEPROMAddressNum = 6; /* 93C46 */
700 else if ((data & 0x30) == 0x10)
701 pAd->EEPROMAddressNum = 8; /* 93C66 */
702 else
703 pAd->EEPROMAddressNum = 8; /* 93C86 */
704 DBGPRINT(RT_DEBUG_TRACE,
705 ("--> EEPROMAddressNum = %d\n", pAd->EEPROMAddressNum));
706
707 /* RT2860 MAC no longer auto load MAC address from E2PROM. Driver has to initialize */
708 /* MAC address registers according to E2PROM setting */
709 if (mac_addr == NULL ||
710 strlen((char *)mac_addr) != 17 ||
711 mac_addr[2] != ':' || mac_addr[5] != ':' || mac_addr[8] != ':' ||
712 mac_addr[11] != ':' || mac_addr[14] != ':') {
713 u16 Addr01, Addr23, Addr45;
714
715 RT28xx_EEPROM_READ16(pAd, 0x04, Addr01);
716 RT28xx_EEPROM_READ16(pAd, 0x06, Addr23);
717 RT28xx_EEPROM_READ16(pAd, 0x08, Addr45);
718
719 pAd->PermanentAddress[0] = (u8)(Addr01 & 0xff);
720 pAd->PermanentAddress[1] = (u8)(Addr01 >> 8);
721 pAd->PermanentAddress[2] = (u8)(Addr23 & 0xff);
722 pAd->PermanentAddress[3] = (u8)(Addr23 >> 8);
723 pAd->PermanentAddress[4] = (u8)(Addr45 & 0xff);
724 pAd->PermanentAddress[5] = (u8)(Addr45 >> 8);
725
726 DBGPRINT(RT_DEBUG_TRACE,
727 ("Initialize MAC Address from E2PROM \n"));
728 } else {
729 int j;
730 char *macptr;
731
732 macptr = (char *)mac_addr;
733
734 for (j = 0; j < MAC_ADDR_LEN; j++) {
735 AtoH(macptr, &pAd->PermanentAddress[j], 1);
736 macptr = macptr + 3;
737 }
738
739 DBGPRINT(RT_DEBUG_TRACE,
740 ("Initialize MAC Address from module parameter \n"));
741 }
742
743 {
744 /*more conveninet to test mbssid, so ap's bssid &0xf1 */
745 if (pAd->PermanentAddress[0] == 0xff)
746 pAd->PermanentAddress[0] = RandomByte(pAd) & 0xf8;
747
748 /*if (pAd->PermanentAddress[5] == 0xff) */
749 /* pAd->PermanentAddress[5] = RandomByte(pAd)&0xf8; */
750
751 DBGPRINT_RAW(RT_DEBUG_TRACE,
752 ("E2PROM MAC: =%pM\n", pAd->PermanentAddress));
753 if (pAd->bLocalAdminMAC == FALSE) {
754 MAC_DW0_STRUC csr2;
755 MAC_DW1_STRUC csr3;
756 COPY_MAC_ADDR(pAd->CurrentAddress,
757 pAd->PermanentAddress);
758 csr2.field.Byte0 = pAd->CurrentAddress[0];
759 csr2.field.Byte1 = pAd->CurrentAddress[1];
760 csr2.field.Byte2 = pAd->CurrentAddress[2];
761 csr2.field.Byte3 = pAd->CurrentAddress[3];
762 RTMP_IO_WRITE32(pAd, MAC_ADDR_DW0, csr2.word);
763 csr3.word = 0;
764 csr3.field.Byte4 = pAd->CurrentAddress[4];
765 csr3.field.Byte5 = pAd->CurrentAddress[5];
766 csr3.field.U2MeMask = 0xff;
767 RTMP_IO_WRITE32(pAd, MAC_ADDR_DW1, csr3.word);
768 DBGPRINT_RAW(RT_DEBUG_TRACE,
769 ("E2PROM MAC: =%pM\n",
770 pAd->PermanentAddress));
771 }
772 }
773
774 /* if not return early. cause fail at emulation. */
775 /* Init the channel number for TX channel power */
776 RTMPReadChannelPwr(pAd);
777
778 /* if E2PROM version mismatch with driver's expectation, then skip */
779 /* all subsequent E2RPOM retieval and set a system error bit to notify GUI */
780 RT28xx_EEPROM_READ16(pAd, EEPROM_VERSION_OFFSET, Version.word);
781 pAd->EepromVersion =
782 Version.field.Version + Version.field.FaeReleaseNumber * 256;
783 DBGPRINT(RT_DEBUG_TRACE,
784 ("E2PROM: Version = %d, FAE release #%d\n",
785 Version.field.Version, Version.field.FaeReleaseNumber));
786
787 if (Version.field.Version > VALID_EEPROM_VERSION) {
788 DBGPRINT_ERR("E2PROM: WRONG VERSION 0x%x, should be %d\n", Version.field.Version, VALID_EEPROM_VERSION);
789 /*pAd->SystemErrorBitmap |= 0x00000001;
790
791 // hard-code default value when no proper E2PROM installed
792 pAd->bAutoTxAgcA = FALSE;
793 pAd->bAutoTxAgcG = FALSE;
794
795 // Default the channel power
796 for (i = 0; i < MAX_NUM_OF_CHANNELS; i++)
797 pAd->TxPower[i].Power = DEFAULT_RF_TX_POWER;
798
799 // Default the channel power
800 for (i = 0; i < MAX_NUM_OF_11JCHANNELS; i++)
801 pAd->TxPower11J[i].Power = DEFAULT_RF_TX_POWER;
802
803 for(i = 0; i < NUM_EEPROM_BBP_PARMS; i++)
804 pAd->EEPROMDefaultValue[i] = 0xffff;
805 return; */
806 }
807 /* Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAd */
808 RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, value);
809 pAd->EEPROMDefaultValue[0] = value;
810
811 RT28xx_EEPROM_READ16(pAd, EEPROM_NIC2_OFFSET, value);
812 pAd->EEPROMDefaultValue[1] = value;
813
814 RT28xx_EEPROM_READ16(pAd, 0x38, value); /* Country Region */
815 pAd->EEPROMDefaultValue[2] = value;
816
817 for (i = 0; i < 8; i++) {
818 RT28xx_EEPROM_READ16(pAd, EEPROM_BBP_BASE_OFFSET + i * 2,
819 value);
820 pAd->EEPROMDefaultValue[i + 3] = value;
821 }
822
823 /* We have to parse NIC configuration 0 at here. */
824 /* If TSSI did not have preloaded value, it should reset the TxAutoAgc to false */
825 /* Therefore, we have to read TxAutoAgc control beforehand. */
826 /* Read Tx AGC control bit */
827 Antenna.word = pAd->EEPROMDefaultValue[0];
828 if (Antenna.word == 0xFFFF) {
829#ifdef RT30xx
830 if (IS_RT3090(pAd) || IS_RT3390(pAd)) {
831 Antenna.word = 0;
832 Antenna.field.RfIcType = RFIC_3020;
833 Antenna.field.TxPath = 1;
834 Antenna.field.RxPath = 1;
835 } else
836#endif /* RT30xx // */
837 {
838
839 Antenna.word = 0;
840 Antenna.field.RfIcType = RFIC_2820;
841 Antenna.field.TxPath = 1;
842 Antenna.field.RxPath = 2;
843 DBGPRINT(RT_DEBUG_WARN,
844 ("E2PROM error, hard code as 0x%04x\n",
845 Antenna.word));
846 }
847 }
848 /* Choose the desired Tx&Rx stream. */
849 if ((pAd->CommonCfg.TxStream == 0)
850 || (pAd->CommonCfg.TxStream > Antenna.field.TxPath))
851 pAd->CommonCfg.TxStream = Antenna.field.TxPath;
852
853 if ((pAd->CommonCfg.RxStream == 0)
854 || (pAd->CommonCfg.RxStream > Antenna.field.RxPath)) {
855 pAd->CommonCfg.RxStream = Antenna.field.RxPath;
856
857 if ((pAd->MACVersion < RALINK_2883_VERSION) &&
858 (pAd->CommonCfg.RxStream > 2)) {
859 /* only 2 Rx streams for RT2860 series */
860 pAd->CommonCfg.RxStream = 2;
861 }
862 }
863 /* 3*3 */
864 /* read value from EEPROM and set them to CSR174 ~ 177 in chain0 ~ chain2 */
865 /* yet implement */
866 for (i = 0; i < 3; i++) {
867 }
868
869 NicConfig2.word = pAd->EEPROMDefaultValue[1];
870
871 {
872 if ((NicConfig2.word & 0x00ff) == 0xff) {
873 NicConfig2.word &= 0xff00;
874 }
875
876 if ((NicConfig2.word >> 8) == 0xff) {
877 NicConfig2.word &= 0x00ff;
878 }
879 }
880
881 if (NicConfig2.field.DynamicTxAgcControl == 1)
882 pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
883 else
884 pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
885
886 DBGPRINT_RAW(RT_DEBUG_TRACE,
887 ("NICReadEEPROMParameters: RxPath = %d, TxPath = %d\n",
888 Antenna.field.RxPath, Antenna.field.TxPath));
889
890 /* Save the antenna for future use */
891 pAd->Antenna.word = Antenna.word;
892
893 /* Set the RfICType here, then we can initialize RFIC related operation callbacks */
894 pAd->Mlme.RealRxPath = (u8)Antenna.field.RxPath;
895 pAd->RfIcType = (u8)Antenna.field.RfIcType;
896
897#ifdef RTMP_RF_RW_SUPPORT
898 RtmpChipOpsRFHook(pAd);
899#endif /* RTMP_RF_RW_SUPPORT // */
900
901#ifdef RTMP_MAC_PCI
902 sprintf((char *)pAd->nickname, "RT2860STA");
903#endif /* RTMP_MAC_PCI // */
904
905 /* */
906 /* Reset PhyMode if we don't support 802.11a */
907 /* Only RFIC_2850 & RFIC_2750 support 802.11a */
908 /* */
909 if ((Antenna.field.RfIcType != RFIC_2850)
910 && (Antenna.field.RfIcType != RFIC_2750)
911 && (Antenna.field.RfIcType != RFIC_3052)) {
912 if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) ||
913 (pAd->CommonCfg.PhyMode == PHY_11A))
914 pAd->CommonCfg.PhyMode = PHY_11BG_MIXED;
915 else if ((pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) ||
916 (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED) ||
917 (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) ||
918 (pAd->CommonCfg.PhyMode == PHY_11N_5G))
919 pAd->CommonCfg.PhyMode = PHY_11BGN_MIXED;
920 }
921 /* Read TSSI reference and TSSI boundary for temperature compensation. This is ugly */
922 /* 0. 11b/g */
923 {
924 /* these are tempature reference value (0x00 ~ 0xFE)
925 ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0
926 TssiPlusBoundaryG [4] [3] [2] [1] [0] (smaller) +
927 TssiMinusBoundaryG[0] [1] [2] [3] [4] (larger) */
928 RT28xx_EEPROM_READ16(pAd, 0x6E, Power.word);
929 pAd->TssiMinusBoundaryG[4] = Power.field.Byte0;
930 pAd->TssiMinusBoundaryG[3] = Power.field.Byte1;
931 RT28xx_EEPROM_READ16(pAd, 0x70, Power.word);
932 pAd->TssiMinusBoundaryG[2] = Power.field.Byte0;
933 pAd->TssiMinusBoundaryG[1] = Power.field.Byte1;
934 RT28xx_EEPROM_READ16(pAd, 0x72, Power.word);
935 pAd->TssiRefG = Power.field.Byte0; /* reference value [0] */
936 pAd->TssiPlusBoundaryG[1] = Power.field.Byte1;
937 RT28xx_EEPROM_READ16(pAd, 0x74, Power.word);
938 pAd->TssiPlusBoundaryG[2] = Power.field.Byte0;
939 pAd->TssiPlusBoundaryG[3] = Power.field.Byte1;
940 RT28xx_EEPROM_READ16(pAd, 0x76, Power.word);
941 pAd->TssiPlusBoundaryG[4] = Power.field.Byte0;
942 pAd->TxAgcStepG = Power.field.Byte1;
943 pAd->TxAgcCompensateG = 0;
944 pAd->TssiMinusBoundaryG[0] = pAd->TssiRefG;
945 pAd->TssiPlusBoundaryG[0] = pAd->TssiRefG;
946
947 /* Disable TxAgc if the based value is not right */
948 if (pAd->TssiRefG == 0xff)
949 pAd->bAutoTxAgcG = FALSE;
950
951 DBGPRINT(RT_DEBUG_TRACE,
952 ("E2PROM: G Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
953 pAd->TssiMinusBoundaryG[4],
954 pAd->TssiMinusBoundaryG[3],
955 pAd->TssiMinusBoundaryG[2],
956 pAd->TssiMinusBoundaryG[1], pAd->TssiRefG,
957 pAd->TssiPlusBoundaryG[1], pAd->TssiPlusBoundaryG[2],
958 pAd->TssiPlusBoundaryG[3], pAd->TssiPlusBoundaryG[4],
959 pAd->TxAgcStepG, pAd->bAutoTxAgcG));
960 }
961 /* 1. 11a */
962 {
963 RT28xx_EEPROM_READ16(pAd, 0xD4, Power.word);
964 pAd->TssiMinusBoundaryA[4] = Power.field.Byte0;
965 pAd->TssiMinusBoundaryA[3] = Power.field.Byte1;
966 RT28xx_EEPROM_READ16(pAd, 0xD6, Power.word);
967 pAd->TssiMinusBoundaryA[2] = Power.field.Byte0;
968 pAd->TssiMinusBoundaryA[1] = Power.field.Byte1;
969 RT28xx_EEPROM_READ16(pAd, 0xD8, Power.word);
970 pAd->TssiRefA = Power.field.Byte0;
971 pAd->TssiPlusBoundaryA[1] = Power.field.Byte1;
972 RT28xx_EEPROM_READ16(pAd, 0xDA, Power.word);
973 pAd->TssiPlusBoundaryA[2] = Power.field.Byte0;
974 pAd->TssiPlusBoundaryA[3] = Power.field.Byte1;
975 RT28xx_EEPROM_READ16(pAd, 0xDC, Power.word);
976 pAd->TssiPlusBoundaryA[4] = Power.field.Byte0;
977 pAd->TxAgcStepA = Power.field.Byte1;
978 pAd->TxAgcCompensateA = 0;
979 pAd->TssiMinusBoundaryA[0] = pAd->TssiRefA;
980 pAd->TssiPlusBoundaryA[0] = pAd->TssiRefA;
981
982 /* Disable TxAgc if the based value is not right */
983 if (pAd->TssiRefA == 0xff)
984 pAd->bAutoTxAgcA = FALSE;
985
986 DBGPRINT(RT_DEBUG_TRACE,
987 ("E2PROM: A Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n",
988 pAd->TssiMinusBoundaryA[4],
989 pAd->TssiMinusBoundaryA[3],
990 pAd->TssiMinusBoundaryA[2],
991 pAd->TssiMinusBoundaryA[1], pAd->TssiRefA,
992 pAd->TssiPlusBoundaryA[1], pAd->TssiPlusBoundaryA[2],
993 pAd->TssiPlusBoundaryA[3], pAd->TssiPlusBoundaryA[4],
994 pAd->TxAgcStepA, pAd->bAutoTxAgcA));
995 }
996 pAd->BbpRssiToDbmDelta = 0x0;
997
998 /* Read frequency offset setting for RF */
999 RT28xx_EEPROM_READ16(pAd, EEPROM_FREQ_OFFSET, value);
1000 if ((value & 0x00FF) != 0x00FF)
1001 pAd->RfFreqOffset = (unsigned long)(value & 0x00FF);
1002 else
1003 pAd->RfFreqOffset = 0;
1004 DBGPRINT(RT_DEBUG_TRACE,
1005 ("E2PROM: RF FreqOffset=0x%lx \n", pAd->RfFreqOffset));
1006
1007 /*CountryRegion byte offset (38h) */
1008 value = pAd->EEPROMDefaultValue[2] >> 8; /* 2.4G band */
1009 value2 = pAd->EEPROMDefaultValue[2] & 0x00FF; /* 5G band */
1010
1011 if ((value <= REGION_MAXIMUM_BG_BAND)
1012 && (value2 <= REGION_MAXIMUM_A_BAND)) {
1013 pAd->CommonCfg.CountryRegion = ((u8)value) | 0x80;
1014 pAd->CommonCfg.CountryRegionForABand = ((u8)value2) | 0x80;
1015 TmpPhy = pAd->CommonCfg.PhyMode;
1016 pAd->CommonCfg.PhyMode = 0xff;
1017 RTMPSetPhyMode(pAd, TmpPhy);
1018 SetCommonHT(pAd);
1019 }
1020 /* */
1021 /* Get RSSI Offset on EEPROM 0x9Ah & 0x9Ch. */
1022 /* The valid value are (-10 ~ 10) */
1023 /* */
1024 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, value);
1025 pAd->BGRssiOffset0 = value & 0x00ff;
1026 pAd->BGRssiOffset1 = (value >> 8);
1027 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET + 2, value);
1028 pAd->BGRssiOffset2 = value & 0x00ff;
1029 pAd->ALNAGain1 = (value >> 8);
1030 RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, value);
1031 pAd->BLNAGain = value & 0x00ff;
1032 pAd->ALNAGain0 = (value >> 8);
1033
1034 /* Validate 11b/g RSSI_0 offset. */
1035 if ((pAd->BGRssiOffset0 < -10) || (pAd->BGRssiOffset0 > 10))
1036 pAd->BGRssiOffset0 = 0;
1037
1038 /* Validate 11b/g RSSI_1 offset. */
1039 if ((pAd->BGRssiOffset1 < -10) || (pAd->BGRssiOffset1 > 10))
1040 pAd->BGRssiOffset1 = 0;
1041
1042 /* Validate 11b/g RSSI_2 offset. */
1043 if ((pAd->BGRssiOffset2 < -10) || (pAd->BGRssiOffset2 > 10))
1044 pAd->BGRssiOffset2 = 0;
1045
1046 RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, value);
1047 pAd->ARssiOffset0 = value & 0x00ff;
1048 pAd->ARssiOffset1 = (value >> 8);
1049 RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET + 2), value);
1050 pAd->ARssiOffset2 = value & 0x00ff;
1051 pAd->ALNAGain2 = (value >> 8);
1052
1053 if (((u8)pAd->ALNAGain1 == 0xFF) || (pAd->ALNAGain1 == 0x00))
1054 pAd->ALNAGain1 = pAd->ALNAGain0;
1055 if (((u8)pAd->ALNAGain2 == 0xFF) || (pAd->ALNAGain2 == 0x00))
1056 pAd->ALNAGain2 = pAd->ALNAGain0;
1057
1058 /* Validate 11a RSSI_0 offset. */
1059 if ((pAd->ARssiOffset0 < -10) || (pAd->ARssiOffset0 > 10))
1060 pAd->ARssiOffset0 = 0;
1061
1062 /* Validate 11a RSSI_1 offset. */
1063 if ((pAd->ARssiOffset1 < -10) || (pAd->ARssiOffset1 > 10))
1064 pAd->ARssiOffset1 = 0;
1065
1066 /*Validate 11a RSSI_2 offset. */
1067 if ((pAd->ARssiOffset2 < -10) || (pAd->ARssiOffset2 > 10))
1068 pAd->ARssiOffset2 = 0;
1069
1070#ifdef RT30xx
1071 /* */
1072 /* Get TX mixer gain setting */
1073 /* 0xff are invalid value */
1074 /* Note: RT30xX default value is 0x00 and will program to RF_R17 only when this value is not zero. */
1075 /* RT359X default value is 0x02 */
1076 /* */
1077 if (IS_RT30xx(pAd) || IS_RT3572(pAd)) {
1078 RT28xx_EEPROM_READ16(pAd, EEPROM_TXMIXER_GAIN_2_4G, value);
1079 pAd->TxMixerGain24G = 0;
1080 value &= 0x00ff;
1081 if (value != 0xff) {
1082 value &= 0x07;
1083 pAd->TxMixerGain24G = (u8)value;
1084 }
1085 }
1086#endif /* RT30xx // */
1087
1088 /* */
1089 /* Get LED Setting. */
1090 /* */
1091 RT28xx_EEPROM_READ16(pAd, 0x3a, value);
1092 pAd->LedCntl.word = (value >> 8);
1093 RT28xx_EEPROM_READ16(pAd, EEPROM_LED1_OFFSET, value);
1094 pAd->Led1 = value;
1095 RT28xx_EEPROM_READ16(pAd, EEPROM_LED2_OFFSET, value);
1096 pAd->Led2 = value;
1097 RT28xx_EEPROM_READ16(pAd, EEPROM_LED3_OFFSET, value);
1098 pAd->Led3 = value;
1099
1100 RTMPReadTxPwrPerRate(pAd);
1101
1102#ifdef RT30xx
1103#ifdef RTMP_EFUSE_SUPPORT
1104 RtmpEfuseSupportCheck(pAd);
1105#endif /* RTMP_EFUSE_SUPPORT // */
1106#endif /* RT30xx // */
1107
1108 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICReadEEPROMParameters\n"));
1109}
1110
1111/*
1112 ========================================================================
1113
1114 Routine Description:
1115 Set default value from EEPROM
1116
1117 Arguments:
1118 Adapter Pointer to our adapter
1119
1120 Return Value:
1121 None
1122
1123 IRQL = PASSIVE_LEVEL
1124
1125 Note:
1126
1127 ========================================================================
1128*/
1129void NICInitAsicFromEEPROM(struct rt_rtmp_adapter *pAd)
1130{
1131 u32 data = 0;
1132 u8 BBPR1 = 0;
1133 u16 i;
1134/* EEPROM_ANTENNA_STRUC Antenna; */
1135 EEPROM_NIC_CONFIG2_STRUC NicConfig2;
1136 u8 BBPR3 = 0;
1137
1138 DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitAsicFromEEPROM\n"));
1139 for (i = 3; i < NUM_EEPROM_BBP_PARMS; i++) {
1140 u8 BbpRegIdx, BbpValue;
1141
1142 if ((pAd->EEPROMDefaultValue[i] != 0xFFFF)
1143 && (pAd->EEPROMDefaultValue[i] != 0)) {
1144 BbpRegIdx = (u8)(pAd->EEPROMDefaultValue[i] >> 8);
1145 BbpValue = (u8)(pAd->EEPROMDefaultValue[i] & 0xff);
1146 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BbpRegIdx, BbpValue);
1147 }
1148 }
1149
1150 NicConfig2.word = pAd->EEPROMDefaultValue[1];
1151
1152 {
1153 if ((NicConfig2.word & 0x00ff) == 0xff) {
1154 NicConfig2.word &= 0xff00;
1155 }
1156
1157 if ((NicConfig2.word >> 8) == 0xff) {
1158 NicConfig2.word &= 0x00ff;
1159 }
1160 }
1161
1162 /* Save the antenna for future use */
1163 pAd->NicConfig2.word = NicConfig2.word;
1164
1165#ifdef RT30xx
1166 /* set default antenna as main */
1167 if (pAd->RfIcType == RFIC_3020)
1168 AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
1169#endif /* RT30xx // */
1170
1171 /* */
1172 /* Send LED Setting to MCU. */
1173 /* */
1174 if (pAd->LedCntl.word == 0xFF) {
1175 pAd->LedCntl.word = 0x01;
1176 pAd->Led1 = 0x5555;
1177 pAd->Led2 = 0x2221;
1178
1179#ifdef RTMP_MAC_PCI
1180 pAd->Led3 = 0xA9F8;
1181#endif /* RTMP_MAC_PCI // */
1182#ifdef RTMP_MAC_USB
1183 pAd->Led3 = 0x5627;
1184#endif /* RTMP_MAC_USB // */
1185 }
1186
1187 AsicSendCommandToMcu(pAd, 0x52, 0xff, (u8)pAd->Led1,
1188 (u8)(pAd->Led1 >> 8));
1189 AsicSendCommandToMcu(pAd, 0x53, 0xff, (u8)pAd->Led2,
1190 (u8)(pAd->Led2 >> 8));
1191 AsicSendCommandToMcu(pAd, 0x54, 0xff, (u8)pAd->Led3,
1192 (u8)(pAd->Led3 >> 8));
1193 AsicSendCommandToMcu(pAd, 0x51, 0xff, 0, pAd->LedCntl.field.Polarity);
1194
1195 pAd->LedIndicatorStrength = 0xFF;
1196 RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, before link up */
1197
1198 {
1199 /* Read Hardware controlled Radio state enable bit */
1200 if (NicConfig2.field.HardwareRadioControl == 1) {
1201 pAd->StaCfg.bHardwareRadio = TRUE;
1202
1203 /* Read GPIO pin2 as Hardware controlled radio state */
1204 RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data);
1205 if ((data & 0x04) == 0) {
1206 pAd->StaCfg.bHwRadio = FALSE;
1207 pAd->StaCfg.bRadio = FALSE;
1208/* RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818); */
1209 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1210 }
1211 } else
1212 pAd->StaCfg.bHardwareRadio = FALSE;
1213
1214 if (pAd->StaCfg.bRadio == FALSE) {
1215 RTMPSetLED(pAd, LED_RADIO_OFF);
1216 } else {
1217 RTMPSetLED(pAd, LED_RADIO_ON);
1218#ifdef RTMP_MAC_PCI
1219#ifdef RT3090
1220 AsicSendCommandToMcu(pAd, 0x30, PowerRadioOffCID, 0xff,
1221 0x02);
1222 AsicCheckCommanOk(pAd, PowerRadioOffCID);
1223#endif /* RT3090 // */
1224#ifndef RT3090
1225 AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02);
1226#endif /* RT3090 // */
1227 AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00,
1228 0x00);
1229 /* 2-1. wait command ok. */
1230 AsicCheckCommanOk(pAd, PowerWakeCID);
1231#endif /* RTMP_MAC_PCI // */
1232 }
1233 }
1234
1235#ifdef RTMP_MAC_PCI
1236#ifdef RT30xx
1237 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) {
1238 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
1239 if (pChipOps->AsicReverseRfFromSleepMode)
1240 pChipOps->AsicReverseRfFromSleepMode(pAd);
1241 }
1242 /* 3090 MCU Wakeup command needs more time to be stable. */
1243 /* Before stable, don't issue other MCU command to prevent from firmware error. */
1244
1245 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
1246 && IS_VERSION_AFTER_F(pAd)
1247 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
1248 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
1249 DBGPRINT(RT_DEBUG_TRACE, ("%s, release Mcu Lock\n", __func__));
1250 RTMP_SEM_LOCK(&pAd->McuCmdLock);
1251 pAd->brt30xxBanMcuCmd = FALSE;
1252 RTMP_SEM_UNLOCK(&pAd->McuCmdLock);
1253 }
1254#endif /* RT30xx // */
1255#endif /* RTMP_MAC_PCI // */
1256
1257 /* Turn off patching for cardbus controller */
1258 if (NicConfig2.field.CardbusAcceleration == 1) {
1259/* pAd->bTest1 = TRUE; */
1260 }
1261
1262 if (NicConfig2.field.DynamicTxAgcControl == 1)
1263 pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE;
1264 else
1265 pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE;
1266 /* */
1267 /* Since BBP has been progamed, to make sure BBP setting will be */
1268 /* upate inside of AsicAntennaSelect, so reset to UNKNOWN_BAND! */
1269 /* */
1270 pAd->CommonCfg.BandState = UNKNOWN_BAND;
1271
1272 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3);
1273 BBPR3 &= (~0x18);
1274 if (pAd->Antenna.field.RxPath == 3) {
1275 BBPR3 |= (0x10);
1276 } else if (pAd->Antenna.field.RxPath == 2) {
1277 BBPR3 |= (0x8);
1278 } else if (pAd->Antenna.field.RxPath == 1) {
1279 BBPR3 |= (0x0);
1280 }
1281 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3);
1282
1283 {
1284 /* Handle the difference when 1T */
1285 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BBPR1);
1286 if (pAd->Antenna.field.TxPath == 1) {
1287 BBPR1 &= (~0x18);
1288 }
1289 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BBPR1);
1290
1291 DBGPRINT(RT_DEBUG_TRACE,
1292 ("Use Hw Radio Control Pin=%d; if used Pin=%d;\n",
1293 pAd->CommonCfg.bHardwareRadio,
1294 pAd->CommonCfg.bHardwareRadio));
1295 }
1296
1297#ifdef RTMP_MAC_USB
1298#ifdef RT30xx
1299 /* update registers from EEPROM for RT3071 or later(3572/3592). */
1300
1301 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) {
1302 u8 RegIdx, RegValue;
1303 u16 value;
1304
1305 /* after RT3071, write BBP from EEPROM 0xF0 to 0x102 */
1306 for (i = 0xF0; i <= 0x102; i = i + 2) {
1307 value = 0xFFFF;
1308 RT28xx_EEPROM_READ16(pAd, i, value);
1309 if ((value != 0xFFFF) && (value != 0)) {
1310 RegIdx = (u8)(value >> 8);
1311 RegValue = (u8)(value & 0xff);
1312 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, RegIdx,
1313 RegValue);
1314 DBGPRINT(RT_DEBUG_TRACE,
1315 ("Update BBP Registers from EEPROM(0x%0x), BBP(0x%x) = 0x%x\n",
1316 i, RegIdx, RegValue));
1317 }
1318 }
1319
1320 /* after RT3071, write RF from EEPROM 0x104 to 0x116 */
1321 for (i = 0x104; i <= 0x116; i = i + 2) {
1322 value = 0xFFFF;
1323 RT28xx_EEPROM_READ16(pAd, i, value);
1324 if ((value != 0xFFFF) && (value != 0)) {
1325 RegIdx = (u8)(value >> 8);
1326 RegValue = (u8)(value & 0xff);
1327 RT30xxWriteRFRegister(pAd, RegIdx, RegValue);
1328 DBGPRINT(RT_DEBUG_TRACE,
1329 ("Update RF Registers from EEPROM0x%x), BBP(0x%x) = 0x%x\n",
1330 i, RegIdx, RegValue));
1331 }
1332 }
1333 }
1334#endif /* RT30xx // */
1335#endif /* RTMP_MAC_USB // */
1336
1337 DBGPRINT(RT_DEBUG_TRACE,
1338 ("TxPath = %d, RxPath = %d, RFIC=%d, Polar+LED mode=%x\n",
1339 pAd->Antenna.field.TxPath, pAd->Antenna.field.RxPath,
1340 pAd->RfIcType, pAd->LedCntl.word));
1341 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitAsicFromEEPROM\n"));
1342}
1343
1344/*
1345 ========================================================================
1346
1347 Routine Description:
1348 Initialize NIC hardware
1349
1350 Arguments:
1351 Adapter Pointer to our adapter
1352
1353 Return Value:
1354 None
1355
1356 IRQL = PASSIVE_LEVEL
1357
1358 Note:
1359
1360 ========================================================================
1361*/
1362int NICInitializeAdapter(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset)
1363{
1364 int Status = NDIS_STATUS_SUCCESS;
1365 WPDMA_GLO_CFG_STRUC GloCfg;
1366#ifdef RTMP_MAC_PCI
1367 u32 Value;
1368 DELAY_INT_CFG_STRUC IntCfg;
1369#endif /* RTMP_MAC_PCI // */
1370/* INT_MASK_CSR_STRUC IntMask; */
1371 unsigned long i = 0, j = 0;
1372 AC_TXOP_CSR0_STRUC csr0;
1373
1374 DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAdapter\n"));
1375
1376 /* 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits: */
1377retry:
1378 i = 0;
1379 do {
1380 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1381 if ((GloCfg.field.TxDMABusy == 0)
1382 && (GloCfg.field.RxDMABusy == 0))
1383 break;
1384
1385 RTMPusecDelay(1000);
1386 i++;
1387 } while (i < 100);
1388 DBGPRINT(RT_DEBUG_TRACE,
1389 ("<== DMA offset 0x208 = 0x%x\n", GloCfg.word));
1390 GloCfg.word &= 0xff0;
1391 GloCfg.field.EnTXWriteBackDDONE = 1;
1392 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1393
1394 /* Record HW Beacon offset */
1395 pAd->BeaconOffset[0] = HW_BEACON_BASE0;
1396 pAd->BeaconOffset[1] = HW_BEACON_BASE1;
1397 pAd->BeaconOffset[2] = HW_BEACON_BASE2;
1398 pAd->BeaconOffset[3] = HW_BEACON_BASE3;
1399 pAd->BeaconOffset[4] = HW_BEACON_BASE4;
1400 pAd->BeaconOffset[5] = HW_BEACON_BASE5;
1401 pAd->BeaconOffset[6] = HW_BEACON_BASE6;
1402 pAd->BeaconOffset[7] = HW_BEACON_BASE7;
1403
1404 /* */
1405 /* write all shared Ring's base address into ASIC */
1406 /* */
1407
1408 /* asic simulation sequence put this ahead before loading firmware. */
1409 /* pbf hardware reset */
1410#ifdef RTMP_MAC_PCI
1411 RTMP_IO_WRITE32(pAd, WPDMA_RST_IDX, 0x1003f); /* 0x10000 for reset rx, 0x3f resets all 6 tx rings. */
1412 RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0xe1f);
1413 RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0xe00);
1414#endif /* RTMP_MAC_PCI // */
1415
1416 /* Initialze ASIC for TX & Rx operation */
1417 if (NICInitializeAsic(pAd, bHardReset) != NDIS_STATUS_SUCCESS) {
1418 if (j++ == 0) {
1419 NICLoadFirmware(pAd);
1420 goto retry;
1421 }
1422 return NDIS_STATUS_FAILURE;
1423 }
1424
1425#ifdef RTMP_MAC_PCI
1426 /* Write AC_BK base address register */
1427 Value =
1428 RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_BK].Cell[0].AllocPa);
1429 RTMP_IO_WRITE32(pAd, TX_BASE_PTR1, Value);
1430 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR1 : 0x%x\n", Value));
1431
1432 /* Write AC_BE base address register */
1433 Value =
1434 RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_BE].Cell[0].AllocPa);
1435 RTMP_IO_WRITE32(pAd, TX_BASE_PTR0, Value);
1436 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR0 : 0x%x\n", Value));
1437
1438 /* Write AC_VI base address register */
1439 Value =
1440 RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_VI].Cell[0].AllocPa);
1441 RTMP_IO_WRITE32(pAd, TX_BASE_PTR2, Value);
1442 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR2 : 0x%x\n", Value));
1443
1444 /* Write AC_VO base address register */
1445 Value =
1446 RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_VO].Cell[0].AllocPa);
1447 RTMP_IO_WRITE32(pAd, TX_BASE_PTR3, Value);
1448 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR3 : 0x%x\n", Value));
1449
1450 /* Write MGMT_BASE_CSR register */
1451 Value = RTMP_GetPhysicalAddressLow(pAd->MgmtRing.Cell[0].AllocPa);
1452 RTMP_IO_WRITE32(pAd, TX_BASE_PTR5, Value);
1453 DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR5 : 0x%x\n", Value));
1454
1455 /* Write RX_BASE_CSR register */
1456 Value = RTMP_GetPhysicalAddressLow(pAd->RxRing.Cell[0].AllocPa);
1457 RTMP_IO_WRITE32(pAd, RX_BASE_PTR, Value);
1458 DBGPRINT(RT_DEBUG_TRACE, ("--> RX_BASE_PTR : 0x%x\n", Value));
1459
1460 /* Init RX Ring index pointer */
1461 pAd->RxRing.RxSwReadIdx = 0;
1462 pAd->RxRing.RxCpuIdx = RX_RING_SIZE - 1;
1463 RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx);
1464
1465 /* Init TX rings index pointer */
1466 {
1467 for (i = 0; i < NUM_OF_TX_RING; i++) {
1468 pAd->TxRing[i].TxSwFreeIdx = 0;
1469 pAd->TxRing[i].TxCpuIdx = 0;
1470 RTMP_IO_WRITE32(pAd, (TX_CTX_IDX0 + i * 0x10),
1471 pAd->TxRing[i].TxCpuIdx);
1472 }
1473 }
1474
1475 /* init MGMT ring index pointer */
1476 pAd->MgmtRing.TxSwFreeIdx = 0;
1477 pAd->MgmtRing.TxCpuIdx = 0;
1478 RTMP_IO_WRITE32(pAd, TX_MGMTCTX_IDX, pAd->MgmtRing.TxCpuIdx);
1479
1480 /* */
1481 /* set each Ring's SIZE into ASIC. Descriptor Size is fixed by design. */
1482 /* */
1483
1484 /* Write TX_RING_CSR0 register */
1485 Value = TX_RING_SIZE;
1486 RTMP_IO_WRITE32(pAd, TX_MAX_CNT0, Value);
1487 RTMP_IO_WRITE32(pAd, TX_MAX_CNT1, Value);
1488 RTMP_IO_WRITE32(pAd, TX_MAX_CNT2, Value);
1489 RTMP_IO_WRITE32(pAd, TX_MAX_CNT3, Value);
1490 RTMP_IO_WRITE32(pAd, TX_MAX_CNT4, Value);
1491 Value = MGMT_RING_SIZE;
1492 RTMP_IO_WRITE32(pAd, TX_MGMTMAX_CNT, Value);
1493
1494 /* Write RX_RING_CSR register */
1495 Value = RX_RING_SIZE;
1496 RTMP_IO_WRITE32(pAd, RX_MAX_CNT, Value);
1497#endif /* RTMP_MAC_PCI // */
1498
1499 /* WMM parameter */
1500 csr0.word = 0;
1501 RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word);
1502 if (pAd->CommonCfg.PhyMode == PHY_11B) {
1503 csr0.field.Ac0Txop = 192; /* AC_VI: 192*32us ~= 6ms */
1504 csr0.field.Ac1Txop = 96; /* AC_VO: 96*32us ~= 3ms */
1505 } else {
1506 csr0.field.Ac0Txop = 96; /* AC_VI: 96*32us ~= 3ms */
1507 csr0.field.Ac1Txop = 48; /* AC_VO: 48*32us ~= 1.5ms */
1508 }
1509 RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr0.word);
1510
1511#ifdef RTMP_MAC_PCI
1512 /* 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits: */
1513 i = 0;
1514 do {
1515 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1516 if ((GloCfg.field.TxDMABusy == 0)
1517 && (GloCfg.field.RxDMABusy == 0))
1518 break;
1519
1520 RTMPusecDelay(1000);
1521 i++;
1522 } while (i < 100);
1523
1524 GloCfg.word &= 0xff0;
1525 GloCfg.field.EnTXWriteBackDDONE = 1;
1526 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1527
1528 IntCfg.word = 0;
1529 RTMP_IO_WRITE32(pAd, DELAY_INT_CFG, IntCfg.word);
1530#endif /* RTMP_MAC_PCI // */
1531
1532 /* reset action */
1533 /* Load firmware */
1534 /* Status = NICLoadFirmware(pAd); */
1535
1536 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAdapter\n"));
1537 return Status;
1538}
1539
1540/*
1541 ========================================================================
1542
1543 Routine Description:
1544 Initialize ASIC
1545
1546 Arguments:
1547 Adapter Pointer to our adapter
1548
1549 Return Value:
1550 None
1551
1552 IRQL = PASSIVE_LEVEL
1553
1554 Note:
1555
1556 ========================================================================
1557*/
1558int NICInitializeAsic(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset)
1559{
1560 unsigned long Index = 0;
1561 u8 R0 = 0xff;
1562 u32 MacCsr12 = 0, Counter = 0;
1563#ifdef RTMP_MAC_USB
1564 u32 MacCsr0 = 0;
1565 int Status;
1566 u8 Value = 0xff;
1567#endif /* RTMP_MAC_USB // */
1568#ifdef RT30xx
1569 u8 bbpreg = 0;
1570 u8 RFValue = 0;
1571#endif /* RT30xx // */
1572 u16 KeyIdx;
1573 int i, apidx;
1574
1575 DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAsic\n"));
1576
1577#ifdef RTMP_MAC_PCI
1578 RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x3); /* To fix driver disable/enable hang issue when radio off */
1579 if (bHardReset == TRUE) {
1580 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3);
1581 } else
1582 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
1583
1584 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
1585 /* Initialize MAC register to default value */
1586 for (Index = 0; Index < NUM_MAC_REG_PARMS; Index++) {
1587 RTMP_IO_WRITE32(pAd, MACRegTable[Index].Register,
1588 MACRegTable[Index].Value);
1589 }
1590
1591 {
1592 for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++) {
1593 RTMP_IO_WRITE32(pAd, STAMACRegTable[Index].Register,
1594 STAMACRegTable[Index].Value);
1595 }
1596 }
1597#endif /* RTMP_MAC_PCI // */
1598#ifdef RTMP_MAC_USB
1599 /* */
1600 /* Make sure MAC gets ready after NICLoadFirmware(). */
1601 /* */
1602 Index = 0;
1603
1604 /*To avoid hang-on issue when interface up in kernel 2.4, */
1605 /*we use a local variable "MacCsr0" instead of using "pAd->MACVersion" directly. */
1606 do {
1607 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
1608
1609 if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF))
1610 break;
1611
1612 RTMPusecDelay(10);
1613 } while (Index++ < 100);
1614
1615 pAd->MACVersion = MacCsr0;
1616 DBGPRINT(RT_DEBUG_TRACE,
1617 ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
1618 /* turn on bit13 (set to zero) after rt2860D. This is to solve high-current issue. */
1619 RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacCsr12);
1620 MacCsr12 &= (~0x2000);
1621 RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, MacCsr12);
1622
1623 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3);
1624 RTMP_IO_WRITE32(pAd, USB_DMA_CFG, 0x0);
1625 Status = RTUSBVenderReset(pAd);
1626
1627 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
1628
1629 /* Initialize MAC register to default value */
1630 for (Index = 0; Index < NUM_MAC_REG_PARMS; Index++) {
1631#ifdef RT30xx
1632 if ((MACRegTable[Index].Register == TX_SW_CFG0)
1633 && (IS_RT3070(pAd) || IS_RT3071(pAd) || IS_RT3572(pAd)
1634 || IS_RT3090(pAd) || IS_RT3390(pAd))) {
1635 MACRegTable[Index].Value = 0x00000400;
1636 }
1637#endif /* RT30xx // */
1638 RTMP_IO_WRITE32(pAd, (u16)MACRegTable[Index].Register,
1639 MACRegTable[Index].Value);
1640 }
1641
1642 {
1643 for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++) {
1644 RTMP_IO_WRITE32(pAd,
1645 (u16)STAMACRegTable[Index].Register,
1646 STAMACRegTable[Index].Value);
1647 }
1648 }
1649#endif /* RTMP_MAC_USB // */
1650
1651#ifdef RT30xx
1652 /* Initialize RT3070 serial MAC registers which is different from RT2870 serial */
1653 if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) {
1654 RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0);
1655
1656 /* RT3071 version E has fixed this issue */
1657 if ((pAd->MACVersion & 0xffff) < 0x0211) {
1658 if (pAd->NicConfig2.field.DACTestBit == 1) {
1659 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x2C); /* To fix throughput drop drastically */
1660 } else {
1661 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0F); /* To fix throughput drop drastically */
1662 }
1663 } else {
1664 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0);
1665 }
1666 } else if (IS_RT3070(pAd)) {
1667 if (((pAd->MACVersion & 0xffff) < 0x0201)) {
1668 RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0);
1669 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x2C); /* To fix throughput drop drastically */
1670 } else {
1671 RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0);
1672 }
1673 }
1674#endif /* RT30xx // */
1675
1676 /* */
1677 /* Before program BBP, we need to wait BBP/RF get wake up. */
1678 /* */
1679 Index = 0;
1680 do {
1681 RTMP_IO_READ32(pAd, MAC_STATUS_CFG, &MacCsr12);
1682
1683 if ((MacCsr12 & 0x03) == 0) /* if BB.RF is stable */
1684 break;
1685
1686 DBGPRINT(RT_DEBUG_TRACE,
1687 ("Check MAC_STATUS_CFG = Busy = %x\n", MacCsr12));
1688 RTMPusecDelay(1000);
1689 } while (Index++ < 100);
1690
1691 /* The commands to firmware should be after these commands, these commands will init firmware */
1692 /* PCI and USB are not the same because PCI driver needs to wait for PCI bus ready */
1693 RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, 0); /* initialize BBP R/W access agent */
1694 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, 0);
1695#ifdef RT3090
1696 /*2008/11/28:KH add to fix the dead rf frequency offset bug<-- */
1697 AsicSendCommandToMcu(pAd, 0x72, 0, 0, 0);
1698 /*2008/11/28:KH add to fix the dead rf frequency offset bug--> */
1699#endif /* RT3090 // */
1700 RTMPusecDelay(1000);
1701
1702 /* Read BBP register, make sure BBP is up and running before write new data */
1703 Index = 0;
1704 do {
1705 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R0, &R0);
1706 DBGPRINT(RT_DEBUG_TRACE, ("BBP version = %x\n", R0));
1707 } while ((++Index < 20) && ((R0 == 0xff) || (R0 == 0x00)));
1708 /*ASSERT(Index < 20); //this will cause BSOD on Check-build driver */
1709
1710 if ((R0 == 0xff) || (R0 == 0x00))
1711 return NDIS_STATUS_FAILURE;
1712
1713 /* Initialize BBP register to default value */
1714 for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++) {
1715 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register,
1716 BBPRegTable[Index].Value);
1717 }
1718
1719#ifdef RTMP_MAC_PCI
1720 /* TODO: shiang, check MACVersion, currently, rbus-based chip use this. */
1721 if (pAd->MACVersion == 0x28720200) {
1722 /*u8 value; */
1723 unsigned long value2;
1724
1725 /*disable MLD by Bruce 20080704 */
1726 /*BBP_IO_READ8_BY_REG_ID(pAd, BBP_R105, &value); */
1727 /*BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R105, value | 4); */
1728
1729 /*Maximum PSDU length from 16K to 32K bytes */
1730 RTMP_IO_READ32(pAd, MAX_LEN_CFG, &value2);
1731 value2 &= ~(0x3 << 12);
1732 value2 |= (0x2 << 12);
1733 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, value2);
1734 }
1735#endif /* RTMP_MAC_PCI // */
1736
1737 /* for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT. */
1738 /* RT3090 should not program BBP R84 to 0x19, otherwise TX will block. */
1739 /*3070/71/72,3090,3090A( are included in RT30xx),3572,3390 */
1740 if (((pAd->MACVersion & 0xffff) != 0x0101)
1741 && !(IS_RT30xx(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)))
1742 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x19);
1743
1744#ifdef RT30xx
1745/* add by johnli, RF power sequence setup */
1746 if (IS_RT30xx(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) { /*update for RT3070/71/72/90/91/92,3572,3390. */
1747 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R79, 0x13);
1748 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R80, 0x05);
1749 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R81, 0x33);
1750 }
1751
1752 if (IS_RT3090(pAd) || IS_RT3390(pAd)) /* RT309x, RT3071/72 */
1753 {
1754 /* enable DC filter */
1755 if ((pAd->MACVersion & 0xffff) >= 0x0211) {
1756 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R103, 0xc0);
1757 }
1758 /* improve power consumption */
1759 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R138, &bbpreg);
1760 if (pAd->Antenna.field.TxPath == 1) {
1761 /* turn off tx DAC_1 */
1762 bbpreg = (bbpreg | 0x20);
1763 }
1764
1765 if (pAd->Antenna.field.RxPath == 1) {
1766 /* turn off tx ADC_1 */
1767 bbpreg &= (~0x2);
1768 }
1769 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R138, bbpreg);
1770
1771 /* improve power consumption in RT3071 Ver.E */
1772 if ((pAd->MACVersion & 0xffff) >= 0x0211) {
1773 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R31, &bbpreg);
1774 bbpreg &= (~0x3);
1775 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R31, bbpreg);
1776 }
1777 } else if (IS_RT3070(pAd)) {
1778 if ((pAd->MACVersion & 0xffff) >= 0x0201) {
1779 /* enable DC filter */
1780 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R103, 0xc0);
1781
1782 /* improve power consumption in RT3070 Ver.F */
1783 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R31, &bbpreg);
1784 bbpreg &= (~0x3);
1785 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R31, bbpreg);
1786 }
1787 /* TX_LO1_en, RF R17 register Bit 3 to 0 */
1788 RT30xxReadRFRegister(pAd, RF_R17, &RFValue);
1789 RFValue &= (~0x08);
1790 /* to fix rx long range issue */
1791 if (pAd->NicConfig2.field.ExternalLNAForG == 0) {
1792 RFValue |= 0x20;
1793 }
1794 /* set RF_R17_bit[2:0] equal to EEPROM setting at 0x48h */
1795 if (pAd->TxMixerGain24G >= 1) {
1796 RFValue &= (~0x7); /* clean bit [2:0] */
1797 RFValue |= pAd->TxMixerGain24G;
1798 }
1799 RT30xxWriteRFRegister(pAd, RF_R17, RFValue);
1800 }
1801/* end johnli */
1802#endif /* RT30xx // */
1803
1804 if (pAd->MACVersion == 0x28600100) {
1805 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
1806 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x12);
1807 }
1808
1809 if (pAd->MACVersion >= RALINK_2880E_VERSION && pAd->MACVersion < RALINK_3070_VERSION) /* 3*3 */
1810 {
1811 /* enlarge MAX_LEN_CFG */
1812 u32 csr;
1813 RTMP_IO_READ32(pAd, MAX_LEN_CFG, &csr);
1814 csr &= 0xFFF;
1815 csr |= 0x2000;
1816 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, csr);
1817 }
1818#ifdef RTMP_MAC_USB
1819 {
1820 u8 MAC_Value[] =
1821 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0 };
1822
1823 /*Initialize WCID table */
1824 Value = 0xff;
1825 for (Index = 0; Index < 254; Index++) {
1826 RTUSBMultiWrite(pAd,
1827 (u16)(MAC_WCID_BASE + Index * 8),
1828 MAC_Value, 8);
1829 }
1830 }
1831#endif /* RTMP_MAC_USB // */
1832
1833 /* Add radio off control */
1834 {
1835 if (pAd->StaCfg.bRadio == FALSE) {
1836/* RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818); */
1837 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1838 DBGPRINT(RT_DEBUG_TRACE, ("Set Radio Off\n"));
1839 }
1840 }
1841
1842 /* Clear raw counters */
1843 RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter);
1844 RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter);
1845 RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter);
1846 RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter);
1847 RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter);
1848 RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter);
1849
1850 /* ASIC will keep garbage value after boot */
1851 /* Clear all shared key table when initial */
1852 /* This routine can be ignored in radio-ON/OFF operation. */
1853 if (bHardReset) {
1854 for (KeyIdx = 0; KeyIdx < 4; KeyIdx++) {
1855 RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * KeyIdx,
1856 0);
1857 }
1858
1859 /* Clear all pairwise key table when initial */
1860 for (KeyIdx = 0; KeyIdx < 256; KeyIdx++) {
1861 RTMP_IO_WRITE32(pAd,
1862 MAC_WCID_ATTRIBUTE_BASE +
1863 (KeyIdx * HW_WCID_ATTRI_SIZE), 1);
1864 }
1865 }
1866 /* assert HOST ready bit */
1867/* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x0); // 2004-09-14 asked by Mark */
1868/* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x4); */
1869
1870 /* It isn't necessary to clear this space when not hard reset. */
1871 if (bHardReset == TRUE) {
1872 /* clear all on-chip BEACON frame space */
1873 for (apidx = 0; apidx < HW_BEACON_MAX_COUNT; apidx++) {
1874 for (i = 0; i < HW_BEACON_OFFSET >> 2; i += 4)
1875 RTMP_IO_WRITE32(pAd,
1876 pAd->BeaconOffset[apidx] + i,
1877 0x00);
1878 }
1879 }
1880#ifdef RTMP_MAC_USB
1881 AsicDisableSync(pAd);
1882 /* Clear raw counters */
1883 RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter);
1884 RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter);
1885 RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter);
1886 RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter);
1887 RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter);
1888 RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter);
1889 /* Default PCI clock cycle per ms is different as default setting, which is based on PCI. */
1890 RTMP_IO_READ32(pAd, USB_CYC_CFG, &Counter);
1891 Counter &= 0xffffff00;
1892 Counter |= 0x000001e;
1893 RTMP_IO_WRITE32(pAd, USB_CYC_CFG, Counter);
1894#endif /* RTMP_MAC_USB // */
1895
1896 {
1897 /* for rt2860E and after, init TXOP_CTRL_CFG with 0x583f. This is for extension channel overlapping IOT. */
1898 if ((pAd->MACVersion & 0xffff) != 0x0101)
1899 RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x583f);
1900 }
1901
1902 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAsic\n"));
1903 return NDIS_STATUS_SUCCESS;
1904}
1905
1906/*
1907 ========================================================================
1908
1909 Routine Description:
1910 Reset NIC Asics
1911
1912 Arguments:
1913 Adapter Pointer to our adapter
1914
1915 Return Value:
1916 None
1917
1918 IRQL = PASSIVE_LEVEL
1919
1920 Note:
1921 Reset NIC to initial state AS IS system boot up time.
1922
1923 ========================================================================
1924*/
1925void NICIssueReset(struct rt_rtmp_adapter *pAd)
1926{
1927 u32 Value = 0;
1928 DBGPRINT(RT_DEBUG_TRACE, ("--> NICIssueReset\n"));
1929
1930 /* Abort Tx, prevent ASIC from writing to Host memory */
1931 /*RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x001f0000); */
1932
1933 /* Disable Rx, register value supposed will remain after reset */
1934 RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value);
1935 Value &= (0xfffffff3);
1936 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value);
1937
1938 /* Issue reset and clear from reset state */
1939 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x03); /* 2004-09-17 change from 0x01 */
1940 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x00);
1941
1942 DBGPRINT(RT_DEBUG_TRACE, ("<-- NICIssueReset\n"));
1943}
1944
1945/*
1946 ========================================================================
1947
1948 Routine Description:
1949 Check ASIC registers and find any reason the system might hang
1950
1951 Arguments:
1952 Adapter Pointer to our adapter
1953
1954 Return Value:
1955 None
1956
1957 IRQL = DISPATCH_LEVEL
1958
1959 ========================================================================
1960*/
1961BOOLEAN NICCheckForHang(struct rt_rtmp_adapter *pAd)
1962{
1963 return (FALSE);
1964}
1965
1966void NICUpdateFifoStaCounters(struct rt_rtmp_adapter *pAd)
1967{
1968 TX_STA_FIFO_STRUC StaFifo;
1969 struct rt_mac_table_entry *pEntry;
1970 u8 i = 0;
1971 u8 pid = 0, wcid = 0;
1972 char reTry;
1973 u8 succMCS;
1974
1975 do {
1976 RTMP_IO_READ32(pAd, TX_STA_FIFO, &StaFifo.word);
1977
1978 if (StaFifo.field.bValid == 0)
1979 break;
1980
1981 wcid = (u8)StaFifo.field.wcid;
1982
1983 /* ignore NoACK and MGMT frame use 0xFF as WCID */
1984 if ((StaFifo.field.TxAckRequired == 0)
1985 || (wcid >= MAX_LEN_OF_MAC_TABLE)) {
1986 i++;
1987 continue;
1988 }
1989
1990 /* PID store Tx MCS Rate */
1991 pid = (u8)StaFifo.field.PidType;
1992
1993 pEntry = &pAd->MacTab.Content[wcid];
1994
1995 pEntry->DebugFIFOCount++;
1996
1997 if (StaFifo.field.TxBF) /* 3*3 */
1998 pEntry->TxBFCount++;
1999
2000 if (!StaFifo.field.TxSuccess) {
2001 pEntry->FIFOCount++;
2002 pEntry->OneSecTxFailCount++;
2003
2004 if (pEntry->FIFOCount >= 1) {
2005 DBGPRINT(RT_DEBUG_TRACE, ("#"));
2006 pEntry->NoBADataCountDown = 64;
2007
2008 if (pEntry->PsMode == PWR_ACTIVE) {
2009 int tid;
2010 for (tid = 0; tid < NUM_OF_TID; tid++) {
2011 BAOriSessionTearDown(pAd,
2012 pEntry->
2013 Aid, tid,
2014 FALSE,
2015 FALSE);
2016 }
2017
2018 /* Update the continuous transmission counter except PS mode */
2019 pEntry->ContinueTxFailCnt++;
2020 } else {
2021 /* Clear the FIFOCount when sta in Power Save mode. Basically we assume */
2022 /* this tx error happened due to sta just go to sleep. */
2023 pEntry->FIFOCount = 0;
2024 pEntry->ContinueTxFailCnt = 0;
2025 }
2026 /*pEntry->FIFOCount = 0; */
2027 }
2028 /*pEntry->bSendBAR = TRUE; */
2029 } else {
2030 if ((pEntry->PsMode != PWR_SAVE)
2031 && (pEntry->NoBADataCountDown > 0)) {
2032 pEntry->NoBADataCountDown--;
2033 if (pEntry->NoBADataCountDown == 0) {
2034 DBGPRINT(RT_DEBUG_TRACE, ("@\n"));
2035 }
2036 }
2037
2038 pEntry->FIFOCount = 0;
2039 pEntry->OneSecTxNoRetryOkCount++;
2040 /* update NoDataIdleCount when successful send packet to STA. */
2041 pEntry->NoDataIdleCount = 0;
2042 pEntry->ContinueTxFailCnt = 0;
2043 }
2044
2045 succMCS = StaFifo.field.SuccessRate & 0x7F;
2046
2047 reTry = pid - succMCS;
2048
2049 if (StaFifo.field.TxSuccess) {
2050 pEntry->TXMCSExpected[pid]++;
2051 if (pid == succMCS) {
2052 pEntry->TXMCSSuccessful[pid]++;
2053 } else {
2054 pEntry->TXMCSAutoFallBack[pid][succMCS]++;
2055 }
2056 } else {
2057 pEntry->TXMCSFailed[pid]++;
2058 }
2059
2060 if (reTry > 0) {
2061 if ((pid >= 12) && succMCS <= 7) {
2062 reTry -= 4;
2063 }
2064 pEntry->OneSecTxRetryOkCount += reTry;
2065 }
2066
2067 i++;
2068 /* ASIC store 16 stack */
2069 } while (i < (2 * TX_RING_SIZE));
2070
2071}
2072
2073/*
2074 ========================================================================
2075
2076 Routine Description:
2077 Read statistical counters from hardware registers and record them
2078 in software variables for later on query
2079
2080 Arguments:
2081 pAd Pointer to our adapter
2082
2083 Return Value:
2084 None
2085
2086 IRQL = DISPATCH_LEVEL
2087
2088 ========================================================================
2089*/
2090void NICUpdateRawCounters(struct rt_rtmp_adapter *pAd)
2091{
2092 u32 OldValue; /*, Value2; */
2093 /*unsigned long PageSum, OneSecTransmitCount; */
2094 /*unsigned long TxErrorRatio, Retry, Fail; */
2095 RX_STA_CNT0_STRUC RxStaCnt0;
2096 RX_STA_CNT1_STRUC RxStaCnt1;
2097 RX_STA_CNT2_STRUC RxStaCnt2;
2098 TX_STA_CNT0_STRUC TxStaCnt0;
2099 TX_STA_CNT1_STRUC StaTx1;
2100 TX_STA_CNT2_STRUC StaTx2;
2101 TX_AGG_CNT_STRUC TxAggCnt;
2102 TX_AGG_CNT0_STRUC TxAggCnt0;
2103 TX_AGG_CNT1_STRUC TxAggCnt1;
2104 TX_AGG_CNT2_STRUC TxAggCnt2;
2105 TX_AGG_CNT3_STRUC TxAggCnt3;
2106 TX_AGG_CNT4_STRUC TxAggCnt4;
2107 TX_AGG_CNT5_STRUC TxAggCnt5;
2108 TX_AGG_CNT6_STRUC TxAggCnt6;
2109 TX_AGG_CNT7_STRUC TxAggCnt7;
2110 struct rt_counter_ralink *pRalinkCounters;
2111
2112 pRalinkCounters = &pAd->RalinkCounters;
2113
2114 RTMP_IO_READ32(pAd, RX_STA_CNT0, &RxStaCnt0.word);
2115 RTMP_IO_READ32(pAd, RX_STA_CNT2, &RxStaCnt2.word);
2116
2117 {
2118 RTMP_IO_READ32(pAd, RX_STA_CNT1, &RxStaCnt1.word);
2119 /* Update RX PLCP error counter */
2120 pAd->PrivateInfo.PhyRxErrCnt += RxStaCnt1.field.PlcpErr;
2121 /* Update False CCA counter */
2122 pAd->RalinkCounters.OneSecFalseCCACnt +=
2123 RxStaCnt1.field.FalseCca;
2124 }
2125
2126 /* Update FCS counters */
2127 OldValue = pAd->WlanCounters.FCSErrorCount.u.LowPart;
2128 pAd->WlanCounters.FCSErrorCount.u.LowPart += (RxStaCnt0.field.CrcErr); /* >> 7); */
2129 if (pAd->WlanCounters.FCSErrorCount.u.LowPart < OldValue)
2130 pAd->WlanCounters.FCSErrorCount.u.HighPart++;
2131
2132 /* Add FCS error count to private counters */
2133 pRalinkCounters->OneSecRxFcsErrCnt += RxStaCnt0.field.CrcErr;
2134 OldValue = pRalinkCounters->RealFcsErrCount.u.LowPart;
2135 pRalinkCounters->RealFcsErrCount.u.LowPart += RxStaCnt0.field.CrcErr;
2136 if (pRalinkCounters->RealFcsErrCount.u.LowPart < OldValue)
2137 pRalinkCounters->RealFcsErrCount.u.HighPart++;
2138
2139 /* Update Duplicate Rcv check */
2140 pRalinkCounters->DuplicateRcv += RxStaCnt2.field.RxDupliCount;
2141 pAd->WlanCounters.FrameDuplicateCount.u.LowPart +=
2142 RxStaCnt2.field.RxDupliCount;
2143 /* Update RX Overflow counter */
2144 pAd->Counters8023.RxNoBuffer += (RxStaCnt2.field.RxFifoOverflowCount);
2145
2146 /*pAd->RalinkCounters.RxCount = 0; */
2147#ifdef RTMP_MAC_USB
2148 if (pRalinkCounters->RxCount != pAd->watchDogRxCnt) {
2149 pAd->watchDogRxCnt = pRalinkCounters->RxCount;
2150 pAd->watchDogRxOverFlowCnt = 0;
2151 } else {
2152 if (RxStaCnt2.field.RxFifoOverflowCount)
2153 pAd->watchDogRxOverFlowCnt++;
2154 else
2155 pAd->watchDogRxOverFlowCnt = 0;
2156 }
2157#endif /* RTMP_MAC_USB // */
2158
2159 /*if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) || */
2160 /* (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) && (pAd->MacTab.Size != 1))) */
2161 if (!pAd->bUpdateBcnCntDone) {
2162 /* Update BEACON sent count */
2163 RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word);
2164 RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word);
2165 RTMP_IO_READ32(pAd, TX_STA_CNT2, &StaTx2.word);
2166 pRalinkCounters->OneSecBeaconSentCnt +=
2167 TxStaCnt0.field.TxBeaconCount;
2168 pRalinkCounters->OneSecTxRetryOkCount +=
2169 StaTx1.field.TxRetransmit;
2170 pRalinkCounters->OneSecTxNoRetryOkCount +=
2171 StaTx1.field.TxSuccess;
2172 pRalinkCounters->OneSecTxFailCount +=
2173 TxStaCnt0.field.TxFailCount;
2174 pAd->WlanCounters.TransmittedFragmentCount.u.LowPart +=
2175 StaTx1.field.TxSuccess;
2176 pAd->WlanCounters.RetryCount.u.LowPart +=
2177 StaTx1.field.TxRetransmit;
2178 pAd->WlanCounters.FailedCount.u.LowPart +=
2179 TxStaCnt0.field.TxFailCount;
2180 }
2181
2182 /*if (pAd->bStaFifoTest == TRUE) */
2183 {
2184 RTMP_IO_READ32(pAd, TX_AGG_CNT, &TxAggCnt.word);
2185 RTMP_IO_READ32(pAd, TX_AGG_CNT0, &TxAggCnt0.word);
2186 RTMP_IO_READ32(pAd, TX_AGG_CNT1, &TxAggCnt1.word);
2187 RTMP_IO_READ32(pAd, TX_AGG_CNT2, &TxAggCnt2.word);
2188 RTMP_IO_READ32(pAd, TX_AGG_CNT3, &TxAggCnt3.word);
2189 RTMP_IO_READ32(pAd, TX_AGG_CNT4, &TxAggCnt4.word);
2190 RTMP_IO_READ32(pAd, TX_AGG_CNT5, &TxAggCnt5.word);
2191 RTMP_IO_READ32(pAd, TX_AGG_CNT6, &TxAggCnt6.word);
2192 RTMP_IO_READ32(pAd, TX_AGG_CNT7, &TxAggCnt7.word);
2193 pRalinkCounters->TxAggCount += TxAggCnt.field.AggTxCount;
2194 pRalinkCounters->TxNonAggCount += TxAggCnt.field.NonAggTxCount;
2195 pRalinkCounters->TxAgg1MPDUCount +=
2196 TxAggCnt0.field.AggSize1Count;
2197 pRalinkCounters->TxAgg2MPDUCount +=
2198 TxAggCnt0.field.AggSize2Count;
2199
2200 pRalinkCounters->TxAgg3MPDUCount +=
2201 TxAggCnt1.field.AggSize3Count;
2202 pRalinkCounters->TxAgg4MPDUCount +=
2203 TxAggCnt1.field.AggSize4Count;
2204 pRalinkCounters->TxAgg5MPDUCount +=
2205 TxAggCnt2.field.AggSize5Count;
2206 pRalinkCounters->TxAgg6MPDUCount +=
2207 TxAggCnt2.field.AggSize6Count;
2208
2209 pRalinkCounters->TxAgg7MPDUCount +=
2210 TxAggCnt3.field.AggSize7Count;
2211 pRalinkCounters->TxAgg8MPDUCount +=
2212 TxAggCnt3.field.AggSize8Count;
2213 pRalinkCounters->TxAgg9MPDUCount +=
2214 TxAggCnt4.field.AggSize9Count;
2215 pRalinkCounters->TxAgg10MPDUCount +=
2216 TxAggCnt4.field.AggSize10Count;
2217
2218 pRalinkCounters->TxAgg11MPDUCount +=
2219 TxAggCnt5.field.AggSize11Count;
2220 pRalinkCounters->TxAgg12MPDUCount +=
2221 TxAggCnt5.field.AggSize12Count;
2222 pRalinkCounters->TxAgg13MPDUCount +=
2223 TxAggCnt6.field.AggSize13Count;
2224 pRalinkCounters->TxAgg14MPDUCount +=
2225 TxAggCnt6.field.AggSize14Count;
2226
2227 pRalinkCounters->TxAgg15MPDUCount +=
2228 TxAggCnt7.field.AggSize15Count;
2229 pRalinkCounters->TxAgg16MPDUCount +=
2230 TxAggCnt7.field.AggSize16Count;
2231
2232 /* Calculate the transmitted A-MPDU count */
2233 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2234 TxAggCnt0.field.AggSize1Count;
2235 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2236 (TxAggCnt0.field.AggSize2Count / 2);
2237
2238 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2239 (TxAggCnt1.field.AggSize3Count / 3);
2240 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2241 (TxAggCnt1.field.AggSize4Count / 4);
2242
2243 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2244 (TxAggCnt2.field.AggSize5Count / 5);
2245 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2246 (TxAggCnt2.field.AggSize6Count / 6);
2247
2248 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2249 (TxAggCnt3.field.AggSize7Count / 7);
2250 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2251 (TxAggCnt3.field.AggSize8Count / 8);
2252
2253 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2254 (TxAggCnt4.field.AggSize9Count / 9);
2255 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2256 (TxAggCnt4.field.AggSize10Count / 10);
2257
2258 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2259 (TxAggCnt5.field.AggSize11Count / 11);
2260 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2261 (TxAggCnt5.field.AggSize12Count / 12);
2262
2263 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2264 (TxAggCnt6.field.AggSize13Count / 13);
2265 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2266 (TxAggCnt6.field.AggSize14Count / 14);
2267
2268 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2269 (TxAggCnt7.field.AggSize15Count / 15);
2270 pRalinkCounters->TransmittedAMPDUCount.u.LowPart +=
2271 (TxAggCnt7.field.AggSize16Count / 16);
2272 }
2273
2274}
2275
2276/*
2277 ========================================================================
2278
2279 Routine Description:
2280 Reset NIC from error
2281
2282 Arguments:
2283 Adapter Pointer to our adapter
2284
2285 Return Value:
2286 None
2287
2288 IRQL = PASSIVE_LEVEL
2289
2290 Note:
2291 Reset NIC from error state
2292
2293 ========================================================================
2294*/
2295void NICResetFromError(struct rt_rtmp_adapter *pAd)
2296{
2297 /* Reset BBP (according to alex, reset ASIC will force reset BBP */
2298 /* Therefore, skip the reset BBP */
2299 /* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x2); */
2300
2301 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1);
2302 /* Remove ASIC from reset state */
2303 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0);
2304
2305 NICInitializeAdapter(pAd, FALSE);
2306 NICInitAsicFromEEPROM(pAd);
2307
2308 /* Switch to current channel, since during reset process, the connection should remains on. */
2309 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
2310 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
2311}
2312
2313int NICLoadFirmware(struct rt_rtmp_adapter *pAd)
2314{
2315 int status = NDIS_STATUS_SUCCESS;
2316 if (pAd->chipOps.loadFirmware)
2317 status = pAd->chipOps.loadFirmware(pAd);
2318
2319 return status;
2320}
2321
2322/*
2323 ========================================================================
2324
2325 Routine Description:
2326 erase 8051 firmware image in MAC ASIC
2327
2328 Arguments:
2329 Adapter Pointer to our adapter
2330
2331 IRQL = PASSIVE_LEVEL
2332
2333 ========================================================================
2334*/
2335void NICEraseFirmware(struct rt_rtmp_adapter *pAd)
2336{
2337 if (pAd->chipOps.eraseFirmware)
2338 pAd->chipOps.eraseFirmware(pAd);
2339
2340} /* End of NICEraseFirmware */
2341
2342/*
2343 ========================================================================
2344
2345 Routine Description:
2346 Load Tx rate switching parameters
2347
2348 Arguments:
2349 Adapter Pointer to our adapter
2350
2351 Return Value:
2352 NDIS_STATUS_SUCCESS firmware image load ok
2353 NDIS_STATUS_FAILURE image not found
2354
2355 IRQL = PASSIVE_LEVEL
2356
2357 Rate Table Format:
2358 1. (B0: Valid Item number) (B1:Initial item from zero)
2359 2. Item Number(Dec) Mode(Hex) Current MCS(Dec) TrainUp(Dec) TrainDown(Dec)
2360
2361 ========================================================================
2362*/
2363int NICLoadRateSwitchingParams(struct rt_rtmp_adapter *pAd)
2364{
2365 return NDIS_STATUS_SUCCESS;
2366}
2367
2368/*
2369 ========================================================================
2370
2371 Routine Description:
2372 Compare two memory block
2373
2374 Arguments:
2375 pSrc1 Pointer to first memory address
2376 pSrc2 Pointer to second memory address
2377
2378 Return Value:
2379 0: memory is equal
2380 1: pSrc1 memory is larger
2381 2: pSrc2 memory is larger
2382
2383 IRQL = DISPATCH_LEVEL
2384
2385 Note:
2386
2387 ========================================================================
2388*/
2389unsigned long RTMPCompareMemory(void *pSrc1, void *pSrc2, unsigned long Length)
2390{
2391 u8 *pMem1;
2392 u8 *pMem2;
2393 unsigned long Index = 0;
2394
2395 pMem1 = (u8 *)pSrc1;
2396 pMem2 = (u8 *)pSrc2;
2397
2398 for (Index = 0; Index < Length; Index++) {
2399 if (pMem1[Index] > pMem2[Index])
2400 return (1);
2401 else if (pMem1[Index] < pMem2[Index])
2402 return (2);
2403 }
2404
2405 /* Equal */
2406 return (0);
2407}
2408
2409/*
2410 ========================================================================
2411
2412 Routine Description:
2413 Zero out memory block
2414
2415 Arguments:
2416 pSrc1 Pointer to memory address
2417 Length Size
2418
2419 Return Value:
2420 None
2421
2422 IRQL = PASSIVE_LEVEL
2423 IRQL = DISPATCH_LEVEL
2424
2425 Note:
2426
2427 ========================================================================
2428*/
2429void RTMPZeroMemory(void *pSrc, unsigned long Length)
2430{
2431 u8 *pMem;
2432 unsigned long Index = 0;
2433
2434 pMem = (u8 *)pSrc;
2435
2436 for (Index = 0; Index < Length; Index++) {
2437 pMem[Index] = 0x00;
2438 }
2439}
2440
2441/*
2442 ========================================================================
2443
2444 Routine Description:
2445 Copy data from memory block 1 to memory block 2
2446
2447 Arguments:
2448 pDest Pointer to destination memory address
2449 pSrc Pointer to source memory address
2450 Length Copy size
2451
2452 Return Value:
2453 None
2454
2455 IRQL = PASSIVE_LEVEL
2456 IRQL = DISPATCH_LEVEL
2457
2458 Note:
2459
2460 ========================================================================
2461*/
2462void RTMPMoveMemory(void *pDest, void *pSrc, unsigned long Length)
2463{
2464 u8 *pMem1;
2465 u8 *pMem2;
2466 u32 Index;
2467
2468 ASSERT((Length == 0) || (pDest && pSrc));
2469
2470 pMem1 = (u8 *)pDest;
2471 pMem2 = (u8 *)pSrc;
2472
2473 for (Index = 0; Index < Length; Index++) {
2474 pMem1[Index] = pMem2[Index];
2475 }
2476}
2477
2478/*
2479 ========================================================================
2480
2481 Routine Description:
2482 Initialize port configuration structure
2483
2484 Arguments:
2485 Adapter Pointer to our adapter
2486
2487 Return Value:
2488 None
2489
2490 IRQL = PASSIVE_LEVEL
2491
2492 Note:
2493
2494 ========================================================================
2495*/
2496void UserCfgInit(struct rt_rtmp_adapter *pAd)
2497{
2498 u32 key_index, bss_index;
2499
2500 DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit\n"));
2501
2502 /* */
2503 /* part I. initialize common configuration */
2504 /* */
2505#ifdef RTMP_MAC_USB
2506 pAd->BulkOutReq = 0;
2507
2508 pAd->BulkOutComplete = 0;
2509 pAd->BulkOutCompleteOther = 0;
2510 pAd->BulkOutCompleteCancel = 0;
2511 pAd->BulkInReq = 0;
2512 pAd->BulkInComplete = 0;
2513 pAd->BulkInCompleteFail = 0;
2514
2515 /*pAd->QuickTimerP = 100; */
2516 /*pAd->TurnAggrBulkInCount = 0; */
2517 pAd->bUsbTxBulkAggre = 0;
2518
2519 /* init as unused value to ensure driver will set to MCU once. */
2520 pAd->LedIndicatorStrength = 0xFF;
2521
2522 pAd->CommonCfg.MaxPktOneTxBulk = 2;
2523 pAd->CommonCfg.TxBulkFactor = 1;
2524 pAd->CommonCfg.RxBulkFactor = 1;
2525
2526 pAd->CommonCfg.TxPower = 100; /*mW */
2527
2528 NdisZeroMemory(&pAd->CommonCfg.IOTestParm,
2529 sizeof(pAd->CommonCfg.IOTestParm));
2530#endif /* RTMP_MAC_USB // */
2531
2532 for (key_index = 0; key_index < SHARE_KEY_NUM; key_index++) {
2533 for (bss_index = 0; bss_index < MAX_MBSSID_NUM; bss_index++) {
2534 pAd->SharedKey[bss_index][key_index].KeyLen = 0;
2535 pAd->SharedKey[bss_index][key_index].CipherAlg =
2536 CIPHER_NONE;
2537 }
2538 }
2539
2540 pAd->EepromAccess = FALSE;
2541
2542 pAd->Antenna.word = 0;
2543 pAd->CommonCfg.BBPCurrentBW = BW_20;
2544
2545 pAd->LedCntl.word = 0;
2546#ifdef RTMP_MAC_PCI
2547 pAd->LedIndicatorStrength = 0;
2548 pAd->RLnkCtrlOffset = 0;
2549 pAd->HostLnkCtrlOffset = 0;
2550 pAd->StaCfg.PSControl.field.EnableNewPS = TRUE;
2551 pAd->CheckDmaBusyCount = 0;
2552#endif /* RTMP_MAC_PCI // */
2553
2554 pAd->bAutoTxAgcA = FALSE; /* Default is OFF */
2555 pAd->bAutoTxAgcG = FALSE; /* Default is OFF */
2556 pAd->RfIcType = RFIC_2820;
2557
2558 /* Init timer for reset complete event */
2559 pAd->CommonCfg.CentralChannel = 1;
2560 pAd->bForcePrintTX = FALSE;
2561 pAd->bForcePrintRX = FALSE;
2562 pAd->bStaFifoTest = FALSE;
2563 pAd->bProtectionTest = FALSE;
2564 pAd->CommonCfg.Dsifs = 10; /* in units of usec */
2565 pAd->CommonCfg.TxPower = 100; /*mW */
2566 pAd->CommonCfg.TxPowerPercentage = 0xffffffff; /* AUTO */
2567 pAd->CommonCfg.TxPowerDefault = 0xffffffff; /* AUTO */
2568 pAd->CommonCfg.TxPreamble = Rt802_11PreambleAuto; /* use Long preamble on TX by defaut */
2569 pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
2570 pAd->CommonCfg.RtsThreshold = 2347;
2571 pAd->CommonCfg.FragmentThreshold = 2346;
2572 pAd->CommonCfg.UseBGProtection = 0; /* 0: AUTO */
2573 pAd->CommonCfg.bEnableTxBurst = TRUE; /*0; */
2574 pAd->CommonCfg.PhyMode = 0xff; /* unknown */
2575 pAd->CommonCfg.BandState = UNKNOWN_BAND;
2576 pAd->CommonCfg.RadarDetect.CSPeriod = 10;
2577 pAd->CommonCfg.RadarDetect.CSCount = 0;
2578 pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
2579
2580 pAd->CommonCfg.RadarDetect.ChMovingTime = 65;
2581 pAd->CommonCfg.RadarDetect.LongPulseRadarTh = 3;
2582 pAd->CommonCfg.bAPSDCapable = FALSE;
2583 pAd->CommonCfg.bNeedSendTriggerFrame = FALSE;
2584 pAd->CommonCfg.TriggerTimerCount = 0;
2585 pAd->CommonCfg.bAPSDForcePowerSave = FALSE;
2586 pAd->CommonCfg.bCountryFlag = FALSE;
2587 pAd->CommonCfg.TxStream = 0;
2588 pAd->CommonCfg.RxStream = 0;
2589
2590 NdisZeroMemory(&pAd->BeaconTxWI, sizeof(pAd->BeaconTxWI));
2591
2592 NdisZeroMemory(&pAd->CommonCfg.HtCapability,
2593 sizeof(pAd->CommonCfg.HtCapability));
2594 pAd->HTCEnable = FALSE;
2595 pAd->bBroadComHT = FALSE;
2596 pAd->CommonCfg.bRdg = FALSE;
2597
2598 NdisZeroMemory(&pAd->CommonCfg.AddHTInfo,
2599 sizeof(pAd->CommonCfg.AddHTInfo));
2600 pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
2601 pAd->CommonCfg.BACapability.field.MpduDensity = 0;
2602 pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
2603 pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64; /*32; */
2604 pAd->CommonCfg.BACapability.field.TxBAWinLimit = 64; /*32; */
2605 DBGPRINT(RT_DEBUG_TRACE,
2606 ("--> UserCfgInit. BACapability = 0x%x\n",
2607 pAd->CommonCfg.BACapability.word));
2608
2609 pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
2610 BATableInit(pAd, &pAd->BATable);
2611
2612 pAd->CommonCfg.bExtChannelSwitchAnnouncement = 1;
2613 pAd->CommonCfg.bHTProtect = 1;
2614 pAd->CommonCfg.bMIMOPSEnable = TRUE;
2615 /*2008/11/05:KH add to support Antenna power-saving of AP<-- */
2616 pAd->CommonCfg.bGreenAPEnable = FALSE;
2617 /*2008/11/05:KH add to support Antenna power-saving of AP--> */
2618 pAd->CommonCfg.bBADecline = FALSE;
2619 pAd->CommonCfg.bDisableReordering = FALSE;
2620
2621 if (pAd->MACVersion == 0x28720200) {
2622 pAd->CommonCfg.TxBASize = 13; /*by Jerry recommend */
2623 } else {
2624 pAd->CommonCfg.TxBASize = 7;
2625 }
2626
2627 pAd->CommonCfg.REGBACapability.word = pAd->CommonCfg.BACapability.word;
2628
2629 /*pAd->CommonCfg.HTPhyMode.field.BW = BW_20; */
2630 /*pAd->CommonCfg.HTPhyMode.field.MCS = MCS_AUTO; */
2631 /*pAd->CommonCfg.HTPhyMode.field.ShortGI = GI_800; */
2632 /*pAd->CommonCfg.HTPhyMode.field.STBC = STBC_NONE; */
2633 pAd->CommonCfg.TxRate = RATE_6;
2634
2635 pAd->CommonCfg.MlmeTransmit.field.MCS = MCS_RATE_6;
2636 pAd->CommonCfg.MlmeTransmit.field.BW = BW_20;
2637 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
2638
2639 pAd->CommonCfg.BeaconPeriod = 100; /* in mSec */
2640
2641 /* */
2642 /* part II. initialize STA specific configuration */
2643 /* */
2644 {
2645 RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_DIRECT);
2646 RX_FILTER_CLEAR_FLAG(pAd, fRX_FILTER_ACCEPT_MULTICAST);
2647 RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_BROADCAST);
2648 RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_ALL_MULTICAST);
2649
2650 pAd->StaCfg.Psm = PWR_ACTIVE;
2651
2652 pAd->StaCfg.OrigWepStatus = Ndis802_11EncryptionDisabled;
2653 pAd->StaCfg.PairCipher = Ndis802_11EncryptionDisabled;
2654 pAd->StaCfg.GroupCipher = Ndis802_11EncryptionDisabled;
2655 pAd->StaCfg.bMixCipher = FALSE;
2656 pAd->StaCfg.DefaultKeyId = 0;
2657
2658 /* 802.1x port control */
2659 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
2660 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2661 pAd->StaCfg.LastMicErrorTime = 0;
2662 pAd->StaCfg.MicErrCnt = 0;
2663 pAd->StaCfg.bBlockAssoc = FALSE;
2664 pAd->StaCfg.WpaState = SS_NOTUSE;
2665
2666 pAd->CommonCfg.NdisRadioStateOff = FALSE; /* New to support microsoft disable radio with OID command */
2667
2668 pAd->StaCfg.RssiTrigger = 0;
2669 NdisZeroMemory(&pAd->StaCfg.RssiSample, sizeof(struct rt_rssi_sample));
2670 pAd->StaCfg.RssiTriggerMode =
2671 RSSI_TRIGGERED_UPON_BELOW_THRESHOLD;
2672 pAd->StaCfg.AtimWin = 0;
2673 pAd->StaCfg.DefaultListenCount = 3; /*default listen count; */
2674 pAd->StaCfg.BssType = BSS_INFRA; /* BSS_INFRA or BSS_ADHOC or BSS_MONITOR */
2675 pAd->StaCfg.bScanReqIsFromWebUI = FALSE;
2676 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
2677 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WAKEUP_NOW);
2678
2679 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2680 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2681 }
2682
2683#ifdef PCIE_PS_SUPPORT
2684 pAd->brt30xxBanMcuCmd = FALSE;
2685 pAd->b3090ESpecialChip = FALSE;
2686/*KH Debug:the following must be removed */
2687 pAd->StaCfg.PSControl.field.rt30xxPowerMode = 3;
2688 pAd->StaCfg.PSControl.field.rt30xxForceASPMTest = 0;
2689 pAd->StaCfg.PSControl.field.rt30xxFollowHostASPM = 1;
2690#endif /* PCIE_PS_SUPPORT // */
2691
2692 /* global variables mXXXX used in MAC protocol state machines */
2693 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
2694 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
2695 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
2696
2697 /* PHY specification */
2698 pAd->CommonCfg.PhyMode = PHY_11BG_MIXED; /* default PHY mode */
2699 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); /* CCK use long preamble */
2700
2701 {
2702 /* user desired power mode */
2703 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
2704 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
2705 pAd->StaCfg.bWindowsACCAMEnable = FALSE;
2706
2707 RTMPInitTimer(pAd, &pAd->StaCfg.StaQuickResponeForRateUpTimer,
2708 GET_TIMER_FUNCTION(StaQuickResponeForRateUpExec),
2709 pAd, FALSE);
2710 pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE;
2711
2712 /* Patch for Ndtest */
2713 pAd->StaCfg.ScanCnt = 0;
2714
2715 pAd->StaCfg.bHwRadio = TRUE; /* Default Hardware Radio status is On */
2716 pAd->StaCfg.bSwRadio = TRUE; /* Default Software Radio status is On */
2717 pAd->StaCfg.bRadio = TRUE; /* bHwRadio && bSwRadio */
2718 pAd->StaCfg.bHardwareRadio = FALSE; /* Default is OFF */
2719 pAd->StaCfg.bShowHiddenSSID = FALSE; /* Default no show */
2720
2721 /* Nitro mode control */
2722 pAd->StaCfg.bAutoReconnect = TRUE;
2723
2724 /* Save the init time as last scan time, the system should do scan after 2 seconds. */
2725 /* This patch is for driver wake up from standby mode, system will do scan right away. */
2726 NdisGetSystemUpTime(&pAd->StaCfg.LastScanTime);
2727 if (pAd->StaCfg.LastScanTime > 10 * OS_HZ)
2728 pAd->StaCfg.LastScanTime -= (10 * OS_HZ);
2729
2730 NdisZeroMemory(pAd->nickname, IW_ESSID_MAX_SIZE + 1);
2731#ifdef RTMP_MAC_PCI
2732 sprintf((char *)pAd->nickname, "RT2860STA");
2733#endif /* RTMP_MAC_PCI // */
2734#ifdef RTMP_MAC_USB
2735 sprintf((char *)pAd->nickname, "RT2870STA");
2736#endif /* RTMP_MAC_USB // */
2737 RTMPInitTimer(pAd, &pAd->StaCfg.WpaDisassocAndBlockAssocTimer,
2738 GET_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc),
2739 pAd, FALSE);
2740 pAd->StaCfg.IEEE8021X = FALSE;
2741 pAd->StaCfg.IEEE8021x_required_keys = FALSE;
2742 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
2743 pAd->StaCfg.bRSN_IE_FromWpaSupplicant = FALSE;
2744 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
2745
2746 NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
2747
2748 pAd->StaCfg.bAutoConnectByBssid = FALSE;
2749 pAd->StaCfg.BeaconLostTime = BEACON_LOST_TIME;
2750 NdisZeroMemory(pAd->StaCfg.WpaPassPhrase, 64);
2751 pAd->StaCfg.WpaPassPhraseLen = 0;
2752 pAd->StaCfg.bAutoRoaming = FALSE;
2753 pAd->StaCfg.bForceTxBurst = FALSE;
2754 }
2755
2756 /* Default for extra information is not valid */
2757 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2758
2759 /* Default Config change flag */
2760 pAd->bConfigChanged = FALSE;
2761
2762 /* */
2763 /* part III. AP configurations */
2764 /* */
2765
2766 /* */
2767 /* part IV. others */
2768 /* */
2769 /* dynamic BBP R66:sensibity tuning to overcome background noise */
2770 pAd->BbpTuning.bEnable = TRUE;
2771 pAd->BbpTuning.FalseCcaLowerThreshold = 100;
2772 pAd->BbpTuning.FalseCcaUpperThreshold = 512;
2773 pAd->BbpTuning.R66Delta = 4;
2774 pAd->Mlme.bEnableAutoAntennaCheck = TRUE;
2775
2776 /* */
2777 /* Also initial R66CurrentValue, RTUSBResumeMsduTransmission might use this value. */
2778 /* if not initial this value, the default value will be 0. */
2779 /* */
2780 pAd->BbpTuning.R66CurrentValue = 0x38;
2781
2782 pAd->Bbp94 = BBPR94_DEFAULT;
2783 pAd->BbpForCCK = FALSE;
2784
2785 /* Default is FALSE for test bit 1 */
2786 /*pAd->bTest1 = FALSE; */
2787
2788 /* initialize MAC table and allocate spin lock */
2789 NdisZeroMemory(&pAd->MacTab, sizeof(struct rt_mac_table));
2790 InitializeQueueHeader(&pAd->MacTab.McastPsQueue);
2791 NdisAllocateSpinLock(&pAd->MacTabLock);
2792
2793 /*RTMPInitTimer(pAd, &pAd->RECBATimer, RECBATimerTimeout, pAd, TRUE); */
2794 /*RTMPSetTimer(&pAd->RECBATimer, REORDER_EXEC_INTV); */
2795
2796 pAd->CommonCfg.bWiFiTest = FALSE;
2797#ifdef RTMP_MAC_PCI
2798 pAd->bPCIclkOff = FALSE;
2799#endif /* RTMP_MAC_PCI // */
2800
2801 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
2802 DBGPRINT(RT_DEBUG_TRACE, ("<-- UserCfgInit\n"));
2803}
2804
2805/* IRQL = PASSIVE_LEVEL */
2806/* */
2807/* FUNCTION: AtoH(char *, u8 *, int) */
2808/* */
2809/* PURPOSE: Converts ascii string to network order hex */
2810/* */
2811/* PARAMETERS: */
2812/* src - pointer to input ascii string */
2813/* dest - pointer to output hex */
2814/* destlen - size of dest */
2815/* */
2816/* COMMENTS: */
2817/* */
2818/* 2 ascii bytes make a hex byte so must put 1st ascii byte of pair */
2819/* into upper nibble and 2nd ascii byte of pair into lower nibble. */
2820/* */
2821/* IRQL = PASSIVE_LEVEL */
2822
2823void AtoH(char *src, u8 *dest, int destlen)
2824{
2825 char *srcptr;
2826 u8 *destTemp;
2827
2828 srcptr = src;
2829 destTemp = (u8 *)dest;
2830
2831 while (destlen--) {
2832 *destTemp = hex_to_bin(*srcptr++) << 4; /* Put 1st ascii byte in upper nibble. */
2833 *destTemp += hex_to_bin(*srcptr++); /* Add 2nd ascii byte to above. */
2834 destTemp++;
2835 }
2836}
2837
2838/*+++Mark by shiang, not use now, need to remove after confirm */
2839/*---Mark by shiang, not use now, need to remove after confirm */
2840
2841/*
2842 ========================================================================
2843
2844 Routine Description:
2845 Init timer objects
2846
2847 Arguments:
2848 pAd Pointer to our adapter
2849 pTimer Timer structure
2850 pTimerFunc Function to execute when timer expired
2851 Repeat Ture for period timer
2852
2853 Return Value:
2854 None
2855
2856 Note:
2857
2858 ========================================================================
2859*/
2860void RTMPInitTimer(struct rt_rtmp_adapter *pAd,
2861 struct rt_ralink_timer *pTimer,
2862 void *pTimerFunc, void *pData, IN BOOLEAN Repeat)
2863{
2864 /* */
2865 /* Set Valid to TRUE for later used. */
2866 /* It will crash if we cancel a timer or set a timer */
2867 /* that we haven't initialize before. */
2868 /* */
2869 pTimer->Valid = TRUE;
2870
2871 pTimer->PeriodicType = Repeat;
2872 pTimer->State = FALSE;
2873 pTimer->cookie = (unsigned long)pData;
2874
2875#ifdef RTMP_TIMER_TASK_SUPPORT
2876 pTimer->pAd = pAd;
2877#endif /* RTMP_TIMER_TASK_SUPPORT // */
2878
2879 RTMP_OS_Init_Timer(pAd, &pTimer->TimerObj, pTimerFunc, (void *)pTimer);
2880}
2881
2882/*
2883 ========================================================================
2884
2885 Routine Description:
2886 Init timer objects
2887
2888 Arguments:
2889 pTimer Timer structure
2890 Value Timer value in milliseconds
2891
2892 Return Value:
2893 None
2894
2895 Note:
2896 To use this routine, must call RTMPInitTimer before.
2897
2898 ========================================================================
2899*/
2900void RTMPSetTimer(struct rt_ralink_timer *pTimer, unsigned long Value)
2901{
2902 if (pTimer->Valid) {
2903 pTimer->TimerValue = Value;
2904 pTimer->State = FALSE;
2905 if (pTimer->PeriodicType == TRUE) {
2906 pTimer->Repeat = TRUE;
2907 RTMP_SetPeriodicTimer(&pTimer->TimerObj, Value);
2908 } else {
2909 pTimer->Repeat = FALSE;
2910 RTMP_OS_Add_Timer(&pTimer->TimerObj, Value);
2911 }
2912 } else {
2913 DBGPRINT_ERR("RTMPSetTimer failed, Timer hasn't been initialize!\n");
2914 }
2915}
2916
2917/*
2918 ========================================================================
2919
2920 Routine Description:
2921 Init timer objects
2922
2923 Arguments:
2924 pTimer Timer structure
2925 Value Timer value in milliseconds
2926
2927 Return Value:
2928 None
2929
2930 Note:
2931 To use this routine, must call RTMPInitTimer before.
2932
2933 ========================================================================
2934*/
2935void RTMPModTimer(struct rt_ralink_timer *pTimer, unsigned long Value)
2936{
2937 BOOLEAN Cancel;
2938
2939 if (pTimer->Valid) {
2940 pTimer->TimerValue = Value;
2941 pTimer->State = FALSE;
2942 if (pTimer->PeriodicType == TRUE) {
2943 RTMPCancelTimer(pTimer, &Cancel);
2944 RTMPSetTimer(pTimer, Value);
2945 } else {
2946 RTMP_OS_Mod_Timer(&pTimer->TimerObj, Value);
2947 }
2948 } else {
2949 DBGPRINT_ERR("RTMPModTimer failed, Timer hasn't been initialize!\n");
2950 }
2951}
2952
2953/*
2954 ========================================================================
2955
2956 Routine Description:
2957 Cancel timer objects
2958
2959 Arguments:
2960 Adapter Pointer to our adapter
2961
2962 Return Value:
2963 None
2964
2965 IRQL = PASSIVE_LEVEL
2966 IRQL = DISPATCH_LEVEL
2967
2968 Note:
2969 1.) To use this routine, must call RTMPInitTimer before.
2970 2.) Reset NIC to initial state AS IS system boot up time.
2971
2972 ========================================================================
2973*/
2974void RTMPCancelTimer(struct rt_ralink_timer *pTimer, OUT BOOLEAN * pCancelled)
2975{
2976 if (pTimer->Valid) {
2977 if (pTimer->State == FALSE)
2978 pTimer->Repeat = FALSE;
2979
2980 RTMP_OS_Del_Timer(&pTimer->TimerObj, pCancelled);
2981
2982 if (*pCancelled == TRUE)
2983 pTimer->State = TRUE;
2984
2985#ifdef RTMP_TIMER_TASK_SUPPORT
2986 /* We need to go-through the TimerQ to findout this timer handler and remove it if */
2987 /* it's still waiting for execution. */
2988 RtmpTimerQRemove(pTimer->pAd, pTimer);
2989#endif /* RTMP_TIMER_TASK_SUPPORT // */
2990 } else {
2991 DBGPRINT_ERR("RTMPCancelTimer failed, Timer hasn't been initialize!\n");
2992 }
2993}
2994
2995/*
2996 ========================================================================
2997
2998 Routine Description:
2999 Set LED Status
3000
3001 Arguments:
3002 pAd Pointer to our adapter
3003 Status LED Status
3004
3005 Return Value:
3006 None
3007
3008 IRQL = PASSIVE_LEVEL
3009 IRQL = DISPATCH_LEVEL
3010
3011 Note:
3012
3013 ========================================================================
3014*/
3015void RTMPSetLED(struct rt_rtmp_adapter *pAd, u8 Status)
3016{
3017 /*unsigned long data; */
3018 u8 HighByte = 0;
3019 u8 LowByte;
3020
3021 LowByte = pAd->LedCntl.field.LedMode & 0x7f;
3022 switch (Status) {
3023 case LED_LINK_DOWN:
3024 HighByte = 0x20;
3025 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3026 pAd->LedIndicatorStrength = 0;
3027 break;
3028 case LED_LINK_UP:
3029 if (pAd->CommonCfg.Channel > 14)
3030 HighByte = 0xa0;
3031 else
3032 HighByte = 0x60;
3033 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3034 break;
3035 case LED_RADIO_ON:
3036 HighByte = 0x20;
3037 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3038 break;
3039 case LED_HALT:
3040 LowByte = 0; /* Driver sets MAC register and MAC controls LED */
3041 case LED_RADIO_OFF:
3042 HighByte = 0;
3043 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3044 break;
3045 case LED_WPS:
3046 HighByte = 0x10;
3047 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3048 break;
3049 case LED_ON_SITE_SURVEY:
3050 HighByte = 0x08;
3051 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3052 break;
3053 case LED_POWER_UP:
3054 HighByte = 0x04;
3055 AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
3056 break;
3057 default:
3058 DBGPRINT(RT_DEBUG_WARN,
3059 ("RTMPSetLED::Unknown Status %d\n", Status));
3060 break;
3061 }
3062
3063 /* */
3064 /* Keep LED status for LED SiteSurvey mode. */
3065 /* After SiteSurvey, we will set the LED mode to previous status. */
3066 /* */
3067 if ((Status != LED_ON_SITE_SURVEY) && (Status != LED_POWER_UP))
3068 pAd->LedStatus = Status;
3069
3070 DBGPRINT(RT_DEBUG_TRACE,
3071 ("RTMPSetLED::Mode=%d,HighByte=0x%02x,LowByte=0x%02x\n",
3072 pAd->LedCntl.field.LedMode, HighByte, LowByte));
3073}
3074
3075/*
3076 ========================================================================
3077
3078 Routine Description:
3079 Set LED Signal Strength
3080
3081 Arguments:
3082 pAd Pointer to our adapter
3083 Dbm Signal Strength
3084
3085 Return Value:
3086 None
3087
3088 IRQL = PASSIVE_LEVEL
3089
3090 Note:
3091 Can be run on any IRQL level.
3092
3093 According to Microsoft Zero Config Wireless Signal Strength definition as belows.
3094 <= -90 No Signal
3095 <= -81 Very Low
3096 <= -71 Low
3097 <= -67 Good
3098 <= -57 Very Good
3099 > -57 Excellent
3100 ========================================================================
3101*/
3102void RTMPSetSignalLED(struct rt_rtmp_adapter *pAd, IN NDIS_802_11_RSSI Dbm)
3103{
3104 u8 nLed = 0;
3105
3106 if (pAd->LedCntl.field.LedMode == LED_MODE_SIGNAL_STREGTH) {
3107 if (Dbm <= -90)
3108 nLed = 0;
3109 else if (Dbm <= -81)
3110 nLed = 1;
3111 else if (Dbm <= -71)
3112 nLed = 3;
3113 else if (Dbm <= -67)
3114 nLed = 7;
3115 else if (Dbm <= -57)
3116 nLed = 15;
3117 else
3118 nLed = 31;
3119
3120 /* */
3121 /* Update Signal Strength to firmware if changed. */
3122 /* */
3123 if (pAd->LedIndicatorStrength != nLed) {
3124 AsicSendCommandToMcu(pAd, 0x51, 0xff, nLed,
3125 pAd->LedCntl.field.Polarity);
3126 pAd->LedIndicatorStrength = nLed;
3127 }
3128 }
3129}
3130
3131/*
3132 ========================================================================
3133
3134 Routine Description:
3135 Enable RX
3136
3137 Arguments:
3138 pAd Pointer to our adapter
3139
3140 Return Value:
3141 None
3142
3143 IRQL <= DISPATCH_LEVEL
3144
3145 Note:
3146 Before Enable RX, make sure you have enabled Interrupt.
3147 ========================================================================
3148*/
3149void RTMPEnableRxTx(struct rt_rtmp_adapter *pAd)
3150{
3151/* WPDMA_GLO_CFG_STRUC GloCfg; */
3152/* unsigned long i = 0; */
3153 u32 rx_filter_flag;
3154
3155 DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPEnableRxTx\n"));
3156
3157 /* Enable Rx DMA. */
3158 RT28XXDMAEnable(pAd);
3159
3160 /* enable RX of MAC block */
3161 if (pAd->OpMode == OPMODE_AP) {
3162 rx_filter_flag = APNORMAL;
3163
3164 RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag); /* enable RX of DMA block */
3165 } else {
3166 if (pAd->CommonCfg.PSPXlink)
3167 rx_filter_flag = PSPXLINK;
3168 else
3169 rx_filter_flag = STANORMAL; /* Station not drop control frame will fail WiFi Certification. */
3170 RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag);
3171 }
3172
3173 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xc);
3174 DBGPRINT(RT_DEBUG_TRACE, ("<== RTMPEnableRxTx\n"));
3175}
3176
3177/*+++Add by shiang, move from os/linux/rt_main_dev.c */
3178void CfgInitHook(struct rt_rtmp_adapter *pAd)
3179{
3180 pAd->bBroadComHT = TRUE;
3181}
3182
3183int rt28xx_init(struct rt_rtmp_adapter *pAd,
3184 char *pDefaultMac, char *pHostName)
3185{
3186 u32 index;
3187 u8 TmpPhy;
3188 int Status;
3189 u32 MacCsr0 = 0;
3190
3191#ifdef RTMP_MAC_PCI
3192 {
3193 /* If dirver doesn't wake up firmware here, */
3194 /* NICLoadFirmware will hang forever when interface is up again. */
3195 /* RT2860 PCI */
3196 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) &&
3197 OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
3198 AUTO_WAKEUP_STRUC AutoWakeupCfg;
3199 AsicForceWakeup(pAd, TRUE);
3200 AutoWakeupCfg.word = 0;
3201 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG,
3202 AutoWakeupCfg.word);
3203 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
3204 }
3205 }
3206#endif /* RTMP_MAC_PCI // */
3207
3208 /* reset Adapter flags */
3209 RTMP_CLEAR_FLAGS(pAd);
3210
3211 /* Init BssTab & ChannelInfo tabbles for auto channel select. */
3212
3213 /* Allocate BA Reordering memory */
3214 ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
3215
3216 /* Make sure MAC gets ready. */
3217 index = 0;
3218 do {
3219 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
3220 pAd->MACVersion = MacCsr0;
3221
3222 if ((pAd->MACVersion != 0x00)
3223 && (pAd->MACVersion != 0xFFFFFFFF))
3224 break;
3225
3226 RTMPusecDelay(10);
3227 } while (index++ < 100);
3228 DBGPRINT(RT_DEBUG_TRACE,
3229 ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
3230
3231#ifdef RTMP_MAC_PCI
3232#ifdef PCIE_PS_SUPPORT
3233 /*Iverson patch PCIE L1 issue to make sure that driver can be read,write ,BBP and RF register at pcie L.1 level */
3234 if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
3235 && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
3236 RTMP_IO_READ32(pAd, AUX_CTRL, &MacCsr0);
3237 MacCsr0 |= 0x402;
3238 RTMP_IO_WRITE32(pAd, AUX_CTRL, MacCsr0);
3239 DBGPRINT(RT_DEBUG_TRACE, ("AUX_CTRL = 0x%x\n", MacCsr0));
3240 }
3241#endif /* PCIE_PS_SUPPORT // */
3242
3243 /* To fix driver disable/enable hang issue when radio off */
3244 RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x2);
3245#endif /* RTMP_MAC_PCI // */
3246
3247 /* Disable DMA */
3248 RT28XXDMADisable(pAd);
3249
3250 /* Load 8051 firmware */
3251 Status = NICLoadFirmware(pAd);
3252 if (Status != NDIS_STATUS_SUCCESS) {
3253 DBGPRINT_ERR("NICLoadFirmware failed, Status[=0x%08x]\n", Status);
3254 goto err1;
3255 }
3256
3257 NICLoadRateSwitchingParams(pAd);
3258
3259 /* Disable interrupts here which is as soon as possible */
3260 /* This statement should never be true. We might consider to remove it later */
3261#ifdef RTMP_MAC_PCI
3262 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE)) {
3263 RTMP_ASIC_INTERRUPT_DISABLE(pAd);
3264 }
3265#endif /* RTMP_MAC_PCI // */
3266
3267 Status = RTMPAllocTxRxRingMemory(pAd);
3268 if (Status != NDIS_STATUS_SUCCESS) {
3269 DBGPRINT_ERR("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status);
3270 goto err1;
3271 }
3272
3273 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
3274
3275 /* initialize MLME */
3276 /* */
3277
3278 Status = RtmpMgmtTaskInit(pAd);
3279 if (Status != NDIS_STATUS_SUCCESS)
3280 goto err2;
3281
3282 Status = MlmeInit(pAd);
3283 if (Status != NDIS_STATUS_SUCCESS) {
3284 DBGPRINT_ERR("MlmeInit failed, Status[=0x%08x]\n", Status);
3285 goto err2;
3286 }
3287 /* Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default */
3288 /* */
3289 UserCfgInit(pAd);
3290 Status = RtmpNetTaskInit(pAd);
3291 if (Status != NDIS_STATUS_SUCCESS)
3292 goto err3;
3293
3294/* COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr); */
3295/* pAd->bForcePrintTX = TRUE; */
3296
3297 CfgInitHook(pAd);
3298
3299 NdisAllocateSpinLock(&pAd->MacTabLock);
3300
3301 MeasureReqTabInit(pAd);
3302 TpcReqTabInit(pAd);
3303
3304 /* */
3305 /* Init the hardware, we need to init asic before read registry, otherwise mac register will be reset */
3306 /* */
3307 Status = NICInitializeAdapter(pAd, TRUE);
3308 if (Status != NDIS_STATUS_SUCCESS) {
3309 DBGPRINT_ERR("NICInitializeAdapter failed, Status[=0x%08x]\n", Status);
3310 if (Status != NDIS_STATUS_SUCCESS)
3311 goto err3;
3312 }
3313
3314 DBGPRINT(RT_DEBUG_OFF, ("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode));
3315
3316#ifdef RTMP_MAC_USB
3317 pAd->CommonCfg.bMultipleIRP = FALSE;
3318
3319 if (pAd->CommonCfg.bMultipleIRP)
3320 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
3321 else
3322 pAd->CommonCfg.NumOfBulkInIRP = 1;
3323#endif /* RTMP_MAC_USB // */
3324
3325 /*Init Ba Capability parameters. */
3326/* RT28XX_BA_INIT(pAd); */
3327 pAd->CommonCfg.DesiredHtPhy.MpduDensity =
3328 (u8)pAd->CommonCfg.BACapability.field.MpduDensity;
3329 pAd->CommonCfg.DesiredHtPhy.AmsduEnable =
3330 (u16)pAd->CommonCfg.BACapability.field.AmsduEnable;
3331 pAd->CommonCfg.DesiredHtPhy.AmsduSize =
3332 (u16)pAd->CommonCfg.BACapability.field.AmsduSize;
3333 pAd->CommonCfg.DesiredHtPhy.MimoPs =
3334 (u16)pAd->CommonCfg.BACapability.field.MMPSmode;
3335 /* UPdata to HT IE */
3336 pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs =
3337 (u16)pAd->CommonCfg.BACapability.field.MMPSmode;
3338 pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize =
3339 (u16)pAd->CommonCfg.BACapability.field.AmsduSize;
3340 pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity =
3341 (u8)pAd->CommonCfg.BACapability.field.MpduDensity;
3342
3343 /* after reading Registry, we now know if in AP mode or STA mode */
3344
3345 /* Load 8051 firmware; crash when FW image not existent */
3346 /* Status = NICLoadFirmware(pAd); */
3347 /* if (Status != NDIS_STATUS_SUCCESS) */
3348 /* break; */
3349
3350 DBGPRINT(RT_DEBUG_OFF, ("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode));
3351
3352 /* We should read EEPROM for all cases. rt2860b */
3353 NICReadEEPROMParameters(pAd, (u8 *)pDefaultMac);
3354
3355 DBGPRINT(RT_DEBUG_OFF, ("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode));
3356
3357 NICInitAsicFromEEPROM(pAd); /*rt2860b */
3358
3359 /* Set PHY to appropriate mode */
3360 TmpPhy = pAd->CommonCfg.PhyMode;
3361 pAd->CommonCfg.PhyMode = 0xff;
3362 RTMPSetPhyMode(pAd, TmpPhy);
3363 SetCommonHT(pAd);
3364
3365 /* No valid channels. */
3366 if (pAd->ChannelListNum == 0) {
3367 DBGPRINT(RT_DEBUG_ERROR,
3368 ("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n"));
3369 goto err4;
3370 }
3371
3372 DBGPRINT(RT_DEBUG_OFF,
3373 ("MCS Set = %02x %02x %02x %02x %02x\n",
3374 pAd->CommonCfg.HtCapability.MCSSet[0],
3375 pAd->CommonCfg.HtCapability.MCSSet[1],
3376 pAd->CommonCfg.HtCapability.MCSSet[2],
3377 pAd->CommonCfg.HtCapability.MCSSet[3],
3378 pAd->CommonCfg.HtCapability.MCSSet[4]));
3379
3380#ifdef RTMP_RF_RW_SUPPORT
3381 /*Init RT30xx RFRegisters after read RFIC type from EEPROM */
3382 NICInitRFRegisters(pAd);
3383#endif /* RTMP_RF_RW_SUPPORT // */
3384
3385/* APInitialize(pAd); */
3386
3387 /* */
3388 /* Initialize RF register to default value */
3389 /* */
3390 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
3391 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
3392
3393 /* 8051 firmware require the signal during booting time. */
3394 /*2008/11/28:KH marked the following codes to patch Frequency offset bug */
3395 /*AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00); */
3396
3397 if (pAd && (Status != NDIS_STATUS_SUCCESS)) {
3398 /* */
3399 /* Undo everything if it failed */
3400 /* */
3401 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
3402/* NdisMDeregisterInterrupt(&pAd->Interrupt); */
3403 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
3404 }
3405/* RTMPFreeAdapter(pAd); // we will free it in disconnect() */
3406 } else if (pAd) {
3407 /* Microsoft HCT require driver send a disconnect event after driver initialization. */
3408 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
3409/* pAd->IndicateMediaState = NdisMediaStateDisconnected; */
3410 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
3411
3412 DBGPRINT(RT_DEBUG_TRACE,
3413 ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
3414
3415#ifdef RTMP_MAC_USB
3416 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
3417 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
3418
3419 /* */
3420 /* Support multiple BulkIn IRP, */
3421 /* the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1. */
3422 /* */
3423 for (index = 0; index < pAd->CommonCfg.NumOfBulkInIRP; index++) {
3424 RTUSBBulkReceive(pAd);
3425 DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n"));
3426 }
3427#endif /* RTMP_MAC_USB // */
3428 } /* end of else */
3429
3430 /* Set up the Mac address */
3431 RtmpOSNetDevAddrSet(pAd->net_dev, &pAd->CurrentAddress[0]);
3432
3433 DBGPRINT_S(Status, ("<==== rt28xx_init, Status=%x\n", Status));
3434
3435 return TRUE;
3436
3437err4:
3438err3:
3439 MlmeHalt(pAd);
3440err2:
3441 RTMPFreeTxRxRingMemory(pAd);
3442err1:
3443
3444 os_free_mem(pAd, pAd->mpdu_blk_pool.mem); /* free BA pool */
3445
3446 /* shall not set priv to NULL here because the priv didn't been free yet. */
3447 /*net_dev->ml_priv = 0; */
3448#ifdef ST
3449err0:
3450#endif /* ST // */
3451
3452 DBGPRINT(RT_DEBUG_ERROR, ("rt28xx Initialized fail!\n"));
3453 return FALSE;
3454}
3455
3456/*---Add by shiang, move from os/linux/rt_main_dev.c */
3457
3458static int RtmpChipOpsRegister(struct rt_rtmp_adapter *pAd, int infType)
3459{
3460 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
3461 int status;
3462
3463 memset(pChipOps, 0, sizeof(struct rt_rtmp_chip_op));
3464
3465 /* set eeprom related hook functions */
3466 status = RtmpChipOpsEepromHook(pAd, infType);
3467
3468 /* set mcu related hook functions */
3469 switch (infType) {
3470#ifdef RTMP_PCI_SUPPORT
3471 case RTMP_DEV_INF_PCI:
3472 pChipOps->loadFirmware = RtmpAsicLoadFirmware;
3473 pChipOps->eraseFirmware = RtmpAsicEraseFirmware;
3474 pChipOps->sendCommandToMcu = RtmpAsicSendCommandToMcu;
3475 break;
3476#endif /* RTMP_PCI_SUPPORT // */
3477#ifdef RTMP_USB_SUPPORT
3478 case RTMP_DEV_INF_USB:
3479 pChipOps->loadFirmware = RtmpAsicLoadFirmware;
3480 pChipOps->sendCommandToMcu = RtmpAsicSendCommandToMcu;
3481 break;
3482#endif /* RTMP_USB_SUPPORT // */
3483 default:
3484 break;
3485 }
3486
3487 return status;
3488}
3489
3490int RtmpRaDevCtrlInit(struct rt_rtmp_adapter *pAd, IN RTMP_INF_TYPE infType)
3491{
3492 /*void *handle; */
3493
3494 /* Assign the interface type. We need use it when do register/EEPROM access. */
3495 pAd->infType = infType;
3496
3497 pAd->OpMode = OPMODE_STA;
3498 DBGPRINT(RT_DEBUG_TRACE,
3499 ("STA Driver version-%s\n", STA_DRIVER_VERSION));
3500
3501#ifdef RTMP_MAC_USB
3502 sema_init(&(pAd->UsbVendorReq_semaphore), 1);
3503 os_alloc_mem(pAd, (u8 **) & pAd->UsbVendorReqBuf,
3504 MAX_PARAM_BUFFER_SIZE - 1);
3505 if (pAd->UsbVendorReqBuf == NULL) {
3506 DBGPRINT(RT_DEBUG_ERROR,
3507 ("Allocate vendor request temp buffer failed!\n"));
3508 return FALSE;
3509 }
3510#endif /* RTMP_MAC_USB // */
3511
3512 RtmpChipOpsRegister(pAd, infType);
3513
3514 return 0;
3515}
3516
3517BOOLEAN RtmpRaDevCtrlExit(struct rt_rtmp_adapter *pAd)
3518{
3519
3520 RTMPFreeAdapter(pAd);
3521
3522 return TRUE;
3523}
3524
3525/* not yet support MBSS */
3526struct net_device *get_netdev_from_bssid(struct rt_rtmp_adapter *pAd, u8 FromWhichBSSID)
3527{
3528 struct net_device *dev_p = NULL;
3529
3530 {
3531 dev_p = pAd->net_dev;
3532 }
3533
3534 ASSERT(dev_p);
3535 return dev_p; /* return one of MBSS */
3536}
diff --git a/drivers/staging/rt2860/common/rtmp_mcu.c b/drivers/staging/rt2860/common/rtmp_mcu.c
deleted file mode 100644
index 80fa4160ed6..00000000000
--- a/drivers/staging/rt2860/common/rtmp_mcu.c
+++ /dev/null
@@ -1,336 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_mcu.c
29
30 Abstract:
31 Miniport generic portion header file
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#include "../rt_config.h"
39
40#include <linux/crc-ccitt.h>
41#include <linux/firmware.h>
42
43#ifdef RTMP_MAC_USB
44
45#define FIRMWAREIMAGE_LENGTH 0x1000
46
47#define FIRMWARE_2870_MIN_VERSION 12
48#define FIRMWARE_2870_FILENAME "rt2870.bin"
49MODULE_FIRMWARE(FIRMWARE_2870_FILENAME);
50
51#define FIRMWARE_3070_MIN_VERSION 17
52#define FIRMWARE_3070_FILENAME "rt3070.bin"
53MODULE_FIRMWARE(FIRMWARE_3070_FILENAME);
54
55#define FIRMWARE_3071_MIN_VERSION 17
56#define FIRMWARE_3071_FILENAME "rt3071.bin" /* for RT3071/RT3072 */
57MODULE_FIRMWARE(FIRMWARE_3071_FILENAME);
58
59#else /* RTMP_MAC_PCI */
60
61#define FIRMWAREIMAGE_LENGTH 0x2000
62
63#define FIRMWARE_2860_MIN_VERSION 11
64#define FIRMWARE_2860_FILENAME "rt2860.bin"
65MODULE_FIRMWARE(FIRMWARE_2860_FILENAME);
66
67#define FIRMWARE_3090_MIN_VERSION 19
68#define FIRMWARE_3090_FILENAME "rt3090.bin" /* for RT3090/RT3390 */
69MODULE_FIRMWARE(FIRMWARE_3090_FILENAME);
70
71#endif
72
73/*
74 ========================================================================
75
76 Routine Description:
77 erase 8051 firmware image in MAC ASIC
78
79 Arguments:
80 Adapter Pointer to our adapter
81
82 IRQL = PASSIVE_LEVEL
83
84 ========================================================================
85*/
86int RtmpAsicEraseFirmware(struct rt_rtmp_adapter *pAd)
87{
88 unsigned long i;
89
90 for (i = 0; i < MAX_FIRMWARE_IMAGE_SIZE; i += 4)
91 RTMP_IO_WRITE32(pAd, FIRMWARE_IMAGE_BASE + i, 0);
92
93 return 0;
94}
95
96static const struct firmware *rtmp_get_firmware(struct rt_rtmp_adapter *adapter)
97{
98 const char *name;
99 const struct firmware *fw = NULL;
100 u8 min_version;
101 struct device *dev;
102 int err;
103
104 if (adapter->firmware)
105 return adapter->firmware;
106
107#ifdef RTMP_MAC_USB
108 if (IS_RT3071(adapter)) {
109 name = FIRMWARE_3071_FILENAME;
110 min_version = FIRMWARE_3071_MIN_VERSION;
111 } else if (IS_RT3070(adapter)) {
112 name = FIRMWARE_3070_FILENAME;
113 min_version = FIRMWARE_3070_MIN_VERSION;
114 } else {
115 name = FIRMWARE_2870_FILENAME;
116 min_version = FIRMWARE_2870_MIN_VERSION;
117 }
118 dev = &((struct os_cookie *)adapter->OS_Cookie)->pUsb_Dev->dev;
119#else /* RTMP_MAC_PCI */
120 if (IS_RT3090(adapter) || IS_RT3390(adapter)) {
121 name = FIRMWARE_3090_FILENAME;
122 min_version = FIRMWARE_3090_MIN_VERSION;
123 } else {
124 name = FIRMWARE_2860_FILENAME;
125 min_version = FIRMWARE_2860_MIN_VERSION;
126 }
127 dev = &((struct os_cookie *)adapter->OS_Cookie)->pci_dev->dev;
128#endif
129
130 err = request_firmware(&fw, name, dev);
131 if (err) {
132 dev_err(dev, "firmware file %s request failed (%d)\n",
133 name, err);
134 return NULL;
135 }
136
137 if (fw->size < FIRMWAREIMAGE_LENGTH) {
138 dev_err(dev, "firmware file %s size is invalid\n", name);
139 goto invalid;
140 }
141
142 /* is it new enough? */
143 adapter->FirmwareVersion = fw->data[FIRMWAREIMAGE_LENGTH - 3];
144 if (adapter->FirmwareVersion < min_version) {
145 dev_err(dev,
146 "firmware file %s is too old;"
147 " driver requires v%d or later\n",
148 name, min_version);
149 goto invalid;
150 }
151
152 /* is the internal CRC correct? */
153 if (crc_ccitt(0xffff, fw->data, FIRMWAREIMAGE_LENGTH - 2) !=
154 (fw->data[FIRMWAREIMAGE_LENGTH - 2] |
155 (fw->data[FIRMWAREIMAGE_LENGTH - 1] << 8))) {
156 dev_err(dev, "firmware file %s failed internal CRC\n", name);
157 goto invalid;
158 }
159
160 adapter->firmware = fw;
161 return fw;
162
163invalid:
164 release_firmware(fw);
165 return NULL;
166}
167
168/*
169 ========================================================================
170
171 Routine Description:
172 Load 8051 firmware file into MAC ASIC
173
174 Arguments:
175 Adapter Pointer to our adapter
176
177 Return Value:
178 NDIS_STATUS_SUCCESS firmware image load ok
179 NDIS_STATUS_FAILURE image not found
180
181 IRQL = PASSIVE_LEVEL
182
183 ========================================================================
184*/
185int RtmpAsicLoadFirmware(struct rt_rtmp_adapter *pAd)
186{
187 const struct firmware *fw;
188 int Status = NDIS_STATUS_SUCCESS;
189 unsigned long Index;
190 u32 MacReg = 0;
191
192 fw = rtmp_get_firmware(pAd);
193 if (!fw)
194 return NDIS_STATUS_FAILURE;
195
196 RTMP_WRITE_FIRMWARE(pAd, fw->data, FIRMWAREIMAGE_LENGTH);
197
198 /* check if MCU is ready */
199 Index = 0;
200 do {
201 RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacReg);
202
203 if (MacReg & 0x80)
204 break;
205
206 RTMPusecDelay(1000);
207 } while (Index++ < 1000);
208
209 if (Index > 1000) {
210 DBGPRINT(RT_DEBUG_ERROR,
211 ("NICLoadFirmware: MCU is not ready\n"));
212 Status = NDIS_STATUS_FAILURE;
213 }
214
215 DBGPRINT(RT_DEBUG_TRACE, ("<=== %s (status=%d)\n", __func__, Status));
216
217 return Status;
218}
219
220int RtmpAsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
221 u8 Command,
222 u8 Token, u8 Arg0, u8 Arg1)
223{
224 HOST_CMD_CSR_STRUC H2MCmd;
225 H2M_MAILBOX_STRUC H2MMailbox;
226 unsigned long i = 0;
227
228#ifdef PCIE_PS_SUPPORT
229 /* 3090F power solution 3 has hw limitation that needs to ban all mcu command */
230 /* when firmware is in radio state. For other chip doesn't have this limitation. */
231 if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
232 && IS_VERSION_AFTER_F(pAd)) && IS_VERSION_AFTER_F(pAd)
233 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
234 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) {
235 RTMP_SEM_LOCK(&pAd->McuCmdLock);
236 if ((pAd->brt30xxBanMcuCmd == TRUE)
237 && (Command != WAKE_MCU_CMD) && (Command != RFOFF_MCU_CMD)) {
238 RTMP_SEM_UNLOCK(&pAd->McuCmdLock);
239 DBGPRINT(RT_DEBUG_TRACE,
240 (" Ban Mcu Cmd %x in sleep mode\n", Command));
241 return FALSE;
242 } else if ((Command == SLEEP_MCU_CMD)
243 || (Command == RFOFF_MCU_CMD)) {
244 pAd->brt30xxBanMcuCmd = TRUE;
245 } else if (Command != WAKE_MCU_CMD) {
246 pAd->brt30xxBanMcuCmd = FALSE;
247 }
248
249 RTMP_SEM_UNLOCK(&pAd->McuCmdLock);
250
251 }
252 if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
253 && IS_VERSION_AFTER_F(pAd)) && IS_VERSION_AFTER_F(pAd)
254 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
255 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)
256 && (Command == WAKE_MCU_CMD)) {
257
258 do {
259 RTMP_IO_FORCE_READ32(pAd, H2M_MAILBOX_CSR,
260 &H2MMailbox.word);
261 if (H2MMailbox.field.Owner == 0)
262 break;
263
264 RTMPusecDelay(2);
265 DBGPRINT(RT_DEBUG_INFO,
266 ("AsicSendCommanToMcu::Mail box is busy\n"));
267 } while (i++ < 100);
268
269 if (i > 100) {
270 DBGPRINT_ERR("H2M_MAILBOX still hold by MCU. command fail\n");
271 return FALSE;
272 }
273
274 H2MMailbox.field.Owner = 1; /* pass ownership to MCU */
275 H2MMailbox.field.CmdToken = Token;
276 H2MMailbox.field.HighByte = Arg1;
277 H2MMailbox.field.LowByte = Arg0;
278 RTMP_IO_FORCE_WRITE32(pAd, H2M_MAILBOX_CSR, H2MMailbox.word);
279
280 H2MCmd.word = 0;
281 H2MCmd.field.HostCommand = Command;
282 RTMP_IO_FORCE_WRITE32(pAd, HOST_CMD_CSR, H2MCmd.word);
283
284 } else
285#endif /* PCIE_PS_SUPPORT // */
286 {
287 do {
288 RTMP_IO_READ32(pAd, H2M_MAILBOX_CSR, &H2MMailbox.word);
289 if (H2MMailbox.field.Owner == 0)
290 break;
291
292 RTMPusecDelay(2);
293 } while (i++ < 100);
294
295 if (i > 100) {
296#ifdef RTMP_MAC_PCI
297#endif /* RTMP_MAC_PCI // */
298 {
299 DBGPRINT_ERR("H2M_MAILBOX still hold by MCU. command fail\n");
300 }
301 return FALSE;
302 }
303#ifdef RTMP_MAC_PCI
304#endif /* RTMP_MAC_PCI // */
305
306 H2MMailbox.field.Owner = 1; /* pass ownership to MCU */
307 H2MMailbox.field.CmdToken = Token;
308 H2MMailbox.field.HighByte = Arg1;
309 H2MMailbox.field.LowByte = Arg0;
310 RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, H2MMailbox.word);
311
312 H2MCmd.word = 0;
313 H2MCmd.field.HostCommand = Command;
314 RTMP_IO_WRITE32(pAd, HOST_CMD_CSR, H2MCmd.word);
315
316 if (Command != 0x80) {
317 }
318 }
319#ifdef PCIE_PS_SUPPORT
320 /* 3090 MCU Wakeup command needs more time to be stable. */
321 /* Before stable, don't issue other MCU command to prevent from firmware error. */
322 if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))
323 && IS_VERSION_AFTER_F(pAd)) && IS_VERSION_AFTER_F(pAd)
324 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3)
325 && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)
326 && (Command == WAKE_MCU_CMD)) {
327 RTMPusecDelay(2000);
328 /*Put this is after RF programming. */
329 /*NdisAcquireSpinLock(&pAd->McuCmdLock); */
330 /*pAd->brt30xxBanMcuCmd = FALSE; */
331 /*NdisReleaseSpinLock(&pAd->McuCmdLock); */
332 }
333#endif /* PCIE_PS_SUPPORT // */
334
335 return TRUE;
336}
diff --git a/drivers/staging/rt2860/common/rtmp_timer.c b/drivers/staging/rt2860/common/rtmp_timer.c
deleted file mode 100644
index ab520909490..00000000000
--- a/drivers/staging/rt2860/common/rtmp_timer.c
+++ /dev/null
@@ -1,302 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_timer.c
29
30 Abstract:
31 task for timer handling
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Name Date Modification logs
37 Shiang Tu 08-28-2008 init version
38
39*/
40
41#include "../rt_config.h"
42
43BUILD_TIMER_FUNCTION(MlmePeriodicExec);
44/*BUILD_TIMER_FUNCTION(MlmeRssiReportExec); */
45BUILD_TIMER_FUNCTION(AsicRxAntEvalTimeout);
46BUILD_TIMER_FUNCTION(APSDPeriodicExec);
47BUILD_TIMER_FUNCTION(AsicRfTuningExec);
48#ifdef RTMP_MAC_USB
49BUILD_TIMER_FUNCTION(BeaconUpdateExec);
50#endif /* RTMP_MAC_USB // */
51
52BUILD_TIMER_FUNCTION(BeaconTimeout);
53BUILD_TIMER_FUNCTION(ScanTimeout);
54BUILD_TIMER_FUNCTION(AuthTimeout);
55BUILD_TIMER_FUNCTION(AssocTimeout);
56BUILD_TIMER_FUNCTION(ReassocTimeout);
57BUILD_TIMER_FUNCTION(DisassocTimeout);
58BUILD_TIMER_FUNCTION(LinkDownExec);
59BUILD_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
60BUILD_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
61#ifdef RTMP_MAC_PCI
62BUILD_TIMER_FUNCTION(PsPollWakeExec);
63BUILD_TIMER_FUNCTION(RadioOnExec);
64#endif /* RTMP_MAC_PCI // */
65#ifdef RTMP_MAC_USB
66BUILD_TIMER_FUNCTION(RtmpUsbStaAsicForceWakeupTimeout);
67#endif /* RTMP_MAC_USB // */
68
69#if defined(AP_LED) || defined(STA_LED)
70extern void LedCtrlMain(void *SystemSpecific1,
71 void *FunctionContext,
72 void *SystemSpecific2, void *SystemSpecific3);
73BUILD_TIMER_FUNCTION(LedCtrlMain);
74#endif
75
76#ifdef RTMP_TIMER_TASK_SUPPORT
77static void RtmpTimerQHandle(struct rt_rtmp_adapter *pAd)
78{
79#ifndef KTHREAD_SUPPORT
80 int status;
81#endif
82 struct rt_ralink_timer *pTimer;
83 struct rt_rtmp_timer_task_entry *pEntry;
84 unsigned long irqFlag;
85 struct rt_rtmp_os_task *pTask;
86
87 pTask = &pAd->timerTask;
88 while (!pTask->task_killed) {
89 pTimer = NULL;
90
91#ifdef KTHREAD_SUPPORT
92 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
93#else
94 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
95#endif
96
97 if (pAd->TimerQ.status == RTMP_TASK_STAT_STOPED)
98 break;
99
100 /* event happened. */
101 while (pAd->TimerQ.pQHead) {
102 RTMP_INT_LOCK(&pAd->TimerQLock, irqFlag);
103 pEntry = pAd->TimerQ.pQHead;
104 if (pEntry) {
105 pTimer = pEntry->pRaTimer;
106
107 /* update pQHead */
108 pAd->TimerQ.pQHead = pEntry->pNext;
109 if (pEntry == pAd->TimerQ.pQTail)
110 pAd->TimerQ.pQTail = NULL;
111
112 /* return this queue entry to timerQFreeList. */
113 pEntry->pNext = pAd->TimerQ.pQPollFreeList;
114 pAd->TimerQ.pQPollFreeList = pEntry;
115 }
116 RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlag);
117
118 if (pTimer) {
119 if ((pTimer->handle != NULL)
120 && (!pAd->PM_FlgSuspend))
121 pTimer->handle(NULL,
122 (void *)pTimer->cookie,
123 NULL, pTimer);
124 if ((pTimer->Repeat)
125 && (pTimer->State == FALSE))
126 RTMP_OS_Add_Timer(&pTimer->TimerObj,
127 pTimer->TimerValue);
128 }
129 }
130
131#ifndef KTHREAD_SUPPORT
132 if (status != 0) {
133 pAd->TimerQ.status = RTMP_TASK_STAT_STOPED;
134 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
135 break;
136 }
137#endif
138 }
139}
140
141int RtmpTimerQThread(IN void *Context)
142{
143 struct rt_rtmp_os_task *pTask;
144 struct rt_rtmp_adapter *pAd;
145
146 pTask = Context;
147 pAd = pTask->priv;
148
149 RtmpOSTaskCustomize(pTask);
150
151 RtmpTimerQHandle(pAd);
152
153 DBGPRINT(RT_DEBUG_TRACE, ("<---%s\n", __func__));
154#ifndef KTHREAD_SUPPORT
155 pTask->taskPID = THREAD_PID_INIT_VALUE;
156#endif
157 /* notify the exit routine that we're actually exiting now
158 *
159 * complete()/wait_for_completion() is similar to up()/down(),
160 * except that complete() is safe in the case where the structure
161 * is getting deleted in a parallel mode of execution (i.e. just
162 * after the down() -- that's necessary for the thread-shutdown
163 * case.
164 *
165 * complete_and_exit() goes even further than this -- it is safe in
166 * the case that the thread of the caller is going away (not just
167 * the structure) -- this is necessary for the module-remove case.
168 * This is important in preemption kernels, which transfer the flow
169 * of execution immediately upon a complete().
170 */
171 RtmpOSTaskNotifyToExit(pTask);
172
173 return 0;
174
175}
176
177struct rt_rtmp_timer_task_entry *RtmpTimerQInsert(struct rt_rtmp_adapter *pAd,
178 struct rt_ralink_timer *pTimer)
179{
180 struct rt_rtmp_timer_task_entry *pQNode = NULL, *pQTail;
181 unsigned long irqFlags;
182 struct rt_rtmp_os_task *pTask = &pAd->timerTask;
183
184 RTMP_INT_LOCK(&pAd->TimerQLock, irqFlags);
185 if (pAd->TimerQ.status & RTMP_TASK_CAN_DO_INSERT) {
186 if (pAd->TimerQ.pQPollFreeList) {
187 pQNode = pAd->TimerQ.pQPollFreeList;
188 pAd->TimerQ.pQPollFreeList = pQNode->pNext;
189
190 pQNode->pRaTimer = pTimer;
191 pQNode->pNext = NULL;
192
193 pQTail = pAd->TimerQ.pQTail;
194 if (pAd->TimerQ.pQTail != NULL)
195 pQTail->pNext = pQNode;
196 pAd->TimerQ.pQTail = pQNode;
197 if (pAd->TimerQ.pQHead == NULL)
198 pAd->TimerQ.pQHead = pQNode;
199 }
200 }
201 RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlags);
202
203 if (pQNode) {
204#ifdef KTHREAD_SUPPORT
205 WAKE_UP(pTask);
206#else
207 RTMP_SEM_EVENT_UP(&pTask->taskSema);
208#endif
209 }
210
211 return pQNode;
212}
213
214BOOLEAN RtmpTimerQRemove(struct rt_rtmp_adapter *pAd, struct rt_ralink_timer *pTimer)
215{
216 struct rt_rtmp_timer_task_entry *pNode, *pPrev = NULL;
217 unsigned long irqFlags;
218
219 RTMP_INT_LOCK(&pAd->TimerQLock, irqFlags);
220 if (pAd->TimerQ.status >= RTMP_TASK_STAT_INITED) {
221 pNode = pAd->TimerQ.pQHead;
222 while (pNode) {
223 if (pNode->pRaTimer == pTimer)
224 break;
225 pPrev = pNode;
226 pNode = pNode->pNext;
227 }
228
229 /* Now move it to freeList queue. */
230 if (pNode) {
231 if (pNode == pAd->TimerQ.pQHead)
232 pAd->TimerQ.pQHead = pNode->pNext;
233 if (pNode == pAd->TimerQ.pQTail)
234 pAd->TimerQ.pQTail = pPrev;
235 if (pPrev != NULL)
236 pPrev->pNext = pNode->pNext;
237
238 /* return this queue entry to timerQFreeList. */
239 pNode->pNext = pAd->TimerQ.pQPollFreeList;
240 pAd->TimerQ.pQPollFreeList = pNode;
241 }
242 }
243 RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlags);
244
245 return TRUE;
246}
247
248void RtmpTimerQExit(struct rt_rtmp_adapter *pAd)
249{
250 struct rt_rtmp_timer_task_entry *pTimerQ;
251 unsigned long irqFlags;
252
253 RTMP_INT_LOCK(&pAd->TimerQLock, irqFlags);
254 while (pAd->TimerQ.pQHead) {
255 pTimerQ = pAd->TimerQ.pQHead;
256 pAd->TimerQ.pQHead = pTimerQ->pNext;
257 /* remove the timeQ */
258 }
259 pAd->TimerQ.pQPollFreeList = NULL;
260 os_free_mem(pAd, pAd->TimerQ.pTimerQPoll);
261 pAd->TimerQ.pQTail = NULL;
262 pAd->TimerQ.pQHead = NULL;
263#ifndef KTHREAD_SUPPORT
264 pAd->TimerQ.status = RTMP_TASK_STAT_STOPED;
265#endif
266 RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlags);
267
268}
269
270void RtmpTimerQInit(struct rt_rtmp_adapter *pAd)
271{
272 int i;
273 struct rt_rtmp_timer_task_entry *pQNode, *pEntry;
274 unsigned long irqFlags;
275
276 NdisAllocateSpinLock(&pAd->TimerQLock);
277
278 NdisZeroMemory(&pAd->TimerQ, sizeof(pAd->TimerQ));
279
280 os_alloc_mem(pAd, &pAd->TimerQ.pTimerQPoll,
281 sizeof(struct rt_rtmp_timer_task_entry) * TIMER_QUEUE_SIZE_MAX);
282 if (pAd->TimerQ.pTimerQPoll) {
283 pEntry = NULL;
284 pQNode = (struct rt_rtmp_timer_task_entry *)pAd->TimerQ.pTimerQPoll;
285 NdisZeroMemory(pAd->TimerQ.pTimerQPoll,
286 sizeof(struct rt_rtmp_timer_task_entry) *
287 TIMER_QUEUE_SIZE_MAX);
288
289 RTMP_INT_LOCK(&pAd->TimerQLock, irqFlags);
290 for (i = 0; i < TIMER_QUEUE_SIZE_MAX; i++) {
291 pQNode->pNext = pEntry;
292 pEntry = pQNode;
293 pQNode++;
294 }
295 pAd->TimerQ.pQPollFreeList = pEntry;
296 pAd->TimerQ.pQHead = NULL;
297 pAd->TimerQ.pQTail = NULL;
298 pAd->TimerQ.status = RTMP_TASK_STAT_INITED;
299 RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlags);
300 }
301}
302#endif /* RTMP_TIMER_TASK_SUPPORT // */
diff --git a/drivers/staging/rt2860/common/spectrum.c b/drivers/staging/rt2860/common/spectrum.c
deleted file mode 100644
index ceb622df12d..00000000000
--- a/drivers/staging/rt2860/common/spectrum.c
+++ /dev/null
@@ -1,2205 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 action.c
29
30 Abstract:
31 Handle association related requests either from WSTA or from local MLME
32
33 Revision History:
34 Who When What
35 --------- ---------- ----------------------------------------------
36 Fonchi Wu 2008 created for 802.11h
37 */
38
39#include "../rt_config.h"
40#include "action.h"
41
42/* The regulatory information in the USA (US) */
43struct rt_dot11_regulatory_information USARegulatoryInfo[] = {
44/* "regulatory class" "number of channels" "Max Tx Pwr" "channel list" */
45 {0, {0, 0, {0}
46 }
47 }
48 , /* Invlid entry */
49 {1, {4, 16, {36, 40, 44, 48}
50 }
51 }
52 ,
53 {2, {4, 23, {52, 56, 60, 64}
54 }
55 }
56 ,
57 {3, {4, 29, {149, 153, 157, 161}
58 }
59 }
60 ,
61 {4, {11, 23, {100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}
62 }
63 }
64 ,
65 {5, {5, 30, {149, 153, 157, 161, 165}
66 }
67 }
68 ,
69 {6, {10, 14, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
70 }
71 }
72 ,
73 {7, {10, 27, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
74 }
75 }
76 ,
77 {8, {5, 17, {11, 13, 15, 17, 19}
78 }
79 }
80 ,
81 {9, {5, 30, {11, 13, 15, 17, 19}
82 }
83 }
84 ,
85 {10, {2, 20, {21, 25}
86 }
87 }
88 ,
89 {11, {2, 33, {21, 25}
90 }
91 }
92 ,
93 {12, {11, 30, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
94 }
95 }
96};
97
98#define USA_REGULATORY_INFO_SIZE (sizeof(USARegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information))
99
100/* The regulatory information in Europe */
101struct rt_dot11_regulatory_information EuropeRegulatoryInfo[] = {
102/* "regulatory class" "number of channels" "Max Tx Pwr" "channel list" */
103 {0, {0, 0, {0}
104 }
105 }
106 , /* Invalid entry */
107 {1, {4, 20, {36, 40, 44, 48}
108 }
109 }
110 ,
111 {2, {4, 20, {52, 56, 60, 64}
112 }
113 }
114 ,
115 {3, {11, 30, {100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140}
116 }
117 }
118 ,
119 {4, {13, 20, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
120 }
121 }
122};
123
124#define EU_REGULATORY_INFO_SIZE (sizeof(EuropeRegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information))
125
126/* The regulatory information in Japan */
127struct rt_dot11_regulatory_information JapanRegulatoryInfo[] = {
128/* "regulatory class" "number of channels" "Max Tx Pwr" "channel list" */
129 {0, {0, 0, {0}
130 }
131 }
132 , /* Invalid entry */
133 {1, {4, 22, {34, 38, 42, 46}
134 }
135 }
136 ,
137 {2, {3, 24, {8, 12, 16}
138 }
139 }
140 ,
141 {3, {3, 24, {8, 12, 16}
142 }
143 }
144 ,
145 {4, {3, 24, {8, 12, 16}
146 }
147 }
148 ,
149 {5, {3, 24, {8, 12, 16}
150 }
151 }
152 ,
153 {6, {3, 22, {8, 12, 16}
154 }
155 }
156 ,
157 {7, {4, 24, {184, 188, 192, 196}
158 }
159 }
160 ,
161 {8, {4, 24, {184, 188, 192, 196}
162 }
163 }
164 ,
165 {9, {4, 24, {184, 188, 192, 196}
166 }
167 }
168 ,
169 {10, {4, 24, {184, 188, 192, 196}
170 }
171 }
172 ,
173 {11, {4, 22, {184, 188, 192, 196}
174 }
175 }
176 ,
177 {12, {4, 24, {7, 8, 9, 11}
178 }
179 }
180 ,
181 {13, {4, 24, {7, 8, 9, 11}
182 }
183 }
184 ,
185 {14, {4, 24, {7, 8, 9, 11}
186 }
187 }
188 ,
189 {15, {4, 24, {7, 8, 9, 11}
190 }
191 }
192 ,
193 {16, {6, 24, {183, 184, 185, 187, 188, 189}
194 }
195 }
196 ,
197 {17, {6, 24, {183, 184, 185, 187, 188, 189}
198 }
199 }
200 ,
201 {18, {6, 24, {183, 184, 185, 187, 188, 189}
202 }
203 }
204 ,
205 {19, {6, 24, {183, 184, 185, 187, 188, 189}
206 }
207 }
208 ,
209 {20, {6, 17, {183, 184, 185, 187, 188, 189}
210 }
211 }
212 ,
213 {21, {6, 24, {6, 7, 8, 9, 10, 11}
214 }
215 }
216 ,
217 {22, {6, 24, {6, 7, 8, 9, 10, 11}
218 }
219 }
220 ,
221 {23, {6, 24, {6, 7, 8, 9, 10, 11}
222 }
223 }
224 ,
225 {24, {6, 24, {6, 7, 8, 9, 10, 11}
226 }
227 }
228 ,
229 {25, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189}
230 }
231 }
232 ,
233 {26, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189}
234 }
235 }
236 ,
237 {27, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189}
238 }
239 }
240 ,
241 {28, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189}
242 }
243 }
244 ,
245 {29, {8, 17, {182, 183, 184, 185, 186, 187, 188, 189}
246 }
247 }
248 ,
249 {30, {13, 23, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
250 }
251 }
252 ,
253 {31, {1, 23, {14}
254 }
255 }
256 ,
257 {32, {4, 22, {52, 56, 60, 64}
258 }
259 }
260};
261
262#define JP_REGULATORY_INFO_SIZE (sizeof(JapanRegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information))
263
264char RTMP_GetTxPwr(struct rt_rtmp_adapter *pAd, IN HTTRANSMIT_SETTING HTTxMode)
265{
266 struct tx_pwr_cfg {
267 u8 Mode;
268 u8 MCS;
269 u16 req;
270 u8 shift;
271 u32 BitMask;
272 };
273
274 u32 Value;
275 int Idx;
276 u8 PhyMode;
277 char CurTxPwr;
278 u8 TxPwrRef = 0;
279 char DaltaPwr;
280 unsigned long TxPwr[5];
281
282 struct tx_pwr_cfg TxPwrCfg[] = {
283 {MODE_CCK, 0, 0, 4, 0x000000f0},
284 {MODE_CCK, 1, 0, 0, 0x0000000f},
285 {MODE_CCK, 2, 0, 12, 0x0000f000},
286 {MODE_CCK, 3, 0, 8, 0x00000f00},
287
288 {MODE_OFDM, 0, 0, 20, 0x00f00000},
289 {MODE_OFDM, 1, 0, 16, 0x000f0000},
290 {MODE_OFDM, 2, 0, 28, 0xf0000000},
291 {MODE_OFDM, 3, 0, 24, 0x0f000000},
292 {MODE_OFDM, 4, 1, 4, 0x000000f0},
293 {MODE_OFDM, 5, 1, 0, 0x0000000f},
294 {MODE_OFDM, 6, 1, 12, 0x0000f000},
295 {MODE_OFDM, 7, 1, 8, 0x00000f00}
296 , {MODE_HTMIX, 0, 1, 20, 0x00f00000},
297 {MODE_HTMIX, 1, 1, 16, 0x000f0000},
298 {MODE_HTMIX, 2, 1, 28, 0xf0000000},
299 {MODE_HTMIX, 3, 1, 24, 0x0f000000},
300 {MODE_HTMIX, 4, 2, 4, 0x000000f0},
301 {MODE_HTMIX, 5, 2, 0, 0x0000000f},
302 {MODE_HTMIX, 6, 2, 12, 0x0000f000},
303 {MODE_HTMIX, 7, 2, 8, 0x00000f00},
304 {MODE_HTMIX, 8, 2, 20, 0x00f00000},
305 {MODE_HTMIX, 9, 2, 16, 0x000f0000},
306 {MODE_HTMIX, 10, 2, 28, 0xf0000000},
307 {MODE_HTMIX, 11, 2, 24, 0x0f000000},
308 {MODE_HTMIX, 12, 3, 4, 0x000000f0},
309 {MODE_HTMIX, 13, 3, 0, 0x0000000f},
310 {MODE_HTMIX, 14, 3, 12, 0x0000f000},
311 {MODE_HTMIX, 15, 3, 8, 0x00000f00}
312 };
313#define MAX_TXPWR_TAB_SIZE (sizeof(TxPwrCfg) / sizeof(struct tx_pwr_cfg))
314
315 CurTxPwr = 19;
316
317 /* check Tx Power setting from UI. */
318 if (pAd->CommonCfg.TxPowerPercentage > 90) ;
319 else if (pAd->CommonCfg.TxPowerPercentage > 60) /* reduce Pwr for 1 dB. */
320 CurTxPwr -= 1;
321 else if (pAd->CommonCfg.TxPowerPercentage > 30) /* reduce Pwr for 3 dB. */
322 CurTxPwr -= 3;
323 else if (pAd->CommonCfg.TxPowerPercentage > 15) /* reduce Pwr for 6 dB. */
324 CurTxPwr -= 6;
325 else if (pAd->CommonCfg.TxPowerPercentage > 9) /* reduce Pwr for 9 dB. */
326 CurTxPwr -= 9;
327 else /* reduce Pwr for 12 dB. */
328 CurTxPwr -= 12;
329
330 if (pAd->CommonCfg.BBPCurrentBW == BW_40) {
331 if (pAd->CommonCfg.CentralChannel > 14) {
332 TxPwr[0] = pAd->Tx40MPwrCfgABand[0];
333 TxPwr[1] = pAd->Tx40MPwrCfgABand[1];
334 TxPwr[2] = pAd->Tx40MPwrCfgABand[2];
335 TxPwr[3] = pAd->Tx40MPwrCfgABand[3];
336 TxPwr[4] = pAd->Tx40MPwrCfgABand[4];
337 } else {
338 TxPwr[0] = pAd->Tx40MPwrCfgGBand[0];
339 TxPwr[1] = pAd->Tx40MPwrCfgGBand[1];
340 TxPwr[2] = pAd->Tx40MPwrCfgGBand[2];
341 TxPwr[3] = pAd->Tx40MPwrCfgGBand[3];
342 TxPwr[4] = pAd->Tx40MPwrCfgGBand[4];
343 }
344 } else {
345 if (pAd->CommonCfg.Channel > 14) {
346 TxPwr[0] = pAd->Tx20MPwrCfgABand[0];
347 TxPwr[1] = pAd->Tx20MPwrCfgABand[1];
348 TxPwr[2] = pAd->Tx20MPwrCfgABand[2];
349 TxPwr[3] = pAd->Tx20MPwrCfgABand[3];
350 TxPwr[4] = pAd->Tx20MPwrCfgABand[4];
351 } else {
352 TxPwr[0] = pAd->Tx20MPwrCfgGBand[0];
353 TxPwr[1] = pAd->Tx20MPwrCfgGBand[1];
354 TxPwr[2] = pAd->Tx20MPwrCfgGBand[2];
355 TxPwr[3] = pAd->Tx20MPwrCfgGBand[3];
356 TxPwr[4] = pAd->Tx20MPwrCfgGBand[4];
357 }
358 }
359
360 switch (HTTxMode.field.MODE) {
361 case MODE_CCK:
362 case MODE_OFDM:
363 Value = TxPwr[1];
364 TxPwrRef = (Value & 0x00000f00) >> 8;
365
366 break;
367
368 case MODE_HTMIX:
369 case MODE_HTGREENFIELD:
370 if (pAd->CommonCfg.TxStream == 1) {
371 Value = TxPwr[2];
372 TxPwrRef = (Value & 0x00000f00) >> 8;
373 } else if (pAd->CommonCfg.TxStream == 2) {
374 Value = TxPwr[3];
375 TxPwrRef = (Value & 0x00000f00) >> 8;
376 }
377 break;
378 }
379
380 PhyMode = (HTTxMode.field.MODE == MODE_HTGREENFIELD)
381 ? MODE_HTMIX : HTTxMode.field.MODE;
382
383 for (Idx = 0; Idx < MAX_TXPWR_TAB_SIZE; Idx++) {
384 if ((TxPwrCfg[Idx].Mode == PhyMode)
385 && (TxPwrCfg[Idx].MCS == HTTxMode.field.MCS)) {
386 Value = TxPwr[TxPwrCfg[Idx].req];
387 DaltaPwr =
388 TxPwrRef - (char)((Value & TxPwrCfg[Idx].BitMask)
389 >> TxPwrCfg[Idx].shift);
390 CurTxPwr -= DaltaPwr;
391 break;
392 }
393 }
394
395 return CurTxPwr;
396}
397
398void MeasureReqTabInit(struct rt_rtmp_adapter *pAd)
399{
400 NdisAllocateSpinLock(&pAd->CommonCfg.MeasureReqTabLock);
401
402 pAd->CommonCfg.pMeasureReqTab =
403 kmalloc(sizeof(struct rt_measure_req_tab), GFP_ATOMIC);
404 if (pAd->CommonCfg.pMeasureReqTab)
405 NdisZeroMemory(pAd->CommonCfg.pMeasureReqTab,
406 sizeof(struct rt_measure_req_tab));
407 else
408 DBGPRINT(RT_DEBUG_ERROR,
409 ("%s Fail to alloc memory for pAd->CommonCfg.pMeasureReqTab.\n",
410 __func__));
411
412 return;
413}
414
415void MeasureReqTabExit(struct rt_rtmp_adapter *pAd)
416{
417 NdisFreeSpinLock(&pAd->CommonCfg.MeasureReqTabLock);
418
419 kfree(pAd->CommonCfg.pMeasureReqTab);
420 pAd->CommonCfg.pMeasureReqTab = NULL;
421
422 return;
423}
424
425struct rt_measure_req_entry *MeasureReqLookUp(struct rt_rtmp_adapter *pAd, u8 DialogToken)
426{
427 u32 HashIdx;
428 struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab;
429 struct rt_measure_req_entry *pEntry = NULL;
430 struct rt_measure_req_entry *pPrevEntry = NULL;
431
432 if (pTab == NULL) {
433 DBGPRINT(RT_DEBUG_ERROR,
434 ("%s: pMeasureReqTab doesn't exist.\n", __func__));
435 return NULL;
436 }
437
438 RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
439
440 HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken);
441 pEntry = pTab->Hash[HashIdx];
442
443 while (pEntry) {
444 if (pEntry->DialogToken == DialogToken)
445 break;
446 else {
447 pPrevEntry = pEntry;
448 pEntry = pEntry->pNext;
449 }
450 }
451
452 RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
453
454 return pEntry;
455}
456
457struct rt_measure_req_entry *MeasureReqInsert(struct rt_rtmp_adapter *pAd, u8 DialogToken)
458{
459 int i;
460 unsigned long HashIdx;
461 struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab;
462 struct rt_measure_req_entry *pEntry = NULL, *pCurrEntry;
463 unsigned long Now;
464
465 if (pTab == NULL) {
466 DBGPRINT(RT_DEBUG_ERROR,
467 ("%s: pMeasureReqTab doesn't exist.\n", __func__));
468 return NULL;
469 }
470
471 pEntry = MeasureReqLookUp(pAd, DialogToken);
472 if (pEntry == NULL) {
473 RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
474 for (i = 0; i < MAX_MEASURE_REQ_TAB_SIZE; i++) {
475 NdisGetSystemUpTime(&Now);
476 pEntry = &pTab->Content[i];
477
478 if ((pEntry->Valid == TRUE)
479 && RTMP_TIME_AFTER((unsigned long)Now,
480 (unsigned long)(pEntry->
481 lastTime +
482 MQ_REQ_AGE_OUT)))
483 {
484 struct rt_measure_req_entry *pPrevEntry = NULL;
485 unsigned long HashIdx =
486 MQ_DIALOGTOKEN_HASH_INDEX(pEntry->
487 DialogToken);
488 struct rt_measure_req_entry *pProbeEntry =
489 pTab->Hash[HashIdx];
490
491 /* update Hash list */
492 do {
493 if (pProbeEntry == pEntry) {
494 if (pPrevEntry == NULL) {
495 pTab->Hash[HashIdx] =
496 pEntry->pNext;
497 } else {
498 pPrevEntry->pNext =
499 pEntry->pNext;
500 }
501 break;
502 }
503
504 pPrevEntry = pProbeEntry;
505 pProbeEntry = pProbeEntry->pNext;
506 } while (pProbeEntry);
507
508 NdisZeroMemory(pEntry,
509 sizeof(struct rt_measure_req_entry));
510 pTab->Size--;
511
512 break;
513 }
514
515 if (pEntry->Valid == FALSE)
516 break;
517 }
518
519 if (i < MAX_MEASURE_REQ_TAB_SIZE) {
520 NdisGetSystemUpTime(&Now);
521 pEntry->lastTime = Now;
522 pEntry->Valid = TRUE;
523 pEntry->DialogToken = DialogToken;
524 pTab->Size++;
525 } else {
526 pEntry = NULL;
527 DBGPRINT(RT_DEBUG_ERROR,
528 ("%s: pMeasureReqTab tab full.\n", __func__));
529 }
530
531 /* add this Neighbor entry into HASH table */
532 if (pEntry) {
533 HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken);
534 if (pTab->Hash[HashIdx] == NULL) {
535 pTab->Hash[HashIdx] = pEntry;
536 } else {
537 pCurrEntry = pTab->Hash[HashIdx];
538 while (pCurrEntry->pNext != NULL)
539 pCurrEntry = pCurrEntry->pNext;
540 pCurrEntry->pNext = pEntry;
541 }
542 }
543
544 RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
545 }
546
547 return pEntry;
548}
549
550void MeasureReqDelete(struct rt_rtmp_adapter *pAd, u8 DialogToken)
551{
552 struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab;
553 struct rt_measure_req_entry *pEntry = NULL;
554
555 if (pTab == NULL) {
556 DBGPRINT(RT_DEBUG_ERROR,
557 ("%s: pMeasureReqTab doesn't exist.\n", __func__));
558 return;
559 }
560 /* if empty, return */
561 if (pTab->Size == 0) {
562 DBGPRINT(RT_DEBUG_ERROR, ("pMeasureReqTab empty.\n"));
563 return;
564 }
565
566 pEntry = MeasureReqLookUp(pAd, DialogToken);
567 if (pEntry != NULL) {
568 struct rt_measure_req_entry *pPrevEntry = NULL;
569 unsigned long HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
570 struct rt_measure_req_entry *pProbeEntry = pTab->Hash[HashIdx];
571
572 RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock);
573 /* update Hash list */
574 do {
575 if (pProbeEntry == pEntry) {
576 if (pPrevEntry == NULL) {
577 pTab->Hash[HashIdx] = pEntry->pNext;
578 } else {
579 pPrevEntry->pNext = pEntry->pNext;
580 }
581 break;
582 }
583
584 pPrevEntry = pProbeEntry;
585 pProbeEntry = pProbeEntry->pNext;
586 } while (pProbeEntry);
587
588 NdisZeroMemory(pEntry, sizeof(struct rt_measure_req_entry));
589 pTab->Size--;
590
591 RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock);
592 }
593
594 return;
595}
596
597void TpcReqTabInit(struct rt_rtmp_adapter *pAd)
598{
599 NdisAllocateSpinLock(&pAd->CommonCfg.TpcReqTabLock);
600
601 pAd->CommonCfg.pTpcReqTab = kmalloc(sizeof(struct rt_tpc_req_tab), GFP_ATOMIC);
602 if (pAd->CommonCfg.pTpcReqTab)
603 NdisZeroMemory(pAd->CommonCfg.pTpcReqTab, sizeof(struct rt_tpc_req_tab));
604 else
605 DBGPRINT(RT_DEBUG_ERROR,
606 ("%s Fail to alloc memory for pAd->CommonCfg.pTpcReqTab.\n",
607 __func__));
608
609 return;
610}
611
612void TpcReqTabExit(struct rt_rtmp_adapter *pAd)
613{
614 NdisFreeSpinLock(&pAd->CommonCfg.TpcReqTabLock);
615
616 kfree(pAd->CommonCfg.pTpcReqTab);
617 pAd->CommonCfg.pTpcReqTab = NULL;
618
619 return;
620}
621
622static struct rt_tpc_req_entry *TpcReqLookUp(struct rt_rtmp_adapter *pAd, u8 DialogToken)
623{
624 u32 HashIdx;
625 struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab;
626 struct rt_tpc_req_entry *pEntry = NULL;
627 struct rt_tpc_req_entry *pPrevEntry = NULL;
628
629 if (pTab == NULL) {
630 DBGPRINT(RT_DEBUG_ERROR,
631 ("%s: pTpcReqTab doesn't exist.\n", __func__));
632 return NULL;
633 }
634
635 RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
636
637 HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken);
638 pEntry = pTab->Hash[HashIdx];
639
640 while (pEntry) {
641 if (pEntry->DialogToken == DialogToken)
642 break;
643 else {
644 pPrevEntry = pEntry;
645 pEntry = pEntry->pNext;
646 }
647 }
648
649 RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
650
651 return pEntry;
652}
653
654static struct rt_tpc_req_entry *TpcReqInsert(struct rt_rtmp_adapter *pAd, u8 DialogToken)
655{
656 int i;
657 unsigned long HashIdx;
658 struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab;
659 struct rt_tpc_req_entry *pEntry = NULL, *pCurrEntry;
660 unsigned long Now;
661
662 if (pTab == NULL) {
663 DBGPRINT(RT_DEBUG_ERROR,
664 ("%s: pTpcReqTab doesn't exist.\n", __func__));
665 return NULL;
666 }
667
668 pEntry = TpcReqLookUp(pAd, DialogToken);
669 if (pEntry == NULL) {
670 RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
671 for (i = 0; i < MAX_TPC_REQ_TAB_SIZE; i++) {
672 NdisGetSystemUpTime(&Now);
673 pEntry = &pTab->Content[i];
674
675 if ((pEntry->Valid == TRUE)
676 && RTMP_TIME_AFTER((unsigned long)Now,
677 (unsigned long)(pEntry->
678 lastTime +
679 TPC_REQ_AGE_OUT)))
680 {
681 struct rt_tpc_req_entry *pPrevEntry = NULL;
682 unsigned long HashIdx =
683 TPC_DIALOGTOKEN_HASH_INDEX(pEntry->
684 DialogToken);
685 struct rt_tpc_req_entry *pProbeEntry =
686 pTab->Hash[HashIdx];
687
688 /* update Hash list */
689 do {
690 if (pProbeEntry == pEntry) {
691 if (pPrevEntry == NULL) {
692 pTab->Hash[HashIdx] =
693 pEntry->pNext;
694 } else {
695 pPrevEntry->pNext =
696 pEntry->pNext;
697 }
698 break;
699 }
700
701 pPrevEntry = pProbeEntry;
702 pProbeEntry = pProbeEntry->pNext;
703 } while (pProbeEntry);
704
705 NdisZeroMemory(pEntry, sizeof(struct rt_tpc_req_entry));
706 pTab->Size--;
707
708 break;
709 }
710
711 if (pEntry->Valid == FALSE)
712 break;
713 }
714
715 if (i < MAX_TPC_REQ_TAB_SIZE) {
716 NdisGetSystemUpTime(&Now);
717 pEntry->lastTime = Now;
718 pEntry->Valid = TRUE;
719 pEntry->DialogToken = DialogToken;
720 pTab->Size++;
721 } else {
722 pEntry = NULL;
723 DBGPRINT(RT_DEBUG_ERROR,
724 ("%s: pTpcReqTab tab full.\n", __func__));
725 }
726
727 /* add this Neighbor entry into HASH table */
728 if (pEntry) {
729 HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken);
730 if (pTab->Hash[HashIdx] == NULL) {
731 pTab->Hash[HashIdx] = pEntry;
732 } else {
733 pCurrEntry = pTab->Hash[HashIdx];
734 while (pCurrEntry->pNext != NULL)
735 pCurrEntry = pCurrEntry->pNext;
736 pCurrEntry->pNext = pEntry;
737 }
738 }
739
740 RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
741 }
742
743 return pEntry;
744}
745
746static void TpcReqDelete(struct rt_rtmp_adapter *pAd, u8 DialogToken)
747{
748 struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab;
749 struct rt_tpc_req_entry *pEntry = NULL;
750
751 if (pTab == NULL) {
752 DBGPRINT(RT_DEBUG_ERROR,
753 ("%s: pTpcReqTab doesn't exist.\n", __func__));
754 return;
755 }
756 /* if empty, return */
757 if (pTab->Size == 0) {
758 DBGPRINT(RT_DEBUG_ERROR, ("pTpcReqTab empty.\n"));
759 return;
760 }
761
762 pEntry = TpcReqLookUp(pAd, DialogToken);
763 if (pEntry != NULL) {
764 struct rt_tpc_req_entry *pPrevEntry = NULL;
765 unsigned long HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken);
766 struct rt_tpc_req_entry *pProbeEntry = pTab->Hash[HashIdx];
767
768 RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock);
769 /* update Hash list */
770 do {
771 if (pProbeEntry == pEntry) {
772 if (pPrevEntry == NULL) {
773 pTab->Hash[HashIdx] = pEntry->pNext;
774 } else {
775 pPrevEntry->pNext = pEntry->pNext;
776 }
777 break;
778 }
779
780 pPrevEntry = pProbeEntry;
781 pProbeEntry = pProbeEntry->pNext;
782 } while (pProbeEntry);
783
784 NdisZeroMemory(pEntry, sizeof(struct rt_tpc_req_entry));
785 pTab->Size--;
786
787 RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock);
788 }
789
790 return;
791}
792
793/*
794 ==========================================================================
795 Description:
796 Get Current TimeS tamp.
797
798 Parametrs:
799
800 Return : Current Time Stamp.
801 ==========================================================================
802 */
803static u64 GetCurrentTimeStamp(struct rt_rtmp_adapter *pAd)
804{
805 /* get current time stamp. */
806 return 0;
807}
808
809/*
810 ==========================================================================
811 Description:
812 Get Current Transmit Power.
813
814 Parametrs:
815
816 Return : Current Time Stamp.
817 ==========================================================================
818 */
819static u8 GetCurTxPwr(struct rt_rtmp_adapter *pAd, u8 Wcid)
820{
821 return 16; /* 16 dBm */
822}
823
824/*
825 ==========================================================================
826 Description:
827 Get Current Transmit Power.
828
829 Parametrs:
830
831 Return : Current Time Stamp.
832 ==========================================================================
833 */
834void InsertChannelRepIE(struct rt_rtmp_adapter *pAd,
835 u8 *pFrameBuf,
836 unsigned long *pFrameLen,
837 char *pCountry, u8 RegulatoryClass)
838{
839 unsigned long TempLen;
840 u8 Len;
841 u8 IEId = IE_AP_CHANNEL_REPORT;
842 u8 *pChListPtr = NULL;
843
844 Len = 1;
845 if (strncmp(pCountry, "US", 2) == 0) {
846 if (RegulatoryClass >= USA_REGULATORY_INFO_SIZE) {
847 DBGPRINT(RT_DEBUG_ERROR,
848 ("%s: USA Unknow Requlatory class (%d)\n",
849 __func__, RegulatoryClass));
850 return;
851 }
852
853 Len +=
854 USARegulatoryInfo[RegulatoryClass].ChannelSet.
855 NumberOfChannels;
856 pChListPtr =
857 USARegulatoryInfo[RegulatoryClass].ChannelSet.ChannelList;
858 } else if (strncmp(pCountry, "JP", 2) == 0) {
859 if (RegulatoryClass >= JP_REGULATORY_INFO_SIZE) {
860 DBGPRINT(RT_DEBUG_ERROR,
861 ("%s: JP Unknow Requlatory class (%d)\n",
862 __func__, RegulatoryClass));
863 return;
864 }
865
866 Len +=
867 JapanRegulatoryInfo[RegulatoryClass].ChannelSet.
868 NumberOfChannels;
869 pChListPtr =
870 JapanRegulatoryInfo[RegulatoryClass].ChannelSet.ChannelList;
871 } else {
872 DBGPRINT(RT_DEBUG_ERROR, ("%s: Unknow Country (%s)\n",
873 __func__, pCountry));
874 return;
875 }
876
877 MakeOutgoingFrame(pFrameBuf, &TempLen,
878 1, &IEId,
879 1, &Len,
880 1, &RegulatoryClass,
881 Len - 1, pChListPtr, END_OF_ARGS);
882
883 *pFrameLen = *pFrameLen + TempLen;
884
885 return;
886}
887
888/*
889 ==========================================================================
890 Description:
891 Insert Dialog Token into frame.
892
893 Parametrs:
894 1. frame buffer pointer.
895 2. frame length.
896 3. Dialog token.
897
898 Return : None.
899 ==========================================================================
900 */
901void InsertDialogToken(struct rt_rtmp_adapter *pAd,
902 u8 *pFrameBuf,
903 unsigned long *pFrameLen, u8 DialogToken)
904{
905 unsigned long TempLen;
906 MakeOutgoingFrame(pFrameBuf, &TempLen, 1, &DialogToken, END_OF_ARGS);
907
908 *pFrameLen = *pFrameLen + TempLen;
909
910 return;
911}
912
913/*
914 ==========================================================================
915 Description:
916 Insert TPC Request IE into frame.
917
918 Parametrs:
919 1. frame buffer pointer.
920 2. frame length.
921
922 Return : None.
923 ==========================================================================
924 */
925static void InsertTpcReqIE(struct rt_rtmp_adapter *pAd,
926 u8 *pFrameBuf, unsigned long *pFrameLen)
927{
928 unsigned long TempLen;
929 unsigned long Len = 0;
930 u8 ElementID = IE_TPC_REQUEST;
931
932 MakeOutgoingFrame(pFrameBuf, &TempLen,
933 1, &ElementID, 1, &Len, END_OF_ARGS);
934
935 *pFrameLen = *pFrameLen + TempLen;
936
937 return;
938}
939
940/*
941 ==========================================================================
942 Description:
943 Insert TPC Report IE into frame.
944
945 Parametrs:
946 1. frame buffer pointer.
947 2. frame length.
948 3. Transmit Power.
949 4. Link Margin.
950
951 Return : None.
952 ==========================================================================
953 */
954void InsertTpcReportIE(struct rt_rtmp_adapter *pAd,
955 u8 *pFrameBuf,
956 unsigned long *pFrameLen,
957 u8 TxPwr, u8 LinkMargin)
958{
959 unsigned long TempLen;
960 unsigned long Len = sizeof(struct rt_tpc_report_info);
961 u8 ElementID = IE_TPC_REPORT;
962 struct rt_tpc_report_info TpcReportIE;
963
964 TpcReportIE.TxPwr = TxPwr;
965 TpcReportIE.LinkMargin = LinkMargin;
966
967 MakeOutgoingFrame(pFrameBuf, &TempLen,
968 1, &ElementID,
969 1, &Len, Len, &TpcReportIE, END_OF_ARGS);
970
971 *pFrameLen = *pFrameLen + TempLen;
972
973 return;
974}
975
976/*
977 ==========================================================================
978 Description:
979 Insert Channel Switch Announcement IE into frame.
980
981 Parametrs:
982 1. frame buffer pointer.
983 2. frame length.
984 3. channel switch announcement mode.
985 4. new selected channel.
986 5. channel switch announcement count.
987
988 Return : None.
989 ==========================================================================
990 */
991static void InsertChSwAnnIE(struct rt_rtmp_adapter *pAd,
992 u8 *pFrameBuf,
993 unsigned long *pFrameLen,
994 u8 ChSwMode,
995 u8 NewChannel, u8 ChSwCnt)
996{
997 unsigned long TempLen;
998 unsigned long Len = sizeof(struct rt_ch_sw_ann_info);
999 u8 ElementID = IE_CHANNEL_SWITCH_ANNOUNCEMENT;
1000 struct rt_ch_sw_ann_info ChSwAnnIE;
1001
1002 ChSwAnnIE.ChSwMode = ChSwMode;
1003 ChSwAnnIE.Channel = NewChannel;
1004 ChSwAnnIE.ChSwCnt = ChSwCnt;
1005
1006 MakeOutgoingFrame(pFrameBuf, &TempLen,
1007 1, &ElementID, 1, &Len, Len, &ChSwAnnIE, END_OF_ARGS);
1008
1009 *pFrameLen = *pFrameLen + TempLen;
1010
1011 return;
1012}
1013
1014/*
1015 ==========================================================================
1016 Description:
1017 Insert Measure Request IE into frame.
1018
1019 Parametrs:
1020 1. frame buffer pointer.
1021 2. frame length.
1022 3. Measure Token.
1023 4. Measure Request Mode.
1024 5. Measure Request Type.
1025 6. Measure Channel.
1026 7. Measure Start time.
1027 8. Measure Duration.
1028
1029 Return : None.
1030 ==========================================================================
1031 */
1032static void InsertMeasureReqIE(struct rt_rtmp_adapter *pAd,
1033 u8 *pFrameBuf,
1034 unsigned long *pFrameLen,
1035 u8 Len, struct rt_measure_req_info * pMeasureReqIE)
1036{
1037 unsigned long TempLen;
1038 u8 ElementID = IE_MEASUREMENT_REQUEST;
1039
1040 MakeOutgoingFrame(pFrameBuf, &TempLen,
1041 1, &ElementID,
1042 1, &Len,
1043 sizeof(struct rt_measure_req_info), pMeasureReqIE, END_OF_ARGS);
1044
1045 *pFrameLen = *pFrameLen + TempLen;
1046
1047 return;
1048}
1049
1050/*
1051 ==========================================================================
1052 Description:
1053 Insert Measure Report IE into frame.
1054
1055 Parametrs:
1056 1. frame buffer pointer.
1057 2. frame length.
1058 3. Measure Token.
1059 4. Measure Request Mode.
1060 5. Measure Request Type.
1061 6. Length of Report Information
1062 7. Pointer of Report Information Buffer.
1063
1064 Return : None.
1065 ==========================================================================
1066 */
1067static void InsertMeasureReportIE(struct rt_rtmp_adapter *pAd,
1068 u8 *pFrameBuf,
1069 unsigned long *pFrameLen,
1070 struct rt_measure_report_info * pMeasureReportIE,
1071 u8 ReportLnfoLen, u8 *pReportInfo)
1072{
1073 unsigned long TempLen;
1074 unsigned long Len;
1075 u8 ElementID = IE_MEASUREMENT_REPORT;
1076
1077 Len = sizeof(struct rt_measure_report_info) + ReportLnfoLen;
1078
1079 MakeOutgoingFrame(pFrameBuf, &TempLen,
1080 1, &ElementID,
1081 1, &Len, Len, pMeasureReportIE, END_OF_ARGS);
1082
1083 *pFrameLen = *pFrameLen + TempLen;
1084
1085 if ((ReportLnfoLen > 0) && (pReportInfo != NULL)) {
1086 MakeOutgoingFrame(pFrameBuf + *pFrameLen, &TempLen,
1087 ReportLnfoLen, pReportInfo, END_OF_ARGS);
1088
1089 *pFrameLen = *pFrameLen + TempLen;
1090 }
1091 return;
1092}
1093
1094/*
1095 ==========================================================================
1096 Description:
1097 Prepare Measurement request action frame and enqueue it into
1098 management queue waiting for transmition.
1099
1100 Parametrs:
1101 1. the destination mac address of the frame.
1102
1103 Return : None.
1104 ==========================================================================
1105 */
1106void MakeMeasurementReqFrame(struct rt_rtmp_adapter *pAd,
1107 u8 *pOutBuffer,
1108 unsigned long *pFrameLen,
1109 u8 TotalLen,
1110 u8 Category,
1111 u8 Action,
1112 u8 MeasureToken,
1113 u8 MeasureReqMode,
1114 u8 MeasureReqType, u8 NumOfRepetitions)
1115{
1116 unsigned long TempLen;
1117 struct rt_measure_req_info MeasureReqIE;
1118
1119 InsertActField(pAd, (pOutBuffer + *pFrameLen), pFrameLen, Category,
1120 Action);
1121
1122 /* fill Dialog Token */
1123 InsertDialogToken(pAd, (pOutBuffer + *pFrameLen), pFrameLen,
1124 MeasureToken);
1125
1126 /* fill Number of repetitions. */
1127 if (Category == CATEGORY_RM) {
1128 MakeOutgoingFrame((pOutBuffer + *pFrameLen), &TempLen,
1129 2, &NumOfRepetitions, END_OF_ARGS);
1130
1131 *pFrameLen += TempLen;
1132 }
1133 /* prepare Measurement IE. */
1134 NdisZeroMemory(&MeasureReqIE, sizeof(struct rt_measure_req_info));
1135 MeasureReqIE.Token = MeasureToken;
1136 MeasureReqIE.ReqMode.word = MeasureReqMode;
1137 MeasureReqIE.ReqType = MeasureReqType;
1138 InsertMeasureReqIE(pAd, (pOutBuffer + *pFrameLen), pFrameLen,
1139 TotalLen, &MeasureReqIE);
1140
1141 return;
1142}
1143
1144/*
1145 ==========================================================================
1146 Description:
1147 Prepare Measurement report action frame and enqueue it into
1148 management queue waiting for transmition.
1149
1150 Parametrs:
1151 1. the destination mac address of the frame.
1152
1153 Return : None.
1154 ==========================================================================
1155 */
1156void EnqueueMeasurementRep(struct rt_rtmp_adapter *pAd,
1157 u8 *pDA,
1158 u8 DialogToken,
1159 u8 MeasureToken,
1160 u8 MeasureReqMode,
1161 u8 MeasureReqType,
1162 u8 ReportInfoLen, u8 *pReportInfo)
1163{
1164 u8 *pOutBuffer = NULL;
1165 int NStatus;
1166 unsigned long FrameLen;
1167 struct rt_header_802_11 ActHdr;
1168 struct rt_measure_report_info MeasureRepIE;
1169
1170 /* build action frame header. */
1171 MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
1172 pAd->CurrentAddress);
1173
1174 NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */
1175 if (NStatus != NDIS_STATUS_SUCCESS) {
1176 DBGPRINT(RT_DEBUG_TRACE,
1177 ("%s() allocate memory failed \n", __func__));
1178 return;
1179 }
1180 NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
1181 FrameLen = sizeof(struct rt_header_802_11);
1182
1183 InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen,
1184 CATEGORY_SPECTRUM, SPEC_MRP);
1185
1186 /* fill Dialog Token */
1187 InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
1188
1189 /* prepare Measurement IE. */
1190 NdisZeroMemory(&MeasureRepIE, sizeof(struct rt_measure_report_info));
1191 MeasureRepIE.Token = MeasureToken;
1192 MeasureRepIE.ReportMode = MeasureReqMode;
1193 MeasureRepIE.ReportType = MeasureReqType;
1194 InsertMeasureReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen,
1195 &MeasureRepIE, ReportInfoLen, pReportInfo);
1196
1197 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
1198 MlmeFreeMemory(pAd, pOutBuffer);
1199
1200 return;
1201}
1202
1203/*
1204 ==========================================================================
1205 Description:
1206 Prepare TPC Request action frame and enqueue it into
1207 management queue waiting for transmition.
1208
1209 Parametrs:
1210 1. the destination mac address of the frame.
1211
1212 Return : None.
1213 ==========================================================================
1214 */
1215void EnqueueTPCReq(struct rt_rtmp_adapter *pAd, u8 *pDA, u8 DialogToken)
1216{
1217 u8 *pOutBuffer = NULL;
1218 int NStatus;
1219 unsigned long FrameLen;
1220
1221 struct rt_header_802_11 ActHdr;
1222
1223 /* build action frame header. */
1224 MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
1225 pAd->CurrentAddress);
1226
1227 NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */
1228 if (NStatus != NDIS_STATUS_SUCCESS) {
1229 DBGPRINT(RT_DEBUG_TRACE,
1230 ("%s() allocate memory failed \n", __func__));
1231 return;
1232 }
1233 NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
1234 FrameLen = sizeof(struct rt_header_802_11);
1235
1236 InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen,
1237 CATEGORY_SPECTRUM, SPEC_TPCRQ);
1238
1239 /* fill Dialog Token */
1240 InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
1241
1242 /* Insert TPC Request IE. */
1243 InsertTpcReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen);
1244
1245 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
1246 MlmeFreeMemory(pAd, pOutBuffer);
1247
1248 return;
1249}
1250
1251/*
1252 ==========================================================================
1253 Description:
1254 Prepare TPC Report action frame and enqueue it into
1255 management queue waiting for transmition.
1256
1257 Parametrs:
1258 1. the destination mac address of the frame.
1259
1260 Return : None.
1261 ==========================================================================
1262 */
1263void EnqueueTPCRep(struct rt_rtmp_adapter *pAd,
1264 u8 *pDA,
1265 u8 DialogToken, u8 TxPwr, u8 LinkMargin)
1266{
1267 u8 *pOutBuffer = NULL;
1268 int NStatus;
1269 unsigned long FrameLen;
1270
1271 struct rt_header_802_11 ActHdr;
1272
1273 /* build action frame header. */
1274 MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
1275 pAd->CurrentAddress);
1276
1277 NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */
1278 if (NStatus != NDIS_STATUS_SUCCESS) {
1279 DBGPRINT(RT_DEBUG_TRACE,
1280 ("%s() allocate memory failed \n", __func__));
1281 return;
1282 }
1283 NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
1284 FrameLen = sizeof(struct rt_header_802_11);
1285
1286 InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen,
1287 CATEGORY_SPECTRUM, SPEC_TPCRP);
1288
1289 /* fill Dialog Token */
1290 InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken);
1291
1292 /* Insert TPC Request IE. */
1293 InsertTpcReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, TxPwr,
1294 LinkMargin);
1295
1296 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
1297 MlmeFreeMemory(pAd, pOutBuffer);
1298
1299 return;
1300}
1301
1302/*
1303 ==========================================================================
1304 Description:
1305 Prepare Channel Switch Announcement action frame and enqueue it into
1306 management queue waiting for transmition.
1307
1308 Parametrs:
1309 1. the destination mac address of the frame.
1310 2. Channel switch announcement mode.
1311 2. a New selected channel.
1312
1313 Return : None.
1314 ==========================================================================
1315 */
1316void EnqueueChSwAnn(struct rt_rtmp_adapter *pAd,
1317 u8 *pDA, u8 ChSwMode, u8 NewCh)
1318{
1319 u8 *pOutBuffer = NULL;
1320 int NStatus;
1321 unsigned long FrameLen;
1322
1323 struct rt_header_802_11 ActHdr;
1324
1325 /* build action frame header. */
1326 MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
1327 pAd->CurrentAddress);
1328
1329 NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */
1330 if (NStatus != NDIS_STATUS_SUCCESS) {
1331 DBGPRINT(RT_DEBUG_TRACE,
1332 ("%s() allocate memory failed \n", __func__));
1333 return;
1334 }
1335 NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
1336 FrameLen = sizeof(struct rt_header_802_11);
1337
1338 InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen,
1339 CATEGORY_SPECTRUM, SPEC_CHANNEL_SWITCH);
1340
1341 InsertChSwAnnIE(pAd, (pOutBuffer + FrameLen), &FrameLen, ChSwMode,
1342 NewCh, 0);
1343
1344 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
1345 MlmeFreeMemory(pAd, pOutBuffer);
1346
1347 return;
1348}
1349
1350static BOOLEAN DfsRequirementCheck(struct rt_rtmp_adapter *pAd, u8 Channel)
1351{
1352 BOOLEAN Result = FALSE;
1353 int i;
1354
1355 do {
1356 /* check DFS procedure is running. */
1357 /* make sure DFS procedure won't start twice. */
1358 if (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE) {
1359 Result = FALSE;
1360 break;
1361 }
1362 /* check the new channel carried from Channel Switch Announcemnet is valid. */
1363 for (i = 0; i < pAd->ChannelListNum; i++) {
1364 if ((Channel == pAd->ChannelList[i].Channel)
1365 && (pAd->ChannelList[i].RemainingTimeForUse == 0)) {
1366 /* found radar signal in the channel. the channel can't use at least for 30 minutes. */
1367 pAd->ChannelList[i].RemainingTimeForUse = 1800; /*30 min = 1800 sec */
1368 Result = TRUE;
1369 break;
1370 }
1371 }
1372 } while (FALSE);
1373
1374 return Result;
1375}
1376
1377void NotifyChSwAnnToPeerAPs(struct rt_rtmp_adapter *pAd,
1378 u8 *pRA,
1379 u8 *pTA, u8 ChSwMode, u8 Channel)
1380{
1381}
1382
1383static void StartDFSProcedure(struct rt_rtmp_adapter *pAd,
1384 u8 Channel, u8 ChSwMode)
1385{
1386 /* start DFS procedure */
1387 pAd->CommonCfg.Channel = Channel;
1388
1389 N_ChannelCheck(pAd);
1390
1391 pAd->CommonCfg.RadarDetect.RDMode = RD_SWITCHING_MODE;
1392 pAd->CommonCfg.RadarDetect.CSCount = 0;
1393}
1394
1395/*
1396 ==========================================================================
1397 Description:
1398 Channel Switch Announcement action frame sanity check.
1399
1400 Parametrs:
1401 1. MLME message containing the received frame
1402 2. message length.
1403 3. Channel switch announcement information buffer.
1404
1405 Return : None.
1406 ==========================================================================
1407 */
1408
1409/*
1410 Channel Switch Announcement IE.
1411 +----+-----+-----------+------------+-----------+
1412 | ID | Len |Ch Sw Mode | New Ch Num | Ch Sw Cnt |
1413 +----+-----+-----------+------------+-----------+
1414 1 1 1 1 1
1415*/
1416static BOOLEAN PeerChSwAnnSanity(struct rt_rtmp_adapter *pAd,
1417 void * pMsg,
1418 unsigned long MsgLen,
1419 struct rt_ch_sw_ann_info * pChSwAnnInfo)
1420{
1421 struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
1422 u8 *pFramePtr = Fr->Octet;
1423 BOOLEAN result = FALSE;
1424 struct rt_eid * eid_ptr;
1425
1426 /* skip 802.11 header. */
1427 MsgLen -= sizeof(struct rt_header_802_11);
1428
1429 /* skip category and action code. */
1430 pFramePtr += 2;
1431 MsgLen -= 2;
1432
1433 if (pChSwAnnInfo == NULL)
1434 return result;
1435
1436 eid_ptr = (struct rt_eid *) pFramePtr;
1437 while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
1438 ((u8 *)pFramePtr + MsgLen)) {
1439 switch (eid_ptr->Eid) {
1440 case IE_CHANNEL_SWITCH_ANNOUNCEMENT:
1441 NdisMoveMemory(&pChSwAnnInfo->ChSwMode, eid_ptr->Octet,
1442 1);
1443 NdisMoveMemory(&pChSwAnnInfo->Channel,
1444 eid_ptr->Octet + 1, 1);
1445 NdisMoveMemory(&pChSwAnnInfo->ChSwCnt,
1446 eid_ptr->Octet + 2, 1);
1447
1448 result = TRUE;
1449 break;
1450
1451 default:
1452 break;
1453 }
1454 eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
1455 }
1456
1457 return result;
1458}
1459
1460/*
1461 ==========================================================================
1462 Description:
1463 Measurement request action frame sanity check.
1464
1465 Parametrs:
1466 1. MLME message containing the received frame
1467 2. message length.
1468 3. Measurement request information buffer.
1469
1470 Return : None.
1471 ==========================================================================
1472 */
1473static BOOLEAN PeerMeasureReqSanity(struct rt_rtmp_adapter *pAd,
1474 void * pMsg,
1475 unsigned long MsgLen,
1476 u8 *pDialogToken,
1477 struct rt_measure_req_info * pMeasureReqInfo,
1478 struct rt_measure_req * pMeasureReq)
1479{
1480 struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
1481 u8 *pFramePtr = Fr->Octet;
1482 BOOLEAN result = FALSE;
1483 struct rt_eid * eid_ptr;
1484 u8 *ptr;
1485 u64 MeasureStartTime;
1486 u16 MeasureDuration;
1487
1488 /* skip 802.11 header. */
1489 MsgLen -= sizeof(struct rt_header_802_11);
1490
1491 /* skip category and action code. */
1492 pFramePtr += 2;
1493 MsgLen -= 2;
1494
1495 if (pMeasureReqInfo == NULL)
1496 return result;
1497
1498 NdisMoveMemory(pDialogToken, pFramePtr, 1);
1499 pFramePtr += 1;
1500 MsgLen -= 1;
1501
1502 eid_ptr = (struct rt_eid *) pFramePtr;
1503 while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
1504 ((u8 *)pFramePtr + MsgLen)) {
1505 switch (eid_ptr->Eid) {
1506 case IE_MEASUREMENT_REQUEST:
1507 NdisMoveMemory(&pMeasureReqInfo->Token, eid_ptr->Octet,
1508 1);
1509 NdisMoveMemory(&pMeasureReqInfo->ReqMode.word,
1510 eid_ptr->Octet + 1, 1);
1511 NdisMoveMemory(&pMeasureReqInfo->ReqType,
1512 eid_ptr->Octet + 2, 1);
1513 ptr = (u8 *)(eid_ptr->Octet + 3);
1514 NdisMoveMemory(&pMeasureReq->ChNum, ptr, 1);
1515 NdisMoveMemory(&MeasureStartTime, ptr + 1, 8);
1516 pMeasureReq->MeasureStartTime =
1517 SWAP64(MeasureStartTime);
1518 NdisMoveMemory(&MeasureDuration, ptr + 9, 2);
1519 pMeasureReq->MeasureDuration = SWAP16(MeasureDuration);
1520
1521 result = TRUE;
1522 break;
1523
1524 default:
1525 break;
1526 }
1527 eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
1528 }
1529
1530 return result;
1531}
1532
1533/*
1534 ==========================================================================
1535 Description:
1536 Measurement report action frame sanity check.
1537
1538 Parametrs:
1539 1. MLME message containing the received frame
1540 2. message length.
1541 3. Measurement report information buffer.
1542 4. basic report information buffer.
1543
1544 Return : None.
1545 ==========================================================================
1546 */
1547
1548/*
1549 Measurement Report IE.
1550 +----+-----+-------+-------------+--------------+----------------+
1551 | ID | Len | Token | Report Mode | Measure Type | Measure Report |
1552 +----+-----+-------+-------------+--------------+----------------+
1553 1 1 1 1 1 variable
1554
1555 Basic Report.
1556 +--------+------------+----------+-----+
1557 | Ch Num | Start Time | Duration | Map |
1558 +--------+------------+----------+-----+
1559 1 8 2 1
1560
1561 Map Field Bit Format.
1562 +-----+---------------+---------------------+-------+------------+----------+
1563 | Bss | OFDM Preamble | Unidentified signal | Radar | Unmeasured | Reserved |
1564 +-----+---------------+---------------------+-------+------------+----------+
1565 0 1 2 3 4 5-7
1566*/
1567static BOOLEAN PeerMeasureReportSanity(struct rt_rtmp_adapter *pAd,
1568 void * pMsg,
1569 unsigned long MsgLen,
1570 u8 *pDialogToken,
1571 struct rt_measure_report_info *
1572 pMeasureReportInfo,
1573 u8 *pReportBuf)
1574{
1575 struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
1576 u8 *pFramePtr = Fr->Octet;
1577 BOOLEAN result = FALSE;
1578 struct rt_eid * eid_ptr;
1579 u8 *ptr;
1580
1581 /* skip 802.11 header. */
1582 MsgLen -= sizeof(struct rt_header_802_11);
1583
1584 /* skip category and action code. */
1585 pFramePtr += 2;
1586 MsgLen -= 2;
1587
1588 if (pMeasureReportInfo == NULL)
1589 return result;
1590
1591 NdisMoveMemory(pDialogToken, pFramePtr, 1);
1592 pFramePtr += 1;
1593 MsgLen -= 1;
1594
1595 eid_ptr = (struct rt_eid *) pFramePtr;
1596 while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
1597 ((u8 *)pFramePtr + MsgLen)) {
1598 switch (eid_ptr->Eid) {
1599 case IE_MEASUREMENT_REPORT:
1600 NdisMoveMemory(&pMeasureReportInfo->Token,
1601 eid_ptr->Octet, 1);
1602 NdisMoveMemory(&pMeasureReportInfo->ReportMode,
1603 eid_ptr->Octet + 1, 1);
1604 NdisMoveMemory(&pMeasureReportInfo->ReportType,
1605 eid_ptr->Octet + 2, 1);
1606 if (pMeasureReportInfo->ReportType == RM_BASIC) {
1607 struct rt_measure_basic_report * pReport =
1608 (struct rt_measure_basic_report *) pReportBuf;
1609 ptr = (u8 *)(eid_ptr->Octet + 3);
1610 NdisMoveMemory(&pReport->ChNum, ptr, 1);
1611 NdisMoveMemory(&pReport->MeasureStartTime,
1612 ptr + 1, 8);
1613 NdisMoveMemory(&pReport->MeasureDuration,
1614 ptr + 9, 2);
1615 NdisMoveMemory(&pReport->Map, ptr + 11, 1);
1616
1617 } else if (pMeasureReportInfo->ReportType == RM_CCA) {
1618 struct rt_measure_cca_report * pReport =
1619 (struct rt_measure_cca_report *) pReportBuf;
1620 ptr = (u8 *)(eid_ptr->Octet + 3);
1621 NdisMoveMemory(&pReport->ChNum, ptr, 1);
1622 NdisMoveMemory(&pReport->MeasureStartTime,
1623 ptr + 1, 8);
1624 NdisMoveMemory(&pReport->MeasureDuration,
1625 ptr + 9, 2);
1626 NdisMoveMemory(&pReport->CCA_Busy_Fraction,
1627 ptr + 11, 1);
1628
1629 } else if (pMeasureReportInfo->ReportType ==
1630 RM_RPI_HISTOGRAM) {
1631 struct rt_measure_rpi_report * pReport =
1632 (struct rt_measure_rpi_report *) pReportBuf;
1633 ptr = (u8 *)(eid_ptr->Octet + 3);
1634 NdisMoveMemory(&pReport->ChNum, ptr, 1);
1635 NdisMoveMemory(&pReport->MeasureStartTime,
1636 ptr + 1, 8);
1637 NdisMoveMemory(&pReport->MeasureDuration,
1638 ptr + 9, 2);
1639 NdisMoveMemory(&pReport->RPI_Density, ptr + 11,
1640 8);
1641 }
1642 result = TRUE;
1643 break;
1644
1645 default:
1646 break;
1647 }
1648 eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
1649 }
1650
1651 return result;
1652}
1653
1654/*
1655 ==========================================================================
1656 Description:
1657 TPC Request action frame sanity check.
1658
1659 Parametrs:
1660 1. MLME message containing the received frame
1661 2. message length.
1662 3. Dialog Token.
1663
1664 Return : None.
1665 ==========================================================================
1666 */
1667static BOOLEAN PeerTpcReqSanity(struct rt_rtmp_adapter *pAd,
1668 void * pMsg,
1669 unsigned long MsgLen, u8 *pDialogToken)
1670{
1671 struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
1672 u8 *pFramePtr = Fr->Octet;
1673 BOOLEAN result = FALSE;
1674 struct rt_eid * eid_ptr;
1675
1676 MsgLen -= sizeof(struct rt_header_802_11);
1677
1678 /* skip category and action code. */
1679 pFramePtr += 2;
1680 MsgLen -= 2;
1681
1682 if (pDialogToken == NULL)
1683 return result;
1684
1685 NdisMoveMemory(pDialogToken, pFramePtr, 1);
1686 pFramePtr += 1;
1687 MsgLen -= 1;
1688
1689 eid_ptr = (struct rt_eid *) pFramePtr;
1690 while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
1691 ((u8 *)pFramePtr + MsgLen)) {
1692 switch (eid_ptr->Eid) {
1693 case IE_TPC_REQUEST:
1694 result = TRUE;
1695 break;
1696
1697 default:
1698 break;
1699 }
1700 eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
1701 }
1702
1703 return result;
1704}
1705
1706/*
1707 ==========================================================================
1708 Description:
1709 TPC Report action frame sanity check.
1710
1711 Parametrs:
1712 1. MLME message containing the received frame
1713 2. message length.
1714 3. Dialog Token.
1715 4. TPC Report IE.
1716
1717 Return : None.
1718 ==========================================================================
1719 */
1720static BOOLEAN PeerTpcRepSanity(struct rt_rtmp_adapter *pAd,
1721 void * pMsg,
1722 unsigned long MsgLen,
1723 u8 *pDialogToken,
1724 struct rt_tpc_report_info * pTpcRepInfo)
1725{
1726 struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg;
1727 u8 *pFramePtr = Fr->Octet;
1728 BOOLEAN result = FALSE;
1729 struct rt_eid * eid_ptr;
1730
1731 MsgLen -= sizeof(struct rt_header_802_11);
1732
1733 /* skip category and action code. */
1734 pFramePtr += 2;
1735 MsgLen -= 2;
1736
1737 if (pDialogToken == NULL)
1738 return result;
1739
1740 NdisMoveMemory(pDialogToken, pFramePtr, 1);
1741 pFramePtr += 1;
1742 MsgLen -= 1;
1743
1744 eid_ptr = (struct rt_eid *) pFramePtr;
1745 while (((u8 *) eid_ptr + eid_ptr->Len + 1) <
1746 ((u8 *)pFramePtr + MsgLen)) {
1747 switch (eid_ptr->Eid) {
1748 case IE_TPC_REPORT:
1749 NdisMoveMemory(&pTpcRepInfo->TxPwr, eid_ptr->Octet, 1);
1750 NdisMoveMemory(&pTpcRepInfo->LinkMargin,
1751 eid_ptr->Octet + 1, 1);
1752 result = TRUE;
1753 break;
1754
1755 default:
1756 break;
1757 }
1758 eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len);
1759 }
1760
1761 return result;
1762}
1763
1764/*
1765 ==========================================================================
1766 Description:
1767 Channel Switch Announcement action frame handler.
1768
1769 Parametrs:
1770 Elme - MLME message containing the received frame
1771
1772 Return : None.
1773 ==========================================================================
1774 */
1775static void PeerChSwAnnAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1776{
1777 struct rt_ch_sw_ann_info ChSwAnnInfo;
1778 struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg;
1779 u8 index = 0, Channel = 0, NewChannel = 0;
1780 unsigned long Bssidx = 0;
1781
1782 NdisZeroMemory(&ChSwAnnInfo, sizeof(struct rt_ch_sw_ann_info));
1783 if (!PeerChSwAnnSanity(pAd, Elem->Msg, Elem->MsgLen, &ChSwAnnInfo)) {
1784 DBGPRINT(RT_DEBUG_TRACE,
1785 ("Invalid Channel Switch Action Frame.\n"));
1786 return;
1787 }
1788
1789 if (pAd->OpMode == OPMODE_STA) {
1790 Bssidx =
1791 BssTableSearch(&pAd->ScanTab, pFr->Hdr.Addr3,
1792 pAd->CommonCfg.Channel);
1793 if (Bssidx == BSS_NOT_FOUND) {
1794 DBGPRINT(RT_DEBUG_TRACE,
1795 ("PeerChSwAnnAction - Bssidx is not found\n"));
1796 return;
1797 }
1798
1799 DBGPRINT(RT_DEBUG_TRACE,
1800 ("\n****Bssidx is %d, Channel = %d\n", index,
1801 pAd->ScanTab.BssEntry[Bssidx].Channel));
1802 hex_dump("SSID", pAd->ScanTab.BssEntry[Bssidx].Bssid, 6);
1803
1804 Channel = pAd->CommonCfg.Channel;
1805 NewChannel = ChSwAnnInfo.Channel;
1806
1807 if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0)
1808 && (Channel != NewChannel)) {
1809 /* Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection). */
1810 /* In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results. */
1811 AsicSwitchChannel(pAd, 1, FALSE);
1812 AsicLockChannel(pAd, 1);
1813 LinkDown(pAd, FALSE);
1814 MlmeQueueInit(&pAd->Mlme.Queue);
1815 BssTableInit(&pAd->ScanTab);
1816 RTMPusecDelay(1000000); /* use delay to prevent STA do reassoc */
1817
1818 /* channel sanity check */
1819 for (index = 0; index < pAd->ChannelListNum; index++) {
1820 if (pAd->ChannelList[index].Channel ==
1821 NewChannel) {
1822 pAd->ScanTab.BssEntry[Bssidx].Channel =
1823 NewChannel;
1824 pAd->CommonCfg.Channel = NewChannel;
1825 AsicSwitchChannel(pAd,
1826 pAd->CommonCfg.
1827 Channel, FALSE);
1828 AsicLockChannel(pAd,
1829 pAd->CommonCfg.Channel);
1830 DBGPRINT(RT_DEBUG_TRACE,
1831 ("&&&&&&&&&&&&&&&&PeerChSwAnnAction - STA receive channel switch announcement IE (New Channel =%d)\n",
1832 NewChannel));
1833 break;
1834 }
1835 }
1836
1837 if (index >= pAd->ChannelListNum) {
1838 DBGPRINT_ERR("&&&&&&&&&&&&&&&&&&&&&&&&&&PeerChSwAnnAction(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum);
1839 }
1840 }
1841 }
1842
1843 return;
1844}
1845
1846/*
1847 ==========================================================================
1848 Description:
1849 Measurement Request action frame handler.
1850
1851 Parametrs:
1852 Elme - MLME message containing the received frame
1853
1854 Return : None.
1855 ==========================================================================
1856 */
1857static void PeerMeasureReqAction(struct rt_rtmp_adapter *pAd,
1858 struct rt_mlme_queue_elem *Elem)
1859{
1860 struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg;
1861 u8 DialogToken;
1862 struct rt_measure_req_info MeasureReqInfo;
1863 struct rt_measure_req MeasureReq;
1864 MEASURE_REPORT_MODE ReportMode;
1865
1866 if (PeerMeasureReqSanity
1867 (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReqInfo,
1868 &MeasureReq)) {
1869 ReportMode.word = 0;
1870 ReportMode.field.Incapable = 1;
1871 EnqueueMeasurementRep(pAd, pFr->Hdr.Addr2, DialogToken,
1872 MeasureReqInfo.Token, ReportMode.word,
1873 MeasureReqInfo.ReqType, 0, NULL);
1874 }
1875
1876 return;
1877}
1878
1879/*
1880 ==========================================================================
1881 Description:
1882 Measurement Report action frame handler.
1883
1884 Parametrs:
1885 Elme - MLME message containing the received frame
1886
1887 Return : None.
1888 ==========================================================================
1889 */
1890static void PeerMeasureReportAction(struct rt_rtmp_adapter *pAd,
1891 struct rt_mlme_queue_elem *Elem)
1892{
1893 struct rt_measure_report_info MeasureReportInfo;
1894 struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg;
1895 u8 DialogToken;
1896 u8 *pMeasureReportInfo;
1897
1898/* if (pAd->CommonCfg.bIEEE80211H != TRUE) */
1899/* return; */
1900
1901 pMeasureReportInfo = kmalloc(sizeof(struct rt_measure_rpi_report), GFP_ATOMIC);
1902 if (pMeasureReportInfo == NULL) {
1903 DBGPRINT(RT_DEBUG_ERROR,
1904 ("%s unable to alloc memory for measure report buffer (size=%zu).\n",
1905 __func__, sizeof(struct rt_measure_rpi_report)));
1906 return;
1907 }
1908
1909 NdisZeroMemory(&MeasureReportInfo, sizeof(struct rt_measure_report_info));
1910 NdisZeroMemory(pMeasureReportInfo, sizeof(struct rt_measure_rpi_report));
1911 if (PeerMeasureReportSanity
1912 (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReportInfo,
1913 pMeasureReportInfo)) {
1914 do {
1915 struct rt_measure_req_entry *pEntry = NULL;
1916
1917 /* Not a autonomous measure report. */
1918 /* check the dialog token field. drop it if the dialog token doesn't match. */
1919 if ((DialogToken != 0)
1920 && ((pEntry = MeasureReqLookUp(pAd, DialogToken)) ==
1921 NULL))
1922 break;
1923
1924 if (pEntry != NULL)
1925 MeasureReqDelete(pAd, pEntry->DialogToken);
1926
1927 if (MeasureReportInfo.ReportType == RM_BASIC) {
1928 struct rt_measure_basic_report * pBasicReport =
1929 (struct rt_measure_basic_report *) pMeasureReportInfo;
1930 if ((pBasicReport->Map.field.Radar)
1931 &&
1932 (DfsRequirementCheck
1933 (pAd, pBasicReport->ChNum) == TRUE)) {
1934 NotifyChSwAnnToPeerAPs(pAd,
1935 pFr->Hdr.Addr1,
1936 pFr->Hdr.Addr2,
1937 1,
1938 pBasicReport->
1939 ChNum);
1940 StartDFSProcedure(pAd,
1941 pBasicReport->ChNum,
1942 1);
1943 }
1944 }
1945 } while (FALSE);
1946 } else
1947 DBGPRINT(RT_DEBUG_TRACE,
1948 ("Invalid Measurement Report Frame.\n"));
1949
1950 kfree(pMeasureReportInfo);
1951
1952 return;
1953}
1954
1955/*
1956 ==========================================================================
1957 Description:
1958 TPC Request action frame handler.
1959
1960 Parametrs:
1961 Elme - MLME message containing the received frame
1962
1963 Return : None.
1964 ==========================================================================
1965 */
1966static void PeerTpcReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1967{
1968 struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg;
1969 u8 *pFramePtr = pFr->Octet;
1970 u8 DialogToken;
1971 u8 TxPwr = GetCurTxPwr(pAd, Elem->Wcid);
1972 u8 LinkMargin = 0;
1973 char RealRssi;
1974
1975 /* link margin: Ratio of the received signal power to the minimum desired by the station (STA). The */
1976 /* STA may incorporate rate information and channel conditions, including interference, into its computation */
1977 /* of link margin. */
1978
1979 RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0),
1980 ConvertToRssi(pAd, Elem->Rssi1, RSSI_1),
1981 ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
1982
1983 /* skip Category and action code. */
1984 pFramePtr += 2;
1985
1986 /* Dialog token. */
1987 NdisMoveMemory(&DialogToken, pFramePtr, 1);
1988
1989 LinkMargin = (RealRssi / MIN_RCV_PWR);
1990 if (PeerTpcReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken))
1991 EnqueueTPCRep(pAd, pFr->Hdr.Addr2, DialogToken, TxPwr,
1992 LinkMargin);
1993
1994 return;
1995}
1996
1997/*
1998 ==========================================================================
1999 Description:
2000 TPC Report action frame handler.
2001
2002 Parametrs:
2003 Elme - MLME message containing the received frame
2004
2005 Return : None.
2006 ==========================================================================
2007 */
2008static void PeerTpcRepAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
2009{
2010 u8 DialogToken;
2011 struct rt_tpc_report_info TpcRepInfo;
2012 struct rt_tpc_req_entry *pEntry = NULL;
2013
2014 NdisZeroMemory(&TpcRepInfo, sizeof(struct rt_tpc_report_info));
2015 if (PeerTpcRepSanity
2016 (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &TpcRepInfo)) {
2017 pEntry = TpcReqLookUp(pAd, DialogToken);
2018 if (pEntry != NULL) {
2019 TpcReqDelete(pAd, pEntry->DialogToken);
2020 DBGPRINT(RT_DEBUG_TRACE,
2021 ("%s: DialogToken=%x, TxPwr=%d, LinkMargin=%d\n",
2022 __func__, DialogToken, TpcRepInfo.TxPwr,
2023 TpcRepInfo.LinkMargin));
2024 }
2025 }
2026
2027 return;
2028}
2029
2030/*
2031 ==========================================================================
2032 Description:
2033 Spectrun action frames Handler such as channel switch annoucement,
2034 measurement report, measurement request actions frames.
2035
2036 Parametrs:
2037 Elme - MLME message containing the received frame
2038
2039 Return : None.
2040 ==========================================================================
2041 */
2042void PeerSpectrumAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
2043{
2044
2045 u8 Action = Elem->Msg[LENGTH_802_11 + 1];
2046
2047 if (pAd->CommonCfg.bIEEE80211H != TRUE)
2048 return;
2049
2050 switch (Action) {
2051 case SPEC_MRQ:
2052 /* current rt2860 unable do such measure specified in Measurement Request. */
2053 /* reject all measurement request. */
2054 PeerMeasureReqAction(pAd, Elem);
2055 break;
2056
2057 case SPEC_MRP:
2058 PeerMeasureReportAction(pAd, Elem);
2059 break;
2060
2061 case SPEC_TPCRQ:
2062 PeerTpcReqAction(pAd, Elem);
2063 break;
2064
2065 case SPEC_TPCRP:
2066 PeerTpcRepAction(pAd, Elem);
2067 break;
2068
2069 case SPEC_CHANNEL_SWITCH:
2070
2071 PeerChSwAnnAction(pAd, Elem);
2072 break;
2073 }
2074
2075 return;
2076}
2077
2078/*
2079 ==========================================================================
2080 Description:
2081
2082 Parametrs:
2083
2084 Return : None.
2085 ==========================================================================
2086 */
2087int Set_MeasureReq_Proc(struct rt_rtmp_adapter *pAd, char *arg)
2088{
2089 u32 Aid = 1;
2090 u32 ArgIdx;
2091 char *thisChar;
2092
2093 MEASURE_REQ_MODE MeasureReqMode;
2094 u8 MeasureReqToken = RandomByte(pAd);
2095 u8 MeasureReqType = RM_BASIC;
2096 u8 MeasureCh = 1;
2097 u64 MeasureStartTime = GetCurrentTimeStamp(pAd);
2098 struct rt_measure_req MeasureReq;
2099 u8 TotalLen;
2100
2101 struct rt_header_802_11 ActHdr;
2102 u8 *pOutBuffer = NULL;
2103 int NStatus;
2104 unsigned long FrameLen;
2105
2106 NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */
2107 if (NStatus != NDIS_STATUS_SUCCESS) {
2108 DBGPRINT(RT_DEBUG_TRACE,
2109 ("%s() allocate memory failed \n", __func__));
2110 goto END_OF_MEASURE_REQ;
2111 }
2112
2113 ArgIdx = 1;
2114 while ((thisChar = strsep((char **)&arg, "-")) != NULL) {
2115 switch (ArgIdx) {
2116 case 1: /* Aid. */
2117 Aid = (u8)simple_strtol(thisChar, 0, 16);
2118 break;
2119
2120 case 2: /* Measurement Request Type. */
2121 MeasureReqType = simple_strtol(thisChar, 0, 16);
2122 if (MeasureReqType > 3) {
2123 DBGPRINT(RT_DEBUG_ERROR,
2124 ("%s: unknow MeasureReqType(%d)\n",
2125 __func__, MeasureReqType));
2126 goto END_OF_MEASURE_REQ;
2127 }
2128 break;
2129
2130 case 3: /* Measurement channel. */
2131 MeasureCh = (u8)simple_strtol(thisChar, 0, 16);
2132 break;
2133 }
2134 ArgIdx++;
2135 }
2136
2137 DBGPRINT(RT_DEBUG_TRACE,
2138 ("%s::Aid = %d, MeasureReqType=%d MeasureCh=%d\n", __func__,
2139 Aid, MeasureReqType, MeasureCh));
2140 if (!VALID_WCID(Aid)) {
2141 DBGPRINT(RT_DEBUG_ERROR,
2142 ("%s: unknow sta of Aid(%d)\n", __func__, Aid));
2143 goto END_OF_MEASURE_REQ;
2144 }
2145
2146 MeasureReqMode.word = 0;
2147 MeasureReqMode.field.Enable = 1;
2148
2149 MeasureReqInsert(pAd, MeasureReqToken);
2150
2151 /* build action frame header. */
2152 MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0,
2153 pAd->MacTab.Content[Aid].Addr, pAd->CurrentAddress);
2154
2155 NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11));
2156 FrameLen = sizeof(struct rt_header_802_11);
2157
2158 TotalLen = sizeof(struct rt_measure_req_info) + sizeof(struct rt_measure_req);
2159
2160 MakeMeasurementReqFrame(pAd, pOutBuffer, &FrameLen,
2161 sizeof(struct rt_measure_req_info), CATEGORY_RM, RM_BASIC,
2162 MeasureReqToken, MeasureReqMode.word,
2163 MeasureReqType, 0);
2164
2165 MeasureReq.ChNum = MeasureCh;
2166 MeasureReq.MeasureStartTime = cpu2le64(MeasureStartTime);
2167 MeasureReq.MeasureDuration = cpu2le16(2000);
2168
2169 {
2170 unsigned long TempLen;
2171 MakeOutgoingFrame(pOutBuffer + FrameLen, &TempLen,
2172 sizeof(struct rt_measure_req), &MeasureReq,
2173 END_OF_ARGS);
2174 FrameLen += TempLen;
2175 }
2176
2177 MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, (u32)FrameLen);
2178
2179END_OF_MEASURE_REQ:
2180 MlmeFreeMemory(pAd, pOutBuffer);
2181
2182 return TRUE;
2183}
2184
2185int Set_TpcReq_Proc(struct rt_rtmp_adapter *pAd, char *arg)
2186{
2187 u32 Aid;
2188
2189 u8 TpcReqToken = RandomByte(pAd);
2190
2191 Aid = (u32)simple_strtol(arg, 0, 16);
2192
2193 DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d\n", __func__, Aid));
2194 if (!VALID_WCID(Aid)) {
2195 DBGPRINT(RT_DEBUG_ERROR,
2196 ("%s: unknow sta of Aid(%d)\n", __func__, Aid));
2197 return TRUE;
2198 }
2199
2200 TpcReqInsert(pAd, TpcReqToken);
2201
2202 EnqueueTPCReq(pAd, pAd->MacTab.Content[Aid].Addr, TpcReqToken);
2203
2204 return TRUE;
2205}
diff --git a/drivers/staging/rt2860/crypt_hmac.h b/drivers/staging/rt2860/crypt_hmac.h
deleted file mode 100644
index 7a56515d726..00000000000
--- a/drivers/staging/rt2860/crypt_hmac.h
+++ /dev/null
@@ -1,65 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28/****************************************************************************
29 Module Name:
30 HMAC
31
32 Abstract:
33 FIPS 198: The Keyed-Hash Message Authentication Code (HMAC)
34
35 Revision History:
36 Who When What
37 -------- ---------- ------------------------------------------
38 Eddy 2008/11/24 Create HMAC-SHA1, HMAC-SHA256
39***************************************************************************/
40#ifndef __CRYPT_HMAC_H__
41#define __CRYPT_HMAC_H__
42
43#ifdef CRYPT_TESTPLAN
44#include "crypt_testplan.h"
45#else
46#include "rt_config.h"
47#endif /* CRYPT_TESTPLAN */
48
49#ifdef SHA1_SUPPORT
50#define HMAC_SHA1_SUPPORT
51void HMAC_SHA1(IN const u8 Key[],
52 u32 KeyLen,
53 IN const u8 Message[],
54 u32 MessageLen, u8 MAC[], u32 MACLen);
55#endif /* SHA1_SUPPORT */
56
57#ifdef MD5_SUPPORT
58#define HMAC_MD5_SUPPORT
59void HMAC_MD5(IN const u8 Key[],
60 u32 KeyLen,
61 IN const u8 Message[],
62 u32 MessageLen, u8 MAC[], u32 MACLen);
63#endif /* MD5_SUPPORT */
64
65#endif /* __CRYPT_HMAC_H__ */
diff --git a/drivers/staging/rt2860/crypt_md5.h b/drivers/staging/rt2860/crypt_md5.h
deleted file mode 100644
index 26f974554b2..00000000000
--- a/drivers/staging/rt2860/crypt_md5.h
+++ /dev/null
@@ -1,73 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28/****************************************************************************
29 Module Name:
30 MD5
31
32 Abstract:
33 RFC1321: The MD5 Message-Digest Algorithm
34
35 Revision History:
36 Who When What
37 -------- ---------- ------------------------------------------
38 Eddy 2008/11/24 Create md5
39***************************************************************************/
40
41#ifndef __CRYPT_MD5_H__
42#define __CRYPT_MD5_H__
43
44#ifdef CRYPT_TESTPLAN
45#include "crypt_testplan.h"
46#else
47#include "rt_config.h"
48#endif /* CRYPT_TESTPLAN */
49
50/* Algorithm options */
51#define MD5_SUPPORT
52
53#ifdef MD5_SUPPORT
54#define MD5_BLOCK_SIZE 64 /* 512 bits = 64 bytes */
55#define MD5_DIGEST_SIZE 16 /* 128 bits = 16 bytes */
56
57struct rt_md5_ctx_struc {
58 u32 HashValue[4];
59 u64 MessageLen;
60 u8 Block[MD5_BLOCK_SIZE];
61 u32 BlockLen;
62};
63
64void MD5_Init(struct rt_md5_ctx_struc *pMD5_CTX);
65void MD5_Hash(struct rt_md5_ctx_struc *pMD5_CTX);
66void MD5_Append(struct rt_md5_ctx_struc *pMD5_CTX,
67 IN const u8 Message[], u32 MessageLen);
68void MD5_End(struct rt_md5_ctx_struc *pMD5_CTX, u8 DigestMessage[]);
69void RT_MD5(IN const u8 Message[],
70 u32 MessageLen, u8 DigestMessage[]);
71#endif /* MD5_SUPPORT */
72
73#endif /* __CRYPT_MD5_H__ */
diff --git a/drivers/staging/rt2860/crypt_sha2.h b/drivers/staging/rt2860/crypt_sha2.h
deleted file mode 100644
index 20d11ab865c..00000000000
--- a/drivers/staging/rt2860/crypt_sha2.h
+++ /dev/null
@@ -1,73 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28/****************************************************************************
29 Module Name:
30 SHA2
31
32 Abstract:
33 FIPS 180-2: Secure Hash Standard (SHS)
34
35 Revision History:
36 Who When What
37 -------- ---------- ------------------------------------------
38 Eddy 2008/11/24 Create SHA1
39 Eddy 2008/07/23 Create SHA256
40***************************************************************************/
41
42#ifndef __CRYPT_SHA2_H__
43#define __CRYPT_SHA2_H__
44
45#ifdef CRYPT_TESTPLAN
46#include "crypt_testplan.h"
47#else
48#include "rt_config.h"
49#endif /* CRYPT_TESTPLAN */
50
51/* Algorithm options */
52#define SHA1_SUPPORT
53
54#ifdef SHA1_SUPPORT
55#define SHA1_BLOCK_SIZE 64 /* 512 bits = 64 bytes */
56#define SHA1_DIGEST_SIZE 20 /* 160 bits = 20 bytes */
57struct rt_sha1_ctx {
58 u32 HashValue[5]; /* 5 = (SHA1_DIGEST_SIZE / 32) */
59 u64 MessageLen; /* total size */
60 u8 Block[SHA1_BLOCK_SIZE];
61 u32 BlockLen;
62};
63
64void RT_SHA1_Init(struct rt_sha1_ctx *pSHA_CTX);
65void SHA1_Hash(struct rt_sha1_ctx *pSHA_CTX);
66void SHA1_Append(struct rt_sha1_ctx *pSHA_CTX,
67 IN const u8 Message[], u32 MessageLen);
68void SHA1_End(struct rt_sha1_ctx *pSHA_CTX, u8 DigestMessage[]);
69void RT_SHA1(IN const u8 Message[],
70 u32 MessageLen, u8 DigestMessage[]);
71#endif /* SHA1_SUPPORT */
72
73#endif /* __CRYPT_SHA2_H__ */
diff --git a/drivers/staging/rt2860/dfs.h b/drivers/staging/rt2860/dfs.h
deleted file mode 100644
index 5fbab259aca..00000000000
--- a/drivers/staging/rt2860/dfs.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 dfs.h
29
30 Abstract:
31 Support DFS function.
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Fonchi 03-12-2007 created
37*/
38
39BOOLEAN RadarChannelCheck(struct rt_rtmp_adapter *pAd, u8 Ch);
diff --git a/drivers/staging/rt2860/eeprom.h b/drivers/staging/rt2860/eeprom.h
deleted file mode 100644
index 72c8fb94165..00000000000
--- a/drivers/staging/rt2860/eeprom.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 eeprom.h
29
30 Abstract:
31 Miniport header file for eeprom related information
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37#ifndef __EEPROM_H__
38#define __EEPROM_H__
39
40#ifdef RTMP_PCI_SUPPORT
41/*************************************************************************
42 * Public function declarations for prom-based chipset
43 ************************************************************************/
44int rtmp_ee_prom_read16(struct rt_rtmp_adapter *pAd,
45 u16 Offset, u16 *pValue);
46#endif /* RTMP_PCI_SUPPORT // */
47#ifdef RTMP_USB_SUPPORT
48/*************************************************************************
49 * Public function declarations for usb-based prom chipset
50 ************************************************************************/
51int RTUSBReadEEPROM16(struct rt_rtmp_adapter *pAd,
52 u16 offset, u16 *pData);
53#endif /* RTMP_USB_SUPPORT // */
54
55#ifdef RT30xx
56#ifdef RTMP_EFUSE_SUPPORT
57int rtmp_ee_efuse_read16(struct rt_rtmp_adapter *pAd,
58 u16 Offset, u16 *pValue);
59#endif /* RTMP_EFUSE_SUPPORT // */
60#endif /* RT30xx // */
61
62/*************************************************************************
63 * Public function declarations for prom operation callback functions setting
64 ************************************************************************/
65int RtmpChipOpsEepromHook(struct rt_rtmp_adapter *pAd, int infType);
66
67#endif /* __EEPROM_H__ // */
diff --git a/drivers/staging/rt2860/iface/rtmp_pci.h b/drivers/staging/rt2860/iface/rtmp_pci.h
deleted file mode 100644
index 3d66e386bd8..00000000000
--- a/drivers/staging/rt2860/iface/rtmp_pci.h
+++ /dev/null
@@ -1,80 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27
28#ifndef __RTMP_PCI_H__
29#define __RTMP_PCI_H__
30
31#define RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p) \
32 ((struct os_cookie *)handle)->pci_dev = dev_p;
33
34#ifdef LINUX
35/* set driver data */
36#define RT28XX_DRVDATA_SET(_a) pci_set_drvdata(_a, net_dev);
37
38#define RT28XX_PUT_DEVICE(dev_p)
39
40#define SA_SHIRQ IRQF_SHARED
41
42#ifdef PCI_MSI_SUPPORT
43#define RTMP_MSI_ENABLE(_pAd) \
44 { struct os_cookie *_pObj = (struct os_cookie *)(_pAd->OS_Cookie); \
45 (_pAd)->HaveMsi = pci_enable_msi(_pObj->pci_dev) \
46 == 0 ? TRUE : FALSE; \
47 }
48
49#define RTMP_MSI_DISABLE(_pAd) \
50 { struct os_cookie *_pObj = (struct os_cookie *)(_pAd->OS_Cookie); \
51 if (_pAd->HaveMsi == TRUE) \
52 pci_disable_msi(_pObj->pci_dev); \
53 _pAd->HaveMsi = FALSE; \
54 }
55#else
56#define RTMP_MSI_ENABLE(_pAd) do {} while (0)
57#define RTMP_MSI_DISABLE(_pAd) do {} while (0)
58#endif /* PCI_MSI_SUPPORT */
59
60#define RTMP_PCI_DEV_UNMAP() \
61{ if (net_dev->base_addr) { \
62 iounmap((void *)(net_dev->base_addr)); \
63 release_mem_region(pci_resource_start(dev_p, 0), \
64 pci_resource_len(dev_p, 0)); } \
65 if (net_dev->irq) \
66 pci_release_regions(dev_p); }
67
68#define PCI_REG_READ_WORD(pci_dev, offset, Configuration) {\
69 if (pci_read_config_word(pci_dev, offset, &reg16) == 0) \
70 Configuration = le2cpu16(reg16); \
71 else \
72 Configuration = 0; }
73
74#define PCI_REG_WIRTE_WORD(pci_dev, offset, Configuration) {\
75 reg16 = cpu2le16(Configuration); \
76 pci_write_config_word(pci_dev, offset, reg16); }
77
78#endif /* LINUX */
79
80#endif /* __RTMP_PCI_H__ */
diff --git a/drivers/staging/rt2860/iface/rtmp_usb.h b/drivers/staging/rt2860/iface/rtmp_usb.h
deleted file mode 100644
index 57128963797..00000000000
--- a/drivers/staging/rt2860/iface/rtmp_usb.h
+++ /dev/null
@@ -1,196 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27
28#ifndef __RTMP_USB_H__
29#define __RTMP_USB_H__
30
31#include "../rtusb_io.h"
32
33#ifdef LINUX
34#include <linux/usb.h>
35#endif /* LINUX */
36
37extern u8 EpToQueue[6];
38
39#define RXBULKAGGRE_ZISE 12
40#define MAX_TXBULK_LIMIT (LOCAL_TXBUF_SIZE*(BULKAGGRE_ZISE-1))
41#define MAX_TXBULK_SIZE (LOCAL_TXBUF_SIZE*BULKAGGRE_ZISE)
42#define MAX_RXBULK_SIZE (LOCAL_TXBUF_SIZE*RXBULKAGGRE_ZISE)
43#define MAX_MLME_HANDLER_MEMORY 20
44
45/* Flags for Bulkflags control for bulk out data */
46#define fRTUSB_BULK_OUT_DATA_NULL 0x00000001
47#define fRTUSB_BULK_OUT_RTS 0x00000002
48#define fRTUSB_BULK_OUT_MLME 0x00000004
49
50#define fRTUSB_BULK_OUT_PSPOLL 0x00000010
51#define fRTUSB_BULK_OUT_DATA_FRAG 0x00000020
52#define fRTUSB_BULK_OUT_DATA_FRAG_2 0x00000040
53#define fRTUSB_BULK_OUT_DATA_FRAG_3 0x00000080
54#define fRTUSB_BULK_OUT_DATA_FRAG_4 0x00000100
55
56#define fRTUSB_BULK_OUT_DATA_NORMAL 0x00010000
57#define fRTUSB_BULK_OUT_DATA_NORMAL_2 0x00020000
58#define fRTUSB_BULK_OUT_DATA_NORMAL_3 0x00040000
59#define fRTUSB_BULK_OUT_DATA_NORMAL_4 0x00080000
60
61/* TODO:move to ./ate/include/iface/ate_usb.h */
62
63#define FREE_HTTX_RING(_pCookie, _pipeId, _txContext) \
64{ \
65 if ((_txContext)->ENextBulkOutPosition == \
66 (_txContext)->CurWritePosition) {\
67 (_txContext)->bRingEmpty = TRUE; \
68 } \
69 /*NdisInterlockedDecrement(&(_p)->TxCount); */\
70}
71
72/******************************************************************************
73
74 USB Bulk operation related definitions
75
76******************************************************************************/
77
78#ifdef LINUX
79#define BULKAGGRE_ZISE 100
80#define RT28XX_PUT_DEVICE usb_put_dev
81#define RTUSB_ALLOC_URB(iso) usb_alloc_urb(iso, GFP_ATOMIC)
82#define RTUSB_SUBMIT_URB(pUrb) usb_submit_urb(pUrb, \
83 GFP_ATOMIC)
84#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, \
85 BufSize, \
86 pDma_addr) \
87 usb_alloc_coherent(\
88 pUsb_Dev, \
89 BufSize, \
90 GFP_ATOMIC, \
91 pDma_addr)
92#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, \
93 BufSize, \
94 pTransferBuf, \
95 Dma_addr) \
96 usb_free_coherent( \
97 pUsb_Dev, \
98 BufSize, \
99 pTransferBuf, \
100 Dma_addr)
101
102#define RTUSB_FREE_URB(pUrb) usb_free_urb(pUrb)
103
104/* unlink urb */
105#define RTUSB_UNLINK_URB(pUrb) usb_kill_urb(pUrb)
106
107extern void dump_urb(struct urb *purb);
108
109#define InterlockedIncrement atomic_inc
110#define NdisInterlockedIncrement atomic_inc
111#define InterlockedDecrement atomic_dec
112#define NdisInterlockedDecrement atomic_dec
113#define InterlockedExchange atomic_set
114
115#endif /* LINUX */
116
117#define NT_SUCCESS(status) (((status) >= 0) ? (TRUE) : (FALSE))
118
119#define USBD_TRANSFER_DIRECTION_OUT 0
120#define USBD_TRANSFER_DIRECTION_IN 0
121#define USBD_SHORT_TRANSFER_OK 0
122#define PURB struct urb *
123
124#define PIRP void *
125#define NDIS_OID u32
126#ifndef USB_ST_NOERROR
127#define USB_ST_NOERROR 0
128#endif
129
130/* vendor-specific control operations */
131#define CONTROL_TIMEOUT_JIFFIES ((100 * OS_HZ) / 1000)
132#define UNLINK_TIMEOUT_MS 3
133
134void RTUSBBulkOutDataPacketComplete(struct urb *purb, struct pt_regs *pt_regs);
135void RTUSBBulkOutMLMEPacketComplete(struct urb *pUrb, struct pt_regs *pt_regs);
136void RTUSBBulkOutNullFrameComplete(struct urb *pUrb, struct pt_regs *pt_regs);
137void RTUSBBulkOutRTSFrameComplete(struct urb *pUrb, struct pt_regs *pt_regs);
138void RTUSBBulkOutPsPollComplete(struct urb *pUrb, struct pt_regs *pt_regs);
139void RTUSBBulkRxComplete(struct urb *pUrb, struct pt_regs *pt_regs);
140
141#ifdef KTHREAD_SUPPORT
142#define RTUSBMlmeUp(pAd) \
143 do { \
144 struct rt_rtmp_os_task *_pTask = &((pAd)->mlmeTask);\
145 if (_pTask->kthread_task) {\
146 _pTask->kthread_running = TRUE; \
147 wake_up(&_pTask->kthread_q); \
148 } \
149 } while (0)
150#else
151#define RTUSBMlmeUp(pAd) \
152 do { \
153 struct rt_rtmp_os_task *_pTask = &((pAd)->mlmeTask);\
154 CHECK_PID_LEGALITY(_pTask->taskPID) \
155 { \
156 RTMP_SEM_EVENT_UP(&(_pTask->taskSema)); \
157 } \
158 } while (0)
159#endif
160
161#ifdef KTHREAD_SUPPORT
162#define RTUSBCMDUp(pAd) \
163 do { \
164 struct rt_rtmp_os_task *_pTask = &((pAd)->cmdQTask); \
165 { \
166 _pTask->kthread_running = TRUE; \
167 wake_up(&_pTask->kthread_q); \
168 } \
169 } while (0)
170
171#else
172#define RTUSBCMDUp(pAd) \
173 do { \
174 struct rt_rtmp_os_task *_pTask = &((pAd)->cmdQTask); \
175 CHECK_PID_LEGALITY(_pTask->taskPID) \
176 {\
177 RTMP_SEM_EVENT_UP(&(_pTask->taskSema)); \
178 } \
179 } while (0)
180#endif
181
182#define DEVICE_VENDOR_REQUEST_OUT 0x40
183#define DEVICE_VENDOR_REQUEST_IN 0xc0
184/*#define INTERFACE_VENDOR_REQUEST_OUT 0x41*/
185/*#define INTERFACE_VENDOR_REQUEST_IN 0xc1*/
186
187#define BULKOUT_MGMT_RESET_FLAG 0x80
188
189#define RTUSB_SET_BULK_FLAG(_M, _F) ((_M)->BulkFlags |= (_F))
190#define RTUSB_CLEAR_BULK_FLAG(_M, _F) ((_M)->BulkFlags &= ~(_F))
191#define RTUSB_TEST_BULK_FLAG(_M, _F) (((_M)->BulkFlags & (_F)) != 0)
192
193#define RTMP_IRQ_REQUEST(net_dev) do {} while (0)
194#define RTMP_IRQ_RELEASE(net_dev) do {} while (0)
195
196#endif /* __RTMP_USB_H__ */
diff --git a/drivers/staging/rt2860/mlme.h b/drivers/staging/rt2860/mlme.h
deleted file mode 100644
index a285851692e..00000000000
--- a/drivers/staging/rt2860/mlme.h
+++ /dev/null
@@ -1,1050 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 mlme.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ------------------------------
35 John Chang 2003-08-28 Created
36 John Chang 2004-09-06 modified for RT2600
37 Justin P. Mattock 11/07/2010 Fix typos in comments
38
39*/
40#ifndef __MLME_H__
41#define __MLME_H__
42
43#include "rtmp_dot11.h"
44
45/* maximum supported capability information */
46/* ESS, IBSS, Privacy, Short Preamble, Spectrum mgmt, Short Slot */
47#define SUPPORTED_CAPABILITY_INFO 0x0533
48
49#define END_OF_ARGS -1
50#define LFSR_MASK 0x80000057
51#define MLME_TASK_EXEC_INTV 100/*200*/ /* */
52#define LEAD_TIME 5
53#define MLME_TASK_EXEC_MULTIPLE 10 /*5*/ /* MLME_TASK_EXEC_MULTIPLE * MLME_TASK_EXEC_INTV = 1 sec */
54#define REORDER_EXEC_INTV 100 /* 0.1 sec */
55
56/* The definition of Radar detection duration region */
57#define CE 0
58#define FCC 1
59#define JAP 2
60#define JAP_W53 3
61#define JAP_W56 4
62#define MAX_RD_REGION 5
63
64#define BEACON_LOST_TIME (4 * OS_HZ) /* 2048 msec = 2 sec */
65
66#define DLS_TIMEOUT 1200 /* unit: msec */
67#define AUTH_TIMEOUT 300 /* unit: msec */
68#define ASSOC_TIMEOUT 300 /* unit: msec */
69#define JOIN_TIMEOUT 2000 /* unit: msec */
70#define SHORT_CHANNEL_TIME 90 /* unit: msec */
71#define MIN_CHANNEL_TIME 110 /* unit: msec, for dual band scan */
72#define MAX_CHANNEL_TIME 140 /* unit: msec, for single band scan */
73#define FAST_ACTIVE_SCAN_TIME 30 /* Active scan waiting for probe response time */
74#define CW_MIN_IN_BITS 4 /* actual CwMin = 2^CW_MIN_IN_BITS - 1 */
75#define LINK_DOWN_TIMEOUT 20000 /* unit: msec */
76#define AUTO_WAKEUP_TIMEOUT 70 /*unit: msec */
77
78#define CW_MAX_IN_BITS 10 /* actual CwMax = 2^CW_MAX_IN_BITS - 1 */
79
80/* Note: RSSI_TO_DBM_OFFSET has been changed to variable for new RF (2004-0720). */
81/* Should not refer to this constant anymore */
82/*#define RSSI_TO_DBM_OFFSET 120 // for RT2530 RSSI-115 = dBm */
83#define RSSI_FOR_MID_TX_POWER -55 /* -55 db is considered mid-distance */
84#define RSSI_FOR_LOW_TX_POWER -45 /* -45 db is considered very short distance and */
85 /* eligible to use a lower TX power */
86#define RSSI_FOR_LOWEST_TX_POWER -30
87/*#define MID_TX_POWER_DELTA 0 // 0 db from full TX power upon mid-distance to AP */
88#define LOW_TX_POWER_DELTA 6 /* -3 db from full TX power upon very short distance. 1 grade is 0.5 db */
89#define LOWEST_TX_POWER_DELTA 16 /* -8 db from full TX power upon shortest distance. 1 grade is 0.5 db */
90
91#define RSSI_TRIGGERED_UPON_BELOW_THRESHOLD 0
92#define RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD 1
93#define RSSI_THRESHOLD_FOR_ROAMING 25
94#define RSSI_DELTA 5
95
96/* Channel Quality Indication */
97#define CQI_IS_GOOD(cqi) ((cqi) >= 50)
98/*#define CQI_IS_FAIR(cqi) (((cqi) >= 20) && ((cqi) < 50)) */
99#define CQI_IS_POOR(cqi) (cqi < 50) /*(((cqi) >= 5) && ((cqi) < 20)) */
100#define CQI_IS_BAD(cqi) (cqi < 5)
101#define CQI_IS_DEAD(cqi) (cqi == 0)
102
103/* weighting factor to calculate Channel quality, total should be 100% */
104#define RSSI_WEIGHTING 50
105#define TX_WEIGHTING 30
106#define RX_WEIGHTING 20
107
108#define BSS_NOT_FOUND 0xFFFFFFFF
109
110#define MAX_LEN_OF_MLME_QUEUE 40 /*10 */
111
112#define SCAN_PASSIVE 18 /* scan with no probe request, only wait beacon and probe response */
113#define SCAN_ACTIVE 19 /* scan with probe request, and wait beacon and probe response */
114#define SCAN_CISCO_PASSIVE 20 /* Single channel passive scan */
115#define SCAN_CISCO_ACTIVE 21 /* Single channel active scan */
116#define SCAN_CISCO_NOISE 22 /* Single channel passive scan for noise histogram collection */
117#define SCAN_CISCO_CHANNEL_LOAD 23 /* Single channel passive scan for channel load collection */
118#define FAST_SCAN_ACTIVE 24 /* scan with probe request, and wait beacon and probe response */
119
120#define MAC_ADDR_IS_GROUP(Addr) (((Addr[0]) & 0x01))
121#define MAC_ADDR_HASH(Addr) (Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5])
122#define MAC_ADDR_HASH_INDEX(Addr) (MAC_ADDR_HASH(Addr) % HASH_TABLE_SIZE)
123#define TID_MAC_HASH(Addr, TID) (TID^Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5])
124#define TID_MAC_HASH_INDEX(Addr, TID) (TID_MAC_HASH(Addr, TID) % HASH_TABLE_SIZE)
125
126/* LED Control */
127/* association ON. one LED ON. another blinking when TX, OFF when idle */
128/* no association, both LED off */
129#define ASIC_LED_ACT_ON(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00031e46)
130#define ASIC_LED_ACT_OFF(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00001e46)
131
132/* bit definition of the 2-byte pBEACON->Capability field */
133#define CAP_IS_ESS_ON(x) (((x) & 0x0001) != 0)
134#define CAP_IS_IBSS_ON(x) (((x) & 0x0002) != 0)
135#define CAP_IS_CF_POLLABLE_ON(x) (((x) & 0x0004) != 0)
136#define CAP_IS_CF_POLL_REQ_ON(x) (((x) & 0x0008) != 0)
137#define CAP_IS_PRIVACY_ON(x) (((x) & 0x0010) != 0)
138#define CAP_IS_SHORT_PREAMBLE_ON(x) (((x) & 0x0020) != 0)
139#define CAP_IS_PBCC_ON(x) (((x) & 0x0040) != 0)
140#define CAP_IS_AGILITY_ON(x) (((x) & 0x0080) != 0)
141#define CAP_IS_SPECTRUM_MGMT(x) (((x) & 0x0100) != 0) /* 802.11e d9 */
142#define CAP_IS_QOS(x) (((x) & 0x0200) != 0) /* 802.11e d9 */
143#define CAP_IS_SHORT_SLOT(x) (((x) & 0x0400) != 0)
144#define CAP_IS_APSD(x) (((x) & 0x0800) != 0) /* 802.11e d9 */
145#define CAP_IS_IMMED_BA(x) (((x) & 0x1000) != 0) /* 802.11e d9 */
146#define CAP_IS_DSSS_OFDM(x) (((x) & 0x2000) != 0)
147#define CAP_IS_DELAY_BA(x) (((x) & 0x4000) != 0) /* 802.11e d9 */
148
149#define CAP_GENERATE(ess, ibss, priv, s_pre, s_slot, spectrum) (((ess) ? 0x0001 : 0x0000) | ((ibss) ? 0x0002 : 0x0000) | ((priv) ? 0x0010 : 0x0000) | ((s_pre) ? 0x0020 : 0x0000) | ((s_slot) ? 0x0400 : 0x0000) | ((spectrum) ? 0x0100 : 0x0000))
150
151#define ERP_IS_NON_ERP_PRESENT(x) (((x) & 0x01) != 0) /* 802.11g */
152#define ERP_IS_USE_PROTECTION(x) (((x) & 0x02) != 0) /* 802.11g */
153#define ERP_IS_USE_BARKER_PREAMBLE(x) (((x) & 0x04) != 0) /* 802.11g */
154
155#define DRS_TX_QUALITY_WORST_BOUND 8 /* 3 // just test by gary */
156#define DRS_PENALTY 8
157
158#define BA_NOTUSE 2
159/*BA Policy subfiled value in ADDBA frame */
160#define IMMED_BA 1
161#define DELAY_BA 0
162
163/* BA Initiator subfield in DELBA frame */
164#define ORIGINATOR 1
165#define RECIPIENT 0
166
167/* ADDBA Status Code */
168#define ADDBA_RESULTCODE_SUCCESS 0
169#define ADDBA_RESULTCODE_REFUSED 37
170#define ADDBA_RESULTCODE_INVALID_PARAMETERS 38
171
172/* DELBA Reason Code */
173#define DELBA_REASONCODE_QSTA_LEAVING 36
174#define DELBA_REASONCODE_END_BA 37
175#define DELBA_REASONCODE_UNKNOWN_BA 38
176#define DELBA_REASONCODE_TIMEOUT 39
177
178/* reset all OneSecTx counters */
179#define RESET_ONE_SEC_TX_CNT(__pEntry) \
180if (((__pEntry)) != NULL) { \
181 (__pEntry)->OneSecTxRetryOkCount = 0; \
182 (__pEntry)->OneSecTxFailCount = 0; \
183 (__pEntry)->OneSecTxNoRetryOkCount = 0; \
184}
185
186/* */
187/* 802.11 frame formats */
188/* */
189/* HT Capability INFO field in HT Cap IE . */
190struct PACKED rt_ht_cap_info {
191 u16 AdvCoding:1;
192 u16 ChannelWidth:1;
193 u16 MimoPs:2; /*momi power safe */
194 u16 GF:1; /*green field */
195 u16 ShortGIfor20:1;
196 u16 ShortGIfor40:1; /*for40MHz */
197 u16 TxSTBC:1;
198 u16 RxSTBC:2;
199 u16 DelayedBA:1; /*rt2860c not support */
200 u16 AMsduSize:1; /* only support as zero */
201 u16 CCKmodein40:1;
202 u16 PSMP:1;
203 u16 Forty_Mhz_Intolerant:1;
204 u16 LSIGTxopProSup:1;
205};
206
207/* HT Capability INFO field in HT Cap IE . */
208struct PACKED rt_ht_cap_parm {
209 u8 MaxRAmpduFactor:2;
210 u8 MpduDensity:3;
211 u8 rsv:3; /*momi power safe */
212};
213
214/* HT Capability INFO field in HT Cap IE . */
215struct PACKED rt_ht_mcs_set {
216 u8 MCSSet[10];
217 u8 SupRate[2]; /* unit : 1Mbps */
218 u8 TxMCSSetDefined:1;
219 u8 TxRxNotEqual:1;
220 u8 TxStream:2;
221 u8 MpduDensity:1;
222 u8 rsv:3;
223 u8 rsv3[3];
224};
225
226/* HT Capability INFO field in HT Cap IE . */
227struct PACKED rt_ext_ht_cap_info {
228 u16 Pco:1;
229 u16 TranTime:2;
230 u16 rsv:5; /*momi power safe */
231 u16 MCSFeedback:2; /*0:no MCS feedback, 2:unsolicited MCS feedback, 3:Full MCS feedback, 1:rsv. */
232 u16 PlusHTC:1; /*+HTC control field support */
233 u16 RDGSupport:1; /*reverse Direction Grant support */
234 u16 rsv2:4;
235};
236
237/* HT Beamforming field in HT Cap IE . */
238struct PACKED rt_ht_bf_cap {
239 unsigned long TxBFRecCapable:1;
240 unsigned long RxSoundCapable:1;
241 unsigned long TxSoundCapable:1;
242 unsigned long RxNDPCapable:1;
243 unsigned long TxNDPCapable:1;
244 unsigned long ImpTxBFCapable:1;
245 unsigned long Calibration:2;
246 unsigned long ExpCSICapable:1;
247 unsigned long ExpNoComSteerCapable:1;
248 unsigned long ExpComSteerCapable:1;
249 unsigned long ExpCSIFbk:2;
250 unsigned long ExpNoComBF:2;
251 unsigned long ExpComBF:2;
252 unsigned long MinGrouping:2;
253 unsigned long CSIBFAntSup:2;
254 unsigned long NoComSteerBFAntSup:2;
255 unsigned long ComSteerBFAntSup:2;
256 unsigned long CSIRowBFSup:2;
257 unsigned long ChanEstimation:2;
258 unsigned long rsv:3;
259};
260
261/* HT antenna selection field in HT Cap IE . */
262struct PACKED rt_ht_as_cap {
263 u8 AntSelect:1;
264 u8 ExpCSIFbkTxASEL:1;
265 u8 AntIndFbkTxASEL:1;
266 u8 ExpCSIFbk:1;
267 u8 AntIndFbk:1;
268 u8 RxASel:1;
269 u8 TxSoundPPDU:1;
270 u8 rsv:1;
271};
272
273/* Draft 1.0 set IE length 26, but is extensible.. */
274#define SIZE_HT_CAP_IE 26
275/* The structure for HT Capability IE. */
276struct PACKED rt_ht_capability_ie {
277 struct rt_ht_cap_info HtCapInfo;
278 struct rt_ht_cap_parm HtCapParm;
279/* struct rt_ht_mcs_set HtMCSSet; */
280 u8 MCSSet[16];
281 struct rt_ext_ht_cap_info ExtHtCapInfo;
282 struct rt_ht_bf_cap TxBFCap; /* beamforming cap. rt2860c not support beamforming. */
283 struct rt_ht_as_cap ASCap; /*antenna selection. */
284};
285
286/* 802.11n draft3 related structure definitions. */
287/* 7.3.2.60 */
288#define dot11OBSSScanPassiveDwell 20 /* in TU. min amount of time that the STA continuously scans each channel when performing an active OBSS scan. */
289#define dot11OBSSScanActiveDwell 10 /* in TU.min amount of time that the STA continuously scans each channel when performing an passive OBSS scan. */
290#define dot11BSSWidthTriggerScanInterval 300 /* in sec. max interval between scan operations to be performed to detect BSS channel width trigger events. */
291#define dot11OBSSScanPassiveTotalPerChannel 200 /* in TU. min total amount of time that the STA scans each channel when performing a passive OBSS scan. */
292#define dot11OBSSScanActiveTotalPerChannel 20 /*in TU. min total amount of time that the STA scans each channel when performing a active OBSS scan */
293#define dot11BSSWidthChannelTransactionDelayFactor 5 /* min ratio between the delay time in performing a switch from 20MHz BSS to 20/40 BSS operation and the maximum */
294 /* interval between overlapping BSS scan operations. */
295#define dot11BSSScanActivityThreshold 25 /* in %%, max total time that a STA may be active on the medium during a period of */
296 /* (dot11BSSWidthChannelTransactionDelayFactor * dot11BSSWidthTriggerScanInterval) seconds without */
297 /* being obligated to perform OBSS Scan operations. default is 25(== 0.25%) */
298
299struct PACKED rt_overlap_bss_scan_ie {
300 u16 ScanPassiveDwell;
301 u16 ScanActiveDwell;
302 u16 TriggerScanInt; /* Trigger scan interval */
303 u16 PassiveTalPerChannel; /* passive total per channel */
304 u16 ActiveTalPerChannel; /* active total per channel */
305 u16 DelayFactor; /* BSS width channel transition delay factor */
306 u16 ScanActThre; /* Scan Activity threshold */
307};
308
309/* 7.3.2.56. 20/40 Coexistence element used in Element ID = 72 = IE_2040_BSS_COEXIST */
310typedef union PACKED _BSS_2040_COEXIST_IE {
311 struct PACKED {
312 u8 InfoReq:1;
313 u8 Intolerant40:1; /* Inter-BSS. set 1 when prohibits a receiving BSS from operating as a 20/40 Mhz BSS. */
314 u8 BSS20WidthReq:1; /* Intra-BSS set 1 when prohibits a receiving AP from operating its BSS as a 20/40MHz BSS. */
315 u8 rsv:5;
316 } field;
317 u8 word;
318} BSS_2040_COEXIST_IE, *PBSS_2040_COEXIST_IE;
319
320struct rt_trigger_eventa {
321 BOOLEAN bValid;
322 u8 BSSID[6];
323 u8 RegClass; /* Regulatory Class */
324 u16 Channel;
325 unsigned long CDCounter; /* Maintain a separate count down counter for each Event A. */
326};
327
328/* 20/40 trigger event table */
329/* If one Event (A) is deleted or created, or if Event (B) is detected or not detected, STA should send 2040BSSCoexistence to AP. */
330#define MAX_TRIGGER_EVENT 64
331struct rt_trigger_event_tab {
332 u8 EventANo;
333 struct rt_trigger_eventa EventA[MAX_TRIGGER_EVENT];
334 unsigned long EventBCountDown; /* Count down counter for Event B. */
335};
336
337/* 7.3.27 20/40 Bss Coexistence Mgmt capability used in extended capabilities information IE( ID = 127 = IE_EXT_CAPABILITY). */
338/* This is the first octet and was defined in 802.11n D3.03 and 802.11yD9.0 */
339struct PACKED rt_ext_cap_info_element {
340 u8 BssCoexistMgmtSupport:1;
341 u8 rsv:1;
342 u8 ExtendChannelSwitch:1;
343 u8 rsv2:5;
344};
345
346/* 802.11n 7.3.2.61 */
347struct PACKED rt_bss_2040_coexist_element {
348 u8 ElementID; /* ID = IE_2040_BSS_COEXIST = 72 */
349 u8 Len;
350 BSS_2040_COEXIST_IE BssCoexistIe;
351};
352
353/*802.11n 7.3.2.59 */
354struct PACKED rt_bss_2040_intolerant_ch_report {
355 u8 ElementID; /* ID = IE_2040_BSS_INTOLERANT_REPORT = 73 */
356 u8 Len;
357 u8 RegulatoryClass;
358 u8 ChList[0];
359};
360
361/* The structure for channel switch announcement IE. This is in 802.11n D3.03 */
362struct PACKED rt_cha_switch_announce_ie {
363 u8 SwitchMode; /*channel switch mode */
364 u8 NewChannel; /* */
365 u8 SwitchCount; /* */
366};
367
368/* The structure for channel switch announcement IE. This is in 802.11n D3.03 */
369struct PACKED rt_sec_cha_offset_ie {
370 u8 SecondaryChannelOffset; /* 1: Secondary above, 3: Secondary below, 0: no Secondary */
371};
372
373/* This structure is extracted from struct struct rt_ht_capability */
374struct rt_ht_phy_info {
375 BOOLEAN bHtEnable; /* If we should use ht rate. */
376 BOOLEAN bPreNHt; /* If we should use ht rate. */
377 /*Subtract from HT Capability IE */
378 u8 MCSSet[16];
379};
380
381/*This structure subtracts ralink supports from all 802.11n-related features. */
382/*Features not listed here but contained in 802.11n spec are not supported in rt2860. */
383struct rt_ht_capability {
384 u16 ChannelWidth:1;
385 u16 MimoPs:2; /*mimo power safe MMPS_ */
386 u16 GF:1; /*green field */
387 u16 ShortGIfor20:1;
388 u16 ShortGIfor40:1; /*for40MHz */
389 u16 TxSTBC:1;
390 u16 RxSTBC:2; /* 2 bits */
391 u16 AmsduEnable:1; /* Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benefit of 802.11n */
392 u16 AmsduSize:1; /* Max receiving A-MSDU size */
393 u16 rsv:5;
394
395 /*Subtract from Addiont HT INFO IE */
396 u8 MaxRAmpduFactor:2;
397 u8 MpduDensity:3;
398 u8 ExtChanOffset:2; /* Please note the difference with following u8 NewExtChannelOffset; from 802.11n */
399 u8 RecomWidth:1;
400
401 u16 OperaionMode:2;
402 u16 NonGfPresent:1;
403 u16 rsv3:1;
404 u16 OBSS_NonHTExist:1;
405 u16 rsv2:11;
406
407 /* New Extension Channel Offset IE */
408 u8 NewExtChannelOffset;
409 /* Extension Capability IE = 127 */
410 u8 BSSCoexist2040;
411};
412
413/* field in Additional HT Information IE . */
414struct PACKED rt_add_htinfo {
415 u8 ExtChanOffset:2;
416 u8 RecomWidth:1;
417 u8 RifsMode:1;
418 u8 S_PSMPSup:1; /*Indicate support for scheduled PSMP */
419 u8 SerInterGranu:3; /*service interval granularity */
420};
421
422struct PACKED rt_add_htinfo2 {
423 u16 OperaionMode:2;
424 u16 NonGfPresent:1;
425 u16 rsv:1;
426 u16 OBSS_NonHTExist:1;
427 u16 rsv2:11;
428};
429
430/* TODO: Need sync with spec about the definition of StbcMcs. In Draft 3.03, it's reserved. */
431struct PACKED rt_add_htinfo3 {
432 u16 StbcMcs:6;
433 u16 DualBeacon:1;
434 u16 DualCTSProtect:1;
435 u16 STBCBeacon:1;
436 u16 LsigTxopProt:1; /* L-SIG TXOP protection full support */
437 u16 PcoActive:1;
438 u16 PcoPhase:1;
439 u16 rsv:4;
440};
441
442#define SIZE_ADD_HT_INFO_IE 22
443struct PACKED rt_add_ht_info_ie {
444 u8 ControlChan;
445 struct rt_add_htinfo AddHtInfo;
446 struct rt_add_htinfo2 AddHtInfo2;
447 struct rt_add_htinfo3 AddHtInfo3;
448 u8 MCSSet[16]; /* Basic MCS set */
449};
450
451struct PACKED rt_new_ext_chan_ie {
452 u8 NewExtChanOffset;
453};
454
455struct PACKED rt_frame_802_11 {
456 struct rt_header_802_11 Hdr;
457 u8 Octet[1];
458};
459
460/* QoSNull embedding of management action. When HT Control MA field set to 1. */
461struct PACKED rt_ma_body {
462 u8 Category;
463 u8 Action;
464 u8 Octet[1];
465};
466
467struct PACKED rt_header_802_3 {
468 u8 DAAddr1[MAC_ADDR_LEN];
469 u8 SAAddr2[MAC_ADDR_LEN];
470 u8 Octet[2];
471};
472/*//Block ACK related format */
473/* 2-byte BA Parameter field in DELBA frames to terminate an already set up bA */
474struct PACKED rt_delba_parm {
475 u16 Rsv:11; /* always set to 0 */
476 u16 Initiator:1; /* 1: originator 0:recipient */
477 u16 TID:4; /* value of TC os TS */
478};
479
480/* 2-byte BA Parameter Set field in ADDBA frames to signal parm for setting up a BA */
481struct PACKED rt_ba_parm {
482 u16 AMSDUSupported:1; /* 0: not permitted 1: permitted */
483 u16 BAPolicy:1; /* 1: immediately BA 0:delayed BA */
484 u16 TID:4; /* value of TC os TS */
485 u16 BufSize:10; /* number of buffer of size 2304 octetsr */
486};
487
488/* 2-byte BA Starting Seq CONTROL field */
489typedef union PACKED _BASEQ_CONTROL {
490 struct PACKED {
491 u16 FragNum:4; /* always set to 0 */
492 u16 StartSeq:12; /* sequence number of the 1st MSDU for which this BAR is sent */
493 } field;
494 u16 word;
495} BASEQ_CONTROL, *PBASEQ_CONTROL;
496
497/*BAControl and BARControl are the same */
498/* 2-byte BA CONTROL field in BA frame */
499struct PACKED rt_ba_control {
500 u16 ACKPolicy:1; /* only related to N-Delayed BA. But not support in RT2860b. 0:NormalACK 1:No ACK */
501 u16 MTID:1; /*EWC V1.24 */
502 u16 Compressed:1;
503 u16 Rsv:9;
504 u16 TID:4;
505};
506
507/* 2-byte BAR CONTROL field in BAR frame */
508struct PACKED rt_bar_control {
509 u16 ACKPolicy:1; /* 0:normal ack, 1:no ack. */
510 u16 MTID:1; /*if this bit1, use struct rt_frame_mtba_req, if 0, use struct rt_frame_ba_req */
511 u16 Compressed:1;
512 u16 Rsv1:9;
513 u16 TID:4;
514};
515
516/* BARControl in MTBAR frame */
517struct PACKED rt_mtbar_control {
518 u16 ACKPolicy:1;
519 u16 MTID:1;
520 u16 Compressed:1;
521 u16 Rsv1:9;
522 u16 NumTID:4;
523};
524
525struct PACKED rt_per_tid_info {
526 u16 Rsv1:12;
527 u16 TID:4;
528};
529
530struct rt_each_tid {
531 struct rt_per_tid_info PerTID;
532 BASEQ_CONTROL BAStartingSeq;
533};
534
535/* BAREQ AND MTBAREQ have the same subtype BAR, 802.11n BAR use compressed bitmap. */
536struct PACKED rt_frame_ba_req {
537 struct rt_frame_control FC;
538 u16 Duration;
539 u8 Addr1[MAC_ADDR_LEN];
540 u8 Addr2[MAC_ADDR_LEN];
541 struct rt_bar_control BARControl;
542 BASEQ_CONTROL BAStartingSeq;
543};
544
545struct PACKED rt_frame_mtba_req {
546 struct rt_frame_control FC;
547 u16 Duration;
548 u8 Addr1[MAC_ADDR_LEN];
549 u8 Addr2[MAC_ADDR_LEN];
550 struct rt_mtbar_control MTBARControl;
551 struct rt_per_tid_info PerTIDInfo;
552 BASEQ_CONTROL BAStartingSeq;
553};
554
555/* Compressed format is mandatory in HT STA */
556struct PACKED rt_frame_mtba {
557 struct rt_frame_control FC;
558 u16 Duration;
559 u8 Addr1[MAC_ADDR_LEN];
560 u8 Addr2[MAC_ADDR_LEN];
561 struct rt_ba_control BAControl;
562 BASEQ_CONTROL BAStartingSeq;
563 u8 BitMap[8];
564};
565
566struct PACKED rt_frame_psmp_action {
567 struct rt_header_802_11 Hdr;
568 u8 Category;
569 u8 Action;
570 u8 Psmp; /* 7.3.1.25 */
571};
572
573struct PACKED rt_frame_action_hdr {
574 struct rt_header_802_11 Hdr;
575 u8 Category;
576 u8 Action;
577};
578
579/*Action Frame */
580/*Action Frame Category:Spectrum, Action:Channel Switch. 7.3.2.20 */
581struct PACKED rt_chan_switch_announce {
582 u8 ElementID; /* ID = IE_CHANNEL_SWITCH_ANNOUNCEMENT = 37 */
583 u8 Len;
584 struct rt_cha_switch_announce_ie CSAnnounceIe;
585};
586
587/*802.11n : 7.3.2.20a */
588struct PACKED rt_second_chan_offset {
589 u8 ElementID; /* ID = IE_SECONDARY_CH_OFFSET = 62 */
590 u8 Len;
591 struct rt_sec_cha_offset_ie SecChOffsetIe;
592};
593
594struct PACKED rt_frame_spetrum_cs {
595 struct rt_header_802_11 Hdr;
596 u8 Category;
597 u8 Action;
598 struct rt_chan_switch_announce CSAnnounce;
599 struct rt_second_chan_offset SecondChannel;
600};
601
602struct PACKED rt_frame_addba_req {
603 struct rt_header_802_11 Hdr;
604 u8 Category;
605 u8 Action;
606 u8 Token; /* 1 */
607 struct rt_ba_parm BaParm; /* 2 - 10 */
608 u16 TimeOutValue; /* 0 - 0 */
609 BASEQ_CONTROL BaStartSeq; /* 0-0 */
610};
611
612struct PACKED rt_frame_addba_rsp {
613 struct rt_header_802_11 Hdr;
614 u8 Category;
615 u8 Action;
616 u8 Token;
617 u16 StatusCode;
618 struct rt_ba_parm BaParm; /*0 - 2 */
619 u16 TimeOutValue;
620};
621
622struct PACKED rt_frame_delba_req {
623 struct rt_header_802_11 Hdr;
624 u8 Category;
625 u8 Action;
626 struct rt_delba_parm DelbaParm;
627 u16 ReasonCode;
628};
629
630/*7.2.1.7 */
631struct PACKED rt_frame_bar {
632 struct rt_frame_control FC;
633 u16 Duration;
634 u8 Addr1[MAC_ADDR_LEN];
635 u8 Addr2[MAC_ADDR_LEN];
636 struct rt_bar_control BarControl;
637 BASEQ_CONTROL StartingSeq;
638};
639
640/*7.2.1.7 */
641struct PACKED rt_frame_ba {
642 struct rt_frame_control FC;
643 u16 Duration;
644 u8 Addr1[MAC_ADDR_LEN];
645 u8 Addr2[MAC_ADDR_LEN];
646 struct rt_bar_control BarControl;
647 BASEQ_CONTROL StartingSeq;
648 u8 bitmask[8];
649};
650
651/* Radio Measurement Request Frame Format */
652struct PACKED rt_frame_rm_req_action {
653 struct rt_header_802_11 Hdr;
654 u8 Category;
655 u8 Action;
656 u8 Token;
657 u16 Repetition;
658 u8 data[0];
659};
660
661struct PACKED rt_ht_ext_channel_switch_announcement_ie {
662 u8 ID;
663 u8 Length;
664 u8 ChannelSwitchMode;
665 u8 NewRegClass;
666 u8 NewChannelNum;
667 u8 ChannelSwitchCount;
668};
669
670/* */
671/* _Limit must be the 2**n - 1 */
672/* _SEQ1 , _SEQ2 must be within 0 ~ _Limit */
673/* */
674#define SEQ_STEPONE(_SEQ1, _SEQ2, _Limit) ((_SEQ1 == ((_SEQ2+1) & _Limit)))
675#define SEQ_SMALLER(_SEQ1, _SEQ2, _Limit) (((_SEQ1-_SEQ2) & ((_Limit+1)>>1)))
676#define SEQ_LARGER(_SEQ1, _SEQ2, _Limit) ((_SEQ1 != _SEQ2) && !(((_SEQ1-_SEQ2) & ((_Limit+1)>>1))))
677#define SEQ_WITHIN_WIN(_SEQ1, _SEQ2, _WIN, _Limit) (SEQ_LARGER(_SEQ1, _SEQ2, _Limit) && \
678 SEQ_SMALLER(_SEQ1, ((_SEQ2+_WIN+1)&_Limit), _Limit))
679
680/* */
681/* Contention-free parameter (without ID and Length) */
682/* */
683struct PACKED rt_cf_parm {
684 BOOLEAN bValid; /* 1: variable contains valid value */
685 u8 CfpCount;
686 u8 CfpPeriod;
687 u16 CfpMaxDuration;
688 u16 CfpDurRemaining;
689};
690
691struct rt_cipher_suite {
692 NDIS_802_11_ENCRYPTION_STATUS PairCipher; /* Unicast cipher 1, this one has more secured cipher suite */
693 NDIS_802_11_ENCRYPTION_STATUS PairCipherAux; /* Unicast cipher 2 if AP announce two unicast cipher suite */
694 NDIS_802_11_ENCRYPTION_STATUS GroupCipher; /* Group cipher */
695 u16 RsnCapability; /* RSN capability from beacon */
696 BOOLEAN bMixMode; /* Indicate Pair & Group cipher might be different */
697};
698
699/* EDCA configuration from AP's BEACON/ProbeRsp */
700struct rt_edca_parm {
701 BOOLEAN bValid; /* 1: variable contains valid value */
702 BOOLEAN bAdd; /* 1: variable contains valid value */
703 BOOLEAN bQAck;
704 BOOLEAN bQueueRequest;
705 BOOLEAN bTxopRequest;
706 BOOLEAN bAPSDCapable;
707/* BOOLEAN bMoreDataAck; */
708 u8 EdcaUpdateCount;
709 u8 Aifsn[4]; /* 0:AC_BK, 1:AC_BE, 2:AC_VI, 3:AC_VO */
710 u8 Cwmin[4];
711 u8 Cwmax[4];
712 u16 Txop[4]; /* in unit of 32-us */
713 BOOLEAN bACM[4]; /* 1: Admission Control of AC_BK is mandatory */
714};
715
716/* QBSS LOAD information from QAP's BEACON/ProbeRsp */
717struct rt_qbss_load_parm {
718 BOOLEAN bValid; /* 1: variable contains valid value */
719 u16 StaNum;
720 u8 ChannelUtilization;
721 u16 RemainingAdmissionControl; /* in unit of 32-us */
722};
723
724/* QBSS Info field in QSTA's assoc req */
725struct PACKED rt_qbss_sta_info_parm {
726 u8 UAPSD_AC_VO:1;
727 u8 UAPSD_AC_VI:1;
728 u8 UAPSD_AC_BK:1;
729 u8 UAPSD_AC_BE:1;
730 u8 Rsv1:1;
731 u8 MaxSPLength:2;
732 u8 Rsv2:1;
733};
734
735/* QBSS Info field in QAP's Beacon/ProbeRsp */
736struct PACKED rt_qbss_ap_info_parm {
737 u8 ParamSetCount:4;
738 u8 Rsv:3;
739 u8 UAPSD:1;
740};
741
742/* QOS Capability reported in QAP's BEACON/ProbeRsp */
743/* QOS Capability sent out in QSTA's AssociateReq/ReAssociateReq */
744struct rt_qos_capability_parm {
745 BOOLEAN bValid; /* 1: variable contains valid value */
746 BOOLEAN bQAck;
747 BOOLEAN bQueueRequest;
748 BOOLEAN bTxopRequest;
749/* BOOLEAN bMoreDataAck; */
750 u8 EdcaUpdateCount;
751};
752
753struct rt_wpa_ie {
754 u8 IELen;
755 u8 IE[MAX_CUSTOM_LEN];
756};
757
758struct rt_bss_entry {
759 u8 Bssid[MAC_ADDR_LEN];
760 u8 Channel;
761 u8 CentralChannel; /*Store the wide-band central channel for 40MHz. used in 40MHz AP. Or this is the same as Channel. */
762 u8 BssType;
763 u16 AtimWin;
764 u16 BeaconPeriod;
765
766 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
767 u8 SupRateLen;
768 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
769 u8 ExtRateLen;
770 struct rt_ht_capability_ie HtCapability;
771 u8 HtCapabilityLen;
772 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
773 u8 AddHtInfoLen;
774 u8 NewExtChanOffset;
775 char Rssi;
776 u8 Privacy; /* Indicate security function ON/OFF. Don't mess up with auth mode. */
777 u8 Hidden;
778
779 u16 DtimPeriod;
780 u16 CapabilityInfo;
781
782 u16 CfpCount;
783 u16 CfpPeriod;
784 u16 CfpMaxDuration;
785 u16 CfpDurRemaining;
786 u8 SsidLen;
787 char Ssid[MAX_LEN_OF_SSID];
788
789 unsigned long LastBeaconRxTime; /* OS's timestamp */
790
791 BOOLEAN bSES;
792
793 /* New for WPA2 */
794 struct rt_cipher_suite WPA; /* AP announced WPA cipher suite */
795 struct rt_cipher_suite WPA2; /* AP announced WPA2 cipher suite */
796
797 /* New for microsoft WPA support */
798 struct rt_ndis_802_11_fixed_ies FixIEs;
799 NDIS_802_11_AUTHENTICATION_MODE AuthModeAux; /* Addition mode for WPA2 / WPA capable AP */
800 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
801 NDIS_802_11_WEP_STATUS WepStatus; /* Unicast Encryption Algorithm extract from VAR_IE */
802 u16 VarIELen; /* Length of next VIE include EID & Length */
803 u8 VarIEs[MAX_VIE_LEN];
804
805 /* CCX Ckip information */
806 u8 CkipFlag;
807
808 /* CCX 2 TSF */
809 u8 PTSF[4]; /* Parent TSF */
810 u8 TTSF[8]; /* Target TSF */
811
812 /* 802.11e d9, and WMM */
813 struct rt_edca_parm EdcaParm;
814 struct rt_qos_capability_parm QosCapability;
815 struct rt_qbss_load_parm QbssLoad;
816 struct rt_wpa_ie WpaIE;
817 struct rt_wpa_ie RsnIE;
818};
819
820struct rt_bss_table {
821 u8 BssNr;
822 u8 BssOverlapNr;
823 struct rt_bss_entry BssEntry[MAX_LEN_OF_BSS_TABLE];
824};
825
826struct rt_mlme_queue_elem {
827 unsigned long Machine;
828 unsigned long MsgType;
829 unsigned long MsgLen;
830 u8 Msg[MGMT_DMA_BUFFER_SIZE];
831 LARGE_INTEGER TimeStamp;
832 u8 Rssi0;
833 u8 Rssi1;
834 u8 Rssi2;
835 u8 Signal;
836 u8 Channel;
837 u8 Wcid;
838 BOOLEAN Occupied;
839};
840
841struct rt_mlme_queue {
842 unsigned long Num;
843 unsigned long Head;
844 unsigned long Tail;
845 spinlock_t Lock;
846 struct rt_mlme_queue_elem Entry[MAX_LEN_OF_MLME_QUEUE];
847};
848
849typedef void(*STATE_MACHINE_FUNC) (void *Adaptor, struct rt_mlme_queue_elem *Elem);
850
851struct rt_state_machine {
852 unsigned long Base;
853 unsigned long NrState;
854 unsigned long NrMsg;
855 unsigned long CurrState;
856 STATE_MACHINE_FUNC *TransFunc;
857};
858
859/* MLME AUX data structure that holds temporarliy settings during a connection attempt. */
860/* Once this attempt succeeds, all settings will be copy to pAd->StaActive. */
861/* A connection attempt (user set OID, roaming, CCX fast roaming,..) consists of */
862/* several steps (JOIN, AUTH, ASSOC or REASSOC) and may fail at any step. We purposely */
863/* separate this under-trial settings away from pAd->StaActive so that once */
864/* this new attempt failed, driver can auto-recover back to the active settings. */
865struct rt_mlme_aux {
866 u8 BssType;
867 u8 Ssid[MAX_LEN_OF_SSID];
868 u8 SsidLen;
869 u8 Bssid[MAC_ADDR_LEN];
870 u8 AutoReconnectSsid[MAX_LEN_OF_SSID];
871 u8 AutoReconnectSsidLen;
872 u16 Alg;
873 u8 ScanType;
874 u8 Channel;
875 u8 CentralChannel;
876 u16 Aid;
877 u16 CapabilityInfo;
878 u16 BeaconPeriod;
879 u16 CfpMaxDuration;
880 u16 CfpPeriod;
881 u16 AtimWin;
882
883 /* Copy supported rate from desired AP's beacon. We are trying to match */
884 /* AP's supported and extended rate settings. */
885 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
886 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
887 u8 SupRateLen;
888 u8 ExtRateLen;
889 struct rt_ht_capability_ie HtCapability;
890 u8 HtCapabilityLen;
891 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
892 u8 NewExtChannelOffset;
893 /*struct rt_ht_capability SupportedHtPhy; */
894
895 /* new for QOS */
896 struct rt_qos_capability_parm APQosCapability; /* QOS capability of the current associated AP */
897 struct rt_edca_parm APEdcaParm; /* EDCA parameters of the current associated AP */
898 struct rt_qbss_load_parm APQbssLoad; /* QBSS load of the current associated AP */
899
900 /* new to keep Ralink specific feature */
901 unsigned long APRalinkIe;
902
903 struct rt_bss_table SsidBssTab; /* AP list for the same SSID */
904 struct rt_bss_table RoamTab; /* AP list eligible for roaming */
905 unsigned long BssIdx;
906 unsigned long RoamIdx;
907
908 BOOLEAN CurrReqIsFromNdis;
909
910 struct rt_ralink_timer BeaconTimer, ScanTimer;
911 struct rt_ralink_timer AuthTimer;
912 struct rt_ralink_timer AssocTimer, ReassocTimer, DisassocTimer;
913};
914
915struct rt_mlme_addba_req {
916 u8 Wcid; /* */
917 u8 pAddr[MAC_ADDR_LEN];
918 u8 BaBufSize;
919 u16 TimeOutValue;
920 u8 TID;
921 u8 Token;
922 u16 BaStartSeq;
923};
924
925struct rt_mlme_delba_req {
926 u8 Wcid; /* */
927 u8 Addr[MAC_ADDR_LEN];
928 u8 TID;
929 u8 Initiator;
930};
931
932/* assoc struct is equal to reassoc */
933struct rt_mlme_assoc_req {
934 u8 Addr[MAC_ADDR_LEN];
935 u16 CapabilityInfo;
936 u16 ListenIntv;
937 unsigned long Timeout;
938};
939
940struct rt_mlme_disassoc_req {
941 u8 Addr[MAC_ADDR_LEN];
942 u16 Reason;
943};
944
945struct rt_mlme_auth_req {
946 u8 Addr[MAC_ADDR_LEN];
947 u16 Alg;
948 unsigned long Timeout;
949};
950
951struct rt_mlme_deauth_req {
952 u8 Addr[MAC_ADDR_LEN];
953 u16 Reason;
954};
955
956struct rt_mlme_join_req {
957 unsigned long BssIdx;
958};
959
960struct rt_mlme_scan_req {
961 u8 Bssid[MAC_ADDR_LEN];
962 u8 BssType;
963 u8 ScanType;
964 u8 SsidLen;
965 char Ssid[MAX_LEN_OF_SSID];
966};
967
968struct rt_mlme_start_req {
969 char Ssid[MAX_LEN_OF_SSID];
970 u8 SsidLen;
971};
972
973struct PACKED rt_eid {
974 u8 Eid;
975 u8 Len;
976 u8 Octet[1];
977};
978
979struct PACKED rt_rtmp_tx_rate_switch {
980 u8 ItemNo;
981 u8 STBC:1;
982 u8 ShortGI:1;
983 u8 BW:1;
984 u8 Rsv1:1;
985 u8 Mode:2;
986 u8 Rsv2:2;
987 u8 CurrMCS;
988 u8 TrainUp;
989 u8 TrainDown;
990};
991
992/* ========================== AP mlme.h =============================== */
993#define TBTT_PRELOAD_TIME 384 /* usec. LomgPreamble + 24-byte at 1Mbps */
994#define DEFAULT_DTIM_PERIOD 1
995
996#define MAC_TABLE_AGEOUT_TIME 300 /* unit: sec */
997#define MAC_TABLE_ASSOC_TIMEOUT 5 /* unit: sec */
998#define MAC_TABLE_FULL(Tab) ((Tab).size == MAX_LEN_OF_MAC_TABLE)
999
1000/* AP shall drop the sta if continue Tx fail count reach it. */
1001#define MAC_ENTRY_LIFE_CHECK_CNT 20 /* packet cnt. */
1002
1003/* Value domain of pMacEntry->Sst */
1004typedef enum _Sst {
1005 SST_NOT_AUTH, /* 0: equivalent to IEEE 802.11/1999 state 1 */
1006 SST_AUTH, /* 1: equivalent to IEEE 802.11/1999 state 2 */
1007 SST_ASSOC /* 2: equivalent to IEEE 802.11/1999 state 3 */
1008} SST;
1009
1010/* value domain of pMacEntry->AuthState */
1011typedef enum _AuthState {
1012 AS_NOT_AUTH,
1013 AS_AUTH_OPEN, /* STA has been authenticated using OPEN SYSTEM */
1014 AS_AUTH_KEY, /* STA has been authenticated using SHARED KEY */
1015 AS_AUTHENTICATING /* STA is waiting for AUTH seq#3 using SHARED KEY */
1016} AUTH_STATE;
1017
1018/*for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114 */
1019typedef enum _ApWpaState {
1020 AS_NOTUSE, /* 0 */
1021 AS_DISCONNECT, /* 1 */
1022 AS_DISCONNECTED, /* 2 */
1023 AS_INITIALIZE, /* 3 */
1024 AS_AUTHENTICATION, /* 4 */
1025 AS_AUTHENTICATION2, /* 5 */
1026 AS_INITPMK, /* 6 */
1027 AS_INITPSK, /* 7 */
1028 AS_PTKSTART, /* 8 */
1029 AS_PTKINIT_NEGOTIATING, /* 9 */
1030 AS_PTKINITDONE, /* 10 */
1031 AS_UPDATEKEYS, /* 11 */
1032 AS_INTEGRITY_FAILURE, /* 12 */
1033 AS_KEYUPDATE, /* 13 */
1034} AP_WPA_STATE;
1035
1036/* for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114 */
1037typedef enum _GTKState {
1038 REKEY_NEGOTIATING,
1039 REKEY_ESTABLISHED,
1040 KEYERROR,
1041} GTK_STATE;
1042
1043/* for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114 */
1044typedef enum _WpaGTKState {
1045 SETKEYS,
1046 SETKEYS_DONE,
1047} WPA_GTK_STATE;
1048/* ====================== end of AP mlme.h ============================ */
1049
1050#endif /* MLME_H__ */
diff --git a/drivers/staging/rt2860/oid.h b/drivers/staging/rt2860/oid.h
deleted file mode 100644
index 5a25f0d3cfe..00000000000
--- a/drivers/staging/rt2860/oid.h
+++ /dev/null
@@ -1,779 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 oid.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Justin P. Mattock 11/07/2010 Fix typos in comments
37*/
38#ifndef _OID_H_
39#define _OID_H_
40
41/*#include <linux/wireless.h> */
42
43#ifndef TRUE
44#define TRUE 1
45#endif
46#ifndef FALSE
47#define FALSE 0
48#endif
49/* */
50/* IEEE 802.11 Structures and definitions */
51/* */
52#define MAX_TX_POWER_LEVEL 100 /* mW */
53#define MAX_RSSI_TRIGGER -10 /* dBm */
54#define MIN_RSSI_TRIGGER -200 /* dBm */
55#define MAX_FRAG_THRESHOLD 2346 /* byte count */
56#define MIN_FRAG_THRESHOLD 256 /* byte count */
57#define MAX_RTS_THRESHOLD 2347 /* byte count */
58
59/* new types for Media Specific Indications */
60/* Extension channel offset */
61#define EXTCHA_NONE 0
62#define EXTCHA_ABOVE 0x1
63#define EXTCHA_BELOW 0x3
64
65/* BW */
66#define BAND_WIDTH_20 0
67#define BAND_WIDTH_40 1
68#define BAND_WIDTH_BOTH 2
69#define BAND_WIDTH_10 3 /* 802.11j has 10MHz. This definition is for internal usage. doesn't fill in the IE or other field. */
70/* SHORTGI */
71#define GAP_INTERVAL_400 1 /* only support in HT mode */
72#define GAP_INTERVAL_800 0
73#define GAP_INTERVAL_BOTH 2
74
75#define NdisMediaStateConnected 1
76#define NdisMediaStateDisconnected 0
77
78#define NDIS_802_11_LENGTH_SSID 32
79#define NDIS_802_11_LENGTH_RATES 8
80#define NDIS_802_11_LENGTH_RATES_EX 16
81#define MAC_ADDR_LENGTH 6
82/*#define MAX_NUM_OF_CHS 49 // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination */
83#define MAX_NUM_OF_CHS 54 /* 14 channels @2.4G + 12@UNII(lower/middle) + 16@HiperLAN2 + 11@UNII(upper) + 0 @Japan + 1 as NULL termination */
84#define MAX_NUMBER_OF_EVENT 10 /* entry # in EVENT table */
85#define MAX_NUMBER_OF_MAC 32 /* if MAX_MBSSID_NUM is 8, this value can't be larger than 211 */
86#define MAX_NUMBER_OF_ACL 64
87#define MAX_LENGTH_OF_SUPPORT_RATES 12 /* 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */
88#define MAX_NUMBER_OF_DLS_ENTRY 4
89
90#define RT_QUERY_SIGNAL_CONTEXT 0x0402
91#define RT_SET_IAPP_PID 0x0404
92#define RT_SET_APD_PID 0x0405
93#define RT_SET_DEL_MAC_ENTRY 0x0406
94#define RT_QUERY_EVENT_TABLE 0x0407
95/* */
96/* IEEE 802.11 OIDs */
97/* */
98#define OID_GET_SET_TOGGLE 0x8000
99#define OID_GET_SET_FROM_UI 0x4000
100
101#define OID_802_11_ADD_WEP 0x0112
102#define OID_802_11_DISASSOCIATE 0x0114
103#define OID_802_11_BSSID_LIST_SCAN 0x0508
104#define OID_802_11_SSID 0x0509
105#define OID_802_11_BSSID 0x050A
106#define OID_802_11_MIC_FAILURE_REPORT_FRAME 0x0528
107
108#define RT_OID_DEVICE_NAME 0x0607
109#define RT_OID_VERSION_INFO 0x0608
110#define OID_802_11_BSSID_LIST 0x0609
111#define OID_802_3_CURRENT_ADDRESS 0x060A
112#define OID_GEN_MEDIA_CONNECT_STATUS 0x060B
113#define RT_OID_802_11_QUERY_LINK_STATUS 0x060C
114#define OID_802_11_RSSI 0x060D
115#define OID_802_11_STATISTICS 0x060E
116#define OID_GEN_RCV_OK 0x060F
117#define OID_GEN_RCV_NO_BUFFER 0x0610
118#define RT_OID_802_11_QUERY_EEPROM_VERSION 0x0611
119#define RT_OID_802_11_QUERY_FIRMWARE_VERSION 0x0612
120#define RT_OID_802_11_QUERY_LAST_RX_RATE 0x0613
121#define RT_OID_802_11_TX_POWER_LEVEL_1 0x0614
122#define RT_OID_802_11_QUERY_PIDVID 0x0615
123/*for WPA_SUPPLICANT_SUPPORT */
124#define OID_SET_COUNTERMEASURES 0x0616
125#define RT_OID_WPA_SUPPLICANT_SUPPORT 0x0621
126#define RT_OID_WE_VERSION_COMPILED 0x0622
127#define RT_OID_NEW_DRIVER 0x0623
128
129#define RT_OID_DRIVER_DEVICE_NAME 0x0645
130#define RT_OID_QUERY_MULTIPLE_CARD_SUPPORT 0x0647
131
132typedef enum _NDIS_802_11_STATUS_TYPE {
133 Ndis802_11StatusType_Authentication,
134 Ndis802_11StatusType_MediaStreamMode,
135 Ndis802_11StatusType_PMKID_CandidateList,
136 Ndis802_11StatusTypeMax /* not a real type, defined as an upper bound */
137} NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
138
139typedef u8 NDIS_802_11_MAC_ADDRESS[6];
140
141struct rt_ndis_802_11_status_indication {
142 NDIS_802_11_STATUS_TYPE StatusType;
143};
144
145/* mask for authentication/integrity fields */
146#define NDIS_802_11_AUTH_REQUEST_AUTH_FIELDS 0x0f
147
148#define NDIS_802_11_AUTH_REQUEST_REAUTH 0x01
149#define NDIS_802_11_AUTH_REQUEST_KEYUPDATE 0x02
150#define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR 0x06
151#define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR 0x0E
152
153struct rt_ndis_802_11_authentication_request {
154 unsigned long Length; /* Length of structure */
155 NDIS_802_11_MAC_ADDRESS Bssid;
156 unsigned long Flags;
157};
158
159/*Added new types for PMKID Candidate lists. */
160struct rt_pmkid_candidate {
161 NDIS_802_11_MAC_ADDRESS BSSID;
162 unsigned long Flags;
163};
164
165struct rt_ndis_802_11_pmkid_candidate_list {
166 unsigned long Version; /* Version of the structure */
167 unsigned long NumCandidates; /* No. of pmkid candidates */
168 struct rt_pmkid_candidate CandidateList[1];
169};
170
171/*Flags for PMKID Candidate list structure */
172#define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
173
174/* Added new types for OFDM 5G and 2.4G */
175typedef enum _NDIS_802_11_NETWORK_TYPE {
176 Ndis802_11FH,
177 Ndis802_11DS,
178 Ndis802_11OFDM5,
179 Ndis802_11OFDM24,
180 Ndis802_11Automode,
181 Ndis802_11OFDM5_N,
182 Ndis802_11OFDM24_N,
183 Ndis802_11NetworkTypeMax /* not a real type, defined as an upper bound */
184} NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE;
185
186struct rt_ndis_802_11_network_type_list {
187 u32 NumberOfItems; /* in list below, at least 1 */
188 NDIS_802_11_NETWORK_TYPE NetworkType[1];
189};
190
191typedef enum _NDIS_802_11_POWER_MODE {
192 Ndis802_11PowerModeCAM,
193 Ndis802_11PowerModeMAX_PSP,
194 Ndis802_11PowerModeFast_PSP,
195 Ndis802_11PowerModeLegacy_PSP,
196 Ndis802_11PowerModeMax /* not a real mode, defined as an upper bound */
197} NDIS_802_11_POWER_MODE, *PNDIS_802_11_POWER_MODE;
198
199typedef unsigned long NDIS_802_11_TX_POWER_LEVEL; /* in milliwatts */
200
201/* */
202/* Received Signal Strength Indication */
203/* */
204typedef long NDIS_802_11_RSSI; /* in dBm */
205
206struct rt_ndis_802_11_configuration_fh {
207 unsigned long Length; /* Length of structure */
208 unsigned long HopPattern; /* As defined by 802.11, MSB set */
209 unsigned long HopSet; /* to one if non-802.11 */
210 unsigned long DwellTime; /* units are Kusec */
211};
212
213struct rt_ndis_802_11_configuration {
214 unsigned long Length; /* Length of structure */
215 unsigned long BeaconPeriod; /* units are Kusec */
216 unsigned long ATIMWindow; /* units are Kusec */
217 unsigned long DSConfig; /* Frequency, units are kHz */
218 struct rt_ndis_802_11_configuration_fh FHConfig;
219};
220
221struct rt_ndis_802_11_statistics {
222 unsigned long Length; /* Length of structure */
223 LARGE_INTEGER TransmittedFragmentCount;
224 LARGE_INTEGER MulticastTransmittedFrameCount;
225 LARGE_INTEGER FailedCount;
226 LARGE_INTEGER RetryCount;
227 LARGE_INTEGER MultipleRetryCount;
228 LARGE_INTEGER RTSSuccessCount;
229 LARGE_INTEGER RTSFailureCount;
230 LARGE_INTEGER ACKFailureCount;
231 LARGE_INTEGER FrameDuplicateCount;
232 LARGE_INTEGER ReceivedFragmentCount;
233 LARGE_INTEGER MulticastReceivedFrameCount;
234 LARGE_INTEGER FCSErrorCount;
235 LARGE_INTEGER TKIPLocalMICFailures;
236 LARGE_INTEGER TKIPRemoteMICErrors;
237 LARGE_INTEGER TKIPICVErrors;
238 LARGE_INTEGER TKIPCounterMeasuresInvoked;
239 LARGE_INTEGER TKIPReplays;
240 LARGE_INTEGER CCMPFormatErrors;
241 LARGE_INTEGER CCMPReplays;
242 LARGE_INTEGER CCMPDecryptErrors;
243 LARGE_INTEGER FourWayHandshakeFailures;
244};
245
246typedef unsigned long NDIS_802_11_KEY_INDEX;
247typedef unsigned long long NDIS_802_11_KEY_RSC;
248
249#define MAX_RADIUS_SRV_NUM 2 /* 802.1x failover number */
250
251struct PACKED rt_radius_srv_info {
252 u32 radius_ip;
253 u32 radius_port;
254 u8 radius_key[64];
255 u8 radius_key_len;
256};
257
258struct PACKED rt_radius_key_info {
259 u8 radius_srv_num;
260 struct rt_radius_srv_info radius_srv_info[MAX_RADIUS_SRV_NUM];
261 u8 ieee8021xWEP; /* dynamic WEP */
262 u8 key_index;
263 u8 key_length; /* length of key in bytes */
264 u8 key_material[13];
265};
266
267/* It's used by 802.1x daemon to require relative configuration */
268struct PACKED rt_radius_conf {
269 u32 Length; /* Length of this structure */
270 u8 mbss_num; /* indicate multiple BSS number */
271 u32 own_ip_addr;
272 u32 retry_interval;
273 u32 session_timeout_interval;
274 u8 EAPifname[8][IFNAMSIZ];
275 u8 EAPifname_len[8];
276 u8 PreAuthifname[8][IFNAMSIZ];
277 u8 PreAuthifname_len[8];
278 struct rt_radius_key_info RadiusInfo[8];
279};
280
281/* Key mapping keys require a BSSID */
282struct rt_ndis_802_11_key {
283 u32 Length; /* Length of this structure */
284 u32 KeyIndex;
285 u32 KeyLength; /* length of key in bytes */
286 NDIS_802_11_MAC_ADDRESS BSSID;
287 NDIS_802_11_KEY_RSC KeyRSC;
288 u8 KeyMaterial[1]; /* variable length depending on above field */
289};
290
291struct rt_ndis_802_11_passphrase {
292 u32 KeyLength; /* length of key in bytes */
293 NDIS_802_11_MAC_ADDRESS BSSID;
294 u8 KeyMaterial[1]; /* variable length depending on above field */
295};
296
297struct rt_ndis_802_11_remove_key {
298 u32 Length; /* Length of this structure */
299 u32 KeyIndex;
300 NDIS_802_11_MAC_ADDRESS BSSID;
301};
302
303struct rt_ndis_802_11_wep {
304 u32 Length; /* Length of this structure */
305 u32 KeyIndex; /* 0 is the per-client key, 1-N are the */
306 /* global keys */
307 u32 KeyLength; /* length of key in bytes */
308 u8 KeyMaterial[1]; /* variable length depending on above field */
309};
310
311typedef enum _NDIS_802_11_NETWORK_INFRASTRUCTURE {
312 Ndis802_11IBSS,
313 Ndis802_11Infrastructure,
314 Ndis802_11AutoUnknown,
315 Ndis802_11Monitor,
316 Ndis802_11InfrastructureMax /* Not a real value, defined as upper bound */
317} NDIS_802_11_NETWORK_INFRASTRUCTURE, *PNDIS_802_11_NETWORK_INFRASTRUCTURE;
318
319/* Add new authentication modes */
320typedef enum _NDIS_802_11_AUTHENTICATION_MODE {
321 Ndis802_11AuthModeOpen,
322 Ndis802_11AuthModeShared,
323 Ndis802_11AuthModeAutoSwitch,
324 Ndis802_11AuthModeWPA,
325 Ndis802_11AuthModeWPAPSK,
326 Ndis802_11AuthModeWPANone,
327 Ndis802_11AuthModeWPA2,
328 Ndis802_11AuthModeWPA2PSK,
329 Ndis802_11AuthModeWPA1WPA2,
330 Ndis802_11AuthModeWPA1PSKWPA2PSK,
331 Ndis802_11AuthModeMax /* Not a real mode, defined as upper bound */
332} NDIS_802_11_AUTHENTICATION_MODE, *PNDIS_802_11_AUTHENTICATION_MODE;
333
334typedef u8 NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES]; /* Set of 8 data rates */
335typedef u8 NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX]; /* Set of 16 data rates */
336
337struct PACKED rt_ndis_802_11_ssid {
338 u32 SsidLength; /* length of SSID field below, in bytes; */
339 /* this can be zero. */
340 u8 Ssid[NDIS_802_11_LENGTH_SSID]; /* SSID information field */
341};
342
343struct PACKED rt_ndis_wlan_bssid {
344 unsigned long Length; /* Length of this structure */
345 NDIS_802_11_MAC_ADDRESS MacAddress; /* BSSID */
346 u8 Reserved[2];
347 struct rt_ndis_802_11_ssid Ssid; /* SSID */
348 unsigned long Privacy; /* WEP encryption requirement */
349 NDIS_802_11_RSSI Rssi; /* receive signal strength in dBm */
350 NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
351 struct rt_ndis_802_11_configuration Configuration;
352 NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
353 NDIS_802_11_RATES SupportedRates;
354};
355
356struct PACKED rt_ndis_802_11_bssid_list {
357 u32 NumberOfItems; /* in list below, at least 1 */
358 struct rt_ndis_wlan_bssid Bssid[1];
359};
360
361/* Added Capabilities, IELength and IEs for each BSSID */
362struct PACKED rt_ndis_wlan_bssid_ex {
363 unsigned long Length; /* Length of this structure */
364 NDIS_802_11_MAC_ADDRESS MacAddress; /* BSSID */
365 u8 Reserved[2];
366 struct rt_ndis_802_11_ssid Ssid; /* SSID */
367 u32 Privacy; /* WEP encryption requirement */
368 NDIS_802_11_RSSI Rssi; /* receive signal */
369 /* strength in dBm */
370 NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
371 struct rt_ndis_802_11_configuration Configuration;
372 NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode;
373 NDIS_802_11_RATES_EX SupportedRates;
374 unsigned long IELength;
375 u8 IEs[1];
376};
377
378struct PACKED rt_ndis_802_11_bssid_list_ex {
379 u32 NumberOfItems; /* in list below, at least 1 */
380 struct rt_ndis_wlan_bssid_ex Bssid[1];
381};
382
383struct PACKED rt_ndis_802_11_fixed_ies {
384 u8 Timestamp[8];
385 u16 BeaconInterval;
386 u16 Capabilities;
387};
388
389struct rt_ndis_802_11_variable_ies {
390 u8 ElementID;
391 u8 Length; /* Number of bytes in data field */
392 u8 data[1];
393};
394
395typedef unsigned long NDIS_802_11_FRAGMENTATION_THRESHOLD;
396
397typedef unsigned long NDIS_802_11_RTS_THRESHOLD;
398
399typedef unsigned long NDIS_802_11_ANTENNA;
400
401typedef enum _NDIS_802_11_PRIVACY_FILTER {
402 Ndis802_11PrivFilterAcceptAll,
403 Ndis802_11PrivFilter8021xWEP
404} NDIS_802_11_PRIVACY_FILTER, *PNDIS_802_11_PRIVACY_FILTER;
405
406/* Added new encryption types */
407/* Also aliased typedef to new name */
408typedef enum _NDIS_802_11_WEP_STATUS {
409 Ndis802_11WEPEnabled,
410 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
411 Ndis802_11WEPDisabled,
412 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
413 Ndis802_11WEPKeyAbsent,
414 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
415 Ndis802_11WEPNotSupported,
416 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
417 Ndis802_11Encryption2Enabled,
418 Ndis802_11Encryption2KeyAbsent,
419 Ndis802_11Encryption3Enabled,
420 Ndis802_11Encryption3KeyAbsent,
421 Ndis802_11Encryption4Enabled, /* TKIP or AES mix */
422 Ndis802_11Encryption4KeyAbsent,
423 Ndis802_11GroupWEP40Enabled,
424 Ndis802_11GroupWEP104Enabled,
425} NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
426 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
427
428typedef enum _NDIS_802_11_RELOAD_DEFAULTS {
429 Ndis802_11ReloadWEPKeys
430} NDIS_802_11_RELOAD_DEFAULTS, *PNDIS_802_11_RELOAD_DEFAULTS;
431
432#define NDIS_802_11_AI_REQFI_CAPABILITIES 1
433#define NDIS_802_11_AI_REQFI_LISTENINTERVAL 2
434#define NDIS_802_11_AI_REQFI_CURRENTAPADDRESS 4
435
436#define NDIS_802_11_AI_RESFI_CAPABILITIES 1
437#define NDIS_802_11_AI_RESFI_STATUSCODE 2
438#define NDIS_802_11_AI_RESFI_ASSOCIATIONID 4
439
440struct rt_ndis_802_11_ai_reqfi {
441 u16 Capabilities;
442 u16 ListenInterval;
443 NDIS_802_11_MAC_ADDRESS CurrentAPAddress;
444};
445
446struct rt_ndis_802_11_ai_resfi {
447 u16 Capabilities;
448 u16 StatusCode;
449 u16 AssociationId;
450};
451
452struct rt_ndis_802_11_association_information {
453 unsigned long Length;
454 u16 AvailableRequestFixedIEs;
455 struct rt_ndis_802_11_ai_reqfi RequestFixedIEs;
456 unsigned long RequestIELength;
457 unsigned long OffsetRequestIEs;
458 u16 AvailableResponseFixedIEs;
459 struct rt_ndis_802_11_ai_resfi ResponseFixedIEs;
460 unsigned long ResponseIELength;
461 unsigned long OffsetResponseIEs;
462};
463
464struct rt_ndis_802_11_authentication_event {
465 struct rt_ndis_802_11_status_indication Status;
466 struct rt_ndis_802_11_authentication_request Request[1];
467};
468
469/* 802.11 Media stream constraints, associated with OID_802_11_MEDIA_STREAM_MODE */
470typedef enum _NDIS_802_11_MEDIA_STREAM_MODE {
471 Ndis802_11MediaStreamOff,
472 Ndis802_11MediaStreamOn,
473} NDIS_802_11_MEDIA_STREAM_MODE, *PNDIS_802_11_MEDIA_STREAM_MODE;
474
475/* PMKID Structures */
476typedef u8 NDIS_802_11_PMKID_VALUE[16];
477
478struct rt_bssid_info {
479 NDIS_802_11_MAC_ADDRESS BSSID;
480 NDIS_802_11_PMKID_VALUE PMKID;
481};
482
483struct rt_ndis_802_11_pmkid {
484 u32 Length;
485 u32 BSSIDInfoCount;
486 struct rt_bssid_info BSSIDInfo[1];
487};
488
489struct rt_ndis_802_11_authentication_encryption {
490 NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported;
491 NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported;
492};
493
494struct rt_ndis_802_11_capability {
495 unsigned long Length;
496 unsigned long Version;
497 unsigned long NoOfPMKIDs;
498 unsigned long NoOfAuthEncryptPairsSupported;
499 struct rt_ndis_802_11_authentication_encryption
500 AuthenticationEncryptionSupported[1];
501};
502
503#define RT_PRIV_IOCTL (SIOCIWFIRSTPRIV + 0x01) /* Sync. with AP for wsc upnp daemon */
504#define RTPRIV_IOCTL_SET (SIOCIWFIRSTPRIV + 0x02)
505
506#define RTPRIV_IOCTL_STATISTICS (SIOCIWFIRSTPRIV + 0x09)
507#define RTPRIV_IOCTL_ADD_PMKID_CACHE (SIOCIWFIRSTPRIV + 0x0A)
508#define RTPRIV_IOCTL_RADIUS_DATA (SIOCIWFIRSTPRIV + 0x0C)
509#define RTPRIV_IOCTL_GSITESURVEY (SIOCIWFIRSTPRIV + 0x0D)
510#define RT_PRIV_IOCTL_EXT (SIOCIWFIRSTPRIV + 0x0E) /* Sync. with RT61 (for wpa_supplicant) */
511#define RTPRIV_IOCTL_GET_MAC_TABLE (SIOCIWFIRSTPRIV + 0x0F)
512
513#define RTPRIV_IOCTL_SHOW (SIOCIWFIRSTPRIV + 0x11)
514enum {
515 SHOW_CONN_STATUS = 4,
516 SHOW_DRVIER_VERION = 5,
517 SHOW_BA_INFO = 6,
518 SHOW_DESC_INFO = 7,
519#ifdef RTMP_MAC_USB
520 SHOW_RXBULK_INFO = 8,
521 SHOW_TXBULK_INFO = 9,
522#endif /* RTMP_MAC_USB // */
523 RAIO_OFF = 10,
524 RAIO_ON = 11,
525 SHOW_CFG_VALUE = 20,
526 SHOW_ADHOC_ENTRY_INFO = 21,
527};
528
529#define OID_802_11_BUILD_CHANNEL_EX 0x0714
530#define OID_802_11_GET_CH_LIST 0x0715
531#define OID_802_11_GET_COUNTRY_CODE 0x0716
532#define OID_802_11_GET_CHANNEL_GEOGRAPHY 0x0717
533
534#define RT_OID_WSC_SET_PASSPHRASE 0x0740 /* passphrase for wpa(2)-psk */
535#define RT_OID_WSC_DRIVER_AUTO_CONNECT 0x0741
536#define RT_OID_WSC_QUERY_DEFAULT_PROFILE 0x0742
537#define RT_OID_WSC_SET_CONN_BY_PROFILE_INDEX 0x0743
538#define RT_OID_WSC_SET_ACTION 0x0744
539#define RT_OID_WSC_SET_SSID 0x0745
540#define RT_OID_WSC_SET_PIN_CODE 0x0746
541#define RT_OID_WSC_SET_MODE 0x0747 /* PIN or PBC */
542#define RT_OID_WSC_SET_CONF_MODE 0x0748 /* Enrollee or Registrar */
543#define RT_OID_WSC_SET_PROFILE 0x0749
544#define RT_OID_WSC_CONFIG_STATUS 0x074F
545#define RT_OID_802_11_WSC_QUERY_PROFILE 0x0750
546/* for consistency with RT61 */
547#define RT_OID_WSC_QUERY_STATUS 0x0751
548#define RT_OID_WSC_PIN_CODE 0x0752
549#define RT_OID_WSC_UUID 0x0753
550#define RT_OID_WSC_SET_SELECTED_REGISTRAR 0x0754
551#define RT_OID_WSC_EAPMSG 0x0755
552#define RT_OID_WSC_MANUFACTURER 0x0756
553#define RT_OID_WSC_MODEL_NAME 0x0757
554#define RT_OID_WSC_MODEL_NO 0x0758
555#define RT_OID_WSC_SERIAL_NO 0x0759
556#define RT_OID_WSC_MAC_ADDRESS 0x0760
557
558/* New for MeetingHouse Api support */
559#define OID_MH_802_1X_SUPPORTED 0xFFEDC100
560
561/* MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI. Don't change this definition! */
562typedef union _HTTRANSMIT_SETTING {
563 struct {
564 u16 MCS:7; /* MCS */
565 u16 BW:1; /*channel bandwidth 20MHz or 40 MHz */
566 u16 ShortGI:1;
567 u16 STBC:2; /*SPACE */
568/* u16 rsv:3; */
569 u16 rsv:2;
570 u16 TxBF:1;
571 u16 MODE:2; /* Use definition MODE_xxx. */
572 } field;
573 u16 word;
574} HTTRANSMIT_SETTING, *PHTTRANSMIT_SETTING;
575
576typedef enum _RT_802_11_PREAMBLE {
577 Rt802_11PreambleLong,
578 Rt802_11PreambleShort,
579 Rt802_11PreambleAuto
580} RT_802_11_PREAMBLE, *PRT_802_11_PREAMBLE;
581
582typedef enum _RT_802_11_PHY_MODE {
583 PHY_11BG_MIXED = 0,
584 PHY_11B,
585 PHY_11A,
586 PHY_11ABG_MIXED,
587 PHY_11G,
588 PHY_11ABGN_MIXED, /* both band 5 */
589 PHY_11N_2_4G, /* 11n-only with 2.4G band 6 */
590 PHY_11GN_MIXED, /* 2.4G band 7 */
591 PHY_11AN_MIXED, /* 5G band 8 */
592 PHY_11BGN_MIXED, /* if check 802.11b. 9 */
593 PHY_11AGN_MIXED, /* if check 802.11b. 10 */
594 PHY_11N_5G, /* 11n-only with 5G band 11 */
595} RT_802_11_PHY_MODE;
596
597/* put all proprietery for-query objects here to reduce # of Query_OID */
598struct rt_802_11_link_status {
599 unsigned long CurrTxRate; /* in units of 0.5Mbps */
600 unsigned long ChannelQuality; /* 0..100 % */
601 unsigned long TxByteCount; /* both ok and fail */
602 unsigned long RxByteCount; /* both ok and fail */
603 unsigned long CentralChannel; /* 40MHz central channel number */
604};
605
606struct rt_802_11_event_log {
607 LARGE_INTEGER SystemTime; /* timestammp via NdisGetCurrentSystemTime() */
608 u8 Addr[MAC_ADDR_LENGTH];
609 u16 Event; /* EVENT_xxx */
610};
611
612struct rt_802_11_event_table {
613 unsigned long Num;
614 unsigned long Rsv; /* to align Log[] at LARGE_INTEGER boundary */
615 struct rt_802_11_event_log Log[MAX_NUMBER_OF_EVENT];
616};
617
618/* MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI. Don't change this definition! */
619typedef union _MACHTTRANSMIT_SETTING {
620 struct {
621 u16 MCS:7; /* MCS */
622 u16 BW:1; /*channel bandwidth 20MHz or 40 MHz */
623 u16 ShortGI:1;
624 u16 STBC:2; /*SPACE */
625 u16 rsv:3;
626 u16 MODE:2; /* Use definition MODE_xxx. */
627 } field;
628 u16 word;
629} MACHTTRANSMIT_SETTING, *PMACHTTRANSMIT_SETTING;
630
631struct rt_802_11_mac_entry {
632 u8 Addr[MAC_ADDR_LENGTH];
633 u8 Aid;
634 u8 Psm; /* 0:PWR_ACTIVE, 1:PWR_SAVE */
635 u8 MimoPs; /* 0:MMPS_STATIC, 1:MMPS_DYNAMIC, 3:MMPS_Enabled */
636 char AvgRssi0;
637 char AvgRssi1;
638 char AvgRssi2;
639 u32 ConnectedTime;
640 MACHTTRANSMIT_SETTING TxRate;
641};
642
643struct rt_802_11_mac_table {
644 unsigned long Num;
645 struct rt_802_11_mac_entry Entry[MAX_NUMBER_OF_MAC];
646};
647
648/* structure for query/set hardware register - MAC, BBP, RF register */
649struct rt_802_11_hardware_register {
650 unsigned long HardwareType; /* 0:MAC, 1:BBP, 2:RF register, 3:EEPROM */
651 unsigned long Offset; /* Q/S register offset addr */
652 unsigned long Data; /* R/W data buffer */
653};
654
655struct rt_802_11_ap_config {
656 unsigned long EnableTxBurst; /* 0-disable, 1-enable */
657 unsigned long EnableTurboRate; /* 0-disable, 1-enable 72/100mbps turbo rate */
658 unsigned long IsolateInterStaTraffic; /* 0-disable, 1-enable isolation */
659 unsigned long HideSsid; /* 0-disable, 1-enable hiding */
660 unsigned long UseBGProtection; /* 0-AUTO, 1-always ON, 2-always OFF */
661 unsigned long UseShortSlotTime; /* 0-no use, 1-use 9-us short slot time */
662 unsigned long Rsv1; /* must be 0 */
663 unsigned long SystemErrorBitmap; /* ignore upon SET, return system error upon QUERY */
664};
665
666/* structure to query/set STA_CONFIG */
667struct rt_802_11_sta_config {
668 unsigned long EnableTxBurst; /* 0-disable, 1-enable */
669 unsigned long EnableTurboRate; /* 0-disable, 1-enable 72/100mbps turbo rate */
670 unsigned long UseBGProtection; /* 0-AUTO, 1-always ON, 2-always OFF */
671 unsigned long UseShortSlotTime; /* 0-no use, 1-use 9-us short slot time when applicable */
672 unsigned long AdhocMode; /* 0-11b rates only (WIFI spec), 1 - b/g mixed, 2 - g only */
673 unsigned long HwRadioStatus; /* 0-OFF, 1-ON, default is 1, Read-Only */
674 unsigned long Rsv1; /* must be 0 */
675 unsigned long SystemErrorBitmap; /* ignore upon SET, return system error upon QUERY */
676};
677
678/* */
679/* For OID Query or Set about BA structure */
680/* */
681struct rt_oid_bacap {
682 u8 RxBAWinLimit;
683 u8 TxBAWinLimit;
684 u8 Policy; /* 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use. other value invalid */
685 u8 MpduDensity; /* 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use. other value invalid */
686 u8 AmsduEnable; /*Enable AMSDU transmisstion */
687 u8 AmsduSize; /* 0:3839, 1:7935 bytes. u32 MSDUSizeToBytes[] = { 3839, 7935}; */
688 u8 MMPSmode; /* MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable */
689 BOOLEAN AutoBA; /* Auto BA will automatically */
690};
691
692struct rt_802_11_acl_entry {
693 u8 Addr[MAC_ADDR_LENGTH];
694 u16 Rsv;
695};
696
697struct PACKED rt_rt_802_11_acl {
698 unsigned long Policy; /* 0-disable, 1-positive list, 2-negative list */
699 unsigned long Num;
700 struct rt_802_11_acl_entry Entry[MAX_NUMBER_OF_ACL];
701};
702
703struct rt_802_11_wds {
704 unsigned long Num;
705 NDIS_802_11_MAC_ADDRESS Entry[24 /*MAX_NUM_OF_WDS_LINK */];
706 unsigned long KeyLength;
707 u8 KeyMaterial[32];
708};
709
710struct rt_802_11_tx_rates {
711 u8 SupRateLen;
712 u8 SupRate[MAX_LENGTH_OF_SUPPORT_RATES];
713 u8 ExtRateLen;
714 u8 ExtRate[MAX_LENGTH_OF_SUPPORT_RATES];
715};
716
717/* Definition of extra information code */
718#define GENERAL_LINK_UP 0x0 /* Link is Up */
719#define GENERAL_LINK_DOWN 0x1 /* Link is Down */
720#define HW_RADIO_OFF 0x2 /* Hardware radio off */
721#define SW_RADIO_OFF 0x3 /* Software radio off */
722#define AUTH_FAIL 0x4 /* Open authentication fail */
723#define AUTH_FAIL_KEYS 0x5 /* Shared authentication fail */
724#define ASSOC_FAIL 0x6 /* Association failed */
725#define EAP_MIC_FAILURE 0x7 /* Deauthentication because MIC failure */
726#define EAP_4WAY_TIMEOUT 0x8 /* Deauthentication on 4-way handshake timeout */
727#define EAP_GROUP_KEY_TIMEOUT 0x9 /* Deauthentication on group key handshake timeout */
728#define EAP_SUCCESS 0xa /* EAP succeed */
729#define DETECT_RADAR_SIGNAL 0xb /* Radar signal occur in current channel */
730#define EXTRA_INFO_MAX 0xb /* Indicate Last OID */
731
732#define EXTRA_INFO_CLEAR 0xffffffff
733
734/* This is OID setting structure. So only GF or MM as Mode. This is valid when our wirelss mode has 802.11n in use. */
735struct rt_oid_set_ht_phymode {
736 RT_802_11_PHY_MODE PhyMode; /* */
737 u8 TransmitNo;
738 u8 HtMode; /*HTMODE_GF or HTMODE_MM */
739 u8 ExtOffset; /*extension channel above or below */
740 u8 MCS;
741 u8 BW;
742 u8 STBC;
743 u8 SHORTGI;
744 u8 rsv;
745};
746
747#define MAX_CUSTOM_LEN 128
748
749typedef enum _RT_802_11_D_CLIENT_MODE {
750 Rt802_11_D_None,
751 Rt802_11_D_Flexible,
752 Rt802_11_D_Strict,
753} RT_802_11_D_CLIENT_MODE, *PRT_802_11_D_CLIENT_MODE;
754
755struct rt_channel_list_info {
756 u8 ChannelList[MAX_NUM_OF_CHS]; /* list all supported channels for site survey */
757 u8 ChannelListNum; /* number of channel in ChannelList[] */
758};
759
760/* WSC configured credential */
761struct rt_wsc_credential {
762 struct rt_ndis_802_11_ssid SSID; /* mandatory */
763 u16 AuthType; /* mandatory, 1: open, 2: wpa-psk, 4: shared, 8:wpa, 0x10: wpa2, 0x20: wpa2-psk */
764 u16 EncrType; /* mandatory, 1: none, 2: wep, 4: tkip, 8: aes */
765 u8 Key[64]; /* mandatory, Maximum 64 byte */
766 u16 KeyLength;
767 u8 MacAddr[6]; /* mandatory, AP MAC address */
768 u8 KeyIndex; /* optional, default is 1 */
769 u8 Rsvd[3]; /* Make alignment */
770};
771
772/* WSC configured profiles */
773struct rt_wsc_profile {
774 u32 ProfileCnt;
775 u32 ApplyProfileIdx; /* add by johnli, fix WPS test plan 5.1.1 */
776 struct rt_wsc_credential Profile[8]; /* Support up to 8 profiles */
777};
778
779#endif /* _OID_H_ */
diff --git a/drivers/staging/rt2860/pci_main_dev.c b/drivers/staging/rt2860/pci_main_dev.c
deleted file mode 100644
index 25fbb1880ff..00000000000
--- a/drivers/staging/rt2860/pci_main_dev.c
+++ /dev/null
@@ -1,1192 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 pci_main_dev.c
29
30 Abstract:
31 Create and register network interface for PCI based chipsets in Linux platform.
32
33 Revision History:
34 Who When What
35 Justin P. Mattock 11/07/2010 Fix typos in some comments
36 -------- ---------- ----------------------------------------------
37*/
38
39#include "rt_config.h"
40#include <linux/pci.h>
41#include <linux/slab.h>
42
43/* Following information will be show when you run 'modinfo' */
44/* If you have a solution for a bug in current version of driver, please e-mail me. */
45/* Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. */
46MODULE_AUTHOR("Jett Chen <jett_chen@ralinktech.com>");
47MODULE_DESCRIPTION("RT2860/RT3090 Wireless Lan Linux Driver");
48MODULE_LICENSE("GPL");
49MODULE_ALIAS("rt3090sta");
50
51/* */
52/* Function declarations */
53/* */
54static void __devexit rt2860_remove_one(struct pci_dev *pci_dev);
55static int __devinit rt2860_probe(struct pci_dev *pci_dev,
56 const struct pci_device_id *ent);
57static void __exit rt2860_cleanup_module(void);
58static int __init rt2860_init_module(void);
59
60static void RTMPInitPCIeDevice(IN struct pci_dev *pci_dev,
61 struct rt_rtmp_adapter *pAd);
62
63#ifdef CONFIG_PM
64static int rt2860_suspend(struct pci_dev *pci_dev, pm_message_t state);
65static int rt2860_resume(struct pci_dev *pci_dev);
66#endif /* CONFIG_PM // */
67
68/* */
69/* Ralink PCI device table, include all supported chipsets */
70/* */
71static struct pci_device_id rt2860_pci_tbl[] __devinitdata = {
72#ifdef RT2860
73 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2860_PCI_DEVICE_ID)}, /*RT28602.4G */
74 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2860_PCIe_DEVICE_ID)},
75 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2760_PCI_DEVICE_ID)},
76 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2790_PCIe_DEVICE_ID)},
77 {PCI_DEVICE(VEN_AWT_PCI_VENDOR_ID, VEN_AWT_PCIe_DEVICE_ID)},
78 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7708)},
79 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7728)},
80 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7758)},
81 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7727)},
82 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7738)},
83 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7748)},
84 {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7768)},
85#endif
86#ifdef RT3090
87 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3090_PCIe_DEVICE_ID)},
88 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3091_PCIe_DEVICE_ID)},
89 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3092_PCIe_DEVICE_ID)},
90#endif /* RT3090 // */
91#ifdef RT3390
92 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3390_PCIe_DEVICE_ID)},
93 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3391_PCIe_DEVICE_ID)},
94 {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3392_PCIe_DEVICE_ID)},
95#endif /* RT3390 // */
96 {0,} /* terminate list */
97};
98
99MODULE_DEVICE_TABLE(pci, rt2860_pci_tbl);
100#ifdef MODULE_VERSION
101MODULE_VERSION(STA_DRIVER_VERSION);
102#endif
103
104/* */
105/* Our PCI driver structure */
106/* */
107static struct pci_driver rt2860_driver = {
108name: "rt2860",
109id_table : rt2860_pci_tbl,
110probe : rt2860_probe,
111remove : __devexit_p(rt2860_remove_one),
112#ifdef CONFIG_PM
113suspend : rt2860_suspend,
114resume : rt2860_resume,
115#endif
116};
117
118/***************************************************************************
119 *
120 * PCI device initialization related procedures.
121 *
122 ***************************************************************************/
123#ifdef CONFIG_PM
124
125void RT2860RejectPendingPackets(struct rt_rtmp_adapter *pAd)
126{
127 /* clear PS packets */
128 /* clear TxSw packets */
129}
130
131static int rt2860_suspend(struct pci_dev *pci_dev, pm_message_t state)
132{
133 struct net_device *net_dev = pci_get_drvdata(pci_dev);
134 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL;
135 int retval = 0;
136
137 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_suspend()\n"));
138
139 if (net_dev == NULL) {
140 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
141 } else {
142 GET_PAD_FROM_NET_DEV(pAd, net_dev);
143
144 /* we can not use IFF_UP because ra0 down but ra1 up */
145 /* and 1 suspend/resume function for 1 module, not for each interface */
146 /* so Linux will call suspend/resume function once */
147 if (VIRTUAL_IF_NUM(pAd) > 0) {
148 /* avoid users do suspend after interface is down */
149
150 /* stop interface */
151 netif_carrier_off(net_dev);
152 netif_stop_queue(net_dev);
153
154 /* mark device as removed from system and therefore no longer available */
155 netif_device_detach(net_dev);
156
157 /* mark halt flag */
158 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
159 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
160
161 /* take down the device */
162 rt28xx_close((struct net_device *)net_dev);
163
164 RT_MOD_DEC_USE_COUNT();
165 }
166 }
167
168 /* reference to http://vovo2000.com/type-lab/linux/kernel-api/linux-kernel-api.html */
169 /* enable device to generate PME# when suspended */
170 /* pci_choose_state(): Choose the power state of a PCI device to be suspended */
171 retval = pci_enable_wake(pci_dev, pci_choose_state(pci_dev, state), 1);
172 /* save the PCI configuration space of a device before suspending */
173 pci_save_state(pci_dev);
174 /* disable PCI device after use */
175 pci_disable_device(pci_dev);
176
177 retval = pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
178
179 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_suspend()\n"));
180 return retval;
181}
182
183static int rt2860_resume(struct pci_dev *pci_dev)
184{
185 struct net_device *net_dev = pci_get_drvdata(pci_dev);
186 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL;
187 int retval;
188
189 /* set the power state of a PCI device */
190 /* PCI has 4 power states, DO (normal) ~ D3(less power) */
191 /* in include/linux/pci.h, you can find that */
192 /* #define PCI_D0 ((pci_power_t __force) 0) */
193 /* #define PCI_D1 ((pci_power_t __force) 1) */
194 /* #define PCI_D2 ((pci_power_t __force) 2) */
195 /* #define PCI_D3hot ((pci_power_t __force) 3) */
196 /* #define PCI_D3cold ((pci_power_t __force) 4) */
197 /* #define PCI_UNKNOWN ((pci_power_t __force) 5) */
198 /* #define PCI_POWER_ERROR ((pci_power_t __force) -1) */
199 retval = pci_set_power_state(pci_dev, PCI_D0);
200
201 /* restore the saved state of a PCI device */
202 pci_restore_state(pci_dev);
203
204 /* initialize device before it's used by a driver */
205 if (pci_enable_device(pci_dev)) {
206 printk(KERN_ERR "rt2860: pci enable fail!\n");
207 return 0;
208 }
209
210 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_resume()\n"));
211
212 if (net_dev == NULL)
213 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
214 else
215 GET_PAD_FROM_NET_DEV(pAd, net_dev);
216
217 if (pAd != NULL) {
218 /* we can not use IFF_UP because ra0 down but ra1 up */
219 /* and 1 suspend/resume function for 1 module, not for each interface */
220 /* so Linux will call suspend/resume function once */
221 if (VIRTUAL_IF_NUM(pAd) > 0) {
222 /* mark device as attached from system and restart if needed */
223 netif_device_attach(net_dev);
224
225 if (rt28xx_open((struct net_device *)net_dev) != 0) {
226 /* open fail */
227 DBGPRINT(RT_DEBUG_TRACE,
228 ("<=== rt2860_resume()\n"));
229 return 0;
230 }
231 /* increase MODULE use count */
232 RT_MOD_INC_USE_COUNT();
233
234 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
235 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
236
237 netif_start_queue(net_dev);
238 netif_carrier_on(net_dev);
239 netif_wake_queue(net_dev);
240 }
241 }
242
243 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_resume()\n"));
244 return 0;
245}
246#endif /* CONFIG_PM // */
247
248static int __init rt2860_init_module(void)
249{
250 return pci_register_driver(&rt2860_driver);
251}
252
253/* */
254/* Driver module unload function */
255/* */
256static void __exit rt2860_cleanup_module(void)
257{
258 pci_unregister_driver(&rt2860_driver);
259}
260
261module_init(rt2860_init_module);
262module_exit(rt2860_cleanup_module);
263
264/* */
265/* PCI device probe & initialization function */
266/* */
267static int __devinit rt2860_probe(IN struct pci_dev *pci_dev,
268 IN const struct pci_device_id *pci_id)
269{
270 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL;
271 struct net_device *net_dev;
272 void *handle;
273 char *print_name;
274 unsigned long csr_addr;
275 int rv = 0;
276 struct rt_rtmp_os_netdev_op_hook netDevHook;
277
278 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n"));
279
280/*PCIDevInit============================================== */
281 /* wake up and enable device */
282 rv = pci_enable_device(pci_dev);
283
284 if (rv != 0) {
285 DBGPRINT(RT_DEBUG_ERROR,
286 ("Enable PCI device failed, errno=%d!\n", rv));
287 return rv;
288 }
289
290 print_name = (char *)pci_name(pci_dev);
291
292 rv = pci_request_regions(pci_dev, print_name);
293
294 if (rv != 0) {
295 DBGPRINT(RT_DEBUG_ERROR,
296 ("Request PCI resource failed, errno=%d!\n", rv));
297 goto err_out;
298 }
299 /* map physical address to virtual address for accessing register */
300 csr_addr =
301 (unsigned long)ioremap(pci_resource_start(pci_dev, 0),
302 pci_resource_len(pci_dev, 0));
303 if (!csr_addr) {
304 DBGPRINT(RT_DEBUG_ERROR,
305 ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n",
306 print_name, (unsigned long)pci_resource_len(pci_dev, 0),
307 (unsigned long)pci_resource_start(pci_dev, 0)));
308 goto err_out_free_res;
309 } else {
310 DBGPRINT(RT_DEBUG_TRACE,
311 ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name,
312 (unsigned long)pci_resource_start(pci_dev, 0),
313 (unsigned long)csr_addr, pci_dev->irq));
314 }
315
316 /* Set DMA master */
317 pci_set_master(pci_dev);
318
319/*RtmpDevInit============================================== */
320 /* Allocate struct rt_rtmp_adapter adapter structure */
321 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
322 if (handle == NULL) {
323 DBGPRINT(RT_DEBUG_ERROR,
324 ("%s(): Allocate memory for os handle failed!\n",
325 __func__));
326 goto err_out_iounmap;
327 }
328
329 ((struct os_cookie *)handle)->pci_dev = pci_dev;
330
331 rv = RTMPAllocAdapterBlock(handle, &pAd); /*shiang: we may need the pci_dev for allocate structure of "struct rt_rtmp_adapter" */
332 if (rv != NDIS_STATUS_SUCCESS)
333 goto err_out_iounmap;
334 /* Here are the struct rt_rtmp_adapter structure with pci-bus specific parameters. */
335 pAd->CSRBaseAddress = (u8 *)csr_addr;
336 DBGPRINT(RT_DEBUG_ERROR,
337 ("pAd->CSRBaseAddress =0x%lx, csr_addr=0x%lx!\n",
338 (unsigned long)pAd->CSRBaseAddress, csr_addr));
339 RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCI);
340
341/*NetDevInit============================================== */
342 net_dev = RtmpPhyNetDevInit(pAd, &netDevHook);
343 if (net_dev == NULL)
344 goto err_out_free_radev;
345
346 /* Here are the net_device structure with pci-bus specific parameters. */
347 net_dev->irq = pci_dev->irq; /* Interrupt IRQ number */
348 net_dev->base_addr = csr_addr; /* Save CSR virtual address and irq to device structure */
349 pci_set_drvdata(pci_dev, net_dev); /* Set driver data */
350
351/* for supporting Network Manager */
352 /* Set the sysfs physical device reference for the network logical device
353 * if set prior to registration will cause a symlink during initialization.
354 */
355 SET_NETDEV_DEV(net_dev, &(pci_dev->dev));
356
357/*All done, it's time to register the net device to linux kernel. */
358 /* Register this device */
359 rv = RtmpOSNetDevAttach(net_dev, &netDevHook);
360 if (rv)
361 goto err_out_free_netdev;
362
363 pAd->StaCfg.OriDevType = net_dev->type;
364 RTMPInitPCIeDevice(pci_dev, pAd);
365
366 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n"));
367
368 return 0; /* probe ok */
369
370 /* --------------------------- ERROR HANDLE --------------------------- */
371err_out_free_netdev:
372 RtmpOSNetDevFree(net_dev);
373
374err_out_free_radev:
375 /* free struct rt_rtmp_adapter strcuture and os_cookie */
376 RTMPFreeAdapter(pAd);
377
378err_out_iounmap:
379 iounmap((void *)(csr_addr));
380 release_mem_region(pci_resource_start(pci_dev, 0),
381 pci_resource_len(pci_dev, 0));
382
383err_out_free_res:
384 pci_release_regions(pci_dev);
385
386err_out:
387 pci_disable_device(pci_dev);
388
389 DBGPRINT(RT_DEBUG_ERROR,
390 ("<=== rt2860_probe failed with rv = %d!\n", rv));
391
392 return -ENODEV; /* probe fail */
393}
394
395static void __devexit rt2860_remove_one(IN struct pci_dev *pci_dev)
396{
397 struct net_device *net_dev = pci_get_drvdata(pci_dev);
398 struct rt_rtmp_adapter *pAd = NULL;
399 unsigned long csr_addr = net_dev->base_addr; /* pAd->CSRBaseAddress; */
400
401 GET_PAD_FROM_NET_DEV(pAd, net_dev);
402
403 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_remove_one\n"));
404
405 if (pAd != NULL) {
406 /* Unregister/Free all allocated net_device. */
407 RtmpPhyNetDevExit(pAd, net_dev);
408
409 /* Unmap CSR base address */
410 iounmap((char *)(csr_addr));
411
412 /* release memory region */
413 release_mem_region(pci_resource_start(pci_dev, 0),
414 pci_resource_len(pci_dev, 0));
415
416 /* Free struct rt_rtmp_adapter related structures. */
417 RtmpRaDevCtrlExit(pAd);
418
419 } else {
420 /* Unregister network device */
421 RtmpOSNetDevDetach(net_dev);
422
423 /* Unmap CSR base address */
424 iounmap((char *)(net_dev->base_addr));
425
426 /* release memory region */
427 release_mem_region(pci_resource_start(pci_dev, 0),
428 pci_resource_len(pci_dev, 0));
429 }
430
431 /* Free the root net_device */
432 RtmpOSNetDevFree(net_dev);
433
434}
435
436/*
437========================================================================
438Routine Description:
439 Check the chipset vendor/product ID.
440
441Arguments:
442 _dev_p Point to the PCI or USB device
443
444Return Value:
445 TRUE Check ok
446 FALSE Check fail
447
448Note:
449========================================================================
450*/
451BOOLEAN RT28XXChipsetCheck(IN void *_dev_p)
452{
453 /* always TRUE */
454 return TRUE;
455}
456
457/***************************************************************************
458 *
459 * PCIe device initialization related procedures.
460 *
461 ***************************************************************************/
462static void RTMPInitPCIeDevice(struct pci_dev *pci_dev, struct rt_rtmp_adapter *pAd)
463{
464 u16 device_id;
465 struct os_cookie *pObj;
466
467 pObj = (struct os_cookie *)pAd->OS_Cookie;
468 pci_read_config_word(pci_dev, PCI_DEVICE_ID, &device_id);
469 device_id = le2cpu16(device_id);
470 pObj->DeviceID = device_id;
471 if (
472#ifdef RT2860
473 (device_id == NIC2860_PCIe_DEVICE_ID) ||
474 (device_id == NIC2790_PCIe_DEVICE_ID) ||
475 (device_id == VEN_AWT_PCIe_DEVICE_ID) ||
476#endif
477#ifdef RT3090
478 (device_id == NIC3090_PCIe_DEVICE_ID) ||
479 (device_id == NIC3091_PCIe_DEVICE_ID) ||
480 (device_id == NIC3092_PCIe_DEVICE_ID) ||
481#endif /* RT3090 // */
482 0) {
483 u32 MacCsr0 = 0, Index = 0;
484 do {
485 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
486
487 if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF))
488 break;
489
490 RTMPusecDelay(10);
491 } while (Index++ < 100);
492
493 /* Support advanced power save after 2892/2790. */
494 /* MAC version at offset 0x1000 is 0x2872XXXX/0x2870XXXX(PCIe, USB, SDIO). */
495 if ((MacCsr0 & 0xffff0000) != 0x28600000)
496 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_PCIE_DEVICE);
497 }
498}
499
500void RTMPInitPCIeLinkCtrlValue(struct rt_rtmp_adapter *pAd)
501{
502 int pos;
503 u16 reg16, data2, PCIePowerSaveLevel, Configuration;
504 u32 MacValue;
505 BOOLEAN bFindIntel = FALSE;
506 struct os_cookie *pObj;
507
508 pObj = (struct os_cookie *)pAd->OS_Cookie;
509
510 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE))
511 return;
512
513 DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__));
514 /* Init EEPROM, and save settings */
515 if (!(IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) {
516 RT28xx_EEPROM_READ16(pAd, 0x22, PCIePowerSaveLevel);
517 pAd->PCIePowerSaveLevel = PCIePowerSaveLevel & 0xff;
518
519 pAd->LnkCtrlBitMask = 0;
520 if ((PCIePowerSaveLevel & 0xff) == 0xff) {
521 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PCIE_DEVICE);
522 DBGPRINT(RT_DEBUG_TRACE,
523 ("====> PCIePowerSaveLevel = 0x%x.\n",
524 PCIePowerSaveLevel));
525 return;
526 } else {
527 PCIePowerSaveLevel &= 0x3;
528 RT28xx_EEPROM_READ16(pAd, 0x24, data2);
529
530 if (!
531 (((data2 & 0xff00) == 0x9200)
532 && ((data2 & 0x80) != 0))) {
533 if (PCIePowerSaveLevel > 1)
534 PCIePowerSaveLevel = 1;
535 }
536
537 DBGPRINT(RT_DEBUG_TRACE,
538 ("====> Write 0x83 = 0x%x.\n",
539 PCIePowerSaveLevel));
540 AsicSendCommandToMcu(pAd, 0x83, 0xff,
541 (u8)PCIePowerSaveLevel, 0x00);
542 RT28xx_EEPROM_READ16(pAd, 0x22, PCIePowerSaveLevel);
543 PCIePowerSaveLevel &= 0xff;
544 PCIePowerSaveLevel = PCIePowerSaveLevel >> 6;
545 switch (PCIePowerSaveLevel) {
546 case 0: /* Only support L0 */
547 pAd->LnkCtrlBitMask = 0;
548 break;
549 case 1: /* Only enable L0s */
550 pAd->LnkCtrlBitMask = 1;
551 break;
552 case 2: /* enable L1, L0s */
553 pAd->LnkCtrlBitMask = 3;
554 break;
555 case 3: /* sync with host clk and enable L1, L0s */
556 pAd->LnkCtrlBitMask = 0x103;
557 break;
558 }
559 RT28xx_EEPROM_READ16(pAd, 0x24, data2);
560 if ((PCIePowerSaveLevel & 0xff) != 0xff) {
561 PCIePowerSaveLevel &= 0x3;
562
563 if (!
564 (((data2 & 0xff00) == 0x9200)
565 && ((data2 & 0x80) != 0))) {
566 if (PCIePowerSaveLevel > 1)
567 PCIePowerSaveLevel = 1;
568 }
569
570 DBGPRINT(RT_DEBUG_TRACE,
571 ("====> rt28xx Write 0x83 Command = 0x%x.\n",
572 PCIePowerSaveLevel));
573
574 AsicSendCommandToMcu(pAd, 0x83, 0xff,
575 (u8)PCIePowerSaveLevel,
576 0x00);
577 }
578 DBGPRINT(RT_DEBUG_TRACE,
579 ("====> LnkCtrlBitMask = 0x%x.\n",
580 pAd->LnkCtrlBitMask));
581 }
582 } else if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) {
583 u8 LinkCtrlSetting = 0;
584
585 /* Check 3090E special setting chip. */
586 RT28xx_EEPROM_READ16(pAd, 0x24, data2);
587 if ((data2 == 0x9280) && ((pAd->MACVersion & 0xffff) == 0x0211)) {
588 pAd->b3090ESpecialChip = TRUE;
589 DBGPRINT_RAW(RT_DEBUG_ERROR, ("Special 3090E chip \n"));
590 }
591
592 RTMP_IO_READ32(pAd, AUX_CTRL, &MacValue);
593 /*enable WAKE_PCIE function, which forces to enable PCIE clock when mpu interrupt asserting. */
594 /*Force PCIE 125MHz CLK to toggle */
595 MacValue |= 0x402;
596 RTMP_IO_WRITE32(pAd, AUX_CTRL, MacValue);
597 DBGPRINT_RAW(RT_DEBUG_ERROR,
598 (" AUX_CTRL = 0x%32x\n", MacValue));
599
600 /* for RT30xx F and after, PCIe interface, and for power solution 3 */
601 if ((IS_VERSION_AFTER_F(pAd))
602 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode >= 2)
603 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode <= 3)) {
604 RTMP_IO_READ32(pAd, AUX_CTRL, &MacValue);
605 DBGPRINT_RAW(RT_DEBUG_ERROR,
606 (" Read AUX_CTRL = 0x%x\n", MacValue));
607 /* turn on bit 12. */
608 /*enable 32KHz clock mode for power saving */
609 MacValue |= 0x1000;
610 if (MacValue != 0xffffffff) {
611 RTMP_IO_WRITE32(pAd, AUX_CTRL, MacValue);
612 DBGPRINT_RAW(RT_DEBUG_ERROR,
613 (" Write AUX_CTRL = 0x%x\n",
614 MacValue));
615 /* 1. if use PCIePowerSetting is 2 or 3, need to program OSC_CTRL to 0x3ff11. */
616 MacValue = 0x3ff11;
617 RTMP_IO_WRITE32(pAd, OSC_CTRL, MacValue);
618 DBGPRINT_RAW(RT_DEBUG_ERROR,
619 (" OSC_CTRL = 0x%x\n", MacValue));
620 /* 2. Write PCI register Clk ref bit */
621 RTMPrt3xSetPCIePowerLinkCtrl(pAd);
622 } else {
623 /* Error read Aux_Ctrl value. Force to use solution 1 */
624 DBGPRINT(RT_DEBUG_ERROR,
625 (" Error Value in AUX_CTRL = 0x%x\n",
626 MacValue));
627 pAd->StaCfg.PSControl.field.rt30xxPowerMode = 1;
628 DBGPRINT(RT_DEBUG_ERROR,
629 (" Force to use power solution1 \n"));
630 }
631 }
632 /* 1. read setting from inf file. */
633
634 PCIePowerSaveLevel =
635 (u16)pAd->StaCfg.PSControl.field.rt30xxPowerMode;
636 DBGPRINT(RT_DEBUG_ERROR,
637 ("====> rt30xx Read PowerLevelMode = 0x%x.\n",
638 PCIePowerSaveLevel));
639 /* 2. Check EnableNewPS. */
640 if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE)
641 PCIePowerSaveLevel = 1;
642
643 if (IS_VERSION_BEFORE_F(pAd)
644 && (pAd->b3090ESpecialChip == FALSE)) {
645 /* Chip Version E only allow 1, So force set 1. */
646 PCIePowerSaveLevel &= 0x1;
647 pAd->PCIePowerSaveLevel = (u16)PCIePowerSaveLevel;
648 DBGPRINT(RT_DEBUG_TRACE,
649 ("====> rt30xx E Write 0x83 Command = 0x%x.\n",
650 PCIePowerSaveLevel));
651
652 AsicSendCommandToMcu(pAd, 0x83, 0xff,
653 (u8)PCIePowerSaveLevel, 0x00);
654 } else {
655 /* Chip Version F and after only allow 1 or 2 or 3. This might be modified after new chip version come out. */
656 if (!
657 ((PCIePowerSaveLevel == 1)
658 || (PCIePowerSaveLevel == 3)))
659 PCIePowerSaveLevel = 1;
660 DBGPRINT(RT_DEBUG_ERROR,
661 ("====> rt30xx F Write 0x83 Command = 0x%x.\n",
662 PCIePowerSaveLevel));
663 pAd->PCIePowerSaveLevel = (u16)PCIePowerSaveLevel;
664 /* for 3090F , we need to add high-byte arg for 0x83 command to indicate the link control setting in */
665 /* PCI Configuration Space. Because firmware can't read PCI Configuration Space */
666 if ((pAd->Rt3xxRalinkLinkCtrl & 0x2)
667 && (pAd->Rt3xxHostLinkCtrl & 0x2)) {
668 LinkCtrlSetting = 1;
669 }
670 DBGPRINT(RT_DEBUG_TRACE,
671 ("====> rt30xxF LinkCtrlSetting = 0x%x.\n",
672 LinkCtrlSetting));
673 AsicSendCommandToMcu(pAd, 0x83, 0xff,
674 (u8)PCIePowerSaveLevel,
675 LinkCtrlSetting);
676 }
677 }
678 /* Find Ralink PCIe Device's Express Capability Offset */
679 pos = pci_find_capability(pObj->pci_dev, PCI_CAP_ID_EXP);
680
681 if (pos != 0) {
682 /* Ralink PCIe Device's Link Control Register Offset */
683 pAd->RLnkCtrlOffset = pos + PCI_EXP_LNKCTL;
684 pci_read_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset,
685 &reg16);
686 Configuration = le2cpu16(reg16);
687 DBGPRINT(RT_DEBUG_TRACE,
688 ("Read (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n",
689 pAd->RLnkCtrlOffset, Configuration));
690 pAd->RLnkCtrlConfiguration = (Configuration & 0x103);
691 Configuration &= 0xfefc;
692 Configuration |= (0x0);
693#ifdef RT2860
694 if ((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID)
695 || (pObj->DeviceID == NIC2790_PCIe_DEVICE_ID)) {
696 reg16 = cpu2le16(Configuration);
697 pci_write_config_word(pObj->pci_dev,
698 pAd->RLnkCtrlOffset, reg16);
699 DBGPRINT(RT_DEBUG_TRACE,
700 ("Write (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n",
701 pos + PCI_EXP_LNKCTL, Configuration));
702 }
703#endif /* RT2860 // */
704
705 RTMPFindHostPCIDev(pAd);
706 if (pObj->parent_pci_dev) {
707 u16 vendor_id;
708
709 pci_read_config_word(pObj->parent_pci_dev,
710 PCI_VENDOR_ID, &vendor_id);
711 vendor_id = le2cpu16(vendor_id);
712 if (vendor_id == PCIBUS_INTEL_VENDOR) {
713 bFindIntel = TRUE;
714 RTMP_SET_PSFLAG(pAd, fRTMP_PS_TOGGLE_L1);
715 }
716 /* Find PCI-to-PCI Bridge Express Capability Offset */
717 pos =
718 pci_find_capability(pObj->parent_pci_dev,
719 PCI_CAP_ID_EXP);
720
721 if (pos != 0) {
722 BOOLEAN bChange = FALSE;
723 /* PCI-to-PCI Bridge Link Control Register Offset */
724 pAd->HostLnkCtrlOffset = pos + PCI_EXP_LNKCTL;
725 pci_read_config_word(pObj->parent_pci_dev,
726 pAd->HostLnkCtrlOffset,
727 &reg16);
728 Configuration = le2cpu16(reg16);
729 DBGPRINT(RT_DEBUG_TRACE,
730 ("Read (Host PCI-to-PCI Bridge Link Control Register) offset 0x%x = 0x%x\n",
731 pAd->HostLnkCtrlOffset,
732 Configuration));
733 pAd->HostLnkCtrlConfiguration =
734 (Configuration & 0x103);
735 Configuration &= 0xfefc;
736 Configuration |= (0x0);
737
738 switch (pObj->DeviceID) {
739#ifdef RT2860
740 case NIC2860_PCIe_DEVICE_ID:
741 case NIC2790_PCIe_DEVICE_ID:
742 bChange = TRUE;
743 break;
744#endif /* RT2860 // */
745#ifdef RT3090
746 case NIC3090_PCIe_DEVICE_ID:
747 case NIC3091_PCIe_DEVICE_ID:
748 case NIC3092_PCIe_DEVICE_ID:
749 if (bFindIntel == FALSE)
750 bChange = TRUE;
751 break;
752#endif /* RT3090 // */
753 default:
754 break;
755 }
756
757 if (bChange) {
758 reg16 = cpu2le16(Configuration);
759 pci_write_config_word(pObj->
760 parent_pci_dev,
761 pAd->
762 HostLnkCtrlOffset,
763 reg16);
764 DBGPRINT(RT_DEBUG_TRACE,
765 ("Write (Host PCI-to-PCI Bridge Link Control Register) offset 0x%x = 0x%x\n",
766 pAd->HostLnkCtrlOffset,
767 Configuration));
768 }
769 } else {
770 pAd->HostLnkCtrlOffset = 0;
771 DBGPRINT(RT_DEBUG_ERROR,
772 ("%s: cannot find PCI-to-PCI Bridge PCI Express Capability!\n",
773 __func__));
774 }
775 }
776 } else {
777 pAd->RLnkCtrlOffset = 0;
778 pAd->HostLnkCtrlOffset = 0;
779 DBGPRINT(RT_DEBUG_ERROR,
780 ("%s: cannot find Ralink PCIe Device's PCI Express Capability!\n",
781 __func__));
782 }
783
784 if (bFindIntel == FALSE) {
785 DBGPRINT(RT_DEBUG_TRACE,
786 ("Doesn't find Intel PCI host controller. \n"));
787 /* Doesn't switch L0, L1, So set PCIePowerSaveLevel to 0xff */
788 pAd->PCIePowerSaveLevel = 0xff;
789 if ((pAd->RLnkCtrlOffset != 0)
790#ifdef RT3090
791 && ((pObj->DeviceID == NIC3090_PCIe_DEVICE_ID)
792 || (pObj->DeviceID == NIC3091_PCIe_DEVICE_ID)
793 || (pObj->DeviceID == NIC3092_PCIe_DEVICE_ID))
794#endif /* RT3090 // */
795 ) {
796 pci_read_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset,
797 &reg16);
798 Configuration = le2cpu16(reg16);
799 DBGPRINT(RT_DEBUG_TRACE,
800 ("Read (Ralink 30xx PCIe Link Control Register) offset 0x%x = 0x%x\n",
801 pAd->RLnkCtrlOffset, Configuration));
802 pAd->RLnkCtrlConfiguration = (Configuration & 0x103);
803 Configuration &= 0xfefc;
804 Configuration |= (0x0);
805 reg16 = cpu2le16(Configuration);
806 pci_write_config_word(pObj->pci_dev,
807 pAd->RLnkCtrlOffset, reg16);
808 DBGPRINT(RT_DEBUG_TRACE,
809 ("Write (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n",
810 pos + PCI_EXP_LNKCTL, Configuration));
811 }
812 }
813}
814
815void RTMPFindHostPCIDev(struct rt_rtmp_adapter *pAd)
816{
817 u16 reg16;
818 u8 reg8;
819 u32 DevFn;
820 struct pci_dev *pPci_dev;
821 struct os_cookie *pObj;
822
823 pObj = (struct os_cookie *)pAd->OS_Cookie;
824
825 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE))
826 return;
827
828 DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__));
829
830 pObj->parent_pci_dev = NULL;
831 if (pObj->pci_dev->bus->parent) {
832 for (DevFn = 0; DevFn < 255; DevFn++) {
833 pPci_dev =
834 pci_get_slot(pObj->pci_dev->bus->parent, DevFn);
835 if (pPci_dev) {
836 pci_read_config_word(pPci_dev, PCI_CLASS_DEVICE,
837 &reg16);
838 reg16 = le2cpu16(reg16);
839 pci_read_config_byte(pPci_dev, PCI_CB_CARD_BUS,
840 &reg8);
841 if ((reg16 == PCI_CLASS_BRIDGE_PCI)
842 && (reg8 == pObj->pci_dev->bus->number)) {
843 pObj->parent_pci_dev = pPci_dev;
844 }
845 }
846 }
847 }
848}
849
850/*
851 ========================================================================
852
853 Routine Description:
854
855 Arguments:
856 Level = RESTORE_HALT : Restore PCI host and Ralink PCIe Link Control field to its default value.
857 Level = Other Value : Restore from dot11 power save or radio off status. And force PCI host Link Control fields to 0x1
858
859 ========================================================================
860*/
861void RTMPPCIeLinkCtrlValueRestore(struct rt_rtmp_adapter *pAd, u8 Level)
862{
863 u16 PCIePowerSaveLevel, reg16;
864 u16 Configuration;
865 struct os_cookie *pObj;
866
867 pObj = (struct os_cookie *)pAd->OS_Cookie;
868
869 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE))
870 return;
871
872#ifdef RT2860
873 if (!((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID)
874 || (pObj->DeviceID == NIC2790_PCIe_DEVICE_ID)))
875 return;
876#endif /* RT2860 // */
877 /* Check PSControl Configuration */
878 if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE)
879 return;
880
881 /*3090 will not execute the following codes. */
882 /* Check interface : If not PCIe interface, return. */
883
884#ifdef RT3090
885 if ((pObj->DeviceID == NIC3090_PCIe_DEVICE_ID)
886 || (pObj->DeviceID == NIC3091_PCIe_DEVICE_ID)
887 || (pObj->DeviceID == NIC3092_PCIe_DEVICE_ID))
888 return;
889#endif /* RT3090 // */
890
891 DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__));
892 PCIePowerSaveLevel = pAd->PCIePowerSaveLevel;
893 if ((PCIePowerSaveLevel & 0xff) == 0xff) {
894 DBGPRINT(RT_DEBUG_TRACE, ("return \n"));
895 return;
896 }
897
898 if (pObj->parent_pci_dev && (pAd->HostLnkCtrlOffset != 0)) {
899 PCI_REG_READ_WORD(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset,
900 Configuration);
901 if ((Configuration != 0) && (Configuration != 0xFFFF)) {
902 Configuration &= 0xfefc;
903 /* If call from interface down, restore to original setting. */
904 if (Level == RESTORE_CLOSE)
905 Configuration |= pAd->HostLnkCtrlConfiguration;
906 else
907 Configuration |= 0x0;
908 PCI_REG_WIRTE_WORD(pObj->parent_pci_dev,
909 pAd->HostLnkCtrlOffset,
910 Configuration);
911 DBGPRINT(RT_DEBUG_TRACE,
912 ("Restore PCI host : offset 0x%x = 0x%x\n",
913 pAd->HostLnkCtrlOffset, Configuration));
914 } else
915 DBGPRINT(RT_DEBUG_ERROR,
916 ("Restore PCI host : PCI_REG_READ_WORD failed (Configuration = 0x%x)\n",
917 Configuration));
918 }
919
920 if (pObj->pci_dev && (pAd->RLnkCtrlOffset != 0)) {
921 PCI_REG_READ_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset,
922 Configuration);
923 if ((Configuration != 0) && (Configuration != 0xFFFF)) {
924 Configuration &= 0xfefc;
925 /* If call from interface down, restore to original setting. */
926 if (Level == RESTORE_CLOSE)
927 Configuration |= pAd->RLnkCtrlConfiguration;
928 else
929 Configuration |= 0x0;
930 PCI_REG_WIRTE_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset,
931 Configuration);
932 DBGPRINT(RT_DEBUG_TRACE,
933 ("Restore Ralink : offset 0x%x = 0x%x\n",
934 pAd->RLnkCtrlOffset, Configuration));
935 } else
936 DBGPRINT(RT_DEBUG_ERROR,
937 ("Restore Ralink : PCI_REG_READ_WORD failed (Configuration = 0x%x)\n",
938 Configuration));
939 }
940
941 DBGPRINT(RT_DEBUG_TRACE, ("%s <===\n", __func__));
942}
943
944/*
945 ========================================================================
946
947 Routine Description:
948
949 Arguments:
950 Max : limit Host PCI and Ralink PCIe device's LINK CONTROL field's value.
951 Because now frequently set our device to mode 1 or mode 3 will cause problem.
952
953 ========================================================================
954*/
955void RTMPPCIeLinkCtrlSetting(struct rt_rtmp_adapter *pAd, u16 Max)
956{
957 u16 PCIePowerSaveLevel, reg16;
958 u16 Configuration;
959 struct os_cookie *pObj;
960
961 pObj = (struct os_cookie *)pAd->OS_Cookie;
962
963 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE))
964 return;
965
966#ifdef RT2860
967 if (!((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID)
968 || (pObj->DeviceID == NIC2790_PCIe_DEVICE_ID)))
969 return;
970#endif /* RT2860 // */
971 /* Check PSControl Configuration */
972 if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE)
973 return;
974
975 /* Check interface : If not PCIe interface, return. */
976 /*Block 3090 to enter the following function */
977
978#ifdef RT3090
979 if ((pObj->DeviceID == NIC3090_PCIe_DEVICE_ID)
980 || (pObj->DeviceID == NIC3091_PCIe_DEVICE_ID)
981 || (pObj->DeviceID == NIC3092_PCIe_DEVICE_ID))
982 return;
983#endif /* RT3090 // */
984 if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP)) {
985 DBGPRINT(RT_DEBUG_INFO,
986 ("RTMPPCIePowerLinkCtrl return on fRTMP_PS_CAN_GO_SLEEP flag\n"));
987 return;
988 }
989
990 DBGPRINT(RT_DEBUG_TRACE, ("%s===>\n", __func__));
991 PCIePowerSaveLevel = pAd->PCIePowerSaveLevel;
992 if ((PCIePowerSaveLevel & 0xff) == 0xff) {
993 DBGPRINT(RT_DEBUG_TRACE, ("return \n"));
994 return;
995 }
996 PCIePowerSaveLevel = PCIePowerSaveLevel >> 6;
997
998 /* Skip non-exist deice right away */
999 if (pObj->parent_pci_dev && (pAd->HostLnkCtrlOffset != 0)) {
1000 PCI_REG_READ_WORD(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset,
1001 Configuration);
1002 switch (PCIePowerSaveLevel) {
1003 case 0:
1004 /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 00 */
1005 Configuration &= 0xfefc;
1006 break;
1007 case 1:
1008 /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 01 */
1009 Configuration &= 0xfefc;
1010 Configuration |= 0x1;
1011 break;
1012 case 2:
1013 /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 11 */
1014 Configuration &= 0xfefc;
1015 Configuration |= 0x3;
1016 break;
1017 case 3:
1018 /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 11 and bit 8 of LinkControl of 2892 to 1 */
1019 Configuration &= 0xfefc;
1020 Configuration |= 0x103;
1021 break;
1022 }
1023 PCI_REG_WIRTE_WORD(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset,
1024 Configuration);
1025 DBGPRINT(RT_DEBUG_TRACE,
1026 ("Write PCI host offset 0x%x = 0x%x\n",
1027 pAd->HostLnkCtrlOffset, Configuration));
1028 }
1029
1030 if (pObj->pci_dev && (pAd->RLnkCtrlOffset != 0)) {
1031 /* first 2892 chip not allow to frequently set mode 3. will cause hang problem. */
1032 if (PCIePowerSaveLevel > Max)
1033 PCIePowerSaveLevel = Max;
1034
1035 PCI_REG_READ_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset,
1036 Configuration);
1037 switch (PCIePowerSaveLevel) {
1038 case 0:
1039 /* No PCI power safe */
1040 /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 00 . */
1041 Configuration &= 0xfefc;
1042 break;
1043 case 1:
1044 /* L0 */
1045 /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 01 . */
1046 Configuration &= 0xfefc;
1047 Configuration |= 0x1;
1048 break;
1049 case 2:
1050 /* L0 and L1 */
1051 /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 11 */
1052 Configuration &= 0xfefc;
1053 Configuration |= 0x3;
1054 break;
1055 case 3:
1056 /* L0 , L1 and clock management. */
1057 /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 11 and bit 8 of LinkControl of 2892 to 1 */
1058 Configuration &= 0xfefc;
1059 Configuration |= 0x103;
1060 pAd->bPCIclkOff = TRUE;
1061 break;
1062 }
1063 PCI_REG_WIRTE_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset,
1064 Configuration);
1065 DBGPRINT(RT_DEBUG_TRACE,
1066 ("Write Ralink device : offset 0x%x = 0x%x\n",
1067 pAd->RLnkCtrlOffset, Configuration));
1068 }
1069
1070 DBGPRINT(RT_DEBUG_TRACE, ("RTMPPCIePowerLinkCtrl <==============\n"));
1071}
1072
1073/*
1074 ========================================================================
1075
1076 Routine Description:
1077 1. Write a PCI register for rt30xx power solution 3
1078
1079 ========================================================================
1080*/
1081void RTMPrt3xSetPCIePowerLinkCtrl(struct rt_rtmp_adapter *pAd)
1082{
1083
1084 unsigned long HostConfiguration = 0;
1085 unsigned long Configuration;
1086 struct os_cookie *pObj;
1087 int pos;
1088 u16 reg16;
1089
1090 pObj = (struct os_cookie *)pAd->OS_Cookie;
1091
1092 DBGPRINT(RT_DEBUG_INFO,
1093 ("RTMPrt3xSetPCIePowerLinkCtrl.===> %lx\n",
1094 pAd->StaCfg.PSControl.word));
1095
1096 /* Check PSControl Configuration */
1097 if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE)
1098 return;
1099 RTMPFindHostPCIDev(pAd);
1100 if (pObj->parent_pci_dev) {
1101 /* Find PCI-to-PCI Bridge Express Capability Offset */
1102 pos = pci_find_capability(pObj->parent_pci_dev, PCI_CAP_ID_EXP);
1103
1104 if (pos != 0)
1105 pAd->HostLnkCtrlOffset = pos + PCI_EXP_LNKCTL;
1106
1107 /* If configured to turn on L1. */
1108 HostConfiguration = 0;
1109 if (pAd->StaCfg.PSControl.field.rt30xxForceASPMTest == 1) {
1110 DBGPRINT(RT_DEBUG_TRACE, ("Enter,PSM : Force ASPM\n"));
1111
1112 /* Skip non-exist device right away */
1113 if ((pAd->HostLnkCtrlOffset != 0)) {
1114 PCI_REG_READ_WORD(pObj->parent_pci_dev,
1115 pAd->HostLnkCtrlOffset,
1116 HostConfiguration);
1117 /* Prepare Configuration to write to Host */
1118 HostConfiguration |= 0x3;
1119 PCI_REG_WIRTE_WORD(pObj->parent_pci_dev,
1120 pAd->HostLnkCtrlOffset,
1121 HostConfiguration);
1122 pAd->Rt3xxHostLinkCtrl = HostConfiguration;
1123 /* Because in rt30xxForceASPMTest Mode, Force turn on L0s, L1. */
1124 /* Fix HostConfiguration bit0:1 = 0x3 for later use. */
1125 HostConfiguration = 0x3;
1126 DBGPRINT(RT_DEBUG_TRACE,
1127 ("PSM : Force ASPM : "
1128 "Host device L1/L0s Value = 0x%lx\n",
1129 HostConfiguration));
1130 }
1131 } else if (pAd->StaCfg.PSControl.field.rt30xxFollowHostASPM ==
1132 1) {
1133
1134 /* Skip non-exist deice right away */
1135 if ((pAd->HostLnkCtrlOffset != 0)) {
1136 PCI_REG_READ_WORD(pObj->parent_pci_dev,
1137 pAd->HostLnkCtrlOffset,
1138 HostConfiguration);
1139 pAd->Rt3xxHostLinkCtrl = HostConfiguration;
1140 HostConfiguration &= 0x3;
1141 DBGPRINT(RT_DEBUG_TRACE,
1142 ("PSM : Follow Host ASPM : "
1143 "Host device L1/L0s Value = 0x%lx\n",
1144 HostConfiguration));
1145 }
1146 }
1147 }
1148 /* Prepare to write Ralink setting. */
1149 /* Find Ralink PCIe Device's Express Capability Offset */
1150 pos = pci_find_capability(pObj->pci_dev, PCI_CAP_ID_EXP);
1151
1152 if (pos != 0) {
1153 /* Ralink PCIe Device's Link Control Register Offset */
1154 pAd->RLnkCtrlOffset = pos + PCI_EXP_LNKCTL;
1155 pci_read_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset,
1156 &reg16);
1157 Configuration = le2cpu16(reg16);
1158 DBGPRINT(RT_DEBUG_TRACE,
1159 ("Read (Ralink PCIe Link Control Register) "
1160 "offset 0x%x = 0x%lx\n",
1161 pAd->RLnkCtrlOffset, Configuration));
1162 Configuration |= 0x100;
1163 if ((pAd->StaCfg.PSControl.field.rt30xxFollowHostASPM == 1)
1164 || (pAd->StaCfg.PSControl.field.rt30xxForceASPMTest == 1)) {
1165 switch (HostConfiguration) {
1166 case 0:
1167 Configuration &= 0xffffffc;
1168 break;
1169 case 1:
1170 Configuration &= 0xffffffc;
1171 Configuration |= 0x1;
1172 break;
1173 case 2:
1174 Configuration &= 0xffffffc;
1175 Configuration |= 0x2;
1176 break;
1177 case 3:
1178 Configuration |= 0x3;
1179 break;
1180 }
1181 }
1182 reg16 = cpu2le16(Configuration);
1183 pci_write_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset,
1184 reg16);
1185 pAd->Rt3xxRalinkLinkCtrl = Configuration;
1186 DBGPRINT(RT_DEBUG_TRACE,
1187 ("PSM :Write Ralink device L1/L0s Value = 0x%lx\n",
1188 Configuration));
1189 }
1190 DBGPRINT(RT_DEBUG_INFO,
1191 ("PSM :RTMPrt3xSetPCIePowerLinkCtrl <==============\n"));
1192}
diff --git a/drivers/staging/rt2860/rt_config.h b/drivers/staging/rt2860/rt_config.h
deleted file mode 100644
index d1adef8948a..00000000000
--- a/drivers/staging/rt2860/rt_config.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt_config.h
29
30 Abstract:
31 Central header file to maintain all include files for all NDIS
32 miniport driver routines.
33
34 Revision History:
35 Who When What
36 -------- ---------- ----------------------------------------------
37 Paul Lin 08-01-2002 created
38
39*/
40#ifndef __RT_CONFIG_H__
41#define __RT_CONFIG_H__
42
43#include "rtmp_type.h"
44#include "rtmp_os.h"
45
46#include "rtmp_def.h"
47#include "rtmp_chip.h"
48#include "rtmp_timer.h"
49
50#include "oid.h"
51#include "mlme.h"
52#include "wpa.h"
53#include "crypt_md5.h"
54#include "crypt_sha2.h"
55#include "crypt_hmac.h"
56#include "rtmp.h"
57#include "ap.h"
58#include "dfs.h"
59#include "chlist.h"
60#include "spectrum.h"
61
62#include "eeprom.h"
63#if defined(RTMP_PCI_SUPPORT) || defined(RTMP_USB_SUPPORT)
64#include "rtmp_mcu.h"
65#endif
66
67#ifdef IGMP_SNOOP_SUPPORT
68#include "igmp_snoop.h"
69#endif /* IGMP_SNOOP_SUPPORT // */
70
71#endif /* __RT_CONFIG_H__ */
diff --git a/drivers/staging/rt2860/rt_linux.c b/drivers/staging/rt2860/rt_linux.c
deleted file mode 100644
index 1583347fcd5..00000000000
--- a/drivers/staging/rt2860/rt_linux.c
+++ /dev/null
@@ -1,1367 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28#include <linux/firmware.h>
29#include <linux/sched.h>
30#include <linux/slab.h>
31#include "rt_config.h"
32
33unsigned long RTDebugLevel = RT_DEBUG_ERROR;
34
35/* for wireless system event message */
36char const *pWirelessSysEventText[IW_SYS_EVENT_TYPE_NUM] = {
37 /* system status event */
38 "had associated successfully", /* IW_ASSOC_EVENT_FLAG */
39 "had disassociated", /* IW_DISASSOC_EVENT_FLAG */
40 "had deauthenticated", /* IW_DEAUTH_EVENT_FLAG */
41 "had been aged-out and disassociated", /* IW_AGEOUT_EVENT_FLAG */
42 "occurred CounterMeasures attack", /* IW_COUNTER_MEASURES_EVENT_FLAG */
43 "occurred replay counter different in Key Handshaking", /* IW_REPLAY_COUNTER_DIFF_EVENT_FLAG */
44 "occurred RSNIE different in Key Handshaking", /* IW_RSNIE_DIFF_EVENT_FLAG */
45 "occurred MIC different in Key Handshaking", /* IW_MIC_DIFF_EVENT_FLAG */
46 "occurred ICV error in RX", /* IW_ICV_ERROR_EVENT_FLAG */
47 "occurred MIC error in RX", /* IW_MIC_ERROR_EVENT_FLAG */
48 "Group Key Handshaking timeout", /* IW_GROUP_HS_TIMEOUT_EVENT_FLAG */
49 "Pairwise Key Handshaking timeout", /* IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG */
50 "RSN IE sanity check failure", /* IW_RSNIE_SANITY_FAIL_EVENT_FLAG */
51 "set key done in WPA/WPAPSK", /* IW_SET_KEY_DONE_WPA1_EVENT_FLAG */
52 "set key done in WPA2/WPA2PSK", /* IW_SET_KEY_DONE_WPA2_EVENT_FLAG */
53 "connects with our wireless client", /* IW_STA_LINKUP_EVENT_FLAG */
54 "disconnects with our wireless client", /* IW_STA_LINKDOWN_EVENT_FLAG */
55 "scan completed" /* IW_SCAN_COMPLETED_EVENT_FLAG */
56 "scan terminate! Busy! Enqueue fail!" /* IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG */
57};
58
59/* for wireless IDS_spoof_attack event message */
60char const *pWirelessSpoofEventText[IW_SPOOF_EVENT_TYPE_NUM] = {
61 "detected conflict SSID", /* IW_CONFLICT_SSID_EVENT_FLAG */
62 "detected spoofed association response", /* IW_SPOOF_ASSOC_RESP_EVENT_FLAG */
63 "detected spoofed reassociation responses", /* IW_SPOOF_REASSOC_RESP_EVENT_FLAG */
64 "detected spoofed probe response", /* IW_SPOOF_PROBE_RESP_EVENT_FLAG */
65 "detected spoofed beacon", /* IW_SPOOF_BEACON_EVENT_FLAG */
66 "detected spoofed disassociation", /* IW_SPOOF_DISASSOC_EVENT_FLAG */
67 "detected spoofed authentication", /* IW_SPOOF_AUTH_EVENT_FLAG */
68 "detected spoofed deauthentication", /* IW_SPOOF_DEAUTH_EVENT_FLAG */
69 "detected spoofed unknown management frame", /* IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG */
70 "detected replay attack" /* IW_REPLAY_ATTACK_EVENT_FLAG */
71};
72
73/* for wireless IDS_flooding_attack event message */
74char const *pWirelessFloodEventText[IW_FLOOD_EVENT_TYPE_NUM] = {
75 "detected authentication flooding", /* IW_FLOOD_AUTH_EVENT_FLAG */
76 "detected association request flooding", /* IW_FLOOD_ASSOC_REQ_EVENT_FLAG */
77 "detected reassociation request flooding", /* IW_FLOOD_REASSOC_REQ_EVENT_FLAG */
78 "detected probe request flooding", /* IW_FLOOD_PROBE_REQ_EVENT_FLAG */
79 "detected disassociation flooding", /* IW_FLOOD_DISASSOC_EVENT_FLAG */
80 "detected deauthentication flooding", /* IW_FLOOD_DEAUTH_EVENT_FLAG */
81 "detected 802.1x eap-request flooding" /* IW_FLOOD_EAP_REQ_EVENT_FLAG */
82};
83
84/* timeout -- ms */
85void RTMP_SetPeriodicTimer(struct timer_list *pTimer,
86 IN unsigned long timeout)
87{
88 timeout = ((timeout * OS_HZ) / 1000);
89 pTimer->expires = jiffies + timeout;
90 add_timer(pTimer);
91}
92
93/* convert NdisMInitializeTimer --> RTMP_OS_Init_Timer */
94void RTMP_OS_Init_Timer(struct rt_rtmp_adapter *pAd,
95 struct timer_list *pTimer,
96 IN TIMER_FUNCTION function, void *data)
97{
98 init_timer(pTimer);
99 pTimer->data = (unsigned long)data;
100 pTimer->function = function;
101}
102
103void RTMP_OS_Add_Timer(struct timer_list *pTimer,
104 IN unsigned long timeout)
105{
106 if (timer_pending(pTimer))
107 return;
108
109 timeout = ((timeout * OS_HZ) / 1000);
110 pTimer->expires = jiffies + timeout;
111 add_timer(pTimer);
112}
113
114void RTMP_OS_Mod_Timer(struct timer_list *pTimer,
115 IN unsigned long timeout)
116{
117 timeout = ((timeout * OS_HZ) / 1000);
118 mod_timer(pTimer, jiffies + timeout);
119}
120
121void RTMP_OS_Del_Timer(struct timer_list *pTimer, OUT BOOLEAN *pCancelled)
122{
123 if (timer_pending(pTimer)) {
124 *pCancelled = del_timer_sync(pTimer);
125 } else {
126 *pCancelled = TRUE;
127 }
128
129}
130
131void RTMP_OS_Release_Packet(struct rt_rtmp_adapter *pAd, struct rt_queue_entry *pEntry)
132{
133 /*RTMPFreeNdisPacket(pAd, (struct sk_buff *)pEntry); */
134}
135
136/* Unify all delay routine by using udelay */
137void RTMPusecDelay(unsigned long usec)
138{
139 unsigned long i;
140
141 for (i = 0; i < (usec / 50); i++)
142 udelay(50);
143
144 if (usec % 50)
145 udelay(usec % 50);
146}
147
148void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time)
149{
150 time->u.LowPart = jiffies;
151}
152
153/* pAd MUST allow to be NULL */
154int os_alloc_mem(struct rt_rtmp_adapter *pAd, u8 ** mem, unsigned long size)
155{
156 *mem = kmalloc(size, GFP_ATOMIC);
157 if (*mem)
158 return NDIS_STATUS_SUCCESS;
159 else
160 return NDIS_STATUS_FAILURE;
161}
162
163/* pAd MUST allow to be NULL */
164int os_free_mem(struct rt_rtmp_adapter *pAd, void *mem)
165{
166
167 ASSERT(mem);
168 kfree(mem);
169 return NDIS_STATUS_SUCCESS;
170}
171
172void *RtmpOSNetPktAlloc(struct rt_rtmp_adapter *pAd, IN int size)
173{
174 struct sk_buff *skb;
175 /* Add 2 more bytes for ip header alignment */
176 skb = dev_alloc_skb(size + 2);
177
178 return (void *)skb;
179}
180
181void *RTMP_AllocateFragPacketBuffer(struct rt_rtmp_adapter *pAd,
182 unsigned long Length)
183{
184 struct sk_buff *pkt;
185
186 pkt = dev_alloc_skb(Length);
187
188 if (pkt == NULL) {
189 DBGPRINT(RT_DEBUG_ERROR,
190 ("can't allocate frag rx %ld size packet\n", Length));
191 }
192
193 if (pkt) {
194 RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
195 }
196
197 return (void *)pkt;
198}
199
200void *RTMP_AllocateTxPacketBuffer(struct rt_rtmp_adapter *pAd,
201 unsigned long Length,
202 IN BOOLEAN Cached,
203 void **VirtualAddress)
204{
205 struct sk_buff *pkt;
206
207 pkt = dev_alloc_skb(Length);
208
209 if (pkt == NULL) {
210 DBGPRINT(RT_DEBUG_ERROR,
211 ("can't allocate tx %ld size packet\n", Length));
212 }
213
214 if (pkt) {
215 RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
216 *VirtualAddress = (void *)pkt->data;
217 } else {
218 *VirtualAddress = (void *)NULL;
219 }
220
221 return (void *)pkt;
222}
223
224void build_tx_packet(struct rt_rtmp_adapter *pAd,
225 void *pPacket,
226 u8 *pFrame, unsigned long FrameLen)
227{
228
229 struct sk_buff *pTxPkt;
230
231 ASSERT(pPacket);
232 pTxPkt = RTPKT_TO_OSPKT(pPacket);
233
234 NdisMoveMemory(skb_put(pTxPkt, FrameLen), pFrame, FrameLen);
235}
236
237void RTMPFreeAdapter(struct rt_rtmp_adapter *pAd)
238{
239 struct os_cookie *os_cookie;
240 int index;
241
242 os_cookie = (struct os_cookie *)pAd->OS_Cookie;
243
244 kfree(pAd->BeaconBuf);
245
246 NdisFreeSpinLock(&pAd->MgmtRingLock);
247
248#ifdef RTMP_MAC_PCI
249 NdisFreeSpinLock(&pAd->RxRingLock);
250#ifdef RT3090
251 NdisFreeSpinLock(&pAd->McuCmdLock);
252#endif /* RT3090 // */
253#endif /* RTMP_MAC_PCI // */
254
255 for (index = 0; index < NUM_OF_TX_RING; index++) {
256 NdisFreeSpinLock(&pAd->TxSwQueueLock[index]);
257 NdisFreeSpinLock(&pAd->DeQueueLock[index]);
258 pAd->DeQueueRunning[index] = FALSE;
259 }
260
261 NdisFreeSpinLock(&pAd->irq_lock);
262
263 release_firmware(pAd->firmware);
264
265 vfree(pAd); /* pci_free_consistent(os_cookie->pci_dev,sizeof(struct rt_rtmp_adapter),pAd,os_cookie->pAd_pa); */
266 kfree(os_cookie);
267}
268
269BOOLEAN OS_Need_Clone_Packet(void)
270{
271 return FALSE;
272}
273
274/*
275 ========================================================================
276
277 Routine Description:
278 clone an input NDIS PACKET to another one. The new internally created NDIS PACKET
279 must have only one NDIS BUFFER
280 return - byte copied. 0 means can't create NDIS PACKET
281 NOTE: internally created char should be destroyed by RTMPFreeNdisPacket
282
283 Arguments:
284 pAd Pointer to our adapter
285 pInsAMSDUHdr EWC A-MSDU format has extra 14-bytes header. if TRUE, insert this 14-byte hdr in front of MSDU.
286 *pSrcTotalLen return total packet length. This length is calculated with 802.3 format packet.
287
288 Return Value:
289 NDIS_STATUS_SUCCESS
290 NDIS_STATUS_FAILURE
291
292 Note:
293
294 ========================================================================
295*/
296int RTMPCloneNdisPacket(struct rt_rtmp_adapter *pAd,
297 IN BOOLEAN pInsAMSDUHdr,
298 void *pInPacket,
299 void **ppOutPacket)
300{
301
302 struct sk_buff *pkt;
303
304 ASSERT(pInPacket);
305 ASSERT(ppOutPacket);
306
307 /* 1. Allocate a packet */
308 pkt = dev_alloc_skb(2048);
309
310 if (pkt == NULL) {
311 return NDIS_STATUS_FAILURE;
312 }
313
314 skb_put(pkt, GET_OS_PKT_LEN(pInPacket));
315 NdisMoveMemory(pkt->data, GET_OS_PKT_DATAPTR(pInPacket),
316 GET_OS_PKT_LEN(pInPacket));
317 *ppOutPacket = OSPKT_TO_RTPKT(pkt);
318
319 RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
320
321 printk(KERN_DEBUG "###Clone###\n");
322
323 return NDIS_STATUS_SUCCESS;
324}
325
326/* the allocated NDIS PACKET must be freed via RTMPFreeNdisPacket() */
327int RTMPAllocateNdisPacket(struct rt_rtmp_adapter *pAd,
328 void **ppPacket,
329 u8 *pHeader,
330 u32 HeaderLen,
331 u8 *pData, u32 DataLen)
332{
333 void *pPacket;
334 ASSERT(pData);
335 ASSERT(DataLen);
336
337 /* 1. Allocate a packet */
338 pPacket =
339 (void **) dev_alloc_skb(HeaderLen + DataLen +
340 RTMP_PKT_TAIL_PADDING);
341 if (pPacket == NULL) {
342 *ppPacket = NULL;
343 pr_devel("RTMPAllocateNdisPacket Fail\n");
344
345 return NDIS_STATUS_FAILURE;
346 }
347 /* 2. clone the frame content */
348 if (HeaderLen > 0)
349 NdisMoveMemory(GET_OS_PKT_DATAPTR(pPacket), pHeader, HeaderLen);
350 if (DataLen > 0)
351 NdisMoveMemory(GET_OS_PKT_DATAPTR(pPacket) + HeaderLen, pData,
352 DataLen);
353
354 /* 3. update length of packet */
355 skb_put(GET_OS_PKT_TYPE(pPacket), HeaderLen + DataLen);
356
357 RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
358/* printk("%s : pPacket = %p, len = %d\n", __func__, pPacket, GET_OS_PKT_LEN(pPacket)); */
359 *ppPacket = pPacket;
360 return NDIS_STATUS_SUCCESS;
361}
362
363/*
364 ========================================================================
365 Description:
366 This routine frees a miniport internally allocated char and its
367 corresponding NDIS_BUFFER and allocated memory.
368 ========================================================================
369*/
370void RTMPFreeNdisPacket(struct rt_rtmp_adapter *pAd, void *pPacket)
371{
372 dev_kfree_skb_any(RTPKT_TO_OSPKT(pPacket));
373}
374
375/* IRQL = DISPATCH_LEVEL */
376/* NOTE: we do have an assumption here, that Byte0 and Byte1 always reasid at the same */
377/* scatter gather buffer */
378int Sniff2BytesFromNdisBuffer(char *pFirstBuffer,
379 u8 DesiredOffset,
380 u8 *pByte0, u8 *pByte1)
381{
382 *pByte0 = *(u8 *)(pFirstBuffer + DesiredOffset);
383 *pByte1 = *(u8 *)(pFirstBuffer + DesiredOffset + 1);
384
385 return NDIS_STATUS_SUCCESS;
386}
387
388void RTMP_QueryPacketInfo(void *pPacket,
389 struct rt_packet_info *pPacketInfo,
390 u8 **pSrcBufVA, u32 * pSrcBufLen)
391{
392 pPacketInfo->BufferCount = 1;
393 pPacketInfo->pFirstBuffer = (char *)GET_OS_PKT_DATAPTR(pPacket);
394 pPacketInfo->PhysicalBufferCount = 1;
395 pPacketInfo->TotalPacketLength = GET_OS_PKT_LEN(pPacket);
396
397 *pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
398 *pSrcBufLen = GET_OS_PKT_LEN(pPacket);
399}
400
401void RTMP_QueryNextPacketInfo(void **ppPacket,
402 struct rt_packet_info *pPacketInfo,
403 u8 **pSrcBufVA, u32 * pSrcBufLen)
404{
405 void *pPacket = NULL;
406
407 if (*ppPacket)
408 pPacket = GET_OS_PKT_NEXT(*ppPacket);
409
410 if (pPacket) {
411 pPacketInfo->BufferCount = 1;
412 pPacketInfo->pFirstBuffer =
413 (char *)GET_OS_PKT_DATAPTR(pPacket);
414 pPacketInfo->PhysicalBufferCount = 1;
415 pPacketInfo->TotalPacketLength = GET_OS_PKT_LEN(pPacket);
416
417 *pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket);
418 *pSrcBufLen = GET_OS_PKT_LEN(pPacket);
419 *ppPacket = GET_OS_PKT_NEXT(pPacket);
420 } else {
421 pPacketInfo->BufferCount = 0;
422 pPacketInfo->pFirstBuffer = NULL;
423 pPacketInfo->PhysicalBufferCount = 0;
424 pPacketInfo->TotalPacketLength = 0;
425
426 *pSrcBufVA = NULL;
427 *pSrcBufLen = 0;
428 *ppPacket = NULL;
429 }
430}
431
432void *DuplicatePacket(struct rt_rtmp_adapter *pAd,
433 void *pPacket, u8 FromWhichBSSID)
434{
435 struct sk_buff *skb;
436 void *pRetPacket = NULL;
437 u16 DataSize;
438 u8 *pData;
439
440 DataSize = (u16)GET_OS_PKT_LEN(pPacket);
441 pData = (u8 *)GET_OS_PKT_DATAPTR(pPacket);
442
443 skb = skb_clone(RTPKT_TO_OSPKT(pPacket), MEM_ALLOC_FLAG);
444 if (skb) {
445 skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
446 pRetPacket = OSPKT_TO_RTPKT(skb);
447 }
448
449 return pRetPacket;
450
451}
452
453void *duplicate_pkt(struct rt_rtmp_adapter *pAd,
454 u8 *pHeader802_3,
455 u32 HdrLen,
456 u8 *pData,
457 unsigned long DataSize, u8 FromWhichBSSID)
458{
459 struct sk_buff *skb;
460 void *pPacket = NULL;
461
462 skb = __dev_alloc_skb(HdrLen + DataSize + 2, MEM_ALLOC_FLAG);
463 if (skb != NULL) {
464 skb_reserve(skb, 2);
465 NdisMoveMemory(skb_tail_pointer(skb), pHeader802_3, HdrLen);
466 skb_put(skb, HdrLen);
467 NdisMoveMemory(skb_tail_pointer(skb), pData, DataSize);
468 skb_put(skb, DataSize);
469 skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
470 pPacket = OSPKT_TO_RTPKT(skb);
471 }
472
473 return pPacket;
474}
475
476#define TKIP_TX_MIC_SIZE 8
477void *duplicate_pkt_with_TKIP_MIC(struct rt_rtmp_adapter *pAd,
478 void *pPacket)
479{
480 struct sk_buff *skb, *newskb;
481
482 skb = RTPKT_TO_OSPKT(pPacket);
483 if (skb_tailroom(skb) < TKIP_TX_MIC_SIZE) {
484 /* alloc a new skb and copy the packet */
485 newskb =
486 skb_copy_expand(skb, skb_headroom(skb), TKIP_TX_MIC_SIZE,
487 GFP_ATOMIC);
488 dev_kfree_skb_any(skb);
489 if (newskb == NULL) {
490 DBGPRINT(RT_DEBUG_ERROR,
491 ("Extend Tx.MIC for packet failed!, dropping packet!\n"));
492 return NULL;
493 }
494 skb = newskb;
495 }
496
497 return OSPKT_TO_RTPKT(skb);
498}
499
500void *ClonePacket(struct rt_rtmp_adapter *pAd,
501 void *pPacket,
502 u8 *pData, unsigned long DataSize)
503{
504 struct sk_buff *pRxPkt;
505 struct sk_buff *pClonedPkt;
506
507 ASSERT(pPacket);
508 pRxPkt = RTPKT_TO_OSPKT(pPacket);
509
510 /* clone the packet */
511 pClonedPkt = skb_clone(pRxPkt, MEM_ALLOC_FLAG);
512
513 if (pClonedPkt) {
514 /* set the correct dataptr and data len */
515 pClonedPkt->dev = pRxPkt->dev;
516 pClonedPkt->data = pData;
517 pClonedPkt->len = DataSize;
518 skb_set_tail_pointer(pClonedPkt, DataSize)
519 ASSERT(DataSize < 1530);
520 }
521 return pClonedPkt;
522}
523
524/* */
525/* change OS packet DataPtr and DataLen */
526/* */
527void update_os_packet_info(struct rt_rtmp_adapter *pAd,
528 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
529{
530 struct sk_buff *pOSPkt;
531
532 ASSERT(pRxBlk->pRxPacket);
533 pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
534
535 pOSPkt->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
536 pOSPkt->data = pRxBlk->pData;
537 pOSPkt->len = pRxBlk->DataSize;
538 skb_set_tail_pointer(pOSPkt, pOSPkt->len);
539}
540
541void wlan_802_11_to_802_3_packet(struct rt_rtmp_adapter *pAd,
542 struct rt_rx_blk *pRxBlk,
543 u8 *pHeader802_3,
544 u8 FromWhichBSSID)
545{
546 struct sk_buff *pOSPkt;
547
548 ASSERT(pRxBlk->pRxPacket);
549 ASSERT(pHeader802_3);
550
551 pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
552
553 pOSPkt->dev = get_netdev_from_bssid(pAd, FromWhichBSSID);
554 pOSPkt->data = pRxBlk->pData;
555 pOSPkt->len = pRxBlk->DataSize;
556 skb_set_tail_pointer(pOSPkt, pOSPkt->len);
557
558 /* */
559 /* copy 802.3 header */
560 /* */
561 /* */
562
563 NdisMoveMemory(skb_push(pOSPkt, LENGTH_802_3), pHeader802_3,
564 LENGTH_802_3);
565}
566
567void announce_802_3_packet(struct rt_rtmp_adapter *pAd, void *pPacket)
568{
569
570 struct sk_buff *pRxPkt;
571
572 ASSERT(pPacket);
573
574 pRxPkt = RTPKT_TO_OSPKT(pPacket);
575
576 /* Push up the protocol stack */
577 pRxPkt->protocol = eth_type_trans(pRxPkt, pRxPkt->dev);
578
579 netif_rx(pRxPkt);
580}
581
582struct rt_rtmp_sg_list *
583rt_get_sg_list_from_packet(void *pPacket, struct rt_rtmp_sg_list *sg)
584{
585 sg->NumberOfElements = 1;
586 sg->Elements[0].Address = GET_OS_PKT_DATAPTR(pPacket);
587 sg->Elements[0].Length = GET_OS_PKT_LEN(pPacket);
588 return sg;
589}
590
591void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen)
592{
593 unsigned char *pt;
594 int x;
595
596 if (RTDebugLevel < RT_DEBUG_TRACE)
597 return;
598
599 pt = pSrcBufVA;
600 printk(KERN_DEBUG "%s: %p, len = %d\n", str, pSrcBufVA, SrcBufLen);
601 for (x = 0; x < SrcBufLen; x++) {
602 if (x % 16 == 0)
603 printk(KERN_DEBUG "0x%04x : ", x);
604 printk(KERN_DEBUG "%02x ", ((unsigned char)pt[x]));
605 if (x % 16 == 15)
606 printk(KERN_DEBUG "\n");
607 }
608 printk(KERN_DEBUG "\n");
609}
610
611/*
612 ========================================================================
613
614 Routine Description:
615 Send log message through wireless event
616
617 Support standard iw_event with IWEVCUSTOM. It is used below.
618
619 iwreq_data.data.flags is used to store event_flag that is defined by user.
620 iwreq_data.data.length is the length of the event log.
621
622 The format of the event log is composed of the entry's MAC address and
623 the desired log message (refer to pWirelessEventText).
624
625 ex: 11:22:33:44:55:66 has associated successfully
626
627 p.s. The requirement of Wireless Extension is v15 or newer.
628
629 ========================================================================
630*/
631void RTMPSendWirelessEvent(struct rt_rtmp_adapter *pAd,
632 u16 Event_flag,
633 u8 *pAddr, u8 BssIdx, char Rssi)
634{
635
636 /*union iwreq_data wrqu; */
637 char *pBuf = NULL, *pBufPtr = NULL;
638 u16 event, type, BufLen;
639 u8 event_table_len = 0;
640
641 type = Event_flag & 0xFF00;
642 event = Event_flag & 0x00FF;
643
644 switch (type) {
645 case IW_SYS_EVENT_FLAG_START:
646 event_table_len = IW_SYS_EVENT_TYPE_NUM;
647 break;
648
649 case IW_SPOOF_EVENT_FLAG_START:
650 event_table_len = IW_SPOOF_EVENT_TYPE_NUM;
651 break;
652
653 case IW_FLOOD_EVENT_FLAG_START:
654 event_table_len = IW_FLOOD_EVENT_TYPE_NUM;
655 break;
656 }
657
658 if (event_table_len == 0) {
659 DBGPRINT(RT_DEBUG_ERROR,
660 ("%s : The type(%0x02x) is not valid.\n", __func__,
661 type));
662 return;
663 }
664
665 if (event >= event_table_len) {
666 DBGPRINT(RT_DEBUG_ERROR,
667 ("%s : The event(%0x02x) is not valid.\n", __func__,
668 event));
669 return;
670 }
671 /*Allocate memory and copy the msg. */
672 pBuf = kmalloc(IW_CUSTOM_MAX_LEN, GFP_ATOMIC);
673 if (pBuf != NULL) {
674 /*Prepare the payload */
675 memset(pBuf, 0, IW_CUSTOM_MAX_LEN);
676
677 pBufPtr = pBuf;
678
679 if (pAddr)
680 pBufPtr +=
681 sprintf(pBufPtr, "(RT2860) STA(%pM) ", pAddr);
682 else if (BssIdx < MAX_MBSSID_NUM)
683 pBufPtr +=
684 sprintf(pBufPtr, "(RT2860) BSS(wlan%d) ", BssIdx);
685 else
686 pBufPtr += sprintf(pBufPtr, "(RT2860) ");
687
688 if (type == IW_SYS_EVENT_FLAG_START)
689 pBufPtr +=
690 sprintf(pBufPtr, "%s",
691 pWirelessSysEventText[event]);
692 else if (type == IW_SPOOF_EVENT_FLAG_START)
693 pBufPtr +=
694 sprintf(pBufPtr, "%s (RSSI=%d)",
695 pWirelessSpoofEventText[event], Rssi);
696 else if (type == IW_FLOOD_EVENT_FLAG_START)
697 pBufPtr +=
698 sprintf(pBufPtr, "%s",
699 pWirelessFloodEventText[event]);
700 else
701 pBufPtr += sprintf(pBufPtr, "%s", "unknown event");
702
703 pBufPtr[pBufPtr - pBuf] = '\0';
704 BufLen = pBufPtr - pBuf;
705
706 RtmpOSWrielessEventSend(pAd, IWEVCUSTOM, Event_flag, NULL,
707 (u8 *)pBuf, BufLen);
708 /*DBGPRINT(RT_DEBUG_TRACE, ("%s : %s\n", __func__, pBuf)); */
709
710 kfree(pBuf);
711 } else
712 DBGPRINT(RT_DEBUG_ERROR,
713 ("%s : Can't allocate memory for wireless event.\n",
714 __func__));
715}
716
717void send_monitor_packets(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk)
718{
719 struct sk_buff *pOSPkt;
720 struct rt_wlan_ng_prism2_header *ph;
721 int rate_index = 0;
722 u16 header_len = 0;
723 u8 temp_header[40] = { 0 };
724
725 u_int32_t ralinkrate[256] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 109, 110, 111, 112, 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, 27, 54, 81, 108, 162, 216, 243, 270, /* Last 38 */
726 54, 108, 162, 216, 324, 432, 486, 540, 14, 29, 43, 57, 87, 115,
727 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, 30, 60, 90,
728 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540,
729 600, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
730 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
731 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
732 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
733 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
734 72, 73, 74, 75, 76, 77, 78, 79, 80
735 };
736
737 ASSERT(pRxBlk->pRxPacket);
738 if (pRxBlk->DataSize < 10) {
739 DBGPRINT(RT_DEBUG_ERROR,
740 ("%s : Size is too small! (%d)\n", __func__,
741 pRxBlk->DataSize));
742 goto err_free_sk_buff;
743 }
744
745 if (pRxBlk->DataSize + sizeof(struct rt_wlan_ng_prism2_header) >
746 RX_BUFFER_AGGRESIZE) {
747 DBGPRINT(RT_DEBUG_ERROR,
748 ("%s : Size is too large! (%zu)\n", __func__,
749 pRxBlk->DataSize + sizeof(struct rt_wlan_ng_prism2_header)));
750 goto err_free_sk_buff;
751 }
752
753 pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket);
754 pOSPkt->dev = get_netdev_from_bssid(pAd, BSS0);
755 if (pRxBlk->pHeader->FC.Type == BTYPE_DATA) {
756 pRxBlk->DataSize -= LENGTH_802_11;
757 if ((pRxBlk->pHeader->FC.ToDs == 1) &&
758 (pRxBlk->pHeader->FC.FrDs == 1))
759 header_len = LENGTH_802_11_WITH_ADDR4;
760 else
761 header_len = LENGTH_802_11;
762
763 /* QOS */
764 if (pRxBlk->pHeader->FC.SubType & 0x08) {
765 header_len += 2;
766 /* Data skip QOS control field */
767 pRxBlk->DataSize -= 2;
768 }
769 /* Order bit: A-Ralink or HTC+ */
770 if (pRxBlk->pHeader->FC.Order) {
771 header_len += 4;
772 /* Data skip HTC control field */
773 pRxBlk->DataSize -= 4;
774 }
775 /* Copy Header */
776 if (header_len <= 40)
777 NdisMoveMemory(temp_header, pRxBlk->pData, header_len);
778
779 /* skip HW padding */
780 if (pRxBlk->RxD.L2PAD)
781 pRxBlk->pData += (header_len + 2);
782 else
783 pRxBlk->pData += header_len;
784 } /*end if */
785
786 if (pRxBlk->DataSize < pOSPkt->len) {
787 skb_trim(pOSPkt, pRxBlk->DataSize);
788 } else {
789 skb_put(pOSPkt, (pRxBlk->DataSize - pOSPkt->len));
790 } /*end if */
791
792 if ((pRxBlk->pData - pOSPkt->data) > 0) {
793 skb_put(pOSPkt, (pRxBlk->pData - pOSPkt->data));
794 skb_pull(pOSPkt, (pRxBlk->pData - pOSPkt->data));
795 } /*end if */
796
797 if (skb_headroom(pOSPkt) < (sizeof(struct rt_wlan_ng_prism2_header) + header_len)) {
798 if (pskb_expand_head
799 (pOSPkt, (sizeof(struct rt_wlan_ng_prism2_header) + header_len), 0,
800 GFP_ATOMIC)) {
801 DBGPRINT(RT_DEBUG_ERROR,
802 ("%s : Reallocate header size of sk_buff fail!\n",
803 __func__));
804 goto err_free_sk_buff;
805 } /*end if */
806 } /*end if */
807
808 if (header_len > 0)
809 NdisMoveMemory(skb_push(pOSPkt, header_len), temp_header,
810 header_len);
811
812 ph = (struct rt_wlan_ng_prism2_header *)skb_push(pOSPkt,
813 sizeof(struct rt_wlan_ng_prism2_header));
814 NdisZeroMemory(ph, sizeof(struct rt_wlan_ng_prism2_header));
815
816 ph->msgcode = DIDmsg_lnxind_wlansniffrm;
817 ph->msglen = sizeof(struct rt_wlan_ng_prism2_header);
818 strcpy((char *)ph->devname, (char *)pAd->net_dev->name);
819
820 ph->hosttime.did = DIDmsg_lnxind_wlansniffrm_hosttime;
821 ph->hosttime.status = 0;
822 ph->hosttime.len = 4;
823 ph->hosttime.data = jiffies;
824
825 ph->mactime.did = DIDmsg_lnxind_wlansniffrm_mactime;
826 ph->mactime.status = 0;
827 ph->mactime.len = 0;
828 ph->mactime.data = 0;
829
830 ph->istx.did = DIDmsg_lnxind_wlansniffrm_istx;
831 ph->istx.status = 0;
832 ph->istx.len = 0;
833 ph->istx.data = 0;
834
835 ph->channel.did = DIDmsg_lnxind_wlansniffrm_channel;
836 ph->channel.status = 0;
837 ph->channel.len = 4;
838
839 ph->channel.data = (u_int32_t) pAd->CommonCfg.Channel;
840
841 ph->rssi.did = DIDmsg_lnxind_wlansniffrm_rssi;
842 ph->rssi.status = 0;
843 ph->rssi.len = 4;
844 ph->rssi.data =
845 (u_int32_t) RTMPMaxRssi(pAd,
846 ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI0,
847 RSSI_0), ConvertToRssi(pAd,
848 pRxBlk->
849 pRxWI->
850 RSSI1,
851 RSSI_1),
852 ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI2,
853 RSSI_2));
854
855 ph->signal.did = DIDmsg_lnxind_wlansniffrm_signal;
856 ph->signal.status = 0;
857 ph->signal.len = 4;
858 ph->signal.data = 0; /*rssi + noise; */
859
860 ph->noise.did = DIDmsg_lnxind_wlansniffrm_noise;
861 ph->noise.status = 0;
862 ph->noise.len = 4;
863 ph->noise.data = 0;
864
865 if (pRxBlk->pRxWI->PHYMODE >= MODE_HTMIX) {
866 rate_index =
867 16 + ((u8)pRxBlk->pRxWI->BW * 16) +
868 ((u8)pRxBlk->pRxWI->ShortGI * 32) +
869 ((u8)pRxBlk->pRxWI->MCS);
870 } else if (pRxBlk->pRxWI->PHYMODE == MODE_OFDM)
871 rate_index = (u8)(pRxBlk->pRxWI->MCS) + 4;
872 else
873 rate_index = (u8)(pRxBlk->pRxWI->MCS);
874 if (rate_index < 0)
875 rate_index = 0;
876 if (rate_index > 255)
877 rate_index = 255;
878
879 ph->rate.did = DIDmsg_lnxind_wlansniffrm_rate;
880 ph->rate.status = 0;
881 ph->rate.len = 4;
882 ph->rate.data = ralinkrate[rate_index];
883
884 ph->frmlen.did = DIDmsg_lnxind_wlansniffrm_frmlen;
885 ph->frmlen.status = 0;
886 ph->frmlen.len = 4;
887 ph->frmlen.data = (u_int32_t) pRxBlk->DataSize;
888
889 pOSPkt->pkt_type = PACKET_OTHERHOST;
890 pOSPkt->protocol = eth_type_trans(pOSPkt, pOSPkt->dev);
891 pOSPkt->ip_summed = CHECKSUM_NONE;
892 netif_rx(pOSPkt);
893
894 return;
895
896err_free_sk_buff:
897 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
898 return;
899
900}
901
902/*******************************************************************************
903
904 Device IRQ related functions.
905
906 *******************************************************************************/
907int RtmpOSIRQRequest(struct net_device *pNetDev)
908{
909#ifdef RTMP_PCI_SUPPORT
910 struct net_device *net_dev = pNetDev;
911 struct rt_rtmp_adapter *pAd = NULL;
912 int retval = 0;
913
914 GET_PAD_FROM_NET_DEV(pAd, pNetDev);
915
916 ASSERT(pAd);
917
918 if (pAd->infType == RTMP_DEV_INF_PCI) {
919 struct os_cookie *_pObj = (struct os_cookie *)(pAd->OS_Cookie);
920 RTMP_MSI_ENABLE(pAd);
921 retval =
922 request_irq(_pObj->pci_dev->irq, rt2860_interrupt, SA_SHIRQ,
923 (net_dev)->name, (net_dev));
924 if (retval != 0)
925 printk(KERN_ERR "rt2860: request_irq ERROR(%d)\n", retval);
926 }
927
928 return retval;
929#else
930 return 0;
931#endif
932}
933
934int RtmpOSIRQRelease(struct net_device *pNetDev)
935{
936 struct net_device *net_dev = pNetDev;
937 struct rt_rtmp_adapter *pAd = NULL;
938
939 GET_PAD_FROM_NET_DEV(pAd, net_dev);
940
941 ASSERT(pAd);
942
943#ifdef RTMP_PCI_SUPPORT
944 if (pAd->infType == RTMP_DEV_INF_PCI) {
945 struct os_cookie *pObj = (struct os_cookie *)(pAd->OS_Cookie);
946 synchronize_irq(pObj->pci_dev->irq);
947 free_irq(pObj->pci_dev->irq, (net_dev));
948 RTMP_MSI_DISABLE(pAd);
949 }
950#endif /* RTMP_PCI_SUPPORT // */
951
952 return 0;
953}
954
955/*******************************************************************************
956
957 File open/close related functions.
958
959 *******************************************************************************/
960struct file *RtmpOSFileOpen(char *pPath, int flag, int mode)
961{
962 struct file *filePtr;
963
964 filePtr = filp_open(pPath, flag, 0);
965 if (IS_ERR(filePtr)) {
966 DBGPRINT(RT_DEBUG_ERROR,
967 ("%s(): Error %ld opening %s\n", __func__,
968 -PTR_ERR(filePtr), pPath));
969 }
970
971 return (struct file *)filePtr;
972}
973
974int RtmpOSFileClose(struct file *osfd)
975{
976 filp_close(osfd, NULL);
977 return 0;
978}
979
980void RtmpOSFileSeek(struct file *osfd, int offset)
981{
982 osfd->f_pos = offset;
983}
984
985int RtmpOSFileRead(struct file *osfd, char *pDataPtr, int readLen)
986{
987 /* The object must have a read method */
988 if (osfd->f_op && osfd->f_op->read) {
989 return osfd->f_op->read(osfd, pDataPtr, readLen, &osfd->f_pos);
990 } else {
991 DBGPRINT(RT_DEBUG_ERROR, ("no file read method\n"));
992 return -1;
993 }
994}
995
996int RtmpOSFileWrite(struct file *osfd, char *pDataPtr, int writeLen)
997{
998 return osfd->f_op->write(osfd, pDataPtr, (size_t) writeLen,
999 &osfd->f_pos);
1000}
1001
1002/*******************************************************************************
1003
1004 Task create/management/kill related functions.
1005
1006 *******************************************************************************/
1007int RtmpOSTaskKill(struct rt_rtmp_os_task *pTask)
1008{
1009 struct rt_rtmp_adapter *pAd;
1010 int ret = NDIS_STATUS_FAILURE;
1011
1012 pAd = pTask->priv;
1013
1014#ifdef KTHREAD_SUPPORT
1015 if (pTask->kthread_task) {
1016 kthread_stop(pTask->kthread_task);
1017 ret = NDIS_STATUS_SUCCESS;
1018 }
1019#else
1020 CHECK_PID_LEGALITY(pTask->taskPID) {
1021 printk(KERN_INFO "Terminate the task(%s) with pid(%d)!\n",
1022 pTask->taskName, GET_PID_NUMBER(pTask->taskPID));
1023 mb();
1024 pTask->task_killed = 1;
1025 mb();
1026 ret = KILL_THREAD_PID(pTask->taskPID, SIGTERM, 1);
1027 if (ret) {
1028 printk(KERN_WARNING
1029 "kill task(%s) with pid(%d) failed(retVal=%d)!\n",
1030 pTask->taskName, GET_PID_NUMBER(pTask->taskPID),
1031 ret);
1032 } else {
1033 wait_for_completion(&pTask->taskComplete);
1034 pTask->taskPID = THREAD_PID_INIT_VALUE;
1035 pTask->task_killed = 0;
1036 ret = NDIS_STATUS_SUCCESS;
1037 }
1038 }
1039#endif
1040
1041 return ret;
1042
1043}
1044
1045int RtmpOSTaskNotifyToExit(struct rt_rtmp_os_task *pTask)
1046{
1047
1048#ifndef KTHREAD_SUPPORT
1049 complete_and_exit(&pTask->taskComplete, 0);
1050#endif
1051
1052 return 0;
1053}
1054
1055void RtmpOSTaskCustomize(struct rt_rtmp_os_task *pTask)
1056{
1057
1058#ifndef KTHREAD_SUPPORT
1059
1060 daemonize((char *)&pTask->taskName[0] /*"%s",pAd->net_dev->name */);
1061
1062 allow_signal(SIGTERM);
1063 allow_signal(SIGKILL);
1064 current->flags |= PF_NOFREEZE;
1065
1066 /* signal that we've started the thread */
1067 complete(&pTask->taskComplete);
1068
1069#endif
1070}
1071
1072int RtmpOSTaskAttach(struct rt_rtmp_os_task *pTask,
1073 IN int (*fn) (void *), IN void *arg)
1074{
1075 int status = NDIS_STATUS_SUCCESS;
1076
1077#ifdef KTHREAD_SUPPORT
1078 pTask->task_killed = 0;
1079 pTask->kthread_task = NULL;
1080 pTask->kthread_task = kthread_run(fn, arg, pTask->taskName);
1081 if (IS_ERR(pTask->kthread_task))
1082 status = NDIS_STATUS_FAILURE;
1083#else
1084 pid_number = kernel_thread(fn, arg, RTMP_OS_MGMT_TASK_FLAGS);
1085 if (pid_number < 0) {
1086 DBGPRINT(RT_DEBUG_ERROR,
1087 ("Attach task(%s) failed!\n", pTask->taskName));
1088 status = NDIS_STATUS_FAILURE;
1089 } else {
1090 pTask->taskPID = GET_PID(pid_number);
1091
1092 /* Wait for the thread to start */
1093 wait_for_completion(&pTask->taskComplete);
1094 status = NDIS_STATUS_SUCCESS;
1095 }
1096#endif
1097 return status;
1098}
1099
1100int RtmpOSTaskInit(struct rt_rtmp_os_task *pTask,
1101 char *pTaskName, void * pPriv)
1102{
1103 int len;
1104
1105 ASSERT(pTask);
1106
1107#ifndef KTHREAD_SUPPORT
1108 NdisZeroMemory((u8 *)(pTask), sizeof(struct rt_rtmp_os_task));
1109#endif
1110
1111 len = strlen(pTaskName);
1112 len =
1113 len >
1114 (RTMP_OS_TASK_NAME_LEN - 1) ? (RTMP_OS_TASK_NAME_LEN - 1) : len;
1115 NdisMoveMemory(&pTask->taskName[0], pTaskName, len);
1116 pTask->priv = pPriv;
1117
1118#ifndef KTHREAD_SUPPORT
1119 RTMP_SEM_EVENT_INIT_LOCKED(&(pTask->taskSema));
1120 pTask->taskPID = THREAD_PID_INIT_VALUE;
1121
1122 init_completion(&pTask->taskComplete);
1123#endif
1124
1125 return NDIS_STATUS_SUCCESS;
1126}
1127
1128void RTMP_IndicateMediaState(struct rt_rtmp_adapter *pAd)
1129{
1130 if (pAd->CommonCfg.bWirelessEvent) {
1131 if (pAd->IndicateMediaState == NdisMediaStateConnected) {
1132 RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG,
1133 pAd->MacTab.Content[BSSID_WCID].
1134 Addr, BSS0, 0);
1135 } else {
1136 RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG,
1137 pAd->MacTab.Content[BSSID_WCID].
1138 Addr, BSS0, 0);
1139 }
1140 }
1141}
1142
1143int RtmpOSWrielessEventSend(struct rt_rtmp_adapter *pAd,
1144 u32 eventType,
1145 int flags,
1146 u8 *pSrcMac,
1147 u8 *pData, u32 dataLen)
1148{
1149 union iwreq_data wrqu;
1150
1151 memset(&wrqu, 0, sizeof(wrqu));
1152
1153 if (flags > -1)
1154 wrqu.data.flags = flags;
1155
1156 if (pSrcMac)
1157 memcpy(wrqu.ap_addr.sa_data, pSrcMac, MAC_ADDR_LEN);
1158
1159 if ((pData != NULL) && (dataLen > 0))
1160 wrqu.data.length = dataLen;
1161
1162 wireless_send_event(pAd->net_dev, eventType, &wrqu, (char *)pData);
1163 return 0;
1164}
1165
1166int RtmpOSNetDevAddrSet(struct net_device *pNetDev, u8 *pMacAddr)
1167{
1168 struct net_device *net_dev;
1169 struct rt_rtmp_adapter *pAd;
1170
1171 net_dev = pNetDev;
1172 GET_PAD_FROM_NET_DEV(pAd, net_dev);
1173
1174 /* work-around for SuSE, due to them having their own interface name management system. */
1175 {
1176 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
1177 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name,
1178 strlen(net_dev->name));
1179 }
1180
1181 NdisMoveMemory(net_dev->dev_addr, pMacAddr, 6);
1182
1183 return 0;
1184}
1185
1186/*
1187 * Assign the network dev name for created Ralink WiFi interface.
1188 */
1189static int RtmpOSNetDevRequestName(struct rt_rtmp_adapter *pAd,
1190 struct net_device *dev,
1191 char *pPrefixStr, int devIdx)
1192{
1193 struct net_device *existNetDev;
1194 char suffixName[IFNAMSIZ];
1195 char desiredName[IFNAMSIZ];
1196 int ifNameIdx, prefixLen, slotNameLen;
1197 int Status;
1198
1199 prefixLen = strlen(pPrefixStr);
1200 ASSERT((prefixLen < IFNAMSIZ));
1201
1202 for (ifNameIdx = devIdx; ifNameIdx < 32; ifNameIdx++) {
1203 memset(suffixName, 0, IFNAMSIZ);
1204 memset(desiredName, 0, IFNAMSIZ);
1205 strncpy(&desiredName[0], pPrefixStr, prefixLen);
1206
1207 sprintf(suffixName, "%d", ifNameIdx);
1208
1209 slotNameLen = strlen(suffixName);
1210 ASSERT(((slotNameLen + prefixLen) < IFNAMSIZ));
1211 strcat(desiredName, suffixName);
1212
1213 existNetDev = RtmpOSNetDevGetByName(dev, &desiredName[0]);
1214 if (existNetDev == NULL)
1215 break;
1216 else
1217 RtmpOSNetDeviceRefPut(existNetDev);
1218 }
1219
1220 if (ifNameIdx < 32) {
1221 strcpy(&dev->name[0], &desiredName[0]);
1222 Status = NDIS_STATUS_SUCCESS;
1223 } else {
1224 DBGPRINT(RT_DEBUG_ERROR,
1225 ("Cannot request DevName with preifx(%s) and in range(0~32) as suffix from OS!\n",
1226 pPrefixStr));
1227 Status = NDIS_STATUS_FAILURE;
1228 }
1229
1230 return Status;
1231}
1232
1233void RtmpOSNetDevClose(struct net_device *pNetDev)
1234{
1235 dev_close(pNetDev);
1236}
1237
1238void RtmpOSNetDevFree(struct net_device *pNetDev)
1239{
1240 ASSERT(pNetDev);
1241
1242 free_netdev(pNetDev);
1243}
1244
1245int RtmpOSNetDevAlloc(struct net_device **new_dev_p, u32 privDataSize)
1246{
1247 /* assign it as null first. */
1248 *new_dev_p = NULL;
1249
1250 DBGPRINT(RT_DEBUG_TRACE,
1251 ("Allocate a net device with private data size=%d!\n",
1252 privDataSize));
1253 *new_dev_p = alloc_etherdev(privDataSize);
1254 if (*new_dev_p)
1255 return NDIS_STATUS_SUCCESS;
1256 else
1257 return NDIS_STATUS_FAILURE;
1258}
1259
1260struct net_device *RtmpOSNetDevGetByName(struct net_device *pNetDev, char *pDevName)
1261{
1262 struct net_device *pTargetNetDev = NULL;
1263
1264 pTargetNetDev = dev_get_by_name(dev_net(pNetDev), pDevName);
1265
1266 return pTargetNetDev;
1267}
1268
1269void RtmpOSNetDeviceRefPut(struct net_device *pNetDev)
1270{
1271 /*
1272 every time dev_get_by_name is called, and it has returned a valid struct
1273 net_device*, dev_put should be called afterwards, because otherwise the
1274 machine hangs when the device is unregistered (since dev->refcnt > 1).
1275 */
1276 if (pNetDev)
1277 dev_put(pNetDev);
1278}
1279
1280int RtmpOSNetDevDestory(struct rt_rtmp_adapter *pAd, struct net_device *pNetDev)
1281{
1282
1283 /* TODO: Need to fix this */
1284 printk("WARNING: This function(%s) not implement yet!\n", __func__);
1285 return 0;
1286}
1287
1288void RtmpOSNetDevDetach(struct net_device *pNetDev)
1289{
1290 unregister_netdev(pNetDev);
1291}
1292
1293int RtmpOSNetDevAttach(struct net_device *pNetDev,
1294 struct rt_rtmp_os_netdev_op_hook *pDevOpHook)
1295{
1296 int ret, rtnl_locked = FALSE;
1297
1298 DBGPRINT(RT_DEBUG_TRACE, ("RtmpOSNetDevAttach()--->\n"));
1299 /* If we need hook some callback function to the net device structure, now do it. */
1300 if (pDevOpHook) {
1301 struct rt_rtmp_adapter *pAd = NULL;
1302
1303 GET_PAD_FROM_NET_DEV(pAd, pNetDev);
1304
1305 pNetDev->netdev_ops = pDevOpHook->netdev_ops;
1306
1307 /* OS specific flags, here we used to indicate if we are virtual interface */
1308 pNetDev->priv_flags = pDevOpHook->priv_flags;
1309
1310 if (pAd->OpMode == OPMODE_STA)
1311 pNetDev->wireless_handlers = &rt28xx_iw_handler_def;
1312
1313 /* copy the net device mac address to the net_device structure. */
1314 NdisMoveMemory(pNetDev->dev_addr, &pDevOpHook->devAddr[0],
1315 MAC_ADDR_LEN);
1316
1317 rtnl_locked = pDevOpHook->needProtcted;
1318 }
1319
1320 if (rtnl_locked)
1321 ret = register_netdevice(pNetDev);
1322 else
1323 ret = register_netdev(pNetDev);
1324
1325 DBGPRINT(RT_DEBUG_TRACE, ("<---RtmpOSNetDevAttach(), ret=%d\n", ret));
1326 if (ret == 0)
1327 return NDIS_STATUS_SUCCESS;
1328 else
1329 return NDIS_STATUS_FAILURE;
1330}
1331
1332struct net_device *RtmpOSNetDevCreate(struct rt_rtmp_adapter *pAd,
1333 int devType,
1334 int devNum,
1335 int privMemSize, char *pNamePrefix)
1336{
1337 struct net_device *pNetDev = NULL;
1338 int status;
1339
1340 /* allocate a new network device */
1341 status = RtmpOSNetDevAlloc(&pNetDev, 0 /*privMemSize */);
1342 if (status != NDIS_STATUS_SUCCESS) {
1343 /* allocation fail, exit */
1344 DBGPRINT(RT_DEBUG_ERROR,
1345 ("Allocate network device fail (%s)...\n",
1346 pNamePrefix));
1347 return NULL;
1348 }
1349
1350 /* find an available interface name, max 32 interfaces */
1351 status = RtmpOSNetDevRequestName(pAd, pNetDev, pNamePrefix, devNum);
1352 if (status != NDIS_STATUS_SUCCESS) {
1353 /* error! no available ra name can be used! */
1354 DBGPRINT(RT_DEBUG_ERROR,
1355 ("Assign interface name (%s with suffix 0~32) failed...\n",
1356 pNamePrefix));
1357 RtmpOSNetDevFree(pNetDev);
1358
1359 return NULL;
1360 } else {
1361 DBGPRINT(RT_DEBUG_TRACE,
1362 ("The name of the new %s interface is %s...\n",
1363 pNamePrefix, pNetDev->name));
1364 }
1365
1366 return pNetDev;
1367}
diff --git a/drivers/staging/rt2860/rt_linux.h b/drivers/staging/rt2860/rt_linux.h
deleted file mode 100644
index 3efb88fdffc..00000000000
--- a/drivers/staging/rt2860/rt_linux.h
+++ /dev/null
@@ -1,835 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt_linux.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 Justin P. Mattock 11/07/2010 Fix typo in a comment
35 --------- ---------- ----------------------------------------------
36*/
37
38#ifndef __RT_LINUX_H__
39#define __RT_LINUX_H__
40
41#include <linux/module.h>
42#include <linux/kernel.h>
43#include <linux/spinlock.h>
44#include <linux/init.h>
45#include <linux/string.h>
46#include <linux/timer.h>
47#include <linux/errno.h>
48#include <linux/slab.h>
49#include <linux/interrupt.h>
50#include <linux/pci.h>
51#include <linux/netdevice.h>
52#include <linux/etherdevice.h>
53#include <linux/skbuff.h>
54#include <linux/ethtool.h>
55#include <linux/wireless.h>
56#include <linux/proc_fs.h>
57#include <linux/delay.h>
58#include <linux/if_arp.h>
59#include <linux/ctype.h>
60#include <linux/vmalloc.h>
61
62#include <net/iw_handler.h>
63
64/* load firmware */
65#define __KERNEL_SYSCALLS__
66#include <linux/unistd.h>
67#include <asm/uaccess.h>
68#include <asm/types.h>
69#include <asm/unaligned.h> /* for get_unaligned() */
70
71#define KTHREAD_SUPPORT 1
72/* RT2870 2.1.0.0 has it disabled */
73
74#ifdef KTHREAD_SUPPORT
75#include <linux/err.h>
76#include <linux/kthread.h>
77#endif /* KTHREAD_SUPPORT // */
78
79/***********************************************************************************
80 * Profile related sections
81 ***********************************************************************************/
82
83#ifdef RTMP_MAC_PCI
84#define STA_DRIVER_VERSION "2.1.0.0"
85#endif /* RTMP_MAC_PCI // */
86#ifdef RTMP_MAC_USB
87#define STA_DRIVER_VERSION "2.1.0.0"
88/* RT3070 version: 2.1.1.0 */
89#endif /* RTMP_MAC_USB // */
90
91extern const struct iw_handler_def rt28xx_iw_handler_def;
92
93/***********************************************************************************
94 * Compiler related definitions
95 ***********************************************************************************/
96#undef __inline
97#define __inline static inline
98#define IN
99#define OUT
100#define INOUT
101
102/***********************************************************************************
103 * OS Specific definitions and data structures
104 ***********************************************************************************/
105typedef int (*HARD_START_XMIT_FUNC) (struct sk_buff *skb,
106 struct net_device *net_dev);
107
108#ifdef RTMP_MAC_PCI
109#ifndef PCI_DEVICE
110#define PCI_DEVICE(vend,dev) \
111 .vendor = (vend), .device = (dev), \
112 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
113#endif /* PCI_DEVICE // */
114#endif /* RTMP_MAC_PCI // */
115
116#define RT_MOD_INC_USE_COUNT() \
117 if (!try_module_get(THIS_MODULE)) \
118 { \
119 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
120 return -1; \
121 }
122
123#define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
124
125#define RTMP_INC_REF(_A) 0
126#define RTMP_DEC_REF(_A) 0
127#define RTMP_GET_REF(_A) 0
128
129/* This function will be called when query /proc */
130struct iw_statistics *rt28xx_get_wireless_stats(IN struct net_device *net_dev);
131
132/***********************************************************************************
133 * Network related constant definitions
134 ***********************************************************************************/
135#ifndef IFNAMSIZ
136#define IFNAMSIZ 16
137#endif
138
139#define ETH_LENGTH_OF_ADDRESS 6
140
141#define NDIS_STATUS_SUCCESS 0x00
142#define NDIS_STATUS_FAILURE 0x01
143#define NDIS_STATUS_INVALID_DATA 0x02
144#define NDIS_STATUS_RESOURCES 0x03
145
146#define NDIS_SET_PACKET_STATUS(_p, _status) do{} while(0)
147#define NdisWriteErrorLogEntry(_a, _b, _c, _d) do{} while(0)
148
149/* statistics counter */
150#define STATS_INC_RX_PACKETS(_pAd, _dev)
151#define STATS_INC_TX_PACKETS(_pAd, _dev)
152
153#define STATS_INC_RX_BYTESS(_pAd, _dev, len)
154#define STATS_INC_TX_BYTESS(_pAd, _dev, len)
155
156#define STATS_INC_RX_ERRORS(_pAd, _dev)
157#define STATS_INC_TX_ERRORS(_pAd, _dev)
158
159#define STATS_INC_RX_DROPPED(_pAd, _dev)
160#define STATS_INC_TX_DROPPED(_pAd, _dev)
161
162/***********************************************************************************
163 * Ralink Specific network related constant definitions
164 ***********************************************************************************/
165#define MIN_NET_DEVICE_FOR_AID 0x00 /*0x00~0x3f */
166#define MIN_NET_DEVICE_FOR_MBSSID 0x00 /*0x00,0x10,0x20,0x30 */
167#define MIN_NET_DEVICE_FOR_WDS 0x10 /*0x40,0x50,0x60,0x70 */
168#define MIN_NET_DEVICE_FOR_APCLI 0x20
169#define MIN_NET_DEVICE_FOR_MESH 0x30
170#define MIN_NET_DEVICE_FOR_DLS 0x40
171#define NET_DEVICE_REAL_IDX_MASK 0x0f /* for each operation mode, we maximum support 15 entities. */
172
173#define NDIS_PACKET_TYPE_DIRECTED 0
174#define NDIS_PACKET_TYPE_MULTICAST 1
175#define NDIS_PACKET_TYPE_BROADCAST 2
176#define NDIS_PACKET_TYPE_ALL_MULTICAST 3
177#define NDIS_PACKET_TYPE_PROMISCUOUS 4
178
179/***********************************************************************************
180 * OS signaling related constant definitions
181 ***********************************************************************************/
182
183/***********************************************************************************
184 * OS file operation related data structure definitions
185 ***********************************************************************************/
186struct rt_rtmp_os_fs_info {
187 int fsuid;
188 int fsgid;
189 mm_segment_t fs;
190};
191
192#define IS_FILE_OPEN_ERR(_fd) IS_ERR((_fd))
193
194/***********************************************************************************
195 * OS semaphore related data structure and definitions
196 ***********************************************************************************/
197struct os_lock {
198 spinlock_t lock;
199 unsigned long flags;
200};
201
202/* */
203/* spin_lock enhanced for Nested spin lock */
204/* */
205#define NdisAllocateSpinLock(__lock) \
206{ \
207 spin_lock_init((spinlock_t *)(__lock)); \
208}
209
210#define NdisFreeSpinLock(lock) \
211 do{}while(0)
212
213#define RTMP_SEM_LOCK(__lock) \
214{ \
215 spin_lock_bh((spinlock_t *)(__lock)); \
216}
217
218#define RTMP_SEM_UNLOCK(__lock) \
219{ \
220 spin_unlock_bh((spinlock_t *)(__lock)); \
221}
222
223/* sample, use semaphore lock to replace IRQ lock, 2007/11/15 */
224#define RTMP_IRQ_LOCK(__lock, __irqflags) \
225{ \
226 __irqflags = 0; \
227 spin_lock_bh((spinlock_t *)(__lock)); \
228 pAd->irq_disabled |= 1; \
229}
230
231#define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
232{ \
233 pAd->irq_disabled &= 0; \
234 spin_unlock_bh((spinlock_t *)(__lock)); \
235}
236
237#define RTMP_INT_LOCK(__lock, __irqflags) \
238{ \
239 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
240}
241
242#define RTMP_INT_UNLOCK(__lock, __irqflag) \
243{ \
244 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
245}
246
247#define NdisAcquireSpinLock RTMP_SEM_LOCK
248#define NdisReleaseSpinLock RTMP_SEM_UNLOCK
249
250#ifndef wait_event_interruptible_timeout
251#define __wait_event_interruptible_timeout(wq, condition, ret) \
252do { \
253 wait_queue_t __wait; \
254 init_waitqueue_entry(&__wait, current); \
255 add_wait_queue(&wq, &__wait); \
256 for (;;) { \
257 set_current_state(TASK_INTERRUPTIBLE); \
258 if (condition) \
259 break; \
260 if (!signal_pending(current)) { \
261 ret = schedule_timeout(ret); \
262 if (!ret) \
263 break; \
264 continue; \
265 } \
266 ret = -ERESTARTSYS; \
267 break; \
268 } \
269 current->state = TASK_RUNNING; \
270 remove_wait_queue(&wq, &__wait); \
271} while (0)
272
273#define wait_event_interruptible_timeout(wq, condition, timeout) \
274({ \
275 long __ret = timeout; \
276 if (!(condition)) \
277 __wait_event_interruptible_timeout(wq, condition, __ret); \
278 __ret; \
279})
280#endif
281
282#define RTMP_SEM_EVENT_INIT_LOCKED(_pSema) sema_init((_pSema), 0)
283#define RTMP_SEM_EVENT_INIT(_pSema) sema_init((_pSema), 1)
284#define RTMP_SEM_EVENT_WAIT(_pSema, _status) ((_status) = down_interruptible((_pSema)))
285#define RTMP_SEM_EVENT_UP(_pSema) up(_pSema)
286
287#ifdef KTHREAD_SUPPORT
288#define RTMP_WAIT_EVENT_INTERRUPTIBLE(_pAd, _pTask) \
289{ \
290 wait_event_interruptible(_pTask->kthread_q, \
291 _pTask->kthread_running || kthread_should_stop()); \
292 _pTask->kthread_running = FALSE; \
293 if (kthread_should_stop()) \
294 { \
295 RTMP_SET_FLAG(_pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); \
296 break; \
297 } \
298}
299#endif
300
301#ifdef KTHREAD_SUPPORT
302#define WAKE_UP(_pTask) \
303 do{ \
304 if ((_pTask)->kthread_task) \
305 { \
306 (_pTask)->kthread_running = TRUE; \
307 wake_up(&(_pTask)->kthread_q); \
308 } \
309 }while(0)
310#endif
311
312/***********************************************************************************
313 * OS Memory Access related data structure and definitions
314 ***********************************************************************************/
315#define MEM_ALLOC_FLAG (GFP_ATOMIC) /*(GFP_DMA | GFP_ATOMIC) */
316
317#define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
318#define NdisCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
319#define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
320#define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
321#define NdisCmpMemory(Destination, Source, Length) memcmp(Destination, Source, Length)
322#define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
323#define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
324
325#define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
326#define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
327
328#define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
329
330/***********************************************************************************
331 * OS task related data structure and definitions
332 ***********************************************************************************/
333#define RTMP_OS_MGMT_TASK_FLAGS CLONE_VM
334
335#define THREAD_PID_INIT_VALUE NULL
336#define GET_PID(_v) find_get_pid((_v))
337#define GET_PID_NUMBER(_v) pid_nr((_v))
338#define CHECK_PID_LEGALITY(_pid) if (pid_nr((_pid)) > 0)
339#define KILL_THREAD_PID(_A, _B, _C) kill_pid((_A), (_B), (_C))
340
341/***********************************************************************************
342 * Timer related definitions and data structures.
343 **********************************************************************************/
344#define OS_HZ HZ
345
346typedef void (*TIMER_FUNCTION) (unsigned long);
347
348#define OS_WAIT(_time) \
349{ int _i; \
350 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
351 wait_queue_head_t _wait; \
352 init_waitqueue_head(&_wait); \
353 for (_i=0; _i<(_loop); _i++) \
354 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
355
356#define RTMP_TIME_AFTER(a,b) \
357 (typecheck(unsigned long, (unsigned long)a) && \
358 typecheck(unsigned long, (unsigned long)b) && \
359 ((long)(b) - (long)(a) < 0))
360
361#define RTMP_TIME_AFTER_EQ(a,b) \
362 (typecheck(unsigned long, (unsigned long)a) && \
363 typecheck(unsigned long, (unsigned long)b) && \
364 ((long)(a) - (long)(b) >= 0))
365#define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
366
367#define ONE_TICK 1
368
369static inline void NdisGetSystemUpTime(unsigned long *time)
370{
371 *time = jiffies;
372}
373
374/***********************************************************************************
375 * OS specific cookie data structure binding to struct rt_rtmp_adapter
376 ***********************************************************************************/
377
378struct os_cookie {
379#ifdef RTMP_MAC_PCI
380 struct pci_dev *pci_dev;
381 struct pci_dev *parent_pci_dev;
382 u16 DeviceID;
383 dma_addr_t pAd_pa;
384#endif /* RTMP_MAC_PCI // */
385#ifdef RTMP_MAC_USB
386 struct usb_device *pUsb_Dev;
387#endif /* RTMP_MAC_USB // */
388
389 struct tasklet_struct rx_done_task;
390 struct tasklet_struct mgmt_dma_done_task;
391 struct tasklet_struct ac0_dma_done_task;
392 struct tasklet_struct ac1_dma_done_task;
393 struct tasklet_struct ac2_dma_done_task;
394 struct tasklet_struct ac3_dma_done_task;
395 struct tasklet_struct tbtt_task;
396#ifdef RTMP_MAC_PCI
397 struct tasklet_struct fifo_statistic_full_task;
398#endif /* RTMP_MAC_PCI // */
399#ifdef RTMP_MAC_USB
400 struct tasklet_struct null_frame_complete_task;
401 struct tasklet_struct rts_frame_complete_task;
402 struct tasklet_struct pspoll_frame_complete_task;
403#endif /* RTMP_MAC_USB // */
404
405 unsigned long apd_pid; /*802.1x daemon pid */
406 int ioctl_if_type;
407 int ioctl_if;
408};
409
410/***********************************************************************************
411 * OS debugging and printing related definitions and data structure
412 ***********************************************************************************/
413#ifdef DBG
414extern unsigned long RTDebugLevel;
415
416#define DBGPRINT_RAW(Level, Fmt) \
417do{ \
418 if (Level <= RTDebugLevel) \
419 { \
420 printk Fmt; \
421 } \
422}while(0)
423
424#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
425
426#define DBGPRINT_ERR(fmt, args...) printk(KERN_ERR fmt, ##args)
427
428#define DBGPRINT_S(Status, Fmt) \
429{ \
430 printk Fmt; \
431}
432
433#else
434#define DBGPRINT(Level, Fmt)
435#define DBGPRINT_RAW(Level, Fmt)
436#define DBGPRINT_S(Status, Fmt)
437#define DBGPRINT_ERR(Fmt)
438#endif
439
440#define ASSERT(x)
441
442void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
443
444/*********************************************************************************************************
445 The following code are not revised, temporary put it here.
446 *********************************************************************************************************/
447
448/***********************************************************************************
449 * Device DMA Access related definitions and data structures.
450 **********************************************************************************/
451#ifdef RTMP_MAC_PCI
452struct rt_rtmp_adapter;
453dma_addr_t linux_pci_map_single(struct rt_rtmp_adapter *pAd, void *ptr,
454 size_t size, int sd_idx, int direction);
455void linux_pci_unmap_single(struct rt_rtmp_adapter *pAd, dma_addr_t dma_addr,
456 size_t size, int direction);
457
458#define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
459 linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
460
461#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
462 linux_pci_unmap_single(_handle, _ptr, _size, _dir)
463
464#define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
465 pci_alloc_consistent(_pci_dev, _size, _ptr)
466
467#define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
468 pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
469
470#define DEV_ALLOC_SKB(_length) \
471 dev_alloc_skb(_length)
472#endif /* RTMP_MAC_PCI // */
473
474/*
475 * unsigned long
476 * RTMP_GetPhysicalAddressLow(
477 * dma_addr_t PhysicalAddress);
478 */
479#define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
480
481/*
482 * unsigned long
483 * RTMP_GetPhysicalAddressHigh(
484 * dma_addr_t PhysicalAddress);
485 */
486#define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
487
488/*
489 * void
490 * RTMP_SetPhysicalAddressLow(
491 * dma_addr_t PhysicalAddress,
492 * unsigned long Value);
493 */
494#define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
495 PhysicalAddress = Value;
496
497/*
498 * void
499 * RTMP_SetPhysicalAddressHigh(
500 * dma_addr_t PhysicalAddress,
501 * unsigned long Value);
502 */
503#define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
504
505#define NdisMIndicateStatus(_w, _x, _y, _z)
506
507/***********************************************************************************
508 * Device Register I/O Access related definitions and data structures.
509 **********************************************************************************/
510#ifdef RTMP_MAC_PCI
511/*Patch for ASIC turst read/write bug, needs to remove after metel fix */
512#define RTMP_IO_READ32(_A, _R, _pV) \
513{ \
514 if ((_A)->bPCIclkOff == FALSE) \
515 { \
516 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
517 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
518 } \
519 else \
520 *_pV = 0; \
521}
522
523#define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
524{ \
525 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
526 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
527}
528
529#define RTMP_IO_READ8(_A, _R, _pV) \
530{ \
531 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
532 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
533}
534#define RTMP_IO_WRITE32(_A, _R, _V) \
535{ \
536 if ((_A)->bPCIclkOff == FALSE) \
537 { \
538 u32 Val; \
539 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
540 writel((_V), (void *)((_A)->CSRBaseAddress + (_R))); \
541 } \
542}
543
544#define RTMP_IO_FORCE_WRITE32(_A, _R, _V) \
545{ \
546 u32 Val; \
547 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
548 writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \
549}
550
551#if defined(RALINK_2880) || defined(RALINK_3052)
552#define RTMP_IO_WRITE8(_A, _R, _V) \
553{ \
554 unsigned long Val; \
555 u8 _i; \
556 _i = ((_R) & 0x3); \
557 Val = readl((void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
558 Val = Val & (~(0x000000ff << ((_i)*8))); \
559 Val = Val | ((unsigned long)(_V) << ((_i)*8)); \
560 writel((Val), (void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
561}
562#else
563#define RTMP_IO_WRITE8(_A, _R, _V) \
564{ \
565 u32 Val; \
566 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
567 writeb((_V), (u8 *)((_A)->CSRBaseAddress + (_R))); \
568}
569#endif /* #if defined(BRCM_6358) || defined(RALINK_2880) // */
570
571#define RTMP_IO_WRITE16(_A, _R, _V) \
572{ \
573 u32 Val; \
574 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
575 writew((_V), (u16 *)((_A)->CSRBaseAddress + (_R))); \
576}
577#endif /* RTMP_MAC_PCI // */
578#ifdef RTMP_MAC_USB
579/*Patch for ASIC turst read/write bug, needs to remove after metel fix */
580#define RTMP_IO_READ32(_A, _R, _pV) \
581 RTUSBReadMACRegister((_A), (_R), (u32 *)(_pV))
582
583#define RTMP_IO_READ8(_A, _R, _pV) \
584{ \
585}
586
587#define RTMP_IO_WRITE32(_A, _R, _V) \
588 RTUSBWriteMACRegister((_A), (_R), (u32)(_V))
589
590#define RTMP_IO_WRITE8(_A, _R, _V) \
591{ \
592 u16 _Val = _V; \
593 RTUSBSingleWrite((_A), (_R), (u16)(_Val)); \
594}
595
596#define RTMP_IO_WRITE16(_A, _R, _V) \
597{ \
598 RTUSBSingleWrite((_A), (_R), (u16)(_V)); \
599}
600#endif /* RTMP_MAC_USB // */
601
602/***********************************************************************************
603 * Network Related data structure and marco definitions
604 ***********************************************************************************/
605#define PKTSRC_NDIS 0x7f
606#define PKTSRC_DRIVER 0x0f
607
608#define RTMP_OS_NETDEV_SET_PRIV(_pNetDev, _pPriv) ((_pNetDev)->ml_priv = (_pPriv))
609#define RTMP_OS_NETDEV_GET_PRIV(_pNetDev) ((_pNetDev)->ml_priv)
610#define RTMP_OS_NETDEV_GET_DEVNAME(_pNetDev) ((_pNetDev)->name)
611#define RTMP_OS_NETDEV_GET_PHYADDR(_PNETDEV) ((_PNETDEV)->dev_addr)
612
613#define RTMP_OS_NETDEV_START_QUEUE(_pNetDev) netif_start_queue((_pNetDev))
614#define RTMP_OS_NETDEV_STOP_QUEUE(_pNetDev) netif_stop_queue((_pNetDev))
615#define RTMP_OS_NETDEV_WAKE_QUEUE(_pNetDev) netif_wake_queue((_pNetDev))
616#define RTMP_OS_NETDEV_CARRIER_OFF(_pNetDev) netif_carrier_off((_pNetDev))
617
618#define QUEUE_ENTRY_TO_PACKET(pEntry) \
619 (void *)(pEntry)
620
621#define PACKET_TO_QUEUE_ENTRY(pPacket) \
622 (struct rt_queue_entry *)(pPacket)
623
624#define GET_SG_LIST_FROM_PACKET(_p, _sc) \
625 rt_get_sg_list_from_packet(_p, _sc)
626
627#define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
628{ \
629 RTMPFreeNdisPacket(_pAd, _pPacket); \
630}
631
632/*
633 * packet helper
634 * - convert internal rt packet to os packet or
635 * os packet to rt packet
636 */
637#define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
638#define OSPKT_TO_RTPKT(_p) ((void *)(_p))
639
640#define GET_OS_PKT_DATAPTR(_pkt) \
641 (RTPKT_TO_OSPKT(_pkt)->data)
642#define SET_OS_PKT_DATAPTR(_pkt, _dataPtr) \
643 (RTPKT_TO_OSPKT(_pkt)->data) = (_dataPtr)
644
645#define GET_OS_PKT_LEN(_pkt) \
646 (RTPKT_TO_OSPKT(_pkt)->len)
647#define SET_OS_PKT_LEN(_pkt, _len) \
648 (RTPKT_TO_OSPKT(_pkt)->len) = (_len)
649
650#define GET_OS_PKT_DATATAIL(_pkt) \
651 (skb_tail_pointer(RTPKT_TO_OSPKT(_pkt))
652#define SET_OS_PKT_DATATAIL(_pkt, _start, _len) \
653 (skb_set_tail_pointer(RTPKT_TO_OSPKT(_pkt), _len))
654
655#define GET_OS_PKT_HEAD(_pkt) \
656 (RTPKT_TO_OSPKT(_pkt)->head)
657
658#define GET_OS_PKT_END(_pkt) \
659 (RTPKT_TO_OSPKT(_pkt)->end)
660
661#define GET_OS_PKT_NETDEV(_pkt) \
662 (RTPKT_TO_OSPKT(_pkt)->dev)
663#define SET_OS_PKT_NETDEV(_pkt, _pNetDev) \
664 (RTPKT_TO_OSPKT(_pkt)->dev) = (_pNetDev)
665
666#define GET_OS_PKT_TYPE(_pkt) \
667 (RTPKT_TO_OSPKT(_pkt))
668
669#define GET_OS_PKT_NEXT(_pkt) \
670 (RTPKT_TO_OSPKT(_pkt)->next)
671
672#define OS_PKT_CLONED(_pkt) skb_cloned(RTPKT_TO_OSPKT(_pkt))
673
674#define OS_NTOHS(_Val) \
675 (ntohs(_Val))
676#define OS_HTONS(_Val) \
677 (htons(_Val))
678#define OS_NTOHL(_Val) \
679 (ntohl(_Val))
680#define OS_HTONL(_Val) \
681 (htonl(_Val))
682
683#define CB_OFF 10
684
685/* User Priority */
686#define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
687#define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
688
689/* Fragment # */
690#define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
691#define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
692
693/* 0x0 ~0x7f: TX to AP's own BSS which has the specified AID. if AID>127, set bit 7 in RTMP_SET_PACKET_EMACTAB too. */
694/*(this value also as MAC(on-chip WCID) table index) */
695/* 0x80~0xff: TX to a WDS link. b0~6: WDS index */
696#define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
697#define RTMP_GET_PACKET_WCID(_p) ((u8)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
698
699/* 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet */
700#define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
701#define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
702
703/* RTS/CTS-to-self protection method */
704#define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
705#define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
706/* see RTMP_S(G)ET_PACKET_EMACTAB */
707
708/* TX rate index */
709#define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
710#define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
711
712/* From which Interface */
713#define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
714#define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
715#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
716#define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
717#define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
718#define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
719#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
720#define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
721
722#define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
723#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
724
725/* */
726/* Specific Packet Type definition */
727/* */
728#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
729
730#define RTMP_PACKET_SPECIFIC_DHCP 0x01
731#define RTMP_PACKET_SPECIFIC_EAPOL 0x02
732#define RTMP_PACKET_SPECIFIC_IPV4 0x04
733#define RTMP_PACKET_SPECIFIC_WAI 0x08
734#define RTMP_PACKET_SPECIFIC_VLAN 0x10
735#define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
736
737/*Specific */
738#define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
739
740/*DHCP */
741#define RTMP_SET_PACKET_DHCP(_p, _flg) \
742 do{ \
743 if (_flg) \
744 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
745 else \
746 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
747 }while(0)
748#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
749
750/*EAPOL */
751#define RTMP_SET_PACKET_EAPOL(_p, _flg) \
752 do{ \
753 if (_flg) \
754 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
755 else \
756 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
757 }while(0)
758#define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
759
760/*WAI */
761#define RTMP_SET_PACKET_WAI(_p, _flg) \
762 do{ \
763 if (_flg) \
764 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
765 else \
766 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
767 }while(0)
768#define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
769
770#define RTMP_GET_PACKET_LOWRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & (RTMP_PACKET_SPECIFIC_EAPOL | RTMP_PACKET_SPECIFIC_DHCP | RTMP_PACKET_SPECIFIC_WAI))
771
772/*VLAN */
773#define RTMP_SET_PACKET_VLAN(_p, _flg) \
774 do{ \
775 if (_flg) \
776 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
777 else \
778 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
779 }while(0)
780#define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
781
782/*LLC/SNAP */
783#define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
784 do{ \
785 if (_flg) \
786 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
787 else \
788 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
789 }while(0)
790
791#define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
792
793/* IP */
794#define RTMP_SET_PACKET_IPV4(_p, _flg) \
795 do{ \
796 if (_flg) \
797 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
798 else \
799 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
800 }while(0)
801
802#define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
803
804/* If this flag is set, it indicates that this EAPoL frame MUST be clear. */
805#define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
806#define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
807
808/* use bit3 of cb[CB_OFF+16] */
809
810#define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
811#define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
812
813/* Max skb->cb = 48B = [CB_OFF+38] */
814
815/***********************************************************************************
816 * Other function prototypes definitions
817 ***********************************************************************************/
818void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
819int rt28xx_packet_xmit(struct sk_buff *skb);
820
821#ifdef RTMP_MAC_PCI
822/* function declarations */
823#define IRQ_HANDLE_TYPE irqreturn_t
824
825IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance);
826#endif /* RTMP_MAC_PCI // */
827
828int rt28xx_sta_ioctl(struct net_device *net_dev, IN OUT struct ifreq *rq, int cmd);
829
830extern int ra_mtd_write(int num, loff_t to, size_t len, const u_char *buf);
831extern int ra_mtd_read(int num, loff_t from, size_t len, u_char *buf);
832
833#define GET_PAD_FROM_NET_DEV(_pAd, _net_dev) (_pAd) = (struct rt_rtmp_adapter *)(_net_dev)->ml_priv;
834
835#endif /* __RT_LINUX_H__ // */
diff --git a/drivers/staging/rt2860/rt_main_dev.c b/drivers/staging/rt2860/rt_main_dev.c
deleted file mode 100644
index 236dd36d349..00000000000
--- a/drivers/staging/rt2860/rt_main_dev.c
+++ /dev/null
@@ -1,736 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt_main_dev.c
29
30 Abstract:
31 Create and register network interface.
32
33 Revision History:
34 Who When What
35 Justin P. Mattock 11/07/2010 Fix typos in comments
36 -------- ---------- ----------------------------------------------
37*/
38
39#include "rt_config.h"
40
41/*---------------------------------------------------------------------*/
42/* Private Variables Used */
43/*---------------------------------------------------------------------*/
44
45char *mac = ""; /* default 00:00:00:00:00:00 */
46char *hostname = ""; /* default CMPC */
47module_param(mac, charp, 0);
48MODULE_PARM_DESC(mac, "rt28xx: wireless mac addr");
49
50/*---------------------------------------------------------------------*/
51/* Prototypes of Functions Used */
52/*---------------------------------------------------------------------*/
53
54/* public function prototype */
55int rt28xx_close(IN struct net_device *net_dev);
56int rt28xx_open(struct net_device *net_dev);
57
58/* private function prototype */
59static int rt28xx_send_packets(IN struct sk_buff *skb_p,
60 IN struct net_device *net_dev);
61
62static struct net_device_stats *RT28xx_get_ether_stats(IN struct net_device
63 *net_dev);
64
65/*
66========================================================================
67Routine Description:
68 Close raxx interface.
69
70Arguments:
71 *net_dev the raxx interface pointer
72
73Return Value:
74 0 Open OK
75 otherwise Open Fail
76
77Note:
78 1. if open fail, kernel will not call the close function.
79 2. Free memory for
80 (1) Mlme Memory Handler: MlmeHalt()
81 (2) TX & RX: RTMPFreeTxRxRingMemory()
82 (3) BA Reordering: ba_reordering_resource_release()
83========================================================================
84*/
85int MainVirtualIF_close(IN struct net_device *net_dev)
86{
87 struct rt_rtmp_adapter *pAd = NULL;
88
89 GET_PAD_FROM_NET_DEV(pAd, net_dev);
90
91 /* Sanity check for pAd */
92 if (pAd == NULL)
93 return 0; /* close ok */
94
95 netif_carrier_off(pAd->net_dev);
96 netif_stop_queue(pAd->net_dev);
97
98 {
99 BOOLEAN Cancelled;
100
101 if (INFRA_ON(pAd) &&
102 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
103 struct rt_mlme_disassoc_req DisReq;
104 struct rt_mlme_queue_elem *MsgElem =
105 kmalloc(sizeof(struct rt_mlme_queue_elem),
106 MEM_ALLOC_FLAG);
107
108 if (MsgElem) {
109 COPY_MAC_ADDR(DisReq.Addr,
110 pAd->CommonCfg.Bssid);
111 DisReq.Reason = REASON_DEAUTH_STA_LEAVING;
112
113 MsgElem->Machine = ASSOC_STATE_MACHINE;
114 MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
115 MsgElem->MsgLen =
116 sizeof(struct rt_mlme_disassoc_req);
117 NdisMoveMemory(MsgElem->Msg, &DisReq,
118 sizeof
119 (struct rt_mlme_disassoc_req));
120
121 /* Prevent to connect AP again in STAMlmePeriodicExec */
122 pAd->MlmeAux.AutoReconnectSsidLen = 32;
123 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid,
124 pAd->MlmeAux.
125 AutoReconnectSsidLen);
126
127 pAd->Mlme.CntlMachine.CurrState =
128 CNTL_WAIT_OID_DISASSOC;
129 MlmeDisassocReqAction(pAd, MsgElem);
130 kfree(MsgElem);
131 }
132
133 RTMPusecDelay(1000);
134 }
135
136 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer,
137 &Cancelled);
138 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer,
139 &Cancelled);
140 }
141
142 VIRTUAL_IF_DOWN(pAd);
143
144 RT_MOD_DEC_USE_COUNT();
145
146 return 0; /* close ok */
147}
148
149/*
150========================================================================
151Routine Description:
152 Open raxx interface.
153
154Arguments:
155 *net_dev the raxx interface pointer
156
157Return Value:
158 0 Open OK
159 otherwise Open Fail
160
161Note:
162 1. if open fail, kernel will not call the close function.
163 2. Free memory for
164 (1) Mlme Memory Handler: MlmeHalt()
165 (2) TX & RX: RTMPFreeTxRxRingMemory()
166 (3) BA Reordering: ba_reordering_resource_release()
167========================================================================
168*/
169int MainVirtualIF_open(IN struct net_device *net_dev)
170{
171 struct rt_rtmp_adapter *pAd = NULL;
172
173 GET_PAD_FROM_NET_DEV(pAd, net_dev);
174
175 /* Sanity check for pAd */
176 if (pAd == NULL)
177 return 0; /* close ok */
178
179 if (VIRTUAL_IF_UP(pAd) != 0)
180 return -1;
181
182 /* increase MODULE use count */
183 RT_MOD_INC_USE_COUNT();
184
185 netif_start_queue(net_dev);
186 netif_carrier_on(net_dev);
187 netif_wake_queue(net_dev);
188
189 return 0;
190}
191
192/*
193========================================================================
194Routine Description:
195 Close raxx interface.
196
197Arguments:
198 *net_dev the raxx interface pointer
199
200Return Value:
201 0 Open OK
202 otherwise Open Fail
203
204Note:
205 1. if open fail, kernel will not call the close function.
206 2. Free memory for
207 (1) Mlme Memory Handler: MlmeHalt()
208 (2) TX & RX: RTMPFreeTxRxRingMemory()
209 (3) BA Reordering: ba_reordering_resource_release()
210========================================================================
211*/
212int rt28xx_close(struct net_device *dev)
213{
214 struct net_device *net_dev = (struct net_device *)dev;
215 struct rt_rtmp_adapter *pAd = NULL;
216 BOOLEAN Cancelled;
217 u32 i = 0;
218
219#ifdef RTMP_MAC_USB
220 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup);
221 DECLARE_WAITQUEUE(wait, current);
222#endif /* RTMP_MAC_USB // */
223
224 GET_PAD_FROM_NET_DEV(pAd, net_dev);
225
226 DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
227
228 Cancelled = FALSE;
229 /* Sanity check for pAd */
230 if (pAd == NULL)
231 return 0; /* close ok */
232
233 {
234#ifdef RTMP_MAC_PCI
235 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_CLOSE);
236#endif /* RTMP_MAC_PCI // */
237
238 /* If driver doesn't wake up firmware here, */
239 /* NICLoadFirmware will hang forever when interface is up again. */
240 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) {
241 AsicForceWakeup(pAd, TRUE);
242 }
243#ifdef RTMP_MAC_USB
244 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
245#endif /* RTMP_MAC_USB // */
246
247 MlmeRadioOff(pAd);
248#ifdef RTMP_MAC_PCI
249 pAd->bPCIclkOff = FALSE;
250#endif /* RTMP_MAC_PCI // */
251 }
252
253 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
254
255 for (i = 0; i < NUM_OF_TX_RING; i++) {
256 while (pAd->DeQueueRunning[i] == TRUE) {
257 DBGPRINT(RT_DEBUG_TRACE,
258 ("Waiting for TxQueue[%d] done..........\n",
259 i));
260 RTMPusecDelay(1000);
261 }
262 }
263
264#ifdef RTMP_MAC_USB
265 /* ensure there are no more active urbs. */
266 add_wait_queue(&unlink_wakeup, &wait);
267 pAd->wait = &unlink_wakeup;
268
269 /* maybe wait for deletions to finish. */
270 i = 0;
271 /*while((i < 25) && atomic_read(&pAd->PendingRx) > 0) */
272 while (i < 25) {
273 unsigned long IrqFlags;
274
275 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
276 if (pAd->PendingRx == 0) {
277 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
278 break;
279 }
280 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
281
282 msleep(UNLINK_TIMEOUT_MS); /*Time in millisecond */
283 i++;
284 }
285 pAd->wait = NULL;
286 remove_wait_queue(&unlink_wakeup, &wait);
287#endif /* RTMP_MAC_USB // */
288
289 /* Stop Mlme state machine */
290 MlmeHalt(pAd);
291
292 /* Close net tasklets */
293 RtmpNetTaskExit(pAd);
294
295 {
296 MacTableReset(pAd);
297 }
298
299 MeasureReqTabExit(pAd);
300 TpcReqTabExit(pAd);
301
302 /* Close kernel threads */
303 RtmpMgmtTaskExit(pAd);
304
305#ifdef RTMP_MAC_PCI
306 {
307 BOOLEAN brc;
308 /* unsigned long Value; */
309
310 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE)) {
311 RTMP_ASIC_INTERRUPT_DISABLE(pAd);
312 }
313 /* Receive packets to clear DMA index after disable interrupt. */
314 /* RTMPHandleRxDoneInterrupt(pAd); */
315 /* put radio off to save power when driver unloads. After radiooff, can't write/read register, so need to finish all. */
316 /* register access before Radio off. */
317
318 brc = RT28xxPciAsicRadioOff(pAd, RTMP_HALT, 0);
319
320/*In solution 3 of 3090F, the bPCIclkOff will be set to TRUE after calling RT28xxPciAsicRadioOff */
321 pAd->bPCIclkOff = FALSE;
322
323 if (brc == FALSE) {
324 DBGPRINT(RT_DEBUG_ERROR,
325 ("%s call RT28xxPciAsicRadioOff fail!\n",
326 __func__));
327 }
328 }
329
330/*
331 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE))
332 {
333 RTMP_ASIC_INTERRUPT_DISABLE(pAd);
334 }
335
336 // Disable Rx, register value supposed will remain after reset
337 NICIssueReset(pAd);
338*/
339#endif /* RTMP_MAC_PCI // */
340
341 /* Free IRQ */
342 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
343#ifdef RTMP_MAC_PCI
344 /* Deregister interrupt function */
345 RtmpOSIRQRelease(net_dev);
346#endif /* RTMP_MAC_PCI // */
347 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
348 }
349 /* Free Ring or USB buffers */
350 RTMPFreeTxRxRingMemory(pAd);
351
352 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
353
354 /* Free BA reorder resource */
355 ba_reordering_resource_release(pAd);
356
357 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
358
359/*+++Modify by woody to solve the bulk fail+++*/
360 {
361 }
362
363 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt28xx_close\n"));
364 return 0; /* close ok */
365} /* End of rt28xx_close */
366
367/*
368========================================================================
369Routine Description:
370 Open raxx interface.
371
372Arguments:
373 *net_dev the raxx interface pointer
374
375Return Value:
376 0 Open OK
377 otherwise Open Fail
378
379Note:
380========================================================================
381*/
382int rt28xx_open(struct net_device *dev)
383{
384 struct net_device *net_dev = (struct net_device *)dev;
385 struct rt_rtmp_adapter *pAd = NULL;
386 int retval = 0;
387 /*struct os_cookie *pObj; */
388
389 GET_PAD_FROM_NET_DEV(pAd, net_dev);
390
391 /* Sanity check for pAd */
392 if (pAd == NULL) {
393 /* if 1st open fail, pAd will be free;
394 So the net_dev->ml_priv will be NULL in 2rd open */
395 return -1;
396 }
397
398 if (net_dev->priv_flags == INT_MAIN) {
399 if (pAd->OpMode == OPMODE_STA)
400 net_dev->wireless_handlers =
401 (struct iw_handler_def *)&rt28xx_iw_handler_def;
402 }
403 /* Request interrupt service routine for PCI device */
404 /* register the interrupt routine with the os */
405 RtmpOSIRQRequest(net_dev);
406
407 /* Init IRQ parameters stored in pAd */
408 RTMP_IRQ_INIT(pAd);
409
410 /* Chip & other init */
411 if (rt28xx_init(pAd, mac, hostname) == FALSE)
412 goto err;
413
414 /* Enable Interrupt */
415 RTMP_IRQ_ENABLE(pAd);
416
417 /* Now Enable RxTx */
418 RTMPEnableRxTx(pAd);
419 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
420
421 {
422 u32 reg = 0;
423 RTMP_IO_READ32(pAd, 0x1300, &reg); /* clear garbage interrupts */
424 printk(KERN_DEBUG "0x1300 = %08x\n", reg);
425 }
426
427 {
428/* u32 reg; */
429/* u8 byte; */
430/* u16 tmp; */
431
432/* RTMP_IO_READ32(pAd, XIFS_TIME_CFG, &reg); */
433
434/* tmp = 0x0805; */
435/* reg = (reg & 0xffff0000) | tmp; */
436/* RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg); */
437
438 }
439#ifdef RTMP_MAC_PCI
440 RTMPInitPCIeLinkCtrlValue(pAd);
441#endif /* RTMP_MAC_PCI // */
442
443 return retval;
444
445err:
446/*+++Add by shiang, move from rt28xx_init() to here. */
447 RtmpOSIRQRelease(net_dev);
448/*---Add by shiang, move from rt28xx_init() to here. */
449 return -1;
450} /* End of rt28xx_open */
451
452static const struct net_device_ops rt2860_netdev_ops = {
453 .ndo_open = MainVirtualIF_open,
454 .ndo_stop = MainVirtualIF_close,
455 .ndo_do_ioctl = rt28xx_sta_ioctl,
456 .ndo_get_stats = RT28xx_get_ether_stats,
457 .ndo_validate_addr = NULL,
458 .ndo_set_mac_address = eth_mac_addr,
459 .ndo_change_mtu = eth_change_mtu,
460 .ndo_start_xmit = rt28xx_send_packets,
461};
462
463struct net_device *RtmpPhyNetDevInit(struct rt_rtmp_adapter *pAd,
464 struct rt_rtmp_os_netdev_op_hook *pNetDevHook)
465{
466 struct net_device *net_dev = NULL;
467/* int Status; */
468
469 net_dev =
470 RtmpOSNetDevCreate(pAd, INT_MAIN, 0, sizeof(struct rt_rtmp_adapter *),
471 INF_MAIN_DEV_NAME);
472 if (net_dev == NULL) {
473 printk
474 ("RtmpPhyNetDevInit(): creation failed for main physical net device!\n");
475 return NULL;
476 }
477
478 NdisZeroMemory((unsigned char *)pNetDevHook,
479 sizeof(struct rt_rtmp_os_netdev_op_hook));
480 pNetDevHook->netdev_ops = &rt2860_netdev_ops;
481 pNetDevHook->priv_flags = INT_MAIN;
482 pNetDevHook->needProtcted = FALSE;
483
484 net_dev->ml_priv = (void *)pAd;
485 pAd->net_dev = net_dev;
486
487 return net_dev;
488
489}
490
491/*
492========================================================================
493Routine Description:
494 The entry point for Linux kernel sent packet to our driver.
495
496Arguments:
497 sk_buff *skb the pointer refer to a sk_buffer.
498
499Return Value:
500 0
501
502Note:
503 This function is the entry point of Tx Path for Os delivery packet to
504 our driver. You only can put OS-depened & STA/AP common handle procedures
505 in here.
506========================================================================
507*/
508int rt28xx_packet_xmit(struct sk_buff *skb)
509{
510 struct net_device *net_dev = skb->dev;
511 struct rt_rtmp_adapter *pAd = NULL;
512 int status = NETDEV_TX_OK;
513 void *pPacket = (void *)skb;
514
515 GET_PAD_FROM_NET_DEV(pAd, net_dev);
516
517 /* RT2870STA does this in RTMPSendPackets() */
518
519 {
520 /* Drop send request since we are in monitor mode */
521 if (MONITOR_ON(pAd)) {
522 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
523 goto done;
524 }
525 }
526
527 /* EapolStart size is 18 */
528 if (skb->len < 14) {
529 /*printk("bad packet size: %d\n", pkt->len); */
530 hex_dump("bad packet", skb->data, skb->len);
531 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
532 goto done;
533 }
534
535 RTMP_SET_PACKET_5VT(pPacket, 0);
536 STASendPackets((void *)pAd, (void **)&pPacket, 1);
537
538 status = NETDEV_TX_OK;
539done:
540
541 return status;
542}
543
544/*
545========================================================================
546Routine Description:
547 Send a packet to WLAN.
548
549Arguments:
550 skb_p points to our adapter
551 dev_p which WLAN network interface
552
553Return Value:
554 0: transmit successfully
555 otherwise: transmit fail
556
557Note:
558========================================================================
559*/
560static int rt28xx_send_packets(IN struct sk_buff *skb_p,
561 IN struct net_device *net_dev)
562{
563 struct rt_rtmp_adapter *pAd = NULL;
564
565 GET_PAD_FROM_NET_DEV(pAd, net_dev);
566
567 if (!(net_dev->flags & IFF_UP)) {
568 RELEASE_NDIS_PACKET(pAd, (void *)skb_p,
569 NDIS_STATUS_FAILURE);
570 return NETDEV_TX_OK;
571 }
572
573 NdisZeroMemory((u8 *)&skb_p->cb[CB_OFF], 15);
574 RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
575
576 return rt28xx_packet_xmit(skb_p);
577}
578
579/* This function will be called when query /proc */
580struct iw_statistics *rt28xx_get_wireless_stats(IN struct net_device *net_dev)
581{
582 struct rt_rtmp_adapter *pAd = NULL;
583
584 GET_PAD_FROM_NET_DEV(pAd, net_dev);
585
586 DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
587
588 pAd->iw_stats.status = 0; /* Status - device dependent for now */
589
590 /* link quality */
591 if (pAd->OpMode == OPMODE_STA)
592 pAd->iw_stats.qual.qual =
593 ((pAd->Mlme.ChannelQuality * 12) / 10 + 10);
594
595 if (pAd->iw_stats.qual.qual > 100)
596 pAd->iw_stats.qual.qual = 100;
597
598 if (pAd->OpMode == OPMODE_STA) {
599 pAd->iw_stats.qual.level =
600 RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0,
601 pAd->StaCfg.RssiSample.LastRssi1,
602 pAd->StaCfg.RssiSample.LastRssi2);
603 }
604
605 pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; /* noise level (dBm) */
606
607 pAd->iw_stats.qual.noise += 256 - 143;
608 pAd->iw_stats.qual.updated = 1; /* Flags to know if updated */
609#ifdef IW_QUAL_DBM
610 pAd->iw_stats.qual.updated |= IW_QUAL_DBM; /* Level + Noise are dBm */
611#endif /* IW_QUAL_DBM // */
612
613 pAd->iw_stats.discard.nwid = 0; /* Rx : Wrong nwid/essid */
614 pAd->iw_stats.miss.beacon = 0; /* Missed beacons/superframe */
615
616 DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
617 return &pAd->iw_stats;
618}
619
620void tbtt_tasklet(unsigned long data)
621{
622/*#define MAX_TX_IN_TBTT (16) */
623
624}
625
626/*
627 ========================================================================
628
629 Routine Description:
630 return ethernet statistics counter
631
632 Arguments:
633 net_dev Pointer to net_device
634
635 Return Value:
636 net_device_stats*
637
638 Note:
639
640 ========================================================================
641*/
642static struct net_device_stats *RT28xx_get_ether_stats(IN struct net_device
643 *net_dev)
644{
645 struct rt_rtmp_adapter *pAd = NULL;
646
647 if (net_dev)
648 GET_PAD_FROM_NET_DEV(pAd, net_dev);
649
650 if (pAd) {
651
652 pAd->stats.rx_packets =
653 pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
654 pAd->stats.tx_packets =
655 pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
656
657 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
658 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
659
660 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
661 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
662
663 pAd->stats.rx_dropped = 0;
664 pAd->stats.tx_dropped = 0;
665
666 pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; /* multicast packets received */
667 pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; /* Collision packets */
668
669 pAd->stats.rx_length_errors = 0;
670 pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; /* receiver ring buff overflow */
671 pAd->stats.rx_crc_errors = 0; /*pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error */
672 pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; /* recv'd frame alignment error */
673 pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; /* recv'r fifo overrun */
674 pAd->stats.rx_missed_errors = 0; /* receiver missed packet */
675
676 /* detailed tx_errors */
677 pAd->stats.tx_aborted_errors = 0;
678 pAd->stats.tx_carrier_errors = 0;
679 pAd->stats.tx_fifo_errors = 0;
680 pAd->stats.tx_heartbeat_errors = 0;
681 pAd->stats.tx_window_errors = 0;
682
683 /* for cslip etc */
684 pAd->stats.rx_compressed = 0;
685 pAd->stats.tx_compressed = 0;
686
687 return &pAd->stats;
688 } else
689 return NULL;
690}
691
692BOOLEAN RtmpPhyNetDevExit(struct rt_rtmp_adapter *pAd, struct net_device *net_dev)
693{
694
695 /* Unregister network device */
696 if (net_dev != NULL) {
697 printk
698 ("RtmpOSNetDevDetach(): RtmpOSNetDeviceDetach(), dev->name=%s!\n",
699 net_dev->name);
700 RtmpOSNetDevDetach(net_dev);
701 }
702
703 return TRUE;
704
705}
706
707/*
708========================================================================
709Routine Description:
710 Allocate memory for adapter control block.
711
712Arguments:
713 pAd Pointer to our adapter
714
715Return Value:
716 NDIS_STATUS_SUCCESS
717 NDIS_STATUS_FAILURE
718 NDIS_STATUS_RESOURCES
719
720Note:
721========================================================================
722*/
723int AdapterBlockAllocateMemory(void *handle, void ** ppAd)
724{
725
726 *ppAd = vmalloc(sizeof(struct rt_rtmp_adapter));
727 /* pci_alloc_consistent(pci_dev, sizeof(struct rt_rtmp_adapter), phy_addr); */
728
729 if (*ppAd) {
730 NdisZeroMemory(*ppAd, sizeof(struct rt_rtmp_adapter));
731 ((struct rt_rtmp_adapter *)*ppAd)->OS_Cookie = handle;
732 return NDIS_STATUS_SUCCESS;
733 } else {
734 return NDIS_STATUS_FAILURE;
735 }
736}
diff --git a/drivers/staging/rt2860/rt_pci_rbus.c b/drivers/staging/rt2860/rt_pci_rbus.c
deleted file mode 100644
index f80ab4e6a0a..00000000000
--- a/drivers/staging/rt2860/rt_pci_rbus.c
+++ /dev/null
@@ -1,837 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt_pci_rbus.c
29
30 Abstract:
31 Create and register network interface.
32
33 Revision History:
34 Who When What
35 Justin P. Mattock 11/07/2010 Fix a typo
36 -------- ---------- ----------------------------------------------
37*/
38
39#include "rt_config.h"
40#include <linux/pci.h>
41
42IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance);
43
44static void rx_done_tasklet(unsigned long data);
45static void mgmt_dma_done_tasklet(unsigned long data);
46static void ac0_dma_done_tasklet(unsigned long data);
47static void ac1_dma_done_tasklet(unsigned long data);
48static void ac2_dma_done_tasklet(unsigned long data);
49static void ac3_dma_done_tasklet(unsigned long data);
50static void fifo_statistic_full_tasklet(unsigned long data);
51
52/*---------------------------------------------------------------------*/
53/* Symbol & Macro Definitions */
54/*---------------------------------------------------------------------*/
55#define RT2860_INT_RX_DLY (1<<0) /* bit 0 */
56#define RT2860_INT_TX_DLY (1<<1) /* bit 1 */
57#define RT2860_INT_RX_DONE (1<<2) /* bit 2 */
58#define RT2860_INT_AC0_DMA_DONE (1<<3) /* bit 3 */
59#define RT2860_INT_AC1_DMA_DONE (1<<4) /* bit 4 */
60#define RT2860_INT_AC2_DMA_DONE (1<<5) /* bit 5 */
61#define RT2860_INT_AC3_DMA_DONE (1<<6) /* bit 6 */
62#define RT2860_INT_HCCA_DMA_DONE (1<<7) /* bit 7 */
63#define RT2860_INT_MGMT_DONE (1<<8) /* bit 8 */
64
65#define INT_RX RT2860_INT_RX_DONE
66
67#define INT_AC0_DLY (RT2860_INT_AC0_DMA_DONE) /*| RT2860_INT_TX_DLY) */
68#define INT_AC1_DLY (RT2860_INT_AC1_DMA_DONE) /*| RT2860_INT_TX_DLY) */
69#define INT_AC2_DLY (RT2860_INT_AC2_DMA_DONE) /*| RT2860_INT_TX_DLY) */
70#define INT_AC3_DLY (RT2860_INT_AC3_DMA_DONE) /*| RT2860_INT_TX_DLY) */
71#define INT_HCCA_DLY (RT2860_INT_HCCA_DMA_DONE) /*| RT2860_INT_TX_DLY) */
72#define INT_MGMT_DLY RT2860_INT_MGMT_DONE
73
74/***************************************************************************
75 *
76 * Interface-depended memory allocation/Free related procedures.
77 * Mainly for Hardware TxDesc/RxDesc/MgmtDesc, DMA Memory for TxData/RxData, etc.,
78 *
79 **************************************************************************/
80/* Function for TxDesc Memory allocation. */
81void RTMP_AllocateTxDescMemory(struct rt_rtmp_adapter *pAd,
82 u32 Index,
83 unsigned long Length,
84 IN BOOLEAN Cached,
85 void **VirtualAddress,
86 dma_addr_t *PhysicalAddress)
87{
88 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
89
90 *VirtualAddress =
91 (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length,
92 PhysicalAddress);
93
94}
95
96/* Function for MgmtDesc Memory allocation. */
97void RTMP_AllocateMgmtDescMemory(struct rt_rtmp_adapter *pAd,
98 unsigned long Length,
99 IN BOOLEAN Cached,
100 void **VirtualAddress,
101 dma_addr_t *PhysicalAddress)
102{
103 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
104
105 *VirtualAddress =
106 (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length,
107 PhysicalAddress);
108
109}
110
111/* Function for RxDesc Memory allocation. */
112void RTMP_AllocateRxDescMemory(struct rt_rtmp_adapter *pAd,
113 unsigned long Length,
114 IN BOOLEAN Cached,
115 void **VirtualAddress,
116 dma_addr_t *PhysicalAddress)
117{
118 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
119
120 *VirtualAddress =
121 (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length,
122 PhysicalAddress);
123
124}
125
126/* Function for free allocated Desc Memory. */
127void RTMP_FreeDescMemory(struct rt_rtmp_adapter *pAd,
128 unsigned long Length,
129 void *VirtualAddress,
130 dma_addr_t PhysicalAddress)
131{
132 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
133
134 pci_free_consistent(pObj->pci_dev, Length, VirtualAddress,
135 PhysicalAddress);
136}
137
138/* Function for TxData DMA Memory allocation. */
139void RTMP_AllocateFirstTxBuffer(struct rt_rtmp_adapter *pAd,
140 u32 Index,
141 unsigned long Length,
142 IN BOOLEAN Cached,
143 void **VirtualAddress,
144 dma_addr_t *PhysicalAddress)
145{
146 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
147
148 *VirtualAddress =
149 (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length,
150 PhysicalAddress);
151}
152
153void RTMP_FreeFirstTxBuffer(struct rt_rtmp_adapter *pAd,
154 unsigned long Length,
155 IN BOOLEAN Cached,
156 void *VirtualAddress,
157 dma_addr_t PhysicalAddress)
158{
159 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
160
161 pci_free_consistent(pObj->pci_dev, Length, VirtualAddress,
162 PhysicalAddress);
163}
164
165/*
166 * FUNCTION: Allocate a common buffer for DMA
167 * ARGUMENTS:
168 * AdapterHandle: AdapterHandle
169 * Length: Number of bytes to allocate
170 * Cached: Whether or not the memory can be cached
171 * VirtualAddress: Pointer to memory is returned here
172 * PhysicalAddress: Physical address corresponding to virtual address
173 */
174void RTMP_AllocateSharedMemory(struct rt_rtmp_adapter *pAd,
175 unsigned long Length,
176 IN BOOLEAN Cached,
177 void **VirtualAddress,
178 dma_addr_t *PhysicalAddress)
179{
180 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
181
182 *VirtualAddress =
183 (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length,
184 PhysicalAddress);
185}
186
187/*
188 * FUNCTION: Allocate a packet buffer for DMA
189 * ARGUMENTS:
190 * AdapterHandle: AdapterHandle
191 * Length: Number of bytes to allocate
192 * Cached: Whether or not the memory can be cached
193 * VirtualAddress: Pointer to memory is returned here
194 * PhysicalAddress: Physical address corresponding to virtual address
195 * Notes:
196 * Cached is ignored: always cached memory
197 */
198void *RTMP_AllocateRxPacketBuffer(struct rt_rtmp_adapter *pAd,
199 unsigned long Length,
200 IN BOOLEAN Cached,
201 void **VirtualAddress,
202 OUT dma_addr_t *
203 PhysicalAddress)
204{
205 struct sk_buff *pkt;
206
207 pkt = dev_alloc_skb(Length);
208
209 if (pkt == NULL) {
210 DBGPRINT(RT_DEBUG_ERROR,
211 ("can't allocate rx %ld size packet\n", Length));
212 }
213
214 if (pkt) {
215 RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
216 *VirtualAddress = (void *)pkt->data;
217 *PhysicalAddress =
218 PCI_MAP_SINGLE(pAd, *VirtualAddress, Length, -1,
219 PCI_DMA_FROMDEVICE);
220 } else {
221 *VirtualAddress = (void *)NULL;
222 *PhysicalAddress = (dma_addr_t)NULL;
223 }
224
225 return (void *)pkt;
226}
227
228void Invalid_Remaining_Packet(struct rt_rtmp_adapter *pAd, unsigned long VirtualAddress)
229{
230 dma_addr_t PhysicalAddress;
231
232 PhysicalAddress =
233 PCI_MAP_SINGLE(pAd, (void *)(VirtualAddress + 1600),
234 RX_BUFFER_NORMSIZE - 1600, -1, PCI_DMA_FROMDEVICE);
235}
236
237int RtmpNetTaskInit(struct rt_rtmp_adapter *pAd)
238{
239 struct os_cookie *pObj;
240
241 pObj = (struct os_cookie *)pAd->OS_Cookie;
242
243 tasklet_init(&pObj->rx_done_task, rx_done_tasklet, (unsigned long)pAd);
244 tasklet_init(&pObj->mgmt_dma_done_task, mgmt_dma_done_tasklet,
245 (unsigned long)pAd);
246 tasklet_init(&pObj->ac0_dma_done_task, ac0_dma_done_tasklet,
247 (unsigned long)pAd);
248 tasklet_init(&pObj->ac1_dma_done_task, ac1_dma_done_tasklet,
249 (unsigned long)pAd);
250 tasklet_init(&pObj->ac2_dma_done_task, ac2_dma_done_tasklet,
251 (unsigned long)pAd);
252 tasklet_init(&pObj->ac3_dma_done_task, ac3_dma_done_tasklet,
253 (unsigned long)pAd);
254 tasklet_init(&pObj->tbtt_task, tbtt_tasklet, (unsigned long)pAd);
255 tasklet_init(&pObj->fifo_statistic_full_task,
256 fifo_statistic_full_tasklet, (unsigned long)pAd);
257
258 return NDIS_STATUS_SUCCESS;
259}
260
261void RtmpNetTaskExit(struct rt_rtmp_adapter *pAd)
262{
263 struct os_cookie *pObj;
264
265 pObj = (struct os_cookie *)pAd->OS_Cookie;
266
267 tasklet_kill(&pObj->rx_done_task);
268 tasklet_kill(&pObj->mgmt_dma_done_task);
269 tasklet_kill(&pObj->ac0_dma_done_task);
270 tasklet_kill(&pObj->ac1_dma_done_task);
271 tasklet_kill(&pObj->ac2_dma_done_task);
272 tasklet_kill(&pObj->ac3_dma_done_task);
273 tasklet_kill(&pObj->tbtt_task);
274 tasklet_kill(&pObj->fifo_statistic_full_task);
275}
276
277int RtmpMgmtTaskInit(struct rt_rtmp_adapter *pAd)
278{
279
280 return NDIS_STATUS_SUCCESS;
281}
282
283/*
284========================================================================
285Routine Description:
286 Close kernel threads.
287
288Arguments:
289 *pAd the raxx interface data pointer
290
291Return Value:
292 NONE
293
294Note:
295========================================================================
296*/
297void RtmpMgmtTaskExit(struct rt_rtmp_adapter *pAd)
298{
299
300 return;
301}
302
303static inline void rt2860_int_enable(struct rt_rtmp_adapter *pAd, unsigned int mode)
304{
305 u32 regValue;
306
307 pAd->int_disable_mask &= ~(mode);
308 regValue = pAd->int_enable_reg & ~(pAd->int_disable_mask);
309 /*if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) */
310 {
311 RTMP_IO_WRITE32(pAd, INT_MASK_CSR, regValue); /* 1:enable */
312 }
313 /*else */
314 /* DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_DOZE !\n")); */
315
316 if (regValue != 0)
317 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE);
318}
319
320static inline void rt2860_int_disable(struct rt_rtmp_adapter *pAd, unsigned int mode)
321{
322 u32 regValue;
323
324 pAd->int_disable_mask |= mode;
325 regValue = pAd->int_enable_reg & ~(pAd->int_disable_mask);
326 RTMP_IO_WRITE32(pAd, INT_MASK_CSR, regValue); /* 0: disable */
327
328 if (regValue == 0) {
329 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE);
330 }
331}
332
333/***************************************************************************
334 *
335 * tasklet related procedures.
336 *
337 **************************************************************************/
338static void mgmt_dma_done_tasklet(unsigned long data)
339{
340 unsigned long flags;
341 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data;
342 INT_SOURCE_CSR_STRUC IntSource;
343 struct os_cookie *pObj;
344
345 /* Do nothing if the driver is starting halt state. */
346 /* This might happen when timer already been fired before cancel timer with mlmehalt */
347 if (RTMP_TEST_FLAG
348 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
349 return;
350
351 pObj = (struct os_cookie *)pAd->OS_Cookie;
352
353/* printk("mgmt_dma_done_process\n"); */
354 IntSource.word = 0;
355 IntSource.field.MgmtDmaDone = 1;
356 pAd->int_pending &= ~INT_MGMT_DLY;
357
358 RTMPHandleMgmtRingDmaDoneInterrupt(pAd);
359
360 /* if you use RTMP_SEM_LOCK, sometimes kernel will hang up, without any */
361 /* bug report output */
362 RTMP_INT_LOCK(&pAd->irq_lock, flags);
363 /*
364 * double check to avoid lose of interrupts
365 */
366 if (pAd->int_pending & INT_MGMT_DLY) {
367 tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
368 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
369 return;
370 }
371
372 /* enable TxDataInt again */
373 rt2860_int_enable(pAd, INT_MGMT_DLY);
374 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
375}
376
377static void rx_done_tasklet(unsigned long data)
378{
379 unsigned long flags;
380 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data;
381 BOOLEAN bReschedule = 0;
382 struct os_cookie *pObj;
383
384 /* Do nothing if the driver is starting halt state. */
385 /* This might happen when timer already been fired before cancel timer with mlmehalt */
386 if (RTMP_TEST_FLAG
387 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
388 return;
389
390 pObj = (struct os_cookie *)pAd->OS_Cookie;
391
392 pAd->int_pending &= ~(INT_RX);
393 bReschedule = STARxDoneInterruptHandle(pAd, 0);
394
395 RTMP_INT_LOCK(&pAd->irq_lock, flags);
396 /*
397 * double check to avoid rotting packet
398 */
399 if (pAd->int_pending & INT_RX || bReschedule) {
400 tasklet_hi_schedule(&pObj->rx_done_task);
401 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
402 return;
403 }
404
405 /* enable Rxint again */
406 rt2860_int_enable(pAd, INT_RX);
407 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
408
409}
410
411void fifo_statistic_full_tasklet(unsigned long data)
412{
413 unsigned long flags;
414 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data;
415 struct os_cookie *pObj;
416
417 /* Do nothing if the driver is starting halt state. */
418 /* This might happen when timer already been fired before cancel timer with mlmehalt */
419 if (RTMP_TEST_FLAG
420 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
421 return;
422
423 pObj = (struct os_cookie *)pAd->OS_Cookie;
424
425 pAd->int_pending &= ~(FifoStaFullInt);
426 NICUpdateFifoStaCounters(pAd);
427
428 RTMP_INT_LOCK(&pAd->irq_lock, flags);
429 /*
430 * double check to avoid rotting packet
431 */
432 if (pAd->int_pending & FifoStaFullInt) {
433 tasklet_hi_schedule(&pObj->fifo_statistic_full_task);
434 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
435 return;
436 }
437
438 /* enable Rxint again */
439
440 rt2860_int_enable(pAd, FifoStaFullInt);
441 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
442
443}
444
445static void ac3_dma_done_tasklet(unsigned long data)
446{
447 unsigned long flags;
448 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data;
449 INT_SOURCE_CSR_STRUC IntSource;
450 struct os_cookie *pObj;
451 BOOLEAN bReschedule = 0;
452
453 /* Do nothing if the driver is starting halt state. */
454 /* This might happen when timer already been fired before cancel timer with mlmehalt */
455 if (RTMP_TEST_FLAG
456 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
457 return;
458
459 pObj = (struct os_cookie *)pAd->OS_Cookie;
460
461/* printk("ac0_dma_done_process\n"); */
462 IntSource.word = 0;
463 IntSource.field.Ac3DmaDone = 1;
464 pAd->int_pending &= ~INT_AC3_DLY;
465
466 bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
467
468 RTMP_INT_LOCK(&pAd->irq_lock, flags);
469 /*
470 * double check to avoid lose of interrupts
471 */
472 if ((pAd->int_pending & INT_AC3_DLY) || bReschedule) {
473 tasklet_hi_schedule(&pObj->ac3_dma_done_task);
474 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
475 return;
476 }
477
478 /* enable TxDataInt again */
479 rt2860_int_enable(pAd, INT_AC3_DLY);
480 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
481}
482
483static void ac2_dma_done_tasklet(unsigned long data)
484{
485 unsigned long flags;
486 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data;
487 INT_SOURCE_CSR_STRUC IntSource;
488 struct os_cookie *pObj;
489 BOOLEAN bReschedule = 0;
490
491 /* Do nothing if the driver is starting halt state. */
492 /* This might happen when timer already been fired before cancel timer with mlmehalt */
493 if (RTMP_TEST_FLAG
494 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
495 return;
496
497 pObj = (struct os_cookie *)pAd->OS_Cookie;
498
499 IntSource.word = 0;
500 IntSource.field.Ac2DmaDone = 1;
501 pAd->int_pending &= ~INT_AC2_DLY;
502
503 bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
504
505 RTMP_INT_LOCK(&pAd->irq_lock, flags);
506
507 /*
508 * double check to avoid lose of interrupts
509 */
510 if ((pAd->int_pending & INT_AC2_DLY) || bReschedule) {
511 tasklet_hi_schedule(&pObj->ac2_dma_done_task);
512 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
513 return;
514 }
515
516 /* enable TxDataInt again */
517 rt2860_int_enable(pAd, INT_AC2_DLY);
518 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
519}
520
521static void ac1_dma_done_tasklet(unsigned long data)
522{
523 unsigned long flags;
524 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data;
525 INT_SOURCE_CSR_STRUC IntSource;
526 struct os_cookie *pObj;
527 BOOLEAN bReschedule = 0;
528
529 /* Do nothing if the driver is starting halt state. */
530 /* This might happen when timer already been fired before cancel timer with mlmehalt */
531 if (RTMP_TEST_FLAG
532 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
533 return;
534
535 pObj = (struct os_cookie *)pAd->OS_Cookie;
536
537/* printk("ac0_dma_done_process\n"); */
538 IntSource.word = 0;
539 IntSource.field.Ac1DmaDone = 1;
540 pAd->int_pending &= ~INT_AC1_DLY;
541
542 bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
543
544 RTMP_INT_LOCK(&pAd->irq_lock, flags);
545 /*
546 * double check to avoid lose of interrupts
547 */
548 if ((pAd->int_pending & INT_AC1_DLY) || bReschedule) {
549 tasklet_hi_schedule(&pObj->ac1_dma_done_task);
550 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
551 return;
552 }
553
554 /* enable TxDataInt again */
555 rt2860_int_enable(pAd, INT_AC1_DLY);
556 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
557}
558
559static void ac0_dma_done_tasklet(unsigned long data)
560{
561 unsigned long flags;
562 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data;
563 INT_SOURCE_CSR_STRUC IntSource;
564 struct os_cookie *pObj;
565 BOOLEAN bReschedule = 0;
566
567 /* Do nothing if the driver is starting halt state. */
568 /* This might happen when timer already been fired before cancel timer with mlmehalt */
569 if (RTMP_TEST_FLAG
570 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
571 return;
572
573 pObj = (struct os_cookie *)pAd->OS_Cookie;
574
575/* printk("ac0_dma_done_process\n"); */
576 IntSource.word = 0;
577 IntSource.field.Ac0DmaDone = 1;
578 pAd->int_pending &= ~INT_AC0_DLY;
579
580/* RTMPHandleMgmtRingDmaDoneInterrupt(pAd); */
581 bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
582
583 RTMP_INT_LOCK(&pAd->irq_lock, flags);
584 /*
585 * double check to avoid lose of interrupts
586 */
587 if ((pAd->int_pending & INT_AC0_DLY) || bReschedule) {
588 tasklet_hi_schedule(&pObj->ac0_dma_done_task);
589 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
590 return;
591 }
592
593 /* enable TxDataInt again */
594 rt2860_int_enable(pAd, INT_AC0_DLY);
595 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
596}
597
598/***************************************************************************
599 *
600 * interrupt handler related procedures.
601 *
602 **************************************************************************/
603int print_int_count;
604
605IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance)
606{
607 struct net_device *net_dev = (struct net_device *)dev_instance;
608 struct rt_rtmp_adapter *pAd = NULL;
609 INT_SOURCE_CSR_STRUC IntSource;
610 struct os_cookie *pObj;
611
612 GET_PAD_FROM_NET_DEV(pAd, net_dev);
613
614 pObj = (struct os_cookie *)pAd->OS_Cookie;
615
616 /* Note 03312008: we can not return here before
617 RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word);
618 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word);
619 Or kernel will panic after ifconfig ra0 down sometimes */
620
621 /* */
622 /* Initial the Interrupt source. */
623 /* */
624 IntSource.word = 0x00000000L;
625/* McuIntSource.word = 0x00000000L; */
626
627 /* */
628 /* Get the interrupt sources & saved to local variable */
629 /* */
630 /*RTMP_IO_READ32(pAd, where, &McuIntSource.word); */
631 /*RTMP_IO_WRITE32(pAd, , McuIntSource.word); */
632
633 /* */
634 /* Flag fOP_STATUS_DOZE On, means ASIC put to sleep, elase means ASICK WakeUp */
635 /* And at the same time, clock maybe turned off that say there is no DMA service. */
636 /* when ASIC get to sleep. */
637 /* To prevent system hang on power saving. */
638 /* We need to check it before handle the INT_SOURCE_CSR, ASIC must be wake up. */
639 /* */
640 /* RT2661 => when ASIC is sleeping, MAC register cannot be read and written. */
641 /* RT2860 => when ASIC is sleeping, MAC register can be read and written. */
642/* if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) */
643 {
644 RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word);
645 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word); /* write 1 to clear */
646 }
647/* else */
648/* DBGPRINT(RT_DEBUG_TRACE, (">>>fOP_STATUS_DOZE<<<\n")); */
649
650/* RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IsrAfterClear); */
651/* RTMP_IO_READ32(pAd, MCU_INT_SOURCE_CSR, &McuIsrAfterClear); */
652/* DBGPRINT(RT_DEBUG_INFO, ("====> RTMPHandleInterrupt(ISR=%08x,Mcu ISR=%08x, After clear ISR=%08x, MCU ISR=%08x)\n", */
653/* IntSource.word, McuIntSource.word, IsrAfterClear, McuIsrAfterClear)); */
654
655 /* Do nothing if Reset in progress */
656 if (RTMP_TEST_FLAG
657 (pAd,
658 (fRTMP_ADAPTER_RESET_IN_PROGRESS |
659 fRTMP_ADAPTER_HALT_IN_PROGRESS))) {
660 return IRQ_HANDLED;
661 }
662 /* */
663 /* Handle interrupt, walk through all bits */
664 /* Should start from highest priority interrupt */
665 /* The priority can be adjust by altering processing if statement */
666 /* */
667
668#ifdef DBG
669
670#endif
671
672 pAd->bPCIclkOff = FALSE;
673
674 /* If required spinlock, each interrupt service routine has to acquire */
675 /* and release itself. */
676 /* */
677
678 /* Do nothing if NIC doesn't exist */
679 if (IntSource.word == 0xffffffff) {
680 RTMP_SET_FLAG(pAd,
681 (fRTMP_ADAPTER_NIC_NOT_EXIST |
682 fRTMP_ADAPTER_HALT_IN_PROGRESS));
683 return IRQ_HANDLED;
684 }
685
686 if (IntSource.word & TxCoherent) {
687 DBGPRINT(RT_DEBUG_ERROR, (">>>TxCoherent<<<\n"));
688 RTMPHandleRxCoherentInterrupt(pAd);
689 }
690
691 if (IntSource.word & RxCoherent) {
692 DBGPRINT(RT_DEBUG_ERROR, (">>>RxCoherent<<<\n"));
693 RTMPHandleRxCoherentInterrupt(pAd);
694 }
695
696 if (IntSource.word & FifoStaFullInt) {
697 if ((pAd->int_disable_mask & FifoStaFullInt) == 0) {
698 /* mask FifoStaFullInt */
699 rt2860_int_disable(pAd, FifoStaFullInt);
700 tasklet_hi_schedule(&pObj->fifo_statistic_full_task);
701 }
702 pAd->int_pending |= FifoStaFullInt;
703 }
704
705 if (IntSource.word & INT_MGMT_DLY) {
706 if ((pAd->int_disable_mask & INT_MGMT_DLY) == 0) {
707 rt2860_int_disable(pAd, INT_MGMT_DLY);
708 tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
709 }
710 pAd->int_pending |= INT_MGMT_DLY;
711 }
712
713 if (IntSource.word & INT_RX) {
714 if ((pAd->int_disable_mask & INT_RX) == 0) {
715
716 /* mask Rxint */
717 rt2860_int_disable(pAd, INT_RX);
718 tasklet_hi_schedule(&pObj->rx_done_task);
719 }
720 pAd->int_pending |= INT_RX;
721 }
722
723 if (IntSource.word & INT_AC3_DLY) {
724
725 if ((pAd->int_disable_mask & INT_AC3_DLY) == 0) {
726 /* mask TxDataInt */
727 rt2860_int_disable(pAd, INT_AC3_DLY);
728 tasklet_hi_schedule(&pObj->ac3_dma_done_task);
729 }
730 pAd->int_pending |= INT_AC3_DLY;
731 }
732
733 if (IntSource.word & INT_AC2_DLY) {
734
735 if ((pAd->int_disable_mask & INT_AC2_DLY) == 0) {
736 /* mask TxDataInt */
737 rt2860_int_disable(pAd, INT_AC2_DLY);
738 tasklet_hi_schedule(&pObj->ac2_dma_done_task);
739 }
740 pAd->int_pending |= INT_AC2_DLY;
741 }
742
743 if (IntSource.word & INT_AC1_DLY) {
744
745 pAd->int_pending |= INT_AC1_DLY;
746
747 if ((pAd->int_disable_mask & INT_AC1_DLY) == 0) {
748 /* mask TxDataInt */
749 rt2860_int_disable(pAd, INT_AC1_DLY);
750 tasklet_hi_schedule(&pObj->ac1_dma_done_task);
751 }
752
753 }
754
755 if (IntSource.word & INT_AC0_DLY) {
756
757/*
758 if (IntSource.word & 0x2) {
759 u32 reg;
760 RTMP_IO_READ32(pAd, DELAY_INT_CFG, &reg);
761 printk("IntSource.word = %08x, DELAY_REG = %08x\n", IntSource.word, reg);
762 }
763*/
764 pAd->int_pending |= INT_AC0_DLY;
765
766 if ((pAd->int_disable_mask & INT_AC0_DLY) == 0) {
767 /* mask TxDataInt */
768 rt2860_int_disable(pAd, INT_AC0_DLY);
769 tasklet_hi_schedule(&pObj->ac0_dma_done_task);
770 }
771
772 }
773
774 if (IntSource.word & PreTBTTInt) {
775 RTMPHandlePreTBTTInterrupt(pAd);
776 }
777
778 if (IntSource.word & TBTTInt) {
779 RTMPHandleTBTTInterrupt(pAd);
780 }
781
782 {
783 if (IntSource.word & AutoWakeupInt)
784 RTMPHandleTwakeupInterrupt(pAd);
785 }
786
787 return IRQ_HANDLED;
788}
789
790/*
791 * invalid or writeback cache
792 * and convert virtual address to physical address
793 */
794dma_addr_t linux_pci_map_single(struct rt_rtmp_adapter *pAd, void *ptr,
795 size_t size, int sd_idx, int direction)
796{
797 struct os_cookie *pObj;
798
799 /*
800 ------ Porting Information ------
801 > For Tx Alloc:
802 mgmt packets => sd_idx = 0
803 SwIdx: pAd->MgmtRing.TxCpuIdx
804 pTxD : pAd->MgmtRing.Cell[SwIdx].AllocVa;
805
806 data packets => sd_idx = 1
807 TxIdx : pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx
808 QueIdx: pTxBlk->QueIdx
809 pTxD : pAd->TxRing[pTxBlk->QueIdx].Cell[TxIdx].AllocVa;
810
811 > For Rx Alloc:
812 sd_idx = -1
813 */
814
815 pObj = (struct os_cookie *)pAd->OS_Cookie;
816
817 if (sd_idx == 1) {
818 struct rt_tx_blk *pTxBlk;
819 pTxBlk = (struct rt_tx_blk *)ptr;
820 return pci_map_single(pObj->pci_dev, pTxBlk->pSrcBufData,
821 pTxBlk->SrcBufLen, direction);
822 } else {
823 return pci_map_single(pObj->pci_dev, ptr, size, direction);
824 }
825
826}
827
828void linux_pci_unmap_single(struct rt_rtmp_adapter *pAd, dma_addr_t dma_addr,
829 size_t size, int direction)
830{
831 struct os_cookie *pObj;
832
833 pObj = (struct os_cookie *)pAd->OS_Cookie;
834
835 pci_unmap_single(pObj->pci_dev, dma_addr, size, direction);
836
837}
diff --git a/drivers/staging/rt2860/rt_usb.c b/drivers/staging/rt2860/rt_usb.c
deleted file mode 100644
index eb037d2e04a..00000000000
--- a/drivers/staging/rt2860/rt_usb.c
+++ /dev/null
@@ -1,794 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtusb_bulk.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Justin P. Mattock 11/07/2010 Fix some typos.
37
38*/
39
40#include "rt_config.h"
41
42void dump_urb(struct urb *purb)
43{
44 printk(KERN_DEBUG "urb :0x%08lx\n", (unsigned long)purb);
45 printk(KERN_DEBUG "\tdev :0x%08lx\n", (unsigned long)purb->dev);
46 printk(KERN_DEBUG "\t\tdev->state :0x%d\n", purb->dev->state);
47 printk(KERN_DEBUG "\tpipe :0x%08x\n", purb->pipe);
48 printk(KERN_DEBUG "\tstatus :%d\n", purb->status);
49 printk(KERN_DEBUG "\ttransfer_flags :0x%08x\n", purb->transfer_flags);
50 printk(KERN_DEBUG "\ttransfer_buffer :0x%08lx\n",
51 (unsigned long)purb->transfer_buffer);
52 printk(KERN_DEBUG "\ttransfer_buffer_length:%d\n", purb->transfer_buffer_length);
53 printk(KERN_DEBUG "\tactual_length :%d\n", purb->actual_length);
54 printk(KERN_DEBUG "\tsetup_packet :0x%08lx\n",
55 (unsigned long)purb->setup_packet);
56 printk(KERN_DEBUG "\tstart_frame :%d\n", purb->start_frame);
57 printk(KERN_DEBUG "\tnumber_of_packets :%d\n", purb->number_of_packets);
58 printk(KERN_DEBUG "\tinterval :%d\n", purb->interval);
59 printk(KERN_DEBUG "\terror_count :%d\n", purb->error_count);
60 printk(KERN_DEBUG "\tcontext :0x%08lx\n",
61 (unsigned long)purb->context);
62 printk(KERN_DEBUG "\tcomplete :0x%08lx\n\n",
63 (unsigned long)purb->complete);
64}
65
66/*
67========================================================================
68Routine Description:
69 Create kernel threads & tasklets.
70
71Arguments:
72 *net_dev Pointer to wireless net device interface
73
74Return Value:
75 NDIS_STATUS_SUCCESS
76 NDIS_STATUS_FAILURE
77
78Note:
79========================================================================
80*/
81int RtmpMgmtTaskInit(struct rt_rtmp_adapter *pAd)
82{
83 struct rt_rtmp_os_task *pTask;
84 int status;
85
86 /*
87 Creat TimerQ Thread, We need init timerQ related structure before create the timer thread.
88 */
89 RtmpTimerQInit(pAd);
90
91 pTask = &pAd->timerTask;
92 RtmpOSTaskInit(pTask, "RtmpTimerTask", pAd);
93 status = RtmpOSTaskAttach(pTask, RtmpTimerQThread, pTask);
94 if (status == NDIS_STATUS_FAILURE) {
95 printk(KERN_WARNING "%s: unable to start RtmpTimerQThread\n",
96 RTMP_OS_NETDEV_GET_DEVNAME(pAd->net_dev));
97 return NDIS_STATUS_FAILURE;
98 }
99
100 /* Creat MLME Thread */
101 pTask = &pAd->mlmeTask;
102 RtmpOSTaskInit(pTask, "RtmpMlmeTask", pAd);
103 status = RtmpOSTaskAttach(pTask, MlmeThread, pTask);
104 if (status == NDIS_STATUS_FAILURE) {
105 printk(KERN_WARNING "%s: unable to start MlmeThread\n",
106 RTMP_OS_NETDEV_GET_DEVNAME(pAd->net_dev));
107 return NDIS_STATUS_FAILURE;
108 }
109
110 /* Creat Command Thread */
111 pTask = &pAd->cmdQTask;
112 RtmpOSTaskInit(pTask, "RtmpCmdQTask", pAd);
113 status = RtmpOSTaskAttach(pTask, RTUSBCmdThread, pTask);
114 if (status == NDIS_STATUS_FAILURE) {
115 printk(KERN_WARNING "%s: unable to start RTUSBCmdThread\n",
116 RTMP_OS_NETDEV_GET_DEVNAME(pAd->net_dev));
117 return NDIS_STATUS_FAILURE;
118 }
119
120 return NDIS_STATUS_SUCCESS;
121}
122
123/*
124========================================================================
125Routine Description:
126 Close kernel threads.
127
128Arguments:
129 *pAd the raxx interface data pointer
130
131Return Value:
132 NONE
133
134Note:
135========================================================================
136*/
137void RtmpMgmtTaskExit(struct rt_rtmp_adapter *pAd)
138{
139 int ret;
140 struct rt_rtmp_os_task *pTask;
141
142 /* Sleep 50 milliseconds so pending io might finish normally */
143 RTMPusecDelay(50000);
144
145 /* We want to wait until all pending receives and sends to the */
146 /* device object. We cancel any */
147 /* irps. Wait until sends and receives have stopped. */
148 RTUSBCancelPendingIRPs(pAd);
149
150 /* We need clear timerQ related structure before exits of the timer thread. */
151 RtmpTimerQExit(pAd);
152
153 /* Terminate Mlme Thread */
154 pTask = &pAd->mlmeTask;
155 ret = RtmpOSTaskKill(pTask);
156 if (ret == NDIS_STATUS_FAILURE) {
157 DBGPRINT(RT_DEBUG_ERROR, ("%s: kill task(%s) failed!\n",
158 RTMP_OS_NETDEV_GET_DEVNAME(pAd->
159 net_dev),
160 pTask->taskName));
161 }
162
163 /* Terminate cmdQ thread */
164 pTask = &pAd->cmdQTask;
165#ifdef KTHREAD_SUPPORT
166 if (pTask->kthread_task)
167#else
168 CHECK_PID_LEGALITY(pTask->taskPID)
169#endif
170 {
171 mb();
172 NdisAcquireSpinLock(&pAd->CmdQLock);
173 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_STOPED;
174 NdisReleaseSpinLock(&pAd->CmdQLock);
175 mb();
176 /*RTUSBCMDUp(pAd); */
177 ret = RtmpOSTaskKill(pTask);
178 if (ret == NDIS_STATUS_FAILURE) {
179 DBGPRINT(RT_DEBUG_ERROR, ("%s: kill task(%s) failed!\n",
180 RTMP_OS_NETDEV_GET_DEVNAME
181 (pAd->net_dev),
182 pTask->taskName));
183 }
184 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_UNKNOWN;
185 }
186
187 /* Terminate timer thread */
188 pTask = &pAd->timerTask;
189 ret = RtmpOSTaskKill(pTask);
190 if (ret == NDIS_STATUS_FAILURE) {
191 DBGPRINT(RT_DEBUG_ERROR, ("%s: kill task(%s) failed!\n",
192 RTMP_OS_NETDEV_GET_DEVNAME(pAd->
193 net_dev),
194 pTask->taskName));
195 }
196
197}
198
199static void rtusb_dataout_complete(unsigned long data)
200{
201 struct rt_rtmp_adapter *pAd;
202 struct urb *pUrb;
203 struct os_cookie *pObj;
204 struct rt_ht_tx_context *pHTTXContext;
205 u8 BulkOutPipeId;
206 int Status;
207 unsigned long IrqFlags;
208
209 pUrb = (struct urb *)data;
210 pHTTXContext = (struct rt_ht_tx_context *)pUrb->context;
211 pAd = pHTTXContext->pAd;
212 pObj = (struct os_cookie *)pAd->OS_Cookie;
213 Status = pUrb->status;
214
215 /* Store BulkOut PipeId */
216 BulkOutPipeId = pHTTXContext->BulkOutPipeId;
217 pAd->BulkOutDataOneSecCount++;
218
219 /*DBGPRINT(RT_DEBUG_LOUD, ("Done-B(%d):I=0x%lx, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", BulkOutPipeId, in_interrupt(), pHTTXContext->CurWritePosition, */
220 /* pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad)); */
221
222 RTMP_IRQ_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
223 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
224 pHTTXContext->IRPPending = FALSE;
225 pAd->watchDogTxPendingCnt[BulkOutPipeId] = 0;
226
227 if (Status == USB_ST_NOERROR) {
228 pAd->BulkOutComplete++;
229
230 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
231
232 pAd->Counters8023.GoodTransmits++;
233 /*RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); */
234 FREE_HTTX_RING(pAd, BulkOutPipeId, pHTTXContext);
235 /*RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); */
236
237 } else { /* STATUS_OTHER */
238 u8 *pBuf;
239
240 pAd->BulkOutCompleteOther++;
241
242 pBuf =
243 &pHTTXContext->TransferBuffer->field.
244 WirelessPacket[pHTTXContext->NextBulkOutPosition];
245
246 if (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
247 fRTMP_ADAPTER_HALT_IN_PROGRESS |
248 fRTMP_ADAPTER_NIC_NOT_EXIST |
249 fRTMP_ADAPTER_BULKOUT_RESET))) {
250 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
251 pAd->bulkResetPipeid = BulkOutPipeId;
252 pAd->bulkResetReq[BulkOutPipeId] = pAd->BulkOutReq;
253 }
254 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
255
256 DBGPRINT_RAW(RT_DEBUG_ERROR,
257 ("BulkOutDataPacket failed: ReasonCode=%d!\n",
258 Status));
259 DBGPRINT_RAW(RT_DEBUG_ERROR,
260 ("\t>>BulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n",
261 pAd->BulkOutReq, pAd->BulkOutComplete,
262 pAd->BulkOutCompleteOther));
263 DBGPRINT_RAW(RT_DEBUG_ERROR,
264 ("\t>>BulkOut Header:%x %x %x %x %x %x %x %x\n",
265 pBuf[0], pBuf[1], pBuf[2], pBuf[3], pBuf[4],
266 pBuf[5], pBuf[6], pBuf[7]));
267 /*DBGPRINT_RAW(RT_DEBUG_ERROR, (">>BulkOutCompleteCancel=0x%x, BulkOutCompleteOther=0x%x\n", pAd->BulkOutCompleteCancel, pAd->BulkOutCompleteOther)); */
268
269 }
270
271 /* */
272 /* bInUse = TRUE, means some process are filling TX data, after that must turn on bWaitingBulkOut */
273 /* bWaitingBulkOut = TRUE, means the TX data are waiting for bulk out. */
274 /* */
275 /*RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); */
276 if ((pHTTXContext->ENextBulkOutPosition !=
277 pHTTXContext->CurWritePosition)
278 && (pHTTXContext->ENextBulkOutPosition !=
279 (pHTTXContext->CurWritePosition + 8))
280 && !RTUSB_TEST_BULK_FLAG(pAd,
281 (fRTUSB_BULK_OUT_DATA_FRAG <<
282 BulkOutPipeId))) {
283 /* Indicate There is data available */
284 RTUSB_SET_BULK_FLAG(pAd,
285 (fRTUSB_BULK_OUT_DATA_NORMAL <<
286 BulkOutPipeId));
287 }
288 /*RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); */
289
290 /* Always call Bulk routine, even reset bulk. */
291 /* The protection of rest bulk should be in BulkOut routine */
292 RTUSBKickBulkOut(pAd);
293}
294
295static void rtusb_null_frame_done_tasklet(unsigned long data)
296{
297 struct rt_rtmp_adapter *pAd;
298 struct rt_tx_context *pNullContext;
299 struct urb *pUrb;
300 int Status;
301 unsigned long irqFlag;
302
303 pUrb = (struct urb *)data;
304 pNullContext = (struct rt_tx_context *)pUrb->context;
305 pAd = pNullContext->pAd;
306 Status = pUrb->status;
307
308 /* Reset Null frame context flags */
309 RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag);
310 pNullContext->IRPPending = FALSE;
311 pNullContext->InUse = FALSE;
312 pAd->BulkOutPending[0] = FALSE;
313 pAd->watchDogTxPendingCnt[0] = 0;
314
315 if (Status == USB_ST_NOERROR) {
316 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
317
318 RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
319 } else { /* STATUS_OTHER */
320 if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
321 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
322 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
323 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) {
324 DBGPRINT_RAW(RT_DEBUG_ERROR,
325 ("Bulk Out Null Frame Failed, ReasonCode=%d!\n",
326 Status));
327 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
328 pAd->bulkResetPipeid =
329 (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
330 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
331 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT,
332 NULL, 0);
333 } else {
334 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
335 }
336 }
337
338 /* Always call Bulk routine, even reset bulk. */
339 /* The protection of rest bulk should be in BulkOut routine */
340 RTUSBKickBulkOut(pAd);
341}
342
343static void rtusb_rts_frame_done_tasklet(unsigned long data)
344{
345 struct rt_rtmp_adapter *pAd;
346 struct rt_tx_context *pRTSContext;
347 struct urb *pUrb;
348 int Status;
349 unsigned long irqFlag;
350
351 pUrb = (struct urb *)data;
352 pRTSContext = (struct rt_tx_context *)pUrb->context;
353 pAd = pRTSContext->pAd;
354 Status = pUrb->status;
355
356 /* Reset RTS frame context flags */
357 RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag);
358 pRTSContext->IRPPending = FALSE;
359 pRTSContext->InUse = FALSE;
360
361 if (Status == USB_ST_NOERROR) {
362 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
363 RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
364 } else { /* STATUS_OTHER */
365 if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
366 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
367 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
368 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) {
369 DBGPRINT_RAW(RT_DEBUG_ERROR,
370 ("Bulk Out RTS Frame Failed\n"));
371 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
372 pAd->bulkResetPipeid =
373 (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
374 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
375 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT,
376 NULL, 0);
377 } else {
378 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag);
379 }
380 }
381
382 RTMP_SEM_LOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]);
383 pAd->BulkOutPending[pRTSContext->BulkOutPipeId] = FALSE;
384 RTMP_SEM_UNLOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]);
385
386 /* Always call Bulk routine, even reset bulk. */
387 /* The protection of rest bulk should be in BulkOut routine */
388 RTUSBKickBulkOut(pAd);
389
390}
391
392static void rtusb_pspoll_frame_done_tasklet(unsigned long data)
393{
394 struct rt_rtmp_adapter *pAd;
395 struct rt_tx_context *pPsPollContext;
396 struct urb *pUrb;
397 int Status;
398
399 pUrb = (struct urb *)data;
400 pPsPollContext = (struct rt_tx_context *)pUrb->context;
401 pAd = pPsPollContext->pAd;
402 Status = pUrb->status;
403
404 /* Reset PsPoll context flags */
405 pPsPollContext->IRPPending = FALSE;
406 pPsPollContext->InUse = FALSE;
407 pAd->watchDogTxPendingCnt[0] = 0;
408
409 if (Status == USB_ST_NOERROR) {
410 RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
411 } else { /* STATUS_OTHER */
412 if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
413 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
414 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
415 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) {
416 DBGPRINT_RAW(RT_DEBUG_ERROR,
417 ("Bulk Out PSPoll Failed\n"));
418 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
419 pAd->bulkResetPipeid =
420 (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
421 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT,
422 NULL, 0);
423 }
424 }
425
426 RTMP_SEM_LOCK(&pAd->BulkOutLock[0]);
427 pAd->BulkOutPending[0] = FALSE;
428 RTMP_SEM_UNLOCK(&pAd->BulkOutLock[0]);
429
430 /* Always call Bulk routine, even reset bulk. */
431 /* The protection of rest bulk should be in BulkOut routine */
432 RTUSBKickBulkOut(pAd);
433
434}
435
436/*
437========================================================================
438Routine Description:
439 Handle received packets.
440
441Arguments:
442 data - URB information pointer
443
444Return Value:
445 None
446
447Note:
448========================================================================
449*/
450static void rx_done_tasklet(unsigned long data)
451{
452 struct urb *pUrb;
453 struct rt_rx_context *pRxContext;
454 struct rt_rtmp_adapter *pAd;
455 int Status;
456 unsigned int IrqFlags;
457
458 pUrb = (struct urb *)data;
459 pRxContext = (struct rt_rx_context *)pUrb->context;
460 pAd = pRxContext->pAd;
461 Status = pUrb->status;
462
463 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
464 pRxContext->InUse = FALSE;
465 pRxContext->IRPPending = FALSE;
466 pRxContext->BulkInOffset += pUrb->actual_length;
467 /*NdisInterlockedDecrement(&pAd->PendingRx); */
468 pAd->PendingRx--;
469
470 if (Status == USB_ST_NOERROR) {
471 pAd->BulkInComplete++;
472 pAd->NextRxBulkInPosition = 0;
473 if (pRxContext->BulkInOffset) { /* As jan's comment, it may bulk-in success but size is zero. */
474 pRxContext->Readable = TRUE;
475 INC_RING_INDEX(pAd->NextRxBulkInIndex, RX_RING_SIZE);
476 }
477 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
478 } else { /* STATUS_OTHER */
479 pAd->BulkInCompleteFail++;
480 /* Still read this packet although it may comtain wrong bytes. */
481 pRxContext->Readable = FALSE;
482 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
483
484 /* Parsing all packets. because after reset, the index will reset to all zero. */
485 if ((!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
486 fRTMP_ADAPTER_BULKIN_RESET |
487 fRTMP_ADAPTER_HALT_IN_PROGRESS |
488 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
489
490 DBGPRINT_RAW(RT_DEBUG_ERROR,
491 ("Bulk In Failed. Status=%d, BIIdx=0x%x, BIRIdx=0x%x, actual_length= 0x%x\n",
492 Status, pAd->NextRxBulkInIndex,
493 pAd->NextRxBulkInReadIndex,
494 pRxContext->pUrb->actual_length));
495
496 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
497 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN,
498 NULL, 0);
499 }
500 }
501
502 ASSERT((pRxContext->InUse == pRxContext->IRPPending));
503
504 RTUSBBulkReceive(pAd);
505
506 return;
507
508}
509
510static void rtusb_mgmt_dma_done_tasklet(unsigned long data)
511{
512 struct rt_rtmp_adapter *pAd;
513 struct rt_tx_context *pMLMEContext;
514 int index;
515 void *pPacket;
516 struct urb *pUrb;
517 int Status;
518 unsigned long IrqFlags;
519
520 pUrb = (struct urb *)data;
521 pMLMEContext = (struct rt_tx_context *)pUrb->context;
522 pAd = pMLMEContext->pAd;
523 Status = pUrb->status;
524 index = pMLMEContext->SelfIdx;
525
526 ASSERT((pAd->MgmtRing.TxDmaIdx == index));
527
528 RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
529
530 if (Status != USB_ST_NOERROR) {
531 /*Bulk-Out fail status handle */
532 if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) &&
533 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) &&
534 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&
535 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) {
536 DBGPRINT_RAW(RT_DEBUG_ERROR,
537 ("Bulk Out MLME Failed, Status=%d!\n",
538 Status));
539 /* TODO: How to handle about the MLMEBulkOut failed issue. Need to resend the mgmt pkt? */
540 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET);
541 pAd->bulkResetPipeid =
542 (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG);
543 }
544 }
545
546 pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
547 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
548
549 RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags);
550 /* Reset MLME context flags */
551 pMLMEContext->IRPPending = FALSE;
552 pMLMEContext->InUse = FALSE;
553 pMLMEContext->bWaitingBulkOut = FALSE;
554 pMLMEContext->BulkOutSize = 0;
555
556 pPacket = pAd->MgmtRing.Cell[index].pNdisPacket;
557 pAd->MgmtRing.Cell[index].pNdisPacket = NULL;
558
559 /* Increase MgmtRing Index */
560 INC_RING_INDEX(pAd->MgmtRing.TxDmaIdx, MGMT_RING_SIZE);
561 pAd->MgmtRing.TxSwFreeIdx++;
562 RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags);
563
564 /* No-matter success or fail, we free the mgmt packet. */
565 if (pPacket)
566 RTMPFreeNdisPacket(pAd, pPacket);
567
568 if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
569 fRTMP_ADAPTER_HALT_IN_PROGRESS |
570 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
571 /* do nothing and return directly. */
572 } else {
573 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET) && ((pAd->bulkResetPipeid & BULKOUT_MGMT_RESET_FLAG) == BULKOUT_MGMT_RESET_FLAG)) { /* For Mgmt Bulk-Out failed, ignore it now. */
574 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT,
575 NULL, 0);
576 } else {
577
578 /* Always call Bulk routine, even reset bulk. */
579 /* The protection of rest bulk should be in BulkOut routine */
580 if (pAd->MgmtRing.TxSwFreeIdx <
581 MGMT_RING_SIZE
582 /* pMLMEContext->bWaitingBulkOut == TRUE */) {
583 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
584 }
585 RTUSBKickBulkOut(pAd);
586 }
587 }
588
589}
590
591static void rtusb_ac3_dma_done_tasklet(unsigned long data)
592{
593 struct rt_rtmp_adapter *pAd;
594 struct rt_ht_tx_context *pHTTXContext;
595 u8 BulkOutPipeId = 3;
596 struct urb *pUrb;
597
598 pUrb = (struct urb *)data;
599 pHTTXContext = (struct rt_ht_tx_context *)pUrb->context;
600 pAd = pHTTXContext->pAd;
601
602 rtusb_dataout_complete((unsigned long)pUrb);
603
604 if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
605 fRTMP_ADAPTER_HALT_IN_PROGRESS |
606 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
607 /* do nothing and return directly. */
608 } else {
609 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) {
610 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT,
611 NULL, 0);
612 } else {
613 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
614 if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
615 /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
616 (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
617 (pHTTXContext->bCurWriting == FALSE)) {
618 RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId,
619 MAX_TX_PROCESS);
620 }
621
622 RTUSB_SET_BULK_FLAG(pAd,
623 fRTUSB_BULK_OUT_DATA_NORMAL << 3);
624 RTUSBKickBulkOut(pAd);
625 }
626 }
627
628 return;
629}
630
631static void rtusb_ac2_dma_done_tasklet(unsigned long data)
632{
633 struct rt_rtmp_adapter *pAd;
634 struct rt_ht_tx_context *pHTTXContext;
635 u8 BulkOutPipeId = 2;
636 struct urb *pUrb;
637
638 pUrb = (struct urb *)data;
639 pHTTXContext = (struct rt_ht_tx_context *)pUrb->context;
640 pAd = pHTTXContext->pAd;
641
642 rtusb_dataout_complete((unsigned long)pUrb);
643
644 if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
645 fRTMP_ADAPTER_HALT_IN_PROGRESS |
646 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
647 /* do nothing and return directly. */
648 } else {
649 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) {
650 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT,
651 NULL, 0);
652 } else {
653 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
654 if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
655 /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
656 (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
657 (pHTTXContext->bCurWriting == FALSE)) {
658 RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId,
659 MAX_TX_PROCESS);
660 }
661
662 RTUSB_SET_BULK_FLAG(pAd,
663 fRTUSB_BULK_OUT_DATA_NORMAL << 2);
664 RTUSBKickBulkOut(pAd);
665 }
666 }
667
668 return;
669}
670
671static void rtusb_ac1_dma_done_tasklet(unsigned long data)
672{
673 struct rt_rtmp_adapter *pAd;
674 struct rt_ht_tx_context *pHTTXContext;
675 u8 BulkOutPipeId = 1;
676 struct urb *pUrb;
677
678 pUrb = (struct urb *)data;
679 pHTTXContext = (struct rt_ht_tx_context *)pUrb->context;
680 pAd = pHTTXContext->pAd;
681
682 rtusb_dataout_complete((unsigned long)pUrb);
683
684 if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
685 fRTMP_ADAPTER_HALT_IN_PROGRESS |
686 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
687 /* do nothing and return directly. */
688 } else {
689 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) {
690 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT,
691 NULL, 0);
692 } else {
693 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
694 if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
695 /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
696 (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
697 (pHTTXContext->bCurWriting == FALSE)) {
698 RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId,
699 MAX_TX_PROCESS);
700 }
701
702 RTUSB_SET_BULK_FLAG(pAd,
703 fRTUSB_BULK_OUT_DATA_NORMAL << 1);
704 RTUSBKickBulkOut(pAd);
705 }
706 }
707 return;
708
709}
710
711static void rtusb_ac0_dma_done_tasklet(unsigned long data)
712{
713 struct rt_rtmp_adapter *pAd;
714 struct rt_ht_tx_context *pHTTXContext;
715 u8 BulkOutPipeId = 0;
716 struct urb *pUrb;
717
718 pUrb = (struct urb *)data;
719 pHTTXContext = (struct rt_ht_tx_context *)pUrb->context;
720 pAd = pHTTXContext->pAd;
721
722 rtusb_dataout_complete((unsigned long)pUrb);
723
724 if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
725 fRTMP_ADAPTER_HALT_IN_PROGRESS |
726 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
727 /* do nothing and return directly. */
728 } else {
729 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) {
730 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT,
731 NULL, 0);
732 } else {
733 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
734 if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) &&
735 /* ((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */
736 (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) &&
737 (pHTTXContext->bCurWriting == FALSE)) {
738 RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId,
739 MAX_TX_PROCESS);
740 }
741
742 RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL);
743 RTUSBKickBulkOut(pAd);
744 }
745 }
746
747 return;
748
749}
750
751int RtmpNetTaskInit(struct rt_rtmp_adapter *pAd)
752{
753 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
754
755 /* Create receive tasklet */
756 tasklet_init(&pObj->rx_done_task, rx_done_tasklet, (unsigned long)pAd);
757 tasklet_init(&pObj->mgmt_dma_done_task, rtusb_mgmt_dma_done_tasklet,
758 (unsigned long)pAd);
759 tasklet_init(&pObj->ac0_dma_done_task, rtusb_ac0_dma_done_tasklet,
760 (unsigned long)pAd);
761 tasklet_init(&pObj->ac1_dma_done_task, rtusb_ac1_dma_done_tasklet,
762 (unsigned long)pAd);
763 tasklet_init(&pObj->ac2_dma_done_task, rtusb_ac2_dma_done_tasklet,
764 (unsigned long)pAd);
765 tasklet_init(&pObj->ac3_dma_done_task, rtusb_ac3_dma_done_tasklet,
766 (unsigned long)pAd);
767 tasklet_init(&pObj->tbtt_task, tbtt_tasklet, (unsigned long)pAd);
768 tasklet_init(&pObj->null_frame_complete_task,
769 rtusb_null_frame_done_tasklet, (unsigned long)pAd);
770 tasklet_init(&pObj->rts_frame_complete_task,
771 rtusb_rts_frame_done_tasklet, (unsigned long)pAd);
772 tasklet_init(&pObj->pspoll_frame_complete_task,
773 rtusb_pspoll_frame_done_tasklet, (unsigned long)pAd);
774
775 return NDIS_STATUS_SUCCESS;
776}
777
778void RtmpNetTaskExit(struct rt_rtmp_adapter *pAd)
779{
780 struct os_cookie *pObj;
781
782 pObj = (struct os_cookie *)pAd->OS_Cookie;
783
784 tasklet_kill(&pObj->rx_done_task);
785 tasklet_kill(&pObj->mgmt_dma_done_task);
786 tasklet_kill(&pObj->ac0_dma_done_task);
787 tasklet_kill(&pObj->ac1_dma_done_task);
788 tasklet_kill(&pObj->ac2_dma_done_task);
789 tasklet_kill(&pObj->ac3_dma_done_task);
790 tasklet_kill(&pObj->tbtt_task);
791 tasklet_kill(&pObj->null_frame_complete_task);
792 tasklet_kill(&pObj->rts_frame_complete_task);
793 tasklet_kill(&pObj->pspoll_frame_complete_task);
794}
diff --git a/drivers/staging/rt2860/rtmp.h b/drivers/staging/rt2860/rtmp.h
deleted file mode 100644
index 3c31340c946..00000000000
--- a/drivers/staging/rt2860/rtmp.h
+++ /dev/null
@@ -1,4332 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp.h
29
30 Abstract:
31 Miniport generic portion header file
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Paul Lin 2002-08-01 created
37 James Tan 2002-09-06 modified (Revise NTCRegTable)
38 John Chang 2004-09-06 modified for RT2600
39 Justin P. Mattock 11/07/2010 Fix some typos
40*/
41#ifndef __RTMP_H__
42#define __RTMP_H__
43
44#include "spectrum_def.h"
45#include "rtmp_dot11.h"
46#include "rtmp_chip.h"
47
48struct rt_rtmp_adapter;
49
50/*#define DBG 1 */
51
52/*#define DBG_DIAGNOSE 1 */
53
54/*+++Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function */
55#define MAX_DATAMM_RETRY 3
56#define MGMT_USE_QUEUE_FLAG 0x80
57/*---Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function */
58
59#define MAXSEQ (0xFFF)
60
61extern unsigned char SNAP_AIRONET[];
62extern unsigned char CISCO_OUI[];
63extern u8 BaSizeArray[4];
64
65extern u8 BROADCAST_ADDR[MAC_ADDR_LEN];
66extern u8 ZERO_MAC_ADDR[MAC_ADDR_LEN];
67extern unsigned long BIT32[32];
68extern u8 BIT8[8];
69extern char *CipherName[];
70extern char *MCSToMbps[];
71extern u8 RxwiMCSToOfdmRate[12];
72extern u8 SNAP_802_1H[6];
73extern u8 SNAP_BRIDGE_TUNNEL[6];
74extern u8 SNAP_AIRONET[8];
75extern u8 CKIP_LLC_SNAP[8];
76extern u8 EAPOL_LLC_SNAP[8];
77extern u8 EAPOL[2];
78extern u8 IPX[2];
79extern u8 APPLE_TALK[2];
80extern u8 RateIdToPlcpSignal[12]; /* see IEEE802.11a-1999 p.14 */
81extern u8 OfdmRateToRxwiMCS[];
82extern u8 OfdmSignalToRateId[16];
83extern u8 default_cwmin[4];
84extern u8 default_cwmax[4];
85extern u8 default_sta_aifsn[4];
86extern u8 MapUserPriorityToAccessCategory[8];
87
88extern u16 RateUpPER[];
89extern u16 RateDownPER[];
90extern u8 Phy11BNextRateDownward[];
91extern u8 Phy11BNextRateUpward[];
92extern u8 Phy11BGNextRateDownward[];
93extern u8 Phy11BGNextRateUpward[];
94extern u8 Phy11ANextRateDownward[];
95extern u8 Phy11ANextRateUpward[];
96extern char RssiSafeLevelForTxRate[];
97extern u8 RateIdToMbps[];
98extern u16 RateIdTo500Kbps[];
99
100extern u8 CipherSuiteWpaNoneTkip[];
101extern u8 CipherSuiteWpaNoneTkipLen;
102
103extern u8 CipherSuiteWpaNoneAes[];
104extern u8 CipherSuiteWpaNoneAesLen;
105
106extern u8 SsidIe;
107extern u8 SupRateIe;
108extern u8 ExtRateIe;
109
110extern u8 HtCapIe;
111extern u8 AddHtInfoIe;
112extern u8 NewExtChanIe;
113
114extern u8 ErpIe;
115extern u8 DsIe;
116extern u8 TimIe;
117extern u8 WpaIe;
118extern u8 Wpa2Ie;
119extern u8 IbssIe;
120extern u8 Ccx2Ie;
121extern u8 WapiIe;
122
123extern u8 WPA_OUI[];
124extern u8 RSN_OUI[];
125extern u8 WAPI_OUI[];
126extern u8 WME_INFO_ELEM[];
127extern u8 WME_PARM_ELEM[];
128extern u8 Ccx2QosInfo[];
129extern u8 Ccx2IeInfo[];
130extern u8 RALINK_OUI[];
131extern u8 PowerConstraintIE[];
132
133extern u8 RateSwitchTable[];
134extern u8 RateSwitchTable11B[];
135extern u8 RateSwitchTable11G[];
136extern u8 RateSwitchTable11BG[];
137
138extern u8 RateSwitchTable11BGN1S[];
139extern u8 RateSwitchTable11BGN2S[];
140extern u8 RateSwitchTable11BGN2SForABand[];
141extern u8 RateSwitchTable11N1S[];
142extern u8 RateSwitchTable11N2S[];
143extern u8 RateSwitchTable11N2SForABand[];
144
145extern u8 PRE_N_HT_OUI[];
146
147struct rt_rssi_sample {
148 char LastRssi0; /* last received RSSI */
149 char LastRssi1; /* last received RSSI */
150 char LastRssi2; /* last received RSSI */
151 char AvgRssi0;
152 char AvgRssi1;
153 char AvgRssi2;
154 short AvgRssi0X8;
155 short AvgRssi1X8;
156 short AvgRssi2X8;
157};
158
159/* */
160/* Queue structure and macros */
161/* */
162struct rt_queue_entry;
163
164struct rt_queue_entry {
165 struct rt_queue_entry *Next;
166};
167
168/* Queue structure */
169struct rt_queue_header {
170 struct rt_queue_entry *Head;
171 struct rt_queue_entry *Tail;
172 unsigned long Number;
173};
174
175#define InitializeQueueHeader(QueueHeader) \
176{ \
177 (QueueHeader)->Head = (QueueHeader)->Tail = NULL; \
178 (QueueHeader)->Number = 0; \
179}
180
181#define RemoveHeadQueue(QueueHeader) \
182(QueueHeader)->Head; \
183{ \
184 struct rt_queue_entry *pNext; \
185 if ((QueueHeader)->Head != NULL) { \
186 pNext = (QueueHeader)->Head->Next; \
187 (QueueHeader)->Head->Next = NULL; \
188 (QueueHeader)->Head = pNext; \
189 if (pNext == NULL) \
190 (QueueHeader)->Tail = NULL; \
191 (QueueHeader)->Number--; \
192 } \
193}
194
195#define InsertHeadQueue(QueueHeader, QueueEntry) \
196{ \
197 ((struct rt_queue_entry *)QueueEntry)->Next = (QueueHeader)->Head; \
198 (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry); \
199 if ((QueueHeader)->Tail == NULL) \
200 (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry); \
201 (QueueHeader)->Number++; \
202}
203
204#define InsertTailQueue(QueueHeader, QueueEntry) \
205{ \
206 ((struct rt_queue_entry *)QueueEntry)->Next = NULL; \
207 if ((QueueHeader)->Tail) \
208 (QueueHeader)->Tail->Next = (struct rt_queue_entry *)(QueueEntry); \
209 else \
210 (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry); \
211 (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry); \
212 (QueueHeader)->Number++; \
213}
214
215#define InsertTailQueueAc(pAd, pEntry, QueueHeader, QueueEntry) \
216{ \
217 ((struct rt_queue_entry *)QueueEntry)->Next = NULL; \
218 if ((QueueHeader)->Tail) \
219 (QueueHeader)->Tail->Next = (struct rt_queue_entry *)(QueueEntry); \
220 else \
221 (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry); \
222 (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry); \
223 (QueueHeader)->Number++; \
224}
225
226/* */
227/* Macros for flag and ref count operations */
228/* */
229#define RTMP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
230#define RTMP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
231#define RTMP_CLEAR_FLAGS(_M) ((_M)->Flags = 0)
232#define RTMP_TEST_FLAG(_M, _F) (((_M)->Flags & (_F)) != 0)
233#define RTMP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
234/* Macro for power save flag. */
235#define RTMP_SET_PSFLAG(_M, _F) ((_M)->PSFlags |= (_F))
236#define RTMP_CLEAR_PSFLAG(_M, _F) ((_M)->PSFlags &= ~(_F))
237#define RTMP_CLEAR_PSFLAGS(_M) ((_M)->PSFlags = 0)
238#define RTMP_TEST_PSFLAG(_M, _F) (((_M)->PSFlags & (_F)) != 0)
239#define RTMP_TEST_PSFLAGS(_M, _F) (((_M)->PSFlags & (_F)) == (_F))
240
241#define OPSTATUS_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags |= (_F))
242#define OPSTATUS_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags &= ~(_F))
243#define OPSTATUS_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.OpStatusFlags & (_F)) != 0)
244
245#define CLIENT_STATUS_SET_FLAG(_pEntry, _F) ((_pEntry)->ClientStatusFlags |= (_F))
246#define CLIENT_STATUS_CLEAR_FLAG(_pEntry, _F) ((_pEntry)->ClientStatusFlags &= ~(_F))
247#define CLIENT_STATUS_TEST_FLAG(_pEntry, _F) (((_pEntry)->ClientStatusFlags & (_F)) != 0)
248
249#define RX_FILTER_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter |= (_F))
250#define RX_FILTER_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter &= ~(_F))
251#define RX_FILTER_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.PacketFilter & (_F)) != 0)
252
253#define STA_NO_SECURITY_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11EncryptionDisabled)
254#define STA_WEP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
255#define STA_TKIP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
256#define STA_AES_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)
257
258#define STA_TGN_WIFI_ON(_p) (_p->StaCfg.bTGnWifiTest == TRUE)
259
260#define CKIP_KP_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x10) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
261#define CKIP_CMIC_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x08) && ((_p)->StaCfg.bCkipCmicOn == TRUE))
262
263#define INC_RING_INDEX(_idx, _RingSize) \
264{ \
265 (_idx) = (_idx+1) % (_RingSize); \
266}
267
268/* StaActive.SupportedHtPhy.MCSSet is copied from AP beacon. Don't need to update here. */
269#define COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
270{ \
271 _pAd->StaActive.SupportedHtPhy.ChannelWidth = _pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth; \
272 _pAd->StaActive.SupportedHtPhy.MimoPs = _pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs; \
273 _pAd->StaActive.SupportedHtPhy.GF = _pAd->MlmeAux.HtCapability.HtCapInfo.GF; \
274 _pAd->StaActive.SupportedHtPhy.ShortGIfor20 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20; \
275 _pAd->StaActive.SupportedHtPhy.ShortGIfor40 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40; \
276 _pAd->StaActive.SupportedHtPhy.TxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC; \
277 _pAd->StaActive.SupportedHtPhy.RxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC; \
278 _pAd->StaActive.SupportedHtPhy.ExtChanOffset = _pAd->MlmeAux.AddHtInfo.AddHtInfo.ExtChanOffset; \
279 _pAd->StaActive.SupportedHtPhy.RecomWidth = _pAd->MlmeAux.AddHtInfo.AddHtInfo.RecomWidth; \
280 _pAd->StaActive.SupportedHtPhy.OperaionMode = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode; \
281 _pAd->StaActive.SupportedHtPhy.NonGfPresent = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent; \
282 NdisMoveMemory((_pAd)->MacTab.Content[BSSID_WCID].HTCapability.MCSSet, (_pAd)->StaActive.SupportedPhyInfo.MCSSet, sizeof(u8) * 16);\
283}
284
285#define COPY_AP_HTSETTINGS_FROM_BEACON(_pAd, _pHtCapability) \
286{ \
287 _pAd->MacTab.Content[BSSID_WCID].AMsduSize = (u8)(_pHtCapability->HtCapInfo.AMsduSize); \
288 _pAd->MacTab.Content[BSSID_WCID].MmpsMode = (u8)(_pHtCapability->HtCapInfo.MimoPs); \
289 _pAd->MacTab.Content[BSSID_WCID].MaxRAmpduFactor = (u8)(_pHtCapability->HtCapParm.MaxRAmpduFactor); \
290}
291
292/* */
293/* MACRO for 32-bit PCI register read / write */
294/* */
295/* Usage : RTMP_IO_READ32( */
296/* struct rt_rtmp_adapter *pAd, */
297/* unsigned long Register_Offset, */
298/* unsigned long * pValue) */
299/* */
300/* RTMP_IO_WRITE32( */
301/* struct rt_rtmp_adapter *pAd, */
302/* unsigned long Register_Offset, */
303/* unsigned long Value) */
304/* */
305
306/* */
307/* Common fragment list structure - Identical to the scatter gather frag list structure */
308/* */
309/*#define struct rt_rtmp_sg_element SCATTER_GATHER_ELEMENT */
310/*#define struct rt_rtmp_sg_element *PSCATTER_GATHER_ELEMENT */
311#define NIC_MAX_PHYS_BUF_COUNT 8
312
313struct rt_rtmp_sg_element {
314 void *Address;
315 unsigned long Length;
316 unsigned long *Reserved;
317};
318
319struct rt_rtmp_sg_list {
320 unsigned long NumberOfElements;
321 unsigned long *Reserved;
322 struct rt_rtmp_sg_element Elements[NIC_MAX_PHYS_BUF_COUNT];
323};
324
325/* */
326/* Some utility macros */
327/* */
328#define GET_LNA_GAIN(_pAd) ((_pAd->LatchRfRegs.Channel <= 14) ? (_pAd->BLNAGain) : ((_pAd->LatchRfRegs.Channel <= 64) ? (_pAd->ALNAGain0) : ((_pAd->LatchRfRegs.Channel <= 128) ? (_pAd->ALNAGain1) : (_pAd->ALNAGain2))))
329
330#define INC_COUNTER64(Val) (Val.QuadPart++)
331
332#define INFRA_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_INFRA_ON))
333#define ADHOC_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_ADHOC_ON))
334#define MONITOR_ON(_p) (((_p)->StaCfg.BssType) == BSS_MONITOR)
335#define IDLE_ON(_p) (!INFRA_ON(_p) && !ADHOC_ON(_p))
336
337/* Check LEAP & CCKM flags */
338#define LEAP_ON(_p) (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP)
339#define LEAP_CCKM_ON(_p) ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE))
340
341/* if original Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required */
342#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap) \
343{ \
344 if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) { \
345 _pExtraLlcSnapEncap = SNAP_802_1H; \
346 if (NdisEqualMemory(IPX, _pBufVA + 12, 2) || \
347 NdisEqualMemory(APPLE_TALK, _pBufVA + 12, 2)) { \
348 _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \
349 } \
350 } \
351 else { \
352 _pExtraLlcSnapEncap = NULL; \
353 } \
354}
355
356/* New Define for new Tx Path. */
357#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(_pBufVA, _pExtraLlcSnapEncap) \
358{ \
359 if (((*(_pBufVA) << 8) + *(_pBufVA + 1)) > 1500) { \
360 _pExtraLlcSnapEncap = SNAP_802_1H; \
361 if (NdisEqualMemory(IPX, _pBufVA, 2) || \
362 NdisEqualMemory(APPLE_TALK, _pBufVA, 2)) { \
363 _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \
364 } \
365 } \
366 else { \
367 _pExtraLlcSnapEncap = NULL; \
368 } \
369}
370
371#define MAKE_802_3_HEADER(_p, _pMac1, _pMac2, _pType) \
372{ \
373 NdisMoveMemory(_p, _pMac1, MAC_ADDR_LEN); \
374 NdisMoveMemory((_p + MAC_ADDR_LEN), _pMac2, MAC_ADDR_LEN); \
375 NdisMoveMemory((_p + MAC_ADDR_LEN * 2), _pType, LENGTH_802_3_TYPE); \
376}
377
378/* if pData has no LLC/SNAP (neither RFC1042 nor Bridge tunnel), keep it that way. */
379/* else if the received frame is LLC/SNAP-encaped IPX or APPLETALK, preserve the LLC/SNAP field */
380/* else remove the LLC/SNAP field from the result Ethernet frame */
381/* Patch for WHQL only, which did not turn on Netbios but use IPX within its payload */
382/* Note: */
383/* _pData & _DataSize may be altered (remove 8-byte LLC/SNAP) by this MACRO */
384/* _pRemovedLLCSNAP: pointer to removed LLC/SNAP; NULL is not removed */
385#define CONVERT_TO_802_3(_p8023hdr, _pDA, _pSA, _pData, _DataSize, _pRemovedLLCSNAP) \
386{ \
387 char LLC_Len[2]; \
388 \
389 _pRemovedLLCSNAP = NULL; \
390 if (NdisEqualMemory(SNAP_802_1H, _pData, 6) || \
391 NdisEqualMemory(SNAP_BRIDGE_TUNNEL, _pData, 6)) { \
392 u8 *pProto = _pData + 6; \
393 \
394 if ((NdisEqualMemory(IPX, pProto, 2) || NdisEqualMemory(APPLE_TALK, pProto, 2)) && \
395 NdisEqualMemory(SNAP_802_1H, _pData, 6)) { \
396 LLC_Len[0] = (u8)(_DataSize / 256); \
397 LLC_Len[1] = (u8)(_DataSize % 256); \
398 MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \
399 } \
400 else { \
401 MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, pProto); \
402 _pRemovedLLCSNAP = _pData; \
403 _DataSize -= LENGTH_802_1_H; \
404 _pData += LENGTH_802_1_H; \
405 } \
406 } \
407 else { \
408 LLC_Len[0] = (u8)(_DataSize / 256); \
409 LLC_Len[1] = (u8)(_DataSize % 256); \
410 MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \
411 } \
412}
413
414/* Enqueue this frame to MLME engine */
415/* We need to enqueue the whole frame because MLME need to pass data type */
416/* information from 802.11 header */
417#ifdef RTMP_MAC_PCI
418#define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal) \
419{ \
420 u32 High32TSF, Low32TSF; \
421 RTMP_IO_READ32(_pAd, TSF_TIMER_DW1, &High32TSF); \
422 RTMP_IO_READ32(_pAd, TSF_TIMER_DW0, &Low32TSF); \
423 MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (u8)_Rssi0, (u8)_Rssi1, (u8)_Rssi2, _FrameSize, _pFrame, (u8)_PlcpSignal); \
424}
425#endif /* RTMP_MAC_PCI // */
426#ifdef RTMP_MAC_USB
427#define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal) \
428{ \
429 u32 High32TSF = 0, Low32TSF = 0; \
430 MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (u8)_Rssi0, (u8)_Rssi1, (u8)_Rssi2, _FrameSize, _pFrame, (u8)_PlcpSignal); \
431}
432#endif /* RTMP_MAC_USB // */
433
434#define MAC_ADDR_EQUAL(pAddr1, pAddr2) RTMPEqualMemory((void *)(pAddr1), (void *)(pAddr2), MAC_ADDR_LEN)
435#define SSID_EQUAL(ssid1, len1, ssid2, len2) ((len1 == len2) && (RTMPEqualMemory(ssid1, ssid2, len1)))
436
437/* */
438/* Check if it is Japan W53(ch52,56,60,64) channel. */
439/* */
440#define JapanChannelCheck(channel) ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64))
441
442#define STA_EXTRA_SETTING(_pAd)
443
444#define STA_PORT_SECURED(_pAd) \
445{ \
446 BOOLEAN Cancelled; \
447 (_pAd)->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; \
448 NdisAcquireSpinLock(&((_pAd)->MacTabLock)); \
449 (_pAd)->MacTab.Content[BSSID_WCID].PortSecured = (_pAd)->StaCfg.PortSecured; \
450 (_pAd)->MacTab.Content[BSSID_WCID].PrivacyFilter = Ndis802_11PrivFilterAcceptAll;\
451 NdisReleaseSpinLock(&(_pAd)->MacTabLock); \
452 RTMPCancelTimer(&((_pAd)->Mlme.LinkDownTimer), &Cancelled);\
453 STA_EXTRA_SETTING(_pAd); \
454}
455
456/* */
457/* Data buffer for DMA operation, the buffer must be contiguous physical memory */
458/* Both DMA to / from CPU use the same structure. */
459/* */
460struct rt_rtmp_dmabuf {
461 unsigned long AllocSize;
462 void *AllocVa; /* TxBuf virtual address */
463 dma_addr_t AllocPa; /* TxBuf physical address */
464};
465
466/* */
467/* Control block (Descriptor) for all ring descriptor DMA operation, buffer must be */
468/* contiguous physical memory. char stored the binding Rx packet descriptor */
469/* which won't be released, driver has to wait until upper layer return the packet */
470/* before giving up this rx ring descriptor to ASIC. NDIS_BUFFER is associated pair */
471/* to describe the packet buffer. For Tx, char stored the tx packet descriptor */
472/* which driver should ACK upper layer when the tx is physically done or failed. */
473/* */
474struct rt_rtmp_dmacb {
475 unsigned long AllocSize; /* Control block size */
476 void *AllocVa; /* Control block virtual address */
477 dma_addr_t AllocPa; /* Control block physical address */
478 void *pNdisPacket;
479 void *pNextNdisPacket;
480
481 struct rt_rtmp_dmabuf DmaBuf; /* Associated DMA buffer structure */
482};
483
484struct rt_rtmp_tx_ring {
485 struct rt_rtmp_dmacb Cell[TX_RING_SIZE];
486 u32 TxCpuIdx;
487 u32 TxDmaIdx;
488 u32 TxSwFreeIdx; /* software next free tx index */
489};
490
491struct rt_rtmp_rx_ring {
492 struct rt_rtmp_dmacb Cell[RX_RING_SIZE];
493 u32 RxCpuIdx;
494 u32 RxDmaIdx;
495 int RxSwReadIdx; /* software next read index */
496};
497
498struct rt_rtmp_mgmt_ring {
499 struct rt_rtmp_dmacb Cell[MGMT_RING_SIZE];
500 u32 TxCpuIdx;
501 u32 TxDmaIdx;
502 u32 TxSwFreeIdx; /* software next free tx index */
503};
504
505/* */
506/* Statistic counter structure */
507/* */
508struct rt_counter_802_3 {
509 /* General Stats */
510 unsigned long GoodTransmits;
511 unsigned long GoodReceives;
512 unsigned long TxErrors;
513 unsigned long RxErrors;
514 unsigned long RxNoBuffer;
515
516 /* Ethernet Stats */
517 unsigned long RcvAlignmentErrors;
518 unsigned long OneCollision;
519 unsigned long MoreCollisions;
520
521};
522
523struct rt_counter_802_11 {
524 unsigned long Length;
525 LARGE_INTEGER LastTransmittedFragmentCount;
526 LARGE_INTEGER TransmittedFragmentCount;
527 LARGE_INTEGER MulticastTransmittedFrameCount;
528 LARGE_INTEGER FailedCount;
529 LARGE_INTEGER RetryCount;
530 LARGE_INTEGER MultipleRetryCount;
531 LARGE_INTEGER RTSSuccessCount;
532 LARGE_INTEGER RTSFailureCount;
533 LARGE_INTEGER ACKFailureCount;
534 LARGE_INTEGER FrameDuplicateCount;
535 LARGE_INTEGER ReceivedFragmentCount;
536 LARGE_INTEGER MulticastReceivedFrameCount;
537 LARGE_INTEGER FCSErrorCount;
538};
539
540struct rt_counter_ralink {
541 unsigned long TransmittedByteCount; /* both successful and failure, used to calculate TX throughput */
542 unsigned long ReceivedByteCount; /* both CRC okay and CRC error, used to calculate RX throughput */
543 unsigned long BeenDisassociatedCount;
544 unsigned long BadCQIAutoRecoveryCount;
545 unsigned long PoorCQIRoamingCount;
546 unsigned long MgmtRingFullCount;
547 unsigned long RxCountSinceLastNULL;
548 unsigned long RxCount;
549 unsigned long RxRingErrCount;
550 unsigned long KickTxCount;
551 unsigned long TxRingErrCount;
552 LARGE_INTEGER RealFcsErrCount;
553 unsigned long PendingNdisPacketCount;
554
555 unsigned long OneSecOsTxCount[NUM_OF_TX_RING];
556 unsigned long OneSecDmaDoneCount[NUM_OF_TX_RING];
557 u32 OneSecTxDoneCount;
558 unsigned long OneSecRxCount;
559 u32 OneSecTxAggregationCount;
560 u32 OneSecRxAggregationCount;
561 u32 OneSecReceivedByteCount;
562 u32 OneSecFrameDuplicateCount;
563
564 u32 OneSecTransmittedByteCount; /* both successful and failure, used to calculate TX throughput */
565 u32 OneSecTxNoRetryOkCount;
566 u32 OneSecTxRetryOkCount;
567 u32 OneSecTxFailCount;
568 u32 OneSecFalseCCACnt; /* CCA error count, for debug purpose, might move to global counter */
569 u32 OneSecRxOkCnt; /* RX without error */
570 u32 OneSecRxOkDataCnt; /* unicast-to-me DATA frame count */
571 u32 OneSecRxFcsErrCnt; /* CRC error */
572 u32 OneSecBeaconSentCnt;
573 u32 LastOneSecTotalTxCount; /* OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount */
574 u32 LastOneSecRxOkDataCnt; /* OneSecRxOkDataCnt */
575 unsigned long DuplicateRcv;
576 unsigned long TxAggCount;
577 unsigned long TxNonAggCount;
578 unsigned long TxAgg1MPDUCount;
579 unsigned long TxAgg2MPDUCount;
580 unsigned long TxAgg3MPDUCount;
581 unsigned long TxAgg4MPDUCount;
582 unsigned long TxAgg5MPDUCount;
583 unsigned long TxAgg6MPDUCount;
584 unsigned long TxAgg7MPDUCount;
585 unsigned long TxAgg8MPDUCount;
586 unsigned long TxAgg9MPDUCount;
587 unsigned long TxAgg10MPDUCount;
588 unsigned long TxAgg11MPDUCount;
589 unsigned long TxAgg12MPDUCount;
590 unsigned long TxAgg13MPDUCount;
591 unsigned long TxAgg14MPDUCount;
592 unsigned long TxAgg15MPDUCount;
593 unsigned long TxAgg16MPDUCount;
594
595 LARGE_INTEGER TransmittedOctetsInAMSDU;
596 LARGE_INTEGER TransmittedAMSDUCount;
597 LARGE_INTEGER ReceivedOctesInAMSDUCount;
598 LARGE_INTEGER ReceivedAMSDUCount;
599 LARGE_INTEGER TransmittedAMPDUCount;
600 LARGE_INTEGER TransmittedMPDUsInAMPDUCount;
601 LARGE_INTEGER TransmittedOctetsInAMPDUCount;
602 LARGE_INTEGER MPDUInReceivedAMPDUCount;
603};
604
605struct rt_counter_drs {
606 /* record each TX rate's quality. 0 is best, the bigger the worse. */
607 u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
608 u8 PER[MAX_STEP_OF_TX_RATE_SWITCH];
609 u8 TxRateUpPenalty; /* extra # of second penalty due to last unstable condition */
610 unsigned long CurrTxRateStableTime; /* # of second in current TX rate */
611 BOOLEAN fNoisyEnvironment;
612 BOOLEAN fLastSecAccordingRSSI;
613 u8 LastSecTxRateChangeAction; /* 0: no change, 1:rate UP, 2:rate down */
614 u8 LastTimeTxRateChangeAction; /*Keep last time value of LastSecTxRateChangeAction */
615 unsigned long LastTxOkCount;
616};
617
618/***************************************************************************
619 * security key related data structure
620 **************************************************************************/
621struct rt_cipher_key {
622 u8 Key[16]; /* right now we implement 4 keys, 128 bits max */
623 u8 RxMic[8]; /* make alignment */
624 u8 TxMic[8];
625 u8 TxTsc[6]; /* 48bit TSC value */
626 u8 RxTsc[6]; /* 48bit TSC value */
627 u8 CipherAlg; /* 0-none, 1:WEP64, 2:WEP128, 3:TKIP, 4:AES, 5:CKIP64, 6:CKIP128 */
628 u8 KeyLen;
629 u8 BssId[6];
630 /* Key length for each key, 0: entry is invalid */
631 u8 Type; /* Indicate Pairwise/Group when reporting MIC error */
632};
633
634/* structure to define WPA Group Key Rekey Interval */
635struct PACKED rt_802_11_wpa_rekey {
636 unsigned long ReKeyMethod; /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
637 unsigned long ReKeyInterval; /* time-based: seconds, packet-based: kilo-packets */
638};
639
640#ifdef RTMP_MAC_USB
641/***************************************************************************
642 * RTUSB I/O related data structure
643 **************************************************************************/
644struct rt_set_asic_wcid {
645 unsigned long WCID; /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
646 unsigned long SetTid; /* time-based: seconds, packet-based: kilo-packets */
647 unsigned long DeleteTid; /* time-based: seconds, packet-based: kilo-packets */
648 u8 Addr[MAC_ADDR_LEN]; /* avoid in interrupt when write key */
649};
650
651struct rt_set_asic_wcid_attri {
652 unsigned long WCID; /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */
653 unsigned long Cipher; /* ASIC Cipher definition */
654 u8 Addr[ETH_LENGTH_OF_ADDRESS];
655};
656
657/* for USB interface, avoid in interrupt when write key */
658struct rt_add_pairwise_key_entry {
659 u8 MacAddr[6];
660 u16 MacTabMatchWCID; /* ASIC */
661 struct rt_cipher_key CipherKey;
662};
663
664/* Cipher suite type for mixed mode group cipher, P802.11i-2004 */
665typedef enum _RT_802_11_CIPHER_SUITE_TYPE {
666 Cipher_Type_NONE,
667 Cipher_Type_WEP40,
668 Cipher_Type_TKIP,
669 Cipher_Type_RSVD,
670 Cipher_Type_CCMP,
671 Cipher_Type_WEP104
672} RT_802_11_CIPHER_SUITE_TYPE, *PRT_802_11_CIPHER_SUITE_TYPE;
673#endif /* RTMP_MAC_USB // */
674
675struct rt_rogueap_entry {
676 u8 Addr[MAC_ADDR_LEN];
677 u8 ErrorCode[2]; /*00 01-Invalid authentication type */
678 /*00 02-Authentication timeout */
679 /*00 03-Challenge from AP failed */
680 /*00 04-Challenge to AP failed */
681 BOOLEAN Reported;
682};
683
684struct rt_rogueap_table {
685 u8 RogueApNr;
686 struct rt_rogueap_entry RogueApEntry[MAX_LEN_OF_BSS_TABLE];
687};
688
689/* */
690/* Cisco IAPP format */
691/* */
692struct rt_cisco_iapp_content {
693 u16 Length; /*IAPP Length */
694 u8 MessageType; /*IAPP type */
695 u8 FunctionCode; /*IAPP function type */
696 u8 DestinaionMAC[MAC_ADDR_LEN];
697 u8 SourceMAC[MAC_ADDR_LEN];
698 u16 Tag; /*Tag(element IE) - Adjacent AP report */
699 u16 TagLength; /*Length of element not including 4 byte header */
700 u8 OUI[4]; /*0x00, 0x40, 0x96, 0x00 */
701 u8 PreviousAP[MAC_ADDR_LEN]; /*MAC Address of access point */
702 u16 Channel;
703 u16 SsidLen;
704 u8 Ssid[MAX_LEN_OF_SSID];
705 u16 Seconds; /*Seconds that the client has been disassociated. */
706};
707
708/*
709 * Fragment Frame structure
710 */
711struct rt_fragment_frame {
712 void *pFragPacket;
713 unsigned long RxSize;
714 u16 Sequence;
715 u16 LastFrag;
716 unsigned long Flags; /* Some extra frame information. bit 0: LLC presented */
717};
718
719/* */
720/* Packet information for NdisQueryPacket */
721/* */
722struct rt_packet_info {
723 u32 PhysicalBufferCount; /* Physical breaks of buffer descriptor chained */
724 u32 BufferCount; /* Number of Buffer descriptor chained */
725 u32 TotalPacketLength; /* Self explained */
726 char *pFirstBuffer; /* Pointer to first buffer descriptor */
727};
728
729/* */
730/* Arcfour Structure Added by PaulWu */
731/* */
732struct rt_arcfourcontext {
733 u32 X;
734 u32 Y;
735 u8 STATE[256];
736};
737
738/* */
739/* Tkip Key structure which RC4 key & MIC calculation */
740/* */
741struct rt_tkip_key_info {
742 u32 nBytesInM; /* # bytes in M for MICKEY */
743 unsigned long IV16;
744 unsigned long IV32;
745 unsigned long K0; /* for MICKEY Low */
746 unsigned long K1; /* for MICKEY Hig */
747 unsigned long L; /* Current state for MICKEY */
748 unsigned long R; /* Current state for MICKEY */
749 unsigned long M; /* Message accumulator for MICKEY */
750 u8 RC4KEY[16];
751 u8 MIC[8];
752};
753
754/* */
755/* Private / Misc data, counters for driver internal use */
756/* */
757struct rt_private {
758 u32 SystemResetCnt; /* System reset counter */
759 u32 TxRingFullCnt; /* Tx ring full occurrence number */
760 u32 PhyRxErrCnt; /* PHY Rx error count, for debug purpose, might move to global counter */
761 /* Variables for WEP encryption / decryption in rtmp_wep.c */
762 u32 FCSCRC32;
763 struct rt_arcfourcontext WEPCONTEXT;
764 /* Tkip stuff */
765 struct rt_tkip_key_info Tx;
766 struct rt_tkip_key_info Rx;
767};
768
769/***************************************************************************
770 * Channel and BBP related data structures
771 **************************************************************************/
772/* structure to tune BBP R66 (BBP TUNING) */
773struct rt_bbp_r66_tuning {
774 BOOLEAN bEnable;
775 u16 FalseCcaLowerThreshold; /* default 100 */
776 u16 FalseCcaUpperThreshold; /* default 512 */
777 u8 R66Delta;
778 u8 R66CurrentValue;
779 BOOLEAN R66LowerUpperSelect; /*Before LinkUp, Used LowerBound or UpperBound as R66 value. */
780};
781
782/* structure to store channel TX power */
783struct rt_channel_tx_power {
784 u16 RemainingTimeForUse; /*unit: sec */
785 u8 Channel;
786 char Power;
787 char Power2;
788 u8 MaxTxPwr;
789 u8 DfsReq;
790};
791
792/* structure to store 802.11j channel TX power */
793struct rt_channel_11j_tx_power {
794 u8 Channel;
795 u8 BW; /* BW_10 or BW_20 */
796 char Power;
797 char Power2;
798 u16 RemainingTimeForUse; /*unit: sec */
799};
800
801struct rt_soft_rx_ant_diversity {
802 u8 EvaluatePeriod; /* 0:not evalute status, 1: evaluate status, 2: switching status */
803 u8 EvaluateStableCnt;
804 u8 Pair1PrimaryRxAnt; /* 0:Ant-E1, 1:Ant-E2 */
805 u8 Pair1SecondaryRxAnt; /* 0:Ant-E1, 1:Ant-E2 */
806 u8 Pair2PrimaryRxAnt; /* 0:Ant-E3, 1:Ant-E4 */
807 u8 Pair2SecondaryRxAnt; /* 0:Ant-E3, 1:Ant-E4 */
808 short Pair1AvgRssi[2]; /* AvgRssi[0]:E1, AvgRssi[1]:E2 */
809 short Pair2AvgRssi[2]; /* AvgRssi[0]:E3, AvgRssi[1]:E4 */
810 short Pair1LastAvgRssi; /* */
811 short Pair2LastAvgRssi; /* */
812 unsigned long RcvPktNumWhenEvaluate;
813 BOOLEAN FirstPktArrivedWhenEvaluate;
814 struct rt_ralink_timer RxAntDiversityTimer;
815};
816
817/***************************************************************************
818 * structure for radar detection and channel switch
819 **************************************************************************/
820struct rt_radar_detect {
821 /*BOOLEAN IEEE80211H; // 0: disable, 1: enable IEEE802.11h */
822 u8 CSCount; /*Channel switch counter */
823 u8 CSPeriod; /*Channel switch period (beacon count) */
824 u8 RDCount; /*Radar detection counter */
825 u8 RDMode; /*Radar Detection mode */
826 u8 RDDurRegion; /*Radar detection duration region */
827 u8 BBPR16;
828 u8 BBPR17;
829 u8 BBPR18;
830 u8 BBPR21;
831 u8 BBPR22;
832 u8 BBPR64;
833 unsigned long InServiceMonitorCount; /* unit: sec */
834 u8 DfsSessionTime;
835 BOOLEAN bFastDfs;
836 u8 ChMovingTime;
837 u8 LongPulseRadarTh;
838};
839
840typedef enum _ABGBAND_STATE_ {
841 UNKNOWN_BAND,
842 BG_BAND,
843 A_BAND,
844} ABGBAND_STATE;
845
846#ifdef RTMP_MAC_PCI
847/* Power save method control */
848typedef union _PS_CONTROL {
849 struct {
850 unsigned long EnablePSinIdle:1; /* Enable radio off when not connected to AP. radio on only when sitesurvey, */
851 unsigned long EnableNewPS:1; /* Enable new Chip power save function . New method can only be applied in chip version after 2872. and PCIe. */
852 unsigned long rt30xxPowerMode:2; /* Power Level Mode for rt30xx chip */
853 unsigned long rt30xxFollowHostASPM:1; /* Card Follows Host's setting for rt30xx chip. */
854 unsigned long rt30xxForceASPMTest:1; /* Force enable L1 for rt30xx chip. This has higher priority than rt30xxFollowHostASPM Mode. */
855 unsigned long rsv:26; /* Radio Measurement Enable */
856 } field;
857 unsigned long word;
858} PS_CONTROL, *PPS_CONTROL;
859#endif /* RTMP_MAC_PCI // */
860
861/***************************************************************************
862 * structure for MLME state machine
863 **************************************************************************/
864struct rt_mlme {
865 /* STA state machines */
866 struct rt_state_machine CntlMachine;
867 struct rt_state_machine AssocMachine;
868 struct rt_state_machine AuthMachine;
869 struct rt_state_machine AuthRspMachine;
870 struct rt_state_machine SyncMachine;
871 struct rt_state_machine WpaPskMachine;
872 struct rt_state_machine LeapMachine;
873 STATE_MACHINE_FUNC AssocFunc[ASSOC_FUNC_SIZE];
874 STATE_MACHINE_FUNC AuthFunc[AUTH_FUNC_SIZE];
875 STATE_MACHINE_FUNC AuthRspFunc[AUTH_RSP_FUNC_SIZE];
876 STATE_MACHINE_FUNC SyncFunc[SYNC_FUNC_SIZE];
877 STATE_MACHINE_FUNC ActFunc[ACT_FUNC_SIZE];
878 /* Action */
879 struct rt_state_machine ActMachine;
880
881 /* common WPA state machine */
882 struct rt_state_machine WpaMachine;
883 STATE_MACHINE_FUNC WpaFunc[WPA_FUNC_SIZE];
884
885 unsigned long ChannelQuality; /* 0..100, Channel Quality Indication for Roaming */
886 unsigned long Now32; /* latch the value of NdisGetSystemUpTime() */
887 unsigned long LastSendNULLpsmTime;
888
889 BOOLEAN bRunning;
890 spinlock_t TaskLock;
891 struct rt_mlme_queue Queue;
892
893 u32 ShiftReg;
894
895 struct rt_ralink_timer PeriodicTimer;
896 struct rt_ralink_timer APSDPeriodicTimer;
897 struct rt_ralink_timer LinkDownTimer;
898 struct rt_ralink_timer LinkUpTimer;
899#ifdef RTMP_MAC_PCI
900 u8 bPsPollTimerRunning;
901 struct rt_ralink_timer PsPollTimer;
902 struct rt_ralink_timer RadioOnOffTimer;
903#endif /* RTMP_MAC_PCI // */
904 unsigned long PeriodicRound;
905 unsigned long OneSecPeriodicRound;
906
907 u8 RealRxPath;
908 BOOLEAN bLowThroughput;
909 BOOLEAN bEnableAutoAntennaCheck;
910 struct rt_ralink_timer RxAntEvalTimer;
911
912#ifdef RT30xx
913 u8 CaliBW40RfR24;
914 u8 CaliBW20RfR24;
915#endif /* RT30xx // */
916
917#ifdef RTMP_MAC_USB
918 struct rt_ralink_timer AutoWakeupTimer;
919 BOOLEAN AutoWakeupTimerRunning;
920#endif /* RTMP_MAC_USB // */
921};
922
923/***************************************************************************
924 * 802.11 N related data structures
925 **************************************************************************/
926struct reordering_mpdu {
927 struct reordering_mpdu *next;
928 void *pPacket; /* converted to 802.3 frame */
929 int Sequence; /* sequence number of MPDU */
930 BOOLEAN bAMSDU;
931};
932
933struct reordering_list {
934 struct reordering_mpdu *next;
935 int qlen;
936};
937
938struct reordering_mpdu_pool {
939 void *mem;
940 spinlock_t lock;
941 struct reordering_list freelist;
942};
943
944typedef enum _REC_BLOCKACK_STATUS {
945 Recipient_NONE = 0,
946 Recipient_USED,
947 Recipient_HandleRes,
948 Recipient_Accept
949} REC_BLOCKACK_STATUS, *PREC_BLOCKACK_STATUS;
950
951typedef enum _ORI_BLOCKACK_STATUS {
952 Originator_NONE = 0,
953 Originator_USED,
954 Originator_WaitRes,
955 Originator_Done
956} ORI_BLOCKACK_STATUS, *PORI_BLOCKACK_STATUS;
957
958struct rt_ba_ori_entry {
959 u8 Wcid;
960 u8 TID;
961 u8 BAWinSize;
962 u8 Token;
963/* Sequence is to fill every outgoing QoS DATA frame's sequence field in 802.11 header. */
964 u16 Sequence;
965 u16 TimeOutValue;
966 ORI_BLOCKACK_STATUS ORI_BA_Status;
967 struct rt_ralink_timer ORIBATimer;
968 void *pAdapter;
969};
970
971struct rt_ba_rec_entry {
972 u8 Wcid;
973 u8 TID;
974 u8 BAWinSize; /* 7.3.1.14. each buffer is capable of holding a max AMSDU or MSDU. */
975 /*u8 NumOfRxPkt; */
976 /*u8 Curindidx; // the head in the RX reordering buffer */
977 u16 LastIndSeq;
978/* u16 LastIndSeqAtTimer; */
979 u16 TimeOutValue;
980 struct rt_ralink_timer RECBATimer;
981 unsigned long LastIndSeqAtTimer;
982 unsigned long nDropPacket;
983 unsigned long rcvSeq;
984 REC_BLOCKACK_STATUS REC_BA_Status;
985/* u8 RxBufIdxUsed; */
986 /* corresponding virtual address for RX reordering packet storage. */
987 /*RTMP_REORDERDMABUF MAP_RXBuf[MAX_RX_REORDERBUF]; */
988 spinlock_t RxReRingLock; /* Rx Ring spinlock */
989/* struct _BA_REC_ENTRY *pNext; */
990 void *pAdapter;
991 struct reordering_list list;
992};
993
994struct rt_ba_table {
995 unsigned long numAsRecipient; /* I am recipient of numAsRecipient clients. These client are in the BARecEntry[] */
996 unsigned long numAsOriginator; /* I am originator of numAsOriginator clients. These clients are in the BAOriEntry[] */
997 unsigned long numDoneOriginator; /* count Done Originator sessions */
998 struct rt_ba_ori_entry BAOriEntry[MAX_LEN_OF_BA_ORI_TABLE];
999 struct rt_ba_rec_entry BARecEntry[MAX_LEN_OF_BA_REC_TABLE];
1000};
1001
1002/*For QureyBATableOID use; */
1003struct PACKED rt_oid_ba_rec_entry {
1004 u8 MACAddr[MAC_ADDR_LEN];
1005 u8 BaBitmap; /* if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize */
1006 u8 rsv;
1007 u8 BufSize[8];
1008 REC_BLOCKACK_STATUS REC_BA_Status[8];
1009};
1010
1011/*For QureyBATableOID use; */
1012struct PACKED rt_oid_ba_ori_entry {
1013 u8 MACAddr[MAC_ADDR_LEN];
1014 u8 BaBitmap; /* if (BaBitmap&(1<<TID)), this session with{MACAddr, TID}exists, so read BufSize[TID] for BufferSize, read ORI_BA_Status[TID] for status */
1015 u8 rsv;
1016 u8 BufSize[8];
1017 ORI_BLOCKACK_STATUS ORI_BA_Status[8];
1018};
1019
1020struct rt_queryba_table {
1021 struct rt_oid_ba_ori_entry BAOriEntry[32];
1022 struct rt_oid_ba_rec_entry BARecEntry[32];
1023 u8 OriNum; /* Number of below BAOriEntry */
1024 u8 RecNum; /* Number of below BARecEntry */
1025};
1026
1027typedef union _BACAP_STRUC {
1028 struct {
1029 u32 RxBAWinLimit:8;
1030 u32 TxBAWinLimit:8;
1031 u32 AutoBA:1; /* automatically BA */
1032 u32 Policy:2; /* 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use */
1033 u32 MpduDensity:3;
1034 u32 AmsduEnable:1; /*Enable AMSDU transmisstion */
1035 u32 AmsduSize:1; /* 0:3839, 1:7935 bytes. u32 MSDUSizeToBytes[] = { 3839, 7935}; */
1036 u32 MMPSmode:2; /* MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable */
1037 u32 bHtAdhoc:1; /* adhoc can use ht rate. */
1038 u32 b2040CoexistScanSup:1; /*As Sta, support do 2040 coexistence scan for AP. As Ap, support monitor trigger event to check if can use BW 40MHz. */
1039 u32: 4;
1040 } field;
1041 u32 word;
1042} BACAP_STRUC, *PBACAP_STRUC;
1043
1044struct rt_oid_add_ba_entry {
1045 BOOLEAN IsRecipient;
1046 u8 MACAddr[MAC_ADDR_LEN];
1047 u8 TID;
1048 u8 nMSDU;
1049 u16 TimeOut;
1050 BOOLEAN bAllTid; /* If True, delete all TID for BA sessions with this MACaddr. */
1051};
1052
1053#define IS_HT_STA(_pMacEntry) \
1054 (_pMacEntry->MaxHTPhyMode.field.MODE >= MODE_HTMIX)
1055
1056#define IS_HT_RATE(_pMacEntry) \
1057 (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
1058
1059#define PEER_IS_HT_RATE(_pMacEntry) \
1060 (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX)
1061
1062/*This structure is for all 802.11n card InterOptibilityTest action. Reset all Num every n second. (Details see MLMEPeriodic) */
1063struct rt_iot {
1064 u8 Threshold[2];
1065 u8 ReorderTimeOutNum[MAX_LEN_OF_BA_REC_TABLE]; /* compare with threshold[0] */
1066 u8 RefreshNum[MAX_LEN_OF_BA_REC_TABLE]; /* compare with threshold[1] */
1067 unsigned long OneSecInWindowCount;
1068 unsigned long OneSecFrameDuplicateCount;
1069 unsigned long OneSecOutWindowCount;
1070 u8 DelOriAct;
1071 u8 DelRecAct;
1072 u8 RTSShortProt;
1073 u8 RTSLongProt;
1074 BOOLEAN bRTSLongProtOn;
1075 BOOLEAN bLastAtheros;
1076 BOOLEAN bCurrentAtheros;
1077 BOOLEAN bNowAtherosBurstOn;
1078 BOOLEAN bNextDisableRxBA;
1079 BOOLEAN bToggle;
1080};
1081
1082/* This is the registry setting for 802.11n transmit setting. Used in advanced page. */
1083typedef union _REG_TRANSMIT_SETTING {
1084 struct {
1085 /*u32 PhyMode:4; */
1086 /*u32 MCS:7; // MCS */
1087 u32 rsv0:10;
1088 u32 TxBF:1;
1089 u32 BW:1; /*channel bandwidth 20MHz or 40 MHz */
1090 u32 ShortGI:1;
1091 u32 STBC:1; /*SPACE */
1092 u32 TRANSNO:2;
1093 u32 HTMODE:1;
1094 u32 EXTCHA:2;
1095 u32 rsv:13;
1096 } field;
1097 u32 word;
1098} REG_TRANSMIT_SETTING, *PREG_TRANSMIT_SETTING;
1099
1100typedef union _DESIRED_TRANSMIT_SETTING {
1101 struct {
1102 u16 MCS:7; /* MCS */
1103 u16 PhyMode:4;
1104 u16 FixedTxMode:2; /* If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode. */
1105 u16 rsv:3;
1106 } field;
1107 u16 word;
1108} DESIRED_TRANSMIT_SETTING, *PDESIRED_TRANSMIT_SETTING;
1109
1110#ifdef RTMP_MAC_USB
1111/***************************************************************************
1112 * USB-based chip Beacon related data structures
1113 **************************************************************************/
1114#define BEACON_BITMAP_MASK 0xff
1115struct rt_beacon_sync {
1116 u8 BeaconBuf[HW_BEACON_MAX_COUNT][HW_BEACON_OFFSET];
1117 u8 BeaconTxWI[HW_BEACON_MAX_COUNT][TXWI_SIZE];
1118 unsigned long TimIELocationInBeacon[HW_BEACON_MAX_COUNT];
1119 unsigned long CapabilityInfoLocationInBeacon[HW_BEACON_MAX_COUNT];
1120 BOOLEAN EnableBeacon; /* trigger to enable beacon transmission. */
1121 u8 BeaconBitMap; /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter needs to change. */
1122 u8 DtimBitOn; /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter needs to change. */
1123};
1124#endif /* RTMP_MAC_USB // */
1125
1126/***************************************************************************
1127 * Multiple SSID related data structures
1128 **************************************************************************/
1129#define WLAN_MAX_NUM_OF_TIM ((MAX_LEN_OF_MAC_TABLE >> 3) + 1) /* /8 + 1 */
1130#define WLAN_CT_TIM_BCMC_OFFSET 0 /* unit: 32B */
1131
1132/* clear bcmc TIM bit */
1133#define WLAN_MR_TIM_BCMC_CLEAR(apidx) \
1134 pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] &= ~BIT8[0];
1135
1136/* set bcmc TIM bit */
1137#define WLAN_MR_TIM_BCMC_SET(apidx) \
1138 pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] |= BIT8[0];
1139
1140/* clear a station PS TIM bit */
1141#define WLAN_MR_TIM_BIT_CLEAR(ad_p, apidx, wcid) \
1142 { u8 tim_offset = wcid >> 3; \
1143 u8 bit_offset = wcid & 0x7; \
1144 ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] &= (~BIT8[bit_offset]); }
1145
1146/* set a station PS TIM bit */
1147#define WLAN_MR_TIM_BIT_SET(ad_p, apidx, wcid) \
1148 { u8 tim_offset = wcid >> 3; \
1149 u8 bit_offset = wcid & 0x7; \
1150 ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] |= BIT8[bit_offset]; }
1151
1152/* configuration common to OPMODE_AP as well as OPMODE_STA */
1153struct rt_common_config {
1154
1155 BOOLEAN bCountryFlag;
1156 u8 CountryCode[3];
1157 u8 Geography;
1158 u8 CountryRegion; /* Enum of country region, 0:FCC, 1:IC, 2:ETSI, 3:SPAIN, 4:France, 5:MKK, 6:MKK1, 7:Israel */
1159 u8 CountryRegionForABand; /* Enum of country region for A band */
1160 u8 PhyMode; /* PHY_11A, PHY_11B, PHY_11BG_MIXED, PHY_ABG_MIXED */
1161 u16 Dsifs; /* in units of usec */
1162 unsigned long PacketFilter; /* Packet filter for receiving */
1163 u8 RegulatoryClass;
1164
1165 char Ssid[MAX_LEN_OF_SSID]; /* NOT NULL-terminated */
1166 u8 SsidLen; /* the actual ssid length in used */
1167 u8 LastSsidLen; /* the actual ssid length in used */
1168 char LastSsid[MAX_LEN_OF_SSID]; /* NOT NULL-terminated */
1169 u8 LastBssid[MAC_ADDR_LEN];
1170
1171 u8 Bssid[MAC_ADDR_LEN];
1172 u16 BeaconPeriod;
1173 u8 Channel;
1174 u8 CentralChannel; /* Central Channel when using 40MHz is indicating. not real channel. */
1175
1176 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
1177 u8 SupRateLen;
1178 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
1179 u8 ExtRateLen;
1180 u8 DesireRate[MAX_LEN_OF_SUPPORTED_RATES]; /* OID_802_11_DESIRED_RATES */
1181 u8 MaxDesiredRate;
1182 u8 ExpectedACKRate[MAX_LEN_OF_SUPPORTED_RATES];
1183
1184 unsigned long BasicRateBitmap; /* backup basic ratebitmap */
1185
1186 BOOLEAN bAPSDCapable;
1187 BOOLEAN bInServicePeriod;
1188 BOOLEAN bAPSDAC_BE;
1189 BOOLEAN bAPSDAC_BK;
1190 BOOLEAN bAPSDAC_VI;
1191 BOOLEAN bAPSDAC_VO;
1192
1193 /* because TSPEC can modify the APSD flag, we need to keep the APSD flag
1194 requested in association stage from the station;
1195 we need to recover the APSD flag after the TSPEC is deleted. */
1196 BOOLEAN bACMAPSDBackup[4]; /* for delivery-enabled & trigger-enabled both */
1197 BOOLEAN bACMAPSDTr[4]; /* no use */
1198
1199 BOOLEAN bNeedSendTriggerFrame;
1200 BOOLEAN bAPSDForcePowerSave; /* Force power save mode, should only use in APSD-STAUT */
1201 unsigned long TriggerTimerCount;
1202 u8 MaxSPLength;
1203 u8 BBPCurrentBW; /* BW_10, BW_20, BW_40 */
1204 /* move to MULTISSID_STRUCT for MBSS */
1205 /*HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI. */
1206 REG_TRANSMIT_SETTING RegTransmitSetting; /*registry transmit setting. this is for reading registry setting only. not useful. */
1207 /*u8 FixedTxMode; // Fixed Tx Mode (CCK, OFDM), for HT fixed tx mode (GF, MIX) , refer to RegTransmitSetting.field.HTMode */
1208 u8 TxRate; /* Same value to fill in TXD. TxRate is 6-bit */
1209 u8 MaxTxRate; /* RATE_1, RATE_2, RATE_5_5, RATE_11 */
1210 u8 TxRateIndex; /* Tx rate index in RateSwitchTable */
1211 u8 TxRateTableSize; /* Valid Tx rate table size in RateSwitchTable */
1212 /*BOOLEAN bAutoTxRateSwitch; */
1213 u8 MinTxRate; /* RATE_1, RATE_2, RATE_5_5, RATE_11 */
1214 u8 RtsRate; /* RATE_xxx */
1215 HTTRANSMIT_SETTING MlmeTransmit; /* MGMT frame PHY rate setting when operation at Ht rate. */
1216 u8 MlmeRate; /* RATE_xxx, used to send MLME frames */
1217 u8 BasicMlmeRate; /* Default Rate for sending MLME frames */
1218
1219 u16 RtsThreshold; /* in unit of BYTE */
1220 u16 FragmentThreshold; /* in unit of BYTE */
1221
1222 u8 TxPower; /* in unit of mW */
1223 unsigned long TxPowerPercentage; /* 0~100 % */
1224 unsigned long TxPowerDefault; /* keep for TxPowerPercentage */
1225 u8 PwrConstraint;
1226
1227 BACAP_STRUC BACapability; /* NO USE = 0XFF ; IMMED_BA =1 ; DELAY_BA=0 */
1228 BACAP_STRUC REGBACapability; /* NO USE = 0XFF ; IMMED_BA =1 ; DELAY_BA=0 */
1229
1230 struct rt_iot IOTestParm; /* 802.11n InterOpbility Test Parameter; */
1231 unsigned long TxPreamble; /* Rt802_11PreambleLong, Rt802_11PreambleShort, Rt802_11PreambleAuto */
1232 BOOLEAN bUseZeroToDisableFragment; /* Microsoft use 0 as disable */
1233 unsigned long UseBGProtection; /* 0: auto, 1: always use, 2: always not use */
1234 BOOLEAN bUseShortSlotTime; /* 0: disable, 1 - use short slot (9us) */
1235 BOOLEAN bEnableTxBurst; /* 1: enble TX PACKET BURST (when BA is established or AP is not a legacy WMM AP), 0: disable TX PACKET BURST */
1236 BOOLEAN bAggregationCapable; /* 1: enable TX aggregation when the peer supports it */
1237 BOOLEAN bPiggyBackCapable; /* 1: enable TX piggy-back according MAC's version */
1238 BOOLEAN bIEEE80211H; /* 1: enable IEEE802.11h spec. */
1239 unsigned long DisableOLBCDetect; /* 0: enable OLBC detect; 1 disable OLBC detect */
1240
1241 BOOLEAN bRdg;
1242
1243 BOOLEAN bWmmCapable; /* 0:disable WMM, 1:enable WMM */
1244 struct rt_qos_capability_parm APQosCapability; /* QOS capability of the current associated AP */
1245 struct rt_edca_parm APEdcaParm; /* EDCA parameters of the current associated AP */
1246 struct rt_qbss_load_parm APQbssLoad; /* QBSS load of the current associated AP */
1247 u8 AckPolicy[4]; /* ACK policy of the specified AC. see ACK_xxx */
1248 BOOLEAN bDLSCapable; /* 0:disable DLS, 1:enable DLS */
1249 /* a bitmap of BOOLEAN flags. each bit represent an operation status of a particular */
1250 /* BOOLEAN control, either ON or OFF. These flags should always be accessed via */
1251 /* OPSTATUS_TEST_FLAG(), OPSTATUS_SET_FLAG(), OP_STATUS_CLEAR_FLAG() macros. */
1252 /* see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition */
1253 unsigned long OpStatusFlags;
1254
1255 BOOLEAN NdisRadioStateOff; /*For HCT 12.0, set this flag to TRUE instead of called MlmeRadioOff. */
1256 ABGBAND_STATE BandState; /* For setting BBP used on B/G or A mode. */
1257
1258 /* IEEE802.11H--DFS. */
1259 struct rt_radar_detect RadarDetect;
1260
1261 /* HT */
1262 u8 BASize; /* USer desired BAWindowSize. Should not exceed our max capability */
1263 /*struct rt_ht_capability SupportedHtPhy; */
1264 struct rt_ht_capability DesiredHtPhy;
1265 struct rt_ht_capability_ie HtCapability;
1266 struct rt_add_ht_info_ie AddHTInfo; /* Useful as AP. */
1267 /*This IE is used with channel switch announcement element when changing to a new 40MHz. */
1268 /*This IE is included in channel switch announcement frames 7.4.1.5, beacons, probe Rsp. */
1269 struct rt_new_ext_chan_ie NewExtChanOffset; /*7.3.2.20A, 1 if extension channel is above the control channel, 3 if below, 0 if not present */
1270
1271 BOOLEAN bHTProtect;
1272 BOOLEAN bMIMOPSEnable;
1273 BOOLEAN bBADecline;
1274/*2008/11/05: KH add to support Antenna power-saving of AP<-- */
1275 BOOLEAN bGreenAPEnable;
1276/*2008/11/05: KH add to support Antenna power-saving of AP--> */
1277 BOOLEAN bDisableReordering;
1278 BOOLEAN bForty_Mhz_Intolerant;
1279 BOOLEAN bExtChannelSwitchAnnouncement;
1280 BOOLEAN bRcvBSSWidthTriggerEvents;
1281 unsigned long LastRcvBSSWidthTriggerEventsTime;
1282
1283 u8 TxBASize;
1284
1285 /* Enable wireless event */
1286 BOOLEAN bWirelessEvent;
1287 BOOLEAN bWiFiTest; /* Enable this parameter for WiFi test */
1288
1289 /* Tx & Rx Stream number selection */
1290 u8 TxStream;
1291 u8 RxStream;
1292
1293 BOOLEAN bHardwareRadio; /* Hardware controlled Radio enabled */
1294
1295#ifdef RTMP_MAC_USB
1296 BOOLEAN bMultipleIRP; /* Multiple Bulk IN flag */
1297 u8 NumOfBulkInIRP; /* if bMultipleIRP == TRUE, NumOfBulkInIRP will be 4 otherwise be 1 */
1298 struct rt_ht_capability SupportedHtPhy;
1299 unsigned long MaxPktOneTxBulk;
1300 u8 TxBulkFactor;
1301 u8 RxBulkFactor;
1302
1303 BOOLEAN IsUpdateBeacon;
1304 struct rt_beacon_sync *pBeaconSync;
1305 struct rt_ralink_timer BeaconUpdateTimer;
1306 u32 BeaconAdjust;
1307 u32 BeaconFactor;
1308 u32 BeaconRemain;
1309#endif /* RTMP_MAC_USB // */
1310
1311 spinlock_t MeasureReqTabLock;
1312 struct rt_measure_req_tab *pMeasureReqTab;
1313
1314 spinlock_t TpcReqTabLock;
1315 struct rt_tpc_req_tab *pTpcReqTab;
1316
1317 BOOLEAN PSPXlink; /* 0: Disable. 1: Enable */
1318
1319#if defined(RT305x) || defined(RT30xx)
1320 /* request by Gary, for High Power issue */
1321 u8 HighPowerPatchDisabled;
1322#endif
1323
1324 BOOLEAN HT_DisallowTKIP; /* Restrict the encryption type in 11n HT mode */
1325};
1326
1327/* Modified by Wu Xi-Kun 4/21/2006 */
1328/* STA configuration and status */
1329struct rt_sta_admin_config {
1330 /* GROUP 1 - */
1331 /* User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */
1332 /* the user intended configuration, but not necessary fully equal to the final */
1333 /* settings in ACTIVE BSS after negotiation/compromise with the BSS holder (either */
1334 /* AP or IBSS holder). */
1335 /* Once initialized, user configuration can only be changed via OID_xxx */
1336 u8 BssType; /* BSS_INFRA or BSS_ADHOC */
1337 u16 AtimWin; /* used when starting a new IBSS */
1338
1339 /* GROUP 2 - */
1340 /* User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */
1341 /* the user intended configuration, and should be always applied to the final */
1342 /* settings in ACTIVE BSS without compromising with the BSS holder. */
1343 /* Once initialized, user configuration can only be changed via OID_xxx */
1344 u8 RssiTrigger;
1345 u8 RssiTriggerMode; /* RSSI_TRIGGERED_UPON_BELOW_THRESHOLD or RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD */
1346 u16 DefaultListenCount; /* default listen count; */
1347 unsigned long WindowsPowerMode; /* Power mode for AC power */
1348 unsigned long WindowsBatteryPowerMode; /* Power mode for battery if exists */
1349 BOOLEAN bWindowsACCAMEnable; /* Enable CAM power mode when AC on */
1350 BOOLEAN bAutoReconnect; /* Set to TRUE when setting OID_802_11_SSID with no matching BSSID */
1351 unsigned long WindowsPowerProfile; /* Windows power profile, for NDIS5.1 PnP */
1352
1353 /* MIB:ieee802dot11.dot11smt(1).dot11StationConfigTable(1) */
1354 u16 Psm; /* power management mode (PWR_ACTIVE|PWR_SAVE) */
1355 u16 DisassocReason;
1356 u8 DisassocSta[MAC_ADDR_LEN];
1357 u16 DeauthReason;
1358 u8 DeauthSta[MAC_ADDR_LEN];
1359 u16 AuthFailReason;
1360 u8 AuthFailSta[MAC_ADDR_LEN];
1361
1362 NDIS_802_11_PRIVACY_FILTER PrivacyFilter; /* PrivacyFilter enum for 802.1X */
1363 NDIS_802_11_AUTHENTICATION_MODE AuthMode; /* This should match to whatever microsoft defined */
1364 NDIS_802_11_WEP_STATUS WepStatus;
1365 NDIS_802_11_WEP_STATUS OrigWepStatus; /* Original wep status set from OID */
1366
1367 /* Add to support different cipher suite for WPA2/WPA mode */
1368 NDIS_802_11_ENCRYPTION_STATUS GroupCipher; /* Multicast cipher suite */
1369 NDIS_802_11_ENCRYPTION_STATUS PairCipher; /* Unicast cipher suite */
1370 BOOLEAN bMixCipher; /* Indicate current Pair & Group use different cipher suites */
1371 u16 RsnCapability;
1372
1373 NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
1374
1375 u8 WpaPassPhrase[64]; /* WPA PSK pass phrase */
1376 u32 WpaPassPhraseLen; /* the length of WPA PSK pass phrase */
1377 u8 PMK[32]; /* WPA PSK mode PMK */
1378 u8 PTK[64]; /* WPA PSK mode PTK */
1379 u8 GTK[32]; /* GTK from authenticator */
1380 struct rt_bssid_info SavedPMK[PMKID_NO];
1381 u32 SavedPMKNum; /* Saved PMKID number */
1382
1383 u8 DefaultKeyId;
1384
1385 /* WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED */
1386 u8 PortSecured;
1387
1388 /* For WPA countermeasures */
1389 unsigned long LastMicErrorTime; /* record last MIC error time */
1390 unsigned long MicErrCnt; /* Should be 0, 1, 2, then reset to zero (after disassociation). */
1391 BOOLEAN bBlockAssoc; /* Block associate attempt for 60 seconds after counter measure occurred. */
1392 /* For WPA-PSK supplicant state */
1393 WPA_STATE WpaState; /* Default is SS_NOTUSE and handled by microsoft 802.1x */
1394 u8 ReplayCounter[8];
1395 u8 ANonce[32]; /* ANonce for WPA-PSK from auhenticator */
1396 u8 SNonce[32]; /* SNonce for WPA-PSK */
1397
1398 u8 LastSNR0; /* last received BEACON's SNR */
1399 u8 LastSNR1; /* last received BEACON's SNR for 2nd antenna */
1400 struct rt_rssi_sample RssiSample;
1401 unsigned long NumOfAvgRssiSample;
1402
1403 unsigned long LastBeaconRxTime; /* OS's timestamp of the last BEACON RX time */
1404 unsigned long Last11bBeaconRxTime; /* OS's timestamp of the last 11B BEACON RX time */
1405 unsigned long Last11gBeaconRxTime; /* OS's timestamp of the last 11G BEACON RX time */
1406 unsigned long Last20NBeaconRxTime; /* OS's timestamp of the last 20MHz N BEACON RX time */
1407
1408 unsigned long LastScanTime; /* Record last scan time for issue BSSID_SCAN_LIST */
1409 unsigned long ScanCnt; /* Scan counts since most recent SSID, BSSID, SCAN OID request */
1410 BOOLEAN bSwRadio; /* Software controlled Radio On/Off, TRUE: On */
1411 BOOLEAN bHwRadio; /* Hardware controlled Radio On/Off, TRUE: On */
1412 BOOLEAN bRadio; /* Radio state, And of Sw & Hw radio state */
1413 BOOLEAN bHardwareRadio; /* Hardware controlled Radio enabled */
1414 BOOLEAN bShowHiddenSSID; /* Show all known SSID in SSID list get operation */
1415
1416 /* New for WPA, windows want us to keep association information and */
1417 /* Fixed IEs from last association response */
1418 struct rt_ndis_802_11_association_information AssocInfo;
1419 u16 ReqVarIELen; /* Length of next VIE include EID & Length */
1420 u8 ReqVarIEs[MAX_VIE_LEN]; /* The content saved here should be little-endian format. */
1421 u16 ResVarIELen; /* Length of next VIE include EID & Length */
1422 u8 ResVarIEs[MAX_VIE_LEN];
1423
1424 u8 RSNIE_Len;
1425 u8 RSN_IE[MAX_LEN_OF_RSNIE]; /* The content saved here should be little-endian format. */
1426
1427 unsigned long CLBusyBytes; /* Save the total bytes received during channel load scan time */
1428 u16 RPIDensity[8]; /* Array for RPI density collection */
1429
1430 u8 RMReqCnt; /* Number of measurement request saved. */
1431 u8 CurrentRMReqIdx; /* Number of measurement request saved. */
1432 BOOLEAN ParallelReq; /* Parallel measurement, only one request performed, */
1433 /* It must be the same channel with maximum duration */
1434 u16 ParallelDuration; /* Maximum duration for parallel measurement */
1435 u8 ParallelChannel; /* Only one channel with parallel measurement */
1436 u16 IAPPToken; /* IAPP dialog token */
1437 /* Hack for channel load and noise histogram parameters */
1438 u8 NHFactor; /* Parameter for Noise histogram */
1439 u8 CLFactor; /* Parameter for channel load */
1440
1441 struct rt_ralink_timer StaQuickResponeForRateUpTimer;
1442 BOOLEAN StaQuickResponeForRateUpTimerRunning;
1443
1444 u8 DtimCount; /* 0.. DtimPeriod-1 */
1445 u8 DtimPeriod; /* default = 3 */
1446
1447 /*////////////////////////////////////////////////////////////////////////////////////// */
1448 /* This is only for WHQL test. */
1449 BOOLEAN WhqlTest;
1450 /*////////////////////////////////////////////////////////////////////////////////////// */
1451
1452 struct rt_ralink_timer WpaDisassocAndBlockAssocTimer;
1453 /* Fast Roaming */
1454 BOOLEAN bAutoRoaming; /* 0:disable auto roaming by RSSI, 1:enable auto roaming by RSSI */
1455 char dBmToRoam; /* the condition to roam when receiving Rssi less than this value. It's negative value. */
1456
1457 BOOLEAN IEEE8021X;
1458 BOOLEAN IEEE8021x_required_keys;
1459 struct rt_cipher_key DesireSharedKey[4]; /* Record user desired WEP keys */
1460 u8 DesireSharedKeyId;
1461
1462 /* 0: driver ignores wpa_supplicant */
1463 /* 1: wpa_supplicant initiates scanning and AP selection */
1464 /* 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters */
1465 u8 WpaSupplicantUP;
1466 u8 WpaSupplicantScanCount;
1467 BOOLEAN bRSN_IE_FromWpaSupplicant;
1468
1469 char dev_name[16];
1470 u16 OriDevType;
1471
1472 BOOLEAN bTGnWifiTest;
1473 BOOLEAN bScanReqIsFromWebUI;
1474
1475 HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode; /* For transmit phy setting in TXWI. */
1476 DESIRED_TRANSMIT_SETTING DesiredTransmitSetting;
1477 struct rt_ht_phy_info DesiredHtPhyInfo;
1478 BOOLEAN bAutoTxRateSwitch;
1479
1480#ifdef RTMP_MAC_PCI
1481 u8 BBPR3;
1482 /* PS Control has 2 meanings for advanced power save function. */
1483 /* 1. EnablePSinIdle : When no connection, always radio off except need to do site survey. */
1484 /* 2. EnableNewPS : will save more current in sleep or radio off mode. */
1485 PS_CONTROL PSControl;
1486#endif /* RTMP_MAC_PCI // */
1487
1488 BOOLEAN bAutoConnectByBssid;
1489 unsigned long BeaconLostTime; /* seconds */
1490 BOOLEAN bForceTxBurst; /* 1: force enble TX PACKET BURST, 0: disable */
1491};
1492
1493/* This data structure keeps the current active BSS/IBSS's configuration that this STA */
1494/* had agreed upon joining the network. Which means these parameters are usually decided */
1495/* by the BSS/IBSS creator instead of user configuration. Data in this data structure */
1496/* is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE. */
1497/* Normally, after SCAN or failed roaming attempts, we need to recover back to */
1498/* the current active settings. */
1499struct rt_sta_active_config {
1500 u16 Aid;
1501 u16 AtimWin; /* in kusec; IBSS parameter set element */
1502 u16 CapabilityInfo;
1503 u16 CfpMaxDuration;
1504 u16 CfpPeriod;
1505
1506 /* Copy supported rate from desired AP's beacon. We are trying to match */
1507 /* AP's supported and extended rate settings. */
1508 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
1509 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
1510 u8 SupRateLen;
1511 u8 ExtRateLen;
1512 /* Copy supported ht from desired AP's beacon. We are trying to match */
1513 struct rt_ht_phy_info SupportedPhyInfo;
1514 struct rt_ht_capability SupportedHtPhy;
1515};
1516
1517struct rt_mac_table_entry;
1518
1519struct rt_mac_table_entry {
1520 /*Choose 1 from ValidAsWDS and ValidAsCLI to validize. */
1521 BOOLEAN ValidAsCLI; /* Sta mode, set this TRUE after Linkup,too. */
1522 BOOLEAN ValidAsWDS; /* This is WDS Entry. only for AP mode. */
1523 BOOLEAN ValidAsApCli; /* This is a AP-Client entry, only for AP mode which enable AP-Client functions. */
1524 BOOLEAN ValidAsMesh;
1525 BOOLEAN ValidAsDls; /* This is DLS Entry. only for STA mode. */
1526 BOOLEAN isCached;
1527 BOOLEAN bIAmBadAtheros; /* Flag if this is Atheros chip that has IOT problem. We need to turn on RTS/CTS protection. */
1528
1529 u8 EnqueueEapolStartTimerRunning; /* Enqueue EAPoL-Start for triggering EAP SM */
1530 /*jan for wpa */
1531 /* record which entry revoke MIC Failure, if it leaves the BSS itself, AP won't update aMICFailTime MIB */
1532 u8 CMTimerRunning;
1533 u8 apidx; /* MBSS number */
1534 u8 RSNIE_Len;
1535 u8 RSN_IE[MAX_LEN_OF_RSNIE];
1536 u8 ANonce[LEN_KEY_DESC_NONCE];
1537 u8 SNonce[LEN_KEY_DESC_NONCE];
1538 u8 R_Counter[LEN_KEY_DESC_REPLAY];
1539 u8 PTK[64];
1540 u8 ReTryCounter;
1541 struct rt_ralink_timer RetryTimer;
1542 struct rt_ralink_timer EnqueueStartForPSKTimer; /* A timer which enqueue EAPoL-Start for triggering PSK SM */
1543 NDIS_802_11_AUTHENTICATION_MODE AuthMode; /* This should match to whatever microsoft defined */
1544 NDIS_802_11_WEP_STATUS WepStatus;
1545 NDIS_802_11_WEP_STATUS GroupKeyWepStatus;
1546 AP_WPA_STATE WpaState;
1547 GTK_STATE GTKState;
1548 u16 PortSecured;
1549 NDIS_802_11_PRIVACY_FILTER PrivacyFilter; /* PrivacyFilter enum for 802.1X */
1550 struct rt_cipher_key PairwiseKey;
1551 void *pAd;
1552 int PMKID_CacheIdx;
1553 u8 PMKID[LEN_PMKID];
1554
1555 u8 Addr[MAC_ADDR_LEN];
1556 u8 PsMode;
1557 SST Sst;
1558 AUTH_STATE AuthState; /* for SHARED KEY authentication state machine used only */
1559 BOOLEAN IsReassocSta; /* Indicate whether this is a reassociation procedure */
1560 u16 Aid;
1561 u16 CapabilityInfo;
1562 u8 LastRssi;
1563 unsigned long NoDataIdleCount;
1564 u16 StationKeepAliveCount; /* unit: second */
1565 unsigned long PsQIdleCount;
1566 struct rt_queue_header PsQueue;
1567
1568 u32 StaConnectTime; /* the live time of this station since associated with AP */
1569
1570 BOOLEAN bSendBAR;
1571 u16 NoBADataCountDown;
1572
1573 u32 CachedBuf[16]; /* u32 (4 bytes) for alignment */
1574 u32 TxBFCount; /* 3*3 */
1575 u32 FIFOCount;
1576 u32 DebugFIFOCount;
1577 u32 DebugTxCount;
1578 BOOLEAN bDlsInit;
1579
1580/*==================================================== */
1581/*WDS entry needs these */
1582/* if ValidAsWDS==TRUE, MatchWDSTabIdx is the index in WdsTab.MacTab */
1583 u32 MatchWDSTabIdx;
1584 u8 MaxSupportedRate;
1585 u8 CurrTxRate;
1586 u8 CurrTxRateIndex;
1587 /* to record the each TX rate's quality. 0 is best, the bigger the worse. */
1588 u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
1589/* u16 OneSecTxOkCount; */
1590 u32 OneSecTxNoRetryOkCount;
1591 u32 OneSecTxRetryOkCount;
1592 u32 OneSecTxFailCount;
1593 u32 ContinueTxFailCnt;
1594 u32 CurrTxRateStableTime; /* # of second in current TX rate */
1595 u8 TxRateUpPenalty; /* extra # of second penalty due to last unstable condition */
1596/*==================================================== */
1597
1598 BOOLEAN fNoisyEnvironment;
1599 BOOLEAN fLastSecAccordingRSSI;
1600 u8 LastSecTxRateChangeAction; /* 0: no change, 1:rate UP, 2:rate down */
1601 char LastTimeTxRateChangeAction; /*Keep last time value of LastSecTxRateChangeAction */
1602 unsigned long LastTxOkCount;
1603 u8 PER[MAX_STEP_OF_TX_RATE_SWITCH];
1604
1605 /* a bitmap of BOOLEAN flags. each bit represent an operation status of a particular */
1606 /* BOOLEAN control, either ON or OFF. These flags should always be accessed via */
1607 /* CLIENT_STATUS_TEST_FLAG(), CLIENT_STATUS_SET_FLAG(), CLIENT_STATUS_CLEAR_FLAG() macros. */
1608 /* see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition. fCLIENT_STATUS_AMSDU_INUSED */
1609 unsigned long ClientStatusFlags;
1610
1611 HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode; /* For transmit phy setting in TXWI. */
1612
1613 /* HT EWC MIMO-N used parameters */
1614 u16 RXBAbitmap; /* fill to on-chip RXWI_BA_BITMASK in 8.1.3RX attribute entry format */
1615 u16 TXBAbitmap; /* This bitmap as originator, only keep in software used to mark AMPDU bit in TXWI */
1616 u16 TXAutoBAbitmap;
1617 u16 BADeclineBitmap;
1618 u16 BARecWcidArray[NUM_OF_TID]; /* The mapping wcid of recipient session. if RXBAbitmap bit is masked */
1619 u16 BAOriWcidArray[NUM_OF_TID]; /* The mapping wcid of originator session. if TXBAbitmap bit is masked */
1620 u16 BAOriSequence[NUM_OF_TID]; /* The mapping wcid of originator session. if TXBAbitmap bit is masked */
1621
1622 /* 802.11n features. */
1623 u8 MpduDensity;
1624 u8 MaxRAmpduFactor;
1625 u8 AMsduSize;
1626 u8 MmpsMode; /* MIMO power save more. */
1627
1628 struct rt_ht_capability_ie HTCapability;
1629
1630 BOOLEAN bAutoTxRateSwitch;
1631
1632 u8 RateLen;
1633 struct rt_mac_table_entry *pNext;
1634 u16 TxSeq[NUM_OF_TID];
1635 u16 NonQosDataSeq;
1636
1637 struct rt_rssi_sample RssiSample;
1638
1639 u32 TXMCSExpected[16];
1640 u32 TXMCSSuccessful[16];
1641 u32 TXMCSFailed[16];
1642 u32 TXMCSAutoFallBack[16][16];
1643
1644 unsigned long LastBeaconRxTime;
1645
1646 unsigned long AssocDeadLine;
1647};
1648
1649struct rt_mac_table {
1650 u16 Size;
1651 struct rt_mac_table_entry *Hash[HASH_TABLE_SIZE];
1652 struct rt_mac_table_entry Content[MAX_LEN_OF_MAC_TABLE];
1653 struct rt_queue_header McastPsQueue;
1654 unsigned long PsQIdleCount;
1655 BOOLEAN fAnyStationInPsm;
1656 BOOLEAN fAnyStationBadAtheros; /* Check if any Station is atheros 802.11n Chip. We need to use RTS/CTS with Atheros 802,.11n chip. */
1657 BOOLEAN fAnyTxOPForceDisable; /* Check if it is necessary to disable BE TxOP */
1658 BOOLEAN fAllStationAsRalink; /* Check if all stations are ralink-chipset */
1659 BOOLEAN fAnyStationIsLegacy; /* Check if I use legacy rate to transmit to my BSS Station/ */
1660 BOOLEAN fAnyStationNonGF; /* Check if any Station can't support GF. */
1661 BOOLEAN fAnyStation20Only; /* Check if any Station can't support GF. */
1662 BOOLEAN fAnyStationMIMOPSDynamic; /* Check if any Station is MIMO Dynamic */
1663 BOOLEAN fAnyBASession; /* Check if there is BA session. Force turn on RTS/CTS */
1664/*2008/10/28: KH add to support Antenna power-saving of AP<-- */
1665/*2008/10/28: KH add to support Antenna power-saving of AP--> */
1666};
1667
1668struct wificonf {
1669 BOOLEAN bShortGI;
1670 BOOLEAN bGreenField;
1671};
1672
1673struct rt_rtmp_dev_info {
1674 u8 chipName[16];
1675 RTMP_INF_TYPE infType;
1676};
1677
1678struct rt_rtmp_chip_op {
1679 /* Calibration access related callback functions */
1680 int (*eeinit) (struct rt_rtmp_adapter *pAd); /* int (*eeinit)(struct rt_rtmp_adapter *pAd); */
1681 int (*eeread) (struct rt_rtmp_adapter *pAd, u16 offset, u16 *pValue); /* int (*eeread)(struct rt_rtmp_adapter *pAd, int offset, u16 *pValue); */
1682
1683 /* MCU related callback functions */
1684 int (*loadFirmware) (struct rt_rtmp_adapter *pAd); /* int (*loadFirmware)(struct rt_rtmp_adapter *pAd); */
1685 int (*eraseFirmware) (struct rt_rtmp_adapter *pAd); /* int (*eraseFirmware)(struct rt_rtmp_adapter *pAd); */
1686 int (*sendCommandToMcu) (struct rt_rtmp_adapter *pAd, u8 cmd, u8 token, u8 arg0, u8 arg1);; /* int (*sendCommandToMcu)(struct rt_rtmp_adapter *pAd, u8 cmd, u8 token, u8 arg0, u8 arg1); */
1687
1688 /* RF access related callback functions */
1689 struct rt_reg_pair *pRFRegTable;
1690 void (*AsicRfInit) (struct rt_rtmp_adapter *pAd);
1691 void (*AsicRfTurnOn) (struct rt_rtmp_adapter *pAd);
1692 void (*AsicRfTurnOff) (struct rt_rtmp_adapter *pAd);
1693 void (*AsicReverseRfFromSleepMode) (struct rt_rtmp_adapter *pAd);
1694 void (*AsicHaltAction) (struct rt_rtmp_adapter *pAd);
1695};
1696
1697/* */
1698/* The miniport adapter structure */
1699/* */
1700struct rt_rtmp_adapter {
1701 void *OS_Cookie; /* save specific structure relative to OS */
1702 struct net_device *net_dev;
1703 unsigned long VirtualIfCnt;
1704 const struct firmware *firmware;
1705
1706 struct rt_rtmp_chip_op chipOps;
1707 u16 ThisTbttNumToNextWakeUp;
1708
1709#ifdef RTMP_MAC_PCI
1710/*****************************************************************************************/
1711/* PCI related parameters */
1712/*****************************************************************************************/
1713 u8 *CSRBaseAddress; /* PCI MMIO Base Address, all access will use */
1714 unsigned int irq_num;
1715
1716 u16 LnkCtrlBitMask;
1717 u16 RLnkCtrlConfiguration;
1718 u16 RLnkCtrlOffset;
1719 u16 HostLnkCtrlConfiguration;
1720 u16 HostLnkCtrlOffset;
1721 u16 PCIePowerSaveLevel;
1722 unsigned long Rt3xxHostLinkCtrl; /* USed for 3090F chip */
1723 unsigned long Rt3xxRalinkLinkCtrl; /* USed for 3090F chip */
1724 u16 DeviceID; /* Read from PCI config */
1725 unsigned long AccessBBPFailCount;
1726 BOOLEAN bPCIclkOff; /* flag that indicates if the PICE power status in Configuration Space.. */
1727 BOOLEAN bPCIclkOffDisableTx; /* */
1728
1729 BOOLEAN brt30xxBanMcuCmd; /*when = 0xff means all commands are ok to set . */
1730 BOOLEAN b3090ESpecialChip; /*3090E special chip that write EEPROM 0x24=0x9280. */
1731 unsigned long CheckDmaBusyCount; /* Check Interrupt Status Register Count. */
1732
1733 u32 int_enable_reg;
1734 u32 int_disable_mask;
1735 u32 int_pending;
1736
1737 struct rt_rtmp_dmabuf TxBufSpace[NUM_OF_TX_RING]; /* Shared memory of all 1st pre-allocated TxBuf associated with each TXD */
1738 struct rt_rtmp_dmabuf RxDescRing; /* Shared memory for RX descriptors */
1739 struct rt_rtmp_dmabuf TxDescRing[NUM_OF_TX_RING]; /* Shared memory for Tx descriptors */
1740 struct rt_rtmp_tx_ring TxRing[NUM_OF_TX_RING]; /* AC0~4 + HCCA */
1741#endif /* RTMP_MAC_PCI // */
1742
1743 spinlock_t irq_lock;
1744 u8 irq_disabled;
1745
1746#ifdef RTMP_MAC_USB
1747/*****************************************************************************************/
1748/* USB related parameters */
1749/*****************************************************************************************/
1750 struct usb_config_descriptor *config;
1751 u32 BulkInEpAddr; /* bulk-in endpoint address */
1752 u32 BulkOutEpAddr[6]; /* bulk-out endpoint address */
1753
1754 u32 NumberOfPipes;
1755 u16 BulkOutMaxPacketSize;
1756 u16 BulkInMaxPacketSize;
1757
1758 /*======Control Flags */
1759 long PendingIoCount;
1760 unsigned long BulkFlags;
1761 BOOLEAN bUsbTxBulkAggre; /* Flags for bulk out data priority */
1762
1763 /*======Cmd Thread */
1764 struct rt_cmdq CmdQ;
1765 spinlock_t CmdQLock; /* CmdQLock spinlock */
1766 struct rt_rtmp_os_task cmdQTask;
1767
1768 /*======Semaphores (event) */
1769 struct semaphore UsbVendorReq_semaphore;
1770 void *UsbVendorReqBuf;
1771 wait_queue_head_t *wait;
1772#endif /* RTMP_MAC_USB // */
1773
1774/*****************************************************************************************/
1775/* RBUS related parameters */
1776/*****************************************************************************************/
1777
1778/*****************************************************************************************/
1779/* Both PCI/USB related parameters */
1780/*****************************************************************************************/
1781 /*struct rt_rtmp_dev_info chipInfo; */
1782 RTMP_INF_TYPE infType;
1783
1784/*****************************************************************************************/
1785/* Driver Mgmt related parameters */
1786/*****************************************************************************************/
1787 struct rt_rtmp_os_task mlmeTask;
1788#ifdef RTMP_TIMER_TASK_SUPPORT
1789 /* If you want use timer task to handle the timer related jobs, enable this. */
1790 struct rt_rtmp_timer_task_queue TimerQ;
1791 spinlock_t TimerQLock;
1792 struct rt_rtmp_os_task timerTask;
1793#endif /* RTMP_TIMER_TASK_SUPPORT // */
1794
1795/*****************************************************************************************/
1796/* Tx related parameters */
1797/*****************************************************************************************/
1798 BOOLEAN DeQueueRunning[NUM_OF_TX_RING]; /* for ensuring RTUSBDeQueuePacket get call once */
1799 spinlock_t DeQueueLock[NUM_OF_TX_RING];
1800
1801#ifdef RTMP_MAC_USB
1802 /* Data related context and AC specified, 4 AC supported */
1803 spinlock_t BulkOutLock[6]; /* BulkOut spinlock for 4 ACs */
1804 spinlock_t MLMEBulkOutLock; /* MLME BulkOut lock */
1805
1806 struct rt_ht_tx_context TxContext[NUM_OF_TX_RING];
1807 spinlock_t TxContextQueueLock[NUM_OF_TX_RING]; /* TxContextQueue spinlock */
1808
1809 /* 4 sets of Bulk Out index and pending flag */
1810 u8 NextBulkOutIndex[4]; /* only used for 4 EDCA bulkout pipe */
1811
1812 BOOLEAN BulkOutPending[6]; /* used for total 6 bulkout pipe */
1813 u8 bulkResetPipeid;
1814 BOOLEAN MgmtBulkPending;
1815 unsigned long bulkResetReq[6];
1816#endif /* RTMP_MAC_USB // */
1817
1818 /* resource for software backlog queues */
1819 struct rt_queue_header TxSwQueue[NUM_OF_TX_RING]; /* 4 AC + 1 HCCA */
1820 spinlock_t TxSwQueueLock[NUM_OF_TX_RING]; /* TxSwQueue spinlock */
1821
1822 struct rt_rtmp_dmabuf MgmtDescRing; /* Shared memory for MGMT descriptors */
1823 struct rt_rtmp_mgmt_ring MgmtRing;
1824 spinlock_t MgmtRingLock; /* Prio Ring spinlock */
1825
1826/*****************************************************************************************/
1827/* Rx related parameters */
1828/*****************************************************************************************/
1829
1830#ifdef RTMP_MAC_PCI
1831 struct rt_rtmp_rx_ring RxRing;
1832 spinlock_t RxRingLock; /* Rx Ring spinlock */
1833#ifdef RT3090
1834 spinlock_t McuCmdLock; /*MCU Command Queue spinlock */
1835#endif /* RT3090 // */
1836#endif /* RTMP_MAC_PCI // */
1837#ifdef RTMP_MAC_USB
1838 struct rt_rx_context RxContext[RX_RING_SIZE]; /* 1 for redundant multiple IRP bulk in. */
1839 spinlock_t BulkInLock; /* BulkIn spinlock for 4 ACs */
1840 u8 PendingRx; /* The Maximum pending Rx value should be RX_RING_SIZE. */
1841 u8 NextRxBulkInIndex; /* Indicate the current RxContext Index which hold by Host controller. */
1842 u8 NextRxBulkInReadIndex; /* Indicate the current RxContext Index which driver can read & process it. */
1843 unsigned long NextRxBulkInPosition; /* Want to contatenate 2 URB buffer while 1st is bulkin failed URB. This Position is 1st URB TransferLength. */
1844 unsigned long TransferBufferLength; /* current length of the packet buffer */
1845 unsigned long ReadPosition; /* current read position in a packet buffer */
1846#endif /* RTMP_MAC_USB // */
1847
1848/*****************************************************************************************/
1849/* ASIC related parameters */
1850/*****************************************************************************************/
1851 u32 MACVersion; /* MAC version. Record rt2860C(0x28600100) or rt2860D (0x28600101).. */
1852
1853 /* --------------------------- */
1854 /* E2PROM */
1855 /* --------------------------- */
1856 unsigned long EepromVersion; /* byte 0: version, byte 1: revision, byte 2~3: unused */
1857 unsigned long FirmwareVersion; /* byte 0: Minor version, byte 1: Major version, otherwise unused. */
1858 u16 EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS];
1859 u8 EEPROMAddressNum; /* 93c46=6 93c66=8 */
1860 BOOLEAN EepromAccess;
1861 u8 EFuseTag;
1862
1863 /* --------------------------- */
1864 /* BBP Control */
1865 /* --------------------------- */
1866 u8 BbpWriteLatch[140]; /* record last BBP register value written via BBP_IO_WRITE/BBP_IO_WRITE_VY_REG_ID */
1867 char BbpRssiToDbmDelta; /* change from u8 to char for high power */
1868 struct rt_bbp_r66_tuning BbpTuning;
1869
1870 /* ---------------------------- */
1871 /* RFIC control */
1872 /* ---------------------------- */
1873 u8 RfIcType; /* RFIC_xxx */
1874 unsigned long RfFreqOffset; /* Frequency offset for channel switching */
1875 struct rt_rtmp_rf_regs LatchRfRegs; /* latch the latest RF programming value since RF IC doesn't support READ */
1876
1877 EEPROM_ANTENNA_STRUC Antenna; /* Since Antenna definition is different for a & g. We need to save it for future reference. */
1878 EEPROM_NIC_CONFIG2_STRUC NicConfig2;
1879
1880 /* This soft Rx Antenna Diversity mechanism is used only when user set */
1881 /* RX Antenna = DIVERSITY ON */
1882 struct rt_soft_rx_ant_diversity RxAnt;
1883
1884 u8 RFProgSeq;
1885 struct rt_channel_tx_power TxPower[MAX_NUM_OF_CHANNELS]; /* Store Tx power value for all channels. */
1886 struct rt_channel_tx_power ChannelList[MAX_NUM_OF_CHANNELS]; /* list all supported channels for site survey */
1887 struct rt_channel_11j_tx_power TxPower11J[MAX_NUM_OF_11JCHANNELS]; /* 802.11j channel and bw */
1888 struct rt_channel_11j_tx_power ChannelList11J[MAX_NUM_OF_11JCHANNELS]; /* list all supported channels for site survey */
1889
1890 u8 ChannelListNum; /* number of channel in ChannelList[] */
1891 u8 Bbp94;
1892 BOOLEAN BbpForCCK;
1893 unsigned long Tx20MPwrCfgABand[5];
1894 unsigned long Tx20MPwrCfgGBand[5];
1895 unsigned long Tx40MPwrCfgABand[5];
1896 unsigned long Tx40MPwrCfgGBand[5];
1897
1898 BOOLEAN bAutoTxAgcA; /* Enable driver auto Tx Agc control */
1899 u8 TssiRefA; /* Store Tssi reference value as 25 temperature. */
1900 u8 TssiPlusBoundaryA[5]; /* Tssi boundary for increase Tx power to compensate. */
1901 u8 TssiMinusBoundaryA[5]; /* Tssi boundary for decrease Tx power to compensate. */
1902 u8 TxAgcStepA; /* Store Tx TSSI delta increment / decrement value */
1903 char TxAgcCompensateA; /* Store the compensation (TxAgcStep * (idx-1)) */
1904
1905 BOOLEAN bAutoTxAgcG; /* Enable driver auto Tx Agc control */
1906 u8 TssiRefG; /* Store Tssi reference value as 25 temperature. */
1907 u8 TssiPlusBoundaryG[5]; /* Tssi boundary for increase Tx power to compensate. */
1908 u8 TssiMinusBoundaryG[5]; /* Tssi boundary for decrease Tx power to compensate. */
1909 u8 TxAgcStepG; /* Store Tx TSSI delta increment / decrement value */
1910 char TxAgcCompensateG; /* Store the compensation (TxAgcStep * (idx-1)) */
1911
1912 char BGRssiOffset0; /* Store B/G RSSI#0 Offset value on EEPROM 0x46h */
1913 char BGRssiOffset1; /* Store B/G RSSI#1 Offset value */
1914 char BGRssiOffset2; /* Store B/G RSSI#2 Offset value */
1915
1916 char ARssiOffset0; /* Store A RSSI#0 Offset value on EEPROM 0x4Ah */
1917 char ARssiOffset1; /* Store A RSSI#1 Offset value */
1918 char ARssiOffset2; /* Store A RSSI#2 Offset value */
1919
1920 char BLNAGain; /* Store B/G external LNA#0 value on EEPROM 0x44h */
1921 char ALNAGain0; /* Store A external LNA#0 value for ch36~64 */
1922 char ALNAGain1; /* Store A external LNA#1 value for ch100~128 */
1923 char ALNAGain2; /* Store A external LNA#2 value for ch132~165 */
1924#ifdef RT30xx
1925 /* for 3572 */
1926 u8 Bbp25;
1927 u8 Bbp26;
1928
1929 u8 TxMixerGain24G; /* Tx mixer gain value from EEPROM to improve Tx EVM / Tx DAC, 2.4G */
1930 u8 TxMixerGain5G;
1931#endif /* RT30xx // */
1932 /* ---------------------------- */
1933 /* LED control */
1934 /* ---------------------------- */
1935 MCU_LEDCS_STRUC LedCntl;
1936 u16 Led1; /* read from EEPROM 0x3c */
1937 u16 Led2; /* EEPROM 0x3e */
1938 u16 Led3; /* EEPROM 0x40 */
1939 u8 LedIndicatorStrength;
1940 u8 RssiSingalstrengthOffet;
1941 BOOLEAN bLedOnScanning;
1942 u8 LedStatus;
1943
1944/*****************************************************************************************/
1945/* 802.11 related parameters */
1946/*****************************************************************************************/
1947 /* outgoing BEACON frame buffer and corresponding TXD */
1948 struct rt_txwi BeaconTxWI;
1949 u8 *BeaconBuf;
1950 u16 BeaconOffset[HW_BEACON_MAX_COUNT];
1951
1952 /* pre-build PS-POLL and NULL frame upon link up. for efficiency purpose. */
1953 struct rt_pspoll_frame PsPollFrame;
1954 struct rt_header_802_11 NullFrame;
1955
1956#ifdef RTMP_MAC_USB
1957 struct rt_tx_context BeaconContext[BEACON_RING_SIZE];
1958 struct rt_tx_context NullContext;
1959 struct rt_tx_context PsPollContext;
1960 struct rt_tx_context RTSContext;
1961#endif /* RTMP_MAC_USB // */
1962
1963/*=========AP=========== */
1964
1965/*=======STA=========== */
1966 /* ----------------------------------------------- */
1967 /* STA specific configuration & operation status */
1968 /* used only when pAd->OpMode == OPMODE_STA */
1969 /* ----------------------------------------------- */
1970 struct rt_sta_admin_config StaCfg; /* user desired settings */
1971 struct rt_sta_active_config StaActive; /* valid only when ADHOC_ON(pAd) || INFRA_ON(pAd) */
1972 char nickname[IW_ESSID_MAX_SIZE + 1]; /* nickname, only used in the iwconfig i/f */
1973 int PreMediaState;
1974
1975/*=======Common=========== */
1976 /* OP mode: either AP or STA */
1977 u8 OpMode; /* OPMODE_STA, OPMODE_AP */
1978
1979 int IndicateMediaState; /* Base on Indication state, default is NdisMediaStateDisConnected */
1980
1981 /* MAT related parameters */
1982
1983 /* configuration: read from Registry & E2PROM */
1984 BOOLEAN bLocalAdminMAC; /* Use user changed MAC */
1985 u8 PermanentAddress[MAC_ADDR_LEN]; /* Factory default MAC address */
1986 u8 CurrentAddress[MAC_ADDR_LEN]; /* User changed MAC address */
1987
1988 /* ------------------------------------------------------ */
1989 /* common configuration to both OPMODE_STA and OPMODE_AP */
1990 /* ------------------------------------------------------ */
1991 struct rt_common_config CommonCfg;
1992 struct rt_mlme Mlme;
1993
1994 /* AP needs those variables for site survey feature. */
1995 struct rt_mlme_aux MlmeAux; /* temporary settings used during MLME state machine */
1996 struct rt_bss_table ScanTab; /* store the latest SCAN result */
1997
1998 /*About MacTab, the sta driver will use #0 and #1 for multicast and AP. */
1999 struct rt_mac_table MacTab; /* ASIC on-chip WCID entry table. At TX, ASIC always use key according to this on-chip table. */
2000 spinlock_t MacTabLock;
2001
2002 struct rt_ba_table BATable;
2003
2004 spinlock_t BATabLock;
2005 struct rt_ralink_timer RECBATimer;
2006
2007 /* encryption/decryption KEY tables */
2008 struct rt_cipher_key SharedKey[MAX_MBSSID_NUM][4]; /* STA always use SharedKey[BSS0][0..3] */
2009
2010 /* RX re-assembly buffer for fragmentation */
2011 struct rt_fragment_frame FragFrame; /* Frame storage for fragment frame */
2012
2013 /* various Counters */
2014 struct rt_counter_802_3 Counters8023; /* 802.3 counters */
2015 struct rt_counter_802_11 WlanCounters; /* 802.11 MIB counters */
2016 struct rt_counter_ralink RalinkCounters; /* Ralink proprietary counters */
2017 struct rt_counter_drs DrsCounters; /* counters for Dynamic TX Rate Switching */
2018 struct rt_private PrivateInfo; /* Private information & counters */
2019
2020 /* flags, see fRTMP_ADAPTER_xxx flags */
2021 unsigned long Flags; /* Represent current device status */
2022 unsigned long PSFlags; /* Power Save operation flag. */
2023
2024 /* current TX sequence # */
2025 u16 Sequence;
2026
2027 /* Control disconnect / connect event generation */
2028 /*+++Not used anymore */
2029 unsigned long LinkDownTime;
2030 /*--- */
2031 unsigned long LastRxRate;
2032 unsigned long LastTxRate;
2033 /*+++Used only for Station */
2034 BOOLEAN bConfigChanged; /* Config Change flag for the same SSID setting */
2035 /*--- */
2036
2037 unsigned long ExtraInfo; /* Extra information for displaying status */
2038 unsigned long SystemErrorBitmap; /* b0: E2PROM version error */
2039
2040 /*+++Not used anymore */
2041 unsigned long MacIcVersion; /* MAC/BBP serial interface issue solved after ver.D */
2042 /*--- */
2043
2044 /* --------------------------- */
2045 /* System event log */
2046 /* --------------------------- */
2047 struct rt_802_11_event_table EventTab;
2048
2049 BOOLEAN HTCEnable;
2050
2051 /*****************************************************************************************/
2052 /* Statistic related parameters */
2053 /*****************************************************************************************/
2054#ifdef RTMP_MAC_USB
2055 unsigned long BulkOutDataOneSecCount;
2056 unsigned long BulkInDataOneSecCount;
2057 unsigned long BulkLastOneSecCount; /* BulkOutDataOneSecCount + BulkInDataOneSecCount */
2058 unsigned long watchDogRxCnt;
2059 unsigned long watchDogRxOverFlowCnt;
2060 unsigned long watchDogTxPendingCnt[NUM_OF_TX_RING];
2061 int TransferedLength[NUM_OF_TX_RING];
2062#endif /* RTMP_MAC_USB // */
2063
2064 BOOLEAN bUpdateBcnCntDone;
2065 unsigned long watchDogMacDeadlock; /* prevent MAC/BBP into deadlock condition */
2066 /* ---------------------------- */
2067 /* DEBUG paramerts */
2068 /* ---------------------------- */
2069 /*unsigned long DebugSetting[4]; */
2070 BOOLEAN bBanAllBaSetup;
2071 BOOLEAN bPromiscuous;
2072
2073 /* ---------------------------- */
2074 /* rt2860c emulation-use Parameters */
2075 /* ---------------------------- */
2076 /*unsigned long rtsaccu[30]; */
2077 /*unsigned long ctsaccu[30]; */
2078 /*unsigned long cfendaccu[30]; */
2079 /*unsigned long bacontent[16]; */
2080 /*unsigned long rxint[RX_RING_SIZE+1]; */
2081 /*u8 rcvba[60]; */
2082 BOOLEAN bLinkAdapt;
2083 BOOLEAN bForcePrintTX;
2084 BOOLEAN bForcePrintRX;
2085 /*BOOLEAN bDisablescanning; //defined in RT2870 USB */
2086 BOOLEAN bStaFifoTest;
2087 BOOLEAN bProtectionTest;
2088 BOOLEAN bBroadComHT;
2089 /*+++Following add from RT2870 USB. */
2090 unsigned long BulkOutReq;
2091 unsigned long BulkOutComplete;
2092 unsigned long BulkOutCompleteOther;
2093 unsigned long BulkOutCompleteCancel; /* seems not used now? */
2094 unsigned long BulkInReq;
2095 unsigned long BulkInComplete;
2096 unsigned long BulkInCompleteFail;
2097 /*--- */
2098
2099 struct wificonf WIFItestbed;
2100
2101 struct reordering_mpdu_pool mpdu_blk_pool;
2102
2103 unsigned long OneSecondnonBEpackets; /* record non BE packets per second */
2104
2105#ifdef LINUX
2106 struct iw_statistics iw_stats;
2107
2108 struct net_device_stats stats;
2109#endif /* LINUX // */
2110
2111 unsigned long TbttTickCount;
2112#ifdef PCI_MSI_SUPPORT
2113 BOOLEAN HaveMsi;
2114#endif /* PCI_MSI_SUPPORT // */
2115
2116 u8 is_on;
2117
2118#define TIME_BASE (1000000/OS_HZ)
2119#define TIME_ONE_SECOND (1000000/TIME_BASE)
2120 u8 flg_be_adjust;
2121 unsigned long be_adjust_last_time;
2122
2123 u8 FlgCtsEnabled;
2124 u8 PM_FlgSuspend;
2125
2126#ifdef RT30xx
2127#ifdef RTMP_EFUSE_SUPPORT
2128 BOOLEAN bUseEfuse;
2129 u8 EEPROMImage[1024];
2130#endif /* RTMP_EFUSE_SUPPORT // */
2131#endif /* RT30xx // */
2132};
2133
2134#define DELAYINTMASK 0x0003fffb
2135#define INTMASK 0x0003fffb
2136#define IndMask 0x0003fffc
2137#define RxINT 0x00000005 /* Delayed Rx or indivi rx */
2138#define TxDataInt 0x000000fa /* Delayed Tx or indivi tx */
2139#define TxMgmtInt 0x00000102 /* Delayed Tx or indivi tx */
2140#define TxCoherent 0x00020000 /* tx coherent */
2141#define RxCoherent 0x00010000 /* rx coherent */
2142#define McuCommand 0x00000200 /* mcu */
2143#define PreTBTTInt 0x00001000 /* Pre-TBTT interrupt */
2144#define TBTTInt 0x00000800 /* TBTT interrupt */
2145#define GPTimeOutInt 0x00008000 /* GPtimeout interrupt */
2146#define AutoWakeupInt 0x00004000 /* AutoWakeupInt interrupt */
2147#define FifoStaFullInt 0x00002000 /* fifo statistics full interrupt */
2148
2149/***************************************************************************
2150 * Rx Path software control block related data structures
2151 **************************************************************************/
2152struct rt_rx_blk {
2153 RT28XX_RXD_STRUC RxD;
2154 struct rt_rxwi *pRxWI;
2155 struct rt_header_802_11 *pHeader;
2156 void *pRxPacket;
2157 u8 *pData;
2158 u16 DataSize;
2159 u16 Flags;
2160 u8 UserPriority; /* for calculate TKIP MIC using */
2161};
2162
2163#define RX_BLK_SET_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags |= _flag)
2164#define RX_BLK_TEST_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags & _flag)
2165#define RX_BLK_CLEAR_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags &= ~(_flag))
2166
2167#define fRX_WDS 0x0001
2168#define fRX_AMSDU 0x0002
2169#define fRX_ARALINK 0x0004
2170#define fRX_HTC 0x0008
2171#define fRX_PAD 0x0010
2172#define fRX_AMPDU 0x0020
2173#define fRX_QOS 0x0040
2174#define fRX_INFRA 0x0080
2175#define fRX_EAP 0x0100
2176#define fRX_MESH 0x0200
2177#define fRX_APCLI 0x0400
2178#define fRX_DLS 0x0800
2179#define fRX_WPI 0x1000
2180
2181#define LENGTH_AMSDU_SUBFRAMEHEAD 14
2182#define LENGTH_ARALINK_SUBFRAMEHEAD 14
2183#define LENGTH_ARALINK_HEADER_FIELD 2
2184
2185/***************************************************************************
2186 * Tx Path software control block related data structures
2187 **************************************************************************/
2188#define TX_UNKOWN_FRAME 0x00
2189#define TX_MCAST_FRAME 0x01
2190#define TX_LEGACY_FRAME 0x02
2191#define TX_AMPDU_FRAME 0x04
2192#define TX_AMSDU_FRAME 0x08
2193#define TX_RALINK_FRAME 0x10
2194#define TX_FRAG_FRAME 0x20
2195
2196/* Currently the sizeof(struct rt_tx_blk) is 148 bytes. */
2197struct rt_tx_blk {
2198 u8 QueIdx;
2199 u8 TxFrameType; /* Indicate the Transmission type of the all frames in one batch */
2200 u8 TotalFrameNum; /* Total frame number that wants to send-out in one batch */
2201 u16 TotalFragNum; /* Total frame fragments required in one batch */
2202 u16 TotalFrameLen; /* Total length of all frames that wants to send-out in one batch */
2203
2204 struct rt_queue_header TxPacketList;
2205 struct rt_mac_table_entry *pMacEntry; /* NULL: packet with 802.11 RA field is multicast/broadcast address */
2206 HTTRANSMIT_SETTING *pTransmit;
2207
2208 /* Following structure used for the characteristics of a specific packet. */
2209 void *pPacket;
2210 u8 *pSrcBufHeader; /* Reference to the head of sk_buff->data */
2211 u8 *pSrcBufData; /* Reference to the sk_buff->data, will change depending on the handling progresss */
2212 u32 SrcBufLen; /* Length of packet payload which not including Layer 2 header */
2213 u8 *pExtraLlcSnapEncap; /* NULL means no extra LLC/SNAP is required */
2214 u8 HeaderBuf[128]; /* TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP */
2215 /*RT2870 2.1.0.0 uses only 80 bytes */
2216 /*RT3070 2.1.1.0 uses only 96 bytes */
2217 /*RT3090 2.1.0.0 uses only 96 bytes */
2218 u8 MpduHeaderLen; /* 802.11 header length NOT including the padding */
2219 u8 HdrPadLen; /* recording Header Padding Length; */
2220 u8 apidx; /* The interface associated to this packet */
2221 u8 Wcid; /* The MAC entry associated to this packet */
2222 u8 UserPriority; /* priority class of packet */
2223 u8 FrameGap; /* what kind of IFS does this packet use */
2224 u8 MpduReqNum; /* number of fragments of this frame */
2225 u8 TxRate; /* TODO: Obsoleted? Should change to MCS? */
2226 u8 CipherAlg; /* cipher alogrithm */
2227 struct rt_cipher_key *pKey;
2228
2229 u16 Flags; /*See following definitions for detail. */
2230
2231 /*YOU SHOULD NOT TOUCH IT! Following parameters are used for hardware-depended layer. */
2232 unsigned long Priv; /* Hardware specific value saved in here. */
2233};
2234
2235#define fTX_bRtsRequired 0x0001 /* Indicate if need send RTS frame for protection. Not used in RT2860/RT2870. */
2236#define fTX_bAckRequired 0x0002 /* the packet need ack response */
2237#define fTX_bPiggyBack 0x0004 /* Legacy device use Piggback or not */
2238#define fTX_bHTRate 0x0008 /* allow to use HT rate */
2239#define fTX_bForceNonQoS 0x0010 /* force to transmit frame without WMM-QoS in HT mode */
2240#define fTX_bAllowFrag 0x0020 /* allow to fragment the packet, A-MPDU, A-MSDU, A-Ralink is not allowed to fragment */
2241#define fTX_bMoreData 0x0040 /* there are more data packets in PowerSave Queue */
2242#define fTX_bWMM 0x0080 /* QOS Data */
2243#define fTX_bClearEAPFrame 0x0100
2244
2245#define TX_BLK_SET_FLAG(_pTxBlk, _flag) (_pTxBlk->Flags |= _flag)
2246#define TX_BLK_TEST_FLAG(_pTxBlk, _flag) (((_pTxBlk->Flags & _flag) == _flag) ? 1 : 0)
2247#define TX_BLK_CLEAR_FLAG(_pTxBlk, _flag) (_pTxBlk->Flags &= ~(_flag))
2248
2249/***************************************************************************
2250 * Other static inline function definitions
2251 **************************************************************************/
2252static inline void ConvertMulticastIP2MAC(u8 *pIpAddr,
2253 u8 **ppMacAddr,
2254 u16 ProtoType)
2255{
2256 if (pIpAddr == NULL)
2257 return;
2258
2259 if (ppMacAddr == NULL || *ppMacAddr == NULL)
2260 return;
2261
2262 switch (ProtoType) {
2263 case ETH_P_IPV6:
2264/* memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS); */
2265 *(*ppMacAddr) = 0x33;
2266 *(*ppMacAddr + 1) = 0x33;
2267 *(*ppMacAddr + 2) = pIpAddr[12];
2268 *(*ppMacAddr + 3) = pIpAddr[13];
2269 *(*ppMacAddr + 4) = pIpAddr[14];
2270 *(*ppMacAddr + 5) = pIpAddr[15];
2271 break;
2272
2273 case ETH_P_IP:
2274 default:
2275/* memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS); */
2276 *(*ppMacAddr) = 0x01;
2277 *(*ppMacAddr + 1) = 0x00;
2278 *(*ppMacAddr + 2) = 0x5e;
2279 *(*ppMacAddr + 3) = pIpAddr[1] & 0x7f;
2280 *(*ppMacAddr + 4) = pIpAddr[2];
2281 *(*ppMacAddr + 5) = pIpAddr[3];
2282 break;
2283 }
2284
2285 return;
2286}
2287
2288char *GetPhyMode(int Mode);
2289char *GetBW(int BW);
2290
2291/* */
2292/* Private routines in rtmp_init.c */
2293/* */
2294int RTMPAllocAdapterBlock(void *handle,
2295 struct rt_rtmp_adapter **ppAdapter);
2296
2297int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd);
2298
2299void RTMPFreeAdapter(struct rt_rtmp_adapter *pAd);
2300
2301int NICReadRegParameters(struct rt_rtmp_adapter *pAd,
2302 void *WrapperConfigurationContext);
2303
2304#ifdef RTMP_RF_RW_SUPPORT
2305void NICInitRFRegisters(struct rt_rtmp_adapter *pAd);
2306
2307void RtmpChipOpsRFHook(struct rt_rtmp_adapter *pAd);
2308
2309int RT30xxWriteRFRegister(struct rt_rtmp_adapter *pAd,
2310 u8 regID, u8 value);
2311
2312int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd,
2313 u8 regID, u8 *pValue);
2314#endif /* RTMP_RF_RW_SUPPORT // */
2315
2316void NICReadEEPROMParameters(struct rt_rtmp_adapter *pAd, u8 *mac_addr);
2317
2318void NICInitAsicFromEEPROM(struct rt_rtmp_adapter *pAd);
2319
2320int NICInitializeAdapter(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset);
2321
2322int NICInitializeAsic(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset);
2323
2324void NICIssueReset(struct rt_rtmp_adapter *pAd);
2325
2326void RTMPRingCleanUp(struct rt_rtmp_adapter *pAd, u8 RingType);
2327
2328void UserCfgInit(struct rt_rtmp_adapter *pAd);
2329
2330void NICResetFromError(struct rt_rtmp_adapter *pAd);
2331
2332int NICLoadFirmware(struct rt_rtmp_adapter *pAd);
2333
2334void NICEraseFirmware(struct rt_rtmp_adapter *pAd);
2335
2336int NICLoadRateSwitchingParams(struct rt_rtmp_adapter *pAd);
2337
2338BOOLEAN NICCheckForHang(struct rt_rtmp_adapter *pAd);
2339
2340void NICUpdateFifoStaCounters(struct rt_rtmp_adapter *pAd);
2341
2342void NICUpdateRawCounters(struct rt_rtmp_adapter *pAd);
2343
2344void RTMPZeroMemory(void *pSrc, unsigned long Length);
2345
2346unsigned long RTMPCompareMemory(void *pSrc1, void *pSrc2, unsigned long Length);
2347
2348void RTMPMoveMemory(void *pDest, void *pSrc, unsigned long Length);
2349
2350void AtoH(char *src, u8 *dest, int destlen);
2351
2352void RTMPPatchMacBbpBug(struct rt_rtmp_adapter *pAd);
2353
2354void RTMPInitTimer(struct rt_rtmp_adapter *pAd,
2355 struct rt_ralink_timer *pTimer,
2356 void *pTimerFunc, void *pData, IN BOOLEAN Repeat);
2357
2358void RTMPSetTimer(struct rt_ralink_timer *pTimer, unsigned long Value);
2359
2360void RTMPModTimer(struct rt_ralink_timer *pTimer, unsigned long Value);
2361
2362void RTMPCancelTimer(struct rt_ralink_timer *pTimer, OUT BOOLEAN * pCancelled);
2363
2364void RTMPSetLED(struct rt_rtmp_adapter *pAd, u8 Status);
2365
2366void RTMPSetSignalLED(struct rt_rtmp_adapter *pAd, IN NDIS_802_11_RSSI Dbm);
2367
2368void RTMPEnableRxTx(struct rt_rtmp_adapter *pAd);
2369
2370/* */
2371/* prototype in action.c */
2372/* */
2373void ActionStateMachineInit(struct rt_rtmp_adapter *pAd,
2374 struct rt_state_machine *S,
2375 OUT STATE_MACHINE_FUNC Trans[]);
2376
2377void MlmeADDBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2378
2379void MlmeDELBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2380
2381void MlmeDLSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2382
2383void MlmeInvalidAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2384
2385void MlmeQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2386
2387void PeerAddBAReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2388
2389void PeerAddBARspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2390
2391void PeerDelBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2392
2393void PeerBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2394
2395void SendPSMPAction(struct rt_rtmp_adapter *pAd, u8 Wcid, u8 Psmp);
2396
2397void PeerRMAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2398
2399void PeerPublicAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2400
2401void PeerHTAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2402
2403void PeerQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2404
2405void RECBATimerTimeout(void *SystemSpecific1,
2406 void *FunctionContext,
2407 void *SystemSpecific2, void *SystemSpecific3);
2408
2409void ORIBATimerTimeout(struct rt_rtmp_adapter *pAd);
2410
2411void SendRefreshBAR(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
2412
2413void ActHeaderInit(struct rt_rtmp_adapter *pAd,
2414 struct rt_header_802_11 *pHdr80211,
2415 u8 *Addr1, u8 *Addr2, u8 *Addr3);
2416
2417void BarHeaderInit(struct rt_rtmp_adapter *pAd,
2418 struct rt_frame_bar *pCntlBar, u8 *pDA, u8 *pSA);
2419
2420void InsertActField(struct rt_rtmp_adapter *pAd,
2421 u8 *pFrameBuf,
2422 unsigned long *pFrameLen, u8 Category, u8 ActCode);
2423
2424BOOLEAN CntlEnqueueForRecv(struct rt_rtmp_adapter *pAd,
2425 unsigned long Wcid,
2426 unsigned long MsgLen, struct rt_frame_ba_req *pMsg);
2427
2428/* */
2429/* Private routines in rtmp_data.c */
2430/* */
2431BOOLEAN RTMPHandleRxDoneInterrupt(struct rt_rtmp_adapter *pAd);
2432
2433BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd,
2434 INT_SOURCE_CSR_STRUC TxRingBitmap);
2435
2436void RTMPHandleMgmtRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd);
2437
2438void RTMPHandleTBTTInterrupt(struct rt_rtmp_adapter *pAd);
2439
2440void RTMPHandlePreTBTTInterrupt(struct rt_rtmp_adapter *pAd);
2441
2442void RTMPHandleTwakeupInterrupt(struct rt_rtmp_adapter *pAd);
2443
2444void RTMPHandleRxCoherentInterrupt(struct rt_rtmp_adapter *pAd);
2445
2446BOOLEAN TxFrameIsAggregatible(struct rt_rtmp_adapter *pAd,
2447 u8 *pPrevAddr1, u8 *p8023hdr);
2448
2449BOOLEAN PeerIsAggreOn(struct rt_rtmp_adapter *pAd,
2450 unsigned long TxRate, struct rt_mac_table_entry *pMacEntry);
2451
2452int Sniff2BytesFromNdisBuffer(char *pFirstBuffer,
2453 u8 DesiredOffset,
2454 u8 *pByte0, u8 *pByte1);
2455
2456int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket);
2457
2458void STASendPackets(void *MiniportAdapterContext,
2459 void **ppPacketArray, u32 NumberOfPackets);
2460
2461void RTMPDeQueuePacket(struct rt_rtmp_adapter *pAd,
2462 IN BOOLEAN bIntContext,
2463 u8 QueIdx, u8 Max_Tx_Packets);
2464
2465int RTMPHardTransmit(struct rt_rtmp_adapter *pAd,
2466 void *pPacket,
2467 u8 QueIdx, unsigned long *pFreeTXDLeft);
2468
2469int STAHardTransmit(struct rt_rtmp_adapter *pAd,
2470 struct rt_tx_blk *pTxBlk, u8 QueIdx);
2471
2472void STARxEAPOLFrameIndicate(struct rt_rtmp_adapter *pAd,
2473 struct rt_mac_table_entry *pEntry,
2474 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
2475
2476int RTMPFreeTXDRequest(struct rt_rtmp_adapter *pAd,
2477 u8 RingType,
2478 u8 NumberRequired, u8 *FreeNumberIs);
2479
2480int MlmeHardTransmit(struct rt_rtmp_adapter *pAd,
2481 u8 QueIdx, void *pPacket);
2482
2483int MlmeHardTransmitMgmtRing(struct rt_rtmp_adapter *pAd,
2484 u8 QueIdx, void *pPacket);
2485
2486#ifdef RTMP_MAC_PCI
2487int MlmeHardTransmitTxRing(struct rt_rtmp_adapter *pAd,
2488 u8 QueIdx, void *pPacket);
2489
2490int MlmeDataHardTransmit(struct rt_rtmp_adapter *pAd,
2491 u8 QueIdx, void *pPacket);
2492
2493void RTMPWriteTxDescriptor(struct rt_rtmp_adapter *pAd,
2494 struct rt_txd *pTxD, IN BOOLEAN bWIV, u8 QSEL);
2495#endif /* RTMP_MAC_PCI // */
2496
2497u16 RTMPCalcDuration(struct rt_rtmp_adapter *pAd, u8 Rate, unsigned long Size);
2498
2499void RTMPWriteTxWI(struct rt_rtmp_adapter *pAd, struct rt_txwi * pTxWI, IN BOOLEAN FRAG, IN BOOLEAN CFACK, IN BOOLEAN InsTimestamp, IN BOOLEAN AMPDU, IN BOOLEAN Ack, IN BOOLEAN NSeq, /* HW new a sequence. */
2500 u8 BASize,
2501 u8 WCID,
2502 unsigned long Length,
2503 u8 PID,
2504 u8 TID,
2505 u8 TxRate,
2506 u8 Txopmode,
2507 IN BOOLEAN CfAck, IN HTTRANSMIT_SETTING *pTransmit);
2508
2509void RTMPWriteTxWI_Data(struct rt_rtmp_adapter *pAd,
2510 struct rt_txwi *pTxWI, struct rt_tx_blk *pTxBlk);
2511
2512void RTMPWriteTxWI_Cache(struct rt_rtmp_adapter *pAd,
2513 struct rt_txwi *pTxWI, struct rt_tx_blk *pTxBlk);
2514
2515void RTMPSuspendMsduTransmission(struct rt_rtmp_adapter *pAd);
2516
2517void RTMPResumeMsduTransmission(struct rt_rtmp_adapter *pAd);
2518
2519int MiniportMMRequest(struct rt_rtmp_adapter *pAd,
2520 u8 QueIdx, u8 *pData, u32 Length);
2521
2522/*+++mark by shiang, now this function merge to MiniportMMRequest() */
2523/*---mark by shiang, now this function merge to MiniportMMRequest() */
2524
2525void RTMPSendNullFrame(struct rt_rtmp_adapter *pAd,
2526 u8 TxRate, IN BOOLEAN bQosNull);
2527
2528void RTMPSendDisassociationFrame(struct rt_rtmp_adapter *pAd);
2529
2530void RTMPSendRTSFrame(struct rt_rtmp_adapter *pAd,
2531 u8 *pDA,
2532 IN unsigned int NextMpduSize,
2533 u8 TxRate,
2534 u8 RTSRate,
2535 u16 AckDuration,
2536 u8 QueIdx, u8 FrameGap);
2537
2538struct rt_queue_header *RTMPCheckTxSwQueue(struct rt_rtmp_adapter *pAd, u8 * QueIdx);
2539
2540void RTMPReportMicError(struct rt_rtmp_adapter *pAd, struct rt_cipher_key *pWpaKey);
2541
2542void WpaMicFailureReportFrame(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2543
2544void WpaDisassocApAndBlockAssoc(void *SystemSpecific1,
2545 void *FunctionContext,
2546 void *SystemSpecific2,
2547 void *SystemSpecific3);
2548
2549void WpaStaPairwiseKeySetting(struct rt_rtmp_adapter *pAd);
2550
2551void WpaStaGroupKeySetting(struct rt_rtmp_adapter *pAd);
2552
2553int RTMPCloneNdisPacket(struct rt_rtmp_adapter *pAd,
2554 IN BOOLEAN pInsAMSDUHdr,
2555 void *pInPacket,
2556 void **ppOutPacket);
2557
2558int RTMPAllocateNdisPacket(struct rt_rtmp_adapter *pAd,
2559 void **pPacket,
2560 u8 *pHeader,
2561 u32 HeaderLen,
2562 u8 *pData, u32 DataLen);
2563
2564void RTMPFreeNdisPacket(struct rt_rtmp_adapter *pAd, void *pPacket);
2565
2566BOOLEAN RTMPFreeTXDUponTxDmaDone(struct rt_rtmp_adapter *pAd, u8 QueIdx);
2567
2568BOOLEAN RTMPCheckDHCPFrame(struct rt_rtmp_adapter *pAd, void *pPacket);
2569
2570BOOLEAN RTMPCheckEtherType(struct rt_rtmp_adapter *pAd, void *pPacket);
2571
2572/* */
2573/* Private routines in rtmp_wep.c */
2574/* */
2575void RTMPInitWepEngine(struct rt_rtmp_adapter *pAd,
2576 u8 *pKey,
2577 u8 KeyId, u8 KeyLen, u8 *pDest);
2578
2579void RTMPEncryptData(struct rt_rtmp_adapter *pAd,
2580 u8 *pSrc, u8 *pDest, u32 Len);
2581
2582BOOLEAN RTMPSoftDecryptWEP(struct rt_rtmp_adapter *pAd,
2583 u8 *pData,
2584 unsigned long DataByteCnt, struct rt_cipher_key *pGroupKey);
2585
2586void RTMPSetICV(struct rt_rtmp_adapter *pAd, u8 *pDest);
2587
2588void ARCFOUR_INIT(struct rt_arcfourcontext *Ctx, u8 *pKey, u32 KeyLen);
2589
2590u8 ARCFOUR_BYTE(struct rt_arcfourcontext *Ctx);
2591
2592void ARCFOUR_DECRYPT(struct rt_arcfourcontext *Ctx,
2593 u8 *pDest, u8 *pSrc, u32 Len);
2594
2595void ARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx,
2596 u8 *pDest, u8 *pSrc, u32 Len);
2597
2598void WPAARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx,
2599 u8 *pDest, u8 *pSrc, u32 Len);
2600
2601u32 RTMP_CALC_FCS32(u32 Fcs, u8 *Cp, int Len);
2602
2603/* */
2604/* MLME routines */
2605/* */
2606
2607/* Asic/RF/BBP related functions */
2608
2609void AsicAdjustTxPower(struct rt_rtmp_adapter *pAd);
2610
2611void AsicUpdateProtect(struct rt_rtmp_adapter *pAd,
2612 u16 OperaionMode,
2613 u8 SetMask,
2614 IN BOOLEAN bDisableBGProtect, IN BOOLEAN bNonGFExist);
2615
2616void AsicSwitchChannel(struct rt_rtmp_adapter *pAd,
2617 u8 Channel, IN BOOLEAN bScan);
2618
2619void AsicLockChannel(struct rt_rtmp_adapter *pAd, u8 Channel);
2620
2621void AsicRfTuningExec(void *SystemSpecific1,
2622 void *FunctionContext,
2623 void *SystemSpecific2, void *SystemSpecific3);
2624
2625void AsicResetBBPAgent(struct rt_rtmp_adapter *pAd);
2626
2627void AsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
2628 u16 TbttNumToNextWakeUp);
2629
2630void AsicForceSleep(struct rt_rtmp_adapter *pAd);
2631
2632void AsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
2633
2634void AsicSetBssid(struct rt_rtmp_adapter *pAd, u8 *pBssid);
2635
2636void AsicSetMcastWC(struct rt_rtmp_adapter *pAd);
2637
2638void AsicDelWcidTab(struct rt_rtmp_adapter *pAd, u8 Wcid);
2639
2640void AsicEnableRDG(struct rt_rtmp_adapter *pAd);
2641
2642void AsicDisableRDG(struct rt_rtmp_adapter *pAd);
2643
2644void AsicDisableSync(struct rt_rtmp_adapter *pAd);
2645
2646void AsicEnableBssSync(struct rt_rtmp_adapter *pAd);
2647
2648void AsicEnableIbssSync(struct rt_rtmp_adapter *pAd);
2649
2650void AsicSetEdcaParm(struct rt_rtmp_adapter *pAd, struct rt_edca_parm *pEdcaParm);
2651
2652void AsicSetSlotTime(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUseShortSlotTime);
2653
2654void AsicAddSharedKeyEntry(struct rt_rtmp_adapter *pAd,
2655 u8 BssIndex,
2656 u8 KeyIdx,
2657 u8 CipherAlg,
2658 u8 *pKey, u8 *pTxMic, u8 *pRxMic);
2659
2660void AsicRemoveSharedKeyEntry(struct rt_rtmp_adapter *pAd,
2661 u8 BssIndex, u8 KeyIdx);
2662
2663void AsicUpdateWCIDAttribute(struct rt_rtmp_adapter *pAd,
2664 u16 WCID,
2665 u8 BssIndex,
2666 u8 CipherAlg,
2667 IN BOOLEAN bUsePairewiseKeyTable);
2668
2669void AsicUpdateWCIDIVEIV(struct rt_rtmp_adapter *pAd,
2670 u16 WCID, unsigned long uIV, unsigned long uEIV);
2671
2672void AsicUpdateRxWCIDTable(struct rt_rtmp_adapter *pAd,
2673 u16 WCID, u8 *pAddr);
2674
2675void AsicAddKeyEntry(struct rt_rtmp_adapter *pAd,
2676 u16 WCID,
2677 u8 BssIndex,
2678 u8 KeyIdx,
2679 struct rt_cipher_key *pCipherKey,
2680 IN BOOLEAN bUsePairewiseKeyTable, IN BOOLEAN bTxKey);
2681
2682void AsicAddPairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2683 u8 *pAddr,
2684 u8 WCID, struct rt_cipher_key *pCipherKey);
2685
2686void AsicRemovePairwiseKeyEntry(struct rt_rtmp_adapter *pAd,
2687 u8 BssIdx, u8 Wcid);
2688
2689BOOLEAN AsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
2690 u8 Command,
2691 u8 Token, u8 Arg0, u8 Arg1);
2692
2693#ifdef RTMP_MAC_PCI
2694BOOLEAN AsicCheckCommanOk(struct rt_rtmp_adapter *pAd, u8 Command);
2695#endif /* RTMP_MAC_PCI // */
2696
2697void MacAddrRandomBssid(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2698
2699void MgtMacHeaderInit(struct rt_rtmp_adapter *pAd,
2700 struct rt_header_802_11 *pHdr80211,
2701 u8 SubType,
2702 u8 ToDs, u8 *pDA, u8 *pBssid);
2703
2704void MlmeRadioOff(struct rt_rtmp_adapter *pAd);
2705
2706void MlmeRadioOn(struct rt_rtmp_adapter *pAd);
2707
2708void BssTableInit(struct rt_bss_table *Tab);
2709
2710void BATableInit(struct rt_rtmp_adapter *pAd, struct rt_ba_table *Tab);
2711
2712unsigned long BssTableSearch(struct rt_bss_table *Tab, u8 *pBssid, u8 Channel);
2713
2714unsigned long BssSsidTableSearch(struct rt_bss_table *Tab,
2715 u8 *pBssid,
2716 u8 *pSsid, u8 SsidLen, u8 Channel);
2717
2718unsigned long BssTableSearchWithSSID(struct rt_bss_table *Tab,
2719 u8 *Bssid,
2720 u8 *pSsid,
2721 u8 SsidLen, u8 Channel);
2722
2723unsigned long BssSsidTableSearchBySSID(struct rt_bss_table *Tab,
2724 u8 *pSsid, u8 SsidLen);
2725
2726void BssTableDeleteEntry(struct rt_bss_table *pTab,
2727 u8 *pBssid, u8 Channel);
2728
2729void BATableDeleteORIEntry(struct rt_rtmp_adapter *pAd,
2730 struct rt_ba_ori_entry *pBAORIEntry);
2731
2732void BssEntrySet(struct rt_rtmp_adapter *pAd, struct rt_bss_entry *pBss, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */
2733 u8 HtCapabilityLen,
2734 u8 AddHtInfoLen,
2735 u8 NewExtChanOffset,
2736 u8 Channel,
2737 char Rssi,
2738 IN LARGE_INTEGER TimeStamp,
2739 u8 CkipFlag,
2740 struct rt_edca_parm *pEdcaParm,
2741 struct rt_qos_capability_parm *pQosCapability,
2742 struct rt_qbss_load_parm *pQbssLoad,
2743 u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE);
2744
2745unsigned long BssTableSetEntry(struct rt_rtmp_adapter *pAd, struct rt_bss_table *pTab, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */
2746 u8 HtCapabilityLen,
2747 u8 AddHtInfoLen,
2748 u8 NewExtChanOffset,
2749 u8 Channel,
2750 char Rssi,
2751 IN LARGE_INTEGER TimeStamp,
2752 u8 CkipFlag,
2753 struct rt_edca_parm *pEdcaParm,
2754 struct rt_qos_capability_parm *pQosCapability,
2755 struct rt_qbss_load_parm *pQbssLoad,
2756 u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE);
2757
2758void BATableInsertEntry(struct rt_rtmp_adapter *pAd,
2759 u16 Aid,
2760 u16 TimeOutValue,
2761 u16 StartingSeq,
2762 u8 TID,
2763 u8 BAWinSize,
2764 u8 OriginatorStatus, IN BOOLEAN IsRecipient);
2765
2766void BssTableSsidSort(struct rt_rtmp_adapter *pAd,
2767 struct rt_bss_table *OutTab, char Ssid[], u8 SsidLen);
2768
2769void BssTableSortByRssi(struct rt_bss_table *OutTab);
2770
2771void BssCipherParse(struct rt_bss_entry *pBss);
2772
2773int MlmeQueueInit(struct rt_mlme_queue *Queue);
2774
2775void MlmeQueueDestroy(struct rt_mlme_queue *Queue);
2776
2777BOOLEAN MlmeEnqueue(struct rt_rtmp_adapter *pAd,
2778 unsigned long Machine,
2779 unsigned long MsgType, unsigned long MsgLen, void *Msg);
2780
2781BOOLEAN MlmeEnqueueForRecv(struct rt_rtmp_adapter *pAd,
2782 unsigned long Wcid,
2783 unsigned long TimeStampHigh,
2784 unsigned long TimeStampLow,
2785 u8 Rssi0,
2786 u8 Rssi1,
2787 u8 Rssi2,
2788 unsigned long MsgLen, void *Msg, u8 Signal);
2789
2790BOOLEAN MlmeDequeue(struct rt_mlme_queue *Queue, struct rt_mlme_queue_elem **Elem);
2791
2792void MlmeRestartStateMachine(struct rt_rtmp_adapter *pAd);
2793
2794BOOLEAN MlmeQueueEmpty(struct rt_mlme_queue *Queue);
2795
2796BOOLEAN MlmeQueueFull(struct rt_mlme_queue *Queue);
2797
2798BOOLEAN MsgTypeSubst(struct rt_rtmp_adapter *pAd,
2799 struct rt_frame_802_11 *pFrame,
2800 int *Machine, int *MsgType);
2801
2802void StateMachineInit(struct rt_state_machine *Sm,
2803 IN STATE_MACHINE_FUNC Trans[],
2804 unsigned long StNr,
2805 unsigned long MsgNr,
2806 IN STATE_MACHINE_FUNC DefFunc,
2807 unsigned long InitState, unsigned long Base);
2808
2809void StateMachineSetAction(struct rt_state_machine *S,
2810 unsigned long St, unsigned long Msg, IN STATE_MACHINE_FUNC F);
2811
2812void StateMachinePerformAction(struct rt_rtmp_adapter *pAd,
2813 struct rt_state_machine *S, struct rt_mlme_queue_elem *Elem);
2814
2815void Drop(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2816
2817void AssocStateMachineInit(struct rt_rtmp_adapter *pAd,
2818 struct rt_state_machine *Sm,
2819 OUT STATE_MACHINE_FUNC Trans[]);
2820
2821void ReassocTimeout(void *SystemSpecific1,
2822 void *FunctionContext,
2823 void *SystemSpecific2, void *SystemSpecific3);
2824
2825void AssocTimeout(void *SystemSpecific1,
2826 void *FunctionContext,
2827 void *SystemSpecific2, void *SystemSpecific3);
2828
2829void DisassocTimeout(void *SystemSpecific1,
2830 void *FunctionContext,
2831 void *SystemSpecific2, void *SystemSpecific3);
2832
2833/*---------------------------------------------- */
2834void MlmeAssocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2835
2836void MlmeReassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2837
2838void MlmeDisassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2839
2840void PeerAssocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2841
2842void PeerReassocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2843
2844void PeerDisassocAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2845
2846void DisassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2847
2848void AssocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2849
2850void ReassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2851
2852void Cls3errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2853
2854void InvalidStateWhenAssoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2855
2856void InvalidStateWhenReassoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2857
2858void InvalidStateWhenDisassociate(struct rt_rtmp_adapter *pAd,
2859 struct rt_mlme_queue_elem *Elem);
2860
2861#ifdef RTMP_MAC_USB
2862void MlmeCntlConfirm(struct rt_rtmp_adapter *pAd, unsigned long MsgType, u16 Msg);
2863#endif /* RTMP_MAC_USB // */
2864
2865void ComposePsPoll(struct rt_rtmp_adapter *pAd);
2866
2867void ComposeNullFrame(struct rt_rtmp_adapter *pAd);
2868
2869void AssocPostProc(struct rt_rtmp_adapter *pAd,
2870 u8 *pAddr2,
2871 u16 CapabilityInfo,
2872 u16 Aid,
2873 u8 SupRate[],
2874 u8 SupRateLen,
2875 u8 ExtRate[],
2876 u8 ExtRateLen,
2877 struct rt_edca_parm *pEdcaParm,
2878 struct rt_ht_capability_ie *pHtCapability,
2879 u8 HtCapabilityLen, struct rt_add_ht_info_ie *pAddHtInfo);
2880
2881void AuthStateMachineInit(struct rt_rtmp_adapter *pAd,
2882 struct rt_state_machine *sm, OUT STATE_MACHINE_FUNC Trans[]);
2883
2884void AuthTimeout(void *SystemSpecific1,
2885 void *FunctionContext,
2886 void *SystemSpecific2, void *SystemSpecific3);
2887
2888void MlmeAuthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2889
2890void PeerAuthRspAtSeq2Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2891
2892void PeerAuthRspAtSeq4Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2893
2894void AuthTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2895
2896void Cls2errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr);
2897
2898void MlmeDeauthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2899
2900void InvalidStateWhenAuth(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2901
2902/*============================================= */
2903
2904void AuthRspStateMachineInit(struct rt_rtmp_adapter *pAd,
2905 struct rt_state_machine *Sm,
2906 IN STATE_MACHINE_FUNC Trans[]);
2907
2908void PeerDeauthAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2909
2910void PeerAuthSimpleRspGenAndSend(struct rt_rtmp_adapter *pAd,
2911 struct rt_header_802_11 *pHdr80211,
2912 u16 Alg,
2913 u16 Seq,
2914 u16 Reason, u16 Status);
2915
2916/* */
2917/* Private routines in dls.c */
2918/* */
2919
2920/*======================================== */
2921
2922void SyncStateMachineInit(struct rt_rtmp_adapter *pAd,
2923 struct rt_state_machine *Sm,
2924 OUT STATE_MACHINE_FUNC Trans[]);
2925
2926void BeaconTimeout(void *SystemSpecific1,
2927 void *FunctionContext,
2928 void *SystemSpecific2, void *SystemSpecific3);
2929
2930void ScanTimeout(void *SystemSpecific1,
2931 void *FunctionContext,
2932 void *SystemSpecific2, void *SystemSpecific3);
2933
2934void InvalidStateWhenScan(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2935
2936void InvalidStateWhenJoin(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2937
2938void InvalidStateWhenStart(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2939
2940void EnqueueProbeRequest(struct rt_rtmp_adapter *pAd);
2941
2942BOOLEAN ScanRunning(struct rt_rtmp_adapter *pAd);
2943/*========================================= */
2944
2945void MlmeCntlInit(struct rt_rtmp_adapter *pAd,
2946 struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[]);
2947
2948void MlmeCntlMachinePerformAction(struct rt_rtmp_adapter *pAd,
2949 struct rt_state_machine *S,
2950 struct rt_mlme_queue_elem *Elem);
2951
2952void CntlIdleProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2953
2954void CntlOidScanProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2955
2956void CntlOidSsidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2957
2958void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2959
2960void CntlMlmeRoamingProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2961
2962void CntlWaitDisassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2963
2964void CntlWaitJoinProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2965
2966void CntlWaitReassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2967
2968void CntlWaitStartProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2969
2970void CntlWaitAuthProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2971
2972void CntlWaitAuthProc2(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2973
2974void CntlWaitAssocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
2975
2976void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType);
2977
2978void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP);
2979
2980void IterateOnBssTab(struct rt_rtmp_adapter *pAd);
2981
2982void IterateOnBssTab2(struct rt_rtmp_adapter *pAd);
2983
2984void JoinParmFill(struct rt_rtmp_adapter *pAd,
2985 struct rt_mlme_join_req *JoinReq, unsigned long BssIdx);
2986
2987void AssocParmFill(struct rt_rtmp_adapter *pAd,
2988 struct rt_mlme_assoc_req *AssocReq,
2989 u8 *pAddr,
2990 u16 CapabilityInfo,
2991 unsigned long Timeout, u16 ListenIntv);
2992
2993void ScanParmFill(struct rt_rtmp_adapter *pAd,
2994 struct rt_mlme_scan_req *ScanReq,
2995 char Ssid[],
2996 u8 SsidLen, u8 BssType, u8 ScanType);
2997
2998void DisassocParmFill(struct rt_rtmp_adapter *pAd,
2999 struct rt_mlme_disassoc_req *DisassocReq,
3000 u8 *pAddr, u16 Reason);
3001
3002void StartParmFill(struct rt_rtmp_adapter *pAd,
3003 struct rt_mlme_start_req *StartReq,
3004 char Ssid[], u8 SsidLen);
3005
3006void AuthParmFill(struct rt_rtmp_adapter *pAd,
3007 struct rt_mlme_auth_req *AuthReq,
3008 u8 *pAddr, u16 Alg);
3009
3010void EnqueuePsPoll(struct rt_rtmp_adapter *pAd);
3011
3012void EnqueueBeaconFrame(struct rt_rtmp_adapter *pAd);
3013
3014void MlmeJoinReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3015
3016void MlmeScanReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3017
3018void MlmeStartReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3019
3020void ScanTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3021
3022void BeaconTimeoutAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3023
3024void PeerBeaconAtScanAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3025
3026void PeerBeaconAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3027
3028void PeerBeacon(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3029
3030void PeerProbeReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
3031
3032void ScanNextChannel(struct rt_rtmp_adapter *pAd);
3033
3034unsigned long MakeIbssBeacon(struct rt_rtmp_adapter *pAd);
3035
3036BOOLEAN MlmeScanReqSanity(struct rt_rtmp_adapter *pAd,
3037 void *Msg,
3038 unsigned long MsgLen,
3039 u8 *BssType,
3040 char ssid[],
3041 u8 *SsidLen, u8 *ScanType);
3042
3043BOOLEAN PeerBeaconAndProbeRspSanity(struct rt_rtmp_adapter *pAd,
3044 void *Msg,
3045 unsigned long MsgLen,
3046 u8 MsgChannel,
3047 u8 *pAddr2,
3048 u8 *pBssid,
3049 char Ssid[],
3050 u8 *pSsidLen,
3051 u8 *pBssType,
3052 u16 *pBeaconPeriod,
3053 u8 *pChannel,
3054 u8 *pNewChannel,
3055 OUT LARGE_INTEGER *pTimestamp,
3056 struct rt_cf_parm *pCfParm,
3057 u16 *pAtimWin,
3058 u16 *pCapabilityInfo,
3059 u8 *pErp,
3060 u8 *pDtimCount,
3061 u8 *pDtimPeriod,
3062 u8 *pBcastFlag,
3063 u8 *pMessageToMe,
3064 u8 SupRate[],
3065 u8 *pSupRateLen,
3066 u8 ExtRate[],
3067 u8 *pExtRateLen,
3068 u8 *pCkipFlag,
3069 u8 *pAironetCellPowerLimit,
3070 struct rt_edca_parm *pEdcaParm,
3071 struct rt_qbss_load_parm *pQbssLoad,
3072 struct rt_qos_capability_parm *pQosCapability,
3073 unsigned long *pRalinkIe,
3074 u8 *pHtCapabilityLen,
3075 u8 *pPreNHtCapabilityLen,
3076 struct rt_ht_capability_ie *pHtCapability,
3077 u8 *AddHtInfoLen,
3078 struct rt_add_ht_info_ie *AddHtInfo,
3079 u8 *NewExtChannel,
3080 u16 *LengthVIE,
3081 struct rt_ndis_802_11_variable_ies *pVIE);
3082
3083BOOLEAN PeerAddBAReqActionSanity(struct rt_rtmp_adapter *pAd,
3084 void *pMsg,
3085 unsigned long MsgLen, u8 *pAddr2);
3086
3087BOOLEAN PeerAddBARspActionSanity(struct rt_rtmp_adapter *pAd,
3088 void *pMsg, unsigned long MsgLen);
3089
3090BOOLEAN PeerDelBAActionSanity(struct rt_rtmp_adapter *pAd,
3091 u8 Wcid, void *pMsg, unsigned long MsgLen);
3092
3093BOOLEAN MlmeAssocReqSanity(struct rt_rtmp_adapter *pAd,
3094 void *Msg,
3095 unsigned long MsgLen,
3096 u8 *pApAddr,
3097 u16 *CapabilityInfo,
3098 unsigned long *Timeout, u16 *ListenIntv);
3099
3100BOOLEAN MlmeAuthReqSanity(struct rt_rtmp_adapter *pAd,
3101 void *Msg,
3102 unsigned long MsgLen,
3103 u8 *pAddr,
3104 unsigned long *Timeout, u16 *Alg);
3105
3106BOOLEAN MlmeStartReqSanity(struct rt_rtmp_adapter *pAd,
3107 void *Msg,
3108 unsigned long MsgLen,
3109 char Ssid[], u8 *Ssidlen);
3110
3111BOOLEAN PeerAuthSanity(struct rt_rtmp_adapter *pAd,
3112 void *Msg,
3113 unsigned long MsgLen,
3114 u8 *pAddr,
3115 u16 *Alg,
3116 u16 *Seq,
3117 u16 *Status, char ChlgText[]);
3118
3119BOOLEAN PeerAssocRspSanity(struct rt_rtmp_adapter *pAd, void *pMsg, unsigned long MsgLen, u8 *pAddr2, u16 *pCapabilityInfo, u16 *pStatus, u16 *pAid, u8 SupRate[], u8 *pSupRateLen, u8 ExtRate[], u8 *pExtRateLen, struct rt_ht_capability_ie *pHtCapability, struct rt_add_ht_info_ie *pAddHtInfo, /* AP might use this additional ht info IE */
3120 u8 *pHtCapabilityLen,
3121 u8 *pAddHtInfoLen,
3122 u8 *pNewExtChannelOffset,
3123 struct rt_edca_parm *pEdcaParm, u8 *pCkipFlag);
3124
3125BOOLEAN PeerDisassocSanity(struct rt_rtmp_adapter *pAd,
3126 void *Msg,
3127 unsigned long MsgLen,
3128 u8 *pAddr2, u16 *Reason);
3129
3130BOOLEAN PeerWpaMessageSanity(struct rt_rtmp_adapter *pAd,
3131 struct rt_eapol_packet *pMsg,
3132 unsigned long MsgLen,
3133 u8 MsgType, struct rt_mac_table_entry *pEntry);
3134
3135BOOLEAN PeerDeauthSanity(struct rt_rtmp_adapter *pAd,
3136 void *Msg,
3137 unsigned long MsgLen,
3138 u8 *pAddr2, u16 *Reason);
3139
3140BOOLEAN PeerProbeReqSanity(struct rt_rtmp_adapter *pAd,
3141 void *Msg,
3142 unsigned long MsgLen,
3143 u8 *pAddr2,
3144 char Ssid[], u8 *pSsidLen);
3145
3146BOOLEAN GetTimBit(char *Ptr,
3147 u16 Aid,
3148 u8 *TimLen,
3149 u8 *BcastFlag,
3150 u8 *DtimCount,
3151 u8 *DtimPeriod, u8 *MessageToMe);
3152
3153u8 ChannelSanity(struct rt_rtmp_adapter *pAd, u8 channel);
3154
3155NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(struct rt_bss_entry *pBss);
3156
3157BOOLEAN MlmeDelBAReqSanity(struct rt_rtmp_adapter *pAd,
3158 void *Msg, unsigned long MsgLen);
3159
3160BOOLEAN MlmeAddBAReqSanity(struct rt_rtmp_adapter *pAd,
3161 void *Msg, unsigned long MsgLen, u8 *pAddr2);
3162
3163unsigned long MakeOutgoingFrame(u8 *Buffer, unsigned long *Length, ...);
3164
3165void LfsrInit(struct rt_rtmp_adapter *pAd, unsigned long Seed);
3166
3167u8 RandomByte(struct rt_rtmp_adapter *pAd);
3168
3169void AsicUpdateAutoFallBackTable(struct rt_rtmp_adapter *pAd, u8 *pTxRate);
3170
3171void MlmePeriodicExec(void *SystemSpecific1,
3172 void *FunctionContext,
3173 void *SystemSpecific2, void *SystemSpecific3);
3174
3175void LinkDownExec(void *SystemSpecific1,
3176 void *FunctionContext,
3177 void *SystemSpecific2, void *SystemSpecific3);
3178
3179void STAMlmePeriodicExec(struct rt_rtmp_adapter *pAd);
3180
3181void MlmeAutoScan(struct rt_rtmp_adapter *pAd);
3182
3183void MlmeAutoReconnectLastSSID(struct rt_rtmp_adapter *pAd);
3184
3185BOOLEAN MlmeValidateSSID(u8 *pSsid, u8 SsidLen);
3186
3187void MlmeCheckForRoaming(struct rt_rtmp_adapter *pAd, unsigned long Now32);
3188
3189BOOLEAN MlmeCheckForFastRoaming(struct rt_rtmp_adapter *pAd);
3190
3191void MlmeDynamicTxRateSwitching(struct rt_rtmp_adapter *pAd);
3192
3193void MlmeSetTxRate(struct rt_rtmp_adapter *pAd,
3194 struct rt_mac_table_entry *pEntry, struct rt_rtmp_tx_rate_switch * pTxRate);
3195
3196void MlmeSelectTxRateTable(struct rt_rtmp_adapter *pAd,
3197 struct rt_mac_table_entry *pEntry,
3198 u8 **ppTable,
3199 u8 *pTableSize, u8 *pInitTxRateIdx);
3200
3201void MlmeCalculateChannelQuality(struct rt_rtmp_adapter *pAd,
3202 struct rt_mac_table_entry *pMacEntry, unsigned long Now);
3203
3204void MlmeCheckPsmChange(struct rt_rtmp_adapter *pAd, unsigned long Now32);
3205
3206void MlmeSetPsmBit(struct rt_rtmp_adapter *pAd, u16 psm);
3207
3208void MlmeSetTxPreamble(struct rt_rtmp_adapter *pAd, u16 TxPreamble);
3209
3210void UpdateBasicRateBitmap(struct rt_rtmp_adapter *pAd);
3211
3212void MlmeUpdateTxRates(struct rt_rtmp_adapter *pAd,
3213 IN BOOLEAN bLinkUp, u8 apidx);
3214
3215void MlmeUpdateHtTxRates(struct rt_rtmp_adapter *pAd, u8 apidx);
3216
3217void RTMPCheckRates(struct rt_rtmp_adapter *pAd,
3218 IN u8 SupRate[], IN u8 *SupRateLen);
3219
3220BOOLEAN RTMPCheckChannel(struct rt_rtmp_adapter *pAd,
3221 u8 CentralChannel, u8 Channel);
3222
3223BOOLEAN RTMPCheckHt(struct rt_rtmp_adapter *pAd,
3224 u8 Wcid,
3225 struct rt_ht_capability_ie *pHtCapability,
3226 struct rt_add_ht_info_ie *pAddHtInfo);
3227
3228void StaQuickResponeForRateUpExec(void *SystemSpecific1,
3229 void *FunctionContext,
3230 void *SystemSpecific2,
3231 void *SystemSpecific3);
3232
3233void RTMPUpdateMlmeRate(struct rt_rtmp_adapter *pAd);
3234
3235char RTMPMaxRssi(struct rt_rtmp_adapter *pAd,
3236 char Rssi0, char Rssi1, char Rssi2);
3237
3238#ifdef RT30xx
3239void AsicSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant);
3240
3241void RTMPFilterCalibration(struct rt_rtmp_adapter *pAd);
3242
3243#ifdef RTMP_EFUSE_SUPPORT
3244/*2008/09/11:KH add to support efuse<-- */
3245int set_eFuseGetFreeBlockCount_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3246
3247int set_eFusedump_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3248
3249void eFusePhysicalReadRegisters(struct rt_rtmp_adapter *pAd,
3250 u16 Offset,
3251 u16 Length, u16 *pData);
3252
3253int RtmpEfuseSupportCheck(struct rt_rtmp_adapter *pAd);
3254
3255void eFuseGetFreeBlockCount(struct rt_rtmp_adapter *pAd, u32 *EfuseFreeBlock);
3256
3257int eFuse_init(struct rt_rtmp_adapter *pAd);
3258/*2008/09/11:KH add to support efuse--> */
3259#endif /* RTMP_EFUSE_SUPPORT // */
3260
3261/* add by johnli, RF power sequence setup */
3262void RT30xxLoadRFNormalModeSetup(struct rt_rtmp_adapter *pAd);
3263
3264void RT30xxLoadRFSleepModeSetup(struct rt_rtmp_adapter *pAd);
3265
3266void RT30xxReverseRFSleepModeSetup(struct rt_rtmp_adapter *pAd);
3267/* end johnli */
3268
3269#ifdef RT3070
3270void NICInitRT3070RFRegisters(struct rt_rtmp_adapter *pAd);
3271#endif /* RT3070 // */
3272#ifdef RT3090
3273void NICInitRT3090RFRegisters(struct rt_rtmp_adapter *pAd);
3274#endif /* RT3090 // */
3275
3276void RT30xxHaltAction(struct rt_rtmp_adapter *pAd);
3277
3278void RT30xxSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant);
3279#endif /* RT30xx // */
3280
3281void AsicEvaluateRxAnt(struct rt_rtmp_adapter *pAd);
3282
3283void AsicRxAntEvalTimeout(void *SystemSpecific1,
3284 void *FunctionContext,
3285 void *SystemSpecific2, void *SystemSpecific3);
3286
3287void APSDPeriodicExec(void *SystemSpecific1,
3288 void *FunctionContext,
3289 void *SystemSpecific2, void *SystemSpecific3);
3290
3291BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(struct rt_rtmp_adapter *pAd,
3292 struct rt_mac_table_entry *pEntry);
3293
3294u8 RTMPStaFixedTxMode(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3295
3296void RTMPUpdateLegacyTxSetting(u8 fixed_tx_mode, struct rt_mac_table_entry *pEntry);
3297
3298BOOLEAN RTMPAutoRateSwitchCheck(struct rt_rtmp_adapter *pAd);
3299
3300int MlmeInit(struct rt_rtmp_adapter *pAd);
3301
3302void MlmeHandler(struct rt_rtmp_adapter *pAd);
3303
3304void MlmeHalt(struct rt_rtmp_adapter *pAd);
3305
3306void MlmeResetRalinkCounters(struct rt_rtmp_adapter *pAd);
3307
3308void BuildChannelList(struct rt_rtmp_adapter *pAd);
3309
3310u8 FirstChannel(struct rt_rtmp_adapter *pAd);
3311
3312u8 NextChannel(struct rt_rtmp_adapter *pAd, u8 channel);
3313
3314void ChangeToCellPowerLimit(struct rt_rtmp_adapter *pAd,
3315 u8 AironetCellPowerLimit);
3316
3317/* */
3318/* Prototypes of function definition in rtmp_tkip.c */
3319/* */
3320void RTMPInitTkipEngine(struct rt_rtmp_adapter *pAd,
3321 u8 *pTKey,
3322 u8 KeyId,
3323 u8 *pTA,
3324 u8 *pMICKey,
3325 u8 *pTSC, unsigned long *pIV16, unsigned long *pIV32);
3326
3327void RTMPInitMICEngine(struct rt_rtmp_adapter *pAd,
3328 u8 *pKey,
3329 u8 *pDA,
3330 u8 *pSA, u8 UserPriority, u8 *pMICKey);
3331
3332BOOLEAN RTMPTkipCompareMICValue(struct rt_rtmp_adapter *pAd,
3333 u8 *pSrc,
3334 u8 *pDA,
3335 u8 *pSA,
3336 u8 *pMICKey,
3337 u8 UserPriority, u32 Len);
3338
3339void RTMPCalculateMICValue(struct rt_rtmp_adapter *pAd,
3340 void *pPacket,
3341 u8 *pEncap,
3342 struct rt_cipher_key *pKey, u8 apidx);
3343
3344void RTMPTkipAppendByte(struct rt_tkip_key_info *pTkip, u8 uChar);
3345
3346void RTMPTkipAppend(struct rt_tkip_key_info *pTkip, u8 *pSrc, u32 nBytes);
3347
3348void RTMPTkipGetMIC(struct rt_tkip_key_info *pTkip);
3349
3350BOOLEAN RTMPSoftDecryptTKIP(struct rt_rtmp_adapter *pAd,
3351 u8 *pData,
3352 unsigned long DataByteCnt,
3353 u8 UserPriority, struct rt_cipher_key *pWpaKey);
3354
3355BOOLEAN RTMPSoftDecryptAES(struct rt_rtmp_adapter *pAd,
3356 u8 *pData,
3357 unsigned long DataByteCnt, struct rt_cipher_key *pWpaKey);
3358
3359/* */
3360/* Prototypes of function definition in cmm_info.c */
3361/* */
3362int RT_CfgSetCountryRegion(struct rt_rtmp_adapter *pAd, char *arg, int band);
3363
3364int RT_CfgSetWirelessMode(struct rt_rtmp_adapter *pAd, char *arg);
3365
3366int RT_CfgSetShortSlot(struct rt_rtmp_adapter *pAd, char *arg);
3367
3368int RT_CfgSetWepKey(struct rt_rtmp_adapter *pAd,
3369 char *keyString,
3370 struct rt_cipher_key *pSharedKey, int keyIdx);
3371
3372int RT_CfgSetWPAPSKKey(struct rt_rtmp_adapter *pAd,
3373 char *keyString,
3374 u8 *pHashStr,
3375 int hashStrLen, u8 *pPMKBuf);
3376
3377/* */
3378/* Prototypes of function definition in cmm_info.c */
3379/* */
3380void RTMPWPARemoveAllKeys(struct rt_rtmp_adapter *pAd);
3381
3382void RTMPSetPhyMode(struct rt_rtmp_adapter *pAd, unsigned long phymode);
3383
3384void RTMPUpdateHTIE(struct rt_ht_capability *pRtHt,
3385 u8 *pMcsSet,
3386 struct rt_ht_capability_ie *pHtCapability,
3387 struct rt_add_ht_info_ie *pAddHtInfo);
3388
3389void RTMPAddWcidAttributeEntry(struct rt_rtmp_adapter *pAd,
3390 u8 BssIdx,
3391 u8 KeyIdx,
3392 u8 CipherAlg, struct rt_mac_table_entry *pEntry);
3393
3394char *GetEncryptType(char enc);
3395
3396char *GetAuthMode(char auth);
3397
3398void RTMPSetHT(struct rt_rtmp_adapter *pAd, struct rt_oid_set_ht_phymode *pHTPhyMode);
3399
3400void RTMPSetIndividualHT(struct rt_rtmp_adapter *pAd, u8 apidx);
3401
3402void RTMPSendWirelessEvent(struct rt_rtmp_adapter *pAd,
3403 u16 Event_flag,
3404 u8 *pAddr, u8 BssIdx, char Rssi);
3405
3406char ConvertToRssi(struct rt_rtmp_adapter *pAd, char Rssi, u8 RssiNumber);
3407
3408/*===================================
3409 Function prototype in cmm_wpa.c
3410 =================================== */
3411void RTMPToWirelessSta(struct rt_rtmp_adapter *pAd,
3412 struct rt_mac_table_entry *pEntry,
3413 u8 *pHeader802_3,
3414 u32 HdrLen,
3415 u8 *pData,
3416 u32 DataLen, IN BOOLEAN bClearFrame);
3417
3418void WpaDerivePTK(struct rt_rtmp_adapter *pAd,
3419 u8 *PMK,
3420 u8 *ANonce,
3421 u8 *AA,
3422 u8 *SNonce,
3423 u8 *SA, u8 *output, u32 len);
3424
3425void GenRandom(struct rt_rtmp_adapter *pAd, u8 *macAddr, u8 *random);
3426
3427BOOLEAN RTMPCheckWPAframe(struct rt_rtmp_adapter *pAd,
3428 struct rt_mac_table_entry *pEntry,
3429 u8 *pData,
3430 unsigned long DataByteCount, u8 FromWhichBSSID);
3431
3432void AES_GTK_KEY_UNWRAP(u8 *key,
3433 u8 *plaintext,
3434 u32 c_len, u8 *ciphertext);
3435
3436BOOLEAN RTMPParseEapolKeyData(struct rt_rtmp_adapter *pAd,
3437 u8 *pKeyData,
3438 u8 KeyDataLen,
3439 u8 GroupKeyIndex,
3440 u8 MsgType,
3441 IN BOOLEAN bWPA2, struct rt_mac_table_entry *pEntry);
3442
3443void ConstructEapolMsg(struct rt_mac_table_entry *pEntry,
3444 u8 GroupKeyWepStatus,
3445 u8 MsgType,
3446 u8 DefaultKeyIdx,
3447 u8 *KeyNonce,
3448 u8 *TxRSC,
3449 u8 *GTK,
3450 u8 *RSNIE,
3451 u8 RSNIE_Len, struct rt_eapol_packet *pMsg);
3452
3453int RTMPSoftDecryptBroadCastData(struct rt_rtmp_adapter *pAd,
3454 struct rt_rx_blk *pRxBlk,
3455 IN NDIS_802_11_ENCRYPTION_STATUS
3456 GroupCipher,
3457 struct rt_cipher_key *pShard_key);
3458
3459void RTMPMakeRSNIE(struct rt_rtmp_adapter *pAd,
3460 u32 AuthMode, u32 WepStatus, u8 apidx);
3461
3462/* */
3463/* function prototype in ap_wpa.c */
3464/* */
3465void RTMPGetTxTscFromAsic(struct rt_rtmp_adapter *pAd,
3466 u8 apidx, u8 *pTxTsc);
3467
3468void APInstallPairwiseKey(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3469
3470u32 APValidateRSNIE(struct rt_rtmp_adapter *pAd,
3471 struct rt_mac_table_entry *pEntry,
3472 u8 *pRsnIe, u8 rsnie_len);
3473
3474void HandleCounterMeasure(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3475
3476void WPAStart4WayHS(struct rt_rtmp_adapter *pAd,
3477 struct rt_mac_table_entry *pEntry, unsigned long TimeInterval);
3478
3479void WPAStart2WayGroupHS(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry);
3480
3481void PeerPairMsg1Action(struct rt_rtmp_adapter *pAd,
3482 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3483
3484void PeerPairMsg2Action(struct rt_rtmp_adapter *pAd,
3485 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3486
3487void PeerPairMsg3Action(struct rt_rtmp_adapter *pAd,
3488 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3489
3490void PeerPairMsg4Action(struct rt_rtmp_adapter *pAd,
3491 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3492
3493void PeerGroupMsg1Action(struct rt_rtmp_adapter *pAd,
3494 struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem);
3495
3496void PeerGroupMsg2Action(struct rt_rtmp_adapter *pAd,
3497 struct rt_mac_table_entry *pEntry,
3498 void *Msg, u32 MsgLen);
3499
3500void WpaDeriveGTK(u8 *PMK,
3501 u8 *GNonce,
3502 u8 *AA, u8 *output, u32 len);
3503
3504void AES_GTK_KEY_WRAP(u8 *key,
3505 u8 *plaintext,
3506 u32 p_len, u8 *ciphertext);
3507
3508/*typedef void (*TIMER_FUNCTION)(unsigned long); */
3509
3510/* timeout -- ms */
3511void RTMP_SetPeriodicTimer(struct timer_list *pTimer,
3512 IN unsigned long timeout);
3513
3514void RTMP_OS_Init_Timer(struct rt_rtmp_adapter *pAd,
3515 struct timer_list *pTimer,
3516 IN TIMER_FUNCTION function, void *data);
3517
3518void RTMP_OS_Add_Timer(struct timer_list *pTimer,
3519 IN unsigned long timeout);
3520
3521void RTMP_OS_Mod_Timer(struct timer_list *pTimer,
3522 IN unsigned long timeout);
3523
3524void RTMP_OS_Del_Timer(struct timer_list *pTimer,
3525 OUT BOOLEAN *pCancelled);
3526
3527void RTMP_OS_Release_Packet(struct rt_rtmp_adapter *pAd, struct rt_queue_entry *pEntry);
3528
3529void RTMPusecDelay(unsigned long usec);
3530
3531int os_alloc_mem(struct rt_rtmp_adapter *pAd,
3532 u8 **mem, unsigned long size);
3533
3534int os_free_mem(struct rt_rtmp_adapter *pAd, void *mem);
3535
3536void RTMP_AllocateSharedMemory(struct rt_rtmp_adapter *pAd,
3537 unsigned long Length,
3538 IN BOOLEAN Cached,
3539 void **VirtualAddress,
3540 dma_addr_t *PhysicalAddress);
3541
3542void RTMPFreeTxRxRingMemory(struct rt_rtmp_adapter *pAd);
3543
3544int AdapterBlockAllocateMemory(void *handle, void **ppAd);
3545
3546void RTMP_AllocateTxDescMemory(struct rt_rtmp_adapter *pAd,
3547 u32 Index,
3548 unsigned long Length,
3549 IN BOOLEAN Cached,
3550 void **VirtualAddress,
3551 dma_addr_t *PhysicalAddress);
3552
3553void RTMP_AllocateFirstTxBuffer(struct rt_rtmp_adapter *pAd,
3554 u32 Index,
3555 unsigned long Length,
3556 IN BOOLEAN Cached,
3557 void **VirtualAddress,
3558 dma_addr_t *PhysicalAddress);
3559
3560void RTMP_FreeFirstTxBuffer(struct rt_rtmp_adapter *pAd,
3561 unsigned long Length,
3562 IN BOOLEAN Cached,
3563 void *VirtualAddress,
3564 dma_addr_t PhysicalAddress);
3565
3566void RTMP_AllocateMgmtDescMemory(struct rt_rtmp_adapter *pAd,
3567 unsigned long Length,
3568 IN BOOLEAN Cached,
3569 void **VirtualAddress,
3570 dma_addr_t *PhysicalAddress);
3571
3572void RTMP_AllocateRxDescMemory(struct rt_rtmp_adapter *pAd,
3573 unsigned long Length,
3574 IN BOOLEAN Cached,
3575 void **VirtualAddress,
3576 dma_addr_t *PhysicalAddress);
3577
3578void RTMP_FreeDescMemory(struct rt_rtmp_adapter *pAd,
3579 unsigned long Length,
3580 void *VirtualAddress,
3581 dma_addr_t PhysicalAddress);
3582
3583void *RtmpOSNetPktAlloc(struct rt_rtmp_adapter *pAd, IN int size);
3584
3585void *RTMP_AllocateRxPacketBuffer(struct rt_rtmp_adapter *pAd,
3586 unsigned long Length,
3587 IN BOOLEAN Cached,
3588 void **VirtualAddress,
3589 OUT dma_addr_t *PhysicalAddress);
3590
3591void *RTMP_AllocateTxPacketBuffer(struct rt_rtmp_adapter *pAd,
3592 unsigned long Length,
3593 IN BOOLEAN Cached,
3594 void **VirtualAddress);
3595
3596void *RTMP_AllocateFragPacketBuffer(struct rt_rtmp_adapter *pAd,
3597 unsigned long Length);
3598
3599void RTMP_QueryPacketInfo(void *pPacket,
3600 struct rt_packet_info *pPacketInfo,
3601 u8 **pSrcBufVA, u32 *pSrcBufLen);
3602
3603void RTMP_QueryNextPacketInfo(void **ppPacket,
3604 struct rt_packet_info *pPacketInfo,
3605 u8 **pSrcBufVA, u32 *pSrcBufLen);
3606
3607BOOLEAN RTMP_FillTxBlkInfo(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk);
3608
3609struct rt_rtmp_sg_list *rt_get_sg_list_from_packet(void *pPacket,
3610 struct rt_rtmp_sg_list *sg);
3611
3612void announce_802_3_packet(struct rt_rtmp_adapter *pAd, void *pPacket);
3613
3614u32 BA_Reorder_AMSDU_Announce(struct rt_rtmp_adapter *pAd, void *pPacket);
3615
3616struct net_device *get_netdev_from_bssid(struct rt_rtmp_adapter *pAd, u8 FromWhichBSSID);
3617
3618void *duplicate_pkt(struct rt_rtmp_adapter *pAd,
3619 u8 *pHeader802_3,
3620 u32 HdrLen,
3621 u8 *pData,
3622 unsigned long DataSize, u8 FromWhichBSSID);
3623
3624void *duplicate_pkt_with_TKIP_MIC(struct rt_rtmp_adapter *pAd,
3625 void *pOldPkt);
3626
3627void ba_flush_reordering_timeout_mpdus(struct rt_rtmp_adapter *pAd,
3628 struct rt_ba_rec_entry *pBAEntry,
3629 unsigned long Now32);
3630
3631void BAOriSessionSetUp(struct rt_rtmp_adapter *pAd,
3632 struct rt_mac_table_entry *pEntry,
3633 u8 TID,
3634 u16 TimeOut,
3635 unsigned long DelayTime, IN BOOLEAN isForced);
3636
3637void BASessionTearDownALL(struct rt_rtmp_adapter *pAd, u8 Wcid);
3638
3639BOOLEAN OS_Need_Clone_Packet(void);
3640
3641void build_tx_packet(struct rt_rtmp_adapter *pAd,
3642 void *pPacket,
3643 u8 *pFrame, unsigned long FrameLen);
3644
3645void BAOriSessionTearDown(struct rt_rtmp_adapter *pAd,
3646 u8 Wcid,
3647 u8 TID,
3648 IN BOOLEAN bPassive, IN BOOLEAN bForceSend);
3649
3650void BARecSessionTearDown(struct rt_rtmp_adapter *pAd,
3651 u8 Wcid, u8 TID, IN BOOLEAN bPassive);
3652
3653BOOLEAN ba_reordering_resource_init(struct rt_rtmp_adapter *pAd, int num);
3654void ba_reordering_resource_release(struct rt_rtmp_adapter *pAd);
3655
3656char *rstrtok(char *s, IN const char *ct);
3657
3658/*//////// common ioctl functions ////////// */
3659int SetCommonHT(struct rt_rtmp_adapter *pAd);
3660
3661int WpaCheckEapCode(struct rt_rtmp_adapter *pAd,
3662 u8 *pFrame, u16 FrameLen, u16 OffSet);
3663
3664void WpaSendMicFailureToWpaSupplicant(struct rt_rtmp_adapter *pAd,
3665 IN BOOLEAN bUnicast);
3666
3667int wext_notify_event_assoc(struct rt_rtmp_adapter *pAd);
3668
3669BOOLEAN STARxDoneInterruptHandle(struct rt_rtmp_adapter *pAd, IN BOOLEAN argc);
3670
3671/* AMPDU packet indication */
3672void Indicate_AMPDU_Packet(struct rt_rtmp_adapter *pAd,
3673 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3674
3675/* AMSDU packet indication */
3676void Indicate_AMSDU_Packet(struct rt_rtmp_adapter *pAd,
3677 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3678
3679/* Normal legacy Rx packet indication */
3680void Indicate_Legacy_Packet(struct rt_rtmp_adapter *pAd,
3681 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3682
3683void Indicate_EAPOL_Packet(struct rt_rtmp_adapter *pAd,
3684 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3685
3686void update_os_packet_info(struct rt_rtmp_adapter *pAd,
3687 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3688
3689void wlan_802_11_to_802_3_packet(struct rt_rtmp_adapter *pAd,
3690 struct rt_rx_blk *pRxBlk,
3691 u8 *pHeader802_3,
3692 u8 FromWhichBSSID);
3693
3694/* remove LLC and get 802_3 Header */
3695#define RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(_pRxBlk, _pHeader802_3) \
3696{ \
3697 u8 *_pRemovedLLCSNAP = NULL, *_pDA, *_pSA; \
3698 \
3699 if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_MESH)) { \
3700 _pDA = _pRxBlk->pHeader->Addr3; \
3701 _pSA = (u8 *)_pRxBlk->pHeader + sizeof(struct rt_header_802_11); \
3702 } \
3703 else {\
3704 if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_INFRA)) {\
3705 _pDA = _pRxBlk->pHeader->Addr1; \
3706 if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_DLS)) \
3707 _pSA = _pRxBlk->pHeader->Addr2; \
3708 else \
3709 _pSA = _pRxBlk->pHeader->Addr3; \
3710 } \
3711 else { \
3712 _pDA = _pRxBlk->pHeader->Addr1; \
3713 _pSA = _pRxBlk->pHeader->Addr2; \
3714 } \
3715 } \
3716 \
3717 CONVERT_TO_802_3(_pHeader802_3, _pDA, _pSA, _pRxBlk->pData, \
3718 _pRxBlk->DataSize, _pRemovedLLCSNAP); \
3719}
3720
3721void Sta_Announce_or_Forward_802_3_Packet(struct rt_rtmp_adapter *pAd,
3722 void *pPacket,
3723 u8 FromWhichBSSID);
3724
3725#define ANNOUNCE_OR_FORWARD_802_3_PACKET(_pAd, _pPacket, _FromWhichBSS)\
3726 Sta_Announce_or_Forward_802_3_Packet(_pAd, _pPacket, _FromWhichBSS);
3727 /*announce_802_3_packet(_pAd, _pPacket); */
3728
3729void *DuplicatePacket(struct rt_rtmp_adapter *pAd,
3730 void *pPacket, u8 FromWhichBSSID);
3731
3732void *ClonePacket(struct rt_rtmp_adapter *pAd,
3733 void *pPacket,
3734 u8 *pData, unsigned long DataSize);
3735
3736/* Normal, AMPDU or AMSDU */
3737void CmmRxnonRalinkFrameIndicate(struct rt_rtmp_adapter *pAd,
3738 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3739
3740void CmmRxRalinkFrameIndicate(struct rt_rtmp_adapter *pAd,
3741 struct rt_mac_table_entry *pEntry,
3742 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID);
3743
3744void Update_Rssi_Sample(struct rt_rtmp_adapter *pAd,
3745 struct rt_rssi_sample *pRssi, struct rt_rxwi * pRxWI);
3746
3747void *GetPacketFromRxRing(struct rt_rtmp_adapter *pAd,
3748 OUT PRT28XX_RXD_STRUC pSaveRxD,
3749 OUT BOOLEAN *pbReschedule,
3750 IN u32 *pRxPending);
3751
3752void *RTMPDeFragmentDataFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk);
3753
3754enum {
3755 DIDmsg_lnxind_wlansniffrm = 0x00000044,
3756 DIDmsg_lnxind_wlansniffrm_hosttime = 0x00010044,
3757 DIDmsg_lnxind_wlansniffrm_mactime = 0x00020044,
3758 DIDmsg_lnxind_wlansniffrm_channel = 0x00030044,
3759 DIDmsg_lnxind_wlansniffrm_rssi = 0x00040044,
3760 DIDmsg_lnxind_wlansniffrm_sq = 0x00050044,
3761 DIDmsg_lnxind_wlansniffrm_signal = 0x00060044,
3762 DIDmsg_lnxind_wlansniffrm_noise = 0x00070044,
3763 DIDmsg_lnxind_wlansniffrm_rate = 0x00080044,
3764 DIDmsg_lnxind_wlansniffrm_istx = 0x00090044,
3765 DIDmsg_lnxind_wlansniffrm_frmlen = 0x000A0044
3766};
3767enum {
3768 P80211ENUM_msgitem_status_no_value = 0x00
3769};
3770enum {
3771 P80211ENUM_truth_false = 0x00,
3772 P80211ENUM_truth_true = 0x01
3773};
3774
3775/* Definition from madwifi */
3776struct rt_p80211item_uint32 {
3777 u32 did;
3778 u16 status;
3779 u16 len;
3780 u32 data;
3781};
3782
3783struct rt_wlan_ng_prism2_header {
3784 u32 msgcode;
3785 u32 msglen;
3786#define WLAN_DEVNAMELEN_MAX 16
3787 u8 devname[WLAN_DEVNAMELEN_MAX];
3788 struct rt_p80211item_uint32 hosttime;
3789 struct rt_p80211item_uint32 mactime;
3790 struct rt_p80211item_uint32 channel;
3791 struct rt_p80211item_uint32 rssi;
3792 struct rt_p80211item_uint32 sq;
3793 struct rt_p80211item_uint32 signal;
3794 struct rt_p80211item_uint32 noise;
3795 struct rt_p80211item_uint32 rate;
3796 struct rt_p80211item_uint32 istx;
3797 struct rt_p80211item_uint32 frmlen;
3798};
3799
3800/* The radio capture header precedes the 802.11 header. */
3801struct PACKED rt_ieee80211_radiotap_header {
3802 u8 it_version; /* Version 0. Only increases
3803 * for drastic changes,
3804 * introduction of compatible
3805 * new fields does not count.
3806 */
3807 u8 it_pad;
3808 u16 it_len; /* length of the whole
3809 * header in bytes, including
3810 * it_version, it_pad,
3811 * it_len, and data fields.
3812 */
3813 u32 it_present; /* A bitmap telling which
3814 * fields are present. Set bit 31
3815 * (0x80000000) to extend the
3816 * bitmap by another 32 bits.
3817 * Additional extensions are made
3818 * by setting bit 31.
3819 */
3820};
3821
3822enum ieee80211_radiotap_type {
3823 IEEE80211_RADIOTAP_TSFT = 0,
3824 IEEE80211_RADIOTAP_FLAGS = 1,
3825 IEEE80211_RADIOTAP_RATE = 2,
3826 IEEE80211_RADIOTAP_CHANNEL = 3,
3827 IEEE80211_RADIOTAP_FHSS = 4,
3828 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
3829 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
3830 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
3831 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
3832 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
3833 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
3834 IEEE80211_RADIOTAP_ANTENNA = 11,
3835 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
3836 IEEE80211_RADIOTAP_DB_ANTNOISE = 13
3837};
3838
3839#define WLAN_RADIOTAP_PRESENT ( \
3840 (1 << IEEE80211_RADIOTAP_TSFT) | \
3841 (1 << IEEE80211_RADIOTAP_FLAGS) | \
3842 (1 << IEEE80211_RADIOTAP_RATE) | \
3843 0)
3844
3845struct rt_wlan_radiotap_header {
3846 struct rt_ieee80211_radiotap_header wt_ihdr;
3847 long long wt_tsft;
3848 u8 wt_flags;
3849 u8 wt_rate;
3850};
3851/* Definition from madwifi */
3852
3853void send_monitor_packets(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk);
3854
3855void RTMPSetDesiredRates(struct rt_rtmp_adapter *pAdapter, long Rates);
3856
3857int Set_FixedTxMode_Proc(struct rt_rtmp_adapter *pAd, char *arg);
3858
3859BOOLEAN RT28XXChipsetCheck(IN void *_dev_p);
3860
3861void RT28XXDMADisable(struct rt_rtmp_adapter *pAd);
3862
3863void RT28XXDMAEnable(struct rt_rtmp_adapter *pAd);
3864
3865void RT28xx_UpdateBeaconToAsic(struct rt_rtmp_adapter *pAd,
3866 int apidx,
3867 unsigned long BeaconLen, unsigned long UpdatePos);
3868
3869int rt28xx_init(struct rt_rtmp_adapter *pAd,
3870 char *pDefaultMac, char *pHostName);
3871
3872int RtmpNetTaskInit(struct rt_rtmp_adapter *pAd);
3873
3874void RtmpNetTaskExit(struct rt_rtmp_adapter *pAd);
3875
3876int RtmpMgmtTaskInit(struct rt_rtmp_adapter *pAd);
3877
3878void RtmpMgmtTaskExit(struct rt_rtmp_adapter *pAd);
3879
3880void tbtt_tasklet(unsigned long data);
3881
3882struct net_device *RtmpPhyNetDevInit(struct rt_rtmp_adapter *pAd,
3883 struct rt_rtmp_os_netdev_op_hook *pNetHook);
3884
3885BOOLEAN RtmpPhyNetDevExit(struct rt_rtmp_adapter *pAd, struct net_device *net_dev);
3886
3887int RtmpRaDevCtrlInit(struct rt_rtmp_adapter *pAd, IN RTMP_INF_TYPE infType);
3888
3889BOOLEAN RtmpRaDevCtrlExit(struct rt_rtmp_adapter *pAd);
3890
3891#ifdef RTMP_MAC_PCI
3892/* */
3893/* Function Prototype in cmm_data_pci.c */
3894/* */
3895u16 RtmpPCI_WriteTxResource(struct rt_rtmp_adapter *pAd,
3896 struct rt_tx_blk *pTxBlk,
3897 IN BOOLEAN bIsLast, u16 *FreeNumber);
3898
3899u16 RtmpPCI_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
3900 struct rt_tx_blk *pTxBlk,
3901 IN BOOLEAN bIsLast,
3902 u16 *FreeNumber);
3903
3904u16 RtmpPCI_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
3905 struct rt_tx_blk *pTxBlk,
3906 u8 frameNum, u16 *FreeNumber);
3907
3908u16 RtmpPCI_WriteFragTxResource(struct rt_rtmp_adapter *pAd,
3909 struct rt_tx_blk *pTxBlk,
3910 u8 fragNum, u16 *FreeNumber);
3911
3912u16 RtmpPCI_WriteSubTxResource(struct rt_rtmp_adapter *pAd,
3913 struct rt_tx_blk *pTxBlk,
3914 IN BOOLEAN bIsLast, u16 *FreeNumber);
3915
3916void RtmpPCI_FinalWriteTxResource(struct rt_rtmp_adapter *pAd,
3917 struct rt_tx_blk *pTxBlk,
3918 u16 totalMPDUSize,
3919 u16 FirstTxIdx);
3920
3921void RtmpPCIDataLastTxIdx(struct rt_rtmp_adapter *pAd,
3922 u8 QueIdx, u16 LastTxIdx);
3923
3924void RtmpPCIDataKickOut(struct rt_rtmp_adapter *pAd,
3925 struct rt_tx_blk *pTxBlk, u8 QueIdx);
3926
3927int RtmpPCIMgmtKickOut(struct rt_rtmp_adapter *pAd,
3928 u8 QueIdx,
3929 void *pPacket,
3930 u8 *pSrcBufVA, u32 SrcBufLen);
3931
3932int RTMPCheckRxError(struct rt_rtmp_adapter *pAd,
3933 struct rt_header_802_11 *pHeader,
3934 struct rt_rxwi *pRxWI, IN PRT28XX_RXD_STRUC pRxD);
3935
3936BOOLEAN RT28xxPciAsicRadioOff(struct rt_rtmp_adapter *pAd,
3937 u8 Level, u16 TbttNumToNextWakeUp);
3938
3939BOOLEAN RT28xxPciAsicRadioOn(struct rt_rtmp_adapter *pAd, u8 Level);
3940
3941void RTMPInitPCIeLinkCtrlValue(struct rt_rtmp_adapter *pAd);
3942
3943void RTMPFindHostPCIDev(struct rt_rtmp_adapter *pAd);
3944
3945void RTMPPCIeLinkCtrlValueRestore(struct rt_rtmp_adapter *pAd, u8 Level);
3946
3947void RTMPPCIeLinkCtrlSetting(struct rt_rtmp_adapter *pAd, u16 Max);
3948
3949void RTMPrt3xSetPCIePowerLinkCtrl(struct rt_rtmp_adapter *pAd);
3950
3951void PsPollWakeExec(void *SystemSpecific1,
3952 void *FunctionContext,
3953 void *SystemSpecific2, void *SystemSpecific3);
3954
3955void RadioOnExec(void *SystemSpecific1,
3956 void *FunctionContext,
3957 void *SystemSpecific2, void *SystemSpecific3);
3958
3959void RT28xxPciStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
3960
3961void RT28xxPciStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
3962 u16 TbttNumToNextWakeUp);
3963
3964void RT28xxPciMlmeRadioOn(struct rt_rtmp_adapter *pAd);
3965
3966void RT28xxPciMlmeRadioOFF(struct rt_rtmp_adapter *pAd);
3967#endif /* RTMP_MAC_PCI // */
3968
3969#ifdef RTMP_MAC_USB
3970/* */
3971/* Function Prototype in rtusb_bulk.c */
3972/* */
3973void RTUSBInitTxDesc(struct rt_rtmp_adapter *pAd,
3974 struct rt_tx_context *pTxContext,
3975 u8 BulkOutPipeId, IN usb_complete_t Func);
3976
3977void RTUSBInitHTTxDesc(struct rt_rtmp_adapter *pAd,
3978 struct rt_ht_tx_context *pTxContext,
3979 u8 BulkOutPipeId,
3980 unsigned long BulkOutSize, IN usb_complete_t Func);
3981
3982void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext);
3983
3984void RTUSBCleanUpDataBulkOutQueue(struct rt_rtmp_adapter *pAd);
3985
3986void RTUSBCancelPendingBulkOutIRP(struct rt_rtmp_adapter *pAd);
3987
3988void RTUSBBulkOutDataPacket(struct rt_rtmp_adapter *pAd,
3989 u8 BulkOutPipeId, u8 Index);
3990
3991void RTUSBBulkOutNullFrame(struct rt_rtmp_adapter *pAd);
3992
3993void RTUSBBulkOutRTSFrame(struct rt_rtmp_adapter *pAd);
3994
3995void RTUSBCancelPendingBulkInIRP(struct rt_rtmp_adapter *pAd);
3996
3997void RTUSBCancelPendingIRPs(struct rt_rtmp_adapter *pAd);
3998
3999void RTUSBBulkOutMLMEPacket(struct rt_rtmp_adapter *pAd, u8 Index);
4000
4001void RTUSBBulkOutPsPoll(struct rt_rtmp_adapter *pAd);
4002
4003void RTUSBCleanUpMLMEBulkOutQueue(struct rt_rtmp_adapter *pAd);
4004
4005void RTUSBKickBulkOut(struct rt_rtmp_adapter *pAd);
4006
4007void RTUSBBulkReceive(struct rt_rtmp_adapter *pAd);
4008
4009void DoBulkIn(struct rt_rtmp_adapter *pAd);
4010
4011void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext);
4012
4013void RTUSBBulkRxHandle(IN unsigned long data);
4014
4015/* */
4016/* Function Prototype in rtusb_io.c */
4017/* */
4018int RTUSBMultiRead(struct rt_rtmp_adapter *pAd,
4019 u16 Offset, u8 *pData, u16 length);
4020
4021int RTUSBMultiWrite(struct rt_rtmp_adapter *pAd,
4022 u16 Offset, const u8 *pData, u16 length);
4023
4024int RTUSBMultiWrite_OneByte(struct rt_rtmp_adapter *pAd,
4025 u16 Offset, const u8 *pData);
4026
4027int RTUSBReadBBPRegister(struct rt_rtmp_adapter *pAd,
4028 u8 Id, u8 *pValue);
4029
4030int RTUSBWriteBBPRegister(struct rt_rtmp_adapter *pAd,
4031 u8 Id, u8 Value);
4032
4033int RTUSBWriteRFRegister(struct rt_rtmp_adapter *pAd, u32 Value);
4034
4035int RTUSB_VendorRequest(struct rt_rtmp_adapter *pAd,
4036 u32 TransferFlags,
4037 u8 ReservedBits,
4038 u8 Request,
4039 u16 Value,
4040 u16 Index,
4041 void *TransferBuffer,
4042 u32 TransferBufferLength);
4043
4044int RTUSBReadEEPROM(struct rt_rtmp_adapter *pAd,
4045 u16 Offset, u8 *pData, u16 length);
4046
4047int RTUSBWriteEEPROM(struct rt_rtmp_adapter *pAd,
4048 u16 Offset, u8 *pData, u16 length);
4049
4050void RTUSBPutToSleep(struct rt_rtmp_adapter *pAd);
4051
4052int RTUSBWakeUp(struct rt_rtmp_adapter *pAd);
4053
4054void RTUSBInitializeCmdQ(struct rt_cmdq *cmdq);
4055
4056int RTUSBEnqueueCmdFromNdis(struct rt_rtmp_adapter *pAd,
4057 IN NDIS_OID Oid,
4058 IN BOOLEAN SetInformation,
4059 void *pInformationBuffer,
4060 u32 InformationBufferLength);
4061
4062int RTUSBEnqueueInternalCmd(struct rt_rtmp_adapter *pAd,
4063 IN NDIS_OID Oid,
4064 void *pInformationBuffer,
4065 u32 InformationBufferLength);
4066
4067void RTUSBDequeueCmd(struct rt_cmdq *cmdq, struct rt_cmdqelmt * * pcmdqelmt);
4068
4069int RTUSBCmdThread(IN void *Context);
4070
4071void RTUSBBssBeaconExit(struct rt_rtmp_adapter *pAd);
4072
4073void RTUSBBssBeaconStop(struct rt_rtmp_adapter *pAd);
4074
4075void RTUSBBssBeaconStart(struct rt_rtmp_adapter *pAd);
4076
4077void RTUSBBssBeaconInit(struct rt_rtmp_adapter *pAd);
4078
4079void RTUSBWatchDog(struct rt_rtmp_adapter *pAd);
4080
4081int RTUSBWriteMACRegister(struct rt_rtmp_adapter *pAd,
4082 u16 Offset, u32 Value);
4083
4084int RTUSBReadMACRegister(struct rt_rtmp_adapter *pAd,
4085 u16 Offset, u32 *pValue);
4086
4087int RTUSBSingleWrite(struct rt_rtmp_adapter *pAd,
4088 u16 Offset, u16 Value);
4089
4090int RTUSBFirmwareWrite(struct rt_rtmp_adapter *pAd,
4091 const u8 *pFwImage, unsigned long FwLen);
4092
4093int RTUSBVenderReset(struct rt_rtmp_adapter *pAd);
4094
4095int RTUSBSetHardWareRegister(struct rt_rtmp_adapter *pAdapter, void *pBuf);
4096
4097int RTUSBQueryHardWareRegister(struct rt_rtmp_adapter *pAdapter,
4098 void *pBuf);
4099
4100void CMDHandler(struct rt_rtmp_adapter *pAd);
4101
4102int RTUSBWriteHWMACAddress(struct rt_rtmp_adapter *pAdapter);
4103
4104void MacTableInitialize(struct rt_rtmp_adapter *pAd);
4105
4106void MlmeSetPsm(struct rt_rtmp_adapter *pAd, u16 psm);
4107
4108int RTMPWPAAddKeyProc(struct rt_rtmp_adapter *pAd, void *pBuf);
4109
4110void AsicRxAntEvalAction(struct rt_rtmp_adapter *pAd);
4111
4112void append_pkt(struct rt_rtmp_adapter *pAd,
4113 u8 *pHeader802_3,
4114 u32 HdrLen,
4115 u8 *pData,
4116 unsigned long DataSize, void **ppPacket);
4117
4118u32 deaggregate_AMSDU_announce(struct rt_rtmp_adapter *pAd,
4119 void *pPacket,
4120 u8 *pData, unsigned long DataSize);
4121
4122int RTMPCheckRxError(struct rt_rtmp_adapter *pAd,
4123 struct rt_header_802_11 *pHeader,
4124 struct rt_rxwi *pRxWI,
4125 IN PRT28XX_RXD_STRUC pRxINFO);
4126
4127void RTUSBMlmeHardTransmit(struct rt_rtmp_adapter *pAd, struct rt_mgmt *pMgmt);
4128
4129int MlmeThread(void *Context);
4130
4131/* */
4132/* Function Prototype in rtusb_data.c */
4133/* */
4134int RTUSBFreeDescriptorRequest(struct rt_rtmp_adapter *pAd,
4135 u8 BulkOutPipeId,
4136 u32 NumberRequired);
4137
4138BOOLEAN RTUSBNeedQueueBackForAgg(struct rt_rtmp_adapter *pAd, u8 BulkOutPipeId);
4139
4140void RTMPWriteTxInfo(struct rt_rtmp_adapter *pAd,
4141 struct rt_txinfo *pTxInfo,
4142 u16 USBDMApktLen,
4143 IN BOOLEAN bWiv,
4144 u8 QueueSel, u8 NextValid, u8 TxBurst);
4145
4146/* */
4147/* Function Prototype in cmm_data_usb.c */
4148/* */
4149u16 RtmpUSB_WriteSubTxResource(struct rt_rtmp_adapter *pAd,
4150 struct rt_tx_blk *pTxBlk,
4151 IN BOOLEAN bIsLast, u16 *FreeNumber);
4152
4153u16 RtmpUSB_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
4154 struct rt_tx_blk *pTxBlk,
4155 IN BOOLEAN bIsLast,
4156 u16 *FreeNumber);
4157
4158u16 RtmpUSB_WriteFragTxResource(struct rt_rtmp_adapter *pAd,
4159 struct rt_tx_blk *pTxBlk,
4160 u8 fragNum, u16 *FreeNumber);
4161
4162u16 RtmpUSB_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
4163 struct rt_tx_blk *pTxBlk,
4164 u8 frameNum, u16 *FreeNumber);
4165
4166void RtmpUSB_FinalWriteTxResource(struct rt_rtmp_adapter *pAd,
4167 struct rt_tx_blk *pTxBlk,
4168 u16 totalMPDUSize, u16 TxIdx);
4169
4170void RtmpUSBDataLastTxIdx(struct rt_rtmp_adapter *pAd,
4171 u8 QueIdx, u16 TxIdx);
4172
4173void RtmpUSBDataKickOut(struct rt_rtmp_adapter *pAd,
4174 struct rt_tx_blk *pTxBlk, u8 QueIdx);
4175
4176int RtmpUSBMgmtKickOut(struct rt_rtmp_adapter *pAd,
4177 u8 QueIdx,
4178 void *pPacket,
4179 u8 *pSrcBufVA, u32 SrcBufLen);
4180
4181void RtmpUSBNullFrameKickOut(struct rt_rtmp_adapter *pAd,
4182 u8 QueIdx,
4183 u8 *pNullFrame, u32 frameLen);
4184
4185void RtmpUsbStaAsicForceWakeupTimeout(void *SystemSpecific1,
4186 void *FunctionContext,
4187 void *SystemSpecific2,
4188 void *SystemSpecific3);
4189
4190void RT28xxUsbStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx);
4191
4192void RT28xxUsbStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd,
4193 u16 TbttNumToNextWakeUp);
4194
4195void RT28xxUsbMlmeRadioOn(struct rt_rtmp_adapter *pAd);
4196
4197void RT28xxUsbMlmeRadioOFF(struct rt_rtmp_adapter *pAd);
4198#endif /* RTMP_MAC_USB // */
4199
4200void AsicTurnOffRFClk(struct rt_rtmp_adapter *pAd, u8 Channel);
4201
4202void AsicTurnOnRFClk(struct rt_rtmp_adapter *pAd, u8 Channel);
4203
4204#ifdef RTMP_TIMER_TASK_SUPPORT
4205int RtmpTimerQThread(IN void *Context);
4206
4207struct rt_rtmp_timer_task_entry *RtmpTimerQInsert(struct rt_rtmp_adapter *pAd,
4208 struct rt_ralink_timer *pTimer);
4209
4210BOOLEAN RtmpTimerQRemove(struct rt_rtmp_adapter *pAd,
4211 struct rt_ralink_timer *pTimer);
4212
4213void RtmpTimerQExit(struct rt_rtmp_adapter *pAd);
4214
4215void RtmpTimerQInit(struct rt_rtmp_adapter *pAd);
4216#endif /* RTMP_TIMER_TASK_SUPPORT // */
4217
4218void AsicStaBbpTuning(struct rt_rtmp_adapter *pAd);
4219
4220BOOLEAN StaAddMacTableEntry(struct rt_rtmp_adapter *pAd,
4221 struct rt_mac_table_entry *pEntry,
4222 u8 MaxSupportedRateIn500Kbps,
4223 struct rt_ht_capability_ie *pHtCapability,
4224 u8 HtCapabilityLen,
4225 struct rt_add_ht_info_ie *pAddHtInfo,
4226 u8 AddHtInfoLen, u16 CapabilityInfo);
4227
4228BOOLEAN AUTH_ReqSend(struct rt_rtmp_adapter *pAd,
4229 struct rt_mlme_queue_elem *pElem,
4230 struct rt_ralink_timer *pAuthTimer,
4231 char *pSMName,
4232 u16 SeqNo,
4233 u8 *pNewElement, unsigned long ElementLen);
4234
4235void RTMP_IndicateMediaState(struct rt_rtmp_adapter *pAd);
4236
4237void ReSyncBeaconTime(struct rt_rtmp_adapter *pAd);
4238
4239void RTMPSetAGCInitValue(struct rt_rtmp_adapter *pAd, u8 BandWidth);
4240
4241int rt28xx_close(struct net_device *dev);
4242int rt28xx_open(struct net_device *dev);
4243
4244#define VIRTUAL_IF_INC(__pAd) ((__pAd)->VirtualIfCnt++)
4245#define VIRTUAL_IF_DEC(__pAd) ((__pAd)->VirtualIfCnt--)
4246#define VIRTUAL_IF_NUM(__pAd) ((__pAd)->VirtualIfCnt)
4247
4248#ifdef LINUX
4249__inline int VIRTUAL_IF_UP(struct rt_rtmp_adapter *pAd)
4250{
4251 if (VIRTUAL_IF_NUM(pAd) == 0) {
4252 if (rt28xx_open(pAd->net_dev) != 0) {
4253 DBGPRINT(RT_DEBUG_TRACE,
4254 ("rt28xx_open return fail!\n"));
4255 return -1;
4256 }
4257 } else {
4258 }
4259 VIRTUAL_IF_INC(pAd);
4260 return 0;
4261}
4262
4263__inline void VIRTUAL_IF_DOWN(struct rt_rtmp_adapter *pAd)
4264{
4265 VIRTUAL_IF_DEC(pAd);
4266 if (VIRTUAL_IF_NUM(pAd) == 0)
4267 rt28xx_close(pAd->net_dev);
4268 return;
4269}
4270#endif /* LINUX // */
4271
4272/*
4273 OS Related funciton prototype definitions.
4274 TODO: Maybe we need to move these function prototypes to other proper place.
4275*/
4276int RtmpOSWrielessEventSend(struct rt_rtmp_adapter *pAd,
4277 u32 eventType,
4278 int flags,
4279 u8 *pSrcMac,
4280 u8 *pData, u32 dataLen);
4281
4282int RtmpOSNetDevAddrSet(struct net_device *pNetDev, u8 *pMacAddr);
4283
4284int RtmpOSNetDevAttach(struct net_device *pNetDev,
4285 struct rt_rtmp_os_netdev_op_hook *pDevOpHook);
4286
4287void RtmpOSNetDevClose(struct net_device *pNetDev);
4288
4289void RtmpOSNetDevDetach(struct net_device *pNetDev);
4290
4291int RtmpOSNetDevAlloc(struct net_device **pNewNetDev, u32 privDataSize);
4292
4293void RtmpOSNetDevFree(struct net_device *pNetDev);
4294
4295struct net_device *RtmpOSNetDevGetByName(struct net_device *pNetDev, char *pDevName);
4296
4297void RtmpOSNetDeviceRefPut(struct net_device *pNetDev);
4298
4299struct net_device *RtmpOSNetDevCreate(struct rt_rtmp_adapter *pAd,
4300 int devType,
4301 int devNum,
4302 int privMemSize, char *pNamePrefix);
4303
4304/*
4305 Task operation related function prototypes
4306*/
4307void RtmpOSTaskCustomize(struct rt_rtmp_os_task *pTask);
4308
4309int RtmpOSTaskNotifyToExit(struct rt_rtmp_os_task *pTask);
4310
4311int RtmpOSTaskKill(struct rt_rtmp_os_task *pTask);
4312
4313int RtmpOSTaskInit(struct rt_rtmp_os_task *pTask,
4314 char *pTaskName, void * pPriv);
4315
4316int RtmpOSTaskAttach(struct rt_rtmp_os_task *pTask,
4317 IN int (*fn) (void *), IN void *arg);
4318
4319/*
4320 File operation related function prototypes
4321*/
4322struct file *RtmpOSFileOpen(IN char *pPath, IN int flag, IN int mode);
4323
4324int RtmpOSFileClose(struct file *osfd);
4325
4326void RtmpOSFileSeek(struct file *osfd, IN int offset);
4327
4328int RtmpOSFileRead(struct file *osfd, IN char *pDataPtr, IN int readLen);
4329
4330int RtmpOSFileWrite(struct file *osfd, IN char *pDataPtr, IN int writeLen);
4331
4332#endif /* __RTMP_H__ */
diff --git a/drivers/staging/rt2860/rtmp_chip.h b/drivers/staging/rt2860/rtmp_chip.h
deleted file mode 100644
index 0adf2cd2deb..00000000000
--- a/drivers/staging/rt2860/rtmp_chip.h
+++ /dev/null
@@ -1,258 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_chip.h
29
30 Abstract:
31 Ralink Wireless Chip related definition & structures
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#ifndef __RTMP_CHIP_H__
39#define __RTMP_CHIP_H__
40
41#include "rtmp_type.h"
42
43#ifdef RT2860
44#include "chip/rt2860.h"
45#endif /* RT2860 // */
46#ifdef RT2870
47#include "chip/rt2870.h"
48#endif /* RT2870 // */
49#ifdef RT3070
50#include "chip/rt3070.h"
51#endif /* RT3070 // */
52#ifdef RT3090
53#include "chip/rt3090.h"
54#endif /* RT3090 // */
55
56/* We will have a cost down version which mac version is 0x3090xxxx */
57/* */
58/* RT3090A facts */
59/* */
60/* a) 2.4 GHz */
61/* b) Replacement for RT3090 */
62/* c) Internal LNA */
63/* d) Interference over channel #14 */
64/* e) New BBP features (e.g., SIG re-modulation) */
65/* */
66#define IS_RT3090A(_pAd) ((((_pAd)->MACVersion & 0xffff0000) == 0x30900000))
67
68/* We will have a cost down version which mac version is 0x3090xxxx */
69#define IS_RT3090(_pAd) ((((_pAd)->MACVersion & 0xffff0000) == 0x30710000) || (IS_RT3090A(_pAd)))
70
71#define IS_RT3070(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x30700000)
72#define IS_RT3071(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x30710000)
73#define IS_RT2070(_pAd) (((_pAd)->RfIcType == RFIC_2020) || ((_pAd)->EFuseTag == 0x27))
74
75#define IS_RT30xx(_pAd) (((_pAd)->MACVersion & 0xfff00000) == 0x30700000||IS_RT3090A(_pAd))
76/*#define IS_RT305X(_pAd) ((_pAd)->MACVersion == 0x28720200) */
77
78/* RT3572, 3592, 3562, 3062 share the same MAC version */
79#define IS_RT3572(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x35720000)
80#define IS_VERSION_BEFORE_F(_pAd) (((_pAd)->MACVersion&0xffff) <= 0x0211)
81/* F version is 0x0212, E version is 0x0211. 309x can save more power after F version. */
82#define IS_VERSION_AFTER_F(_pAd) ((((_pAd)->MACVersion&0xffff) >= 0x0212) || (((_pAd)->b3090ESpecialChip == TRUE)))
83/* */
84/* RT3390 facts */
85/* */
86/* a) Base on RT3090 (RF IC: RT3020) */
87/* b) 2.4 GHz */
88/* c) 1x1 */
89/* d) Single chip */
90/* e) Internal components: PA and LNA */
91/* */
92/*RT3390,RT3370 */
93#define IS_RT3390(_pAd) (((_pAd)->MACVersion & 0xFFFF0000) == 0x33900000)
94
95/* ------------------------------------------------------ */
96/* PCI registers - base address 0x0000 */
97/* ------------------------------------------------------ */
98#define CHIP_PCI_CFG 0x0000
99#define CHIP_PCI_EECTRL 0x0004
100#define CHIP_PCI_MCUCTRL 0x0008
101
102#define OPT_14 0x114
103
104#define RETRY_LIMIT 10
105
106/* ------------------------------------------------------ */
107/* BBP & RF definition */
108/* ------------------------------------------------------ */
109#define BUSY 1
110#define IDLE 0
111
112/*------------------------------------------------------------------------- */
113/* EEPROM definition */
114/*------------------------------------------------------------------------- */
115#define EEDO 0x08
116#define EEDI 0x04
117#define EECS 0x02
118#define EESK 0x01
119#define EERL 0x80
120
121#define EEPROM_WRITE_OPCODE 0x05
122#define EEPROM_READ_OPCODE 0x06
123#define EEPROM_EWDS_OPCODE 0x10
124#define EEPROM_EWEN_OPCODE 0x13
125
126#define NUM_EEPROM_BBP_PARMS 19 /* Include NIC Config 0, 1, CR, TX ALC step, BBPs */
127#define NUM_EEPROM_TX_G_PARMS 7
128#define EEPROM_NIC1_OFFSET 0x34 /* The address is from NIC config 0, not BBP register ID */
129#define EEPROM_NIC2_OFFSET 0x36 /* The address is from NIC config 0, not BBP register ID */
130#define EEPROM_BBP_BASE_OFFSET 0xf0 /* The address is from NIC config 0, not BBP register ID */
131#define EEPROM_G_TX_PWR_OFFSET 0x52
132#define EEPROM_G_TX2_PWR_OFFSET 0x60
133#define EEPROM_LED1_OFFSET 0x3c
134#define EEPROM_LED2_OFFSET 0x3e
135#define EEPROM_LED3_OFFSET 0x40
136#define EEPROM_LNA_OFFSET 0x44
137#define EEPROM_RSSI_BG_OFFSET 0x46
138#define EEPROM_TXMIXER_GAIN_2_4G 0x48
139#define EEPROM_RSSI_A_OFFSET 0x4a
140#define EEPROM_TXMIXER_GAIN_5G 0x4c
141#define EEPROM_DEFINE_MAX_TXPWR 0x4e
142#define EEPROM_TXPOWER_BYRATE_20MHZ_2_4G 0xde /* 20MHZ 2.4G tx power. */
143#define EEPROM_TXPOWER_BYRATE_40MHZ_2_4G 0xee /* 40MHZ 2.4G tx power. */
144#define EEPROM_TXPOWER_BYRATE_20MHZ_5G 0xfa /* 20MHZ 5G tx power. */
145#define EEPROM_TXPOWER_BYRATE_40MHZ_5G 0x10a /* 40MHZ 5G tx power. */
146#define EEPROM_A_TX_PWR_OFFSET 0x78
147#define EEPROM_A_TX2_PWR_OFFSET 0xa6
148/*#define EEPROM_Japan_TX_PWR_OFFSET 0x90 // 802.11j */
149/*#define EEPROM_Japan_TX2_PWR_OFFSET 0xbe */
150/*#define EEPROM_TSSI_REF_OFFSET 0x54 */
151/*#define EEPROM_TSSI_DELTA_OFFSET 0x24 */
152/*#define EEPROM_CCK_TX_PWR_OFFSET 0x62 */
153/*#define EEPROM_CALIBRATE_OFFSET 0x7c */
154#define EEPROM_VERSION_OFFSET 0x02
155#define EEPROM_FREQ_OFFSET 0x3a
156#define EEPROM_TXPOWER_BYRATE 0xde /* 20MHZ power. */
157#define EEPROM_TXPOWER_DELTA 0x50 /* 20MHZ AND 40 MHZ use different power. This is delta in 40MHZ. */
158#define VALID_EEPROM_VERSION 1
159
160/*
161 * EEPROM operation related marcos
162 */
163#define RT28xx_EEPROM_READ16(_pAd, _offset, _value) \
164 (_pAd)->chipOps.eeread((struct rt_rtmp_adapter *)(_pAd), (u16)(_offset), (u16 *)&(_value))
165
166/* ------------------------------------------------------------------- */
167/* E2PROM data layout */
168/* ------------------------------------------------------------------- */
169
170/* */
171/* MCU_LEDCS: MCU LED Control Setting. */
172/* */
173typedef union _MCU_LEDCS_STRUC {
174 struct {
175 u8 LedMode:7;
176 u8 Polarity:1;
177 } field;
178 u8 word;
179} MCU_LEDCS_STRUC, *PMCU_LEDCS_STRUC;
180
181/* */
182/* EEPROM antenna select format */
183/* */
184typedef union _EEPROM_ANTENNA_STRUC {
185 struct {
186 u16 RxPath:4; /* 1: 1R, 2: 2R, 3: 3R */
187 u16 TxPath:4; /* 1: 1T, 2: 2T */
188 u16 RfIcType:4; /* see E2PROM document */
189 u16 Rsv:4;
190 } field;
191 u16 word;
192} EEPROM_ANTENNA_STRUC, *PEEPROM_ANTENNA_STRUC;
193
194typedef union _EEPROM_NIC_CINFIG2_STRUC {
195 struct {
196 u16 HardwareRadioControl:1; /* 1:enable, 0:disable */
197 u16 DynamicTxAgcControl:1; /* */
198 u16 ExternalLNAForG:1; /* */
199 u16 ExternalLNAForA:1; /* external LNA enable for 2.4G */
200 u16 CardbusAcceleration:1; /* ! NOTE: 0 - enable, 1 - disable */
201 u16 BW40MSidebandForG:1;
202 u16 BW40MSidebandForA:1;
203 u16 EnableWPSPBC:1; /* WPS PBC Control bit */
204 u16 BW40MAvailForG:1; /* 0:enable, 1:disable */
205 u16 BW40MAvailForA:1; /* 0:enable, 1:disable */
206 u16 Rsv1:1; /* must be 0 */
207 u16 AntDiversity:1; /* Antenna diversity */
208 u16 Rsv2:3; /* must be 0 */
209 u16 DACTestBit:1; /* control if driver should patch the DAC issue */
210 } field;
211 u16 word;
212} EEPROM_NIC_CONFIG2_STRUC, *PEEPROM_NIC_CONFIG2_STRUC;
213
214/* */
215/* TX_PWR Value valid range 0xFA(-6) ~ 0x24(36) */
216/* */
217typedef union _EEPROM_TX_PWR_STRUC {
218 struct {
219 char Byte0; /* Low Byte */
220 char Byte1; /* High Byte */
221 } field;
222 u16 word;
223} EEPROM_TX_PWR_STRUC, *PEEPROM_TX_PWR_STRUC;
224
225typedef union _EEPROM_VERSION_STRUC {
226 struct {
227 u8 FaeReleaseNumber; /* Low Byte */
228 u8 Version; /* High Byte */
229 } field;
230 u16 word;
231} EEPROM_VERSION_STRUC, *PEEPROM_VERSION_STRUC;
232
233typedef union _EEPROM_LED_STRUC {
234 struct {
235 u16 PolarityRDY_G:1; /* Polarity RDY_G setting. */
236 u16 PolarityRDY_A:1; /* Polarity RDY_A setting. */
237 u16 PolarityACT:1; /* Polarity ACT setting. */
238 u16 PolarityGPIO_0:1; /* Polarity GPIO#0 setting. */
239 u16 PolarityGPIO_1:1; /* Polarity GPIO#1 setting. */
240 u16 PolarityGPIO_2:1; /* Polarity GPIO#2 setting. */
241 u16 PolarityGPIO_3:1; /* Polarity GPIO#3 setting. */
242 u16 PolarityGPIO_4:1; /* Polarity GPIO#4 setting. */
243 u16 LedMode:5; /* Led mode. */
244 u16 Rsvd:3; /* Reserved */
245 } field;
246 u16 word;
247} EEPROM_LED_STRUC, *PEEPROM_LED_STRUC;
248
249typedef union _EEPROM_TXPOWER_DELTA_STRUC {
250 struct {
251 u8 DeltaValue:6; /* Tx Power dalta value (MAX=4) */
252 u8 Type:1; /* 1: plus the delta value, 0: minus the delta value */
253 u8 TxPowerEnable:1; /* Enable */
254 } field;
255 u8 value;
256} EEPROM_TXPOWER_DELTA_STRUC, *PEEPROM_TXPOWER_DELTA_STRUC;
257
258#endif /* __RTMP_CHIP_H__ // */
diff --git a/drivers/staging/rt2860/rtmp_ckipmic.h b/drivers/staging/rt2860/rtmp_ckipmic.h
deleted file mode 100644
index 6ff935dd3dd..00000000000
--- a/drivers/staging/rt2860/rtmp_ckipmic.h
+++ /dev/null
@@ -1,63 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_ckipmic.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36*/
37#ifndef __RTMP_CKIPMIC_H__
38#define __RTMP_CKIPMIC_H__
39
40struct rt_mic_context {
41 /* --- MMH context */
42 u8 CK[16]; /* the key */
43 u8 coefficient[16]; /* current aes counter mode coefficients */
44 unsigned long long accum; /* accumulated mic, reduced to u32 in final() */
45 u32 position; /* current position (byte offset) in message */
46 u8 part[4]; /* for conversion of message to u32 for mmh */
47};
48
49void xor_128(u8 *a, u8 *b, u8 *out);
50
51u8 RTMPCkipSbox(u8 a);
52
53void xor_32(u8 *a, u8 *b, u8 *out);
54
55void next_key(u8 *key, int round);
56
57void byte_sub(u8 *in, u8 *out);
58
59void shift_row(u8 *in, u8 *out);
60
61void mix_column(u8 *in, u8 *out);
62
63#endif /*__RTMP_CKIPMIC_H__ */
diff --git a/drivers/staging/rt2860/rtmp_def.h b/drivers/staging/rt2860/rtmp_def.h
deleted file mode 100644
index 6ac617e7c9b..00000000000
--- a/drivers/staging/rt2860/rtmp_def.h
+++ /dev/null
@@ -1,1427 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_def.h
29
30 Abstract:
31 Miniport related definition header
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Paul Lin 08-01-2002 created
37 John Chang 08-05-2003 add definition for 11g & other drafts
38 Justin P. Mattock 11/07/2010 Fix some typos
39*/
40#ifndef __RTMP_DEF_H__
41#define __RTMP_DEF_H__
42
43#include "oid.h"
44
45/* */
46/* Debug information verbosity: lower values indicate higher urgency */
47/* */
48#define RT_DEBUG_OFF 0
49#define RT_DEBUG_ERROR 1
50#define RT_DEBUG_WARN 2
51#define RT_DEBUG_TRACE 3
52#define RT_DEBUG_INFO 4
53#define RT_DEBUG_LOUD 5
54
55#define NIC_TAG ((unsigned long)'0682')
56#define NIC_DBG_char ("**RT28xx**")
57
58#ifdef RTMP_MAC_USB
59#define TX_RING_SIZE 8 /* 1 */
60#define PRIO_RING_SIZE 8
61#define MGMT_RING_SIZE 32 /* PRIO_RING_SIZE */
62#define RX_RING_SIZE 8
63#define MAX_TX_PROCESS 4
64#define LOCAL_TXBUF_SIZE 2048
65#endif /* RTMP_MAC_USB // */
66
67/*#define PACKED */
68
69#define RALINK_2883_VERSION ((u32)0x28830300)
70#define RALINK_2880E_VERSION ((u32)0x28720200)
71#define RALINK_3070_VERSION ((u32)0x30700200)
72
73#define MAX_RX_PKT_LEN 1520
74
75/* */
76/* Entry number for each DMA descriptor ring */
77/* */
78
79#ifdef RTMP_MAC_PCI
80#define TX_RING_SIZE 64 /*64 */
81#define MGMT_RING_SIZE 128
82#define RX_RING_SIZE 128 /*64 */
83#define MAX_TX_PROCESS TX_RING_SIZE /*8 */
84#define MAX_DMA_DONE_PROCESS TX_RING_SIZE
85#define MAX_TX_DONE_PROCESS TX_RING_SIZE /*8 */
86#define LOCAL_TXBUF_SIZE 2
87#endif /* RTMP_MAC_PCI // */
88
89#define MAX_RX_PROCESS 128 /*64 //32 */
90#define NUM_OF_LOCAL_TXBUF 2
91#define TXD_SIZE 16
92#define TXWI_SIZE 16
93#define RXD_SIZE 16
94#define RXWI_SIZE 16
95/* TXINFO_SIZE + TXWI_SIZE + 802.11 Header Size + AMSDU sub frame header */
96#define TX_DMA_1ST_BUFFER_SIZE 96 /* only the 1st physical buffer is pre-allocated */
97#define MGMT_DMA_BUFFER_SIZE 1536 /*2048 */
98#define RX_BUFFER_AGGRESIZE 3840 /*3904 //3968 //4096 //2048 //4096 */
99#define RX_BUFFER_NORMSIZE 3840 /*3904 //3968 //4096 //2048 //4096 */
100#define TX_BUFFER_NORMSIZE RX_BUFFER_NORMSIZE
101#define MAX_FRAME_SIZE 2346 /* Maximum 802.11 frame size */
102#define MAX_AGGREGATION_SIZE 3840 /*3904 //3968 //4096 */
103#define MAX_NUM_OF_TUPLE_CACHE 2
104#define MAX_MCAST_LIST_SIZE 32
105#define MAX_LEN_OF_VENDOR_DESC 64
106/*#define MAX_SIZE_OF_MCAST_PSQ (NUM_OF_LOCAL_TXBUF >> 2) // AP won't spend more than 1/4 of total buffers on M/BCAST PSQ */
107#define MAX_SIZE_OF_MCAST_PSQ 32
108
109#define MAX_RX_PROCESS_CNT (RX_RING_SIZE)
110
111/*
112 WMM Note: If memory of your system is not much, please reduce the definition;
113 or when you do WMM test, the queue for low priority AC will be full, i.e.
114 TX_RING_SIZE + MAX_PACKETS_IN_QUEUE packets for the AC will be buffered in
115 WLAN, maybe no packet buffers can get into the Ethernet driver.
116
117 Sometimes no packet buffer can be get into the Ethernet driver, the system will
118 send flow control packet to the sender to slow down its sending rate.
119 So no WMM can be seen in the air.
120*/
121
122/*
123 Need to use 64 in vxworks for test case WMM A5-T07
124 Two dnlink (10Mbps) from a WMM station to a non-WMM station.
125 If use 256, queue is not enough.
126 And in rt_main_end.c, clConfig.clNum = RX_RING_SIZE * 3; is changed to
127 clConfig.clNum = RX_RING_SIZE * 4;
128*/
129/* TODO: For VxWorks the size is 256. Shall we change the value as 256 for all OS? */
130#define MAX_PACKETS_IN_QUEUE (512) /*(512) // to pass WMM A5-WPAPSK */
131
132#define MAX_PACKETS_IN_MCAST_PS_QUEUE 32
133#define MAX_PACKETS_IN_PS_QUEUE 128 /*32 */
134#define WMM_NUM_OF_AC 4 /* AC0, AC1, AC2, and AC3 */
135
136#ifdef RTMP_EFUSE_SUPPORT
137/*2008/09/11:KH add to support efuse<-- */
138#define MAX_EEPROM_BIN_FILE_SIZE 1024
139#define EFUSE_BUFFER_PATH "/tmp/RT30xxEEPROM.bin"
140/*2008/09/11:KH add to support efuse--> */
141#endif /* RTMP_EFUSE_SUPPORT // */
142
143/* RxFilter */
144#define STANORMAL 0x17f97
145#define APNORMAL 0x15f97
146#define PSPXLINK 0x17f93
147/* */
148/* struct rt_rtmp_adapter flags */
149/* */
150#define fRTMP_ADAPTER_MAP_REGISTER 0x00000001
151#define fRTMP_ADAPTER_INTERRUPT_IN_USE 0x00000002
152#define fRTMP_ADAPTER_HARDWARE_ERROR 0x00000004
153#define fRTMP_ADAPTER_SCATTER_GATHER 0x00000008
154#define fRTMP_ADAPTER_SEND_PACKET_ERROR 0x00000010
155#define fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS 0x00000020
156#define fRTMP_ADAPTER_HALT_IN_PROGRESS 0x00000040
157#define fRTMP_ADAPTER_RESET_IN_PROGRESS 0x00000080
158#define fRTMP_ADAPTER_NIC_NOT_EXIST 0x00000100
159#define fRTMP_ADAPTER_TX_RING_ALLOCATED 0x00000200
160#define fRTMP_ADAPTER_REMOVE_IN_PROGRESS 0x00000400
161#define fRTMP_ADAPTER_MIMORATE_INUSED 0x00000800
162#define fRTMP_ADAPTER_RX_RING_ALLOCATED 0x00001000
163#define fRTMP_ADAPTER_INTERRUPT_ACTIVE 0x00002000
164#define fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS 0x00004000
165#define fRTMP_ADAPTER_REASSOC_IN_PROGRESS 0x00008000
166#define fRTMP_ADAPTER_MEDIA_STATE_PENDING 0x00010000
167#define fRTMP_ADAPTER_RADIO_OFF 0x00020000
168#define fRTMP_ADAPTER_BULKOUT_RESET 0x00040000
169#define fRTMP_ADAPTER_BULKIN_RESET 0x00080000
170#define fRTMP_ADAPTER_RDG_ACTIVE 0x00100000
171#define fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE 0x00200000
172#define fRTMP_ADAPTER_SCAN_2040 0x04000000
173#define fRTMP_ADAPTER_RADIO_MEASUREMENT 0x08000000
174
175#define fRTMP_ADAPTER_START_UP 0x10000000 /*Device already initialized and enabled Tx/Rx. */
176#define fRTMP_ADAPTER_MEDIA_STATE_CHANGE 0x20000000
177#define fRTMP_ADAPTER_IDLE_RADIO_OFF 0x40000000
178
179/* */
180/* STA operation status flags */
181/* */
182#define fOP_STATUS_INFRA_ON 0x00000001
183#define fOP_STATUS_ADHOC_ON 0x00000002
184#define fOP_STATUS_BG_PROTECTION_INUSED 0x00000004
185#define fOP_STATUS_SHORT_SLOT_INUSED 0x00000008
186#define fOP_STATUS_SHORT_PREAMBLE_INUSED 0x00000010
187#define fOP_STATUS_RECEIVE_DTIM 0x00000020
188#define fOP_STATUS_MEDIA_STATE_CONNECTED 0x00000080
189#define fOP_STATUS_WMM_INUSED 0x00000100
190#define fOP_STATUS_AGGREGATION_INUSED 0x00000200
191#define fOP_STATUS_DOZE 0x00000400 /* debug purpose */
192#define fOP_STATUS_PIGGYBACK_INUSED 0x00000800 /* piggy-back, and aggregation */
193#define fOP_STATUS_APSD_INUSED 0x00001000
194#define fOP_STATUS_TX_AMSDU_INUSED 0x00002000
195#define fOP_STATUS_MAX_RETRY_ENABLED 0x00004000
196#define fOP_STATUS_WAKEUP_NOW 0x00008000
197#define fOP_STATUS_PCIE_DEVICE 0x00020000
198#define fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE fOP_STATUS_PCIE_DEVICE
199
200/* */
201/* struct rt_rtmp_adapter PSFlags : related to advanced power save. */
202/* */
203/* Indicate whether driver can go to sleep mode from now. This flag is useful AFTER link up */
204#define fRTMP_PS_CAN_GO_SLEEP 0x00000001
205/* Indicate whether driver has issue a LinkControl command to PCIe L1 */
206#define fRTMP_PS_SET_PCI_CLK_OFF_COMMAND 0x00000002
207/* Indicate driver should disable kick off hardware to send packets from now. */
208#define fRTMP_PS_DISABLE_TX 0x00000004
209/* Indicate driver should IMMEDIATELY go to sleep after receiving AP's beacon in which doesn't indicate unicate nor multicast packets for me */
210/* This flag is used ONLY in RTMPHandleRxDoneInterrupt routine. */
211#define fRTMP_PS_GO_TO_SLEEP_NOW 0x00000008
212#define fRTMP_PS_TOGGLE_L1 0x00000010 /* Use Toggle L1 mechanism for rt28xx PCIe */
213
214#ifdef RT3090
215#define WAKE_MCU_CMD 0x31
216#define SLEEP_MCU_CMD 0x30
217#define RFOFF_MCU_CMD 0x35
218#endif /* RT3090 // */
219
220#define CCKSETPROTECT 0x1
221#define OFDMSETPROTECT 0x2
222#define MM20SETPROTECT 0x4
223#define MM40SETPROTECT 0x8
224#define GF20SETPROTECT 0x10
225#define GR40SETPROTECT 0x20
226#define ALLN_SETPROTECT (GR40SETPROTECT | GF20SETPROTECT | MM40SETPROTECT | MM20SETPROTECT)
227
228/* */
229/* AP's client table operation status flags */
230/* */
231#define fCLIENT_STATUS_WMM_CAPABLE 0x00000001 /* CLIENT can parse QOS DATA frame */
232#define fCLIENT_STATUS_AGGREGATION_CAPABLE 0x00000002 /* CLIENT can receive Ralink's proprietary TX aggregation frame */
233#define fCLIENT_STATUS_PIGGYBACK_CAPABLE 0x00000004 /* CLIENT support piggy-back */
234#define fCLIENT_STATUS_AMSDU_INUSED 0x00000008
235#define fCLIENT_STATUS_SGI20_CAPABLE 0x00000010
236#define fCLIENT_STATUS_SGI40_CAPABLE 0x00000020
237#define fCLIENT_STATUS_TxSTBC_CAPABLE 0x00000040
238#define fCLIENT_STATUS_RxSTBC_CAPABLE 0x00000080
239#define fCLIENT_STATUS_HTC_CAPABLE 0x00000100
240#define fCLIENT_STATUS_RDG_CAPABLE 0x00000200
241#define fCLIENT_STATUS_MCSFEEDBACK_CAPABLE 0x00000400
242#define fCLIENT_STATUS_APSD_CAPABLE 0x00000800 /* UAPSD STATION */
243
244#define fCLIENT_STATUS_RALINK_CHIPSET 0x00100000
245/* */
246/* STA configuration flags */
247/* */
248
249/* 802.11n Operating Mode Definition. 0-3 also used in ASICUPdateProtect switch case */
250#define HT_NO_PROTECT 0
251#define HT_LEGACY_PROTECT 1
252#define HT_40_PROTECT 2
253#define HT_2040_PROTECT 3
254#define HT_RTSCTS_6M 7
255/*following is our own definition in order to turn on our ASIC protection register in INFRASTRUCTURE. */
256#define HT_ATHEROS 8 /* rt2860c has problem with atheros chip. we need to turn on RTS/CTS . */
257#define HT_FORCERTSCTS 9 /* Force turn on RTS/CTS first. then go to evaluate if this force RTS is necessary. */
258
259/* */
260/* RX Packet Filter control flags. Apply on pAd->PacketFilter */
261/* */
262#define fRX_FILTER_ACCEPT_DIRECT NDIS_PACKET_TYPE_DIRECTED
263#define fRX_FILTER_ACCEPT_MULTICAST NDIS_PACKET_TYPE_MULTICAST
264#define fRX_FILTER_ACCEPT_BROADCAST NDIS_PACKET_TYPE_BROADCAST
265#define fRX_FILTER_ACCEPT_ALL_MULTICAST NDIS_PACKET_TYPE_ALL_MULTICAST
266#define fRX_FILTER_ACCEPT_PROMISCUOUS NDIS_PACKET_TYPE_PROMISCUOUS
267
268/* */
269/* Error code section */
270/* */
271/* NDIS_ERROR_CODE_ADAPTER_NOT_FOUND */
272#define ERRLOG_READ_PCI_SLOT_FAILED 0x00000101L
273#define ERRLOG_WRITE_PCI_SLOT_FAILED 0x00000102L
274#define ERRLOG_VENDOR_DEVICE_NOMATCH 0x00000103L
275
276/* NDIS_ERROR_CODE_ADAPTER_DISABLED */
277#define ERRLOG_BUS_MASTER_DISABLED 0x00000201L
278
279/* NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION */
280#define ERRLOG_INVALID_SPEED_DUPLEX 0x00000301L
281#define ERRLOG_SET_SECONDARY_FAILED 0x00000302L
282
283/* NDIS_ERROR_CODE_OUT_OF_RESOURCES */
284#define ERRLOG_OUT_OF_MEMORY 0x00000401L
285#define ERRLOG_OUT_OF_SHARED_MEMORY 0x00000402L
286#define ERRLOG_OUT_OF_MAP_REGISTERS 0x00000403L
287#define ERRLOG_OUT_OF_BUFFER_POOL 0x00000404L
288#define ERRLOG_OUT_OF_NDIS_BUFFER 0x00000405L
289#define ERRLOG_OUT_OF_PACKET_POOL 0x00000406L
290#define ERRLOG_OUT_OF_NDIS_PACKET 0x00000407L
291#define ERRLOG_OUT_OF_LOOKASIDE_MEMORY 0x00000408L
292
293/* NDIS_ERROR_CODE_HARDWARE_FAILURE */
294#define ERRLOG_SELFTEST_FAILED 0x00000501L
295#define ERRLOG_INITIALIZE_ADAPTER 0x00000502L
296#define ERRLOG_REMOVE_MINIPORT 0x00000503L
297
298/* NDIS_ERROR_CODE_RESOURCE_CONFLICT */
299#define ERRLOG_MAP_IO_SPACE 0x00000601L
300#define ERRLOG_QUERY_ADAPTER_RESOURCES 0x00000602L
301#define ERRLOG_NO_IO_RESOURCE 0x00000603L
302#define ERRLOG_NO_INTERRUPT_RESOURCE 0x00000604L
303#define ERRLOG_NO_MEMORY_RESOURCE 0x00000605L
304
305/* WDS definition */
306#define MAX_WDS_ENTRY 4
307#define WDS_PAIRWISE_KEY_OFFSET 60 /* WDS links use pairwise key#60 ~ 63 in ASIC pairwise key table */
308
309#define WDS_DISABLE_MODE 0
310#define WDS_RESTRICT_MODE 1
311#define WDS_BRIDGE_MODE 2
312#define WDS_REPEATER_MODE 3
313#define WDS_LAZY_MODE 4
314
315#define MAX_MESH_NUM 0
316
317#define MAX_APCLI_NUM 0
318
319#define MAX_MBSSID_NUM 1
320#ifdef MBSS_SUPPORT
321#undef MAX_MBSSID_NUM
322#define MAX_MBSSID_NUM (8 - MAX_MESH_NUM - MAX_APCLI_NUM)
323#endif /* MBSS_SUPPORT // */
324
325/* sanity check for apidx */
326#define MBSS_MR_APIDX_SANITY_CHECK(apidx) \
327 { if (apidx > MAX_MBSSID_NUM) { \
328 DBGPRINT(RT_DEBUG_ERROR, ("%s> Error! apidx = %d > MAX_MBSSID_NUM!\n", __func__, apidx)); \
329 apidx = MAIN_MBSSID; } }
330
331#define VALID_WCID(_wcid) ((_wcid) > 0 && (_wcid) < MAX_LEN_OF_MAC_TABLE )
332
333#define MAIN_MBSSID 0
334#define FIRST_MBSSID 1
335
336#define MAX_BEACON_SIZE 512
337/* If the MAX_MBSSID_NUM is larger than 6, */
338/* it shall reserve some WCID space(wcid 222~253) for beacon frames. */
339/* - these wcid 238~253 are reserved for beacon#6(ra6). */
340/* - these wcid 222~237 are reserved for beacon#7(ra7). */
341#if defined(MAX_MBSSID_NUM) && (MAX_MBSSID_NUM == 8)
342#define HW_RESERVED_WCID 222
343#elif defined(MAX_MBSSID_NUM) && (MAX_MBSSID_NUM == 7)
344#define HW_RESERVED_WCID 238
345#else
346#define HW_RESERVED_WCID 255
347#endif
348
349/* Then dedicate wcid of DFS and Carrier-Sense. */
350#define DFS_CTS_WCID (HW_RESERVED_WCID - 1)
351#define CS_CTS_WCID (HW_RESERVED_WCID - 2)
352#define LAST_SPECIFIC_WCID (HW_RESERVED_WCID - 2)
353
354/* If MAX_MBSSID_NUM is 8, the maximum available wcid for the associated STA is 211. */
355/* If MAX_MBSSID_NUM is 7, the maximum available wcid for the associated STA is 228. */
356#define MAX_AVAILABLE_CLIENT_WCID (LAST_SPECIFIC_WCID - MAX_MBSSID_NUM - 1)
357
358/* TX need WCID to find Cipher Key */
359/* these wcid 212 ~ 219 are reserved for bc/mc packets if MAX_MBSSID_NUM is 8. */
360#define GET_GroupKey_WCID(__wcid, __bssidx) \
361 { \
362 __wcid = LAST_SPECIFIC_WCID - (MAX_MBSSID_NUM) + __bssidx; \
363 }
364
365#define IsGroupKeyWCID(__wcid) (((__wcid) < LAST_SPECIFIC_WCID) && ((__wcid) >= (LAST_SPECIFIC_WCID - (MAX_MBSSID_NUM))))
366
367/* definition to support multiple BSSID */
368#define BSS0 0
369#define BSS1 1
370#define BSS2 2
371#define BSS3 3
372#define BSS4 4
373#define BSS5 5
374#define BSS6 6
375#define BSS7 7
376
377/*============================================================ */
378/* Length definitions */
379#define PEER_KEY_NO 2
380#define MAC_ADDR_LEN 6
381#define TIMESTAMP_LEN 8
382#define MAX_LEN_OF_SUPPORTED_RATES MAX_LENGTH_OF_SUPPORT_RATES /* 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */
383#define MAX_LEN_OF_KEY 32 /* 32 octets == 256 bits, Redefine for WPA */
384#define MAX_NUM_OF_CHANNELS MAX_NUM_OF_CHS /* 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination */
385#define MAX_NUM_OF_11JCHANNELS 20 /* 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination */
386#define MAX_LEN_OF_SSID 32
387#define CIPHER_TEXT_LEN 128
388#define HASH_TABLE_SIZE 256
389#define MAX_VIE_LEN 1024 /* New for WPA cipher suite variable IE sizes. */
390#define MAX_SUPPORT_MCS 32
391#define MAX_NUM_OF_BBP_LATCH 140
392
393/*============================================================ */
394/* ASIC WCID Table definition. */
395/*============================================================ */
396#define BSSID_WCID 1 /* in infra mode, always put bssid with this WCID */
397#define MCAST_WCID 0x0
398#define BSS0Mcast_WCID 0x0
399#define BSS1Mcast_WCID 0xf8
400#define BSS2Mcast_WCID 0xf9
401#define BSS3Mcast_WCID 0xfa
402#define BSS4Mcast_WCID 0xfb
403#define BSS5Mcast_WCID 0xfc
404#define BSS6Mcast_WCID 0xfd
405#define BSS7Mcast_WCID 0xfe
406#define RESERVED_WCID 0xff
407
408#define MAX_NUM_OF_ACL_LIST MAX_NUMBER_OF_ACL
409
410#define MAX_LEN_OF_MAC_TABLE MAX_NUMBER_OF_MAC /* if MAX_MBSSID_NUM is 8, this value can't be larger than 211 */
411
412#if MAX_LEN_OF_MAC_TABLE>MAX_AVAILABLE_CLIENT_WCID
413#error MAX_LEN_OF_MAC_TABLE can not be larger than MAX_AVAILABLE_CLIENT_WCID!
414#endif
415
416#define MAX_NUM_OF_WDS_LINK_PERBSSID 3
417#define MAX_NUM_OF_WDS_LINK (MAX_NUM_OF_WDS_LINK_PERBSSID*MAX_MBSSID_NUM)
418#define MAX_NUM_OF_EVENT MAX_NUMBER_OF_EVENT
419#define WDS_LINK_START_WCID (MAX_LEN_OF_MAC_TABLE-1)
420
421#define NUM_OF_TID 8
422#define MAX_AID_BA 4
423#define MAX_LEN_OF_BA_REC_TABLE ((NUM_OF_TID * MAX_LEN_OF_MAC_TABLE)/2) /* (NUM_OF_TID*MAX_AID_BA + 32) //Block ACK recipient */
424#define MAX_LEN_OF_BA_ORI_TABLE ((NUM_OF_TID * MAX_LEN_OF_MAC_TABLE)/2) /* (NUM_OF_TID*MAX_AID_BA + 32) // Block ACK originator */
425#define MAX_LEN_OF_BSS_TABLE 64
426#define MAX_REORDERING_MPDU_NUM 512
427
428/* key related definitions */
429#define SHARE_KEY_NUM 4
430#define MAX_LEN_OF_SHARE_KEY 16 /* byte count */
431#define MAX_LEN_OF_PEER_KEY 16 /* byte count */
432#define PAIRWISE_KEY_NUM 64 /* in MAC ASIC pairwise key table */
433#define GROUP_KEY_NUM 4
434#define PMK_LEN 32
435#define WDS_PAIRWISE_KEY_OFFSET 60 /* WDS links uses pairwise key#60 ~ 63 in ASIC pairwise key table */
436#define PMKID_NO 4 /* Number of PMKID saved supported */
437#define MAX_LEN_OF_MLME_BUFFER 2048
438
439/* power status related definitions */
440#define PWR_ACTIVE 0
441#define PWR_SAVE 1
442#define PWR_MMPS 2 /*MIMO power save */
443
444/* Auth and Assoc mode related definitions */
445#define AUTH_MODE_OPEN 0x00
446#define AUTH_MODE_KEY 0x01
447
448/* BSS Type definitions */
449#define BSS_ADHOC 0 /* = Ndis802_11IBSS */
450#define BSS_INFRA 1 /* = Ndis802_11Infrastructure */
451#define BSS_ANY 2 /* = Ndis802_11AutoUnknown */
452#define BSS_MONITOR 3 /* = Ndis802_11Monitor */
453
454/* Reason code definitions */
455#define REASON_RESERVED 0
456#define REASON_UNSPECIFY 1
457#define REASON_NO_longER_VALID 2
458#define REASON_DEAUTH_STA_LEAVING 3
459#define REASON_DISASSOC_INACTIVE 4
460#define REASON_DISASSPC_AP_UNABLE 5
461#define REASON_CLS2ERR 6
462#define REASON_CLS3ERR 7
463#define REASON_DISASSOC_STA_LEAVING 8
464#define REASON_STA_REQ_ASSOC_NOT_AUTH 9
465#define REASON_INVALID_IE 13
466#define REASON_MIC_FAILURE 14
467#define REASON_4_WAY_TIMEOUT 15
468#define REASON_GROUP_KEY_HS_TIMEOUT 16
469#define REASON_IE_DIFFERENT 17
470#define REASON_MCIPHER_NOT_VALID 18
471#define REASON_UCIPHER_NOT_VALID 19
472#define REASON_AKMP_NOT_VALID 20
473#define REASON_UNSUPPORT_RSNE_VER 21
474#define REASON_INVALID_RSNE_CAP 22
475#define REASON_8021X_AUTH_FAIL 23
476#define REASON_CIPHER_SUITE_REJECTED 24
477#define REASON_DECLINED 37
478
479#define REASON_QOS_UNSPECIFY 32
480#define REASON_QOS_LACK_BANDWIDTH 33
481#define REASON_POOR_CHANNEL_CONDITION 34
482#define REASON_QOS_OUTSIDE_TXOP_LIMITION 35
483#define REASON_QOS_QSTA_LEAVING_QBSS 36
484#define REASON_QOS_UNWANTED_MECHANISM 37
485#define REASON_QOS_MECH_SETUP_REQUIRED 38
486#define REASON_QOS_REQUEST_TIMEOUT 39
487#define REASON_QOS_CIPHER_NOT_SUPPORT 45
488
489/* Status code definitions */
490#define MLME_SUCCESS 0
491#define MLME_UNSPECIFY_FAIL 1
492#define MLME_CANNOT_SUPPORT_CAP 10
493#define MLME_REASSOC_DENY_ASSOC_EXIST 11
494#define MLME_ASSOC_DENY_OUT_SCOPE 12
495#define MLME_ALG_NOT_SUPPORT 13
496#define MLME_SEQ_NR_OUT_OF_SEQUENCE 14
497#define MLME_REJ_CHALLENGE_FAILURE 15
498#define MLME_REJ_TIMEOUT 16
499#define MLME_ASSOC_REJ_UNABLE_HANDLE_STA 17
500#define MLME_ASSOC_REJ_DATA_RATE 18
501
502#define MLME_ASSOC_REJ_NO_EXT_RATE 22
503#define MLME_ASSOC_REJ_NO_EXT_RATE_PBCC 23
504#define MLME_ASSOC_REJ_NO_CCK_OFDM 24
505
506#define MLME_QOS_UNSPECIFY 32
507#define MLME_REQUEST_DECLINED 37
508#define MLME_REQUEST_WITH_INVALID_PARAM 38
509#define MLME_INVALID_GROUP_CIPHER 41
510#define MLME_INVALID_PAIRWISE_CIPHER 42
511#define MLME_INVALID_AKMP 43
512#define MLME_DLS_NOT_ALLOW_IN_QBSS 48
513#define MLME_DEST_STA_NOT_IN_QBSS 49
514#define MLME_DEST_STA_IS_NOT_A_QSTA 50
515
516#define MLME_INVALID_FORMAT 0x51
517#define MLME_FAIL_NO_RESOURCE 0x52
518#define MLME_STATE_MACHINE_REJECT 0x53
519#define MLME_MAC_TABLE_FAIL 0x54
520
521/* IE code */
522#define IE_SSID 0
523#define IE_SUPP_RATES 1
524#define IE_FH_PARM 2
525#define IE_DS_PARM 3
526#define IE_CF_PARM 4
527#define IE_TIM 5
528#define IE_IBSS_PARM 6
529#define IE_COUNTRY 7 /* 802.11d */
530#define IE_802_11D_REQUEST 10 /* 802.11d */
531#define IE_QBSS_LOAD 11 /* 802.11e d9 */
532#define IE_EDCA_PARAMETER 12 /* 802.11e d9 */
533#define IE_TSPEC 13 /* 802.11e d9 */
534#define IE_TCLAS 14 /* 802.11e d9 */
535#define IE_SCHEDULE 15 /* 802.11e d9 */
536#define IE_CHALLENGE_TEXT 16
537#define IE_POWER_CONSTRAint 32 /* 802.11h d3.3 */
538#define IE_POWER_CAPABILITY 33 /* 802.11h d3.3 */
539#define IE_TPC_REQUEST 34 /* 802.11h d3.3 */
540#define IE_TPC_REPORT 35 /* 802.11h d3.3 */
541#define IE_SUPP_CHANNELS 36 /* 802.11h d3.3 */
542#define IE_CHANNEL_SWITCH_ANNOUNCEMENT 37 /* 802.11h d3.3 */
543#define IE_MEASUREMENT_REQUEST 38 /* 802.11h d3.3 */
544#define IE_MEASUREMENT_REPORT 39 /* 802.11h d3.3 */
545#define IE_QUIET 40 /* 802.11h d3.3 */
546#define IE_IBSS_DFS 41 /* 802.11h d3.3 */
547#define IE_ERP 42 /* 802.11g */
548#define IE_TS_DELAY 43 /* 802.11e d9 */
549#define IE_TCLAS_PROCESSING 44 /* 802.11e d9 */
550#define IE_QOS_CAPABILITY 46 /* 802.11e d6 */
551#define IE_HT_CAP 45 /* 802.11n d1. HT CAPABILITY. ELEMENT ID TBD */
552#define IE_AP_CHANNEL_REPORT 51 /* 802.11k d6 */
553#define IE_HT_CAP2 52 /* 802.11n d1. HT CAPABILITY. ELEMENT ID TBD */
554#define IE_RSN 48 /* 802.11i d3.0 */
555#define IE_WPA2 48 /* WPA2 */
556#define IE_EXT_SUPP_RATES 50 /* 802.11g */
557#define IE_SUPP_REG_CLASS 59 /* 802.11y. Supported regulatory classes. */
558#define IE_EXT_CHANNEL_SWITCH_ANNOUNCEMENT 60 /* 802.11n */
559#define IE_ADD_HT 61 /* 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD */
560#define IE_ADD_HT2 53 /* 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD */
561
562/* For 802.11n D3.03 */
563/*#define IE_NEW_EXT_CHA_OFFSET 62 // 802.11n d1. New extension channel offset element */
564#define IE_SECONDARY_CH_OFFSET 62 /* 802.11n D3.03 Secondary Channel Offset element */
565#define IE_WAPI 68 /* WAPI information element */
566#define IE_2040_BSS_COEXIST 72 /* 802.11n D3.0.3 */
567#define IE_2040_BSS_INTOLERANT_REPORT 73 /* 802.11n D3.03 */
568#define IE_OVERLAPBSS_SCAN_PARM 74 /* 802.11n D3.03 */
569#define IE_EXT_CAPABILITY 127 /* 802.11n D3.03 */
570
571#define IE_WPA 221 /* WPA */
572#define IE_VENDOR_SPECIFIC 221 /* Wifi WMM (WME) */
573
574#define OUI_BROADCOM_HT 51 /* */
575#define OUI_BROADCOM_HTADD 52 /* */
576#define OUI_PREN_HT_CAP 51 /* */
577#define OUI_PREN_ADD_HT 52 /* */
578
579/* CCX information */
580#define IE_AIRONET_CKIP 133 /* CCX1.0 ID 85H for CKIP */
581#define IE_AP_TX_POWER 150 /* CCX 2.0 for AP transmit power */
582#define IE_MEASUREMENT_CAPABILITY 221 /* CCX 2.0 */
583#define IE_CCX_V2 221
584#define IE_AIRONET_IPADDRESS 149 /* CCX ID 95H for IP Address */
585#define IE_AIRONET_CCKMREASSOC 156 /* CCX ID 9CH for CCKM Reassociation Request element */
586#define CKIP_NEGOTIATION_LENGTH 30
587#define AIRONET_IPADDRESS_LENGTH 10
588#define AIRONET_CCKMREASSOC_LENGTH 24
589
590/* ======================================================== */
591/* MLME state machine definition */
592/* ======================================================== */
593
594/* STA MLME state mahcines */
595#define ASSOC_STATE_MACHINE 1
596#define AUTH_STATE_MACHINE 2
597#define AUTH_RSP_STATE_MACHINE 3
598#define SYNC_STATE_MACHINE 4
599#define MLME_CNTL_STATE_MACHINE 5
600#define WPA_PSK_STATE_MACHINE 6
601/*#define LEAP_STATE_MACHINE 7 */
602#define AIRONET_STATE_MACHINE 8
603#define ACTION_STATE_MACHINE 9
604
605/* AP MLME state machines */
606#define AP_ASSOC_STATE_MACHINE 11
607#define AP_AUTH_STATE_MACHINE 12
608#define AP_SYNC_STATE_MACHINE 14
609#define AP_CNTL_STATE_MACHINE 15
610#define WSC_STATE_MACHINE 17
611#define WSC_UPNP_STATE_MACHINE 18
612
613#define WPA_STATE_MACHINE 23
614
615/* */
616/* STA's CONTROL/CONNECT state machine: states, events, total function # */
617/* */
618#define CNTL_IDLE 0
619#define CNTL_WAIT_DISASSOC 1
620#define CNTL_WAIT_JOIN 2
621#define CNTL_WAIT_REASSOC 3
622#define CNTL_WAIT_START 4
623#define CNTL_WAIT_AUTH 5
624#define CNTL_WAIT_ASSOC 6
625#define CNTL_WAIT_AUTH2 7
626#define CNTL_WAIT_OID_LIST_SCAN 8
627#define CNTL_WAIT_OID_DISASSOC 9
628#ifdef RTMP_MAC_USB
629#define CNTL_WAIT_SCAN_FOR_CONNECT 10
630#endif /* RTMP_MAC_USB // */
631
632#define MT2_ASSOC_CONF 34
633#define MT2_AUTH_CONF 35
634#define MT2_DEAUTH_CONF 36
635#define MT2_DISASSOC_CONF 37
636#define MT2_REASSOC_CONF 38
637#define MT2_PWR_MGMT_CONF 39
638#define MT2_JOIN_CONF 40
639#define MT2_SCAN_CONF 41
640#define MT2_START_CONF 42
641#define MT2_GET_CONF 43
642#define MT2_SET_CONF 44
643#define MT2_RESET_CONF 45
644#define MT2_FT_OTD_CONF 46
645#define MT2_MLME_ROAMING_REQ 52
646
647#define CNTL_FUNC_SIZE 1
648
649/* */
650/* STA's ASSOC state machine: states, events, total function # */
651/* */
652#define ASSOC_IDLE 0
653#define ASSOC_WAIT_RSP 1
654#define REASSOC_WAIT_RSP 2
655#define DISASSOC_WAIT_RSP 3
656#define MAX_ASSOC_STATE 4
657
658#define ASSOC_MACHINE_BASE 0
659#define MT2_MLME_ASSOC_REQ 0
660#define MT2_MLME_REASSOC_REQ 1
661#define MT2_MLME_DISASSOC_REQ 2
662#define MT2_PEER_DISASSOC_REQ 3
663#define MT2_PEER_ASSOC_REQ 4
664#define MT2_PEER_ASSOC_RSP 5
665#define MT2_PEER_REASSOC_REQ 6
666#define MT2_PEER_REASSOC_RSP 7
667#define MT2_DISASSOC_TIMEOUT 8
668#define MT2_ASSOC_TIMEOUT 9
669#define MT2_REASSOC_TIMEOUT 10
670#define MAX_ASSOC_MSG 11
671
672#define ASSOC_FUNC_SIZE (MAX_ASSOC_STATE * MAX_ASSOC_MSG)
673
674/* */
675/* ACT state machine: states, events, total function # */
676/* */
677#define ACT_IDLE 0
678#define MAX_ACT_STATE 1
679
680#define ACT_MACHINE_BASE 0
681
682/*Those PEER_xx_CATE number is based on real Categary value in IEEE spec. Please do not modify it by your self. */
683/*Category */
684#define MT2_PEER_SPECTRUM_CATE 0
685#define MT2_PEER_QOS_CATE 1
686#define MT2_PEER_DLS_CATE 2
687#define MT2_PEER_BA_CATE 3
688#define MT2_PEER_PUBLIC_CATE 4
689#define MT2_PEER_RM_CATE 5
690/* "FT_CATEGORY_BSS_TRANSITION equal to 6" is defined file of "dot11r_ft.h" */
691#define MT2_PEER_HT_CATE 7 /* 7.4.7 */
692#define MAX_PEER_CATE_MSG 7
693
694#define MT2_MLME_ADD_BA_CATE 8
695#define MT2_MLME_ORI_DELBA_CATE 9
696#define MT2_MLME_REC_DELBA_CATE 10
697#define MT2_MLME_QOS_CATE 11
698#define MT2_MLME_DLS_CATE 12
699#define MT2_ACT_INVALID 13
700#define MAX_ACT_MSG 14
701
702/*Category field */
703#define CATEGORY_SPECTRUM 0
704#define CATEGORY_QOS 1
705#define CATEGORY_DLS 2
706#define CATEGORY_BA 3
707#define CATEGORY_PUBLIC 4
708#define CATEGORY_RM 5
709#define CATEGORY_HT 7
710
711/* DLS Action frame definition */
712#define ACTION_DLS_REQUEST 0
713#define ACTION_DLS_RESPONSE 1
714#define ACTION_DLS_TEARDOWN 2
715
716/*Spectrum Action field value 802.11h 7.4.1 */
717#define SPEC_MRQ 0 /* Request */
718#define SPEC_MRP 1 /*Report */
719#define SPEC_TPCRQ 2
720#define SPEC_TPCRP 3
721#define SPEC_CHANNEL_SWITCH 4
722
723/*BA Action field value */
724#define ADDBA_REQ 0
725#define ADDBA_RESP 1
726#define DELBA 2
727
728/*Public's Action field value in Public Category. Some in 802.11y and some in 11n */
729#define ACTION_BSS_2040_COEXIST 0 /* 11n */
730#define ACTION_DSE_ENABLEMENT 1 /* 11y D9.0 */
731#define ACTION_DSE_DEENABLEMENT 2 /* 11y D9.0 */
732#define ACTION_DSE_REG_LOCATION_ANNOUNCE 3 /* 11y D9.0 */
733#define ACTION_EXT_CH_SWITCH_ANNOUNCE 4 /* 11y D9.0 */
734#define ACTION_DSE_MEASUREMENT_REQ 5 /* 11y D9.0 */
735#define ACTION_DSE_MEASUREMENT_REPORT 6 /* 11y D9.0 */
736#define ACTION_MEASUREMENT_PILOT_ACTION 7 /* 11y D9.0 */
737#define ACTION_DSE_POWER_CONSTRAINT 8 /* 11y D9.0 */
738
739/*HT Action field value */
740#define NOTIFY_BW_ACTION 0
741#define SMPS_ACTION 1
742#define PSMP_ACTION 2
743#define SETPCO_ACTION 3
744#define MIMO_CHA_MEASURE_ACTION 4
745#define MIMO_N_BEACONFORM 5
746#define MIMO_BEACONFORM 6
747#define ANTENNA_SELECT 7
748#define HT_INFO_EXCHANGE 8
749
750#define ACT_FUNC_SIZE (MAX_ACT_STATE * MAX_ACT_MSG)
751/* */
752/* STA's AUTHENTICATION state machine: states, events, total function # */
753/* */
754#define AUTH_REQ_IDLE 0
755#define AUTH_WAIT_SEQ2 1
756#define AUTH_WAIT_SEQ4 2
757#define MAX_AUTH_STATE 3
758
759#define AUTH_MACHINE_BASE 0
760#define MT2_MLME_AUTH_REQ 0
761#define MT2_PEER_AUTH_EVEN 1
762#define MT2_AUTH_TIMEOUT 2
763#define MAX_AUTH_MSG 3
764
765#define AUTH_FUNC_SIZE (MAX_AUTH_STATE * MAX_AUTH_MSG)
766
767/* */
768/* STA's AUTH_RSP state machine: states, events, total function # */
769/* */
770#define AUTH_RSP_IDLE 0
771#define AUTH_RSP_WAIT_CHAL 1
772#define MAX_AUTH_RSP_STATE 2
773
774#define AUTH_RSP_MACHINE_BASE 0
775#define MT2_AUTH_CHALLENGE_TIMEOUT 0
776#define MT2_PEER_AUTH_ODD 1
777#define MT2_PEER_DEAUTH 2
778#define MAX_AUTH_RSP_MSG 3
779
780#define AUTH_RSP_FUNC_SIZE (MAX_AUTH_RSP_STATE * MAX_AUTH_RSP_MSG)
781
782/* */
783/* STA's SYNC state machine: states, events, total function # */
784/* */
785#define SYNC_IDLE 0 /* merge NO_BSS,IBSS_IDLE,IBSS_ACTIVE and BSS in to 1 state */
786#define JOIN_WAIT_BEACON 1
787#define SCAN_LISTEN 2
788#define MAX_SYNC_STATE 3
789
790#define SYNC_MACHINE_BASE 0
791#define MT2_MLME_SCAN_REQ 0
792#define MT2_MLME_JOIN_REQ 1
793#define MT2_MLME_START_REQ 2
794#define MT2_PEER_BEACON 3
795#define MT2_PEER_PROBE_RSP 4
796#define MT2_PEER_ATIM 5
797#define MT2_SCAN_TIMEOUT 6
798#define MT2_BEACON_TIMEOUT 7
799#define MT2_ATIM_TIMEOUT 8
800#define MT2_PEER_PROBE_REQ 9
801#define MAX_SYNC_MSG 10
802
803#define SYNC_FUNC_SIZE (MAX_SYNC_STATE * MAX_SYNC_MSG)
804
805/*Messages for the DLS state machine */
806#define DLS_IDLE 0
807#define MAX_DLS_STATE 1
808
809#define DLS_MACHINE_BASE 0
810#define MT2_MLME_DLS_REQ 0
811#define MT2_PEER_DLS_REQ 1
812#define MT2_PEER_DLS_RSP 2
813#define MT2_MLME_DLS_TEAR_DOWN 3
814#define MT2_PEER_DLS_TEAR_DOWN 4
815#define MAX_DLS_MSG 5
816
817#define DLS_FUNC_SIZE (MAX_DLS_STATE * MAX_DLS_MSG)
818
819/* */
820/* WSC State machine: states, events, total function # */
821/* */
822
823/* */
824/* AP's CONTROL/CONNECT state machine: states, events, total function # */
825/* */
826#define AP_CNTL_FUNC_SIZE 1
827
828/* */
829/* AP's ASSOC state machine: states, events, total function # */
830/* */
831#define AP_ASSOC_IDLE 0
832#define AP_MAX_ASSOC_STATE 1
833
834#define AP_ASSOC_MACHINE_BASE 0
835#define APMT2_MLME_DISASSOC_REQ 0
836#define APMT2_PEER_DISASSOC_REQ 1
837#define APMT2_PEER_ASSOC_REQ 2
838#define APMT2_PEER_REASSOC_REQ 3
839#define APMT2_CLS3ERR 4
840#define AP_MAX_ASSOC_MSG 5
841
842#define AP_ASSOC_FUNC_SIZE (AP_MAX_ASSOC_STATE * AP_MAX_ASSOC_MSG)
843
844/* */
845/* AP's AUTHENTICATION state machine: states, events, total function # */
846/* */
847#define AP_AUTH_REQ_IDLE 0
848#define AP_MAX_AUTH_STATE 1
849
850#define AP_AUTH_MACHINE_BASE 0
851#define APMT2_MLME_DEAUTH_REQ 0
852#define APMT2_CLS2ERR 1
853#define APMT2_PEER_DEAUTH 2
854#define APMT2_PEER_AUTH_REQ 3
855#define APMT2_PEER_AUTH_CONFIRM 4
856#define AP_MAX_AUTH_MSG 5
857
858#define AP_AUTH_FUNC_SIZE (AP_MAX_AUTH_STATE * AP_MAX_AUTH_MSG)
859
860/* */
861/* AP's SYNC state machine: states, events, total function # */
862/* */
863#define AP_SYNC_IDLE 0
864#define AP_SCAN_LISTEN 1
865#define AP_MAX_SYNC_STATE 2
866
867#define AP_SYNC_MACHINE_BASE 0
868#define APMT2_PEER_PROBE_REQ 0
869#define APMT2_PEER_BEACON 1
870#define APMT2_MLME_SCAN_REQ 2
871#define APMT2_PEER_PROBE_RSP 3
872#define APMT2_SCAN_TIMEOUT 4
873#define APMT2_MLME_SCAN_CNCL 5
874#define AP_MAX_SYNC_MSG 6
875
876#define AP_SYNC_FUNC_SIZE (AP_MAX_SYNC_STATE * AP_MAX_SYNC_MSG)
877
878/* */
879/* Common WPA state machine: states, events, total function # */
880/* */
881#define WPA_PTK 0
882#define MAX_WPA_PTK_STATE 1
883
884#define WPA_MACHINE_BASE 0
885#define MT2_EAPPacket 0
886#define MT2_EAPOLStart 1
887#define MT2_EAPOLLogoff 2
888#define MT2_EAPOLKey 3
889#define MT2_EAPOLASFAlert 4
890#define MAX_WPA_MSG 5
891
892#define WPA_FUNC_SIZE (MAX_WPA_PTK_STATE * MAX_WPA_MSG)
893
894/* ============================================================================= */
895
896/* value domain of 802.11 header FC.Tyte, which is b3..b2 of the 1st-byte of MAC header */
897#define BTYPE_MGMT 0
898#define BTYPE_CNTL 1
899#define BTYPE_DATA 2
900
901/* value domain of 802.11 MGMT frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header */
902#define SUBTYPE_ASSOC_REQ 0
903#define SUBTYPE_ASSOC_RSP 1
904#define SUBTYPE_REASSOC_REQ 2
905#define SUBTYPE_REASSOC_RSP 3
906#define SUBTYPE_PROBE_REQ 4
907#define SUBTYPE_PROBE_RSP 5
908#define SUBTYPE_BEACON 8
909#define SUBTYPE_ATIM 9
910#define SUBTYPE_DISASSOC 10
911#define SUBTYPE_AUTH 11
912#define SUBTYPE_DEAUTH 12
913#define SUBTYPE_ACTION 13
914#define SUBTYPE_ACTION_NO_ACK 14
915
916/* value domain of 802.11 CNTL frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header */
917#define SUBTYPE_WRAPPER 7
918#define SUBTYPE_BLOCK_ACK_REQ 8
919#define SUBTYPE_BLOCK_ACK 9
920#define SUBTYPE_PS_POLL 10
921#define SUBTYPE_RTS 11
922#define SUBTYPE_CTS 12
923#define SUBTYPE_ACK 13
924#define SUBTYPE_CFEND 14
925#define SUBTYPE_CFEND_CFACK 15
926
927/* value domain of 802.11 DATA frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header */
928#define SUBTYPE_DATA 0
929#define SUBTYPE_DATA_CFACK 1
930#define SUBTYPE_DATA_CFPOLL 2
931#define SUBTYPE_DATA_CFACK_CFPOLL 3
932#define SUBTYPE_NULL_FUNC 4
933#define SUBTYPE_CFACK 5
934#define SUBTYPE_CFPOLL 6
935#define SUBTYPE_CFACK_CFPOLL 7
936#define SUBTYPE_QDATA 8
937#define SUBTYPE_QDATA_CFACK 9
938#define SUBTYPE_QDATA_CFPOLL 10
939#define SUBTYPE_QDATA_CFACK_CFPOLL 11
940#define SUBTYPE_QOS_NULL 12
941#define SUBTYPE_QOS_CFACK 13
942#define SUBTYPE_QOS_CFPOLL 14
943#define SUBTYPE_QOS_CFACK_CFPOLL 15
944
945/* ACK policy of QOS Control field bit 6:5 */
946#define NORMAL_ACK 0x00 /* b6:5 = 00 */
947#define NO_ACK 0x20 /* b6:5 = 01 */
948#define NO_EXPLICIT_ACK 0x40 /* b6:5 = 10 */
949#define BLOCK_ACK 0x60 /* b6:5 = 11 */
950
951/* */
952/* rtmp_data.c uses this definition */
953/* */
954#define LENGTH_802_11 24
955#define LENGTH_802_11_AND_H 30
956#define LENGTH_802_11_CRC_H 34
957#define LENGTH_802_11_CRC 28
958#define LENGTH_802_11_WITH_ADDR4 30
959#define LENGTH_802_3 14
960#define LENGTH_802_3_TYPE 2
961#define LENGTH_802_1_H 8
962#define LENGTH_EAPOL_H 4
963#define LENGTH_WMMQOS_H 2
964#define LENGTH_CRC 4
965#define MAX_SEQ_NUMBER 0x0fff
966#define LENGTH_802_3_NO_TYPE 12
967#define LENGTH_802_1Q 4 /* VLAN related */
968
969/* STA_CSR4.field.TxResult */
970#define TX_RESULT_SUCCESS 0
971#define TX_RESULT_ZERO_LENGTH 1
972#define TX_RESULT_UNDER_RUN 2
973#define TX_RESULT_OHY_ERROR 4
974#define TX_RESULT_RETRY_FAIL 6
975
976/* All PHY rate summary in TXD */
977/* Preamble MODE in TxD */
978#define MODE_CCK 0
979#define MODE_OFDM 1
980#define MODE_HTMIX 2
981#define MODE_HTGREENFIELD 3
982
983/* MCS for CCK. BW.SGI.STBC are reserved */
984#define MCS_longP_RATE_1 0 /* long preamble CCK 1Mbps */
985#define MCS_longP_RATE_2 1 /* long preamble CCK 1Mbps */
986#define MCS_longP_RATE_5_5 2
987#define MCS_longP_RATE_11 3
988#define MCS_SHORTP_RATE_1 4 /* long preamble CCK 1Mbps. short is forbidden in 1Mbps */
989#define MCS_SHORTP_RATE_2 5 /* short preamble CCK 2Mbps */
990#define MCS_SHORTP_RATE_5_5 6
991#define MCS_SHORTP_RATE_11 7
992/* To send duplicate legacy OFDM. set BW=BW_40. SGI.STBC are reserved */
993#define MCS_RATE_6 0 /* legacy OFDM */
994#define MCS_RATE_9 1 /* OFDM */
995#define MCS_RATE_12 2 /* OFDM */
996#define MCS_RATE_18 3 /* OFDM */
997#define MCS_RATE_24 4 /* OFDM */
998#define MCS_RATE_36 5 /* OFDM */
999#define MCS_RATE_48 6 /* OFDM */
1000#define MCS_RATE_54 7 /* OFDM */
1001/* HT */
1002#define MCS_0 0 /* 1S */
1003#define MCS_1 1
1004#define MCS_2 2
1005#define MCS_3 3
1006#define MCS_4 4
1007#define MCS_5 5
1008#define MCS_6 6
1009#define MCS_7 7
1010#define MCS_8 8 /* 2S */
1011#define MCS_9 9
1012#define MCS_10 10
1013#define MCS_11 11
1014#define MCS_12 12
1015#define MCS_13 13
1016#define MCS_14 14
1017#define MCS_15 15
1018#define MCS_16 16 /* 3*3 */
1019#define MCS_17 17
1020#define MCS_18 18
1021#define MCS_19 19
1022#define MCS_20 20
1023#define MCS_21 21
1024#define MCS_22 22
1025#define MCS_23 23
1026#define MCS_32 32
1027#define MCS_AUTO 33
1028
1029/* OID_HTPHYMODE */
1030/* MODE */
1031#define HTMODE_MM 0
1032#define HTMODE_GF 1
1033
1034/* Fixed Tx MODE - HT, CCK or OFDM */
1035#define FIXED_TXMODE_HT 0
1036#define FIXED_TXMODE_CCK 1
1037#define FIXED_TXMODE_OFDM 2
1038/* BW */
1039#define BW_20 BAND_WIDTH_20
1040#define BW_40 BAND_WIDTH_40
1041#define BW_BOTH BAND_WIDTH_BOTH
1042#define BW_10 BAND_WIDTH_10 /* 802.11j has 10MHz. This definition is for internal usage. doesn't fill in the IE or other field. */
1043
1044/* SHORTGI */
1045#define GI_400 GAP_INTERVAL_400 /* only support in HT mode */
1046#define GI_BOTH GAP_INTERVAL_BOTH
1047#define GI_800 GAP_INTERVAL_800
1048/* STBC */
1049#define STBC_NONE 0
1050#define STBC_USE 1 /* limited use in rt2860b phy */
1051#define RXSTBC_ONE 1 /* rx support of one spatial stream */
1052#define RXSTBC_TWO 2 /* rx support of 1 and 2 spatial stream */
1053#define RXSTBC_THR 3 /* rx support of 1~3 spatial stream */
1054/* MCS FEEDBACK */
1055#define MCSFBK_NONE 0 /* not support mcs feedback / */
1056#define MCSFBK_RSV 1 /* reserved */
1057#define MCSFBK_UNSOLICIT 2 /* only support unsolict mcs feedback */
1058#define MCSFBK_MRQ 3 /* response to both MRQ and unsolict mcs feedback */
1059
1060/* MIMO power safe */
1061#define MMPS_STATIC 0
1062#define MMPS_DYNAMIC 1
1063#define MMPS_RSV 2
1064#define MMPS_ENABLE 3
1065
1066/* A-MSDU size */
1067#define AMSDU_0 0
1068#define AMSDU_1 1
1069
1070/* MCS use 7 bits */
1071#define TXRATEMIMO 0x80
1072#define TXRATEMCS 0x7F
1073#define TXRATEOFDM 0x7F
1074#define RATE_1 0
1075#define RATE_2 1
1076#define RATE_5_5 2
1077#define RATE_11 3
1078#define RATE_6 4 /* OFDM */
1079#define RATE_9 5 /* OFDM */
1080#define RATE_12 6 /* OFDM */
1081#define RATE_18 7 /* OFDM */
1082#define RATE_24 8 /* OFDM */
1083#define RATE_36 9 /* OFDM */
1084#define RATE_48 10 /* OFDM */
1085#define RATE_54 11 /* OFDM */
1086#define RATE_FIRST_OFDM_RATE RATE_6
1087#define RATE_LAST_OFDM_RATE RATE_54
1088#define RATE_6_5 12 /* HT mix */
1089#define RATE_13 13 /* HT mix */
1090#define RATE_19_5 14 /* HT mix */
1091#define RATE_26 15 /* HT mix */
1092#define RATE_39 16 /* HT mix */
1093#define RATE_52 17 /* HT mix */
1094#define RATE_58_5 18 /* HT mix */
1095#define RATE_65 19 /* HT mix */
1096#define RATE_78 20 /* HT mix */
1097#define RATE_104 21 /* HT mix */
1098#define RATE_117 22 /* HT mix */
1099#define RATE_130 23 /* HT mix */
1100/*#define RATE_AUTO_SWITCH 255 // for StaCfg.FixedTxRate only */
1101#define HTRATE_0 12
1102#define RATE_FIRST_MM_RATE HTRATE_0
1103#define RATE_FIRST_HT_RATE HTRATE_0
1104#define RATE_LAST_HT_RATE HTRATE_0
1105
1106/* pTxWI->txop */
1107#define IFS_HTTXOP 0 /* The txop will be handles by ASIC. */
1108#define IFS_PIFS 1
1109#define IFS_SIFS 2
1110#define IFS_BACKOFF 3
1111
1112/* pTxD->RetryMode */
1113#define long_RETRY 1
1114#define SHORT_RETRY 0
1115
1116/* Country Region definition */
1117#define REGION_MINIMUM_BG_BAND 0
1118#define REGION_0_BG_BAND 0 /* 1-11 */
1119#define REGION_1_BG_BAND 1 /* 1-13 */
1120#define REGION_2_BG_BAND 2 /* 10-11 */
1121#define REGION_3_BG_BAND 3 /* 10-13 */
1122#define REGION_4_BG_BAND 4 /* 14 */
1123#define REGION_5_BG_BAND 5 /* 1-14 */
1124#define REGION_6_BG_BAND 6 /* 3-9 */
1125#define REGION_7_BG_BAND 7 /* 5-13 */
1126#define REGION_31_BG_BAND 31 /* 5-13 */
1127#define REGION_MAXIMUM_BG_BAND 7
1128
1129#define REGION_MINIMUM_A_BAND 0
1130#define REGION_0_A_BAND 0 /* 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165 */
1131#define REGION_1_A_BAND 1 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 */
1132#define REGION_2_A_BAND 2 /* 36, 40, 44, 48, 52, 56, 60, 64 */
1133#define REGION_3_A_BAND 3 /* 52, 56, 60, 64, 149, 153, 157, 161 */
1134#define REGION_4_A_BAND 4 /* 149, 153, 157, 161, 165 */
1135#define REGION_5_A_BAND 5 /* 149, 153, 157, 161 */
1136#define REGION_6_A_BAND 6 /* 36, 40, 44, 48 */
1137#define REGION_7_A_BAND 7 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165, 169, 173 */
1138#define REGION_8_A_BAND 8 /* 52, 56, 60, 64 */
1139#define REGION_9_A_BAND 9 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165 */
1140#define REGION_10_A_BAND 10 /* 36, 40, 44, 48, 149, 153, 157, 161, 165 */
1141#define REGION_11_A_BAND 11 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 149, 153, 157, 161 */
1142#define REGION_12_A_BAND 12 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 */
1143#define REGION_13_A_BAND 13 /* 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161 */
1144#define REGION_14_A_BAND 14 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 136, 140, 149, 153, 157, 161, 165 */
1145#define REGION_15_A_BAND 15 /* 149, 153, 157, 161, 165, 169, 173 */
1146#define REGION_MAXIMUM_A_BAND 15
1147
1148/* pTxD->CipherAlg */
1149#define CIPHER_NONE 0
1150#define CIPHER_WEP64 1
1151#define CIPHER_WEP128 2
1152#define CIPHER_TKIP 3
1153#define CIPHER_AES 4
1154#define CIPHER_CKIP64 5
1155#define CIPHER_CKIP128 6
1156#define CIPHER_TKIP_NO_MIC 7 /* MIC appended by driver: not a valid value in hardware key table */
1157#define CIPHER_SMS4 8
1158
1159/* LED Status. */
1160#define LED_LINK_DOWN 0
1161#define LED_LINK_UP 1
1162#define LED_RADIO_OFF 2
1163#define LED_RADIO_ON 3
1164#define LED_HALT 4
1165#define LED_WPS 5
1166#define LED_ON_SITE_SURVEY 6
1167#define LED_POWER_UP 7
1168
1169/* value domain of pAd->LedCntl.LedMode and E2PROM */
1170#define LED_MODE_DEFAULT 0
1171#define LED_MODE_TWO_LED 1
1172/*#define LED_MODE_SIGNAL_STREGTH 8 // EEPROM define =8 */
1173#define LED_MODE_SIGNAL_STREGTH 0x40 /* EEPROM define = 64 */
1174
1175/* RC4 init value, used fro WEP & TKIP */
1176#define PPPINITFCS32 0xffffffff /* Initial FCS value */
1177
1178/* value domain of pAd->StaCfg.PortSecured. 802.1X controlled port definition */
1179#define WPA_802_1X_PORT_SECURED 1
1180#define WPA_802_1X_PORT_NOT_SECURED 2
1181
1182#define PAIRWISE_KEY 1
1183#define GROUP_KEY 2
1184
1185/*definition of DRS */
1186#define MAX_STEP_OF_TX_RATE_SWITCH 32
1187
1188/* pre-allocated free NDIS PACKET/BUFFER poll for internal usage */
1189#define MAX_NUM_OF_FREE_NDIS_PACKET 128
1190
1191/*Block ACK */
1192#define MAX_TX_REORDERBUF 64
1193#define MAX_RX_REORDERBUF 64
1194#define DEFAULT_TX_TIMEOUT 30
1195#define DEFAULT_RX_TIMEOUT 30
1196
1197/* definition of Recipient or Originator */
1198#define I_RECIPIENT TRUE
1199#define I_ORIGINATOR FALSE
1200
1201#define DEFAULT_BBP_TX_POWER 0
1202#define DEFAULT_RF_TX_POWER 5
1203
1204#define MAX_INI_BUFFER_SIZE 4096
1205#define MAX_PARAM_BUFFER_SIZE (2048) /* enough for ACL (18*64) */
1206 /*18 : the length of Mac address acceptable format "01:02:03:04:05:06;") */
1207 /*64 : MAX_NUM_OF_ACL_LIST */
1208/* definition of pAd->OpMode */
1209#define OPMODE_STA 0
1210#define OPMODE_AP 1
1211/*#define OPMODE_L3_BRG 2 // as AP and STA at the same time */
1212
1213/* ========================= AP rtmp_def.h =========================== */
1214/* value domain for pAd->EventTab.Log[].Event */
1215#define EVENT_RESET_ACCESS_POint 0 /* Log = "hh:mm:ss Restart Access Point" */
1216#define EVENT_ASSOCIATED 1 /* Log = "hh:mm:ss STA 00:01:02:03:04:05 associated" */
1217#define EVENT_DISASSOCIATED 2 /* Log = "hh:mm:ss STA 00:01:02:03:04:05 left this BSS" */
1218#define EVENT_AGED_OUT 3 /* Log = "hh:mm:ss STA 00:01:02:03:04:05 was aged-out and removed from this BSS" */
1219#define EVENT_COUNTER_M 4
1220#define EVENT_INVALID_PSK 5
1221#define EVENT_MAX_EVENT_TYPE 6
1222/* ==== end of AP rtmp_def.h ============ */
1223
1224/* definition RSSI Number */
1225#define RSSI_0 0
1226#define RSSI_1 1
1227#define RSSI_2 2
1228
1229/* definition of radar detection */
1230#define RD_NORMAL_MODE 0 /* Not found radar signal */
1231#define RD_SWITCHING_MODE 1 /* Found radar signal, and doing channel switch */
1232#define RD_SILENCE_MODE 2 /* After channel switch, need to be silence a while to ensure radar not found */
1233
1234/*Driver defined cid for mapping status and command. */
1235#define SLEEPCID 0x11
1236#define WAKECID 0x22
1237#define QUERYPOWERCID 0x33
1238#define OWNERMCU 0x1
1239#define OWNERCPU 0x0
1240
1241/* MBSSID definition */
1242#define ENTRY_NOT_FOUND 0xFF
1243
1244/* After Linux 2.6.9,
1245 * VLAN module use Private (from user) interface flags (netdevice->priv_flags).
1246 * #define IFF_802_1Q_VLAN 0x1 -- 802.1Q VLAN device. in if.h
1247 * ref to ip_sabotage_out() [ out->priv_flags & IFF_802_1Q_VLAN ] in br_netfilter.c
1248 *
1249 * For this reason, we MUST use EVEN value in priv_flags
1250 */
1251#define INT_MAIN 0x0100
1252#define INT_MBSSID 0x0200
1253#define INT_WDS 0x0300
1254#define INT_APCLI 0x0400
1255#define INT_MESH 0x0500
1256
1257#define INF_MAIN_DEV_NAME "wlan"
1258#define INF_MBSSID_DEV_NAME "ra"
1259#define INF_WDS_DEV_NAME "wds"
1260#define INF_APCLI_DEV_NAME "apcli"
1261#define INF_MESH_DEV_NAME "mesh"
1262
1263/* WEP Key TYPE */
1264#define WEP_HEXADECIMAL_TYPE 0
1265#define WEP_ASCII_TYPE 1
1266
1267/* WIRELESS EVENTS definition */
1268/* Max number of char in custom event, refer to wireless_tools.28/wireless.20.h */
1269#define IW_CUSTOM_MAX_LEN 255 /* In bytes */
1270
1271/* For system event - start */
1272#define IW_SYS_EVENT_FLAG_START 0x0200
1273#define IW_ASSOC_EVENT_FLAG 0x0200
1274#define IW_DISASSOC_EVENT_FLAG 0x0201
1275#define IW_DEAUTH_EVENT_FLAG 0x0202
1276#define IW_AGEOUT_EVENT_FLAG 0x0203
1277#define IW_COUNTER_MEASURES_EVENT_FLAG 0x0204
1278#define IW_REPLAY_COUNTER_DIFF_EVENT_FLAG 0x0205
1279#define IW_RSNIE_DIFF_EVENT_FLAG 0x0206
1280#define IW_MIC_DIFF_EVENT_FLAG 0x0207
1281#define IW_ICV_ERROR_EVENT_FLAG 0x0208
1282#define IW_MIC_ERROR_EVENT_FLAG 0x0209
1283#define IW_GROUP_HS_TIMEOUT_EVENT_FLAG 0x020A
1284#define IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG 0x020B
1285#define IW_RSNIE_SANITY_FAIL_EVENT_FLAG 0x020C
1286#define IW_SET_KEY_DONE_WPA1_EVENT_FLAG 0x020D
1287#define IW_SET_KEY_DONE_WPA2_EVENT_FLAG 0x020E
1288#define IW_STA_LINKUP_EVENT_FLAG 0x020F
1289#define IW_STA_LINKDOWN_EVENT_FLAG 0x0210
1290#define IW_SCAN_COMPLETED_EVENT_FLAG 0x0211
1291#define IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG 0x0212
1292/* if add new system event flag, please update the IW_SYS_EVENT_FLAG_END */
1293#define IW_SYS_EVENT_FLAG_END 0x0212
1294#define IW_SYS_EVENT_TYPE_NUM (IW_SYS_EVENT_FLAG_END - IW_SYS_EVENT_FLAG_START + 1)
1295/* For system event - end */
1296
1297/* For spoof attack event - start */
1298#define IW_SPOOF_EVENT_FLAG_START 0x0300
1299#define IW_CONFLICT_SSID_EVENT_FLAG 0x0300
1300#define IW_SPOOF_ASSOC_RESP_EVENT_FLAG 0x0301
1301#define IW_SPOOF_REASSOC_RESP_EVENT_FLAG 0x0302
1302#define IW_SPOOF_PROBE_RESP_EVENT_FLAG 0x0303
1303#define IW_SPOOF_BEACON_EVENT_FLAG 0x0304
1304#define IW_SPOOF_DISASSOC_EVENT_FLAG 0x0305
1305#define IW_SPOOF_AUTH_EVENT_FLAG 0x0306
1306#define IW_SPOOF_DEAUTH_EVENT_FLAG 0x0307
1307#define IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG 0x0308
1308#define IW_REPLAY_ATTACK_EVENT_FLAG 0x0309
1309/* if add new spoof attack event flag, please update the IW_SPOOF_EVENT_FLAG_END */
1310#define IW_SPOOF_EVENT_FLAG_END 0x0309
1311#define IW_SPOOF_EVENT_TYPE_NUM (IW_SPOOF_EVENT_FLAG_END - IW_SPOOF_EVENT_FLAG_START + 1)
1312/* For spoof attack event - end */
1313
1314/* For flooding attack event - start */
1315#define IW_FLOOD_EVENT_FLAG_START 0x0400
1316#define IW_FLOOD_AUTH_EVENT_FLAG 0x0400
1317#define IW_FLOOD_ASSOC_REQ_EVENT_FLAG 0x0401
1318#define IW_FLOOD_REASSOC_REQ_EVENT_FLAG 0x0402
1319#define IW_FLOOD_PROBE_REQ_EVENT_FLAG 0x0403
1320#define IW_FLOOD_DISASSOC_EVENT_FLAG 0x0404
1321#define IW_FLOOD_DEAUTH_EVENT_FLAG 0x0405
1322#define IW_FLOOD_EAP_REQ_EVENT_FLAG 0x0406
1323/* if add new flooding attack event flag, please update the IW_FLOOD_EVENT_FLAG_END */
1324#define IW_FLOOD_EVENT_FLAG_END 0x0406
1325#define IW_FLOOD_EVENT_TYPE_NUM (IW_FLOOD_EVENT_FLAG_END - IW_FLOOD_EVENT_FLAG_START + 1)
1326/* For flooding attack - end */
1327
1328/* End - WIRELESS EVENTS definition */
1329
1330/* definition for DLS, kathy */
1331#define MAX_NUM_OF_INIT_DLS_ENTRY 1
1332#define MAX_NUM_OF_DLS_ENTRY MAX_NUMBER_OF_DLS_ENTRY
1333
1334/*Block ACK, kathy */
1335#define MAX_TX_REORDERBUF 64
1336#define MAX_RX_REORDERBUF 64
1337#define DEFAULT_TX_TIMEOUT 30
1338#define DEFAULT_RX_TIMEOUT 30
1339#define MAX_BARECI_SESSION 8
1340
1341#ifndef IW_ESSID_MAX_SIZE
1342/* Maximum size of the ESSID and pAd->nickname strings */
1343#define IW_ESSID_MAX_SIZE 32
1344#endif
1345
1346/* For AsicRadioOff/AsicRadioOn function */
1347#define DOT11POWERSAVE 0
1348#define GUIRADIO_OFF 1
1349#define RTMP_HALT 2
1350#define GUI_IDLE_POWER_SAVE 3
1351/* -- */
1352
1353/* definition for WpaSupport flag */
1354#define WPA_SUPPLICANT_DISABLE 0
1355#define WPA_SUPPLICANT_ENABLE 1
1356#define WPA_SUPPLICANT_ENABLE_WITH_WEB_UI 2
1357
1358/* Endian byte swapping codes */
1359#define SWAP16(x) \
1360 ((u16)( \
1361 (((u16)(x) & (u16)0x00ffU) << 8) | \
1362 (((u16)(x) & (u16)0xff00U) >> 8) ))
1363
1364#define SWAP32(x) \
1365 ((u32)( \
1366 (((u32)(x) & (u32)0x000000ffUL) << 24) | \
1367 (((u32)(x) & (u32)0x0000ff00UL) << 8) | \
1368 (((u32)(x) & (u32)0x00ff0000UL) >> 8) | \
1369 (((u32)(x) & (u32)0xff000000UL) >> 24) ))
1370
1371#define SWAP64(x) \
1372 ((u64)( \
1373 (u64)(((u64)(x) & (u64)0x00000000000000ffULL) << 56) | \
1374 (u64)(((u64)(x) & (u64)0x000000000000ff00ULL) << 40) | \
1375 (u64)(((u64)(x) & (u64)0x0000000000ff0000ULL) << 24) | \
1376 (u64)(((u64)(x) & (u64)0x00000000ff000000ULL) << 8) | \
1377 (u64)(((u64)(x) & (u64)0x000000ff00000000ULL) >> 8) | \
1378 (u64)(((u64)(x) & (u64)0x0000ff0000000000ULL) >> 24) | \
1379 (u64)(((u64)(x) & (u64)0x00ff000000000000ULL) >> 40) | \
1380 (u64)(((u64)(x) & (u64)0xff00000000000000ULL) >> 56) ))
1381
1382#define cpu2le64(x) ((u64)(x))
1383#define le2cpu64(x) ((u64)(x))
1384#define cpu2le32(x) ((u32)(x))
1385#define le2cpu32(x) ((u32)(x))
1386#define cpu2le16(x) ((u16)(x))
1387#define le2cpu16(x) ((u16)(x))
1388#define cpu2be64(x) SWAP64((x))
1389#define be2cpu64(x) SWAP64((x))
1390#define cpu2be32(x) SWAP32((x))
1391#define be2cpu32(x) SWAP32((x))
1392#define cpu2be16(x) SWAP16((x))
1393#define be2cpu16(x) SWAP16((x))
1394
1395#define ABS(_x, _y) ((_x) > (_y)) ? ((_x) -(_y)) : ((_y) -(_x))
1396
1397#define A2Dec(_X, _p) \
1398{ \
1399 u8 *p; \
1400 _X = 0; \
1401 p = _p; \
1402 while (((*p >= '0') && (*p <= '9'))) \
1403 { \
1404 if ((*p >= '0') && (*p <= '9')) \
1405 _X = _X * 10 + *p - 48; \
1406 p++; \
1407 } \
1408}
1409
1410#define A2Hex(_X, _p) \
1411do{ \
1412 char *__p; \
1413 (_X) = 0; \
1414 __p = (char *)(_p); \
1415 while (((*__p >= 'a') && (*__p <= 'f')) || ((*__p >= 'A') && (*__p <= 'F')) || ((*__p >= '0') && (*__p <= '9'))) \
1416 { \
1417 if ((*__p >= 'a') && (*__p <= 'f')) \
1418 (_X) = (_X) * 16 + *__p - 87; \
1419 else if ((*__p >= 'A') && (*__p <= 'F')) \
1420 (_X) = (_X) * 16 + *__p - 55; \
1421 else if ((*__p >= '0') && (*__p <= '9')) \
1422 (_X) = (_X) * 16 + *__p - 48; \
1423 __p++; \
1424 } \
1425}while(0)
1426
1427#endif /* __RTMP_DEF_H__ */
diff --git a/drivers/staging/rt2860/rtmp_dot11.h b/drivers/staging/rt2860/rtmp_dot11.h
deleted file mode 100644
index 4f8abd77ada..00000000000
--- a/drivers/staging/rt2860/rtmp_dot11.h
+++ /dev/null
@@ -1,100 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27
28#ifndef __DOT11_BASE_H__
29#define __DOT11_BASE_H__
30
31#include "rtmp_type.h"
32
33/* 4-byte HTC field. maybe included in any frame except non-QOS data frame. The Order bit must set 1. */
34struct PACKED rt_ht_control {
35 u32 MA:1; /*management action payload exist in (QoS Null+HTC) */
36 u32 TRQ:1; /*sounding request */
37 u32 MRQ:1; /*MCS feedback. Request for a MCS feedback */
38 u32 MRSorASI:3; /* MRQ Sequence identifier. unchanged during entire procedure. 0x000-0x110. */
39 u32 MFS:3; /*SET to the received value of MRS. 0x111 for unsolicited MFB. */
40 u32 MFBorASC:7; /*Link adaptation feedback containing recommended MCS. 0x7f for no feedback or not available */
41 u32 CalPos:2; /* calibration position */
42 u32 CalSeq:2; /*calibration sequence */
43 u32 FBKReq:2; /*feedback request */
44 u32 CSISTEERING:2; /*CSI/ STEERING */
45 u32 ZLFAnnouce:1; /* ZLF announcement */
46 u32 rsv:5; /*calibration sequence */
47 u32 ACConstraint:1; /*feedback request */
48 u32 RDG:1; /*RDG / More PPDU */
49};
50
51/* 2-byte QOS CONTROL field */
52struct PACKED rt_qos_control {
53 u16 TID:4;
54 u16 EOSP:1;
55 u16 AckPolicy:2; /*0: normal ACK 1:No ACK 2:scheduled under MTBA/PSMP 3: BA */
56 u16 AMsduPresent:1;
57 u16 Txop_QueueSize:8;
58};
59
60/* 2-byte Frame control field */
61struct PACKED rt_frame_control {
62 u16 Ver:2; /* Protocol version */
63 u16 Type:2; /* MSDU type */
64 u16 SubType:4; /* MSDU subtype */
65 u16 ToDs:1; /* To DS indication */
66 u16 FrDs:1; /* From DS indication */
67 u16 MoreFrag:1; /* More fragment bit */
68 u16 Retry:1; /* Retry status bit */
69 u16 PwrMgmt:1; /* Power management bit */
70 u16 MoreData:1; /* More data bit */
71 u16 Wep:1; /* Wep data */
72 u16 Order:1; /* Strict order expected */
73};
74
75struct PACKED rt_header_802_11 {
76 struct rt_frame_control FC;
77 u16 Duration;
78 u8 Addr1[MAC_ADDR_LEN];
79 u8 Addr2[MAC_ADDR_LEN];
80 u8 Addr3[MAC_ADDR_LEN];
81 u16 Frag:4;
82 u16 Sequence:12;
83 u8 Octet[0];
84};
85
86struct PACKED rt_pspoll_frame {
87 struct rt_frame_control FC;
88 u16 Aid;
89 u8 Bssid[MAC_ADDR_LEN];
90 u8 Ta[MAC_ADDR_LEN];
91};
92
93struct PACKED rt_rts_frame {
94 struct rt_frame_control FC;
95 u16 Duration;
96 u8 Addr1[MAC_ADDR_LEN];
97 u8 Addr2[MAC_ADDR_LEN];
98};
99
100#endif /* __DOT11_BASE_H__ // */
diff --git a/drivers/staging/rt2860/rtmp_iface.h b/drivers/staging/rt2860/rtmp_iface.h
deleted file mode 100644
index 808c0552984..00000000000
--- a/drivers/staging/rt2860/rtmp_iface.h
+++ /dev/null
@@ -1,75 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rt_iface.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 --------- ---------- ----------------------------------------------
35 */
36
37#ifndef __RTMP_IFACE_H__
38#define __RTMP_IFACE_H__
39
40#ifdef RTMP_PCI_SUPPORT
41#include "iface/rtmp_pci.h"
42#endif /* RTMP_PCI_SUPPORT // */
43#ifdef RTMP_USB_SUPPORT
44#include "iface/rtmp_usb.h"
45#endif /* RTMP_USB_SUPPORT // */
46
47struct rt_inf_pci_config {
48 unsigned long CSRBaseAddress; /* PCI MMIO Base Address, all access will use */
49 unsigned int irq_num;
50};
51
52struct rt_inf_usb_config {
53 u8 BulkInEpAddr; /* bulk-in endpoint address */
54 u8 BulkOutEpAddr[6]; /* bulk-out endpoint address */
55};
56
57struct rt_inf_rbus_config {
58 unsigned long csr_addr;
59 unsigned int irq;
60};
61
62typedef enum _RTMP_INF_TYPE_ {
63 RTMP_DEV_INF_UNKNOWN = 0,
64 RTMP_DEV_INF_PCI = 1,
65 RTMP_DEV_INF_USB = 2,
66 RTMP_DEV_INF_RBUS = 4,
67} RTMP_INF_TYPE;
68
69typedef union _RTMP_INF_CONFIG_ {
70 struct rt_inf_pci_config pciConfig;
71 struct rt_inf_usb_config usbConfig;
72 struct rt_inf_rbus_config rbusConfig;
73} RTMP_INF_CONFIG;
74
75#endif /* __RTMP_IFACE_H__ // */
diff --git a/drivers/staging/rt2860/rtmp_mcu.h b/drivers/staging/rt2860/rtmp_mcu.h
deleted file mode 100644
index d0987e55cda..00000000000
--- a/drivers/staging/rt2860/rtmp_mcu.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_mcu.h
29
30 Abstract:
31 Miniport header file for mcu related information
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36*/
37
38#ifndef __RTMP_MCU_H__
39#define __RTMP_MCU_H__
40
41int RtmpAsicEraseFirmware(struct rt_rtmp_adapter *pAd);
42
43int RtmpAsicLoadFirmware(struct rt_rtmp_adapter *pAd);
44
45int RtmpAsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
46 u8 Command,
47 u8 Token, u8 Arg0, u8 Arg1);
48
49#endif /* __RTMP_MCU_H__ // */
diff --git a/drivers/staging/rt2860/rtmp_os.h b/drivers/staging/rt2860/rtmp_os.h
deleted file mode 100644
index 94c30c8ca66..00000000000
--- a/drivers/staging/rt2860/rtmp_os.h
+++ /dev/null
@@ -1,90 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_os.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 --------- ---------- ----------------------------------------------
35 */
36
37#ifndef __RTMP_OS_H__
38#define __RTMP_OS_H__
39
40#ifdef LINUX
41#include "rt_linux.h"
42#endif /* LINUX // */
43
44/*
45 This data structure mainly strip some callback function defined in
46 "struct net_device" in kernel source "include/linux/netdevice.h".
47
48 The definition of this data structure may various depends on different
49 OS. Use it carefully.
50*/
51struct rt_rtmp_os_netdev_op_hook {
52 const struct net_device_ops *netdev_ops;
53 void *priv;
54 int priv_flags;
55 unsigned char devAddr[6];
56 unsigned char devName[16];
57 unsigned char needProtcted;
58};
59
60typedef enum _RTMP_TASK_STATUS_ {
61 RTMP_TASK_STAT_UNKNOWN = 0,
62 RTMP_TASK_STAT_INITED = 1,
63 RTMP_TASK_STAT_RUNNING = 2,
64 RTMP_TASK_STAT_STOPED = 4,
65} RTMP_TASK_STATUS;
66#define RTMP_TASK_CAN_DO_INSERT (RTMP_TASK_STAT_INITED |RTMP_TASK_STAT_RUNNING)
67
68#define RTMP_OS_TASK_NAME_LEN 16
69struct rt_rtmp_os_task {
70 char taskName[RTMP_OS_TASK_NAME_LEN];
71 void *priv;
72 /*unsigned long taskFlags; */
73 RTMP_TASK_STATUS taskStatus;
74#ifndef KTHREAD_SUPPORT
75 struct semaphore taskSema;
76 struct pid *taskPID;
77 struct completion taskComplete;
78#endif
79 unsigned char task_killed;
80#ifdef KTHREAD_SUPPORT
81 struct task_struct *kthread_task;
82 wait_queue_head_t kthread_q;
83 BOOLEAN kthread_running;
84#endif
85};
86
87int RtmpOSIRQRequest(struct net_device *pNetDev);
88int RtmpOSIRQRelease(struct net_device *pNetDev);
89
90#endif /* __RMTP_OS_H__ // */
diff --git a/drivers/staging/rt2860/rtmp_timer.h b/drivers/staging/rt2860/rtmp_timer.h
deleted file mode 100644
index 15b62874350..00000000000
--- a/drivers/staging/rt2860/rtmp_timer.h
+++ /dev/null
@@ -1,148 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_timer.h
29
30 Abstract:
31 Ralink Wireless Driver timer related data structures and declarations
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Name Date Modification logs
37 Shiang Tu Aug-28-2008 init version
38 Justin P. Mattock 11/07/2010 Fix a typo
39
40*/
41
42#ifndef __RTMP_TIMER_H__
43#define __RTMP_TIMER_H__
44
45#include "rtmp_os.h"
46
47#define DECLARE_TIMER_FUNCTION(_func) \
48 void rtmp_timer_##_func(unsigned long data)
49
50#define GET_TIMER_FUNCTION(_func) \
51 rtmp_timer_##_func
52
53/* ----------------- Timer Related MARCO ---------------*/
54/* In some os or chipset, we have a lot of timer functions and will read/write register, */
55/* it's not allowed in Linux USB sub-system to do it ( because of sleep issue when */
56/* submit to ctrl pipe). So we need a wrapper function to take care it. */
57
58#ifdef RTMP_TIMER_TASK_SUPPORT
59typedef void(*RTMP_TIMER_TASK_HANDLE) (void *SystemSpecific1,
60 void *FunctionContext,
61 void *SystemSpecific2,
62 void *SystemSpecific3);
63#endif /* RTMP_TIMER_TASK_SUPPORT // */
64
65struct rt_ralink_timer {
66 struct timer_list TimerObj; /* Ndis Timer object */
67 BOOLEAN Valid; /* Set to True when call RTMPInitTimer */
68 BOOLEAN State; /* True if timer cancelled */
69 BOOLEAN PeriodicType; /* True if timer is periodic timer */
70 BOOLEAN Repeat; /* True if periodic timer */
71 unsigned long TimerValue; /* Timer value in milliseconds */
72 unsigned long cookie; /* os specific object */
73#ifdef RTMP_TIMER_TASK_SUPPORT
74 RTMP_TIMER_TASK_HANDLE handle;
75 void *pAd;
76#endif /* RTMP_TIMER_TASK_SUPPORT // */
77};
78
79#ifdef RTMP_TIMER_TASK_SUPPORT
80struct rt_rtmp_timer_task_entry {
81 struct rt_ralink_timer *pRaTimer;
82 struct rt_rtmp_timer_task_entry *pNext;
83};
84
85#define TIMER_QUEUE_SIZE_MAX 128
86struct rt_rtmp_timer_task_queue {
87 unsigned int status;
88 unsigned char *pTimerQPoll;
89 struct rt_rtmp_timer_task_entry *pQPollFreeList;
90 struct rt_rtmp_timer_task_entry *pQHead;
91 struct rt_rtmp_timer_task_entry *pQTail;
92};
93
94#define BUILD_TIMER_FUNCTION(_func) \
95void rtmp_timer_##_func(unsigned long data) \
96{ \
97 struct rt_ralink_timer *_pTimer = (struct rt_ralink_timer *)data; \
98 struct rt_rtmp_timer_task_entry *_pQNode; \
99 struct rt_rtmp_adapter *_pAd; \
100 \
101 _pTimer->handle = _func; \
102 _pAd = (struct rt_rtmp_adapter *)_pTimer->pAd; \
103 _pQNode = RtmpTimerQInsert(_pAd, _pTimer); \
104 if ((_pQNode == NULL) && (_pAd->TimerQ.status & RTMP_TASK_CAN_DO_INSERT)) \
105 RTMP_OS_Add_Timer(&_pTimer->TimerObj, OS_HZ); \
106}
107#else
108#define BUILD_TIMER_FUNCTION(_func) \
109void rtmp_timer_##_func(unsigned long data) \
110{ \
111 struct rt_ralink_timer *pTimer = (struct rt_ralink_timer *)data; \
112 \
113 _func(NULL, (void *)pTimer->cookie, NULL, pTimer); \
114 if (pTimer->Repeat) \
115 RTMP_OS_Add_Timer(&pTimer->TimerObj, pTimer->TimerValue); \
116}
117#endif /* RTMP_TIMER_TASK_SUPPORT // */
118
119DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
120DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
121DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
122DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
123DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
124#ifdef RTMP_MAC_USB
125DECLARE_TIMER_FUNCTION(BeaconUpdateExec);
126#endif /* RTMP_MAC_USB // */
127
128DECLARE_TIMER_FUNCTION(BeaconTimeout);
129DECLARE_TIMER_FUNCTION(ScanTimeout);
130DECLARE_TIMER_FUNCTION(AuthTimeout);
131DECLARE_TIMER_FUNCTION(AssocTimeout);
132DECLARE_TIMER_FUNCTION(ReassocTimeout);
133DECLARE_TIMER_FUNCTION(DisassocTimeout);
134DECLARE_TIMER_FUNCTION(LinkDownExec);
135DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
136DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
137DECLARE_TIMER_FUNCTION(PsPollWakeExec);
138DECLARE_TIMER_FUNCTION(RadioOnExec);
139
140#ifdef RTMP_MAC_USB
141DECLARE_TIMER_FUNCTION(RtmpUsbStaAsicForceWakeupTimeout);
142#endif /* RTMP_MAC_USB // */
143
144#if defined(AP_LED) || defined(STA_LED)
145DECLARE_TIMER_FUNCTION(LedCtrlMain);
146#endif
147
148#endif /* __RTMP_TIMER_H__ // */
diff --git a/drivers/staging/rt2860/rtmp_type.h b/drivers/staging/rt2860/rtmp_type.h
deleted file mode 100644
index d9bb2d64c8b..00000000000
--- a/drivers/staging/rt2860/rtmp_type.h
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_type.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Paul Lin 1-2-2004
37*/
38#ifndef __RTMP_TYPE_H__
39#define __RTMP_TYPE_H__
40
41#include <linux/types.h>
42
43#define PACKED __attribute__ ((packed))
44
45typedef unsigned char BOOLEAN;
46
47typedef union _LARGE_INTEGER {
48 struct {
49 u32 LowPart;
50 int HighPart;
51 } u;
52 long long QuadPart;
53} LARGE_INTEGER;
54
55/* */
56/* Register set pair for initialzation register set definition */
57/* */
58struct rt_rtmp_reg_pair {
59 unsigned long Register;
60 unsigned long Value;
61};
62
63struct rt_reg_pair {
64 u8 Register;
65 u8 Value;
66};
67
68/* */
69/* Register set pair for initialzation register set definition */
70/* */
71struct rt_rtmp_rf_regs {
72 u8 Channel;
73 unsigned long R1;
74 unsigned long R2;
75 unsigned long R3;
76 unsigned long R4;
77};
78
79struct rt_frequency_item {
80 u8 Channel;
81 u8 N;
82 u8 R;
83 u8 K;
84};
85
86#define STATUS_SUCCESS 0x00
87#define STATUS_UNSUCCESSFUL 0x01
88
89#endif /* __RTMP_TYPE_H__ // */
diff --git a/drivers/staging/rt2860/rtusb_io.h b/drivers/staging/rt2860/rtusb_io.h
deleted file mode 100644
index 64a2fe43528..00000000000
--- a/drivers/staging/rt2860/rtusb_io.h
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26*/
27
28#ifndef __RTUSB_IO_H__
29#define __RTUSB_IO_H__
30
31#include "rtmp_type.h"
32
33/* New for MeetingHouse Api support */
34#define CMDTHREAD_VENDOR_RESET 0x0D730101 /* cmd */
35#define CMDTHREAD_VENDOR_UNPLUG 0x0D730102 /* cmd */
36#define CMDTHREAD_VENDOR_SWITCH_FUNCTION 0x0D730103 /* cmd */
37#define CMDTHREAD_MULTI_WRITE_MAC 0x0D730107 /* cmd */
38#define CMDTHREAD_MULTI_READ_MAC 0x0D730108 /* cmd */
39#define CMDTHREAD_VENDOR_EEPROM_WRITE 0x0D73010A /* cmd */
40#define CMDTHREAD_VENDOR_EEPROM_READ 0x0D73010B /* cmd */
41#define CMDTHREAD_VENDOR_ENTER_TESTMODE 0x0D73010C /* cmd */
42#define CMDTHREAD_VENDOR_EXIT_TESTMODE 0x0D73010D /* cmd */
43#define CMDTHREAD_VENDOR_WRITE_BBP 0x0D730119 /* cmd */
44#define CMDTHREAD_VENDOR_READ_BBP 0x0D730118 /* cmd */
45#define CMDTHREAD_VENDOR_WRITE_RF 0x0D73011A /* cmd */
46#define CMDTHREAD_VENDOR_FLIP_IQ 0x0D73011D /* cmd */
47#define CMDTHREAD_RESET_BULK_OUT 0x0D730210 /* cmd */
48#define CMDTHREAD_RESET_BULK_IN 0x0D730211 /* cmd */
49#define CMDTHREAD_SET_PSM_BIT 0x0D730212 /* cmd */
50#define CMDTHREAD_SET_RADIO 0x0D730214 /* cmd */
51#define CMDTHREAD_UPDATE_TX_RATE 0x0D730216 /* cmd */
52#define CMDTHREAD_802_11_ADD_KEY_WEP 0x0D730218 /* cmd */
53#define CMDTHREAD_RESET_FROM_ERROR 0x0D73021A /* cmd */
54#define CMDTHREAD_LINK_DOWN 0x0D73021B /* cmd */
55#define CMDTHREAD_RESET_FROM_NDIS 0x0D73021C /* cmd */
56#define CMDTHREAD_CHECK_GPIO 0x0D730215 /* cmd */
57#define CMDTHREAD_FORCE_WAKE_UP 0x0D730222 /* cmd */
58#define CMDTHREAD_SET_BW 0x0D730225 /* cmd */
59#define CMDTHREAD_SET_ASIC_WCID 0x0D730226 /* cmd */
60#define CMDTHREAD_SET_ASIC_WCID_CIPHER 0x0D730227 /* cmd */
61#define CMDTHREAD_QKERIODIC_EXECUT 0x0D73023D /* cmd */
62#define RT_CMD_SET_KEY_TABLE 0x0D730228 /* cmd */
63#define RT_CMD_SET_RX_WCID_TABLE 0x0D730229 /* cmd */
64#define CMDTHREAD_SET_CLIENT_MAC_ENTRY 0x0D73023E /* cmd */
65#define CMDTHREAD_SET_GROUP_KEY 0x0D73023F /* cmd */
66#define CMDTHREAD_SET_PAIRWISE_KEY 0x0D730240 /* cmd */
67
68#define CMDTHREAD_802_11_QUERY_HARDWARE_REGISTER 0x0D710105 /* cmd */
69#define CMDTHREAD_802_11_SET_PHY_MODE 0x0D79010C /* cmd */
70#define CMDTHREAD_802_11_SET_STA_CONFIG 0x0D790111 /* cmd */
71#define CMDTHREAD_802_11_SET_PREAMBLE 0x0D790101 /* cmd */
72#define CMDTHREAD_802_11_COUNTER_MEASURE 0x0D790102 /* cmd */
73/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */
74#define CMDTHREAD_UPDATE_PROTECT 0x0D790103 /* cmd */
75/* end johnli */
76
77/*CMDTHREAD_MULTI_READ_MAC */
78/*CMDTHREAD_MULTI_WRITE_MAC */
79/*CMDTHREAD_VENDOR_EEPROM_READ */
80/*CMDTHREAD_VENDOR_EEPROM_WRITE */
81struct rt_cmdhandler_tlv {
82 u16 Offset;
83 u16 Length;
84 u8 DataFirst;
85};
86
87struct rt_cmdqelmt;
88
89struct rt_cmdqelmt {
90 u32 command;
91 void *buffer;
92 unsigned long bufferlength;
93 BOOLEAN CmdFromNdis;
94 BOOLEAN SetOperation;
95 struct rt_cmdqelmt *next;
96};
97
98struct rt_cmdq {
99 u32 size;
100 struct rt_cmdqelmt *head;
101 struct rt_cmdqelmt *tail;
102 u32 CmdQState;
103};
104
105#define EnqueueCmd(cmdq, cmdqelmt) \
106{ \
107 if (cmdq->size == 0) \
108 cmdq->head = cmdqelmt; \
109 else \
110 cmdq->tail->next = cmdqelmt; \
111 cmdq->tail = cmdqelmt; \
112 cmdqelmt->next = NULL; \
113 cmdq->size++; \
114}
115
116/******************************************************************************
117
118 USB Cmd to ASIC Related MACRO
119
120******************************************************************************/
121/* reset MAC of a station entry to 0xFFFFFFFFFFFF */
122#define RTMP_STA_ENTRY_MAC_RESET(pAd, Wcid) \
123 { struct rt_set_asic_wcid SetAsicWcid; \
124 SetAsicWcid.WCID = Wcid; \
125 SetAsicWcid.SetTid = 0xffffffff; \
126 SetAsicWcid.DeleteTid = 0xffffffff; \
127 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID, \
128 &SetAsicWcid, sizeof(struct rt_set_asic_wcid)); }
129
130/* add this entry into ASIC RX WCID search table */
131#define RTMP_STA_ENTRY_ADD(pAd, pEntry) \
132 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_CLIENT_MAC_ENTRY, \
133 pEntry, sizeof(struct rt_mac_table_entry));
134
135/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */
136/* Set MAC register value according operation mode */
137#define RTMP_UPDATE_PROTECT(pAd) \
138 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_UPDATE_PROTECT, NULL, 0);
139/* end johnli */
140
141/* remove Pair-wise key material from ASIC */
142/* yet implement */
143#define RTMP_STA_ENTRY_KEY_DEL(pAd, BssIdx, Wcid)
144
145/* add Client security information into ASIC WCID table and IVEIV table */
146#define RTMP_STA_SECURITY_INFO_ADD(pAd, apidx, KeyID, pEntry) \
147 { RTMP_STA_ENTRY_MAC_RESET(pAd, pEntry->Aid); \
148 if (pEntry->Aid >= 1) { \
149 struct rt_set_asic_wcid_attri SetAsicWcidAttri; \
150 SetAsicWcidAttri.WCID = pEntry->Aid; \
151 if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) && \
152 (pEntry->WepStatus == Ndis802_11Encryption1Enabled)) \
153 { \
154 SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg; \
155 } \
156 else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone) \
157 { \
158 SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg; \
159 } \
160 else SetAsicWcidAttri.Cipher = 0; \
161 DBGPRINT(RT_DEBUG_TRACE, ("aid cipher = %ld\n",SetAsicWcidAttri.Cipher)); \
162 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID_CIPHER, \
163 &SetAsicWcidAttri, sizeof(struct rt_set_asic_wcid_attri)); } }
164
165/* Insert the BA bitmap to ASIC for the Wcid entry */
166#define RTMP_ADD_BA_SESSION_TO_ASIC(_pAd, _Aid, _TID) \
167 do{ \
168 struct rt_set_asic_wcid SetAsicWcid; \
169 SetAsicWcid.WCID = (_Aid); \
170 SetAsicWcid.SetTid = (0x10000<<(_TID)); \
171 SetAsicWcid.DeleteTid = 0xffffffff; \
172 RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(struct rt_set_asic_wcid)); \
173 }while(0)
174
175/* Remove the BA bitmap from ASIC for the Wcid entry */
176#define RTMP_DEL_BA_SESSION_FROM_ASIC(_pAd, _Wcid, _TID) \
177 do{ \
178 struct rt_set_asic_wcid SetAsicWcid; \
179 SetAsicWcid.WCID = (_Wcid); \
180 SetAsicWcid.SetTid = (0xffffffff); \
181 SetAsicWcid.DeleteTid = (0x10000<<(_TID) ); \
182 RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(struct rt_set_asic_wcid)); \
183 }while(0)
184
185#endif /* __RTUSB_IO_H__ // */
diff --git a/drivers/staging/rt2860/spectrum.h b/drivers/staging/rt2860/spectrum.h
deleted file mode 100644
index 4c325ba7ba2..00000000000
--- a/drivers/staging/rt2860/spectrum.h
+++ /dev/null
@@ -1,189 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26 */
27
28#ifndef __SPECTRUM_H__
29#define __SPECTRUM_H__
30
31#include "rtmp_type.h"
32#include "spectrum_def.h"
33
34char RTMP_GetTxPwr(struct rt_rtmp_adapter *pAd, IN HTTRANSMIT_SETTING HTTxMode);
35
36/*
37 ==========================================================================
38 Description:
39 Prepare Measurement request action frame and enqueue it into
40 management queue waiting for transmission.
41
42 Parametrs:
43 1. the destination mac address of the frame.
44
45 Return : None.
46 ==========================================================================
47 */
48void MakeMeasurementReqFrame(struct rt_rtmp_adapter *pAd,
49 u8 *pOutBuffer,
50 unsigned long *pFrameLen,
51 u8 TotalLen,
52 u8 Category,
53 u8 Action,
54 u8 MeasureToken,
55 u8 MeasureReqMode,
56 u8 MeasureReqType,
57 u8 NumOfRepetitions);
58
59/*
60 ==========================================================================
61 Description:
62 Prepare Measurement report action frame and enqueue it into
63 management queue waiting for transmission.
64
65 Parametrs:
66 1. the destination mac address of the frame.
67
68 Return : None.
69 ==========================================================================
70 */
71void EnqueueMeasurementRep(struct rt_rtmp_adapter *pAd,
72 u8 *pDA,
73 u8 DialogToken,
74 u8 MeasureToken,
75 u8 MeasureReqMode,
76 u8 MeasureReqType,
77 u8 ReportInfoLen, u8 *pReportInfo);
78
79/*
80 ==========================================================================
81 Description:
82 Prepare TPC Request action frame and enqueue it into
83 management queue waiting for transmission.
84
85 Parametrs:
86 1. the destination mac address of the frame.
87
88 Return : None.
89 ==========================================================================
90 */
91void EnqueueTPCReq(struct rt_rtmp_adapter *pAd, u8 *pDA, u8 DialogToken);
92
93/*
94 ==========================================================================
95 Description:
96 Prepare TPC Report action frame and enqueue it into
97 management queue waiting for transmission.
98
99 Parametrs:
100 1. the destination mac address of the frame.
101
102 Return : None.
103 ==========================================================================
104 */
105void EnqueueTPCRep(struct rt_rtmp_adapter *pAd,
106 u8 *pDA,
107 u8 DialogToken, u8 TxPwr, u8 LinkMargin);
108
109/*
110 ==========================================================================
111 Description:
112 Prepare Channel Switch Announcement action frame and enqueue it into
113 management queue waiting for transmission.
114
115 Parametrs:
116 1. the destination mac address of the frame.
117 2. Channel switch announcement mode.
118 2. a New selected channel.
119
120 Return : None.
121 ==========================================================================
122 */
123void EnqueueChSwAnn(struct rt_rtmp_adapter *pAd,
124 u8 *pDA, u8 ChSwMode, u8 NewCh);
125
126/*
127 ==========================================================================
128 Description:
129 Spectrun action frames Handler such as channel switch announcement,
130 measurement report, measurement request actions frames.
131
132 Parametrs:
133 Elme - MLME message containing the received frame
134
135 Return : None.
136 ==========================================================================
137 */
138void PeerSpectrumAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem);
139
140/*
141 ==========================================================================
142 Description:
143
144 Parametrs:
145
146 Return : None.
147 ==========================================================================
148 */
149int Set_MeasureReq_Proc(struct rt_rtmp_adapter *pAd, char *arg);
150
151int Set_TpcReq_Proc(struct rt_rtmp_adapter *pAd, char *arg);
152
153int Set_PwrConstraint(struct rt_rtmp_adapter *pAd, char *arg);
154
155void MeasureReqTabInit(struct rt_rtmp_adapter *pAd);
156
157void MeasureReqTabExit(struct rt_rtmp_adapter *pAd);
158
159struct rt_measure_req_entry *MeasureReqLookUp(struct rt_rtmp_adapter *pAd, u8 DialogToken);
160
161struct rt_measure_req_entry *MeasureReqInsert(struct rt_rtmp_adapter *pAd, u8 DialogToken);
162
163void MeasureReqDelete(struct rt_rtmp_adapter *pAd, u8 DialogToken);
164
165void InsertChannelRepIE(struct rt_rtmp_adapter *pAd,
166 u8 *pFrameBuf,
167 unsigned long *pFrameLen,
168 char *pCountry, u8 RegulatoryClass);
169
170void InsertTpcReportIE(struct rt_rtmp_adapter *pAd,
171 u8 *pFrameBuf,
172 unsigned long *pFrameLen,
173 u8 TxPwr, u8 LinkMargin);
174
175void InsertDialogToken(struct rt_rtmp_adapter *pAd,
176 u8 *pFrameBuf,
177 unsigned long *pFrameLen, u8 DialogToken);
178
179void TpcReqTabInit(struct rt_rtmp_adapter *pAd);
180
181void TpcReqTabExit(struct rt_rtmp_adapter *pAd);
182
183void NotifyChSwAnnToPeerAPs(struct rt_rtmp_adapter *pAd,
184 u8 *pRA,
185 u8 *pTA, u8 ChSwMode, u8 Channel);
186
187void RguClass_BuildBcnChList(struct rt_rtmp_adapter *pAd,
188 u8 *pBuf, unsigned long *pBufLen);
189#endif /* __SPECTRUM_H__ // */
diff --git a/drivers/staging/rt2860/spectrum_def.h b/drivers/staging/rt2860/spectrum_def.h
deleted file mode 100644
index 8ffcfb0d04f..00000000000
--- a/drivers/staging/rt2860/spectrum_def.h
+++ /dev/null
@@ -1,202 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 spectrum_def.h
29
30 Abstract:
31 Handle association related requests either from WSTA or from local MLME
32
33 Revision History:
34 Who When What
35 --------- ---------- ----------------------------------------------
36 Fonchi Wu 2008 created for 802.11h
37 */
38
39#ifndef __SPECTRUM_DEF_H__
40#define __SPECTRUM_DEF_H__
41
42#define MAX_MEASURE_REQ_TAB_SIZE 32
43#define MAX_HASH_MEASURE_REQ_TAB_SIZE MAX_MEASURE_REQ_TAB_SIZE
44
45#define MAX_TPC_REQ_TAB_SIZE 32
46#define MAX_HASH_TPC_REQ_TAB_SIZE MAX_TPC_REQ_TAB_SIZE
47
48#define MIN_RCV_PWR 100 /* Negative value ((dBm) */
49
50#define TPC_REQ_AGE_OUT 500 /* ms */
51#define MQ_REQ_AGE_OUT 500 /* ms */
52
53#define TPC_DIALOGTOKEN_HASH_INDEX(_DialogToken) ((_DialogToken) % MAX_HASH_TPC_REQ_TAB_SIZE)
54#define MQ_DIALOGTOKEN_HASH_INDEX(_DialogToken) ((_DialogToken) % MAX_MEASURE_REQ_TAB_SIZE)
55
56struct rt_measure_req_entry;
57
58struct rt_measure_req_entry {
59 struct rt_measure_req_entry *pNext;
60 unsigned long lastTime;
61 BOOLEAN Valid;
62 u8 DialogToken;
63 u8 MeasureDialogToken[3]; /* 0:basic measure, 1: CCA measure, 2: RPI_Histogram measure. */
64};
65
66struct rt_measure_req_tab {
67 u8 Size;
68 struct rt_measure_req_entry *Hash[MAX_HASH_MEASURE_REQ_TAB_SIZE];
69 struct rt_measure_req_entry Content[MAX_MEASURE_REQ_TAB_SIZE];
70};
71
72struct rt_tpc_req_entry;
73
74struct rt_tpc_req_entry {
75 struct rt_tpc_req_entry *pNext;
76 unsigned long lastTime;
77 BOOLEAN Valid;
78 u8 DialogToken;
79};
80
81struct rt_tpc_req_tab {
82 u8 Size;
83 struct rt_tpc_req_entry *Hash[MAX_HASH_TPC_REQ_TAB_SIZE];
84 struct rt_tpc_req_entry Content[MAX_TPC_REQ_TAB_SIZE];
85};
86
87/* The regulatory information */
88struct rt_dot11_channel_set {
89 u8 NumberOfChannels;
90 u8 MaxTxPwr;
91 u8 ChannelList[16];
92};
93
94struct rt_dot11_regulatory_information {
95 u8 RegulatoryClass;
96 struct rt_dot11_channel_set ChannelSet;
97};
98
99#define RM_TPC_REQ 0
100#define RM_MEASURE_REQ 1
101
102#define RM_BASIC 0
103#define RM_CCA 1
104#define RM_RPI_HISTOGRAM 2
105#define RM_CH_LOAD 3
106#define RM_NOISE_HISTOGRAM 4
107
108struct PACKED rt_tpc_report_info {
109 u8 TxPwr;
110 u8 LinkMargin;
111};
112
113struct PACKED rt_ch_sw_ann_info {
114 u8 ChSwMode;
115 u8 Channel;
116 u8 ChSwCnt;
117};
118
119typedef union PACKED _MEASURE_REQ_MODE {
120 struct PACKED {
121 u8 Parallel:1;
122 u8 Enable:1;
123 u8 Request:1;
124 u8 Report:1;
125 u8 DurationMandatory:1;
126 u8:3;
127 } field;
128 u8 word;
129} MEASURE_REQ_MODE, *PMEASURE_REQ_MODE;
130
131struct PACKED rt_measure_req {
132 u8 ChNum;
133 u64 MeasureStartTime;
134 u16 MeasureDuration;
135};
136
137struct PACKED rt_measure_req_info {
138 u8 Token;
139 MEASURE_REQ_MODE ReqMode;
140 u8 ReqType;
141 u8 Oct[0];
142};
143
144typedef union PACKED _MEASURE_BASIC_REPORT_MAP {
145 struct PACKED {
146 u8 BSS:1;
147
148 u8 OfdmPreamble:1;
149 u8 UnidentifiedSignal:1;
150 u8 Radar:1;
151 u8 Unmeasure:1;
152 u8 Rev:3;
153 } field;
154 u8 word;
155} MEASURE_BASIC_REPORT_MAP, *PMEASURE_BASIC_REPORT_MAP;
156
157struct PACKED rt_measure_basic_report {
158 u8 ChNum;
159 u64 MeasureStartTime;
160 u16 MeasureDuration;
161 MEASURE_BASIC_REPORT_MAP Map;
162};
163
164struct PACKED rt_measure_cca_report {
165 u8 ChNum;
166 u64 MeasureStartTime;
167 u16 MeasureDuration;
168 u8 CCA_Busy_Fraction;
169};
170
171struct PACKED rt_measure_rpi_report {
172 u8 ChNum;
173 u64 MeasureStartTime;
174 u16 MeasureDuration;
175 u8 RPI_Density[8];
176};
177
178typedef union PACKED _MEASURE_REPORT_MODE {
179 struct PACKED {
180 u8 Late:1;
181 u8 Incapable:1;
182 u8 Refused:1;
183 u8 Rev:5;
184 } field;
185 u8 word;
186} MEASURE_REPORT_MODE, *PMEASURE_REPORT_MODE;
187
188struct PACKED rt_measure_report_info {
189 u8 Token;
190 u8 ReportMode;
191 u8 ReportType;
192 u8 Octect[0];
193};
194
195struct PACKED rt_quiet_info {
196 u8 QuietCnt;
197 u8 QuietPeriod;
198 u16 QuietDuration;
199 u16 QuietOffset;
200};
201
202#endif /* __SPECTRUM_DEF_H__ // */
diff --git a/drivers/staging/rt2860/sta/assoc.c b/drivers/staging/rt2860/sta/assoc.c
deleted file mode 100644
index 59e931c3190..00000000000
--- a/drivers/staging/rt2860/sta/assoc.c
+++ /dev/null
@@ -1,1602 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 assoc.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John 2004-9-3 porting from RT2500
36 Justin P. Mattock 11/07/2010 Fix typos
37*/
38#include "../rt_config.h"
39
40u8 CipherWpaTemplate[] = {
41 0xdd, /* WPA IE */
42 0x16, /* Length */
43 0x00, 0x50, 0xf2, 0x01, /* oui */
44 0x01, 0x00, /* Version */
45 0x00, 0x50, 0xf2, 0x02, /* Multicast */
46 0x01, 0x00, /* Number of unicast */
47 0x00, 0x50, 0xf2, 0x02, /* unicast */
48 0x01, 0x00, /* number of authentication method */
49 0x00, 0x50, 0xf2, 0x01 /* authentication */
50};
51
52u8 CipherWpa2Template[] = {
53 0x30, /* RSN IE */
54 0x14, /* Length */
55 0x01, 0x00, /* Version */
56 0x00, 0x0f, 0xac, 0x02, /* group cipher, TKIP */
57 0x01, 0x00, /* number of pairwise */
58 0x00, 0x0f, 0xac, 0x02, /* unicast */
59 0x01, 0x00, /* number of authentication method */
60 0x00, 0x0f, 0xac, 0x02, /* authentication */
61 0x00, 0x00, /* RSN capability */
62};
63
64u8 Ccx2IeInfo[] = { 0x00, 0x40, 0x96, 0x03, 0x02 };
65
66/*
67 ==========================================================================
68 Description:
69 association state machine init, including state transition and timer init
70 Parameters:
71 S - pointer to the association state machine
72
73 IRQL = PASSIVE_LEVEL
74
75 ==========================================================================
76 */
77void AssocStateMachineInit(struct rt_rtmp_adapter *pAd,
78 struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[])
79{
80 StateMachineInit(S, Trans, MAX_ASSOC_STATE, MAX_ASSOC_MSG,
81 (STATE_MACHINE_FUNC) Drop, ASSOC_IDLE,
82 ASSOC_MACHINE_BASE);
83
84 /* first column */
85 StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_ASSOC_REQ,
86 (STATE_MACHINE_FUNC) MlmeAssocReqAction);
87 StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_REASSOC_REQ,
88 (STATE_MACHINE_FUNC) MlmeReassocReqAction);
89 StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_DISASSOC_REQ,
90 (STATE_MACHINE_FUNC) MlmeDisassocReqAction);
91 StateMachineSetAction(S, ASSOC_IDLE, MT2_PEER_DISASSOC_REQ,
92 (STATE_MACHINE_FUNC) PeerDisassocAction);
93
94 /* second column */
95 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ,
96 (STATE_MACHINE_FUNC) InvalidStateWhenAssoc);
97 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ,
98 (STATE_MACHINE_FUNC) InvalidStateWhenReassoc);
99 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ,
100 (STATE_MACHINE_FUNC)
101 InvalidStateWhenDisassociate);
102 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ,
103 (STATE_MACHINE_FUNC) PeerDisassocAction);
104 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP,
105 (STATE_MACHINE_FUNC) PeerAssocRspAction);
106 /* */
107 /* Patch 3Com AP MOde:3CRWE454G72 */
108 /* We send Assoc request frame to this AP, it always send Reassoc Rsp not Associate Rsp. */
109 /* */
110 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP,
111 (STATE_MACHINE_FUNC) PeerAssocRspAction);
112 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_ASSOC_TIMEOUT,
113 (STATE_MACHINE_FUNC) AssocTimeoutAction);
114
115 /* third column */
116 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ,
117 (STATE_MACHINE_FUNC) InvalidStateWhenAssoc);
118 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ,
119 (STATE_MACHINE_FUNC) InvalidStateWhenReassoc);
120 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ,
121 (STATE_MACHINE_FUNC)
122 InvalidStateWhenDisassociate);
123 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ,
124 (STATE_MACHINE_FUNC) PeerDisassocAction);
125 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP,
126 (STATE_MACHINE_FUNC) PeerReassocRspAction);
127 /* */
128 /* Patch, AP doesn't send Reassociate Rsp frame to Station. */
129 /* */
130 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP,
131 (STATE_MACHINE_FUNC) PeerReassocRspAction);
132 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_REASSOC_TIMEOUT,
133 (STATE_MACHINE_FUNC) ReassocTimeoutAction);
134
135 /* fourth column */
136 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ,
137 (STATE_MACHINE_FUNC) InvalidStateWhenAssoc);
138 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ,
139 (STATE_MACHINE_FUNC) InvalidStateWhenReassoc);
140 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ,
141 (STATE_MACHINE_FUNC)
142 InvalidStateWhenDisassociate);
143 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ,
144 (STATE_MACHINE_FUNC) PeerDisassocAction);
145 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_DISASSOC_TIMEOUT,
146 (STATE_MACHINE_FUNC) DisassocTimeoutAction);
147
148 /* initialize the timer */
149 RTMPInitTimer(pAd, &pAd->MlmeAux.AssocTimer,
150 GET_TIMER_FUNCTION(AssocTimeout), pAd, FALSE);
151 RTMPInitTimer(pAd, &pAd->MlmeAux.ReassocTimer,
152 GET_TIMER_FUNCTION(ReassocTimeout), pAd, FALSE);
153 RTMPInitTimer(pAd, &pAd->MlmeAux.DisassocTimer,
154 GET_TIMER_FUNCTION(DisassocTimeout), pAd, FALSE);
155}
156
157/*
158 ==========================================================================
159 Description:
160 Association timeout procedure. After association timeout, this function
161 will be called and it will put a message into the MLME queue
162 Parameters:
163 Standard timer parameters
164
165 IRQL = DISPATCH_LEVEL
166
167 ==========================================================================
168 */
169void AssocTimeout(void *SystemSpecific1,
170 void *FunctionContext,
171 void *SystemSpecific2, void *SystemSpecific3)
172{
173 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
174
175 /* Do nothing if the driver is starting halt state. */
176 /* This might happen when timer already been fired before cancel timer with mlmehalt */
177 if (RTMP_TEST_FLAG
178 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
179 return;
180
181 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_ASSOC_TIMEOUT, 0, NULL);
182 RTMP_MLME_HANDLER(pAd);
183}
184
185/*
186 ==========================================================================
187 Description:
188 Reassociation timeout procedure. After reassociation timeout, this
189 function will be called and put a message into the MLME queue
190 Parameters:
191 Standard timer parameters
192
193 IRQL = DISPATCH_LEVEL
194
195 ==========================================================================
196 */
197void ReassocTimeout(void *SystemSpecific1,
198 void *FunctionContext,
199 void *SystemSpecific2, void *SystemSpecific3)
200{
201 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
202
203 /* Do nothing if the driver is starting halt state. */
204 /* This might happen when timer already been fired before cancel timer with mlmehalt */
205 if (RTMP_TEST_FLAG
206 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
207 return;
208
209 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_REASSOC_TIMEOUT, 0, NULL);
210 RTMP_MLME_HANDLER(pAd);
211}
212
213/*
214 ==========================================================================
215 Description:
216 Disassociation timeout procedure. After disassociation timeout, this
217 function will be called and put a message into the MLME queue
218 Parameters:
219 Standard timer parameters
220
221 IRQL = DISPATCH_LEVEL
222
223 ==========================================================================
224 */
225void DisassocTimeout(void *SystemSpecific1,
226 void *FunctionContext,
227 void *SystemSpecific2, void *SystemSpecific3)
228{
229 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
230
231 /* Do nothing if the driver is starting halt state. */
232 /* This might happen when timer already been fired before cancel timer with mlmehalt */
233 if (RTMP_TEST_FLAG
234 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
235 return;
236
237 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_DISASSOC_TIMEOUT, 0, NULL);
238 RTMP_MLME_HANDLER(pAd);
239}
240
241/*
242 ==========================================================================
243 Description:
244 mlme assoc req handling procedure
245 Parameters:
246 Adapter - Adapter pointer
247 Elem - MLME Queue Element
248 Pre:
249 the station has been authenticated and the following information is stored in the config
250 -# SSID
251 -# supported rates and their length
252 -# listen interval (Adapter->StaCfg.default_listen_count)
253 -# Transmit power (Adapter->StaCfg.tx_power)
254 Post :
255 -# An association request frame is generated and sent to the air
256 -# Association timer starts
257 -# Association state -> ASSOC_WAIT_RSP
258
259 IRQL = DISPATCH_LEVEL
260
261 ==========================================================================
262 */
263void MlmeAssocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
264{
265 u8 ApAddr[6];
266 struct rt_header_802_11 AssocHdr;
267 u8 WmeIe[9] =
268 { IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01,
269 0x00 };
270 u16 ListenIntv;
271 unsigned long Timeout;
272 u16 CapabilityInfo;
273 BOOLEAN TimerCancelled;
274 u8 *pOutBuffer = NULL;
275 int NStatus;
276 unsigned long FrameLen = 0;
277 unsigned long tmp;
278 u16 VarIesOffset;
279 u16 Status;
280
281 /* Block all authentication request during WPA block period */
282 if (pAd->StaCfg.bBlockAssoc == TRUE) {
283 DBGPRINT(RT_DEBUG_TRACE,
284 ("ASSOC - Block Assoc request during WPA block period!\n"));
285 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
286 Status = MLME_STATE_MACHINE_REJECT;
287 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2,
288 &Status);
289 }
290 /* check sanity first */
291 else if (MlmeAssocReqSanity
292 (pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo,
293 &Timeout, &ListenIntv)) {
294 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);
295 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
296
297 /* Get an unused nonpaged memory */
298 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
299 if (NStatus != NDIS_STATUS_SUCCESS) {
300 DBGPRINT(RT_DEBUG_TRACE,
301 ("ASSOC - MlmeAssocReqAction() allocate memory failed \n"));
302 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
303 Status = MLME_FAIL_NO_RESOURCE;
304 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
305 MT2_ASSOC_CONF, 2, &Status);
306 return;
307 }
308 /* Add by James 03/06/27 */
309 pAd->StaCfg.AssocInfo.Length =
310 sizeof(struct rt_ndis_802_11_association_information);
311 /* Association don't need to report MAC address */
312 pAd->StaCfg.AssocInfo.AvailableRequestFixedIEs =
313 NDIS_802_11_AI_REQFI_CAPABILITIES |
314 NDIS_802_11_AI_REQFI_LISTENINTERVAL;
315 pAd->StaCfg.AssocInfo.RequestFixedIEs.Capabilities =
316 CapabilityInfo;
317 pAd->StaCfg.AssocInfo.RequestFixedIEs.ListenInterval =
318 ListenIntv;
319 /* Only reassociate need this */
320 /*COPY_MAC_ADDR(pAd->StaCfg.AssocInfo.RequestFixedIEs.CurrentAPAddress, ApAddr); */
321 pAd->StaCfg.AssocInfo.OffsetRequestIEs =
322 sizeof(struct rt_ndis_802_11_association_information);
323
324 NdisZeroMemory(pAd->StaCfg.ReqVarIEs, MAX_VIE_LEN);
325 /* First add SSID */
326 VarIesOffset = 0;
327 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SsidIe,
328 1);
329 VarIesOffset += 1;
330 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
331 &pAd->MlmeAux.SsidLen, 1);
332 VarIesOffset += 1;
333 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
334 pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
335 VarIesOffset += pAd->MlmeAux.SsidLen;
336
337 /* Second add Supported rates */
338 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SupRateIe,
339 1);
340 VarIesOffset += 1;
341 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
342 &pAd->MlmeAux.SupRateLen, 1);
343 VarIesOffset += 1;
344 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
345 pAd->MlmeAux.SupRate, pAd->MlmeAux.SupRateLen);
346 VarIesOffset += pAd->MlmeAux.SupRateLen;
347 /* End Add by James */
348
349 if ((pAd->CommonCfg.Channel > 14) &&
350 (pAd->CommonCfg.bIEEE80211H == TRUE))
351 CapabilityInfo |= 0x0100;
352
353 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send ASSOC request...\n"));
354 MgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, ApAddr,
355 ApAddr);
356
357 /* Build basic frame first */
358 MakeOutgoingFrame(pOutBuffer, &FrameLen,
359 sizeof(struct rt_header_802_11), &AssocHdr,
360 2, &CapabilityInfo,
361 2, &ListenIntv,
362 1, &SsidIe,
363 1, &pAd->MlmeAux.SsidLen,
364 pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
365 1, &SupRateIe,
366 1, &pAd->MlmeAux.SupRateLen,
367 pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
368 END_OF_ARGS);
369
370 if (pAd->MlmeAux.ExtRateLen != 0) {
371 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
372 1, &ExtRateIe,
373 1, &pAd->MlmeAux.ExtRateLen,
374 pAd->MlmeAux.ExtRateLen,
375 pAd->MlmeAux.ExtRate, END_OF_ARGS);
376 FrameLen += tmp;
377 }
378 /* HT */
379 if ((pAd->MlmeAux.HtCapabilityLen > 0)
380 && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
381 unsigned long TmpLen;
382 u8 HtLen;
383 u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 };
384 if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE) {
385 HtLen = SIZE_HT_CAP_IE + 4;
386 MakeOutgoingFrame(pOutBuffer + FrameLen,
387 &TmpLen, 1, &WpaIe, 1, &HtLen,
388 4, &BROADCOM[0],
389 pAd->MlmeAux.HtCapabilityLen,
390 &pAd->MlmeAux.HtCapability,
391 END_OF_ARGS);
392 } else {
393 MakeOutgoingFrame(pOutBuffer + FrameLen,
394 &TmpLen, 1, &HtCapIe, 1,
395 &pAd->MlmeAux.HtCapabilityLen,
396 pAd->MlmeAux.HtCapabilityLen,
397 &pAd->MlmeAux.HtCapability,
398 END_OF_ARGS);
399 }
400 FrameLen += TmpLen;
401 }
402 /* add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION */
403 /* Case I: (Aggregation + Piggy-Back) */
404 /* 1. user enable aggregation, AND */
405 /* 2. Mac support piggy-back */
406 /* 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON */
407 /* Case II: (Aggregation) */
408 /* 1. user enable aggregation, AND */
409 /* 2. AP annouces it's AGGREGATION-capable in BEACON */
410 if (pAd->CommonCfg.bAggregationCapable) {
411 if ((pAd->CommonCfg.bPiggyBackCapable)
412 && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)) {
413 unsigned long TmpLen;
414 u8 RalinkIe[9] =
415 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43,
416 0x03, 0x00, 0x00, 0x00 };
417 MakeOutgoingFrame(pOutBuffer + FrameLen,
418 &TmpLen, 9, RalinkIe,
419 END_OF_ARGS);
420 FrameLen += TmpLen;
421 } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) {
422 unsigned long TmpLen;
423 u8 RalinkIe[9] =
424 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43,
425 0x01, 0x00, 0x00, 0x00 };
426 MakeOutgoingFrame(pOutBuffer + FrameLen,
427 &TmpLen, 9, RalinkIe,
428 END_OF_ARGS);
429 FrameLen += TmpLen;
430 }
431 } else {
432 unsigned long TmpLen;
433 u8 RalinkIe[9] =
434 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x06,
435 0x00, 0x00, 0x00 };
436 MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen, 9,
437 RalinkIe, END_OF_ARGS);
438 FrameLen += TmpLen;
439 }
440
441 if (pAd->MlmeAux.APEdcaParm.bValid) {
442 if (pAd->CommonCfg.bAPSDCapable
443 && pAd->MlmeAux.APEdcaParm.bAPSDCapable) {
444 struct rt_qbss_sta_info_parm QosInfo;
445
446 NdisZeroMemory(&QosInfo,
447 sizeof(struct rt_qbss_sta_info_parm));
448 QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;
449 QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;
450 QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;
451 QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;
452 QosInfo.MaxSPLength =
453 pAd->CommonCfg.MaxSPLength;
454 WmeIe[8] |= *(u8 *)& QosInfo;
455 } else {
456 /* The Parameter Set Count is set to ¡§0¡¨ in the association request frames */
457 /* WmeIe[8] |= (pAd->MlmeAux.APEdcaParm.EdcaUpdateCount & 0x0f); */
458 }
459
460 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
461 9, &WmeIe[0], END_OF_ARGS);
462 FrameLen += tmp;
463 }
464 /* */
465 /* Let WPA(#221) Element ID on the end of this association frame. */
466 /* Otherwise some AP will fail on parsing Element ID and set status fail on Assoc Rsp. */
467 /* For example: Put Vendor Specific IE on the front of WPA IE. */
468 /* This happens on AP (Model No:Linksys WRK54G) */
469 /* */
470 if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
471 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
472 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
473 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
474 )
475 ) {
476 u8 RSNIe = IE_WPA;
477
478 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
479 || (pAd->StaCfg.AuthMode ==
480 Ndis802_11AuthModeWPA2)) {
481 RSNIe = IE_WPA2;
482 }
483
484 if ((pAd->StaCfg.WpaSupplicantUP !=
485 WPA_SUPPLICANT_ENABLE)
486 && (pAd->StaCfg.bRSN_IE_FromWpaSupplicant == FALSE))
487 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode,
488 pAd->StaCfg.WepStatus, BSS0);
489
490 /* Check for WPA PMK cache list */
491 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) {
492 int idx;
493 BOOLEAN FoundPMK = FALSE;
494 /* Search chched PMKID, append it if existed */
495 for (idx = 0; idx < PMKID_NO; idx++) {
496 if (NdisEqualMemory
497 (ApAddr,
498 &pAd->StaCfg.SavedPMK[idx].BSSID,
499 6)) {
500 FoundPMK = TRUE;
501 break;
502 }
503 }
504 if (FoundPMK) {
505 /* Set PMK number */
506 *(u16 *)& pAd->StaCfg.RSN_IE[pAd->
507 StaCfg.
508 RSNIE_Len]
509 = 1;
510 NdisMoveMemory(&pAd->StaCfg.
511 RSN_IE[pAd->StaCfg.
512 RSNIE_Len + 2],
513 &pAd->StaCfg.
514 SavedPMK[idx].PMKID, 16);
515 pAd->StaCfg.RSNIE_Len += 18;
516 }
517 }
518
519 if ((pAd->StaCfg.WpaSupplicantUP ==
520 WPA_SUPPLICANT_ENABLE)
521 && (pAd->StaCfg.bRSN_IE_FromWpaSupplicant ==
522 TRUE)) {
523 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
524 pAd->StaCfg.RSNIE_Len,
525 pAd->StaCfg.RSN_IE,
526 END_OF_ARGS);
527 } else {
528 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
529 1, &RSNIe,
530 1, &pAd->StaCfg.RSNIE_Len,
531 pAd->StaCfg.RSNIE_Len,
532 pAd->StaCfg.RSN_IE,
533 END_OF_ARGS);
534 }
535
536 FrameLen += tmp;
537
538 if ((pAd->StaCfg.WpaSupplicantUP !=
539 WPA_SUPPLICANT_ENABLE)
540 || (pAd->StaCfg.bRSN_IE_FromWpaSupplicant ==
541 FALSE)) {
542 /* Append Variable IE */
543 NdisMoveMemory(pAd->StaCfg.ReqVarIEs +
544 VarIesOffset, &RSNIe, 1);
545 VarIesOffset += 1;
546 NdisMoveMemory(pAd->StaCfg.ReqVarIEs +
547 VarIesOffset,
548 &pAd->StaCfg.RSNIE_Len, 1);
549 VarIesOffset += 1;
550 }
551 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
552 pAd->StaCfg.RSN_IE,
553 pAd->StaCfg.RSNIE_Len);
554 VarIesOffset += pAd->StaCfg.RSNIE_Len;
555
556 /* Set Variable IEs Length */
557 pAd->StaCfg.ReqVarIELen = VarIesOffset;
558 }
559
560 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
561 MlmeFreeMemory(pAd, pOutBuffer);
562
563 RTMPSetTimer(&pAd->MlmeAux.AssocTimer, Timeout);
564 pAd->Mlme.AssocMachine.CurrState = ASSOC_WAIT_RSP;
565 } else {
566 DBGPRINT(RT_DEBUG_TRACE,
567 ("ASSOC - MlmeAssocReqAction() sanity check failed. BUG!\n"));
568 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
569 Status = MLME_INVALID_FORMAT;
570 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2,
571 &Status);
572 }
573
574}
575
576/*
577 ==========================================================================
578 Description:
579 mlme reassoc req handling procedure
580 Parameters:
581 Elem -
582 Pre:
583 -# SSID (Adapter->StaCfg.ssid[])
584 -# BSSID (AP address, Adapter->StaCfg.bssid)
585 -# Supported rates (Adapter->StaCfg.supported_rates[])
586 -# Supported rates length (Adapter->StaCfg.supported_rates_len)
587 -# Tx power (Adapter->StaCfg.tx_power)
588
589 IRQL = DISPATCH_LEVEL
590
591 ==========================================================================
592 */
593void MlmeReassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
594{
595 u8 ApAddr[6];
596 struct rt_header_802_11 ReassocHdr;
597 u8 WmeIe[9] =
598 { IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01,
599 0x00 };
600 u16 CapabilityInfo, ListenIntv;
601 unsigned long Timeout;
602 unsigned long FrameLen = 0;
603 BOOLEAN TimerCancelled;
604 int NStatus;
605 unsigned long tmp;
606 u8 *pOutBuffer = NULL;
607 u16 Status;
608
609 /* Block all authentication request during WPA block period */
610 if (pAd->StaCfg.bBlockAssoc == TRUE) {
611 DBGPRINT(RT_DEBUG_TRACE,
612 ("ASSOC - Block ReAssoc request during WPA block period!\n"));
613 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
614 Status = MLME_STATE_MACHINE_REJECT;
615 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2,
616 &Status);
617 }
618 /* the parameters are the same as the association */
619 else if (MlmeAssocReqSanity
620 (pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo,
621 &Timeout, &ListenIntv)) {
622 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled);
623
624 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
625 if (NStatus != NDIS_STATUS_SUCCESS) {
626 DBGPRINT(RT_DEBUG_TRACE,
627 ("ASSOC - MlmeReassocReqAction() allocate memory failed \n"));
628 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
629 Status = MLME_FAIL_NO_RESOURCE;
630 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
631 MT2_REASSOC_CONF, 2, &Status);
632 return;
633 }
634
635 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
636
637 /* make frame, use bssid as the AP address?? */
638 DBGPRINT(RT_DEBUG_TRACE,
639 ("ASSOC - Send RE-ASSOC request...\n"));
640 MgtMacHeaderInit(pAd, &ReassocHdr, SUBTYPE_REASSOC_REQ, 0,
641 ApAddr, ApAddr);
642 MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11),
643 &ReassocHdr, 2, &CapabilityInfo, 2,
644 &ListenIntv, MAC_ADDR_LEN, ApAddr, 1, &SsidIe,
645 1, &pAd->MlmeAux.SsidLen,
646 pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid, 1,
647 &SupRateIe, 1, &pAd->MlmeAux.SupRateLen,
648 pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
649 END_OF_ARGS);
650
651 if (pAd->MlmeAux.ExtRateLen != 0) {
652 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
653 1, &ExtRateIe,
654 1, &pAd->MlmeAux.ExtRateLen,
655 pAd->MlmeAux.ExtRateLen,
656 pAd->MlmeAux.ExtRate, END_OF_ARGS);
657 FrameLen += tmp;
658 }
659
660 if (pAd->MlmeAux.APEdcaParm.bValid) {
661 if (pAd->CommonCfg.bAPSDCapable
662 && pAd->MlmeAux.APEdcaParm.bAPSDCapable) {
663 struct rt_qbss_sta_info_parm QosInfo;
664
665 NdisZeroMemory(&QosInfo,
666 sizeof(struct rt_qbss_sta_info_parm));
667 QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;
668 QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;
669 QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;
670 QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;
671 QosInfo.MaxSPLength =
672 pAd->CommonCfg.MaxSPLength;
673 WmeIe[8] |= *(u8 *)& QosInfo;
674 }
675
676 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
677 9, &WmeIe[0], END_OF_ARGS);
678 FrameLen += tmp;
679 }
680 /* HT */
681 if ((pAd->MlmeAux.HtCapabilityLen > 0)
682 && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
683 unsigned long TmpLen;
684 u8 HtLen;
685 u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 };
686 if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE) {
687 HtLen = SIZE_HT_CAP_IE + 4;
688 MakeOutgoingFrame(pOutBuffer + FrameLen,
689 &TmpLen, 1, &WpaIe, 1, &HtLen,
690 4, &BROADCOM[0],
691 pAd->MlmeAux.HtCapabilityLen,
692 &pAd->MlmeAux.HtCapability,
693 END_OF_ARGS);
694 } else {
695 MakeOutgoingFrame(pOutBuffer + FrameLen,
696 &TmpLen, 1, &HtCapIe, 1,
697 &pAd->MlmeAux.HtCapabilityLen,
698 pAd->MlmeAux.HtCapabilityLen,
699 &pAd->MlmeAux.HtCapability,
700 END_OF_ARGS);
701 }
702 FrameLen += TmpLen;
703 }
704 /* add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION */
705 /* Case I: (Aggregation + Piggy-Back) */
706 /* 1. user enable aggregation, AND */
707 /* 2. Mac support piggy-back */
708 /* 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON */
709 /* Case II: (Aggregation) */
710 /* 1. user enable aggregation, AND */
711 /* 2. AP annouces it's AGGREGATION-capable in BEACON */
712 if (pAd->CommonCfg.bAggregationCapable) {
713 if ((pAd->CommonCfg.bPiggyBackCapable)
714 && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)) {
715 unsigned long TmpLen;
716 u8 RalinkIe[9] =
717 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43,
718 0x03, 0x00, 0x00, 0x00 };
719 MakeOutgoingFrame(pOutBuffer + FrameLen,
720 &TmpLen, 9, RalinkIe,
721 END_OF_ARGS);
722 FrameLen += TmpLen;
723 } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) {
724 unsigned long TmpLen;
725 u8 RalinkIe[9] =
726 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43,
727 0x01, 0x00, 0x00, 0x00 };
728 MakeOutgoingFrame(pOutBuffer + FrameLen,
729 &TmpLen, 9, RalinkIe,
730 END_OF_ARGS);
731 FrameLen += TmpLen;
732 }
733 } else {
734 unsigned long TmpLen;
735 u8 RalinkIe[9] =
736 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x04,
737 0x00, 0x00, 0x00 };
738 MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen, 9,
739 RalinkIe, END_OF_ARGS);
740 FrameLen += TmpLen;
741 }
742
743 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
744 MlmeFreeMemory(pAd, pOutBuffer);
745
746 RTMPSetTimer(&pAd->MlmeAux.ReassocTimer, Timeout); /* in mSec */
747 pAd->Mlme.AssocMachine.CurrState = REASSOC_WAIT_RSP;
748 } else {
749 DBGPRINT(RT_DEBUG_TRACE,
750 ("ASSOC - MlmeReassocReqAction() sanity check failed. BUG!\n"));
751 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
752 Status = MLME_INVALID_FORMAT;
753 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2,
754 &Status);
755 }
756}
757
758/*
759 ==========================================================================
760 Description:
761 Upper layer issues disassoc request
762 Parameters:
763 Elem -
764
765 IRQL = PASSIVE_LEVEL
766
767 ==========================================================================
768 */
769void MlmeDisassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
770{
771 struct rt_mlme_disassoc_req *pDisassocReq;
772 struct rt_header_802_11 DisassocHdr;
773 struct rt_header_802_11 * pDisassocHdr;
774 u8 *pOutBuffer = NULL;
775 unsigned long FrameLen = 0;
776 int NStatus;
777 BOOLEAN TimerCancelled;
778 unsigned long Timeout = 500;
779 u16 Status;
780
781 /* skip sanity check */
782 pDisassocReq = (struct rt_mlme_disassoc_req *)(Elem->Msg);
783
784 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
785 if (NStatus != NDIS_STATUS_SUCCESS) {
786 DBGPRINT(RT_DEBUG_TRACE,
787 ("ASSOC - MlmeDisassocReqAction() allocate memory failed\n"));
788 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
789 Status = MLME_FAIL_NO_RESOURCE;
790 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2,
791 &Status);
792 return;
793 }
794
795 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &TimerCancelled);
796
797 DBGPRINT(RT_DEBUG_TRACE,
798 ("ASSOC - Send DISASSOC request[BSSID::%pM (Reason=%d)\n",
799 pDisassocReq->Addr, pDisassocReq->Reason));
800 MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pDisassocReq->Addr, pDisassocReq->Addr); /* patch peap ttls switching issue */
801 MakeOutgoingFrame(pOutBuffer, &FrameLen,
802 sizeof(struct rt_header_802_11), &DisassocHdr,
803 2, &pDisassocReq->Reason, END_OF_ARGS);
804 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
805
806 /* To patch Instance and Buffalo(N) AP */
807 /* Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine */
808 /* Therefore, we send both of them. */
809 pDisassocHdr = (struct rt_header_802_11 *) pOutBuffer;
810 pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;
811 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
812
813 MlmeFreeMemory(pAd, pOutBuffer);
814
815 pAd->StaCfg.DisassocReason = REASON_DISASSOC_STA_LEAVING;
816 COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pDisassocReq->Addr);
817
818 RTMPSetTimer(&pAd->MlmeAux.DisassocTimer, Timeout); /* in mSec */
819 pAd->Mlme.AssocMachine.CurrState = DISASSOC_WAIT_RSP;
820
821 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, 0);
822
823}
824
825/*
826 ==========================================================================
827 Description:
828 peer sends assoc rsp back
829 Parameters:
830 Elme - MLME message containing the received frame
831
832 IRQL = DISPATCH_LEVEL
833
834 ==========================================================================
835 */
836void PeerAssocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
837{
838 u16 CapabilityInfo, Status, Aid;
839 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
840 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
841 u8 Addr2[MAC_ADDR_LEN];
842 BOOLEAN TimerCancelled;
843 u8 CkipFlag;
844 struct rt_edca_parm EdcaParm;
845 struct rt_ht_capability_ie HtCapability;
846 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
847 u8 HtCapabilityLen = 0;
848 u8 AddHtInfoLen;
849 u8 NewExtChannelOffset = 0xff;
850
851 if (PeerAssocRspSanity
852 (pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status,
853 &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen, &HtCapability,
854 &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen, &NewExtChannelOffset,
855 &EdcaParm, &CkipFlag)) {
856 /* The frame is for me ? */
857 if (MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) {
858 DBGPRINT(RT_DEBUG_TRACE,
859 ("PeerAssocRspAction():ASSOC - receive ASSOC_RSP to me (status=%d)\n",
860 Status));
861 DBGPRINT(RT_DEBUG_TRACE,
862 ("PeerAssocRspAction():MacTable [%d].AMsduSize = %d. ClientStatusFlags = 0x%lx \n",
863 Elem->Wcid,
864 pAd->MacTab.Content[BSSID_WCID].AMsduSize,
865 pAd->MacTab.Content[BSSID_WCID].
866 ClientStatusFlags));
867 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer,
868 &TimerCancelled);
869
870 if (Status == MLME_SUCCESS) {
871 u8 MaxSupportedRateIn500Kbps = 0;
872 u8 idx;
873
874 /* supported rates array may not be sorted. sort it and find the maximum rate */
875 for (idx = 0; idx < SupRateLen; idx++) {
876 if (MaxSupportedRateIn500Kbps <
877 (SupRate[idx] & 0x7f))
878 MaxSupportedRateIn500Kbps =
879 SupRate[idx] & 0x7f;
880 }
881
882 for (idx = 0; idx < ExtRateLen; idx++) {
883 if (MaxSupportedRateIn500Kbps <
884 (ExtRate[idx] & 0x7f))
885 MaxSupportedRateIn500Kbps =
886 ExtRate[idx] & 0x7f;
887 }
888 /* go to procedure listed on page 376 */
889 AssocPostProc(pAd, Addr2, CapabilityInfo, Aid,
890 SupRate, SupRateLen, ExtRate,
891 ExtRateLen, &EdcaParm,
892 &HtCapability, HtCapabilityLen,
893 &AddHtInfo);
894
895 StaAddMacTableEntry(pAd,
896 &pAd->MacTab.
897 Content[BSSID_WCID],
898 MaxSupportedRateIn500Kbps,
899 &HtCapability,
900 HtCapabilityLen, &AddHtInfo,
901 AddHtInfoLen,
902 CapabilityInfo);
903 }
904 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
905 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
906 MT2_ASSOC_CONF, 2, &Status);
907 }
908 } else {
909 DBGPRINT(RT_DEBUG_TRACE,
910 ("ASSOC - PeerAssocRspAction() sanity check fail\n"));
911 }
912}
913
914/*
915 ==========================================================================
916 Description:
917 peer sends reassoc rsp
918 Parametrs:
919 Elem - MLME message cntaining the received frame
920
921 IRQL = DISPATCH_LEVEL
922
923 ==========================================================================
924 */
925void PeerReassocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
926{
927 u16 CapabilityInfo;
928 u16 Status;
929 u16 Aid;
930 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
931 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
932 u8 Addr2[MAC_ADDR_LEN];
933 u8 CkipFlag;
934 BOOLEAN TimerCancelled;
935 struct rt_edca_parm EdcaParm;
936 struct rt_ht_capability_ie HtCapability;
937 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
938 u8 HtCapabilityLen;
939 u8 AddHtInfoLen;
940 u8 NewExtChannelOffset = 0xff;
941
942 if (PeerAssocRspSanity
943 (pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status,
944 &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen, &HtCapability,
945 &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen, &NewExtChannelOffset,
946 &EdcaParm, &CkipFlag)) {
947 if (MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) /* The frame is for me ? */
948 {
949 DBGPRINT(RT_DEBUG_TRACE,
950 ("ASSOC - receive REASSOC_RSP to me (status=%d)\n",
951 Status));
952 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer,
953 &TimerCancelled);
954
955 if (Status == MLME_SUCCESS) {
956 /* go to procedure listed on page 376 */
957 AssocPostProc(pAd, Addr2, CapabilityInfo, Aid,
958 SupRate, SupRateLen, ExtRate,
959 ExtRateLen, &EdcaParm,
960 &HtCapability, HtCapabilityLen,
961 &AddHtInfo);
962
963 {
964 wext_notify_event_assoc(pAd);
965 RtmpOSWrielessEventSend(pAd, SIOCGIWAP,
966 -1,
967 &pAd->MlmeAux.
968 Bssid[0], NULL,
969 0);
970 }
971
972 }
973 /* CkipFlag is no use for reassociate */
974 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
975 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
976 MT2_REASSOC_CONF, 2, &Status);
977 }
978 } else {
979 DBGPRINT(RT_DEBUG_TRACE,
980 ("ASSOC - PeerReassocRspAction() sanity check fail\n"));
981 }
982
983}
984
985/*
986 ==========================================================================
987 Description:
988 procedures on IEEE 802.11/1999 p.376
989 Parametrs:
990
991 IRQL = DISPATCH_LEVEL
992
993 ==========================================================================
994 */
995void AssocPostProc(struct rt_rtmp_adapter *pAd, u8 *pAddr2, u16 CapabilityInfo, u16 Aid, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_edca_parm *pEdcaParm, struct rt_ht_capability_ie * pHtCapability, u8 HtCapabilityLen, struct rt_add_ht_info_ie * pAddHtInfo) /* AP might use this additional ht info IE */
996{
997 unsigned long Idx;
998
999 pAd->MlmeAux.BssType = BSS_INFRA;
1000 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pAddr2);
1001 pAd->MlmeAux.Aid = Aid;
1002 pAd->MlmeAux.CapabilityInfo =
1003 CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
1004
1005 /* Some HT AP might lost WMM IE. We add WMM ourselves. because HT requires QoS on. */
1006 if ((HtCapabilityLen > 0) && (pEdcaParm->bValid == FALSE)) {
1007 pEdcaParm->bValid = TRUE;
1008 pEdcaParm->Aifsn[0] = 3;
1009 pEdcaParm->Aifsn[1] = 7;
1010 pEdcaParm->Aifsn[2] = 2;
1011 pEdcaParm->Aifsn[3] = 2;
1012
1013 pEdcaParm->Cwmin[0] = 4;
1014 pEdcaParm->Cwmin[1] = 4;
1015 pEdcaParm->Cwmin[2] = 3;
1016 pEdcaParm->Cwmin[3] = 2;
1017
1018 pEdcaParm->Cwmax[0] = 10;
1019 pEdcaParm->Cwmax[1] = 10;
1020 pEdcaParm->Cwmax[2] = 4;
1021 pEdcaParm->Cwmax[3] = 3;
1022
1023 pEdcaParm->Txop[0] = 0;
1024 pEdcaParm->Txop[1] = 0;
1025 pEdcaParm->Txop[2] = 96;
1026 pEdcaParm->Txop[3] = 48;
1027
1028 }
1029
1030 NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, pEdcaParm, sizeof(struct rt_edca_parm));
1031
1032 /* filter out un-supported rates */
1033 pAd->MlmeAux.SupRateLen = SupRateLen;
1034 NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);
1035 RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
1036
1037 /* filter out un-supported rates */
1038 pAd->MlmeAux.ExtRateLen = ExtRateLen;
1039 NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);
1040 RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
1041
1042 if (HtCapabilityLen > 0) {
1043 RTMPCheckHt(pAd, BSSID_WCID, pHtCapability, pAddHtInfo);
1044 }
1045 DBGPRINT(RT_DEBUG_TRACE,
1046 ("AssocPostProc===> AP.AMsduSize = %d. ClientStatusFlags = 0x%lx \n",
1047 pAd->MacTab.Content[BSSID_WCID].AMsduSize,
1048 pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
1049
1050 DBGPRINT(RT_DEBUG_TRACE,
1051 ("AssocPostProc===> (Mmps=%d, AmsduSize=%d, )\n",
1052 pAd->MacTab.Content[BSSID_WCID].MmpsMode,
1053 pAd->MacTab.Content[BSSID_WCID].AMsduSize));
1054
1055 /* Set New WPA information */
1056 Idx = BssTableSearch(&pAd->ScanTab, pAddr2, pAd->MlmeAux.Channel);
1057 if (Idx == BSS_NOT_FOUND) {
1058 DBGPRINT_ERR("ASSOC - Can't find BSS after receiving Assoc response\n");
1059 } else {
1060 /* Init variable */
1061 pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = 0;
1062 NdisZeroMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE,
1063 MAX_LEN_OF_RSNIE);
1064
1065 /* Store appropriate RSN_IE for WPA SM negotiation later */
1066 if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
1067 && (pAd->ScanTab.BssEntry[Idx].VarIELen != 0)) {
1068 u8 *pVIE;
1069 u16 len;
1070 struct rt_eid * pEid;
1071
1072 pVIE = pAd->ScanTab.BssEntry[Idx].VarIEs;
1073 len = pAd->ScanTab.BssEntry[Idx].VarIELen;
1074 /*KH need to check again */
1075 /* Don't allow to go to sleep mode if authmode is WPA-related. */
1076 /*This can make Authentication process more smoothly. */
1077 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1078
1079 while (len > 0) {
1080 pEid = (struct rt_eid *) pVIE;
1081 /* For WPA/WPAPSK */
1082 if ((pEid->Eid == IE_WPA)
1083 &&
1084 (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))
1085 && (pAd->StaCfg.AuthMode ==
1086 Ndis802_11AuthModeWPA
1087 || pAd->StaCfg.AuthMode ==
1088 Ndis802_11AuthModeWPAPSK)) {
1089 NdisMoveMemory(pAd->MacTab.
1090 Content[BSSID_WCID].
1091 RSN_IE, pVIE,
1092 (pEid->Len + 2));
1093 pAd->MacTab.Content[BSSID_WCID].
1094 RSNIE_Len = (pEid->Len + 2);
1095 DBGPRINT(RT_DEBUG_TRACE,
1096 ("AssocPostProc===> Store RSN_IE for WPA SM negotiation \n"));
1097 }
1098 /* For WPA2/WPA2PSK */
1099 else if ((pEid->Eid == IE_RSN)
1100 &&
1101 (NdisEqualMemory
1102 (pEid->Octet + 2, RSN_OUI, 3))
1103 && (pAd->StaCfg.AuthMode ==
1104 Ndis802_11AuthModeWPA2
1105 || pAd->StaCfg.AuthMode ==
1106 Ndis802_11AuthModeWPA2PSK)) {
1107 NdisMoveMemory(pAd->MacTab.
1108 Content[BSSID_WCID].
1109 RSN_IE, pVIE,
1110 (pEid->Len + 2));
1111 pAd->MacTab.Content[BSSID_WCID].
1112 RSNIE_Len = (pEid->Len + 2);
1113 DBGPRINT(RT_DEBUG_TRACE,
1114 ("AssocPostProc===> Store RSN_IE for WPA2 SM negotiation \n"));
1115 }
1116
1117 pVIE += (pEid->Len + 2);
1118 len -= (pEid->Len + 2);
1119 }
1120
1121 }
1122
1123 if (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == 0) {
1124 DBGPRINT(RT_DEBUG_TRACE,
1125 ("AssocPostProc===> no RSN_IE \n"));
1126 } else {
1127 hex_dump("RSN_IE",
1128 pAd->MacTab.Content[BSSID_WCID].RSN_IE,
1129 pAd->MacTab.Content[BSSID_WCID].RSNIE_Len);
1130 }
1131 }
1132}
1133
1134/*
1135 ==========================================================================
1136 Description:
1137 left part of IEEE 802.11/1999 p.374
1138 Parameters:
1139 Elem - MLME message containing the received frame
1140
1141 IRQL = DISPATCH_LEVEL
1142
1143 ==========================================================================
1144 */
1145void PeerDisassocAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1146{
1147 u8 Addr2[MAC_ADDR_LEN];
1148 u16 Reason;
1149
1150 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction()\n"));
1151 if (PeerDisassocSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason)) {
1152 DBGPRINT(RT_DEBUG_TRACE,
1153 ("ASSOC - PeerDisassocAction() Reason = %d\n",
1154 Reason));
1155 if (INFRA_ON(pAd)
1156 && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, Addr2)) {
1157
1158 if (pAd->CommonCfg.bWirelessEvent) {
1159 RTMPSendWirelessEvent(pAd,
1160 IW_DISASSOC_EVENT_FLAG,
1161 pAd->MacTab.
1162 Content[BSSID_WCID].Addr,
1163 BSS0, 0);
1164 }
1165
1166 LinkDown(pAd, TRUE);
1167 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1168
1169 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL,
1170 0);
1171 }
1172 } else {
1173 DBGPRINT(RT_DEBUG_TRACE,
1174 ("ASSOC - PeerDisassocAction() sanity check fail\n"));
1175 }
1176
1177}
1178
1179/*
1180 ==========================================================================
1181 Description:
1182 what the state machine will do after assoc timeout
1183 Parameters:
1184 Elme -
1185
1186 IRQL = DISPATCH_LEVEL
1187
1188 ==========================================================================
1189 */
1190void AssocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1191{
1192 u16 Status;
1193 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - AssocTimeoutAction\n"));
1194 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1195 Status = MLME_REJ_TIMEOUT;
1196 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
1197}
1198
1199/*
1200 ==========================================================================
1201 Description:
1202 what the state machine will do after reassoc timeout
1203
1204 IRQL = DISPATCH_LEVEL
1205
1206 ==========================================================================
1207 */
1208void ReassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1209{
1210 u16 Status;
1211 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - ReassocTimeoutAction\n"));
1212 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1213 Status = MLME_REJ_TIMEOUT;
1214 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
1215}
1216
1217/*
1218 ==========================================================================
1219 Description:
1220 what the state machine will do after disassoc timeout
1221
1222 IRQL = DISPATCH_LEVEL
1223
1224 ==========================================================================
1225 */
1226void DisassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1227{
1228 u16 Status;
1229 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - DisassocTimeoutAction\n"));
1230 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1231 Status = MLME_SUCCESS;
1232 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2,
1233 &Status);
1234}
1235
1236void InvalidStateWhenAssoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1237{
1238 u16 Status;
1239 DBGPRINT(RT_DEBUG_TRACE,
1240 ("ASSOC - InvalidStateWhenAssoc(state=%ld), reset ASSOC state machine\n",
1241 pAd->Mlme.AssocMachine.CurrState));
1242 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1243 Status = MLME_STATE_MACHINE_REJECT;
1244 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
1245}
1246
1247void InvalidStateWhenReassoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1248{
1249 u16 Status;
1250 DBGPRINT(RT_DEBUG_TRACE,
1251 ("ASSOC - InvalidStateWhenReassoc(state=%ld), reset ASSOC state machine\n",
1252 pAd->Mlme.AssocMachine.CurrState));
1253 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1254 Status = MLME_STATE_MACHINE_REJECT;
1255 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
1256}
1257
1258void InvalidStateWhenDisassociate(struct rt_rtmp_adapter *pAd,
1259 struct rt_mlme_queue_elem *Elem)
1260{
1261 u16 Status;
1262 DBGPRINT(RT_DEBUG_TRACE,
1263 ("ASSOC - InvalidStateWhenDisassoc(state=%ld), reset ASSOC state machine\n",
1264 pAd->Mlme.AssocMachine.CurrState));
1265 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1266 Status = MLME_STATE_MACHINE_REJECT;
1267 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2,
1268 &Status);
1269}
1270
1271/*
1272 ==========================================================================
1273 Description:
1274 right part of IEEE 802.11/1999 page 374
1275 Note:
1276 This event should never cause ASSOC state machine perform state
1277 transition, and has no relationship with CNTL machine. So we separate
1278 this routine as a service outside of ASSOC state transition table.
1279
1280 IRQL = DISPATCH_LEVEL
1281
1282 ==========================================================================
1283 */
1284void Cls3errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr)
1285{
1286 struct rt_header_802_11 DisassocHdr;
1287 struct rt_header_802_11 * pDisassocHdr;
1288 u8 *pOutBuffer = NULL;
1289 unsigned long FrameLen = 0;
1290 int NStatus;
1291 u16 Reason = REASON_CLS3ERR;
1292
1293 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
1294 if (NStatus != NDIS_STATUS_SUCCESS)
1295 return;
1296
1297 DBGPRINT(RT_DEBUG_TRACE,
1298 ("ASSOC - Class 3 Error, Send DISASSOC frame\n"));
1299 MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pAddr, pAd->CommonCfg.Bssid); /* patch peap ttls switching issue */
1300 MakeOutgoingFrame(pOutBuffer, &FrameLen,
1301 sizeof(struct rt_header_802_11), &DisassocHdr,
1302 2, &Reason, END_OF_ARGS);
1303 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
1304
1305 /* To patch Instance and Buffalo(N) AP */
1306 /* Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine */
1307 /* Therefore, we send both of them. */
1308 pDisassocHdr = (struct rt_header_802_11 *) pOutBuffer;
1309 pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;
1310 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
1311
1312 MlmeFreeMemory(pAd, pOutBuffer);
1313
1314 pAd->StaCfg.DisassocReason = REASON_CLS3ERR;
1315 COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pAddr);
1316}
1317
1318int wext_notify_event_assoc(struct rt_rtmp_adapter *pAd)
1319{
1320 char custom[IW_CUSTOM_MAX] = { 0 };
1321
1322 if (pAd->StaCfg.ReqVarIELen <= IW_CUSTOM_MAX) {
1323 NdisMoveMemory(custom, pAd->StaCfg.ReqVarIEs,
1324 pAd->StaCfg.ReqVarIELen);
1325 RtmpOSWrielessEventSend(pAd, IWEVASSOCREQIE, -1, NULL, custom,
1326 pAd->StaCfg.ReqVarIELen);
1327 } else
1328 DBGPRINT(RT_DEBUG_TRACE,
1329 ("pAd->StaCfg.ReqVarIELen > MAX_CUSTOM_LEN\n"));
1330
1331 return 0;
1332
1333}
1334
1335BOOLEAN StaAddMacTableEntry(struct rt_rtmp_adapter *pAd,
1336 struct rt_mac_table_entry *pEntry,
1337 u8 MaxSupportedRateIn500Kbps,
1338 struct rt_ht_capability_ie * pHtCapability,
1339 u8 HtCapabilityLen,
1340 struct rt_add_ht_info_ie * pAddHtInfo,
1341 u8 AddHtInfoLen, u16 CapabilityInfo)
1342{
1343 u8 MaxSupportedRate = RATE_11;
1344
1345 if (ADHOC_ON(pAd))
1346 CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
1347
1348 switch (MaxSupportedRateIn500Kbps) {
1349 case 108:
1350 MaxSupportedRate = RATE_54;
1351 break;
1352 case 96:
1353 MaxSupportedRate = RATE_48;
1354 break;
1355 case 72:
1356 MaxSupportedRate = RATE_36;
1357 break;
1358 case 48:
1359 MaxSupportedRate = RATE_24;
1360 break;
1361 case 36:
1362 MaxSupportedRate = RATE_18;
1363 break;
1364 case 24:
1365 MaxSupportedRate = RATE_12;
1366 break;
1367 case 18:
1368 MaxSupportedRate = RATE_9;
1369 break;
1370 case 12:
1371 MaxSupportedRate = RATE_6;
1372 break;
1373 case 22:
1374 MaxSupportedRate = RATE_11;
1375 break;
1376 case 11:
1377 MaxSupportedRate = RATE_5_5;
1378 break;
1379 case 4:
1380 MaxSupportedRate = RATE_2;
1381 break;
1382 case 2:
1383 MaxSupportedRate = RATE_1;
1384 break;
1385 default:
1386 MaxSupportedRate = RATE_11;
1387 break;
1388 }
1389
1390 if ((pAd->CommonCfg.PhyMode == PHY_11G)
1391 && (MaxSupportedRate < RATE_FIRST_OFDM_RATE))
1392 return FALSE;
1393
1394 /* 11n only */
1395 if (((pAd->CommonCfg.PhyMode == PHY_11N_2_4G)
1396 || (pAd->CommonCfg.PhyMode == PHY_11N_5G))
1397 && (HtCapabilityLen == 0))
1398 return FALSE;
1399
1400 if (!pEntry)
1401 return FALSE;
1402
1403 NdisAcquireSpinLock(&pAd->MacTabLock);
1404 if (pEntry) {
1405 pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
1406 if ((MaxSupportedRate < RATE_FIRST_OFDM_RATE) ||
1407 (pAd->CommonCfg.PhyMode == PHY_11B)) {
1408 pEntry->RateLen = 4;
1409 if (MaxSupportedRate >= RATE_FIRST_OFDM_RATE)
1410 MaxSupportedRate = RATE_11;
1411 } else
1412 pEntry->RateLen = 12;
1413
1414 pEntry->MaxHTPhyMode.word = 0;
1415 pEntry->MinHTPhyMode.word = 0;
1416 pEntry->HTPhyMode.word = 0;
1417 pEntry->MaxSupportedRate = MaxSupportedRate;
1418 if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE) {
1419 pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
1420 pEntry->MaxHTPhyMode.field.MCS =
1421 pEntry->MaxSupportedRate;
1422 pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
1423 pEntry->MinHTPhyMode.field.MCS =
1424 pEntry->MaxSupportedRate;
1425 pEntry->HTPhyMode.field.MODE = MODE_CCK;
1426 pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
1427 } else {
1428 pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
1429 pEntry->MaxHTPhyMode.field.MCS =
1430 OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
1431 pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
1432 pEntry->MinHTPhyMode.field.MCS =
1433 OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
1434 pEntry->HTPhyMode.field.MODE = MODE_OFDM;
1435 pEntry->HTPhyMode.field.MCS =
1436 OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
1437 }
1438 pEntry->CapabilityInfo = CapabilityInfo;
1439 CLIENT_STATUS_CLEAR_FLAG(pEntry,
1440 fCLIENT_STATUS_AGGREGATION_CAPABLE);
1441 CLIENT_STATUS_CLEAR_FLAG(pEntry,
1442 fCLIENT_STATUS_PIGGYBACK_CAPABLE);
1443 }
1444
1445 NdisZeroMemory(&pEntry->HTCapability, sizeof(pEntry->HTCapability));
1446 /* If this Entry supports 802.11n, upgrade to HT rate. */
1447 if ((HtCapabilityLen != 0)
1448 && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
1449 u8 j, bitmask; /*k,bitmask; */
1450 char i;
1451
1452 if (ADHOC_ON(pAd))
1453 CLIENT_STATUS_SET_FLAG(pEntry,
1454 fCLIENT_STATUS_WMM_CAPABLE);
1455 if ((pHtCapability->HtCapInfo.GF)
1456 && (pAd->CommonCfg.DesiredHtPhy.GF)) {
1457 pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
1458 } else {
1459 pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
1460 pAd->MacTab.fAnyStationNonGF = TRUE;
1461 pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
1462 }
1463
1464 if ((pHtCapability->HtCapInfo.ChannelWidth) &&
1465 (pAd->CommonCfg.DesiredHtPhy.ChannelWidth) &&
1466 ((pAd->StaCfg.BssType == BSS_INFRA)
1467 || ((pAd->StaCfg.BssType == BSS_ADHOC)
1468 && (pAddHtInfo->AddHtInfo.ExtChanOffset ==
1469 pAd->CommonCfg.AddHTInfo.AddHtInfo.
1470 ExtChanOffset)))) {
1471 pEntry->MaxHTPhyMode.field.BW = BW_40;
1472 pEntry->MaxHTPhyMode.field.ShortGI =
1473 ((pAd->CommonCfg.DesiredHtPhy.
1474 ShortGIfor40) & (pHtCapability->HtCapInfo.
1475 ShortGIfor40));
1476 } else {
1477 pEntry->MaxHTPhyMode.field.BW = BW_20;
1478 pEntry->MaxHTPhyMode.field.ShortGI =
1479 ((pAd->CommonCfg.DesiredHtPhy.
1480 ShortGIfor20) & (pHtCapability->HtCapInfo.
1481 ShortGIfor20));
1482 pAd->MacTab.fAnyStation20Only = TRUE;
1483 }
1484
1485 /* 3*3 */
1486 if (pAd->MACVersion >= RALINK_2883_VERSION
1487 && pAd->MACVersion < RALINK_3070_VERSION)
1488 pEntry->MaxHTPhyMode.field.TxBF =
1489 pAd->CommonCfg.RegTransmitSetting.field.TxBF;
1490
1491 /* find max fixed rate */
1492 for (i = 23; i >= 0; i--) /* 3*3 */
1493 {
1494 j = i / 8;
1495 bitmask = (1 << (i - (j * 8)));
1496 if ((pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j] & bitmask)
1497 && (pHtCapability->MCSSet[j] & bitmask)) {
1498 pEntry->MaxHTPhyMode.field.MCS = i;
1499 break;
1500 }
1501 if (i == 0)
1502 break;
1503 }
1504
1505 if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) {
1506 if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32) {
1507 /* Fix MCS as HT Duplicated Mode */
1508 pEntry->MaxHTPhyMode.field.BW = 1;
1509 pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
1510 pEntry->MaxHTPhyMode.field.STBC = 0;
1511 pEntry->MaxHTPhyMode.field.ShortGI = 0;
1512 pEntry->MaxHTPhyMode.field.MCS = 32;
1513 } else if (pEntry->MaxHTPhyMode.field.MCS >
1514 pAd->StaCfg.HTPhyMode.field.MCS) {
1515 /* STA supports fixed MCS */
1516 pEntry->MaxHTPhyMode.field.MCS =
1517 pAd->StaCfg.HTPhyMode.field.MCS;
1518 }
1519 }
1520
1521 pEntry->MaxHTPhyMode.field.STBC =
1522 (pHtCapability->HtCapInfo.
1523 RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
1524 pEntry->MpduDensity = pHtCapability->HtCapParm.MpduDensity;
1525 pEntry->MaxRAmpduFactor =
1526 pHtCapability->HtCapParm.MaxRAmpduFactor;
1527 pEntry->MmpsMode = (u8)pHtCapability->HtCapInfo.MimoPs;
1528 pEntry->AMsduSize = (u8)pHtCapability->HtCapInfo.AMsduSize;
1529 pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
1530
1531 if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable
1532 && (pAd->CommonCfg.REGBACapability.field.AutoBA == FALSE))
1533 CLIENT_STATUS_SET_FLAG(pEntry,
1534 fCLIENT_STATUS_AMSDU_INUSED);
1535 if (pHtCapability->HtCapInfo.ShortGIfor20)
1536 CLIENT_STATUS_SET_FLAG(pEntry,
1537 fCLIENT_STATUS_SGI20_CAPABLE);
1538 if (pHtCapability->HtCapInfo.ShortGIfor40)
1539 CLIENT_STATUS_SET_FLAG(pEntry,
1540 fCLIENT_STATUS_SGI40_CAPABLE);
1541 if (pHtCapability->HtCapInfo.TxSTBC)
1542 CLIENT_STATUS_SET_FLAG(pEntry,
1543 fCLIENT_STATUS_TxSTBC_CAPABLE);
1544 if (pHtCapability->HtCapInfo.RxSTBC)
1545 CLIENT_STATUS_SET_FLAG(pEntry,
1546 fCLIENT_STATUS_RxSTBC_CAPABLE);
1547 if (pHtCapability->ExtHtCapInfo.PlusHTC)
1548 CLIENT_STATUS_SET_FLAG(pEntry,
1549 fCLIENT_STATUS_HTC_CAPABLE);
1550 if (pAd->CommonCfg.bRdg
1551 && pHtCapability->ExtHtCapInfo.RDGSupport)
1552 CLIENT_STATUS_SET_FLAG(pEntry,
1553 fCLIENT_STATUS_RDG_CAPABLE);
1554 if (pHtCapability->ExtHtCapInfo.MCSFeedback == 0x03)
1555 CLIENT_STATUS_SET_FLAG(pEntry,
1556 fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
1557 NdisMoveMemory(&pEntry->HTCapability, pHtCapability,
1558 HtCapabilityLen);
1559 } else {
1560 pAd->MacTab.fAnyStationIsLegacy = TRUE;
1561 }
1562
1563 pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
1564 pEntry->CurrTxRate = pEntry->MaxSupportedRate;
1565
1566 /* Set asic auto fall back */
1567 if (pAd->StaCfg.bAutoTxRateSwitch == TRUE) {
1568 u8 *pTable;
1569 u8 TableSize = 0;
1570
1571 MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize,
1572 &pEntry->CurrTxRateIndex);
1573 pEntry->bAutoTxRateSwitch = TRUE;
1574 } else {
1575 pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
1576 pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
1577 pEntry->bAutoTxRateSwitch = FALSE;
1578
1579 /* If the legacy mode is set, overwrite the transmit setting of this entry. */
1580 RTMPUpdateLegacyTxSetting((u8)pAd->StaCfg.
1581 DesiredTransmitSetting.field.
1582 FixedTxMode, pEntry);
1583 }
1584
1585 pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
1586 pEntry->Sst = SST_ASSOC;
1587 pEntry->AuthState = AS_AUTH_OPEN;
1588 pEntry->AuthMode = pAd->StaCfg.AuthMode;
1589 pEntry->WepStatus = pAd->StaCfg.WepStatus;
1590
1591 NdisReleaseSpinLock(&pAd->MacTabLock);
1592
1593 {
1594 union iwreq_data wrqu;
1595 wext_notify_event_assoc(pAd);
1596
1597 memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
1598 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
1599
1600 }
1601 return TRUE;
1602}
diff --git a/drivers/staging/rt2860/sta/auth.c b/drivers/staging/rt2860/sta/auth.c
deleted file mode 100644
index 23ea00b896b..00000000000
--- a/drivers/staging/rt2860/sta/auth.c
+++ /dev/null
@@ -1,517 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 auth.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John 2004-9-3 porting from RT2500
36 Justin P. Mattock 11/07/2010 Fix typos
37*/
38#include "../rt_config.h"
39
40/*
41 ==========================================================================
42 Description:
43 authenticate state machine init, including state transition and timer init
44 Parameters:
45 Sm - pointer to the auth state machine
46 Note:
47 The state machine looks like this
48
49 AUTH_REQ_IDLE AUTH_WAIT_SEQ2 AUTH_WAIT_SEQ4
50 MT2_MLME_AUTH_REQ mlme_auth_req_action invalid_state_when_auth invalid_state_when_auth
51 MT2_PEER_AUTH_EVEN drop peer_auth_even_at_seq2_action peer_auth_even_at_seq4_action
52 MT2_AUTH_TIMEOUT Drop auth_timeout_action auth_timeout_action
53
54 IRQL = PASSIVE_LEVEL
55
56 ==========================================================================
57 */
58
59void AuthStateMachineInit(struct rt_rtmp_adapter *pAd,
60 struct rt_state_machine *Sm, OUT STATE_MACHINE_FUNC Trans[])
61{
62 StateMachineInit(Sm, Trans, MAX_AUTH_STATE, MAX_AUTH_MSG,
63 (STATE_MACHINE_FUNC) Drop, AUTH_REQ_IDLE,
64 AUTH_MACHINE_BASE);
65
66 /* the first column */
67 StateMachineSetAction(Sm, AUTH_REQ_IDLE, MT2_MLME_AUTH_REQ,
68 (STATE_MACHINE_FUNC) MlmeAuthReqAction);
69
70 /* the second column */
71 StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_MLME_AUTH_REQ,
72 (STATE_MACHINE_FUNC) InvalidStateWhenAuth);
73 StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_PEER_AUTH_EVEN,
74 (STATE_MACHINE_FUNC) PeerAuthRspAtSeq2Action);
75 StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_AUTH_TIMEOUT,
76 (STATE_MACHINE_FUNC) AuthTimeoutAction);
77
78 /* the third column */
79 StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_MLME_AUTH_REQ,
80 (STATE_MACHINE_FUNC) InvalidStateWhenAuth);
81 StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_PEER_AUTH_EVEN,
82 (STATE_MACHINE_FUNC) PeerAuthRspAtSeq4Action);
83 StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_AUTH_TIMEOUT,
84 (STATE_MACHINE_FUNC) AuthTimeoutAction);
85
86 RTMPInitTimer(pAd, &pAd->MlmeAux.AuthTimer,
87 GET_TIMER_FUNCTION(AuthTimeout), pAd, FALSE);
88}
89
90/*
91 ==========================================================================
92 Description:
93 function to be executed at timer thread when auth timer expires
94
95 IRQL = DISPATCH_LEVEL
96
97 ==========================================================================
98 */
99void AuthTimeout(void *SystemSpecific1,
100 void *FunctionContext,
101 void *SystemSpecific2, void *SystemSpecific3)
102{
103 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
104
105 DBGPRINT(RT_DEBUG_TRACE, ("AUTH - AuthTimeout\n"));
106
107 /* Do nothing if the driver is starting halt state. */
108 /* This might happen when timer already been fired before cancel timer with mlmehalt */
109 if (RTMP_TEST_FLAG
110 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
111 return;
112
113 /* send a de-auth to reset AP's state machine (Patch AP-Dir635) */
114 if (pAd->Mlme.AuthMachine.CurrState == AUTH_WAIT_SEQ2)
115 Cls2errAction(pAd, pAd->MlmeAux.Bssid);
116
117 MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_AUTH_TIMEOUT, 0, NULL);
118 RTMP_MLME_HANDLER(pAd);
119}
120
121/*
122 ==========================================================================
123 Description:
124
125 IRQL = DISPATCH_LEVEL
126
127 ==========================================================================
128 */
129void MlmeAuthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
130{
131 if (AUTH_ReqSend
132 (pAd, Elem, &pAd->MlmeAux.AuthTimer, "AUTH", 1, NULL, 0))
133 pAd->Mlme.AuthMachine.CurrState = AUTH_WAIT_SEQ2;
134 else {
135 u16 Status;
136
137 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
138 Status = MLME_INVALID_FORMAT;
139 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2,
140 &Status);
141 }
142}
143
144/*
145 ==========================================================================
146 Description:
147
148 IRQL = DISPATCH_LEVEL
149
150 ==========================================================================
151 */
152void PeerAuthRspAtSeq2Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
153{
154 u8 Addr2[MAC_ADDR_LEN];
155 u16 Seq, Status, RemoteStatus, Alg;
156 u8 ChlgText[CIPHER_TEXT_LEN];
157 u8 CyperChlgText[CIPHER_TEXT_LEN + 8 + 8];
158 u8 Element[2];
159 struct rt_header_802_11 AuthHdr;
160 BOOLEAN TimerCancelled;
161 u8 *pOutBuffer = NULL;
162 int NStatus;
163 unsigned long FrameLen = 0;
164 u16 Status2;
165
166 if (PeerAuthSanity
167 (pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status,
168 (char *)ChlgText)) {
169 if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 2) {
170 DBGPRINT(RT_DEBUG_TRACE,
171 ("AUTH - Receive AUTH_RSP seq#2 to me (Alg=%d, Status=%d)\n",
172 Alg, Status));
173 RTMPCancelTimer(&pAd->MlmeAux.AuthTimer,
174 &TimerCancelled);
175
176 if (Status == MLME_SUCCESS) {
177 /* Authentication Mode "LEAP" has allow for CCX 1.X */
178 if (pAd->MlmeAux.Alg == Ndis802_11AuthModeOpen) {
179 pAd->Mlme.AuthMachine.CurrState =
180 AUTH_REQ_IDLE;
181 MlmeEnqueue(pAd,
182 MLME_CNTL_STATE_MACHINE,
183 MT2_AUTH_CONF, 2, &Status);
184 } else {
185 /* 2. shared key, need to be challenged */
186 Seq++;
187 RemoteStatus = MLME_SUCCESS;
188
189 /* Get an unused nonpaged memory */
190 NStatus =
191 MlmeAllocateMemory(pAd,
192 &pOutBuffer);
193 if (NStatus != NDIS_STATUS_SUCCESS) {
194 DBGPRINT(RT_DEBUG_TRACE,
195 ("AUTH - PeerAuthRspAtSeq2Action() allocate memory fail\n"));
196 pAd->Mlme.AuthMachine.
197 CurrState = AUTH_REQ_IDLE;
198 Status2 = MLME_FAIL_NO_RESOURCE;
199 MlmeEnqueue(pAd,
200 MLME_CNTL_STATE_MACHINE,
201 MT2_AUTH_CONF, 2,
202 &Status2);
203 return;
204 }
205
206 DBGPRINT(RT_DEBUG_TRACE,
207 ("AUTH - Send AUTH request seq#3...\n"));
208 MgtMacHeaderInit(pAd, &AuthHdr,
209 SUBTYPE_AUTH, 0, Addr2,
210 pAd->MlmeAux.Bssid);
211 AuthHdr.FC.Wep = 1;
212 /* Encrypt challenge text & auth information */
213 RTMPInitWepEngine(pAd,
214 pAd->
215 SharedKey[BSS0][pAd->
216 StaCfg.
217 DefaultKeyId].
218 Key,
219 pAd->StaCfg.
220 DefaultKeyId,
221 pAd->
222 SharedKey[BSS0][pAd->
223 StaCfg.
224 DefaultKeyId].
225 KeyLen,
226 CyperChlgText);
227
228 Alg = cpu2le16(*(u16 *) & Alg);
229 Seq = cpu2le16(*(u16 *) & Seq);
230 RemoteStatus =
231 cpu2le16(*(u16 *) &
232 RemoteStatus);
233
234 RTMPEncryptData(pAd, (u8 *)& Alg,
235 CyperChlgText + 4, 2);
236 RTMPEncryptData(pAd, (u8 *)& Seq,
237 CyperChlgText + 6, 2);
238 RTMPEncryptData(pAd,
239 (u8 *)& RemoteStatus,
240 CyperChlgText + 8, 2);
241 Element[0] = 16;
242 Element[1] = 128;
243 RTMPEncryptData(pAd, Element,
244 CyperChlgText + 10, 2);
245 RTMPEncryptData(pAd, ChlgText,
246 CyperChlgText + 12,
247 128);
248 RTMPSetICV(pAd, CyperChlgText + 140);
249 MakeOutgoingFrame(pOutBuffer, &FrameLen,
250 sizeof(struct rt_header_802_11),
251 &AuthHdr,
252 CIPHER_TEXT_LEN + 16,
253 CyperChlgText,
254 END_OF_ARGS);
255 MiniportMMRequest(pAd, 0, pOutBuffer,
256 FrameLen);
257 MlmeFreeMemory(pAd, pOutBuffer);
258
259 RTMPSetTimer(&pAd->MlmeAux.AuthTimer,
260 AUTH_TIMEOUT);
261 pAd->Mlme.AuthMachine.CurrState =
262 AUTH_WAIT_SEQ4;
263 }
264 } else {
265 pAd->StaCfg.AuthFailReason = Status;
266 COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2);
267 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
268 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
269 MT2_AUTH_CONF, 2, &Status);
270 }
271 }
272 } else {
273 DBGPRINT(RT_DEBUG_TRACE,
274 ("AUTH - PeerAuthSanity() sanity check fail\n"));
275 }
276}
277
278/*
279 ==========================================================================
280 Description:
281
282 IRQL = DISPATCH_LEVEL
283
284 ==========================================================================
285 */
286void PeerAuthRspAtSeq4Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
287{
288 u8 Addr2[MAC_ADDR_LEN];
289 u16 Alg, Seq, Status;
290 char ChlgText[CIPHER_TEXT_LEN];
291 BOOLEAN TimerCancelled;
292
293 if (PeerAuthSanity
294 (pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status,
295 ChlgText)) {
296 if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 4) {
297 DBGPRINT(RT_DEBUG_TRACE,
298 ("AUTH - Receive AUTH_RSP seq#4 to me\n"));
299 RTMPCancelTimer(&pAd->MlmeAux.AuthTimer,
300 &TimerCancelled);
301
302 if (Status != MLME_SUCCESS) {
303 pAd->StaCfg.AuthFailReason = Status;
304 COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2);
305 }
306
307 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
308 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF,
309 2, &Status);
310 }
311 } else {
312 DBGPRINT(RT_DEBUG_TRACE,
313 ("AUTH - PeerAuthRspAtSeq4Action() sanity check fail\n"));
314 }
315}
316
317/*
318 ==========================================================================
319 Description:
320
321 IRQL = DISPATCH_LEVEL
322
323 ==========================================================================
324 */
325void MlmeDeauthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
326{
327 struct rt_mlme_deauth_req *pInfo;
328 struct rt_header_802_11 DeauthHdr;
329 u8 *pOutBuffer = NULL;
330 int NStatus;
331 unsigned long FrameLen = 0;
332 u16 Status;
333
334 pInfo = (struct rt_mlme_deauth_req *)Elem->Msg;
335
336 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
337 if (NStatus != NDIS_STATUS_SUCCESS) {
338 DBGPRINT(RT_DEBUG_TRACE,
339 ("AUTH - MlmeDeauthReqAction() allocate memory fail\n"));
340 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
341 Status = MLME_FAIL_NO_RESOURCE;
342 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2,
343 &Status);
344 return;
345 }
346
347 DBGPRINT(RT_DEBUG_TRACE,
348 ("AUTH - Send DE-AUTH request (Reason=%d)...\n",
349 pInfo->Reason));
350 MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pInfo->Addr,
351 pAd->MlmeAux.Bssid);
352 MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11),
353 &DeauthHdr, 2, &pInfo->Reason, END_OF_ARGS);
354 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
355 MlmeFreeMemory(pAd, pOutBuffer);
356
357 pAd->StaCfg.DeauthReason = pInfo->Reason;
358 COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pInfo->Addr);
359 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
360 Status = MLME_SUCCESS;
361 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, &Status);
362
363 /* send wireless event - for deauthentication */
364 if (pAd->CommonCfg.bWirelessEvent)
365 RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG,
366 pAd->MacTab.Content[BSSID_WCID].Addr,
367 BSS0, 0);
368}
369
370/*
371 ==========================================================================
372 Description:
373
374 IRQL = DISPATCH_LEVEL
375
376 ==========================================================================
377 */
378void AuthTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
379{
380 u16 Status;
381 DBGPRINT(RT_DEBUG_TRACE, ("AUTH - AuthTimeoutAction\n"));
382 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
383 Status = MLME_REJ_TIMEOUT;
384 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
385}
386
387/*
388 ==========================================================================
389 Description:
390
391 IRQL = DISPATCH_LEVEL
392
393 ==========================================================================
394 */
395void InvalidStateWhenAuth(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
396{
397 u16 Status;
398 DBGPRINT(RT_DEBUG_TRACE,
399 ("AUTH - InvalidStateWhenAuth (state=%ld), reset AUTH state machine\n",
400 pAd->Mlme.AuthMachine.CurrState));
401 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
402 Status = MLME_STATE_MACHINE_REJECT;
403 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status);
404}
405
406/*
407 ==========================================================================
408 Description:
409 Some STA/AP
410 Note:
411 This action should never trigger AUTH state transition, therefore we
412 separate it from AUTH state machine, and make it as a standalone service
413
414 IRQL = DISPATCH_LEVEL
415
416 ==========================================================================
417 */
418void Cls2errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr)
419{
420 struct rt_header_802_11 DeauthHdr;
421 u8 *pOutBuffer = NULL;
422 int NStatus;
423 unsigned long FrameLen = 0;
424 u16 Reason = REASON_CLS2ERR;
425
426 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
427 if (NStatus != NDIS_STATUS_SUCCESS)
428 return;
429
430 DBGPRINT(RT_DEBUG_TRACE,
431 ("AUTH - Class 2 error, Send DEAUTH frame...\n"));
432 MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pAddr,
433 pAd->MlmeAux.Bssid);
434 MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11),
435 &DeauthHdr, 2, &Reason, END_OF_ARGS);
436 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
437 MlmeFreeMemory(pAd, pOutBuffer);
438
439 pAd->StaCfg.DeauthReason = Reason;
440 COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pAddr);
441}
442
443BOOLEAN AUTH_ReqSend(struct rt_rtmp_adapter *pAd,
444 struct rt_mlme_queue_elem *pElem,
445 struct rt_ralink_timer *pAuthTimer,
446 char *pSMName,
447 u16 SeqNo,
448 u8 *pNewElement, unsigned long ElementLen)
449{
450 u16 Alg, Seq, Status;
451 u8 Addr[6];
452 unsigned long Timeout;
453 struct rt_header_802_11 AuthHdr;
454 BOOLEAN TimerCancelled;
455 int NStatus;
456 u8 *pOutBuffer = NULL;
457 unsigned long FrameLen = 0, tmp = 0;
458
459 /* Block all authentication request during WPA block period */
460 if (pAd->StaCfg.bBlockAssoc == TRUE) {
461 DBGPRINT(RT_DEBUG_TRACE,
462 ("%s - Block Auth request during WPA block period!\n",
463 pSMName));
464 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
465 Status = MLME_STATE_MACHINE_REJECT;
466 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2,
467 &Status);
468 } else
469 if (MlmeAuthReqSanity
470 (pAd, pElem->Msg, pElem->MsgLen, Addr, &Timeout, &Alg)) {
471 /* reset timer */
472 RTMPCancelTimer(pAuthTimer, &TimerCancelled);
473
474 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, Addr);
475 pAd->MlmeAux.Alg = Alg;
476 Seq = SeqNo;
477 Status = MLME_SUCCESS;
478
479 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
480 if (NStatus != NDIS_STATUS_SUCCESS) {
481 DBGPRINT(RT_DEBUG_TRACE,
482 ("%s - MlmeAuthReqAction(Alg:%d) allocate memory failed\n",
483 pSMName, Alg));
484 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
485 Status = MLME_FAIL_NO_RESOURCE;
486 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF,
487 2, &Status);
488 return FALSE;
489 }
490
491 DBGPRINT(RT_DEBUG_TRACE,
492 ("%s - Send AUTH request seq#1 (Alg=%d)...\n", pSMName,
493 Alg));
494 MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr,
495 pAd->MlmeAux.Bssid);
496 MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11),
497 &AuthHdr, 2, &Alg, 2, &Seq, 2, &Status,
498 END_OF_ARGS);
499
500 if (pNewElement && ElementLen) {
501 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
502 ElementLen, pNewElement, END_OF_ARGS);
503 FrameLen += tmp;
504 }
505
506 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
507 MlmeFreeMemory(pAd, pOutBuffer);
508
509 RTMPSetTimer(pAuthTimer, Timeout);
510 return TRUE;
511 } else {
512 DBGPRINT_ERR("%s - MlmeAuthReqAction() sanity check failed\n", pSMName);
513 return FALSE;
514 }
515
516 return TRUE;
517}
diff --git a/drivers/staging/rt2860/sta/auth_rsp.c b/drivers/staging/rt2860/sta/auth_rsp.c
deleted file mode 100644
index 5b018b75730..00000000000
--- a/drivers/staging/rt2860/sta/auth_rsp.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 auth_rsp.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John 2004-10-1 copy from RT2560
36*/
37#include "../rt_config.h"
38
39/*
40 ==========================================================================
41 Description:
42 authentication state machine init procedure
43 Parameters:
44 Sm - the state machine
45
46 IRQL = PASSIVE_LEVEL
47
48 ==========================================================================
49 */
50void AuthRspStateMachineInit(struct rt_rtmp_adapter *pAd,
51 struct rt_state_machine *Sm,
52 IN STATE_MACHINE_FUNC Trans[])
53{
54 StateMachineInit(Sm, Trans, MAX_AUTH_RSP_STATE, MAX_AUTH_RSP_MSG,
55 (STATE_MACHINE_FUNC) Drop, AUTH_RSP_IDLE,
56 AUTH_RSP_MACHINE_BASE);
57
58 /* column 1 */
59 StateMachineSetAction(Sm, AUTH_RSP_IDLE, MT2_PEER_DEAUTH,
60 (STATE_MACHINE_FUNC) PeerDeauthAction);
61
62 /* column 2 */
63 StateMachineSetAction(Sm, AUTH_RSP_WAIT_CHAL, MT2_PEER_DEAUTH,
64 (STATE_MACHINE_FUNC) PeerDeauthAction);
65
66}
67
68/*
69 ==========================================================================
70 Description:
71
72 IRQL = DISPATCH_LEVEL
73
74 ==========================================================================
75*/
76void PeerAuthSimpleRspGenAndSend(struct rt_rtmp_adapter *pAd,
77 struct rt_header_802_11 * pHdr80211,
78 u16 Alg,
79 u16 Seq,
80 u16 Reason, u16 Status)
81{
82 struct rt_header_802_11 AuthHdr;
83 unsigned long FrameLen = 0;
84 u8 *pOutBuffer = NULL;
85 int NStatus;
86
87 if (Reason != MLME_SUCCESS) {
88 DBGPRINT(RT_DEBUG_TRACE, ("Peer AUTH fail...\n"));
89 return;
90 }
91 /*Get an unused nonpaged memory */
92 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
93 if (NStatus != NDIS_STATUS_SUCCESS)
94 return;
95
96 DBGPRINT(RT_DEBUG_TRACE, ("Send AUTH response (seq#2)...\n"));
97 MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, pHdr80211->Addr2,
98 pAd->MlmeAux.Bssid);
99 MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11),
100 &AuthHdr, 2, &Alg, 2, &Seq, 2, &Reason, END_OF_ARGS);
101 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
102 MlmeFreeMemory(pAd, pOutBuffer);
103}
104
105/*
106 ==========================================================================
107 Description:
108
109 IRQL = DISPATCH_LEVEL
110
111 ==========================================================================
112*/
113void PeerDeauthAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
114{
115 u8 Addr2[MAC_ADDR_LEN];
116 u16 Reason;
117
118 if (PeerDeauthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason)) {
119 if (INFRA_ON(pAd)
120 && MAC_ADDR_EQUAL(Addr2, pAd->CommonCfg.Bssid)
121 ) {
122 DBGPRINT(RT_DEBUG_TRACE,
123 ("AUTH_RSP - receive DE-AUTH from our AP (Reason=%d)\n",
124 Reason));
125
126 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL,
127 0);
128
129 /* send wireless event - for deauthentication */
130 if (pAd->CommonCfg.bWirelessEvent)
131 RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG,
132 pAd->MacTab.
133 Content[BSSID_WCID].Addr,
134 BSS0, 0);
135
136 LinkDown(pAd, TRUE);
137 }
138 } else {
139 DBGPRINT(RT_DEBUG_TRACE,
140 ("AUTH_RSP - PeerDeauthAction() sanity check fail\n"));
141 }
142}
diff --git a/drivers/staging/rt2860/sta/connect.c b/drivers/staging/rt2860/sta/connect.c
deleted file mode 100644
index 4996258f6ec..00000000000
--- a/drivers/staging/rt2860/sta/connect.c
+++ /dev/null
@@ -1,2613 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 connect.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John 2004-08-08 Major modification from RT2560
36 Justin P. Mattock 11/07/2010 Fix typos
37*/
38#include "../rt_config.h"
39
40u8 CipherSuiteWpaNoneTkip[] = {
41 0x00, 0x50, 0xf2, 0x01, /* oui */
42 0x01, 0x00, /* Version */
43 0x00, 0x50, 0xf2, 0x02, /* Multicast */
44 0x01, 0x00, /* Number of unicast */
45 0x00, 0x50, 0xf2, 0x02, /* unicast */
46 0x01, 0x00, /* number of authentication method */
47 0x00, 0x50, 0xf2, 0x00 /* authentication */
48};
49
50u8 CipherSuiteWpaNoneTkipLen =
51 (sizeof(CipherSuiteWpaNoneTkip) / sizeof(u8));
52
53u8 CipherSuiteWpaNoneAes[] = {
54 0x00, 0x50, 0xf2, 0x01, /* oui */
55 0x01, 0x00, /* Version */
56 0x00, 0x50, 0xf2, 0x04, /* Multicast */
57 0x01, 0x00, /* Number of unicast */
58 0x00, 0x50, 0xf2, 0x04, /* unicast */
59 0x01, 0x00, /* number of authentication method */
60 0x00, 0x50, 0xf2, 0x00 /* authentication */
61};
62
63u8 CipherSuiteWpaNoneAesLen =
64 (sizeof(CipherSuiteWpaNoneAes) / sizeof(u8));
65
66/* The following MACRO is called after 1. starting an new IBSS, 2. successfully JOIN an IBSS, */
67/* or 3. successfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS */
68/* All settings successfuly negotiated firing MLME state machines become final settings */
69/* and are copied to pAd->StaActive */
70#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
71{ \
72 NdisZeroMemory((_pAd)->CommonCfg.Ssid, MAX_LEN_OF_SSID); \
73 (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \
74 NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \
75 COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \
76 (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \
77 (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \
78 (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \
79 (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \
80 (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \
81 (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \
82 (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \
83 (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \
84 (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \
85 NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\
86 (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \
87 NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\
88 NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(struct rt_edca_parm));\
89 NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(struct rt_qos_capability_parm));\
90 NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(struct rt_qbss_load_parm));\
91 COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \
92 (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \
93 (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\
94 COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\
95 (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\
96}
97
98/*
99 ==========================================================================
100 Description:
101
102 IRQL = PASSIVE_LEVEL
103
104 ==========================================================================
105*/
106void MlmeCntlInit(struct rt_rtmp_adapter *pAd,
107 struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[])
108{
109 /* Control state machine differs from other state machines, the interface */
110 /* follows the standard interface */
111 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
112}
113
114/*
115 ==========================================================================
116 Description:
117
118 IRQL = DISPATCH_LEVEL
119
120 ==========================================================================
121*/
122void MlmeCntlMachinePerformAction(struct rt_rtmp_adapter *pAd,
123 struct rt_state_machine *S,
124 struct rt_mlme_queue_elem *Elem)
125{
126 switch (pAd->Mlme.CntlMachine.CurrState) {
127 case CNTL_IDLE:
128 CntlIdleProc(pAd, Elem);
129 break;
130 case CNTL_WAIT_DISASSOC:
131 CntlWaitDisassocProc(pAd, Elem);
132 break;
133 case CNTL_WAIT_JOIN:
134 CntlWaitJoinProc(pAd, Elem);
135 break;
136
137 /* CNTL_WAIT_REASSOC is the only state in CNTL machine that does */
138 /* not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)". */
139 /* Therefore not protected by NDIS's "only one outstanding OID request" */
140 /* rule. Which means NDIS may SET OID in the middle of ROAMing attempts. */
141 /* Current approach is to block new SET request at RTMPSetInformation() */
142 /* when CntlMachine.CurrState is not CNTL_IDLE */
143 case CNTL_WAIT_REASSOC:
144 CntlWaitReassocProc(pAd, Elem);
145 break;
146
147 case CNTL_WAIT_START:
148 CntlWaitStartProc(pAd, Elem);
149 break;
150 case CNTL_WAIT_AUTH:
151 CntlWaitAuthProc(pAd, Elem);
152 break;
153 case CNTL_WAIT_AUTH2:
154 CntlWaitAuthProc2(pAd, Elem);
155 break;
156 case CNTL_WAIT_ASSOC:
157 CntlWaitAssocProc(pAd, Elem);
158 break;
159
160 case CNTL_WAIT_OID_LIST_SCAN:
161 if (Elem->MsgType == MT2_SCAN_CONF) {
162 /* Resume TxRing after SCANING complete. We hope the out-of-service time */
163 /* won't be too long to let upper layer time-out the waiting frames */
164 RTMPResumeMsduTransmission(pAd);
165
166 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
167
168 /* */
169 /* Set LED status to previous status. */
170 /* */
171 if (pAd->bLedOnScanning) {
172 pAd->bLedOnScanning = FALSE;
173 RTMPSetLED(pAd, pAd->LedStatus);
174 }
175 }
176 break;
177
178 case CNTL_WAIT_OID_DISASSOC:
179 if (Elem->MsgType == MT2_DISASSOC_CONF) {
180 LinkDown(pAd, FALSE);
181 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
182 }
183 break;
184#ifdef RTMP_MAC_USB
185 /* */
186 /* This state is for that we want to connect to an AP but */
187 /* it didn't find on BSS List table. So we need to scan the air first, */
188 /* after that we can try to connect to the desired AP if available. */
189 /* */
190 case CNTL_WAIT_SCAN_FOR_CONNECT:
191 if (Elem->MsgType == MT2_SCAN_CONF) {
192 /* Resume TxRing after SCANING complete. We hope the out-of-service time */
193 /* won't be too long to let upper layer time-out the waiting frames */
194 RTMPResumeMsduTransmission(pAd);
195#ifdef CCX_SUPPORT
196 if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) {
197 /* Cisco scan request is finished, prepare beacon report */
198 MlmeEnqueue(pAd, AIRONET_STATE_MACHINE,
199 MT2_AIRONET_SCAN_DONE, 0, NULL);
200 }
201#endif /* CCX_SUPPORT // */
202 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
203
204 /* */
205 /* Check if we can connect to. */
206 /* */
207 BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab,
208 (char *) pAd->MlmeAux.
209 AutoReconnectSsid,
210 pAd->MlmeAux.AutoReconnectSsidLen);
211 if (pAd->MlmeAux.SsidBssTab.BssNr > 0) {
212 MlmeAutoReconnectLastSSID(pAd);
213 }
214 }
215 break;
216#endif /* RTMP_MAC_USB // */
217 default:
218 DBGPRINT_ERR("ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType);
219 break;
220 }
221}
222
223/*
224 ==========================================================================
225 Description:
226
227 IRQL = DISPATCH_LEVEL
228
229 ==========================================================================
230*/
231void CntlIdleProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
232{
233 struct rt_mlme_disassoc_req DisassocReq;
234
235 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
236 return;
237
238 switch (Elem->MsgType) {
239 case OID_802_11_SSID:
240 CntlOidSsidProc(pAd, Elem);
241 break;
242
243 case OID_802_11_BSSID:
244 CntlOidRTBssidProc(pAd, Elem);
245 break;
246
247 case OID_802_11_BSSID_LIST_SCAN:
248 CntlOidScanProc(pAd, Elem);
249 break;
250
251 case OID_802_11_DISASSOCIATE:
252 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid,
253 REASON_DISASSOC_STA_LEAVING);
254 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
255 sizeof(struct rt_mlme_disassoc_req), &DisassocReq);
256 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
257
258 if (pAd->StaCfg.WpaSupplicantUP !=
259 WPA_SUPPLICANT_ENABLE_WITH_WEB_UI) {
260 /* Set the AutoReconnectSsid to prevent it reconnect to old SSID */
261 /* Since calling this indicate user don't want to connect to that SSID anymore. */
262 pAd->MlmeAux.AutoReconnectSsidLen = 32;
263 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid,
264 pAd->MlmeAux.AutoReconnectSsidLen);
265 }
266 break;
267
268 case MT2_MLME_ROAMING_REQ:
269 CntlMlmeRoamingProc(pAd, Elem);
270 break;
271
272 case OID_802_11_MIC_FAILURE_REPORT_FRAME:
273 WpaMicFailureReportFrame(pAd, Elem);
274 break;
275
276 default:
277 DBGPRINT(RT_DEBUG_TRACE,
278 ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",
279 Elem->MsgType));
280 break;
281 }
282}
283
284void CntlOidScanProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
285{
286 struct rt_mlme_scan_req ScanReq;
287 unsigned long BssIdx = BSS_NOT_FOUND;
288 struct rt_bss_entry CurrBss;
289
290 /* record current BSS if network is connected. */
291 /* 2003-2-13 do not include current IBSS if this is the only STA in this IBSS. */
292 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
293 BssIdx =
294 BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid,
295 (u8 *)pAd->CommonCfg.Ssid,
296 pAd->CommonCfg.SsidLen,
297 pAd->CommonCfg.Channel);
298 if (BssIdx != BSS_NOT_FOUND) {
299 NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx],
300 sizeof(struct rt_bss_entry));
301 }
302 }
303 /* clean up previous SCAN result, add current BSS back to table if any */
304 BssTableInit(&pAd->ScanTab);
305 if (BssIdx != BSS_NOT_FOUND) {
306 /* DDK Note: If the NIC is associated with a particular BSSID and SSID */
307 /* that are not contained in the list of BSSIDs generated by this scan, the */
308 /* BSSID description of the currently associated BSSID and SSID should be */
309 /* appended to the list of BSSIDs in the NIC's database. */
310 /* To ensure this, we append this BSS as the first entry in SCAN result */
311 NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss,
312 sizeof(struct rt_bss_entry));
313 pAd->ScanTab.BssNr = 1;
314 }
315
316 ScanParmFill(pAd, &ScanReq, (char *)Elem->Msg, Elem->MsgLen, BSS_ANY,
317 SCAN_ACTIVE);
318 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
319 sizeof(struct rt_mlme_scan_req), &ScanReq);
320 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
321}
322
323/*
324 ==========================================================================
325 Description:
326 Before calling this routine, user desired SSID should already been
327 recorded in CommonCfg.Ssid[]
328 IRQL = DISPATCH_LEVEL
329
330 ==========================================================================
331*/
332void CntlOidSsidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
333{
334 struct rt_ndis_802_11_ssid * pOidSsid = (struct rt_ndis_802_11_ssid *) Elem->Msg;
335 struct rt_mlme_disassoc_req DisassocReq;
336 unsigned long Now;
337
338 /* Step 1. record the desired user settings to MlmeAux */
339 NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
340 NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength);
341 pAd->MlmeAux.SsidLen = (u8)pOidSsid->SsidLength;
342 NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
343 pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
344
345 pAd->StaCfg.bAutoConnectByBssid = FALSE;
346
347 /* */
348 /* Update Reconnect Ssid, that user desired to connect. */
349 /* */
350 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
351 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid,
352 pAd->MlmeAux.SsidLen);
353 pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
354
355 /* step 2. find all matching BSS in the lastest SCAN result (inBssTab) */
356 /* & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order */
357 BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab,
358 (char *)pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
359
360 DBGPRINT(RT_DEBUG_TRACE,
361 ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n",
362 pAd->MlmeAux.SsidBssTab.BssNr, pAd->ScanTab.BssNr,
363 pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid));
364 NdisGetSystemUpTime(&Now);
365
366 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
367 (pAd->CommonCfg.SsidLen ==
368 pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen)
369 && NdisEqualMemory(pAd->CommonCfg.Ssid,
370 pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid,
371 pAd->CommonCfg.SsidLen)
372 && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid,
373 pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid)) {
374 /* Case 1. already connected with an AP who has the desired SSID */
375 /* with highest RSSI */
376
377 /* Add checking Mode "LEAP" for CCX 1.0 */
378 if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
379 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
380 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
381 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
382 ) &&
383 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) {
384 /* case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo */
385 /* connection process */
386 DBGPRINT(RT_DEBUG_TRACE,
387 ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
388 DisassocParmFill(pAd, &DisassocReq,
389 pAd->CommonCfg.Bssid,
390 REASON_DISASSOC_STA_LEAVING);
391 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
392 MT2_MLME_DISASSOC_REQ,
393 sizeof(struct rt_mlme_disassoc_req),
394 &DisassocReq);
395 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
396 } else if (pAd->bConfigChanged == TRUE) {
397 /* case 1.2 Important Config has changed, we have to reconnect to the same AP */
398 DBGPRINT(RT_DEBUG_TRACE,
399 ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));
400 DisassocParmFill(pAd, &DisassocReq,
401 pAd->CommonCfg.Bssid,
402 REASON_DISASSOC_STA_LEAVING);
403 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
404 MT2_MLME_DISASSOC_REQ,
405 sizeof(struct rt_mlme_disassoc_req),
406 &DisassocReq);
407 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
408 } else {
409 /* case 1.3. already connected to the SSID with highest RSSI. */
410 DBGPRINT(RT_DEBUG_TRACE,
411 ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n"));
412 /* */
413 /* (HCT 12.1) 1c_wlan_mediaevents required */
414 /* media connect events are indicated when associating with the same AP */
415 /* */
416 if (INFRA_ON(pAd)) {
417 /* */
418 /* Since MediaState already is NdisMediaStateConnected */
419 /* We just indicate the connect event again to meet the WHQL required. */
420 /* */
421 pAd->IndicateMediaState =
422 NdisMediaStateConnected;
423 RTMP_IndicateMediaState(pAd);
424 pAd->ExtraInfo = GENERAL_LINK_UP; /* Update extra information to link is up */
425 }
426
427 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
428 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1,
429 &pAd->MlmeAux.Bssid[0], NULL,
430 0);
431 }
432 } else if (INFRA_ON(pAd)) {
433 /* */
434 /* For RT61 */
435 /* [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: ) */
436 /* RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect */
437 /* But media status is connected, so the SSID not report correctly. */
438 /* */
439 if (!SSID_EQUAL
440 (pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen,
441 pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen)) {
442 /* */
443 /* Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event. */
444 /* */
445 pAd->MlmeAux.CurrReqIsFromNdis = TRUE;
446 }
447 /* case 2. active INFRA association existent */
448 /* roaming is done within miniport driver, nothing to do with configuration */
449 /* utility. so upon a new SET(OID_802_11_SSID) is received, we just */
450 /* disassociate with the current associated AP, */
451 /* then perform a new association with this new SSID, no matter the */
452 /* new/old SSID are the same or not. */
453 DBGPRINT(RT_DEBUG_TRACE,
454 ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
455 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid,
456 REASON_DISASSOC_STA_LEAVING);
457 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
458 sizeof(struct rt_mlme_disassoc_req), &DisassocReq);
459 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
460 } else {
461 if (ADHOC_ON(pAd)) {
462 DBGPRINT(RT_DEBUG_TRACE,
463 ("CntlOidSsidProc():CNTL - drop current ADHOC\n"));
464 LinkDown(pAd, FALSE);
465 OPSTATUS_CLEAR_FLAG(pAd,
466 fOP_STATUS_MEDIA_STATE_CONNECTED);
467 pAd->IndicateMediaState = NdisMediaStateDisconnected;
468 RTMP_IndicateMediaState(pAd);
469 pAd->ExtraInfo = GENERAL_LINK_DOWN;
470 DBGPRINT(RT_DEBUG_TRACE,
471 ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
472 }
473
474 if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) &&
475 (pAd->StaCfg.bAutoReconnect == TRUE) &&
476 (pAd->MlmeAux.BssType == BSS_INFRA) &&
477 (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen)
478 == TRUE)
479 ) {
480 struct rt_mlme_scan_req ScanReq;
481
482 DBGPRINT(RT_DEBUG_TRACE,
483 ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n"));
484 ScanParmFill(pAd, &ScanReq, (char *)pAd->MlmeAux.Ssid,
485 pAd->MlmeAux.SsidLen, BSS_ANY,
486 SCAN_ACTIVE);
487 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
488 sizeof(struct rt_mlme_scan_req), &ScanReq);
489 pAd->Mlme.CntlMachine.CurrState =
490 CNTL_WAIT_OID_LIST_SCAN;
491 /* Reset Missed scan number */
492 pAd->StaCfg.LastScanTime = Now;
493 } else {
494 pAd->MlmeAux.BssIdx = 0;
495 IterateOnBssTab(pAd);
496 }
497 }
498}
499
500/*
501 ==========================================================================
502 Description:
503
504 IRQL = DISPATCH_LEVEL
505
506 ==========================================================================
507*/
508void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
509{
510 unsigned long BssIdx;
511 u8 *pOidBssid = (u8 *)Elem->Msg;
512 struct rt_mlme_disassoc_req DisassocReq;
513 struct rt_mlme_join_req JoinReq;
514
515 /* record user desired settings */
516 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);
517 pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
518
519 /* find the desired BSS in the latest SCAN result table */
520 BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel);
521 if (BssIdx == BSS_NOT_FOUND) {
522 struct rt_mlme_scan_req ScanReq;
523
524 DBGPRINT(RT_DEBUG_TRACE,
525 ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"));
526 /*pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; */
527
528 DBGPRINT(RT_DEBUG_TRACE,
529 ("CNTL - BSSID not found. start a new scan\n"));
530 ScanParmFill(pAd, &ScanReq, (char *)pAd->MlmeAux.Ssid,
531 pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE);
532 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
533 sizeof(struct rt_mlme_scan_req), &ScanReq);
534 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
535 /* Reset Missed scan number */
536 NdisGetSystemUpTime(&pAd->StaCfg.LastScanTime);
537 return;
538 }
539 /* */
540 /* Update Reconnect Ssid, that user desired to connect. */
541 /* */
542 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
543 pAd->MlmeAux.AutoReconnectSsidLen =
544 pAd->ScanTab.BssEntry[BssIdx].SsidLen;
545 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid,
546 pAd->ScanTab.BssEntry[BssIdx].Ssid,
547 pAd->ScanTab.BssEntry[BssIdx].SsidLen);
548
549 /* copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why? */
550 /* Because we need this entry to become the JOIN target in later on SYNC state machine */
551 pAd->MlmeAux.BssIdx = 0;
552 pAd->MlmeAux.SsidBssTab.BssNr = 1;
553 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0],
554 &pAd->ScanTab.BssEntry[BssIdx], sizeof(struct rt_bss_entry));
555
556 /* Add SSID into MlmeAux for site survey joining hidden SSID */
557 pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
558 NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid,
559 pAd->MlmeAux.SsidLen);
560
561 {
562 if (INFRA_ON(pAd)) {
563 /* disassoc from current AP first */
564 DBGPRINT(RT_DEBUG_TRACE,
565 ("CNTL - disassociate with current AP ...\n"));
566 DisassocParmFill(pAd, &DisassocReq,
567 pAd->CommonCfg.Bssid,
568 REASON_DISASSOC_STA_LEAVING);
569 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
570 MT2_MLME_DISASSOC_REQ,
571 sizeof(struct rt_mlme_disassoc_req),
572 &DisassocReq);
573
574 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
575 } else {
576 if (ADHOC_ON(pAd)) {
577 DBGPRINT(RT_DEBUG_TRACE,
578 ("CNTL - drop current ADHOC\n"));
579 LinkDown(pAd, FALSE);
580 OPSTATUS_CLEAR_FLAG(pAd,
581 fOP_STATUS_MEDIA_STATE_CONNECTED);
582 pAd->IndicateMediaState =
583 NdisMediaStateDisconnected;
584 RTMP_IndicateMediaState(pAd);
585 pAd->ExtraInfo = GENERAL_LINK_DOWN;
586 DBGPRINT(RT_DEBUG_TRACE,
587 ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
588 }
589 /* Change the wepstatus to original wepstatus */
590 pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
591 pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
592 pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
593
594 /* Check cipher suite, AP must have more secured cipher than station setting */
595 /* Set the Pairwise and Group cipher to match the intended AP setting */
596 /* We can only connect to AP with less secured cipher setting */
597 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA)
598 || (pAd->StaCfg.AuthMode ==
599 Ndis802_11AuthModeWPAPSK)) {
600 pAd->StaCfg.GroupCipher =
601 pAd->ScanTab.BssEntry[BssIdx].WPA.
602 GroupCipher;
603
604 if (pAd->StaCfg.WepStatus ==
605 pAd->ScanTab.BssEntry[BssIdx].WPA.
606 PairCipher)
607 pAd->StaCfg.PairCipher =
608 pAd->ScanTab.BssEntry[BssIdx].WPA.
609 PairCipher;
610 else if (pAd->ScanTab.BssEntry[BssIdx].WPA.
611 PairCipherAux != Ndis802_11WEPDisabled)
612 pAd->StaCfg.PairCipher =
613 pAd->ScanTab.BssEntry[BssIdx].WPA.
614 PairCipherAux;
615 else /* There is no PairCipher Aux, downgrade our capability to TKIP */
616 pAd->StaCfg.PairCipher =
617 Ndis802_11Encryption2Enabled;
618 } else
619 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
620 || (pAd->StaCfg.AuthMode ==
621 Ndis802_11AuthModeWPA2PSK)) {
622 pAd->StaCfg.GroupCipher =
623 pAd->ScanTab.BssEntry[BssIdx].WPA2.
624 GroupCipher;
625
626 if (pAd->StaCfg.WepStatus ==
627 pAd->ScanTab.BssEntry[BssIdx].WPA2.
628 PairCipher)
629 pAd->StaCfg.PairCipher =
630 pAd->ScanTab.BssEntry[BssIdx].WPA2.
631 PairCipher;
632 else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.
633 PairCipherAux != Ndis802_11WEPDisabled)
634 pAd->StaCfg.PairCipher =
635 pAd->ScanTab.BssEntry[BssIdx].WPA2.
636 PairCipherAux;
637 else /* There is no PairCipher Aux, downgrade our capability to TKIP */
638 pAd->StaCfg.PairCipher =
639 Ndis802_11Encryption2Enabled;
640
641 /* RSN capability */
642 pAd->StaCfg.RsnCapability =
643 pAd->ScanTab.BssEntry[BssIdx].WPA2.
644 RsnCapability;
645 }
646 /* Set Mix cipher flag */
647 pAd->StaCfg.bMixCipher =
648 (pAd->StaCfg.PairCipher ==
649 pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
650 /*if (pAd->StaCfg.bMixCipher == TRUE)
651 {
652 // If mix cipher, re-build RSNIE
653 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
654 } */
655 /* No active association, join the BSS immediately */
656 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - joining %pM ...\n",
657 pOidBssid));
658
659 JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx);
660 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ,
661 sizeof(struct rt_mlme_join_req), &JoinReq);
662
663 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
664 }
665 }
666}
667
668/* Roaming is the only external request triggering CNTL state machine */
669/* despite of other "SET OID" operation. All "SET OID" related operations */
670/* happen in sequence, because no other SET OID will be sent to this device */
671/* until the the previous SET operation is complete (successful o failed). */
672/* So, how do we quarantee this ROAMING request won't corrupt other "SET OID"? */
673/* or been corrupted by other "SET OID"? */
674/* */
675/* IRQL = DISPATCH_LEVEL */
676void CntlMlmeRoamingProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
677{
678 u8 BBPValue = 0;
679
680 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Roaming in MlmeAux.RoamTab...\n"));
681
682 {
683 /*Let BBP register at 20MHz to do (fast) roaming. */
684 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
685 BBPValue &= (~0x18);
686 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
687
688 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab,
689 sizeof(pAd->MlmeAux.RoamTab));
690 pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr;
691
692 BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab);
693 pAd->MlmeAux.BssIdx = 0;
694 IterateOnBssTab(pAd);
695 }
696}
697
698/*
699 ==========================================================================
700 Description:
701
702 IRQL = DISPATCH_LEVEL
703
704 ==========================================================================
705*/
706void CntlWaitDisassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
707{
708 struct rt_mlme_start_req StartReq;
709
710 if (Elem->MsgType == MT2_DISASSOC_CONF) {
711 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n"));
712
713 if (pAd->CommonCfg.bWirelessEvent) {
714 RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG,
715 pAd->MacTab.Content[BSSID_WCID].
716 Addr, BSS0, 0);
717 }
718
719 LinkDown(pAd, FALSE);
720
721 /* case 1. no matching BSS, and user wants ADHOC, so we just start a new one */
722 if ((pAd->MlmeAux.SsidBssTab.BssNr == 0)
723 && (pAd->StaCfg.BssType == BSS_ADHOC)) {
724 DBGPRINT(RT_DEBUG_TRACE,
725 ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",
726 pAd->MlmeAux.Ssid));
727 StartParmFill(pAd, &StartReq, (char *)pAd->MlmeAux.Ssid,
728 pAd->MlmeAux.SsidLen);
729 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ,
730 sizeof(struct rt_mlme_start_req), &StartReq);
731 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
732 }
733 /* case 2. try each matched BSS */
734 else {
735 pAd->MlmeAux.BssIdx = 0;
736
737 IterateOnBssTab(pAd);
738 }
739 }
740}
741
742/*
743 ==========================================================================
744 Description:
745
746 IRQL = DISPATCH_LEVEL
747
748 ==========================================================================
749*/
750void CntlWaitJoinProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
751{
752 u16 Reason;
753 struct rt_mlme_auth_req AuthReq;
754
755 if (Elem->MsgType == MT2_JOIN_CONF) {
756 NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16));
757 if (Reason == MLME_SUCCESS) {
758 /* 1. joined an IBSS, we are pretty much done here */
759 if (pAd->MlmeAux.BssType == BSS_ADHOC) {
760 /* */
761 /* 5G bands rules of Japan: */
762 /* Ad hoc must be disabled in W53(ch52,56,60,64) channels. */
763 /* */
764 if ((pAd->CommonCfg.bIEEE80211H == 1) &&
765 RadarChannelCheck(pAd,
766 pAd->CommonCfg.Channel)
767 ) {
768 pAd->Mlme.CntlMachine.CurrState =
769 CNTL_IDLE;
770 DBGPRINT(RT_DEBUG_TRACE,
771 ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n",
772 pAd->CommonCfg.Channel));
773 return;
774 }
775
776 LinkUp(pAd, BSS_ADHOC);
777 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
778 DBGPRINT(RT_DEBUG_TRACE,
779 ("CNTL - join the IBSS = %pM ...\n",
780 pAd->CommonCfg.Bssid));
781
782 pAd->IndicateMediaState =
783 NdisMediaStateConnected;
784 pAd->ExtraInfo = GENERAL_LINK_UP;
785 }
786 /* 2. joined a new INFRA network, start from authentication */
787 else {
788 {
789 /* either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first */
790 if ((pAd->StaCfg.AuthMode ==
791 Ndis802_11AuthModeShared)
792 || (pAd->StaCfg.AuthMode ==
793 Ndis802_11AuthModeAutoSwitch)) {
794 AuthParmFill(pAd, &AuthReq,
795 pAd->MlmeAux.Bssid,
796 AUTH_MODE_KEY);
797 } else {
798 AuthParmFill(pAd, &AuthReq,
799 pAd->MlmeAux.Bssid,
800 AUTH_MODE_OPEN);
801 }
802 MlmeEnqueue(pAd, AUTH_STATE_MACHINE,
803 MT2_MLME_AUTH_REQ,
804 sizeof
805 (struct rt_mlme_auth_req),
806 &AuthReq);
807 }
808
809 pAd->Mlme.CntlMachine.CurrState =
810 CNTL_WAIT_AUTH;
811 }
812 } else {
813 /* 3. failed, try next BSS */
814 pAd->MlmeAux.BssIdx++;
815 IterateOnBssTab(pAd);
816 }
817 }
818}
819
820/*
821 ==========================================================================
822 Description:
823
824 IRQL = DISPATCH_LEVEL
825
826 ==========================================================================
827*/
828void CntlWaitStartProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
829{
830 u16 Result;
831
832 if (Elem->MsgType == MT2_START_CONF) {
833 NdisMoveMemory(&Result, Elem->Msg, sizeof(u16));
834 if (Result == MLME_SUCCESS) {
835 /* */
836 /* 5G bands rules of Japan: */
837 /* Ad hoc must be disabled in W53(ch52,56,60,64) channels. */
838 /* */
839 if ((pAd->CommonCfg.bIEEE80211H == 1) &&
840 RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
841 ) {
842 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
843 DBGPRINT(RT_DEBUG_TRACE,
844 ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n",
845 pAd->CommonCfg.Channel));
846 return;
847 }
848 NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo.
849 MCSSet[0], 16);
850 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) {
851 N_ChannelCheck(pAd);
852 SetCommonHT(pAd);
853 NdisMoveMemory(&pAd->MlmeAux.AddHtInfo,
854 &pAd->CommonCfg.AddHTInfo,
855 sizeof(struct rt_add_ht_info_ie));
856 RTMPCheckHt(pAd, BSSID_WCID,
857 &pAd->CommonCfg.HtCapability,
858 &pAd->CommonCfg.AddHTInfo);
859 pAd->StaActive.SupportedPhyInfo.bHtEnable =
860 TRUE;
861 NdisMoveMemory(&pAd->StaActive.SupportedPhyInfo.
862 MCSSet[0],
863 &pAd->CommonCfg.HtCapability.
864 MCSSet[0], 16);
865 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG
866 (pAd);
867
868 if ((pAd->CommonCfg.HtCapability.HtCapInfo.
869 ChannelWidth == BW_40)
870 && (pAd->CommonCfg.AddHTInfo.AddHtInfo.
871 ExtChanOffset == EXTCHA_ABOVE)) {
872 pAd->MlmeAux.CentralChannel =
873 pAd->CommonCfg.Channel + 2;
874 } else
875 if ((pAd->CommonCfg.HtCapability.HtCapInfo.
876 ChannelWidth == BW_40)
877 && (pAd->CommonCfg.AddHTInfo.AddHtInfo.
878 ExtChanOffset == EXTCHA_BELOW)) {
879 pAd->MlmeAux.CentralChannel =
880 pAd->CommonCfg.Channel - 2;
881 }
882 } else {
883 pAd->StaActive.SupportedPhyInfo.bHtEnable =
884 FALSE;
885 }
886 LinkUp(pAd, BSS_ADHOC);
887 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
888 /* Before send beacon, driver need do radar detection */
889 if ((pAd->CommonCfg.Channel > 14)
890 && (pAd->CommonCfg.bIEEE80211H == 1)
891 && RadarChannelCheck(pAd, pAd->CommonCfg.Channel)) {
892 pAd->CommonCfg.RadarDetect.RDMode =
893 RD_SILENCE_MODE;
894 pAd->CommonCfg.RadarDetect.RDCount = 0;
895 }
896
897 DBGPRINT(RT_DEBUG_TRACE,
898 ("CNTL - start a new IBSS = %pM ...\n",
899 pAd->CommonCfg.Bssid));
900 } else {
901 DBGPRINT(RT_DEBUG_TRACE,
902 ("CNTL - Start IBSS fail. BUG!\n"));
903 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
904 }
905 }
906}
907
908/*
909 ==========================================================================
910 Description:
911
912 IRQL = DISPATCH_LEVEL
913
914 ==========================================================================
915*/
916void CntlWaitAuthProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
917{
918 u16 Reason;
919 struct rt_mlme_assoc_req AssocReq;
920 struct rt_mlme_auth_req AuthReq;
921
922 if (Elem->MsgType == MT2_AUTH_CONF) {
923 NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16));
924 if (Reason == MLME_SUCCESS) {
925 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
926 AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid,
927 pAd->MlmeAux.CapabilityInfo,
928 ASSOC_TIMEOUT,
929 pAd->StaCfg.DefaultListenCount);
930
931 {
932 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
933 MT2_MLME_ASSOC_REQ,
934 sizeof(struct rt_mlme_assoc_req),
935 &AssocReq);
936
937 pAd->Mlme.CntlMachine.CurrState =
938 CNTL_WAIT_ASSOC;
939 }
940 } else {
941 /* This fail may because of the AP already keep us in its MAC table without */
942 /* ageing-out. The previous authentication attempt must have let it remove us. */
943 /* so try Authentication again may help. For D-Link DWL-900AP+ compatibility. */
944 DBGPRINT(RT_DEBUG_TRACE,
945 ("CNTL - AUTH FAIL, try again...\n"));
946
947 {
948 if ((pAd->StaCfg.AuthMode ==
949 Ndis802_11AuthModeShared)
950 || (pAd->StaCfg.AuthMode ==
951 Ndis802_11AuthModeAutoSwitch)) {
952 /* either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first */
953 AuthParmFill(pAd, &AuthReq,
954 pAd->MlmeAux.Bssid,
955 AUTH_MODE_KEY);
956 } else {
957 AuthParmFill(pAd, &AuthReq,
958 pAd->MlmeAux.Bssid,
959 AUTH_MODE_OPEN);
960 }
961 MlmeEnqueue(pAd, AUTH_STATE_MACHINE,
962 MT2_MLME_AUTH_REQ,
963 sizeof(struct rt_mlme_auth_req),
964 &AuthReq);
965
966 }
967 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
968 }
969 }
970}
971
972/*
973 ==========================================================================
974 Description:
975
976 IRQL = DISPATCH_LEVEL
977
978 ==========================================================================
979*/
980void CntlWaitAuthProc2(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
981{
982 u16 Reason;
983 struct rt_mlme_assoc_req AssocReq;
984 struct rt_mlme_auth_req AuthReq;
985
986 if (Elem->MsgType == MT2_AUTH_CONF) {
987 NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16));
988 if (Reason == MLME_SUCCESS) {
989 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
990 AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid,
991 pAd->MlmeAux.CapabilityInfo,
992 ASSOC_TIMEOUT,
993 pAd->StaCfg.DefaultListenCount);
994 {
995 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
996 MT2_MLME_ASSOC_REQ,
997 sizeof(struct rt_mlme_assoc_req),
998 &AssocReq);
999
1000 pAd->Mlme.CntlMachine.CurrState =
1001 CNTL_WAIT_ASSOC;
1002 }
1003 } else {
1004 if ((pAd->StaCfg.AuthMode ==
1005 Ndis802_11AuthModeAutoSwitch)
1006 && (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared)) {
1007 DBGPRINT(RT_DEBUG_TRACE,
1008 ("CNTL - AUTH FAIL, try OPEN system...\n"));
1009 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid,
1010 Ndis802_11AuthModeOpen);
1011 MlmeEnqueue(pAd, AUTH_STATE_MACHINE,
1012 MT2_MLME_AUTH_REQ,
1013 sizeof(struct rt_mlme_auth_req),
1014 &AuthReq);
1015
1016 pAd->Mlme.CntlMachine.CurrState =
1017 CNTL_WAIT_AUTH2;
1018 } else {
1019 /* not success, try next BSS */
1020 DBGPRINT(RT_DEBUG_TRACE,
1021 ("CNTL - AUTH FAIL, give up; try next BSS\n"));
1022 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; /*??????? */
1023 pAd->MlmeAux.BssIdx++;
1024 IterateOnBssTab(pAd);
1025 }
1026 }
1027 }
1028}
1029
1030/*
1031 ==========================================================================
1032 Description:
1033
1034 IRQL = DISPATCH_LEVEL
1035
1036 ==========================================================================
1037*/
1038void CntlWaitAssocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1039{
1040 u16 Reason;
1041
1042 if (Elem->MsgType == MT2_ASSOC_CONF) {
1043 NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16));
1044 if (Reason == MLME_SUCCESS) {
1045 if (pAd->CommonCfg.bWirelessEvent) {
1046 RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG,
1047 pAd->MacTab.
1048 Content[BSSID_WCID].Addr,
1049 BSS0, 0);
1050 }
1051
1052 LinkUp(pAd, BSS_INFRA);
1053 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
1054 DBGPRINT(RT_DEBUG_TRACE,
1055 ("CNTL - Association successful on BSS #%ld\n",
1056 pAd->MlmeAux.BssIdx));
1057 } else {
1058 /* not success, try next BSS */
1059 DBGPRINT(RT_DEBUG_TRACE,
1060 ("CNTL - Association fails on BSS #%ld\n",
1061 pAd->MlmeAux.BssIdx));
1062 pAd->MlmeAux.BssIdx++;
1063 IterateOnBssTab(pAd);
1064 }
1065 }
1066}
1067
1068/*
1069 ==========================================================================
1070 Description:
1071
1072 IRQL = DISPATCH_LEVEL
1073
1074 ==========================================================================
1075*/
1076void CntlWaitReassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1077{
1078 u16 Result;
1079
1080 if (Elem->MsgType == MT2_REASSOC_CONF) {
1081 NdisMoveMemory(&Result, Elem->Msg, sizeof(u16));
1082 if (Result == MLME_SUCCESS) {
1083 /* send wireless event - for association */
1084 if (pAd->CommonCfg.bWirelessEvent)
1085 RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG,
1086 pAd->MacTab.
1087 Content[BSSID_WCID].Addr,
1088 BSS0, 0);
1089
1090 /* */
1091 /* NDIS requires a new Link UP indication but no Link Down for RE-ASSOC */
1092 /* */
1093 LinkUp(pAd, BSS_INFRA);
1094
1095 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
1096 DBGPRINT(RT_DEBUG_TRACE,
1097 ("CNTL - Re-assocition successful on BSS #%ld\n",
1098 pAd->MlmeAux.RoamIdx));
1099 } else {
1100 /* reassoc failed, try to pick next BSS in the BSS Table */
1101 DBGPRINT(RT_DEBUG_TRACE,
1102 ("CNTL - Re-assocition fails on BSS #%ld\n",
1103 pAd->MlmeAux.RoamIdx));
1104 {
1105 pAd->MlmeAux.RoamIdx++;
1106 IterateOnBssTab2(pAd);
1107 }
1108 }
1109 }
1110}
1111
1112void AdhocTurnOnQos(struct rt_rtmp_adapter *pAd)
1113{
1114#define AC0_DEF_TXOP 0
1115#define AC1_DEF_TXOP 0
1116#define AC2_DEF_TXOP 94
1117#define AC3_DEF_TXOP 47
1118
1119 /* Turn on QOs if use HT rate. */
1120 if (pAd->CommonCfg.APEdcaParm.bValid == FALSE) {
1121 pAd->CommonCfg.APEdcaParm.bValid = TRUE;
1122 pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
1123 pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
1124 pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
1125 pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
1126
1127 pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
1128 pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
1129 pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
1130 pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
1131
1132 pAd->CommonCfg.APEdcaParm.Cwmax[0] = 10;
1133 pAd->CommonCfg.APEdcaParm.Cwmax[1] = 6;
1134 pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
1135 pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
1136
1137 pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
1138 pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
1139 pAd->CommonCfg.APEdcaParm.Txop[2] = AC2_DEF_TXOP;
1140 pAd->CommonCfg.APEdcaParm.Txop[3] = AC3_DEF_TXOP;
1141 }
1142 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1143}
1144
1145/*
1146 ==========================================================================
1147 Description:
1148
1149 IRQL = DISPATCH_LEVEL
1150
1151 ==========================================================================
1152*/
1153void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType)
1154{
1155 unsigned long Now;
1156 u32 Data;
1157 BOOLEAN Cancelled;
1158 u8 Value = 0, idx = 0, HashIdx = 0;
1159 struct rt_mac_table_entry *pEntry = NULL, *pCurrEntry = NULL;
1160
1161 /* Init ChannelQuality to prevent DEAD_CQI at initial LinkUp */
1162 pAd->Mlme.ChannelQuality = 50;
1163
1164 pEntry = MacTableLookup(pAd, pAd->CommonCfg.Bssid);
1165 if (pEntry) {
1166 MacTableDeleteEntry(pAd, pEntry->Aid, pEntry->Addr);
1167 pEntry = NULL;
1168 }
1169
1170 pEntry = &pAd->MacTab.Content[BSSID_WCID];
1171
1172 /* */
1173 /* ASSOC - DisassocTimeoutAction */
1174 /* CNTL - Dis-associate successful */
1175 /* ! LINK DOWN ! */
1176 /* [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: ) */
1177 /* */
1178 /* To prevent DisassocTimeoutAction to call Link down after we link up, */
1179 /* cancel the DisassocTimer no matter what it start or not. */
1180 /* */
1181 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
1182
1183 COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
1184
1185 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
1186
1187#ifdef RTMP_MAC_PCI
1188 /* Before power save before link up function, We will force use 1R. */
1189 /* So after link up, check Rx antenna # again. */
1190 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1191 if (pAd->Antenna.field.RxPath == 3) {
1192 Value |= (0x10);
1193 } else if (pAd->Antenna.field.RxPath == 2) {
1194 Value |= (0x8);
1195 } else if (pAd->Antenna.field.RxPath == 1) {
1196 Value |= (0x0);
1197 }
1198 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1199 pAd->StaCfg.BBPR3 = Value;
1200#endif /* RTMP_MAC_PCI // */
1201
1202 if (BssType == BSS_ADHOC) {
1203 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1204 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
1205
1206 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
1207 AdhocTurnOnQos(pAd);
1208
1209 DBGPRINT(RT_DEBUG_TRACE, ("Adhoc LINK UP!\n"));
1210 } else {
1211 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON);
1212 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1213
1214 DBGPRINT(RT_DEBUG_TRACE, ("Infra LINK UP!\n"));
1215 }
1216
1217 /* 3*3 */
1218 /* reset Tx beamforming bit */
1219 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1220 Value &= (~0x01);
1221 Value |= pAd->CommonCfg.RegTransmitSetting.field.TxBF;
1222 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1223
1224 /* Change to AP channel */
1225 if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel)
1226 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40)) {
1227 /* Must use 40MHz. */
1228 pAd->CommonCfg.BBPCurrentBW = BW_40;
1229 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1230 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
1231
1232 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1233 Value &= (~0x18);
1234 Value |= 0x10;
1235 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1236
1237 /* RX : control channel at lower */
1238 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1239 Value &= (~0x20);
1240 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1241#ifdef RTMP_MAC_PCI
1242 pAd->StaCfg.BBPR3 = Value;
1243#endif /* RTMP_MAC_PCI // */
1244
1245 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1246 Data &= 0xfffffffe;
1247 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1248
1249 if (pAd->MACVersion == 0x28600100) {
1250 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
1251 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
1252 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
1253 DBGPRINT(RT_DEBUG_TRACE, ("rt2860C !\n"));
1254 }
1255
1256 DBGPRINT(RT_DEBUG_TRACE,
1257 ("40MHz Lower LINK UP! Control Channel at Below. Central = %d \n",
1258 pAd->CommonCfg.CentralChannel));
1259 } else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel)
1260 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth ==
1261 BW_40)) {
1262 /* Must use 40MHz. */
1263 pAd->CommonCfg.BBPCurrentBW = BW_40;
1264 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1265 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
1266
1267 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1268 Value &= (~0x18);
1269 Value |= 0x10;
1270 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1271
1272 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1273 Data |= 0x1;
1274 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1275
1276 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1277 Value |= (0x20);
1278 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1279#ifdef RTMP_MAC_PCI
1280 pAd->StaCfg.BBPR3 = Value;
1281#endif /* RTMP_MAC_PCI // */
1282
1283 if (pAd->MACVersion == 0x28600100) {
1284 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
1285 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
1286 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
1287 DBGPRINT(RT_DEBUG_TRACE, ("rt2860C !\n"));
1288 }
1289
1290 DBGPRINT(RT_DEBUG_TRACE,
1291 ("40MHz Upper LINK UP! Control Channel at UpperCentral = %d \n",
1292 pAd->CommonCfg.CentralChannel));
1293 } else {
1294 pAd->CommonCfg.BBPCurrentBW = BW_20;
1295 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
1296 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
1297 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
1298
1299 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1300 Value &= (~0x18);
1301 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1302
1303 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1304 Data &= 0xfffffffe;
1305 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1306
1307 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1308 Value &= (~0x20);
1309 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1310#ifdef RTMP_MAC_PCI
1311 pAd->StaCfg.BBPR3 = Value;
1312#endif /* RTMP_MAC_PCI // */
1313
1314 if (pAd->MACVersion == 0x28600100) {
1315 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
1316 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);
1317 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);
1318 DBGPRINT(RT_DEBUG_TRACE, ("rt2860C !\n"));
1319 }
1320
1321 DBGPRINT(RT_DEBUG_TRACE, ("20MHz LINK UP!\n"));
1322 }
1323
1324 RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
1325
1326 /* */
1327 /* Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission */
1328 /* */
1329 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66,
1330 &pAd->BbpTuning.R66CurrentValue);
1331
1332 DBGPRINT(RT_DEBUG_TRACE,
1333 ("LINK UP! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n",
1334 BssType, pAd->StaActive.Aid, pAd->CommonCfg.Ssid,
1335 pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
1336
1337 DBGPRINT(RT_DEBUG_TRACE,
1338 ("LINK UP! (Density =%d, )\n",
1339 pAd->MacTab.Content[BSSID_WCID].MpduDensity));
1340
1341 AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
1342
1343 AsicSetSlotTime(pAd, TRUE);
1344 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1345
1346 /* Call this for RTS protection for legacy rate, we will always enable RTS threshold, but normally it will not hit */
1347 AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE,
1348 FALSE);
1349
1350 if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)) {
1351 /* Update HT protection for based on AP's operating mode. */
1352 if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1) {
1353 AsicUpdateProtect(pAd,
1354 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1355 OperaionMode, ALLN_SETPROTECT, FALSE,
1356 TRUE);
1357 } else
1358 AsicUpdateProtect(pAd,
1359 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1360 OperaionMode, ALLN_SETPROTECT, FALSE,
1361 FALSE);
1362 }
1363
1364 NdisZeroMemory(&pAd->DrsCounters, sizeof(struct rt_counter_drs));
1365
1366 NdisGetSystemUpTime(&Now);
1367 pAd->StaCfg.LastBeaconRxTime = Now; /* last RX timestamp */
1368
1369 if ((pAd->CommonCfg.TxPreamble != Rt802_11PreambleLong) &&
1370 CAP_IS_SHORT_PREAMBLE_ON(pAd->StaActive.CapabilityInfo)) {
1371 MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
1372 }
1373
1374 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1375
1376 if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE) {
1377 }
1378 pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
1379
1380 if (BssType == BSS_ADHOC) {
1381 MakeIbssBeacon(pAd);
1382 if ((pAd->CommonCfg.Channel > 14)
1383 && (pAd->CommonCfg.bIEEE80211H == 1)
1384 && RadarChannelCheck(pAd, pAd->CommonCfg.Channel)) {
1385 ; /*Do nothing */
1386 } else {
1387 AsicEnableIbssSync(pAd);
1388 }
1389
1390 /* In ad hoc mode, use MAC table from index 1. */
1391 /* p.s ASIC use all 0xff as termination of WCID table search.To prevent it's 0xff-ff-ff-ff-ff-ff, Write 0 here. */
1392 RTMP_IO_WRITE32(pAd, MAC_WCID_BASE, 0x00);
1393 RTMP_IO_WRITE32(pAd, 0x1808, 0x00);
1394
1395 /* If WEP is enabled, add key material and cipherAlg into Asic */
1396 /* Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000) */
1397
1398 if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) {
1399 u8 *Key;
1400 u8 CipherAlg;
1401
1402 for (idx = 0; idx < SHARE_KEY_NUM; idx++) {
1403 CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
1404 Key = pAd->SharedKey[BSS0][idx].Key;
1405
1406 if (pAd->SharedKey[BSS0][idx].KeyLen > 0) {
1407 /* Set key material and cipherAlg to Asic */
1408 AsicAddSharedKeyEntry(pAd, BSS0, idx,
1409 CipherAlg, Key,
1410 NULL, NULL);
1411
1412 if (idx == pAd->StaCfg.DefaultKeyId) {
1413 /* Update WCID attribute table and IVEIV table for this group key table */
1414 RTMPAddWcidAttributeEntry(pAd,
1415 BSS0,
1416 idx,
1417 CipherAlg,
1418 NULL);
1419 }
1420 }
1421
1422 }
1423 }
1424 /* If WPANone is enabled, add key material and cipherAlg into Asic */
1425 /* Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000) */
1426 else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) {
1427 pAd->StaCfg.DefaultKeyId = 0; /* always be zero */
1428
1429 NdisZeroMemory(&pAd->SharedKey[BSS0][0],
1430 sizeof(struct rt_cipher_key));
1431 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
1432 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key,
1433 pAd->StaCfg.PMK, LEN_TKIP_EK);
1434
1435 if (pAd->StaCfg.PairCipher ==
1436 Ndis802_11Encryption2Enabled) {
1437 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic,
1438 &pAd->StaCfg.PMK[16],
1439 LEN_TKIP_RXMICK);
1440 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic,
1441 &pAd->StaCfg.PMK[16],
1442 LEN_TKIP_TXMICK);
1443 }
1444 /* Decide its ChiperAlg */
1445 if (pAd->StaCfg.PairCipher ==
1446 Ndis802_11Encryption2Enabled)
1447 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
1448 else if (pAd->StaCfg.PairCipher ==
1449 Ndis802_11Encryption3Enabled)
1450 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
1451 else {
1452 DBGPRINT(RT_DEBUG_TRACE,
1453 ("Unknow Cipher (=%d), set Cipher to AES\n",
1454 pAd->StaCfg.PairCipher));
1455 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
1456 }
1457
1458 /* Set key material and cipherAlg to Asic */
1459 AsicAddSharedKeyEntry(pAd,
1460 BSS0,
1461 0,
1462 pAd->SharedKey[BSS0][0].CipherAlg,
1463 pAd->SharedKey[BSS0][0].Key,
1464 pAd->SharedKey[BSS0][0].TxMic,
1465 pAd->SharedKey[BSS0][0].RxMic);
1466
1467 /* Update WCID attribute table and IVEIV table for this group key table */
1468 RTMPAddWcidAttributeEntry(pAd, BSS0, 0,
1469 pAd->SharedKey[BSS0][0].
1470 CipherAlg, NULL);
1471
1472 }
1473
1474 } else /* BSS_INFRA */
1475 {
1476 /* Check the new SSID with last SSID */
1477 while (Cancelled == TRUE) {
1478 if (pAd->CommonCfg.LastSsidLen ==
1479 pAd->CommonCfg.SsidLen) {
1480 if (RTMPCompareMemory
1481 (pAd->CommonCfg.LastSsid,
1482 pAd->CommonCfg.Ssid,
1483 pAd->CommonCfg.LastSsidLen) == 0) {
1484 /* Link to the old one no linkdown is required. */
1485 break;
1486 }
1487 }
1488 /* Send link down event before set to link up */
1489 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1490 RTMP_IndicateMediaState(pAd);
1491 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1492 DBGPRINT(RT_DEBUG_TRACE,
1493 ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n"));
1494 break;
1495 }
1496
1497 /* */
1498 /* On WPA mode, Remove All Keys if not connect to the last BSSID */
1499 /* Key will be set after 4-way handshake. */
1500 /* */
1501 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) {
1502 unsigned long IV;
1503
1504 /* Remove all WPA keys */
1505 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1506 RTMPWPARemoveAllKeys(pAd);
1507 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1508 pAd->StaCfg.PrivacyFilter =
1509 Ndis802_11PrivFilter8021xWEP;
1510
1511 /* Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP */
1512 /* If IV related values are too large in GroupMsg2, AP would ignore this message. */
1513 IV = 1;
1514 IV |= (pAd->StaCfg.DefaultKeyId << 30);
1515 AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0);
1516 }
1517 /* NOTE: */
1518 /* the decision of using "short slot time" or not may change dynamically due to */
1519 /* new STA association to the AP. so we have to decide that upon parsing BEACON, not here */
1520
1521 /* NOTE: */
1522 /* the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically */
1523 /* due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here */
1524
1525 ComposePsPoll(pAd);
1526 ComposeNullFrame(pAd);
1527
1528 AsicEnableBssSync(pAd);
1529
1530 /* Add BSSID to WCID search table */
1531 AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid);
1532
1533 /* If WEP is enabled, add pairwise and shared key */
1534 if (((pAd->StaCfg.WpaSupplicantUP) &&
1535 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
1536 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||
1537 ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE) &&
1538 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled))) {
1539 u8 *Key;
1540 u8 CipherAlg;
1541
1542 for (idx = 0; idx < SHARE_KEY_NUM; idx++) {
1543 CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
1544 Key = pAd->SharedKey[BSS0][idx].Key;
1545
1546 if (pAd->SharedKey[BSS0][idx].KeyLen > 0) {
1547 /* Set key material and cipherAlg to Asic */
1548 AsicAddSharedKeyEntry(pAd, BSS0, idx,
1549 CipherAlg, Key,
1550 NULL, NULL);
1551
1552 if (idx == pAd->StaCfg.DefaultKeyId) {
1553 /* Assign group key info */
1554 RTMPAddWcidAttributeEntry(pAd,
1555 BSS0,
1556 idx,
1557 CipherAlg,
1558 NULL);
1559
1560 pEntry->Aid = BSSID_WCID;
1561 /* Assign pairwise key info */
1562 RTMPAddWcidAttributeEntry(pAd,
1563 BSS0,
1564 idx,
1565 CipherAlg,
1566 pEntry);
1567 }
1568 }
1569 }
1570 }
1571 /* only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode */
1572 /* should wait until at least 2 active nodes in this BSSID. */
1573 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1574
1575 /* For GUI ++ */
1576 if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA) {
1577 pAd->IndicateMediaState = NdisMediaStateConnected;
1578 pAd->ExtraInfo = GENERAL_LINK_UP;
1579 RTMP_IndicateMediaState(pAd);
1580 } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
1581 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
1582 {
1583 if (pAd->StaCfg.WpaSupplicantUP ==
1584 WPA_SUPPLICANT_DISABLE)
1585 RTMPSetTimer(&pAd->Mlme.LinkDownTimer,
1586 LINK_DOWN_TIMEOUT);
1587 }
1588 /* -- */
1589
1590 /* Add BSSID in my MAC Table. */
1591 NdisAcquireSpinLock(&pAd->MacTabLock);
1592 /* add this MAC entry into HASH table */
1593 if (pEntry) {
1594 HashIdx = MAC_ADDR_HASH_INDEX(pAd->CommonCfg.Bssid);
1595 if (pAd->MacTab.Hash[HashIdx] == NULL) {
1596 pAd->MacTab.Hash[HashIdx] = pEntry;
1597 } else {
1598 pCurrEntry = pAd->MacTab.Hash[HashIdx];
1599 while (pCurrEntry->pNext != NULL) {
1600 pCurrEntry = pCurrEntry->pNext;
1601 }
1602 pCurrEntry->pNext = pEntry;
1603 }
1604 }
1605 RTMPMoveMemory(pEntry->Addr, pAd->CommonCfg.Bssid,
1606 MAC_ADDR_LEN);
1607 pEntry->Aid = BSSID_WCID;
1608 pEntry->pAd = pAd;
1609 pEntry->ValidAsCLI = TRUE; /*Although this is bssid..still set ValidAsCl */
1610 pAd->MacTab.Size = 1; /* infra mode always set MACtab size =1. */
1611 pEntry->Sst = SST_ASSOC;
1612 pEntry->AuthState = SST_ASSOC;
1613 pEntry->AuthMode = pAd->StaCfg.AuthMode;
1614 pEntry->WepStatus = pAd->StaCfg.WepStatus;
1615 if (pEntry->AuthMode < Ndis802_11AuthModeWPA) {
1616 pEntry->WpaState = AS_NOTUSE;
1617 pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
1618 } else {
1619 pEntry->WpaState = AS_PTKSTART;
1620 pEntry->PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
1621 }
1622 NdisReleaseSpinLock(&pAd->MacTabLock);
1623
1624 DBGPRINT(RT_DEBUG_TRACE,
1625 ("LINK UP! ClientStatusFlags=%lx)\n",
1626 pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
1627
1628 MlmeUpdateTxRates(pAd, TRUE, BSS0);
1629 MlmeUpdateHtTxRates(pAd, BSS0);
1630 DBGPRINT(RT_DEBUG_TRACE,
1631 ("LINK UP! (StaActive.bHtEnable =%d, )\n",
1632 pAd->StaActive.SupportedPhyInfo.bHtEnable));
1633
1634 if (pAd->CommonCfg.bAggregationCapable) {
1635 if ((pAd->CommonCfg.bPiggyBackCapable)
1636 && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3) {
1637 OPSTATUS_SET_FLAG(pAd,
1638 fOP_STATUS_PIGGYBACK_INUSED);
1639 OPSTATUS_SET_FLAG(pAd,
1640 fOP_STATUS_AGGREGATION_INUSED);
1641 CLIENT_STATUS_SET_FLAG(pEntry,
1642 fCLIENT_STATUS_AGGREGATION_CAPABLE);
1643 CLIENT_STATUS_SET_FLAG(pEntry,
1644 fCLIENT_STATUS_PIGGYBACK_CAPABLE);
1645 RTMPSetPiggyBack(pAd, TRUE);
1646 DBGPRINT(RT_DEBUG_TRACE,
1647 ("Turn on Piggy-Back\n"));
1648 } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) {
1649 OPSTATUS_SET_FLAG(pAd,
1650 fOP_STATUS_AGGREGATION_INUSED);
1651 CLIENT_STATUS_SET_FLAG(pEntry,
1652 fCLIENT_STATUS_AGGREGATION_CAPABLE);
1653 DBGPRINT(RT_DEBUG_TRACE,
1654 ("Ralink Aggregation\n"));
1655 }
1656 }
1657
1658 if (pAd->MlmeAux.APRalinkIe != 0x0) {
1659 if (CLIENT_STATUS_TEST_FLAG
1660 (pEntry, fCLIENT_STATUS_RDG_CAPABLE)) {
1661 AsicEnableRDG(pAd);
1662 }
1663 OPSTATUS_SET_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
1664 CLIENT_STATUS_SET_FLAG(pEntry,
1665 fCLIENT_STATUS_RALINK_CHIPSET);
1666 } else {
1667 OPSTATUS_CLEAR_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
1668 CLIENT_STATUS_CLEAR_FLAG(pEntry,
1669 fCLIENT_STATUS_RALINK_CHIPSET);
1670 }
1671 }
1672
1673 DBGPRINT(RT_DEBUG_TRACE,
1674 ("NDIS_STATUS_MEDIA_CONNECT Event B!.BACapability = %x. ClientStatusFlags = %lx\n",
1675 pAd->CommonCfg.BACapability.word,
1676 pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
1677
1678 /* Set LED */
1679 RTMPSetLED(pAd, LED_LINK_UP);
1680
1681 pAd->Mlme.PeriodicRound = 0;
1682 pAd->Mlme.OneSecPeriodicRound = 0;
1683 pAd->bConfigChanged = FALSE; /* Reset config flag */
1684 pAd->ExtraInfo = GENERAL_LINK_UP; /* Update extra information after link is up */
1685
1686 /* Set basic auto fall back */
1687 {
1688 u8 *pTable;
1689 u8 TableSize = 0;
1690
1691 MlmeSelectTxRateTable(pAd, &pAd->MacTab.Content[BSSID_WCID],
1692 &pTable, &TableSize,
1693 &pAd->CommonCfg.TxRateIndex);
1694 AsicUpdateAutoFallBackTable(pAd, pTable);
1695 }
1696
1697 NdisAcquireSpinLock(&pAd->MacTabLock);
1698 pEntry->HTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
1699 pEntry->MaxHTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
1700 if (pAd->StaCfg.bAutoTxRateSwitch == FALSE) {
1701 pEntry->bAutoTxRateSwitch = FALSE;
1702
1703 if (pEntry->HTPhyMode.field.MCS == 32)
1704 pEntry->HTPhyMode.field.ShortGI = GI_800;
1705
1706 if ((pEntry->HTPhyMode.field.MCS > MCS_7)
1707 || (pEntry->HTPhyMode.field.MCS == 32))
1708 pEntry->HTPhyMode.field.STBC = STBC_NONE;
1709
1710 /* If the legacy mode is set, overwrite the transmit setting of this entry. */
1711 if (pEntry->HTPhyMode.field.MODE <= MODE_OFDM)
1712 RTMPUpdateLegacyTxSetting((u8)pAd->StaCfg.
1713 DesiredTransmitSetting.field.
1714 FixedTxMode, pEntry);
1715 } else
1716 pEntry->bAutoTxRateSwitch = TRUE;
1717 NdisReleaseSpinLock(&pAd->MacTabLock);
1718
1719 /* Let Link Status Page display first initial rate. */
1720 pAd->LastTxRate = (u16)(pEntry->HTPhyMode.word);
1721 /* Select DAC according to HT or Legacy */
1722 if (pAd->StaActive.SupportedPhyInfo.MCSSet[0] != 0x00) {
1723 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
1724 Value &= (~0x18);
1725 if (pAd->Antenna.field.TxPath == 2) {
1726 Value |= 0x10;
1727 }
1728 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
1729 } else {
1730 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
1731 Value &= (~0x18);
1732 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
1733 }
1734
1735 if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) {
1736 } else if (pEntry->MaxRAmpduFactor == 0) {
1737 /* If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0. */
1738 /* Because our Init value is 1 at MACRegTable. */
1739 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x0fff);
1740 }
1741 /* Patch for Marvel AP to gain high throughput */
1742 /* Need to set as following, */
1743 /* 1. Set txop in register-EDCA_AC0_CFG as 0x60 */
1744 /* 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero */
1745 /* 3. PBF_MAX_PCNT as 0x1F3FBF9F */
1746 /* 4. kick per two packets when dequeue */
1747 /* */
1748 /* Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable */
1749 /* */
1750 /* if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is. */
1751 if (!((pAd->CommonCfg.RxStream == 1) && (pAd->CommonCfg.TxStream == 1))
1752 && (pAd->StaCfg.bForceTxBurst == FALSE)
1753 &&
1754 (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
1755 && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))
1756 || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)
1757 && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE)))) {
1758 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1759 Data &= 0xFFFFFF00;
1760 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1761
1762 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
1763 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 1\n"));
1764 } else if (pAd->CommonCfg.bEnableTxBurst) {
1765 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1766 Data &= 0xFFFFFF00;
1767 Data |= 0x60;
1768 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1769 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = TRUE;
1770
1771 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3FBF9F);
1772 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 2\n"));
1773 } else {
1774 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1775 Data &= 0xFFFFFF00;
1776 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1777
1778 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
1779 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 3\n"));
1780 }
1781
1782 /* Re-check to turn on TX burst or not. */
1783 if ((pAd->CommonCfg.IOTestParm.bLastAtheros == TRUE)
1784 && ((STA_WEP_ON(pAd)) || (STA_TKIP_ON(pAd)))) {
1785 pAd->CommonCfg.IOTestParm.bNextDisableRxBA = TRUE;
1786 if (pAd->CommonCfg.bEnableTxBurst) {
1787 u32 MACValue = 0;
1788 /* Force disable TXOP value in this case. The same action in MLMEUpdateProtect too. */
1789 /* I didn't change PBF_MAX_PCNT setting. */
1790 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &MACValue);
1791 MACValue &= 0xFFFFFF00;
1792 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, MACValue);
1793 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
1794 }
1795 } else {
1796 pAd->CommonCfg.IOTestParm.bNextDisableRxBA = FALSE;
1797 }
1798
1799 pAd->CommonCfg.IOTestParm.bLastAtheros = FALSE;
1800 COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
1801 DBGPRINT(RT_DEBUG_TRACE,
1802 ("pAd->bNextDisableRxBA= %d \n",
1803 pAd->CommonCfg.IOTestParm.bNextDisableRxBA));
1804 /* BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap */
1805 /* Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver. */
1806 /* Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same. */
1807
1808 if (pAd->StaCfg.WepStatus <= Ndis802_11WEPDisabled) {
1809 if (pAd->StaCfg.WpaSupplicantUP &&
1810 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
1811 (pAd->StaCfg.IEEE8021X == TRUE)) ;
1812 else {
1813 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1814 pAd->StaCfg.PrivacyFilter =
1815 Ndis802_11PrivFilterAcceptAll;
1816 }
1817 }
1818
1819 NdisAcquireSpinLock(&pAd->MacTabLock);
1820 pEntry->PortSecured = pAd->StaCfg.PortSecured;
1821 NdisReleaseSpinLock(&pAd->MacTabLock);
1822
1823 /* */
1824 /* Patch Atheros AP TX will breakdown issue. */
1825 /* AP Model: DLink DWL-8200AP */
1826 /* */
1827 if (INFRA_ON(pAd) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)
1828 && STA_TKIP_ON(pAd)) {
1829 RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x01);
1830 } else {
1831 RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x00);
1832 }
1833
1834 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
1835
1836 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
1837}
1838
1839/*
1840 ==========================================================================
1841
1842 Routine Description:
1843 Disconnect current BSSID
1844
1845 Arguments:
1846 pAd - Pointer to our adapter
1847 IsReqFromAP - Request from AP
1848
1849 Return Value:
1850 None
1851
1852 IRQL = DISPATCH_LEVEL
1853
1854 Note:
1855 We need more information to know it's this requst from AP.
1856 If yes! we need to do extra handling, for example, remove the WPA key.
1857 Otherwise on 4-way handshaking will fail, since the WPA key didn't get
1858 removed while auto reconnect.
1859 Disconnect request from AP, it means we will start afresh 4-way handshaking
1860 on WPA mode.
1861
1862 ==========================================================================
1863*/
1864void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP)
1865{
1866 u8 i, ByteValue = 0;
1867
1868 /* Do nothing if monitor mode is on */
1869 if (MONITOR_ON(pAd))
1870 return;
1871
1872 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
1873 /* Comment the codes, because the line 2291 call the same function. */
1874 /* RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); */
1875 /* Not allowed go to sleep within the linkdown function. */
1876 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1877
1878 if (pAd->CommonCfg.bWirelessEvent) {
1879 RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG,
1880 pAd->MacTab.Content[BSSID_WCID].Addr,
1881 BSS0, 0);
1882 }
1883
1884 DBGPRINT(RT_DEBUG_TRACE, ("LINK DOWN!\n"));
1885 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1886
1887#ifdef RTMP_MAC_PCI
1888 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
1889 BOOLEAN Cancelled;
1890 pAd->Mlme.bPsPollTimerRunning = FALSE;
1891 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1892 }
1893
1894 pAd->bPCIclkOff = FALSE;
1895#endif /* RTMP_MAC_PCI // */
1896
1897 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)
1898 || RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND)
1899 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF)) {
1900 AUTO_WAKEUP_STRUC AutoWakeupCfg;
1901 AsicForceWakeup(pAd, TRUE);
1902 AutoWakeupCfg.word = 0;
1903 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
1904 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
1905 }
1906#ifdef RTMP_MAC_PCI
1907 pAd->bPCIclkOff = FALSE;
1908#endif /* RTMP_MAC_PCI // */
1909
1910 if (ADHOC_ON(pAd)) /* Adhoc mode link down */
1911 {
1912 DBGPRINT(RT_DEBUG_TRACE, ("LINK DOWN 1!\n"));
1913
1914 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1915 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1916 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1917 RTMP_IndicateMediaState(pAd);
1918 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1919 BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid,
1920 pAd->CommonCfg.Channel);
1921 DBGPRINT(RT_DEBUG_TRACE,
1922 (" MacTab.Size=%d !\n", pAd->MacTab.Size));
1923 } else /* Infra structure mode */
1924 {
1925 DBGPRINT(RT_DEBUG_TRACE, ("LINK DOWN 2!\n"));
1926
1927 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
1928 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1929
1930 /* Saved last SSID for linkup comparison */
1931 pAd->CommonCfg.LastSsidLen = pAd->CommonCfg.SsidLen;
1932 NdisMoveMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid,
1933 pAd->CommonCfg.LastSsidLen);
1934 COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
1935 if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE) {
1936 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1937 RTMP_IndicateMediaState(pAd);
1938 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1939 DBGPRINT(RT_DEBUG_TRACE,
1940 ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n"));
1941 pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
1942 } else {
1943 /* */
1944 /* If disassociation request is from NDIS, then we don't need to delete BSSID from entry. */
1945 /* Otherwise lost beacon or receive De-Authentication from AP, */
1946 /* then we should delete BSSID from BssTable. */
1947 /* If we don't delete from entry, roaming will fail. */
1948 /* */
1949 BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid,
1950 pAd->CommonCfg.Channel);
1951 }
1952
1953 /* restore back to - */
1954 /* 1. long slot (20 us) or short slot (9 us) time */
1955 /* 2. turn on/off RTS/CTS and/or CTS-to-self protection */
1956 /* 3. short preamble */
1957 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
1958
1959 }
1960
1961 for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) {
1962 if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)
1963 MacTableDeleteEntry(pAd, pAd->MacTab.Content[i].Aid,
1964 pAd->MacTab.Content[i].Addr);
1965 }
1966
1967 AsicSetSlotTime(pAd, TRUE); /*FALSE); */
1968 AsicSetEdcaParm(pAd, NULL);
1969
1970 /* Set LED */
1971 RTMPSetLED(pAd, LED_LINK_DOWN);
1972 pAd->LedIndicatorStrength = 0xF0;
1973 RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, firmware has not done it. */
1974
1975 AsicDisableSync(pAd);
1976
1977 pAd->Mlme.PeriodicRound = 0;
1978 pAd->Mlme.OneSecPeriodicRound = 0;
1979
1980 if (pAd->StaCfg.BssType == BSS_INFRA) {
1981 /* Remove StaCfg Information after link down */
1982 NdisZeroMemory(pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
1983 NdisZeroMemory(pAd->CommonCfg.Ssid, MAX_LEN_OF_SSID);
1984 pAd->CommonCfg.SsidLen = 0;
1985 }
1986
1987 NdisZeroMemory(&pAd->MlmeAux.HtCapability, sizeof(struct rt_ht_capability_ie));
1988 NdisZeroMemory(&pAd->MlmeAux.AddHtInfo, sizeof(struct rt_add_ht_info_ie));
1989 pAd->MlmeAux.HtCapabilityLen = 0;
1990 pAd->MlmeAux.NewExtChannelOffset = 0xff;
1991
1992 /* Reset WPA-PSK state. Only reset when supplicant enabled */
1993 if (pAd->StaCfg.WpaState != SS_NOTUSE) {
1994 pAd->StaCfg.WpaState = SS_START;
1995 /* Clear Replay counter */
1996 NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
1997
1998 }
1999 /* */
2000 /* if link down come from AP, we need to remove all WPA keys on WPA mode. */
2001 /* otherwise will cause 4-way handshaking failed, since the WPA key not empty. */
2002 /* */
2003 if ((IsReqFromAP) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)) {
2004 /* Remove all WPA keys */
2005 RTMPWPARemoveAllKeys(pAd);
2006 }
2007 /* 802.1x port control */
2008
2009 /* Prevent clear PortSecured here with static WEP */
2010 /* NetworkManger set security policy first then set SSID to connect AP. */
2011 if (pAd->StaCfg.WpaSupplicantUP &&
2012 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
2013 (pAd->StaCfg.IEEE8021X == FALSE)) {
2014 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2015 } else {
2016 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2017 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
2018 }
2019
2020 NdisAcquireSpinLock(&pAd->MacTabLock);
2021 NdisZeroMemory(&pAd->MacTab, sizeof(struct rt_mac_table));
2022 pAd->MacTab.Content[BSSID_WCID].PortSecured = pAd->StaCfg.PortSecured;
2023 NdisReleaseSpinLock(&pAd->MacTabLock);
2024
2025 pAd->StaCfg.MicErrCnt = 0;
2026
2027 pAd->IndicateMediaState = NdisMediaStateDisconnected;
2028 /* Update extra information to link is up */
2029 pAd->ExtraInfo = GENERAL_LINK_DOWN;
2030
2031 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
2032
2033#ifdef RTMP_MAC_USB
2034 pAd->bUsbTxBulkAggre = FALSE;
2035#endif /* RTMP_MAC_USB // */
2036
2037 /* Clean association information */
2038 NdisZeroMemory(&pAd->StaCfg.AssocInfo,
2039 sizeof(struct rt_ndis_802_11_association_information));
2040 pAd->StaCfg.AssocInfo.Length =
2041 sizeof(struct rt_ndis_802_11_association_information);
2042 pAd->StaCfg.ReqVarIELen = 0;
2043 pAd->StaCfg.ResVarIELen = 0;
2044
2045 /* */
2046 /* Reset RSSI value after link down */
2047 /* */
2048 pAd->StaCfg.RssiSample.AvgRssi0 = 0;
2049 pAd->StaCfg.RssiSample.AvgRssi0X8 = 0;
2050 pAd->StaCfg.RssiSample.AvgRssi1 = 0;
2051 pAd->StaCfg.RssiSample.AvgRssi1X8 = 0;
2052 pAd->StaCfg.RssiSample.AvgRssi2 = 0;
2053 pAd->StaCfg.RssiSample.AvgRssi2X8 = 0;
2054
2055 /* Restore MlmeRate */
2056 pAd->CommonCfg.MlmeRate = pAd->CommonCfg.BasicMlmeRate;
2057 pAd->CommonCfg.RtsRate = pAd->CommonCfg.BasicMlmeRate;
2058
2059 /* */
2060 /* After Link down, reset piggy-back setting in ASIC. Disable RDG. */
2061 /* */
2062 if (pAd->CommonCfg.BBPCurrentBW == BW_40) {
2063 pAd->CommonCfg.BBPCurrentBW = BW_20;
2064 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &ByteValue);
2065 ByteValue &= (~0x18);
2066 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, ByteValue);
2067 }
2068 /* Reset DAC */
2069 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &ByteValue);
2070 ByteValue &= (~0x18);
2071 if (pAd->Antenna.field.TxPath == 2) {
2072 ByteValue |= 0x10;
2073 }
2074 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, ByteValue);
2075
2076 RTMPSetPiggyBack(pAd, FALSE);
2077 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
2078
2079 pAd->CommonCfg.BACapability.word = pAd->CommonCfg.REGBACapability.word;
2080
2081 /* Restore all settings in the following. */
2082 AsicUpdateProtect(pAd, 0,
2083 (ALLN_SETPROTECT | CCKSETPROTECT | OFDMSETPROTECT),
2084 TRUE, FALSE);
2085 AsicDisableRDG(pAd);
2086 pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE;
2087 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
2088
2089 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff);
2090 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
2091
2092/* Allow go to sleep after linkdown steps. */
2093 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
2094
2095 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, 0);
2096
2097#ifdef RT30xx
2098 if ((IS_RT30xx(pAd) || IS_RT3090(pAd) || IS_RT3390(pAd))
2099 && (pAd->Antenna.field.RxPath > 1 || pAd->Antenna.field.TxPath > 1)) {
2100 RTMP_ASIC_MMPS_DISABLE(pAd);
2101 }
2102#endif /* RT30xx // */
2103}
2104
2105/*
2106 ==========================================================================
2107 Description:
2108
2109 IRQL = DISPATCH_LEVEL
2110
2111 ==========================================================================
2112*/
2113void IterateOnBssTab(struct rt_rtmp_adapter *pAd)
2114{
2115 struct rt_mlme_start_req StartReq;
2116 struct rt_mlme_join_req JoinReq;
2117 unsigned long BssIdx;
2118
2119 /* Change the wepstatus to original wepstatus */
2120 pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
2121 pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
2122 pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
2123
2124 BssIdx = pAd->MlmeAux.BssIdx;
2125 if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr) {
2126 /* Check cipher suite, AP must have more secured cipher than station setting */
2127 /* Set the Pairwise and Group cipher to match the intended AP setting */
2128 /* We can only connect to AP with less secured cipher setting */
2129 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA)
2130 || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) {
2131 pAd->StaCfg.GroupCipher =
2132 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.
2133 GroupCipher;
2134
2135 if (pAd->StaCfg.WepStatus ==
2136 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.
2137 PairCipher)
2138 pAd->StaCfg.PairCipher =
2139 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].
2140 WPA.PairCipher;
2141 else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.
2142 PairCipherAux != Ndis802_11WEPDisabled)
2143 pAd->StaCfg.PairCipher =
2144 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].
2145 WPA.PairCipherAux;
2146 else /* There is no PairCipher Aux, downgrade our capability to TKIP */
2147 pAd->StaCfg.PairCipher =
2148 Ndis802_11Encryption2Enabled;
2149 } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
2150 || (pAd->StaCfg.AuthMode ==
2151 Ndis802_11AuthModeWPA2PSK)) {
2152 pAd->StaCfg.GroupCipher =
2153 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.
2154 GroupCipher;
2155
2156 if (pAd->StaCfg.WepStatus ==
2157 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.
2158 PairCipher)
2159 pAd->StaCfg.PairCipher =
2160 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].
2161 WPA2.PairCipher;
2162 else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.
2163 PairCipherAux != Ndis802_11WEPDisabled)
2164 pAd->StaCfg.PairCipher =
2165 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].
2166 WPA2.PairCipherAux;
2167 else /* There is no PairCipher Aux, downgrade our capability to TKIP */
2168 pAd->StaCfg.PairCipher =
2169 Ndis802_11Encryption2Enabled;
2170
2171 /* RSN capability */
2172 pAd->StaCfg.RsnCapability =
2173 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.
2174 RsnCapability;
2175 }
2176 /* Set Mix cipher flag */
2177 pAd->StaCfg.bMixCipher =
2178 (pAd->StaCfg.PairCipher ==
2179 pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
2180 /*if (pAd->StaCfg.bMixCipher == TRUE)
2181 {
2182 // If mix cipher, re-build RSNIE
2183 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
2184 } */
2185
2186 DBGPRINT(RT_DEBUG_TRACE,
2187 ("CNTL - iterate BSS %ld of %d\n", BssIdx,
2188 pAd->MlmeAux.SsidBssTab.BssNr));
2189 JoinParmFill(pAd, &JoinReq, BssIdx);
2190 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ,
2191 sizeof(struct rt_mlme_join_req), &JoinReq);
2192 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
2193 } else if (pAd->StaCfg.BssType == BSS_ADHOC) {
2194 DBGPRINT(RT_DEBUG_TRACE,
2195 ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",
2196 pAd->MlmeAux.Ssid));
2197 StartParmFill(pAd, &StartReq, (char *)pAd->MlmeAux.Ssid,
2198 pAd->MlmeAux.SsidLen);
2199 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ,
2200 sizeof(struct rt_mlme_start_req), &StartReq);
2201 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
2202 } else /* no more BSS */
2203 {
2204
2205 {
2206 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
2207 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
2208 DBGPRINT(RT_DEBUG_TRACE,
2209 ("CNTL - All roaming failed, restore to channel %d, Total BSS[%02d]\n",
2210 pAd->CommonCfg.Channel, pAd->ScanTab.BssNr));
2211 }
2212
2213 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
2214 }
2215}
2216
2217/* for re-association only */
2218/* IRQL = DISPATCH_LEVEL */
2219void IterateOnBssTab2(struct rt_rtmp_adapter *pAd)
2220{
2221 struct rt_mlme_assoc_req ReassocReq;
2222 unsigned long BssIdx;
2223 struct rt_bss_entry *pBss;
2224
2225 BssIdx = pAd->MlmeAux.RoamIdx;
2226 pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx];
2227
2228 if (BssIdx < pAd->MlmeAux.RoamTab.BssNr) {
2229 DBGPRINT(RT_DEBUG_TRACE,
2230 ("CNTL - iterate BSS %ld of %d\n", BssIdx,
2231 pAd->MlmeAux.RoamTab.BssNr));
2232
2233 AsicSwitchChannel(pAd, pBss->Channel, FALSE);
2234 AsicLockChannel(pAd, pBss->Channel);
2235
2236 /* reassociate message has the same structure as associate message */
2237 AssocParmFill(pAd, &ReassocReq, pBss->Bssid,
2238 pBss->CapabilityInfo, ASSOC_TIMEOUT,
2239 pAd->StaCfg.DefaultListenCount);
2240 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
2241 sizeof(struct rt_mlme_assoc_req), &ReassocReq);
2242
2243 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
2244 } else /* no more BSS */
2245 {
2246
2247 {
2248 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
2249 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
2250 DBGPRINT(RT_DEBUG_TRACE,
2251 ("CNTL - All roaming failed, restore to channel %d, Total BSS[%02d]\n",
2252 pAd->CommonCfg.Channel, pAd->ScanTab.BssNr));
2253 }
2254
2255 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
2256 }
2257}
2258
2259/*
2260 ==========================================================================
2261 Description:
2262
2263 IRQL = DISPATCH_LEVEL
2264
2265 ==========================================================================
2266*/
2267void JoinParmFill(struct rt_rtmp_adapter *pAd,
2268 struct rt_mlme_join_req *JoinReq, unsigned long BssIdx)
2269{
2270 JoinReq->BssIdx = BssIdx;
2271}
2272
2273/*
2274 ==========================================================================
2275 Description:
2276
2277 IRQL = DISPATCH_LEVEL
2278
2279 ==========================================================================
2280*/
2281void ScanParmFill(struct rt_rtmp_adapter *pAd,
2282 struct rt_mlme_scan_req *ScanReq,
2283 char Ssid[],
2284 u8 SsidLen, u8 BssType, u8 ScanType)
2285{
2286 NdisZeroMemory(ScanReq->Ssid, MAX_LEN_OF_SSID);
2287 ScanReq->SsidLen = SsidLen;
2288 NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen);
2289 ScanReq->BssType = BssType;
2290 ScanReq->ScanType = ScanType;
2291}
2292
2293/*
2294 ==========================================================================
2295 Description:
2296
2297 IRQL = DISPATCH_LEVEL
2298
2299 ==========================================================================
2300*/
2301void StartParmFill(struct rt_rtmp_adapter *pAd,
2302 struct rt_mlme_start_req *StartReq,
2303 char Ssid[], u8 SsidLen)
2304{
2305 ASSERT(SsidLen <= MAX_LEN_OF_SSID);
2306 NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen);
2307 StartReq->SsidLen = SsidLen;
2308}
2309
2310/*
2311 ==========================================================================
2312 Description:
2313
2314 IRQL = DISPATCH_LEVEL
2315
2316 ==========================================================================
2317*/
2318void AuthParmFill(struct rt_rtmp_adapter *pAd,
2319 struct rt_mlme_auth_req *AuthReq,
2320 u8 *pAddr, u16 Alg)
2321{
2322 COPY_MAC_ADDR(AuthReq->Addr, pAddr);
2323 AuthReq->Alg = Alg;
2324 AuthReq->Timeout = AUTH_TIMEOUT;
2325}
2326
2327/*
2328 ==========================================================================
2329 Description:
2330
2331 IRQL = DISPATCH_LEVEL
2332
2333 ==========================================================================
2334 */
2335#ifdef RTMP_MAC_PCI
2336void ComposePsPoll(struct rt_rtmp_adapter *pAd)
2337{
2338 NdisZeroMemory(&pAd->PsPollFrame, sizeof(struct rt_pspoll_frame));
2339 pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
2340 pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
2341 pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;
2342 COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);
2343 COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
2344}
2345
2346/* IRQL = DISPATCH_LEVEL */
2347void ComposeNullFrame(struct rt_rtmp_adapter *pAd)
2348{
2349 NdisZeroMemory(&pAd->NullFrame, sizeof(struct rt_header_802_11));
2350 pAd->NullFrame.FC.Type = BTYPE_DATA;
2351 pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
2352 pAd->NullFrame.FC.ToDs = 1;
2353 COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);
2354 COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
2355 COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
2356}
2357#endif /* RTMP_MAC_PCI // */
2358#ifdef RTMP_MAC_USB
2359void MlmeCntlConfirm(struct rt_rtmp_adapter *pAd, unsigned long MsgType, u16 Msg)
2360{
2361 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MsgType, sizeof(u16),
2362 &Msg);
2363}
2364
2365void ComposePsPoll(struct rt_rtmp_adapter *pAd)
2366{
2367 struct rt_txinfo *pTxInfo;
2368 struct rt_txwi * pTxWI;
2369
2370 DBGPRINT(RT_DEBUG_TRACE, ("ComposePsPoll\n"));
2371 NdisZeroMemory(&pAd->PsPollFrame, sizeof(struct rt_pspoll_frame));
2372
2373 pAd->PsPollFrame.FC.PwrMgmt = 0;
2374 pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
2375 pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
2376 pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;
2377 COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);
2378 COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
2379
2380 RTMPZeroMemory(&pAd->PsPollContext.TransferBuffer->field.
2381 WirelessPacket[0], 100);
2382 pTxInfo =
2383 (struct rt_txinfo *)& pAd->PsPollContext.TransferBuffer->field.
2384 WirelessPacket[0];
2385 RTMPWriteTxInfo(pAd, pTxInfo,
2386 (u16)(sizeof(struct rt_pspoll_frame) + TXWI_SIZE), TRUE,
2387 EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
2388 pTxWI =
2389 (struct rt_txwi *) & pAd->PsPollContext.TransferBuffer->field.
2390 WirelessPacket[TXINFO_SIZE];
2391 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0,
2392 BSSID_WCID, (sizeof(struct rt_pspoll_frame)), 0, 0,
2393 (u8)pAd->CommonCfg.MlmeTransmit.field.MCS,
2394 IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
2395 RTMPMoveMemory(&pAd->PsPollContext.TransferBuffer->field.
2396 WirelessPacket[TXWI_SIZE + TXINFO_SIZE],
2397 &pAd->PsPollFrame, sizeof(struct rt_pspoll_frame));
2398 /* Append 4 extra zero bytes. */
2399 pAd->PsPollContext.BulkOutSize =
2400 TXINFO_SIZE + TXWI_SIZE + sizeof(struct rt_pspoll_frame) + 4;
2401}
2402
2403/* IRQL = DISPATCH_LEVEL */
2404void ComposeNullFrame(struct rt_rtmp_adapter *pAd)
2405{
2406 struct rt_txinfo *pTxInfo;
2407 struct rt_txwi * pTxWI;
2408
2409 NdisZeroMemory(&pAd->NullFrame, sizeof(struct rt_header_802_11));
2410 pAd->NullFrame.FC.Type = BTYPE_DATA;
2411 pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
2412 pAd->NullFrame.FC.ToDs = 1;
2413 COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);
2414 COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
2415 COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
2416 RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.
2417 WirelessPacket[0], 100);
2418 pTxInfo =
2419 (struct rt_txinfo *)& pAd->NullContext.TransferBuffer->field.
2420 WirelessPacket[0];
2421 RTMPWriteTxInfo(pAd, pTxInfo,
2422 (u16)(sizeof(struct rt_header_802_11) + TXWI_SIZE), TRUE,
2423 EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
2424 pTxWI =
2425 (struct rt_txwi *) & pAd->NullContext.TransferBuffer->field.
2426 WirelessPacket[TXINFO_SIZE];
2427 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0,
2428 BSSID_WCID, (sizeof(struct rt_header_802_11)), 0, 0,
2429 (u8)pAd->CommonCfg.MlmeTransmit.field.MCS,
2430 IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
2431 RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.
2432 WirelessPacket[TXWI_SIZE + TXINFO_SIZE], &pAd->NullFrame,
2433 sizeof(struct rt_header_802_11));
2434 pAd->NullContext.BulkOutSize =
2435 TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
2436}
2437#endif /* RTMP_MAC_USB // */
2438
2439/*
2440 ==========================================================================
2441 Description:
2442 Pre-build a BEACON frame in the shared memory
2443
2444 IRQL = PASSIVE_LEVEL
2445 IRQL = DISPATCH_LEVEL
2446
2447 ==========================================================================
2448*/
2449unsigned long MakeIbssBeacon(struct rt_rtmp_adapter *pAd)
2450{
2451 u8 DsLen = 1, IbssLen = 2;
2452 u8 LocalErpIe[3] = { IE_ERP, 1, 0x04 };
2453 struct rt_header_802_11 BcnHdr;
2454 u16 CapabilityInfo;
2455 LARGE_INTEGER FakeTimestamp;
2456 unsigned long FrameLen = 0;
2457 struct rt_txwi * pTxWI = &pAd->BeaconTxWI;
2458 u8 *pBeaconFrame = pAd->BeaconBuf;
2459 BOOLEAN Privacy;
2460 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
2461 u8 SupRateLen = 0;
2462 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
2463 u8 ExtRateLen = 0;
2464 u8 RSNIe = IE_WPA;
2465
2466 if ((pAd->CommonCfg.PhyMode == PHY_11B)
2467 && (pAd->CommonCfg.Channel <= 14)) {
2468 SupRate[0] = 0x82; /* 1 mbps */
2469 SupRate[1] = 0x84; /* 2 mbps */
2470 SupRate[2] = 0x8b; /* 5.5 mbps */
2471 SupRate[3] = 0x96; /* 11 mbps */
2472 SupRateLen = 4;
2473 ExtRateLen = 0;
2474 } else if (pAd->CommonCfg.Channel > 14) {
2475 SupRate[0] = 0x8C; /* 6 mbps, in units of 0.5 Mbps, basic rate */
2476 SupRate[1] = 0x12; /* 9 mbps, in units of 0.5 Mbps */
2477 SupRate[2] = 0x98; /* 12 mbps, in units of 0.5 Mbps, basic rate */
2478 SupRate[3] = 0x24; /* 18 mbps, in units of 0.5 Mbps */
2479 SupRate[4] = 0xb0; /* 24 mbps, in units of 0.5 Mbps, basic rate */
2480 SupRate[5] = 0x48; /* 36 mbps, in units of 0.5 Mbps */
2481 SupRate[6] = 0x60; /* 48 mbps, in units of 0.5 Mbps */
2482 SupRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */
2483 SupRateLen = 8;
2484 ExtRateLen = 0;
2485
2486 /* */
2487 /* Also Update MlmeRate & RtsRate for G only & A only */
2488 /* */
2489 pAd->CommonCfg.MlmeRate = RATE_6;
2490 pAd->CommonCfg.RtsRate = RATE_6;
2491 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
2492 pAd->CommonCfg.MlmeTransmit.field.MCS =
2493 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
2494 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE =
2495 MODE_OFDM;
2496 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS =
2497 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
2498 } else {
2499 SupRate[0] = 0x82; /* 1 mbps */
2500 SupRate[1] = 0x84; /* 2 mbps */
2501 SupRate[2] = 0x8b; /* 5.5 mbps */
2502 SupRate[3] = 0x96; /* 11 mbps */
2503 SupRateLen = 4;
2504
2505 ExtRate[0] = 0x0C; /* 6 mbps, in units of 0.5 Mbps, */
2506 ExtRate[1] = 0x12; /* 9 mbps, in units of 0.5 Mbps */
2507 ExtRate[2] = 0x18; /* 12 mbps, in units of 0.5 Mbps, */
2508 ExtRate[3] = 0x24; /* 18 mbps, in units of 0.5 Mbps */
2509 ExtRate[4] = 0x30; /* 24 mbps, in units of 0.5 Mbps, */
2510 ExtRate[5] = 0x48; /* 36 mbps, in units of 0.5 Mbps */
2511 ExtRate[6] = 0x60; /* 48 mbps, in units of 0.5 Mbps */
2512 ExtRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */
2513 ExtRateLen = 8;
2514 }
2515
2516 pAd->StaActive.SupRateLen = SupRateLen;
2517 NdisMoveMemory(pAd->StaActive.SupRate, SupRate, SupRateLen);
2518 pAd->StaActive.ExtRateLen = ExtRateLen;
2519 NdisMoveMemory(pAd->StaActive.ExtRate, ExtRate, ExtRateLen);
2520
2521 /* compose IBSS beacon frame */
2522 MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR,
2523 pAd->CommonCfg.Bssid);
2524 Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
2525 || (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2526 || (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
2527 CapabilityInfo =
2528 CAP_GENERATE(0, 1, Privacy,
2529 (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort),
2530 0, 0);
2531
2532 MakeOutgoingFrame(pBeaconFrame, &FrameLen,
2533 sizeof(struct rt_header_802_11), &BcnHdr,
2534 TIMESTAMP_LEN, &FakeTimestamp,
2535 2, &pAd->CommonCfg.BeaconPeriod,
2536 2, &CapabilityInfo,
2537 1, &SsidIe,
2538 1, &pAd->CommonCfg.SsidLen,
2539 pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
2540 1, &SupRateIe,
2541 1, &SupRateLen,
2542 SupRateLen, SupRate,
2543 1, &DsIe,
2544 1, &DsLen,
2545 1, &pAd->CommonCfg.Channel,
2546 1, &IbssIe,
2547 1, &IbssLen, 2, &pAd->StaActive.AtimWin, END_OF_ARGS);
2548
2549 /* add ERP_IE and EXT_RAE IE of in 802.11g */
2550 if (ExtRateLen) {
2551 unsigned long tmp;
2552
2553 MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
2554 3, LocalErpIe,
2555 1, &ExtRateIe,
2556 1, &ExtRateLen,
2557 ExtRateLen, ExtRate, END_OF_ARGS);
2558 FrameLen += tmp;
2559 }
2560 /* If adhoc secruity is set for WPA-None, append the cipher suite IE */
2561 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) {
2562 unsigned long tmp;
2563 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus,
2564 BSS0);
2565
2566 MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
2567 1, &RSNIe,
2568 1, &pAd->StaCfg.RSNIE_Len,
2569 pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
2570 END_OF_ARGS);
2571 FrameLen += tmp;
2572 }
2573
2574 if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
2575 unsigned long TmpLen;
2576 u8 HtLen, HtLen1;
2577
2578 /* add HT Capability IE */
2579 HtLen = sizeof(pAd->CommonCfg.HtCapability);
2580 HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo);
2581
2582 MakeOutgoingFrame(pBeaconFrame + FrameLen, &TmpLen,
2583 1, &HtCapIe,
2584 1, &HtLen,
2585 HtLen, &pAd->CommonCfg.HtCapability,
2586 1, &AddHtInfoIe,
2587 1, &HtLen1,
2588 HtLen1, &pAd->CommonCfg.AddHTInfo,
2589 END_OF_ARGS);
2590
2591 FrameLen += TmpLen;
2592 }
2593 /*beacon use reserved WCID 0xff */
2594 if (pAd->CommonCfg.Channel > 14) {
2595 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE,
2596 TRUE, 0, 0xff, FrameLen, PID_MGMT, PID_BEACON,
2597 RATE_1, IFS_HTTXOP, FALSE,
2598 &pAd->CommonCfg.MlmeTransmit);
2599 } else {
2600 /* Set to use 1Mbps for Adhoc beacon. */
2601 HTTRANSMIT_SETTING Transmit;
2602 Transmit.word = 0;
2603 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE,
2604 TRUE, 0, 0xff, FrameLen, PID_MGMT, PID_BEACON,
2605 RATE_1, IFS_HTTXOP, FALSE, &Transmit);
2606 }
2607
2608 DBGPRINT(RT_DEBUG_TRACE,
2609 ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",
2610 FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel,
2611 pAd->CommonCfg.PhyMode));
2612 return FrameLen;
2613}
diff --git a/drivers/staging/rt2860/sta/rtmp_data.c b/drivers/staging/rt2860/sta/rtmp_data.c
deleted file mode 100644
index e82c6b669eb..00000000000
--- a/drivers/staging/rt2860/sta/rtmp_data.c
+++ /dev/null
@@ -1,2552 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtmp_data.c
29
30 Abstract:
31 Data path subroutines
32
33 Revision History:
34 Who When What
35 Justin P. Mattock 11/07/2010 Fix typos
36 -------- ---------- ----------------------------------------------
37*/
38#include "../rt_config.h"
39#include <linux/kernel.h>
40
41void STARxEAPOLFrameIndicate(struct rt_rtmp_adapter *pAd,
42 struct rt_mac_table_entry *pEntry,
43 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
44{
45 PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
46 struct rt_rxwi * pRxWI = pRxBlk->pRxWI;
47 u8 *pTmpBuf;
48
49 if (pAd->StaCfg.WpaSupplicantUP) {
50 /* All EAPoL frames have to pass to upper layer (ex. WPA_SUPPLICANT daemon) */
51 /* TBD : process fragmented EAPol frames */
52 {
53 /* In 802.1x mode, if the received frame is EAP-SUCCESS packet, turn on the PortSecured variable */
54 if (pAd->StaCfg.IEEE8021X == TRUE &&
55 (EAP_CODE_SUCCESS ==
56 WpaCheckEapCode(pAd, pRxBlk->pData,
57 pRxBlk->DataSize,
58 LENGTH_802_1_H))) {
59 u8 *Key;
60 u8 CipherAlg;
61 int idx = 0;
62
63 DBGPRINT_RAW(RT_DEBUG_TRACE,
64 ("Receive EAP-SUCCESS Packet\n"));
65 /*pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
66 STA_PORT_SECURED(pAd);
67
68 if (pAd->StaCfg.IEEE8021x_required_keys ==
69 FALSE) {
70 idx = pAd->StaCfg.DesireSharedKeyId;
71 CipherAlg =
72 pAd->StaCfg.DesireSharedKey[idx].
73 CipherAlg;
74 Key =
75 pAd->StaCfg.DesireSharedKey[idx].
76 Key;
77
78 if (pAd->StaCfg.DesireSharedKey[idx].
79 KeyLen > 0) {
80#ifdef RTMP_MAC_PCI
81 struct rt_mac_table_entry *pEntry =
82 &pAd->MacTab.
83 Content[BSSID_WCID];
84
85 /* Set key material and cipherAlg to Asic */
86 AsicAddSharedKeyEntry(pAd, BSS0,
87 idx,
88 CipherAlg,
89 Key, NULL,
90 NULL);
91
92 /* Assign group key info */
93 RTMPAddWcidAttributeEntry(pAd,
94 BSS0,
95 idx,
96 CipherAlg,
97 NULL);
98
99 /* Assign pairwise key info */
100 RTMPAddWcidAttributeEntry(pAd,
101 BSS0,
102 idx,
103 CipherAlg,
104 pEntry);
105
106 pAd->IndicateMediaState =
107 NdisMediaStateConnected;
108 pAd->ExtraInfo =
109 GENERAL_LINK_UP;
110#endif /* RTMP_MAC_PCI // */
111#ifdef RTMP_MAC_USB
112 union {
113 char buf[sizeof
114 (struct rt_ndis_802_11_wep)
115 +
116 MAX_LEN_OF_KEY
117 - 1];
118 struct rt_ndis_802_11_wep keyinfo;
119 }
120 WepKey;
121 int len;
122
123 NdisZeroMemory(&WepKey,
124 sizeof(WepKey));
125 len =
126 pAd->StaCfg.
127 DesireSharedKey[idx].KeyLen;
128
129 NdisMoveMemory(WepKey.keyinfo.
130 KeyMaterial,
131 pAd->StaCfg.
132 DesireSharedKey
133 [idx].Key,
134 pAd->StaCfg.
135 DesireSharedKey
136 [idx].KeyLen);
137
138 WepKey.keyinfo.KeyIndex =
139 0x80000000 + idx;
140 WepKey.keyinfo.KeyLength = len;
141 pAd->SharedKey[BSS0][idx].
142 KeyLen =
143 (u8)(len <= 5 ? 5 : 13);
144
145 pAd->IndicateMediaState =
146 NdisMediaStateConnected;
147 pAd->ExtraInfo =
148 GENERAL_LINK_UP;
149 /* need to enqueue cmd to thread */
150 RTUSBEnqueueCmdFromNdis(pAd,
151 OID_802_11_ADD_WEP,
152 TRUE,
153 &WepKey,
154 sizeof
155 (WepKey.
156 keyinfo)
157 + len -
158 1);
159#endif /* RTMP_MAC_USB // */
160 /* For Preventing ShardKey Table is cleared by remove key procedure. */
161 pAd->SharedKey[BSS0][idx].
162 CipherAlg = CipherAlg;
163 pAd->SharedKey[BSS0][idx].
164 KeyLen =
165 pAd->StaCfg.
166 DesireSharedKey[idx].KeyLen;
167 NdisMoveMemory(pAd->
168 SharedKey[BSS0]
169 [idx].Key,
170 pAd->StaCfg.
171 DesireSharedKey
172 [idx].Key,
173 pAd->StaCfg.
174 DesireSharedKey
175 [idx].KeyLen);
176 }
177 }
178 }
179
180 Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
181 return;
182 }
183 } else {
184 /* Special DATA frame that has to pass to MLME */
185 /* 1. Cisco Aironet frames for CCX2. We need pass it to MLME for special process */
186 /* 2. EAPOL handshaking frames when driver supplicant enabled, pass to MLME for special process */
187 {
188 pTmpBuf = pRxBlk->pData - LENGTH_802_11;
189 NdisMoveMemory(pTmpBuf, pRxBlk->pHeader, LENGTH_802_11);
190 REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID,
191 pTmpBuf,
192 pRxBlk->DataSize +
193 LENGTH_802_11, pRxWI->RSSI0,
194 pRxWI->RSSI1, pRxWI->RSSI2,
195 pRxD->PlcpSignal);
196 DBGPRINT_RAW(RT_DEBUG_TRACE,
197 ("report EAPOL/AIRONET DATA to MLME (len=%d) !\n",
198 pRxBlk->DataSize));
199 }
200 }
201
202 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE);
203 return;
204
205}
206
207void STARxDataFrameAnnounce(struct rt_rtmp_adapter *pAd,
208 struct rt_mac_table_entry *pEntry,
209 struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID)
210{
211
212 /* non-EAP frame */
213 if (!RTMPCheckWPAframe
214 (pAd, pEntry, pRxBlk->pData, pRxBlk->DataSize, FromWhichBSSID)) {
215
216 {
217 /* drop all non-EAP DATA frame before */
218 /* this client's Port-Access-Control is secured */
219 if (pRxBlk->pHeader->FC.Wep) {
220 /* unsupported cipher suite */
221 if (pAd->StaCfg.WepStatus ==
222 Ndis802_11EncryptionDisabled) {
223 /* release packet */
224 RELEASE_NDIS_PACKET(pAd,
225 pRxBlk->pRxPacket,
226 NDIS_STATUS_FAILURE);
227 return;
228 }
229 } else {
230 /* encryption in-use but receive a non-EAPOL clear text frame, drop it */
231 if ((pAd->StaCfg.WepStatus !=
232 Ndis802_11EncryptionDisabled)
233 && (pAd->StaCfg.PortSecured ==
234 WPA_802_1X_PORT_NOT_SECURED)) {
235 /* release packet */
236 RELEASE_NDIS_PACKET(pAd,
237 pRxBlk->pRxPacket,
238 NDIS_STATUS_FAILURE);
239 return;
240 }
241 }
242 }
243 RX_BLK_CLEAR_FLAG(pRxBlk, fRX_EAP);
244 if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_ARALINK)) {
245 /* Normal legacy, AMPDU or AMSDU */
246 CmmRxnonRalinkFrameIndicate(pAd, pRxBlk,
247 FromWhichBSSID);
248
249 } else {
250 /* ARALINK */
251 CmmRxRalinkFrameIndicate(pAd, pEntry, pRxBlk,
252 FromWhichBSSID);
253 }
254 } else {
255 RX_BLK_SET_FLAG(pRxBlk, fRX_EAP);
256
257 if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU)
258 && (pAd->CommonCfg.bDisableReordering == 0)) {
259 Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);
260 } else {
261 /* Determine the destination of the EAP frame */
262 /* to WPA state machine or upper layer */
263 STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk,
264 FromWhichBSSID);
265 }
266 }
267}
268
269/* For TKIP frame, calculate the MIC value */
270BOOLEAN STACheckTkipMICValue(struct rt_rtmp_adapter *pAd,
271 struct rt_mac_table_entry *pEntry, struct rt_rx_blk *pRxBlk)
272{
273 struct rt_header_802_11 * pHeader = pRxBlk->pHeader;
274 u8 *pData = pRxBlk->pData;
275 u16 DataSize = pRxBlk->DataSize;
276 u8 UserPriority = pRxBlk->UserPriority;
277 struct rt_cipher_key *pWpaKey;
278 u8 *pDA, *pSA;
279
280 pWpaKey = &pAd->SharedKey[BSS0][pRxBlk->pRxWI->KeyIndex];
281
282 pDA = pHeader->Addr1;
283 if (RX_BLK_TEST_FLAG(pRxBlk, fRX_INFRA)) {
284 pSA = pHeader->Addr3;
285 } else {
286 pSA = pHeader->Addr2;
287 }
288
289 if (RTMPTkipCompareMICValue(pAd,
290 pData,
291 pDA,
292 pSA,
293 pWpaKey->RxMic,
294 UserPriority, DataSize) == FALSE) {
295 DBGPRINT_RAW(RT_DEBUG_ERROR, ("Rx MIC Value error 2\n"));
296
297 if (pAd->StaCfg.WpaSupplicantUP) {
298 WpaSendMicFailureToWpaSupplicant(pAd,
299 (pWpaKey->Type ==
300 PAIRWISEKEY) ? TRUE :
301 FALSE);
302 } else {
303 RTMPReportMicError(pAd, pWpaKey);
304 }
305
306 /* release packet */
307 RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket,
308 NDIS_STATUS_FAILURE);
309 return FALSE;
310 }
311
312 return TRUE;
313}
314
315/* */
316/* All Rx routines use struct rt_rx_blk structure to hande rx events */
317/* It is very important to build pRxBlk attributes */
318/* 1. pHeader pointer to 802.11 Header */
319/* 2. pData pointer to payload including LLC (just skip Header) */
320/* 3. set payload size including LLC to DataSize */
321/* 4. set some flags with RX_BLK_SET_FLAG() */
322/* */
323void STAHandleRxDataFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk)
324{
325 PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
326 struct rt_rxwi * pRxWI = pRxBlk->pRxWI;
327 struct rt_header_802_11 * pHeader = pRxBlk->pHeader;
328 void *pRxPacket = pRxBlk->pRxPacket;
329 BOOLEAN bFragment = FALSE;
330 struct rt_mac_table_entry *pEntry = NULL;
331 u8 FromWhichBSSID = BSS0;
332 u8 UserPriority = 0;
333
334 {
335 /* before LINK UP, all DATA frames are rejected */
336 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
337 /* release packet */
338 RELEASE_NDIS_PACKET(pAd, pRxPacket,
339 NDIS_STATUS_FAILURE);
340 return;
341 }
342 /* Drop not my BSS frames */
343 if (pRxD->MyBss == 0) {
344 {
345 /* release packet */
346 RELEASE_NDIS_PACKET(pAd, pRxPacket,
347 NDIS_STATUS_FAILURE);
348 return;
349 }
350 }
351
352 pAd->RalinkCounters.RxCountSinceLastNULL++;
353 if (pAd->CommonCfg.bAPSDCapable
354 && pAd->CommonCfg.APEdcaParm.bAPSDCapable
355 && (pHeader->FC.SubType & 0x08)) {
356 u8 *pData;
357 DBGPRINT(RT_DEBUG_INFO, ("bAPSDCapable\n"));
358
359 /* Qos bit 4 */
360 pData = (u8 *)pHeader + LENGTH_802_11;
361 if ((*pData >> 4) & 0x01) {
362 DBGPRINT(RT_DEBUG_INFO,
363 ("RxDone- Rcv EOSP frame, driver may fall into sleep\n"));
364 pAd->CommonCfg.bInServicePeriod = FALSE;
365
366 /* Force driver to fall into sleep mode when rcv EOSP frame */
367 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) {
368 u16 TbttNumToNextWakeUp;
369 u16 NextDtim =
370 pAd->StaCfg.DtimPeriod;
371 unsigned long Now;
372
373 NdisGetSystemUpTime(&Now);
374 NextDtim -=
375 (u16)(Now -
376 pAd->StaCfg.
377 LastBeaconRxTime) /
378 pAd->CommonCfg.BeaconPeriod;
379
380 TbttNumToNextWakeUp =
381 pAd->StaCfg.DefaultListenCount;
382 if (OPSTATUS_TEST_FLAG
383 (pAd, fOP_STATUS_RECEIVE_DTIM)
384 && (TbttNumToNextWakeUp > NextDtim))
385 TbttNumToNextWakeUp = NextDtim;
386
387 RTMP_SET_PSM_BIT(pAd, PWR_SAVE);
388 /* if WMM-APSD is failed, try to disable following line */
389 AsicSleepThenAutoWakeup(pAd,
390 TbttNumToNextWakeUp);
391 }
392 }
393
394 if ((pHeader->FC.MoreData)
395 && (pAd->CommonCfg.bInServicePeriod)) {
396 DBGPRINT(RT_DEBUG_TRACE,
397 ("Sending another trigger frame when More Data bit is set to 1\n"));
398 }
399 }
400 /* Drop NULL, CF-ACK(no data), CF-POLL(no data), and CF-ACK+CF-POLL(no data) data frame */
401 if ((pHeader->FC.SubType & 0x04)) /* bit 2 : no DATA */
402 {
403 /* release packet */
404 RELEASE_NDIS_PACKET(pAd, pRxPacket,
405 NDIS_STATUS_FAILURE);
406 return;
407 }
408 /* Drop not my BSS frame (we can not only check the MyBss bit in RxD) */
409
410 if (INFRA_ON(pAd)) {
411 /* Infrastructure mode, check address 2 for BSSID */
412 if (!RTMPEqualMemory
413 (&pHeader->Addr2, &pAd->CommonCfg.Bssid, 6)) {
414 /* Receive frame not my BSSID */
415 /* release packet */
416 RELEASE_NDIS_PACKET(pAd, pRxPacket,
417 NDIS_STATUS_FAILURE);
418 return;
419 }
420 } else /* Ad-Hoc mode or Not associated */
421 {
422 /* Ad-Hoc mode, check address 3 for BSSID */
423 if (!RTMPEqualMemory
424 (&pHeader->Addr3, &pAd->CommonCfg.Bssid, 6)) {
425 /* Receive frame not my BSSID */
426 /* release packet */
427 RELEASE_NDIS_PACKET(pAd, pRxPacket,
428 NDIS_STATUS_FAILURE);
429 return;
430 }
431 }
432
433 /* */
434 /* find pEntry */
435 /* */
436 if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE) {
437 pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
438 } else {
439 /* 1. release packet if infra mode */
440 /* 2. new a pEntry if ad-hoc mode */
441 RELEASE_NDIS_PACKET(pAd, pRxPacket,
442 NDIS_STATUS_FAILURE);
443 return;
444 }
445
446 /* infra or ad-hoc */
447 if (INFRA_ON(pAd)) {
448 RX_BLK_SET_FLAG(pRxBlk, fRX_INFRA);
449 ASSERT(pRxWI->WirelessCliID == BSSID_WCID);
450 }
451 /* check Atheros Client */
452 if ((pEntry->bIAmBadAtheros == FALSE) && (pRxD->AMPDU == 1)
453 && (pHeader->FC.Retry)) {
454 pEntry->bIAmBadAtheros = TRUE;
455 pAd->CommonCfg.IOTestParm.bCurrentAtheros = TRUE;
456 pAd->CommonCfg.IOTestParm.bLastAtheros = TRUE;
457 if (!STA_AES_ON(pAd)) {
458 AsicUpdateProtect(pAd, 8, ALLN_SETPROTECT, TRUE,
459 FALSE);
460 }
461 }
462 }
463
464 pRxBlk->pData = (u8 *) pHeader;
465
466 /* */
467 /* update RxBlk->pData, DataSize */
468 /* 802.11 Header, QOS, HTC, Hw Padding */
469 /* */
470
471 /* 1. skip 802.11 HEADER */
472 {
473 pRxBlk->pData += LENGTH_802_11;
474 pRxBlk->DataSize -= LENGTH_802_11;
475 }
476
477 /* 2. QOS */
478 if (pHeader->FC.SubType & 0x08) {
479 RX_BLK_SET_FLAG(pRxBlk, fRX_QOS);
480 UserPriority = *(pRxBlk->pData) & 0x0f;
481 /* bit 7 in QoS Control field signals the HT A-MSDU format */
482 if ((*pRxBlk->pData) & 0x80) {
483 RX_BLK_SET_FLAG(pRxBlk, fRX_AMSDU);
484 }
485 /* skip QOS contorl field */
486 pRxBlk->pData += 2;
487 pRxBlk->DataSize -= 2;
488 }
489 pRxBlk->UserPriority = UserPriority;
490
491 /* check if need to resend PS Poll when received packet with MoreData = 1 */
492 if ((pAd->StaCfg.Psm == PWR_SAVE) && (pHeader->FC.MoreData == 1)) {
493 if ((((UserPriority == 0) || (UserPriority == 3)) &&
494 pAd->CommonCfg.bAPSDAC_BE == 0) ||
495 (((UserPriority == 1) || (UserPriority == 2)) &&
496 pAd->CommonCfg.bAPSDAC_BK == 0) ||
497 (((UserPriority == 4) || (UserPriority == 5)) &&
498 pAd->CommonCfg.bAPSDAC_VI == 0) ||
499 (((UserPriority == 6) || (UserPriority == 7)) &&
500 pAd->CommonCfg.bAPSDAC_VO == 0)) {
501 /* non-UAPSD delivery-enabled AC */
502 RTMP_PS_POLL_ENQUEUE(pAd);
503 }
504 }
505 /* 3. Order bit: A-Ralink or HTC+ */
506 if (pHeader->FC.Order) {
507#ifdef AGGREGATION_SUPPORT
508 if ((pRxWI->PHYMODE <= MODE_OFDM)
509 && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)))
510 {
511 RX_BLK_SET_FLAG(pRxBlk, fRX_ARALINK);
512 } else
513#endif /* AGGREGATION_SUPPORT // */
514 {
515 RX_BLK_SET_FLAG(pRxBlk, fRX_HTC);
516 /* skip HTC contorl field */
517 pRxBlk->pData += 4;
518 pRxBlk->DataSize -= 4;
519 }
520 }
521 /* 4. skip HW padding */
522 if (pRxD->L2PAD) {
523 /* just move pData pointer */
524 /* because DataSize excluding HW padding */
525 RX_BLK_SET_FLAG(pRxBlk, fRX_PAD);
526 pRxBlk->pData += 2;
527 }
528
529 if (pRxD->BA) {
530 RX_BLK_SET_FLAG(pRxBlk, fRX_AMPDU);
531 }
532 /* */
533 /* Case I Process Broadcast & Multicast data frame */
534 /* */
535 if (pRxD->Bcast || pRxD->Mcast) {
536 INC_COUNTER64(pAd->WlanCounters.MulticastReceivedFrameCount);
537
538 /* Drop Mcast/Bcast frame with fragment bit on */
539 if (pHeader->FC.MoreFrag) {
540 /* release packet */
541 RELEASE_NDIS_PACKET(pAd, pRxPacket,
542 NDIS_STATUS_FAILURE);
543 return;
544 }
545 /* Filter out Bcast frame which AP relayed for us */
546 if (pHeader->FC.FrDs
547 && MAC_ADDR_EQUAL(pHeader->Addr3, pAd->CurrentAddress)) {
548 /* release packet */
549 RELEASE_NDIS_PACKET(pAd, pRxPacket,
550 NDIS_STATUS_FAILURE);
551 return;
552 }
553
554 Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID);
555 return;
556 } else if (pRxD->U2M) {
557 pAd->LastRxRate =
558 (u16)((pRxWI->MCS) + (pRxWI->BW << 7) +
559 (pRxWI->ShortGI << 8) + (pRxWI->PHYMODE << 14));
560
561 if (ADHOC_ON(pAd)) {
562 pEntry = MacTableLookup(pAd, pHeader->Addr2);
563 if (pEntry)
564 Update_Rssi_Sample(pAd, &pEntry->RssiSample,
565 pRxWI);
566 }
567
568 Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
569
570 pAd->StaCfg.LastSNR0 = (u8)(pRxWI->SNR0);
571 pAd->StaCfg.LastSNR1 = (u8)(pRxWI->SNR1);
572
573 pAd->RalinkCounters.OneSecRxOkDataCnt++;
574
575 if (!((pHeader->Frag == 0) && (pHeader->FC.MoreFrag == 0))) {
576 /* re-assemble the fragmented packets */
577 /* return complete frame (pRxPacket) or NULL */
578 bFragment = TRUE;
579 pRxPacket = RTMPDeFragmentDataFrame(pAd, pRxBlk);
580 }
581
582 if (pRxPacket) {
583 pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID];
584
585 /* process complete frame */
586 if (bFragment && (pRxD->Decrypted)
587 && (pEntry->WepStatus ==
588 Ndis802_11Encryption2Enabled)) {
589 /* Minus MIC length */
590 pRxBlk->DataSize -= 8;
591
592 /* For TKIP frame, calculate the MIC value */
593 if (STACheckTkipMICValue(pAd, pEntry, pRxBlk) ==
594 FALSE) {
595 return;
596 }
597 }
598
599 STARxDataFrameAnnounce(pAd, pEntry, pRxBlk,
600 FromWhichBSSID);
601 return;
602 } else {
603 /* just return */
604 /* because RTMPDeFragmentDataFrame() will release rx packet, */
605 /* if packet is fragmented */
606 return;
607 }
608 }
609
610 ASSERT(0);
611 /* release packet */
612 RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
613}
614
615void STAHandleRxMgmtFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk)
616{
617 PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD);
618 struct rt_rxwi * pRxWI = pRxBlk->pRxWI;
619 struct rt_header_802_11 * pHeader = pRxBlk->pHeader;
620 void *pRxPacket = pRxBlk->pRxPacket;
621
622 do {
623
624 /* check if need to resend PS Poll when received packet with MoreData = 1 */
625 if ((pAd->StaCfg.Psm == PWR_SAVE)
626 && (pHeader->FC.MoreData == 1)) {
627 /* for UAPSD, all management frames will be VO priority */
628 if (pAd->CommonCfg.bAPSDAC_VO == 0) {
629 /* non-UAPSD delivery-enabled AC */
630 RTMP_PS_POLL_ENQUEUE(pAd);
631 }
632 }
633
634 /* TODO: if MoreData == 0, station can go to sleep */
635
636 /* We should collect RSSI not only U2M data but also my beacon */
637 if ((pHeader->FC.SubType == SUBTYPE_BEACON)
638 && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2))
639 && (pAd->RxAnt.EvaluatePeriod == 0)) {
640 Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI);
641
642 pAd->StaCfg.LastSNR0 = (u8)(pRxWI->SNR0);
643 pAd->StaCfg.LastSNR1 = (u8)(pRxWI->SNR1);
644 }
645
646 /* First check the size, it MUST not exceed the mlme queue size */
647 if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE) {
648 DBGPRINT_ERR("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount);
649 break;
650 }
651
652 REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pHeader,
653 pRxWI->MPDUtotalByteCount,
654 pRxWI->RSSI0, pRxWI->RSSI1,
655 pRxWI->RSSI2, pRxD->PlcpSignal);
656 } while (FALSE);
657
658 RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS);
659}
660
661void STAHandleRxControlFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk)
662{
663 struct rt_rxwi * pRxWI = pRxBlk->pRxWI;
664 struct rt_header_802_11 * pHeader = pRxBlk->pHeader;
665 void *pRxPacket = pRxBlk->pRxPacket;
666
667 switch (pHeader->FC.SubType) {
668 case SUBTYPE_BLOCK_ACK_REQ:
669 {
670 CntlEnqueueForRecv(pAd, pRxWI->WirelessCliID,
671 (pRxWI->MPDUtotalByteCount),
672 (struct rt_frame_ba_req *) pHeader);
673 }
674 break;
675 case SUBTYPE_BLOCK_ACK:
676 case SUBTYPE_ACK:
677 default:
678 break;
679 }
680
681 RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE);
682}
683
684/*
685 ========================================================================
686
687 Routine Description:
688 Process RxDone interrupt, running in DPC level
689
690 Arguments:
691 pAd Pointer to our adapter
692
693 Return Value:
694 None
695
696 IRQL = DISPATCH_LEVEL
697
698 Note:
699 This routine has to maintain Rx ring read pointer.
700 Need to consider QOS DATA format when converting to 802.3
701 ========================================================================
702*/
703BOOLEAN STARxDoneInterruptHandle(struct rt_rtmp_adapter *pAd, IN BOOLEAN argc)
704{
705 int Status;
706 u32 RxProcessed, RxPending;
707 BOOLEAN bReschedule = FALSE;
708 PRT28XX_RXD_STRUC pRxD;
709 u8 *pData;
710 struct rt_rxwi * pRxWI;
711 void *pRxPacket;
712 struct rt_header_802_11 * pHeader;
713 struct rt_rx_blk RxCell;
714
715 RxProcessed = RxPending = 0;
716
717 /* process whole rx ring */
718 while (1) {
719
720 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF |
721 fRTMP_ADAPTER_RESET_IN_PROGRESS |
722 fRTMP_ADAPTER_HALT_IN_PROGRESS |
723 fRTMP_ADAPTER_NIC_NOT_EXIST) ||
724 !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)) {
725 break;
726 }
727#ifdef RTMP_MAC_PCI
728 if (RxProcessed++ > MAX_RX_PROCESS_CNT) {
729 /* need to reschedule rx handle */
730 bReschedule = TRUE;
731 break;
732 }
733#endif /* RTMP_MAC_PCI // */
734
735 RxProcessed++; /* test */
736
737 /* 1. allocate a new data packet into rx ring to replace received packet */
738 /* then processing the received packet */
739 /* 2. the callee must take charge of release of packet */
740 /* 3. As far as driver is concerned , */
741 /* the rx packet must */
742 /* a. be indicated to upper layer or */
743 /* b. be released if it is discarded */
744 pRxPacket =
745 GetPacketFromRxRing(pAd, &(RxCell.RxD), &bReschedule,
746 &RxPending);
747 if (pRxPacket == NULL) {
748 /* no more packet to process */
749 break;
750 }
751 /* get rx ring descriptor */
752 pRxD = &(RxCell.RxD);
753 /* get rx data buffer */
754 pData = GET_OS_PKT_DATAPTR(pRxPacket);
755 pRxWI = (struct rt_rxwi *) pData;
756 pHeader = (struct rt_header_802_11 *) (pData + RXWI_SIZE);
757
758 /* build RxCell */
759 RxCell.pRxWI = pRxWI;
760 RxCell.pHeader = pHeader;
761 RxCell.pRxPacket = pRxPacket;
762 RxCell.pData = (u8 *) pHeader;
763 RxCell.DataSize = pRxWI->MPDUtotalByteCount;
764 RxCell.Flags = 0;
765
766 /* Increase Total receive byte counter after real data received no mater any error or not */
767 pAd->RalinkCounters.ReceivedByteCount +=
768 pRxWI->MPDUtotalByteCount;
769 pAd->RalinkCounters.OneSecReceivedByteCount +=
770 pRxWI->MPDUtotalByteCount;
771 pAd->RalinkCounters.RxCount++;
772
773 INC_COUNTER64(pAd->WlanCounters.ReceivedFragmentCount);
774
775 if (pRxWI->MPDUtotalByteCount < 14)
776 Status = NDIS_STATUS_FAILURE;
777
778 if (MONITOR_ON(pAd)) {
779 send_monitor_packets(pAd, &RxCell);
780 break;
781 }
782
783 /* STARxDoneInterruptHandle() is called in rtusb_bulk.c */
784
785 /* Check for all RxD errors */
786 Status = RTMPCheckRxError(pAd, pHeader, pRxWI, pRxD);
787
788 /* Handle the received frame */
789 if (Status == NDIS_STATUS_SUCCESS) {
790 switch (pHeader->FC.Type) {
791 /* CASE I, receive a DATA frame */
792 case BTYPE_DATA:
793 {
794 /* process DATA frame */
795 STAHandleRxDataFrame(pAd, &RxCell);
796 }
797 break;
798 /* CASE II, receive a MGMT frame */
799 case BTYPE_MGMT:
800 {
801 STAHandleRxMgmtFrame(pAd, &RxCell);
802 }
803 break;
804 /* CASE III. receive a CNTL frame */
805 case BTYPE_CNTL:
806 {
807 STAHandleRxControlFrame(pAd, &RxCell);
808 }
809 break;
810 /* discard other type */
811 default:
812 RELEASE_NDIS_PACKET(pAd, pRxPacket,
813 NDIS_STATUS_FAILURE);
814 break;
815 }
816 } else {
817 pAd->Counters8023.RxErrors++;
818 /* discard this frame */
819 RELEASE_NDIS_PACKET(pAd, pRxPacket,
820 NDIS_STATUS_FAILURE);
821 }
822 }
823
824 return bReschedule;
825}
826
827/*
828 ========================================================================
829
830 Routine Description:
831 Arguments:
832 pAd Pointer to our adapter
833
834 IRQL = DISPATCH_LEVEL
835
836 ========================================================================
837*/
838void RTMPHandleTwakeupInterrupt(struct rt_rtmp_adapter *pAd)
839{
840 AsicForceWakeup(pAd, FALSE);
841}
842
843/*
844========================================================================
845Routine Description:
846 Early checking and OS-depened parsing for Tx packet send to our STA driver.
847
848Arguments:
849 void * MiniportAdapterContext Pointer refer to the device handle, i.e., the pAd.
850 void ** ppPacketArray The packet array need to do transmission.
851 u32 NumberOfPackets Number of packet in packet array.
852
853Return Value:
854 NONE
855
856Note:
857 This function does early checking and classification for send-out packet.
858 You only can put OS-depened & STA related code in here.
859========================================================================
860*/
861void STASendPackets(void *MiniportAdapterContext,
862 void **ppPacketArray, u32 NumberOfPackets)
863{
864 u32 Index;
865 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)MiniportAdapterContext;
866 void *pPacket;
867 BOOLEAN allowToSend = FALSE;
868
869 for (Index = 0; Index < NumberOfPackets; Index++) {
870 pPacket = ppPacketArray[Index];
871
872 do {
873 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)
874 || RTMP_TEST_FLAG(pAd,
875 fRTMP_ADAPTER_HALT_IN_PROGRESS)
876 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) {
877 /* Drop send request since hardware is in reset state */
878 break;
879 } else if (!INFRA_ON(pAd) && !ADHOC_ON(pAd)) {
880 /* Drop send request since there are no physical connection yet */
881 break;
882 } else {
883 /* Record that orignal packet source is from NDIS layer,so that */
884 /* later on driver knows how to release this NDIS PACKET */
885 RTMP_SET_PACKET_WCID(pPacket, 0); /* this field is useless when in STA mode */
886 RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
887 NDIS_SET_PACKET_STATUS(pPacket,
888 NDIS_STATUS_PENDING);
889 pAd->RalinkCounters.PendingNdisPacketCount++;
890
891 allowToSend = TRUE;
892 }
893 } while (FALSE);
894
895 if (allowToSend == TRUE)
896 STASendPacket(pAd, pPacket);
897 else
898 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
899 }
900
901 /* Dequeue outgoing frames from TxSwQueue[] and process it */
902 RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS);
903
904}
905
906/*
907========================================================================
908Routine Description:
909 This routine is used to do packet parsing and classification for Tx packet
910 to STA device, and it will en-queue packets to our TxSwQueue depends on AC
911 class.
912
913Arguments:
914 pAd Pointer to our adapter
915 pPacket Pointer to send packet
916
917Return Value:
918 NDIS_STATUS_SUCCESS If success to queue the packet into TxSwQueue.
919 NDIS_STATUS_FAILURE If failed to do en-queue.
920
921Note:
922 You only can put OS-indepened & STA related code in here.
923========================================================================
924*/
925int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket)
926{
927 struct rt_packet_info PacketInfo;
928 u8 *pSrcBufVA;
929 u32 SrcBufLen;
930 u32 AllowFragSize;
931 u8 NumberOfFrag;
932 u8 RTSRequired;
933 u8 QueIdx, UserPriority;
934 struct rt_mac_table_entry *pEntry = NULL;
935 unsigned int IrqFlags;
936 u8 FlgIsIP = 0;
937 u8 Rate;
938
939 /* Prepare packet information structure for buffer descriptor */
940 /* chained within a single NDIS packet. */
941 RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen);
942
943 if (pSrcBufVA == NULL) {
944 DBGPRINT(RT_DEBUG_ERROR,
945 ("STASendPacket --> pSrcBufVA == NULL !SrcBufLen=%x\n",
946 SrcBufLen));
947 /* Resource is low, system did not allocate virtual address */
948 /* return NDIS_STATUS_FAILURE directly to upper layer */
949 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
950 return NDIS_STATUS_FAILURE;
951 }
952
953 if (SrcBufLen < 14) {
954 DBGPRINT(RT_DEBUG_ERROR,
955 ("STASendPacket --> Ndis Packet buffer error!\n"));
956 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
957 return (NDIS_STATUS_FAILURE);
958 }
959 /* In HT rate adhoc mode, A-MPDU is often used. So need to lookup BA Table and MAC Entry. */
960 /* Note multicast packets in adhoc also use BSSID_WCID index. */
961 {
962 if (INFRA_ON(pAd)) {
963 {
964 pEntry = &pAd->MacTab.Content[BSSID_WCID];
965 RTMP_SET_PACKET_WCID(pPacket, BSSID_WCID);
966 Rate = pAd->CommonCfg.TxRate;
967 }
968 } else if (ADHOC_ON(pAd)) {
969 if (*pSrcBufVA & 0x01) {
970 RTMP_SET_PACKET_WCID(pPacket, MCAST_WCID);
971 pEntry = &pAd->MacTab.Content[MCAST_WCID];
972 } else {
973 pEntry = MacTableLookup(pAd, pSrcBufVA);
974 }
975 Rate = pAd->CommonCfg.TxRate;
976 }
977 }
978
979 if (!pEntry) {
980 DBGPRINT(RT_DEBUG_ERROR,
981 ("STASendPacket->Cannot find pEntry(%pM) in MacTab!\n",
982 pSrcBufVA));
983 /* Resource is low, system did not allocate virtual address */
984 /* return NDIS_STATUS_FAILURE directly to upper layer */
985 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
986 return NDIS_STATUS_FAILURE;
987 }
988
989 if (ADHOC_ON(pAd)
990 ) {
991 RTMP_SET_PACKET_WCID(pPacket, (u8)pEntry->Aid);
992 }
993 /* */
994 /* Check the Ethernet Frame type of this packet, and set the RTMP_SET_PACKET_SPECIFIC flags. */
995 /* Here we set the PACKET_SPECIFIC flags(LLC, VLAN, DHCP/ARP, EAPOL). */
996 RTMPCheckEtherType(pAd, pPacket);
997
998 /* */
999 /* WPA 802.1x secured port control - drop all non-802.1x frame before port secured */
1000 /* */
1001 if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1002 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
1003 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
1004 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
1005 || (pAd->StaCfg.IEEE8021X == TRUE)
1006 )
1007 && ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)
1008 || (pAd->StaCfg.MicErrCnt >= 2))
1009 && (RTMP_GET_PACKET_EAPOL(pPacket) == FALSE)
1010 ) {
1011 DBGPRINT(RT_DEBUG_TRACE,
1012 ("STASendPacket --> Drop packet before port secured!\n"));
1013 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1014
1015 return (NDIS_STATUS_FAILURE);
1016 }
1017
1018 /* STEP 1. Decide number of fragments required to deliver this MSDU. */
1019 /* The estimation here is not very accurate because difficult to */
1020 /* take encryption overhead into consideration here. The result */
1021 /* "NumberOfFrag" is then just used to pre-check if enough free */
1022 /* TXD are available to hold this MSDU. */
1023
1024 if (*pSrcBufVA & 0x01) /* fragmentation not allowed on multicast & broadcast */
1025 NumberOfFrag = 1;
1026 else if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED))
1027 NumberOfFrag = 1; /* Aggregation overwhelms fragmentation */
1028 else if (CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED))
1029 NumberOfFrag = 1; /* Aggregation overwhelms fragmentation */
1030 else if ((pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTMIX)
1031 || (pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTGREENFIELD))
1032 NumberOfFrag = 1; /* MIMO RATE overwhelms fragmentation */
1033 else {
1034 /* The calculated "NumberOfFrag" is a rough estimation because of various */
1035 /* encryption/encapsulation overhead not taken into consideration. This number is just */
1036 /* used to make sure enough free TXD are available before fragmentation takes place. */
1037 /* In case the actual required number of fragments of an NDIS packet */
1038 /* excceeds "NumberOfFrag"caculated here and not enough free TXD available, the */
1039 /* last fragment (i.e. last MPDU) will be dropped in RTMPHardTransmit() due to out of */
1040 /* resource, and the NDIS packet will be indicated NDIS_STATUS_FAILURE. This should */
1041 /* rarely happen and the penalty is just like a TX RETRY fail. Affordable. */
1042
1043 AllowFragSize =
1044 (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 -
1045 LENGTH_CRC;
1046 NumberOfFrag =
1047 ((PacketInfo.TotalPacketLength - LENGTH_802_3 +
1048 LENGTH_802_1_H) / AllowFragSize) + 1;
1049 /* To get accurate number of fragmentation, Minus 1 if the size just match to allowable fragment size */
1050 if (((PacketInfo.TotalPacketLength - LENGTH_802_3 +
1051 LENGTH_802_1_H) % AllowFragSize) == 0) {
1052 NumberOfFrag--;
1053 }
1054 }
1055
1056 /* Save fragment number to Ndis packet reserved field */
1057 RTMP_SET_PACKET_FRAGMENTS(pPacket, NumberOfFrag);
1058
1059 /* STEP 2. Check the requirement of RTS: */
1060 /* If multiple fragment required, RTS is required only for the first fragment */
1061 /* if the fragment size is larger than RTS threshold */
1062 /* For RT28xx, Let ASIC send RTS/CTS */
1063 /* RTMP_SET_PACKET_RTS(pPacket, 0); */
1064 if (NumberOfFrag > 1)
1065 RTSRequired =
1066 (pAd->CommonCfg.FragmentThreshold >
1067 pAd->CommonCfg.RtsThreshold) ? 1 : 0;
1068 else
1069 RTSRequired =
1070 (PacketInfo.TotalPacketLength >
1071 pAd->CommonCfg.RtsThreshold) ? 1 : 0;
1072
1073 /* Save RTS requirement to Ndis packet reserved field */
1074 RTMP_SET_PACKET_RTS(pPacket, RTSRequired);
1075 RTMP_SET_PACKET_TXRATE(pPacket, pAd->CommonCfg.TxRate);
1076
1077 /* */
1078 /* STEP 3. Traffic classification. outcome = <UserPriority, QueIdx> */
1079 /* */
1080 UserPriority = 0;
1081 QueIdx = QID_AC_BE;
1082 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
1083 CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE)) {
1084 u16 Protocol;
1085 u8 LlcSnapLen = 0, Byte0, Byte1;
1086 do {
1087 /* get Ethernet protocol field */
1088 Protocol =
1089 (u16)((pSrcBufVA[12] << 8) + pSrcBufVA[13]);
1090 if (Protocol <= 1500) {
1091 /* get Ethernet protocol field from LLC/SNAP */
1092 if (Sniff2BytesFromNdisBuffer
1093 (PacketInfo.pFirstBuffer, LENGTH_802_3 + 6,
1094 &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)
1095 break;
1096
1097 Protocol = (u16)((Byte0 << 8) + Byte1);
1098 LlcSnapLen = 8;
1099 }
1100 /* always AC_BE for non-IP packet */
1101 if (Protocol != 0x0800)
1102 break;
1103
1104 /* get IP header */
1105 if (Sniff2BytesFromNdisBuffer
1106 (PacketInfo.pFirstBuffer, LENGTH_802_3 + LlcSnapLen,
1107 &Byte0, &Byte1) != NDIS_STATUS_SUCCESS)
1108 break;
1109
1110 /* return AC_BE if packet is not IPv4 */
1111 if ((Byte0 & 0xf0) != 0x40)
1112 break;
1113
1114 FlgIsIP = 1;
1115 UserPriority = (Byte1 & 0xe0) >> 5;
1116 QueIdx = MapUserPriorityToAccessCategory[UserPriority];
1117
1118 /* TODO: have to check ACM bit. apply TSPEC if ACM is ON */
1119 /* TODO: downgrade UP & QueIdx before passing ACM */
1120 /*
1121 Under WMM ACM control, we dont need to check the bit;
1122 Or when a TSPEC is built for VO but we will change to issue
1123 BA session for BE here, so we will not use BA to send VO packets.
1124 */
1125 if (pAd->CommonCfg.APEdcaParm.bACM[QueIdx]) {
1126 UserPriority = 0;
1127 QueIdx = QID_AC_BE;
1128 }
1129 } while (FALSE);
1130 }
1131
1132 RTMP_SET_PACKET_UP(pPacket, UserPriority);
1133
1134 /* Make sure SendTxWait queue resource won't be used by other threads */
1135 RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
1136 if (pAd->TxSwQueue[QueIdx].Number >= MAX_PACKETS_IN_QUEUE) {
1137 RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
1138 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1139
1140 return NDIS_STATUS_FAILURE;
1141 } else {
1142 InsertTailQueueAc(pAd, pEntry, &pAd->TxSwQueue[QueIdx],
1143 PACKET_TO_QUEUE_ENTRY(pPacket));
1144 }
1145 RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
1146
1147 if ((pAd->CommonCfg.BACapability.field.AutoBA == TRUE) &&
1148 IS_HT_STA(pEntry)) {
1149 /*struct rt_mac_table_entry *pMacEntry = &pAd->MacTab.Content[BSSID_WCID]; */
1150 if (((pEntry->TXBAbitmap & (1 << UserPriority)) == 0) &&
1151 ((pEntry->BADeclineBitmap & (1 << UserPriority)) == 0) &&
1152 (pEntry->PortSecured == WPA_802_1X_PORT_SECURED)
1153 /* For IOT compatibility, if */
1154 /* 1. It is Ralink chip or */
1155 /* 2. It is OPEN or AES mode, */
1156 /* then BA session can be bulit. */
1157 && ((pEntry->ValidAsCLI && pAd->MlmeAux.APRalinkIe != 0x0)
1158 || (pEntry->WepStatus != Ndis802_11WEPEnabled
1159 && pEntry->WepStatus !=
1160 Ndis802_11Encryption2Enabled))
1161 ) {
1162 BAOriSessionSetUp(pAd, pEntry, UserPriority, 0, 10,
1163 FALSE);
1164 }
1165 }
1166
1167 pAd->RalinkCounters.OneSecOsTxCount[QueIdx]++; /* TODO: for debug only. to be removed */
1168 return NDIS_STATUS_SUCCESS;
1169}
1170
1171/*
1172 ========================================================================
1173
1174 Routine Description:
1175 This subroutine will scan through relative ring descriptor to find
1176 out available free ring descriptor and compare with request size.
1177
1178 Arguments:
1179 pAd Pointer to our adapter
1180 QueIdx Selected TX Ring
1181
1182 Return Value:
1183 NDIS_STATUS_FAILURE Not enough free descriptor
1184 NDIS_STATUS_SUCCESS Enough free descriptor
1185
1186 IRQL = PASSIVE_LEVEL
1187 IRQL = DISPATCH_LEVEL
1188
1189 Note:
1190
1191 ========================================================================
1192*/
1193#ifdef RTMP_MAC_PCI
1194int RTMPFreeTXDRequest(struct rt_rtmp_adapter *pAd,
1195 u8 QueIdx,
1196 u8 NumberRequired, u8 *FreeNumberIs)
1197{
1198 unsigned long FreeNumber = 0;
1199 int Status = NDIS_STATUS_FAILURE;
1200
1201 switch (QueIdx) {
1202 case QID_AC_BK:
1203 case QID_AC_BE:
1204 case QID_AC_VI:
1205 case QID_AC_VO:
1206 if (pAd->TxRing[QueIdx].TxSwFreeIdx >
1207 pAd->TxRing[QueIdx].TxCpuIdx)
1208 FreeNumber =
1209 pAd->TxRing[QueIdx].TxSwFreeIdx -
1210 pAd->TxRing[QueIdx].TxCpuIdx - 1;
1211 else
1212 FreeNumber =
1213 pAd->TxRing[QueIdx].TxSwFreeIdx + TX_RING_SIZE -
1214 pAd->TxRing[QueIdx].TxCpuIdx - 1;
1215
1216 if (FreeNumber >= NumberRequired)
1217 Status = NDIS_STATUS_SUCCESS;
1218 break;
1219
1220 case QID_MGMT:
1221 if (pAd->MgmtRing.TxSwFreeIdx > pAd->MgmtRing.TxCpuIdx)
1222 FreeNumber =
1223 pAd->MgmtRing.TxSwFreeIdx - pAd->MgmtRing.TxCpuIdx -
1224 1;
1225 else
1226 FreeNumber =
1227 pAd->MgmtRing.TxSwFreeIdx + MGMT_RING_SIZE -
1228 pAd->MgmtRing.TxCpuIdx - 1;
1229
1230 if (FreeNumber >= NumberRequired)
1231 Status = NDIS_STATUS_SUCCESS;
1232 break;
1233
1234 default:
1235 DBGPRINT(RT_DEBUG_ERROR,
1236 ("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx));
1237 break;
1238 }
1239 *FreeNumberIs = (u8)FreeNumber;
1240
1241 return (Status);
1242}
1243#endif /* RTMP_MAC_PCI // */
1244#ifdef RTMP_MAC_USB
1245/*
1246 Actually, this function used to check if the TxHardware Queue still has frame need to send.
1247 If no frame need to send, go to sleep, else, still wake up.
1248*/
1249int RTMPFreeTXDRequest(struct rt_rtmp_adapter *pAd,
1250 u8 QueIdx,
1251 u8 NumberRequired, u8 *FreeNumberIs)
1252{
1253 /*unsigned long FreeNumber = 0; */
1254 int Status = NDIS_STATUS_FAILURE;
1255 unsigned long IrqFlags;
1256 struct rt_ht_tx_context *pHTTXContext;
1257
1258 switch (QueIdx) {
1259 case QID_AC_BK:
1260 case QID_AC_BE:
1261 case QID_AC_VI:
1262 case QID_AC_VO:
1263 {
1264 pHTTXContext = &pAd->TxContext[QueIdx];
1265 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx],
1266 IrqFlags);
1267 if ((pHTTXContext->CurWritePosition !=
1268 pHTTXContext->ENextBulkOutPosition)
1269 || (pHTTXContext->IRPPending == TRUE)) {
1270 Status = NDIS_STATUS_FAILURE;
1271 } else {
1272 Status = NDIS_STATUS_SUCCESS;
1273 }
1274 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx],
1275 IrqFlags);
1276 }
1277 break;
1278 case QID_MGMT:
1279 if (pAd->MgmtRing.TxSwFreeIdx != MGMT_RING_SIZE)
1280 Status = NDIS_STATUS_FAILURE;
1281 else
1282 Status = NDIS_STATUS_SUCCESS;
1283 break;
1284 default:
1285 DBGPRINT(RT_DEBUG_ERROR,
1286 ("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx));
1287 break;
1288 }
1289
1290 return (Status);
1291}
1292#endif /* RTMP_MAC_USB // */
1293
1294void RTMPSendDisassociationFrame(struct rt_rtmp_adapter *pAd)
1295{
1296}
1297
1298void RTMPSendNullFrame(struct rt_rtmp_adapter *pAd,
1299 u8 TxRate, IN BOOLEAN bQosNull)
1300{
1301 u8 NullFrame[48];
1302 unsigned long Length;
1303 struct rt_header_802_11 * pHeader_802_11;
1304
1305 /* WPA 802.1x secured port control */
1306 if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1307 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
1308 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
1309 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
1310 || (pAd->StaCfg.IEEE8021X == TRUE)
1311 ) && (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) {
1312 return;
1313 }
1314
1315 NdisZeroMemory(NullFrame, 48);
1316 Length = sizeof(struct rt_header_802_11);
1317
1318 pHeader_802_11 = (struct rt_header_802_11 *) NullFrame;
1319
1320 pHeader_802_11->FC.Type = BTYPE_DATA;
1321 pHeader_802_11->FC.SubType = SUBTYPE_NULL_FUNC;
1322 pHeader_802_11->FC.ToDs = 1;
1323 COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid);
1324 COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress);
1325 COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid);
1326
1327 if (pAd->CommonCfg.bAPSDForcePowerSave) {
1328 pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
1329 } else {
1330 pHeader_802_11->FC.PwrMgmt =
1331 (pAd->StaCfg.Psm == PWR_SAVE) ? 1 : 0;
1332 }
1333 pHeader_802_11->Duration =
1334 pAd->CommonCfg.Dsifs + RTMPCalcDuration(pAd, TxRate, 14);
1335
1336 pAd->Sequence++;
1337 pHeader_802_11->Sequence = pAd->Sequence;
1338
1339 /* Prepare QosNull function frame */
1340 if (bQosNull) {
1341 pHeader_802_11->FC.SubType = SUBTYPE_QOS_NULL;
1342
1343 /* copy QOS control bytes */
1344 NullFrame[Length] = 0;
1345 NullFrame[Length + 1] = 0;
1346 Length += 2; /* if pad with 2 bytes for alignment, APSD will fail */
1347 }
1348
1349 HAL_KickOutNullFrameTx(pAd, 0, NullFrame, Length);
1350
1351}
1352
1353/* IRQL = DISPATCH_LEVEL */
1354void RTMPSendRTSFrame(struct rt_rtmp_adapter *pAd,
1355 u8 *pDA,
1356 IN unsigned int NextMpduSize,
1357 u8 TxRate,
1358 u8 RTSRate,
1359 u16 AckDuration, u8 QueIdx, u8 FrameGap)
1360{
1361}
1362
1363/* -------------------------------------------------------- */
1364/* FIND ENCRYPT KEY AND DECIDE CIPHER ALGORITHM */
1365/* Find the WPA key, either Group or Pairwise Key */
1366/* LEAP + TKIP also use WPA key. */
1367/* -------------------------------------------------------- */
1368/* Decide WEP bit and cipher suite to be used. Same cipher suite should be used for whole fragment burst */
1369/* In Cisco CCX 2.0 Leap Authentication */
1370/* WepStatus is Ndis802_11Encryption1Enabled but the key will use PairwiseKey */
1371/* Instead of the SharedKey, SharedKey Length may be Zero. */
1372void STAFindCipherAlgorithm(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
1373{
1374 NDIS_802_11_ENCRYPTION_STATUS Cipher; /* To indicate cipher used for this packet */
1375 u8 CipherAlg = CIPHER_NONE; /* cipher alogrithm */
1376 u8 KeyIdx = 0xff;
1377 u8 *pSrcBufVA;
1378 struct rt_cipher_key *pKey = NULL;
1379
1380 pSrcBufVA = GET_OS_PKT_DATAPTR(pTxBlk->pPacket);
1381
1382 {
1383 /* Select Cipher */
1384 if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd)))
1385 Cipher = pAd->StaCfg.GroupCipher; /* Cipher for Multicast or Broadcast */
1386 else
1387 Cipher = pAd->StaCfg.PairCipher; /* Cipher for Unicast */
1388
1389 if (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket)) {
1390 ASSERT(pAd->SharedKey[BSS0][0].CipherAlg <=
1391 CIPHER_CKIP128);
1392
1393 /* 4-way handshaking frame must be clear */
1394 if (!(TX_BLK_TEST_FLAG(pTxBlk, fTX_bClearEAPFrame))
1395 && (pAd->SharedKey[BSS0][0].CipherAlg)
1396 && (pAd->SharedKey[BSS0][0].KeyLen)) {
1397 CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
1398 KeyIdx = 0;
1399 }
1400 } else if (Cipher == Ndis802_11Encryption1Enabled) {
1401 KeyIdx = pAd->StaCfg.DefaultKeyId;
1402 } else if ((Cipher == Ndis802_11Encryption2Enabled) ||
1403 (Cipher == Ndis802_11Encryption3Enabled)) {
1404 if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) /* multicast */
1405 KeyIdx = pAd->StaCfg.DefaultKeyId;
1406 else if (pAd->SharedKey[BSS0][0].KeyLen)
1407 KeyIdx = 0;
1408 else
1409 KeyIdx = pAd->StaCfg.DefaultKeyId;
1410 }
1411
1412 if (KeyIdx == 0xff)
1413 CipherAlg = CIPHER_NONE;
1414 else if ((Cipher == Ndis802_11EncryptionDisabled)
1415 || (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 0))
1416 CipherAlg = CIPHER_NONE;
1417 else if (pAd->StaCfg.WpaSupplicantUP &&
1418 (Cipher == Ndis802_11Encryption1Enabled) &&
1419 (pAd->StaCfg.IEEE8021X == TRUE) &&
1420 (pAd->StaCfg.PortSecured ==
1421 WPA_802_1X_PORT_NOT_SECURED))
1422 CipherAlg = CIPHER_NONE;
1423 else {
1424 /*Header_802_11.FC.Wep = 1; */
1425 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
1426 pKey = &pAd->SharedKey[BSS0][KeyIdx];
1427 }
1428 }
1429
1430 pTxBlk->CipherAlg = CipherAlg;
1431 pTxBlk->pKey = pKey;
1432}
1433
1434void STABuildCommon802_11Header(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
1435{
1436 struct rt_header_802_11 *pHeader_802_11;
1437
1438 /* */
1439 /* MAKE A COMMON 802.11 HEADER */
1440 /* */
1441
1442 /* normal wlan header size : 24 octets */
1443 pTxBlk->MpduHeaderLen = sizeof(struct rt_header_802_11);
1444
1445 pHeader_802_11 =
1446 (struct rt_header_802_11 *) & pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
1447
1448 NdisZeroMemory(pHeader_802_11, sizeof(struct rt_header_802_11));
1449
1450 pHeader_802_11->FC.FrDs = 0;
1451 pHeader_802_11->FC.Type = BTYPE_DATA;
1452 pHeader_802_11->FC.SubType =
1453 ((TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) ? SUBTYPE_QDATA :
1454 SUBTYPE_DATA);
1455
1456 if (pTxBlk->pMacEntry) {
1457 if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bForceNonQoS)) {
1458 pHeader_802_11->Sequence =
1459 pTxBlk->pMacEntry->NonQosDataSeq;
1460 pTxBlk->pMacEntry->NonQosDataSeq =
1461 (pTxBlk->pMacEntry->NonQosDataSeq + 1) & MAXSEQ;
1462 } else {
1463 {
1464 pHeader_802_11->Sequence =
1465 pTxBlk->pMacEntry->TxSeq[pTxBlk->
1466 UserPriority];
1467 pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority] =
1468 (pTxBlk->pMacEntry->
1469 TxSeq[pTxBlk->UserPriority] + 1) & MAXSEQ;
1470 }
1471 }
1472 } else {
1473 pHeader_802_11->Sequence = pAd->Sequence;
1474 pAd->Sequence = (pAd->Sequence + 1) & MAXSEQ; /* next sequence */
1475 }
1476
1477 pHeader_802_11->Frag = 0;
1478
1479 pHeader_802_11->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);
1480
1481 {
1482 if (INFRA_ON(pAd)) {
1483 {
1484 COPY_MAC_ADDR(pHeader_802_11->Addr1,
1485 pAd->CommonCfg.Bssid);
1486 COPY_MAC_ADDR(pHeader_802_11->Addr2,
1487 pAd->CurrentAddress);
1488 COPY_MAC_ADDR(pHeader_802_11->Addr3,
1489 pTxBlk->pSrcBufHeader);
1490 pHeader_802_11->FC.ToDs = 1;
1491 }
1492 } else if (ADHOC_ON(pAd)) {
1493 COPY_MAC_ADDR(pHeader_802_11->Addr1,
1494 pTxBlk->pSrcBufHeader);
1495 COPY_MAC_ADDR(pHeader_802_11->Addr2,
1496 pAd->CurrentAddress);
1497 COPY_MAC_ADDR(pHeader_802_11->Addr3,
1498 pAd->CommonCfg.Bssid);
1499 pHeader_802_11->FC.ToDs = 0;
1500 }
1501 }
1502
1503 if (pTxBlk->CipherAlg != CIPHER_NONE)
1504 pHeader_802_11->FC.Wep = 1;
1505
1506 /* ----------------------------------------------------------------- */
1507 /* STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later. */
1508 /* ----------------------------------------------------------------- */
1509 if (pAd->CommonCfg.bAPSDForcePowerSave)
1510 pHeader_802_11->FC.PwrMgmt = PWR_SAVE;
1511 else
1512 pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
1513}
1514
1515void STABuildCache802_11Header(struct rt_rtmp_adapter *pAd,
1516 struct rt_tx_blk *pTxBlk, u8 * pHeader)
1517{
1518 struct rt_mac_table_entry *pMacEntry;
1519 struct rt_header_802_11 * pHeader80211;
1520
1521 pHeader80211 = (struct rt_header_802_11 *) pHeader;
1522 pMacEntry = pTxBlk->pMacEntry;
1523
1524 /* */
1525 /* Update the cached 802.11 HEADER */
1526 /* */
1527
1528 /* normal wlan header size : 24 octets */
1529 pTxBlk->MpduHeaderLen = sizeof(struct rt_header_802_11);
1530
1531 /* More Bit */
1532 pHeader80211->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData);
1533
1534 /* Sequence */
1535 pHeader80211->Sequence = pMacEntry->TxSeq[pTxBlk->UserPriority];
1536 pMacEntry->TxSeq[pTxBlk->UserPriority] =
1537 (pMacEntry->TxSeq[pTxBlk->UserPriority] + 1) & MAXSEQ;
1538
1539 {
1540 /* Check if the frame can be sent through DLS direct link interface */
1541 /* If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability) */
1542
1543 /* The addr3 of normal packet send from DS is Dest Mac address. */
1544 if (ADHOC_ON(pAd))
1545 COPY_MAC_ADDR(pHeader80211->Addr3,
1546 pAd->CommonCfg.Bssid);
1547 else
1548 COPY_MAC_ADDR(pHeader80211->Addr3,
1549 pTxBlk->pSrcBufHeader);
1550 }
1551
1552 /* ----------------------------------------------------------------- */
1553 /* STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later. */
1554 /* ----------------------------------------------------------------- */
1555 if (pAd->CommonCfg.bAPSDForcePowerSave)
1556 pHeader80211->FC.PwrMgmt = PWR_SAVE;
1557 else
1558 pHeader80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE);
1559}
1560
1561static inline u8 *STA_Build_ARalink_Frame_Header(struct rt_rtmp_adapter *pAd,
1562 struct rt_tx_blk *pTxBlk)
1563{
1564 u8 *pHeaderBufPtr;
1565 struct rt_header_802_11 *pHeader_802_11;
1566 void *pNextPacket;
1567 u32 nextBufLen;
1568 struct rt_queue_entry *pQEntry;
1569
1570 STAFindCipherAlgorithm(pAd, pTxBlk);
1571 STABuildCommon802_11Header(pAd, pTxBlk);
1572
1573 pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
1574 pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr;
1575
1576 /* steal "order" bit to mark "aggregation" */
1577 pHeader_802_11->FC.Order = 1;
1578
1579 /* skip common header */
1580 pHeaderBufPtr += pTxBlk->MpduHeaderLen;
1581
1582 if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) {
1583 /* */
1584 /* build QOS Control bytes */
1585 /* */
1586 *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
1587
1588 *(pHeaderBufPtr + 1) = 0;
1589 pHeaderBufPtr += 2;
1590 pTxBlk->MpduHeaderLen += 2;
1591 }
1592 /* padding at front of LLC header. LLC header should at 4-bytes alignment. */
1593 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr;
1594 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4);
1595 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen);
1596
1597 /* For RA Aggregation, */
1598 /* put the 2nd MSDU length(extra 2-byte field) after struct rt_qos_control in little endian format */
1599 pQEntry = pTxBlk->TxPacketList.Head;
1600 pNextPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
1601 nextBufLen = GET_OS_PKT_LEN(pNextPacket);
1602 if (RTMP_GET_PACKET_VLAN(pNextPacket))
1603 nextBufLen -= LENGTH_802_1Q;
1604
1605 *pHeaderBufPtr = (u8)nextBufLen & 0xff;
1606 *(pHeaderBufPtr + 1) = (u8)(nextBufLen >> 8);
1607
1608 pHeaderBufPtr += 2;
1609 pTxBlk->MpduHeaderLen += 2;
1610
1611 return pHeaderBufPtr;
1612
1613}
1614
1615static inline u8 *STA_Build_AMSDU_Frame_Header(struct rt_rtmp_adapter *pAd,
1616 struct rt_tx_blk *pTxBlk)
1617{
1618 u8 *pHeaderBufPtr; /*, pSaveBufPtr; */
1619 struct rt_header_802_11 *pHeader_802_11;
1620
1621 STAFindCipherAlgorithm(pAd, pTxBlk);
1622 STABuildCommon802_11Header(pAd, pTxBlk);
1623
1624 pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
1625 pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr;
1626
1627 /* skip common header */
1628 pHeaderBufPtr += pTxBlk->MpduHeaderLen;
1629
1630 /* */
1631 /* build QOS Control bytes */
1632 /* */
1633 *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
1634
1635 /* */
1636 /* A-MSDU packet */
1637 /* */
1638 *pHeaderBufPtr |= 0x80;
1639
1640 *(pHeaderBufPtr + 1) = 0;
1641 pHeaderBufPtr += 2;
1642 pTxBlk->MpduHeaderLen += 2;
1643
1644 /*pSaveBufPtr = pHeaderBufPtr; */
1645
1646 /* */
1647 /* padding at front of LLC header */
1648 /* LLC header should locate at 4-octets aligment */
1649 /* */
1650 /* @@@ MpduHeaderLen excluding padding @@@ */
1651 /* */
1652 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr;
1653 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4);
1654 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen);
1655
1656 return pHeaderBufPtr;
1657
1658}
1659
1660void STA_AMPDU_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
1661{
1662 struct rt_header_802_11 *pHeader_802_11;
1663 u8 *pHeaderBufPtr;
1664 u16 FreeNumber;
1665 struct rt_mac_table_entry *pMacEntry;
1666 BOOLEAN bVLANPkt;
1667 struct rt_queue_entry *pQEntry;
1668
1669 ASSERT(pTxBlk);
1670
1671 while (pTxBlk->TxPacketList.Head) {
1672 pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
1673 pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
1674 if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) {
1675 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket,
1676 NDIS_STATUS_FAILURE);
1677 continue;
1678 }
1679
1680 bVLANPkt =
1681 (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
1682
1683 pMacEntry = pTxBlk->pMacEntry;
1684 if (pMacEntry->isCached) {
1685 /* NOTE: Please make sure the size of pMacEntry->CachedBuf[] is smaller than pTxBlk->HeaderBuf[]! */
1686 NdisMoveMemory((u8 *)& pTxBlk->
1687 HeaderBuf[TXINFO_SIZE],
1688 (u8 *)& pMacEntry->CachedBuf[0],
1689 TXWI_SIZE + sizeof(struct rt_header_802_11));
1690 pHeaderBufPtr =
1691 (u8 *)(&pTxBlk->
1692 HeaderBuf[TXINFO_SIZE + TXWI_SIZE]);
1693 STABuildCache802_11Header(pAd, pTxBlk, pHeaderBufPtr);
1694 } else {
1695 STAFindCipherAlgorithm(pAd, pTxBlk);
1696 STABuildCommon802_11Header(pAd, pTxBlk);
1697
1698 pHeaderBufPtr =
1699 &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
1700 }
1701
1702 pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr;
1703
1704 /* skip common header */
1705 pHeaderBufPtr += pTxBlk->MpduHeaderLen;
1706
1707 /* */
1708 /* build QOS Control bytes */
1709 /* */
1710 *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
1711 *(pHeaderBufPtr + 1) = 0;
1712 pHeaderBufPtr += 2;
1713 pTxBlk->MpduHeaderLen += 2;
1714
1715 /* */
1716 /* build HTC+ */
1717 /* HTC control filed following QoS field */
1718 /* */
1719 if ((pAd->CommonCfg.bRdg == TRUE)
1720 && CLIENT_STATUS_TEST_FLAG(pTxBlk->pMacEntry,
1721 fCLIENT_STATUS_RDG_CAPABLE)) {
1722 if (pMacEntry->isCached == FALSE) {
1723 /* mark HTC bit */
1724 pHeader_802_11->FC.Order = 1;
1725
1726 NdisZeroMemory(pHeaderBufPtr, 4);
1727 *(pHeaderBufPtr + 3) |= 0x80;
1728 }
1729 pHeaderBufPtr += 4;
1730 pTxBlk->MpduHeaderLen += 4;
1731 }
1732 /*pTxBlk->MpduHeaderLen = pHeaderBufPtr - pTxBlk->HeaderBuf - TXWI_SIZE - TXINFO_SIZE; */
1733 ASSERT(pTxBlk->MpduHeaderLen >= 24);
1734
1735 /* skip 802.3 header */
1736 pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
1737 pTxBlk->SrcBufLen -= LENGTH_802_3;
1738
1739 /* skip vlan tag */
1740 if (bVLANPkt) {
1741 pTxBlk->pSrcBufData += LENGTH_802_1Q;
1742 pTxBlk->SrcBufLen -= LENGTH_802_1Q;
1743 }
1744 /* */
1745 /* padding at front of LLC header */
1746 /* LLC header should locate at 4-octets aligment */
1747 /* */
1748 /* @@@ MpduHeaderLen excluding padding @@@ */
1749 /* */
1750 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr;
1751 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4);
1752 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen);
1753
1754 {
1755
1756 /* */
1757 /* Insert LLC-SNAP encapsulation - 8 octets */
1758 /* */
1759 EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->
1760 pSrcBufData - 2,
1761 pTxBlk->
1762 pExtraLlcSnapEncap);
1763 if (pTxBlk->pExtraLlcSnapEncap) {
1764 NdisMoveMemory(pHeaderBufPtr,
1765 pTxBlk->pExtraLlcSnapEncap, 6);
1766 pHeaderBufPtr += 6;
1767 /* get 2 octets (TypeofLen) */
1768 NdisMoveMemory(pHeaderBufPtr,
1769 pTxBlk->pSrcBufData - 2, 2);
1770 pHeaderBufPtr += 2;
1771 pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
1772 }
1773
1774 }
1775
1776 if (pMacEntry->isCached) {
1777 RTMPWriteTxWI_Cache(pAd,
1778 (struct rt_txwi *) (&pTxBlk->
1779 HeaderBuf
1780 [TXINFO_SIZE]),
1781 pTxBlk);
1782 } else {
1783 RTMPWriteTxWI_Data(pAd,
1784 (struct rt_txwi *) (&pTxBlk->
1785 HeaderBuf
1786 [TXINFO_SIZE]),
1787 pTxBlk);
1788
1789 NdisZeroMemory((u8 *)(&pMacEntry->CachedBuf[0]),
1790 sizeof(pMacEntry->CachedBuf));
1791 NdisMoveMemory((u8 *)(&pMacEntry->CachedBuf[0]),
1792 (u8 *)(&pTxBlk->
1793 HeaderBuf[TXINFO_SIZE]),
1794 (pHeaderBufPtr -
1795 (u8 *)(&pTxBlk->
1796 HeaderBuf[TXINFO_SIZE])));
1797 pMacEntry->isCached = TRUE;
1798 }
1799
1800 /* calculate Transmitted AMPDU count and ByteCount */
1801 {
1802 pAd->RalinkCounters.TransmittedMPDUsInAMPDUCount.u.
1803 LowPart++;
1804 pAd->RalinkCounters.TransmittedOctetsInAMPDUCount.
1805 QuadPart += pTxBlk->SrcBufLen;
1806 }
1807
1808 /*FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); */
1809
1810 HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);
1811
1812 /* */
1813 /* Kick out Tx */
1814 /* */
1815 if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
1816 HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
1817
1818 pAd->RalinkCounters.KickTxCount++;
1819 pAd->RalinkCounters.OneSecTxDoneCount++;
1820 }
1821
1822}
1823
1824void STA_AMSDU_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
1825{
1826 u8 *pHeaderBufPtr;
1827 u16 FreeNumber;
1828 u16 subFramePayloadLen = 0; /* AMSDU Subframe length without AMSDU-Header / Padding. */
1829 u16 totalMPDUSize = 0;
1830 u8 *subFrameHeader;
1831 u8 padding = 0;
1832 u16 FirstTx = 0, LastTxIdx = 0;
1833 BOOLEAN bVLANPkt;
1834 int frameNum = 0;
1835 struct rt_queue_entry *pQEntry;
1836
1837 ASSERT(pTxBlk);
1838
1839 ASSERT((pTxBlk->TxPacketList.Number > 1));
1840
1841 while (pTxBlk->TxPacketList.Head) {
1842 pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
1843 pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
1844 if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) {
1845 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket,
1846 NDIS_STATUS_FAILURE);
1847 continue;
1848 }
1849
1850 bVLANPkt =
1851 (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
1852
1853 /* skip 802.3 header */
1854 pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
1855 pTxBlk->SrcBufLen -= LENGTH_802_3;
1856
1857 /* skip vlan tag */
1858 if (bVLANPkt) {
1859 pTxBlk->pSrcBufData += LENGTH_802_1Q;
1860 pTxBlk->SrcBufLen -= LENGTH_802_1Q;
1861 }
1862
1863 if (frameNum == 0) {
1864 pHeaderBufPtr =
1865 STA_Build_AMSDU_Frame_Header(pAd, pTxBlk);
1866
1867 /* NOTE: TxWI->MPDUtotalByteCount will be updated after final frame was handled. */
1868 RTMPWriteTxWI_Data(pAd,
1869 (struct rt_txwi *) (&pTxBlk->
1870 HeaderBuf
1871 [TXINFO_SIZE]),
1872 pTxBlk);
1873 } else {
1874 pHeaderBufPtr = &pTxBlk->HeaderBuf[0];
1875 padding =
1876 ROUND_UP(LENGTH_AMSDU_SUBFRAMEHEAD +
1877 subFramePayloadLen,
1878 4) - (LENGTH_AMSDU_SUBFRAMEHEAD +
1879 subFramePayloadLen);
1880 NdisZeroMemory(pHeaderBufPtr,
1881 padding + LENGTH_AMSDU_SUBFRAMEHEAD);
1882 pHeaderBufPtr += padding;
1883 pTxBlk->MpduHeaderLen = padding;
1884 }
1885
1886 /* */
1887 /* A-MSDU subframe */
1888 /* DA(6)+SA(6)+Length(2) + LLC/SNAP Encap */
1889 /* */
1890 subFrameHeader = pHeaderBufPtr;
1891 subFramePayloadLen = pTxBlk->SrcBufLen;
1892
1893 NdisMoveMemory(subFrameHeader, pTxBlk->pSrcBufHeader, 12);
1894
1895 pHeaderBufPtr += LENGTH_AMSDU_SUBFRAMEHEAD;
1896 pTxBlk->MpduHeaderLen += LENGTH_AMSDU_SUBFRAMEHEAD;
1897
1898 /* */
1899 /* Insert LLC-SNAP encapsulation - 8 octets */
1900 /* */
1901 EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData - 2,
1902 pTxBlk->pExtraLlcSnapEncap);
1903
1904 subFramePayloadLen = pTxBlk->SrcBufLen;
1905
1906 if (pTxBlk->pExtraLlcSnapEncap) {
1907 NdisMoveMemory(pHeaderBufPtr,
1908 pTxBlk->pExtraLlcSnapEncap, 6);
1909 pHeaderBufPtr += 6;
1910 /* get 2 octets (TypeofLen) */
1911 NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData - 2,
1912 2);
1913 pHeaderBufPtr += 2;
1914 pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
1915 subFramePayloadLen += LENGTH_802_1_H;
1916 }
1917 /* update subFrame Length field */
1918 subFrameHeader[12] = (subFramePayloadLen & 0xFF00) >> 8;
1919 subFrameHeader[13] = subFramePayloadLen & 0xFF;
1920
1921 totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
1922
1923 if (frameNum == 0)
1924 FirstTx =
1925 HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum,
1926 &FreeNumber);
1927 else
1928 LastTxIdx =
1929 HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum,
1930 &FreeNumber);
1931
1932 frameNum++;
1933
1934 pAd->RalinkCounters.KickTxCount++;
1935 pAd->RalinkCounters.OneSecTxDoneCount++;
1936
1937 /* calculate Transmitted AMSDU Count and ByteCount */
1938 {
1939 pAd->RalinkCounters.TransmittedAMSDUCount.u.LowPart++;
1940 pAd->RalinkCounters.TransmittedOctetsInAMSDU.QuadPart +=
1941 totalMPDUSize;
1942 }
1943
1944 }
1945
1946 HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);
1947 HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);
1948
1949 /* */
1950 /* Kick out Tx */
1951 /* */
1952 if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
1953 HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
1954}
1955
1956void STA_Legacy_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
1957{
1958 struct rt_header_802_11 *pHeader_802_11;
1959 u8 *pHeaderBufPtr;
1960 u16 FreeNumber;
1961 BOOLEAN bVLANPkt;
1962 struct rt_queue_entry *pQEntry;
1963
1964 ASSERT(pTxBlk);
1965
1966 pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
1967 pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
1968 if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) {
1969 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
1970 return;
1971 }
1972
1973 if (pTxBlk->TxFrameType == TX_MCAST_FRAME) {
1974 INC_COUNTER64(pAd->WlanCounters.MulticastTransmittedFrameCount);
1975 }
1976
1977 if (RTMP_GET_PACKET_RTS(pTxBlk->pPacket))
1978 TX_BLK_SET_FLAG(pTxBlk, fTX_bRtsRequired);
1979 else
1980 TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bRtsRequired);
1981
1982 bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
1983
1984 if (pTxBlk->TxRate < pAd->CommonCfg.MinTxRate)
1985 pTxBlk->TxRate = pAd->CommonCfg.MinTxRate;
1986
1987 STAFindCipherAlgorithm(pAd, pTxBlk);
1988 STABuildCommon802_11Header(pAd, pTxBlk);
1989
1990 /* skip 802.3 header */
1991 pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
1992 pTxBlk->SrcBufLen -= LENGTH_802_3;
1993
1994 /* skip vlan tag */
1995 if (bVLANPkt) {
1996 pTxBlk->pSrcBufData += LENGTH_802_1Q;
1997 pTxBlk->SrcBufLen -= LENGTH_802_1Q;
1998 }
1999
2000 pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
2001 pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr;
2002
2003 /* skip common header */
2004 pHeaderBufPtr += pTxBlk->MpduHeaderLen;
2005
2006 if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) {
2007 /* */
2008 /* build QOS Control bytes */
2009 /* */
2010 *(pHeaderBufPtr) =
2011 ((pTxBlk->UserPriority & 0x0F) | (pAd->CommonCfg.
2012 AckPolicy[pTxBlk->
2013 QueIdx] << 5));
2014 *(pHeaderBufPtr + 1) = 0;
2015 pHeaderBufPtr += 2;
2016 pTxBlk->MpduHeaderLen += 2;
2017 }
2018 /* The remaining content of MPDU header should locate at 4-octets alignment */
2019 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr;
2020 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4);
2021 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen);
2022
2023 {
2024
2025 /* */
2026 /* Insert LLC-SNAP encapsulation - 8 octets */
2027 /* */
2028 /* */
2029 /* if original Ethernet frame contains no LLC/SNAP, */
2030 /* then an extra LLC/SNAP encap is required */
2031 /* */
2032 EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader,
2033 pTxBlk->pExtraLlcSnapEncap);
2034 if (pTxBlk->pExtraLlcSnapEncap) {
2035 u8 vlan_size;
2036
2037 NdisMoveMemory(pHeaderBufPtr,
2038 pTxBlk->pExtraLlcSnapEncap, 6);
2039 pHeaderBufPtr += 6;
2040 /* skip vlan tag */
2041 vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;
2042 /* get 2 octets (TypeofLen) */
2043 NdisMoveMemory(pHeaderBufPtr,
2044 pTxBlk->pSrcBufHeader + 12 + vlan_size,
2045 2);
2046 pHeaderBufPtr += 2;
2047 pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
2048 }
2049
2050 }
2051
2052 /* */
2053 /* prepare for TXWI */
2054 /* use Wcid as Key Index */
2055 /* */
2056
2057 RTMPWriteTxWI_Data(pAd, (struct rt_txwi *) (&pTxBlk->HeaderBuf[TXINFO_SIZE]),
2058 pTxBlk);
2059
2060 /*FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); */
2061
2062 HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber);
2063
2064 pAd->RalinkCounters.KickTxCount++;
2065 pAd->RalinkCounters.OneSecTxDoneCount++;
2066
2067 /* */
2068 /* Kick out Tx */
2069 /* */
2070 if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
2071 HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
2072}
2073
2074void STA_ARalink_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
2075{
2076 u8 *pHeaderBufPtr;
2077 u16 FreeNumber;
2078 u16 totalMPDUSize = 0;
2079 u16 FirstTx, LastTxIdx;
2080 int frameNum = 0;
2081 BOOLEAN bVLANPkt;
2082 struct rt_queue_entry *pQEntry;
2083
2084 ASSERT(pTxBlk);
2085
2086 ASSERT((pTxBlk->TxPacketList.Number == 2));
2087
2088 FirstTx = LastTxIdx = 0; /* Is it ok init they as 0? */
2089 while (pTxBlk->TxPacketList.Head) {
2090 pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
2091 pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
2092
2093 if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) {
2094 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket,
2095 NDIS_STATUS_FAILURE);
2096 continue;
2097 }
2098
2099 bVLANPkt =
2100 (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
2101
2102 /* skip 802.3 header */
2103 pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
2104 pTxBlk->SrcBufLen -= LENGTH_802_3;
2105
2106 /* skip vlan tag */
2107 if (bVLANPkt) {
2108 pTxBlk->pSrcBufData += LENGTH_802_1Q;
2109 pTxBlk->SrcBufLen -= LENGTH_802_1Q;
2110 }
2111
2112 if (frameNum == 0) { /* For first frame, we need to create the 802.11 header + padding(optional) + RA-AGG-LEN + SNAP Header */
2113
2114 pHeaderBufPtr =
2115 STA_Build_ARalink_Frame_Header(pAd, pTxBlk);
2116
2117 /* It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount */
2118 /* will be updated after final frame was handled. */
2119 RTMPWriteTxWI_Data(pAd,
2120 (struct rt_txwi *) (&pTxBlk->
2121 HeaderBuf
2122 [TXINFO_SIZE]),
2123 pTxBlk);
2124
2125 /* */
2126 /* Insert LLC-SNAP encapsulation - 8 octets */
2127 /* */
2128 EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->
2129 pSrcBufData - 2,
2130 pTxBlk->
2131 pExtraLlcSnapEncap);
2132
2133 if (pTxBlk->pExtraLlcSnapEncap) {
2134 NdisMoveMemory(pHeaderBufPtr,
2135 pTxBlk->pExtraLlcSnapEncap, 6);
2136 pHeaderBufPtr += 6;
2137 /* get 2 octets (TypeofLen) */
2138 NdisMoveMemory(pHeaderBufPtr,
2139 pTxBlk->pSrcBufData - 2, 2);
2140 pHeaderBufPtr += 2;
2141 pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
2142 }
2143 } else { /* For second aggregated frame, we need create the 802.3 header to headerBuf, because PCI will copy it to SDPtr0. */
2144
2145 pHeaderBufPtr = &pTxBlk->HeaderBuf[0];
2146 pTxBlk->MpduHeaderLen = 0;
2147
2148 /* A-Ralink sub-sequent frame header is the same as 802.3 header. */
2149 /* DA(6)+SA(6)+FrameType(2) */
2150 NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader,
2151 12);
2152 pHeaderBufPtr += 12;
2153 /* get 2 octets (TypeofLen) */
2154 NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData - 2,
2155 2);
2156 pHeaderBufPtr += 2;
2157 pTxBlk->MpduHeaderLen = LENGTH_ARALINK_SUBFRAMEHEAD;
2158 }
2159
2160 totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen;
2161
2162 /*FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); */
2163 if (frameNum == 0)
2164 FirstTx =
2165 HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum,
2166 &FreeNumber);
2167 else
2168 LastTxIdx =
2169 HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum,
2170 &FreeNumber);
2171
2172 frameNum++;
2173
2174 pAd->RalinkCounters.OneSecTxAggregationCount++;
2175 pAd->RalinkCounters.KickTxCount++;
2176 pAd->RalinkCounters.OneSecTxDoneCount++;
2177
2178 }
2179
2180 HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx);
2181 HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx);
2182
2183 /* */
2184 /* Kick out Tx */
2185 /* */
2186 if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
2187 HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
2188
2189}
2190
2191void STA_Fragment_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
2192{
2193 struct rt_header_802_11 *pHeader_802_11;
2194 u8 *pHeaderBufPtr;
2195 u16 FreeNumber;
2196 u8 fragNum = 0;
2197 struct rt_packet_info PacketInfo;
2198 u16 EncryptionOverhead = 0;
2199 u32 FreeMpduSize, SrcRemainingBytes;
2200 u16 AckDuration;
2201 u32 NextMpduSize;
2202 BOOLEAN bVLANPkt;
2203 struct rt_queue_entry *pQEntry;
2204 HTTRANSMIT_SETTING *pTransmit;
2205
2206 ASSERT(pTxBlk);
2207
2208 pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList);
2209 pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
2210 if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) {
2211 RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE);
2212 return;
2213 }
2214
2215 ASSERT(TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag));
2216 bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE);
2217
2218 STAFindCipherAlgorithm(pAd, pTxBlk);
2219 STABuildCommon802_11Header(pAd, pTxBlk);
2220
2221 if (pTxBlk->CipherAlg == CIPHER_TKIP) {
2222 pTxBlk->pPacket =
2223 duplicate_pkt_with_TKIP_MIC(pAd, pTxBlk->pPacket);
2224 if (pTxBlk->pPacket == NULL)
2225 return;
2226 RTMP_QueryPacketInfo(pTxBlk->pPacket, &PacketInfo,
2227 &pTxBlk->pSrcBufHeader,
2228 &pTxBlk->SrcBufLen);
2229 }
2230 /* skip 802.3 header */
2231 pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3;
2232 pTxBlk->SrcBufLen -= LENGTH_802_3;
2233
2234 /* skip vlan tag */
2235 if (bVLANPkt) {
2236 pTxBlk->pSrcBufData += LENGTH_802_1Q;
2237 pTxBlk->SrcBufLen -= LENGTH_802_1Q;
2238 }
2239
2240 pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE];
2241 pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr;
2242
2243 /* skip common header */
2244 pHeaderBufPtr += pTxBlk->MpduHeaderLen;
2245
2246 if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) {
2247 /* */
2248 /* build QOS Control bytes */
2249 /* */
2250 *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F);
2251
2252 *(pHeaderBufPtr + 1) = 0;
2253 pHeaderBufPtr += 2;
2254 pTxBlk->MpduHeaderLen += 2;
2255 }
2256 /* */
2257 /* padding at front of LLC header */
2258 /* LLC header should locate at 4-octets aligment */
2259 /* */
2260 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr;
2261 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4);
2262 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen);
2263
2264 /* */
2265 /* Insert LLC-SNAP encapsulation - 8 octets */
2266 /* */
2267 /* */
2268 /* if original Ethernet frame contains no LLC/SNAP, */
2269 /* then an extra LLC/SNAP encap is required */
2270 /* */
2271 EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader,
2272 pTxBlk->pExtraLlcSnapEncap);
2273 if (pTxBlk->pExtraLlcSnapEncap) {
2274 u8 vlan_size;
2275
2276 NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6);
2277 pHeaderBufPtr += 6;
2278 /* skip vlan tag */
2279 vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0;
2280 /* get 2 octets (TypeofLen) */
2281 NdisMoveMemory(pHeaderBufPtr,
2282 pTxBlk->pSrcBufHeader + 12 + vlan_size, 2);
2283 pHeaderBufPtr += 2;
2284 pTxBlk->MpduHeaderLen += LENGTH_802_1_H;
2285 }
2286
2287 /* If TKIP is used and fragmentation is required. Driver has to */
2288 /* append TKIP MIC at tail of the scatter buffer */
2289 /* MAC ASIC will only perform IV/EIV/ICV insertion but no TKIP MIC */
2290 if (pTxBlk->CipherAlg == CIPHER_TKIP) {
2291 RTMPCalculateMICValue(pAd, pTxBlk->pPacket,
2292 pTxBlk->pExtraLlcSnapEncap, pTxBlk->pKey,
2293 0);
2294
2295 /* NOTE: DON'T refer the skb->len directly after following copy. Because the length is not adjusted */
2296 /* to correct length, refer to pTxBlk->SrcBufLen for the packet length in following progress. */
2297 NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen,
2298 &pAd->PrivateInfo.Tx.MIC[0], 8);
2299 /*skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8); */
2300 pTxBlk->SrcBufLen += 8;
2301 pTxBlk->TotalFrameLen += 8;
2302 pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC;
2303 }
2304 /* */
2305 /* calculate the overhead bytes that encryption algorithm may add. This */
2306 /* affects the calculate of "duration" field */
2307 /* */
2308 if ((pTxBlk->CipherAlg == CIPHER_WEP64)
2309 || (pTxBlk->CipherAlg == CIPHER_WEP128))
2310 EncryptionOverhead = 8; /*WEP: IV[4] + ICV[4]; */
2311 else if (pTxBlk->CipherAlg == CIPHER_TKIP_NO_MIC)
2312 EncryptionOverhead = 12; /*TKIP: IV[4] + EIV[4] + ICV[4], MIC will be added to TotalPacketLength */
2313 else if (pTxBlk->CipherAlg == CIPHER_TKIP)
2314 EncryptionOverhead = 20; /*TKIP: IV[4] + EIV[4] + ICV[4] + MIC[8] */
2315 else if (pTxBlk->CipherAlg == CIPHER_AES)
2316 EncryptionOverhead = 16; /* AES: IV[4] + EIV[4] + MIC[8] */
2317 else
2318 EncryptionOverhead = 0;
2319
2320 pTransmit = pTxBlk->pTransmit;
2321 /* Decide the TX rate */
2322 if (pTransmit->field.MODE == MODE_CCK)
2323 pTxBlk->TxRate = pTransmit->field.MCS;
2324 else if (pTransmit->field.MODE == MODE_OFDM)
2325 pTxBlk->TxRate = pTransmit->field.MCS + RATE_FIRST_OFDM_RATE;
2326 else
2327 pTxBlk->TxRate = RATE_6_5;
2328
2329 /* decide how much time an ACK/CTS frame will consume in the air */
2330 if (pTxBlk->TxRate <= RATE_LAST_OFDM_RATE)
2331 AckDuration =
2332 RTMPCalcDuration(pAd,
2333 pAd->CommonCfg.ExpectedACKRate[pTxBlk->
2334 TxRate],
2335 14);
2336 else
2337 AckDuration = RTMPCalcDuration(pAd, RATE_6_5, 14);
2338
2339 /* Init the total payload length of this frame. */
2340 SrcRemainingBytes = pTxBlk->SrcBufLen;
2341
2342 pTxBlk->TotalFragNum = 0xff;
2343
2344 do {
2345
2346 FreeMpduSize = pAd->CommonCfg.FragmentThreshold - LENGTH_CRC;
2347
2348 FreeMpduSize -= pTxBlk->MpduHeaderLen;
2349
2350 if (SrcRemainingBytes <= FreeMpduSize) { /* this is the last or only fragment */
2351
2352 pTxBlk->SrcBufLen = SrcRemainingBytes;
2353
2354 pHeader_802_11->FC.MoreFrag = 0;
2355 pHeader_802_11->Duration =
2356 pAd->CommonCfg.Dsifs + AckDuration;
2357
2358 /* Indicate the lower layer that this's the last fragment. */
2359 pTxBlk->TotalFragNum = fragNum;
2360 } else { /* more fragment is required */
2361
2362 pTxBlk->SrcBufLen = FreeMpduSize;
2363
2364 NextMpduSize =
2365 min(((u32)SrcRemainingBytes - pTxBlk->SrcBufLen),
2366 ((u32)pAd->CommonCfg.FragmentThreshold));
2367 pHeader_802_11->FC.MoreFrag = 1;
2368 pHeader_802_11->Duration =
2369 (3 * pAd->CommonCfg.Dsifs) + (2 * AckDuration) +
2370 RTMPCalcDuration(pAd, pTxBlk->TxRate,
2371 NextMpduSize + EncryptionOverhead);
2372 }
2373
2374 if (fragNum == 0)
2375 pTxBlk->FrameGap = IFS_HTTXOP;
2376 else
2377 pTxBlk->FrameGap = IFS_SIFS;
2378
2379 RTMPWriteTxWI_Data(pAd,
2380 (struct rt_txwi *) (&pTxBlk->
2381 HeaderBuf[TXINFO_SIZE]),
2382 pTxBlk);
2383
2384 HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, &FreeNumber);
2385
2386 pAd->RalinkCounters.KickTxCount++;
2387 pAd->RalinkCounters.OneSecTxDoneCount++;
2388
2389 /* Update the frame number, remaining size of the NDIS packet payload. */
2390
2391 /* space for 802.11 header. */
2392 if (fragNum == 0 && pTxBlk->pExtraLlcSnapEncap)
2393 pTxBlk->MpduHeaderLen -= LENGTH_802_1_H;
2394
2395 fragNum++;
2396 SrcRemainingBytes -= pTxBlk->SrcBufLen;
2397 pTxBlk->pSrcBufData += pTxBlk->SrcBufLen;
2398
2399 pHeader_802_11->Frag++; /* increase Frag # */
2400
2401 } while (SrcRemainingBytes > 0);
2402
2403 /* */
2404 /* Kick out Tx */
2405 /* */
2406 if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX))
2407 HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx);
2408}
2409
2410#define RELEASE_FRAMES_OF_TXBLK(_pAd, _pTxBlk, _pQEntry, _Status) \
2411 while(_pTxBlk->TxPacketList.Head) \
2412 { \
2413 _pQEntry = RemoveHeadQueue(&_pTxBlk->TxPacketList); \
2414 RELEASE_NDIS_PACKET(_pAd, QUEUE_ENTRY_TO_PACKET(_pQEntry), _Status); \
2415 }
2416
2417/*
2418 ========================================================================
2419
2420 Routine Description:
2421 Copy frame from waiting queue into relative ring buffer and set
2422 appropriate ASIC register to kick hardware encryption before really
2423 sent out to air.
2424
2425 Arguments:
2426 pAd Pointer to our adapter
2427 void * Pointer to outgoing Ndis frame
2428 NumberOfFrag Number of fragment required
2429
2430 Return Value:
2431 None
2432
2433 IRQL = DISPATCH_LEVEL
2434
2435 Note:
2436
2437 ========================================================================
2438*/
2439int STAHardTransmit(struct rt_rtmp_adapter *pAd,
2440 struct rt_tx_blk *pTxBlk, u8 QueIdx)
2441{
2442 char *pPacket;
2443 struct rt_queue_entry *pQEntry;
2444
2445 /* --------------------------------------------- */
2446 /* STEP 0. DO SANITY CHECK AND SOME EARLY PREPARATION. */
2447 /* --------------------------------------------- */
2448 /* */
2449 ASSERT(pTxBlk->TxPacketList.Number);
2450 if (pTxBlk->TxPacketList.Head == NULL) {
2451 DBGPRINT(RT_DEBUG_ERROR,
2452 ("pTxBlk->TotalFrameNum == %ld!\n",
2453 pTxBlk->TxPacketList.Number));
2454 return NDIS_STATUS_FAILURE;
2455 }
2456
2457 pPacket = QUEUE_ENTRY_TO_PACKET(pTxBlk->TxPacketList.Head);
2458
2459 /* ------------------------------------------------------------------ */
2460 /* STEP 1. WAKE UP PHY */
2461 /* outgoing frame always wakeup PHY to prevent frame lost and */
2462 /* turn off PSM bit to improve performance */
2463 /* ------------------------------------------------------------------ */
2464 /* not to change PSM bit, just send this frame out? */
2465 if ((pAd->StaCfg.Psm == PWR_SAVE)
2466 && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) {
2467 DBGPRINT_RAW(RT_DEBUG_INFO, ("AsicForceWakeup At HardTx\n"));
2468#ifdef RTMP_MAC_PCI
2469 AsicForceWakeup(pAd, TRUE);
2470#endif /* RTMP_MAC_PCI // */
2471#ifdef RTMP_MAC_USB
2472 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_FORCE_WAKE_UP, NULL, 0);
2473#endif /* RTMP_MAC_USB // */
2474 }
2475 /* It should not change PSM bit, when APSD turn on. */
2476 if ((!
2477 (pAd->CommonCfg.bAPSDCapable
2478 && pAd->CommonCfg.APEdcaParm.bAPSDCapable)
2479 && (pAd->CommonCfg.bAPSDForcePowerSave == FALSE))
2480 || (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket))
2481 || (RTMP_GET_PACKET_WAI(pTxBlk->pPacket))) {
2482 if ((pAd->StaCfg.Psm == PWR_SAVE) &&
2483 (pAd->StaCfg.WindowsPowerMode ==
2484 Ndis802_11PowerModeFast_PSP))
2485 RTMP_SET_PSM_BIT(pAd, PWR_ACTIVE);
2486 }
2487
2488 switch (pTxBlk->TxFrameType) {
2489 case TX_AMPDU_FRAME:
2490 STA_AMPDU_Frame_Tx(pAd, pTxBlk);
2491 break;
2492 case TX_AMSDU_FRAME:
2493 STA_AMSDU_Frame_Tx(pAd, pTxBlk);
2494 break;
2495 case TX_LEGACY_FRAME:
2496 STA_Legacy_Frame_Tx(pAd, pTxBlk);
2497 break;
2498 case TX_MCAST_FRAME:
2499 STA_Legacy_Frame_Tx(pAd, pTxBlk);
2500 break;
2501 case TX_RALINK_FRAME:
2502 STA_ARalink_Frame_Tx(pAd, pTxBlk);
2503 break;
2504 case TX_FRAG_FRAME:
2505 STA_Fragment_Frame_Tx(pAd, pTxBlk);
2506 break;
2507 default:
2508 {
2509 /* It should not happened! */
2510 DBGPRINT(RT_DEBUG_ERROR,
2511 ("Send a packet was not classified! It should not happen!\n"));
2512 while (pTxBlk->TxPacketList.Number) {
2513 pQEntry =
2514 RemoveHeadQueue(&pTxBlk->TxPacketList);
2515 pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry);
2516 if (pPacket)
2517 RELEASE_NDIS_PACKET(pAd, pPacket,
2518 NDIS_STATUS_FAILURE);
2519 }
2520 }
2521 break;
2522 }
2523
2524 return (NDIS_STATUS_SUCCESS);
2525
2526}
2527
2528unsigned long HashBytesPolynomial(u8 * value, unsigned int len)
2529{
2530 unsigned char *word = value;
2531 unsigned int ret = 0;
2532 unsigned int i;
2533
2534 for (i = 0; i < len; i++) {
2535 int mod = i % 32;
2536 ret ^= (unsigned int)(word[i]) << mod;
2537 ret ^= (unsigned int)(word[i]) >> (32 - mod);
2538 }
2539 return ret;
2540}
2541
2542void Sta_Announce_or_Forward_802_3_Packet(struct rt_rtmp_adapter *pAd,
2543 void *pPacket,
2544 u8 FromWhichBSSID)
2545{
2546 if (TRUE) {
2547 announce_802_3_packet(pAd, pPacket);
2548 } else {
2549 /* release packet */
2550 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
2551 }
2552}
diff --git a/drivers/staging/rt2860/sta/sanity.c b/drivers/staging/rt2860/sta/sanity.c
deleted file mode 100644
index 0c32604f2d3..00000000000
--- a/drivers/staging/rt2860/sta/sanity.c
+++ /dev/null
@@ -1,362 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 sanity.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John Chang 2004-09-01 add WMM support
36 Justin P. Mattock 11/07/2010 Fix typos
37*/
38#include "../rt_config.h"
39
40extern u8 CISCO_OUI[];
41
42extern u8 WPA_OUI[];
43extern u8 RSN_OUI[];
44extern u8 WME_INFO_ELEM[];
45extern u8 WME_PARM_ELEM[];
46extern u8 Ccx2QosInfo[];
47extern u8 RALINK_OUI[];
48extern u8 BROADCOM_OUI[];
49
50/*
51 ==========================================================================
52 Description:
53 MLME message sanity check
54 Return:
55 TRUE if all parameters are OK, FALSE otherwise
56 ==========================================================================
57 */
58BOOLEAN MlmeStartReqSanity(struct rt_rtmp_adapter *pAd,
59 void * Msg,
60 unsigned long MsgLen,
61 char Ssid[], u8 * pSsidLen)
62{
63 struct rt_mlme_start_req *Info;
64
65 Info = (struct rt_mlme_start_req *)(Msg);
66
67 if (Info->SsidLen > MAX_LEN_OF_SSID) {
68 DBGPRINT(RT_DEBUG_TRACE,
69 ("MlmeStartReqSanity fail - wrong SSID length\n"));
70 return FALSE;
71 }
72
73 *pSsidLen = Info->SsidLen;
74 NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);
75
76 return TRUE;
77}
78
79/*
80 ==========================================================================
81 Description:
82 MLME message sanity check
83 Return:
84 TRUE if all parameters are OK, FALSE otherwise
85
86 IRQL = DISPATCH_LEVEL
87
88 ==========================================================================
89 */
90BOOLEAN PeerAssocRspSanity(struct rt_rtmp_adapter *pAd, void * pMsg, unsigned long MsgLen, u8 *pAddr2, u16 * pCapabilityInfo, u16 * pStatus, u16 * pAid, u8 SupRate[], u8 * pSupRateLen, u8 ExtRate[], u8 * pExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */
91 u8 * pHtCapabilityLen,
92 u8 * pAddHtInfoLen,
93 u8 * pNewExtChannelOffset,
94 struct rt_edca_parm *pEdcaParm, u8 * pCkipFlag)
95{
96 char IeType, *Ptr;
97 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) pMsg;
98 struct rt_eid * pEid;
99 unsigned long Length = 0;
100
101 *pNewExtChannelOffset = 0xff;
102 *pHtCapabilityLen = 0;
103 *pAddHtInfoLen = 0;
104 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
105 Ptr = (char *)pFrame->Octet;
106 Length += LENGTH_802_11;
107
108 NdisMoveMemory(pCapabilityInfo, &pFrame->Octet[0], 2);
109 Length += 2;
110 NdisMoveMemory(pStatus, &pFrame->Octet[2], 2);
111 Length += 2;
112 *pCkipFlag = 0;
113 *pExtRateLen = 0;
114 pEdcaParm->bValid = FALSE;
115
116 if (*pStatus != MLME_SUCCESS)
117 return TRUE;
118
119 NdisMoveMemory(pAid, &pFrame->Octet[4], 2);
120 Length += 2;
121
122 /* Aid already swapped byte order in RTMPFrameEndianChange() for big endian platform */
123 *pAid = (*pAid) & 0x3fff; /* AID is low 14-bit */
124
125 /* -- get supported rates from payload and advance the pointer */
126 IeType = pFrame->Octet[6];
127 *pSupRateLen = pFrame->Octet[7];
128 if ((IeType != IE_SUPP_RATES)
129 || (*pSupRateLen > MAX_LEN_OF_SUPPORTED_RATES)) {
130 DBGPRINT(RT_DEBUG_TRACE,
131 ("PeerAssocRspSanity fail - wrong SupportedRates IE\n"));
132 return FALSE;
133 } else
134 NdisMoveMemory(SupRate, &pFrame->Octet[8], *pSupRateLen);
135
136 Length = Length + 2 + *pSupRateLen;
137
138 /* many AP implement proprietary IEs in non-standard order, we'd better */
139 /* tolerate mis-ordered IEs to get best compatibility */
140 pEid = (struct rt_eid *) & pFrame->Octet[8 + (*pSupRateLen)];
141
142 /* get variable fields from payload and advance the pointer */
143 while ((Length + 2 + pEid->Len) <= MsgLen) {
144 switch (pEid->Eid) {
145 case IE_EXT_SUPP_RATES:
146 if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) {
147 NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);
148 *pExtRateLen = pEid->Len;
149 }
150 break;
151
152 case IE_HT_CAP:
153 case IE_HT_CAP2:
154 if (pEid->Len >= SIZE_HT_CAP_IE) /*Note: allow extension! */
155 {
156 NdisMoveMemory(pHtCapability, pEid->Octet,
157 SIZE_HT_CAP_IE);
158
159 *(u16 *) (&pHtCapability->HtCapInfo) =
160 cpu2le16(*(u16 *)
161 (&pHtCapability->HtCapInfo));
162 *(u16 *) (&pHtCapability->ExtHtCapInfo) =
163 cpu2le16(*(u16 *)
164 (&pHtCapability->ExtHtCapInfo));
165
166 *pHtCapabilityLen = SIZE_HT_CAP_IE;
167 } else {
168 DBGPRINT(RT_DEBUG_WARN,
169 ("PeerAssocRspSanity - wrong IE_HT_CAP. \n"));
170 }
171
172 break;
173 case IE_ADD_HT:
174 case IE_ADD_HT2:
175 if (pEid->Len >= sizeof(struct rt_add_ht_info_ie)) {
176 /* This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only */
177 /* copy first sizeof(struct rt_add_ht_info_ie) */
178 NdisMoveMemory(pAddHtInfo, pEid->Octet,
179 sizeof(struct rt_add_ht_info_ie));
180
181 *(u16 *) (&pAddHtInfo->AddHtInfo2) =
182 cpu2le16(*(u16 *)
183 (&pAddHtInfo->AddHtInfo2));
184 *(u16 *) (&pAddHtInfo->AddHtInfo3) =
185 cpu2le16(*(u16 *)
186 (&pAddHtInfo->AddHtInfo3));
187
188 *pAddHtInfoLen = SIZE_ADD_HT_INFO_IE;
189 } else {
190 DBGPRINT(RT_DEBUG_WARN,
191 ("PeerAssocRspSanity - wrong IE_ADD_HT. \n"));
192 }
193
194 break;
195 case IE_SECONDARY_CH_OFFSET:
196 if (pEid->Len == 1) {
197 *pNewExtChannelOffset = pEid->Octet[0];
198 } else {
199 DBGPRINT(RT_DEBUG_WARN,
200 ("PeerAssocRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));
201 }
202 break;
203
204 case IE_VENDOR_SPECIFIC:
205 /* handle WME PARAMTER ELEMENT */
206 if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6)
207 && (pEid->Len == 24)) {
208 u8 *ptr;
209 int i;
210
211 /* parsing EDCA parameters */
212 pEdcaParm->bValid = TRUE;
213 pEdcaParm->bQAck = FALSE; /* pEid->Octet[0] & 0x10; */
214 pEdcaParm->bQueueRequest = FALSE; /* pEid->Octet[0] & 0x20; */
215 pEdcaParm->bTxopRequest = FALSE; /* pEid->Octet[0] & 0x40; */
216 /*pEdcaParm->bMoreDataAck = FALSE; // pEid->Octet[0] & 0x80; */
217 pEdcaParm->EdcaUpdateCount =
218 pEid->Octet[6] & 0x0f;
219 pEdcaParm->bAPSDCapable =
220 (pEid->Octet[6] & 0x80) ? 1 : 0;
221 ptr = (u8 *)& pEid->Octet[8];
222 for (i = 0; i < 4; i++) {
223 u8 aci = (*ptr & 0x60) >> 5; /* b5~6 is AC INDEX */
224 pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); /* b5 is ACM */
225 pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; /* b0~3 is AIFSN */
226 pEdcaParm->Cwmin[aci] = *(ptr + 1) & 0x0f; /* b0~4 is Cwmin */
227 pEdcaParm->Cwmax[aci] = *(ptr + 1) >> 4; /* b5~8 is Cwmax */
228 pEdcaParm->Txop[aci] = *(ptr + 2) + 256 * (*(ptr + 3)); /* in unit of 32-us */
229 ptr += 4; /* point to next AC */
230 }
231 }
232 break;
233 default:
234 DBGPRINT(RT_DEBUG_TRACE,
235 ("PeerAssocRspSanity - ignore unrecognized EID = %d\n",
236 pEid->Eid));
237 break;
238 }
239
240 Length = Length + 2 + pEid->Len;
241 pEid = (struct rt_eid *) ((u8 *) pEid + 2 + pEid->Len);
242 }
243
244 return TRUE;
245}
246
247/*
248 ==========================================================================
249 Description:
250 MLME message sanity check
251 Return:
252 TRUE if all parameters are OK, FALSE otherwise
253
254 IRQL = DISPATCH_LEVEL
255
256 ==========================================================================
257 */
258BOOLEAN PeerProbeReqSanity(struct rt_rtmp_adapter *pAd,
259 void * Msg,
260 unsigned long MsgLen,
261 u8 *pAddr2,
262 char Ssid[], u8 * pSsidLen)
263{
264 u8 Idx;
265 u8 RateLen;
266 char IeType;
267 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg;
268
269 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
270
271 if ((pFrame->Octet[0] != IE_SSID)
272 || (pFrame->Octet[1] > MAX_LEN_OF_SSID)) {
273 DBGPRINT(RT_DEBUG_TRACE,
274 ("PeerProbeReqSanity fail - wrong SSID IE(Type=%d,Len=%d)\n",
275 pFrame->Octet[0], pFrame->Octet[1]));
276 return FALSE;
277 }
278
279 *pSsidLen = pFrame->Octet[1];
280 NdisMoveMemory(Ssid, &pFrame->Octet[2], *pSsidLen);
281
282 Idx = *pSsidLen + 2;
283
284 /* -- get supported rates from payload and advance the pointer */
285 IeType = pFrame->Octet[Idx];
286 RateLen = pFrame->Octet[Idx + 1];
287 if (IeType != IE_SUPP_RATES) {
288 DBGPRINT(RT_DEBUG_TRACE,
289 ("PeerProbeReqSanity fail - wrong SupportRates IE(Type=%d,Len=%d)\n",
290 pFrame->Octet[Idx], pFrame->Octet[Idx + 1]));
291 return FALSE;
292 } else {
293 if ((pAd->CommonCfg.PhyMode == PHY_11G) && (RateLen < 8))
294 return (FALSE);
295 }
296
297 return TRUE;
298}
299
300/*
301 ==========================================================================
302 Description:
303
304 IRQL = DISPATCH_LEVEL
305
306 ==========================================================================
307 */
308BOOLEAN GetTimBit(char * Ptr,
309 u16 Aid,
310 u8 * TimLen,
311 u8 * BcastFlag,
312 u8 * DtimCount,
313 u8 * DtimPeriod, u8 * MessageToMe)
314{
315 u8 BitCntl, N1, N2, MyByte, MyBit;
316 char *IdxPtr;
317
318 IdxPtr = Ptr;
319
320 IdxPtr++;
321 *TimLen = *IdxPtr;
322
323 /* get DTIM Count from TIM element */
324 IdxPtr++;
325 *DtimCount = *IdxPtr;
326
327 /* get DTIM Period from TIM element */
328 IdxPtr++;
329 *DtimPeriod = *IdxPtr;
330
331 /* get Bitmap Control from TIM element */
332 IdxPtr++;
333 BitCntl = *IdxPtr;
334
335 if ((*DtimCount == 0) && (BitCntl & 0x01))
336 *BcastFlag = TRUE;
337 else
338 *BcastFlag = FALSE;
339
340 /* Parse Partial Virtual Bitmap from TIM element */
341 N1 = BitCntl & 0xfe; /* N1 is the first bitmap byte# */
342 N2 = *TimLen - 4 + N1; /* N2 is the last bitmap byte# */
343
344 if ((Aid < (N1 << 3)) || (Aid >= ((N2 + 1) << 3)))
345 *MessageToMe = FALSE;
346 else {
347 MyByte = (Aid >> 3) - N1; /* my byte position in the bitmap byte-stream */
348 MyBit = Aid % 16 - ((MyByte & 0x01) ? 8 : 0);
349
350 IdxPtr += (MyByte + 1);
351
352 /*if (*IdxPtr) */
353 /* DBGPRINT(RT_DEBUG_WARN, ("TIM bitmap = 0x%02x\n", *IdxPtr)); */
354
355 if (*IdxPtr & (0x01 << MyBit))
356 *MessageToMe = TRUE;
357 else
358 *MessageToMe = FALSE;
359 }
360
361 return TRUE;
362}
diff --git a/drivers/staging/rt2860/sta/sync.c b/drivers/staging/rt2860/sta/sync.c
deleted file mode 100644
index 7054ba1323d..00000000000
--- a/drivers/staging/rt2860/sta/sync.c
+++ /dev/null
@@ -1,1968 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 sync.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John Chang 2004-09-01 modified for rt2561/2661
36 Jan Lee 2006-08-01 modified for rt2860 for 802.11n
37 Justin P. Mattock 11/07/2010 Fix typos
38*/
39#include "../rt_config.h"
40
41#define ADHOC_ENTRY_BEACON_LOST_TIME (2*OS_HZ) /* 2 sec */
42
43/*
44 ==========================================================================
45 Description:
46 The sync state machine,
47 Parameters:
48 Sm - pointer to the state machine
49 Note:
50 the state machine looks like the following
51
52 ==========================================================================
53 */
54void SyncStateMachineInit(struct rt_rtmp_adapter *pAd,
55 struct rt_state_machine *Sm, OUT STATE_MACHINE_FUNC Trans[])
56{
57 StateMachineInit(Sm, Trans, MAX_SYNC_STATE, MAX_SYNC_MSG,
58 (STATE_MACHINE_FUNC) Drop, SYNC_IDLE,
59 SYNC_MACHINE_BASE);
60
61 /* column 1 */
62 StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_SCAN_REQ,
63 (STATE_MACHINE_FUNC) MlmeScanReqAction);
64 StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_JOIN_REQ,
65 (STATE_MACHINE_FUNC) MlmeJoinReqAction);
66 StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_START_REQ,
67 (STATE_MACHINE_FUNC) MlmeStartReqAction);
68 StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_BEACON,
69 (STATE_MACHINE_FUNC) PeerBeacon);
70 StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_PROBE_REQ,
71 (STATE_MACHINE_FUNC) PeerProbeReqAction);
72
73 /*column 2 */
74 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_SCAN_REQ,
75 (STATE_MACHINE_FUNC) InvalidStateWhenScan);
76 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_JOIN_REQ,
77 (STATE_MACHINE_FUNC) InvalidStateWhenJoin);
78 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_START_REQ,
79 (STATE_MACHINE_FUNC) InvalidStateWhenStart);
80 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_PEER_BEACON,
81 (STATE_MACHINE_FUNC) PeerBeaconAtJoinAction);
82 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_BEACON_TIMEOUT,
83 (STATE_MACHINE_FUNC) BeaconTimeoutAtJoinAction);
84
85 /* column 3 */
86 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_SCAN_REQ,
87 (STATE_MACHINE_FUNC) InvalidStateWhenScan);
88 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_JOIN_REQ,
89 (STATE_MACHINE_FUNC) InvalidStateWhenJoin);
90 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_START_REQ,
91 (STATE_MACHINE_FUNC) InvalidStateWhenStart);
92 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_BEACON,
93 (STATE_MACHINE_FUNC) PeerBeaconAtScanAction);
94 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_PROBE_RSP,
95 (STATE_MACHINE_FUNC) PeerBeaconAtScanAction);
96 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_SCAN_TIMEOUT,
97 (STATE_MACHINE_FUNC) ScanTimeoutAction);
98
99 /* timer init */
100 RTMPInitTimer(pAd, &pAd->MlmeAux.BeaconTimer,
101 GET_TIMER_FUNCTION(BeaconTimeout), pAd, FALSE);
102 RTMPInitTimer(pAd, &pAd->MlmeAux.ScanTimer,
103 GET_TIMER_FUNCTION(ScanTimeout), pAd, FALSE);
104}
105
106/*
107 ==========================================================================
108 Description:
109 Beacon timeout handler, executed in timer thread
110
111 IRQL = DISPATCH_LEVEL
112
113 ==========================================================================
114 */
115void BeaconTimeout(void *SystemSpecific1,
116 void *FunctionContext,
117 void *SystemSpecific2, void *SystemSpecific3)
118{
119 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
120
121 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BeaconTimeout\n"));
122
123 /* Do nothing if the driver is starting halt state. */
124 /* This might happen when timer already been fired before cancel timer with mlmehalt */
125 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
126 return;
127
128 if ((pAd->CommonCfg.BBPCurrentBW == BW_40)
129 ) {
130 u8 BBPValue = 0;
131 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
132 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
133 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
134 BBPValue &= (~0x18);
135 BBPValue |= 0x10;
136 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
137 DBGPRINT(RT_DEBUG_TRACE,
138 ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",
139 pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr));
140 }
141
142 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_BEACON_TIMEOUT, 0, NULL);
143 RTMP_MLME_HANDLER(pAd);
144}
145
146/*
147 ==========================================================================
148 Description:
149 Scan timeout handler, executed in timer thread
150
151 IRQL = DISPATCH_LEVEL
152
153 ==========================================================================
154 */
155void ScanTimeout(void *SystemSpecific1,
156 void *FunctionContext,
157 void *SystemSpecific2, void *SystemSpecific3)
158{
159 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
160
161 /* Do nothing if the driver is starting halt state. */
162 /* This might happen when timer already been fired before cancel timer with mlmehalt */
163 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
164 return;
165
166 if (MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_SCAN_TIMEOUT, 0, NULL)) {
167 RTMP_MLME_HANDLER(pAd);
168 } else {
169 /* To prevent SyncMachine.CurrState is SCAN_LISTEN forever. */
170 pAd->MlmeAux.Channel = 0;
171 ScanNextChannel(pAd);
172 if (pAd->CommonCfg.bWirelessEvent) {
173 RTMPSendWirelessEvent(pAd,
174 IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG,
175 pAd->MacTab.Content[BSSID_WCID].
176 Addr, BSS0, 0);
177 }
178 }
179}
180
181/*
182 ==========================================================================
183 Description:
184 MLME SCAN req state machine procedure
185 ==========================================================================
186 */
187void MlmeScanReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
188{
189 u8 Ssid[MAX_LEN_OF_SSID], SsidLen, ScanType, BssType, BBPValue = 0;
190 BOOLEAN TimerCancelled;
191 unsigned long Now;
192 u16 Status;
193 struct rt_header_802_11 * pHdr80211;
194 u8 *pOutBuffer = NULL;
195 int NStatus;
196
197 /* Check the total scan tries for one single OID command */
198 /* If this is the CCX 2.0 Case, skip that! */
199 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)) {
200 DBGPRINT(RT_DEBUG_TRACE,
201 ("SYNC - MlmeScanReqAction before Startup\n"));
202 return;
203 }
204 /* Increase the scan retry counters. */
205 pAd->StaCfg.ScanCnt++;
206
207#ifdef RTMP_MAC_PCI
208 if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) &&
209 (IDLE_ON(pAd)) &&
210 (pAd->StaCfg.bRadio == TRUE) &&
211 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))) {
212 if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE) {
213 AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00,
214 0x02);
215 AsicCheckCommanOk(pAd, PowerWakeCID);
216 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF);
217 DBGPRINT(RT_DEBUG_TRACE,
218 ("PSM - Issue Wake up command \n"));
219 } else {
220 RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE);
221 }
222 }
223#endif /* RTMP_MAC_PCI // */
224
225 /* first check the parameter sanity */
226 if (MlmeScanReqSanity(pAd,
227 Elem->Msg,
228 Elem->MsgLen,
229 &BssType, (char *)Ssid, &SsidLen, &ScanType)) {
230
231 /* Check for channel load and noise hist request */
232 /* Suspend MSDU only at scan request, not the last two mentioned */
233 /* Suspend MSDU transmission here */
234 RTMPSuspendMsduTransmission(pAd);
235
236 /* */
237 /* To prevent data loss. */
238 /* Send a NULL data with turned PSM bit on to current associated AP before SCAN progress. */
239 /* And should send a NULL data with turned PSM bit off to AP, when scan progress done */
240 /* */
241 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
242 && (INFRA_ON(pAd))) {
243 NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer);
244 if (NStatus == NDIS_STATUS_SUCCESS) {
245 pHdr80211 = (struct rt_header_802_11 *) pOutBuffer;
246 MgtMacHeaderInit(pAd, pHdr80211,
247 SUBTYPE_NULL_FUNC, 1,
248 pAd->CommonCfg.Bssid,
249 pAd->CommonCfg.Bssid);
250 pHdr80211->Duration = 0;
251 pHdr80211->FC.Type = BTYPE_DATA;
252 pHdr80211->FC.PwrMgmt = PWR_SAVE;
253
254 /* Send using priority queue */
255 MiniportMMRequest(pAd, 0, pOutBuffer,
256 sizeof(struct rt_header_802_11));
257 DBGPRINT(RT_DEBUG_TRACE,
258 ("MlmeScanReqAction -- Send PSM Data frame for off channel RM\n"));
259 MlmeFreeMemory(pAd, pOutBuffer);
260 RTMPusecDelay(5000);
261 }
262 }
263
264 NdisGetSystemUpTime(&Now);
265 pAd->StaCfg.LastScanTime = Now;
266 /* reset all the timers */
267 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
268 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
269
270 /* record desired BSS parameters */
271 pAd->MlmeAux.BssType = BssType;
272 pAd->MlmeAux.ScanType = ScanType;
273 pAd->MlmeAux.SsidLen = SsidLen;
274 NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
275 NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
276
277 /* start from the first channel */
278 pAd->MlmeAux.Channel = FirstChannel(pAd);
279
280 /* Let BBP register at 20MHz to do scan */
281 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
282 BBPValue &= (~0x18);
283 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
284 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
285 ScanNextChannel(pAd);
286 } else {
287 DBGPRINT_ERR("SYNC - MlmeScanReqAction() sanity check fail\n");
288 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
289 Status = MLME_INVALID_FORMAT;
290 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2,
291 &Status);
292 }
293}
294
295/*
296 ==========================================================================
297 Description:
298 MLME JOIN req state machine procedure
299 ==========================================================================
300 */
301void MlmeJoinReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
302{
303 u8 BBPValue = 0;
304 struct rt_bss_entry *pBss;
305 BOOLEAN TimerCancelled;
306 struct rt_header_802_11 Hdr80211;
307 int NStatus;
308 unsigned long FrameLen = 0;
309 u8 *pOutBuffer = NULL;
310 u8 *pSupRate = NULL;
311 u8 SupRateLen;
312 u8 *pExtRate = NULL;
313 u8 ExtRateLen;
314 u8 ASupRate[] = { 0x8C, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6C };
315 u8 ASupRateLen = sizeof(ASupRate) / sizeof(u8);
316 struct rt_mlme_join_req *pInfo = (struct rt_mlme_join_req *)(Elem->Msg);
317
318 DBGPRINT(RT_DEBUG_TRACE,
319 ("SYNC - MlmeJoinReqAction(BSS #%ld)\n", pInfo->BssIdx));
320
321#ifdef RTMP_MAC_PCI
322 if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) &&
323 (IDLE_ON(pAd)) &&
324 (pAd->StaCfg.bRadio == TRUE) &&
325 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))) {
326 RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE);
327 }
328#endif /* RTMP_MAC_PCI // */
329
330 /* reset all the timers */
331 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
332 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
333
334 pBss = &pAd->MlmeAux.SsidBssTab.BssEntry[pInfo->BssIdx];
335
336 /* record the desired SSID & BSSID we're waiting for */
337 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pBss->Bssid);
338
339 /* If AP's SSID is not hidden, it is OK for updating ssid to MlmeAux again. */
340 if (pBss->Hidden == 0) {
341 RTMPZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
342 NdisMoveMemory(pAd->MlmeAux.Ssid, pBss->Ssid, pBss->SsidLen);
343 pAd->MlmeAux.SsidLen = pBss->SsidLen;
344 }
345
346 pAd->MlmeAux.BssType = pBss->BssType;
347 pAd->MlmeAux.Channel = pBss->Channel;
348 pAd->MlmeAux.CentralChannel = pBss->CentralChannel;
349
350 /* Let BBP register at 20MHz to do scan */
351 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
352 BBPValue &= (~0x18);
353 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
354
355 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
356
357 /* switch channel and waiting for beacon timer */
358 AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);
359 AsicLockChannel(pAd, pAd->MlmeAux.Channel);
360 RTMPSetTimer(&pAd->MlmeAux.BeaconTimer, JOIN_TIMEOUT);
361
362 do {
363 if (((pAd->CommonCfg.bIEEE80211H == 1) &&
364 (pAd->MlmeAux.Channel > 14) &&
365 RadarChannelCheck(pAd, pAd->MlmeAux.Channel))
366 ) {
367 /* */
368 /* We can't send any Probe request frame to meet 802.11h. */
369 /* */
370 if (pBss->Hidden == 0)
371 break;
372 }
373 /* */
374 /* send probe request */
375 /* */
376 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
377 if (NStatus == NDIS_STATUS_SUCCESS) {
378 if (pAd->MlmeAux.Channel <= 14) {
379 pSupRate = pAd->CommonCfg.SupRate;
380 SupRateLen = pAd->CommonCfg.SupRateLen;
381 pExtRate = pAd->CommonCfg.ExtRate;
382 ExtRateLen = pAd->CommonCfg.ExtRateLen;
383 } else {
384 /* */
385 /* Overwrite Support Rate, CCK rate are not allowed */
386 /* */
387 pSupRate = ASupRate;
388 SupRateLen = ASupRateLen;
389 ExtRateLen = 0;
390 }
391
392 if (pAd->MlmeAux.BssType == BSS_INFRA)
393 MgtMacHeaderInit(pAd, &Hdr80211,
394 SUBTYPE_PROBE_REQ, 0,
395 pAd->MlmeAux.Bssid,
396 pAd->MlmeAux.Bssid);
397 else
398 MgtMacHeaderInit(pAd, &Hdr80211,
399 SUBTYPE_PROBE_REQ, 0,
400 BROADCAST_ADDR,
401 BROADCAST_ADDR);
402
403 MakeOutgoingFrame(pOutBuffer, &FrameLen,
404 sizeof(struct rt_header_802_11), &Hdr80211,
405 1, &SsidIe,
406 1, &pAd->MlmeAux.SsidLen,
407 pAd->MlmeAux.SsidLen,
408 pAd->MlmeAux.Ssid, 1, &SupRateIe, 1,
409 &SupRateLen, SupRateLen, pSupRate,
410 END_OF_ARGS);
411
412 if (ExtRateLen) {
413 unsigned long Tmp;
414 MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
415 1, &ExtRateIe,
416 1, &ExtRateLen,
417 ExtRateLen, pExtRate,
418 END_OF_ARGS);
419 FrameLen += Tmp;
420 }
421
422 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
423 MlmeFreeMemory(pAd, pOutBuffer);
424 }
425 } while (FALSE);
426
427 DBGPRINT(RT_DEBUG_TRACE,
428 ("SYNC - Switch to ch %d, Wait BEACON from %pM\n",
429 pBss->Channel, pBss->Bssid));
430
431 pAd->Mlme.SyncMachine.CurrState = JOIN_WAIT_BEACON;
432}
433
434/*
435 ==========================================================================
436 Description:
437 MLME START Request state machine procedure, starting an IBSS
438 ==========================================================================
439 */
440void MlmeStartReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
441{
442 u8 Ssid[MAX_LEN_OF_SSID], SsidLen;
443 BOOLEAN TimerCancelled;
444
445 /* New for WPA security suites */
446 u8 VarIE[MAX_VIE_LEN]; /* Total VIE length = MAX_VIE_LEN - -5 */
447 struct rt_ndis_802_11_variable_ies *pVIE = NULL;
448 LARGE_INTEGER TimeStamp;
449 BOOLEAN Privacy;
450 u16 Status;
451
452 /* Init Variable IE structure */
453 pVIE = (struct rt_ndis_802_11_variable_ies *)VarIE;
454 pVIE->Length = 0;
455 TimeStamp.u.LowPart = 0;
456 TimeStamp.u.HighPart = 0;
457
458 if (MlmeStartReqSanity
459 (pAd, Elem->Msg, Elem->MsgLen, (char *)Ssid, &SsidLen)) {
460 /* reset all the timers */
461 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
462 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
463
464 /* */
465 /* Start a new IBSS. All IBSS parameters are decided now.... */
466 /* */
467 DBGPRINT(RT_DEBUG_TRACE,
468 ("MlmeStartReqAction - Start a new IBSS. All IBSS parameters are decided now.... \n"));
469 pAd->MlmeAux.BssType = BSS_ADHOC;
470 NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
471 pAd->MlmeAux.SsidLen = SsidLen;
472
473 /* generate a radom number as BSSID */
474 MacAddrRandomBssid(pAd, pAd->MlmeAux.Bssid);
475 DBGPRINT(RT_DEBUG_TRACE,
476 ("MlmeStartReqAction - generate a radom number as BSSID \n"));
477
478 Privacy =
479 (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
480 || (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
481 || (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
482 pAd->MlmeAux.CapabilityInfo =
483 CAP_GENERATE(0, 1, Privacy,
484 (pAd->CommonCfg.TxPreamble ==
485 Rt802_11PreambleShort), 1, 0);
486 pAd->MlmeAux.BeaconPeriod = pAd->CommonCfg.BeaconPeriod;
487 pAd->MlmeAux.AtimWin = pAd->StaCfg.AtimWin;
488 pAd->MlmeAux.Channel = pAd->CommonCfg.Channel;
489
490 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
491 pAd->MlmeAux.CentralChannel = pAd->CommonCfg.CentralChannel;
492
493 pAd->MlmeAux.SupRateLen = pAd->CommonCfg.SupRateLen;
494 NdisMoveMemory(pAd->MlmeAux.SupRate, pAd->CommonCfg.SupRate,
495 MAX_LEN_OF_SUPPORTED_RATES);
496 RTMPCheckRates(pAd, pAd->MlmeAux.SupRate,
497 &pAd->MlmeAux.SupRateLen);
498 pAd->MlmeAux.ExtRateLen = pAd->CommonCfg.ExtRateLen;
499 NdisMoveMemory(pAd->MlmeAux.ExtRate, pAd->CommonCfg.ExtRate,
500 MAX_LEN_OF_SUPPORTED_RATES);
501 RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate,
502 &pAd->MlmeAux.ExtRateLen);
503
504 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) {
505 RTMPUpdateHTIE(&pAd->CommonCfg.DesiredHtPhy,
506 &pAd->StaCfg.DesiredHtPhyInfo.MCSSet[0],
507 &pAd->MlmeAux.HtCapability,
508 &pAd->MlmeAux.AddHtInfo);
509 pAd->MlmeAux.HtCapabilityLen = sizeof(struct rt_ht_capability_ie);
510 /* Not turn pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE here. */
511 DBGPRINT(RT_DEBUG_TRACE,
512 ("SYNC -pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE\n"));
513 } else {
514 pAd->MlmeAux.HtCapabilityLen = 0;
515 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
516 NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo.
517 MCSSet[0], 16);
518 }
519 /* temporarily not support QOS in IBSS */
520 NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(struct rt_edca_parm));
521 NdisZeroMemory(&pAd->MlmeAux.APQbssLoad,
522 sizeof(struct rt_qbss_load_parm));
523 NdisZeroMemory(&pAd->MlmeAux.APQosCapability,
524 sizeof(struct rt_qos_capability_parm));
525
526 AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);
527 AsicLockChannel(pAd, pAd->MlmeAux.Channel);
528
529 DBGPRINT(RT_DEBUG_TRACE,
530 ("SYNC - MlmeStartReqAction(ch= %d,sup rates= %d, ext rates=%d)\n",
531 pAd->MlmeAux.Channel, pAd->MlmeAux.SupRateLen,
532 pAd->MlmeAux.ExtRateLen));
533
534 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
535 Status = MLME_SUCCESS;
536 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2,
537 &Status);
538 } else {
539 DBGPRINT_ERR("SYNC - MlmeStartReqAction() sanity check fail.\n");
540 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
541 Status = MLME_INVALID_FORMAT;
542 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2,
543 &Status);
544 }
545}
546
547/*
548 ==========================================================================
549 Description:
550 peer sends beacon back when scanning
551 ==========================================================================
552 */
553void PeerBeaconAtScanAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
554{
555 u8 Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
556 u8 Ssid[MAX_LEN_OF_SSID], BssType, Channel, NewChannel,
557 SsidLen, DtimCount, DtimPeriod, BcastFlag, MessageToMe;
558 struct rt_cf_parm CfParm;
559 u16 BeaconPeriod, AtimWin, CapabilityInfo;
560 struct rt_frame_802_11 * pFrame;
561 LARGE_INTEGER TimeStamp;
562 u8 Erp;
563 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES],
564 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
565 u8 SupRateLen, ExtRateLen;
566 u16 LenVIE;
567 u8 CkipFlag;
568 u8 AironetCellPowerLimit;
569 struct rt_edca_parm EdcaParm;
570 struct rt_qbss_load_parm QbssLoad;
571 struct rt_qos_capability_parm QosCapability;
572 unsigned long RalinkIe;
573 u8 VarIE[MAX_VIE_LEN]; /* Total VIE length = MAX_VIE_LEN - -5 */
574 struct rt_ndis_802_11_variable_ies *pVIE = NULL;
575 struct rt_ht_capability_ie HtCapability;
576 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
577 u8 HtCapabilityLen = 0, PreNHtCapabilityLen = 0;
578 u8 AddHtInfoLen;
579 u8 NewExtChannelOffset = 0xff;
580
581 /* NdisFillMemory(Ssid, MAX_LEN_OF_SSID, 0x00); */
582 pFrame = (struct rt_frame_802_11 *) Elem->Msg;
583 /* Init Variable IE structure */
584 pVIE = (struct rt_ndis_802_11_variable_ies *)VarIE;
585 pVIE->Length = 0;
586
587 RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
588 RTMPZeroMemory(&AddHtInfo, sizeof(struct rt_add_ht_info_ie));
589
590 if (PeerBeaconAndProbeRspSanity(pAd,
591 Elem->Msg,
592 Elem->MsgLen,
593 Elem->Channel,
594 Addr2,
595 Bssid,
596 (char *)Ssid,
597 &SsidLen,
598 &BssType,
599 &BeaconPeriod,
600 &Channel,
601 &NewChannel,
602 &TimeStamp,
603 &CfParm,
604 &AtimWin,
605 &CapabilityInfo,
606 &Erp,
607 &DtimCount,
608 &DtimPeriod,
609 &BcastFlag,
610 &MessageToMe,
611 SupRate,
612 &SupRateLen,
613 ExtRate,
614 &ExtRateLen,
615 &CkipFlag,
616 &AironetCellPowerLimit,
617 &EdcaParm,
618 &QbssLoad,
619 &QosCapability,
620 &RalinkIe,
621 &HtCapabilityLen,
622 &PreNHtCapabilityLen,
623 &HtCapability,
624 &AddHtInfoLen,
625 &AddHtInfo,
626 &NewExtChannelOffset, &LenVIE, pVIE)) {
627 unsigned long Idx;
628 char Rssi = 0;
629
630 Idx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
631 if (Idx != BSS_NOT_FOUND)
632 Rssi = pAd->ScanTab.BssEntry[Idx].Rssi;
633
634 Rssi =
635 RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0),
636 ConvertToRssi(pAd, Elem->Rssi1, RSSI_1),
637 ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
638
639 if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
640 HtCapabilityLen = SIZE_HT_CAP_IE;
641
642 Idx =
643 BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, (char *)Ssid,
644 SsidLen, BssType, BeaconPeriod, &CfParm,
645 AtimWin, CapabilityInfo, SupRate,
646 SupRateLen, ExtRate, ExtRateLen,
647 &HtCapability, &AddHtInfo, HtCapabilityLen,
648 AddHtInfoLen, NewExtChannelOffset, Channel,
649 Rssi, TimeStamp, CkipFlag, &EdcaParm,
650 &QosCapability, &QbssLoad, LenVIE, pVIE);
651
652 if (Idx != BSS_NOT_FOUND) {
653 NdisMoveMemory(pAd->ScanTab.BssEntry[Idx].PTSF,
654 &Elem->Msg[24], 4);
655 NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[0],
656 &Elem->TimeStamp.u.LowPart, 4);
657 NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[4],
658 &Elem->TimeStamp.u.LowPart, 4);
659 }
660
661 }
662 /* sanity check fail, ignored */
663}
664
665/*
666 ==========================================================================
667 Description:
668 When waiting joining the (I)BSS, beacon received from external
669 ==========================================================================
670 */
671void PeerBeaconAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
672{
673 u8 Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
674 u8 Ssid[MAX_LEN_OF_SSID], SsidLen, BssType, Channel, MessageToMe,
675 DtimCount, DtimPeriod, BcastFlag, NewChannel;
676 LARGE_INTEGER TimeStamp;
677 u16 BeaconPeriod, AtimWin, CapabilityInfo;
678 struct rt_cf_parm Cf;
679 BOOLEAN TimerCancelled;
680 u8 Erp;
681 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES],
682 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
683 u8 SupRateLen, ExtRateLen;
684 u8 CkipFlag;
685 u16 LenVIE;
686 u8 AironetCellPowerLimit;
687 struct rt_edca_parm EdcaParm;
688 struct rt_qbss_load_parm QbssLoad;
689 struct rt_qos_capability_parm QosCapability;
690 u16 Status;
691 u8 VarIE[MAX_VIE_LEN]; /* Total VIE length = MAX_VIE_LEN - -5 */
692 struct rt_ndis_802_11_variable_ies *pVIE = NULL;
693 unsigned long RalinkIe;
694 unsigned long Idx;
695 struct rt_ht_capability_ie HtCapability;
696 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
697 u8 HtCapabilityLen = 0, PreNHtCapabilityLen = 0;
698 u8 AddHtInfoLen;
699 u8 NewExtChannelOffset = 0xff;
700 u8 CentralChannel;
701 BOOLEAN bAllowNrate = FALSE;
702
703 /* Init Variable IE structure */
704 pVIE = (struct rt_ndis_802_11_variable_ies *)VarIE;
705 pVIE->Length = 0;
706 RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
707 RTMPZeroMemory(&AddHtInfo, sizeof(struct rt_add_ht_info_ie));
708
709 if (PeerBeaconAndProbeRspSanity(pAd,
710 Elem->Msg,
711 Elem->MsgLen,
712 Elem->Channel,
713 Addr2,
714 Bssid,
715 (char *)Ssid,
716 &SsidLen,
717 &BssType,
718 &BeaconPeriod,
719 &Channel,
720 &NewChannel,
721 &TimeStamp,
722 &Cf,
723 &AtimWin,
724 &CapabilityInfo,
725 &Erp,
726 &DtimCount,
727 &DtimPeriod,
728 &BcastFlag,
729 &MessageToMe,
730 SupRate,
731 &SupRateLen,
732 ExtRate,
733 &ExtRateLen,
734 &CkipFlag,
735 &AironetCellPowerLimit,
736 &EdcaParm,
737 &QbssLoad,
738 &QosCapability,
739 &RalinkIe,
740 &HtCapabilityLen,
741 &PreNHtCapabilityLen,
742 &HtCapability,
743 &AddHtInfoLen,
744 &AddHtInfo,
745 &NewExtChannelOffset, &LenVIE, pVIE)) {
746 /* Disqualify 11b only adhoc when we are in 11g only adhoc mode */
747 if ((BssType == BSS_ADHOC)
748 && (pAd->CommonCfg.PhyMode == PHY_11G)
749 && ((SupRateLen + ExtRateLen) < 12))
750 return;
751
752 /* BEACON from desired BSS/IBSS found. We should be able to decide most */
753 /* BSS parameters here. */
754 /* Q. But what happen if this JOIN doesn't conclude a successful ASSOCIATION? */
755 /* Do we need to recover back all parameters belonging to previous BSS? */
756 /* A. Should be not. There's no back-door recover to previous AP. It still needs */
757 /* a new JOIN-AUTH-ASSOC sequence. */
758 if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Bssid)) {
759 DBGPRINT(RT_DEBUG_TRACE,
760 ("SYNC - receive desired BEACON at JoinWaitBeacon... Channel = %d\n",
761 Channel));
762 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer,
763 &TimerCancelled);
764
765 /* Update RSSI to prevent No signal display when cards first initialized */
766 pAd->StaCfg.RssiSample.LastRssi0 =
767 ConvertToRssi(pAd, Elem->Rssi0, RSSI_0);
768 pAd->StaCfg.RssiSample.LastRssi1 =
769 ConvertToRssi(pAd, Elem->Rssi1, RSSI_1);
770 pAd->StaCfg.RssiSample.LastRssi2 =
771 ConvertToRssi(pAd, Elem->Rssi2, RSSI_2);
772 pAd->StaCfg.RssiSample.AvgRssi0 =
773 pAd->StaCfg.RssiSample.LastRssi0;
774 pAd->StaCfg.RssiSample.AvgRssi0X8 =
775 pAd->StaCfg.RssiSample.AvgRssi0 << 3;
776 pAd->StaCfg.RssiSample.AvgRssi1 =
777 pAd->StaCfg.RssiSample.LastRssi1;
778 pAd->StaCfg.RssiSample.AvgRssi1X8 =
779 pAd->StaCfg.RssiSample.AvgRssi1 << 3;
780 pAd->StaCfg.RssiSample.AvgRssi2 =
781 pAd->StaCfg.RssiSample.LastRssi2;
782 pAd->StaCfg.RssiSample.AvgRssi2X8 =
783 pAd->StaCfg.RssiSample.AvgRssi2 << 3;
784
785 /* */
786 /* We need to check if SSID only set to any, then we can record the current SSID. */
787 /* Otherwise will cause hidden SSID association failed. */
788 /* */
789 if (pAd->MlmeAux.SsidLen == 0) {
790 NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid,
791 SsidLen);
792 pAd->MlmeAux.SsidLen = SsidLen;
793 } else {
794 Idx =
795 BssSsidTableSearch(&pAd->ScanTab, Bssid,
796 pAd->MlmeAux.Ssid,
797 pAd->MlmeAux.SsidLen,
798 Channel);
799
800 if (Idx == BSS_NOT_FOUND) {
801 char Rssi = 0;
802 Rssi =
803 RTMPMaxRssi(pAd,
804 ConvertToRssi(pAd,
805 Elem->
806 Rssi0,
807 RSSI_0),
808 ConvertToRssi(pAd,
809 Elem->
810 Rssi1,
811 RSSI_1),
812 ConvertToRssi(pAd,
813 Elem->
814 Rssi2,
815 RSSI_2));
816 Idx =
817 BssTableSetEntry(pAd, &pAd->ScanTab,
818 Bssid,
819 (char *) Ssid,
820 SsidLen, BssType,
821 BeaconPeriod, &Cf,
822 AtimWin,
823 CapabilityInfo,
824 SupRate,
825 SupRateLen,
826 ExtRate,
827 ExtRateLen,
828 &HtCapability,
829 &AddHtInfo,
830 HtCapabilityLen,
831 AddHtInfoLen,
832 NewExtChannelOffset,
833 Channel, Rssi,
834 TimeStamp,
835 CkipFlag,
836 &EdcaParm,
837 &QosCapability,
838 &QbssLoad, LenVIE,
839 pVIE);
840 if (Idx != BSS_NOT_FOUND) {
841 NdisMoveMemory(pAd->ScanTab.
842 BssEntry[Idx].
843 PTSF,
844 &Elem->Msg[24],
845 4);
846 NdisMoveMemory(&pAd->ScanTab.
847 BssEntry[Idx].
848 TTSF[0],
849 &Elem->TimeStamp.
850 u.LowPart, 4);
851 NdisMoveMemory(&pAd->ScanTab.
852 BssEntry[Idx].
853 TTSF[4],
854 &Elem->TimeStamp.
855 u.LowPart, 4);
856 CapabilityInfo =
857 pAd->ScanTab.BssEntry[Idx].
858 CapabilityInfo;
859 }
860 } else {
861 /* */
862 /* Multiple SSID case, used correct CapabilityInfo */
863 /* */
864 CapabilityInfo =
865 pAd->ScanTab.BssEntry[Idx].
866 CapabilityInfo;
867 }
868 }
869 NdisMoveMemory(pAd->MlmeAux.Bssid, Bssid, MAC_ADDR_LEN);
870 pAd->MlmeAux.CapabilityInfo =
871 CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
872 pAd->MlmeAux.BssType = BssType;
873 pAd->MlmeAux.BeaconPeriod = BeaconPeriod;
874 pAd->MlmeAux.Channel = Channel;
875 pAd->MlmeAux.AtimWin = AtimWin;
876 pAd->MlmeAux.CfpPeriod = Cf.CfpPeriod;
877 pAd->MlmeAux.CfpMaxDuration = Cf.CfpMaxDuration;
878 pAd->MlmeAux.APRalinkIe = RalinkIe;
879
880 /* Copy AP's supported rate to MlmeAux for creating association request */
881 /* Also filter out not supported rate */
882 pAd->MlmeAux.SupRateLen = SupRateLen;
883 NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate,
884 SupRateLen);
885 RTMPCheckRates(pAd, pAd->MlmeAux.SupRate,
886 &pAd->MlmeAux.SupRateLen);
887 pAd->MlmeAux.ExtRateLen = ExtRateLen;
888 NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate,
889 ExtRateLen);
890 RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate,
891 &pAd->MlmeAux.ExtRateLen);
892
893 NdisZeroMemory(pAd->StaActive.SupportedPhyInfo.MCSSet,
894 16);
895
896 if (((pAd->StaCfg.WepStatus != Ndis802_11WEPEnabled)
897 && (pAd->StaCfg.WepStatus !=
898 Ndis802_11Encryption2Enabled))
899 || (pAd->CommonCfg.HT_DisallowTKIP == FALSE)) {
900 bAllowNrate = TRUE;
901 }
902
903 pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;
904 pAd->MlmeAux.HtCapabilityLen = HtCapabilityLen;
905
906 RTMPZeroMemory(&pAd->MlmeAux.HtCapability,
907 SIZE_HT_CAP_IE);
908 /* filter out un-supported ht rates */
909 if (((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
910 && ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
911 && (bAllowNrate))) {
912 RTMPMoveMemory(&pAd->MlmeAux.AddHtInfo,
913 &AddHtInfo, SIZE_ADD_HT_INFO_IE);
914
915 /* StaActive.SupportedHtPhy.MCSSet stores Peer AP's 11n Rx capability */
916 NdisMoveMemory(pAd->StaActive.SupportedPhyInfo.
917 MCSSet, HtCapability.MCSSet, 16);
918 pAd->MlmeAux.NewExtChannelOffset =
919 NewExtChannelOffset;
920 pAd->MlmeAux.HtCapabilityLen = SIZE_HT_CAP_IE;
921 pAd->StaActive.SupportedPhyInfo.bHtEnable =
922 TRUE;
923 if (PreNHtCapabilityLen > 0)
924 pAd->StaActive.SupportedPhyInfo.
925 bPreNHt = TRUE;
926 RTMPCheckHt(pAd, BSSID_WCID, &HtCapability,
927 &AddHtInfo);
928 /* Copy AP Parameter to StaActive. This is also in LinkUp. */
929 DBGPRINT(RT_DEBUG_TRACE,
930 ("PeerBeaconAtJoinAction! (MpduDensity=%d, MaxRAmpduFactor=%d, BW=%d)\n",
931 pAd->StaActive.SupportedHtPhy.
932 MpduDensity,
933 pAd->StaActive.SupportedHtPhy.
934 MaxRAmpduFactor,
935 HtCapability.HtCapInfo.ChannelWidth));
936
937 if (AddHtInfoLen > 0) {
938 CentralChannel = AddHtInfo.ControlChan;
939 /* Check again the Bandwidth capability of this AP. */
940 if ((AddHtInfo.ControlChan > 2)
941 && (AddHtInfo.AddHtInfo.
942 ExtChanOffset == EXTCHA_BELOW)
943 && (HtCapability.HtCapInfo.
944 ChannelWidth == BW_40)) {
945 CentralChannel =
946 AddHtInfo.ControlChan - 2;
947 } else
948 if ((AddHtInfo.AddHtInfo.
949 ExtChanOffset == EXTCHA_ABOVE)
950 && (HtCapability.HtCapInfo.
951 ChannelWidth == BW_40)) {
952 CentralChannel =
953 AddHtInfo.ControlChan + 2;
954 }
955 /* Check Error . */
956 if (pAd->MlmeAux.CentralChannel !=
957 CentralChannel)
958 DBGPRINT(RT_DEBUG_ERROR,
959 ("PeerBeaconAtJoinAction HT===>Beacon Central Channel = %d, Control Channel = %d. Mlmeaux CentralChannel = %d\n",
960 CentralChannel,
961 AddHtInfo.ControlChan,
962 pAd->MlmeAux.
963 CentralChannel));
964
965 DBGPRINT(RT_DEBUG_TRACE,
966 ("PeerBeaconAtJoinAction HT===>Central Channel = %d, Control Channel = %d, .\n",
967 CentralChannel,
968 AddHtInfo.ControlChan));
969
970 }
971
972 } else {
973 /* To prevent error, let legacy AP must have same CentralChannel and Channel. */
974 if ((HtCapabilityLen == 0)
975 && (PreNHtCapabilityLen == 0))
976 pAd->MlmeAux.CentralChannel =
977 pAd->MlmeAux.Channel;
978
979 pAd->StaActive.SupportedPhyInfo.bHtEnable =
980 FALSE;
981 pAd->MlmeAux.NewExtChannelOffset = 0xff;
982 RTMPZeroMemory(&pAd->MlmeAux.HtCapability,
983 SIZE_HT_CAP_IE);
984 pAd->MlmeAux.HtCapabilityLen = 0;
985 RTMPZeroMemory(&pAd->MlmeAux.AddHtInfo,
986 SIZE_ADD_HT_INFO_IE);
987 }
988
989 RTMPUpdateMlmeRate(pAd);
990
991 /* copy QOS related information */
992 if ((pAd->CommonCfg.bWmmCapable)
993 || (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
994 ) {
995 NdisMoveMemory(&pAd->MlmeAux.APEdcaParm,
996 &EdcaParm, sizeof(struct rt_edca_parm));
997 NdisMoveMemory(&pAd->MlmeAux.APQbssLoad,
998 &QbssLoad,
999 sizeof(struct rt_qbss_load_parm));
1000 NdisMoveMemory(&pAd->MlmeAux.APQosCapability,
1001 &QosCapability,
1002 sizeof(struct rt_qos_capability_parm));
1003 } else {
1004 NdisZeroMemory(&pAd->MlmeAux.APEdcaParm,
1005 sizeof(struct rt_edca_parm));
1006 NdisZeroMemory(&pAd->MlmeAux.APQbssLoad,
1007 sizeof(struct rt_qbss_load_parm));
1008 NdisZeroMemory(&pAd->MlmeAux.APQosCapability,
1009 sizeof(struct rt_qos_capability_parm));
1010 }
1011
1012 DBGPRINT(RT_DEBUG_TRACE,
1013 ("SYNC - after JOIN, SupRateLen=%d, ExtRateLen=%d\n",
1014 pAd->MlmeAux.SupRateLen,
1015 pAd->MlmeAux.ExtRateLen));
1016
1017 if (AironetCellPowerLimit != 0xFF) {
1018 /*We need to change our TxPower for CCX 2.0 AP Control of Client Transmit Power */
1019 ChangeToCellPowerLimit(pAd,
1020 AironetCellPowerLimit);
1021 } else /*Used the default TX Power Percentage. */
1022 pAd->CommonCfg.TxPowerPercentage =
1023 pAd->CommonCfg.TxPowerDefault;
1024
1025 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1026 Status = MLME_SUCCESS;
1027 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF,
1028 2, &Status);
1029 }
1030 /* not to me BEACON, ignored */
1031 }
1032 /* sanity check fail, ignore this frame */
1033}
1034
1035/*
1036 ==========================================================================
1037 Description:
1038 receive BEACON from peer
1039
1040 IRQL = DISPATCH_LEVEL
1041
1042 ==========================================================================
1043 */
1044void PeerBeacon(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1045{
1046 u8 Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
1047 char Ssid[MAX_LEN_OF_SSID];
1048 struct rt_cf_parm CfParm;
1049 u8 SsidLen, MessageToMe = 0, BssType, Channel, NewChannel, index = 0;
1050 u8 DtimCount = 0, DtimPeriod = 0, BcastFlag = 0;
1051 u16 CapabilityInfo, AtimWin, BeaconPeriod;
1052 LARGE_INTEGER TimeStamp;
1053 u16 TbttNumToNextWakeUp;
1054 u8 Erp;
1055 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES],
1056 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
1057 u8 SupRateLen, ExtRateLen;
1058 u8 CkipFlag;
1059 u16 LenVIE;
1060 u8 AironetCellPowerLimit;
1061 struct rt_edca_parm EdcaParm;
1062 struct rt_qbss_load_parm QbssLoad;
1063 struct rt_qos_capability_parm QosCapability;
1064 unsigned long RalinkIe;
1065 /* New for WPA security suites */
1066 u8 VarIE[MAX_VIE_LEN]; /* Total VIE length = MAX_VIE_LEN - -5 */
1067 struct rt_ndis_802_11_variable_ies *pVIE = NULL;
1068 struct rt_ht_capability_ie HtCapability;
1069 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
1070 u8 HtCapabilityLen, PreNHtCapabilityLen;
1071 u8 AddHtInfoLen;
1072 u8 NewExtChannelOffset = 0xff;
1073
1074 if (!(INFRA_ON(pAd) || ADHOC_ON(pAd)
1075 ))
1076 return;
1077
1078 /* Init Variable IE structure */
1079 pVIE = (struct rt_ndis_802_11_variable_ies *)VarIE;
1080 pVIE->Length = 0;
1081 RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
1082 RTMPZeroMemory(&AddHtInfo, sizeof(struct rt_add_ht_info_ie));
1083
1084 if (PeerBeaconAndProbeRspSanity(pAd,
1085 Elem->Msg,
1086 Elem->MsgLen,
1087 Elem->Channel,
1088 Addr2,
1089 Bssid,
1090 Ssid,
1091 &SsidLen,
1092 &BssType,
1093 &BeaconPeriod,
1094 &Channel,
1095 &NewChannel,
1096 &TimeStamp,
1097 &CfParm,
1098 &AtimWin,
1099 &CapabilityInfo,
1100 &Erp,
1101 &DtimCount,
1102 &DtimPeriod,
1103 &BcastFlag,
1104 &MessageToMe,
1105 SupRate,
1106 &SupRateLen,
1107 ExtRate,
1108 &ExtRateLen,
1109 &CkipFlag,
1110 &AironetCellPowerLimit,
1111 &EdcaParm,
1112 &QbssLoad,
1113 &QosCapability,
1114 &RalinkIe,
1115 &HtCapabilityLen,
1116 &PreNHtCapabilityLen,
1117 &HtCapability,
1118 &AddHtInfoLen,
1119 &AddHtInfo,
1120 &NewExtChannelOffset, &LenVIE, pVIE)) {
1121 BOOLEAN is_my_bssid, is_my_ssid;
1122 unsigned long Bssidx, Now;
1123 struct rt_bss_entry *pBss;
1124 char RealRssi =
1125 RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0),
1126 ConvertToRssi(pAd, Elem->Rssi1, RSSI_1),
1127 ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
1128
1129 is_my_bssid =
1130 MAC_ADDR_EQUAL(Bssid, pAd->CommonCfg.Bssid) ? TRUE : FALSE;
1131 is_my_ssid =
1132 SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid,
1133 pAd->CommonCfg.SsidLen) ? TRUE : FALSE;
1134
1135 /* ignore BEACON not for my SSID */
1136 if ((!is_my_ssid) && (!is_my_bssid))
1137 return;
1138
1139 /* It means STA waits disassoc completely from this AP, ignores this beacon. */
1140 if (pAd->Mlme.CntlMachine.CurrState == CNTL_WAIT_DISASSOC)
1141 return;
1142
1143 /* Copy Control channel for this BSSID. */
1144 if (AddHtInfoLen != 0)
1145 Channel = AddHtInfo.ControlChan;
1146
1147 if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
1148 HtCapabilityLen = SIZE_HT_CAP_IE;
1149
1150 /* */
1151 /* Housekeeping "SsidBssTab" table for later-on ROAMing usage. */
1152 /* */
1153 Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
1154 if (Bssidx == BSS_NOT_FOUND) {
1155 /* discover new AP of this network, create BSS entry */
1156 Bssidx =
1157 BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid,
1158 SsidLen, BssType, BeaconPeriod,
1159 &CfParm, AtimWin, CapabilityInfo,
1160 SupRate, SupRateLen, ExtRate,
1161 ExtRateLen, &HtCapability,
1162 &AddHtInfo, HtCapabilityLen,
1163 AddHtInfoLen, NewExtChannelOffset,
1164 Channel, RealRssi, TimeStamp,
1165 CkipFlag, &EdcaParm,
1166 &QosCapability, &QbssLoad, LenVIE,
1167 pVIE);
1168 if (Bssidx == BSS_NOT_FOUND) /* return if BSS table full */
1169 return;
1170
1171 NdisMoveMemory(pAd->ScanTab.BssEntry[Bssidx].PTSF,
1172 &Elem->Msg[24], 4);
1173 NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[0],
1174 &Elem->TimeStamp.u.LowPart, 4);
1175 NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[4],
1176 &Elem->TimeStamp.u.LowPart, 4);
1177
1178 }
1179
1180 if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0)
1181 && (Channel != NewChannel)) {
1182 /* Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection). */
1183 /* In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results. */
1184 AsicSwitchChannel(pAd, 1, FALSE);
1185 AsicLockChannel(pAd, 1);
1186 LinkDown(pAd, FALSE);
1187 MlmeQueueInit(&pAd->Mlme.Queue);
1188 BssTableInit(&pAd->ScanTab);
1189 RTMPusecDelay(1000000); /* use delay to prevent STA do reassoc */
1190
1191 /* channel sanity check */
1192 for (index = 0; index < pAd->ChannelListNum; index++) {
1193 if (pAd->ChannelList[index].Channel ==
1194 NewChannel) {
1195 pAd->ScanTab.BssEntry[Bssidx].Channel =
1196 NewChannel;
1197 pAd->CommonCfg.Channel = NewChannel;
1198 AsicSwitchChannel(pAd,
1199 pAd->CommonCfg.
1200 Channel, FALSE);
1201 AsicLockChannel(pAd,
1202 pAd->CommonCfg.Channel);
1203 DBGPRINT(RT_DEBUG_TRACE,
1204 ("PeerBeacon - STA receive channel switch announcement IE (New Channel =%d)\n",
1205 NewChannel));
1206 break;
1207 }
1208 }
1209
1210 if (index >= pAd->ChannelListNum) {
1211 DBGPRINT_ERR("PeerBeacon(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum);
1212 }
1213 }
1214 /* if the ssid matched & bssid unmatched, we should select the bssid with large value. */
1215 /* This might happened when two STA start at the same time */
1216 if ((!is_my_bssid) && ADHOC_ON(pAd)) {
1217 int i;
1218
1219 /* Add the safeguard against the mismatch of adhoc wep status */
1220 if (pAd->StaCfg.WepStatus !=
1221 pAd->ScanTab.BssEntry[Bssidx].WepStatus) {
1222 return;
1223 }
1224 /* collapse into the ADHOC network which has bigger BSSID value. */
1225 for (i = 0; i < 6; i++) {
1226 if (Bssid[i] > pAd->CommonCfg.Bssid[i]) {
1227 DBGPRINT(RT_DEBUG_TRACE,
1228 ("SYNC - merge to the IBSS "
1229 "with bigger BSSID="
1230 "%pM\n", Bssid));
1231 AsicDisableSync(pAd);
1232 COPY_MAC_ADDR(pAd->CommonCfg.Bssid,
1233 Bssid);
1234 AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
1235 MakeIbssBeacon(pAd); /* re-build BEACON frame */
1236 AsicEnableIbssSync(pAd); /* copy BEACON frame to on-chip memory */
1237 is_my_bssid = TRUE;
1238 break;
1239 } else if (Bssid[i] < pAd->CommonCfg.Bssid[i])
1240 break;
1241 }
1242 }
1243
1244 NdisGetSystemUpTime(&Now);
1245 pBss = &pAd->ScanTab.BssEntry[Bssidx];
1246 pBss->Rssi = RealRssi; /* lastest RSSI */
1247 pBss->LastBeaconRxTime = Now; /* last RX timestamp */
1248
1249 /* */
1250 /* BEACON from my BSSID - either IBSS or INFRA network */
1251 /* */
1252 if (is_my_bssid) {
1253 struct rt_rxwi RxWI;
1254
1255 pAd->StaCfg.DtimCount = DtimCount;
1256 pAd->StaCfg.DtimPeriod = DtimPeriod;
1257 pAd->StaCfg.LastBeaconRxTime = Now;
1258
1259 RxWI.RSSI0 = Elem->Rssi0;
1260 RxWI.RSSI1 = Elem->Rssi1;
1261 RxWI.RSSI2 = Elem->Rssi2;
1262
1263 Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, &RxWI);
1264 if (AironetCellPowerLimit != 0xFF) {
1265 /* */
1266 /* We get the Cisco (ccx) "TxPower Limit" required */
1267 /* Changed to appropriate TxPower Limit for Ciso Compatible Extensions */
1268 /* */
1269 ChangeToCellPowerLimit(pAd,
1270 AironetCellPowerLimit);
1271 } else {
1272 /* */
1273 /* AironetCellPowerLimit equal to 0xFF means the Cisco (ccx) "TxPower Limit" not exist. */
1274 /* Used the default TX Power Percentage, that set from UI. */
1275 /* */
1276 pAd->CommonCfg.TxPowerPercentage =
1277 pAd->CommonCfg.TxPowerDefault;
1278 }
1279
1280 if (ADHOC_ON(pAd) && (CAP_IS_IBSS_ON(CapabilityInfo))) {
1281 u8 MaxSupportedRateIn500Kbps = 0;
1282 u8 idx;
1283 struct rt_mac_table_entry *pEntry;
1284
1285 /* supported rates array may not be sorted. sort it and find the maximum rate */
1286 for (idx = 0; idx < SupRateLen; idx++) {
1287 if (MaxSupportedRateIn500Kbps <
1288 (SupRate[idx] & 0x7f))
1289 MaxSupportedRateIn500Kbps =
1290 SupRate[idx] & 0x7f;
1291 }
1292
1293 for (idx = 0; idx < ExtRateLen; idx++) {
1294 if (MaxSupportedRateIn500Kbps <
1295 (ExtRate[idx] & 0x7f))
1296 MaxSupportedRateIn500Kbps =
1297 ExtRate[idx] & 0x7f;
1298 }
1299
1300 /* look up the existing table */
1301 pEntry = MacTableLookup(pAd, Addr2);
1302
1303 /* Ad-hoc mode is using MAC address as BA session. So we need to continuously find newly joined adhoc station by receiving beacon. */
1304 /* To prevent always check this, we use wcid == RESERVED_WCID to recognize it as newly joined adhoc station. */
1305 if ((ADHOC_ON(pAd)
1306 && (Elem->Wcid == RESERVED_WCID))
1307 || (pEntry
1308 &&
1309 ((pEntry->LastBeaconRxTime +
1310 ADHOC_ENTRY_BEACON_LOST_TIME) <
1311 Now))) {
1312 if (pEntry == NULL)
1313 /* Another adhoc joining, add to our MAC table. */
1314 pEntry =
1315 MacTableInsertEntry(pAd,
1316 Addr2,
1317 BSS0,
1318 FALSE);
1319
1320 if (StaAddMacTableEntry(pAd,
1321 pEntry,
1322 MaxSupportedRateIn500Kbps,
1323 &HtCapability,
1324 HtCapabilityLen,
1325 &AddHtInfo,
1326 AddHtInfoLen,
1327 CapabilityInfo)
1328 == FALSE) {
1329 DBGPRINT(RT_DEBUG_TRACE,
1330 ("ADHOC - Add Entry failed.\n"));
1331 return;
1332 }
1333
1334 if (pEntry &&
1335 (Elem->Wcid == RESERVED_WCID)) {
1336 idx = pAd->StaCfg.DefaultKeyId;
1337 RTMP_STA_SECURITY_INFO_ADD(pAd,
1338 BSS0,
1339 idx,
1340 pEntry);
1341 }
1342 }
1343
1344 if (pEntry && pEntry->ValidAsCLI)
1345 pEntry->LastBeaconRxTime = Now;
1346
1347 /* At least another peer in this IBSS, declare MediaState as CONNECTED */
1348 if (!OPSTATUS_TEST_FLAG
1349 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
1350 OPSTATUS_SET_FLAG(pAd,
1351 fOP_STATUS_MEDIA_STATE_CONNECTED);
1352
1353 pAd->IndicateMediaState =
1354 NdisMediaStateConnected;
1355 RTMP_IndicateMediaState(pAd);
1356 pAd->ExtraInfo = GENERAL_LINK_UP;
1357 AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
1358
1359 /* 2003/03/12 - john */
1360 /* Make sure this entry in "ScanTab" table, thus complies to Microsoft's policy that */
1361 /* "site survey" result should always include the current connected network. */
1362 /* */
1363 Bssidx =
1364 BssTableSearch(&pAd->ScanTab, Bssid,
1365 Channel);
1366 if (Bssidx == BSS_NOT_FOUND) {
1367 Bssidx =
1368 BssTableSetEntry(pAd,
1369 &pAd->
1370 ScanTab,
1371 Bssid,
1372 Ssid,
1373 SsidLen,
1374 BssType,
1375 BeaconPeriod,
1376 &CfParm,
1377 AtimWin,
1378 CapabilityInfo,
1379 SupRate,
1380 SupRateLen,
1381 ExtRate,
1382 ExtRateLen,
1383 &HtCapability,
1384 &AddHtInfo,
1385 HtCapabilityLen,
1386 AddHtInfoLen,
1387 NewExtChannelOffset,
1388 Channel,
1389 RealRssi,
1390 TimeStamp,
1391 0,
1392 &EdcaParm,
1393 &QosCapability,
1394 &QbssLoad,
1395 LenVIE,
1396 pVIE);
1397 }
1398 DBGPRINT(RT_DEBUG_TRACE,
1399 ("ADHOC fOP_STATUS_MEDIA_STATE_CONNECTED.\n"));
1400 }
1401 }
1402
1403 if (INFRA_ON(pAd)) {
1404 BOOLEAN bUseShortSlot, bUseBGProtection;
1405
1406 /* decide to use/change to - */
1407 /* 1. long slot (20 us) or short slot (9 us) time */
1408 /* 2. turn on/off RTS/CTS and/or CTS-to-self protection */
1409 /* 3. short preamble */
1410
1411 /*bUseShortSlot = pAd->CommonCfg.bUseShortSlotTime && CAP_IS_SHORT_SLOT(CapabilityInfo); */
1412 bUseShortSlot =
1413 CAP_IS_SHORT_SLOT(CapabilityInfo);
1414 if (bUseShortSlot !=
1415 OPSTATUS_TEST_FLAG(pAd,
1416 fOP_STATUS_SHORT_SLOT_INUSED))
1417 AsicSetSlotTime(pAd, bUseShortSlot);
1418
1419 bUseBGProtection = (pAd->CommonCfg.UseBGProtection == 1) || /* always use */
1420 ((pAd->CommonCfg.UseBGProtection == 0)
1421 && ERP_IS_USE_PROTECTION(Erp));
1422
1423 if (pAd->CommonCfg.Channel > 14) /* always no BG protection in A-band. falsely happened when switching A/G band to a dual-band AP */
1424 bUseBGProtection = FALSE;
1425
1426 if (bUseBGProtection !=
1427 OPSTATUS_TEST_FLAG(pAd,
1428 fOP_STATUS_BG_PROTECTION_INUSED))
1429 {
1430 if (bUseBGProtection) {
1431 OPSTATUS_SET_FLAG(pAd,
1432 fOP_STATUS_BG_PROTECTION_INUSED);
1433 AsicUpdateProtect(pAd,
1434 pAd->MlmeAux.
1435 AddHtInfo.
1436 AddHtInfo2.
1437 OperaionMode,
1438 (OFDMSETPROTECT
1439 |
1440 CCKSETPROTECT
1441 |
1442 ALLN_SETPROTECT),
1443 FALSE,
1444 (pAd->MlmeAux.
1445 AddHtInfo.
1446 AddHtInfo2.
1447 NonGfPresent
1448 == 1));
1449 } else {
1450 OPSTATUS_CLEAR_FLAG(pAd,
1451 fOP_STATUS_BG_PROTECTION_INUSED);
1452 AsicUpdateProtect(pAd,
1453 pAd->MlmeAux.
1454 AddHtInfo.
1455 AddHtInfo2.
1456 OperaionMode,
1457 (OFDMSETPROTECT
1458 |
1459 CCKSETPROTECT
1460 |
1461 ALLN_SETPROTECT),
1462 TRUE,
1463 (pAd->MlmeAux.
1464 AddHtInfo.
1465 AddHtInfo2.
1466 NonGfPresent
1467 == 1));
1468 }
1469
1470 DBGPRINT(RT_DEBUG_WARN,
1471 ("SYNC - AP changed B/G protection to %d\n",
1472 bUseBGProtection));
1473 }
1474 /* check Ht protection mode. and adhere to the Non-GF device indication by AP. */
1475 if ((AddHtInfoLen != 0) &&
1476 ((AddHtInfo.AddHtInfo2.OperaionMode !=
1477 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1478 OperaionMode)
1479 || (AddHtInfo.AddHtInfo2.NonGfPresent !=
1480 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1481 NonGfPresent))) {
1482 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1483 NonGfPresent =
1484 AddHtInfo.AddHtInfo2.NonGfPresent;
1485 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1486 OperaionMode =
1487 AddHtInfo.AddHtInfo2.OperaionMode;
1488 if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1489 NonGfPresent == 1) {
1490 AsicUpdateProtect(pAd,
1491 pAd->MlmeAux.
1492 AddHtInfo.
1493 AddHtInfo2.
1494 OperaionMode,
1495 ALLN_SETPROTECT,
1496 FALSE, TRUE);
1497 } else
1498 AsicUpdateProtect(pAd,
1499 pAd->MlmeAux.
1500 AddHtInfo.
1501 AddHtInfo2.
1502 OperaionMode,
1503 ALLN_SETPROTECT,
1504 FALSE, FALSE);
1505
1506 DBGPRINT(RT_DEBUG_TRACE,
1507 ("SYNC - AP changed N OperaionMode to %d\n",
1508 pAd->MlmeAux.AddHtInfo.
1509 AddHtInfo2.OperaionMode));
1510 }
1511
1512 if (OPSTATUS_TEST_FLAG
1513 (pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED)
1514 && ERP_IS_USE_BARKER_PREAMBLE(Erp)) {
1515 MlmeSetTxPreamble(pAd,
1516 Rt802_11PreambleLong);
1517 DBGPRINT(RT_DEBUG_TRACE,
1518 ("SYNC - AP forced to use long preamble\n"));
1519 }
1520
1521 if (OPSTATUS_TEST_FLAG
1522 (pAd, fOP_STATUS_WMM_INUSED)
1523 && (EdcaParm.bValid == TRUE)
1524 && (EdcaParm.EdcaUpdateCount !=
1525 pAd->CommonCfg.APEdcaParm.
1526 EdcaUpdateCount)) {
1527 DBGPRINT(RT_DEBUG_TRACE,
1528 ("SYNC - AP change EDCA parameters(from %d to %d)\n",
1529 pAd->CommonCfg.APEdcaParm.
1530 EdcaUpdateCount,
1531 EdcaParm.EdcaUpdateCount));
1532 AsicSetEdcaParm(pAd, &EdcaParm);
1533 }
1534 /* copy QOS related information */
1535 NdisMoveMemory(&pAd->CommonCfg.APQbssLoad,
1536 &QbssLoad,
1537 sizeof(struct rt_qbss_load_parm));
1538 NdisMoveMemory(&pAd->CommonCfg.APQosCapability,
1539 &QosCapability,
1540 sizeof(struct rt_qos_capability_parm));
1541 }
1542 /* only INFRASTRUCTURE mode support power-saving feature */
1543 if ((INFRA_ON(pAd) && (pAd->StaCfg.Psm == PWR_SAVE))
1544 || (pAd->CommonCfg.bAPSDForcePowerSave)) {
1545 u8 FreeNumber;
1546 /* 1. AP has backlogged unicast-to-me frame, stay AWAKE, send PSPOLL */
1547 /* 2. AP has backlogged broadcast/multicast frame and we want those frames, stay AWAKE */
1548 /* 3. we have outgoing frames in TxRing or MgmtRing, better stay AWAKE */
1549 /* 4. Psm change to PWR_SAVE, but AP not been informed yet, we better stay AWAKE */
1550 /* 5. otherwise, put PHY back to sleep to save battery. */
1551 if (MessageToMe) {
1552#ifdef RTMP_MAC_PCI
1553 if (OPSTATUS_TEST_FLAG
1554 (pAd, fOP_STATUS_PCIE_DEVICE)) {
1555 /* Restore to correct BBP R3 value */
1556 if (pAd->Antenna.field.RxPath >
1557 1)
1558 RTMP_BBP_IO_WRITE8_BY_REG_ID
1559 (pAd, BBP_R3,
1560 pAd->StaCfg.BBPR3);
1561 /* Turn clk to 80Mhz. */
1562 }
1563#endif /* RTMP_MAC_PCI // */
1564 if (pAd->CommonCfg.bAPSDCapable
1565 && pAd->CommonCfg.APEdcaParm.
1566 bAPSDCapable
1567 && pAd->CommonCfg.bAPSDAC_BE
1568 && pAd->CommonCfg.bAPSDAC_BK
1569 && pAd->CommonCfg.bAPSDAC_VI
1570 && pAd->CommonCfg.bAPSDAC_VO) {
1571 pAd->CommonCfg.
1572 bNeedSendTriggerFrame =
1573 TRUE;
1574 } else
1575 RTMP_PS_POLL_ENQUEUE(pAd);
1576 } else if (BcastFlag && (DtimCount == 0)
1577 && OPSTATUS_TEST_FLAG(pAd,
1578 fOP_STATUS_RECEIVE_DTIM))
1579 {
1580#ifdef RTMP_MAC_PCI
1581 if (OPSTATUS_TEST_FLAG
1582 (pAd, fOP_STATUS_PCIE_DEVICE)) {
1583 if (pAd->Antenna.field.RxPath >
1584 1)
1585 RTMP_BBP_IO_WRITE8_BY_REG_ID
1586 (pAd, BBP_R3,
1587 pAd->StaCfg.BBPR3);
1588 }
1589#endif /* RTMP_MAC_PCI // */
1590 } else
1591 if ((pAd->TxSwQueue[QID_AC_BK].Number != 0)
1592 || (pAd->TxSwQueue[QID_AC_BE].Number !=
1593 0)
1594 || (pAd->TxSwQueue[QID_AC_VI].Number !=
1595 0)
1596 || (pAd->TxSwQueue[QID_AC_VO].Number !=
1597 0)
1598 ||
1599 (RTMPFreeTXDRequest
1600 (pAd, QID_AC_BK, TX_RING_SIZE - 1,
1601 &FreeNumber) != NDIS_STATUS_SUCCESS)
1602 ||
1603 (RTMPFreeTXDRequest
1604 (pAd, QID_AC_BE, TX_RING_SIZE - 1,
1605 &FreeNumber) != NDIS_STATUS_SUCCESS)
1606 ||
1607 (RTMPFreeTXDRequest
1608 (pAd, QID_AC_VI, TX_RING_SIZE - 1,
1609 &FreeNumber) != NDIS_STATUS_SUCCESS)
1610 ||
1611 (RTMPFreeTXDRequest
1612 (pAd, QID_AC_VO, TX_RING_SIZE - 1,
1613 &FreeNumber) != NDIS_STATUS_SUCCESS)
1614 ||
1615 (RTMPFreeTXDRequest
1616 (pAd, QID_MGMT, MGMT_RING_SIZE - 1,
1617 &FreeNumber) !=
1618 NDIS_STATUS_SUCCESS)) {
1619 /* TODO: consider scheduled HCCA. might not be proper to use traditional DTIM-based power-saving scheme */
1620 /* can we cheat here (i.e. just check MGMT & AC_BE) for better performance? */
1621#ifdef RTMP_MAC_PCI
1622 if (OPSTATUS_TEST_FLAG
1623 (pAd, fOP_STATUS_PCIE_DEVICE)) {
1624 if (pAd->Antenna.field.RxPath >
1625 1)
1626 RTMP_BBP_IO_WRITE8_BY_REG_ID
1627 (pAd, BBP_R3,
1628 pAd->StaCfg.BBPR3);
1629 }
1630#endif /* RTMP_MAC_PCI // */
1631 } else {
1632 if ((pAd->CommonCfg.
1633 bACMAPSDTr[QID_AC_VO])
1634 || (pAd->CommonCfg.
1635 bACMAPSDTr[QID_AC_VI])
1636 || (pAd->CommonCfg.
1637 bACMAPSDTr[QID_AC_BK])
1638 || (pAd->CommonCfg.
1639 bACMAPSDTr[QID_AC_BE])) {
1640 /*
1641 WMM Spec v1.0 3.6.2.4,
1642 The WMM STA shall remain awake until it receives a
1643 QoS Data or Null frame addressed to it, with the
1644 EOSP subfield in QoS Control field set to 1.
1645
1646 So we can not sleep here or we will suffer a case:
1647
1648 PS Management Frame -->
1649 Trigger frame -->
1650 Beacon (TIM=0) (Beacon is closer to Trig frame) -->
1651 Station goes to sleep -->
1652 AP delivery queued UAPSD packets -->
1653 Station can NOT receive the reply
1654
1655 Maybe we need a timeout timer to avoid that we do
1656 NOT receive the EOSP frame.
1657
1658 We can not use More Data to check if SP is ended
1659 due to MaxSPLength.
1660 */
1661 } else {
1662 u16 NextDtim = DtimCount;
1663
1664 if (NextDtim == 0)
1665 NextDtim = DtimPeriod;
1666
1667 TbttNumToNextWakeUp =
1668 pAd->StaCfg.
1669 DefaultListenCount;
1670 if (OPSTATUS_TEST_FLAG
1671 (pAd,
1672 fOP_STATUS_RECEIVE_DTIM)
1673 && (TbttNumToNextWakeUp >
1674 NextDtim))
1675 TbttNumToNextWakeUp =
1676 NextDtim;
1677
1678 if (!OPSTATUS_TEST_FLAG
1679 (pAd, fOP_STATUS_DOZE)) {
1680 /* Set a flag to go to sleep . Then after parse this RxDoneInterrupt, will go to sleep mode. */
1681 pAd->
1682 ThisTbttNumToNextWakeUp
1683 =
1684 TbttNumToNextWakeUp;
1685 AsicSleepThenAutoWakeup
1686 (pAd,
1687 pAd->
1688 ThisTbttNumToNextWakeUp);
1689 }
1690 }
1691 }
1692 }
1693 }
1694 /* not my BSSID, ignore it */
1695 }
1696 /* sanity check fail, ignore this frame */
1697}
1698
1699/*
1700 ==========================================================================
1701 Description:
1702 Receive PROBE REQ from remote peer when operating in IBSS mode
1703 ==========================================================================
1704 */
1705void PeerProbeReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1706{
1707 u8 Addr2[MAC_ADDR_LEN];
1708 char Ssid[MAX_LEN_OF_SSID];
1709 u8 SsidLen;
1710 u8 HtLen, AddHtLen, NewExtLen;
1711 struct rt_header_802_11 ProbeRspHdr;
1712 int NStatus;
1713 u8 *pOutBuffer = NULL;
1714 unsigned long FrameLen = 0;
1715 LARGE_INTEGER FakeTimestamp;
1716 u8 DsLen = 1, IbssLen = 2;
1717 u8 LocalErpIe[3] = { IE_ERP, 1, 0 };
1718 BOOLEAN Privacy;
1719 u16 CapabilityInfo;
1720 u8 RSNIe = IE_WPA;
1721
1722 if (!ADHOC_ON(pAd))
1723 return;
1724
1725 if (PeerProbeReqSanity
1726 (pAd, Elem->Msg, Elem->MsgLen, Addr2, Ssid, &SsidLen)) {
1727 if ((SsidLen == 0)
1728 || SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid,
1729 pAd->CommonCfg.SsidLen)) {
1730 /* allocate and send out ProbeRsp frame */
1731 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
1732 if (NStatus != NDIS_STATUS_SUCCESS)
1733 return;
1734
1735 /*pAd->StaCfg.AtimWin = 0; // ?????? */
1736
1737 Privacy =
1738 (pAd->StaCfg.WepStatus ==
1739 Ndis802_11Encryption1Enabled)
1740 || (pAd->StaCfg.WepStatus ==
1741 Ndis802_11Encryption2Enabled)
1742 || (pAd->StaCfg.WepStatus ==
1743 Ndis802_11Encryption3Enabled);
1744 CapabilityInfo =
1745 CAP_GENERATE(0, 1, Privacy,
1746 (pAd->CommonCfg.TxPreamble ==
1747 Rt802_11PreambleShort), 0, 0);
1748
1749 MakeOutgoingFrame(pOutBuffer, &FrameLen,
1750 sizeof(struct rt_header_802_11), &ProbeRspHdr,
1751 TIMESTAMP_LEN, &FakeTimestamp,
1752 2, &pAd->CommonCfg.BeaconPeriod,
1753 2, &CapabilityInfo,
1754 1, &SsidIe,
1755 1, &pAd->CommonCfg.SsidLen,
1756 pAd->CommonCfg.SsidLen,
1757 pAd->CommonCfg.Ssid, 1, &SupRateIe, 1,
1758 &pAd->StaActive.SupRateLen,
1759 pAd->StaActive.SupRateLen,
1760 pAd->StaActive.SupRate, 1, &DsIe, 1,
1761 &DsLen, 1, &pAd->CommonCfg.Channel, 1,
1762 &IbssIe, 1, &IbssLen, 2,
1763 &pAd->StaActive.AtimWin, END_OF_ARGS);
1764
1765 if (pAd->StaActive.ExtRateLen) {
1766 unsigned long tmp;
1767 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1768 3, LocalErpIe,
1769 1, &ExtRateIe,
1770 1, &pAd->StaActive.ExtRateLen,
1771 pAd->StaActive.ExtRateLen,
1772 &pAd->StaActive.ExtRate,
1773 END_OF_ARGS);
1774 FrameLen += tmp;
1775 }
1776 /* If adhoc secruity is set for WPA-None, append the cipher suite IE */
1777 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) {
1778 unsigned long tmp;
1779 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1780 1, &RSNIe,
1781 1, &pAd->StaCfg.RSNIE_Len,
1782 pAd->StaCfg.RSNIE_Len,
1783 pAd->StaCfg.RSN_IE,
1784 END_OF_ARGS);
1785 FrameLen += tmp;
1786 }
1787
1788 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) {
1789 unsigned long TmpLen;
1790 u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 };
1791 HtLen = sizeof(pAd->CommonCfg.HtCapability);
1792 AddHtLen = sizeof(pAd->CommonCfg.AddHTInfo);
1793 NewExtLen = 1;
1794 /*New extension channel offset IE is included in Beacon, Probe Rsp or channel Switch Announcement Frame */
1795 if (pAd->bBroadComHT == TRUE) {
1796 MakeOutgoingFrame(pOutBuffer + FrameLen,
1797 &TmpLen, 1, &WpaIe, 4,
1798 &BROADCOM[0],
1799 pAd->MlmeAux.
1800 HtCapabilityLen,
1801 &pAd->MlmeAux.
1802 HtCapability,
1803 END_OF_ARGS);
1804 } else {
1805 MakeOutgoingFrame(pOutBuffer + FrameLen,
1806 &TmpLen, 1, &HtCapIe,
1807 1, &HtLen,
1808 sizeof
1809 (struct rt_ht_capability_ie),
1810 &pAd->CommonCfg.
1811 HtCapability, 1,
1812 &AddHtInfoIe, 1,
1813 &AddHtLen,
1814 sizeof
1815 (struct rt_add_ht_info_ie),
1816 &pAd->CommonCfg.
1817 AddHTInfo, 1,
1818 &NewExtChanIe, 1,
1819 &NewExtLen,
1820 sizeof
1821 (struct rt_new_ext_chan_ie),
1822 &pAd->CommonCfg.
1823 NewExtChanOffset,
1824 END_OF_ARGS);
1825 }
1826 FrameLen += TmpLen;
1827 }
1828
1829 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
1830 MlmeFreeMemory(pAd, pOutBuffer);
1831 }
1832 }
1833}
1834
1835void BeaconTimeoutAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1836{
1837 u16 Status;
1838 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BeaconTimeoutAtJoinAction\n"));
1839 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1840 Status = MLME_REJ_TIMEOUT;
1841 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
1842}
1843
1844/*
1845 ==========================================================================
1846 Description:
1847 Scan timeout procedure. basically add channel index by 1 and rescan
1848 ==========================================================================
1849 */
1850void ScanTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1851{
1852 pAd->MlmeAux.Channel = NextChannel(pAd, pAd->MlmeAux.Channel);
1853
1854 /* Only one channel scanned for CISCO beacon request */
1855 if ((pAd->MlmeAux.ScanType == SCAN_CISCO_ACTIVE) ||
1856 (pAd->MlmeAux.ScanType == SCAN_CISCO_PASSIVE) ||
1857 (pAd->MlmeAux.ScanType == SCAN_CISCO_NOISE) ||
1858 (pAd->MlmeAux.ScanType == SCAN_CISCO_CHANNEL_LOAD))
1859 pAd->MlmeAux.Channel = 0;
1860
1861 /* this routine will stop if pAd->MlmeAux.Channel == 0 */
1862 ScanNextChannel(pAd);
1863}
1864
1865/*
1866 ==========================================================================
1867 Description:
1868 ==========================================================================
1869 */
1870void InvalidStateWhenScan(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1871{
1872 u16 Status;
1873 DBGPRINT(RT_DEBUG_TRACE,
1874 ("AYNC - InvalidStateWhenScan(state=%ld). Reset SYNC machine\n",
1875 pAd->Mlme.SyncMachine.CurrState));
1876 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1877 Status = MLME_STATE_MACHINE_REJECT;
1878 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
1879}
1880
1881/*
1882 ==========================================================================
1883 Description:
1884 ==========================================================================
1885 */
1886void InvalidStateWhenJoin(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1887{
1888 u16 Status;
1889 DBGPRINT(RT_DEBUG_TRACE,
1890 ("InvalidStateWhenJoin(state=%ld). Reset SYNC machine\n",
1891 pAd->Mlme.SyncMachine.CurrState));
1892 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1893 Status = MLME_STATE_MACHINE_REJECT;
1894 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
1895}
1896
1897/*
1898 ==========================================================================
1899 Description:
1900 ==========================================================================
1901 */
1902void InvalidStateWhenStart(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1903{
1904 u16 Status;
1905 DBGPRINT(RT_DEBUG_TRACE,
1906 ("InvalidStateWhenStart(state=%ld). Reset SYNC machine\n",
1907 pAd->Mlme.SyncMachine.CurrState));
1908 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1909 Status = MLME_STATE_MACHINE_REJECT;
1910 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
1911}
1912
1913/*
1914 ==========================================================================
1915 Description:
1916
1917 IRQL = DISPATCH_LEVEL
1918
1919 ==========================================================================
1920 */
1921void EnqueuePsPoll(struct rt_rtmp_adapter *pAd)
1922{
1923
1924 if (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeLegacy_PSP)
1925 pAd->PsPollFrame.FC.PwrMgmt = PWR_SAVE;
1926 MiniportMMRequest(pAd, 0, (u8 *)& pAd->PsPollFrame,
1927 sizeof(struct rt_pspoll_frame));
1928}
1929
1930/*
1931 ==========================================================================
1932 Description:
1933 ==========================================================================
1934 */
1935void EnqueueProbeRequest(struct rt_rtmp_adapter *pAd)
1936{
1937 int NState;
1938 u8 *pOutBuffer;
1939 unsigned long FrameLen = 0;
1940 struct rt_header_802_11 Hdr80211;
1941
1942 DBGPRINT(RT_DEBUG_TRACE, ("force out a ProbeRequest ...\n"));
1943
1944 NState = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
1945 if (NState == NDIS_STATUS_SUCCESS) {
1946 MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0,
1947 BROADCAST_ADDR, BROADCAST_ADDR);
1948
1949 /* this ProbeRequest explicitly specify SSID to reduce unwanted ProbeResponse */
1950 MakeOutgoingFrame(pOutBuffer, &FrameLen,
1951 sizeof(struct rt_header_802_11), &Hdr80211,
1952 1, &SsidIe,
1953 1, &pAd->CommonCfg.SsidLen,
1954 pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
1955 1, &SupRateIe,
1956 1, &pAd->StaActive.SupRateLen,
1957 pAd->StaActive.SupRateLen,
1958 pAd->StaActive.SupRate, END_OF_ARGS);
1959 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
1960 MlmeFreeMemory(pAd, pOutBuffer);
1961 }
1962
1963}
1964
1965BOOLEAN ScanRunning(struct rt_rtmp_adapter *pAd)
1966{
1967 return (pAd->Mlme.SyncMachine.CurrState == SCAN_LISTEN) ? TRUE : FALSE;
1968}
diff --git a/drivers/staging/rt2860/sta/wpa.c b/drivers/staging/rt2860/sta/wpa.c
deleted file mode 100644
index ff348325028..00000000000
--- a/drivers/staging/rt2860/sta/wpa.c
+++ /dev/null
@@ -1,374 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 wpa.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Jan Lee 03-07-22 Initial
36 Paul Lin 03-11-28 Modify for supplicant
37 Justin P. Mattock 11/07/2010 Fix typos
38*/
39#include "../rt_config.h"
40
41void inc_byte_array(u8 * counter, int len);
42
43/*
44 ========================================================================
45
46 Routine Description:
47 Process MIC error indication and record MIC error timer.
48
49 Arguments:
50 pAd Pointer to our adapter
51 pWpaKey Pointer to the WPA key structure
52
53 Return Value:
54 None
55
56 IRQL = DISPATCH_LEVEL
57
58 Note:
59
60 ========================================================================
61*/
62void RTMPReportMicError(struct rt_rtmp_adapter *pAd, struct rt_cipher_key *pWpaKey)
63{
64 unsigned long Now;
65 u8 unicastKey = (pWpaKey->Type == PAIRWISE_KEY ? 1 : 0);
66
67 /* Record Last MIC error time and count */
68 NdisGetSystemUpTime(&Now);
69 if (pAd->StaCfg.MicErrCnt == 0) {
70 pAd->StaCfg.MicErrCnt++;
71 pAd->StaCfg.LastMicErrorTime = Now;
72 NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
73 } else if (pAd->StaCfg.MicErrCnt == 1) {
74 if ((pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ)) < Now) {
75 /* Update Last MIC error time, this did not violate two MIC errors within 60 seconds */
76 pAd->StaCfg.LastMicErrorTime = Now;
77 } else {
78
79 if (pAd->CommonCfg.bWirelessEvent)
80 RTMPSendWirelessEvent(pAd,
81 IW_COUNTER_MEASURES_EVENT_FLAG,
82 pAd->MacTab.
83 Content[BSSID_WCID].Addr,
84 BSS0, 0);
85
86 pAd->StaCfg.LastMicErrorTime = Now;
87 /* Violate MIC error counts, MIC countermeasures kicks in */
88 pAd->StaCfg.MicErrCnt++;
89 /* We shall block all reception */
90 /* We shall clean all Tx ring and disassociate from AP after next EAPOL frame */
91 /* */
92 /* No necessary to clean all Tx ring, on RTMPHardTransmit will stop sending non-802.1X EAPOL packets */
93 /* if pAd->StaCfg.MicErrCnt greater than 2. */
94 /* */
95 /* RTMPRingCleanUp(pAd, QID_AC_BK); */
96 /* RTMPRingCleanUp(pAd, QID_AC_BE); */
97 /* RTMPRingCleanUp(pAd, QID_AC_VI); */
98 /* RTMPRingCleanUp(pAd, QID_AC_VO); */
99 /* RTMPRingCleanUp(pAd, QID_HCCA); */
100 }
101 } else {
102 /* MIC error count >= 2 */
103 /* This should not happen */
104 ;
105 }
106 MlmeEnqueue(pAd,
107 MLME_CNTL_STATE_MACHINE,
108 OID_802_11_MIC_FAILURE_REPORT_FRAME, 1, &unicastKey);
109
110 if (pAd->StaCfg.MicErrCnt == 2) {
111 RTMPSetTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, 100);
112 }
113}
114
115#define LENGTH_EAP_H 4
116/* If the received frame is EAP-Packet ,find out its EAP-Code (Request(0x01), Response(0x02), Success(0x03), Failure(0x04)). */
117int WpaCheckEapCode(struct rt_rtmp_adapter *pAd,
118 u8 *pFrame, u16 FrameLen, u16 OffSet)
119{
120
121 u8 *pData;
122 int result = 0;
123
124 if (FrameLen < OffSet + LENGTH_EAPOL_H + LENGTH_EAP_H)
125 return result;
126
127 pData = pFrame + OffSet; /* skip offset bytes */
128
129 if (*(pData + 1) == EAPPacket) /* 802.1x header - Packet Type */
130 {
131 result = *(pData + 4); /* EAP header - Code */
132 }
133
134 return result;
135}
136
137void WpaSendMicFailureToWpaSupplicant(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUnicast)
138{
139 char custom[IW_CUSTOM_MAX] = { 0 };
140
141 sprintf(custom, "MLME-MICHAELMICFAILURE.indication");
142 if (bUnicast)
143 sprintf(custom, "%s unicast", custom);
144
145 RtmpOSWrielessEventSend(pAd, IWEVCUSTOM, -1, NULL, (u8 *)custom,
146 strlen(custom));
147
148 return;
149}
150
151void WpaMicFailureReportFrame(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
152{
153 u8 *pOutBuffer = NULL;
154 u8 Header802_3[14];
155 unsigned long FrameLen = 0;
156 struct rt_eapol_packet Packet;
157 u8 Mic[16];
158 BOOLEAN bUnicast;
159
160 DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame ----->\n"));
161
162 bUnicast = (Elem->Msg[0] == 1 ? TRUE : FALSE);
163 pAd->Sequence = ((pAd->Sequence) + 1) & (MAX_SEQ_NUMBER);
164
165 /* init 802.3 header and Fill Packet */
166 MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid,
167 pAd->CurrentAddress, EAPOL);
168
169 NdisZeroMemory(&Packet, sizeof(Packet));
170 Packet.ProVer = EAPOL_VER;
171 Packet.ProType = EAPOLKey;
172
173 Packet.KeyDesc.Type = WPA1_KEY_DESC;
174
175 /* Request field presented */
176 Packet.KeyDesc.KeyInfo.Request = 1;
177
178 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) {
179 Packet.KeyDesc.KeyInfo.KeyDescVer = 2;
180 } else /* TKIP */
181 {
182 Packet.KeyDesc.KeyInfo.KeyDescVer = 1;
183 }
184
185 Packet.KeyDesc.KeyInfo.KeyType = (bUnicast ? PAIRWISEKEY : GROUPKEY);
186
187 /* KeyMic field presented */
188 Packet.KeyDesc.KeyInfo.KeyMic = 1;
189
190 /* Error field presented */
191 Packet.KeyDesc.KeyInfo.Error = 1;
192
193 /* Update packet length after decide Key data payload */
194 SET_u16_TO_ARRARY(Packet.Body_Len, LEN_EAPOL_KEY_MSG)
195 /* Key Replay Count */
196 NdisMoveMemory(Packet.KeyDesc.ReplayCounter,
197 pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY);
198 inc_byte_array(pAd->StaCfg.ReplayCounter, 8);
199
200 /* Convert to little-endian format. */
201 *((u16 *) & Packet.KeyDesc.KeyInfo) =
202 cpu2le16(*((u16 *) & Packet.KeyDesc.KeyInfo));
203
204 MlmeAllocateMemory(pAd, (u8 **) & pOutBuffer); /* allocate memory */
205 if (pOutBuffer == NULL) {
206 return;
207 }
208 /* Prepare EAPOL frame for MIC calculation */
209 /* Be careful, only EAPOL frame is counted for MIC calculation */
210 MakeOutgoingFrame(pOutBuffer, &FrameLen,
211 CONV_ARRARY_TO_u16(Packet.Body_Len) + 4, &Packet,
212 END_OF_ARGS);
213
214 /* Prepare and Fill MIC value */
215 NdisZeroMemory(Mic, sizeof(Mic));
216 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) { /* AES */
217 u8 digest[20] = { 0 };
218 HMAC_SHA1(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen,
219 digest, SHA1_DIGEST_SIZE);
220 NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC);
221 } else { /* TKIP */
222 HMAC_MD5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen,
223 Mic, MD5_DIGEST_SIZE);
224 }
225 NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC);
226
227 /* copy frame to Tx ring and send MIC failure report frame to authenticator */
228 RTMPToWirelessSta(pAd, &pAd->MacTab.Content[BSSID_WCID],
229 Header802_3, LENGTH_802_3,
230 (u8 *)& Packet,
231 CONV_ARRARY_TO_u16(Packet.Body_Len) + 4, FALSE);
232
233 MlmeFreeMemory(pAd, (u8 *)pOutBuffer);
234
235 DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame <-----\n"));
236}
237
238/** from wpa_supplicant
239 * inc_byte_array - Increment arbitrary length byte array by one
240 * @counter: Pointer to byte array
241 * @len: Length of the counter in bytes
242 *
243 * This function increments the last byte of the counter by one and continues
244 * rolling over to more significant bytes if the byte was incremented from
245 * 0xff to 0x00.
246 */
247void inc_byte_array(u8 * counter, int len)
248{
249 int pos = len - 1;
250 while (pos >= 0) {
251 counter[pos]++;
252 if (counter[pos] != 0)
253 break;
254 pos--;
255 }
256}
257
258void WpaDisassocApAndBlockAssoc(void *SystemSpecific1,
259 void *FunctionContext,
260 void *SystemSpecific2,
261 void *SystemSpecific3)
262{
263 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
264 struct rt_mlme_disassoc_req DisassocReq;
265
266 /* disassoc from current AP first */
267 DBGPRINT(RT_DEBUG_TRACE,
268 ("RTMPReportMicError - disassociate with current AP after sending second continuous EAPOL frame\n"));
269 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid,
270 REASON_MIC_FAILURE);
271 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
272 sizeof(struct rt_mlme_disassoc_req), &DisassocReq);
273
274 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
275 pAd->StaCfg.bBlockAssoc = TRUE;
276}
277
278void WpaStaPairwiseKeySetting(struct rt_rtmp_adapter *pAd)
279{
280 struct rt_cipher_key *pSharedKey;
281 struct rt_mac_table_entry *pEntry;
282
283 pEntry = &pAd->MacTab.Content[BSSID_WCID];
284
285 /* Pairwise key shall use key#0 */
286 pSharedKey = &pAd->SharedKey[BSS0][0];
287
288 NdisMoveMemory(pAd->StaCfg.PTK, pEntry->PTK, LEN_PTK);
289
290 /* Prepare pair-wise key information into shared key table */
291 NdisZeroMemory(pSharedKey, sizeof(struct rt_cipher_key));
292 pSharedKey->KeyLen = LEN_TKIP_EK;
293 NdisMoveMemory(pSharedKey->Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);
294 NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.PTK[48],
295 LEN_TKIP_RXMICK);
296 NdisMoveMemory(pSharedKey->TxMic,
297 &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
298
299 /* Decide its ChiperAlg */
300 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
301 pSharedKey->CipherAlg = CIPHER_TKIP;
302 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
303 pSharedKey->CipherAlg = CIPHER_AES;
304 else
305 pSharedKey->CipherAlg = CIPHER_NONE;
306
307 /* Update these related information to struct rt_mac_table_entry */
308 NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32],
309 LEN_TKIP_EK);
310 NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48],
311 LEN_TKIP_RXMICK);
312 NdisMoveMemory(pEntry->PairwiseKey.TxMic,
313 &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);
314 pEntry->PairwiseKey.CipherAlg = pSharedKey->CipherAlg;
315
316 /* Update pairwise key information to ASIC Shared Key Table */
317 AsicAddSharedKeyEntry(pAd,
318 BSS0,
319 0,
320 pSharedKey->CipherAlg,
321 pSharedKey->Key,
322 pSharedKey->TxMic, pSharedKey->RxMic);
323
324 /* Update ASIC WCID attribute table and IVEIV table */
325 RTMPAddWcidAttributeEntry(pAd, BSS0, 0, pSharedKey->CipherAlg, pEntry);
326 STA_PORT_SECURED(pAd);
327 pAd->IndicateMediaState = NdisMediaStateConnected;
328
329 DBGPRINT(RT_DEBUG_TRACE,
330 ("%s : AID(%d) port secured\n", __func__, pEntry->Aid));
331
332}
333
334void WpaStaGroupKeySetting(struct rt_rtmp_adapter *pAd)
335{
336 struct rt_cipher_key *pSharedKey;
337
338 pSharedKey = &pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId];
339
340 /* Prepare pair-wise key information into shared key table */
341 NdisZeroMemory(pSharedKey, sizeof(struct rt_cipher_key));
342 pSharedKey->KeyLen = LEN_TKIP_EK;
343 NdisMoveMemory(pSharedKey->Key, pAd->StaCfg.GTK, LEN_TKIP_EK);
344 NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.GTK[16],
345 LEN_TKIP_RXMICK);
346 NdisMoveMemory(pSharedKey->TxMic, &pAd->StaCfg.GTK[24],
347 LEN_TKIP_TXMICK);
348
349 /* Update Shared Key CipherAlg */
350 pSharedKey->CipherAlg = CIPHER_NONE;
351 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
352 pSharedKey->CipherAlg = CIPHER_TKIP;
353 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
354 pSharedKey->CipherAlg = CIPHER_AES;
355 else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled)
356 pSharedKey->CipherAlg = CIPHER_WEP64;
357 else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
358 pSharedKey->CipherAlg = CIPHER_WEP128;
359
360 /* Update group key information to ASIC Shared Key Table */
361 AsicAddSharedKeyEntry(pAd,
362 BSS0,
363 pAd->StaCfg.DefaultKeyId,
364 pSharedKey->CipherAlg,
365 pSharedKey->Key,
366 pSharedKey->TxMic, pSharedKey->RxMic);
367
368 /* Update ASIC WCID attribute table and IVEIV table */
369 RTMPAddWcidAttributeEntry(pAd,
370 BSS0,
371 pAd->StaCfg.DefaultKeyId,
372 pSharedKey->CipherAlg, NULL);
373
374}
diff --git a/drivers/staging/rt2860/sta_ioctl.c b/drivers/staging/rt2860/sta_ioctl.c
deleted file mode 100644
index 49b1013e7a0..00000000000
--- a/drivers/staging/rt2860/sta_ioctl.c
+++ /dev/null
@@ -1,2912 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 sta_ioctl.c
29
30 Abstract:
31 IOCTL related subroutines
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Rory Chen 01-03-2003 created
37 Rory Chen 02-14-2005 modify to support RT61
38 Justin P. Mattock 11/07/2010 Fix typos
39*/
40
41#include "rt_config.h"
42
43#ifdef DBG
44extern unsigned long RTDebugLevel;
45#endif
46
47#define NR_WEP_KEYS 4
48#define WEP_SMALL_KEY_LEN (40/8)
49#define WEP_LARGE_KEY_LEN (104/8)
50
51#define GROUP_KEY_NO 4
52
53extern u8 CipherWpa2Template[];
54
55struct PACKED rt_version_info {
56 u8 DriverVersionW;
57 u8 DriverVersionX;
58 u8 DriverVersionY;
59 u8 DriverVersionZ;
60 u32 DriverBuildYear;
61 u32 DriverBuildMonth;
62 u32 DriverBuildDay;
63};
64
65static __s32 ralinkrate[] = { 2, 4, 11, 22, /* CCK */
66 12, 18, 24, 36, 48, 72, 96, 108, /* OFDM */
67 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, /* 20MHz, 800ns GI, MCS: 0 ~ 15 */
68 39, 78, 117, 156, 234, 312, 351, 390, /* 20MHz, 800ns GI, MCS: 16 ~ 23 */
69 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, /* 40MHz, 800ns GI, MCS: 0 ~ 15 */
70 81, 162, 243, 324, 486, 648, 729, 810, /* 40MHz, 800ns GI, MCS: 16 ~ 23 */
71 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, /* 20MHz, 400ns GI, MCS: 0 ~ 15 */
72 43, 87, 130, 173, 260, 317, 390, 433, /* 20MHz, 400ns GI, MCS: 16 ~ 23 */
73 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, /* 40MHz, 400ns GI, MCS: 0 ~ 15 */
74 90, 180, 270, 360, 540, 720, 810, 900
75};
76
77int Set_SSID_Proc(struct rt_rtmp_adapter *pAdapter, char *arg);
78
79int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg);
80
81void RTMPAddKey(struct rt_rtmp_adapter *pAd, struct rt_ndis_802_11_key *pKey)
82{
83 unsigned long KeyIdx;
84 struct rt_mac_table_entry *pEntry;
85
86 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
87
88 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) {
89 if (pKey->KeyIndex & 0x80000000) {
90 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) {
91 NdisZeroMemory(pAd->StaCfg.PMK, 32);
92 NdisMoveMemory(pAd->StaCfg.PMK,
93 pKey->KeyMaterial,
94 pKey->KeyLength);
95 goto end;
96 }
97 /* Update PTK */
98 NdisZeroMemory(&pAd->SharedKey[BSS0][0],
99 sizeof(struct rt_cipher_key));
100 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
101 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key,
102 pKey->KeyMaterial, LEN_TKIP_EK);
103
104 if (pAd->StaCfg.PairCipher ==
105 Ndis802_11Encryption2Enabled) {
106 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic,
107 pKey->KeyMaterial + LEN_TKIP_EK,
108 LEN_TKIP_TXMICK);
109 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic,
110 pKey->KeyMaterial + LEN_TKIP_EK +
111 LEN_TKIP_TXMICK,
112 LEN_TKIP_RXMICK);
113 } else {
114 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic,
115 pKey->KeyMaterial + LEN_TKIP_EK,
116 LEN_TKIP_TXMICK);
117 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic,
118 pKey->KeyMaterial + LEN_TKIP_EK +
119 LEN_TKIP_TXMICK,
120 LEN_TKIP_RXMICK);
121 }
122
123 /* Decide its ChiperAlg */
124 if (pAd->StaCfg.PairCipher ==
125 Ndis802_11Encryption2Enabled)
126 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
127 else if (pAd->StaCfg.PairCipher ==
128 Ndis802_11Encryption3Enabled)
129 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
130 else
131 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
132
133 /* Update these related information to struct rt_mac_table_entry */
134 pEntry = &pAd->MacTab.Content[BSSID_WCID];
135 NdisMoveMemory(pEntry->PairwiseKey.Key,
136 pAd->SharedKey[BSS0][0].Key,
137 LEN_TKIP_EK);
138 NdisMoveMemory(pEntry->PairwiseKey.RxMic,
139 pAd->SharedKey[BSS0][0].RxMic,
140 LEN_TKIP_RXMICK);
141 NdisMoveMemory(pEntry->PairwiseKey.TxMic,
142 pAd->SharedKey[BSS0][0].TxMic,
143 LEN_TKIP_TXMICK);
144 pEntry->PairwiseKey.CipherAlg =
145 pAd->SharedKey[BSS0][0].CipherAlg;
146
147 /* Update pairwise key information to ASIC Shared Key Table */
148 AsicAddSharedKeyEntry(pAd,
149 BSS0,
150 0,
151 pAd->SharedKey[BSS0][0].CipherAlg,
152 pAd->SharedKey[BSS0][0].Key,
153 pAd->SharedKey[BSS0][0].TxMic,
154 pAd->SharedKey[BSS0][0].RxMic);
155
156 /* Update ASIC WCID attribute table and IVEIV table */
157 RTMPAddWcidAttributeEntry(pAd,
158 BSS0,
159 0,
160 pAd->SharedKey[BSS0][0].
161 CipherAlg, pEntry);
162
163 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2) {
164 /* set 802.1x port control */
165 /*pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
166 STA_PORT_SECURED(pAd);
167
168 /* Indicate Connected for GUI */
169 pAd->IndicateMediaState =
170 NdisMediaStateConnected;
171 }
172 } else {
173 /* Update GTK */
174 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
175 NdisZeroMemory(&pAd->
176 SharedKey[BSS0][pAd->StaCfg.
177 DefaultKeyId],
178 sizeof(struct rt_cipher_key));
179 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen =
180 LEN_TKIP_EK;
181 NdisMoveMemory(pAd->
182 SharedKey[BSS0][pAd->StaCfg.
183 DefaultKeyId].Key,
184 pKey->KeyMaterial, LEN_TKIP_EK);
185
186 if (pAd->StaCfg.GroupCipher ==
187 Ndis802_11Encryption2Enabled) {
188 NdisMoveMemory(pAd->
189 SharedKey[BSS0][pAd->StaCfg.
190 DefaultKeyId].
191 RxMic,
192 pKey->KeyMaterial + LEN_TKIP_EK,
193 LEN_TKIP_TXMICK);
194 NdisMoveMemory(pAd->
195 SharedKey[BSS0][pAd->StaCfg.
196 DefaultKeyId].
197 TxMic,
198 pKey->KeyMaterial + LEN_TKIP_EK +
199 LEN_TKIP_TXMICK,
200 LEN_TKIP_RXMICK);
201 } else {
202 NdisMoveMemory(pAd->
203 SharedKey[BSS0][pAd->StaCfg.
204 DefaultKeyId].
205 TxMic,
206 pKey->KeyMaterial + LEN_TKIP_EK,
207 LEN_TKIP_TXMICK);
208 NdisMoveMemory(pAd->
209 SharedKey[BSS0][pAd->StaCfg.
210 DefaultKeyId].
211 RxMic,
212 pKey->KeyMaterial + LEN_TKIP_EK +
213 LEN_TKIP_TXMICK,
214 LEN_TKIP_RXMICK);
215 }
216
217 /* Update Shared Key CipherAlg */
218 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].
219 CipherAlg = CIPHER_NONE;
220 if (pAd->StaCfg.GroupCipher ==
221 Ndis802_11Encryption2Enabled)
222 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].
223 CipherAlg = CIPHER_TKIP;
224 else if (pAd->StaCfg.GroupCipher ==
225 Ndis802_11Encryption3Enabled)
226 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].
227 CipherAlg = CIPHER_AES;
228
229 /* Update group key information to ASIC Shared Key Table */
230 AsicAddSharedKeyEntry(pAd,
231 BSS0,
232 pAd->StaCfg.DefaultKeyId,
233 pAd->SharedKey[BSS0][pAd->StaCfg.
234 DefaultKeyId].
235 CipherAlg,
236 pAd->SharedKey[BSS0][pAd->StaCfg.
237 DefaultKeyId].
238 Key,
239 pAd->SharedKey[BSS0][pAd->StaCfg.
240 DefaultKeyId].
241 TxMic,
242 pAd->SharedKey[BSS0][pAd->StaCfg.
243 DefaultKeyId].
244 RxMic);
245
246 /* Update ASIC WCID attribute table and IVEIV table */
247 RTMPAddWcidAttributeEntry(pAd,
248 BSS0,
249 pAd->StaCfg.DefaultKeyId,
250 pAd->SharedKey[BSS0][pAd->
251 StaCfg.
252 DefaultKeyId].
253 CipherAlg, NULL);
254
255 /* set 802.1x port control */
256 /*pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
257 STA_PORT_SECURED(pAd);
258
259 /* Indicate Connected for GUI */
260 pAd->IndicateMediaState = NdisMediaStateConnected;
261 }
262 } else /* dynamic WEP from wpa_supplicant */
263 {
264 u8 CipherAlg;
265 u8 *Key;
266
267 if (pKey->KeyLength == 32)
268 goto end;
269
270 KeyIdx = pKey->KeyIndex & 0x0fffffff;
271
272 if (KeyIdx < 4) {
273 /* it is a default shared key, for Pairwise key setting */
274 if (pKey->KeyIndex & 0x80000000) {
275 pEntry = MacTableLookup(pAd, pKey->BSSID);
276
277 if (pEntry) {
278 DBGPRINT(RT_DEBUG_TRACE,
279 ("RTMPAddKey: Set Pair-wise Key\n"));
280
281 /* set key material and key length */
282 pEntry->PairwiseKey.KeyLen =
283 (u8)pKey->KeyLength;
284 NdisMoveMemory(pEntry->PairwiseKey.Key,
285 &pKey->KeyMaterial,
286 pKey->KeyLength);
287
288 /* set Cipher type */
289 if (pKey->KeyLength == 5)
290 pEntry->PairwiseKey.CipherAlg =
291 CIPHER_WEP64;
292 else
293 pEntry->PairwiseKey.CipherAlg =
294 CIPHER_WEP128;
295
296 /* Add Pair-wise key to Asic */
297 AsicAddPairwiseKeyEntry(pAd,
298 pEntry->Addr,
299 (u8)pEntry->
300 Aid,
301 &pEntry->
302 PairwiseKey);
303
304 /* update WCID attribute table and IVEIV table for this entry */
305 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, /* The value may be not zero */
306 pEntry->
307 PairwiseKey.
308 CipherAlg,
309 pEntry);
310
311 }
312 } else {
313 /* Default key for tx (shared key) */
314 pAd->StaCfg.DefaultKeyId = (u8)KeyIdx;
315
316 /* set key material and key length */
317 pAd->SharedKey[BSS0][KeyIdx].KeyLen =
318 (u8)pKey->KeyLength;
319 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key,
320 &pKey->KeyMaterial,
321 pKey->KeyLength);
322
323 /* Set Ciper type */
324 if (pKey->KeyLength == 5)
325 pAd->SharedKey[BSS0][KeyIdx].CipherAlg =
326 CIPHER_WEP64;
327 else
328 pAd->SharedKey[BSS0][KeyIdx].CipherAlg =
329 CIPHER_WEP128;
330
331 CipherAlg =
332 pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
333 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
334
335 /* Set Group key material to Asic */
336 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx,
337 CipherAlg, Key, NULL,
338 NULL);
339
340 /* Update WCID attribute table and IVEIV table for this group key table */
341 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx,
342 CipherAlg, NULL);
343
344 }
345 }
346 }
347end:
348 return;
349}
350
351char *rtstrchr(const char *s, int c)
352{
353 for (; *s != (char)c; ++s)
354 if (*s == '\0')
355 return NULL;
356 return (char *)s;
357}
358
359/*
360This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
361*/
362
363int
364rt_ioctl_giwname(struct net_device *dev,
365 struct iw_request_info *info, char *name, char *extra)
366{
367 strncpy(name, "Ralink STA", IFNAMSIZ);
368 /* RT2870 2.1.0.0 uses "RT2870 Wireless" */
369 /* RT3090 2.1.0.0 uses "RT2860 Wireless" */
370 return 0;
371}
372
373int rt_ioctl_siwfreq(struct net_device *dev,
374 struct iw_request_info *info,
375 struct iw_freq *freq, char *extra)
376{
377 struct rt_rtmp_adapter *pAdapter = NULL;
378 int chan = -1;
379
380 GET_PAD_FROM_NET_DEV(pAdapter, dev);
381
382 /*check if the interface is down */
383 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
384 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
385 return -ENETDOWN;
386 }
387
388 if (freq->e > 1)
389 return -EINVAL;
390
391 if ((freq->e == 0) && (freq->m <= 1000))
392 chan = freq->m; /* Setting by channel number */
393 else
394 MAP_KHZ_TO_CHANNEL_ID((freq->m / 100), chan); /* Setting by frequency - search the table , like 2.412G, 2.422G, */
395
396 if (ChannelSanity(pAdapter, chan) == TRUE) {
397 pAdapter->CommonCfg.Channel = chan;
398 DBGPRINT(RT_DEBUG_ERROR,
399 ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n",
400 SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
401 } else
402 return -EINVAL;
403
404 return 0;
405}
406
407int rt_ioctl_giwfreq(struct net_device *dev,
408 struct iw_request_info *info,
409 struct iw_freq *freq, char *extra)
410{
411 struct rt_rtmp_adapter *pAdapter = NULL;
412 u8 ch;
413 unsigned long m = 2412000;
414
415 GET_PAD_FROM_NET_DEV(pAdapter, dev);
416
417 ch = pAdapter->CommonCfg.Channel;
418
419 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwfreq %d\n", ch));
420
421 MAP_CHANNEL_ID_TO_KHZ(ch, m);
422 freq->m = m * 100;
423 freq->e = 1;
424 return 0;
425}
426
427int rt_ioctl_siwmode(struct net_device *dev,
428 struct iw_request_info *info, __u32 * mode, char *extra)
429{
430 struct rt_rtmp_adapter *pAdapter = NULL;
431
432 GET_PAD_FROM_NET_DEV(pAdapter, dev);
433
434 /*check if the interface is down */
435 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
436 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
437 return -ENETDOWN;
438 }
439
440 switch (*mode) {
441 case IW_MODE_ADHOC:
442 Set_NetworkType_Proc(pAdapter, "Adhoc");
443 break;
444 case IW_MODE_INFRA:
445 Set_NetworkType_Proc(pAdapter, "Infra");
446 break;
447 case IW_MODE_MONITOR:
448 Set_NetworkType_Proc(pAdapter, "Monitor");
449 break;
450 default:
451 DBGPRINT(RT_DEBUG_TRACE,
452 ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n",
453 *mode));
454 return -EINVAL;
455 }
456
457 /* Reset Ralink supplicant to not use, it will be set to start when UI set PMK key */
458 pAdapter->StaCfg.WpaState = SS_NOTUSE;
459
460 return 0;
461}
462
463int rt_ioctl_giwmode(struct net_device *dev,
464 struct iw_request_info *info, __u32 * mode, char *extra)
465{
466 struct rt_rtmp_adapter *pAdapter = NULL;
467
468 GET_PAD_FROM_NET_DEV(pAdapter, dev);
469
470 if (ADHOC_ON(pAdapter))
471 *mode = IW_MODE_ADHOC;
472 else if (INFRA_ON(pAdapter))
473 *mode = IW_MODE_INFRA;
474 else if (MONITOR_ON(pAdapter)) {
475 *mode = IW_MODE_MONITOR;
476 } else
477 *mode = IW_MODE_AUTO;
478
479 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
480 return 0;
481}
482
483int rt_ioctl_siwsens(struct net_device *dev,
484 struct iw_request_info *info, char *name, char *extra)
485{
486 struct rt_rtmp_adapter *pAdapter = NULL;
487
488 GET_PAD_FROM_NET_DEV(pAdapter, dev);
489
490 /*check if the interface is down */
491 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
492 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
493 return -ENETDOWN;
494 }
495
496 return 0;
497}
498
499int rt_ioctl_giwsens(struct net_device *dev,
500 struct iw_request_info *info, char *name, char *extra)
501{
502 return 0;
503}
504
505int rt_ioctl_giwrange(struct net_device *dev,
506 struct iw_request_info *info,
507 struct iw_point *data, char *extra)
508{
509 struct rt_rtmp_adapter *pAdapter = NULL;
510 struct iw_range *range = (struct iw_range *)extra;
511 u16 val;
512 int i;
513
514 GET_PAD_FROM_NET_DEV(pAdapter, dev);
515
516 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwrange\n"));
517 data->length = sizeof(struct iw_range);
518 memset(range, 0, sizeof(struct iw_range));
519
520 range->txpower_capa = IW_TXPOW_DBM;
521
522 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter)) {
523 range->min_pmp = 1 * 1024;
524 range->max_pmp = 65535 * 1024;
525 range->min_pmt = 1 * 1024;
526 range->max_pmt = 1000 * 1024;
527 range->pmp_flags = IW_POWER_PERIOD;
528 range->pmt_flags = IW_POWER_TIMEOUT;
529 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
530 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
531 }
532
533 range->we_version_compiled = WIRELESS_EXT;
534 range->we_version_source = 14;
535
536 range->retry_capa = IW_RETRY_LIMIT;
537 range->retry_flags = IW_RETRY_LIMIT;
538 range->min_retry = 0;
539 range->max_retry = 255;
540
541 range->num_channels = pAdapter->ChannelListNum;
542
543 val = 0;
544 for (i = 1; i <= range->num_channels; i++) {
545 u32 m = 2412000;
546 range->freq[val].i = pAdapter->ChannelList[i - 1].Channel;
547 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i - 1].Channel, m);
548 range->freq[val].m = m * 100; /* OS_HZ */
549
550 range->freq[val].e = 1;
551 val++;
552 if (val == IW_MAX_FREQUENCIES)
553 break;
554 }
555 range->num_frequency = val;
556
557 range->max_qual.qual = 100; /* what is correct max? This was not
558 * documented exactly. At least
559 * 69 has been observed. */
560 range->max_qual.level = 0; /* dB */
561 range->max_qual.noise = 0; /* dB */
562
563 /* What would be suitable values for "average/typical" qual? */
564 range->avg_qual.qual = 20;
565 range->avg_qual.level = -60;
566 range->avg_qual.noise = -95;
567 range->sensitivity = 3;
568
569 range->max_encoding_tokens = NR_WEP_KEYS;
570 range->num_encoding_sizes = 2;
571 range->encoding_size[0] = 5;
572 range->encoding_size[1] = 13;
573
574 range->min_rts = 0;
575 range->max_rts = 2347;
576 range->min_frag = 256;
577 range->max_frag = 2346;
578
579 /* IW_ENC_CAPA_* bit field */
580 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
581 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
582
583 return 0;
584}
585
586int rt_ioctl_siwap(struct net_device *dev,
587 struct iw_request_info *info,
588 struct sockaddr *ap_addr, char *extra)
589{
590 struct rt_rtmp_adapter *pAdapter = NULL;
591 NDIS_802_11_MAC_ADDRESS Bssid;
592
593 GET_PAD_FROM_NET_DEV(pAdapter, dev);
594
595 /*check if the interface is down */
596 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
597 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
598 return -ENETDOWN;
599 }
600
601 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) {
602 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
603 DBGPRINT(RT_DEBUG_TRACE,
604 ("MLME busy, reset MLME state machine!\n"));
605 }
606 /* tell CNTL state machine to call NdisMSetInformationComplete() after completing */
607 /* this request, because this request is initiated by NDIS. */
608 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
609 /* Prevent to connect AP again in STAMlmePeriodicExec */
610 pAdapter->MlmeAux.AutoReconnectSsidLen = 32;
611
612 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
613 MlmeEnqueue(pAdapter,
614 MLME_CNTL_STATE_MACHINE,
615 OID_802_11_BSSID,
616 sizeof(NDIS_802_11_MAC_ADDRESS), (void *) & Bssid);
617
618 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %pM\n", Bssid));
619
620 return 0;
621}
622
623int rt_ioctl_giwap(struct net_device *dev,
624 struct iw_request_info *info,
625 struct sockaddr *ap_addr, char *extra)
626{
627 struct rt_rtmp_adapter *pAdapter = NULL;
628
629 GET_PAD_FROM_NET_DEV(pAdapter, dev);
630
631 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter)) {
632 ap_addr->sa_family = ARPHRD_ETHER;
633 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
634 }
635 /* Add for RT2870 */
636 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) {
637 ap_addr->sa_family = ARPHRD_ETHER;
638 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
639 } else {
640 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
641 return -ENOTCONN;
642 }
643
644 return 0;
645}
646
647/*
648 * Units are in db above the noise floor. That means the
649 * rssi values reported in the tx/rx descriptors in the
650 * driver are the SNR expressed in db.
651 *
652 * If you assume that the noise floor is -95, which is an
653 * excellent assumption 99.5 % of the time, then you can
654 * derive the absolute signal level (i.e. -95 + rssi).
655 * There are some other slight factors to take into account
656 * depending on whether the rssi measurement is from 11b,
657 * 11g, or 11a. These differences are at most 2db and
658 * can be documented.
659 *
660 * NB: various calculations are based on the orinoco/wavelan
661 * drivers for compatibility
662 */
663static void set_quality(struct rt_rtmp_adapter *pAdapter,
664 struct iw_quality *iq, signed char rssi)
665{
666 __u8 ChannelQuality;
667
668 /* Normalize Rssi */
669 if (rssi >= -50)
670 ChannelQuality = 100;
671 else if (rssi >= -80) /* between -50 ~ -80dbm */
672 ChannelQuality = (__u8) (24 + ((rssi + 80) * 26) / 10);
673 else if (rssi >= -90) /* between -80 ~ -90dbm */
674 ChannelQuality = (__u8) ((rssi + 90) * 26) / 10;
675 else
676 ChannelQuality = 0;
677
678 iq->qual = (__u8) ChannelQuality;
679
680 iq->level = (__u8) (rssi);
681 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8) pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); /* noise level (dBm) */
682 iq->noise += 256 - 143;
683 iq->updated = pAdapter->iw_stats.qual.updated;
684}
685
686int rt_ioctl_iwaplist(struct net_device *dev,
687 struct iw_request_info *info,
688 struct iw_point *data, char *extra)
689{
690 struct rt_rtmp_adapter *pAdapter = NULL;
691
692 struct sockaddr addr[IW_MAX_AP];
693 struct iw_quality qual[IW_MAX_AP];
694 int i;
695
696 GET_PAD_FROM_NET_DEV(pAdapter, dev);
697
698 /*check if the interface is down */
699 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
700 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
701 data->length = 0;
702 return 0;
703 /*return -ENETDOWN; */
704 }
705
706 for (i = 0; i < IW_MAX_AP; i++) {
707 if (i >= pAdapter->ScanTab.BssNr)
708 break;
709 addr[i].sa_family = ARPHRD_ETHER;
710 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid,
711 MAC_ADDR_LEN);
712 set_quality(pAdapter, &qual[i],
713 pAdapter->ScanTab.BssEntry[i].Rssi);
714 }
715 data->length = i;
716 memcpy(extra, &addr, i * sizeof(addr[0]));
717 data->flags = 1; /* signal quality present (sort of) */
718 memcpy(extra + i * sizeof(addr[0]), &qual, i * sizeof(qual[i]));
719
720 return 0;
721}
722
723int rt_ioctl_siwscan(struct net_device *dev,
724 struct iw_request_info *info,
725 struct iw_point *data, char *extra)
726{
727 struct rt_rtmp_adapter *pAdapter = NULL;
728
729 unsigned long Now;
730 int Status = NDIS_STATUS_SUCCESS;
731
732 GET_PAD_FROM_NET_DEV(pAdapter, dev);
733
734 /*check if the interface is down */
735 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
736 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
737 return -ENETDOWN;
738 }
739
740 if (MONITOR_ON(pAdapter)) {
741 DBGPRINT(RT_DEBUG_TRACE,
742 ("Driver is in Monitor Mode now!\n"));
743 return -EINVAL;
744 }
745
746 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) {
747 pAdapter->StaCfg.WpaSupplicantScanCount++;
748 }
749
750 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
751 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
752 return NDIS_STATUS_SUCCESS;
753 do {
754 Now = jiffies;
755
756 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
757 && (pAdapter->StaCfg.WpaSupplicantScanCount > 3)) {
758 DBGPRINT(RT_DEBUG_TRACE,
759 ("WpaSupplicantScanCount > 3\n"));
760 Status = NDIS_STATUS_SUCCESS;
761 break;
762 }
763
764 if ((OPSTATUS_TEST_FLAG
765 (pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
766 && ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA)
767 || (pAdapter->StaCfg.AuthMode ==
768 Ndis802_11AuthModeWPAPSK))
769 && (pAdapter->StaCfg.PortSecured ==
770 WPA_802_1X_PORT_NOT_SECURED)) {
771 DBGPRINT(RT_DEBUG_TRACE,
772 ("Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
773 Status = NDIS_STATUS_SUCCESS;
774 break;
775 }
776
777 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) {
778 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
779 DBGPRINT(RT_DEBUG_TRACE,
780 ("MLME busy, reset MLME state machine!\n"));
781 }
782 /* tell CNTL state machine to call NdisMSetInformationComplete() after completing */
783 /* this request, because this request is initiated by NDIS. */
784 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
785 /* Reset allowed scan retries */
786 pAdapter->StaCfg.ScanCnt = 0;
787 pAdapter->StaCfg.LastScanTime = Now;
788
789 MlmeEnqueue(pAdapter,
790 MLME_CNTL_STATE_MACHINE,
791 OID_802_11_BSSID_LIST_SCAN, 0, NULL);
792
793 Status = NDIS_STATUS_SUCCESS;
794 RTMP_MLME_HANDLER(pAdapter);
795 } while (0);
796 return NDIS_STATUS_SUCCESS;
797}
798
799int rt_ioctl_giwscan(struct net_device *dev,
800 struct iw_request_info *info,
801 struct iw_point *data, char *extra)
802{
803 struct rt_rtmp_adapter *pAdapter = NULL;
804 int i = 0;
805 char *current_ev = extra, *previous_ev = extra;
806 char *end_buf;
807 char *current_val;
808 char custom[MAX_CUSTOM_LEN] = { 0 };
809 struct iw_event iwe;
810
811 GET_PAD_FROM_NET_DEV(pAdapter, dev);
812
813 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) {
814 /*
815 * Still scanning, indicate the caller should try again.
816 */
817 return -EAGAIN;
818 }
819
820 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) {
821 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
822 }
823
824 if (pAdapter->ScanTab.BssNr == 0) {
825 data->length = 0;
826 return 0;
827 }
828
829 if (data->length > 0)
830 end_buf = extra + data->length;
831 else
832 end_buf = extra + IW_SCAN_MAX_DATA;
833
834 for (i = 0; i < pAdapter->ScanTab.BssNr; i++) {
835 if (current_ev >= end_buf) {
836 return -E2BIG;
837 }
838 /*MAC address */
839 /*================================ */
840 memset(&iwe, 0, sizeof(iwe));
841 iwe.cmd = SIOCGIWAP;
842 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
843 memcpy(iwe.u.ap_addr.sa_data,
844 &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
845
846 previous_ev = current_ev;
847 current_ev =
848 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
849 IW_EV_ADDR_LEN);
850 if (current_ev == previous_ev)
851 return -E2BIG;
852
853 /*
854 Protocol:
855 it will show scanned AP's WirelessMode.
856 it might be
857 802.11a
858 802.11a/n
859 802.11g/n
860 802.11b/g/n
861 802.11g
862 802.11b/g
863 */
864 memset(&iwe, 0, sizeof(iwe));
865 iwe.cmd = SIOCGIWNAME;
866
867 {
868 struct rt_bss_entry *pBssEntry = &pAdapter->ScanTab.BssEntry[i];
869 BOOLEAN isGonly = FALSE;
870 int rateCnt = 0;
871
872 if (pBssEntry->Channel > 14) {
873 if (pBssEntry->HtCapabilityLen != 0)
874 strcpy(iwe.u.name, "802.11a/n");
875 else
876 strcpy(iwe.u.name, "802.11a");
877 } else {
878 /*
879 if one of non B mode rate is set supported rate, it means G only.
880 */
881 for (rateCnt = 0;
882 rateCnt < pBssEntry->SupRateLen;
883 rateCnt++) {
884 /*
885 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate, it means G only.
886 */
887 if (pBssEntry->SupRate[rateCnt] == 140
888 || pBssEntry->SupRate[rateCnt] ==
889 146
890 || pBssEntry->SupRate[rateCnt] >=
891 152)
892 isGonly = TRUE;
893 }
894
895 for (rateCnt = 0;
896 rateCnt < pBssEntry->ExtRateLen;
897 rateCnt++) {
898 if (pBssEntry->ExtRate[rateCnt] == 140
899 || pBssEntry->ExtRate[rateCnt] ==
900 146
901 || pBssEntry->ExtRate[rateCnt] >=
902 152)
903 isGonly = TRUE;
904 }
905
906 if (pBssEntry->HtCapabilityLen != 0) {
907 if (isGonly == TRUE)
908 strcpy(iwe.u.name, "802.11g/n");
909 else
910 strcpy(iwe.u.name,
911 "802.11b/g/n");
912 } else {
913 if (isGonly == TRUE)
914 strcpy(iwe.u.name, "802.11g");
915 else {
916 if (pBssEntry->SupRateLen == 4
917 && pBssEntry->ExtRateLen ==
918 0)
919 strcpy(iwe.u.name,
920 "802.11b");
921 else
922 strcpy(iwe.u.name,
923 "802.11b/g");
924 }
925 }
926 }
927 }
928
929 previous_ev = current_ev;
930 current_ev =
931 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
932 IW_EV_ADDR_LEN);
933 if (current_ev == previous_ev)
934 return -E2BIG;
935
936 /*ESSID */
937 /*================================ */
938 memset(&iwe, 0, sizeof(iwe));
939 iwe.cmd = SIOCGIWESSID;
940 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
941 iwe.u.data.flags = 1;
942
943 previous_ev = current_ev;
944 current_ev =
945 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
946 (char *)pAdapter->ScanTab.
947 BssEntry[i].Ssid);
948 if (current_ev == previous_ev)
949 return -E2BIG;
950
951 /*Network Type */
952 /*================================ */
953 memset(&iwe, 0, sizeof(iwe));
954 iwe.cmd = SIOCGIWMODE;
955 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS) {
956 iwe.u.mode = IW_MODE_ADHOC;
957 } else if (pAdapter->ScanTab.BssEntry[i].BssType ==
958 Ndis802_11Infrastructure) {
959 iwe.u.mode = IW_MODE_INFRA;
960 } else {
961 iwe.u.mode = IW_MODE_AUTO;
962 }
963 iwe.len = IW_EV_UINT_LEN;
964
965 previous_ev = current_ev;
966 current_ev =
967 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
968 IW_EV_UINT_LEN);
969 if (current_ev == previous_ev)
970 return -E2BIG;
971
972 /*Channel and Frequency */
973 /*================================ */
974 memset(&iwe, 0, sizeof(iwe));
975 iwe.cmd = SIOCGIWFREQ;
976 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
977 iwe.u.freq.e = 0;
978 iwe.u.freq.i = 0;
979
980 previous_ev = current_ev;
981 current_ev =
982 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
983 IW_EV_FREQ_LEN);
984 if (current_ev == previous_ev)
985 return -E2BIG;
986
987 /*Add quality statistics */
988 /*================================ */
989 memset(&iwe, 0, sizeof(iwe));
990 iwe.cmd = IWEVQUAL;
991 iwe.u.qual.level = 0;
992 iwe.u.qual.noise = 0;
993 set_quality(pAdapter, &iwe.u.qual,
994 pAdapter->ScanTab.BssEntry[i].Rssi);
995 current_ev =
996 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
997 IW_EV_QUAL_LEN);
998 if (current_ev == previous_ev)
999 return -E2BIG;
1000
1001 /*Encyption key */
1002 /*================================ */
1003 memset(&iwe, 0, sizeof(iwe));
1004 iwe.cmd = SIOCGIWENCODE;
1005 if (CAP_IS_PRIVACY_ON
1006 (pAdapter->ScanTab.BssEntry[i].CapabilityInfo))
1007 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1008 else
1009 iwe.u.data.flags = IW_ENCODE_DISABLED;
1010
1011 previous_ev = current_ev;
1012 current_ev =
1013 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1014 (char *)pAdapter->
1015 SharedKey[BSS0][(iwe.u.data.
1016 flags &
1017 IW_ENCODE_INDEX) -
1018 1].Key);
1019 if (current_ev == previous_ev)
1020 return -E2BIG;
1021
1022 /*Bit Rate */
1023 /*================================ */
1024 if (pAdapter->ScanTab.BssEntry[i].SupRateLen) {
1025 u8 tmpRate =
1026 pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->
1027 ScanTab.
1028 BssEntry[i].
1029 SupRateLen -
1030 1];
1031 memset(&iwe, 0, sizeof(iwe));
1032 iwe.cmd = SIOCGIWRATE;
1033 current_val = current_ev + IW_EV_LCP_LEN;
1034 if (tmpRate == 0x82)
1035 iwe.u.bitrate.value = 1 * 1000000;
1036 else if (tmpRate == 0x84)
1037 iwe.u.bitrate.value = 2 * 1000000;
1038 else if (tmpRate == 0x8B)
1039 iwe.u.bitrate.value = 5.5 * 1000000;
1040 else if (tmpRate == 0x96)
1041 iwe.u.bitrate.value = 11 * 1000000;
1042 else
1043 iwe.u.bitrate.value = (tmpRate / 2) * 1000000;
1044
1045 if (tmpRate == 0x6c
1046 && pAdapter->ScanTab.BssEntry[i].HtCapabilityLen >
1047 0) {
1048 int rate_count = ARRAY_SIZE(ralinkrate);
1049 struct rt_ht_cap_info capInfo =
1050 pAdapter->ScanTab.BssEntry[i].HtCapability.
1051 HtCapInfo;
1052 int shortGI =
1053 capInfo.ChannelWidth ? capInfo.
1054 ShortGIfor40 : capInfo.ShortGIfor20;
1055 int maxMCS =
1056 pAdapter->ScanTab.BssEntry[i].HtCapability.
1057 MCSSet[1] ? 15 : 7;
1058 int rate_index =
1059 12 + ((u8)capInfo.ChannelWidth * 24) +
1060 ((u8)shortGI * 48) + ((u8)maxMCS);
1061
1062 if (rate_index < 0)
1063 rate_index = 0;
1064 if (rate_index >= rate_count)
1065 rate_index = rate_count - 1;
1066 iwe.u.bitrate.value =
1067 ralinkrate[rate_index] * 500000;
1068 }
1069
1070 iwe.u.bitrate.disabled = 0;
1071 current_val = iwe_stream_add_value(info, current_ev,
1072 current_val, end_buf,
1073 &iwe,
1074 IW_EV_PARAM_LEN);
1075
1076 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1077 current_ev = current_val;
1078 else
1079 return -E2BIG;
1080 }
1081 /*WPA IE */
1082 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0) {
1083 memset(&iwe, 0, sizeof(iwe));
1084 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1085 memcpy(custom,
1086 &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1087 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1088 iwe.cmd = IWEVGENIE;
1089 iwe.u.data.length =
1090 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1091 current_ev =
1092 iwe_stream_add_point(info, current_ev, end_buf,
1093 &iwe, custom);
1094 if (current_ev == previous_ev)
1095 return -E2BIG;
1096 }
1097 /*WPA2 IE */
1098 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0) {
1099 memset(&iwe, 0, sizeof(iwe));
1100 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1101 memcpy(custom,
1102 &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1103 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1104 iwe.cmd = IWEVGENIE;
1105 iwe.u.data.length =
1106 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1107 current_ev =
1108 iwe_stream_add_point(info, current_ev, end_buf,
1109 &iwe, custom);
1110 if (current_ev == previous_ev)
1111 return -E2BIG;
1112 }
1113 }
1114
1115 data->length = current_ev - extra;
1116 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1117 DBGPRINT(RT_DEBUG_ERROR,
1118 ("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",
1119 i, pAdapter->ScanTab.BssNr, data->length));
1120 return 0;
1121}
1122
1123int rt_ioctl_siwessid(struct net_device *dev,
1124 struct iw_request_info *info,
1125 struct iw_point *data, char *essid)
1126{
1127 struct rt_rtmp_adapter *pAdapter = NULL;
1128
1129 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1130
1131 /*check if the interface is down */
1132 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1133 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1134 return -ENETDOWN;
1135 }
1136
1137 if (data->flags) {
1138 char *pSsidString = NULL;
1139
1140 /* Includes null character. */
1141 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1142 return -E2BIG;
1143
1144 pSsidString = kmalloc(MAX_LEN_OF_SSID + 1, MEM_ALLOC_FLAG);
1145 if (pSsidString) {
1146 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID + 1);
1147 NdisMoveMemory(pSsidString, essid, data->length);
1148 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1149 return -EINVAL;
1150 } else
1151 return -ENOMEM;
1152 } else {
1153 /* ANY ssid */
1154 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1155 return -EINVAL;
1156 }
1157 return 0;
1158}
1159
1160int rt_ioctl_giwessid(struct net_device *dev,
1161 struct iw_request_info *info,
1162 struct iw_point *data, char *essid)
1163{
1164 struct rt_rtmp_adapter *pAdapter = NULL;
1165
1166 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1167
1168 data->flags = 1;
1169 if (MONITOR_ON(pAdapter)) {
1170 data->length = 0;
1171 return 0;
1172 }
1173
1174 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
1175 DBGPRINT(RT_DEBUG_TRACE, ("MediaState is connected\n"));
1176 data->length = pAdapter->CommonCfg.SsidLen;
1177 memcpy(essid, pAdapter->CommonCfg.Ssid,
1178 pAdapter->CommonCfg.SsidLen);
1179 }
1180#ifdef RTMP_MAC_USB
1181 /* Add for RT2870 */
1182 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) {
1183 data->length = pAdapter->CommonCfg.SsidLen;
1184 memcpy(essid, pAdapter->CommonCfg.Ssid,
1185 pAdapter->CommonCfg.SsidLen);
1186 }
1187#endif /* RTMP_MAC_USB // */
1188 else { /*the ANY ssid was specified */
1189 data->length = 0;
1190 DBGPRINT(RT_DEBUG_TRACE,
1191 ("MediaState is not connected, ess\n"));
1192 }
1193
1194 return 0;
1195
1196}
1197
1198int rt_ioctl_siwnickn(struct net_device *dev,
1199 struct iw_request_info *info,
1200 struct iw_point *data, char *nickname)
1201{
1202 struct rt_rtmp_adapter *pAdapter = NULL;
1203
1204 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1205
1206 /*check if the interface is down */
1207 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1208 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1209 return -ENETDOWN;
1210 }
1211
1212 if (data->length > IW_ESSID_MAX_SIZE)
1213 return -EINVAL;
1214
1215 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1216 memcpy(pAdapter->nickname, nickname, data->length);
1217
1218 return 0;
1219}
1220
1221int rt_ioctl_giwnickn(struct net_device *dev,
1222 struct iw_request_info *info,
1223 struct iw_point *data, char *nickname)
1224{
1225 struct rt_rtmp_adapter *pAdapter = NULL;
1226
1227 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1228
1229 if (data->length > strlen((char *)pAdapter->nickname) + 1)
1230 data->length = strlen((char *)pAdapter->nickname) + 1;
1231 if (data->length > 0) {
1232 memcpy(nickname, pAdapter->nickname, data->length - 1);
1233 nickname[data->length - 1] = '\0';
1234 }
1235 return 0;
1236}
1237
1238int rt_ioctl_siwrts(struct net_device *dev,
1239 struct iw_request_info *info,
1240 struct iw_param *rts, char *extra)
1241{
1242 struct rt_rtmp_adapter *pAdapter = NULL;
1243 u16 val;
1244
1245 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1246
1247 /*check if the interface is down */
1248 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1249 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1250 return -ENETDOWN;
1251 }
1252
1253 if (rts->disabled)
1254 val = MAX_RTS_THRESHOLD;
1255 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1256 return -EINVAL;
1257 else if (rts->value == 0)
1258 val = MAX_RTS_THRESHOLD;
1259 else
1260 val = rts->value;
1261
1262 if (val != pAdapter->CommonCfg.RtsThreshold)
1263 pAdapter->CommonCfg.RtsThreshold = val;
1264
1265 return 0;
1266}
1267
1268int rt_ioctl_giwrts(struct net_device *dev,
1269 struct iw_request_info *info,
1270 struct iw_param *rts, char *extra)
1271{
1272 struct rt_rtmp_adapter *pAdapter = NULL;
1273
1274 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1275
1276 /*check if the interface is down */
1277 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1278 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1279 return -ENETDOWN;
1280 }
1281
1282 rts->value = pAdapter->CommonCfg.RtsThreshold;
1283 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1284 rts->fixed = 1;
1285
1286 return 0;
1287}
1288
1289int rt_ioctl_siwfrag(struct net_device *dev,
1290 struct iw_request_info *info,
1291 struct iw_param *frag, char *extra)
1292{
1293 struct rt_rtmp_adapter *pAdapter = NULL;
1294 u16 val;
1295
1296 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1297
1298 /*check if the interface is down */
1299 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1300 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1301 return -ENETDOWN;
1302 }
1303
1304 if (frag->disabled)
1305 val = MAX_FRAG_THRESHOLD;
1306 else if (frag->value >= MIN_FRAG_THRESHOLD
1307 && frag->value <= MAX_FRAG_THRESHOLD)
1308 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1309 else if (frag->value == 0)
1310 val = MAX_FRAG_THRESHOLD;
1311 else
1312 return -EINVAL;
1313
1314 pAdapter->CommonCfg.FragmentThreshold = val;
1315 return 0;
1316}
1317
1318int rt_ioctl_giwfrag(struct net_device *dev,
1319 struct iw_request_info *info,
1320 struct iw_param *frag, char *extra)
1321{
1322 struct rt_rtmp_adapter *pAdapter = NULL;
1323
1324 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1325
1326 /*check if the interface is down */
1327 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1328 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1329 return -ENETDOWN;
1330 }
1331
1332 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1333 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1334 frag->fixed = 1;
1335
1336 return 0;
1337}
1338
1339#define MAX_WEP_KEY_SIZE 13
1340#define MIN_WEP_KEY_SIZE 5
1341int rt_ioctl_siwencode(struct net_device *dev,
1342 struct iw_request_info *info,
1343 struct iw_point *erq, char *extra)
1344{
1345 struct rt_rtmp_adapter *pAdapter = NULL;
1346
1347 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1348
1349 /*check if the interface is down */
1350 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1351 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1352 return -ENETDOWN;
1353 }
1354
1355 if ((erq->length == 0) && (erq->flags & IW_ENCODE_DISABLED)) {
1356 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1357 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1358 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1359 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1360 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1361 goto done;
1362 } else if (erq->flags & IW_ENCODE_RESTRICTED
1363 || erq->flags & IW_ENCODE_OPEN) {
1364 /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
1365 STA_PORT_SECURED(pAdapter);
1366 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1367 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1368 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1369 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1370 if (erq->flags & IW_ENCODE_RESTRICTED)
1371 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1372 else
1373 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1374 }
1375
1376 if (erq->length > 0) {
1377 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1378 /* Check the size of the key */
1379 if (erq->length > MAX_WEP_KEY_SIZE) {
1380 return -EINVAL;
1381 }
1382 /* Check key index */
1383 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS)) {
1384 DBGPRINT(RT_DEBUG_TRACE,
1385 ("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1386 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1387
1388 /*Using default key */
1389 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1390 } else
1391 pAdapter->StaCfg.DefaultKeyId = keyIdx;
1392
1393 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1394
1395 if (erq->length == MAX_WEP_KEY_SIZE) {
1396 pAdapter->SharedKey[BSS0][keyIdx].KeyLen =
1397 MAX_WEP_KEY_SIZE;
1398 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg =
1399 CIPHER_WEP128;
1400 } else if (erq->length == MIN_WEP_KEY_SIZE) {
1401 pAdapter->SharedKey[BSS0][keyIdx].KeyLen =
1402 MIN_WEP_KEY_SIZE;
1403 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg =
1404 CIPHER_WEP64;
1405 } else
1406 /* Disable the key */
1407 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1408
1409 /* Check if the key is not marked as invalid */
1410 if (!(erq->flags & IW_ENCODE_NOKEY)) {
1411 /* Copy the key in the driver */
1412 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key,
1413 extra, erq->length);
1414 }
1415 } else {
1416 /* Do we want to just set the transmit key index ? */
1417 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1418 if ((index >= 0) && (index < 4)) {
1419 pAdapter->StaCfg.DefaultKeyId = index;
1420 } else
1421 /* Don't complain if the mode is only changed */
1422 if (!(erq->flags & IW_ENCODE_MODE))
1423 return -EINVAL;
1424 }
1425
1426done:
1427 DBGPRINT(RT_DEBUG_TRACE,
1428 ("==>rt_ioctl_siwencode::erq->flags=%x\n", erq->flags));
1429 DBGPRINT(RT_DEBUG_TRACE,
1430 ("==>rt_ioctl_siwencode::AuthMode=%x\n",
1431 pAdapter->StaCfg.AuthMode));
1432 DBGPRINT(RT_DEBUG_TRACE,
1433 ("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",
1434 pAdapter->StaCfg.DefaultKeyId,
1435 pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].
1436 KeyLen));
1437 DBGPRINT(RT_DEBUG_TRACE,
1438 ("==>rt_ioctl_siwencode::WepStatus=%x\n",
1439 pAdapter->StaCfg.WepStatus));
1440 return 0;
1441}
1442
1443int
1444rt_ioctl_giwencode(struct net_device *dev,
1445 struct iw_request_info *info,
1446 struct iw_point *erq, char *key)
1447{
1448 int kid;
1449 struct rt_rtmp_adapter *pAdapter = NULL;
1450
1451 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1452
1453 /*check if the interface is down */
1454 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1455 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1456 return -ENETDOWN;
1457 }
1458
1459 kid = erq->flags & IW_ENCODE_INDEX;
1460 DBGPRINT(RT_DEBUG_TRACE,
1461 ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1462
1463 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) {
1464 erq->length = 0;
1465 erq->flags = IW_ENCODE_DISABLED;
1466 } else if ((kid > 0) && (kid <= 4)) {
1467 /* copy wep key */
1468 erq->flags = kid; /* NB: base 1 */
1469 if (erq->length > pAdapter->SharedKey[BSS0][kid - 1].KeyLen)
1470 erq->length = pAdapter->SharedKey[BSS0][kid - 1].KeyLen;
1471 memcpy(key, pAdapter->SharedKey[BSS0][kid - 1].Key,
1472 erq->length);
1473 /*if ((kid == pAdapter->PortCfg.DefaultKeyId)) */
1474 /*erq->flags |= IW_ENCODE_ENABLED; */ /* XXX */
1475 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1476 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1477 else
1478 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1479
1480 } else if (kid == 0) {
1481 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1482 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1483 else
1484 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1485 erq->length =
1486 pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].
1487 KeyLen;
1488 memcpy(key,
1489 pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].
1490 Key, erq->length);
1491 /* copy default key ID */
1492 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1493 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1494 else
1495 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1496 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1497 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1498 }
1499
1500 return 0;
1501
1502}
1503
1504void getBaInfo(struct rt_rtmp_adapter *pAd, char *pOutBuf)
1505{
1506 int i, j;
1507 struct rt_ba_ori_entry *pOriBAEntry;
1508 struct rt_ba_rec_entry *pRecBAEntry;
1509
1510 for (i = 0; i < MAX_LEN_OF_MAC_TABLE; i++) {
1511 struct rt_mac_table_entry *pEntry = &pAd->MacTab.Content[i];
1512 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli)
1513 && (pEntry->Sst == SST_ASSOC))
1514 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh)) {
1515 sprintf(pOutBuf + strlen(pOutBuf), "\n%pM (Aid = %d) "
1516 "(AP) -\n", pEntry->Addr, pEntry->Aid);
1517
1518 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
1519 for (j = 0; j < NUM_OF_TID; j++) {
1520 if (pEntry->BARecWcidArray[j] != 0) {
1521 pRecBAEntry =
1522 &pAd->BATable.BARecEntry[pEntry->
1523 BARecWcidArray
1524 [j]];
1525 sprintf(pOutBuf + strlen(pOutBuf),
1526 "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n",
1527 j, pRecBAEntry->BAWinSize,
1528 pRecBAEntry->LastIndSeq,
1529 pRecBAEntry->list.qlen);
1530 }
1531 }
1532 sprintf(pOutBuf, "%s\n", pOutBuf);
1533
1534 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
1535 for (j = 0; j < NUM_OF_TID; j++) {
1536 if (pEntry->BAOriWcidArray[j] != 0) {
1537 pOriBAEntry =
1538 &pAd->BATable.BAOriEntry[pEntry->
1539 BAOriWcidArray
1540 [j]];
1541 sprintf(pOutBuf + strlen(pOutBuf),
1542 "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n",
1543 j, pOriBAEntry->BAWinSize,
1544 pOriBAEntry->Sequence,
1545 pEntry->TxSeq[j]);
1546 }
1547 }
1548 sprintf(pOutBuf, "%s\n\n", pOutBuf);
1549 }
1550 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
1551 break;
1552 }
1553
1554 return;
1555}
1556
1557int rt_ioctl_siwmlme(struct net_device *dev,
1558 struct iw_request_info *info,
1559 union iwreq_data *wrqu, char *extra)
1560{
1561 struct rt_rtmp_adapter *pAd = NULL;
1562 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
1563 struct rt_mlme_queue_elem MsgElem;
1564 struct rt_mlme_disassoc_req DisAssocReq;
1565 struct rt_mlme_deauth_req DeAuthReq;
1566
1567 GET_PAD_FROM_NET_DEV(pAd, dev);
1568
1569 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
1570
1571 if (pMlme == NULL)
1572 return -EINVAL;
1573
1574 switch (pMlme->cmd) {
1575#ifdef IW_MLME_DEAUTH
1576 case IW_MLME_DEAUTH:
1577 DBGPRINT(RT_DEBUG_TRACE,
1578 ("====> %s - IW_MLME_DEAUTH\n", __func__));
1579 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
1580 DeAuthReq.Reason = pMlme->reason_code;
1581 MsgElem.MsgLen = sizeof(struct rt_mlme_deauth_req);
1582 NdisMoveMemory(MsgElem.Msg, &DeAuthReq,
1583 sizeof(struct rt_mlme_deauth_req));
1584 MlmeDeauthReqAction(pAd, &MsgElem);
1585 if (INFRA_ON(pAd)) {
1586 LinkDown(pAd, FALSE);
1587 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1588 }
1589 break;
1590#endif /* IW_MLME_DEAUTH // */
1591#ifdef IW_MLME_DISASSOC
1592 case IW_MLME_DISASSOC:
1593 DBGPRINT(RT_DEBUG_TRACE,
1594 ("====> %s - IW_MLME_DISASSOC\n", __func__));
1595 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
1596 DisAssocReq.Reason = pMlme->reason_code;
1597
1598 MsgElem.Machine = ASSOC_STATE_MACHINE;
1599 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
1600 MsgElem.MsgLen = sizeof(struct rt_mlme_disassoc_req);
1601 NdisMoveMemory(MsgElem.Msg, &DisAssocReq,
1602 sizeof(struct rt_mlme_disassoc_req));
1603
1604 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
1605 MlmeDisassocReqAction(pAd, &MsgElem);
1606 break;
1607#endif /* IW_MLME_DISASSOC // */
1608 default:
1609 DBGPRINT(RT_DEBUG_TRACE,
1610 ("====> %s - Unknow Command\n", __func__));
1611 break;
1612 }
1613
1614 return 0;
1615}
1616
1617int rt_ioctl_siwauth(struct net_device *dev,
1618 struct iw_request_info *info,
1619 union iwreq_data *wrqu, char *extra)
1620{
1621 struct rt_rtmp_adapter *pAdapter = NULL;
1622 struct iw_param *param = &wrqu->param;
1623
1624 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1625
1626 /*check if the interface is down */
1627 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1628 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1629 return -ENETDOWN;
1630 }
1631 switch (param->flags & IW_AUTH_INDEX) {
1632 case IW_AUTH_WPA_VERSION:
1633 if (param->value == IW_AUTH_WPA_VERSION_WPA) {
1634 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
1635 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
1636 pAdapter->StaCfg.AuthMode =
1637 Ndis802_11AuthModeWPANone;
1638 } else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
1639 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
1640
1641 DBGPRINT(RT_DEBUG_TRACE,
1642 ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n",
1643 __func__, param->value));
1644 break;
1645 case IW_AUTH_CIPHER_PAIRWISE:
1646 if (param->value == IW_AUTH_CIPHER_NONE) {
1647 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1648 pAdapter->StaCfg.OrigWepStatus =
1649 pAdapter->StaCfg.WepStatus;
1650 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1651 } else if (param->value == IW_AUTH_CIPHER_WEP40 ||
1652 param->value == IW_AUTH_CIPHER_WEP104) {
1653 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1654 pAdapter->StaCfg.OrigWepStatus =
1655 pAdapter->StaCfg.WepStatus;
1656 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1657 pAdapter->StaCfg.IEEE8021X = FALSE;
1658 } else if (param->value == IW_AUTH_CIPHER_TKIP) {
1659 pAdapter->StaCfg.WepStatus =
1660 Ndis802_11Encryption2Enabled;
1661 pAdapter->StaCfg.OrigWepStatus =
1662 pAdapter->StaCfg.WepStatus;
1663 pAdapter->StaCfg.PairCipher =
1664 Ndis802_11Encryption2Enabled;
1665 } else if (param->value == IW_AUTH_CIPHER_CCMP) {
1666 pAdapter->StaCfg.WepStatus =
1667 Ndis802_11Encryption3Enabled;
1668 pAdapter->StaCfg.OrigWepStatus =
1669 pAdapter->StaCfg.WepStatus;
1670 pAdapter->StaCfg.PairCipher =
1671 Ndis802_11Encryption3Enabled;
1672 }
1673 DBGPRINT(RT_DEBUG_TRACE,
1674 ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n",
1675 __func__, param->value));
1676 break;
1677 case IW_AUTH_CIPHER_GROUP:
1678 if (param->value == IW_AUTH_CIPHER_NONE) {
1679 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1680 } else if (param->value == IW_AUTH_CIPHER_WEP40 ||
1681 param->value == IW_AUTH_CIPHER_WEP104) {
1682 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1683 } else if (param->value == IW_AUTH_CIPHER_TKIP) {
1684 pAdapter->StaCfg.GroupCipher =
1685 Ndis802_11Encryption2Enabled;
1686 } else if (param->value == IW_AUTH_CIPHER_CCMP) {
1687 pAdapter->StaCfg.GroupCipher =
1688 Ndis802_11Encryption3Enabled;
1689 }
1690 DBGPRINT(RT_DEBUG_TRACE,
1691 ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n",
1692 __func__, param->value));
1693 break;
1694 case IW_AUTH_KEY_MGMT:
1695 if (param->value == IW_AUTH_KEY_MGMT_802_1X) {
1696 if (pAdapter->StaCfg.AuthMode ==
1697 Ndis802_11AuthModeWPAPSK) {
1698 pAdapter->StaCfg.AuthMode =
1699 Ndis802_11AuthModeWPA;
1700 pAdapter->StaCfg.IEEE8021X = FALSE;
1701 } else if (pAdapter->StaCfg.AuthMode ==
1702 Ndis802_11AuthModeWPA2PSK) {
1703 pAdapter->StaCfg.AuthMode =
1704 Ndis802_11AuthModeWPA2;
1705 pAdapter->StaCfg.IEEE8021X = FALSE;
1706 } else
1707 /* WEP 1x */
1708 pAdapter->StaCfg.IEEE8021X = TRUE;
1709 } else if (param->value == 0) {
1710 /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
1711 STA_PORT_SECURED(pAdapter);
1712 }
1713 DBGPRINT(RT_DEBUG_TRACE,
1714 ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n",
1715 __func__, param->value));
1716 break;
1717 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1718 break;
1719 case IW_AUTH_PRIVACY_INVOKED:
1720 /*if (param->value == 0)
1721 {
1722 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1723 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1724 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1725 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1726 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1727 } */
1728 DBGPRINT(RT_DEBUG_TRACE,
1729 ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n",
1730 __func__, param->value));
1731 break;
1732 case IW_AUTH_DROP_UNENCRYPTED:
1733 if (param->value != 0)
1734 pAdapter->StaCfg.PortSecured =
1735 WPA_802_1X_PORT_NOT_SECURED;
1736 else {
1737 /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
1738 STA_PORT_SECURED(pAdapter);
1739 }
1740 DBGPRINT(RT_DEBUG_TRACE,
1741 ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n",
1742 __func__, param->value));
1743 break;
1744 case IW_AUTH_80211_AUTH_ALG:
1745 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
1746 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1747 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1748 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1749 } else
1750 return -EINVAL;
1751 DBGPRINT(RT_DEBUG_TRACE,
1752 ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n",
1753 __func__, param->value));
1754 break;
1755 case IW_AUTH_WPA_ENABLED:
1756 DBGPRINT(RT_DEBUG_TRACE,
1757 ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n",
1758 __func__, param->value));
1759 break;
1760 default:
1761 return -EOPNOTSUPP;
1762 }
1763
1764 return 0;
1765}
1766
1767int rt_ioctl_giwauth(struct net_device *dev,
1768 struct iw_request_info *info,
1769 union iwreq_data *wrqu, char *extra)
1770{
1771 struct rt_rtmp_adapter *pAdapter = NULL;
1772 struct iw_param *param = &wrqu->param;
1773
1774 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1775
1776 /*check if the interface is down */
1777 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1778 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1779 return -ENETDOWN;
1780 }
1781
1782 switch (param->flags & IW_AUTH_INDEX) {
1783 case IW_AUTH_DROP_UNENCRYPTED:
1784 param->value =
1785 (pAdapter->StaCfg.WepStatus ==
1786 Ndis802_11WEPDisabled) ? 0 : 1;
1787 break;
1788
1789 case IW_AUTH_80211_AUTH_ALG:
1790 param->value =
1791 (pAdapter->StaCfg.AuthMode ==
1792 Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY :
1793 IW_AUTH_ALG_OPEN_SYSTEM;
1794 break;
1795
1796 case IW_AUTH_WPA_ENABLED:
1797 param->value =
1798 (pAdapter->StaCfg.AuthMode >=
1799 Ndis802_11AuthModeWPA) ? 1 : 0;
1800 break;
1801
1802 default:
1803 return -EOPNOTSUPP;
1804 }
1805 DBGPRINT(RT_DEBUG_TRACE,
1806 ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
1807 return 0;
1808}
1809
1810void fnSetCipherKey(struct rt_rtmp_adapter *pAdapter,
1811 int keyIdx,
1812 u8 CipherAlg,
1813 IN BOOLEAN bGTK, IN struct iw_encode_ext *ext)
1814{
1815 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(struct rt_cipher_key));
1816 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
1817 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key,
1818 LEN_TKIP_EK);
1819 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic,
1820 ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
1821 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic,
1822 ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK,
1823 LEN_TKIP_RXMICK);
1824 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
1825
1826 /* Update group key information to ASIC Shared Key Table */
1827 AsicAddSharedKeyEntry(pAdapter,
1828 BSS0,
1829 keyIdx,
1830 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
1831 pAdapter->SharedKey[BSS0][keyIdx].Key,
1832 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
1833 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
1834
1835 if (bGTK)
1836 /* Update ASIC WCID attribute table and IVEIV table */
1837 RTMPAddWcidAttributeEntry(pAdapter,
1838 BSS0,
1839 keyIdx,
1840 pAdapter->SharedKey[BSS0][keyIdx].
1841 CipherAlg, NULL);
1842 else
1843 /* Update ASIC WCID attribute table and IVEIV table */
1844 RTMPAddWcidAttributeEntry(pAdapter,
1845 BSS0,
1846 keyIdx,
1847 pAdapter->SharedKey[BSS0][keyIdx].
1848 CipherAlg,
1849 &pAdapter->MacTab.
1850 Content[BSSID_WCID]);
1851}
1852
1853int rt_ioctl_siwencodeext(struct net_device *dev,
1854 struct iw_request_info *info,
1855 union iwreq_data *wrqu, char *extra)
1856{
1857 struct rt_rtmp_adapter *pAdapter = NULL;
1858 struct iw_point *encoding = &wrqu->encoding;
1859 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1860 int keyIdx, alg = ext->alg;
1861
1862 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1863
1864 /*check if the interface is down */
1865 if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
1866 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1867 return -ENETDOWN;
1868 }
1869
1870 if (encoding->flags & IW_ENCODE_DISABLED) {
1871 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
1872 /* set BSSID wcid entry of the Pair-wise Key table as no-security mode */
1873 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
1874 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1875 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
1876 AsicRemoveSharedKeyEntry(pAdapter, 0, (u8)keyIdx);
1877 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx],
1878 sizeof(struct rt_cipher_key));
1879 DBGPRINT(RT_DEBUG_TRACE,
1880 ("%s::Remove all keys!(encoding->flags = %x)\n",
1881 __func__, encoding->flags));
1882 } else {
1883 /* Get Key Index and convet to our own defined key index */
1884 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
1885 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1886 return -EINVAL;
1887
1888 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1889 pAdapter->StaCfg.DefaultKeyId = keyIdx;
1890 DBGPRINT(RT_DEBUG_TRACE,
1891 ("%s::DefaultKeyId = %d\n", __func__,
1892 pAdapter->StaCfg.DefaultKeyId));
1893 }
1894
1895 switch (alg) {
1896 case IW_ENCODE_ALG_NONE:
1897 DBGPRINT(RT_DEBUG_TRACE,
1898 ("%s::IW_ENCODE_ALG_NONE\n", __func__));
1899 break;
1900 case IW_ENCODE_ALG_WEP:
1901 DBGPRINT(RT_DEBUG_TRACE,
1902 ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n",
1903 __func__, ext->key_len, keyIdx));
1904 if (ext->key_len == MAX_WEP_KEY_SIZE) {
1905 pAdapter->SharedKey[BSS0][keyIdx].KeyLen =
1906 MAX_WEP_KEY_SIZE;
1907 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg =
1908 CIPHER_WEP128;
1909 } else if (ext->key_len == MIN_WEP_KEY_SIZE) {
1910 pAdapter->SharedKey[BSS0][keyIdx].KeyLen =
1911 MIN_WEP_KEY_SIZE;
1912 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg =
1913 CIPHER_WEP64;
1914 } else
1915 return -EINVAL;
1916
1917 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key,
1918 16);
1919 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key,
1920 ext->key, ext->key_len);
1921 if (pAdapter->StaCfg.GroupCipher ==
1922 Ndis802_11GroupWEP40Enabled
1923 || pAdapter->StaCfg.GroupCipher ==
1924 Ndis802_11GroupWEP104Enabled) {
1925 /* Set Group key material to Asic */
1926 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx,
1927 pAdapter->
1928 SharedKey[BSS0][keyIdx].
1929 CipherAlg,
1930 pAdapter->
1931 SharedKey[BSS0][keyIdx].
1932 Key, NULL, NULL);
1933
1934 /* Update WCID attribute table and IVEIV table for this group key table */
1935 RTMPAddWcidAttributeEntry(pAdapter, BSS0,
1936 keyIdx,
1937 pAdapter->
1938 SharedKey[BSS0]
1939 [keyIdx].CipherAlg,
1940 NULL);
1941
1942 STA_PORT_SECURED(pAdapter);
1943
1944 /* Indicate Connected for GUI */
1945 pAdapter->IndicateMediaState =
1946 NdisMediaStateConnected;
1947 }
1948 break;
1949 case IW_ENCODE_ALG_TKIP:
1950 DBGPRINT(RT_DEBUG_TRACE,
1951 ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n",
1952 __func__, keyIdx, ext->key_len));
1953 if (ext->key_len == 32) {
1954 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1955 fnSetCipherKey(pAdapter, keyIdx,
1956 CIPHER_TKIP, FALSE, ext);
1957 if (pAdapter->StaCfg.AuthMode >=
1958 Ndis802_11AuthModeWPA2) {
1959 /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
1960 STA_PORT_SECURED(pAdapter);
1961 pAdapter->IndicateMediaState =
1962 NdisMediaStateConnected;
1963 }
1964 } else if (ext->
1965 ext_flags & IW_ENCODE_EXT_GROUP_KEY)
1966 {
1967 fnSetCipherKey(pAdapter, keyIdx,
1968 CIPHER_TKIP, TRUE, ext);
1969
1970 /* set 802.1x port control */
1971 /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
1972 STA_PORT_SECURED(pAdapter);
1973 pAdapter->IndicateMediaState =
1974 NdisMediaStateConnected;
1975 }
1976 } else
1977 return -EINVAL;
1978 break;
1979 case IW_ENCODE_ALG_CCMP:
1980 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1981 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES,
1982 FALSE, ext);
1983 if (pAdapter->StaCfg.AuthMode >=
1984 Ndis802_11AuthModeWPA2)
1985 /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
1986 STA_PORT_SECURED(pAdapter);
1987 pAdapter->IndicateMediaState =
1988 NdisMediaStateConnected;
1989 } else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1990 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES,
1991 TRUE, ext);
1992
1993 /* set 802.1x port control */
1994 /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */
1995 STA_PORT_SECURED(pAdapter);
1996 pAdapter->IndicateMediaState =
1997 NdisMediaStateConnected;
1998 }
1999 break;
2000 default:
2001 return -EINVAL;
2002 }
2003 }
2004
2005 return 0;
2006}
2007
2008int
2009rt_ioctl_giwencodeext(struct net_device *dev,
2010 struct iw_request_info *info,
2011 union iwreq_data *wrqu, char *extra)
2012{
2013 struct rt_rtmp_adapter *pAd = NULL;
2014 char *pKey = NULL;
2015 struct iw_point *encoding = &wrqu->encoding;
2016 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2017 int idx, max_key_len;
2018
2019 GET_PAD_FROM_NET_DEV(pAd, dev);
2020
2021 DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_giwencodeext\n"));
2022
2023 max_key_len = encoding->length - sizeof(*ext);
2024 if (max_key_len < 0)
2025 return -EINVAL;
2026
2027 idx = encoding->flags & IW_ENCODE_INDEX;
2028 if (idx) {
2029 if (idx < 1 || idx > 4)
2030 return -EINVAL;
2031 idx--;
2032
2033 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2034 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)) {
2035 if (idx != pAd->StaCfg.DefaultKeyId) {
2036 ext->key_len = 0;
2037 return 0;
2038 }
2039 }
2040 } else
2041 idx = pAd->StaCfg.DefaultKeyId;
2042
2043 encoding->flags = idx + 1;
2044 memset(ext, 0, sizeof(*ext));
2045
2046 ext->key_len = 0;
2047 switch (pAd->StaCfg.WepStatus) {
2048 case Ndis802_11WEPDisabled:
2049 ext->alg = IW_ENCODE_ALG_NONE;
2050 encoding->flags |= IW_ENCODE_DISABLED;
2051 break;
2052 case Ndis802_11WEPEnabled:
2053 ext->alg = IW_ENCODE_ALG_WEP;
2054 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2055 return -E2BIG;
2056 else {
2057 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2058 pKey = (char *)& (pAd->SharedKey[BSS0][idx].Key[0]);
2059 }
2060 break;
2061 case Ndis802_11Encryption2Enabled:
2062 case Ndis802_11Encryption3Enabled:
2063 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2064 ext->alg = IW_ENCODE_ALG_TKIP;
2065 else
2066 ext->alg = IW_ENCODE_ALG_CCMP;
2067
2068 if (max_key_len < 32)
2069 return -E2BIG;
2070 else {
2071 ext->key_len = 32;
2072 pKey = (char *)& pAd->StaCfg.PMK[0];
2073 }
2074 break;
2075 default:
2076 return -EINVAL;
2077 }
2078
2079 if (ext->key_len && pKey) {
2080 encoding->flags |= IW_ENCODE_ENABLED;
2081 memcpy(ext->key, pKey, ext->key_len);
2082 }
2083
2084 return 0;
2085}
2086
2087int rt_ioctl_siwgenie(struct net_device *dev,
2088 struct iw_request_info *info,
2089 union iwreq_data *wrqu, char *extra)
2090{
2091 struct rt_rtmp_adapter *pAd = NULL;
2092
2093 GET_PAD_FROM_NET_DEV(pAd, dev);
2094
2095 DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_siwgenie\n"));
2096 pAd->StaCfg.bRSN_IE_FromWpaSupplicant = FALSE;
2097 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2098 (wrqu->data.length && extra == NULL))
2099 return -EINVAL;
2100
2101 if (wrqu->data.length) {
2102 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2103 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra,
2104 pAd->StaCfg.RSNIE_Len);
2105 pAd->StaCfg.bRSN_IE_FromWpaSupplicant = TRUE;
2106 } else {
2107 pAd->StaCfg.RSNIE_Len = 0;
2108 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2109 }
2110
2111 return 0;
2112}
2113
2114int rt_ioctl_giwgenie(struct net_device *dev,
2115 struct iw_request_info *info,
2116 union iwreq_data *wrqu, char *extra)
2117{
2118 struct rt_rtmp_adapter *pAd = NULL;
2119
2120 GET_PAD_FROM_NET_DEV(pAd, dev);
2121
2122 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2123 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)) {
2124 wrqu->data.length = 0;
2125 return 0;
2126 }
2127
2128 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) {
2129 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2130 return -E2BIG;
2131
2132 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2133 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2134 } else {
2135 u8 RSNIe = IE_WPA;
2136
2137 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) /* ID, Len */
2138 return -E2BIG;
2139 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2140
2141 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2142 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2143 RSNIe = IE_RSN;
2144
2145 extra[0] = (char)RSNIe;
2146 extra[1] = pAd->StaCfg.RSNIE_Len;
2147 memcpy(extra + 2, &pAd->StaCfg.RSN_IE[0],
2148 pAd->StaCfg.RSNIE_Len);
2149 }
2150
2151 return 0;
2152}
2153
2154int rt_ioctl_siwpmksa(struct net_device *dev,
2155 struct iw_request_info *info,
2156 union iwreq_data *wrqu, char *extra)
2157{
2158 struct rt_rtmp_adapter *pAd = NULL;
2159 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2160 int CachedIdx = 0, idx = 0;
2161
2162 GET_PAD_FROM_NET_DEV(pAd, dev);
2163
2164 if (pPmksa == NULL)
2165 return -EINVAL;
2166
2167 DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_siwpmksa\n"));
2168 switch (pPmksa->cmd) {
2169 case IW_PMKSA_FLUSH:
2170 NdisZeroMemory(pAd->StaCfg.SavedPMK,
2171 sizeof(struct rt_bssid_info) * PMKID_NO);
2172 DBGPRINT(RT_DEBUG_TRACE,
2173 ("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2174 break;
2175 case IW_PMKSA_REMOVE:
2176 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum;
2177 CachedIdx++) {
2178 /* compare the BSSID */
2179 if (NdisEqualMemory
2180 (pPmksa->bssid.sa_data,
2181 pAd->StaCfg.SavedPMK[CachedIdx].BSSID,
2182 MAC_ADDR_LEN)) {
2183 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].
2184 BSSID, MAC_ADDR_LEN);
2185 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].
2186 PMKID, 16);
2187 for (idx = CachedIdx;
2188 idx < (pAd->StaCfg.SavedPMKNum - 1);
2189 idx++) {
2190 NdisMoveMemory(&pAd->StaCfg.
2191 SavedPMK[idx].BSSID[0],
2192 &pAd->StaCfg.
2193 SavedPMK[idx +
2194 1].BSSID[0],
2195 MAC_ADDR_LEN);
2196 NdisMoveMemory(&pAd->StaCfg.
2197 SavedPMK[idx].PMKID[0],
2198 &pAd->StaCfg.
2199 SavedPMK[idx +
2200 1].PMKID[0],
2201 16);
2202 }
2203 pAd->StaCfg.SavedPMKNum--;
2204 break;
2205 }
2206 }
2207
2208 DBGPRINT(RT_DEBUG_TRACE,
2209 ("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2210 break;
2211 case IW_PMKSA_ADD:
2212 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum;
2213 CachedIdx++) {
2214 /* compare the BSSID */
2215 if (NdisEqualMemory
2216 (pPmksa->bssid.sa_data,
2217 pAd->StaCfg.SavedPMK[CachedIdx].BSSID,
2218 MAC_ADDR_LEN))
2219 break;
2220 }
2221
2222 /* Found, replace it */
2223 if (CachedIdx < PMKID_NO) {
2224 DBGPRINT(RT_DEBUG_OFF,
2225 ("Update PMKID, idx = %d\n", CachedIdx));
2226 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].
2227 BSSID[0], pPmksa->bssid.sa_data,
2228 MAC_ADDR_LEN);
2229 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].
2230 PMKID[0], pPmksa->pmkid, 16);
2231 pAd->StaCfg.SavedPMKNum++;
2232 }
2233 /* Not found, replace the last one */
2234 else {
2235 /* Randomly replace one */
2236 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2237 DBGPRINT(RT_DEBUG_OFF,
2238 ("Update PMKID, idx = %d\n", CachedIdx));
2239 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].
2240 BSSID[0], pPmksa->bssid.sa_data,
2241 MAC_ADDR_LEN);
2242 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].
2243 PMKID[0], pPmksa->pmkid, 16);
2244 }
2245
2246 DBGPRINT(RT_DEBUG_TRACE,
2247 ("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2248 break;
2249 default:
2250 DBGPRINT(RT_DEBUG_TRACE,
2251 ("rt_ioctl_siwpmksa - Unknown Command!\n"));
2252 break;
2253 }
2254
2255 return 0;
2256}
2257
2258int rt_ioctl_siwrate(struct net_device *dev,
2259 struct iw_request_info *info,
2260 union iwreq_data *wrqu, char *extra)
2261{
2262 struct rt_rtmp_adapter *pAd = NULL;
2263 u32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2264
2265 GET_PAD_FROM_NET_DEV(pAd, dev);
2266
2267 /*check if the interface is down */
2268 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
2269 DBGPRINT(RT_DEBUG_TRACE,
2270 ("rt_ioctl_siwrate::Network is down!\n"));
2271 return -ENETDOWN;
2272 }
2273
2274 DBGPRINT(RT_DEBUG_TRACE,
2275 ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2276 /* rate = -1 => auto rate
2277 rate = X, fixed = 1 => (fixed rate X)
2278 */
2279 if (rate == -1) {
2280 /*Auto Rate */
2281 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2282 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2283 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2284 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <=
2285 MODE_OFDM))
2286 RTMPSetDesiredRates(pAd, -1);
2287
2288 SetCommonHT(pAd);
2289 } else {
2290 if (fixed) {
2291 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
2292 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2293 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.
2294 MODE <= MODE_OFDM))
2295 RTMPSetDesiredRates(pAd, rate);
2296 else {
2297 pAd->StaCfg.DesiredTransmitSetting.field.MCS =
2298 MCS_AUTO;
2299 SetCommonHT(pAd);
2300 }
2301 DBGPRINT(RT_DEBUG_TRACE,
2302 ("rt_ioctl_siwrate::(HtMcs=%d)\n",
2303 pAd->StaCfg.DesiredTransmitSetting.field.
2304 MCS));
2305 } else {
2306 /* TODO: rate = X, fixed = 0 => (rates <= X) */
2307 return -EOPNOTSUPP;
2308 }
2309 }
2310
2311 return 0;
2312}
2313
2314int rt_ioctl_giwrate(struct net_device *dev,
2315 struct iw_request_info *info,
2316 union iwreq_data *wrqu, char *extra)
2317{
2318 struct rt_rtmp_adapter *pAd = NULL;
2319 int rate_index = 0, rate_count = 0;
2320 HTTRANSMIT_SETTING ht_setting;
2321/* Remove to global variable
2322 __s32 ralinkrate[] =
2323 {2, 4, 11, 22, // CCK
2324 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
2325 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
2326 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
2327 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
2328 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
2329 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
2330 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
2331 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
2332 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
2333*/
2334 GET_PAD_FROM_NET_DEV(pAd, dev);
2335
2336 rate_count = ARRAY_SIZE(ralinkrate);
2337 /*check if the interface is down */
2338 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
2339 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2340 return -ENETDOWN;
2341 }
2342
2343 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
2344 (INFRA_ON(pAd)) &&
2345 ((pAd->CommonCfg.PhyMode <= PHY_11G)
2346 || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <=
2347 MODE_OFDM)))
2348 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
2349 else
2350 ht_setting.word =
2351 pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
2352
2353 if (ht_setting.field.MODE >= MODE_HTMIX) {
2354/* rate_index = 12 + ((u8)ht_setting.field.BW *16) + ((u8)ht_setting.field.ShortGI *32) + ((u8)ht_setting.field.MCS); */
2355 rate_index =
2356 12 + ((u8)ht_setting.field.BW * 24) +
2357 ((u8)ht_setting.field.ShortGI * 48) +
2358 ((u8)ht_setting.field.MCS);
2359 } else if (ht_setting.field.MODE == MODE_OFDM)
2360 rate_index = (u8)(ht_setting.field.MCS) + 4;
2361 else if (ht_setting.field.MODE == MODE_CCK)
2362 rate_index = (u8)(ht_setting.field.MCS);
2363
2364 if (rate_index < 0)
2365 rate_index = 0;
2366
2367 if (rate_index >= rate_count)
2368 rate_index = rate_count - 1;
2369
2370 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
2371 wrqu->bitrate.disabled = 0;
2372
2373 return 0;
2374}
2375
2376static const iw_handler rt_handler[] = {
2377 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2378 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
2379 (iw_handler) NULL, /* SIOCSIWNWID */
2380 (iw_handler) NULL, /* SIOCGIWNWID */
2381 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
2382 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
2383 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
2384 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
2385 (iw_handler) NULL, /* SIOCSIWSENS */
2386 (iw_handler) NULL, /* SIOCGIWSENS */
2387 (iw_handler) NULL /* not used */ , /* SIOCSIWRANGE */
2388 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
2389 (iw_handler) NULL /* not used */ , /* SIOCSIWPRIV */
2390 (iw_handler) NULL /* kernel code */ , /* SIOCGIWPRIV */
2391 (iw_handler) NULL /* not used */ , /* SIOCSIWSTATS */
2392 (iw_handler) rt28xx_get_wireless_stats /* kernel code */ , /* SIOCGIWSTATS */
2393 (iw_handler) NULL, /* SIOCSIWSPY */
2394 (iw_handler) NULL, /* SIOCGIWSPY */
2395 (iw_handler) NULL, /* SIOCSIWTHRSPY */
2396 (iw_handler) NULL, /* SIOCGIWTHRSPY */
2397 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
2398 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
2399 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
2400 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
2401 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
2402 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
2403 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
2404 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
2405 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
2406 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
2407 (iw_handler) NULL, /* -- hole -- */
2408 (iw_handler) NULL, /* -- hole -- */
2409 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
2410 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
2411 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
2412 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
2413 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
2414 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
2415 (iw_handler) NULL, /* SIOCSIWTXPOW */
2416 (iw_handler) NULL, /* SIOCGIWTXPOW */
2417 (iw_handler) NULL, /* SIOCSIWRETRY */
2418 (iw_handler) NULL, /* SIOCGIWRETRY */
2419 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
2420 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
2421 (iw_handler) NULL, /* SIOCSIWPOWER */
2422 (iw_handler) NULL, /* SIOCGIWPOWER */
2423 (iw_handler) NULL, /* -- hole -- */
2424 (iw_handler) NULL, /* -- hole -- */
2425 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
2426 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
2427 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
2428 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
2429 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
2430 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
2431 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
2432};
2433
2434const struct iw_handler_def rt28xx_iw_handler_def = {
2435 .standard = (iw_handler *) rt_handler,
2436 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
2437#if IW_HANDLER_VERSION >= 7
2438 .get_wireless_stats = rt28xx_get_wireless_stats,
2439#endif
2440};
2441
2442int rt28xx_sta_ioctl(IN struct net_device *net_dev,
2443 IN OUT struct ifreq *rq, int cmd)
2444{
2445 struct os_cookie *pObj;
2446 struct rt_rtmp_adapter *pAd = NULL;
2447 struct iwreq *wrq = (struct iwreq *)rq;
2448 BOOLEAN StateMachineTouched = FALSE;
2449 int Status = NDIS_STATUS_SUCCESS;
2450
2451 GET_PAD_FROM_NET_DEV(pAd, net_dev);
2452
2453 pObj = (struct os_cookie *)pAd->OS_Cookie;
2454
2455 /*check if the interface is down */
2456 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) {
2457 {
2458 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2459 return -ENETDOWN;
2460 }
2461 }
2462
2463 { /* determine this ioctl command is coming from which interface. */
2464 pObj->ioctl_if_type = INT_MAIN;
2465 pObj->ioctl_if = MAIN_MBSSID;
2466 }
2467
2468 switch (cmd) {
2469 case SIOCGIFHWADDR:
2470 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
2471 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
2472 break;
2473 case SIOCGIWNAME:
2474 {
2475 char *name = &wrq->u.name[0];
2476 rt_ioctl_giwname(net_dev, NULL, name, NULL);
2477 break;
2478 }
2479 case SIOCGIWESSID: /*Get ESSID */
2480 {
2481 struct iw_point *essid = &wrq->u.essid;
2482 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
2483 break;
2484 }
2485 case SIOCSIWESSID: /*Set ESSID */
2486 {
2487 struct iw_point *essid = &wrq->u.essid;
2488 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
2489 break;
2490 }
2491 case SIOCSIWNWID: /* set network id (the cell) */
2492 case SIOCGIWNWID: /* get network id */
2493 Status = -EOPNOTSUPP;
2494 break;
2495 case SIOCSIWFREQ: /*set channel/frequency (Hz) */
2496 {
2497 struct iw_freq *freq = &wrq->u.freq;
2498 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
2499 break;
2500 }
2501 case SIOCGIWFREQ: /* get channel/frequency (Hz) */
2502 {
2503 struct iw_freq *freq = &wrq->u.freq;
2504 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
2505 break;
2506 }
2507 case SIOCSIWNICKN: /*set node name/nickname */
2508 {
2509 /*struct iw_point *data=&wrq->u.data; */
2510 /*rt_ioctl_siwnickn(net_dev, NULL, data, NULL); */
2511 break;
2512 }
2513 case SIOCGIWNICKN: /*get node name/nickname */
2514 {
2515 struct iw_point *erq = NULL;
2516 erq = &wrq->u.data;
2517 erq->length = strlen((char *)pAd->nickname);
2518 Status =
2519 copy_to_user(erq->pointer, pAd->nickname,
2520 erq->length);
2521 if (Status)
2522 Status = -EFAULT;
2523 break;
2524 }
2525 case SIOCGIWRATE: /*get default bit rate (bps) */
2526 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
2527 break;
2528 case SIOCSIWRATE: /*set default bit rate (bps) */
2529 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
2530 break;
2531 case SIOCGIWRTS: /* get RTS/CTS threshold (bytes) */
2532 {
2533 struct iw_param *rts = &wrq->u.rts;
2534 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
2535 break;
2536 }
2537 case SIOCSIWRTS: /*set RTS/CTS threshold (bytes) */
2538 {
2539 struct iw_param *rts = &wrq->u.rts;
2540 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
2541 break;
2542 }
2543 case SIOCGIWFRAG: /*get fragmentation thr (bytes) */
2544 {
2545 struct iw_param *frag = &wrq->u.frag;
2546 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
2547 break;
2548 }
2549 case SIOCSIWFRAG: /*set fragmentation thr (bytes) */
2550 {
2551 struct iw_param *frag = &wrq->u.frag;
2552 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
2553 break;
2554 }
2555 case SIOCGIWENCODE: /*get encoding token & mode */
2556 {
2557 struct iw_point *erq = &wrq->u.encoding;
2558 if (erq)
2559 rt_ioctl_giwencode(net_dev, NULL, erq,
2560 erq->pointer);
2561 break;
2562 }
2563 case SIOCSIWENCODE: /*set encoding token & mode */
2564 {
2565 struct iw_point *erq = &wrq->u.encoding;
2566 if (erq)
2567 rt_ioctl_siwencode(net_dev, NULL, erq,
2568 erq->pointer);
2569 break;
2570 }
2571 case SIOCGIWAP: /*get access point MAC addresses */
2572 {
2573 struct sockaddr *ap_addr = &wrq->u.ap_addr;
2574 rt_ioctl_giwap(net_dev, NULL, ap_addr,
2575 ap_addr->sa_data);
2576 break;
2577 }
2578 case SIOCSIWAP: /*set access point MAC addresses */
2579 {
2580 struct sockaddr *ap_addr = &wrq->u.ap_addr;
2581 rt_ioctl_siwap(net_dev, NULL, ap_addr,
2582 ap_addr->sa_data);
2583 break;
2584 }
2585 case SIOCGIWMODE: /*get operation mode */
2586 {
2587 __u32 *mode = &wrq->u.mode;
2588 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
2589 break;
2590 }
2591 case SIOCSIWMODE: /*set operation mode */
2592 {
2593 __u32 *mode = &wrq->u.mode;
2594 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
2595 break;
2596 }
2597 case SIOCGIWSENS: /*get sensitivity (dBm) */
2598 case SIOCSIWSENS: /*set sensitivity (dBm) */
2599 case SIOCGIWPOWER: /*get Power Management settings */
2600 case SIOCSIWPOWER: /*set Power Management settings */
2601 case SIOCGIWTXPOW: /*get transmit power (dBm) */
2602 case SIOCSIWTXPOW: /*set transmit power (dBm) */
2603 case SIOCGIWRANGE: /*Get range of parameters */
2604 case SIOCGIWRETRY: /*get retry limits and lifetime */
2605 case SIOCSIWRETRY: /*set retry limits and lifetime */
2606 case RT_PRIV_IOCTL:
2607 case RT_PRIV_IOCTL_EXT:
2608 case RTPRIV_IOCTL_SET:
2609 case RTPRIV_IOCTL_GSITESURVEY:
2610 case SIOCGIWPRIV:
2611 Status = -EOPNOTSUPP;
2612 break;
2613 case SIOCETHTOOL:
2614 break;
2615 default:
2616 DBGPRINT(RT_DEBUG_ERROR,
2617 ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
2618 Status = -EOPNOTSUPP;
2619 break;
2620 }
2621
2622 if (StateMachineTouched) /* Upper layer sent a MLME-related operations */
2623 RTMP_MLME_HANDLER(pAd);
2624
2625 return Status;
2626}
2627
2628/*
2629 ==========================================================================
2630 Description:
2631 Set SSID
2632 Return:
2633 TRUE if all parameters are OK, FALSE otherwise
2634 ==========================================================================
2635*/
2636int Set_SSID_Proc(struct rt_rtmp_adapter *pAdapter, char *arg)
2637{
2638 struct rt_ndis_802_11_ssid Ssid, *pSsid = NULL;
2639 BOOLEAN StateMachineTouched = FALSE;
2640 int success = TRUE;
2641
2642 if (strlen(arg) <= MAX_LEN_OF_SSID) {
2643 NdisZeroMemory(&Ssid, sizeof(struct rt_ndis_802_11_ssid));
2644 if (strlen(arg) != 0) {
2645 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
2646 Ssid.SsidLength = strlen(arg);
2647 } else /*ANY ssid */
2648 {
2649 Ssid.SsidLength = 0;
2650 memcpy(Ssid.Ssid, "", 0);
2651 pAdapter->StaCfg.BssType = BSS_INFRA;
2652 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2653 pAdapter->StaCfg.WepStatus =
2654 Ndis802_11EncryptionDisabled;
2655 }
2656 pSsid = &Ssid;
2657
2658 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) {
2659 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
2660 DBGPRINT(RT_DEBUG_TRACE,
2661 ("MLME busy, reset MLME state machine!\n"));
2662 }
2663
2664 if ((pAdapter->StaCfg.WpaPassPhraseLen >= 8) &&
2665 (pAdapter->StaCfg.WpaPassPhraseLen <= 64)) {
2666 char passphrase_str[65] = { 0 };
2667 u8 keyMaterial[40];
2668
2669 RTMPMoveMemory(passphrase_str,
2670 pAdapter->StaCfg.WpaPassPhrase,
2671 pAdapter->StaCfg.WpaPassPhraseLen);
2672 RTMPZeroMemory(pAdapter->StaCfg.PMK, 32);
2673 if (pAdapter->StaCfg.WpaPassPhraseLen == 64) {
2674 AtoH((char *)pAdapter->StaCfg.WpaPassPhrase,
2675 pAdapter->StaCfg.PMK, 32);
2676 } else {
2677 PasswordHash((char *)pAdapter->StaCfg.
2678 WpaPassPhrase, Ssid.Ssid,
2679 Ssid.SsidLength, keyMaterial);
2680 NdisMoveMemory(pAdapter->StaCfg.PMK,
2681 keyMaterial, 32);
2682 }
2683 }
2684
2685 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
2686 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
2687 pAdapter->bConfigChanged = TRUE;
2688
2689 MlmeEnqueue(pAdapter,
2690 MLME_CNTL_STATE_MACHINE,
2691 OID_802_11_SSID,
2692 sizeof(struct rt_ndis_802_11_ssid), (void *) pSsid);
2693
2694 StateMachineTouched = TRUE;
2695 DBGPRINT(RT_DEBUG_TRACE,
2696 ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength,
2697 Ssid.Ssid));
2698 } else
2699 success = FALSE;
2700
2701 if (StateMachineTouched) /* Upper layer sent a MLME-related operations */
2702 RTMP_MLME_HANDLER(pAdapter);
2703
2704 return success;
2705}
2706
2707/*
2708 ==========================================================================
2709 Description:
2710 Set Network Type(Infrastructure/Adhoc mode)
2711 Return:
2712 TRUE if all parameters are OK, FALSE otherwise
2713 ==========================================================================
2714*/
2715int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg)
2716{
2717 u32 Value = 0;
2718
2719 if (strcmp(arg, "Adhoc") == 0) {
2720 if (pAdapter->StaCfg.BssType != BSS_ADHOC) {
2721 /* Config has changed */
2722 pAdapter->bConfigChanged = TRUE;
2723 if (MONITOR_ON(pAdapter)) {
2724 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG,
2725 STANORMAL);
2726 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
2727 Value &= (~0x80);
2728 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
2729 OPSTATUS_CLEAR_FLAG(pAdapter,
2730 fOP_STATUS_MEDIA_STATE_CONNECTED);
2731 pAdapter->StaCfg.bAutoReconnect = TRUE;
2732 LinkDown(pAdapter, FALSE);
2733 }
2734 if (INFRA_ON(pAdapter)) {
2735 /*BOOLEAN Cancelled; */
2736 /* Set the AutoReconnectSsid to prevent it from reconnecting to the old SSID */
2737 /* Since calling this indicates users don't want to connect to that SSID anymore. */
2738 pAdapter->MlmeAux.AutoReconnectSsidLen = 32;
2739 NdisZeroMemory(pAdapter->MlmeAux.
2740 AutoReconnectSsid,
2741 pAdapter->MlmeAux.
2742 AutoReconnectSsidLen);
2743
2744 LinkDown(pAdapter, FALSE);
2745
2746 DBGPRINT(RT_DEBUG_TRACE,
2747 ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
2748 }
2749 }
2750 pAdapter->StaCfg.BssType = BSS_ADHOC;
2751 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
2752 DBGPRINT(RT_DEBUG_TRACE,
2753 ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
2754 } else if (strcmp(arg, "Infra") == 0) {
2755 if (pAdapter->StaCfg.BssType != BSS_INFRA) {
2756 /* Config has changed */
2757 pAdapter->bConfigChanged = TRUE;
2758 if (MONITOR_ON(pAdapter)) {
2759 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG,
2760 STANORMAL);
2761 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
2762 Value &= (~0x80);
2763 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
2764 OPSTATUS_CLEAR_FLAG(pAdapter,
2765 fOP_STATUS_MEDIA_STATE_CONNECTED);
2766 pAdapter->StaCfg.bAutoReconnect = TRUE;
2767 LinkDown(pAdapter, FALSE);
2768 }
2769 if (ADHOC_ON(pAdapter)) {
2770 /* Set the AutoReconnectSsid to prevent it from reconnecting to the old SSID */
2771 /* Since calling this indicates users don't want to connect to that SSID anymore. */
2772 pAdapter->MlmeAux.AutoReconnectSsidLen = 32;
2773 NdisZeroMemory(pAdapter->MlmeAux.
2774 AutoReconnectSsid,
2775 pAdapter->MlmeAux.
2776 AutoReconnectSsidLen);
2777
2778 LinkDown(pAdapter, FALSE);
2779 }
2780 }
2781 pAdapter->StaCfg.BssType = BSS_INFRA;
2782 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
2783 DBGPRINT(RT_DEBUG_TRACE,
2784 ("===>Set_NetworkType_Proc::(INFRA)\n"));
2785 } else if (strcmp(arg, "Monitor") == 0) {
2786 u8 bbpValue = 0;
2787 BCN_TIME_CFG_STRUC csr;
2788 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
2789 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
2790 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
2791 /* disable all periodic state machine */
2792 pAdapter->StaCfg.bAutoReconnect = FALSE;
2793 /* reset all mlme state machine */
2794 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
2795 DBGPRINT(RT_DEBUG_TRACE,
2796 ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
2797 if (pAdapter->CommonCfg.CentralChannel == 0) {
2798 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
2799 pAdapter->CommonCfg.CentralChannel = 36;
2800 else
2801 pAdapter->CommonCfg.CentralChannel = 6;
2802 } else
2803 N_ChannelCheck(pAdapter);
2804
2805 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2806 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
2807 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA ==
2808 EXTCHA_ABOVE) {
2809 /* 40MHz ,control channel at lower */
2810 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4,
2811 &bbpValue);
2812 bbpValue &= (~0x18);
2813 bbpValue |= 0x10;
2814 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4,
2815 bbpValue);
2816 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
2817 /* RX : control channel at lower */
2818 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3,
2819 &bbpValue);
2820 bbpValue &= (~0x20);
2821 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3,
2822 bbpValue);
2823
2824 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
2825 Value &= 0xfffffffe;
2826 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
2827 pAdapter->CommonCfg.CentralChannel =
2828 pAdapter->CommonCfg.Channel + 2;
2829 AsicSwitchChannel(pAdapter,
2830 pAdapter->CommonCfg.CentralChannel,
2831 FALSE);
2832 AsicLockChannel(pAdapter,
2833 pAdapter->CommonCfg.CentralChannel);
2834 DBGPRINT(RT_DEBUG_TRACE,
2835 ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
2836 pAdapter->CommonCfg.Channel,
2837 pAdapter->CommonCfg.CentralChannel));
2838 } else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED
2839 && pAdapter->CommonCfg.RegTransmitSetting.field.BW ==
2840 BW_40
2841 && pAdapter->CommonCfg.RegTransmitSetting.field.
2842 EXTCHA == EXTCHA_BELOW) {
2843 /* 40MHz ,control channel at upper */
2844 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4,
2845 &bbpValue);
2846 bbpValue &= (~0x18);
2847 bbpValue |= 0x10;
2848 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4,
2849 bbpValue);
2850 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
2851 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
2852 Value |= 0x1;
2853 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
2854
2855 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3,
2856 &bbpValue);
2857 bbpValue |= (0x20);
2858 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3,
2859 bbpValue);
2860 pAdapter->CommonCfg.CentralChannel =
2861 pAdapter->CommonCfg.Channel - 2;
2862 AsicSwitchChannel(pAdapter,
2863 pAdapter->CommonCfg.CentralChannel,
2864 FALSE);
2865 AsicLockChannel(pAdapter,
2866 pAdapter->CommonCfg.CentralChannel);
2867 DBGPRINT(RT_DEBUG_TRACE,
2868 ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
2869 pAdapter->CommonCfg.Channel,
2870 pAdapter->CommonCfg.CentralChannel));
2871 } else {
2872 /* 20MHz */
2873 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4,
2874 &bbpValue);
2875 bbpValue &= (~0x18);
2876 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4,
2877 bbpValue);
2878 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
2879 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel,
2880 FALSE);
2881 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
2882 DBGPRINT(RT_DEBUG_TRACE,
2883 ("BW_20, Channel(%d)\n",
2884 pAdapter->CommonCfg.Channel));
2885 }
2886 /* Enable Rx with promiscuous reception */
2887 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
2888 /* ASIC supports sniffer function with replacing RSSI with timestamp. */
2889 /*RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); */
2890 /*Value |= (0x80); */
2891 /*RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); */
2892 /* disable sync */
2893 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
2894 csr.field.bBeaconGen = 0;
2895 csr.field.bTBTTEnable = 0;
2896 csr.field.TsfSyncMode = 0;
2897 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
2898
2899 pAdapter->StaCfg.BssType = BSS_MONITOR;
2900 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; /*ARPHRD_IEEE80211; // IEEE80211 */
2901 DBGPRINT(RT_DEBUG_TRACE,
2902 ("===>Set_NetworkType_Proc::(MONITOR)\n"));
2903 }
2904 /* Reset Ralink supplicant to not use, it will be set to start when UI set PMK key */
2905 pAdapter->StaCfg.WpaState = SS_NOTUSE;
2906
2907 DBGPRINT(RT_DEBUG_TRACE,
2908 ("Set_NetworkType_Proc::(NetworkType=%d)\n",
2909 pAdapter->StaCfg.BssType));
2910
2911 return TRUE;
2912}
diff --git a/drivers/staging/rt2860/usb_main_dev.c b/drivers/staging/rt2860/usb_main_dev.c
deleted file mode 100644
index 322bf49ee90..00000000000
--- a/drivers/staging/rt2860/usb_main_dev.c
+++ /dev/null
@@ -1,927 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************/
26
27#include "rt_config.h"
28
29/* Following information will be show when you run 'modinfo' */
30/* If you have a solution for the bug in current version of driver, please e-mail me. */
31/* Otherwise post to the forum at ralinktech's web site(www.ralinktech.com) and let all users help you. */
32MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");
33MODULE_DESCRIPTION("RT2870/RT3070 Wireless Lan Linux Driver");
34MODULE_LICENSE("GPL");
35#ifdef MODULE_VERSION
36MODULE_VERSION(STA_DRIVER_VERSION);
37#endif
38
39/* module table */
40struct usb_device_id rtusb_usb_id[] = {
41#ifdef RT2870
42 {USB_DEVICE(0x148F, 0x2770)}, /* Ralink */
43 {USB_DEVICE(0x148F, 0x2870)}, /* Ralink */
44 {USB_DEVICE(0x07B8, 0x2870)}, /* AboCom */
45 {USB_DEVICE(0x07B8, 0x2770)}, /* AboCom */
46 {USB_DEVICE(0x0DF6, 0x0039)}, /* Sitecom 2770 */
47 {USB_DEVICE(0x0DF6, 0x003F)}, /* Sitecom 2770 */
48 {USB_DEVICE(0x083A, 0x7512)}, /* Arcadyan 2770 */
49 {USB_DEVICE(0x0789, 0x0162)}, /* Logitec 2870 */
50 {USB_DEVICE(0x0789, 0x0163)}, /* Logitec 2870 */
51 {USB_DEVICE(0x0789, 0x0164)}, /* Logitec 2870 */
52 {USB_DEVICE(0x177f, 0x0302)}, /* lsusb */
53 {USB_DEVICE(0x0B05, 0x1731)}, /* Asus */
54 {USB_DEVICE(0x0B05, 0x1732)}, /* Asus */
55 {USB_DEVICE(0x0B05, 0x1742)}, /* Asus */
56 {USB_DEVICE(0x0DF6, 0x0017)}, /* Sitecom */
57 {USB_DEVICE(0x0DF6, 0x002B)}, /* Sitecom */
58 {USB_DEVICE(0x0DF6, 0x002C)}, /* Sitecom */
59 {USB_DEVICE(0x0DF6, 0x002D)}, /* Sitecom */
60 {USB_DEVICE(0x14B2, 0x3C06)}, /* Conceptronic */
61 {USB_DEVICE(0x14B2, 0x3C28)}, /* Conceptronic */
62 {USB_DEVICE(0x2019, 0xED06)}, /* Planex Communications, Inc. */
63 {USB_DEVICE(0x07D1, 0x3C09)}, /* D-Link */
64 {USB_DEVICE(0x07D1, 0x3C11)}, /* D-Link */
65 {USB_DEVICE(0x14B2, 0x3C07)}, /* AL */
66 {USB_DEVICE(0x050D, 0x8053)}, /* Belkin */
67 {USB_DEVICE(0x050D, 0x825B)}, /* Belkin */
68 {USB_DEVICE(0x050D, 0x935A)}, /* Belkin F6D4050 v1 */
69 {USB_DEVICE(0x050D, 0x935B)}, /* Belkin F6D4050 v2 */
70 {USB_DEVICE(0x14B2, 0x3C23)}, /* Airlink */
71 {USB_DEVICE(0x14B2, 0x3C27)}, /* Airlink */
72 {USB_DEVICE(0x07AA, 0x002F)}, /* Corega */
73 {USB_DEVICE(0x07AA, 0x003C)}, /* Corega */
74 {USB_DEVICE(0x07AA, 0x003F)}, /* Corega */
75 {USB_DEVICE(0x1044, 0x800B)}, /* Gigabyte */
76 {USB_DEVICE(0x15A9, 0x0006)}, /* Sparklan */
77 {USB_DEVICE(0x083A, 0xB522)}, /* SMC */
78 {USB_DEVICE(0x083A, 0xA618)}, /* SMC */
79 {USB_DEVICE(0x083A, 0x8522)}, /* Arcadyan */
80 {USB_DEVICE(0x083A, 0x7522)}, /* Arcadyan */
81 {USB_DEVICE(0x0CDE, 0x0022)}, /* ZCOM */
82 {USB_DEVICE(0x0586, 0x3416)}, /* Zyxel */
83 {USB_DEVICE(0x0586, 0x341a)}, /* Zyxel NWD-270N */
84 {USB_DEVICE(0x0CDE, 0x0025)}, /* Zyxel */
85 {USB_DEVICE(0x1740, 0x9701)}, /* EnGenius */
86 {USB_DEVICE(0x1740, 0x9702)}, /* EnGenius */
87 {USB_DEVICE(0x0471, 0x200f)}, /* Philips */
88 {USB_DEVICE(0x14B2, 0x3C25)}, /* Draytek */
89 {USB_DEVICE(0x13D3, 0x3247)}, /* AzureWave */
90 {USB_DEVICE(0x083A, 0x6618)}, /* Accton */
91 {USB_DEVICE(0x15c5, 0x0008)}, /* Amit */
92 {USB_DEVICE(0x0E66, 0x0001)}, /* Hawking */
93 {USB_DEVICE(0x0E66, 0x0003)}, /* Hawking */
94 {USB_DEVICE(0x129B, 0x1828)}, /* Siemens */
95 {USB_DEVICE(0x157E, 0x300E)}, /* U-Media */
96 {USB_DEVICE(0x050d, 0x805c)},
97 {USB_DEVICE(0x050d, 0x815c)},
98 {USB_DEVICE(0x1482, 0x3C09)}, /* Abocom */
99 {USB_DEVICE(0x14B2, 0x3C09)}, /* Alpha */
100 {USB_DEVICE(0x04E8, 0x2018)}, /* samsung linkstick2 */
101 {USB_DEVICE(0x1690, 0x0740)}, /* Askey */
102 {USB_DEVICE(0x5A57, 0x0280)}, /* Zinwell */
103 {USB_DEVICE(0x5A57, 0x0282)}, /* Zinwell */
104 {USB_DEVICE(0x7392, 0x7718)},
105 {USB_DEVICE(0x7392, 0x7717)},
106 {USB_DEVICE(0x0411, 0x016f)}, /* MelCo.,Inc. WLI-UC-G301N */
107 {USB_DEVICE(0x1737, 0x0070)}, /* Linksys WUSB100 */
108 {USB_DEVICE(0x1737, 0x0071)}, /* Linksys WUSB600N */
109 {USB_DEVICE(0x1737, 0x0078)}, /* Linksys WUSB100v2 */
110 {USB_DEVICE(0x0411, 0x00e8)}, /* Buffalo WLI-UC-G300N */
111 {USB_DEVICE(0x050d, 0x815c)}, /* Belkin F5D8053 */
112 {USB_DEVICE(0x100D, 0x9031)}, /* Motorola 2770 */
113#endif /* RT2870 // */
114#ifdef RT3070
115 {USB_DEVICE(0x148F, 0x3070)}, /* Ralink 3070 */
116 {USB_DEVICE(0x148F, 0x3071)}, /* Ralink 3071 */
117 {USB_DEVICE(0x148F, 0x3072)}, /* Ralink 3072 */
118 {USB_DEVICE(0x0DB0, 0x3820)}, /* Ralink 3070 */
119 {USB_DEVICE(0x0DB0, 0x871C)}, /* Ralink 3070 */
120 {USB_DEVICE(0x0DB0, 0x822C)}, /* Ralink 3070 */
121 {USB_DEVICE(0x0DB0, 0x871B)}, /* Ralink 3070 */
122 {USB_DEVICE(0x0DB0, 0x822B)}, /* Ralink 3070 */
123 {USB_DEVICE(0x0DF6, 0x003E)}, /* Sitecom 3070 */
124 {USB_DEVICE(0x0DF6, 0x0042)}, /* Sitecom 3072 */
125 {USB_DEVICE(0x0DF6, 0x0048)}, /* Sitecom 3070 */
126 {USB_DEVICE(0x0DF6, 0x0047)}, /* Sitecom 3071 */
127 {USB_DEVICE(0x14B2, 0x3C12)}, /* AL 3070 */
128 {USB_DEVICE(0x18C5, 0x0012)}, /* Corega 3070 */
129 {USB_DEVICE(0x083A, 0x7511)}, /* Arcadyan 3070 */
130 {USB_DEVICE(0x083A, 0xA701)}, /* SMC 3070 */
131 {USB_DEVICE(0x083A, 0xA702)}, /* SMC 3072 */
132 {USB_DEVICE(0x1740, 0x9703)}, /* EnGenius 3070 */
133 {USB_DEVICE(0x1740, 0x9705)}, /* EnGenius 3071 */
134 {USB_DEVICE(0x1740, 0x9706)}, /* EnGenius 3072 */
135 {USB_DEVICE(0x1740, 0x9707)}, /* EnGenius 3070 */
136 {USB_DEVICE(0x1740, 0x9708)}, /* EnGenius 3071 */
137 {USB_DEVICE(0x1740, 0x9709)}, /* EnGenius 3072 */
138 {USB_DEVICE(0x13D3, 0x3273)}, /* AzureWave 3070 */
139 {USB_DEVICE(0x13D3, 0x3305)}, /* AzureWave 3070*/
140 {USB_DEVICE(0x1044, 0x800D)}, /* Gigabyte GN-WB32L 3070 */
141 {USB_DEVICE(0x2019, 0xAB25)}, /* Planex Communications, Inc. RT3070 */
142 {USB_DEVICE(0x07B8, 0x3070)}, /* AboCom 3070 */
143 {USB_DEVICE(0x07B8, 0x3071)}, /* AboCom 3071 */
144 {USB_DEVICE(0x07B8, 0x3072)}, /* Abocom 3072 */
145 {USB_DEVICE(0x7392, 0x7711)}, /* Edimax 3070 */
146 {USB_DEVICE(0x1A32, 0x0304)}, /* Quanta 3070 */
147 {USB_DEVICE(0x1EDA, 0x2310)}, /* AirTies 3070 */
148 {USB_DEVICE(0x07D1, 0x3C0A)}, /* D-Link 3072 */
149 {USB_DEVICE(0x07D1, 0x3C0D)}, /* D-Link 3070 */
150 {USB_DEVICE(0x07D1, 0x3C0E)}, /* D-Link 3070 */
151 {USB_DEVICE(0x07D1, 0x3C0F)}, /* D-Link 3070 */
152 {USB_DEVICE(0x07D1, 0x3C16)}, /* D-Link 3070 */
153 {USB_DEVICE(0x07D1, 0x3C17)}, /* D-Link 8070 */
154 {USB_DEVICE(0x1D4D, 0x000C)}, /* Pegatron Corporation 3070 */
155 {USB_DEVICE(0x1D4D, 0x000E)}, /* Pegatron Corporation 3070 */
156 {USB_DEVICE(0x5A57, 0x5257)}, /* Zinwell 3070 */
157 {USB_DEVICE(0x5A57, 0x0283)}, /* Zinwell 3072 */
158 {USB_DEVICE(0x04BB, 0x0945)}, /* I-O DATA 3072 */
159 {USB_DEVICE(0x04BB, 0x0947)}, /* I-O DATA 3070 */
160 {USB_DEVICE(0x04BB, 0x0948)}, /* I-O DATA 3072 */
161 {USB_DEVICE(0x203D, 0x1480)}, /* Encore 3070 */
162 {USB_DEVICE(0x20B8, 0x8888)}, /* PARA INDUSTRIAL 3070 */
163 {USB_DEVICE(0x0B05, 0x1784)}, /* Asus 3072 */
164 {USB_DEVICE(0x203D, 0x14A9)}, /* Encore 3070*/
165 {USB_DEVICE(0x0DB0, 0x899A)}, /* MSI 3070*/
166 {USB_DEVICE(0x0DB0, 0x3870)}, /* MSI 3070*/
167 {USB_DEVICE(0x0DB0, 0x870A)}, /* MSI 3070*/
168 {USB_DEVICE(0x0DB0, 0x6899)}, /* MSI 3070 */
169 {USB_DEVICE(0x0DB0, 0x3822)}, /* MSI 3070 */
170 {USB_DEVICE(0x0DB0, 0x3871)}, /* MSI 3070 */
171 {USB_DEVICE(0x0DB0, 0x871A)}, /* MSI 3070 */
172 {USB_DEVICE(0x0DB0, 0x822A)}, /* MSI 3070 */
173 {USB_DEVICE(0x0DB0, 0x3821)}, /* Ralink 3070 */
174 {USB_DEVICE(0x0DB0, 0x821A)}, /* Ralink 3070 */
175 {USB_DEVICE(0x083A, 0xA703)}, /* IO-MAGIC */
176 {USB_DEVICE(0x13D3, 0x3307)}, /* Azurewave */
177 {USB_DEVICE(0x13D3, 0x3321)}, /* Azurewave */
178 {USB_DEVICE(0x07FA, 0x7712)}, /* Edimax */
179 {USB_DEVICE(0x0789, 0x0166)}, /* Edimax */
180 {USB_DEVICE(0x148F, 0x2070)}, /* Edimax */
181#endif /* RT3070 // */
182 {USB_DEVICE(0x1737, 0x0077)}, /* Linksys WUSB54GC-EU v3 */
183 {USB_DEVICE(0x2001, 0x3C09)}, /* D-Link */
184 {USB_DEVICE(0x2001, 0x3C0A)}, /* D-Link 3072 */
185 {USB_DEVICE(0x2019, 0xED14)}, /* Planex Communications, Inc. */
186 {USB_DEVICE(0x0411, 0x015D)}, /* Buffalo Airstation WLI-UC-GN */
187 {} /* Terminating entry */
188};
189
190int const rtusb_usb_id_len =
191 sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);
192
193MODULE_DEVICE_TABLE(usb, rtusb_usb_id);
194
195static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pAd);
196
197static int __devinit rt2870_probe(IN struct usb_interface *intf,
198 IN struct usb_device *usb_dev,
199 IN const struct usb_device_id *dev_id,
200 struct rt_rtmp_adapter **ppAd);
201
202#ifndef PF_NOFREEZE
203#define PF_NOFREEZE 0
204#endif
205
206extern int rt28xx_close(IN struct net_device *net_dev);
207extern int rt28xx_open(struct net_device *net_dev);
208
209static BOOLEAN USBDevConfigInit(IN struct usb_device *dev,
210 IN struct usb_interface *intf,
211 struct rt_rtmp_adapter *pAd);
212
213/*
214========================================================================
215Routine Description:
216 Check the chipset vendor/product ID.
217
218Arguments:
219 _dev_p Point to the PCI or USB device
220
221Return Value:
222 TRUE Check ok
223 FALSE Check fail
224
225Note:
226========================================================================
227*/
228BOOLEAN RT28XXChipsetCheck(IN void *_dev_p)
229{
230 struct usb_interface *intf = (struct usb_interface *)_dev_p;
231 struct usb_device *dev_p = interface_to_usbdev(intf);
232 u32 i;
233
234 for (i = 0; i < rtusb_usb_id_len; i++) {
235 if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
236 dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct) {
237 printk(KERN_INFO "rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
238 dev_p->descriptor.idVendor,
239 dev_p->descriptor.idProduct);
240 break;
241 }
242 }
243
244 if (i == rtusb_usb_id_len) {
245 printk(KERN_ERR "rt2870: Error! Device Descriptor not matching!\n");
246 return FALSE;
247 }
248
249 return TRUE;
250}
251
252/**************************************************************************/
253/**************************************************************************/
254/*tested for kernel 2.6series */
255/**************************************************************************/
256/**************************************************************************/
257
258#ifdef CONFIG_PM
259static int rt2870_suspend(struct usb_interface *intf, pm_message_t state);
260static int rt2870_resume(struct usb_interface *intf);
261#endif /* CONFIG_PM // */
262
263static BOOLEAN USBDevConfigInit(IN struct usb_device *dev,
264 IN struct usb_interface *intf,
265 struct rt_rtmp_adapter *pAd)
266{
267 struct usb_host_interface *iface_desc;
268 unsigned long BulkOutIdx;
269 u32 i;
270
271 /* get the active interface descriptor */
272 iface_desc = intf->cur_altsetting;
273
274 /* get # of enpoints */
275 pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints;
276 DBGPRINT(RT_DEBUG_TRACE,
277 ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints));
278
279 /* Configure Pipes */
280 BulkOutIdx = 0;
281
282 for (i = 0; i < pAd->NumberOfPipes; i++) {
283 if ((iface_desc->endpoint[i].desc.bmAttributes ==
284 USB_ENDPOINT_XFER_BULK) &&
285 ((iface_desc->endpoint[i].desc.bEndpointAddress &
286 USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)) {
287 pAd->BulkInEpAddr =
288 iface_desc->endpoint[i].desc.bEndpointAddress;
289 pAd->BulkInMaxPacketSize =
290 le2cpu16(iface_desc->endpoint[i].desc.
291 wMaxPacketSize);
292
293 DBGPRINT_RAW(RT_DEBUG_TRACE,
294 ("BULK IN MaxPacketSize = %d\n",
295 pAd->BulkInMaxPacketSize));
296 DBGPRINT_RAW(RT_DEBUG_TRACE,
297 ("EP address = 0x%2x\n",
298 iface_desc->endpoint[i].desc.
299 bEndpointAddress));
300 } else
301 if ((iface_desc->endpoint[i].desc.bmAttributes ==
302 USB_ENDPOINT_XFER_BULK)
303 &&
304 ((iface_desc->endpoint[i].desc.
305 bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
306 USB_DIR_OUT)) {
307 /* there are 6 bulk out EP. EP6 highest priority. */
308 /* EP1-4 is EDCA. EP5 is HCCA. */
309 pAd->BulkOutEpAddr[BulkOutIdx++] =
310 iface_desc->endpoint[i].desc.bEndpointAddress;
311 pAd->BulkOutMaxPacketSize =
312 le2cpu16(iface_desc->endpoint[i].desc.
313 wMaxPacketSize);
314
315 DBGPRINT_RAW(RT_DEBUG_TRACE,
316 ("BULK OUT MaxPacketSize = %d\n",
317 pAd->BulkOutMaxPacketSize));
318 DBGPRINT_RAW(RT_DEBUG_TRACE,
319 ("EP address = 0x%2x \n",
320 iface_desc->endpoint[i].desc.
321 bEndpointAddress));
322 }
323 }
324
325 if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) {
326 printk
327 (KERN_ERR "%s: Could not find both bulk-in and bulk-out endpoints\n",
328 __FUNCTION__);
329 return FALSE;
330 }
331
332 pAd->config = &dev->config->desc;
333 usb_set_intfdata(intf, pAd);
334
335 return TRUE;
336
337}
338
339static int __devinit rtusb_probe(struct usb_interface *intf,
340 const struct usb_device_id *id)
341{
342 struct rt_rtmp_adapter *pAd;
343 struct usb_device *dev;
344 int rv;
345
346 dev = interface_to_usbdev(intf);
347 dev = usb_get_dev(dev);
348
349 rv = rt2870_probe(intf, dev, id, &pAd);
350 if (rv != 0)
351 usb_put_dev(dev);
352
353 return rv;
354}
355
356static void rtusb_disconnect(struct usb_interface *intf)
357{
358 struct usb_device *dev = interface_to_usbdev(intf);
359 struct rt_rtmp_adapter *pAd;
360
361 pAd = usb_get_intfdata(intf);
362 usb_set_intfdata(intf, NULL);
363
364 rt2870_disconnect(dev, pAd);
365}
366
367struct usb_driver rtusb_driver = {
368 .name = "rt2870",
369 .probe = rtusb_probe,
370 .disconnect = rtusb_disconnect,
371 .id_table = rtusb_usb_id,
372
373#ifdef CONFIG_PM
374suspend:rt2870_suspend,
375resume:rt2870_resume,
376#endif
377};
378
379#ifdef CONFIG_PM
380
381void RT2870RejectPendingPackets(struct rt_rtmp_adapter *pAd)
382{
383 /* clear PS packets */
384 /* clear TxSw packets */
385}
386
387static int rt2870_suspend(struct usb_interface *intf, pm_message_t state)
388{
389 struct net_device *net_dev;
390 struct rt_rtmp_adapter *pAd = usb_get_intfdata(intf);
391
392 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n"));
393 net_dev = pAd->net_dev;
394 netif_device_detach(net_dev);
395
396 pAd->PM_FlgSuspend = 1;
397 if (netif_running(net_dev)) {
398 RTUSBCancelPendingBulkInIRP(pAd);
399 RTUSBCancelPendingBulkOutIRP(pAd);
400 }
401 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n"));
402 return 0;
403}
404
405static int rt2870_resume(struct usb_interface *intf)
406{
407 struct net_device *net_dev;
408 struct rt_rtmp_adapter *pAd = usb_get_intfdata(intf);
409
410 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n"));
411
412 pAd->PM_FlgSuspend = 0;
413 net_dev = pAd->net_dev;
414 netif_device_attach(net_dev);
415 netif_start_queue(net_dev);
416 netif_carrier_on(net_dev);
417 netif_wake_queue(net_dev);
418
419 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n"));
420 return 0;
421}
422#endif /* CONFIG_PM // */
423
424/* Init driver module */
425int __init rtusb_init(void)
426{
427 printk(KERN_DEBUG "rtusb init --->\n");
428 return usb_register(&rtusb_driver);
429}
430
431/* Deinit driver module */
432void __exit rtusb_exit(void)
433{
434 usb_deregister(&rtusb_driver);
435 printk(KERN_DEBUG "<--- rtusb exit\n");
436}
437
438module_init(rtusb_init);
439module_exit(rtusb_exit);
440
441/*--------------------------------------------------------------------- */
442/* function declarations */
443/*--------------------------------------------------------------------- */
444
445/*
446========================================================================
447Routine Description:
448 MLME kernel thread.
449
450Arguments:
451 *Context the pAd, driver control block pointer
452
453Return Value:
454 0 close the thread
455
456Note:
457========================================================================
458*/
459int MlmeThread(IN void *Context)
460{
461 struct rt_rtmp_adapter *pAd;
462 struct rt_rtmp_os_task *pTask;
463 int status;
464 status = 0;
465
466 pTask = Context;
467 pAd = pTask->priv;
468
469 RtmpOSTaskCustomize(pTask);
470
471 while (!pTask->task_killed) {
472#ifdef KTHREAD_SUPPORT
473 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
474#else
475 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
476
477 /* unlock the device pointers */
478 if (status != 0) {
479 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
480 break;
481 }
482#endif
483
484 /* lock the device pointers , need to check if required */
485 /*down(&(pAd->usbdev_semaphore)); */
486
487 if (!pAd->PM_FlgSuspend)
488 MlmeHandler(pAd);
489 }
490
491 /* notify the exit routine that we're actually exiting now
492 *
493 * complete()/wait_for_completion() is similar to up()/down(),
494 * except that complete() is safe in the case where the structure
495 * is getting deleted in a parallel mode of execution (i.e. just
496 * after the down() -- that's necessary for the thread-shutdown
497 * case.
498 *
499 * complete_and_exit() goes even further than this -- it is safe in
500 * the case that the thread of the caller is going away (not just
501 * the structure) -- this is necessary for the module-remove case.
502 * This is important in preemption kernels, which transfer the flow
503 * of execution immediately upon a complete().
504 */
505 DBGPRINT(RT_DEBUG_TRACE, ("<---%s\n", __FUNCTION__));
506#ifndef KTHREAD_SUPPORT
507 pTask->taskPID = THREAD_PID_INIT_VALUE;
508 complete_and_exit(&pTask->taskComplete, 0);
509#endif
510 return 0;
511
512}
513
514/*
515========================================================================
516Routine Description:
517 USB command kernel thread.
518
519Arguments:
520 *Context the pAd, driver control block pointer
521
522Return Value:
523 0 close the thread
524
525Note:
526========================================================================
527*/
528int RTUSBCmdThread(IN void *Context)
529{
530 struct rt_rtmp_adapter *pAd;
531 struct rt_rtmp_os_task *pTask;
532 int status;
533 status = 0;
534
535 pTask = Context;
536 pAd = pTask->priv;
537
538 RtmpOSTaskCustomize(pTask);
539
540 NdisAcquireSpinLock(&pAd->CmdQLock);
541 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_RUNNING;
542 NdisReleaseSpinLock(&pAd->CmdQLock);
543
544 while (pAd && pAd->CmdQ.CmdQState == RTMP_TASK_STAT_RUNNING) {
545#ifdef KTHREAD_SUPPORT
546 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
547#else
548 /* lock the device pointers */
549 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
550
551 if (status != 0) {
552 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
553 break;
554 }
555#endif
556
557 if (pAd->CmdQ.CmdQState == RTMP_TASK_STAT_STOPED)
558 break;
559
560 if (!pAd->PM_FlgSuspend)
561 CMDHandler(pAd);
562 }
563
564 if (pAd && !pAd->PM_FlgSuspend) { /* Clear the CmdQElements. */
565 struct rt_cmdqelmt *pCmdQElmt = NULL;
566
567 NdisAcquireSpinLock(&pAd->CmdQLock);
568 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_STOPED;
569 while (pAd->CmdQ.size) {
570 RTUSBDequeueCmd(&pAd->CmdQ, &pCmdQElmt);
571 if (pCmdQElmt) {
572 if (pCmdQElmt->CmdFromNdis == TRUE) {
573 if (pCmdQElmt->buffer != NULL)
574 os_free_mem(pAd,
575 pCmdQElmt->buffer);
576 os_free_mem(pAd, (u8 *)pCmdQElmt);
577 } else {
578 if ((pCmdQElmt->buffer != NULL)
579 && (pCmdQElmt->bufferlength != 0))
580 os_free_mem(pAd,
581 pCmdQElmt->buffer);
582 os_free_mem(pAd, (u8 *)pCmdQElmt);
583 }
584 }
585 }
586
587 NdisReleaseSpinLock(&pAd->CmdQLock);
588 }
589 /* notify the exit routine that we're actually exiting now
590 *
591 * complete()/wait_for_completion() is similar to up()/down(),
592 * except that complete() is safe in the case where the structure
593 * is getting deleted in a parallel mode of execution (i.e. just
594 * after the down() -- that's necessary for the thread-shutdown
595 * case.
596 *
597 * complete_and_exit() goes even further than this -- it is safe in
598 * the case that the thread of the caller is going away (not just
599 * the structure) -- this is necessary for the module-remove case.
600 * This is important in preemption kernels, which transfer the flow
601 * of execution immediately upon a complete().
602 */
603 DBGPRINT(RT_DEBUG_TRACE, ("<---RTUSBCmdThread\n"));
604
605#ifndef KTHREAD_SUPPORT
606 pTask->taskPID = THREAD_PID_INIT_VALUE;
607 complete_and_exit(&pTask->taskComplete, 0);
608#endif
609 return 0;
610
611}
612
613void RTUSBWatchDog(struct rt_rtmp_adapter *pAd)
614{
615 struct rt_ht_tx_context *pHTTXContext;
616 int idx;
617 unsigned long irqFlags;
618 PURB pUrb;
619 BOOLEAN needDumpSeq = FALSE;
620 u32 MACValue;
621 u32 TxRxQ_Pcnt;
622
623 idx = 0;
624 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
625 if ((MACValue & 0xff) != 0) {
626 DBGPRINT(RT_DEBUG_TRACE,
627 ("TX QUEUE 0 Not EMPTY(Value=0x%0x)!\n",
628 MACValue));
629 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40012);
630 while ((MACValue & 0xff) != 0 && (idx++ < 10)) {
631 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
632 RTMPusecDelay(1);
633 }
634 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
635 }
636
637 if (pAd->watchDogRxOverFlowCnt >= 2) {
638 DBGPRINT(RT_DEBUG_TRACE,
639 ("Maybe the Rx Bulk-In hanged! Cancel the pending Rx bulks request!\n"));
640 if ((!RTMP_TEST_FLAG
641 (pAd,
642 (fRTMP_ADAPTER_RESET_IN_PROGRESS |
643 fRTMP_ADAPTER_BULKIN_RESET |
644 fRTMP_ADAPTER_HALT_IN_PROGRESS |
645 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
646 DBGPRINT(RT_DEBUG_TRACE,
647 ("Call CMDTHREAD_RESET_BULK_IN to cancel the pending Rx Bulk!\n"));
648 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
649 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN,
650 NULL, 0);
651 needDumpSeq = TRUE;
652 }
653 pAd->watchDogRxOverFlowCnt = 0;
654 }
655
656 RTUSBReadMACRegister(pAd, 0x438, &TxRxQ_Pcnt);
657
658 for (idx = 0; idx < NUM_OF_TX_RING; idx++) {
659 pUrb = NULL;
660
661 RTMP_IRQ_LOCK(&pAd->BulkOutLock[idx], irqFlags);
662 if ((pAd->BulkOutPending[idx] == TRUE)
663 && pAd->watchDogTxPendingCnt) {
664 int actual_length = 0, transfer_buffer_length = 0;
665 BOOLEAN isDataPacket = FALSE;
666 pAd->watchDogTxPendingCnt[idx]++;
667
668 if ((pAd->watchDogTxPendingCnt[idx] > 2) &&
669 (!RTMP_TEST_FLAG
670 (pAd,
671 (fRTMP_ADAPTER_RESET_IN_PROGRESS |
672 fRTMP_ADAPTER_HALT_IN_PROGRESS |
673 fRTMP_ADAPTER_NIC_NOT_EXIST |
674 fRTMP_ADAPTER_BULKOUT_RESET)))
675 ) {
676 /* FIXME: Following code just support single bulk out. If you wanna support multiple bulk out. Modify it! */
677 pHTTXContext =
678 (struct rt_ht_tx_context *)(&pAd->TxContext[idx]);
679 if (pHTTXContext->IRPPending) { /* Check TxContext. */
680 pUrb = pHTTXContext->pUrb;
681
682 actual_length = pUrb->actual_length;
683 transfer_buffer_length =
684 pUrb->transfer_buffer_length;
685 isDataPacket = TRUE;
686 } else if (idx == MGMTPIPEIDX) {
687 struct rt_tx_context *pMLMEContext, *pNULLContext,
688 *pPsPollContext;
689
690 /*Check MgmtContext. */
691 pMLMEContext =
692 (struct rt_tx_context *)(pAd->MgmtRing.
693 Cell[pAd->MgmtRing.
694 TxDmaIdx].
695 AllocVa);
696 pPsPollContext =
697 (struct rt_tx_context *)(&pAd->PsPollContext);
698 pNULLContext =
699 (struct rt_tx_context *)(&pAd->NullContext);
700
701 if (pMLMEContext->IRPPending) {
702 ASSERT(pMLMEContext->
703 IRPPending);
704 pUrb = pMLMEContext->pUrb;
705 } else if (pNULLContext->IRPPending) {
706 ASSERT(pNULLContext->
707 IRPPending);
708 pUrb = pNULLContext->pUrb;
709 } else if (pPsPollContext->IRPPending) {
710 ASSERT(pPsPollContext->
711 IRPPending);
712 pUrb = pPsPollContext->pUrb;
713 }
714 }
715
716 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx],
717 irqFlags);
718
719 printk(KERN_INFO "%d:%lu LTL=%d , TL=%d L:%d\n",
720 idx, pAd->watchDogTxPendingCnt[idx],
721 pAd->TransferedLength[idx],
722 actual_length, transfer_buffer_length);
723
724 if (pUrb) {
725 if ((isDataPacket
726 && pAd->TransferedLength[idx] ==
727 actual_length
728 && pAd->TransferedLength[idx] <
729 transfer_buffer_length
730 && actual_length != 0
731/* && TxRxQ_Pcnt==0 */
732 && pAd->watchDogTxPendingCnt[idx] >
733 3)
734 || isDataPacket == FALSE
735 || pAd->watchDogTxPendingCnt[idx] >
736 6) {
737 DBGPRINT(RT_DEBUG_TRACE,
738 ("Maybe the Tx Bulk-Out hanged! Cancel the pending Tx bulks request of idx(%d)!\n",
739 idx));
740 DBGPRINT(RT_DEBUG_TRACE,
741 ("Unlink the pending URB!\n"));
742 /* unlink it now */
743 RTUSB_UNLINK_URB(pUrb);
744 /* Sleep 200 microseconds to give cancellation time to work */
745 /*RTMPusecDelay(200); */
746 needDumpSeq = TRUE;
747 }
748 } else {
749 DBGPRINT(RT_DEBUG_ERROR,
750 ("Unknown bulkOut URB maybe hanged!\n"));
751 }
752 } else {
753 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx],
754 irqFlags);
755 }
756
757 if (isDataPacket == TRUE)
758 pAd->TransferedLength[idx] = actual_length;
759 } else {
760 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
761 }
762 }
763
764 /* For Sigma debug, dump the ba_reordering sequence. */
765 if ((needDumpSeq == TRUE) && (pAd->CommonCfg.bDisableReordering == 0)) {
766 u16 Idx;
767 struct rt_ba_rec_entry *pBAEntry = NULL;
768 u8 count = 0;
769 struct reordering_mpdu *mpdu_blk;
770
771 Idx = pAd->MacTab.Content[BSSID_WCID].BARecWcidArray[0];
772
773 pBAEntry = &pAd->BATable.BARecEntry[Idx];
774 if ((pBAEntry->list.qlen > 0) && (pBAEntry->list.next != NULL)) {
775 DBGPRINT(RT_DEBUG_TRACE,
776 ("NICUpdateRawCounters():The Queueing pkt in reordering buffer:\n"));
777 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
778 mpdu_blk = pBAEntry->list.next;
779 while (mpdu_blk) {
780 DBGPRINT(RT_DEBUG_TRACE,
781 ("\t%d:Seq-%d, bAMSDU-%d!\n", count,
782 mpdu_blk->Sequence,
783 mpdu_blk->bAMSDU));
784 mpdu_blk = mpdu_blk->next;
785 count++;
786 }
787
788 DBGPRINT(RT_DEBUG_TRACE,
789 ("\npBAEntry->LastIndSeq=%d!\n",
790 pBAEntry->LastIndSeq));
791 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
792 }
793 }
794}
795
796/*
797========================================================================
798Routine Description:
799 Release allocated resources.
800
801Arguments:
802 *dev Point to the PCI or USB device
803 pAd driver control block pointer
804
805Return Value:
806 None
807
808Note:
809========================================================================
810*/
811static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pAd)
812{
813 DBGPRINT(RT_DEBUG_ERROR,
814 ("rtusb_disconnect: unregister usbnet usb-%s-%s\n",
815 dev->bus->bus_name, dev->devpath));
816 if (!pAd) {
817 usb_put_dev(dev);
818 printk(KERN_ERR "rtusb_disconnect: pAd == NULL!\n");
819 return;
820 }
821 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
822
823 /* for debug, wait to show some messages to /proc system */
824 udelay(1);
825
826 RtmpPhyNetDevExit(pAd, pAd->net_dev);
827
828 /* FIXME: Shall we need following delay and flush the schedule?? */
829 udelay(1);
830 flush_scheduled_work();
831 udelay(1);
832
833 /* free the root net_device */
834 RtmpOSNetDevFree(pAd->net_dev);
835
836 RtmpRaDevCtrlExit(pAd);
837
838 /* release a use of the usb device structure */
839 usb_put_dev(dev);
840 udelay(1);
841
842 DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n"));
843}
844
845static int __devinit rt2870_probe(IN struct usb_interface *intf,
846 IN struct usb_device *usb_dev,
847 IN const struct usb_device_id *dev_id,
848 struct rt_rtmp_adapter **ppAd)
849{
850 struct net_device *net_dev = NULL;
851 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL;
852 int status, rv;
853 void *handle;
854 struct rt_rtmp_os_netdev_op_hook netDevHook;
855
856 DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n"));
857
858 /* Check chipset vendor/product ID */
859 /*if (RT28XXChipsetCheck(_dev_p) == FALSE) */
860 /* goto err_out; */
861
862/*RtmpDevInit============================================= */
863 /* Allocate struct rt_rtmp_adapter adapter structure */
864 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
865 if (handle == NULL) {
866 printk
867 ("rt2870_probe(): Allocate memory for os handle failed!\n");
868 return -ENOMEM;
869 }
870 ((struct os_cookie *)handle)->pUsb_Dev = usb_dev;
871
872 rv = RTMPAllocAdapterBlock(handle, &pAd);
873 if (rv != NDIS_STATUS_SUCCESS) {
874 kfree(handle);
875 goto err_out;
876 }
877/*USBDevInit============================================== */
878 if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE)
879 goto err_out_free_radev;
880
881 RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_USB);
882
883/*NetDevInit============================================== */
884 net_dev = RtmpPhyNetDevInit(pAd, &netDevHook);
885 if (net_dev == NULL)
886 goto err_out_free_radev;
887
888 /* Here are the net_device structure with usb specific parameters.
889 * for supporting Network Manager.
890 * Set the sysfs physical device reference for the network logical device if set prior to registration will
891 * cause a symlink during initialization.
892 */
893 SET_NETDEV_DEV(net_dev, &(usb_dev->dev));
894
895 pAd->StaCfg.OriDevType = net_dev->type;
896
897/*All done, it's time to register the net device to linux kernel. */
898 /* Register this device */
899 status = RtmpOSNetDevAttach(net_dev, &netDevHook);
900 if (status != 0)
901 goto err_out_free_netdev;
902
903#ifdef KTHREAD_SUPPORT
904 init_waitqueue_head(&pAd->mlmeTask.kthread_q);
905 init_waitqueue_head(&pAd->timerTask.kthread_q);
906 init_waitqueue_head(&pAd->cmdQTask.kthread_q);
907#endif
908
909 *ppAd = pAd;
910
911 DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n"));
912
913 return 0;
914
915 /* --------------------------- ERROR HANDLE --------------------------- */
916err_out_free_netdev:
917 RtmpOSNetDevFree(net_dev);
918
919err_out_free_radev:
920 RTMPFreeAdapter(pAd);
921
922err_out:
923 *ppAd = NULL;
924
925 return -1;
926
927}
diff --git a/drivers/staging/rt2860/wpa.h b/drivers/staging/rt2860/wpa.h
deleted file mode 100644
index a7796d330b7..00000000000
--- a/drivers/staging/rt2860/wpa.h
+++ /dev/null
@@ -1,390 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 wpa.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Justin P. Mattock 11/07/2010 Fix a typo
37*/
38
39#ifndef __WPA_H__
40#define __WPA_H__
41
42/* EAPOL Key descriptor frame format related length */
43#define LEN_KEY_DESC_NONCE 32
44#define LEN_KEY_DESC_IV 16
45#define LEN_KEY_DESC_RSC 8
46#define LEN_KEY_DESC_ID 8
47#define LEN_KEY_DESC_REPLAY 8
48#define LEN_KEY_DESC_MIC 16
49
50/* The length is the EAPoL-Key frame except key data field. */
51/* Please refer to 802.11i-2004 ,Figure 43u in p.78 */
52#define LEN_EAPOL_KEY_MSG (sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE)
53
54/* EAP Code Type. */
55#define EAP_CODE_REQUEST 1
56#define EAP_CODE_RESPONSE 2
57#define EAP_CODE_SUCCESS 3
58#define EAP_CODE_FAILURE 4
59
60/* EAPOL frame Protocol Version */
61#define EAPOL_VER 1
62#define EAPOL_VER2 2
63
64/* EAPOL-KEY Descriptor Type */
65#define WPA1_KEY_DESC 0xfe
66#define WPA2_KEY_DESC 0x02
67
68/* Key Descriptor Version of Key Information */
69#define DESC_TYPE_TKIP 1
70#define DESC_TYPE_AES 2
71
72#define LEN_MSG1_2WAY 0x7f
73#define MAX_LEN_OF_EAP_HS 256
74
75#define LEN_MASTER_KEY 32
76
77/* EAPOL EK, MK */
78#define LEN_EAP_EK 16
79#define LEN_EAP_MICK 16
80#define LEN_EAP_KEY ((LEN_EAP_EK)+(LEN_EAP_MICK))
81/* TKIP key related */
82#define LEN_PMKID 16
83#define LEN_TKIP_EK 16
84#define LEN_TKIP_RXMICK 8
85#define LEN_TKIP_TXMICK 8
86#define LEN_AES_EK 16
87#define LEN_AES_KEY LEN_AES_EK
88#define LEN_TKIP_KEY ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK))
89#define TKIP_AP_TXMICK_OFFSET ((LEN_EAP_KEY)+(LEN_TKIP_EK))
90#define TKIP_AP_RXMICK_OFFSET (TKIP_AP_TXMICK_OFFSET+LEN_TKIP_TXMICK)
91#define TKIP_GTK_LENGTH ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK))
92#define LEN_PTK ((LEN_EAP_KEY)+(LEN_TKIP_KEY))
93#define MIN_LEN_OF_GTK 5
94#define LEN_PMK 32
95#define LEN_PMK_NAME 16
96#define LEN_NONCE 32
97
98/* RSN IE Length definition */
99#define MAX_LEN_OF_RSNIE 255
100#define MIN_LEN_OF_RSNIE 8
101
102#define KEY_LIFETIME 3600
103
104/*EAP Packet Type */
105#define EAPPacket 0
106#define EAPOLStart 1
107#define EAPOLLogoff 2
108#define EAPOLKey 3
109#define EAPOLASFAlert 4
110#define EAPTtypeMax 5
111
112#define EAPOL_MSG_INVALID 0
113#define EAPOL_PAIR_MSG_1 1
114#define EAPOL_PAIR_MSG_2 2
115#define EAPOL_PAIR_MSG_3 3
116#define EAPOL_PAIR_MSG_4 4
117#define EAPOL_GROUP_MSG_1 5
118#define EAPOL_GROUP_MSG_2 6
119
120#define PAIRWISEKEY 1
121#define GROUPKEY 0
122
123/* Retry timer counter initial value */
124#define PEER_MSG1_RETRY_TIMER_CTR 0
125#define PEER_MSG3_RETRY_TIMER_CTR 10
126#define GROUP_MSG1_RETRY_TIMER_CTR 20
127
128/*#ifdef CONFIG_AP_SUPPORT */
129/* WPA mechanism retry timer interval */
130#define PEER_MSG1_RETRY_EXEC_INTV 1000 /* 1 sec */
131#define PEER_MSG3_RETRY_EXEC_INTV 3000 /* 3 sec */
132#define GROUP_KEY_UPDATE_EXEC_INTV 1000 /* 1 sec */
133#define PEER_GROUP_KEY_UPDATE_INIV 2000 /* 2 sec */
134
135#define ENQUEUE_EAPOL_START_TIMER 200 /* 200 ms */
136
137/* group rekey interval */
138#define TIME_REKEY 0
139#define PKT_REKEY 1
140#define DISABLE_REKEY 2
141#define MAX_REKEY 2
142
143#define MAX_REKEY_INTER 0x3ffffff
144/*#endif // CONFIG_AP_SUPPORT // */
145
146#define GROUP_SUITE 0
147#define PAIRWISE_SUITE 1
148#define AKM_SUITE 2
149#define PMKID_LIST 3
150
151#define EAPOL_START_DISABLE 0
152#define EAPOL_START_PSK 1
153#define EAPOL_START_1X 2
154
155#define MIX_CIPHER_WPA_TKIP_ON(x) (((x) & 0x08) != 0)
156#define MIX_CIPHER_WPA_AES_ON(x) (((x) & 0x04) != 0)
157#define MIX_CIPHER_WPA2_TKIP_ON(x) (((x) & 0x02) != 0)
158#define MIX_CIPHER_WPA2_AES_ON(x) (((x) & 0x01) != 0)
159
160#ifndef ROUND_UP
161#define ROUND_UP(__x, __y) \
162 (((unsigned long)((__x)+((__y)-1))) & ((unsigned long)~((__y)-1)))
163#endif
164
165#define SET_u16_TO_ARRARY(_V, _LEN) \
166{ \
167 _V[0] = (_LEN & 0xFF00) >> 8; \
168 _V[1] = (_LEN & 0xFF); \
169}
170
171#define INC_u16_TO_ARRARY(_V, _LEN) \
172{ \
173 u16 var_len; \
174 \
175 var_len = (_V[0]<<8) | (_V[1]); \
176 var_len += _LEN; \
177 \
178 _V[0] = (var_len & 0xFF00) >> 8; \
179 _V[1] = (var_len & 0xFF); \
180}
181
182#define CONV_ARRARY_TO_u16(_V) ((_V[0]<<8) | (_V[1]))
183
184#define ADD_ONE_To_64BIT_VAR(_V) \
185{ \
186 u8 cnt = LEN_KEY_DESC_REPLAY; \
187 do \
188 { \
189 cnt--; \
190 _V[cnt]++; \
191 if (cnt == 0) \
192 break; \
193 }while (_V[cnt] == 0); \
194}
195
196#define IS_WPA_CAPABILITY(a) (((a) >= Ndis802_11AuthModeWPA) && ((a) <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
197
198/* EAPOL Key Information definition within Key descriptor format */
199struct PACKED rt_key_info {
200 u8 KeyMic:1;
201 u8 Secure:1;
202 u8 Error:1;
203 u8 Request:1;
204 u8 EKD_DL:1; /* EKD for AP; DL for STA */
205 u8 Rsvd:3;
206 u8 KeyDescVer:3;
207 u8 KeyType:1;
208 u8 KeyIndex:2;
209 u8 Install:1;
210 u8 KeyAck:1;
211};
212
213/* EAPOL Key descriptor format */
214struct PACKED rt_key_descripter {
215 u8 Type;
216 struct rt_key_info KeyInfo;
217 u8 KeyLength[2];
218 u8 ReplayCounter[LEN_KEY_DESC_REPLAY];
219 u8 KeyNonce[LEN_KEY_DESC_NONCE];
220 u8 KeyIv[LEN_KEY_DESC_IV];
221 u8 KeyRsc[LEN_KEY_DESC_RSC];
222 u8 KeyId[LEN_KEY_DESC_ID];
223 u8 KeyMic[LEN_KEY_DESC_MIC];
224 u8 KeyDataLen[2];
225 u8 KeyData[MAX_LEN_OF_RSNIE];
226};
227
228struct PACKED rt_eapol_packet {
229 u8 ProVer;
230 u8 ProType;
231 u8 Body_Len[2];
232 struct rt_key_descripter KeyDesc;
233};
234
235/*802.11i D10 page 83 */
236struct PACKED rt_gtk_encap {
237 u8 Kid:2;
238 u8 tx:1;
239 u8 rsv:5;
240 u8 rsv1;
241 u8 GTK[TKIP_GTK_LENGTH];
242};
243
244struct PACKED rt_kde_encap {
245 u8 Type;
246 u8 Len;
247 u8 OUI[3];
248 u8 DataType;
249 struct rt_gtk_encap GTKEncap;
250};
251
252/* For WPA1 */
253struct PACKED rt_rsnie {
254 u8 oui[4];
255 u16 version;
256 u8 mcast[4];
257 u16 ucount;
258 struct PACKED {
259 u8 oui[4];
260 } ucast[1];
261};
262
263/* For WPA2 */
264struct PACKED rt_rsnie2 {
265 u16 version;
266 u8 mcast[4];
267 u16 ucount;
268 struct PACKED {
269 u8 oui[4];
270 } ucast[1];
271};
272
273/* AKM Suite */
274struct PACKED rt_rsnie_auth {
275 u16 acount;
276 struct PACKED {
277 u8 oui[4];
278 } auth[1];
279};
280
281typedef union PACKED _RSN_CAPABILITIES {
282 struct PACKED {
283 u16 PreAuth:1;
284 u16 No_Pairwise:1;
285 u16 PTKSA_R_Counter:2;
286 u16 GTKSA_R_Counter:2;
287 u16 Rsvd:10;
288 } field;
289 u16 word;
290} RSN_CAPABILITIES, *PRSN_CAPABILITIES;
291
292struct PACKED rt_eap_hdr {
293 u8 ProVer;
294 u8 ProType;
295 u8 Body_Len[2];
296 u8 code;
297 u8 identifier;
298 u8 length[2]; /* including code and identifier, followed by length-2 octets of data */
299};
300
301/* For supplicant state machine states. 802.11i Draft 4.1, p. 97 */
302/* We simplified it */
303typedef enum _WpaState {
304 SS_NOTUSE, /* 0 */
305 SS_START, /* 1 */
306 SS_WAIT_MSG_3, /* 2 */
307 SS_WAIT_GROUP, /* 3 */
308 SS_FINISH, /* 4 */
309 SS_KEYUPDATE, /* 5 */
310} WPA_STATE;
311
312/* */
313/* The definition of the cipher combination */
314/* */
315/* bit3 bit2 bit1 bit0 */
316/* +------------+------------+ */
317/* | WPA | WPA2 | */
318/* +------+-----+------+-----+ */
319/* | TKIP | AES | TKIP | AES | */
320/* | 0 | 1 | 1 | 0 | -> 0x06 */
321/* | 0 | 1 | 1 | 1 | -> 0x07 */
322/* | 1 | 0 | 0 | 1 | -> 0x09 */
323/* | 1 | 0 | 1 | 1 | -> 0x0B */
324/* | 1 | 1 | 0 | 1 | -> 0x0D */
325/* | 1 | 1 | 1 | 0 | -> 0x0E */
326/* | 1 | 1 | 1 | 1 | -> 0x0F */
327/* +------+-----+------+-----+ */
328/* */
329typedef enum _WpaMixPairCipher {
330 MIX_CIPHER_NOTUSE = 0x00,
331 WPA_NONE_WPA2_TKIPAES = 0x03, /* WPA2-TKIPAES */
332 WPA_AES_WPA2_TKIP = 0x06,
333 WPA_AES_WPA2_TKIPAES = 0x07,
334 WPA_TKIP_WPA2_AES = 0x09,
335 WPA_TKIP_WPA2_TKIPAES = 0x0B,
336 WPA_TKIPAES_WPA2_NONE = 0x0C, /* WPA-TKIPAES */
337 WPA_TKIPAES_WPA2_AES = 0x0D,
338 WPA_TKIPAES_WPA2_TKIP = 0x0E,
339 WPA_TKIPAES_WPA2_TKIPAES = 0x0F,
340} WPA_MIX_PAIR_CIPHER;
341
342struct PACKED rt_rsn_ie_header {
343 u8 Eid;
344 u8 Length;
345 u16 Version; /* Little endian format */
346};
347
348/* Cipher suite selector types */
349struct PACKED rt_cipher_suite_struct {
350 u8 Oui[3];
351 u8 Type;
352};
353
354/* Authentication and Key Management suite selector */
355struct PACKED rt_akm_suite {
356 u8 Oui[3];
357 u8 Type;
358};
359
360/* RSN capability */
361struct PACKED rt_rsn_capability {
362 u16 Rsv:10;
363 u16 GTKSAReplayCnt:2;
364 u16 PTKSAReplayCnt:2;
365 u16 NoPairwise:1;
366 u16 PreAuth:1;
367};
368
369/*========================================
370 The prototype is defined in cmm_wpa.c
371 ========================================*/
372BOOLEAN WpaMsgTypeSubst(u8 EAPType, int *MsgType);
373
374void PRF(u8 *key, int key_len, u8 *prefix, int prefix_len,
375 u8 *data, int data_len, u8 *output, int len);
376
377int PasswordHash(char *password,
378 unsigned char *ssid, int ssidlength, unsigned char *output);
379
380u8 *GetSuiteFromRSNIE(u8 *rsnie, u32 rsnie_len, u8 type, u8 *count);
381
382void WpaShowAllsuite(u8 *rsnie, u32 rsnie_len);
383
384void RTMPInsertRSNIE(u8 *pFrameBuf,
385 unsigned long *pFrameLen,
386 u8 *rsnie_ptr,
387 u8 rsnie_len,
388 u8 *pmkid_ptr, u8 pmkid_len);
389
390#endif
diff --git a/drivers/staging/rt2870/Kconfig b/drivers/staging/rt2870/Kconfig
deleted file mode 100644
index e988680b5be..00000000000
--- a/drivers/staging/rt2870/Kconfig
+++ /dev/null
@@ -1,9 +0,0 @@
1config RT2870
2 tristate "Ralink 2870/3070 wireless support"
3 depends on USB && (X86 || ARM) && WLAN
4 select WIRELESS_EXT
5 select WEXT_PRIV
6 select CRC_CCITT
7 select FW_LOADER
8 ---help---
9 This is an experimental driver for the Ralink xx70 wireless chips.
diff --git a/drivers/staging/rt2870/Makefile b/drivers/staging/rt2870/Makefile
deleted file mode 100644
index b499910ed73..00000000000
--- a/drivers/staging/rt2870/Makefile
+++ /dev/null
@@ -1,55 +0,0 @@
1#
2obj-$(CONFIG_RT2870) += rt2870sta.o
3
4# TODO: all of these should be removed
5ccflags-y := -DLINUX -DAGGREGATION_SUPPORT -DPIGGYBACK_SUPPORT -DWMM_SUPPORT
6ccflags-y += -DRTMP_MAC_USB -DRTMP_USB_SUPPORT -DRT2870 -DRTMP_TIMER_TASK_SUPPORT
7ccflags-y += -DRTMP_RF_RW_SUPPORT -DRTMP_EFUSE_SUPPORT -DRT30xx -DRT3070
8ccflags-y += -DDBG
9
10rt2870sta-y := \
11 common/crypt_md5.o \
12 common/crypt_sha2.o \
13 common/crypt_hmac.o \
14 common/mlme.o \
15 common/cmm_wep.o \
16 common/action.o \
17 common/cmm_data.o \
18 common/rtmp_init.o \
19 common/cmm_tkip.o \
20 common/cmm_aes.o \
21 common/cmm_sync.o \
22 common/eeprom.o \
23 common/cmm_sanity.o \
24 common/cmm_info.o \
25 common/cmm_cfg.o \
26 common/cmm_wpa.o \
27 common/dfs.o \
28 common/spectrum.o \
29 common/rtmp_timer.o \
30 common/rt_channel.o \
31 common/cmm_asic.o \
32 sta/assoc.o \
33 sta/auth.o \
34 sta/auth_rsp.o \
35 sta/sync.o \
36 sta/sanity.o \
37 sta/rtmp_data.o \
38 sta/connect.o \
39 sta/wpa.o \
40 rt_linux.o \
41 rt_main_dev.o \
42 sta_ioctl.o \
43 common/ba_action.o \
44 usb_main_dev.o \
45 rt_usb.o \
46 common/cmm_mac_usb.o \
47 common/rtusb_io.o \
48 common/rtusb_bulk.o \
49 common/rtusb_data.o \
50 common/cmm_data_usb.o \
51 common/rtmp_mcu.o \
52 common/ee_efuse.o \
53 chips/rt30xx.o \
54 common/rt_rf.o \
55 chips/rt3070.o
diff --git a/drivers/staging/rt2870/TODO b/drivers/staging/rt2870/TODO
deleted file mode 100644
index 2df1bfed9a5..00000000000
--- a/drivers/staging/rt2870/TODO
+++ /dev/null
@@ -1,17 +0,0 @@
1I'm hesitant to add a TODO file here, as the wireless developers would
2really have people help them out on the "clean" rt2870 driver that can
3be found at the http://rt2x00.serialmonkey.com/ site.
4
5But, if you wish to clean up this driver instead, here's a short list of
6things that need to be done to get it into a more mergable shape:
7
8TODO:
9 - checkpatch.pl clean
10 - sparse clean
11 - port to in-kernel 80211 stack and common rt2x00 infrastructure
12 - remove reading from /etc/ config files
13 - review by the wireless developer community
14
15Please send any patches or complaints about this driver to Greg
16Kroah-Hartman <greg@kroah.com> and don't bother the upstream wireless
17kernel developers about it, they want nothing to do with it.
diff --git a/drivers/staging/rt2870/aironet.h b/drivers/staging/rt2870/aironet.h
deleted file mode 100644
index ae6259710a4..00000000000
--- a/drivers/staging/rt2870/aironet.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/aironet.h"
diff --git a/drivers/staging/rt2870/ap.h b/drivers/staging/rt2870/ap.h
deleted file mode 100644
index fe04b5f45f2..00000000000
--- a/drivers/staging/rt2870/ap.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/ap.h"
diff --git a/drivers/staging/rt2870/chips/rt3070.c b/drivers/staging/rt2870/chips/rt3070.c
deleted file mode 100644
index 3a6db5ea89a..00000000000
--- a/drivers/staging/rt2870/chips/rt3070.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/chips/rt3070.c"
diff --git a/drivers/staging/rt2870/chips/rt30xx.c b/drivers/staging/rt2870/chips/rt30xx.c
deleted file mode 100644
index 6c56b84c75d..00000000000
--- a/drivers/staging/rt2870/chips/rt30xx.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/chips/rt30xx.c"
diff --git a/drivers/staging/rt2870/chlist.h b/drivers/staging/rt2870/chlist.h
deleted file mode 100644
index 31999583b37..00000000000
--- a/drivers/staging/rt2870/chlist.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/chlist.h"
diff --git a/drivers/staging/rt2870/common/acction.c b/drivers/staging/rt2870/common/acction.c
deleted file mode 100644
index fd806c3871a..00000000000
--- a/drivers/staging/rt2870/common/acction.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/action.c"
diff --git a/drivers/staging/rt2870/common/action.c b/drivers/staging/rt2870/common/action.c
deleted file mode 100644
index fd806c3871a..00000000000
--- a/drivers/staging/rt2870/common/action.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/action.c"
diff --git a/drivers/staging/rt2870/common/action.h b/drivers/staging/rt2870/common/action.h
deleted file mode 100644
index 9a1895525f3..00000000000
--- a/drivers/staging/rt2870/common/action.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/action.h"
diff --git a/drivers/staging/rt2870/common/ba_action.c b/drivers/staging/rt2870/common/ba_action.c
deleted file mode 100644
index a9e6a09d994..00000000000
--- a/drivers/staging/rt2870/common/ba_action.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/ba_action.c"
diff --git a/drivers/staging/rt2870/common/cmm_aes.c b/drivers/staging/rt2870/common/cmm_aes.c
deleted file mode 100644
index 15d6a14d2d9..00000000000
--- a/drivers/staging/rt2870/common/cmm_aes.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_aes.c"
diff --git a/drivers/staging/rt2870/common/cmm_asic.c b/drivers/staging/rt2870/common/cmm_asic.c
deleted file mode 100644
index 38de817991f..00000000000
--- a/drivers/staging/rt2870/common/cmm_asic.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_asic.c"
diff --git a/drivers/staging/rt2870/common/cmm_cfg.c b/drivers/staging/rt2870/common/cmm_cfg.c
deleted file mode 100644
index 6b2bdd7d44e..00000000000
--- a/drivers/staging/rt2870/common/cmm_cfg.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_cfg.c"
diff --git a/drivers/staging/rt2870/common/cmm_data.c b/drivers/staging/rt2870/common/cmm_data.c
deleted file mode 100644
index df775c3cf69..00000000000
--- a/drivers/staging/rt2870/common/cmm_data.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_data.c"
diff --git a/drivers/staging/rt2870/common/cmm_data_usb.c b/drivers/staging/rt2870/common/cmm_data_usb.c
deleted file mode 100644
index 704675fccb7..00000000000
--- a/drivers/staging/rt2870/common/cmm_data_usb.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_data_usb.c"
diff --git a/drivers/staging/rt2870/common/cmm_info.c b/drivers/staging/rt2870/common/cmm_info.c
deleted file mode 100644
index 226187ee556..00000000000
--- a/drivers/staging/rt2870/common/cmm_info.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_info.c"
diff --git a/drivers/staging/rt2870/common/cmm_mac_usb.c b/drivers/staging/rt2870/common/cmm_mac_usb.c
deleted file mode 100644
index b26af4af890..00000000000
--- a/drivers/staging/rt2870/common/cmm_mac_usb.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_mac_usb.c"
diff --git a/drivers/staging/rt2870/common/cmm_profile.c b/drivers/staging/rt2870/common/cmm_profile.c
deleted file mode 100644
index 9926e45aba3..00000000000
--- a/drivers/staging/rt2870/common/cmm_profile.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_profile.c"
diff --git a/drivers/staging/rt2870/common/cmm_sanity.c b/drivers/staging/rt2870/common/cmm_sanity.c
deleted file mode 100644
index cb3352118c5..00000000000
--- a/drivers/staging/rt2870/common/cmm_sanity.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_sanity.c"
diff --git a/drivers/staging/rt2870/common/cmm_sync.c b/drivers/staging/rt2870/common/cmm_sync.c
deleted file mode 100644
index 5e7221d7cb2..00000000000
--- a/drivers/staging/rt2870/common/cmm_sync.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_sync.c"
diff --git a/drivers/staging/rt2870/common/cmm_tkip.c b/drivers/staging/rt2870/common/cmm_tkip.c
deleted file mode 100644
index f73c71bafe8..00000000000
--- a/drivers/staging/rt2870/common/cmm_tkip.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_tkip.c"
diff --git a/drivers/staging/rt2870/common/cmm_wep.c b/drivers/staging/rt2870/common/cmm_wep.c
deleted file mode 100644
index 5f681078387..00000000000
--- a/drivers/staging/rt2870/common/cmm_wep.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_wep.c"
diff --git a/drivers/staging/rt2870/common/cmm_wpa.c b/drivers/staging/rt2870/common/cmm_wpa.c
deleted file mode 100644
index 04a54bb2185..00000000000
--- a/drivers/staging/rt2870/common/cmm_wpa.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/cmm_wpa.c"
diff --git a/drivers/staging/rt2870/common/crypt_hmac.c b/drivers/staging/rt2870/common/crypt_hmac.c
deleted file mode 100644
index 24d84e7724f..00000000000
--- a/drivers/staging/rt2870/common/crypt_hmac.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/crypt_hmac.c"
diff --git a/drivers/staging/rt2870/common/crypt_md5.c b/drivers/staging/rt2870/common/crypt_md5.c
deleted file mode 100644
index 457a2caca1e..00000000000
--- a/drivers/staging/rt2870/common/crypt_md5.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/crypt_md5.c"
diff --git a/drivers/staging/rt2870/common/crypt_sha2.c b/drivers/staging/rt2870/common/crypt_sha2.c
deleted file mode 100644
index 07ffb300c19..00000000000
--- a/drivers/staging/rt2870/common/crypt_sha2.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/crypt_sha2.c"
diff --git a/drivers/staging/rt2870/common/dfs.c b/drivers/staging/rt2870/common/dfs.c
deleted file mode 100644
index ac2da4c0e2c..00000000000
--- a/drivers/staging/rt2870/common/dfs.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/dfs.c"
diff --git a/drivers/staging/rt2870/common/ee_efuse.c b/drivers/staging/rt2870/common/ee_efuse.c
deleted file mode 100644
index 0e34e65e5f2..00000000000
--- a/drivers/staging/rt2870/common/ee_efuse.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/ee_efuse.c"
diff --git a/drivers/staging/rt2870/common/eeprom.c b/drivers/staging/rt2870/common/eeprom.c
deleted file mode 100644
index def09658fd8..00000000000
--- a/drivers/staging/rt2870/common/eeprom.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/eeprom.c"
diff --git a/drivers/staging/rt2870/common/md5.c b/drivers/staging/rt2870/common/md5.c
deleted file mode 100644
index 195645c0e1a..00000000000
--- a/drivers/staging/rt2870/common/md5.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/md5.c"
diff --git a/drivers/staging/rt2870/common/mlme.c b/drivers/staging/rt2870/common/mlme.c
deleted file mode 100644
index f88040abd26..00000000000
--- a/drivers/staging/rt2870/common/mlme.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/mlme.c"
diff --git a/drivers/staging/rt2870/common/rt_channel.c b/drivers/staging/rt2870/common/rt_channel.c
deleted file mode 100644
index c8ceb4c177d..00000000000
--- a/drivers/staging/rt2870/common/rt_channel.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/rt_channel.c"
diff --git a/drivers/staging/rt2870/common/rt_rf.c b/drivers/staging/rt2870/common/rt_rf.c
deleted file mode 100644
index b81cff34969..00000000000
--- a/drivers/staging/rt2870/common/rt_rf.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/rt_rf.c"
diff --git a/drivers/staging/rt2870/common/rtmp_init.c b/drivers/staging/rt2870/common/rtmp_init.c
deleted file mode 100644
index eef10efda19..00000000000
--- a/drivers/staging/rt2870/common/rtmp_init.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/rtmp_init.c"
diff --git a/drivers/staging/rt2870/common/rtmp_mcu.c b/drivers/staging/rt2870/common/rtmp_mcu.c
deleted file mode 100644
index 20b7f13d60f..00000000000
--- a/drivers/staging/rt2870/common/rtmp_mcu.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/rtmp_mcu.c"
diff --git a/drivers/staging/rt2870/common/rtmp_timer.c b/drivers/staging/rt2870/common/rtmp_timer.c
deleted file mode 100644
index fd4aedcd5e8..00000000000
--- a/drivers/staging/rt2870/common/rtmp_timer.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/rtmp_timer.c"
diff --git a/drivers/staging/rt2870/common/rtmp_tkip.c b/drivers/staging/rt2870/common/rtmp_tkip.c
deleted file mode 100644
index 240bf67f521..00000000000
--- a/drivers/staging/rt2870/common/rtmp_tkip.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/rtmp_tkip.c"
diff --git a/drivers/staging/rt2870/common/rtmp_wep.c b/drivers/staging/rt2870/common/rtmp_wep.c
deleted file mode 100644
index ae255adc9f7..00000000000
--- a/drivers/staging/rt2870/common/rtmp_wep.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/rtmp_wep.c"
diff --git a/drivers/staging/rt2870/common/rtusb_bulk.c b/drivers/staging/rt2870/common/rtusb_bulk.c
deleted file mode 100644
index 679b802d216..00000000000
--- a/drivers/staging/rt2870/common/rtusb_bulk.c
+++ /dev/null
@@ -1,1232 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtusb_bulk.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Paul Lin 06-25-2004 created
37
38*/
39
40#ifdef RTMP_MAC_USB
41
42#include "../rt_config.h"
43/* Match total 6 bulkout endpoint to corresponding queue. */
44u8 EpToQueue[6] =
45 { FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_MGMT };
46
47/*static BOOLEAN SingleBulkOut = FALSE; */
48
49void RTUSB_FILL_BULK_URB(struct urb *pUrb,
50 struct usb_device *pUsb_Dev,
51 unsigned int bulkpipe,
52 void *pTransferBuf,
53 int BufSize, usb_complete_t Complete, void *pContext)
54{
55
56 usb_fill_bulk_urb(pUrb, pUsb_Dev, bulkpipe, pTransferBuf, BufSize,
57 (usb_complete_t) Complete, pContext);
58
59}
60
61void RTUSBInitTxDesc(struct rt_rtmp_adapter *pAd,
62 struct rt_tx_context *pTxContext,
63 u8 BulkOutPipeId, IN usb_complete_t Func)
64{
65 PURB pUrb;
66 u8 *pSrc = NULL;
67 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
68
69 pUrb = pTxContext->pUrb;
70 ASSERT(pUrb);
71
72 /* Store BulkOut PipeId */
73 pTxContext->BulkOutPipeId = BulkOutPipeId;
74
75 if (pTxContext->bAggregatible) {
76 pSrc = &pTxContext->TransferBuffer->Aggregation[2];
77 } else {
78 pSrc =
79 (u8 *)pTxContext->TransferBuffer->field.WirelessPacket;
80 }
81
82 /*Initialize a tx bulk urb */
83 RTUSB_FILL_BULK_URB(pUrb,
84 pObj->pUsb_Dev,
85 usb_sndbulkpipe(pObj->pUsb_Dev,
86 pAd->BulkOutEpAddr[BulkOutPipeId]),
87 pSrc, pTxContext->BulkOutSize, Func, pTxContext);
88
89 if (pTxContext->bAggregatible)
90 pUrb->transfer_dma =
91 (pTxContext->data_dma + TX_BUFFER_NORMSIZE + 2);
92 else
93 pUrb->transfer_dma = pTxContext->data_dma;
94
95 pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
96
97}
98
99void RTUSBInitHTTxDesc(struct rt_rtmp_adapter *pAd,
100 struct rt_ht_tx_context *pTxContext,
101 u8 BulkOutPipeId,
102 unsigned long BulkOutSize, IN usb_complete_t Func)
103{
104 PURB pUrb;
105 u8 *pSrc = NULL;
106 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
107
108 pUrb = pTxContext->pUrb;
109 ASSERT(pUrb);
110
111 /* Store BulkOut PipeId */
112 pTxContext->BulkOutPipeId = BulkOutPipeId;
113
114 pSrc =
115 &pTxContext->TransferBuffer->field.WirelessPacket[pTxContext->
116 NextBulkOutPosition];
117
118 /*Initialize a tx bulk urb */
119 RTUSB_FILL_BULK_URB(pUrb,
120 pObj->pUsb_Dev,
121 usb_sndbulkpipe(pObj->pUsb_Dev,
122 pAd->BulkOutEpAddr[BulkOutPipeId]),
123 pSrc, BulkOutSize, Func, pTxContext);
124
125 pUrb->transfer_dma =
126 (pTxContext->data_dma + pTxContext->NextBulkOutPosition);
127 pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
128
129}
130
131void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext)
132{
133 PURB pUrb;
134 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
135 unsigned long RX_bulk_size;
136
137 pUrb = pRxContext->pUrb;
138 ASSERT(pUrb);
139
140 if (pAd->BulkInMaxPacketSize == 64)
141 RX_bulk_size = 4096;
142 else
143 RX_bulk_size = MAX_RXBULK_SIZE;
144
145 /*Initialize a rx bulk urb */
146 RTUSB_FILL_BULK_URB(pUrb,
147 pObj->pUsb_Dev,
148 usb_rcvbulkpipe(pObj->pUsb_Dev, pAd->BulkInEpAddr),
149 &(pRxContext->
150 TransferBuffer[pAd->NextRxBulkInPosition]),
151 RX_bulk_size - (pAd->NextRxBulkInPosition),
152 (usb_complete_t) RTUSBBulkRxComplete,
153 (void *)pRxContext);
154
155 pUrb->transfer_dma = pRxContext->data_dma + pAd->NextRxBulkInPosition;
156 pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
157
158}
159
160/*
161 ========================================================================
162
163 Routine Description:
164
165 Arguments:
166
167 Return Value:
168
169 Note:
170
171 ========================================================================
172*/
173
174#define BULK_OUT_LOCK(pLock, IrqFlags) \
175 if (1 /*!(in_interrupt() & 0xffff0000)*/) \
176 RTMP_IRQ_LOCK((pLock), IrqFlags);
177
178#define BULK_OUT_UNLOCK(pLock, IrqFlags) \
179 if (1 /*!(in_interrupt() & 0xffff0000)*/) \
180 RTMP_IRQ_UNLOCK((pLock), IrqFlags);
181
182void RTUSBBulkOutDataPacket(struct rt_rtmp_adapter *pAd,
183 u8 BulkOutPipeId, u8 Index)
184{
185
186 struct rt_ht_tx_context *pHTTXContext;
187 PURB pUrb;
188 int ret = 0;
189 struct rt_txinfo *pTxInfo, *pLastTxInfo = NULL;
190 struct rt_txwi *pTxWI;
191 unsigned long TmpBulkEndPos, ThisBulkSize;
192 unsigned long IrqFlags = 0, IrqFlags2 = 0;
193 u8 *pWirelessPkt, *pAppendant;
194 BOOLEAN bTxQLastRound = FALSE;
195 u8 allzero[4] = { 0x0, 0x0, 0x0, 0x0 };
196
197 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
198 if ((pAd->BulkOutPending[BulkOutPipeId] == TRUE)
199 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)) {
200 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
201 return;
202 }
203 pAd->BulkOutPending[BulkOutPipeId] = TRUE;
204
205 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
206 ) {
207 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
208 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
209 return;
210 }
211 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
212
213 pHTTXContext = &(pAd->TxContext[BulkOutPipeId]);
214
215 BULK_OUT_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
216 if ((pHTTXContext->ENextBulkOutPosition ==
217 pHTTXContext->CurWritePosition)
218 || ((pHTTXContext->ENextBulkOutPosition - 8) ==
219 pHTTXContext->CurWritePosition)) {
220 BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId],
221 IrqFlags2);
222
223 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
224 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
225
226 /* Clear Data flag */
227 RTUSB_CLEAR_BULK_FLAG(pAd,
228 (fRTUSB_BULK_OUT_DATA_FRAG <<
229 BulkOutPipeId));
230 RTUSB_CLEAR_BULK_FLAG(pAd,
231 (fRTUSB_BULK_OUT_DATA_NORMAL <<
232 BulkOutPipeId));
233
234 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
235 return;
236 }
237 /* Clear Data flag */
238 RTUSB_CLEAR_BULK_FLAG(pAd,
239 (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId));
240 RTUSB_CLEAR_BULK_FLAG(pAd,
241 (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId));
242
243 /*DBGPRINT(RT_DEBUG_TRACE,("BulkOut-B:I=0x%lx, CWPos=%ld, CWRPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", in_interrupt(), */
244 /* pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->NextBulkOutPosition, */
245 /* pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad)); */
246 pHTTXContext->NextBulkOutPosition = pHTTXContext->ENextBulkOutPosition;
247 ThisBulkSize = 0;
248 TmpBulkEndPos = pHTTXContext->NextBulkOutPosition;
249 pWirelessPkt = &pHTTXContext->TransferBuffer->field.WirelessPacket[0];
250
251 if ((pHTTXContext->bCopySavePad == TRUE)) {
252 if (RTMPEqualMemory(pHTTXContext->SavedPad, allzero, 4)) {
253 DBGPRINT_RAW(RT_DEBUG_ERROR,
254 ("e1, allzero : %x %x %x %x %x %x %x %x \n",
255 pHTTXContext->SavedPad[0],
256 pHTTXContext->SavedPad[1],
257 pHTTXContext->SavedPad[2],
258 pHTTXContext->SavedPad[3]
259 , pHTTXContext->SavedPad[4],
260 pHTTXContext->SavedPad[5],
261 pHTTXContext->SavedPad[6],
262 pHTTXContext->SavedPad[7]));
263 }
264 NdisMoveMemory(&pWirelessPkt[TmpBulkEndPos],
265 pHTTXContext->SavedPad, 8);
266 pHTTXContext->bCopySavePad = FALSE;
267 if (pAd->bForcePrintTX == TRUE)
268 DBGPRINT(RT_DEBUG_TRACE,
269 ("RTUSBBulkOutDataPacket --> COPY PAD. CurWrite = %ld, NextBulk = %ld. ENextBulk = %ld.\n",
270 pHTTXContext->CurWritePosition,
271 pHTTXContext->NextBulkOutPosition,
272 pHTTXContext->ENextBulkOutPosition));
273 }
274
275 do {
276 pTxInfo = (struct rt_txinfo *)&pWirelessPkt[TmpBulkEndPos];
277 pTxWI =
278 (struct rt_txwi *)&pWirelessPkt[TmpBulkEndPos + TXINFO_SIZE];
279
280 if (pAd->bForcePrintTX == TRUE)
281 DBGPRINT(RT_DEBUG_TRACE,
282 ("RTUSBBulkOutDataPacket AMPDU = %d.\n",
283 pTxWI->AMPDU));
284
285 /* add by Iverson, limit BulkOut size to 4k to pass WMM b mode 2T1R test items */
286 /*if ((ThisBulkSize != 0) && (pTxWI->AMPDU == 0)) */
287 if ((ThisBulkSize != 0) && (pTxWI->PHYMODE == MODE_CCK)) {
288 if (((ThisBulkSize & 0xffff8000) != 0)
289 || ((ThisBulkSize & 0x1000) == 0x1000)) {
290 /* Limit BulkOut size to about 4k bytes. */
291 pHTTXContext->ENextBulkOutPosition =
292 TmpBulkEndPos;
293 break;
294 } else
295 if (((pAd->BulkOutMaxPacketSize < 512)
296 && ((ThisBulkSize & 0xfffff800) !=
297 0))
298 /*|| ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0)) */
299 ) {
300 /* For USB 1.1 or peer which didn't support AMPDU, limit the BulkOut size. */
301 /* For performance in b/g mode, now just check for USB 1.1 and didn't care about the APMDU or not! 2008/06/04. */
302 pHTTXContext->ENextBulkOutPosition =
303 TmpBulkEndPos;
304 break;
305 }
306 }
307 /* end Iverson */
308 else {
309 if (((ThisBulkSize & 0xffff8000) != 0) || ((ThisBulkSize & 0x6000) == 0x6000)) { /* Limit BulkOut size to about 24k bytes. */
310 pHTTXContext->ENextBulkOutPosition =
311 TmpBulkEndPos;
312 break;
313 } else if (((pAd->BulkOutMaxPacketSize < 512) && ((ThisBulkSize & 0xfffff800) != 0)) /*|| ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0)) */) { /* For USB 1.1 or peer which didn't support AMPDU, limit the BulkOut size. */
314 /* For performance in b/g mode, now just check for USB 1.1 and didn't care about the APMDU or not! 2008/06/04. */
315 pHTTXContext->ENextBulkOutPosition =
316 TmpBulkEndPos;
317 break;
318 }
319 }
320
321 if (TmpBulkEndPos == pHTTXContext->CurWritePosition) {
322 pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos;
323 break;
324 }
325
326 if (pTxInfo->QSEL != FIFO_EDCA) {
327 DBGPRINT(RT_DEBUG_ERROR,
328 ("%s(): ====> pTxInfo->QueueSel(%d)!= FIFO_EDCA!!!!\n",
329 __func__, pTxInfo->QSEL));
330 DBGPRINT(RT_DEBUG_ERROR,
331 ("\tCWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n",
332 pHTTXContext->CurWritePosition,
333 pHTTXContext->NextBulkOutPosition,
334 pHTTXContext->ENextBulkOutPosition,
335 pHTTXContext->bCopySavePad));
336 hex_dump("Wrong QSel Pkt:",
337 (u8 *)&pWirelessPkt[TmpBulkEndPos],
338 (pHTTXContext->CurWritePosition -
339 pHTTXContext->NextBulkOutPosition));
340 }
341
342 if (pTxInfo->USBDMATxPktLen <= 8) {
343 BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId],
344 IrqFlags2);
345 DBGPRINT(RT_DEBUG_ERROR /*RT_DEBUG_TRACE */ ,
346 ("e2, USBDMATxPktLen==0, Size=%ld, bCSPad=%d, CWPos=%ld, NBPos=%ld, CWRPos=%ld!\n",
347 pHTTXContext->BulkOutSize,
348 pHTTXContext->bCopySavePad,
349 pHTTXContext->CurWritePosition,
350 pHTTXContext->NextBulkOutPosition,
351 pHTTXContext->CurWriteRealPos));
352 {
353 DBGPRINT_RAW(RT_DEBUG_ERROR /*RT_DEBUG_TRACE */
354 ,
355 ("%x %x %x %x %x %x %x %x \n",
356 pHTTXContext->SavedPad[0],
357 pHTTXContext->SavedPad[1],
358 pHTTXContext->SavedPad[2],
359 pHTTXContext->SavedPad[3]
360 , pHTTXContext->SavedPad[4],
361 pHTTXContext->SavedPad[5],
362 pHTTXContext->SavedPad[6],
363 pHTTXContext->SavedPad[7]));
364 }
365 pAd->bForcePrintTX = TRUE;
366 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId],
367 IrqFlags);
368 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
369 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId],
370 IrqFlags);
371 /*DBGPRINT(RT_DEBUG_LOUD,("Out:pTxInfo->USBDMATxPktLen=%d!\n", pTxInfo->USBDMATxPktLen)); */
372 return;
373 }
374 /* Increase Total transmit byte counter */
375 pAd->RalinkCounters.OneSecTransmittedByteCount +=
376 pTxWI->MPDUtotalByteCount;
377 pAd->RalinkCounters.TransmittedByteCount +=
378 pTxWI->MPDUtotalByteCount;
379
380 pLastTxInfo = pTxInfo;
381
382 /* Make sure we use EDCA QUEUE. */
383 pTxInfo->QSEL = FIFO_EDCA;
384 ThisBulkSize += (pTxInfo->USBDMATxPktLen + 4);
385 TmpBulkEndPos += (pTxInfo->USBDMATxPktLen + 4);
386
387 if (TmpBulkEndPos != pHTTXContext->CurWritePosition)
388 pTxInfo->USBDMANextVLD = 1;
389
390 if (pTxInfo->SwUseLastRound == 1) {
391 if (pHTTXContext->CurWritePosition == 8)
392 pTxInfo->USBDMANextVLD = 0;
393 pTxInfo->SwUseLastRound = 0;
394
395 bTxQLastRound = TRUE;
396 pHTTXContext->ENextBulkOutPosition = 8;
397
398 break;
399 }
400
401 } while (TRUE);
402
403 /* adjust the pTxInfo->USBDMANextVLD value of last pTxInfo. */
404 if (pLastTxInfo)
405 pLastTxInfo->USBDMANextVLD = 0;
406
407 /*
408 We need to copy SavedPad when following condition matched!
409 1. Not the last round of the TxQueue and
410 2. any match of following cases:
411 (1). The End Position of this bulk out is reach to the Currenct Write position and
412 the TxInfo and related header already write to the CurWritePosition.
413 =>(ENextBulkOutPosition == CurWritePosition) && (CurWriteRealPos > CurWritePosition)
414
415 (2). The EndPosition of the bulk out is not reach to the Current Write Position.
416 =>(ENextBulkOutPosition != CurWritePosition)
417 */
418 if ((bTxQLastRound == FALSE) &&
419 (((pHTTXContext->ENextBulkOutPosition ==
420 pHTTXContext->CurWritePosition)
421 && (pHTTXContext->CurWriteRealPos >
422 pHTTXContext->CurWritePosition))
423 || (pHTTXContext->ENextBulkOutPosition !=
424 pHTTXContext->CurWritePosition))
425 ) {
426 NdisMoveMemory(pHTTXContext->SavedPad,
427 &pWirelessPkt[pHTTXContext->
428 ENextBulkOutPosition], 8);
429 pHTTXContext->bCopySavePad = TRUE;
430 if (RTMPEqualMemory(pHTTXContext->SavedPad, allzero, 4)) {
431 u8 *pBuf = &pHTTXContext->SavedPad[0];
432 DBGPRINT_RAW(RT_DEBUG_ERROR,
433 ("WARNING-Zero-3:%02x%02x%02x%02x%02x%02x%02x%02x,CWPos=%ld, CWRPos=%ld, bCW=%d, NBPos=%ld, TBPos=%ld, TBSize=%ld\n",
434 pBuf[0], pBuf[1], pBuf[2], pBuf[3],
435 pBuf[4], pBuf[5], pBuf[6], pBuf[7],
436 pHTTXContext->CurWritePosition,
437 pHTTXContext->CurWriteRealPos,
438 pHTTXContext->bCurWriting,
439 pHTTXContext->NextBulkOutPosition,
440 TmpBulkEndPos, ThisBulkSize));
441
442 pBuf = &pWirelessPkt[pHTTXContext->CurWritePosition];
443 DBGPRINT_RAW(RT_DEBUG_ERROR,
444 ("\tCWPos=%02x%02x%02x%02x%02x%02x%02x%02x\n",
445 pBuf[0], pBuf[1], pBuf[2], pBuf[3],
446 pBuf[4], pBuf[5], pBuf[6], pBuf[7]));
447 }
448 /*DBGPRINT(RT_DEBUG_LOUD,("ENPos==CWPos=%ld, CWRPos=%ld, bCSPad=%d!\n", pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->bCopySavePad)); */
449 }
450
451 if (pAd->bForcePrintTX == TRUE)
452 DBGPRINT(RT_DEBUG_TRACE,
453 ("BulkOut-A:Size=%ld, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n",
454 ThisBulkSize, pHTTXContext->CurWritePosition,
455 pHTTXContext->NextBulkOutPosition,
456 pHTTXContext->ENextBulkOutPosition,
457 pHTTXContext->bCopySavePad));
458 /*DBGPRINT(RT_DEBUG_LOUD,("BulkOut-A:Size=%ld, CWPos=%ld, CWRPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, bLRound=%d!\n", ThisBulkSize, pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad, bTxQLastRound)); */
459
460 /* USB DMA engine requires to pad extra 4 bytes. This pad doesn't count into real bulkoutsize. */
461 pAppendant = &pWirelessPkt[TmpBulkEndPos];
462 NdisZeroMemory(pAppendant, 8);
463 ThisBulkSize += 4;
464 pHTTXContext->LastOne = TRUE;
465 if ((ThisBulkSize % pAd->BulkOutMaxPacketSize) == 0)
466 ThisBulkSize += 4;
467 pHTTXContext->BulkOutSize = ThisBulkSize;
468
469 pAd->watchDogTxPendingCnt[BulkOutPipeId] = 1;
470 BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2);
471
472 /* Init Tx context descriptor */
473 RTUSBInitHTTxDesc(pAd, pHTTXContext, BulkOutPipeId, ThisBulkSize,
474 (usb_complete_t) RTUSBBulkOutDataPacketComplete);
475
476 pUrb = pHTTXContext->pUrb;
477 ret = RTUSB_SUBMIT_URB(pUrb);
478 if (ret != 0) {
479 DBGPRINT(RT_DEBUG_ERROR,
480 ("RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n",
481 ret));
482
483 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
484 pAd->BulkOutPending[BulkOutPipeId] = FALSE;
485 pAd->watchDogTxPendingCnt[BulkOutPipeId] = 0;
486 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
487
488 return;
489 }
490
491 BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
492 pHTTXContext->IRPPending = TRUE;
493 BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags);
494 pAd->BulkOutReq++;
495
496}
497
498void RTUSBBulkOutDataPacketComplete(struct urb *pUrb, struct pt_regs * pt_regs)
499{
500 struct rt_ht_tx_context *pHTTXContext;
501 struct rt_rtmp_adapter *pAd;
502 struct os_cookie *pObj;
503 u8 BulkOutPipeId;
504
505 pHTTXContext = (struct rt_ht_tx_context *)pUrb->context;
506 pAd = pHTTXContext->pAd;
507 pObj = (struct os_cookie *)pAd->OS_Cookie;
508
509 /* Store BulkOut PipeId */
510 BulkOutPipeId = pHTTXContext->BulkOutPipeId;
511 pAd->BulkOutDataOneSecCount++;
512
513 switch (BulkOutPipeId) {
514 case 0:
515 pObj->ac0_dma_done_task.data = (unsigned long)pUrb;
516 tasklet_hi_schedule(&pObj->ac0_dma_done_task);
517 break;
518 case 1:
519 pObj->ac1_dma_done_task.data = (unsigned long)pUrb;
520 tasklet_hi_schedule(&pObj->ac1_dma_done_task);
521 break;
522 case 2:
523 pObj->ac2_dma_done_task.data = (unsigned long)pUrb;
524 tasklet_hi_schedule(&pObj->ac2_dma_done_task);
525 break;
526 case 3:
527 pObj->ac3_dma_done_task.data = (unsigned long)pUrb;
528 tasklet_hi_schedule(&pObj->ac3_dma_done_task);
529 break;
530 }
531
532}
533
534/*
535 ========================================================================
536
537 Routine Description:
538
539 Arguments:
540
541 Return Value:
542
543 Note: NULL frame use BulkOutPipeId = 0
544
545 ========================================================================
546*/
547void RTUSBBulkOutNullFrame(struct rt_rtmp_adapter *pAd)
548{
549 struct rt_tx_context *pNullContext = &(pAd->NullContext);
550 PURB pUrb;
551 int ret = 0;
552 unsigned long IrqFlags;
553
554 RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
555 if ((pAd->BulkOutPending[0] == TRUE)
556 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)) {
557 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
558 return;
559 }
560 pAd->BulkOutPending[0] = TRUE;
561 pAd->watchDogTxPendingCnt[0] = 1;
562 pNullContext->IRPPending = TRUE;
563 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
564
565 /* Increase Total transmit byte counter */
566 pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize;
567
568 /* Clear Null frame bulk flag */
569 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL);
570
571 /* Init Tx context descriptor */
572 RTUSBInitTxDesc(pAd, pNullContext, 0,
573 (usb_complete_t) RTUSBBulkOutNullFrameComplete);
574
575 pUrb = pNullContext->pUrb;
576 ret = RTUSB_SUBMIT_URB(pUrb);
577 if (ret != 0) {
578 RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
579 pAd->BulkOutPending[0] = FALSE;
580 pAd->watchDogTxPendingCnt[0] = 0;
581 pNullContext->IRPPending = FALSE;
582 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
583
584 DBGPRINT(RT_DEBUG_ERROR,
585 ("RTUSBBulkOutNullFrame: Submit Tx URB failed %d\n",
586 ret));
587 return;
588 }
589
590}
591
592/* NULL frame use BulkOutPipeId = 0 */
593void RTUSBBulkOutNullFrameComplete(struct urb *pUrb, struct pt_regs * pt_regs)
594{
595 struct rt_rtmp_adapter *pAd;
596 struct rt_tx_context *pNullContext;
597 int Status;
598 struct os_cookie *pObj;
599
600 pNullContext = (struct rt_tx_context *)pUrb->context;
601 pAd = pNullContext->pAd;
602 Status = pUrb->status;
603
604 pObj = (struct os_cookie *)pAd->OS_Cookie;
605 pObj->null_frame_complete_task.data = (unsigned long)pUrb;
606 tasklet_hi_schedule(&pObj->null_frame_complete_task);
607}
608
609/*
610 ========================================================================
611
612 Routine Description:
613
614 Arguments:
615
616 Return Value:
617
618 Note: MLME use BulkOutPipeId = 0
619
620 ========================================================================
621*/
622void RTUSBBulkOutMLMEPacket(struct rt_rtmp_adapter *pAd, u8 Index)
623{
624 struct rt_tx_context *pMLMEContext;
625 PURB pUrb;
626 int ret = 0;
627 unsigned long IrqFlags;
628
629 pMLMEContext =
630 (struct rt_tx_context *)pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa;
631 pUrb = pMLMEContext->pUrb;
632
633 if ((pAd->MgmtRing.TxSwFreeIdx >= MGMT_RING_SIZE) ||
634 (pMLMEContext->InUse == FALSE) ||
635 (pMLMEContext->bWaitingBulkOut == FALSE)) {
636
637 /* Clear MLME bulk flag */
638 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
639
640 return;
641 }
642
643 RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
644 if ((pAd->BulkOutPending[MGMTPIPEIDX] == TRUE)
645 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)) {
646 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
647 return;
648 }
649
650 pAd->BulkOutPending[MGMTPIPEIDX] = TRUE;
651 pAd->watchDogTxPendingCnt[MGMTPIPEIDX] = 1;
652 pMLMEContext->IRPPending = TRUE;
653 pMLMEContext->bWaitingBulkOut = FALSE;
654 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
655
656 /* Increase Total transmit byte counter */
657 pAd->RalinkCounters.TransmittedByteCount += pMLMEContext->BulkOutSize;
658
659 /* Clear MLME bulk flag */
660 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME);
661
662 /* Init Tx context descriptor */
663 RTUSBInitTxDesc(pAd, pMLMEContext, MGMTPIPEIDX,
664 (usb_complete_t) RTUSBBulkOutMLMEPacketComplete);
665
666 /*For mgmt urb buffer, because we use sk_buff, so we need to notify the USB controller do dma mapping. */
667 pUrb->transfer_dma = 0;
668 pUrb->transfer_flags &= (~URB_NO_TRANSFER_DMA_MAP);
669
670 pUrb = pMLMEContext->pUrb;
671 ret = RTUSB_SUBMIT_URB(pUrb);
672 if (ret != 0) {
673 DBGPRINT(RT_DEBUG_ERROR,
674 ("RTUSBBulkOutMLMEPacket: Submit MLME URB failed %d\n",
675 ret));
676 RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
677 pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
678 pAd->watchDogTxPendingCnt[MGMTPIPEIDX] = 0;
679 pMLMEContext->IRPPending = FALSE;
680 pMLMEContext->bWaitingBulkOut = TRUE;
681 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags);
682
683 return;
684 }
685 /*DBGPRINT_RAW(RT_DEBUG_INFO, ("<---RTUSBBulkOutMLMEPacket \n")); */
686/* printk("<---RTUSBBulkOutMLMEPacket,Cpu=%d!, Dma=%d, SwIdx=%d!\n", pAd->MgmtRing.TxCpuIdx, pAd->MgmtRing.TxDmaIdx, pAd->MgmtRing.TxSwFreeIdx); */
687}
688
689void RTUSBBulkOutMLMEPacketComplete(struct urb *pUrb, struct pt_regs * pt_regs)
690{
691 struct rt_tx_context *pMLMEContext;
692 struct rt_rtmp_adapter *pAd;
693 int Status;
694 struct os_cookie *pObj;
695 int index;
696
697 /*DBGPRINT_RAW(RT_DEBUG_INFO, ("--->RTUSBBulkOutMLMEPacketComplete\n")); */
698 pMLMEContext = (struct rt_tx_context *)pUrb->context;
699 pAd = pMLMEContext->pAd;
700 pObj = (struct os_cookie *)pAd->OS_Cookie;
701 Status = pUrb->status;
702 index = pMLMEContext->SelfIdx;
703
704 pObj->mgmt_dma_done_task.data = (unsigned long)pUrb;
705 tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
706}
707
708/*
709 ========================================================================
710
711 Routine Description:
712
713 Arguments:
714
715 Return Value:
716
717 Note: PsPoll use BulkOutPipeId = 0
718
719 ========================================================================
720*/
721void RTUSBBulkOutPsPoll(struct rt_rtmp_adapter *pAd)
722{
723 struct rt_tx_context *pPsPollContext = &(pAd->PsPollContext);
724 PURB pUrb;
725 int ret = 0;
726 unsigned long IrqFlags;
727
728 RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
729 if ((pAd->BulkOutPending[0] == TRUE)
730 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)) {
731 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
732 return;
733 }
734 pAd->BulkOutPending[0] = TRUE;
735 pAd->watchDogTxPendingCnt[0] = 1;
736 pPsPollContext->IRPPending = TRUE;
737 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
738
739 /* Clear PS-Poll bulk flag */
740 RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL);
741
742 /* Init Tx context descriptor */
743 RTUSBInitTxDesc(pAd, pPsPollContext, MGMTPIPEIDX,
744 (usb_complete_t) RTUSBBulkOutPsPollComplete);
745
746 pUrb = pPsPollContext->pUrb;
747 ret = RTUSB_SUBMIT_URB(pUrb);
748 if (ret != 0) {
749 RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags);
750 pAd->BulkOutPending[0] = FALSE;
751 pAd->watchDogTxPendingCnt[0] = 0;
752 pPsPollContext->IRPPending = FALSE;
753 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags);
754
755 DBGPRINT(RT_DEBUG_ERROR,
756 ("RTUSBBulkOutPsPoll: Submit Tx URB failed %d\n",
757 ret));
758 return;
759 }
760
761}
762
763/* PS-Poll frame use BulkOutPipeId = 0 */
764void RTUSBBulkOutPsPollComplete(struct urb *pUrb, struct pt_regs * pt_regs)
765{
766 struct rt_rtmp_adapter *pAd;
767 struct rt_tx_context *pPsPollContext;
768 int Status;
769 struct os_cookie *pObj;
770
771 pPsPollContext = (struct rt_tx_context *)pUrb->context;
772 pAd = pPsPollContext->pAd;
773 Status = pUrb->status;
774
775 pObj = (struct os_cookie *)pAd->OS_Cookie;
776 pObj->pspoll_frame_complete_task.data = (unsigned long)pUrb;
777 tasklet_hi_schedule(&pObj->pspoll_frame_complete_task);
778}
779
780void DoBulkIn(struct rt_rtmp_adapter *pAd)
781{
782 struct rt_rx_context *pRxContext;
783 PURB pUrb;
784 int ret = 0;
785 unsigned long IrqFlags;
786
787 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
788 pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]);
789 if ((pAd->PendingRx > 0) || (pRxContext->Readable == TRUE)
790 || (pRxContext->InUse == TRUE)) {
791 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
792 return;
793 }
794 pRxContext->InUse = TRUE;
795 pRxContext->IRPPending = TRUE;
796 pAd->PendingRx++;
797 pAd->BulkInReq++;
798 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
799
800 /* Init Rx context descriptor */
801 NdisZeroMemory(pRxContext->TransferBuffer, pRxContext->BulkInOffset);
802 RTUSBInitRxDesc(pAd, pRxContext);
803
804 pUrb = pRxContext->pUrb;
805 ret = RTUSB_SUBMIT_URB(pUrb);
806 if (ret != 0) { /* fail */
807
808 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
809 pRxContext->InUse = FALSE;
810 pRxContext->IRPPending = FALSE;
811 pAd->PendingRx--;
812 pAd->BulkInReq--;
813 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
814 DBGPRINT(RT_DEBUG_ERROR,
815 ("RTUSBBulkReceive: Submit Rx URB failed %d\n", ret));
816 } else { /* success */
817 ASSERT((pRxContext->InUse == pRxContext->IRPPending));
818 /*printk("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex); */
819 }
820}
821
822/*
823 ========================================================================
824
825 Routine Description:
826 USB_RxPacket initializes a URB and uses the Rx IRP to submit it
827 to USB. It checks if an Rx Descriptor is available and passes the
828 the coresponding buffer to be filled. If no descriptor is available
829 fails the request. When setting the completion routine we pass our
830 Adapter Object as Context.
831
832 Arguments:
833
834 Return Value:
835 TRUE found matched tuple cache
836 FALSE no matched found
837
838 Note:
839
840 ========================================================================
841*/
842#define fRTMP_ADAPTER_NEED_STOP_RX \
843 (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
844 fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_RESET_IN_PROGRESS | \
845 fRTMP_ADAPTER_REMOVE_IN_PROGRESS | fRTMP_ADAPTER_BULKIN_RESET)
846
847#define fRTMP_ADAPTER_NEED_STOP_HANDLE_RX \
848 (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
849 fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_RESET_IN_PROGRESS | \
850 fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
851
852void RTUSBBulkReceive(struct rt_rtmp_adapter *pAd)
853{
854 struct rt_rx_context *pRxContext;
855 unsigned long IrqFlags;
856
857 /* sanity check */
858 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_HANDLE_RX))
859 return;
860
861 while (1) {
862
863 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
864 pRxContext = &(pAd->RxContext[pAd->NextRxBulkInReadIndex]);
865 if (((pRxContext->InUse == FALSE)
866 && (pRxContext->Readable == TRUE))
867 && (pRxContext->bRxHandling == FALSE)) {
868 pRxContext->bRxHandling = TRUE;
869 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
870
871 /* read RxContext, Since not */
872 STARxDoneInterruptHandle(pAd, TRUE);
873
874 /* Finish to handle this bulkIn buffer. */
875 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
876 pRxContext->BulkInOffset = 0;
877 pRxContext->Readable = FALSE;
878 pRxContext->bRxHandling = FALSE;
879 pAd->ReadPosition = 0;
880 pAd->TransferBufferLength = 0;
881 INC_RING_INDEX(pAd->NextRxBulkInReadIndex,
882 RX_RING_SIZE);
883 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
884
885 } else {
886 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
887 break;
888 }
889 }
890
891 if (!(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_RX)))
892 DoBulkIn(pAd);
893
894}
895
896/*
897 ========================================================================
898
899 Routine Description:
900 This routine process Rx Irp and call rx complete function.
901
902 Arguments:
903 DeviceObject Pointer to the device object for next lower
904 device. DeviceObject passed in here belongs to
905 the next lower driver in the stack because we
906 were invoked via IoCallDriver in USB_RxPacket
907 AND it is not OUR device object
908 Irp Ptr to completed IRP
909 Context Ptr to our Adapter object (context specified
910 in IoSetCompletionRoutine
911
912 Return Value:
913 Always returns STATUS_MORE_PROCESSING_REQUIRED
914
915 Note:
916 Always returns STATUS_MORE_PROCESSING_REQUIRED
917 ========================================================================
918*/
919void RTUSBBulkRxComplete(struct urb *pUrb, struct pt_regs *pt_regs)
920{
921 /* use a receive tasklet to handle received packets; */
922 /* or sometimes hardware IRQ will be disabled here, so we can not */
923 /* use spin_lock_bh()/spin_unlock_bh() after IRQ is disabled. :< */
924 struct rt_rx_context *pRxContext;
925 struct rt_rtmp_adapter *pAd;
926 struct os_cookie *pObj;
927
928 pRxContext = (struct rt_rx_context *)pUrb->context;
929 pAd = pRxContext->pAd;
930 pObj = (struct os_cookie *)pAd->OS_Cookie;
931
932 pObj->rx_done_task.data = (unsigned long)pUrb;
933 tasklet_hi_schedule(&pObj->rx_done_task);
934
935}
936
937/*
938 ========================================================================
939
940 Routine Description:
941
942 Arguments:
943
944 Return Value:
945
946 Note:
947
948 ========================================================================
949*/
950void RTUSBKickBulkOut(struct rt_rtmp_adapter *pAd)
951{
952 /* BulkIn Reset will reset whole USB PHY. So we need to make sure fRTMP_ADAPTER_BULKIN_RESET not flaged. */
953 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)
954 ) {
955 /* 2. PS-Poll frame is next */
956 if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL))
957 RTUSBBulkOutPsPoll(pAd);
958 /* 5. Mlme frame is next */
959 else if ((RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME)) ||
960 (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE)) {
961 RTUSBBulkOutMLMEPacket(pAd, pAd->MgmtRing.TxDmaIdx);
962 }
963 /* 6. Data frame normal is next */
964 if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL)) {
965 if (((!RTMP_TEST_FLAG
966 (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
967 ||
968 (!OPSTATUS_TEST_FLAG
969 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
970 )) {
971 RTUSBBulkOutDataPacket(pAd, 0,
972 pAd->
973 NextBulkOutIndex[0]);
974 }
975 }
976 if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_2)) {
977 if (((!RTMP_TEST_FLAG
978 (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
979 ||
980 (!OPSTATUS_TEST_FLAG
981 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
982 )) {
983 RTUSBBulkOutDataPacket(pAd, 1,
984 pAd->
985 NextBulkOutIndex[1]);
986 }
987 }
988 if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_3)) {
989 if (((!RTMP_TEST_FLAG
990 (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
991 ||
992 (!OPSTATUS_TEST_FLAG
993 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
994 )) {
995 RTUSBBulkOutDataPacket(pAd, 2,
996 pAd->
997 NextBulkOutIndex[2]);
998 }
999 }
1000 if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_4)) {
1001 if (((!RTMP_TEST_FLAG
1002 (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1003 ||
1004 (!OPSTATUS_TEST_FLAG
1005 (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
1006 )) {
1007 RTUSBBulkOutDataPacket(pAd, 3,
1008 pAd->
1009 NextBulkOutIndex[3]);
1010 }
1011 }
1012 /* 7. Null frame is the last */
1013 else if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL)) {
1014 if (!RTMP_TEST_FLAG
1015 (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) {
1016 RTUSBBulkOutNullFrame(pAd);
1017 }
1018 }
1019 /* 8. No data available */
1020 else
1021 ;
1022 }
1023}
1024
1025/*
1026 ========================================================================
1027
1028 Routine Description:
1029 Call from Reset action after BulkOut failed.
1030 Arguments:
1031
1032 Return Value:
1033
1034 Note:
1035
1036 ========================================================================
1037*/
1038void RTUSBCleanUpDataBulkOutQueue(struct rt_rtmp_adapter *pAd)
1039{
1040 u8 Idx;
1041 struct rt_ht_tx_context *pTxContext;
1042
1043 DBGPRINT(RT_DEBUG_TRACE, ("--->CleanUpDataBulkOutQueue\n"));
1044
1045 for (Idx = 0; Idx < 4; Idx++) {
1046 pTxContext = &pAd->TxContext[Idx];
1047
1048 pTxContext->CurWritePosition = pTxContext->NextBulkOutPosition;
1049 pTxContext->LastOne = FALSE;
1050 NdisAcquireSpinLock(&pAd->BulkOutLock[Idx]);
1051 pAd->BulkOutPending[Idx] = FALSE;
1052 NdisReleaseSpinLock(&pAd->BulkOutLock[Idx]);
1053 }
1054
1055 DBGPRINT(RT_DEBUG_TRACE, ("<---CleanUpDataBulkOutQueue\n"));
1056}
1057
1058/*
1059 ========================================================================
1060
1061 Routine Description:
1062
1063 Arguments:
1064
1065 Return Value:
1066
1067 Note:
1068
1069 ========================================================================
1070*/
1071void RTUSBCleanUpMLMEBulkOutQueue(struct rt_rtmp_adapter *pAd)
1072{
1073 DBGPRINT(RT_DEBUG_TRACE, ("--->CleanUpMLMEBulkOutQueue\n"));
1074 DBGPRINT(RT_DEBUG_TRACE, ("<---CleanUpMLMEBulkOutQueue\n"));
1075}
1076
1077/*
1078 ========================================================================
1079
1080 Routine Description:
1081
1082 Arguments:
1083
1084 Return Value:
1085
1086 Note:
1087
1088 ========================================================================
1089*/
1090void RTUSBCancelPendingIRPs(struct rt_rtmp_adapter *pAd)
1091{
1092 RTUSBCancelPendingBulkInIRP(pAd);
1093 RTUSBCancelPendingBulkOutIRP(pAd);
1094}
1095
1096/*
1097 ========================================================================
1098
1099 Routine Description:
1100
1101 Arguments:
1102
1103 Return Value:
1104
1105 Note:
1106
1107 ========================================================================
1108*/
1109void RTUSBCancelPendingBulkInIRP(struct rt_rtmp_adapter *pAd)
1110{
1111 struct rt_rx_context *pRxContext;
1112 u32 i;
1113
1114 DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->RTUSBCancelPendingBulkInIRP\n"));
1115 for (i = 0; i < (RX_RING_SIZE); i++) {
1116 pRxContext = &(pAd->RxContext[i]);
1117 if (pRxContext->IRPPending == TRUE) {
1118 RTUSB_UNLINK_URB(pRxContext->pUrb);
1119 pRxContext->IRPPending = FALSE;
1120 pRxContext->InUse = FALSE;
1121 /*NdisInterlockedDecrement(&pAd->PendingRx); */
1122 /*pAd->PendingRx--; */
1123 }
1124 }
1125 DBGPRINT_RAW(RT_DEBUG_TRACE, ("<---RTUSBCancelPendingBulkInIRP\n"));
1126}
1127
1128/*
1129 ========================================================================
1130
1131 Routine Description:
1132
1133 Arguments:
1134
1135 Return Value:
1136
1137 Note:
1138
1139 ========================================================================
1140*/
1141void RTUSBCancelPendingBulkOutIRP(struct rt_rtmp_adapter *pAd)
1142{
1143 struct rt_ht_tx_context *pHTTXContext;
1144 struct rt_tx_context *pMLMEContext;
1145 struct rt_tx_context *pBeaconContext;
1146 struct rt_tx_context *pNullContext;
1147 struct rt_tx_context *pPsPollContext;
1148 struct rt_tx_context *pRTSContext;
1149 u32 i, Idx;
1150/* unsigned int IrqFlags; */
1151/* spinlock_t *pLock; */
1152/* BOOLEAN *pPending; */
1153
1154/* pLock = &pAd->BulkOutLock[MGMTPIPEIDX]; */
1155/* pPending = &pAd->BulkOutPending[MGMTPIPEIDX]; */
1156
1157 for (Idx = 0; Idx < 4; Idx++) {
1158 pHTTXContext = &(pAd->TxContext[Idx]);
1159
1160 if (pHTTXContext->IRPPending == TRUE) {
1161
1162 /* Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself */
1163 /* remove it from the HeadPendingSendList and NULL out HeadPendingSendList */
1164 /* when the last IRP on the list has been cancelled; that's how we exit this loop */
1165 /* */
1166
1167 RTUSB_UNLINK_URB(pHTTXContext->pUrb);
1168
1169 /* Sleep 200 microseconds to give cancellation time to work */
1170 RTMPusecDelay(200);
1171 }
1172
1173 pAd->BulkOutPending[Idx] = FALSE;
1174 }
1175
1176 /*RTMP_IRQ_LOCK(pLock, IrqFlags); */
1177 for (i = 0; i < MGMT_RING_SIZE; i++) {
1178 pMLMEContext = (struct rt_tx_context *)pAd->MgmtRing.Cell[i].AllocVa;
1179 if (pMLMEContext && (pMLMEContext->IRPPending == TRUE)) {
1180
1181 /* Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself */
1182 /* remove it from the HeadPendingSendList and NULL out HeadPendingSendList */
1183 /* when the last IRP on the list has been cancelled; that's how we exit this loop */
1184 /* */
1185
1186 RTUSB_UNLINK_URB(pMLMEContext->pUrb);
1187 pMLMEContext->IRPPending = FALSE;
1188
1189 /* Sleep 200 microsecs to give cancellation time to work */
1190 RTMPusecDelay(200);
1191 }
1192 }
1193 pAd->BulkOutPending[MGMTPIPEIDX] = FALSE;
1194 /*RTMP_IRQ_UNLOCK(pLock, IrqFlags); */
1195
1196 for (i = 0; i < BEACON_RING_SIZE; i++) {
1197 pBeaconContext = &(pAd->BeaconContext[i]);
1198
1199 if (pBeaconContext->IRPPending == TRUE) {
1200
1201 /* Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself */
1202 /* remove it from the HeadPendingSendList and NULL out HeadPendingSendList */
1203 /* when the last IRP on the list has been cancelled; that's how we exit this loop */
1204 /* */
1205
1206 RTUSB_UNLINK_URB(pBeaconContext->pUrb);
1207
1208 /* Sleep 200 microsecs to give cancellation time to work */
1209 RTMPusecDelay(200);
1210 }
1211 }
1212
1213 pNullContext = &(pAd->NullContext);
1214 if (pNullContext->IRPPending == TRUE)
1215 RTUSB_UNLINK_URB(pNullContext->pUrb);
1216
1217 pRTSContext = &(pAd->RTSContext);
1218 if (pRTSContext->IRPPending == TRUE)
1219 RTUSB_UNLINK_URB(pRTSContext->pUrb);
1220
1221 pPsPollContext = &(pAd->PsPollContext);
1222 if (pPsPollContext->IRPPending == TRUE)
1223 RTUSB_UNLINK_URB(pPsPollContext->pUrb);
1224
1225 for (Idx = 0; Idx < 4; Idx++) {
1226 NdisAcquireSpinLock(&pAd->BulkOutLock[Idx]);
1227 pAd->BulkOutPending[Idx] = FALSE;
1228 NdisReleaseSpinLock(&pAd->BulkOutLock[Idx]);
1229 }
1230}
1231
1232#endif /* RTMP_MAC_USB // */
diff --git a/drivers/staging/rt2870/common/rtusb_data.c b/drivers/staging/rt2870/common/rtusb_data.c
deleted file mode 100644
index 5b72bcdaa78..00000000000
--- a/drivers/staging/rt2870/common/rtusb_data.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtusb_data.c
29
30 Abstract:
31 Ralink USB driver Tx/Rx functions.
32
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Jan 03-25-2006 created
37
38*/
39
40#ifdef RTMP_MAC_USB
41
42#include "../rt_config.h"
43
44extern u8 Phy11BGNextRateUpward[]; /* defined in mlme.c */
45extern u8 EpToQueue[];
46
47void REPORT_AMSDU_FRAMES_TO_LLC(struct rt_rtmp_adapter *pAd,
48 u8 *pData, unsigned long DataSize)
49{
50 void *pPacket;
51 u32 nMSDU;
52 struct sk_buff *pSkb;
53
54 nMSDU = 0;
55 /* allocate a rx packet */
56 pSkb = dev_alloc_skb(RX_BUFFER_AGGRESIZE);
57 pPacket = (void *)OSPKT_TO_RTPKT(pSkb);
58 if (pSkb) {
59
60 /* convert 802.11 to 802.3 packet */
61 pSkb->dev = get_netdev_from_bssid(pAd, BSS0);
62 RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
63 deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize);
64 } else {
65 DBGPRINT(RT_DEBUG_ERROR, ("Can't allocate skb\n"));
66 }
67}
68
69/*
70 ========================================================================
71
72 Routine Description:
73 This subroutine will scan through releative ring descriptor to find
74 out available free ring descriptor and compare with request size.
75
76 Arguments:
77 pAd Pointer to our adapter
78 RingType Selected Ring
79
80 Return Value:
81 NDIS_STATUS_FAILURE Not enough free descriptor
82 NDIS_STATUS_SUCCESS Enough free descriptor
83
84 Note:
85
86 ========================================================================
87*/
88int RTUSBFreeDescriptorRequest(struct rt_rtmp_adapter *pAd,
89 u8 BulkOutPipeId,
90 u32 NumberRequired)
91{
92/* u8 FreeNumber = 0; */
93/* u32 Index; */
94 int Status = NDIS_STATUS_FAILURE;
95 unsigned long IrqFlags;
96 struct rt_ht_tx_context *pHTTXContext;
97
98 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
99 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
100 if ((pHTTXContext->CurWritePosition < pHTTXContext->NextBulkOutPosition)
101 &&
102 ((pHTTXContext->CurWritePosition + NumberRequired +
103 LOCAL_TXBUF_SIZE) > pHTTXContext->NextBulkOutPosition)) {
104
105 RTUSB_SET_BULK_FLAG(pAd,
106 (fRTUSB_BULK_OUT_DATA_NORMAL <<
107 BulkOutPipeId));
108 } else if ((pHTTXContext->CurWritePosition == 8)
109 && (pHTTXContext->NextBulkOutPosition <
110 (NumberRequired + LOCAL_TXBUF_SIZE))) {
111 RTUSB_SET_BULK_FLAG(pAd,
112 (fRTUSB_BULK_OUT_DATA_NORMAL <<
113 BulkOutPipeId));
114 } else if (pHTTXContext->bCurWriting == TRUE) {
115 DBGPRINT(RT_DEBUG_TRACE,
116 ("RTUSBFreeD c3 --> QueIdx=%d, CWPos=%ld, NBOutPos=%ld!\n",
117 BulkOutPipeId, pHTTXContext->CurWritePosition,
118 pHTTXContext->NextBulkOutPosition));
119 RTUSB_SET_BULK_FLAG(pAd,
120 (fRTUSB_BULK_OUT_DATA_NORMAL <<
121 BulkOutPipeId));
122 } else {
123 Status = NDIS_STATUS_SUCCESS;
124 }
125 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
126
127 return Status;
128}
129
130int RTUSBFreeDescriptorRelease(struct rt_rtmp_adapter *pAd,
131 u8 BulkOutPipeId)
132{
133 unsigned long IrqFlags;
134 struct rt_ht_tx_context *pHTTXContext;
135
136 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
137 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
138 pHTTXContext->bCurWriting = FALSE;
139 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
140
141 return NDIS_STATUS_SUCCESS;
142}
143
144BOOLEAN RTUSBNeedQueueBackForAgg(struct rt_rtmp_adapter *pAd, u8 BulkOutPipeId)
145{
146 unsigned long IrqFlags;
147 struct rt_ht_tx_context *pHTTXContext;
148 BOOLEAN needQueBack = FALSE;
149
150 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
151
152 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
153 if ((pHTTXContext->IRPPending ==
154 TRUE) /*&& (pAd->TxSwQueue[BulkOutPipeId].Number == 0) */) {
155 if ((pHTTXContext->CurWritePosition <
156 pHTTXContext->ENextBulkOutPosition)
157 &&
158 (((pHTTXContext->ENextBulkOutPosition +
159 MAX_AGGREGATION_SIZE) < MAX_TXBULK_LIMIT)
160 || (pHTTXContext->CurWritePosition >
161 MAX_AGGREGATION_SIZE))) {
162 needQueBack = TRUE;
163 } else
164 if ((pHTTXContext->CurWritePosition >
165 pHTTXContext->ENextBulkOutPosition)
166 &&
167 ((pHTTXContext->ENextBulkOutPosition +
168 MAX_AGGREGATION_SIZE) <
169 pHTTXContext->CurWritePosition)) {
170 needQueBack = TRUE;
171 }
172 }
173 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
174
175 return needQueBack;
176
177}
178
179/*
180 ========================================================================
181
182 Routine Description:
183
184 Arguments:
185
186 Return Value:
187
188 IRQL =
189
190 Note:
191
192 ========================================================================
193*/
194void RTUSBRejectPendingPackets(struct rt_rtmp_adapter *pAd)
195{
196 u8 Index;
197 struct rt_queue_entry *pEntry;
198 void *pPacket;
199 struct rt_queue_header *pQueue;
200
201 for (Index = 0; Index < 4; Index++) {
202 NdisAcquireSpinLock(&pAd->TxSwQueueLock[Index]);
203 while (pAd->TxSwQueue[Index].Head != NULL) {
204 pQueue = (struct rt_queue_header *)&(pAd->TxSwQueue[Index]);
205 pEntry = RemoveHeadQueue(pQueue);
206 pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
207 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
208 }
209 NdisReleaseSpinLock(&pAd->TxSwQueueLock[Index]);
210
211 }
212
213}
214
215/*
216 ========================================================================
217
218 Routine Description:
219 Calculates the duration which is required to transmit out frames
220 with given size and specified rate.
221
222 Arguments:
223 pTxD Pointer to transmit descriptor
224 Ack Setting for Ack requirement bit
225 Fragment Setting for Fragment bit
226 RetryMode Setting for retry mode
227 Ifs Setting for IFS gap
228 Rate Setting for transmit rate
229 Service Setting for service
230 Length Frame length
231 TxPreamble Short or Long preamble when using CCK rates
232 QueIdx - 0-3, according to 802.11e/d4.4 June/2003
233
234 Return Value:
235 None
236
237 IRQL = PASSIVE_LEVEL
238 IRQL = DISPATCH_LEVEL
239
240 ========================================================================
241*/
242
243void RTMPWriteTxInfo(struct rt_rtmp_adapter *pAd,
244 struct rt_txinfo *pTxInfo,
245 u16 USBDMApktLen,
246 IN BOOLEAN bWiv,
247 u8 QueueSel, u8 NextValid, u8 TxBurst)
248{
249 pTxInfo->USBDMATxPktLen = USBDMApktLen;
250 pTxInfo->QSEL = QueueSel;
251 if (QueueSel != FIFO_EDCA)
252 DBGPRINT(RT_DEBUG_TRACE,
253 ("====> QueueSel != FIFO_EDCA<============\n"));
254 pTxInfo->USBDMANextVLD = FALSE; /*NextValid; // Need to check with Jan about this. */
255 pTxInfo->USBDMATxburst = TxBurst;
256 pTxInfo->WIV = bWiv;
257 pTxInfo->SwUseLastRound = 0;
258 pTxInfo->rsv = 0;
259 pTxInfo->rsv2 = 0;
260}
261
262#endif /* RTMP_MAC_USB // */
diff --git a/drivers/staging/rt2870/common/rtusb_io.c b/drivers/staging/rt2870/common/rtusb_io.c
deleted file mode 100644
index 7d2f7e05814..00000000000
--- a/drivers/staging/rt2870/common/rtusb_io.c
+++ /dev/null
@@ -1,2104 +0,0 @@
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 rtusb_io.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
36 Paul Lin 06-25-2004 created
37*/
38
39#ifdef RTMP_MAC_USB
40
41#include "../rt_config.h"
42
43/*
44 ========================================================================
45
46 Routine Description: NIC initialization complete
47
48 Arguments:
49
50 Return Value:
51
52 IRQL =
53
54 Note:
55
56 ========================================================================
57*/
58
59static int RTUSBFirmwareRun(struct rt_rtmp_adapter *pAd)
60{
61 int Status;
62
63 Status = RTUSB_VendorRequest(pAd,
64 USBD_TRANSFER_DIRECTION_OUT,
65 DEVICE_VENDOR_REQUEST_OUT,
66 0x01, 0x8, 0, NULL, 0);
67
68 return Status;
69}
70
71/*
72 ========================================================================
73
74 Routine Description: Write Firmware to NIC.
75
76 Arguments:
77
78 Return Value:
79
80 IRQL =
81
82 Note:
83
84 ========================================================================
85*/
86int RTUSBFirmwareWrite(struct rt_rtmp_adapter *pAd,
87 const u8 *pFwImage, unsigned long FwLen)
88{
89 u32 MacReg;
90 int Status;
91/* unsigned long i; */
92 u16 writeLen;
93
94 Status = RTUSBReadMACRegister(pAd, MAC_CSR0, &MacReg);
95
96 writeLen = FwLen;
97 RTUSBMultiWrite(pAd, FIRMWARE_IMAGE_BASE, pFwImage, writeLen);
98
99 Status = RTUSBWriteMACRegister(pAd, 0x7014, 0xffffffff);
100 Status = RTUSBWriteMACRegister(pAd, 0x701c, 0xffffffff);
101 Status = RTUSBFirmwareRun(pAd);
102
103 /*2008/11/28:KH add to fix the dead rf frequency offset bug<-- */
104 RTMPusecDelay(10000);
105 RTUSBWriteMACRegister(pAd, H2M_MAILBOX_CSR, 0);
106 AsicSendCommandToMcu(pAd, 0x72, 0x00, 0x00, 0x00); /*reset rf by MCU supported by new firmware */
107 /*2008/11/28:KH add to fix the dead rf frequency offset bug--> */
108
109 return Status;
110}
111
112int RTUSBVenderReset(struct rt_rtmp_adapter *pAd)
113{
114 int Status;
115 DBGPRINT_RAW(RT_DEBUG_ERROR, ("-->RTUSBVenderReset\n"));
116 Status = RTUSB_VendorRequest(pAd,
117 USBD_TRANSFER_DIRECTION_OUT,
118 DEVICE_VENDOR_REQUEST_OUT,
119 0x01, 0x1, 0, NULL, 0);
120
121 DBGPRINT_RAW(RT_DEBUG_ERROR, ("<--RTUSBVenderReset\n"));
122 return Status;
123}
124
125/*
126 ========================================================================
127
128 Routine Description: Read various length data from RT2573
129
130 Arguments:
131
132 Return Value:
133
134 IRQL =
135
136 Note:
137
138 ========================================================================
139*/
140int RTUSBMultiRead(struct rt_rtmp_adapter *pAd,
141 u16 Offset, u8 *pData, u16 length)
142{
143 int Status;
144
145 Status = RTUSB_VendorRequest(pAd,
146 (USBD_TRANSFER_DIRECTION_IN |
147 USBD_SHORT_TRANSFER_OK),
148 DEVICE_VENDOR_REQUEST_IN, 0x7, 0, Offset,
149 pData, length);
150
151 return Status;
152}
153
154/*
155 ========================================================================
156
157 Routine Description: Write various length data to RT2573
158
159 Arguments:
160
161 Return Value:
162
163 IRQL =
164
165 Note:
166
167 ========================================================================
168*/
169int RTUSBMultiWrite_OneByte(struct rt_rtmp_adapter *pAd,
170 u16 Offset, const u8 *pData)
171{
172 int Status;
173
174 /* TODO: In 2870, use this funciton carefully cause it's not stable. */
175 Status = RTUSB_VendorRequest(pAd,
176 USBD_TRANSFER_DIRECTION_OUT,
177 DEVICE_VENDOR_REQUEST_OUT,
178 0x6, 0, Offset, (u8 *)pData, 1);
179
180 return Status;
181}
182
183int RTUSBMultiWrite(struct rt_rtmp_adapter *pAd,
184 u16 Offset, const u8 *pData, u16 length)
185{
186 int Status;
187
188 u16 index = 0, Value;
189 const u8 *pSrc = pData;
190 u16 resude = 0;
191
192 resude = length % 2;
193 length += resude;
194 do {
195 Value = (u16)(*pSrc | (*(pSrc + 1) << 8));
196 Status = RTUSBSingleWrite(pAd, Offset + index, Value);
197 index += 2;
198 length -= 2;
199 pSrc = pSrc + 2;
200 } while (length > 0);
201
202 return Status;
203}
204
205int RTUSBSingleWrite(struct rt_rtmp_adapter *pAd,
206 u16 Offset, u16 Value)
207{
208 int Status;
209
210 Status = RTUSB_VendorRequest(pAd,
211 USBD_TRANSFER_DIRECTION_OUT,
212 DEVICE_VENDOR_REQUEST_OUT,
213 0x2, Value, Offset, NULL, 0);
214
215 return Status;
216
217}
218
219/*
220 ========================================================================
221
222 Routine Description: Read 32-bit MAC register
223
224 Arguments:
225
226 Return Value:
227
228 IRQL =
229
230 Note:
231
232 ========================================================================
233*/
234int RTUSBReadMACRegister(struct rt_rtmp_adapter *pAd,
235 u16 Offset, u32 *pValue)
236{
237 int Status = 0;
238 u32 localVal;
239
240 Status = RTUSB_VendorRequest(pAd,
241 (USBD_TRANSFER_DIRECTION_IN |
242 USBD_SHORT_TRANSFER_OK),
243 DEVICE_VENDOR_REQUEST_IN, 0x7, 0, Offset,
244 &localVal, 4);
245
246 *pValue = le2cpu32(localVal);
247
248 if (Status < 0)
249 *pValue = 0xffffffff;
250
251 return Status;
252}
253
254/*
255 ========================================================================
256
257 Routine Description: Write 32-bit MAC register
258
259 Arguments:
260
261 Return Value:
262
263 IRQL =
264
265 Note:
266
267 ========================================================================
268*/
269int RTUSBWriteMACRegister(struct rt_rtmp_adapter *pAd,
270 u16 Offset, u32 Value)
271{
272 int Status;
273 u32 localVal;
274
275 localVal = Value;
276
277 Status = RTUSBSingleWrite(pAd, Offset, (u16)(localVal & 0xffff));
278 Status =
279 RTUSBSingleWrite(pAd, Offset + 2,
280 (u16)((localVal & 0xffff0000) >> 16));
281
282 return Status;
283}
284
285/*
286 ========================================================================
287
288 Routine Description: Read 8-bit BBP register
289
290 Arguments:
291
292 Return Value:
293
294 IRQL =
295
296 Note:
297
298 ========================================================================
299*/
300int RTUSBReadBBPRegister(struct rt_rtmp_adapter *pAd,
301 u8 Id, u8 *pValue)
302{
303 BBP_CSR_CFG_STRUC BbpCsr;
304 u32 i = 0;
305 int status;
306
307 /* Verify the busy condition */
308 do {
309 status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
310 if (status >= 0) {
311 if (!(BbpCsr.field.Busy == BUSY))
312 break;
313 }
314 DBGPRINT(RT_DEBUG_TRACE,
315 ("RTUSBReadBBPRegister(BBP_CSR_CFG_1):retry count=%d!\n",
316 i));
317 i++;
318 } while ((i < RETRY_LIMIT)
319 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
320
321 if ((i == RETRY_LIMIT)
322 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
323 /* */
324 /* Read failed then Return Default value. */
325 /* */
326 *pValue = pAd->BbpWriteLatch[Id];
327
328 DBGPRINT_RAW(RT_DEBUG_ERROR,
329 ("Retry count exhausted or device removed!!!\n"));
330 return STATUS_UNSUCCESSFUL;
331 }
332 /* Prepare for write material */
333 BbpCsr.word = 0;
334 BbpCsr.field.fRead = 1;
335 BbpCsr.field.Busy = 1;
336 BbpCsr.field.RegNum = Id;
337 RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word);
338
339 i = 0;
340 /* Verify the busy condition */
341 do {
342 status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
343 if (status >= 0) {
344 if (!(BbpCsr.field.Busy == BUSY)) {
345 *pValue = (u8)BbpCsr.field.Value;
346 break;
347 }
348 }
349 DBGPRINT(RT_DEBUG_TRACE,
350 ("RTUSBReadBBPRegister(BBP_CSR_CFG_2):retry count=%d!\n",
351 i));
352 i++;
353 } while ((i < RETRY_LIMIT)
354 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
355
356 if ((i == RETRY_LIMIT)
357 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
358 /* */
359 /* Read failed then Return Default value. */
360 /* */
361 *pValue = pAd->BbpWriteLatch[Id];
362
363 DBGPRINT_RAW(RT_DEBUG_ERROR,
364 ("Retry count exhausted or device removed!!!\n"));
365 return STATUS_UNSUCCESSFUL;
366 }
367
368 return STATUS_SUCCESS;
369}
370
371/*
372 ========================================================================
373
374 Routine Description: Write 8-bit BBP register
375
376 Arguments:
377
378 Return Value:
379
380 IRQL =
381
382 Note:
383
384 ========================================================================
385*/
386int RTUSBWriteBBPRegister(struct rt_rtmp_adapter *pAd,
387 u8 Id, u8 Value)
388{
389 BBP_CSR_CFG_STRUC BbpCsr;
390 u32 i = 0;
391 int status;
392 /* Verify the busy condition */
393 do {
394 status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word);
395 if (status >= 0) {
396 if (!(BbpCsr.field.Busy == BUSY))
397 break;
398 }
399 DBGPRINT(RT_DEBUG_TRACE,
400 ("RTUSBWriteBBPRegister(BBP_CSR_CFG):retry count=%d!\n",
401 i));
402 i++;
403 } while ((i < RETRY_LIMIT)
404 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
405
406 if ((i == RETRY_LIMIT)
407 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
408 DBGPRINT_RAW(RT_DEBUG_ERROR,
409 ("Retry count exhausted or device removed!!!\n"));
410 return STATUS_UNSUCCESSFUL;
411 }
412 /* Prepare for write material */
413 BbpCsr.word = 0;
414 BbpCsr.field.fRead = 0;
415 BbpCsr.field.Value = Value;
416 BbpCsr.field.Busy = 1;
417 BbpCsr.field.RegNum = Id;
418 RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word);
419
420 pAd->BbpWriteLatch[Id] = Value;
421
422 return STATUS_SUCCESS;
423}
424
425/*
426 ========================================================================
427
428 Routine Description: Write RF register through MAC
429
430 Arguments:
431
432 Return Value:
433
434 IRQL =
435
436 Note:
437
438 ========================================================================
439*/
440int RTUSBWriteRFRegister(struct rt_rtmp_adapter *pAd, u32 Value)
441{
442 PHY_CSR4_STRUC PhyCsr4;
443 u32 i = 0;
444 int status;
445
446 NdisZeroMemory(&PhyCsr4, sizeof(PHY_CSR4_STRUC));
447 do {
448 status = RTUSBReadMACRegister(pAd, RF_CSR_CFG0, &PhyCsr4.word);
449 if (status >= 0) {
450 if (!(PhyCsr4.field.Busy))
451 break;
452 }
453 DBGPRINT(RT_DEBUG_TRACE,
454 ("RTUSBWriteRFRegister(RF_CSR_CFG0):retry count=%d!\n",
455 i));
456 i++;
457 } while ((i < RETRY_LIMIT)
458 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
459
460 if ((i == RETRY_LIMIT)
461 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
462 DBGPRINT_RAW(RT_DEBUG_ERROR,
463 ("Retry count exhausted or device removed!!!\n"));
464 return STATUS_UNSUCCESSFUL;
465 }
466
467 RTUSBWriteMACRegister(pAd, RF_CSR_CFG0, Value);
468
469 return STATUS_SUCCESS;
470}
471
472/*
473 ========================================================================
474
475 Routine Description:
476
477 Arguments:
478
479 Return Value:
480
481 IRQL =
482
483 Note:
484
485 ========================================================================
486*/
487int RTUSBReadEEPROM(struct rt_rtmp_adapter *pAd,
488 u16 Offset, u8 *pData, u16 length)
489{
490 int Status = STATUS_SUCCESS;
491
492 Status = RTUSB_VendorRequest(pAd,
493 (USBD_TRANSFER_DIRECTION_IN |
494 USBD_SHORT_TRANSFER_OK),
495 DEVICE_VENDOR_REQUEST_IN, 0x9, 0, Offset,
496 pData, length);
497
498 return Status;
499}
500
501/*
502 ========================================================================
503
504 Routine Description:
505
506 Arguments:
507
508 Return Value:
509
510 IRQL =
511
512 Note:
513
514 ========================================================================
515*/
516int RTUSBWriteEEPROM(struct rt_rtmp_adapter *pAd,
517 u16 Offset, u8 *pData, u16 length)
518{
519 int Status = STATUS_SUCCESS;
520
521 Status = RTUSB_VendorRequest(pAd,
522 USBD_TRANSFER_DIRECTION_OUT,
523 DEVICE_VENDOR_REQUEST_OUT,
524 0x8, 0, Offset, pData, length);
525
526 return Status;
527}
528
529int RTUSBReadEEPROM16(struct rt_rtmp_adapter *pAd,
530 u16 offset, u16 *pData)
531{
532 int status;
533 u16 localData;
534
535 status = RTUSBReadEEPROM(pAd, offset, (u8 *)(&localData), 2);
536 if (status == STATUS_SUCCESS)
537 *pData = le2cpu16(localData);
538
539 return status;
540
541}
542
543/*
544 ========================================================================
545
546 Routine Description:
547
548 Arguments:
549
550 Return Value:
551
552 IRQL =
553
554 Note:
555
556 ========================================================================
557*/
558void RTUSBPutToSleep(struct rt_rtmp_adapter *pAd)
559{
560 u32 value;
561
562 /* Timeout 0x40 x 50us */
563 value = (SLEEPCID << 16) + (OWNERMCU << 24) + (0x40 << 8) + 1;
564 RTUSBWriteMACRegister(pAd, 0x7010, value);
565 RTUSBWriteMACRegister(pAd, 0x404, 0x30);
566 /*RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); */
567 DBGPRINT_RAW(RT_DEBUG_ERROR, ("Sleep Mailbox testvalue %x\n", value));
568
569}
570
571/*
572 ========================================================================
573
574 Routine Description:
575
576 Arguments:
577
578 Return Value:
579
580 IRQL =
581
582 Note:
583
584 ========================================================================
585*/
586int RTUSBWakeUp(struct rt_rtmp_adapter *pAd)
587{
588 int Status;
589
590 Status = RTUSB_VendorRequest(pAd,
591 USBD_TRANSFER_DIRECTION_OUT,
592 DEVICE_VENDOR_REQUEST_OUT,
593 0x01, 0x09, 0, NULL, 0);
594
595 return Status;
596}
597
598/*
599 ========================================================================
600
601 Routine Description:
602
603 Arguments:
604
605 Return Value:
606
607 IRQL =
608
609 Note:
610
611 ========================================================================
612*/
613void RTUSBInitializeCmdQ(struct rt_cmdq *cmdq)
614{
615 cmdq->head = NULL;
616 cmdq->tail = NULL;
617 cmdq->size = 0;
618 cmdq->CmdQState = RTMP_TASK_STAT_INITED;
619}
620
621/*
622 ========================================================================
623
624 Routine Description:
625
626 Arguments:
627
628 Return Value:
629
630 IRQL =
631
632 Note:
633
634 ========================================================================
635*/
636int RTUSBEnqueueCmdFromNdis(struct rt_rtmp_adapter *pAd,
637 IN NDIS_OID Oid,
638 IN BOOLEAN SetInformation,
639 void *pInformationBuffer,
640 u32 InformationBufferLength)
641{
642 int status;
643 struct rt_cmdqelmt *cmdqelmt = NULL;
644 struct rt_rtmp_os_task *pTask = &pAd->cmdQTask;
645
646#ifdef KTHREAD_SUPPORT
647 if (pTask->kthread_task == NULL)
648#else
649 CHECK_PID_LEGALITY(pTask->taskPID) {
650 }
651 else
652#endif
653 return NDIS_STATUS_RESOURCES;
654
655 status = os_alloc_mem(pAd, (u8 **) (&cmdqelmt), sizeof(struct rt_cmdqelmt));
656 if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL))
657 return NDIS_STATUS_RESOURCES;
658
659 cmdqelmt->buffer = NULL;
660 if (pInformationBuffer != NULL) {
661 status =
662 os_alloc_mem(pAd, (u8 **) & cmdqelmt->buffer,
663 InformationBufferLength);
664 if ((status != NDIS_STATUS_SUCCESS)
665 || (cmdqelmt->buffer == NULL)) {
666 kfree(cmdqelmt);
667 return NDIS_STATUS_RESOURCES;
668 } else {
669 NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer,
670 InformationBufferLength);
671 cmdqelmt->bufferlength = InformationBufferLength;
672 }
673 } else
674 cmdqelmt->bufferlength = 0;
675
676 cmdqelmt->command = Oid;
677 cmdqelmt->CmdFromNdis = TRUE;
678 if (SetInformation == TRUE)
679 cmdqelmt->SetOperation = TRUE;
680 else
681 cmdqelmt->SetOperation = FALSE;
682
683 NdisAcquireSpinLock(&pAd->CmdQLock);
684 if (pAd->CmdQ.CmdQState & RTMP_TASK_CAN_DO_INSERT) {
685 EnqueueCmd((&pAd->CmdQ), cmdqelmt);
686 status = NDIS_STATUS_SUCCESS;
687 } else {
688 status = NDIS_STATUS_FAILURE;
689 }
690 NdisReleaseSpinLock(&pAd->CmdQLock);
691
692 if (status == NDIS_STATUS_FAILURE) {
693 if (cmdqelmt->buffer)
694 os_free_mem(pAd, cmdqelmt->buffer);
695 os_free_mem(pAd, cmdqelmt);
696 } else
697 RTUSBCMDUp(pAd);
698
699 return NDIS_STATUS_SUCCESS;
700}
701
702/*
703 ========================================================================
704
705 Routine Description:
706
707 Arguments:
708
709 Return Value:
710
711 IRQL =
712
713 Note:
714
715 ========================================================================
716*/
717int RTUSBEnqueueInternalCmd(struct rt_rtmp_adapter *pAd,
718 IN NDIS_OID Oid,
719 void *pInformationBuffer,
720 u32 InformationBufferLength)
721{
722 int status;
723 struct rt_cmdqelmt *cmdqelmt = NULL;
724
725 status = os_alloc_mem(pAd, (u8 **) & cmdqelmt, sizeof(struct rt_cmdqelmt));
726 if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL))
727 return NDIS_STATUS_RESOURCES;
728 NdisZeroMemory(cmdqelmt, sizeof(struct rt_cmdqelmt));
729
730 if (InformationBufferLength > 0) {
731 status =
732 os_alloc_mem(pAd, (u8 **) & cmdqelmt->buffer,
733 InformationBufferLength);
734 if ((status != NDIS_STATUS_SUCCESS)
735 || (cmdqelmt->buffer == NULL)) {
736 os_free_mem(pAd, cmdqelmt);
737 return NDIS_STATUS_RESOURCES;
738 } else {
739 NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer,
740 InformationBufferLength);
741 cmdqelmt->bufferlength = InformationBufferLength;
742 }
743 } else {
744 cmdqelmt->buffer = NULL;
745 cmdqelmt->bufferlength = 0;
746 }
747
748 cmdqelmt->command = Oid;
749 cmdqelmt->CmdFromNdis = FALSE;
750
751 if (cmdqelmt != NULL) {
752 NdisAcquireSpinLock(&pAd->CmdQLock);
753 if (pAd->CmdQ.CmdQState & RTMP_TASK_CAN_DO_INSERT) {
754 EnqueueCmd((&pAd->CmdQ), cmdqelmt);
755 status = NDIS_STATUS_SUCCESS;
756 } else {
757 status = NDIS_STATUS_FAILURE;
758 }
759 NdisReleaseSpinLock(&pAd->CmdQLock);
760
761 if (status == NDIS_STATUS_FAILURE) {
762 if (cmdqelmt->buffer)
763 os_free_mem(pAd, cmdqelmt->buffer);
764 os_free_mem(pAd, cmdqelmt);
765 } else
766 RTUSBCMDUp(pAd);
767 }
768 return NDIS_STATUS_SUCCESS;
769}
770
771/*
772 ========================================================================
773
774 Routine Description:
775
776 Arguments:
777
778 Return Value:
779
780 IRQL =
781
782 Note:
783
784 ========================================================================
785*/
786void RTUSBDequeueCmd(struct rt_cmdq *cmdq, struct rt_cmdqelmt * * pcmdqelmt)
787{
788 *pcmdqelmt = cmdq->head;
789
790 if (*pcmdqelmt != NULL) {
791 cmdq->head = cmdq->head->next;
792 cmdq->size--;
793 if (cmdq->size == 0)
794 cmdq->tail = NULL;
795 }
796}
797
798/*
799 ========================================================================
800 usb_control_msg - Builds a control urb, sends it off and waits for completion
801 @dev: pointer to the usb device to send the message to
802 @pipe: endpoint "pipe" to send the message to
803 @request: USB message request value
804 @requesttype: USB message request type value
805 @value: USB message value
806 @index: USB message index value
807 @data: pointer to the data to send
808 @size: length in bytes of the data to send
809 @timeout: time in jiffies to wait for the message to complete before
810 timing out (if 0 the wait is forever)
811 Context: !in_interrupt ()
812
813 This function sends a simple control message to a specified endpoint
814 and waits for the message to complete, or timeout.
815 If successful, it returns the number of bytes transferred, otherwise a negative error number.
816
817 Don't use this function from within an interrupt context, like a
818 bottom half handler. If you need an asynchronous message, or need to send
819 a message from within interrupt context, use usb_submit_urb()
820 If a thread in your driver uses this call, make sure your disconnect()
821 method can wait for it to complete. Since you don't have a handle on
822 the URB used, you can't cancel the request.
823
824 Routine Description:
825
826 Arguments:
827
828 Return Value:
829
830 Note:
831
832 ========================================================================
833*/
834int RTUSB_VendorRequest(struct rt_rtmp_adapter *pAd,
835 u32 TransferFlags,
836 u8 RequestType,
837 u8 Request,
838 u16 Value,
839 u16 Index,
840 void *TransferBuffer,
841 u32 TransferBufferLength)
842{
843 int ret = 0;
844 struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie;
845
846 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) {
847 DBGPRINT(RT_DEBUG_ERROR, ("device disconnected\n"));
848 return -1;
849 } else if (in_interrupt()) {
850 DBGPRINT(RT_DEBUG_ERROR,
851 ("in_interrupt, RTUSB_VendorRequest Request%02x Value%04x Offset%04x\n",
852 Request, Value, Index));
853
854 return -1;
855 } else {
856#define MAX_RETRY_COUNT 10
857
858 int retryCount = 0;
859 void *tmpBuf = TransferBuffer;
860
861 ret = down_interruptible(&(pAd->UsbVendorReq_semaphore));
862 if (pAd->UsbVendorReqBuf) {
863 ASSERT(TransferBufferLength < MAX_PARAM_BUFFER_SIZE);
864
865 tmpBuf = (void *)pAd->UsbVendorReqBuf;
866 NdisZeroMemory(pAd->UsbVendorReqBuf,
867 TransferBufferLength);
868
869 if (RequestType == DEVICE_VENDOR_REQUEST_OUT)
870 NdisMoveMemory(tmpBuf, TransferBuffer,
871 TransferBufferLength);
872 }
873
874 do {
875 if (RequestType == DEVICE_VENDOR_REQUEST_OUT)
876 ret =
877 usb_control_msg(pObj->pUsb_Dev,
878 usb_sndctrlpipe(pObj->
879 pUsb_Dev,
880 0), Request,
881 RequestType, Value, Index,
882 tmpBuf,
883 TransferBufferLength,
884 CONTROL_TIMEOUT_JIFFIES);
885 else if (RequestType == DEVICE_VENDOR_REQUEST_IN)
886 ret =
887 usb_control_msg(pObj->pUsb_Dev,
888 usb_rcvctrlpipe(pObj->
889 pUsb_Dev,
890 0), Request,
891 RequestType, Value, Index,
892 tmpBuf,
893 TransferBufferLength,
894 CONTROL_TIMEOUT_JIFFIES);
895 else {
896 DBGPRINT(RT_DEBUG_ERROR,
897 ("vendor request direction is failed\n"));
898 ret = -1;
899 }
900
901 retryCount++;
902 if (ret < 0) {
903 DBGPRINT(RT_DEBUG_OFF, ("#\n"));
904 RTMPusecDelay(5000);
905 }
906 } while ((ret < 0) && (retryCount < MAX_RETRY_COUNT));
907
908 if ((pAd->UsbVendorReqBuf)
909 && (RequestType == DEVICE_VENDOR_REQUEST_IN))
910 NdisMoveMemory(TransferBuffer, tmpBuf,
911 TransferBufferLength);
912 up(&(pAd->UsbVendorReq_semaphore));
913
914 if (ret < 0) {
915 DBGPRINT(RT_DEBUG_ERROR,
916 ("RTUSB_VendorRequest failed(%d),TxFlags=0x%x, ReqType=%s, Req=0x%x, Index=0x%x\n",
917 ret, TransferFlags,
918 (RequestType ==
919 DEVICE_VENDOR_REQUEST_OUT ? "OUT" : "IN"),
920 Request, Index));
921 if (Request == 0x2)
922 DBGPRINT(RT_DEBUG_ERROR,
923 ("\tRequest Value=0x%04x!\n", Value));
924
925 if ((TransferBuffer != NULL)
926 && (TransferBufferLength > 0))
927 hex_dump("Failed TransferBuffer value",
928 TransferBuffer, TransferBufferLength);
929 }
930
931 }
932
933 if (ret != -1)
934 return STATUS_SUCCESS;
935 else
936 return STATUS_UNSUCCESSFUL;
937}
938
939/*
940 ========================================================================
941
942 Routine Description:
943 Creates an IRP to submite an IOCTL_INTERNAL_USB_RESET_PORT
944 synchronously. Callers of this function must be running at
945 PASSIVE LEVEL.
946
947 Arguments:
948
949 Return Value:
950
951 Note:
952
953 ========================================================================
954*/
955int RTUSB_ResetDevice(struct rt_rtmp_adapter *pAd)
956{
957 int Status = TRUE;
958
959 DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->USB_ResetDevice\n"));
960 /*RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS); */
961 return Status;
962}
963
964void CMDHandler(struct rt_rtmp_adapter *pAd)
965{
966 struct rt_cmdqelmt *cmdqelmt;
967 u8 *pData;
968 int NdisStatus = NDIS_STATUS_SUCCESS;
969/* unsigned long Now = 0; */
970 int ntStatus;
971/* unsigned long IrqFlags; */
972
973 while (pAd && pAd->CmdQ.size > 0) {
974 NdisStatus = NDIS_STATUS_SUCCESS;
975
976 NdisAcquireSpinLock(&pAd->CmdQLock);
977 RTUSBDequeueCmd(&pAd->CmdQ, &cmdqelmt);
978 NdisReleaseSpinLock(&pAd->CmdQLock);
979
980 if (cmdqelmt == NULL)
981 break;
982
983 pData = cmdqelmt->buffer;
984
985 if (!
986 (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)
987 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) {
988 switch (cmdqelmt->command) {
989 case CMDTHREAD_CHECK_GPIO:
990 {
991 u32 data;
992
993 {
994 /* Read GPIO pin2 as Hardware controlled radio state */
995
996 RTUSBReadMACRegister(pAd,
997 GPIO_CTRL_CFG,
998 &data);
999
1000 if (data & 0x04) {
1001 pAd->StaCfg.bHwRadio =
1002 TRUE;
1003 } else {
1004 pAd->StaCfg.bHwRadio =
1005 FALSE;
1006 }
1007
1008 if (pAd->StaCfg.bRadio !=
1009 (pAd->StaCfg.bHwRadio
1010 && pAd->StaCfg.bSwRadio)) {
1011 pAd->StaCfg.bRadio =
1012 (pAd->StaCfg.
1013 bHwRadio
1014 && pAd->StaCfg.
1015 bSwRadio);
1016 if (pAd->StaCfg.
1017 bRadio == TRUE) {
1018 DBGPRINT_RAW
1019 (RT_DEBUG_ERROR,
1020 ("!!! Radio On !!!\n"));
1021
1022 MlmeRadioOn
1023 (pAd);
1024 /* Update extra information */
1025 pAd->ExtraInfo =
1026 EXTRA_INFO_CLEAR;
1027 } else {
1028 DBGPRINT_RAW
1029 (RT_DEBUG_ERROR,
1030 ("!!! Radio Off !!!\n"));
1031
1032 MlmeRadioOff
1033 (pAd);
1034 /* Update extra information */
1035 pAd->ExtraInfo =
1036 HW_RADIO_OFF;
1037 }
1038 }
1039 }
1040 }
1041 break;
1042
1043 case CMDTHREAD_QKERIODIC_EXECUT:
1044 {
1045 StaQuickResponeForRateUpExec(NULL, pAd,
1046 NULL,
1047 NULL);
1048 }
1049 break;
1050
1051 case CMDTHREAD_RESET_BULK_OUT:
1052 {
1053 u32 MACValue;
1054 u8 Index;
1055 int ret = 0;
1056 struct rt_ht_tx_context *pHTTXContext;
1057/* struct rt_rtmp_tx_ring *pTxRing; */
1058 unsigned long IrqFlags;
1059
1060 DBGPRINT_RAW(RT_DEBUG_TRACE,
1061 ("CmdThread : CMDTHREAD_RESET_BULK_OUT(ResetPipeid=0x%0x)===>\n",
1062 pAd->bulkResetPipeid));
1063 /* All transfers must be aborted or cancelled before attempting to reset the pipe. */
1064 /*RTUSBCancelPendingBulkOutIRP(pAd); */
1065 /* Wait 10ms to let previous packet that are already in HW FIFO to clear. by MAXLEE 12-25-2007 */
1066 Index = 0;
1067 do {
1068 RTUSBReadMACRegister(pAd,
1069 TXRXQ_PCNT,
1070 &MACValue);
1071 if ((MACValue & 0xf00000
1072 /*0x800000 */) == 0)
1073 break;
1074 Index++;
1075 RTMPusecDelay(10000);
1076 } while (Index < 100);
1077 MACValue = 0;
1078 RTUSBReadMACRegister(pAd, USB_DMA_CFG,
1079 &MACValue);
1080 /* To prevent Read Register error, we 2nd check the validity. */
1081 if ((MACValue & 0xc00000) == 0)
1082 RTUSBReadMACRegister(pAd,
1083 USB_DMA_CFG,
1084 &MACValue);
1085 /* To prevent Read Register error, we 3rd check the validity. */
1086 if ((MACValue & 0xc00000) == 0)
1087 RTUSBReadMACRegister(pAd,
1088 USB_DMA_CFG,
1089 &MACValue);
1090 MACValue |= 0x80000;
1091 RTUSBWriteMACRegister(pAd, USB_DMA_CFG,
1092 MACValue);
1093
1094 /* Wait 1ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 */
1095 RTMPusecDelay(1000);
1096
1097 MACValue &= (~0x80000);
1098 RTUSBWriteMACRegister(pAd, USB_DMA_CFG,
1099 MACValue);
1100 DBGPRINT_RAW(RT_DEBUG_TRACE,
1101 ("\tSet 0x2a0 bit19. Clear USB DMA TX path\n"));
1102
1103 /* Wait 5ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 */
1104 /*RTMPusecDelay(5000); */
1105
1106 if ((pAd->
1107 bulkResetPipeid &
1108 BULKOUT_MGMT_RESET_FLAG) ==
1109 BULKOUT_MGMT_RESET_FLAG) {
1110 RTMP_CLEAR_FLAG(pAd,
1111 fRTMP_ADAPTER_BULKOUT_RESET);
1112 if (pAd->MgmtRing.TxSwFreeIdx <
1113 MGMT_RING_SIZE
1114 /* pMLMEContext->bWaitingBulkOut == TRUE */
1115 ) {
1116 RTUSB_SET_BULK_FLAG(pAd,
1117 fRTUSB_BULK_OUT_MLME);
1118 }
1119 RTUSBKickBulkOut(pAd);
1120
1121 DBGPRINT_RAW(RT_DEBUG_TRACE,
1122 ("\tTX MGMT RECOVER Done!\n"));
1123 } else {
1124 pHTTXContext =
1125 &(pAd->
1126 TxContext[pAd->
1127 bulkResetPipeid]);
1128 /*NdisAcquireSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */
1129 RTMP_INT_LOCK(&pAd->
1130 BulkOutLock[pAd->
1131 bulkResetPipeid],
1132 IrqFlags);
1133 if (pAd->
1134 BulkOutPending[pAd->
1135 bulkResetPipeid]
1136 == FALSE) {
1137 pAd->
1138 BulkOutPending[pAd->
1139 bulkResetPipeid]
1140 = TRUE;
1141 pHTTXContext->
1142 IRPPending = TRUE;
1143 pAd->
1144 watchDogTxPendingCnt
1145 [pAd->
1146 bulkResetPipeid] =
1147 1;
1148
1149 /* no matter what, clean the flag */
1150 RTMP_CLEAR_FLAG(pAd,
1151 fRTMP_ADAPTER_BULKOUT_RESET);
1152
1153 /*NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */
1154 RTMP_INT_UNLOCK(&pAd->
1155 BulkOutLock
1156 [pAd->
1157 bulkResetPipeid],
1158 IrqFlags);
1159 {
1160 RTUSBInitHTTxDesc
1161 (pAd,
1162 pHTTXContext,
1163 pAd->
1164 bulkResetPipeid,
1165 pHTTXContext->
1166 BulkOutSize,
1167 (usb_complete_t)
1168 RTUSBBulkOutDataPacketComplete);
1169
1170 ret = RTUSB_SUBMIT_URB
1171 (pHTTXContext->
1172 pUrb);
1173 if (ret != 0) {
1174 RTMP_INT_LOCK
1175 (&pAd->
1176 BulkOutLock
1177 [pAd->
1178 bulkResetPipeid],
1179 IrqFlags);
1180 pAd->
1181 BulkOutPending
1182 [pAd->
1183 bulkResetPipeid]
1184 =
1185 FALSE;
1186 pHTTXContext->
1187 IRPPending
1188 =
1189 FALSE;
1190 pAd->
1191 watchDogTxPendingCnt
1192 [pAd->
1193 bulkResetPipeid]
1194 = 0;
1195 RTMP_INT_UNLOCK
1196 (&pAd->
1197 BulkOutLock
1198 [pAd->
1199 bulkResetPipeid],
1200 IrqFlags);
1201
1202 DBGPRINT
1203 (RT_DEBUG_ERROR,
1204 ("CmdThread : CMDTHREAD_RESET_BULK_OUT: Submit Tx URB failed %d\n",
1205 ret));
1206 } else {
1207 RTMP_IRQ_LOCK
1208 (&pAd->
1209 BulkOutLock
1210 [pAd->
1211 bulkResetPipeid],
1212 IrqFlags);
1213 DBGPRINT_RAW
1214 (RT_DEBUG_TRACE,
1215 ("\tCMDTHREAD_RESET_BULK_OUT: TxContext[%d]:CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, pending=%d!\n",
1216 pAd->
1217 bulkResetPipeid,
1218 pHTTXContext->
1219 CurWritePosition,
1220 pHTTXContext->
1221 NextBulkOutPosition,
1222 pHTTXContext->
1223 ENextBulkOutPosition,
1224 pHTTXContext->
1225 bCopySavePad,
1226 pAd->
1227 BulkOutPending
1228 [pAd->
1229 bulkResetPipeid]));
1230 DBGPRINT_RAW
1231 (RT_DEBUG_TRACE,
1232 ("\t\tBulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n",
1233 pAd->
1234 BulkOutReq,
1235 pAd->
1236 BulkOutComplete,
1237 pAd->
1238 BulkOutCompleteOther));
1239 RTMP_IRQ_UNLOCK
1240 (&pAd->
1241 BulkOutLock
1242 [pAd->
1243 bulkResetPipeid],
1244 IrqFlags);
1245 DBGPRINT_RAW
1246 (RT_DEBUG_TRACE,
1247 ("\tCMDTHREAD_RESET_BULK_OUT: Submit Tx DATA URB for failed BulkReq(0x%lx) Done, status=%d!\n",
1248 pAd->
1249 bulkResetReq
1250 [pAd->
1251 bulkResetPipeid],
1252 pHTTXContext->
1253 pUrb->
1254 status));
1255
1256 }
1257 }
1258 } else {
1259 /*NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */
1260 /*RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); */
1261
1262 DBGPRINT_RAW
1263 (RT_DEBUG_ERROR,
1264 ("CmdThread : TX DATA RECOVER FAIL for BulkReq(0x%lx) because BulkOutPending[%d] is TRUE!\n",
1265 pAd->
1266 bulkResetReq[pAd->
1267 bulkResetPipeid],
1268 pAd->
1269 bulkResetPipeid));
1270 if (pAd->
1271 bulkResetPipeid ==
1272 0) {
1273 u8
1274 pendingContext
1275 = 0;
1276 struct rt_ht_tx_context *
1277 pHTTXContext
1278 =
1279 (struct rt_ht_tx_context *)
1280 (&pAd->
1281 TxContext
1282 [pAd->
1283 bulkResetPipeid]);
1284 struct rt_tx_context *
1285 pMLMEContext
1286 =
1287 (struct rt_tx_context *)
1288 (pAd->
1289 MgmtRing.
1290 Cell[pAd->
1291 MgmtRing.
1292 TxDmaIdx].
1293 AllocVa);
1294 struct rt_tx_context *
1295 pNULLContext
1296 =
1297 (struct rt_tx_context *)
1298 (&pAd->
1299 PsPollContext);
1300 struct rt_tx_context *
1301 pPsPollContext
1302 =
1303 (struct rt_tx_context *)
1304 (&pAd->
1305 NullContext);
1306
1307 if (pHTTXContext->IRPPending)
1308 pendingContext
1309 |=
1310 1;
1311 else if
1312 (pMLMEContext->
1313 IRPPending)
1314 pendingContext
1315 |=
1316 2;
1317 else if
1318 (pNULLContext->
1319 IRPPending)
1320 pendingContext
1321 |=
1322 4;
1323 else if
1324 (pPsPollContext->
1325 IRPPending)
1326 pendingContext
1327 |=
1328 8;
1329 else
1330 pendingContext
1331 = 0;
1332
1333 DBGPRINT_RAW
1334 (RT_DEBUG_ERROR,
1335 ("\tTX Occupied by %d!\n",
1336 pendingContext));
1337 }
1338 /* no matter what, clean the flag */
1339 RTMP_CLEAR_FLAG(pAd,
1340 fRTMP_ADAPTER_BULKOUT_RESET);
1341
1342 RTMP_INT_UNLOCK(&pAd->
1343 BulkOutLock
1344 [pAd->
1345 bulkResetPipeid],
1346 IrqFlags);
1347
1348 RTUSB_SET_BULK_FLAG(pAd,
1349 (fRTUSB_BULK_OUT_DATA_NORMAL
1350 <<
1351 pAd->
1352 bulkResetPipeid));
1353 }
1354
1355 RTMPDeQueuePacket(pAd, FALSE,
1356 NUM_OF_TX_RING,
1357 MAX_TX_PROCESS);
1358 /*RTUSBKickBulkOut(pAd); */
1359 }
1360
1361 }
1362 /*
1363 // Don't cancel BULKIN.
1364 while ((atomic_read(&pAd->PendingRx) > 0) &&
1365 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
1366 {
1367 if (atomic_read(&pAd->PendingRx) > 0)
1368 {
1369 DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!cancel it!\n"));
1370 RTUSBCancelPendingBulkInIRP(pAd);
1371 }
1372 RTMPusecDelay(100000);
1373 }
1374
1375 if ((atomic_read(&pAd->PendingRx) == 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)))
1376 {
1377 u8 i;
1378 RTUSBRxPacket(pAd);
1379 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
1380 pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
1381 for (i = 0; i < (RX_RING_SIZE); i++)
1382 {
1383 struct rt_rx_context *pRxContext = &(pAd->RxContext[i]);
1384
1385 pRxContext->pAd = pAd;
1386 pRxContext->InUse = FALSE;
1387 pRxContext->IRPPending = FALSE;
1388 pRxContext->Readable = FALSE;
1389 pRxContext->ReorderInUse = FALSE;
1390
1391 }
1392 RTUSBBulkReceive(pAd);
1393 DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTUSBBulkReceive\n"));
1394 } */
1395 DBGPRINT_RAW(RT_DEBUG_TRACE,
1396 ("CmdThread : CMDTHREAD_RESET_BULK_OUT<===\n"));
1397 break;
1398
1399 case CMDTHREAD_RESET_BULK_IN:
1400 DBGPRINT_RAW(RT_DEBUG_TRACE,
1401 ("CmdThread : CMDTHREAD_RESET_BULK_IN === >\n"));
1402
1403 /* All transfers must be aborted or cancelled before attempting to reset the pipe. */
1404 {
1405 u32 MACValue;
1406 {
1407 /*while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) */
1408 if ((pAd->PendingRx > 0)
1409 &&
1410 (!RTMP_TEST_FLAG
1411 (pAd,
1412 fRTMP_ADAPTER_NIC_NOT_EXIST))) {
1413 DBGPRINT_RAW
1414 (RT_DEBUG_ERROR,
1415 ("BulkIn IRP Pending!!!\n"));
1416 RTUSBCancelPendingBulkInIRP
1417 (pAd);
1418 RTMPusecDelay(100000);
1419 pAd->PendingRx = 0;
1420 }
1421 }
1422 /* Wait 10ms before reading register. */
1423 RTMPusecDelay(10000);
1424 ntStatus =
1425 RTUSBReadMACRegister(pAd, MAC_CSR0,
1426 &MACValue);
1427
1428 if ((NT_SUCCESS(ntStatus) == TRUE) &&
1429 (!(RTMP_TEST_FLAG
1430 (pAd,
1431 (fRTMP_ADAPTER_RESET_IN_PROGRESS
1432 | fRTMP_ADAPTER_RADIO_OFF |
1433 fRTMP_ADAPTER_HALT_IN_PROGRESS
1434 |
1435 fRTMP_ADAPTER_NIC_NOT_EXIST)))))
1436 {
1437 u8 i;
1438
1439 if (RTMP_TEST_FLAG
1440 (pAd,
1441 (fRTMP_ADAPTER_RESET_IN_PROGRESS
1442 | fRTMP_ADAPTER_RADIO_OFF
1443 |
1444 fRTMP_ADAPTER_HALT_IN_PROGRESS
1445 |
1446 fRTMP_ADAPTER_NIC_NOT_EXIST)))
1447 break;
1448 pAd->NextRxBulkInPosition =
1449 pAd->RxContext[pAd->
1450 NextRxBulkInIndex].
1451 BulkInOffset;
1452 DBGPRINT(RT_DEBUG_TRACE,
1453 ("BULK_IN_RESET: NBIIdx=0x%x,NBIRIdx=0x%x, BIRPos=0x%lx. BIReq=x%lx, BIComplete=0x%lx, BICFail0x%lx\n",
1454 pAd->
1455 NextRxBulkInIndex,
1456 pAd->
1457 NextRxBulkInReadIndex,
1458 pAd->
1459 NextRxBulkInPosition,
1460 pAd->BulkInReq,
1461 pAd->BulkInComplete,
1462 pAd->
1463 BulkInCompleteFail));
1464 for (i = 0; i < RX_RING_SIZE;
1465 i++) {
1466 DBGPRINT(RT_DEBUG_TRACE,
1467 ("\tRxContext[%d]: IRPPending=%d, InUse=%d, Readable=%d!\n",
1468 i,
1469 pAd->
1470 RxContext[i].
1471 IRPPending,
1472 pAd->
1473 RxContext[i].
1474 InUse,
1475 pAd->
1476 RxContext[i].
1477 Readable));
1478 }
1479 /*
1480
1481 DBGPRINT_RAW(RT_DEBUG_ERROR, ("==========================================\n"));
1482
1483 pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index
1484 pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer
1485 for (i = 0; i < (RX_RING_SIZE); i++)
1486 {
1487 struct rt_rx_context *pRxContext = &(pAd->RxContext[i]);
1488
1489 pRxContext->pAd = pAd;
1490 pRxContext->InUse = FALSE;
1491 pRxContext->IRPPending = FALSE;
1492 pRxContext->Readable = FALSE;
1493 pRxContext->ReorderInUse = FALSE;
1494
1495 } */
1496 RTMP_CLEAR_FLAG(pAd,
1497 fRTMP_ADAPTER_BULKIN_RESET);
1498 for (i = 0;
1499 i <
1500 pAd->CommonCfg.
1501 NumOfBulkInIRP; i++) {
1502 /*RTUSBBulkReceive(pAd); */
1503 struct rt_rx_context *pRxContext;
1504 PURB pUrb;
1505 int ret = 0;
1506 unsigned long IrqFlags;
1507
1508 RTMP_IRQ_LOCK(&pAd->
1509 BulkInLock,
1510 IrqFlags);
1511 pRxContext =
1512 &(pAd->
1513 RxContext[pAd->
1514 NextRxBulkInIndex]);
1515 if ((pAd->PendingRx > 0)
1516 || (pRxContext->
1517 Readable ==
1518 TRUE)
1519 || (pRxContext->
1520 InUse ==
1521 TRUE)) {
1522 RTMP_IRQ_UNLOCK
1523 (&pAd->
1524 BulkInLock,
1525 IrqFlags);
1526 break;
1527 }
1528 pRxContext->InUse =
1529 TRUE;
1530 pRxContext->IRPPending =
1531 TRUE;
1532 pAd->PendingRx++;
1533 pAd->BulkInReq++;
1534 RTMP_IRQ_UNLOCK(&pAd->
1535 BulkInLock,
1536 IrqFlags);
1537
1538 /* Init Rx context descriptor */
1539 RTUSBInitRxDesc(pAd,
1540 pRxContext);
1541 pUrb = pRxContext->pUrb;
1542 ret = RTUSB_SUBMIT_URB(pUrb);
1543 if (ret != 0) { /* fail */
1544
1545 RTMP_IRQ_LOCK
1546 (&pAd->
1547 BulkInLock,
1548 IrqFlags);
1549 pRxContext->
1550 InUse =
1551 FALSE;
1552 pRxContext->
1553 IRPPending =
1554 FALSE;
1555 pAd->
1556 PendingRx--;
1557 pAd->
1558 BulkInReq--;
1559 RTMP_IRQ_UNLOCK
1560 (&pAd->
1561 BulkInLock,
1562 IrqFlags);
1563 DBGPRINT
1564 (RT_DEBUG_ERROR,
1565 ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB failed(%d), status=%d\n",
1566 ret,
1567 pUrb->
1568 status));
1569 } else { /* success */
1570 /*DBGPRINT(RT_DEBUG_TRACE, ("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", */
1571 /* pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex)); */
1572 DBGPRINT_RAW
1573 (RT_DEBUG_TRACE,
1574 ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB Done, status=%d!\n",
1575 pUrb->
1576 status));
1577 ASSERT((pRxContext->InUse == pRxContext->IRPPending));
1578 }
1579 }
1580
1581 } else {
1582 /* Card must be removed */
1583 if (NT_SUCCESS(ntStatus) !=
1584 TRUE) {
1585 RTMP_SET_FLAG(pAd,
1586 fRTMP_ADAPTER_NIC_NOT_EXIST);
1587 DBGPRINT_RAW
1588 (RT_DEBUG_ERROR,
1589 ("CMDTHREAD_RESET_BULK_IN: Read Register Failed!Card must be removed!!\n\n"));
1590 } else {
1591 DBGPRINT_RAW
1592 (RT_DEBUG_ERROR,
1593 ("CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x%lx) on !\n",
1594 pAd->Flags));
1595 }
1596 }
1597 }
1598 DBGPRINT_RAW(RT_DEBUG_TRACE,
1599 ("CmdThread : CMDTHREAD_RESET_BULK_IN <===\n"));
1600 break;
1601
1602 case CMDTHREAD_SET_ASIC_WCID:
1603 {
1604 struct rt_set_asic_wcid SetAsicWcid;
1605 u16 offset;
1606 u32 MACValue, MACRValue = 0;
1607 SetAsicWcid =
1608 *((struct rt_set_asic_wcid *)(pData));
1609
1610 if (SetAsicWcid.WCID >=
1611 MAX_LEN_OF_MAC_TABLE)
1612 return;
1613
1614 offset =
1615 MAC_WCID_BASE +
1616 ((u8)SetAsicWcid.WCID) *
1617 HW_WCID_ENTRY_SIZE;
1618
1619 DBGPRINT_RAW(RT_DEBUG_TRACE,
1620 ("CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = %ld, SetTid = %lx, DeleteTid = %lx.\n",
1621 SetAsicWcid.WCID,
1622 SetAsicWcid.SetTid,
1623 SetAsicWcid.DeleteTid));
1624 MACValue =
1625 (pAd->MacTab.
1626 Content[SetAsicWcid.WCID].
1627 Addr[3] << 24) +
1628 (pAd->MacTab.
1629 Content[SetAsicWcid.WCID].
1630 Addr[2] << 16) +
1631 (pAd->MacTab.
1632 Content[SetAsicWcid.WCID].
1633 Addr[1] << 8) +
1634 (pAd->MacTab.
1635 Content[SetAsicWcid.WCID].Addr[0]);
1636 DBGPRINT_RAW(RT_DEBUG_TRACE,
1637 ("1-MACValue= %x,\n",
1638 MACValue));
1639 RTUSBWriteMACRegister(pAd, offset,
1640 MACValue);
1641 /* Read bitmask */
1642 RTUSBReadMACRegister(pAd, offset + 4,
1643 &MACRValue);
1644 if (SetAsicWcid.DeleteTid != 0xffffffff)
1645 MACRValue &=
1646 (~SetAsicWcid.DeleteTid);
1647 if (SetAsicWcid.SetTid != 0xffffffff)
1648 MACRValue |=
1649 (SetAsicWcid.SetTid);
1650 MACRValue &= 0xffff0000;
1651
1652 MACValue =
1653 (pAd->MacTab.
1654 Content[SetAsicWcid.WCID].
1655 Addr[5] << 8) +
1656 pAd->MacTab.Content[SetAsicWcid.
1657 WCID].Addr[4];
1658 MACValue |= MACRValue;
1659 RTUSBWriteMACRegister(pAd, offset + 4,
1660 MACValue);
1661
1662 DBGPRINT_RAW(RT_DEBUG_TRACE,
1663 ("2-MACValue= %x,\n",
1664 MACValue));
1665 }
1666 break;
1667
1668 case CMDTHREAD_SET_ASIC_WCID_CIPHER:
1669 {
1670 struct rt_set_asic_wcid_attri SetAsicWcidAttri;
1671 u16 offset;
1672 u32 MACRValue = 0;
1673 SHAREDKEY_MODE_STRUC csr1;
1674 SetAsicWcidAttri =
1675 *((struct rt_set_asic_wcid_attri *)
1676 (pData));
1677
1678 if (SetAsicWcidAttri.WCID >=
1679 MAX_LEN_OF_MAC_TABLE)
1680 return;
1681
1682 offset =
1683 MAC_WCID_ATTRIBUTE_BASE +
1684 ((u8)SetAsicWcidAttri.WCID) *
1685 HW_WCID_ATTRI_SIZE;
1686
1687 DBGPRINT_RAW(RT_DEBUG_TRACE,
1688 ("Cmd : CMDTHREAD_SET_ASIC_WCID_CIPHER : WCID = %ld, Cipher = %lx.\n",
1689 SetAsicWcidAttri.WCID,
1690 SetAsicWcidAttri.Cipher));
1691 /* Read bitmask */
1692 RTUSBReadMACRegister(pAd, offset,
1693 &MACRValue);
1694 MACRValue = 0;
1695 MACRValue |=
1696 (((u8)SetAsicWcidAttri.
1697 Cipher) << 1);
1698
1699 RTUSBWriteMACRegister(pAd, offset,
1700 MACRValue);
1701 DBGPRINT_RAW(RT_DEBUG_TRACE,
1702 ("2-offset = %x , MACValue= %x,\n",
1703 offset, MACRValue));
1704
1705 offset =
1706 PAIRWISE_IVEIV_TABLE_BASE +
1707 ((u8)SetAsicWcidAttri.WCID) *
1708 HW_IVEIV_ENTRY_SIZE;
1709 MACRValue = 0;
1710 if ((SetAsicWcidAttri.Cipher <=
1711 CIPHER_WEP128))
1712 MACRValue |=
1713 (pAd->StaCfg.
1714 DefaultKeyId << 30);
1715 else
1716 MACRValue |= (0x20000000);
1717 RTUSBWriteMACRegister(pAd, offset,
1718 MACRValue);
1719 DBGPRINT_RAW(RT_DEBUG_TRACE,
1720 ("2-offset = %x , MACValue= %x,\n",
1721 offset, MACRValue));
1722
1723 /* */
1724 /* Update cipher algorithm. WSTA always use BSS0 */
1725 /* */
1726 /* for adhoc mode only ,because wep status slow than add key, when use zero config */
1727 if (pAd->StaCfg.BssType == BSS_ADHOC) {
1728 offset =
1729 MAC_WCID_ATTRIBUTE_BASE;
1730
1731 RTUSBReadMACRegister(pAd,
1732 offset,
1733 &MACRValue);
1734 MACRValue &= (~0xe);
1735 MACRValue |=
1736 (((u8)SetAsicWcidAttri.
1737 Cipher) << 1);
1738
1739 RTUSBWriteMACRegister(pAd,
1740 offset,
1741 MACRValue);
1742
1743 /*Update group key cipher,,because wep status slow than add key, when use zero config */
1744 RTUSBReadMACRegister(pAd,
1745 SHARED_KEY_MODE_BASE
1746 +
1747 4 * (0 /
1748 2),
1749 &csr1.
1750 word);
1751
1752 csr1.field.Bss0Key0CipherAlg =
1753 SetAsicWcidAttri.Cipher;
1754 csr1.field.Bss0Key1CipherAlg =
1755 SetAsicWcidAttri.Cipher;
1756
1757 RTUSBWriteMACRegister(pAd,
1758 SHARED_KEY_MODE_BASE
1759 +
1760 4 * (0 /
1761 2),
1762 csr1.
1763 word);
1764 }
1765 }
1766 break;
1767
1768/*Benson modified for USB interface, avoid in interrupt when write key, 20080724 --> */
1769 case RT_CMD_SET_KEY_TABLE: /*General call for AsicAddPairwiseKeyEntry() */
1770 {
1771 struct rt_add_pairwise_key_entry KeyInfo;
1772 KeyInfo =
1773 *((struct rt_add_pairwise_key_entry *)
1774 (pData));
1775 AsicAddPairwiseKeyEntry(pAd,
1776 KeyInfo.MacAddr,
1777 (u8)KeyInfo.
1778 MacTabMatchWCID,
1779 &KeyInfo.
1780 CipherKey);
1781 }
1782 break;
1783
1784 case RT_CMD_SET_RX_WCID_TABLE: /*General call for RTMPAddWcidAttributeEntry() */
1785 {
1786 struct rt_mac_table_entry *pEntry;
1787 u8 KeyIdx = 0;
1788 u8 CipherAlg = CIPHER_NONE;
1789 u8 ApIdx = BSS0;
1790
1791 pEntry = (struct rt_mac_table_entry *)(pData);
1792
1793 RTMPAddWcidAttributeEntry(pAd,
1794 ApIdx,
1795 KeyIdx,
1796 CipherAlg,
1797 pEntry);
1798 }
1799 break;
1800/*Benson modified for USB interface, avoid in interrupt when write key, 20080724 <-- */
1801
1802 case CMDTHREAD_SET_CLIENT_MAC_ENTRY:
1803 {
1804 struct rt_mac_table_entry *pEntry;
1805 pEntry = (struct rt_mac_table_entry *)pData;
1806
1807 {
1808 AsicRemovePairwiseKeyEntry(pAd,
1809 pEntry->
1810 apidx,
1811 (u8)
1812 pEntry->
1813 Aid);
1814 if ((pEntry->AuthMode <=
1815 Ndis802_11AuthModeAutoSwitch)
1816 && (pEntry->WepStatus ==
1817 Ndis802_11Encryption1Enabled))
1818 {
1819 u32 uIV = 1;
1820 u8 *ptr;
1821
1822 ptr = (u8 *)& uIV;
1823 *(ptr + 3) =
1824 (pAd->StaCfg.
1825 DefaultKeyId << 6);
1826 AsicUpdateWCIDIVEIV(pAd,
1827 pEntry->
1828 Aid,
1829 uIV,
1830 0);
1831 AsicUpdateWCIDAttribute
1832 (pAd, pEntry->Aid,
1833 BSS0,
1834 pAd->
1835 SharedKey[BSS0]
1836 [pAd->StaCfg.
1837 DefaultKeyId].
1838 CipherAlg, FALSE);
1839 } else if (pEntry->AuthMode ==
1840 Ndis802_11AuthModeWPANone)
1841 {
1842 u32 uIV = 1;
1843 u8 *ptr;
1844
1845 ptr = (u8 *)& uIV;
1846 *(ptr + 3) =
1847 (pAd->StaCfg.
1848 DefaultKeyId << 6);
1849 AsicUpdateWCIDIVEIV(pAd,
1850 pEntry->
1851 Aid,
1852 uIV,
1853 0);
1854 AsicUpdateWCIDAttribute
1855 (pAd, pEntry->Aid,
1856 BSS0,
1857 pAd->
1858 SharedKey[BSS0]
1859 [pAd->StaCfg.
1860 DefaultKeyId].
1861 CipherAlg, FALSE);
1862 } else {
1863 /* */
1864 /* Other case, disable engine. */
1865 /* Don't worry WPA key, we will add WPA Key after 4-Way handshaking. */
1866 /* */
1867 u16 offset;
1868 offset =
1869 MAC_WCID_ATTRIBUTE_BASE
1870 +
1871 (pEntry->Aid *
1872 HW_WCID_ATTRI_SIZE);
1873 /* RX_PKEY_MODE:0 for no security; RX_KEY_TAB:0 for shared key table; BSS_IDX:0 */
1874 RTUSBWriteMACRegister
1875 (pAd, offset, 0);
1876 }
1877 }
1878
1879 AsicUpdateRxWCIDTable(pAd, pEntry->Aid,
1880 pEntry->Addr);
1881 DBGPRINT(RT_DEBUG_TRACE,
1882 ("UpdateRxWCIDTable(): Aid=%d, "
1883 "Addr=%pM!\n",
1884 pEntry->Aid,
1885 pEntry->Addr));
1886 }
1887 break;
1888
1889/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */
1890 case CMDTHREAD_UPDATE_PROTECT:
1891 {
1892 AsicUpdateProtect(pAd, 0,
1893 (ALLN_SETPROTECT),
1894 TRUE, 0);
1895 }
1896 break;
1897/* end johnli */
1898
1899 case OID_802_11_ADD_WEP:
1900 {
1901 u32 i;
1902 u32 KeyIdx;
1903 struct rt_ndis_802_11_wep *pWepKey;
1904
1905 DBGPRINT(RT_DEBUG_TRACE,
1906 ("CmdThread::OID_802_11_ADD_WEP \n"));
1907
1908 pWepKey = (struct rt_ndis_802_11_wep *)pData;
1909 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
1910
1911 /* it is a shared key */
1912 if ((KeyIdx >= 4)
1913 || ((pWepKey->KeyLength != 5)
1914 && (pWepKey->KeyLength !=
1915 13))) {
1916 NdisStatus =
1917 NDIS_STATUS_INVALID_DATA;
1918 DBGPRINT(RT_DEBUG_ERROR,
1919 ("CmdThread::OID_802_11_ADD_WEP, INVALID_DATA!!\n"));
1920 } else {
1921 u8 CipherAlg;
1922 pAd->SharedKey[BSS0][KeyIdx].
1923 KeyLen =
1924 (u8)pWepKey->KeyLength;
1925 NdisMoveMemory(pAd->
1926 SharedKey[BSS0]
1927 [KeyIdx].Key,
1928 &pWepKey->
1929 KeyMaterial,
1930 pWepKey->
1931 KeyLength);
1932 CipherAlg =
1933 (pAd->
1934 SharedKey[BSS0][KeyIdx].
1935 KeyLen ==
1936 5) ? CIPHER_WEP64 :
1937 CIPHER_WEP128;
1938
1939 /* */
1940 /* Change the WEP cipher to CKIP cipher if CKIP KP on. */
1941 /* Funk UI or Meetinghouse UI will add ckip key from this path. */
1942 /* */
1943
1944 if (pAd->OpMode == OPMODE_STA) {
1945 pAd->MacTab.
1946 Content[BSSID_WCID].
1947 PairwiseKey.
1948 CipherAlg =
1949 pAd->
1950 SharedKey[BSS0]
1951 [KeyIdx].CipherAlg;
1952 pAd->MacTab.
1953 Content[BSSID_WCID].
1954 PairwiseKey.KeyLen =
1955 pAd->
1956 SharedKey[BSS0]
1957 [KeyIdx].KeyLen;
1958 }
1959 pAd->SharedKey[BSS0][KeyIdx].
1960 CipherAlg = CipherAlg;
1961 if (pWepKey->
1962 KeyIndex & 0x80000000) {
1963 /* Default key for tx (shared key) */
1964 u8 IVEIV[8];
1965 u32 WCIDAttri, Value;
1966 u16 offset, offset2;
1967 NdisZeroMemory(IVEIV,
1968 8);
1969 pAd->StaCfg.
1970 DefaultKeyId =
1971 (u8)KeyIdx;
1972 /* Add BSSID to WCTable. because this is Tx wep key. */
1973 /* WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0 */
1974 WCIDAttri =
1975 (CipherAlg << 1) |
1976 SHAREDKEYTABLE;
1977
1978 offset =
1979 MAC_WCID_ATTRIBUTE_BASE
1980 +
1981 (BSSID_WCID *
1982 HW_WCID_ATTRI_SIZE);
1983 RTUSBWriteMACRegister
1984 (pAd, offset,
1985 WCIDAttri);
1986 /* 1. IV/EIV */
1987 /* Specify key index to find shared key. */
1988 IVEIV[3] = (u8)(KeyIdx << 6); /*WEP Eiv bit off. groupkey index is not 0 */
1989 offset =
1990 PAIRWISE_IVEIV_TABLE_BASE
1991 +
1992 (BSS0Mcast_WCID *
1993 HW_IVEIV_ENTRY_SIZE);
1994 offset2 =
1995 PAIRWISE_IVEIV_TABLE_BASE
1996 +
1997 (BSSID_WCID *
1998 HW_IVEIV_ENTRY_SIZE);
1999 for (i = 0; i < 8;) {
2000 Value =
2001 IVEIV[i];
2002 Value +=
2003 (IVEIV
2004 [i +
2005 1] << 8);
2006 Value +=
2007 (IVEIV
2008 [i +
2009 2] << 16);
2010 Value +=
2011 (IVEIV
2012 [i +
2013 3] << 24);
2014 RTUSBWriteMACRegister
2015 (pAd,
2016 offset + i,
2017 Value);
2018 RTUSBWriteMACRegister
2019 (pAd,
2020 offset2 +
2021 i, Value);
2022 i += 4;
2023 }
2024
2025 /* 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0 */
2026 WCIDAttri =
2027 (pAd->
2028 SharedKey[BSS0]
2029 [KeyIdx].
2030 CipherAlg << 1) |
2031 SHAREDKEYTABLE;
2032 offset =
2033 MAC_WCID_ATTRIBUTE_BASE
2034 +
2035 (BSS0Mcast_WCID *
2036 HW_WCID_ATTRI_SIZE);
2037 DBGPRINT(RT_DEBUG_TRACE,
2038 ("BSS0Mcast_WCID : offset = %x, WCIDAttri = %x\n",
2039 offset,
2040 WCIDAttri));
2041 RTUSBWriteMACRegister
2042 (pAd, offset,
2043 WCIDAttri);
2044
2045 }
2046 AsicAddSharedKeyEntry(pAd, BSS0,
2047 (u8)
2048 KeyIdx,
2049 CipherAlg,
2050 pWepKey->
2051 KeyMaterial,
2052 NULL,
2053 NULL);
2054 DBGPRINT(RT_DEBUG_TRACE,
2055 ("CmdThread::OID_802_11_ADD_WEP (KeyIdx=%d, Len=%d-byte)\n",
2056 KeyIdx,
2057 pWepKey->KeyLength));
2058 }
2059 }
2060 break;
2061
2062 case CMDTHREAD_802_11_COUNTER_MEASURE:
2063 break;
2064
2065 case CMDTHREAD_SET_GROUP_KEY:
2066 WpaStaGroupKeySetting(pAd);
2067 break;
2068
2069 case CMDTHREAD_SET_PAIRWISE_KEY:
2070 WpaStaPairwiseKeySetting(pAd);
2071 break;
2072
2073 case CMDTHREAD_SET_PSM_BIT:
2074 {
2075 u16 *pPsm = (u16 *) pData;
2076 MlmeSetPsmBit(pAd, *pPsm);
2077 }
2078 break;
2079 case CMDTHREAD_FORCE_WAKE_UP:
2080 AsicForceWakeup(pAd, TRUE);
2081 break;
2082
2083 default:
2084 DBGPRINT(RT_DEBUG_ERROR,
2085 ("--> Control Thread !! ERROR !! Unknown(cmdqelmt->command=0x%x) !! \n",
2086 cmdqelmt->command));
2087 break;
2088 }
2089 }
2090
2091 if (cmdqelmt->CmdFromNdis == TRUE) {
2092 if (cmdqelmt->buffer != NULL)
2093 os_free_mem(pAd, cmdqelmt->buffer);
2094 os_free_mem(pAd, cmdqelmt);
2095 } else {
2096 if ((cmdqelmt->buffer != NULL)
2097 && (cmdqelmt->bufferlength != 0))
2098 os_free_mem(pAd, cmdqelmt->buffer);
2099 os_free_mem(pAd, cmdqelmt);
2100 }
2101 } /* end of while */
2102}
2103
2104#endif /* RTMP_MAC_USB // */
diff --git a/drivers/staging/rt2870/common/spectrum.c b/drivers/staging/rt2870/common/spectrum.c
deleted file mode 100644
index 1cf2c263f45..00000000000
--- a/drivers/staging/rt2870/common/spectrum.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/common/spectrum.c"
diff --git a/drivers/staging/rt2870/dfs.h b/drivers/staging/rt2870/dfs.h
deleted file mode 100644
index 1fdbd7bc5de..00000000000
--- a/drivers/staging/rt2870/dfs.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/dfs.h"
diff --git a/drivers/staging/rt2870/md5.h b/drivers/staging/rt2870/md5.h
deleted file mode 100644
index d60cd05b54f..00000000000
--- a/drivers/staging/rt2870/md5.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/md5.h"
diff --git a/drivers/staging/rt2870/mlme.h b/drivers/staging/rt2870/mlme.h
deleted file mode 100644
index 58753ac441d..00000000000
--- a/drivers/staging/rt2870/mlme.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/mlme.h"
diff --git a/drivers/staging/rt2870/oid.h b/drivers/staging/rt2870/oid.h
deleted file mode 100644
index 1223d81bfc6..00000000000
--- a/drivers/staging/rt2870/oid.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/oid.h"
diff --git a/drivers/staging/rt2870/rt28xx.h b/drivers/staging/rt2870/rt28xx.h
deleted file mode 100644
index 29bad957de4..00000000000
--- a/drivers/staging/rt2870/rt28xx.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rt28xx.h"
diff --git a/drivers/staging/rt2870/rt_config.h b/drivers/staging/rt2870/rt_config.h
deleted file mode 100644
index 1f6d6ed5630..00000000000
--- a/drivers/staging/rt2870/rt_config.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rt_config.h"
diff --git a/drivers/staging/rt2870/rt_linux.c b/drivers/staging/rt2870/rt_linux.c
deleted file mode 100644
index 88c697bf90e..00000000000
--- a/drivers/staging/rt2870/rt_linux.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rt_linux.c"
diff --git a/drivers/staging/rt2870/rt_linux.h b/drivers/staging/rt2870/rt_linux.h
deleted file mode 100644
index b2aeafbd518..00000000000
--- a/drivers/staging/rt2870/rt_linux.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rt_linux.h"
diff --git a/drivers/staging/rt2870/rt_main_dev.c b/drivers/staging/rt2870/rt_main_dev.c
deleted file mode 100644
index 121e1636017..00000000000
--- a/drivers/staging/rt2870/rt_main_dev.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rt_main_dev.c"
diff --git a/drivers/staging/rt2870/rt_profile.c b/drivers/staging/rt2870/rt_profile.c
deleted file mode 100644
index 15988c5d9df..00000000000
--- a/drivers/staging/rt2870/rt_profile.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rt_profile.c"
diff --git a/drivers/staging/rt2870/rt_usb.c b/drivers/staging/rt2870/rt_usb.c
deleted file mode 100644
index 5e02d4c88d7..00000000000
--- a/drivers/staging/rt2870/rt_usb.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rt_usb.c"
diff --git a/drivers/staging/rt2870/rtmp.h b/drivers/staging/rt2870/rtmp.h
deleted file mode 100644
index e5ef89f8bef..00000000000
--- a/drivers/staging/rt2870/rtmp.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rtmp.h"
diff --git a/drivers/staging/rt2870/rtmp_ckipmic.h b/drivers/staging/rt2870/rtmp_ckipmic.h
deleted file mode 100644
index 0e7f1dfd454..00000000000
--- a/drivers/staging/rt2870/rtmp_ckipmic.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rtmp_ckipmic.h"
diff --git a/drivers/staging/rt2870/rtmp_def.h b/drivers/staging/rt2870/rtmp_def.h
deleted file mode 100644
index 839d791b4f6..00000000000
--- a/drivers/staging/rt2870/rtmp_def.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rtmp_def.h"
diff --git a/drivers/staging/rt2870/rtmp_type.h b/drivers/staging/rt2870/rtmp_type.h
deleted file mode 100644
index fbf97d0fa5d..00000000000
--- a/drivers/staging/rt2870/rtmp_type.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/rtmp_type.h"
diff --git a/drivers/staging/rt2870/spectrum.h b/drivers/staging/rt2870/spectrum.h
deleted file mode 100644
index 8aa23a1833b..00000000000
--- a/drivers/staging/rt2870/spectrum.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/spectrum.h"
diff --git a/drivers/staging/rt2870/spectrum_def.h b/drivers/staging/rt2870/spectrum_def.h
deleted file mode 100644
index a65f551e391..00000000000
--- a/drivers/staging/rt2870/spectrum_def.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/spectrum_def.h"
diff --git a/drivers/staging/rt2870/sta/aironet.c b/drivers/staging/rt2870/sta/aironet.c
deleted file mode 100644
index 72b7f2e6bf7..00000000000
--- a/drivers/staging/rt2870/sta/aironet.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/aironet.c"
diff --git a/drivers/staging/rt2870/sta/assoc.c b/drivers/staging/rt2870/sta/assoc.c
deleted file mode 100644
index 46564d7a01a..00000000000
--- a/drivers/staging/rt2870/sta/assoc.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/assoc.c"
diff --git a/drivers/staging/rt2870/sta/auth.c b/drivers/staging/rt2870/sta/auth.c
deleted file mode 100644
index 57632f9ec78..00000000000
--- a/drivers/staging/rt2870/sta/auth.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/auth.c"
diff --git a/drivers/staging/rt2870/sta/auth_rsp.c b/drivers/staging/rt2870/sta/auth_rsp.c
deleted file mode 100644
index 783e266d3e8..00000000000
--- a/drivers/staging/rt2870/sta/auth_rsp.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/auth_rsp.c"
diff --git a/drivers/staging/rt2870/sta/connect.c b/drivers/staging/rt2870/sta/connect.c
deleted file mode 100644
index f6c7bbf542d..00000000000
--- a/drivers/staging/rt2870/sta/connect.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/connect.c"
diff --git a/drivers/staging/rt2870/sta/rtmp_data.c b/drivers/staging/rt2870/sta/rtmp_data.c
deleted file mode 100644
index b67e06952bc..00000000000
--- a/drivers/staging/rt2870/sta/rtmp_data.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/rtmp_data.c"
diff --git a/drivers/staging/rt2870/sta/sanity.c b/drivers/staging/rt2870/sta/sanity.c
deleted file mode 100644
index f1f2333bb99..00000000000
--- a/drivers/staging/rt2870/sta/sanity.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/sanity.c"
diff --git a/drivers/staging/rt2870/sta/sync.c b/drivers/staging/rt2870/sta/sync.c
deleted file mode 100644
index 66c8772ad34..00000000000
--- a/drivers/staging/rt2870/sta/sync.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/sync.c"
diff --git a/drivers/staging/rt2870/sta/wpa.c b/drivers/staging/rt2870/sta/wpa.c
deleted file mode 100644
index 57a2eb2d089..00000000000
--- a/drivers/staging/rt2870/sta/wpa.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../rt2860/sta/wpa.c"
diff --git a/drivers/staging/rt2870/sta_ioctl.c b/drivers/staging/rt2870/sta_ioctl.c
deleted file mode 100644
index 3553a6c898b..00000000000
--- a/drivers/staging/rt2870/sta_ioctl.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/sta_ioctl.c"
diff --git a/drivers/staging/rt2870/usb_main_dev.c b/drivers/staging/rt2870/usb_main_dev.c
deleted file mode 100644
index 6e63bc50047..00000000000
--- a/drivers/staging/rt2870/usb_main_dev.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/usb_main_dev.c"
diff --git a/drivers/staging/rt2870/wpa.h b/drivers/staging/rt2870/wpa.h
deleted file mode 100644
index 71250722414..00000000000
--- a/drivers/staging/rt2870/wpa.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../rt2860/wpa.h"