Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c) |
2 | * | |
3 | * A driver for Hermes or Prism 2 chipset based PCMCIA wireless | |
4 | * adaptors, with Lucent/Agere, Intersil or Symbol firmware. | |
5 | * | |
6 | * Current maintainers (as of 29 September 2003) are: | |
7 | * Pavel Roskin <proski AT gnu.org> | |
8 | * and David Gibson <hermes AT gibson.dropbear.id.au> | |
9 | * | |
10 | * (C) Copyright David Gibson, IBM Corporation 2001-2003. | |
11 | * Copyright (C) 2000 David Gibson, Linuxcare Australia. | |
12 | * With some help from : | |
13 | * Copyright (C) 2001 Jean Tourrilhes, HP Labs | |
14 | * Copyright (C) 2001 Benjamin Herrenschmidt | |
15 | * | |
16 | * Based on dummy_cs.c 1.27 2000/06/12 21:27:25 | |
17 | * | |
18 | * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy | |
19 | * AT fasta.fh-dortmund.de> | |
20 | * http://www.stud.fh-dortmund.de/~andy/wvlan/ | |
21 | * | |
22 | * The contents of this file are subject to the Mozilla Public License | |
23 | * Version 1.1 (the "License"); you may not use this file except in | |
24 | * compliance with the License. You may obtain a copy of the License | |
25 | * at http://www.mozilla.org/MPL/ | |
26 | * | |
27 | * Software distributed under the License is distributed on an "AS IS" | |
28 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | |
29 | * the License for the specific language governing rights and | |
30 | * limitations under the License. | |
31 | * | |
32 | * The initial developer of the original code is David A. Hinds | |
33 | * <dahinds AT users.sourceforge.net>. Portions created by David | |
34 | * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights | |
35 | * Reserved. | |
36 | * | |
37 | * Alternatively, the contents of this file may be used under the | |
38 | * terms of the GNU General Public License version 2 (the "GPL"), in | |
39 | * which case the provisions of the GPL are applicable instead of the | |
40 | * above. If you wish to allow the use of your version of this file | |
41 | * only under the terms of the GPL and not to allow others to use your | |
42 | * version of this file under the MPL, indicate your decision by | |
43 | * deleting the provisions above and replace them with the notice and | |
44 | * other provisions required by the GPL. If you do not delete the | |
45 | * provisions above, a recipient may use your version of this file | |
46 | * under either the MPL or the GPL. */ | |
47 | ||
48 | /* | |
1da177e4 | 49 | * TODO |
1da177e4 LT |
50 | * o Handle de-encapsulation within network layer, provide 802.11 |
51 | * headers (patch from Thomas 'Dent' Mirlacher) | |
1da177e4 LT |
52 | * o Fix possible races in SPY handling. |
53 | * o Disconnect wireless extensions from fundamental configuration. | |
54 | * o (maybe) Software WEP support (patch from Stano Meduna). | |
55 | * o (maybe) Use multiple Tx buffers - driver handling queue | |
56 | * rather than firmware. | |
57 | */ | |
58 | ||
59 | /* Locking and synchronization: | |
60 | * | |
61 | * The basic principle is that everything is serialized through a | |
62 | * single spinlock, priv->lock. The lock is used in user, bh and irq | |
63 | * context, so when taken outside hardirq context it should always be | |
64 | * taken with interrupts disabled. The lock protects both the | |
65 | * hardware and the struct orinoco_private. | |
66 | * | |
67 | * Another flag, priv->hw_unavailable indicates that the hardware is | |
68 | * unavailable for an extended period of time (e.g. suspended, or in | |
69 | * the middle of a hard reset). This flag is protected by the | |
70 | * spinlock. All code which touches the hardware should check the | |
71 | * flag after taking the lock, and if it is set, give up on whatever | |
72 | * they are doing and drop the lock again. The orinoco_lock() | |
73 | * function handles this (it unlocks and returns -EBUSY if | |
74 | * hw_unavailable is non-zero). | |
75 | */ | |
76 | ||
77 | #define DRIVER_NAME "orinoco" | |
78 | ||
1da177e4 LT |
79 | #include <linux/module.h> |
80 | #include <linux/kernel.h> | |
81 | #include <linux/init.h> | |
d03032af | 82 | #include <linux/delay.h> |
1da177e4 | 83 | #include <linux/netdevice.h> |
1da177e4 | 84 | #include <linux/etherdevice.h> |
1fab2e8b | 85 | #include <linux/ethtool.h> |
3994d502 | 86 | #include <linux/firmware.h> |
39d1ffee | 87 | #include <linux/suspend.h> |
9c974fb1 | 88 | #include <linux/if_arp.h> |
1da177e4 | 89 | #include <linux/wireless.h> |
2c706002 | 90 | #include <linux/ieee80211.h> |
620554e4 | 91 | #include <net/iw_handler.h> |
1da177e4 | 92 | |
23edcc41 DK |
93 | #include <linux/scatterlist.h> |
94 | #include <linux/crypto.h> | |
95 | ||
1da177e4 | 96 | #include "hermes_rid.h" |
3994d502 | 97 | #include "hermes_dld.h" |
1da177e4 | 98 | #include "orinoco.h" |
1da177e4 LT |
99 | |
100 | /********************************************************************/ | |
101 | /* Module information */ | |
102 | /********************************************************************/ | |
103 | ||
104 | MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>"); | |
105 | MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards"); | |
106 | MODULE_LICENSE("Dual MPL/GPL"); | |
107 | ||
108 | /* Level of debugging. Used in the macros in orinoco.h */ | |
109 | #ifdef ORINOCO_DEBUG | |
110 | int orinoco_debug = ORINOCO_DEBUG; | |
111 | module_param(orinoco_debug, int, 0644); | |
112 | MODULE_PARM_DESC(orinoco_debug, "Debug level"); | |
113 | EXPORT_SYMBOL(orinoco_debug); | |
114 | #endif | |
115 | ||
116 | static int suppress_linkstatus; /* = 0 */ | |
117 | module_param(suppress_linkstatus, bool, 0644); | |
118 | MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes"); | |
7bb7c3a3 DG |
119 | static int ignore_disconnect; /* = 0 */ |
120 | module_param(ignore_disconnect, int, 0644); | |
121 | MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer"); | |
1da177e4 | 122 | |
98c4cae1 CH |
123 | static int force_monitor; /* = 0 */ |
124 | module_param(force_monitor, int, 0644); | |
125 | MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions"); | |
126 | ||
1da177e4 LT |
127 | /********************************************************************/ |
128 | /* Compile time configuration and compatibility stuff */ | |
129 | /********************************************************************/ | |
130 | ||
131 | /* We do this this way to avoid ifdefs in the actual code */ | |
132 | #ifdef WIRELESS_SPY | |
343c686c | 133 | #define SPY_NUMBER(priv) (priv->spy_data.spy_number) |
1da177e4 LT |
134 | #else |
135 | #define SPY_NUMBER(priv) 0 | |
136 | #endif /* WIRELESS_SPY */ | |
137 | ||
138 | /********************************************************************/ | |
139 | /* Internal constants */ | |
140 | /********************************************************************/ | |
141 | ||
95dd91fb CH |
142 | /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */ |
143 | static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; | |
144 | #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2) | |
145 | ||
1da177e4 | 146 | #define ORINOCO_MIN_MTU 256 |
2c706002 | 147 | #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD) |
1da177e4 LT |
148 | |
149 | #define SYMBOL_MAX_VER_LEN (14) | |
150 | #define USER_BAP 0 | |
151 | #define IRQ_BAP 1 | |
152 | #define MAX_IRQLOOPS_PER_IRQ 10 | |
153 | #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of | |
154 | * how many events the | |
155 | * device could | |
156 | * legitimately generate */ | |
157 | #define SMALL_KEY_SIZE 5 | |
158 | #define LARGE_KEY_SIZE 13 | |
159 | #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */ | |
160 | ||
161 | #define DUMMY_FID 0xFFFF | |
162 | ||
163 | /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \ | |
164 | HERMES_MAX_MULTICAST : 0)*/ | |
165 | #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST) | |
166 | ||
167 | #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \ | |
168 | | HERMES_EV_TX | HERMES_EV_TXEXC \ | |
169 | | HERMES_EV_WTERR | HERMES_EV_INFO \ | |
170 | | HERMES_EV_INFDROP ) | |
171 | ||
620554e4 CH |
172 | #define MAX_RID_LEN 1024 |
173 | ||
174 | static const struct iw_handler_def orinoco_handler_def; | |
7282d491 | 175 | static const struct ethtool_ops orinoco_ethtool_ops; |
620554e4 | 176 | |
1da177e4 LT |
177 | /********************************************************************/ |
178 | /* Data tables */ | |
179 | /********************************************************************/ | |
180 | ||
181 | /* The frequency of each channel in MHz */ | |
182 | static const long channel_frequency[] = { | |
183 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, | |
184 | 2447, 2452, 2457, 2462, 2467, 2472, 2484 | |
185 | }; | |
186 | #define NUM_CHANNELS ARRAY_SIZE(channel_frequency) | |
187 | ||
188 | /* This tables gives the actual meanings of the bitrate IDs returned | |
189 | * by the firmware. */ | |
190 | static struct { | |
191 | int bitrate; /* in 100s of kilobits */ | |
192 | int automatic; | |
193 | u16 agere_txratectrl; | |
194 | u16 intersil_txratectrl; | |
195 | } bitrate_table[] = { | |
196 | {110, 1, 3, 15}, /* Entry 0 is the default */ | |
197 | {10, 0, 1, 1}, | |
198 | {10, 1, 1, 1}, | |
199 | {20, 0, 2, 2}, | |
200 | {20, 1, 6, 3}, | |
201 | {55, 0, 4, 4}, | |
202 | {55, 1, 7, 7}, | |
203 | {110, 0, 5, 8}, | |
204 | }; | |
205 | #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table) | |
206 | ||
207 | /********************************************************************/ | |
208 | /* Data types */ | |
209 | /********************************************************************/ | |
210 | ||
30c2d3b4 PR |
211 | /* Beginning of the Tx descriptor, used in TxExc handling */ |
212 | struct hermes_txexc_data { | |
213 | struct hermes_tx_descriptor desc; | |
d133ae4c PR |
214 | __le16 frame_ctl; |
215 | __le16 duration_id; | |
95dd91fb | 216 | u8 addr1[ETH_ALEN]; |
1da177e4 LT |
217 | } __attribute__ ((packed)); |
218 | ||
8f2abf44 | 219 | /* Rx frame header except compatibility 802.3 header */ |
1da177e4 | 220 | struct hermes_rx_descriptor { |
8f2abf44 | 221 | /* Control */ |
d133ae4c PR |
222 | __le16 status; |
223 | __le32 time; | |
1da177e4 LT |
224 | u8 silence; |
225 | u8 signal; | |
226 | u8 rate; | |
227 | u8 rxflow; | |
d133ae4c | 228 | __le32 reserved; |
8f2abf44 CH |
229 | |
230 | /* 802.11 header */ | |
d133ae4c PR |
231 | __le16 frame_ctl; |
232 | __le16 duration_id; | |
8f2abf44 CH |
233 | u8 addr1[ETH_ALEN]; |
234 | u8 addr2[ETH_ALEN]; | |
235 | u8 addr3[ETH_ALEN]; | |
d133ae4c | 236 | __le16 seq_ctl; |
8f2abf44 CH |
237 | u8 addr4[ETH_ALEN]; |
238 | ||
239 | /* Data length */ | |
d133ae4c | 240 | __le16 data_len; |
1da177e4 LT |
241 | } __attribute__ ((packed)); |
242 | ||
243 | /********************************************************************/ | |
244 | /* Function prototypes */ | |
245 | /********************************************************************/ | |
246 | ||
1da177e4 LT |
247 | static int __orinoco_program_rids(struct net_device *dev); |
248 | static void __orinoco_set_multicast_list(struct net_device *dev); | |
1da177e4 | 249 | |
23edcc41 DK |
250 | /********************************************************************/ |
251 | /* Michael MIC crypto setup */ | |
252 | /********************************************************************/ | |
253 | #define MICHAEL_MIC_LEN 8 | |
254 | static int orinoco_mic_init(struct orinoco_private *priv) | |
255 | { | |
256 | priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0); | |
257 | if (IS_ERR(priv->tx_tfm_mic)) { | |
258 | printk(KERN_DEBUG "orinoco_mic_init: could not allocate " | |
259 | "crypto API michael_mic\n"); | |
260 | priv->tx_tfm_mic = NULL; | |
261 | return -ENOMEM; | |
262 | } | |
263 | ||
264 | priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0); | |
265 | if (IS_ERR(priv->rx_tfm_mic)) { | |
266 | printk(KERN_DEBUG "orinoco_mic_init: could not allocate " | |
267 | "crypto API michael_mic\n"); | |
268 | priv->rx_tfm_mic = NULL; | |
269 | return -ENOMEM; | |
270 | } | |
271 | ||
272 | return 0; | |
273 | } | |
274 | ||
275 | static void orinoco_mic_free(struct orinoco_private *priv) | |
276 | { | |
277 | if (priv->tx_tfm_mic) | |
278 | crypto_free_hash(priv->tx_tfm_mic); | |
279 | if (priv->rx_tfm_mic) | |
280 | crypto_free_hash(priv->rx_tfm_mic); | |
281 | } | |
282 | ||
283 | static int michael_mic(struct crypto_hash *tfm_michael, u8 *key, | |
284 | u8 *da, u8 *sa, u8 priority, | |
285 | u8 *data, size_t data_len, u8 *mic) | |
286 | { | |
287 | struct hash_desc desc; | |
288 | struct scatterlist sg[2]; | |
289 | u8 hdr[ETH_HLEN + 2]; /* size of header + padding */ | |
290 | ||
291 | if (tfm_michael == NULL) { | |
292 | printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n"); | |
293 | return -1; | |
294 | } | |
295 | ||
296 | /* Copy header into buffer. We need the padding on the end zeroed */ | |
297 | memcpy(&hdr[0], da, ETH_ALEN); | |
298 | memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN); | |
299 | hdr[ETH_ALEN*2] = priority; | |
300 | hdr[ETH_ALEN*2+1] = 0; | |
301 | hdr[ETH_ALEN*2+2] = 0; | |
302 | hdr[ETH_ALEN*2+3] = 0; | |
303 | ||
304 | /* Use scatter gather to MIC header and data in one go */ | |
305 | sg_init_table(sg, 2); | |
306 | sg_set_buf(&sg[0], hdr, sizeof(hdr)); | |
307 | sg_set_buf(&sg[1], data, data_len); | |
308 | ||
309 | if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN)) | |
310 | return -1; | |
311 | ||
312 | desc.tfm = tfm_michael; | |
313 | desc.flags = 0; | |
314 | return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr), | |
315 | mic); | |
316 | } | |
317 | ||
1da177e4 LT |
318 | /********************************************************************/ |
319 | /* Internal helper functions */ | |
320 | /********************************************************************/ | |
321 | ||
322 | static inline void set_port_type(struct orinoco_private *priv) | |
323 | { | |
324 | switch (priv->iw_mode) { | |
325 | case IW_MODE_INFRA: | |
326 | priv->port_type = 1; | |
327 | priv->createibss = 0; | |
328 | break; | |
329 | case IW_MODE_ADHOC: | |
330 | if (priv->prefer_port3) { | |
331 | priv->port_type = 3; | |
332 | priv->createibss = 0; | |
333 | } else { | |
334 | priv->port_type = priv->ibss_port; | |
335 | priv->createibss = 1; | |
336 | } | |
337 | break; | |
98c4cae1 CH |
338 | case IW_MODE_MONITOR: |
339 | priv->port_type = 3; | |
340 | priv->createibss = 0; | |
341 | break; | |
1da177e4 LT |
342 | default: |
343 | printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n", | |
344 | priv->ndev->name); | |
345 | } | |
346 | } | |
347 | ||
1e3428e9 DW |
348 | #define ORINOCO_MAX_BSS_COUNT 64 |
349 | static int orinoco_bss_data_allocate(struct orinoco_private *priv) | |
350 | { | |
01632fa4 | 351 | if (priv->bss_xbss_data) |
1e3428e9 DW |
352 | return 0; |
353 | ||
01632fa4 DK |
354 | if (priv->has_ext_scan) |
355 | priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT * | |
356 | sizeof(struct xbss_element), | |
357 | GFP_KERNEL); | |
358 | else | |
359 | priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT * | |
360 | sizeof(struct bss_element), | |
361 | GFP_KERNEL); | |
362 | ||
363 | if (!priv->bss_xbss_data) { | |
1e3428e9 DW |
364 | printk(KERN_WARNING "Out of memory allocating beacons"); |
365 | return -ENOMEM; | |
366 | } | |
367 | return 0; | |
368 | } | |
369 | ||
370 | static void orinoco_bss_data_free(struct orinoco_private *priv) | |
371 | { | |
01632fa4 DK |
372 | kfree(priv->bss_xbss_data); |
373 | priv->bss_xbss_data = NULL; | |
1e3428e9 DW |
374 | } |
375 | ||
01632fa4 DK |
376 | #define PRIV_BSS ((struct bss_element *)priv->bss_xbss_data) |
377 | #define PRIV_XBSS ((struct xbss_element *)priv->bss_xbss_data) | |
1e3428e9 DW |
378 | static void orinoco_bss_data_init(struct orinoco_private *priv) |
379 | { | |
380 | int i; | |
381 | ||
382 | INIT_LIST_HEAD(&priv->bss_free_list); | |
383 | INIT_LIST_HEAD(&priv->bss_list); | |
01632fa4 DK |
384 | if (priv->has_ext_scan) |
385 | for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++) | |
386 | list_add_tail(&(PRIV_XBSS[i].list), | |
387 | &priv->bss_free_list); | |
388 | else | |
389 | for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++) | |
390 | list_add_tail(&(PRIV_BSS[i].list), | |
391 | &priv->bss_free_list); | |
392 | ||
393 | } | |
394 | ||
395 | static inline u8 *orinoco_get_ie(u8 *data, size_t len, | |
2c706002 | 396 | enum ieee80211_eid eid) |
01632fa4 DK |
397 | { |
398 | u8 *p = data; | |
399 | while ((p + 2) < (data + len)) { | |
400 | if (p[0] == eid) | |
401 | return p; | |
402 | p += p[1] + 2; | |
403 | } | |
404 | return NULL; | |
405 | } | |
406 | ||
407 | #define WPA_OUI_TYPE "\x00\x50\xF2\x01" | |
408 | #define WPA_SELECTOR_LEN 4 | |
409 | static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len) | |
410 | { | |
411 | u8 *p = data; | |
412 | while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) { | |
2c706002 | 413 | if ((p[0] == WLAN_EID_GENERIC) && |
01632fa4 DK |
414 | (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0)) |
415 | return p; | |
416 | p += p[1] + 2; | |
417 | } | |
418 | return NULL; | |
1e3428e9 DW |
419 | } |
420 | ||
3994d502 DK |
421 | |
422 | /********************************************************************/ | |
423 | /* Download functionality */ | |
424 | /********************************************************************/ | |
425 | ||
426 | struct fw_info { | |
427 | char *pri_fw; | |
428 | char *sta_fw; | |
429 | char *ap_fw; | |
430 | u32 pda_addr; | |
431 | u16 pda_size; | |
432 | }; | |
433 | ||
434 | const static struct fw_info orinoco_fw[] = { | |
74734312 DK |
435 | { NULL, "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 }, |
436 | { NULL, "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 }, | |
437 | { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", NULL, 0x00003100, 512 } | |
3994d502 DK |
438 | }; |
439 | ||
440 | /* Structure used to access fields in FW | |
441 | * Make sure LE decoding macros are used | |
442 | */ | |
443 | struct orinoco_fw_header { | |
444 | char hdr_vers[6]; /* ASCII string for header version */ | |
445 | __le16 headersize; /* Total length of header */ | |
446 | __le32 entry_point; /* NIC entry point */ | |
447 | __le32 blocks; /* Number of blocks to program */ | |
448 | __le32 block_offset; /* Offset of block data from eof header */ | |
449 | __le32 pdr_offset; /* Offset to PDR data from eof header */ | |
450 | __le32 pri_offset; /* Offset to primary plug data */ | |
451 | __le32 compat_offset; /* Offset to compatibility data*/ | |
452 | char signature[0]; /* FW signature length headersize-20 */ | |
453 | } __attribute__ ((packed)); | |
454 | ||
455 | /* Download either STA or AP firmware into the card. */ | |
456 | static int | |
457 | orinoco_dl_firmware(struct orinoco_private *priv, | |
458 | const struct fw_info *fw, | |
459 | int ap) | |
460 | { | |
461 | /* Plug Data Area (PDA) */ | |
70458259 | 462 | __le16 *pda; |
3994d502 DK |
463 | |
464 | hermes_t *hw = &priv->hw; | |
465 | const struct firmware *fw_entry; | |
466 | const struct orinoco_fw_header *hdr; | |
467 | const unsigned char *first_block; | |
468 | const unsigned char *end; | |
469 | const char *firmware; | |
470 | struct net_device *dev = priv->ndev; | |
70458259 AB |
471 | int err = 0; |
472 | ||
473 | pda = kzalloc(fw->pda_size, GFP_KERNEL); | |
474 | if (!pda) | |
475 | return -ENOMEM; | |
3994d502 DK |
476 | |
477 | if (ap) | |
478 | firmware = fw->ap_fw; | |
479 | else | |
480 | firmware = fw->sta_fw; | |
481 | ||
482 | printk(KERN_DEBUG "%s: Attempting to download firmware %s\n", | |
483 | dev->name, firmware); | |
484 | ||
485 | /* Read current plug data */ | |
70458259 | 486 | err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0); |
3994d502 DK |
487 | printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err); |
488 | if (err) | |
70458259 | 489 | goto free; |
3994d502 | 490 | |
74734312 | 491 | if (!priv->cached_fw) { |
4fb30784 | 492 | err = request_firmware(&fw_entry, firmware, priv->dev); |
74734312 | 493 | |
4fb30784 AB |
494 | if (err) { |
495 | printk(KERN_ERR "%s: Cannot find firmware %s\n", | |
496 | dev->name, firmware); | |
497 | err = -ENOENT; | |
498 | goto free; | |
499 | } | |
74734312 DK |
500 | } else |
501 | fw_entry = priv->cached_fw; | |
3994d502 DK |
502 | |
503 | hdr = (const struct orinoco_fw_header *) fw_entry->data; | |
504 | ||
505 | /* Enable aux port to allow programming */ | |
506 | err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point)); | |
507 | printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err); | |
508 | if (err != 0) | |
509 | goto abort; | |
510 | ||
511 | /* Program data */ | |
512 | first_block = (fw_entry->data + | |
513 | le16_to_cpu(hdr->headersize) + | |
514 | le32_to_cpu(hdr->block_offset)); | |
515 | end = fw_entry->data + fw_entry->size; | |
516 | ||
517 | err = hermes_program(hw, first_block, end); | |
518 | printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err); | |
519 | if (err != 0) | |
520 | goto abort; | |
521 | ||
522 | /* Update production data */ | |
523 | first_block = (fw_entry->data + | |
524 | le16_to_cpu(hdr->headersize) + | |
525 | le32_to_cpu(hdr->pdr_offset)); | |
526 | ||
527 | err = hermes_apply_pda_with_defaults(hw, first_block, pda); | |
528 | printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err); | |
529 | if (err) | |
530 | goto abort; | |
531 | ||
532 | /* Tell card we've finished */ | |
533 | err = hermesi_program_end(hw); | |
534 | printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err); | |
535 | if (err != 0) | |
536 | goto abort; | |
537 | ||
538 | /* Check if we're running */ | |
539 | printk(KERN_DEBUG "%s: hermes_present returned %d\n", | |
540 | dev->name, hermes_present(hw)); | |
541 | ||
542 | abort: | |
74734312 DK |
543 | /* If we requested the firmware, release it. */ |
544 | if (!priv->cached_fw) | |
4fb30784 | 545 | release_firmware(fw_entry); |
70458259 AB |
546 | |
547 | free: | |
548 | kfree(pda); | |
3994d502 DK |
549 | return err; |
550 | } | |
551 | ||
552 | /* End markers */ | |
553 | #define TEXT_END 0x1A /* End of text header */ | |
554 | ||
555 | /* | |
556 | * Process a firmware image - stop the card, load the firmware, reset | |
557 | * the card and make sure it responds. For the secondary firmware take | |
558 | * care of the PDA - read it and then write it on top of the firmware. | |
559 | */ | |
560 | static int | |
561 | symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw, | |
562 | const unsigned char *image, const unsigned char *end, | |
563 | int secondary) | |
564 | { | |
565 | hermes_t *hw = &priv->hw; | |
70458259 | 566 | int ret = 0; |
3994d502 DK |
567 | const unsigned char *ptr; |
568 | const unsigned char *first_block; | |
569 | ||
570 | /* Plug Data Area (PDA) */ | |
70458259 | 571 | __le16 *pda = NULL; |
3994d502 DK |
572 | |
573 | /* Binary block begins after the 0x1A marker */ | |
574 | ptr = image; | |
575 | while (*ptr++ != TEXT_END); | |
576 | first_block = ptr; | |
577 | ||
578 | /* Read the PDA from EEPROM */ | |
579 | if (secondary) { | |
70458259 AB |
580 | pda = kzalloc(fw->pda_size, GFP_KERNEL); |
581 | if (!pda) | |
582 | return -ENOMEM; | |
583 | ||
584 | ret = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 1); | |
3994d502 | 585 | if (ret) |
70458259 | 586 | goto free; |
3994d502 DK |
587 | } |
588 | ||
589 | /* Stop the firmware, so that it can be safely rewritten */ | |
590 | if (priv->stop_fw) { | |
591 | ret = priv->stop_fw(priv, 1); | |
592 | if (ret) | |
70458259 | 593 | goto free; |
3994d502 DK |
594 | } |
595 | ||
596 | /* Program the adapter with new firmware */ | |
597 | ret = hermes_program(hw, first_block, end); | |
598 | if (ret) | |
70458259 | 599 | goto free; |
3994d502 DK |
600 | |
601 | /* Write the PDA to the adapter */ | |
602 | if (secondary) { | |
603 | size_t len = hermes_blocks_length(first_block); | |
604 | ptr = first_block + len; | |
605 | ret = hermes_apply_pda(hw, ptr, pda); | |
70458259 | 606 | kfree(pda); |
3994d502 DK |
607 | if (ret) |
608 | return ret; | |
609 | } | |
610 | ||
611 | /* Run the firmware */ | |
612 | if (priv->stop_fw) { | |
613 | ret = priv->stop_fw(priv, 0); | |
614 | if (ret) | |
615 | return ret; | |
616 | } | |
617 | ||
618 | /* Reset hermes chip and make sure it responds */ | |
619 | ret = hermes_init(hw); | |
620 | ||
621 | /* hermes_reset() should return 0 with the secondary firmware */ | |
622 | if (secondary && ret != 0) | |
623 | return -ENODEV; | |
624 | ||
625 | /* And this should work with any firmware */ | |
626 | if (!hermes_present(hw)) | |
627 | return -ENODEV; | |
628 | ||
629 | return 0; | |
70458259 AB |
630 | |
631 | free: | |
632 | kfree(pda); | |
633 | return ret; | |
3994d502 DK |
634 | } |
635 | ||
636 | ||
637 | /* | |
638 | * Download the firmware into the card, this also does a PCMCIA soft | |
639 | * reset on the card, to make sure it's in a sane state. | |
640 | */ | |
641 | static int | |
642 | symbol_dl_firmware(struct orinoco_private *priv, | |
643 | const struct fw_info *fw) | |
644 | { | |
645 | struct net_device *dev = priv->ndev; | |
646 | int ret; | |
647 | const struct firmware *fw_entry; | |
648 | ||
2cea7b26 DK |
649 | if (!priv->cached_pri_fw) { |
650 | if (request_firmware(&fw_entry, fw->pri_fw, priv->dev) != 0) { | |
651 | printk(KERN_ERR "%s: Cannot find firmware: %s\n", | |
652 | dev->name, fw->pri_fw); | |
653 | return -ENOENT; | |
654 | } | |
655 | } else | |
656 | fw_entry = priv->cached_pri_fw; | |
3994d502 DK |
657 | |
658 | /* Load primary firmware */ | |
659 | ret = symbol_dl_image(priv, fw, fw_entry->data, | |
660 | fw_entry->data + fw_entry->size, 0); | |
2cea7b26 DK |
661 | |
662 | if (!priv->cached_pri_fw) | |
663 | release_firmware(fw_entry); | |
3994d502 DK |
664 | if (ret) { |
665 | printk(KERN_ERR "%s: Primary firmware download failed\n", | |
666 | dev->name); | |
667 | return ret; | |
668 | } | |
669 | ||
2cea7b26 DK |
670 | if (!priv->cached_fw) { |
671 | if (request_firmware(&fw_entry, fw->sta_fw, priv->dev) != 0) { | |
672 | printk(KERN_ERR "%s: Cannot find firmware: %s\n", | |
673 | dev->name, fw->sta_fw); | |
674 | return -ENOENT; | |
675 | } | |
676 | } else | |
677 | fw_entry = priv->cached_fw; | |
3994d502 DK |
678 | |
679 | /* Load secondary firmware */ | |
680 | ret = symbol_dl_image(priv, fw, fw_entry->data, | |
681 | fw_entry->data + fw_entry->size, 1); | |
2cea7b26 DK |
682 | if (!priv->cached_fw) |
683 | release_firmware(fw_entry); | |
3994d502 DK |
684 | if (ret) { |
685 | printk(KERN_ERR "%s: Secondary firmware download failed\n", | |
686 | dev->name); | |
687 | } | |
688 | ||
689 | return ret; | |
690 | } | |
691 | ||
692 | static int orinoco_download(struct orinoco_private *priv) | |
693 | { | |
694 | int err = 0; | |
695 | /* Reload firmware */ | |
696 | switch (priv->firmware_type) { | |
697 | case FIRMWARE_TYPE_AGERE: | |
698 | /* case FIRMWARE_TYPE_INTERSIL: */ | |
699 | err = orinoco_dl_firmware(priv, | |
700 | &orinoco_fw[priv->firmware_type], 0); | |
701 | break; | |
702 | ||
703 | case FIRMWARE_TYPE_SYMBOL: | |
704 | err = symbol_dl_firmware(priv, | |
705 | &orinoco_fw[priv->firmware_type]); | |
706 | break; | |
707 | case FIRMWARE_TYPE_INTERSIL: | |
708 | break; | |
709 | } | |
710 | /* TODO: if we fail we probably need to reinitialise | |
711 | * the driver */ | |
712 | ||
713 | return err; | |
714 | } | |
715 | ||
39d1ffee | 716 | #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP) |
74734312 DK |
717 | static void orinoco_cache_fw(struct orinoco_private *priv, int ap) |
718 | { | |
719 | const struct firmware *fw_entry = NULL; | |
2cea7b26 | 720 | const char *pri_fw; |
74734312 DK |
721 | const char *fw; |
722 | ||
2cea7b26 | 723 | pri_fw = orinoco_fw[priv->firmware_type].pri_fw; |
74734312 DK |
724 | if (ap) |
725 | fw = orinoco_fw[priv->firmware_type].ap_fw; | |
726 | else | |
727 | fw = orinoco_fw[priv->firmware_type].sta_fw; | |
728 | ||
2cea7b26 DK |
729 | if (pri_fw) { |
730 | if (request_firmware(&fw_entry, pri_fw, priv->dev) == 0) | |
731 | priv->cached_pri_fw = fw_entry; | |
732 | } | |
733 | ||
74734312 DK |
734 | if (fw) { |
735 | if (request_firmware(&fw_entry, fw, priv->dev) == 0) | |
736 | priv->cached_fw = fw_entry; | |
737 | } | |
738 | } | |
739 | ||
740 | static void orinoco_uncache_fw(struct orinoco_private *priv) | |
741 | { | |
2cea7b26 DK |
742 | if (priv->cached_pri_fw) |
743 | release_firmware(priv->cached_pri_fw); | |
74734312 DK |
744 | if (priv->cached_fw) |
745 | release_firmware(priv->cached_fw); | |
746 | ||
2cea7b26 | 747 | priv->cached_pri_fw = NULL; |
74734312 DK |
748 | priv->cached_fw = NULL; |
749 | } | |
39d1ffee DK |
750 | #else |
751 | #define orinoco_cache_fw(priv, ap) | |
752 | #define orinoco_uncache_fw(priv) | |
753 | #endif | |
74734312 | 754 | |
1da177e4 LT |
755 | /********************************************************************/ |
756 | /* Device methods */ | |
757 | /********************************************************************/ | |
758 | ||
759 | static int orinoco_open(struct net_device *dev) | |
760 | { | |
761 | struct orinoco_private *priv = netdev_priv(dev); | |
762 | unsigned long flags; | |
763 | int err; | |
764 | ||
765 | if (orinoco_lock(priv, &flags) != 0) | |
766 | return -EBUSY; | |
767 | ||
768 | err = __orinoco_up(dev); | |
769 | ||
770 | if (! err) | |
771 | priv->open = 1; | |
772 | ||
773 | orinoco_unlock(priv, &flags); | |
774 | ||
775 | return err; | |
776 | } | |
777 | ||
ad8f451b | 778 | static int orinoco_stop(struct net_device *dev) |
1da177e4 LT |
779 | { |
780 | struct orinoco_private *priv = netdev_priv(dev); | |
781 | int err = 0; | |
782 | ||
783 | /* We mustn't use orinoco_lock() here, because we need to be | |
784 | able to close the interface even if hw_unavailable is set | |
785 | (e.g. as we're released after a PC Card removal) */ | |
786 | spin_lock_irq(&priv->lock); | |
787 | ||
788 | priv->open = 0; | |
789 | ||
790 | err = __orinoco_down(dev); | |
791 | ||
792 | spin_unlock_irq(&priv->lock); | |
793 | ||
794 | return err; | |
795 | } | |
796 | ||
797 | static struct net_device_stats *orinoco_get_stats(struct net_device *dev) | |
798 | { | |
799 | struct orinoco_private *priv = netdev_priv(dev); | |
800 | ||
801 | return &priv->stats; | |
802 | } | |
803 | ||
804 | static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev) | |
805 | { | |
806 | struct orinoco_private *priv = netdev_priv(dev); | |
807 | hermes_t *hw = &priv->hw; | |
808 | struct iw_statistics *wstats = &priv->wstats; | |
e67d9d9d | 809 | int err; |
1da177e4 LT |
810 | unsigned long flags; |
811 | ||
812 | if (! netif_device_present(dev)) { | |
813 | printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n", | |
814 | dev->name); | |
815 | return NULL; /* FIXME: Can we do better than this? */ | |
816 | } | |
817 | ||
e67d9d9d DG |
818 | /* If busy, return the old stats. Returning NULL may cause |
819 | * the interface to disappear from /proc/net/wireless */ | |
1da177e4 | 820 | if (orinoco_lock(priv, &flags) != 0) |
e67d9d9d DG |
821 | return wstats; |
822 | ||
823 | /* We can't really wait for the tallies inquiry command to | |
824 | * complete, so we just use the previous results and trigger | |
825 | * a new tallies inquiry command for next time - Jean II */ | |
826 | /* FIXME: Really we should wait for the inquiry to come back - | |
827 | * as it is the stats we give don't make a whole lot of sense. | |
828 | * Unfortunately, it's not clear how to do that within the | |
829 | * wireless extensions framework: I think we're in user | |
830 | * context, but a lock seems to be held by the time we get in | |
831 | * here so we're not safe to sleep here. */ | |
832 | hermes_inquire(hw, HERMES_INQ_TALLIES); | |
1da177e4 LT |
833 | |
834 | if (priv->iw_mode == IW_MODE_ADHOC) { | |
835 | memset(&wstats->qual, 0, sizeof(wstats->qual)); | |
836 | /* If a spy address is defined, we report stats of the | |
837 | * first spy address - Jean II */ | |
838 | if (SPY_NUMBER(priv)) { | |
343c686c PR |
839 | wstats->qual.qual = priv->spy_data.spy_stat[0].qual; |
840 | wstats->qual.level = priv->spy_data.spy_stat[0].level; | |
841 | wstats->qual.noise = priv->spy_data.spy_stat[0].noise; | |
842 | wstats->qual.updated = priv->spy_data.spy_stat[0].updated; | |
1da177e4 LT |
843 | } |
844 | } else { | |
845 | struct { | |
a208c4e1 | 846 | __le16 qual, signal, noise, unused; |
1da177e4 LT |
847 | } __attribute__ ((packed)) cq; |
848 | ||
849 | err = HERMES_READ_RECORD(hw, USER_BAP, | |
850 | HERMES_RID_COMMSQUALITY, &cq); | |
e67d9d9d DG |
851 | |
852 | if (!err) { | |
853 | wstats->qual.qual = (int)le16_to_cpu(cq.qual); | |
854 | wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95; | |
855 | wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95; | |
f941f859 | 856 | wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
e67d9d9d | 857 | } |
1da177e4 LT |
858 | } |
859 | ||
1da177e4 | 860 | orinoco_unlock(priv, &flags); |
1da177e4 LT |
861 | return wstats; |
862 | } | |
863 | ||
864 | static void orinoco_set_multicast_list(struct net_device *dev) | |
865 | { | |
866 | struct orinoco_private *priv = netdev_priv(dev); | |
867 | unsigned long flags; | |
868 | ||
869 | if (orinoco_lock(priv, &flags) != 0) { | |
870 | printk(KERN_DEBUG "%s: orinoco_set_multicast_list() " | |
871 | "called when hw_unavailable\n", dev->name); | |
872 | return; | |
873 | } | |
874 | ||
875 | __orinoco_set_multicast_list(dev); | |
876 | orinoco_unlock(priv, &flags); | |
877 | } | |
878 | ||
879 | static int orinoco_change_mtu(struct net_device *dev, int new_mtu) | |
880 | { | |
881 | struct orinoco_private *priv = netdev_priv(dev); | |
882 | ||
883 | if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) ) | |
884 | return -EINVAL; | |
885 | ||
2c706002 JB |
886 | /* MTU + encapsulation + header length */ |
887 | if ( (new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) > | |
1da177e4 LT |
888 | (priv->nicbuf_size - ETH_HLEN) ) |
889 | return -EINVAL; | |
890 | ||
891 | dev->mtu = new_mtu; | |
892 | ||
893 | return 0; | |
894 | } | |
895 | ||
896 | /********************************************************************/ | |
897 | /* Tx path */ | |
898 | /********************************************************************/ | |
899 | ||
900 | static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev) | |
901 | { | |
902 | struct orinoco_private *priv = netdev_priv(dev); | |
903 | struct net_device_stats *stats = &priv->stats; | |
904 | hermes_t *hw = &priv->hw; | |
905 | int err = 0; | |
906 | u16 txfid = priv->txfid; | |
1da177e4 | 907 | struct ethhdr *eh; |
6eecad77 | 908 | int tx_control; |
1da177e4 LT |
909 | unsigned long flags; |
910 | ||
1da177e4 LT |
911 | if (! netif_running(dev)) { |
912 | printk(KERN_ERR "%s: Tx on stopped device!\n", | |
913 | dev->name); | |
b34b867e | 914 | return NETDEV_TX_BUSY; |
1da177e4 LT |
915 | } |
916 | ||
917 | if (netif_queue_stopped(dev)) { | |
918 | printk(KERN_DEBUG "%s: Tx while transmitter busy!\n", | |
919 | dev->name); | |
b34b867e | 920 | return NETDEV_TX_BUSY; |
1da177e4 LT |
921 | } |
922 | ||
923 | if (orinoco_lock(priv, &flags) != 0) { | |
924 | printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n", | |
925 | dev->name); | |
b34b867e | 926 | return NETDEV_TX_BUSY; |
1da177e4 LT |
927 | } |
928 | ||
98c4cae1 | 929 | if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) { |
1da177e4 LT |
930 | /* Oops, the firmware hasn't established a connection, |
931 | silently drop the packet (this seems to be the | |
932 | safest approach). */ | |
470e2aa6 | 933 | goto drop; |
1da177e4 LT |
934 | } |
935 | ||
8d5be088 | 936 | /* Check packet length */ |
a28dc81d | 937 | if (skb->len < ETH_HLEN) |
470e2aa6 | 938 | goto drop; |
1da177e4 | 939 | |
6eecad77 DK |
940 | tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX; |
941 | ||
23edcc41 DK |
942 | if (priv->encode_alg == IW_ENCODE_ALG_TKIP) |
943 | tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) | | |
944 | HERMES_TXCTRL_MIC; | |
945 | ||
6eecad77 DK |
946 | if (priv->has_alt_txcntl) { |
947 | /* WPA enabled firmwares have tx_cntl at the end of | |
948 | * the 802.11 header. So write zeroed descriptor and | |
949 | * 802.11 header at the same time | |
950 | */ | |
951 | char desc[HERMES_802_3_OFFSET]; | |
952 | __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET]; | |
953 | ||
954 | memset(&desc, 0, sizeof(desc)); | |
955 | ||
956 | *txcntl = cpu_to_le16(tx_control); | |
957 | err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), | |
958 | txfid, 0); | |
959 | if (err) { | |
960 | if (net_ratelimit()) | |
961 | printk(KERN_ERR "%s: Error %d writing Tx " | |
962 | "descriptor to BAP\n", dev->name, err); | |
963 | goto busy; | |
964 | } | |
965 | } else { | |
966 | struct hermes_tx_descriptor desc; | |
967 | ||
968 | memset(&desc, 0, sizeof(desc)); | |
969 | ||
970 | desc.tx_control = cpu_to_le16(tx_control); | |
971 | err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), | |
972 | txfid, 0); | |
973 | if (err) { | |
974 | if (net_ratelimit()) | |
975 | printk(KERN_ERR "%s: Error %d writing Tx " | |
976 | "descriptor to BAP\n", dev->name, err); | |
977 | goto busy; | |
978 | } | |
1da177e4 | 979 | |
6eecad77 DK |
980 | /* Clear the 802.11 header and data length fields - some |
981 | * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused | |
982 | * if this isn't done. */ | |
983 | hermes_clear_words(hw, HERMES_DATA0, | |
984 | HERMES_802_3_OFFSET - HERMES_802_11_OFFSET); | |
985 | } | |
1da177e4 | 986 | |
23edcc41 DK |
987 | eh = (struct ethhdr *)skb->data; |
988 | ||
1da177e4 LT |
989 | /* Encapsulate Ethernet-II frames */ |
990 | if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */ | |
a28dc81d PR |
991 | struct header_struct { |
992 | struct ethhdr eth; /* 802.3 header */ | |
993 | u8 encap[6]; /* 802.2 header */ | |
994 | } __attribute__ ((packed)) hdr; | |
995 | ||
996 | /* Strip destination and source from the data */ | |
997 | skb_pull(skb, 2 * ETH_ALEN); | |
a28dc81d PR |
998 | |
999 | /* And move them to a separate header */ | |
1000 | memcpy(&hdr.eth, eh, 2 * ETH_ALEN); | |
1001 | hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len); | |
1002 | memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr)); | |
1003 | ||
23edcc41 DK |
1004 | /* Insert the SNAP header */ |
1005 | if (skb_headroom(skb) < sizeof(hdr)) { | |
1006 | printk(KERN_ERR | |
1007 | "%s: Not enough headroom for 802.2 headers %d\n", | |
1008 | dev->name, skb_headroom(skb)); | |
1009 | goto drop; | |
1da177e4 | 1010 | } |
23edcc41 DK |
1011 | eh = (struct ethhdr *) skb_push(skb, sizeof(hdr)); |
1012 | memcpy(eh, &hdr, sizeof(hdr)); | |
1da177e4 LT |
1013 | } |
1014 | ||
a28dc81d | 1015 | err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len, |
23edcc41 | 1016 | txfid, HERMES_802_3_OFFSET); |
1da177e4 LT |
1017 | if (err) { |
1018 | printk(KERN_ERR "%s: Error %d writing packet to BAP\n", | |
1019 | dev->name, err); | |
470e2aa6 | 1020 | goto busy; |
1da177e4 LT |
1021 | } |
1022 | ||
23edcc41 DK |
1023 | /* Calculate Michael MIC */ |
1024 | if (priv->encode_alg == IW_ENCODE_ALG_TKIP) { | |
1025 | u8 mic_buf[MICHAEL_MIC_LEN + 1]; | |
1026 | u8 *mic; | |
1027 | size_t offset; | |
1028 | size_t len; | |
1029 | ||
1030 | if (skb->len % 2) { | |
1031 | /* MIC start is on an odd boundary */ | |
1032 | mic_buf[0] = skb->data[skb->len - 1]; | |
1033 | mic = &mic_buf[1]; | |
1034 | offset = skb->len - 1; | |
1035 | len = MICHAEL_MIC_LEN + 1; | |
1036 | } else { | |
1037 | mic = &mic_buf[0]; | |
1038 | offset = skb->len; | |
1039 | len = MICHAEL_MIC_LEN; | |
1040 | } | |
1041 | ||
1042 | michael_mic(priv->tx_tfm_mic, | |
1043 | priv->tkip_key[priv->tx_key].tx_mic, | |
1044 | eh->h_dest, eh->h_source, 0 /* priority */, | |
1045 | skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic); | |
1046 | ||
1047 | /* Write the MIC */ | |
1048 | err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len, | |
1049 | txfid, HERMES_802_3_OFFSET + offset); | |
1050 | if (err) { | |
1051 | printk(KERN_ERR "%s: Error %d writing MIC to BAP\n", | |
1052 | dev->name, err); | |
1053 | goto busy; | |
1054 | } | |
1055 | } | |
1056 | ||
1da177e4 LT |
1057 | /* Finally, we actually initiate the send */ |
1058 | netif_stop_queue(dev); | |
1059 | ||
1060 | err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL, | |
1061 | txfid, NULL); | |
1062 | if (err) { | |
1063 | netif_start_queue(dev); | |
c367c21c AM |
1064 | if (net_ratelimit()) |
1065 | printk(KERN_ERR "%s: Error %d transmitting packet\n", | |
1066 | dev->name, err); | |
470e2aa6 | 1067 | goto busy; |
1da177e4 LT |
1068 | } |
1069 | ||
1070 | dev->trans_start = jiffies; | |
23edcc41 | 1071 | stats->tx_bytes += HERMES_802_3_OFFSET + skb->len; |
470e2aa6 | 1072 | goto ok; |
1da177e4 | 1073 | |
470e2aa6 PR |
1074 | drop: |
1075 | stats->tx_errors++; | |
1076 | stats->tx_dropped++; | |
1da177e4 | 1077 | |
470e2aa6 PR |
1078 | ok: |
1079 | orinoco_unlock(priv, &flags); | |
1da177e4 | 1080 | dev_kfree_skb(skb); |
b34b867e | 1081 | return NETDEV_TX_OK; |
1da177e4 | 1082 | |
470e2aa6 | 1083 | busy: |
2c1bd260 JB |
1084 | if (err == -EIO) |
1085 | schedule_work(&priv->reset_work); | |
1da177e4 | 1086 | orinoco_unlock(priv, &flags); |
b34b867e | 1087 | return NETDEV_TX_BUSY; |
1da177e4 LT |
1088 | } |
1089 | ||
1090 | static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw) | |
1091 | { | |
1092 | struct orinoco_private *priv = netdev_priv(dev); | |
1093 | u16 fid = hermes_read_regn(hw, ALLOCFID); | |
1094 | ||
1095 | if (fid != priv->txfid) { | |
1096 | if (fid != DUMMY_FID) | |
1097 | printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n", | |
1098 | dev->name, fid); | |
1099 | return; | |
1100 | } | |
1101 | ||
1102 | hermes_write_regn(hw, ALLOCFID, DUMMY_FID); | |
1103 | } | |
1104 | ||
1105 | static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw) | |
1106 | { | |
1107 | struct orinoco_private *priv = netdev_priv(dev); | |
1108 | struct net_device_stats *stats = &priv->stats; | |
1109 | ||
1110 | stats->tx_packets++; | |
1111 | ||
1112 | netif_wake_queue(dev); | |
1113 | ||
1114 | hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); | |
1115 | } | |
1116 | ||
1117 | static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw) | |
1118 | { | |
1119 | struct orinoco_private *priv = netdev_priv(dev); | |
1120 | struct net_device_stats *stats = &priv->stats; | |
1121 | u16 fid = hermes_read_regn(hw, TXCOMPLFID); | |
d133ae4c | 1122 | u16 status; |
30c2d3b4 | 1123 | struct hermes_txexc_data hdr; |
1da177e4 LT |
1124 | int err = 0; |
1125 | ||
1126 | if (fid == DUMMY_FID) | |
1127 | return; /* Nothing's really happened */ | |
1128 | ||
48ca7038 | 1129 | /* Read part of the frame header - we need status and addr1 */ |
95dd91fb | 1130 | err = hermes_bap_pread(hw, IRQ_BAP, &hdr, |
30c2d3b4 | 1131 | sizeof(struct hermes_txexc_data), |
95dd91fb CH |
1132 | fid, 0); |
1133 | ||
1134 | hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); | |
1135 | stats->tx_errors++; | |
1136 | ||
1da177e4 LT |
1137 | if (err) { |
1138 | printk(KERN_WARNING "%s: Unable to read descriptor on Tx error " | |
1139 | "(FID=%04X error %d)\n", | |
1140 | dev->name, fid, err); | |
95dd91fb | 1141 | return; |
1da177e4 LT |
1142 | } |
1143 | ||
95dd91fb CH |
1144 | DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name, |
1145 | err, fid); | |
1146 | ||
1147 | /* We produce a TXDROP event only for retry or lifetime | |
1148 | * exceeded, because that's the only status that really mean | |
1149 | * that this particular node went away. | |
1150 | * Other errors means that *we* screwed up. - Jean II */ | |
30c2d3b4 | 1151 | status = le16_to_cpu(hdr.desc.status); |
d133ae4c | 1152 | if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) { |
95dd91fb CH |
1153 | union iwreq_data wrqu; |
1154 | ||
1155 | /* Copy 802.11 dest address. | |
1156 | * We use the 802.11 header because the frame may | |
1157 | * not be 802.3 or may be mangled... | |
1158 | * In Ad-Hoc mode, it will be the node address. | |
1159 | * In managed mode, it will be most likely the AP addr | |
1160 | * User space will figure out how to convert it to | |
1161 | * whatever it needs (IP address or else). | |
1162 | * - Jean II */ | |
1163 | memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN); | |
1164 | wrqu.addr.sa_family = ARPHRD_ETHER; | |
1165 | ||
1166 | /* Send event to user space */ | |
1167 | wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL); | |
1168 | } | |
1da177e4 LT |
1169 | |
1170 | netif_wake_queue(dev); | |
1da177e4 LT |
1171 | } |
1172 | ||
1173 | static void orinoco_tx_timeout(struct net_device *dev) | |
1174 | { | |
1175 | struct orinoco_private *priv = netdev_priv(dev); | |
1176 | struct net_device_stats *stats = &priv->stats; | |
1177 | struct hermes *hw = &priv->hw; | |
1178 | ||
1179 | printk(KERN_WARNING "%s: Tx timeout! " | |
1180 | "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n", | |
1181 | dev->name, hermes_read_regn(hw, ALLOCFID), | |
1182 | hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT)); | |
1183 | ||
1184 | stats->tx_errors++; | |
1185 | ||
1186 | schedule_work(&priv->reset_work); | |
1187 | } | |
1188 | ||
1189 | /********************************************************************/ | |
1190 | /* Rx path (data frames) */ | |
1191 | /********************************************************************/ | |
1192 | ||
1193 | /* Does the frame have a SNAP header indicating it should be | |
1194 | * de-encapsulated to Ethernet-II? */ | |
1195 | static inline int is_ethersnap(void *_hdr) | |
1196 | { | |
1197 | u8 *hdr = _hdr; | |
1198 | ||
1199 | /* We de-encapsulate all packets which, a) have SNAP headers | |
1200 | * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header | |
1201 | * and where b) the OUI of the SNAP header is 00:00:00 or | |
1202 | * 00:00:f8 - we need both because different APs appear to use | |
1203 | * different OUIs for some reason */ | |
1204 | return (memcmp(hdr, &encaps_hdr, 5) == 0) | |
1205 | && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) ); | |
1206 | } | |
1207 | ||
1208 | static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac, | |
1209 | int level, int noise) | |
1210 | { | |
343c686c PR |
1211 | struct iw_quality wstats; |
1212 | wstats.level = level - 0x95; | |
1213 | wstats.noise = noise - 0x95; | |
1214 | wstats.qual = (level > noise) ? (level - noise) : 0; | |
f941f859 | 1215 | wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
343c686c PR |
1216 | /* Update spy records */ |
1217 | wireless_spy_update(dev, mac, &wstats); | |
1da177e4 LT |
1218 | } |
1219 | ||
1220 | static void orinoco_stat_gather(struct net_device *dev, | |
1221 | struct sk_buff *skb, | |
1222 | struct hermes_rx_descriptor *desc) | |
1223 | { | |
1224 | struct orinoco_private *priv = netdev_priv(dev); | |
1225 | ||
1226 | /* Using spy support with lots of Rx packets, like in an | |
1227 | * infrastructure (AP), will really slow down everything, because | |
1228 | * the MAC address must be compared to each entry of the spy list. | |
1229 | * If the user really asks for it (set some address in the | |
1230 | * spy list), we do it, but he will pay the price. | |
1231 | * Note that to get here, you need both WIRELESS_SPY | |
1232 | * compiled in AND some addresses in the list !!! | |
1233 | */ | |
1234 | /* Note : gcc will optimise the whole section away if | |
1235 | * WIRELESS_SPY is not defined... - Jean II */ | |
1236 | if (SPY_NUMBER(priv)) { | |
98e399f8 | 1237 | orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN, |
1da177e4 LT |
1238 | desc->signal, desc->silence); |
1239 | } | |
1240 | } | |
1241 | ||
98c4cae1 CH |
1242 | /* |
1243 | * orinoco_rx_monitor - handle received monitor frames. | |
1244 | * | |
1245 | * Arguments: | |
1246 | * dev network device | |
1247 | * rxfid received FID | |
1248 | * desc rx descriptor of the frame | |
1249 | * | |
1250 | * Call context: interrupt | |
1251 | */ | |
1252 | static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid, | |
1253 | struct hermes_rx_descriptor *desc) | |
1254 | { | |
1255 | u32 hdrlen = 30; /* return full header by default */ | |
1256 | u32 datalen = 0; | |
1257 | u16 fc; | |
1258 | int err; | |
1259 | int len; | |
1260 | struct sk_buff *skb; | |
1261 | struct orinoco_private *priv = netdev_priv(dev); | |
1262 | struct net_device_stats *stats = &priv->stats; | |
1263 | hermes_t *hw = &priv->hw; | |
1264 | ||
1265 | len = le16_to_cpu(desc->data_len); | |
1266 | ||
1267 | /* Determine the size of the header and the data */ | |
1268 | fc = le16_to_cpu(desc->frame_ctl); | |
1269 | switch (fc & IEEE80211_FCTL_FTYPE) { | |
1270 | case IEEE80211_FTYPE_DATA: | |
1271 | if ((fc & IEEE80211_FCTL_TODS) | |
1272 | && (fc & IEEE80211_FCTL_FROMDS)) | |
1273 | hdrlen = 30; | |
1274 | else | |
1275 | hdrlen = 24; | |
1276 | datalen = len; | |
1277 | break; | |
1278 | case IEEE80211_FTYPE_MGMT: | |
1279 | hdrlen = 24; | |
1280 | datalen = len; | |
1281 | break; | |
1282 | case IEEE80211_FTYPE_CTL: | |
1283 | switch (fc & IEEE80211_FCTL_STYPE) { | |
1284 | case IEEE80211_STYPE_PSPOLL: | |
1285 | case IEEE80211_STYPE_RTS: | |
1286 | case IEEE80211_STYPE_CFEND: | |
1287 | case IEEE80211_STYPE_CFENDACK: | |
1288 | hdrlen = 16; | |
1289 | break; | |
1290 | case IEEE80211_STYPE_CTS: | |
1291 | case IEEE80211_STYPE_ACK: | |
1292 | hdrlen = 10; | |
1293 | break; | |
1294 | } | |
1295 | break; | |
1296 | default: | |
1297 | /* Unknown frame type */ | |
1298 | break; | |
1299 | } | |
1300 | ||
1301 | /* sanity check the length */ | |
2c706002 | 1302 | if (datalen > IEEE80211_MAX_DATA_LEN + 12) { |
98c4cae1 CH |
1303 | printk(KERN_DEBUG "%s: oversized monitor frame, " |
1304 | "data length = %d\n", dev->name, datalen); | |
98c4cae1 CH |
1305 | stats->rx_length_errors++; |
1306 | goto update_stats; | |
1307 | } | |
1308 | ||
1309 | skb = dev_alloc_skb(hdrlen + datalen); | |
1310 | if (!skb) { | |
1311 | printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n", | |
1312 | dev->name); | |
bb6e093d | 1313 | goto update_stats; |
98c4cae1 CH |
1314 | } |
1315 | ||
1316 | /* Copy the 802.11 header to the skb */ | |
1317 | memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen); | |
459a98ed | 1318 | skb_reset_mac_header(skb); |
98c4cae1 CH |
1319 | |
1320 | /* If any, copy the data from the card to the skb */ | |
1321 | if (datalen > 0) { | |
1322 | err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen), | |
1323 | ALIGN(datalen, 2), rxfid, | |
1324 | HERMES_802_2_OFFSET); | |
1325 | if (err) { | |
1326 | printk(KERN_ERR "%s: error %d reading monitor frame\n", | |
1327 | dev->name, err); | |
1328 | goto drop; | |
1329 | } | |
1330 | } | |
1331 | ||
1332 | skb->dev = dev; | |
1333 | skb->ip_summed = CHECKSUM_NONE; | |
1334 | skb->pkt_type = PACKET_OTHERHOST; | |
1335 | skb->protocol = __constant_htons(ETH_P_802_2); | |
1336 | ||
98c4cae1 CH |
1337 | stats->rx_packets++; |
1338 | stats->rx_bytes += skb->len; | |
1339 | ||
1340 | netif_rx(skb); | |
1341 | return; | |
1342 | ||
1343 | drop: | |
1344 | dev_kfree_skb_irq(skb); | |
1345 | update_stats: | |
1346 | stats->rx_errors++; | |
1347 | stats->rx_dropped++; | |
1348 | } | |
1349 | ||
23edcc41 DK |
1350 | /* Get tsc from the firmware */ |
1351 | static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, | |
1352 | u8 *tsc) | |
1353 | { | |
1354 | hermes_t *hw = &priv->hw; | |
1355 | int err = 0; | |
1356 | u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE]; | |
1357 | ||
1358 | if ((key < 0) || (key > 4)) | |
1359 | return -EINVAL; | |
1360 | ||
1361 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV, | |
1362 | sizeof(tsc_arr), NULL, &tsc_arr); | |
1363 | if (!err) | |
1364 | memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0])); | |
1365 | ||
1366 | return err; | |
1367 | } | |
1368 | ||
1da177e4 LT |
1369 | static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw) |
1370 | { | |
1371 | struct orinoco_private *priv = netdev_priv(dev); | |
1372 | struct net_device_stats *stats = &priv->stats; | |
1373 | struct iw_statistics *wstats = &priv->wstats; | |
1374 | struct sk_buff *skb = NULL; | |
31afcef3 | 1375 | u16 rxfid, status; |
8f2abf44 | 1376 | int length; |
31afcef3 DK |
1377 | struct hermes_rx_descriptor *desc; |
1378 | struct orinoco_rx_data *rx_data; | |
1da177e4 LT |
1379 | int err; |
1380 | ||
31afcef3 DK |
1381 | desc = kmalloc(sizeof(*desc), GFP_ATOMIC); |
1382 | if (!desc) { | |
1383 | printk(KERN_WARNING | |
1384 | "%s: Can't allocate space for RX descriptor\n", | |
1385 | dev->name); | |
1386 | goto update_stats; | |
1387 | } | |
1388 | ||
1da177e4 LT |
1389 | rxfid = hermes_read_regn(hw, RXFID); |
1390 | ||
31afcef3 | 1391 | err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc), |
1da177e4 LT |
1392 | rxfid, 0); |
1393 | if (err) { | |
1394 | printk(KERN_ERR "%s: error %d reading Rx descriptor. " | |
1395 | "Frame dropped.\n", dev->name, err); | |
98c4cae1 | 1396 | goto update_stats; |
1da177e4 LT |
1397 | } |
1398 | ||
31afcef3 | 1399 | status = le16_to_cpu(desc->status); |
1da177e4 | 1400 | |
98c4cae1 CH |
1401 | if (status & HERMES_RXSTAT_BADCRC) { |
1402 | DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", | |
1403 | dev->name); | |
1404 | stats->rx_crc_errors++; | |
1405 | goto update_stats; | |
1da177e4 LT |
1406 | } |
1407 | ||
98c4cae1 CH |
1408 | /* Handle frames in monitor mode */ |
1409 | if (priv->iw_mode == IW_MODE_MONITOR) { | |
31afcef3 DK |
1410 | orinoco_rx_monitor(dev, rxfid, desc); |
1411 | goto out; | |
98c4cae1 | 1412 | } |
1da177e4 | 1413 | |
98c4cae1 CH |
1414 | if (status & HERMES_RXSTAT_UNDECRYPTABLE) { |
1415 | DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n", | |
1416 | dev->name); | |
1417 | wstats->discard.code++; | |
1418 | goto update_stats; | |
1da177e4 LT |
1419 | } |
1420 | ||
31afcef3 | 1421 | length = le16_to_cpu(desc->data_len); |
8f2abf44 | 1422 | |
1da177e4 LT |
1423 | /* Sanity checks */ |
1424 | if (length < 3) { /* No for even an 802.2 LLC header */ | |
1425 | /* At least on Symbol firmware with PCF we get quite a | |
1426 | lot of these legitimately - Poll frames with no | |
1427 | data. */ | |
31afcef3 | 1428 | goto out; |
1da177e4 | 1429 | } |
2c706002 | 1430 | if (length > IEEE80211_MAX_DATA_LEN) { |
1da177e4 LT |
1431 | printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n", |
1432 | dev->name, length); | |
1433 | stats->rx_length_errors++; | |
98c4cae1 | 1434 | goto update_stats; |
1da177e4 LT |
1435 | } |
1436 | ||
23edcc41 DK |
1437 | /* Payload size does not include Michael MIC. Increase payload |
1438 | * size to read it together with the data. */ | |
1439 | if (status & HERMES_RXSTAT_MIC) | |
1440 | length += MICHAEL_MIC_LEN; | |
1441 | ||
1da177e4 LT |
1442 | /* We need space for the packet data itself, plus an ethernet |
1443 | header, plus 2 bytes so we can align the IP header on a | |
1444 | 32bit boundary, plus 1 byte so we can read in odd length | |
1445 | packets from the card, which has an IO granularity of 16 | |
1446 | bits */ | |
1447 | skb = dev_alloc_skb(length+ETH_HLEN+2+1); | |
1448 | if (!skb) { | |
1449 | printk(KERN_WARNING "%s: Can't allocate skb for Rx\n", | |
1450 | dev->name); | |
98c4cae1 | 1451 | goto update_stats; |
1da177e4 LT |
1452 | } |
1453 | ||
8f2abf44 CH |
1454 | /* We'll prepend the header, so reserve space for it. The worst |
1455 | case is no decapsulation, when 802.3 header is prepended and | |
1456 | nothing is removed. 2 is for aligning the IP header. */ | |
1457 | skb_reserve(skb, ETH_HLEN + 2); | |
1458 | ||
1459 | err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length), | |
1460 | ALIGN(length, 2), rxfid, | |
1461 | HERMES_802_2_OFFSET); | |
1462 | if (err) { | |
1463 | printk(KERN_ERR "%s: error %d reading frame. " | |
1464 | "Frame dropped.\n", dev->name, err); | |
8f2abf44 CH |
1465 | goto drop; |
1466 | } | |
1da177e4 | 1467 | |
31afcef3 DK |
1468 | /* Add desc and skb to rx queue */ |
1469 | rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC); | |
1470 | if (!rx_data) { | |
1471 | printk(KERN_WARNING "%s: Can't allocate RX packet\n", | |
1472 | dev->name); | |
1473 | goto drop; | |
1474 | } | |
1475 | rx_data->desc = desc; | |
1476 | rx_data->skb = skb; | |
1477 | list_add_tail(&rx_data->list, &priv->rx_list); | |
1478 | tasklet_schedule(&priv->rx_tasklet); | |
1479 | ||
1480 | return; | |
1481 | ||
1482 | drop: | |
1483 | dev_kfree_skb_irq(skb); | |
1484 | update_stats: | |
1485 | stats->rx_errors++; | |
1486 | stats->rx_dropped++; | |
1487 | out: | |
1488 | kfree(desc); | |
1489 | } | |
1490 | ||
1491 | static void orinoco_rx(struct net_device *dev, | |
1492 | struct hermes_rx_descriptor *desc, | |
1493 | struct sk_buff *skb) | |
1494 | { | |
1495 | struct orinoco_private *priv = netdev_priv(dev); | |
1496 | struct net_device_stats *stats = &priv->stats; | |
1497 | u16 status, fc; | |
1498 | int length; | |
1499 | struct ethhdr *hdr; | |
1500 | ||
1501 | status = le16_to_cpu(desc->status); | |
1502 | length = le16_to_cpu(desc->data_len); | |
1503 | fc = le16_to_cpu(desc->frame_ctl); | |
1504 | ||
23edcc41 DK |
1505 | /* Calculate and check MIC */ |
1506 | if (status & HERMES_RXSTAT_MIC) { | |
1507 | int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >> | |
1508 | HERMES_MIC_KEY_ID_SHIFT); | |
1509 | u8 mic[MICHAEL_MIC_LEN]; | |
1510 | u8 *rxmic; | |
1511 | u8 *src = (fc & IEEE80211_FCTL_FROMDS) ? | |
1512 | desc->addr3 : desc->addr2; | |
1513 | ||
1514 | /* Extract Michael MIC from payload */ | |
1515 | rxmic = skb->data + skb->len - MICHAEL_MIC_LEN; | |
1516 | ||
1517 | skb_trim(skb, skb->len - MICHAEL_MIC_LEN); | |
1518 | length -= MICHAEL_MIC_LEN; | |
1519 | ||
1520 | michael_mic(priv->rx_tfm_mic, | |
1521 | priv->tkip_key[key_id].rx_mic, | |
1522 | desc->addr1, | |
1523 | src, | |
1524 | 0, /* priority or QoS? */ | |
1525 | skb->data, | |
1526 | skb->len, | |
1527 | &mic[0]); | |
1528 | ||
1529 | if (memcmp(mic, rxmic, | |
1530 | MICHAEL_MIC_LEN)) { | |
1531 | union iwreq_data wrqu; | |
1532 | struct iw_michaelmicfailure wxmic; | |
23edcc41 DK |
1533 | |
1534 | printk(KERN_WARNING "%s: " | |
e174961c | 1535 | "Invalid Michael MIC in data frame from %pM, " |
23edcc41 | 1536 | "using key %i\n", |
e174961c | 1537 | dev->name, src, key_id); |
23edcc41 DK |
1538 | |
1539 | /* TODO: update stats */ | |
1540 | ||
1541 | /* Notify userspace */ | |
1542 | memset(&wxmic, 0, sizeof(wxmic)); | |
1543 | wxmic.flags = key_id & IW_MICFAILURE_KEY_ID; | |
1544 | wxmic.flags |= (desc->addr1[0] & 1) ? | |
1545 | IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE; | |
1546 | wxmic.src_addr.sa_family = ARPHRD_ETHER; | |
1547 | memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN); | |
1548 | ||
1549 | (void) orinoco_hw_get_tkip_iv(priv, key_id, | |
1550 | &wxmic.tsc[0]); | |
1551 | ||
1552 | memset(&wrqu, 0, sizeof(wrqu)); | |
1553 | wrqu.data.length = sizeof(wxmic); | |
1554 | wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, | |
1555 | (char *) &wxmic); | |
1556 | ||
1557 | goto drop; | |
1558 | } | |
1559 | } | |
1560 | ||
1da177e4 LT |
1561 | /* Handle decapsulation |
1562 | * In most cases, the firmware tell us about SNAP frames. | |
1563 | * For some reason, the SNAP frames sent by LinkSys APs | |
1564 | * are not properly recognised by most firmwares. | |
1565 | * So, check ourselves */ | |
8f2abf44 CH |
1566 | if (length >= ENCAPS_OVERHEAD && |
1567 | (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) || | |
1568 | ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) || | |
1569 | is_ethersnap(skb->data))) { | |
1da177e4 LT |
1570 | /* These indicate a SNAP within 802.2 LLC within |
1571 | 802.11 frame which we'll need to de-encapsulate to | |
1572 | the original EthernetII frame. */ | |
8f2abf44 | 1573 | hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD); |
1da177e4 | 1574 | } else { |
8f2abf44 CH |
1575 | /* 802.3 frame - prepend 802.3 header as is */ |
1576 | hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN); | |
1577 | hdr->h_proto = htons(length); | |
1da177e4 | 1578 | } |
31afcef3 | 1579 | memcpy(hdr->h_dest, desc->addr1, ETH_ALEN); |
8f2abf44 | 1580 | if (fc & IEEE80211_FCTL_FROMDS) |
31afcef3 | 1581 | memcpy(hdr->h_source, desc->addr3, ETH_ALEN); |
8f2abf44 | 1582 | else |
31afcef3 | 1583 | memcpy(hdr->h_source, desc->addr2, ETH_ALEN); |
1da177e4 | 1584 | |
1da177e4 LT |
1585 | skb->protocol = eth_type_trans(skb, dev); |
1586 | skb->ip_summed = CHECKSUM_NONE; | |
8f2abf44 CH |
1587 | if (fc & IEEE80211_FCTL_TODS) |
1588 | skb->pkt_type = PACKET_OTHERHOST; | |
1da177e4 LT |
1589 | |
1590 | /* Process the wireless stats if needed */ | |
31afcef3 | 1591 | orinoco_stat_gather(dev, skb, desc); |
1da177e4 LT |
1592 | |
1593 | /* Pass the packet to the networking stack */ | |
1594 | netif_rx(skb); | |
1595 | stats->rx_packets++; | |
1596 | stats->rx_bytes += length; | |
1597 | ||
1598 | return; | |
23edcc41 DK |
1599 | |
1600 | drop: | |
1601 | dev_kfree_skb(skb); | |
1602 | stats->rx_errors++; | |
1603 | stats->rx_dropped++; | |
31afcef3 | 1604 | } |
1da177e4 | 1605 | |
31afcef3 DK |
1606 | static void orinoco_rx_isr_tasklet(unsigned long data) |
1607 | { | |
1608 | struct net_device *dev = (struct net_device *) data; | |
1609 | struct orinoco_private *priv = netdev_priv(dev); | |
1610 | struct orinoco_rx_data *rx_data, *temp; | |
1611 | struct hermes_rx_descriptor *desc; | |
1612 | struct sk_buff *skb; | |
20953ad6 DK |
1613 | unsigned long flags; |
1614 | ||
1615 | /* orinoco_rx requires the driver lock, and we also need to | |
1616 | * protect priv->rx_list, so just hold the lock over the | |
1617 | * lot. | |
1618 | * | |
1619 | * If orinoco_lock fails, we've unplugged the card. In this | |
1620 | * case just abort. */ | |
1621 | if (orinoco_lock(priv, &flags) != 0) | |
1622 | return; | |
31afcef3 DK |
1623 | |
1624 | /* extract desc and skb from queue */ | |
1625 | list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) { | |
1626 | desc = rx_data->desc; | |
1627 | skb = rx_data->skb; | |
1628 | list_del(&rx_data->list); | |
1629 | kfree(rx_data); | |
1630 | ||
1631 | orinoco_rx(dev, desc, skb); | |
1632 | ||
1633 | kfree(desc); | |
1634 | } | |
20953ad6 DK |
1635 | |
1636 | orinoco_unlock(priv, &flags); | |
1da177e4 LT |
1637 | } |
1638 | ||
1639 | /********************************************************************/ | |
1640 | /* Rx path (info frames) */ | |
1641 | /********************************************************************/ | |
1642 | ||
1643 | static void print_linkstatus(struct net_device *dev, u16 status) | |
1644 | { | |
1645 | char * s; | |
1646 | ||
1647 | if (suppress_linkstatus) | |
1648 | return; | |
1649 | ||
1650 | switch (status) { | |
1651 | case HERMES_LINKSTATUS_NOT_CONNECTED: | |
1652 | s = "Not Connected"; | |
1653 | break; | |
1654 | case HERMES_LINKSTATUS_CONNECTED: | |
1655 | s = "Connected"; | |
1656 | break; | |
1657 | case HERMES_LINKSTATUS_DISCONNECTED: | |
1658 | s = "Disconnected"; | |
1659 | break; | |
1660 | case HERMES_LINKSTATUS_AP_CHANGE: | |
1661 | s = "AP Changed"; | |
1662 | break; | |
1663 | case HERMES_LINKSTATUS_AP_OUT_OF_RANGE: | |
1664 | s = "AP Out of Range"; | |
1665 | break; | |
1666 | case HERMES_LINKSTATUS_AP_IN_RANGE: | |
1667 | s = "AP In Range"; | |
1668 | break; | |
1669 | case HERMES_LINKSTATUS_ASSOC_FAILED: | |
1670 | s = "Association Failed"; | |
1671 | break; | |
1672 | default: | |
1673 | s = "UNKNOWN"; | |
1674 | } | |
1675 | ||
11eaea41 | 1676 | printk(KERN_DEBUG "%s: New link status: %s (%04x)\n", |
1da177e4 LT |
1677 | dev->name, s, status); |
1678 | } | |
1679 | ||
16739b06 | 1680 | /* Search scan results for requested BSSID, join it if found */ |
c4028958 | 1681 | static void orinoco_join_ap(struct work_struct *work) |
16739b06 | 1682 | { |
c4028958 DH |
1683 | struct orinoco_private *priv = |
1684 | container_of(work, struct orinoco_private, join_work); | |
1685 | struct net_device *dev = priv->ndev; | |
16739b06 CH |
1686 | struct hermes *hw = &priv->hw; |
1687 | int err; | |
1688 | unsigned long flags; | |
1689 | struct join_req { | |
1690 | u8 bssid[ETH_ALEN]; | |
d133ae4c | 1691 | __le16 channel; |
16739b06 CH |
1692 | } __attribute__ ((packed)) req; |
1693 | const int atom_len = offsetof(struct prism2_scan_apinfo, atim); | |
c89cc225 | 1694 | struct prism2_scan_apinfo *atom = NULL; |
16739b06 | 1695 | int offset = 4; |
c89cc225 | 1696 | int found = 0; |
16739b06 CH |
1697 | u8 *buf; |
1698 | u16 len; | |
1699 | ||
1700 | /* Allocate buffer for scan results */ | |
1701 | buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL); | |
1702 | if (! buf) | |
1703 | return; | |
1704 | ||
1705 | if (orinoco_lock(priv, &flags) != 0) | |
f3cb4cc1 | 1706 | goto fail_lock; |
16739b06 CH |
1707 | |
1708 | /* Sanity checks in case user changed something in the meantime */ | |
1709 | if (! priv->bssid_fixed) | |
1710 | goto out; | |
1711 | ||
1712 | if (strlen(priv->desired_essid) == 0) | |
1713 | goto out; | |
1714 | ||
1715 | /* Read scan results from the firmware */ | |
1716 | err = hermes_read_ltv(hw, USER_BAP, | |
1717 | HERMES_RID_SCANRESULTSTABLE, | |
1718 | MAX_SCAN_LEN, &len, buf); | |
1719 | if (err) { | |
1720 | printk(KERN_ERR "%s: Cannot read scan results\n", | |
1721 | dev->name); | |
1722 | goto out; | |
1723 | } | |
1724 | ||
1725 | len = HERMES_RECLEN_TO_BYTES(len); | |
1726 | ||
1727 | /* Go through the scan results looking for the channel of the AP | |
1728 | * we were requested to join */ | |
1729 | for (; offset + atom_len <= len; offset += atom_len) { | |
1730 | atom = (struct prism2_scan_apinfo *) (buf + offset); | |
c89cc225 PR |
1731 | if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) { |
1732 | found = 1; | |
1733 | break; | |
1734 | } | |
16739b06 CH |
1735 | } |
1736 | ||
c89cc225 PR |
1737 | if (! found) { |
1738 | DEBUG(1, "%s: Requested AP not found in scan results\n", | |
1739 | dev->name); | |
1740 | goto out; | |
1741 | } | |
16739b06 | 1742 | |
16739b06 CH |
1743 | memcpy(req.bssid, priv->desired_bssid, ETH_ALEN); |
1744 | req.channel = atom->channel; /* both are little-endian */ | |
1745 | err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST, | |
1746 | &req); | |
1747 | if (err) | |
1748 | printk(KERN_ERR "%s: Error issuing join request\n", dev->name); | |
1749 | ||
1750 | out: | |
16739b06 | 1751 | orinoco_unlock(priv, &flags); |
f3cb4cc1 PR |
1752 | |
1753 | fail_lock: | |
1754 | kfree(buf); | |
16739b06 CH |
1755 | } |
1756 | ||
95dd91fb | 1757 | /* Send new BSSID to userspace */ |
6cd90b1c | 1758 | static void orinoco_send_bssid_wevent(struct orinoco_private *priv) |
95dd91fb | 1759 | { |
c4028958 | 1760 | struct net_device *dev = priv->ndev; |
95dd91fb CH |
1761 | struct hermes *hw = &priv->hw; |
1762 | union iwreq_data wrqu; | |
1763 | int err; | |
95dd91fb | 1764 | |
499b702a | 1765 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID, |
95dd91fb CH |
1766 | ETH_ALEN, NULL, wrqu.ap_addr.sa_data); |
1767 | if (err != 0) | |
6cd90b1c | 1768 | return; |
95dd91fb CH |
1769 | |
1770 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1771 | ||
1772 | /* Send event to user space */ | |
1773 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); | |
6cd90b1c DK |
1774 | } |
1775 | ||
06009fda DK |
1776 | static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv) |
1777 | { | |
1778 | struct net_device *dev = priv->ndev; | |
1779 | struct hermes *hw = &priv->hw; | |
1780 | union iwreq_data wrqu; | |
1781 | int err; | |
1782 | u8 buf[88]; | |
1783 | u8 *ie; | |
1784 | ||
1785 | if (!priv->has_wpa) | |
1786 | return; | |
1787 | ||
499b702a | 1788 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO, |
06009fda DK |
1789 | sizeof(buf), NULL, &buf); |
1790 | if (err != 0) | |
1791 | return; | |
1792 | ||
1793 | ie = orinoco_get_wpa_ie(buf, sizeof(buf)); | |
1794 | if (ie) { | |
1795 | int rem = sizeof(buf) - (ie - &buf[0]); | |
1796 | wrqu.data.length = ie[1] + 2; | |
1797 | if (wrqu.data.length > rem) | |
1798 | wrqu.data.length = rem; | |
1799 | ||
1800 | if (wrqu.data.length) | |
1801 | /* Send event to user space */ | |
1802 | wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie); | |
1803 | } | |
1804 | } | |
1805 | ||
1806 | static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv) | |
1807 | { | |
1808 | struct net_device *dev = priv->ndev; | |
1809 | struct hermes *hw = &priv->hw; | |
1810 | union iwreq_data wrqu; | |
1811 | int err; | |
1812 | u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */ | |
1813 | u8 *ie; | |
1814 | ||
1815 | if (!priv->has_wpa) | |
1816 | return; | |
1817 | ||
499b702a | 1818 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO, |
06009fda DK |
1819 | sizeof(buf), NULL, &buf); |
1820 | if (err != 0) | |
1821 | return; | |
1822 | ||
1823 | ie = orinoco_get_wpa_ie(buf, sizeof(buf)); | |
1824 | if (ie) { | |
1825 | int rem = sizeof(buf) - (ie - &buf[0]); | |
1826 | wrqu.data.length = ie[1] + 2; | |
1827 | if (wrqu.data.length > rem) | |
1828 | wrqu.data.length = rem; | |
1829 | ||
1830 | if (wrqu.data.length) | |
1831 | /* Send event to user space */ | |
1832 | wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie); | |
1833 | } | |
1834 | } | |
1835 | ||
6cd90b1c DK |
1836 | static void orinoco_send_wevents(struct work_struct *work) |
1837 | { | |
1838 | struct orinoco_private *priv = | |
1839 | container_of(work, struct orinoco_private, wevent_work); | |
1840 | unsigned long flags; | |
1841 | ||
1842 | if (orinoco_lock(priv, &flags) != 0) | |
1843 | return; | |
1844 | ||
06009fda DK |
1845 | orinoco_send_assocreqie_wevent(priv); |
1846 | orinoco_send_assocrespie_wevent(priv); | |
6cd90b1c | 1847 | orinoco_send_bssid_wevent(priv); |
8aeabc37 | 1848 | |
95dd91fb CH |
1849 | orinoco_unlock(priv, &flags); |
1850 | } | |
1851 | ||
1e3428e9 DW |
1852 | static inline void orinoco_clear_scan_results(struct orinoco_private *priv, |
1853 | unsigned long scan_age) | |
1854 | { | |
01632fa4 DK |
1855 | if (priv->has_ext_scan) { |
1856 | struct xbss_element *bss; | |
1857 | struct xbss_element *tmp_bss; | |
1858 | ||
1859 | /* Blow away current list of scan results */ | |
1860 | list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) { | |
1861 | if (!scan_age || | |
1862 | time_after(jiffies, bss->last_scanned + scan_age)) { | |
1863 | list_move_tail(&bss->list, | |
1864 | &priv->bss_free_list); | |
1865 | /* Don't blow away ->list, just BSS data */ | |
1866 | memset(&bss->bss, 0, sizeof(bss->bss)); | |
1867 | bss->last_scanned = 0; | |
1868 | } | |
1e3428e9 | 1869 | } |
01632fa4 DK |
1870 | } else { |
1871 | struct bss_element *bss; | |
1872 | struct bss_element *tmp_bss; | |
1873 | ||
1874 | /* Blow away current list of scan results */ | |
1875 | list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) { | |
1876 | if (!scan_age || | |
1877 | time_after(jiffies, bss->last_scanned + scan_age)) { | |
1878 | list_move_tail(&bss->list, | |
1879 | &priv->bss_free_list); | |
1880 | /* Don't blow away ->list, just BSS data */ | |
1881 | memset(&bss->bss, 0, sizeof(bss->bss)); | |
1882 | bss->last_scanned = 0; | |
1883 | } | |
1884 | } | |
1885 | } | |
1886 | } | |
1887 | ||
1888 | static void orinoco_add_ext_scan_result(struct orinoco_private *priv, | |
1889 | struct agere_ext_scan_info *atom) | |
1890 | { | |
1891 | struct xbss_element *bss = NULL; | |
1892 | int found = 0; | |
1893 | ||
1894 | /* Try to update an existing bss first */ | |
1895 | list_for_each_entry(bss, &priv->bss_list, list) { | |
1896 | if (compare_ether_addr(bss->bss.bssid, atom->bssid)) | |
1897 | continue; | |
1898 | /* ESSID lengths */ | |
1899 | if (bss->bss.data[1] != atom->data[1]) | |
1900 | continue; | |
1901 | if (memcmp(&bss->bss.data[2], &atom->data[2], | |
1902 | atom->data[1])) | |
1903 | continue; | |
1904 | found = 1; | |
1905 | break; | |
1906 | } | |
1907 | ||
1908 | /* Grab a bss off the free list */ | |
1909 | if (!found && !list_empty(&priv->bss_free_list)) { | |
1910 | bss = list_entry(priv->bss_free_list.next, | |
1911 | struct xbss_element, list); | |
1912 | list_del(priv->bss_free_list.next); | |
1913 | ||
1914 | list_add_tail(&bss->list, &priv->bss_list); | |
1915 | } | |
1916 | ||
1917 | if (bss) { | |
1918 | /* Always update the BSS to get latest beacon info */ | |
1919 | memcpy(&bss->bss, atom, sizeof(bss->bss)); | |
1920 | bss->last_scanned = jiffies; | |
1e3428e9 DW |
1921 | } |
1922 | } | |
1923 | ||
1924 | static int orinoco_process_scan_results(struct net_device *dev, | |
1925 | unsigned char *buf, | |
1926 | int len) | |
1927 | { | |
1928 | struct orinoco_private *priv = netdev_priv(dev); | |
1929 | int offset; /* In the scan data */ | |
1930 | union hermes_scan_info *atom; | |
1931 | int atom_len; | |
1932 | ||
1933 | switch (priv->firmware_type) { | |
1934 | case FIRMWARE_TYPE_AGERE: | |
1935 | atom_len = sizeof(struct agere_scan_apinfo); | |
1936 | offset = 0; | |
1937 | break; | |
1938 | case FIRMWARE_TYPE_SYMBOL: | |
1939 | /* Lack of documentation necessitates this hack. | |
1940 | * Different firmwares have 68 or 76 byte long atoms. | |
1941 | * We try modulo first. If the length divides by both, | |
1942 | * we check what would be the channel in the second | |
1943 | * frame for a 68-byte atom. 76-byte atoms have 0 there. | |
1944 | * Valid channel cannot be 0. */ | |
1945 | if (len % 76) | |
1946 | atom_len = 68; | |
1947 | else if (len % 68) | |
1948 | atom_len = 76; | |
1949 | else if (len >= 1292 && buf[68] == 0) | |
1950 | atom_len = 76; | |
1951 | else | |
1952 | atom_len = 68; | |
1953 | offset = 0; | |
1954 | break; | |
1955 | case FIRMWARE_TYPE_INTERSIL: | |
1956 | offset = 4; | |
1957 | if (priv->has_hostscan) { | |
1958 | atom_len = le16_to_cpup((__le16 *)buf); | |
1959 | /* Sanity check for atom_len */ | |
1960 | if (atom_len < sizeof(struct prism2_scan_apinfo)) { | |
1961 | printk(KERN_ERR "%s: Invalid atom_len in scan " | |
1962 | "data: %d\n", dev->name, atom_len); | |
1963 | return -EIO; | |
1964 | } | |
1965 | } else | |
1966 | atom_len = offsetof(struct prism2_scan_apinfo, atim); | |
1967 | break; | |
1968 | default: | |
1969 | return -EOPNOTSUPP; | |
1970 | } | |
1971 | ||
1972 | /* Check that we got an whole number of atoms */ | |
1973 | if ((len - offset) % atom_len) { | |
1974 | printk(KERN_ERR "%s: Unexpected scan data length %d, " | |
1975 | "atom_len %d, offset %d\n", dev->name, len, | |
1976 | atom_len, offset); | |
1977 | return -EIO; | |
1978 | } | |
1979 | ||
1980 | orinoco_clear_scan_results(priv, msecs_to_jiffies(15000)); | |
1981 | ||
1982 | /* Read the entries one by one */ | |
1983 | for (; offset + atom_len <= len; offset += atom_len) { | |
1984 | int found = 0; | |
3056c404 | 1985 | struct bss_element *bss = NULL; |
1e3428e9 DW |
1986 | |
1987 | /* Get next atom */ | |
1988 | atom = (union hermes_scan_info *) (buf + offset); | |
1989 | ||
1990 | /* Try to update an existing bss first */ | |
1991 | list_for_each_entry(bss, &priv->bss_list, list) { | |
1992 | if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid)) | |
1993 | continue; | |
1994 | if (le16_to_cpu(bss->bss.a.essid_len) != | |
1995 | le16_to_cpu(atom->a.essid_len)) | |
1996 | continue; | |
1997 | if (memcmp(bss->bss.a.essid, atom->a.essid, | |
1998 | le16_to_cpu(atom->a.essid_len))) | |
1999 | continue; | |
1e3428e9 DW |
2000 | found = 1; |
2001 | break; | |
2002 | } | |
2003 | ||
2004 | /* Grab a bss off the free list */ | |
2005 | if (!found && !list_empty(&priv->bss_free_list)) { | |
2006 | bss = list_entry(priv->bss_free_list.next, | |
3056c404 | 2007 | struct bss_element, list); |
1e3428e9 DW |
2008 | list_del(priv->bss_free_list.next); |
2009 | ||
1e3428e9 DW |
2010 | list_add_tail(&bss->list, &priv->bss_list); |
2011 | } | |
2236761b DW |
2012 | |
2013 | if (bss) { | |
2014 | /* Always update the BSS to get latest beacon info */ | |
2015 | memcpy(&bss->bss, atom, sizeof(bss->bss)); | |
2016 | bss->last_scanned = jiffies; | |
2017 | } | |
1e3428e9 DW |
2018 | } |
2019 | ||
2020 | return 0; | |
2021 | } | |
2022 | ||
1da177e4 LT |
2023 | static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw) |
2024 | { | |
2025 | struct orinoco_private *priv = netdev_priv(dev); | |
2026 | u16 infofid; | |
2027 | struct { | |
d133ae4c PR |
2028 | __le16 len; |
2029 | __le16 type; | |
1da177e4 LT |
2030 | } __attribute__ ((packed)) info; |
2031 | int len, type; | |
2032 | int err; | |
2033 | ||
2034 | /* This is an answer to an INQUIRE command that we did earlier, | |
2035 | * or an information "event" generated by the card | |
2036 | * The controller return to us a pseudo frame containing | |
2037 | * the information in question - Jean II */ | |
2038 | infofid = hermes_read_regn(hw, INFOFID); | |
2039 | ||
2040 | /* Read the info frame header - don't try too hard */ | |
2041 | err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info), | |
2042 | infofid, 0); | |
2043 | if (err) { | |
2044 | printk(KERN_ERR "%s: error %d reading info frame. " | |
2045 | "Frame dropped.\n", dev->name, err); | |
2046 | return; | |
2047 | } | |
2048 | ||
2049 | len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len)); | |
2050 | type = le16_to_cpu(info.type); | |
2051 | ||
2052 | switch (type) { | |
2053 | case HERMES_INQ_TALLIES: { | |
2054 | struct hermes_tallies_frame tallies; | |
2055 | struct iw_statistics *wstats = &priv->wstats; | |
2056 | ||
2057 | if (len > sizeof(tallies)) { | |
2058 | printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n", | |
2059 | dev->name, len); | |
2060 | len = sizeof(tallies); | |
2061 | } | |
2062 | ||
84d8a2fb CH |
2063 | err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len, |
2064 | infofid, sizeof(info)); | |
2065 | if (err) | |
2066 | break; | |
1da177e4 LT |
2067 | |
2068 | /* Increment our various counters */ | |
2069 | /* wstats->discard.nwid - no wrong BSSID stuff */ | |
2070 | wstats->discard.code += | |
2071 | le16_to_cpu(tallies.RxWEPUndecryptable); | |
2072 | if (len == sizeof(tallies)) | |
2073 | wstats->discard.code += | |
2074 | le16_to_cpu(tallies.RxDiscards_WEPICVError) + | |
2075 | le16_to_cpu(tallies.RxDiscards_WEPExcluded); | |
2076 | wstats->discard.misc += | |
2077 | le16_to_cpu(tallies.TxDiscardsWrongSA); | |
2078 | wstats->discard.fragment += | |
2079 | le16_to_cpu(tallies.RxMsgInBadMsgFragments); | |
2080 | wstats->discard.retries += | |
2081 | le16_to_cpu(tallies.TxRetryLimitExceeded); | |
2082 | /* wstats->miss.beacon - no match */ | |
2083 | } | |
2084 | break; | |
2085 | case HERMES_INQ_LINKSTATUS: { | |
2086 | struct hermes_linkstatus linkstatus; | |
2087 | u16 newstatus; | |
2088 | int connected; | |
2089 | ||
8f2abf44 CH |
2090 | if (priv->iw_mode == IW_MODE_MONITOR) |
2091 | break; | |
2092 | ||
1da177e4 LT |
2093 | if (len != sizeof(linkstatus)) { |
2094 | printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n", | |
2095 | dev->name, len); | |
2096 | break; | |
2097 | } | |
2098 | ||
84d8a2fb CH |
2099 | err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len, |
2100 | infofid, sizeof(info)); | |
2101 | if (err) | |
2102 | break; | |
1da177e4 LT |
2103 | newstatus = le16_to_cpu(linkstatus.linkstatus); |
2104 | ||
95dd91fb CH |
2105 | /* Symbol firmware uses "out of range" to signal that |
2106 | * the hostscan frame can be requested. */ | |
2107 | if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE && | |
2108 | priv->firmware_type == FIRMWARE_TYPE_SYMBOL && | |
2109 | priv->has_hostscan && priv->scan_inprogress) { | |
2110 | hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL); | |
2111 | break; | |
2112 | } | |
2113 | ||
1da177e4 LT |
2114 | connected = (newstatus == HERMES_LINKSTATUS_CONNECTED) |
2115 | || (newstatus == HERMES_LINKSTATUS_AP_CHANGE) | |
2116 | || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE); | |
2117 | ||
2118 | if (connected) | |
2119 | netif_carrier_on(dev); | |
7bb7c3a3 | 2120 | else if (!ignore_disconnect) |
1da177e4 LT |
2121 | netif_carrier_off(dev); |
2122 | ||
95dd91fb CH |
2123 | if (newstatus != priv->last_linkstatus) { |
2124 | priv->last_linkstatus = newstatus; | |
1da177e4 | 2125 | print_linkstatus(dev, newstatus); |
95dd91fb CH |
2126 | /* The info frame contains only one word which is the |
2127 | * status (see hermes.h). The status is pretty boring | |
2128 | * in itself, that's why we export the new BSSID... | |
2129 | * Jean II */ | |
2130 | schedule_work(&priv->wevent_work); | |
2131 | } | |
2132 | } | |
2133 | break; | |
2134 | case HERMES_INQ_SCAN: | |
2135 | if (!priv->scan_inprogress && priv->bssid_fixed && | |
2136 | priv->firmware_type == FIRMWARE_TYPE_INTERSIL) { | |
2137 | schedule_work(&priv->join_work); | |
2138 | break; | |
2139 | } | |
2140 | /* fall through */ | |
2141 | case HERMES_INQ_HOSTSCAN: | |
2142 | case HERMES_INQ_HOSTSCAN_SYMBOL: { | |
2143 | /* Result of a scanning. Contains information about | |
2144 | * cells in the vicinity - Jean II */ | |
2145 | union iwreq_data wrqu; | |
2146 | unsigned char *buf; | |
2147 | ||
1e3428e9 DW |
2148 | /* Scan is no longer in progress */ |
2149 | priv->scan_inprogress = 0; | |
2150 | ||
95dd91fb CH |
2151 | /* Sanity check */ |
2152 | if (len > 4096) { | |
2153 | printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n", | |
2154 | dev->name, len); | |
2155 | break; | |
2156 | } | |
2157 | ||
95dd91fb CH |
2158 | /* Allocate buffer for results */ |
2159 | buf = kmalloc(len, GFP_ATOMIC); | |
2160 | if (buf == NULL) | |
2161 | /* No memory, so can't printk()... */ | |
2162 | break; | |
2163 | ||
2164 | /* Read scan data */ | |
2165 | err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len, | |
2166 | infofid, sizeof(info)); | |
708218b0 PR |
2167 | if (err) { |
2168 | kfree(buf); | |
95dd91fb | 2169 | break; |
708218b0 | 2170 | } |
1da177e4 | 2171 | |
95dd91fb CH |
2172 | #ifdef ORINOCO_DEBUG |
2173 | { | |
2174 | int i; | |
2175 | printk(KERN_DEBUG "Scan result [%02X", buf[0]); | |
2176 | for(i = 1; i < (len * 2); i++) | |
2177 | printk(":%02X", buf[i]); | |
2178 | printk("]\n"); | |
2179 | } | |
2180 | #endif /* ORINOCO_DEBUG */ | |
2181 | ||
1e3428e9 DW |
2182 | if (orinoco_process_scan_results(dev, buf, len) == 0) { |
2183 | /* Send an empty event to user space. | |
2184 | * We don't send the received data on the event because | |
2185 | * it would require us to do complex transcoding, and | |
2186 | * we want to minimise the work done in the irq handler | |
2187 | * Use a request to extract the data - Jean II */ | |
2188 | wrqu.data.length = 0; | |
2189 | wrqu.data.flags = 0; | |
2190 | wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); | |
2191 | } | |
2192 | kfree(buf); | |
1da177e4 LT |
2193 | } |
2194 | break; | |
01632fa4 DK |
2195 | case HERMES_INQ_CHANNELINFO: |
2196 | { | |
2197 | struct agere_ext_scan_info *bss; | |
2198 | ||
2199 | if (!priv->scan_inprogress) { | |
2200 | printk(KERN_DEBUG "%s: Got chaninfo without scan, " | |
2201 | "len=%d\n", dev->name, len); | |
2202 | break; | |
2203 | } | |
2204 | ||
2205 | /* An empty result indicates that the scan is complete */ | |
2206 | if (len == 0) { | |
2207 | union iwreq_data wrqu; | |
2208 | ||
2209 | /* Scan is no longer in progress */ | |
2210 | priv->scan_inprogress = 0; | |
2211 | ||
2212 | wrqu.data.length = 0; | |
2213 | wrqu.data.flags = 0; | |
2214 | wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); | |
2215 | break; | |
2216 | } | |
2217 | ||
2218 | /* Sanity check */ | |
2219 | else if (len > sizeof(*bss)) { | |
2220 | printk(KERN_WARNING | |
2221 | "%s: Ext scan results too large (%d bytes). " | |
2222 | "Truncating results to %zd bytes.\n", | |
2223 | dev->name, len, sizeof(*bss)); | |
2224 | len = sizeof(*bss); | |
2225 | } else if (len < (offsetof(struct agere_ext_scan_info, | |
2226 | data) + 2)) { | |
2227 | /* Drop this result now so we don't have to | |
2228 | * keep checking later */ | |
2229 | printk(KERN_WARNING | |
2230 | "%s: Ext scan results too short (%d bytes)\n", | |
2231 | dev->name, len); | |
2232 | break; | |
2233 | } | |
2234 | ||
2235 | bss = kmalloc(sizeof(*bss), GFP_ATOMIC); | |
2236 | if (bss == NULL) | |
2237 | break; | |
2238 | ||
2239 | /* Read scan data */ | |
2240 | err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len, | |
2241 | infofid, sizeof(info)); | |
2242 | if (err) { | |
2243 | kfree(bss); | |
2244 | break; | |
2245 | } | |
2246 | ||
2247 | orinoco_add_ext_scan_result(priv, bss); | |
2248 | ||
2249 | kfree(bss); | |
2250 | break; | |
2251 | } | |
95dd91fb CH |
2252 | case HERMES_INQ_SEC_STAT_AGERE: |
2253 | /* Security status (Agere specific) */ | |
2254 | /* Ignore this frame for now */ | |
2255 | if (priv->firmware_type == FIRMWARE_TYPE_AGERE) | |
2256 | break; | |
2257 | /* fall through */ | |
1da177e4 LT |
2258 | default: |
2259 | printk(KERN_DEBUG "%s: Unknown information frame received: " | |
2260 | "type 0x%04x, length %d\n", dev->name, type, len); | |
2261 | /* We don't actually do anything about it */ | |
2262 | break; | |
2263 | } | |
2264 | } | |
2265 | ||
2266 | static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw) | |
2267 | { | |
2268 | if (net_ratelimit()) | |
2269 | printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name); | |
2270 | } | |
2271 | ||
2272 | /********************************************************************/ | |
2273 | /* Internal hardware control routines */ | |
2274 | /********************************************************************/ | |
2275 | ||
2276 | int __orinoco_up(struct net_device *dev) | |
2277 | { | |
2278 | struct orinoco_private *priv = netdev_priv(dev); | |
2279 | struct hermes *hw = &priv->hw; | |
2280 | int err; | |
2281 | ||
84d8a2fb CH |
2282 | netif_carrier_off(dev); /* just to make sure */ |
2283 | ||
1da177e4 LT |
2284 | err = __orinoco_program_rids(dev); |
2285 | if (err) { | |
2286 | printk(KERN_ERR "%s: Error %d configuring card\n", | |
2287 | dev->name, err); | |
2288 | return err; | |
2289 | } | |
2290 | ||
2291 | /* Fire things up again */ | |
2292 | hermes_set_irqmask(hw, ORINOCO_INTEN); | |
2293 | err = hermes_enable_port(hw, 0); | |
2294 | if (err) { | |
2295 | printk(KERN_ERR "%s: Error %d enabling MAC port\n", | |
2296 | dev->name, err); | |
2297 | return err; | |
2298 | } | |
2299 | ||
2300 | netif_start_queue(dev); | |
2301 | ||
2302 | return 0; | |
2303 | } | |
2304 | ||
2305 | int __orinoco_down(struct net_device *dev) | |
2306 | { | |
2307 | struct orinoco_private *priv = netdev_priv(dev); | |
2308 | struct hermes *hw = &priv->hw; | |
2309 | int err; | |
2310 | ||
2311 | netif_stop_queue(dev); | |
2312 | ||
2313 | if (! priv->hw_unavailable) { | |
2314 | if (! priv->broken_disableport) { | |
2315 | err = hermes_disable_port(hw, 0); | |
2316 | if (err) { | |
2317 | /* Some firmwares (e.g. Intersil 1.3.x) seem | |
2318 | * to have problems disabling the port, oh | |
2319 | * well, too bad. */ | |
2320 | printk(KERN_WARNING "%s: Error %d disabling MAC port\n", | |
2321 | dev->name, err); | |
2322 | priv->broken_disableport = 1; | |
2323 | } | |
2324 | } | |
2325 | hermes_set_irqmask(hw, 0); | |
2326 | hermes_write_regn(hw, EVACK, 0xffff); | |
2327 | } | |
2328 | ||
2329 | /* firmware will have to reassociate */ | |
2330 | netif_carrier_off(dev); | |
2331 | priv->last_linkstatus = 0xffff; | |
2332 | ||
2333 | return 0; | |
2334 | } | |
2335 | ||
37a6c611 | 2336 | static int orinoco_allocate_fid(struct net_device *dev) |
1da177e4 LT |
2337 | { |
2338 | struct orinoco_private *priv = netdev_priv(dev); | |
2339 | struct hermes *hw = &priv->hw; | |
2340 | int err; | |
2341 | ||
1da177e4 | 2342 | err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid); |
b24d4582 | 2343 | if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) { |
1da177e4 LT |
2344 | /* Try workaround for old Symbol firmware bug */ |
2345 | printk(KERN_WARNING "%s: firmware ALLOC bug detected " | |
2346 | "(old Symbol firmware?). Trying to work around... ", | |
2347 | dev->name); | |
2348 | ||
2349 | priv->nicbuf_size = TX_NICBUF_SIZE_BUG; | |
2350 | err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid); | |
2351 | if (err) | |
2352 | printk("failed!\n"); | |
2353 | else | |
2354 | printk("ok.\n"); | |
2355 | } | |
2356 | ||
2357 | return err; | |
2358 | } | |
2359 | ||
37a6c611 PR |
2360 | int orinoco_reinit_firmware(struct net_device *dev) |
2361 | { | |
2362 | struct orinoco_private *priv = netdev_priv(dev); | |
2363 | struct hermes *hw = &priv->hw; | |
2364 | int err; | |
2365 | ||
2366 | err = hermes_init(hw); | |
0df6cbb7 AB |
2367 | if (priv->do_fw_download && !err) { |
2368 | err = orinoco_download(priv); | |
2369 | if (err) | |
2370 | priv->do_fw_download = 0; | |
2371 | } | |
37a6c611 PR |
2372 | if (!err) |
2373 | err = orinoco_allocate_fid(dev); | |
2374 | ||
2375 | return err; | |
2376 | } | |
2377 | ||
1da177e4 LT |
2378 | static int __orinoco_hw_set_bitrate(struct orinoco_private *priv) |
2379 | { | |
2380 | hermes_t *hw = &priv->hw; | |
2381 | int err = 0; | |
2382 | ||
2383 | if (priv->bitratemode >= BITRATE_TABLE_SIZE) { | |
2384 | printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n", | |
2385 | priv->ndev->name, priv->bitratemode); | |
2386 | return -EINVAL; | |
2387 | } | |
2388 | ||
2389 | switch (priv->firmware_type) { | |
2390 | case FIRMWARE_TYPE_AGERE: | |
2391 | err = hermes_write_wordrec(hw, USER_BAP, | |
2392 | HERMES_RID_CNFTXRATECONTROL, | |
2393 | bitrate_table[priv->bitratemode].agere_txratectrl); | |
2394 | break; | |
2395 | case FIRMWARE_TYPE_INTERSIL: | |
2396 | case FIRMWARE_TYPE_SYMBOL: | |
2397 | err = hermes_write_wordrec(hw, USER_BAP, | |
2398 | HERMES_RID_CNFTXRATECONTROL, | |
2399 | bitrate_table[priv->bitratemode].intersil_txratectrl); | |
2400 | break; | |
2401 | default: | |
2402 | BUG(); | |
2403 | } | |
2404 | ||
2405 | return err; | |
2406 | } | |
2407 | ||
16739b06 CH |
2408 | /* Set fixed AP address */ |
2409 | static int __orinoco_hw_set_wap(struct orinoco_private *priv) | |
2410 | { | |
2411 | int roaming_flag; | |
2412 | int err = 0; | |
2413 | hermes_t *hw = &priv->hw; | |
2414 | ||
2415 | switch (priv->firmware_type) { | |
2416 | case FIRMWARE_TYPE_AGERE: | |
2417 | /* not supported */ | |
2418 | break; | |
2419 | case FIRMWARE_TYPE_INTERSIL: | |
2420 | if (priv->bssid_fixed) | |
2421 | roaming_flag = 2; | |
2422 | else | |
2423 | roaming_flag = 1; | |
2424 | ||
2425 | err = hermes_write_wordrec(hw, USER_BAP, | |
2426 | HERMES_RID_CNFROAMINGMODE, | |
2427 | roaming_flag); | |
2428 | break; | |
2429 | case FIRMWARE_TYPE_SYMBOL: | |
2430 | err = HERMES_WRITE_RECORD(hw, USER_BAP, | |
2431 | HERMES_RID_CNFMANDATORYBSSID_SYMBOL, | |
2432 | &priv->desired_bssid); | |
2433 | break; | |
2434 | } | |
2435 | return err; | |
2436 | } | |
2437 | ||
1da177e4 | 2438 | /* Change the WEP keys and/or the current keys. Can be called |
d03032af | 2439 | * either from __orinoco_hw_setup_enc() or directly from |
1da177e4 LT |
2440 | * orinoco_ioctl_setiwencode(). In the later case the association |
2441 | * with the AP is not broken (if the firmware can handle it), | |
2442 | * which is needed for 802.1x implementations. */ | |
2443 | static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv) | |
2444 | { | |
2445 | hermes_t *hw = &priv->hw; | |
2446 | int err = 0; | |
2447 | ||
2448 | switch (priv->firmware_type) { | |
2449 | case FIRMWARE_TYPE_AGERE: | |
2450 | err = HERMES_WRITE_RECORD(hw, USER_BAP, | |
2451 | HERMES_RID_CNFWEPKEYS_AGERE, | |
2452 | &priv->keys); | |
2453 | if (err) | |
2454 | return err; | |
2455 | err = hermes_write_wordrec(hw, USER_BAP, | |
2456 | HERMES_RID_CNFTXKEY_AGERE, | |
2457 | priv->tx_key); | |
2458 | if (err) | |
2459 | return err; | |
2460 | break; | |
2461 | case FIRMWARE_TYPE_INTERSIL: | |
2462 | case FIRMWARE_TYPE_SYMBOL: | |
2463 | { | |
2464 | int keylen; | |
2465 | int i; | |
2466 | ||
2467 | /* Force uniform key length to work around firmware bugs */ | |
2468 | keylen = le16_to_cpu(priv->keys[priv->tx_key].len); | |
2469 | ||
2470 | if (keylen > LARGE_KEY_SIZE) { | |
2471 | printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n", | |
2472 | priv->ndev->name, priv->tx_key, keylen); | |
2473 | return -E2BIG; | |
2474 | } | |
2475 | ||
2476 | /* Write all 4 keys */ | |
2477 | for(i = 0; i < ORINOCO_MAX_KEYS; i++) { | |
2478 | err = hermes_write_ltv(hw, USER_BAP, | |
2479 | HERMES_RID_CNFDEFAULTKEY0 + i, | |
2480 | HERMES_BYTES_TO_RECLEN(keylen), | |
2481 | priv->keys[i].data); | |
2482 | if (err) | |
2483 | return err; | |
2484 | } | |
2485 | ||
2486 | /* Write the index of the key used in transmission */ | |
2487 | err = hermes_write_wordrec(hw, USER_BAP, | |
2488 | HERMES_RID_CNFWEPDEFAULTKEYID, | |
2489 | priv->tx_key); | |
2490 | if (err) | |
2491 | return err; | |
2492 | } | |
2493 | break; | |
2494 | } | |
2495 | ||
2496 | return 0; | |
2497 | } | |
2498 | ||
d03032af | 2499 | static int __orinoco_hw_setup_enc(struct orinoco_private *priv) |
1da177e4 LT |
2500 | { |
2501 | hermes_t *hw = &priv->hw; | |
2502 | int err = 0; | |
2503 | int master_wep_flag; | |
2504 | int auth_flag; | |
4ae6ee2d | 2505 | int enc_flag; |
1da177e4 | 2506 | |
d03032af DK |
2507 | /* Setup WEP keys for WEP and WPA */ |
2508 | if (priv->encode_alg) | |
1da177e4 LT |
2509 | __orinoco_hw_setup_wepkeys(priv); |
2510 | ||
2511 | if (priv->wep_restrict) | |
2512 | auth_flag = HERMES_AUTH_SHARED_KEY; | |
2513 | else | |
2514 | auth_flag = HERMES_AUTH_OPEN; | |
2515 | ||
d03032af DK |
2516 | if (priv->wpa_enabled) |
2517 | enc_flag = 2; | |
2518 | else if (priv->encode_alg == IW_ENCODE_ALG_WEP) | |
4ae6ee2d DK |
2519 | enc_flag = 1; |
2520 | else | |
2521 | enc_flag = 0; | |
2522 | ||
1da177e4 LT |
2523 | switch (priv->firmware_type) { |
2524 | case FIRMWARE_TYPE_AGERE: /* Agere style WEP */ | |
4ae6ee2d | 2525 | if (priv->encode_alg == IW_ENCODE_ALG_WEP) { |
1da177e4 LT |
2526 | /* Enable the shared-key authentication. */ |
2527 | err = hermes_write_wordrec(hw, USER_BAP, | |
2528 | HERMES_RID_CNFAUTHENTICATION_AGERE, | |
2529 | auth_flag); | |
2530 | } | |
2531 | err = hermes_write_wordrec(hw, USER_BAP, | |
2532 | HERMES_RID_CNFWEPENABLED_AGERE, | |
4ae6ee2d | 2533 | enc_flag); |
1da177e4 LT |
2534 | if (err) |
2535 | return err; | |
d03032af DK |
2536 | |
2537 | if (priv->has_wpa) { | |
2538 | /* Set WPA key management */ | |
2539 | err = hermes_write_wordrec(hw, USER_BAP, | |
2540 | HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE, | |
2541 | priv->key_mgmt); | |
2542 | if (err) | |
2543 | return err; | |
2544 | } | |
2545 | ||
1da177e4 LT |
2546 | break; |
2547 | ||
2548 | case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */ | |
2549 | case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */ | |
4ae6ee2d | 2550 | if (priv->encode_alg == IW_ENCODE_ALG_WEP) { |
1da177e4 LT |
2551 | if (priv->wep_restrict || |
2552 | (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)) | |
2553 | master_wep_flag = HERMES_WEP_PRIVACY_INVOKED | | |
2554 | HERMES_WEP_EXCL_UNENCRYPTED; | |
2555 | else | |
2556 | master_wep_flag = HERMES_WEP_PRIVACY_INVOKED; | |
2557 | ||
2558 | err = hermes_write_wordrec(hw, USER_BAP, | |
2559 | HERMES_RID_CNFAUTHENTICATION, | |
2560 | auth_flag); | |
2561 | if (err) | |
2562 | return err; | |
2563 | } else | |
2564 | master_wep_flag = 0; | |
2565 | ||
2566 | if (priv->iw_mode == IW_MODE_MONITOR) | |
2567 | master_wep_flag |= HERMES_WEP_HOST_DECRYPT; | |
2568 | ||
2569 | /* Master WEP setting : on/off */ | |
2570 | err = hermes_write_wordrec(hw, USER_BAP, | |
2571 | HERMES_RID_CNFWEPFLAGS_INTERSIL, | |
2572 | master_wep_flag); | |
2573 | if (err) | |
2574 | return err; | |
2575 | ||
2576 | break; | |
2577 | } | |
2578 | ||
2579 | return 0; | |
2580 | } | |
2581 | ||
d03032af DK |
2582 | /* key must be 32 bytes, including the tx and rx MIC keys. |
2583 | * rsc must be 8 bytes | |
2584 | * tsc must be 8 bytes or NULL | |
2585 | */ | |
2586 | static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx, | |
2587 | u8 *key, u8 *rsc, u8 *tsc) | |
2588 | { | |
2589 | struct { | |
2590 | __le16 idx; | |
2591 | u8 rsc[IW_ENCODE_SEQ_MAX_SIZE]; | |
2592 | u8 key[TKIP_KEYLEN]; | |
2593 | u8 tx_mic[MIC_KEYLEN]; | |
2594 | u8 rx_mic[MIC_KEYLEN]; | |
2595 | u8 tsc[IW_ENCODE_SEQ_MAX_SIZE]; | |
2596 | } __attribute__ ((packed)) buf; | |
2597 | int ret; | |
2598 | int err; | |
2599 | int k; | |
2600 | u16 xmitting; | |
2601 | ||
2602 | key_idx &= 0x3; | |
2603 | ||
2604 | if (set_tx) | |
2605 | key_idx |= 0x8000; | |
2606 | ||
2607 | buf.idx = cpu_to_le16(key_idx); | |
2608 | memcpy(buf.key, key, | |
2609 | sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic)); | |
2610 | ||
2611 | if (rsc == NULL) | |
2612 | memset(buf.rsc, 0, sizeof(buf.rsc)); | |
2613 | else | |
2614 | memcpy(buf.rsc, rsc, sizeof(buf.rsc)); | |
2615 | ||
2616 | if (tsc == NULL) { | |
2617 | memset(buf.tsc, 0, sizeof(buf.tsc)); | |
2618 | buf.tsc[4] = 0x10; | |
2619 | } else { | |
2620 | memcpy(buf.tsc, tsc, sizeof(buf.tsc)); | |
2621 | } | |
2622 | ||
2623 | /* Wait upto 100ms for tx queue to empty */ | |
2624 | k = 100; | |
2625 | do { | |
2626 | k--; | |
2627 | udelay(1000); | |
2628 | ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY, | |
2629 | &xmitting); | |
2630 | if (ret) | |
2631 | break; | |
2632 | } while ((k > 0) && xmitting); | |
2633 | ||
2634 | if (k == 0) | |
2635 | ret = -ETIMEDOUT; | |
2636 | ||
2637 | err = HERMES_WRITE_RECORD(hw, USER_BAP, | |
2638 | HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE, | |
2639 | &buf); | |
2640 | ||
2641 | return ret ? ret : err; | |
2642 | } | |
2643 | ||
2644 | static int orinoco_clear_tkip_key(struct orinoco_private *priv, | |
2645 | int key_idx) | |
2646 | { | |
2647 | hermes_t *hw = &priv->hw; | |
2648 | int err; | |
2649 | ||
2650 | memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx])); | |
2651 | err = hermes_write_wordrec(hw, USER_BAP, | |
2652 | HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE, | |
2653 | key_idx); | |
2654 | if (err) | |
2655 | printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n", | |
2656 | priv->ndev->name, err, key_idx); | |
2657 | return err; | |
2658 | } | |
2659 | ||
1da177e4 LT |
2660 | static int __orinoco_program_rids(struct net_device *dev) |
2661 | { | |
2662 | struct orinoco_private *priv = netdev_priv(dev); | |
2663 | hermes_t *hw = &priv->hw; | |
2664 | int err; | |
2665 | struct hermes_idstring idbuf; | |
2666 | ||
2667 | /* Set the MAC address */ | |
2668 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR, | |
2669 | HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr); | |
2670 | if (err) { | |
2671 | printk(KERN_ERR "%s: Error %d setting MAC address\n", | |
2672 | dev->name, err); | |
2673 | return err; | |
2674 | } | |
2675 | ||
2676 | /* Set up the link mode */ | |
2677 | err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE, | |
2678 | priv->port_type); | |
2679 | if (err) { | |
2680 | printk(KERN_ERR "%s: Error %d setting port type\n", | |
2681 | dev->name, err); | |
2682 | return err; | |
2683 | } | |
2684 | /* Set the channel/frequency */ | |
d51d8b1f DG |
2685 | if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) { |
2686 | err = hermes_write_wordrec(hw, USER_BAP, | |
2687 | HERMES_RID_CNFOWNCHANNEL, | |
2688 | priv->channel); | |
2689 | if (err) { | |
2690 | printk(KERN_ERR "%s: Error %d setting channel %d\n", | |
2691 | dev->name, err, priv->channel); | |
2692 | return err; | |
2693 | } | |
1da177e4 LT |
2694 | } |
2695 | ||
2696 | if (priv->has_ibss) { | |
2697 | u16 createibss; | |
2698 | ||
2699 | if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) { | |
2700 | printk(KERN_WARNING "%s: This firmware requires an " | |
2701 | "ESSID in IBSS-Ad-Hoc mode.\n", dev->name); | |
2702 | /* With wvlan_cs, in this case, we would crash. | |
2703 | * hopefully, this driver will behave better... | |
2704 | * Jean II */ | |
2705 | createibss = 0; | |
2706 | } else { | |
2707 | createibss = priv->createibss; | |
2708 | } | |
2709 | ||
2710 | err = hermes_write_wordrec(hw, USER_BAP, | |
2711 | HERMES_RID_CNFCREATEIBSS, | |
2712 | createibss); | |
2713 | if (err) { | |
2714 | printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n", | |
2715 | dev->name, err); | |
2716 | return err; | |
2717 | } | |
2718 | } | |
2719 | ||
16739b06 CH |
2720 | /* Set the desired BSSID */ |
2721 | err = __orinoco_hw_set_wap(priv); | |
2722 | if (err) { | |
2723 | printk(KERN_ERR "%s: Error %d setting AP address\n", | |
2724 | dev->name, err); | |
2725 | return err; | |
2726 | } | |
1da177e4 LT |
2727 | /* Set the desired ESSID */ |
2728 | idbuf.len = cpu_to_le16(strlen(priv->desired_essid)); | |
2729 | memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val)); | |
2730 | /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */ | |
2731 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID, | |
2732 | HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2), | |
2733 | &idbuf); | |
2734 | if (err) { | |
2735 | printk(KERN_ERR "%s: Error %d setting OWNSSID\n", | |
2736 | dev->name, err); | |
2737 | return err; | |
2738 | } | |
2739 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID, | |
2740 | HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2), | |
2741 | &idbuf); | |
2742 | if (err) { | |
2743 | printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n", | |
2744 | dev->name, err); | |
2745 | return err; | |
2746 | } | |
2747 | ||
2748 | /* Set the station name */ | |
2749 | idbuf.len = cpu_to_le16(strlen(priv->nick)); | |
2750 | memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val)); | |
2751 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME, | |
2752 | HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2), | |
2753 | &idbuf); | |
2754 | if (err) { | |
2755 | printk(KERN_ERR "%s: Error %d setting nickname\n", | |
2756 | dev->name, err); | |
2757 | return err; | |
2758 | } | |
2759 | ||
2760 | /* Set AP density */ | |
2761 | if (priv->has_sensitivity) { | |
2762 | err = hermes_write_wordrec(hw, USER_BAP, | |
2763 | HERMES_RID_CNFSYSTEMSCALE, | |
2764 | priv->ap_density); | |
2765 | if (err) { | |
2766 | printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. " | |
2767 | "Disabling sensitivity control\n", | |
2768 | dev->name, err); | |
2769 | ||
2770 | priv->has_sensitivity = 0; | |
2771 | } | |
2772 | } | |
2773 | ||
2774 | /* Set RTS threshold */ | |
2775 | err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, | |
2776 | priv->rts_thresh); | |
2777 | if (err) { | |
2778 | printk(KERN_ERR "%s: Error %d setting RTS threshold\n", | |
2779 | dev->name, err); | |
2780 | return err; | |
2781 | } | |
2782 | ||
2783 | /* Set fragmentation threshold or MWO robustness */ | |
2784 | if (priv->has_mwo) | |
2785 | err = hermes_write_wordrec(hw, USER_BAP, | |
2786 | HERMES_RID_CNFMWOROBUST_AGERE, | |
2787 | priv->mwo_robust); | |
2788 | else | |
2789 | err = hermes_write_wordrec(hw, USER_BAP, | |
2790 | HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, | |
2791 | priv->frag_thresh); | |
2792 | if (err) { | |
2793 | printk(KERN_ERR "%s: Error %d setting fragmentation\n", | |
2794 | dev->name, err); | |
2795 | return err; | |
2796 | } | |
2797 | ||
2798 | /* Set bitrate */ | |
2799 | err = __orinoco_hw_set_bitrate(priv); | |
2800 | if (err) { | |
2801 | printk(KERN_ERR "%s: Error %d setting bitrate\n", | |
2802 | dev->name, err); | |
2803 | return err; | |
2804 | } | |
2805 | ||
2806 | /* Set power management */ | |
2807 | if (priv->has_pm) { | |
2808 | err = hermes_write_wordrec(hw, USER_BAP, | |
2809 | HERMES_RID_CNFPMENABLED, | |
2810 | priv->pm_on); | |
2811 | if (err) { | |
2812 | printk(KERN_ERR "%s: Error %d setting up PM\n", | |
2813 | dev->name, err); | |
2814 | return err; | |
2815 | } | |
2816 | ||
2817 | err = hermes_write_wordrec(hw, USER_BAP, | |
2818 | HERMES_RID_CNFMULTICASTRECEIVE, | |
2819 | priv->pm_mcast); | |
2820 | if (err) { | |
2821 | printk(KERN_ERR "%s: Error %d setting up PM\n", | |
2822 | dev->name, err); | |
2823 | return err; | |
2824 | } | |
2825 | err = hermes_write_wordrec(hw, USER_BAP, | |
2826 | HERMES_RID_CNFMAXSLEEPDURATION, | |
2827 | priv->pm_period); | |
2828 | if (err) { | |
2829 | printk(KERN_ERR "%s: Error %d setting up PM\n", | |
2830 | dev->name, err); | |
2831 | return err; | |
2832 | } | |
2833 | err = hermes_write_wordrec(hw, USER_BAP, | |
2834 | HERMES_RID_CNFPMHOLDOVERDURATION, | |
2835 | priv->pm_timeout); | |
2836 | if (err) { | |
2837 | printk(KERN_ERR "%s: Error %d setting up PM\n", | |
2838 | dev->name, err); | |
2839 | return err; | |
2840 | } | |
2841 | } | |
2842 | ||
2843 | /* Set preamble - only for Symbol so far... */ | |
2844 | if (priv->has_preamble) { | |
2845 | err = hermes_write_wordrec(hw, USER_BAP, | |
2846 | HERMES_RID_CNFPREAMBLE_SYMBOL, | |
2847 | priv->preamble); | |
2848 | if (err) { | |
2849 | printk(KERN_ERR "%s: Error %d setting preamble\n", | |
2850 | dev->name, err); | |
2851 | return err; | |
2852 | } | |
2853 | } | |
2854 | ||
2855 | /* Set up encryption */ | |
d03032af DK |
2856 | if (priv->has_wep || priv->has_wpa) { |
2857 | err = __orinoco_hw_setup_enc(priv); | |
1da177e4 | 2858 | if (err) { |
d03032af | 2859 | printk(KERN_ERR "%s: Error %d activating encryption\n", |
1da177e4 LT |
2860 | dev->name, err); |
2861 | return err; | |
2862 | } | |
2863 | } | |
2864 | ||
98c4cae1 CH |
2865 | if (priv->iw_mode == IW_MODE_MONITOR) { |
2866 | /* Enable monitor mode */ | |
2867 | dev->type = ARPHRD_IEEE80211; | |
2868 | err = hermes_docmd_wait(hw, HERMES_CMD_TEST | | |
2869 | HERMES_TEST_MONITOR, 0, NULL); | |
2870 | } else { | |
2871 | /* Disable monitor mode */ | |
2872 | dev->type = ARPHRD_ETHER; | |
2873 | err = hermes_docmd_wait(hw, HERMES_CMD_TEST | | |
2874 | HERMES_TEST_STOP, 0, NULL); | |
2875 | } | |
2876 | if (err) | |
2877 | return err; | |
2878 | ||
1da177e4 LT |
2879 | /* Set promiscuity / multicast*/ |
2880 | priv->promiscuous = 0; | |
2881 | priv->mc_count = 0; | |
932ff279 HX |
2882 | |
2883 | /* FIXME: what about netif_tx_lock */ | |
2884 | __orinoco_set_multicast_list(dev); | |
1da177e4 LT |
2885 | |
2886 | return 0; | |
2887 | } | |
2888 | ||
2889 | /* FIXME: return int? */ | |
2890 | static void | |
2891 | __orinoco_set_multicast_list(struct net_device *dev) | |
2892 | { | |
2893 | struct orinoco_private *priv = netdev_priv(dev); | |
2894 | hermes_t *hw = &priv->hw; | |
2895 | int err = 0; | |
2896 | int promisc, mc_count; | |
2897 | ||
2898 | /* The Hermes doesn't seem to have an allmulti mode, so we go | |
2899 | * into promiscuous mode and let the upper levels deal. */ | |
2900 | if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) || | |
2901 | (dev->mc_count > MAX_MULTICAST(priv)) ) { | |
2902 | promisc = 1; | |
2903 | mc_count = 0; | |
2904 | } else { | |
2905 | promisc = 0; | |
2906 | mc_count = dev->mc_count; | |
2907 | } | |
2908 | ||
2909 | if (promisc != priv->promiscuous) { | |
2910 | err = hermes_write_wordrec(hw, USER_BAP, | |
2911 | HERMES_RID_CNFPROMISCUOUSMODE, | |
2912 | promisc); | |
2913 | if (err) { | |
2914 | printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n", | |
2915 | dev->name, err); | |
2916 | } else | |
2917 | priv->promiscuous = promisc; | |
2918 | } | |
2919 | ||
667d4100 DK |
2920 | /* If we're not in promiscuous mode, then we need to set the |
2921 | * group address if either we want to multicast, or if we were | |
2922 | * multicasting and want to stop */ | |
1da177e4 LT |
2923 | if (! promisc && (mc_count || priv->mc_count) ) { |
2924 | struct dev_mc_list *p = dev->mc_list; | |
2925 | struct hermes_multicast mclist; | |
2926 | int i; | |
2927 | ||
2928 | for (i = 0; i < mc_count; i++) { | |
2929 | /* paranoia: is list shorter than mc_count? */ | |
2930 | BUG_ON(! p); | |
2931 | /* paranoia: bad address size in list? */ | |
2932 | BUG_ON(p->dmi_addrlen != ETH_ALEN); | |
2933 | ||
2934 | memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN); | |
2935 | p = p->next; | |
2936 | } | |
2937 | ||
2938 | if (p) | |
2939 | printk(KERN_WARNING "%s: Multicast list is " | |
2940 | "longer than mc_count\n", dev->name); | |
2941 | ||
667d4100 DK |
2942 | err = hermes_write_ltv(hw, USER_BAP, |
2943 | HERMES_RID_CNFGROUPADDRESSES, | |
2944 | HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN), | |
2945 | &mclist); | |
1da177e4 LT |
2946 | if (err) |
2947 | printk(KERN_ERR "%s: Error %d setting multicast list.\n", | |
2948 | dev->name, err); | |
2949 | else | |
2950 | priv->mc_count = mc_count; | |
2951 | } | |
1da177e4 LT |
2952 | } |
2953 | ||
1da177e4 LT |
2954 | /* This must be called from user context, without locks held - use |
2955 | * schedule_work() */ | |
c4028958 | 2956 | static void orinoco_reset(struct work_struct *work) |
1da177e4 | 2957 | { |
c4028958 DH |
2958 | struct orinoco_private *priv = |
2959 | container_of(work, struct orinoco_private, reset_work); | |
2960 | struct net_device *dev = priv->ndev; | |
1da177e4 | 2961 | struct hermes *hw = &priv->hw; |
8551cb98 | 2962 | int err; |
1da177e4 LT |
2963 | unsigned long flags; |
2964 | ||
2965 | if (orinoco_lock(priv, &flags) != 0) | |
2966 | /* When the hardware becomes available again, whatever | |
2967 | * detects that is responsible for re-initializing | |
2968 | * it. So no need for anything further */ | |
2969 | return; | |
2970 | ||
2971 | netif_stop_queue(dev); | |
2972 | ||
2973 | /* Shut off interrupts. Depending on what state the hardware | |
2974 | * is in, this might not work, but we'll try anyway */ | |
2975 | hermes_set_irqmask(hw, 0); | |
2976 | hermes_write_regn(hw, EVACK, 0xffff); | |
2977 | ||
2978 | priv->hw_unavailable++; | |
2979 | priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */ | |
2980 | netif_carrier_off(dev); | |
2981 | ||
2982 | orinoco_unlock(priv, &flags); | |
2983 | ||
95dd91fb | 2984 | /* Scanning support: Cleanup of driver struct */ |
1e3428e9 | 2985 | orinoco_clear_scan_results(priv, 0); |
95dd91fb CH |
2986 | priv->scan_inprogress = 0; |
2987 | ||
8551cb98 | 2988 | if (priv->hard_reset) { |
1da177e4 | 2989 | err = (*priv->hard_reset)(priv); |
8551cb98 CH |
2990 | if (err) { |
2991 | printk(KERN_ERR "%s: orinoco_reset: Error %d " | |
2992 | "performing hard reset\n", dev->name, err); | |
2993 | goto disable; | |
2994 | } | |
1da177e4 LT |
2995 | } |
2996 | ||
2997 | err = orinoco_reinit_firmware(dev); | |
2998 | if (err) { | |
2999 | printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n", | |
3000 | dev->name, err); | |
8551cb98 | 3001 | goto disable; |
1da177e4 LT |
3002 | } |
3003 | ||
3004 | spin_lock_irq(&priv->lock); /* This has to be called from user context */ | |
3005 | ||
3006 | priv->hw_unavailable--; | |
3007 | ||
3008 | /* priv->open or priv->hw_unavailable might have changed while | |
3009 | * we dropped the lock */ | |
3010 | if (priv->open && (! priv->hw_unavailable)) { | |
3011 | err = __orinoco_up(dev); | |
3012 | if (err) { | |
3013 | printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n", | |
3014 | dev->name, err); | |
3015 | } else | |
3016 | dev->trans_start = jiffies; | |
3017 | } | |
3018 | ||
3019 | spin_unlock_irq(&priv->lock); | |
3020 | ||
3021 | return; | |
8551cb98 CH |
3022 | disable: |
3023 | hermes_set_irqmask(hw, 0); | |
3024 | netif_device_detach(dev); | |
3025 | printk(KERN_ERR "%s: Device has been disabled!\n", dev->name); | |
1da177e4 LT |
3026 | } |
3027 | ||
3028 | /********************************************************************/ | |
3029 | /* Interrupt handler */ | |
3030 | /********************************************************************/ | |
3031 | ||
3032 | static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw) | |
3033 | { | |
3034 | printk(KERN_DEBUG "%s: TICK\n", dev->name); | |
3035 | } | |
3036 | ||
3037 | static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw) | |
3038 | { | |
3039 | /* This seems to happen a fair bit under load, but ignoring it | |
3040 | seems to work fine...*/ | |
3041 | printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n", | |
3042 | dev->name); | |
3043 | } | |
3044 | ||
7d12e780 | 3045 | irqreturn_t orinoco_interrupt(int irq, void *dev_id) |
1da177e4 | 3046 | { |
c31f28e7 | 3047 | struct net_device *dev = dev_id; |
1da177e4 LT |
3048 | struct orinoco_private *priv = netdev_priv(dev); |
3049 | hermes_t *hw = &priv->hw; | |
3050 | int count = MAX_IRQLOOPS_PER_IRQ; | |
3051 | u16 evstat, events; | |
3052 | /* These are used to detect a runaway interrupt situation */ | |
3053 | /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy, | |
3054 | * we panic and shut down the hardware */ | |
3055 | static int last_irq_jiffy = 0; /* jiffies value the last time | |
3056 | * we were called */ | |
3057 | static int loops_this_jiffy = 0; | |
3058 | unsigned long flags; | |
3059 | ||
3060 | if (orinoco_lock(priv, &flags) != 0) { | |
3061 | /* If hw is unavailable - we don't know if the irq was | |
3062 | * for us or not */ | |
3063 | return IRQ_HANDLED; | |
3064 | } | |
3065 | ||
3066 | evstat = hermes_read_regn(hw, EVSTAT); | |
3067 | events = evstat & hw->inten; | |
3068 | if (! events) { | |
3069 | orinoco_unlock(priv, &flags); | |
3070 | return IRQ_NONE; | |
3071 | } | |
3072 | ||
3073 | if (jiffies != last_irq_jiffy) | |
3074 | loops_this_jiffy = 0; | |
3075 | last_irq_jiffy = jiffies; | |
3076 | ||
3077 | while (events && count--) { | |
3078 | if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) { | |
3079 | printk(KERN_WARNING "%s: IRQ handler is looping too " | |
3080 | "much! Resetting.\n", dev->name); | |
3081 | /* Disable interrupts for now */ | |
3082 | hermes_set_irqmask(hw, 0); | |
3083 | schedule_work(&priv->reset_work); | |
3084 | break; | |
3085 | } | |
3086 | ||
3087 | /* Check the card hasn't been removed */ | |
3088 | if (! hermes_present(hw)) { | |
3089 | DEBUG(0, "orinoco_interrupt(): card removed\n"); | |
3090 | break; | |
3091 | } | |
3092 | ||
3093 | if (events & HERMES_EV_TICK) | |
3094 | __orinoco_ev_tick(dev, hw); | |
3095 | if (events & HERMES_EV_WTERR) | |
3096 | __orinoco_ev_wterr(dev, hw); | |
3097 | if (events & HERMES_EV_INFDROP) | |
3098 | __orinoco_ev_infdrop(dev, hw); | |
3099 | if (events & HERMES_EV_INFO) | |
3100 | __orinoco_ev_info(dev, hw); | |
3101 | if (events & HERMES_EV_RX) | |
3102 | __orinoco_ev_rx(dev, hw); | |
3103 | if (events & HERMES_EV_TXEXC) | |
3104 | __orinoco_ev_txexc(dev, hw); | |
3105 | if (events & HERMES_EV_TX) | |
3106 | __orinoco_ev_tx(dev, hw); | |
3107 | if (events & HERMES_EV_ALLOC) | |
3108 | __orinoco_ev_alloc(dev, hw); | |
3109 | ||
84d8a2fb | 3110 | hermes_write_regn(hw, EVACK, evstat); |
1da177e4 LT |
3111 | |
3112 | evstat = hermes_read_regn(hw, EVSTAT); | |
3113 | events = evstat & hw->inten; | |
3114 | }; | |
3115 | ||
3116 | orinoco_unlock(priv, &flags); | |
3117 | return IRQ_HANDLED; | |
3118 | } | |
3119 | ||
39d1ffee DK |
3120 | /********************************************************************/ |
3121 | /* Power management */ | |
3122 | /********************************************************************/ | |
3123 | #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT) | |
3124 | static int orinoco_pm_notifier(struct notifier_block *notifier, | |
3125 | unsigned long pm_event, | |
3126 | void *unused) | |
3127 | { | |
3128 | struct orinoco_private *priv = container_of(notifier, | |
3129 | struct orinoco_private, | |
3130 | pm_notifier); | |
3131 | ||
3132 | /* All we need to do is cache the firmware before suspend, and | |
3133 | * release it when we come out. | |
3134 | * | |
3135 | * Only need to do this if we're downloading firmware. */ | |
3136 | if (!priv->do_fw_download) | |
3137 | return NOTIFY_DONE; | |
3138 | ||
3139 | switch (pm_event) { | |
3140 | case PM_HIBERNATION_PREPARE: | |
3141 | case PM_SUSPEND_PREPARE: | |
3142 | orinoco_cache_fw(priv, 0); | |
3143 | break; | |
3144 | ||
3145 | case PM_POST_RESTORE: | |
3146 | /* Restore from hibernation failed. We need to clean | |
3147 | * up in exactly the same way, so fall through. */ | |
3148 | case PM_POST_HIBERNATION: | |
3149 | case PM_POST_SUSPEND: | |
3150 | orinoco_uncache_fw(priv); | |
3151 | break; | |
3152 | ||
3153 | case PM_RESTORE_PREPARE: | |
3154 | default: | |
3155 | break; | |
3156 | } | |
3157 | ||
3158 | return NOTIFY_DONE; | |
3159 | } | |
3160 | #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */ | |
3161 | #define orinoco_pm_notifier NULL | |
3162 | #endif | |
3163 | ||
1da177e4 LT |
3164 | /********************************************************************/ |
3165 | /* Initialization */ | |
3166 | /********************************************************************/ | |
3167 | ||
3168 | struct comp_id { | |
3169 | u16 id, variant, major, minor; | |
3170 | } __attribute__ ((packed)); | |
3171 | ||
3172 | static inline fwtype_t determine_firmware_type(struct comp_id *nic_id) | |
3173 | { | |
3174 | if (nic_id->id < 0x8000) | |
3175 | return FIRMWARE_TYPE_AGERE; | |
3176 | else if (nic_id->id == 0x8000 && nic_id->major == 0) | |
3177 | return FIRMWARE_TYPE_SYMBOL; | |
3178 | else | |
3179 | return FIRMWARE_TYPE_INTERSIL; | |
3180 | } | |
3181 | ||
3182 | /* Set priv->firmware type, determine firmware properties */ | |
3183 | static int determine_firmware(struct net_device *dev) | |
3184 | { | |
3185 | struct orinoco_private *priv = netdev_priv(dev); | |
3186 | hermes_t *hw = &priv->hw; | |
3187 | int err; | |
3188 | struct comp_id nic_id, sta_id; | |
3189 | unsigned int firmver; | |
dde6d43d | 3190 | char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2))); |
1da177e4 LT |
3191 | |
3192 | /* Get the hardware version */ | |
3193 | err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id); | |
3194 | if (err) { | |
3195 | printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n", | |
3196 | dev->name, err); | |
3197 | return err; | |
3198 | } | |
3199 | ||
3200 | le16_to_cpus(&nic_id.id); | |
3201 | le16_to_cpus(&nic_id.variant); | |
3202 | le16_to_cpus(&nic_id.major); | |
3203 | le16_to_cpus(&nic_id.minor); | |
3204 | printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n", | |
3205 | dev->name, nic_id.id, nic_id.variant, | |
3206 | nic_id.major, nic_id.minor); | |
3207 | ||
3208 | priv->firmware_type = determine_firmware_type(&nic_id); | |
3209 | ||
3210 | /* Get the firmware version */ | |
3211 | err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id); | |
3212 | if (err) { | |
3213 | printk(KERN_ERR "%s: Cannot read station identity: error %d\n", | |
3214 | dev->name, err); | |
3215 | return err; | |
3216 | } | |
3217 | ||
3218 | le16_to_cpus(&sta_id.id); | |
3219 | le16_to_cpus(&sta_id.variant); | |
3220 | le16_to_cpus(&sta_id.major); | |
3221 | le16_to_cpus(&sta_id.minor); | |
3222 | printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n", | |
3223 | dev->name, sta_id.id, sta_id.variant, | |
3224 | sta_id.major, sta_id.minor); | |
3225 | ||
3226 | switch (sta_id.id) { | |
3227 | case 0x15: | |
3228 | printk(KERN_ERR "%s: Primary firmware is active\n", | |
3229 | dev->name); | |
3230 | return -ENODEV; | |
3231 | case 0x14b: | |
3232 | printk(KERN_ERR "%s: Tertiary firmware is active\n", | |
3233 | dev->name); | |
3234 | return -ENODEV; | |
3235 | case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */ | |
3236 | case 0x21: /* Symbol Spectrum24 Trilogy */ | |
3237 | break; | |
3238 | default: | |
3239 | printk(KERN_NOTICE "%s: Unknown station ID, please report\n", | |
3240 | dev->name); | |
3241 | break; | |
3242 | } | |
3243 | ||
3244 | /* Default capabilities */ | |
3245 | priv->has_sensitivity = 1; | |
3246 | priv->has_mwo = 0; | |
3247 | priv->has_preamble = 0; | |
3248 | priv->has_port3 = 1; | |
3249 | priv->has_ibss = 1; | |
3250 | priv->has_wep = 0; | |
3251 | priv->has_big_wep = 0; | |
6eecad77 | 3252 | priv->has_alt_txcntl = 0; |
01632fa4 | 3253 | priv->has_ext_scan = 0; |
d03032af | 3254 | priv->has_wpa = 0; |
3994d502 | 3255 | priv->do_fw_download = 0; |
1da177e4 LT |
3256 | |
3257 | /* Determine capabilities from the firmware version */ | |
3258 | switch (priv->firmware_type) { | |
3259 | case FIRMWARE_TYPE_AGERE: | |
3260 | /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout, | |
3261 | ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */ | |
3262 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, | |
3263 | "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor); | |
3264 | ||
3265 | firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor; | |
3266 | ||
3267 | priv->has_ibss = (firmver >= 0x60006); | |
3268 | priv->has_wep = (firmver >= 0x40020); | |
3269 | priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell | |
3270 | Gold cards from the others? */ | |
3271 | priv->has_mwo = (firmver >= 0x60000); | |
3272 | priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */ | |
3273 | priv->ibss_port = 1; | |
95dd91fb | 3274 | priv->has_hostscan = (firmver >= 0x8000a); |
3994d502 | 3275 | priv->do_fw_download = 1; |
98c4cae1 | 3276 | priv->broken_monitor = (firmver >= 0x80000); |
6eecad77 | 3277 | priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */ |
01632fa4 | 3278 | priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */ |
d03032af | 3279 | priv->has_wpa = (firmver >= 0x9002a); |
1da177e4 LT |
3280 | /* Tested with Agere firmware : |
3281 | * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II | |
3282 | * Tested CableTron firmware : 4.32 => Anton */ | |
3283 | break; | |
3284 | case FIRMWARE_TYPE_SYMBOL: | |
3285 | /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */ | |
3286 | /* Intel MAC : 00:02:B3:* */ | |
3287 | /* 3Com MAC : 00:50:DA:* */ | |
3288 | memset(tmp, 0, sizeof(tmp)); | |
3289 | /* Get the Symbol firmware version */ | |
3290 | err = hermes_read_ltv(hw, USER_BAP, | |
3291 | HERMES_RID_SECONDARYVERSION_SYMBOL, | |
3292 | SYMBOL_MAX_VER_LEN, NULL, &tmp); | |
3293 | if (err) { | |
3294 | printk(KERN_WARNING | |
3295 | "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n", | |
3296 | dev->name, err); | |
3297 | firmver = 0; | |
3298 | tmp[0] = '\0'; | |
3299 | } else { | |
3300 | /* The firmware revision is a string, the format is | |
3301 | * something like : "V2.20-01". | |
3302 | * Quick and dirty parsing... - Jean II | |
3303 | */ | |
3304 | firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12) | |
3305 | | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4) | |
3306 | | (tmp[7] - '0'); | |
3307 | ||
3308 | tmp[SYMBOL_MAX_VER_LEN] = '\0'; | |
3309 | } | |
3310 | ||
3311 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, | |
3312 | "Symbol %s", tmp); | |
3313 | ||
3314 | priv->has_ibss = (firmver >= 0x20000); | |
3315 | priv->has_wep = (firmver >= 0x15012); | |
3316 | priv->has_big_wep = (firmver >= 0x20000); | |
3317 | priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) || | |
3318 | (firmver >= 0x29000 && firmver < 0x30000) || | |
3319 | firmver >= 0x31000; | |
3320 | priv->has_preamble = (firmver >= 0x20000); | |
3321 | priv->ibss_port = 4; | |
3994d502 DK |
3322 | |
3323 | /* Symbol firmware is found on various cards, but | |
3324 | * there has been no attempt to check firmware | |
3325 | * download on non-spectrum_cs based cards. | |
3326 | * | |
3327 | * Given that the Agere firmware download works | |
3328 | * differently, we should avoid doing a firmware | |
3329 | * download with the Symbol algorithm on non-spectrum | |
3330 | * cards. | |
3331 | * | |
3332 | * For now we can identify a spectrum_cs based card | |
3333 | * because it has a firmware reset function. | |
3334 | */ | |
3335 | priv->do_fw_download = (priv->stop_fw != NULL); | |
3336 | ||
649e59e6 CH |
3337 | priv->broken_disableport = (firmver == 0x25013) || |
3338 | (firmver >= 0x30000 && firmver <= 0x31000); | |
95dd91fb CH |
3339 | priv->has_hostscan = (firmver >= 0x31001) || |
3340 | (firmver >= 0x29057 && firmver < 0x30000); | |
1da177e4 LT |
3341 | /* Tested with Intel firmware : 0x20015 => Jean II */ |
3342 | /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */ | |
3343 | break; | |
3344 | case FIRMWARE_TYPE_INTERSIL: | |
3345 | /* D-Link, Linksys, Adtron, ZoomAir, and many others... | |
3346 | * Samsung, Compaq 100/200 and Proxim are slightly | |
3347 | * different and less well tested */ | |
3348 | /* D-Link MAC : 00:40:05:* */ | |
3349 | /* Addtron MAC : 00:90:D1:* */ | |
3350 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, | |
3351 | "Intersil %d.%d.%d", sta_id.major, sta_id.minor, | |
3352 | sta_id.variant); | |
3353 | ||
3354 | firmver = ((unsigned long)sta_id.major << 16) | | |
3355 | ((unsigned long)sta_id.minor << 8) | sta_id.variant; | |
3356 | ||
3357 | priv->has_ibss = (firmver >= 0x000700); /* FIXME */ | |
3358 | priv->has_big_wep = priv->has_wep = (firmver >= 0x000800); | |
3359 | priv->has_pm = (firmver >= 0x000700); | |
95dd91fb | 3360 | priv->has_hostscan = (firmver >= 0x010301); |
1da177e4 LT |
3361 | |
3362 | if (firmver >= 0x000800) | |
3363 | priv->ibss_port = 0; | |
3364 | else { | |
3365 | printk(KERN_NOTICE "%s: Intersil firmware earlier " | |
3366 | "than v0.8.x - several features not supported\n", | |
3367 | dev->name); | |
3368 | priv->ibss_port = 1; | |
3369 | } | |
3370 | break; | |
3371 | } | |
3372 | printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name, | |
3373 | priv->fw_name); | |
3374 | ||
3375 | return 0; | |
3376 | } | |
3377 | ||
3378 | static int orinoco_init(struct net_device *dev) | |
3379 | { | |
3380 | struct orinoco_private *priv = netdev_priv(dev); | |
3381 | hermes_t *hw = &priv->hw; | |
3382 | int err = 0; | |
3383 | struct hermes_idstring nickbuf; | |
3384 | u16 reclen; | |
3385 | int len; | |
3386 | ||
1da177e4 LT |
3387 | /* No need to lock, the hw_unavailable flag is already set in |
3388 | * alloc_orinocodev() */ | |
2c706002 | 3389 | priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN; |
1da177e4 LT |
3390 | |
3391 | /* Initialize the firmware */ | |
37a6c611 | 3392 | err = hermes_init(hw); |
1da177e4 LT |
3393 | if (err != 0) { |
3394 | printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n", | |
3395 | dev->name, err); | |
3396 | goto out; | |
3397 | } | |
3398 | ||
3399 | err = determine_firmware(dev); | |
3400 | if (err != 0) { | |
3401 | printk(KERN_ERR "%s: Incompatible firmware, aborting\n", | |
3402 | dev->name); | |
3403 | goto out; | |
3404 | } | |
3405 | ||
3994d502 | 3406 | if (priv->do_fw_download) { |
39d1ffee | 3407 | #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT |
74734312 | 3408 | orinoco_cache_fw(priv, 0); |
39d1ffee | 3409 | #endif |
74734312 | 3410 | |
3994d502 DK |
3411 | err = orinoco_download(priv); |
3412 | if (err) | |
3413 | priv->do_fw_download = 0; | |
3414 | ||
3415 | /* Check firmware version again */ | |
3416 | err = determine_firmware(dev); | |
3417 | if (err != 0) { | |
3418 | printk(KERN_ERR "%s: Incompatible firmware, aborting\n", | |
3419 | dev->name); | |
3420 | goto out; | |
3421 | } | |
3422 | } | |
3423 | ||
1da177e4 LT |
3424 | if (priv->has_port3) |
3425 | printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name); | |
3426 | if (priv->has_ibss) | |
3427 | printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n", | |
3428 | dev->name); | |
3429 | if (priv->has_wep) { | |
3430 | printk(KERN_DEBUG "%s: WEP supported, ", dev->name); | |
3431 | if (priv->has_big_wep) | |
3432 | printk("104-bit key\n"); | |
3433 | else | |
3434 | printk("40-bit key\n"); | |
3435 | } | |
23edcc41 | 3436 | if (priv->has_wpa) { |
d03032af | 3437 | printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name); |
23edcc41 DK |
3438 | if (orinoco_mic_init(priv)) { |
3439 | printk(KERN_ERR "%s: Failed to setup MIC crypto " | |
3440 | "algorithm. Disabling WPA support\n", dev->name); | |
3441 | priv->has_wpa = 0; | |
3442 | } | |
3443 | } | |
1da177e4 | 3444 | |
01632fa4 DK |
3445 | /* Now we have the firmware capabilities, allocate appropiate |
3446 | * sized scan buffers */ | |
3447 | if (orinoco_bss_data_allocate(priv)) | |
3448 | goto out; | |
3449 | orinoco_bss_data_init(priv); | |
3450 | ||
1da177e4 LT |
3451 | /* Get the MAC address */ |
3452 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR, | |
3453 | ETH_ALEN, NULL, dev->dev_addr); | |
3454 | if (err) { | |
3455 | printk(KERN_WARNING "%s: failed to read MAC address!\n", | |
3456 | dev->name); | |
3457 | goto out; | |
3458 | } | |
3459 | ||
e174961c JB |
3460 | printk(KERN_DEBUG "%s: MAC address %pM\n", |
3461 | dev->name, dev->dev_addr); | |
1da177e4 LT |
3462 | |
3463 | /* Get the station name */ | |
3464 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME, | |
3465 | sizeof(nickbuf), &reclen, &nickbuf); | |
3466 | if (err) { | |
3467 | printk(KERN_ERR "%s: failed to read station name\n", | |
3468 | dev->name); | |
3469 | goto out; | |
3470 | } | |
3471 | if (nickbuf.len) | |
3472 | len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len)); | |
3473 | else | |
3474 | len = min(IW_ESSID_MAX_SIZE, 2 * reclen); | |
3475 | memcpy(priv->nick, &nickbuf.val, len); | |
3476 | priv->nick[len] = '\0'; | |
3477 | ||
3478 | printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick); | |
3479 | ||
37a6c611 PR |
3480 | err = orinoco_allocate_fid(dev); |
3481 | if (err) { | |
3482 | printk(KERN_ERR "%s: failed to allocate NIC buffer!\n", | |
3483 | dev->name); | |
3484 | goto out; | |
3485 | } | |
3486 | ||
1da177e4 LT |
3487 | /* Get allowed channels */ |
3488 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST, | |
3489 | &priv->channel_mask); | |
3490 | if (err) { | |
3491 | printk(KERN_ERR "%s: failed to read channel list!\n", | |
3492 | dev->name); | |
3493 | goto out; | |
3494 | } | |
3495 | ||
3496 | /* Get initial AP density */ | |
3497 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE, | |
3498 | &priv->ap_density); | |
3499 | if (err || priv->ap_density < 1 || priv->ap_density > 3) { | |
3500 | priv->has_sensitivity = 0; | |
3501 | } | |
3502 | ||
3503 | /* Get initial RTS threshold */ | |
3504 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, | |
3505 | &priv->rts_thresh); | |
3506 | if (err) { | |
3507 | printk(KERN_ERR "%s: failed to read RTS threshold!\n", | |
3508 | dev->name); | |
3509 | goto out; | |
3510 | } | |
3511 | ||
3512 | /* Get initial fragmentation settings */ | |
3513 | if (priv->has_mwo) | |
3514 | err = hermes_read_wordrec(hw, USER_BAP, | |
3515 | HERMES_RID_CNFMWOROBUST_AGERE, | |
3516 | &priv->mwo_robust); | |
3517 | else | |
3518 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, | |
3519 | &priv->frag_thresh); | |
3520 | if (err) { | |
3521 | printk(KERN_ERR "%s: failed to read fragmentation settings!\n", | |
3522 | dev->name); | |
3523 | goto out; | |
3524 | } | |
3525 | ||
3526 | /* Power management setup */ | |
3527 | if (priv->has_pm) { | |
3528 | priv->pm_on = 0; | |
3529 | priv->pm_mcast = 1; | |
3530 | err = hermes_read_wordrec(hw, USER_BAP, | |
3531 | HERMES_RID_CNFMAXSLEEPDURATION, | |
3532 | &priv->pm_period); | |
3533 | if (err) { | |
3534 | printk(KERN_ERR "%s: failed to read power management period!\n", | |
3535 | dev->name); | |
3536 | goto out; | |
3537 | } | |
3538 | err = hermes_read_wordrec(hw, USER_BAP, | |
3539 | HERMES_RID_CNFPMHOLDOVERDURATION, | |
3540 | &priv->pm_timeout); | |
3541 | if (err) { | |
3542 | printk(KERN_ERR "%s: failed to read power management timeout!\n", | |
3543 | dev->name); | |
3544 | goto out; | |
3545 | } | |
3546 | } | |
3547 | ||
3548 | /* Preamble setup */ | |
3549 | if (priv->has_preamble) { | |
3550 | err = hermes_read_wordrec(hw, USER_BAP, | |
3551 | HERMES_RID_CNFPREAMBLE_SYMBOL, | |
3552 | &priv->preamble); | |
3553 | if (err) | |
3554 | goto out; | |
3555 | } | |
3556 | ||
3557 | /* Set up the default configuration */ | |
3558 | priv->iw_mode = IW_MODE_INFRA; | |
3559 | /* By default use IEEE/IBSS ad-hoc mode if we have it */ | |
3560 | priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss); | |
3561 | set_port_type(priv); | |
d51d8b1f | 3562 | priv->channel = 0; /* use firmware default */ |
1da177e4 LT |
3563 | |
3564 | priv->promiscuous = 0; | |
4ae6ee2d | 3565 | priv->encode_alg = IW_ENCODE_ALG_NONE; |
1da177e4 | 3566 | priv->tx_key = 0; |
d03032af DK |
3567 | priv->wpa_enabled = 0; |
3568 | priv->tkip_cm_active = 0; | |
3569 | priv->key_mgmt = 0; | |
3570 | priv->wpa_ie_len = 0; | |
3571 | priv->wpa_ie = NULL; | |
1da177e4 | 3572 | |
1da177e4 LT |
3573 | /* Make the hardware available, as long as it hasn't been |
3574 | * removed elsewhere (e.g. by PCMCIA hot unplug) */ | |
3575 | spin_lock_irq(&priv->lock); | |
3576 | priv->hw_unavailable--; | |
3577 | spin_unlock_irq(&priv->lock); | |
3578 | ||
3579 | printk(KERN_DEBUG "%s: ready\n", dev->name); | |
3580 | ||
3581 | out: | |
1da177e4 LT |
3582 | return err; |
3583 | } | |
3584 | ||
3994d502 DK |
3585 | struct net_device |
3586 | *alloc_orinocodev(int sizeof_card, | |
3587 | struct device *device, | |
3588 | int (*hard_reset)(struct orinoco_private *), | |
3589 | int (*stop_fw)(struct orinoco_private *, int)) | |
1da177e4 LT |
3590 | { |
3591 | struct net_device *dev; | |
3592 | struct orinoco_private *priv; | |
3593 | ||
3594 | dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card); | |
3595 | if (! dev) | |
3596 | return NULL; | |
3597 | priv = netdev_priv(dev); | |
3598 | priv->ndev = dev; | |
3599 | if (sizeof_card) | |
84d8a2fb | 3600 | priv->card = (void *)((unsigned long)priv |
1da177e4 LT |
3601 | + sizeof(struct orinoco_private)); |
3602 | else | |
3603 | priv->card = NULL; | |
3994d502 | 3604 | priv->dev = device; |
1da177e4 LT |
3605 | |
3606 | /* Setup / override net_device fields */ | |
3607 | dev->init = orinoco_init; | |
3608 | dev->hard_start_xmit = orinoco_xmit; | |
3609 | dev->tx_timeout = orinoco_tx_timeout; | |
3610 | dev->watchdog_timeo = HZ; /* 1 second timeout */ | |
3611 | dev->get_stats = orinoco_get_stats; | |
1fab2e8b | 3612 | dev->ethtool_ops = &orinoco_ethtool_ops; |
620554e4 | 3613 | dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def; |
343c686c PR |
3614 | #ifdef WIRELESS_SPY |
3615 | priv->wireless_data.spy_data = &priv->spy_data; | |
3616 | dev->wireless_data = &priv->wireless_data; | |
3617 | #endif | |
1da177e4 LT |
3618 | dev->change_mtu = orinoco_change_mtu; |
3619 | dev->set_multicast_list = orinoco_set_multicast_list; | |
3620 | /* we use the default eth_mac_addr for setting the MAC addr */ | |
3621 | ||
23edcc41 DK |
3622 | /* Reserve space in skb for the SNAP header */ |
3623 | dev->hard_header_len += ENCAPS_OVERHEAD; | |
3624 | ||
1da177e4 LT |
3625 | /* Set up default callbacks */ |
3626 | dev->open = orinoco_open; | |
3627 | dev->stop = orinoco_stop; | |
3628 | priv->hard_reset = hard_reset; | |
3994d502 | 3629 | priv->stop_fw = stop_fw; |
1da177e4 LT |
3630 | |
3631 | spin_lock_init(&priv->lock); | |
3632 | priv->open = 0; | |
3633 | priv->hw_unavailable = 1; /* orinoco_init() must clear this | |
3634 | * before anything else touches the | |
3635 | * hardware */ | |
c4028958 DH |
3636 | INIT_WORK(&priv->reset_work, orinoco_reset); |
3637 | INIT_WORK(&priv->join_work, orinoco_join_ap); | |
3638 | INIT_WORK(&priv->wevent_work, orinoco_send_wevents); | |
1da177e4 | 3639 | |
31afcef3 DK |
3640 | INIT_LIST_HEAD(&priv->rx_list); |
3641 | tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet, | |
3642 | (unsigned long) dev); | |
3643 | ||
1da177e4 LT |
3644 | netif_carrier_off(dev); |
3645 | priv->last_linkstatus = 0xffff; | |
3646 | ||
2cea7b26 | 3647 | priv->cached_pri_fw = NULL; |
4fb30784 AB |
3648 | priv->cached_fw = NULL; |
3649 | ||
39d1ffee DK |
3650 | /* Register PM notifiers */ |
3651 | priv->pm_notifier.notifier_call = orinoco_pm_notifier; | |
3652 | register_pm_notifier(&priv->pm_notifier); | |
3653 | ||
1da177e4 | 3654 | return dev; |
1da177e4 LT |
3655 | } |
3656 | ||
3657 | void free_orinocodev(struct net_device *dev) | |
3658 | { | |
95dd91fb | 3659 | struct orinoco_private *priv = netdev_priv(dev); |
20953ad6 | 3660 | struct orinoco_rx_data *rx_data, *temp; |
95dd91fb | 3661 | |
20953ad6 DK |
3662 | /* If the tasklet is scheduled when we call tasklet_kill it |
3663 | * will run one final time. However the tasklet will only | |
3664 | * drain priv->rx_list if the hw is still available. */ | |
31afcef3 | 3665 | tasklet_kill(&priv->rx_tasklet); |
74734312 | 3666 | |
20953ad6 DK |
3667 | /* Explicitly drain priv->rx_list */ |
3668 | list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) { | |
3669 | list_del(&rx_data->list); | |
3670 | ||
3671 | dev_kfree_skb(rx_data->skb); | |
3672 | kfree(rx_data->desc); | |
3673 | kfree(rx_data); | |
3674 | } | |
3675 | ||
39d1ffee | 3676 | unregister_pm_notifier(&priv->pm_notifier); |
74734312 DK |
3677 | orinoco_uncache_fw(priv); |
3678 | ||
d03032af DK |
3679 | priv->wpa_ie_len = 0; |
3680 | kfree(priv->wpa_ie); | |
23edcc41 | 3681 | orinoco_mic_free(priv); |
1e3428e9 | 3682 | orinoco_bss_data_free(priv); |
1da177e4 LT |
3683 | free_netdev(dev); |
3684 | } | |
3685 | ||
3686 | /********************************************************************/ | |
3687 | /* Wireless extensions */ | |
3688 | /********************************************************************/ | |
3689 | ||
7e4e8d99 | 3690 | /* Return : < 0 -> error code ; >= 0 -> length */ |
1da177e4 LT |
3691 | static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active, |
3692 | char buf[IW_ESSID_MAX_SIZE+1]) | |
3693 | { | |
3694 | hermes_t *hw = &priv->hw; | |
3695 | int err = 0; | |
3696 | struct hermes_idstring essidbuf; | |
3697 | char *p = (char *)(&essidbuf.val); | |
3698 | int len; | |
3699 | unsigned long flags; | |
3700 | ||
3701 | if (orinoco_lock(priv, &flags) != 0) | |
3702 | return -EBUSY; | |
3703 | ||
3704 | if (strlen(priv->desired_essid) > 0) { | |
3705 | /* We read the desired SSID from the hardware rather | |
3706 | than from priv->desired_essid, just in case the | |
3707 | firmware is allowed to change it on us. I'm not | |
3708 | sure about this */ | |
3709 | /* My guess is that the OWNSSID should always be whatever | |
3710 | * we set to the card, whereas CURRENT_SSID is the one that | |
3711 | * may change... - Jean II */ | |
3712 | u16 rid; | |
3713 | ||
3714 | *active = 1; | |
3715 | ||
3716 | rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID : | |
3717 | HERMES_RID_CNFDESIREDSSID; | |
3718 | ||
3719 | err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf), | |
3720 | NULL, &essidbuf); | |
3721 | if (err) | |
3722 | goto fail_unlock; | |
3723 | } else { | |
3724 | *active = 0; | |
3725 | ||
3726 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID, | |
3727 | sizeof(essidbuf), NULL, &essidbuf); | |
3728 | if (err) | |
3729 | goto fail_unlock; | |
3730 | } | |
3731 | ||
3732 | len = le16_to_cpu(essidbuf.len); | |
84d8a2fb | 3733 | BUG_ON(len > IW_ESSID_MAX_SIZE); |
1da177e4 | 3734 | |
7e4e8d99 | 3735 | memset(buf, 0, IW_ESSID_MAX_SIZE); |
1da177e4 | 3736 | memcpy(buf, p, len); |
7e4e8d99 | 3737 | err = len; |
1da177e4 LT |
3738 | |
3739 | fail_unlock: | |
3740 | orinoco_unlock(priv, &flags); | |
3741 | ||
3742 | return err; | |
3743 | } | |
3744 | ||
3745 | static long orinoco_hw_get_freq(struct orinoco_private *priv) | |
3746 | { | |
3747 | ||
3748 | hermes_t *hw = &priv->hw; | |
3749 | int err = 0; | |
3750 | u16 channel; | |
3751 | long freq = 0; | |
3752 | unsigned long flags; | |
3753 | ||
3754 | if (orinoco_lock(priv, &flags) != 0) | |
3755 | return -EBUSY; | |
3756 | ||
3757 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel); | |
3758 | if (err) | |
3759 | goto out; | |
3760 | ||
3761 | /* Intersil firmware 1.3.5 returns 0 when the interface is down */ | |
3762 | if (channel == 0) { | |
3763 | err = -EBUSY; | |
3764 | goto out; | |
3765 | } | |
3766 | ||
3767 | if ( (channel < 1) || (channel > NUM_CHANNELS) ) { | |
3768 | printk(KERN_WARNING "%s: Channel out of range (%d)!\n", | |
3769 | priv->ndev->name, channel); | |
3770 | err = -EBUSY; | |
3771 | goto out; | |
3772 | ||
3773 | } | |
3774 | freq = channel_frequency[channel-1] * 100000; | |
3775 | ||
3776 | out: | |
3777 | orinoco_unlock(priv, &flags); | |
3778 | ||
3779 | if (err > 0) | |
3780 | err = -EBUSY; | |
3781 | return err ? err : freq; | |
3782 | } | |
3783 | ||
3784 | static int orinoco_hw_get_bitratelist(struct orinoco_private *priv, | |
3785 | int *numrates, s32 *rates, int max) | |
3786 | { | |
3787 | hermes_t *hw = &priv->hw; | |
3788 | struct hermes_idstring list; | |
3789 | unsigned char *p = (unsigned char *)&list.val; | |
3790 | int err = 0; | |
3791 | int num; | |
3792 | int i; | |
3793 | unsigned long flags; | |
3794 | ||
3795 | if (orinoco_lock(priv, &flags) != 0) | |
3796 | return -EBUSY; | |
3797 | ||
3798 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES, | |
3799 | sizeof(list), NULL, &list); | |
3800 | orinoco_unlock(priv, &flags); | |
3801 | ||
3802 | if (err) | |
3803 | return err; | |
3804 | ||
3805 | num = le16_to_cpu(list.len); | |
3806 | *numrates = num; | |
3807 | num = min(num, max); | |
3808 | ||
3809 | for (i = 0; i < num; i++) { | |
3810 | rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */ | |
3811 | } | |
3812 | ||
3813 | return 0; | |
3814 | } | |
3815 | ||
620554e4 CH |
3816 | static int orinoco_ioctl_getname(struct net_device *dev, |
3817 | struct iw_request_info *info, | |
3818 | char *name, | |
3819 | char *extra) | |
1da177e4 LT |
3820 | { |
3821 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 | 3822 | int numrates; |
620554e4 CH |
3823 | int err; |
3824 | ||
3825 | err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0); | |
3826 | ||
3827 | if (!err && (numrates > 2)) | |
3828 | strcpy(name, "IEEE 802.11b"); | |
3829 | else | |
3830 | strcpy(name, "IEEE 802.11-DS"); | |
3831 | ||
3832 | return 0; | |
3833 | } | |
3834 | ||
16739b06 CH |
3835 | static int orinoco_ioctl_setwap(struct net_device *dev, |
3836 | struct iw_request_info *info, | |
3837 | struct sockaddr *ap_addr, | |
3838 | char *extra) | |
3839 | { | |
3840 | struct orinoco_private *priv = netdev_priv(dev); | |
3841 | int err = -EINPROGRESS; /* Call commit handler */ | |
1da177e4 | 3842 | unsigned long flags; |
16739b06 CH |
3843 | static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
3844 | static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
1da177e4 | 3845 | |
16739b06 CH |
3846 | if (orinoco_lock(priv, &flags) != 0) |
3847 | return -EBUSY; | |
3848 | ||
3849 | /* Enable automatic roaming - no sanity checks are needed */ | |
3850 | if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 || | |
3851 | memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) { | |
3852 | priv->bssid_fixed = 0; | |
3853 | memset(priv->desired_bssid, 0, ETH_ALEN); | |
3854 | ||
3855 | /* "off" means keep existing connection */ | |
3856 | if (ap_addr->sa_data[0] == 0) { | |
3857 | __orinoco_hw_set_wap(priv); | |
3858 | err = 0; | |
3859 | } | |
3860 | goto out; | |
3861 | } | |
3862 | ||
3863 | if (priv->firmware_type == FIRMWARE_TYPE_AGERE) { | |
3864 | printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't " | |
3865 | "support manual roaming\n", | |
3866 | dev->name); | |
3867 | err = -EOPNOTSUPP; | |
3868 | goto out; | |
3869 | } | |
3870 | ||
3871 | if (priv->iw_mode != IW_MODE_INFRA) { | |
3872 | printk(KERN_WARNING "%s: Manual roaming supported only in " | |
3873 | "managed mode\n", dev->name); | |
3874 | err = -EOPNOTSUPP; | |
3875 | goto out; | |
3876 | } | |
3877 | ||
3878 | /* Intersil firmware hangs without Desired ESSID */ | |
3879 | if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL && | |
3880 | strlen(priv->desired_essid) == 0) { | |
3881 | printk(KERN_WARNING "%s: Desired ESSID must be set for " | |
3882 | "manual roaming\n", dev->name); | |
3883 | err = -EOPNOTSUPP; | |
3884 | goto out; | |
3885 | } | |
3886 | ||
3887 | /* Finally, enable manual roaming */ | |
3888 | priv->bssid_fixed = 1; | |
3889 | memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN); | |
3890 | ||
3891 | out: | |
3892 | orinoco_unlock(priv, &flags); | |
3893 | return err; | |
3894 | } | |
3895 | ||
620554e4 CH |
3896 | static int orinoco_ioctl_getwap(struct net_device *dev, |
3897 | struct iw_request_info *info, | |
3898 | struct sockaddr *ap_addr, | |
3899 | char *extra) | |
3900 | { | |
3901 | struct orinoco_private *priv = netdev_priv(dev); | |
3902 | ||
3903 | hermes_t *hw = &priv->hw; | |
3904 | int err = 0; | |
1da177e4 LT |
3905 | unsigned long flags; |
3906 | ||
620554e4 CH |
3907 | if (orinoco_lock(priv, &flags) != 0) |
3908 | return -EBUSY; | |
1da177e4 | 3909 | |
620554e4 CH |
3910 | ap_addr->sa_family = ARPHRD_ETHER; |
3911 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID, | |
3912 | ETH_ALEN, NULL, ap_addr->sa_data); | |
1da177e4 | 3913 | |
620554e4 CH |
3914 | orinoco_unlock(priv, &flags); |
3915 | ||
3916 | return err; | |
3917 | } | |
1da177e4 | 3918 | |
620554e4 CH |
3919 | static int orinoco_ioctl_setmode(struct net_device *dev, |
3920 | struct iw_request_info *info, | |
3921 | u32 *mode, | |
3922 | char *extra) | |
3923 | { | |
3924 | struct orinoco_private *priv = netdev_priv(dev); | |
3925 | int err = -EINPROGRESS; /* Call commit handler */ | |
3926 | unsigned long flags; | |
1da177e4 | 3927 | |
620554e4 CH |
3928 | if (priv->iw_mode == *mode) |
3929 | return 0; | |
1da177e4 LT |
3930 | |
3931 | if (orinoco_lock(priv, &flags) != 0) | |
3932 | return -EBUSY; | |
3933 | ||
620554e4 CH |
3934 | switch (*mode) { |
3935 | case IW_MODE_ADHOC: | |
3936 | if (!priv->has_ibss && !priv->has_port3) | |
3937 | err = -EOPNOTSUPP; | |
3938 | break; | |
3939 | ||
3940 | case IW_MODE_INFRA: | |
3941 | break; | |
3942 | ||
98c4cae1 CH |
3943 | case IW_MODE_MONITOR: |
3944 | if (priv->broken_monitor && !force_monitor) { | |
3945 | printk(KERN_WARNING "%s: Monitor mode support is " | |
3946 | "buggy in this firmware, not enabling\n", | |
3947 | dev->name); | |
3948 | err = -EOPNOTSUPP; | |
3949 | } | |
3950 | break; | |
3951 | ||
620554e4 CH |
3952 | default: |
3953 | err = -EOPNOTSUPP; | |
3954 | break; | |
3955 | } | |
3956 | ||
3957 | if (err == -EINPROGRESS) { | |
3958 | priv->iw_mode = *mode; | |
3959 | set_port_type(priv); | |
3960 | } | |
3961 | ||
1da177e4 LT |
3962 | orinoco_unlock(priv, &flags); |
3963 | ||
620554e4 CH |
3964 | return err; |
3965 | } | |
1da177e4 | 3966 | |
620554e4 CH |
3967 | static int orinoco_ioctl_getmode(struct net_device *dev, |
3968 | struct iw_request_info *info, | |
3969 | u32 *mode, | |
3970 | char *extra) | |
3971 | { | |
3972 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 | 3973 | |
620554e4 CH |
3974 | *mode = priv->iw_mode; |
3975 | return 0; | |
3976 | } | |
1da177e4 | 3977 | |
620554e4 CH |
3978 | static int orinoco_ioctl_getiwrange(struct net_device *dev, |
3979 | struct iw_request_info *info, | |
3980 | struct iw_point *rrq, | |
3981 | char *extra) | |
3982 | { | |
3983 | struct orinoco_private *priv = netdev_priv(dev); | |
3984 | int err = 0; | |
3985 | struct iw_range *range = (struct iw_range *) extra; | |
3986 | int numrates; | |
3987 | int i, k; | |
3988 | ||
620554e4 CH |
3989 | rrq->length = sizeof(struct iw_range); |
3990 | memset(range, 0, sizeof(struct iw_range)); | |
3991 | ||
3992 | range->we_version_compiled = WIRELESS_EXT; | |
d03032af | 3993 | range->we_version_source = 22; |
1da177e4 LT |
3994 | |
3995 | /* Set available channels/frequencies */ | |
620554e4 | 3996 | range->num_channels = NUM_CHANNELS; |
1da177e4 LT |
3997 | k = 0; |
3998 | for (i = 0; i < NUM_CHANNELS; i++) { | |
3999 | if (priv->channel_mask & (1 << i)) { | |
620554e4 CH |
4000 | range->freq[k].i = i + 1; |
4001 | range->freq[k].m = channel_frequency[i] * 100000; | |
4002 | range->freq[k].e = 1; | |
1da177e4 LT |
4003 | k++; |
4004 | } | |
4005 | ||
4006 | if (k >= IW_MAX_FREQUENCIES) | |
4007 | break; | |
4008 | } | |
620554e4 CH |
4009 | range->num_frequency = k; |
4010 | range->sensitivity = 3; | |
1da177e4 | 4011 | |
620554e4 CH |
4012 | if (priv->has_wep) { |
4013 | range->max_encoding_tokens = ORINOCO_MAX_KEYS; | |
4014 | range->encoding_size[0] = SMALL_KEY_SIZE; | |
4015 | range->num_encoding_sizes = 1; | |
1da177e4 | 4016 | |
620554e4 CH |
4017 | if (priv->has_big_wep) { |
4018 | range->encoding_size[1] = LARGE_KEY_SIZE; | |
4019 | range->num_encoding_sizes = 2; | |
4020 | } | |
4021 | } | |
1da177e4 | 4022 | |
d03032af DK |
4023 | if (priv->has_wpa) |
4024 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP; | |
4025 | ||
343c686c | 4026 | if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){ |
1da177e4 | 4027 | /* Quality stats meaningless in ad-hoc mode */ |
1da177e4 | 4028 | } else { |
620554e4 CH |
4029 | range->max_qual.qual = 0x8b - 0x2f; |
4030 | range->max_qual.level = 0x2f - 0x95 - 1; | |
4031 | range->max_qual.noise = 0x2f - 0x95 - 1; | |
1da177e4 | 4032 | /* Need to get better values */ |
620554e4 CH |
4033 | range->avg_qual.qual = 0x24; |
4034 | range->avg_qual.level = 0xC2; | |
4035 | range->avg_qual.noise = 0x9E; | |
1da177e4 LT |
4036 | } |
4037 | ||
4038 | err = orinoco_hw_get_bitratelist(priv, &numrates, | |
620554e4 | 4039 | range->bitrate, IW_MAX_BITRATES); |
1da177e4 LT |
4040 | if (err) |
4041 | return err; | |
620554e4 CH |
4042 | range->num_bitrates = numrates; |
4043 | ||
1da177e4 LT |
4044 | /* Set an indication of the max TCP throughput in bit/s that we can |
4045 | * expect using this interface. May be use for QoS stuff... | |
4046 | * Jean II */ | |
620554e4 CH |
4047 | if (numrates > 2) |
4048 | range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */ | |
1da177e4 | 4049 | else |
620554e4 CH |
4050 | range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */ |
4051 | ||
4052 | range->min_rts = 0; | |
4053 | range->max_rts = 2347; | |
4054 | range->min_frag = 256; | |
4055 | range->max_frag = 2346; | |
4056 | ||
4057 | range->min_pmp = 0; | |
4058 | range->max_pmp = 65535000; | |
4059 | range->min_pmt = 0; | |
4060 | range->max_pmt = 65535 * 1000; /* ??? */ | |
4061 | range->pmp_flags = IW_POWER_PERIOD; | |
4062 | range->pmt_flags = IW_POWER_TIMEOUT; | |
4063 | range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R; | |
4064 | ||
4065 | range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME; | |
4066 | range->retry_flags = IW_RETRY_LIMIT; | |
4067 | range->r_time_flags = IW_RETRY_LIFETIME; | |
4068 | range->min_retry = 0; | |
4069 | range->max_retry = 65535; /* ??? */ | |
4070 | range->min_r_time = 0; | |
4071 | range->max_r_time = 65535 * 1000; /* ??? */ | |
1da177e4 | 4072 | |
0753bba2 DK |
4073 | if (priv->firmware_type == FIRMWARE_TYPE_AGERE) |
4074 | range->scan_capa = IW_SCAN_CAPA_ESSID; | |
4075 | else | |
4076 | range->scan_capa = IW_SCAN_CAPA_NONE; | |
4077 | ||
343c686c PR |
4078 | /* Event capability (kernel) */ |
4079 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); | |
4080 | /* Event capability (driver) */ | |
4081 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY); | |
4082 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); | |
4083 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); | |
4084 | IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP); | |
4085 | ||
1da177e4 LT |
4086 | return 0; |
4087 | } | |
4088 | ||
620554e4 CH |
4089 | static int orinoco_ioctl_setiwencode(struct net_device *dev, |
4090 | struct iw_request_info *info, | |
4091 | struct iw_point *erq, | |
4092 | char *keybuf) | |
1da177e4 LT |
4093 | { |
4094 | struct orinoco_private *priv = netdev_priv(dev); | |
4095 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; | |
4096 | int setindex = priv->tx_key; | |
4ae6ee2d | 4097 | int encode_alg = priv->encode_alg; |
1da177e4 LT |
4098 | int restricted = priv->wep_restrict; |
4099 | u16 xlen = 0; | |
620554e4 | 4100 | int err = -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
4101 | unsigned long flags; |
4102 | ||
4103 | if (! priv->has_wep) | |
4104 | return -EOPNOTSUPP; | |
4105 | ||
4106 | if (erq->pointer) { | |
4107 | /* We actually have a key to set - check its length */ | |
4108 | if (erq->length > LARGE_KEY_SIZE) | |
4109 | return -E2BIG; | |
4110 | ||
4111 | if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep ) | |
4112 | return -E2BIG; | |
1da177e4 LT |
4113 | } |
4114 | ||
4115 | if (orinoco_lock(priv, &flags) != 0) | |
4116 | return -EBUSY; | |
4117 | ||
d03032af DK |
4118 | /* Clear any TKIP key we have */ |
4119 | if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP)) | |
4120 | (void) orinoco_clear_tkip_key(priv, setindex); | |
4121 | ||
fe397d46 | 4122 | if (erq->length > 0) { |
1da177e4 LT |
4123 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) |
4124 | index = priv->tx_key; | |
4125 | ||
4126 | /* Adjust key length to a supported value */ | |
4127 | if (erq->length > SMALL_KEY_SIZE) { | |
4128 | xlen = LARGE_KEY_SIZE; | |
4129 | } else if (erq->length > 0) { | |
4130 | xlen = SMALL_KEY_SIZE; | |
4131 | } else | |
4132 | xlen = 0; | |
4133 | ||
4134 | /* Switch on WEP if off */ | |
4ae6ee2d | 4135 | if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) { |
1da177e4 | 4136 | setindex = index; |
4ae6ee2d | 4137 | encode_alg = IW_ENCODE_ALG_WEP; |
1da177e4 LT |
4138 | } |
4139 | } else { | |
4140 | /* Important note : if the user do "iwconfig eth0 enc off", | |
4141 | * we will arrive there with an index of -1. This is valid | |
4142 | * but need to be taken care off... Jean II */ | |
4143 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) { | |
4144 | if((index != -1) || (erq->flags == 0)) { | |
4145 | err = -EINVAL; | |
4146 | goto out; | |
4147 | } | |
4148 | } else { | |
4149 | /* Set the index : Check that the key is valid */ | |
4150 | if(priv->keys[index].len == 0) { | |
4151 | err = -EINVAL; | |
4152 | goto out; | |
4153 | } | |
4154 | setindex = index; | |
4155 | } | |
4156 | } | |
4157 | ||
4158 | if (erq->flags & IW_ENCODE_DISABLED) | |
4ae6ee2d | 4159 | encode_alg = IW_ENCODE_ALG_NONE; |
1da177e4 LT |
4160 | if (erq->flags & IW_ENCODE_OPEN) |
4161 | restricted = 0; | |
4162 | if (erq->flags & IW_ENCODE_RESTRICTED) | |
4163 | restricted = 1; | |
4164 | ||
fe397d46 | 4165 | if (erq->pointer && erq->length > 0) { |
1da177e4 LT |
4166 | priv->keys[index].len = cpu_to_le16(xlen); |
4167 | memset(priv->keys[index].data, 0, | |
4168 | sizeof(priv->keys[index].data)); | |
4169 | memcpy(priv->keys[index].data, keybuf, erq->length); | |
4170 | } | |
4171 | priv->tx_key = setindex; | |
4172 | ||
4173 | /* Try fast key change if connected and only keys are changed */ | |
4ae6ee2d DK |
4174 | if ((priv->encode_alg == encode_alg) && |
4175 | (priv->wep_restrict == restricted) && | |
1da177e4 LT |
4176 | netif_carrier_ok(dev)) { |
4177 | err = __orinoco_hw_setup_wepkeys(priv); | |
4178 | /* No need to commit if successful */ | |
4179 | goto out; | |
4180 | } | |
4181 | ||
4ae6ee2d | 4182 | priv->encode_alg = encode_alg; |
1da177e4 LT |
4183 | priv->wep_restrict = restricted; |
4184 | ||
4185 | out: | |
4186 | orinoco_unlock(priv, &flags); | |
4187 | ||
4188 | return err; | |
4189 | } | |
4190 | ||
620554e4 CH |
4191 | static int orinoco_ioctl_getiwencode(struct net_device *dev, |
4192 | struct iw_request_info *info, | |
4193 | struct iw_point *erq, | |
4194 | char *keybuf) | |
1da177e4 LT |
4195 | { |
4196 | struct orinoco_private *priv = netdev_priv(dev); | |
4197 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; | |
4198 | u16 xlen = 0; | |
1da177e4 LT |
4199 | unsigned long flags; |
4200 | ||
4201 | if (! priv->has_wep) | |
4202 | return -EOPNOTSUPP; | |
4203 | ||
4204 | if (orinoco_lock(priv, &flags) != 0) | |
4205 | return -EBUSY; | |
4206 | ||
4207 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) | |
4208 | index = priv->tx_key; | |
4209 | ||
4210 | erq->flags = 0; | |
4ae6ee2d | 4211 | if (!priv->encode_alg) |
1da177e4 LT |
4212 | erq->flags |= IW_ENCODE_DISABLED; |
4213 | erq->flags |= index + 1; | |
4214 | ||
4215 | if (priv->wep_restrict) | |
4216 | erq->flags |= IW_ENCODE_RESTRICTED; | |
4217 | else | |
4218 | erq->flags |= IW_ENCODE_OPEN; | |
4219 | ||
4220 | xlen = le16_to_cpu(priv->keys[index].len); | |
4221 | ||
4222 | erq->length = xlen; | |
4223 | ||
4224 | memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE); | |
4225 | ||
4226 | orinoco_unlock(priv, &flags); | |
1da177e4 LT |
4227 | return 0; |
4228 | } | |
4229 | ||
620554e4 CH |
4230 | static int orinoco_ioctl_setessid(struct net_device *dev, |
4231 | struct iw_request_info *info, | |
4232 | struct iw_point *erq, | |
4233 | char *essidbuf) | |
1da177e4 LT |
4234 | { |
4235 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
4236 | unsigned long flags; |
4237 | ||
4238 | /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it | |
4239 | * anyway... - Jean II */ | |
4240 | ||
620554e4 CH |
4241 | /* Hum... Should not use Wireless Extension constant (may change), |
4242 | * should use our own... - Jean II */ | |
4243 | if (erq->length > IW_ESSID_MAX_SIZE) | |
4244 | return -E2BIG; | |
1da177e4 LT |
4245 | |
4246 | if (orinoco_lock(priv, &flags) != 0) | |
4247 | return -EBUSY; | |
4248 | ||
620554e4 CH |
4249 | /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */ |
4250 | memset(priv->desired_essid, 0, sizeof(priv->desired_essid)); | |
4251 | ||
4252 | /* If not ANY, get the new ESSID */ | |
4253 | if (erq->flags) { | |
4254 | memcpy(priv->desired_essid, essidbuf, erq->length); | |
4255 | } | |
1da177e4 LT |
4256 | |
4257 | orinoco_unlock(priv, &flags); | |
4258 | ||
620554e4 | 4259 | return -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
4260 | } |
4261 | ||
620554e4 CH |
4262 | static int orinoco_ioctl_getessid(struct net_device *dev, |
4263 | struct iw_request_info *info, | |
4264 | struct iw_point *erq, | |
4265 | char *essidbuf) | |
1da177e4 LT |
4266 | { |
4267 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
4268 | int active; |
4269 | int err = 0; | |
4270 | unsigned long flags; | |
4271 | ||
1da177e4 LT |
4272 | if (netif_running(dev)) { |
4273 | err = orinoco_hw_get_essid(priv, &active, essidbuf); | |
7e4e8d99 | 4274 | if (err < 0) |
1da177e4 | 4275 | return err; |
7e4e8d99 | 4276 | erq->length = err; |
1da177e4 LT |
4277 | } else { |
4278 | if (orinoco_lock(priv, &flags) != 0) | |
4279 | return -EBUSY; | |
7e4e8d99 JT |
4280 | memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE); |
4281 | erq->length = strlen(priv->desired_essid); | |
1da177e4 LT |
4282 | orinoco_unlock(priv, &flags); |
4283 | } | |
4284 | ||
4285 | erq->flags = 1; | |
1da177e4 | 4286 | |
1da177e4 LT |
4287 | return 0; |
4288 | } | |
4289 | ||
620554e4 CH |
4290 | static int orinoco_ioctl_setnick(struct net_device *dev, |
4291 | struct iw_request_info *info, | |
4292 | struct iw_point *nrq, | |
4293 | char *nickbuf) | |
1da177e4 LT |
4294 | { |
4295 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
4296 | unsigned long flags; |
4297 | ||
4298 | if (nrq->length > IW_ESSID_MAX_SIZE) | |
4299 | return -E2BIG; | |
4300 | ||
1da177e4 LT |
4301 | if (orinoco_lock(priv, &flags) != 0) |
4302 | return -EBUSY; | |
4303 | ||
620554e4 CH |
4304 | memset(priv->nick, 0, sizeof(priv->nick)); |
4305 | memcpy(priv->nick, nickbuf, nrq->length); | |
1da177e4 LT |
4306 | |
4307 | orinoco_unlock(priv, &flags); | |
4308 | ||
620554e4 | 4309 | return -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
4310 | } |
4311 | ||
620554e4 CH |
4312 | static int orinoco_ioctl_getnick(struct net_device *dev, |
4313 | struct iw_request_info *info, | |
4314 | struct iw_point *nrq, | |
4315 | char *nickbuf) | |
1da177e4 LT |
4316 | { |
4317 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
4318 | unsigned long flags; |
4319 | ||
4320 | if (orinoco_lock(priv, &flags) != 0) | |
4321 | return -EBUSY; | |
4322 | ||
7e4e8d99 | 4323 | memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE); |
1da177e4 LT |
4324 | orinoco_unlock(priv, &flags); |
4325 | ||
7e4e8d99 | 4326 | nrq->length = strlen(priv->nick); |
1da177e4 | 4327 | |
1da177e4 LT |
4328 | return 0; |
4329 | } | |
4330 | ||
620554e4 CH |
4331 | static int orinoco_ioctl_setfreq(struct net_device *dev, |
4332 | struct iw_request_info *info, | |
4333 | struct iw_freq *frq, | |
4334 | char *extra) | |
1da177e4 LT |
4335 | { |
4336 | struct orinoco_private *priv = netdev_priv(dev); | |
4337 | int chan = -1; | |
4338 | unsigned long flags; | |
620554e4 | 4339 | int err = -EINPROGRESS; /* Call commit handler */ |
1da177e4 | 4340 | |
98c4cae1 CH |
4341 | /* In infrastructure mode the AP sets the channel */ |
4342 | if (priv->iw_mode == IW_MODE_INFRA) | |
4343 | return -EBUSY; | |
1da177e4 LT |
4344 | |
4345 | if ( (frq->e == 0) && (frq->m <= 1000) ) { | |
4346 | /* Setting by channel number */ | |
4347 | chan = frq->m; | |
4348 | } else { | |
4349 | /* Setting by frequency - search the table */ | |
4350 | int mult = 1; | |
4351 | int i; | |
4352 | ||
4353 | for (i = 0; i < (6 - frq->e); i++) | |
4354 | mult *= 10; | |
4355 | ||
4356 | for (i = 0; i < NUM_CHANNELS; i++) | |
4357 | if (frq->m == (channel_frequency[i] * mult)) | |
4358 | chan = i+1; | |
4359 | } | |
4360 | ||
4361 | if ( (chan < 1) || (chan > NUM_CHANNELS) || | |
4362 | ! (priv->channel_mask & (1 << (chan-1)) ) ) | |
4363 | return -EINVAL; | |
4364 | ||
4365 | if (orinoco_lock(priv, &flags) != 0) | |
4366 | return -EBUSY; | |
98c4cae1 | 4367 | |
1da177e4 | 4368 | priv->channel = chan; |
98c4cae1 CH |
4369 | if (priv->iw_mode == IW_MODE_MONITOR) { |
4370 | /* Fast channel change - no commit if successful */ | |
4371 | hermes_t *hw = &priv->hw; | |
4372 | err = hermes_docmd_wait(hw, HERMES_CMD_TEST | | |
4373 | HERMES_TEST_SET_CHANNEL, | |
4374 | chan, NULL); | |
4375 | } | |
1da177e4 LT |
4376 | orinoco_unlock(priv, &flags); |
4377 | ||
620554e4 CH |
4378 | return err; |
4379 | } | |
4380 | ||
4381 | static int orinoco_ioctl_getfreq(struct net_device *dev, | |
4382 | struct iw_request_info *info, | |
4383 | struct iw_freq *frq, | |
4384 | char *extra) | |
4385 | { | |
4386 | struct orinoco_private *priv = netdev_priv(dev); | |
4387 | int tmp; | |
4388 | ||
4389 | /* Locking done in there */ | |
4390 | tmp = orinoco_hw_get_freq(priv); | |
4391 | if (tmp < 0) { | |
4392 | return tmp; | |
4393 | } | |
4394 | ||
4395 | frq->m = tmp; | |
4396 | frq->e = 1; | |
4397 | ||
1da177e4 LT |
4398 | return 0; |
4399 | } | |
4400 | ||
620554e4 CH |
4401 | static int orinoco_ioctl_getsens(struct net_device *dev, |
4402 | struct iw_request_info *info, | |
4403 | struct iw_param *srq, | |
4404 | char *extra) | |
1da177e4 LT |
4405 | { |
4406 | struct orinoco_private *priv = netdev_priv(dev); | |
4407 | hermes_t *hw = &priv->hw; | |
4408 | u16 val; | |
4409 | int err; | |
4410 | unsigned long flags; | |
4411 | ||
4412 | if (!priv->has_sensitivity) | |
4413 | return -EOPNOTSUPP; | |
4414 | ||
4415 | if (orinoco_lock(priv, &flags) != 0) | |
4416 | return -EBUSY; | |
4417 | err = hermes_read_wordrec(hw, USER_BAP, | |
4418 | HERMES_RID_CNFSYSTEMSCALE, &val); | |
4419 | orinoco_unlock(priv, &flags); | |
4420 | ||
4421 | if (err) | |
4422 | return err; | |
4423 | ||
4424 | srq->value = val; | |
4425 | srq->fixed = 0; /* auto */ | |
4426 | ||
4427 | return 0; | |
4428 | } | |
4429 | ||
620554e4 CH |
4430 | static int orinoco_ioctl_setsens(struct net_device *dev, |
4431 | struct iw_request_info *info, | |
4432 | struct iw_param *srq, | |
4433 | char *extra) | |
1da177e4 LT |
4434 | { |
4435 | struct orinoco_private *priv = netdev_priv(dev); | |
4436 | int val = srq->value; | |
4437 | unsigned long flags; | |
4438 | ||
4439 | if (!priv->has_sensitivity) | |
4440 | return -EOPNOTSUPP; | |
4441 | ||
4442 | if ((val < 1) || (val > 3)) | |
4443 | return -EINVAL; | |
4444 | ||
4445 | if (orinoco_lock(priv, &flags) != 0) | |
4446 | return -EBUSY; | |
4447 | priv->ap_density = val; | |
4448 | orinoco_unlock(priv, &flags); | |
4449 | ||
620554e4 | 4450 | return -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
4451 | } |
4452 | ||
620554e4 CH |
4453 | static int orinoco_ioctl_setrts(struct net_device *dev, |
4454 | struct iw_request_info *info, | |
4455 | struct iw_param *rrq, | |
4456 | char *extra) | |
1da177e4 LT |
4457 | { |
4458 | struct orinoco_private *priv = netdev_priv(dev); | |
4459 | int val = rrq->value; | |
4460 | unsigned long flags; | |
4461 | ||
4462 | if (rrq->disabled) | |
4463 | val = 2347; | |
4464 | ||
4465 | if ( (val < 0) || (val > 2347) ) | |
4466 | return -EINVAL; | |
4467 | ||
4468 | if (orinoco_lock(priv, &flags) != 0) | |
4469 | return -EBUSY; | |
4470 | ||
4471 | priv->rts_thresh = val; | |
4472 | orinoco_unlock(priv, &flags); | |
4473 | ||
620554e4 CH |
4474 | return -EINPROGRESS; /* Call commit handler */ |
4475 | } | |
4476 | ||
4477 | static int orinoco_ioctl_getrts(struct net_device *dev, | |
4478 | struct iw_request_info *info, | |
4479 | struct iw_param *rrq, | |
4480 | char *extra) | |
4481 | { | |
4482 | struct orinoco_private *priv = netdev_priv(dev); | |
4483 | ||
4484 | rrq->value = priv->rts_thresh; | |
4485 | rrq->disabled = (rrq->value == 2347); | |
4486 | rrq->fixed = 1; | |
4487 | ||
1da177e4 LT |
4488 | return 0; |
4489 | } | |
4490 | ||
620554e4 CH |
4491 | static int orinoco_ioctl_setfrag(struct net_device *dev, |
4492 | struct iw_request_info *info, | |
4493 | struct iw_param *frq, | |
4494 | char *extra) | |
1da177e4 LT |
4495 | { |
4496 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 4497 | int err = -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
4498 | unsigned long flags; |
4499 | ||
4500 | if (orinoco_lock(priv, &flags) != 0) | |
4501 | return -EBUSY; | |
4502 | ||
4503 | if (priv->has_mwo) { | |
4504 | if (frq->disabled) | |
4505 | priv->mwo_robust = 0; | |
4506 | else { | |
4507 | if (frq->fixed) | |
4508 | printk(KERN_WARNING "%s: Fixed fragmentation is " | |
4509 | "not supported on this firmware. " | |
4510 | "Using MWO robust instead.\n", dev->name); | |
4511 | priv->mwo_robust = 1; | |
4512 | } | |
4513 | } else { | |
4514 | if (frq->disabled) | |
4515 | priv->frag_thresh = 2346; | |
4516 | else { | |
4517 | if ( (frq->value < 256) || (frq->value > 2346) ) | |
4518 | err = -EINVAL; | |
4519 | else | |
4520 | priv->frag_thresh = frq->value & ~0x1; /* must be even */ | |
4521 | } | |
4522 | } | |
4523 | ||
4524 | orinoco_unlock(priv, &flags); | |
4525 | ||
4526 | return err; | |
4527 | } | |
4528 | ||
620554e4 CH |
4529 | static int orinoco_ioctl_getfrag(struct net_device *dev, |
4530 | struct iw_request_info *info, | |
4531 | struct iw_param *frq, | |
4532 | char *extra) | |
1da177e4 LT |
4533 | { |
4534 | struct orinoco_private *priv = netdev_priv(dev); | |
4535 | hermes_t *hw = &priv->hw; | |
620554e4 | 4536 | int err; |
1da177e4 LT |
4537 | u16 val; |
4538 | unsigned long flags; | |
4539 | ||
4540 | if (orinoco_lock(priv, &flags) != 0) | |
4541 | return -EBUSY; | |
4542 | ||
4543 | if (priv->has_mwo) { | |
4544 | err = hermes_read_wordrec(hw, USER_BAP, | |
4545 | HERMES_RID_CNFMWOROBUST_AGERE, | |
4546 | &val); | |
4547 | if (err) | |
4548 | val = 0; | |
4549 | ||
4550 | frq->value = val ? 2347 : 0; | |
4551 | frq->disabled = ! val; | |
4552 | frq->fixed = 0; | |
4553 | } else { | |
4554 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, | |
4555 | &val); | |
4556 | if (err) | |
4557 | val = 0; | |
4558 | ||
4559 | frq->value = val; | |
4560 | frq->disabled = (val >= 2346); | |
4561 | frq->fixed = 1; | |
4562 | } | |
4563 | ||
4564 | orinoco_unlock(priv, &flags); | |
4565 | ||
4566 | return err; | |
4567 | } | |
4568 | ||
620554e4 CH |
4569 | static int orinoco_ioctl_setrate(struct net_device *dev, |
4570 | struct iw_request_info *info, | |
4571 | struct iw_param *rrq, | |
4572 | char *extra) | |
1da177e4 LT |
4573 | { |
4574 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
4575 | int ratemode = -1; |
4576 | int bitrate; /* 100s of kilobits */ | |
4577 | int i; | |
4578 | unsigned long flags; | |
4579 | ||
4580 | /* As the user space doesn't know our highest rate, it uses -1 | |
4581 | * to ask us to set the highest rate. Test it using "iwconfig | |
4582 | * ethX rate auto" - Jean II */ | |
4583 | if (rrq->value == -1) | |
4584 | bitrate = 110; | |
4585 | else { | |
4586 | if (rrq->value % 100000) | |
4587 | return -EINVAL; | |
4588 | bitrate = rrq->value / 100000; | |
4589 | } | |
4590 | ||
4591 | if ( (bitrate != 10) && (bitrate != 20) && | |
4592 | (bitrate != 55) && (bitrate != 110) ) | |
4593 | return -EINVAL; | |
4594 | ||
4595 | for (i = 0; i < BITRATE_TABLE_SIZE; i++) | |
4596 | if ( (bitrate_table[i].bitrate == bitrate) && | |
4597 | (bitrate_table[i].automatic == ! rrq->fixed) ) { | |
4598 | ratemode = i; | |
4599 | break; | |
4600 | } | |
4601 | ||
4602 | if (ratemode == -1) | |
4603 | return -EINVAL; | |
4604 | ||
4605 | if (orinoco_lock(priv, &flags) != 0) | |
4606 | return -EBUSY; | |
4607 | priv->bitratemode = ratemode; | |
4608 | orinoco_unlock(priv, &flags); | |
4609 | ||
620554e4 | 4610 | return -EINPROGRESS; |
1da177e4 LT |
4611 | } |
4612 | ||
620554e4 CH |
4613 | static int orinoco_ioctl_getrate(struct net_device *dev, |
4614 | struct iw_request_info *info, | |
4615 | struct iw_param *rrq, | |
4616 | char *extra) | |
1da177e4 LT |
4617 | { |
4618 | struct orinoco_private *priv = netdev_priv(dev); | |
4619 | hermes_t *hw = &priv->hw; | |
4620 | int err = 0; | |
4621 | int ratemode; | |
4622 | int i; | |
4623 | u16 val; | |
4624 | unsigned long flags; | |
4625 | ||
4626 | if (orinoco_lock(priv, &flags) != 0) | |
4627 | return -EBUSY; | |
4628 | ||
4629 | ratemode = priv->bitratemode; | |
4630 | ||
4631 | BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE)); | |
4632 | ||
4633 | rrq->value = bitrate_table[ratemode].bitrate * 100000; | |
4634 | rrq->fixed = ! bitrate_table[ratemode].automatic; | |
4635 | rrq->disabled = 0; | |
4636 | ||
4637 | /* If the interface is running we try to find more about the | |
4638 | current mode */ | |
4639 | if (netif_running(dev)) { | |
4640 | err = hermes_read_wordrec(hw, USER_BAP, | |
4641 | HERMES_RID_CURRENTTXRATE, &val); | |
4642 | if (err) | |
4643 | goto out; | |
4644 | ||
4645 | switch (priv->firmware_type) { | |
4646 | case FIRMWARE_TYPE_AGERE: /* Lucent style rate */ | |
4647 | /* Note : in Lucent firmware, the return value of | |
4648 | * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s, | |
4649 | * and therefore is totally different from the | |
4650 | * encoding of HERMES_RID_CNFTXRATECONTROL. | |
4651 | * Don't forget that 6Mb/s is really 5.5Mb/s */ | |
4652 | if (val == 6) | |
4653 | rrq->value = 5500000; | |
4654 | else | |
4655 | rrq->value = val * 1000000; | |
4656 | break; | |
4657 | case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */ | |
4658 | case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */ | |
4659 | for (i = 0; i < BITRATE_TABLE_SIZE; i++) | |
4660 | if (bitrate_table[i].intersil_txratectrl == val) { | |
4661 | ratemode = i; | |
4662 | break; | |
4663 | } | |
4664 | if (i >= BITRATE_TABLE_SIZE) | |
4665 | printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n", | |
4666 | dev->name, val); | |
4667 | ||
4668 | rrq->value = bitrate_table[ratemode].bitrate * 100000; | |
4669 | break; | |
4670 | default: | |
4671 | BUG(); | |
4672 | } | |
4673 | } | |
4674 | ||
4675 | out: | |
4676 | orinoco_unlock(priv, &flags); | |
4677 | ||
4678 | return err; | |
4679 | } | |
4680 | ||
620554e4 CH |
4681 | static int orinoco_ioctl_setpower(struct net_device *dev, |
4682 | struct iw_request_info *info, | |
4683 | struct iw_param *prq, | |
4684 | char *extra) | |
1da177e4 LT |
4685 | { |
4686 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 4687 | int err = -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
4688 | unsigned long flags; |
4689 | ||
4690 | if (orinoco_lock(priv, &flags) != 0) | |
4691 | return -EBUSY; | |
4692 | ||
4693 | if (prq->disabled) { | |
4694 | priv->pm_on = 0; | |
4695 | } else { | |
4696 | switch (prq->flags & IW_POWER_MODE) { | |
4697 | case IW_POWER_UNICAST_R: | |
4698 | priv->pm_mcast = 0; | |
4699 | priv->pm_on = 1; | |
4700 | break; | |
4701 | case IW_POWER_ALL_R: | |
4702 | priv->pm_mcast = 1; | |
4703 | priv->pm_on = 1; | |
4704 | break; | |
4705 | case IW_POWER_ON: | |
4706 | /* No flags : but we may have a value - Jean II */ | |
4707 | break; | |
4708 | default: | |
4709 | err = -EINVAL; | |
1da177e4 | 4710 | goto out; |
c08ad1e3 | 4711 | } |
1da177e4 LT |
4712 | |
4713 | if (prq->flags & IW_POWER_TIMEOUT) { | |
4714 | priv->pm_on = 1; | |
4715 | priv->pm_timeout = prq->value / 1000; | |
4716 | } | |
4717 | if (prq->flags & IW_POWER_PERIOD) { | |
4718 | priv->pm_on = 1; | |
4719 | priv->pm_period = prq->value / 1000; | |
4720 | } | |
4721 | /* It's valid to not have a value if we are just toggling | |
4722 | * the flags... Jean II */ | |
4723 | if(!priv->pm_on) { | |
4724 | err = -EINVAL; | |
4725 | goto out; | |
4726 | } | |
4727 | } | |
4728 | ||
4729 | out: | |
4730 | orinoco_unlock(priv, &flags); | |
4731 | ||
4732 | return err; | |
4733 | } | |
4734 | ||
620554e4 CH |
4735 | static int orinoco_ioctl_getpower(struct net_device *dev, |
4736 | struct iw_request_info *info, | |
4737 | struct iw_param *prq, | |
4738 | char *extra) | |
1da177e4 LT |
4739 | { |
4740 | struct orinoco_private *priv = netdev_priv(dev); | |
4741 | hermes_t *hw = &priv->hw; | |
4742 | int err = 0; | |
4743 | u16 enable, period, timeout, mcast; | |
4744 | unsigned long flags; | |
4745 | ||
4746 | if (orinoco_lock(priv, &flags) != 0) | |
4747 | return -EBUSY; | |
4748 | ||
4749 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable); | |
4750 | if (err) | |
4751 | goto out; | |
4752 | ||
4753 | err = hermes_read_wordrec(hw, USER_BAP, | |
4754 | HERMES_RID_CNFMAXSLEEPDURATION, &period); | |
4755 | if (err) | |
4756 | goto out; | |
4757 | ||
4758 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout); | |
4759 | if (err) | |
4760 | goto out; | |
4761 | ||
4762 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast); | |
4763 | if (err) | |
4764 | goto out; | |
4765 | ||
4766 | prq->disabled = !enable; | |
4767 | /* Note : by default, display the period */ | |
4768 | if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { | |
4769 | prq->flags = IW_POWER_TIMEOUT; | |
4770 | prq->value = timeout * 1000; | |
4771 | } else { | |
4772 | prq->flags = IW_POWER_PERIOD; | |
4773 | prq->value = period * 1000; | |
4774 | } | |
4775 | if (mcast) | |
4776 | prq->flags |= IW_POWER_ALL_R; | |
4777 | else | |
4778 | prq->flags |= IW_POWER_UNICAST_R; | |
4779 | ||
4780 | out: | |
4781 | orinoco_unlock(priv, &flags); | |
4782 | ||
4783 | return err; | |
4784 | } | |
4785 | ||
d03032af DK |
4786 | static int orinoco_ioctl_set_encodeext(struct net_device *dev, |
4787 | struct iw_request_info *info, | |
4788 | union iwreq_data *wrqu, | |
4789 | char *extra) | |
4790 | { | |
4791 | struct orinoco_private *priv = netdev_priv(dev); | |
4792 | struct iw_point *encoding = &wrqu->encoding; | |
4793 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
4794 | int idx, alg = ext->alg, set_key = 1; | |
4795 | unsigned long flags; | |
4796 | int err = -EINVAL; | |
4797 | u16 key_len; | |
4798 | ||
4799 | if (orinoco_lock(priv, &flags) != 0) | |
4800 | return -EBUSY; | |
4801 | ||
4802 | /* Determine and validate the key index */ | |
4803 | idx = encoding->flags & IW_ENCODE_INDEX; | |
4804 | if (idx) { | |
2c706002 | 4805 | if ((idx < 1) || (idx > 4)) |
d03032af DK |
4806 | goto out; |
4807 | idx--; | |
4808 | } else | |
4809 | idx = priv->tx_key; | |
4810 | ||
4811 | if (encoding->flags & IW_ENCODE_DISABLED) | |
4812 | alg = IW_ENCODE_ALG_NONE; | |
4813 | ||
4814 | if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) { | |
4815 | /* Clear any TKIP TX key we had */ | |
4816 | (void) orinoco_clear_tkip_key(priv, priv->tx_key); | |
4817 | } | |
4818 | ||
4819 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { | |
4820 | priv->tx_key = idx; | |
4821 | set_key = ((alg == IW_ENCODE_ALG_TKIP) || | |
4822 | (ext->key_len > 0)) ? 1 : 0; | |
4823 | } | |
4824 | ||
4825 | if (set_key) { | |
4826 | /* Set the requested key first */ | |
4827 | switch (alg) { | |
4828 | case IW_ENCODE_ALG_NONE: | |
4829 | priv->encode_alg = alg; | |
4830 | priv->keys[idx].len = 0; | |
4831 | break; | |
4832 | ||
4833 | case IW_ENCODE_ALG_WEP: | |
4834 | if (ext->key_len > SMALL_KEY_SIZE) | |
4835 | key_len = LARGE_KEY_SIZE; | |
4836 | else if (ext->key_len > 0) | |
4837 | key_len = SMALL_KEY_SIZE; | |
4838 | else | |
4839 | goto out; | |
4840 | ||
4841 | priv->encode_alg = alg; | |
4842 | priv->keys[idx].len = cpu_to_le16(key_len); | |
4843 | ||
4844 | key_len = min(ext->key_len, key_len); | |
4845 | ||
4846 | memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE); | |
4847 | memcpy(priv->keys[idx].data, ext->key, key_len); | |
4848 | break; | |
4849 | ||
4850 | case IW_ENCODE_ALG_TKIP: | |
4851 | { | |
4852 | hermes_t *hw = &priv->hw; | |
4853 | u8 *tkip_iv = NULL; | |
4854 | ||
4855 | if (!priv->has_wpa || | |
4856 | (ext->key_len > sizeof(priv->tkip_key[0]))) | |
4857 | goto out; | |
4858 | ||
4859 | priv->encode_alg = alg; | |
4860 | memset(&priv->tkip_key[idx], 0, | |
4861 | sizeof(priv->tkip_key[idx])); | |
4862 | memcpy(&priv->tkip_key[idx], ext->key, ext->key_len); | |
4863 | ||
4864 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) | |
4865 | tkip_iv = &ext->rx_seq[0]; | |
4866 | ||
4867 | err = __orinoco_hw_set_tkip_key(hw, idx, | |
4868 | ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, | |
4869 | (u8 *) &priv->tkip_key[idx], | |
4870 | tkip_iv, NULL); | |
4871 | if (err) | |
4872 | printk(KERN_ERR "%s: Error %d setting TKIP key" | |
4873 | "\n", dev->name, err); | |
4874 | ||
4875 | goto out; | |
4876 | } | |
4877 | default: | |
4878 | goto out; | |
4879 | } | |
4880 | } | |
4881 | err = -EINPROGRESS; | |
4882 | out: | |
4883 | orinoco_unlock(priv, &flags); | |
4884 | ||
4885 | return err; | |
4886 | } | |
4887 | ||
4888 | static int orinoco_ioctl_get_encodeext(struct net_device *dev, | |
4889 | struct iw_request_info *info, | |
4890 | union iwreq_data *wrqu, | |
4891 | char *extra) | |
4892 | { | |
4893 | struct orinoco_private *priv = netdev_priv(dev); | |
4894 | struct iw_point *encoding = &wrqu->encoding; | |
4895 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
4896 | int idx, max_key_len; | |
4897 | unsigned long flags; | |
4898 | int err; | |
4899 | ||
4900 | if (orinoco_lock(priv, &flags) != 0) | |
4901 | return -EBUSY; | |
4902 | ||
4903 | err = -EINVAL; | |
4904 | max_key_len = encoding->length - sizeof(*ext); | |
4905 | if (max_key_len < 0) | |
4906 | goto out; | |
4907 | ||
4908 | idx = encoding->flags & IW_ENCODE_INDEX; | |
4909 | if (idx) { | |
2c706002 | 4910 | if ((idx < 1) || (idx > 4)) |
d03032af DK |
4911 | goto out; |
4912 | idx--; | |
4913 | } else | |
4914 | idx = priv->tx_key; | |
4915 | ||
4916 | encoding->flags = idx + 1; | |
4917 | memset(ext, 0, sizeof(*ext)); | |
4918 | ||
4919 | ext->alg = priv->encode_alg; | |
4920 | switch (priv->encode_alg) { | |
4921 | case IW_ENCODE_ALG_NONE: | |
4922 | ext->key_len = 0; | |
4923 | encoding->flags |= IW_ENCODE_DISABLED; | |
4924 | break; | |
4925 | case IW_ENCODE_ALG_WEP: | |
75d31cf1 DK |
4926 | ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len), |
4927 | max_key_len); | |
d03032af DK |
4928 | memcpy(ext->key, priv->keys[idx].data, ext->key_len); |
4929 | encoding->flags |= IW_ENCODE_ENABLED; | |
4930 | break; | |
4931 | case IW_ENCODE_ALG_TKIP: | |
75d31cf1 DK |
4932 | ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key), |
4933 | max_key_len); | |
d03032af DK |
4934 | memcpy(ext->key, &priv->tkip_key[idx], ext->key_len); |
4935 | encoding->flags |= IW_ENCODE_ENABLED; | |
4936 | break; | |
4937 | } | |
4938 | ||
4939 | err = 0; | |
4940 | out: | |
4941 | orinoco_unlock(priv, &flags); | |
4942 | ||
4943 | return err; | |
4944 | } | |
4945 | ||
4946 | static int orinoco_ioctl_set_auth(struct net_device *dev, | |
4947 | struct iw_request_info *info, | |
4948 | union iwreq_data *wrqu, char *extra) | |
4949 | { | |
4950 | struct orinoco_private *priv = netdev_priv(dev); | |
4951 | hermes_t *hw = &priv->hw; | |
4952 | struct iw_param *param = &wrqu->param; | |
4953 | unsigned long flags; | |
4954 | int ret = -EINPROGRESS; | |
4955 | ||
4956 | if (orinoco_lock(priv, &flags) != 0) | |
4957 | return -EBUSY; | |
4958 | ||
4959 | switch (param->flags & IW_AUTH_INDEX) { | |
4960 | case IW_AUTH_WPA_VERSION: | |
4961 | case IW_AUTH_CIPHER_PAIRWISE: | |
4962 | case IW_AUTH_CIPHER_GROUP: | |
4963 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
4964 | case IW_AUTH_PRIVACY_INVOKED: | |
4965 | case IW_AUTH_DROP_UNENCRYPTED: | |
4966 | /* | |
4967 | * orinoco does not use these parameters | |
4968 | */ | |
4969 | break; | |
4970 | ||
4971 | case IW_AUTH_KEY_MGMT: | |
4972 | /* wl_lkm implies value 2 == PSK for Hermes I | |
4973 | * which ties in with WEXT | |
4974 | * no other hints tho :( | |
4975 | */ | |
4976 | priv->key_mgmt = param->value; | |
4977 | break; | |
4978 | ||
4979 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
4980 | /* When countermeasures are enabled, shut down the | |
4981 | * card; when disabled, re-enable the card. This must | |
4982 | * take effect immediately. | |
4983 | * | |
4984 | * TODO: Make sure that the EAPOL message is getting | |
4985 | * out before card disabled | |
4986 | */ | |
4987 | if (param->value) { | |
4988 | priv->tkip_cm_active = 1; | |
4989 | ret = hermes_enable_port(hw, 0); | |
4990 | } else { | |
4991 | priv->tkip_cm_active = 0; | |
4992 | ret = hermes_disable_port(hw, 0); | |
4993 | } | |
4994 | break; | |
4995 | ||
4996 | case IW_AUTH_80211_AUTH_ALG: | |
4997 | if (param->value & IW_AUTH_ALG_SHARED_KEY) | |
4998 | priv->wep_restrict = 1; | |
4999 | else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) | |
5000 | priv->wep_restrict = 0; | |
5001 | else | |
5002 | ret = -EINVAL; | |
5003 | break; | |
5004 | ||
5005 | case IW_AUTH_WPA_ENABLED: | |
5006 | if (priv->has_wpa) { | |
5007 | priv->wpa_enabled = param->value ? 1 : 0; | |
5008 | } else { | |
5009 | if (param->value) | |
5010 | ret = -EOPNOTSUPP; | |
5011 | /* else silently accept disable of WPA */ | |
5012 | priv->wpa_enabled = 0; | |
5013 | } | |
5014 | break; | |
5015 | ||
5016 | default: | |
5017 | ret = -EOPNOTSUPP; | |
5018 | } | |
5019 | ||
5020 | orinoco_unlock(priv, &flags); | |
5021 | return ret; | |
5022 | } | |
5023 | ||
5024 | static int orinoco_ioctl_get_auth(struct net_device *dev, | |
5025 | struct iw_request_info *info, | |
5026 | union iwreq_data *wrqu, char *extra) | |
5027 | { | |
5028 | struct orinoco_private *priv = netdev_priv(dev); | |
5029 | struct iw_param *param = &wrqu->param; | |
5030 | unsigned long flags; | |
5031 | int ret = 0; | |
5032 | ||
5033 | if (orinoco_lock(priv, &flags) != 0) | |
5034 | return -EBUSY; | |
5035 | ||
5036 | switch (param->flags & IW_AUTH_INDEX) { | |
5037 | case IW_AUTH_KEY_MGMT: | |
5038 | param->value = priv->key_mgmt; | |
5039 | break; | |
5040 | ||
5041 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
5042 | param->value = priv->tkip_cm_active; | |
5043 | break; | |
5044 | ||
5045 | case IW_AUTH_80211_AUTH_ALG: | |
5046 | if (priv->wep_restrict) | |
5047 | param->value = IW_AUTH_ALG_SHARED_KEY; | |
5048 | else | |
5049 | param->value = IW_AUTH_ALG_OPEN_SYSTEM; | |
5050 | break; | |
5051 | ||
5052 | case IW_AUTH_WPA_ENABLED: | |
5053 | param->value = priv->wpa_enabled; | |
5054 | break; | |
5055 | ||
5056 | default: | |
5057 | ret = -EOPNOTSUPP; | |
5058 | } | |
5059 | ||
5060 | orinoco_unlock(priv, &flags); | |
5061 | return ret; | |
5062 | } | |
5063 | ||
5064 | static int orinoco_ioctl_set_genie(struct net_device *dev, | |
5065 | struct iw_request_info *info, | |
5066 | union iwreq_data *wrqu, char *extra) | |
5067 | { | |
5068 | struct orinoco_private *priv = netdev_priv(dev); | |
5069 | u8 *buf; | |
5070 | unsigned long flags; | |
d03032af | 5071 | |
2c706002 JB |
5072 | /* cut off at IEEE80211_MAX_DATA_LEN */ |
5073 | if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) || | |
d03032af DK |
5074 | (wrqu->data.length && (extra == NULL))) |
5075 | return -EINVAL; | |
5076 | ||
d03032af DK |
5077 | if (wrqu->data.length) { |
5078 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); | |
7fe99c4e AB |
5079 | if (buf == NULL) |
5080 | return -ENOMEM; | |
d03032af DK |
5081 | |
5082 | memcpy(buf, extra, wrqu->data.length); | |
7fe99c4e AB |
5083 | } else |
5084 | buf = NULL; | |
5085 | ||
5086 | if (orinoco_lock(priv, &flags) != 0) { | |
5087 | kfree(buf); | |
5088 | return -EBUSY; | |
d03032af DK |
5089 | } |
5090 | ||
7fe99c4e AB |
5091 | kfree(priv->wpa_ie); |
5092 | priv->wpa_ie = buf; | |
5093 | priv->wpa_ie_len = wrqu->data.length; | |
5094 | ||
d03032af DK |
5095 | if (priv->wpa_ie) { |
5096 | /* Looks like wl_lkm wants to check the auth alg, and | |
5097 | * somehow pass it to the firmware. | |
5098 | * Instead it just calls the key mgmt rid | |
5099 | * - we do this in set auth. | |
5100 | */ | |
5101 | } | |
5102 | ||
d03032af | 5103 | orinoco_unlock(priv, &flags); |
7fe99c4e | 5104 | return 0; |
d03032af DK |
5105 | } |
5106 | ||
5107 | static int orinoco_ioctl_get_genie(struct net_device *dev, | |
5108 | struct iw_request_info *info, | |
5109 | union iwreq_data *wrqu, char *extra) | |
5110 | { | |
5111 | struct orinoco_private *priv = netdev_priv(dev); | |
5112 | unsigned long flags; | |
5113 | int err = 0; | |
5114 | ||
5115 | if (orinoco_lock(priv, &flags) != 0) | |
5116 | return -EBUSY; | |
5117 | ||
5118 | if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) { | |
5119 | wrqu->data.length = 0; | |
5120 | goto out; | |
5121 | } | |
5122 | ||
5123 | if (wrqu->data.length < priv->wpa_ie_len) { | |
5124 | err = -E2BIG; | |
5125 | goto out; | |
5126 | } | |
5127 | ||
5128 | wrqu->data.length = priv->wpa_ie_len; | |
5129 | memcpy(extra, priv->wpa_ie, priv->wpa_ie_len); | |
5130 | ||
5131 | out: | |
5132 | orinoco_unlock(priv, &flags); | |
5133 | return err; | |
5134 | } | |
5135 | ||
5136 | static int orinoco_ioctl_set_mlme(struct net_device *dev, | |
5137 | struct iw_request_info *info, | |
5138 | union iwreq_data *wrqu, char *extra) | |
5139 | { | |
5140 | struct orinoco_private *priv = netdev_priv(dev); | |
5141 | hermes_t *hw = &priv->hw; | |
5142 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | |
5143 | unsigned long flags; | |
5144 | int ret = 0; | |
5145 | ||
5146 | if (orinoco_lock(priv, &flags) != 0) | |
5147 | return -EBUSY; | |
5148 | ||
5149 | switch (mlme->cmd) { | |
5150 | case IW_MLME_DEAUTH: | |
5151 | /* silently ignore */ | |
5152 | break; | |
5153 | ||
5154 | case IW_MLME_DISASSOC: | |
5155 | { | |
5156 | struct { | |
5157 | u8 addr[ETH_ALEN]; | |
5158 | __le16 reason_code; | |
5159 | } __attribute__ ((packed)) buf; | |
5160 | ||
5161 | memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN); | |
5162 | buf.reason_code = cpu_to_le16(mlme->reason_code); | |
5163 | ret = HERMES_WRITE_RECORD(hw, USER_BAP, | |
5164 | HERMES_RID_CNFDISASSOCIATE, | |
5165 | &buf); | |
5166 | break; | |
5167 | } | |
5168 | default: | |
5169 | ret = -EOPNOTSUPP; | |
5170 | } | |
5171 | ||
5172 | orinoco_unlock(priv, &flags); | |
5173 | return ret; | |
5174 | } | |
5175 | ||
620554e4 CH |
5176 | static int orinoco_ioctl_getretry(struct net_device *dev, |
5177 | struct iw_request_info *info, | |
5178 | struct iw_param *rrq, | |
5179 | char *extra) | |
1da177e4 LT |
5180 | { |
5181 | struct orinoco_private *priv = netdev_priv(dev); | |
5182 | hermes_t *hw = &priv->hw; | |
5183 | int err = 0; | |
5184 | u16 short_limit, long_limit, lifetime; | |
5185 | unsigned long flags; | |
5186 | ||
5187 | if (orinoco_lock(priv, &flags) != 0) | |
5188 | return -EBUSY; | |
5189 | ||
5190 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT, | |
5191 | &short_limit); | |
5192 | if (err) | |
5193 | goto out; | |
5194 | ||
5195 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT, | |
5196 | &long_limit); | |
5197 | if (err) | |
5198 | goto out; | |
5199 | ||
5200 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME, | |
5201 | &lifetime); | |
5202 | if (err) | |
5203 | goto out; | |
5204 | ||
5205 | rrq->disabled = 0; /* Can't be disabled */ | |
5206 | ||
5207 | /* Note : by default, display the retry number */ | |
5208 | if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | |
5209 | rrq->flags = IW_RETRY_LIFETIME; | |
5210 | rrq->value = lifetime * 1000; /* ??? */ | |
5211 | } else { | |
5212 | /* By default, display the min number */ | |
eeec9f1a JT |
5213 | if ((rrq->flags & IW_RETRY_LONG)) { |
5214 | rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; | |
1da177e4 LT |
5215 | rrq->value = long_limit; |
5216 | } else { | |
5217 | rrq->flags = IW_RETRY_LIMIT; | |
5218 | rrq->value = short_limit; | |
5219 | if(short_limit != long_limit) | |
eeec9f1a | 5220 | rrq->flags |= IW_RETRY_SHORT; |
1da177e4 LT |
5221 | } |
5222 | } | |
5223 | ||
5224 | out: | |
5225 | orinoco_unlock(priv, &flags); | |
5226 | ||
5227 | return err; | |
5228 | } | |
5229 | ||
620554e4 CH |
5230 | static int orinoco_ioctl_reset(struct net_device *dev, |
5231 | struct iw_request_info *info, | |
5232 | void *wrqu, | |
5233 | char *extra) | |
5234 | { | |
5235 | struct orinoco_private *priv = netdev_priv(dev); | |
5236 | ||
5237 | if (! capable(CAP_NET_ADMIN)) | |
5238 | return -EPERM; | |
5239 | ||
5240 | if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) { | |
5241 | printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name); | |
5242 | ||
5243 | /* Firmware reset */ | |
c4028958 | 5244 | orinoco_reset(&priv->reset_work); |
620554e4 CH |
5245 | } else { |
5246 | printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name); | |
5247 | ||
5248 | schedule_work(&priv->reset_work); | |
5249 | } | |
5250 | ||
5251 | return 0; | |
5252 | } | |
5253 | ||
5254 | static int orinoco_ioctl_setibssport(struct net_device *dev, | |
5255 | struct iw_request_info *info, | |
5256 | void *wrqu, | |
5257 | char *extra) | |
5258 | ||
1da177e4 LT |
5259 | { |
5260 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 5261 | int val = *( (int *) extra ); |
1da177e4 LT |
5262 | unsigned long flags; |
5263 | ||
5264 | if (orinoco_lock(priv, &flags) != 0) | |
5265 | return -EBUSY; | |
5266 | ||
5267 | priv->ibss_port = val ; | |
5268 | ||
5269 | /* Actually update the mode we are using */ | |
5270 | set_port_type(priv); | |
5271 | ||
5272 | orinoco_unlock(priv, &flags); | |
620554e4 | 5273 | return -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
5274 | } |
5275 | ||
620554e4 CH |
5276 | static int orinoco_ioctl_getibssport(struct net_device *dev, |
5277 | struct iw_request_info *info, | |
5278 | void *wrqu, | |
5279 | char *extra) | |
1da177e4 LT |
5280 | { |
5281 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 5282 | int *val = (int *) extra; |
1da177e4 LT |
5283 | |
5284 | *val = priv->ibss_port; | |
1da177e4 LT |
5285 | return 0; |
5286 | } | |
5287 | ||
620554e4 CH |
5288 | static int orinoco_ioctl_setport3(struct net_device *dev, |
5289 | struct iw_request_info *info, | |
5290 | void *wrqu, | |
5291 | char *extra) | |
1da177e4 LT |
5292 | { |
5293 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 5294 | int val = *( (int *) extra ); |
1da177e4 LT |
5295 | int err = 0; |
5296 | unsigned long flags; | |
5297 | ||
5298 | if (orinoco_lock(priv, &flags) != 0) | |
5299 | return -EBUSY; | |
5300 | ||
5301 | switch (val) { | |
5302 | case 0: /* Try to do IEEE ad-hoc mode */ | |
5303 | if (! priv->has_ibss) { | |
5304 | err = -EINVAL; | |
5305 | break; | |
5306 | } | |
5307 | priv->prefer_port3 = 0; | |
5308 | ||
5309 | break; | |
5310 | ||
5311 | case 1: /* Try to do Lucent proprietary ad-hoc mode */ | |
5312 | if (! priv->has_port3) { | |
5313 | err = -EINVAL; | |
5314 | break; | |
5315 | } | |
5316 | priv->prefer_port3 = 1; | |
5317 | break; | |
5318 | ||
5319 | default: | |
5320 | err = -EINVAL; | |
5321 | } | |
5322 | ||
620554e4 | 5323 | if (! err) { |
1da177e4 LT |
5324 | /* Actually update the mode we are using */ |
5325 | set_port_type(priv); | |
620554e4 CH |
5326 | err = -EINPROGRESS; |
5327 | } | |
1da177e4 LT |
5328 | |
5329 | orinoco_unlock(priv, &flags); | |
5330 | ||
5331 | return err; | |
5332 | } | |
5333 | ||
620554e4 CH |
5334 | static int orinoco_ioctl_getport3(struct net_device *dev, |
5335 | struct iw_request_info *info, | |
5336 | void *wrqu, | |
5337 | char *extra) | |
5338 | { | |
5339 | struct orinoco_private *priv = netdev_priv(dev); | |
5340 | int *val = (int *) extra; | |
5341 | ||
5342 | *val = priv->prefer_port3; | |
5343 | return 0; | |
5344 | } | |
5345 | ||
5346 | static int orinoco_ioctl_setpreamble(struct net_device *dev, | |
5347 | struct iw_request_info *info, | |
5348 | void *wrqu, | |
5349 | char *extra) | |
1da177e4 LT |
5350 | { |
5351 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 | 5352 | unsigned long flags; |
620554e4 CH |
5353 | int val; |
5354 | ||
5355 | if (! priv->has_preamble) | |
5356 | return -EOPNOTSUPP; | |
5357 | ||
5358 | /* 802.11b has recently defined some short preamble. | |
5359 | * Basically, the Phy header has been reduced in size. | |
5360 | * This increase performance, especially at high rates | |
5361 | * (the preamble is transmitted at 1Mb/s), unfortunately | |
5362 | * this give compatibility troubles... - Jean II */ | |
5363 | val = *( (int *) extra ); | |
1da177e4 LT |
5364 | |
5365 | if (orinoco_lock(priv, &flags) != 0) | |
5366 | return -EBUSY; | |
5367 | ||
620554e4 CH |
5368 | if (val) |
5369 | priv->preamble = 1; | |
5370 | else | |
5371 | priv->preamble = 0; | |
5372 | ||
1da177e4 | 5373 | orinoco_unlock(priv, &flags); |
620554e4 CH |
5374 | |
5375 | return -EINPROGRESS; /* Call commit handler */ | |
5376 | } | |
5377 | ||
5378 | static int orinoco_ioctl_getpreamble(struct net_device *dev, | |
5379 | struct iw_request_info *info, | |
5380 | void *wrqu, | |
5381 | char *extra) | |
5382 | { | |
5383 | struct orinoco_private *priv = netdev_priv(dev); | |
5384 | int *val = (int *) extra; | |
5385 | ||
5386 | if (! priv->has_preamble) | |
5387 | return -EOPNOTSUPP; | |
5388 | ||
5389 | *val = priv->preamble; | |
1da177e4 LT |
5390 | return 0; |
5391 | } | |
5392 | ||
620554e4 CH |
5393 | /* ioctl interface to hermes_read_ltv() |
5394 | * To use with iwpriv, pass the RID as the token argument, e.g. | |
5395 | * iwpriv get_rid [0xfc00] | |
5396 | * At least Wireless Tools 25 is required to use iwpriv. | |
5397 | * For Wireless Tools 25 and 26 append "dummy" are the end. */ | |
5398 | static int orinoco_ioctl_getrid(struct net_device *dev, | |
5399 | struct iw_request_info *info, | |
5400 | struct iw_point *data, | |
5401 | char *extra) | |
5402 | { | |
5403 | struct orinoco_private *priv = netdev_priv(dev); | |
5404 | hermes_t *hw = &priv->hw; | |
5405 | int rid = data->flags; | |
5406 | u16 length; | |
5407 | int err; | |
5408 | unsigned long flags; | |
5409 | ||
5410 | /* It's a "get" function, but we don't want users to access the | |
5411 | * WEP key and other raw firmware data */ | |
5412 | if (! capable(CAP_NET_ADMIN)) | |
5413 | return -EPERM; | |
5414 | ||
5415 | if (rid < 0xfc00 || rid > 0xffff) | |
5416 | return -EINVAL; | |
5417 | ||
5418 | if (orinoco_lock(priv, &flags) != 0) | |
5419 | return -EBUSY; | |
5420 | ||
5421 | err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length, | |
5422 | extra); | |
5423 | if (err) | |
5424 | goto out; | |
5425 | ||
5426 | data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length), | |
5427 | MAX_RID_LEN); | |
5428 | ||
5429 | out: | |
5430 | orinoco_unlock(priv, &flags); | |
5431 | return err; | |
5432 | } | |
5433 | ||
17a1a887 | 5434 | /* Trigger a scan (look for other cells in the vicinity) */ |
95dd91fb CH |
5435 | static int orinoco_ioctl_setscan(struct net_device *dev, |
5436 | struct iw_request_info *info, | |
9930ccee | 5437 | struct iw_point *srq, |
95dd91fb | 5438 | char *extra) |
1da177e4 LT |
5439 | { |
5440 | struct orinoco_private *priv = netdev_priv(dev); | |
95dd91fb | 5441 | hermes_t *hw = &priv->hw; |
0753bba2 | 5442 | struct iw_scan_req *si = (struct iw_scan_req *) extra; |
1da177e4 | 5443 | int err = 0; |
1da177e4 LT |
5444 | unsigned long flags; |
5445 | ||
95dd91fb | 5446 | /* Note : you may have realised that, as this is a SET operation, |
7f927fcc | 5447 | * this is privileged and therefore a normal user can't |
95dd91fb CH |
5448 | * perform scanning. |
5449 | * This is not an error, while the device perform scanning, | |
5450 | * traffic doesn't flow, so it's a perfect DoS... | |
5451 | * Jean II */ | |
1da177e4 | 5452 | |
95dd91fb CH |
5453 | if (orinoco_lock(priv, &flags) != 0) |
5454 | return -EBUSY; | |
1da177e4 | 5455 | |
95dd91fb CH |
5456 | /* Scanning with port 0 disabled would fail */ |
5457 | if (!netif_running(dev)) { | |
5458 | err = -ENETDOWN; | |
5459 | goto out; | |
5460 | } | |
1da177e4 | 5461 | |
95dd91fb CH |
5462 | /* In monitor mode, the scan results are always empty. |
5463 | * Probe responses are passed to the driver as received | |
5464 | * frames and could be processed in software. */ | |
5465 | if (priv->iw_mode == IW_MODE_MONITOR) { | |
5466 | err = -EOPNOTSUPP; | |
5467 | goto out; | |
5468 | } | |
1da177e4 | 5469 | |
95dd91fb CH |
5470 | /* Note : because we don't lock out the irq handler, the way |
5471 | * we access scan variables in priv is critical. | |
5472 | * o scan_inprogress : not touched by irq handler | |
5473 | * o scan_mode : not touched by irq handler | |
95dd91fb CH |
5474 | * Before modifying anything on those variables, please think hard ! |
5475 | * Jean II */ | |
1da177e4 | 5476 | |
95dd91fb CH |
5477 | /* Save flags */ |
5478 | priv->scan_mode = srq->flags; | |
1da177e4 | 5479 | |
95dd91fb CH |
5480 | /* Always trigger scanning, even if it's in progress. |
5481 | * This way, if the info frame get lost, we will recover somewhat | |
5482 | * gracefully - Jean II */ | |
1da177e4 | 5483 | |
95dd91fb CH |
5484 | if (priv->has_hostscan) { |
5485 | switch (priv->firmware_type) { | |
5486 | case FIRMWARE_TYPE_SYMBOL: | |
5487 | err = hermes_write_wordrec(hw, USER_BAP, | |
5488 | HERMES_RID_CNFHOSTSCAN_SYMBOL, | |
5489 | HERMES_HOSTSCAN_SYMBOL_ONCE | | |
5490 | HERMES_HOSTSCAN_SYMBOL_BCAST); | |
5491 | break; | |
5492 | case FIRMWARE_TYPE_INTERSIL: { | |
d133ae4c | 5493 | __le16 req[3]; |
95dd91fb CH |
5494 | |
5495 | req[0] = cpu_to_le16(0x3fff); /* All channels */ | |
5496 | req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */ | |
5497 | req[2] = 0; /* Any ESSID */ | |
5498 | err = HERMES_WRITE_RECORD(hw, USER_BAP, | |
5499 | HERMES_RID_CNFHOSTSCAN, &req); | |
5500 | } | |
1da177e4 | 5501 | break; |
95dd91fb | 5502 | case FIRMWARE_TYPE_AGERE: |
0753bba2 DK |
5503 | if (priv->scan_mode & IW_SCAN_THIS_ESSID) { |
5504 | struct hermes_idstring idbuf; | |
5505 | size_t len = min(sizeof(idbuf.val), | |
5506 | (size_t) si->essid_len); | |
5507 | idbuf.len = cpu_to_le16(len); | |
5508 | memcpy(idbuf.val, si->essid, len); | |
5509 | ||
5510 | err = hermes_write_ltv(hw, USER_BAP, | |
5511 | HERMES_RID_CNFSCANSSID_AGERE, | |
5512 | HERMES_BYTES_TO_RECLEN(len + 2), | |
5513 | &idbuf); | |
5514 | } else | |
5515 | err = hermes_write_wordrec(hw, USER_BAP, | |
95dd91fb CH |
5516 | HERMES_RID_CNFSCANSSID_AGERE, |
5517 | 0); /* Any ESSID */ | |
5518 | if (err) | |
5519 | break; | |
1da177e4 | 5520 | |
01632fa4 DK |
5521 | if (priv->has_ext_scan) { |
5522 | /* Clear scan results at the start of | |
5523 | * an extended scan */ | |
5524 | orinoco_clear_scan_results(priv, | |
5525 | msecs_to_jiffies(15000)); | |
5526 | ||
5527 | /* TODO: Is this available on older firmware? | |
5528 | * Can we use it to scan specific channels | |
5529 | * for IW_SCAN_THIS_FREQ? */ | |
5530 | err = hermes_write_wordrec(hw, USER_BAP, | |
5531 | HERMES_RID_CNFSCANCHANNELS2GHZ, | |
5532 | 0x7FFF); | |
5533 | if (err) | |
5534 | goto out; | |
5535 | ||
5536 | err = hermes_inquire(hw, | |
5537 | HERMES_INQ_CHANNELINFO); | |
5538 | } else | |
5539 | err = hermes_inquire(hw, HERMES_INQ_SCAN); | |
1da177e4 LT |
5540 | break; |
5541 | } | |
95dd91fb CH |
5542 | } else |
5543 | err = hermes_inquire(hw, HERMES_INQ_SCAN); | |
1da177e4 | 5544 | |
95dd91fb CH |
5545 | /* One more client */ |
5546 | if (! err) | |
5547 | priv->scan_inprogress = 1; | |
1da177e4 | 5548 | |
95dd91fb CH |
5549 | out: |
5550 | orinoco_unlock(priv, &flags); | |
5551 | return err; | |
5552 | } | |
1da177e4 | 5553 | |
1e3428e9 DW |
5554 | #define MAX_CUSTOM_LEN 64 |
5555 | ||
95dd91fb | 5556 | /* Translate scan data returned from the card to a card independant |
17a1a887 | 5557 | * format that the Wireless Tools will understand - Jean II */ |
1e3428e9 | 5558 | static inline char *orinoco_translate_scan(struct net_device *dev, |
ccc58057 | 5559 | struct iw_request_info *info, |
1e3428e9 DW |
5560 | char *current_ev, |
5561 | char *end_buf, | |
5562 | union hermes_scan_info *bss, | |
dfe1bafd | 5563 | unsigned long last_scanned) |
95dd91fb CH |
5564 | { |
5565 | struct orinoco_private *priv = netdev_priv(dev); | |
95dd91fb CH |
5566 | u16 capabilities; |
5567 | u16 channel; | |
5568 | struct iw_event iwe; /* Temporary buffer */ | |
1e3428e9 DW |
5569 | char custom[MAX_CUSTOM_LEN]; |
5570 | ||
17a1a887 DK |
5571 | memset(&iwe, 0, sizeof(iwe)); |
5572 | ||
1e3428e9 DW |
5573 | /* First entry *MUST* be the AP MAC address */ |
5574 | iwe.cmd = SIOCGIWAP; | |
5575 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
5576 | memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN); | |
ccc58057 DM |
5577 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
5578 | &iwe, IW_EV_ADDR_LEN); | |
1e3428e9 DW |
5579 | |
5580 | /* Other entries will be displayed in the order we give them */ | |
5581 | ||
5582 | /* Add the ESSID */ | |
5583 | iwe.u.data.length = le16_to_cpu(bss->a.essid_len); | |
5584 | if (iwe.u.data.length > 32) | |
5585 | iwe.u.data.length = 32; | |
5586 | iwe.cmd = SIOCGIWESSID; | |
5587 | iwe.u.data.flags = 1; | |
ccc58057 DM |
5588 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
5589 | &iwe, bss->a.essid); | |
1e3428e9 DW |
5590 | |
5591 | /* Add mode */ | |
5592 | iwe.cmd = SIOCGIWMODE; | |
5593 | capabilities = le16_to_cpu(bss->a.capabilities); | |
17a1a887 DK |
5594 | if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) { |
5595 | if (capabilities & WLAN_CAPABILITY_ESS) | |
1e3428e9 | 5596 | iwe.u.mode = IW_MODE_MASTER; |
95dd91fb | 5597 | else |
1e3428e9 | 5598 | iwe.u.mode = IW_MODE_ADHOC; |
ccc58057 DM |
5599 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
5600 | &iwe, IW_EV_UINT_LEN); | |
95dd91fb | 5601 | } |
1da177e4 | 5602 | |
1e3428e9 DW |
5603 | channel = bss->s.channel; |
5604 | if ((channel >= 1) && (channel <= NUM_CHANNELS)) { | |
17a1a887 | 5605 | /* Add channel and frequency */ |
1e3428e9 | 5606 | iwe.cmd = SIOCGIWFREQ; |
17a1a887 DK |
5607 | iwe.u.freq.m = channel; |
5608 | iwe.u.freq.e = 0; | |
5609 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | |
5610 | &iwe, IW_EV_FREQ_LEN); | |
5611 | ||
1e3428e9 DW |
5612 | iwe.u.freq.m = channel_frequency[channel-1] * 100000; |
5613 | iwe.u.freq.e = 1; | |
ccc58057 | 5614 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
1e3428e9 | 5615 | &iwe, IW_EV_FREQ_LEN); |
95dd91fb | 5616 | } |
1da177e4 | 5617 | |
17a1a887 | 5618 | /* Add quality statistics. level and noise in dB. No link quality */ |
1e3428e9 | 5619 | iwe.cmd = IWEVQUAL; |
17a1a887 | 5620 | iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID; |
1e3428e9 DW |
5621 | iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95; |
5622 | iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95; | |
5623 | /* Wireless tools prior to 27.pre22 will show link quality | |
5624 | * anyway, so we provide a reasonable value. */ | |
5625 | if (iwe.u.qual.level > iwe.u.qual.noise) | |
5626 | iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise; | |
5627 | else | |
5628 | iwe.u.qual.qual = 0; | |
ccc58057 DM |
5629 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
5630 | &iwe, IW_EV_QUAL_LEN); | |
1da177e4 | 5631 | |
1e3428e9 DW |
5632 | /* Add encryption capability */ |
5633 | iwe.cmd = SIOCGIWENCODE; | |
17a1a887 | 5634 | if (capabilities & WLAN_CAPABILITY_PRIVACY) |
1e3428e9 DW |
5635 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
5636 | else | |
5637 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
5638 | iwe.u.data.length = 0; | |
ccc58057 | 5639 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
17a1a887 | 5640 | &iwe, NULL); |
1e3428e9 DW |
5641 | |
5642 | /* Bit rate is not available in Lucent/Agere firmwares */ | |
5643 | if (priv->firmware_type != FIRMWARE_TYPE_AGERE) { | |
ccc58057 | 5644 | char *current_val = current_ev + iwe_stream_lcp_len(info); |
1e3428e9 DW |
5645 | int i; |
5646 | int step; | |
1da177e4 | 5647 | |
1e3428e9 DW |
5648 | if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL) |
5649 | step = 2; | |
95dd91fb | 5650 | else |
1e3428e9 DW |
5651 | step = 1; |
5652 | ||
5653 | iwe.cmd = SIOCGIWRATE; | |
5654 | /* Those two flags are ignored... */ | |
5655 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | |
5656 | /* Max 10 values */ | |
5657 | for (i = 0; i < 10; i += step) { | |
5658 | /* NULL terminated */ | |
5659 | if (bss->p.rates[i] == 0x0) | |
5660 | break; | |
5661 | /* Bit rate given in 500 kb/s units (+ 0x80) */ | |
17a1a887 DK |
5662 | iwe.u.bitrate.value = |
5663 | ((bss->p.rates[i] & 0x7f) * 500000); | |
ccc58057 DM |
5664 | current_val = iwe_stream_add_value(info, current_ev, |
5665 | current_val, | |
1e3428e9 DW |
5666 | end_buf, &iwe, |
5667 | IW_EV_PARAM_LEN); | |
95dd91fb | 5668 | } |
1e3428e9 | 5669 | /* Check if we added any event */ |
ccc58057 | 5670 | if ((current_val - current_ev) > iwe_stream_lcp_len(info)) |
1e3428e9 | 5671 | current_ev = current_val; |
95dd91fb | 5672 | } |
1e3428e9 | 5673 | |
17a1a887 DK |
5674 | /* Beacon interval */ |
5675 | iwe.cmd = IWEVCUSTOM; | |
5676 | iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN, | |
5677 | "bcn_int=%d", | |
5678 | le16_to_cpu(bss->a.beacon_interv)); | |
5679 | if (iwe.u.data.length) | |
5680 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5681 | &iwe, custom); | |
5682 | ||
5683 | /* Capabilites */ | |
5684 | iwe.cmd = IWEVCUSTOM; | |
5685 | iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN, | |
5686 | "capab=0x%04x", | |
5687 | capabilities); | |
5688 | if (iwe.u.data.length) | |
5689 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5690 | &iwe, custom); | |
5691 | ||
5692 | /* Add EXTRA: Age to display seconds since last beacon/probe response | |
5693 | * for given network. */ | |
5694 | iwe.cmd = IWEVCUSTOM; | |
5695 | iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN, | |
5696 | " Last beacon: %dms ago", | |
5697 | jiffies_to_msecs(jiffies - last_scanned)); | |
5698 | if (iwe.u.data.length) | |
5699 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5700 | &iwe, custom); | |
5701 | ||
1e3428e9 | 5702 | return current_ev; |
95dd91fb | 5703 | } |
1da177e4 | 5704 | |
01632fa4 DK |
5705 | static inline char *orinoco_translate_ext_scan(struct net_device *dev, |
5706 | struct iw_request_info *info, | |
5707 | char *current_ev, | |
5708 | char *end_buf, | |
5709 | struct agere_ext_scan_info *bss, | |
dfe1bafd | 5710 | unsigned long last_scanned) |
01632fa4 DK |
5711 | { |
5712 | u16 capabilities; | |
5713 | u16 channel; | |
5714 | struct iw_event iwe; /* Temporary buffer */ | |
5715 | char custom[MAX_CUSTOM_LEN]; | |
5716 | u8 *ie; | |
5717 | ||
5718 | memset(&iwe, 0, sizeof(iwe)); | |
5719 | ||
5720 | /* First entry *MUST* be the AP MAC address */ | |
5721 | iwe.cmd = SIOCGIWAP; | |
5722 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
5723 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); | |
5724 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | |
5725 | &iwe, IW_EV_ADDR_LEN); | |
5726 | ||
5727 | /* Other entries will be displayed in the order we give them */ | |
5728 | ||
5729 | /* Add the ESSID */ | |
5730 | ie = bss->data; | |
5731 | iwe.u.data.length = ie[1]; | |
5732 | if (iwe.u.data.length) { | |
5733 | if (iwe.u.data.length > 32) | |
5734 | iwe.u.data.length = 32; | |
5735 | iwe.cmd = SIOCGIWESSID; | |
5736 | iwe.u.data.flags = 1; | |
5737 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5738 | &iwe, &ie[2]); | |
5739 | } | |
5740 | ||
5741 | /* Add mode */ | |
5742 | capabilities = le16_to_cpu(bss->capabilities); | |
5743 | if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) { | |
5744 | iwe.cmd = SIOCGIWMODE; | |
5745 | if (capabilities & WLAN_CAPABILITY_ESS) | |
5746 | iwe.u.mode = IW_MODE_MASTER; | |
5747 | else | |
5748 | iwe.u.mode = IW_MODE_ADHOC; | |
5749 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | |
5750 | &iwe, IW_EV_UINT_LEN); | |
5751 | } | |
5752 | ||
2c706002 | 5753 | ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS); |
01632fa4 DK |
5754 | channel = ie ? ie[2] : 0; |
5755 | if ((channel >= 1) && (channel <= NUM_CHANNELS)) { | |
5756 | /* Add channel and frequency */ | |
5757 | iwe.cmd = SIOCGIWFREQ; | |
5758 | iwe.u.freq.m = channel; | |
5759 | iwe.u.freq.e = 0; | |
5760 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | |
5761 | &iwe, IW_EV_FREQ_LEN); | |
5762 | ||
5763 | iwe.u.freq.m = channel_frequency[channel-1] * 100000; | |
5764 | iwe.u.freq.e = 1; | |
5765 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | |
5766 | &iwe, IW_EV_FREQ_LEN); | |
5767 | } | |
5768 | ||
5769 | /* Add quality statistics. level and noise in dB. No link quality */ | |
5770 | iwe.cmd = IWEVQUAL; | |
5771 | iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID; | |
5772 | iwe.u.qual.level = bss->level - 0x95; | |
5773 | iwe.u.qual.noise = bss->noise - 0x95; | |
5774 | /* Wireless tools prior to 27.pre22 will show link quality | |
5775 | * anyway, so we provide a reasonable value. */ | |
5776 | if (iwe.u.qual.level > iwe.u.qual.noise) | |
5777 | iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise; | |
5778 | else | |
5779 | iwe.u.qual.qual = 0; | |
5780 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | |
5781 | &iwe, IW_EV_QUAL_LEN); | |
5782 | ||
5783 | /* Add encryption capability */ | |
5784 | iwe.cmd = SIOCGIWENCODE; | |
5785 | if (capabilities & WLAN_CAPABILITY_PRIVACY) | |
5786 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | |
5787 | else | |
5788 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
5789 | iwe.u.data.length = 0; | |
5790 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5791 | &iwe, NULL); | |
5792 | ||
5793 | /* WPA IE */ | |
5794 | ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data)); | |
5795 | if (ie) { | |
5796 | iwe.cmd = IWEVGENIE; | |
5797 | iwe.u.data.length = ie[1] + 2; | |
5798 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5799 | &iwe, ie); | |
5800 | } | |
5801 | ||
5802 | /* RSN IE */ | |
2c706002 | 5803 | ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN); |
01632fa4 DK |
5804 | if (ie) { |
5805 | iwe.cmd = IWEVGENIE; | |
5806 | iwe.u.data.length = ie[1] + 2; | |
5807 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5808 | &iwe, ie); | |
5809 | } | |
5810 | ||
2c706002 | 5811 | ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES); |
01632fa4 DK |
5812 | if (ie) { |
5813 | char *p = current_ev + iwe_stream_lcp_len(info); | |
5814 | int i; | |
5815 | ||
5816 | iwe.cmd = SIOCGIWRATE; | |
5817 | /* Those two flags are ignored... */ | |
5818 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | |
5819 | ||
5820 | for (i = 2; i < (ie[1] + 2); i++) { | |
5821 | iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000); | |
5822 | p = iwe_stream_add_value(info, current_ev, p, end_buf, | |
5823 | &iwe, IW_EV_PARAM_LEN); | |
5824 | } | |
5825 | /* Check if we added any event */ | |
5826 | if (p > (current_ev + iwe_stream_lcp_len(info))) | |
5827 | current_ev = p; | |
5828 | } | |
5829 | ||
5830 | /* Timestamp */ | |
5831 | iwe.cmd = IWEVCUSTOM; | |
75d31cf1 DK |
5832 | iwe.u.data.length = |
5833 | snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx", | |
5834 | (unsigned long long) le64_to_cpu(bss->timestamp)); | |
01632fa4 DK |
5835 | if (iwe.u.data.length) |
5836 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5837 | &iwe, custom); | |
5838 | ||
5839 | /* Beacon interval */ | |
5840 | iwe.cmd = IWEVCUSTOM; | |
5841 | iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN, | |
5842 | "bcn_int=%d", | |
5843 | le16_to_cpu(bss->beacon_interval)); | |
5844 | if (iwe.u.data.length) | |
5845 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5846 | &iwe, custom); | |
5847 | ||
5848 | /* Capabilites */ | |
5849 | iwe.cmd = IWEVCUSTOM; | |
5850 | iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN, | |
5851 | "capab=0x%04x", | |
5852 | capabilities); | |
5853 | if (iwe.u.data.length) | |
5854 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5855 | &iwe, custom); | |
5856 | ||
5857 | /* Add EXTRA: Age to display seconds since last beacon/probe response | |
5858 | * for given network. */ | |
5859 | iwe.cmd = IWEVCUSTOM; | |
5860 | iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN, | |
5861 | " Last beacon: %dms ago", | |
5862 | jiffies_to_msecs(jiffies - last_scanned)); | |
5863 | if (iwe.u.data.length) | |
5864 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
5865 | &iwe, custom); | |
5866 | ||
5867 | return current_ev; | |
5868 | } | |
5869 | ||
95dd91fb CH |
5870 | /* Return results of a scan */ |
5871 | static int orinoco_ioctl_getscan(struct net_device *dev, | |
5872 | struct iw_request_info *info, | |
5873 | struct iw_point *srq, | |
5874 | char *extra) | |
5875 | { | |
5876 | struct orinoco_private *priv = netdev_priv(dev); | |
5877 | int err = 0; | |
5878 | unsigned long flags; | |
1e3428e9 | 5879 | char *current_ev = extra; |
1da177e4 | 5880 | |
95dd91fb CH |
5881 | if (orinoco_lock(priv, &flags) != 0) |
5882 | return -EBUSY; | |
1da177e4 | 5883 | |
1e3428e9 DW |
5884 | if (priv->scan_inprogress) { |
5885 | /* Important note : we don't want to block the caller | |
5886 | * until results are ready for various reasons. | |
5887 | * First, managing wait queues is complex and racy. | |
5888 | * Second, we grab some rtnetlink lock before comming | |
5889 | * here (in dev_ioctl()). | |
5890 | * Third, we generate an Wireless Event, so the | |
5891 | * caller can wait itself on that - Jean II */ | |
5892 | err = -EAGAIN; | |
5893 | goto out; | |
5894 | } | |
95dd91fb | 5895 | |
01632fa4 DK |
5896 | if (priv->has_ext_scan) { |
5897 | struct xbss_element *bss; | |
5898 | ||
5899 | list_for_each_entry(bss, &priv->bss_list, list) { | |
5900 | /* Translate this entry to WE format */ | |
5901 | current_ev = | |
5902 | orinoco_translate_ext_scan(dev, info, | |
5903 | current_ev, | |
5904 | extra + srq->length, | |
5905 | &bss->bss, | |
5906 | bss->last_scanned); | |
5907 | ||
5908 | /* Check if there is space for one more entry */ | |
5909 | if ((extra + srq->length - current_ev) | |
5910 | <= IW_EV_ADDR_LEN) { | |
5911 | /* Ask user space to try again with a | |
5912 | * bigger buffer */ | |
5913 | err = -E2BIG; | |
5914 | goto out; | |
5915 | } | |
5916 | } | |
5917 | ||
5918 | } else { | |
5919 | struct bss_element *bss; | |
5920 | ||
5921 | list_for_each_entry(bss, &priv->bss_list, list) { | |
5922 | /* Translate this entry to WE format */ | |
5923 | current_ev = orinoco_translate_scan(dev, info, | |
5924 | current_ev, | |
5925 | extra + srq->length, | |
5926 | &bss->bss, | |
5927 | bss->last_scanned); | |
5928 | ||
5929 | /* Check if there is space for one more entry */ | |
5930 | if ((extra + srq->length - current_ev) | |
5931 | <= IW_EV_ADDR_LEN) { | |
5932 | /* Ask user space to try again with a | |
5933 | * bigger buffer */ | |
5934 | err = -E2BIG; | |
5935 | goto out; | |
5936 | } | |
70817c40 | 5937 | } |
95dd91fb | 5938 | } |
1e3428e9 DW |
5939 | |
5940 | srq->length = (current_ev - extra); | |
5941 | srq->flags = (__u16) priv->scan_mode; | |
5942 | ||
5943 | out: | |
95dd91fb CH |
5944 | orinoco_unlock(priv, &flags); |
5945 | return err; | |
5946 | } | |
1da177e4 | 5947 | |
620554e4 CH |
5948 | /* Commit handler, called after set operations */ |
5949 | static int orinoco_ioctl_commit(struct net_device *dev, | |
5950 | struct iw_request_info *info, | |
5951 | void *wrqu, | |
5952 | char *extra) | |
1da177e4 LT |
5953 | { |
5954 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 5955 | struct hermes *hw = &priv->hw; |
1da177e4 | 5956 | unsigned long flags; |
620554e4 | 5957 | int err = 0; |
1da177e4 | 5958 | |
620554e4 CH |
5959 | if (!priv->open) |
5960 | return 0; | |
1da177e4 | 5961 | |
620554e4 | 5962 | if (priv->broken_disableport) { |
c4028958 | 5963 | orinoco_reset(&priv->reset_work); |
620554e4 CH |
5964 | return 0; |
5965 | } | |
1da177e4 | 5966 | |
620554e4 CH |
5967 | if (orinoco_lock(priv, &flags) != 0) |
5968 | return err; | |
1da177e4 | 5969 | |
620554e4 CH |
5970 | err = hermes_disable_port(hw, 0); |
5971 | if (err) { | |
5972 | printk(KERN_WARNING "%s: Unable to disable port " | |
5973 | "while reconfiguring card\n", dev->name); | |
5974 | priv->broken_disableport = 1; | |
5975 | goto out; | |
5976 | } | |
1da177e4 | 5977 | |
620554e4 CH |
5978 | err = __orinoco_program_rids(dev); |
5979 | if (err) { | |
5980 | printk(KERN_WARNING "%s: Unable to reconfigure card\n", | |
5981 | dev->name); | |
5982 | goto out; | |
5983 | } | |
1da177e4 | 5984 | |
620554e4 CH |
5985 | err = hermes_enable_port(hw, 0); |
5986 | if (err) { | |
5987 | printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n", | |
5988 | dev->name); | |
5989 | goto out; | |
5990 | } | |
1da177e4 | 5991 | |
620554e4 CH |
5992 | out: |
5993 | if (err) { | |
5994 | printk(KERN_WARNING "%s: Resetting instead...\n", dev->name); | |
1da177e4 | 5995 | schedule_work(&priv->reset_work); |
620554e4 CH |
5996 | err = 0; |
5997 | } | |
1da177e4 | 5998 | |
620554e4 CH |
5999 | orinoco_unlock(priv, &flags); |
6000 | return err; | |
6001 | } | |
1da177e4 | 6002 | |
620554e4 CH |
6003 | static const struct iw_priv_args orinoco_privtab[] = { |
6004 | { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" }, | |
6005 | { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" }, | |
6006 | { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
6007 | 0, "set_port3" }, | |
6008 | { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
6009 | "get_port3" }, | |
6010 | { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
6011 | 0, "set_preamble" }, | |
6012 | { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
6013 | "get_preamble" }, | |
6014 | { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
6015 | 0, "set_ibssport" }, | |
6016 | { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
6017 | "get_ibssport" }, | |
6018 | { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN, | |
6019 | "get_rid" }, | |
6020 | }; | |
1da177e4 | 6021 | |
1da177e4 | 6022 | |
620554e4 CH |
6023 | /* |
6024 | * Structures to export the Wireless Handlers | |
6025 | */ | |
1da177e4 | 6026 | |
409644a9 DK |
6027 | #define STD_IW_HANDLER(id, func) \ |
6028 | [IW_IOCTL_IDX(id)] = (iw_handler) func | |
620554e4 | 6029 | static const iw_handler orinoco_handler[] = { |
409644a9 DK |
6030 | STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit), |
6031 | STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname), | |
6032 | STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq), | |
6033 | STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq), | |
6034 | STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode), | |
6035 | STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode), | |
6036 | STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens), | |
6037 | STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens), | |
6038 | STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange), | |
6039 | STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy), | |
6040 | STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy), | |
6041 | STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy), | |
6042 | STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy), | |
6043 | STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap), | |
6044 | STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap), | |
6045 | STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan), | |
6046 | STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan), | |
6047 | STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid), | |
6048 | STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid), | |
6049 | STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick), | |
6050 | STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick), | |
6051 | STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate), | |
6052 | STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate), | |
6053 | STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts), | |
6054 | STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts), | |
6055 | STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag), | |
6056 | STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag), | |
6057 | STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry), | |
6058 | STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode), | |
6059 | STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode), | |
6060 | STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower), | |
6061 | STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower), | |
d03032af DK |
6062 | STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie), |
6063 | STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie), | |
6064 | STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme), | |
6065 | STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth), | |
6066 | STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth), | |
6067 | STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext), | |
6068 | STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext), | |
620554e4 | 6069 | }; |
1da177e4 | 6070 | |
1da177e4 | 6071 | |
620554e4 CH |
6072 | /* |
6073 | Added typecasting since we no longer use iwreq_data -- Moustafa | |
6074 | */ | |
6075 | static const iw_handler orinoco_private_handler[] = { | |
6b9b97ce PH |
6076 | [0] = (iw_handler) orinoco_ioctl_reset, |
6077 | [1] = (iw_handler) orinoco_ioctl_reset, | |
6078 | [2] = (iw_handler) orinoco_ioctl_setport3, | |
6079 | [3] = (iw_handler) orinoco_ioctl_getport3, | |
6080 | [4] = (iw_handler) orinoco_ioctl_setpreamble, | |
6081 | [5] = (iw_handler) orinoco_ioctl_getpreamble, | |
6082 | [6] = (iw_handler) orinoco_ioctl_setibssport, | |
6083 | [7] = (iw_handler) orinoco_ioctl_getibssport, | |
6084 | [9] = (iw_handler) orinoco_ioctl_getrid, | |
620554e4 | 6085 | }; |
1da177e4 | 6086 | |
620554e4 CH |
6087 | static const struct iw_handler_def orinoco_handler_def = { |
6088 | .num_standard = ARRAY_SIZE(orinoco_handler), | |
6089 | .num_private = ARRAY_SIZE(orinoco_private_handler), | |
6090 | .num_private_args = ARRAY_SIZE(orinoco_privtab), | |
6091 | .standard = orinoco_handler, | |
6092 | .private = orinoco_private_handler, | |
6093 | .private_args = orinoco_privtab, | |
343c686c | 6094 | .get_wireless_stats = orinoco_get_wireless_stats, |
620554e4 | 6095 | }; |
1da177e4 | 6096 | |
1fab2e8b CH |
6097 | static void orinoco_get_drvinfo(struct net_device *dev, |
6098 | struct ethtool_drvinfo *info) | |
6099 | { | |
6100 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 | 6101 | |
1fab2e8b CH |
6102 | strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1); |
6103 | strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1); | |
6104 | strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1); | |
43cb76d9 | 6105 | if (dev->dev.parent) |
fb28ad35 | 6106 | strncpy(info->bus_info, dev_name(dev->dev.parent), |
1fab2e8b CH |
6107 | sizeof(info->bus_info) - 1); |
6108 | else | |
6109 | snprintf(info->bus_info, sizeof(info->bus_info) - 1, | |
6110 | "PCMCIA %p", priv->hw.iobase); | |
1da177e4 LT |
6111 | } |
6112 | ||
7282d491 | 6113 | static const struct ethtool_ops orinoco_ethtool_ops = { |
1fab2e8b CH |
6114 | .get_drvinfo = orinoco_get_drvinfo, |
6115 | .get_link = ethtool_op_get_link, | |
6116 | }; | |
1da177e4 | 6117 | |
1da177e4 LT |
6118 | /********************************************************************/ |
6119 | /* Module initialization */ | |
6120 | /********************************************************************/ | |
6121 | ||
6122 | EXPORT_SYMBOL(alloc_orinocodev); | |
6123 | EXPORT_SYMBOL(free_orinocodev); | |
6124 | ||
6125 | EXPORT_SYMBOL(__orinoco_up); | |
6126 | EXPORT_SYMBOL(__orinoco_down); | |
1da177e4 LT |
6127 | EXPORT_SYMBOL(orinoco_reinit_firmware); |
6128 | ||
6129 | EXPORT_SYMBOL(orinoco_interrupt); | |
6130 | ||
6131 | /* Can't be declared "const" or the whole __initdata section will | |
6132 | * become const */ | |
6133 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION | |
6134 | " (David Gibson <hermes@gibson.dropbear.id.au>, " | |
6135 | "Pavel Roskin <proski@gnu.org>, et al)"; | |
6136 | ||
6137 | static int __init init_orinoco(void) | |
6138 | { | |
6139 | printk(KERN_DEBUG "%s\n", version); | |
6140 | return 0; | |
6141 | } | |
6142 | ||
6143 | static void __exit exit_orinoco(void) | |
6144 | { | |
6145 | } | |
6146 | ||
6147 | module_init(init_orinoco); | |
6148 | module_exit(exit_orinoco); |