diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2009-02-03 19:28:48 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@kvm.kroah.org> | 2009-02-09 14:26:17 -0500 |
commit | 89cb7e7fd6c0917bb9236ea48bf538d4668ed009 (patch) | |
tree | 7abc032bbb32db29f460ef84806d72296b237a94 /drivers | |
parent | f06da264cfb0f9444d41ca247213e419f90aa72a (diff) |
Revert Staging: at76_usb: update drivers/staging/at76_usb w/ mac80211 port
Reverts 02227c28391b5059a7710d6039c52912b0ee2c1d
(Had to be done by hand due to other patches that had come after this.)
Turns out that we don't want the mac80211 port of this driver just yet, as
there is a different driver working on adding this support.
So keep things old and different for now.
This is being reverted at the request of the linux-wireless developers.
Cc: Kalle Valo <kalle.valo@iki.fi>
Cc: John W. Linville <linville@tuxdriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/at76_usb/Kconfig | 2 | ||||
-rw-r--r-- | drivers/staging/at76_usb/at76_usb.c | 4614 | ||||
-rw-r--r-- | drivers/staging/at76_usb/at76_usb.h | 227 |
3 files changed, 3878 insertions, 965 deletions
diff --git a/drivers/staging/at76_usb/Kconfig b/drivers/staging/at76_usb/Kconfig index 4c0e55e15448..8606f9621624 100644 --- a/drivers/staging/at76_usb/Kconfig +++ b/drivers/staging/at76_usb/Kconfig | |||
@@ -1,6 +1,6 @@ | |||
1 | config USB_ATMEL | 1 | config USB_ATMEL |
2 | tristate "Atmel at76c503/at76c505/at76c505a USB cards" | 2 | tristate "Atmel at76c503/at76c505/at76c505a USB cards" |
3 | depends on MAC80211 && WLAN_80211 && USB | 3 | depends on WLAN_80211 && USB |
4 | default N | 4 | default N |
5 | select FW_LOADER | 5 | select FW_LOADER |
6 | ---help--- | 6 | ---help--- |
diff --git a/drivers/staging/at76_usb/at76_usb.c b/drivers/staging/at76_usb/at76_usb.c index 185533e54769..9195ee9319ff 100644 --- a/drivers/staging/at76_usb/at76_usb.c +++ b/drivers/staging/at76_usb/at76_usb.c | |||
@@ -6,7 +6,6 @@ | |||
6 | * Copyright (c) 2004 Nick Jones | 6 | * Copyright (c) 2004 Nick Jones |
7 | * Copyright (c) 2004 Balint Seeber <n0_5p4m_p13453@hotmail.com> | 7 | * Copyright (c) 2004 Balint Seeber <n0_5p4m_p13453@hotmail.com> |
8 | * Copyright (c) 2007 Guido Guenther <agx@sigxcpu.org> | 8 | * Copyright (c) 2007 Guido Guenther <agx@sigxcpu.org> |
9 | * Copyright (c) 2007 Kalle Valo <kalle.valo@iki.fi> | ||
10 | * | 9 | * |
11 | * This program is free software; you can redistribute it and/or | 10 | * This program is free software; you can redistribute it and/or |
12 | * modify it under the terms of the GNU General Public License as | 11 | * modify it under the terms of the GNU General Public License as |
@@ -17,13 +16,6 @@ | |||
17 | * Atmel AT76C503A/505/505A. | 16 | * Atmel AT76C503A/505/505A. |
18 | * | 17 | * |
19 | * Some iw_handler code was taken from airo.c, (C) 1999 Benjamin Reed | 18 | * Some iw_handler code was taken from airo.c, (C) 1999 Benjamin Reed |
20 | * | ||
21 | * TODO for the mac80211 port: | ||
22 | * o adhoc support | ||
23 | * o RTS/CTS support | ||
24 | * o Power Save Mode support | ||
25 | * o support for short/long preambles | ||
26 | * o export variables through debugfs/sysfs | ||
27 | */ | 19 | */ |
28 | 20 | ||
29 | #include <linux/init.h> | 21 | #include <linux/init.h> |
@@ -44,7 +36,7 @@ | |||
44 | #include <net/ieee80211_radiotap.h> | 36 | #include <net/ieee80211_radiotap.h> |
45 | #include <linux/firmware.h> | 37 | #include <linux/firmware.h> |
46 | #include <linux/leds.h> | 38 | #include <linux/leds.h> |
47 | #include <net/mac80211.h> | 39 | #include <net/ieee80211.h> |
48 | 40 | ||
49 | #include "at76_usb.h" | 41 | #include "at76_usb.h" |
50 | 42 | ||
@@ -84,43 +76,31 @@ | |||
84 | #define DBG_WE_EVENTS 0x08000000 /* dump wireless events */ | 76 | #define DBG_WE_EVENTS 0x08000000 /* dump wireless events */ |
85 | #define DBG_FW 0x10000000 /* firmware download */ | 77 | #define DBG_FW 0x10000000 /* firmware download */ |
86 | #define DBG_DFU 0x20000000 /* device firmware upgrade */ | 78 | #define DBG_DFU 0x20000000 /* device firmware upgrade */ |
87 | #define DBG_CMD 0x40000000 | ||
88 | #define DBG_MAC80211 0x80000000 | ||
89 | 79 | ||
90 | #define DBG_DEFAULTS 0 | 80 | #define DBG_DEFAULTS 0 |
91 | 81 | ||
92 | /* Use our own dbg macro */ | 82 | /* Use our own dbg macro */ |
93 | #define at76_dbg(bits, format, arg...) \ | 83 | #define at76_dbg(bits, format, arg...) \ |
94 | do { \ | 84 | do { \ |
95 | if (at76_debug & (bits)) \ | 85 | if (at76_debug & (bits)) \ |
96 | printk(KERN_DEBUG DRIVER_NAME ": " format "\n" , ## arg); \ | ||
97 | } while (0) | ||
98 | |||
99 | #define at76_dbg_dump(bits, buf, len, format, arg...) \ | ||
100 | do { \ | ||
101 | if (at76_debug & (bits)) { \ | ||
102 | printk(KERN_DEBUG DRIVER_NAME ": " format "\n" , ## arg); \ | 86 | printk(KERN_DEBUG DRIVER_NAME ": " format "\n" , ## arg); \ |
103 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len); \ | 87 | } while (0) |
104 | } \ | ||
105 | } while (0) | ||
106 | 88 | ||
107 | static int at76_debug = DBG_DEFAULTS; | 89 | static int at76_debug = DBG_DEFAULTS; |
108 | 90 | ||
109 | #define FIRMWARE_IS_WPA(ver) ((ver.major == 1) && (ver.minor == 103)) | ||
110 | |||
111 | /* Protect against concurrent firmware loading and parsing */ | 91 | /* Protect against concurrent firmware loading and parsing */ |
112 | static struct mutex fw_mutex; | 92 | static struct mutex fw_mutex; |
113 | 93 | ||
114 | static struct fwentry firmwares[] = { | 94 | static struct fwentry firmwares[] = { |
115 | [0] = { "" }, | 95 | [0] = {""}, |
116 | [BOARD_503_ISL3861] = { "atmel_at76c503-i3861.bin" }, | 96 | [BOARD_503_ISL3861] = {"atmel_at76c503-i3861.bin"}, |
117 | [BOARD_503_ISL3863] = { "atmel_at76c503-i3863.bin" }, | 97 | [BOARD_503_ISL3863] = {"atmel_at76c503-i3863.bin"}, |
118 | [BOARD_503] = { "atmel_at76c503-rfmd.bin" }, | 98 | [BOARD_503] = {"atmel_at76c503-rfmd.bin"}, |
119 | [BOARD_503_ACC] = { "atmel_at76c503-rfmd-acc.bin" }, | 99 | [BOARD_503_ACC] = {"atmel_at76c503-rfmd-acc.bin"}, |
120 | [BOARD_505] = { "atmel_at76c505-rfmd.bin" }, | 100 | [BOARD_505] = {"atmel_at76c505-rfmd.bin"}, |
121 | [BOARD_505_2958] = { "atmel_at76c505-rfmd2958.bin" }, | 101 | [BOARD_505_2958] = {"atmel_at76c505-rfmd2958.bin"}, |
122 | [BOARD_505A] = { "atmel_at76c505a-rfmd2958.bin" }, | 102 | [BOARD_505A] = {"atmel_at76c505a-rfmd2958.bin"}, |
123 | [BOARD_505AMX] = { "atmel_at76c505amx-rfmd.bin" }, | 103 | [BOARD_505AMX] = {"atmel_at76c505amx-rfmd.bin"}, |
124 | }; | 104 | }; |
125 | 105 | ||
126 | #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops) | 106 | #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops) |
@@ -130,133 +110,133 @@ static struct usb_device_id dev_table[] = { | |||
130 | * at76c503-i3861 | 110 | * at76c503-i3861 |
131 | */ | 111 | */ |
132 | /* Generic AT76C503/3861 device */ | 112 | /* Generic AT76C503/3861 device */ |
133 | { USB_DEVICE(0x03eb, 0x7603), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 113 | {USB_DEVICE(0x03eb, 0x7603), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
134 | /* Linksys WUSB11 v2.1/v2.6 */ | 114 | /* Linksys WUSB11 v2.1/v2.6 */ |
135 | { USB_DEVICE(0x066b, 0x2211), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 115 | {USB_DEVICE(0x066b, 0x2211), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
136 | /* Netgear MA101 rev. A */ | 116 | /* Netgear MA101 rev. A */ |
137 | { USB_DEVICE(0x0864, 0x4100), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 117 | {USB_DEVICE(0x0864, 0x4100), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
138 | /* Tekram U300C / Allnet ALL0193 */ | 118 | /* Tekram U300C / Allnet ALL0193 */ |
139 | { USB_DEVICE(0x0b3b, 0x1612), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 119 | {USB_DEVICE(0x0b3b, 0x1612), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
140 | /* HP HN210W J7801A */ | 120 | /* HP HN210W J7801A */ |
141 | { USB_DEVICE(0x03f0, 0x011c), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 121 | {USB_DEVICE(0x03f0, 0x011c), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
142 | /* Sitecom/Z-Com/Zyxel M4Y-750 */ | 122 | /* Sitecom/Z-Com/Zyxel M4Y-750 */ |
143 | { USB_DEVICE(0x0cde, 0x0001), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 123 | {USB_DEVICE(0x0cde, 0x0001), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
144 | /* Dynalink/Askey WLL013 (intersil) */ | 124 | /* Dynalink/Askey WLL013 (intersil) */ |
145 | { USB_DEVICE(0x069a, 0x0320), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 125 | {USB_DEVICE(0x069a, 0x0320), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
146 | /* EZ connect 11Mpbs Wireless USB Adapter SMC2662W v1 */ | 126 | /* EZ connect 11Mpbs Wireless USB Adapter SMC2662W v1 */ |
147 | { USB_DEVICE(0x0d5c, 0xa001), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 127 | {USB_DEVICE(0x0d5c, 0xa001), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
148 | /* BenQ AWL300 */ | 128 | /* BenQ AWL300 */ |
149 | { USB_DEVICE(0x04a5, 0x9000), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 129 | {USB_DEVICE(0x04a5, 0x9000), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
150 | /* Addtron AWU-120, Compex WLU11 */ | 130 | /* Addtron AWU-120, Compex WLU11 */ |
151 | { USB_DEVICE(0x05dd, 0xff31), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 131 | {USB_DEVICE(0x05dd, 0xff31), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
152 | /* Intel AP310 AnyPoint II USB */ | 132 | /* Intel AP310 AnyPoint II USB */ |
153 | { USB_DEVICE(0x8086, 0x0200), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 133 | {USB_DEVICE(0x8086, 0x0200), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
154 | /* Dynalink L11U */ | 134 | /* Dynalink L11U */ |
155 | { USB_DEVICE(0x0d8e, 0x7100), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 135 | {USB_DEVICE(0x0d8e, 0x7100), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
156 | /* Arescom WL-210, FCC id 07J-GL2411USB */ | 136 | /* Arescom WL-210, FCC id 07J-GL2411USB */ |
157 | { USB_DEVICE(0x0d8e, 0x7110), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 137 | {USB_DEVICE(0x0d8e, 0x7110), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
158 | /* I-O DATA WN-B11/USB */ | 138 | /* I-O DATA WN-B11/USB */ |
159 | { USB_DEVICE(0x04bb, 0x0919), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 139 | {USB_DEVICE(0x04bb, 0x0919), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
160 | /* BT Voyager 1010 */ | 140 | /* BT Voyager 1010 */ |
161 | { USB_DEVICE(0x069a, 0x0821), USB_DEVICE_DATA(BOARD_503_ISL3861) }, | 141 | {USB_DEVICE(0x069a, 0x0821), USB_DEVICE_DATA(BOARD_503_ISL3861)}, |
162 | /* | 142 | /* |
163 | * at76c503-i3863 | 143 | * at76c503-i3863 |
164 | */ | 144 | */ |
165 | /* Generic AT76C503/3863 device */ | 145 | /* Generic AT76C503/3863 device */ |
166 | { USB_DEVICE(0x03eb, 0x7604), USB_DEVICE_DATA(BOARD_503_ISL3863) }, | 146 | {USB_DEVICE(0x03eb, 0x7604), USB_DEVICE_DATA(BOARD_503_ISL3863)}, |
167 | /* Samsung SWL-2100U */ | 147 | /* Samsung SWL-2100U */ |
168 | { USB_DEVICE(0x055d, 0xa000), USB_DEVICE_DATA(BOARD_503_ISL3863) }, | 148 | {USB_DEVICE(0x055d, 0xa000), USB_DEVICE_DATA(BOARD_503_ISL3863)}, |
169 | /* | 149 | /* |
170 | * at76c503-rfmd | 150 | * at76c503-rfmd |
171 | */ | 151 | */ |
172 | /* Generic AT76C503/RFMD device */ | 152 | /* Generic AT76C503/RFMD device */ |
173 | { USB_DEVICE(0x03eb, 0x7605), USB_DEVICE_DATA(BOARD_503) }, | 153 | {USB_DEVICE(0x03eb, 0x7605), USB_DEVICE_DATA(BOARD_503)}, |
174 | /* Dynalink/Askey WLL013 (rfmd) */ | 154 | /* Dynalink/Askey WLL013 (rfmd) */ |
175 | { USB_DEVICE(0x069a, 0x0321), USB_DEVICE_DATA(BOARD_503) }, | 155 | {USB_DEVICE(0x069a, 0x0321), USB_DEVICE_DATA(BOARD_503)}, |
176 | /* Linksys WUSB11 v2.6 */ | 156 | /* Linksys WUSB11 v2.6 */ |
177 | { USB_DEVICE(0x077b, 0x2219), USB_DEVICE_DATA(BOARD_503) }, | 157 | {USB_DEVICE(0x077b, 0x2219), USB_DEVICE_DATA(BOARD_503)}, |
178 | /* Network Everywhere NWU11B */ | 158 | /* Network Everywhere NWU11B */ |
179 | { USB_DEVICE(0x077b, 0x2227), USB_DEVICE_DATA(BOARD_503) }, | 159 | {USB_DEVICE(0x077b, 0x2227), USB_DEVICE_DATA(BOARD_503)}, |
180 | /* Netgear MA101 rev. B */ | 160 | /* Netgear MA101 rev. B */ |
181 | { USB_DEVICE(0x0864, 0x4102), USB_DEVICE_DATA(BOARD_503) }, | 161 | {USB_DEVICE(0x0864, 0x4102), USB_DEVICE_DATA(BOARD_503)}, |
182 | /* D-Link DWL-120 rev. E */ | 162 | /* D-Link DWL-120 rev. E */ |
183 | { USB_DEVICE(0x2001, 0x3200), USB_DEVICE_DATA(BOARD_503) }, | 163 | {USB_DEVICE(0x2001, 0x3200), USB_DEVICE_DATA(BOARD_503)}, |
184 | /* Actiontec 802UAT1, HWU01150-01UK */ | 164 | /* Actiontec 802UAT1, HWU01150-01UK */ |
185 | { USB_DEVICE(0x1668, 0x7605), USB_DEVICE_DATA(BOARD_503) }, | 165 | {USB_DEVICE(0x1668, 0x7605), USB_DEVICE_DATA(BOARD_503)}, |
186 | /* AirVast W-Buddie WN210 */ | 166 | /* AirVast W-Buddie WN210 */ |
187 | { USB_DEVICE(0x03eb, 0x4102), USB_DEVICE_DATA(BOARD_503) }, | 167 | {USB_DEVICE(0x03eb, 0x4102), USB_DEVICE_DATA(BOARD_503)}, |
188 | /* Dick Smith Electronics XH1153 802.11b USB adapter */ | 168 | /* Dick Smith Electronics XH1153 802.11b USB adapter */ |
189 | { USB_DEVICE(0x1371, 0x5743), USB_DEVICE_DATA(BOARD_503) }, | 169 | {USB_DEVICE(0x1371, 0x5743), USB_DEVICE_DATA(BOARD_503)}, |
190 | /* CNet CNUSB611 */ | 170 | /* CNet CNUSB611 */ |
191 | { USB_DEVICE(0x1371, 0x0001), USB_DEVICE_DATA(BOARD_503) }, | 171 | {USB_DEVICE(0x1371, 0x0001), USB_DEVICE_DATA(BOARD_503)}, |
192 | /* FiberLine FL-WL200U */ | 172 | /* FiberLine FL-WL200U */ |
193 | { USB_DEVICE(0x1371, 0x0002), USB_DEVICE_DATA(BOARD_503) }, | 173 | {USB_DEVICE(0x1371, 0x0002), USB_DEVICE_DATA(BOARD_503)}, |
194 | /* BenQ AWL400 USB stick */ | 174 | /* BenQ AWL400 USB stick */ |
195 | { USB_DEVICE(0x04a5, 0x9001), USB_DEVICE_DATA(BOARD_503) }, | 175 | {USB_DEVICE(0x04a5, 0x9001), USB_DEVICE_DATA(BOARD_503)}, |
196 | /* 3Com 3CRSHEW696 */ | 176 | /* 3Com 3CRSHEW696 */ |
197 | { USB_DEVICE(0x0506, 0x0a01), USB_DEVICE_DATA(BOARD_503) }, | 177 | {USB_DEVICE(0x0506, 0x0a01), USB_DEVICE_DATA(BOARD_503)}, |
198 | /* Siemens Santis ADSL WLAN USB adapter WLL 013 */ | 178 | /* Siemens Santis ADSL WLAN USB adapter WLL 013 */ |
199 | { USB_DEVICE(0x0681, 0x001b), USB_DEVICE_DATA(BOARD_503) }, | 179 | {USB_DEVICE(0x0681, 0x001b), USB_DEVICE_DATA(BOARD_503)}, |
200 | /* Belkin F5D6050, version 2 */ | 180 | /* Belkin F5D6050, version 2 */ |
201 | { USB_DEVICE(0x050d, 0x0050), USB_DEVICE_DATA(BOARD_503) }, | 181 | {USB_DEVICE(0x050d, 0x0050), USB_DEVICE_DATA(BOARD_503)}, |
202 | /* iBlitzz, BWU613 (not *B or *SB) */ | 182 | /* iBlitzz, BWU613 (not *B or *SB) */ |
203 | { USB_DEVICE(0x07b8, 0xb000), USB_DEVICE_DATA(BOARD_503) }, | 183 | {USB_DEVICE(0x07b8, 0xb000), USB_DEVICE_DATA(BOARD_503)}, |
204 | /* Gigabyte GN-WLBM101 */ | 184 | /* Gigabyte GN-WLBM101 */ |
205 | { USB_DEVICE(0x1044, 0x8003), USB_DEVICE_DATA(BOARD_503) }, | 185 | {USB_DEVICE(0x1044, 0x8003), USB_DEVICE_DATA(BOARD_503)}, |
206 | /* Planex GW-US11S */ | 186 | /* Planex GW-US11S */ |
207 | { USB_DEVICE(0x2019, 0x3220), USB_DEVICE_DATA(BOARD_503) }, | 187 | {USB_DEVICE(0x2019, 0x3220), USB_DEVICE_DATA(BOARD_503)}, |
208 | /* Internal WLAN adapter in h5[4,5]xx series iPAQs */ | 188 | /* Internal WLAN adapter in h5[4,5]xx series iPAQs */ |
209 | { USB_DEVICE(0x049f, 0x0032), USB_DEVICE_DATA(BOARD_503) }, | 189 | {USB_DEVICE(0x049f, 0x0032), USB_DEVICE_DATA(BOARD_503)}, |
210 | /* Corega Wireless LAN USB-11 mini */ | 190 | /* Corega Wireless LAN USB-11 mini */ |
211 | { USB_DEVICE(0x07aa, 0x0011), USB_DEVICE_DATA(BOARD_503) }, | 191 | {USB_DEVICE(0x07aa, 0x0011), USB_DEVICE_DATA(BOARD_503)}, |
212 | /* Corega Wireless LAN USB-11 mini2 */ | 192 | /* Corega Wireless LAN USB-11 mini2 */ |
213 | { USB_DEVICE(0x07aa, 0x0018), USB_DEVICE_DATA(BOARD_503) }, | 193 | {USB_DEVICE(0x07aa, 0x0018), USB_DEVICE_DATA(BOARD_503)}, |
214 | /* Uniden PCW100 */ | 194 | /* Uniden PCW100 */ |
215 | { USB_DEVICE(0x05dd, 0xff35), USB_DEVICE_DATA(BOARD_503) }, | 195 | {USB_DEVICE(0x05dd, 0xff35), USB_DEVICE_DATA(BOARD_503)}, |
216 | /* | 196 | /* |
217 | * at76c503-rfmd-acc | 197 | * at76c503-rfmd-acc |
218 | */ | 198 | */ |
219 | /* SMC2664W */ | 199 | /* SMC2664W */ |
220 | { USB_DEVICE(0x083a, 0x3501), USB_DEVICE_DATA(BOARD_503_ACC) }, | 200 | {USB_DEVICE(0x083a, 0x3501), USB_DEVICE_DATA(BOARD_503_ACC)}, |
221 | /* Belkin F5D6050, SMC2662W v2, SMC2662W-AR */ | 201 | /* Belkin F5D6050, SMC2662W v2, SMC2662W-AR */ |
222 | { USB_DEVICE(0x0d5c, 0xa002), USB_DEVICE_DATA(BOARD_503_ACC) }, | 202 | {USB_DEVICE(0x0d5c, 0xa002), USB_DEVICE_DATA(BOARD_503_ACC)}, |
223 | /* | 203 | /* |
224 | * at76c505-rfmd | 204 | * at76c505-rfmd |
225 | */ | 205 | */ |
226 | /* Generic AT76C505/RFMD */ | 206 | /* Generic AT76C505/RFMD */ |
227 | { USB_DEVICE(0x03eb, 0x7606), USB_DEVICE_DATA(BOARD_505) }, | 207 | {USB_DEVICE(0x03eb, 0x7606), USB_DEVICE_DATA(BOARD_505)}, |
228 | /* | 208 | /* |
229 | * at76c505-rfmd2958 | 209 | * at76c505-rfmd2958 |
230 | */ | 210 | */ |
231 | /* Generic AT76C505/RFMD, OvisLink WL-1130USB */ | 211 | /* Generic AT76C505/RFMD, OvisLink WL-1130USB */ |
232 | { USB_DEVICE(0x03eb, 0x7613), USB_DEVICE_DATA(BOARD_505_2958) }, | 212 | {USB_DEVICE(0x03eb, 0x7613), USB_DEVICE_DATA(BOARD_505_2958)}, |
233 | /* Fiberline FL-WL240U */ | 213 | /* Fiberline FL-WL240U */ |
234 | { USB_DEVICE(0x1371, 0x0014), USB_DEVICE_DATA(BOARD_505_2958) }, | 214 | {USB_DEVICE(0x1371, 0x0014), USB_DEVICE_DATA(BOARD_505_2958)}, |
235 | /* CNet CNUSB-611G */ | 215 | /* CNet CNUSB-611G */ |
236 | { USB_DEVICE(0x1371, 0x0013), USB_DEVICE_DATA(BOARD_505_2958) }, | 216 | {USB_DEVICE(0x1371, 0x0013), USB_DEVICE_DATA(BOARD_505_2958)}, |
237 | /* Linksys WUSB11 v2.8 */ | 217 | /* Linksys WUSB11 v2.8 */ |
238 | { USB_DEVICE(0x1915, 0x2233), USB_DEVICE_DATA(BOARD_505_2958) }, | 218 | {USB_DEVICE(0x1915, 0x2233), USB_DEVICE_DATA(BOARD_505_2958)}, |
239 | /* Xterasys XN-2122B, IBlitzz BWU613B/BWU613SB */ | 219 | /* Xterasys XN-2122B, IBlitzz BWU613B/BWU613SB */ |
240 | { USB_DEVICE(0x12fd, 0x1001), USB_DEVICE_DATA(BOARD_505_2958) }, | 220 | {USB_DEVICE(0x12fd, 0x1001), USB_DEVICE_DATA(BOARD_505_2958)}, |
241 | /* Corega WLAN USB Stick 11 */ | 221 | /* Corega WLAN USB Stick 11 */ |
242 | { USB_DEVICE(0x07aa, 0x7613), USB_DEVICE_DATA(BOARD_505_2958) }, | 222 | {USB_DEVICE(0x07aa, 0x7613), USB_DEVICE_DATA(BOARD_505_2958)}, |
243 | /* Microstar MSI Box MS6978 */ | 223 | /* Microstar MSI Box MS6978 */ |
244 | { USB_DEVICE(0x0db0, 0x1020), USB_DEVICE_DATA(BOARD_505_2958) }, | 224 | {USB_DEVICE(0x0db0, 0x1020), USB_DEVICE_DATA(BOARD_505_2958)}, |
245 | /* | 225 | /* |
246 | * at76c505a-rfmd2958 | 226 | * at76c505a-rfmd2958 |
247 | */ | 227 | */ |
248 | /* Generic AT76C505A device */ | 228 | /* Generic AT76C505A device */ |
249 | { USB_DEVICE(0x03eb, 0x7614), USB_DEVICE_DATA(BOARD_505A) }, | 229 | {USB_DEVICE(0x03eb, 0x7614), USB_DEVICE_DATA(BOARD_505A)}, |
250 | /* Generic AT76C505AS device */ | 230 | /* Generic AT76C505AS device */ |
251 | { USB_DEVICE(0x03eb, 0x7617), USB_DEVICE_DATA(BOARD_505A) }, | 231 | {USB_DEVICE(0x03eb, 0x7617), USB_DEVICE_DATA(BOARD_505A)}, |
252 | /* Siemens Gigaset USB WLAN Adapter 11 */ | 232 | /* Siemens Gigaset USB WLAN Adapter 11 */ |
253 | { USB_DEVICE(0x1690, 0x0701), USB_DEVICE_DATA(BOARD_505A) }, | 233 | {USB_DEVICE(0x1690, 0x0701), USB_DEVICE_DATA(BOARD_505A)}, |
254 | /* | 234 | /* |
255 | * at76c505amx-rfmd | 235 | * at76c505amx-rfmd |
256 | */ | 236 | */ |
257 | /* Generic AT76C505AMX device */ | 237 | /* Generic AT76C505AMX device */ |
258 | { USB_DEVICE(0x03eb, 0x7615), USB_DEVICE_DATA(BOARD_505AMX) }, | 238 | {USB_DEVICE(0x03eb, 0x7615), USB_DEVICE_DATA(BOARD_505AMX)}, |
259 | { } | 239 | {} |
260 | }; | 240 | }; |
261 | 241 | ||
262 | MODULE_DEVICE_TABLE(usb, dev_table); | 242 | MODULE_DEVICE_TABLE(usb, dev_table); |
@@ -264,8 +244,26 @@ MODULE_DEVICE_TABLE(usb, dev_table); | |||
264 | /* Supported rates of this hardware, bit 7 marks basic rates */ | 244 | /* Supported rates of this hardware, bit 7 marks basic rates */ |
265 | static const u8 hw_rates[] = { 0x82, 0x84, 0x0b, 0x16 }; | 245 | static const u8 hw_rates[] = { 0x82, 0x84, 0x0b, 0x16 }; |
266 | 246 | ||
247 | /* Frequency of each channel in MHz */ | ||
248 | static const long channel_frequency[] = { | ||
249 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, | ||
250 | 2447, 2452, 2457, 2462, 2467, 2472, 2484 | ||
251 | }; | ||
252 | |||
253 | #define NUM_CHANNELS ARRAY_SIZE(channel_frequency) | ||
254 | |||
267 | static const char *const preambles[] = { "long", "short", "auto" }; | 255 | static const char *const preambles[] = { "long", "short", "auto" }; |
268 | 256 | ||
257 | static const char *const mac_states[] = { | ||
258 | [MAC_INIT] = "INIT", | ||
259 | [MAC_SCANNING] = "SCANNING", | ||
260 | [MAC_AUTH] = "AUTH", | ||
261 | [MAC_ASSOC] = "ASSOC", | ||
262 | [MAC_JOINING] = "JOINING", | ||
263 | [MAC_CONNECTED] = "CONNECTED", | ||
264 | [MAC_OWN_IBSS] = "OWN_IBSS" | ||
265 | }; | ||
266 | |||
269 | /* Firmware download */ | 267 | /* Firmware download */ |
270 | /* DFU states */ | 268 | /* DFU states */ |
271 | #define STATE_IDLE 0x00 | 269 | #define STATE_IDLE 0x00 |
@@ -300,30 +298,17 @@ struct dfu_status { | |||
300 | 298 | ||
301 | static inline int at76_is_intersil(enum board_type board) | 299 | static inline int at76_is_intersil(enum board_type board) |
302 | { | 300 | { |
303 | if (board == BOARD_503_ISL3861 || board == BOARD_503_ISL3863) | 301 | return (board == BOARD_503_ISL3861 || board == BOARD_503_ISL3863); |
304 | return 1; | ||
305 | return 0; | ||
306 | } | 302 | } |
307 | 303 | ||
308 | static inline int at76_is_503rfmd(enum board_type board) | 304 | static inline int at76_is_503rfmd(enum board_type board) |
309 | { | 305 | { |
310 | if (board == BOARD_503 || board == BOARD_503_ACC) | 306 | return (board == BOARD_503 || board == BOARD_503_ACC); |
311 | return 1; | ||
312 | return 0; | ||
313 | } | ||
314 | |||
315 | static inline int at76_is_505(enum board_type board) | ||
316 | { | ||
317 | if (board == BOARD_505 || board == BOARD_505_2958) | ||
318 | return 1; | ||
319 | return 0; | ||
320 | } | 307 | } |
321 | 308 | ||
322 | static inline int at76_is_505a(enum board_type board) | 309 | static inline int at76_is_505a(enum board_type board) |
323 | { | 310 | { |
324 | if (board == BOARD_505A || board == BOARD_505AMX) | 311 | return (board == BOARD_505A || board == BOARD_505AMX); |
325 | return 1; | ||
326 | return 0; | ||
327 | } | 312 | } |
328 | 313 | ||
329 | /* Load a block of the first (internal) part of the firmware */ | 314 | /* Load a block of the first (internal) part of the firmware */ |
@@ -504,6 +489,41 @@ exit: | |||
504 | return ret; | 489 | return ret; |
505 | } | 490 | } |
506 | 491 | ||
492 | /* Report that the scan results are ready */ | ||
493 | static inline void at76_iwevent_scan_complete(struct net_device *netdev) | ||
494 | { | ||
495 | union iwreq_data wrqu; | ||
496 | wrqu.data.length = 0; | ||
497 | wrqu.data.flags = 0; | ||
498 | wireless_send_event(netdev, SIOCGIWSCAN, &wrqu, NULL); | ||
499 | at76_dbg(DBG_WE_EVENTS, "%s: SIOCGIWSCAN sent", netdev->name); | ||
500 | } | ||
501 | |||
502 | static inline void at76_iwevent_bss_connect(struct net_device *netdev, | ||
503 | u8 *bssid) | ||
504 | { | ||
505 | union iwreq_data wrqu; | ||
506 | wrqu.data.length = 0; | ||
507 | wrqu.data.flags = 0; | ||
508 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); | ||
509 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | ||
510 | wireless_send_event(netdev, SIOCGIWAP, &wrqu, NULL); | ||
511 | at76_dbg(DBG_WE_EVENTS, "%s: %s: SIOCGIWAP sent", netdev->name, | ||
512 | __func__); | ||
513 | } | ||
514 | |||
515 | static inline void at76_iwevent_bss_disconnect(struct net_device *netdev) | ||
516 | { | ||
517 | union iwreq_data wrqu; | ||
518 | wrqu.data.length = 0; | ||
519 | wrqu.data.flags = 0; | ||
520 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | ||
521 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | ||
522 | wireless_send_event(netdev, SIOCGIWAP, &wrqu, NULL); | ||
523 | at76_dbg(DBG_WE_EVENTS, "%s: %s: SIOCGIWAP sent", netdev->name, | ||
524 | __func__); | ||
525 | } | ||
526 | |||
507 | #define HEX2STR_BUFFERS 4 | 527 | #define HEX2STR_BUFFERS 4 |
508 | #define HEX2STR_MAX_LEN 64 | 528 | #define HEX2STR_MAX_LEN 64 |
509 | #define BIN2HEX(x) ((x) < 10 ? '0' + (x) : (x) + 'A' - 10) | 529 | #define BIN2HEX(x) ((x) < 10 ? '0' + (x) : (x) + 'A' - 10) |
@@ -575,6 +595,37 @@ static void at76_ledtrig_tx_activity(void) | |||
575 | mod_timer(&ledtrig_tx_timer, jiffies + HZ / 4); | 595 | mod_timer(&ledtrig_tx_timer, jiffies + HZ / 4); |
576 | } | 596 | } |
577 | 597 | ||
598 | /* Check if the given ssid is hidden */ | ||
599 | static inline int at76_is_hidden_ssid(u8 *ssid, int length) | ||
600 | { | ||
601 | static const u8 zeros[32]; | ||
602 | |||
603 | if (length == 0) | ||
604 | return 1; | ||
605 | |||
606 | if (length == 1 && ssid[0] == ' ') | ||
607 | return 1; | ||
608 | |||
609 | return (memcmp(ssid, zeros, length) == 0); | ||
610 | } | ||
611 | |||
612 | static inline void at76_free_bss_list(struct at76_priv *priv) | ||
613 | { | ||
614 | struct list_head *next, *ptr; | ||
615 | unsigned long flags; | ||
616 | |||
617 | spin_lock_irqsave(&priv->bss_list_spinlock, flags); | ||
618 | |||
619 | priv->curr_bss = NULL; | ||
620 | |||
621 | list_for_each_safe(ptr, next, &priv->bss_list) { | ||
622 | list_del(ptr); | ||
623 | kfree(list_entry(ptr, struct bss_info, list)); | ||
624 | } | ||
625 | |||
626 | spin_unlock_irqrestore(&priv->bss_list_spinlock, flags); | ||
627 | } | ||
628 | |||
578 | static int at76_remap(struct usb_device *udev) | 629 | static int at76_remap(struct usb_device *udev) |
579 | { | 630 | { |
580 | int ret; | 631 | int ret; |
@@ -676,7 +727,7 @@ exit: | |||
676 | kfree(hwcfg); | 727 | kfree(hwcfg); |
677 | if (ret < 0) | 728 | if (ret < 0) |
678 | printk(KERN_ERR "%s: cannot get HW Config (error %d)\n", | 729 | printk(KERN_ERR "%s: cannot get HW Config (error %d)\n", |
679 | wiphy_name(priv->hw->wiphy), ret); | 730 | priv->netdev->name, ret); |
680 | 731 | ||
681 | return ret; | 732 | return ret; |
682 | } | 733 | } |
@@ -685,15 +736,15 @@ static struct reg_domain const *at76_get_reg_domain(u16 code) | |||
685 | { | 736 | { |
686 | int i; | 737 | int i; |
687 | static struct reg_domain const fd_tab[] = { | 738 | static struct reg_domain const fd_tab[] = { |
688 | { 0x10, "FCC (USA)", 0x7ff }, /* ch 1-11 */ | 739 | {0x10, "FCC (USA)", 0x7ff}, /* ch 1-11 */ |
689 | { 0x20, "IC (Canada)", 0x7ff }, /* ch 1-11 */ | 740 | {0x20, "IC (Canada)", 0x7ff}, /* ch 1-11 */ |
690 | { 0x30, "ETSI (most of Europe)", 0x1fff }, /* ch 1-13 */ | 741 | {0x30, "ETSI (most of Europe)", 0x1fff}, /* ch 1-13 */ |
691 | { 0x31, "Spain", 0x600 }, /* ch 10-11 */ | 742 | {0x31, "Spain", 0x600}, /* ch 10-11 */ |
692 | { 0x32, "France", 0x1e00 }, /* ch 10-13 */ | 743 | {0x32, "France", 0x1e00}, /* ch 10-13 */ |
693 | { 0x40, "MKK (Japan)", 0x2000 }, /* ch 14 */ | 744 | {0x40, "MKK (Japan)", 0x2000}, /* ch 14 */ |
694 | { 0x41, "MKK1 (Japan)", 0x3fff }, /* ch 1-14 */ | 745 | {0x41, "MKK1 (Japan)", 0x3fff}, /* ch 1-14 */ |
695 | { 0x50, "Israel", 0x3fc }, /* ch 3-9 */ | 746 | {0x50, "Israel", 0x3fc}, /* ch 3-9 */ |
696 | { 0x00, "<unknown>", 0xffffffff } /* ch 1-32 */ | 747 | {0x00, "<unknown>", 0xffffffff} /* ch 1-32 */ |
697 | }; | 748 | }; |
698 | 749 | ||
699 | /* Last entry is fallback for unknown domain code */ | 750 | /* Last entry is fallback for unknown domain code */ |
@@ -739,24 +790,6 @@ static inline int at76_get_cmd_status(struct usb_device *udev, u8 cmd) | |||
739 | return ret; | 790 | return ret; |
740 | } | 791 | } |
741 | 792 | ||
742 | #define MAKE_CMD_CASE(c) case (c): return #c | ||
743 | |||
744 | static const char *at76_get_cmd_string(u8 cmd_status) | ||
745 | { | ||
746 | switch (cmd_status) { | ||
747 | MAKE_CMD_CASE(CMD_SET_MIB); | ||
748 | MAKE_CMD_CASE(CMD_GET_MIB); | ||
749 | MAKE_CMD_CASE(CMD_SCAN); | ||
750 | MAKE_CMD_CASE(CMD_JOIN); | ||
751 | MAKE_CMD_CASE(CMD_START_IBSS); | ||
752 | MAKE_CMD_CASE(CMD_RADIO_ON); | ||
753 | MAKE_CMD_CASE(CMD_RADIO_OFF); | ||
754 | MAKE_CMD_CASE(CMD_STARTUP); | ||
755 | } | ||
756 | |||
757 | return "UNKNOWN"; | ||
758 | } | ||
759 | |||
760 | static int at76_set_card_command(struct usb_device *udev, u8 cmd, void *buf, | 793 | static int at76_set_card_command(struct usb_device *udev, u8 cmd, void *buf, |
761 | int buf_size) | 794 | int buf_size) |
762 | { | 795 | { |
@@ -772,10 +805,6 @@ static int at76_set_card_command(struct usb_device *udev, u8 cmd, void *buf, | |||
772 | cmd_buf->size = cpu_to_le16(buf_size); | 805 | cmd_buf->size = cpu_to_le16(buf_size); |
773 | memcpy(cmd_buf->data, buf, buf_size); | 806 | memcpy(cmd_buf->data, buf, buf_size); |
774 | 807 | ||
775 | at76_dbg_dump(DBG_CMD, cmd_buf, sizeof(struct at76_command) + buf_size, | ||
776 | "issuing command %s (0x%02x)", | ||
777 | at76_get_cmd_string(cmd), cmd); | ||
778 | |||
779 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x0e, | 808 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x0e, |
780 | USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE, | 809 | USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE, |
781 | 0, 0, cmd_buf, | 810 | 0, 0, cmd_buf, |
@@ -813,13 +842,13 @@ static int at76_wait_completion(struct at76_priv *priv, int cmd) | |||
813 | status = at76_get_cmd_status(priv->udev, cmd); | 842 | status = at76_get_cmd_status(priv->udev, cmd); |
814 | if (status < 0) { | 843 | if (status < 0) { |
815 | printk(KERN_ERR "%s: at76_get_cmd_status failed: %d\n", | 844 | printk(KERN_ERR "%s: at76_get_cmd_status failed: %d\n", |
816 | wiphy_name(priv->hw->wiphy), status); | 845 | priv->netdev->name, status); |
817 | break; | 846 | break; |
818 | } | 847 | } |
819 | 848 | ||
820 | at76_dbg(DBG_WAIT_COMPLETE, | 849 | at76_dbg(DBG_WAIT_COMPLETE, |
821 | "%s: Waiting on cmd %d, status = %d (%s)", | 850 | "%s: Waiting on cmd %d, status = %d (%s)", |
822 | wiphy_name(priv->hw->wiphy), cmd, status, | 851 | priv->netdev->name, cmd, status, |
823 | at76_get_cmd_status_string(status)); | 852 | at76_get_cmd_status_string(status)); |
824 | 853 | ||
825 | if (status != CMD_STATUS_IN_PROGRESS | 854 | if (status != CMD_STATUS_IN_PROGRESS |
@@ -830,7 +859,7 @@ static int at76_wait_completion(struct at76_priv *priv, int cmd) | |||
830 | if (time_after(jiffies, timeout)) { | 859 | if (time_after(jiffies, timeout)) { |
831 | printk(KERN_ERR | 860 | printk(KERN_ERR |
832 | "%s: completion timeout for command %d\n", | 861 | "%s: completion timeout for command %d\n", |
833 | wiphy_name(priv->hw->wiphy), cmd); | 862 | priv->netdev->name, cmd); |
834 | status = -ETIMEDOUT; | 863 | status = -ETIMEDOUT; |
835 | break; | 864 | break; |
836 | } | 865 | } |
@@ -853,7 +882,7 @@ static int at76_set_mib(struct at76_priv *priv, struct set_mib_buffer *buf) | |||
853 | if (ret != CMD_STATUS_COMPLETE) { | 882 | if (ret != CMD_STATUS_COMPLETE) { |
854 | printk(KERN_INFO | 883 | printk(KERN_INFO |
855 | "%s: set_mib: at76_wait_completion failed " | 884 | "%s: set_mib: at76_wait_completion failed " |
856 | "with %d\n", wiphy_name(priv->hw->wiphy), ret); | 885 | "with %d\n", priv->netdev->name, ret); |
857 | ret = -EIO; | 886 | ret = -EIO; |
858 | } | 887 | } |
859 | 888 | ||
@@ -874,7 +903,7 @@ static int at76_set_radio(struct at76_priv *priv, int enable) | |||
874 | ret = at76_set_card_command(priv->udev, cmd, NULL, 0); | 903 | ret = at76_set_card_command(priv->udev, cmd, NULL, 0); |
875 | if (ret < 0) | 904 | if (ret < 0) |
876 | printk(KERN_ERR "%s: at76_set_card_command(%d) failed: %d\n", | 905 | printk(KERN_ERR "%s: at76_set_card_command(%d) failed: %d\n", |
877 | wiphy_name(priv->hw->wiphy), cmd, ret); | 906 | priv->netdev->name, cmd, ret); |
878 | else | 907 | else |
879 | ret = 1; | 908 | ret = 1; |
880 | 909 | ||
@@ -895,7 +924,44 @@ static int at76_set_pm_mode(struct at76_priv *priv) | |||
895 | ret = at76_set_mib(priv, &priv->mib_buf); | 924 | ret = at76_set_mib(priv, &priv->mib_buf); |
896 | if (ret < 0) | 925 | if (ret < 0) |
897 | printk(KERN_ERR "%s: set_mib (pm_mode) failed: %d\n", | 926 | printk(KERN_ERR "%s: set_mib (pm_mode) failed: %d\n", |
898 | wiphy_name(priv->hw->wiphy), ret); | 927 | priv->netdev->name, ret); |
928 | |||
929 | return ret; | ||
930 | } | ||
931 | |||
932 | /* Set the association id for power save mode */ | ||
933 | static int at76_set_associd(struct at76_priv *priv, u16 id) | ||
934 | { | ||
935 | int ret = 0; | ||
936 | |||
937 | priv->mib_buf.type = MIB_MAC_MGMT; | ||
938 | priv->mib_buf.size = 2; | ||
939 | priv->mib_buf.index = offsetof(struct mib_mac_mgmt, station_id); | ||
940 | priv->mib_buf.data.word = cpu_to_le16(id); | ||
941 | |||
942 | ret = at76_set_mib(priv, &priv->mib_buf); | ||
943 | if (ret < 0) | ||
944 | printk(KERN_ERR "%s: set_mib (associd) failed: %d\n", | ||
945 | priv->netdev->name, ret); | ||
946 | |||
947 | return ret; | ||
948 | } | ||
949 | |||
950 | /* Set the listen interval for power save mode */ | ||
951 | static int at76_set_listen_interval(struct at76_priv *priv, u16 interval) | ||
952 | { | ||
953 | int ret = 0; | ||
954 | |||
955 | priv->mib_buf.type = MIB_MAC; | ||
956 | priv->mib_buf.size = 2; | ||
957 | priv->mib_buf.index = offsetof(struct mib_mac, listen_interval); | ||
958 | priv->mib_buf.data.word = cpu_to_le16(interval); | ||
959 | |||
960 | ret = at76_set_mib(priv, &priv->mib_buf); | ||
961 | if (ret < 0) | ||
962 | printk(KERN_ERR | ||
963 | "%s: set_mib (listen_interval) failed: %d\n", | ||
964 | priv->netdev->name, ret); | ||
899 | 965 | ||
900 | return ret; | 966 | return ret; |
901 | } | 967 | } |
@@ -912,7 +978,7 @@ static int at76_set_preamble(struct at76_priv *priv, u8 type) | |||
912 | ret = at76_set_mib(priv, &priv->mib_buf); | 978 | ret = at76_set_mib(priv, &priv->mib_buf); |
913 | if (ret < 0) | 979 | if (ret < 0) |
914 | printk(KERN_ERR "%s: set_mib (preamble) failed: %d\n", | 980 | printk(KERN_ERR "%s: set_mib (preamble) failed: %d\n", |
915 | wiphy_name(priv->hw->wiphy), ret); | 981 | priv->netdev->name, ret); |
916 | 982 | ||
917 | return ret; | 983 | return ret; |
918 | } | 984 | } |
@@ -929,7 +995,7 @@ static int at76_set_frag(struct at76_priv *priv, u16 size) | |||
929 | ret = at76_set_mib(priv, &priv->mib_buf); | 995 | ret = at76_set_mib(priv, &priv->mib_buf); |
930 | if (ret < 0) | 996 | if (ret < 0) |
931 | printk(KERN_ERR "%s: set_mib (frag threshold) failed: %d\n", | 997 | printk(KERN_ERR "%s: set_mib (frag threshold) failed: %d\n", |
932 | wiphy_name(priv->hw->wiphy), ret); | 998 | priv->netdev->name, ret); |
933 | 999 | ||
934 | return ret; | 1000 | return ret; |
935 | } | 1001 | } |
@@ -946,7 +1012,7 @@ static int at76_set_rts(struct at76_priv *priv, u16 size) | |||
946 | ret = at76_set_mib(priv, &priv->mib_buf); | 1012 | ret = at76_set_mib(priv, &priv->mib_buf); |
947 | if (ret < 0) | 1013 | if (ret < 0) |
948 | printk(KERN_ERR "%s: set_mib (rts) failed: %d\n", | 1014 | printk(KERN_ERR "%s: set_mib (rts) failed: %d\n", |
949 | wiphy_name(priv->hw->wiphy), ret); | 1015 | priv->netdev->name, ret); |
950 | 1016 | ||
951 | return ret; | 1017 | return ret; |
952 | } | 1018 | } |
@@ -963,41 +1029,24 @@ static int at76_set_autorate_fallback(struct at76_priv *priv, int onoff) | |||
963 | ret = at76_set_mib(priv, &priv->mib_buf); | 1029 | ret = at76_set_mib(priv, &priv->mib_buf); |
964 | if (ret < 0) | 1030 | if (ret < 0) |
965 | printk(KERN_ERR "%s: set_mib (autorate fallback) failed: %d\n", | 1031 | printk(KERN_ERR "%s: set_mib (autorate fallback) failed: %d\n", |
966 | wiphy_name(priv->hw->wiphy), ret); | 1032 | priv->netdev->name, ret); |
967 | 1033 | ||
968 | return ret; | 1034 | return ret; |
969 | } | 1035 | } |
970 | 1036 | ||
971 | static int at76_set_tkip_bssid(struct at76_priv *priv, const void *addr) | 1037 | static int at76_add_mac_address(struct at76_priv *priv, void *addr) |
972 | { | 1038 | { |
973 | int ret = 0; | 1039 | int ret = 0; |
974 | 1040 | ||
975 | priv->mib_buf.type = MIB_MAC_ENCRYPTION; | 1041 | priv->mib_buf.type = MIB_MAC_ADDR; |
976 | priv->mib_buf.size = ETH_ALEN; | 1042 | priv->mib_buf.size = ETH_ALEN; |
977 | priv->mib_buf.index = offsetof(struct mib_mac_encryption, tkip_bssid); | 1043 | priv->mib_buf.index = offsetof(struct mib_mac_addr, mac_addr); |
978 | memcpy(priv->mib_buf.data.addr, addr, ETH_ALEN); | 1044 | memcpy(priv->mib_buf.data.addr, addr, ETH_ALEN); |
979 | 1045 | ||
980 | ret = at76_set_mib(priv, &priv->mib_buf); | 1046 | ret = at76_set_mib(priv, &priv->mib_buf); |
981 | if (ret < 0) | 1047 | if (ret < 0) |
982 | printk(KERN_ERR "%s: set_mib (MAC_ENCRYPTION, tkip_bssid) failed: %d\n", | 1048 | printk(KERN_ERR "%s: set_mib (MAC_ADDR, mac_addr) failed: %d\n", |
983 | wiphy_name(priv->hw->wiphy), ret); | 1049 | priv->netdev->name, ret); |
984 | |||
985 | return ret; | ||
986 | } | ||
987 | |||
988 | static int at76_reset_rsc(struct at76_priv *priv) | ||
989 | { | ||
990 | int ret = 0; | ||
991 | |||
992 | priv->mib_buf.type = MIB_MAC_ENCRYPTION; | ||
993 | priv->mib_buf.size = 4 * 8; | ||
994 | priv->mib_buf.index = offsetof(struct mib_mac_encryption, key_rsc); | ||
995 | memset(priv->mib_buf.data.data, 0 , priv->mib_buf.size); | ||
996 | |||
997 | ret = at76_set_mib(priv, &priv->mib_buf); | ||
998 | if (ret < 0) | ||
999 | printk(KERN_ERR "%s: set_mib (MAC_ENCRYPTION, key_rsc) failed: %d\n", | ||
1000 | wiphy_name(priv->hw->wiphy), ret); | ||
1001 | 1050 | ||
1002 | return ret; | 1051 | return ret; |
1003 | } | 1052 | } |
@@ -1016,16 +1065,16 @@ static void at76_dump_mib_mac_addr(struct at76_priv *priv) | |||
1016 | sizeof(struct mib_mac_addr)); | 1065 | sizeof(struct mib_mac_addr)); |
1017 | if (ret < 0) { | 1066 | if (ret < 0) { |
1018 | printk(KERN_ERR "%s: at76_get_mib (MAC_ADDR) failed: %d\n", | 1067 | printk(KERN_ERR "%s: at76_get_mib (MAC_ADDR) failed: %d\n", |
1019 | wiphy_name(priv->hw->wiphy), ret); | 1068 | priv->netdev->name, ret); |
1020 | goto exit; | 1069 | goto exit; |
1021 | } | 1070 | } |
1022 | 1071 | ||
1023 | at76_dbg(DBG_MIB, "%s: MIB MAC_ADDR: mac_addr %s res 0x%x 0x%x", | 1072 | at76_dbg(DBG_MIB, "%s: MIB MAC_ADDR: mac_addr %s res 0x%x 0x%x", |
1024 | wiphy_name(priv->hw->wiphy), | 1073 | priv->netdev->name, |
1025 | mac2str(m->mac_addr), m->res[0], m->res[1]); | 1074 | mac2str(m->mac_addr), m->res[0], m->res[1]); |
1026 | for (i = 0; i < ARRAY_SIZE(m->group_addr); i++) | 1075 | for (i = 0; i < ARRAY_SIZE(m->group_addr); i++) |
1027 | at76_dbg(DBG_MIB, "%s: MIB MAC_ADDR: group addr %d: %s, " | 1076 | at76_dbg(DBG_MIB, "%s: MIB MAC_ADDR: group addr %d: %s, " |
1028 | "status %d", wiphy_name(priv->hw->wiphy), i, | 1077 | "status %d", priv->netdev->name, i, |
1029 | mac2str(m->group_addr[i]), m->group_addr_status[i]); | 1078 | mac2str(m->group_addr[i]), m->group_addr_status[i]); |
1030 | exit: | 1079 | exit: |
1031 | kfree(m); | 1080 | kfree(m); |
@@ -1045,13 +1094,13 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv) | |||
1045 | sizeof(struct mib_mac_wep)); | 1094 | sizeof(struct mib_mac_wep)); |
1046 | if (ret < 0) { | 1095 | if (ret < 0) { |
1047 | printk(KERN_ERR "%s: at76_get_mib (MAC_WEP) failed: %d\n", | 1096 | printk(KERN_ERR "%s: at76_get_mib (MAC_WEP) failed: %d\n", |
1048 | wiphy_name(priv->hw->wiphy), ret); | 1097 | priv->netdev->name, ret); |
1049 | goto exit; | 1098 | goto exit; |
1050 | } | 1099 | } |
1051 | 1100 | ||
1052 | at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: priv_invoked %u def_key_id %u " | 1101 | at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: priv_invoked %u def_key_id %u " |
1053 | "key_len %u excl_unencr %u wep_icv_err %u wep_excluded %u " | 1102 | "key_len %u excl_unencr %u wep_icv_err %u wep_excluded %u " |
1054 | "encr_level %u key %d", wiphy_name(priv->hw->wiphy), | 1103 | "encr_level %u key %d", priv->netdev->name, |
1055 | m->privacy_invoked, m->wep_default_key_id, | 1104 | m->privacy_invoked, m->wep_default_key_id, |
1056 | m->wep_key_mapping_len, m->exclude_unencrypted, | 1105 | m->wep_key_mapping_len, m->exclude_unencrypted, |
1057 | le32_to_cpu(m->wep_icv_error_count), | 1106 | le32_to_cpu(m->wep_icv_error_count), |
@@ -1063,55 +1112,12 @@ static void at76_dump_mib_mac_wep(struct at76_priv *priv) | |||
1063 | 1112 | ||
1064 | for (i = 0; i < WEP_KEYS; i++) | 1113 | for (i = 0; i < WEP_KEYS; i++) |
1065 | at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s", | 1114 | at76_dbg(DBG_MIB, "%s: MIB MAC_WEP: key %d: %s", |
1066 | wiphy_name(priv->hw->wiphy), i, | 1115 | priv->netdev->name, i, |
1067 | hex2str(m->wep_default_keyvalue[i], key_len)); | 1116 | hex2str(m->wep_default_keyvalue[i], key_len)); |
1068 | exit: | 1117 | exit: |
1069 | kfree(m); | 1118 | kfree(m); |
1070 | } | 1119 | } |
1071 | 1120 | ||
1072 | static void at76_dump_mib_mac_encryption(struct at76_priv *priv) | ||
1073 | { | ||
1074 | int i; | ||
1075 | int ret; | ||
1076 | /*int key_len;*/ | ||
1077 | struct mib_mac_encryption *m; | ||
1078 | |||
1079 | m = kmalloc(sizeof(struct mib_mac_encryption), GFP_KERNEL); | ||
1080 | if (!m) | ||
1081 | return; | ||
1082 | |||
1083 | ret = at76_get_mib(priv->udev, MIB_MAC_ENCRYPTION, m, | ||
1084 | sizeof(struct mib_mac_encryption)); | ||
1085 | if (ret < 0) { | ||
1086 | dev_err(&priv->udev->dev, | ||
1087 | "%s: at76_get_mib (MAC_ENCRYPTION) failed: %d\n", | ||
1088 | wiphy_name(priv->hw->wiphy), ret); | ||
1089 | goto exit; | ||
1090 | } | ||
1091 | |||
1092 | at76_dbg(DBG_MIB, | ||
1093 | "%s: MIB MAC_ENCRYPTION: tkip_bssid %s priv_invoked %u " | ||
1094 | "ciph_key_id %u grp_key_id %u excl_unencr %u " | ||
1095 | "ckip_key_perm %u wep_icv_err %u wep_excluded %u", | ||
1096 | wiphy_name(priv->hw->wiphy), mac2str(m->tkip_bssid), | ||
1097 | m->privacy_invoked, m->cipher_default_key_id, | ||
1098 | m->cipher_default_group_key_id, m->exclude_unencrypted, | ||
1099 | m->ckip_key_permutation, | ||
1100 | le32_to_cpu(m->wep_icv_error_count), | ||
1101 | le32_to_cpu(m->wep_excluded_count)); | ||
1102 | |||
1103 | /*key_len = (m->encryption_level == 1) ? | ||
1104 | WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;*/ | ||
1105 | |||
1106 | for (i = 0; i < CIPHER_KEYS; i++) | ||
1107 | at76_dbg(DBG_MIB, "%s: MIB MAC_ENCRYPTION: key %d: %s", | ||
1108 | wiphy_name(priv->hw->wiphy), i, | ||
1109 | hex2str(m->cipher_default_keyvalue[i], | ||
1110 | CIPHER_KEY_LEN)); | ||
1111 | exit: | ||
1112 | kfree(m); | ||
1113 | } | ||
1114 | |||
1115 | static void at76_dump_mib_mac_mgmt(struct at76_priv *priv) | 1121 | static void at76_dump_mib_mac_mgmt(struct at76_priv *priv) |
1116 | { | 1122 | { |
1117 | int ret; | 1123 | int ret; |
@@ -1125,7 +1131,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv) | |||
1125 | sizeof(struct mib_mac_mgmt)); | 1131 | sizeof(struct mib_mac_mgmt)); |
1126 | if (ret < 0) { | 1132 | if (ret < 0) { |
1127 | printk(KERN_ERR "%s: at76_get_mib (MAC_MGMT) failed: %d\n", | 1133 | printk(KERN_ERR "%s: at76_get_mib (MAC_MGMT) failed: %d\n", |
1128 | wiphy_name(priv->hw->wiphy), ret); | 1134 | priv->netdev->name, ret); |
1129 | goto exit; | 1135 | goto exit; |
1130 | } | 1136 | } |
1131 | 1137 | ||
@@ -1136,7 +1142,7 @@ static void at76_dump_mib_mac_mgmt(struct at76_priv *priv) | |||
1136 | "pm_mode %d ibss_change %d res %d " | 1142 | "pm_mode %d ibss_change %d res %d " |
1137 | "multi_domain_capability_implemented %d " | 1143 | "multi_domain_capability_implemented %d " |
1138 | "international_roaming %d country_string %.3s", | 1144 | "international_roaming %d country_string %.3s", |
1139 | wiphy_name(priv->hw->wiphy), le16_to_cpu(m->beacon_period), | 1145 | priv->netdev->name, le16_to_cpu(m->beacon_period), |
1140 | le16_to_cpu(m->CFP_max_duration), | 1146 | le16_to_cpu(m->CFP_max_duration), |
1141 | le16_to_cpu(m->medium_occupancy_limit), | 1147 | le16_to_cpu(m->medium_occupancy_limit), |
1142 | le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window), | 1148 | le16_to_cpu(m->station_id), le16_to_cpu(m->ATIM_window), |
@@ -1161,7 +1167,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv) | |||
1161 | ret = at76_get_mib(priv->udev, MIB_MAC, m, sizeof(struct mib_mac)); | 1167 | ret = at76_get_mib(priv->udev, MIB_MAC, m, sizeof(struct mib_mac)); |
1162 | if (ret < 0) { | 1168 | if (ret < 0) { |
1163 | printk(KERN_ERR "%s: at76_get_mib (MAC) failed: %d\n", | 1169 | printk(KERN_ERR "%s: at76_get_mib (MAC) failed: %d\n", |
1164 | wiphy_name(priv->hw->wiphy), ret); | 1170 | priv->netdev->name, ret); |
1165 | goto exit; | 1171 | goto exit; |
1166 | } | 1172 | } |
1167 | 1173 | ||
@@ -1171,8 +1177,7 @@ static void at76_dump_mib_mac(struct at76_priv *priv) | |||
1171 | "scan_type %d scan_channel %d probe_delay %u " | 1177 | "scan_type %d scan_channel %d probe_delay %u " |
1172 | "min_channel_time %d max_channel_time %d listen_int %d " | 1178 | "min_channel_time %d max_channel_time %d listen_int %d " |
1173 | "desired_ssid %s desired_bssid %s desired_bsstype %d", | 1179 | "desired_ssid %s desired_bssid %s desired_bsstype %d", |
1174 | wiphy_name(priv->hw->wiphy), | 1180 | priv->netdev->name, le32_to_cpu(m->max_tx_msdu_lifetime), |
1175 | le32_to_cpu(m->max_tx_msdu_lifetime), | ||
1176 | le32_to_cpu(m->max_rx_lifetime), | 1181 | le32_to_cpu(m->max_rx_lifetime), |
1177 | le16_to_cpu(m->frag_threshold), le16_to_cpu(m->rts_threshold), | 1182 | le16_to_cpu(m->frag_threshold), le16_to_cpu(m->rts_threshold), |
1178 | le16_to_cpu(m->cwmin), le16_to_cpu(m->cwmax), | 1183 | le16_to_cpu(m->cwmin), le16_to_cpu(m->cwmax), |
@@ -1198,7 +1203,7 @@ static void at76_dump_mib_phy(struct at76_priv *priv) | |||
1198 | ret = at76_get_mib(priv->udev, MIB_PHY, m, sizeof(struct mib_phy)); | 1203 | ret = at76_get_mib(priv->udev, MIB_PHY, m, sizeof(struct mib_phy)); |
1199 | if (ret < 0) { | 1204 | if (ret < 0) { |
1200 | printk(KERN_ERR "%s: at76_get_mib (PHY) failed: %d\n", | 1205 | printk(KERN_ERR "%s: at76_get_mib (PHY) failed: %d\n", |
1201 | wiphy_name(priv->hw->wiphy), ret); | 1206 | priv->netdev->name, ret); |
1202 | goto exit; | 1207 | goto exit; |
1203 | } | 1208 | } |
1204 | 1209 | ||
@@ -1207,7 +1212,7 @@ static void at76_dump_mib_phy(struct at76_priv *priv) | |||
1207 | "mpdu_max_length %d cca_mode_supported %d operation_rate_set " | 1212 | "mpdu_max_length %d cca_mode_supported %d operation_rate_set " |
1208 | "0x%x 0x%x 0x%x 0x%x channel_id %d current_cca_mode %d " | 1213 | "0x%x 0x%x 0x%x 0x%x channel_id %d current_cca_mode %d " |
1209 | "phy_type %d current_reg_domain %d", | 1214 | "phy_type %d current_reg_domain %d", |
1210 | wiphy_name(priv->hw->wiphy), le32_to_cpu(m->ed_threshold), | 1215 | priv->netdev->name, le32_to_cpu(m->ed_threshold), |
1211 | le16_to_cpu(m->slot_time), le16_to_cpu(m->sifs_time), | 1216 | le16_to_cpu(m->slot_time), le16_to_cpu(m->sifs_time), |
1212 | le16_to_cpu(m->preamble_length), | 1217 | le16_to_cpu(m->preamble_length), |
1213 | le16_to_cpu(m->plcp_header_length), | 1218 | le16_to_cpu(m->plcp_header_length), |
@@ -1231,14 +1236,13 @@ static void at76_dump_mib_local(struct at76_priv *priv) | |||
1231 | ret = at76_get_mib(priv->udev, MIB_LOCAL, m, sizeof(struct mib_local)); | 1236 | ret = at76_get_mib(priv->udev, MIB_LOCAL, m, sizeof(struct mib_local)); |
1232 | if (ret < 0) { | 1237 | if (ret < 0) { |
1233 | printk(KERN_ERR "%s: at76_get_mib (LOCAL) failed: %d\n", | 1238 | printk(KERN_ERR "%s: at76_get_mib (LOCAL) failed: %d\n", |
1234 | wiphy_name(priv->hw->wiphy), ret); | 1239 | priv->netdev->name, ret); |
1235 | goto exit; | 1240 | goto exit; |
1236 | } | 1241 | } |
1237 | 1242 | ||
1238 | at76_dbg(DBG_MIB, "%s: MIB LOCAL: beacon_enable %d " | 1243 | at76_dbg(DBG_MIB, "%s: MIB LOCAL: beacon_enable %d " |
1239 | "txautorate_fallback %d ssid_size %d promiscuous_mode %d " | 1244 | "txautorate_fallback %d ssid_size %d promiscuous_mode %d " |
1240 | "preamble_type %d", wiphy_name(priv->hw->wiphy), | 1245 | "preamble_type %d", priv->netdev->name, m->beacon_enable, |
1241 | m->beacon_enable, | ||
1242 | m->txautorate_fallback, m->ssid_size, m->promiscuous_mode, | 1246 | m->txautorate_fallback, m->ssid_size, m->promiscuous_mode, |
1243 | m->preamble_type); | 1247 | m->preamble_type); |
1244 | exit: | 1248 | exit: |
@@ -1257,21 +1261,118 @@ static void at76_dump_mib_mdomain(struct at76_priv *priv) | |||
1257 | sizeof(struct mib_mdomain)); | 1261 | sizeof(struct mib_mdomain)); |
1258 | if (ret < 0) { | 1262 | if (ret < 0) { |
1259 | printk(KERN_ERR "%s: at76_get_mib (MDOMAIN) failed: %d\n", | 1263 | printk(KERN_ERR "%s: at76_get_mib (MDOMAIN) failed: %d\n", |
1260 | wiphy_name(priv->hw->wiphy), ret); | 1264 | priv->netdev->name, ret); |
1261 | goto exit; | 1265 | goto exit; |
1262 | } | 1266 | } |
1263 | 1267 | ||
1264 | at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s", | 1268 | at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s", |
1265 | wiphy_name(priv->hw->wiphy), | 1269 | priv->netdev->name, |
1266 | hex2str(m->channel_list, sizeof(m->channel_list))); | 1270 | hex2str(m->channel_list, sizeof(m->channel_list))); |
1267 | 1271 | ||
1268 | at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s", | 1272 | at76_dbg(DBG_MIB, "%s: MIB MDOMAIN: tx_powerlevel %s", |
1269 | wiphy_name(priv->hw->wiphy), | 1273 | priv->netdev->name, |
1270 | hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel))); | 1274 | hex2str(m->tx_powerlevel, sizeof(m->tx_powerlevel))); |
1271 | exit: | 1275 | exit: |
1272 | kfree(m); | 1276 | kfree(m); |
1273 | } | 1277 | } |
1274 | 1278 | ||
1279 | static int at76_get_current_bssid(struct at76_priv *priv) | ||
1280 | { | ||
1281 | int ret = 0; | ||
1282 | struct mib_mac_mgmt *mac_mgmt = | ||
1283 | kmalloc(sizeof(struct mib_mac_mgmt), GFP_KERNEL); | ||
1284 | |||
1285 | if (!mac_mgmt) { | ||
1286 | ret = -ENOMEM; | ||
1287 | goto exit; | ||
1288 | } | ||
1289 | |||
1290 | ret = at76_get_mib(priv->udev, MIB_MAC_MGMT, mac_mgmt, | ||
1291 | sizeof(struct mib_mac_mgmt)); | ||
1292 | if (ret < 0) { | ||
1293 | printk(KERN_ERR "%s: at76_get_mib failed: %d\n", | ||
1294 | priv->netdev->name, ret); | ||
1295 | goto error; | ||
1296 | } | ||
1297 | memcpy(priv->bssid, mac_mgmt->current_bssid, ETH_ALEN); | ||
1298 | printk(KERN_INFO "%s: using BSSID %s\n", priv->netdev->name, | ||
1299 | mac2str(priv->bssid)); | ||
1300 | error: | ||
1301 | kfree(mac_mgmt); | ||
1302 | exit: | ||
1303 | return ret; | ||
1304 | } | ||
1305 | |||
1306 | static int at76_get_current_channel(struct at76_priv *priv) | ||
1307 | { | ||
1308 | int ret = 0; | ||
1309 | struct mib_phy *phy = kmalloc(sizeof(struct mib_phy), GFP_KERNEL); | ||
1310 | |||
1311 | if (!phy) { | ||
1312 | ret = -ENOMEM; | ||
1313 | goto exit; | ||
1314 | } | ||
1315 | ret = at76_get_mib(priv->udev, MIB_PHY, phy, sizeof(struct mib_phy)); | ||
1316 | if (ret < 0) { | ||
1317 | printk(KERN_ERR "%s: at76_get_mib(MIB_PHY) failed: %d\n", | ||
1318 | priv->netdev->name, ret); | ||
1319 | goto error; | ||
1320 | } | ||
1321 | priv->channel = phy->channel_id; | ||
1322 | error: | ||
1323 | kfree(phy); | ||
1324 | exit: | ||
1325 | return ret; | ||
1326 | } | ||
1327 | |||
1328 | /** | ||
1329 | * at76_start_scan - start a scan | ||
1330 | * | ||
1331 | * @use_essid - use the configured ESSID in non passive mode | ||
1332 | */ | ||
1333 | static int at76_start_scan(struct at76_priv *priv, int use_essid) | ||
1334 | { | ||
1335 | struct at76_req_scan scan; | ||
1336 | |||
1337 | memset(&scan, 0, sizeof(struct at76_req_scan)); | ||
1338 | memset(scan.bssid, 0xff, ETH_ALEN); | ||
1339 | |||
1340 | if (use_essid) { | ||
1341 | memcpy(scan.essid, priv->essid, IW_ESSID_MAX_SIZE); | ||
1342 | scan.essid_size = priv->essid_size; | ||
1343 | } else | ||
1344 | scan.essid_size = 0; | ||
1345 | |||
1346 | /* jal: why should we start at a certain channel? we do scan the whole | ||
1347 | range allowed by reg domain. */ | ||
1348 | scan.channel = priv->channel; | ||
1349 | |||
1350 | /* atmelwlandriver differs between scan type 0 and 1 (active/passive) | ||
1351 | For ad-hoc mode, it uses type 0 only. */ | ||
1352 | scan.scan_type = priv->scan_mode; | ||
1353 | |||
1354 | /* INFO: For probe_delay, not multiplying by 1024 as this will be | ||
1355 | slightly less than min_channel_time | ||
1356 | (per spec: probe delay < min. channel time) */ | ||
1357 | scan.min_channel_time = cpu_to_le16(priv->scan_min_time); | ||
1358 | scan.max_channel_time = cpu_to_le16(priv->scan_max_time); | ||
1359 | scan.probe_delay = cpu_to_le16(priv->scan_min_time * 1000); | ||
1360 | scan.international_scan = 0; | ||
1361 | |||
1362 | /* other values are set to 0 for type 0 */ | ||
1363 | |||
1364 | at76_dbg(DBG_PROGRESS, "%s: start_scan (use_essid = %d, intl = %d, " | ||
1365 | "channel = %d, probe_delay = %d, scan_min_time = %d, " | ||
1366 | "scan_max_time = %d)", | ||
1367 | priv->netdev->name, use_essid, | ||
1368 | scan.international_scan, scan.channel, | ||
1369 | le16_to_cpu(scan.probe_delay), | ||
1370 | le16_to_cpu(scan.min_channel_time), | ||
1371 | le16_to_cpu(scan.max_channel_time)); | ||
1372 | |||
1373 | return at76_set_card_command(priv->udev, CMD_SCAN, &scan, sizeof(scan)); | ||
1374 | } | ||
1375 | |||
1275 | /* Enable monitor mode */ | 1376 | /* Enable monitor mode */ |
1276 | static int at76_start_monitor(struct at76_priv *priv) | 1377 | static int at76_start_monitor(struct at76_priv *priv) |
1277 | { | 1378 | { |
@@ -1292,6 +1393,86 @@ static int at76_start_monitor(struct at76_priv *priv) | |||
1292 | return ret; | 1393 | return ret; |
1293 | } | 1394 | } |
1294 | 1395 | ||
1396 | static int at76_start_ibss(struct at76_priv *priv) | ||
1397 | { | ||
1398 | struct at76_req_ibss bss; | ||
1399 | int ret; | ||
1400 | |||
1401 | WARN_ON(priv->mac_state != MAC_OWN_IBSS); | ||
1402 | if (priv->mac_state != MAC_OWN_IBSS) | ||
1403 | return -EBUSY; | ||
1404 | |||
1405 | memset(&bss, 0, sizeof(struct at76_req_ibss)); | ||
1406 | memset(bss.bssid, 0xff, ETH_ALEN); | ||
1407 | memcpy(bss.essid, priv->essid, IW_ESSID_MAX_SIZE); | ||
1408 | bss.essid_size = priv->essid_size; | ||
1409 | bss.bss_type = ADHOC_MODE; | ||
1410 | bss.channel = priv->channel; | ||
1411 | |||
1412 | ret = at76_set_card_command(priv->udev, CMD_START_IBSS, &bss, | ||
1413 | sizeof(struct at76_req_ibss)); | ||
1414 | if (ret < 0) { | ||
1415 | printk(KERN_ERR "%s: start_ibss failed: %d\n", | ||
1416 | priv->netdev->name, ret); | ||
1417 | return ret; | ||
1418 | } | ||
1419 | |||
1420 | ret = at76_wait_completion(priv, CMD_START_IBSS); | ||
1421 | if (ret != CMD_STATUS_COMPLETE) { | ||
1422 | printk(KERN_ERR "%s: start_ibss failed to complete, %d\n", | ||
1423 | priv->netdev->name, ret); | ||
1424 | return ret; | ||
1425 | } | ||
1426 | |||
1427 | ret = at76_get_current_bssid(priv); | ||
1428 | if (ret < 0) | ||
1429 | return ret; | ||
1430 | |||
1431 | ret = at76_get_current_channel(priv); | ||
1432 | if (ret < 0) | ||
1433 | return ret; | ||
1434 | |||
1435 | /* not sure what this is good for ??? */ | ||
1436 | priv->mib_buf.type = MIB_MAC_MGMT; | ||
1437 | priv->mib_buf.size = 1; | ||
1438 | priv->mib_buf.index = offsetof(struct mib_mac_mgmt, ibss_change); | ||
1439 | priv->mib_buf.data.byte = 0; | ||
1440 | |||
1441 | ret = at76_set_mib(priv, &priv->mib_buf); | ||
1442 | if (ret < 0) { | ||
1443 | printk(KERN_ERR "%s: set_mib (ibss change ok) failed: %d\n", | ||
1444 | priv->netdev->name, ret); | ||
1445 | return ret; | ||
1446 | } | ||
1447 | |||
1448 | netif_carrier_on(priv->netdev); | ||
1449 | netif_start_queue(priv->netdev); | ||
1450 | return 0; | ||
1451 | } | ||
1452 | |||
1453 | /* Request card to join BSS in managed or ad-hoc mode */ | ||
1454 | static int at76_join_bss(struct at76_priv *priv, struct bss_info *ptr) | ||
1455 | { | ||
1456 | struct at76_req_join join; | ||
1457 | |||
1458 | BUG_ON(!ptr); | ||
1459 | |||
1460 | memset(&join, 0, sizeof(struct at76_req_join)); | ||
1461 | memcpy(join.bssid, ptr->bssid, ETH_ALEN); | ||
1462 | memcpy(join.essid, ptr->ssid, ptr->ssid_len); | ||
1463 | join.essid_size = ptr->ssid_len; | ||
1464 | join.bss_type = (priv->iw_mode == IW_MODE_ADHOC ? 1 : 2); | ||
1465 | join.channel = ptr->channel; | ||
1466 | join.timeout = cpu_to_le16(2000); | ||
1467 | |||
1468 | at76_dbg(DBG_PROGRESS, | ||
1469 | "%s join addr %s ssid %s type %d ch %d timeout %d", | ||
1470 | priv->netdev->name, mac2str(join.bssid), join.essid, | ||
1471 | join.bss_type, join.channel, le16_to_cpu(join.timeout)); | ||
1472 | return at76_set_card_command(priv->udev, CMD_JOIN, &join, | ||
1473 | sizeof(struct at76_req_join)); | ||
1474 | } | ||
1475 | |||
1295 | /* Calculate padding from txbuf->wlength (which excludes the USB TX header), | 1476 | /* Calculate padding from txbuf->wlength (which excludes the USB TX header), |
1296 | likely to compensate a flaw in the AT76C503A USB part ... */ | 1477 | likely to compensate a flaw in the AT76C503A USB part ... */ |
1297 | static inline int at76_calc_padding(int wlen) | 1478 | static inline int at76_calc_padding(int wlen) |
@@ -1310,6 +1491,14 @@ static inline int at76_calc_padding(int wlen) | |||
1310 | return 0; | 1491 | return 0; |
1311 | } | 1492 | } |
1312 | 1493 | ||
1494 | /* We are doing a lot of things here in an interrupt. Need | ||
1495 | a bh handler (Watching TV with a TV card is probably | ||
1496 | a good test: if you see flickers, we are doing too much. | ||
1497 | Currently I do see flickers... even with our tasklet :-( ) | ||
1498 | Maybe because the bttv driver and usb-uhci use the same interrupt | ||
1499 | */ | ||
1500 | /* Or maybe because our BH handler is preempting bttv's BH handler.. BHs don't | ||
1501 | * solve everything.. (alex) */ | ||
1313 | static void at76_rx_callback(struct urb *urb) | 1502 | static void at76_rx_callback(struct urb *urb) |
1314 | { | 1503 | { |
1315 | struct at76_priv *priv = urb->context; | 1504 | struct at76_priv *priv = urb->context; |
@@ -1319,6 +1508,1758 @@ static void at76_rx_callback(struct urb *urb) | |||
1319 | return; | 1508 | return; |
1320 | } | 1509 | } |
1321 | 1510 | ||
1511 | static void at76_tx_callback(struct urb *urb) | ||
1512 | { | ||
1513 | struct at76_priv *priv = urb->context; | ||
1514 | struct net_device_stats *stats = &priv->stats; | ||
1515 | unsigned long flags; | ||
1516 | struct at76_tx_buffer *mgmt_buf; | ||
1517 | int ret; | ||
1518 | |||
1519 | switch (urb->status) { | ||
1520 | case 0: | ||
1521 | stats->tx_packets++; | ||
1522 | break; | ||
1523 | case -ENOENT: | ||
1524 | case -ECONNRESET: | ||
1525 | /* urb has been unlinked */ | ||
1526 | return; | ||
1527 | default: | ||
1528 | at76_dbg(DBG_URB, "%s - nonzero tx status received: %d", | ||
1529 | __func__, urb->status); | ||
1530 | stats->tx_errors++; | ||
1531 | break; | ||
1532 | } | ||
1533 | |||
1534 | spin_lock_irqsave(&priv->mgmt_spinlock, flags); | ||
1535 | mgmt_buf = priv->next_mgmt_bulk; | ||
1536 | priv->next_mgmt_bulk = NULL; | ||
1537 | spin_unlock_irqrestore(&priv->mgmt_spinlock, flags); | ||
1538 | |||
1539 | if (!mgmt_buf) { | ||
1540 | netif_wake_queue(priv->netdev); | ||
1541 | return; | ||
1542 | } | ||
1543 | |||
1544 | /* we don't copy the padding bytes, but add them | ||
1545 | to the length */ | ||
1546 | memcpy(priv->bulk_out_buffer, mgmt_buf, | ||
1547 | le16_to_cpu(mgmt_buf->wlength) + AT76_TX_HDRLEN); | ||
1548 | usb_fill_bulk_urb(priv->tx_urb, priv->udev, priv->tx_pipe, | ||
1549 | priv->bulk_out_buffer, | ||
1550 | le16_to_cpu(mgmt_buf->wlength) + mgmt_buf->padding + | ||
1551 | AT76_TX_HDRLEN, at76_tx_callback, priv); | ||
1552 | ret = usb_submit_urb(priv->tx_urb, GFP_ATOMIC); | ||
1553 | if (ret) | ||
1554 | printk(KERN_ERR "%s: error in tx submit urb: %d\n", | ||
1555 | priv->netdev->name, ret); | ||
1556 | |||
1557 | kfree(mgmt_buf); | ||
1558 | } | ||
1559 | |||
1560 | /* Send a management frame on bulk-out. txbuf->wlength must be set */ | ||
1561 | static int at76_tx_mgmt(struct at76_priv *priv, struct at76_tx_buffer *txbuf) | ||
1562 | { | ||
1563 | unsigned long flags; | ||
1564 | int ret; | ||
1565 | int urb_status; | ||
1566 | void *oldbuf = NULL; | ||
1567 | |||
1568 | netif_carrier_off(priv->netdev); /* stop netdev watchdog */ | ||
1569 | netif_stop_queue(priv->netdev); /* stop tx data packets */ | ||
1570 | |||
1571 | spin_lock_irqsave(&priv->mgmt_spinlock, flags); | ||
1572 | |||
1573 | urb_status = priv->tx_urb->status; | ||
1574 | if (urb_status == -EINPROGRESS) { | ||
1575 | /* cannot transmit now, put in the queue */ | ||
1576 | oldbuf = priv->next_mgmt_bulk; | ||
1577 | priv->next_mgmt_bulk = txbuf; | ||
1578 | } | ||
1579 | spin_unlock_irqrestore(&priv->mgmt_spinlock, flags); | ||
1580 | |||
1581 | if (oldbuf) { | ||
1582 | /* a data/mgmt tx is already pending in the URB - | ||
1583 | if this is no error in some situations we must | ||
1584 | implement a queue or silently modify the old msg */ | ||
1585 | printk(KERN_ERR "%s: removed pending mgmt buffer %s\n", | ||
1586 | priv->netdev->name, hex2str(oldbuf, 64)); | ||
1587 | kfree(oldbuf); | ||
1588 | return 0; | ||
1589 | } | ||
1590 | |||
1591 | txbuf->tx_rate = TX_RATE_1MBIT; | ||
1592 | txbuf->padding = at76_calc_padding(le16_to_cpu(txbuf->wlength)); | ||
1593 | memset(txbuf->reserved, 0, sizeof(txbuf->reserved)); | ||
1594 | |||
1595 | if (priv->next_mgmt_bulk) | ||
1596 | printk(KERN_ERR "%s: URB status %d, but mgmt is pending\n", | ||
1597 | priv->netdev->name, urb_status); | ||
1598 | |||
1599 | at76_dbg(DBG_TX_MGMT, | ||
1600 | "%s: tx mgmt: wlen %d tx_rate %d pad %d %s", | ||
1601 | priv->netdev->name, le16_to_cpu(txbuf->wlength), | ||
1602 | txbuf->tx_rate, txbuf->padding, | ||
1603 | hex2str(txbuf->packet, le16_to_cpu(txbuf->wlength))); | ||
1604 | |||
1605 | /* txbuf was not consumed above -> send mgmt msg immediately */ | ||
1606 | memcpy(priv->bulk_out_buffer, txbuf, | ||
1607 | le16_to_cpu(txbuf->wlength) + AT76_TX_HDRLEN); | ||
1608 | usb_fill_bulk_urb(priv->tx_urb, priv->udev, priv->tx_pipe, | ||
1609 | priv->bulk_out_buffer, | ||
1610 | le16_to_cpu(txbuf->wlength) + txbuf->padding + | ||
1611 | AT76_TX_HDRLEN, at76_tx_callback, priv); | ||
1612 | ret = usb_submit_urb(priv->tx_urb, GFP_ATOMIC); | ||
1613 | if (ret) | ||
1614 | printk(KERN_ERR "%s: error in tx submit urb: %d\n", | ||
1615 | priv->netdev->name, ret); | ||
1616 | |||
1617 | kfree(txbuf); | ||
1618 | |||
1619 | return ret; | ||
1620 | } | ||
1621 | |||
1622 | /* Go to the next information element */ | ||
1623 | static inline void next_ie(struct ieee80211_info_element **ie) | ||
1624 | { | ||
1625 | *ie = (struct ieee80211_info_element *)(&(*ie)->data[(*ie)->len]); | ||
1626 | } | ||
1627 | |||
1628 | /* Challenge is the challenge string (in TLV format) | ||
1629 | we got with seq_nr 2 for shared secret authentication only and | ||
1630 | send in seq_nr 3 WEP encrypted to prove we have the correct WEP key; | ||
1631 | otherwise it is NULL */ | ||
1632 | static int at76_auth_req(struct at76_priv *priv, struct bss_info *bss, | ||
1633 | int seq_nr, struct ieee80211_info_element *challenge) | ||
1634 | { | ||
1635 | struct at76_tx_buffer *tx_buffer; | ||
1636 | struct ieee80211_hdr_3addr *mgmt; | ||
1637 | struct ieee80211_auth *req; | ||
1638 | int buf_len = (seq_nr != 3 ? AUTH_FRAME_SIZE : | ||
1639 | AUTH_FRAME_SIZE + 1 + 1 + challenge->len); | ||
1640 | |||
1641 | BUG_ON(!bss); | ||
1642 | BUG_ON(seq_nr == 3 && !challenge); | ||
1643 | tx_buffer = kmalloc(buf_len + MAX_PADDING_SIZE, GFP_ATOMIC); | ||
1644 | if (!tx_buffer) | ||
1645 | return -ENOMEM; | ||
1646 | |||
1647 | req = (struct ieee80211_auth *)tx_buffer->packet; | ||
1648 | mgmt = &req->header; | ||
1649 | |||
1650 | /* make wireless header */ | ||
1651 | /* first auth msg is not encrypted, only the second (seq_nr == 3) */ | ||
1652 | mgmt->frame_ctl = | ||
1653 | cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH | | ||
1654 | (seq_nr == 3 ? IEEE80211_FCTL_PROTECTED : 0)); | ||
1655 | |||
1656 | mgmt->duration_id = cpu_to_le16(0x8000); | ||
1657 | memcpy(mgmt->addr1, bss->bssid, ETH_ALEN); | ||
1658 | memcpy(mgmt->addr2, priv->netdev->dev_addr, ETH_ALEN); | ||
1659 | memcpy(mgmt->addr3, bss->bssid, ETH_ALEN); | ||
1660 | mgmt->seq_ctl = cpu_to_le16(0); | ||
1661 | |||
1662 | req->algorithm = cpu_to_le16(priv->auth_mode); | ||
1663 | req->transaction = cpu_to_le16(seq_nr); | ||
1664 | req->status = cpu_to_le16(0); | ||
1665 | |||
1666 | if (seq_nr == 3) | ||
1667 | memcpy(req->info_element, challenge, 1 + 1 + challenge->len); | ||
1668 | |||
1669 | /* init. at76_priv tx header */ | ||
1670 | tx_buffer->wlength = cpu_to_le16(buf_len - AT76_TX_HDRLEN); | ||
1671 | at76_dbg(DBG_TX_MGMT, "%s: AuthReq bssid %s alg %d seq_nr %d", | ||
1672 | priv->netdev->name, mac2str(mgmt->addr3), | ||
1673 | le16_to_cpu(req->algorithm), le16_to_cpu(req->transaction)); | ||
1674 | if (seq_nr == 3) | ||
1675 | at76_dbg(DBG_TX_MGMT, "%s: AuthReq challenge: %s ...", | ||
1676 | priv->netdev->name, hex2str(req->info_element, 18)); | ||
1677 | |||
1678 | /* either send immediately (if no data tx is pending | ||
1679 | or put it in pending list */ | ||
1680 | return at76_tx_mgmt(priv, tx_buffer); | ||
1681 | } | ||
1682 | |||
1683 | static int at76_assoc_req(struct at76_priv *priv, struct bss_info *bss) | ||
1684 | { | ||
1685 | struct at76_tx_buffer *tx_buffer; | ||
1686 | struct ieee80211_hdr_3addr *mgmt; | ||
1687 | struct ieee80211_assoc_request *req; | ||
1688 | struct ieee80211_info_element *ie; | ||
1689 | char *essid; | ||
1690 | int essid_len; | ||
1691 | u16 capa; | ||
1692 | |||
1693 | BUG_ON(!bss); | ||
1694 | |||
1695 | tx_buffer = kmalloc(ASSOCREQ_MAX_SIZE + MAX_PADDING_SIZE, GFP_ATOMIC); | ||
1696 | if (!tx_buffer) | ||
1697 | return -ENOMEM; | ||
1698 | |||
1699 | req = (struct ieee80211_assoc_request *)tx_buffer->packet; | ||
1700 | mgmt = &req->header; | ||
1701 | ie = req->info_element; | ||
1702 | |||
1703 | /* make wireless header */ | ||
1704 | mgmt->frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | | ||
1705 | IEEE80211_STYPE_ASSOC_REQ); | ||
1706 | |||
1707 | mgmt->duration_id = cpu_to_le16(0x8000); | ||
1708 | memcpy(mgmt->addr1, bss->bssid, ETH_ALEN); | ||
1709 | memcpy(mgmt->addr2, priv->netdev->dev_addr, ETH_ALEN); | ||
1710 | memcpy(mgmt->addr3, bss->bssid, ETH_ALEN); | ||
1711 | mgmt->seq_ctl = cpu_to_le16(0); | ||
1712 | |||
1713 | /* we must set the Privacy bit in the capabilities to assure an | ||
1714 | Agere-based AP with optional WEP transmits encrypted frames | ||
1715 | to us. AP only set the Privacy bit in their capabilities | ||
1716 | if WEP is mandatory in the BSS! */ | ||
1717 | capa = bss->capa; | ||
1718 | if (priv->wep_enabled) | ||
1719 | capa |= WLAN_CAPABILITY_PRIVACY; | ||
1720 | if (priv->preamble_type != PREAMBLE_TYPE_LONG) | ||
1721 | capa |= WLAN_CAPABILITY_SHORT_PREAMBLE; | ||
1722 | req->capability = cpu_to_le16(capa); | ||
1723 | |||
1724 | req->listen_interval = cpu_to_le16(2 * bss->beacon_interval); | ||
1725 | |||
1726 | /* write TLV data elements */ | ||
1727 | |||
1728 | ie->id = MFIE_TYPE_SSID; | ||
1729 | ie->len = bss->ssid_len; | ||
1730 | memcpy(ie->data, bss->ssid, bss->ssid_len); | ||
1731 | next_ie(&ie); | ||
1732 | |||
1733 | ie->id = MFIE_TYPE_RATES; | ||
1734 | ie->len = sizeof(hw_rates); | ||
1735 | memcpy(ie->data, hw_rates, sizeof(hw_rates)); | ||
1736 | next_ie(&ie); /* ie points behind the supp_rates field */ | ||
1737 | |||
1738 | /* init. at76_priv tx header */ | ||
1739 | tx_buffer->wlength = cpu_to_le16((u8 *)ie - (u8 *)mgmt); | ||
1740 | |||
1741 | ie = req->info_element; | ||
1742 | essid = ie->data; | ||
1743 | essid_len = min_t(int, IW_ESSID_MAX_SIZE, ie->len); | ||
1744 | |||
1745 | next_ie(&ie); /* points to IE of rates now */ | ||
1746 | at76_dbg(DBG_TX_MGMT, | ||
1747 | "%s: AssocReq bssid %s capa 0x%04x ssid %.*s rates %s", | ||
1748 | priv->netdev->name, mac2str(mgmt->addr3), | ||
1749 | le16_to_cpu(req->capability), essid_len, essid, | ||
1750 | hex2str(ie->data, ie->len)); | ||
1751 | |||
1752 | /* either send immediately (if no data tx is pending | ||
1753 | or put it in pending list */ | ||
1754 | return at76_tx_mgmt(priv, tx_buffer); | ||
1755 | } | ||
1756 | |||
1757 | /* We got to check the bss_list for old entries */ | ||
1758 | static void at76_bss_list_timeout(unsigned long par) | ||
1759 | { | ||
1760 | struct at76_priv *priv = (struct at76_priv *)par; | ||
1761 | unsigned long flags; | ||
1762 | struct list_head *lptr, *nptr; | ||
1763 | struct bss_info *ptr; | ||
1764 | |||
1765 | spin_lock_irqsave(&priv->bss_list_spinlock, flags); | ||
1766 | |||
1767 | list_for_each_safe(lptr, nptr, &priv->bss_list) { | ||
1768 | |||
1769 | ptr = list_entry(lptr, struct bss_info, list); | ||
1770 | |||
1771 | if (ptr != priv->curr_bss | ||
1772 | && time_after(jiffies, ptr->last_rx + BSS_LIST_TIMEOUT)) { | ||
1773 | at76_dbg(DBG_BSS_TABLE_RM, | ||
1774 | "%s: bss_list: removing old BSS %s ch %d", | ||
1775 | priv->netdev->name, mac2str(ptr->bssid), | ||
1776 | ptr->channel); | ||
1777 | list_del(&ptr->list); | ||
1778 | kfree(ptr); | ||
1779 | } | ||
1780 | } | ||
1781 | spin_unlock_irqrestore(&priv->bss_list_spinlock, flags); | ||
1782 | /* restart the timer */ | ||
1783 | mod_timer(&priv->bss_list_timer, jiffies + BSS_LIST_TIMEOUT); | ||
1784 | } | ||
1785 | |||
1786 | static inline void at76_set_mac_state(struct at76_priv *priv, | ||
1787 | enum mac_state mac_state) | ||
1788 | { | ||
1789 | at76_dbg(DBG_MAC_STATE, "%s state: %s", priv->netdev->name, | ||
1790 | mac_states[mac_state]); | ||
1791 | priv->mac_state = mac_state; | ||
1792 | } | ||
1793 | |||
1794 | static void at76_dump_bss_table(struct at76_priv *priv) | ||
1795 | { | ||
1796 | struct bss_info *ptr; | ||
1797 | unsigned long flags; | ||
1798 | struct list_head *lptr; | ||
1799 | |||
1800 | spin_lock_irqsave(&priv->bss_list_spinlock, flags); | ||
1801 | |||
1802 | at76_dbg(DBG_BSS_TABLE, "%s BSS table (curr=%p):", priv->netdev->name, | ||
1803 | priv->curr_bss); | ||
1804 | |||
1805 | list_for_each(lptr, &priv->bss_list) { | ||
1806 | ptr = list_entry(lptr, struct bss_info, list); | ||
1807 | at76_dbg(DBG_BSS_TABLE, "0x%p: bssid %s channel %d ssid %.*s " | ||
1808 | "(%s) capa 0x%04x rates %s rssi %d link %d noise %d", | ||
1809 | ptr, mac2str(ptr->bssid), ptr->channel, ptr->ssid_len, | ||
1810 | ptr->ssid, hex2str(ptr->ssid, ptr->ssid_len), | ||
1811 | ptr->capa, hex2str(ptr->rates, ptr->rates_len), | ||
1812 | ptr->rssi, ptr->link_qual, ptr->noise_level); | ||
1813 | } | ||
1814 | spin_unlock_irqrestore(&priv->bss_list_spinlock, flags); | ||
1815 | } | ||
1816 | |||
1817 | /* Called upon successful association to mark interface as connected */ | ||
1818 | static void at76_work_assoc_done(struct work_struct *work) | ||
1819 | { | ||
1820 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
1821 | work_assoc_done); | ||
1822 | |||
1823 | mutex_lock(&priv->mtx); | ||
1824 | |||
1825 | WARN_ON(priv->mac_state != MAC_ASSOC); | ||
1826 | WARN_ON(!priv->curr_bss); | ||
1827 | if (priv->mac_state != MAC_ASSOC || !priv->curr_bss) | ||
1828 | goto exit; | ||
1829 | |||
1830 | if (priv->iw_mode == IW_MODE_INFRA) { | ||
1831 | if (priv->pm_mode != AT76_PM_OFF) { | ||
1832 | /* calculate the listen interval in units of | ||
1833 | beacon intervals of the curr_bss */ | ||
1834 | u32 pm_period_beacon = (priv->pm_period >> 10) / | ||
1835 | priv->curr_bss->beacon_interval; | ||
1836 | |||
1837 | pm_period_beacon = max(pm_period_beacon, 2u); | ||
1838 | pm_period_beacon = min(pm_period_beacon, 0xffffu); | ||
1839 | |||
1840 | at76_dbg(DBG_PM, | ||
1841 | "%s: pm_mode %d assoc id 0x%x listen int %d", | ||
1842 | priv->netdev->name, priv->pm_mode, | ||
1843 | priv->assoc_id, pm_period_beacon); | ||
1844 | |||
1845 | at76_set_associd(priv, priv->assoc_id); | ||
1846 | at76_set_listen_interval(priv, (u16)pm_period_beacon); | ||
1847 | } | ||
1848 | schedule_delayed_work(&priv->dwork_beacon, BEACON_TIMEOUT); | ||
1849 | } | ||
1850 | at76_set_pm_mode(priv); | ||
1851 | |||
1852 | netif_carrier_on(priv->netdev); | ||
1853 | netif_wake_queue(priv->netdev); | ||
1854 | at76_set_mac_state(priv, MAC_CONNECTED); | ||
1855 | at76_iwevent_bss_connect(priv->netdev, priv->curr_bss->bssid); | ||
1856 | at76_dbg(DBG_PROGRESS, "%s: connected to BSSID %s", | ||
1857 | priv->netdev->name, mac2str(priv->curr_bss->bssid)); | ||
1858 | |||
1859 | exit: | ||
1860 | mutex_unlock(&priv->mtx); | ||
1861 | } | ||
1862 | |||
1863 | /* We only store the new mac address in netdev struct, | ||
1864 | it gets set when the netdev is opened. */ | ||
1865 | static int at76_set_mac_address(struct net_device *netdev, void *addr) | ||
1866 | { | ||
1867 | struct sockaddr *mac = addr; | ||
1868 | memcpy(netdev->dev_addr, mac->sa_data, ETH_ALEN); | ||
1869 | return 1; | ||
1870 | } | ||
1871 | |||
1872 | static struct net_device_stats *at76_get_stats(struct net_device *netdev) | ||
1873 | { | ||
1874 | struct at76_priv *priv = netdev_priv(netdev); | ||
1875 | return &priv->stats; | ||
1876 | } | ||
1877 | |||
1878 | static struct iw_statistics *at76_get_wireless_stats(struct net_device *netdev) | ||
1879 | { | ||
1880 | struct at76_priv *priv = netdev_priv(netdev); | ||
1881 | |||
1882 | at76_dbg(DBG_IOCTL, "RETURN qual %d level %d noise %d updated %d", | ||
1883 | priv->wstats.qual.qual, priv->wstats.qual.level, | ||
1884 | priv->wstats.qual.noise, priv->wstats.qual.updated); | ||
1885 | |||
1886 | return &priv->wstats; | ||
1887 | } | ||
1888 | |||
1889 | static void at76_set_multicast(struct net_device *netdev) | ||
1890 | { | ||
1891 | struct at76_priv *priv = netdev_priv(netdev); | ||
1892 | int promisc; | ||
1893 | |||
1894 | promisc = ((netdev->flags & IFF_PROMISC) != 0); | ||
1895 | if (promisc != priv->promisc) { | ||
1896 | /* This gets called in interrupt, must reschedule */ | ||
1897 | priv->promisc = promisc; | ||
1898 | schedule_work(&priv->work_set_promisc); | ||
1899 | } | ||
1900 | } | ||
1901 | |||
1902 | /* Stop all network activity, flush all pending tasks */ | ||
1903 | static void at76_quiesce(struct at76_priv *priv) | ||
1904 | { | ||
1905 | unsigned long flags; | ||
1906 | |||
1907 | netif_stop_queue(priv->netdev); | ||
1908 | netif_carrier_off(priv->netdev); | ||
1909 | |||
1910 | at76_set_mac_state(priv, MAC_INIT); | ||
1911 | |||
1912 | cancel_delayed_work(&priv->dwork_get_scan); | ||
1913 | cancel_delayed_work(&priv->dwork_beacon); | ||
1914 | cancel_delayed_work(&priv->dwork_auth); | ||
1915 | cancel_delayed_work(&priv->dwork_assoc); | ||
1916 | cancel_delayed_work(&priv->dwork_restart); | ||
1917 | |||
1918 | spin_lock_irqsave(&priv->mgmt_spinlock, flags); | ||
1919 | kfree(priv->next_mgmt_bulk); | ||
1920 | priv->next_mgmt_bulk = NULL; | ||
1921 | spin_unlock_irqrestore(&priv->mgmt_spinlock, flags); | ||
1922 | } | ||
1923 | |||
1924 | /******************************************************************************* | ||
1925 | * at76_priv implementations of iw_handler functions: | ||
1926 | */ | ||
1927 | static int at76_iw_handler_commit(struct net_device *netdev, | ||
1928 | struct iw_request_info *info, | ||
1929 | void *null, char *extra) | ||
1930 | { | ||
1931 | struct at76_priv *priv = netdev_priv(netdev); | ||
1932 | |||
1933 | at76_dbg(DBG_IOCTL, "%s %s: restarting the device", netdev->name, | ||
1934 | __func__); | ||
1935 | |||
1936 | if (priv->mac_state != MAC_INIT) | ||
1937 | at76_quiesce(priv); | ||
1938 | |||
1939 | /* Wait half second before the restart to process subsequent | ||
1940 | * requests from the same iwconfig in a single restart */ | ||
1941 | schedule_delayed_work(&priv->dwork_restart, HZ / 2); | ||
1942 | |||
1943 | return 0; | ||
1944 | } | ||
1945 | |||
1946 | static int at76_iw_handler_get_name(struct net_device *netdev, | ||
1947 | struct iw_request_info *info, | ||
1948 | char *name, char *extra) | ||
1949 | { | ||
1950 | strcpy(name, "IEEE 802.11b"); | ||
1951 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWNAME - name %s", netdev->name, name); | ||
1952 | return 0; | ||
1953 | } | ||
1954 | |||
1955 | static int at76_iw_handler_set_freq(struct net_device *netdev, | ||
1956 | struct iw_request_info *info, | ||
1957 | struct iw_freq *freq, char *extra) | ||
1958 | { | ||
1959 | struct at76_priv *priv = netdev_priv(netdev); | ||
1960 | int chan = -1; | ||
1961 | int ret = -EIWCOMMIT; | ||
1962 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWFREQ - freq.m %d freq.e %d", | ||
1963 | netdev->name, freq->m, freq->e); | ||
1964 | |||
1965 | if ((freq->e == 0) && (freq->m <= 1000)) | ||
1966 | /* Setting by channel number */ | ||
1967 | chan = freq->m; | ||
1968 | else { | ||
1969 | /* Setting by frequency - search the table */ | ||
1970 | int mult = 1; | ||
1971 | int i; | ||
1972 | |||
1973 | for (i = 0; i < (6 - freq->e); i++) | ||
1974 | mult *= 10; | ||
1975 | |||
1976 | for (i = 0; i < NUM_CHANNELS; i++) { | ||
1977 | if (freq->m == (channel_frequency[i] * mult)) | ||
1978 | chan = i + 1; | ||
1979 | } | ||
1980 | } | ||
1981 | |||
1982 | if (chan < 1 || !priv->domain) | ||
1983 | /* non-positive channels are invalid | ||
1984 | * we need a domain info to set the channel | ||
1985 | * either that or an invalid frequency was | ||
1986 | * provided by the user */ | ||
1987 | ret = -EINVAL; | ||
1988 | else if (!(priv->domain->channel_map & (1 << (chan - 1)))) { | ||
1989 | printk(KERN_INFO "%s: channel %d not allowed for domain %s\n", | ||
1990 | priv->netdev->name, chan, priv->domain->name); | ||
1991 | ret = -EINVAL; | ||
1992 | } | ||
1993 | |||
1994 | if (ret == -EIWCOMMIT) { | ||
1995 | priv->channel = chan; | ||
1996 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWFREQ - ch %d", netdev->name, | ||
1997 | chan); | ||
1998 | } | ||
1999 | |||
2000 | return ret; | ||
2001 | } | ||
2002 | |||
2003 | static int at76_iw_handler_get_freq(struct net_device *netdev, | ||
2004 | struct iw_request_info *info, | ||
2005 | struct iw_freq *freq, char *extra) | ||
2006 | { | ||
2007 | struct at76_priv *priv = netdev_priv(netdev); | ||
2008 | |||
2009 | freq->m = priv->channel; | ||
2010 | freq->e = 0; | ||
2011 | |||
2012 | if (priv->channel) | ||
2013 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWFREQ - freq %ld x 10e%d", | ||
2014 | netdev->name, channel_frequency[priv->channel - 1], 6); | ||
2015 | |||
2016 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWFREQ - ch %d", netdev->name, | ||
2017 | priv->channel); | ||
2018 | |||
2019 | return 0; | ||
2020 | } | ||
2021 | |||
2022 | static int at76_iw_handler_set_mode(struct net_device *netdev, | ||
2023 | struct iw_request_info *info, | ||
2024 | __u32 *mode, char *extra) | ||
2025 | { | ||
2026 | struct at76_priv *priv = netdev_priv(netdev); | ||
2027 | |||
2028 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWMODE - %d", netdev->name, *mode); | ||
2029 | |||
2030 | if ((*mode != IW_MODE_ADHOC) && (*mode != IW_MODE_INFRA) && | ||
2031 | (*mode != IW_MODE_MONITOR)) | ||
2032 | return -EINVAL; | ||
2033 | |||
2034 | priv->iw_mode = *mode; | ||
2035 | if (priv->iw_mode != IW_MODE_INFRA) | ||
2036 | priv->pm_mode = AT76_PM_OFF; | ||
2037 | |||
2038 | return -EIWCOMMIT; | ||
2039 | } | ||
2040 | |||
2041 | static int at76_iw_handler_get_mode(struct net_device *netdev, | ||
2042 | struct iw_request_info *info, | ||
2043 | __u32 *mode, char *extra) | ||
2044 | { | ||
2045 | struct at76_priv *priv = netdev_priv(netdev); | ||
2046 | |||
2047 | *mode = priv->iw_mode; | ||
2048 | |||
2049 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWMODE - %d", netdev->name, *mode); | ||
2050 | |||
2051 | return 0; | ||
2052 | } | ||
2053 | |||
2054 | static int at76_iw_handler_get_range(struct net_device *netdev, | ||
2055 | struct iw_request_info *info, | ||
2056 | struct iw_point *data, char *extra) | ||
2057 | { | ||
2058 | /* inspired by atmel.c */ | ||
2059 | struct at76_priv *priv = netdev_priv(netdev); | ||
2060 | struct iw_range *range = (struct iw_range *)extra; | ||
2061 | int i; | ||
2062 | |||
2063 | data->length = sizeof(struct iw_range); | ||
2064 | memset(range, 0, sizeof(struct iw_range)); | ||
2065 | |||
2066 | /* TODO: range->throughput = xxxxxx; */ | ||
2067 | |||
2068 | range->min_nwid = 0x0000; | ||
2069 | range->max_nwid = 0x0000; | ||
2070 | |||
2071 | /* this driver doesn't maintain sensitivity information */ | ||
2072 | range->sensitivity = 0; | ||
2073 | |||
2074 | range->max_qual.qual = 100; | ||
2075 | range->max_qual.level = 100; | ||
2076 | range->max_qual.noise = 0; | ||
2077 | range->max_qual.updated = IW_QUAL_NOISE_INVALID; | ||
2078 | |||
2079 | range->avg_qual.qual = 50; | ||
2080 | range->avg_qual.level = 50; | ||
2081 | range->avg_qual.noise = 0; | ||
2082 | range->avg_qual.updated = IW_QUAL_NOISE_INVALID; | ||
2083 | |||
2084 | range->bitrate[0] = 1000000; | ||
2085 | range->bitrate[1] = 2000000; | ||
2086 | range->bitrate[2] = 5500000; | ||
2087 | range->bitrate[3] = 11000000; | ||
2088 | range->num_bitrates = 4; | ||
2089 | |||
2090 | range->min_rts = 0; | ||
2091 | range->max_rts = MAX_RTS_THRESHOLD; | ||
2092 | |||
2093 | range->min_frag = MIN_FRAG_THRESHOLD; | ||
2094 | range->max_frag = MAX_FRAG_THRESHOLD; | ||
2095 | |||
2096 | range->pmp_flags = IW_POWER_PERIOD; | ||
2097 | range->pmt_flags = IW_POWER_ON; | ||
2098 | range->pm_capa = IW_POWER_PERIOD | IW_POWER_ALL_R; | ||
2099 | |||
2100 | range->encoding_size[0] = WEP_SMALL_KEY_LEN; | ||
2101 | range->encoding_size[1] = WEP_LARGE_KEY_LEN; | ||
2102 | range->num_encoding_sizes = 2; | ||
2103 | range->max_encoding_tokens = WEP_KEYS; | ||
2104 | |||
2105 | /* both WL-240U and Linksys WUSB11 v2.6 specify 15 dBm as output power | ||
2106 | - take this for all (ignore antenna gains) */ | ||
2107 | range->txpower[0] = 15; | ||
2108 | range->num_txpower = 1; | ||
2109 | range->txpower_capa = IW_TXPOW_DBM; | ||
2110 | |||
2111 | range->we_version_source = WIRELESS_EXT; | ||
2112 | range->we_version_compiled = WIRELESS_EXT; | ||
2113 | |||
2114 | /* same as the values used in atmel.c */ | ||
2115 | range->retry_capa = IW_RETRY_LIMIT; | ||
2116 | range->retry_flags = IW_RETRY_LIMIT; | ||
2117 | range->r_time_flags = 0; | ||
2118 | range->min_retry = 1; | ||
2119 | range->max_retry = 255; | ||
2120 | |||
2121 | range->num_channels = NUM_CHANNELS; | ||
2122 | range->num_frequency = 0; | ||
2123 | |||
2124 | for (i = 0; i < NUM_CHANNELS; i++) { | ||
2125 | /* test if channel map bit is raised */ | ||
2126 | if (priv->domain->channel_map & (0x1 << i)) { | ||
2127 | range->num_frequency += 1; | ||
2128 | |||
2129 | range->freq[i].i = i + 1; | ||
2130 | range->freq[i].m = channel_frequency[i] * 100000; | ||
2131 | range->freq[i].e = 1; /* freq * 10^1 */ | ||
2132 | } | ||
2133 | } | ||
2134 | |||
2135 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWRANGE", netdev->name); | ||
2136 | |||
2137 | return 0; | ||
2138 | } | ||
2139 | |||
2140 | static int at76_iw_handler_set_spy(struct net_device *netdev, | ||
2141 | struct iw_request_info *info, | ||
2142 | struct iw_point *data, char *extra) | ||
2143 | { | ||
2144 | struct at76_priv *priv = netdev_priv(netdev); | ||
2145 | int ret = 0; | ||
2146 | |||
2147 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWSPY - number of addresses %d", | ||
2148 | netdev->name, data->length); | ||
2149 | |||
2150 | spin_lock_bh(&priv->spy_spinlock); | ||
2151 | ret = iw_handler_set_spy(priv->netdev, info, (union iwreq_data *)data, | ||
2152 | extra); | ||
2153 | spin_unlock_bh(&priv->spy_spinlock); | ||
2154 | |||
2155 | return ret; | ||
2156 | } | ||
2157 | |||
2158 | static int at76_iw_handler_get_spy(struct net_device *netdev, | ||
2159 | struct iw_request_info *info, | ||
2160 | struct iw_point *data, char *extra) | ||
2161 | { | ||
2162 | |||
2163 | struct at76_priv *priv = netdev_priv(netdev); | ||
2164 | int ret = 0; | ||
2165 | |||
2166 | spin_lock_bh(&priv->spy_spinlock); | ||
2167 | ret = iw_handler_get_spy(priv->netdev, info, | ||
2168 | (union iwreq_data *)data, extra); | ||
2169 | spin_unlock_bh(&priv->spy_spinlock); | ||
2170 | |||
2171 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWSPY - number of addresses %d", | ||
2172 | netdev->name, data->length); | ||
2173 | |||
2174 | return ret; | ||
2175 | } | ||
2176 | |||
2177 | static int at76_iw_handler_set_thrspy(struct net_device *netdev, | ||
2178 | struct iw_request_info *info, | ||
2179 | struct iw_point *data, char *extra) | ||
2180 | { | ||
2181 | struct at76_priv *priv = netdev_priv(netdev); | ||
2182 | int ret; | ||
2183 | |||
2184 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWTHRSPY - number of addresses %d)", | ||
2185 | netdev->name, data->length); | ||
2186 | |||
2187 | spin_lock_bh(&priv->spy_spinlock); | ||
2188 | ret = iw_handler_set_thrspy(netdev, info, (union iwreq_data *)data, | ||
2189 | extra); | ||
2190 | spin_unlock_bh(&priv->spy_spinlock); | ||
2191 | |||
2192 | return ret; | ||
2193 | } | ||
2194 | |||
2195 | static int at76_iw_handler_get_thrspy(struct net_device *netdev, | ||
2196 | struct iw_request_info *info, | ||
2197 | struct iw_point *data, char *extra) | ||
2198 | { | ||
2199 | struct at76_priv *priv = netdev_priv(netdev); | ||
2200 | int ret; | ||
2201 | |||
2202 | spin_lock_bh(&priv->spy_spinlock); | ||
2203 | ret = iw_handler_get_thrspy(netdev, info, (union iwreq_data *)data, | ||
2204 | extra); | ||
2205 | spin_unlock_bh(&priv->spy_spinlock); | ||
2206 | |||
2207 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWTHRSPY - number of addresses %d)", | ||
2208 | netdev->name, data->length); | ||
2209 | |||
2210 | return ret; | ||
2211 | } | ||
2212 | |||
2213 | static int at76_iw_handler_set_wap(struct net_device *netdev, | ||
2214 | struct iw_request_info *info, | ||
2215 | struct sockaddr *ap_addr, char *extra) | ||
2216 | { | ||
2217 | struct at76_priv *priv = netdev_priv(netdev); | ||
2218 | |||
2219 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWAP - wap/bssid %s", netdev->name, | ||
2220 | mac2str(ap_addr->sa_data)); | ||
2221 | |||
2222 | /* if the incoming address == ff:ff:ff:ff:ff:ff, the user has | ||
2223 | chosen any or auto AP preference */ | ||
2224 | if (is_broadcast_ether_addr(ap_addr->sa_data) | ||
2225 | || is_zero_ether_addr(ap_addr->sa_data)) | ||
2226 | priv->wanted_bssid_valid = 0; | ||
2227 | else { | ||
2228 | /* user wants to set a preferred AP address */ | ||
2229 | priv->wanted_bssid_valid = 1; | ||
2230 | memcpy(priv->wanted_bssid, ap_addr->sa_data, ETH_ALEN); | ||
2231 | } | ||
2232 | |||
2233 | return -EIWCOMMIT; | ||
2234 | } | ||
2235 | |||
2236 | static int at76_iw_handler_get_wap(struct net_device *netdev, | ||
2237 | struct iw_request_info *info, | ||
2238 | struct sockaddr *ap_addr, char *extra) | ||
2239 | { | ||
2240 | struct at76_priv *priv = netdev_priv(netdev); | ||
2241 | |||
2242 | ap_addr->sa_family = ARPHRD_ETHER; | ||
2243 | memcpy(ap_addr->sa_data, priv->bssid, ETH_ALEN); | ||
2244 | |||
2245 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWAP - wap/bssid %s", netdev->name, | ||
2246 | mac2str(ap_addr->sa_data)); | ||
2247 | |||
2248 | return 0; | ||
2249 | } | ||
2250 | |||
2251 | static int at76_iw_handler_set_scan(struct net_device *netdev, | ||
2252 | struct iw_request_info *info, | ||
2253 | union iwreq_data *wrqu, char *extra) | ||
2254 | { | ||
2255 | struct at76_priv *priv = netdev_priv(netdev); | ||
2256 | int ret = 0; | ||
2257 | |||
2258 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWSCAN", netdev->name); | ||
2259 | |||
2260 | if (mutex_lock_interruptible(&priv->mtx)) | ||
2261 | return -EINTR; | ||
2262 | |||
2263 | if (!netif_running(netdev)) { | ||
2264 | ret = -ENETDOWN; | ||
2265 | goto exit; | ||
2266 | } | ||
2267 | |||
2268 | /* jal: we don't allow "iwlist ethX scan" while we are | ||
2269 | in monitor mode */ | ||
2270 | if (priv->iw_mode == IW_MODE_MONITOR) { | ||
2271 | ret = -EBUSY; | ||
2272 | goto exit; | ||
2273 | } | ||
2274 | |||
2275 | /* Discard old scan results */ | ||
2276 | if ((jiffies - priv->last_scan) > (20 * HZ)) | ||
2277 | priv->scan_state = SCAN_IDLE; | ||
2278 | priv->last_scan = jiffies; | ||
2279 | |||
2280 | /* Initiate a scan command */ | ||
2281 | if (priv->scan_state == SCAN_IN_PROGRESS) { | ||
2282 | ret = -EBUSY; | ||
2283 | goto exit; | ||
2284 | } | ||
2285 | |||
2286 | priv->scan_state = SCAN_IN_PROGRESS; | ||
2287 | |||
2288 | at76_quiesce(priv); | ||
2289 | |||
2290 | /* Try to do passive or active scan if WE asks as. */ | ||
2291 | if (wrqu->data.length | ||
2292 | && wrqu->data.length == sizeof(struct iw_scan_req)) { | ||
2293 | struct iw_scan_req *req = (struct iw_scan_req *)extra; | ||
2294 | |||
2295 | if (req->scan_type == IW_SCAN_TYPE_PASSIVE) | ||
2296 | priv->scan_mode = SCAN_TYPE_PASSIVE; | ||
2297 | else if (req->scan_type == IW_SCAN_TYPE_ACTIVE) | ||
2298 | priv->scan_mode = SCAN_TYPE_ACTIVE; | ||
2299 | |||
2300 | /* Sanity check values? */ | ||
2301 | if (req->min_channel_time > 0) | ||
2302 | priv->scan_min_time = req->min_channel_time; | ||
2303 | |||
2304 | if (req->max_channel_time > 0) | ||
2305 | priv->scan_max_time = req->max_channel_time; | ||
2306 | } | ||
2307 | |||
2308 | /* change to scanning state */ | ||
2309 | at76_set_mac_state(priv, MAC_SCANNING); | ||
2310 | schedule_work(&priv->work_start_scan); | ||
2311 | |||
2312 | exit: | ||
2313 | mutex_unlock(&priv->mtx); | ||
2314 | return ret; | ||
2315 | } | ||
2316 | |||
2317 | static int at76_iw_handler_get_scan(struct net_device *netdev, | ||
2318 | struct iw_request_info *info, | ||
2319 | struct iw_point *data, char *extra) | ||
2320 | { | ||
2321 | struct at76_priv *priv = netdev_priv(netdev); | ||
2322 | unsigned long flags; | ||
2323 | struct list_head *lptr, *nptr; | ||
2324 | struct bss_info *curr_bss; | ||
2325 | struct iw_event *iwe = kmalloc(sizeof(struct iw_event), GFP_KERNEL); | ||
2326 | char *curr_val, *curr_pos = extra; | ||
2327 | int i; | ||
2328 | |||
2329 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWSCAN", netdev->name); | ||
2330 | |||
2331 | if (!iwe) | ||
2332 | return -ENOMEM; | ||
2333 | |||
2334 | if (priv->scan_state != SCAN_COMPLETED) { | ||
2335 | /* scan not yet finished */ | ||
2336 | kfree(iwe); | ||
2337 | return -EAGAIN; | ||
2338 | } | ||
2339 | |||
2340 | spin_lock_irqsave(&priv->bss_list_spinlock, flags); | ||
2341 | |||
2342 | list_for_each_safe(lptr, nptr, &priv->bss_list) { | ||
2343 | curr_bss = list_entry(lptr, struct bss_info, list); | ||
2344 | |||
2345 | iwe->cmd = SIOCGIWAP; | ||
2346 | iwe->u.ap_addr.sa_family = ARPHRD_ETHER; | ||
2347 | memcpy(iwe->u.ap_addr.sa_data, curr_bss->bssid, 6); | ||
2348 | curr_pos = iwe_stream_add_event(info, curr_pos, | ||
2349 | extra + IW_SCAN_MAX_DATA, iwe, | ||
2350 | IW_EV_ADDR_LEN); | ||
2351 | |||
2352 | iwe->u.data.length = curr_bss->ssid_len; | ||
2353 | iwe->cmd = SIOCGIWESSID; | ||
2354 | iwe->u.data.flags = 1; | ||
2355 | |||
2356 | curr_pos = iwe_stream_add_point(info, curr_pos, | ||
2357 | extra + IW_SCAN_MAX_DATA, iwe, | ||
2358 | curr_bss->ssid); | ||
2359 | |||
2360 | iwe->cmd = SIOCGIWMODE; | ||
2361 | iwe->u.mode = (curr_bss->capa & WLAN_CAPABILITY_IBSS) ? | ||
2362 | IW_MODE_ADHOC : | ||
2363 | (curr_bss->capa & WLAN_CAPABILITY_ESS) ? | ||
2364 | IW_MODE_MASTER : IW_MODE_AUTO; | ||
2365 | /* IW_MODE_AUTO = 0 which I thought is | ||
2366 | * the most logical value to return in this case */ | ||
2367 | curr_pos = iwe_stream_add_event(info, curr_pos, | ||
2368 | extra + IW_SCAN_MAX_DATA, iwe, | ||
2369 | IW_EV_UINT_LEN); | ||
2370 | |||
2371 | iwe->cmd = SIOCGIWFREQ; | ||
2372 | iwe->u.freq.m = curr_bss->channel; | ||
2373 | iwe->u.freq.e = 0; | ||
2374 | curr_pos = iwe_stream_add_event(info, curr_pos, | ||
2375 | extra + IW_SCAN_MAX_DATA, iwe, | ||
2376 | IW_EV_FREQ_LEN); | ||
2377 | |||
2378 | iwe->cmd = SIOCGIWENCODE; | ||
2379 | if (curr_bss->capa & WLAN_CAPABILITY_PRIVACY) | ||
2380 | iwe->u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | ||
2381 | else | ||
2382 | iwe->u.data.flags = IW_ENCODE_DISABLED; | ||
2383 | |||
2384 | iwe->u.data.length = 0; | ||
2385 | curr_pos = iwe_stream_add_point(info, curr_pos, | ||
2386 | extra + IW_SCAN_MAX_DATA, iwe, | ||
2387 | NULL); | ||
2388 | |||
2389 | /* Add quality statistics */ | ||
2390 | iwe->cmd = IWEVQUAL; | ||
2391 | iwe->u.qual.noise = 0; | ||
2392 | iwe->u.qual.updated = | ||
2393 | IW_QUAL_NOISE_INVALID | IW_QUAL_LEVEL_UPDATED; | ||
2394 | iwe->u.qual.level = (curr_bss->rssi * 100 / 42); | ||
2395 | if (iwe->u.qual.level > 100) | ||
2396 | iwe->u.qual.level = 100; | ||
2397 | if (at76_is_intersil(priv->board_type)) | ||
2398 | iwe->u.qual.qual = curr_bss->link_qual; | ||
2399 | else { | ||
2400 | iwe->u.qual.qual = 0; | ||
2401 | iwe->u.qual.updated |= IW_QUAL_QUAL_INVALID; | ||
2402 | } | ||
2403 | /* Add new value to event */ | ||
2404 | curr_pos = iwe_stream_add_event(info, curr_pos, | ||
2405 | extra + IW_SCAN_MAX_DATA, iwe, | ||
2406 | IW_EV_QUAL_LEN); | ||
2407 | |||
2408 | /* Rate: stuffing multiple values in a single event requires | ||
2409 | * a bit more of magic - Jean II */ | ||
2410 | curr_val = curr_pos + IW_EV_LCP_LEN; | ||
2411 | |||
2412 | iwe->cmd = SIOCGIWRATE; | ||
2413 | /* Those two flags are ignored... */ | ||
2414 | iwe->u.bitrate.fixed = 0; | ||
2415 | iwe->u.bitrate.disabled = 0; | ||
2416 | /* Max 8 values */ | ||
2417 | for (i = 0; i < curr_bss->rates_len; i++) { | ||
2418 | /* Bit rate given in 500 kb/s units (+ 0x80) */ | ||
2419 | iwe->u.bitrate.value = | ||
2420 | ((curr_bss->rates[i] & 0x7f) * 500000); | ||
2421 | /* Add new value to event */ | ||
2422 | curr_val = iwe_stream_add_value(info, curr_pos, | ||
2423 | curr_val, | ||
2424 | extra + | ||
2425 | IW_SCAN_MAX_DATA, iwe, | ||
2426 | IW_EV_PARAM_LEN); | ||
2427 | } | ||
2428 | |||
2429 | /* Check if we added any event */ | ||
2430 | if ((curr_val - curr_pos) > IW_EV_LCP_LEN) | ||
2431 | curr_pos = curr_val; | ||
2432 | |||
2433 | /* more information may be sent back using IWECUSTOM */ | ||
2434 | |||
2435 | } | ||
2436 | |||
2437 | spin_unlock_irqrestore(&priv->bss_list_spinlock, flags); | ||
2438 | |||
2439 | data->length = (curr_pos - extra); | ||
2440 | data->flags = 0; | ||
2441 | |||
2442 | kfree(iwe); | ||
2443 | return 0; | ||
2444 | } | ||
2445 | |||
2446 | static int at76_iw_handler_set_essid(struct net_device *netdev, | ||
2447 | struct iw_request_info *info, | ||
2448 | struct iw_point *data, char *extra) | ||
2449 | { | ||
2450 | struct at76_priv *priv = netdev_priv(netdev); | ||
2451 | |||
2452 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWESSID - %s", netdev->name, extra); | ||
2453 | |||
2454 | if (data->flags) { | ||
2455 | memcpy(priv->essid, extra, data->length); | ||
2456 | priv->essid_size = data->length; | ||
2457 | } else | ||
2458 | priv->essid_size = 0; /* Use any SSID */ | ||
2459 | |||
2460 | return -EIWCOMMIT; | ||
2461 | } | ||
2462 | |||
2463 | static int at76_iw_handler_get_essid(struct net_device *netdev, | ||
2464 | struct iw_request_info *info, | ||
2465 | struct iw_point *data, char *extra) | ||
2466 | { | ||
2467 | struct at76_priv *priv = netdev_priv(netdev); | ||
2468 | |||
2469 | if (priv->essid_size) { | ||
2470 | /* not the ANY ssid in priv->essid */ | ||
2471 | data->flags = 1; | ||
2472 | data->length = priv->essid_size; | ||
2473 | memcpy(extra, priv->essid, data->length); | ||
2474 | } else { | ||
2475 | /* the ANY ssid was specified */ | ||
2476 | if (priv->mac_state == MAC_CONNECTED && priv->curr_bss) { | ||
2477 | /* report the SSID we have found */ | ||
2478 | data->flags = 1; | ||
2479 | data->length = priv->curr_bss->ssid_len; | ||
2480 | memcpy(extra, priv->curr_bss->ssid, data->length); | ||
2481 | } else { | ||
2482 | /* report ANY back */ | ||
2483 | data->flags = 0; | ||
2484 | data->length = 0; | ||
2485 | } | ||
2486 | } | ||
2487 | |||
2488 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWESSID - %.*s", netdev->name, | ||
2489 | data->length, extra); | ||
2490 | |||
2491 | return 0; | ||
2492 | } | ||
2493 | |||
2494 | static int at76_iw_handler_set_rate(struct net_device *netdev, | ||
2495 | struct iw_request_info *info, | ||
2496 | struct iw_param *bitrate, char *extra) | ||
2497 | { | ||
2498 | struct at76_priv *priv = netdev_priv(netdev); | ||
2499 | int ret = -EIWCOMMIT; | ||
2500 | |||
2501 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWRATE - %d", netdev->name, | ||
2502 | bitrate->value); | ||
2503 | |||
2504 | switch (bitrate->value) { | ||
2505 | case -1: | ||
2506 | priv->txrate = TX_RATE_AUTO; | ||
2507 | break; /* auto rate */ | ||
2508 | case 1000000: | ||
2509 | priv->txrate = TX_RATE_1MBIT; | ||
2510 | break; | ||
2511 | case 2000000: | ||
2512 | priv->txrate = TX_RATE_2MBIT; | ||
2513 | break; | ||
2514 | case 5500000: | ||
2515 | priv->txrate = TX_RATE_5_5MBIT; | ||
2516 | break; | ||
2517 | case 11000000: | ||
2518 | priv->txrate = TX_RATE_11MBIT; | ||
2519 | break; | ||
2520 | default: | ||
2521 | ret = -EINVAL; | ||
2522 | } | ||
2523 | |||
2524 | return ret; | ||
2525 | } | ||
2526 | |||
2527 | static int at76_iw_handler_get_rate(struct net_device *netdev, | ||
2528 | struct iw_request_info *info, | ||
2529 | struct iw_param *bitrate, char *extra) | ||
2530 | { | ||
2531 | struct at76_priv *priv = netdev_priv(netdev); | ||
2532 | int ret = 0; | ||
2533 | |||
2534 | switch (priv->txrate) { | ||
2535 | /* return max rate if RATE_AUTO */ | ||
2536 | case TX_RATE_AUTO: | ||
2537 | bitrate->value = 11000000; | ||
2538 | break; | ||
2539 | case TX_RATE_1MBIT: | ||
2540 | bitrate->value = 1000000; | ||
2541 | break; | ||
2542 | case TX_RATE_2MBIT: | ||
2543 | bitrate->value = 2000000; | ||
2544 | break; | ||
2545 | case TX_RATE_5_5MBIT: | ||
2546 | bitrate->value = 5500000; | ||
2547 | break; | ||
2548 | case TX_RATE_11MBIT: | ||
2549 | bitrate->value = 11000000; | ||
2550 | break; | ||
2551 | default: | ||
2552 | ret = -EINVAL; | ||
2553 | } | ||
2554 | |||
2555 | bitrate->fixed = (priv->txrate != TX_RATE_AUTO); | ||
2556 | bitrate->disabled = 0; | ||
2557 | |||
2558 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWRATE - %d", netdev->name, | ||
2559 | bitrate->value); | ||
2560 | |||
2561 | return ret; | ||
2562 | } | ||
2563 | |||
2564 | static int at76_iw_handler_set_rts(struct net_device *netdev, | ||
2565 | struct iw_request_info *info, | ||
2566 | struct iw_param *rts, char *extra) | ||
2567 | { | ||
2568 | struct at76_priv *priv = netdev_priv(netdev); | ||
2569 | int ret = -EIWCOMMIT; | ||
2570 | int rthr = rts->value; | ||
2571 | |||
2572 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWRTS - value %d disabled %s", | ||
2573 | netdev->name, rts->value, (rts->disabled) ? "true" : "false"); | ||
2574 | |||
2575 | if (rts->disabled) | ||
2576 | rthr = MAX_RTS_THRESHOLD; | ||
2577 | |||
2578 | if ((rthr < 0) || (rthr > MAX_RTS_THRESHOLD)) | ||
2579 | ret = -EINVAL; | ||
2580 | else | ||
2581 | priv->rts_threshold = rthr; | ||
2582 | |||
2583 | return ret; | ||
2584 | } | ||
2585 | |||
2586 | static int at76_iw_handler_get_rts(struct net_device *netdev, | ||
2587 | struct iw_request_info *info, | ||
2588 | struct iw_param *rts, char *extra) | ||
2589 | { | ||
2590 | struct at76_priv *priv = netdev_priv(netdev); | ||
2591 | |||
2592 | rts->value = priv->rts_threshold; | ||
2593 | rts->disabled = (rts->value >= MAX_RTS_THRESHOLD); | ||
2594 | rts->fixed = 1; | ||
2595 | |||
2596 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWRTS - value %d disabled %s", | ||
2597 | netdev->name, rts->value, (rts->disabled) ? "true" : "false"); | ||
2598 | |||
2599 | return 0; | ||
2600 | } | ||
2601 | |||
2602 | static int at76_iw_handler_set_frag(struct net_device *netdev, | ||
2603 | struct iw_request_info *info, | ||
2604 | struct iw_param *frag, char *extra) | ||
2605 | { | ||
2606 | struct at76_priv *priv = netdev_priv(netdev); | ||
2607 | int ret = -EIWCOMMIT; | ||
2608 | int fthr = frag->value; | ||
2609 | |||
2610 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWFRAG - value %d, disabled %s", | ||
2611 | netdev->name, frag->value, | ||
2612 | (frag->disabled) ? "true" : "false"); | ||
2613 | |||
2614 | if (frag->disabled) | ||
2615 | fthr = MAX_FRAG_THRESHOLD; | ||
2616 | |||
2617 | if ((fthr < MIN_FRAG_THRESHOLD) || (fthr > MAX_FRAG_THRESHOLD)) | ||
2618 | ret = -EINVAL; | ||
2619 | else | ||
2620 | priv->frag_threshold = fthr & ~0x1; /* get an even value */ | ||
2621 | |||
2622 | return ret; | ||
2623 | } | ||
2624 | |||
2625 | static int at76_iw_handler_get_frag(struct net_device *netdev, | ||
2626 | struct iw_request_info *info, | ||
2627 | struct iw_param *frag, char *extra) | ||
2628 | { | ||
2629 | struct at76_priv *priv = netdev_priv(netdev); | ||
2630 | |||
2631 | frag->value = priv->frag_threshold; | ||
2632 | frag->disabled = (frag->value >= MAX_FRAG_THRESHOLD); | ||
2633 | frag->fixed = 1; | ||
2634 | |||
2635 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWFRAG - value %d, disabled %s", | ||
2636 | netdev->name, frag->value, | ||
2637 | (frag->disabled) ? "true" : "false"); | ||
2638 | |||
2639 | return 0; | ||
2640 | } | ||
2641 | |||
2642 | static int at76_iw_handler_get_txpow(struct net_device *netdev, | ||
2643 | struct iw_request_info *info, | ||
2644 | struct iw_param *power, char *extra) | ||
2645 | { | ||
2646 | power->value = 15; | ||
2647 | power->fixed = 1; /* No power control */ | ||
2648 | power->disabled = 0; | ||
2649 | power->flags = IW_TXPOW_DBM; | ||
2650 | |||
2651 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWTXPOW - txpow %d dBm", netdev->name, | ||
2652 | power->value); | ||
2653 | |||
2654 | return 0; | ||
2655 | } | ||
2656 | |||
2657 | /* jal: short retry is handled by the firmware (at least 0.90.x), | ||
2658 | while long retry is not (?) */ | ||
2659 | static int at76_iw_handler_set_retry(struct net_device *netdev, | ||
2660 | struct iw_request_info *info, | ||
2661 | struct iw_param *retry, char *extra) | ||
2662 | { | ||
2663 | struct at76_priv *priv = netdev_priv(netdev); | ||
2664 | int ret = -EIWCOMMIT; | ||
2665 | |||
2666 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWRETRY disabled %d flags 0x%x val %d", | ||
2667 | netdev->name, retry->disabled, retry->flags, retry->value); | ||
2668 | |||
2669 | if (!retry->disabled && (retry->flags & IW_RETRY_LIMIT)) { | ||
2670 | if ((retry->flags & IW_RETRY_MIN) || | ||
2671 | !(retry->flags & IW_RETRY_MAX)) | ||
2672 | priv->short_retry_limit = retry->value; | ||
2673 | else | ||
2674 | ret = -EINVAL; | ||
2675 | } else | ||
2676 | ret = -EINVAL; | ||
2677 | |||
2678 | return ret; | ||
2679 | } | ||
2680 | |||
2681 | /* Adapted (ripped) from atmel.c */ | ||
2682 | static int at76_iw_handler_get_retry(struct net_device *netdev, | ||
2683 | struct iw_request_info *info, | ||
2684 | struct iw_param *retry, char *extra) | ||
2685 | { | ||
2686 | struct at76_priv *priv = netdev_priv(netdev); | ||
2687 | |||
2688 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWRETRY", netdev->name); | ||
2689 | |||
2690 | retry->disabled = 0; /* Can't be disabled */ | ||
2691 | retry->flags = IW_RETRY_LIMIT; | ||
2692 | retry->value = priv->short_retry_limit; | ||
2693 | |||
2694 | return 0; | ||
2695 | } | ||
2696 | |||
2697 | static int at76_iw_handler_set_encode(struct net_device *netdev, | ||
2698 | struct iw_request_info *info, | ||
2699 | struct iw_point *encoding, char *extra) | ||
2700 | { | ||
2701 | struct at76_priv *priv = netdev_priv(netdev); | ||
2702 | int index = (encoding->flags & IW_ENCODE_INDEX) - 1; | ||
2703 | int len = encoding->length; | ||
2704 | |||
2705 | at76_dbg(DBG_IOCTL, "%s: SIOCSIWENCODE - enc.flags %08x " | ||
2706 | "pointer %p len %d", netdev->name, encoding->flags, | ||
2707 | encoding->pointer, encoding->length); | ||
2708 | at76_dbg(DBG_IOCTL, | ||
2709 | "%s: SIOCSIWENCODE - old wepstate: enabled %s key_id %d " | ||
2710 | "auth_mode %s", netdev->name, | ||
2711 | (priv->wep_enabled) ? "true" : "false", priv->wep_key_id, | ||
2712 | (priv->auth_mode == | ||
2713 | WLAN_AUTH_SHARED_KEY) ? "restricted" : "open"); | ||
2714 | |||
2715 | /* take the old default key if index is invalid */ | ||
2716 | if ((index < 0) || (index >= WEP_KEYS)) | ||
2717 | index = priv->wep_key_id; | ||
2718 | |||
2719 | if (len > 0) { | ||
2720 | if (len > WEP_LARGE_KEY_LEN) | ||
2721 | len = WEP_LARGE_KEY_LEN; | ||
2722 | |||
2723 | memset(priv->wep_keys[index], 0, WEP_KEY_LEN); | ||
2724 | memcpy(priv->wep_keys[index], extra, len); | ||
2725 | priv->wep_keys_len[index] = (len <= WEP_SMALL_KEY_LEN) ? | ||
2726 | WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN; | ||
2727 | priv->wep_enabled = 1; | ||
2728 | } | ||
2729 | |||
2730 | priv->wep_key_id = index; | ||
2731 | priv->wep_enabled = ((encoding->flags & IW_ENCODE_DISABLED) == 0); | ||
2732 | |||
2733 | if (encoding->flags & IW_ENCODE_RESTRICTED) | ||
2734 | priv->auth_mode = WLAN_AUTH_SHARED_KEY; | ||
2735 | if (encoding->flags & IW_ENCODE_OPEN) | ||
2736 | priv->auth_mode = WLAN_AUTH_OPEN; | ||
2737 | |||
2738 | at76_dbg(DBG_IOCTL, | ||
2739 | "%s: SIOCSIWENCODE - new wepstate: enabled %s key_id %d " | ||
2740 | "key_len %d auth_mode %s", netdev->name, | ||
2741 | (priv->wep_enabled) ? "true" : "false", priv->wep_key_id + 1, | ||
2742 | priv->wep_keys_len[priv->wep_key_id], | ||
2743 | (priv->auth_mode == | ||
2744 | WLAN_AUTH_SHARED_KEY) ? "restricted" : "open"); | ||
2745 | |||
2746 | return -EIWCOMMIT; | ||
2747 | } | ||
2748 | |||
2749 | static int at76_iw_handler_get_encode(struct net_device *netdev, | ||
2750 | struct iw_request_info *info, | ||
2751 | struct iw_point *encoding, char *extra) | ||
2752 | { | ||
2753 | struct at76_priv *priv = netdev_priv(netdev); | ||
2754 | int index = (encoding->flags & IW_ENCODE_INDEX) - 1; | ||
2755 | |||
2756 | if ((index < 0) || (index >= WEP_KEYS)) | ||
2757 | index = priv->wep_key_id; | ||
2758 | |||
2759 | encoding->flags = | ||
2760 | (priv->auth_mode == WLAN_AUTH_SHARED_KEY) ? | ||
2761 | IW_ENCODE_RESTRICTED : IW_ENCODE_OPEN; | ||
2762 | |||
2763 | if (!priv->wep_enabled) | ||
2764 | encoding->flags |= IW_ENCODE_DISABLED; | ||
2765 | |||
2766 | if (encoding->pointer) { | ||
2767 | encoding->length = priv->wep_keys_len[index]; | ||
2768 | |||
2769 | memcpy(extra, priv->wep_keys[index], priv->wep_keys_len[index]); | ||
2770 | |||
2771 | encoding->flags |= (index + 1); | ||
2772 | } | ||
2773 | |||
2774 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWENCODE - enc.flags %08x " | ||
2775 | "pointer %p len %d", netdev->name, encoding->flags, | ||
2776 | encoding->pointer, encoding->length); | ||
2777 | at76_dbg(DBG_IOCTL, | ||
2778 | "%s: SIOCGIWENCODE - wepstate: enabled %s key_id %d " | ||
2779 | "key_len %d auth_mode %s", netdev->name, | ||
2780 | (priv->wep_enabled) ? "true" : "false", priv->wep_key_id + 1, | ||
2781 | priv->wep_keys_len[priv->wep_key_id], | ||
2782 | (priv->auth_mode == | ||
2783 | WLAN_AUTH_SHARED_KEY) ? "restricted" : "open"); | ||
2784 | |||
2785 | return 0; | ||
2786 | } | ||
2787 | |||
2788 | static int at76_iw_handler_set_power(struct net_device *netdev, | ||
2789 | struct iw_request_info *info, | ||
2790 | struct iw_param *prq, char *extra) | ||
2791 | { | ||
2792 | int err = -EIWCOMMIT; | ||
2793 | struct at76_priv *priv = netdev_priv(netdev); | ||
2794 | |||
2795 | at76_dbg(DBG_IOCTL, | ||
2796 | "%s: SIOCSIWPOWER - disabled %s flags 0x%x value 0x%x", | ||
2797 | netdev->name, (prq->disabled) ? "true" : "false", prq->flags, | ||
2798 | prq->value); | ||
2799 | |||
2800 | if (prq->disabled) | ||
2801 | priv->pm_mode = AT76_PM_OFF; | ||
2802 | else { | ||
2803 | switch (prq->flags & IW_POWER_MODE) { | ||
2804 | case IW_POWER_ALL_R: | ||
2805 | case IW_POWER_ON: | ||
2806 | break; | ||
2807 | default: | ||
2808 | err = -EINVAL; | ||
2809 | goto exit; | ||
2810 | } | ||
2811 | if (prq->flags & IW_POWER_PERIOD) | ||
2812 | priv->pm_period = prq->value; | ||
2813 | |||
2814 | if (prq->flags & IW_POWER_TIMEOUT) { | ||
2815 | err = -EINVAL; | ||
2816 | goto exit; | ||
2817 | } | ||
2818 | priv->pm_mode = AT76_PM_ON; | ||
2819 | } | ||
2820 | exit: | ||
2821 | return err; | ||
2822 | } | ||
2823 | |||
2824 | static int at76_iw_handler_get_power(struct net_device *netdev, | ||
2825 | struct iw_request_info *info, | ||
2826 | struct iw_param *power, char *extra) | ||
2827 | { | ||
2828 | struct at76_priv *priv = netdev_priv(netdev); | ||
2829 | |||
2830 | power->disabled = (priv->pm_mode == AT76_PM_OFF); | ||
2831 | if (!power->disabled) { | ||
2832 | power->flags = IW_POWER_PERIOD | IW_POWER_ALL_R; | ||
2833 | power->value = priv->pm_period; | ||
2834 | } | ||
2835 | |||
2836 | at76_dbg(DBG_IOCTL, "%s: SIOCGIWPOWER - %s flags 0x%x value 0x%x", | ||
2837 | netdev->name, power->disabled ? "disabled" : "enabled", | ||
2838 | power->flags, power->value); | ||
2839 | |||
2840 | return 0; | ||
2841 | } | ||
2842 | |||
2843 | /******************************************************************************* | ||
2844 | * Private IOCTLS | ||
2845 | */ | ||
2846 | static int at76_iw_set_short_preamble(struct net_device *netdev, | ||
2847 | struct iw_request_info *info, char *name, | ||
2848 | char *extra) | ||
2849 | { | ||
2850 | struct at76_priv *priv = netdev_priv(netdev); | ||
2851 | int val = *((int *)name); | ||
2852 | int ret = -EIWCOMMIT; | ||
2853 | |||
2854 | at76_dbg(DBG_IOCTL, "%s: AT76_SET_SHORT_PREAMBLE, %d", | ||
2855 | netdev->name, val); | ||
2856 | |||
2857 | if (val < PREAMBLE_TYPE_LONG || val > PREAMBLE_TYPE_AUTO) | ||
2858 | ret = -EINVAL; | ||
2859 | else | ||
2860 | priv->preamble_type = val; | ||
2861 | |||
2862 | return ret; | ||
2863 | } | ||
2864 | |||
2865 | static int at76_iw_get_short_preamble(struct net_device *netdev, | ||
2866 | struct iw_request_info *info, | ||
2867 | union iwreq_data *wrqu, char *extra) | ||
2868 | { | ||
2869 | struct at76_priv *priv = netdev_priv(netdev); | ||
2870 | |||
2871 | snprintf(wrqu->name, sizeof(wrqu->name), "%s (%d)", | ||
2872 | preambles[priv->preamble_type], priv->preamble_type); | ||
2873 | return 0; | ||
2874 | } | ||
2875 | |||
2876 | static int at76_iw_set_debug(struct net_device *netdev, | ||
2877 | struct iw_request_info *info, | ||
2878 | struct iw_point *data, char *extra) | ||
2879 | { | ||
2880 | char *ptr; | ||
2881 | u32 val; | ||
2882 | |||
2883 | if (data->length > 0) { | ||
2884 | val = simple_strtol(extra, &ptr, 0); | ||
2885 | |||
2886 | if (ptr == extra) | ||
2887 | val = DBG_DEFAULTS; | ||
2888 | |||
2889 | at76_dbg(DBG_IOCTL, "%s: AT76_SET_DEBUG input %d: %s -> 0x%x", | ||
2890 | netdev->name, data->length, extra, val); | ||
2891 | } else | ||
2892 | val = DBG_DEFAULTS; | ||
2893 | |||
2894 | at76_dbg(DBG_IOCTL, "%s: AT76_SET_DEBUG, old 0x%x, new 0x%x", | ||
2895 | netdev->name, at76_debug, val); | ||
2896 | |||
2897 | /* jal: some more output to pin down lockups */ | ||
2898 | at76_dbg(DBG_IOCTL, "%s: netif running %d queue_stopped %d " | ||
2899 | "carrier_ok %d", netdev->name, netif_running(netdev), | ||
2900 | netif_queue_stopped(netdev), netif_carrier_ok(netdev)); | ||
2901 | |||
2902 | at76_debug = val; | ||
2903 | |||
2904 | return 0; | ||
2905 | } | ||
2906 | |||
2907 | static int at76_iw_get_debug(struct net_device *netdev, | ||
2908 | struct iw_request_info *info, | ||
2909 | union iwreq_data *wrqu, char *extra) | ||
2910 | { | ||
2911 | snprintf(wrqu->name, sizeof(wrqu->name), "0x%08x", at76_debug); | ||
2912 | return 0; | ||
2913 | } | ||
2914 | |||
2915 | static int at76_iw_set_powersave_mode(struct net_device *netdev, | ||
2916 | struct iw_request_info *info, char *name, | ||
2917 | char *extra) | ||
2918 | { | ||
2919 | struct at76_priv *priv = netdev_priv(netdev); | ||
2920 | int val = *((int *)name); | ||
2921 | int ret = -EIWCOMMIT; | ||
2922 | |||
2923 | at76_dbg(DBG_IOCTL, "%s: AT76_SET_POWERSAVE_MODE, %d (%s)", | ||
2924 | netdev->name, val, | ||
2925 | val == AT76_PM_OFF ? "active" : val == AT76_PM_ON ? "save" : | ||
2926 | val == AT76_PM_SMART ? "smart save" : "<invalid>"); | ||
2927 | if (val < AT76_PM_OFF || val > AT76_PM_SMART) | ||
2928 | ret = -EINVAL; | ||
2929 | else | ||
2930 | priv->pm_mode = val; | ||
2931 | |||
2932 | return ret; | ||
2933 | } | ||
2934 | |||
2935 | static int at76_iw_get_powersave_mode(struct net_device *netdev, | ||
2936 | struct iw_request_info *info, | ||
2937 | union iwreq_data *wrqu, char *extra) | ||
2938 | { | ||
2939 | struct at76_priv *priv = netdev_priv(netdev); | ||
2940 | int *param = (int *)extra; | ||
2941 | |||
2942 | param[0] = priv->pm_mode; | ||
2943 | return 0; | ||
2944 | } | ||
2945 | |||
2946 | static int at76_iw_set_scan_times(struct net_device *netdev, | ||
2947 | struct iw_request_info *info, char *name, | ||
2948 | char *extra) | ||
2949 | { | ||
2950 | struct at76_priv *priv = netdev_priv(netdev); | ||
2951 | int mint = *((int *)name); | ||
2952 | int maxt = *((int *)name + 1); | ||
2953 | int ret = -EIWCOMMIT; | ||
2954 | |||
2955 | at76_dbg(DBG_IOCTL, "%s: AT76_SET_SCAN_TIMES - min %d max %d", | ||
2956 | netdev->name, mint, maxt); | ||
2957 | if (mint <= 0 || maxt <= 0 || mint > maxt) | ||
2958 | ret = -EINVAL; | ||
2959 | else { | ||
2960 | priv->scan_min_time = mint; | ||
2961 | priv->scan_max_time = maxt; | ||
2962 | } | ||
2963 | |||
2964 | return ret; | ||
2965 | } | ||
2966 | |||
2967 | static int at76_iw_get_scan_times(struct net_device *netdev, | ||
2968 | struct iw_request_info *info, | ||
2969 | union iwreq_data *wrqu, char *extra) | ||
2970 | { | ||
2971 | struct at76_priv *priv = netdev_priv(netdev); | ||
2972 | int *param = (int *)extra; | ||
2973 | |||
2974 | param[0] = priv->scan_min_time; | ||
2975 | param[1] = priv->scan_max_time; | ||
2976 | return 0; | ||
2977 | } | ||
2978 | |||
2979 | static int at76_iw_set_scan_mode(struct net_device *netdev, | ||
2980 | struct iw_request_info *info, char *name, | ||
2981 | char *extra) | ||
2982 | { | ||
2983 | struct at76_priv *priv = netdev_priv(netdev); | ||
2984 | int val = *((int *)name); | ||
2985 | int ret = -EIWCOMMIT; | ||
2986 | |||
2987 | at76_dbg(DBG_IOCTL, "%s: AT76_SET_SCAN_MODE - mode %s", | ||
2988 | netdev->name, (val = SCAN_TYPE_ACTIVE) ? "active" : | ||
2989 | (val = SCAN_TYPE_PASSIVE) ? "passive" : "<invalid>"); | ||
2990 | |||
2991 | if (val != SCAN_TYPE_ACTIVE && val != SCAN_TYPE_PASSIVE) | ||
2992 | ret = -EINVAL; | ||
2993 | else | ||
2994 | priv->scan_mode = val; | ||
2995 | |||
2996 | return ret; | ||
2997 | } | ||
2998 | |||
2999 | static int at76_iw_get_scan_mode(struct net_device *netdev, | ||
3000 | struct iw_request_info *info, | ||
3001 | union iwreq_data *wrqu, char *extra) | ||
3002 | { | ||
3003 | struct at76_priv *priv = netdev_priv(netdev); | ||
3004 | int *param = (int *)extra; | ||
3005 | |||
3006 | param[0] = priv->scan_mode; | ||
3007 | return 0; | ||
3008 | } | ||
3009 | |||
3010 | #define AT76_SET_HANDLER(h, f) [h - SIOCIWFIRST] = (iw_handler) f | ||
3011 | |||
3012 | /* Standard wireless handlers */ | ||
3013 | static const iw_handler at76_handlers[] = { | ||
3014 | AT76_SET_HANDLER(SIOCSIWCOMMIT, at76_iw_handler_commit), | ||
3015 | AT76_SET_HANDLER(SIOCGIWNAME, at76_iw_handler_get_name), | ||
3016 | AT76_SET_HANDLER(SIOCSIWFREQ, at76_iw_handler_set_freq), | ||
3017 | AT76_SET_HANDLER(SIOCGIWFREQ, at76_iw_handler_get_freq), | ||
3018 | AT76_SET_HANDLER(SIOCSIWMODE, at76_iw_handler_set_mode), | ||
3019 | AT76_SET_HANDLER(SIOCGIWMODE, at76_iw_handler_get_mode), | ||
3020 | AT76_SET_HANDLER(SIOCGIWRANGE, at76_iw_handler_get_range), | ||
3021 | AT76_SET_HANDLER(SIOCSIWSPY, at76_iw_handler_set_spy), | ||
3022 | AT76_SET_HANDLER(SIOCGIWSPY, at76_iw_handler_get_spy), | ||
3023 | AT76_SET_HANDLER(SIOCSIWTHRSPY, at76_iw_handler_set_thrspy), | ||
3024 | AT76_SET_HANDLER(SIOCGIWTHRSPY, at76_iw_handler_get_thrspy), | ||
3025 | AT76_SET_HANDLER(SIOCSIWAP, at76_iw_handler_set_wap), | ||
3026 | AT76_SET_HANDLER(SIOCGIWAP, at76_iw_handler_get_wap), | ||
3027 | AT76_SET_HANDLER(SIOCSIWSCAN, at76_iw_handler_set_scan), | ||
3028 | AT76_SET_HANDLER(SIOCGIWSCAN, at76_iw_handler_get_scan), | ||
3029 | AT76_SET_HANDLER(SIOCSIWESSID, at76_iw_handler_set_essid), | ||
3030 | AT76_SET_HANDLER(SIOCGIWESSID, at76_iw_handler_get_essid), | ||
3031 | AT76_SET_HANDLER(SIOCSIWRATE, at76_iw_handler_set_rate), | ||
3032 | AT76_SET_HANDLER(SIOCGIWRATE, at76_iw_handler_get_rate), | ||
3033 | AT76_SET_HANDLER(SIOCSIWRTS, at76_iw_handler_set_rts), | ||
3034 | AT76_SET_HANDLER(SIOCGIWRTS, at76_iw_handler_get_rts), | ||
3035 | AT76_SET_HANDLER(SIOCSIWFRAG, at76_iw_handler_set_frag), | ||
3036 | AT76_SET_HANDLER(SIOCGIWFRAG, at76_iw_handler_get_frag), | ||
3037 | AT76_SET_HANDLER(SIOCGIWTXPOW, at76_iw_handler_get_txpow), | ||
3038 | AT76_SET_HANDLER(SIOCSIWRETRY, at76_iw_handler_set_retry), | ||
3039 | AT76_SET_HANDLER(SIOCGIWRETRY, at76_iw_handler_get_retry), | ||
3040 | AT76_SET_HANDLER(SIOCSIWENCODE, at76_iw_handler_set_encode), | ||
3041 | AT76_SET_HANDLER(SIOCGIWENCODE, at76_iw_handler_get_encode), | ||
3042 | AT76_SET_HANDLER(SIOCSIWPOWER, at76_iw_handler_set_power), | ||
3043 | AT76_SET_HANDLER(SIOCGIWPOWER, at76_iw_handler_get_power) | ||
3044 | }; | ||
3045 | |||
3046 | #define AT76_SET_PRIV(h, f) [h - SIOCIWFIRSTPRIV] = (iw_handler) f | ||
3047 | |||
3048 | /* Private wireless handlers */ | ||
3049 | static const iw_handler at76_priv_handlers[] = { | ||
3050 | AT76_SET_PRIV(AT76_SET_SHORT_PREAMBLE, at76_iw_set_short_preamble), | ||
3051 | AT76_SET_PRIV(AT76_GET_SHORT_PREAMBLE, at76_iw_get_short_preamble), | ||
3052 | AT76_SET_PRIV(AT76_SET_DEBUG, at76_iw_set_debug), | ||
3053 | AT76_SET_PRIV(AT76_GET_DEBUG, at76_iw_get_debug), | ||
3054 | AT76_SET_PRIV(AT76_SET_POWERSAVE_MODE, at76_iw_set_powersave_mode), | ||
3055 | AT76_SET_PRIV(AT76_GET_POWERSAVE_MODE, at76_iw_get_powersave_mode), | ||
3056 | AT76_SET_PRIV(AT76_SET_SCAN_TIMES, at76_iw_set_scan_times), | ||
3057 | AT76_SET_PRIV(AT76_GET_SCAN_TIMES, at76_iw_get_scan_times), | ||
3058 | AT76_SET_PRIV(AT76_SET_SCAN_MODE, at76_iw_set_scan_mode), | ||
3059 | AT76_SET_PRIV(AT76_GET_SCAN_MODE, at76_iw_get_scan_mode), | ||
3060 | }; | ||
3061 | |||
3062 | /* Names and arguments of private wireless handlers */ | ||
3063 | static const struct iw_priv_args at76_priv_args[] = { | ||
3064 | /* 0 - long, 1 - short */ | ||
3065 | {AT76_SET_SHORT_PREAMBLE, | ||
3066 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"}, | ||
3067 | |||
3068 | {AT76_GET_SHORT_PREAMBLE, | ||
3069 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 10, "get_preamble"}, | ||
3070 | |||
3071 | /* we must pass the new debug mask as a string, because iwpriv cannot | ||
3072 | * parse hex numbers starting with 0x :-( */ | ||
3073 | {AT76_SET_DEBUG, | ||
3074 | IW_PRIV_TYPE_CHAR | 10, 0, "set_debug"}, | ||
3075 | |||
3076 | {AT76_GET_DEBUG, | ||
3077 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 10, "get_debug"}, | ||
3078 | |||
3079 | /* 1 - active, 2 - power save, 3 - smart power save */ | ||
3080 | {AT76_SET_POWERSAVE_MODE, | ||
3081 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_powersave"}, | ||
3082 | |||
3083 | {AT76_GET_POWERSAVE_MODE, | ||
3084 | 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_powersave"}, | ||
3085 | |||
3086 | /* min_channel_time, max_channel_time */ | ||
3087 | {AT76_SET_SCAN_TIMES, | ||
3088 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_scan_times"}, | ||
3089 | |||
3090 | {AT76_GET_SCAN_TIMES, | ||
3091 | 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, "get_scan_times"}, | ||
3092 | |||
3093 | /* 0 - active, 1 - passive scan */ | ||
3094 | {AT76_SET_SCAN_MODE, | ||
3095 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_scan_mode"}, | ||
3096 | |||
3097 | {AT76_GET_SCAN_MODE, | ||
3098 | 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_scan_mode"}, | ||
3099 | }; | ||
3100 | |||
3101 | static const struct iw_handler_def at76_handler_def = { | ||
3102 | .num_standard = ARRAY_SIZE(at76_handlers), | ||
3103 | .num_private = ARRAY_SIZE(at76_priv_handlers), | ||
3104 | .num_private_args = ARRAY_SIZE(at76_priv_args), | ||
3105 | .standard = at76_handlers, | ||
3106 | .private = at76_priv_handlers, | ||
3107 | .private_args = at76_priv_args, | ||
3108 | .get_wireless_stats = at76_get_wireless_stats, | ||
3109 | }; | ||
3110 | |||
3111 | static const u8 snapsig[] = { 0xaa, 0xaa, 0x03 }; | ||
3112 | |||
3113 | /* RFC 1042 encapsulates Ethernet frames in 802.2 SNAP (0xaa, 0xaa, 0x03) with | ||
3114 | * a SNAP OID of 0 (0x00, 0x00, 0x00) */ | ||
3115 | static const u8 rfc1042sig[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | ||
3116 | |||
3117 | static int at76_tx(struct sk_buff *skb, struct net_device *netdev) | ||
3118 | { | ||
3119 | struct at76_priv *priv = netdev_priv(netdev); | ||
3120 | struct net_device_stats *stats = &priv->stats; | ||
3121 | int ret = 0; | ||
3122 | int wlen; | ||
3123 | int submit_len; | ||
3124 | struct at76_tx_buffer *tx_buffer = priv->bulk_out_buffer; | ||
3125 | struct ieee80211_hdr_3addr *i802_11_hdr = | ||
3126 | (struct ieee80211_hdr_3addr *)tx_buffer->packet; | ||
3127 | u8 *payload = i802_11_hdr->payload; | ||
3128 | struct ethhdr *eh = (struct ethhdr *)skb->data; | ||
3129 | |||
3130 | if (netif_queue_stopped(netdev)) { | ||
3131 | printk(KERN_ERR "%s: %s called while netdev is stopped\n", | ||
3132 | netdev->name, __func__); | ||
3133 | /* skip this packet */ | ||
3134 | dev_kfree_skb(skb); | ||
3135 | return 0; | ||
3136 | } | ||
3137 | |||
3138 | if (priv->tx_urb->status == -EINPROGRESS) { | ||
3139 | printk(KERN_ERR "%s: %s called while tx urb is pending\n", | ||
3140 | netdev->name, __func__); | ||
3141 | /* skip this packet */ | ||
3142 | dev_kfree_skb(skb); | ||
3143 | return 0; | ||
3144 | } | ||
3145 | |||
3146 | if (skb->len < ETH_HLEN) { | ||
3147 | printk(KERN_ERR "%s: %s: skb too short (%d)\n", | ||
3148 | netdev->name, __func__, skb->len); | ||
3149 | dev_kfree_skb(skb); | ||
3150 | return 0; | ||
3151 | } | ||
3152 | |||
3153 | at76_ledtrig_tx_activity(); /* tell ledtrigger we send a packet */ | ||
3154 | |||
3155 | /* we can get rid of memcpy if we set netdev->hard_header_len to | ||
3156 | reserve enough space, but we would need to keep the skb around */ | ||
3157 | |||
3158 | if (ntohs(eh->h_proto) <= ETH_DATA_LEN) { | ||
3159 | /* this is a 802.3 packet */ | ||
3160 | if (skb->len >= ETH_HLEN + sizeof(rfc1042sig) | ||
3161 | && skb->data[ETH_HLEN] == rfc1042sig[0] | ||
3162 | && skb->data[ETH_HLEN + 1] == rfc1042sig[1]) { | ||
3163 | /* higher layer delivered SNAP header - keep it */ | ||
3164 | memcpy(payload, skb->data + ETH_HLEN, | ||
3165 | skb->len - ETH_HLEN); | ||
3166 | wlen = IEEE80211_3ADDR_LEN + skb->len - ETH_HLEN; | ||
3167 | } else { | ||
3168 | printk(KERN_ERR "%s: dropping non-SNAP 802.2 packet " | ||
3169 | "(DSAP 0x%02x SSAP 0x%02x cntrl 0x%02x)\n", | ||
3170 | priv->netdev->name, skb->data[ETH_HLEN], | ||
3171 | skb->data[ETH_HLEN + 1], | ||
3172 | skb->data[ETH_HLEN + 2]); | ||
3173 | dev_kfree_skb(skb); | ||
3174 | return 0; | ||
3175 | } | ||
3176 | } else { | ||
3177 | /* add RFC 1042 header in front */ | ||
3178 | memcpy(payload, rfc1042sig, sizeof(rfc1042sig)); | ||
3179 | memcpy(payload + sizeof(rfc1042sig), &eh->h_proto, | ||
3180 | skb->len - offsetof(struct ethhdr, h_proto)); | ||
3181 | wlen = IEEE80211_3ADDR_LEN + sizeof(rfc1042sig) + skb->len - | ||
3182 | offsetof(struct ethhdr, h_proto); | ||
3183 | } | ||
3184 | |||
3185 | /* make wireless header */ | ||
3186 | i802_11_hdr->frame_ctl = | ||
3187 | cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
3188 | (priv->wep_enabled ? IEEE80211_FCTL_PROTECTED : 0) | | ||
3189 | (priv->iw_mode == | ||
3190 | IW_MODE_INFRA ? IEEE80211_FCTL_TODS : 0)); | ||
3191 | |||
3192 | if (priv->iw_mode == IW_MODE_ADHOC) { | ||
3193 | memcpy(i802_11_hdr->addr1, eh->h_dest, ETH_ALEN); | ||
3194 | memcpy(i802_11_hdr->addr2, eh->h_source, ETH_ALEN); | ||
3195 | memcpy(i802_11_hdr->addr3, priv->bssid, ETH_ALEN); | ||
3196 | } else if (priv->iw_mode == IW_MODE_INFRA) { | ||
3197 | memcpy(i802_11_hdr->addr1, priv->bssid, ETH_ALEN); | ||
3198 | memcpy(i802_11_hdr->addr2, eh->h_source, ETH_ALEN); | ||
3199 | memcpy(i802_11_hdr->addr3, eh->h_dest, ETH_ALEN); | ||
3200 | } | ||
3201 | |||
3202 | i802_11_hdr->duration_id = cpu_to_le16(0); | ||
3203 | i802_11_hdr->seq_ctl = cpu_to_le16(0); | ||
3204 | |||
3205 | /* setup 'Atmel' header */ | ||
3206 | tx_buffer->wlength = cpu_to_le16(wlen); | ||
3207 | tx_buffer->tx_rate = priv->txrate; | ||
3208 | /* for broadcast destination addresses, the firmware 0.100.x | ||
3209 | seems to choose the highest rate set with CMD_STARTUP in | ||
3210 | basic_rate_set replacing this value */ | ||
3211 | |||
3212 | memset(tx_buffer->reserved, 0, sizeof(tx_buffer->reserved)); | ||
3213 | |||
3214 | tx_buffer->padding = at76_calc_padding(wlen); | ||
3215 | submit_len = wlen + AT76_TX_HDRLEN + tx_buffer->padding; | ||
3216 | |||
3217 | at76_dbg(DBG_TX_DATA_CONTENT, "%s skb->data %s", priv->netdev->name, | ||
3218 | hex2str(skb->data, 32)); | ||
3219 | at76_dbg(DBG_TX_DATA, "%s tx: wlen 0x%x pad 0x%x rate %d hdr %s", | ||
3220 | priv->netdev->name, | ||
3221 | le16_to_cpu(tx_buffer->wlength), | ||
3222 | tx_buffer->padding, tx_buffer->tx_rate, | ||
3223 | hex2str(i802_11_hdr, sizeof(*i802_11_hdr))); | ||
3224 | at76_dbg(DBG_TX_DATA_CONTENT, "%s payload %s", priv->netdev->name, | ||
3225 | hex2str(payload, 48)); | ||
3226 | |||
3227 | /* send stuff */ | ||
3228 | netif_stop_queue(netdev); | ||
3229 | netdev->trans_start = jiffies; | ||
3230 | |||
3231 | usb_fill_bulk_urb(priv->tx_urb, priv->udev, priv->tx_pipe, tx_buffer, | ||
3232 | submit_len, at76_tx_callback, priv); | ||
3233 | ret = usb_submit_urb(priv->tx_urb, GFP_ATOMIC); | ||
3234 | if (ret) { | ||
3235 | stats->tx_errors++; | ||
3236 | printk(KERN_ERR "%s: error in tx submit urb: %d\n", | ||
3237 | netdev->name, ret); | ||
3238 | if (ret == -EINVAL) | ||
3239 | printk(KERN_ERR | ||
3240 | "%s: -EINVAL: tx urb %p hcpriv %p complete %p\n", | ||
3241 | priv->netdev->name, priv->tx_urb, | ||
3242 | priv->tx_urb->hcpriv, priv->tx_urb->complete); | ||
3243 | } else { | ||
3244 | stats->tx_bytes += skb->len; | ||
3245 | dev_kfree_skb(skb); | ||
3246 | } | ||
3247 | |||
3248 | return ret; | ||
3249 | } | ||
3250 | |||
3251 | static void at76_tx_timeout(struct net_device *netdev) | ||
3252 | { | ||
3253 | struct at76_priv *priv = netdev_priv(netdev); | ||
3254 | |||
3255 | if (!priv) | ||
3256 | return; | ||
3257 | dev_warn(&netdev->dev, "tx timeout."); | ||
3258 | |||
3259 | usb_unlink_urb(priv->tx_urb); | ||
3260 | priv->stats.tx_errors++; | ||
3261 | } | ||
3262 | |||
1322 | static int at76_submit_rx_urb(struct at76_priv *priv) | 3263 | static int at76_submit_rx_urb(struct at76_priv *priv) |
1323 | { | 3264 | { |
1324 | int ret; | 3265 | int ret; |
@@ -1327,7 +3268,7 @@ static int at76_submit_rx_urb(struct at76_priv *priv) | |||
1327 | 3268 | ||
1328 | if (!priv->rx_urb) { | 3269 | if (!priv->rx_urb) { |
1329 | printk(KERN_ERR "%s: %s: priv->rx_urb is NULL\n", | 3270 | printk(KERN_ERR "%s: %s: priv->rx_urb is NULL\n", |
1330 | wiphy_name(priv->hw->wiphy), __func__); | 3271 | priv->netdev->name, __func__); |
1331 | return -EFAULT; | 3272 | return -EFAULT; |
1332 | } | 3273 | } |
1333 | 3274 | ||
@@ -1335,7 +3276,7 @@ static int at76_submit_rx_urb(struct at76_priv *priv) | |||
1335 | skb = dev_alloc_skb(sizeof(struct at76_rx_buffer)); | 3276 | skb = dev_alloc_skb(sizeof(struct at76_rx_buffer)); |
1336 | if (!skb) { | 3277 | if (!skb) { |
1337 | printk(KERN_ERR "%s: cannot allocate rx skbuff\n", | 3278 | printk(KERN_ERR "%s: cannot allocate rx skbuff\n", |
1338 | wiphy_name(priv->hw->wiphy)); | 3279 | priv->netdev->name); |
1339 | ret = -ENOMEM; | 3280 | ret = -ENOMEM; |
1340 | goto exit; | 3281 | goto exit; |
1341 | } | 3282 | } |
@@ -1355,18 +3296,110 @@ static int at76_submit_rx_urb(struct at76_priv *priv) | |||
1355 | "usb_submit_urb returned -ENODEV"); | 3296 | "usb_submit_urb returned -ENODEV"); |
1356 | else | 3297 | else |
1357 | printk(KERN_ERR "%s: rx, usb_submit_urb failed: %d\n", | 3298 | printk(KERN_ERR "%s: rx, usb_submit_urb failed: %d\n", |
1358 | wiphy_name(priv->hw->wiphy), ret); | 3299 | priv->netdev->name, ret); |
1359 | } | 3300 | } |
1360 | 3301 | ||
1361 | exit: | 3302 | exit: |
1362 | if (ret < 0 && ret != -ENODEV) | 3303 | if (ret < 0 && ret != -ENODEV) |
1363 | printk(KERN_ERR "%s: cannot submit rx urb - please unload the " | 3304 | printk(KERN_ERR "%s: cannot submit rx urb - please unload the " |
1364 | "driver and/or power cycle the device\n", | 3305 | "driver and/or power cycle the device\n", |
1365 | wiphy_name(priv->hw->wiphy)); | 3306 | priv->netdev->name); |
1366 | 3307 | ||
1367 | return ret; | 3308 | return ret; |
1368 | } | 3309 | } |
1369 | 3310 | ||
3311 | static int at76_open(struct net_device *netdev) | ||
3312 | { | ||
3313 | struct at76_priv *priv = netdev_priv(netdev); | ||
3314 | int ret = 0; | ||
3315 | |||
3316 | at76_dbg(DBG_PROC_ENTRY, "%s(): entry", __func__); | ||
3317 | |||
3318 | if (mutex_lock_interruptible(&priv->mtx)) | ||
3319 | return -EINTR; | ||
3320 | |||
3321 | /* if netdev->dev_addr != priv->mac_addr we must | ||
3322 | set the mac address in the device ! */ | ||
3323 | if (compare_ether_addr(netdev->dev_addr, priv->mac_addr)) { | ||
3324 | if (at76_add_mac_address(priv, netdev->dev_addr) >= 0) | ||
3325 | at76_dbg(DBG_PROGRESS, "%s: set new MAC addr %s", | ||
3326 | netdev->name, mac2str(netdev->dev_addr)); | ||
3327 | } | ||
3328 | |||
3329 | priv->scan_state = SCAN_IDLE; | ||
3330 | priv->last_scan = jiffies; | ||
3331 | |||
3332 | ret = at76_submit_rx_urb(priv); | ||
3333 | if (ret < 0) { | ||
3334 | printk(KERN_ERR "%s: open: submit_rx_urb failed: %d\n", | ||
3335 | netdev->name, ret); | ||
3336 | goto error; | ||
3337 | } | ||
3338 | |||
3339 | schedule_delayed_work(&priv->dwork_restart, 0); | ||
3340 | |||
3341 | at76_dbg(DBG_PROC_ENTRY, "%s(): end", __func__); | ||
3342 | error: | ||
3343 | mutex_unlock(&priv->mtx); | ||
3344 | return ret < 0 ? ret : 0; | ||
3345 | } | ||
3346 | |||
3347 | static int at76_stop(struct net_device *netdev) | ||
3348 | { | ||
3349 | struct at76_priv *priv = netdev_priv(netdev); | ||
3350 | |||
3351 | at76_dbg(DBG_DEVSTART, "%s: ENTER", __func__); | ||
3352 | |||
3353 | if (mutex_lock_interruptible(&priv->mtx)) | ||
3354 | return -EINTR; | ||
3355 | |||
3356 | at76_quiesce(priv); | ||
3357 | |||
3358 | if (!priv->device_unplugged) { | ||
3359 | /* We are called by "ifconfig ethX down", not because the | ||
3360 | * device is not available anymore. */ | ||
3361 | at76_set_radio(priv, 0); | ||
3362 | |||
3363 | /* We unlink rx_urb because at76_open() re-submits it. | ||
3364 | * If unplugged, at76_delete_device() takes care of it. */ | ||
3365 | usb_kill_urb(priv->rx_urb); | ||
3366 | } | ||
3367 | |||
3368 | /* free the bss_list */ | ||
3369 | at76_free_bss_list(priv); | ||
3370 | |||
3371 | mutex_unlock(&priv->mtx); | ||
3372 | at76_dbg(DBG_DEVSTART, "%s: EXIT", __func__); | ||
3373 | |||
3374 | return 0; | ||
3375 | } | ||
3376 | |||
3377 | static void at76_ethtool_get_drvinfo(struct net_device *netdev, | ||
3378 | struct ethtool_drvinfo *info) | ||
3379 | { | ||
3380 | struct at76_priv *priv = netdev_priv(netdev); | ||
3381 | |||
3382 | strncpy(info->driver, DRIVER_NAME, sizeof(info->driver)); | ||
3383 | strncpy(info->version, DRIVER_VERSION, sizeof(info->version)); | ||
3384 | |||
3385 | usb_make_path(priv->udev, info->bus_info, sizeof(info->bus_info)); | ||
3386 | |||
3387 | snprintf(info->fw_version, sizeof(info->fw_version), "%d.%d.%d-%d", | ||
3388 | priv->fw_version.major, priv->fw_version.minor, | ||
3389 | priv->fw_version.patch, priv->fw_version.build); | ||
3390 | } | ||
3391 | |||
3392 | static u32 at76_ethtool_get_link(struct net_device *netdev) | ||
3393 | { | ||
3394 | struct at76_priv *priv = netdev_priv(netdev); | ||
3395 | return priv->mac_state == MAC_CONNECTED; | ||
3396 | } | ||
3397 | |||
3398 | static struct ethtool_ops at76_ethtool_ops = { | ||
3399 | .get_drvinfo = at76_ethtool_get_drvinfo, | ||
3400 | .get_link = at76_ethtool_get_link, | ||
3401 | }; | ||
3402 | |||
1370 | /* Download external firmware */ | 3403 | /* Download external firmware */ |
1371 | static int at76_load_external_fw(struct usb_device *udev, struct fwentry *fwe) | 3404 | static int at76_load_external_fw(struct usb_device *udev, struct fwentry *fwe) |
1372 | { | 3405 | { |
@@ -1463,6 +3496,406 @@ exit: | |||
1463 | return ret; | 3496 | return ret; |
1464 | } | 3497 | } |
1465 | 3498 | ||
3499 | static int at76_match_essid(struct at76_priv *priv, struct bss_info *ptr) | ||
3500 | { | ||
3501 | /* common criteria for both modi */ | ||
3502 | |||
3503 | int ret = (priv->essid_size == 0 /* ANY ssid */ || | ||
3504 | (priv->essid_size == ptr->ssid_len && | ||
3505 | !memcmp(priv->essid, ptr->ssid, ptr->ssid_len))); | ||
3506 | if (!ret) | ||
3507 | at76_dbg(DBG_BSS_MATCH, | ||
3508 | "%s bss table entry %p: essid didn't match", | ||
3509 | priv->netdev->name, ptr); | ||
3510 | return ret; | ||
3511 | } | ||
3512 | |||
3513 | static inline int at76_match_mode(struct at76_priv *priv, struct bss_info *ptr) | ||
3514 | { | ||
3515 | int ret; | ||
3516 | |||
3517 | if (priv->iw_mode == IW_MODE_ADHOC) | ||
3518 | ret = ptr->capa & WLAN_CAPABILITY_IBSS; | ||
3519 | else | ||
3520 | ret = ptr->capa & WLAN_CAPABILITY_ESS; | ||
3521 | if (!ret) | ||
3522 | at76_dbg(DBG_BSS_MATCH, | ||
3523 | "%s bss table entry %p: mode didn't match", | ||
3524 | priv->netdev->name, ptr); | ||
3525 | return ret; | ||
3526 | } | ||
3527 | |||
3528 | static int at76_match_rates(struct at76_priv *priv, struct bss_info *ptr) | ||
3529 | { | ||
3530 | int i; | ||
3531 | |||
3532 | for (i = 0; i < ptr->rates_len; i++) { | ||
3533 | u8 rate = ptr->rates[i]; | ||
3534 | |||
3535 | if (!(rate & 0x80)) | ||
3536 | continue; | ||
3537 | |||
3538 | /* this is a basic rate we have to support | ||
3539 | (see IEEE802.11, ch. 7.3.2.2) */ | ||
3540 | if (rate != (0x80 | hw_rates[0]) | ||
3541 | && rate != (0x80 | hw_rates[1]) | ||
3542 | && rate != (0x80 | hw_rates[2]) | ||
3543 | && rate != (0x80 | hw_rates[3])) { | ||
3544 | at76_dbg(DBG_BSS_MATCH, | ||
3545 | "%s: bss table entry %p: basic rate %02x not " | ||
3546 | "supported", priv->netdev->name, ptr, rate); | ||
3547 | return 0; | ||
3548 | } | ||
3549 | } | ||
3550 | |||
3551 | /* if we use short preamble, the bss must support it */ | ||
3552 | if (priv->preamble_type == PREAMBLE_TYPE_SHORT && | ||
3553 | !(ptr->capa & WLAN_CAPABILITY_SHORT_PREAMBLE)) { | ||
3554 | at76_dbg(DBG_BSS_MATCH, | ||
3555 | "%s: %p does not support short preamble", | ||
3556 | priv->netdev->name, ptr); | ||
3557 | return 0; | ||
3558 | } else | ||
3559 | return 1; | ||
3560 | } | ||
3561 | |||
3562 | static inline int at76_match_wep(struct at76_priv *priv, struct bss_info *ptr) | ||
3563 | { | ||
3564 | if (!priv->wep_enabled && ptr->capa & WLAN_CAPABILITY_PRIVACY) { | ||
3565 | /* we have disabled WEP, but the BSS signals privacy */ | ||
3566 | at76_dbg(DBG_BSS_MATCH, | ||
3567 | "%s: bss table entry %p: requires encryption", | ||
3568 | priv->netdev->name, ptr); | ||
3569 | return 0; | ||
3570 | } | ||
3571 | /* otherwise if the BSS does not signal privacy it may well | ||
3572 | accept encrypted packets from us ... */ | ||
3573 | return 1; | ||
3574 | } | ||
3575 | |||
3576 | static inline int at76_match_bssid(struct at76_priv *priv, struct bss_info *ptr) | ||
3577 | { | ||
3578 | if (!priv->wanted_bssid_valid || | ||
3579 | !compare_ether_addr(ptr->bssid, priv->wanted_bssid)) | ||
3580 | return 1; | ||
3581 | |||
3582 | at76_dbg(DBG_BSS_MATCH, | ||
3583 | "%s: requested bssid - %s does not match", | ||
3584 | priv->netdev->name, mac2str(priv->wanted_bssid)); | ||
3585 | at76_dbg(DBG_BSS_MATCH, | ||
3586 | " AP bssid - %s of bss table entry %p", | ||
3587 | mac2str(ptr->bssid), ptr); | ||
3588 | return 0; | ||
3589 | } | ||
3590 | |||
3591 | /** | ||
3592 | * at76_match_bss - try to find a matching bss in priv->bss | ||
3593 | * | ||
3594 | * last - last bss tried | ||
3595 | * | ||
3596 | * last == NULL signals a new round starting with priv->bss_list.next | ||
3597 | * this function must be called inside an acquired priv->bss_list_spinlock | ||
3598 | * otherwise the timeout on bss may remove the newly chosen entry | ||
3599 | */ | ||
3600 | static struct bss_info *at76_match_bss(struct at76_priv *priv, | ||
3601 | struct bss_info *last) | ||
3602 | { | ||
3603 | struct bss_info *ptr = NULL; | ||
3604 | struct list_head *curr; | ||
3605 | |||
3606 | curr = last ? last->list.next : priv->bss_list.next; | ||
3607 | while (curr != &priv->bss_list) { | ||
3608 | ptr = list_entry(curr, struct bss_info, list); | ||
3609 | if (at76_match_essid(priv, ptr) && at76_match_mode(priv, ptr) | ||
3610 | && at76_match_wep(priv, ptr) && at76_match_rates(priv, ptr) | ||
3611 | && at76_match_bssid(priv, ptr)) | ||
3612 | break; | ||
3613 | curr = curr->next; | ||
3614 | } | ||
3615 | |||
3616 | if (curr == &priv->bss_list) | ||
3617 | ptr = NULL; | ||
3618 | /* otherwise ptr points to the struct bss_info we have chosen */ | ||
3619 | |||
3620 | at76_dbg(DBG_BSS_TABLE, "%s %s: returned %p", priv->netdev->name, | ||
3621 | __func__, ptr); | ||
3622 | return ptr; | ||
3623 | } | ||
3624 | |||
3625 | /* Start joining a matching BSS, or create own IBSS */ | ||
3626 | static void at76_work_join(struct work_struct *work) | ||
3627 | { | ||
3628 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
3629 | work_join); | ||
3630 | int ret; | ||
3631 | unsigned long flags; | ||
3632 | |||
3633 | mutex_lock(&priv->mtx); | ||
3634 | |||
3635 | WARN_ON(priv->mac_state != MAC_JOINING); | ||
3636 | if (priv->mac_state != MAC_JOINING) | ||
3637 | goto exit; | ||
3638 | |||
3639 | /* secure the access to priv->curr_bss ! */ | ||
3640 | spin_lock_irqsave(&priv->bss_list_spinlock, flags); | ||
3641 | priv->curr_bss = at76_match_bss(priv, priv->curr_bss); | ||
3642 | spin_unlock_irqrestore(&priv->bss_list_spinlock, flags); | ||
3643 | |||
3644 | if (!priv->curr_bss) { | ||
3645 | /* here we haven't found a matching (i)bss ... */ | ||
3646 | if (priv->iw_mode == IW_MODE_ADHOC) { | ||
3647 | at76_set_mac_state(priv, MAC_OWN_IBSS); | ||
3648 | at76_start_ibss(priv); | ||
3649 | goto exit; | ||
3650 | } | ||
3651 | /* haven't found a matching BSS in infra mode - try again */ | ||
3652 | at76_set_mac_state(priv, MAC_SCANNING); | ||
3653 | schedule_work(&priv->work_start_scan); | ||
3654 | goto exit; | ||
3655 | } | ||
3656 | |||
3657 | ret = at76_join_bss(priv, priv->curr_bss); | ||
3658 | if (ret < 0) { | ||
3659 | printk(KERN_ERR "%s: join_bss failed with %d\n", | ||
3660 | priv->netdev->name, ret); | ||
3661 | goto exit; | ||
3662 | } | ||
3663 | |||
3664 | ret = at76_wait_completion(priv, CMD_JOIN); | ||
3665 | if (ret != CMD_STATUS_COMPLETE) { | ||
3666 | if (ret != CMD_STATUS_TIME_OUT) | ||
3667 | printk(KERN_ERR "%s: join_bss completed with %d\n", | ||
3668 | priv->netdev->name, ret); | ||
3669 | else | ||
3670 | printk(KERN_INFO "%s: join_bss ssid %s timed out\n", | ||
3671 | priv->netdev->name, | ||
3672 | mac2str(priv->curr_bss->bssid)); | ||
3673 | |||
3674 | /* retry next BSS immediately */ | ||
3675 | schedule_work(&priv->work_join); | ||
3676 | goto exit; | ||
3677 | } | ||
3678 | |||
3679 | /* here we have joined the (I)BSS */ | ||
3680 | if (priv->iw_mode == IW_MODE_ADHOC) { | ||
3681 | struct bss_info *bptr = priv->curr_bss; | ||
3682 | at76_set_mac_state(priv, MAC_CONNECTED); | ||
3683 | /* get ESSID, BSSID and channel for priv->curr_bss */ | ||
3684 | priv->essid_size = bptr->ssid_len; | ||
3685 | memcpy(priv->essid, bptr->ssid, bptr->ssid_len); | ||
3686 | memcpy(priv->bssid, bptr->bssid, ETH_ALEN); | ||
3687 | priv->channel = bptr->channel; | ||
3688 | at76_iwevent_bss_connect(priv->netdev, bptr->bssid); | ||
3689 | netif_carrier_on(priv->netdev); | ||
3690 | netif_start_queue(priv->netdev); | ||
3691 | /* just to be sure */ | ||
3692 | cancel_delayed_work(&priv->dwork_get_scan); | ||
3693 | cancel_delayed_work(&priv->dwork_auth); | ||
3694 | cancel_delayed_work(&priv->dwork_assoc); | ||
3695 | } else { | ||
3696 | /* send auth req */ | ||
3697 | priv->retries = AUTH_RETRIES; | ||
3698 | at76_set_mac_state(priv, MAC_AUTH); | ||
3699 | at76_auth_req(priv, priv->curr_bss, 1, NULL); | ||
3700 | at76_dbg(DBG_MGMT_TIMER, | ||
3701 | "%s:%d: starting mgmt_timer + HZ", __func__, __LINE__); | ||
3702 | schedule_delayed_work(&priv->dwork_auth, AUTH_TIMEOUT); | ||
3703 | } | ||
3704 | |||
3705 | exit: | ||
3706 | mutex_unlock(&priv->mtx); | ||
3707 | } | ||
3708 | |||
3709 | /* Reap scan results */ | ||
3710 | static void at76_dwork_get_scan(struct work_struct *work) | ||
3711 | { | ||
3712 | int status; | ||
3713 | int ret; | ||
3714 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
3715 | dwork_get_scan.work); | ||
3716 | |||
3717 | mutex_lock(&priv->mtx); | ||
3718 | WARN_ON(priv->mac_state != MAC_SCANNING); | ||
3719 | if (priv->mac_state != MAC_SCANNING) | ||
3720 | goto exit; | ||
3721 | |||
3722 | status = at76_get_cmd_status(priv->udev, CMD_SCAN); | ||
3723 | if (status < 0) { | ||
3724 | printk(KERN_ERR "%s: %s: at76_get_cmd_status failed with %d\n", | ||
3725 | priv->netdev->name, __func__, status); | ||
3726 | status = CMD_STATUS_IN_PROGRESS; | ||
3727 | /* INFO: Hope it was a one off error - if not, scanning | ||
3728 | further down the line and stop this cycle */ | ||
3729 | } | ||
3730 | at76_dbg(DBG_PROGRESS, | ||
3731 | "%s %s: got cmd_status %d (state %s, need_any %d)", | ||
3732 | priv->netdev->name, __func__, status, | ||
3733 | mac_states[priv->mac_state], priv->scan_need_any); | ||
3734 | |||
3735 | if (status != CMD_STATUS_COMPLETE) { | ||
3736 | if ((status != CMD_STATUS_IN_PROGRESS) && | ||
3737 | (status != CMD_STATUS_IDLE)) | ||
3738 | printk(KERN_ERR "%s: %s: Bad scan status: %s\n", | ||
3739 | priv->netdev->name, __func__, | ||
3740 | at76_get_cmd_status_string(status)); | ||
3741 | |||
3742 | /* the first cmd status after scan start is always a IDLE -> | ||
3743 | start the timer to poll again until COMPLETED */ | ||
3744 | at76_dbg(DBG_MGMT_TIMER, | ||
3745 | "%s:%d: starting mgmt_timer for %d ticks", | ||
3746 | __func__, __LINE__, SCAN_POLL_INTERVAL); | ||
3747 | schedule_delayed_work(&priv->dwork_get_scan, | ||
3748 | SCAN_POLL_INTERVAL); | ||
3749 | goto exit; | ||
3750 | } | ||
3751 | |||
3752 | if (at76_debug & DBG_BSS_TABLE) | ||
3753 | at76_dump_bss_table(priv); | ||
3754 | |||
3755 | if (priv->scan_need_any) { | ||
3756 | ret = at76_start_scan(priv, 0); | ||
3757 | if (ret < 0) | ||
3758 | printk(KERN_ERR | ||
3759 | "%s: %s: start_scan (ANY) failed with %d\n", | ||
3760 | priv->netdev->name, __func__, ret); | ||
3761 | at76_dbg(DBG_MGMT_TIMER, | ||
3762 | "%s:%d: starting mgmt_timer for %d ticks", __func__, | ||
3763 | __LINE__, SCAN_POLL_INTERVAL); | ||
3764 | schedule_delayed_work(&priv->dwork_get_scan, | ||
3765 | SCAN_POLL_INTERVAL); | ||
3766 | priv->scan_need_any = 0; | ||
3767 | } else { | ||
3768 | priv->scan_state = SCAN_COMPLETED; | ||
3769 | /* report the end of scan to user space */ | ||
3770 | at76_iwevent_scan_complete(priv->netdev); | ||
3771 | at76_set_mac_state(priv, MAC_JOINING); | ||
3772 | schedule_work(&priv->work_join); | ||
3773 | } | ||
3774 | |||
3775 | exit: | ||
3776 | mutex_unlock(&priv->mtx); | ||
3777 | } | ||
3778 | |||
3779 | /* Handle loss of beacons from the AP */ | ||
3780 | static void at76_dwork_beacon(struct work_struct *work) | ||
3781 | { | ||
3782 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
3783 | dwork_beacon.work); | ||
3784 | |||
3785 | mutex_lock(&priv->mtx); | ||
3786 | if (priv->mac_state != MAC_CONNECTED || priv->iw_mode != IW_MODE_INFRA) | ||
3787 | goto exit; | ||
3788 | |||
3789 | /* We haven't received any beacons from out AP for BEACON_TIMEOUT */ | ||
3790 | printk(KERN_INFO "%s: lost beacon bssid %s\n", | ||
3791 | priv->netdev->name, mac2str(priv->curr_bss->bssid)); | ||
3792 | |||
3793 | netif_carrier_off(priv->netdev); | ||
3794 | netif_stop_queue(priv->netdev); | ||
3795 | at76_iwevent_bss_disconnect(priv->netdev); | ||
3796 | at76_set_mac_state(priv, MAC_SCANNING); | ||
3797 | schedule_work(&priv->work_start_scan); | ||
3798 | |||
3799 | exit: | ||
3800 | mutex_unlock(&priv->mtx); | ||
3801 | } | ||
3802 | |||
3803 | /* Handle authentication response timeout */ | ||
3804 | static void at76_dwork_auth(struct work_struct *work) | ||
3805 | { | ||
3806 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
3807 | dwork_auth.work); | ||
3808 | |||
3809 | mutex_lock(&priv->mtx); | ||
3810 | WARN_ON(priv->mac_state != MAC_AUTH); | ||
3811 | if (priv->mac_state != MAC_AUTH) | ||
3812 | goto exit; | ||
3813 | |||
3814 | at76_dbg(DBG_PROGRESS, "%s: authentication response timeout", | ||
3815 | priv->netdev->name); | ||
3816 | |||
3817 | if (priv->retries-- >= 0) { | ||
3818 | at76_auth_req(priv, priv->curr_bss, 1, NULL); | ||
3819 | at76_dbg(DBG_MGMT_TIMER, "%s:%d: starting mgmt_timer + HZ", | ||
3820 | __func__, __LINE__); | ||
3821 | schedule_delayed_work(&priv->dwork_auth, AUTH_TIMEOUT); | ||
3822 | } else { | ||
3823 | /* try to get next matching BSS */ | ||
3824 | at76_set_mac_state(priv, MAC_JOINING); | ||
3825 | schedule_work(&priv->work_join); | ||
3826 | } | ||
3827 | |||
3828 | exit: | ||
3829 | mutex_unlock(&priv->mtx); | ||
3830 | } | ||
3831 | |||
3832 | /* Handle association response timeout */ | ||
3833 | static void at76_dwork_assoc(struct work_struct *work) | ||
3834 | { | ||
3835 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
3836 | dwork_assoc.work); | ||
3837 | |||
3838 | mutex_lock(&priv->mtx); | ||
3839 | WARN_ON(priv->mac_state != MAC_ASSOC); | ||
3840 | if (priv->mac_state != MAC_ASSOC) | ||
3841 | goto exit; | ||
3842 | |||
3843 | at76_dbg(DBG_PROGRESS, "%s: association response timeout", | ||
3844 | priv->netdev->name); | ||
3845 | |||
3846 | if (priv->retries-- >= 0) { | ||
3847 | at76_assoc_req(priv, priv->curr_bss); | ||
3848 | at76_dbg(DBG_MGMT_TIMER, "%s:%d: starting mgmt_timer + HZ", | ||
3849 | __func__, __LINE__); | ||
3850 | schedule_delayed_work(&priv->dwork_assoc, ASSOC_TIMEOUT); | ||
3851 | } else { | ||
3852 | /* try to get next matching BSS */ | ||
3853 | at76_set_mac_state(priv, MAC_JOINING); | ||
3854 | schedule_work(&priv->work_join); | ||
3855 | } | ||
3856 | |||
3857 | exit: | ||
3858 | mutex_unlock(&priv->mtx); | ||
3859 | } | ||
3860 | |||
3861 | /* Read new bssid in ad-hoc mode */ | ||
3862 | static void at76_work_new_bss(struct work_struct *work) | ||
3863 | { | ||
3864 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
3865 | work_new_bss); | ||
3866 | int ret; | ||
3867 | struct mib_mac_mgmt mac_mgmt; | ||
3868 | |||
3869 | mutex_lock(&priv->mtx); | ||
3870 | |||
3871 | ret = at76_get_mib(priv->udev, MIB_MAC_MGMT, &mac_mgmt, | ||
3872 | sizeof(struct mib_mac_mgmt)); | ||
3873 | if (ret < 0) { | ||
3874 | printk(KERN_ERR "%s: at76_get_mib failed: %d\n", | ||
3875 | priv->netdev->name, ret); | ||
3876 | goto exit; | ||
3877 | } | ||
3878 | |||
3879 | at76_dbg(DBG_PROGRESS, "ibss_change = 0x%2x", mac_mgmt.ibss_change); | ||
3880 | memcpy(priv->bssid, mac_mgmt.current_bssid, ETH_ALEN); | ||
3881 | at76_dbg(DBG_PROGRESS, "using BSSID %s", mac2str(priv->bssid)); | ||
3882 | |||
3883 | at76_iwevent_bss_connect(priv->netdev, priv->bssid); | ||
3884 | |||
3885 | priv->mib_buf.type = MIB_MAC_MGMT; | ||
3886 | priv->mib_buf.size = 1; | ||
3887 | priv->mib_buf.index = offsetof(struct mib_mac_mgmt, ibss_change); | ||
3888 | priv->mib_buf.data.byte = 0; | ||
3889 | |||
3890 | ret = at76_set_mib(priv, &priv->mib_buf); | ||
3891 | if (ret < 0) | ||
3892 | printk(KERN_ERR "%s: set_mib (ibss change ok) failed: %d\n", | ||
3893 | priv->netdev->name, ret); | ||
3894 | |||
3895 | exit: | ||
3896 | mutex_unlock(&priv->mtx); | ||
3897 | } | ||
3898 | |||
1466 | static int at76_startup_device(struct at76_priv *priv) | 3899 | static int at76_startup_device(struct at76_priv *priv) |
1467 | { | 3900 | { |
1468 | struct at76_card_config *ccfg = &priv->card_config; | 3901 | struct at76_card_config *ccfg = &priv->card_config; |
@@ -1470,14 +3903,14 @@ static int at76_startup_device(struct at76_priv *priv) | |||
1470 | 3903 | ||
1471 | at76_dbg(DBG_PARAMS, | 3904 | at76_dbg(DBG_PARAMS, |
1472 | "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d " | 3905 | "%s param: ssid %.*s (%s) mode %s ch %d wep %s key %d " |
1473 | "keylen %d", wiphy_name(priv->hw->wiphy), priv->essid_size, | 3906 | "keylen %d", priv->netdev->name, priv->essid_size, priv->essid, |
1474 | priv->essid, hex2str(priv->essid, IW_ESSID_MAX_SIZE), | 3907 | hex2str(priv->essid, IW_ESSID_MAX_SIZE), |
1475 | priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra", | 3908 | priv->iw_mode == IW_MODE_ADHOC ? "adhoc" : "infra", |
1476 | priv->channel, priv->wep_enabled ? "enabled" : "disabled", | 3909 | priv->channel, priv->wep_enabled ? "enabled" : "disabled", |
1477 | priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]); | 3910 | priv->wep_key_id, priv->wep_keys_len[priv->wep_key_id]); |
1478 | at76_dbg(DBG_PARAMS, | 3911 | at76_dbg(DBG_PARAMS, |
1479 | "%s param: preamble %s rts %d retry %d frag %d " | 3912 | "%s param: preamble %s rts %d retry %d frag %d " |
1480 | "txrate %s auth_mode %d", wiphy_name(priv->hw->wiphy), | 3913 | "txrate %s auth_mode %d", priv->netdev->name, |
1481 | preambles[priv->preamble_type], priv->rts_threshold, | 3914 | preambles[priv->preamble_type], priv->rts_threshold, |
1482 | priv->short_retry_limit, priv->frag_threshold, | 3915 | priv->short_retry_limit, priv->frag_threshold, |
1483 | priv->txrate == TX_RATE_1MBIT ? "1MBit" : priv->txrate == | 3916 | priv->txrate == TX_RATE_1MBIT ? "1MBit" : priv->txrate == |
@@ -1488,7 +3921,7 @@ static int at76_startup_device(struct at76_priv *priv) | |||
1488 | at76_dbg(DBG_PARAMS, | 3921 | at76_dbg(DBG_PARAMS, |
1489 | "%s param: pm_mode %d pm_period %d auth_mode %s " | 3922 | "%s param: pm_mode %d pm_period %d auth_mode %s " |
1490 | "scan_times %d %d scan_mode %s", | 3923 | "scan_times %d %d scan_mode %s", |
1491 | wiphy_name(priv->hw->wiphy), priv->pm_mode, priv->pm_period, | 3924 | priv->netdev->name, priv->pm_mode, priv->pm_period, |
1492 | priv->auth_mode == WLAN_AUTH_OPEN ? "open" : "shared_secret", | 3925 | priv->auth_mode == WLAN_AUTH_OPEN ? "open" : "shared_secret", |
1493 | priv->scan_min_time, priv->scan_max_time, | 3926 | priv->scan_min_time, priv->scan_max_time, |
1494 | priv->scan_mode == SCAN_TYPE_ACTIVE ? "active" : "passive"); | 3927 | priv->scan_mode == SCAN_TYPE_ACTIVE ? "active" : "passive"); |
@@ -1522,8 +3955,7 @@ static int at76_startup_device(struct at76_priv *priv) | |||
1522 | ccfg->ssid_len = priv->essid_size; | 3955 | ccfg->ssid_len = priv->essid_size; |
1523 | 3956 | ||
1524 | ccfg->wep_default_key_id = priv->wep_key_id; | 3957 | ccfg->wep_default_key_id = priv->wep_key_id; |
1525 | memcpy(ccfg->wep_default_key_value, priv->wep_keys, | 3958 | memcpy(ccfg->wep_default_key_value, priv->wep_keys, 4 * WEP_KEY_LEN); |
1526 | sizeof(priv->wep_keys)); | ||
1527 | 3959 | ||
1528 | ccfg->short_preamble = priv->preamble_type; | 3960 | ccfg->short_preamble = priv->preamble_type; |
1529 | ccfg->beacon_period = cpu_to_le16(priv->beacon_period); | 3961 | ccfg->beacon_period = cpu_to_le16(priv->beacon_period); |
@@ -1532,7 +3964,7 @@ static int at76_startup_device(struct at76_priv *priv) | |||
1532 | sizeof(struct at76_card_config)); | 3964 | sizeof(struct at76_card_config)); |
1533 | if (ret < 0) { | 3965 | if (ret < 0) { |
1534 | printk(KERN_ERR "%s: at76_set_card_command failed: %d\n", | 3966 | printk(KERN_ERR "%s: at76_set_card_command failed: %d\n", |
1535 | wiphy_name(priv->hw->wiphy), ret); | 3967 | priv->netdev->name, ret); |
1536 | return ret; | 3968 | return ret; |
1537 | } | 3969 | } |
1538 | 3970 | ||
@@ -1578,6 +4010,69 @@ static int at76_startup_device(struct at76_priv *priv) | |||
1578 | return 0; | 4010 | return 0; |
1579 | } | 4011 | } |
1580 | 4012 | ||
4013 | /* Restart the interface */ | ||
4014 | static void at76_dwork_restart(struct work_struct *work) | ||
4015 | { | ||
4016 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
4017 | dwork_restart.work); | ||
4018 | |||
4019 | mutex_lock(&priv->mtx); | ||
4020 | |||
4021 | netif_carrier_off(priv->netdev); /* stop netdev watchdog */ | ||
4022 | netif_stop_queue(priv->netdev); /* stop tx data packets */ | ||
4023 | |||
4024 | at76_startup_device(priv); | ||
4025 | |||
4026 | if (priv->iw_mode != IW_MODE_MONITOR) { | ||
4027 | priv->netdev->type = ARPHRD_ETHER; | ||
4028 | at76_set_mac_state(priv, MAC_SCANNING); | ||
4029 | schedule_work(&priv->work_start_scan); | ||
4030 | } else { | ||
4031 | priv->netdev->type = ARPHRD_IEEE80211_RADIOTAP; | ||
4032 | at76_start_monitor(priv); | ||
4033 | } | ||
4034 | |||
4035 | mutex_unlock(&priv->mtx); | ||
4036 | } | ||
4037 | |||
4038 | /* Initiate scanning */ | ||
4039 | static void at76_work_start_scan(struct work_struct *work) | ||
4040 | { | ||
4041 | struct at76_priv *priv = container_of(work, struct at76_priv, | ||
4042 | work_start_scan); | ||
4043 | int ret; | ||
4044 | |||
4045 | mutex_lock(&priv->mtx); | ||
4046 | |||
4047 | WARN_ON(priv->mac_state != MAC_SCANNING); | ||
4048 | if (priv->mac_state != MAC_SCANNING) | ||
4049 | goto exit; | ||
4050 | |||
4051 | /* only clear the bss list when a scan is actively initiated, | ||
4052 | * otherwise simply rely on at76_bss_list_timeout */ | ||
4053 | if (priv->scan_state == SCAN_IN_PROGRESS) { | ||
4054 | at76_free_bss_list(priv); | ||
4055 | priv->scan_need_any = 1; | ||
4056 | } else | ||
4057 | priv->scan_need_any = 0; | ||
4058 | |||
4059 | ret = at76_start_scan(priv, 1); | ||
4060 | |||
4061 | if (ret < 0) | ||
4062 | printk(KERN_ERR "%s: %s: start_scan failed with %d\n", | ||
4063 | priv->netdev->name, __func__, ret); | ||
4064 | else { | ||
4065 | at76_dbg(DBG_MGMT_TIMER, | ||
4066 | "%s:%d: starting mgmt_timer for %d ticks", | ||
4067 | __func__, __LINE__, SCAN_POLL_INTERVAL); | ||
4068 | schedule_delayed_work(&priv->dwork_get_scan, | ||
4069 | SCAN_POLL_INTERVAL); | ||
4070 | } | ||
4071 | |||
4072 | exit: | ||
4073 | mutex_unlock(&priv->mtx); | ||
4074 | } | ||
4075 | |||
1581 | /* Enable or disable promiscuous mode */ | 4076 | /* Enable or disable promiscuous mode */ |
1582 | static void at76_work_set_promisc(struct work_struct *work) | 4077 | static void at76_work_set_promisc(struct work_struct *work) |
1583 | { | 4078 | { |
@@ -1595,7 +4090,7 @@ static void at76_work_set_promisc(struct work_struct *work) | |||
1595 | ret = at76_set_mib(priv, &priv->mib_buf); | 4090 | ret = at76_set_mib(priv, &priv->mib_buf); |
1596 | if (ret < 0) | 4091 | if (ret < 0) |
1597 | printk(KERN_ERR "%s: set_mib (promiscuous_mode) failed: %d\n", | 4092 | printk(KERN_ERR "%s: set_mib (promiscuous_mode) failed: %d\n", |
1598 | wiphy_name(priv->hw->wiphy), ret); | 4093 | priv->netdev->name, ret); |
1599 | 4094 | ||
1600 | mutex_unlock(&priv->mtx); | 4095 | mutex_unlock(&priv->mtx); |
1601 | } | 4096 | } |
@@ -1611,759 +4106,1088 @@ static void at76_work_submit_rx(struct work_struct *work) | |||
1611 | mutex_unlock(&priv->mtx); | 4106 | mutex_unlock(&priv->mtx); |
1612 | } | 4107 | } |
1613 | 4108 | ||
1614 | static void at76_rx_tasklet(unsigned long param) | 4109 | /* We got an association response */ |
4110 | static void at76_rx_mgmt_assoc(struct at76_priv *priv, | ||
4111 | struct at76_rx_buffer *buf) | ||
1615 | { | 4112 | { |
1616 | struct urb *urb = (struct urb *)param; | 4113 | struct ieee80211_assoc_response *resp = |
1617 | struct at76_priv *priv = urb->context; | 4114 | (struct ieee80211_assoc_response *)buf->packet; |
1618 | struct at76_rx_buffer *buf; | 4115 | u16 assoc_id = le16_to_cpu(resp->aid); |
1619 | struct ieee80211_rx_status rx_status = { 0 }; | 4116 | u16 status = le16_to_cpu(resp->status); |
1620 | 4117 | ||
1621 | if (priv->device_unplugged) { | 4118 | at76_dbg(DBG_RX_MGMT, "%s: rx AssocResp bssid %s capa 0x%04x status " |
1622 | at76_dbg(DBG_DEVSTART, "device unplugged"); | 4119 | "0x%04x assoc_id 0x%04x rates %s", priv->netdev->name, |
1623 | if (urb) | 4120 | mac2str(resp->header.addr3), le16_to_cpu(resp->capability), |
1624 | at76_dbg(DBG_DEVSTART, "urb status %d", urb->status); | 4121 | status, assoc_id, hex2str(resp->info_element->data, |
4122 | resp->info_element->len)); | ||
4123 | |||
4124 | if (priv->mac_state != MAC_ASSOC) { | ||
4125 | printk(KERN_INFO "%s: AssocResp in state %s ignored\n", | ||
4126 | priv->netdev->name, mac_states[priv->mac_state]); | ||
1625 | return; | 4127 | return; |
1626 | } | 4128 | } |
1627 | 4129 | ||
1628 | if (!priv->rx_skb || !priv->rx_skb->data) | 4130 | BUG_ON(!priv->curr_bss); |
1629 | return; | 4131 | |
1630 | 4132 | cancel_delayed_work(&priv->dwork_assoc); | |
1631 | buf = (struct at76_rx_buffer *)priv->rx_skb->data; | 4133 | if (status == WLAN_STATUS_SUCCESS) { |
1632 | 4134 | struct bss_info *ptr = priv->curr_bss; | |
1633 | if (urb->status != 0) { | 4135 | priv->assoc_id = assoc_id & 0x3fff; |
1634 | if (urb->status != -ENOENT && urb->status != -ECONNRESET) | 4136 | /* update iwconfig params */ |
1635 | at76_dbg(DBG_URB, | 4137 | memcpy(priv->bssid, ptr->bssid, ETH_ALEN); |
1636 | "%s %s: - nonzero Rx bulk status received: %d", | 4138 | memcpy(priv->essid, ptr->ssid, ptr->ssid_len); |
1637 | __func__, wiphy_name(priv->hw->wiphy), | 4139 | priv->essid_size = ptr->ssid_len; |
1638 | urb->status); | 4140 | priv->channel = ptr->channel; |
1639 | return; | 4141 | schedule_work(&priv->work_assoc_done); |
4142 | } else { | ||
4143 | at76_set_mac_state(priv, MAC_JOINING); | ||
4144 | schedule_work(&priv->work_join); | ||
1640 | } | 4145 | } |
4146 | } | ||
1641 | 4147 | ||
1642 | at76_dbg(DBG_RX_ATMEL_HDR, | 4148 | /* Process disassociation request from the AP */ |
1643 | "%s: rx frame: rate %d rssi %d noise %d link %d", | 4149 | static void at76_rx_mgmt_disassoc(struct at76_priv *priv, |
1644 | wiphy_name(priv->hw->wiphy), buf->rx_rate, buf->rssi, | 4150 | struct at76_rx_buffer *buf) |
1645 | buf->noise_level, buf->link_quality); | 4151 | { |
1646 | 4152 | struct ieee80211_disassoc *resp = | |
1647 | skb_trim(priv->rx_skb, le16_to_cpu(buf->wlength) + AT76_RX_HDRLEN); | 4153 | (struct ieee80211_disassoc *)buf->packet; |
1648 | at76_dbg_dump(DBG_RX_DATA, &priv->rx_skb->data[AT76_RX_HDRLEN], | 4154 | struct ieee80211_hdr_3addr *mgmt = &resp->header; |
1649 | priv->rx_skb->len, "RX: len=%d", | 4155 | |
1650 | (int)(priv->rx_skb->len - AT76_RX_HDRLEN)); | 4156 | at76_dbg(DBG_RX_MGMT, |
4157 | "%s: rx DisAssoc bssid %s reason 0x%04x destination %s", | ||
4158 | priv->netdev->name, mac2str(mgmt->addr3), | ||
4159 | le16_to_cpu(resp->reason), mac2str(mgmt->addr1)); | ||
4160 | |||
4161 | /* We are not connected, ignore */ | ||
4162 | if (priv->mac_state == MAC_SCANNING || priv->mac_state == MAC_INIT | ||
4163 | || !priv->curr_bss) | ||
4164 | return; | ||
1651 | 4165 | ||
1652 | rx_status.signal = buf->rssi; | 4166 | /* Not our BSSID, ignore */ |
1653 | /* FIXME: is rate_idx still present in structure? */ | 4167 | if (compare_ether_addr(mgmt->addr3, priv->curr_bss->bssid)) |
1654 | rx_status.rate_idx = buf->rx_rate; | 4168 | return; |
1655 | rx_status.flag |= RX_FLAG_DECRYPTED; | ||
1656 | rx_status.flag |= RX_FLAG_IV_STRIPPED; | ||
1657 | 4169 | ||
1658 | skb_pull(priv->rx_skb, AT76_RX_HDRLEN); | 4170 | /* Not for our STA and not broadcast, ignore */ |
1659 | at76_dbg(DBG_MAC80211, "calling ieee80211_rx_irqsafe(): %d/%d", | 4171 | if (compare_ether_addr(priv->netdev->dev_addr, mgmt->addr1) |
1660 | priv->rx_skb->len, priv->rx_skb->data_len); | 4172 | && !is_broadcast_ether_addr(mgmt->addr1)) |
1661 | ieee80211_rx_irqsafe(priv->hw, priv->rx_skb, &rx_status); | 4173 | return; |
1662 | 4174 | ||
1663 | /* Use a new skb for the next receive */ | 4175 | if (priv->mac_state != MAC_ASSOC && priv->mac_state != MAC_CONNECTED |
1664 | priv->rx_skb = NULL; | 4176 | && priv->mac_state != MAC_JOINING) { |
4177 | printk(KERN_INFO "%s: DisAssoc in state %s ignored\n", | ||
4178 | priv->netdev->name, mac_states[priv->mac_state]); | ||
4179 | return; | ||
4180 | } | ||
1665 | 4181 | ||
1666 | at76_submit_rx_urb(priv); | 4182 | if (priv->mac_state == MAC_CONNECTED) { |
4183 | netif_carrier_off(priv->netdev); | ||
4184 | netif_stop_queue(priv->netdev); | ||
4185 | at76_iwevent_bss_disconnect(priv->netdev); | ||
4186 | } | ||
4187 | cancel_delayed_work(&priv->dwork_get_scan); | ||
4188 | cancel_delayed_work(&priv->dwork_beacon); | ||
4189 | cancel_delayed_work(&priv->dwork_auth); | ||
4190 | cancel_delayed_work(&priv->dwork_assoc); | ||
4191 | at76_set_mac_state(priv, MAC_JOINING); | ||
4192 | schedule_work(&priv->work_join); | ||
1667 | } | 4193 | } |
1668 | 4194 | ||
1669 | /* Load firmware into kernel memory and parse it */ | 4195 | static void at76_rx_mgmt_auth(struct at76_priv *priv, |
1670 | static struct fwentry *at76_load_firmware(struct usb_device *udev, | 4196 | struct at76_rx_buffer *buf) |
1671 | enum board_type board_type) | ||
1672 | { | 4197 | { |
1673 | int ret; | 4198 | struct ieee80211_auth *resp = (struct ieee80211_auth *)buf->packet; |
1674 | char *str; | 4199 | struct ieee80211_hdr_3addr *mgmt = &resp->header; |
1675 | struct at76_fw_header *fwh; | 4200 | int seq_nr = le16_to_cpu(resp->transaction); |
1676 | struct fwentry *fwe = &firmwares[board_type]; | 4201 | int alg = le16_to_cpu(resp->algorithm); |
1677 | 4202 | int status = le16_to_cpu(resp->status); | |
1678 | mutex_lock(&fw_mutex); | 4203 | |
1679 | 4204 | at76_dbg(DBG_RX_MGMT, | |
1680 | if (fwe->loaded) { | 4205 | "%s: rx AuthFrame bssid %s alg %d seq_nr %d status %d " |
1681 | at76_dbg(DBG_FW, "re-using previously loaded fw"); | 4206 | "destination %s", priv->netdev->name, mac2str(mgmt->addr3), |
1682 | goto exit; | 4207 | alg, seq_nr, status, mac2str(mgmt->addr1)); |
4208 | |||
4209 | if (alg == WLAN_AUTH_SHARED_KEY && seq_nr == 2) | ||
4210 | at76_dbg(DBG_RX_MGMT, "%s: AuthFrame challenge %s ...", | ||
4211 | priv->netdev->name, hex2str(resp->info_element, 18)); | ||
4212 | |||
4213 | if (priv->mac_state != MAC_AUTH) { | ||
4214 | printk(KERN_INFO "%s: ignored AuthFrame in state %s\n", | ||
4215 | priv->netdev->name, mac_states[priv->mac_state]); | ||
4216 | return; | ||
1683 | } | 4217 | } |
1684 | 4218 | if (priv->auth_mode != alg) { | |
1685 | at76_dbg(DBG_FW, "downloading firmware %s", fwe->fwname); | 4219 | printk(KERN_INFO "%s: ignored AuthFrame for alg %d\n", |
1686 | ret = request_firmware(&fwe->fw, fwe->fwname, &udev->dev); | 4220 | priv->netdev->name, alg); |
1687 | if (ret < 0) { | 4221 | return; |
1688 | dev_printk(KERN_ERR, &udev->dev, "firmware %s not found!\n", | ||
1689 | fwe->fwname); | ||
1690 | dev_printk(KERN_ERR, &udev->dev, | ||
1691 | "you may need to download the firmware from " | ||
1692 | "http://developer.berlios.de/projects/at76c503a/\n"); | ||
1693 | goto exit; | ||
1694 | } | 4222 | } |
1695 | 4223 | ||
1696 | at76_dbg(DBG_FW, "got it."); | 4224 | BUG_ON(!priv->curr_bss); |
1697 | fwh = (struct at76_fw_header *)(fwe->fw->data); | ||
1698 | 4225 | ||
1699 | if (fwe->fw->size <= sizeof(*fwh)) { | 4226 | /* Not our BSSID or not for our STA, ignore */ |
1700 | dev_printk(KERN_ERR, &udev->dev, | 4227 | if (compare_ether_addr(mgmt->addr3, priv->curr_bss->bssid) |
1701 | "firmware is too short (0x%zx)\n", fwe->fw->size); | 4228 | || compare_ether_addr(priv->netdev->dev_addr, mgmt->addr1)) |
1702 | goto exit; | 4229 | return; |
4230 | |||
4231 | cancel_delayed_work(&priv->dwork_auth); | ||
4232 | if (status != WLAN_STATUS_SUCCESS) { | ||
4233 | /* try to join next bss */ | ||
4234 | at76_set_mac_state(priv, MAC_JOINING); | ||
4235 | schedule_work(&priv->work_join); | ||
4236 | return; | ||
1703 | } | 4237 | } |
1704 | 4238 | ||
1705 | /* CRC currently not checked */ | 4239 | if (priv->auth_mode == WLAN_AUTH_OPEN || seq_nr == 4) { |
1706 | fwe->board_type = le32_to_cpu(fwh->board_type); | 4240 | priv->retries = ASSOC_RETRIES; |
1707 | if (fwe->board_type != board_type) { | 4241 | at76_set_mac_state(priv, MAC_ASSOC); |
1708 | dev_printk(KERN_ERR, &udev->dev, | 4242 | at76_assoc_req(priv, priv->curr_bss); |
1709 | "board type mismatch, requested %u, got %u\n", | 4243 | at76_dbg(DBG_MGMT_TIMER, |
1710 | board_type, fwe->board_type); | 4244 | "%s:%d: starting mgmt_timer + HZ", __func__, __LINE__); |
1711 | goto exit; | 4245 | schedule_delayed_work(&priv->dwork_assoc, ASSOC_TIMEOUT); |
4246 | return; | ||
1712 | } | 4247 | } |
1713 | 4248 | ||
1714 | fwe->fw_version.major = fwh->major; | 4249 | WARN_ON(seq_nr != 2); |
1715 | fwe->fw_version.minor = fwh->minor; | 4250 | at76_auth_req(priv, priv->curr_bss, seq_nr + 1, resp->info_element); |
1716 | fwe->fw_version.patch = fwh->patch; | 4251 | at76_dbg(DBG_MGMT_TIMER, "%s:%d: starting mgmt_timer + HZ", __func__, |
1717 | fwe->fw_version.build = fwh->build; | 4252 | __LINE__); |
4253 | schedule_delayed_work(&priv->dwork_auth, AUTH_TIMEOUT); | ||
4254 | } | ||
1718 | 4255 | ||
1719 | str = (char *)fwh + le32_to_cpu(fwh->str_offset); | 4256 | static void at76_rx_mgmt_deauth(struct at76_priv *priv, |
1720 | fwe->intfw = (u8 *)fwh + le32_to_cpu(fwh->int_fw_offset); | 4257 | struct at76_rx_buffer *buf) |
1721 | fwe->intfw_size = le32_to_cpu(fwh->int_fw_len); | 4258 | { |
1722 | fwe->extfw = (u8 *)fwh + le32_to_cpu(fwh->ext_fw_offset); | 4259 | struct ieee80211_disassoc *resp = |
1723 | fwe->extfw_size = le32_to_cpu(fwh->ext_fw_len); | 4260 | (struct ieee80211_disassoc *)buf->packet; |
4261 | struct ieee80211_hdr_3addr *mgmt = &resp->header; | ||
4262 | |||
4263 | at76_dbg(DBG_RX_MGMT | DBG_PROGRESS, | ||
4264 | "%s: rx DeAuth bssid %s reason 0x%04x destination %s", | ||
4265 | priv->netdev->name, mac2str(mgmt->addr3), | ||
4266 | le16_to_cpu(resp->reason), mac2str(mgmt->addr1)); | ||
4267 | |||
4268 | if (priv->mac_state != MAC_AUTH && priv->mac_state != MAC_ASSOC | ||
4269 | && priv->mac_state != MAC_CONNECTED) { | ||
4270 | printk(KERN_INFO "%s: DeAuth in state %s ignored\n", | ||
4271 | priv->netdev->name, mac_states[priv->mac_state]); | ||
4272 | return; | ||
4273 | } | ||
1724 | 4274 | ||
1725 | fwe->loaded = 1; | 4275 | BUG_ON(!priv->curr_bss); |
1726 | 4276 | ||
1727 | dev_printk(KERN_DEBUG, &udev->dev, | 4277 | /* Not our BSSID, ignore */ |
1728 | "using firmware %s (version %d.%d.%d-%d)\n", | 4278 | if (compare_ether_addr(mgmt->addr3, priv->curr_bss->bssid)) |
1729 | fwe->fwname, fwh->major, fwh->minor, fwh->patch, fwh->build); | 4279 | return; |
1730 | 4280 | ||
1731 | at76_dbg(DBG_DEVSTART, "board %u, int %d:%d, ext %d:%d", board_type, | 4281 | /* Not for our STA and not broadcast, ignore */ |
1732 | le32_to_cpu(fwh->int_fw_offset), le32_to_cpu(fwh->int_fw_len), | 4282 | if (compare_ether_addr(priv->netdev->dev_addr, mgmt->addr1) |
1733 | le32_to_cpu(fwh->ext_fw_offset), le32_to_cpu(fwh->ext_fw_len)); | 4283 | && !is_broadcast_ether_addr(mgmt->addr1)) |
1734 | at76_dbg(DBG_DEVSTART, "firmware id %s", str); | 4284 | return; |
1735 | 4285 | ||
1736 | exit: | 4286 | if (priv->mac_state == MAC_CONNECTED) |
1737 | mutex_unlock(&fw_mutex); | 4287 | at76_iwevent_bss_disconnect(priv->netdev); |
1738 | 4288 | ||
1739 | if (fwe->loaded) | 4289 | at76_set_mac_state(priv, MAC_JOINING); |
1740 | return fwe; | 4290 | schedule_work(&priv->work_join); |
1741 | else | 4291 | cancel_delayed_work(&priv->dwork_get_scan); |
1742 | return NULL; | 4292 | cancel_delayed_work(&priv->dwork_beacon); |
4293 | cancel_delayed_work(&priv->dwork_auth); | ||
4294 | cancel_delayed_work(&priv->dwork_assoc); | ||
1743 | } | 4295 | } |
1744 | 4296 | ||
1745 | static void at76_mac80211_tx_callback(struct urb *urb) | 4297 | static void at76_rx_mgmt_beacon(struct at76_priv *priv, |
4298 | struct at76_rx_buffer *buf) | ||
1746 | { | 4299 | { |
1747 | struct at76_priv *priv = urb->context; | 4300 | int varpar_len; |
1748 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(priv->tx_skb); | 4301 | /* beacon content */ |
4302 | struct ieee80211_beacon *bdata = (struct ieee80211_beacon *)buf->packet; | ||
4303 | struct ieee80211_hdr_3addr *mgmt = &bdata->header; | ||
4304 | |||
4305 | struct list_head *lptr; | ||
4306 | struct bss_info *match; /* entry matching addr3 with its bssid */ | ||
4307 | int new_entry = 0; | ||
4308 | int len; | ||
4309 | struct ieee80211_info_element *ie; | ||
4310 | int have_ssid = 0; | ||
4311 | int have_rates = 0; | ||
4312 | int have_channel = 0; | ||
4313 | int keep_going = 1; | ||
4314 | unsigned long flags; | ||
4315 | |||
4316 | spin_lock_irqsave(&priv->bss_list_spinlock, flags); | ||
4317 | if (priv->mac_state == MAC_CONNECTED) { | ||
4318 | /* in state MAC_CONNECTED we use the mgmt_timer to control | ||
4319 | the beacon of the BSS */ | ||
4320 | BUG_ON(!priv->curr_bss); | ||
4321 | |||
4322 | if (!compare_ether_addr(priv->curr_bss->bssid, mgmt->addr3)) { | ||
4323 | /* We got our AP's beacon, defer the timeout handler. | ||
4324 | Kill pending work first, as schedule_delayed_work() | ||
4325 | won't do it. */ | ||
4326 | cancel_delayed_work(&priv->dwork_beacon); | ||
4327 | schedule_delayed_work(&priv->dwork_beacon, | ||
4328 | BEACON_TIMEOUT); | ||
4329 | priv->curr_bss->rssi = buf->rssi; | ||
4330 | priv->beacons_received++; | ||
4331 | goto exit; | ||
4332 | } | ||
4333 | } | ||
1749 | 4334 | ||
1750 | at76_dbg(DBG_MAC80211, "%s()", __func__); | 4335 | /* look if we have this BSS already in the list */ |
4336 | match = NULL; | ||
1751 | 4337 | ||
1752 | switch (urb->status) { | 4338 | if (!list_empty(&priv->bss_list)) { |
1753 | case 0: | 4339 | list_for_each(lptr, &priv->bss_list) { |
1754 | /* success */ | 4340 | struct bss_info *bss_ptr = |
1755 | /* FIXME: | 4341 | list_entry(lptr, struct bss_info, list); |
1756 | * is the frame really ACKed when tx_callback is called ? */ | 4342 | if (!compare_ether_addr(bss_ptr->bssid, mgmt->addr3)) { |
1757 | info->flags |= IEEE80211_TX_STAT_ACK; | 4343 | match = bss_ptr; |
1758 | break; | 4344 | break; |
1759 | case -ENOENT: | 4345 | } |
1760 | case -ECONNRESET: | 4346 | } |
1761 | /* fail, urb has been unlinked */ | ||
1762 | /* FIXME: add error message */ | ||
1763 | break; | ||
1764 | default: | ||
1765 | at76_dbg(DBG_URB, "%s - nonzero tx status received: %d", | ||
1766 | __func__, urb->status); | ||
1767 | break; | ||
1768 | } | 4347 | } |
1769 | 4348 | ||
1770 | memset(&info->status, 0, sizeof(info->status)); | 4349 | if (!match) { |
4350 | /* BSS not in the list - append it */ | ||
4351 | match = kzalloc(sizeof(struct bss_info), GFP_ATOMIC); | ||
4352 | if (!match) { | ||
4353 | at76_dbg(DBG_BSS_TABLE, | ||
4354 | "%s: cannot kmalloc new bss info (%zd byte)", | ||
4355 | priv->netdev->name, sizeof(struct bss_info)); | ||
4356 | goto exit; | ||
4357 | } | ||
4358 | new_entry = 1; | ||
4359 | list_add_tail(&match->list, &priv->bss_list); | ||
4360 | } | ||
1771 | 4361 | ||
1772 | ieee80211_tx_status_irqsafe(priv->hw, priv->tx_skb); | 4362 | match->capa = le16_to_cpu(bdata->capability); |
4363 | match->beacon_interval = le16_to_cpu(bdata->beacon_interval); | ||
4364 | match->rssi = buf->rssi; | ||
4365 | match->link_qual = buf->link_quality; | ||
4366 | match->noise_level = buf->noise_level; | ||
4367 | memcpy(match->bssid, mgmt->addr3, ETH_ALEN); | ||
4368 | at76_dbg(DBG_RX_BEACON, "%s: bssid %s", priv->netdev->name, | ||
4369 | mac2str(match->bssid)); | ||
4370 | |||
4371 | ie = bdata->info_element; | ||
4372 | |||
4373 | /* length of var length beacon parameters */ | ||
4374 | varpar_len = min_t(int, le16_to_cpu(buf->wlength) - | ||
4375 | sizeof(struct ieee80211_beacon), | ||
4376 | BEACON_MAX_DATA_LENGTH); | ||
4377 | |||
4378 | /* This routine steps through the bdata->data array to get | ||
4379 | * some useful information about the access point. | ||
4380 | * Currently, this implementation supports receipt of: SSID, | ||
4381 | * supported transfer rates and channel, in any order, with some | ||
4382 | * tolerance for intermittent unknown codes (although this | ||
4383 | * functionality may not be necessary as the useful information will | ||
4384 | * usually arrive in consecutively, but there have been some | ||
4385 | * reports of some of the useful information fields arriving in a | ||
4386 | * different order). | ||
4387 | * It does not support any more IE types although MFIE_TYPE_TIM may | ||
4388 | * be supported (on my AP at least). | ||
4389 | * The bdata->data array is about 1500 bytes long but only ~36 of those | ||
4390 | * bytes are useful, hence the have_ssid etc optimizations. */ | ||
4391 | |||
4392 | while (keep_going && | ||
4393 | ((&ie->data[ie->len] - (u8 *)bdata->info_element) <= | ||
4394 | varpar_len)) { | ||
4395 | |||
4396 | switch (ie->id) { | ||
4397 | |||
4398 | case MFIE_TYPE_SSID: | ||
4399 | if (have_ssid) | ||
4400 | break; | ||
1773 | 4401 | ||
1774 | priv->tx_skb = NULL; | 4402 | len = min_t(int, IW_ESSID_MAX_SIZE, ie->len); |
1775 | 4403 | ||
1776 | ieee80211_wake_queues(priv->hw); | 4404 | /* we copy only if this is a new entry, |
1777 | } | 4405 | or the incoming SSID is not a hidden SSID. This |
4406 | will protect us from overwriting a real SSID read | ||
4407 | in a ProbeResponse with a hidden one from a | ||
4408 | following beacon. */ | ||
4409 | if (!new_entry && at76_is_hidden_ssid(ie->data, len)) { | ||
4410 | have_ssid = 1; | ||
4411 | break; | ||
4412 | } | ||
1778 | 4413 | ||
1779 | static int at76_mac80211_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | 4414 | match->ssid_len = len; |
1780 | { | 4415 | memcpy(match->ssid, ie->data, len); |
1781 | struct at76_priv *priv = hw->priv; | 4416 | at76_dbg(DBG_RX_BEACON, "%s: SSID - %.*s", |
1782 | struct at76_tx_buffer *tx_buffer = priv->bulk_out_buffer; | 4417 | priv->netdev->name, len, match->ssid); |
1783 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | 4418 | have_ssid = 1; |
1784 | int padding, submit_len, ret; | 4419 | break; |
1785 | 4420 | ||
1786 | at76_dbg(DBG_MAC80211, "%s()", __func__); | 4421 | case MFIE_TYPE_RATES: |
4422 | if (have_rates) | ||
4423 | break; | ||
1787 | 4424 | ||
1788 | if (priv->tx_urb->status == -EINPROGRESS) { | 4425 | match->rates_len = |
1789 | printk(KERN_ERR "%s: %s called while tx urb is pending\n", | 4426 | min_t(int, sizeof(match->rates), ie->len); |
1790 | wiphy_name(priv->hw->wiphy), __func__); | 4427 | memcpy(match->rates, ie->data, match->rates_len); |
1791 | return NETDEV_TX_BUSY; | 4428 | have_rates = 1; |
1792 | } | 4429 | at76_dbg(DBG_RX_BEACON, "%s: SUPPORTED RATES %s", |
4430 | priv->netdev->name, | ||
4431 | hex2str(ie->data, ie->len)); | ||
4432 | break; | ||
1793 | 4433 | ||
1794 | ieee80211_stop_queues(hw); | 4434 | case MFIE_TYPE_DS_SET: |
4435 | if (have_channel) | ||
4436 | break; | ||
1795 | 4437 | ||
1796 | at76_ledtrig_tx_activity(); /* tell ledtrigger we send a packet */ | 4438 | match->channel = ie->data[0]; |
4439 | have_channel = 1; | ||
4440 | at76_dbg(DBG_RX_BEACON, "%s: CHANNEL - %d", | ||
4441 | priv->netdev->name, match->channel); | ||
4442 | break; | ||
1797 | 4443 | ||
1798 | WARN_ON(priv->tx_skb != NULL); | 4444 | case MFIE_TYPE_CF_SET: |
4445 | case MFIE_TYPE_TIM: | ||
4446 | case MFIE_TYPE_IBSS_SET: | ||
4447 | default: | ||
4448 | at76_dbg(DBG_RX_BEACON, "%s: beacon IE id %d len %d %s", | ||
4449 | priv->netdev->name, ie->id, ie->len, | ||
4450 | hex2str(ie->data, ie->len)); | ||
4451 | break; | ||
4452 | } | ||
1799 | 4453 | ||
1800 | priv->tx_skb = skb; | 4454 | /* advance to the next informational element */ |
1801 | padding = at76_calc_padding(skb->len); | 4455 | next_ie(&ie); |
1802 | submit_len = AT76_TX_HDRLEN + skb->len + padding; | ||
1803 | 4456 | ||
1804 | /* setup 'Atmel' header */ | 4457 | /* Optimization: after all, the bdata->data array is |
1805 | memset(tx_buffer, 0, sizeof(*tx_buffer)); | 4458 | * varpar_len bytes long, whereas we get all of the useful |
1806 | tx_buffer->padding = padding; | 4459 | * information after only ~36 bytes, this saves us a lot of |
1807 | tx_buffer->wlength = cpu_to_le16(skb->len); | 4460 | * time (and trouble as the remaining portion of the array |
1808 | tx_buffer->tx_rate = ieee80211_get_tx_rate(hw, info)->hw_value; | 4461 | * could be full of junk) |
1809 | if (FIRMWARE_IS_WPA(priv->fw_version) && info->control.hw_key) { | 4462 | * Comment this out if you want to see what other information |
1810 | tx_buffer->key_id = (info->control.hw_key->keyidx); | 4463 | * comes from the AP - although little of it may be useful */ |
1811 | tx_buffer->cipher_type = | 4464 | } |
1812 | priv->keys[info->control.hw_key->keyidx].cipher; | ||
1813 | tx_buffer->cipher_length = | ||
1814 | priv->keys[info->control.hw_key->keyidx].keylen; | ||
1815 | tx_buffer->reserved = 0; | ||
1816 | } else { | ||
1817 | tx_buffer->key_id = 0; | ||
1818 | tx_buffer->cipher_type = 0; | ||
1819 | tx_buffer->cipher_length = 0; | ||
1820 | tx_buffer->reserved = 0; | ||
1821 | }; | ||
1822 | /* memset(tx_buffer->reserved, 0, sizeof(tx_buffer->reserved)); */ | ||
1823 | memcpy(tx_buffer->packet, skb->data, skb->len); | ||
1824 | 4465 | ||
1825 | at76_dbg(DBG_TX_DATA, "%s tx: wlen 0x%x pad 0x%x rate %d hdr", | 4466 | at76_dbg(DBG_RX_BEACON, "%s: Finished processing beacon data", |
1826 | wiphy_name(priv->hw->wiphy), le16_to_cpu(tx_buffer->wlength), | 4467 | priv->netdev->name); |
1827 | tx_buffer->padding, tx_buffer->tx_rate); | ||
1828 | 4468 | ||
1829 | /* send stuff */ | 4469 | match->last_rx = jiffies; /* record last rx of beacon */ |
1830 | at76_dbg_dump(DBG_TX_DATA_CONTENT, tx_buffer, submit_len, | ||
1831 | "%s(): tx_buffer %d bytes:", __func__, submit_len); | ||
1832 | usb_fill_bulk_urb(priv->tx_urb, priv->udev, priv->tx_pipe, tx_buffer, | ||
1833 | submit_len, at76_mac80211_tx_callback, priv); | ||
1834 | ret = usb_submit_urb(priv->tx_urb, GFP_ATOMIC); | ||
1835 | if (ret) { | ||
1836 | printk(KERN_ERR "%s: error in tx submit urb: %d\n", | ||
1837 | wiphy_name(priv->hw->wiphy), ret); | ||
1838 | if (ret == -EINVAL) | ||
1839 | printk(KERN_ERR | ||
1840 | "%s: -EINVAL: tx urb %p hcpriv %p complete %p\n", | ||
1841 | wiphy_name(priv->hw->wiphy), priv->tx_urb, | ||
1842 | priv->tx_urb->hcpriv, priv->tx_urb->complete); | ||
1843 | } | ||
1844 | 4470 | ||
1845 | return 0; | 4471 | exit: |
4472 | spin_unlock_irqrestore(&priv->bss_list_spinlock, flags); | ||
1846 | } | 4473 | } |
1847 | 4474 | ||
1848 | static int at76_mac80211_start(struct ieee80211_hw *hw) | 4475 | /* Calculate the link level from a given rx_buffer */ |
4476 | static void at76_calc_level(struct at76_priv *priv, struct at76_rx_buffer *buf, | ||
4477 | struct iw_quality *qual) | ||
1849 | { | 4478 | { |
1850 | struct at76_priv *priv = hw->priv; | 4479 | /* just a guess for now, might be different for other chips */ |
1851 | int ret; | 4480 | int max_rssi = 42; |
1852 | |||
1853 | at76_dbg(DBG_MAC80211, "%s()", __func__); | ||
1854 | 4481 | ||
1855 | mutex_lock(&priv->mtx); | 4482 | qual->level = (buf->rssi * 100 / max_rssi); |
1856 | 4483 | if (qual->level > 100) | |
1857 | ret = at76_submit_rx_urb(priv); | 4484 | qual->level = 100; |
1858 | if (ret < 0) { | 4485 | qual->updated |= IW_QUAL_LEVEL_UPDATED; |
1859 | printk(KERN_ERR "%s: open: submit_rx_urb failed: %d\n", | 4486 | } |
1860 | wiphy_name(priv->hw->wiphy), ret); | ||
1861 | goto error; | ||
1862 | } | ||
1863 | 4487 | ||
1864 | at76_startup_device(priv); | 4488 | /* Calculate the link quality from a given rx_buffer */ |
4489 | static void at76_calc_qual(struct at76_priv *priv, struct at76_rx_buffer *buf, | ||
4490 | struct iw_quality *qual) | ||
4491 | { | ||
4492 | if (at76_is_intersil(priv->board_type)) | ||
4493 | qual->qual = buf->link_quality; | ||
4494 | else { | ||
4495 | unsigned long elapsed; | ||
1865 | 4496 | ||
1866 | at76_start_monitor(priv); | 4497 | /* Update qual at most once a second */ |
4498 | elapsed = jiffies - priv->beacons_last_qual; | ||
4499 | if (elapsed < 1 * HZ) | ||
4500 | return; | ||
1867 | 4501 | ||
1868 | error: | 4502 | qual->qual = qual->level * priv->beacons_received * |
1869 | mutex_unlock(&priv->mtx); | 4503 | msecs_to_jiffies(priv->beacon_period) / elapsed; |
1870 | 4504 | ||
1871 | return 0; | 4505 | priv->beacons_last_qual = jiffies; |
4506 | priv->beacons_received = 0; | ||
4507 | } | ||
4508 | qual->qual = (qual->qual > 100) ? 100 : qual->qual; | ||
4509 | qual->updated |= IW_QUAL_QUAL_UPDATED; | ||
1872 | } | 4510 | } |
1873 | 4511 | ||
1874 | static void at76_mac80211_stop(struct ieee80211_hw *hw) | 4512 | /* Calculate the noise quality from a given rx_buffer */ |
4513 | static void at76_calc_noise(struct at76_priv *priv, struct at76_rx_buffer *buf, | ||
4514 | struct iw_quality *qual) | ||
1875 | { | 4515 | { |
1876 | struct at76_priv *priv = hw->priv; | 4516 | qual->noise = 0; |
1877 | 4517 | qual->updated |= IW_QUAL_NOISE_INVALID; | |
1878 | at76_dbg(DBG_MAC80211, "%s()", __func__); | 4518 | } |
1879 | |||
1880 | mutex_lock(&priv->mtx); | ||
1881 | 4519 | ||
1882 | if (!priv->device_unplugged) { | 4520 | static void at76_update_wstats(struct at76_priv *priv, |
1883 | /* We are called by "ifconfig ethX down", not because the | 4521 | struct at76_rx_buffer *buf) |
1884 | * device is not available anymore. */ | 4522 | { |
1885 | if (at76_set_radio(priv, 0) == 1) | 4523 | struct iw_quality *qual = &priv->wstats.qual; |
1886 | at76_wait_completion(priv, CMD_RADIO_ON); | ||
1887 | 4524 | ||
1888 | /* We unlink rx_urb because at76_open() re-submits it. | 4525 | if (buf->rssi && priv->mac_state == MAC_CONNECTED) { |
1889 | * If unplugged, at76_delete_device() takes care of it. */ | 4526 | qual->updated = 0; |
1890 | usb_kill_urb(priv->rx_urb); | 4527 | at76_calc_level(priv, buf, qual); |
4528 | at76_calc_qual(priv, buf, qual); | ||
4529 | at76_calc_noise(priv, buf, qual); | ||
4530 | } else { | ||
4531 | qual->qual = 0; | ||
4532 | qual->level = 0; | ||
4533 | qual->noise = 0; | ||
4534 | qual->updated = IW_QUAL_ALL_INVALID; | ||
1891 | } | 4535 | } |
1892 | |||
1893 | mutex_unlock(&priv->mtx); | ||
1894 | } | 4536 | } |
1895 | 4537 | ||
1896 | static int at76_add_interface(struct ieee80211_hw *hw, | 4538 | static void at76_rx_mgmt(struct at76_priv *priv, struct at76_rx_buffer *buf) |
1897 | struct ieee80211_if_init_conf *conf) | ||
1898 | { | 4539 | { |
1899 | struct at76_priv *priv = hw->priv; | 4540 | struct ieee80211_hdr_3addr *mgmt = |
1900 | int ret = 0; | 4541 | (struct ieee80211_hdr_3addr *)buf->packet; |
4542 | u16 framectl = le16_to_cpu(mgmt->frame_ctl); | ||
4543 | |||
4544 | /* update wstats */ | ||
4545 | if (priv->mac_state != MAC_INIT && priv->mac_state != MAC_SCANNING) { | ||
4546 | /* jal: this is a dirty hack needed by Tim in ad-hoc mode */ | ||
4547 | /* Data packets always seem to have a 0 link level, so we | ||
4548 | only read link quality info from management packets. | ||
4549 | Atmel driver actually averages the present, and previous | ||
4550 | values, we just present the raw value at the moment - TJS */ | ||
4551 | if (priv->iw_mode == IW_MODE_ADHOC | ||
4552 | || (priv->curr_bss | ||
4553 | && !compare_ether_addr(mgmt->addr3, | ||
4554 | priv->curr_bss->bssid))) | ||
4555 | at76_update_wstats(priv, buf); | ||
4556 | } | ||
1901 | 4557 | ||
1902 | at76_dbg(DBG_MAC80211, "%s()", __func__); | 4558 | at76_dbg(DBG_RX_MGMT_CONTENT, "%s rx mgmt framectl 0x%x %s", |
4559 | priv->netdev->name, framectl, | ||
4560 | hex2str(mgmt, le16_to_cpu(buf->wlength))); | ||
1903 | 4561 | ||
1904 | mutex_lock(&priv->mtx); | 4562 | switch (framectl & IEEE80211_FCTL_STYPE) { |
4563 | case IEEE80211_STYPE_BEACON: | ||
4564 | case IEEE80211_STYPE_PROBE_RESP: | ||
4565 | at76_rx_mgmt_beacon(priv, buf); | ||
4566 | break; | ||
4567 | |||
4568 | case IEEE80211_STYPE_ASSOC_RESP: | ||
4569 | at76_rx_mgmt_assoc(priv, buf); | ||
4570 | break; | ||
1905 | 4571 | ||
1906 | switch (conf->type) { | 4572 | case IEEE80211_STYPE_DISASSOC: |
1907 | case NL80211_IFTYPE_STATION: | 4573 | at76_rx_mgmt_disassoc(priv, buf); |
1908 | priv->iw_mode = IW_MODE_INFRA; | ||
1909 | break; | 4574 | break; |
4575 | |||
4576 | case IEEE80211_STYPE_AUTH: | ||
4577 | at76_rx_mgmt_auth(priv, buf); | ||
4578 | break; | ||
4579 | |||
4580 | case IEEE80211_STYPE_DEAUTH: | ||
4581 | at76_rx_mgmt_deauth(priv, buf); | ||
4582 | break; | ||
4583 | |||
1910 | default: | 4584 | default: |
1911 | ret = -EOPNOTSUPP; | 4585 | printk(KERN_DEBUG "%s: ignoring frame with framectl 0x%04x\n", |
1912 | goto exit; | 4586 | priv->netdev->name, framectl); |
1913 | } | 4587 | } |
1914 | 4588 | ||
1915 | exit: | 4589 | return; |
1916 | mutex_unlock(&priv->mtx); | ||
1917 | |||
1918 | return ret; | ||
1919 | } | 4590 | } |
1920 | 4591 | ||
1921 | static void at76_remove_interface(struct ieee80211_hw *hw, | 4592 | /* Convert the 802.11 header into an ethernet-style header, make skb |
1922 | struct ieee80211_if_init_conf *conf) | 4593 | * ready for consumption by netif_rx() */ |
4594 | static void at76_ieee80211_to_eth(struct sk_buff *skb, int iw_mode) | ||
1923 | { | 4595 | { |
1924 | at76_dbg(DBG_MAC80211, "%s()", __func__); | 4596 | struct ieee80211_hdr_3addr *i802_11_hdr; |
1925 | } | 4597 | struct ethhdr *eth_hdr_p; |
4598 | u8 *src_addr; | ||
4599 | u8 *dest_addr; | ||
1926 | 4600 | ||
1927 | static int at76_join(struct at76_priv *priv) | 4601 | i802_11_hdr = (struct ieee80211_hdr_3addr *)skb->data; |
1928 | { | ||
1929 | struct at76_req_join join; | ||
1930 | int ret; | ||
1931 | 4602 | ||
1932 | memset(&join, 0, sizeof(struct at76_req_join)); | 4603 | /* That would be the ethernet header if the hardware converted |
1933 | memcpy(join.essid, priv->essid, priv->essid_size); | 4604 | * the frame for us. Make sure the source and the destination |
1934 | join.essid_size = priv->essid_size; | 4605 | * match the 802.11 header. Which hardware does it? */ |
1935 | memcpy(join.bssid, priv->bssid, ETH_ALEN); | 4606 | eth_hdr_p = (struct ethhdr *)skb_pull(skb, IEEE80211_3ADDR_LEN); |
1936 | join.bss_type = INFRASTRUCTURE_MODE; | ||
1937 | join.channel = priv->channel; | ||
1938 | join.timeout = cpu_to_le16(2000); | ||
1939 | 4607 | ||
1940 | at76_dbg(DBG_MAC80211, "%s: sending CMD_JOIN", __func__); | 4608 | dest_addr = i802_11_hdr->addr1; |
1941 | ret = at76_set_card_command(priv->udev, CMD_JOIN, &join, | 4609 | if (iw_mode == IW_MODE_ADHOC) |
1942 | sizeof(struct at76_req_join)); | 4610 | src_addr = i802_11_hdr->addr2; |
4611 | else | ||
4612 | src_addr = i802_11_hdr->addr3; | ||
1943 | 4613 | ||
1944 | if (ret < 0) { | 4614 | if (!compare_ether_addr(eth_hdr_p->h_source, src_addr) && |
1945 | printk(KERN_ERR "%s: at76_set_card_command failed: %d\n", | 4615 | !compare_ether_addr(eth_hdr_p->h_dest, dest_addr)) |
1946 | wiphy_name(priv->hw->wiphy), ret); | 4616 | /* Yes, we already have an ethernet header */ |
1947 | return 0; | 4617 | skb_reset_mac_header(skb); |
1948 | } | 4618 | else { |
4619 | u16 len; | ||
4620 | |||
4621 | /* Need to build an ethernet header */ | ||
4622 | if (!memcmp(skb->data, snapsig, sizeof(snapsig))) { | ||
4623 | /* SNAP frame - decapsulate, keep proto */ | ||
4624 | skb_push(skb, offsetof(struct ethhdr, h_proto) - | ||
4625 | sizeof(rfc1042sig)); | ||
4626 | len = 0; | ||
4627 | } else { | ||
4628 | /* 802.3 frame, proto is length */ | ||
4629 | len = skb->len; | ||
4630 | skb_push(skb, ETH_HLEN); | ||
4631 | } | ||
1949 | 4632 | ||
1950 | ret = at76_wait_completion(priv, CMD_JOIN); | 4633 | skb_reset_mac_header(skb); |
1951 | at76_dbg(DBG_MAC80211, "%s: CMD_JOIN returned: 0x%02x", __func__, ret); | 4634 | eth_hdr_p = eth_hdr(skb); |
1952 | if (ret != CMD_STATUS_COMPLETE) { | 4635 | /* This needs to be done in this order (eth_hdr_p->h_dest may |
1953 | printk(KERN_ERR "%s: at76_wait_completion failed: %d\n", | 4636 | * overlap src_addr) */ |
1954 | wiphy_name(priv->hw->wiphy), ret); | 4637 | memcpy(eth_hdr_p->h_source, src_addr, ETH_ALEN); |
1955 | return 0; | 4638 | memcpy(eth_hdr_p->h_dest, dest_addr, ETH_ALEN); |
4639 | if (len) | ||
4640 | eth_hdr_p->h_proto = htons(len); | ||
1956 | } | 4641 | } |
1957 | 4642 | ||
1958 | at76_set_tkip_bssid(priv, priv->bssid); | 4643 | skb->protocol = eth_type_trans(skb, skb->dev); |
1959 | at76_set_pm_mode(priv); | ||
1960 | |||
1961 | return 0; | ||
1962 | } | 4644 | } |
1963 | 4645 | ||
1964 | static void at76_dwork_hw_scan(struct work_struct *work) | 4646 | /* Check for fragmented data in priv->rx_skb. If the packet was no fragment |
4647 | or it was the last of a fragment set a skb containing the whole packet | ||
4648 | is returned for further processing. Otherwise we get NULL and are | ||
4649 | done and the packet is either stored inside the fragment buffer | ||
4650 | or thrown away. Every returned skb starts with the ieee802_11 header | ||
4651 | and contains _no_ FCS at the end */ | ||
4652 | static struct sk_buff *at76_check_for_rx_frags(struct at76_priv *priv) | ||
1965 | { | 4653 | { |
1966 | struct at76_priv *priv = container_of(work, struct at76_priv, | 4654 | struct sk_buff *skb = priv->rx_skb; |
1967 | dwork_hw_scan.work); | 4655 | struct at76_rx_buffer *buf = (struct at76_rx_buffer *)skb->data; |
1968 | int ret; | 4656 | struct ieee80211_hdr_3addr *i802_11_hdr = |
4657 | (struct ieee80211_hdr_3addr *)buf->packet; | ||
4658 | /* seq_ctrl, fragment_number, sequence number of new packet */ | ||
4659 | u16 sctl = le16_to_cpu(i802_11_hdr->seq_ctl); | ||
4660 | u16 fragnr = sctl & 0xf; | ||
4661 | u16 seqnr = sctl >> 4; | ||
4662 | u16 frame_ctl = le16_to_cpu(i802_11_hdr->frame_ctl); | ||
1969 | 4663 | ||
1970 | ret = at76_get_cmd_status(priv->udev, CMD_SCAN); | 4664 | /* Length including the IEEE802.11 header, but without the trailing |
1971 | at76_dbg(DBG_MAC80211, "%s: CMD_SCAN status 0x%02x", __func__, ret); | 4665 | * FCS and without the Atmel Rx header */ |
4666 | int length = le16_to_cpu(buf->wlength) - IEEE80211_FCS_LEN; | ||
1972 | 4667 | ||
1973 | /* FIXME: add maximum time for scan to complete */ | 4668 | /* where does the data payload start in skb->data ? */ |
4669 | u8 *data = i802_11_hdr->payload; | ||
1974 | 4670 | ||
1975 | if (ret != CMD_STATUS_COMPLETE) { | 4671 | /* length of payload, excl. the trailing FCS */ |
1976 | queue_delayed_work(priv->hw->workqueue, &priv->dwork_hw_scan, | 4672 | int data_len = length - IEEE80211_3ADDR_LEN; |
1977 | SCAN_POLL_INTERVAL); | 4673 | |
1978 | goto exit; | 4674 | int i; |
4675 | struct rx_data_buf *bptr, *optr; | ||
4676 | unsigned long oldest = ~0UL; | ||
4677 | |||
4678 | at76_dbg(DBG_RX_FRAGS, | ||
4679 | "%s: rx data frame_ctl %04x addr2 %s seq/frag %d/%d " | ||
4680 | "length %d data %d: %s ...", priv->netdev->name, frame_ctl, | ||
4681 | mac2str(i802_11_hdr->addr2), seqnr, fragnr, length, data_len, | ||
4682 | hex2str(data, 32)); | ||
4683 | |||
4684 | at76_dbg(DBG_RX_FRAGS_SKB, "%s: incoming skb: head %p data %p " | ||
4685 | "tail %p end %p len %d", priv->netdev->name, skb->head, | ||
4686 | skb->data, skb_tail_pointer(skb), skb_end_pointer(skb), | ||
4687 | skb->len); | ||
4688 | |||
4689 | if (data_len < 0) { | ||
4690 | /* make sure data starts in the buffer */ | ||
4691 | printk(KERN_INFO "%s: data frame too short\n", | ||
4692 | priv->netdev->name); | ||
4693 | return NULL; | ||
1979 | } | 4694 | } |
1980 | 4695 | ||
1981 | ieee80211_scan_completed(priv->hw); | 4696 | WARN_ON(length <= AT76_RX_HDRLEN); |
4697 | if (length <= AT76_RX_HDRLEN) | ||
4698 | return NULL; | ||
1982 | 4699 | ||
1983 | if (is_valid_ether_addr(priv->bssid)) { | 4700 | /* remove the at76_rx_buffer header - we don't need it anymore */ |
1984 | ieee80211_wake_queues(priv->hw); | 4701 | /* we need the IEEE802.11 header (for the addresses) if this packet |
1985 | at76_join(priv); | 4702 | is the first of a chain */ |
4703 | skb_pull(skb, AT76_RX_HDRLEN); | ||
4704 | |||
4705 | /* remove FCS at end */ | ||
4706 | skb_trim(skb, length); | ||
4707 | |||
4708 | at76_dbg(DBG_RX_FRAGS_SKB, "%s: trimmed skb: head %p data %p tail %p " | ||
4709 | "end %p len %d data %p data_len %d", priv->netdev->name, | ||
4710 | skb->head, skb->data, skb_tail_pointer(skb), | ||
4711 | skb_end_pointer(skb), skb->len, data, data_len); | ||
4712 | |||
4713 | if (fragnr == 0 && !(frame_ctl & IEEE80211_FCTL_MOREFRAGS)) { | ||
4714 | /* unfragmented packet received */ | ||
4715 | /* Use a new skb for the next receive */ | ||
4716 | priv->rx_skb = NULL; | ||
4717 | at76_dbg(DBG_RX_FRAGS, "%s: unfragmented", priv->netdev->name); | ||
4718 | return skb; | ||
1986 | } | 4719 | } |
1987 | 4720 | ||
1988 | ieee80211_wake_queues(priv->hw); | 4721 | /* look if we've got a chain for the sender address. |
4722 | afterwards optr points to first free or the oldest entry, | ||
4723 | or, if i < NR_RX_DATA_BUF, bptr points to the entry for the | ||
4724 | sender address */ | ||
4725 | /* determining the oldest entry doesn't cope with jiffies wrapping | ||
4726 | but I don't care to delete a young entry at these rare moments ... */ | ||
4727 | |||
4728 | bptr = priv->rx_data; | ||
4729 | optr = NULL; | ||
4730 | for (i = 0; i < NR_RX_DATA_BUF; i++, bptr++) { | ||
4731 | if (!bptr->skb) { | ||
4732 | optr = bptr; | ||
4733 | oldest = 0UL; | ||
4734 | continue; | ||
4735 | } | ||
1989 | 4736 | ||
1990 | exit: | 4737 | if (!compare_ether_addr(i802_11_hdr->addr2, bptr->sender)) |
1991 | return; | 4738 | break; |
1992 | } | ||
1993 | 4739 | ||
1994 | static int at76_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) | 4740 | if (!optr) { |
1995 | { | 4741 | optr = bptr; |
1996 | struct at76_priv *priv = hw->priv; | 4742 | oldest = bptr->last_rx; |
1997 | struct at76_req_scan scan; | 4743 | } else if (bptr->last_rx < oldest) |
1998 | int ret; | 4744 | optr = bptr; |
4745 | } | ||
1999 | 4746 | ||
2000 | at76_dbg(DBG_MAC80211, "%s():", __func__); | 4747 | if (i < NR_RX_DATA_BUF) { |
2001 | at76_dbg_dump(DBG_MAC80211, ssid, len, "ssid %zd bytes:", len); | 4748 | |
4749 | at76_dbg(DBG_RX_FRAGS, "%s: %d. cacheentry (seq/frag = %d/%d) " | ||
4750 | "matched sender addr", | ||
4751 | priv->netdev->name, i, bptr->seqnr, bptr->fragnr); | ||
4752 | |||
4753 | /* bptr points to an entry for the sender address */ | ||
4754 | if (bptr->seqnr == seqnr) { | ||
4755 | int left; | ||
4756 | /* the fragment has the current sequence number */ | ||
4757 | if (((bptr->fragnr + 1) & 0xf) != fragnr) { | ||
4758 | /* wrong fragment number -> ignore it */ | ||
4759 | /* is & 0xf necessary above ??? */ | ||
4760 | at76_dbg(DBG_RX_FRAGS, | ||
4761 | "%s: frag nr mismatch: %d + 1 != %d", | ||
4762 | priv->netdev->name, bptr->fragnr, | ||
4763 | fragnr); | ||
4764 | return NULL; | ||
4765 | } | ||
4766 | bptr->last_rx = jiffies; | ||
4767 | /* the next following fragment number -> | ||
4768 | add the data at the end */ | ||
4769 | |||
4770 | /* for test only ??? */ | ||
4771 | left = skb_tailroom(bptr->skb); | ||
4772 | if (left < data_len) | ||
4773 | printk(KERN_INFO | ||
4774 | "%s: only %d byte free (need %d)\n", | ||
4775 | priv->netdev->name, left, data_len); | ||
4776 | else | ||
4777 | memcpy(skb_put(bptr->skb, data_len), data, | ||
4778 | data_len); | ||
4779 | |||
4780 | bptr->fragnr = fragnr; | ||
4781 | if (frame_ctl & IEEE80211_FCTL_MOREFRAGS) | ||
4782 | return NULL; | ||
4783 | |||
4784 | /* this was the last fragment - send it */ | ||
4785 | skb = bptr->skb; | ||
4786 | bptr->skb = NULL; /* free the entry */ | ||
4787 | at76_dbg(DBG_RX_FRAGS, "%s: last frag of seq %d", | ||
4788 | priv->netdev->name, seqnr); | ||
4789 | return skb; | ||
4790 | } | ||
2002 | 4791 | ||
2003 | mutex_lock(&priv->mtx); | 4792 | /* got another sequence number */ |
4793 | if (fragnr == 0) { | ||
4794 | /* it's the start of a new chain - replace the | ||
4795 | old one by this */ | ||
4796 | /* bptr->sender has the correct value already */ | ||
4797 | at76_dbg(DBG_RX_FRAGS, | ||
4798 | "%s: start of new seq %d, removing old seq %d", | ||
4799 | priv->netdev->name, seqnr, bptr->seqnr); | ||
4800 | bptr->seqnr = seqnr; | ||
4801 | bptr->fragnr = 0; | ||
4802 | bptr->last_rx = jiffies; | ||
4803 | /* swap bptr->skb and priv->rx_skb */ | ||
4804 | skb = bptr->skb; | ||
4805 | bptr->skb = priv->rx_skb; | ||
4806 | priv->rx_skb = skb; | ||
4807 | } else { | ||
4808 | /* it from the middle of a new chain -> | ||
4809 | delete the old entry and skip the new one */ | ||
4810 | at76_dbg(DBG_RX_FRAGS, | ||
4811 | "%s: middle of new seq %d (%d) " | ||
4812 | "removing old seq %d", | ||
4813 | priv->netdev->name, seqnr, fragnr, | ||
4814 | bptr->seqnr); | ||
4815 | dev_kfree_skb(bptr->skb); | ||
4816 | bptr->skb = NULL; | ||
4817 | } | ||
4818 | return NULL; | ||
4819 | } | ||
2004 | 4820 | ||
2005 | ieee80211_stop_queues(hw); | 4821 | /* if we didn't find a chain for the sender address, optr |
4822 | points either to the first free or the oldest entry */ | ||
2006 | 4823 | ||
2007 | memset(&scan, 0, sizeof(struct at76_req_scan)); | 4824 | if (fragnr != 0) { |
2008 | memset(scan.bssid, 0xFF, ETH_ALEN); | 4825 | /* this is not the begin of a fragment chain ... */ |
2009 | scan.scan_type = SCAN_TYPE_ACTIVE; | 4826 | at76_dbg(DBG_RX_FRAGS, |
2010 | if (priv->essid_size > 0) { | 4827 | "%s: no chain for non-first fragment (%d)", |
2011 | memcpy(scan.essid, ssid, len); | 4828 | priv->netdev->name, fragnr); |
2012 | scan.essid_size = len; | 4829 | return NULL; |
2013 | } | 4830 | } |
2014 | scan.min_channel_time = cpu_to_le16(priv->scan_min_time); | ||
2015 | scan.max_channel_time = cpu_to_le16(priv->scan_max_time); | ||
2016 | scan.probe_delay = cpu_to_le16(priv->scan_min_time * 1000); | ||
2017 | scan.international_scan = 0; | ||
2018 | 4831 | ||
2019 | at76_dbg(DBG_MAC80211, "%s: sending CMD_SCAN", __func__); | 4832 | BUG_ON(!optr); |
2020 | ret = at76_set_card_command(priv->udev, CMD_SCAN, &scan, sizeof(scan)); | 4833 | if (optr->skb) { |
4834 | /* swap the skb's */ | ||
4835 | skb = optr->skb; | ||
4836 | optr->skb = priv->rx_skb; | ||
4837 | priv->rx_skb = skb; | ||
2021 | 4838 | ||
2022 | if (ret < 0) { | 4839 | at76_dbg(DBG_RX_FRAGS, |
2023 | err("CMD_SCAN failed: %d", ret); | 4840 | "%s: free old contents: sender %s seq/frag %d/%d", |
2024 | goto exit; | 4841 | priv->netdev->name, mac2str(optr->sender), |
2025 | } | 4842 | optr->seqnr, optr->fragnr); |
2026 | 4843 | ||
2027 | queue_delayed_work(priv->hw->workqueue, &priv->dwork_hw_scan, | 4844 | } else { |
2028 | SCAN_POLL_INTERVAL); | 4845 | /* take the skb from priv->rx_skb */ |
4846 | optr->skb = priv->rx_skb; | ||
4847 | /* let at76_submit_rx_urb() allocate a new skb */ | ||
4848 | priv->rx_skb = NULL; | ||
2029 | 4849 | ||
2030 | exit: | 4850 | at76_dbg(DBG_RX_FRAGS, "%s: use a free entry", |
2031 | mutex_unlock(&priv->mtx); | 4851 | priv->netdev->name); |
4852 | } | ||
4853 | memcpy(optr->sender, i802_11_hdr->addr2, ETH_ALEN); | ||
4854 | optr->seqnr = seqnr; | ||
4855 | optr->fragnr = 0; | ||
4856 | optr->last_rx = jiffies; | ||
2032 | 4857 | ||
2033 | return 0; | 4858 | return NULL; |
2034 | } | 4859 | } |
2035 | 4860 | ||
2036 | static int at76_config(struct ieee80211_hw *hw, u32 changed) | 4861 | /* Rx interrupt: we expect the complete data buffer in priv->rx_skb */ |
4862 | static void at76_rx_data(struct at76_priv *priv) | ||
2037 | { | 4863 | { |
2038 | struct at76_priv *priv = hw->priv; | 4864 | struct net_device *netdev = priv->netdev; |
2039 | struct ieee80211_conf *conf = &hw->conf; | 4865 | struct net_device_stats *stats = &priv->stats; |
4866 | struct sk_buff *skb = priv->rx_skb; | ||
4867 | struct at76_rx_buffer *buf = (struct at76_rx_buffer *)skb->data; | ||
4868 | struct ieee80211_hdr_3addr *i802_11_hdr; | ||
4869 | int length = le16_to_cpu(buf->wlength); | ||
2040 | 4870 | ||
2041 | at76_dbg(DBG_MAC80211, "%s(): channel %d radio %d", | 4871 | at76_dbg(DBG_RX_DATA, "%s received data packet: %s", netdev->name, |
2042 | __func__, conf->channel->hw_value, conf->radio_enabled); | 4872 | hex2str(skb->data, AT76_RX_HDRLEN)); |
2043 | at76_dbg_dump(DBG_MAC80211, priv->essid, priv->essid_size, "ssid:"); | ||
2044 | at76_dbg_dump(DBG_MAC80211, priv->bssid, ETH_ALEN, "bssid:"); | ||
2045 | 4873 | ||
2046 | mutex_lock(&priv->mtx); | 4874 | at76_dbg(DBG_RX_DATA_CONTENT, "rx packet: %s", |
4875 | hex2str(skb->data + AT76_RX_HDRLEN, length)); | ||
2047 | 4876 | ||
2048 | priv->channel = conf->channel->hw_value; | 4877 | skb = at76_check_for_rx_frags(priv); |
4878 | if (!skb) | ||
4879 | return; | ||
2049 | 4880 | ||
2050 | if (is_valid_ether_addr(priv->bssid)) { | 4881 | /* Atmel header and the FCS are already removed */ |
2051 | at76_join(priv); | 4882 | i802_11_hdr = (struct ieee80211_hdr_3addr *)skb->data; |
2052 | ieee80211_wake_queues(priv->hw); | ||
2053 | } else { | ||
2054 | ieee80211_stop_queues(priv->hw); | ||
2055 | at76_start_monitor(priv); | ||
2056 | }; | ||
2057 | 4883 | ||
2058 | mutex_unlock(&priv->mtx); | 4884 | skb->dev = netdev; |
4885 | skb->ip_summed = CHECKSUM_NONE; /* TODO: should check CRC */ | ||
2059 | 4886 | ||
2060 | return 0; | 4887 | if (is_broadcast_ether_addr(i802_11_hdr->addr1)) { |
2061 | } | 4888 | if (!compare_ether_addr(i802_11_hdr->addr1, netdev->broadcast)) |
4889 | skb->pkt_type = PACKET_BROADCAST; | ||
4890 | else | ||
4891 | skb->pkt_type = PACKET_MULTICAST; | ||
4892 | } else if (compare_ether_addr(i802_11_hdr->addr1, netdev->dev_addr)) | ||
4893 | skb->pkt_type = PACKET_OTHERHOST; | ||
2062 | 4894 | ||
2063 | static int at76_config_interface(struct ieee80211_hw *hw, | 4895 | at76_ieee80211_to_eth(skb, priv->iw_mode); |
2064 | struct ieee80211_vif *vif, | ||
2065 | struct ieee80211_if_conf *conf) | ||
2066 | { | ||
2067 | struct at76_priv *priv = hw->priv; | ||
2068 | 4896 | ||
2069 | at76_dbg_dump(DBG_MAC80211, conf->bssid, ETH_ALEN, "bssid:"); | 4897 | netdev->last_rx = jiffies; |
4898 | netif_rx(skb); | ||
4899 | stats->rx_packets++; | ||
4900 | stats->rx_bytes += length; | ||
2070 | 4901 | ||
2071 | mutex_lock(&priv->mtx); | 4902 | return; |
4903 | } | ||
2072 | 4904 | ||
2073 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); | 4905 | static void at76_rx_monitor_mode(struct at76_priv *priv) |
2074 | // memcpy(priv->essid, conf->ssid, conf->ssid_len); | 4906 | { |
2075 | // priv->essid_size = conf->ssid_len; | 4907 | struct at76_rx_radiotap *rt; |
4908 | u8 *payload; | ||
4909 | int skblen; | ||
4910 | struct net_device *netdev = priv->netdev; | ||
4911 | struct at76_rx_buffer *buf = | ||
4912 | (struct at76_rx_buffer *)priv->rx_skb->data; | ||
4913 | /* length including the IEEE802.11 header and the trailing FCS, | ||
4914 | but not at76_rx_buffer */ | ||
4915 | int length = le16_to_cpu(buf->wlength); | ||
4916 | struct sk_buff *skb = priv->rx_skb; | ||
4917 | struct net_device_stats *stats = &priv->stats; | ||
2076 | 4918 | ||
2077 | if (is_valid_ether_addr(priv->bssid)) { | 4919 | if (length < IEEE80211_FCS_LEN) { |
2078 | /* mac80211 is joining a bss */ | 4920 | /* buffer contains no data */ |
2079 | ieee80211_wake_queues(priv->hw); | 4921 | at76_dbg(DBG_MONITOR_MODE, |
2080 | at76_join(priv); | 4922 | "%s: MONITOR MODE: rx skb without data", |
2081 | } else | 4923 | priv->netdev->name); |
2082 | ieee80211_stop_queues(priv->hw); | 4924 | return; |
4925 | } | ||
2083 | 4926 | ||
2084 | mutex_unlock(&priv->mtx); | 4927 | skblen = sizeof(struct at76_rx_radiotap) + length; |
2085 | 4928 | ||
2086 | return 0; | 4929 | skb = dev_alloc_skb(skblen); |
4930 | if (!skb) { | ||
4931 | printk(KERN_ERR "%s: MONITOR MODE: dev_alloc_skb for radiotap " | ||
4932 | "header returned NULL\n", priv->netdev->name); | ||
4933 | return; | ||
4934 | } | ||
4935 | |||
4936 | skb_put(skb, skblen); | ||
4937 | |||
4938 | rt = (struct at76_rx_radiotap *)skb->data; | ||
4939 | payload = skb->data + sizeof(struct at76_rx_radiotap); | ||
4940 | |||
4941 | rt->rt_hdr.it_version = 0; | ||
4942 | rt->rt_hdr.it_pad = 0; | ||
4943 | rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct at76_rx_radiotap)); | ||
4944 | rt->rt_hdr.it_present = cpu_to_le32(AT76_RX_RADIOTAP_PRESENT); | ||
4945 | |||
4946 | rt->rt_tsft = cpu_to_le64(le32_to_cpu(buf->rx_time)); | ||
4947 | rt->rt_rate = hw_rates[buf->rx_rate] & (~0x80); | ||
4948 | rt->rt_signal = buf->rssi; | ||
4949 | rt->rt_noise = buf->noise_level; | ||
4950 | rt->rt_flags = IEEE80211_RADIOTAP_F_FCS; | ||
4951 | if (buf->fragmentation) | ||
4952 | rt->rt_flags |= IEEE80211_RADIOTAP_F_FRAG; | ||
4953 | |||
4954 | memcpy(payload, buf->packet, length); | ||
4955 | skb->dev = netdev; | ||
4956 | skb->ip_summed = CHECKSUM_NONE; | ||
4957 | skb_reset_mac_header(skb); | ||
4958 | skb->pkt_type = PACKET_OTHERHOST; | ||
4959 | skb->protocol = htons(ETH_P_802_2); | ||
4960 | |||
4961 | netdev->last_rx = jiffies; | ||
4962 | netif_rx(skb); | ||
4963 | stats->rx_packets++; | ||
4964 | stats->rx_bytes += length; | ||
2087 | } | 4965 | } |
2088 | 4966 | ||
2089 | /* must be atomic */ | 4967 | /* Check if we spy on the sender address in buf and update stats */ |
2090 | static void at76_configure_filter(struct ieee80211_hw *hw, | 4968 | static void at76_iwspy_update(struct at76_priv *priv, |
2091 | unsigned int changed_flags, | 4969 | struct at76_rx_buffer *buf) |
2092 | unsigned int *total_flags, int mc_count, | ||
2093 | struct dev_addr_list *mc_list) | ||
2094 | { | 4970 | { |
2095 | struct at76_priv *priv = hw->priv; | 4971 | struct ieee80211_hdr_3addr *hdr = |
2096 | int flags; | 4972 | (struct ieee80211_hdr_3addr *)buf->packet; |
2097 | 4973 | struct iw_quality qual; | |
2098 | at76_dbg(DBG_MAC80211, "%s(): changed_flags=0x%08x " | ||
2099 | "total_flags=0x%08x mc_count=%d", | ||
2100 | __func__, changed_flags, *total_flags, mc_count); | ||
2101 | 4974 | ||
2102 | flags = changed_flags & AT76_SUPPORTED_FILTERS; | 4975 | /* We can only set the level here */ |
2103 | *total_flags = AT76_SUPPORTED_FILTERS; | 4976 | qual.updated = IW_QUAL_QUAL_INVALID | IW_QUAL_NOISE_INVALID; |
4977 | qual.level = 0; | ||
4978 | qual.noise = 0; | ||
4979 | at76_calc_level(priv, buf, &qual); | ||
2104 | 4980 | ||
2105 | /* FIXME: access to priv->promisc should be protected with | 4981 | spin_lock_bh(&priv->spy_spinlock); |
2106 | * priv->mtx, but it's impossible because this function needs to be | ||
2107 | * atomic */ | ||
2108 | 4982 | ||
2109 | if (flags && !priv->promisc) { | 4983 | if (priv->spy_data.spy_number > 0) |
2110 | /* mac80211 wants us to enable promiscuous mode */ | 4984 | wireless_spy_update(priv->netdev, hdr->addr2, &qual); |
2111 | priv->promisc = 1; | ||
2112 | } else if (!flags && priv->promisc) { | ||
2113 | /* we need to disable promiscuous mode */ | ||
2114 | priv->promisc = 0; | ||
2115 | } else | ||
2116 | return; | ||
2117 | 4985 | ||
2118 | queue_work(hw->workqueue, &priv->work_set_promisc); | 4986 | spin_unlock_bh(&priv->spy_spinlock); |
2119 | } | 4987 | } |
2120 | 4988 | ||
2121 | static int at76_set_key_oldfw(struct ieee80211_hw *hw, enum set_key_cmd cmd, | 4989 | static void at76_rx_tasklet(unsigned long param) |
2122 | const u8 *local_address, const u8 *address, | ||
2123 | struct ieee80211_key_conf *key) | ||
2124 | { | 4990 | { |
2125 | struct at76_priv *priv = hw->priv; | 4991 | struct urb *urb = (struct urb *)param; |
2126 | 4992 | struct at76_priv *priv = urb->context; | |
2127 | int i; | 4993 | struct net_device *netdev = priv->netdev; |
2128 | 4994 | struct at76_rx_buffer *buf; | |
2129 | at76_dbg(DBG_MAC80211, "%s(): cmd %d key->alg %d key->keyidx %d " | 4995 | struct ieee80211_hdr_3addr *i802_11_hdr; |
2130 | "key->keylen %d", | 4996 | u16 frame_ctl; |
2131 | __func__, cmd, key->alg, key->keyidx, key->keylen); | ||
2132 | 4997 | ||
2133 | if (key->alg != ALG_WEP) | 4998 | if (priv->device_unplugged) { |
2134 | return -EOPNOTSUPP; | 4999 | at76_dbg(DBG_DEVSTART, "device unplugged"); |
5000 | if (urb) | ||
5001 | at76_dbg(DBG_DEVSTART, "urb status %d", urb->status); | ||
5002 | return; | ||
5003 | } | ||
2135 | 5004 | ||
2136 | key->hw_key_idx = key->keyidx; | 5005 | if (!priv->rx_skb || !netdev || !priv->rx_skb->data) |
5006 | return; | ||
2137 | 5007 | ||
2138 | mutex_lock(&priv->mtx); | 5008 | buf = (struct at76_rx_buffer *)priv->rx_skb->data; |
2139 | 5009 | ||
2140 | switch (cmd) { | 5010 | i802_11_hdr = (struct ieee80211_hdr_3addr *)buf->packet; |
2141 | case SET_KEY: | ||
2142 | memcpy(priv->wep_keys[key->keyidx], key->key, key->keylen); | ||
2143 | priv->wep_keys_len[key->keyidx] = key->keylen; | ||
2144 | 5011 | ||
2145 | /* FIXME: find out how to do this properly */ | 5012 | frame_ctl = le16_to_cpu(i802_11_hdr->frame_ctl); |
2146 | priv->wep_key_id = key->keyidx; | ||
2147 | 5013 | ||
2148 | break; | 5014 | if (urb->status != 0) { |
2149 | case DISABLE_KEY: | 5015 | if (urb->status != -ENOENT && urb->status != -ECONNRESET) |
2150 | default: | 5016 | at76_dbg(DBG_URB, |
2151 | priv->wep_keys_len[key->keyidx] = 0; | 5017 | "%s %s: - nonzero Rx bulk status received: %d", |
2152 | break; | 5018 | __func__, netdev->name, urb->status); |
5019 | return; | ||
2153 | } | 5020 | } |
2154 | 5021 | ||
2155 | priv->wep_enabled = 0; | 5022 | at76_dbg(DBG_RX_ATMEL_HDR, |
5023 | "%s: rx frame: rate %d rssi %d noise %d link %d %s", | ||
5024 | priv->netdev->name, buf->rx_rate, buf->rssi, buf->noise_level, | ||
5025 | buf->link_quality, hex2str(i802_11_hdr, 48)); | ||
5026 | if (priv->iw_mode == IW_MODE_MONITOR) { | ||
5027 | at76_rx_monitor_mode(priv); | ||
5028 | goto exit; | ||
5029 | } | ||
2156 | 5030 | ||
2157 | for (i = 0; i < WEP_KEYS; i++) { | 5031 | /* there is a new bssid around, accept it: */ |
2158 | if (priv->wep_keys_len[i] != 0) | 5032 | if (buf->newbss && priv->iw_mode == IW_MODE_ADHOC) { |
2159 | priv->wep_enabled = 1; | 5033 | at76_dbg(DBG_PROGRESS, "%s: rx newbss", netdev->name); |
5034 | schedule_work(&priv->work_new_bss); | ||
2160 | } | 5035 | } |
2161 | 5036 | ||
2162 | at76_startup_device(priv); | 5037 | switch (frame_ctl & IEEE80211_FCTL_FTYPE) { |
5038 | case IEEE80211_FTYPE_DATA: | ||
5039 | at76_rx_data(priv); | ||
5040 | break; | ||
2163 | 5041 | ||
2164 | mutex_unlock(&priv->mtx); | 5042 | case IEEE80211_FTYPE_MGMT: |
5043 | /* jal: TODO: find out if we can update iwspy also on | ||
5044 | other frames than management (might depend on the | ||
5045 | radio chip / firmware version !) */ | ||
2165 | 5046 | ||
2166 | return 0; | 5047 | at76_iwspy_update(priv, buf); |
2167 | } | ||
2168 | 5048 | ||
2169 | static int at76_set_key_newfw(struct ieee80211_hw *hw, enum set_key_cmd cmd, | 5049 | at76_rx_mgmt(priv, buf); |
2170 | const u8 *local_address, const u8 *address, | 5050 | break; |
2171 | struct ieee80211_key_conf *key) | ||
2172 | { | ||
2173 | struct at76_priv *priv = hw->priv; | ||
2174 | int ret = -EOPNOTSUPP; | ||
2175 | |||
2176 | at76_dbg(DBG_MAC80211, "%s(): cmd %d key->alg %d key->keyidx %d " | ||
2177 | "key->keylen %d", | ||
2178 | __func__, cmd, key->alg, key->keyidx, key->keylen); | ||
2179 | 5051 | ||
2180 | mutex_lock(&priv->mtx); | 5052 | case IEEE80211_FTYPE_CTL: |
5053 | at76_dbg(DBG_RX_CTRL, "%s: ignored ctrl frame: %04x", | ||
5054 | priv->netdev->name, frame_ctl); | ||
5055 | break; | ||
2181 | 5056 | ||
2182 | priv->mib_buf.type = MIB_MAC_ENCRYPTION; | 5057 | default: |
5058 | printk(KERN_DEBUG "%s: ignoring frame with framectl 0x%04x\n", | ||
5059 | priv->netdev->name, frame_ctl); | ||
5060 | } | ||
5061 | exit: | ||
5062 | at76_submit_rx_urb(priv); | ||
5063 | } | ||
2183 | 5064 | ||
2184 | if (cmd == DISABLE_KEY) { | 5065 | /* Load firmware into kernel memory and parse it */ |
2185 | priv->mib_buf.size = CIPHER_KEY_LEN; | 5066 | static struct fwentry *at76_load_firmware(struct usb_device *udev, |
2186 | priv->mib_buf.index = offsetof(struct mib_mac_encryption, | 5067 | enum board_type board_type) |
2187 | cipher_default_keyvalue[key->keyidx]); | 5068 | { |
2188 | memset(priv->mib_buf.data.data, 0, CIPHER_KEY_LEN); | 5069 | int ret; |
2189 | if (at76_set_mib(priv, &priv->mib_buf) != CMD_STATUS_COMPLETE) | 5070 | char *str; |
2190 | ret = -EOPNOTSUPP; /* -EIO would be probably better */ | 5071 | struct at76_fw_header *fwh; |
2191 | else { | 5072 | struct fwentry *fwe = &firmwares[board_type]; |
2192 | 5073 | ||
2193 | priv->keys[key->keyidx].cipher = CIPHER_NONE; | 5074 | mutex_lock(&fw_mutex); |
2194 | priv->keys[key->keyidx].keylen = 0; | ||
2195 | }; | ||
2196 | if (priv->default_group_key == key->keyidx) | ||
2197 | priv->default_group_key = 0xff; | ||
2198 | 5075 | ||
2199 | if (priv->default_pairwise_key == key->keyidx) | 5076 | if (fwe->loaded) { |
2200 | priv->default_pairwise_key = 0xff; | 5077 | at76_dbg(DBG_FW, "re-using previously loaded fw"); |
2201 | /* If default pairwise key is removed, fall back to | ||
2202 | * group key? */ | ||
2203 | ret = 0; | ||
2204 | goto exit; | 5078 | goto exit; |
2205 | }; | 5079 | } |
2206 | |||
2207 | if (cmd == SET_KEY) { | ||
2208 | /* store key into MIB */ | ||
2209 | priv->mib_buf.size = CIPHER_KEY_LEN; | ||
2210 | priv->mib_buf.index = offsetof(struct mib_mac_encryption, | ||
2211 | cipher_default_keyvalue[key->keyidx]); | ||
2212 | memset(priv->mib_buf.data.data, 0, CIPHER_KEY_LEN); | ||
2213 | memcpy(priv->mib_buf.data.data, key->key, key->keylen); | ||
2214 | |||
2215 | switch (key->alg) { | ||
2216 | case ALG_WEP: | ||
2217 | if (key->keylen == 5) { | ||
2218 | priv->keys[key->keyidx].cipher = | ||
2219 | CIPHER_WEP64; | ||
2220 | priv->keys[key->keyidx].keylen = 8; | ||
2221 | } else if (key->keylen == 13) { | ||
2222 | priv->keys[key->keyidx].cipher = | ||
2223 | CIPHER_WEP128; | ||
2224 | /* Firmware needs this */ | ||
2225 | priv->keys[key->keyidx].keylen = 8; | ||
2226 | } else { | ||
2227 | ret = -EOPNOTSUPP; | ||
2228 | goto exit; | ||
2229 | }; | ||
2230 | break; | ||
2231 | case ALG_TKIP: | ||
2232 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | ||
2233 | priv->keys[key->keyidx].cipher = CIPHER_TKIP; | ||
2234 | priv->keys[key->keyidx].keylen = 12; | ||
2235 | break; | ||
2236 | 5080 | ||
2237 | case ALG_CCMP: | 5081 | at76_dbg(DBG_FW, "downloading firmware %s", fwe->fwname); |
2238 | if (!at76_is_505a(priv->board_type)) { | 5082 | ret = request_firmware(&fwe->fw, fwe->fwname, &udev->dev); |
2239 | ret = -EOPNOTSUPP; | 5083 | if (ret < 0) { |
2240 | goto exit; | 5084 | dev_printk(KERN_ERR, &udev->dev, "firmware %s not found!\n", |
2241 | }; | 5085 | fwe->fwname); |
2242 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | 5086 | dev_printk(KERN_ERR, &udev->dev, |
2243 | priv->keys[key->keyidx].cipher = CIPHER_CCMP; | 5087 | "you may need to download the firmware from " |
2244 | priv->keys[key->keyidx].keylen = 16; | 5088 | "http://developer.berlios.de/projects/at76c503a/"); |
2245 | break; | 5089 | goto exit; |
5090 | } | ||
2246 | 5091 | ||
2247 | default: | 5092 | at76_dbg(DBG_FW, "got it."); |
2248 | ret = -EOPNOTSUPP; | 5093 | fwh = (struct at76_fw_header *)(fwe->fw->data); |
2249 | goto exit; | ||
2250 | }; | ||
2251 | |||
2252 | priv->mib_buf.data.data[38] = priv->keys[key->keyidx].cipher; | ||
2253 | priv->mib_buf.data.data[39] = 1; /* Taken from atmelwlandriver, | ||
2254 | not documented */ | ||
2255 | |||
2256 | if (is_valid_ether_addr(address)) | ||
2257 | /* Pairwise key */ | ||
2258 | priv->mib_buf.data.data[39] |= (KEY_PAIRWISE | KEY_TX); | ||
2259 | else if (is_broadcast_ether_addr(address)) | ||
2260 | /* Group key */ | ||
2261 | priv->mib_buf.data.data[39] |= (KEY_TX); | ||
2262 | else /* Key used only for transmission ??? */ | ||
2263 | priv->mib_buf.data.data[39] |= (KEY_TX); | ||
2264 | |||
2265 | if (at76_set_mib(priv, &priv->mib_buf) != | ||
2266 | CMD_STATUS_COMPLETE) { | ||
2267 | ret = -EOPNOTSUPP; /* -EIO would be probably better */ | ||
2268 | goto exit; | ||
2269 | }; | ||
2270 | 5094 | ||
2271 | if ((key->alg == ALG_TKIP) || (key->alg == ALG_CCMP)) | 5095 | if (fwe->fw->size <= sizeof(*fwh)) { |
2272 | at76_reset_rsc(priv); | 5096 | dev_printk(KERN_ERR, &udev->dev, |
5097 | "firmware is too short (0x%zx)\n", fwe->fw->size); | ||
5098 | goto exit; | ||
5099 | } | ||
2273 | 5100 | ||
2274 | key->hw_key_idx = key->keyidx; | 5101 | /* CRC currently not checked */ |
5102 | fwe->board_type = le32_to_cpu(fwh->board_type); | ||
5103 | if (fwe->board_type != board_type) { | ||
5104 | dev_printk(KERN_ERR, &udev->dev, | ||
5105 | "board type mismatch, requested %u, got %u\n", | ||
5106 | board_type, fwe->board_type); | ||
5107 | goto exit; | ||
5108 | } | ||
2275 | 5109 | ||
2276 | /* Set up default keys */ | 5110 | fwe->fw_version.major = fwh->major; |
2277 | if (is_broadcast_ether_addr(address)) | 5111 | fwe->fw_version.minor = fwh->minor; |
2278 | priv->default_group_key = key->keyidx; | 5112 | fwe->fw_version.patch = fwh->patch; |
2279 | if (is_valid_ether_addr(address)) | 5113 | fwe->fw_version.build = fwh->build; |
2280 | priv->default_pairwise_key = key->keyidx; | ||
2281 | 5114 | ||
2282 | /* Set up encryption MIBs */ | 5115 | str = (char *)fwh + le32_to_cpu(fwh->str_offset); |
5116 | fwe->intfw = (u8 *)fwh + le32_to_cpu(fwh->int_fw_offset); | ||
5117 | fwe->intfw_size = le32_to_cpu(fwh->int_fw_len); | ||
5118 | fwe->extfw = (u8 *)fwh + le32_to_cpu(fwh->ext_fw_offset); | ||
5119 | fwe->extfw_size = le32_to_cpu(fwh->ext_fw_len); | ||
2283 | 5120 | ||
2284 | /* first block of settings */ | 5121 | fwe->loaded = 1; |
2285 | priv->mib_buf.size = 3; | ||
2286 | priv->mib_buf.index = offsetof(struct mib_mac_encryption, | ||
2287 | privacy_invoked); | ||
2288 | priv->mib_buf.data.data[0] = 1; /* privacy_invoked */ | ||
2289 | priv->mib_buf.data.data[1] = priv->default_pairwise_key; | ||
2290 | priv->mib_buf.data.data[2] = priv->default_group_key; | ||
2291 | 5122 | ||
2292 | ret = at76_set_mib(priv, &priv->mib_buf); | 5123 | dev_printk(KERN_DEBUG, &udev->dev, |
2293 | if (ret != CMD_STATUS_COMPLETE) | 5124 | "using firmware %s (version %d.%d.%d-%d)\n", |
2294 | goto exit; | 5125 | fwe->fwname, fwh->major, fwh->minor, fwh->patch, fwh->build); |
2295 | 5126 | ||
2296 | /* second block of settings */ | 5127 | at76_dbg(DBG_DEVSTART, "board %u, int %d:%d, ext %d:%d", board_type, |
2297 | priv->mib_buf.size = 3; | 5128 | le32_to_cpu(fwh->int_fw_offset), le32_to_cpu(fwh->int_fw_len), |
2298 | priv->mib_buf.index = offsetof(struct mib_mac_encryption, | 5129 | le32_to_cpu(fwh->ext_fw_offset), le32_to_cpu(fwh->ext_fw_len)); |
2299 | exclude_unencrypted); | 5130 | at76_dbg(DBG_DEVSTART, "firmware id %s", str); |
2300 | priv->mib_buf.data.data[0] = 1; /* exclude_unencrypted */ | ||
2301 | priv->mib_buf.data.data[1] = 0; /* wep_encryption_type */ | ||
2302 | priv->mib_buf.data.data[2] = 0; /* ckip_key_permutation */ | ||
2303 | 5131 | ||
2304 | ret = at76_set_mib(priv, &priv->mib_buf); | ||
2305 | if (ret != CMD_STATUS_COMPLETE) | ||
2306 | goto exit; | ||
2307 | ret = 0; | ||
2308 | }; | ||
2309 | exit: | 5132 | exit: |
2310 | at76_dump_mib_mac_encryption(priv); | 5133 | mutex_unlock(&fw_mutex); |
2311 | mutex_unlock(&priv->mtx); | ||
2312 | return ret; | ||
2313 | } | ||
2314 | |||
2315 | static int at76_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | ||
2316 | const u8 *local_address, const u8 *address, | ||
2317 | struct ieee80211_key_conf *key) | ||
2318 | { | ||
2319 | struct at76_priv *priv = hw->priv; | ||
2320 | |||
2321 | at76_dbg(DBG_MAC80211, "%s(): cmd %d key->alg %d key->keyidx %d " | ||
2322 | "key->keylen %d", | ||
2323 | __func__, cmd, key->alg, key->keyidx, key->keylen); | ||
2324 | 5134 | ||
2325 | if (FIRMWARE_IS_WPA(priv->fw_version)) | 5135 | if (fwe->loaded) |
2326 | return at76_set_key_newfw(hw, cmd, local_address, address, key); | 5136 | return fwe; |
2327 | else | 5137 | else |
2328 | return at76_set_key_oldfw(hw, cmd, local_address, address, key); | 5138 | return NULL; |
2329 | |||
2330 | } | 5139 | } |
2331 | 5140 | ||
2332 | static const struct ieee80211_ops at76_ops = { | ||
2333 | .tx = at76_mac80211_tx, | ||
2334 | .add_interface = at76_add_interface, | ||
2335 | .remove_interface = at76_remove_interface, | ||
2336 | .config = at76_config, | ||
2337 | .config_interface = at76_config_interface, | ||
2338 | .configure_filter = at76_configure_filter, | ||
2339 | .start = at76_mac80211_start, | ||
2340 | .stop = at76_mac80211_stop, | ||
2341 | .hw_scan = at76_hw_scan, | ||
2342 | .set_key = at76_set_key, | ||
2343 | }; | ||
2344 | |||
2345 | /* Allocate network device and initialize private data */ | 5141 | /* Allocate network device and initialize private data */ |
2346 | static struct at76_priv *at76_alloc_new_device(struct usb_device *udev) | 5142 | static struct at76_priv *at76_alloc_new_device(struct usb_device *udev) |
2347 | { | 5143 | { |
2348 | struct ieee80211_hw *hw; | 5144 | struct net_device *netdev; |
2349 | struct at76_priv *priv; | 5145 | struct at76_priv *priv; |
5146 | int i; | ||
2350 | 5147 | ||
2351 | hw = ieee80211_alloc_hw(sizeof(struct at76_priv), &at76_ops); | 5148 | /* allocate memory for our device state and initialize it */ |
2352 | if (!hw) { | 5149 | netdev = alloc_etherdev(sizeof(struct at76_priv)); |
2353 | printk(KERN_ERR DRIVER_NAME ": could not register" | 5150 | if (!netdev) { |
2354 | " ieee80211_hw\n"); | 5151 | dev_printk(KERN_ERR, &udev->dev, "out of memory\n"); |
2355 | return NULL; | 5152 | return NULL; |
2356 | } | 5153 | } |
2357 | 5154 | ||
2358 | priv = hw->priv; | 5155 | priv = netdev_priv(netdev); |
2359 | priv->hw = hw; | ||
2360 | 5156 | ||
2361 | priv->udev = udev; | 5157 | priv->udev = udev; |
5158 | priv->netdev = netdev; | ||
2362 | 5159 | ||
2363 | mutex_init(&priv->mtx); | 5160 | mutex_init(&priv->mtx); |
5161 | INIT_WORK(&priv->work_assoc_done, at76_work_assoc_done); | ||
5162 | INIT_WORK(&priv->work_join, at76_work_join); | ||
5163 | INIT_WORK(&priv->work_new_bss, at76_work_new_bss); | ||
5164 | INIT_WORK(&priv->work_start_scan, at76_work_start_scan); | ||
2364 | INIT_WORK(&priv->work_set_promisc, at76_work_set_promisc); | 5165 | INIT_WORK(&priv->work_set_promisc, at76_work_set_promisc); |
2365 | INIT_WORK(&priv->work_submit_rx, at76_work_submit_rx); | 5166 | INIT_WORK(&priv->work_submit_rx, at76_work_submit_rx); |
2366 | INIT_DELAYED_WORK(&priv->dwork_hw_scan, at76_dwork_hw_scan); | 5167 | INIT_DELAYED_WORK(&priv->dwork_restart, at76_dwork_restart); |
5168 | INIT_DELAYED_WORK(&priv->dwork_get_scan, at76_dwork_get_scan); | ||
5169 | INIT_DELAYED_WORK(&priv->dwork_beacon, at76_dwork_beacon); | ||
5170 | INIT_DELAYED_WORK(&priv->dwork_auth, at76_dwork_auth); | ||
5171 | INIT_DELAYED_WORK(&priv->dwork_assoc, at76_dwork_assoc); | ||
5172 | |||
5173 | spin_lock_init(&priv->mgmt_spinlock); | ||
5174 | priv->next_mgmt_bulk = NULL; | ||
5175 | priv->mac_state = MAC_INIT; | ||
5176 | |||
5177 | /* initialize empty BSS list */ | ||
5178 | priv->curr_bss = NULL; | ||
5179 | INIT_LIST_HEAD(&priv->bss_list); | ||
5180 | spin_lock_init(&priv->bss_list_spinlock); | ||
5181 | |||
5182 | init_timer(&priv->bss_list_timer); | ||
5183 | priv->bss_list_timer.data = (unsigned long)priv; | ||
5184 | priv->bss_list_timer.function = at76_bss_list_timeout; | ||
5185 | |||
5186 | spin_lock_init(&priv->spy_spinlock); | ||
5187 | |||
5188 | /* mark all rx data entries as unused */ | ||
5189 | for (i = 0; i < NR_RX_DATA_BUF; i++) | ||
5190 | priv->rx_data[i].skb = NULL; | ||
2367 | 5191 | ||
2368 | priv->rx_tasklet.func = at76_rx_tasklet; | 5192 | priv->rx_tasklet.func = at76_rx_tasklet; |
2369 | priv->rx_tasklet.data = 0; | 5193 | priv->rx_tasklet.data = 0; |
@@ -2371,9 +5195,6 @@ static struct at76_priv *at76_alloc_new_device(struct usb_device *udev) | |||
2371 | priv->pm_mode = AT76_PM_OFF; | 5195 | priv->pm_mode = AT76_PM_OFF; |
2372 | priv->pm_period = 0; | 5196 | priv->pm_period = 0; |
2373 | 5197 | ||
2374 | /* unit us */ | ||
2375 | priv->hw->channel_change_time = 100000; | ||
2376 | |||
2377 | return priv; | 5198 | return priv; |
2378 | } | 5199 | } |
2379 | 5200 | ||
@@ -2436,42 +5257,11 @@ static int at76_alloc_urbs(struct at76_priv *priv, | |||
2436 | return 0; | 5257 | return 0; |
2437 | } | 5258 | } |
2438 | 5259 | ||
2439 | static struct ieee80211_rate at76_rates[] = { | ||
2440 | { .bitrate = 10, .hw_value = TX_RATE_1MBIT, }, | ||
2441 | { .bitrate = 20, .hw_value = TX_RATE_2MBIT, }, | ||
2442 | { .bitrate = 55, .hw_value = TX_RATE_5_5MBIT, }, | ||
2443 | { .bitrate = 110, .hw_value = TX_RATE_11MBIT, }, | ||
2444 | }; | ||
2445 | |||
2446 | static struct ieee80211_channel at76_channels[] = { | ||
2447 | { .center_freq = 2412, .hw_value = 1 }, | ||
2448 | { .center_freq = 2417, .hw_value = 2 }, | ||
2449 | { .center_freq = 2422, .hw_value = 3 }, | ||
2450 | { .center_freq = 2427, .hw_value = 4 }, | ||
2451 | { .center_freq = 2432, .hw_value = 5 }, | ||
2452 | { .center_freq = 2437, .hw_value = 6 }, | ||
2453 | { .center_freq = 2442, .hw_value = 7 }, | ||
2454 | { .center_freq = 2447, .hw_value = 8 }, | ||
2455 | { .center_freq = 2452, .hw_value = 9 }, | ||
2456 | { .center_freq = 2457, .hw_value = 10 }, | ||
2457 | { .center_freq = 2462, .hw_value = 11 }, | ||
2458 | { .center_freq = 2467, .hw_value = 12 }, | ||
2459 | { .center_freq = 2472, .hw_value = 13 }, | ||
2460 | { .center_freq = 2484, .hw_value = 14 } | ||
2461 | }; | ||
2462 | |||
2463 | static struct ieee80211_supported_band at76_supported_band = { | ||
2464 | .channels = at76_channels, | ||
2465 | .n_channels = ARRAY_SIZE(at76_channels), | ||
2466 | .bitrates = at76_rates, | ||
2467 | .n_bitrates = ARRAY_SIZE(at76_rates), | ||
2468 | }; | ||
2469 | |||
2470 | /* Register network device and initialize the hardware */ | 5260 | /* Register network device and initialize the hardware */ |
2471 | static int at76_init_new_device(struct at76_priv *priv, | 5261 | static int at76_init_new_device(struct at76_priv *priv, |
2472 | struct usb_interface *interface) | 5262 | struct usb_interface *interface) |
2473 | { | 5263 | { |
2474 | struct device *dev = &interface->dev; | 5264 | struct net_device *netdev = priv->netdev; |
2475 | int ret; | 5265 | int ret; |
2476 | 5266 | ||
2477 | /* set up the endpoint information */ | 5267 | /* set up the endpoint information */ |
@@ -2487,11 +5277,14 @@ static int at76_init_new_device(struct at76_priv *priv, | |||
2487 | /* MAC address */ | 5277 | /* MAC address */ |
2488 | ret = at76_get_hw_config(priv); | 5278 | ret = at76_get_hw_config(priv); |
2489 | if (ret < 0) { | 5279 | if (ret < 0) { |
2490 | dev_err(dev, "cannot get MAC address\n"); | 5280 | dev_printk(KERN_ERR, &interface->dev, |
5281 | "cannot get MAC address\n"); | ||
2491 | goto exit; | 5282 | goto exit; |
2492 | } | 5283 | } |
2493 | 5284 | ||
2494 | priv->domain = at76_get_reg_domain(priv->regulatory_domain); | 5285 | priv->domain = at76_get_reg_domain(priv->regulatory_domain); |
5286 | /* init. netdev->dev_addr */ | ||
5287 | memcpy(netdev->dev_addr, priv->mac_addr, ETH_ALEN); | ||
2495 | 5288 | ||
2496 | priv->channel = DEF_CHANNEL; | 5289 | priv->channel = DEF_CHANNEL; |
2497 | priv->iw_mode = IW_MODE_INFRA; | 5290 | priv->iw_mode = IW_MODE_INFRA; |
@@ -2501,54 +5294,47 @@ static int at76_init_new_device(struct at76_priv *priv, | |||
2501 | priv->txrate = TX_RATE_AUTO; | 5294 | priv->txrate = TX_RATE_AUTO; |
2502 | priv->preamble_type = PREAMBLE_TYPE_LONG; | 5295 | priv->preamble_type = PREAMBLE_TYPE_LONG; |
2503 | priv->beacon_period = 100; | 5296 | priv->beacon_period = 100; |
5297 | priv->beacons_last_qual = jiffies; | ||
2504 | priv->auth_mode = WLAN_AUTH_OPEN; | 5298 | priv->auth_mode = WLAN_AUTH_OPEN; |
2505 | priv->scan_min_time = DEF_SCAN_MIN_TIME; | 5299 | priv->scan_min_time = DEF_SCAN_MIN_TIME; |
2506 | priv->scan_max_time = DEF_SCAN_MAX_TIME; | 5300 | priv->scan_max_time = DEF_SCAN_MAX_TIME; |
2507 | priv->scan_mode = SCAN_TYPE_ACTIVE; | 5301 | priv->scan_mode = SCAN_TYPE_ACTIVE; |
2508 | priv->default_pairwise_key = 0xff; | ||
2509 | priv->default_group_key = 0xff; | ||
2510 | |||
2511 | /* mac80211 initialisation */ | ||
2512 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &at76_supported_band; | ||
2513 | 5302 | ||
2514 | if (FIRMWARE_IS_WPA(priv->fw_version) && | 5303 | netdev->flags &= ~IFF_MULTICAST; /* not yet or never */ |
2515 | (at76_is_503rfmd(priv->board_type) || | 5304 | netdev->open = at76_open; |
2516 | at76_is_505(priv->board_type))) | 5305 | netdev->stop = at76_stop; |
2517 | priv->hw->flags = IEEE80211_HW_SIGNAL_UNSPEC; | 5306 | netdev->get_stats = at76_get_stats; |
2518 | else | 5307 | netdev->ethtool_ops = &at76_ethtool_ops; |
2519 | priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | | 5308 | |
2520 | IEEE80211_HW_SIGNAL_UNSPEC; | 5309 | /* Add pointers to enable iwspy support. */ |
2521 | 5310 | priv->wireless_data.spy_data = &priv->spy_data; | |
2522 | priv->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); | 5311 | netdev->wireless_data = &priv->wireless_data; |
2523 | 5312 | ||
2524 | SET_IEEE80211_DEV(priv->hw, &interface->dev); | 5313 | netdev->hard_start_xmit = at76_tx; |
2525 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); | 5314 | netdev->tx_timeout = at76_tx_timeout; |
2526 | 5315 | netdev->watchdog_timeo = 2 * HZ; | |
2527 | ret = ieee80211_register_hw(priv->hw); | 5316 | netdev->wireless_handlers = &at76_handler_def; |
5317 | netdev->set_multicast_list = at76_set_multicast; | ||
5318 | netdev->set_mac_address = at76_set_mac_address; | ||
5319 | dev_alloc_name(netdev, "wlan%d"); | ||
5320 | |||
5321 | ret = register_netdev(priv->netdev); | ||
2528 | if (ret) { | 5322 | if (ret) { |
2529 | dev_err(dev, "cannot register mac80211 hw (status %d)!\n", ret); | 5323 | dev_printk(KERN_ERR, &interface->dev, |
5324 | "cannot register netdevice (status %d)!\n", ret); | ||
2530 | goto exit; | 5325 | goto exit; |
2531 | } | 5326 | } |
5327 | priv->netdev_registered = 1; | ||
2532 | 5328 | ||
2533 | priv->mac80211_registered = 1; | 5329 | printk(KERN_INFO "%s: USB %s, MAC %s, firmware %d.%d.%d-%d\n", |
5330 | netdev->name, dev_name(&interface->dev), mac2str(priv->mac_addr), | ||
5331 | priv->fw_version.major, priv->fw_version.minor, | ||
5332 | priv->fw_version.patch, priv->fw_version.build); | ||
5333 | printk(KERN_INFO "%s: regulatory domain 0x%02x: %s\n", netdev->name, | ||
5334 | priv->regulatory_domain, priv->domain->name); | ||
2534 | 5335 | ||
2535 | dev_info(dev, "%s: USB %s, MAC %s, firmware %d.%d.%d-%d\n", | 5336 | /* we let this timer run the whole time this driver instance lives */ |
2536 | wiphy_name(priv->hw->wiphy), | 5337 | mod_timer(&priv->bss_list_timer, jiffies + BSS_LIST_TIMEOUT); |
2537 | dev_name(&interface->dev), mac2str(priv->mac_addr), | ||
2538 | priv->fw_version.major, priv->fw_version.minor, | ||
2539 | priv->fw_version.patch, priv->fw_version.build); | ||
2540 | dev_info(dev, "%s: regulatory domain 0x%02x: %s\n", | ||
2541 | wiphy_name(priv->hw->wiphy), | ||
2542 | priv->regulatory_domain, priv->domain->name); | ||
2543 | dev_info(dev, "%s: WPA support: ", wiphy_name(priv->hw->wiphy)); | ||
2544 | if (!FIRMWARE_IS_WPA(priv->fw_version)) | ||
2545 | printk("none\n"); | ||
2546 | else { | ||
2547 | if (!at76_is_505a(priv->board_type)) | ||
2548 | printk("TKIP\n"); | ||
2549 | else | ||
2550 | printk("TKIP, AES/CCMP\n"); | ||
2551 | }; | ||
2552 | 5338 | ||
2553 | exit: | 5339 | exit: |
2554 | return ret; | 5340 | return ret; |
@@ -2556,13 +5342,15 @@ exit: | |||
2556 | 5342 | ||
2557 | static void at76_delete_device(struct at76_priv *priv) | 5343 | static void at76_delete_device(struct at76_priv *priv) |
2558 | { | 5344 | { |
5345 | int i; | ||
5346 | |||
2559 | at76_dbg(DBG_PROC_ENTRY, "%s: ENTER", __func__); | 5347 | at76_dbg(DBG_PROC_ENTRY, "%s: ENTER", __func__); |
2560 | 5348 | ||
2561 | /* The device is gone, don't bother turning it off */ | 5349 | /* The device is gone, don't bother turning it off */ |
2562 | priv->device_unplugged = 1; | 5350 | priv->device_unplugged = 1; |
2563 | 5351 | ||
2564 | if (priv->mac80211_registered) | 5352 | if (priv->netdev_registered) |
2565 | ieee80211_unregister_hw(priv->hw); | 5353 | unregister_netdev(priv->netdev); |
2566 | 5354 | ||
2567 | /* assuming we used keventd, it must quiesce too */ | 5355 | /* assuming we used keventd, it must quiesce too */ |
2568 | flush_scheduled_work(); | 5356 | flush_scheduled_work(); |
@@ -2583,11 +5371,25 @@ static void at76_delete_device(struct at76_priv *priv) | |||
2583 | if (priv->rx_skb) | 5371 | if (priv->rx_skb) |
2584 | kfree_skb(priv->rx_skb); | 5372 | kfree_skb(priv->rx_skb); |
2585 | 5373 | ||
5374 | at76_free_bss_list(priv); | ||
5375 | del_timer_sync(&priv->bss_list_timer); | ||
5376 | cancel_delayed_work(&priv->dwork_get_scan); | ||
5377 | cancel_delayed_work(&priv->dwork_beacon); | ||
5378 | cancel_delayed_work(&priv->dwork_auth); | ||
5379 | cancel_delayed_work(&priv->dwork_assoc); | ||
5380 | |||
5381 | if (priv->mac_state == MAC_CONNECTED) | ||
5382 | at76_iwevent_bss_disconnect(priv->netdev); | ||
5383 | |||
5384 | for (i = 0; i < NR_RX_DATA_BUF; i++) | ||
5385 | if (priv->rx_data[i].skb) { | ||
5386 | dev_kfree_skb(priv->rx_data[i].skb); | ||
5387 | priv->rx_data[i].skb = NULL; | ||
5388 | } | ||
2586 | usb_put_dev(priv->udev); | 5389 | usb_put_dev(priv->udev); |
2587 | 5390 | ||
2588 | at76_dbg(DBG_PROC_ENTRY, "%s: before freeing priv/ieee80211_hw", | 5391 | at76_dbg(DBG_PROC_ENTRY, "%s: before freeing priv/netdev", __func__); |
2589 | __func__); | 5392 | free_netdev(priv->netdev); /* priv is in netdev */ |
2590 | ieee80211_free_hw(priv->hw); | ||
2591 | 5393 | ||
2592 | at76_dbg(DBG_PROC_ENTRY, "%s: EXIT", __func__); | 5394 | at76_dbg(DBG_PROC_ENTRY, "%s: EXIT", __func__); |
2593 | } | 5395 | } |
@@ -2621,8 +5423,8 @@ static int at76_probe(struct usb_interface *interface, | |||
2621 | we get 204 with 2.4.23, Fiberline FL-WL240u (505A+RFMD2958) ??? */ | 5423 | we get 204 with 2.4.23, Fiberline FL-WL240u (505A+RFMD2958) ??? */ |
2622 | 5424 | ||
2623 | if (op_mode == OPMODE_HW_CONFIG_MODE) { | 5425 | if (op_mode == OPMODE_HW_CONFIG_MODE) { |
2624 | dev_err(&interface->dev, | 5426 | dev_printk(KERN_ERR, &interface->dev, |
2625 | "cannot handle a device in HW_CONFIG_MODE\n"); | 5427 | "cannot handle a device in HW_CONFIG_MODE\n"); |
2626 | ret = -EBUSY; | 5428 | ret = -EBUSY; |
2627 | goto error; | 5429 | goto error; |
2628 | } | 5430 | } |
@@ -2630,12 +5432,13 @@ static int at76_probe(struct usb_interface *interface, | |||
2630 | if (op_mode != OPMODE_NORMAL_NIC_WITH_FLASH | 5432 | if (op_mode != OPMODE_NORMAL_NIC_WITH_FLASH |
2631 | && op_mode != OPMODE_NORMAL_NIC_WITHOUT_FLASH) { | 5433 | && op_mode != OPMODE_NORMAL_NIC_WITHOUT_FLASH) { |
2632 | /* download internal firmware part */ | 5434 | /* download internal firmware part */ |
2633 | dev_dbg(&interface->dev, "downloading internal firmware\n"); | 5435 | dev_printk(KERN_DEBUG, &interface->dev, |
5436 | "downloading internal firmware\n"); | ||
2634 | ret = at76_load_internal_fw(udev, fwe); | 5437 | ret = at76_load_internal_fw(udev, fwe); |
2635 | if (ret < 0) { | 5438 | if (ret < 0) { |
2636 | dev_err(&interface->dev, | 5439 | dev_printk(KERN_ERR, &interface->dev, |
2637 | "error %d downloading internal firmware\n", | 5440 | "error %d downloading internal firmware\n", |
2638 | ret); | 5441 | ret); |
2639 | goto error; | 5442 | goto error; |
2640 | } | 5443 | } |
2641 | usb_put_dev(udev); | 5444 | usb_put_dev(udev); |
@@ -2660,7 +5463,8 @@ static int at76_probe(struct usb_interface *interface, | |||
2660 | need_ext_fw = 1; | 5463 | need_ext_fw = 1; |
2661 | 5464 | ||
2662 | if (need_ext_fw) { | 5465 | if (need_ext_fw) { |
2663 | dev_dbg(&interface->dev, "downloading external firmware\n"); | 5466 | dev_printk(KERN_DEBUG, &interface->dev, |
5467 | "downloading external firmware\n"); | ||
2664 | 5468 | ||
2665 | ret = at76_load_external_fw(udev, fwe); | 5469 | ret = at76_load_external_fw(udev, fwe); |
2666 | if (ret) | 5470 | if (ret) |
@@ -2669,8 +5473,8 @@ static int at76_probe(struct usb_interface *interface, | |||
2669 | /* Re-check firmware version */ | 5473 | /* Re-check firmware version */ |
2670 | ret = at76_get_mib(udev, MIB_FW_VERSION, &fwv, sizeof(fwv)); | 5474 | ret = at76_get_mib(udev, MIB_FW_VERSION, &fwv, sizeof(fwv)); |
2671 | if (ret < 0) { | 5475 | if (ret < 0) { |
2672 | dev_err(&interface->dev, | 5476 | dev_printk(KERN_ERR, &interface->dev, |
2673 | "error %d getting firmware version\n", ret); | 5477 | "error %d getting firmware version\n", ret); |
2674 | goto error; | 5478 | goto error; |
2675 | } | 5479 | } |
2676 | } | 5480 | } |
@@ -2681,6 +5485,7 @@ static int at76_probe(struct usb_interface *interface, | |||
2681 | goto error; | 5485 | goto error; |
2682 | } | 5486 | } |
2683 | 5487 | ||
5488 | SET_NETDEV_DEV(priv->netdev, &interface->dev); | ||
2684 | usb_set_intfdata(interface, priv); | 5489 | usb_set_intfdata(interface, priv); |
2685 | 5490 | ||
2686 | memcpy(&priv->fw_version, &fwv, sizeof(struct mib_fw_version)); | 5491 | memcpy(&priv->fw_version, &fwv, sizeof(struct mib_fw_version)); |
@@ -2708,7 +5513,7 @@ static void at76_disconnect(struct usb_interface *interface) | |||
2708 | if (!priv) | 5513 | if (!priv) |
2709 | return; | 5514 | return; |
2710 | 5515 | ||
2711 | printk(KERN_INFO "%s: disconnecting\n", wiphy_name(priv->hw->wiphy)); | 5516 | printk(KERN_INFO "%s: disconnecting\n", priv->netdev->name); |
2712 | at76_delete_device(priv); | 5517 | at76_delete_device(priv); |
2713 | dev_printk(KERN_INFO, &interface->dev, "disconnected\n"); | 5518 | dev_printk(KERN_INFO, &interface->dev, "disconnected\n"); |
2714 | } | 5519 | } |
@@ -2764,8 +5569,5 @@ MODULE_AUTHOR("Alex <alex@foogod.com>"); | |||
2764 | MODULE_AUTHOR("Nick Jones"); | 5569 | MODULE_AUTHOR("Nick Jones"); |
2765 | MODULE_AUTHOR("Balint Seeber <n0_5p4m_p13453@hotmail.com>"); | 5570 | MODULE_AUTHOR("Balint Seeber <n0_5p4m_p13453@hotmail.com>"); |
2766 | MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>"); | 5571 | MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>"); |
2767 | MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>"); | ||
2768 | MODULE_AUTHOR("Kalle Valo <kalle.valo@iki.fi>"); | ||
2769 | MODULE_AUTHOR("Milan Plzik <milan.plzik@gmail.com>"); | ||
2770 | MODULE_DESCRIPTION(DRIVER_DESC); | 5572 | MODULE_DESCRIPTION(DRIVER_DESC); |
2771 | MODULE_LICENSE("GPL"); | 5573 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/staging/at76_usb/at76_usb.h b/drivers/staging/at76_usb/at76_usb.h index 8bb352f16d45..b20be9da1fa1 100644 --- a/drivers/staging/at76_usb/at76_usb.h +++ b/drivers/staging/at76_usb/at76_usb.h | |||
@@ -34,6 +34,23 @@ enum board_type { | |||
34 | BOARD_505AMX = 8 | 34 | BOARD_505AMX = 8 |
35 | }; | 35 | }; |
36 | 36 | ||
37 | /* our private ioctl's */ | ||
38 | /* preamble length (0 - long, 1 - short, 2 - auto) */ | ||
39 | #define AT76_SET_SHORT_PREAMBLE (SIOCIWFIRSTPRIV + 0) | ||
40 | #define AT76_GET_SHORT_PREAMBLE (SIOCIWFIRSTPRIV + 1) | ||
41 | /* which debug channels are enabled */ | ||
42 | #define AT76_SET_DEBUG (SIOCIWFIRSTPRIV + 2) | ||
43 | #define AT76_GET_DEBUG (SIOCIWFIRSTPRIV + 3) | ||
44 | /* power save mode (incl. the Atmel proprietary smart save mode) */ | ||
45 | #define AT76_SET_POWERSAVE_MODE (SIOCIWFIRSTPRIV + 4) | ||
46 | #define AT76_GET_POWERSAVE_MODE (SIOCIWFIRSTPRIV + 5) | ||
47 | /* min and max channel times for scan */ | ||
48 | #define AT76_SET_SCAN_TIMES (SIOCIWFIRSTPRIV + 6) | ||
49 | #define AT76_GET_SCAN_TIMES (SIOCIWFIRSTPRIV + 7) | ||
50 | /* scan mode (0 - active, 1 - passive) */ | ||
51 | #define AT76_SET_SCAN_MODE (SIOCIWFIRSTPRIV + 8) | ||
52 | #define AT76_GET_SCAN_MODE (SIOCIWFIRSTPRIV + 9) | ||
53 | |||
37 | #define CMD_STATUS_IDLE 0x00 | 54 | #define CMD_STATUS_IDLE 0x00 |
38 | #define CMD_STATUS_COMPLETE 0x01 | 55 | #define CMD_STATUS_COMPLETE 0x01 |
39 | #define CMD_STATUS_UNKNOWN 0x02 | 56 | #define CMD_STATUS_UNKNOWN 0x02 |
@@ -65,7 +82,6 @@ enum board_type { | |||
65 | #define MIB_MAC 0x03 | 82 | #define MIB_MAC 0x03 |
66 | #define MIB_MAC_MGMT 0x05 | 83 | #define MIB_MAC_MGMT 0x05 |
67 | #define MIB_MAC_WEP 0x06 | 84 | #define MIB_MAC_WEP 0x06 |
68 | #define MIB_MAC_ENCRYPTION 0x06 | ||
69 | #define MIB_PHY 0x07 | 85 | #define MIB_PHY 0x07 |
70 | #define MIB_FW_VERSION 0x08 | 86 | #define MIB_FW_VERSION 0x08 |
71 | #define MIB_MDOMAIN 0x09 | 87 | #define MIB_MDOMAIN 0x09 |
@@ -90,26 +106,6 @@ enum board_type { | |||
90 | #define AT76_PM_ON 2 | 106 | #define AT76_PM_ON 2 |
91 | #define AT76_PM_SMART 3 | 107 | #define AT76_PM_SMART 3 |
92 | 108 | ||
93 | /* cipher values for encryption keys */ | ||
94 | #define CIPHER_NONE 0 /* this value is only guessed */ | ||
95 | #define CIPHER_WEP64 1 | ||
96 | #define CIPHER_TKIP 2 | ||
97 | #define CIPHER_CCMP 3 | ||
98 | #define CIPHER_CCX 4 /* for consistency sake only */ | ||
99 | #define CIPHER_WEP128 5 | ||
100 | |||
101 | /* bit flags key types for encryption keys */ | ||
102 | #define KEY_PAIRWISE 2 | ||
103 | #define KEY_TX 4 | ||
104 | |||
105 | #define CIPHER_KEYS (4) | ||
106 | #define CIPHER_KEY_LEN (40) | ||
107 | |||
108 | struct key_config { | ||
109 | u8 cipher; | ||
110 | u8 keylen; | ||
111 | }; | ||
112 | |||
113 | struct hwcfg_r505 { | 109 | struct hwcfg_r505 { |
114 | u8 cr39_values[14]; | 110 | u8 cr39_values[14]; |
115 | u8 reserved1[14]; | 111 | u8 reserved1[14]; |
@@ -151,9 +147,6 @@ union at76_hwcfg { | |||
151 | 147 | ||
152 | #define WEP_SMALL_KEY_LEN (40 / 8) | 148 | #define WEP_SMALL_KEY_LEN (40 / 8) |
153 | #define WEP_LARGE_KEY_LEN (104 / 8) | 149 | #define WEP_LARGE_KEY_LEN (104 / 8) |
154 | #define WEP_KEYS (4) | ||
155 | |||
156 | |||
157 | 150 | ||
158 | struct at76_card_config { | 151 | struct at76_card_config { |
159 | u8 exclude_unencrypted; | 152 | u8 exclude_unencrypted; |
@@ -168,7 +161,7 @@ struct at76_card_config { | |||
168 | u8 privacy_invoked; | 161 | u8 privacy_invoked; |
169 | u8 wep_default_key_id; /* 0..3 */ | 162 | u8 wep_default_key_id; /* 0..3 */ |
170 | u8 current_ssid[32]; | 163 | u8 current_ssid[32]; |
171 | u8 wep_default_key_value[4][WEP_LARGE_KEY_LEN]; | 164 | u8 wep_default_key_value[4][WEP_KEY_LEN]; |
172 | u8 ssid_len; | 165 | u8 ssid_len; |
173 | u8 short_preamble; | 166 | u8 short_preamble; |
174 | __le16 beacon_period; | 167 | __le16 beacon_period; |
@@ -193,7 +186,7 @@ struct at76_rx_buffer { | |||
193 | u8 link_quality; | 186 | u8 link_quality; |
194 | u8 noise_level; | 187 | u8 noise_level; |
195 | __le32 rx_time; | 188 | __le32 rx_time; |
196 | u8 packet[IEEE80211_MAX_FRAG_THRESHOLD]; | 189 | u8 packet[IEEE80211_FRAME_LEN + IEEE80211_FCS_LEN]; |
197 | } __attribute__((packed)); | 190 | } __attribute__((packed)); |
198 | 191 | ||
199 | /* Length of Atmel-specific Tx header before 802.11 frame */ | 192 | /* Length of Atmel-specific Tx header before 802.11 frame */ |
@@ -203,11 +196,8 @@ struct at76_tx_buffer { | |||
203 | __le16 wlength; | 196 | __le16 wlength; |
204 | u8 tx_rate; | 197 | u8 tx_rate; |
205 | u8 padding; | 198 | u8 padding; |
206 | u8 key_id; | 199 | u8 reserved[4]; |
207 | u8 cipher_type; | 200 | u8 packet[IEEE80211_FRAME_LEN + IEEE80211_FCS_LEN]; |
208 | u8 cipher_length; | ||
209 | u8 reserved; | ||
210 | u8 packet[IEEE80211_MAX_FRAG_THRESHOLD]; | ||
211 | } __attribute__((packed)); | 201 | } __attribute__((packed)); |
212 | 202 | ||
213 | /* defines for scan_type below */ | 203 | /* defines for scan_type below */ |
@@ -254,7 +244,6 @@ struct set_mib_buffer { | |||
254 | u8 byte; | 244 | u8 byte; |
255 | __le16 word; | 245 | __le16 word; |
256 | u8 addr[ETH_ALEN]; | 246 | u8 addr[ETH_ALEN]; |
257 | u8 data[256]; /* we need more space for mib_mac_encryption */ | ||
258 | } data; | 247 | } data; |
259 | } __attribute__((packed)); | 248 | } __attribute__((packed)); |
260 | 249 | ||
@@ -328,24 +317,10 @@ struct mib_mac_wep { | |||
328 | u8 exclude_unencrypted; | 317 | u8 exclude_unencrypted; |
329 | __le32 wep_icv_error_count; | 318 | __le32 wep_icv_error_count; |
330 | __le32 wep_excluded_count; | 319 | __le32 wep_excluded_count; |
331 | u8 wep_default_keyvalue[WEP_KEYS][WEP_LARGE_KEY_LEN]; | 320 | u8 wep_default_keyvalue[WEP_KEYS][WEP_KEY_LEN]; |
332 | u8 encryption_level; /* 1 for 40bit, 2 for 104bit encryption */ | 321 | u8 encryption_level; /* 1 for 40bit, 2 for 104bit encryption */ |
333 | } __attribute__((packed)); | 322 | } __attribute__((packed)); |
334 | 323 | ||
335 | struct mib_mac_encryption { | ||
336 | u8 cipher_default_keyvalue[CIPHER_KEYS][CIPHER_KEY_LEN]; | ||
337 | u8 tkip_bssid[6]; | ||
338 | u8 privacy_invoked; | ||
339 | u8 cipher_default_key_id; | ||
340 | u8 cipher_default_group_key_id; | ||
341 | u8 exclude_unencrypted; | ||
342 | u8 wep_encryption_type; | ||
343 | u8 ckip_key_permutation; /* bool */ | ||
344 | __le32 wep_icv_error_count; | ||
345 | __le32 wep_excluded_count; | ||
346 | u8 key_rsc[CIPHER_KEYS][8]; | ||
347 | } __attribute__((packed)); | ||
348 | |||
349 | struct mib_phy { | 324 | struct mib_phy { |
350 | __le32 ed_threshold; | 325 | __le32 ed_threshold; |
351 | 326 | ||
@@ -389,6 +364,16 @@ struct at76_fw_header { | |||
389 | __le32 ext_fw_len; /* external firmware image length */ | 364 | __le32 ext_fw_len; /* external firmware image length */ |
390 | } __attribute__((packed)); | 365 | } __attribute__((packed)); |
391 | 366 | ||
367 | enum mac_state { | ||
368 | MAC_INIT, | ||
369 | MAC_SCANNING, | ||
370 | MAC_AUTH, | ||
371 | MAC_ASSOC, | ||
372 | MAC_JOINING, | ||
373 | MAC_CONNECTED, | ||
374 | MAC_OWN_IBSS | ||
375 | }; | ||
376 | |||
392 | /* a description of a regulatory domain and the allowed channels */ | 377 | /* a description of a regulatory domain and the allowed channels */ |
393 | struct reg_domain { | 378 | struct reg_domain { |
394 | u16 code; | 379 | u16 code; |
@@ -396,6 +381,47 @@ struct reg_domain { | |||
396 | u32 channel_map; /* if bit N is set, channel (N+1) is allowed */ | 381 | u32 channel_map; /* if bit N is set, channel (N+1) is allowed */ |
397 | }; | 382 | }; |
398 | 383 | ||
384 | /* how long do we keep a (I)BSS in the bss_list in jiffies | ||
385 | this should be long enough for the user to retrieve the table | ||
386 | (by iwlist ?) after the device started, because all entries from | ||
387 | other channels than the one the device locks on get removed, too */ | ||
388 | #define BSS_LIST_TIMEOUT (120 * HZ) | ||
389 | /* struct to store BSS info found during scan */ | ||
390 | #define BSS_LIST_MAX_RATE_LEN 32 /* 32 rates should be enough ... */ | ||
391 | |||
392 | struct bss_info { | ||
393 | struct list_head list; | ||
394 | |||
395 | u8 bssid[ETH_ALEN]; /* bssid */ | ||
396 | u8 ssid[IW_ESSID_MAX_SIZE]; /* essid */ | ||
397 | u8 ssid_len; /* length of ssid above */ | ||
398 | u8 channel; | ||
399 | u16 capa; /* BSS capabilities */ | ||
400 | u16 beacon_interval; /* beacon interval, Kus (1024 microseconds) */ | ||
401 | u8 rates[BSS_LIST_MAX_RATE_LEN]; /* supported rates in units of | ||
402 | 500 kbps, ORed with 0x80 for | ||
403 | basic rates */ | ||
404 | u8 rates_len; | ||
405 | |||
406 | /* quality of received beacon */ | ||
407 | u8 rssi; | ||
408 | u8 link_qual; | ||
409 | u8 noise_level; | ||
410 | |||
411 | unsigned long last_rx; /* time (jiffies) of last beacon received */ | ||
412 | }; | ||
413 | |||
414 | /* a rx data buffer to collect rx fragments */ | ||
415 | struct rx_data_buf { | ||
416 | u8 sender[ETH_ALEN]; /* sender address */ | ||
417 | u16 seqnr; /* sequence number */ | ||
418 | u16 fragnr; /* last fragment received */ | ||
419 | unsigned long last_rx; /* jiffies of last rx */ | ||
420 | struct sk_buff *skb; /* == NULL if entry is free */ | ||
421 | }; | ||
422 | |||
423 | #define NR_RX_DATA_BUF 8 | ||
424 | |||
399 | /* Data for one loaded firmware file */ | 425 | /* Data for one loaded firmware file */ |
400 | struct fwentry { | 426 | struct fwentry { |
401 | const char *const fwname; | 427 | const char *const fwname; |
@@ -412,9 +438,11 @@ struct fwentry { | |||
412 | 438 | ||
413 | struct at76_priv { | 439 | struct at76_priv { |
414 | struct usb_device *udev; /* USB device pointer */ | 440 | struct usb_device *udev; /* USB device pointer */ |
441 | struct net_device *netdev; /* net device pointer */ | ||
442 | struct net_device_stats stats; /* net device stats */ | ||
443 | struct iw_statistics wstats; /* wireless stats */ | ||
415 | 444 | ||
416 | struct sk_buff *rx_skb; /* skbuff for receiving data */ | 445 | struct sk_buff *rx_skb; /* skbuff for receiving data */ |
417 | struct sk_buff *tx_skb; /* skbuff for transmitting data */ | ||
418 | void *bulk_out_buffer; /* buffer for sending data */ | 446 | void *bulk_out_buffer; /* buffer for sending data */ |
419 | 447 | ||
420 | struct urb *tx_urb; /* URB for sending data */ | 448 | struct urb *tx_urb; /* URB for sending data */ |
@@ -426,17 +454,26 @@ struct at76_priv { | |||
426 | struct mutex mtx; /* locks this structure */ | 454 | struct mutex mtx; /* locks this structure */ |
427 | 455 | ||
428 | /* work queues */ | 456 | /* work queues */ |
457 | struct work_struct work_assoc_done; | ||
458 | struct work_struct work_join; | ||
459 | struct work_struct work_new_bss; | ||
460 | struct work_struct work_start_scan; | ||
429 | struct work_struct work_set_promisc; | 461 | struct work_struct work_set_promisc; |
430 | struct work_struct work_submit_rx; | 462 | struct work_struct work_submit_rx; |
431 | struct delayed_work dwork_hw_scan; | 463 | struct delayed_work dwork_restart; |
464 | struct delayed_work dwork_get_scan; | ||
465 | struct delayed_work dwork_beacon; | ||
466 | struct delayed_work dwork_auth; | ||
467 | struct delayed_work dwork_assoc; | ||
432 | 468 | ||
433 | struct tasklet_struct rx_tasklet; | 469 | struct tasklet_struct rx_tasklet; |
434 | 470 | ||
435 | /* the WEP stuff */ | 471 | /* the WEP stuff */ |
436 | int wep_enabled; /* 1 if WEP is enabled */ | 472 | int wep_enabled; /* 1 if WEP is enabled */ |
437 | int wep_key_id; /* key id to be used */ | 473 | int wep_key_id; /* key id to be used */ |
438 | u8 wep_keys[WEP_KEYS][WEP_LARGE_KEY_LEN]; /* WEP keys */ | 474 | u8 wep_keys[WEP_KEYS][WEP_KEY_LEN]; /* the four WEP keys, |
439 | u8 wep_keys_len[WEP_KEYS]; /* length of WEP keys */ | 475 | 5 or 13 bytes are used */ |
476 | u8 wep_keys_len[WEP_KEYS]; /* the length of the above keys */ | ||
440 | 477 | ||
441 | int channel; | 478 | int channel; |
442 | int iw_mode; | 479 | int iw_mode; |
@@ -458,13 +495,44 @@ struct at76_priv { | |||
458 | int scan_mode; /* SCAN_TYPE_ACTIVE, SCAN_TYPE_PASSIVE */ | 495 | int scan_mode; /* SCAN_TYPE_ACTIVE, SCAN_TYPE_PASSIVE */ |
459 | int scan_need_any; /* if set, need to scan for any ESSID */ | 496 | int scan_need_any; /* if set, need to scan for any ESSID */ |
460 | 497 | ||
498 | /* the list we got from scanning */ | ||
499 | spinlock_t bss_list_spinlock; /* protects bss_list operations */ | ||
500 | struct list_head bss_list; /* list of BSS we got beacons from */ | ||
501 | struct timer_list bss_list_timer; /* timer to purge old entries | ||
502 | from bss_list */ | ||
503 | struct bss_info *curr_bss; /* current BSS */ | ||
461 | u16 assoc_id; /* current association ID, if associated */ | 504 | u16 assoc_id; /* current association ID, if associated */ |
462 | 505 | ||
506 | u8 wanted_bssid[ETH_ALEN]; | ||
507 | int wanted_bssid_valid; /* != 0 if wanted_bssid is to be used */ | ||
508 | |||
509 | /* some data for infrastructure mode only */ | ||
510 | spinlock_t mgmt_spinlock; /* this spinlock protects access to | ||
511 | next_mgmt_bulk */ | ||
512 | |||
513 | struct at76_tx_buffer *next_mgmt_bulk; /* pending management msg to | ||
514 | send via bulk out */ | ||
515 | enum mac_state mac_state; | ||
516 | enum { | ||
517 | SCAN_IDLE, | ||
518 | SCAN_IN_PROGRESS, | ||
519 | SCAN_COMPLETED | ||
520 | } scan_state; | ||
521 | time_t last_scan; | ||
522 | |||
523 | int retries; /* remaining retries in case of timeout when | ||
524 | * sending AuthReq or AssocReq */ | ||
463 | u8 pm_mode; /* power management mode */ | 525 | u8 pm_mode; /* power management mode */ |
464 | u32 pm_period; /* power management period in microseconds */ | 526 | u32 pm_period; /* power management period in microseconds */ |
465 | 527 | ||
466 | struct reg_domain const *domain; /* reg domain description */ | 528 | struct reg_domain const *domain; /* reg domain description */ |
467 | 529 | ||
530 | /* iwspy support */ | ||
531 | spinlock_t spy_spinlock; | ||
532 | struct iw_spy_data spy_data; | ||
533 | |||
534 | struct iw_public_data wireless_data; | ||
535 | |||
468 | /* These fields contain HW config provided by the device (not all of | 536 | /* These fields contain HW config provided by the device (not all of |
469 | * these fields are used by all board types) */ | 537 | * these fields are used by all board types) */ |
470 | u8 mac_addr[ETH_ALEN]; | 538 | u8 mac_addr[ETH_ALEN]; |
@@ -472,6 +540,9 @@ struct at76_priv { | |||
472 | 540 | ||
473 | struct at76_card_config card_config; | 541 | struct at76_card_config card_config; |
474 | 542 | ||
543 | /* store rx fragments until complete */ | ||
544 | struct rx_data_buf rx_data[NR_RX_DATA_BUF]; | ||
545 | |||
475 | enum board_type board_type; | 546 | enum board_type board_type; |
476 | struct mib_fw_version fw_version; | 547 | struct mib_fw_version fw_version; |
477 | 548 | ||
@@ -479,20 +550,58 @@ struct at76_priv { | |||
479 | unsigned int netdev_registered:1; | 550 | unsigned int netdev_registered:1; |
480 | struct set_mib_buffer mib_buf; /* global buffer for set_mib calls */ | 551 | struct set_mib_buffer mib_buf; /* global buffer for set_mib calls */ |
481 | 552 | ||
553 | /* beacon counting */ | ||
482 | int beacon_period; /* period of mgmt beacons, Kus */ | 554 | int beacon_period; /* period of mgmt beacons, Kus */ |
555 | int beacons_received; | ||
556 | unsigned long beacons_last_qual; /* time we restarted counting | ||
557 | beacons */ | ||
558 | }; | ||
483 | 559 | ||
484 | struct ieee80211_hw *hw; | 560 | struct at76_rx_radiotap { |
485 | int mac80211_registered; | 561 | struct ieee80211_radiotap_header rt_hdr; |
486 | 562 | __le64 rt_tsft; | |
487 | struct key_config keys[4]; /* installed key types */ | 563 | u8 rt_flags; |
488 | u8 default_pairwise_key; | 564 | u8 rt_rate; |
489 | u8 default_group_key; | 565 | s8 rt_signal; |
566 | s8 rt_noise; | ||
490 | }; | 567 | }; |
491 | 568 | ||
492 | #define AT76_SUPPORTED_FILTERS FIF_PROMISC_IN_BSS | 569 | #define AT76_RX_RADIOTAP_PRESENT \ |
570 | ((1 << IEEE80211_RADIOTAP_TSFT) | \ | ||
571 | (1 << IEEE80211_RADIOTAP_FLAGS) | \ | ||
572 | (1 << IEEE80211_RADIOTAP_RATE) | \ | ||
573 | (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \ | ||
574 | (1 << IEEE80211_RADIOTAP_DB_ANTNOISE)) | ||
575 | |||
576 | #define BEACON_MAX_DATA_LENGTH 1500 | ||
577 | |||
578 | /* the maximum size of an AssocReq packet */ | ||
579 | #define ASSOCREQ_MAX_SIZE \ | ||
580 | (AT76_TX_HDRLEN + sizeof(struct ieee80211_assoc_request) + \ | ||
581 | 1 + 1 + IW_ESSID_MAX_SIZE + 1 + 1 + 4) | ||
582 | |||
583 | /* for shared secret auth, add the challenge text size */ | ||
584 | #define AUTH_FRAME_SIZE (AT76_TX_HDRLEN + sizeof(struct ieee80211_auth)) | ||
585 | |||
586 | /* Maximal number of AuthReq retries */ | ||
587 | #define AUTH_RETRIES 3 | ||
493 | 588 | ||
589 | /* Maximal number of AssocReq retries */ | ||
590 | #define ASSOC_RETRIES 3 | ||
591 | |||
592 | /* Beacon timeout in managed mode when we are connected */ | ||
593 | #define BEACON_TIMEOUT (10 * HZ) | ||
594 | |||
595 | /* Timeout for authentication response */ | ||
596 | #define AUTH_TIMEOUT (1 * HZ) | ||
597 | |||
598 | /* Timeout for association response */ | ||
599 | #define ASSOC_TIMEOUT (1 * HZ) | ||
600 | |||
601 | /* Polling interval when scan is running */ | ||
494 | #define SCAN_POLL_INTERVAL (HZ / 4) | 602 | #define SCAN_POLL_INTERVAL (HZ / 4) |
495 | 603 | ||
604 | /* Command completion timeout */ | ||
496 | #define CMD_COMPLETION_TIMEOUT (5 * HZ) | 605 | #define CMD_COMPLETION_TIMEOUT (5 * HZ) |
497 | 606 | ||
498 | #define DEF_RTS_THRESHOLD 1536 | 607 | #define DEF_RTS_THRESHOLD 1536 |
@@ -502,6 +611,8 @@ struct at76_priv { | |||
502 | #define DEF_SCAN_MIN_TIME 10 | 611 | #define DEF_SCAN_MIN_TIME 10 |
503 | #define DEF_SCAN_MAX_TIME 120 | 612 | #define DEF_SCAN_MAX_TIME 120 |
504 | 613 | ||
614 | #define MAX_RTS_THRESHOLD (MAX_FRAG_THRESHOLD + 1) | ||
615 | |||
505 | /* the max padding size for tx in bytes (see calc_padding) */ | 616 | /* the max padding size for tx in bytes (see calc_padding) */ |
506 | #define MAX_PADDING_SIZE 53 | 617 | #define MAX_PADDING_SIZE 53 |
507 | 618 | ||