orinoco: Extend hermes_dld routines for Agere firmware
[deliverable/linux.git] / drivers / net / wireless / orinoco.c
CommitLineData
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>
1da177e4 82#include <linux/netdevice.h>
1da177e4 83#include <linux/etherdevice.h>
1fab2e8b 84#include <linux/ethtool.h>
9c974fb1 85#include <linux/if_arp.h>
1da177e4 86#include <linux/wireless.h>
620554e4 87#include <net/iw_handler.h>
5d558b7f 88#include <net/ieee80211.h>
1da177e4 89
1da177e4
LT
90#include "hermes_rid.h"
91#include "orinoco.h"
1da177e4
LT
92
93/********************************************************************/
94/* Module information */
95/********************************************************************/
96
97MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
98MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
99MODULE_LICENSE("Dual MPL/GPL");
100
101/* Level of debugging. Used in the macros in orinoco.h */
102#ifdef ORINOCO_DEBUG
103int orinoco_debug = ORINOCO_DEBUG;
104module_param(orinoco_debug, int, 0644);
105MODULE_PARM_DESC(orinoco_debug, "Debug level");
106EXPORT_SYMBOL(orinoco_debug);
107#endif
108
109static int suppress_linkstatus; /* = 0 */
110module_param(suppress_linkstatus, bool, 0644);
111MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
7bb7c3a3
DG
112static int ignore_disconnect; /* = 0 */
113module_param(ignore_disconnect, int, 0644);
114MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
1da177e4 115
98c4cae1
CH
116static int force_monitor; /* = 0 */
117module_param(force_monitor, int, 0644);
118MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
119
1da177e4
LT
120/********************************************************************/
121/* Compile time configuration and compatibility stuff */
122/********************************************************************/
123
124/* We do this this way to avoid ifdefs in the actual code */
125#ifdef WIRELESS_SPY
343c686c 126#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
1da177e4
LT
127#else
128#define SPY_NUMBER(priv) 0
129#endif /* WIRELESS_SPY */
130
131/********************************************************************/
132/* Internal constants */
133/********************************************************************/
134
95dd91fb
CH
135/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
136static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
137#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
138
1da177e4 139#define ORINOCO_MIN_MTU 256
b453872c 140#define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
1da177e4
LT
141
142#define SYMBOL_MAX_VER_LEN (14)
143#define USER_BAP 0
144#define IRQ_BAP 1
145#define MAX_IRQLOOPS_PER_IRQ 10
146#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
147 * how many events the
148 * device could
149 * legitimately generate */
150#define SMALL_KEY_SIZE 5
151#define LARGE_KEY_SIZE 13
152#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
153
154#define DUMMY_FID 0xFFFF
155
156/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
157 HERMES_MAX_MULTICAST : 0)*/
158#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
159
160#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
161 | HERMES_EV_TX | HERMES_EV_TXEXC \
162 | HERMES_EV_WTERR | HERMES_EV_INFO \
163 | HERMES_EV_INFDROP )
164
620554e4
CH
165#define MAX_RID_LEN 1024
166
167static const struct iw_handler_def orinoco_handler_def;
7282d491 168static const struct ethtool_ops orinoco_ethtool_ops;
620554e4 169
1da177e4
LT
170/********************************************************************/
171/* Data tables */
172/********************************************************************/
173
174/* The frequency of each channel in MHz */
175static const long channel_frequency[] = {
176 2412, 2417, 2422, 2427, 2432, 2437, 2442,
177 2447, 2452, 2457, 2462, 2467, 2472, 2484
178};
179#define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
180
181/* This tables gives the actual meanings of the bitrate IDs returned
182 * by the firmware. */
183static struct {
184 int bitrate; /* in 100s of kilobits */
185 int automatic;
186 u16 agere_txratectrl;
187 u16 intersil_txratectrl;
188} bitrate_table[] = {
189 {110, 1, 3, 15}, /* Entry 0 is the default */
190 {10, 0, 1, 1},
191 {10, 1, 1, 1},
192 {20, 0, 2, 2},
193 {20, 1, 6, 3},
194 {55, 0, 4, 4},
195 {55, 1, 7, 7},
196 {110, 0, 5, 8},
197};
198#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
199
200/********************************************************************/
201/* Data types */
202/********************************************************************/
203
30c2d3b4
PR
204/* Beginning of the Tx descriptor, used in TxExc handling */
205struct hermes_txexc_data {
206 struct hermes_tx_descriptor desc;
d133ae4c
PR
207 __le16 frame_ctl;
208 __le16 duration_id;
95dd91fb 209 u8 addr1[ETH_ALEN];
1da177e4
LT
210} __attribute__ ((packed));
211
8f2abf44 212/* Rx frame header except compatibility 802.3 header */
1da177e4 213struct hermes_rx_descriptor {
8f2abf44 214 /* Control */
d133ae4c
PR
215 __le16 status;
216 __le32 time;
1da177e4
LT
217 u8 silence;
218 u8 signal;
219 u8 rate;
220 u8 rxflow;
d133ae4c 221 __le32 reserved;
8f2abf44
CH
222
223 /* 802.11 header */
d133ae4c
PR
224 __le16 frame_ctl;
225 __le16 duration_id;
8f2abf44
CH
226 u8 addr1[ETH_ALEN];
227 u8 addr2[ETH_ALEN];
228 u8 addr3[ETH_ALEN];
d133ae4c 229 __le16 seq_ctl;
8f2abf44
CH
230 u8 addr4[ETH_ALEN];
231
232 /* Data length */
d133ae4c 233 __le16 data_len;
1da177e4
LT
234} __attribute__ ((packed));
235
236/********************************************************************/
237/* Function prototypes */
238/********************************************************************/
239
1da177e4
LT
240static int __orinoco_program_rids(struct net_device *dev);
241static void __orinoco_set_multicast_list(struct net_device *dev);
1da177e4
LT
242
243/********************************************************************/
244/* Internal helper functions */
245/********************************************************************/
246
247static inline void set_port_type(struct orinoco_private *priv)
248{
249 switch (priv->iw_mode) {
250 case IW_MODE_INFRA:
251 priv->port_type = 1;
252 priv->createibss = 0;
253 break;
254 case IW_MODE_ADHOC:
255 if (priv->prefer_port3) {
256 priv->port_type = 3;
257 priv->createibss = 0;
258 } else {
259 priv->port_type = priv->ibss_port;
260 priv->createibss = 1;
261 }
262 break;
98c4cae1
CH
263 case IW_MODE_MONITOR:
264 priv->port_type = 3;
265 priv->createibss = 0;
266 break;
1da177e4
LT
267 default:
268 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
269 priv->ndev->name);
270 }
271}
272
1e3428e9
DW
273#define ORINOCO_MAX_BSS_COUNT 64
274static int orinoco_bss_data_allocate(struct orinoco_private *priv)
275{
276 if (priv->bss_data)
277 return 0;
278
279 priv->bss_data =
280 kzalloc(ORINOCO_MAX_BSS_COUNT * sizeof(bss_element), GFP_KERNEL);
281 if (!priv->bss_data) {
282 printk(KERN_WARNING "Out of memory allocating beacons");
283 return -ENOMEM;
284 }
285 return 0;
286}
287
288static void orinoco_bss_data_free(struct orinoco_private *priv)
289{
290 kfree(priv->bss_data);
291 priv->bss_data = NULL;
292}
293
294static void orinoco_bss_data_init(struct orinoco_private *priv)
295{
296 int i;
297
298 INIT_LIST_HEAD(&priv->bss_free_list);
299 INIT_LIST_HEAD(&priv->bss_list);
300 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
301 list_add_tail(&priv->bss_data[i].list, &priv->bss_free_list);
302}
303
1da177e4
LT
304/********************************************************************/
305/* Device methods */
306/********************************************************************/
307
308static int orinoco_open(struct net_device *dev)
309{
310 struct orinoco_private *priv = netdev_priv(dev);
311 unsigned long flags;
312 int err;
313
314 if (orinoco_lock(priv, &flags) != 0)
315 return -EBUSY;
316
317 err = __orinoco_up(dev);
318
319 if (! err)
320 priv->open = 1;
321
322 orinoco_unlock(priv, &flags);
323
324 return err;
325}
326
ad8f451b 327static int orinoco_stop(struct net_device *dev)
1da177e4
LT
328{
329 struct orinoco_private *priv = netdev_priv(dev);
330 int err = 0;
331
332 /* We mustn't use orinoco_lock() here, because we need to be
333 able to close the interface even if hw_unavailable is set
334 (e.g. as we're released after a PC Card removal) */
335 spin_lock_irq(&priv->lock);
336
337 priv->open = 0;
338
339 err = __orinoco_down(dev);
340
341 spin_unlock_irq(&priv->lock);
342
343 return err;
344}
345
346static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
347{
348 struct orinoco_private *priv = netdev_priv(dev);
349
350 return &priv->stats;
351}
352
353static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
354{
355 struct orinoco_private *priv = netdev_priv(dev);
356 hermes_t *hw = &priv->hw;
357 struct iw_statistics *wstats = &priv->wstats;
e67d9d9d 358 int err;
1da177e4
LT
359 unsigned long flags;
360
361 if (! netif_device_present(dev)) {
362 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
363 dev->name);
364 return NULL; /* FIXME: Can we do better than this? */
365 }
366
e67d9d9d
DG
367 /* If busy, return the old stats. Returning NULL may cause
368 * the interface to disappear from /proc/net/wireless */
1da177e4 369 if (orinoco_lock(priv, &flags) != 0)
e67d9d9d
DG
370 return wstats;
371
372 /* We can't really wait for the tallies inquiry command to
373 * complete, so we just use the previous results and trigger
374 * a new tallies inquiry command for next time - Jean II */
375 /* FIXME: Really we should wait for the inquiry to come back -
376 * as it is the stats we give don't make a whole lot of sense.
377 * Unfortunately, it's not clear how to do that within the
378 * wireless extensions framework: I think we're in user
379 * context, but a lock seems to be held by the time we get in
380 * here so we're not safe to sleep here. */
381 hermes_inquire(hw, HERMES_INQ_TALLIES);
1da177e4
LT
382
383 if (priv->iw_mode == IW_MODE_ADHOC) {
384 memset(&wstats->qual, 0, sizeof(wstats->qual));
385 /* If a spy address is defined, we report stats of the
386 * first spy address - Jean II */
387 if (SPY_NUMBER(priv)) {
343c686c
PR
388 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
389 wstats->qual.level = priv->spy_data.spy_stat[0].level;
390 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
391 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
1da177e4
LT
392 }
393 } else {
394 struct {
a208c4e1 395 __le16 qual, signal, noise, unused;
1da177e4
LT
396 } __attribute__ ((packed)) cq;
397
398 err = HERMES_READ_RECORD(hw, USER_BAP,
399 HERMES_RID_COMMSQUALITY, &cq);
e67d9d9d
DG
400
401 if (!err) {
402 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
403 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
404 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
405 wstats->qual.updated = 7;
406 }
1da177e4
LT
407 }
408
1da177e4 409 orinoco_unlock(priv, &flags);
1da177e4
LT
410 return wstats;
411}
412
413static void orinoco_set_multicast_list(struct net_device *dev)
414{
415 struct orinoco_private *priv = netdev_priv(dev);
416 unsigned long flags;
417
418 if (orinoco_lock(priv, &flags) != 0) {
419 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
420 "called when hw_unavailable\n", dev->name);
421 return;
422 }
423
424 __orinoco_set_multicast_list(dev);
425 orinoco_unlock(priv, &flags);
426}
427
428static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
429{
430 struct orinoco_private *priv = netdev_priv(dev);
431
432 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
433 return -EINVAL;
434
b453872c 435 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
1da177e4
LT
436 (priv->nicbuf_size - ETH_HLEN) )
437 return -EINVAL;
438
439 dev->mtu = new_mtu;
440
441 return 0;
442}
443
444/********************************************************************/
445/* Tx path */
446/********************************************************************/
447
448static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
449{
450 struct orinoco_private *priv = netdev_priv(dev);
451 struct net_device_stats *stats = &priv->stats;
452 hermes_t *hw = &priv->hw;
453 int err = 0;
454 u16 txfid = priv->txfid;
1da177e4 455 struct ethhdr *eh;
a28dc81d 456 int data_off;
1da177e4
LT
457 struct hermes_tx_descriptor desc;
458 unsigned long flags;
459
1da177e4
LT
460 if (! netif_running(dev)) {
461 printk(KERN_ERR "%s: Tx on stopped device!\n",
462 dev->name);
b34b867e 463 return NETDEV_TX_BUSY;
1da177e4
LT
464 }
465
466 if (netif_queue_stopped(dev)) {
467 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
468 dev->name);
b34b867e 469 return NETDEV_TX_BUSY;
1da177e4
LT
470 }
471
472 if (orinoco_lock(priv, &flags) != 0) {
473 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
474 dev->name);
b34b867e 475 return NETDEV_TX_BUSY;
1da177e4
LT
476 }
477
98c4cae1 478 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
1da177e4
LT
479 /* Oops, the firmware hasn't established a connection,
480 silently drop the packet (this seems to be the
481 safest approach). */
470e2aa6 482 goto drop;
1da177e4
LT
483 }
484
8d5be088 485 /* Check packet length */
a28dc81d 486 if (skb->len < ETH_HLEN)
470e2aa6 487 goto drop;
1da177e4
LT
488
489 eh = (struct ethhdr *)skb->data;
490
491 memset(&desc, 0, sizeof(desc));
492 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
493 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
494 if (err) {
495 if (net_ratelimit())
496 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
497 "to BAP\n", dev->name, err);
470e2aa6 498 goto busy;
1da177e4
LT
499 }
500
501 /* Clear the 802.11 header and data length fields - some
502 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
503 * if this isn't done. */
504 hermes_clear_words(hw, HERMES_DATA0,
505 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
506
507 /* Encapsulate Ethernet-II frames */
508 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
a28dc81d
PR
509 struct header_struct {
510 struct ethhdr eth; /* 802.3 header */
511 u8 encap[6]; /* 802.2 header */
512 } __attribute__ ((packed)) hdr;
513
514 /* Strip destination and source from the data */
515 skb_pull(skb, 2 * ETH_ALEN);
516 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
517
518 /* And move them to a separate header */
519 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
520 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
521 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
522
523 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
524 txfid, HERMES_802_3_OFFSET);
1da177e4
LT
525 if (err) {
526 if (net_ratelimit())
527 printk(KERN_ERR "%s: Error %d writing packet "
528 "header to BAP\n", dev->name, err);
470e2aa6 529 goto busy;
1da177e4
LT
530 }
531 } else { /* IEEE 802.3 frame */
1da177e4 532 data_off = HERMES_802_3_OFFSET;
1da177e4
LT
533 }
534
a28dc81d 535 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
1da177e4
LT
536 txfid, data_off);
537 if (err) {
538 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
539 dev->name, err);
470e2aa6 540 goto busy;
1da177e4
LT
541 }
542
543 /* Finally, we actually initiate the send */
544 netif_stop_queue(dev);
545
546 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
547 txfid, NULL);
548 if (err) {
549 netif_start_queue(dev);
c367c21c
AM
550 if (net_ratelimit())
551 printk(KERN_ERR "%s: Error %d transmitting packet\n",
552 dev->name, err);
470e2aa6 553 goto busy;
1da177e4
LT
554 }
555
556 dev->trans_start = jiffies;
a28dc81d 557 stats->tx_bytes += data_off + skb->len;
470e2aa6 558 goto ok;
1da177e4 559
470e2aa6
PR
560 drop:
561 stats->tx_errors++;
562 stats->tx_dropped++;
1da177e4 563
470e2aa6
PR
564 ok:
565 orinoco_unlock(priv, &flags);
1da177e4 566 dev_kfree_skb(skb);
b34b867e 567 return NETDEV_TX_OK;
1da177e4 568
470e2aa6 569 busy:
2c1bd260
JB
570 if (err == -EIO)
571 schedule_work(&priv->reset_work);
1da177e4 572 orinoco_unlock(priv, &flags);
b34b867e 573 return NETDEV_TX_BUSY;
1da177e4
LT
574}
575
576static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
577{
578 struct orinoco_private *priv = netdev_priv(dev);
579 u16 fid = hermes_read_regn(hw, ALLOCFID);
580
581 if (fid != priv->txfid) {
582 if (fid != DUMMY_FID)
583 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
584 dev->name, fid);
585 return;
586 }
587
588 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
589}
590
591static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
592{
593 struct orinoco_private *priv = netdev_priv(dev);
594 struct net_device_stats *stats = &priv->stats;
595
596 stats->tx_packets++;
597
598 netif_wake_queue(dev);
599
600 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
601}
602
603static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
604{
605 struct orinoco_private *priv = netdev_priv(dev);
606 struct net_device_stats *stats = &priv->stats;
607 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
d133ae4c 608 u16 status;
30c2d3b4 609 struct hermes_txexc_data hdr;
1da177e4
LT
610 int err = 0;
611
612 if (fid == DUMMY_FID)
613 return; /* Nothing's really happened */
614
48ca7038 615 /* Read part of the frame header - we need status and addr1 */
95dd91fb 616 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
30c2d3b4 617 sizeof(struct hermes_txexc_data),
95dd91fb
CH
618 fid, 0);
619
620 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
621 stats->tx_errors++;
622
1da177e4
LT
623 if (err) {
624 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
625 "(FID=%04X error %d)\n",
626 dev->name, fid, err);
95dd91fb 627 return;
1da177e4
LT
628 }
629
95dd91fb
CH
630 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
631 err, fid);
632
633 /* We produce a TXDROP event only for retry or lifetime
634 * exceeded, because that's the only status that really mean
635 * that this particular node went away.
636 * Other errors means that *we* screwed up. - Jean II */
30c2d3b4 637 status = le16_to_cpu(hdr.desc.status);
d133ae4c 638 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
95dd91fb
CH
639 union iwreq_data wrqu;
640
641 /* Copy 802.11 dest address.
642 * We use the 802.11 header because the frame may
643 * not be 802.3 or may be mangled...
644 * In Ad-Hoc mode, it will be the node address.
645 * In managed mode, it will be most likely the AP addr
646 * User space will figure out how to convert it to
647 * whatever it needs (IP address or else).
648 * - Jean II */
649 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
650 wrqu.addr.sa_family = ARPHRD_ETHER;
651
652 /* Send event to user space */
653 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
654 }
1da177e4
LT
655
656 netif_wake_queue(dev);
1da177e4
LT
657}
658
659static void orinoco_tx_timeout(struct net_device *dev)
660{
661 struct orinoco_private *priv = netdev_priv(dev);
662 struct net_device_stats *stats = &priv->stats;
663 struct hermes *hw = &priv->hw;
664
665 printk(KERN_WARNING "%s: Tx timeout! "
666 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
667 dev->name, hermes_read_regn(hw, ALLOCFID),
668 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
669
670 stats->tx_errors++;
671
672 schedule_work(&priv->reset_work);
673}
674
675/********************************************************************/
676/* Rx path (data frames) */
677/********************************************************************/
678
679/* Does the frame have a SNAP header indicating it should be
680 * de-encapsulated to Ethernet-II? */
681static inline int is_ethersnap(void *_hdr)
682{
683 u8 *hdr = _hdr;
684
685 /* We de-encapsulate all packets which, a) have SNAP headers
686 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
687 * and where b) the OUI of the SNAP header is 00:00:00 or
688 * 00:00:f8 - we need both because different APs appear to use
689 * different OUIs for some reason */
690 return (memcmp(hdr, &encaps_hdr, 5) == 0)
691 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
692}
693
694static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
695 int level, int noise)
696{
343c686c
PR
697 struct iw_quality wstats;
698 wstats.level = level - 0x95;
699 wstats.noise = noise - 0x95;
700 wstats.qual = (level > noise) ? (level - noise) : 0;
701 wstats.updated = 7;
702 /* Update spy records */
703 wireless_spy_update(dev, mac, &wstats);
1da177e4
LT
704}
705
706static void orinoco_stat_gather(struct net_device *dev,
707 struct sk_buff *skb,
708 struct hermes_rx_descriptor *desc)
709{
710 struct orinoco_private *priv = netdev_priv(dev);
711
712 /* Using spy support with lots of Rx packets, like in an
713 * infrastructure (AP), will really slow down everything, because
714 * the MAC address must be compared to each entry of the spy list.
715 * If the user really asks for it (set some address in the
716 * spy list), we do it, but he will pay the price.
717 * Note that to get here, you need both WIRELESS_SPY
718 * compiled in AND some addresses in the list !!!
719 */
720 /* Note : gcc will optimise the whole section away if
721 * WIRELESS_SPY is not defined... - Jean II */
722 if (SPY_NUMBER(priv)) {
98e399f8 723 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
1da177e4
LT
724 desc->signal, desc->silence);
725 }
726}
727
98c4cae1
CH
728/*
729 * orinoco_rx_monitor - handle received monitor frames.
730 *
731 * Arguments:
732 * dev network device
733 * rxfid received FID
734 * desc rx descriptor of the frame
735 *
736 * Call context: interrupt
737 */
738static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
739 struct hermes_rx_descriptor *desc)
740{
741 u32 hdrlen = 30; /* return full header by default */
742 u32 datalen = 0;
743 u16 fc;
744 int err;
745 int len;
746 struct sk_buff *skb;
747 struct orinoco_private *priv = netdev_priv(dev);
748 struct net_device_stats *stats = &priv->stats;
749 hermes_t *hw = &priv->hw;
750
751 len = le16_to_cpu(desc->data_len);
752
753 /* Determine the size of the header and the data */
754 fc = le16_to_cpu(desc->frame_ctl);
755 switch (fc & IEEE80211_FCTL_FTYPE) {
756 case IEEE80211_FTYPE_DATA:
757 if ((fc & IEEE80211_FCTL_TODS)
758 && (fc & IEEE80211_FCTL_FROMDS))
759 hdrlen = 30;
760 else
761 hdrlen = 24;
762 datalen = len;
763 break;
764 case IEEE80211_FTYPE_MGMT:
765 hdrlen = 24;
766 datalen = len;
767 break;
768 case IEEE80211_FTYPE_CTL:
769 switch (fc & IEEE80211_FCTL_STYPE) {
770 case IEEE80211_STYPE_PSPOLL:
771 case IEEE80211_STYPE_RTS:
772 case IEEE80211_STYPE_CFEND:
773 case IEEE80211_STYPE_CFENDACK:
774 hdrlen = 16;
775 break;
776 case IEEE80211_STYPE_CTS:
777 case IEEE80211_STYPE_ACK:
778 hdrlen = 10;
779 break;
780 }
781 break;
782 default:
783 /* Unknown frame type */
784 break;
785 }
786
787 /* sanity check the length */
788 if (datalen > IEEE80211_DATA_LEN + 12) {
789 printk(KERN_DEBUG "%s: oversized monitor frame, "
790 "data length = %d\n", dev->name, datalen);
98c4cae1
CH
791 stats->rx_length_errors++;
792 goto update_stats;
793 }
794
795 skb = dev_alloc_skb(hdrlen + datalen);
796 if (!skb) {
797 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
798 dev->name);
bb6e093d 799 goto update_stats;
98c4cae1
CH
800 }
801
802 /* Copy the 802.11 header to the skb */
803 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
459a98ed 804 skb_reset_mac_header(skb);
98c4cae1
CH
805
806 /* If any, copy the data from the card to the skb */
807 if (datalen > 0) {
808 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
809 ALIGN(datalen, 2), rxfid,
810 HERMES_802_2_OFFSET);
811 if (err) {
812 printk(KERN_ERR "%s: error %d reading monitor frame\n",
813 dev->name, err);
814 goto drop;
815 }
816 }
817
818 skb->dev = dev;
819 skb->ip_summed = CHECKSUM_NONE;
820 skb->pkt_type = PACKET_OTHERHOST;
821 skb->protocol = __constant_htons(ETH_P_802_2);
822
823 dev->last_rx = jiffies;
824 stats->rx_packets++;
825 stats->rx_bytes += skb->len;
826
827 netif_rx(skb);
828 return;
829
830 drop:
831 dev_kfree_skb_irq(skb);
832 update_stats:
833 stats->rx_errors++;
834 stats->rx_dropped++;
835}
836
1da177e4
LT
837static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
838{
839 struct orinoco_private *priv = netdev_priv(dev);
840 struct net_device_stats *stats = &priv->stats;
841 struct iw_statistics *wstats = &priv->wstats;
842 struct sk_buff *skb = NULL;
8f2abf44
CH
843 u16 rxfid, status, fc;
844 int length;
1da177e4 845 struct hermes_rx_descriptor desc;
8f2abf44 846 struct ethhdr *hdr;
1da177e4
LT
847 int err;
848
849 rxfid = hermes_read_regn(hw, RXFID);
850
851 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
852 rxfid, 0);
853 if (err) {
854 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
855 "Frame dropped.\n", dev->name, err);
98c4cae1 856 goto update_stats;
1da177e4
LT
857 }
858
859 status = le16_to_cpu(desc.status);
860
98c4cae1
CH
861 if (status & HERMES_RXSTAT_BADCRC) {
862 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
863 dev->name);
864 stats->rx_crc_errors++;
865 goto update_stats;
1da177e4
LT
866 }
867
98c4cae1
CH
868 /* Handle frames in monitor mode */
869 if (priv->iw_mode == IW_MODE_MONITOR) {
870 orinoco_rx_monitor(dev, rxfid, &desc);
871 return;
872 }
1da177e4 873
98c4cae1
CH
874 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
875 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
876 dev->name);
877 wstats->discard.code++;
878 goto update_stats;
1da177e4
LT
879 }
880
8f2abf44
CH
881 length = le16_to_cpu(desc.data_len);
882 fc = le16_to_cpu(desc.frame_ctl);
883
1da177e4
LT
884 /* Sanity checks */
885 if (length < 3) { /* No for even an 802.2 LLC header */
886 /* At least on Symbol firmware with PCF we get quite a
887 lot of these legitimately - Poll frames with no
888 data. */
98c4cae1 889 return;
1da177e4 890 }
b453872c 891 if (length > IEEE80211_DATA_LEN) {
1da177e4
LT
892 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
893 dev->name, length);
894 stats->rx_length_errors++;
98c4cae1 895 goto update_stats;
1da177e4
LT
896 }
897
898 /* We need space for the packet data itself, plus an ethernet
899 header, plus 2 bytes so we can align the IP header on a
900 32bit boundary, plus 1 byte so we can read in odd length
901 packets from the card, which has an IO granularity of 16
902 bits */
903 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
904 if (!skb) {
905 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
906 dev->name);
98c4cae1 907 goto update_stats;
1da177e4
LT
908 }
909
8f2abf44
CH
910 /* We'll prepend the header, so reserve space for it. The worst
911 case is no decapsulation, when 802.3 header is prepended and
912 nothing is removed. 2 is for aligning the IP header. */
913 skb_reserve(skb, ETH_HLEN + 2);
914
915 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
916 ALIGN(length, 2), rxfid,
917 HERMES_802_2_OFFSET);
918 if (err) {
919 printk(KERN_ERR "%s: error %d reading frame. "
920 "Frame dropped.\n", dev->name, err);
8f2abf44
CH
921 goto drop;
922 }
1da177e4
LT
923
924 /* Handle decapsulation
925 * In most cases, the firmware tell us about SNAP frames.
926 * For some reason, the SNAP frames sent by LinkSys APs
927 * are not properly recognised by most firmwares.
928 * So, check ourselves */
8f2abf44
CH
929 if (length >= ENCAPS_OVERHEAD &&
930 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
931 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
932 is_ethersnap(skb->data))) {
1da177e4
LT
933 /* These indicate a SNAP within 802.2 LLC within
934 802.11 frame which we'll need to de-encapsulate to
935 the original EthernetII frame. */
8f2abf44 936 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
1da177e4 937 } else {
8f2abf44
CH
938 /* 802.3 frame - prepend 802.3 header as is */
939 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
940 hdr->h_proto = htons(length);
1da177e4 941 }
8f2abf44
CH
942 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
943 if (fc & IEEE80211_FCTL_FROMDS)
944 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
945 else
946 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
1da177e4
LT
947
948 dev->last_rx = jiffies;
1da177e4
LT
949 skb->protocol = eth_type_trans(skb, dev);
950 skb->ip_summed = CHECKSUM_NONE;
8f2abf44
CH
951 if (fc & IEEE80211_FCTL_TODS)
952 skb->pkt_type = PACKET_OTHERHOST;
1da177e4
LT
953
954 /* Process the wireless stats if needed */
955 orinoco_stat_gather(dev, skb, &desc);
956
957 /* Pass the packet to the networking stack */
958 netif_rx(skb);
959 stats->rx_packets++;
960 stats->rx_bytes += length;
961
962 return;
963
964 drop:
98c4cae1
CH
965 dev_kfree_skb_irq(skb);
966 update_stats:
967 stats->rx_errors++;
1da177e4 968 stats->rx_dropped++;
1da177e4
LT
969}
970
971/********************************************************************/
972/* Rx path (info frames) */
973/********************************************************************/
974
975static void print_linkstatus(struct net_device *dev, u16 status)
976{
977 char * s;
978
979 if (suppress_linkstatus)
980 return;
981
982 switch (status) {
983 case HERMES_LINKSTATUS_NOT_CONNECTED:
984 s = "Not Connected";
985 break;
986 case HERMES_LINKSTATUS_CONNECTED:
987 s = "Connected";
988 break;
989 case HERMES_LINKSTATUS_DISCONNECTED:
990 s = "Disconnected";
991 break;
992 case HERMES_LINKSTATUS_AP_CHANGE:
993 s = "AP Changed";
994 break;
995 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
996 s = "AP Out of Range";
997 break;
998 case HERMES_LINKSTATUS_AP_IN_RANGE:
999 s = "AP In Range";
1000 break;
1001 case HERMES_LINKSTATUS_ASSOC_FAILED:
1002 s = "Association Failed";
1003 break;
1004 default:
1005 s = "UNKNOWN";
1006 }
1007
1008 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1009 dev->name, s, status);
1010}
1011
16739b06 1012/* Search scan results for requested BSSID, join it if found */
c4028958 1013static void orinoco_join_ap(struct work_struct *work)
16739b06 1014{
c4028958
DH
1015 struct orinoco_private *priv =
1016 container_of(work, struct orinoco_private, join_work);
1017 struct net_device *dev = priv->ndev;
16739b06
CH
1018 struct hermes *hw = &priv->hw;
1019 int err;
1020 unsigned long flags;
1021 struct join_req {
1022 u8 bssid[ETH_ALEN];
d133ae4c 1023 __le16 channel;
16739b06
CH
1024 } __attribute__ ((packed)) req;
1025 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
c89cc225 1026 struct prism2_scan_apinfo *atom = NULL;
16739b06 1027 int offset = 4;
c89cc225 1028 int found = 0;
16739b06
CH
1029 u8 *buf;
1030 u16 len;
1031
1032 /* Allocate buffer for scan results */
1033 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1034 if (! buf)
1035 return;
1036
1037 if (orinoco_lock(priv, &flags) != 0)
f3cb4cc1 1038 goto fail_lock;
16739b06
CH
1039
1040 /* Sanity checks in case user changed something in the meantime */
1041 if (! priv->bssid_fixed)
1042 goto out;
1043
1044 if (strlen(priv->desired_essid) == 0)
1045 goto out;
1046
1047 /* Read scan results from the firmware */
1048 err = hermes_read_ltv(hw, USER_BAP,
1049 HERMES_RID_SCANRESULTSTABLE,
1050 MAX_SCAN_LEN, &len, buf);
1051 if (err) {
1052 printk(KERN_ERR "%s: Cannot read scan results\n",
1053 dev->name);
1054 goto out;
1055 }
1056
1057 len = HERMES_RECLEN_TO_BYTES(len);
1058
1059 /* Go through the scan results looking for the channel of the AP
1060 * we were requested to join */
1061 for (; offset + atom_len <= len; offset += atom_len) {
1062 atom = (struct prism2_scan_apinfo *) (buf + offset);
c89cc225
PR
1063 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1064 found = 1;
1065 break;
1066 }
16739b06
CH
1067 }
1068
c89cc225
PR
1069 if (! found) {
1070 DEBUG(1, "%s: Requested AP not found in scan results\n",
1071 dev->name);
1072 goto out;
1073 }
16739b06 1074
16739b06
CH
1075 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1076 req.channel = atom->channel; /* both are little-endian */
1077 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1078 &req);
1079 if (err)
1080 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1081
1082 out:
16739b06 1083 orinoco_unlock(priv, &flags);
f3cb4cc1
PR
1084
1085 fail_lock:
1086 kfree(buf);
16739b06
CH
1087}
1088
95dd91fb 1089/* Send new BSSID to userspace */
c4028958 1090static void orinoco_send_wevents(struct work_struct *work)
95dd91fb 1091{
c4028958
DH
1092 struct orinoco_private *priv =
1093 container_of(work, struct orinoco_private, wevent_work);
1094 struct net_device *dev = priv->ndev;
95dd91fb
CH
1095 struct hermes *hw = &priv->hw;
1096 union iwreq_data wrqu;
1097 int err;
1098 unsigned long flags;
1099
1100 if (orinoco_lock(priv, &flags) != 0)
1101 return;
1102
1103 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1104 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1105 if (err != 0)
8aeabc37 1106 goto out;
95dd91fb
CH
1107
1108 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1109
1110 /* Send event to user space */
1111 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
8aeabc37
PR
1112
1113 out:
95dd91fb
CH
1114 orinoco_unlock(priv, &flags);
1115}
1116
1e3428e9
DW
1117
1118static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1119 unsigned long scan_age)
1120{
1121 bss_element *bss;
1122 bss_element *tmp_bss;
1123
1124 /* Blow away current list of scan results */
1125 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1126 if (!scan_age ||
1127 time_after(jiffies, bss->last_scanned + scan_age)) {
1128 list_move_tail(&bss->list, &priv->bss_free_list);
1129 /* Don't blow away ->list, just BSS data */
1130 memset(bss, 0, sizeof(bss->bss));
1131 bss->last_scanned = 0;
1132 }
1133 }
1134}
1135
1136static int orinoco_process_scan_results(struct net_device *dev,
1137 unsigned char *buf,
1138 int len)
1139{
1140 struct orinoco_private *priv = netdev_priv(dev);
1141 int offset; /* In the scan data */
1142 union hermes_scan_info *atom;
1143 int atom_len;
1144
1145 switch (priv->firmware_type) {
1146 case FIRMWARE_TYPE_AGERE:
1147 atom_len = sizeof(struct agere_scan_apinfo);
1148 offset = 0;
1149 break;
1150 case FIRMWARE_TYPE_SYMBOL:
1151 /* Lack of documentation necessitates this hack.
1152 * Different firmwares have 68 or 76 byte long atoms.
1153 * We try modulo first. If the length divides by both,
1154 * we check what would be the channel in the second
1155 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1156 * Valid channel cannot be 0. */
1157 if (len % 76)
1158 atom_len = 68;
1159 else if (len % 68)
1160 atom_len = 76;
1161 else if (len >= 1292 && buf[68] == 0)
1162 atom_len = 76;
1163 else
1164 atom_len = 68;
1165 offset = 0;
1166 break;
1167 case FIRMWARE_TYPE_INTERSIL:
1168 offset = 4;
1169 if (priv->has_hostscan) {
1170 atom_len = le16_to_cpup((__le16 *)buf);
1171 /* Sanity check for atom_len */
1172 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1173 printk(KERN_ERR "%s: Invalid atom_len in scan "
1174 "data: %d\n", dev->name, atom_len);
1175 return -EIO;
1176 }
1177 } else
1178 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1179 break;
1180 default:
1181 return -EOPNOTSUPP;
1182 }
1183
1184 /* Check that we got an whole number of atoms */
1185 if ((len - offset) % atom_len) {
1186 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1187 "atom_len %d, offset %d\n", dev->name, len,
1188 atom_len, offset);
1189 return -EIO;
1190 }
1191
1192 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1193
1194 /* Read the entries one by one */
1195 for (; offset + atom_len <= len; offset += atom_len) {
1196 int found = 0;
2236761b 1197 bss_element *bss = NULL;
1e3428e9
DW
1198
1199 /* Get next atom */
1200 atom = (union hermes_scan_info *) (buf + offset);
1201
1202 /* Try to update an existing bss first */
1203 list_for_each_entry(bss, &priv->bss_list, list) {
1204 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1205 continue;
1206 if (le16_to_cpu(bss->bss.a.essid_len) !=
1207 le16_to_cpu(atom->a.essid_len))
1208 continue;
1209 if (memcmp(bss->bss.a.essid, atom->a.essid,
1210 le16_to_cpu(atom->a.essid_len)))
1211 continue;
1e3428e9
DW
1212 found = 1;
1213 break;
1214 }
1215
1216 /* Grab a bss off the free list */
1217 if (!found && !list_empty(&priv->bss_free_list)) {
1218 bss = list_entry(priv->bss_free_list.next,
1219 bss_element, list);
1220 list_del(priv->bss_free_list.next);
1221
1e3428e9
DW
1222 list_add_tail(&bss->list, &priv->bss_list);
1223 }
2236761b
DW
1224
1225 if (bss) {
1226 /* Always update the BSS to get latest beacon info */
1227 memcpy(&bss->bss, atom, sizeof(bss->bss));
1228 bss->last_scanned = jiffies;
1229 }
1e3428e9
DW
1230 }
1231
1232 return 0;
1233}
1234
1da177e4
LT
1235static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1236{
1237 struct orinoco_private *priv = netdev_priv(dev);
1238 u16 infofid;
1239 struct {
d133ae4c
PR
1240 __le16 len;
1241 __le16 type;
1da177e4
LT
1242 } __attribute__ ((packed)) info;
1243 int len, type;
1244 int err;
1245
1246 /* This is an answer to an INQUIRE command that we did earlier,
1247 * or an information "event" generated by the card
1248 * The controller return to us a pseudo frame containing
1249 * the information in question - Jean II */
1250 infofid = hermes_read_regn(hw, INFOFID);
1251
1252 /* Read the info frame header - don't try too hard */
1253 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1254 infofid, 0);
1255 if (err) {
1256 printk(KERN_ERR "%s: error %d reading info frame. "
1257 "Frame dropped.\n", dev->name, err);
1258 return;
1259 }
1260
1261 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1262 type = le16_to_cpu(info.type);
1263
1264 switch (type) {
1265 case HERMES_INQ_TALLIES: {
1266 struct hermes_tallies_frame tallies;
1267 struct iw_statistics *wstats = &priv->wstats;
1268
1269 if (len > sizeof(tallies)) {
1270 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1271 dev->name, len);
1272 len = sizeof(tallies);
1273 }
1274
84d8a2fb
CH
1275 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1276 infofid, sizeof(info));
1277 if (err)
1278 break;
1da177e4
LT
1279
1280 /* Increment our various counters */
1281 /* wstats->discard.nwid - no wrong BSSID stuff */
1282 wstats->discard.code +=
1283 le16_to_cpu(tallies.RxWEPUndecryptable);
1284 if (len == sizeof(tallies))
1285 wstats->discard.code +=
1286 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1287 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1288 wstats->discard.misc +=
1289 le16_to_cpu(tallies.TxDiscardsWrongSA);
1290 wstats->discard.fragment +=
1291 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1292 wstats->discard.retries +=
1293 le16_to_cpu(tallies.TxRetryLimitExceeded);
1294 /* wstats->miss.beacon - no match */
1295 }
1296 break;
1297 case HERMES_INQ_LINKSTATUS: {
1298 struct hermes_linkstatus linkstatus;
1299 u16 newstatus;
1300 int connected;
1301
8f2abf44
CH
1302 if (priv->iw_mode == IW_MODE_MONITOR)
1303 break;
1304
1da177e4
LT
1305 if (len != sizeof(linkstatus)) {
1306 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1307 dev->name, len);
1308 break;
1309 }
1310
84d8a2fb
CH
1311 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1312 infofid, sizeof(info));
1313 if (err)
1314 break;
1da177e4
LT
1315 newstatus = le16_to_cpu(linkstatus.linkstatus);
1316
95dd91fb
CH
1317 /* Symbol firmware uses "out of range" to signal that
1318 * the hostscan frame can be requested. */
1319 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1320 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1321 priv->has_hostscan && priv->scan_inprogress) {
1322 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1323 break;
1324 }
1325
1da177e4
LT
1326 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1327 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1328 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1329
1330 if (connected)
1331 netif_carrier_on(dev);
7bb7c3a3 1332 else if (!ignore_disconnect)
1da177e4
LT
1333 netif_carrier_off(dev);
1334
95dd91fb
CH
1335 if (newstatus != priv->last_linkstatus) {
1336 priv->last_linkstatus = newstatus;
1da177e4 1337 print_linkstatus(dev, newstatus);
95dd91fb
CH
1338 /* The info frame contains only one word which is the
1339 * status (see hermes.h). The status is pretty boring
1340 * in itself, that's why we export the new BSSID...
1341 * Jean II */
1342 schedule_work(&priv->wevent_work);
1343 }
1344 }
1345 break;
1346 case HERMES_INQ_SCAN:
1347 if (!priv->scan_inprogress && priv->bssid_fixed &&
1348 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1349 schedule_work(&priv->join_work);
1350 break;
1351 }
1352 /* fall through */
1353 case HERMES_INQ_HOSTSCAN:
1354 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1355 /* Result of a scanning. Contains information about
1356 * cells in the vicinity - Jean II */
1357 union iwreq_data wrqu;
1358 unsigned char *buf;
1359
1e3428e9
DW
1360 /* Scan is no longer in progress */
1361 priv->scan_inprogress = 0;
1362
95dd91fb
CH
1363 /* Sanity check */
1364 if (len > 4096) {
1365 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1366 dev->name, len);
1367 break;
1368 }
1369
95dd91fb
CH
1370 /* Allocate buffer for results */
1371 buf = kmalloc(len, GFP_ATOMIC);
1372 if (buf == NULL)
1373 /* No memory, so can't printk()... */
1374 break;
1375
1376 /* Read scan data */
1377 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1378 infofid, sizeof(info));
708218b0
PR
1379 if (err) {
1380 kfree(buf);
95dd91fb 1381 break;
708218b0 1382 }
1da177e4 1383
95dd91fb
CH
1384#ifdef ORINOCO_DEBUG
1385 {
1386 int i;
1387 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1388 for(i = 1; i < (len * 2); i++)
1389 printk(":%02X", buf[i]);
1390 printk("]\n");
1391 }
1392#endif /* ORINOCO_DEBUG */
1393
1e3428e9
DW
1394 if (orinoco_process_scan_results(dev, buf, len) == 0) {
1395 /* Send an empty event to user space.
1396 * We don't send the received data on the event because
1397 * it would require us to do complex transcoding, and
1398 * we want to minimise the work done in the irq handler
1399 * Use a request to extract the data - Jean II */
1400 wrqu.data.length = 0;
1401 wrqu.data.flags = 0;
1402 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1403 }
1404 kfree(buf);
1da177e4
LT
1405 }
1406 break;
95dd91fb
CH
1407 case HERMES_INQ_SEC_STAT_AGERE:
1408 /* Security status (Agere specific) */
1409 /* Ignore this frame for now */
1410 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1411 break;
1412 /* fall through */
1da177e4
LT
1413 default:
1414 printk(KERN_DEBUG "%s: Unknown information frame received: "
1415 "type 0x%04x, length %d\n", dev->name, type, len);
1416 /* We don't actually do anything about it */
1417 break;
1418 }
1419}
1420
1421static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1422{
1423 if (net_ratelimit())
1424 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1425}
1426
1427/********************************************************************/
1428/* Internal hardware control routines */
1429/********************************************************************/
1430
1431int __orinoco_up(struct net_device *dev)
1432{
1433 struct orinoco_private *priv = netdev_priv(dev);
1434 struct hermes *hw = &priv->hw;
1435 int err;
1436
84d8a2fb
CH
1437 netif_carrier_off(dev); /* just to make sure */
1438
1da177e4
LT
1439 err = __orinoco_program_rids(dev);
1440 if (err) {
1441 printk(KERN_ERR "%s: Error %d configuring card\n",
1442 dev->name, err);
1443 return err;
1444 }
1445
1446 /* Fire things up again */
1447 hermes_set_irqmask(hw, ORINOCO_INTEN);
1448 err = hermes_enable_port(hw, 0);
1449 if (err) {
1450 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1451 dev->name, err);
1452 return err;
1453 }
1454
1455 netif_start_queue(dev);
1456
1457 return 0;
1458}
1459
1460int __orinoco_down(struct net_device *dev)
1461{
1462 struct orinoco_private *priv = netdev_priv(dev);
1463 struct hermes *hw = &priv->hw;
1464 int err;
1465
1466 netif_stop_queue(dev);
1467
1468 if (! priv->hw_unavailable) {
1469 if (! priv->broken_disableport) {
1470 err = hermes_disable_port(hw, 0);
1471 if (err) {
1472 /* Some firmwares (e.g. Intersil 1.3.x) seem
1473 * to have problems disabling the port, oh
1474 * well, too bad. */
1475 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1476 dev->name, err);
1477 priv->broken_disableport = 1;
1478 }
1479 }
1480 hermes_set_irqmask(hw, 0);
1481 hermes_write_regn(hw, EVACK, 0xffff);
1482 }
1483
1484 /* firmware will have to reassociate */
1485 netif_carrier_off(dev);
1486 priv->last_linkstatus = 0xffff;
1487
1488 return 0;
1489}
1490
37a6c611 1491static int orinoco_allocate_fid(struct net_device *dev)
1da177e4
LT
1492{
1493 struct orinoco_private *priv = netdev_priv(dev);
1494 struct hermes *hw = &priv->hw;
1495 int err;
1496
1da177e4 1497 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
b24d4582 1498 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1da177e4
LT
1499 /* Try workaround for old Symbol firmware bug */
1500 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1501 "(old Symbol firmware?). Trying to work around... ",
1502 dev->name);
1503
1504 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1505 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1506 if (err)
1507 printk("failed!\n");
1508 else
1509 printk("ok.\n");
1510 }
1511
1512 return err;
1513}
1514
37a6c611
PR
1515int orinoco_reinit_firmware(struct net_device *dev)
1516{
1517 struct orinoco_private *priv = netdev_priv(dev);
1518 struct hermes *hw = &priv->hw;
1519 int err;
1520
1521 err = hermes_init(hw);
1522 if (!err)
1523 err = orinoco_allocate_fid(dev);
1524
1525 return err;
1526}
1527
1da177e4
LT
1528static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1529{
1530 hermes_t *hw = &priv->hw;
1531 int err = 0;
1532
1533 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1534 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1535 priv->ndev->name, priv->bitratemode);
1536 return -EINVAL;
1537 }
1538
1539 switch (priv->firmware_type) {
1540 case FIRMWARE_TYPE_AGERE:
1541 err = hermes_write_wordrec(hw, USER_BAP,
1542 HERMES_RID_CNFTXRATECONTROL,
1543 bitrate_table[priv->bitratemode].agere_txratectrl);
1544 break;
1545 case FIRMWARE_TYPE_INTERSIL:
1546 case FIRMWARE_TYPE_SYMBOL:
1547 err = hermes_write_wordrec(hw, USER_BAP,
1548 HERMES_RID_CNFTXRATECONTROL,
1549 bitrate_table[priv->bitratemode].intersil_txratectrl);
1550 break;
1551 default:
1552 BUG();
1553 }
1554
1555 return err;
1556}
1557
16739b06
CH
1558/* Set fixed AP address */
1559static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1560{
1561 int roaming_flag;
1562 int err = 0;
1563 hermes_t *hw = &priv->hw;
1564
1565 switch (priv->firmware_type) {
1566 case FIRMWARE_TYPE_AGERE:
1567 /* not supported */
1568 break;
1569 case FIRMWARE_TYPE_INTERSIL:
1570 if (priv->bssid_fixed)
1571 roaming_flag = 2;
1572 else
1573 roaming_flag = 1;
1574
1575 err = hermes_write_wordrec(hw, USER_BAP,
1576 HERMES_RID_CNFROAMINGMODE,
1577 roaming_flag);
1578 break;
1579 case FIRMWARE_TYPE_SYMBOL:
1580 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1581 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1582 &priv->desired_bssid);
1583 break;
1584 }
1585 return err;
1586}
1587
1da177e4
LT
1588/* Change the WEP keys and/or the current keys. Can be called
1589 * either from __orinoco_hw_setup_wep() or directly from
1590 * orinoco_ioctl_setiwencode(). In the later case the association
1591 * with the AP is not broken (if the firmware can handle it),
1592 * which is needed for 802.1x implementations. */
1593static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1594{
1595 hermes_t *hw = &priv->hw;
1596 int err = 0;
1597
1598 switch (priv->firmware_type) {
1599 case FIRMWARE_TYPE_AGERE:
1600 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1601 HERMES_RID_CNFWEPKEYS_AGERE,
1602 &priv->keys);
1603 if (err)
1604 return err;
1605 err = hermes_write_wordrec(hw, USER_BAP,
1606 HERMES_RID_CNFTXKEY_AGERE,
1607 priv->tx_key);
1608 if (err)
1609 return err;
1610 break;
1611 case FIRMWARE_TYPE_INTERSIL:
1612 case FIRMWARE_TYPE_SYMBOL:
1613 {
1614 int keylen;
1615 int i;
1616
1617 /* Force uniform key length to work around firmware bugs */
1618 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1619
1620 if (keylen > LARGE_KEY_SIZE) {
1621 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1622 priv->ndev->name, priv->tx_key, keylen);
1623 return -E2BIG;
1624 }
1625
1626 /* Write all 4 keys */
1627 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1628 err = hermes_write_ltv(hw, USER_BAP,
1629 HERMES_RID_CNFDEFAULTKEY0 + i,
1630 HERMES_BYTES_TO_RECLEN(keylen),
1631 priv->keys[i].data);
1632 if (err)
1633 return err;
1634 }
1635
1636 /* Write the index of the key used in transmission */
1637 err = hermes_write_wordrec(hw, USER_BAP,
1638 HERMES_RID_CNFWEPDEFAULTKEYID,
1639 priv->tx_key);
1640 if (err)
1641 return err;
1642 }
1643 break;
1644 }
1645
1646 return 0;
1647}
1648
1649static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1650{
1651 hermes_t *hw = &priv->hw;
1652 int err = 0;
1653 int master_wep_flag;
1654 int auth_flag;
1655
1656 if (priv->wep_on)
1657 __orinoco_hw_setup_wepkeys(priv);
1658
1659 if (priv->wep_restrict)
1660 auth_flag = HERMES_AUTH_SHARED_KEY;
1661 else
1662 auth_flag = HERMES_AUTH_OPEN;
1663
1664 switch (priv->firmware_type) {
1665 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1666 if (priv->wep_on) {
1667 /* Enable the shared-key authentication. */
1668 err = hermes_write_wordrec(hw, USER_BAP,
1669 HERMES_RID_CNFAUTHENTICATION_AGERE,
1670 auth_flag);
1671 }
1672 err = hermes_write_wordrec(hw, USER_BAP,
1673 HERMES_RID_CNFWEPENABLED_AGERE,
1674 priv->wep_on);
1675 if (err)
1676 return err;
1677 break;
1678
1679 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1680 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1681 if (priv->wep_on) {
1682 if (priv->wep_restrict ||
1683 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1684 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1685 HERMES_WEP_EXCL_UNENCRYPTED;
1686 else
1687 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1688
1689 err = hermes_write_wordrec(hw, USER_BAP,
1690 HERMES_RID_CNFAUTHENTICATION,
1691 auth_flag);
1692 if (err)
1693 return err;
1694 } else
1695 master_wep_flag = 0;
1696
1697 if (priv->iw_mode == IW_MODE_MONITOR)
1698 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1699
1700 /* Master WEP setting : on/off */
1701 err = hermes_write_wordrec(hw, USER_BAP,
1702 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1703 master_wep_flag);
1704 if (err)
1705 return err;
1706
1707 break;
1708 }
1709
1710 return 0;
1711}
1712
1713static int __orinoco_program_rids(struct net_device *dev)
1714{
1715 struct orinoco_private *priv = netdev_priv(dev);
1716 hermes_t *hw = &priv->hw;
1717 int err;
1718 struct hermes_idstring idbuf;
1719
1720 /* Set the MAC address */
1721 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1722 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1723 if (err) {
1724 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1725 dev->name, err);
1726 return err;
1727 }
1728
1729 /* Set up the link mode */
1730 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1731 priv->port_type);
1732 if (err) {
1733 printk(KERN_ERR "%s: Error %d setting port type\n",
1734 dev->name, err);
1735 return err;
1736 }
1737 /* Set the channel/frequency */
d51d8b1f
DG
1738 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1739 err = hermes_write_wordrec(hw, USER_BAP,
1740 HERMES_RID_CNFOWNCHANNEL,
1741 priv->channel);
1742 if (err) {
1743 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1744 dev->name, err, priv->channel);
1745 return err;
1746 }
1da177e4
LT
1747 }
1748
1749 if (priv->has_ibss) {
1750 u16 createibss;
1751
1752 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1753 printk(KERN_WARNING "%s: This firmware requires an "
1754 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1755 /* With wvlan_cs, in this case, we would crash.
1756 * hopefully, this driver will behave better...
1757 * Jean II */
1758 createibss = 0;
1759 } else {
1760 createibss = priv->createibss;
1761 }
1762
1763 err = hermes_write_wordrec(hw, USER_BAP,
1764 HERMES_RID_CNFCREATEIBSS,
1765 createibss);
1766 if (err) {
1767 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1768 dev->name, err);
1769 return err;
1770 }
1771 }
1772
16739b06
CH
1773 /* Set the desired BSSID */
1774 err = __orinoco_hw_set_wap(priv);
1775 if (err) {
1776 printk(KERN_ERR "%s: Error %d setting AP address\n",
1777 dev->name, err);
1778 return err;
1779 }
1da177e4
LT
1780 /* Set the desired ESSID */
1781 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1782 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1783 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1784 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1785 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1786 &idbuf);
1787 if (err) {
1788 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1789 dev->name, err);
1790 return err;
1791 }
1792 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1793 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1794 &idbuf);
1795 if (err) {
1796 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1797 dev->name, err);
1798 return err;
1799 }
1800
1801 /* Set the station name */
1802 idbuf.len = cpu_to_le16(strlen(priv->nick));
1803 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1804 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1805 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1806 &idbuf);
1807 if (err) {
1808 printk(KERN_ERR "%s: Error %d setting nickname\n",
1809 dev->name, err);
1810 return err;
1811 }
1812
1813 /* Set AP density */
1814 if (priv->has_sensitivity) {
1815 err = hermes_write_wordrec(hw, USER_BAP,
1816 HERMES_RID_CNFSYSTEMSCALE,
1817 priv->ap_density);
1818 if (err) {
1819 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1820 "Disabling sensitivity control\n",
1821 dev->name, err);
1822
1823 priv->has_sensitivity = 0;
1824 }
1825 }
1826
1827 /* Set RTS threshold */
1828 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1829 priv->rts_thresh);
1830 if (err) {
1831 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1832 dev->name, err);
1833 return err;
1834 }
1835
1836 /* Set fragmentation threshold or MWO robustness */
1837 if (priv->has_mwo)
1838 err = hermes_write_wordrec(hw, USER_BAP,
1839 HERMES_RID_CNFMWOROBUST_AGERE,
1840 priv->mwo_robust);
1841 else
1842 err = hermes_write_wordrec(hw, USER_BAP,
1843 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1844 priv->frag_thresh);
1845 if (err) {
1846 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1847 dev->name, err);
1848 return err;
1849 }
1850
1851 /* Set bitrate */
1852 err = __orinoco_hw_set_bitrate(priv);
1853 if (err) {
1854 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1855 dev->name, err);
1856 return err;
1857 }
1858
1859 /* Set power management */
1860 if (priv->has_pm) {
1861 err = hermes_write_wordrec(hw, USER_BAP,
1862 HERMES_RID_CNFPMENABLED,
1863 priv->pm_on);
1864 if (err) {
1865 printk(KERN_ERR "%s: Error %d setting up PM\n",
1866 dev->name, err);
1867 return err;
1868 }
1869
1870 err = hermes_write_wordrec(hw, USER_BAP,
1871 HERMES_RID_CNFMULTICASTRECEIVE,
1872 priv->pm_mcast);
1873 if (err) {
1874 printk(KERN_ERR "%s: Error %d setting up PM\n",
1875 dev->name, err);
1876 return err;
1877 }
1878 err = hermes_write_wordrec(hw, USER_BAP,
1879 HERMES_RID_CNFMAXSLEEPDURATION,
1880 priv->pm_period);
1881 if (err) {
1882 printk(KERN_ERR "%s: Error %d setting up PM\n",
1883 dev->name, err);
1884 return err;
1885 }
1886 err = hermes_write_wordrec(hw, USER_BAP,
1887 HERMES_RID_CNFPMHOLDOVERDURATION,
1888 priv->pm_timeout);
1889 if (err) {
1890 printk(KERN_ERR "%s: Error %d setting up PM\n",
1891 dev->name, err);
1892 return err;
1893 }
1894 }
1895
1896 /* Set preamble - only for Symbol so far... */
1897 if (priv->has_preamble) {
1898 err = hermes_write_wordrec(hw, USER_BAP,
1899 HERMES_RID_CNFPREAMBLE_SYMBOL,
1900 priv->preamble);
1901 if (err) {
1902 printk(KERN_ERR "%s: Error %d setting preamble\n",
1903 dev->name, err);
1904 return err;
1905 }
1906 }
1907
1908 /* Set up encryption */
1909 if (priv->has_wep) {
1910 err = __orinoco_hw_setup_wep(priv);
1911 if (err) {
1912 printk(KERN_ERR "%s: Error %d activating WEP\n",
1913 dev->name, err);
1914 return err;
1915 }
1916 }
1917
98c4cae1
CH
1918 if (priv->iw_mode == IW_MODE_MONITOR) {
1919 /* Enable monitor mode */
1920 dev->type = ARPHRD_IEEE80211;
1921 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1922 HERMES_TEST_MONITOR, 0, NULL);
1923 } else {
1924 /* Disable monitor mode */
1925 dev->type = ARPHRD_ETHER;
1926 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1927 HERMES_TEST_STOP, 0, NULL);
1928 }
1929 if (err)
1930 return err;
1931
1da177e4
LT
1932 /* Set promiscuity / multicast*/
1933 priv->promiscuous = 0;
1934 priv->mc_count = 0;
932ff279
HX
1935
1936 /* FIXME: what about netif_tx_lock */
1937 __orinoco_set_multicast_list(dev);
1da177e4
LT
1938
1939 return 0;
1940}
1941
1942/* FIXME: return int? */
1943static void
1944__orinoco_set_multicast_list(struct net_device *dev)
1945{
1946 struct orinoco_private *priv = netdev_priv(dev);
1947 hermes_t *hw = &priv->hw;
1948 int err = 0;
1949 int promisc, mc_count;
1950
1951 /* The Hermes doesn't seem to have an allmulti mode, so we go
1952 * into promiscuous mode and let the upper levels deal. */
1953 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1954 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1955 promisc = 1;
1956 mc_count = 0;
1957 } else {
1958 promisc = 0;
1959 mc_count = dev->mc_count;
1960 }
1961
1962 if (promisc != priv->promiscuous) {
1963 err = hermes_write_wordrec(hw, USER_BAP,
1964 HERMES_RID_CNFPROMISCUOUSMODE,
1965 promisc);
1966 if (err) {
1967 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1968 dev->name, err);
1969 } else
1970 priv->promiscuous = promisc;
1971 }
1972
1973 if (! promisc && (mc_count || priv->mc_count) ) {
1974 struct dev_mc_list *p = dev->mc_list;
1975 struct hermes_multicast mclist;
1976 int i;
1977
1978 for (i = 0; i < mc_count; i++) {
1979 /* paranoia: is list shorter than mc_count? */
1980 BUG_ON(! p);
1981 /* paranoia: bad address size in list? */
1982 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1983
1984 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1985 p = p->next;
1986 }
1987
1988 if (p)
1989 printk(KERN_WARNING "%s: Multicast list is "
1990 "longer than mc_count\n", dev->name);
1991
1992 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1993 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1994 &mclist);
1995 if (err)
1996 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1997 dev->name, err);
1998 else
1999 priv->mc_count = mc_count;
2000 }
1da177e4
LT
2001}
2002
1da177e4
LT
2003/* This must be called from user context, without locks held - use
2004 * schedule_work() */
c4028958 2005static void orinoco_reset(struct work_struct *work)
1da177e4 2006{
c4028958
DH
2007 struct orinoco_private *priv =
2008 container_of(work, struct orinoco_private, reset_work);
2009 struct net_device *dev = priv->ndev;
1da177e4 2010 struct hermes *hw = &priv->hw;
8551cb98 2011 int err;
1da177e4
LT
2012 unsigned long flags;
2013
2014 if (orinoco_lock(priv, &flags) != 0)
2015 /* When the hardware becomes available again, whatever
2016 * detects that is responsible for re-initializing
2017 * it. So no need for anything further */
2018 return;
2019
2020 netif_stop_queue(dev);
2021
2022 /* Shut off interrupts. Depending on what state the hardware
2023 * is in, this might not work, but we'll try anyway */
2024 hermes_set_irqmask(hw, 0);
2025 hermes_write_regn(hw, EVACK, 0xffff);
2026
2027 priv->hw_unavailable++;
2028 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2029 netif_carrier_off(dev);
2030
2031 orinoco_unlock(priv, &flags);
2032
95dd91fb 2033 /* Scanning support: Cleanup of driver struct */
1e3428e9 2034 orinoco_clear_scan_results(priv, 0);
95dd91fb
CH
2035 priv->scan_inprogress = 0;
2036
8551cb98 2037 if (priv->hard_reset) {
1da177e4 2038 err = (*priv->hard_reset)(priv);
8551cb98
CH
2039 if (err) {
2040 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2041 "performing hard reset\n", dev->name, err);
2042 goto disable;
2043 }
1da177e4
LT
2044 }
2045
2046 err = orinoco_reinit_firmware(dev);
2047 if (err) {
2048 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2049 dev->name, err);
8551cb98 2050 goto disable;
1da177e4
LT
2051 }
2052
2053 spin_lock_irq(&priv->lock); /* This has to be called from user context */
2054
2055 priv->hw_unavailable--;
2056
2057 /* priv->open or priv->hw_unavailable might have changed while
2058 * we dropped the lock */
2059 if (priv->open && (! priv->hw_unavailable)) {
2060 err = __orinoco_up(dev);
2061 if (err) {
2062 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2063 dev->name, err);
2064 } else
2065 dev->trans_start = jiffies;
2066 }
2067
2068 spin_unlock_irq(&priv->lock);
2069
2070 return;
8551cb98
CH
2071 disable:
2072 hermes_set_irqmask(hw, 0);
2073 netif_device_detach(dev);
2074 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1da177e4
LT
2075}
2076
2077/********************************************************************/
2078/* Interrupt handler */
2079/********************************************************************/
2080
2081static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2082{
2083 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2084}
2085
2086static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2087{
2088 /* This seems to happen a fair bit under load, but ignoring it
2089 seems to work fine...*/
2090 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2091 dev->name);
2092}
2093
7d12e780 2094irqreturn_t orinoco_interrupt(int irq, void *dev_id)
1da177e4 2095{
c31f28e7 2096 struct net_device *dev = dev_id;
1da177e4
LT
2097 struct orinoco_private *priv = netdev_priv(dev);
2098 hermes_t *hw = &priv->hw;
2099 int count = MAX_IRQLOOPS_PER_IRQ;
2100 u16 evstat, events;
2101 /* These are used to detect a runaway interrupt situation */
2102 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2103 * we panic and shut down the hardware */
2104 static int last_irq_jiffy = 0; /* jiffies value the last time
2105 * we were called */
2106 static int loops_this_jiffy = 0;
2107 unsigned long flags;
2108
2109 if (orinoco_lock(priv, &flags) != 0) {
2110 /* If hw is unavailable - we don't know if the irq was
2111 * for us or not */
2112 return IRQ_HANDLED;
2113 }
2114
2115 evstat = hermes_read_regn(hw, EVSTAT);
2116 events = evstat & hw->inten;
2117 if (! events) {
2118 orinoco_unlock(priv, &flags);
2119 return IRQ_NONE;
2120 }
2121
2122 if (jiffies != last_irq_jiffy)
2123 loops_this_jiffy = 0;
2124 last_irq_jiffy = jiffies;
2125
2126 while (events && count--) {
2127 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2128 printk(KERN_WARNING "%s: IRQ handler is looping too "
2129 "much! Resetting.\n", dev->name);
2130 /* Disable interrupts for now */
2131 hermes_set_irqmask(hw, 0);
2132 schedule_work(&priv->reset_work);
2133 break;
2134 }
2135
2136 /* Check the card hasn't been removed */
2137 if (! hermes_present(hw)) {
2138 DEBUG(0, "orinoco_interrupt(): card removed\n");
2139 break;
2140 }
2141
2142 if (events & HERMES_EV_TICK)
2143 __orinoco_ev_tick(dev, hw);
2144 if (events & HERMES_EV_WTERR)
2145 __orinoco_ev_wterr(dev, hw);
2146 if (events & HERMES_EV_INFDROP)
2147 __orinoco_ev_infdrop(dev, hw);
2148 if (events & HERMES_EV_INFO)
2149 __orinoco_ev_info(dev, hw);
2150 if (events & HERMES_EV_RX)
2151 __orinoco_ev_rx(dev, hw);
2152 if (events & HERMES_EV_TXEXC)
2153 __orinoco_ev_txexc(dev, hw);
2154 if (events & HERMES_EV_TX)
2155 __orinoco_ev_tx(dev, hw);
2156 if (events & HERMES_EV_ALLOC)
2157 __orinoco_ev_alloc(dev, hw);
2158
84d8a2fb 2159 hermes_write_regn(hw, EVACK, evstat);
1da177e4
LT
2160
2161 evstat = hermes_read_regn(hw, EVSTAT);
2162 events = evstat & hw->inten;
2163 };
2164
2165 orinoco_unlock(priv, &flags);
2166 return IRQ_HANDLED;
2167}
2168
2169/********************************************************************/
2170/* Initialization */
2171/********************************************************************/
2172
2173struct comp_id {
2174 u16 id, variant, major, minor;
2175} __attribute__ ((packed));
2176
2177static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2178{
2179 if (nic_id->id < 0x8000)
2180 return FIRMWARE_TYPE_AGERE;
2181 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2182 return FIRMWARE_TYPE_SYMBOL;
2183 else
2184 return FIRMWARE_TYPE_INTERSIL;
2185}
2186
2187/* Set priv->firmware type, determine firmware properties */
2188static int determine_firmware(struct net_device *dev)
2189{
2190 struct orinoco_private *priv = netdev_priv(dev);
2191 hermes_t *hw = &priv->hw;
2192 int err;
2193 struct comp_id nic_id, sta_id;
2194 unsigned int firmver;
dde6d43d 2195 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
1da177e4
LT
2196
2197 /* Get the hardware version */
2198 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2199 if (err) {
2200 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2201 dev->name, err);
2202 return err;
2203 }
2204
2205 le16_to_cpus(&nic_id.id);
2206 le16_to_cpus(&nic_id.variant);
2207 le16_to_cpus(&nic_id.major);
2208 le16_to_cpus(&nic_id.minor);
2209 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2210 dev->name, nic_id.id, nic_id.variant,
2211 nic_id.major, nic_id.minor);
2212
2213 priv->firmware_type = determine_firmware_type(&nic_id);
2214
2215 /* Get the firmware version */
2216 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2217 if (err) {
2218 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2219 dev->name, err);
2220 return err;
2221 }
2222
2223 le16_to_cpus(&sta_id.id);
2224 le16_to_cpus(&sta_id.variant);
2225 le16_to_cpus(&sta_id.major);
2226 le16_to_cpus(&sta_id.minor);
2227 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2228 dev->name, sta_id.id, sta_id.variant,
2229 sta_id.major, sta_id.minor);
2230
2231 switch (sta_id.id) {
2232 case 0x15:
2233 printk(KERN_ERR "%s: Primary firmware is active\n",
2234 dev->name);
2235 return -ENODEV;
2236 case 0x14b:
2237 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2238 dev->name);
2239 return -ENODEV;
2240 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2241 case 0x21: /* Symbol Spectrum24 Trilogy */
2242 break;
2243 default:
2244 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2245 dev->name);
2246 break;
2247 }
2248
2249 /* Default capabilities */
2250 priv->has_sensitivity = 1;
2251 priv->has_mwo = 0;
2252 priv->has_preamble = 0;
2253 priv->has_port3 = 1;
2254 priv->has_ibss = 1;
2255 priv->has_wep = 0;
2256 priv->has_big_wep = 0;
2257
2258 /* Determine capabilities from the firmware version */
2259 switch (priv->firmware_type) {
2260 case FIRMWARE_TYPE_AGERE:
2261 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2262 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2263 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2264 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2265
2266 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2267
2268 priv->has_ibss = (firmver >= 0x60006);
2269 priv->has_wep = (firmver >= 0x40020);
2270 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2271 Gold cards from the others? */
2272 priv->has_mwo = (firmver >= 0x60000);
2273 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2274 priv->ibss_port = 1;
95dd91fb 2275 priv->has_hostscan = (firmver >= 0x8000a);
98c4cae1 2276 priv->broken_monitor = (firmver >= 0x80000);
1da177e4
LT
2277
2278 /* Tested with Agere firmware :
2279 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2280 * Tested CableTron firmware : 4.32 => Anton */
2281 break;
2282 case FIRMWARE_TYPE_SYMBOL:
2283 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2284 /* Intel MAC : 00:02:B3:* */
2285 /* 3Com MAC : 00:50:DA:* */
2286 memset(tmp, 0, sizeof(tmp));
2287 /* Get the Symbol firmware version */
2288 err = hermes_read_ltv(hw, USER_BAP,
2289 HERMES_RID_SECONDARYVERSION_SYMBOL,
2290 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2291 if (err) {
2292 printk(KERN_WARNING
2293 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2294 dev->name, err);
2295 firmver = 0;
2296 tmp[0] = '\0';
2297 } else {
2298 /* The firmware revision is a string, the format is
2299 * something like : "V2.20-01".
2300 * Quick and dirty parsing... - Jean II
2301 */
2302 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2303 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2304 | (tmp[7] - '0');
2305
2306 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2307 }
2308
2309 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2310 "Symbol %s", tmp);
2311
2312 priv->has_ibss = (firmver >= 0x20000);
2313 priv->has_wep = (firmver >= 0x15012);
2314 priv->has_big_wep = (firmver >= 0x20000);
2315 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2316 (firmver >= 0x29000 && firmver < 0x30000) ||
2317 firmver >= 0x31000;
2318 priv->has_preamble = (firmver >= 0x20000);
2319 priv->ibss_port = 4;
649e59e6
CH
2320 priv->broken_disableport = (firmver == 0x25013) ||
2321 (firmver >= 0x30000 && firmver <= 0x31000);
95dd91fb
CH
2322 priv->has_hostscan = (firmver >= 0x31001) ||
2323 (firmver >= 0x29057 && firmver < 0x30000);
1da177e4
LT
2324 /* Tested with Intel firmware : 0x20015 => Jean II */
2325 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2326 break;
2327 case FIRMWARE_TYPE_INTERSIL:
2328 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2329 * Samsung, Compaq 100/200 and Proxim are slightly
2330 * different and less well tested */
2331 /* D-Link MAC : 00:40:05:* */
2332 /* Addtron MAC : 00:90:D1:* */
2333 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2334 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2335 sta_id.variant);
2336
2337 firmver = ((unsigned long)sta_id.major << 16) |
2338 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2339
2340 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2341 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2342 priv->has_pm = (firmver >= 0x000700);
95dd91fb 2343 priv->has_hostscan = (firmver >= 0x010301);
1da177e4
LT
2344
2345 if (firmver >= 0x000800)
2346 priv->ibss_port = 0;
2347 else {
2348 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2349 "than v0.8.x - several features not supported\n",
2350 dev->name);
2351 priv->ibss_port = 1;
2352 }
2353 break;
2354 }
2355 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2356 priv->fw_name);
2357
2358 return 0;
2359}
2360
2361static int orinoco_init(struct net_device *dev)
2362{
2363 struct orinoco_private *priv = netdev_priv(dev);
2364 hermes_t *hw = &priv->hw;
2365 int err = 0;
2366 struct hermes_idstring nickbuf;
2367 u16 reclen;
2368 int len;
0795af57 2369 DECLARE_MAC_BUF(mac);
1da177e4 2370
1da177e4
LT
2371 /* No need to lock, the hw_unavailable flag is already set in
2372 * alloc_orinocodev() */
b453872c 2373 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
1da177e4
LT
2374
2375 /* Initialize the firmware */
37a6c611 2376 err = hermes_init(hw);
1da177e4
LT
2377 if (err != 0) {
2378 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2379 dev->name, err);
2380 goto out;
2381 }
2382
2383 err = determine_firmware(dev);
2384 if (err != 0) {
2385 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2386 dev->name);
2387 goto out;
2388 }
2389
2390 if (priv->has_port3)
2391 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2392 if (priv->has_ibss)
2393 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2394 dev->name);
2395 if (priv->has_wep) {
2396 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2397 if (priv->has_big_wep)
2398 printk("104-bit key\n");
2399 else
2400 printk("40-bit key\n");
2401 }
2402
2403 /* Get the MAC address */
2404 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2405 ETH_ALEN, NULL, dev->dev_addr);
2406 if (err) {
2407 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2408 dev->name);
2409 goto out;
2410 }
2411
0795af57
JP
2412 printk(KERN_DEBUG "%s: MAC address %s\n",
2413 dev->name, print_mac(mac, dev->dev_addr));
1da177e4
LT
2414
2415 /* Get the station name */
2416 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2417 sizeof(nickbuf), &reclen, &nickbuf);
2418 if (err) {
2419 printk(KERN_ERR "%s: failed to read station name\n",
2420 dev->name);
2421 goto out;
2422 }
2423 if (nickbuf.len)
2424 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2425 else
2426 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2427 memcpy(priv->nick, &nickbuf.val, len);
2428 priv->nick[len] = '\0';
2429
2430 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2431
37a6c611
PR
2432 err = orinoco_allocate_fid(dev);
2433 if (err) {
2434 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2435 dev->name);
2436 goto out;
2437 }
2438
1da177e4
LT
2439 /* Get allowed channels */
2440 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2441 &priv->channel_mask);
2442 if (err) {
2443 printk(KERN_ERR "%s: failed to read channel list!\n",
2444 dev->name);
2445 goto out;
2446 }
2447
2448 /* Get initial AP density */
2449 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2450 &priv->ap_density);
2451 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2452 priv->has_sensitivity = 0;
2453 }
2454
2455 /* Get initial RTS threshold */
2456 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2457 &priv->rts_thresh);
2458 if (err) {
2459 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2460 dev->name);
2461 goto out;
2462 }
2463
2464 /* Get initial fragmentation settings */
2465 if (priv->has_mwo)
2466 err = hermes_read_wordrec(hw, USER_BAP,
2467 HERMES_RID_CNFMWOROBUST_AGERE,
2468 &priv->mwo_robust);
2469 else
2470 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2471 &priv->frag_thresh);
2472 if (err) {
2473 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2474 dev->name);
2475 goto out;
2476 }
2477
2478 /* Power management setup */
2479 if (priv->has_pm) {
2480 priv->pm_on = 0;
2481 priv->pm_mcast = 1;
2482 err = hermes_read_wordrec(hw, USER_BAP,
2483 HERMES_RID_CNFMAXSLEEPDURATION,
2484 &priv->pm_period);
2485 if (err) {
2486 printk(KERN_ERR "%s: failed to read power management period!\n",
2487 dev->name);
2488 goto out;
2489 }
2490 err = hermes_read_wordrec(hw, USER_BAP,
2491 HERMES_RID_CNFPMHOLDOVERDURATION,
2492 &priv->pm_timeout);
2493 if (err) {
2494 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2495 dev->name);
2496 goto out;
2497 }
2498 }
2499
2500 /* Preamble setup */
2501 if (priv->has_preamble) {
2502 err = hermes_read_wordrec(hw, USER_BAP,
2503 HERMES_RID_CNFPREAMBLE_SYMBOL,
2504 &priv->preamble);
2505 if (err)
2506 goto out;
2507 }
2508
2509 /* Set up the default configuration */
2510 priv->iw_mode = IW_MODE_INFRA;
2511 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2512 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2513 set_port_type(priv);
d51d8b1f 2514 priv->channel = 0; /* use firmware default */
1da177e4
LT
2515
2516 priv->promiscuous = 0;
2517 priv->wep_on = 0;
2518 priv->tx_key = 0;
2519
1da177e4
LT
2520 /* Make the hardware available, as long as it hasn't been
2521 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2522 spin_lock_irq(&priv->lock);
2523 priv->hw_unavailable--;
2524 spin_unlock_irq(&priv->lock);
2525
2526 printk(KERN_DEBUG "%s: ready\n", dev->name);
2527
2528 out:
1da177e4
LT
2529 return err;
2530}
2531
2532struct net_device *alloc_orinocodev(int sizeof_card,
2533 int (*hard_reset)(struct orinoco_private *))
2534{
2535 struct net_device *dev;
2536 struct orinoco_private *priv;
2537
2538 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2539 if (! dev)
2540 return NULL;
2541 priv = netdev_priv(dev);
2542 priv->ndev = dev;
2543 if (sizeof_card)
84d8a2fb 2544 priv->card = (void *)((unsigned long)priv
1da177e4
LT
2545 + sizeof(struct orinoco_private));
2546 else
2547 priv->card = NULL;
2548
1e3428e9
DW
2549 if (orinoco_bss_data_allocate(priv))
2550 goto err_out_free;
2551 orinoco_bss_data_init(priv);
2552
1da177e4
LT
2553 /* Setup / override net_device fields */
2554 dev->init = orinoco_init;
2555 dev->hard_start_xmit = orinoco_xmit;
2556 dev->tx_timeout = orinoco_tx_timeout;
2557 dev->watchdog_timeo = HZ; /* 1 second timeout */
2558 dev->get_stats = orinoco_get_stats;
1fab2e8b 2559 dev->ethtool_ops = &orinoco_ethtool_ops;
620554e4 2560 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
343c686c
PR
2561#ifdef WIRELESS_SPY
2562 priv->wireless_data.spy_data = &priv->spy_data;
2563 dev->wireless_data = &priv->wireless_data;
2564#endif
1da177e4
LT
2565 dev->change_mtu = orinoco_change_mtu;
2566 dev->set_multicast_list = orinoco_set_multicast_list;
2567 /* we use the default eth_mac_addr for setting the MAC addr */
2568
2569 /* Set up default callbacks */
2570 dev->open = orinoco_open;
2571 dev->stop = orinoco_stop;
2572 priv->hard_reset = hard_reset;
2573
2574 spin_lock_init(&priv->lock);
2575 priv->open = 0;
2576 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2577 * before anything else touches the
2578 * hardware */
c4028958
DH
2579 INIT_WORK(&priv->reset_work, orinoco_reset);
2580 INIT_WORK(&priv->join_work, orinoco_join_ap);
2581 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
1da177e4
LT
2582
2583 netif_carrier_off(dev);
2584 priv->last_linkstatus = 0xffff;
2585
2586 return dev;
2587
1e3428e9
DW
2588err_out_free:
2589 free_netdev(dev);
2590 return NULL;
1da177e4
LT
2591}
2592
2593void free_orinocodev(struct net_device *dev)
2594{
95dd91fb
CH
2595 struct orinoco_private *priv = netdev_priv(dev);
2596
1e3428e9 2597 orinoco_bss_data_free(priv);
1da177e4
LT
2598 free_netdev(dev);
2599}
2600
2601/********************************************************************/
2602/* Wireless extensions */
2603/********************************************************************/
2604
7e4e8d99 2605/* Return : < 0 -> error code ; >= 0 -> length */
1da177e4
LT
2606static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2607 char buf[IW_ESSID_MAX_SIZE+1])
2608{
2609 hermes_t *hw = &priv->hw;
2610 int err = 0;
2611 struct hermes_idstring essidbuf;
2612 char *p = (char *)(&essidbuf.val);
2613 int len;
2614 unsigned long flags;
2615
2616 if (orinoco_lock(priv, &flags) != 0)
2617 return -EBUSY;
2618
2619 if (strlen(priv->desired_essid) > 0) {
2620 /* We read the desired SSID from the hardware rather
2621 than from priv->desired_essid, just in case the
2622 firmware is allowed to change it on us. I'm not
2623 sure about this */
2624 /* My guess is that the OWNSSID should always be whatever
2625 * we set to the card, whereas CURRENT_SSID is the one that
2626 * may change... - Jean II */
2627 u16 rid;
2628
2629 *active = 1;
2630
2631 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2632 HERMES_RID_CNFDESIREDSSID;
2633
2634 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2635 NULL, &essidbuf);
2636 if (err)
2637 goto fail_unlock;
2638 } else {
2639 *active = 0;
2640
2641 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2642 sizeof(essidbuf), NULL, &essidbuf);
2643 if (err)
2644 goto fail_unlock;
2645 }
2646
2647 len = le16_to_cpu(essidbuf.len);
84d8a2fb 2648 BUG_ON(len > IW_ESSID_MAX_SIZE);
1da177e4 2649
7e4e8d99 2650 memset(buf, 0, IW_ESSID_MAX_SIZE);
1da177e4 2651 memcpy(buf, p, len);
7e4e8d99 2652 err = len;
1da177e4
LT
2653
2654 fail_unlock:
2655 orinoco_unlock(priv, &flags);
2656
2657 return err;
2658}
2659
2660static long orinoco_hw_get_freq(struct orinoco_private *priv)
2661{
2662
2663 hermes_t *hw = &priv->hw;
2664 int err = 0;
2665 u16 channel;
2666 long freq = 0;
2667 unsigned long flags;
2668
2669 if (orinoco_lock(priv, &flags) != 0)
2670 return -EBUSY;
2671
2672 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2673 if (err)
2674 goto out;
2675
2676 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2677 if (channel == 0) {
2678 err = -EBUSY;
2679 goto out;
2680 }
2681
2682 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2683 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2684 priv->ndev->name, channel);
2685 err = -EBUSY;
2686 goto out;
2687
2688 }
2689 freq = channel_frequency[channel-1] * 100000;
2690
2691 out:
2692 orinoco_unlock(priv, &flags);
2693
2694 if (err > 0)
2695 err = -EBUSY;
2696 return err ? err : freq;
2697}
2698
2699static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2700 int *numrates, s32 *rates, int max)
2701{
2702 hermes_t *hw = &priv->hw;
2703 struct hermes_idstring list;
2704 unsigned char *p = (unsigned char *)&list.val;
2705 int err = 0;
2706 int num;
2707 int i;
2708 unsigned long flags;
2709
2710 if (orinoco_lock(priv, &flags) != 0)
2711 return -EBUSY;
2712
2713 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2714 sizeof(list), NULL, &list);
2715 orinoco_unlock(priv, &flags);
2716
2717 if (err)
2718 return err;
2719
2720 num = le16_to_cpu(list.len);
2721 *numrates = num;
2722 num = min(num, max);
2723
2724 for (i = 0; i < num; i++) {
2725 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2726 }
2727
2728 return 0;
2729}
2730
620554e4
CH
2731static int orinoco_ioctl_getname(struct net_device *dev,
2732 struct iw_request_info *info,
2733 char *name,
2734 char *extra)
1da177e4
LT
2735{
2736 struct orinoco_private *priv = netdev_priv(dev);
1da177e4 2737 int numrates;
620554e4
CH
2738 int err;
2739
2740 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2741
2742 if (!err && (numrates > 2))
2743 strcpy(name, "IEEE 802.11b");
2744 else
2745 strcpy(name, "IEEE 802.11-DS");
2746
2747 return 0;
2748}
2749
16739b06
CH
2750static int orinoco_ioctl_setwap(struct net_device *dev,
2751 struct iw_request_info *info,
2752 struct sockaddr *ap_addr,
2753 char *extra)
2754{
2755 struct orinoco_private *priv = netdev_priv(dev);
2756 int err = -EINPROGRESS; /* Call commit handler */
1da177e4 2757 unsigned long flags;
16739b06
CH
2758 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2759 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1da177e4 2760
16739b06
CH
2761 if (orinoco_lock(priv, &flags) != 0)
2762 return -EBUSY;
2763
2764 /* Enable automatic roaming - no sanity checks are needed */
2765 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2766 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2767 priv->bssid_fixed = 0;
2768 memset(priv->desired_bssid, 0, ETH_ALEN);
2769
2770 /* "off" means keep existing connection */
2771 if (ap_addr->sa_data[0] == 0) {
2772 __orinoco_hw_set_wap(priv);
2773 err = 0;
2774 }
2775 goto out;
2776 }
2777
2778 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2779 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2780 "support manual roaming\n",
2781 dev->name);
2782 err = -EOPNOTSUPP;
2783 goto out;
2784 }
2785
2786 if (priv->iw_mode != IW_MODE_INFRA) {
2787 printk(KERN_WARNING "%s: Manual roaming supported only in "
2788 "managed mode\n", dev->name);
2789 err = -EOPNOTSUPP;
2790 goto out;
2791 }
2792
2793 /* Intersil firmware hangs without Desired ESSID */
2794 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2795 strlen(priv->desired_essid) == 0) {
2796 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2797 "manual roaming\n", dev->name);
2798 err = -EOPNOTSUPP;
2799 goto out;
2800 }
2801
2802 /* Finally, enable manual roaming */
2803 priv->bssid_fixed = 1;
2804 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2805
2806 out:
2807 orinoco_unlock(priv, &flags);
2808 return err;
2809}
2810
620554e4
CH
2811static int orinoco_ioctl_getwap(struct net_device *dev,
2812 struct iw_request_info *info,
2813 struct sockaddr *ap_addr,
2814 char *extra)
2815{
2816 struct orinoco_private *priv = netdev_priv(dev);
2817
2818 hermes_t *hw = &priv->hw;
2819 int err = 0;
1da177e4
LT
2820 unsigned long flags;
2821
620554e4
CH
2822 if (orinoco_lock(priv, &flags) != 0)
2823 return -EBUSY;
1da177e4 2824
620554e4
CH
2825 ap_addr->sa_family = ARPHRD_ETHER;
2826 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2827 ETH_ALEN, NULL, ap_addr->sa_data);
1da177e4 2828
620554e4
CH
2829 orinoco_unlock(priv, &flags);
2830
2831 return err;
2832}
1da177e4 2833
620554e4
CH
2834static int orinoco_ioctl_setmode(struct net_device *dev,
2835 struct iw_request_info *info,
2836 u32 *mode,
2837 char *extra)
2838{
2839 struct orinoco_private *priv = netdev_priv(dev);
2840 int err = -EINPROGRESS; /* Call commit handler */
2841 unsigned long flags;
1da177e4 2842
620554e4
CH
2843 if (priv->iw_mode == *mode)
2844 return 0;
1da177e4
LT
2845
2846 if (orinoco_lock(priv, &flags) != 0)
2847 return -EBUSY;
2848
620554e4
CH
2849 switch (*mode) {
2850 case IW_MODE_ADHOC:
2851 if (!priv->has_ibss && !priv->has_port3)
2852 err = -EOPNOTSUPP;
2853 break;
2854
2855 case IW_MODE_INFRA:
2856 break;
2857
98c4cae1
CH
2858 case IW_MODE_MONITOR:
2859 if (priv->broken_monitor && !force_monitor) {
2860 printk(KERN_WARNING "%s: Monitor mode support is "
2861 "buggy in this firmware, not enabling\n",
2862 dev->name);
2863 err = -EOPNOTSUPP;
2864 }
2865 break;
2866
620554e4
CH
2867 default:
2868 err = -EOPNOTSUPP;
2869 break;
2870 }
2871
2872 if (err == -EINPROGRESS) {
2873 priv->iw_mode = *mode;
2874 set_port_type(priv);
2875 }
2876
1da177e4
LT
2877 orinoco_unlock(priv, &flags);
2878
620554e4
CH
2879 return err;
2880}
1da177e4 2881
620554e4
CH
2882static int orinoco_ioctl_getmode(struct net_device *dev,
2883 struct iw_request_info *info,
2884 u32 *mode,
2885 char *extra)
2886{
2887 struct orinoco_private *priv = netdev_priv(dev);
1da177e4 2888
620554e4
CH
2889 *mode = priv->iw_mode;
2890 return 0;
2891}
1da177e4 2892
620554e4
CH
2893static int orinoco_ioctl_getiwrange(struct net_device *dev,
2894 struct iw_request_info *info,
2895 struct iw_point *rrq,
2896 char *extra)
2897{
2898 struct orinoco_private *priv = netdev_priv(dev);
2899 int err = 0;
2900 struct iw_range *range = (struct iw_range *) extra;
2901 int numrates;
2902 int i, k;
2903
620554e4
CH
2904 rrq->length = sizeof(struct iw_range);
2905 memset(range, 0, sizeof(struct iw_range));
2906
2907 range->we_version_compiled = WIRELESS_EXT;
2908 range->we_version_source = 14;
1da177e4
LT
2909
2910 /* Set available channels/frequencies */
620554e4 2911 range->num_channels = NUM_CHANNELS;
1da177e4
LT
2912 k = 0;
2913 for (i = 0; i < NUM_CHANNELS; i++) {
2914 if (priv->channel_mask & (1 << i)) {
620554e4
CH
2915 range->freq[k].i = i + 1;
2916 range->freq[k].m = channel_frequency[i] * 100000;
2917 range->freq[k].e = 1;
1da177e4
LT
2918 k++;
2919 }
2920
2921 if (k >= IW_MAX_FREQUENCIES)
2922 break;
2923 }
620554e4
CH
2924 range->num_frequency = k;
2925 range->sensitivity = 3;
1da177e4 2926
620554e4
CH
2927 if (priv->has_wep) {
2928 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2929 range->encoding_size[0] = SMALL_KEY_SIZE;
2930 range->num_encoding_sizes = 1;
1da177e4 2931
620554e4
CH
2932 if (priv->has_big_wep) {
2933 range->encoding_size[1] = LARGE_KEY_SIZE;
2934 range->num_encoding_sizes = 2;
2935 }
2936 }
1da177e4 2937
343c686c 2938 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
1da177e4 2939 /* Quality stats meaningless in ad-hoc mode */
1da177e4 2940 } else {
620554e4
CH
2941 range->max_qual.qual = 0x8b - 0x2f;
2942 range->max_qual.level = 0x2f - 0x95 - 1;
2943 range->max_qual.noise = 0x2f - 0x95 - 1;
1da177e4 2944 /* Need to get better values */
620554e4
CH
2945 range->avg_qual.qual = 0x24;
2946 range->avg_qual.level = 0xC2;
2947 range->avg_qual.noise = 0x9E;
1da177e4
LT
2948 }
2949
2950 err = orinoco_hw_get_bitratelist(priv, &numrates,
620554e4 2951 range->bitrate, IW_MAX_BITRATES);
1da177e4
LT
2952 if (err)
2953 return err;
620554e4
CH
2954 range->num_bitrates = numrates;
2955
1da177e4
LT
2956 /* Set an indication of the max TCP throughput in bit/s that we can
2957 * expect using this interface. May be use for QoS stuff...
2958 * Jean II */
620554e4
CH
2959 if (numrates > 2)
2960 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
1da177e4 2961 else
620554e4
CH
2962 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2963
2964 range->min_rts = 0;
2965 range->max_rts = 2347;
2966 range->min_frag = 256;
2967 range->max_frag = 2346;
2968
2969 range->min_pmp = 0;
2970 range->max_pmp = 65535000;
2971 range->min_pmt = 0;
2972 range->max_pmt = 65535 * 1000; /* ??? */
2973 range->pmp_flags = IW_POWER_PERIOD;
2974 range->pmt_flags = IW_POWER_TIMEOUT;
2975 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2976
2977 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2978 range->retry_flags = IW_RETRY_LIMIT;
2979 range->r_time_flags = IW_RETRY_LIFETIME;
2980 range->min_retry = 0;
2981 range->max_retry = 65535; /* ??? */
2982 range->min_r_time = 0;
2983 range->max_r_time = 65535 * 1000; /* ??? */
1da177e4 2984
0753bba2
DK
2985 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
2986 range->scan_capa = IW_SCAN_CAPA_ESSID;
2987 else
2988 range->scan_capa = IW_SCAN_CAPA_NONE;
2989
343c686c
PR
2990 /* Event capability (kernel) */
2991 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2992 /* Event capability (driver) */
2993 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2994 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2995 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2996 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2997
1da177e4
LT
2998 return 0;
2999}
3000
620554e4
CH
3001static int orinoco_ioctl_setiwencode(struct net_device *dev,
3002 struct iw_request_info *info,
3003 struct iw_point *erq,
3004 char *keybuf)
1da177e4
LT
3005{
3006 struct orinoco_private *priv = netdev_priv(dev);
3007 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3008 int setindex = priv->tx_key;
3009 int enable = priv->wep_on;
3010 int restricted = priv->wep_restrict;
3011 u16 xlen = 0;
620554e4 3012 int err = -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3013 unsigned long flags;
3014
3015 if (! priv->has_wep)
3016 return -EOPNOTSUPP;
3017
3018 if (erq->pointer) {
3019 /* We actually have a key to set - check its length */
3020 if (erq->length > LARGE_KEY_SIZE)
3021 return -E2BIG;
3022
3023 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
3024 return -E2BIG;
1da177e4
LT
3025 }
3026
3027 if (orinoco_lock(priv, &flags) != 0)
3028 return -EBUSY;
3029
fe397d46 3030 if (erq->length > 0) {
1da177e4
LT
3031 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3032 index = priv->tx_key;
3033
3034 /* Adjust key length to a supported value */
3035 if (erq->length > SMALL_KEY_SIZE) {
3036 xlen = LARGE_KEY_SIZE;
3037 } else if (erq->length > 0) {
3038 xlen = SMALL_KEY_SIZE;
3039 } else
3040 xlen = 0;
3041
3042 /* Switch on WEP if off */
3043 if ((!enable) && (xlen > 0)) {
3044 setindex = index;
3045 enable = 1;
3046 }
3047 } else {
3048 /* Important note : if the user do "iwconfig eth0 enc off",
3049 * we will arrive there with an index of -1. This is valid
3050 * but need to be taken care off... Jean II */
3051 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3052 if((index != -1) || (erq->flags == 0)) {
3053 err = -EINVAL;
3054 goto out;
3055 }
3056 } else {
3057 /* Set the index : Check that the key is valid */
3058 if(priv->keys[index].len == 0) {
3059 err = -EINVAL;
3060 goto out;
3061 }
3062 setindex = index;
3063 }
3064 }
3065
3066 if (erq->flags & IW_ENCODE_DISABLED)
3067 enable = 0;
3068 if (erq->flags & IW_ENCODE_OPEN)
3069 restricted = 0;
3070 if (erq->flags & IW_ENCODE_RESTRICTED)
3071 restricted = 1;
3072
fe397d46 3073 if (erq->pointer && erq->length > 0) {
1da177e4
LT
3074 priv->keys[index].len = cpu_to_le16(xlen);
3075 memset(priv->keys[index].data, 0,
3076 sizeof(priv->keys[index].data));
3077 memcpy(priv->keys[index].data, keybuf, erq->length);
3078 }
3079 priv->tx_key = setindex;
3080
3081 /* Try fast key change if connected and only keys are changed */
3082 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
3083 netif_carrier_ok(dev)) {
3084 err = __orinoco_hw_setup_wepkeys(priv);
3085 /* No need to commit if successful */
3086 goto out;
3087 }
3088
3089 priv->wep_on = enable;
3090 priv->wep_restrict = restricted;
3091
3092 out:
3093 orinoco_unlock(priv, &flags);
3094
3095 return err;
3096}
3097
620554e4
CH
3098static int orinoco_ioctl_getiwencode(struct net_device *dev,
3099 struct iw_request_info *info,
3100 struct iw_point *erq,
3101 char *keybuf)
1da177e4
LT
3102{
3103 struct orinoco_private *priv = netdev_priv(dev);
3104 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3105 u16 xlen = 0;
1da177e4
LT
3106 unsigned long flags;
3107
3108 if (! priv->has_wep)
3109 return -EOPNOTSUPP;
3110
3111 if (orinoco_lock(priv, &flags) != 0)
3112 return -EBUSY;
3113
3114 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3115 index = priv->tx_key;
3116
3117 erq->flags = 0;
3118 if (! priv->wep_on)
3119 erq->flags |= IW_ENCODE_DISABLED;
3120 erq->flags |= index + 1;
3121
3122 if (priv->wep_restrict)
3123 erq->flags |= IW_ENCODE_RESTRICTED;
3124 else
3125 erq->flags |= IW_ENCODE_OPEN;
3126
3127 xlen = le16_to_cpu(priv->keys[index].len);
3128
3129 erq->length = xlen;
3130
3131 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3132
3133 orinoco_unlock(priv, &flags);
1da177e4
LT
3134 return 0;
3135}
3136
620554e4
CH
3137static int orinoco_ioctl_setessid(struct net_device *dev,
3138 struct iw_request_info *info,
3139 struct iw_point *erq,
3140 char *essidbuf)
1da177e4
LT
3141{
3142 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3143 unsigned long flags;
3144
3145 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3146 * anyway... - Jean II */
3147
620554e4
CH
3148 /* Hum... Should not use Wireless Extension constant (may change),
3149 * should use our own... - Jean II */
3150 if (erq->length > IW_ESSID_MAX_SIZE)
3151 return -E2BIG;
1da177e4
LT
3152
3153 if (orinoco_lock(priv, &flags) != 0)
3154 return -EBUSY;
3155
620554e4
CH
3156 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3157 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3158
3159 /* If not ANY, get the new ESSID */
3160 if (erq->flags) {
3161 memcpy(priv->desired_essid, essidbuf, erq->length);
3162 }
1da177e4
LT
3163
3164 orinoco_unlock(priv, &flags);
3165
620554e4 3166 return -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3167}
3168
620554e4
CH
3169static int orinoco_ioctl_getessid(struct net_device *dev,
3170 struct iw_request_info *info,
3171 struct iw_point *erq,
3172 char *essidbuf)
1da177e4
LT
3173{
3174 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3175 int active;
3176 int err = 0;
3177 unsigned long flags;
3178
1da177e4
LT
3179 if (netif_running(dev)) {
3180 err = orinoco_hw_get_essid(priv, &active, essidbuf);
7e4e8d99 3181 if (err < 0)
1da177e4 3182 return err;
7e4e8d99 3183 erq->length = err;
1da177e4
LT
3184 } else {
3185 if (orinoco_lock(priv, &flags) != 0)
3186 return -EBUSY;
7e4e8d99
JT
3187 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3188 erq->length = strlen(priv->desired_essid);
1da177e4
LT
3189 orinoco_unlock(priv, &flags);
3190 }
3191
3192 erq->flags = 1;
1da177e4 3193
1da177e4
LT
3194 return 0;
3195}
3196
620554e4
CH
3197static int orinoco_ioctl_setnick(struct net_device *dev,
3198 struct iw_request_info *info,
3199 struct iw_point *nrq,
3200 char *nickbuf)
1da177e4
LT
3201{
3202 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3203 unsigned long flags;
3204
3205 if (nrq->length > IW_ESSID_MAX_SIZE)
3206 return -E2BIG;
3207
1da177e4
LT
3208 if (orinoco_lock(priv, &flags) != 0)
3209 return -EBUSY;
3210
620554e4
CH
3211 memset(priv->nick, 0, sizeof(priv->nick));
3212 memcpy(priv->nick, nickbuf, nrq->length);
1da177e4
LT
3213
3214 orinoco_unlock(priv, &flags);
3215
620554e4 3216 return -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3217}
3218
620554e4
CH
3219static int orinoco_ioctl_getnick(struct net_device *dev,
3220 struct iw_request_info *info,
3221 struct iw_point *nrq,
3222 char *nickbuf)
1da177e4
LT
3223{
3224 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3225 unsigned long flags;
3226
3227 if (orinoco_lock(priv, &flags) != 0)
3228 return -EBUSY;
3229
7e4e8d99 3230 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
1da177e4
LT
3231 orinoco_unlock(priv, &flags);
3232
7e4e8d99 3233 nrq->length = strlen(priv->nick);
1da177e4 3234
1da177e4
LT
3235 return 0;
3236}
3237
620554e4
CH
3238static int orinoco_ioctl_setfreq(struct net_device *dev,
3239 struct iw_request_info *info,
3240 struct iw_freq *frq,
3241 char *extra)
1da177e4
LT
3242{
3243 struct orinoco_private *priv = netdev_priv(dev);
3244 int chan = -1;
3245 unsigned long flags;
620554e4 3246 int err = -EINPROGRESS; /* Call commit handler */
1da177e4 3247
98c4cae1
CH
3248 /* In infrastructure mode the AP sets the channel */
3249 if (priv->iw_mode == IW_MODE_INFRA)
3250 return -EBUSY;
1da177e4
LT
3251
3252 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3253 /* Setting by channel number */
3254 chan = frq->m;
3255 } else {
3256 /* Setting by frequency - search the table */
3257 int mult = 1;
3258 int i;
3259
3260 for (i = 0; i < (6 - frq->e); i++)
3261 mult *= 10;
3262
3263 for (i = 0; i < NUM_CHANNELS; i++)
3264 if (frq->m == (channel_frequency[i] * mult))
3265 chan = i+1;
3266 }
3267
3268 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3269 ! (priv->channel_mask & (1 << (chan-1)) ) )
3270 return -EINVAL;
3271
3272 if (orinoco_lock(priv, &flags) != 0)
3273 return -EBUSY;
98c4cae1 3274
1da177e4 3275 priv->channel = chan;
98c4cae1
CH
3276 if (priv->iw_mode == IW_MODE_MONITOR) {
3277 /* Fast channel change - no commit if successful */
3278 hermes_t *hw = &priv->hw;
3279 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3280 HERMES_TEST_SET_CHANNEL,
3281 chan, NULL);
3282 }
1da177e4
LT
3283 orinoco_unlock(priv, &flags);
3284
620554e4
CH
3285 return err;
3286}
3287
3288static int orinoco_ioctl_getfreq(struct net_device *dev,
3289 struct iw_request_info *info,
3290 struct iw_freq *frq,
3291 char *extra)
3292{
3293 struct orinoco_private *priv = netdev_priv(dev);
3294 int tmp;
3295
3296 /* Locking done in there */
3297 tmp = orinoco_hw_get_freq(priv);
3298 if (tmp < 0) {
3299 return tmp;
3300 }
3301
3302 frq->m = tmp;
3303 frq->e = 1;
3304
1da177e4
LT
3305 return 0;
3306}
3307
620554e4
CH
3308static int orinoco_ioctl_getsens(struct net_device *dev,
3309 struct iw_request_info *info,
3310 struct iw_param *srq,
3311 char *extra)
1da177e4
LT
3312{
3313 struct orinoco_private *priv = netdev_priv(dev);
3314 hermes_t *hw = &priv->hw;
3315 u16 val;
3316 int err;
3317 unsigned long flags;
3318
3319 if (!priv->has_sensitivity)
3320 return -EOPNOTSUPP;
3321
3322 if (orinoco_lock(priv, &flags) != 0)
3323 return -EBUSY;
3324 err = hermes_read_wordrec(hw, USER_BAP,
3325 HERMES_RID_CNFSYSTEMSCALE, &val);
3326 orinoco_unlock(priv, &flags);
3327
3328 if (err)
3329 return err;
3330
3331 srq->value = val;
3332 srq->fixed = 0; /* auto */
3333
3334 return 0;
3335}
3336
620554e4
CH
3337static int orinoco_ioctl_setsens(struct net_device *dev,
3338 struct iw_request_info *info,
3339 struct iw_param *srq,
3340 char *extra)
1da177e4
LT
3341{
3342 struct orinoco_private *priv = netdev_priv(dev);
3343 int val = srq->value;
3344 unsigned long flags;
3345
3346 if (!priv->has_sensitivity)
3347 return -EOPNOTSUPP;
3348
3349 if ((val < 1) || (val > 3))
3350 return -EINVAL;
3351
3352 if (orinoco_lock(priv, &flags) != 0)
3353 return -EBUSY;
3354 priv->ap_density = val;
3355 orinoco_unlock(priv, &flags);
3356
620554e4 3357 return -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3358}
3359
620554e4
CH
3360static int orinoco_ioctl_setrts(struct net_device *dev,
3361 struct iw_request_info *info,
3362 struct iw_param *rrq,
3363 char *extra)
1da177e4
LT
3364{
3365 struct orinoco_private *priv = netdev_priv(dev);
3366 int val = rrq->value;
3367 unsigned long flags;
3368
3369 if (rrq->disabled)
3370 val = 2347;
3371
3372 if ( (val < 0) || (val > 2347) )
3373 return -EINVAL;
3374
3375 if (orinoco_lock(priv, &flags) != 0)
3376 return -EBUSY;
3377
3378 priv->rts_thresh = val;
3379 orinoco_unlock(priv, &flags);
3380
620554e4
CH
3381 return -EINPROGRESS; /* Call commit handler */
3382}
3383
3384static int orinoco_ioctl_getrts(struct net_device *dev,
3385 struct iw_request_info *info,
3386 struct iw_param *rrq,
3387 char *extra)
3388{
3389 struct orinoco_private *priv = netdev_priv(dev);
3390
3391 rrq->value = priv->rts_thresh;
3392 rrq->disabled = (rrq->value == 2347);
3393 rrq->fixed = 1;
3394
1da177e4
LT
3395 return 0;
3396}
3397
620554e4
CH
3398static int orinoco_ioctl_setfrag(struct net_device *dev,
3399 struct iw_request_info *info,
3400 struct iw_param *frq,
3401 char *extra)
1da177e4
LT
3402{
3403 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3404 int err = -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3405 unsigned long flags;
3406
3407 if (orinoco_lock(priv, &flags) != 0)
3408 return -EBUSY;
3409
3410 if (priv->has_mwo) {
3411 if (frq->disabled)
3412 priv->mwo_robust = 0;
3413 else {
3414 if (frq->fixed)
3415 printk(KERN_WARNING "%s: Fixed fragmentation is "
3416 "not supported on this firmware. "
3417 "Using MWO robust instead.\n", dev->name);
3418 priv->mwo_robust = 1;
3419 }
3420 } else {
3421 if (frq->disabled)
3422 priv->frag_thresh = 2346;
3423 else {
3424 if ( (frq->value < 256) || (frq->value > 2346) )
3425 err = -EINVAL;
3426 else
3427 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3428 }
3429 }
3430
3431 orinoco_unlock(priv, &flags);
3432
3433 return err;
3434}
3435
620554e4
CH
3436static int orinoco_ioctl_getfrag(struct net_device *dev,
3437 struct iw_request_info *info,
3438 struct iw_param *frq,
3439 char *extra)
1da177e4
LT
3440{
3441 struct orinoco_private *priv = netdev_priv(dev);
3442 hermes_t *hw = &priv->hw;
620554e4 3443 int err;
1da177e4
LT
3444 u16 val;
3445 unsigned long flags;
3446
3447 if (orinoco_lock(priv, &flags) != 0)
3448 return -EBUSY;
3449
3450 if (priv->has_mwo) {
3451 err = hermes_read_wordrec(hw, USER_BAP,
3452 HERMES_RID_CNFMWOROBUST_AGERE,
3453 &val);
3454 if (err)
3455 val = 0;
3456
3457 frq->value = val ? 2347 : 0;
3458 frq->disabled = ! val;
3459 frq->fixed = 0;
3460 } else {
3461 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3462 &val);
3463 if (err)
3464 val = 0;
3465
3466 frq->value = val;
3467 frq->disabled = (val >= 2346);
3468 frq->fixed = 1;
3469 }
3470
3471 orinoco_unlock(priv, &flags);
3472
3473 return err;
3474}
3475
620554e4
CH
3476static int orinoco_ioctl_setrate(struct net_device *dev,
3477 struct iw_request_info *info,
3478 struct iw_param *rrq,
3479 char *extra)
1da177e4
LT
3480{
3481 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3482 int ratemode = -1;
3483 int bitrate; /* 100s of kilobits */
3484 int i;
3485 unsigned long flags;
3486
3487 /* As the user space doesn't know our highest rate, it uses -1
3488 * to ask us to set the highest rate. Test it using "iwconfig
3489 * ethX rate auto" - Jean II */
3490 if (rrq->value == -1)
3491 bitrate = 110;
3492 else {
3493 if (rrq->value % 100000)
3494 return -EINVAL;
3495 bitrate = rrq->value / 100000;
3496 }
3497
3498 if ( (bitrate != 10) && (bitrate != 20) &&
3499 (bitrate != 55) && (bitrate != 110) )
3500 return -EINVAL;
3501
3502 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3503 if ( (bitrate_table[i].bitrate == bitrate) &&
3504 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3505 ratemode = i;
3506 break;
3507 }
3508
3509 if (ratemode == -1)
3510 return -EINVAL;
3511
3512 if (orinoco_lock(priv, &flags) != 0)
3513 return -EBUSY;
3514 priv->bitratemode = ratemode;
3515 orinoco_unlock(priv, &flags);
3516
620554e4 3517 return -EINPROGRESS;
1da177e4
LT
3518}
3519
620554e4
CH
3520static int orinoco_ioctl_getrate(struct net_device *dev,
3521 struct iw_request_info *info,
3522 struct iw_param *rrq,
3523 char *extra)
1da177e4
LT
3524{
3525 struct orinoco_private *priv = netdev_priv(dev);
3526 hermes_t *hw = &priv->hw;
3527 int err = 0;
3528 int ratemode;
3529 int i;
3530 u16 val;
3531 unsigned long flags;
3532
3533 if (orinoco_lock(priv, &flags) != 0)
3534 return -EBUSY;
3535
3536 ratemode = priv->bitratemode;
3537
3538 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3539
3540 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3541 rrq->fixed = ! bitrate_table[ratemode].automatic;
3542 rrq->disabled = 0;
3543
3544 /* If the interface is running we try to find more about the
3545 current mode */
3546 if (netif_running(dev)) {
3547 err = hermes_read_wordrec(hw, USER_BAP,
3548 HERMES_RID_CURRENTTXRATE, &val);
3549 if (err)
3550 goto out;
3551
3552 switch (priv->firmware_type) {
3553 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3554 /* Note : in Lucent firmware, the return value of
3555 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3556 * and therefore is totally different from the
3557 * encoding of HERMES_RID_CNFTXRATECONTROL.
3558 * Don't forget that 6Mb/s is really 5.5Mb/s */
3559 if (val == 6)
3560 rrq->value = 5500000;
3561 else
3562 rrq->value = val * 1000000;
3563 break;
3564 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3565 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3566 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3567 if (bitrate_table[i].intersil_txratectrl == val) {
3568 ratemode = i;
3569 break;
3570 }
3571 if (i >= BITRATE_TABLE_SIZE)
3572 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3573 dev->name, val);
3574
3575 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3576 break;
3577 default:
3578 BUG();
3579 }
3580 }
3581
3582 out:
3583 orinoco_unlock(priv, &flags);
3584
3585 return err;
3586}
3587
620554e4
CH
3588static int orinoco_ioctl_setpower(struct net_device *dev,
3589 struct iw_request_info *info,
3590 struct iw_param *prq,
3591 char *extra)
1da177e4
LT
3592{
3593 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3594 int err = -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3595 unsigned long flags;
3596
3597 if (orinoco_lock(priv, &flags) != 0)
3598 return -EBUSY;
3599
3600 if (prq->disabled) {
3601 priv->pm_on = 0;
3602 } else {
3603 switch (prq->flags & IW_POWER_MODE) {
3604 case IW_POWER_UNICAST_R:
3605 priv->pm_mcast = 0;
3606 priv->pm_on = 1;
3607 break;
3608 case IW_POWER_ALL_R:
3609 priv->pm_mcast = 1;
3610 priv->pm_on = 1;
3611 break;
3612 case IW_POWER_ON:
3613 /* No flags : but we may have a value - Jean II */
3614 break;
3615 default:
3616 err = -EINVAL;
1da177e4 3617 goto out;
c08ad1e3 3618 }
1da177e4
LT
3619
3620 if (prq->flags & IW_POWER_TIMEOUT) {
3621 priv->pm_on = 1;
3622 priv->pm_timeout = prq->value / 1000;
3623 }
3624 if (prq->flags & IW_POWER_PERIOD) {
3625 priv->pm_on = 1;
3626 priv->pm_period = prq->value / 1000;
3627 }
3628 /* It's valid to not have a value if we are just toggling
3629 * the flags... Jean II */
3630 if(!priv->pm_on) {
3631 err = -EINVAL;
3632 goto out;
3633 }
3634 }
3635
3636 out:
3637 orinoco_unlock(priv, &flags);
3638
3639 return err;
3640}
3641
620554e4
CH
3642static int orinoco_ioctl_getpower(struct net_device *dev,
3643 struct iw_request_info *info,
3644 struct iw_param *prq,
3645 char *extra)
1da177e4
LT
3646{
3647 struct orinoco_private *priv = netdev_priv(dev);
3648 hermes_t *hw = &priv->hw;
3649 int err = 0;
3650 u16 enable, period, timeout, mcast;
3651 unsigned long flags;
3652
3653 if (orinoco_lock(priv, &flags) != 0)
3654 return -EBUSY;
3655
3656 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3657 if (err)
3658 goto out;
3659
3660 err = hermes_read_wordrec(hw, USER_BAP,
3661 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3662 if (err)
3663 goto out;
3664
3665 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3666 if (err)
3667 goto out;
3668
3669 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3670 if (err)
3671 goto out;
3672
3673 prq->disabled = !enable;
3674 /* Note : by default, display the period */
3675 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3676 prq->flags = IW_POWER_TIMEOUT;
3677 prq->value = timeout * 1000;
3678 } else {
3679 prq->flags = IW_POWER_PERIOD;
3680 prq->value = period * 1000;
3681 }
3682 if (mcast)
3683 prq->flags |= IW_POWER_ALL_R;
3684 else
3685 prq->flags |= IW_POWER_UNICAST_R;
3686
3687 out:
3688 orinoco_unlock(priv, &flags);
3689
3690 return err;
3691}
3692
620554e4
CH
3693static int orinoco_ioctl_getretry(struct net_device *dev,
3694 struct iw_request_info *info,
3695 struct iw_param *rrq,
3696 char *extra)
1da177e4
LT
3697{
3698 struct orinoco_private *priv = netdev_priv(dev);
3699 hermes_t *hw = &priv->hw;
3700 int err = 0;
3701 u16 short_limit, long_limit, lifetime;
3702 unsigned long flags;
3703
3704 if (orinoco_lock(priv, &flags) != 0)
3705 return -EBUSY;
3706
3707 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3708 &short_limit);
3709 if (err)
3710 goto out;
3711
3712 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3713 &long_limit);
3714 if (err)
3715 goto out;
3716
3717 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3718 &lifetime);
3719 if (err)
3720 goto out;
3721
3722 rrq->disabled = 0; /* Can't be disabled */
3723
3724 /* Note : by default, display the retry number */
3725 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3726 rrq->flags = IW_RETRY_LIFETIME;
3727 rrq->value = lifetime * 1000; /* ??? */
3728 } else {
3729 /* By default, display the min number */
eeec9f1a
JT
3730 if ((rrq->flags & IW_RETRY_LONG)) {
3731 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1da177e4
LT
3732 rrq->value = long_limit;
3733 } else {
3734 rrq->flags = IW_RETRY_LIMIT;
3735 rrq->value = short_limit;
3736 if(short_limit != long_limit)
eeec9f1a 3737 rrq->flags |= IW_RETRY_SHORT;
1da177e4
LT
3738 }
3739 }
3740
3741 out:
3742 orinoco_unlock(priv, &flags);
3743
3744 return err;
3745}
3746
620554e4
CH
3747static int orinoco_ioctl_reset(struct net_device *dev,
3748 struct iw_request_info *info,
3749 void *wrqu,
3750 char *extra)
3751{
3752 struct orinoco_private *priv = netdev_priv(dev);
3753
3754 if (! capable(CAP_NET_ADMIN))
3755 return -EPERM;
3756
3757 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3758 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3759
3760 /* Firmware reset */
c4028958 3761 orinoco_reset(&priv->reset_work);
620554e4
CH
3762 } else {
3763 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3764
3765 schedule_work(&priv->reset_work);
3766 }
3767
3768 return 0;
3769}
3770
3771static int orinoco_ioctl_setibssport(struct net_device *dev,
3772 struct iw_request_info *info,
3773 void *wrqu,
3774 char *extra)
3775
1da177e4
LT
3776{
3777 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3778 int val = *( (int *) extra );
1da177e4
LT
3779 unsigned long flags;
3780
3781 if (orinoco_lock(priv, &flags) != 0)
3782 return -EBUSY;
3783
3784 priv->ibss_port = val ;
3785
3786 /* Actually update the mode we are using */
3787 set_port_type(priv);
3788
3789 orinoco_unlock(priv, &flags);
620554e4 3790 return -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3791}
3792
620554e4
CH
3793static int orinoco_ioctl_getibssport(struct net_device *dev,
3794 struct iw_request_info *info,
3795 void *wrqu,
3796 char *extra)
1da177e4
LT
3797{
3798 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3799 int *val = (int *) extra;
1da177e4
LT
3800
3801 *val = priv->ibss_port;
1da177e4
LT
3802 return 0;
3803}
3804
620554e4
CH
3805static int orinoco_ioctl_setport3(struct net_device *dev,
3806 struct iw_request_info *info,
3807 void *wrqu,
3808 char *extra)
1da177e4
LT
3809{
3810 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3811 int val = *( (int *) extra );
1da177e4
LT
3812 int err = 0;
3813 unsigned long flags;
3814
3815 if (orinoco_lock(priv, &flags) != 0)
3816 return -EBUSY;
3817
3818 switch (val) {
3819 case 0: /* Try to do IEEE ad-hoc mode */
3820 if (! priv->has_ibss) {
3821 err = -EINVAL;
3822 break;
3823 }
3824 priv->prefer_port3 = 0;
3825
3826 break;
3827
3828 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3829 if (! priv->has_port3) {
3830 err = -EINVAL;
3831 break;
3832 }
3833 priv->prefer_port3 = 1;
3834 break;
3835
3836 default:
3837 err = -EINVAL;
3838 }
3839
620554e4 3840 if (! err) {
1da177e4
LT
3841 /* Actually update the mode we are using */
3842 set_port_type(priv);
620554e4
CH
3843 err = -EINPROGRESS;
3844 }
1da177e4
LT
3845
3846 orinoco_unlock(priv, &flags);
3847
3848 return err;
3849}
3850
620554e4
CH
3851static int orinoco_ioctl_getport3(struct net_device *dev,
3852 struct iw_request_info *info,
3853 void *wrqu,
3854 char *extra)
3855{
3856 struct orinoco_private *priv = netdev_priv(dev);
3857 int *val = (int *) extra;
3858
3859 *val = priv->prefer_port3;
3860 return 0;
3861}
3862
3863static int orinoco_ioctl_setpreamble(struct net_device *dev,
3864 struct iw_request_info *info,
3865 void *wrqu,
3866 char *extra)
1da177e4
LT
3867{
3868 struct orinoco_private *priv = netdev_priv(dev);
1da177e4 3869 unsigned long flags;
620554e4
CH
3870 int val;
3871
3872 if (! priv->has_preamble)
3873 return -EOPNOTSUPP;
3874
3875 /* 802.11b has recently defined some short preamble.
3876 * Basically, the Phy header has been reduced in size.
3877 * This increase performance, especially at high rates
3878 * (the preamble is transmitted at 1Mb/s), unfortunately
3879 * this give compatibility troubles... - Jean II */
3880 val = *( (int *) extra );
1da177e4
LT
3881
3882 if (orinoco_lock(priv, &flags) != 0)
3883 return -EBUSY;
3884
620554e4
CH
3885 if (val)
3886 priv->preamble = 1;
3887 else
3888 priv->preamble = 0;
3889
1da177e4 3890 orinoco_unlock(priv, &flags);
620554e4
CH
3891
3892 return -EINPROGRESS; /* Call commit handler */
3893}
3894
3895static int orinoco_ioctl_getpreamble(struct net_device *dev,
3896 struct iw_request_info *info,
3897 void *wrqu,
3898 char *extra)
3899{
3900 struct orinoco_private *priv = netdev_priv(dev);
3901 int *val = (int *) extra;
3902
3903 if (! priv->has_preamble)
3904 return -EOPNOTSUPP;
3905
3906 *val = priv->preamble;
1da177e4
LT
3907 return 0;
3908}
3909
620554e4
CH
3910/* ioctl interface to hermes_read_ltv()
3911 * To use with iwpriv, pass the RID as the token argument, e.g.
3912 * iwpriv get_rid [0xfc00]
3913 * At least Wireless Tools 25 is required to use iwpriv.
3914 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3915static int orinoco_ioctl_getrid(struct net_device *dev,
3916 struct iw_request_info *info,
3917 struct iw_point *data,
3918 char *extra)
3919{
3920 struct orinoco_private *priv = netdev_priv(dev);
3921 hermes_t *hw = &priv->hw;
3922 int rid = data->flags;
3923 u16 length;
3924 int err;
3925 unsigned long flags;
3926
3927 /* It's a "get" function, but we don't want users to access the
3928 * WEP key and other raw firmware data */
3929 if (! capable(CAP_NET_ADMIN))
3930 return -EPERM;
3931
3932 if (rid < 0xfc00 || rid > 0xffff)
3933 return -EINVAL;
3934
3935 if (orinoco_lock(priv, &flags) != 0)
3936 return -EBUSY;
3937
3938 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3939 extra);
3940 if (err)
3941 goto out;
3942
3943 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3944 MAX_RID_LEN);
3945
3946 out:
3947 orinoco_unlock(priv, &flags);
3948 return err;
3949}
3950
17a1a887 3951/* Trigger a scan (look for other cells in the vicinity) */
95dd91fb
CH
3952static int orinoco_ioctl_setscan(struct net_device *dev,
3953 struct iw_request_info *info,
3954 struct iw_param *srq,
3955 char *extra)
1da177e4
LT
3956{
3957 struct orinoco_private *priv = netdev_priv(dev);
95dd91fb 3958 hermes_t *hw = &priv->hw;
0753bba2 3959 struct iw_scan_req *si = (struct iw_scan_req *) extra;
1da177e4 3960 int err = 0;
1da177e4
LT
3961 unsigned long flags;
3962
95dd91fb 3963 /* Note : you may have realised that, as this is a SET operation,
7f927fcc 3964 * this is privileged and therefore a normal user can't
95dd91fb
CH
3965 * perform scanning.
3966 * This is not an error, while the device perform scanning,
3967 * traffic doesn't flow, so it's a perfect DoS...
3968 * Jean II */
1da177e4 3969
95dd91fb
CH
3970 if (orinoco_lock(priv, &flags) != 0)
3971 return -EBUSY;
1da177e4 3972
95dd91fb
CH
3973 /* Scanning with port 0 disabled would fail */
3974 if (!netif_running(dev)) {
3975 err = -ENETDOWN;
3976 goto out;
3977 }
1da177e4 3978
95dd91fb
CH
3979 /* In monitor mode, the scan results are always empty.
3980 * Probe responses are passed to the driver as received
3981 * frames and could be processed in software. */
3982 if (priv->iw_mode == IW_MODE_MONITOR) {
3983 err = -EOPNOTSUPP;
3984 goto out;
3985 }
1da177e4 3986
95dd91fb
CH
3987 /* Note : because we don't lock out the irq handler, the way
3988 * we access scan variables in priv is critical.
3989 * o scan_inprogress : not touched by irq handler
3990 * o scan_mode : not touched by irq handler
95dd91fb
CH
3991 * Before modifying anything on those variables, please think hard !
3992 * Jean II */
1da177e4 3993
95dd91fb
CH
3994 /* Save flags */
3995 priv->scan_mode = srq->flags;
1da177e4 3996
95dd91fb
CH
3997 /* Always trigger scanning, even if it's in progress.
3998 * This way, if the info frame get lost, we will recover somewhat
3999 * gracefully - Jean II */
1da177e4 4000
95dd91fb
CH
4001 if (priv->has_hostscan) {
4002 switch (priv->firmware_type) {
4003 case FIRMWARE_TYPE_SYMBOL:
4004 err = hermes_write_wordrec(hw, USER_BAP,
4005 HERMES_RID_CNFHOSTSCAN_SYMBOL,
4006 HERMES_HOSTSCAN_SYMBOL_ONCE |
4007 HERMES_HOSTSCAN_SYMBOL_BCAST);
4008 break;
4009 case FIRMWARE_TYPE_INTERSIL: {
d133ae4c 4010 __le16 req[3];
95dd91fb
CH
4011
4012 req[0] = cpu_to_le16(0x3fff); /* All channels */
4013 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4014 req[2] = 0; /* Any ESSID */
4015 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4016 HERMES_RID_CNFHOSTSCAN, &req);
4017 }
1da177e4 4018 break;
95dd91fb 4019 case FIRMWARE_TYPE_AGERE:
0753bba2
DK
4020 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
4021 struct hermes_idstring idbuf;
4022 size_t len = min(sizeof(idbuf.val),
4023 (size_t) si->essid_len);
4024 idbuf.len = cpu_to_le16(len);
4025 memcpy(idbuf.val, si->essid, len);
4026
4027 err = hermes_write_ltv(hw, USER_BAP,
4028 HERMES_RID_CNFSCANSSID_AGERE,
4029 HERMES_BYTES_TO_RECLEN(len + 2),
4030 &idbuf);
4031 } else
4032 err = hermes_write_wordrec(hw, USER_BAP,
95dd91fb
CH
4033 HERMES_RID_CNFSCANSSID_AGERE,
4034 0); /* Any ESSID */
4035 if (err)
4036 break;
1da177e4 4037
95dd91fb 4038 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1da177e4
LT
4039 break;
4040 }
95dd91fb
CH
4041 } else
4042 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1da177e4 4043
95dd91fb
CH
4044 /* One more client */
4045 if (! err)
4046 priv->scan_inprogress = 1;
1da177e4 4047
95dd91fb
CH
4048 out:
4049 orinoco_unlock(priv, &flags);
4050 return err;
4051}
1da177e4 4052
1e3428e9
DW
4053#define MAX_CUSTOM_LEN 64
4054
95dd91fb 4055/* Translate scan data returned from the card to a card independant
17a1a887 4056 * format that the Wireless Tools will understand - Jean II */
1e3428e9 4057static inline char *orinoco_translate_scan(struct net_device *dev,
ccc58057 4058 struct iw_request_info *info,
1e3428e9
DW
4059 char *current_ev,
4060 char *end_buf,
4061 union hermes_scan_info *bss,
4062 unsigned int last_scanned)
95dd91fb
CH
4063{
4064 struct orinoco_private *priv = netdev_priv(dev);
95dd91fb
CH
4065 u16 capabilities;
4066 u16 channel;
4067 struct iw_event iwe; /* Temporary buffer */
1e3428e9
DW
4068 char custom[MAX_CUSTOM_LEN];
4069
17a1a887
DK
4070 memset(&iwe, 0, sizeof(iwe));
4071
1e3428e9
DW
4072 /* First entry *MUST* be the AP MAC address */
4073 iwe.cmd = SIOCGIWAP;
4074 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4075 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
ccc58057
DM
4076 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4077 &iwe, IW_EV_ADDR_LEN);
1e3428e9
DW
4078
4079 /* Other entries will be displayed in the order we give them */
4080
4081 /* Add the ESSID */
4082 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
4083 if (iwe.u.data.length > 32)
4084 iwe.u.data.length = 32;
4085 iwe.cmd = SIOCGIWESSID;
4086 iwe.u.data.flags = 1;
ccc58057
DM
4087 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4088 &iwe, bss->a.essid);
1e3428e9
DW
4089
4090 /* Add mode */
4091 iwe.cmd = SIOCGIWMODE;
4092 capabilities = le16_to_cpu(bss->a.capabilities);
17a1a887
DK
4093 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
4094 if (capabilities & WLAN_CAPABILITY_ESS)
1e3428e9 4095 iwe.u.mode = IW_MODE_MASTER;
95dd91fb 4096 else
1e3428e9 4097 iwe.u.mode = IW_MODE_ADHOC;
ccc58057
DM
4098 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4099 &iwe, IW_EV_UINT_LEN);
95dd91fb 4100 }
1da177e4 4101
1e3428e9
DW
4102 channel = bss->s.channel;
4103 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
17a1a887 4104 /* Add channel and frequency */
1e3428e9 4105 iwe.cmd = SIOCGIWFREQ;
17a1a887
DK
4106 iwe.u.freq.m = channel;
4107 iwe.u.freq.e = 0;
4108 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4109 &iwe, IW_EV_FREQ_LEN);
4110
1e3428e9
DW
4111 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4112 iwe.u.freq.e = 1;
ccc58057 4113 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1e3428e9 4114 &iwe, IW_EV_FREQ_LEN);
95dd91fb 4115 }
1da177e4 4116
17a1a887 4117 /* Add quality statistics. level and noise in dB. No link quality */
1e3428e9 4118 iwe.cmd = IWEVQUAL;
17a1a887 4119 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
1e3428e9
DW
4120 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
4121 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
4122 /* Wireless tools prior to 27.pre22 will show link quality
4123 * anyway, so we provide a reasonable value. */
4124 if (iwe.u.qual.level > iwe.u.qual.noise)
4125 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4126 else
4127 iwe.u.qual.qual = 0;
ccc58057
DM
4128 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4129 &iwe, IW_EV_QUAL_LEN);
1da177e4 4130
1e3428e9
DW
4131 /* Add encryption capability */
4132 iwe.cmd = SIOCGIWENCODE;
17a1a887 4133 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1e3428e9
DW
4134 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4135 else
4136 iwe.u.data.flags = IW_ENCODE_DISABLED;
4137 iwe.u.data.length = 0;
ccc58057 4138 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
17a1a887 4139 &iwe, NULL);
1e3428e9
DW
4140
4141 /* Bit rate is not available in Lucent/Agere firmwares */
4142 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
ccc58057 4143 char *current_val = current_ev + iwe_stream_lcp_len(info);
1e3428e9
DW
4144 int i;
4145 int step;
1da177e4 4146
1e3428e9
DW
4147 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4148 step = 2;
95dd91fb 4149 else
1e3428e9
DW
4150 step = 1;
4151
4152 iwe.cmd = SIOCGIWRATE;
4153 /* Those two flags are ignored... */
4154 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4155 /* Max 10 values */
4156 for (i = 0; i < 10; i += step) {
4157 /* NULL terminated */
4158 if (bss->p.rates[i] == 0x0)
4159 break;
4160 /* Bit rate given in 500 kb/s units (+ 0x80) */
17a1a887
DK
4161 iwe.u.bitrate.value =
4162 ((bss->p.rates[i] & 0x7f) * 500000);
ccc58057
DM
4163 current_val = iwe_stream_add_value(info, current_ev,
4164 current_val,
1e3428e9
DW
4165 end_buf, &iwe,
4166 IW_EV_PARAM_LEN);
95dd91fb 4167 }
1e3428e9 4168 /* Check if we added any event */
ccc58057 4169 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
1e3428e9 4170 current_ev = current_val;
95dd91fb 4171 }
1e3428e9 4172
17a1a887
DK
4173 /* Beacon interval */
4174 iwe.cmd = IWEVCUSTOM;
4175 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4176 "bcn_int=%d",
4177 le16_to_cpu(bss->a.beacon_interv));
4178 if (iwe.u.data.length)
4179 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4180 &iwe, custom);
4181
4182 /* Capabilites */
4183 iwe.cmd = IWEVCUSTOM;
4184 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4185 "capab=0x%04x",
4186 capabilities);
4187 if (iwe.u.data.length)
4188 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4189 &iwe, custom);
4190
4191 /* Add EXTRA: Age to display seconds since last beacon/probe response
4192 * for given network. */
4193 iwe.cmd = IWEVCUSTOM;
4194 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4195 " Last beacon: %dms ago",
4196 jiffies_to_msecs(jiffies - last_scanned));
4197 if (iwe.u.data.length)
4198 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4199 &iwe, custom);
4200
1e3428e9 4201 return current_ev;
95dd91fb 4202}
1da177e4 4203
95dd91fb
CH
4204/* Return results of a scan */
4205static int orinoco_ioctl_getscan(struct net_device *dev,
4206 struct iw_request_info *info,
4207 struct iw_point *srq,
4208 char *extra)
4209{
4210 struct orinoco_private *priv = netdev_priv(dev);
1e3428e9 4211 bss_element *bss;
95dd91fb
CH
4212 int err = 0;
4213 unsigned long flags;
1e3428e9 4214 char *current_ev = extra;
1da177e4 4215
95dd91fb
CH
4216 if (orinoco_lock(priv, &flags) != 0)
4217 return -EBUSY;
1da177e4 4218
1e3428e9
DW
4219 if (priv->scan_inprogress) {
4220 /* Important note : we don't want to block the caller
4221 * until results are ready for various reasons.
4222 * First, managing wait queues is complex and racy.
4223 * Second, we grab some rtnetlink lock before comming
4224 * here (in dev_ioctl()).
4225 * Third, we generate an Wireless Event, so the
4226 * caller can wait itself on that - Jean II */
4227 err = -EAGAIN;
4228 goto out;
4229 }
95dd91fb 4230
1e3428e9
DW
4231 list_for_each_entry(bss, &priv->bss_list, list) {
4232 /* Translate to WE format this entry */
ccc58057 4233 current_ev = orinoco_translate_scan(dev, info, current_ev,
1e3428e9
DW
4234 extra + srq->length,
4235 &bss->bss,
4236 bss->last_scanned);
4237
4238 /* Check if there is space for one more entry */
4239 if ((extra + srq->length - current_ev) <= IW_EV_ADDR_LEN) {
4240 /* Ask user space to try again with a bigger buffer */
4241 err = -E2BIG;
4242 goto out;
70817c40 4243 }
95dd91fb 4244 }
1e3428e9
DW
4245
4246 srq->length = (current_ev - extra);
4247 srq->flags = (__u16) priv->scan_mode;
4248
4249out:
95dd91fb
CH
4250 orinoco_unlock(priv, &flags);
4251 return err;
4252}
1da177e4 4253
620554e4
CH
4254/* Commit handler, called after set operations */
4255static int orinoco_ioctl_commit(struct net_device *dev,
4256 struct iw_request_info *info,
4257 void *wrqu,
4258 char *extra)
1da177e4
LT
4259{
4260 struct orinoco_private *priv = netdev_priv(dev);
620554e4 4261 struct hermes *hw = &priv->hw;
1da177e4 4262 unsigned long flags;
620554e4 4263 int err = 0;
1da177e4 4264
620554e4
CH
4265 if (!priv->open)
4266 return 0;
1da177e4 4267
620554e4 4268 if (priv->broken_disableport) {
c4028958 4269 orinoco_reset(&priv->reset_work);
620554e4
CH
4270 return 0;
4271 }
1da177e4 4272
620554e4
CH
4273 if (orinoco_lock(priv, &flags) != 0)
4274 return err;
1da177e4 4275
620554e4
CH
4276 err = hermes_disable_port(hw, 0);
4277 if (err) {
4278 printk(KERN_WARNING "%s: Unable to disable port "
4279 "while reconfiguring card\n", dev->name);
4280 priv->broken_disableport = 1;
4281 goto out;
4282 }
1da177e4 4283
620554e4
CH
4284 err = __orinoco_program_rids(dev);
4285 if (err) {
4286 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4287 dev->name);
4288 goto out;
4289 }
1da177e4 4290
620554e4
CH
4291 err = hermes_enable_port(hw, 0);
4292 if (err) {
4293 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4294 dev->name);
4295 goto out;
4296 }
1da177e4 4297
620554e4
CH
4298 out:
4299 if (err) {
4300 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
1da177e4 4301 schedule_work(&priv->reset_work);
620554e4
CH
4302 err = 0;
4303 }
1da177e4 4304
620554e4
CH
4305 orinoco_unlock(priv, &flags);
4306 return err;
4307}
1da177e4 4308
620554e4
CH
4309static const struct iw_priv_args orinoco_privtab[] = {
4310 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4311 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4312 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4313 0, "set_port3" },
4314 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4315 "get_port3" },
4316 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4317 0, "set_preamble" },
4318 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4319 "get_preamble" },
4320 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4321 0, "set_ibssport" },
4322 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4323 "get_ibssport" },
4324 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4325 "get_rid" },
4326};
1da177e4 4327
1da177e4 4328
620554e4
CH
4329/*
4330 * Structures to export the Wireless Handlers
4331 */
1da177e4 4332
620554e4 4333static const iw_handler orinoco_handler[] = {
6b9b97ce
PH
4334 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4335 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4336 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4337 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4338 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4339 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4340 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4341 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4342 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
343c686c
PR
4343 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4344 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4345 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4346 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
6b9b97ce
PH
4347 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4348 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4349 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4350 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4351 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4352 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4353 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4354 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4355 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4356 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4357 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4358 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4359 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4360 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4361 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4362 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4363 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4364 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4365 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
620554e4 4366};
1da177e4 4367
1da177e4 4368
620554e4
CH
4369/*
4370 Added typecasting since we no longer use iwreq_data -- Moustafa
4371 */
4372static const iw_handler orinoco_private_handler[] = {
6b9b97ce
PH
4373 [0] = (iw_handler) orinoco_ioctl_reset,
4374 [1] = (iw_handler) orinoco_ioctl_reset,
4375 [2] = (iw_handler) orinoco_ioctl_setport3,
4376 [3] = (iw_handler) orinoco_ioctl_getport3,
4377 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4378 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4379 [6] = (iw_handler) orinoco_ioctl_setibssport,
4380 [7] = (iw_handler) orinoco_ioctl_getibssport,
4381 [9] = (iw_handler) orinoco_ioctl_getrid,
620554e4 4382};
1da177e4 4383
620554e4
CH
4384static const struct iw_handler_def orinoco_handler_def = {
4385 .num_standard = ARRAY_SIZE(orinoco_handler),
4386 .num_private = ARRAY_SIZE(orinoco_private_handler),
4387 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4388 .standard = orinoco_handler,
4389 .private = orinoco_private_handler,
4390 .private_args = orinoco_privtab,
343c686c 4391 .get_wireless_stats = orinoco_get_wireless_stats,
620554e4 4392};
1da177e4 4393
1fab2e8b
CH
4394static void orinoco_get_drvinfo(struct net_device *dev,
4395 struct ethtool_drvinfo *info)
4396{
4397 struct orinoco_private *priv = netdev_priv(dev);
1da177e4 4398
1fab2e8b
CH
4399 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4400 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4401 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
43cb76d9
GKH
4402 if (dev->dev.parent)
4403 strncpy(info->bus_info, dev->dev.parent->bus_id,
1fab2e8b
CH
4404 sizeof(info->bus_info) - 1);
4405 else
4406 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4407 "PCMCIA %p", priv->hw.iobase);
1da177e4
LT
4408}
4409
7282d491 4410static const struct ethtool_ops orinoco_ethtool_ops = {
1fab2e8b
CH
4411 .get_drvinfo = orinoco_get_drvinfo,
4412 .get_link = ethtool_op_get_link,
4413};
1da177e4 4414
1da177e4
LT
4415/********************************************************************/
4416/* Module initialization */
4417/********************************************************************/
4418
4419EXPORT_SYMBOL(alloc_orinocodev);
4420EXPORT_SYMBOL(free_orinocodev);
4421
4422EXPORT_SYMBOL(__orinoco_up);
4423EXPORT_SYMBOL(__orinoco_down);
1da177e4
LT
4424EXPORT_SYMBOL(orinoco_reinit_firmware);
4425
4426EXPORT_SYMBOL(orinoco_interrupt);
4427
4428/* Can't be declared "const" or the whole __initdata section will
4429 * become const */
4430static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4431 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4432 "Pavel Roskin <proski@gnu.org>, et al)";
4433
4434static int __init init_orinoco(void)
4435{
4436 printk(KERN_DEBUG "%s\n", version);
4437 return 0;
4438}
4439
4440static void __exit exit_orinoco(void)
4441{
4442}
4443
4444module_init(init_orinoco);
4445module_exit(exit_orinoco);
This page took 0.677846 seconds and 5 git commands to generate.