blob: 5db2bbad65c42986b0a1dcf41dd4402a8229999a [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
Pavel Roskin9bc39be2005-10-04 21:33:10 -0400493 /* Check packet length, pad short packets, round up odd length */
494 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);
John W. Linville36841c92005-10-18 21:30:58 -0400495 skb = skb_padto(skb, len);
496 if (skb == NULL)
497 goto fail;
Pavel Roskin9bc39be2005-10-04 21:33:10 -0400498 len -= ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 eh = (struct ethhdr *)skb->data;
501
502 memset(&desc, 0, sizeof(desc));
503 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
504 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
505 if (err) {
506 if (net_ratelimit())
507 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
508 "to BAP\n", dev->name, err);
509 stats->tx_errors++;
510 goto fail;
511 }
512
513 /* Clear the 802.11 header and data length fields - some
514 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
515 * if this isn't done. */
516 hermes_clear_words(hw, HERMES_DATA0,
517 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
518
519 /* Encapsulate Ethernet-II frames */
520 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
521 struct header_struct hdr;
522 data_len = len;
523 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
524 p = skb->data + ETH_HLEN;
525
526 /* 802.3 header */
527 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
528 memcpy(hdr.src, eh->h_source, ETH_ALEN);
529 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
530
531 /* 802.2 header */
532 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
533
534 hdr.ethertype = eh->h_proto;
535 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
536 txfid, HERMES_802_3_OFFSET);
537 if (err) {
538 if (net_ratelimit())
539 printk(KERN_ERR "%s: Error %d writing packet "
540 "header to BAP\n", dev->name, err);
541 stats->tx_errors++;
542 goto fail;
543 }
544 } else { /* IEEE 802.3 frame */
545 data_len = len + ETH_HLEN;
546 data_off = HERMES_802_3_OFFSET;
547 p = skb->data;
548 }
549
Pavel Roskin9bc39be2005-10-04 21:33:10 -0400550 err = hermes_bap_pwrite(hw, USER_BAP, p, data_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 txfid, data_off);
552 if (err) {
553 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
554 dev->name, err);
555 stats->tx_errors++;
556 goto fail;
557 }
558
559 /* Finally, we actually initiate the send */
560 netif_stop_queue(dev);
561
562 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
563 txfid, NULL);
564 if (err) {
565 netif_start_queue(dev);
566 printk(KERN_ERR "%s: Error %d transmitting packet\n",
567 dev->name, err);
568 stats->tx_errors++;
569 goto fail;
570 }
571
572 dev->trans_start = jiffies;
573 stats->tx_bytes += data_off + data_len;
574
575 orinoco_unlock(priv, &flags);
576
577 dev_kfree_skb(skb);
578
579 TRACE_EXIT(dev->name);
580
581 return 0;
582 fail:
583 TRACE_EXIT(dev->name);
584
585 orinoco_unlock(priv, &flags);
586 return err;
587}
588
589static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
590{
591 struct orinoco_private *priv = netdev_priv(dev);
592 u16 fid = hermes_read_regn(hw, ALLOCFID);
593
594 if (fid != priv->txfid) {
595 if (fid != DUMMY_FID)
596 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
597 dev->name, fid);
598 return;
599 }
600
601 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
602}
603
604static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
605{
606 struct orinoco_private *priv = netdev_priv(dev);
607 struct net_device_stats *stats = &priv->stats;
608
609 stats->tx_packets++;
610
611 netif_wake_queue(dev);
612
613 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
614}
615
616static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
617{
618 struct orinoco_private *priv = netdev_priv(dev);
619 struct net_device_stats *stats = &priv->stats;
620 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -0400621 u16 status;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200622 struct hermes_tx_descriptor_802_11 hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 int err = 0;
624
625 if (fid == DUMMY_FID)
626 return; /* Nothing's really happened */
627
Pavel Roskin48ca7032005-09-23 04:18:06 -0400628 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200629 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin48ca7032005-09-23 04:18:06 -0400630 offsetof(struct hermes_tx_descriptor_802_11,
631 addr2),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200632 fid, 0);
633
634 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
635 stats->tx_errors++;
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (err) {
638 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
639 "(FID=%04X error %d)\n",
640 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200641 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200644 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
645 err, fid);
646
647 /* We produce a TXDROP event only for retry or lifetime
648 * exceeded, because that's the only status that really mean
649 * that this particular node went away.
650 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskind133ae42005-09-23 04:18:06 -0400651 status = le16_to_cpu(hdr.status);
652 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200653 union iwreq_data wrqu;
654
655 /* Copy 802.11 dest address.
656 * We use the 802.11 header because the frame may
657 * not be 802.3 or may be mangled...
658 * In Ad-Hoc mode, it will be the node address.
659 * In managed mode, it will be most likely the AP addr
660 * User space will figure out how to convert it to
661 * whatever it needs (IP address or else).
662 * - Jean II */
663 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
664 wrqu.addr.sa_family = ARPHRD_ETHER;
665
666 /* Send event to user space */
667 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
673static void orinoco_tx_timeout(struct net_device *dev)
674{
675 struct orinoco_private *priv = netdev_priv(dev);
676 struct net_device_stats *stats = &priv->stats;
677 struct hermes *hw = &priv->hw;
678
679 printk(KERN_WARNING "%s: Tx timeout! "
680 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
681 dev->name, hermes_read_regn(hw, ALLOCFID),
682 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
683
684 stats->tx_errors++;
685
686 schedule_work(&priv->reset_work);
687}
688
689/********************************************************************/
690/* Rx path (data frames) */
691/********************************************************************/
692
693/* Does the frame have a SNAP header indicating it should be
694 * de-encapsulated to Ethernet-II? */
695static inline int is_ethersnap(void *_hdr)
696{
697 u8 *hdr = _hdr;
698
699 /* We de-encapsulate all packets which, a) have SNAP headers
700 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
701 * and where b) the OUI of the SNAP header is 00:00:00 or
702 * 00:00:f8 - we need both because different APs appear to use
703 * different OUIs for some reason */
704 return (memcmp(hdr, &encaps_hdr, 5) == 0)
705 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
706}
707
708static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
709 int level, int noise)
710{
Pavel Roskin343c6862005-09-09 18:43:02 -0400711 struct iw_quality wstats;
712 wstats.level = level - 0x95;
713 wstats.noise = noise - 0x95;
714 wstats.qual = (level > noise) ? (level - noise) : 0;
715 wstats.updated = 7;
716 /* Update spy records */
717 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718}
719
720static void orinoco_stat_gather(struct net_device *dev,
721 struct sk_buff *skb,
722 struct hermes_rx_descriptor *desc)
723{
724 struct orinoco_private *priv = netdev_priv(dev);
725
726 /* Using spy support with lots of Rx packets, like in an
727 * infrastructure (AP), will really slow down everything, because
728 * the MAC address must be compared to each entry of the spy list.
729 * If the user really asks for it (set some address in the
730 * spy list), we do it, but he will pay the price.
731 * Note that to get here, you need both WIRELESS_SPY
732 * compiled in AND some addresses in the list !!!
733 */
734 /* Note : gcc will optimise the whole section away if
735 * WIRELESS_SPY is not defined... - Jean II */
736 if (SPY_NUMBER(priv)) {
737 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
738 desc->signal, desc->silence);
739 }
740}
741
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200742/*
743 * orinoco_rx_monitor - handle received monitor frames.
744 *
745 * Arguments:
746 * dev network device
747 * rxfid received FID
748 * desc rx descriptor of the frame
749 *
750 * Call context: interrupt
751 */
752static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
753 struct hermes_rx_descriptor *desc)
754{
755 u32 hdrlen = 30; /* return full header by default */
756 u32 datalen = 0;
757 u16 fc;
758 int err;
759 int len;
760 struct sk_buff *skb;
761 struct orinoco_private *priv = netdev_priv(dev);
762 struct net_device_stats *stats = &priv->stats;
763 hermes_t *hw = &priv->hw;
764
765 len = le16_to_cpu(desc->data_len);
766
767 /* Determine the size of the header and the data */
768 fc = le16_to_cpu(desc->frame_ctl);
769 switch (fc & IEEE80211_FCTL_FTYPE) {
770 case IEEE80211_FTYPE_DATA:
771 if ((fc & IEEE80211_FCTL_TODS)
772 && (fc & IEEE80211_FCTL_FROMDS))
773 hdrlen = 30;
774 else
775 hdrlen = 24;
776 datalen = len;
777 break;
778 case IEEE80211_FTYPE_MGMT:
779 hdrlen = 24;
780 datalen = len;
781 break;
782 case IEEE80211_FTYPE_CTL:
783 switch (fc & IEEE80211_FCTL_STYPE) {
784 case IEEE80211_STYPE_PSPOLL:
785 case IEEE80211_STYPE_RTS:
786 case IEEE80211_STYPE_CFEND:
787 case IEEE80211_STYPE_CFENDACK:
788 hdrlen = 16;
789 break;
790 case IEEE80211_STYPE_CTS:
791 case IEEE80211_STYPE_ACK:
792 hdrlen = 10;
793 break;
794 }
795 break;
796 default:
797 /* Unknown frame type */
798 break;
799 }
800
801 /* sanity check the length */
802 if (datalen > IEEE80211_DATA_LEN + 12) {
803 printk(KERN_DEBUG "%s: oversized monitor frame, "
804 "data length = %d\n", dev->name, datalen);
805 err = -EIO;
806 stats->rx_length_errors++;
807 goto update_stats;
808 }
809
810 skb = dev_alloc_skb(hdrlen + datalen);
811 if (!skb) {
812 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
813 dev->name);
814 err = -ENOMEM;
815 goto drop;
816 }
817
818 /* Copy the 802.11 header to the skb */
819 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
820 skb->mac.raw = skb->data;
821
822 /* If any, copy the data from the card to the skb */
823 if (datalen > 0) {
824 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
825 ALIGN(datalen, 2), rxfid,
826 HERMES_802_2_OFFSET);
827 if (err) {
828 printk(KERN_ERR "%s: error %d reading monitor frame\n",
829 dev->name, err);
830 goto drop;
831 }
832 }
833
834 skb->dev = dev;
835 skb->ip_summed = CHECKSUM_NONE;
836 skb->pkt_type = PACKET_OTHERHOST;
837 skb->protocol = __constant_htons(ETH_P_802_2);
838
839 dev->last_rx = jiffies;
840 stats->rx_packets++;
841 stats->rx_bytes += skb->len;
842
843 netif_rx(skb);
844 return;
845
846 drop:
847 dev_kfree_skb_irq(skb);
848 update_stats:
849 stats->rx_errors++;
850 stats->rx_dropped++;
851}
852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
854{
855 struct orinoco_private *priv = netdev_priv(dev);
856 struct net_device_stats *stats = &priv->stats;
857 struct iw_statistics *wstats = &priv->wstats;
858 struct sk_buff *skb = NULL;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200859 u16 rxfid, status, fc;
860 int length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 struct hermes_rx_descriptor desc;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200862 struct ethhdr *hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 int err;
864
865 rxfid = hermes_read_regn(hw, RXFID);
866
867 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
868 rxfid, 0);
869 if (err) {
870 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
871 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200872 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
874
875 status = le16_to_cpu(desc.status);
876
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200877 if (status & HERMES_RXSTAT_BADCRC) {
878 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
879 dev->name);
880 stats->rx_crc_errors++;
881 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
883
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200884 /* Handle frames in monitor mode */
885 if (priv->iw_mode == IW_MODE_MONITOR) {
886 orinoco_rx_monitor(dev, rxfid, &desc);
887 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 }
889
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200890 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
891 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
892 dev->name);
893 wstats->discard.code++;
894 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 }
896
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200897 length = le16_to_cpu(desc.data_len);
898 fc = le16_to_cpu(desc.frame_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 /* Sanity checks */
901 if (length < 3) { /* No for even an 802.2 LLC header */
902 /* At least on Symbol firmware with PCF we get quite a
903 lot of these legitimately - Poll frames with no
904 data. */
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200905 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400907 if (length > IEEE80211_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
909 dev->name, length);
910 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200911 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 }
913
914 /* We need space for the packet data itself, plus an ethernet
915 header, plus 2 bytes so we can align the IP header on a
916 32bit boundary, plus 1 byte so we can read in odd length
917 packets from the card, which has an IO granularity of 16
918 bits */
919 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
920 if (!skb) {
921 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
922 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200923 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200926 /* We'll prepend the header, so reserve space for it. The worst
927 case is no decapsulation, when 802.3 header is prepended and
928 nothing is removed. 2 is for aligning the IP header. */
929 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200931 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
932 ALIGN(length, 2), rxfid,
933 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 if (err) {
935 printk(KERN_ERR "%s: error %d reading frame. "
936 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 goto drop;
938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 /* Handle decapsulation
941 * In most cases, the firmware tell us about SNAP frames.
942 * For some reason, the SNAP frames sent by LinkSys APs
943 * are not properly recognised by most firmwares.
944 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200945 if (length >= ENCAPS_OVERHEAD &&
946 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
947 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
948 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 /* These indicate a SNAP within 802.2 LLC within
950 802.11 frame which we'll need to de-encapsulate to
951 the original EthernetII frame. */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200952 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200954 /* 802.3 frame - prepend 802.3 header as is */
955 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
956 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200958 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
959 if (fc & IEEE80211_FCTL_FROMDS)
960 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
961 else
962 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 dev->last_rx = jiffies;
965 skb->dev = dev;
966 skb->protocol = eth_type_trans(skb, dev);
967 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200968 if (fc & IEEE80211_FCTL_TODS)
969 skb->pkt_type = PACKET_OTHERHOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 /* Process the wireless stats if needed */
972 orinoco_stat_gather(dev, skb, &desc);
973
974 /* Pass the packet to the networking stack */
975 netif_rx(skb);
976 stats->rx_packets++;
977 stats->rx_bytes += length;
978
979 return;
980
981 drop:
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200982 dev_kfree_skb_irq(skb);
983 update_stats:
984 stats->rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 stats->rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
988/********************************************************************/
989/* Rx path (info frames) */
990/********************************************************************/
991
992static void print_linkstatus(struct net_device *dev, u16 status)
993{
994 char * s;
995
996 if (suppress_linkstatus)
997 return;
998
999 switch (status) {
1000 case HERMES_LINKSTATUS_NOT_CONNECTED:
1001 s = "Not Connected";
1002 break;
1003 case HERMES_LINKSTATUS_CONNECTED:
1004 s = "Connected";
1005 break;
1006 case HERMES_LINKSTATUS_DISCONNECTED:
1007 s = "Disconnected";
1008 break;
1009 case HERMES_LINKSTATUS_AP_CHANGE:
1010 s = "AP Changed";
1011 break;
1012 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1013 s = "AP Out of Range";
1014 break;
1015 case HERMES_LINKSTATUS_AP_IN_RANGE:
1016 s = "AP In Range";
1017 break;
1018 case HERMES_LINKSTATUS_ASSOC_FAILED:
1019 s = "Association Failed";
1020 break;
1021 default:
1022 s = "UNKNOWN";
1023 }
1024
1025 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1026 dev->name, s, status);
1027}
1028
Christoph Hellwig16739b02005-06-19 01:27:51 +02001029/* Search scan results for requested BSSID, join it if found */
1030static void orinoco_join_ap(struct net_device *dev)
1031{
1032 struct orinoco_private *priv = netdev_priv(dev);
1033 struct hermes *hw = &priv->hw;
1034 int err;
1035 unsigned long flags;
1036 struct join_req {
1037 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001038 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001039 } __attribute__ ((packed)) req;
1040 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001041 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001042 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001043 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001044 u8 *buf;
1045 u16 len;
1046
1047 /* Allocate buffer for scan results */
1048 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1049 if (! buf)
1050 return;
1051
1052 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001053 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001054
1055 /* Sanity checks in case user changed something in the meantime */
1056 if (! priv->bssid_fixed)
1057 goto out;
1058
1059 if (strlen(priv->desired_essid) == 0)
1060 goto out;
1061
1062 /* Read scan results from the firmware */
1063 err = hermes_read_ltv(hw, USER_BAP,
1064 HERMES_RID_SCANRESULTSTABLE,
1065 MAX_SCAN_LEN, &len, buf);
1066 if (err) {
1067 printk(KERN_ERR "%s: Cannot read scan results\n",
1068 dev->name);
1069 goto out;
1070 }
1071
1072 len = HERMES_RECLEN_TO_BYTES(len);
1073
1074 /* Go through the scan results looking for the channel of the AP
1075 * we were requested to join */
1076 for (; offset + atom_len <= len; offset += atom_len) {
1077 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001078 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1079 found = 1;
1080 break;
1081 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001082 }
1083
Pavel Roskinc89cc222005-09-01 20:06:06 -04001084 if (! found) {
1085 DEBUG(1, "%s: Requested AP not found in scan results\n",
1086 dev->name);
1087 goto out;
1088 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001089
Christoph Hellwig16739b02005-06-19 01:27:51 +02001090 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1091 req.channel = atom->channel; /* both are little-endian */
1092 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1093 &req);
1094 if (err)
1095 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1096
1097 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001098 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001099
1100 fail_lock:
1101 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001102}
1103
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001104/* Send new BSSID to userspace */
1105static void orinoco_send_wevents(struct net_device *dev)
1106{
1107 struct orinoco_private *priv = netdev_priv(dev);
1108 struct hermes *hw = &priv->hw;
1109 union iwreq_data wrqu;
1110 int err;
1111 unsigned long flags;
1112
1113 if (orinoco_lock(priv, &flags) != 0)
1114 return;
1115
1116 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1117 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1118 if (err != 0)
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001119 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001120
1121 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1122
1123 /* Send event to user space */
1124 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001125
1126 out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001127 orinoco_unlock(priv, &flags);
1128}
1129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1131{
1132 struct orinoco_private *priv = netdev_priv(dev);
1133 u16 infofid;
1134 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001135 __le16 len;
1136 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 } __attribute__ ((packed)) info;
1138 int len, type;
1139 int err;
1140
1141 /* This is an answer to an INQUIRE command that we did earlier,
1142 * or an information "event" generated by the card
1143 * The controller return to us a pseudo frame containing
1144 * the information in question - Jean II */
1145 infofid = hermes_read_regn(hw, INFOFID);
1146
1147 /* Read the info frame header - don't try too hard */
1148 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1149 infofid, 0);
1150 if (err) {
1151 printk(KERN_ERR "%s: error %d reading info frame. "
1152 "Frame dropped.\n", dev->name, err);
1153 return;
1154 }
1155
1156 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1157 type = le16_to_cpu(info.type);
1158
1159 switch (type) {
1160 case HERMES_INQ_TALLIES: {
1161 struct hermes_tallies_frame tallies;
1162 struct iw_statistics *wstats = &priv->wstats;
1163
1164 if (len > sizeof(tallies)) {
1165 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1166 dev->name, len);
1167 len = sizeof(tallies);
1168 }
1169
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001170 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1171 infofid, sizeof(info));
1172 if (err)
1173 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
1175 /* Increment our various counters */
1176 /* wstats->discard.nwid - no wrong BSSID stuff */
1177 wstats->discard.code +=
1178 le16_to_cpu(tallies.RxWEPUndecryptable);
1179 if (len == sizeof(tallies))
1180 wstats->discard.code +=
1181 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1182 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1183 wstats->discard.misc +=
1184 le16_to_cpu(tallies.TxDiscardsWrongSA);
1185 wstats->discard.fragment +=
1186 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1187 wstats->discard.retries +=
1188 le16_to_cpu(tallies.TxRetryLimitExceeded);
1189 /* wstats->miss.beacon - no match */
1190 }
1191 break;
1192 case HERMES_INQ_LINKSTATUS: {
1193 struct hermes_linkstatus linkstatus;
1194 u16 newstatus;
1195 int connected;
1196
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001197 if (priv->iw_mode == IW_MODE_MONITOR)
1198 break;
1199
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 if (len != sizeof(linkstatus)) {
1201 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1202 dev->name, len);
1203 break;
1204 }
1205
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001206 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1207 infofid, sizeof(info));
1208 if (err)
1209 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 newstatus = le16_to_cpu(linkstatus.linkstatus);
1211
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001212 /* Symbol firmware uses "out of range" to signal that
1213 * the hostscan frame can be requested. */
1214 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1215 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1216 priv->has_hostscan && priv->scan_inprogress) {
1217 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1218 break;
1219 }
1220
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1222 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1223 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1224
1225 if (connected)
1226 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001227 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 netif_carrier_off(dev);
1229
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001230 if (newstatus != priv->last_linkstatus) {
1231 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001233 /* The info frame contains only one word which is the
1234 * status (see hermes.h). The status is pretty boring
1235 * in itself, that's why we export the new BSSID...
1236 * Jean II */
1237 schedule_work(&priv->wevent_work);
1238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 }
1240 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001241 case HERMES_INQ_SCAN:
1242 if (!priv->scan_inprogress && priv->bssid_fixed &&
1243 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1244 schedule_work(&priv->join_work);
1245 break;
1246 }
1247 /* fall through */
1248 case HERMES_INQ_HOSTSCAN:
1249 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1250 /* Result of a scanning. Contains information about
1251 * cells in the vicinity - Jean II */
1252 union iwreq_data wrqu;
1253 unsigned char *buf;
1254
1255 /* Sanity check */
1256 if (len > 4096) {
1257 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1258 dev->name, len);
1259 break;
1260 }
1261
1262 /* We are a strict producer. If the previous scan results
1263 * have not been consumed, we just have to drop this
1264 * frame. We can't remove the previous results ourselves,
1265 * that would be *very* racy... Jean II */
1266 if (priv->scan_result != NULL) {
1267 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1268 break;
1269 }
1270
1271 /* Allocate buffer for results */
1272 buf = kmalloc(len, GFP_ATOMIC);
1273 if (buf == NULL)
1274 /* No memory, so can't printk()... */
1275 break;
1276
1277 /* Read scan data */
1278 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1279 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001280 if (err) {
1281 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001282 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001283 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001284
1285#ifdef ORINOCO_DEBUG
1286 {
1287 int i;
1288 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1289 for(i = 1; i < (len * 2); i++)
1290 printk(":%02X", buf[i]);
1291 printk("]\n");
1292 }
1293#endif /* ORINOCO_DEBUG */
1294
1295 /* Allow the clients to access the results */
1296 priv->scan_len = len;
1297 priv->scan_result = buf;
1298
1299 /* Send an empty event to user space.
1300 * We don't send the received data on the event because
1301 * it would require us to do complex transcoding, and
1302 * we want to minimise the work done in the irq handler
1303 * Use a request to extract the data - Jean II */
1304 wrqu.data.length = 0;
1305 wrqu.data.flags = 0;
1306 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1307 }
1308 break;
1309 case HERMES_INQ_SEC_STAT_AGERE:
1310 /* Security status (Agere specific) */
1311 /* Ignore this frame for now */
1312 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1313 break;
1314 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 default:
1316 printk(KERN_DEBUG "%s: Unknown information frame received: "
1317 "type 0x%04x, length %d\n", dev->name, type, len);
1318 /* We don't actually do anything about it */
1319 break;
1320 }
1321}
1322
1323static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1324{
1325 if (net_ratelimit())
1326 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1327}
1328
1329/********************************************************************/
1330/* Internal hardware control routines */
1331/********************************************************************/
1332
1333int __orinoco_up(struct net_device *dev)
1334{
1335 struct orinoco_private *priv = netdev_priv(dev);
1336 struct hermes *hw = &priv->hw;
1337 int err;
1338
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001339 netif_carrier_off(dev); /* just to make sure */
1340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 err = __orinoco_program_rids(dev);
1342 if (err) {
1343 printk(KERN_ERR "%s: Error %d configuring card\n",
1344 dev->name, err);
1345 return err;
1346 }
1347
1348 /* Fire things up again */
1349 hermes_set_irqmask(hw, ORINOCO_INTEN);
1350 err = hermes_enable_port(hw, 0);
1351 if (err) {
1352 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1353 dev->name, err);
1354 return err;
1355 }
1356
1357 netif_start_queue(dev);
1358
1359 return 0;
1360}
1361
1362int __orinoco_down(struct net_device *dev)
1363{
1364 struct orinoco_private *priv = netdev_priv(dev);
1365 struct hermes *hw = &priv->hw;
1366 int err;
1367
1368 netif_stop_queue(dev);
1369
1370 if (! priv->hw_unavailable) {
1371 if (! priv->broken_disableport) {
1372 err = hermes_disable_port(hw, 0);
1373 if (err) {
1374 /* Some firmwares (e.g. Intersil 1.3.x) seem
1375 * to have problems disabling the port, oh
1376 * well, too bad. */
1377 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1378 dev->name, err);
1379 priv->broken_disableport = 1;
1380 }
1381 }
1382 hermes_set_irqmask(hw, 0);
1383 hermes_write_regn(hw, EVACK, 0xffff);
1384 }
1385
1386 /* firmware will have to reassociate */
1387 netif_carrier_off(dev);
1388 priv->last_linkstatus = 0xffff;
1389
1390 return 0;
1391}
1392
1393int orinoco_reinit_firmware(struct net_device *dev)
1394{
1395 struct orinoco_private *priv = netdev_priv(dev);
1396 struct hermes *hw = &priv->hw;
1397 int err;
1398
1399 err = hermes_init(hw);
1400 if (err)
1401 return err;
1402
1403 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04001404 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 /* Try workaround for old Symbol firmware bug */
1406 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1407 "(old Symbol firmware?). Trying to work around... ",
1408 dev->name);
1409
1410 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1411 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1412 if (err)
1413 printk("failed!\n");
1414 else
1415 printk("ok.\n");
1416 }
1417
1418 return err;
1419}
1420
1421static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1422{
1423 hermes_t *hw = &priv->hw;
1424 int err = 0;
1425
1426 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1427 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1428 priv->ndev->name, priv->bitratemode);
1429 return -EINVAL;
1430 }
1431
1432 switch (priv->firmware_type) {
1433 case FIRMWARE_TYPE_AGERE:
1434 err = hermes_write_wordrec(hw, USER_BAP,
1435 HERMES_RID_CNFTXRATECONTROL,
1436 bitrate_table[priv->bitratemode].agere_txratectrl);
1437 break;
1438 case FIRMWARE_TYPE_INTERSIL:
1439 case FIRMWARE_TYPE_SYMBOL:
1440 err = hermes_write_wordrec(hw, USER_BAP,
1441 HERMES_RID_CNFTXRATECONTROL,
1442 bitrate_table[priv->bitratemode].intersil_txratectrl);
1443 break;
1444 default:
1445 BUG();
1446 }
1447
1448 return err;
1449}
1450
Christoph Hellwig16739b02005-06-19 01:27:51 +02001451/* Set fixed AP address */
1452static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1453{
1454 int roaming_flag;
1455 int err = 0;
1456 hermes_t *hw = &priv->hw;
1457
1458 switch (priv->firmware_type) {
1459 case FIRMWARE_TYPE_AGERE:
1460 /* not supported */
1461 break;
1462 case FIRMWARE_TYPE_INTERSIL:
1463 if (priv->bssid_fixed)
1464 roaming_flag = 2;
1465 else
1466 roaming_flag = 1;
1467
1468 err = hermes_write_wordrec(hw, USER_BAP,
1469 HERMES_RID_CNFROAMINGMODE,
1470 roaming_flag);
1471 break;
1472 case FIRMWARE_TYPE_SYMBOL:
1473 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1474 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1475 &priv->desired_bssid);
1476 break;
1477 }
1478 return err;
1479}
1480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481/* Change the WEP keys and/or the current keys. Can be called
1482 * either from __orinoco_hw_setup_wep() or directly from
1483 * orinoco_ioctl_setiwencode(). In the later case the association
1484 * with the AP is not broken (if the firmware can handle it),
1485 * which is needed for 802.1x implementations. */
1486static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1487{
1488 hermes_t *hw = &priv->hw;
1489 int err = 0;
1490
1491 switch (priv->firmware_type) {
1492 case FIRMWARE_TYPE_AGERE:
1493 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1494 HERMES_RID_CNFWEPKEYS_AGERE,
1495 &priv->keys);
1496 if (err)
1497 return err;
1498 err = hermes_write_wordrec(hw, USER_BAP,
1499 HERMES_RID_CNFTXKEY_AGERE,
1500 priv->tx_key);
1501 if (err)
1502 return err;
1503 break;
1504 case FIRMWARE_TYPE_INTERSIL:
1505 case FIRMWARE_TYPE_SYMBOL:
1506 {
1507 int keylen;
1508 int i;
1509
1510 /* Force uniform key length to work around firmware bugs */
1511 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1512
1513 if (keylen > LARGE_KEY_SIZE) {
1514 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1515 priv->ndev->name, priv->tx_key, keylen);
1516 return -E2BIG;
1517 }
1518
1519 /* Write all 4 keys */
1520 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1521 err = hermes_write_ltv(hw, USER_BAP,
1522 HERMES_RID_CNFDEFAULTKEY0 + i,
1523 HERMES_BYTES_TO_RECLEN(keylen),
1524 priv->keys[i].data);
1525 if (err)
1526 return err;
1527 }
1528
1529 /* Write the index of the key used in transmission */
1530 err = hermes_write_wordrec(hw, USER_BAP,
1531 HERMES_RID_CNFWEPDEFAULTKEYID,
1532 priv->tx_key);
1533 if (err)
1534 return err;
1535 }
1536 break;
1537 }
1538
1539 return 0;
1540}
1541
1542static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1543{
1544 hermes_t *hw = &priv->hw;
1545 int err = 0;
1546 int master_wep_flag;
1547 int auth_flag;
1548
1549 if (priv->wep_on)
1550 __orinoco_hw_setup_wepkeys(priv);
1551
1552 if (priv->wep_restrict)
1553 auth_flag = HERMES_AUTH_SHARED_KEY;
1554 else
1555 auth_flag = HERMES_AUTH_OPEN;
1556
1557 switch (priv->firmware_type) {
1558 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1559 if (priv->wep_on) {
1560 /* Enable the shared-key authentication. */
1561 err = hermes_write_wordrec(hw, USER_BAP,
1562 HERMES_RID_CNFAUTHENTICATION_AGERE,
1563 auth_flag);
1564 }
1565 err = hermes_write_wordrec(hw, USER_BAP,
1566 HERMES_RID_CNFWEPENABLED_AGERE,
1567 priv->wep_on);
1568 if (err)
1569 return err;
1570 break;
1571
1572 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1573 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1574 if (priv->wep_on) {
1575 if (priv->wep_restrict ||
1576 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1577 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1578 HERMES_WEP_EXCL_UNENCRYPTED;
1579 else
1580 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1581
1582 err = hermes_write_wordrec(hw, USER_BAP,
1583 HERMES_RID_CNFAUTHENTICATION,
1584 auth_flag);
1585 if (err)
1586 return err;
1587 } else
1588 master_wep_flag = 0;
1589
1590 if (priv->iw_mode == IW_MODE_MONITOR)
1591 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1592
1593 /* Master WEP setting : on/off */
1594 err = hermes_write_wordrec(hw, USER_BAP,
1595 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1596 master_wep_flag);
1597 if (err)
1598 return err;
1599
1600 break;
1601 }
1602
1603 return 0;
1604}
1605
1606static int __orinoco_program_rids(struct net_device *dev)
1607{
1608 struct orinoco_private *priv = netdev_priv(dev);
1609 hermes_t *hw = &priv->hw;
1610 int err;
1611 struct hermes_idstring idbuf;
1612
1613 /* Set the MAC address */
1614 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1615 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1616 if (err) {
1617 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1618 dev->name, err);
1619 return err;
1620 }
1621
1622 /* Set up the link mode */
1623 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1624 priv->port_type);
1625 if (err) {
1626 printk(KERN_ERR "%s: Error %d setting port type\n",
1627 dev->name, err);
1628 return err;
1629 }
1630 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04001631 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1632 err = hermes_write_wordrec(hw, USER_BAP,
1633 HERMES_RID_CNFOWNCHANNEL,
1634 priv->channel);
1635 if (err) {
1636 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1637 dev->name, err, priv->channel);
1638 return err;
1639 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 }
1641
1642 if (priv->has_ibss) {
1643 u16 createibss;
1644
1645 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1646 printk(KERN_WARNING "%s: This firmware requires an "
1647 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1648 /* With wvlan_cs, in this case, we would crash.
1649 * hopefully, this driver will behave better...
1650 * Jean II */
1651 createibss = 0;
1652 } else {
1653 createibss = priv->createibss;
1654 }
1655
1656 err = hermes_write_wordrec(hw, USER_BAP,
1657 HERMES_RID_CNFCREATEIBSS,
1658 createibss);
1659 if (err) {
1660 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1661 dev->name, err);
1662 return err;
1663 }
1664 }
1665
Christoph Hellwig16739b02005-06-19 01:27:51 +02001666 /* Set the desired BSSID */
1667 err = __orinoco_hw_set_wap(priv);
1668 if (err) {
1669 printk(KERN_ERR "%s: Error %d setting AP address\n",
1670 dev->name, err);
1671 return err;
1672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 /* Set the desired ESSID */
1674 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1675 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1676 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1677 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1678 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1679 &idbuf);
1680 if (err) {
1681 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1682 dev->name, err);
1683 return err;
1684 }
1685 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1686 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1687 &idbuf);
1688 if (err) {
1689 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1690 dev->name, err);
1691 return err;
1692 }
1693
1694 /* Set the station name */
1695 idbuf.len = cpu_to_le16(strlen(priv->nick));
1696 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1697 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1698 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1699 &idbuf);
1700 if (err) {
1701 printk(KERN_ERR "%s: Error %d setting nickname\n",
1702 dev->name, err);
1703 return err;
1704 }
1705
1706 /* Set AP density */
1707 if (priv->has_sensitivity) {
1708 err = hermes_write_wordrec(hw, USER_BAP,
1709 HERMES_RID_CNFSYSTEMSCALE,
1710 priv->ap_density);
1711 if (err) {
1712 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1713 "Disabling sensitivity control\n",
1714 dev->name, err);
1715
1716 priv->has_sensitivity = 0;
1717 }
1718 }
1719
1720 /* Set RTS threshold */
1721 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1722 priv->rts_thresh);
1723 if (err) {
1724 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1725 dev->name, err);
1726 return err;
1727 }
1728
1729 /* Set fragmentation threshold or MWO robustness */
1730 if (priv->has_mwo)
1731 err = hermes_write_wordrec(hw, USER_BAP,
1732 HERMES_RID_CNFMWOROBUST_AGERE,
1733 priv->mwo_robust);
1734 else
1735 err = hermes_write_wordrec(hw, USER_BAP,
1736 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1737 priv->frag_thresh);
1738 if (err) {
1739 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1740 dev->name, err);
1741 return err;
1742 }
1743
1744 /* Set bitrate */
1745 err = __orinoco_hw_set_bitrate(priv);
1746 if (err) {
1747 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1748 dev->name, err);
1749 return err;
1750 }
1751
1752 /* Set power management */
1753 if (priv->has_pm) {
1754 err = hermes_write_wordrec(hw, USER_BAP,
1755 HERMES_RID_CNFPMENABLED,
1756 priv->pm_on);
1757 if (err) {
1758 printk(KERN_ERR "%s: Error %d setting up PM\n",
1759 dev->name, err);
1760 return err;
1761 }
1762
1763 err = hermes_write_wordrec(hw, USER_BAP,
1764 HERMES_RID_CNFMULTICASTRECEIVE,
1765 priv->pm_mcast);
1766 if (err) {
1767 printk(KERN_ERR "%s: Error %d setting up PM\n",
1768 dev->name, err);
1769 return err;
1770 }
1771 err = hermes_write_wordrec(hw, USER_BAP,
1772 HERMES_RID_CNFMAXSLEEPDURATION,
1773 priv->pm_period);
1774 if (err) {
1775 printk(KERN_ERR "%s: Error %d setting up PM\n",
1776 dev->name, err);
1777 return err;
1778 }
1779 err = hermes_write_wordrec(hw, USER_BAP,
1780 HERMES_RID_CNFPMHOLDOVERDURATION,
1781 priv->pm_timeout);
1782 if (err) {
1783 printk(KERN_ERR "%s: Error %d setting up PM\n",
1784 dev->name, err);
1785 return err;
1786 }
1787 }
1788
1789 /* Set preamble - only for Symbol so far... */
1790 if (priv->has_preamble) {
1791 err = hermes_write_wordrec(hw, USER_BAP,
1792 HERMES_RID_CNFPREAMBLE_SYMBOL,
1793 priv->preamble);
1794 if (err) {
1795 printk(KERN_ERR "%s: Error %d setting preamble\n",
1796 dev->name, err);
1797 return err;
1798 }
1799 }
1800
1801 /* Set up encryption */
1802 if (priv->has_wep) {
1803 err = __orinoco_hw_setup_wep(priv);
1804 if (err) {
1805 printk(KERN_ERR "%s: Error %d activating WEP\n",
1806 dev->name, err);
1807 return err;
1808 }
1809 }
1810
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001811 if (priv->iw_mode == IW_MODE_MONITOR) {
1812 /* Enable monitor mode */
1813 dev->type = ARPHRD_IEEE80211;
1814 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1815 HERMES_TEST_MONITOR, 0, NULL);
1816 } else {
1817 /* Disable monitor mode */
1818 dev->type = ARPHRD_ETHER;
1819 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1820 HERMES_TEST_STOP, 0, NULL);
1821 }
1822 if (err)
1823 return err;
1824
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 /* Set promiscuity / multicast*/
1826 priv->promiscuous = 0;
1827 priv->mc_count = 0;
1828 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1829
1830 return 0;
1831}
1832
1833/* FIXME: return int? */
1834static void
1835__orinoco_set_multicast_list(struct net_device *dev)
1836{
1837 struct orinoco_private *priv = netdev_priv(dev);
1838 hermes_t *hw = &priv->hw;
1839 int err = 0;
1840 int promisc, mc_count;
1841
1842 /* The Hermes doesn't seem to have an allmulti mode, so we go
1843 * into promiscuous mode and let the upper levels deal. */
1844 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1845 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1846 promisc = 1;
1847 mc_count = 0;
1848 } else {
1849 promisc = 0;
1850 mc_count = dev->mc_count;
1851 }
1852
1853 if (promisc != priv->promiscuous) {
1854 err = hermes_write_wordrec(hw, USER_BAP,
1855 HERMES_RID_CNFPROMISCUOUSMODE,
1856 promisc);
1857 if (err) {
1858 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1859 dev->name, err);
1860 } else
1861 priv->promiscuous = promisc;
1862 }
1863
1864 if (! promisc && (mc_count || priv->mc_count) ) {
1865 struct dev_mc_list *p = dev->mc_list;
1866 struct hermes_multicast mclist;
1867 int i;
1868
1869 for (i = 0; i < mc_count; i++) {
1870 /* paranoia: is list shorter than mc_count? */
1871 BUG_ON(! p);
1872 /* paranoia: bad address size in list? */
1873 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1874
1875 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1876 p = p->next;
1877 }
1878
1879 if (p)
1880 printk(KERN_WARNING "%s: Multicast list is "
1881 "longer than mc_count\n", dev->name);
1882
1883 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1884 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1885 &mclist);
1886 if (err)
1887 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1888 dev->name, err);
1889 else
1890 priv->mc_count = mc_count;
1891 }
1892
1893 /* Since we can set the promiscuous flag when it wasn't asked
1894 for, make sure the net_device knows about it. */
1895 if (priv->promiscuous)
1896 dev->flags |= IFF_PROMISC;
1897 else
1898 dev->flags &= ~IFF_PROMISC;
1899}
1900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901/* This must be called from user context, without locks held - use
1902 * schedule_work() */
1903static void orinoco_reset(struct net_device *dev)
1904{
1905 struct orinoco_private *priv = netdev_priv(dev);
1906 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001907 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 unsigned long flags;
1909
1910 if (orinoco_lock(priv, &flags) != 0)
1911 /* When the hardware becomes available again, whatever
1912 * detects that is responsible for re-initializing
1913 * it. So no need for anything further */
1914 return;
1915
1916 netif_stop_queue(dev);
1917
1918 /* Shut off interrupts. Depending on what state the hardware
1919 * is in, this might not work, but we'll try anyway */
1920 hermes_set_irqmask(hw, 0);
1921 hermes_write_regn(hw, EVACK, 0xffff);
1922
1923 priv->hw_unavailable++;
1924 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1925 netif_carrier_off(dev);
1926
1927 orinoco_unlock(priv, &flags);
1928
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001929 /* Scanning support: Cleanup of driver struct */
1930 kfree(priv->scan_result);
1931 priv->scan_result = NULL;
1932 priv->scan_inprogress = 0;
1933
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001934 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001936 if (err) {
1937 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1938 "performing hard reset\n", dev->name, err);
1939 goto disable;
1940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 }
1942
1943 err = orinoco_reinit_firmware(dev);
1944 if (err) {
1945 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1946 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001947 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 }
1949
1950 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1951
1952 priv->hw_unavailable--;
1953
1954 /* priv->open or priv->hw_unavailable might have changed while
1955 * we dropped the lock */
1956 if (priv->open && (! priv->hw_unavailable)) {
1957 err = __orinoco_up(dev);
1958 if (err) {
1959 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1960 dev->name, err);
1961 } else
1962 dev->trans_start = jiffies;
1963 }
1964
1965 spin_unlock_irq(&priv->lock);
1966
1967 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001968 disable:
1969 hermes_set_irqmask(hw, 0);
1970 netif_device_detach(dev);
1971 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972}
1973
1974/********************************************************************/
1975/* Interrupt handler */
1976/********************************************************************/
1977
1978static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1979{
1980 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1981}
1982
1983static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1984{
1985 /* This seems to happen a fair bit under load, but ignoring it
1986 seems to work fine...*/
1987 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1988 dev->name);
1989}
1990
1991irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1992{
1993 struct net_device *dev = (struct net_device *)dev_id;
1994 struct orinoco_private *priv = netdev_priv(dev);
1995 hermes_t *hw = &priv->hw;
1996 int count = MAX_IRQLOOPS_PER_IRQ;
1997 u16 evstat, events;
1998 /* These are used to detect a runaway interrupt situation */
1999 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2000 * we panic and shut down the hardware */
2001 static int last_irq_jiffy = 0; /* jiffies value the last time
2002 * we were called */
2003 static int loops_this_jiffy = 0;
2004 unsigned long flags;
2005
2006 if (orinoco_lock(priv, &flags) != 0) {
2007 /* If hw is unavailable - we don't know if the irq was
2008 * for us or not */
2009 return IRQ_HANDLED;
2010 }
2011
2012 evstat = hermes_read_regn(hw, EVSTAT);
2013 events = evstat & hw->inten;
2014 if (! events) {
2015 orinoco_unlock(priv, &flags);
2016 return IRQ_NONE;
2017 }
2018
2019 if (jiffies != last_irq_jiffy)
2020 loops_this_jiffy = 0;
2021 last_irq_jiffy = jiffies;
2022
2023 while (events && count--) {
2024 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2025 printk(KERN_WARNING "%s: IRQ handler is looping too "
2026 "much! Resetting.\n", dev->name);
2027 /* Disable interrupts for now */
2028 hermes_set_irqmask(hw, 0);
2029 schedule_work(&priv->reset_work);
2030 break;
2031 }
2032
2033 /* Check the card hasn't been removed */
2034 if (! hermes_present(hw)) {
2035 DEBUG(0, "orinoco_interrupt(): card removed\n");
2036 break;
2037 }
2038
2039 if (events & HERMES_EV_TICK)
2040 __orinoco_ev_tick(dev, hw);
2041 if (events & HERMES_EV_WTERR)
2042 __orinoco_ev_wterr(dev, hw);
2043 if (events & HERMES_EV_INFDROP)
2044 __orinoco_ev_infdrop(dev, hw);
2045 if (events & HERMES_EV_INFO)
2046 __orinoco_ev_info(dev, hw);
2047 if (events & HERMES_EV_RX)
2048 __orinoco_ev_rx(dev, hw);
2049 if (events & HERMES_EV_TXEXC)
2050 __orinoco_ev_txexc(dev, hw);
2051 if (events & HERMES_EV_TX)
2052 __orinoco_ev_tx(dev, hw);
2053 if (events & HERMES_EV_ALLOC)
2054 __orinoco_ev_alloc(dev, hw);
2055
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002056 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
2058 evstat = hermes_read_regn(hw, EVSTAT);
2059 events = evstat & hw->inten;
2060 };
2061
2062 orinoco_unlock(priv, &flags);
2063 return IRQ_HANDLED;
2064}
2065
2066/********************************************************************/
2067/* Initialization */
2068/********************************************************************/
2069
2070struct comp_id {
2071 u16 id, variant, major, minor;
2072} __attribute__ ((packed));
2073
2074static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2075{
2076 if (nic_id->id < 0x8000)
2077 return FIRMWARE_TYPE_AGERE;
2078 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2079 return FIRMWARE_TYPE_SYMBOL;
2080 else
2081 return FIRMWARE_TYPE_INTERSIL;
2082}
2083
2084/* Set priv->firmware type, determine firmware properties */
2085static int determine_firmware(struct net_device *dev)
2086{
2087 struct orinoco_private *priv = netdev_priv(dev);
2088 hermes_t *hw = &priv->hw;
2089 int err;
2090 struct comp_id nic_id, sta_id;
2091 unsigned int firmver;
2092 char tmp[SYMBOL_MAX_VER_LEN+1];
2093
2094 /* Get the hardware version */
2095 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2096 if (err) {
2097 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2098 dev->name, err);
2099 return err;
2100 }
2101
2102 le16_to_cpus(&nic_id.id);
2103 le16_to_cpus(&nic_id.variant);
2104 le16_to_cpus(&nic_id.major);
2105 le16_to_cpus(&nic_id.minor);
2106 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2107 dev->name, nic_id.id, nic_id.variant,
2108 nic_id.major, nic_id.minor);
2109
2110 priv->firmware_type = determine_firmware_type(&nic_id);
2111
2112 /* Get the firmware version */
2113 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2114 if (err) {
2115 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2116 dev->name, err);
2117 return err;
2118 }
2119
2120 le16_to_cpus(&sta_id.id);
2121 le16_to_cpus(&sta_id.variant);
2122 le16_to_cpus(&sta_id.major);
2123 le16_to_cpus(&sta_id.minor);
2124 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2125 dev->name, sta_id.id, sta_id.variant,
2126 sta_id.major, sta_id.minor);
2127
2128 switch (sta_id.id) {
2129 case 0x15:
2130 printk(KERN_ERR "%s: Primary firmware is active\n",
2131 dev->name);
2132 return -ENODEV;
2133 case 0x14b:
2134 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2135 dev->name);
2136 return -ENODEV;
2137 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2138 case 0x21: /* Symbol Spectrum24 Trilogy */
2139 break;
2140 default:
2141 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2142 dev->name);
2143 break;
2144 }
2145
2146 /* Default capabilities */
2147 priv->has_sensitivity = 1;
2148 priv->has_mwo = 0;
2149 priv->has_preamble = 0;
2150 priv->has_port3 = 1;
2151 priv->has_ibss = 1;
2152 priv->has_wep = 0;
2153 priv->has_big_wep = 0;
2154
2155 /* Determine capabilities from the firmware version */
2156 switch (priv->firmware_type) {
2157 case FIRMWARE_TYPE_AGERE:
2158 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2159 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2160 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2161 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2162
2163 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2164
2165 priv->has_ibss = (firmver >= 0x60006);
2166 priv->has_wep = (firmver >= 0x40020);
2167 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2168 Gold cards from the others? */
2169 priv->has_mwo = (firmver >= 0x60000);
2170 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2171 priv->ibss_port = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002172 priv->has_hostscan = (firmver >= 0x8000a);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002173 priv->broken_monitor = (firmver >= 0x80000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
2175 /* Tested with Agere firmware :
2176 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2177 * Tested CableTron firmware : 4.32 => Anton */
2178 break;
2179 case FIRMWARE_TYPE_SYMBOL:
2180 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2181 /* Intel MAC : 00:02:B3:* */
2182 /* 3Com MAC : 00:50:DA:* */
2183 memset(tmp, 0, sizeof(tmp));
2184 /* Get the Symbol firmware version */
2185 err = hermes_read_ltv(hw, USER_BAP,
2186 HERMES_RID_SECONDARYVERSION_SYMBOL,
2187 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2188 if (err) {
2189 printk(KERN_WARNING
2190 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2191 dev->name, err);
2192 firmver = 0;
2193 tmp[0] = '\0';
2194 } else {
2195 /* The firmware revision is a string, the format is
2196 * something like : "V2.20-01".
2197 * Quick and dirty parsing... - Jean II
2198 */
2199 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2200 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2201 | (tmp[7] - '0');
2202
2203 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2204 }
2205
2206 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2207 "Symbol %s", tmp);
2208
2209 priv->has_ibss = (firmver >= 0x20000);
2210 priv->has_wep = (firmver >= 0x15012);
2211 priv->has_big_wep = (firmver >= 0x20000);
2212 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2213 (firmver >= 0x29000 && firmver < 0x30000) ||
2214 firmver >= 0x31000;
2215 priv->has_preamble = (firmver >= 0x20000);
2216 priv->ibss_port = 4;
Christoph Hellwig649e59e2005-05-14 17:30:10 +02002217 priv->broken_disableport = (firmver == 0x25013) ||
2218 (firmver >= 0x30000 && firmver <= 0x31000);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002219 priv->has_hostscan = (firmver >= 0x31001) ||
2220 (firmver >= 0x29057 && firmver < 0x30000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 /* Tested with Intel firmware : 0x20015 => Jean II */
2222 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2223 break;
2224 case FIRMWARE_TYPE_INTERSIL:
2225 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2226 * Samsung, Compaq 100/200 and Proxim are slightly
2227 * different and less well tested */
2228 /* D-Link MAC : 00:40:05:* */
2229 /* Addtron MAC : 00:90:D1:* */
2230 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2231 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2232 sta_id.variant);
2233
2234 firmver = ((unsigned long)sta_id.major << 16) |
2235 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2236
2237 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2238 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2239 priv->has_pm = (firmver >= 0x000700);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002240 priv->has_hostscan = (firmver >= 0x010301);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
2242 if (firmver >= 0x000800)
2243 priv->ibss_port = 0;
2244 else {
2245 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2246 "than v0.8.x - several features not supported\n",
2247 dev->name);
2248 priv->ibss_port = 1;
2249 }
2250 break;
2251 }
2252 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2253 priv->fw_name);
2254
2255 return 0;
2256}
2257
2258static int orinoco_init(struct net_device *dev)
2259{
2260 struct orinoco_private *priv = netdev_priv(dev);
2261 hermes_t *hw = &priv->hw;
2262 int err = 0;
2263 struct hermes_idstring nickbuf;
2264 u16 reclen;
2265 int len;
2266
2267 TRACE_ENTER(dev->name);
2268
2269 /* No need to lock, the hw_unavailable flag is already set in
2270 * alloc_orinocodev() */
Jeff Garzikb4538722005-05-12 22:48:20 -04002271 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
2273 /* Initialize the firmware */
David Gibsonb24d4582005-05-12 20:04:16 -04002274 err = orinoco_reinit_firmware(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 if (err != 0) {
2276 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2277 dev->name, err);
2278 goto out;
2279 }
2280
2281 err = determine_firmware(dev);
2282 if (err != 0) {
2283 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2284 dev->name);
2285 goto out;
2286 }
2287
2288 if (priv->has_port3)
2289 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2290 if (priv->has_ibss)
2291 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2292 dev->name);
2293 if (priv->has_wep) {
2294 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2295 if (priv->has_big_wep)
2296 printk("104-bit key\n");
2297 else
2298 printk("40-bit key\n");
2299 }
2300
2301 /* Get the MAC address */
2302 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2303 ETH_ALEN, NULL, dev->dev_addr);
2304 if (err) {
2305 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2306 dev->name);
2307 goto out;
2308 }
2309
2310 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2311 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2312 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2313 dev->dev_addr[5]);
2314
2315 /* Get the station name */
2316 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2317 sizeof(nickbuf), &reclen, &nickbuf);
2318 if (err) {
2319 printk(KERN_ERR "%s: failed to read station name\n",
2320 dev->name);
2321 goto out;
2322 }
2323 if (nickbuf.len)
2324 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2325 else
2326 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2327 memcpy(priv->nick, &nickbuf.val, len);
2328 priv->nick[len] = '\0';
2329
2330 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2331
2332 /* Get allowed channels */
2333 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2334 &priv->channel_mask);
2335 if (err) {
2336 printk(KERN_ERR "%s: failed to read channel list!\n",
2337 dev->name);
2338 goto out;
2339 }
2340
2341 /* Get initial AP density */
2342 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2343 &priv->ap_density);
2344 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2345 priv->has_sensitivity = 0;
2346 }
2347
2348 /* Get initial RTS threshold */
2349 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2350 &priv->rts_thresh);
2351 if (err) {
2352 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2353 dev->name);
2354 goto out;
2355 }
2356
2357 /* Get initial fragmentation settings */
2358 if (priv->has_mwo)
2359 err = hermes_read_wordrec(hw, USER_BAP,
2360 HERMES_RID_CNFMWOROBUST_AGERE,
2361 &priv->mwo_robust);
2362 else
2363 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2364 &priv->frag_thresh);
2365 if (err) {
2366 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2367 dev->name);
2368 goto out;
2369 }
2370
2371 /* Power management setup */
2372 if (priv->has_pm) {
2373 priv->pm_on = 0;
2374 priv->pm_mcast = 1;
2375 err = hermes_read_wordrec(hw, USER_BAP,
2376 HERMES_RID_CNFMAXSLEEPDURATION,
2377 &priv->pm_period);
2378 if (err) {
2379 printk(KERN_ERR "%s: failed to read power management period!\n",
2380 dev->name);
2381 goto out;
2382 }
2383 err = hermes_read_wordrec(hw, USER_BAP,
2384 HERMES_RID_CNFPMHOLDOVERDURATION,
2385 &priv->pm_timeout);
2386 if (err) {
2387 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2388 dev->name);
2389 goto out;
2390 }
2391 }
2392
2393 /* Preamble setup */
2394 if (priv->has_preamble) {
2395 err = hermes_read_wordrec(hw, USER_BAP,
2396 HERMES_RID_CNFPREAMBLE_SYMBOL,
2397 &priv->preamble);
2398 if (err)
2399 goto out;
2400 }
2401
2402 /* Set up the default configuration */
2403 priv->iw_mode = IW_MODE_INFRA;
2404 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2405 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2406 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04002407 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
2409 priv->promiscuous = 0;
2410 priv->wep_on = 0;
2411 priv->tx_key = 0;
2412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 /* Make the hardware available, as long as it hasn't been
2414 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2415 spin_lock_irq(&priv->lock);
2416 priv->hw_unavailable--;
2417 spin_unlock_irq(&priv->lock);
2418
2419 printk(KERN_DEBUG "%s: ready\n", dev->name);
2420
2421 out:
2422 TRACE_EXIT(dev->name);
2423 return err;
2424}
2425
2426struct net_device *alloc_orinocodev(int sizeof_card,
2427 int (*hard_reset)(struct orinoco_private *))
2428{
2429 struct net_device *dev;
2430 struct orinoco_private *priv;
2431
2432 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2433 if (! dev)
2434 return NULL;
2435 priv = netdev_priv(dev);
2436 priv->ndev = dev;
2437 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002438 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 + sizeof(struct orinoco_private));
2440 else
2441 priv->card = NULL;
2442
2443 /* Setup / override net_device fields */
2444 dev->init = orinoco_init;
2445 dev->hard_start_xmit = orinoco_xmit;
2446 dev->tx_timeout = orinoco_tx_timeout;
2447 dev->watchdog_timeo = HZ; /* 1 second timeout */
2448 dev->get_stats = orinoco_get_stats;
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002449 dev->ethtool_ops = &orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002450 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04002451#ifdef WIRELESS_SPY
2452 priv->wireless_data.spy_data = &priv->spy_data;
2453 dev->wireless_data = &priv->wireless_data;
2454#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 dev->change_mtu = orinoco_change_mtu;
2456 dev->set_multicast_list = orinoco_set_multicast_list;
2457 /* we use the default eth_mac_addr for setting the MAC addr */
2458
2459 /* Set up default callbacks */
2460 dev->open = orinoco_open;
2461 dev->stop = orinoco_stop;
2462 priv->hard_reset = hard_reset;
2463
2464 spin_lock_init(&priv->lock);
2465 priv->open = 0;
2466 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2467 * before anything else touches the
2468 * hardware */
2469 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
Christoph Hellwig16739b02005-06-19 01:27:51 +02002470 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002471 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
2473 netif_carrier_off(dev);
2474 priv->last_linkstatus = 0xffff;
2475
2476 return dev;
2477
2478}
2479
2480void free_orinocodev(struct net_device *dev)
2481{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002482 struct orinoco_private *priv = netdev_priv(dev);
2483
2484 kfree(priv->scan_result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 free_netdev(dev);
2486}
2487
2488/********************************************************************/
2489/* Wireless extensions */
2490/********************************************************************/
2491
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2493 char buf[IW_ESSID_MAX_SIZE+1])
2494{
2495 hermes_t *hw = &priv->hw;
2496 int err = 0;
2497 struct hermes_idstring essidbuf;
2498 char *p = (char *)(&essidbuf.val);
2499 int len;
2500 unsigned long flags;
2501
2502 if (orinoco_lock(priv, &flags) != 0)
2503 return -EBUSY;
2504
2505 if (strlen(priv->desired_essid) > 0) {
2506 /* We read the desired SSID from the hardware rather
2507 than from priv->desired_essid, just in case the
2508 firmware is allowed to change it on us. I'm not
2509 sure about this */
2510 /* My guess is that the OWNSSID should always be whatever
2511 * we set to the card, whereas CURRENT_SSID is the one that
2512 * may change... - Jean II */
2513 u16 rid;
2514
2515 *active = 1;
2516
2517 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2518 HERMES_RID_CNFDESIREDSSID;
2519
2520 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2521 NULL, &essidbuf);
2522 if (err)
2523 goto fail_unlock;
2524 } else {
2525 *active = 0;
2526
2527 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2528 sizeof(essidbuf), NULL, &essidbuf);
2529 if (err)
2530 goto fail_unlock;
2531 }
2532
2533 len = le16_to_cpu(essidbuf.len);
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002534 BUG_ON(len > IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
2536 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2537 memcpy(buf, p, len);
2538 buf[len] = '\0';
2539
2540 fail_unlock:
2541 orinoco_unlock(priv, &flags);
2542
2543 return err;
2544}
2545
2546static long orinoco_hw_get_freq(struct orinoco_private *priv)
2547{
2548
2549 hermes_t *hw = &priv->hw;
2550 int err = 0;
2551 u16 channel;
2552 long freq = 0;
2553 unsigned long flags;
2554
2555 if (orinoco_lock(priv, &flags) != 0)
2556 return -EBUSY;
2557
2558 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2559 if (err)
2560 goto out;
2561
2562 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2563 if (channel == 0) {
2564 err = -EBUSY;
2565 goto out;
2566 }
2567
2568 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2569 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2570 priv->ndev->name, channel);
2571 err = -EBUSY;
2572 goto out;
2573
2574 }
2575 freq = channel_frequency[channel-1] * 100000;
2576
2577 out:
2578 orinoco_unlock(priv, &flags);
2579
2580 if (err > 0)
2581 err = -EBUSY;
2582 return err ? err : freq;
2583}
2584
2585static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2586 int *numrates, s32 *rates, int max)
2587{
2588 hermes_t *hw = &priv->hw;
2589 struct hermes_idstring list;
2590 unsigned char *p = (unsigned char *)&list.val;
2591 int err = 0;
2592 int num;
2593 int i;
2594 unsigned long flags;
2595
2596 if (orinoco_lock(priv, &flags) != 0)
2597 return -EBUSY;
2598
2599 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2600 sizeof(list), NULL, &list);
2601 orinoco_unlock(priv, &flags);
2602
2603 if (err)
2604 return err;
2605
2606 num = le16_to_cpu(list.len);
2607 *numrates = num;
2608 num = min(num, max);
2609
2610 for (i = 0; i < num; i++) {
2611 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2612 }
2613
2614 return 0;
2615}
2616
Christoph Hellwig620554e2005-06-19 01:27:33 +02002617static int orinoco_ioctl_getname(struct net_device *dev,
2618 struct iw_request_info *info,
2619 char *name,
2620 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621{
2622 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 int numrates;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002624 int err;
2625
2626 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2627
2628 if (!err && (numrates > 2))
2629 strcpy(name, "IEEE 802.11b");
2630 else
2631 strcpy(name, "IEEE 802.11-DS");
2632
2633 return 0;
2634}
2635
Christoph Hellwig16739b02005-06-19 01:27:51 +02002636static int orinoco_ioctl_setwap(struct net_device *dev,
2637 struct iw_request_info *info,
2638 struct sockaddr *ap_addr,
2639 char *extra)
2640{
2641 struct orinoco_private *priv = netdev_priv(dev);
2642 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 unsigned long flags;
Christoph Hellwig16739b02005-06-19 01:27:51 +02002644 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2645 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
2647 if (orinoco_lock(priv, &flags) != 0)
2648 return -EBUSY;
2649
Christoph Hellwig16739b02005-06-19 01:27:51 +02002650 /* Enable automatic roaming - no sanity checks are needed */
2651 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2652 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2653 priv->bssid_fixed = 0;
2654 memset(priv->desired_bssid, 0, ETH_ALEN);
2655
2656 /* "off" means keep existing connection */
2657 if (ap_addr->sa_data[0] == 0) {
2658 __orinoco_hw_set_wap(priv);
2659 err = 0;
2660 }
2661 goto out;
2662 }
2663
2664 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2665 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2666 "support manual roaming\n",
2667 dev->name);
2668 err = -EOPNOTSUPP;
2669 goto out;
2670 }
2671
2672 if (priv->iw_mode != IW_MODE_INFRA) {
2673 printk(KERN_WARNING "%s: Manual roaming supported only in "
2674 "managed mode\n", dev->name);
2675 err = -EOPNOTSUPP;
2676 goto out;
2677 }
2678
2679 /* Intersil firmware hangs without Desired ESSID */
2680 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2681 strlen(priv->desired_essid) == 0) {
2682 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2683 "manual roaming\n", dev->name);
2684 err = -EOPNOTSUPP;
2685 goto out;
2686 }
2687
2688 /* Finally, enable manual roaming */
2689 priv->bssid_fixed = 1;
2690 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2691
2692 out:
2693 orinoco_unlock(priv, &flags);
2694 return err;
2695}
2696
Christoph Hellwig620554e2005-06-19 01:27:33 +02002697static int orinoco_ioctl_getwap(struct net_device *dev,
2698 struct iw_request_info *info,
2699 struct sockaddr *ap_addr,
2700 char *extra)
2701{
2702 struct orinoco_private *priv = netdev_priv(dev);
2703
2704 hermes_t *hw = &priv->hw;
2705 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 unsigned long flags;
2707
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 if (orinoco_lock(priv, &flags) != 0)
2709 return -EBUSY;
2710
Christoph Hellwig620554e2005-06-19 01:27:33 +02002711 ap_addr->sa_family = ARPHRD_ETHER;
2712 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2713 ETH_ALEN, NULL, ap_addr->sa_data);
2714
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 orinoco_unlock(priv, &flags);
2716
Christoph Hellwig620554e2005-06-19 01:27:33 +02002717 return err;
2718}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
Christoph Hellwig620554e2005-06-19 01:27:33 +02002720static int orinoco_ioctl_setmode(struct net_device *dev,
2721 struct iw_request_info *info,
2722 u32 *mode,
2723 char *extra)
2724{
2725 struct orinoco_private *priv = netdev_priv(dev);
2726 int err = -EINPROGRESS; /* Call commit handler */
2727 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
Christoph Hellwig620554e2005-06-19 01:27:33 +02002729 if (priv->iw_mode == *mode)
2730 return 0;
2731
2732 if (orinoco_lock(priv, &flags) != 0)
2733 return -EBUSY;
2734
2735 switch (*mode) {
2736 case IW_MODE_ADHOC:
2737 if (!priv->has_ibss && !priv->has_port3)
2738 err = -EOPNOTSUPP;
2739 break;
2740
2741 case IW_MODE_INFRA:
2742 break;
2743
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002744 case IW_MODE_MONITOR:
2745 if (priv->broken_monitor && !force_monitor) {
2746 printk(KERN_WARNING "%s: Monitor mode support is "
2747 "buggy in this firmware, not enabling\n",
2748 dev->name);
2749 err = -EOPNOTSUPP;
2750 }
2751 break;
2752
Christoph Hellwig620554e2005-06-19 01:27:33 +02002753 default:
2754 err = -EOPNOTSUPP;
2755 break;
2756 }
2757
2758 if (err == -EINPROGRESS) {
2759 priv->iw_mode = *mode;
2760 set_port_type(priv);
2761 }
2762
2763 orinoco_unlock(priv, &flags);
2764
2765 return err;
2766}
2767
2768static int orinoco_ioctl_getmode(struct net_device *dev,
2769 struct iw_request_info *info,
2770 u32 *mode,
2771 char *extra)
2772{
2773 struct orinoco_private *priv = netdev_priv(dev);
2774
2775 *mode = priv->iw_mode;
2776 return 0;
2777}
2778
2779static int orinoco_ioctl_getiwrange(struct net_device *dev,
2780 struct iw_request_info *info,
2781 struct iw_point *rrq,
2782 char *extra)
2783{
2784 struct orinoco_private *priv = netdev_priv(dev);
2785 int err = 0;
2786 struct iw_range *range = (struct iw_range *) extra;
2787 int numrates;
2788 int i, k;
2789
2790 TRACE_ENTER(dev->name);
2791
2792 rrq->length = sizeof(struct iw_range);
2793 memset(range, 0, sizeof(struct iw_range));
2794
2795 range->we_version_compiled = WIRELESS_EXT;
2796 range->we_version_source = 14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
2798 /* Set available channels/frequencies */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002799 range->num_channels = NUM_CHANNELS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 k = 0;
2801 for (i = 0; i < NUM_CHANNELS; i++) {
2802 if (priv->channel_mask & (1 << i)) {
Christoph Hellwig620554e2005-06-19 01:27:33 +02002803 range->freq[k].i = i + 1;
2804 range->freq[k].m = channel_frequency[i] * 100000;
2805 range->freq[k].e = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 k++;
2807 }
2808
2809 if (k >= IW_MAX_FREQUENCIES)
2810 break;
2811 }
Christoph Hellwig620554e2005-06-19 01:27:33 +02002812 range->num_frequency = k;
2813 range->sensitivity = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814
Christoph Hellwig620554e2005-06-19 01:27:33 +02002815 if (priv->has_wep) {
2816 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2817 range->encoding_size[0] = SMALL_KEY_SIZE;
2818 range->num_encoding_sizes = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
Christoph Hellwig620554e2005-06-19 01:27:33 +02002820 if (priv->has_big_wep) {
2821 range->encoding_size[1] = LARGE_KEY_SIZE;
2822 range->num_encoding_sizes = 2;
2823 }
2824 }
2825
Pavel Roskin343c6862005-09-09 18:43:02 -04002826 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 /* Quality stats meaningless in ad-hoc mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 } else {
Christoph Hellwig620554e2005-06-19 01:27:33 +02002829 range->max_qual.qual = 0x8b - 0x2f;
2830 range->max_qual.level = 0x2f - 0x95 - 1;
2831 range->max_qual.noise = 0x2f - 0x95 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 /* Need to get better values */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002833 range->avg_qual.qual = 0x24;
2834 range->avg_qual.level = 0xC2;
2835 range->avg_qual.noise = 0x9E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 }
2837
2838 err = orinoco_hw_get_bitratelist(priv, &numrates,
Christoph Hellwig620554e2005-06-19 01:27:33 +02002839 range->bitrate, IW_MAX_BITRATES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 if (err)
2841 return err;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002842 range->num_bitrates = numrates;
2843
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 /* Set an indication of the max TCP throughput in bit/s that we can
2845 * expect using this interface. May be use for QoS stuff...
2846 * Jean II */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002847 if (numrates > 2)
2848 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 else
Christoph Hellwig620554e2005-06-19 01:27:33 +02002850 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
Christoph Hellwig620554e2005-06-19 01:27:33 +02002852 range->min_rts = 0;
2853 range->max_rts = 2347;
2854 range->min_frag = 256;
2855 range->max_frag = 2346;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856
Christoph Hellwig620554e2005-06-19 01:27:33 +02002857 range->min_pmp = 0;
2858 range->max_pmp = 65535000;
2859 range->min_pmt = 0;
2860 range->max_pmt = 65535 * 1000; /* ??? */
2861 range->pmp_flags = IW_POWER_PERIOD;
2862 range->pmt_flags = IW_POWER_TIMEOUT;
2863 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
Christoph Hellwig620554e2005-06-19 01:27:33 +02002865 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2866 range->retry_flags = IW_RETRY_LIMIT;
2867 range->r_time_flags = IW_RETRY_LIFETIME;
2868 range->min_retry = 0;
2869 range->max_retry = 65535; /* ??? */
2870 range->min_r_time = 0;
2871 range->max_r_time = 65535 * 1000; /* ??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872
Pavel Roskin343c6862005-09-09 18:43:02 -04002873 /* Event capability (kernel) */
2874 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2875 /* Event capability (driver) */
2876 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2877 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2878 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2879 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2880
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 TRACE_EXIT(dev->name);
2882
2883 return 0;
2884}
2885
Christoph Hellwig620554e2005-06-19 01:27:33 +02002886static int orinoco_ioctl_setiwencode(struct net_device *dev,
2887 struct iw_request_info *info,
2888 struct iw_point *erq,
2889 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890{
2891 struct orinoco_private *priv = netdev_priv(dev);
2892 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2893 int setindex = priv->tx_key;
2894 int enable = priv->wep_on;
2895 int restricted = priv->wep_restrict;
2896 u16 xlen = 0;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002897 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 unsigned long flags;
2899
2900 if (! priv->has_wep)
2901 return -EOPNOTSUPP;
2902
2903 if (erq->pointer) {
2904 /* We actually have a key to set - check its length */
2905 if (erq->length > LARGE_KEY_SIZE)
2906 return -E2BIG;
2907
2908 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2909 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 }
2911
2912 if (orinoco_lock(priv, &flags) != 0)
2913 return -EBUSY;
2914
2915 if (erq->pointer) {
2916 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2917 index = priv->tx_key;
2918
2919 /* Adjust key length to a supported value */
2920 if (erq->length > SMALL_KEY_SIZE) {
2921 xlen = LARGE_KEY_SIZE;
2922 } else if (erq->length > 0) {
2923 xlen = SMALL_KEY_SIZE;
2924 } else
2925 xlen = 0;
2926
2927 /* Switch on WEP if off */
2928 if ((!enable) && (xlen > 0)) {
2929 setindex = index;
2930 enable = 1;
2931 }
2932 } else {
2933 /* Important note : if the user do "iwconfig eth0 enc off",
2934 * we will arrive there with an index of -1. This is valid
2935 * but need to be taken care off... Jean II */
2936 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2937 if((index != -1) || (erq->flags == 0)) {
2938 err = -EINVAL;
2939 goto out;
2940 }
2941 } else {
2942 /* Set the index : Check that the key is valid */
2943 if(priv->keys[index].len == 0) {
2944 err = -EINVAL;
2945 goto out;
2946 }
2947 setindex = index;
2948 }
2949 }
2950
2951 if (erq->flags & IW_ENCODE_DISABLED)
2952 enable = 0;
2953 if (erq->flags & IW_ENCODE_OPEN)
2954 restricted = 0;
2955 if (erq->flags & IW_ENCODE_RESTRICTED)
2956 restricted = 1;
2957
2958 if (erq->pointer) {
2959 priv->keys[index].len = cpu_to_le16(xlen);
2960 memset(priv->keys[index].data, 0,
2961 sizeof(priv->keys[index].data));
2962 memcpy(priv->keys[index].data, keybuf, erq->length);
2963 }
2964 priv->tx_key = setindex;
2965
2966 /* Try fast key change if connected and only keys are changed */
2967 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2968 netif_carrier_ok(dev)) {
2969 err = __orinoco_hw_setup_wepkeys(priv);
2970 /* No need to commit if successful */
2971 goto out;
2972 }
2973
2974 priv->wep_on = enable;
2975 priv->wep_restrict = restricted;
2976
2977 out:
2978 orinoco_unlock(priv, &flags);
2979
2980 return err;
2981}
2982
Christoph Hellwig620554e2005-06-19 01:27:33 +02002983static int orinoco_ioctl_getiwencode(struct net_device *dev,
2984 struct iw_request_info *info,
2985 struct iw_point *erq,
2986 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987{
2988 struct orinoco_private *priv = netdev_priv(dev);
2989 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2990 u16 xlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 unsigned long flags;
2992
2993 if (! priv->has_wep)
2994 return -EOPNOTSUPP;
2995
2996 if (orinoco_lock(priv, &flags) != 0)
2997 return -EBUSY;
2998
2999 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3000 index = priv->tx_key;
3001
3002 erq->flags = 0;
3003 if (! priv->wep_on)
3004 erq->flags |= IW_ENCODE_DISABLED;
3005 erq->flags |= index + 1;
3006
3007 if (priv->wep_restrict)
3008 erq->flags |= IW_ENCODE_RESTRICTED;
3009 else
3010 erq->flags |= IW_ENCODE_OPEN;
3011
3012 xlen = le16_to_cpu(priv->keys[index].len);
3013
3014 erq->length = xlen;
3015
3016 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3017
3018 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 return 0;
3020}
3021
Christoph Hellwig620554e2005-06-19 01:27:33 +02003022static int orinoco_ioctl_setessid(struct net_device *dev,
3023 struct iw_request_info *info,
3024 struct iw_point *erq,
3025 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026{
3027 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 unsigned long flags;
3029
3030 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3031 * anyway... - Jean II */
3032
Christoph Hellwig620554e2005-06-19 01:27:33 +02003033 /* Hum... Should not use Wireless Extension constant (may change),
3034 * should use our own... - Jean II */
3035 if (erq->length > IW_ESSID_MAX_SIZE)
3036 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037
3038 if (orinoco_lock(priv, &flags) != 0)
3039 return -EBUSY;
3040
Christoph Hellwig620554e2005-06-19 01:27:33 +02003041 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3042 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3043
3044 /* If not ANY, get the new ESSID */
3045 if (erq->flags) {
3046 memcpy(priv->desired_essid, essidbuf, erq->length);
3047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
3049 orinoco_unlock(priv, &flags);
3050
Christoph Hellwig620554e2005-06-19 01:27:33 +02003051 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052}
3053
Christoph Hellwig620554e2005-06-19 01:27:33 +02003054static int orinoco_ioctl_getessid(struct net_device *dev,
3055 struct iw_request_info *info,
3056 struct iw_point *erq,
3057 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058{
3059 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 int active;
3061 int err = 0;
3062 unsigned long flags;
3063
3064 TRACE_ENTER(dev->name);
3065
3066 if (netif_running(dev)) {
3067 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3068 if (err)
3069 return err;
3070 } else {
3071 if (orinoco_lock(priv, &flags) != 0)
3072 return -EBUSY;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003073 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 orinoco_unlock(priv, &flags);
3075 }
3076
3077 erq->flags = 1;
3078 erq->length = strlen(essidbuf) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
3080 TRACE_EXIT(dev->name);
3081
3082 return 0;
3083}
3084
Christoph Hellwig620554e2005-06-19 01:27:33 +02003085static int orinoco_ioctl_setnick(struct net_device *dev,
3086 struct iw_request_info *info,
3087 struct iw_point *nrq,
3088 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089{
3090 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 unsigned long flags;
3092
3093 if (nrq->length > IW_ESSID_MAX_SIZE)
3094 return -E2BIG;
3095
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 if (orinoco_lock(priv, &flags) != 0)
3097 return -EBUSY;
3098
Christoph Hellwig620554e2005-06-19 01:27:33 +02003099 memset(priv->nick, 0, sizeof(priv->nick));
3100 memcpy(priv->nick, nickbuf, nrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101
3102 orinoco_unlock(priv, &flags);
3103
Christoph Hellwig620554e2005-06-19 01:27:33 +02003104 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
3106
Christoph Hellwig620554e2005-06-19 01:27:33 +02003107static int orinoco_ioctl_getnick(struct net_device *dev,
3108 struct iw_request_info *info,
3109 struct iw_point *nrq,
3110 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111{
3112 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 unsigned long flags;
3114
3115 if (orinoco_lock(priv, &flags) != 0)
3116 return -EBUSY;
3117
3118 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3119 orinoco_unlock(priv, &flags);
3120
3121 nrq->length = strlen(nickbuf)+1;
3122
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 return 0;
3124}
3125
Christoph Hellwig620554e2005-06-19 01:27:33 +02003126static int orinoco_ioctl_setfreq(struct net_device *dev,
3127 struct iw_request_info *info,
3128 struct iw_freq *frq,
3129 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130{
3131 struct orinoco_private *priv = netdev_priv(dev);
3132 int chan = -1;
3133 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003134 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003136 /* In infrastructure mode the AP sets the channel */
3137 if (priv->iw_mode == IW_MODE_INFRA)
3138 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139
3140 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3141 /* Setting by channel number */
3142 chan = frq->m;
3143 } else {
3144 /* Setting by frequency - search the table */
3145 int mult = 1;
3146 int i;
3147
3148 for (i = 0; i < (6 - frq->e); i++)
3149 mult *= 10;
3150
3151 for (i = 0; i < NUM_CHANNELS; i++)
3152 if (frq->m == (channel_frequency[i] * mult))
3153 chan = i+1;
3154 }
3155
3156 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3157 ! (priv->channel_mask & (1 << (chan-1)) ) )
3158 return -EINVAL;
3159
3160 if (orinoco_lock(priv, &flags) != 0)
3161 return -EBUSY;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003162
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 priv->channel = chan;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003164 if (priv->iw_mode == IW_MODE_MONITOR) {
3165 /* Fast channel change - no commit if successful */
3166 hermes_t *hw = &priv->hw;
3167 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3168 HERMES_TEST_SET_CHANNEL,
3169 chan, NULL);
3170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 orinoco_unlock(priv, &flags);
3172
Christoph Hellwig620554e2005-06-19 01:27:33 +02003173 return err;
3174}
3175
3176static int orinoco_ioctl_getfreq(struct net_device *dev,
3177 struct iw_request_info *info,
3178 struct iw_freq *frq,
3179 char *extra)
3180{
3181 struct orinoco_private *priv = netdev_priv(dev);
3182 int tmp;
3183
3184 /* Locking done in there */
3185 tmp = orinoco_hw_get_freq(priv);
3186 if (tmp < 0) {
3187 return tmp;
3188 }
3189
3190 frq->m = tmp;
3191 frq->e = 1;
3192
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 return 0;
3194}
3195
Christoph Hellwig620554e2005-06-19 01:27:33 +02003196static int orinoco_ioctl_getsens(struct net_device *dev,
3197 struct iw_request_info *info,
3198 struct iw_param *srq,
3199 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200{
3201 struct orinoco_private *priv = netdev_priv(dev);
3202 hermes_t *hw = &priv->hw;
3203 u16 val;
3204 int err;
3205 unsigned long flags;
3206
3207 if (!priv->has_sensitivity)
3208 return -EOPNOTSUPP;
3209
3210 if (orinoco_lock(priv, &flags) != 0)
3211 return -EBUSY;
3212 err = hermes_read_wordrec(hw, USER_BAP,
3213 HERMES_RID_CNFSYSTEMSCALE, &val);
3214 orinoco_unlock(priv, &flags);
3215
3216 if (err)
3217 return err;
3218
3219 srq->value = val;
3220 srq->fixed = 0; /* auto */
3221
3222 return 0;
3223}
3224
Christoph Hellwig620554e2005-06-19 01:27:33 +02003225static int orinoco_ioctl_setsens(struct net_device *dev,
3226 struct iw_request_info *info,
3227 struct iw_param *srq,
3228 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229{
3230 struct orinoco_private *priv = netdev_priv(dev);
3231 int val = srq->value;
3232 unsigned long flags;
3233
3234 if (!priv->has_sensitivity)
3235 return -EOPNOTSUPP;
3236
3237 if ((val < 1) || (val > 3))
3238 return -EINVAL;
3239
3240 if (orinoco_lock(priv, &flags) != 0)
3241 return -EBUSY;
3242 priv->ap_density = val;
3243 orinoco_unlock(priv, &flags);
3244
Christoph Hellwig620554e2005-06-19 01:27:33 +02003245 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246}
3247
Christoph Hellwig620554e2005-06-19 01:27:33 +02003248static int orinoco_ioctl_setrts(struct net_device *dev,
3249 struct iw_request_info *info,
3250 struct iw_param *rrq,
3251 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252{
3253 struct orinoco_private *priv = netdev_priv(dev);
3254 int val = rrq->value;
3255 unsigned long flags;
3256
3257 if (rrq->disabled)
3258 val = 2347;
3259
3260 if ( (val < 0) || (val > 2347) )
3261 return -EINVAL;
3262
3263 if (orinoco_lock(priv, &flags) != 0)
3264 return -EBUSY;
3265
3266 priv->rts_thresh = val;
3267 orinoco_unlock(priv, &flags);
3268
Christoph Hellwig620554e2005-06-19 01:27:33 +02003269 return -EINPROGRESS; /* Call commit handler */
3270}
3271
3272static int orinoco_ioctl_getrts(struct net_device *dev,
3273 struct iw_request_info *info,
3274 struct iw_param *rrq,
3275 char *extra)
3276{
3277 struct orinoco_private *priv = netdev_priv(dev);
3278
3279 rrq->value = priv->rts_thresh;
3280 rrq->disabled = (rrq->value == 2347);
3281 rrq->fixed = 1;
3282
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 return 0;
3284}
3285
Christoph Hellwig620554e2005-06-19 01:27:33 +02003286static int orinoco_ioctl_setfrag(struct net_device *dev,
3287 struct iw_request_info *info,
3288 struct iw_param *frq,
3289 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290{
3291 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003292 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 unsigned long flags;
3294
3295 if (orinoco_lock(priv, &flags) != 0)
3296 return -EBUSY;
3297
3298 if (priv->has_mwo) {
3299 if (frq->disabled)
3300 priv->mwo_robust = 0;
3301 else {
3302 if (frq->fixed)
3303 printk(KERN_WARNING "%s: Fixed fragmentation is "
3304 "not supported on this firmware. "
3305 "Using MWO robust instead.\n", dev->name);
3306 priv->mwo_robust = 1;
3307 }
3308 } else {
3309 if (frq->disabled)
3310 priv->frag_thresh = 2346;
3311 else {
3312 if ( (frq->value < 256) || (frq->value > 2346) )
3313 err = -EINVAL;
3314 else
3315 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3316 }
3317 }
3318
3319 orinoco_unlock(priv, &flags);
3320
3321 return err;
3322}
3323
Christoph Hellwig620554e2005-06-19 01:27:33 +02003324static int orinoco_ioctl_getfrag(struct net_device *dev,
3325 struct iw_request_info *info,
3326 struct iw_param *frq,
3327 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328{
3329 struct orinoco_private *priv = netdev_priv(dev);
3330 hermes_t *hw = &priv->hw;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003331 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 u16 val;
3333 unsigned long flags;
3334
3335 if (orinoco_lock(priv, &flags) != 0)
3336 return -EBUSY;
3337
3338 if (priv->has_mwo) {
3339 err = hermes_read_wordrec(hw, USER_BAP,
3340 HERMES_RID_CNFMWOROBUST_AGERE,
3341 &val);
3342 if (err)
3343 val = 0;
3344
3345 frq->value = val ? 2347 : 0;
3346 frq->disabled = ! val;
3347 frq->fixed = 0;
3348 } else {
3349 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3350 &val);
3351 if (err)
3352 val = 0;
3353
3354 frq->value = val;
3355 frq->disabled = (val >= 2346);
3356 frq->fixed = 1;
3357 }
3358
3359 orinoco_unlock(priv, &flags);
3360
3361 return err;
3362}
3363
Christoph Hellwig620554e2005-06-19 01:27:33 +02003364static int orinoco_ioctl_setrate(struct net_device *dev,
3365 struct iw_request_info *info,
3366 struct iw_param *rrq,
3367 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368{
3369 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 int ratemode = -1;
3371 int bitrate; /* 100s of kilobits */
3372 int i;
3373 unsigned long flags;
3374
3375 /* As the user space doesn't know our highest rate, it uses -1
3376 * to ask us to set the highest rate. Test it using "iwconfig
3377 * ethX rate auto" - Jean II */
3378 if (rrq->value == -1)
3379 bitrate = 110;
3380 else {
3381 if (rrq->value % 100000)
3382 return -EINVAL;
3383 bitrate = rrq->value / 100000;
3384 }
3385
3386 if ( (bitrate != 10) && (bitrate != 20) &&
3387 (bitrate != 55) && (bitrate != 110) )
3388 return -EINVAL;
3389
3390 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3391 if ( (bitrate_table[i].bitrate == bitrate) &&
3392 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3393 ratemode = i;
3394 break;
3395 }
3396
3397 if (ratemode == -1)
3398 return -EINVAL;
3399
3400 if (orinoco_lock(priv, &flags) != 0)
3401 return -EBUSY;
3402 priv->bitratemode = ratemode;
3403 orinoco_unlock(priv, &flags);
3404
Christoph Hellwig620554e2005-06-19 01:27:33 +02003405 return -EINPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406}
3407
Christoph Hellwig620554e2005-06-19 01:27:33 +02003408static int orinoco_ioctl_getrate(struct net_device *dev,
3409 struct iw_request_info *info,
3410 struct iw_param *rrq,
3411 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412{
3413 struct orinoco_private *priv = netdev_priv(dev);
3414 hermes_t *hw = &priv->hw;
3415 int err = 0;
3416 int ratemode;
3417 int i;
3418 u16 val;
3419 unsigned long flags;
3420
3421 if (orinoco_lock(priv, &flags) != 0)
3422 return -EBUSY;
3423
3424 ratemode = priv->bitratemode;
3425
3426 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3427
3428 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3429 rrq->fixed = ! bitrate_table[ratemode].automatic;
3430 rrq->disabled = 0;
3431
3432 /* If the interface is running we try to find more about the
3433 current mode */
3434 if (netif_running(dev)) {
3435 err = hermes_read_wordrec(hw, USER_BAP,
3436 HERMES_RID_CURRENTTXRATE, &val);
3437 if (err)
3438 goto out;
3439
3440 switch (priv->firmware_type) {
3441 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3442 /* Note : in Lucent firmware, the return value of
3443 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3444 * and therefore is totally different from the
3445 * encoding of HERMES_RID_CNFTXRATECONTROL.
3446 * Don't forget that 6Mb/s is really 5.5Mb/s */
3447 if (val == 6)
3448 rrq->value = 5500000;
3449 else
3450 rrq->value = val * 1000000;
3451 break;
3452 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3453 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3454 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3455 if (bitrate_table[i].intersil_txratectrl == val) {
3456 ratemode = i;
3457 break;
3458 }
3459 if (i >= BITRATE_TABLE_SIZE)
3460 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3461 dev->name, val);
3462
3463 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3464 break;
3465 default:
3466 BUG();
3467 }
3468 }
3469
3470 out:
3471 orinoco_unlock(priv, &flags);
3472
3473 return err;
3474}
3475
Christoph Hellwig620554e2005-06-19 01:27:33 +02003476static int orinoco_ioctl_setpower(struct net_device *dev,
3477 struct iw_request_info *info,
3478 struct iw_param *prq,
3479 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480{
3481 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003482 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 unsigned long flags;
3484
3485 if (orinoco_lock(priv, &flags) != 0)
3486 return -EBUSY;
3487
3488 if (prq->disabled) {
3489 priv->pm_on = 0;
3490 } else {
3491 switch (prq->flags & IW_POWER_MODE) {
3492 case IW_POWER_UNICAST_R:
3493 priv->pm_mcast = 0;
3494 priv->pm_on = 1;
3495 break;
3496 case IW_POWER_ALL_R:
3497 priv->pm_mcast = 1;
3498 priv->pm_on = 1;
3499 break;
3500 case IW_POWER_ON:
3501 /* No flags : but we may have a value - Jean II */
3502 break;
3503 default:
3504 err = -EINVAL;
3505 }
3506 if (err)
3507 goto out;
3508
3509 if (prq->flags & IW_POWER_TIMEOUT) {
3510 priv->pm_on = 1;
3511 priv->pm_timeout = prq->value / 1000;
3512 }
3513 if (prq->flags & IW_POWER_PERIOD) {
3514 priv->pm_on = 1;
3515 priv->pm_period = prq->value / 1000;
3516 }
3517 /* It's valid to not have a value if we are just toggling
3518 * the flags... Jean II */
3519 if(!priv->pm_on) {
3520 err = -EINVAL;
3521 goto out;
3522 }
3523 }
3524
3525 out:
3526 orinoco_unlock(priv, &flags);
3527
3528 return err;
3529}
3530
Christoph Hellwig620554e2005-06-19 01:27:33 +02003531static int orinoco_ioctl_getpower(struct net_device *dev,
3532 struct iw_request_info *info,
3533 struct iw_param *prq,
3534 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535{
3536 struct orinoco_private *priv = netdev_priv(dev);
3537 hermes_t *hw = &priv->hw;
3538 int err = 0;
3539 u16 enable, period, timeout, mcast;
3540 unsigned long flags;
3541
3542 if (orinoco_lock(priv, &flags) != 0)
3543 return -EBUSY;
3544
3545 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3546 if (err)
3547 goto out;
3548
3549 err = hermes_read_wordrec(hw, USER_BAP,
3550 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3551 if (err)
3552 goto out;
3553
3554 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3555 if (err)
3556 goto out;
3557
3558 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3559 if (err)
3560 goto out;
3561
3562 prq->disabled = !enable;
3563 /* Note : by default, display the period */
3564 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3565 prq->flags = IW_POWER_TIMEOUT;
3566 prq->value = timeout * 1000;
3567 } else {
3568 prq->flags = IW_POWER_PERIOD;
3569 prq->value = period * 1000;
3570 }
3571 if (mcast)
3572 prq->flags |= IW_POWER_ALL_R;
3573 else
3574 prq->flags |= IW_POWER_UNICAST_R;
3575
3576 out:
3577 orinoco_unlock(priv, &flags);
3578
3579 return err;
3580}
3581
Christoph Hellwig620554e2005-06-19 01:27:33 +02003582static int orinoco_ioctl_getretry(struct net_device *dev,
3583 struct iw_request_info *info,
3584 struct iw_param *rrq,
3585 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586{
3587 struct orinoco_private *priv = netdev_priv(dev);
3588 hermes_t *hw = &priv->hw;
3589 int err = 0;
3590 u16 short_limit, long_limit, lifetime;
3591 unsigned long flags;
3592
3593 if (orinoco_lock(priv, &flags) != 0)
3594 return -EBUSY;
3595
3596 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3597 &short_limit);
3598 if (err)
3599 goto out;
3600
3601 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3602 &long_limit);
3603 if (err)
3604 goto out;
3605
3606 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3607 &lifetime);
3608 if (err)
3609 goto out;
3610
3611 rrq->disabled = 0; /* Can't be disabled */
3612
3613 /* Note : by default, display the retry number */
3614 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3615 rrq->flags = IW_RETRY_LIFETIME;
3616 rrq->value = lifetime * 1000; /* ??? */
3617 } else {
3618 /* By default, display the min number */
3619 if ((rrq->flags & IW_RETRY_MAX)) {
3620 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3621 rrq->value = long_limit;
3622 } else {
3623 rrq->flags = IW_RETRY_LIMIT;
3624 rrq->value = short_limit;
3625 if(short_limit != long_limit)
3626 rrq->flags |= IW_RETRY_MIN;
3627 }
3628 }
3629
3630 out:
3631 orinoco_unlock(priv, &flags);
3632
3633 return err;
3634}
3635
Christoph Hellwig620554e2005-06-19 01:27:33 +02003636static int orinoco_ioctl_reset(struct net_device *dev,
3637 struct iw_request_info *info,
3638 void *wrqu,
3639 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640{
3641 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003642
3643 if (! capable(CAP_NET_ADMIN))
3644 return -EPERM;
3645
3646 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3647 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3648
3649 /* Firmware reset */
3650 orinoco_reset(dev);
3651 } else {
3652 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3653
3654 schedule_work(&priv->reset_work);
3655 }
3656
3657 return 0;
3658}
3659
3660static int orinoco_ioctl_setibssport(struct net_device *dev,
3661 struct iw_request_info *info,
3662 void *wrqu,
3663 char *extra)
3664
3665{
3666 struct orinoco_private *priv = netdev_priv(dev);
3667 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 unsigned long flags;
3669
3670 if (orinoco_lock(priv, &flags) != 0)
3671 return -EBUSY;
3672
3673 priv->ibss_port = val ;
3674
3675 /* Actually update the mode we are using */
3676 set_port_type(priv);
3677
3678 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003679 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680}
3681
Christoph Hellwig620554e2005-06-19 01:27:33 +02003682static int orinoco_ioctl_getibssport(struct net_device *dev,
3683 struct iw_request_info *info,
3684 void *wrqu,
3685 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686{
3687 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003688 int *val = (int *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689
3690 *val = priv->ibss_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 return 0;
3692}
3693
Christoph Hellwig620554e2005-06-19 01:27:33 +02003694static int orinoco_ioctl_setport3(struct net_device *dev,
3695 struct iw_request_info *info,
3696 void *wrqu,
3697 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698{
3699 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003700 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 int err = 0;
3702 unsigned long flags;
3703
3704 if (orinoco_lock(priv, &flags) != 0)
3705 return -EBUSY;
3706
3707 switch (val) {
3708 case 0: /* Try to do IEEE ad-hoc mode */
3709 if (! priv->has_ibss) {
3710 err = -EINVAL;
3711 break;
3712 }
3713 priv->prefer_port3 = 0;
3714
3715 break;
3716
3717 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3718 if (! priv->has_port3) {
3719 err = -EINVAL;
3720 break;
3721 }
3722 priv->prefer_port3 = 1;
3723 break;
3724
3725 default:
3726 err = -EINVAL;
3727 }
3728
Christoph Hellwig620554e2005-06-19 01:27:33 +02003729 if (! err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 /* Actually update the mode we are using */
3731 set_port_type(priv);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003732 err = -EINPROGRESS;
3733 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734
3735 orinoco_unlock(priv, &flags);
3736
3737 return err;
3738}
3739
Christoph Hellwig620554e2005-06-19 01:27:33 +02003740static int orinoco_ioctl_getport3(struct net_device *dev,
3741 struct iw_request_info *info,
3742 void *wrqu,
3743 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744{
3745 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003746 int *val = (int *) extra;
3747
3748 *val = priv->prefer_port3;
3749 return 0;
3750}
3751
3752static int orinoco_ioctl_setpreamble(struct net_device *dev,
3753 struct iw_request_info *info,
3754 void *wrqu,
3755 char *extra)
3756{
3757 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003759 int val;
3760
3761 if (! priv->has_preamble)
3762 return -EOPNOTSUPP;
3763
3764 /* 802.11b has recently defined some short preamble.
3765 * Basically, the Phy header has been reduced in size.
3766 * This increase performance, especially at high rates
3767 * (the preamble is transmitted at 1Mb/s), unfortunately
3768 * this give compatibility troubles... - Jean II */
3769 val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770
3771 if (orinoco_lock(priv, &flags) != 0)
3772 return -EBUSY;
3773
Christoph Hellwig620554e2005-06-19 01:27:33 +02003774 if (val)
3775 priv->preamble = 1;
3776 else
3777 priv->preamble = 0;
3778
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003780
3781 return -EINPROGRESS; /* Call commit handler */
3782}
3783
3784static int orinoco_ioctl_getpreamble(struct net_device *dev,
3785 struct iw_request_info *info,
3786 void *wrqu,
3787 char *extra)
3788{
3789 struct orinoco_private *priv = netdev_priv(dev);
3790 int *val = (int *) extra;
3791
3792 if (! priv->has_preamble)
3793 return -EOPNOTSUPP;
3794
3795 *val = priv->preamble;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 return 0;
3797}
3798
Christoph Hellwig620554e2005-06-19 01:27:33 +02003799/* ioctl interface to hermes_read_ltv()
3800 * To use with iwpriv, pass the RID as the token argument, e.g.
3801 * iwpriv get_rid [0xfc00]
3802 * At least Wireless Tools 25 is required to use iwpriv.
3803 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3804static int orinoco_ioctl_getrid(struct net_device *dev,
3805 struct iw_request_info *info,
3806 struct iw_point *data,
3807 char *extra)
3808{
3809 struct orinoco_private *priv = netdev_priv(dev);
3810 hermes_t *hw = &priv->hw;
3811 int rid = data->flags;
3812 u16 length;
3813 int err;
3814 unsigned long flags;
3815
3816 /* It's a "get" function, but we don't want users to access the
3817 * WEP key and other raw firmware data */
3818 if (! capable(CAP_NET_ADMIN))
3819 return -EPERM;
3820
3821 if (rid < 0xfc00 || rid > 0xffff)
3822 return -EINVAL;
3823
3824 if (orinoco_lock(priv, &flags) != 0)
3825 return -EBUSY;
3826
3827 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3828 extra);
3829 if (err)
3830 goto out;
3831
3832 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3833 MAX_RID_LEN);
3834
3835 out:
3836 orinoco_unlock(priv, &flags);
3837 return err;
3838}
3839
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003840/* Trigger a scan (look for other cells in the vicinity */
3841static int orinoco_ioctl_setscan(struct net_device *dev,
3842 struct iw_request_info *info,
3843 struct iw_param *srq,
3844 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845{
3846 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003847 hermes_t *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 unsigned long flags;
3850
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003851 /* Note : you may have realised that, as this is a SET operation,
3852 * this is priviledged and therefore a normal user can't
3853 * perform scanning.
3854 * This is not an error, while the device perform scanning,
3855 * traffic doesn't flow, so it's a perfect DoS...
3856 * Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003858 if (orinoco_lock(priv, &flags) != 0)
3859 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003861 /* Scanning with port 0 disabled would fail */
3862 if (!netif_running(dev)) {
3863 err = -ENETDOWN;
3864 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003867 /* In monitor mode, the scan results are always empty.
3868 * Probe responses are passed to the driver as received
3869 * frames and could be processed in software. */
3870 if (priv->iw_mode == IW_MODE_MONITOR) {
3871 err = -EOPNOTSUPP;
3872 goto out;
3873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003875 /* Note : because we don't lock out the irq handler, the way
3876 * we access scan variables in priv is critical.
3877 * o scan_inprogress : not touched by irq handler
3878 * o scan_mode : not touched by irq handler
3879 * o scan_result : irq is strict producer, non-irq is strict
3880 * consumer.
3881 * o scan_len : synchronised with scan_result
3882 * Before modifying anything on those variables, please think hard !
3883 * Jean II */
3884
3885 /* If there is still some left-over scan results, get rid of it */
3886 if (priv->scan_result != NULL) {
3887 /* What's likely is that a client did crash or was killed
3888 * between triggering the scan request and reading the
3889 * results, so we need to reset everything.
3890 * Some clients that are too slow may suffer from that...
3891 * Jean II */
3892 kfree(priv->scan_result);
3893 priv->scan_result = NULL;
3894 }
3895
3896 /* Save flags */
3897 priv->scan_mode = srq->flags;
3898
3899 /* Always trigger scanning, even if it's in progress.
3900 * This way, if the info frame get lost, we will recover somewhat
3901 * gracefully - Jean II */
3902
3903 if (priv->has_hostscan) {
3904 switch (priv->firmware_type) {
3905 case FIRMWARE_TYPE_SYMBOL:
3906 err = hermes_write_wordrec(hw, USER_BAP,
3907 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3908 HERMES_HOSTSCAN_SYMBOL_ONCE |
3909 HERMES_HOSTSCAN_SYMBOL_BCAST);
3910 break;
3911 case FIRMWARE_TYPE_INTERSIL: {
Pavel Roskind133ae42005-09-23 04:18:06 -04003912 __le16 req[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003913
3914 req[0] = cpu_to_le16(0x3fff); /* All channels */
3915 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3916 req[2] = 0; /* Any ESSID */
3917 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3918 HERMES_RID_CNFHOSTSCAN, &req);
3919 }
3920 break;
3921 case FIRMWARE_TYPE_AGERE:
3922 err = hermes_write_wordrec(hw, USER_BAP,
3923 HERMES_RID_CNFSCANSSID_AGERE,
3924 0); /* Any ESSID */
3925 if (err)
3926 break;
3927
3928 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3929 break;
3930 }
3931 } else
3932 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3933
3934 /* One more client */
3935 if (! err)
3936 priv->scan_inprogress = 1;
3937
3938 out:
3939 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 return err;
3941}
3942
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003943/* Translate scan data returned from the card to a card independant
Pavel Roskin70817c42005-09-01 20:02:50 -04003944 * format that the Wireless Tools will understand - Jean II
3945 * Return message length or -errno for fatal errors */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003946static inline int orinoco_translate_scan(struct net_device *dev,
3947 char *buffer,
3948 char *scan,
3949 int scan_len)
3950{
3951 struct orinoco_private *priv = netdev_priv(dev);
3952 int offset; /* In the scan data */
3953 union hermes_scan_info *atom;
3954 int atom_len;
3955 u16 capabilities;
3956 u16 channel;
3957 struct iw_event iwe; /* Temporary buffer */
3958 char * current_ev = buffer;
3959 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3960
3961 switch (priv->firmware_type) {
3962 case FIRMWARE_TYPE_AGERE:
3963 atom_len = sizeof(struct agere_scan_apinfo);
3964 offset = 0;
3965 break;
3966 case FIRMWARE_TYPE_SYMBOL:
3967 /* Lack of documentation necessitates this hack.
3968 * Different firmwares have 68 or 76 byte long atoms.
3969 * We try modulo first. If the length divides by both,
3970 * we check what would be the channel in the second
3971 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3972 * Valid channel cannot be 0. */
3973 if (scan_len % 76)
3974 atom_len = 68;
3975 else if (scan_len % 68)
3976 atom_len = 76;
3977 else if (scan_len >= 1292 && scan[68] == 0)
3978 atom_len = 76;
3979 else
3980 atom_len = 68;
3981 offset = 0;
3982 break;
3983 case FIRMWARE_TYPE_INTERSIL:
3984 offset = 4;
Pavel Roskin70817c42005-09-01 20:02:50 -04003985 if (priv->has_hostscan) {
Pavel Roskind133ae42005-09-23 04:18:06 -04003986 atom_len = le16_to_cpup((__le16 *)scan);
Pavel Roskin70817c42005-09-01 20:02:50 -04003987 /* Sanity check for atom_len */
3988 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3989 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3990 dev->name, atom_len);
3991 return -EIO;
3992 }
3993 } else
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003994 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3995 break;
3996 default:
Pavel Roskin70817c42005-09-01 20:02:50 -04003997 return -EOPNOTSUPP;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003998 }
3999
4000 /* Check that we got an whole number of atoms */
4001 if ((scan_len - offset) % atom_len) {
4002 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4003 "atom_len %d, offset %d\n", dev->name, scan_len,
4004 atom_len, offset);
Pavel Roskin70817c42005-09-01 20:02:50 -04004005 return -EIO;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004006 }
4007
4008 /* Read the entries one by one */
4009 for (; offset + atom_len <= scan_len; offset += atom_len) {
4010 /* Get next atom */
4011 atom = (union hermes_scan_info *) (scan + offset);
4012
4013 /* First entry *MUST* be the AP MAC address */
4014 iwe.cmd = SIOCGIWAP;
4015 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4016 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4017 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4018
4019 /* Other entries will be displayed in the order we give them */
4020
4021 /* Add the ESSID */
4022 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4023 if (iwe.u.data.length > 32)
4024 iwe.u.data.length = 32;
4025 iwe.cmd = SIOCGIWESSID;
4026 iwe.u.data.flags = 1;
4027 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4028
4029 /* Add mode */
4030 iwe.cmd = SIOCGIWMODE;
4031 capabilities = le16_to_cpu(atom->a.capabilities);
4032 if (capabilities & 0x3) {
4033 if (capabilities & 0x1)
4034 iwe.u.mode = IW_MODE_MASTER;
4035 else
4036 iwe.u.mode = IW_MODE_ADHOC;
4037 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4038 }
4039
4040 channel = atom->s.channel;
4041 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4042 /* Add frequency */
4043 iwe.cmd = SIOCGIWFREQ;
4044 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4045 iwe.u.freq.e = 1;
4046 current_ev = iwe_stream_add_event(current_ev, end_buf,
4047 &iwe, IW_EV_FREQ_LEN);
4048 }
4049
4050 /* Add quality statistics */
4051 iwe.cmd = IWEVQUAL;
4052 iwe.u.qual.updated = 0x10; /* no link quality */
4053 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4054 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4055 /* Wireless tools prior to 27.pre22 will show link quality
4056 * anyway, so we provide a reasonable value. */
4057 if (iwe.u.qual.level > iwe.u.qual.noise)
4058 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4059 else
4060 iwe.u.qual.qual = 0;
4061 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4062
4063 /* Add encryption capability */
4064 iwe.cmd = SIOCGIWENCODE;
4065 if (capabilities & 0x10)
4066 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4067 else
4068 iwe.u.data.flags = IW_ENCODE_DISABLED;
4069 iwe.u.data.length = 0;
4070 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4071
4072 /* Bit rate is not available in Lucent/Agere firmwares */
4073 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4074 char * current_val = current_ev + IW_EV_LCP_LEN;
4075 int i;
4076 int step;
4077
4078 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4079 step = 2;
4080 else
4081 step = 1;
4082
4083 iwe.cmd = SIOCGIWRATE;
4084 /* Those two flags are ignored... */
4085 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4086 /* Max 10 values */
4087 for (i = 0; i < 10; i += step) {
4088 /* NULL terminated */
4089 if (atom->p.rates[i] == 0x0)
4090 break;
4091 /* Bit rate given in 500 kb/s units (+ 0x80) */
4092 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4093 current_val = iwe_stream_add_value(current_ev, current_val,
4094 end_buf, &iwe,
4095 IW_EV_PARAM_LEN);
4096 }
4097 /* Check if we added any event */
4098 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4099 current_ev = current_val;
4100 }
4101
4102 /* The other data in the scan result are not really
4103 * interesting, so for now drop it - Jean II */
4104 }
4105 return current_ev - buffer;
4106}
4107
4108/* Return results of a scan */
4109static int orinoco_ioctl_getscan(struct net_device *dev,
4110 struct iw_request_info *info,
4111 struct iw_point *srq,
4112 char *extra)
4113{
4114 struct orinoco_private *priv = netdev_priv(dev);
4115 int err = 0;
4116 unsigned long flags;
4117
4118 if (orinoco_lock(priv, &flags) != 0)
4119 return -EBUSY;
4120
4121 /* If no results yet, ask to try again later */
4122 if (priv->scan_result == NULL) {
4123 if (priv->scan_inprogress)
4124 /* Important note : we don't want to block the caller
4125 * until results are ready for various reasons.
4126 * First, managing wait queues is complex and racy.
4127 * Second, we grab some rtnetlink lock before comming
4128 * here (in dev_ioctl()).
4129 * Third, we generate an Wireless Event, so the
4130 * caller can wait itself on that - Jean II */
4131 err = -EAGAIN;
4132 else
4133 /* Client error, no scan results...
4134 * The caller need to restart the scan. */
4135 err = -ENODATA;
4136 } else {
4137 /* We have some results to push back to user space */
4138
4139 /* Translate to WE format */
Pavel Roskin70817c42005-09-01 20:02:50 -04004140 int ret = orinoco_translate_scan(dev, extra,
4141 priv->scan_result,
4142 priv->scan_len);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004143
Pavel Roskin70817c42005-09-01 20:02:50 -04004144 if (ret < 0) {
4145 err = ret;
4146 kfree(priv->scan_result);
4147 priv->scan_result = NULL;
4148 } else {
4149 srq->length = ret;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004150
Pavel Roskin70817c42005-09-01 20:02:50 -04004151 /* Return flags */
4152 srq->flags = (__u16) priv->scan_mode;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004153
Pavel Roskin70817c42005-09-01 20:02:50 -04004154 /* In any case, Scan results will be cleaned up in the
4155 * reset function and when exiting the driver.
4156 * The person triggering the scanning may never come to
4157 * pick the results, so we need to do it in those places.
4158 * Jean II */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004159
4160#ifdef SCAN_SINGLE_READ
Pavel Roskin70817c42005-09-01 20:02:50 -04004161 /* If you enable this option, only one client (the first
4162 * one) will be able to read the result (and only one
4163 * time). If there is multiple concurent clients that
4164 * want to read scan results, this behavior is not
4165 * advisable - Jean II */
4166 kfree(priv->scan_result);
4167 priv->scan_result = NULL;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004168#endif /* SCAN_SINGLE_READ */
Pavel Roskin70817c42005-09-01 20:02:50 -04004169 /* Here, if too much time has elapsed since last scan,
4170 * we may want to clean up scan results... - Jean II */
4171 }
4172
4173 /* Scan is no longer in progress */
4174 priv->scan_inprogress = 0;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004175 }
4176
4177 orinoco_unlock(priv, &flags);
4178 return err;
4179}
4180
Christoph Hellwig620554e2005-06-19 01:27:33 +02004181/* Commit handler, called after set operations */
4182static int orinoco_ioctl_commit(struct net_device *dev,
4183 struct iw_request_info *info,
4184 void *wrqu,
4185 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186{
4187 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004188 struct hermes *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004190 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191
Christoph Hellwig620554e2005-06-19 01:27:33 +02004192 if (!priv->open)
4193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194
Christoph Hellwig620554e2005-06-19 01:27:33 +02004195 if (priv->broken_disableport) {
4196 orinoco_reset(dev);
4197 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199
Christoph Hellwig620554e2005-06-19 01:27:33 +02004200 if (orinoco_lock(priv, &flags) != 0)
4201 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202
Christoph Hellwig620554e2005-06-19 01:27:33 +02004203 err = hermes_disable_port(hw, 0);
4204 if (err) {
4205 printk(KERN_WARNING "%s: Unable to disable port "
4206 "while reconfiguring card\n", dev->name);
4207 priv->broken_disableport = 1;
4208 goto out;
4209 }
4210
4211 err = __orinoco_program_rids(dev);
4212 if (err) {
4213 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4214 dev->name);
4215 goto out;
4216 }
4217
4218 err = hermes_enable_port(hw, 0);
4219 if (err) {
4220 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4221 dev->name);
4222 goto out;
4223 }
4224
4225 out:
4226 if (err) {
4227 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4228 schedule_work(&priv->reset_work);
4229 err = 0;
4230 }
4231
4232 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 return err;
4234}
4235
Christoph Hellwig620554e2005-06-19 01:27:33 +02004236static const struct iw_priv_args orinoco_privtab[] = {
4237 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4238 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4239 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4240 0, "set_port3" },
4241 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4242 "get_port3" },
4243 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4244 0, "set_preamble" },
4245 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4246 "get_preamble" },
4247 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4248 0, "set_ibssport" },
4249 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4250 "get_ibssport" },
4251 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4252 "get_rid" },
4253};
4254
4255
4256/*
4257 * Structures to export the Wireless Handlers
4258 */
4259
4260static const iw_handler orinoco_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004261 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4262 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4263 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4264 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4265 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4266 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4267 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4268 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4269 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
Pavel Roskin343c6862005-09-09 18:43:02 -04004270 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4271 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4272 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4273 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004274 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4275 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4276 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4277 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4278 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4279 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4280 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4281 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4282 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4283 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4284 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4285 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4286 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4287 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4288 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4289 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4290 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4291 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4292 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004293};
4294
4295
4296/*
4297 Added typecasting since we no longer use iwreq_data -- Moustafa
4298 */
4299static const iw_handler orinoco_private_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004300 [0] = (iw_handler) orinoco_ioctl_reset,
4301 [1] = (iw_handler) orinoco_ioctl_reset,
4302 [2] = (iw_handler) orinoco_ioctl_setport3,
4303 [3] = (iw_handler) orinoco_ioctl_getport3,
4304 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4305 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4306 [6] = (iw_handler) orinoco_ioctl_setibssport,
4307 [7] = (iw_handler) orinoco_ioctl_getibssport,
4308 [9] = (iw_handler) orinoco_ioctl_getrid,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004309};
4310
4311static const struct iw_handler_def orinoco_handler_def = {
4312 .num_standard = ARRAY_SIZE(orinoco_handler),
4313 .num_private = ARRAY_SIZE(orinoco_private_handler),
4314 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4315 .standard = orinoco_handler,
4316 .private = orinoco_private_handler,
4317 .private_args = orinoco_privtab,
Pavel Roskin343c6862005-09-09 18:43:02 -04004318 .get_wireless_stats = orinoco_get_wireless_stats,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004319};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004321static void orinoco_get_drvinfo(struct net_device *dev,
4322 struct ethtool_drvinfo *info)
4323{
4324 struct orinoco_private *priv = netdev_priv(dev);
4325
4326 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4327 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4328 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4329 if (dev->class_dev.dev)
4330 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4331 sizeof(info->bus_info) - 1);
4332 else
4333 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4334 "PCMCIA %p", priv->hw.iobase);
4335}
4336
4337static struct ethtool_ops orinoco_ethtool_ops = {
4338 .get_drvinfo = orinoco_get_drvinfo,
4339 .get_link = ethtool_op_get_link,
4340};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341
4342/********************************************************************/
4343/* Debugging */
4344/********************************************************************/
4345
4346#if 0
4347static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4348{
4349 printk(KERN_DEBUG "RX descriptor:\n");
4350 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4351 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4352 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4353 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4354 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4355 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4356 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4357
4358 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4359 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4360 frame->p80211.frame_ctl);
4361 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4362 frame->p80211.duration_id);
4363 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4364 frame->p80211.addr1[0], frame->p80211.addr1[1],
4365 frame->p80211.addr1[2], frame->p80211.addr1[3],
4366 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4367 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4368 frame->p80211.addr2[0], frame->p80211.addr2[1],
4369 frame->p80211.addr2[2], frame->p80211.addr2[3],
4370 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4371 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4372 frame->p80211.addr3[0], frame->p80211.addr3[1],
4373 frame->p80211.addr3[2], frame->p80211.addr3[3],
4374 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4375 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4376 frame->p80211.seq_ctl);
4377 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4378 frame->p80211.addr4[0], frame->p80211.addr4[1],
4379 frame->p80211.addr4[2], frame->p80211.addr4[3],
4380 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4381 printk(KERN_DEBUG " data_len = 0x%04x\n",
4382 frame->p80211.data_len);
4383
4384 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4385 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4386 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4387 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4388 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4389 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4390 frame->p8023.h_source[0], frame->p8023.h_source[1],
4391 frame->p8023.h_source[2], frame->p8023.h_source[3],
4392 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4393 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4394
4395 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4396 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4397 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4398 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4399 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4400 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4401 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4402}
4403#endif /* 0 */
4404
4405/********************************************************************/
4406/* Module initialization */
4407/********************************************************************/
4408
4409EXPORT_SYMBOL(alloc_orinocodev);
4410EXPORT_SYMBOL(free_orinocodev);
4411
4412EXPORT_SYMBOL(__orinoco_up);
4413EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414EXPORT_SYMBOL(orinoco_reinit_firmware);
4415
4416EXPORT_SYMBOL(orinoco_interrupt);
4417
4418/* Can't be declared "const" or the whole __initdata section will
4419 * become const */
4420static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4421 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4422 "Pavel Roskin <proski@gnu.org>, et al)";
4423
4424static int __init init_orinoco(void)
4425{
4426 printk(KERN_DEBUG "%s\n", version);
4427 return 0;
4428}
4429
4430static void __exit exit_orinoco(void)
4431{
4432}
4433
4434module_init(init_orinoco);
4435module_exit(exit_orinoco);