blob: 70a3477a20613285c51007ce01b7aa07a7b7fb57 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 * 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
79#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#include <linux/module.h>
81#include <linux/kernel.h>
82#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include <linux/etherdevice.h>
Christoph Hellwig1fab2e82005-06-19 01:27:40 +020085#include <linux/ethtool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#include <linux/wireless.h>
Christoph Hellwig620554e2005-06-19 01:27:33 +020087#include <net/iw_handler.h>
Christoph Hellwig5d558b72005-06-19 01:27:28 +020088#include <net/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#include "hermes_rid.h"
91#include "orinoco.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
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");
David Gibson7bb7c3a2005-05-12 20:02:10 -0400112static int ignore_disconnect; /* = 0 */
113module_param(ignore_disconnect, int, 0644);
114MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200116static int force_monitor; /* = 0 */
117module_param(force_monitor, int, 0644);
118MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120/********************************************************************/
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
Pavel Roskin343c6862005-09-09 18:43:02 -0400126#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#else
128#define SPY_NUMBER(priv) 0
129#endif /* WIRELESS_SPY */
130
131/********************************************************************/
132/* Internal constants */
133/********************************************************************/
134
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200135/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define ORINOCO_MIN_MTU 256
Jeff Garzikb4538722005-05-12 22:48:20 -0400140#define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
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
Christoph Hellwig620554e2005-06-19 01:27:33 +0200165#define MAX_RID_LEN 1024
166
167static const struct iw_handler_def orinoco_handler_def;
Christoph Hellwig1fab2e82005-06-19 01:27:40 +0200168static struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/********************************************************************/
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
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200204/* Used in Event handling.
Pavel Roskind133ae42005-09-23 04:18:06 -0400205 * We avoid nested structures as they break on ARM -- Moustafa */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200206struct hermes_tx_descriptor_802_11 {
207 /* hermes_tx_descriptor */
Pavel Roskind133ae42005-09-23 04:18:06 -0400208 __le16 status;
209 __le16 reserved1;
210 __le16 reserved2;
211 __le32 sw_support;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200212 u8 retry_count;
213 u8 tx_rate;
Pavel Roskind133ae42005-09-23 04:18:06 -0400214 __le16 tx_control;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200215
Pavel Roskind133ae42005-09-23 04:18:06 -0400216 /* ieee80211_hdr */
217 __le16 frame_ctl;
218 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200219 u8 addr1[ETH_ALEN];
220 u8 addr2[ETH_ALEN];
221 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400222 __le16 seq_ctl;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200223 u8 addr4[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400224
225 __le16 data_len;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200226
227 /* ethhdr */
Pavel Roskind133ae42005-09-23 04:18:06 -0400228 u8 h_dest[ETH_ALEN]; /* destination eth addr */
229 u8 h_source[ETH_ALEN]; /* source ether addr */
230 __be16 h_proto; /* packet type ID field */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200231
232 /* p8022_hdr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 u8 dsap;
234 u8 ssap;
235 u8 ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 u8 oui[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200237
Pavel Roskind133ae42005-09-23 04:18:06 -0400238 __be16 ethertype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239} __attribute__ ((packed));
240
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200241/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200243 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400244 __le16 status;
245 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 u8 silence;
247 u8 signal;
248 u8 rate;
249 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400250 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200251
252 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400253 __le16 frame_ctl;
254 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200255 u8 addr1[ETH_ALEN];
256 u8 addr2[ETH_ALEN];
257 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400258 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200259 u8 addr4[ETH_ALEN];
260
261 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400262 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263} __attribute__ ((packed));
264
265/********************************************************************/
266/* Function prototypes */
267/********************************************************************/
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269static int __orinoco_program_rids(struct net_device *dev);
270static void __orinoco_set_multicast_list(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272/********************************************************************/
273/* Internal helper functions */
274/********************************************************************/
275
276static inline void set_port_type(struct orinoco_private *priv)
277{
278 switch (priv->iw_mode) {
279 case IW_MODE_INFRA:
280 priv->port_type = 1;
281 priv->createibss = 0;
282 break;
283 case IW_MODE_ADHOC:
284 if (priv->prefer_port3) {
285 priv->port_type = 3;
286 priv->createibss = 0;
287 } else {
288 priv->port_type = priv->ibss_port;
289 priv->createibss = 1;
290 }
291 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200292 case IW_MODE_MONITOR:
293 priv->port_type = 3;
294 priv->createibss = 0;
295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 default:
297 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
298 priv->ndev->name);
299 }
300}
301
302/********************************************************************/
303/* Device methods */
304/********************************************************************/
305
306static int orinoco_open(struct net_device *dev)
307{
308 struct orinoco_private *priv = netdev_priv(dev);
309 unsigned long flags;
310 int err;
311
312 if (orinoco_lock(priv, &flags) != 0)
313 return -EBUSY;
314
315 err = __orinoco_up(dev);
316
317 if (! err)
318 priv->open = 1;
319
320 orinoco_unlock(priv, &flags);
321
322 return err;
323}
324
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200325static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 struct orinoco_private *priv = netdev_priv(dev);
328 int err = 0;
329
330 /* We mustn't use orinoco_lock() here, because we need to be
331 able to close the interface even if hw_unavailable is set
332 (e.g. as we're released after a PC Card removal) */
333 spin_lock_irq(&priv->lock);
334
335 priv->open = 0;
336
337 err = __orinoco_down(dev);
338
339 spin_unlock_irq(&priv->lock);
340
341 return err;
342}
343
344static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
345{
346 struct orinoco_private *priv = netdev_priv(dev);
347
348 return &priv->stats;
349}
350
351static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
352{
353 struct orinoco_private *priv = netdev_priv(dev);
354 hermes_t *hw = &priv->hw;
355 struct iw_statistics *wstats = &priv->wstats;
David Gibsone67d9d92005-05-12 20:01:22 -0400356 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 unsigned long flags;
358
359 if (! netif_device_present(dev)) {
360 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
361 dev->name);
362 return NULL; /* FIXME: Can we do better than this? */
363 }
364
David Gibsone67d9d92005-05-12 20:01:22 -0400365 /* If busy, return the old stats. Returning NULL may cause
366 * the interface to disappear from /proc/net/wireless */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 if (orinoco_lock(priv, &flags) != 0)
David Gibsone67d9d92005-05-12 20:01:22 -0400368 return wstats;
369
370 /* We can't really wait for the tallies inquiry command to
371 * complete, so we just use the previous results and trigger
372 * a new tallies inquiry command for next time - Jean II */
373 /* FIXME: Really we should wait for the inquiry to come back -
374 * as it is the stats we give don't make a whole lot of sense.
375 * Unfortunately, it's not clear how to do that within the
376 * wireless extensions framework: I think we're in user
377 * context, but a lock seems to be held by the time we get in
378 * here so we're not safe to sleep here. */
379 hermes_inquire(hw, HERMES_INQ_TALLIES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 if (priv->iw_mode == IW_MODE_ADHOC) {
382 memset(&wstats->qual, 0, sizeof(wstats->qual));
383 /* If a spy address is defined, we report stats of the
384 * first spy address - Jean II */
385 if (SPY_NUMBER(priv)) {
Pavel Roskin343c6862005-09-09 18:43:02 -0400386 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
387 wstats->qual.level = priv->spy_data.spy_stat[0].level;
388 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
389 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391 } else {
392 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -0400393 __le16 qual, signal, noise;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 } __attribute__ ((packed)) cq;
395
396 err = HERMES_READ_RECORD(hw, USER_BAP,
397 HERMES_RID_COMMSQUALITY, &cq);
David Gibsone67d9d92005-05-12 20:01:22 -0400398
399 if (!err) {
400 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
401 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
402 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
403 wstats->qual.updated = 7;
404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 }
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 return wstats;
409}
410
411static void orinoco_set_multicast_list(struct net_device *dev)
412{
413 struct orinoco_private *priv = netdev_priv(dev);
414 unsigned long flags;
415
416 if (orinoco_lock(priv, &flags) != 0) {
417 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
418 "called when hw_unavailable\n", dev->name);
419 return;
420 }
421
422 __orinoco_set_multicast_list(dev);
423 orinoco_unlock(priv, &flags);
424}
425
426static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
427{
428 struct orinoco_private *priv = netdev_priv(dev);
429
430 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
431 return -EINVAL;
432
Jeff Garzikb4538722005-05-12 22:48:20 -0400433 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 (priv->nicbuf_size - ETH_HLEN) )
435 return -EINVAL;
436
437 dev->mtu = new_mtu;
438
439 return 0;
440}
441
442/********************************************************************/
443/* Tx path */
444/********************************************************************/
445
446static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
447{
448 struct orinoco_private *priv = netdev_priv(dev);
449 struct net_device_stats *stats = &priv->stats;
450 hermes_t *hw = &priv->hw;
451 int err = 0;
452 u16 txfid = priv->txfid;
453 char *p;
454 struct ethhdr *eh;
455 int len, data_len, data_off;
456 struct hermes_tx_descriptor desc;
457 unsigned long flags;
458
459 TRACE_ENTER(dev->name);
460
461 if (! netif_running(dev)) {
462 printk(KERN_ERR "%s: Tx on stopped device!\n",
463 dev->name);
464 TRACE_EXIT(dev->name);
465 return 1;
466 }
467
468 if (netif_queue_stopped(dev)) {
469 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
470 dev->name);
471 TRACE_EXIT(dev->name);
472 return 1;
473 }
474
475 if (orinoco_lock(priv, &flags) != 0) {
476 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
477 dev->name);
478 TRACE_EXIT(dev->name);
479 return 1;
480 }
481
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200482 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /* Oops, the firmware hasn't established a connection,
484 silently drop the packet (this seems to be the
485 safest approach). */
486 stats->tx_errors++;
487 orinoco_unlock(priv, &flags);
488 dev_kfree_skb(skb);
489 TRACE_EXIT(dev->name);
490 return 0;
491 }
492
Andrew Morton63f57fb2005-10-28 15:14:51 -0700493 /* Length of the packet body */
494 /* FIXME: what if the skb is smaller than this? */
Pavel Roskin9bc39be2005-10-04 21:33:10 -0400495 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);
John W. Linville36841c92005-10-18 21:30:58 -0400496 skb = skb_padto(skb, len);
497 if (skb == NULL)
498 goto fail;
Pavel Roskin9bc39be2005-10-04 21:33:10 -0400499 len -= ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 eh = (struct ethhdr *)skb->data;
502
503 memset(&desc, 0, sizeof(desc));
504 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
505 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
506 if (err) {
507 if (net_ratelimit())
508 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
509 "to BAP\n", dev->name, err);
510 stats->tx_errors++;
511 goto fail;
512 }
513
514 /* Clear the 802.11 header and data length fields - some
515 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
516 * if this isn't done. */
517 hermes_clear_words(hw, HERMES_DATA0,
518 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
519
520 /* Encapsulate Ethernet-II frames */
521 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
522 struct header_struct hdr;
523 data_len = len;
524 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
525 p = skb->data + ETH_HLEN;
526
527 /* 802.3 header */
528 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
529 memcpy(hdr.src, eh->h_source, ETH_ALEN);
530 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
531
532 /* 802.2 header */
533 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
534
535 hdr.ethertype = eh->h_proto;
536 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
537 txfid, HERMES_802_3_OFFSET);
538 if (err) {
539 if (net_ratelimit())
540 printk(KERN_ERR "%s: Error %d writing packet "
541 "header to BAP\n", dev->name, err);
542 stats->tx_errors++;
543 goto fail;
544 }
545 } else { /* IEEE 802.3 frame */
546 data_len = len + ETH_HLEN;
547 data_off = HERMES_802_3_OFFSET;
548 p = skb->data;
549 }
550
Andrew Morton63f57fb2005-10-28 15:14:51 -0700551 /* Round up for odd length packets */
552 err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 txfid, data_off);
554 if (err) {
555 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
556 dev->name, err);
557 stats->tx_errors++;
558 goto fail;
559 }
560
561 /* Finally, we actually initiate the send */
562 netif_stop_queue(dev);
563
564 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
565 txfid, NULL);
566 if (err) {
567 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -0700568 if (net_ratelimit())
569 printk(KERN_ERR "%s: Error %d transmitting packet\n",
570 dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 stats->tx_errors++;
572 goto fail;
573 }
574
575 dev->trans_start = jiffies;
576 stats->tx_bytes += data_off + data_len;
577
578 orinoco_unlock(priv, &flags);
579
580 dev_kfree_skb(skb);
581
582 TRACE_EXIT(dev->name);
583
584 return 0;
585 fail:
586 TRACE_EXIT(dev->name);
587
588 orinoco_unlock(priv, &flags);
589 return err;
590}
591
592static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
593{
594 struct orinoco_private *priv = netdev_priv(dev);
595 u16 fid = hermes_read_regn(hw, ALLOCFID);
596
597 if (fid != priv->txfid) {
598 if (fid != DUMMY_FID)
599 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
600 dev->name, fid);
601 return;
602 }
603
604 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
605}
606
607static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
608{
609 struct orinoco_private *priv = netdev_priv(dev);
610 struct net_device_stats *stats = &priv->stats;
611
612 stats->tx_packets++;
613
614 netif_wake_queue(dev);
615
616 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
617}
618
619static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
620{
621 struct orinoco_private *priv = netdev_priv(dev);
622 struct net_device_stats *stats = &priv->stats;
623 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -0400624 u16 status;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200625 struct hermes_tx_descriptor_802_11 hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 int err = 0;
627
628 if (fid == DUMMY_FID)
629 return; /* Nothing's really happened */
630
Pavel Roskin48ca7032005-09-23 04:18:06 -0400631 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200632 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin48ca7032005-09-23 04:18:06 -0400633 offsetof(struct hermes_tx_descriptor_802_11,
634 addr2),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200635 fid, 0);
636
637 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
638 stats->tx_errors++;
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 if (err) {
641 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
642 "(FID=%04X error %d)\n",
643 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200644 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200647 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
648 err, fid);
649
650 /* We produce a TXDROP event only for retry or lifetime
651 * exceeded, because that's the only status that really mean
652 * that this particular node went away.
653 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskind133ae42005-09-23 04:18:06 -0400654 status = le16_to_cpu(hdr.status);
655 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200656 union iwreq_data wrqu;
657
658 /* Copy 802.11 dest address.
659 * We use the 802.11 header because the frame may
660 * not be 802.3 or may be mangled...
661 * In Ad-Hoc mode, it will be the node address.
662 * In managed mode, it will be most likely the AP addr
663 * User space will figure out how to convert it to
664 * whatever it needs (IP address or else).
665 * - Jean II */
666 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
667 wrqu.addr.sa_family = ARPHRD_ETHER;
668
669 /* Send event to user space */
670 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
676static void orinoco_tx_timeout(struct net_device *dev)
677{
678 struct orinoco_private *priv = netdev_priv(dev);
679 struct net_device_stats *stats = &priv->stats;
680 struct hermes *hw = &priv->hw;
681
682 printk(KERN_WARNING "%s: Tx timeout! "
683 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
684 dev->name, hermes_read_regn(hw, ALLOCFID),
685 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
686
687 stats->tx_errors++;
688
689 schedule_work(&priv->reset_work);
690}
691
692/********************************************************************/
693/* Rx path (data frames) */
694/********************************************************************/
695
696/* Does the frame have a SNAP header indicating it should be
697 * de-encapsulated to Ethernet-II? */
698static inline int is_ethersnap(void *_hdr)
699{
700 u8 *hdr = _hdr;
701
702 /* We de-encapsulate all packets which, a) have SNAP headers
703 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
704 * and where b) the OUI of the SNAP header is 00:00:00 or
705 * 00:00:f8 - we need both because different APs appear to use
706 * different OUIs for some reason */
707 return (memcmp(hdr, &encaps_hdr, 5) == 0)
708 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
709}
710
711static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
712 int level, int noise)
713{
Pavel Roskin343c6862005-09-09 18:43:02 -0400714 struct iw_quality wstats;
715 wstats.level = level - 0x95;
716 wstats.noise = noise - 0x95;
717 wstats.qual = (level > noise) ? (level - noise) : 0;
718 wstats.updated = 7;
719 /* Update spy records */
720 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
723static void orinoco_stat_gather(struct net_device *dev,
724 struct sk_buff *skb,
725 struct hermes_rx_descriptor *desc)
726{
727 struct orinoco_private *priv = netdev_priv(dev);
728
729 /* Using spy support with lots of Rx packets, like in an
730 * infrastructure (AP), will really slow down everything, because
731 * the MAC address must be compared to each entry of the spy list.
732 * If the user really asks for it (set some address in the
733 * spy list), we do it, but he will pay the price.
734 * Note that to get here, you need both WIRELESS_SPY
735 * compiled in AND some addresses in the list !!!
736 */
737 /* Note : gcc will optimise the whole section away if
738 * WIRELESS_SPY is not defined... - Jean II */
739 if (SPY_NUMBER(priv)) {
740 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
741 desc->signal, desc->silence);
742 }
743}
744
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200745/*
746 * orinoco_rx_monitor - handle received monitor frames.
747 *
748 * Arguments:
749 * dev network device
750 * rxfid received FID
751 * desc rx descriptor of the frame
752 *
753 * Call context: interrupt
754 */
755static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
756 struct hermes_rx_descriptor *desc)
757{
758 u32 hdrlen = 30; /* return full header by default */
759 u32 datalen = 0;
760 u16 fc;
761 int err;
762 int len;
763 struct sk_buff *skb;
764 struct orinoco_private *priv = netdev_priv(dev);
765 struct net_device_stats *stats = &priv->stats;
766 hermes_t *hw = &priv->hw;
767
768 len = le16_to_cpu(desc->data_len);
769
770 /* Determine the size of the header and the data */
771 fc = le16_to_cpu(desc->frame_ctl);
772 switch (fc & IEEE80211_FCTL_FTYPE) {
773 case IEEE80211_FTYPE_DATA:
774 if ((fc & IEEE80211_FCTL_TODS)
775 && (fc & IEEE80211_FCTL_FROMDS))
776 hdrlen = 30;
777 else
778 hdrlen = 24;
779 datalen = len;
780 break;
781 case IEEE80211_FTYPE_MGMT:
782 hdrlen = 24;
783 datalen = len;
784 break;
785 case IEEE80211_FTYPE_CTL:
786 switch (fc & IEEE80211_FCTL_STYPE) {
787 case IEEE80211_STYPE_PSPOLL:
788 case IEEE80211_STYPE_RTS:
789 case IEEE80211_STYPE_CFEND:
790 case IEEE80211_STYPE_CFENDACK:
791 hdrlen = 16;
792 break;
793 case IEEE80211_STYPE_CTS:
794 case IEEE80211_STYPE_ACK:
795 hdrlen = 10;
796 break;
797 }
798 break;
799 default:
800 /* Unknown frame type */
801 break;
802 }
803
804 /* sanity check the length */
805 if (datalen > IEEE80211_DATA_LEN + 12) {
806 printk(KERN_DEBUG "%s: oversized monitor frame, "
807 "data length = %d\n", dev->name, datalen);
808 err = -EIO;
809 stats->rx_length_errors++;
810 goto update_stats;
811 }
812
813 skb = dev_alloc_skb(hdrlen + datalen);
814 if (!skb) {
815 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
816 dev->name);
817 err = -ENOMEM;
818 goto drop;
819 }
820
821 /* Copy the 802.11 header to the skb */
822 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
823 skb->mac.raw = skb->data;
824
825 /* If any, copy the data from the card to the skb */
826 if (datalen > 0) {
827 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
828 ALIGN(datalen, 2), rxfid,
829 HERMES_802_2_OFFSET);
830 if (err) {
831 printk(KERN_ERR "%s: error %d reading monitor frame\n",
832 dev->name, err);
833 goto drop;
834 }
835 }
836
837 skb->dev = dev;
838 skb->ip_summed = CHECKSUM_NONE;
839 skb->pkt_type = PACKET_OTHERHOST;
840 skb->protocol = __constant_htons(ETH_P_802_2);
841
842 dev->last_rx = jiffies;
843 stats->rx_packets++;
844 stats->rx_bytes += skb->len;
845
846 netif_rx(skb);
847 return;
848
849 drop:
850 dev_kfree_skb_irq(skb);
851 update_stats:
852 stats->rx_errors++;
853 stats->rx_dropped++;
854}
855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
857{
858 struct orinoco_private *priv = netdev_priv(dev);
859 struct net_device_stats *stats = &priv->stats;
860 struct iw_statistics *wstats = &priv->wstats;
861 struct sk_buff *skb = NULL;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200862 u16 rxfid, status, fc;
863 int length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 struct hermes_rx_descriptor desc;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200865 struct ethhdr *hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 int err;
867
868 rxfid = hermes_read_regn(hw, RXFID);
869
870 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
871 rxfid, 0);
872 if (err) {
873 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
874 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200875 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 }
877
878 status = le16_to_cpu(desc.status);
879
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200880 if (status & HERMES_RXSTAT_BADCRC) {
881 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
882 dev->name);
883 stats->rx_crc_errors++;
884 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
886
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200887 /* Handle frames in monitor mode */
888 if (priv->iw_mode == IW_MODE_MONITOR) {
889 orinoco_rx_monitor(dev, rxfid, &desc);
890 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 }
892
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200893 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
894 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
895 dev->name);
896 wstats->discard.code++;
897 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200900 length = le16_to_cpu(desc.data_len);
901 fc = le16_to_cpu(desc.frame_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 /* Sanity checks */
904 if (length < 3) { /* No for even an 802.2 LLC header */
905 /* At least on Symbol firmware with PCF we get quite a
906 lot of these legitimately - Poll frames with no
907 data. */
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200908 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400910 if (length > IEEE80211_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
912 dev->name, length);
913 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200914 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
916
917 /* We need space for the packet data itself, plus an ethernet
918 header, plus 2 bytes so we can align the IP header on a
919 32bit boundary, plus 1 byte so we can read in odd length
920 packets from the card, which has an IO granularity of 16
921 bits */
922 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
923 if (!skb) {
924 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
925 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200926 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
928
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200929 /* We'll prepend the header, so reserve space for it. The worst
930 case is no decapsulation, when 802.3 header is prepended and
931 nothing is removed. 2 is for aligning the IP header. */
932 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200934 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
935 ALIGN(length, 2), rxfid,
936 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 if (err) {
938 printk(KERN_ERR "%s: error %d reading frame. "
939 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 goto drop;
941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 /* Handle decapsulation
944 * In most cases, the firmware tell us about SNAP frames.
945 * For some reason, the SNAP frames sent by LinkSys APs
946 * are not properly recognised by most firmwares.
947 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200948 if (length >= ENCAPS_OVERHEAD &&
949 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
950 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
951 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 /* These indicate a SNAP within 802.2 LLC within
953 802.11 frame which we'll need to de-encapsulate to
954 the original EthernetII frame. */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200955 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200957 /* 802.3 frame - prepend 802.3 header as is */
958 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
959 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 }
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200961 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
962 if (fc & IEEE80211_FCTL_FROMDS)
963 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
964 else
965 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967 dev->last_rx = jiffies;
968 skb->dev = dev;
969 skb->protocol = eth_type_trans(skb, dev);
970 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200971 if (fc & IEEE80211_FCTL_TODS)
972 skb->pkt_type = PACKET_OTHERHOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
974 /* Process the wireless stats if needed */
975 orinoco_stat_gather(dev, skb, &desc);
976
977 /* Pass the packet to the networking stack */
978 netif_rx(skb);
979 stats->rx_packets++;
980 stats->rx_bytes += length;
981
982 return;
983
984 drop:
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200985 dev_kfree_skb_irq(skb);
986 update_stats:
987 stats->rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 stats->rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
991/********************************************************************/
992/* Rx path (info frames) */
993/********************************************************************/
994
995static void print_linkstatus(struct net_device *dev, u16 status)
996{
997 char * s;
998
999 if (suppress_linkstatus)
1000 return;
1001
1002 switch (status) {
1003 case HERMES_LINKSTATUS_NOT_CONNECTED:
1004 s = "Not Connected";
1005 break;
1006 case HERMES_LINKSTATUS_CONNECTED:
1007 s = "Connected";
1008 break;
1009 case HERMES_LINKSTATUS_DISCONNECTED:
1010 s = "Disconnected";
1011 break;
1012 case HERMES_LINKSTATUS_AP_CHANGE:
1013 s = "AP Changed";
1014 break;
1015 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1016 s = "AP Out of Range";
1017 break;
1018 case HERMES_LINKSTATUS_AP_IN_RANGE:
1019 s = "AP In Range";
1020 break;
1021 case HERMES_LINKSTATUS_ASSOC_FAILED:
1022 s = "Association Failed";
1023 break;
1024 default:
1025 s = "UNKNOWN";
1026 }
1027
1028 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1029 dev->name, s, status);
1030}
1031
Christoph Hellwig16739b02005-06-19 01:27:51 +02001032/* Search scan results for requested BSSID, join it if found */
1033static void orinoco_join_ap(struct net_device *dev)
1034{
1035 struct orinoco_private *priv = netdev_priv(dev);
1036 struct hermes *hw = &priv->hw;
1037 int err;
1038 unsigned long flags;
1039 struct join_req {
1040 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001041 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001042 } __attribute__ ((packed)) req;
1043 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001044 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001045 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001046 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001047 u8 *buf;
1048 u16 len;
1049
1050 /* Allocate buffer for scan results */
1051 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1052 if (! buf)
1053 return;
1054
1055 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001056 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001057
1058 /* Sanity checks in case user changed something in the meantime */
1059 if (! priv->bssid_fixed)
1060 goto out;
1061
1062 if (strlen(priv->desired_essid) == 0)
1063 goto out;
1064
1065 /* Read scan results from the firmware */
1066 err = hermes_read_ltv(hw, USER_BAP,
1067 HERMES_RID_SCANRESULTSTABLE,
1068 MAX_SCAN_LEN, &len, buf);
1069 if (err) {
1070 printk(KERN_ERR "%s: Cannot read scan results\n",
1071 dev->name);
1072 goto out;
1073 }
1074
1075 len = HERMES_RECLEN_TO_BYTES(len);
1076
1077 /* Go through the scan results looking for the channel of the AP
1078 * we were requested to join */
1079 for (; offset + atom_len <= len; offset += atom_len) {
1080 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001081 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1082 found = 1;
1083 break;
1084 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001085 }
1086
Pavel Roskinc89cc222005-09-01 20:06:06 -04001087 if (! found) {
1088 DEBUG(1, "%s: Requested AP not found in scan results\n",
1089 dev->name);
1090 goto out;
1091 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001092
Christoph Hellwig16739b02005-06-19 01:27:51 +02001093 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1094 req.channel = atom->channel; /* both are little-endian */
1095 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1096 &req);
1097 if (err)
1098 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1099
1100 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001101 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001102
1103 fail_lock:
1104 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001105}
1106
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001107/* Send new BSSID to userspace */
1108static void orinoco_send_wevents(struct net_device *dev)
1109{
1110 struct orinoco_private *priv = netdev_priv(dev);
1111 struct hermes *hw = &priv->hw;
1112 union iwreq_data wrqu;
1113 int err;
1114 unsigned long flags;
1115
1116 if (orinoco_lock(priv, &flags) != 0)
1117 return;
1118
1119 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1120 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1121 if (err != 0)
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001122 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001123
1124 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1125
1126 /* Send event to user space */
1127 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001128
1129 out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001130 orinoco_unlock(priv, &flags);
1131}
1132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1134{
1135 struct orinoco_private *priv = netdev_priv(dev);
1136 u16 infofid;
1137 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001138 __le16 len;
1139 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 } __attribute__ ((packed)) info;
1141 int len, type;
1142 int err;
1143
1144 /* This is an answer to an INQUIRE command that we did earlier,
1145 * or an information "event" generated by the card
1146 * The controller return to us a pseudo frame containing
1147 * the information in question - Jean II */
1148 infofid = hermes_read_regn(hw, INFOFID);
1149
1150 /* Read the info frame header - don't try too hard */
1151 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1152 infofid, 0);
1153 if (err) {
1154 printk(KERN_ERR "%s: error %d reading info frame. "
1155 "Frame dropped.\n", dev->name, err);
1156 return;
1157 }
1158
1159 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1160 type = le16_to_cpu(info.type);
1161
1162 switch (type) {
1163 case HERMES_INQ_TALLIES: {
1164 struct hermes_tallies_frame tallies;
1165 struct iw_statistics *wstats = &priv->wstats;
1166
1167 if (len > sizeof(tallies)) {
1168 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1169 dev->name, len);
1170 len = sizeof(tallies);
1171 }
1172
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001173 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1174 infofid, sizeof(info));
1175 if (err)
1176 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 /* Increment our various counters */
1179 /* wstats->discard.nwid - no wrong BSSID stuff */
1180 wstats->discard.code +=
1181 le16_to_cpu(tallies.RxWEPUndecryptable);
1182 if (len == sizeof(tallies))
1183 wstats->discard.code +=
1184 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1185 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1186 wstats->discard.misc +=
1187 le16_to_cpu(tallies.TxDiscardsWrongSA);
1188 wstats->discard.fragment +=
1189 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1190 wstats->discard.retries +=
1191 le16_to_cpu(tallies.TxRetryLimitExceeded);
1192 /* wstats->miss.beacon - no match */
1193 }
1194 break;
1195 case HERMES_INQ_LINKSTATUS: {
1196 struct hermes_linkstatus linkstatus;
1197 u16 newstatus;
1198 int connected;
1199
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001200 if (priv->iw_mode == IW_MODE_MONITOR)
1201 break;
1202
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 if (len != sizeof(linkstatus)) {
1204 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1205 dev->name, len);
1206 break;
1207 }
1208
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001209 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1210 infofid, sizeof(info));
1211 if (err)
1212 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 newstatus = le16_to_cpu(linkstatus.linkstatus);
1214
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001215 /* Symbol firmware uses "out of range" to signal that
1216 * the hostscan frame can be requested. */
1217 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1218 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1219 priv->has_hostscan && priv->scan_inprogress) {
1220 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1221 break;
1222 }
1223
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1225 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1226 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1227
1228 if (connected)
1229 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001230 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 netif_carrier_off(dev);
1232
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001233 if (newstatus != priv->last_linkstatus) {
1234 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001236 /* The info frame contains only one word which is the
1237 * status (see hermes.h). The status is pretty boring
1238 * in itself, that's why we export the new BSSID...
1239 * Jean II */
1240 schedule_work(&priv->wevent_work);
1241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 }
1243 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001244 case HERMES_INQ_SCAN:
1245 if (!priv->scan_inprogress && priv->bssid_fixed &&
1246 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1247 schedule_work(&priv->join_work);
1248 break;
1249 }
1250 /* fall through */
1251 case HERMES_INQ_HOSTSCAN:
1252 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1253 /* Result of a scanning. Contains information about
1254 * cells in the vicinity - Jean II */
1255 union iwreq_data wrqu;
1256 unsigned char *buf;
1257
1258 /* Sanity check */
1259 if (len > 4096) {
1260 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1261 dev->name, len);
1262 break;
1263 }
1264
1265 /* We are a strict producer. If the previous scan results
1266 * have not been consumed, we just have to drop this
1267 * frame. We can't remove the previous results ourselves,
1268 * that would be *very* racy... Jean II */
1269 if (priv->scan_result != NULL) {
1270 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1271 break;
1272 }
1273
1274 /* Allocate buffer for results */
1275 buf = kmalloc(len, GFP_ATOMIC);
1276 if (buf == NULL)
1277 /* No memory, so can't printk()... */
1278 break;
1279
1280 /* Read scan data */
1281 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1282 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001283 if (err) {
1284 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001285 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001286 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001287
1288#ifdef ORINOCO_DEBUG
1289 {
1290 int i;
1291 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1292 for(i = 1; i < (len * 2); i++)
1293 printk(":%02X", buf[i]);
1294 printk("]\n");
1295 }
1296#endif /* ORINOCO_DEBUG */
1297
1298 /* Allow the clients to access the results */
1299 priv->scan_len = len;
1300 priv->scan_result = buf;
1301
1302 /* Send an empty event to user space.
1303 * We don't send the received data on the event because
1304 * it would require us to do complex transcoding, and
1305 * we want to minimise the work done in the irq handler
1306 * Use a request to extract the data - Jean II */
1307 wrqu.data.length = 0;
1308 wrqu.data.flags = 0;
1309 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1310 }
1311 break;
1312 case HERMES_INQ_SEC_STAT_AGERE:
1313 /* Security status (Agere specific) */
1314 /* Ignore this frame for now */
1315 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1316 break;
1317 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 default:
1319 printk(KERN_DEBUG "%s: Unknown information frame received: "
1320 "type 0x%04x, length %d\n", dev->name, type, len);
1321 /* We don't actually do anything about it */
1322 break;
1323 }
1324}
1325
1326static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1327{
1328 if (net_ratelimit())
1329 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1330}
1331
1332/********************************************************************/
1333/* Internal hardware control routines */
1334/********************************************************************/
1335
1336int __orinoco_up(struct net_device *dev)
1337{
1338 struct orinoco_private *priv = netdev_priv(dev);
1339 struct hermes *hw = &priv->hw;
1340 int err;
1341
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001342 netif_carrier_off(dev); /* just to make sure */
1343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 err = __orinoco_program_rids(dev);
1345 if (err) {
1346 printk(KERN_ERR "%s: Error %d configuring card\n",
1347 dev->name, err);
1348 return err;
1349 }
1350
1351 /* Fire things up again */
1352 hermes_set_irqmask(hw, ORINOCO_INTEN);
1353 err = hermes_enable_port(hw, 0);
1354 if (err) {
1355 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1356 dev->name, err);
1357 return err;
1358 }
1359
1360 netif_start_queue(dev);
1361
1362 return 0;
1363}
1364
1365int __orinoco_down(struct net_device *dev)
1366{
1367 struct orinoco_private *priv = netdev_priv(dev);
1368 struct hermes *hw = &priv->hw;
1369 int err;
1370
1371 netif_stop_queue(dev);
1372
1373 if (! priv->hw_unavailable) {
1374 if (! priv->broken_disableport) {
1375 err = hermes_disable_port(hw, 0);
1376 if (err) {
1377 /* Some firmwares (e.g. Intersil 1.3.x) seem
1378 * to have problems disabling the port, oh
1379 * well, too bad. */
1380 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1381 dev->name, err);
1382 priv->broken_disableport = 1;
1383 }
1384 }
1385 hermes_set_irqmask(hw, 0);
1386 hermes_write_regn(hw, EVACK, 0xffff);
1387 }
1388
1389 /* firmware will have to reassociate */
1390 netif_carrier_off(dev);
1391 priv->last_linkstatus = 0xffff;
1392
1393 return 0;
1394}
1395
1396int orinoco_reinit_firmware(struct net_device *dev)
1397{
1398 struct orinoco_private *priv = netdev_priv(dev);
1399 struct hermes *hw = &priv->hw;
1400 int err;
1401
1402 err = hermes_init(hw);
1403 if (err)
1404 return err;
1405
1406 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04001407 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 /* Try workaround for old Symbol firmware bug */
1409 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1410 "(old Symbol firmware?). Trying to work around... ",
1411 dev->name);
1412
1413 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1414 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1415 if (err)
1416 printk("failed!\n");
1417 else
1418 printk("ok.\n");
1419 }
1420
1421 return err;
1422}
1423
1424static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1425{
1426 hermes_t *hw = &priv->hw;
1427 int err = 0;
1428
1429 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1430 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1431 priv->ndev->name, priv->bitratemode);
1432 return -EINVAL;
1433 }
1434
1435 switch (priv->firmware_type) {
1436 case FIRMWARE_TYPE_AGERE:
1437 err = hermes_write_wordrec(hw, USER_BAP,
1438 HERMES_RID_CNFTXRATECONTROL,
1439 bitrate_table[priv->bitratemode].agere_txratectrl);
1440 break;
1441 case FIRMWARE_TYPE_INTERSIL:
1442 case FIRMWARE_TYPE_SYMBOL:
1443 err = hermes_write_wordrec(hw, USER_BAP,
1444 HERMES_RID_CNFTXRATECONTROL,
1445 bitrate_table[priv->bitratemode].intersil_txratectrl);
1446 break;
1447 default:
1448 BUG();
1449 }
1450
1451 return err;
1452}
1453
Christoph Hellwig16739b02005-06-19 01:27:51 +02001454/* Set fixed AP address */
1455static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1456{
1457 int roaming_flag;
1458 int err = 0;
1459 hermes_t *hw = &priv->hw;
1460
1461 switch (priv->firmware_type) {
1462 case FIRMWARE_TYPE_AGERE:
1463 /* not supported */
1464 break;
1465 case FIRMWARE_TYPE_INTERSIL:
1466 if (priv->bssid_fixed)
1467 roaming_flag = 2;
1468 else
1469 roaming_flag = 1;
1470
1471 err = hermes_write_wordrec(hw, USER_BAP,
1472 HERMES_RID_CNFROAMINGMODE,
1473 roaming_flag);
1474 break;
1475 case FIRMWARE_TYPE_SYMBOL:
1476 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1477 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1478 &priv->desired_bssid);
1479 break;
1480 }
1481 return err;
1482}
1483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484/* Change the WEP keys and/or the current keys. Can be called
1485 * either from __orinoco_hw_setup_wep() or directly from
1486 * orinoco_ioctl_setiwencode(). In the later case the association
1487 * with the AP is not broken (if the firmware can handle it),
1488 * which is needed for 802.1x implementations. */
1489static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1490{
1491 hermes_t *hw = &priv->hw;
1492 int err = 0;
1493
1494 switch (priv->firmware_type) {
1495 case FIRMWARE_TYPE_AGERE:
1496 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1497 HERMES_RID_CNFWEPKEYS_AGERE,
1498 &priv->keys);
1499 if (err)
1500 return err;
1501 err = hermes_write_wordrec(hw, USER_BAP,
1502 HERMES_RID_CNFTXKEY_AGERE,
1503 priv->tx_key);
1504 if (err)
1505 return err;
1506 break;
1507 case FIRMWARE_TYPE_INTERSIL:
1508 case FIRMWARE_TYPE_SYMBOL:
1509 {
1510 int keylen;
1511 int i;
1512
1513 /* Force uniform key length to work around firmware bugs */
1514 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1515
1516 if (keylen > LARGE_KEY_SIZE) {
1517 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1518 priv->ndev->name, priv->tx_key, keylen);
1519 return -E2BIG;
1520 }
1521
1522 /* Write all 4 keys */
1523 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1524 err = hermes_write_ltv(hw, USER_BAP,
1525 HERMES_RID_CNFDEFAULTKEY0 + i,
1526 HERMES_BYTES_TO_RECLEN(keylen),
1527 priv->keys[i].data);
1528 if (err)
1529 return err;
1530 }
1531
1532 /* Write the index of the key used in transmission */
1533 err = hermes_write_wordrec(hw, USER_BAP,
1534 HERMES_RID_CNFWEPDEFAULTKEYID,
1535 priv->tx_key);
1536 if (err)
1537 return err;
1538 }
1539 break;
1540 }
1541
1542 return 0;
1543}
1544
1545static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1546{
1547 hermes_t *hw = &priv->hw;
1548 int err = 0;
1549 int master_wep_flag;
1550 int auth_flag;
1551
1552 if (priv->wep_on)
1553 __orinoco_hw_setup_wepkeys(priv);
1554
1555 if (priv->wep_restrict)
1556 auth_flag = HERMES_AUTH_SHARED_KEY;
1557 else
1558 auth_flag = HERMES_AUTH_OPEN;
1559
1560 switch (priv->firmware_type) {
1561 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1562 if (priv->wep_on) {
1563 /* Enable the shared-key authentication. */
1564 err = hermes_write_wordrec(hw, USER_BAP,
1565 HERMES_RID_CNFAUTHENTICATION_AGERE,
1566 auth_flag);
1567 }
1568 err = hermes_write_wordrec(hw, USER_BAP,
1569 HERMES_RID_CNFWEPENABLED_AGERE,
1570 priv->wep_on);
1571 if (err)
1572 return err;
1573 break;
1574
1575 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1576 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1577 if (priv->wep_on) {
1578 if (priv->wep_restrict ||
1579 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1580 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1581 HERMES_WEP_EXCL_UNENCRYPTED;
1582 else
1583 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1584
1585 err = hermes_write_wordrec(hw, USER_BAP,
1586 HERMES_RID_CNFAUTHENTICATION,
1587 auth_flag);
1588 if (err)
1589 return err;
1590 } else
1591 master_wep_flag = 0;
1592
1593 if (priv->iw_mode == IW_MODE_MONITOR)
1594 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1595
1596 /* Master WEP setting : on/off */
1597 err = hermes_write_wordrec(hw, USER_BAP,
1598 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1599 master_wep_flag);
1600 if (err)
1601 return err;
1602
1603 break;
1604 }
1605
1606 return 0;
1607}
1608
1609static int __orinoco_program_rids(struct net_device *dev)
1610{
1611 struct orinoco_private *priv = netdev_priv(dev);
1612 hermes_t *hw = &priv->hw;
1613 int err;
1614 struct hermes_idstring idbuf;
1615
1616 /* Set the MAC address */
1617 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1618 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1619 if (err) {
1620 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1621 dev->name, err);
1622 return err;
1623 }
1624
1625 /* Set up the link mode */
1626 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1627 priv->port_type);
1628 if (err) {
1629 printk(KERN_ERR "%s: Error %d setting port type\n",
1630 dev->name, err);
1631 return err;
1632 }
1633 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04001634 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1635 err = hermes_write_wordrec(hw, USER_BAP,
1636 HERMES_RID_CNFOWNCHANNEL,
1637 priv->channel);
1638 if (err) {
1639 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1640 dev->name, err, priv->channel);
1641 return err;
1642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 }
1644
1645 if (priv->has_ibss) {
1646 u16 createibss;
1647
1648 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1649 printk(KERN_WARNING "%s: This firmware requires an "
1650 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1651 /* With wvlan_cs, in this case, we would crash.
1652 * hopefully, this driver will behave better...
1653 * Jean II */
1654 createibss = 0;
1655 } else {
1656 createibss = priv->createibss;
1657 }
1658
1659 err = hermes_write_wordrec(hw, USER_BAP,
1660 HERMES_RID_CNFCREATEIBSS,
1661 createibss);
1662 if (err) {
1663 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1664 dev->name, err);
1665 return err;
1666 }
1667 }
1668
Christoph Hellwig16739b02005-06-19 01:27:51 +02001669 /* Set the desired BSSID */
1670 err = __orinoco_hw_set_wap(priv);
1671 if (err) {
1672 printk(KERN_ERR "%s: Error %d setting AP address\n",
1673 dev->name, err);
1674 return err;
1675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 /* Set the desired ESSID */
1677 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1678 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1679 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1680 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1681 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1682 &idbuf);
1683 if (err) {
1684 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1685 dev->name, err);
1686 return err;
1687 }
1688 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1689 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1690 &idbuf);
1691 if (err) {
1692 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1693 dev->name, err);
1694 return err;
1695 }
1696
1697 /* Set the station name */
1698 idbuf.len = cpu_to_le16(strlen(priv->nick));
1699 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1700 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1701 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1702 &idbuf);
1703 if (err) {
1704 printk(KERN_ERR "%s: Error %d setting nickname\n",
1705 dev->name, err);
1706 return err;
1707 }
1708
1709 /* Set AP density */
1710 if (priv->has_sensitivity) {
1711 err = hermes_write_wordrec(hw, USER_BAP,
1712 HERMES_RID_CNFSYSTEMSCALE,
1713 priv->ap_density);
1714 if (err) {
1715 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1716 "Disabling sensitivity control\n",
1717 dev->name, err);
1718
1719 priv->has_sensitivity = 0;
1720 }
1721 }
1722
1723 /* Set RTS threshold */
1724 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1725 priv->rts_thresh);
1726 if (err) {
1727 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1728 dev->name, err);
1729 return err;
1730 }
1731
1732 /* Set fragmentation threshold or MWO robustness */
1733 if (priv->has_mwo)
1734 err = hermes_write_wordrec(hw, USER_BAP,
1735 HERMES_RID_CNFMWOROBUST_AGERE,
1736 priv->mwo_robust);
1737 else
1738 err = hermes_write_wordrec(hw, USER_BAP,
1739 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1740 priv->frag_thresh);
1741 if (err) {
1742 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1743 dev->name, err);
1744 return err;
1745 }
1746
1747 /* Set bitrate */
1748 err = __orinoco_hw_set_bitrate(priv);
1749 if (err) {
1750 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1751 dev->name, err);
1752 return err;
1753 }
1754
1755 /* Set power management */
1756 if (priv->has_pm) {
1757 err = hermes_write_wordrec(hw, USER_BAP,
1758 HERMES_RID_CNFPMENABLED,
1759 priv->pm_on);
1760 if (err) {
1761 printk(KERN_ERR "%s: Error %d setting up PM\n",
1762 dev->name, err);
1763 return err;
1764 }
1765
1766 err = hermes_write_wordrec(hw, USER_BAP,
1767 HERMES_RID_CNFMULTICASTRECEIVE,
1768 priv->pm_mcast);
1769 if (err) {
1770 printk(KERN_ERR "%s: Error %d setting up PM\n",
1771 dev->name, err);
1772 return err;
1773 }
1774 err = hermes_write_wordrec(hw, USER_BAP,
1775 HERMES_RID_CNFMAXSLEEPDURATION,
1776 priv->pm_period);
1777 if (err) {
1778 printk(KERN_ERR "%s: Error %d setting up PM\n",
1779 dev->name, err);
1780 return err;
1781 }
1782 err = hermes_write_wordrec(hw, USER_BAP,
1783 HERMES_RID_CNFPMHOLDOVERDURATION,
1784 priv->pm_timeout);
1785 if (err) {
1786 printk(KERN_ERR "%s: Error %d setting up PM\n",
1787 dev->name, err);
1788 return err;
1789 }
1790 }
1791
1792 /* Set preamble - only for Symbol so far... */
1793 if (priv->has_preamble) {
1794 err = hermes_write_wordrec(hw, USER_BAP,
1795 HERMES_RID_CNFPREAMBLE_SYMBOL,
1796 priv->preamble);
1797 if (err) {
1798 printk(KERN_ERR "%s: Error %d setting preamble\n",
1799 dev->name, err);
1800 return err;
1801 }
1802 }
1803
1804 /* Set up encryption */
1805 if (priv->has_wep) {
1806 err = __orinoco_hw_setup_wep(priv);
1807 if (err) {
1808 printk(KERN_ERR "%s: Error %d activating WEP\n",
1809 dev->name, err);
1810 return err;
1811 }
1812 }
1813
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001814 if (priv->iw_mode == IW_MODE_MONITOR) {
1815 /* Enable monitor mode */
1816 dev->type = ARPHRD_IEEE80211;
1817 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1818 HERMES_TEST_MONITOR, 0, NULL);
1819 } else {
1820 /* Disable monitor mode */
1821 dev->type = ARPHRD_ETHER;
1822 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1823 HERMES_TEST_STOP, 0, NULL);
1824 }
1825 if (err)
1826 return err;
1827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 /* Set promiscuity / multicast*/
1829 priv->promiscuous = 0;
1830 priv->mc_count = 0;
1831 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1832
1833 return 0;
1834}
1835
1836/* FIXME: return int? */
1837static void
1838__orinoco_set_multicast_list(struct net_device *dev)
1839{
1840 struct orinoco_private *priv = netdev_priv(dev);
1841 hermes_t *hw = &priv->hw;
1842 int err = 0;
1843 int promisc, mc_count;
1844
1845 /* The Hermes doesn't seem to have an allmulti mode, so we go
1846 * into promiscuous mode and let the upper levels deal. */
1847 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1848 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1849 promisc = 1;
1850 mc_count = 0;
1851 } else {
1852 promisc = 0;
1853 mc_count = dev->mc_count;
1854 }
1855
1856 if (promisc != priv->promiscuous) {
1857 err = hermes_write_wordrec(hw, USER_BAP,
1858 HERMES_RID_CNFPROMISCUOUSMODE,
1859 promisc);
1860 if (err) {
1861 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1862 dev->name, err);
1863 } else
1864 priv->promiscuous = promisc;
1865 }
1866
1867 if (! promisc && (mc_count || priv->mc_count) ) {
1868 struct dev_mc_list *p = dev->mc_list;
1869 struct hermes_multicast mclist;
1870 int i;
1871
1872 for (i = 0; i < mc_count; i++) {
1873 /* paranoia: is list shorter than mc_count? */
1874 BUG_ON(! p);
1875 /* paranoia: bad address size in list? */
1876 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1877
1878 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1879 p = p->next;
1880 }
1881
1882 if (p)
1883 printk(KERN_WARNING "%s: Multicast list is "
1884 "longer than mc_count\n", dev->name);
1885
1886 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1887 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1888 &mclist);
1889 if (err)
1890 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1891 dev->name, err);
1892 else
1893 priv->mc_count = mc_count;
1894 }
1895
1896 /* Since we can set the promiscuous flag when it wasn't asked
1897 for, make sure the net_device knows about it. */
1898 if (priv->promiscuous)
1899 dev->flags |= IFF_PROMISC;
1900 else
1901 dev->flags &= ~IFF_PROMISC;
1902}
1903
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904/* This must be called from user context, without locks held - use
1905 * schedule_work() */
1906static void orinoco_reset(struct net_device *dev)
1907{
1908 struct orinoco_private *priv = netdev_priv(dev);
1909 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001910 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 unsigned long flags;
1912
1913 if (orinoco_lock(priv, &flags) != 0)
1914 /* When the hardware becomes available again, whatever
1915 * detects that is responsible for re-initializing
1916 * it. So no need for anything further */
1917 return;
1918
1919 netif_stop_queue(dev);
1920
1921 /* Shut off interrupts. Depending on what state the hardware
1922 * is in, this might not work, but we'll try anyway */
1923 hermes_set_irqmask(hw, 0);
1924 hermes_write_regn(hw, EVACK, 0xffff);
1925
1926 priv->hw_unavailable++;
1927 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1928 netif_carrier_off(dev);
1929
1930 orinoco_unlock(priv, &flags);
1931
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001932 /* Scanning support: Cleanup of driver struct */
1933 kfree(priv->scan_result);
1934 priv->scan_result = NULL;
1935 priv->scan_inprogress = 0;
1936
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001937 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001939 if (err) {
1940 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1941 "performing hard reset\n", dev->name, err);
1942 goto disable;
1943 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 }
1945
1946 err = orinoco_reinit_firmware(dev);
1947 if (err) {
1948 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1949 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001950 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 }
1952
1953 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1954
1955 priv->hw_unavailable--;
1956
1957 /* priv->open or priv->hw_unavailable might have changed while
1958 * we dropped the lock */
1959 if (priv->open && (! priv->hw_unavailable)) {
1960 err = __orinoco_up(dev);
1961 if (err) {
1962 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1963 dev->name, err);
1964 } else
1965 dev->trans_start = jiffies;
1966 }
1967
1968 spin_unlock_irq(&priv->lock);
1969
1970 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001971 disable:
1972 hermes_set_irqmask(hw, 0);
1973 netif_device_detach(dev);
1974 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975}
1976
1977/********************************************************************/
1978/* Interrupt handler */
1979/********************************************************************/
1980
1981static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1982{
1983 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1984}
1985
1986static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1987{
1988 /* This seems to happen a fair bit under load, but ignoring it
1989 seems to work fine...*/
1990 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1991 dev->name);
1992}
1993
1994irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1995{
1996 struct net_device *dev = (struct net_device *)dev_id;
1997 struct orinoco_private *priv = netdev_priv(dev);
1998 hermes_t *hw = &priv->hw;
1999 int count = MAX_IRQLOOPS_PER_IRQ;
2000 u16 evstat, events;
2001 /* These are used to detect a runaway interrupt situation */
2002 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2003 * we panic and shut down the hardware */
2004 static int last_irq_jiffy = 0; /* jiffies value the last time
2005 * we were called */
2006 static int loops_this_jiffy = 0;
2007 unsigned long flags;
2008
2009 if (orinoco_lock(priv, &flags) != 0) {
2010 /* If hw is unavailable - we don't know if the irq was
2011 * for us or not */
2012 return IRQ_HANDLED;
2013 }
2014
2015 evstat = hermes_read_regn(hw, EVSTAT);
2016 events = evstat & hw->inten;
2017 if (! events) {
2018 orinoco_unlock(priv, &flags);
2019 return IRQ_NONE;
2020 }
2021
2022 if (jiffies != last_irq_jiffy)
2023 loops_this_jiffy = 0;
2024 last_irq_jiffy = jiffies;
2025
2026 while (events && count--) {
2027 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2028 printk(KERN_WARNING "%s: IRQ handler is looping too "
2029 "much! Resetting.\n", dev->name);
2030 /* Disable interrupts for now */
2031 hermes_set_irqmask(hw, 0);
2032 schedule_work(&priv->reset_work);
2033 break;
2034 }
2035
2036 /* Check the card hasn't been removed */
2037 if (! hermes_present(hw)) {
2038 DEBUG(0, "orinoco_interrupt(): card removed\n");
2039 break;
2040 }
2041
2042 if (events & HERMES_EV_TICK)
2043 __orinoco_ev_tick(dev, hw);
2044 if (events & HERMES_EV_WTERR)
2045 __orinoco_ev_wterr(dev, hw);
2046 if (events & HERMES_EV_INFDROP)
2047 __orinoco_ev_infdrop(dev, hw);
2048 if (events & HERMES_EV_INFO)
2049 __orinoco_ev_info(dev, hw);
2050 if (events & HERMES_EV_RX)
2051 __orinoco_ev_rx(dev, hw);
2052 if (events & HERMES_EV_TXEXC)
2053 __orinoco_ev_txexc(dev, hw);
2054 if (events & HERMES_EV_TX)
2055 __orinoco_ev_tx(dev, hw);
2056 if (events & HERMES_EV_ALLOC)
2057 __orinoco_ev_alloc(dev, hw);
2058
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002059 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 evstat = hermes_read_regn(hw, EVSTAT);
2062 events = evstat & hw->inten;
2063 };
2064
2065 orinoco_unlock(priv, &flags);
2066 return IRQ_HANDLED;
2067}
2068
2069/********************************************************************/
2070/* Initialization */
2071/********************************************************************/
2072
2073struct comp_id {
2074 u16 id, variant, major, minor;
2075} __attribute__ ((packed));
2076
2077static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2078{
2079 if (nic_id->id < 0x8000)
2080 return FIRMWARE_TYPE_AGERE;
2081 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2082 return FIRMWARE_TYPE_SYMBOL;
2083 else
2084 return FIRMWARE_TYPE_INTERSIL;
2085}
2086
2087/* Set priv->firmware type, determine firmware properties */
2088static int determine_firmware(struct net_device *dev)
2089{
2090 struct orinoco_private *priv = netdev_priv(dev);
2091 hermes_t *hw = &priv->hw;
2092 int err;
2093 struct comp_id nic_id, sta_id;
2094 unsigned int firmver;
2095 char tmp[SYMBOL_MAX_VER_LEN+1];
2096
2097 /* Get the hardware version */
2098 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2099 if (err) {
2100 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2101 dev->name, err);
2102 return err;
2103 }
2104
2105 le16_to_cpus(&nic_id.id);
2106 le16_to_cpus(&nic_id.variant);
2107 le16_to_cpus(&nic_id.major);
2108 le16_to_cpus(&nic_id.minor);
2109 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2110 dev->name, nic_id.id, nic_id.variant,
2111 nic_id.major, nic_id.minor);
2112
2113 priv->firmware_type = determine_firmware_type(&nic_id);
2114
2115 /* Get the firmware version */
2116 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2117 if (err) {
2118 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2119 dev->name, err);
2120 return err;
2121 }
2122
2123 le16_to_cpus(&sta_id.id);
2124 le16_to_cpus(&sta_id.variant);
2125 le16_to_cpus(&sta_id.major);
2126 le16_to_cpus(&sta_id.minor);
2127 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2128 dev->name, sta_id.id, sta_id.variant,
2129 sta_id.major, sta_id.minor);
2130
2131 switch (sta_id.id) {
2132 case 0x15:
2133 printk(KERN_ERR "%s: Primary firmware is active\n",
2134 dev->name);
2135 return -ENODEV;
2136 case 0x14b:
2137 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2138 dev->name);
2139 return -ENODEV;
2140 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2141 case 0x21: /* Symbol Spectrum24 Trilogy */
2142 break;
2143 default:
2144 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2145 dev->name);
2146 break;
2147 }
2148
2149 /* Default capabilities */
2150 priv->has_sensitivity = 1;
2151 priv->has_mwo = 0;
2152 priv->has_preamble = 0;
2153 priv->has_port3 = 1;
2154 priv->has_ibss = 1;
2155 priv->has_wep = 0;
2156 priv->has_big_wep = 0;
2157
2158 /* Determine capabilities from the firmware version */
2159 switch (priv->firmware_type) {
2160 case FIRMWARE_TYPE_AGERE:
2161 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2162 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2163 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2164 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2165
2166 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2167
2168 priv->has_ibss = (firmver >= 0x60006);
2169 priv->has_wep = (firmver >= 0x40020);
2170 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2171 Gold cards from the others? */
2172 priv->has_mwo = (firmver >= 0x60000);
2173 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2174 priv->ibss_port = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002175 priv->has_hostscan = (firmver >= 0x8000a);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002176 priv->broken_monitor = (firmver >= 0x80000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
2178 /* Tested with Agere firmware :
2179 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2180 * Tested CableTron firmware : 4.32 => Anton */
2181 break;
2182 case FIRMWARE_TYPE_SYMBOL:
2183 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2184 /* Intel MAC : 00:02:B3:* */
2185 /* 3Com MAC : 00:50:DA:* */
2186 memset(tmp, 0, sizeof(tmp));
2187 /* Get the Symbol firmware version */
2188 err = hermes_read_ltv(hw, USER_BAP,
2189 HERMES_RID_SECONDARYVERSION_SYMBOL,
2190 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2191 if (err) {
2192 printk(KERN_WARNING
2193 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2194 dev->name, err);
2195 firmver = 0;
2196 tmp[0] = '\0';
2197 } else {
2198 /* The firmware revision is a string, the format is
2199 * something like : "V2.20-01".
2200 * Quick and dirty parsing... - Jean II
2201 */
2202 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2203 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2204 | (tmp[7] - '0');
2205
2206 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2207 }
2208
2209 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2210 "Symbol %s", tmp);
2211
2212 priv->has_ibss = (firmver >= 0x20000);
2213 priv->has_wep = (firmver >= 0x15012);
2214 priv->has_big_wep = (firmver >= 0x20000);
2215 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2216 (firmver >= 0x29000 && firmver < 0x30000) ||
2217 firmver >= 0x31000;
2218 priv->has_preamble = (firmver >= 0x20000);
2219 priv->ibss_port = 4;
Christoph Hellwig649e59e2005-05-14 17:30:10 +02002220 priv->broken_disableport = (firmver == 0x25013) ||
2221 (firmver >= 0x30000 && firmver <= 0x31000);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002222 priv->has_hostscan = (firmver >= 0x31001) ||
2223 (firmver >= 0x29057 && firmver < 0x30000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 /* Tested with Intel firmware : 0x20015 => Jean II */
2225 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2226 break;
2227 case FIRMWARE_TYPE_INTERSIL:
2228 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2229 * Samsung, Compaq 100/200 and Proxim are slightly
2230 * different and less well tested */
2231 /* D-Link MAC : 00:40:05:* */
2232 /* Addtron MAC : 00:90:D1:* */
2233 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2234 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2235 sta_id.variant);
2236
2237 firmver = ((unsigned long)sta_id.major << 16) |
2238 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2239
2240 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2241 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2242 priv->has_pm = (firmver >= 0x000700);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002243 priv->has_hostscan = (firmver >= 0x010301);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
2245 if (firmver >= 0x000800)
2246 priv->ibss_port = 0;
2247 else {
2248 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2249 "than v0.8.x - several features not supported\n",
2250 dev->name);
2251 priv->ibss_port = 1;
2252 }
2253 break;
2254 }
2255 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2256 priv->fw_name);
2257
2258 return 0;
2259}
2260
2261static int orinoco_init(struct net_device *dev)
2262{
2263 struct orinoco_private *priv = netdev_priv(dev);
2264 hermes_t *hw = &priv->hw;
2265 int err = 0;
2266 struct hermes_idstring nickbuf;
2267 u16 reclen;
2268 int len;
2269
2270 TRACE_ENTER(dev->name);
2271
2272 /* No need to lock, the hw_unavailable flag is already set in
2273 * alloc_orinocodev() */
Jeff Garzikb4538722005-05-12 22:48:20 -04002274 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 /* Initialize the firmware */
David Gibsonb24d4582005-05-12 20:04:16 -04002277 err = orinoco_reinit_firmware(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 if (err != 0) {
2279 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2280 dev->name, err);
2281 goto out;
2282 }
2283
2284 err = determine_firmware(dev);
2285 if (err != 0) {
2286 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2287 dev->name);
2288 goto out;
2289 }
2290
2291 if (priv->has_port3)
2292 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2293 if (priv->has_ibss)
2294 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2295 dev->name);
2296 if (priv->has_wep) {
2297 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2298 if (priv->has_big_wep)
2299 printk("104-bit key\n");
2300 else
2301 printk("40-bit key\n");
2302 }
2303
2304 /* Get the MAC address */
2305 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2306 ETH_ALEN, NULL, dev->dev_addr);
2307 if (err) {
2308 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2309 dev->name);
2310 goto out;
2311 }
2312
2313 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2314 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2315 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2316 dev->dev_addr[5]);
2317
2318 /* Get the station name */
2319 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2320 sizeof(nickbuf), &reclen, &nickbuf);
2321 if (err) {
2322 printk(KERN_ERR "%s: failed to read station name\n",
2323 dev->name);
2324 goto out;
2325 }
2326 if (nickbuf.len)
2327 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2328 else
2329 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2330 memcpy(priv->nick, &nickbuf.val, len);
2331 priv->nick[len] = '\0';
2332
2333 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2334
2335 /* Get allowed channels */
2336 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2337 &priv->channel_mask);
2338 if (err) {
2339 printk(KERN_ERR "%s: failed to read channel list!\n",
2340 dev->name);
2341 goto out;
2342 }
2343
2344 /* Get initial AP density */
2345 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2346 &priv->ap_density);
2347 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2348 priv->has_sensitivity = 0;
2349 }
2350
2351 /* Get initial RTS threshold */
2352 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2353 &priv->rts_thresh);
2354 if (err) {
2355 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2356 dev->name);
2357 goto out;
2358 }
2359
2360 /* Get initial fragmentation settings */
2361 if (priv->has_mwo)
2362 err = hermes_read_wordrec(hw, USER_BAP,
2363 HERMES_RID_CNFMWOROBUST_AGERE,
2364 &priv->mwo_robust);
2365 else
2366 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2367 &priv->frag_thresh);
2368 if (err) {
2369 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2370 dev->name);
2371 goto out;
2372 }
2373
2374 /* Power management setup */
2375 if (priv->has_pm) {
2376 priv->pm_on = 0;
2377 priv->pm_mcast = 1;
2378 err = hermes_read_wordrec(hw, USER_BAP,
2379 HERMES_RID_CNFMAXSLEEPDURATION,
2380 &priv->pm_period);
2381 if (err) {
2382 printk(KERN_ERR "%s: failed to read power management period!\n",
2383 dev->name);
2384 goto out;
2385 }
2386 err = hermes_read_wordrec(hw, USER_BAP,
2387 HERMES_RID_CNFPMHOLDOVERDURATION,
2388 &priv->pm_timeout);
2389 if (err) {
2390 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2391 dev->name);
2392 goto out;
2393 }
2394 }
2395
2396 /* Preamble setup */
2397 if (priv->has_preamble) {
2398 err = hermes_read_wordrec(hw, USER_BAP,
2399 HERMES_RID_CNFPREAMBLE_SYMBOL,
2400 &priv->preamble);
2401 if (err)
2402 goto out;
2403 }
2404
2405 /* Set up the default configuration */
2406 priv->iw_mode = IW_MODE_INFRA;
2407 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2408 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2409 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04002410 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
2412 priv->promiscuous = 0;
2413 priv->wep_on = 0;
2414 priv->tx_key = 0;
2415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 /* Make the hardware available, as long as it hasn't been
2417 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2418 spin_lock_irq(&priv->lock);
2419 priv->hw_unavailable--;
2420 spin_unlock_irq(&priv->lock);
2421
2422 printk(KERN_DEBUG "%s: ready\n", dev->name);
2423
2424 out:
2425 TRACE_EXIT(dev->name);
2426 return err;
2427}
2428
2429struct net_device *alloc_orinocodev(int sizeof_card,
2430 int (*hard_reset)(struct orinoco_private *))
2431{
2432 struct net_device *dev;
2433 struct orinoco_private *priv;
2434
2435 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2436 if (! dev)
2437 return NULL;
2438 priv = netdev_priv(dev);
2439 priv->ndev = dev;
2440 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002441 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 + sizeof(struct orinoco_private));
2443 else
2444 priv->card = NULL;
2445
2446 /* Setup / override net_device fields */
2447 dev->init = orinoco_init;
2448 dev->hard_start_xmit = orinoco_xmit;
2449 dev->tx_timeout = orinoco_tx_timeout;
2450 dev->watchdog_timeo = HZ; /* 1 second timeout */
2451 dev->get_stats = orinoco_get_stats;
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002452 dev->ethtool_ops = &orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002453 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04002454#ifdef WIRELESS_SPY
2455 priv->wireless_data.spy_data = &priv->spy_data;
2456 dev->wireless_data = &priv->wireless_data;
2457#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 dev->change_mtu = orinoco_change_mtu;
2459 dev->set_multicast_list = orinoco_set_multicast_list;
2460 /* we use the default eth_mac_addr for setting the MAC addr */
2461
2462 /* Set up default callbacks */
2463 dev->open = orinoco_open;
2464 dev->stop = orinoco_stop;
2465 priv->hard_reset = hard_reset;
2466
2467 spin_lock_init(&priv->lock);
2468 priv->open = 0;
2469 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2470 * before anything else touches the
2471 * hardware */
2472 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
Christoph Hellwig16739b02005-06-19 01:27:51 +02002473 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002474 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
2476 netif_carrier_off(dev);
2477 priv->last_linkstatus = 0xffff;
2478
2479 return dev;
2480
2481}
2482
2483void free_orinocodev(struct net_device *dev)
2484{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002485 struct orinoco_private *priv = netdev_priv(dev);
2486
2487 kfree(priv->scan_result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 free_netdev(dev);
2489}
2490
2491/********************************************************************/
2492/* Wireless extensions */
2493/********************************************************************/
2494
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2496 char buf[IW_ESSID_MAX_SIZE+1])
2497{
2498 hermes_t *hw = &priv->hw;
2499 int err = 0;
2500 struct hermes_idstring essidbuf;
2501 char *p = (char *)(&essidbuf.val);
2502 int len;
2503 unsigned long flags;
2504
2505 if (orinoco_lock(priv, &flags) != 0)
2506 return -EBUSY;
2507
2508 if (strlen(priv->desired_essid) > 0) {
2509 /* We read the desired SSID from the hardware rather
2510 than from priv->desired_essid, just in case the
2511 firmware is allowed to change it on us. I'm not
2512 sure about this */
2513 /* My guess is that the OWNSSID should always be whatever
2514 * we set to the card, whereas CURRENT_SSID is the one that
2515 * may change... - Jean II */
2516 u16 rid;
2517
2518 *active = 1;
2519
2520 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2521 HERMES_RID_CNFDESIREDSSID;
2522
2523 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2524 NULL, &essidbuf);
2525 if (err)
2526 goto fail_unlock;
2527 } else {
2528 *active = 0;
2529
2530 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2531 sizeof(essidbuf), NULL, &essidbuf);
2532 if (err)
2533 goto fail_unlock;
2534 }
2535
2536 len = le16_to_cpu(essidbuf.len);
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002537 BUG_ON(len > IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
2539 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2540 memcpy(buf, p, len);
2541 buf[len] = '\0';
2542
2543 fail_unlock:
2544 orinoco_unlock(priv, &flags);
2545
2546 return err;
2547}
2548
2549static long orinoco_hw_get_freq(struct orinoco_private *priv)
2550{
2551
2552 hermes_t *hw = &priv->hw;
2553 int err = 0;
2554 u16 channel;
2555 long freq = 0;
2556 unsigned long flags;
2557
2558 if (orinoco_lock(priv, &flags) != 0)
2559 return -EBUSY;
2560
2561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2562 if (err)
2563 goto out;
2564
2565 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2566 if (channel == 0) {
2567 err = -EBUSY;
2568 goto out;
2569 }
2570
2571 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2572 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2573 priv->ndev->name, channel);
2574 err = -EBUSY;
2575 goto out;
2576
2577 }
2578 freq = channel_frequency[channel-1] * 100000;
2579
2580 out:
2581 orinoco_unlock(priv, &flags);
2582
2583 if (err > 0)
2584 err = -EBUSY;
2585 return err ? err : freq;
2586}
2587
2588static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2589 int *numrates, s32 *rates, int max)
2590{
2591 hermes_t *hw = &priv->hw;
2592 struct hermes_idstring list;
2593 unsigned char *p = (unsigned char *)&list.val;
2594 int err = 0;
2595 int num;
2596 int i;
2597 unsigned long flags;
2598
2599 if (orinoco_lock(priv, &flags) != 0)
2600 return -EBUSY;
2601
2602 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2603 sizeof(list), NULL, &list);
2604 orinoco_unlock(priv, &flags);
2605
2606 if (err)
2607 return err;
2608
2609 num = le16_to_cpu(list.len);
2610 *numrates = num;
2611 num = min(num, max);
2612
2613 for (i = 0; i < num; i++) {
2614 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2615 }
2616
2617 return 0;
2618}
2619
Christoph Hellwig620554e2005-06-19 01:27:33 +02002620static int orinoco_ioctl_getname(struct net_device *dev,
2621 struct iw_request_info *info,
2622 char *name,
2623 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624{
2625 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 int numrates;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002627 int err;
2628
2629 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2630
2631 if (!err && (numrates > 2))
2632 strcpy(name, "IEEE 802.11b");
2633 else
2634 strcpy(name, "IEEE 802.11-DS");
2635
2636 return 0;
2637}
2638
Christoph Hellwig16739b02005-06-19 01:27:51 +02002639static int orinoco_ioctl_setwap(struct net_device *dev,
2640 struct iw_request_info *info,
2641 struct sockaddr *ap_addr,
2642 char *extra)
2643{
2644 struct orinoco_private *priv = netdev_priv(dev);
2645 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 unsigned long flags;
Christoph Hellwig16739b02005-06-19 01:27:51 +02002647 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2648 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
2650 if (orinoco_lock(priv, &flags) != 0)
2651 return -EBUSY;
2652
Christoph Hellwig16739b02005-06-19 01:27:51 +02002653 /* Enable automatic roaming - no sanity checks are needed */
2654 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2655 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2656 priv->bssid_fixed = 0;
2657 memset(priv->desired_bssid, 0, ETH_ALEN);
2658
2659 /* "off" means keep existing connection */
2660 if (ap_addr->sa_data[0] == 0) {
2661 __orinoco_hw_set_wap(priv);
2662 err = 0;
2663 }
2664 goto out;
2665 }
2666
2667 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2668 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2669 "support manual roaming\n",
2670 dev->name);
2671 err = -EOPNOTSUPP;
2672 goto out;
2673 }
2674
2675 if (priv->iw_mode != IW_MODE_INFRA) {
2676 printk(KERN_WARNING "%s: Manual roaming supported only in "
2677 "managed mode\n", dev->name);
2678 err = -EOPNOTSUPP;
2679 goto out;
2680 }
2681
2682 /* Intersil firmware hangs without Desired ESSID */
2683 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2684 strlen(priv->desired_essid) == 0) {
2685 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2686 "manual roaming\n", dev->name);
2687 err = -EOPNOTSUPP;
2688 goto out;
2689 }
2690
2691 /* Finally, enable manual roaming */
2692 priv->bssid_fixed = 1;
2693 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2694
2695 out:
2696 orinoco_unlock(priv, &flags);
2697 return err;
2698}
2699
Christoph Hellwig620554e2005-06-19 01:27:33 +02002700static int orinoco_ioctl_getwap(struct net_device *dev,
2701 struct iw_request_info *info,
2702 struct sockaddr *ap_addr,
2703 char *extra)
2704{
2705 struct orinoco_private *priv = netdev_priv(dev);
2706
2707 hermes_t *hw = &priv->hw;
2708 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 unsigned long flags;
2710
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 if (orinoco_lock(priv, &flags) != 0)
2712 return -EBUSY;
2713
Christoph Hellwig620554e2005-06-19 01:27:33 +02002714 ap_addr->sa_family = ARPHRD_ETHER;
2715 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2716 ETH_ALEN, NULL, ap_addr->sa_data);
2717
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 orinoco_unlock(priv, &flags);
2719
Christoph Hellwig620554e2005-06-19 01:27:33 +02002720 return err;
2721}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
Christoph Hellwig620554e2005-06-19 01:27:33 +02002723static int orinoco_ioctl_setmode(struct net_device *dev,
2724 struct iw_request_info *info,
2725 u32 *mode,
2726 char *extra)
2727{
2728 struct orinoco_private *priv = netdev_priv(dev);
2729 int err = -EINPROGRESS; /* Call commit handler */
2730 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731
Christoph Hellwig620554e2005-06-19 01:27:33 +02002732 if (priv->iw_mode == *mode)
2733 return 0;
2734
2735 if (orinoco_lock(priv, &flags) != 0)
2736 return -EBUSY;
2737
2738 switch (*mode) {
2739 case IW_MODE_ADHOC:
2740 if (!priv->has_ibss && !priv->has_port3)
2741 err = -EOPNOTSUPP;
2742 break;
2743
2744 case IW_MODE_INFRA:
2745 break;
2746
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002747 case IW_MODE_MONITOR:
2748 if (priv->broken_monitor && !force_monitor) {
2749 printk(KERN_WARNING "%s: Monitor mode support is "
2750 "buggy in this firmware, not enabling\n",
2751 dev->name);
2752 err = -EOPNOTSUPP;
2753 }
2754 break;
2755
Christoph Hellwig620554e2005-06-19 01:27:33 +02002756 default:
2757 err = -EOPNOTSUPP;
2758 break;
2759 }
2760
2761 if (err == -EINPROGRESS) {
2762 priv->iw_mode = *mode;
2763 set_port_type(priv);
2764 }
2765
2766 orinoco_unlock(priv, &flags);
2767
2768 return err;
2769}
2770
2771static int orinoco_ioctl_getmode(struct net_device *dev,
2772 struct iw_request_info *info,
2773 u32 *mode,
2774 char *extra)
2775{
2776 struct orinoco_private *priv = netdev_priv(dev);
2777
2778 *mode = priv->iw_mode;
2779 return 0;
2780}
2781
2782static int orinoco_ioctl_getiwrange(struct net_device *dev,
2783 struct iw_request_info *info,
2784 struct iw_point *rrq,
2785 char *extra)
2786{
2787 struct orinoco_private *priv = netdev_priv(dev);
2788 int err = 0;
2789 struct iw_range *range = (struct iw_range *) extra;
2790 int numrates;
2791 int i, k;
2792
2793 TRACE_ENTER(dev->name);
2794
2795 rrq->length = sizeof(struct iw_range);
2796 memset(range, 0, sizeof(struct iw_range));
2797
2798 range->we_version_compiled = WIRELESS_EXT;
2799 range->we_version_source = 14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
2801 /* Set available channels/frequencies */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002802 range->num_channels = NUM_CHANNELS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 k = 0;
2804 for (i = 0; i < NUM_CHANNELS; i++) {
2805 if (priv->channel_mask & (1 << i)) {
Christoph Hellwig620554e2005-06-19 01:27:33 +02002806 range->freq[k].i = i + 1;
2807 range->freq[k].m = channel_frequency[i] * 100000;
2808 range->freq[k].e = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 k++;
2810 }
2811
2812 if (k >= IW_MAX_FREQUENCIES)
2813 break;
2814 }
Christoph Hellwig620554e2005-06-19 01:27:33 +02002815 range->num_frequency = k;
2816 range->sensitivity = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
Christoph Hellwig620554e2005-06-19 01:27:33 +02002818 if (priv->has_wep) {
2819 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2820 range->encoding_size[0] = SMALL_KEY_SIZE;
2821 range->num_encoding_sizes = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
Christoph Hellwig620554e2005-06-19 01:27:33 +02002823 if (priv->has_big_wep) {
2824 range->encoding_size[1] = LARGE_KEY_SIZE;
2825 range->num_encoding_sizes = 2;
2826 }
2827 }
2828
Pavel Roskin343c6862005-09-09 18:43:02 -04002829 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 /* Quality stats meaningless in ad-hoc mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 } else {
Christoph Hellwig620554e2005-06-19 01:27:33 +02002832 range->max_qual.qual = 0x8b - 0x2f;
2833 range->max_qual.level = 0x2f - 0x95 - 1;
2834 range->max_qual.noise = 0x2f - 0x95 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 /* Need to get better values */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002836 range->avg_qual.qual = 0x24;
2837 range->avg_qual.level = 0xC2;
2838 range->avg_qual.noise = 0x9E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 }
2840
2841 err = orinoco_hw_get_bitratelist(priv, &numrates,
Christoph Hellwig620554e2005-06-19 01:27:33 +02002842 range->bitrate, IW_MAX_BITRATES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 if (err)
2844 return err;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002845 range->num_bitrates = numrates;
2846
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 /* Set an indication of the max TCP throughput in bit/s that we can
2848 * expect using this interface. May be use for QoS stuff...
2849 * Jean II */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002850 if (numrates > 2)
2851 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 else
Christoph Hellwig620554e2005-06-19 01:27:33 +02002853 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
Christoph Hellwig620554e2005-06-19 01:27:33 +02002855 range->min_rts = 0;
2856 range->max_rts = 2347;
2857 range->min_frag = 256;
2858 range->max_frag = 2346;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859
Christoph Hellwig620554e2005-06-19 01:27:33 +02002860 range->min_pmp = 0;
2861 range->max_pmp = 65535000;
2862 range->min_pmt = 0;
2863 range->max_pmt = 65535 * 1000; /* ??? */
2864 range->pmp_flags = IW_POWER_PERIOD;
2865 range->pmt_flags = IW_POWER_TIMEOUT;
2866 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867
Christoph Hellwig620554e2005-06-19 01:27:33 +02002868 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2869 range->retry_flags = IW_RETRY_LIMIT;
2870 range->r_time_flags = IW_RETRY_LIFETIME;
2871 range->min_retry = 0;
2872 range->max_retry = 65535; /* ??? */
2873 range->min_r_time = 0;
2874 range->max_r_time = 65535 * 1000; /* ??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
Pavel Roskin343c6862005-09-09 18:43:02 -04002876 /* Event capability (kernel) */
2877 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2878 /* Event capability (driver) */
2879 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2880 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2881 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2882 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2883
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 TRACE_EXIT(dev->name);
2885
2886 return 0;
2887}
2888
Christoph Hellwig620554e2005-06-19 01:27:33 +02002889static int orinoco_ioctl_setiwencode(struct net_device *dev,
2890 struct iw_request_info *info,
2891 struct iw_point *erq,
2892 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893{
2894 struct orinoco_private *priv = netdev_priv(dev);
2895 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2896 int setindex = priv->tx_key;
2897 int enable = priv->wep_on;
2898 int restricted = priv->wep_restrict;
2899 u16 xlen = 0;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002900 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 unsigned long flags;
2902
2903 if (! priv->has_wep)
2904 return -EOPNOTSUPP;
2905
2906 if (erq->pointer) {
2907 /* We actually have a key to set - check its length */
2908 if (erq->length > LARGE_KEY_SIZE)
2909 return -E2BIG;
2910
2911 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2912 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 }
2914
2915 if (orinoco_lock(priv, &flags) != 0)
2916 return -EBUSY;
2917
2918 if (erq->pointer) {
2919 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2920 index = priv->tx_key;
2921
2922 /* Adjust key length to a supported value */
2923 if (erq->length > SMALL_KEY_SIZE) {
2924 xlen = LARGE_KEY_SIZE;
2925 } else if (erq->length > 0) {
2926 xlen = SMALL_KEY_SIZE;
2927 } else
2928 xlen = 0;
2929
2930 /* Switch on WEP if off */
2931 if ((!enable) && (xlen > 0)) {
2932 setindex = index;
2933 enable = 1;
2934 }
2935 } else {
2936 /* Important note : if the user do "iwconfig eth0 enc off",
2937 * we will arrive there with an index of -1. This is valid
2938 * but need to be taken care off... Jean II */
2939 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2940 if((index != -1) || (erq->flags == 0)) {
2941 err = -EINVAL;
2942 goto out;
2943 }
2944 } else {
2945 /* Set the index : Check that the key is valid */
2946 if(priv->keys[index].len == 0) {
2947 err = -EINVAL;
2948 goto out;
2949 }
2950 setindex = index;
2951 }
2952 }
2953
2954 if (erq->flags & IW_ENCODE_DISABLED)
2955 enable = 0;
2956 if (erq->flags & IW_ENCODE_OPEN)
2957 restricted = 0;
2958 if (erq->flags & IW_ENCODE_RESTRICTED)
2959 restricted = 1;
2960
2961 if (erq->pointer) {
2962 priv->keys[index].len = cpu_to_le16(xlen);
2963 memset(priv->keys[index].data, 0,
2964 sizeof(priv->keys[index].data));
2965 memcpy(priv->keys[index].data, keybuf, erq->length);
2966 }
2967 priv->tx_key = setindex;
2968
2969 /* Try fast key change if connected and only keys are changed */
2970 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2971 netif_carrier_ok(dev)) {
2972 err = __orinoco_hw_setup_wepkeys(priv);
2973 /* No need to commit if successful */
2974 goto out;
2975 }
2976
2977 priv->wep_on = enable;
2978 priv->wep_restrict = restricted;
2979
2980 out:
2981 orinoco_unlock(priv, &flags);
2982
2983 return err;
2984}
2985
Christoph Hellwig620554e2005-06-19 01:27:33 +02002986static int orinoco_ioctl_getiwencode(struct net_device *dev,
2987 struct iw_request_info *info,
2988 struct iw_point *erq,
2989 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990{
2991 struct orinoco_private *priv = netdev_priv(dev);
2992 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2993 u16 xlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 unsigned long flags;
2995
2996 if (! priv->has_wep)
2997 return -EOPNOTSUPP;
2998
2999 if (orinoco_lock(priv, &flags) != 0)
3000 return -EBUSY;
3001
3002 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3003 index = priv->tx_key;
3004
3005 erq->flags = 0;
3006 if (! priv->wep_on)
3007 erq->flags |= IW_ENCODE_DISABLED;
3008 erq->flags |= index + 1;
3009
3010 if (priv->wep_restrict)
3011 erq->flags |= IW_ENCODE_RESTRICTED;
3012 else
3013 erq->flags |= IW_ENCODE_OPEN;
3014
3015 xlen = le16_to_cpu(priv->keys[index].len);
3016
3017 erq->length = xlen;
3018
3019 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3020
3021 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 return 0;
3023}
3024
Christoph Hellwig620554e2005-06-19 01:27:33 +02003025static int orinoco_ioctl_setessid(struct net_device *dev,
3026 struct iw_request_info *info,
3027 struct iw_point *erq,
3028 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029{
3030 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 unsigned long flags;
3032
3033 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3034 * anyway... - Jean II */
3035
Christoph Hellwig620554e2005-06-19 01:27:33 +02003036 /* Hum... Should not use Wireless Extension constant (may change),
3037 * should use our own... - Jean II */
3038 if (erq->length > IW_ESSID_MAX_SIZE)
3039 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040
3041 if (orinoco_lock(priv, &flags) != 0)
3042 return -EBUSY;
3043
Christoph Hellwig620554e2005-06-19 01:27:33 +02003044 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3045 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3046
3047 /* If not ANY, get the new ESSID */
3048 if (erq->flags) {
3049 memcpy(priv->desired_essid, essidbuf, erq->length);
3050 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051
3052 orinoco_unlock(priv, &flags);
3053
Christoph Hellwig620554e2005-06-19 01:27:33 +02003054 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055}
3056
Christoph Hellwig620554e2005-06-19 01:27:33 +02003057static int orinoco_ioctl_getessid(struct net_device *dev,
3058 struct iw_request_info *info,
3059 struct iw_point *erq,
3060 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061{
3062 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 int active;
3064 int err = 0;
3065 unsigned long flags;
3066
3067 TRACE_ENTER(dev->name);
3068
3069 if (netif_running(dev)) {
3070 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3071 if (err)
3072 return err;
3073 } else {
3074 if (orinoco_lock(priv, &flags) != 0)
3075 return -EBUSY;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003076 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 orinoco_unlock(priv, &flags);
3078 }
3079
3080 erq->flags = 1;
3081 erq->length = strlen(essidbuf) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
3083 TRACE_EXIT(dev->name);
3084
3085 return 0;
3086}
3087
Christoph Hellwig620554e2005-06-19 01:27:33 +02003088static int orinoco_ioctl_setnick(struct net_device *dev,
3089 struct iw_request_info *info,
3090 struct iw_point *nrq,
3091 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092{
3093 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 unsigned long flags;
3095
3096 if (nrq->length > IW_ESSID_MAX_SIZE)
3097 return -E2BIG;
3098
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 if (orinoco_lock(priv, &flags) != 0)
3100 return -EBUSY;
3101
Christoph Hellwig620554e2005-06-19 01:27:33 +02003102 memset(priv->nick, 0, sizeof(priv->nick));
3103 memcpy(priv->nick, nickbuf, nrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104
3105 orinoco_unlock(priv, &flags);
3106
Christoph Hellwig620554e2005-06-19 01:27:33 +02003107 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108}
3109
Christoph Hellwig620554e2005-06-19 01:27:33 +02003110static int orinoco_ioctl_getnick(struct net_device *dev,
3111 struct iw_request_info *info,
3112 struct iw_point *nrq,
3113 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114{
3115 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 unsigned long flags;
3117
3118 if (orinoco_lock(priv, &flags) != 0)
3119 return -EBUSY;
3120
3121 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3122 orinoco_unlock(priv, &flags);
3123
3124 nrq->length = strlen(nickbuf)+1;
3125
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 return 0;
3127}
3128
Christoph Hellwig620554e2005-06-19 01:27:33 +02003129static int orinoco_ioctl_setfreq(struct net_device *dev,
3130 struct iw_request_info *info,
3131 struct iw_freq *frq,
3132 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133{
3134 struct orinoco_private *priv = netdev_priv(dev);
3135 int chan = -1;
3136 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003137 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003139 /* In infrastructure mode the AP sets the channel */
3140 if (priv->iw_mode == IW_MODE_INFRA)
3141 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142
3143 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3144 /* Setting by channel number */
3145 chan = frq->m;
3146 } else {
3147 /* Setting by frequency - search the table */
3148 int mult = 1;
3149 int i;
3150
3151 for (i = 0; i < (6 - frq->e); i++)
3152 mult *= 10;
3153
3154 for (i = 0; i < NUM_CHANNELS; i++)
3155 if (frq->m == (channel_frequency[i] * mult))
3156 chan = i+1;
3157 }
3158
3159 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3160 ! (priv->channel_mask & (1 << (chan-1)) ) )
3161 return -EINVAL;
3162
3163 if (orinoco_lock(priv, &flags) != 0)
3164 return -EBUSY;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003165
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 priv->channel = chan;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003167 if (priv->iw_mode == IW_MODE_MONITOR) {
3168 /* Fast channel change - no commit if successful */
3169 hermes_t *hw = &priv->hw;
3170 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3171 HERMES_TEST_SET_CHANNEL,
3172 chan, NULL);
3173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 orinoco_unlock(priv, &flags);
3175
Christoph Hellwig620554e2005-06-19 01:27:33 +02003176 return err;
3177}
3178
3179static int orinoco_ioctl_getfreq(struct net_device *dev,
3180 struct iw_request_info *info,
3181 struct iw_freq *frq,
3182 char *extra)
3183{
3184 struct orinoco_private *priv = netdev_priv(dev);
3185 int tmp;
3186
3187 /* Locking done in there */
3188 tmp = orinoco_hw_get_freq(priv);
3189 if (tmp < 0) {
3190 return tmp;
3191 }
3192
3193 frq->m = tmp;
3194 frq->e = 1;
3195
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 return 0;
3197}
3198
Christoph Hellwig620554e2005-06-19 01:27:33 +02003199static int orinoco_ioctl_getsens(struct net_device *dev,
3200 struct iw_request_info *info,
3201 struct iw_param *srq,
3202 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203{
3204 struct orinoco_private *priv = netdev_priv(dev);
3205 hermes_t *hw = &priv->hw;
3206 u16 val;
3207 int err;
3208 unsigned long flags;
3209
3210 if (!priv->has_sensitivity)
3211 return -EOPNOTSUPP;
3212
3213 if (orinoco_lock(priv, &flags) != 0)
3214 return -EBUSY;
3215 err = hermes_read_wordrec(hw, USER_BAP,
3216 HERMES_RID_CNFSYSTEMSCALE, &val);
3217 orinoco_unlock(priv, &flags);
3218
3219 if (err)
3220 return err;
3221
3222 srq->value = val;
3223 srq->fixed = 0; /* auto */
3224
3225 return 0;
3226}
3227
Christoph Hellwig620554e2005-06-19 01:27:33 +02003228static int orinoco_ioctl_setsens(struct net_device *dev,
3229 struct iw_request_info *info,
3230 struct iw_param *srq,
3231 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232{
3233 struct orinoco_private *priv = netdev_priv(dev);
3234 int val = srq->value;
3235 unsigned long flags;
3236
3237 if (!priv->has_sensitivity)
3238 return -EOPNOTSUPP;
3239
3240 if ((val < 1) || (val > 3))
3241 return -EINVAL;
3242
3243 if (orinoco_lock(priv, &flags) != 0)
3244 return -EBUSY;
3245 priv->ap_density = val;
3246 orinoco_unlock(priv, &flags);
3247
Christoph Hellwig620554e2005-06-19 01:27:33 +02003248 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249}
3250
Christoph Hellwig620554e2005-06-19 01:27:33 +02003251static int orinoco_ioctl_setrts(struct net_device *dev,
3252 struct iw_request_info *info,
3253 struct iw_param *rrq,
3254 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255{
3256 struct orinoco_private *priv = netdev_priv(dev);
3257 int val = rrq->value;
3258 unsigned long flags;
3259
3260 if (rrq->disabled)
3261 val = 2347;
3262
3263 if ( (val < 0) || (val > 2347) )
3264 return -EINVAL;
3265
3266 if (orinoco_lock(priv, &flags) != 0)
3267 return -EBUSY;
3268
3269 priv->rts_thresh = val;
3270 orinoco_unlock(priv, &flags);
3271
Christoph Hellwig620554e2005-06-19 01:27:33 +02003272 return -EINPROGRESS; /* Call commit handler */
3273}
3274
3275static int orinoco_ioctl_getrts(struct net_device *dev,
3276 struct iw_request_info *info,
3277 struct iw_param *rrq,
3278 char *extra)
3279{
3280 struct orinoco_private *priv = netdev_priv(dev);
3281
3282 rrq->value = priv->rts_thresh;
3283 rrq->disabled = (rrq->value == 2347);
3284 rrq->fixed = 1;
3285
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 return 0;
3287}
3288
Christoph Hellwig620554e2005-06-19 01:27:33 +02003289static int orinoco_ioctl_setfrag(struct net_device *dev,
3290 struct iw_request_info *info,
3291 struct iw_param *frq,
3292 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293{
3294 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003295 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 unsigned long flags;
3297
3298 if (orinoco_lock(priv, &flags) != 0)
3299 return -EBUSY;
3300
3301 if (priv->has_mwo) {
3302 if (frq->disabled)
3303 priv->mwo_robust = 0;
3304 else {
3305 if (frq->fixed)
3306 printk(KERN_WARNING "%s: Fixed fragmentation is "
3307 "not supported on this firmware. "
3308 "Using MWO robust instead.\n", dev->name);
3309 priv->mwo_robust = 1;
3310 }
3311 } else {
3312 if (frq->disabled)
3313 priv->frag_thresh = 2346;
3314 else {
3315 if ( (frq->value < 256) || (frq->value > 2346) )
3316 err = -EINVAL;
3317 else
3318 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3319 }
3320 }
3321
3322 orinoco_unlock(priv, &flags);
3323
3324 return err;
3325}
3326
Christoph Hellwig620554e2005-06-19 01:27:33 +02003327static int orinoco_ioctl_getfrag(struct net_device *dev,
3328 struct iw_request_info *info,
3329 struct iw_param *frq,
3330 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331{
3332 struct orinoco_private *priv = netdev_priv(dev);
3333 hermes_t *hw = &priv->hw;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003334 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 u16 val;
3336 unsigned long flags;
3337
3338 if (orinoco_lock(priv, &flags) != 0)
3339 return -EBUSY;
3340
3341 if (priv->has_mwo) {
3342 err = hermes_read_wordrec(hw, USER_BAP,
3343 HERMES_RID_CNFMWOROBUST_AGERE,
3344 &val);
3345 if (err)
3346 val = 0;
3347
3348 frq->value = val ? 2347 : 0;
3349 frq->disabled = ! val;
3350 frq->fixed = 0;
3351 } else {
3352 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3353 &val);
3354 if (err)
3355 val = 0;
3356
3357 frq->value = val;
3358 frq->disabled = (val >= 2346);
3359 frq->fixed = 1;
3360 }
3361
3362 orinoco_unlock(priv, &flags);
3363
3364 return err;
3365}
3366
Christoph Hellwig620554e2005-06-19 01:27:33 +02003367static int orinoco_ioctl_setrate(struct net_device *dev,
3368 struct iw_request_info *info,
3369 struct iw_param *rrq,
3370 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371{
3372 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 int ratemode = -1;
3374 int bitrate; /* 100s of kilobits */
3375 int i;
3376 unsigned long flags;
3377
3378 /* As the user space doesn't know our highest rate, it uses -1
3379 * to ask us to set the highest rate. Test it using "iwconfig
3380 * ethX rate auto" - Jean II */
3381 if (rrq->value == -1)
3382 bitrate = 110;
3383 else {
3384 if (rrq->value % 100000)
3385 return -EINVAL;
3386 bitrate = rrq->value / 100000;
3387 }
3388
3389 if ( (bitrate != 10) && (bitrate != 20) &&
3390 (bitrate != 55) && (bitrate != 110) )
3391 return -EINVAL;
3392
3393 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3394 if ( (bitrate_table[i].bitrate == bitrate) &&
3395 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3396 ratemode = i;
3397 break;
3398 }
3399
3400 if (ratemode == -1)
3401 return -EINVAL;
3402
3403 if (orinoco_lock(priv, &flags) != 0)
3404 return -EBUSY;
3405 priv->bitratemode = ratemode;
3406 orinoco_unlock(priv, &flags);
3407
Christoph Hellwig620554e2005-06-19 01:27:33 +02003408 return -EINPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409}
3410
Christoph Hellwig620554e2005-06-19 01:27:33 +02003411static int orinoco_ioctl_getrate(struct net_device *dev,
3412 struct iw_request_info *info,
3413 struct iw_param *rrq,
3414 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415{
3416 struct orinoco_private *priv = netdev_priv(dev);
3417 hermes_t *hw = &priv->hw;
3418 int err = 0;
3419 int ratemode;
3420 int i;
3421 u16 val;
3422 unsigned long flags;
3423
3424 if (orinoco_lock(priv, &flags) != 0)
3425 return -EBUSY;
3426
3427 ratemode = priv->bitratemode;
3428
3429 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3430
3431 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3432 rrq->fixed = ! bitrate_table[ratemode].automatic;
3433 rrq->disabled = 0;
3434
3435 /* If the interface is running we try to find more about the
3436 current mode */
3437 if (netif_running(dev)) {
3438 err = hermes_read_wordrec(hw, USER_BAP,
3439 HERMES_RID_CURRENTTXRATE, &val);
3440 if (err)
3441 goto out;
3442
3443 switch (priv->firmware_type) {
3444 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3445 /* Note : in Lucent firmware, the return value of
3446 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3447 * and therefore is totally different from the
3448 * encoding of HERMES_RID_CNFTXRATECONTROL.
3449 * Don't forget that 6Mb/s is really 5.5Mb/s */
3450 if (val == 6)
3451 rrq->value = 5500000;
3452 else
3453 rrq->value = val * 1000000;
3454 break;
3455 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3456 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3457 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3458 if (bitrate_table[i].intersil_txratectrl == val) {
3459 ratemode = i;
3460 break;
3461 }
3462 if (i >= BITRATE_TABLE_SIZE)
3463 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3464 dev->name, val);
3465
3466 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3467 break;
3468 default:
3469 BUG();
3470 }
3471 }
3472
3473 out:
3474 orinoco_unlock(priv, &flags);
3475
3476 return err;
3477}
3478
Christoph Hellwig620554e2005-06-19 01:27:33 +02003479static int orinoco_ioctl_setpower(struct net_device *dev,
3480 struct iw_request_info *info,
3481 struct iw_param *prq,
3482 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483{
3484 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003485 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 unsigned long flags;
3487
3488 if (orinoco_lock(priv, &flags) != 0)
3489 return -EBUSY;
3490
3491 if (prq->disabled) {
3492 priv->pm_on = 0;
3493 } else {
3494 switch (prq->flags & IW_POWER_MODE) {
3495 case IW_POWER_UNICAST_R:
3496 priv->pm_mcast = 0;
3497 priv->pm_on = 1;
3498 break;
3499 case IW_POWER_ALL_R:
3500 priv->pm_mcast = 1;
3501 priv->pm_on = 1;
3502 break;
3503 case IW_POWER_ON:
3504 /* No flags : but we may have a value - Jean II */
3505 break;
3506 default:
3507 err = -EINVAL;
3508 }
3509 if (err)
3510 goto out;
3511
3512 if (prq->flags & IW_POWER_TIMEOUT) {
3513 priv->pm_on = 1;
3514 priv->pm_timeout = prq->value / 1000;
3515 }
3516 if (prq->flags & IW_POWER_PERIOD) {
3517 priv->pm_on = 1;
3518 priv->pm_period = prq->value / 1000;
3519 }
3520 /* It's valid to not have a value if we are just toggling
3521 * the flags... Jean II */
3522 if(!priv->pm_on) {
3523 err = -EINVAL;
3524 goto out;
3525 }
3526 }
3527
3528 out:
3529 orinoco_unlock(priv, &flags);
3530
3531 return err;
3532}
3533
Christoph Hellwig620554e2005-06-19 01:27:33 +02003534static int orinoco_ioctl_getpower(struct net_device *dev,
3535 struct iw_request_info *info,
3536 struct iw_param *prq,
3537 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538{
3539 struct orinoco_private *priv = netdev_priv(dev);
3540 hermes_t *hw = &priv->hw;
3541 int err = 0;
3542 u16 enable, period, timeout, mcast;
3543 unsigned long flags;
3544
3545 if (orinoco_lock(priv, &flags) != 0)
3546 return -EBUSY;
3547
3548 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3549 if (err)
3550 goto out;
3551
3552 err = hermes_read_wordrec(hw, USER_BAP,
3553 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3554 if (err)
3555 goto out;
3556
3557 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3558 if (err)
3559 goto out;
3560
3561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3562 if (err)
3563 goto out;
3564
3565 prq->disabled = !enable;
3566 /* Note : by default, display the period */
3567 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3568 prq->flags = IW_POWER_TIMEOUT;
3569 prq->value = timeout * 1000;
3570 } else {
3571 prq->flags = IW_POWER_PERIOD;
3572 prq->value = period * 1000;
3573 }
3574 if (mcast)
3575 prq->flags |= IW_POWER_ALL_R;
3576 else
3577 prq->flags |= IW_POWER_UNICAST_R;
3578
3579 out:
3580 orinoco_unlock(priv, &flags);
3581
3582 return err;
3583}
3584
Christoph Hellwig620554e2005-06-19 01:27:33 +02003585static int orinoco_ioctl_getretry(struct net_device *dev,
3586 struct iw_request_info *info,
3587 struct iw_param *rrq,
3588 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589{
3590 struct orinoco_private *priv = netdev_priv(dev);
3591 hermes_t *hw = &priv->hw;
3592 int err = 0;
3593 u16 short_limit, long_limit, lifetime;
3594 unsigned long flags;
3595
3596 if (orinoco_lock(priv, &flags) != 0)
3597 return -EBUSY;
3598
3599 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3600 &short_limit);
3601 if (err)
3602 goto out;
3603
3604 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3605 &long_limit);
3606 if (err)
3607 goto out;
3608
3609 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3610 &lifetime);
3611 if (err)
3612 goto out;
3613
3614 rrq->disabled = 0; /* Can't be disabled */
3615
3616 /* Note : by default, display the retry number */
3617 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3618 rrq->flags = IW_RETRY_LIFETIME;
3619 rrq->value = lifetime * 1000; /* ??? */
3620 } else {
3621 /* By default, display the min number */
3622 if ((rrq->flags & IW_RETRY_MAX)) {
3623 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3624 rrq->value = long_limit;
3625 } else {
3626 rrq->flags = IW_RETRY_LIMIT;
3627 rrq->value = short_limit;
3628 if(short_limit != long_limit)
3629 rrq->flags |= IW_RETRY_MIN;
3630 }
3631 }
3632
3633 out:
3634 orinoco_unlock(priv, &flags);
3635
3636 return err;
3637}
3638
Christoph Hellwig620554e2005-06-19 01:27:33 +02003639static int orinoco_ioctl_reset(struct net_device *dev,
3640 struct iw_request_info *info,
3641 void *wrqu,
3642 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643{
3644 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003645
3646 if (! capable(CAP_NET_ADMIN))
3647 return -EPERM;
3648
3649 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3650 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3651
3652 /* Firmware reset */
3653 orinoco_reset(dev);
3654 } else {
3655 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3656
3657 schedule_work(&priv->reset_work);
3658 }
3659
3660 return 0;
3661}
3662
3663static int orinoco_ioctl_setibssport(struct net_device *dev,
3664 struct iw_request_info *info,
3665 void *wrqu,
3666 char *extra)
3667
3668{
3669 struct orinoco_private *priv = netdev_priv(dev);
3670 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 unsigned long flags;
3672
3673 if (orinoco_lock(priv, &flags) != 0)
3674 return -EBUSY;
3675
3676 priv->ibss_port = val ;
3677
3678 /* Actually update the mode we are using */
3679 set_port_type(priv);
3680
3681 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003682 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683}
3684
Christoph Hellwig620554e2005-06-19 01:27:33 +02003685static int orinoco_ioctl_getibssport(struct net_device *dev,
3686 struct iw_request_info *info,
3687 void *wrqu,
3688 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689{
3690 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003691 int *val = (int *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692
3693 *val = priv->ibss_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 return 0;
3695}
3696
Christoph Hellwig620554e2005-06-19 01:27:33 +02003697static int orinoco_ioctl_setport3(struct net_device *dev,
3698 struct iw_request_info *info,
3699 void *wrqu,
3700 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701{
3702 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003703 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 int err = 0;
3705 unsigned long flags;
3706
3707 if (orinoco_lock(priv, &flags) != 0)
3708 return -EBUSY;
3709
3710 switch (val) {
3711 case 0: /* Try to do IEEE ad-hoc mode */
3712 if (! priv->has_ibss) {
3713 err = -EINVAL;
3714 break;
3715 }
3716 priv->prefer_port3 = 0;
3717
3718 break;
3719
3720 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3721 if (! priv->has_port3) {
3722 err = -EINVAL;
3723 break;
3724 }
3725 priv->prefer_port3 = 1;
3726 break;
3727
3728 default:
3729 err = -EINVAL;
3730 }
3731
Christoph Hellwig620554e2005-06-19 01:27:33 +02003732 if (! err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 /* Actually update the mode we are using */
3734 set_port_type(priv);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003735 err = -EINPROGRESS;
3736 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737
3738 orinoco_unlock(priv, &flags);
3739
3740 return err;
3741}
3742
Christoph Hellwig620554e2005-06-19 01:27:33 +02003743static int orinoco_ioctl_getport3(struct net_device *dev,
3744 struct iw_request_info *info,
3745 void *wrqu,
3746 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747{
3748 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003749 int *val = (int *) extra;
3750
3751 *val = priv->prefer_port3;
3752 return 0;
3753}
3754
3755static int orinoco_ioctl_setpreamble(struct net_device *dev,
3756 struct iw_request_info *info,
3757 void *wrqu,
3758 char *extra)
3759{
3760 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003762 int val;
3763
3764 if (! priv->has_preamble)
3765 return -EOPNOTSUPP;
3766
3767 /* 802.11b has recently defined some short preamble.
3768 * Basically, the Phy header has been reduced in size.
3769 * This increase performance, especially at high rates
3770 * (the preamble is transmitted at 1Mb/s), unfortunately
3771 * this give compatibility troubles... - Jean II */
3772 val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773
3774 if (orinoco_lock(priv, &flags) != 0)
3775 return -EBUSY;
3776
Christoph Hellwig620554e2005-06-19 01:27:33 +02003777 if (val)
3778 priv->preamble = 1;
3779 else
3780 priv->preamble = 0;
3781
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003783
3784 return -EINPROGRESS; /* Call commit handler */
3785}
3786
3787static int orinoco_ioctl_getpreamble(struct net_device *dev,
3788 struct iw_request_info *info,
3789 void *wrqu,
3790 char *extra)
3791{
3792 struct orinoco_private *priv = netdev_priv(dev);
3793 int *val = (int *) extra;
3794
3795 if (! priv->has_preamble)
3796 return -EOPNOTSUPP;
3797
3798 *val = priv->preamble;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 return 0;
3800}
3801
Christoph Hellwig620554e2005-06-19 01:27:33 +02003802/* ioctl interface to hermes_read_ltv()
3803 * To use with iwpriv, pass the RID as the token argument, e.g.
3804 * iwpriv get_rid [0xfc00]
3805 * At least Wireless Tools 25 is required to use iwpriv.
3806 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3807static int orinoco_ioctl_getrid(struct net_device *dev,
3808 struct iw_request_info *info,
3809 struct iw_point *data,
3810 char *extra)
3811{
3812 struct orinoco_private *priv = netdev_priv(dev);
3813 hermes_t *hw = &priv->hw;
3814 int rid = data->flags;
3815 u16 length;
3816 int err;
3817 unsigned long flags;
3818
3819 /* It's a "get" function, but we don't want users to access the
3820 * WEP key and other raw firmware data */
3821 if (! capable(CAP_NET_ADMIN))
3822 return -EPERM;
3823
3824 if (rid < 0xfc00 || rid > 0xffff)
3825 return -EINVAL;
3826
3827 if (orinoco_lock(priv, &flags) != 0)
3828 return -EBUSY;
3829
3830 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3831 extra);
3832 if (err)
3833 goto out;
3834
3835 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3836 MAX_RID_LEN);
3837
3838 out:
3839 orinoco_unlock(priv, &flags);
3840 return err;
3841}
3842
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003843/* Trigger a scan (look for other cells in the vicinity */
3844static int orinoco_ioctl_setscan(struct net_device *dev,
3845 struct iw_request_info *info,
3846 struct iw_param *srq,
3847 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848{
3849 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003850 hermes_t *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 unsigned long flags;
3853
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003854 /* Note : you may have realised that, as this is a SET operation,
3855 * this is priviledged and therefore a normal user can't
3856 * perform scanning.
3857 * This is not an error, while the device perform scanning,
3858 * traffic doesn't flow, so it's a perfect DoS...
3859 * Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003861 if (orinoco_lock(priv, &flags) != 0)
3862 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003864 /* Scanning with port 0 disabled would fail */
3865 if (!netif_running(dev)) {
3866 err = -ENETDOWN;
3867 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003870 /* In monitor mode, the scan results are always empty.
3871 * Probe responses are passed to the driver as received
3872 * frames and could be processed in software. */
3873 if (priv->iw_mode == IW_MODE_MONITOR) {
3874 err = -EOPNOTSUPP;
3875 goto out;
3876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003878 /* Note : because we don't lock out the irq handler, the way
3879 * we access scan variables in priv is critical.
3880 * o scan_inprogress : not touched by irq handler
3881 * o scan_mode : not touched by irq handler
3882 * o scan_result : irq is strict producer, non-irq is strict
3883 * consumer.
3884 * o scan_len : synchronised with scan_result
3885 * Before modifying anything on those variables, please think hard !
3886 * Jean II */
3887
3888 /* If there is still some left-over scan results, get rid of it */
3889 if (priv->scan_result != NULL) {
3890 /* What's likely is that a client did crash or was killed
3891 * between triggering the scan request and reading the
3892 * results, so we need to reset everything.
3893 * Some clients that are too slow may suffer from that...
3894 * Jean II */
3895 kfree(priv->scan_result);
3896 priv->scan_result = NULL;
3897 }
3898
3899 /* Save flags */
3900 priv->scan_mode = srq->flags;
3901
3902 /* Always trigger scanning, even if it's in progress.
3903 * This way, if the info frame get lost, we will recover somewhat
3904 * gracefully - Jean II */
3905
3906 if (priv->has_hostscan) {
3907 switch (priv->firmware_type) {
3908 case FIRMWARE_TYPE_SYMBOL:
3909 err = hermes_write_wordrec(hw, USER_BAP,
3910 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3911 HERMES_HOSTSCAN_SYMBOL_ONCE |
3912 HERMES_HOSTSCAN_SYMBOL_BCAST);
3913 break;
3914 case FIRMWARE_TYPE_INTERSIL: {
Pavel Roskind133ae42005-09-23 04:18:06 -04003915 __le16 req[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003916
3917 req[0] = cpu_to_le16(0x3fff); /* All channels */
3918 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3919 req[2] = 0; /* Any ESSID */
3920 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3921 HERMES_RID_CNFHOSTSCAN, &req);
3922 }
3923 break;
3924 case FIRMWARE_TYPE_AGERE:
3925 err = hermes_write_wordrec(hw, USER_BAP,
3926 HERMES_RID_CNFSCANSSID_AGERE,
3927 0); /* Any ESSID */
3928 if (err)
3929 break;
3930
3931 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3932 break;
3933 }
3934 } else
3935 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3936
3937 /* One more client */
3938 if (! err)
3939 priv->scan_inprogress = 1;
3940
3941 out:
3942 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 return err;
3944}
3945
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003946/* Translate scan data returned from the card to a card independant
Pavel Roskin70817c42005-09-01 20:02:50 -04003947 * format that the Wireless Tools will understand - Jean II
3948 * Return message length or -errno for fatal errors */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003949static inline int orinoco_translate_scan(struct net_device *dev,
3950 char *buffer,
3951 char *scan,
3952 int scan_len)
3953{
3954 struct orinoco_private *priv = netdev_priv(dev);
3955 int offset; /* In the scan data */
3956 union hermes_scan_info *atom;
3957 int atom_len;
3958 u16 capabilities;
3959 u16 channel;
3960 struct iw_event iwe; /* Temporary buffer */
3961 char * current_ev = buffer;
3962 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3963
3964 switch (priv->firmware_type) {
3965 case FIRMWARE_TYPE_AGERE:
3966 atom_len = sizeof(struct agere_scan_apinfo);
3967 offset = 0;
3968 break;
3969 case FIRMWARE_TYPE_SYMBOL:
3970 /* Lack of documentation necessitates this hack.
3971 * Different firmwares have 68 or 76 byte long atoms.
3972 * We try modulo first. If the length divides by both,
3973 * we check what would be the channel in the second
3974 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3975 * Valid channel cannot be 0. */
3976 if (scan_len % 76)
3977 atom_len = 68;
3978 else if (scan_len % 68)
3979 atom_len = 76;
3980 else if (scan_len >= 1292 && scan[68] == 0)
3981 atom_len = 76;
3982 else
3983 atom_len = 68;
3984 offset = 0;
3985 break;
3986 case FIRMWARE_TYPE_INTERSIL:
3987 offset = 4;
Pavel Roskin70817c42005-09-01 20:02:50 -04003988 if (priv->has_hostscan) {
Pavel Roskind133ae42005-09-23 04:18:06 -04003989 atom_len = le16_to_cpup((__le16 *)scan);
Pavel Roskin70817c42005-09-01 20:02:50 -04003990 /* Sanity check for atom_len */
3991 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3992 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3993 dev->name, atom_len);
3994 return -EIO;
3995 }
3996 } else
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003997 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3998 break;
3999 default:
Pavel Roskin70817c42005-09-01 20:02:50 -04004000 return -EOPNOTSUPP;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004001 }
4002
4003 /* Check that we got an whole number of atoms */
4004 if ((scan_len - offset) % atom_len) {
4005 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4006 "atom_len %d, offset %d\n", dev->name, scan_len,
4007 atom_len, offset);
Pavel Roskin70817c42005-09-01 20:02:50 -04004008 return -EIO;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004009 }
4010
4011 /* Read the entries one by one */
4012 for (; offset + atom_len <= scan_len; offset += atom_len) {
4013 /* Get next atom */
4014 atom = (union hermes_scan_info *) (scan + offset);
4015
4016 /* First entry *MUST* be the AP MAC address */
4017 iwe.cmd = SIOCGIWAP;
4018 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4019 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4020 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4021
4022 /* Other entries will be displayed in the order we give them */
4023
4024 /* Add the ESSID */
4025 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4026 if (iwe.u.data.length > 32)
4027 iwe.u.data.length = 32;
4028 iwe.cmd = SIOCGIWESSID;
4029 iwe.u.data.flags = 1;
4030 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4031
4032 /* Add mode */
4033 iwe.cmd = SIOCGIWMODE;
4034 capabilities = le16_to_cpu(atom->a.capabilities);
4035 if (capabilities & 0x3) {
4036 if (capabilities & 0x1)
4037 iwe.u.mode = IW_MODE_MASTER;
4038 else
4039 iwe.u.mode = IW_MODE_ADHOC;
4040 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4041 }
4042
4043 channel = atom->s.channel;
4044 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4045 /* Add frequency */
4046 iwe.cmd = SIOCGIWFREQ;
4047 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4048 iwe.u.freq.e = 1;
4049 current_ev = iwe_stream_add_event(current_ev, end_buf,
4050 &iwe, IW_EV_FREQ_LEN);
4051 }
4052
4053 /* Add quality statistics */
4054 iwe.cmd = IWEVQUAL;
4055 iwe.u.qual.updated = 0x10; /* no link quality */
4056 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4057 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4058 /* Wireless tools prior to 27.pre22 will show link quality
4059 * anyway, so we provide a reasonable value. */
4060 if (iwe.u.qual.level > iwe.u.qual.noise)
4061 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4062 else
4063 iwe.u.qual.qual = 0;
4064 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4065
4066 /* Add encryption capability */
4067 iwe.cmd = SIOCGIWENCODE;
4068 if (capabilities & 0x10)
4069 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4070 else
4071 iwe.u.data.flags = IW_ENCODE_DISABLED;
4072 iwe.u.data.length = 0;
4073 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4074
4075 /* Bit rate is not available in Lucent/Agere firmwares */
4076 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4077 char * current_val = current_ev + IW_EV_LCP_LEN;
4078 int i;
4079 int step;
4080
4081 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4082 step = 2;
4083 else
4084 step = 1;
4085
4086 iwe.cmd = SIOCGIWRATE;
4087 /* Those two flags are ignored... */
4088 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4089 /* Max 10 values */
4090 for (i = 0; i < 10; i += step) {
4091 /* NULL terminated */
4092 if (atom->p.rates[i] == 0x0)
4093 break;
4094 /* Bit rate given in 500 kb/s units (+ 0x80) */
4095 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4096 current_val = iwe_stream_add_value(current_ev, current_val,
4097 end_buf, &iwe,
4098 IW_EV_PARAM_LEN);
4099 }
4100 /* Check if we added any event */
4101 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4102 current_ev = current_val;
4103 }
4104
4105 /* The other data in the scan result are not really
4106 * interesting, so for now drop it - Jean II */
4107 }
4108 return current_ev - buffer;
4109}
4110
4111/* Return results of a scan */
4112static int orinoco_ioctl_getscan(struct net_device *dev,
4113 struct iw_request_info *info,
4114 struct iw_point *srq,
4115 char *extra)
4116{
4117 struct orinoco_private *priv = netdev_priv(dev);
4118 int err = 0;
4119 unsigned long flags;
4120
4121 if (orinoco_lock(priv, &flags) != 0)
4122 return -EBUSY;
4123
4124 /* If no results yet, ask to try again later */
4125 if (priv->scan_result == NULL) {
4126 if (priv->scan_inprogress)
4127 /* Important note : we don't want to block the caller
4128 * until results are ready for various reasons.
4129 * First, managing wait queues is complex and racy.
4130 * Second, we grab some rtnetlink lock before comming
4131 * here (in dev_ioctl()).
4132 * Third, we generate an Wireless Event, so the
4133 * caller can wait itself on that - Jean II */
4134 err = -EAGAIN;
4135 else
4136 /* Client error, no scan results...
4137 * The caller need to restart the scan. */
4138 err = -ENODATA;
4139 } else {
4140 /* We have some results to push back to user space */
4141
4142 /* Translate to WE format */
Pavel Roskin70817c42005-09-01 20:02:50 -04004143 int ret = orinoco_translate_scan(dev, extra,
4144 priv->scan_result,
4145 priv->scan_len);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004146
Pavel Roskin70817c42005-09-01 20:02:50 -04004147 if (ret < 0) {
4148 err = ret;
4149 kfree(priv->scan_result);
4150 priv->scan_result = NULL;
4151 } else {
4152 srq->length = ret;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004153
Pavel Roskin70817c42005-09-01 20:02:50 -04004154 /* Return flags */
4155 srq->flags = (__u16) priv->scan_mode;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004156
Pavel Roskin70817c42005-09-01 20:02:50 -04004157 /* In any case, Scan results will be cleaned up in the
4158 * reset function and when exiting the driver.
4159 * The person triggering the scanning may never come to
4160 * pick the results, so we need to do it in those places.
4161 * Jean II */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004162
4163#ifdef SCAN_SINGLE_READ
Pavel Roskin70817c42005-09-01 20:02:50 -04004164 /* If you enable this option, only one client (the first
4165 * one) will be able to read the result (and only one
4166 * time). If there is multiple concurent clients that
4167 * want to read scan results, this behavior is not
4168 * advisable - Jean II */
4169 kfree(priv->scan_result);
4170 priv->scan_result = NULL;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004171#endif /* SCAN_SINGLE_READ */
Pavel Roskin70817c42005-09-01 20:02:50 -04004172 /* Here, if too much time has elapsed since last scan,
4173 * we may want to clean up scan results... - Jean II */
4174 }
4175
4176 /* Scan is no longer in progress */
4177 priv->scan_inprogress = 0;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004178 }
4179
4180 orinoco_unlock(priv, &flags);
4181 return err;
4182}
4183
Christoph Hellwig620554e2005-06-19 01:27:33 +02004184/* Commit handler, called after set operations */
4185static int orinoco_ioctl_commit(struct net_device *dev,
4186 struct iw_request_info *info,
4187 void *wrqu,
4188 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189{
4190 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004191 struct hermes *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004193 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194
Christoph Hellwig620554e2005-06-19 01:27:33 +02004195 if (!priv->open)
4196 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197
Christoph Hellwig620554e2005-06-19 01:27:33 +02004198 if (priv->broken_disableport) {
4199 orinoco_reset(dev);
4200 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202
Christoph Hellwig620554e2005-06-19 01:27:33 +02004203 if (orinoco_lock(priv, &flags) != 0)
4204 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205
Christoph Hellwig620554e2005-06-19 01:27:33 +02004206 err = hermes_disable_port(hw, 0);
4207 if (err) {
4208 printk(KERN_WARNING "%s: Unable to disable port "
4209 "while reconfiguring card\n", dev->name);
4210 priv->broken_disableport = 1;
4211 goto out;
4212 }
4213
4214 err = __orinoco_program_rids(dev);
4215 if (err) {
4216 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4217 dev->name);
4218 goto out;
4219 }
4220
4221 err = hermes_enable_port(hw, 0);
4222 if (err) {
4223 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4224 dev->name);
4225 goto out;
4226 }
4227
4228 out:
4229 if (err) {
4230 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4231 schedule_work(&priv->reset_work);
4232 err = 0;
4233 }
4234
4235 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 return err;
4237}
4238
Christoph Hellwig620554e2005-06-19 01:27:33 +02004239static const struct iw_priv_args orinoco_privtab[] = {
4240 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4241 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4242 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4243 0, "set_port3" },
4244 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4245 "get_port3" },
4246 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4247 0, "set_preamble" },
4248 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4249 "get_preamble" },
4250 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4251 0, "set_ibssport" },
4252 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4253 "get_ibssport" },
4254 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4255 "get_rid" },
4256};
4257
4258
4259/*
4260 * Structures to export the Wireless Handlers
4261 */
4262
4263static const iw_handler orinoco_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004264 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4265 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4266 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4267 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4268 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4269 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4270 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4271 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4272 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
Pavel Roskin343c6862005-09-09 18:43:02 -04004273 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4274 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4275 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4276 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004277 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4278 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4279 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4280 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4281 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4282 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4283 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4284 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4285 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4286 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4287 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4288 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4289 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4290 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4291 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4292 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4293 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4294 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4295 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004296};
4297
4298
4299/*
4300 Added typecasting since we no longer use iwreq_data -- Moustafa
4301 */
4302static const iw_handler orinoco_private_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004303 [0] = (iw_handler) orinoco_ioctl_reset,
4304 [1] = (iw_handler) orinoco_ioctl_reset,
4305 [2] = (iw_handler) orinoco_ioctl_setport3,
4306 [3] = (iw_handler) orinoco_ioctl_getport3,
4307 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4308 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4309 [6] = (iw_handler) orinoco_ioctl_setibssport,
4310 [7] = (iw_handler) orinoco_ioctl_getibssport,
4311 [9] = (iw_handler) orinoco_ioctl_getrid,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004312};
4313
4314static const struct iw_handler_def orinoco_handler_def = {
4315 .num_standard = ARRAY_SIZE(orinoco_handler),
4316 .num_private = ARRAY_SIZE(orinoco_private_handler),
4317 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4318 .standard = orinoco_handler,
4319 .private = orinoco_private_handler,
4320 .private_args = orinoco_privtab,
Pavel Roskin343c6862005-09-09 18:43:02 -04004321 .get_wireless_stats = orinoco_get_wireless_stats,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004322};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004324static void orinoco_get_drvinfo(struct net_device *dev,
4325 struct ethtool_drvinfo *info)
4326{
4327 struct orinoco_private *priv = netdev_priv(dev);
4328
4329 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4330 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4331 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4332 if (dev->class_dev.dev)
4333 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4334 sizeof(info->bus_info) - 1);
4335 else
4336 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4337 "PCMCIA %p", priv->hw.iobase);
4338}
4339
4340static struct ethtool_ops orinoco_ethtool_ops = {
4341 .get_drvinfo = orinoco_get_drvinfo,
4342 .get_link = ethtool_op_get_link,
4343};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344
4345/********************************************************************/
4346/* Debugging */
4347/********************************************************************/
4348
4349#if 0
4350static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4351{
4352 printk(KERN_DEBUG "RX descriptor:\n");
4353 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4354 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4355 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4356 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4357 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4358 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4359 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4360
4361 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4362 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4363 frame->p80211.frame_ctl);
4364 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4365 frame->p80211.duration_id);
4366 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4367 frame->p80211.addr1[0], frame->p80211.addr1[1],
4368 frame->p80211.addr1[2], frame->p80211.addr1[3],
4369 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4370 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4371 frame->p80211.addr2[0], frame->p80211.addr2[1],
4372 frame->p80211.addr2[2], frame->p80211.addr2[3],
4373 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4374 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4375 frame->p80211.addr3[0], frame->p80211.addr3[1],
4376 frame->p80211.addr3[2], frame->p80211.addr3[3],
4377 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4378 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4379 frame->p80211.seq_ctl);
4380 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4381 frame->p80211.addr4[0], frame->p80211.addr4[1],
4382 frame->p80211.addr4[2], frame->p80211.addr4[3],
4383 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4384 printk(KERN_DEBUG " data_len = 0x%04x\n",
4385 frame->p80211.data_len);
4386
4387 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4388 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4389 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4390 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4391 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4392 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4393 frame->p8023.h_source[0], frame->p8023.h_source[1],
4394 frame->p8023.h_source[2], frame->p8023.h_source[3],
4395 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4396 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4397
4398 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4399 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4400 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4401 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4402 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4403 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4404 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4405}
4406#endif /* 0 */
4407
4408/********************************************************************/
4409/* Module initialization */
4410/********************************************************************/
4411
4412EXPORT_SYMBOL(alloc_orinocodev);
4413EXPORT_SYMBOL(free_orinocodev);
4414
4415EXPORT_SYMBOL(__orinoco_up);
4416EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417EXPORT_SYMBOL(orinoco_reinit_firmware);
4418
4419EXPORT_SYMBOL(orinoco_interrupt);
4420
4421/* Can't be declared "const" or the whole __initdata section will
4422 * become const */
4423static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4424 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4425 "Pavel Roskin <proski@gnu.org>, et al)";
4426
4427static int __init init_orinoco(void)
4428{
4429 printk(KERN_DEBUG "%s\n", version);
4430 return 0;
4431}
4432
4433static void __exit exit_orinoco(void)
4434{
4435}
4436
4437module_init(init_orinoco);
4438module_exit(exit_orinoco);