aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/wireless
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/net/wireless')
-rw-r--r--drivers/net/wireless/Kconfig365
-rw-r--r--drivers/net/wireless/Makefile33
-rw-r--r--drivers/net/wireless/README25
-rw-r--r--drivers/net/wireless/airo.c7667
-rw-r--r--drivers/net/wireless/airo_cs.c622
-rw-r--r--drivers/net/wireless/airport.c304
-rw-r--r--drivers/net/wireless/arlan-main.c1896
-rw-r--r--drivers/net/wireless/arlan-proc.c1262
-rw-r--r--drivers/net/wireless/arlan.h541
-rw-r--r--drivers/net/wireless/atmel.c4272
-rw-r--r--drivers/net/wireless/atmel.h43
-rw-r--r--drivers/net/wireless/atmel_cs.c708
-rw-r--r--drivers/net/wireless/atmel_pci.c89
-rw-r--r--drivers/net/wireless/hermes.c554
-rw-r--r--drivers/net/wireless/hermes.h481
-rw-r--r--drivers/net/wireless/hermes_rid.h148
-rw-r--r--drivers/net/wireless/i82586.h413
-rw-r--r--drivers/net/wireless/i82593.h224
-rw-r--r--drivers/net/wireless/ieee802_11.h78
-rw-r--r--drivers/net/wireless/netwave_cs.c1736
-rw-r--r--drivers/net/wireless/orinoco.c4243
-rw-r--r--drivers/net/wireless/orinoco.h153
-rw-r--r--drivers/net/wireless/orinoco_cs.c636
-rw-r--r--drivers/net/wireless/orinoco_pci.c417
-rw-r--r--drivers/net/wireless/orinoco_plx.c419
-rw-r--r--drivers/net/wireless/orinoco_tmd.c276
-rw-r--r--drivers/net/wireless/prism54/Makefile8
-rw-r--r--drivers/net/wireless/prism54/isl_38xx.c260
-rw-r--r--drivers/net/wireless/prism54/isl_38xx.h173
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c2750
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.h51
-rw-r--r--drivers/net/wireless/prism54/isl_oid.h507
-rw-r--r--drivers/net/wireless/prism54/islpci_dev.c956
-rw-r--r--drivers/net/wireless/prism54/islpci_dev.h216
-rw-r--r--drivers/net/wireless/prism54/islpci_eth.c519
-rw-r--r--drivers/net/wireless/prism54/islpci_eth.h73
-rw-r--r--drivers/net/wireless/prism54/islpci_hotplug.c339
-rw-r--r--drivers/net/wireless/prism54/islpci_mgt.c513
-rw-r--r--drivers/net/wireless/prism54/islpci_mgt.h145
-rw-r--r--drivers/net/wireless/prism54/oid_mgt.c907
-rw-r--r--drivers/net/wireless/prism54/oid_mgt.h59
-rw-r--r--drivers/net/wireless/prism54/prismcompat.h44
-rw-r--r--drivers/net/wireless/ray_cs.c2957
-rw-r--r--drivers/net/wireless/ray_cs.h78
-rw-r--r--drivers/net/wireless/rayctl.h732
-rw-r--r--drivers/net/wireless/strip.c2843
-rw-r--r--drivers/net/wireless/todo.txt15
-rw-r--r--drivers/net/wireless/wavelan.c4452
-rw-r--r--drivers/net/wireless/wavelan.h370
-rw-r--r--drivers/net/wireless/wavelan.p.h716
-rw-r--r--drivers/net/wireless/wavelan_cs.c4914
-rw-r--r--drivers/net/wireless/wavelan_cs.h386
-rw-r--r--drivers/net/wireless/wavelan_cs.p.h813
-rw-r--r--drivers/net/wireless/wl3501.h614
-rw-r--r--drivers/net/wireless/wl3501_cs.c2270
55 files changed, 56285 insertions, 0 deletions
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
new file mode 100644
index 000000000000..0aaa12c0c098
--- /dev/null
+++ b/drivers/net/wireless/Kconfig
@@ -0,0 +1,365 @@
+#
+# Wireless LAN device configuration
+#
+
+menu "Wireless LAN (non-hamradio)"
+ depends on NETDEVICES
+
+config NET_RADIO
+ bool "Wireless LAN drivers (non-hamradio) & Wireless Extensions"
+ ---help---
+ Support for wireless LANs and everything having to do with radio,
+ but not with amateur radio or FM broadcasting.
+
+ Saying Y here also enables the Wireless Extensions (creates
+ /proc/net/wireless and enables iwconfig access). The Wireless
+ Extension is a generic API allowing a driver to expose to the user
+ space configuration and statistics specific to common Wireless LANs.
+ The beauty of it is that a single set of tool can support all the
+ variations of Wireless LANs, regardless of their type (as long as
+ the driver supports Wireless Extension). Another advantage is that
+ these parameters may be changed on the fly without restarting the
+ driver (or Linux). If you wish to use Wireless Extensions with
+ wireless PCMCIA (PC-) cards, you need to say Y here; you can fetch
+ the tools from
+ <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>.
+
+ Some user-level drivers for scarab devices which don't require
+ special kernel support are available from
+ <ftp://shadow.cabi.net/pub/Linux/>.
+
+# Note : the cards are obsolete (can't buy them anymore), but the drivers
+# are not, as people are still using them...
+comment "Obsolete Wireless cards support (pre-802.11)"
+ depends on NET_RADIO && (INET || ISA || PCMCIA)
+
+config STRIP
+ tristate "STRIP (Metricom starmode radio IP)"
+ depends on NET_RADIO && INET
+ ---help---
+ Say Y if you have a Metricom radio and intend to use Starmode Radio
+ IP. STRIP is a radio protocol developed for the MosquitoNet project
+ (on the WWW at <http://mosquitonet.stanford.edu/>) to send Internet
+ traffic using Metricom radios. Metricom radios are small, battery
+ powered, 100kbit/sec packet radio transceivers, about the size and
+ weight of a cellular telephone. (You may also have heard them called
+ "Metricom modems" but we avoid the term "modem" because it misleads
+ many people into thinking that you can plug a Metricom modem into a
+ phone line and use it as a modem.)
+
+ You can use STRIP on any Linux machine with a serial port, although
+ it is obviously most useful for people with laptop computers. If you
+ think you might get a Metricom radio in the future, there is no harm
+ in saying Y to STRIP now, except that it makes the kernel a bit
+ bigger.
+
+ To compile this as a module, choose M here: the module will be
+ called strip.
+
+config ARLAN
+ tristate "Aironet Arlan 655 & IC2200 DS support"
+ depends on NET_RADIO && ISA && !64BIT
+ ---help---
+ Aironet makes Arlan, a class of wireless LAN adapters. These use the
+ www.Telxon.com chip, which is also used on several similar cards.
+ This driver is tested on the 655 and IC2200 series cards. Look at
+ <http://www.ylenurme.ee/~elmer/655/> for the latest information.
+
+ The driver is built as two modules, arlan and arlan-proc. The latter
+ is the /proc interface and is not needed most of time.
+
+ On some computers the card ends up in non-valid state after some
+ time. Use a ping-reset script to clear it.
+
+config WAVELAN
+ tristate "AT&T/Lucent old WaveLAN & DEC RoamAbout DS ISA support"
+ depends on NET_RADIO && ISA
+ ---help---
+ The Lucent WaveLAN (formerly NCR and AT&T; or DEC RoamAbout DS) is
+ a Radio LAN (wireless Ethernet-like Local Area Network) using the
+ radio frequencies 900 MHz and 2.4 GHz.
+
+ This driver support the ISA version of the WaveLAN card. A separate
+ driver for the PCMCIA (PC-card) hardware is available in David
+ Hinds' pcmcia-cs package (see the file <file:Documentation/Changes>
+ for location).
+
+ If you want to use an ISA WaveLAN card under Linux, say Y and read
+ the Ethernet-HOWTO, available from
+ <http://www.tldp.org/docs.html#howto>. Some more specific
+ information is contained in
+ <file:Documentation/networking/wavelan.txt> and in the source code
+ <file:drivers/net/wavelan.p.h>.
+
+ You will also need the wireless tools package available from
+ <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>.
+ Please read the man pages contained therein.
+
+ To compile this driver as a module, choose M here: the module will be
+ called wavelan.
+
+config PCMCIA_WAVELAN
+ tristate "AT&T/Lucent old WaveLAN Pcmcia wireless support"
+ depends on NET_RADIO && PCMCIA
+ help
+ Say Y here if you intend to attach an AT&T/Lucent Wavelan PCMCIA
+ (PC-card) wireless Ethernet networking card to your computer. This
+ driver is for the non-IEEE-802.11 Wavelan cards.
+
+ To compile this driver as a module, choose M here: the module will be
+ called wavelan_cs. If unsure, say N.
+
+config PCMCIA_NETWAVE
+ tristate "Xircom Netwave AirSurfer Pcmcia wireless support"
+ depends on NET_RADIO && PCMCIA
+ help
+ Say Y here if you intend to attach this type of PCMCIA (PC-card)
+ wireless Ethernet networking card to your computer.
+
+ To compile this driver as a module, choose M here: the module will be
+ called netwave_cs. If unsure, say N.
+
+comment "Wireless 802.11 Frequency Hopping cards support"
+ depends on NET_RADIO && PCMCIA
+
+config PCMCIA_RAYCS
+ tristate "Aviator/Raytheon 2.4MHz wireless support"
+ depends on NET_RADIO && PCMCIA
+ ---help---
+ Say Y here if you intend to attach an Aviator/Raytheon PCMCIA
+ (PC-card) wireless Ethernet networking card to your computer.
+ Please read the file <file:Documentation/networking/ray_cs.txt> for
+ details.
+
+ To compile this driver as a module, choose M here: the module will be
+ called ray_cs. If unsure, say N.
+
+comment "Wireless 802.11b ISA/PCI cards support"
+ depends on NET_RADIO && (ISA || PCI || PPC_PMAC || PCMCIA)
+
+config AIRO
+ tristate "Cisco/Aironet 34X/35X/4500/4800 ISA and PCI cards"
+ depends on NET_RADIO && ISA && (PCI || BROKEN)
+ ---help---
+ This is the standard Linux driver to support Cisco/Aironet ISA and
+ PCI 802.11 wireless cards.
+ It supports the new 802.11b cards from Cisco (Cisco 34X, Cisco 35X
+ - with or without encryption) as well as card before the Cisco
+ aquisition (Aironet 4500, Aironet 4800, Aironet 4800B).
+
+ This driver support both the standard Linux Wireless Extensions
+ and Cisco proprietary API, so both the Linux Wireless Tools and the
+ Cisco Linux utilities can be used to configure the card.
+
+ The driver can be compiled as a module and will be named "airo".
+
+config HERMES
+ tristate "Hermes chipset 802.11b support (Orinoco/Prism2/Symbol)"
+ depends on NET_RADIO && (PPC_PMAC || PCI || PCMCIA)
+ ---help---
+ A driver for 802.11b wireless cards based based on the "Hermes" or
+ Intersil HFA384x (Prism 2) MAC controller. This includes the vast
+ majority of the PCMCIA 802.11b cards (which are nearly all rebadges)
+ - except for the Cisco/Aironet cards. Cards supported include the
+ Apple Airport (not a PCMCIA card), WavelanIEEE/Orinoco,
+ Cabletron/EnteraSys Roamabout, ELSA AirLancer, MELCO Buffalo, Avaya,
+ IBM High Rate Wireless, Farralon Syyline, Samsung MagicLAN, Netgear
+ MA401, LinkSys WPC-11, D-Link DWL-650, 3Com AirConnect, Intel
+ PRO/Wireless, and Symbol Spectrum24 High Rate amongst others.
+
+ This option includes the guts of the driver, but in order to
+ actually use a card you will also need to enable support for PCMCIA
+ Hermes cards, PLX9052 based PCI adaptors or the Apple Airport below.
+
+ You will also very likely also need the Wireless Tools in order to
+ configure your card and that /etc/pcmcia/wireless.opts works :
+ <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>
+
+config APPLE_AIRPORT
+ tristate "Apple Airport support (built-in)"
+ depends on PPC_PMAC && HERMES
+ help
+ Say Y here to support the Airport 802.11b wireless Ethernet hardware
+ built into the Macintosh iBook and other recent PowerPC-based
+ Macintosh machines. This is essentially a Lucent Orinoco card with
+ a non-standard interface
+
+config PLX_HERMES
+ tristate "Hermes in PLX9052 based PCI adaptor support (Netgear MA301 etc.) (EXPERIMENTAL)"
+ depends on PCI && HERMES && EXPERIMENTAL
+ help
+ Enable support for PCMCIA cards supported by the "Hermes" (aka
+ orinoco) driver when used in PLX9052 based PCI adaptors. These
+ adaptors are not a full PCMCIA controller but act as a more limited
+ PCI <-> PCMCIA bridge. Several vendors sell such adaptors so that
+ 802.11b PCMCIA cards can be used in desktop machines. The Netgear
+ MA301 is such an adaptor.
+
+ Support for these adaptors is so far still incomplete and buggy.
+ You have been warned.
+
+config TMD_HERMES
+ tristate "Hermes in TMD7160 based PCI adaptor support (EXPERIMENTAL)"
+ depends on PCI && HERMES && EXPERIMENTAL
+ help
+ Enable support for PCMCIA cards supported by the "Hermes" (aka
+ orinoco) driver when used in TMD7160 based PCI adaptors. These
+ adaptors are not a full PCMCIA controller but act as a more limited
+ PCI <-> PCMCIA bridge. Several vendors sell such adaptors so that
+ 802.11b PCMCIA cards can be used in desktop machines.
+
+ Support for these adaptors is so far still incomplete and buggy.
+ You have been warned.
+
+config PCI_HERMES
+ tristate "Prism 2.5 PCI 802.11b adaptor support (EXPERIMENTAL)"
+ depends on PCI && HERMES && EXPERIMENTAL
+ help
+ Enable support for PCI and mini-PCI 802.11b wireless NICs based on
+ the Prism 2.5 chipset. These are true PCI cards, not the 802.11b
+ PCMCIA cards bundled with PCI<->PCMCIA adaptors which are also
+ common. Some of the built-in wireless adaptors in laptops are of
+ this variety.
+
+config ATMEL
+ tristate "Atmel at76c50x chipset 802.11b support"
+ depends on NET_RADIO && EXPERIMENTAL
+ select FW_LOADER
+ select CRC32
+ ---help---
+ A driver 802.11b wireless cards based on the Atmel fast-vnet
+ chips. This driver supports standard Linux wireless extensions.
+
+ Many cards based on this chipset do not have flash memory
+ and need their firmware loaded at start-up. If yours is
+ one of these, you will need to provide a firmware image
+ to be loaded into the card by the driver. The Atmel
+ firmware package can be downloaded from
+ <http://www.thekelleys.org.uk/atmel>
+
+config PCI_ATMEL
+ tristate "Atmel at76c506 PCI cards"
+ depends on ATMEL && PCI
+ ---help---
+ Enable support for PCI and mini-PCI cards containing the
+ Atmel at76c506 chip.
+
+# If Pcmcia is compiled in, offer Pcmcia cards...
+comment "Wireless 802.11b Pcmcia/Cardbus cards support"
+ depends on NET_RADIO && PCMCIA
+
+config PCMCIA_HERMES
+ tristate "Hermes PCMCIA card support"
+ depends on NET_RADIO && PCMCIA && HERMES
+ ---help---
+ A driver for "Hermes" chipset based PCMCIA wireless adaptors, such
+ as the Lucent WavelanIEEE/Orinoco cards and their OEM (Cabletron/
+ EnteraSys RoamAbout 802.11, ELSA Airlancer, Melco Buffalo and
+ others). It should also be usable on various Prism II based cards
+ such as the Linksys, D-Link and Farallon Skyline. It should also
+ work on Symbol cards such as the 3Com AirConnect and Ericsson WLAN.
+
+ To use your PC-cards, you will need supporting software from David
+ Hinds' pcmcia-cs package (see the file <file:Documentation/Changes>
+ for location). You also want to check out the PCMCIA-HOWTO,
+ available from <http://www.tldp.org/docs.html#howto>.
+
+ You will also very likely also need the Wireless Tools in order to
+ configure your card and that /etc/pcmcia/wireless.opts works:
+ <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>.
+
+config AIRO_CS
+ tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards"
+ depends on NET_RADIO && PCMCIA
+ ---help---
+ This is the standard Linux driver to support Cisco/Aironet PCMCIA
+ 802.11 wireless cards. This driver is the same as the Aironet
+ driver part of the Linux Pcmcia package.
+ It supports the new 802.11b cards from Cisco (Cisco 34X, Cisco 35X
+ - with or without encryption) as well as card before the Cisco
+ aquisition (Aironet 4500, Aironet 4800, Aironet 4800B). It also
+ supports OEM of Cisco such as the DELL TrueMobile 4800 and Xircom
+ 802.11b cards.
+
+ This driver support both the standard Linux Wireless Extensions
+ and Cisco proprietary API, so both the Linux Wireless Tools and the
+ Cisco Linux utilities can be used to configure the card.
+
+ To use your PC-cards, you will need supporting software from David
+ Hinds' pcmcia-cs package (see the file <file:Documentation/Changes>
+ for location). You also want to check out the PCMCIA-HOWTO,
+ available from <http://www.tldp.org/docs.html#howto>.
+
+config PCMCIA_ATMEL
+ tristate "Atmel at76c502/at76c504 PCMCIA cards"
+ depends on NET_RADIO && ATMEL && PCMCIA
+ select FW_LOADER
+ select CRC32
+ ---help---
+ Enable support for PCMCIA cards containing the
+ Atmel at76c502 and at76c504 chips.
+
+config PCMCIA_WL3501
+ tristate "Planet WL3501 PCMCIA cards"
+ depends on NET_RADIO && EXPERIMENTAL && PCMCIA
+ ---help---
+ A driver for WL3501 PCMCIA 802.11 wireless cards made by Planet.
+ It has basic support for Linux wireless extensions and initial
+ micro support for ethtool.
+
+comment "Prism GT/Duette 802.11(a/b/g) PCI/Cardbus support"
+ depends on NET_RADIO && PCI
+config PRISM54
+ tristate 'Intersil Prism GT/Duette/Indigo PCI/Cardbus'
+ depends on PCI && NET_RADIO && EXPERIMENTAL
+ select FW_LOADER
+ ---help---
+ Enable PCI and Cardbus support for the following chipset based cards:
+
+ ISL3880 - Prism GT 802.11 b/g
+ ISL3877 - Prism Indigo 802.11 a
+ ISL3890 - Prism Duette 802.11 a/b/g
+
+ For a complete list of supported cards visit <http://prism54.org>.
+ Here is the latest confirmed list of supported cards:
+
+ 3com OfficeConnect 11g Cardbus Card aka 3CRWE154G72
+ Allnet ALL0271 PCI Card
+ Compex WL54G Cardbus Card
+ Corega CG-WLCB54GT Cardbus Card
+ D-Link Air Plus Xtreme G A1 Cardbus Card aka DWL-g650
+ I-O Data WN-G54/CB Cardbus Card
+ Kobishi XG-300 aka Z-Com Cardbus Card
+ Netgear WG511 Cardbus Card
+ Ovislink WL-5400PCI PCI Card
+ Peabird WLG-PCI PCI Card
+ Sitecom WL-100i Cardbus Card
+ Sitecom WL-110i PCI Card
+ SMC2802W - EZ Connect g 2.4GHz 54 Mbps Wireless PCI Card
+ SMC2835W - EZ Connect g 2.4GHz 54 Mbps Wireless Cardbus Card
+ SMC2835W-V2 - EZ Connect g 2.4GHz 54 Mbps Wireless Cardbus Card
+ Z-Com XG-900 PCI Card
+ Zyxel G-100 Cardbus Card
+
+ If you enable this you will need a firmware file as well.
+ You will need to copy this to /usr/lib/hotplug/firmware/isl3890.
+ You can get this non-GPL'd firmware file from the Prism54 project page:
+ <http://prism54.org>
+ You will also need the /etc/hotplug/firmware.agent script from
+ a current hotplug package.
+
+ Note: You need a motherboard with DMA support to use any of these cards
+
+ If you want to compile the driver as a module ( = code which can be
+ inserted in and removed from the running kernel whenever you want),
+ say M here and read <file:Documentation/modules.txt>. The module
+ will be called prism54.ko.
+
+# yes, this works even when no drivers are selected
+config NET_WIRELESS
+ bool
+ depends on NET_RADIO && (ISA || PCI || PPC_PMAC || PCMCIA)
+ default y
+
+endmenu
+
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
new file mode 100644
index 000000000000..2b87841322cc
--- /dev/null
+++ b/drivers/net/wireless/Makefile
@@ -0,0 +1,33 @@
+#
+# Makefile for the Linux Wireless network device drivers.
+#
+
+obj-$(CONFIG_STRIP) += strip.o
+obj-$(CONFIG_ARLAN) += arlan.o
+
+arlan-objs := arlan-main.o arlan-proc.o
+
+# Obsolete cards
+obj-$(CONFIG_WAVELAN) += wavelan.o
+obj-$(CONFIG_PCMCIA_NETWAVE) += netwave_cs.o
+obj-$(CONFIG_PCMCIA_WAVELAN) += wavelan_cs.o
+
+obj-$(CONFIG_HERMES) += orinoco.o hermes.o
+obj-$(CONFIG_PCMCIA_HERMES) += orinoco_cs.o
+obj-$(CONFIG_APPLE_AIRPORT) += airport.o
+obj-$(CONFIG_PLX_HERMES) += orinoco_plx.o
+obj-$(CONFIG_PCI_HERMES) += orinoco_pci.o
+obj-$(CONFIG_TMD_HERMES) += orinoco_tmd.o
+
+obj-$(CONFIG_AIRO) += airo.o
+obj-$(CONFIG_AIRO_CS) += airo_cs.o airo.o
+
+obj-$(CONFIG_ATMEL) += atmel.o
+obj-$(CONFIG_PCI_ATMEL) += atmel_pci.o
+obj-$(CONFIG_PCMCIA_ATMEL) += atmel_cs.o
+
+obj-$(CONFIG_PRISM54) += prism54/
+
+# 16-bit wireless PCMCIA client drivers
+obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o
+obj-$(CONFIG_PCMCIA_WL3501) += wl3501_cs.o
diff --git a/drivers/net/wireless/README b/drivers/net/wireless/README
new file mode 100644
index 000000000000..0c274bf6d45e
--- /dev/null
+++ b/drivers/net/wireless/README
@@ -0,0 +1,25 @@
+ README
+ ------
+
+ This directory is mostly for Wireless LAN drivers, in their
+various incarnations (ISA, PCI, Pcmcia...).
+ This separate directory is needed because a lot of driver work
+on different bus (typically PCI + Pcmcia) and share 95% of the
+code. This allow the code and the config options to be in one single
+place instead of scattered all over the driver tree, which is never
+100% satisfactory.
+
+ Note : if you want more info on the topic of Wireless LANs,
+you are kindly invited to have a look at the Wireless Howto :
+ http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/
+ Some Wireless LAN drivers, like orinoco_cs, require the use of
+Wireless Tools to be configured :
+ http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html
+
+ Special notes for distribution maintainers :
+ 1) wvlan_cs will be discontinued soon in favor of orinoco_cs
+ 2) Please add Wireless Tools support in your scripts
+
+ Have fun...
+
+ Jean
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
new file mode 100644
index 000000000000..2899144f2153
--- /dev/null
+++ b/drivers/net/wireless/airo.c
@@ -0,0 +1,7667 @@
+/*======================================================================
+
+ Aironet driver for 4500 and 4800 series cards
+
+ This code is released under both the GPL version 2 and BSD licenses.
+ Either license may be used. The respective licenses are found at
+ the end of this file.
+
+ This code was developed by Benjamin Reed <breed@users.sourceforge.net>
+ including portions of which come from the Aironet PC4500
+ Developer's Reference Manual and used with permission. Copyright
+ (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
+ code in the Developer's manual was granted for this driver by
+ Aironet. Major code contributions were received from Javier Achirica
+ <achirica@users.sourceforge.net> and Jean Tourrilhes <jt@hpl.hp.com>.
+ Code was also integrated from the Cisco Aironet driver for Linux.
+ Support for MPI350 cards was added by Fabrice Bellet
+ <fabrice@bellet.info>.
+
+======================================================================*/
+
+#include <linux/config.h>
+#include <linux/init.h>
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/proc_fs.h>
+#include <linux/smp_lock.h>
+
+#include <linux/sched.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/in.h>
+#include <linux/bitops.h>
+#include <asm/io.h>
+#include <asm/system.h>
+
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/skbuff.h>
+#include <linux/if_arp.h>
+#include <linux/ioport.h>
+#include <linux/pci.h>
+#include <asm/uaccess.h>
+
+#ifdef CONFIG_PCI
+static struct pci_device_id card_ids[] = {
+ { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
+ { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
+ { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
+ { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
+ { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
+ { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, },
+ { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, },
+ { 0, }
+};
+MODULE_DEVICE_TABLE(pci, card_ids);
+
+static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
+static void airo_pci_remove(struct pci_dev *);
+static int airo_pci_suspend(struct pci_dev *pdev, u32 state);
+static int airo_pci_resume(struct pci_dev *pdev);
+
+static struct pci_driver airo_driver = {
+ .name = "airo",
+ .id_table = card_ids,
+ .probe = airo_pci_probe,
+ .remove = __devexit_p(airo_pci_remove),
+ .suspend = airo_pci_suspend,
+ .resume = airo_pci_resume,
+};
+#endif /* CONFIG_PCI */
+
+/* Include Wireless Extension definition and check version - Jean II */
+#include <linux/wireless.h>
+#define WIRELESS_SPY // enable iwspy support
+#include <net/iw_handler.h> // New driver API
+
+#define CISCO_EXT // enable Cisco extensions
+#ifdef CISCO_EXT
+#include <linux/delay.h>
+#endif
+
+/* Support Cisco MIC feature */
+#define MICSUPPORT
+
+#if defined(MICSUPPORT) && !defined(CONFIG_CRYPTO)
+#warning MIC support requires Crypto API
+#undef MICSUPPORT
+#endif
+
+/* Hack to do some power saving */
+#define POWER_ON_DOWN
+
+/* As you can see this list is HUGH!
+ I really don't know what a lot of these counts are about, but they
+ are all here for completeness. If the IGNLABEL macro is put in
+ infront of the label, that statistic will not be included in the list
+ of statistics in the /proc filesystem */
+
+#define IGNLABEL(comment) NULL
+static char *statsLabels[] = {
+ "RxOverrun",
+ IGNLABEL("RxPlcpCrcErr"),
+ IGNLABEL("RxPlcpFormatErr"),
+ IGNLABEL("RxPlcpLengthErr"),
+ "RxMacCrcErr",
+ "RxMacCrcOk",
+ "RxWepErr",
+ "RxWepOk",
+ "RetryLong",
+ "RetryShort",
+ "MaxRetries",
+ "NoAck",
+ "NoCts",
+ "RxAck",
+ "RxCts",
+ "TxAck",
+ "TxRts",
+ "TxCts",
+ "TxMc",
+ "TxBc",
+ "TxUcFrags",
+ "TxUcPackets",
+ "TxBeacon",
+ "RxBeacon",
+ "TxSinColl",
+ "TxMulColl",
+ "DefersNo",
+ "DefersProt",
+ "DefersEngy",
+ "DupFram",
+ "RxFragDisc",
+ "TxAged",
+ "RxAged",
+ "LostSync-MaxRetry",
+ "LostSync-MissedBeacons",
+ "LostSync-ArlExceeded",
+ "LostSync-Deauth",
+ "LostSync-Disassoced",
+ "LostSync-TsfTiming",
+ "HostTxMc",
+ "HostTxBc",
+ "HostTxUc",
+ "HostTxFail",
+ "HostRxMc",
+ "HostRxBc",
+ "HostRxUc",
+ "HostRxDiscard",
+ IGNLABEL("HmacTxMc"),
+ IGNLABEL("HmacTxBc"),
+ IGNLABEL("HmacTxUc"),
+ IGNLABEL("HmacTxFail"),
+ IGNLABEL("HmacRxMc"),
+ IGNLABEL("HmacRxBc"),
+ IGNLABEL("HmacRxUc"),
+ IGNLABEL("HmacRxDiscard"),
+ IGNLABEL("HmacRxAccepted"),
+ "SsidMismatch",
+ "ApMismatch",
+ "RatesMismatch",
+ "AuthReject",
+ "AuthTimeout",
+ "AssocReject",
+ "AssocTimeout",
+ IGNLABEL("ReasonOutsideTable"),
+ IGNLABEL("ReasonStatus1"),
+ IGNLABEL("ReasonStatus2"),
+ IGNLABEL("ReasonStatus3"),
+ IGNLABEL("ReasonStatus4"),
+ IGNLABEL("ReasonStatus5"),
+ IGNLABEL("ReasonStatus6"),
+ IGNLABEL("ReasonStatus7"),
+ IGNLABEL("ReasonStatus8"),
+ IGNLABEL("ReasonStatus9"),
+ IGNLABEL("ReasonStatus10"),
+ IGNLABEL("ReasonStatus11"),
+ IGNLABEL("ReasonStatus12"),
+ IGNLABEL("ReasonStatus13"),
+ IGNLABEL("ReasonStatus14"),
+ IGNLABEL("ReasonStatus15"),
+ IGNLABEL("ReasonStatus16"),
+ IGNLABEL("ReasonStatus17"),
+ IGNLABEL("ReasonStatus18"),
+ IGNLABEL("ReasonStatus19"),
+ "RxMan",
+ "TxMan",
+ "RxRefresh",
+ "TxRefresh",
+ "RxPoll",
+ "TxPoll",
+ "HostRetries",
+ "LostSync-HostReq",
+ "HostTxBytes",
+ "HostRxBytes",
+ "ElapsedUsec",
+ "ElapsedSec",
+ "LostSyncBetterAP",
+ "PrivacyMismatch",
+ "Jammed",
+ "DiscRxNotWepped",
+ "PhyEleMismatch",
+ (char*)-1 };
+#ifndef RUN_AT
+#define RUN_AT(x) (jiffies+(x))
+#endif
+
+
+/* These variables are for insmod, since it seems that the rates
+ can only be set in setup_card. Rates should be a comma separated
+ (no spaces) list of rates (up to 8). */
+
+static int rates[8];
+static int basic_rate;
+static char *ssids[3];
+
+static int io[4];
+static int irq[4];
+
+static
+int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at.
+ 0 means no limit. For old cards this was 4 */
+
+static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */
+static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read
+ the bap, needed on some older cards and buses. */
+static int adhoc;
+
+static int probe = 1;
+
+static int proc_uid /* = 0 */;
+
+static int proc_gid /* = 0 */;
+
+static int airo_perm = 0555;
+
+static int proc_perm = 0644;
+
+MODULE_AUTHOR("Benjamin Reed");
+MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
+ cards. Direct support for ISA/PCI/MPI cards and support \
+ for PCMCIA when used with airo_cs.");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
+module_param_array(io, int, NULL, 0);
+module_param_array(irq, int, NULL, 0);
+module_param(basic_rate, int, 0);
+module_param_array(rates, int, NULL, 0);
+module_param_array(ssids, charp, NULL, 0);
+module_param(auto_wep, int, 0);
+MODULE_PARM_DESC(auto_wep, "If non-zero, the driver will keep looping through \
+the authentication options until an association is made. The value of \
+auto_wep is number of the wep keys to check. A value of 2 will try using \
+the key at index 0 and index 1.");
+module_param(aux_bap, int, 0);
+MODULE_PARM_DESC(aux_bap, "If non-zero, the driver will switch into a mode \
+than seems to work better for older cards with some older buses. Before \
+switching it checks that the switch is needed.");
+module_param(maxencrypt, int, 0);
+MODULE_PARM_DESC(maxencrypt, "The maximum speed that the card can do \
+encryption. Units are in 512kbs. Zero (default) means there is no limit. \
+Older cards used to be limited to 2mbs (4).");
+module_param(adhoc, int, 0);
+MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
+module_param(probe, int, 0);
+MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
+
+module_param(proc_uid, int, 0);
+MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
+module_param(proc_gid, int, 0);
+MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
+module_param(airo_perm, int, 0);
+MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
+module_param(proc_perm, int, 0);
+MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
+
+/* This is a kind of sloppy hack to get this information to OUT4500 and
+ IN4500. I would be extremely interested in the situation where this
+ doesn't work though!!! */
+static int do8bitIO = 0;
+
+/* Return codes */
+#define SUCCESS 0
+#define ERROR -1
+#define NO_PACKET -2
+
+/* Commands */
+#define NOP2 0x0000
+#define MAC_ENABLE 0x0001
+#define MAC_DISABLE 0x0002
+#define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */
+#define CMD_SOFTRESET 0x0004
+#define HOSTSLEEP 0x0005
+#define CMD_MAGIC_PKT 0x0006
+#define CMD_SETWAKEMASK 0x0007
+#define CMD_READCFG 0x0008
+#define CMD_SETMODE 0x0009
+#define CMD_ALLOCATETX 0x000a
+#define CMD_TRANSMIT 0x000b
+#define CMD_DEALLOCATETX 0x000c
+#define NOP 0x0010
+#define CMD_WORKAROUND 0x0011
+#define CMD_ALLOCATEAUX 0x0020
+#define CMD_ACCESS 0x0021
+#define CMD_PCIBAP 0x0022
+#define CMD_PCIAUX 0x0023
+#define CMD_ALLOCBUF 0x0028
+#define CMD_GETTLV 0x0029
+#define CMD_PUTTLV 0x002a
+#define CMD_DELTLV 0x002b
+#define CMD_FINDNEXTTLV 0x002c
+#define CMD_PSPNODES 0x0030
+#define CMD_SETCW 0x0031
+#define CMD_SETPCF 0x0032
+#define CMD_SETPHYREG 0x003e
+#define CMD_TXTEST 0x003f
+#define MAC_ENABLETX 0x0101
+#define CMD_LISTBSS 0x0103
+#define CMD_SAVECFG 0x0108
+#define CMD_ENABLEAUX 0x0111
+#define CMD_WRITERID 0x0121
+#define CMD_USEPSPNODES 0x0130
+#define MAC_ENABLERX 0x0201
+
+/* Command errors */
+#define ERROR_QUALIF 0x00
+#define ERROR_ILLCMD 0x01
+#define ERROR_ILLFMT 0x02
+#define ERROR_INVFID 0x03
+#define ERROR_INVRID 0x04
+#define ERROR_LARGE 0x05
+#define ERROR_NDISABL 0x06
+#define ERROR_ALLOCBSY 0x07
+#define ERROR_NORD 0x0B
+#define ERROR_NOWR 0x0C
+#define ERROR_INVFIDTX 0x0D
+#define ERROR_TESTACT 0x0E
+#define ERROR_TAGNFND 0x12
+#define ERROR_DECODE 0x20
+#define ERROR_DESCUNAV 0x21
+#define ERROR_BADLEN 0x22
+#define ERROR_MODE 0x80
+#define ERROR_HOP 0x81
+#define ERROR_BINTER 0x82
+#define ERROR_RXMODE 0x83
+#define ERROR_MACADDR 0x84
+#define ERROR_RATES 0x85
+#define ERROR_ORDER 0x86
+#define ERROR_SCAN 0x87
+#define ERROR_AUTH 0x88
+#define ERROR_PSMODE 0x89
+#define ERROR_RTYPE 0x8A
+#define ERROR_DIVER 0x8B
+#define ERROR_SSID 0x8C
+#define ERROR_APLIST 0x8D
+#define ERROR_AUTOWAKE 0x8E
+#define ERROR_LEAP 0x8F
+
+/* Registers */
+#define COMMAND 0x00
+#define PARAM0 0x02
+#define PARAM1 0x04
+#define PARAM2 0x06
+#define STATUS 0x08
+#define RESP0 0x0a
+#define RESP1 0x0c
+#define RESP2 0x0e
+#define LINKSTAT 0x10
+#define SELECT0 0x18
+#define OFFSET0 0x1c
+#define RXFID 0x20
+#define TXALLOCFID 0x22
+#define TXCOMPLFID 0x24
+#define DATA0 0x36
+#define EVSTAT 0x30
+#define EVINTEN 0x32
+#define EVACK 0x34
+#define SWS0 0x28
+#define SWS1 0x2a
+#define SWS2 0x2c
+#define SWS3 0x2e
+#define AUXPAGE 0x3A
+#define AUXOFF 0x3C
+#define AUXDATA 0x3E
+
+#define FID_TX 1
+#define FID_RX 2
+/* Offset into aux memory for descriptors */
+#define AUX_OFFSET 0x800
+/* Size of allocated packets */
+#define PKTSIZE 1840
+#define RIDSIZE 2048
+/* Size of the transmit queue */
+#define MAXTXQ 64
+
+/* BAP selectors */
+#define BAP0 0 // Used for receiving packets
+#define BAP1 2 // Used for xmiting packets and working with RIDS
+
+/* Flags */
+#define COMMAND_BUSY 0x8000
+
+#define BAP_BUSY 0x8000
+#define BAP_ERR 0x4000
+#define BAP_DONE 0x2000
+
+#define PROMISC 0xffff
+#define NOPROMISC 0x0000
+
+#define EV_CMD 0x10
+#define EV_CLEARCOMMANDBUSY 0x4000
+#define EV_RX 0x01
+#define EV_TX 0x02
+#define EV_TXEXC 0x04
+#define EV_ALLOC 0x08
+#define EV_LINK 0x80
+#define EV_AWAKE 0x100
+#define EV_TXCPY 0x400
+#define EV_UNKNOWN 0x800
+#define EV_MIC 0x1000 /* Message Integrity Check Interrupt */
+#define EV_AWAKEN 0x2000
+#define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC)
+
+#ifdef CHECK_UNKNOWN_INTS
+#define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
+#else
+#define IGNORE_INTS (~STATUS_INTS)
+#endif
+
+/* RID TYPES */
+#define RID_RW 0x20
+
+/* The RIDs */
+#define RID_CAPABILITIES 0xFF00
+#define RID_APINFO 0xFF01
+#define RID_RADIOINFO 0xFF02
+#define RID_UNKNOWN3 0xFF03
+#define RID_RSSI 0xFF04
+#define RID_CONFIG 0xFF10
+#define RID_SSID 0xFF11
+#define RID_APLIST 0xFF12
+#define RID_DRVNAME 0xFF13
+#define RID_ETHERENCAP 0xFF14
+#define RID_WEP_TEMP 0xFF15
+#define RID_WEP_PERM 0xFF16
+#define RID_MODULATION 0xFF17
+#define RID_OPTIONS 0xFF18
+#define RID_ACTUALCONFIG 0xFF20 /*readonly*/
+#define RID_FACTORYCONFIG 0xFF21
+#define RID_UNKNOWN22 0xFF22
+#define RID_LEAPUSERNAME 0xFF23
+#define RID_LEAPPASSWORD 0xFF24
+#define RID_STATUS 0xFF50
+#define RID_BEACON_HST 0xFF51
+#define RID_BUSY_HST 0xFF52
+#define RID_RETRIES_HST 0xFF53
+#define RID_UNKNOWN54 0xFF54
+#define RID_UNKNOWN55 0xFF55
+#define RID_UNKNOWN56 0xFF56
+#define RID_MIC 0xFF57
+#define RID_STATS16 0xFF60
+#define RID_STATS16DELTA 0xFF61
+#define RID_STATS16DELTACLEAR 0xFF62
+#define RID_STATS 0xFF68
+#define RID_STATSDELTA 0xFF69
+#define RID_STATSDELTACLEAR 0xFF6A
+#define RID_ECHOTEST_RID 0xFF70
+#define RID_ECHOTEST_RESULTS 0xFF71
+#define RID_BSSLISTFIRST 0xFF72
+#define RID_BSSLISTNEXT 0xFF73
+
+typedef struct {
+ u16 cmd;
+ u16 parm0;
+ u16 parm1;
+ u16 parm2;
+} Cmd;
+
+typedef struct {
+ u16 status;
+ u16 rsp0;
+ u16 rsp1;
+ u16 rsp2;
+} Resp;
+
+/*
+ * Rids and endian-ness: The Rids will always be in cpu endian, since
+ * this all the patches from the big-endian guys end up doing that.
+ * so all rid access should use the read/writeXXXRid routines.
+ */
+
+/* This is redundant for x86 archs, but it seems necessary for ARM */
+#pragma pack(1)
+
+/* This structure came from an email sent to me from an engineer at
+ aironet for inclusion into this driver */
+typedef struct {
+ u16 len;
+ u16 kindex;
+ u8 mac[ETH_ALEN];
+ u16 klen;
+ u8 key[16];
+} WepKeyRid;
+
+/* These structures are from the Aironet's PC4500 Developers Manual */
+typedef struct {
+ u16 len;
+ u8 ssid[32];
+} Ssid;
+
+typedef struct {
+ u16 len;
+ Ssid ssids[3];
+} SsidRid;
+
+typedef struct {
+ u16 len;
+ u16 modulation;
+#define MOD_DEFAULT 0
+#define MOD_CCK 1
+#define MOD_MOK 2
+} ModulationRid;
+
+typedef struct {
+ u16 len; /* sizeof(ConfigRid) */
+ u16 opmode; /* operating mode */
+#define MODE_STA_IBSS 0
+#define MODE_STA_ESS 1
+#define MODE_AP 2
+#define MODE_AP_RPTR 3
+#define MODE_ETHERNET_HOST (0<<8) /* rx payloads converted */
+#define MODE_LLC_HOST (1<<8) /* rx payloads left as is */
+#define MODE_AIRONET_EXTEND (1<<9) /* enable Aironet extenstions */
+#define MODE_AP_INTERFACE (1<<10) /* enable ap interface extensions */
+#define MODE_ANTENNA_ALIGN (1<<11) /* enable antenna alignment */
+#define MODE_ETHER_LLC (1<<12) /* enable ethernet LLC */
+#define MODE_LEAF_NODE (1<<13) /* enable leaf node bridge */
+#define MODE_CF_POLLABLE (1<<14) /* enable CF pollable */
+#define MODE_MIC (1<<15) /* enable MIC */
+ u16 rmode; /* receive mode */
+#define RXMODE_BC_MC_ADDR 0
+#define RXMODE_BC_ADDR 1 /* ignore multicasts */
+#define RXMODE_ADDR 2 /* ignore multicast and broadcast */
+#define RXMODE_RFMON 3 /* wireless monitor mode */
+#define RXMODE_RFMON_ANYBSS 4
+#define RXMODE_LANMON 5 /* lan style monitor -- data packets only */
+#define RXMODE_DISABLE_802_3_HEADER (1<<8) /* disables 802.3 header on rx */
+#define RXMODE_NORMALIZED_RSSI (1<<9) /* return normalized RSSI */
+ u16 fragThresh;
+ u16 rtsThres;
+ u8 macAddr[ETH_ALEN];
+ u8 rates[8];
+ u16 shortRetryLimit;
+ u16 longRetryLimit;
+ u16 txLifetime; /* in kusec */
+ u16 rxLifetime; /* in kusec */
+ u16 stationary;
+ u16 ordering;
+ u16 u16deviceType; /* for overriding device type */
+ u16 cfpRate;
+ u16 cfpDuration;
+ u16 _reserved1[3];
+ /*---------- Scanning/Associating ----------*/
+ u16 scanMode;
+#define SCANMODE_ACTIVE 0
+#define SCANMODE_PASSIVE 1
+#define SCANMODE_AIROSCAN 2
+ u16 probeDelay; /* in kusec */
+ u16 probeEnergyTimeout; /* in kusec */
+ u16 probeResponseTimeout;
+ u16 beaconListenTimeout;
+ u16 joinNetTimeout;
+ u16 authTimeout;
+ u16 authType;
+#define AUTH_OPEN 0x1
+#define AUTH_ENCRYPT 0x101
+#define AUTH_SHAREDKEY 0x102
+#define AUTH_ALLOW_UNENCRYPTED 0x200
+ u16 associationTimeout;
+ u16 specifiedApTimeout;
+ u16 offlineScanInterval;
+ u16 offlineScanDuration;
+ u16 linkLossDelay;
+ u16 maxBeaconLostTime;
+ u16 refreshInterval;
+#define DISABLE_REFRESH 0xFFFF
+ u16 _reserved1a[1];
+ /*---------- Power save operation ----------*/
+ u16 powerSaveMode;
+#define POWERSAVE_CAM 0
+#define POWERSAVE_PSP 1
+#define POWERSAVE_PSPCAM 2
+ u16 sleepForDtims;
+ u16 listenInterval;
+ u16 fastListenInterval;
+ u16 listenDecay;
+ u16 fastListenDelay;
+ u16 _reserved2[2];
+ /*---------- Ap/Ibss config items ----------*/
+ u16 beaconPeriod;
+ u16 atimDuration;
+ u16 hopPeriod;
+ u16 channelSet;
+ u16 channel;
+ u16 dtimPeriod;
+ u16 bridgeDistance;
+ u16 radioID;
+ /*---------- Radio configuration ----------*/
+ u16 radioType;
+#define RADIOTYPE_DEFAULT 0
+#define RADIOTYPE_802_11 1
+#define RADIOTYPE_LEGACY 2
+ u8 rxDiversity;
+ u8 txDiversity;
+ u16 txPower;
+#define TXPOWER_DEFAULT 0
+ u16 rssiThreshold;
+#define RSSI_DEFAULT 0
+ u16 modulation;
+#define PREAMBLE_AUTO 0
+#define PREAMBLE_LONG 1
+#define PREAMBLE_SHORT 2
+ u16 preamble;
+ u16 homeProduct;
+ u16 radioSpecific;
+ /*---------- Aironet Extensions ----------*/
+ u8 nodeName[16];
+ u16 arlThreshold;
+ u16 arlDecay;
+ u16 arlDelay;
+ u16 _reserved4[1];
+ /*---------- Aironet Extensions ----------*/
+ u8 magicAction;
+#define MAGIC_ACTION_STSCHG 1
+#define MAGIC_ACTION_RESUME 2
+#define MAGIC_IGNORE_MCAST (1<<8)
+#define MAGIC_IGNORE_BCAST (1<<9)
+#define MAGIC_SWITCH_TO_PSP (0<<10)
+#define MAGIC_STAY_IN_CAM (1<<10)
+ u8 magicControl;
+ u16 autoWake;
+} ConfigRid;
+
+typedef struct {
+ u16 len;
+ u8 mac[ETH_ALEN];
+ u16 mode;
+ u16 errorCode;
+ u16 sigQuality;
+ u16 SSIDlen;
+ char SSID[32];
+ char apName[16];
+ u8 bssid[4][ETH_ALEN];
+ u16 beaconPeriod;
+ u16 dimPeriod;
+ u16 atimDuration;
+ u16 hopPeriod;
+ u16 channelSet;
+ u16 channel;
+ u16 hopsToBackbone;
+ u16 apTotalLoad;
+ u16 generatedLoad;
+ u16 accumulatedArl;
+ u16 signalQuality;
+ u16 currentXmitRate;
+ u16 apDevExtensions;
+ u16 normalizedSignalStrength;
+ u16 shortPreamble;
+ u8 apIP[4];
+ u8 noisePercent; /* Noise percent in last second */
+ u8 noisedBm; /* Noise dBm in last second */
+ u8 noiseAvePercent; /* Noise percent in last minute */
+ u8 noiseAvedBm; /* Noise dBm in last minute */
+ u8 noiseMaxPercent; /* Highest noise percent in last minute */
+ u8 noiseMaxdBm; /* Highest noise dbm in last minute */
+ u16 load;
+ u8 carrier[4];
+ u16 assocStatus;
+#define STAT_NOPACKETS 0
+#define STAT_NOCARRIERSET 10
+#define STAT_GOTCARRIERSET 11
+#define STAT_WRONGSSID 20
+#define STAT_BADCHANNEL 25
+#define STAT_BADBITRATES 30
+#define STAT_BADPRIVACY 35
+#define STAT_APFOUND 40
+#define STAT_APREJECTED 50
+#define STAT_AUTHENTICATING 60
+#define STAT_DEAUTHENTICATED 61
+#define STAT_AUTHTIMEOUT 62
+#define STAT_ASSOCIATING 70
+#define STAT_DEASSOCIATED 71
+#define STAT_ASSOCTIMEOUT 72
+#define STAT_NOTAIROAP 73
+#define STAT_ASSOCIATED 80
+#define STAT_LEAPING 90
+#define STAT_LEAPFAILED 91
+#define STAT_LEAPTIMEDOUT 92
+#define STAT_LEAPCOMPLETE 93
+} StatusRid;
+
+typedef struct {
+ u16 len;
+ u16 spacer;
+ u32 vals[100];
+} StatsRid;
+
+
+typedef struct {
+ u16 len;
+ u8 ap[4][ETH_ALEN];
+} APListRid;
+
+typedef struct {
+ u16 len;
+ char oui[3];
+ char zero;
+ u16 prodNum;
+ char manName[32];
+ char prodName[16];
+ char prodVer[8];
+ char factoryAddr[ETH_ALEN];
+ char aironetAddr[ETH_ALEN];
+ u16 radioType;
+ u16 country;
+ char callid[ETH_ALEN];
+ char supportedRates[8];
+ char rxDiversity;
+ char txDiversity;
+ u16 txPowerLevels[8];
+ u16 hardVer;
+ u16 hardCap;
+ u16 tempRange;
+ u16 softVer;
+ u16 softSubVer;
+ u16 interfaceVer;
+ u16 softCap;
+ u16 bootBlockVer;
+ u16 requiredHard;
+ u16 extSoftCap;
+} CapabilityRid;
+
+typedef struct {
+ u16 len;
+ u16 index; /* First is 0 and 0xffff means end of list */
+#define RADIO_FH 1 /* Frequency hopping radio type */
+#define RADIO_DS 2 /* Direct sequence radio type */
+#define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
+ u16 radioType;
+ u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
+ u8 zero;
+ u8 ssidLen;
+ u8 ssid[32];
+ u16 rssi;
+#define CAP_ESS (1<<0)
+#define CAP_IBSS (1<<1)
+#define CAP_PRIVACY (1<<4)
+#define CAP_SHORTHDR (1<<5)
+ u16 cap;
+ u16 beaconInterval;
+ u8 rates[8]; /* Same as rates for config rid */
+ struct { /* For frequency hopping only */
+ u16 dwell;
+ u8 hopSet;
+ u8 hopPattern;
+ u8 hopIndex;
+ u8 fill;
+ } fh;
+ u16 dsChannel;
+ u16 atimWindow;
+} BSSListRid;
+
+typedef struct {
+ u8 rssipct;
+ u8 rssidBm;
+} tdsRssiEntry;
+
+typedef struct {
+ u16 len;
+ tdsRssiEntry x[256];
+} tdsRssiRid;
+
+typedef struct {
+ u16 len;
+ u16 state;
+ u16 multicastValid;
+ u8 multicast[16];
+ u16 unicastValid;
+ u8 unicast[16];
+} MICRid;
+
+typedef struct {
+ u16 typelen;
+
+ union {
+ u8 snap[8];
+ struct {
+ u8 dsap;
+ u8 ssap;
+ u8 control;
+ u8 orgcode[3];
+ u8 fieldtype[2];
+ } llc;
+ } u;
+ u32 mic;
+ u32 seq;
+} MICBuffer;
+
+typedef struct {
+ u8 da[ETH_ALEN];
+ u8 sa[ETH_ALEN];
+} etherHead;
+
+#pragma pack()
+
+#define TXCTL_TXOK (1<<1) /* report if tx is ok */
+#define TXCTL_TXEX (1<<2) /* report if tx fails */
+#define TXCTL_802_3 (0<<3) /* 802.3 packet */
+#define TXCTL_802_11 (1<<3) /* 802.11 mac packet */
+#define TXCTL_ETHERNET (0<<4) /* payload has ethertype */
+#define TXCTL_LLC (1<<4) /* payload is llc */
+#define TXCTL_RELEASE (0<<5) /* release after completion */
+#define TXCTL_NORELEASE (1<<5) /* on completion returns to host */
+
+#define BUSY_FID 0x10000
+
+#ifdef CISCO_EXT
+#define AIROMAGIC 0xa55a
+/* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */
+#ifdef SIOCIWFIRSTPRIV
+#ifdef SIOCDEVPRIVATE
+#define AIROOLDIOCTL SIOCDEVPRIVATE
+#define AIROOLDIDIFC AIROOLDIOCTL + 1
+#endif /* SIOCDEVPRIVATE */
+#else /* SIOCIWFIRSTPRIV */
+#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
+#endif /* SIOCIWFIRSTPRIV */
+/* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably
+ * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root
+ * only and don't return the modified struct ifreq to the application which
+ * is usually a problem. - Jean II */
+#define AIROIOCTL SIOCIWFIRSTPRIV
+#define AIROIDIFC AIROIOCTL + 1
+
+/* Ioctl constants to be used in airo_ioctl.command */
+
+#define AIROGCAP 0 // Capability rid
+#define AIROGCFG 1 // USED A LOT
+#define AIROGSLIST 2 // System ID list
+#define AIROGVLIST 3 // List of specified AP's
+#define AIROGDRVNAM 4 // NOTUSED
+#define AIROGEHTENC 5 // NOTUSED
+#define AIROGWEPKTMP 6
+#define AIROGWEPKNV 7
+#define AIROGSTAT 8
+#define AIROGSTATSC32 9
+#define AIROGSTATSD32 10
+#define AIROGMICRID 11
+#define AIROGMICSTATS 12
+#define AIROGFLAGS 13
+#define AIROGID 14
+#define AIRORRID 15
+#define AIRORSWVERSION 17
+
+/* Leave gap of 40 commands after AIROGSTATSD32 for future */
+
+#define AIROPCAP AIROGSTATSD32 + 40
+#define AIROPVLIST AIROPCAP + 1
+#define AIROPSLIST AIROPVLIST + 1
+#define AIROPCFG AIROPSLIST + 1
+#define AIROPSIDS AIROPCFG + 1
+#define AIROPAPLIST AIROPSIDS + 1
+#define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
+#define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
+#define AIROPSTCLR AIROPMACOFF + 1
+#define AIROPWEPKEY AIROPSTCLR + 1
+#define AIROPWEPKEYNV AIROPWEPKEY + 1
+#define AIROPLEAPPWD AIROPWEPKEYNV + 1
+#define AIROPLEAPUSR AIROPLEAPPWD + 1
+
+/* Flash codes */
+
+#define AIROFLSHRST AIROPWEPKEYNV + 40
+#define AIROFLSHGCHR AIROFLSHRST + 1
+#define AIROFLSHSTFL AIROFLSHGCHR + 1
+#define AIROFLSHPCHR AIROFLSHSTFL + 1
+#define AIROFLPUTBUF AIROFLSHPCHR + 1
+#define AIRORESTART AIROFLPUTBUF + 1
+
+#define FLASHSIZE 32768
+#define AUXMEMSIZE (256 * 1024)
+
+typedef struct aironet_ioctl {
+ unsigned short command; // What to do
+ unsigned short len; // Len of data
+ unsigned short ridnum; // rid number
+ unsigned char __user *data; // d-data
+} aironet_ioctl;
+
+static char *swversion = "2.1";
+#endif /* CISCO_EXT */
+
+#define NUM_MODULES 2
+#define MIC_MSGLEN_MAX 2400
+#define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
+
+typedef struct {
+ u32 size; // size
+ u8 enabled; // MIC enabled or not
+ u32 rxSuccess; // successful packets received
+ u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
+ u32 rxNotMICed; // pkts dropped due to not being MIC'd
+ u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
+ u32 rxWrongSequence; // pkts dropped due to sequence number violation
+ u32 reserve[32];
+} mic_statistics;
+
+typedef struct {
+ u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
+ u64 accum; // accumulated mic, reduced to u32 in final()
+ int position; // current position (byte offset) in message
+ union {
+ u8 d8[4];
+ u32 d32;
+ } part; // saves partial message word across update() calls
+} emmh32_context;
+
+typedef struct {
+ emmh32_context seed; // Context - the seed
+ u32 rx; // Received sequence number
+ u32 tx; // Tx sequence number
+ u32 window; // Start of window
+ u8 valid; // Flag to say if context is valid or not
+ u8 key[16];
+} miccntx;
+
+typedef struct {
+ miccntx mCtx; // Multicast context
+ miccntx uCtx; // Unicast context
+} mic_module;
+
+typedef struct {
+ unsigned int rid: 16;
+ unsigned int len: 15;
+ unsigned int valid: 1;
+ dma_addr_t host_addr;
+} Rid;
+
+typedef struct {
+ unsigned int offset: 15;
+ unsigned int eoc: 1;
+ unsigned int len: 15;
+ unsigned int valid: 1;
+ dma_addr_t host_addr;
+} TxFid;
+
+typedef struct {
+ unsigned int ctl: 15;
+ unsigned int rdy: 1;
+ unsigned int len: 15;
+ unsigned int valid: 1;
+ dma_addr_t host_addr;
+} RxFid;
+
+/*
+ * Host receive descriptor
+ */
+typedef struct {
+ unsigned char __iomem *card_ram_off; /* offset into card memory of the
+ desc */
+ RxFid rx_desc; /* card receive descriptor */
+ char *virtual_host_addr; /* virtual address of host receive
+ buffer */
+ int pending;
+} HostRxDesc;
+
+/*
+ * Host transmit descriptor
+ */
+typedef struct {
+ unsigned char __iomem *card_ram_off; /* offset into card memory of the
+ desc */
+ TxFid tx_desc; /* card transmit descriptor */
+ char *virtual_host_addr; /* virtual address of host receive
+ buffer */
+ int pending;
+} HostTxDesc;
+
+/*
+ * Host RID descriptor
+ */
+typedef struct {
+ unsigned char __iomem *card_ram_off; /* offset into card memory of the
+ descriptor */
+ Rid rid_desc; /* card RID descriptor */
+ char *virtual_host_addr; /* virtual address of host receive
+ buffer */
+} HostRidDesc;
+
+typedef struct {
+ u16 sw0;
+ u16 sw1;
+ u16 status;
+ u16 len;
+#define HOST_SET (1 << 0)
+#define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */
+#define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */
+#define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */
+#define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */
+#define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */
+#define HOST_CLR_AID (1 << 7) /* clear AID failure */
+#define HOST_RTS (1 << 9) /* Force RTS use */
+#define HOST_SHORT (1 << 10) /* Do short preamble */
+ u16 ctl;
+ u16 aid;
+ u16 retries;
+ u16 fill;
+} TxCtlHdr;
+
+typedef struct {
+ u16 ctl;
+ u16 duration;
+ char addr1[6];
+ char addr2[6];
+ char addr3[6];
+ u16 seq;
+ char addr4[6];
+} WifiHdr;
+
+
+typedef struct {
+ TxCtlHdr ctlhdr;
+ u16 fill1;
+ u16 fill2;
+ WifiHdr wifihdr;
+ u16 gaplen;
+ u16 status;
+} WifiCtlHdr;
+
+WifiCtlHdr wifictlhdr8023 = {
+ .ctlhdr = {
+ .ctl = HOST_DONT_RLSE,
+ }
+};
+
+#ifdef WIRELESS_EXT
+// Frequency list (map channels to frequencies)
+static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
+ 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
+
+// A few details needed for WEP (Wireless Equivalent Privacy)
+#define MAX_KEY_SIZE 13 // 128 (?) bits
+#define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
+typedef struct wep_key_t {
+ u16 len;
+ u8 key[16]; /* 40-bit and 104-bit keys */
+} wep_key_t;
+
+/* Backward compatibility */
+#ifndef IW_ENCODE_NOKEY
+#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
+#define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
+#endif /* IW_ENCODE_NOKEY */
+
+/* List of Wireless Handlers (new API) */
+static const struct iw_handler_def airo_handler_def;
+#endif /* WIRELESS_EXT */
+
+static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
+
+struct airo_info;
+
+static int get_dec_u16( char *buffer, int *start, int limit );
+static void OUT4500( struct airo_info *, u16 register, u16 value );
+static unsigned short IN4500( struct airo_info *, u16 register );
+static u16 setup_card(struct airo_info*, u8 *mac, int lock);
+static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock );
+static void disable_MAC(struct airo_info *ai, int lock);
+static void enable_interrupts(struct airo_info*);
+static void disable_interrupts(struct airo_info*);
+static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
+static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
+static int aux_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
+ int whichbap);
+static int fast_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
+ int whichbap);
+static int bap_write(struct airo_info*, const u16 *pu16Src, int bytelen,
+ int whichbap);
+static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
+static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
+static int PC4500_writerid(struct airo_info*, u16 rid, const void
+ *pBuf, int len, int lock);
+static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
+ int len, int dummy );
+static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
+static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
+static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
+
+static int mpi_send_packet (struct net_device *dev);
+static void mpi_unmap_card(struct pci_dev *pci);
+static void mpi_receive_802_3(struct airo_info *ai);
+static void mpi_receive_802_11(struct airo_info *ai);
+static int waitbusy (struct airo_info *ai);
+
+static irqreturn_t airo_interrupt( int irq, void* dev_id, struct pt_regs
+ *regs);
+static int airo_thread(void *data);
+static void timer_func( struct net_device *dev );
+static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
+#ifdef WIRELESS_EXT
+struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
+static void airo_read_wireless_stats (struct airo_info *local);
+#endif /* WIRELESS_EXT */
+#ifdef CISCO_EXT
+static int readrids(struct net_device *dev, aironet_ioctl *comp);
+static int writerids(struct net_device *dev, aironet_ioctl *comp);
+int flashcard(struct net_device *dev, aironet_ioctl *comp);
+#endif /* CISCO_EXT */
+#ifdef MICSUPPORT
+static void micinit(struct airo_info *ai);
+static int micsetup(struct airo_info *ai);
+static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
+static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
+
+#include <linux/crypto.h>
+#endif
+
+struct airo_info {
+ struct net_device_stats stats;
+ struct net_device *dev;
+ /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
+ use the high bit to mark whether it is in use. */
+#define MAX_FIDS 6
+#define MPI_MAX_FIDS 1
+ int fids[MAX_FIDS];
+ ConfigRid config;
+ char keyindex; // Used with auto wep
+ char defindex; // Used with auto wep
+ struct proc_dir_entry *proc_entry;
+ spinlock_t aux_lock;
+ unsigned long flags;
+#define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */
+#define FLAG_RADIO_OFF 0 /* User disabling of MAC */
+#define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */
+#define FLAG_RADIO_MASK 0x03
+#define FLAG_ENABLED 2
+#define FLAG_ADHOC 3 /* Needed by MIC */
+#define FLAG_MIC_CAPABLE 4
+#define FLAG_UPDATE_MULTI 5
+#define FLAG_UPDATE_UNI 6
+#define FLAG_802_11 7
+#define FLAG_PENDING_XMIT 9
+#define FLAG_PENDING_XMIT11 10
+#define FLAG_MPI 11
+#define FLAG_REGISTERED 12
+#define FLAG_COMMIT 13
+#define FLAG_RESET 14
+#define FLAG_FLASHING 15
+#define JOB_MASK 0x1ff0000
+#define JOB_DIE 16
+#define JOB_XMIT 17
+#define JOB_XMIT11 18
+#define JOB_STATS 19
+#define JOB_PROMISC 20
+#define JOB_MIC 21
+#define JOB_EVENT 22
+#define JOB_AUTOWEP 23
+#define JOB_WSTATS 24
+ int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
+ int whichbap);
+ unsigned short *flash;
+ tdsRssiEntry *rssi;
+ struct task_struct *task;
+ struct semaphore sem;
+ pid_t thr_pid;
+ wait_queue_head_t thr_wait;
+ struct completion thr_exited;
+ unsigned long expires;
+ struct {
+ struct sk_buff *skb;
+ int fid;
+ } xmit, xmit11;
+ struct net_device *wifidev;
+#ifdef WIRELESS_EXT
+ struct iw_statistics wstats; // wireless stats
+ unsigned long scan_timestamp; /* Time started to scan */
+ struct iw_spy_data spy_data;
+ struct iw_public_data wireless_data;
+#endif /* WIRELESS_EXT */
+#ifdef MICSUPPORT
+ /* MIC stuff */
+ struct crypto_tfm *tfm;
+ mic_module mod[2];
+ mic_statistics micstats;
+#endif
+ HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
+ HostTxDesc txfids[MPI_MAX_FIDS];
+ HostRidDesc config_desc;
+ unsigned long ridbus; // phys addr of config_desc
+ struct sk_buff_head txq;// tx queue used by mpi350 code
+ struct pci_dev *pci;
+ unsigned char __iomem *pcimem;
+ unsigned char __iomem *pciaux;
+ unsigned char *shared;
+ dma_addr_t shared_dma;
+ int power;
+ SsidRid *SSID;
+ APListRid *APList;
+#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
+ char proc_name[IFNAMSIZ];
+};
+
+static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen,
+ int whichbap) {
+ return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
+}
+
+static int setup_proc_entry( struct net_device *dev,
+ struct airo_info *apriv );
+static int takedown_proc_entry( struct net_device *dev,
+ struct airo_info *apriv );
+
+#ifdef MICSUPPORT
+/***********************************************************************
+ * MIC ROUTINES *
+ ***********************************************************************
+ */
+
+static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
+static void MoveWindow(miccntx *context, u32 micSeq);
+void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *);
+void emmh32_init(emmh32_context *context);
+void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
+void emmh32_final(emmh32_context *context, u8 digest[4]);
+
+/* micinit - Initialize mic seed */
+
+static void micinit(struct airo_info *ai)
+{
+ MICRid mic_rid;
+
+ clear_bit(JOB_MIC, &ai->flags);
+ PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
+ up(&ai->sem);
+
+ ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0;
+
+ if (ai->micstats.enabled) {
+ /* Key must be valid and different */
+ if (mic_rid.multicastValid && (!ai->mod[0].mCtx.valid ||
+ (memcmp (ai->mod[0].mCtx.key, mic_rid.multicast,
+ sizeof(ai->mod[0].mCtx.key)) != 0))) {
+ /* Age current mic Context */
+ memcpy(&ai->mod[1].mCtx,&ai->mod[0].mCtx,sizeof(miccntx));
+ /* Initialize new context */
+ memcpy(&ai->mod[0].mCtx.key,mic_rid.multicast,sizeof(mic_rid.multicast));
+ ai->mod[0].mCtx.window = 33; //Window always points to the middle
+ ai->mod[0].mCtx.rx = 0; //Rx Sequence numbers
+ ai->mod[0].mCtx.tx = 0; //Tx sequence numbers
+ ai->mod[0].mCtx.valid = 1; //Key is now valid
+
+ /* Give key to mic seed */
+ emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm);
+ }
+
+ /* Key must be valid and different */
+ if (mic_rid.unicastValid && (!ai->mod[0].uCtx.valid ||
+ (memcmp(ai->mod[0].uCtx.key, mic_rid.unicast,
+ sizeof(ai->mod[0].uCtx.key)) != 0))) {
+ /* Age current mic Context */
+ memcpy(&ai->mod[1].uCtx,&ai->mod[0].uCtx,sizeof(miccntx));
+ /* Initialize new context */
+ memcpy(&ai->mod[0].uCtx.key,mic_rid.unicast,sizeof(mic_rid.unicast));
+
+ ai->mod[0].uCtx.window = 33; //Window always points to the middle
+ ai->mod[0].uCtx.rx = 0; //Rx Sequence numbers
+ ai->mod[0].uCtx.tx = 0; //Tx sequence numbers
+ ai->mod[0].uCtx.valid = 1; //Key is now valid
+
+ //Give key to mic seed
+ emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm);
+ }
+ } else {
+ /* So next time we have a valid key and mic is enabled, we will update
+ * the sequence number if the key is the same as before.
+ */
+ ai->mod[0].uCtx.valid = 0;
+ ai->mod[0].mCtx.valid = 0;
+ }
+}
+
+/* micsetup - Get ready for business */
+
+static int micsetup(struct airo_info *ai) {
+ int i;
+
+ if (ai->tfm == NULL)
+ ai->tfm = crypto_alloc_tfm("aes", 0);
+
+ if (ai->tfm == NULL) {
+ printk(KERN_ERR "airo: failed to load transform for AES\n");
+ return ERROR;
+ }
+
+ for (i=0; i < NUM_MODULES; i++) {
+ memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
+ memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
+ }
+ return SUCCESS;
+}
+
+char micsnap[]= {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
+
+/*===========================================================================
+ * Description: Mic a packet
+ *
+ * Inputs: etherHead * pointer to an 802.3 frame
+ *
+ * Returns: BOOLEAN if successful, otherwise false.
+ * PacketTxLen will be updated with the mic'd packets size.
+ *
+ * Caveats: It is assumed that the frame buffer will already
+ * be big enough to hold the largets mic message possible.
+ * (No memory allocation is done here).
+ *
+ * Author: sbraneky (10/15/01)
+ * Merciless hacks by rwilcher (1/14/02)
+ */
+
+static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
+{
+ miccntx *context;
+
+ // Determine correct context
+ // If not adhoc, always use unicast key
+
+ if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
+ context = &ai->mod[0].mCtx;
+ else
+ context = &ai->mod[0].uCtx;
+
+ if (!context->valid)
+ return ERROR;
+
+ mic->typelen = htons(payLen + 16); //Length of Mic'd packet
+
+ memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap
+
+ // Add Tx sequence
+ mic->seq = htonl(context->tx);
+ context->tx += 2;
+
+ emmh32_init(&context->seed); // Mic the packet
+ emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA
+ emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap
+ emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ
+ emmh32_update(&context->seed,frame->da + ETH_ALEN * 2,payLen); //payload
+ emmh32_final(&context->seed, (u8*)&mic->mic);
+
+ /* New Type/length ?????????? */
+ mic->typelen = 0; //Let NIC know it could be an oversized packet
+ return SUCCESS;
+}
+
+typedef enum {
+ NONE,
+ NOMIC,
+ NOMICPLUMMED,
+ SEQUENCE,
+ INCORRECTMIC,
+} mic_error;
+
+/*===========================================================================
+ * Description: Decapsulates a MIC'd packet and returns the 802.3 packet
+ * (removes the MIC stuff) if packet is a valid packet.
+ *
+ * Inputs: etherHead pointer to the 802.3 packet
+ *
+ * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE
+ *
+ * Author: sbraneky (10/15/01)
+ * Merciless hacks by rwilcher (1/14/02)
+ *---------------------------------------------------------------------------
+ */
+
+static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
+{
+ int i;
+ u32 micSEQ;
+ miccntx *context;
+ u8 digest[4];
+ mic_error micError = NONE;
+
+ // Check if the packet is a Mic'd packet
+
+ if (!ai->micstats.enabled) {
+ //No Mic set or Mic OFF but we received a MIC'd packet.
+ if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
+ ai->micstats.rxMICPlummed++;
+ return ERROR;
+ }
+ return SUCCESS;
+ }
+
+ if (ntohs(mic->typelen) == 0x888E)
+ return SUCCESS;
+
+ if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
+ // Mic enabled but packet isn't Mic'd
+ ai->micstats.rxMICPlummed++;
+ return ERROR;
+ }
+
+ micSEQ = ntohl(mic->seq); //store SEQ as CPU order
+
+ //At this point we a have a mic'd packet and mic is enabled
+ //Now do the mic error checking.
+
+ //Receive seq must be odd
+ if ( (micSEQ & 1) == 0 ) {
+ ai->micstats.rxWrongSequence++;
+ return ERROR;
+ }
+
+ for (i = 0; i < NUM_MODULES; i++) {
+ int mcast = eth->da[0] & 1;
+ //Determine proper context
+ context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
+
+ //Make sure context is valid
+ if (!context->valid) {
+ if (i == 0)
+ micError = NOMICPLUMMED;
+ continue;
+ }
+ //DeMic it
+
+ if (!mic->typelen)
+ mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
+
+ emmh32_init(&context->seed);
+ emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
+ emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
+ emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
+ emmh32_update(&context->seed, eth->da + ETH_ALEN*2,payLen);
+ //Calculate MIC
+ emmh32_final(&context->seed, digest);
+
+ if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match
+ //Invalid Mic
+ if (i == 0)
+ micError = INCORRECTMIC;
+ continue;
+ }
+
+ //Check Sequence number if mics pass
+ if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
+ ai->micstats.rxSuccess++;
+ return SUCCESS;
+ }
+ if (i == 0)
+ micError = SEQUENCE;
+ }
+
+ // Update statistics
+ switch (micError) {
+ case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
+ case SEQUENCE: ai->micstats.rxWrongSequence++; break;
+ case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
+ case NONE: break;
+ case NOMIC: break;
+ }
+ return ERROR;
+}
+
+/*===========================================================================
+ * Description: Checks the Rx Seq number to make sure it is valid
+ * and hasn't already been received
+ *
+ * Inputs: miccntx - mic context to check seq against
+ * micSeq - the Mic seq number
+ *
+ * Returns: TRUE if valid otherwise FALSE.
+ *
+ * Author: sbraneky (10/15/01)
+ * Merciless hacks by rwilcher (1/14/02)
+ *---------------------------------------------------------------------------
+ */
+
+static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
+{
+ u32 seq,index;
+
+ //Allow for the ap being rebooted - if it is then use the next
+ //sequence number of the current sequence number - might go backwards
+
+ if (mcast) {
+ if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
+ clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
+ context->window = (micSeq > 33) ? micSeq : 33;
+ context->rx = 0; // Reset rx
+ }
+ } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
+ clear_bit (FLAG_UPDATE_UNI, &ai->flags);
+ context->window = (micSeq > 33) ? micSeq : 33; // Move window
+ context->rx = 0; // Reset rx
+ }
+
+ //Make sequence number relative to START of window
+ seq = micSeq - (context->window - 33);
+
+ //Too old of a SEQ number to check.
+ if ((s32)seq < 0)
+ return ERROR;
+
+ if ( seq > 64 ) {
+ //Window is infinite forward
+ MoveWindow(context,micSeq);
+ return SUCCESS;
+ }
+
+ // We are in the window. Now check the context rx bit to see if it was already sent
+ seq >>= 1; //divide by 2 because we only have odd numbers
+ index = 1 << seq; //Get an index number
+
+ if (!(context->rx & index)) {
+ //micSEQ falls inside the window.
+ //Add seqence number to the list of received numbers.
+ context->rx |= index;
+
+ MoveWindow(context,micSeq);
+
+ return SUCCESS;
+ }
+ return ERROR;
+}
+
+static void MoveWindow(miccntx *context, u32 micSeq)
+{
+ u32 shift;
+
+ //Move window if seq greater than the middle of the window
+ if (micSeq > context->window) {
+ shift = (micSeq - context->window) >> 1;
+
+ //Shift out old
+ if (shift < 32)
+ context->rx >>= shift;
+ else
+ context->rx = 0;
+
+ context->window = micSeq; //Move window
+ }
+}
+
+/*==============================================*/
+/*========== EMMH ROUTINES ====================*/
+/*==============================================*/
+
+/* mic accumulate */
+#define MIC_ACCUM(val) \
+ context->accum += (u64)(val) * context->coeff[coeff_position++];
+
+static unsigned char aes_counter[16];
+
+/* expand the key to fill the MMH coefficient array */
+void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm)
+{
+ /* take the keying material, expand if necessary, truncate at 16-bytes */
+ /* run through AES counter mode to generate context->coeff[] */
+
+ int i,j;
+ u32 counter;
+ u8 *cipher, plain[16];
+ struct scatterlist sg[1];
+
+ crypto_cipher_setkey(tfm, pkey, 16);
+ counter = 0;
+ for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) {
+ aes_counter[15] = (u8)(counter >> 0);
+ aes_counter[14] = (u8)(counter >> 8);
+ aes_counter[13] = (u8)(counter >> 16);
+ aes_counter[12] = (u8)(counter >> 24);
+ counter++;
+ memcpy (plain, aes_counter, 16);
+ sg[0].page = virt_to_page(plain);
+ sg[0].offset = ((long) plain & ~PAGE_MASK);
+ sg[0].length = 16;
+ crypto_cipher_encrypt(tfm, sg, sg, 16);
+ cipher = kmap(sg[0].page) + sg[0].offset;
+ for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
+ context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
+ j += 4;
+ }
+ }
+}
+
+/* prepare for calculation of a new mic */
+void emmh32_init(emmh32_context *context)
+{
+ /* prepare for new mic calculation */
+ context->accum = 0;
+ context->position = 0;
+}
+
+/* add some bytes to the mic calculation */
+void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
+{
+ int coeff_position, byte_position;
+
+ if (len == 0) return;
+
+ coeff_position = context->position >> 2;
+
+ /* deal with partial 32-bit word left over from last update */
+ byte_position = context->position & 3;
+ if (byte_position) {
+ /* have a partial word in part to deal with */
+ do {
+ if (len == 0) return;
+ context->part.d8[byte_position++] = *pOctets++;
+ context->position++;
+ len--;
+ } while (byte_position < 4);
+ MIC_ACCUM(htonl(context->part.d32));
+ }
+
+ /* deal with full 32-bit words */
+ while (len >= 4) {
+ MIC_ACCUM(htonl(*(u32 *)pOctets));
+ context->position += 4;
+ pOctets += 4;
+ len -= 4;
+ }
+
+ /* deal with partial 32-bit word that will be left over from this update */
+ byte_position = 0;
+ while (len > 0) {
+ context->part.d8[byte_position++] = *pOctets++;
+ context->position++;
+ len--;
+ }
+}
+
+/* mask used to zero empty bytes for final partial word */
+static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
+
+/* calculate the mic */
+void emmh32_final(emmh32_context *context, u8 digest[4])
+{
+ int coeff_position, byte_position;
+ u32 val;
+
+ u64 sum, utmp;
+ s64 stmp;
+
+ coeff_position = context->position >> 2;
+
+ /* deal with partial 32-bit word left over from last update */
+ byte_position = context->position & 3;
+ if (byte_position) {
+ /* have a partial word in part to deal with */
+ val = htonl(context->part.d32);
+ MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
+ }
+
+ /* reduce the accumulated u64 to a 32-bit MIC */
+ sum = context->accum;
+ stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
+ utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
+ sum = utmp & 0xffffffffLL;
+ if (utmp > 0x10000000fLL)
+ sum -= 15;
+
+ val = (u32)sum;
+ digest[0] = (val>>24) & 0xFF;
+ digest[1] = (val>>16) & 0xFF;
+ digest[2] = (val>>8) & 0xFF;
+ digest[3] = val & 0xFF;
+}
+#endif
+
+static int readBSSListRid(struct airo_info *ai, int first,
+ BSSListRid *list) {
+ int rc;
+ Cmd cmd;
+ Resp rsp;
+
+ if (first == 1) {
+ if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd=CMD_LISTBSS;
+ if (down_interruptible(&ai->sem))
+ return -ERESTARTSYS;
+ issuecommand(ai, &cmd, &rsp);
+ up(&ai->sem);
+ /* Let the command take effect */
+ ai->task = current;
+ ssleep(3);
+ ai->task = NULL;
+ }
+ rc = PC4500_readrid(ai, first ? RID_BSSLISTFIRST : RID_BSSLISTNEXT,
+ list, sizeof(*list), 1);
+
+ list->len = le16_to_cpu(list->len);
+ list->index = le16_to_cpu(list->index);
+ list->radioType = le16_to_cpu(list->radioType);
+ list->cap = le16_to_cpu(list->cap);
+ list->beaconInterval = le16_to_cpu(list->beaconInterval);
+ list->fh.dwell = le16_to_cpu(list->fh.dwell);
+ list->dsChannel = le16_to_cpu(list->dsChannel);
+ list->atimWindow = le16_to_cpu(list->atimWindow);
+ return rc;
+}
+
+static int readWepKeyRid(struct airo_info*ai, WepKeyRid *wkr, int temp, int lock) {
+ int rc = PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
+ wkr, sizeof(*wkr), lock);
+
+ wkr->len = le16_to_cpu(wkr->len);
+ wkr->kindex = le16_to_cpu(wkr->kindex);
+ wkr->klen = le16_to_cpu(wkr->klen);
+ return rc;
+}
+/* In the writeXXXRid routines we copy the rids so that we don't screwup
+ * the originals when we endian them... */
+static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm, int lock) {
+ int rc;
+ WepKeyRid wkr = *pwkr;
+
+ wkr.len = cpu_to_le16(wkr.len);
+ wkr.kindex = cpu_to_le16(wkr.kindex);
+ wkr.klen = cpu_to_le16(wkr.klen);
+ rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock);
+ if (rc!=SUCCESS) printk(KERN_ERR "airo: WEP_TEMP set %x\n", rc);
+ if (perm) {
+ rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock);
+ if (rc!=SUCCESS) {
+ printk(KERN_ERR "airo: WEP_PERM set %x\n", rc);
+ }
+ }
+ return rc;
+}
+
+static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) {
+ int i;
+ int rc = PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
+
+ ssidr->len = le16_to_cpu(ssidr->len);
+ for(i = 0; i < 3; i++) {
+ ssidr->ssids[i].len = le16_to_cpu(ssidr->ssids[i].len);
+ }
+ return rc;
+}
+static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock) {
+ int rc;
+ int i;
+ SsidRid ssidr = *pssidr;
+
+ ssidr.len = cpu_to_le16(ssidr.len);
+ for(i = 0; i < 3; i++) {
+ ssidr.ssids[i].len = cpu_to_le16(ssidr.ssids[i].len);
+ }
+ rc = PC4500_writerid(ai, RID_SSID, &ssidr, sizeof(ssidr), lock);
+ return rc;
+}
+static int readConfigRid(struct airo_info*ai, int lock) {
+ int rc;
+ u16 *s;
+ ConfigRid cfg;
+
+ if (ai->config.len)
+ return SUCCESS;
+
+ rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
+ if (rc != SUCCESS)
+ return rc;
+
+ for(s = &cfg.len; s <= &cfg.rtsThres; s++) *s = le16_to_cpu(*s);
+
+ for(s = &cfg.shortRetryLimit; s <= &cfg.radioType; s++)
+ *s = le16_to_cpu(*s);
+
+ for(s = &cfg.txPower; s <= &cfg.radioSpecific; s++)
+ *s = le16_to_cpu(*s);
+
+ for(s = &cfg.arlThreshold; s <= &cfg._reserved4[0]; s++)
+ *s = cpu_to_le16(*s);
+
+ for(s = &cfg.autoWake; s <= &cfg.autoWake; s++)
+ *s = cpu_to_le16(*s);
+
+ ai->config = cfg;
+ return SUCCESS;
+}
+static inline void checkThrottle(struct airo_info *ai) {
+ int i;
+/* Old hardware had a limit on encryption speed */
+ if (ai->config.authType != AUTH_OPEN && maxencrypt) {
+ for(i=0; i<8; i++) {
+ if (ai->config.rates[i] > maxencrypt) {
+ ai->config.rates[i] = 0;
+ }
+ }
+ }
+}
+static int writeConfigRid(struct airo_info*ai, int lock) {
+ u16 *s;
+ ConfigRid cfgr;
+
+ if (!test_bit (FLAG_COMMIT, &ai->flags))
+ return SUCCESS;
+
+ clear_bit (FLAG_COMMIT, &ai->flags);
+ clear_bit (FLAG_RESET, &ai->flags);
+ checkThrottle(ai);
+ cfgr = ai->config;
+
+ if ((cfgr.opmode & 0xFF) == MODE_STA_IBSS)
+ set_bit(FLAG_ADHOC, &ai->flags);
+ else
+ clear_bit(FLAG_ADHOC, &ai->flags);
+
+ for(s = &cfgr.len; s <= &cfgr.rtsThres; s++) *s = cpu_to_le16(*s);
+
+ for(s = &cfgr.shortRetryLimit; s <= &cfgr.radioType; s++)
+ *s = cpu_to_le16(*s);
+
+ for(s = &cfgr.txPower; s <= &cfgr.radioSpecific; s++)
+ *s = cpu_to_le16(*s);
+
+ for(s = &cfgr.arlThreshold; s <= &cfgr._reserved4[0]; s++)
+ *s = cpu_to_le16(*s);
+
+ for(s = &cfgr.autoWake; s <= &cfgr.autoWake; s++)
+ *s = cpu_to_le16(*s);
+
+ return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
+}
+static int readStatusRid(struct airo_info*ai, StatusRid *statr, int lock) {
+ int rc = PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
+ u16 *s;
+
+ statr->len = le16_to_cpu(statr->len);
+ for(s = &statr->mode; s <= &statr->SSIDlen; s++) *s = le16_to_cpu(*s);
+
+ for(s = &statr->beaconPeriod; s <= &statr->shortPreamble; s++)
+ *s = le16_to_cpu(*s);
+ statr->load = le16_to_cpu(statr->load);
+ statr->assocStatus = le16_to_cpu(statr->assocStatus);
+ return rc;
+}
+static int readAPListRid(struct airo_info*ai, APListRid *aplr) {
+ int rc = PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
+ aplr->len = le16_to_cpu(aplr->len);
+ return rc;
+}
+static int writeAPListRid(struct airo_info*ai, APListRid *aplr, int lock) {
+ int rc;
+ aplr->len = cpu_to_le16(aplr->len);
+ rc = PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
+ return rc;
+}
+static int readCapabilityRid(struct airo_info*ai, CapabilityRid *capr, int lock) {
+ int rc = PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
+ u16 *s;
+
+ capr->len = le16_to_cpu(capr->len);
+ capr->prodNum = le16_to_cpu(capr->prodNum);
+ capr->radioType = le16_to_cpu(capr->radioType);
+ capr->country = le16_to_cpu(capr->country);
+ for(s = &capr->txPowerLevels[0]; s <= &capr->requiredHard; s++)
+ *s = le16_to_cpu(*s);
+ return rc;
+}
+static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock) {
+ int rc = PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
+ u32 *i;
+
+ sr->len = le16_to_cpu(sr->len);
+ for(i = &sr->vals[0]; i <= &sr->vals[99]; i++) *i = le32_to_cpu(*i);
+ return rc;
+}
+
+static int airo_open(struct net_device *dev) {
+ struct airo_info *info = dev->priv;
+ Resp rsp;
+
+ if (test_bit(FLAG_FLASHING, &info->flags))
+ return -EIO;
+
+ /* Make sure the card is configured.
+ * Wireless Extensions may postpone config changes until the card
+ * is open (to pipeline changes and speed-up card setup). If
+ * those changes are not yet commited, do it now - Jean II */
+ if (test_bit (FLAG_COMMIT, &info->flags)) {
+ disable_MAC(info, 1);
+ writeConfigRid(info, 1);
+ }
+
+ if (info->wifidev != dev) {
+ /* Power on the MAC controller (which may have been disabled) */
+ clear_bit(FLAG_RADIO_DOWN, &info->flags);
+ enable_interrupts(info);
+ }
+ enable_MAC(info, &rsp, 1);
+
+ netif_start_queue(dev);
+ return 0;
+}
+
+static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
+ int npacks, pending;
+ unsigned long flags;
+ struct airo_info *ai = dev->priv;
+
+ if (!skb) {
+ printk(KERN_ERR "airo: %s: skb==NULL\n",__FUNCTION__);
+ return 0;
+ }
+ npacks = skb_queue_len (&ai->txq);
+
+ if (npacks >= MAXTXQ - 1) {
+ netif_stop_queue (dev);
+ if (npacks > MAXTXQ) {
+ ai->stats.tx_fifo_errors++;
+ return 1;
+ }
+ skb_queue_tail (&ai->txq, skb);
+ return 0;
+ }
+
+ spin_lock_irqsave(&ai->aux_lock, flags);
+ skb_queue_tail (&ai->txq, skb);
+ pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
+ spin_unlock_irqrestore(&ai->aux_lock,flags);
+ netif_wake_queue (dev);
+
+ if (pending == 0) {
+ set_bit(FLAG_PENDING_XMIT, &ai->flags);
+ mpi_send_packet (dev);
+ }
+ return 0;
+}
+
+/*
+ * @mpi_send_packet
+ *
+ * Attempt to transmit a packet. Can be called from interrupt
+ * or transmit . return number of packets we tried to send
+ */
+
+static int mpi_send_packet (struct net_device *dev)
+{
+ struct sk_buff *skb;
+ unsigned char *buffer;
+ s16 len, *payloadLen;
+ struct airo_info *ai = dev->priv;
+ u8 *sendbuf;
+
+ /* get a packet to send */
+
+ if ((skb = skb_dequeue(&ai->txq)) == 0) {
+ printk (KERN_ERR
+ "airo: %s: Dequeue'd zero in send_packet()\n",
+ __FUNCTION__);
+ return 0;
+ }
+
+ /* check min length*/
+ len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
+ buffer = skb->data;
+
+ ai->txfids[0].tx_desc.offset = 0;
+ ai->txfids[0].tx_desc.valid = 1;
+ ai->txfids[0].tx_desc.eoc = 1;
+ ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
+
+/*
+ * Magic, the cards firmware needs a length count (2 bytes) in the host buffer
+ * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen
+ * is immediatly after it. ------------------------------------------------
+ * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA|
+ * ------------------------------------------------
+ */
+
+ memcpy((char *)ai->txfids[0].virtual_host_addr,
+ (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
+
+ payloadLen = (s16 *)(ai->txfids[0].virtual_host_addr +
+ sizeof(wifictlhdr8023));
+ sendbuf = ai->txfids[0].virtual_host_addr +
+ sizeof(wifictlhdr8023) + 2 ;
+
+ /*
+ * Firmware automaticly puts 802 header on so
+ * we don't need to account for it in the length
+ */
+#ifdef MICSUPPORT
+ if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
+ (ntohs(((u16 *)buffer)[6]) != 0x888E)) {
+ MICBuffer pMic;
+
+ if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
+ return ERROR;
+
+ *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic));
+ ai->txfids[0].tx_desc.len += sizeof(pMic);
+ /* copy data into airo dma buffer */
+ memcpy (sendbuf, buffer, sizeof(etherHead));
+ buffer += sizeof(etherHead);
+ sendbuf += sizeof(etherHead);
+ memcpy (sendbuf, &pMic, sizeof(pMic));
+ sendbuf += sizeof(pMic);
+ memcpy (sendbuf, buffer, len - sizeof(etherHead));
+ } else
+#endif
+ {
+ *payloadLen = cpu_to_le16(len - sizeof(etherHead));
+
+ dev->trans_start = jiffies;
+
+ /* copy data into airo dma buffer */
+ memcpy(sendbuf, buffer, len);
+ }
+
+ memcpy_toio(ai->txfids[0].card_ram_off,
+ &ai->txfids[0].tx_desc, sizeof(TxFid));
+
+ OUT4500(ai, EVACK, 8);
+
+ dev_kfree_skb_any(skb);
+ return 1;
+}
+
+static void get_tx_error(struct airo_info *ai, u32 fid)
+{
+ u16 status;
+
+ if (fid < 0)
+ status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
+ else {
+ if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
+ return;
+ bap_read(ai, &status, 2, BAP0);
+ }
+ if (le16_to_cpu(status) & 2) /* Too many retries */
+ ai->stats.tx_aborted_errors++;
+ if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
+ ai->stats.tx_heartbeat_errors++;
+ if (le16_to_cpu(status) & 8) /* Aid fail */
+ { }
+ if (le16_to_cpu(status) & 0x10) /* MAC disabled */
+ ai->stats.tx_carrier_errors++;
+ if (le16_to_cpu(status) & 0x20) /* Association lost */
+ { }
+ /* We produce a TXDROP event only for retry or lifetime
+ * exceeded, because that's the only status that really mean
+ * that this particular node went away.
+ * Other errors means that *we* screwed up. - Jean II */
+ if ((le16_to_cpu(status) & 2) ||
+ (le16_to_cpu(status) & 4)) {
+ union iwreq_data wrqu;
+ char junk[0x18];
+
+ /* Faster to skip over useless data than to do
+ * another bap_setup(). We are at offset 0x6 and
+ * need to go to 0x18 and read 6 bytes - Jean II */
+ bap_read(ai, (u16 *) junk, 0x18, BAP0);
+
+ /* Copy 802.11 dest address.
+ * We use the 802.11 header because the frame may
+ * not be 802.3 or may be mangled...
+ * In Ad-Hoc mode, it will be the node address.
+ * In managed mode, it will be most likely the AP addr
+ * User space will figure out how to convert it to
+ * whatever it needs (IP address or else).
+ * - Jean II */
+ memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
+ wrqu.addr.sa_family = ARPHRD_ETHER;
+
+ /* Send event to user space */
+ wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
+ }
+}
+
+static void airo_end_xmit(struct net_device *dev) {
+ u16 status;
+ int i;
+ struct airo_info *priv = dev->priv;
+ struct sk_buff *skb = priv->xmit.skb;
+ int fid = priv->xmit.fid;
+ u32 *fids = priv->fids;
+
+ clear_bit(JOB_XMIT, &priv->flags);
+ clear_bit(FLAG_PENDING_XMIT, &priv->flags);
+ status = transmit_802_3_packet (priv, fids[fid], skb->data);
+ up(&priv->sem);
+
+ i = 0;
+ if ( status == SUCCESS ) {
+ dev->trans_start = jiffies;
+ for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
+ } else {
+ priv->fids[fid] &= 0xffff;
+ priv->stats.tx_window_errors++;
+ }
+ if (i < MAX_FIDS / 2)
+ netif_wake_queue(dev);
+ dev_kfree_skb(skb);
+}
+
+static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
+ s16 len;
+ int i, j;
+ struct airo_info *priv = dev->priv;
+ u32 *fids = priv->fids;
+
+ if ( skb == NULL ) {
+ printk( KERN_ERR "airo: skb == NULL!!!\n" );
+ return 0;
+ }
+
+ /* Find a vacant FID */
+ for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
+ for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
+
+ if ( j >= MAX_FIDS / 2 ) {
+ netif_stop_queue(dev);
+
+ if (i == MAX_FIDS / 2) {
+ priv->stats.tx_fifo_errors++;
+ return 1;
+ }
+ }
+ /* check min length*/
+ len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
+ /* Mark fid as used & save length for later */
+ fids[i] |= (len << 16);
+ priv->xmit.skb = skb;
+ priv->xmit.fid = i;
+ if (down_trylock(&priv->sem) != 0) {
+ set_bit(FLAG_PENDING_XMIT, &priv->flags);
+ netif_stop_queue(dev);
+ set_bit(JOB_XMIT, &priv->flags);
+ wake_up_interruptible(&priv->thr_wait);
+ } else
+ airo_end_xmit(dev);
+ return 0;
+}
+
+static void airo_end_xmit11(struct net_device *dev) {
+ u16 status;
+ int i;
+ struct airo_info *priv = dev->priv;
+ struct sk_buff *skb = priv->xmit11.skb;
+ int fid = priv->xmit11.fid;
+ u32 *fids = priv->fids;
+
+ clear_bit(JOB_XMIT11, &priv->flags);
+ clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
+ status = transmit_802_11_packet (priv, fids[fid], skb->data);
+ up(&priv->sem);
+
+ i = MAX_FIDS / 2;
+ if ( status == SUCCESS ) {
+ dev->trans_start = jiffies;
+ for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
+ } else {
+ priv->fids[fid] &= 0xffff;
+ priv->stats.tx_window_errors++;
+ }
+ if (i < MAX_FIDS)
+ netif_wake_queue(dev);
+ dev_kfree_skb(skb);
+}
+
+static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
+ s16 len;
+ int i, j;
+ struct airo_info *priv = dev->priv;
+ u32 *fids = priv->fids;
+
+ if (test_bit(FLAG_MPI, &priv->flags)) {
+ /* Not implemented yet for MPI350 */
+ netif_stop_queue(dev);
+ return -ENETDOWN;
+ }
+
+ if ( skb == NULL ) {
+ printk( KERN_ERR "airo: skb == NULL!!!\n" );
+ return 0;
+ }
+
+ /* Find a vacant FID */
+ for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
+ for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
+
+ if ( j >= MAX_FIDS ) {
+ netif_stop_queue(dev);
+
+ if (i == MAX_FIDS) {
+ priv->stats.tx_fifo_errors++;
+ return 1;
+ }
+ }
+ /* check min length*/
+ len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
+ /* Mark fid as used & save length for later */
+ fids[i] |= (len << 16);
+ priv->xmit11.skb = skb;
+ priv->xmit11.fid = i;
+ if (down_trylock(&priv->sem) != 0) {
+ set_bit(FLAG_PENDING_XMIT11, &priv->flags);
+ netif_stop_queue(dev);
+ set_bit(JOB_XMIT11, &priv->flags);
+ wake_up_interruptible(&priv->thr_wait);
+ } else
+ airo_end_xmit11(dev);
+ return 0;
+}
+
+static void airo_read_stats(struct airo_info *ai) {
+ StatsRid stats_rid;
+ u32 *vals = stats_rid.vals;
+
+ clear_bit(JOB_STATS, &ai->flags);
+ if (ai->power) {
+ up(&ai->sem);
+ return;
+ }
+ readStatsRid(ai, &stats_rid, RID_STATS, 0);
+ up(&ai->sem);
+
+ ai->stats.rx_packets = vals[43] + vals[44] + vals[45];
+ ai->stats.tx_packets = vals[39] + vals[40] + vals[41];
+ ai->stats.rx_bytes = vals[92];
+ ai->stats.tx_bytes = vals[91];
+ ai->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4];
+ ai->stats.tx_errors = vals[42] + ai->stats.tx_fifo_errors;
+ ai->stats.multicast = vals[43];
+ ai->stats.collisions = vals[89];
+
+ /* detailed rx_errors: */
+ ai->stats.rx_length_errors = vals[3];
+ ai->stats.rx_crc_errors = vals[4];
+ ai->stats.rx_frame_errors = vals[2];
+ ai->stats.rx_fifo_errors = vals[0];
+}
+
+struct net_device_stats *airo_get_stats(struct net_device *dev)
+{
+ struct airo_info *local = dev->priv;
+
+ if (!test_bit(JOB_STATS, &local->flags)) {
+ /* Get stats out of the card if available */
+ if (down_trylock(&local->sem) != 0) {
+ set_bit(JOB_STATS, &local->flags);
+ wake_up_interruptible(&local->thr_wait);
+ } else
+ airo_read_stats(local);
+ }
+
+ return &local->stats;
+}
+
+static void airo_set_promisc(struct airo_info *ai) {
+ Cmd cmd;
+ Resp rsp;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd=CMD_SETMODE;
+ clear_bit(JOB_PROMISC, &ai->flags);
+ cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
+ issuecommand(ai, &cmd, &rsp);
+ up(&ai->sem);
+}
+
+static void airo_set_multicast_list(struct net_device *dev) {
+ struct airo_info *ai = dev->priv;
+
+ if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
+ change_bit(FLAG_PROMISC, &ai->flags);
+ if (down_trylock(&ai->sem) != 0) {
+ set_bit(JOB_PROMISC, &ai->flags);
+ wake_up_interruptible(&ai->thr_wait);
+ } else
+ airo_set_promisc(ai);
+ }
+
+ if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) {
+ /* Turn on multicast. (Should be already setup...) */
+ }
+}
+
+static int airo_set_mac_address(struct net_device *dev, void *p)
+{
+ struct airo_info *ai = dev->priv;
+ struct sockaddr *addr = p;
+ Resp rsp;
+
+ readConfigRid(ai, 1);
+ memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
+ set_bit (FLAG_COMMIT, &ai->flags);
+ disable_MAC(ai, 1);
+ writeConfigRid (ai, 1);
+ enable_MAC(ai, &rsp, 1);
+ memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
+ if (ai->wifidev)
+ memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
+ return 0;
+}
+
+static int airo_change_mtu(struct net_device *dev, int new_mtu)
+{
+ if ((new_mtu < 68) || (new_mtu > 2400))
+ return -EINVAL;
+ dev->mtu = new_mtu;
+ return 0;
+}
+
+
+static int airo_close(struct net_device *dev) {
+ struct airo_info *ai = dev->priv;
+
+ netif_stop_queue(dev);
+
+ if (ai->wifidev != dev) {
+#ifdef POWER_ON_DOWN
+ /* Shut power to the card. The idea is that the user can save
+ * power when he doesn't need the card with "ifconfig down".
+ * That's the method that is most friendly towards the network
+ * stack (i.e. the network stack won't try to broadcast
+ * anything on the interface and routes are gone. Jean II */
+ set_bit(FLAG_RADIO_DOWN, &ai->flags);
+ disable_MAC(ai, 1);
+#endif
+ disable_interrupts( ai );
+ }
+ return 0;
+}
+
+static void del_airo_dev( struct net_device *dev );
+
+void stop_airo_card( struct net_device *dev, int freeres )
+{
+ struct airo_info *ai = dev->priv;
+
+ set_bit(FLAG_RADIO_DOWN, &ai->flags);
+ disable_MAC(ai, 1);
+ disable_interrupts(ai);
+ free_irq( dev->irq, dev );
+ takedown_proc_entry( dev, ai );
+ if (test_bit(FLAG_REGISTERED, &ai->flags)) {
+ unregister_netdev( dev );
+ if (ai->wifidev) {
+ unregister_netdev(ai->wifidev);
+ free_netdev(ai->wifidev);
+ ai->wifidev = NULL;
+ }
+ clear_bit(FLAG_REGISTERED, &ai->flags);
+ }
+ set_bit(JOB_DIE, &ai->flags);
+ kill_proc(ai->thr_pid, SIGTERM, 1);
+ wait_for_completion(&ai->thr_exited);
+
+ /*
+ * Clean out tx queue
+ */
+ if (test_bit(FLAG_MPI, &ai->flags) && skb_queue_len (&ai->txq) > 0) {
+ struct sk_buff *skb = NULL;
+ for (;(skb = skb_dequeue(&ai->txq));)
+ dev_kfree_skb(skb);
+ }
+
+ if (ai->flash)
+ kfree(ai->flash);
+ if (ai->rssi)
+ kfree(ai->rssi);
+ if (ai->APList)
+ kfree(ai->APList);
+ if (ai->SSID)
+ kfree(ai->SSID);
+ if (freeres) {
+ /* PCMCIA frees this stuff, so only for PCI and ISA */
+ release_region( dev->base_addr, 64 );
+ if (test_bit(FLAG_MPI, &ai->flags)) {
+ if (ai->pci)
+ mpi_unmap_card(ai->pci);
+ if (ai->pcimem)
+ iounmap(ai->pcimem);
+ if (ai->pciaux)
+ iounmap(ai->pciaux);
+ pci_free_consistent(ai->pci, PCI_SHARED_LEN,
+ ai->shared, ai->shared_dma);
+ }
+ }
+#ifdef MICSUPPORT
+ if (ai->tfm)
+ crypto_free_tfm(ai->tfm);
+#endif
+ del_airo_dev( dev );
+ free_netdev( dev );
+}
+
+EXPORT_SYMBOL(stop_airo_card);
+
+static int add_airo_dev( struct net_device *dev );
+
+int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
+{
+ memcpy(haddr, skb->mac.raw + 10, ETH_ALEN);
+ return ETH_ALEN;
+}
+
+static void mpi_unmap_card(struct pci_dev *pci)
+{
+ unsigned long mem_start = pci_resource_start(pci, 1);
+ unsigned long mem_len = pci_resource_len(pci, 1);
+ unsigned long aux_start = pci_resource_start(pci, 2);
+ unsigned long aux_len = AUXMEMSIZE;
+
+ release_mem_region(aux_start, aux_len);
+ release_mem_region(mem_start, mem_len);
+}
+
+/*************************************************************
+ * This routine assumes that descriptors have been setup .
+ * Run at insmod time or after reset when the decriptors
+ * have been initialized . Returns 0 if all is well nz
+ * otherwise . Does not allocate memory but sets up card
+ * using previously allocated descriptors.
+ */
+static int mpi_init_descriptors (struct airo_info *ai)
+{
+ Cmd cmd;
+ Resp rsp;
+ int i;
+ int rc = SUCCESS;
+
+ /* Alloc card RX descriptors */
+ netif_stop_queue(ai->dev);
+
+ memset(&rsp,0,sizeof(rsp));
+ memset(&cmd,0,sizeof(cmd));
+
+ cmd.cmd = CMD_ALLOCATEAUX;
+ cmd.parm0 = FID_RX;
+ cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
+ cmd.parm2 = MPI_MAX_FIDS;
+ rc=issuecommand(ai, &cmd, &rsp);
+ if (rc != SUCCESS) {
+ printk(KERN_ERR "airo: Couldn't allocate RX FID\n");
+ return rc;
+ }
+
+ for (i=0; i<MPI_MAX_FIDS; i++) {
+ memcpy_toio(ai->rxfids[i].card_ram_off,
+ &ai->rxfids[i].rx_desc, sizeof(RxFid));
+ }
+
+ /* Alloc card TX descriptors */
+
+ memset(&rsp,0,sizeof(rsp));
+ memset(&cmd,0,sizeof(cmd));
+
+ cmd.cmd = CMD_ALLOCATEAUX;
+ cmd.parm0 = FID_TX;
+ cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
+ cmd.parm2 = MPI_MAX_FIDS;
+
+ for (i=0; i<MPI_MAX_FIDS; i++) {
+ ai->txfids[i].tx_desc.valid = 1;
+ memcpy_toio(ai->txfids[i].card_ram_off,
+ &ai->txfids[i].tx_desc, sizeof(TxFid));
+ }
+ ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
+
+ rc=issuecommand(ai, &cmd, &rsp);
+ if (rc != SUCCESS) {
+ printk(KERN_ERR "airo: Couldn't allocate TX FID\n");
+ return rc;
+ }
+
+ /* Alloc card Rid descriptor */
+ memset(&rsp,0,sizeof(rsp));
+ memset(&cmd,0,sizeof(cmd));
+
+ cmd.cmd = CMD_ALLOCATEAUX;
+ cmd.parm0 = RID_RW;
+ cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
+ cmd.parm2 = 1; /* Magic number... */
+ rc=issuecommand(ai, &cmd, &rsp);
+ if (rc != SUCCESS) {
+ printk(KERN_ERR "airo: Couldn't allocate RID\n");
+ return rc;
+ }
+
+ memcpy_toio(ai->config_desc.card_ram_off,
+ &ai->config_desc.rid_desc, sizeof(Rid));
+
+ return rc;
+}
+
+/*
+ * We are setting up three things here:
+ * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid.
+ * 2) Map PCI memory for issueing commands.
+ * 3) Allocate memory (shared) to send and receive ethernet frames.
+ */
+static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
+ const char *name)
+{
+ unsigned long mem_start, mem_len, aux_start, aux_len;
+ int rc = -1;
+ int i;
+ unsigned char *busaddroff,*vpackoff;
+ unsigned char __iomem *pciaddroff;
+
+ mem_start = pci_resource_start(pci, 1);
+ mem_len = pci_resource_len(pci, 1);
+ aux_start = pci_resource_start(pci, 2);
+ aux_len = AUXMEMSIZE;
+
+ if (!request_mem_region(mem_start, mem_len, name)) {
+ printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n",
+ (int)mem_start, (int)mem_len, name);
+ goto out;
+ }
+ if (!request_mem_region(aux_start, aux_len, name)) {
+ printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n",
+ (int)aux_start, (int)aux_len, name);
+ goto free_region1;
+ }
+
+ ai->pcimem = ioremap(mem_start, mem_len);
+ if (!ai->pcimem) {
+ printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n",
+ (int)mem_start, (int)mem_len, name);
+ goto free_region2;
+ }
+ ai->pciaux = ioremap(aux_start, aux_len);
+ if (!ai->pciaux) {
+ printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n",
+ (int)aux_start, (int)aux_len, name);
+ goto free_memmap;
+ }
+
+ /* Reserve PKTSIZE for each fid and 2K for the Rids */
+ ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
+ if (!ai->shared) {
+ printk(KERN_ERR "airo: Couldn't alloc_consistent %d\n",
+ PCI_SHARED_LEN);
+ goto free_auxmap;
+ }
+
+ /*
+ * Setup descriptor RX, TX, CONFIG
+ */
+ busaddroff = (unsigned char *)ai->shared_dma;
+ pciaddroff = ai->pciaux + AUX_OFFSET;
+ vpackoff = ai->shared;
+
+ /* RX descriptor setup */
+ for(i = 0; i < MPI_MAX_FIDS; i++) {
+ ai->rxfids[i].pending = 0;
+ ai->rxfids[i].card_ram_off = pciaddroff;
+ ai->rxfids[i].virtual_host_addr = vpackoff;
+ ai->rxfids[i].rx_desc.host_addr = (dma_addr_t) busaddroff;
+ ai->rxfids[i].rx_desc.valid = 1;
+ ai->rxfids[i].rx_desc.len = PKTSIZE;
+ ai->rxfids[i].rx_desc.rdy = 0;
+
+ pciaddroff += sizeof(RxFid);
+ busaddroff += PKTSIZE;
+ vpackoff += PKTSIZE;
+ }
+
+ /* TX descriptor setup */
+ for(i = 0; i < MPI_MAX_FIDS; i++) {
+ ai->txfids[i].card_ram_off = pciaddroff;
+ ai->txfids[i].virtual_host_addr = vpackoff;
+ ai->txfids[i].tx_desc.valid = 1;
+ ai->txfids[i].tx_desc.host_addr = (dma_addr_t) busaddroff;
+ memcpy(ai->txfids[i].virtual_host_addr,
+ &wifictlhdr8023, sizeof(wifictlhdr8023));
+
+ pciaddroff += sizeof(TxFid);
+ busaddroff += PKTSIZE;
+ vpackoff += PKTSIZE;
+ }
+ ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
+
+ /* Rid descriptor setup */
+ ai->config_desc.card_ram_off = pciaddroff;
+ ai->config_desc.virtual_host_addr = vpackoff;
+ ai->config_desc.rid_desc.host_addr = (dma_addr_t) busaddroff;
+ ai->ridbus = (dma_addr_t)busaddroff;
+ ai->config_desc.rid_desc.rid = 0;
+ ai->config_desc.rid_desc.len = RIDSIZE;
+ ai->config_desc.rid_desc.valid = 1;
+ pciaddroff += sizeof(Rid);
+ busaddroff += RIDSIZE;
+ vpackoff += RIDSIZE;
+
+ /* Tell card about descriptors */
+ if (mpi_init_descriptors (ai) != SUCCESS)
+ goto free_shared;
+
+ return 0;
+ free_shared:
+ pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
+ free_auxmap:
+ iounmap(ai->pciaux);
+ free_memmap:
+ iounmap(ai->pcimem);
+ free_region2:
+ release_mem_region(aux_start, aux_len);
+ free_region1:
+ release_mem_region(mem_start, mem_len);
+ out:
+ return rc;
+}
+
+static void wifi_setup(struct net_device *dev)
+{
+ dev->hard_header = NULL;
+ dev->rebuild_header = NULL;
+ dev->hard_header_cache = NULL;
+ dev->header_cache_update= NULL;
+
+ dev->hard_header_parse = wll_header_parse;
+ dev->hard_start_xmit = &airo_start_xmit11;
+ dev->get_stats = &airo_get_stats;
+ dev->set_mac_address = &airo_set_mac_address;
+ dev->do_ioctl = &airo_ioctl;
+#ifdef WIRELESS_EXT
+ dev->wireless_handlers = &airo_handler_def;
+#endif /* WIRELESS_EXT */
+ dev->change_mtu = &airo_change_mtu;
+ dev->open = &airo_open;
+ dev->stop = &airo_close;
+
+ dev->type = ARPHRD_IEEE80211;
+ dev->hard_header_len = ETH_HLEN;
+ dev->mtu = 2312;
+ dev->addr_len = ETH_ALEN;
+ dev->tx_queue_len = 100;
+
+ memset(dev->broadcast,0xFF, ETH_ALEN);
+
+ dev->flags = IFF_BROADCAST|IFF_MULTICAST;
+}
+
+static struct net_device *init_wifidev(struct airo_info *ai,
+ struct net_device *ethdev)
+{
+ int err;
+ struct net_device *dev = alloc_netdev(0, "wifi%d", wifi_setup);
+ if (!dev)
+ return NULL;
+ dev->priv = ethdev->priv;
+ dev->irq = ethdev->irq;
+ dev->base_addr = ethdev->base_addr;
+#ifdef WIRELESS_EXT
+ dev->wireless_data = ethdev->wireless_data;
+#endif /* WIRELESS_EXT */
+ memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
+ err = register_netdev(dev);
+ if (err<0) {
+ free_netdev(dev);
+ return NULL;
+ }
+ return dev;
+}
+
+int reset_card( struct net_device *dev , int lock) {
+ struct airo_info *ai = dev->priv;
+
+ if (lock && down_interruptible(&ai->sem))
+ return -1;
+ waitbusy (ai);
+ OUT4500(ai,COMMAND,CMD_SOFTRESET);
+ msleep(200);
+ waitbusy (ai);
+ msleep(200);
+ if (lock)
+ up(&ai->sem);
+ return 0;
+}
+
+struct net_device *_init_airo_card( unsigned short irq, int port,
+ int is_pcmcia, struct pci_dev *pci,
+ struct device *dmdev )
+{
+ struct net_device *dev;
+ struct airo_info *ai;
+ int i, rc;
+
+ /* Create the network device object. */
+ dev = alloc_etherdev(sizeof(*ai));
+ if (!dev) {
+ printk(KERN_ERR "airo: Couldn't alloc_etherdev\n");
+ return NULL;
+ }
+ if (dev_alloc_name(dev, dev->name) < 0) {
+ printk(KERN_ERR "airo: Couldn't get name!\n");
+ goto err_out_free;
+ }
+
+ ai = dev->priv;
+ ai->wifidev = NULL;
+ ai->flags = 0;
+ if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
+ printk(KERN_DEBUG "airo: Found an MPI350 card\n");
+ set_bit(FLAG_MPI, &ai->flags);
+ }
+ ai->dev = dev;
+ spin_lock_init(&ai->aux_lock);
+ sema_init(&ai->sem, 1);
+ ai->config.len = 0;
+ ai->pci = pci;
+ init_waitqueue_head (&ai->thr_wait);
+ init_completion (&ai->thr_exited);
+ ai->thr_pid = kernel_thread(airo_thread, dev, CLONE_FS | CLONE_FILES);
+ if (ai->thr_pid < 0)
+ goto err_out_free;
+#ifdef MICSUPPORT
+ ai->tfm = NULL;
+#endif
+ rc = add_airo_dev( dev );
+ if (rc)
+ goto err_out_thr;
+
+ /* The Airo-specific entries in the device structure. */
+ if (test_bit(FLAG_MPI,&ai->flags)) {
+ skb_queue_head_init (&ai->txq);
+ dev->hard_start_xmit = &mpi_start_xmit;
+ } else
+ dev->hard_start_xmit = &airo_start_xmit;
+ dev->get_stats = &airo_get_stats;
+ dev->set_multicast_list = &airo_set_multicast_list;
+ dev->set_mac_address = &airo_set_mac_address;
+ dev->do_ioctl = &airo_ioctl;
+#ifdef WIRELESS_EXT
+ dev->wireless_handlers = &airo_handler_def;
+ ai->wireless_data.spy_data = &ai->spy_data;
+ dev->wireless_data = &ai->wireless_data;
+#endif /* WIRELESS_EXT */
+ dev->change_mtu = &airo_change_mtu;
+ dev->open = &airo_open;
+ dev->stop = &airo_close;
+ dev->irq = irq;
+ dev->base_addr = port;
+
+ SET_NETDEV_DEV(dev, dmdev);
+
+
+ if (test_bit(FLAG_MPI,&ai->flags))
+ reset_card (dev, 1);
+
+ rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev );
+ if (rc) {
+ printk(KERN_ERR "airo: register interrupt %d failed, rc %d\n", irq, rc );
+ goto err_out_unlink;
+ }
+ if (!is_pcmcia) {
+ if (!request_region( dev->base_addr, 64, dev->name )) {
+ rc = -EBUSY;
+ printk(KERN_ERR "airo: Couldn't request region\n");
+ goto err_out_irq;
+ }
+ }
+
+ if (test_bit(FLAG_MPI,&ai->flags)) {
+ if (mpi_map_card(ai, pci, dev->name)) {
+ printk(KERN_ERR "airo: Could not map memory\n");
+ goto err_out_res;
+ }
+ }
+
+ if (probe) {
+ if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) {
+ printk( KERN_ERR "airo: MAC could not be enabled\n" );
+ rc = -EIO;
+ goto err_out_map;
+ }
+ } else if (!test_bit(FLAG_MPI,&ai->flags)) {
+ ai->bap_read = fast_bap_read;
+ set_bit(FLAG_FLASHING, &ai->flags);
+ }
+
+ rc = register_netdev(dev);
+ if (rc) {
+ printk(KERN_ERR "airo: Couldn't register_netdev\n");
+ goto err_out_map;
+ }
+ ai->wifidev = init_wifidev(ai, dev);
+
+ set_bit(FLAG_REGISTERED,&ai->flags);
+ printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n",
+ dev->name,
+ dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
+ dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
+
+ /* Allocate the transmit buffers */
+ if (probe && !test_bit(FLAG_MPI,&ai->flags))
+ for( i = 0; i < MAX_FIDS; i++ )
+ ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2);
+
+ setup_proc_entry( dev, dev->priv ); /* XXX check for failure */
+ netif_start_queue(dev);
+ SET_MODULE_OWNER(dev);
+ return dev;
+
+err_out_map:
+ if (test_bit(FLAG_MPI,&ai->flags) && pci) {
+ pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
+ iounmap(ai->pciaux);
+ iounmap(ai->pcimem);
+ mpi_unmap_card(ai->pci);
+ }
+err_out_res:
+ if (!is_pcmcia)
+ release_region( dev->base_addr, 64 );
+err_out_irq:
+ free_irq(dev->irq, dev);
+err_out_unlink:
+ del_airo_dev(dev);
+err_out_thr:
+ set_bit(JOB_DIE, &ai->flags);
+ kill_proc(ai->thr_pid, SIGTERM, 1);
+ wait_for_completion(&ai->thr_exited);
+err_out_free:
+ free_netdev(dev);
+ return NULL;
+}
+
+struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia,
+ struct device *dmdev)
+{
+ return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev);
+}
+
+EXPORT_SYMBOL(init_airo_card);
+
+static int waitbusy (struct airo_info *ai) {
+ int delay = 0;
+ while ((IN4500 (ai, COMMAND) & COMMAND_BUSY) & (delay < 10000)) {
+ udelay (10);
+ if ((++delay % 20) == 0)
+ OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
+ }
+ return delay < 10000;
+}
+
+int reset_airo_card( struct net_device *dev )
+{
+ int i;
+ struct airo_info *ai = dev->priv;
+
+ if (reset_card (dev, 1))
+ return -1;
+
+ if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
+ printk( KERN_ERR "airo: MAC could not be enabled\n" );
+ return -1;
+ }
+ printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", dev->name,
+ dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
+ dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+ /* Allocate the transmit buffers if needed */
+ if (!test_bit(FLAG_MPI,&ai->flags))
+ for( i = 0; i < MAX_FIDS; i++ )
+ ai->fids[i] = transmit_allocate (ai,2312,i>=MAX_FIDS/2);
+
+ enable_interrupts( ai );
+ netif_wake_queue(dev);
+ return 0;
+}
+
+EXPORT_SYMBOL(reset_airo_card);
+
+static void airo_send_event(struct net_device *dev) {
+ struct airo_info *ai = dev->priv;
+ union iwreq_data wrqu;
+ StatusRid status_rid;
+
+ clear_bit(JOB_EVENT, &ai->flags);
+ PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
+ up(&ai->sem);
+ wrqu.data.length = 0;
+ wrqu.data.flags = 0;
+ memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
+ wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+
+ /* Send event to user space */
+ wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
+}
+
+static int airo_thread(void *data) {
+ struct net_device *dev = data;
+ struct airo_info *ai = dev->priv;
+ int locked;
+
+ daemonize("%s", dev->name);
+ allow_signal(SIGTERM);
+
+ while(1) {
+ if (signal_pending(current))
+ flush_signals(current);
+
+ /* make swsusp happy with our thread */
+ try_to_freeze(PF_FREEZE);
+
+ if (test_bit(JOB_DIE, &ai->flags))
+ break;
+
+ if (ai->flags & JOB_MASK) {
+ locked = down_interruptible(&ai->sem);
+ } else {
+ wait_queue_t wait;
+
+ init_waitqueue_entry(&wait, current);
+ add_wait_queue(&ai->thr_wait, &wait);
+ for (;;) {
+ set_current_state(TASK_INTERRUPTIBLE);
+ if (ai->flags & JOB_MASK)
+ break;
+ if (ai->expires) {
+ if (time_after_eq(jiffies,ai->expires)){
+ set_bit(JOB_AUTOWEP,&ai->flags);
+ break;
+ }
+ if (!signal_pending(current)) {
+ schedule_timeout(ai->expires - jiffies);
+ continue;
+ }
+ } else if (!signal_pending(current)) {
+ schedule();
+ continue;
+ }
+ break;
+ }
+ current->state = TASK_RUNNING;
+ remove_wait_queue(&ai->thr_wait, &wait);
+ locked = 1;
+ }
+
+ if (locked)
+ continue;
+
+ if (test_bit(JOB_DIE, &ai->flags)) {
+ up(&ai->sem);
+ break;
+ }
+
+ if (ai->power || test_bit(FLAG_FLASHING, &ai->flags)) {
+ up(&ai->sem);
+ continue;
+ }
+
+ if (test_bit(JOB_XMIT, &ai->flags))
+ airo_end_xmit(dev);
+ else if (test_bit(JOB_XMIT11, &ai->flags))
+ airo_end_xmit11(dev);
+ else if (test_bit(JOB_STATS, &ai->flags))
+ airo_read_stats(ai);
+ else if (test_bit(JOB_WSTATS, &ai->flags))
+ airo_read_wireless_stats(ai);
+ else if (test_bit(JOB_PROMISC, &ai->flags))
+ airo_set_promisc(ai);
+#ifdef MICSUPPORT
+ else if (test_bit(JOB_MIC, &ai->flags))
+ micinit(ai);
+#endif
+ else if (test_bit(JOB_EVENT, &ai->flags))
+ airo_send_event(dev);
+ else if (test_bit(JOB_AUTOWEP, &ai->flags))
+ timer_func(dev);
+ }
+ complete_and_exit (&ai->thr_exited, 0);
+}
+
+static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) {
+ struct net_device *dev = (struct net_device *)dev_id;
+ u16 status;
+ u16 fid;
+ struct airo_info *apriv = dev->priv;
+ u16 savedInterrupts = 0;
+ int handled = 0;
+
+ if (!netif_device_present(dev))
+ return IRQ_NONE;
+
+ for (;;) {
+ status = IN4500( apriv, EVSTAT );
+ if ( !(status & STATUS_INTS) || status == 0xffff ) break;
+
+ handled = 1;
+
+ if ( status & EV_AWAKE ) {
+ OUT4500( apriv, EVACK, EV_AWAKE );
+ OUT4500( apriv, EVACK, EV_AWAKE );
+ }
+
+ if (!savedInterrupts) {
+ savedInterrupts = IN4500( apriv, EVINTEN );
+ OUT4500( apriv, EVINTEN, 0 );
+ }
+
+ if ( status & EV_MIC ) {
+ OUT4500( apriv, EVACK, EV_MIC );
+#ifdef MICSUPPORT
+ if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) {
+ set_bit(JOB_MIC, &apriv->flags);
+ wake_up_interruptible(&apriv->thr_wait);
+ }
+#endif
+ }
+ if ( status & EV_LINK ) {
+ union iwreq_data wrqu;
+ /* The link status has changed, if you want to put a
+ monitor hook in, do it here. (Remember that
+ interrupts are still disabled!)
+ */
+ u16 newStatus = IN4500(apriv, LINKSTAT);
+ OUT4500( apriv, EVACK, EV_LINK);
+ /* Here is what newStatus means: */
+#define NOBEACON 0x8000 /* Loss of sync - missed beacons */
+#define MAXRETRIES 0x8001 /* Loss of sync - max retries */
+#define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
+#define FORCELOSS 0x8003 /* Loss of sync - host request */
+#define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
+#define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */
+#define DISASS 0x8200 /* Disassociation (low byte is reason code) */
+#define ASSFAIL 0x8400 /* Association failure (low byte is reason
+ code) */
+#define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason
+ code) */
+#define ASSOCIATED 0x0400 /* Assocatied */
+#define RC_RESERVED 0 /* Reserved return code */
+#define RC_NOREASON 1 /* Unspecified reason */
+#define RC_AUTHINV 2 /* Previous authentication invalid */
+#define RC_DEAUTH 3 /* Deauthenticated because sending station is
+ leaving */
+#define RC_NOACT 4 /* Disassociated due to inactivity */
+#define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle
+ all currently associated stations */
+#define RC_BADCLASS2 6 /* Class 2 frame received from
+ non-Authenticated station */
+#define RC_BADCLASS3 7 /* Class 3 frame received from
+ non-Associated station */
+#define RC_STATLEAVE 8 /* Disassociated because sending station is
+ leaving BSS */
+#define RC_NOAUTH 9 /* Station requesting (Re)Association is not
+ Authenticated with the responding station */
+ if (newStatus != ASSOCIATED) {
+ if (auto_wep && !apriv->expires) {
+ apriv->expires = RUN_AT(3*HZ);
+ wake_up_interruptible(&apriv->thr_wait);
+ }
+ } else {
+ struct task_struct *task = apriv->task;
+ if (auto_wep)
+ apriv->expires = 0;
+ if (task)
+ wake_up_process (task);
+ set_bit(FLAG_UPDATE_UNI, &apriv->flags);
+ set_bit(FLAG_UPDATE_MULTI, &apriv->flags);
+ }
+ /* Question : is ASSOCIATED the only status
+ * that is valid ? We want to catch handover
+ * and reassociations as valid status
+ * Jean II */
+ if(newStatus == ASSOCIATED) {
+ if (apriv->scan_timestamp) {
+ /* Send an empty event to user space.
+ * We don't send the received data on
+ * the event because it would require
+ * us to do complex transcoding, and
+ * we want to minimise the work done in
+ * the irq handler. Use a request to
+ * extract the data - Jean II */
+ wrqu.data.length = 0;
+ wrqu.data.flags = 0;
+ wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
+ apriv->scan_timestamp = 0;
+ }
+ if (down_trylock(&apriv->sem) != 0) {
+ set_bit(JOB_EVENT, &apriv->flags);
+ wake_up_interruptible(&apriv->thr_wait);
+ } else
+ airo_send_event(dev);
+ } else {
+ memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
+ wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+
+ /* Send event to user space */
+ wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL);
+ }
+ }
+
+ /* Check to see if there is something to receive */
+ if ( status & EV_RX ) {
+ struct sk_buff *skb = NULL;
+ u16 fc, len, hdrlen = 0;
+#pragma pack(1)
+ struct {
+ u16 status, len;
+ u8 rssi[2];
+ u8 rate;
+ u8 freq;
+ u16 tmp[4];
+ } hdr;
+#pragma pack()
+ u16 gap;
+ u16 tmpbuf[4];
+ u16 *buffer;
+
+ if (test_bit(FLAG_MPI,&apriv->flags)) {
+ if (test_bit(FLAG_802_11, &apriv->flags))
+ mpi_receive_802_11(apriv);
+ else
+ mpi_receive_802_3(apriv);
+ OUT4500(apriv, EVACK, EV_RX);
+ goto exitrx;
+ }
+
+ fid = IN4500( apriv, RXFID );
+
+ /* Get the packet length */
+ if (test_bit(FLAG_802_11, &apriv->flags)) {
+ bap_setup (apriv, fid, 4, BAP0);
+ bap_read (apriv, (u16*)&hdr, sizeof(hdr), BAP0);
+ /* Bad CRC. Ignore packet */
+ if (le16_to_cpu(hdr.status) & 2)
+ hdr.len = 0;
+ if (apriv->wifidev == NULL)
+ hdr.len = 0;
+ } else {
+ bap_setup (apriv, fid, 0x36, BAP0);
+ bap_read (apriv, (u16*)&hdr.len, 2, BAP0);
+ }
+ len = le16_to_cpu(hdr.len);
+
+ if (len > 2312) {
+ printk( KERN_ERR "airo: Bad size %d\n", len );
+ goto badrx;
+ }
+ if (len == 0)
+ goto badrx;
+
+ if (test_bit(FLAG_802_11, &apriv->flags)) {
+ bap_read (apriv, (u16*)&fc, sizeof(fc), BAP0);
+ fc = le16_to_cpu(fc);
+ switch (fc & 0xc) {
+ case 4:
+ if ((fc & 0xe0) == 0xc0)
+ hdrlen = 10;
+ else
+ hdrlen = 16;
+ break;
+ case 8:
+ if ((fc&0x300)==0x300){
+ hdrlen = 30;
+ break;
+ }
+ default:
+ hdrlen = 24;
+ }
+ } else
+ hdrlen = ETH_ALEN * 2;
+
+ skb = dev_alloc_skb( len + hdrlen + 2 + 2 );
+ if ( !skb ) {
+ apriv->stats.rx_dropped++;
+ goto badrx;
+ }
+ skb_reserve(skb, 2); /* This way the IP header is aligned */
+ buffer = (u16*)skb_put (skb, len + hdrlen);
+ if (test_bit(FLAG_802_11, &apriv->flags)) {
+ buffer[0] = fc;
+ bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
+ if (hdrlen == 24)
+ bap_read (apriv, tmpbuf, 6, BAP0);
+
+ bap_read (apriv, &gap, sizeof(gap), BAP0);
+ gap = le16_to_cpu(gap);
+ if (gap) {
+ if (gap <= 8)
+ bap_read (apriv, tmpbuf, gap, BAP0);
+ else
+ printk(KERN_ERR "airo: gaplen too big. Problems will follow...\n");
+ }
+ bap_read (apriv, buffer + hdrlen/2, len, BAP0);
+ } else {
+#ifdef MICSUPPORT
+ MICBuffer micbuf;
+#endif
+ bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
+#ifdef MICSUPPORT
+ if (apriv->micstats.enabled) {
+ bap_read (apriv,(u16*)&micbuf,sizeof(micbuf),BAP0);
+ if (ntohs(micbuf.typelen) > 0x05DC)
+ bap_setup (apriv, fid, 0x44, BAP0);
+ else {
+ if (len <= sizeof(micbuf))
+ goto badmic;
+
+ len -= sizeof(micbuf);
+ skb_trim (skb, len + hdrlen);
+ }
+ }
+#endif
+ bap_read(apriv,buffer+ETH_ALEN,len,BAP0);
+#ifdef MICSUPPORT
+ if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) {
+badmic:
+ dev_kfree_skb_irq (skb);
+#else
+ if (0) {
+#endif
+badrx:
+ OUT4500( apriv, EVACK, EV_RX);
+ goto exitrx;
+ }
+ }
+#ifdef WIRELESS_SPY
+ if (apriv->spy_data.spy_number > 0) {
+ char *sa;
+ struct iw_quality wstats;
+ /* Prepare spy data : addr + qual */
+ if (!test_bit(FLAG_802_11, &apriv->flags)) {
+ sa = (char*)buffer + 6;
+ bap_setup (apriv, fid, 8, BAP0);
+ bap_read (apriv, (u16*)hdr.rssi, 2, BAP0);
+ } else
+ sa = (char*)buffer + 10;
+ wstats.qual = hdr.rssi[0];
+ if (apriv->rssi)
+ wstats.level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm;
+ else
+ wstats.level = (hdr.rssi[1] + 321) / 2;
+ wstats.updated = 3;
+ /* Update spy records */
+ wireless_spy_update(dev, sa, &wstats);
+ }
+#endif /* WIRELESS_SPY */
+ OUT4500( apriv, EVACK, EV_RX);
+
+ if (test_bit(FLAG_802_11, &apriv->flags)) {
+ skb->mac.raw = skb->data;
+ skb->pkt_type = PACKET_OTHERHOST;
+ skb->dev = apriv->wifidev;
+ skb->protocol = htons(ETH_P_802_2);
+ } else {
+ skb->dev = dev;
+ skb->protocol = eth_type_trans(skb,dev);
+ }
+ skb->dev->last_rx = jiffies;
+ skb->ip_summed = CHECKSUM_NONE;
+
+ netif_rx( skb );
+ }
+exitrx:
+
+ /* Check to see if a packet has been transmitted */
+ if ( status & ( EV_TX|EV_TXCPY|EV_TXEXC ) ) {
+ int i;
+ int len = 0;
+ int index = -1;
+
+ if (test_bit(FLAG_MPI,&apriv->flags)) {
+ unsigned long flags;
+
+ if (status & EV_TXEXC)
+ get_tx_error(apriv, -1);
+ spin_lock_irqsave(&apriv->aux_lock, flags);
+ if (skb_queue_len (&apriv->txq)) {
+ spin_unlock_irqrestore(&apriv->aux_lock,flags);
+ mpi_send_packet (dev);
+ } else {
+ clear_bit(FLAG_PENDING_XMIT, &apriv->flags);
+ spin_unlock_irqrestore(&apriv->aux_lock,flags);
+ netif_wake_queue (dev);
+ }
+ OUT4500( apriv, EVACK,
+ status & (EV_TX|EV_TXCPY|EV_TXEXC));
+ goto exittx;
+ }
+
+ fid = IN4500(apriv, TXCOMPLFID);
+
+ for( i = 0; i < MAX_FIDS; i++ ) {
+ if ( ( apriv->fids[i] & 0xffff ) == fid ) {
+ len = apriv->fids[i] >> 16;
+ index = i;
+ }
+ }
+ if (index != -1) {
+ if (status & EV_TXEXC)
+ get_tx_error(apriv, index);
+ OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC));
+ /* Set up to be used again */
+ apriv->fids[index] &= 0xffff;
+ if (index < MAX_FIDS / 2) {
+ if (!test_bit(FLAG_PENDING_XMIT, &apriv->flags))
+ netif_wake_queue(dev);
+ } else {
+ if (!test_bit(FLAG_PENDING_XMIT11, &apriv->flags))
+ netif_wake_queue(apriv->wifidev);
+ }
+ } else {
+ OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
+ printk( KERN_ERR "airo: Unallocated FID was used to xmit\n" );
+ }
+ }
+exittx:
+ if ( status & ~STATUS_INTS & ~IGNORE_INTS )
+ printk( KERN_WARNING "airo: Got weird status %x\n",
+ status & ~STATUS_INTS & ~IGNORE_INTS );
+ }
+
+ if (savedInterrupts)
+ OUT4500( apriv, EVINTEN, savedInterrupts );
+
+ /* done.. */
+ return IRQ_RETVAL(handled);
+}
+
+/*
+ * Routines to talk to the card
+ */
+
+/*
+ * This was originally written for the 4500, hence the name
+ * NOTE: If use with 8bit mode and SMP bad things will happen!
+ * Why would some one do 8 bit IO in an SMP machine?!?
+ */
+static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
+ if (test_bit(FLAG_MPI,&ai->flags))
+ reg <<= 1;
+ if ( !do8bitIO )
+ outw( val, ai->dev->base_addr + reg );
+ else {
+ outb( val & 0xff, ai->dev->base_addr + reg );
+ outb( val >> 8, ai->dev->base_addr + reg + 1 );
+ }
+}
+
+static u16 IN4500( struct airo_info *ai, u16 reg ) {
+ unsigned short rc;
+
+ if (test_bit(FLAG_MPI,&ai->flags))
+ reg <<= 1;
+ if ( !do8bitIO )
+ rc = inw( ai->dev->base_addr + reg );
+ else {
+ rc = inb( ai->dev->base_addr + reg );
+ rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
+ }
+ return rc;
+}
+
+static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
+ int rc;
+ Cmd cmd;
+
+ /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
+ * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
+ * Note : we could try to use !netif_running(dev) in enable_MAC()
+ * instead of this flag, but I don't trust it *within* the
+ * open/close functions, and testing both flags together is
+ * "cheaper" - Jean II */
+ if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
+
+ if (lock && down_interruptible(&ai->sem))
+ return -ERESTARTSYS;
+
+ if (!test_bit(FLAG_ENABLED, &ai->flags)) {
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd = MAC_ENABLE;
+ rc = issuecommand(ai, &cmd, rsp);
+ if (rc == SUCCESS)
+ set_bit(FLAG_ENABLED, &ai->flags);
+ } else
+ rc = SUCCESS;
+
+ if (lock)
+ up(&ai->sem);
+
+ if (rc)
+ printk(KERN_ERR "%s: Cannot enable MAC, err=%d\n",
+ __FUNCTION__,rc);
+ return rc;
+}
+
+static void disable_MAC( struct airo_info *ai, int lock ) {
+ Cmd cmd;
+ Resp rsp;
+
+ if (lock && down_interruptible(&ai->sem))
+ return;
+
+ if (test_bit(FLAG_ENABLED, &ai->flags)) {
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd = MAC_DISABLE; // disable in case already enabled
+ issuecommand(ai, &cmd, &rsp);
+ clear_bit(FLAG_ENABLED, &ai->flags);
+ }
+ if (lock)
+ up(&ai->sem);
+}
+
+static void enable_interrupts( struct airo_info *ai ) {
+ /* Enable the interrupts */
+ OUT4500( ai, EVINTEN, STATUS_INTS );
+}
+
+static void disable_interrupts( struct airo_info *ai ) {
+ OUT4500( ai, EVINTEN, 0 );
+}
+
+static void mpi_receive_802_3(struct airo_info *ai)
+{
+ RxFid rxd;
+ int len = 0;
+ struct sk_buff *skb;
+ char *buffer;
+#ifdef MICSUPPORT
+ int off = 0;
+ MICBuffer micbuf;
+#endif
+
+ memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
+ /* Make sure we got something */
+ if (rxd.rdy && rxd.valid == 0) {
+ len = rxd.len + 12;
+ if (len < 12 || len > 2048)
+ goto badrx;
+
+ skb = dev_alloc_skb(len);
+ if (!skb) {
+ ai->stats.rx_dropped++;
+ goto badrx;
+ }
+ buffer = skb_put(skb,len);
+#ifdef MICSUPPORT
+ memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
+ if (ai->micstats.enabled) {
+ memcpy(&micbuf,
+ ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
+ sizeof(micbuf));
+ if (ntohs(micbuf.typelen) <= 0x05DC) {
+ if (len <= sizeof(micbuf) + ETH_ALEN * 2)
+ goto badmic;
+
+ off = sizeof(micbuf);
+ skb_trim (skb, len - off);
+ }
+ }
+ memcpy(buffer + ETH_ALEN * 2,
+ ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
+ len - ETH_ALEN * 2 - off);
+ if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) {
+badmic:
+ dev_kfree_skb_irq (skb);
+ goto badrx;
+ }
+#else
+ memcpy(buffer, ai->rxfids[0].virtual_host_addr, len);
+#endif
+#ifdef WIRELESS_SPY
+ if (ai->spy_data.spy_number > 0) {
+ char *sa;
+ struct iw_quality wstats;
+ /* Prepare spy data : addr + qual */
+ sa = buffer + ETH_ALEN;
+ wstats.qual = 0; /* XXX Where do I get that info from ??? */
+ wstats.level = 0;
+ wstats.updated = 0;
+ /* Update spy records */
+ wireless_spy_update(ai->dev, sa, &wstats);
+ }
+#endif /* WIRELESS_SPY */
+
+ skb->dev = ai->dev;
+ skb->ip_summed = CHECKSUM_NONE;
+ skb->protocol = eth_type_trans(skb, ai->dev);
+ skb->dev->last_rx = jiffies;
+ netif_rx(skb);
+ }
+badrx:
+ if (rxd.valid == 0) {
+ rxd.valid = 1;
+ rxd.rdy = 0;
+ rxd.len = PKTSIZE;
+ memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
+ }
+}
+
+void mpi_receive_802_11 (struct airo_info *ai)
+{
+ RxFid rxd;
+ struct sk_buff *skb = NULL;
+ u16 fc, len, hdrlen = 0;
+#pragma pack(1)
+ struct {
+ u16 status, len;
+ u8 rssi[2];
+ u8 rate;
+ u8 freq;
+ u16 tmp[4];
+ } hdr;
+#pragma pack()
+ u16 gap;
+ u16 *buffer;
+ char *ptr = ai->rxfids[0].virtual_host_addr+4;
+
+ memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
+ memcpy ((char *)&hdr, ptr, sizeof(hdr));
+ ptr += sizeof(hdr);
+ /* Bad CRC. Ignore packet */
+ if (le16_to_cpu(hdr.status) & 2)
+ hdr.len = 0;
+ if (ai->wifidev == NULL)
+ hdr.len = 0;
+ len = le16_to_cpu(hdr.len);
+ if (len > 2312) {
+ printk( KERN_ERR "airo: Bad size %d\n", len );
+ goto badrx;
+ }
+ if (len == 0)
+ goto badrx;
+
+ memcpy ((char *)&fc, ptr, sizeof(fc));
+ fc = le16_to_cpu(fc);
+ switch (fc & 0xc) {
+ case 4:
+ if ((fc & 0xe0) == 0xc0)
+ hdrlen = 10;
+ else
+ hdrlen = 16;
+ break;
+ case 8:
+ if ((fc&0x300)==0x300){
+ hdrlen = 30;
+ break;
+ }
+ default:
+ hdrlen = 24;
+ }
+
+ skb = dev_alloc_skb( len + hdrlen + 2 );
+ if ( !skb ) {
+ ai->stats.rx_dropped++;
+ goto badrx;
+ }
+ buffer = (u16*)skb_put (skb, len + hdrlen);
+ memcpy ((char *)buffer, ptr, hdrlen);
+ ptr += hdrlen;
+ if (hdrlen == 24)
+ ptr += 6;
+ memcpy ((char *)&gap, ptr, sizeof(gap));
+ ptr += sizeof(gap);
+ gap = le16_to_cpu(gap);
+ if (gap) {
+ if (gap <= 8)
+ ptr += gap;
+ else
+ printk(KERN_ERR
+ "airo: gaplen too big. Problems will follow...\n");
+ }
+ memcpy ((char *)buffer + hdrlen, ptr, len);
+ ptr += len;
+#ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
+ if (ai->spy_data.spy_number > 0) {
+ char *sa;
+ struct iw_quality wstats;
+ /* Prepare spy data : addr + qual */
+ sa = (char*)buffer + 10;
+ wstats.qual = hdr.rssi[0];
+ if (ai->rssi)
+ wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
+ else
+ wstats.level = (hdr.rssi[1] + 321) / 2;
+ wstats.updated = 3;
+ /* Update spy records */
+ wireless_spy_update(ai->dev, sa, &wstats);
+ }
+#endif /* IW_WIRELESS_SPY */
+ skb->mac.raw = skb->data;
+ skb->pkt_type = PACKET_OTHERHOST;
+ skb->dev = ai->wifidev;
+ skb->protocol = htons(ETH_P_802_2);
+ skb->dev->last_rx = jiffies;
+ skb->ip_summed = CHECKSUM_NONE;
+ netif_rx( skb );
+badrx:
+ if (rxd.valid == 0) {
+ rxd.valid = 1;
+ rxd.rdy = 0;
+ rxd.len = PKTSIZE;
+ memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
+ }
+}
+
+static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
+{
+ Cmd cmd;
+ Resp rsp;
+ int status;
+ int i;
+ SsidRid mySsid;
+ u16 lastindex;
+ WepKeyRid wkr;
+ int rc;
+
+ memset( &mySsid, 0, sizeof( mySsid ) );
+ if (ai->flash) {
+ kfree (ai->flash);
+ ai->flash = NULL;
+ }
+
+ /* The NOP is the first step in getting the card going */
+ cmd.cmd = NOP;
+ cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
+ if (lock && down_interruptible(&ai->sem))
+ return ERROR;
+ if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
+ if (lock)
+ up(&ai->sem);
+ return ERROR;
+ }
+ disable_MAC( ai, 0);
+
+ // Let's figure out if we need to use the AUX port
+ if (!test_bit(FLAG_MPI,&ai->flags)) {
+ cmd.cmd = CMD_ENABLEAUX;
+ if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
+ if (lock)
+ up(&ai->sem);
+ printk(KERN_ERR "airo: Error checking for AUX port\n");
+ return ERROR;
+ }
+ if (!aux_bap || rsp.status & 0xff00) {
+ ai->bap_read = fast_bap_read;
+ printk(KERN_DEBUG "airo: Doing fast bap_reads\n");
+ } else {
+ ai->bap_read = aux_bap_read;
+ printk(KERN_DEBUG "airo: Doing AUX bap_reads\n");
+ }
+ }
+ if (lock)
+ up(&ai->sem);
+ if (ai->config.len == 0) {
+ tdsRssiRid rssi_rid;
+ CapabilityRid cap_rid;
+
+ if (ai->APList) {
+ kfree(ai->APList);
+ ai->APList = NULL;
+ }
+ if (ai->SSID) {
+ kfree(ai->SSID);
+ ai->SSID = NULL;
+ }
+ // general configuration (read/modify/write)
+ status = readConfigRid(ai, lock);
+ if ( status != SUCCESS ) return ERROR;
+
+ status = readCapabilityRid(ai, &cap_rid, lock);
+ if ( status != SUCCESS ) return ERROR;
+
+ status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
+ if ( status == SUCCESS ) {
+ if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
+ memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512);
+ }
+ else {
+ if (ai->rssi) {
+ kfree(ai->rssi);
+ ai->rssi = NULL;
+ }
+ if (cap_rid.softCap & 8)
+ ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
+ else
+ printk(KERN_WARNING "airo: unknown received signal level scale\n");
+ }
+ ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
+ ai->config.authType = AUTH_OPEN;
+ ai->config.modulation = MOD_CCK;
+
+#ifdef MICSUPPORT
+ if ((cap_rid.len>=sizeof(cap_rid)) && (cap_rid.extSoftCap&1) &&
+ (micsetup(ai) == SUCCESS)) {
+ ai->config.opmode |= MODE_MIC;
+ set_bit(FLAG_MIC_CAPABLE, &ai->flags);
+ }
+#endif
+
+ /* Save off the MAC */
+ for( i = 0; i < ETH_ALEN; i++ ) {
+ mac[i] = ai->config.macAddr[i];
+ }
+
+ /* Check to see if there are any insmod configured
+ rates to add */
+ if ( rates[0] ) {
+ int i = 0;
+ memset(ai->config.rates,0,sizeof(ai->config.rates));
+ for( i = 0; i < 8 && rates[i]; i++ ) {
+ ai->config.rates[i] = rates[i];
+ }
+ }
+ if ( basic_rate > 0 ) {
+ int i;
+ for( i = 0; i < 8; i++ ) {
+ if ( ai->config.rates[i] == basic_rate ||
+ !ai->config.rates ) {
+ ai->config.rates[i] = basic_rate | 0x80;
+ break;
+ }
+ }
+ }
+ set_bit (FLAG_COMMIT, &ai->flags);
+ }
+
+ /* Setup the SSIDs if present */
+ if ( ssids[0] ) {
+ int i;
+ for( i = 0; i < 3 && ssids[i]; i++ ) {
+ mySsid.ssids[i].len = strlen(ssids[i]);
+ if ( mySsid.ssids[i].len > 32 )
+ mySsid.ssids[i].len = 32;
+ memcpy(mySsid.ssids[i].ssid, ssids[i],
+ mySsid.ssids[i].len);
+ }
+ mySsid.len = sizeof(mySsid);
+ }
+
+ status = writeConfigRid(ai, lock);
+ if ( status != SUCCESS ) return ERROR;
+
+ /* Set up the SSID list */
+ if ( ssids[0] ) {
+ status = writeSsidRid(ai, &mySsid, lock);
+ if ( status != SUCCESS ) return ERROR;
+ }
+
+ status = enable_MAC(ai, &rsp, lock);
+ if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) {
+ printk( KERN_ERR "airo: Bad MAC enable reason = %x, rid = %x, offset = %d\n", rsp.rsp0, rsp.rsp1, rsp.rsp2 );
+ return ERROR;
+ }
+
+ /* Grab the initial wep key, we gotta save it for auto_wep */
+ rc = readWepKeyRid(ai, &wkr, 1, lock);
+ if (rc == SUCCESS) do {
+ lastindex = wkr.kindex;
+ if (wkr.kindex == 0xffff) {
+ ai->defindex = wkr.mac[0];
+ }
+ rc = readWepKeyRid(ai, &wkr, 0, lock);
+ } while(lastindex != wkr.kindex);
+
+ if (auto_wep) {
+ ai->expires = RUN_AT(3*HZ);
+ wake_up_interruptible(&ai->thr_wait);
+ }
+
+ return SUCCESS;
+}
+
+static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
+ // Im really paranoid about letting it run forever!
+ int max_tries = 600000;
+
+ if (IN4500(ai, EVSTAT) & EV_CMD)
+ OUT4500(ai, EVACK, EV_CMD);
+
+ OUT4500(ai, PARAM0, pCmd->parm0);
+ OUT4500(ai, PARAM1, pCmd->parm1);
+ OUT4500(ai, PARAM2, pCmd->parm2);
+ OUT4500(ai, COMMAND, pCmd->cmd);
+
+ while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
+ if ((IN4500(ai, COMMAND)) == pCmd->cmd)
+ // PC4500 didn't notice command, try again
+ OUT4500(ai, COMMAND, pCmd->cmd);
+ if (!in_atomic() && (max_tries & 255) == 0)
+ schedule();
+ }
+
+ if ( max_tries == -1 ) {
+ printk( KERN_ERR
+ "airo: Max tries exceeded when issueing command\n" );
+ if (IN4500(ai, COMMAND) & COMMAND_BUSY)
+ OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
+ return ERROR;
+ }
+
+ // command completed
+ pRsp->status = IN4500(ai, STATUS);
+ pRsp->rsp0 = IN4500(ai, RESP0);
+ pRsp->rsp1 = IN4500(ai, RESP1);
+ pRsp->rsp2 = IN4500(ai, RESP2);
+ if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) {
+ printk (KERN_ERR "airo: cmd= %x\n", pCmd->cmd);
+ printk (KERN_ERR "airo: status= %x\n", pRsp->status);
+ printk (KERN_ERR "airo: Rsp0= %x\n", pRsp->rsp0);
+ printk (KERN_ERR "airo: Rsp1= %x\n", pRsp->rsp1);
+ printk (KERN_ERR "airo: Rsp2= %x\n", pRsp->rsp2);
+ }
+
+ // clear stuck command busy if necessary
+ if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
+ OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
+ }
+ // acknowledge processing the status/response
+ OUT4500(ai, EVACK, EV_CMD);
+
+ return SUCCESS;
+}
+
+/* Sets up the bap to start exchange data. whichbap should
+ * be one of the BAP0 or BAP1 defines. Locks should be held before
+ * calling! */
+static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
+{
+ int timeout = 50;
+ int max_tries = 3;
+
+ OUT4500(ai, SELECT0+whichbap, rid);
+ OUT4500(ai, OFFSET0+whichbap, offset);
+ while (1) {
+ int status = IN4500(ai, OFFSET0+whichbap);
+ if (status & BAP_BUSY) {
+ /* This isn't really a timeout, but its kinda
+ close */
+ if (timeout--) {
+ continue;
+ }
+ } else if ( status & BAP_ERR ) {
+ /* invalid rid or offset */
+ printk( KERN_ERR "airo: BAP error %x %d\n",
+ status, whichbap );
+ return ERROR;
+ } else if (status & BAP_DONE) { // success
+ return SUCCESS;
+ }
+ if ( !(max_tries--) ) {
+ printk( KERN_ERR
+ "airo: BAP setup error too many retries\n" );
+ return ERROR;
+ }
+ // -- PC4500 missed it, try again
+ OUT4500(ai, SELECT0+whichbap, rid);
+ OUT4500(ai, OFFSET0+whichbap, offset);
+ timeout = 50;
+ }
+}
+
+/* should only be called by aux_bap_read. This aux function and the
+ following use concepts not documented in the developers guide. I
+ got them from a patch given to my by Aironet */
+static u16 aux_setup(struct airo_info *ai, u16 page,
+ u16 offset, u16 *len)
+{
+ u16 next;
+
+ OUT4500(ai, AUXPAGE, page);
+ OUT4500(ai, AUXOFF, 0);
+ next = IN4500(ai, AUXDATA);
+ *len = IN4500(ai, AUXDATA)&0xff;
+ if (offset != 4) OUT4500(ai, AUXOFF, offset);
+ return next;
+}
+
+/* requires call to bap_setup() first */
+static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst,
+ int bytelen, int whichbap)
+{
+ u16 len;
+ u16 page;
+ u16 offset;
+ u16 next;
+ int words;
+ int i;
+ unsigned long flags;
+
+ spin_lock_irqsave(&ai->aux_lock, flags);
+ page = IN4500(ai, SWS0+whichbap);
+ offset = IN4500(ai, SWS2+whichbap);
+ next = aux_setup(ai, page, offset, &len);
+ words = (bytelen+1)>>1;
+
+ for (i=0; i<words;) {
+ int count;
+ count = (len>>1) < (words-i) ? (len>>1) : (words-i);
+ if ( !do8bitIO )
+ insw( ai->dev->base_addr+DATA0+whichbap,
+ pu16Dst+i,count );
+ else
+ insb( ai->dev->base_addr+DATA0+whichbap,
+ pu16Dst+i, count << 1 );
+ i += count;
+ if (i<words) {
+ next = aux_setup(ai, next, 4, &len);
+ }
+ }
+ spin_unlock_irqrestore(&ai->aux_lock, flags);
+ return SUCCESS;
+}
+
+
+/* requires call to bap_setup() first */
+static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst,
+ int bytelen, int whichbap)
+{
+ bytelen = (bytelen + 1) & (~1); // round up to even value
+ if ( !do8bitIO )
+ insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
+ else
+ insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
+ return SUCCESS;
+}
+
+/* requires call to bap_setup() first */
+static int bap_write(struct airo_info *ai, const u16 *pu16Src,
+ int bytelen, int whichbap)
+{
+ bytelen = (bytelen + 1) & (~1); // round up to even value
+ if ( !do8bitIO )
+ outsw( ai->dev->base_addr+DATA0+whichbap,
+ pu16Src, bytelen>>1 );
+ else
+ outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
+ return SUCCESS;
+}
+
+static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
+{
+ Cmd cmd; /* for issuing commands */
+ Resp rsp; /* response from commands */
+ u16 status;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd = accmd;
+ cmd.parm0 = rid;
+ status = issuecommand(ai, &cmd, &rsp);
+ if (status != 0) return status;
+ if ( (rsp.status & 0x7F00) != 0) {
+ return (accmd << 8) + (rsp.rsp0 & 0xFF);
+ }
+ return 0;
+}
+
+/* Note, that we are using BAP1 which is also used by transmit, so
+ * we must get a lock. */
+static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
+{
+ u16 status;
+ int rc = SUCCESS;
+
+ if (lock) {
+ if (down_interruptible(&ai->sem))
+ return ERROR;
+ }
+ if (test_bit(FLAG_MPI,&ai->flags)) {
+ Cmd cmd;
+ Resp rsp;
+
+ memset(&cmd, 0, sizeof(cmd));
+ memset(&rsp, 0, sizeof(rsp));
+ ai->config_desc.rid_desc.valid = 1;
+ ai->config_desc.rid_desc.len = RIDSIZE;
+ ai->config_desc.rid_desc.rid = 0;
+ ai->config_desc.rid_desc.host_addr = ai->ridbus;
+
+ cmd.cmd = CMD_ACCESS;
+ cmd.parm0 = rid;
+
+ memcpy_toio(ai->config_desc.card_ram_off,
+ &ai->config_desc.rid_desc, sizeof(Rid));
+
+ rc = issuecommand(ai, &cmd, &rsp);
+
+ if (rsp.status & 0x7f00)
+ rc = rsp.rsp0;
+ if (!rc)
+ memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
+ goto done;
+ } else {
+ if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
+ rc = status;
+ goto done;
+ }
+ if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
+ rc = ERROR;
+ goto done;
+ }
+ // read the rid length field
+ bap_read(ai, pBuf, 2, BAP1);
+ // length for remaining part of rid
+ len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2;
+
+ if ( len <= 2 ) {
+ printk( KERN_ERR
+ "airo: Rid %x has a length of %d which is too short\n",
+ (int)rid, (int)len );
+ rc = ERROR;
+ goto done;
+ }
+ // read remainder of the rid
+ rc = bap_read(ai, ((u16*)pBuf)+1, len, BAP1);
+ }
+done:
+ if (lock)
+ up(&ai->sem);
+ return rc;
+}
+
+/* Note, that we are using BAP1 which is also used by transmit, so
+ * make sure this isnt called when a transmit is happening */
+static int PC4500_writerid(struct airo_info *ai, u16 rid,
+ const void *pBuf, int len, int lock)
+{
+ u16 status;
+ int rc = SUCCESS;
+
+ *(u16*)pBuf = cpu_to_le16((u16)len);
+
+ if (lock) {
+ if (down_interruptible(&ai->sem))
+ return ERROR;
+ }
+ if (test_bit(FLAG_MPI,&ai->flags)) {
+ Cmd cmd;
+ Resp rsp;
+
+ if (test_bit(FLAG_ENABLED, &ai->flags))
+ printk(KERN_ERR
+ "%s: MAC should be disabled (rid=%04x)\n",
+ __FUNCTION__, rid);
+ memset(&cmd, 0, sizeof(cmd));
+ memset(&rsp, 0, sizeof(rsp));
+
+ ai->config_desc.rid_desc.valid = 1;
+ ai->config_desc.rid_desc.len = *((u16 *)pBuf);
+ ai->config_desc.rid_desc.rid = 0;
+
+ cmd.cmd = CMD_WRITERID;
+ cmd.parm0 = rid;
+
+ memcpy_toio(ai->config_desc.card_ram_off,
+ &ai->config_desc.rid_desc, sizeof(Rid));
+
+ if (len < 4 || len > 2047) {
+ printk(KERN_ERR "%s: len=%d\n",__FUNCTION__,len);
+ rc = -1;
+ } else {
+ memcpy((char *)ai->config_desc.virtual_host_addr,
+ pBuf, len);
+
+ rc = issuecommand(ai, &cmd, &rsp);
+ if ((rc & 0xff00) != 0) {
+ printk(KERN_ERR "%s: Write rid Error %d\n",
+ __FUNCTION__,rc);
+ printk(KERN_ERR "%s: Cmd=%04x\n",
+ __FUNCTION__,cmd.cmd);
+ }
+
+ if ((rsp.status & 0x7f00))
+ rc = rsp.rsp0;
+ }
+ } else {
+ // --- first access so that we can write the rid data
+ if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
+ rc = status;
+ goto done;
+ }
+ // --- now write the rid data
+ if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
+ rc = ERROR;
+ goto done;
+ }
+ bap_write(ai, pBuf, len, BAP1);
+ // ---now commit the rid data
+ rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
+ }
+done:
+ if (lock)
+ up(&ai->sem);
+ return rc;
+}
+
+/* Allocates a FID to be used for transmitting packets. We only use
+ one for now. */
+static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
+{
+ unsigned int loop = 3000;
+ Cmd cmd;
+ Resp rsp;
+ u16 txFid;
+ u16 txControl;
+
+ cmd.cmd = CMD_ALLOCATETX;
+ cmd.parm0 = lenPayload;
+ if (down_interruptible(&ai->sem))
+ return ERROR;
+ if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
+ txFid = ERROR;
+ goto done;
+ }
+ if ( (rsp.status & 0xFF00) != 0) {
+ txFid = ERROR;
+ goto done;
+ }
+ /* wait for the allocate event/indication
+ * It makes me kind of nervous that this can just sit here and spin,
+ * but in practice it only loops like four times. */
+ while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
+ if (!loop) {
+ txFid = ERROR;
+ goto done;
+ }
+
+ // get the allocated fid and acknowledge
+ txFid = IN4500(ai, TXALLOCFID);
+ OUT4500(ai, EVACK, EV_ALLOC);
+
+ /* The CARD is pretty cool since it converts the ethernet packet
+ * into 802.11. Also note that we don't release the FID since we
+ * will be using the same one over and over again. */
+ /* We only have to setup the control once since we are not
+ * releasing the fid. */
+ if (raw)
+ txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
+ | TXCTL_ETHERNET | TXCTL_NORELEASE);
+ else
+ txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
+ | TXCTL_ETHERNET | TXCTL_NORELEASE);
+ if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
+ txFid = ERROR;
+ else
+ bap_write(ai, &txControl, sizeof(txControl), BAP1);
+
+done:
+ up(&ai->sem);
+
+ return txFid;
+}
+
+/* In general BAP1 is dedicated to transmiting packets. However,
+ since we need a BAP when accessing RIDs, we also use BAP1 for that.
+ Make sure the BAP1 spinlock is held when this is called. */
+static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
+{
+ u16 payloadLen;
+ Cmd cmd;
+ Resp rsp;
+ int miclen = 0;
+ u16 txFid = len;
+ MICBuffer pMic;
+
+ len >>= 16;
+
+ if (len <= ETH_ALEN * 2) {
+ printk( KERN_WARNING "Short packet %d\n", len );
+ return ERROR;
+ }
+ len -= ETH_ALEN * 2;
+
+#ifdef MICSUPPORT
+ if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
+ (ntohs(((u16 *)pPacket)[6]) != 0x888E)) {
+ if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
+ return ERROR;
+ miclen = sizeof(pMic);
+ }
+#endif
+
+ // packet is destination[6], source[6], payload[len-12]
+ // write the payload length and dst/src/payload
+ if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
+ /* The hardware addresses aren't counted as part of the payload, so
+ * we have to subtract the 12 bytes for the addresses off */
+ payloadLen = cpu_to_le16(len + miclen);
+ bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
+ bap_write(ai, (const u16*)pPacket, sizeof(etherHead), BAP1);
+ if (miclen)
+ bap_write(ai, (const u16*)&pMic, miclen, BAP1);
+ bap_write(ai, (const u16*)(pPacket + sizeof(etherHead)), len, BAP1);
+ // issue the transmit command
+ memset( &cmd, 0, sizeof( cmd ) );
+ cmd.cmd = CMD_TRANSMIT;
+ cmd.parm0 = txFid;
+ if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
+ if ( (rsp.status & 0xFF00) != 0) return ERROR;
+ return SUCCESS;
+}
+
+static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
+{
+ u16 fc, payloadLen;
+ Cmd cmd;
+ Resp rsp;
+ int hdrlen;
+ struct {
+ u8 addr4[ETH_ALEN];
+ u16 gaplen;
+ u8 gap[6];
+ } gap;
+ u16 txFid = len;
+ len >>= 16;
+ gap.gaplen = 6;
+
+ fc = le16_to_cpu(*(const u16*)pPacket);
+ switch (fc & 0xc) {
+ case 4:
+ if ((fc & 0xe0) == 0xc0)
+ hdrlen = 10;
+ else
+ hdrlen = 16;
+ break;
+ case 8:
+ if ((fc&0x300)==0x300){
+ hdrlen = 30;
+ break;
+ }
+ default:
+ hdrlen = 24;
+ }
+
+ if (len < hdrlen) {
+ printk( KERN_WARNING "Short packet %d\n", len );
+ return ERROR;
+ }
+
+ /* packet is 802.11 header + payload
+ * write the payload length and dst/src/payload */
+ if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
+ /* The 802.11 header aren't counted as part of the payload, so
+ * we have to subtract the header bytes off */
+ payloadLen = cpu_to_le16(len-hdrlen);
+ bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
+ if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
+ bap_write(ai, (const u16*)pPacket, hdrlen, BAP1);
+ bap_write(ai, hdrlen == 30 ?
+ (const u16*)&gap.gaplen : (const u16*)&gap, 38 - hdrlen, BAP1);
+
+ bap_write(ai, (const u16*)(pPacket + hdrlen), len - hdrlen, BAP1);
+ // issue the transmit command
+ memset( &cmd, 0, sizeof( cmd ) );
+ cmd.cmd = CMD_TRANSMIT;
+ cmd.parm0 = txFid;
+ if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
+ if ( (rsp.status & 0xFF00) != 0) return ERROR;
+ return SUCCESS;
+}
+
+/*
+ * This is the proc_fs routines. It is a bit messier than I would
+ * like! Feel free to clean it up!
+ */
+
+static ssize_t proc_read( struct file *file,
+ char __user *buffer,
+ size_t len,
+ loff_t *offset);
+
+static ssize_t proc_write( struct file *file,
+ const char __user *buffer,
+ size_t len,
+ loff_t *offset );
+static int proc_close( struct inode *inode, struct file *file );
+
+static int proc_stats_open( struct inode *inode, struct file *file );
+static int proc_statsdelta_open( struct inode *inode, struct file *file );
+static int proc_status_open( struct inode *inode, struct file *file );
+static int proc_SSID_open( struct inode *inode, struct file *file );
+static int proc_APList_open( struct inode *inode, struct file *file );
+static int proc_BSSList_open( struct inode *inode, struct file *file );
+static int proc_config_open( struct inode *inode, struct file *file );
+static int proc_wepkey_open( struct inode *inode, struct file *file );
+
+static struct file_operations proc_statsdelta_ops = {
+ .read = proc_read,
+ .open = proc_statsdelta_open,
+ .release = proc_close
+};
+
+static struct file_operations proc_stats_ops = {
+ .read = proc_read,
+ .open = proc_stats_open,
+ .release = proc_close
+};
+
+static struct file_operations proc_status_ops = {
+ .read = proc_read,
+ .open = proc_status_open,
+ .release = proc_close
+};
+
+static struct file_operations proc_SSID_ops = {
+ .read = proc_read,
+ .write = proc_write,
+ .open = proc_SSID_open,
+ .release = proc_close
+};
+
+static struct file_operations proc_BSSList_ops = {
+ .read = proc_read,
+ .write = proc_write,
+ .open = proc_BSSList_open,
+ .release = proc_close
+};
+
+static struct file_operations proc_APList_ops = {
+ .read = proc_read,
+ .write = proc_write,
+ .open = proc_APList_open,
+ .release = proc_close
+};
+
+static struct file_operations proc_config_ops = {
+ .read = proc_read,
+ .write = proc_write,
+ .open = proc_config_open,
+ .release = proc_close
+};
+
+static struct file_operations proc_wepkey_ops = {
+ .read = proc_read,
+ .write = proc_write,
+ .open = proc_wepkey_open,
+ .release = proc_close
+};
+
+static struct proc_dir_entry *airo_entry;
+
+struct proc_data {
+ int release_buffer;
+ int readlen;
+ char *rbuffer;
+ int writelen;
+ int maxwritelen;
+ char *wbuffer;
+ void (*on_close) (struct inode *, struct file *);
+};
+
+#ifndef SETPROC_OPS
+#define SETPROC_OPS(entry, ops) (entry)->proc_fops = &(ops)
+#endif
+
+static int setup_proc_entry( struct net_device *dev,
+ struct airo_info *apriv ) {
+ struct proc_dir_entry *entry;
+ /* First setup the device directory */
+ strcpy(apriv->proc_name,dev->name);
+ apriv->proc_entry = create_proc_entry(apriv->proc_name,
+ S_IFDIR|airo_perm,
+ airo_entry);
+ apriv->proc_entry->uid = proc_uid;
+ apriv->proc_entry->gid = proc_gid;
+ apriv->proc_entry->owner = THIS_MODULE;
+
+ /* Setup the StatsDelta */
+ entry = create_proc_entry("StatsDelta",
+ S_IFREG | (S_IRUGO&proc_perm),
+ apriv->proc_entry);
+ entry->uid = proc_uid;
+ entry->gid = proc_gid;
+ entry->data = dev;
+ entry->owner = THIS_MODULE;
+ SETPROC_OPS(entry, proc_statsdelta_ops);
+
+ /* Setup the Stats */
+ entry = create_proc_entry("Stats",
+ S_IFREG | (S_IRUGO&proc_perm),
+ apriv->proc_entry);
+ entry->uid = proc_uid;
+ entry->gid = proc_gid;
+ entry->data = dev;
+ entry->owner = THIS_MODULE;
+ SETPROC_OPS(entry, proc_stats_ops);
+
+ /* Setup the Status */
+ entry = create_proc_entry("Status",
+ S_IFREG | (S_IRUGO&proc_perm),
+ apriv->proc_entry);
+ entry->uid = proc_uid;
+ entry->gid = proc_gid;
+ entry->data = dev;
+ entry->owner = THIS_MODULE;
+ SETPROC_OPS(entry, proc_status_ops);
+
+ /* Setup the Config */
+ entry = create_proc_entry("Config",
+ S_IFREG | proc_perm,
+ apriv->proc_entry);
+ entry->uid = proc_uid;
+ entry->gid = proc_gid;
+ entry->data = dev;
+ entry->owner = THIS_MODULE;
+ SETPROC_OPS(entry, proc_config_ops);
+
+ /* Setup the SSID */
+ entry = create_proc_entry("SSID",
+ S_IFREG | proc_perm,
+ apriv->proc_entry);
+ entry->uid = proc_uid;
+ entry->gid = proc_gid;
+ entry->data = dev;
+ entry->owner = THIS_MODULE;
+ SETPROC_OPS(entry, proc_SSID_ops);
+
+ /* Setup the APList */
+ entry = create_proc_entry("APList",
+ S_IFREG | proc_perm,
+ apriv->proc_entry);
+ entry->uid = proc_uid;
+ entry->gid = proc_gid;
+ entry->data = dev;
+ entry->owner = THIS_MODULE;
+ SETPROC_OPS(entry, proc_APList_ops);
+
+ /* Setup the BSSList */
+ entry = create_proc_entry("BSSList",
+ S_IFREG | proc_perm,
+ apriv->proc_entry);
+ entry->uid = proc_uid;
+ entry->gid = proc_gid;
+ entry->data = dev;
+ entry->owner = THIS_MODULE;
+ SETPROC_OPS(entry, proc_BSSList_ops);
+
+ /* Setup the WepKey */
+ entry = create_proc_entry("WepKey",
+ S_IFREG | proc_perm,
+ apriv->proc_entry);
+ entry->uid = proc_uid;
+ entry->gid = proc_gid;
+ entry->data = dev;
+ entry->owner = THIS_MODULE;
+ SETPROC_OPS(entry, proc_wepkey_ops);
+
+ return 0;
+}
+
+static int takedown_proc_entry( struct net_device *dev,
+ struct airo_info *apriv ) {
+ if ( !apriv->proc_entry->namelen ) return 0;
+ remove_proc_entry("Stats",apriv->proc_entry);
+ remove_proc_entry("StatsDelta",apriv->proc_entry);
+ remove_proc_entry("Status",apriv->proc_entry);
+ remove_proc_entry("Config",apriv->proc_entry);
+ remove_proc_entry("SSID",apriv->proc_entry);
+ remove_proc_entry("APList",apriv->proc_entry);
+ remove_proc_entry("BSSList",apriv->proc_entry);
+ remove_proc_entry("WepKey",apriv->proc_entry);
+ remove_proc_entry(apriv->proc_name,airo_entry);
+ return 0;
+}
+
+/*
+ * What we want from the proc_fs is to be able to efficiently read
+ * and write the configuration. To do this, we want to read the
+ * configuration when the file is opened and write it when the file is
+ * closed. So basically we allocate a read buffer at open and fill it
+ * with data, and allocate a write buffer and read it at close.
+ */
+
+/*
+ * The read routine is generic, it relies on the preallocated rbuffer
+ * to supply the data.
+ */
+static ssize_t proc_read( struct file *file,
+ char __user *buffer,
+ size_t len,
+ loff_t *offset )
+{
+ loff_t pos = *offset;
+ struct proc_data *priv = (struct proc_data*)file->private_data;
+
+ if (!priv->rbuffer)
+ return -EINVAL;
+
+ if (pos < 0)
+ return -EINVAL;
+ if (pos >= priv->readlen)
+ return 0;
+ if (len > priv->readlen - pos)
+ len = priv->readlen - pos;
+ if (copy_to_user(buffer, priv->rbuffer + pos, len))
+ return -EFAULT;
+ *offset = pos + len;
+ return len;
+}
+
+/*
+ * The write routine is generic, it fills in a preallocated rbuffer
+ * to supply the data.
+ */
+static ssize_t proc_write( struct file *file,
+ const char __user *buffer,
+ size_t len,
+ loff_t *offset )
+{
+ loff_t pos = *offset;
+ struct proc_data *priv = (struct proc_data*)file->private_data;
+
+ if (!priv->wbuffer)
+ return -EINVAL;
+
+ if (pos < 0)
+ return -EINVAL;
+ if (pos >= priv->maxwritelen)
+ return 0;
+ if (len > priv->maxwritelen - pos)
+ len = priv->maxwritelen - pos;
+ if (copy_from_user(priv->wbuffer + pos, buffer, len))
+ return -EFAULT;
+ if ( pos + len > priv->writelen )
+ priv->writelen = len + file->f_pos;
+ *offset = pos + len;
+ return len;
+}
+
+static int proc_status_open( struct inode *inode, struct file *file ) {
+ struct proc_data *data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *apriv = dev->priv;
+ CapabilityRid cap_rid;
+ StatusRid status_rid;
+ int i;
+
+ if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ memset(file->private_data, 0, sizeof(struct proc_data));
+ data = (struct proc_data *)file->private_data;
+ if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+
+ readStatusRid(apriv, &status_rid, 1);
+ readCapabilityRid(apriv, &cap_rid, 1);
+
+ i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
+ status_rid.mode & 1 ? "CFG ": "",
+ status_rid.mode & 2 ? "ACT ": "",
+ status_rid.mode & 0x10 ? "SYN ": "",
+ status_rid.mode & 0x20 ? "LNK ": "",
+ status_rid.mode & 0x40 ? "LEAP ": "",
+ status_rid.mode & 0x80 ? "PRIV ": "",
+ status_rid.mode & 0x100 ? "KEY ": "",
+ status_rid.mode & 0x200 ? "WEP ": "",
+ status_rid.mode & 0x8000 ? "ERR ": "");
+ sprintf( data->rbuffer+i, "Mode: %x\n"
+ "Signal Strength: %d\n"
+ "Signal Quality: %d\n"
+ "SSID: %-.*s\n"
+ "AP: %-.16s\n"
+ "Freq: %d\n"
+ "BitRate: %dmbs\n"
+ "Driver Version: %s\n"
+ "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
+ "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
+ "Software Version: %x\nSoftware Subversion: %x\n"
+ "Boot block version: %x\n",
+ (int)status_rid.mode,
+ (int)status_rid.normalizedSignalStrength,
+ (int)status_rid.signalQuality,
+ (int)status_rid.SSIDlen,
+ status_rid.SSID,
+ status_rid.apName,
+ (int)status_rid.channel,
+ (int)status_rid.currentXmitRate/2,
+ version,
+ cap_rid.prodName,
+ cap_rid.manName,
+ cap_rid.prodVer,
+ cap_rid.radioType,
+ cap_rid.country,
+ cap_rid.hardVer,
+ (int)cap_rid.softVer,
+ (int)cap_rid.softSubVer,
+ (int)cap_rid.bootBlockVer );
+ data->readlen = strlen( data->rbuffer );
+ return 0;
+}
+
+static int proc_stats_rid_open(struct inode*, struct file*, u16);
+static int proc_statsdelta_open( struct inode *inode,
+ struct file *file ) {
+ if (file->f_mode&FMODE_WRITE) {
+ return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
+ }
+ return proc_stats_rid_open(inode, file, RID_STATSDELTA);
+}
+
+static int proc_stats_open( struct inode *inode, struct file *file ) {
+ return proc_stats_rid_open(inode, file, RID_STATS);
+}
+
+static int proc_stats_rid_open( struct inode *inode,
+ struct file *file,
+ u16 rid ) {
+ struct proc_data *data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *apriv = dev->priv;
+ StatsRid stats;
+ int i, j;
+ u32 *vals = stats.vals;
+
+ if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ memset(file->private_data, 0, sizeof(struct proc_data));
+ data = (struct proc_data *)file->private_data;
+ if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+
+ readStatsRid(apriv, &stats, rid, 1);
+
+ j = 0;
+ for(i=0; statsLabels[i]!=(char *)-1 &&
+ i*4<stats.len; i++){
+ if (!statsLabels[i]) continue;
+ if (j+strlen(statsLabels[i])+16>4096) {
+ printk(KERN_WARNING
+ "airo: Potentially disasterous buffer overflow averted!\n");
+ break;
+ }
+ j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]);
+ }
+ if (i*4>=stats.len){
+ printk(KERN_WARNING
+ "airo: Got a short rid\n");
+ }
+ data->readlen = j;
+ return 0;
+}
+
+static int get_dec_u16( char *buffer, int *start, int limit ) {
+ u16 value;
+ int valid = 0;
+ for( value = 0; buffer[*start] >= '0' &&
+ buffer[*start] <= '9' &&
+ *start < limit; (*start)++ ) {
+ valid = 1;
+ value *= 10;
+ value += buffer[*start] - '0';
+ }
+ if ( !valid ) return -1;
+ return value;
+}
+
+static int airo_config_commit(struct net_device *dev,
+ struct iw_request_info *info, void *zwrq,
+ char *extra);
+
+static void proc_config_on_close( struct inode *inode, struct file *file ) {
+ struct proc_data *data = file->private_data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ char *line;
+
+ if ( !data->writelen ) return;
+
+ readConfigRid(ai, 1);
+ set_bit (FLAG_COMMIT, &ai->flags);
+
+ line = data->wbuffer;
+ while( line[0] ) {
+/*** Mode processing */
+ if ( !strncmp( line, "Mode: ", 6 ) ) {
+ line += 6;
+ if ((ai->config.rmode & 0xff) >= RXMODE_RFMON)
+ set_bit (FLAG_RESET, &ai->flags);
+ ai->config.rmode &= 0xfe00;
+ clear_bit (FLAG_802_11, &ai->flags);
+ ai->config.opmode &= 0xFF00;
+ ai->config.scanMode = SCANMODE_ACTIVE;
+ if ( line[0] == 'a' ) {
+ ai->config.opmode |= 0;
+ } else {
+ ai->config.opmode |= 1;
+ if ( line[0] == 'r' ) {
+ ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
+ ai->config.scanMode = SCANMODE_PASSIVE;
+ set_bit (FLAG_802_11, &ai->flags);
+ } else if ( line[0] == 'y' ) {
+ ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
+ ai->config.scanMode = SCANMODE_PASSIVE;
+ set_bit (FLAG_802_11, &ai->flags);
+ } else if ( line[0] == 'l' )
+ ai->config.rmode |= RXMODE_LANMON;
+ }
+ set_bit (FLAG_COMMIT, &ai->flags);
+ }
+
+/*** Radio status */
+ else if (!strncmp(line,"Radio: ", 7)) {
+ line += 7;
+ if (!strncmp(line,"off",3)) {
+ set_bit (FLAG_RADIO_OFF, &ai->flags);
+ } else {
+ clear_bit (FLAG_RADIO_OFF, &ai->flags);
+ }
+ }
+/*** NodeName processing */
+ else if ( !strncmp( line, "NodeName: ", 10 ) ) {
+ int j;
+
+ line += 10;
+ memset( ai->config.nodeName, 0, 16 );
+/* Do the name, assume a space between the mode and node name */
+ for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
+ ai->config.nodeName[j] = line[j];
+ }
+ set_bit (FLAG_COMMIT, &ai->flags);
+ }
+
+/*** PowerMode processing */
+ else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
+ line += 11;
+ if ( !strncmp( line, "PSPCAM", 6 ) ) {
+ ai->config.powerSaveMode = POWERSAVE_PSPCAM;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "PSP", 3 ) ) {
+ ai->config.powerSaveMode = POWERSAVE_PSP;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else {
+ ai->config.powerSaveMode = POWERSAVE_CAM;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ }
+ } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
+ int v, i = 0, k = 0; /* i is index into line,
+ k is index to rates */
+
+ line += 11;
+ while((v = get_dec_u16(line, &i, 3))!=-1) {
+ ai->config.rates[k++] = (u8)v;
+ line += i + 1;
+ i = 0;
+ }
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "Channel: ", 9 ) ) {
+ int v, i = 0;
+ line += 9;
+ v = get_dec_u16(line, &i, i+3);
+ if ( v != -1 ) {
+ ai->config.channelSet = (u16)v;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ }
+ } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
+ int v, i = 0;
+ line += 11;
+ v = get_dec_u16(line, &i, i+3);
+ if ( v != -1 ) {
+ ai->config.txPower = (u16)v;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ }
+ } else if ( !strncmp( line, "WEP: ", 5 ) ) {
+ line += 5;
+ switch( line[0] ) {
+ case 's':
+ ai->config.authType = (u16)AUTH_SHAREDKEY;
+ break;
+ case 'e':
+ ai->config.authType = (u16)AUTH_ENCRYPT;
+ break;
+ default:
+ ai->config.authType = (u16)AUTH_OPEN;
+ break;
+ }
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
+ int v, i = 0;
+
+ line += 16;
+ v = get_dec_u16(line, &i, 3);
+ v = (v<0) ? 0 : ((v>255) ? 255 : v);
+ ai->config.longRetryLimit = (u16)v;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
+ int v, i = 0;
+
+ line += 17;
+ v = get_dec_u16(line, &i, 3);
+ v = (v<0) ? 0 : ((v>255) ? 255 : v);
+ ai->config.shortRetryLimit = (u16)v;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
+ int v, i = 0;
+
+ line += 14;
+ v = get_dec_u16(line, &i, 4);
+ v = (v<0) ? 0 : ((v>2312) ? 2312 : v);
+ ai->config.rtsThres = (u16)v;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
+ int v, i = 0;
+
+ line += 16;
+ v = get_dec_u16(line, &i, 5);
+ v = (v<0) ? 0 : v;
+ ai->config.txLifetime = (u16)v;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
+ int v, i = 0;
+
+ line += 16;
+ v = get_dec_u16(line, &i, 5);
+ v = (v<0) ? 0 : v;
+ ai->config.rxLifetime = (u16)v;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
+ ai->config.txDiversity =
+ (line[13]=='l') ? 1 :
+ ((line[13]=='r')? 2: 3);
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
+ ai->config.rxDiversity =
+ (line[13]=='l') ? 1 :
+ ((line[13]=='r')? 2: 3);
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
+ int v, i = 0;
+
+ line += 15;
+ v = get_dec_u16(line, &i, 4);
+ v = (v<256) ? 256 : ((v>2312) ? 2312 : v);
+ v = v & 0xfffe; /* Make sure its even */
+ ai->config.fragThresh = (u16)v;
+ set_bit (FLAG_COMMIT, &ai->flags);
+ } else if (!strncmp(line, "Modulation: ", 12)) {
+ line += 12;
+ switch(*line) {
+ case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
+ case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
+ case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
+ default:
+ printk( KERN_WARNING "airo: Unknown modulation\n" );
+ }
+ } else if (!strncmp(line, "Preamble: ", 10)) {
+ line += 10;
+ switch(*line) {
+ case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
+ case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
+ case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
+ default: printk(KERN_WARNING "airo: Unknown preamble\n");
+ }
+ } else {
+ printk( KERN_WARNING "Couldn't figure out %s\n", line );
+ }
+ while( line[0] && line[0] != '\n' ) line++;
+ if ( line[0] ) line++;
+ }
+ airo_config_commit(dev, NULL, NULL, NULL);
+}
+
+static char *get_rmode(u16 mode) {
+ switch(mode&0xff) {
+ case RXMODE_RFMON: return "rfmon";
+ case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
+ case RXMODE_LANMON: return "lanmon";
+ }
+ return "ESS";
+}
+
+static int proc_config_open( struct inode *inode, struct file *file ) {
+ struct proc_data *data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ int i;
+
+ if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ memset(file->private_data, 0, sizeof(struct proc_data));
+ data = (struct proc_data *)file->private_data;
+ if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ if ((data->wbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
+ kfree (data->rbuffer);
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ memset( data->wbuffer, 0, 2048 );
+ data->maxwritelen = 2048;
+ data->on_close = proc_config_on_close;
+
+ readConfigRid(ai, 1);
+
+ i = sprintf( data->rbuffer,
+ "Mode: %s\n"
+ "Radio: %s\n"
+ "NodeName: %-16s\n"
+ "PowerMode: %s\n"
+ "DataRates: %d %d %d %d %d %d %d %d\n"
+ "Channel: %d\n"
+ "XmitPower: %d\n",
+ (ai->config.opmode & 0xFF) == 0 ? "adhoc" :
+ (ai->config.opmode & 0xFF) == 1 ? get_rmode(ai->config.rmode):
+ (ai->config.opmode & 0xFF) == 2 ? "AP" :
+ (ai->config.opmode & 0xFF) == 3 ? "AP RPTR" : "Error",
+ test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
+ ai->config.nodeName,
+ ai->config.powerSaveMode == 0 ? "CAM" :
+ ai->config.powerSaveMode == 1 ? "PSP" :
+ ai->config.powerSaveMode == 2 ? "PSPCAM" : "Error",
+ (int)ai->config.rates[0],
+ (int)ai->config.rates[1],
+ (int)ai->config.rates[2],
+ (int)ai->config.rates[3],
+ (int)ai->config.rates[4],
+ (int)ai->config.rates[5],
+ (int)ai->config.rates[6],
+ (int)ai->config.rates[7],
+ (int)ai->config.channelSet,
+ (int)ai->config.txPower
+ );
+ sprintf( data->rbuffer + i,
+ "LongRetryLimit: %d\n"
+ "ShortRetryLimit: %d\n"
+ "RTSThreshold: %d\n"
+ "TXMSDULifetime: %d\n"
+ "RXMSDULifetime: %d\n"
+ "TXDiversity: %s\n"
+ "RXDiversity: %s\n"
+ "FragThreshold: %d\n"
+ "WEP: %s\n"
+ "Modulation: %s\n"
+ "Preamble: %s\n",
+ (int)ai->config.longRetryLimit,
+ (int)ai->config.shortRetryLimit,
+ (int)ai->config.rtsThres,
+ (int)ai->config.txLifetime,
+ (int)ai->config.rxLifetime,
+ ai->config.txDiversity == 1 ? "left" :
+ ai->config.txDiversity == 2 ? "right" : "both",
+ ai->config.rxDiversity == 1 ? "left" :
+ ai->config.rxDiversity == 2 ? "right" : "both",
+ (int)ai->config.fragThresh,
+ ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
+ ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
+ ai->config.modulation == 0 ? "default" :
+ ai->config.modulation == MOD_CCK ? "cck" :
+ ai->config.modulation == MOD_MOK ? "mok" : "error",
+ ai->config.preamble == PREAMBLE_AUTO ? "auto" :
+ ai->config.preamble == PREAMBLE_LONG ? "long" :
+ ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
+ );
+ data->readlen = strlen( data->rbuffer );
+ return 0;
+}
+
+static void proc_SSID_on_close( struct inode *inode, struct file *file ) {
+ struct proc_data *data = (struct proc_data *)file->private_data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ SsidRid SSID_rid;
+ Resp rsp;
+ int i;
+ int offset = 0;
+
+ if ( !data->writelen ) return;
+
+ memset( &SSID_rid, 0, sizeof( SSID_rid ) );
+
+ for( i = 0; i < 3; i++ ) {
+ int j;
+ for( j = 0; j+offset < data->writelen && j < 32 &&
+ data->wbuffer[offset+j] != '\n'; j++ ) {
+ SSID_rid.ssids[i].ssid[j] = data->wbuffer[offset+j];
+ }
+ if ( j == 0 ) break;
+ SSID_rid.ssids[i].len = j;
+ offset += j;
+ while( data->wbuffer[offset] != '\n' &&
+ offset < data->writelen ) offset++;
+ offset++;
+ }
+ if (i)
+ SSID_rid.len = sizeof(SSID_rid);
+ disable_MAC(ai, 1);
+ writeSsidRid(ai, &SSID_rid, 1);
+ enable_MAC(ai, &rsp, 1);
+}
+
+inline static u8 hexVal(char c) {
+ if (c>='0' && c<='9') return c -= '0';
+ if (c>='a' && c<='f') return c -= 'a'-10;
+ if (c>='A' && c<='F') return c -= 'A'-10;
+ return 0;
+}
+
+static void proc_APList_on_close( struct inode *inode, struct file *file ) {
+ struct proc_data *data = (struct proc_data *)file->private_data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ APListRid APList_rid;
+ Resp rsp;
+ int i;
+
+ if ( !data->writelen ) return;
+
+ memset( &APList_rid, 0, sizeof(APList_rid) );
+ APList_rid.len = sizeof(APList_rid);
+
+ for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
+ int j;
+ for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) {
+ switch(j%3) {
+ case 0:
+ APList_rid.ap[i][j/3]=
+ hexVal(data->wbuffer[j+i*6*3])<<4;
+ break;
+ case 1:
+ APList_rid.ap[i][j/3]|=
+ hexVal(data->wbuffer[j+i*6*3]);
+ break;
+ }
+ }
+ }
+ disable_MAC(ai, 1);
+ writeAPListRid(ai, &APList_rid, 1);
+ enable_MAC(ai, &rsp, 1);
+}
+
+/* This function wraps PC4500_writerid with a MAC disable */
+static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
+ int len, int dummy ) {
+ int rc;
+ Resp rsp;
+
+ disable_MAC(ai, 1);
+ rc = PC4500_writerid(ai, rid, rid_data, len, 1);
+ enable_MAC(ai, &rsp, 1);
+ return rc;
+}
+
+/* Returns the length of the key at the index. If index == 0xffff
+ * the index of the transmit key is returned. If the key doesn't exist,
+ * -1 will be returned.
+ */
+static int get_wep_key(struct airo_info *ai, u16 index) {
+ WepKeyRid wkr;
+ int rc;
+ u16 lastindex;
+
+ rc = readWepKeyRid(ai, &wkr, 1, 1);
+ if (rc == SUCCESS) do {
+ lastindex = wkr.kindex;
+ if (wkr.kindex == index) {
+ if (index == 0xffff) {
+ return wkr.mac[0];
+ }
+ return wkr.klen;
+ }
+ readWepKeyRid(ai, &wkr, 0, 1);
+ } while(lastindex != wkr.kindex);
+ return -1;
+}
+
+static int set_wep_key(struct airo_info *ai, u16 index,
+ const char *key, u16 keylen, int perm, int lock ) {
+ static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
+ WepKeyRid wkr;
+ Resp rsp;
+
+ memset(&wkr, 0, sizeof(wkr));
+ if (keylen == 0) {
+// We are selecting which key to use
+ wkr.len = sizeof(wkr);
+ wkr.kindex = 0xffff;
+ wkr.mac[0] = (char)index;
+ if (perm) printk(KERN_INFO "Setting transmit key to %d\n", index);
+ if (perm) ai->defindex = (char)index;
+ } else {
+// We are actually setting the key
+ wkr.len = sizeof(wkr);
+ wkr.kindex = index;
+ wkr.klen = keylen;
+ memcpy( wkr.key, key, keylen );
+ memcpy( wkr.mac, macaddr, ETH_ALEN );
+ printk(KERN_INFO "Setting key %d\n", index);
+ }
+
+ disable_MAC(ai, lock);
+ writeWepKeyRid(ai, &wkr, perm, lock);
+ enable_MAC(ai, &rsp, lock);
+ return 0;
+}
+
+static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
+ struct proc_data *data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ int i;
+ char key[16];
+ u16 index = 0;
+ int j = 0;
+
+ memset(key, 0, sizeof(key));
+
+ data = (struct proc_data *)file->private_data;
+ if ( !data->writelen ) return;
+
+ if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
+ (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
+ index = data->wbuffer[0] - '0';
+ if (data->wbuffer[1] == '\n') {
+ set_wep_key(ai, index, NULL, 0, 1, 1);
+ return;
+ }
+ j = 2;
+ } else {
+ printk(KERN_ERR "airo: WepKey passed invalid key index\n");
+ return;
+ }
+
+ for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
+ switch(i%3) {
+ case 0:
+ key[i/3] = hexVal(data->wbuffer[i+j])<<4;
+ break;
+ case 1:
+ key[i/3] |= hexVal(data->wbuffer[i+j]);
+ break;
+ }
+ }
+ set_wep_key(ai, index, key, i/3, 1, 1);
+}
+
+static int proc_wepkey_open( struct inode *inode, struct file *file ) {
+ struct proc_data *data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ char *ptr;
+ WepKeyRid wkr;
+ u16 lastindex;
+ int j=0;
+ int rc;
+
+ if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ memset(file->private_data, 0, sizeof(struct proc_data));
+ memset(&wkr, 0, sizeof(wkr));
+ data = (struct proc_data *)file->private_data;
+ if ((data->rbuffer = kmalloc( 180, GFP_KERNEL )) == NULL) {
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ memset(data->rbuffer, 0, 180);
+ data->writelen = 0;
+ data->maxwritelen = 80;
+ if ((data->wbuffer = kmalloc( 80, GFP_KERNEL )) == NULL) {
+ kfree (data->rbuffer);
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ memset( data->wbuffer, 0, 80 );
+ data->on_close = proc_wepkey_on_close;
+
+ ptr = data->rbuffer;
+ strcpy(ptr, "No wep keys\n");
+ rc = readWepKeyRid(ai, &wkr, 1, 1);
+ if (rc == SUCCESS) do {
+ lastindex = wkr.kindex;
+ if (wkr.kindex == 0xffff) {
+ j += sprintf(ptr+j, "Tx key = %d\n",
+ (int)wkr.mac[0]);
+ } else {
+ j += sprintf(ptr+j, "Key %d set with length = %d\n",
+ (int)wkr.kindex, (int)wkr.klen);
+ }
+ readWepKeyRid(ai, &wkr, 0, 1);
+ } while((lastindex != wkr.kindex) && (j < 180-30));
+
+ data->readlen = strlen( data->rbuffer );
+ return 0;
+}
+
+static int proc_SSID_open( struct inode *inode, struct file *file ) {
+ struct proc_data *data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ int i;
+ char *ptr;
+ SsidRid SSID_rid;
+
+ if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ memset(file->private_data, 0, sizeof(struct proc_data));
+ data = (struct proc_data *)file->private_data;
+ if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ data->writelen = 0;
+ data->maxwritelen = 33*3;
+ if ((data->wbuffer = kmalloc( 33*3, GFP_KERNEL )) == NULL) {
+ kfree (data->rbuffer);
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ memset( data->wbuffer, 0, 33*3 );
+ data->on_close = proc_SSID_on_close;
+
+ readSsidRid(ai, &SSID_rid);
+ ptr = data->rbuffer;
+ for( i = 0; i < 3; i++ ) {
+ int j;
+ if ( !SSID_rid.ssids[i].len ) break;
+ for( j = 0; j < 32 &&
+ j < SSID_rid.ssids[i].len &&
+ SSID_rid.ssids[i].ssid[j]; j++ ) {
+ *ptr++ = SSID_rid.ssids[i].ssid[j];
+ }
+ *ptr++ = '\n';
+ }
+ *ptr = '\0';
+ data->readlen = strlen( data->rbuffer );
+ return 0;
+}
+
+static int proc_APList_open( struct inode *inode, struct file *file ) {
+ struct proc_data *data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ int i;
+ char *ptr;
+ APListRid APList_rid;
+
+ if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ memset(file->private_data, 0, sizeof(struct proc_data));
+ data = (struct proc_data *)file->private_data;
+ if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ data->writelen = 0;
+ data->maxwritelen = 4*6*3;
+ if ((data->wbuffer = kmalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
+ kfree (data->rbuffer);
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ memset( data->wbuffer, 0, data->maxwritelen );
+ data->on_close = proc_APList_on_close;
+
+ readAPListRid(ai, &APList_rid);
+ ptr = data->rbuffer;
+ for( i = 0; i < 4; i++ ) {
+// We end when we find a zero MAC
+ if ( !*(int*)APList_rid.ap[i] &&
+ !*(int*)&APList_rid.ap[i][2]) break;
+ ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x\n",
+ (int)APList_rid.ap[i][0],
+ (int)APList_rid.ap[i][1],
+ (int)APList_rid.ap[i][2],
+ (int)APList_rid.ap[i][3],
+ (int)APList_rid.ap[i][4],
+ (int)APList_rid.ap[i][5]);
+ }
+ if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
+
+ *ptr = '\0';
+ data->readlen = strlen( data->rbuffer );
+ return 0;
+}
+
+static int proc_BSSList_open( struct inode *inode, struct file *file ) {
+ struct proc_data *data;
+ struct proc_dir_entry *dp = PDE(inode);
+ struct net_device *dev = dp->data;
+ struct airo_info *ai = dev->priv;
+ char *ptr;
+ BSSListRid BSSList_rid;
+ int rc;
+ /* If doLoseSync is not 1, we won't do a Lose Sync */
+ int doLoseSync = -1;
+
+ if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ memset(file->private_data, 0, sizeof(struct proc_data));
+ data = (struct proc_data *)file->private_data;
+ if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
+ kfree (file->private_data);
+ return -ENOMEM;
+ }
+ data->writelen = 0;
+ data->maxwritelen = 0;
+ data->wbuffer = NULL;
+ data->on_close = NULL;
+
+ if (file->f_mode & FMODE_WRITE) {
+ if (!(file->f_mode & FMODE_READ)) {
+ Cmd cmd;
+ Resp rsp;
+
+ if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd=CMD_LISTBSS;
+ if (down_interruptible(&ai->sem))
+ return -ERESTARTSYS;
+ issuecommand(ai, &cmd, &rsp);
+ up(&ai->sem);
+ data->readlen = 0;
+ return 0;
+ }
+ doLoseSync = 1;
+ }
+ ptr = data->rbuffer;
+ /* There is a race condition here if there are concurrent opens.
+ Since it is a rare condition, we'll just live with it, otherwise
+ we have to add a spin lock... */
+ rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
+ while(rc == 0 && BSSList_rid.index != 0xffff) {
+ ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x %*s rssi = %d",
+ (int)BSSList_rid.bssid[0],
+ (int)BSSList_rid.bssid[1],
+ (int)BSSList_rid.bssid[2],
+ (int)BSSList_rid.bssid[3],
+ (int)BSSList_rid.bssid[4],
+ (int)BSSList_rid.bssid[5],
+ (int)BSSList_rid.ssidLen,
+ BSSList_rid.ssid,
+ (int)BSSList_rid.rssi);
+ ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
+ (int)BSSList_rid.dsChannel,
+ BSSList_rid.cap & CAP_ESS ? "ESS" : "",
+ BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
+ BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
+ BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
+ rc = readBSSListRid(ai, 0, &BSSList_rid);
+ }
+ *ptr = '\0';
+ data->readlen = strlen( data->rbuffer );
+ return 0;
+}
+
+static int proc_close( struct inode *inode, struct file *file )
+{
+ struct proc_data *data = (struct proc_data *)file->private_data;
+ if ( data->on_close != NULL ) data->on_close( inode, file );
+ if ( data->rbuffer ) kfree( data->rbuffer );
+ if ( data->wbuffer ) kfree( data->wbuffer );
+ kfree( data );
+ return 0;
+}
+
+static struct net_device_list {
+ struct net_device *dev;
+ struct net_device_list *next;
+} *airo_devices;
+
+/* Since the card doesn't automatically switch to the right WEP mode,
+ we will make it do it. If the card isn't associated, every secs we
+ will switch WEP modes to see if that will help. If the card is
+ associated we will check every minute to see if anything has
+ changed. */
+static void timer_func( struct net_device *dev ) {
+ struct airo_info *apriv = dev->priv;
+ Resp rsp;
+
+/* We don't have a link so try changing the authtype */
+ readConfigRid(apriv, 0);
+ disable_MAC(apriv, 0);
+ switch(apriv->config.authType) {
+ case AUTH_ENCRYPT:
+/* So drop to OPEN */
+ apriv->config.authType = AUTH_OPEN;
+ break;
+ case AUTH_SHAREDKEY:
+ if (apriv->keyindex < auto_wep) {
+ set_wep_key(apriv, apriv->keyindex, NULL, 0, 0, 0);
+ apriv->config.authType = AUTH_SHAREDKEY;
+ apriv->keyindex++;
+ } else {
+ /* Drop to ENCRYPT */
+ apriv->keyindex = 0;
+ set_wep_key(apriv, apriv->defindex, NULL, 0, 0, 0);
+ apriv->config.authType = AUTH_ENCRYPT;
+ }
+ break;
+ default: /* We'll escalate to SHAREDKEY */
+ apriv->config.authType = AUTH_SHAREDKEY;
+ }
+ set_bit (FLAG_COMMIT, &apriv->flags);
+ writeConfigRid(apriv, 0);
+ enable_MAC(apriv, &rsp, 0);
+ up(&apriv->sem);
+
+/* Schedule check to see if the change worked */
+ clear_bit(JOB_AUTOWEP, &apriv->flags);
+ apriv->expires = RUN_AT(HZ*3);
+}
+
+static int add_airo_dev( struct net_device *dev ) {
+ struct net_device_list *node = kmalloc( sizeof( *node ), GFP_KERNEL );
+ if ( !node )
+ return -ENOMEM;
+
+ node->dev = dev;
+ node->next = airo_devices;
+ airo_devices = node;
+
+ return 0;
+}
+
+static void del_airo_dev( struct net_device *dev ) {
+ struct net_device_list **p = &airo_devices;
+ while( *p && ( (*p)->dev != dev ) )
+ p = &(*p)->next;
+ if ( *p && (*p)->dev == dev )
+ *p = (*p)->next;
+}
+
+#ifdef CONFIG_PCI
+static int __devinit airo_pci_probe(struct pci_dev *pdev,
+ const struct pci_device_id *pent)
+{
+ struct net_device *dev;
+
+ if (pci_enable_device(pdev))
+ return -ENODEV;
+ pci_set_master(pdev);
+
+ if (pdev->device == 0x5000 || pdev->device == 0xa504)
+ dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
+ else
+ dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
+ if (!dev)
+ return -ENODEV;
+
+ pci_set_drvdata(pdev, dev);
+ return 0;
+}
+
+static void __devexit airo_pci_remove(struct pci_dev *pdev)
+{
+}
+
+static int airo_pci_suspend(struct pci_dev *pdev, u32 state)
+{
+ struct net_device *dev = pci_get_drvdata(pdev);
+ struct airo_info *ai = dev->priv;
+ Cmd cmd;
+ Resp rsp;
+
+ if ((ai->APList == NULL) &&
+ (ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ if ((ai->SSID == NULL) &&
+ (ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ readAPListRid(ai, ai->APList);
+ readSsidRid(ai, ai->SSID);
+ memset(&cmd, 0, sizeof(cmd));
+ /* the lock will be released at the end of the resume callback */
+ if (down_interruptible(&ai->sem))
+ return -EAGAIN;
+ disable_MAC(ai, 0);
+ netif_device_detach(dev);
+ ai->power = state;
+ cmd.cmd=HOSTSLEEP;
+ issuecommand(ai, &cmd, &rsp);
+
+ pci_enable_wake(pdev, state, 1);
+ pci_save_state(pdev);
+ return pci_set_power_state(pdev, state);
+}
+
+static int airo_pci_resume(struct pci_dev *pdev)
+{
+ struct net_device *dev = pci_get_drvdata(pdev);
+ struct airo_info *ai = dev->priv;
+ Resp rsp;
+
+ pci_set_power_state(pdev, 0);
+ pci_restore_state(pdev);
+ pci_enable_wake(pdev, ai->power, 0);
+
+ if (ai->power > 1) {
+ reset_card(dev, 0);
+ mpi_init_descriptors(ai);
+ setup_card(ai, dev->dev_addr, 0);
+ clear_bit(FLAG_RADIO_OFF, &ai->flags);
+ clear_bit(FLAG_PENDING_XMIT, &ai->flags);
+ } else {
+ OUT4500(ai, EVACK, EV_AWAKEN);
+ OUT4500(ai, EVACK, EV_AWAKEN);
+ msleep(100);
+ }
+
+ set_bit (FLAG_COMMIT, &ai->flags);
+ disable_MAC(ai, 0);
+ msleep(200);
+ if (ai->SSID) {
+ writeSsidRid(ai, ai->SSID, 0);
+ kfree(ai->SSID);
+ ai->SSID = NULL;
+ }
+ if (ai->APList) {
+ writeAPListRid(ai, ai->APList, 0);
+ kfree(ai->APList);
+ ai->APList = NULL;
+ }
+ writeConfigRid(ai, 0);
+ enable_MAC(ai, &rsp, 0);
+ ai->power = 0;
+ netif_device_attach(dev);
+ netif_wake_queue(dev);
+ enable_interrupts(ai);
+ up(&ai->sem);
+ return 0;
+}
+#endif
+
+static int __init airo_init_module( void )
+{
+ int i, have_isa_dev = 0;
+
+ airo_entry = create_proc_entry("aironet",
+ S_IFDIR | airo_perm,
+ proc_root_driver);
+ airo_entry->uid = proc_uid;
+ airo_entry->gid = proc_gid;
+
+ for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
+ printk( KERN_INFO
+ "airo: Trying to configure ISA adapter at irq=%d io=0x%x\n",
+ irq[i], io[i] );
+ if (init_airo_card( irq[i], io[i], 0, NULL ))
+ have_isa_dev = 1;
+ }
+
+#ifdef CONFIG_PCI
+ printk( KERN_INFO "airo: Probing for PCI adapters\n" );
+ pci_register_driver(&airo_driver);
+ printk( KERN_INFO "airo: Finished probing for PCI adapters\n" );
+#endif
+
+ /* Always exit with success, as we are a library module
+ * as well as a driver module
+ */
+ return 0;
+}
+
+static void __exit airo_cleanup_module( void )
+{
+ while( airo_devices ) {
+ printk( KERN_INFO "airo: Unregistering %s\n", airo_devices->dev->name );
+ stop_airo_card( airo_devices->dev, 1 );
+ }
+#ifdef CONFIG_PCI
+ pci_unregister_driver(&airo_driver);
+#endif
+ remove_proc_entry("aironet", proc_root_driver);
+}
+
+#ifdef WIRELESS_EXT
+/*
+ * Initial Wireless Extension code for Aironet driver by :
+ * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
+ * Conversion to new driver API by :
+ * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
+ * Javier also did a good amount of work here, adding some new extensions
+ * and fixing my code. Let's just say that without him this code just
+ * would not work at all... - Jean II
+ */
+
+static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
+{
+ int quality = 0;
+
+ if ((status_rid->mode & 0x3f) == 0x3f && (cap_rid->hardCap & 8)) {
+ if (memcmp(cap_rid->prodName, "350", 3))
+ if (status_rid->signalQuality > 0x20)
+ quality = 0;
+ else
+ quality = 0x20 - status_rid->signalQuality;
+ else
+ if (status_rid->signalQuality > 0xb0)
+ quality = 0;
+ else if (status_rid->signalQuality < 0x10)
+ quality = 0xa0;
+ else
+ quality = 0xb0 - status_rid->signalQuality;
+ }
+ return quality;
+}
+
+#define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0)
+#define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50);
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get protocol name
+ */
+static int airo_get_name(struct net_device *dev,
+ struct iw_request_info *info,
+ char *cwrq,
+ char *extra)
+{
+ strcpy(cwrq, "IEEE 802.11-DS");
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set frequency
+ */
+static int airo_set_freq(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_freq *fwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ int rc = -EINPROGRESS; /* Call commit handler */
+
+ /* If setting by frequency, convert to a channel */
+ if((fwrq->e == 1) &&
+ (fwrq->m >= (int) 2.412e8) &&
+ (fwrq->m <= (int) 2.487e8)) {
+ int f = fwrq->m / 100000;
+ int c = 0;
+ while((c < 14) && (f != frequency_list[c]))
+ c++;
+ /* Hack to fall through... */
+ fwrq->e = 0;
+ fwrq->m = c + 1;
+ }
+ /* Setting by channel number */
+ if((fwrq->m > 1000) || (fwrq->e > 0))
+ rc = -EOPNOTSUPP;
+ else {
+ int channel = fwrq->m;
+ /* We should do a better check than that,
+ * based on the card capability !!! */
+ if((channel < 1) || (channel > 16)) {
+ printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m);
+ rc = -EINVAL;
+ } else {
+ readConfigRid(local, 1);
+ /* Yes ! We can set it !!! */
+ local->config.channelSet = (u16)(channel - 1);
+ set_bit (FLAG_COMMIT, &local->flags);
+ }
+ }
+ return rc;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get frequency
+ */
+static int airo_get_freq(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_freq *fwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ StatusRid status_rid; /* Card status info */
+
+ readConfigRid(local, 1);
+ if ((local->config.opmode & 0xFF) == MODE_STA_ESS)
+ status_rid.channel = local->config.channelSet;
+ else
+ readStatusRid(local, &status_rid, 1);
+
+#ifdef WEXT_USECHANNELS
+ fwrq->m = ((int)status_rid.channel) + 1;
+ fwrq->e = 0;
+#else
+ {
+ int f = (int)status_rid.channel;
+ fwrq->m = frequency_list[f] * 100000;
+ fwrq->e = 1;
+ }
+#endif
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set ESSID
+ */
+static int airo_set_essid(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ Resp rsp;
+ SsidRid SSID_rid; /* SSIDs */
+
+ /* Reload the list of current SSID */
+ readSsidRid(local, &SSID_rid);
+
+ /* Check if we asked for `any' */
+ if(dwrq->flags == 0) {
+ /* Just send an empty SSID list */
+ memset(&SSID_rid, 0, sizeof(SSID_rid));
+ } else {
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+
+ /* Check the size of the string */
+ if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
+ return -E2BIG ;
+ }
+ /* Check if index is valid */
+ if((index < 0) || (index >= 4)) {
+ return -EINVAL;
+ }
+
+ /* Set the SSID */
+ memset(SSID_rid.ssids[index].ssid, 0,
+ sizeof(SSID_rid.ssids[index].ssid));
+ memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
+ SSID_rid.ssids[index].len = dwrq->length - 1;
+ }
+ SSID_rid.len = sizeof(SSID_rid);
+ /* Write it to the card */
+ disable_MAC(local, 1);
+ writeSsidRid(local, &SSID_rid, 1);
+ enable_MAC(local, &rsp, 1);
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get ESSID
+ */
+static int airo_get_essid(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ StatusRid status_rid; /* Card status info */
+
+ readStatusRid(local, &status_rid, 1);
+
+ /* Note : if dwrq->flags != 0, we should
+ * get the relevant SSID from the SSID list... */
+
+ /* Get the current SSID */
+ memcpy(extra, status_rid.SSID, status_rid.SSIDlen);
+ extra[status_rid.SSIDlen] = '\0';
+ /* If none, we may want to get the one that was set */
+
+ /* Push it out ! */
+ dwrq->length = status_rid.SSIDlen + 1;
+ dwrq->flags = 1; /* active */
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set AP address
+ */
+static int airo_set_wap(struct net_device *dev,
+ struct iw_request_info *info,
+ struct sockaddr *awrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ Cmd cmd;
+ Resp rsp;
+ APListRid APList_rid;
+ static const unsigned char bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
+
+ if (awrq->sa_family != ARPHRD_ETHER)
+ return -EINVAL;
+ else if (!memcmp(bcast, awrq->sa_data, ETH_ALEN)) {
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd=CMD_LOSE_SYNC;
+ if (down_interruptible(&local->sem))
+ return -ERESTARTSYS;
+ issuecommand(local, &cmd, &rsp);
+ up(&local->sem);
+ } else {
+ memset(&APList_rid, 0, sizeof(APList_rid));
+ APList_rid.len = sizeof(APList_rid);
+ memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
+ disable_MAC(local, 1);
+ writeAPListRid(local, &APList_rid, 1);
+ enable_MAC(local, &rsp, 1);
+ }
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get AP address
+ */
+static int airo_get_wap(struct net_device *dev,
+ struct iw_request_info *info,
+ struct sockaddr *awrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ StatusRid status_rid; /* Card status info */
+
+ readStatusRid(local, &status_rid, 1);
+
+ /* Tentative. This seems to work, wow, I'm lucky !!! */
+ memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
+ awrq->sa_family = ARPHRD_ETHER;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Nickname
+ */
+static int airo_set_nick(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ /* Check the size of the string */
+ if(dwrq->length > 16 + 1) {
+ return -E2BIG;
+ }
+ readConfigRid(local, 1);
+ memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
+ memcpy(local->config.nodeName, extra, dwrq->length);
+ set_bit (FLAG_COMMIT, &local->flags);
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Nickname
+ */
+static int airo_get_nick(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ readConfigRid(local, 1);
+ strncpy(extra, local->config.nodeName, 16);
+ extra[16] = '\0';
+ dwrq->length = strlen(extra) + 1;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Bit-Rate
+ */
+static int airo_set_rate(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ CapabilityRid cap_rid; /* Card capability info */
+ u8 brate = 0;
+ int i;
+
+ /* First : get a valid bit rate value */
+ readCapabilityRid(local, &cap_rid, 1);
+
+ /* Which type of value ? */
+ if((vwrq->value < 8) && (vwrq->value >= 0)) {
+ /* Setting by rate index */
+ /* Find value in the magic rate table */
+ brate = cap_rid.supportedRates[vwrq->value];
+ } else {
+ /* Setting by frequency value */
+ u8 normvalue = (u8) (vwrq->value/500000);
+
+ /* Check if rate is valid */
+ for(i = 0 ; i < 8 ; i++) {
+ if(normvalue == cap_rid.supportedRates[i]) {
+ brate = normvalue;
+ break;
+ }
+ }
+ }
+ /* -1 designed the max rate (mostly auto mode) */
+ if(vwrq->value == -1) {
+ /* Get the highest available rate */
+ for(i = 0 ; i < 8 ; i++) {
+ if(cap_rid.supportedRates[i] == 0)
+ break;
+ }
+ if(i != 0)
+ brate = cap_rid.supportedRates[i - 1];
+ }
+ /* Check that it is valid */
+ if(brate == 0) {
+ return -EINVAL;
+ }
+
+ readConfigRid(local, 1);
+ /* Now, check if we want a fixed or auto value */
+ if(vwrq->fixed == 0) {
+ /* Fill all the rates up to this max rate */
+ memset(local->config.rates, 0, 8);
+ for(i = 0 ; i < 8 ; i++) {
+ local->config.rates[i] = cap_rid.supportedRates[i];
+ if(local->config.rates[i] == brate)
+ break;
+ }
+ } else {
+ /* Fixed mode */
+ /* One rate, fixed */
+ memset(local->config.rates, 0, 8);
+ local->config.rates[0] = brate;
+ }
+ set_bit (FLAG_COMMIT, &local->flags);
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Bit-Rate
+ */
+static int airo_get_rate(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ StatusRid status_rid; /* Card status info */
+
+ readStatusRid(local, &status_rid, 1);
+
+ vwrq->value = status_rid.currentXmitRate * 500000;
+ /* If more than one rate, set auto */
+ readConfigRid(local, 1);
+ vwrq->fixed = (local->config.rates[1] == 0);
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set RTS threshold
+ */
+static int airo_set_rts(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ int rthr = vwrq->value;
+
+ if(vwrq->disabled)
+ rthr = 2312;
+ if((rthr < 0) || (rthr > 2312)) {
+ return -EINVAL;
+ }
+ readConfigRid(local, 1);
+ local->config.rtsThres = rthr;
+ set_bit (FLAG_COMMIT, &local->flags);
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get RTS threshold
+ */
+static int airo_get_rts(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ readConfigRid(local, 1);
+ vwrq->value = local->config.rtsThres;
+ vwrq->disabled = (vwrq->value >= 2312);
+ vwrq->fixed = 1;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Fragmentation threshold
+ */
+static int airo_set_frag(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ int fthr = vwrq->value;
+
+ if(vwrq->disabled)
+ fthr = 2312;
+ if((fthr < 256) || (fthr > 2312)) {
+ return -EINVAL;
+ }
+ fthr &= ~0x1; /* Get an even value - is it really needed ??? */
+ readConfigRid(local, 1);
+ local->config.fragThresh = (u16)fthr;
+ set_bit (FLAG_COMMIT, &local->flags);
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Fragmentation threshold
+ */
+static int airo_get_frag(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ readConfigRid(local, 1);
+ vwrq->value = local->config.fragThresh;
+ vwrq->disabled = (vwrq->value >= 2312);
+ vwrq->fixed = 1;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Mode of Operation
+ */
+static int airo_set_mode(struct net_device *dev,
+ struct iw_request_info *info,
+ __u32 *uwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ int reset = 0;
+
+ readConfigRid(local, 1);
+ if ((local->config.rmode & 0xff) >= RXMODE_RFMON)
+ reset = 1;
+
+ switch(*uwrq) {
+ case IW_MODE_ADHOC:
+ local->config.opmode &= 0xFF00;
+ local->config.opmode |= MODE_STA_IBSS;
+ local->config.rmode &= 0xfe00;
+ local->config.scanMode = SCANMODE_ACTIVE;
+ clear_bit (FLAG_802_11, &local->flags);
+ break;
+ case IW_MODE_INFRA:
+ local->config.opmode &= 0xFF00;
+ local->config.opmode |= MODE_STA_ESS;
+ local->config.rmode &= 0xfe00;
+ local->config.scanMode = SCANMODE_ACTIVE;
+ clear_bit (FLAG_802_11, &local->flags);
+ break;
+ case IW_MODE_MASTER:
+ local->config.opmode &= 0xFF00;
+ local->config.opmode |= MODE_AP;
+ local->config.rmode &= 0xfe00;
+ local->config.scanMode = SCANMODE_ACTIVE;
+ clear_bit (FLAG_802_11, &local->flags);
+ break;
+ case IW_MODE_REPEAT:
+ local->config.opmode &= 0xFF00;
+ local->config.opmode |= MODE_AP_RPTR;
+ local->config.rmode &= 0xfe00;
+ local->config.scanMode = SCANMODE_ACTIVE;
+ clear_bit (FLAG_802_11, &local->flags);
+ break;
+ case IW_MODE_MONITOR:
+ local->config.opmode &= 0xFF00;
+ local->config.opmode |= MODE_STA_ESS;
+ local->config.rmode &= 0xfe00;
+ local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
+ local->config.scanMode = SCANMODE_PASSIVE;
+ set_bit (FLAG_802_11, &local->flags);
+ break;
+ default:
+ return -EINVAL;
+ }
+ if (reset)
+ set_bit (FLAG_RESET, &local->flags);
+ set_bit (FLAG_COMMIT, &local->flags);
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Mode of Operation
+ */
+static int airo_get_mode(struct net_device *dev,
+ struct iw_request_info *info,
+ __u32 *uwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ readConfigRid(local, 1);
+ /* If not managed, assume it's ad-hoc */
+ switch (local->config.opmode & 0xFF) {
+ case MODE_STA_ESS:
+ *uwrq = IW_MODE_INFRA;
+ break;
+ case MODE_AP:
+ *uwrq = IW_MODE_MASTER;
+ break;
+ case MODE_AP_RPTR:
+ *uwrq = IW_MODE_REPEAT;
+ break;
+ default:
+ *uwrq = IW_MODE_ADHOC;
+ }
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Encryption Key
+ */
+static int airo_set_encode(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ CapabilityRid cap_rid; /* Card capability info */
+
+ /* Is WEP supported ? */
+ readCapabilityRid(local, &cap_rid, 1);
+ /* Older firmware doesn't support this...
+ if(!(cap_rid.softCap & 2)) {
+ return -EOPNOTSUPP;
+ } */
+ readConfigRid(local, 1);
+
+ /* Basic checking: do we have a key to set ?
+ * Note : with the new API, it's impossible to get a NULL pointer.
+ * Therefore, we need to check a key size == 0 instead.
+ * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
+ * when no key is present (only change flags), but older versions
+ * don't do it. - Jean II */
+ if (dwrq->length > 0) {
+ wep_key_t key;
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+ int current_index = get_wep_key(local, 0xffff);
+ /* Check the size of the key */
+ if (dwrq->length > MAX_KEY_SIZE) {
+ return -EINVAL;
+ }
+ /* Check the index (none -> use current) */
+ if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4:1)))
+ index = current_index;
+ /* Set the length */
+ if (dwrq->length > MIN_KEY_SIZE)
+ key.len = MAX_KEY_SIZE;
+ else
+ if (dwrq->length > 0)
+ key.len = MIN_KEY_SIZE;
+ else
+ /* Disable the key */
+ key.len = 0;
+ /* Check if the key is not marked as invalid */
+ if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
+ /* Cleanup */
+ memset(key.key, 0, MAX_KEY_SIZE);
+ /* Copy the key in the driver */
+ memcpy(key.key, extra, dwrq->length);
+ /* Send the key to the card */
+ set_wep_key(local, index, key.key, key.len, 1, 1);
+ }
+ /* WE specify that if a valid key is set, encryption
+ * should be enabled (user may turn it off later)
+ * This is also how "iwconfig ethX key on" works */
+ if((index == current_index) && (key.len > 0) &&
+ (local->config.authType == AUTH_OPEN)) {
+ local->config.authType = AUTH_ENCRYPT;
+ set_bit (FLAG_COMMIT, &local->flags);
+ }
+ } else {
+ /* Do we want to just set the transmit key index ? */
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+ if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) {
+ set_wep_key(local, index, NULL, 0, 1, 1);
+ } else
+ /* Don't complain if only change the mode */
+ if(!dwrq->flags & IW_ENCODE_MODE) {
+ return -EINVAL;
+ }
+ }
+ /* Read the flags */
+ if(dwrq->flags & IW_ENCODE_DISABLED)
+ local->config.authType = AUTH_OPEN; // disable encryption
+ if(dwrq->flags & IW_ENCODE_RESTRICTED)
+ local->config.authType = AUTH_SHAREDKEY; // Only Both
+ if(dwrq->flags & IW_ENCODE_OPEN)
+ local->config.authType = AUTH_ENCRYPT; // Only Wep
+ /* Commit the changes to flags if needed */
+ if(dwrq->flags & IW_ENCODE_MODE)
+ set_bit (FLAG_COMMIT, &local->flags);
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Encryption Key
+ */
+static int airo_get_encode(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+ CapabilityRid cap_rid; /* Card capability info */
+
+ /* Is it supported ? */
+ readCapabilityRid(local, &cap_rid, 1);
+ if(!(cap_rid.softCap & 2)) {
+ return -EOPNOTSUPP;
+ }
+ readConfigRid(local, 1);
+ /* Check encryption mode */
+ switch(local->config.authType) {
+ case AUTH_ENCRYPT:
+ dwrq->flags = IW_ENCODE_OPEN;
+ break;
+ case AUTH_SHAREDKEY:
+ dwrq->flags = IW_ENCODE_RESTRICTED;
+ break;
+ default:
+ case AUTH_OPEN:
+ dwrq->flags = IW_ENCODE_DISABLED;
+ break;
+ }
+ /* We can't return the key, so set the proper flag and return zero */
+ dwrq->flags |= IW_ENCODE_NOKEY;
+ memset(extra, 0, 16);
+
+ /* Which key do we want ? -1 -> tx index */
+ if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4 : 1)))
+ index = get_wep_key(local, 0xffff);
+ dwrq->flags |= index + 1;
+ /* Copy the key to the user buffer */
+ dwrq->length = get_wep_key(local, index);
+ if (dwrq->length > 16) {
+ dwrq->length=0;
+ }
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Tx-Power
+ */
+static int airo_set_txpow(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ CapabilityRid cap_rid; /* Card capability info */
+ int i;
+ int rc = -EINVAL;
+
+ readCapabilityRid(local, &cap_rid, 1);
+
+ if (vwrq->disabled) {
+ set_bit (FLAG_RADIO_OFF, &local->flags);
+ set_bit (FLAG_COMMIT, &local->flags);
+ return -EINPROGRESS; /* Call commit handler */
+ }
+ if (vwrq->flags != IW_TXPOW_MWATT) {
+ return -EINVAL;
+ }
+ clear_bit (FLAG_RADIO_OFF, &local->flags);
+ for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
+ if ((vwrq->value==cap_rid.txPowerLevels[i])) {
+ readConfigRid(local, 1);
+ local->config.txPower = vwrq->value;
+ set_bit (FLAG_COMMIT, &local->flags);
+ rc = -EINPROGRESS; /* Call commit handler */
+ break;
+ }
+ return rc;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Tx-Power
+ */
+static int airo_get_txpow(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ readConfigRid(local, 1);
+ vwrq->value = local->config.txPower;
+ vwrq->fixed = 1; /* No power control */
+ vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
+ vwrq->flags = IW_TXPOW_MWATT;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Retry limits
+ */
+static int airo_set_retry(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ int rc = -EINVAL;
+
+ if(vwrq->disabled) {
+ return -EINVAL;
+ }
+ readConfigRid(local, 1);
+ if(vwrq->flags & IW_RETRY_LIMIT) {
+ if(vwrq->flags & IW_RETRY_MAX)
+ local->config.longRetryLimit = vwrq->value;
+ else if (vwrq->flags & IW_RETRY_MIN)
+ local->config.shortRetryLimit = vwrq->value;
+ else {
+ /* No modifier : set both */
+ local->config.longRetryLimit = vwrq->value;
+ local->config.shortRetryLimit = vwrq->value;
+ }
+ set_bit (FLAG_COMMIT, &local->flags);
+ rc = -EINPROGRESS; /* Call commit handler */
+ }
+ if(vwrq->flags & IW_RETRY_LIFETIME) {
+ local->config.txLifetime = vwrq->value / 1024;
+ set_bit (FLAG_COMMIT, &local->flags);
+ rc = -EINPROGRESS; /* Call commit handler */
+ }
+ return rc;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Retry limits
+ */
+static int airo_get_retry(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ vwrq->disabled = 0; /* Can't be disabled */
+
+ readConfigRid(local, 1);
+ /* Note : by default, display the min retry number */
+ if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
+ vwrq->flags = IW_RETRY_LIFETIME;
+ vwrq->value = (int)local->config.txLifetime * 1024;
+ } else if((vwrq->flags & IW_RETRY_MAX)) {
+ vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
+ vwrq->value = (int)local->config.longRetryLimit;
+ } else {
+ vwrq->flags = IW_RETRY_LIMIT;
+ vwrq->value = (int)local->config.shortRetryLimit;
+ if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit)
+ vwrq->flags |= IW_RETRY_MIN;
+ }
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get range info
+ */
+static int airo_get_range(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ struct iw_range *range = (struct iw_range *) extra;
+ CapabilityRid cap_rid; /* Card capability info */
+ int i;
+ int k;
+
+ readCapabilityRid(local, &cap_rid, 1);
+
+ dwrq->length = sizeof(struct iw_range);
+ memset(range, 0, sizeof(*range));
+ range->min_nwid = 0x0000;
+ range->max_nwid = 0x0000;
+ range->num_channels = 14;
+ /* Should be based on cap_rid.country to give only
+ * what the current card support */
+ k = 0;
+ for(i = 0; i < 14; i++) {
+ range->freq[k].i = i + 1; /* List index */
+ range->freq[k].m = frequency_list[i] * 100000;
+ range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
+ }
+ range->num_frequency = k;
+
+ /* Hum... Should put the right values there */
+ range->max_qual.qual = airo_get_max_quality(&cap_rid);
+ range->max_qual.level = 0x100 - 120; /* -120 dBm */
+ range->max_qual.noise = 0;
+ range->sensitivity = 65535;
+
+ for(i = 0 ; i < 8 ; i++) {
+ range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
+ if(range->bitrate[i] == 0)
+ break;
+ }
+ range->num_bitrates = i;
+
+ /* Set an indication of the max TCP throughput
+ * in bit/s that we can expect using this interface.
+ * May be use for QoS stuff... Jean II */
+ if(i > 2)
+ range->throughput = 5000 * 1000;
+ else
+ range->throughput = 1500 * 1000;
+
+ range->min_rts = 0;
+ range->max_rts = 2312;
+ range->min_frag = 256;
+ range->max_frag = 2312;
+
+ if(cap_rid.softCap & 2) {
+ // WEP: RC4 40 bits
+ range->encoding_size[0] = 5;
+ // RC4 ~128 bits
+ if (cap_rid.softCap & 0x100) {
+ range->encoding_size[1] = 13;
+ range->num_encoding_sizes = 2;
+ } else
+ range->num_encoding_sizes = 1;
+ range->max_encoding_tokens = (cap_rid.softCap & 0x80) ? 4 : 1;
+ } else {
+ range->num_encoding_sizes = 0;
+ range->max_encoding_tokens = 0;
+ }
+ range->min_pmp = 0;
+ range->max_pmp = 5000000; /* 5 secs */
+ range->min_pmt = 0;
+ range->max_pmt = 65535 * 1024; /* ??? */
+ range->pmp_flags = IW_POWER_PERIOD;
+ range->pmt_flags = IW_POWER_TIMEOUT;
+ range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
+
+ /* Transmit Power - values are in mW */
+ for(i = 0 ; i < 8 ; i++) {
+ range->txpower[i] = cap_rid.txPowerLevels[i];
+ if(range->txpower[i] == 0)
+ break;
+ }
+ range->num_txpower = i;
+ range->txpower_capa = IW_TXPOW_MWATT;
+ range->we_version_source = 12;
+ range->we_version_compiled = WIRELESS_EXT;
+ range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
+ range->retry_flags = IW_RETRY_LIMIT;
+ range->r_time_flags = IW_RETRY_LIFETIME;
+ range->min_retry = 1;
+ range->max_retry = 65535;
+ range->min_r_time = 1024;
+ range->max_r_time = 65535 * 1024;
+ /* Experimental measurements - boundary 11/5.5 Mb/s */
+ /* Note : with or without the (local->rssi), results
+ * are somewhat different. - Jean II */
+ range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
+ if (local->rssi)
+ range->avg_qual.level = 186; /* -70 dBm */
+ else
+ range->avg_qual.level = 176; /* -80 dBm */
+ range->avg_qual.noise = 0;
+
+ /* Event capability (kernel + driver) */
+ range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
+ IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
+ IW_EVENT_CAPA_MASK(SIOCGIWAP) |
+ IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
+ range->event_capa[1] = IW_EVENT_CAPA_K_1;
+ range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP);
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Power Management
+ */
+static int airo_set_power(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ readConfigRid(local, 1);
+ if (vwrq->disabled) {
+ if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
+ return -EINVAL;
+ }
+ local->config.powerSaveMode = POWERSAVE_CAM;
+ local->config.rmode &= 0xFF00;
+ local->config.rmode |= RXMODE_BC_MC_ADDR;
+ set_bit (FLAG_COMMIT, &local->flags);
+ return -EINPROGRESS; /* Call commit handler */
+ }
+ if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
+ local->config.fastListenDelay = (vwrq->value + 500) / 1024;
+ local->config.powerSaveMode = POWERSAVE_PSPCAM;
+ set_bit (FLAG_COMMIT, &local->flags);
+ } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
+ local->config.fastListenInterval = local->config.listenInterval = (vwrq->value + 500) / 1024;
+ local->config.powerSaveMode = POWERSAVE_PSPCAM;
+ set_bit (FLAG_COMMIT, &local->flags);
+ }
+ switch (vwrq->flags & IW_POWER_MODE) {
+ case IW_POWER_UNICAST_R:
+ if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
+ return -EINVAL;
+ }
+ local->config.rmode &= 0xFF00;
+ local->config.rmode |= RXMODE_ADDR;
+ set_bit (FLAG_COMMIT, &local->flags);
+ break;
+ case IW_POWER_ALL_R:
+ if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
+ return -EINVAL;
+ }
+ local->config.rmode &= 0xFF00;
+ local->config.rmode |= RXMODE_BC_MC_ADDR;
+ set_bit (FLAG_COMMIT, &local->flags);
+ case IW_POWER_ON:
+ break;
+ default:
+ return -EINVAL;
+ }
+ // Note : we may want to factor local->need_commit here
+ // Note2 : may also want to factor RXMODE_RFMON test
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Power Management
+ */
+static int airo_get_power(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ int mode;
+
+ readConfigRid(local, 1);
+ mode = local->config.powerSaveMode;
+ if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
+ return 0;
+ if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
+ vwrq->value = (int)local->config.fastListenDelay * 1024;
+ vwrq->flags = IW_POWER_TIMEOUT;
+ } else {
+ vwrq->value = (int)local->config.fastListenInterval * 1024;
+ vwrq->flags = IW_POWER_PERIOD;
+ }
+ if ((local->config.rmode & 0xFF) == RXMODE_ADDR)
+ vwrq->flags |= IW_POWER_UNICAST_R;
+ else
+ vwrq->flags |= IW_POWER_ALL_R;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : set Sensitivity
+ */
+static int airo_set_sens(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ readConfigRid(local, 1);
+ local->config.rssiThreshold = vwrq->disabled ? RSSI_DEFAULT : vwrq->value;
+ set_bit (FLAG_COMMIT, &local->flags);
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get Sensitivity
+ */
+static int airo_get_sens(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+
+ readConfigRid(local, 1);
+ vwrq->value = local->config.rssiThreshold;
+ vwrq->disabled = (vwrq->value == 0);
+ vwrq->fixed = 1;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : get AP List
+ * Note : this is deprecated in favor of IWSCAN
+ */
+static int airo_get_aplist(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *local = dev->priv;
+ struct sockaddr *address = (struct sockaddr *) extra;
+ struct iw_quality qual[IW_MAX_AP];
+ BSSListRid BSSList;
+ int i;
+ int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
+
+ for (i = 0; i < IW_MAX_AP; i++) {
+ if (readBSSListRid(local, loseSync, &BSSList))
+ break;
+ loseSync = 0;
+ memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
+ address[i].sa_family = ARPHRD_ETHER;
+ if (local->rssi)
+ qual[i].level = 0x100 - local->rssi[BSSList.rssi].rssidBm;
+ else
+ qual[i].level = (BSSList.rssi + 321) / 2;
+ qual[i].qual = qual[i].noise = 0;
+ qual[i].updated = 2;
+ if (BSSList.index == 0xffff)
+ break;
+ }
+ if (!i) {
+ StatusRid status_rid; /* Card status info */
+ readStatusRid(local, &status_rid, 1);
+ for (i = 0;
+ i < min(IW_MAX_AP, 4) &&
+ (status_rid.bssid[i][0]
+ & status_rid.bssid[i][1]
+ & status_rid.bssid[i][2]
+ & status_rid.bssid[i][3]
+ & status_rid.bssid[i][4]
+ & status_rid.bssid[i][5])!=0xff &&
+ (status_rid.bssid[i][0]
+ | status_rid.bssid[i][1]
+ | status_rid.bssid[i][2]
+ | status_rid.bssid[i][3]
+ | status_rid.bssid[i][4]
+ | status_rid.bssid[i][5]);
+ i++) {
+ memcpy(address[i].sa_data,
+ status_rid.bssid[i], ETH_ALEN);
+ address[i].sa_family = ARPHRD_ETHER;
+ }
+ } else {
+ dwrq->flags = 1; /* Should be define'd */
+ memcpy(extra + sizeof(struct sockaddr)*i,
+ &qual, sizeof(struct iw_quality)*i);
+ }
+ dwrq->length = i;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : Initiate Scan
+ */
+static int airo_set_scan(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct airo_info *ai = dev->priv;
+ Cmd cmd;
+ Resp rsp;
+
+ /* Note : you may have realised that, as this is a SET operation,
+ * this is privileged and therefore a normal user can't
+ * perform scanning.
+ * This is not an error, while the device perform scanning,
+ * traffic doesn't flow, so it's a perfect DoS...
+ * Jean II */
+ if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
+
+ /* Initiate a scan command */
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd=CMD_LISTBSS;
+ if (down_interruptible(&ai->sem))
+ return -ERESTARTSYS;
+ issuecommand(ai, &cmd, &rsp);
+ ai->scan_timestamp = jiffies;
+ up(&ai->sem);
+
+ /* At this point, just return to the user. */
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Translate scan data returned from the card to a card independent
+ * format that the Wireless Tools will understand - Jean II
+ */
+static inline char *airo_translate_scan(struct net_device *dev,
+ char *current_ev,
+ char *end_buf,
+ BSSListRid *list)
+{
+ struct airo_info *ai = dev->priv;
+ struct iw_event iwe; /* Temporary buffer */
+ u16 capabilities;
+ char * current_val; /* For rates */
+ int i;
+
+ /* First entry *MUST* be the AP MAC address */
+ iwe.cmd = SIOCGIWAP;
+ iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
+ memcpy(iwe.u.ap_addr.sa_data, list->bssid, ETH_ALEN);
+ current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
+
+ /* Other entries will be displayed in the order we give them */
+
+ /* Add the ESSID */
+ iwe.u.data.length = list->ssidLen;
+ if(iwe.u.data.length > 32)
+ iwe.u.data.length = 32;
+ iwe.cmd = SIOCGIWESSID;
+ iwe.u.data.flags = 1;
+ current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, list->ssid);
+
+ /* Add mode */
+ iwe.cmd = SIOCGIWMODE;
+ capabilities = le16_to_cpu(list->cap);
+ if(capabilities & (CAP_ESS | CAP_IBSS)) {
+ if(capabilities & CAP_ESS)
+ iwe.u.mode = IW_MODE_MASTER;
+ else
+ iwe.u.mode = IW_MODE_ADHOC;
+ current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
+ }
+
+ /* Add frequency */
+ iwe.cmd = SIOCGIWFREQ;
+ iwe.u.freq.m = le16_to_cpu(list->dsChannel);
+ iwe.u.freq.m = frequency_list[iwe.u.freq.m] * 100000;
+ iwe.u.freq.e = 1;
+ current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
+
+ /* Add quality statistics */
+ iwe.cmd = IWEVQUAL;
+ if (ai->rssi)
+ iwe.u.qual.level = 0x100 - ai->rssi[list->rssi].rssidBm;
+ else
+ iwe.u.qual.level = (list->rssi + 321) / 2;
+ iwe.u.qual.noise = 0;
+ iwe.u.qual.qual = 0;
+ current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
+
+ /* Add encryption capability */
+ iwe.cmd = SIOCGIWENCODE;
+ if(capabilities & CAP_PRIVACY)
+ iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
+ else
+ iwe.u.data.flags = IW_ENCODE_DISABLED;
+ iwe.u.data.length = 0;
+ current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, list->ssid);
+
+ /* Rate : stuffing multiple values in a single event require a bit
+ * more of magic - Jean II */
+ current_val = current_ev + IW_EV_LCP_LEN;
+
+ iwe.cmd = SIOCGIWRATE;
+ /* Those two flags are ignored... */
+ iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
+ /* Max 8 values */
+ for(i = 0 ; i < 8 ; i++) {
+ /* NULL terminated */
+ if(list->rates[i] == 0)
+ break;
+ /* Bit rate given in 500 kb/s units (+ 0x80) */
+ iwe.u.bitrate.value = ((list->rates[i] & 0x7f) * 500000);
+ /* Add new value to event */
+ current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
+ }
+ /* Check if we added any event */
+ if((current_val - current_ev) > IW_EV_LCP_LEN)
+ current_ev = current_val;
+
+ /* The other data in the scan result are not really
+ * interesting, so for now drop it - Jean II */
+ return current_ev;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Wireless Handler : Read Scan Results
+ */
+static int airo_get_scan(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct airo_info *ai = dev->priv;
+ BSSListRid BSSList;
+ int rc;
+ char *current_ev = extra;
+
+ /* When we are associated again, the scan has surely finished.
+ * Just in case, let's make sure enough time has elapsed since
+ * we started the scan. - Javier */
+ if(ai->scan_timestamp && time_before(jiffies,ai->scan_timestamp+3*HZ)) {
+ /* Important note : we don't want to block the caller
+ * until results are ready for various reasons.
+ * First, managing wait queues is complex and racy
+ * (there may be multiple simultaneous callers).
+ * Second, we grab some rtnetlink lock before comming
+ * here (in dev_ioctl()).
+ * Third, the caller can wait on the Wireless Event
+ * - Jean II */
+ return -EAGAIN;
+ }
+ ai->scan_timestamp = 0;
+
+ /* There's only a race with proc_BSSList_open(), but its
+ * consequences are begnign. So I don't bother fixing it - Javier */
+
+ /* Try to read the first entry of the scan result */
+ rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 1);
+ if((rc) || (BSSList.index == 0xffff)) {
+ /* Client error, no scan results...
+ * The caller need to restart the scan. */
+ return -ENODATA;
+ }
+
+ /* Read and parse all entries */
+ while((!rc) && (BSSList.index != 0xffff)) {
+ /* Translate to WE format this entry */
+ current_ev = airo_translate_scan(dev, current_ev,
+ extra + dwrq->length,
+ &BSSList);
+
+ /* Check if there is space for one more entry */
+ if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
+ /* Ask user space to try again with a bigger buffer */
+ return -E2BIG;
+ }
+
+ /* Read next entry */
+ rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
+ &BSSList, sizeof(BSSList), 1);
+ }
+ /* Length of data */
+ dwrq->length = (current_ev - extra);
+ dwrq->flags = 0; /* todo */
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Commit handler : called after a bunch of SET operations
+ */
+static int airo_config_commit(struct net_device *dev,
+ struct iw_request_info *info, /* NULL */
+ void *zwrq, /* NULL */
+ char *extra) /* NULL */
+{
+ struct airo_info *local = dev->priv;
+ Resp rsp;
+
+ if (!test_bit (FLAG_COMMIT, &local->flags))
+ return 0;
+
+ /* Some of the "SET" function may have modified some of the
+ * parameters. It's now time to commit them in the card */
+ disable_MAC(local, 1);
+ if (test_bit (FLAG_RESET, &local->flags)) {
+ APListRid APList_rid;
+ SsidRid SSID_rid;
+
+ readAPListRid(local, &APList_rid);
+ readSsidRid(local, &SSID_rid);
+ if (test_bit(FLAG_MPI,&local->flags))
+ setup_card(local, dev->dev_addr, 1 );
+ else
+ reset_airo_card(dev);
+ disable_MAC(local, 1);
+ writeSsidRid(local, &SSID_rid, 1);
+ writeAPListRid(local, &APList_rid, 1);
+ }
+ if (down_interruptible(&local->sem))
+ return -ERESTARTSYS;
+ writeConfigRid(local, 0);
+ enable_MAC(local, &rsp, 0);
+ if (test_bit (FLAG_RESET, &local->flags))
+ airo_set_promisc(local);
+ else
+ up(&local->sem);
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/*
+ * Structures to export the Wireless Handlers
+ */
+
+static const struct iw_priv_args airo_private_args[] = {
+/*{ cmd, set_args, get_args, name } */
+ { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
+ IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
+ { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
+ IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
+};
+
+static const iw_handler airo_handler[] =
+{
+ (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
+ (iw_handler) airo_get_name, /* SIOCGIWNAME */
+ (iw_handler) NULL, /* SIOCSIWNWID */
+ (iw_handler) NULL, /* SIOCGIWNWID */
+ (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
+ (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
+ (iw_handler) airo_set_mode, /* SIOCSIWMODE */
+ (iw_handler) airo_get_mode, /* SIOCGIWMODE */
+ (iw_handler) airo_set_sens, /* SIOCSIWSENS */
+ (iw_handler) airo_get_sens, /* SIOCGIWSENS */
+ (iw_handler) NULL, /* SIOCSIWRANGE */
+ (iw_handler) airo_get_range, /* SIOCGIWRANGE */
+ (iw_handler) NULL, /* SIOCSIWPRIV */
+ (iw_handler) NULL, /* SIOCGIWPRIV */
+ (iw_handler) NULL, /* SIOCSIWSTATS */
+ (iw_handler) NULL, /* SIOCGIWSTATS */
+ iw_handler_set_spy, /* SIOCSIWSPY */
+ iw_handler_get_spy, /* SIOCGIWSPY */
+ iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
+ iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
+ (iw_handler) airo_set_wap, /* SIOCSIWAP */
+ (iw_handler) airo_get_wap, /* SIOCGIWAP */
+ (iw_handler) NULL, /* -- hole -- */
+ (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
+ (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
+ (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
+ (iw_handler) airo_set_essid, /* SIOCSIWESSID */
+ (iw_handler) airo_get_essid, /* SIOCGIWESSID */
+ (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
+ (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
+ (iw_handler) NULL, /* -- hole -- */
+ (iw_handler) NULL, /* -- hole -- */
+ (iw_handler) airo_set_rate, /* SIOCSIWRATE */
+ (iw_handler) airo_get_rate, /* SIOCGIWRATE */
+ (iw_handler) airo_set_rts, /* SIOCSIWRTS */
+ (iw_handler) airo_get_rts, /* SIOCGIWRTS */
+ (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
+ (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
+ (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
+ (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
+ (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
+ (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
+ (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
+ (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
+ (iw_handler) airo_set_power, /* SIOCSIWPOWER */
+ (iw_handler) airo_get_power, /* SIOCGIWPOWER */
+};
+
+/* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
+ * We want to force the use of the ioctl code, because those can't be
+ * won't work the iw_handler code (because they simultaneously read
+ * and write data and iw_handler can't do that).
+ * Note that it's perfectly legal to read/write on a single ioctl command,
+ * you just can't use iwpriv and need to force it via the ioctl handler.
+ * Jean II */
+static const iw_handler airo_private_handler[] =
+{
+ NULL, /* SIOCIWFIRSTPRIV */
+};
+
+static const struct iw_handler_def airo_handler_def =
+{
+ .num_standard = sizeof(airo_handler)/sizeof(iw_handler),
+ .num_private = sizeof(airo_private_handler)/sizeof(iw_handler),
+ .num_private_args = sizeof(airo_private_args)/sizeof(struct iw_priv_args),
+ .standard = airo_handler,
+ .private = airo_private_handler,
+ .private_args = airo_private_args,
+ .get_wireless_stats = airo_get_wireless_stats,
+};
+
+#endif /* WIRELESS_EXT */
+
+/*
+ * This defines the configuration part of the Wireless Extensions
+ * Note : irq and spinlock protection will occur in the subroutines
+ *
+ * TODO :
+ * o Check input value more carefully and fill correct values in range
+ * o Test and shakeout the bugs (if any)
+ *
+ * Jean II
+ *
+ * Javier Achirica did a great job of merging code from the unnamed CISCO
+ * developer that added support for flashing the card.
+ */
+static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+{
+ int rc = 0;
+ struct airo_info *ai = (struct airo_info *)dev->priv;
+
+ if (ai->power)
+ return 0;
+
+ switch (cmd) {
+#ifdef CISCO_EXT
+ case AIROIDIFC:
+#ifdef AIROOLDIDIFC
+ case AIROOLDIDIFC:
+#endif
+ {
+ int val = AIROMAGIC;
+ aironet_ioctl com;
+ if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
+ rc = -EFAULT;
+ else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
+ rc = -EFAULT;
+ }
+ break;
+
+ case AIROIOCTL:
+#ifdef AIROOLDIOCTL
+ case AIROOLDIOCTL:
+#endif
+ /* Get the command struct and hand it off for evaluation by
+ * the proper subfunction
+ */
+ {
+ aironet_ioctl com;
+ if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
+ rc = -EFAULT;
+ break;
+ }
+
+ /* Separate R/W functions bracket legality here
+ */
+ if ( com.command == AIRORSWVERSION ) {
+ if (copy_to_user(com.data, swversion, sizeof(swversion)))
+ rc = -EFAULT;
+ else
+ rc = 0;
+ }
+ else if ( com.command <= AIRORRID)
+ rc = readrids(dev,&com);
+ else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) )
+ rc = writerids(dev,&com);
+ else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
+ rc = flashcard(dev,&com);
+ else
+ rc = -EINVAL; /* Bad command in ioctl */
+ }
+ break;
+#endif /* CISCO_EXT */
+
+ // All other calls are currently unsupported
+ default:
+ rc = -EOPNOTSUPP;
+ }
+ return rc;
+}
+
+#ifdef WIRELESS_EXT
+/*
+ * Get the Wireless stats out of the driver
+ * Note : irq and spinlock protection will occur in the subroutines
+ *
+ * TODO :
+ * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
+ *
+ * Jean
+ */
+static void airo_read_wireless_stats(struct airo_info *local)
+{
+ StatusRid status_rid;
+ StatsRid stats_rid;
+ CapabilityRid cap_rid;
+ u32 *vals = stats_rid.vals;
+
+ /* Get stats out of the card */
+ clear_bit(JOB_WSTATS, &local->flags);
+ if (local->power) {
+ up(&local->sem);
+ return;
+ }
+ readCapabilityRid(local, &cap_rid, 0);
+ readStatusRid(local, &status_rid, 0);
+ readStatsRid(local, &stats_rid, RID_STATS, 0);
+ up(&local->sem);
+
+ /* The status */
+ local->wstats.status = status_rid.mode;
+
+ /* Signal quality and co. But where is the noise level ??? */
+ local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
+ if (local->rssi)
+ local->wstats.qual.level = 0x100 - local->rssi[status_rid.sigQuality].rssidBm;
+ else
+ local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2;
+ if (status_rid.len >= 124) {
+ local->wstats.qual.noise = 256 - status_rid.noisedBm;
+ local->wstats.qual.updated = 7;
+ } else {
+ local->wstats.qual.noise = 0;
+ local->wstats.qual.updated = 3;
+ }
+
+ /* Packets discarded in the wireless adapter due to wireless
+ * specific problems */
+ local->wstats.discard.nwid = vals[56] + vals[57] + vals[58];/* SSID Mismatch */
+ local->wstats.discard.code = vals[6];/* RxWepErr */
+ local->wstats.discard.fragment = vals[30];
+ local->wstats.discard.retries = vals[10];
+ local->wstats.discard.misc = vals[1] + vals[32];
+ local->wstats.miss.beacon = vals[34];
+}
+
+struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
+{
+ struct airo_info *local = dev->priv;
+
+ if (!test_bit(JOB_WSTATS, &local->flags)) {
+ /* Get stats out of the card if available */
+ if (down_trylock(&local->sem) != 0) {
+ set_bit(JOB_WSTATS, &local->flags);
+ wake_up_interruptible(&local->thr_wait);
+ } else
+ airo_read_wireless_stats(local);
+ }
+
+ return &local->wstats;
+}
+#endif /* WIRELESS_EXT */
+
+#ifdef CISCO_EXT
+/*
+ * This just translates from driver IOCTL codes to the command codes to
+ * feed to the radio's host interface. Things can be added/deleted
+ * as needed. This represents the READ side of control I/O to
+ * the card
+ */
+static int readrids(struct net_device *dev, aironet_ioctl *comp) {
+ unsigned short ridcode;
+ unsigned char *iobuf;
+ int len;
+ struct airo_info *ai = dev->priv;
+ Resp rsp;
+
+ if (test_bit(FLAG_FLASHING, &ai->flags))
+ return -EIO;
+
+ switch(comp->command)
+ {
+ case AIROGCAP: ridcode = RID_CAPABILITIES; break;
+ case AIROGCFG: ridcode = RID_CONFIG;
+ if (test_bit(FLAG_COMMIT, &ai->flags)) {
+ disable_MAC (ai, 1);
+ writeConfigRid (ai, 1);
+ enable_MAC (ai, &rsp, 1);
+ }
+ break;
+ case AIROGSLIST: ridcode = RID_SSID; break;
+ case AIROGVLIST: ridcode = RID_APLIST; break;
+ case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
+ case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
+ case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
+ /* Only super-user can read WEP keys */
+ if (!capable(CAP_NET_ADMIN))
+ return -EPERM;
+ break;
+ case AIROGWEPKNV: ridcode = RID_WEP_PERM;
+ /* Only super-user can read WEP keys */
+ if (!capable(CAP_NET_ADMIN))
+ return -EPERM;
+ break;
+ case AIROGSTAT: ridcode = RID_STATUS; break;
+ case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
+ case AIROGSTATSC32: ridcode = RID_STATS; break;
+#ifdef MICSUPPORT
+ case AIROGMICSTATS:
+ if (copy_to_user(comp->data, &ai->micstats,
+ min((int)comp->len,(int)sizeof(ai->micstats))))
+ return -EFAULT;
+ return 0;
+#endif
+ case AIRORRID: ridcode = comp->ridnum; break;
+ default:
+ return -EINVAL;
+ break;
+ }
+
+ if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+
+ PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
+ /* get the count of bytes in the rid docs say 1st 2 bytes is it.
+ * then return it to the user
+ * 9/22/2000 Honor user given length
+ */
+ len = comp->len;
+
+ if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
+ kfree (iobuf);
+ return -EFAULT;
+ }
+ kfree (iobuf);
+ return 0;
+}
+
+/*
+ * Danger Will Robinson write the rids here
+ */
+
+static int writerids(struct net_device *dev, aironet_ioctl *comp) {
+ struct airo_info *ai = dev->priv;
+ int ridcode;
+#ifdef MICSUPPORT
+ int enabled;
+#endif
+ Resp rsp;
+ static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
+ unsigned char *iobuf;
+
+ /* Only super-user can write RIDs */
+ if (!capable(CAP_NET_ADMIN))
+ return -EPERM;
+
+ if (test_bit(FLAG_FLASHING, &ai->flags))
+ return -EIO;
+
+ ridcode = 0;
+ writer = do_writerid;
+
+ switch(comp->command)
+ {
+ case AIROPSIDS: ridcode = RID_SSID; break;
+ case AIROPCAP: ridcode = RID_CAPABILITIES; break;
+ case AIROPAPLIST: ridcode = RID_APLIST; break;
+ case AIROPCFG: ai->config.len = 0;
+ clear_bit(FLAG_COMMIT, &ai->flags);
+ ridcode = RID_CONFIG; break;
+ case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
+ case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
+ case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
+ case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
+ break;
+ case AIROPLEAPUSR+1: ridcode = 0xFF2A; break;
+ case AIROPLEAPUSR+2: ridcode = 0xFF2B; break;
+
+ /* this is not really a rid but a command given to the card
+ * same with MAC off
+ */
+ case AIROPMACON:
+ if (enable_MAC(ai, &rsp, 1) != 0)
+ return -EIO;
+ return 0;
+
+ /*
+ * Evidently this code in the airo driver does not get a symbol
+ * as disable_MAC. it's probably so short the compiler does not gen one.
+ */
+ case AIROPMACOFF:
+ disable_MAC(ai, 1);
+ return 0;
+
+ /* This command merely clears the counts does not actually store any data
+ * only reads rid. But as it changes the cards state, I put it in the
+ * writerid routines.
+ */
+ case AIROPSTCLR:
+ if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+
+ PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
+
+#ifdef MICSUPPORT
+ enabled = ai->micstats.enabled;
+ memset(&ai->micstats,0,sizeof(ai->micstats));
+ ai->micstats.enabled = enabled;
+#endif
+
+ if (copy_to_user(comp->data, iobuf,
+ min((int)comp->len, (int)RIDSIZE))) {
+ kfree (iobuf);
+ return -EFAULT;
+ }
+ kfree (iobuf);
+ return 0;
+
+ default:
+ return -EOPNOTSUPP; /* Blarg! */
+ }
+ if(comp->len > RIDSIZE)
+ return -EINVAL;
+
+ if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+
+ if (copy_from_user(iobuf,comp->data,comp->len)) {
+ kfree (iobuf);
+ return -EFAULT;
+ }
+
+ if (comp->command == AIROPCFG) {
+ ConfigRid *cfg = (ConfigRid *)iobuf;
+
+ if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
+ cfg->opmode |= MODE_MIC;
+
+ if ((cfg->opmode & 0xFF) == MODE_STA_IBSS)
+ set_bit (FLAG_ADHOC, &ai->flags);
+ else
+ clear_bit (FLAG_ADHOC, &ai->flags);
+ }
+
+ if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
+ kfree (iobuf);
+ return -EIO;
+ }
+ kfree (iobuf);
+ return 0;
+}
+
+/*****************************************************************************
+ * Ancillary flash / mod functions much black magic lurkes here *
+ *****************************************************************************
+ */
+
+/*
+ * Flash command switch table
+ */
+
+int flashcard(struct net_device *dev, aironet_ioctl *comp) {
+ int z;
+ int cmdreset(struct airo_info *);
+ int setflashmode(struct airo_info *);
+ int flashgchar(struct airo_info *,int,int);
+ int flashpchar(struct airo_info *,int,int);
+ int flashputbuf(struct airo_info *);
+ int flashrestart(struct airo_info *,struct net_device *);
+
+ /* Only super-user can modify flash */
+ if (!capable(CAP_NET_ADMIN))
+ return -EPERM;
+
+ switch(comp->command)
+ {
+ case AIROFLSHRST:
+ return cmdreset((struct airo_info *)dev->priv);
+
+ case AIROFLSHSTFL:
+ if (!((struct airo_info *)dev->priv)->flash &&
+ (((struct airo_info *)dev->priv)->flash = kmalloc (FLASHSIZE, GFP_KERNEL)) == NULL)
+ return -ENOMEM;
+ return setflashmode((struct airo_info *)dev->priv);
+
+ case AIROFLSHGCHR: /* Get char from aux */
+ if(comp->len != sizeof(int))
+ return -EINVAL;
+ if (copy_from_user(&z,comp->data,comp->len))
+ return -EFAULT;
+ return flashgchar((struct airo_info *)dev->priv,z,8000);
+
+ case AIROFLSHPCHR: /* Send char to card. */
+ if(comp->len != sizeof(int))
+ return -EINVAL;
+ if (copy_from_user(&z,comp->data,comp->len))
+ return -EFAULT;
+ return flashpchar((struct airo_info *)dev->priv,z,8000);
+
+ case AIROFLPUTBUF: /* Send 32k to card */
+ if (!((struct airo_info *)dev->priv)->flash)
+ return -ENOMEM;
+ if(comp->len > FLASHSIZE)
+ return -EINVAL;
+ if(copy_from_user(((struct airo_info *)dev->priv)->flash,comp->data,comp->len))
+ return -EFAULT;
+
+ flashputbuf((struct airo_info *)dev->priv);
+ return 0;
+
+ case AIRORESTART:
+ if(flashrestart((struct airo_info *)dev->priv,dev))
+ return -EIO;
+ return 0;
+ }
+ return -EINVAL;
+}
+
+#define FLASH_COMMAND 0x7e7e
+
+/*
+ * STEP 1)
+ * Disable MAC and do soft reset on
+ * card.
+ */
+
+int cmdreset(struct airo_info *ai) {
+ disable_MAC(ai, 1);
+
+ if(!waitbusy (ai)){
+ printk(KERN_INFO "Waitbusy hang before RESET\n");
+ return -EBUSY;
+ }
+
+ OUT4500(ai,COMMAND,CMD_SOFTRESET);
+
+ ssleep(1); /* WAS 600 12/7/00 */
+
+ if(!waitbusy (ai)){
+ printk(KERN_INFO "Waitbusy hang AFTER RESET\n");
+ return -EBUSY;
+ }
+ return 0;
+}
+
+/* STEP 2)
+ * Put the card in legendary flash
+ * mode
+ */
+
+int setflashmode (struct airo_info *ai) {
+ set_bit (FLAG_FLASHING, &ai->flags);
+
+ OUT4500(ai, SWS0, FLASH_COMMAND);
+ OUT4500(ai, SWS1, FLASH_COMMAND);
+ if (probe) {
+ OUT4500(ai, SWS0, FLASH_COMMAND);
+ OUT4500(ai, COMMAND,0x10);
+ } else {
+ OUT4500(ai, SWS2, FLASH_COMMAND);
+ OUT4500(ai, SWS3, FLASH_COMMAND);
+ OUT4500(ai, COMMAND,0);
+ }
+ msleep(500); /* 500ms delay */
+
+ if(!waitbusy(ai)) {
+ clear_bit (FLAG_FLASHING, &ai->flags);
+ printk(KERN_INFO "Waitbusy hang after setflash mode\n");
+ return -EIO;
+ }
+ return 0;
+}
+
+/* Put character to SWS0 wait for dwelltime
+ * x 50us for echo .
+ */
+
+int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
+ int echo;
+ int waittime;
+
+ byte |= 0x8000;
+
+ if(dwelltime == 0 )
+ dwelltime = 200;
+
+ waittime=dwelltime;
+
+ /* Wait for busy bit d15 to go false indicating buffer empty */
+ while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
+ udelay (50);
+ waittime -= 50;
+ }
+
+ /* timeout for busy clear wait */
+ if(waittime <= 0 ){
+ printk(KERN_INFO "flash putchar busywait timeout! \n");
+ return -EBUSY;
+ }
+
+ /* Port is clear now write byte and wait for it to echo back */
+ do {
+ OUT4500(ai,SWS0,byte);
+ udelay(50);
+ dwelltime -= 50;
+ echo = IN4500(ai,SWS1);
+ } while (dwelltime >= 0 && echo != byte);
+
+ OUT4500(ai,SWS1,0);
+
+ return (echo == byte) ? 0 : -EIO;
+}
+
+/*
+ * Get a character from the card matching matchbyte
+ * Step 3)
+ */
+int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
+ int rchar;
+ unsigned char rbyte=0;
+
+ do {
+ rchar = IN4500(ai,SWS1);
+
+ if(dwelltime && !(0x8000 & rchar)){
+ dwelltime -= 10;
+ mdelay(10);
+ continue;
+ }
+ rbyte = 0xff & rchar;
+
+ if( (rbyte == matchbyte) && (0x8000 & rchar) ){
+ OUT4500(ai,SWS1,0);
+ return 0;
+ }
+ if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
+ break;
+ OUT4500(ai,SWS1,0);
+
+ }while(dwelltime > 0);
+ return -EIO;
+}
+
+/*
+ * Transfer 32k of firmware data from user buffer to our buffer and
+ * send to the card
+ */
+
+int flashputbuf(struct airo_info *ai){
+ int nwords;
+
+ /* Write stuff */
+ if (test_bit(FLAG_MPI,&ai->flags))
+ memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
+ else {
+ OUT4500(ai,AUXPAGE,0x100);
+ OUT4500(ai,AUXOFF,0);
+
+ for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
+ OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
+ }
+ }
+ OUT4500(ai,SWS0,0x8000);
+
+ return 0;
+}
+
+/*
+ *
+ */
+int flashrestart(struct airo_info *ai,struct net_device *dev){
+ int i,status;
+
+ ssleep(1); /* Added 12/7/00 */
+ clear_bit (FLAG_FLASHING, &ai->flags);
+ if (test_bit(FLAG_MPI, &ai->flags)) {
+ status = mpi_init_descriptors(ai);
+ if (status != SUCCESS)
+ return status;
+ }
+ status = setup_card(ai, dev->dev_addr, 1);
+
+ if (!test_bit(FLAG_MPI,&ai->flags))
+ for( i = 0; i < MAX_FIDS; i++ ) {
+ ai->fids[i] = transmit_allocate
+ ( ai, 2312, i >= MAX_FIDS / 2 );
+ }
+
+ ssleep(1); /* Added 12/7/00 */
+ return status;
+}
+#endif /* CISCO_EXT */
+
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ In addition:
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+module_init(airo_init_module);
+module_exit(airo_cleanup_module);
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
new file mode 100644
index 000000000000..fbf53af6cda4
--- /dev/null
+++ b/drivers/net/wireless/airo_cs.c
@@ -0,0 +1,622 @@
+/*======================================================================
+
+ Aironet driver for 4500 and 4800 series cards
+
+ This code is released under both the GPL version 2 and BSD licenses.
+ Either license may be used. The respective licenses are found at
+ the end of this file.
+
+ This code was developed by Benjamin Reed <breed@users.sourceforge.net>
+ including portions of which come from the Aironet PC4500
+ Developer's Reference Manual and used with permission. Copyright
+ (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
+ code in the Developer's manual was granted for this driver by
+ Aironet.
+
+ In addition this module was derived from dummy_cs.
+ The initial developer of dummy_cs is David A. Hinds
+ <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
+ are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
+
+======================================================================*/
+
+#include <linux/config.h>
+#ifdef __IN_PCMCIA_PACKAGE__
+#include <pcmcia/k_compat.h>
+#endif
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/netdevice.h>
+
+#include <pcmcia/version.h>
+#include <pcmcia/cs_types.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/cisreg.h>
+#include <pcmcia/ds.h>
+
+#include <asm/io.h>
+#include <asm/system.h>
+
+/*
+ All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
+ you do not define PCMCIA_DEBUG at all, all the debug code will be
+ left out. If you compile with PCMCIA_DEBUG=0, the debug code will
+ be present but disabled -- but it can then be enabled for specific
+ modules at load time with a 'pc_debug=#' option to insmod.
+*/
+#ifdef PCMCIA_DEBUG
+static int pc_debug = PCMCIA_DEBUG;
+module_param(pc_debug, int, 0);
+static char *version = "$Revision: 1.2 $";
+#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args);
+#else
+#define DEBUG(n, args...)
+#endif
+
+/*====================================================================*/
+
+MODULE_AUTHOR("Benjamin Reed");
+MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
+ cards. This is the module that links the PCMCIA card \
+ with the airo module.");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
+
+/*====================================================================*/
+
+/*
+ The event() function is this driver's Card Services event handler.
+ It will be called by Card Services when an appropriate card status
+ event is received. The config() and release() entry points are
+ used to configure or release a socket, in response to card
+ insertion and ejection events. They are invoked from the airo_cs
+ event handler.
+*/
+
+struct net_device *init_airo_card( int, int, int, struct device * );
+void stop_airo_card( struct net_device *, int );
+int reset_airo_card( struct net_device * );
+
+static void airo_config(dev_link_t *link);
+static void airo_release(dev_link_t *link);
+static int airo_event(event_t event, int priority,
+ event_callback_args_t *args);
+
+/*
+ The attach() and detach() entry points are used to create and destroy
+ "instances" of the driver, where each instance represents everything
+ needed to manage one actual PCMCIA card.
+*/
+
+static dev_link_t *airo_attach(void);
+static void airo_detach(dev_link_t *);
+
+/*
+ You'll also need to prototype all the functions that will actually
+ be used to talk to your device. See 'pcmem_cs' for a good example
+ of a fully self-sufficient driver; the other drivers rely more or
+ less on other parts of the kernel.
+*/
+
+/*
+ The dev_info variable is the "key" that is used to match up this
+ device driver with appropriate cards, through the card configuration
+ database.
+*/
+
+static dev_info_t dev_info = "airo_cs";
+
+/*
+ A linked list of "instances" of the aironet device. Each actual
+ PCMCIA card corresponds to one device instance, and is described
+ by one dev_link_t structure (defined in ds.h).
+
+ You may not want to use a linked list for this -- for example, the
+ memory card driver uses an array of dev_link_t pointers, where minor
+ device numbers are used to derive the corresponding array index.
+*/
+
+static dev_link_t *dev_list = NULL;
+
+/*
+ A dev_link_t structure has fields for most things that are needed
+ to keep track of a socket, but there will usually be some device
+ specific information that also needs to be kept track of. The
+ 'priv' pointer in a dev_link_t structure can be used to point to
+ a device-specific private data structure, like this.
+
+ A driver needs to provide a dev_node_t structure for each device
+ on a card. In some cases, there is only one device per card (for
+ example, ethernet cards, modems). In other cases, there may be
+ many actual or logical devices (SCSI adapters, memory cards with
+ multiple partitions). The dev_node_t structures need to be kept
+ in a linked list starting at the 'dev' field of a dev_link_t
+ structure. We allocate them in the card's private data structure,
+ because they generally shouldn't be allocated dynamically.
+
+ In this case, we also provide a flag to indicate if a device is
+ "stopped" due to a power management event, or card ejection. The
+ device IO routines can use a flag like this to throttle IO to a
+ card that is not ready to accept it.
+*/
+
+typedef struct local_info_t {
+ dev_node_t node;
+ struct net_device *eth_dev;
+} local_info_t;
+
+/*======================================================================
+
+ airo_attach() creates an "instance" of the driver, allocating
+ local data structures for one device. The device is registered
+ with Card Services.
+
+ The dev_link structure is initialized, but we don't actually
+ configure the card at this point -- we wait until we receive a
+ card insertion event.
+
+ ======================================================================*/
+
+static dev_link_t *airo_attach(void)
+{
+ client_reg_t client_reg;
+ dev_link_t *link;
+ local_info_t *local;
+ int ret;
+
+ DEBUG(0, "airo_attach()\n");
+
+ /* Initialize the dev_link_t structure */
+ link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
+ if (!link) {
+ printk(KERN_ERR "airo_cs: no memory for new device\n");
+ return NULL;
+ }
+ memset(link, 0, sizeof(struct dev_link_t));
+
+ /* Interrupt setup */
+ link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
+ link->irq.IRQInfo1 = IRQ_LEVEL_ID;
+ link->irq.Handler = NULL;
+
+ /*
+ General socket configuration defaults can go here. In this
+ client, we assume very little, and rely on the CIS for almost
+ everything. In most clients, many details (i.e., number, sizes,
+ and attributes of IO windows) are fixed by the nature of the
+ device, and can be hard-wired here.
+ */
+ link->conf.Attributes = 0;
+ link->conf.Vcc = 50;
+ link->conf.IntType = INT_MEMORY_AND_IO;
+
+ /* Allocate space for private device-specific data */
+ local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
+ if (!local) {
+ printk(KERN_ERR "airo_cs: no memory for new device\n");
+ kfree (link);
+ return NULL;
+ }
+ memset(local, 0, sizeof(local_info_t));
+ link->priv = local;
+
+ /* Register with Card Services */
+ link->next = dev_list;
+ dev_list = link;
+ client_reg.dev_info = &dev_info;
+ client_reg.EventMask =
+ CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
+ CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
+ CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
+ client_reg.event_handler = &airo_event;
+ client_reg.Version = 0x0210;
+ client_reg.event_callback_args.client_data = link;
+ ret = pcmcia_register_client(&link->handle, &client_reg);
+ if (ret != 0) {
+ cs_error(link->handle, RegisterClient, ret);
+ airo_detach(link);
+ return NULL;
+ }
+
+ return link;
+} /* airo_attach */
+
+/*======================================================================
+
+ This deletes a driver "instance". The device is de-registered
+ with Card Services. If it has been released, all local data
+ structures are freed. Otherwise, the structures will be freed
+ when the device is released.
+
+ ======================================================================*/
+
+static void airo_detach(dev_link_t *link)
+{
+ dev_link_t **linkp;
+
+ DEBUG(0, "airo_detach(0x%p)\n", link);
+
+ /* Locate device structure */
+ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
+ if (*linkp == link) break;
+ if (*linkp == NULL)
+ return;
+
+ if (link->state & DEV_CONFIG)
+ airo_release(link);
+
+ if ( ((local_info_t*)link->priv)->eth_dev ) {
+ stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 );
+ }
+ ((local_info_t*)link->priv)->eth_dev = NULL;
+
+ /* Break the link with Card Services */
+ if (link->handle)
+ pcmcia_deregister_client(link->handle);
+
+
+
+ /* Unlink device structure, free pieces */
+ *linkp = link->next;
+ if (link->priv) {
+ kfree(link->priv);
+ }
+ kfree(link);
+
+} /* airo_detach */
+
+/*======================================================================
+
+ airo_config() is scheduled to run after a CARD_INSERTION event
+ is received, to configure the PCMCIA socket, and to make the
+ device available to the system.
+
+ ======================================================================*/
+
+#define CS_CHECK(fn, ret) \
+do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
+
+static void airo_config(dev_link_t *link)
+{
+ client_handle_t handle;
+ tuple_t tuple;
+ cisparse_t parse;
+ local_info_t *dev;
+ int last_fn, last_ret;
+ u_char buf[64];
+ win_req_t req;
+ memreq_t map;
+
+ handle = link->handle;
+ dev = link->priv;
+
+ DEBUG(0, "airo_config(0x%p)\n", link);
+
+ /*
+ This reads the card's CONFIG tuple to find its configuration
+ registers.
+ */
+ tuple.DesiredTuple = CISTPL_CONFIG;
+ tuple.Attributes = 0;
+ tuple.TupleData = buf;
+ tuple.TupleDataMax = sizeof(buf);
+ tuple.TupleOffset = 0;
+ CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
+ CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
+ CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
+ link->conf.ConfigBase = parse.config.base;
+ link->conf.Present = parse.config.rmask[0];
+
+ /* Configure card */
+ link->state |= DEV_CONFIG;
+
+ /*
+ In this loop, we scan the CIS for configuration table entries,
+ each of which describes a valid card configuration, including
+ voltage, IO window, memory window, and interrupt settings.
+
+ We make no assumptions about the card to be configured: we use
+ just the information available in the CIS. In an ideal world,
+ this would work for any PCMCIA card, but it requires a complete
+ and accurate CIS. In practice, a driver usually "knows" most of
+ these things without consulting the CIS, and most client drivers
+ will only use the CIS to fill in implementation-defined details.
+ */
+ tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
+ CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
+ while (1) {
+ cistpl_cftable_entry_t dflt = { 0 };
+ cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
+ if (pcmcia_get_tuple_data(handle, &tuple) != 0 ||
+ pcmcia_parse_tuple(handle, &tuple, &parse) != 0)
+ goto next_entry;
+
+ if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
+ if (cfg->index == 0) goto next_entry;
+ link->conf.ConfigIndex = cfg->index;
+
+ /* Does this card need audio output? */
+ if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
+ link->conf.Attributes |= CONF_ENABLE_SPKR;
+ link->conf.Status = CCSR_AUDIO_ENA;
+ }
+
+ /* Use power settings for Vcc and Vpp if present */
+ /* Note that the CIS values need to be rescaled */
+ if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM))
+ link->conf.Vcc = cfg->vcc.param[CISTPL_POWER_VNOM]/10000;
+ else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM))
+ link->conf.Vcc = dflt.vcc.param[CISTPL_POWER_VNOM]/10000;
+
+ if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
+ link->conf.Vpp1 = link->conf.Vpp2 =
+ cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
+ else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
+ link->conf.Vpp1 = link->conf.Vpp2 =
+ dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
+
+ /* Do we need to allocate an interrupt? */
+ if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
+ link->conf.Attributes |= CONF_ENABLE_IRQ;
+
+ /* IO window settings */
+ link->io.NumPorts1 = link->io.NumPorts2 = 0;
+ if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
+ cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
+ link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+ if (!(io->flags & CISTPL_IO_8BIT))
+ link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+ if (!(io->flags & CISTPL_IO_16BIT))
+ link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+ link->io.BasePort1 = io->win[0].base;
+ link->io.NumPorts1 = io->win[0].len;
+ if (io->nwin > 1) {
+ link->io.Attributes2 = link->io.Attributes1;
+ link->io.BasePort2 = io->win[1].base;
+ link->io.NumPorts2 = io->win[1].len;
+ }
+ }
+
+ /* This reserves IO space but doesn't actually enable it */
+ if (pcmcia_request_io(link->handle, &link->io) != 0)
+ goto next_entry;
+
+ /*
+ Now set up a common memory window, if needed. There is room
+ in the dev_link_t structure for one memory window handle,
+ but if the base addresses need to be saved, or if multiple
+ windows are needed, the info should go in the private data
+ structure for this device.
+
+ Note that the memory window base is a physical address, and
+ needs to be mapped to virtual space with ioremap() before it
+ is used.
+ */
+ if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
+ cistpl_mem_t *mem =
+ (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
+ req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
+ req.Base = mem->win[0].host_addr;
+ req.Size = mem->win[0].len;
+ req.AccessSpeed = 0;
+ if (pcmcia_request_window(&link->handle, &req, &link->win) != 0)
+ goto next_entry;
+ map.Page = 0; map.CardOffset = mem->win[0].card_addr;
+ if (pcmcia_map_mem_page(link->win, &map) != 0)
+ goto next_entry;
+ }
+ /* If we got this far, we're cool! */
+ break;
+
+ next_entry:
+ CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
+ }
+
+ /*
+ Allocate an interrupt line. Note that this does not assign a
+ handler to the interrupt, unless the 'Handler' member of the
+ irq structure is initialized.
+ */
+ if (link->conf.Attributes & CONF_ENABLE_IRQ)
+ CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
+
+ /*
+ This actually configures the PCMCIA socket -- setting up
+ the I/O windows and the interrupt mapping, and putting the
+ card and host interface into "Memory and IO" mode.
+ */
+ CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
+ ((local_info_t*)link->priv)->eth_dev =
+ init_airo_card( link->irq.AssignedIRQ,
+ link->io.BasePort1, 1, &handle_to_dev(handle) );
+ if (!((local_info_t*)link->priv)->eth_dev) goto cs_failed;
+
+ /*
+ At this point, the dev_node_t structure(s) need to be
+ initialized and arranged in a linked list at link->dev.
+ */
+ strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
+ dev->node.major = dev->node.minor = 0;
+ link->dev = &dev->node;
+
+ /* Finally, report what we've done */
+ printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
+ dev->node.dev_name, link->conf.ConfigIndex,
+ link->conf.Vcc/10, link->conf.Vcc%10);
+ if (link->conf.Vpp1)
+ printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
+ if (link->conf.Attributes & CONF_ENABLE_IRQ)
+ printk(", irq %d", link->irq.AssignedIRQ);
+ if (link->io.NumPorts1)
+ printk(", io 0x%04x-0x%04x", link->io.BasePort1,
+ link->io.BasePort1+link->io.NumPorts1-1);
+ if (link->io.NumPorts2)
+ printk(" & 0x%04x-0x%04x", link->io.BasePort2,
+ link->io.BasePort2+link->io.NumPorts2-1);
+ if (link->win)
+ printk(", mem 0x%06lx-0x%06lx", req.Base,
+ req.Base+req.Size-1);
+ printk("\n");
+
+ link->state &= ~DEV_CONFIG_PENDING;
+ return;
+
+ cs_failed:
+ cs_error(link->handle, last_fn, last_ret);
+ airo_release(link);
+
+} /* airo_config */
+
+/*======================================================================
+
+ After a card is removed, airo_release() will unregister the
+ device, and release the PCMCIA configuration. If the device is
+ still open, this will be postponed until it is closed.
+
+ ======================================================================*/
+
+static void airo_release(dev_link_t *link)
+{
+ DEBUG(0, "airo_release(0x%p)\n", link);
+
+ /* Unlink the device chain */
+ link->dev = NULL;
+
+ /*
+ In a normal driver, additional code may be needed to release
+ other kernel data structures associated with this device.
+ */
+
+ /* Don't bother checking to see if these succeed or not */
+ if (link->win)
+ pcmcia_release_window(link->win);
+ pcmcia_release_configuration(link->handle);
+ if (link->io.NumPorts1)
+ pcmcia_release_io(link->handle, &link->io);
+ if (link->irq.AssignedIRQ)
+ pcmcia_release_irq(link->handle, &link->irq);
+ link->state &= ~DEV_CONFIG;
+}
+
+/*======================================================================
+
+ The card status event handler. Mostly, this schedules other
+ stuff to run after an event is received.
+
+ When a CARD_REMOVAL event is received, we immediately set a
+ private flag to block future accesses to this device. All the
+ functions that actually access the device should check this flag
+ to make sure the card is still present.
+
+ ======================================================================*/
+
+static int airo_event(event_t event, int priority,
+ event_callback_args_t *args)
+{
+ dev_link_t *link = args->client_data;
+ local_info_t *local = link->priv;
+
+ DEBUG(1, "airo_event(0x%06x)\n", event);
+
+ switch (event) {
+ case CS_EVENT_CARD_REMOVAL:
+ link->state &= ~DEV_PRESENT;
+ if (link->state & DEV_CONFIG) {
+ netif_device_detach(local->eth_dev);
+ airo_release(link);
+ }
+ break;
+ case CS_EVENT_CARD_INSERTION:
+ link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
+ airo_config(link);
+ break;
+ case CS_EVENT_PM_SUSPEND:
+ link->state |= DEV_SUSPEND;
+ /* Fall through... */
+ case CS_EVENT_RESET_PHYSICAL:
+ if (link->state & DEV_CONFIG) {
+ netif_device_detach(local->eth_dev);
+ pcmcia_release_configuration(link->handle);
+ }
+ break;
+ case CS_EVENT_PM_RESUME:
+ link->state &= ~DEV_SUSPEND;
+ /* Fall through... */
+ case CS_EVENT_CARD_RESET:
+ if (link->state & DEV_CONFIG) {
+ pcmcia_request_configuration(link->handle, &link->conf);
+ reset_airo_card(local->eth_dev);
+ netif_device_attach(local->eth_dev);
+ }
+ break;
+ }
+ return 0;
+} /* airo_event */
+
+static struct pcmcia_driver airo_driver = {
+ .owner = THIS_MODULE,
+ .drv = {
+ .name = "airo_cs",
+ },
+ .attach = airo_attach,
+ .detach = airo_detach,
+};
+
+static int airo_cs_init(void)
+{
+ return pcmcia_register_driver(&airo_driver);
+}
+
+static void airo_cs_cleanup(void)
+{
+ pcmcia_unregister_driver(&airo_driver);
+ BUG_ON(dev_list != NULL);
+}
+
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ In addition:
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+module_init(airo_cs_init);
+module_exit(airo_cs_cleanup);
diff --git a/drivers/net/wireless/airport.c b/drivers/net/wireless/airport.c
new file mode 100644
index 000000000000..a1dc2a196087
--- /dev/null
+++ b/drivers/net/wireless/airport.c
@@ -0,0 +1,304 @@
+/* airport.c
+ *
+ * A driver for "Hermes" chipset based Apple Airport wireless
+ * card.
+ *
+ * Copyright notice & release notes in file orinoco.c
+ *
+ * Note specific to airport stub:
+ *
+ * 0.05 : first version of the new split driver
+ * 0.06 : fix possible hang on powerup, add sleep support
+ */
+
+#define DRIVER_NAME "airport"
+#define PFX DRIVER_NAME ": "
+
+#include <linux/config.h>
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/if_arp.h>
+#include <linux/etherdevice.h>
+#include <linux/wireless.h>
+
+#include <asm/io.h>
+#include <asm/system.h>
+#include <asm/current.h>
+#include <asm/prom.h>
+#include <asm/machdep.h>
+#include <asm/pmac_feature.h>
+#include <asm/irq.h>
+#include <asm/uaccess.h>
+
+#include "orinoco.h"
+
+#define AIRPORT_IO_LEN (0x1000) /* one page */
+
+struct airport {
+ struct macio_dev *mdev;
+ void __iomem *vaddr;
+ int irq_requested;
+ int ndev_registered;
+};
+
+static int
+airport_suspend(struct macio_dev *mdev, u32 state)
+{
+ struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
+ struct orinoco_private *priv = netdev_priv(dev);
+ unsigned long flags;
+ int err;
+
+ printk(KERN_DEBUG "%s: Airport entering sleep mode\n", dev->name);
+
+ err = orinoco_lock(priv, &flags);
+ if (err) {
+ printk(KERN_ERR "%s: hw_unavailable on PBOOK_SLEEP_NOW\n",
+ dev->name);
+ return 0;
+ }
+
+ err = __orinoco_down(dev);
+ if (err)
+ printk(KERN_WARNING "%s: PBOOK_SLEEP_NOW: Error %d downing interface\n",
+ dev->name, err);
+
+ netif_device_detach(dev);
+
+ priv->hw_unavailable++;
+
+ orinoco_unlock(priv, &flags);
+
+ disable_irq(dev->irq);
+ pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(mdev), 0, 0);
+
+ return 0;
+}
+
+static int
+airport_resume(struct macio_dev *mdev)
+{
+ struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
+ struct orinoco_private *priv = netdev_priv(dev);
+ unsigned long flags;
+ int err;
+
+ printk(KERN_DEBUG "%s: Airport waking up\n", dev->name);
+
+ pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(mdev), 0, 1);
+ msleep(200);
+
+ enable_irq(dev->irq);
+
+ err = orinoco_reinit_firmware(dev);
+ if (err) {
+ printk(KERN_ERR "%s: Error %d re-initializing firmware on PBOOK_WAKE\n",
+ dev->name, err);
+ return 0;
+ }
+
+ spin_lock_irqsave(&priv->lock, flags);
+
+ netif_device_attach(dev);
+
+ priv->hw_unavailable--;
+
+ if (priv->open && (! priv->hw_unavailable)) {
+ err = __orinoco_up(dev);
+ if (err)
+ printk(KERN_ERR "%s: Error %d restarting card on PBOOK_WAKE\n",
+ dev->name, err);
+ }
+
+
+ spin_unlock_irqrestore(&priv->lock, flags);
+
+ return 0;
+}
+
+static int
+airport_detach(struct macio_dev *mdev)
+{
+ struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
+ struct orinoco_private *priv = netdev_priv(dev);
+ struct airport *card = priv->card;
+
+ if (card->ndev_registered)
+ unregister_netdev(dev);
+ card->ndev_registered = 0;
+
+ if (card->irq_requested)
+ free_irq(dev->irq, dev);
+ card->irq_requested = 0;
+
+ if (card->vaddr)
+ iounmap(card->vaddr);
+ card->vaddr = NULL;
+
+ macio_release_resource(mdev, 0);
+
+ pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(mdev), 0, 0);
+ ssleep(1);
+
+ macio_set_drvdata(mdev, NULL);
+ free_orinocodev(dev);
+
+ return 0;
+}
+
+static int airport_hard_reset(struct orinoco_private *priv)
+{
+ /* It would be nice to power cycle the Airport for a real hard
+ * reset, but for some reason although it appears to
+ * re-initialize properly, it falls in a screaming heap
+ * shortly afterwards. */
+#if 0
+ struct net_device *dev = priv->ndev;
+ struct airport *card = priv->card;
+
+ /* Vitally important. If we don't do this it seems we get an
+ * interrupt somewhere during the power cycle, since
+ * hw_unavailable is already set it doesn't get ACKed, we get
+ * into an interrupt loop and the the PMU decides to turn us
+ * off. */
+ disable_irq(dev->irq);
+
+ pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(card->mdev), 0, 0);
+ ssleep(1);
+ pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(card->mdev), 0, 1);
+ ssleep(1);
+
+ enable_irq(dev->irq);
+ ssleep(1);
+#endif
+
+ return 0;
+}
+
+static int
+airport_attach(struct macio_dev *mdev, const struct of_match *match)
+{
+ struct orinoco_private *priv;
+ struct net_device *dev;
+ struct airport *card;
+ unsigned long phys_addr;
+ hermes_t *hw;
+
+ if (macio_resource_count(mdev) < 1 || macio_irq_count(mdev) < 1) {
+ printk(KERN_ERR PFX "Wrong interrupt/addresses in OF tree\n");
+ return -ENODEV;
+ }
+
+ /* Allocate space for private device-specific data */
+ dev = alloc_orinocodev(sizeof(*card), airport_hard_reset);
+ if (! dev) {
+ printk(KERN_ERR PFX "Cannot allocate network device\n");
+ return -ENODEV;
+ }
+ priv = netdev_priv(dev);
+ card = priv->card;
+
+ hw = &priv->hw;
+ card->mdev = mdev;
+
+ if (macio_request_resource(mdev, 0, "airport")) {
+ printk(KERN_ERR PFX "can't request IO resource !\n");
+ free_orinocodev(dev);
+ return -EBUSY;
+ }
+
+ SET_MODULE_OWNER(dev);
+ SET_NETDEV_DEV(dev, &mdev->ofdev.dev);
+
+ macio_set_drvdata(mdev, dev);
+
+ /* Setup interrupts & base address */
+ dev->irq = macio_irq(mdev, 0);
+ phys_addr = macio_resource_start(mdev, 0); /* Physical address */
+ printk(KERN_DEBUG PFX "Physical address %lx\n", phys_addr);
+ dev->base_addr = phys_addr;
+ card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN);
+ if (!card->vaddr) {
+ printk(KERN_ERR PFX "ioremap() failed\n");
+ goto failed;
+ }
+
+ hermes_struct_init(hw, card->vaddr, HERMES_16BIT_REGSPACING);
+
+ /* Power up card */
+ pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, macio_get_of_node(mdev), 0, 1);
+ ssleep(1);
+
+ /* Reset it before we get the interrupt */
+ hermes_init(hw);
+
+ if (request_irq(dev->irq, orinoco_interrupt, 0, dev->name, dev)) {
+ printk(KERN_ERR PFX "Couldn't get IRQ %d\n", dev->irq);
+ goto failed;
+ }
+ card->irq_requested = 1;
+
+ /* Tell the stack we exist */
+ if (register_netdev(dev) != 0) {
+ printk(KERN_ERR PFX "register_netdev() failed\n");
+ goto failed;
+ }
+ printk(KERN_DEBUG PFX "Card registered for interface %s\n", dev->name);
+ card->ndev_registered = 1;
+ return 0;
+ failed:
+ airport_detach(mdev);
+ return -ENODEV;
+} /* airport_attach */
+
+
+static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
+ " (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
+MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
+MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
+MODULE_LICENSE("Dual MPL/GPL");
+
+static struct of_match airport_match[] =
+{
+ {
+ .name = "radio",
+ .type = OF_ANY_MATCH,
+ .compatible = OF_ANY_MATCH
+ },
+ {},
+};
+
+static struct macio_driver airport_driver =
+{
+ .name = DRIVER_NAME,
+ .match_table = airport_match,
+ .probe = airport_attach,
+ .remove = airport_detach,
+ .suspend = airport_suspend,
+ .resume = airport_resume,
+};
+
+static int __init
+init_airport(void)
+{
+ printk(KERN_DEBUG "%s\n", version);
+
+ return macio_register_driver(&airport_driver);
+}
+
+static void __exit
+exit_airport(void)
+{
+ return macio_unregister_driver(&airport_driver);
+}
+
+module_init(init_airport);
+module_exit(exit_airport);
diff --git a/drivers/net/wireless/arlan-main.c b/drivers/net/wireless/arlan-main.c
new file mode 100644
index 000000000000..4f304c6e693a
--- /dev/null
+++ b/drivers/net/wireless/arlan-main.c
@@ -0,0 +1,1896 @@
+/*
+ * Copyright (C) 1997 Cullen Jennings
+ * Copyright (C) 1998 Elmer Joandiu, elmer@ylenurme.ee
+ * GNU General Public License applies
+ * This module provides support for the Arlan 655 card made by Aironet
+ */
+
+#include <linux/config.h>
+#include "arlan.h"
+
+#if BITS_PER_LONG != 32
+# error FIXME: this driver requires a 32-bit platform
+#endif
+
+static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
+
+struct net_device *arlan_device[MAX_ARLANS];
+
+static int SID = SIDUNKNOWN;
+static int radioNodeId = radioNodeIdUNKNOWN;
+static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
+int arlan_debug = debugUNKNOWN;
+static int spreadingCode = spreadingCodeUNKNOWN;
+static int channelNumber = channelNumberUNKNOWN;
+static int channelSet = channelSetUNKNOWN;
+static int systemId = systemIdUNKNOWN;
+static int registrationMode = registrationModeUNKNOWN;
+static int keyStart;
+static int tx_delay_ms;
+static int retries = 5;
+static int tx_queue_len = 1;
+static int arlan_EEPROM_bad;
+
+#ifdef ARLAN_DEBUGGING
+
+static int arlan_entry_debug;
+static int arlan_exit_debug;
+static int testMemory = testMemoryUNKNOWN;
+static int irq = irqUNKNOWN;
+static int txScrambled = 1;
+static int mdebug;
+
+module_param(irq, int, 0);
+module_param(mdebug, int, 0);
+module_param(testMemory, int, 0);
+module_param(arlan_entry_debug, int, 0);
+module_param(arlan_exit_debug, int, 0);
+module_param(txScrambled, int, 0);
+MODULE_PARM_DESC(irq, "(unused)");
+MODULE_PARM_DESC(testMemory, "(unused)");
+MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
+#endif
+
+module_param(arlan_debug, int, 0);
+module_param(spreadingCode, int, 0);
+module_param(channelNumber, int, 0);
+module_param(channelSet, int, 0);
+module_param(systemId, int, 0);
+module_param(registrationMode, int, 0);
+module_param(radioNodeId, int, 0);
+module_param(SID, int, 0);
+module_param(keyStart, int, 0);
+module_param(tx_delay_ms, int, 0);
+module_param(retries, int, 0);
+module_param(tx_queue_len, int, 0);
+module_param(arlan_EEPROM_bad, int, 0);
+MODULE_PARM_DESC(arlan_debug, "Arlan debug enable (0-1)");
+MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
+#ifdef ARLAN_ENTRY_EXIT_DEBUGGING
+MODULE_PARM_DESC(arlan_entry_debug, "Arlan driver function entry debugging");
+MODULE_PARM_DESC(arlan_exit_debug, "Arlan driver function exit debugging");
+MODULE_PARM_DESC(arlan_entry_and_exit_debug, "Arlan driver function entry and exit debugging");
+#else
+MODULE_PARM_DESC(arlan_entry_debug, "(ignored)");
+MODULE_PARM_DESC(arlan_exit_debug, "(ignored)");
+MODULE_PARM_DESC(arlan_entry_and_exit_debug, "(ignored)");
+#endif
+
+struct arlan_conf_stru arlan_conf[MAX_ARLANS];
+static int arlans_found;
+
+static int arlan_open(struct net_device *dev);
+static int arlan_tx(struct sk_buff *skb, struct net_device *dev);
+static irqreturn_t arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs);
+static int arlan_close(struct net_device *dev);
+static struct net_device_stats *
+ arlan_statistics (struct net_device *dev);
+static void arlan_set_multicast (struct net_device *dev);
+static int arlan_hw_tx (struct net_device* dev, char *buf, int length );
+static int arlan_hw_config (struct net_device * dev);
+static void arlan_tx_done_interrupt (struct net_device * dev, int status);
+static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short);
+static void arlan_process_interrupt (struct net_device * dev);
+static void arlan_tx_timeout (struct net_device *dev);
+
+static inline long us2ticks(int us)
+{
+ return us * (1000000 / HZ);
+}
+
+
+#ifdef ARLAN_ENTRY_EXIT_DEBUGGING
+#define ARLAN_DEBUG_ENTRY(name) \
+ {\
+ struct timeval timev;\
+ do_gettimeofday(&timev);\
+ if (arlan_entry_debug || arlan_entry_and_exit_debug)\
+ printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\
+ }
+#define ARLAN_DEBUG_EXIT(name) \
+ {\
+ struct timeval timev;\
+ do_gettimeofday(&timev);\
+ if (arlan_exit_debug || arlan_entry_and_exit_debug)\
+ printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\
+ }
+#else
+#define ARLAN_DEBUG_ENTRY(name)
+#define ARLAN_DEBUG_EXIT(name)
+#endif
+
+
+#define arlan_interrupt_ack(dev)\
+ clearClearInterrupt(dev);\
+ setClearInterrupt(dev);
+
+static inline int arlan_drop_tx(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+ priv->stats.tx_errors++;
+ if (priv->Conf->tx_delay_ms)
+ {
+ priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
+ }
+ else
+ {
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
+ TXHEAD(dev).offset = 0;
+ TXTAIL(dev).offset = 0;
+ priv->txLast = 0;
+ priv->bad = 0;
+ if (!priv->under_reset && !priv->under_config)
+ netif_wake_queue (dev);
+ }
+ return 1;
+}
+
+
+int arlan_command(struct net_device *dev, int command_p)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ struct arlan_conf_stru *conf = priv->Conf;
+ int udelayed = 0;
+ int i = 0;
+ unsigned long flags;
+
+ ARLAN_DEBUG_ENTRY("arlan_command");
+
+ if (priv->card_polling_interval)
+ priv->card_polling_interval = 1;
+
+ if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
+ printk(KERN_DEBUG "arlan_command, %lx commandByte %x waiting %lx incoming %x \n",
+ jiffies, READSHMB(arlan->commandByte),
+ priv->waiting_command_mask, command_p);
+
+ priv->waiting_command_mask |= command_p;
+
+ if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
+ if (time_after(jiffies, priv->lastReset + 5 * HZ))
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
+
+ if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
+ {
+ arlan_interrupt_ack(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
+ }
+ if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
+ {
+ setInterruptEnable(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
+ }
+
+ /* Card access serializing lock */
+ spin_lock_irqsave(&priv->lock, flags);
+
+ /* Check cards status and waiting */
+
+ if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
+ {
+ while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
+ {
+ if (READSHMB(arlan->resetFlag) ||
+ READSHMB(arlan->commandByte)) /* ||
+ (readControlRegister(dev) & ARLAN_ACCESS))
+ */
+ udelay(40);
+ else
+ priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
+
+ udelayed++;
+
+ if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
+ {
+ if (udelayed * 40 > 1000000)
+ {
+ printk(KERN_ERR "%s long wait too long \n", dev->name);
+ priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
+ break;
+ }
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
+ {
+ if (udelayed * 40 > 1000)
+ {
+ printk(KERN_ERR "%s short wait too long \n", dev->name);
+ goto bad_end;
+ }
+ }
+ }
+ }
+ else
+ {
+ i = 0;
+ while ((READSHMB(arlan->resetFlag) ||
+ READSHMB(arlan->commandByte)) &&
+ conf->pre_Command_Wait > (i++) * 10)
+ udelay(10);
+
+
+ if ((READSHMB(arlan->resetFlag) ||
+ READSHMB(arlan->commandByte)) &&
+ !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
+ {
+ goto card_busy_end;
+ }
+ }
+ if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
+ priv->under_reset = 1;
+ if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
+ priv->under_config = 1;
+
+ /* Issuing command */
+ arlan_lock_card_access(dev);
+ if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
+ {
+ // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
+ setPowerOn(dev);
+ arlan_interrupt_lancpu(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
+ priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
+ priv->card_polling_interval = HZ / 10;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
+ {
+ WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE);
+ arlan_interrupt_lancpu(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE;
+ priv->card_polling_interval = HZ / 10;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
+ {
+ if (priv->rx_command_given)
+ {
+ WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
+ arlan_interrupt_lancpu(dev);
+ priv->rx_command_given = 0;
+ }
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
+ priv->card_polling_interval = 1;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
+ {
+ if (priv->tx_command_given)
+ {
+ WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
+ arlan_interrupt_lancpu(dev);
+ priv->tx_command_given = 0;
+ }
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
+ priv->card_polling_interval = 1;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
+ {
+ priv->under_reset=1;
+ netif_stop_queue (dev);
+
+ arlan_drop_tx(dev);
+ if (priv->tx_command_given || priv->rx_command_given)
+ {
+ printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
+ }
+ netif_stop_queue (dev);
+ if (arlan_debug & ARLAN_DEBUG_RESET)
+ printk(KERN_ERR "%s: Doing chip reset\n", dev->name);
+ priv->lastReset = jiffies;
+ WRITESHM(arlan->commandByte, 0, u_char);
+ /* hold card in reset state */
+ setHardwareReset(dev);
+ /* set reset flag and then release reset */
+ WRITESHM(arlan->resetFlag, 0xff, u_char);
+ clearChannelAttention(dev);
+ clearHardwareReset(dev);
+ priv->card_polling_interval = HZ / 4;
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
+ priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
+// priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
+// priv->waiting_command_mask |= ARLAN_COMMAND_RX;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
+ {
+ clearHardwareReset(dev);
+ clearClearInterrupt(dev);
+ setClearInterrupt(dev);
+ setInterruptEnable(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK;
+ priv->waiting_command_mask |= ARLAN_COMMAND_CONF;
+ priv->under_config = 1;
+ priv->under_reset = 0;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
+ {
+ setInterruptEnable(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
+ {
+ if (priv->tx_command_given || priv->rx_command_given)
+ {
+ printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
+ }
+ arlan_drop_tx(dev);
+ setInterruptEnable(dev);
+ arlan_hw_config(dev);
+ arlan_interrupt_lancpu(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
+ priv->card_polling_interval = HZ / 10;
+// priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
+// priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
+ priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
+ {
+ if (READSHMB(arlan->configuredStatusFlag) != 0 &&
+ READSHMB(arlan->diagnosticInfo) == 0xff)
+ {
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT;
+ priv->waiting_command_mask |= ARLAN_COMMAND_RX;
+ priv->waiting_command_mask |= ARLAN_COMMAND_TBUSY_CLEAR;
+ priv->card_polling_interval = HZ / 10;
+ priv->tx_command_given = 0;
+ priv->under_config = 0;
+ }
+ else
+ {
+ priv->card_polling_interval = 1;
+ if (arlan_debug & ARLAN_DEBUG_TIMING)
+ printk(KERN_ERR "configure delayed \n");
+ }
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
+ {
+ if (!registrationBad(dev))
+ {
+ setInterruptEnable(dev);
+ memset_io(arlan->commandParameter, 0, 0xf);
+ WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE);
+ WRITESHMB(arlan->commandParameter[0], conf->rxParameter);
+ arlan_interrupt_lancpu(dev);
+ priv->rx_command_given = 0; // mnjah, bad
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_RX;
+ priv->card_polling_interval = 1;
+ }
+ else
+ priv->card_polling_interval = 2;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR)
+ {
+ if ( !registrationBad(dev) &&
+ (netif_queue_stopped(dev) || !netif_running(dev)) )
+ {
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR;
+ netif_wake_queue (dev);
+ }
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
+ {
+ if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
+ {
+ if (time_after(jiffies,
+ priv->tx_last_sent + us2ticks(conf->rx_tweak1))
+ || time_before(jiffies,
+ priv->last_rx_int_ack_time + us2ticks(conf->rx_tweak2)))
+ {
+ setInterruptEnable(dev);
+ memset_io(arlan->commandParameter, 0, 0xf);
+ WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT);
+ memcpy_toio(arlan->commandParameter, &TXLAST(dev), 14);
+// for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
+ priv->tx_last_sent = jiffies;
+ arlan_interrupt_lancpu(dev);
+ priv->tx_command_given = 1;
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
+ priv->card_polling_interval = 1;
+ }
+ else
+ {
+ priv->tx_command_given = 0;
+ priv->card_polling_interval = 1;
+ }
+ }
+ else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
+ printk(KERN_ERR "tx command when tx chain locked \n");
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
+ {
+ {
+ WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
+ }
+ arlan_interrupt_lancpu(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
+ priv->card_polling_interval = HZ / 3;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
+ {
+ WRITESHMB(arlan->commandByte, ARLAN_COM_NOP);
+ arlan_interrupt_lancpu(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP;
+ priv->card_polling_interval = HZ / 3;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
+ {
+ WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL);
+ arlan_interrupt_lancpu(dev);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL;
+ priv->card_polling_interval = HZ / 3;
+ }
+ else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
+ {
+ setPowerOff(dev);
+ if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
+ printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name);
+ priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
+ priv->card_polling_interval = 3 * HZ;
+ }
+ arlan_unlock_card_access(dev);
+ for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
+ udelay(10);
+ if (READSHMB(arlan->commandByte))
+ if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
+ printk(KERN_ERR "card busy leaving command %lx\n", priv->waiting_command_mask);
+
+ spin_unlock_irqrestore(&priv->lock, flags);
+ ARLAN_DEBUG_EXIT("arlan_command");
+ priv->last_command_buff_free_time = jiffies;
+ return 0;
+
+card_busy_end:
+ if (time_after(jiffies, priv->last_command_buff_free_time + HZ))
+ priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
+
+ if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
+ printk(KERN_ERR "%s arlan_command card busy end \n", dev->name);
+ spin_unlock_irqrestore(&priv->lock, flags);
+ ARLAN_DEBUG_EXIT("arlan_command");
+ return 1;
+
+bad_end:
+ printk(KERN_ERR "%s arlan_command bad end \n", dev->name);
+
+ spin_unlock_irqrestore(&priv->lock, flags);
+ ARLAN_DEBUG_EXIT("arlan_command");
+
+ return -1;
+}
+
+static inline void arlan_command_process(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+ int times = 0;
+ while (priv->waiting_command_mask && times < 8)
+ {
+ if (priv->waiting_command_mask)
+ {
+ if (arlan_command(dev, 0))
+ break;
+ times++;
+ }
+ /* if long command, we won't repeat trying */ ;
+ if (priv->card_polling_interval > 1)
+ break;
+ times++;
+ }
+}
+
+
+static inline void arlan_retransmit_now(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+
+ ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
+ if (TXLAST(dev).offset == 0)
+ {
+ if (TXHEAD(dev).offset)
+ {
+ priv->txLast = 0;
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n");
+
+ }
+ else if (TXTAIL(dev).offset)
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n");
+ priv->txLast = 1;
+ }
+ else
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
+ netif_wake_queue (dev);
+ return;
+
+ }
+ arlan_command(dev, ARLAN_COMMAND_TX);
+
+ priv->Conf->driverRetransmissions++;
+ priv->retransmissions++;
+
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length);
+
+ ARLAN_DEBUG_EXIT("arlan_retransmit_now");
+}
+
+
+
+static void arlan_registration_timer(unsigned long data)
+{
+ struct net_device *dev = (struct net_device *) data;
+ struct arlan_private *priv = netdev_priv(dev);
+ int bh_mark_needed = 0;
+ int next_tick = 1;
+ long lostTime = ((long)jiffies - (long)priv->registrationLastSeen)
+ * (1000/HZ);
+
+ if (registrationBad(dev))
+ {
+ priv->registrationLostCount++;
+ if (lostTime > 7000 && lostTime < 7200)
+ {
+ printk(KERN_NOTICE "%s registration Lost \n", dev->name);
+ }
+ if (lostTime / priv->reRegisterExp > 2000)
+ arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
+ if (lostTime / (priv->reRegisterExp) > 3500)
+ arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
+ if (priv->reRegisterExp < 400)
+ priv->reRegisterExp += 2;
+ if (lostTime > 7200)
+ {
+ next_tick = HZ;
+ arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
+ }
+ }
+ else
+ {
+ if (priv->Conf->registrationMode && lostTime > 10000 &&
+ priv->registrationLostCount)
+ {
+ printk(KERN_NOTICE "%s registration is back after %ld milliseconds\n",
+ dev->name, lostTime);
+ }
+ priv->registrationLastSeen = jiffies;
+ priv->registrationLostCount = 0;
+ priv->reRegisterExp = 1;
+ if (!netif_running(dev) )
+ netif_wake_queue(dev);
+ if (time_after(priv->tx_last_sent,priv->tx_last_cleared) &&
+ time_after(jiffies, priv->tx_last_sent * 5*HZ) ){
+ arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
+ priv->tx_last_cleared = jiffies;
+ }
+ }
+
+
+ if (!registrationBad(dev) && priv->ReTransmitRequested)
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk(KERN_ERR "Retransmit from timer \n");
+ priv->ReTransmitRequested = 0;
+ arlan_retransmit_now(dev);
+ }
+ if (!registrationBad(dev) &&
+ time_after(jiffies, priv->tx_done_delayed) &&
+ priv->tx_done_delayed != 0)
+ {
+ TXLAST(dev).offset = 0;
+ if (priv->txLast)
+ priv->txLast = 0;
+ else if (TXTAIL(dev).offset)
+ priv->txLast = 1;
+ if (TXLAST(dev).offset)
+ {
+ arlan_retransmit_now(dev);
+ dev->trans_start = jiffies;
+ }
+ if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
+ {
+ netif_wake_queue (dev);
+ }
+ priv->tx_done_delayed = 0;
+ bh_mark_needed = 1;
+ }
+ if (bh_mark_needed)
+ {
+ netif_wake_queue (dev);
+ }
+ arlan_process_interrupt(dev);
+
+ if (next_tick < priv->card_polling_interval)
+ next_tick = priv->card_polling_interval;
+
+ priv->timer.expires = jiffies + next_tick;
+
+ add_timer(&priv->timer);
+}
+
+
+#ifdef ARLAN_DEBUGGING
+
+static void arlan_print_registers(struct net_device *dev, int line)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem *arlan = priv->card;
+
+ u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
+ txStatus, rxStatus, interruptInProgress, commandByte;
+
+
+ ARLAN_DEBUG_ENTRY("arlan_print_registers");
+ READSHM(interruptInProgress, arlan->interruptInProgress, u_char);
+ READSHM(hostcpuLock, arlan->hostcpuLock, u_char);
+ READSHM(lancpuLock, arlan->lancpuLock, u_char);
+ READSHM(controlRegister, arlan->controlRegister, u_char);
+ READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char);
+ READSHM(txStatus, arlan->txStatus, u_char);
+ READSHM(rxStatus, arlan->rxStatus, u_char);
+ READSHM(commandByte, arlan->commandByte, u_char);
+
+ printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n",
+ line, interruptInProgress, hostcpuLock, lancpuLock, commandByte,
+ controlRegister, cntrlRegImage, txStatus, rxStatus);
+
+ ARLAN_DEBUG_EXIT("arlan_print_registers");
+}
+#endif
+
+
+static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
+{
+ int i;
+
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ struct arlan_conf_stru *conf = priv->Conf;
+
+ int tailStarts = 0x800;
+ int headEnds = 0x0;
+
+
+ ARLAN_DEBUG_ENTRY("arlan_hw_tx");
+ if (TXHEAD(dev).offset)
+ headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - offsetof(struct arlan_shmem, txBuffer)) / 64) + 1) * 64;
+ if (TXTAIL(dev).offset)
+ tailStarts = 0x800 - (((TXTAIL(dev).offset - offsetof(struct arlan_shmem, txBuffer)) / 64) + 2) * 64;
+
+
+ if (!TXHEAD(dev).offset && length < tailStarts)
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts);
+
+ TXHEAD(dev).offset =
+ offsetof(struct arlan_shmem, txBuffer);
+ TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
+ for (i = 0; i < 6; i++)
+ TXHEAD(dev).dest[i] = buf[i];
+ TXHEAD(dev).clear = conf->txClear;
+ TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
+ TXHEAD(dev).routing = conf->txRouting;
+ TXHEAD(dev).scrambled = conf->txScrambled;
+ memcpy_toio((char __iomem *)arlan + TXHEAD(dev).offset, buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
+ }
+ else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds);
+
+ TXTAIL(dev).offset =
+ offsetof(struct arlan_shmem, txBuffer) + 0x800 - (length / 64 + 2) * 64;
+ TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
+ for (i = 0; i < 6; i++)
+ TXTAIL(dev).dest[i] = buf[i];
+ TXTAIL(dev).clear = conf->txClear;
+ TXTAIL(dev).retries = conf->txRetries;
+ TXTAIL(dev).routing = conf->txRouting;
+ TXTAIL(dev).scrambled = conf->txScrambled;
+ memcpy_toio(((char __iomem *)arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
+ }
+ else
+ {
+ netif_stop_queue (dev);
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds);
+ return -1;
+ }
+ priv->out_bytes += length;
+ priv->out_bytes10 += length;
+ if (conf->measure_rate < 1)
+ conf->measure_rate = 1;
+ if (time_after(jiffies, priv->out_time + conf->measure_rate * HZ))
+ {
+ conf->out_speed = priv->out_bytes / conf->measure_rate;
+ priv->out_bytes = 0;
+ priv->out_time = jiffies;
+ }
+ if (time_after(jiffies, priv->out_time10 + conf->measure_rate * 10*HZ))
+ {
+ conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
+ priv->out_bytes10 = 0;
+ priv->out_time10 = jiffies;
+ }
+ if (TXHEAD(dev).offset && TXTAIL(dev).offset)
+ {
+ netif_stop_queue (dev);
+ return 0;
+ }
+ else
+ netif_start_queue (dev);
+
+
+ IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
+ printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
+ (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3],
+ (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7],
+ (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]);
+
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast);
+
+ arlan_command(dev, ARLAN_COMMAND_TX);
+
+ priv->tx_last_sent = jiffies;
+
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length);
+
+ ARLAN_DEBUG_EXIT("arlan_hw_tx");
+
+ return 0;
+}
+
+
+static int arlan_hw_config(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ struct arlan_conf_stru *conf = priv->Conf;
+
+ ARLAN_DEBUG_ENTRY("arlan_hw_config");
+
+ printk(KERN_NOTICE "%s arlan configure called \n", dev->name);
+ if (arlan_EEPROM_bad)
+ printk(KERN_NOTICE "arlan configure with eeprom bad option \n");
+
+
+ WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
+ WRITESHM(arlan->channelSet, conf->channelSet, u_char);
+
+ if (arlan_EEPROM_bad)
+ WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
+
+ WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
+
+ WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
+ WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
+
+ WRITESHM(arlan->systemId, conf->systemId, u_int);
+
+ WRITESHM(arlan->maxRetries, conf->maxRetries, u_char);
+ WRITESHM(arlan->receiveMode, conf->receiveMode, u_char);
+ WRITESHM(arlan->priority, conf->priority, u_char);
+ WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char);
+ WRITESHM(arlan->SID, conf->SID, u_int);
+
+ WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
+
+ WRITESHM(arlan->registrationFill, conf->registrationFill, u_char);
+ WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char);
+ WRITESHM(arlan->codeFormat, conf->codeFormat, u_char);
+ WRITESHM(arlan->numChannels, conf->numChannels, u_char);
+ WRITESHM(arlan->channel1, conf->channel1, u_char);
+ WRITESHM(arlan->channel2, conf->channel2, u_char);
+ WRITESHM(arlan->channel3, conf->channel3, u_char);
+ WRITESHM(arlan->channel4, conf->channel4, u_char);
+ WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short);
+ WRITESHM(arlan->SID, conf->SID, u_int);
+ WRITESHM(arlan->waitTime, conf->waitTime, u_short);
+ WRITESHM(arlan->lParameter, conf->lParameter, u_short);
+ memcpy_toio(&(arlan->_15), &(conf->_15), 3);
+ WRITESHM(arlan->_15, conf->_15, u_short);
+ WRITESHM(arlan->headerSize, conf->headerSize, u_short);
+ if (arlan_EEPROM_bad)
+ WRITESHM(arlan->hardwareType, conf->hardwareType, u_char);
+ WRITESHM(arlan->radioType, conf->radioType, u_char);
+ if (arlan_EEPROM_bad)
+ WRITESHM(arlan->radioModule, conf->radioType, u_char);
+
+ memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
+ memcpy_toio(arlan->name, conf->siteName, 16);
+
+ WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */
+ memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */
+ memset_io(arlan->commandParameter + 1, 0, 2);
+ if (conf->writeEEPROM)
+ {
+ memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
+// conf->writeEEPROM=0;
+ }
+ if (conf->registrationMode && conf->registrationInterrupts)
+ memset_io(arlan->commandParameter + 3, 1, 1);
+ else
+ memset_io(arlan->commandParameter + 3, 0, 1);
+
+ priv->irq_test_done = 0;
+
+ if (conf->tx_queue_len)
+ dev->tx_queue_len = conf->tx_queue_len;
+ udelay(100);
+
+ ARLAN_DEBUG_EXIT("arlan_hw_config");
+ return 0;
+}
+
+
+static int arlan_read_card_configuration(struct net_device *dev)
+{
+ u_char tlx415;
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ struct arlan_conf_stru *conf = priv->Conf;
+
+ ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
+
+ if (radioNodeId == radioNodeIdUNKNOWN)
+ {
+ READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
+ }
+ else
+ conf->radioNodeId = radioNodeId;
+
+ if (SID == SIDUNKNOWN)
+ {
+ READSHM(conf->SID, arlan->SID, u_int);
+ }
+ else conf->SID = SID;
+
+ if (spreadingCode == spreadingCodeUNKNOWN)
+ {
+ READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
+ }
+ else
+ conf->spreadingCode = spreadingCode;
+
+ if (channelSet == channelSetUNKNOWN)
+ {
+ READSHM(conf->channelSet, arlan->channelSet, u_char);
+ }
+ else conf->channelSet = channelSet;
+
+ if (channelNumber == channelNumberUNKNOWN)
+ {
+ READSHM(conf->channelNumber, arlan->channelNumber, u_char);
+ }
+ else conf->channelNumber = channelNumber;
+
+ READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
+ READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
+
+ if (systemId == systemIdUNKNOWN)
+ {
+ READSHM(conf->systemId, arlan->systemId, u_int);
+ }
+ else conf->systemId = systemId;
+
+ READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short);
+ READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short);
+ READSHM(conf->maxRetries, arlan->maxRetries, u_char);
+ READSHM(conf->receiveMode, arlan->receiveMode, u_char);
+ READSHM(conf->priority, arlan->priority, u_char);
+ READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char);
+
+ if (SID == SIDUNKNOWN)
+ {
+ READSHM(conf->SID, arlan->SID, u_int);
+ }
+ else conf->SID = SID;
+
+ if (registrationMode == registrationModeUNKNOWN)
+ {
+ READSHM(conf->registrationMode, arlan->registrationMode, u_char);
+ }
+ else conf->registrationMode = registrationMode;
+
+ READSHM(conf->registrationFill, arlan->registrationFill, u_char);
+ READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char);
+ READSHM(conf->codeFormat, arlan->codeFormat, u_char);
+ READSHM(conf->numChannels, arlan->numChannels, u_char);
+ READSHM(conf->channel1, arlan->channel1, u_char);
+ READSHM(conf->channel2, arlan->channel2, u_char);
+ READSHM(conf->channel3, arlan->channel3, u_char);
+ READSHM(conf->channel4, arlan->channel4, u_char);
+ READSHM(conf->waitTime, arlan->waitTime, u_short);
+ READSHM(conf->lParameter, arlan->lParameter, u_short);
+ READSHM(conf->_15, arlan->_15, u_short);
+ READSHM(conf->headerSize, arlan->headerSize, u_short);
+ READSHM(conf->hardwareType, arlan->hardwareType, u_char);
+ READSHM(conf->radioType, arlan->radioModule, u_char);
+
+ if (conf->radioType == 0)
+ conf->radioType = 0xc;
+
+ WRITESHM(arlan->configStatus, 0xA5, u_char);
+ READSHM(tlx415, arlan->configStatus, u_char);
+
+ if (tlx415 != 0xA5)
+ printk(KERN_INFO "%s tlx415 chip \n", dev->name);
+
+ conf->txClear = 0;
+ conf->txRetries = 1;
+ conf->txRouting = 1;
+ conf->txScrambled = 0;
+ conf->rxParameter = 1;
+ conf->txTimeoutMs = 4000;
+ conf->waitCardTimeout = 100000;
+ conf->receiveMode = ARLAN_RCV_CLEAN;
+ memcpy_fromio(conf->siteName, arlan->name, 16);
+ conf->siteName[16] = '\0';
+ conf->retries = retries;
+ conf->tx_delay_ms = tx_delay_ms;
+ conf->ReTransmitPacketMaxSize = 200;
+ conf->waitReTransmitPacketMaxSize = 200;
+ conf->txAckTimeoutMs = 900;
+ conf->fastReTransCount = 3;
+
+ ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
+
+ return 0;
+}
+
+
+static int lastFoundAt = 0xbe000;
+
+
+/*
+ * This is the real probe routine. Linux has a history of friendly device
+ * probes on the ISA bus. A good device probes avoids doing writes, and
+ * verifies that the correct device exists and functions.
+ */
+#define ARLAN_SHMEM_SIZE 0x2000
+static int __init arlan_check_fingerprint(unsigned long memaddr)
+{
+ static const char probeText[] = "TELESYSTEM SLW INC. ARLAN \0";
+ volatile struct arlan_shmem __iomem *arlan = (struct arlan_shmem *) memaddr;
+ unsigned long paddr = virt_to_phys((void *) memaddr);
+ char tempBuf[49];
+
+ ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
+
+ if (!request_mem_region(paddr, ARLAN_SHMEM_SIZE, "arlan")) {
+ // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",paddr);
+ return -ENODEV;
+ }
+
+ memcpy_fromio(tempBuf, arlan->textRegion, 29);
+ tempBuf[30] = 0;
+
+ /* check for card at this address */
+ if (0 != strncmp(tempBuf, probeText, 29)){
+ release_mem_region(paddr, ARLAN_SHMEM_SIZE);
+ return -ENODEV;
+ }
+
+// printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
+ ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
+
+ return 0;
+}
+
+static int arlan_change_mtu(struct net_device *dev, int new_mtu)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+ struct arlan_conf_stru *conf = priv->Conf;
+
+ ARLAN_DEBUG_ENTRY("arlan_change_mtu");
+ if (new_mtu > 2032)
+ return -EINVAL;
+ dev->mtu = new_mtu;
+ if (new_mtu < 256)
+ new_mtu = 256; /* cards book suggests 1600 */
+ conf->maxDatagramSize = new_mtu;
+ conf->maxFrameSize = new_mtu + 48;
+
+ arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
+ printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu);
+
+ ARLAN_DEBUG_EXIT("arlan_change_mtu");
+
+ return 0;
+}
+
+static int arlan_mac_addr(struct net_device *dev, void *p)
+{
+ struct sockaddr *addr = p;
+
+
+ ARLAN_DEBUG_ENTRY("arlan_mac_addr");
+ return -EINVAL;
+
+ if (!netif_running(dev))
+ return -EBUSY;
+ memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+
+ ARLAN_DEBUG_EXIT("arlan_mac_addr");
+ return 0;
+}
+
+
+
+static int __init arlan_setup_device(struct net_device *dev, int num)
+{
+ struct arlan_private *ap = netdev_priv(dev);
+ int err;
+
+ ARLAN_DEBUG_ENTRY("arlan_setup_device");
+
+ ap->conf = (struct arlan_shmem *)(ap+1);
+
+ dev->tx_queue_len = tx_queue_len;
+ dev->open = arlan_open;
+ dev->stop = arlan_close;
+ dev->hard_start_xmit = arlan_tx;
+ dev->get_stats = arlan_statistics;
+ dev->set_multicast_list = arlan_set_multicast;
+ dev->change_mtu = arlan_change_mtu;
+ dev->set_mac_address = arlan_mac_addr;
+ dev->tx_timeout = arlan_tx_timeout;
+ dev->watchdog_timeo = 3*HZ;
+
+ ap->irq_test_done = 0;
+ ap->Conf = &arlan_conf[num];
+
+ ap->Conf->pre_Command_Wait = 40;
+ ap->Conf->rx_tweak1 = 30;
+ ap->Conf->rx_tweak2 = 0;
+
+
+ err = register_netdev(dev);
+ if (err) {
+ release_mem_region(virt_to_phys((void *) dev->mem_start),
+ ARLAN_SHMEM_SIZE);
+ free_netdev(dev);
+ return err;
+ }
+ arlan_device[num] = dev;
+ ARLAN_DEBUG_EXIT("arlan_setup_device");
+ return 0;
+}
+
+static int __init arlan_probe_here(struct net_device *dev,
+ unsigned long memaddr)
+{
+ struct arlan_private *ap = netdev_priv(dev);
+
+ ARLAN_DEBUG_ENTRY("arlan_probe_here");
+
+ if (arlan_check_fingerprint(memaddr))
+ return -ENODEV;
+
+ printk(KERN_NOTICE "%s: Arlan found at %x, \n ", dev->name,
+ (int) virt_to_phys((void*)memaddr));
+
+ ap->card = (void *) memaddr;
+ dev->mem_start = memaddr;
+ dev->mem_end = memaddr + ARLAN_SHMEM_SIZE-1;
+
+ if (dev->irq < 2)
+ {
+ READSHM(dev->irq, ap->card->irqLevel, u_char);
+ } else if (dev->irq == 2)
+ dev->irq = 9;
+
+ arlan_read_card_configuration(dev);
+
+ ARLAN_DEBUG_EXIT("arlan_probe_here");
+ return 0;
+}
+
+
+static int arlan_open(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ int ret = 0;
+
+ ARLAN_DEBUG_ENTRY("arlan_open");
+
+ ret = request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev);
+ if (ret)
+ {
+ printk(KERN_ERR "%s: unable to get IRQ %d .\n",
+ dev->name, dev->irq);
+ return ret;
+ }
+
+
+ priv->bad = 0;
+ priv->lastReset = 0;
+ priv->reset = 0;
+ memcpy_fromio(dev->dev_addr, arlan->lanCardNodeId, 6);
+ memset(dev->broadcast, 0xff, 6);
+ dev->tx_queue_len = tx_queue_len;
+ priv->interrupt_processing_active = 0;
+ spin_lock_init(&priv->lock);
+
+ netif_start_queue (dev);
+
+ priv->registrationLostCount = 0;
+ priv->registrationLastSeen = jiffies;
+ priv->txLast = 0;
+ priv->tx_command_given = 0;
+ priv->rx_command_given = 0;
+
+ priv->reRegisterExp = 1;
+ priv->tx_last_sent = jiffies - 1;
+ priv->tx_last_cleared = jiffies;
+ priv->Conf->writeEEPROM = 0;
+ priv->Conf->registrationInterrupts = 1;
+
+ init_timer(&priv->timer);
+ priv->timer.expires = jiffies + HZ / 10;
+ priv->timer.data = (unsigned long) dev;
+ priv->timer.function = &arlan_registration_timer; /* timer handler */
+
+ arlan_command(dev, ARLAN_COMMAND_POWERUP | ARLAN_COMMAND_LONG_WAIT_NOW);
+ mdelay(200);
+ add_timer(&priv->timer);
+
+ ARLAN_DEBUG_EXIT("arlan_open");
+ return 0;
+}
+
+
+static void arlan_tx_timeout (struct net_device *dev)
+{
+ printk(KERN_ERR "%s: arlan transmit timed out, kernel decided\n", dev->name);
+ /* Try to restart the adaptor. */
+ arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
+ // dev->trans_start = jiffies;
+ // netif_start_queue (dev);
+}
+
+
+static int arlan_tx(struct sk_buff *skb, struct net_device *dev)
+{
+ short length;
+ unsigned char *buf;
+
+ ARLAN_DEBUG_ENTRY("arlan_tx");
+
+ length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
+ buf = skb->data;
+
+ if (length + 0x12 > 0x800) {
+ printk(KERN_ERR "TX RING overflow \n");
+ netif_stop_queue (dev);
+ }
+
+ if (arlan_hw_tx(dev, buf, length) == -1)
+ goto bad_end;
+
+ dev->trans_start = jiffies;
+
+ dev_kfree_skb(skb);
+
+ arlan_process_interrupt(dev);
+ ARLAN_DEBUG_EXIT("arlan_tx");
+ return 0;
+
+bad_end:
+ arlan_process_interrupt(dev);
+ netif_stop_queue (dev);
+ ARLAN_DEBUG_EXIT("arlan_tx");
+ return 1;
+}
+
+
+static inline int DoNotReTransmitCrap(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+ if (TXLAST(dev).length < priv->Conf->ReTransmitPacketMaxSize)
+ return 1;
+ return 0;
+
+}
+
+static inline int DoNotWaitReTransmitCrap(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+ if (TXLAST(dev).length < priv->Conf->waitReTransmitPacketMaxSize)
+ return 1;
+ return 0;
+}
+
+static inline void arlan_queue_retransmit(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+ ARLAN_DEBUG_ENTRY("arlan_queue_retransmit");
+
+ if (DoNotWaitReTransmitCrap(dev))
+ {
+ arlan_drop_tx(dev);
+ } else
+ priv->ReTransmitRequested++;
+
+ ARLAN_DEBUG_EXIT("arlan_queue_retransmit");
+}
+
+static inline void RetryOrFail(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+ ARLAN_DEBUG_ENTRY("RetryOrFail");
+
+ if (priv->retransmissions > priv->Conf->retries ||
+ DoNotReTransmitCrap(dev))
+ {
+ arlan_drop_tx(dev);
+ }
+ else if (priv->bad <= priv->Conf->fastReTransCount)
+ {
+ arlan_retransmit_now(dev);
+ }
+ else arlan_queue_retransmit(dev);
+
+ ARLAN_DEBUG_EXIT("RetryOrFail");
+}
+
+
+static void arlan_tx_done_interrupt(struct net_device *dev, int status)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+ ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt");
+
+ priv->tx_last_cleared = jiffies;
+ priv->tx_command_given = 0;
+ switch (status)
+ {
+ case 1:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit OK\n");
+ priv->stats.tx_packets++;
+ priv->bad = 0;
+ priv->reset = 0;
+ priv->retransmissions = 0;
+ if (priv->Conf->tx_delay_ms)
+ {
+ priv->tx_done_delayed = jiffies + (priv->Conf->tx_delay_ms * HZ) / 1000 + 1;
+ }
+ else
+ {
+ TXLAST(dev).offset = 0;
+ if (priv->txLast)
+ priv->txLast = 0;
+ else if (TXTAIL(dev).offset)
+ priv->txLast = 1;
+ if (TXLAST(dev).offset)
+ {
+ arlan_retransmit_now(dev);
+ dev->trans_start = jiffies;
+ }
+ if (!TXHEAD(dev).offset || !TXTAIL(dev).offset)
+ {
+ netif_wake_queue (dev);
+ }
+ }
+ }
+ break;
+
+ case 2:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit timed out\n");
+ priv->bad += 1;
+ //arlan_queue_retransmit(dev);
+ RetryOrFail(dev);
+ }
+ break;
+
+ case 3:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit max retries\n");
+ priv->bad += 1;
+ priv->reset = 0;
+ //arlan_queue_retransmit(dev);
+ RetryOrFail(dev);
+ }
+ break;
+
+ case 4:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit aborted\n");
+ priv->bad += 1;
+ arlan_queue_retransmit(dev);
+ //RetryOrFail(dev);
+ }
+ break;
+
+ case 5:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit not registered\n");
+ priv->bad += 1;
+ //debug=101;
+ arlan_queue_retransmit(dev);
+ }
+ break;
+
+ case 6:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit destination full\n");
+ priv->bad += 1;
+ priv->reset = 0;
+ //arlan_drop_tx(dev);
+ arlan_queue_retransmit(dev);
+ }
+ break;
+
+ case 7:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit unknown ack\n");
+ priv->bad += 1;
+ priv->reset = 0;
+ arlan_queue_retransmit(dev);
+ }
+ break;
+
+ case 8:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit dest mail box full\n");
+ priv->bad += 1;
+ priv->reset = 0;
+ //arlan_drop_tx(dev);
+ arlan_queue_retransmit(dev);
+ }
+ break;
+
+ case 9:
+ {
+ IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
+ printk("arlan intr: transmit root dest not reg.\n");
+ priv->bad += 1;
+ priv->reset = 1;
+ //arlan_drop_tx(dev);
+ arlan_queue_retransmit(dev);
+ }
+ break;
+
+ default:
+ {
+ printk(KERN_ERR "arlan intr: transmit status unknown\n");
+ priv->bad += 1;
+ priv->reset = 1;
+ arlan_drop_tx(dev);
+ }
+ }
+
+ ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt");
+}
+
+
+static void arlan_rx_interrupt(struct net_device *dev, u_char rxStatus, u_short rxOffset, u_short pkt_len)
+{
+ char *skbtmp;
+ int i = 0;
+
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ struct arlan_conf_stru *conf = priv->Conf;
+
+
+ ARLAN_DEBUG_ENTRY("arlan_rx_interrupt");
+ // by spec, not WRITESHMB(arlan->rxStatus,0x00);
+ // prohibited here arlan_command(dev, ARLAN_COMMAND_RX);
+
+ if (pkt_len < 10 || pkt_len > 2048)
+ {
+ printk(KERN_WARNING "%s: got too short or long packet, len %d \n", dev->name, pkt_len);
+ return;
+ }
+ if (rxOffset + pkt_len > 0x2000)
+ {
+ printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset);
+ return;
+ }
+ priv->in_bytes += pkt_len;
+ priv->in_bytes10 += pkt_len;
+ if (conf->measure_rate < 1)
+ conf->measure_rate = 1;
+ if (time_after(jiffies, priv->in_time + conf->measure_rate * HZ))
+ {
+ conf->in_speed = priv->in_bytes / conf->measure_rate;
+ priv->in_bytes = 0;
+ priv->in_time = jiffies;
+ }
+ if (time_after(jiffies, priv->in_time10 + conf->measure_rate * 10*HZ))
+ {
+ conf->in_speed10 = priv->in_bytes10 / (10 * conf->measure_rate);
+ priv->in_bytes10 = 0;
+ priv->in_time10 = jiffies;
+ }
+ DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan->rxStatus, u_char);
+ switch (rxStatus)
+ {
+ case 1:
+ case 2:
+ case 3:
+ {
+ /* Malloc up new buffer. */
+ struct sk_buff *skb;
+
+ DEBUGSHM(50, "arlan recv pkt offs=%d\n", arlan->rxOffset, u_short);
+ DEBUGSHM(1, "arlan rxFrmType = %d \n", arlan->rxFrmType, u_char);
+ DEBUGSHM(1, KERN_INFO "arlan rx scrambled = %d \n", arlan->scrambled, u_char);
+
+ /* here we do multicast filtering to avoid slow 8-bit memcopy */
+#ifdef ARLAN_MULTICAST
+ if (!(dev->flags & IFF_ALLMULTI) &&
+ !(dev->flags & IFF_PROMISC) &&
+ dev->mc_list)
+ {
+ char hw_dst_addr[6];
+ struct dev_mc_list *dmi = dev->mc_list;
+ int i;
+
+ memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6);
+ if (hw_dst_addr[0] == 0x01)
+ {
+ if (mdebug)
+ if (hw_dst_addr[1] == 0x00)
+ printk(KERN_ERR "%s mcast 0x0100 \n", dev->name);
+ else if (hw_dst_addr[1] == 0x40)
+ printk(KERN_ERR "%s m/bcast 0x0140 \n", dev->name);
+ while (dmi)
+ { if (dmi->dmi_addrlen == 6)
+ {
+ if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
+ printk(KERN_ERR "%s mcl %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
+ dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
+ dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]);
+ for (i = 0; i < 6; i++)
+ if (dmi->dmi_addr[i] != hw_dst_addr[i])
+ break;
+ if (i == 6)
+ break;
+ }
+ else
+ printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
+ dmi = dmi->next;
+ }
+ /* we reach here if multicast filtering is on and packet
+ * is multicast and not for receive */
+ goto end_of_interrupt;
+ }
+ }
+#endif // ARLAN_MULTICAST
+ /* multicast filtering ends here */
+ pkt_len += ARLAN_FAKE_HDR_LEN;
+
+ skb = dev_alloc_skb(pkt_len + 4);
+ if (skb == NULL)
+ {
+ printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
+ priv->stats.rx_dropped++;
+ break;
+ }
+ skb_reserve(skb, 2);
+ skb->dev = dev;
+ skbtmp = skb_put(skb, pkt_len);
+
+ memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char __iomem *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN);
+ memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6);
+ memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6);
+ WRITESHMB(arlan->rxStatus, 0x00);
+ arlan_command(dev, ARLAN_COMMAND_RX);
+
+ IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
+ {
+ char immedDestAddress[6];
+ char immedSrcAddress[6];
+ memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
+ memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
+
+ printk(KERN_WARNING "%s t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x imd %2x:%2x:%2x:%2x:%2x:%2x ims %2x:%2x:%2x:%2x:%2x:%2x\n", dev->name,
+ (unsigned char) skbtmp[0], (unsigned char) skbtmp[1], (unsigned char) skbtmp[2], (unsigned char) skbtmp[3],
+ (unsigned char) skbtmp[4], (unsigned char) skbtmp[5], (unsigned char) skbtmp[6], (unsigned char) skbtmp[7],
+ (unsigned char) skbtmp[8], (unsigned char) skbtmp[9], (unsigned char) skbtmp[10], (unsigned char) skbtmp[11],
+ immedDestAddress[0], immedDestAddress[1], immedDestAddress[2],
+ immedDestAddress[3], immedDestAddress[4], immedDestAddress[5],
+ immedSrcAddress[0], immedSrcAddress[1], immedSrcAddress[2],
+ immedSrcAddress[3], immedSrcAddress[4], immedSrcAddress[5]);
+ }
+ skb->protocol = eth_type_trans(skb, dev);
+ IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
+ if (skb->protocol != 0x608 && skb->protocol != 0x8)
+ {
+ for (i = 0; i <= 22; i++)
+ printk("%02x:", (u_char) skbtmp[i + 12]);
+ printk(KERN_ERR "\n");
+ printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol);
+ }
+ netif_rx(skb);
+ dev->last_rx = jiffies;
+ priv->stats.rx_packets++;
+ priv->stats.rx_bytes += pkt_len;
+ }
+ break;
+
+ default:
+ printk(KERN_ERR "arlan intr: received unknown status\n");
+ priv->stats.rx_crc_errors++;
+ break;
+ }
+ ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
+}
+
+static void arlan_process_interrupt(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ u_char rxStatus = READSHMB(arlan->rxStatus);
+ u_char txStatus = READSHMB(arlan->txStatus);
+ u_short rxOffset = READSHMS(arlan->rxOffset);
+ u_short pkt_len = READSHMS(arlan->rxLength);
+ int interrupt_count = 0;
+
+ ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
+
+ if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
+ {
+ if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
+ printk(KERN_ERR "interrupt chain reentering \n");
+ goto end_int_process;
+ }
+ while ((rxStatus || txStatus || priv->interrupt_ack_requested)
+ && (interrupt_count < 5))
+ {
+ if (rxStatus)
+ priv->last_rx_int_ack_time = jiffies;
+
+ arlan_command(dev, ARLAN_COMMAND_INT_ACK);
+ arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
+
+ IFDEBUG(ARLAN_DEBUG_INTERRUPT)
+ printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
+ dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
+ rxOffset, pkt_len);
+
+ if (rxStatus == 0 && txStatus == 0)
+ {
+ if (priv->irq_test_done)
+ {
+ if (!registrationBad(dev))
+ IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
+ dev->name, txStatus, rxStatus);
+ } else {
+ IFDEBUG(ARLAN_DEBUG_INTERRUPT)
+ printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
+
+ }
+ priv->interrupt_ack_requested = 0;
+ goto ends;
+ }
+ if (txStatus != 0)
+ {
+ WRITESHMB(arlan->txStatus, 0x00);
+ arlan_tx_done_interrupt(dev, txStatus);
+ goto ends;
+ }
+ if (rxStatus == 1 || rxStatus == 2)
+ { /* a packet waiting */
+ arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
+ goto ends;
+ }
+ if (rxStatus > 2 && rxStatus < 0xff)
+ {
+ WRITESHMB(arlan->rxStatus, 0x00);
+ printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
+ dev->name, txStatus, rxStatus);
+ goto ends;
+ }
+ if (rxStatus == 0xff)
+ {
+ WRITESHMB(arlan->rxStatus, 0x00);
+ arlan_command(dev, ARLAN_COMMAND_RX);
+ if (registrationBad(dev))
+ netif_device_detach(dev);
+ if (!registrationBad(dev))
+ {
+ priv->registrationLastSeen = jiffies;
+ if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config)
+ netif_wake_queue (dev);
+ }
+ goto ends;
+ }
+ends:
+
+ arlan_command_process(dev);
+
+ rxStatus = READSHMB(arlan->rxStatus);
+ txStatus = READSHMB(arlan->txStatus);
+ rxOffset = READSHMS(arlan->rxOffset);
+ pkt_len = READSHMS(arlan->rxLength);
+
+
+ priv->irq_test_done = 1;
+
+ interrupt_count++;
+ }
+ priv->interrupt_processing_active = 0;
+
+end_int_process:
+ arlan_command_process(dev);
+
+ ARLAN_DEBUG_EXIT("arlan_process_interrupt");
+ return;
+}
+
+static irqreturn_t arlan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ struct net_device *dev = dev_id;
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ u_char rxStatus = READSHMB(arlan->rxStatus);
+ u_char txStatus = READSHMB(arlan->txStatus);
+
+ ARLAN_DEBUG_ENTRY("arlan_interrupt");
+
+
+ if (!rxStatus && !txStatus)
+ priv->interrupt_ack_requested++;
+
+ arlan_process_interrupt(dev);
+
+ priv->irq_test_done = 1;
+
+ ARLAN_DEBUG_EXIT("arlan_interrupt");
+ return IRQ_HANDLED;
+
+}
+
+
+static int arlan_close(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+
+ ARLAN_DEBUG_ENTRY("arlan_close");
+
+ del_timer_sync(&priv->timer);
+
+ arlan_command(dev, ARLAN_COMMAND_POWERDOWN);
+
+ IFDEBUG(ARLAN_DEBUG_STARTUP)
+ printk(KERN_NOTICE "%s: Closing device\n", dev->name);
+
+ netif_stop_queue(dev);
+ free_irq(dev->irq, dev);
+
+ ARLAN_DEBUG_EXIT("arlan_close");
+ return 0;
+}
+
+#ifdef ARLAN_DEBUGGING
+static long alignLong(volatile u_char * ptr)
+{
+ long ret;
+ memcpy_fromio(&ret, (void *) ptr, 4);
+ return ret;
+}
+#endif
+
+/*
+ * Get the current statistics.
+ * This may be called with the card open or closed.
+ */
+
+static struct net_device_stats *arlan_statistics(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+
+
+ ARLAN_DEBUG_ENTRY("arlan_statistics");
+
+ /* Update the statistics from the device registers. */
+
+ READSHM(priv->stats.collisions, arlan->numReTransmissions, u_int);
+ READSHM(priv->stats.rx_crc_errors, arlan->numCRCErrors, u_int);
+ READSHM(priv->stats.rx_dropped, arlan->numFramesDiscarded, u_int);
+ READSHM(priv->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int);
+ READSHM(priv->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int);
+ READSHM(priv->stats.rx_over_errors, arlan->numRXOverruns, u_int);
+ READSHM(priv->stats.rx_packets, arlan->numDatagramsReceived, u_int);
+ READSHM(priv->stats.tx_aborted_errors, arlan->numAbortErrors, u_int);
+ READSHM(priv->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int);
+ READSHM(priv->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int);
+ READSHM(priv->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int);
+ READSHM(priv->stats.tx_packets, arlan->numDatagramsTransmitted, u_int);
+ READSHM(priv->stats.tx_window_errors, arlan->numHoldOffs, u_int);
+
+ ARLAN_DEBUG_EXIT("arlan_statistics");
+
+ return &priv->stats;
+}
+
+
+static void arlan_set_multicast(struct net_device *dev)
+{
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ struct arlan_conf_stru *conf = priv->Conf;
+ int board_conf_needed = 0;
+
+
+ ARLAN_DEBUG_ENTRY("arlan_set_multicast");
+
+ if (dev->flags & IFF_PROMISC)
+ {
+ unsigned char recMode;
+ READSHM(recMode, arlan->receiveMode, u_char);
+ conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL);
+ if (conf->receiveMode != recMode)
+ board_conf_needed = 1;
+ }
+ else
+ {
+ /* turn off promiscuous mode */
+ unsigned char recMode;
+ READSHM(recMode, arlan->receiveMode, u_char);
+ conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL;
+ if (conf->receiveMode != recMode)
+ board_conf_needed = 1;
+ }
+ if (board_conf_needed)
+ arlan_command(dev, ARLAN_COMMAND_CONF);
+
+ ARLAN_DEBUG_EXIT("arlan_set_multicast");
+}
+
+
+struct net_device * __init arlan_probe(int unit)
+{
+ struct net_device *dev;
+ int err;
+ int m;
+
+ ARLAN_DEBUG_ENTRY("arlan_probe");
+
+ if (arlans_found == MAX_ARLANS)
+ return ERR_PTR(-ENODEV);
+
+ /*
+ * Reserve space for local data and a copy of the shared memory
+ * that is used by the /proc interface.
+ */
+ dev = alloc_etherdev(sizeof(struct arlan_private)
+ + sizeof(struct arlan_shmem));
+ if (!dev)
+ return ERR_PTR(-ENOMEM);
+
+ SET_MODULE_OWNER(dev);
+
+ if (unit >= 0) {
+ sprintf(dev->name, "eth%d", unit);
+ netdev_boot_setup_check(dev);
+
+ if (dev->mem_start) {
+ if (arlan_probe_here(dev, dev->mem_start) == 0)
+ goto found;
+ goto not_found;
+ }
+
+ }
+
+
+ for (m = (int)phys_to_virt(lastFoundAt) + ARLAN_SHMEM_SIZE;
+ m <= (int)phys_to_virt(0xDE000);
+ m += ARLAN_SHMEM_SIZE)
+ {
+ if (arlan_probe_here(dev, m) == 0)
+ {
+ lastFoundAt = (int)virt_to_phys((void*)m);
+ goto found;
+ }
+ }
+
+ if (lastFoundAt == 0xbe000)
+ printk(KERN_ERR "arlan: No Arlan devices found \n");
+
+ not_found:
+ free_netdev(dev);
+ return ERR_PTR(-ENODEV);
+
+ found:
+ err = arlan_setup_device(dev, arlans_found);
+ if (err)
+ dev = ERR_PTR(err);
+ else if (!arlans_found++)
+ printk(KERN_INFO "Arlan driver %s\n", arlan_version);
+
+ return dev;
+}
+
+#ifdef MODULE
+int init_module(void)
+{
+ int i = 0;
+
+ ARLAN_DEBUG_ENTRY("init_module");
+
+ if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
+ return -EINVAL;
+
+ for (i = 0; i < MAX_ARLANS; i++) {
+ struct net_device *dev = arlan_probe(i);
+
+ if (IS_ERR(dev))
+ return PTR_ERR(dev);
+ }
+ init_arlan_proc();
+ printk(KERN_INFO "Arlan driver %s\n", arlan_version);
+ ARLAN_DEBUG_EXIT("init_module");
+ return 0;
+}
+
+
+void cleanup_module(void)
+{
+ int i = 0;
+ struct net_device *dev;
+
+ ARLAN_DEBUG_ENTRY("cleanup_module");
+
+ IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
+ printk(KERN_INFO "arlan: unloading module\n");
+
+ cleanup_arlan_proc();
+
+ for (i = 0; i < MAX_ARLANS; i++)
+ {
+ dev = arlan_device[i];
+ if (dev) {
+ arlan_command(dev, ARLAN_COMMAND_POWERDOWN );
+
+ unregister_netdev(dev);
+ release_mem_region(virt_to_phys((void *) dev->mem_start),
+ ARLAN_SHMEM_SIZE);
+ free_netdev(dev);
+ arlan_device[i] = NULL;
+ }
+ }
+
+ ARLAN_DEBUG_EXIT("cleanup_module");
+}
+
+
+#endif
+MODULE_LICENSE("GPL");
diff --git a/drivers/net/wireless/arlan-proc.c b/drivers/net/wireless/arlan-proc.c
new file mode 100644
index 000000000000..a2cca521f444
--- /dev/null
+++ b/drivers/net/wireless/arlan-proc.c
@@ -0,0 +1,1262 @@
+#include <linux/config.h>
+#include "arlan.h"
+
+#include <linux/sysctl.h>
+
+#ifdef CONFIG_PROC_FS
+
+/* void enableReceive(struct net_device* dev);
+*/
+
+
+
+#define ARLAN_STR_SIZE 0x2ff0
+#define DEV_ARLAN_INFO 1
+#define DEV_ARLAN 1
+#define SARLG(type,var) {\
+ pos += sprintf(arlan_drive_info+pos, "%s\t=\t0x%x\n", #var, READSHMB(priva->card->var)); \
+ }
+
+#define SARLBN(type,var,nn) {\
+ pos += sprintf(arlan_drive_info+pos, "%s\t=\t0x",#var);\
+ for (i=0; i < nn; i++ ) pos += sprintf(arlan_drive_info+pos, "%02x",READSHMB(priva->card->var[i]));\
+ pos += sprintf(arlan_drive_info+pos, "\n"); \
+ }
+
+#define SARLBNpln(type,var,nn) {\
+ for (i=0; i < nn; i++ ) pos += sprintf(arlan_drive_info+pos, "%02x",READSHMB(priva->card->var[i]));\
+ }
+
+#define SARLSTR(var,nn) {\
+ char tmpStr[400];\
+ int tmpLn = nn;\
+ if (nn > 399 ) tmpLn = 399; \
+ memcpy(tmpStr,(char *) priva->conf->var,tmpLn);\
+ tmpStr[tmpLn] = 0; \
+ pos += sprintf(arlan_drive_info+pos, "%s\t=\t%s \n",#var,priva->conf->var);\
+ }
+
+#define SARLUC(var) SARLG(u_char, var)
+#define SARLUCN(var,nn) SARLBN(u_char,var, nn)
+#define SARLUS(var) SARLG(u_short, var)
+#define SARLUSN(var,nn) SARLBN(u_short,var, nn)
+#define SARLUI(var) SARLG(u_int, var)
+
+#define SARLUSA(var) {\
+ u_short tmpVar;\
+ memcpy(&tmpVar, (short *) priva->conf->var,2); \
+ pos += sprintf(arlan_drive_info+pos, "%s\t=\t0x%x\n",#var, tmpVar);\
+}
+
+#define SARLUIA(var) {\
+ u_int tmpVar;\
+ memcpy(&tmpVar, (int* )priva->conf->var,4); \
+ pos += sprintf(arlan_drive_info+pos, "%s\t=\t0x%x\n",#var, tmpVar);\
+}
+
+
+static const char *arlan_diagnostic_info_string(struct net_device *dev)
+{
+
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ u_char diagnosticInfo;
+
+ READSHM(diagnosticInfo, arlan->diagnosticInfo, u_char);
+
+ switch (diagnosticInfo)
+ {
+ case 0xFF:
+ return "Diagnostic info is OK";
+ case 0xFE:
+ return "ERROR EPROM Checksum error ";
+ case 0xFD:
+ return "ERROR Local Ram Test Failed ";
+ case 0xFC:
+ return "ERROR SCC failure ";
+ case 0xFB:
+ return "ERROR BackBone failure ";
+ case 0xFA:
+ return "ERROR transceiver not found ";
+ case 0xF9:
+ return "ERROR no more address space ";
+ case 0xF8:
+ return "ERROR Checksum error ";
+ case 0xF7:
+ return "ERROR Missing SS Code";
+ case 0xF6:
+ return "ERROR Invalid config format";
+ case 0xF5:
+ return "ERROR Reserved errorcode F5";
+ case 0xF4:
+ return "ERROR Invalid spreading code/channel number";
+ case 0xF3:
+ return "ERROR Load Code Error";
+ case 0xF2:
+ return "ERROR Reserver errorcode F2 ";
+ case 0xF1:
+ return "ERROR Invalid command receivec by LAN card ";
+ case 0xF0:
+ return "ERROR Invalid parameter found in command ";
+ case 0xEF:
+ return "ERROR On-chip timer failure ";
+ case 0xEE:
+ return "ERROR T410 timer failure ";
+ case 0xED:
+ return "ERROR Too Many TxEnable commands ";
+ case 0xEC:
+ return "ERROR EEPROM error on radio module ";
+ default:
+ return "ERROR unknown Diagnostic info reply code ";
+ }
+}
+
+static const char *arlan_hardware_type_string(struct net_device *dev)
+{
+ u_char hardwareType;
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+
+ READSHM(hardwareType, arlan->hardwareType, u_char);
+ switch (hardwareType)
+ {
+ case 0x00:
+ return "type A450";
+ case 0x01:
+ return "type A650 ";
+ case 0x04:
+ return "type TMA coproc";
+ case 0x0D:
+ return "type A650E ";
+ case 0x18:
+ return "type TMA coproc Australian";
+ case 0x19:
+ return "type A650A ";
+ case 0x26:
+ return "type TMA coproc European";
+ case 0x2E:
+ return "type A655 ";
+ case 0x2F:
+ return "type A655A ";
+ case 0x30:
+ return "type A655E ";
+ case 0x0B:
+ return "type A670 ";
+ case 0x0C:
+ return "type A670E ";
+ case 0x2D:
+ return "type A670A ";
+ case 0x0F:
+ return "type A411T";
+ case 0x16:
+ return "type A411TA";
+ case 0x1B:
+ return "type A440T";
+ case 0x1C:
+ return "type A412T";
+ case 0x1E:
+ return "type A412TA";
+ case 0x22:
+ return "type A411TE";
+ case 0x24:
+ return "type A412TE";
+ case 0x27:
+ return "type A671T ";
+ case 0x29:
+ return "type A671TA ";
+ case 0x2B:
+ return "type A671TE ";
+ case 0x31:
+ return "type A415T ";
+ case 0x33:
+ return "type A415TA ";
+ case 0x35:
+ return "type A415TE ";
+ case 0x37:
+ return "type A672";
+ case 0x39:
+ return "type A672A ";
+ case 0x3B:
+ return "type A672T";
+ case 0x6B:
+ return "type IC2200";
+ default:
+ return "type A672T";
+ }
+}
+#ifdef ARLAN_DEBUGGING
+static void arlan_print_diagnostic_info(struct net_device *dev)
+{
+ int i;
+ u_char diagnosticInfo;
+ u_short diagnosticOffset;
+ u_char hardwareType;
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+
+ // ARLAN_DEBUG_ENTRY("arlan_print_diagnostic_info");
+
+ if (READSHMB(arlan->configuredStatusFlag) == 0)
+ printk("Arlan: Card NOT configured\n");
+ else
+ printk("Arlan: Card is configured\n");
+
+ READSHM(diagnosticInfo, arlan->diagnosticInfo, u_char);
+ READSHM(diagnosticOffset, arlan->diagnosticOffset, u_short);
+
+ printk(KERN_INFO "%s\n", arlan_diagnostic_info_string(dev));
+
+ if (diagnosticInfo != 0xff)
+ printk("%s arlan: Diagnostic Offset %d \n", dev->name, diagnosticOffset);
+
+ printk("arlan: LAN CODE ID = ");
+ for (i = 0; i < 6; i++)
+ DEBUGSHM(1, "%03d:", arlan->lanCardNodeId[i], u_char);
+ printk("\n");
+
+ printk("arlan: Arlan BroadCast address = ");
+ for (i = 0; i < 6; i++)
+ DEBUGSHM(1, "%03d:", arlan->broadcastAddress[i], u_char);
+ printk("\n");
+
+ READSHM(hardwareType, arlan->hardwareType, u_char);
+ printk(KERN_INFO "%s\n", arlan_hardware_type_string(dev));
+
+
+ DEBUGSHM(1, "arlan: channelNumber=%d\n", arlan->channelNumber, u_char);
+ DEBUGSHM(1, "arlan: channelSet=%d\n", arlan->channelSet, u_char);
+ DEBUGSHM(1, "arlan: spreadingCode=%d\n", arlan->spreadingCode, u_char);
+ DEBUGSHM(1, "arlan: radioNodeId=%d\n", arlan->radioNodeId, u_short);
+ DEBUGSHM(1, "arlan: SID =%d\n", arlan->SID, u_short);
+ DEBUGSHM(1, "arlan: rxOffset=%d\n", arlan->rxOffset, u_short);
+
+ DEBUGSHM(1, "arlan: registration mode is %d\n", arlan->registrationMode, u_char);
+
+ printk("arlan: name= ");
+ IFDEBUG(1)
+
+ for (i = 0; i < 16; i++)
+ {
+ char c;
+ READSHM(c, arlan->name[i], char);
+ if (c)
+ printk("%c", c);
+ }
+ printk("\n");
+
+// ARLAN_DEBUG_EXIT("arlan_print_diagnostic_info");
+
+}
+
+
+/****************************** TEST MEMORY **************/
+
+static int arlan_hw_test_memory(struct net_device *dev)
+{
+ u_char *ptr;
+ int i;
+ int memlen = sizeof(struct arlan_shmem) - 0xF; /* avoid control register */
+ volatile char *arlan_mem = (char *) (dev->mem_start);
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+ char pattern;
+
+ ptr = NULL;
+
+ /* hold card in reset state */
+ setHardwareReset(dev);
+
+ /* test memory */
+ pattern = 0;
+ for (i = 0; i < memlen; i++)
+ WRITESHM(arlan_mem[i], ((u_char) pattern++), u_char);
+
+ pattern = 0;
+ for (i = 0; i < memlen; i++)
+ {
+ char res;
+ READSHM(res, arlan_mem[i], char);
+ if (res != pattern++)
+ {
+ printk(KERN_ERR "Arlan driver memory test 1 failed \n");
+ return -1;
+ }
+ }
+
+ pattern = 0;
+ for (i = 0; i < memlen; i++)
+ WRITESHM(arlan_mem[i], ~(pattern++), char);
+
+ pattern = 0;
+ for (i = 0; i < memlen; i++)
+ {
+ char res;
+ READSHM(res, arlan_mem[i], char);
+ if (res != ~(pattern++))
+ {
+ printk(KERN_ERR "Arlan driver memory test 2 failed \n");
+ return -1;
+ }
+ }
+
+ /* zero memory */
+ for (i = 0; i < memlen; i++)
+ WRITESHM(arlan_mem[i], 0x00, char);
+
+ IFDEBUG(1) printk(KERN_INFO "Arlan: memory tests ok\n");
+
+ /* set reset flag and then release reset */
+ WRITESHM(arlan->resetFlag, 0xff, u_char);
+
+ clearChannelAttention(dev);
+ clearHardwareReset(dev);
+
+ /* wait for reset flag to become zero, we'll wait for two seconds */
+ if (arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW))
+ {
+ printk(KERN_ERR "%s arlan: failed to come back from memory test\n", dev->name);
+ return -1;
+ }
+ return 0;
+}
+
+static int arlan_setup_card_by_book(struct net_device *dev)
+{
+ u_char irqLevel, configuredStatusFlag;
+ struct arlan_private *priv = netdev_priv(dev);
+ volatile struct arlan_shmem __iomem *arlan = priv->card;
+
+// ARLAN_DEBUG_ENTRY("arlan_setup_card");
+
+ READSHM(configuredStatusFlag, arlan->configuredStatusFlag, u_char);
+
+ IFDEBUG(10)
+ if (configuredStatusFlag != 0)
+ IFDEBUG(10) printk("arlan: CARD IS CONFIGURED\n");
+ else
+ IFDEBUG(10) printk("arlan: card is NOT configured\n");
+
+ if (testMemory || (READSHMB(arlan->diagnosticInfo) != 0xff))
+ if (arlan_hw_test_memory(dev))
+ return -1;
+
+ DEBUGSHM(4, "arlan configuredStatus = %d \n", arlan->configuredStatusFlag, u_char);
+ DEBUGSHM(4, "arlan driver diagnostic: 0x%2x\n", arlan->diagnosticInfo, u_char);
+
+ /* issue nop command - no interrupt */
+ arlan_command(dev, ARLAN_COMMAND_NOOP);
+ if (arlan_command(dev, ARLAN_COMMAND_WAIT_NOW) != 0)
+ return -1;
+
+ IFDEBUG(50) printk("1st Noop successfully executed !!\n");
+
+ /* try to turn on the arlan interrupts */
+ clearClearInterrupt(dev);
+ setClearInterrupt(dev);
+ setInterruptEnable(dev);
+
+ /* issue nop command - with interrupt */
+
+ arlan_command(dev, ARLAN_COMMAND_NOOPINT);
+ if (arlan_command(dev, ARLAN_COMMAND_WAIT_NOW) != 0)
+ return -1;
+
+
+ IFDEBUG(50) printk("2nd Noop successfully executed !!\n");
+
+ READSHM(irqLevel, arlan->irqLevel, u_char)
+
+ if (irqLevel != dev->irq)
+ {
+ IFDEBUG(1) printk(KERN_WARNING "arlan dip switches set irq to %d\n", irqLevel);
+ printk(KERN_WARNING "device driver irq set to %d - does not match\n", dev->irq);
+ dev->irq = irqLevel;
+ }
+ else
+ IFDEBUG(2) printk("irq level is OK\n");
+
+
+ IFDEBUG(3) arlan_print_diagnostic_info(dev);
+
+ arlan_command(dev, ARLAN_COMMAND_CONF);
+
+ READSHM(configuredStatusFlag, arlan->configuredStatusFlag, u_char);
+ if (configuredStatusFlag == 0)
+ {
+ printk(KERN_WARNING "arlan configure failed\n");
+ return -1;
+ }
+ arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW);
+ arlan_command(dev, ARLAN_COMMAND_RX);
+ arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW);
+ printk(KERN_NOTICE "%s: arlan driver version %s loaded\n",
+ dev->name, arlan_version);
+
+// ARLAN_DEBUG_EXIT("arlan_setup_card");
+
+ return 0; /* no errors */
+}
+#endif
+
+#ifdef ARLAN_PROC_INTERFACE
+#ifdef ARLAN_PROC_SHM_DUMP
+
+static char arlan_drive_info[ARLAN_STR_SIZE] = "A655\n\0";
+
+static int arlan_sysctl_info(ctl_table * ctl, int write, struct file *filp,
+ void __user *buffer, size_t * lenp, loff_t *ppos)
+{
+ int i;
+ int retv, pos, devnum;
+ struct arlan_private *priva = NULL;
+ struct net_device *dev;
+ pos = 0;
+ if (write)
+ {
+ printk("wrirte: ");
+ for (i = 0; i < 100; i++)
+ printk("adi %x \n", arlan_drive_info[i]);
+ }
+ if (ctl->procname == NULL || arlan_drive_info == NULL)
+ {
+ printk(KERN_WARNING " procname is NULL in sysctl_table or arlan_drive_info is NULL \n at arlan module\n ");
+ return -1;
+ }
+ devnum = ctl->procname[5] - '0';
+ if (devnum < 0 || devnum > MAX_ARLANS - 1)
+ {
+ printk(KERN_WARNING "too strange devnum in procfs parse\n ");
+ return -1;
+ }
+ else if (arlan_device[devnum] == NULL)
+ {
+ if (ctl->procname)
+ pos += sprintf(arlan_drive_info + pos, "\t%s\n\n", ctl->procname);
+ pos += sprintf(arlan_drive_info + pos, "No device found here \n");
+ goto final;
+ }
+ else
+ priva = arlan_device[devnum]->priv;
+
+ if (priva == NULL)
+ {
+ printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
+ return -1;
+ }
+ dev = arlan_device[devnum];
+
+ memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
+
+ pos = sprintf(arlan_drive_info, "Arlan info \n");
+ /* Header Signature */
+ SARLSTR(textRegion, 48);
+ SARLUC(resetFlag);
+ pos += sprintf(arlan_drive_info + pos, "diagnosticInfo\t=\t%s \n", arlan_diagnostic_info_string(dev));
+ SARLUC(diagnosticInfo);
+ SARLUS(diagnosticOffset);
+ SARLUCN(_1, 12);
+ SARLUCN(lanCardNodeId, 6);
+ SARLUCN(broadcastAddress, 6);
+ pos += sprintf(arlan_drive_info + pos, "hardwareType =\t %s \n", arlan_hardware_type_string(dev));
+ SARLUC(hardwareType);
+ SARLUC(majorHardwareVersion);
+ SARLUC(minorHardwareVersion);
+ SARLUC(radioModule);
+ SARLUC(defaultChannelSet);
+ SARLUCN(_2, 47);
+
+ /* Control/Status Block - 0x0080 */
+ SARLUC(interruptInProgress);
+ SARLUC(cntrlRegImage);
+
+ SARLUCN(_3, 14);
+ SARLUC(commandByte);
+ SARLUCN(commandParameter, 15);
+
+ /* Receive Status - 0x00a0 */
+ SARLUC(rxStatus);
+ SARLUC(rxFrmType);
+ SARLUS(rxOffset);
+ SARLUS(rxLength);
+ SARLUCN(rxSrc, 6);
+ SARLUC(rxBroadcastFlag);
+ SARLUC(rxQuality);
+ SARLUC(scrambled);
+ SARLUCN(_4, 1);
+
+ /* Transmit Status - 0x00b0 */
+ SARLUC(txStatus);
+ SARLUC(txAckQuality);
+ SARLUC(numRetries);
+ SARLUCN(_5, 14);
+ SARLUCN(registeredRouter, 6);
+ SARLUCN(backboneRouter, 6);
+ SARLUC(registrationStatus);
+ SARLUC(configuredStatusFlag);
+ SARLUCN(_6, 1);
+ SARLUCN(ultimateDestAddress, 6);
+ SARLUCN(immedDestAddress, 6);
+ SARLUCN(immedSrcAddress, 6);
+ SARLUS(rxSequenceNumber);
+ SARLUC(assignedLocaltalkAddress);
+ SARLUCN(_7, 27);
+
+ /* System Parameter Block */
+
+ /* - Driver Parameters (Novell Specific) */
+
+ SARLUS(txTimeout);
+ SARLUS(transportTime);
+ SARLUCN(_8, 4);
+
+ /* - Configuration Parameters */
+ SARLUC(irqLevel);
+ SARLUC(spreadingCode);
+ SARLUC(channelSet);
+ SARLUC(channelNumber);
+ SARLUS(radioNodeId);
+ SARLUCN(_9, 2);
+ SARLUC(scramblingDisable);
+ SARLUC(radioType);
+ SARLUS(routerId);
+ SARLUCN(_10, 9);
+ SARLUC(txAttenuation);
+ SARLUIA(systemId);
+ SARLUS(globalChecksum);
+ SARLUCN(_11, 4);
+ SARLUS(maxDatagramSize);
+ SARLUS(maxFrameSize);
+ SARLUC(maxRetries);
+ SARLUC(receiveMode);
+ SARLUC(priority);
+ SARLUC(rootOrRepeater);
+ SARLUCN(specifiedRouter, 6);
+ SARLUS(fastPollPeriod);
+ SARLUC(pollDecay);
+ SARLUSA(fastPollDelay);
+ SARLUC(arlThreshold);
+ SARLUC(arlDecay);
+ SARLUCN(_12, 1);
+ SARLUS(specRouterTimeout);
+ SARLUCN(_13, 5);
+
+ /* Scrambled Area */
+ SARLUIA(SID);
+ SARLUCN(encryptionKey, 12);
+ SARLUIA(_14);
+ SARLUSA(waitTime);
+ SARLUSA(lParameter);
+ SARLUCN(_15, 3);
+ SARLUS(headerSize);
+ SARLUS(sectionChecksum);
+
+ SARLUC(registrationMode);
+ SARLUC(registrationFill);
+ SARLUS(pollPeriod);
+ SARLUS(refreshPeriod);
+ SARLSTR(name, 16);
+ SARLUCN(NID, 6);
+ SARLUC(localTalkAddress);
+ SARLUC(codeFormat);
+ SARLUC(numChannels);
+ SARLUC(channel1);
+ SARLUC(channel2);
+ SARLUC(channel3);
+ SARLUC(channel4);
+ SARLUCN(SSCode, 59);
+
+/* SARLUCN( _16, 0x140);
+ */
+ /* Statistics Block - 0x0300 */
+ SARLUC(hostcpuLock);
+ SARLUC(lancpuLock);
+ SARLUCN(resetTime, 18);
+ SARLUIA(numDatagramsTransmitted);
+ SARLUIA(numReTransmissions);
+ SARLUIA(numFramesDiscarded);
+ SARLUIA(numDatagramsReceived);
+ SARLUIA(numDuplicateReceivedFrames);
+ SARLUIA(numDatagramsDiscarded);
+ SARLUS(maxNumReTransmitDatagram);
+ SARLUS(maxNumReTransmitFrames);
+ SARLUS(maxNumConsecutiveDuplicateFrames);
+ /* misaligned here so we have to go to characters */
+ SARLUIA(numBytesTransmitted);
+ SARLUIA(numBytesReceived);
+ SARLUIA(numCRCErrors);
+ SARLUIA(numLengthErrors);
+ SARLUIA(numAbortErrors);
+ SARLUIA(numTXUnderruns);
+ SARLUIA(numRXOverruns);
+ SARLUIA(numHoldOffs);
+ SARLUIA(numFramesTransmitted);
+ SARLUIA(numFramesReceived);
+ SARLUIA(numReceiveFramesLost);
+ SARLUIA(numRXBufferOverflows);
+ SARLUIA(numFramesDiscardedAddrMismatch);
+ SARLUIA(numFramesDiscardedSIDMismatch);
+ SARLUIA(numPollsTransmistted);
+ SARLUIA(numPollAcknowledges);
+ SARLUIA(numStatusTimeouts);
+ SARLUIA(numNACKReceived);
+ SARLUS(auxCmd);
+ SARLUCN(dumpPtr, 4);
+ SARLUC(dumpVal);
+ SARLUC(wireTest);
+
+ /* next 4 seems too long for procfs, over single page ?
+ SARLUCN( _17, 0x86);
+ SARLUCN( txBuffer, 0x800);
+ SARLUCN( rxBuffer, 0x800);
+ SARLUCN( _18, 0x0bff);
+ */
+
+ pos += sprintf(arlan_drive_info + pos, "rxRing\t=\t0x");
+ for (i = 0; i < 0x50; i++)
+ pos += sprintf(arlan_drive_info + pos, "%02x", ((char *) priva->conf)[priva->conf->rxOffset + i]);
+ pos += sprintf(arlan_drive_info + pos, "\n");
+
+ SARLUC(configStatus);
+ SARLUC(_22);
+ SARLUC(progIOCtrl);
+ SARLUC(shareMBase);
+ SARLUC(controlRegister);
+
+ pos += sprintf(arlan_drive_info + pos, " total %d chars\n", pos);
+ if (ctl)
+ if (ctl->procname)
+ pos += sprintf(arlan_drive_info + pos, " driver name : %s\n", ctl->procname);
+final:
+ *lenp = pos;
+
+ if (!write)
+ retv = proc_dostring(ctl, write, filp, buffer, lenp, ppos);
+ else
+ {
+ *lenp = 0;
+ return -1;
+ }
+ return retv;
+}
+
+
+static int arlan_sysctl_info161719(ctl_table * ctl, int write, struct file *filp,
+ void __user *buffer, size_t * lenp, loff_t *ppos)
+{
+ int i;
+ int retv, pos, devnum;
+ struct arlan_private *priva = NULL;
+
+ pos = 0;
+ devnum = ctl->procname[5] - '0';
+ if (arlan_device[devnum] == NULL)
+ {
+ pos += sprintf(arlan_drive_info + pos, "No device found here \n");
+ goto final;
+ }
+ else
+ priva = arlan_device[devnum]->priv;
+ if (priva == NULL)
+ {
+ printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
+ return -1;
+ }
+ memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
+ SARLUCN(_16, 0xC0);
+ SARLUCN(_17, 0x6A);
+ SARLUCN(_18, 14);
+ SARLUCN(_19, 0x86);
+ SARLUCN(_21, 0x3fd);
+
+final:
+ *lenp = pos;
+ retv = proc_dostring(ctl, write, filp, buffer, lenp, ppos);
+ return retv;
+}
+
+static int arlan_sysctl_infotxRing(ctl_table * ctl, int write, struct file *filp,
+ void __user *buffer, size_t * lenp, loff_t *ppos)
+{
+ int i;
+ int retv, pos, devnum;
+ struct arlan_private *priva = NULL;
+
+ pos = 0;
+ devnum = ctl->procname[5] - '0';
+ if (arlan_device[devnum] == NULL)
+ {
+ pos += sprintf(arlan_drive_info + pos, "No device found here \n");
+ goto final;
+ }
+ else
+ priva = arlan_device[devnum]->priv;
+ if (priva == NULL)
+ {
+ printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
+ return -1;
+ }
+ memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
+ SARLBNpln(u_char, txBuffer, 0x800);
+final:
+ *lenp = pos;
+ retv = proc_dostring(ctl, write, filp, buffer, lenp, ppos);
+ return retv;
+}
+
+static int arlan_sysctl_inforxRing(ctl_table * ctl, int write, struct file *filp,
+ void __user *buffer, size_t * lenp, loff_t *ppos)
+{
+ int i;
+ int retv, pos, devnum;
+ struct arlan_private *priva = NULL;
+
+ pos = 0;
+ devnum = ctl->procname[5] - '0';
+ if (arlan_device[devnum] == NULL)
+ {
+ pos += sprintf(arlan_drive_info + pos, "No device found here \n");
+ goto final;
+ } else
+ priva = arlan_device[devnum]->priv;
+ if (priva == NULL)
+ {
+ printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
+ return -1;
+ }
+ memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
+ SARLBNpln(u_char, rxBuffer, 0x800);
+final:
+ *lenp = pos;
+ retv = proc_dostring(ctl, write, filp, buffer, lenp, ppos);
+ return retv;
+}
+
+static int arlan_sysctl_info18(ctl_table * ctl, int write, struct file *filp,
+ void __user *buffer, size_t * lenp, loff_t *ppos)
+{
+ int i;
+ int retv, pos, devnum;
+ struct arlan_private *priva = NULL;
+
+ pos = 0;
+ devnum = ctl->procname[5] - '0';
+ if (arlan_device[devnum] == NULL)
+ {
+ pos += sprintf(arlan_drive_info + pos, "No device found here \n");
+ goto final;
+ }
+ else
+ priva = arlan_device[devnum]->priv;
+ if (priva == NULL)
+ {
+ printk(KERN_WARNING " Could not find the device private in arlan procsys, bad\n ");
+ return -1;
+ }
+ memcpy_fromio(priva->conf, priva->card, sizeof(struct arlan_shmem));
+ SARLBNpln(u_char, _18, 0x800);
+
+final:
+ *lenp = pos;
+ retv = proc_dostring(ctl, write, filp, buffer, lenp, ppos);
+ return retv;
+}
+
+
+#endif /* #ifdef ARLAN_PROC_SHM_DUMP */
+
+
+static char conf_reset_result[200];
+
+static int arlan_configure(ctl_table * ctl, int write, struct file *filp,
+ void __user *buffer, size_t * lenp, loff_t *ppos)
+{
+ int pos = 0;
+ int devnum = ctl->procname[6] - '0';
+ struct arlan_private *priv;
+
+ if (devnum < 0 || devnum > MAX_ARLANS - 1)
+ {
+ printk(KERN_WARNING "too strange devnum in procfs parse\n ");
+ return -1;
+ }
+ else if (arlan_device[devnum] != NULL)
+ {
+ priv = arlan_device[devnum]->priv;
+
+ arlan_command(arlan_device[devnum], ARLAN_COMMAND_CLEAN_AND_CONF);
+ }
+ else
+ return -1;
+
+ *lenp = pos;
+ return proc_dostring(ctl, write, filp, buffer, lenp, ppos);
+}
+
+static int arlan_sysctl_reset(ctl_table * ctl, int write, struct file *filp,
+ void __user *buffer, size_t * lenp, loff_t *ppos)
+{
+ int pos = 0;
+ int devnum = ctl->procname[5] - '0';
+ struct arlan_private *priv;
+
+ if (devnum < 0 || devnum > MAX_ARLANS - 1)
+ {
+ printk(KERN_WARNING "too strange devnum in procfs parse\n ");
+ return -1;
+ }
+ else if (arlan_device[devnum] != NULL)
+ {
+ priv = arlan_device[devnum]->priv;
+ arlan_command(arlan_device[devnum], ARLAN_COMMAND_CLEAN_AND_RESET);
+
+ } else
+ return -1;
+ *lenp = pos + 3;
+ return proc_dostring(ctl, write, filp, buffer, lenp, ppos);
+}
+
+
+/* Place files in /proc/sys/dev/arlan */
+#define CTBLN(num,card,nam) \
+ { .ctl_name = num,\
+ .procname = #nam,\
+ .data = &(arlan_conf[card].nam),\
+ .maxlen = sizeof(int), .mode = 0600, .proc_handler = &proc_dointvec}
+#ifdef ARLAN_DEBUGGING
+
+#define ARLAN_PROC_DEBUG_ENTRIES \
+ { .ctl_name = 48, .procname = "entry_exit_debug",\
+ .data = &arlan_entry_and_exit_debug,\
+ .maxlen = sizeof(int), .mode = 0600, .proc_handler = &proc_dointvec},\
+ { .ctl_name = 49, .procname = "debug", .data = &arlan_debug,\
+ .maxlen = sizeof(int), .mode = 0600, .proc_handler = &proc_dointvec},
+#else
+#define ARLAN_PROC_DEBUG_ENTRIES
+#endif
+
+#define ARLAN_SYSCTL_TABLE_TOTAL(cardNo)\
+ CTBLN(1,cardNo,spreadingCode),\
+ CTBLN(2,cardNo, channelNumber),\
+ CTBLN(3,cardNo, scramblingDisable),\
+ CTBLN(4,cardNo, txAttenuation),\
+ CTBLN(5,cardNo, systemId), \
+ CTBLN(6,cardNo, maxDatagramSize),\
+ CTBLN(7,cardNo, maxFrameSize),\
+ CTBLN(8,cardNo, maxRetries),\
+ CTBLN(9,cardNo, receiveMode),\
+ CTBLN(10,cardNo, priority),\
+ CTBLN(11,cardNo, rootOrRepeater),\
+ CTBLN(12,cardNo, SID),\
+ CTBLN(13,cardNo, registrationMode),\
+ CTBLN(14,cardNo, registrationFill),\
+ CTBLN(15,cardNo, localTalkAddress),\
+ CTBLN(16,cardNo, codeFormat),\
+ CTBLN(17,cardNo, numChannels),\
+ CTBLN(18,cardNo, channel1),\
+ CTBLN(19,cardNo, channel2),\
+ CTBLN(20,cardNo, channel3),\
+ CTBLN(21,cardNo, channel4),\
+ CTBLN(22,cardNo, txClear),\
+ CTBLN(23,cardNo, txRetries),\
+ CTBLN(24,cardNo, txRouting),\
+ CTBLN(25,cardNo, txScrambled),\
+ CTBLN(26,cardNo, rxParameter),\
+ CTBLN(27,cardNo, txTimeoutMs),\
+ CTBLN(28,cardNo, waitCardTimeout),\
+ CTBLN(29,cardNo, channelSet), \
+ {.ctl_name = 30, .procname = "name",\
+ .data = arlan_conf[cardNo].siteName,\
+ .maxlen = 16, .mode = 0600, .proc_handler = &proc_dostring},\
+ CTBLN(31,cardNo,waitTime),\
+ CTBLN(32,cardNo,lParameter),\
+ CTBLN(33,cardNo,_15),\
+ CTBLN(34,cardNo,headerSize),\
+ CTBLN(36,cardNo,tx_delay_ms),\
+ CTBLN(37,cardNo,retries),\
+ CTBLN(38,cardNo,ReTransmitPacketMaxSize),\
+ CTBLN(39,cardNo,waitReTransmitPacketMaxSize),\
+ CTBLN(40,cardNo,fastReTransCount),\
+ CTBLN(41,cardNo,driverRetransmissions),\
+ CTBLN(42,cardNo,txAckTimeoutMs),\
+ CTBLN(43,cardNo,registrationInterrupts),\
+ CTBLN(44,cardNo,hardwareType),\
+ CTBLN(45,cardNo,radioType),\
+ CTBLN(46,cardNo,writeEEPROM),\
+ CTBLN(47,cardNo,writeRadioType),\
+ ARLAN_PROC_DEBUG_ENTRIES\
+ CTBLN(50,cardNo,in_speed),\
+ CTBLN(51,cardNo,out_speed),\
+ CTBLN(52,cardNo,in_speed10),\
+ CTBLN(53,cardNo,out_speed10),\
+ CTBLN(54,cardNo,in_speed_max),\
+ CTBLN(55,cardNo,out_speed_max),\
+ CTBLN(56,cardNo,measure_rate),\
+ CTBLN(57,cardNo,pre_Command_Wait),\
+ CTBLN(58,cardNo,rx_tweak1),\
+ CTBLN(59,cardNo,rx_tweak2),\
+ CTBLN(60,cardNo,tx_queue_len),\
+
+
+
+static ctl_table arlan_conf_table0[] =
+{
+ ARLAN_SYSCTL_TABLE_TOTAL(0)
+
+#ifdef ARLAN_PROC_SHM_DUMP
+ {
+ .ctl_name = 150,
+ .procname = "arlan0-txRing",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_infotxRing,
+ },
+ {
+ .ctl_name = 151,
+ .procname = "arlan0-rxRing",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_inforxRing,
+ },
+ {
+ .ctl_name = 152,
+ .procname = "arlan0-18",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info18,
+ },
+ {
+ .ctl_name = 153,
+ .procname = "arlan0-ring",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info161719,
+ },
+ {
+ .ctl_name = 154,
+ .procname = "arlan0-shm-cpy",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info,
+ },
+#endif
+ {
+ .ctl_name = 155,
+ .procname = "config0",
+ .data = &conf_reset_result,
+ .maxlen = 100,
+ .mode = 0400,
+ .proc_handler = &arlan_configure
+ },
+ {
+ .ctl_name = 156,
+ .procname = "reset0",
+ .data = &conf_reset_result,
+ .maxlen = 100,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_reset,
+ },
+ { .ctl_name = 0 }
+};
+
+static ctl_table arlan_conf_table1[] =
+{
+
+ ARLAN_SYSCTL_TABLE_TOTAL(1)
+
+#ifdef ARLAN_PROC_SHM_DUMP
+ {
+ .ctl_name = 150,
+ .procname = "arlan1-txRing",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_infotxRing,
+ },
+ {
+ .ctl_name = 151,
+ .procname = "arlan1-rxRing",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_inforxRing,
+ },
+ {
+ .ctl_name = 152,
+ .procname = "arlan1-18",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info18,
+ },
+ {
+ .ctl_name = 153,
+ .procname = "arlan1-ring",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info161719,
+ },
+ {
+ .ctl_name = 154,
+ .procname = "arlan1-shm-cpy",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info,
+ },
+#endif
+ {
+ .ctl_name = 155,
+ .procname = "config1",
+ .data = &conf_reset_result,
+ .maxlen = 100,
+ .mode = 0400,
+ .proc_handler = &arlan_configure,
+ },
+ {
+ .ctl_name = 156,
+ .procname = "reset1",
+ .data = &conf_reset_result,
+ .maxlen = 100,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_reset,
+ },
+ { .ctl_name = 0 }
+};
+
+static ctl_table arlan_conf_table2[] =
+{
+
+ ARLAN_SYSCTL_TABLE_TOTAL(2)
+
+#ifdef ARLAN_PROC_SHM_DUMP
+ {
+ .ctl_name = 150,
+ .procname = "arlan2-txRing",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_infotxRing,
+ },
+ {
+ .ctl_name = 151,
+ .procname = "arlan2-rxRing",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_inforxRing,
+ },
+ {
+ .ctl_name = 152,
+ .procname = "arlan2-18",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info18,
+ },
+ {
+ .ctl_name = 153,
+ .procname = "arlan2-ring",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info161719,
+ },
+ {
+ .ctl_name = 154,
+ .procname = "arlan2-shm-cpy",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info,
+ },
+#endif
+ {
+ .ctl_name = 155,
+ .procname = "config2",
+ .data = &conf_reset_result,
+ .maxlen = 100,
+ .mode = 0400,
+ .proc_handler = &arlan_configure,
+ },
+ {
+ .ctl_name = 156,
+ .procname = "reset2",
+ .data = &conf_reset_result,
+ .maxlen = 100,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_reset,
+ },
+ { .ctl_name = 0 }
+};
+
+static ctl_table arlan_conf_table3[] =
+{
+
+ ARLAN_SYSCTL_TABLE_TOTAL(3)
+
+#ifdef ARLAN_PROC_SHM_DUMP
+ {
+ .ctl_name = 150,
+ .procname = "arlan3-txRing",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_infotxRing,
+ },
+ {
+ .ctl_name = 151,
+ .procname = "arlan3-rxRing",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_inforxRing,
+ },
+ {
+ .ctl_name = 152,
+ .procname = "arlan3-18",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info18,
+ },
+ {
+ .ctl_name = 153,
+ .procname = "arlan3-ring",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info161719,
+ },
+ {
+ .ctl_name = 154,
+ .procname = "arlan3-shm-cpy",
+ .data = &arlan_drive_info,
+ .maxlen = ARLAN_STR_SIZE,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_info,
+ },
+#endif
+ {
+ .ctl_name = 155,
+ .procname = "config3",
+ .data = &conf_reset_result,
+ .maxlen = 100,
+ .mode = 0400,
+ .proc_handler = &arlan_configure,
+ },
+ {
+ .ctl_name = 156,
+ .procname = "reset3",
+ .data = &conf_reset_result,
+ .maxlen = 100,
+ .mode = 0400,
+ .proc_handler = &arlan_sysctl_reset,
+ },
+ { .ctl_name = 0 }
+};
+
+
+
+static ctl_table arlan_table[] =
+{
+ {
+ .ctl_name = 0,
+ .procname = "arlan0",
+ .maxlen = 0,
+ .mode = 0600,
+ .child = arlan_conf_table0,
+ },
+ {
+ .ctl_name = 0,
+ .procname = "arlan1",
+ .maxlen = 0,
+ .mode = 0600,
+ .child = arlan_conf_table1,
+ },
+ {
+ .ctl_name = 0,
+ .procname = "arlan2",
+ .maxlen = 0,
+ .mode = 0600,
+ .child = arlan_conf_table2,
+ },
+ {
+ .ctl_name = 0,
+ .procname = "arlan3",
+ .maxlen = 0,
+ .mode = 0600,
+ .child = arlan_conf_table3,
+ },
+ { .ctl_name = 0 }
+};
+
+#else
+
+static ctl_table arlan_table[MAX_ARLANS + 1] =
+{
+ { .ctl_name = 0 }
+};
+#endif
+#else
+
+static ctl_table arlan_table[MAX_ARLANS + 1] =
+{
+ { .ctl_name = 0 }
+};
+#endif
+
+
+// static int mmtu = 1234;
+
+static ctl_table arlan_root_table[] =
+{
+ {
+ .ctl_name = 254,
+ .procname = "arlan",
+ .maxlen = 0,
+ .mode = 0555,
+ .child = arlan_table,
+ },
+ { .ctl_name = 0 }
+};
+
+/* Make sure that /proc/sys/dev is there */
+//static ctl_table arlan_device_root_table[] =
+//{
+// {CTL_DEV, "dev", NULL, 0, 0555, arlan_root_table},
+// {0}
+//};
+
+
+#ifdef CONFIG_PROC_FS
+static struct ctl_table_header *arlan_device_sysctl_header;
+
+int __init init_arlan_proc(void)
+{
+
+ int i = 0;
+ if (arlan_device_sysctl_header)
+ return 0;
+ for (i = 0; i < MAX_ARLANS && arlan_device[i]; i++)
+ arlan_table[i].ctl_name = i + 1;
+ arlan_device_sysctl_header = register_sysctl_table(arlan_root_table, 0);
+ if (!arlan_device_sysctl_header)
+ return -1;
+
+ return 0;
+
+}
+
+void __exit cleanup_arlan_proc(void)
+{
+ unregister_sysctl_table(arlan_device_sysctl_header);
+ arlan_device_sysctl_header = NULL;
+
+}
+#endif
diff --git a/drivers/net/wireless/arlan.h b/drivers/net/wireless/arlan.h
new file mode 100644
index 000000000000..70a6d7b83c4a
--- /dev/null
+++ b/drivers/net/wireless/arlan.h
@@ -0,0 +1,541 @@
+/*
+ * Copyright (C) 1997 Cullen Jennings
+ * Copyright (C) 1998 Elmer.Joandi@ut.ee, +37-255-13500
+ * GNU General Public License applies
+ */
+
+#include <linux/module.h>
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/skbuff.h>
+#include <linux/if_ether.h> /* For the statistics structure. */
+#include <linux/if_arp.h> /* For ARPHRD_ETHER */
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/in.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+
+#include <linux/init.h>
+#include <linux/bitops.h>
+#include <asm/system.h>
+#include <asm/io.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+
+
+//#define ARLAN_DEBUGGING 1
+
+#define ARLAN_PROC_INTERFACE
+#define MAX_ARLANS 4 /* not more than 4 ! */
+#define ARLAN_PROC_SHM_DUMP /* shows all card registers, makes driver way larger */
+
+#define ARLAN_MAX_MULTICAST_ADDRS 16
+#define ARLAN_RCV_CLEAN 0
+#define ARLAN_RCV_PROMISC 1
+#define ARLAN_RCV_CONTROL 2
+
+#ifdef CONFIG_PROC_FS
+extern int init_arlan_proc(void);
+extern void cleanup_arlan_proc(void);
+#else
+#define init_arlan_proc() ({ 0; })
+#define cleanup_arlan_proc() do { } while (0)
+#endif
+
+extern struct net_device *arlan_device[MAX_ARLANS];
+extern int arlan_debug;
+extern int arlan_entry_debug;
+extern int arlan_exit_debug;
+extern int testMemory;
+extern int arlan_command(struct net_device * dev, int command);
+
+#define SIDUNKNOWN -1
+#define radioNodeIdUNKNOWN -1
+#define irqUNKNOWN 0
+#define debugUNKNOWN 0
+#define testMemoryUNKNOWN 1
+#define spreadingCodeUNKNOWN 0
+#define channelNumberUNKNOWN 0
+#define channelSetUNKNOWN 0
+#define systemIdUNKNOWN -1
+#define registrationModeUNKNOWN -1
+
+
+#define IFDEBUG( L ) if ( (L) & arlan_debug )
+#define ARLAN_FAKE_HDR_LEN 12
+
+#ifdef ARLAN_DEBUGGING
+ #define DEBUG 1
+ #define ARLAN_ENTRY_EXIT_DEBUGGING 1
+ #define ARLAN_DEBUG(a,b) printk(KERN_DEBUG a, b)
+#else
+ #define ARLAN_DEBUG(a,b)
+#endif
+
+#define ARLAN_SHMEM_SIZE 0x2000
+
+struct arlan_shmem
+{
+ /* Header Signature */
+ volatile char textRegion[48];
+ volatile u_char resetFlag;
+ volatile u_char diagnosticInfo;
+ volatile u_short diagnosticOffset;
+ volatile u_char _1[12];
+ volatile u_char lanCardNodeId[6];
+ volatile u_char broadcastAddress[6];
+ volatile u_char hardwareType;
+ volatile u_char majorHardwareVersion;
+ volatile u_char minorHardwareVersion;
+ volatile u_char radioModule;// shows EEPROM, can be overridden at 0x111
+ volatile u_char defaultChannelSet; // shows EEProm, can be overriiden at 0x10A
+ volatile u_char _2[47];
+
+ /* Control/Status Block - 0x0080 */
+ volatile u_char interruptInProgress; /* not used by lancpu */
+ volatile u_char cntrlRegImage; /* not used by lancpu */
+ volatile u_char _3[13];
+ volatile u_char dumpByte;
+ volatile u_char commandByte; /* non-zero = active */
+ volatile u_char commandParameter[15];
+
+ /* Receive Status - 0x00a0 */
+ volatile u_char rxStatus; /* 1- data, 2-control, 0xff - registr change */
+ volatile u_char rxFrmType;
+ volatile u_short rxOffset;
+ volatile u_short rxLength;
+ volatile u_char rxSrc[6];
+ volatile u_char rxBroadcastFlag;
+ volatile u_char rxQuality;
+ volatile u_char scrambled;
+ volatile u_char _4[1];
+
+ /* Transmit Status - 0x00b0 */
+ volatile u_char txStatus;
+ volatile u_char txAckQuality;
+ volatile u_char numRetries;
+ volatile u_char _5[14];
+ volatile u_char registeredRouter[6];
+ volatile u_char backboneRouter[6];
+ volatile u_char registrationStatus;
+ volatile u_char configuredStatusFlag;
+ volatile u_char _6[1];
+ volatile u_char ultimateDestAddress[6];
+ volatile u_char immedDestAddress[6];
+ volatile u_char immedSrcAddress[6];
+ volatile u_short rxSequenceNumber;
+ volatile u_char assignedLocaltalkAddress;
+ volatile u_char _7[27];
+
+ /* System Parameter Block */
+
+ /* - Driver Parameters (Novell Specific) */
+
+ volatile u_short txTimeout;
+ volatile u_short transportTime;
+ volatile u_char _8[4];
+
+ /* - Configuration Parameters */
+ volatile u_char irqLevel;
+ volatile u_char spreadingCode;
+ volatile u_char channelSet;
+ volatile u_char channelNumber;
+ volatile u_short radioNodeId;
+ volatile u_char _9[2];
+ volatile u_char scramblingDisable;
+ volatile u_char radioType;
+ volatile u_short routerId;
+ volatile u_char _10[9];
+ volatile u_char txAttenuation;
+ volatile u_char systemId[4];
+ volatile u_short globalChecksum;
+ volatile u_char _11[4];
+ volatile u_short maxDatagramSize;
+ volatile u_short maxFrameSize;
+ volatile u_char maxRetries;
+ volatile u_char receiveMode;
+ volatile u_char priority;
+ volatile u_char rootOrRepeater;
+ volatile u_char specifiedRouter[6];
+ volatile u_short fastPollPeriod;
+ volatile u_char pollDecay;
+ volatile u_char fastPollDelay[2];
+ volatile u_char arlThreshold;
+ volatile u_char arlDecay;
+ volatile u_char _12[1];
+ volatile u_short specRouterTimeout;
+ volatile u_char _13[5];
+
+ /* Scrambled Area */
+ volatile u_char SID[4];
+ volatile u_char encryptionKey[12];
+ volatile u_char _14[2];
+ volatile u_char waitTime[2];
+ volatile u_char lParameter[2];
+ volatile u_char _15[3];
+ volatile u_short headerSize;
+ volatile u_short sectionChecksum;
+
+ volatile u_char registrationMode;
+ volatile u_char registrationFill;
+ volatile u_short pollPeriod;
+ volatile u_short refreshPeriod;
+ volatile u_char name[16];
+ volatile u_char NID[6];
+ volatile u_char localTalkAddress;
+ volatile u_char codeFormat;
+ volatile u_char numChannels;
+ volatile u_char channel1;
+ volatile u_char channel2;
+ volatile u_char channel3;
+ volatile u_char channel4;
+ volatile u_char SSCode[59];
+
+ volatile u_char _16[0xC0];
+ volatile u_short auxCmd;
+ volatile u_char dumpPtr[4];
+ volatile u_char dumpVal;
+ volatile u_char _17[0x6A];
+ volatile u_char wireTest;
+ volatile u_char _18[14];
+
+ /* Statistics Block - 0x0300 */
+ volatile u_char hostcpuLock;
+ volatile u_char lancpuLock;
+ volatile u_char resetTime[18];
+
+ volatile u_char numDatagramsTransmitted[4];
+ volatile u_char numReTransmissions[4];
+ volatile u_char numFramesDiscarded[4];
+ volatile u_char numDatagramsReceived[4];
+ volatile u_char numDuplicateReceivedFrames[4];
+ volatile u_char numDatagramsDiscarded[4];
+
+ volatile u_short maxNumReTransmitDatagram;
+ volatile u_short maxNumReTransmitFrames;
+ volatile u_short maxNumConsecutiveDuplicateFrames;
+ /* misaligned here so we have to go to characters */
+
+ volatile u_char numBytesTransmitted[4];
+ volatile u_char numBytesReceived[4];
+ volatile u_char numCRCErrors[4];
+ volatile u_char numLengthErrors[4];
+ volatile u_char numAbortErrors[4];
+ volatile u_char numTXUnderruns[4];
+ volatile u_char numRXOverruns[4];
+ volatile u_char numHoldOffs[4];
+ volatile u_char numFramesTransmitted[4];
+ volatile u_char numFramesReceived[4];
+ volatile u_char numReceiveFramesLost[4];
+ volatile u_char numRXBufferOverflows[4];
+ volatile u_char numFramesDiscardedAddrMismatch[4];
+ volatile u_char numFramesDiscardedSIDMismatch[4];
+ volatile u_char numPollsTransmistted[4];
+ volatile u_char numPollAcknowledges[4];
+ volatile u_char numStatusTimeouts[4];
+ volatile u_char numNACKReceived[4];
+
+ volatile u_char _19[0x86];
+
+ volatile u_char txBuffer[0x800];
+ volatile u_char rxBuffer[0x800];
+
+ volatile u_char _20[0x800];
+ volatile u_char _21[0x3fb];
+ volatile u_char configStatus;
+ volatile u_char _22;
+ volatile u_char progIOCtrl;
+ volatile u_char shareMBase;
+ volatile u_char controlRegister;
+};
+
+struct arlan_conf_stru {
+ int spreadingCode;
+ int channelSet;
+ int channelNumber;
+ int scramblingDisable;
+ int txAttenuation;
+ int systemId;
+ int maxDatagramSize;
+ int maxFrameSize;
+ int maxRetries;
+ int receiveMode;
+ int priority;
+ int rootOrRepeater;
+ int SID;
+ int radioNodeId;
+ int registrationMode;
+ int registrationFill;
+ int localTalkAddress;
+ int codeFormat;
+ int numChannels;
+ int channel1;
+ int channel2;
+ int channel3;
+ int channel4;
+ int txClear;
+ int txRetries;
+ int txRouting;
+ int txScrambled;
+ int rxParameter;
+ int txTimeoutMs;
+ int txAckTimeoutMs;
+ int waitCardTimeout;
+ int waitTime;
+ int lParameter;
+ int _15;
+ int headerSize;
+ int retries;
+ int tx_delay_ms;
+ int waitReTransmitPacketMaxSize;
+ int ReTransmitPacketMaxSize;
+ int fastReTransCount;
+ int driverRetransmissions;
+ int registrationInterrupts;
+ int hardwareType;
+ int radioType;
+ int writeRadioType;
+ int writeEEPROM;
+ char siteName[17];
+ int measure_rate;
+ int in_speed;
+ int out_speed;
+ int in_speed10;
+ int out_speed10;
+ int in_speed_max;
+ int out_speed_max;
+ int pre_Command_Wait;
+ int rx_tweak1;
+ int rx_tweak2;
+ int tx_queue_len;
+};
+
+extern struct arlan_conf_stru arlan_conf[MAX_ARLANS];
+
+struct TxParam
+{
+ volatile short offset;
+ volatile short length;
+ volatile u_char dest[6];
+ volatile unsigned char clear;
+ volatile unsigned char retries;
+ volatile unsigned char routing;
+ volatile unsigned char scrambled;
+};
+
+#define TX_RING_SIZE 2
+/* Information that need to be kept for each board. */
+struct arlan_private {
+ struct net_device_stats stats;
+ struct arlan_shmem __iomem * card;
+ struct arlan_shmem * conf;
+
+ struct arlan_conf_stru * Conf;
+ int bad;
+ int reset;
+ unsigned long lastReset;
+ struct timer_list timer;
+ struct timer_list tx_delay_timer;
+ struct timer_list tx_retry_timer;
+ struct timer_list rx_check_timer;
+
+ int registrationLostCount;
+ int reRegisterExp;
+ int irq_test_done;
+
+ struct TxParam txRing[TX_RING_SIZE];
+ char reTransmitBuff[0x800];
+ int txLast;
+ unsigned ReTransmitRequested;
+ unsigned long tx_done_delayed;
+ unsigned long registrationLastSeen;
+
+ unsigned long tx_last_sent;
+ unsigned long tx_last_cleared;
+ unsigned long retransmissions;
+ unsigned long interrupt_ack_requested;
+ spinlock_t lock;
+ unsigned long waiting_command_mask;
+ unsigned long card_polling_interval;
+ unsigned long last_command_buff_free_time;
+
+ int under_reset;
+ int under_config;
+ int rx_command_given;
+ int tx_command_given;
+ unsigned long interrupt_processing_active;
+ unsigned long last_rx_int_ack_time;
+ unsigned long in_bytes;
+ unsigned long out_bytes;
+ unsigned long in_time;
+ unsigned long out_time;
+ unsigned long in_time10;
+ unsigned long out_time10;
+ unsigned long in_bytes10;
+ unsigned long out_bytes10;
+ int init_etherdev_alloc;
+};
+
+
+
+#define ARLAN_CLEAR 0x00
+#define ARLAN_RESET 0x01
+#define ARLAN_CHANNEL_ATTENTION 0x02
+#define ARLAN_INTERRUPT_ENABLE 0x04
+#define ARLAN_CLEAR_INTERRUPT 0x08
+#define ARLAN_POWER 0x40
+#define ARLAN_ACCESS 0x80
+
+#define ARLAN_COM_CONF 0x01
+#define ARLAN_COM_RX_ENABLE 0x03
+#define ARLAN_COM_RX_ABORT 0x04
+#define ARLAN_COM_TX_ENABLE 0x05
+#define ARLAN_COM_TX_ABORT 0x06
+#define ARLAN_COM_NOP 0x07
+#define ARLAN_COM_STANDBY 0x08
+#define ARLAN_COM_ACTIVATE 0x09
+#define ARLAN_COM_GOTO_SLOW_POLL 0x0a
+#define ARLAN_COM_INT 0x80
+
+
+#define TXLAST(dev) (((struct arlan_private *)netdev_priv(dev))->txRing[((struct arlan_private *)netdev_priv(dev))->txLast])
+#define TXHEAD(dev) (((struct arlan_private *)netdev_priv(dev))->txRing[0])
+#define TXTAIL(dev) (((struct arlan_private *)netdev_priv(dev))->txRing[1])
+
+#define TXBuffStart(dev) offsetof(struct arlan_shmem, txBuffer)
+#define TXBuffEnd(dev) offsetof(struct arlan_shmem, xxBuffer)
+
+#define READSHM(to,from,atype) {\
+ atype tmp;\
+ memcpy_fromio(&(tmp),&(from),sizeof(atype));\
+ to = tmp;\
+ }
+
+#define READSHMEM(from,atype)\
+ atype from; \
+ READSHM(from, arlan->from, atype);
+
+#define WRITESHM(to,from,atype) \
+ { atype tmpSHM = from;\
+ memcpy_toio(&(to),&tmpSHM,sizeof(atype));\
+ }
+
+#define DEBUGSHM(levelSHM,stringSHM,stuff,atype) \
+ { atype tmpSHM; \
+ memcpy_fromio(&tmpSHM,&(stuff),sizeof(atype));\
+ IFDEBUG(levelSHM) printk(stringSHM,tmpSHM);\
+ }
+
+#define WRITESHMB(to, val) \
+ writeb(val,&(to))
+#define READSHMB(to) \
+ readb(&(to))
+#define WRITESHMS(to, val) \
+ writew(val,&(to))
+#define READSHMS(to) \
+ readw(&(to))
+#define WRITESHMI(to, val) \
+ writel(val,&(to))
+#define READSHMI(to) \
+ readl(&(to))
+
+
+
+
+
+#define registrationBad(dev)\
+ ( ( READSHMB(((struct arlan_private *)netdev_priv(dev))->card->registrationMode) > 0) && \
+ ( READSHMB(((struct arlan_private *)netdev_priv(dev))->card->registrationStatus) == 0) )
+
+
+#define readControlRegister(dev)\
+ READSHMB(((struct arlan_private *)netdev_priv(dev))->card->cntrlRegImage)
+
+#define writeControlRegister(dev, v){\
+ WRITESHMB(((struct arlan_private *)netdev_priv(dev))->card->cntrlRegImage ,((v) &0xF) );\
+ WRITESHMB(((struct arlan_private *)netdev_priv(dev))->card->controlRegister ,(v) );}
+
+
+#define arlan_interrupt_lancpu(dev) {\
+ int cr; \
+ \
+ cr = readControlRegister(dev);\
+ if (cr & ARLAN_CHANNEL_ATTENTION){ \
+ writeControlRegister(dev, (cr & ~ARLAN_CHANNEL_ATTENTION));\
+ }else \
+ writeControlRegister(dev, (cr | ARLAN_CHANNEL_ATTENTION));\
+}
+
+#define clearChannelAttention(dev){ \
+ writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_CHANNEL_ATTENTION);}
+#define setHardwareReset(dev) {\
+ writeControlRegister(dev,readControlRegister(dev) | ARLAN_RESET);}
+#define clearHardwareReset(dev) {\
+ writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_RESET);}
+#define setInterruptEnable(dev){\
+ writeControlRegister(dev,readControlRegister(dev) | ARLAN_INTERRUPT_ENABLE) ;}
+#define clearInterruptEnable(dev){\
+ writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_INTERRUPT_ENABLE) ;}
+#define setClearInterrupt(dev){\
+ writeControlRegister(dev,readControlRegister(dev) | ARLAN_CLEAR_INTERRUPT) ;}
+#define clearClearInterrupt(dev){\
+ writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_CLEAR_INTERRUPT);}
+#define setPowerOff(dev){\
+ writeControlRegister(dev,readControlRegister(dev) | (ARLAN_POWER && ARLAN_ACCESS));\
+ writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_ACCESS);}
+#define setPowerOn(dev){\
+ writeControlRegister(dev,readControlRegister(dev) & ~(ARLAN_POWER)); }
+#define arlan_lock_card_access(dev){\
+ writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_ACCESS);}
+#define arlan_unlock_card_access(dev){\
+ writeControlRegister(dev,readControlRegister(dev) | ARLAN_ACCESS ); }
+
+
+
+
+#define ARLAN_COMMAND_RX 0x000001
+#define ARLAN_COMMAND_NOOP 0x000002
+#define ARLAN_COMMAND_NOOPINT 0x000004
+#define ARLAN_COMMAND_TX 0x000008
+#define ARLAN_COMMAND_CONF 0x000010
+#define ARLAN_COMMAND_RESET 0x000020
+#define ARLAN_COMMAND_TX_ABORT 0x000040
+#define ARLAN_COMMAND_RX_ABORT 0x000080
+#define ARLAN_COMMAND_POWERDOWN 0x000100
+#define ARLAN_COMMAND_POWERUP 0x000200
+#define ARLAN_COMMAND_SLOW_POLL 0x000400
+#define ARLAN_COMMAND_ACTIVATE 0x000800
+#define ARLAN_COMMAND_INT_ACK 0x001000
+#define ARLAN_COMMAND_INT_ENABLE 0x002000
+#define ARLAN_COMMAND_WAIT_NOW 0x004000
+#define ARLAN_COMMAND_LONG_WAIT_NOW 0x008000
+#define ARLAN_COMMAND_STANDBY 0x010000
+#define ARLAN_COMMAND_INT_RACK 0x020000
+#define ARLAN_COMMAND_INT_RENABLE 0x040000
+#define ARLAN_COMMAND_CONF_WAIT 0x080000
+#define ARLAN_COMMAND_TBUSY_CLEAR 0x100000
+#define ARLAN_COMMAND_CLEAN_AND_CONF (ARLAN_COMMAND_TX_ABORT\
+ | ARLAN_COMMAND_RX_ABORT\
+ | ARLAN_COMMAND_CONF)
+#define ARLAN_COMMAND_CLEAN_AND_RESET (ARLAN_COMMAND_TX_ABORT\
+ | ARLAN_COMMAND_RX_ABORT\
+ | ARLAN_COMMAND_RESET)
+
+
+
+#define ARLAN_DEBUG_CHAIN_LOCKS 0x00001
+#define ARLAN_DEBUG_RESET 0x00002
+#define ARLAN_DEBUG_TIMING 0x00004
+#define ARLAN_DEBUG_CARD_STATE 0x00008
+#define ARLAN_DEBUG_TX_CHAIN 0x00010
+#define ARLAN_DEBUG_MULTICAST 0x00020
+#define ARLAN_DEBUG_HEADER_DUMP 0x00040
+#define ARLAN_DEBUG_INTERRUPT 0x00080
+#define ARLAN_DEBUG_STARTUP 0x00100
+#define ARLAN_DEBUG_SHUTDOWN 0x00200
+
diff --git a/drivers/net/wireless/atmel.c b/drivers/net/wireless/atmel.c
new file mode 100644
index 000000000000..18a7d38d2a13
--- /dev/null
+++ b/drivers/net/wireless/atmel.c
@@ -0,0 +1,4272 @@
+/*** -*- linux-c -*- **********************************************************
+
+ Driver for Atmel at76c502 at76c504 and at76c506 wireless cards.
+
+ Copyright 2000-2001 ATMEL Corporation.
+ Copyright 2003-2004 Simon Kelley.
+
+ This code was developed from version 2.1.1 of the Atmel drivers,
+ released by Atmel corp. under the GPL in December 2002. It also
+ includes code from the Linux aironet drivers (C) Benjamin Reed,
+ and the Linux PCMCIA package, (C) David Hinds and the Linux wireless
+ extensions, (C) Jean Tourrilhes.
+
+ The firmware module for reading the MAC address of the card comes from
+ net.russotto.AtmelMACFW, written by Matthew T. Russotto and copyright
+ by him. net.russotto.AtmelMACFW is used under the GPL license version 2.
+ This file contains the module in binary form and, under the terms
+ of the GPL, in source form. The source is located at the end of the file.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Atmel wireless lan drivers; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ For all queries about this code, please contact the current author,
+ Simon Kelley <simon@thekelleys.org.uk> and not Atmel Corporation.
+
+ Credit is due to HP UK and Cambridge Online Systems Ltd for supplying
+ hardware used during development of this driver.
+
+******************************************************************************/
+
+#include <linux/config.h>
+#include <linux/init.h>
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/ctype.h>
+#include <linux/timer.h>
+#include <asm/io.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/skbuff.h>
+#include <linux/if_arp.h>
+#include <linux/ioport.h>
+#include <linux/fcntl.h>
+#include <linux/delay.h>
+#include <linux/wireless.h>
+#include <net/iw_handler.h>
+#include <linux/byteorder/generic.h>
+#include <linux/crc32.h>
+#include <linux/proc_fs.h>
+#include <linux/device.h>
+#include <linux/moduleparam.h>
+#include <linux/firmware.h>
+#include "ieee802_11.h"
+#include "atmel.h"
+
+#define DRIVER_MAJOR 0
+#define DRIVER_MINOR 96
+
+MODULE_AUTHOR("Simon Kelley");
+MODULE_DESCRIPTION("Support for Atmel at76c50x 802.11 wireless ethernet cards.");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("Atmel at76c50x wireless cards");
+
+/* The name of the firmware file to be loaded
+ over-rides any automatic selection */
+static char *firmware = NULL;
+module_param(firmware, charp, 0);
+
+/* table of firmware file names */
+static struct {
+ AtmelFWType fw_type;
+ const char *fw_file;
+ const char *fw_file_ext;
+} fw_table[] = {
+ { ATMEL_FW_TYPE_502, "atmel_at76c502", "bin" },
+ { ATMEL_FW_TYPE_502D, "atmel_at76c502d", "bin" },
+ { ATMEL_FW_TYPE_502E, "atmel_at76c502e", "bin" },
+ { ATMEL_FW_TYPE_502_3COM, "atmel_at76c502_3com", "bin" },
+ { ATMEL_FW_TYPE_504, "atmel_at76c504", "bin" },
+ { ATMEL_FW_TYPE_504_2958, "atmel_at76c504_2958", "bin" },
+ { ATMEL_FW_TYPE_504A_2958,"atmel_at76c504a_2958","bin" },
+ { ATMEL_FW_TYPE_506, "atmel_at76c506", "bin" },
+ { ATMEL_FW_TYPE_NONE, NULL, NULL }
+};
+
+#define MAX_SSID_LENGTH 32
+#define MGMT_JIFFIES (256 * HZ / 100)
+
+#define MAX_BSS_ENTRIES 64
+
+/* registers */
+#define GCR 0x00 // (SIR0) General Configuration Register
+#define BSR 0x02 // (SIR1) Bank Switching Select Register
+#define AR 0x04
+#define DR 0x08
+#define MR1 0x12 // Mirror Register 1
+#define MR2 0x14 // Mirror Register 2
+#define MR3 0x16 // Mirror Register 3
+#define MR4 0x18 // Mirror Register 4
+
+#define GPR1 0x0c
+#define GPR2 0x0e
+#define GPR3 0x10
+//
+// Constants for the GCR register.
+//
+#define GCR_REMAP 0x0400 // Remap internal SRAM to 0
+#define GCR_SWRES 0x0080 // BIU reset (ARM and PAI are NOT reset)
+#define GCR_CORES 0x0060 // Core Reset (ARM and PAI are reset)
+#define GCR_ENINT 0x0002 // Enable Interrupts
+#define GCR_ACKINT 0x0008 // Acknowledge Interrupts
+
+#define BSS_SRAM 0x0200 // AMBA module selection --> SRAM
+#define BSS_IRAM 0x0100 // AMBA module selection --> IRAM
+//
+// Constants for the MR registers.
+//
+#define MAC_INIT_COMPLETE 0x0001 // MAC init has been completed
+#define MAC_BOOT_COMPLETE 0x0010 // MAC boot has been completed
+#define MAC_INIT_OK 0x0002 // MAC boot has been completed
+
+#define C80211_SUBTYPE_MGMT_ASS_REQUEST 0x00
+#define C80211_SUBTYPE_MGMT_ASS_RESPONSE 0x10
+#define C80211_SUBTYPE_MGMT_REASS_REQUEST 0x20
+#define C80211_SUBTYPE_MGMT_REASS_RESPONSE 0x30
+#define C80211_SUBTYPE_MGMT_ProbeRequest 0x40
+#define C80211_SUBTYPE_MGMT_ProbeResponse 0x50
+#define C80211_SUBTYPE_MGMT_BEACON 0x80
+#define C80211_SUBTYPE_MGMT_ATIM 0x90
+#define C80211_SUBTYPE_MGMT_DISASSOSIATION 0xA0
+#define C80211_SUBTYPE_MGMT_Authentication 0xB0
+#define C80211_SUBTYPE_MGMT_Deauthentication 0xC0
+
+#define C80211_MGMT_AAN_OPENSYSTEM 0x0000
+#define C80211_MGMT_AAN_SHAREDKEY 0x0001
+
+#define C80211_MGMT_CAPABILITY_ESS 0x0001 // see 802.11 p.58
+#define C80211_MGMT_CAPABILITY_IBSS 0x0002 // - " -
+#define C80211_MGMT_CAPABILITY_CFPollable 0x0004 // - " -
+#define C80211_MGMT_CAPABILITY_CFPollRequest 0x0008 // - " -
+#define C80211_MGMT_CAPABILITY_Privacy 0x0010 // - " -
+
+#define C80211_MGMT_SC_Success 0
+#define C80211_MGMT_SC_Unspecified 1
+#define C80211_MGMT_SC_SupportCapabilities 10
+#define C80211_MGMT_SC_ReassDenied 11
+#define C80211_MGMT_SC_AssDenied 12
+#define C80211_MGMT_SC_AuthAlgNotSupported 13
+#define C80211_MGMT_SC_AuthTransSeqNumError 14
+#define C80211_MGMT_SC_AuthRejectChallenge 15
+#define C80211_MGMT_SC_AuthRejectTimeout 16
+#define C80211_MGMT_SC_AssDeniedHandleAP 17
+#define C80211_MGMT_SC_AssDeniedBSSRate 18
+
+#define C80211_MGMT_ElementID_SSID 0
+#define C80211_MGMT_ElementID_SupportedRates 1
+#define C80211_MGMT_ElementID_ChallengeText 16
+#define C80211_MGMT_CAPABILITY_ShortPreamble 0x0020
+
+#define MIB_MAX_DATA_BYTES 212
+#define MIB_HEADER_SIZE 4 /* first four fields */
+
+struct get_set_mib {
+ u8 type;
+ u8 size;
+ u8 index;
+ u8 reserved;
+ u8 data[MIB_MAX_DATA_BYTES];
+};
+
+struct rx_desc {
+ u32 Next;
+ u16 MsduPos;
+ u16 MsduSize;
+
+ u8 State;
+ u8 Status;
+ u8 Rate;
+ u8 Rssi;
+ u8 LinkQuality;
+ u8 PreambleType;
+ u16 Duration;
+ u32 RxTime;
+
+};
+
+#define RX_DESC_FLAG_VALID 0x80
+#define RX_DESC_FLAG_CONSUMED 0x40
+#define RX_DESC_FLAG_IDLE 0x00
+
+#define RX_STATUS_SUCCESS 0x00
+
+#define RX_DESC_MSDU_POS_OFFSET 4
+#define RX_DESC_MSDU_SIZE_OFFSET 6
+#define RX_DESC_FLAGS_OFFSET 8
+#define RX_DESC_STATUS_OFFSET 9
+#define RX_DESC_RSSI_OFFSET 11
+#define RX_DESC_LINK_QUALITY_OFFSET 12
+#define RX_DESC_PREAMBLE_TYPE_OFFSET 13
+#define RX_DESC_DURATION_OFFSET 14
+#define RX_DESC_RX_TIME_OFFSET 16
+
+
+struct tx_desc {
+ u32 NextDescriptor;
+ u16 TxStartOfFrame;
+ u16 TxLength;
+
+ u8 TxState;
+ u8 TxStatus;
+ u8 RetryCount;
+
+ u8 TxRate;
+
+ u8 KeyIndex;
+ u8 ChiperType;
+ u8 ChipreLength;
+ u8 Reserved1;
+
+ u8 Reserved;
+ u8 PacketType;
+ u16 HostTxLength;
+
+};
+
+
+#define TX_DESC_NEXT_OFFSET 0
+#define TX_DESC_POS_OFFSET 4
+#define TX_DESC_SIZE_OFFSET 6
+#define TX_DESC_FLAGS_OFFSET 8
+#define TX_DESC_STATUS_OFFSET 9
+#define TX_DESC_RETRY_OFFSET 10
+#define TX_DESC_RATE_OFFSET 11
+#define TX_DESC_KEY_INDEX_OFFSET 12
+#define TX_DESC_CIPHER_TYPE_OFFSET 13
+#define TX_DESC_CIPHER_LENGTH_OFFSET 14
+#define TX_DESC_PACKET_TYPE_OFFSET 17
+#define TX_DESC_HOST_LENGTH_OFFSET 18
+
+
+
+///////////////////////////////////////////////////////
+// Host-MAC interface
+///////////////////////////////////////////////////////
+
+#define TX_STATUS_SUCCESS 0x00
+
+#define TX_FIRM_OWN 0x80
+#define TX_DONE 0x40
+
+
+#define TX_ERROR 0x01
+
+#define TX_PACKET_TYPE_DATA 0x01
+#define TX_PACKET_TYPE_MGMT 0x02
+
+#define ISR_EMPTY 0x00 // no bits set in ISR
+#define ISR_TxCOMPLETE 0x01 // packet transmitted
+#define ISR_RxCOMPLETE 0x02 // packet received
+#define ISR_RxFRAMELOST 0x04 // Rx Frame lost
+#define ISR_FATAL_ERROR 0x08 // Fatal error
+#define ISR_COMMAND_COMPLETE 0x10 // command completed
+#define ISR_OUT_OF_RANGE 0x20 // command completed
+#define ISR_IBSS_MERGE 0x40 // (4.1.2.30): IBSS merge
+#define ISR_GENERIC_IRQ 0x80
+
+
+#define Local_Mib_Type 0x01
+#define Mac_Address_Mib_Type 0x02
+#define Mac_Mib_Type 0x03
+#define Statistics_Mib_Type 0x04
+#define Mac_Mgmt_Mib_Type 0x05
+#define Mac_Wep_Mib_Type 0x06
+#define Phy_Mib_Type 0x07
+#define Multi_Domain_MIB 0x08
+
+#define MAC_MGMT_MIB_CUR_BSSID_POS 14
+#define MAC_MIB_FRAG_THRESHOLD_POS 8
+#define MAC_MIB_RTS_THRESHOLD_POS 10
+#define MAC_MIB_SHORT_RETRY_POS 16
+#define MAC_MIB_LONG_RETRY_POS 17
+#define MAC_MIB_SHORT_RETRY_LIMIT_POS 16
+#define MAC_MGMT_MIB_BEACON_PER_POS 0
+#define MAC_MGMT_MIB_STATION_ID_POS 6
+#define MAC_MGMT_MIB_CUR_PRIVACY_POS 11
+#define MAC_MGMT_MIB_CUR_BSSID_POS 14
+#define MAC_MGMT_MIB_PS_MODE_POS 53
+#define MAC_MGMT_MIB_LISTEN_INTERVAL_POS 54
+#define MAC_MGMT_MIB_MULTI_DOMAIN_IMPLEMENTED 56
+#define MAC_MGMT_MIB_MULTI_DOMAIN_ENABLED 57
+#define PHY_MIB_CHANNEL_POS 14
+#define PHY_MIB_RATE_SET_POS 20
+#define PHY_MIB_REG_DOMAIN_POS 26
+#define LOCAL_MIB_AUTO_TX_RATE_POS 3
+#define LOCAL_MIB_SSID_SIZE 5
+#define LOCAL_MIB_TX_PROMISCUOUS_POS 6
+#define LOCAL_MIB_TX_MGMT_RATE_POS 7
+#define LOCAL_MIB_TX_CONTROL_RATE_POS 8
+#define LOCAL_MIB_PREAMBLE_TYPE 9
+#define MAC_ADDR_MIB_MAC_ADDR_POS 0
+
+
+#define CMD_Set_MIB_Vars 0x01
+#define CMD_Get_MIB_Vars 0x02
+#define CMD_Scan 0x03
+#define CMD_Join 0x04
+#define CMD_Start 0x05
+#define CMD_EnableRadio 0x06
+#define CMD_DisableRadio 0x07
+#define CMD_SiteSurvey 0x0B
+
+#define CMD_STATUS_IDLE 0x00
+#define CMD_STATUS_COMPLETE 0x01
+#define CMD_STATUS_UNKNOWN 0x02
+#define CMD_STATUS_INVALID_PARAMETER 0x03
+#define CMD_STATUS_FUNCTION_NOT_SUPPORTED 0x04
+#define CMD_STATUS_TIME_OUT 0x07
+#define CMD_STATUS_IN_PROGRESS 0x08
+#define CMD_STATUS_REJECTED_RADIO_OFF 0x09
+#define CMD_STATUS_HOST_ERROR 0xFF
+#define CMD_STATUS_BUSY 0xFE
+
+
+#define CMD_BLOCK_COMMAND_OFFSET 0
+#define CMD_BLOCK_STATUS_OFFSET 1
+#define CMD_BLOCK_PARAMETERS_OFFSET 4
+
+#define SCAN_OPTIONS_SITE_SURVEY 0x80
+
+#define MGMT_FRAME_BODY_OFFSET 24
+#define MAX_AUTHENTICATION_RETRIES 3
+#define MAX_ASSOCIATION_RETRIES 3
+
+#define AUTHENTICATION_RESPONSE_TIME_OUT 1000
+
+#define MAX_WIRELESS_BODY 2316 /* mtu is 2312, CRC is 4 */
+#define LOOP_RETRY_LIMIT 500000
+
+#define ACTIVE_MODE 1
+#define PS_MODE 2
+
+#define MAX_ENCRYPTION_KEYS 4
+#define MAX_ENCRYPTION_KEY_SIZE 40
+
+///////////////////////////////////////////////////////////////////////////
+// 802.11 related definitions
+///////////////////////////////////////////////////////////////////////////
+
+//
+// Regulatory Domains
+//
+
+#define REG_DOMAIN_FCC 0x10 //Channels 1-11 USA
+#define REG_DOMAIN_DOC 0x20 //Channel 1-11 Canada
+#define REG_DOMAIN_ETSI 0x30 //Channel 1-13 Europe (ex Spain/France)
+#define REG_DOMAIN_SPAIN 0x31 //Channel 10-11 Spain
+#define REG_DOMAIN_FRANCE 0x32 //Channel 10-13 France
+#define REG_DOMAIN_MKK 0x40 //Channel 14 Japan
+#define REG_DOMAIN_MKK1 0x41 //Channel 1-14 Japan(MKK1)
+#define REG_DOMAIN_ISRAEL 0x50 //Channel 3-9 ISRAEL
+
+#define BSS_TYPE_AD_HOC 1
+#define BSS_TYPE_INFRASTRUCTURE 2
+
+#define SCAN_TYPE_ACTIVE 0
+#define SCAN_TYPE_PASSIVE 1
+
+#define LONG_PREAMBLE 0
+#define SHORT_PREAMBLE 1
+#define AUTO_PREAMBLE 2
+
+#define DATA_FRAME_WS_HEADER_SIZE 30
+
+/* promiscuous mode control */
+#define PROM_MODE_OFF 0x0
+#define PROM_MODE_UNKNOWN 0x1
+#define PROM_MODE_CRC_FAILED 0x2
+#define PROM_MODE_DUPLICATED 0x4
+#define PROM_MODE_MGMT 0x8
+#define PROM_MODE_CTRL 0x10
+#define PROM_MODE_BAD_PROTOCOL 0x20
+
+
+#define IFACE_INT_STATUS_OFFSET 0
+#define IFACE_INT_MASK_OFFSET 1
+#define IFACE_LOCKOUT_HOST_OFFSET 2
+#define IFACE_LOCKOUT_MAC_OFFSET 3
+#define IFACE_FUNC_CTRL_OFFSET 28
+#define IFACE_MAC_STAT_OFFSET 30
+#define IFACE_GENERIC_INT_TYPE_OFFSET 32
+
+#define CIPHER_SUITE_NONE 0
+#define CIPHER_SUITE_WEP_64 1
+#define CIPHER_SUITE_TKIP 2
+#define CIPHER_SUITE_AES 3
+#define CIPHER_SUITE_CCX 4
+#define CIPHER_SUITE_WEP_128 5
+
+//
+// IFACE MACROS & definitions
+//
+//
+
+// FuncCtrl field:
+//
+#define FUNC_CTRL_TxENABLE 0x10
+#define FUNC_CTRL_RxENABLE 0x20
+#define FUNC_CTRL_INIT_COMPLETE 0x01
+
+/* A stub firmware image which reads the MAC address from NVRAM on the card.
+ For copyright information and source see the end of this file. */
+static u8 mac_reader[] = {
+ 0x06,0x00,0x00,0xea,0x04,0x00,0x00,0xea,0x03,0x00,0x00,0xea,0x02,0x00,0x00,0xea,
+ 0x01,0x00,0x00,0xea,0x00,0x00,0x00,0xea,0xff,0xff,0xff,0xea,0xfe,0xff,0xff,0xea,
+ 0xd3,0x00,0xa0,0xe3,0x00,0xf0,0x21,0xe1,0x0e,0x04,0xa0,0xe3,0x00,0x10,0xa0,0xe3,
+ 0x81,0x11,0xa0,0xe1,0x00,0x10,0x81,0xe3,0x00,0x10,0x80,0xe5,0x1c,0x10,0x90,0xe5,
+ 0x10,0x10,0xc1,0xe3,0x1c,0x10,0x80,0xe5,0x01,0x10,0xa0,0xe3,0x08,0x10,0x80,0xe5,
+ 0x02,0x03,0xa0,0xe3,0x00,0x10,0xa0,0xe3,0xb0,0x10,0xc0,0xe1,0xb4,0x10,0xc0,0xe1,
+ 0xb8,0x10,0xc0,0xe1,0xbc,0x10,0xc0,0xe1,0x56,0xdc,0xa0,0xe3,0x21,0x00,0x00,0xeb,
+ 0x0a,0x00,0xa0,0xe3,0x1a,0x00,0x00,0xeb,0x10,0x00,0x00,0xeb,0x07,0x00,0x00,0xeb,
+ 0x02,0x03,0xa0,0xe3,0x02,0x14,0xa0,0xe3,0xb4,0x10,0xc0,0xe1,0x4c,0x10,0x9f,0xe5,
+ 0xbc,0x10,0xc0,0xe1,0x10,0x10,0xa0,0xe3,0xb8,0x10,0xc0,0xe1,0xfe,0xff,0xff,0xea,
+ 0x00,0x40,0x2d,0xe9,0x00,0x20,0xa0,0xe3,0x02,0x3c,0xa0,0xe3,0x00,0x10,0xa0,0xe3,
+ 0x28,0x00,0x9f,0xe5,0x37,0x00,0x00,0xeb,0x00,0x40,0xbd,0xe8,0x1e,0xff,0x2f,0xe1,
+ 0x00,0x40,0x2d,0xe9,0x12,0x2e,0xa0,0xe3,0x06,0x30,0xa0,0xe3,0x00,0x10,0xa0,0xe3,
+ 0x02,0x04,0xa0,0xe3,0x2f,0x00,0x00,0xeb,0x00,0x40,0xbd,0xe8,0x1e,0xff,0x2f,0xe1,
+ 0x00,0x02,0x00,0x02,0x80,0x01,0x90,0xe0,0x01,0x00,0x00,0x0a,0x01,0x00,0x50,0xe2,
+ 0xfc,0xff,0xff,0xea,0x1e,0xff,0x2f,0xe1,0x80,0x10,0xa0,0xe3,0xf3,0x06,0xa0,0xe3,
+ 0x00,0x10,0x80,0xe5,0x00,0x10,0xa0,0xe3,0x00,0x10,0x80,0xe5,0x01,0x10,0xa0,0xe3,
+ 0x04,0x10,0x80,0xe5,0x00,0x10,0x80,0xe5,0x0e,0x34,0xa0,0xe3,0x1c,0x10,0x93,0xe5,
+ 0x02,0x1a,0x81,0xe3,0x1c,0x10,0x83,0xe5,0x58,0x11,0x9f,0xe5,0x30,0x10,0x80,0xe5,
+ 0x54,0x11,0x9f,0xe5,0x34,0x10,0x80,0xe5,0x38,0x10,0x80,0xe5,0x3c,0x10,0x80,0xe5,
+ 0x10,0x10,0x90,0xe5,0x08,0x00,0x90,0xe5,0x1e,0xff,0x2f,0xe1,0xf3,0x16,0xa0,0xe3,
+ 0x08,0x00,0x91,0xe5,0x05,0x00,0xa0,0xe3,0x0c,0x00,0x81,0xe5,0x10,0x00,0x91,0xe5,
+ 0x02,0x00,0x10,0xe3,0xfc,0xff,0xff,0x0a,0xff,0x00,0xa0,0xe3,0x0c,0x00,0x81,0xe5,
+ 0x10,0x00,0x91,0xe5,0x02,0x00,0x10,0xe3,0xfc,0xff,0xff,0x0a,0x08,0x00,0x91,0xe5,
+ 0x10,0x00,0x91,0xe5,0x01,0x00,0x10,0xe3,0xfc,0xff,0xff,0x0a,0x08,0x00,0x91,0xe5,
+ 0xff,0x00,0x00,0xe2,0x1e,0xff,0x2f,0xe1,0x30,0x40,0x2d,0xe9,0x00,0x50,0xa0,0xe1,
+ 0x03,0x40,0xa0,0xe1,0xa2,0x02,0xa0,0xe1,0x08,0x00,0x00,0xe2,0x03,0x00,0x80,0xe2,
+ 0xd8,0x10,0x9f,0xe5,0x00,0x00,0xc1,0xe5,0x01,0x20,0xc1,0xe5,0xe2,0xff,0xff,0xeb,
+ 0x01,0x00,0x10,0xe3,0xfc,0xff,0xff,0x1a,0x14,0x00,0xa0,0xe3,0xc4,0xff,0xff,0xeb,
+ 0x04,0x20,0xa0,0xe1,0x05,0x10,0xa0,0xe1,0x02,0x00,0xa0,0xe3,0x01,0x00,0x00,0xeb,
+ 0x30,0x40,0xbd,0xe8,0x1e,0xff,0x2f,0xe1,0x70,0x40,0x2d,0xe9,0xf3,0x46,0xa0,0xe3,
+ 0x00,0x30,0xa0,0xe3,0x00,0x00,0x50,0xe3,0x08,0x00,0x00,0x9a,0x8c,0x50,0x9f,0xe5,
+ 0x03,0x60,0xd5,0xe7,0x0c,0x60,0x84,0xe5,0x10,0x60,0x94,0xe5,0x02,0x00,0x16,0xe3,
+ 0xfc,0xff,0xff,0x0a,0x01,0x30,0x83,0xe2,0x00,0x00,0x53,0xe1,0xf7,0xff,0xff,0x3a,
+ 0xff,0x30,0xa0,0xe3,0x0c,0x30,0x84,0xe5,0x08,0x00,0x94,0xe5,0x10,0x00,0x94,0xe5,
+ 0x01,0x00,0x10,0xe3,0xfc,0xff,0xff,0x0a,0x08,0x00,0x94,0xe5,0x00,0x00,0xa0,0xe3,
+ 0x00,0x00,0x52,0xe3,0x0b,0x00,0x00,0x9a,0x10,0x50,0x94,0xe5,0x02,0x00,0x15,0xe3,
+ 0xfc,0xff,0xff,0x0a,0x0c,0x30,0x84,0xe5,0x10,0x50,0x94,0xe5,0x01,0x00,0x15,0xe3,
+ 0xfc,0xff,0xff,0x0a,0x08,0x50,0x94,0xe5,0x01,0x50,0xc1,0xe4,0x01,0x00,0x80,0xe2,
+ 0x02,0x00,0x50,0xe1,0xf3,0xff,0xff,0x3a,0xc8,0x00,0xa0,0xe3,0x98,0xff,0xff,0xeb,
+ 0x70,0x40,0xbd,0xe8,0x1e,0xff,0x2f,0xe1,0x01,0x0c,0x00,0x02,0x01,0x02,0x00,0x02,
+ 0x00,0x01,0x00,0x02
+};
+
+struct atmel_private {
+ void *card; /* Bus dependent stucture varies for PCcard */
+ int (*present_callback)(void *); /* And callback which uses it */
+ char firmware_id[32];
+ AtmelFWType firmware_type;
+ u8 *firmware;
+ int firmware_length;
+ struct timer_list management_timer;
+ struct net_device *dev;
+ struct device *sys_dev;
+ struct iw_statistics wstats;
+ struct net_device_stats stats; // device stats
+ spinlock_t irqlock, timerlock; // spinlocks
+ enum { BUS_TYPE_PCCARD, BUS_TYPE_PCI } bus_type;
+ enum {
+ CARD_TYPE_PARALLEL_FLASH,
+ CARD_TYPE_SPI_FLASH,
+ CARD_TYPE_EEPROM
+ } card_type;
+ int do_rx_crc; /* If we need to CRC incoming packets */
+ int probe_crc; /* set if we don't yet know */
+ int crc_ok_cnt, crc_ko_cnt; /* counters for probing */
+ u16 rx_desc_head;
+ u16 tx_desc_free, tx_desc_head, tx_desc_tail, tx_desc_previous;
+ u16 tx_free_mem, tx_buff_head, tx_buff_tail;
+
+ u16 frag_seq, frag_len, frag_no;
+ u8 frag_source[6];
+
+ u8 wep_is_on, default_key, exclude_unencrypted, encryption_level;
+ u8 group_cipher_suite, pairwise_cipher_suite;
+ u8 wep_keys[MAX_ENCRYPTION_KEYS][MAX_ENCRYPTION_KEY_SIZE];
+ int wep_key_len[MAX_ENCRYPTION_KEYS];
+ int use_wpa, radio_on_broken; /* firmware dependent stuff. */
+
+ u16 host_info_base;
+ struct host_info_struct {
+ /* NB this is matched to the hardware, don't change. */
+ u8 volatile int_status;
+ u8 volatile int_mask;
+ u8 volatile lockout_host;
+ u8 volatile lockout_mac;
+
+ u16 tx_buff_pos;
+ u16 tx_buff_size;
+ u16 tx_desc_pos;
+ u16 tx_desc_count;
+
+ u16 rx_buff_pos;
+ u16 rx_buff_size;
+ u16 rx_desc_pos;
+ u16 rx_desc_count;
+
+ u16 build_version;
+ u16 command_pos;
+
+ u16 major_version;
+ u16 minor_version;
+
+ u16 func_ctrl;
+ u16 mac_status;
+ u16 generic_IRQ_type;
+ u8 reserved[2];
+ } host_info;
+
+ enum {
+ STATION_STATE_SCANNING,
+ STATION_STATE_JOINNING,
+ STATION_STATE_AUTHENTICATING,
+ STATION_STATE_ASSOCIATING,
+ STATION_STATE_READY,
+ STATION_STATE_REASSOCIATING,
+ STATION_STATE_DOWN,
+ STATION_STATE_MGMT_ERROR
+ } station_state;
+
+ int operating_mode, power_mode;
+ time_t last_qual;
+ int beacons_this_sec;
+ int channel;
+ int reg_domain, config_reg_domain;
+ int tx_rate;
+ int auto_tx_rate;
+ int rts_threshold;
+ int frag_threshold;
+ int long_retry, short_retry;
+ int preamble;
+ int default_beacon_period, beacon_period, listen_interval;
+ int CurrentAuthentTransactionSeqNum, ExpectedAuthentTransactionSeqNum;
+ int AuthenticationRequestRetryCnt, AssociationRequestRetryCnt, ReAssociationRequestRetryCnt;
+ enum {
+ SITE_SURVEY_IDLE,
+ SITE_SURVEY_IN_PROGRESS,
+ SITE_SURVEY_COMPLETED
+ } site_survey_state;
+ time_t last_survey;
+
+ int station_was_associated, station_is_associated;
+ int fast_scan;
+
+ struct bss_info {
+ int channel;
+ int SSIDsize;
+ int RSSI;
+ int UsingWEP;
+ int preamble;
+ int beacon_period;
+ int BSStype;
+ u8 BSSID[6];
+ u8 SSID[MAX_SSID_LENGTH];
+ } BSSinfo[MAX_BSS_ENTRIES];
+ int BSS_list_entries, current_BSS;
+ int connect_to_any_BSS;
+ int SSID_size, new_SSID_size;
+ u8 CurrentBSSID[6], BSSID[6];
+ u8 SSID[MAX_SSID_LENGTH], new_SSID[MAX_SSID_LENGTH];
+ u64 last_beacon_timestamp;
+ u8 rx_buf[MAX_WIRELESS_BODY];
+
+};
+
+static u8 atmel_basic_rates[4] = {0x82,0x84,0x0b,0x16};
+
+static const struct {
+ int reg_domain;
+ int min, max;
+ char *name;
+} channel_table[] = { { REG_DOMAIN_FCC, 1, 11, "USA" },
+ { REG_DOMAIN_DOC, 1, 11, "Canada" },
+ { REG_DOMAIN_ETSI, 1, 13, "Europe" },
+ { REG_DOMAIN_SPAIN, 10, 11, "Spain" },
+ { REG_DOMAIN_FRANCE, 10, 13, "France" },
+ { REG_DOMAIN_MKK, 14, 14, "MKK" },
+ { REG_DOMAIN_MKK1, 1, 14, "MKK1" },
+ { REG_DOMAIN_ISRAEL, 3, 9, "Israel"} };
+
+static void build_wpa_mib(struct atmel_private *priv);
+static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
+static void atmel_copy_to_card(struct net_device *dev, u16 dest, unsigned char *src, u16 len);
+static void atmel_copy_to_host(struct net_device *dev, unsigned char *dest, u16 src, u16 len);
+static void atmel_set_gcr(struct net_device *dev, u16 mask);
+static void atmel_clear_gcr(struct net_device *dev, u16 mask);
+static int atmel_lock_mac(struct atmel_private *priv);
+static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data);
+static void atmel_command_irq(struct atmel_private *priv);
+static int atmel_validate_channel(struct atmel_private *priv, int channel);
+static void atmel_management_frame(struct atmel_private *priv, struct ieee802_11_hdr *header,
+ u16 frame_len, u8 rssi);
+static void atmel_management_timer(u_long a);
+static void atmel_send_command(struct atmel_private *priv, int command, void *cmd, int cmd_size);
+static int atmel_send_command_wait(struct atmel_private *priv, int command, void *cmd, int cmd_size);
+static void atmel_transmit_management_frame(struct atmel_private *priv, struct ieee802_11_hdr *header,
+ u8 *body, int body_len);
+
+static u8 atmel_get_mib8(struct atmel_private *priv, u8 type, u8 index);
+static void atmel_set_mib8(struct atmel_private *priv, u8 type, u8 index, u8 data);
+static void atmel_set_mib16(struct atmel_private *priv, u8 type, u8 index, u16 data);
+static void atmel_set_mib(struct atmel_private *priv, u8 type, u8 index, u8 *data, int data_len);
+static void atmel_get_mib(struct atmel_private *priv, u8 type, u8 index, u8 *data, int data_len);
+static void atmel_scan(struct atmel_private *priv, int specific_ssid);
+static void atmel_join_bss(struct atmel_private *priv, int bss_index);
+static void atmel_smooth_qual(struct atmel_private *priv);
+static void atmel_writeAR(struct net_device *dev, u16 data);
+static int probe_atmel_card(struct net_device *dev);
+static int reset_atmel_card(struct net_device *dev );
+static void atmel_enter_state(struct atmel_private *priv, int new_state);
+int atmel_open (struct net_device *dev);
+
+static inline u16 atmel_hi(struct atmel_private *priv, u16 offset)
+{
+ return priv->host_info_base + offset;
+}
+
+static inline u16 atmel_co(struct atmel_private *priv, u16 offset)
+{
+ return priv->host_info.command_pos + offset;
+}
+
+static inline u16 atmel_rx(struct atmel_private *priv, u16 offset, u16 desc)
+{
+ return priv->host_info.rx_desc_pos + (sizeof(struct rx_desc) * desc) + offset;
+}
+
+static inline u16 atmel_tx(struct atmel_private *priv, u16 offset, u16 desc)
+{
+ return priv->host_info.tx_desc_pos + (sizeof(struct tx_desc) * desc) + offset;
+}
+
+static inline u8 atmel_read8(struct net_device *dev, u16 offset)
+{
+ return inb(dev->base_addr + offset);
+}
+
+static inline void atmel_write8(struct net_device *dev, u16 offset, u8 data)
+{
+ outb(data, dev->base_addr + offset);
+}
+
+static inline u16 atmel_read16(struct net_device *dev, u16 offset)
+{
+ return inw(dev->base_addr + offset);
+}
+
+static inline void atmel_write16(struct net_device *dev, u16 offset, u16 data)
+{
+ outw(data, dev->base_addr + offset);
+}
+
+static inline u8 atmel_rmem8(struct atmel_private *priv, u16 pos)
+{
+ atmel_writeAR(priv->dev, pos);
+ return atmel_read8(priv->dev, DR);
+}
+
+static inline void atmel_wmem8(struct atmel_private *priv, u16 pos, u16 data)
+{
+ atmel_writeAR(priv->dev, pos);
+ atmel_write8(priv->dev, DR, data);
+}
+
+static inline u16 atmel_rmem16(struct atmel_private *priv, u16 pos)
+{
+ atmel_writeAR(priv->dev, pos);
+ return atmel_read16(priv->dev, DR);
+}
+
+static inline void atmel_wmem16(struct atmel_private *priv, u16 pos, u16 data)
+{
+ atmel_writeAR(priv->dev, pos);
+ atmel_write16(priv->dev, DR, data);
+}
+
+static const struct iw_handler_def atmel_handler_def;
+
+static void tx_done_irq(struct atmel_private *priv)
+{
+ int i;
+
+ for (i = 0;
+ atmel_rmem8(priv, atmel_tx(priv, TX_DESC_FLAGS_OFFSET, priv->tx_desc_head)) == TX_DONE &&
+ i < priv->host_info.tx_desc_count;
+ i++) {
+
+ u8 status = atmel_rmem8(priv, atmel_tx(priv, TX_DESC_STATUS_OFFSET, priv->tx_desc_head));
+ u16 msdu_size = atmel_rmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, priv->tx_desc_head));
+ u8 type = atmel_rmem8(priv, atmel_tx(priv, TX_DESC_PACKET_TYPE_OFFSET, priv->tx_desc_head));
+
+ atmel_wmem8(priv, atmel_tx(priv, TX_DESC_FLAGS_OFFSET, priv->tx_desc_head), 0);
+
+ priv->tx_free_mem += msdu_size;
+ priv->tx_desc_free++;
+
+ if (priv->tx_buff_head + msdu_size > (priv->host_info.tx_buff_pos + priv->host_info.tx_buff_size))
+ priv->tx_buff_head = 0;
+ else
+ priv->tx_buff_head += msdu_size;
+
+ if (priv->tx_desc_head < (priv->host_info.tx_desc_count - 1))
+ priv->tx_desc_head++ ;
+ else
+ priv->tx_desc_head = 0;
+
+ if (type == TX_PACKET_TYPE_DATA) {
+ if (status == TX_STATUS_SUCCESS)
+ priv->stats.tx_packets++;
+ else
+ priv->stats.tx_errors++;
+ netif_wake_queue(priv->dev);
+ }
+ }
+}
+
+static u16 find_tx_buff(struct atmel_private *priv, u16 len)
+{
+ u16 bottom_free = priv->host_info.tx_buff_size - priv->tx_buff_tail;
+
+ if (priv->tx_desc_free == 3 || priv->tx_free_mem < len)
+ return 0;
+
+ if (bottom_free >= len)
+ return priv->host_info.tx_buff_pos + priv->tx_buff_tail;
+
+ if (priv->tx_free_mem - bottom_free >= len) {
+ priv->tx_buff_tail = 0;
+ return priv->host_info.tx_buff_pos;
+ }
+
+ return 0;
+}
+
+static void tx_update_descriptor(struct atmel_private *priv, int is_bcast, u16 len, u16 buff, u8 type)
+{
+ atmel_wmem16(priv, atmel_tx(priv, TX_DESC_POS_OFFSET, priv->tx_desc_tail), buff);
+ atmel_wmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, priv->tx_desc_tail), len);
+ if (!priv->use_wpa)
+ atmel_wmem16(priv, atmel_tx(priv, TX_DESC_HOST_LENGTH_OFFSET, priv->tx_desc_tail), len);
+ atmel_wmem8(priv, atmel_tx(priv, TX_DESC_PACKET_TYPE_OFFSET, priv->tx_desc_tail), type);
+ atmel_wmem8(priv, atmel_tx(priv, TX_DESC_RATE_OFFSET, priv->tx_desc_tail), priv->tx_rate);
+ atmel_wmem8(priv, atmel_tx(priv, TX_DESC_RETRY_OFFSET, priv->tx_desc_tail), 0);
+ if (priv->use_wpa) {
+ int cipher_type, cipher_length;
+ if (is_bcast) {
+ cipher_type = priv->group_cipher_suite;
+ if (cipher_type == CIPHER_SUITE_WEP_64 ||
+ cipher_type == CIPHER_SUITE_WEP_128 )
+ cipher_length = 8;
+ else if (cipher_type == CIPHER_SUITE_TKIP)
+ cipher_length = 12;
+ else if (priv->pairwise_cipher_suite == CIPHER_SUITE_WEP_64 ||
+ priv->pairwise_cipher_suite == CIPHER_SUITE_WEP_128) {
+ cipher_type = priv->pairwise_cipher_suite;
+ cipher_length = 8;
+ } else {
+ cipher_type = CIPHER_SUITE_NONE;
+ cipher_length = 0;
+ }
+ } else {
+ cipher_type = priv->pairwise_cipher_suite;
+ if (cipher_type == CIPHER_SUITE_WEP_64 ||
+ cipher_type == CIPHER_SUITE_WEP_128 )
+ cipher_length = 8;
+ else if (cipher_type == CIPHER_SUITE_TKIP)
+ cipher_length = 12;
+ else if (priv->group_cipher_suite == CIPHER_SUITE_WEP_64 ||
+ priv->group_cipher_suite == CIPHER_SUITE_WEP_128) {
+ cipher_type = priv->group_cipher_suite;
+ cipher_length = 8;
+ } else {
+ cipher_type = CIPHER_SUITE_NONE;
+ cipher_length = 0;
+ }
+ }
+
+ atmel_wmem8(priv, atmel_tx(priv, TX_DESC_CIPHER_TYPE_OFFSET, priv->tx_desc_tail),
+ cipher_type);
+ atmel_wmem8(priv, atmel_tx(priv, TX_DESC_CIPHER_LENGTH_OFFSET, priv->tx_desc_tail),
+ cipher_length);
+ }
+ atmel_wmem32(priv, atmel_tx(priv, TX_DESC_NEXT_OFFSET, priv->tx_desc_tail), 0x80000000L);
+ atmel_wmem8(priv, atmel_tx(priv, TX_DESC_FLAGS_OFFSET, priv->tx_desc_tail), TX_FIRM_OWN);
+ if (priv->tx_desc_previous != priv->tx_desc_tail)
+ atmel_wmem32(priv, atmel_tx(priv, TX_DESC_NEXT_OFFSET, priv->tx_desc_previous), 0);
+ priv->tx_desc_previous = priv->tx_desc_tail;
+ if (priv->tx_desc_tail < (priv->host_info.tx_desc_count -1 ))
+ priv->tx_desc_tail++;
+ else
+ priv->tx_desc_tail = 0;
+ priv->tx_desc_free--;
+ priv->tx_free_mem -= len;
+
+}
+
+static int start_tx (struct sk_buff *skb, struct net_device *dev)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ struct ieee802_11_hdr header;
+ unsigned long flags;
+ u16 buff, frame_ctl, len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
+ u8 SNAP_RFC1024[6] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
+
+ if (priv->card && priv->present_callback &&
+ !(*priv->present_callback)(priv->card)) {
+ priv->stats.tx_errors++;
+ dev_kfree_skb(skb);
+ return 0;
+ }
+
+ if (priv->station_state != STATION_STATE_READY) {
+ priv->stats.tx_errors++;
+ dev_kfree_skb(skb);
+ return 0;
+ }
+
+ /* first ensure the timer func cannot run */
+ spin_lock_bh(&priv->timerlock);
+ /* then stop the hardware ISR */
+ spin_lock_irqsave(&priv->irqlock, flags);
+ /* nb doing the above in the opposite order will deadlock */
+
+ /* The Wireless Header is 30 bytes. In the Ethernet packet we "cut" the
+ 12 first bytes (containing DA/SA) and put them in the appropriate fields of
+ the Wireless Header. Thus the packet length is then the initial + 18 (+30-12) */
+
+ if (!(buff = find_tx_buff(priv, len + 18))) {
+ priv->stats.tx_dropped++;
+ spin_unlock_irqrestore(&priv->irqlock, flags);
+ spin_unlock_bh(&priv->timerlock);
+ netif_stop_queue(dev);
+ return 1;
+ }
+
+ frame_ctl = IEEE802_11_FTYPE_DATA;
+ header.duration_id = 0;
+ header.seq_ctl = 0;
+ if (priv->wep_is_on)
+ frame_ctl |= IEEE802_11_FCTL_WEP;
+ if (priv->operating_mode == IW_MODE_ADHOC) {
+ memcpy(&header.addr1, skb->data, 6);
+ memcpy(&header.addr2, dev->dev_addr, 6);
+ memcpy(&header.addr3, priv->BSSID, 6);
+ } else {
+ frame_ctl |= IEEE802_11_FCTL_TODS;
+ memcpy(&header.addr1, priv->CurrentBSSID, 6);
+ memcpy(&header.addr2, dev->dev_addr, 6);
+ memcpy(&header.addr3, skb->data, 6);
+ }
+
+ if (priv->use_wpa)
+ memcpy(&header.addr4, SNAP_RFC1024, 6);
+
+ header.frame_ctl = cpu_to_le16(frame_ctl);
+ /* Copy the wireless header into the card */
+ atmel_copy_to_card(dev, buff, (unsigned char *)&header, DATA_FRAME_WS_HEADER_SIZE);
+ /* Copy the packet sans its 802.3 header addresses which have been replaced */
+ atmel_copy_to_card(dev, buff + DATA_FRAME_WS_HEADER_SIZE, skb->data + 12, len - 12);
+ priv->tx_buff_tail += len - 12 + DATA_FRAME_WS_HEADER_SIZE;
+
+ /* low bit of first byte of destination tells us if broadcast */
+ tx_update_descriptor(priv, *(skb->data) & 0x01, len + 18, buff, TX_PACKET_TYPE_DATA);
+ dev->trans_start = jiffies;
+ priv->stats.tx_bytes += len;
+
+ spin_unlock_irqrestore(&priv->irqlock, flags);
+ spin_unlock_bh(&priv->timerlock);
+ dev_kfree_skb(skb);
+
+ return 0;
+}
+
+static void atmel_transmit_management_frame(struct atmel_private *priv,
+ struct ieee802_11_hdr *header,
+ u8 *body, int body_len)
+{
+ u16 buff;
+ int len = MGMT_FRAME_BODY_OFFSET + body_len;
+
+ if (!(buff = find_tx_buff(priv, len)))
+ return;
+
+ atmel_copy_to_card(priv->dev, buff, (u8 *)header, MGMT_FRAME_BODY_OFFSET);
+ atmel_copy_to_card(priv->dev, buff + MGMT_FRAME_BODY_OFFSET, body, body_len);
+ priv->tx_buff_tail += len;
+ tx_update_descriptor(priv, header->addr1[0] & 0x01, len, buff, TX_PACKET_TYPE_MGMT);
+}
+
+static void fast_rx_path(struct atmel_private *priv, struct ieee802_11_hdr *header,
+ u16 msdu_size, u16 rx_packet_loc, u32 crc)
+{
+ /* fast path: unfragmented packet copy directly into skbuf */
+ u8 mac4[6];
+ struct sk_buff *skb;
+ unsigned char *skbp;
+
+ /* get the final, mac 4 header field, this tells us encapsulation */
+ atmel_copy_to_host(priv->dev, mac4, rx_packet_loc + 24, 6);
+ msdu_size -= 6;
+
+ if (priv->do_rx_crc) {
+ crc = crc32_le(crc, mac4, 6);
+ msdu_size -= 4;
+ }
+
+ if (!(skb = dev_alloc_skb(msdu_size + 14))) {
+ priv->stats.rx_dropped++;
+ return;
+ }
+
+ skb_reserve(skb, 2);
+ skbp = skb_put(skb, msdu_size + 12);
+ atmel_copy_to_host(priv->dev, skbp + 12, rx_packet_loc + 30, msdu_size);
+
+ if (priv->do_rx_crc) {
+ u32 netcrc;
+ crc = crc32_le(crc, skbp + 12, msdu_size);
+ atmel_copy_to_host(priv->dev, (void *)&netcrc, rx_packet_loc + 30 + msdu_size, 4);
+ if ((crc ^ 0xffffffff) != netcrc) {
+ priv->stats.rx_crc_errors++;
+ dev_kfree_skb(skb);
+ return;
+ }
+ }
+
+ memcpy(skbp, header->addr1, 6); /* destination address */
+ if (le16_to_cpu(header->frame_ctl) & IEEE802_11_FCTL_FROMDS)
+ memcpy(&skbp[6], header->addr3, 6);
+ else
+ memcpy(&skbp[6], header->addr2, 6); /* source address */
+
+ priv->dev->last_rx=jiffies;
+ skb->dev = priv->dev;
+ skb->protocol = eth_type_trans(skb, priv->dev);
+ skb->ip_summed = CHECKSUM_NONE;
+ netif_rx(skb);
+ priv->stats.rx_bytes += 12 + msdu_size;
+ priv->stats.rx_packets++;
+}
+
+/* Test to see if the packet in card memory at packet_loc has a valid CRC
+ It doesn't matter that this is slow: it is only used to proble the first few packets. */
+static int probe_crc(struct atmel_private *priv, u16 packet_loc, u16 msdu_size)
+{
+ int i = msdu_size - 4;
+ u32 netcrc, crc = 0xffffffff;
+
+ if (msdu_size < 4)
+ return 0;
+
+ atmel_copy_to_host(priv->dev, (void *)&netcrc, packet_loc + i, 4);
+
+ atmel_writeAR(priv->dev, packet_loc);
+ while (i--) {
+ u8 octet = atmel_read8(priv->dev, DR);
+ crc = crc32_le(crc, &octet, 1);
+ }
+
+ return (crc ^ 0xffffffff) == netcrc;
+}
+
+static void frag_rx_path(struct atmel_private *priv, struct ieee802_11_hdr *header,
+ u16 msdu_size, u16 rx_packet_loc, u32 crc, u16 seq_no, u8 frag_no, int more_frags)
+{
+ u8 mac4[6];
+ u8 source[6];
+ struct sk_buff *skb;
+
+ if (le16_to_cpu(header->frame_ctl) & IEEE802_11_FCTL_FROMDS)
+ memcpy(source, header->addr3, 6);
+ else
+ memcpy(source, header->addr2, 6);
+
+ rx_packet_loc += 24; /* skip header */
+
+ if (priv->do_rx_crc)
+ msdu_size -= 4;
+
+ if (frag_no == 0) { /* first fragment */
+ atmel_copy_to_host(priv->dev, mac4, rx_packet_loc, 6);
+ msdu_size -= 6;
+ rx_packet_loc += 6;
+
+ if (priv->do_rx_crc)
+ crc = crc32_le(crc, mac4, 6);
+
+ priv->frag_seq = seq_no;
+ priv->frag_no = 1;
+ priv->frag_len = msdu_size;
+ memcpy(priv->frag_source, source, 6);
+ memcpy(&priv->rx_buf[6], source, 6);
+ memcpy(priv->rx_buf, header->addr1, 6);
+
+ atmel_copy_to_host(priv->dev, &priv->rx_buf[12], rx_packet_loc, msdu_size);
+
+ if (priv->do_rx_crc) {
+ u32 netcrc;
+ crc = crc32_le(crc, &priv->rx_buf[12], msdu_size);
+ atmel_copy_to_host(priv->dev, (void *)&netcrc, rx_packet_loc + msdu_size, 4);
+ if ((crc ^ 0xffffffff) != netcrc) {
+ priv->stats.rx_crc_errors++;
+ memset(priv->frag_source, 0xff, 6);
+ }
+ }
+
+ } else if (priv->frag_no == frag_no &&
+ priv->frag_seq == seq_no &&
+ memcmp(priv->frag_source, source, 6) == 0) {
+
+ atmel_copy_to_host(priv->dev, &priv->rx_buf[12 + priv->frag_len],
+ rx_packet_loc, msdu_size);
+ if (priv->do_rx_crc) {
+ u32 netcrc;
+ crc = crc32_le(crc,
+ &priv->rx_buf[12 + priv->frag_len],
+ msdu_size);
+ atmel_copy_to_host(priv->dev, (void *)&netcrc, rx_packet_loc + msdu_size, 4);
+ if ((crc ^ 0xffffffff) != netcrc) {
+ priv->stats.rx_crc_errors++;
+ memset(priv->frag_source, 0xff, 6);
+ more_frags = 1; /* don't send broken assembly */
+ }
+ }
+
+ priv->frag_len += msdu_size;
+ priv->frag_no++;
+
+ if (!more_frags) { /* last one */
+ memset(priv->frag_source, 0xff, 6);
+ if (!(skb = dev_alloc_skb(priv->frag_len + 14))) {
+ priv->stats.rx_dropped++;
+ } else {
+ skb_reserve(skb, 2);
+ memcpy(skb_put(skb, priv->frag_len + 12),
+ priv->rx_buf,
+ priv->frag_len + 12);
+ priv->dev->last_rx = jiffies;
+ skb->dev = priv->dev;
+ skb->protocol = eth_type_trans(skb, priv->dev);
+ skb->ip_summed = CHECKSUM_NONE;
+ netif_rx(skb);
+ priv->stats.rx_bytes += priv->frag_len + 12;
+ priv->stats.rx_packets++;
+ }
+ }
+
+ } else
+ priv->wstats.discard.fragment++;
+}
+
+static void rx_done_irq(struct atmel_private *priv)
+{
+ int i;
+ struct ieee802_11_hdr header;
+
+ for (i = 0;
+ atmel_rmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head)) == RX_DESC_FLAG_VALID &&
+ i < priv->host_info.rx_desc_count;
+ i++) {
+
+ u16 msdu_size, rx_packet_loc, frame_ctl, seq_control;
+ u8 status = atmel_rmem8(priv, atmel_rx(priv, RX_DESC_STATUS_OFFSET, priv->rx_desc_head));
+ u32 crc = 0xffffffff;
+
+ if (status != RX_STATUS_SUCCESS) {
+ if (status == 0xc1) /* determined by experiment */
+ priv->wstats.discard.nwid++;
+ else
+ priv->stats.rx_errors++;
+ goto next;
+ }
+
+ msdu_size = atmel_rmem16(priv, atmel_rx(priv, RX_DESC_MSDU_SIZE_OFFSET, priv->rx_desc_head));
+ rx_packet_loc = atmel_rmem16(priv, atmel_rx(priv, RX_DESC_MSDU_POS_OFFSET, priv->rx_desc_head));
+
+ if (msdu_size < 30) {
+ priv->stats.rx_errors++;
+ goto next;
+ }
+
+ /* Get header as far as end of seq_ctl */
+ atmel_copy_to_host(priv->dev, (char *)&header, rx_packet_loc, 24);
+ frame_ctl = le16_to_cpu(header.frame_ctl);
+ seq_control = le16_to_cpu(header.seq_ctl);
+
+ /* probe for CRC use here if needed once five packets have arrived with
+ the same crc status, we assume we know what's happening and stop probing */
+ if (priv->probe_crc) {
+ if (!priv->wep_is_on || !(frame_ctl & IEEE802_11_FCTL_WEP)) {
+ priv->do_rx_crc = probe_crc(priv, rx_packet_loc, msdu_size);
+ } else {
+ priv->do_rx_crc = probe_crc(priv, rx_packet_loc + 24, msdu_size - 24);
+ }
+ if (priv->do_rx_crc) {
+ if (priv->crc_ok_cnt++ > 5)
+ priv->probe_crc = 0;
+ } else {
+ if (priv->crc_ko_cnt++ > 5)
+ priv->probe_crc = 0;
+ }
+ }
+
+ /* don't CRC header when WEP in use */
+ if (priv->do_rx_crc && (!priv->wep_is_on || !(frame_ctl & IEEE802_11_FCTL_WEP))) {
+ crc = crc32_le(0xffffffff, (unsigned char *)&header, 24);
+ }
+ msdu_size -= 24; /* header */
+
+ if ((frame_ctl & IEEE802_11_FCTL_FTYPE) == IEEE802_11_FTYPE_DATA) {
+
+ int more_fragments = frame_ctl & IEEE802_11_FCTL_MOREFRAGS;
+ u8 packet_fragment_no = seq_control & IEEE802_11_SCTL_FRAG;
+ u16 packet_sequence_no = (seq_control & IEEE802_11_SCTL_SEQ) >> 4;
+
+ if (!more_fragments && packet_fragment_no == 0 ) {
+ fast_rx_path(priv, &header, msdu_size, rx_packet_loc, crc);
+ } else {
+ frag_rx_path(priv, &header, msdu_size, rx_packet_loc, crc,
+ packet_sequence_no, packet_fragment_no, more_fragments);
+ }
+ }
+
+ if ((frame_ctl & IEEE802_11_FCTL_FTYPE) == IEEE802_11_FTYPE_MGMT) {
+ /* copy rest of packet into buffer */
+ atmel_copy_to_host(priv->dev, (unsigned char *)&priv->rx_buf, rx_packet_loc + 24, msdu_size);
+
+ /* we use the same buffer for frag reassembly and control packets */
+ memset(priv->frag_source, 0xff, 6);
+
+ if (priv->do_rx_crc) {
+ /* last 4 octets is crc */
+ msdu_size -= 4;
+ crc = crc32_le(crc, (unsigned char *)&priv->rx_buf, msdu_size);
+ if ((crc ^ 0xffffffff) != (*((u32 *)&priv->rx_buf[msdu_size]))) {
+ priv->stats.rx_crc_errors++;
+ goto next;
+ }
+ }
+
+ atmel_management_frame(priv, &header, msdu_size,
+ atmel_rmem8(priv, atmel_rx(priv, RX_DESC_RSSI_OFFSET, priv->rx_desc_head)));
+ }
+
+ next:
+ /* release descriptor */
+ atmel_wmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head), RX_DESC_FLAG_CONSUMED);
+
+ if (priv->rx_desc_head < (priv->host_info.rx_desc_count - 1))
+ priv->rx_desc_head++;
+ else
+ priv->rx_desc_head = 0;
+ }
+}
+
+static irqreturn_t service_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ struct net_device *dev = (struct net_device *) dev_id;
+ struct atmel_private *priv = netdev_priv(dev);
+ u8 isr;
+ int i = -1;
+ static u8 irq_order[] = {
+ ISR_OUT_OF_RANGE,
+ ISR_RxCOMPLETE,
+ ISR_TxCOMPLETE,
+ ISR_RxFRAMELOST,
+ ISR_FATAL_ERROR,
+ ISR_COMMAND_COMPLETE,
+ ISR_IBSS_MERGE,
+ ISR_GENERIC_IRQ
+ };
+
+
+ if (priv->card && priv->present_callback &&
+ !(*priv->present_callback)(priv->card))
+ return IRQ_HANDLED;
+
+ /* In this state upper-level code assumes it can mess with
+ the card unhampered by interrupts which may change register state.
+ Note that even though the card shouldn't generate interrupts
+ the inturrupt line may be shared. This allows card setup
+ to go on without disabling interrupts for a long time. */
+ if (priv->station_state == STATION_STATE_DOWN)
+ return IRQ_NONE;
+
+ atmel_clear_gcr(dev, GCR_ENINT); /* disable interrupts */
+
+ while (1) {
+ if (!atmel_lock_mac(priv)) {
+ /* failed to contact card */
+ printk(KERN_ALERT "%s: failed to contact MAC.\n", dev->name);
+ return IRQ_HANDLED;
+ }
+
+ isr = atmel_rmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET));
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0);
+
+ if (!isr) {
+ atmel_set_gcr(dev, GCR_ENINT); /* enable interrupts */
+ return i == -1 ? IRQ_NONE : IRQ_HANDLED;
+ }
+
+ atmel_set_gcr(dev, GCR_ACKINT); /* acknowledge interrupt */
+
+ for (i = 0; i < sizeof(irq_order)/sizeof(u8); i++)
+ if (isr & irq_order[i])
+ break;
+
+ if (!atmel_lock_mac(priv)) {
+ /* failed to contact card */
+ printk(KERN_ALERT "%s: failed to contact MAC.\n", dev->name);
+ return IRQ_HANDLED;
+ }
+
+ isr = atmel_rmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET));
+ isr ^= irq_order[i];
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET), isr);
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0);
+
+ switch (irq_order[i]) {
+
+ case ISR_OUT_OF_RANGE:
+ if (priv->operating_mode == IW_MODE_INFRA &&
+ priv->station_state == STATION_STATE_READY) {
+ priv->station_is_associated = 0;
+ atmel_scan(priv, 1);
+ }
+ break;
+
+ case ISR_RxFRAMELOST:
+ priv->wstats.discard.misc++;
+ /* fall through */
+ case ISR_RxCOMPLETE:
+ rx_done_irq(priv);
+ break;
+
+ case ISR_TxCOMPLETE:
+ tx_done_irq(priv);
+ break;
+
+ case ISR_FATAL_ERROR:
+ printk(KERN_ALERT "%s: *** FATAL error interrupt ***\n", dev->name);
+ atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
+ break;
+
+ case ISR_COMMAND_COMPLETE:
+ atmel_command_irq(priv);
+ break;
+
+ case ISR_IBSS_MERGE:
+ atmel_get_mib(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_CUR_BSSID_POS,
+ priv->CurrentBSSID, 6);
+ /* The WPA stuff cares about the current AP address */
+ if (priv->use_wpa)
+ build_wpa_mib(priv);
+ break;
+ case ISR_GENERIC_IRQ:
+ printk(KERN_INFO "%s: Generic_irq received.\n", dev->name);
+ break;
+ }
+ }
+}
+
+
+static struct net_device_stats *atmel_get_stats (struct net_device *dev)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ return &priv->stats;
+}
+
+static struct iw_statistics *atmel_get_wireless_stats (struct net_device *dev)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ /* update the link quality here in case we are seeing no beacons
+ at all to drive the process */
+ atmel_smooth_qual(priv);
+
+ priv->wstats.status = priv->station_state;
+
+ if (priv->operating_mode == IW_MODE_INFRA) {
+ if (priv->station_state != STATION_STATE_READY) {
+ priv->wstats.qual.qual = 0;
+ priv->wstats.qual.level = 0;
+ priv->wstats.qual.updated = (IW_QUAL_QUAL_INVALID
+ | IW_QUAL_LEVEL_INVALID);
+ }
+ priv->wstats.qual.noise = 0;
+ priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
+ } else {
+ /* Quality levels cannot be determined in ad-hoc mode,
+ because we can 'hear' more that one remote station. */
+ priv->wstats.qual.qual = 0;
+ priv->wstats.qual.level = 0;
+ priv->wstats.qual.noise = 0;
+ priv->wstats.qual.updated = IW_QUAL_QUAL_INVALID
+ | IW_QUAL_LEVEL_INVALID
+ | IW_QUAL_NOISE_INVALID;
+ priv->wstats.miss.beacon = 0;
+ }
+
+ return (&priv->wstats);
+}
+
+static int atmel_change_mtu(struct net_device *dev, int new_mtu)
+{
+ if ((new_mtu < 68) || (new_mtu > 2312))
+ return -EINVAL;
+ dev->mtu = new_mtu;
+ return 0;
+}
+
+static int atmel_set_mac_address(struct net_device *dev, void *p)
+{
+ struct sockaddr *addr = p;
+
+ memcpy (dev->dev_addr, addr->sa_data, dev->addr_len);
+ return atmel_open(dev);
+}
+
+EXPORT_SYMBOL(atmel_open);
+
+int atmel_open (struct net_device *dev)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ int i, channel;
+
+ /* any scheduled timer is no longer needed and might screw things up.. */
+ del_timer_sync(&priv->management_timer);
+
+ /* Interrupts will not touch the card once in this state... */
+ priv->station_state = STATION_STATE_DOWN;
+
+ if (priv->new_SSID_size) {
+ memcpy(priv->SSID, priv->new_SSID, priv->new_SSID_size);
+ priv->SSID_size = priv->new_SSID_size;
+ priv->new_SSID_size = 0;
+ }
+ priv->BSS_list_entries = 0;
+
+ priv->AuthenticationRequestRetryCnt = 0;
+ priv->AssociationRequestRetryCnt = 0;
+ priv->ReAssociationRequestRetryCnt = 0;
+ priv->CurrentAuthentTransactionSeqNum = 0x0001;
+ priv->ExpectedAuthentTransactionSeqNum = 0x0002;
+
+ priv->site_survey_state = SITE_SURVEY_IDLE;
+ priv->station_is_associated = 0;
+
+ if (!reset_atmel_card(dev))
+ return -EAGAIN;
+
+ if (priv->config_reg_domain) {
+ priv->reg_domain = priv->config_reg_domain;
+ atmel_set_mib8(priv, Phy_Mib_Type, PHY_MIB_REG_DOMAIN_POS, priv->reg_domain);
+ } else {
+ priv->reg_domain = atmel_get_mib8(priv, Phy_Mib_Type, PHY_MIB_REG_DOMAIN_POS);
+ for (i = 0; i < sizeof(channel_table)/sizeof(channel_table[0]); i++)
+ if (priv->reg_domain == channel_table[i].reg_domain)
+ break;
+ if (i == sizeof(channel_table)/sizeof(channel_table[0])) {
+ priv->reg_domain = REG_DOMAIN_MKK1;
+ printk(KERN_ALERT "%s: failed to get regulatory domain: assuming MKK1.\n", dev->name);
+ }
+ }
+
+ if ((channel = atmel_validate_channel(priv, priv->channel)))
+ priv->channel = channel;
+
+ /* this moves station_state on.... */
+ atmel_scan(priv, 1);
+
+ atmel_set_gcr(priv->dev, GCR_ENINT); /* enable interrupts */
+ return 0;
+}
+
+static int atmel_close (struct net_device *dev)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ atmel_enter_state(priv, STATION_STATE_DOWN);
+
+ if (priv->bus_type == BUS_TYPE_PCCARD)
+ atmel_write16(dev, GCR, 0x0060);
+ atmel_write16(dev, GCR, 0x0040);
+ return 0;
+}
+
+static int atmel_validate_channel(struct atmel_private *priv, int channel)
+{
+ /* check that channel is OK, if so return zero,
+ else return suitable default channel */
+ int i;
+
+ for (i = 0; i < sizeof(channel_table)/sizeof(channel_table[0]); i++)
+ if (priv->reg_domain == channel_table[i].reg_domain) {
+ if (channel >= channel_table[i].min &&
+ channel <= channel_table[i].max)
+ return 0;
+ else
+ return channel_table[i].min;
+ }
+ return 0;
+}
+
+static int atmel_proc_output (char *buf, struct atmel_private *priv)
+{
+ int i;
+ char *p = buf;
+ char *s, *r, *c;
+
+ p += sprintf(p, "Driver version:\t\t%d.%d\n", DRIVER_MAJOR, DRIVER_MINOR);
+
+ if (priv->station_state != STATION_STATE_DOWN) {
+ p += sprintf(p, "Firmware version:\t%d.%d build %d\nFirmware location:\t",
+ priv->host_info.major_version,
+ priv->host_info.minor_version,
+ priv->host_info.build_version);
+
+ if (priv->card_type != CARD_TYPE_EEPROM)
+ p += sprintf(p, "on card\n");
+ else if (priv->firmware)
+ p += sprintf(p, "%s loaded by host\n", priv->firmware_id);
+ else
+ p += sprintf(p, "%s loaded by hotplug\n", priv->firmware_id);
+
+ switch(priv->card_type) {
+ case CARD_TYPE_PARALLEL_FLASH: c = "Parallel flash"; break;
+ case CARD_TYPE_SPI_FLASH: c = "SPI flash\n"; break;
+ case CARD_TYPE_EEPROM: c = "EEPROM"; break;
+ default: c = "<unknown>";
+ }
+
+
+ r = "<unknown>";
+ for (i = 0; i < sizeof(channel_table)/sizeof(channel_table[0]); i++)
+ if (priv->reg_domain == channel_table[i].reg_domain)
+ r = channel_table[i].name;
+
+ p += sprintf(p, "MAC memory type:\t%s\n", c);
+ p += sprintf(p, "Regulatory domain:\t%s\n", r);
+ p += sprintf(p, "Host CRC checking:\t%s\n",
+ priv->do_rx_crc ? "On" : "Off");
+ p += sprintf(p, "WPA-capable firmware:\t%s\n",
+ priv->use_wpa ? "Yes" : "No");
+ }
+
+ switch(priv->station_state) {
+ case STATION_STATE_SCANNING: s = "Scanning"; break;
+ case STATION_STATE_JOINNING: s = "Joining"; break;
+ case STATION_STATE_AUTHENTICATING: s = "Authenticating"; break;
+ case STATION_STATE_ASSOCIATING: s = "Associating"; break;
+ case STATION_STATE_READY: s = "Ready"; break;
+ case STATION_STATE_REASSOCIATING: s = "Reassociating"; break;
+ case STATION_STATE_MGMT_ERROR: s = "Management error"; break;
+ case STATION_STATE_DOWN: s = "Down"; break;
+ default: s = "<unknown>";
+ }
+
+ p += sprintf(p, "Current state:\t\t%s\n", s);
+ return p - buf;
+}
+
+static int atmel_read_proc(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ struct atmel_private *priv = data;
+ int len = atmel_proc_output (page, priv);
+ if (len <= off+count) *eof = 1;
+ *start = page + off;
+ len -= off;
+ if (len>count) len = count;
+ if (len<0) len = 0;
+ return len;
+}
+
+struct net_device *init_atmel_card( unsigned short irq, int port, const AtmelFWType fw_type,
+ struct device *sys_dev, int (*card_present)(void *), void *card)
+{
+ struct net_device *dev;
+ struct atmel_private *priv;
+ int rc;
+
+ /* Create the network device object. */
+ dev = alloc_etherdev(sizeof(*priv));
+ if (!dev) {
+ printk(KERN_ERR "atmel: Couldn't alloc_etherdev\n");
+ return NULL;
+ }
+ if (dev_alloc_name(dev, dev->name) < 0) {
+ printk(KERN_ERR "atmel: Couldn't get name!\n");
+ goto err_out_free;
+ }
+
+ priv = netdev_priv(dev);
+ priv->dev = dev;
+ priv->sys_dev = sys_dev;
+ priv->present_callback = card_present;
+ priv->card = card;
+ priv->firmware = NULL;
+ priv->firmware_id[0] = '\0';
+ priv->firmware_type = fw_type;
+ if (firmware) /* module parameter */
+ strcpy(priv->firmware_id, firmware);
+ priv->bus_type = card_present ? BUS_TYPE_PCCARD : BUS_TYPE_PCI;
+ priv->station_state = STATION_STATE_DOWN;
+ priv->do_rx_crc = 0;
+ /* For PCMCIA cards, some chips need CRC, some don't
+ so we have to probe. */
+ if (priv->bus_type == BUS_TYPE_PCCARD) {
+ priv->probe_crc = 1;
+ priv->crc_ok_cnt = priv->crc_ko_cnt = 0;
+ } else
+ priv->probe_crc = 0;
+ memset(&priv->stats, 0, sizeof(priv->stats));
+ memset(&priv->wstats, 0, sizeof(priv->wstats));
+ priv->last_qual = jiffies;
+ priv->last_beacon_timestamp = 0;
+ memset(priv->frag_source, 0xff, sizeof(priv->frag_source));
+ memset(priv->BSSID, 0, 6);
+ priv->CurrentBSSID[0] = 0xFF; /* Initialize to something invalid.... */
+ priv->station_was_associated = 0;
+
+ priv->last_survey = jiffies;
+ priv->preamble = LONG_PREAMBLE;
+ priv->operating_mode = IW_MODE_INFRA;
+ priv->connect_to_any_BSS = 0;
+ priv->config_reg_domain = 0;
+ priv->reg_domain = 0;
+ priv->tx_rate = 3;
+ priv->auto_tx_rate = 1;
+ priv->channel = 4;
+ priv->power_mode = 0;
+ priv->SSID[0] = '\0';
+ priv->SSID_size = 0;
+ priv->new_SSID_size = 0;
+ priv->frag_threshold = 2346;
+ priv->rts_threshold = 2347;
+ priv->short_retry = 7;
+ priv->long_retry = 4;
+
+ priv->wep_is_on = 0;
+ priv->default_key = 0;
+ priv->encryption_level = 0;
+ priv->exclude_unencrypted = 0;
+ priv->group_cipher_suite = priv->pairwise_cipher_suite = CIPHER_SUITE_NONE;
+ priv->use_wpa = 0;
+ memset(priv->wep_keys, 0, sizeof(priv->wep_keys));
+ memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
+
+ priv->default_beacon_period = priv->beacon_period = 100;
+ priv->listen_interval = 1;
+
+ init_timer(&priv->management_timer);
+ spin_lock_init(&priv->irqlock);
+ spin_lock_init(&priv->timerlock);
+ priv->management_timer.function = atmel_management_timer;
+ priv->management_timer.data = (unsigned long) dev;
+
+ dev->open = atmel_open;
+ dev->stop = atmel_close;
+ dev->change_mtu = atmel_change_mtu;
+ dev->set_mac_address = atmel_set_mac_address;
+ dev->hard_start_xmit = start_tx;
+ dev->get_stats = atmel_get_stats;
+ dev->get_wireless_stats = atmel_get_wireless_stats;
+ dev->wireless_handlers = (struct iw_handler_def *)&atmel_handler_def;
+ dev->do_ioctl = atmel_ioctl;
+ dev->irq = irq;
+ dev->base_addr = port;
+
+ SET_NETDEV_DEV(dev, sys_dev);
+
+ if ((rc = request_irq(dev->irq, service_interrupt, SA_SHIRQ, dev->name, dev))) {
+ printk(KERN_ERR "%s: register interrupt %d failed, rc %d\n", dev->name, irq, rc );
+ goto err_out_free;
+ }
+
+ if (priv->bus_type == BUS_TYPE_PCI &&
+ !request_region( dev->base_addr, 64, dev->name )) {
+ goto err_out_irq;
+ }
+
+ if (register_netdev(dev))
+ goto err_out_res;
+
+ if (!probe_atmel_card(dev)){
+ unregister_netdev(dev);
+ goto err_out_res;
+ }
+
+ netif_carrier_off(dev);
+
+ create_proc_read_entry ("driver/atmel", 0, NULL, atmel_read_proc, priv);
+
+ printk(KERN_INFO "%s: Atmel at76c50x wireless. Version %d.%d simon@thekelleys.org.uk\n",
+ dev->name, DRIVER_MAJOR, DRIVER_MINOR);
+
+ SET_MODULE_OWNER(dev);
+ return dev;
+
+ err_out_res:
+ if (priv->bus_type == BUS_TYPE_PCI)
+ release_region( dev->base_addr, 64 );
+ err_out_irq:
+ free_irq(dev->irq, dev);
+ err_out_free:
+ free_netdev(dev);
+ return NULL;
+}
+
+EXPORT_SYMBOL(init_atmel_card);
+
+void stop_atmel_card(struct net_device *dev, int freeres)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ /* put a brick on it... */
+ if (priv->bus_type == BUS_TYPE_PCCARD)
+ atmel_write16(dev, GCR, 0x0060);
+ atmel_write16(dev, GCR, 0x0040);
+
+ del_timer_sync(&priv->management_timer);
+ unregister_netdev(dev);
+ remove_proc_entry("driver/atmel", NULL);
+ free_irq(dev->irq, dev);
+ if (priv->firmware)
+ kfree(priv->firmware);
+ if (freeres) {
+ /* PCMCIA frees this stuff, so only for PCI */
+ release_region(dev->base_addr, 64);
+ }
+ free_netdev(dev);
+}
+
+EXPORT_SYMBOL(stop_atmel_card);
+
+static int atmel_set_essid(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ /* Check if we asked for `any' */
+ if(dwrq->flags == 0) {
+ priv->connect_to_any_BSS = 1;
+ } else {
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+
+ priv->connect_to_any_BSS = 0;
+
+ /* Check the size of the string */
+ if (dwrq->length > MAX_SSID_LENGTH + 1)
+ return -E2BIG ;
+ if (index != 0)
+ return -EINVAL;
+
+ memcpy(priv->new_SSID, extra, dwrq->length - 1);
+ priv->new_SSID_size = dwrq->length - 1;
+ }
+
+ return -EINPROGRESS;
+}
+
+static int atmel_get_essid(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ /* Get the current SSID */
+ if (priv->new_SSID_size != 0) {
+ memcpy(extra, priv->new_SSID, priv->new_SSID_size);
+ extra[priv->new_SSID_size] = '\0';
+ dwrq->length = priv->new_SSID_size + 1;
+ } else {
+ memcpy(extra, priv->SSID, priv->SSID_size);
+ extra[priv->SSID_size] = '\0';
+ dwrq->length = priv->SSID_size + 1;
+ }
+
+ dwrq->flags = !priv->connect_to_any_BSS; /* active */
+
+ return 0;
+}
+
+static int atmel_get_wap(struct net_device *dev,
+ struct iw_request_info *info,
+ struct sockaddr *awrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ memcpy(awrq->sa_data, priv->CurrentBSSID, 6);
+ awrq->sa_family = ARPHRD_ETHER;
+
+ return 0;
+}
+
+static int atmel_set_encode(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ /* Basic checking: do we have a key to set ?
+ * Note : with the new API, it's impossible to get a NULL pointer.
+ * Therefore, we need to check a key size == 0 instead.
+ * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
+ * when no key is present (only change flags), but older versions
+ * don't do it. - Jean II */
+ if (dwrq->length > 0) {
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+ int current_index = priv->default_key;
+ /* Check the size of the key */
+ if (dwrq->length > 13) {
+ return -EINVAL;
+ }
+ /* Check the index (none -> use current) */
+ if (index < 0 || index >= 4)
+ index = current_index;
+ else
+ priv->default_key = index;
+ /* Set the length */
+ if (dwrq->length > 5)
+ priv->wep_key_len[index] = 13;
+ else
+ if (dwrq->length > 0)
+ priv->wep_key_len[index] = 5;
+ else
+ /* Disable the key */
+ priv->wep_key_len[index] = 0;
+ /* Check if the key is not marked as invalid */
+ if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
+ /* Cleanup */
+ memset(priv->wep_keys[index], 0, 13);
+ /* Copy the key in the driver */
+ memcpy(priv->wep_keys[index], extra, dwrq->length);
+ }
+ /* WE specify that if a valid key is set, encryption
+ * should be enabled (user may turn it off later)
+ * This is also how "iwconfig ethX key on" works */
+ if (index == current_index &&
+ priv->wep_key_len[index] > 0) {
+ priv->wep_is_on = 1;
+ priv->exclude_unencrypted = 1;
+ if (priv->wep_key_len[index] > 5) {
+ priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_64;
+ priv->encryption_level = 2;
+ } else {
+ priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_128;
+ priv->encryption_level = 1;
+ }
+ }
+ } else {
+ /* Do we want to just set the transmit key index ? */
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+ if ( index>=0 && index < 4 ) {
+ priv->default_key = index;
+ } else
+ /* Don't complain if only change the mode */
+ if(!dwrq->flags & IW_ENCODE_MODE) {
+ return -EINVAL;
+ }
+ }
+ /* Read the flags */
+ if(dwrq->flags & IW_ENCODE_DISABLED) {
+ priv->wep_is_on = 0;
+ priv->encryption_level = 0;
+ priv->pairwise_cipher_suite = CIPHER_SUITE_NONE;
+ } else {
+ priv->wep_is_on = 1;
+ if (priv->wep_key_len[priv->default_key] > 5) {
+ priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_128;
+ priv->encryption_level = 2;
+ } else {
+ priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_64;
+ priv->encryption_level = 1;
+ }
+ }
+ if(dwrq->flags & IW_ENCODE_RESTRICTED)
+ priv->exclude_unencrypted = 1;
+ if(dwrq->flags & IW_ENCODE_OPEN)
+ priv->exclude_unencrypted = 0;
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+
+static int atmel_get_encode(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+
+ if (!priv->wep_is_on)
+ dwrq->flags = IW_ENCODE_DISABLED;
+ else if (priv->exclude_unencrypted)
+ dwrq->flags = IW_ENCODE_RESTRICTED;
+ else
+ dwrq->flags = IW_ENCODE_OPEN;
+
+ /* Which key do we want ? -1 -> tx index */
+ if (index < 0 || index >= 4)
+ index = priv->default_key;
+ dwrq->flags |= index + 1;
+ /* Copy the key to the user buffer */
+ dwrq->length = priv->wep_key_len[index];
+ if (dwrq->length > 16) {
+ dwrq->length=0;
+ } else {
+ memset(extra, 0, 16);
+ memcpy(extra, priv->wep_keys[index], dwrq->length);
+ }
+
+ return 0;
+}
+
+static int atmel_get_name(struct net_device *dev,
+ struct iw_request_info *info,
+ char *cwrq,
+ char *extra)
+{
+ strcpy(cwrq, "IEEE 802.11-DS");
+ return 0;
+}
+
+static int atmel_set_rate(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ if (vwrq->fixed == 0) {
+ priv->tx_rate = 3;
+ priv->auto_tx_rate = 1;
+ } else {
+ priv->auto_tx_rate = 0;
+
+ /* Which type of value ? */
+ if((vwrq->value < 4) && (vwrq->value >= 0)) {
+ /* Setting by rate index */
+ priv->tx_rate = vwrq->value;
+ } else {
+ /* Setting by frequency value */
+ switch (vwrq->value) {
+ case 1000000: priv->tx_rate = 0; break;
+ case 2000000: priv->tx_rate = 1; break;
+ case 5500000: priv->tx_rate = 2; break;
+ case 11000000: priv->tx_rate = 3; break;
+ default: return -EINVAL;
+ }
+ }
+ }
+
+ return -EINPROGRESS;
+}
+
+static int atmel_set_mode(struct net_device *dev,
+ struct iw_request_info *info,
+ __u32 *uwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ if (*uwrq != IW_MODE_ADHOC && *uwrq != IW_MODE_INFRA)
+ return -EINVAL;
+
+ priv->operating_mode = *uwrq;
+ return -EINPROGRESS;
+}
+
+static int atmel_get_mode(struct net_device *dev,
+ struct iw_request_info *info,
+ __u32 *uwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ *uwrq = priv->operating_mode;
+ return 0;
+}
+
+static int atmel_get_rate(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ if (priv->auto_tx_rate) {
+ vwrq->fixed = 0;
+ vwrq->value = 11000000;
+ } else {
+ vwrq->fixed = 1;
+ switch(priv->tx_rate) {
+ case 0: vwrq->value = 1000000; break;
+ case 1: vwrq->value = 2000000; break;
+ case 2: vwrq->value = 5500000; break;
+ case 3: vwrq->value = 11000000; break;
+ }
+ }
+ return 0;
+}
+
+static int atmel_set_power(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ priv->power_mode = vwrq->disabled ? 0 : 1;
+ return -EINPROGRESS;
+}
+
+static int atmel_get_power(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ vwrq->disabled = priv->power_mode ? 0 : 1;
+ vwrq->flags = IW_POWER_ON;
+ return 0;
+}
+
+static int atmel_set_retry(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ if(!vwrq->disabled && (vwrq->flags & IW_RETRY_LIMIT)) {
+ if(vwrq->flags & IW_RETRY_MAX)
+ priv->long_retry = vwrq->value;
+ else if (vwrq->flags & IW_RETRY_MIN)
+ priv->short_retry = vwrq->value;
+ else {
+ /* No modifier : set both */
+ priv->long_retry = vwrq->value;
+ priv->short_retry = vwrq->value;
+ }
+ return -EINPROGRESS;
+ }
+
+ return -EINVAL;
+}
+
+static int atmel_get_retry(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ vwrq->disabled = 0; /* Can't be disabled */
+
+ /* Note : by default, display the min retry number */
+ if((vwrq->flags & IW_RETRY_MAX)) {
+ vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
+ vwrq->value = priv->long_retry;
+ } else {
+ vwrq->flags = IW_RETRY_LIMIT;
+ vwrq->value = priv->short_retry;
+ if(priv->long_retry != priv->short_retry)
+ vwrq->flags |= IW_RETRY_MIN;
+ }
+
+ return 0;
+}
+
+static int atmel_set_rts(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ int rthr = vwrq->value;
+
+ if(vwrq->disabled)
+ rthr = 2347;
+ if((rthr < 0) || (rthr > 2347)) {
+ return -EINVAL;
+ }
+ priv->rts_threshold = rthr;
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+static int atmel_get_rts(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ vwrq->value = priv->rts_threshold;
+ vwrq->disabled = (vwrq->value >= 2347);
+ vwrq->fixed = 1;
+
+ return 0;
+}
+
+static int atmel_set_frag(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ int fthr = vwrq->value;
+
+ if(vwrq->disabled)
+ fthr = 2346;
+ if((fthr < 256) || (fthr > 2346)) {
+ return -EINVAL;
+ }
+ fthr &= ~0x1; /* Get an even value - is it really needed ??? */
+ priv->frag_threshold = fthr;
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+static int atmel_get_frag(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ vwrq->value = priv->frag_threshold;
+ vwrq->disabled = (vwrq->value >= 2346);
+ vwrq->fixed = 1;
+
+ return 0;
+}
+
+static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
+ 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
+
+static int atmel_set_freq(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_freq *fwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ int rc = -EINPROGRESS; /* Call commit handler */
+
+ /* If setting by frequency, convert to a channel */
+ if((fwrq->e == 1) &&
+ (fwrq->m >= (int) 241200000) &&
+ (fwrq->m <= (int) 248700000)) {
+ int f = fwrq->m / 100000;
+ int c = 0;
+ while((c < 14) && (f != frequency_list[c]))
+ c++;
+ /* Hack to fall through... */
+ fwrq->e = 0;
+ fwrq->m = c + 1;
+ }
+ /* Setting by channel number */
+ if((fwrq->m > 1000) || (fwrq->e > 0))
+ rc = -EOPNOTSUPP;
+ else {
+ int channel = fwrq->m;
+ if (atmel_validate_channel(priv, channel) == 0) {
+ priv->channel = channel;
+ } else {
+ rc = -EINVAL;
+ }
+ }
+ return rc;
+}
+
+static int atmel_get_freq(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_freq *fwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+
+ fwrq->m = priv->channel;
+ fwrq->e = 0;
+ return 0;
+}
+
+static int atmel_set_scan(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_param *vwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ unsigned long flags;
+
+ /* Note : you may have realised that, as this is a SET operation,
+ * this is privileged and therefore a normal user can't
+ * perform scanning.
+ * This is not an error, while the device perform scanning,
+ * traffic doesn't flow, so it's a perfect DoS...
+ * Jean II */
+
+ if (priv->station_state == STATION_STATE_DOWN)
+ return -EAGAIN;
+
+ /* Timeout old surveys. */
+ if ((jiffies - priv->last_survey) > (20 * HZ))
+ priv->site_survey_state = SITE_SURVEY_IDLE;
+ priv->last_survey = jiffies;
+
+ /* Initiate a scan command */
+ if (priv->site_survey_state == SITE_SURVEY_IN_PROGRESS)
+ return -EBUSY;
+
+ del_timer_sync(&priv->management_timer);
+ spin_lock_irqsave(&priv->irqlock, flags);
+
+ priv->site_survey_state = SITE_SURVEY_IN_PROGRESS;
+ priv->fast_scan = 0;
+ atmel_scan(priv, 0);
+ spin_unlock_irqrestore(&priv->irqlock, flags);
+
+ return 0;
+}
+
+static int atmel_get_scan(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ int i;
+ char *current_ev = extra;
+ struct iw_event iwe;
+
+ if (priv->site_survey_state != SITE_SURVEY_COMPLETED)
+ return -EAGAIN;
+
+ for(i=0; i<priv->BSS_list_entries; i++) {
+ iwe.cmd = SIOCGIWAP;
+ iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
+ memcpy(iwe.u.ap_addr.sa_data, priv->BSSinfo[i].BSSID, 6);
+ current_ev = iwe_stream_add_event(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_ADDR_LEN);
+
+ iwe.u.data.length = priv->BSSinfo[i].SSIDsize;
+ if (iwe.u.data.length > 32)
+ iwe.u.data.length = 32;
+ iwe.cmd = SIOCGIWESSID;
+ iwe.u.data.flags = 1;
+ current_ev = iwe_stream_add_point(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, priv->BSSinfo[i].SSID);
+
+ iwe.cmd = SIOCGIWMODE;
+ iwe.u.mode = priv->BSSinfo[i].BSStype;
+ current_ev = iwe_stream_add_event(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_UINT_LEN);
+
+ iwe.cmd = SIOCGIWFREQ;
+ iwe.u.freq.m = priv->BSSinfo[i].channel;
+ iwe.u.freq.e = 0;
+ current_ev = iwe_stream_add_event(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_FREQ_LEN);
+
+ iwe.cmd = SIOCGIWENCODE;
+ if (priv->BSSinfo[i].UsingWEP)
+ iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
+ else
+ iwe.u.data.flags = IW_ENCODE_DISABLED;
+ iwe.u.data.length = 0;
+ current_ev = iwe_stream_add_point(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, NULL);
+
+ }
+
+ /* Length of data */
+ dwrq->length = (current_ev - extra);
+ dwrq->flags = 0;
+
+ return 0;
+}
+
+static int atmel_get_range(struct net_device *dev,
+ struct iw_request_info *info,
+ struct iw_point *dwrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ struct iw_range *range = (struct iw_range *) extra;
+ int k,i,j;
+
+ dwrq->length = sizeof(struct iw_range);
+ memset(range, 0, sizeof(range));
+ range->min_nwid = 0x0000;
+ range->max_nwid = 0x0000;
+ range->num_channels = 0;
+ for (j = 0; j < sizeof(channel_table)/sizeof(channel_table[0]); j++)
+ if (priv->reg_domain == channel_table[j].reg_domain) {
+ range->num_channels = channel_table[j].max - channel_table[j].min + 1;
+ break;
+ }
+ if (range->num_channels != 0) {
+ for(k = 0, i = channel_table[j].min; i <= channel_table[j].max; i++) {
+ range->freq[k].i = i; /* List index */
+ range->freq[k].m = frequency_list[i-1] * 100000;
+ range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
+ }
+ range->num_frequency = k;
+ }
+
+ range->max_qual.qual = 100;
+ range->max_qual.level = 100;
+ range->max_qual.noise = 0;
+ range->max_qual.updated = IW_QUAL_NOISE_INVALID;
+
+ range->avg_qual.qual = 50;
+ range->avg_qual.level = 50;
+ range->avg_qual.noise = 0;
+ range->avg_qual.updated = IW_QUAL_NOISE_INVALID;
+
+ range->sensitivity = 0;
+
+ range->bitrate[0] = 1000000;
+ range->bitrate[1] = 2000000;
+ range->bitrate[2] = 5500000;
+ range->bitrate[3] = 11000000;
+ range->num_bitrates = 4;
+
+ range->min_rts = 0;
+ range->max_rts = 2347;
+ range->min_frag = 256;
+ range->max_frag = 2346;
+
+ range->encoding_size[0] = 5;
+ range->encoding_size[1] = 13;
+ range->num_encoding_sizes = 2;
+ range->max_encoding_tokens = 4;
+
+ range->pmp_flags = IW_POWER_ON;
+ range->pmt_flags = IW_POWER_ON;
+ range->pm_capa = 0;
+
+ range->we_version_source = WIRELESS_EXT;
+ range->we_version_compiled = WIRELESS_EXT;
+ range->retry_capa = IW_RETRY_LIMIT ;
+ range->retry_flags = IW_RETRY_LIMIT;
+ range->r_time_flags = 0;
+ range->min_retry = 1;
+ range->max_retry = 65535;
+
+ return 0;
+}
+
+static int atmel_set_wap(struct net_device *dev,
+ struct iw_request_info *info,
+ struct sockaddr *awrq,
+ char *extra)
+{
+ struct atmel_private *priv = netdev_priv(dev);
+ int i;
+ static const u8 bcast[] = { 255, 255, 255, 255, 255, 255 };
+ unsigned long flags;
+
+ if (awrq->sa_family != ARPHRD_ETHER)
+ return -EINVAL;
+
+ if (memcmp(bcast, awrq->sa_data, 6) == 0) {
+ del_timer_sync(&priv->management_timer);
+ spin_lock_irqsave(&priv->irqlock, flags);
+ atmel_scan(priv, 1);
+ spin_unlock_irqrestore(&priv->irqlock, flags);
+ return 0;
+ }
+
+ for(i=0; i<priv->BSS_list_entries; i++) {
+ if (memcmp(priv->BSSinfo[i].BSSID, awrq->sa_data, 6) == 0) {
+ if (!priv->wep_is_on && priv->BSSinfo[i].UsingWEP) {
+ return -EINVAL;
+ } else if (priv->wep_is_on && !priv->BSSinfo[i].UsingWEP) {
+ return -EINVAL;
+ } else {
+ del_timer_sync(&priv->management_timer);
+ spin_lock_irqsave(&priv->irqlock, flags);
+ atmel_join_bss(priv, i);
+ spin_unlock_irqrestore(&priv->irqlock, flags);
+ return 0;
+ }
+ }
+ }
+
+ return -EINVAL;
+}
+
+static int atmel_config_commit(struct net_device *dev,
+ struct iw_request_info *info, /* NULL */
+ void *zwrq, /* NULL */
+ char *extra) /* NULL */
+{
+ return atmel_open(dev);
+}
+
+static const iw_handler atmel_handler[] =
+{
+ (iw_handler) atmel_config_commit, /* SIOCSIWCOMMIT */
+ (iw_handler) atmel_get_name, /* SIOCGIWNAME */
+ (iw_handler) NULL, /* SIOCSIWNWID */
+ (iw_handler) NULL, /* SIOCGIWNWID */
+ (iw_handler) atmel_set_freq, /* SIOCSIWFREQ */
+ (iw_handler) atmel_get_freq, /* SIOCGIWFREQ */
+ (iw_handler) atmel_set_mode, /* SIOCSIWMODE */
+ (iw_handler) atmel_get_mode, /* SIOCGIWMODE */
+ (iw_handler) NULL, /* SIOCSIWSENS */
+ (iw_handler) NULL, /* SIOCGIWSENS */
+ (iw_handler) NULL, /* SIOCSIWRANGE */
+ (iw_handler) atmel_get_range, /* SIOCGIWRANGE */
+ (iw_handler) NULL, /* SIOCSIWPRIV */
+ (iw_handler) NULL, /* SIOCGIWPRIV */
+ (iw_handler) NULL, /* SIOCSIWSTATS */
+ (iw_handler) NULL, /* SIOCGIWSTATS */
+ (iw_handler) NULL, /* SIOCSIWSPY */
+ (iw_handler) NULL, /* SIOCGIWSPY */
+ (iw_handler) NULL, /* -- hole -- */
+ (iw_handler) NULL, /* -- hole -- */
+ (iw_handler) atmel_set_wap, /* SIOCSIWAP */
+ (iw_handler) atmel_get_wap, /* SIOCGIWAP */
+ (iw_handler) NULL, /* -- hole -- */
+ (iw_handler) NULL, /* SIOCGIWAPLIST */
+ (iw_handler) atmel_set_scan, /* SIOCSIWSCAN */
+ (iw_handler) atmel_get_scan, /* SIOCGIWSCAN */
+ (iw_handler) atmel_set_essid, /* SIOCSIWESSID */
+ (iw_handler) atmel_get_essid, /* SIOCGIWESSID */
+ (iw_handler) NULL, /* SIOCSIWNICKN */
+ (iw_handler) NULL, /* SIOCGIWNICKN */
+ (iw_handler) NULL, /* -- hole -- */
+ (iw_handler) NULL, /* -- hole -- */
+ (iw_handler) atmel_set_rate, /* SIOCSIWRATE */
+ (iw_handler) atmel_get_rate, /* SIOCGIWRATE */
+ (iw_handler) atmel_set_rts, /* SIOCSIWRTS */
+ (iw_handler) atmel_get_rts, /* SIOCGIWRTS */
+ (iw_handler) atmel_set_frag, /* SIOCSIWFRAG */
+ (iw_handler) atmel_get_frag, /* SIOCGIWFRAG */
+ (iw_handler) NULL, /* SIOCSIWTXPOW */
+ (iw_handler) NULL, /* SIOCGIWTXPOW */
+ (iw_handler) atmel_set_retry, /* SIOCSIWRETRY */
+ (iw_handler) atmel_get_retry, /* SIOCGIWRETRY */
+ (iw_handler) atmel_set_encode, /* SIOCSIWENCODE */
+ (iw_handler) atmel_get_encode, /* SIOCGIWENCODE */
+ (iw_handler) atmel_set_power, /* SIOCSIWPOWER */
+ (iw_handler) atmel_get_power, /* SIOCGIWPOWER */
+};
+
+
+static const iw_handler atmel_private_handler[] =
+{
+ NULL, /* SIOCIWFIRSTPRIV */
+};
+
+typedef struct atmel_priv_ioctl {
+ char id[32];
+ unsigned char __user *data;
+ unsigned short len;
+} atmel_priv_ioctl;
+
+
+#define ATMELFWL SIOCIWFIRSTPRIV
+#define ATMELIDIFC ATMELFWL + 1
+#define ATMELRD ATMELFWL + 2
+#define ATMELMAGIC 0x51807
+#define REGDOMAINSZ 20
+
+static const struct iw_priv_args atmel_private_args[] = {
+/*{ cmd, set_args, get_args, name } */
+ { ATMELFWL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (atmel_priv_ioctl), IW_PRIV_TYPE_NONE, "atmelfwl" },
+ { ATMELIDIFC, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "atmelidifc" },
+ { ATMELRD, IW_PRIV_TYPE_CHAR | REGDOMAINSZ, IW_PRIV_TYPE_NONE, "regdomain" },
+};
+
+static const struct iw_handler_def atmel_handler_def =
+{
+ .num_standard = sizeof(atmel_handler)/sizeof(iw_handler),
+ .num_private = sizeof(atmel_private_handler)/sizeof(iw_handler),
+ .num_private_args = sizeof(atmel_private_args)/sizeof(struct iw_priv_args),
+ .standard = (iw_handler *) atmel_handler,
+ .private = (iw_handler *) atmel_private_handler,
+ .private_args = (struct iw_priv_args *) atmel_private_args
+};
+
+static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+{
+ int i, rc = 0;
+ struct atmel_private *priv = netdev_priv(dev);
+ atmel_priv_ioctl com;
+ struct iwreq *wrq = (struct iwreq *) rq;
+ unsigned char *new_firmware;
+ char domain[REGDOMAINSZ+1];
+
+ switch (cmd) {
+ case SIOCGIWPRIV:
+ if(wrq->u.data.pointer) {
+ /* Set the number of ioctl available */
+ wrq->u.data.length = sizeof(atmel_private_args) / sizeof(atmel_private_args[0]);
+
+ /* Copy structure to the user buffer */
+ if (copy_to_user(wrq->u.data.pointer,
+ (u_char *) atmel_private_args,
+ sizeof(atmel_private_args)))
+ rc = -EFAULT;
+ }
+ break;
+
+ case ATMELIDIFC:
+ wrq->u.param.value = ATMELMAGIC;
+ break;
+
+ case ATMELFWL:
+ if (copy_from_user(&com, rq->ifr_data, sizeof(com))) {
+ rc = -EFAULT;
+ break;
+ }
+
+ if (!capable(CAP_NET_ADMIN)) {
+ rc = -EPERM;
+ break;
+ }
+
+ if (!(new_firmware = kmalloc(com.len, GFP_KERNEL))) {
+ rc = -ENOMEM;
+ break;
+ }
+
+ if (copy_from_user(new_firmware, com.data, com.len)) {
+ kfree(new_firmware);
+ rc = -EFAULT;
+ break;
+ }
+
+ if (priv->firmware)
+ kfree(priv->firmware);
+
+ priv->firmware = new_firmware;
+ priv->firmware_length = com.len;
+ strncpy(priv->firmware_id, com.id, 31);
+ priv->firmware_id[31] = '\0';
+ break;
+
+ case ATMELRD:
+ if (copy_from_user(domain, rq->ifr_data, REGDOMAINSZ)) {
+ rc = -EFAULT;
+ break;
+ }
+
+ if (!capable(CAP_NET_ADMIN)) {
+ rc = -EPERM;
+ break;
+ }
+
+ domain[REGDOMAINSZ] = 0;
+ rc = -EINVAL;
+ for (i = 0; i < sizeof(channel_table)/sizeof(channel_table[0]); i++) {
+ /* strcasecmp doesn't exist in the library */
+ char *a = channel_table[i].name;
+ char *b = domain;
+ while (*a) {
+ char c1 = *a++;
+ char c2 = *b++;
+ if (tolower(c1) != tolower(c2))
+ break;
+ }
+ if (!*a && !*b) {
+ priv->config_reg_domain = channel_table[i].reg_domain;
+ rc = 0;
+ }
+ }
+
+ if (rc == 0 && priv->station_state != STATION_STATE_DOWN)
+ rc = atmel_open(dev);
+ break;
+
+ default:
+ rc = -EOPNOTSUPP;
+ }
+
+ return rc;
+}
+
+struct auth_body {
+ u16 alg;
+ u16 trans_seq;
+ u16 status;
+ u8 el_id;
+ u8 chall_text_len;
+ u8 chall_text[253];
+};
+
+static void atmel_enter_state(struct atmel_private *priv, int new_state)
+{
+ int old_state = priv->station_state;
+
+ if (new_state == old_state)
+ return;
+
+ priv->station_state = new_state;
+
+ if (new_state == STATION_STATE_READY) {
+ netif_start_queue(priv->dev);
+ netif_carrier_on(priv->dev);
+ }
+
+ if (old_state == STATION_STATE_READY) {
+ netif_carrier_off(priv->dev);
+ if (netif_running(priv->dev))
+ netif_stop_queue(priv->dev);
+ priv->last_beacon_timestamp = 0;
+ }
+}
+
+static void atmel_scan(struct atmel_private *priv, int specific_ssid)
+{
+ struct {
+ u8 BSSID[6];
+ u8 SSID[MAX_SSID_LENGTH];
+ u8 scan_type;
+ u8 channel;
+ u16 BSS_type;
+ u16 min_channel_time;
+ u16 max_channel_time;
+ u8 options;
+ u8 SSID_size;
+ } cmd;
+
+ memset(cmd.BSSID, 0xff, 6);
+
+ if (priv->fast_scan) {
+ cmd.SSID_size = priv->SSID_size;
+ memcpy(cmd.SSID, priv->SSID, priv->SSID_size);
+ cmd.min_channel_time = cpu_to_le16(10);
+ cmd.max_channel_time = cpu_to_le16(50);
+ } else {
+ priv->BSS_list_entries = 0;
+ cmd.SSID_size = 0;
+ cmd.min_channel_time = cpu_to_le16(10);
+ cmd.max_channel_time = cpu_to_le16(120);
+ }
+
+ cmd.options = 0;
+
+ if (!specific_ssid)
+ cmd.options |= SCAN_OPTIONS_SITE_SURVEY;
+
+ cmd.channel = (priv->channel & 0x7f);
+ cmd.scan_type = SCAN_TYPE_ACTIVE;
+ cmd.BSS_type = cpu_to_le16(priv->operating_mode == IW_MODE_ADHOC ?
+ BSS_TYPE_AD_HOC : BSS_TYPE_INFRASTRUCTURE);
+
+ atmel_send_command(priv, CMD_Scan, &cmd, sizeof(cmd));
+
+ /* This must come after all hardware access to avoid being messed up
+ by stuff happening in interrupt context after we leave STATE_DOWN */
+ atmel_enter_state(priv, STATION_STATE_SCANNING);
+}
+
+static void join(struct atmel_private *priv, int type)
+{
+ struct {
+ u8 BSSID[6];
+ u8 SSID[MAX_SSID_LENGTH];
+ u8 BSS_type; /* this is a short in a scan command - weird */
+ u8 channel;
+ u16 timeout;
+ u8 SSID_size;
+ u8 reserved;
+ } cmd;
+
+ cmd.SSID_size = priv->SSID_size;
+ memcpy(cmd.SSID, priv->SSID, priv->SSID_size);
+ memcpy(cmd.BSSID, priv->CurrentBSSID, 6);
+ cmd.channel = (priv->channel & 0x7f);
+ cmd.BSS_type = type;
+ cmd.timeout = cpu_to_le16(2000);
+
+ atmel_send_command(priv, CMD_Join, &cmd, sizeof(cmd));
+}
+
+
+static void start(struct atmel_private *priv, int type)
+{
+ struct {
+ u8 BSSID[6];
+ u8 SSID[MAX_SSID_LENGTH];
+ u8 BSS_type;
+ u8 channel;
+ u8 SSID_size;
+ u8 reserved[3];
+ } cmd;
+
+ cmd.SSID_size = priv->SSID_size;
+ memcpy(cmd.SSID, priv->SSID, priv->SSID_size);
+ memcpy(cmd.BSSID, priv->BSSID, 6);
+ cmd.BSS_type = type;
+ cmd.channel = (priv->channel & 0x7f);
+
+ atmel_send_command(priv, CMD_Start, &cmd, sizeof(cmd));
+}
+
+static void handle_beacon_probe(struct atmel_private *priv, u16 capability, u8 channel)
+{
+ int rejoin = 0;
+ int new = capability & C80211_MGMT_CAPABILITY_ShortPreamble ?
+ SHORT_PREAMBLE : LONG_PREAMBLE;
+
+ if (priv->preamble != new) {
+ priv->preamble = new;
+ rejoin = 1;
+ atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_PREAMBLE_TYPE, new);
+ }
+
+ if (priv->channel != channel) {
+ priv->channel = channel;
+ rejoin = 1;
+ atmel_set_mib8(priv, Phy_Mib_Type, PHY_MIB_CHANNEL_POS, channel);
+ }
+
+ if (rejoin) {
+ priv->station_is_associated = 0;
+ atmel_enter_state(priv, STATION_STATE_JOINNING);
+
+ if (priv->operating_mode == IW_MODE_INFRA)
+ join(priv, BSS_TYPE_INFRASTRUCTURE);
+ else
+ join(priv, BSS_TYPE_AD_HOC);
+ }
+}
+
+
+static void send_authentication_request(struct atmel_private *priv, u8 *challenge, int challenge_len)
+{
+ struct ieee802_11_hdr header;
+ struct auth_body auth;
+
+ header.frame_ctl = cpu_to_le16(IEEE802_11_FTYPE_MGMT | IEEE802_11_STYPE_AUTH);
+ header.duration_id = cpu_to_le16(0x8000);
+ header.seq_ctl = 0;
+ memcpy(header.addr1, priv->CurrentBSSID, 6);
+ memcpy(header.addr2, priv->dev->dev_addr, 6);
+ memcpy(header.addr3, priv->CurrentBSSID, 6);
+
+ if (priv->wep_is_on) {
+ auth.alg = cpu_to_le16(C80211_MGMT_AAN_SHAREDKEY);
+ /* no WEP for authentication frames with TrSeqNo 1 */
+ if (priv->CurrentAuthentTransactionSeqNum != 1)
+ header.frame_ctl |= cpu_to_le16(IEEE802_11_FCTL_WEP);
+ } else {
+ auth.alg = cpu_to_le16(C80211_MGMT_AAN_OPENSYSTEM);
+ }
+
+ auth.status = 0;
+ auth.trans_seq = cpu_to_le16(priv->CurrentAuthentTransactionSeqNum);
+ priv->ExpectedAuthentTransactionSeqNum = priv->CurrentAuthentTransactionSeqNum+1;
+ priv->CurrentAuthentTransactionSeqNum += 2;
+
+ if (challenge_len != 0) {
+ auth.el_id = 16; /* challenge_text */
+ auth.chall_text_len = challenge_len;
+ memcpy(auth.chall_text, challenge, challenge_len);
+ atmel_transmit_management_frame(priv, &header, (u8 *)&auth, 8 + challenge_len);
+ } else {
+ atmel_transmit_management_frame(priv, &header, (u8 *)&auth, 6);
+ }
+}
+
+static void send_association_request(struct atmel_private *priv, int is_reassoc)
+{
+ u8 *ssid_el_p;
+ int bodysize;
+ struct ieee802_11_hdr header;
+ struct ass_req_format {
+ u16 capability;
+ u16 listen_interval;
+ u8 ap[6]; /* nothing after here directly accessible */
+ u8 ssid_el_id;
+ u8 ssid_len;
+ u8 ssid[MAX_SSID_LENGTH];
+ u8 sup_rates_el_id;
+ u8 sup_rates_len;
+ u8 rates[4];
+ } body;
+
+ header.frame_ctl = cpu_to_le16(IEEE802_11_FTYPE_MGMT |
+ (is_reassoc ? IEEE802_11_STYPE_REASSOC_REQ : IEEE802_11_STYPE_ASSOC_REQ));
+ header.duration_id = cpu_to_le16(0x8000);
+ header.seq_ctl = 0;
+
+ memcpy(header.addr1, priv->CurrentBSSID, 6);
+ memcpy(header.addr2, priv->dev->dev_addr, 6);
+ memcpy(header.addr3, priv->CurrentBSSID, 6);
+
+ body.capability = cpu_to_le16(C80211_MGMT_CAPABILITY_ESS);
+ if (priv->wep_is_on)
+ body.capability |= cpu_to_le16(C80211_MGMT_CAPABILITY_Privacy);
+ if (priv->preamble == SHORT_PREAMBLE)
+ body.capability |= cpu_to_le16(C80211_MGMT_CAPABILITY_ShortPreamble);
+
+ body.listen_interval = cpu_to_le16(priv->listen_interval * priv->beacon_period);
+
+ /* current AP address - only in reassoc frame */
+ if (is_reassoc) {
+ memcpy(body.ap, priv->CurrentBSSID, 6);
+ ssid_el_p = (u8 *)&body.ssid_el_id;
+ bodysize = 18 + priv->SSID_size;
+ } else {
+ ssid_el_p = (u8 *)&body.ap[0];
+ bodysize = 12 + priv->SSID_size;
+ }
+
+ ssid_el_p[0]= C80211_MGMT_ElementID_SSID;
+ ssid_el_p[1] = priv->SSID_size;
+ memcpy(ssid_el_p + 2, priv->SSID, priv->SSID_size);
+ ssid_el_p[2 + priv->SSID_size] = C80211_MGMT_ElementID_SupportedRates;
+ ssid_el_p[3 + priv->SSID_size] = 4; /* len of suported rates */
+ memcpy(ssid_el_p + 4 + priv->SSID_size, atmel_basic_rates, 4);
+
+ atmel_transmit_management_frame(priv, &header, (void *)&body, bodysize);
+}
+
+static int is_frame_from_current_bss(struct atmel_private *priv, struct ieee802_11_hdr *header)
+{
+ if (le16_to_cpu(header->frame_ctl) & IEEE802_11_FCTL_FROMDS)
+ return memcmp(header->addr3, priv->CurrentBSSID, 6) == 0;
+ else
+ return memcmp(header->addr2, priv->CurrentBSSID, 6) == 0;
+}
+
+static int retrieve_bss(struct atmel_private *priv)
+{
+ int i;
+ int max_rssi = -128;
+ int max_index = -1;
+
+ if (priv->BSS_list_entries == 0)
+ return -1;
+
+ if (priv->connect_to_any_BSS) {
+ /* Select a BSS with the max-RSSI but of the same type and of the same WEP mode
+ and that it is not marked as 'bad' (i.e. we had previously failed to connect to
+ this BSS with the settings that we currently use) */
+ priv->current_BSS = 0;
+ for(i=0; i<priv->BSS_list_entries; i++) {
+ if (priv->operating_mode == priv->BSSinfo[i].BSStype &&
+ ((!priv->wep_is_on && !priv->BSSinfo[i].UsingWEP) ||
+ (priv->wep_is_on && priv->BSSinfo[i].UsingWEP)) &&
+ !(priv->BSSinfo[i].channel & 0x80)) {
+ max_rssi = priv->BSSinfo[i].RSSI;
+ priv->current_BSS = max_index = i;
+ }
+
+ }
+ return max_index;
+ }
+
+ for(i=0; i<priv->BSS_list_entries; i++) {
+ if (priv->SSID_size == priv->BSSinfo[i].SSIDsize &&
+ memcmp(priv->SSID, priv->BSSinfo[i].SSID, priv->SSID_size) == 0 &&
+ priv->operating_mode == priv->BSSinfo[i].BSStype &&
+ atmel_validate_channel(priv, priv->BSSinfo[i].channel) == 0) {
+ if (priv->BSSinfo[i].RSSI >= max_rssi) {
+ max_rssi = priv->BSSinfo[i].RSSI;
+ max_index = i;
+ }
+ }
+ }
+ return max_index;
+}
+
+
+static void store_bss_info(struct atmel_private *priv, struct ieee802_11_hdr *header,
+ u16 capability, u16 beacon_period, u8 channel, u8 rssi,
+ u8 ssid_len, u8 *ssid, int is_beacon)
+{
+ u8 *bss = capability & C80211_MGMT_CAPABILITY_ESS ? header->addr2 : header->addr3;
+ int i, index;
+
+ for (index = -1, i = 0; i < priv->BSS_list_entries; i++)
+ if (memcmp(bss, priv->BSSinfo[i].BSSID, 6) == 0)
+ index = i;
+
+ /* If we process a probe and an entry from this BSS exists
+ we will update the BSS entry with the info from this BSS.
+ If we process a beacon we will only update RSSI */
+
+ if (index == -1) {
+ if (priv->BSS_list_entries == MAX_BSS_ENTRIES)
+ return;
+ index = priv->BSS_list_entries++;
+ memcpy(priv->BSSinfo[index].BSSID, bss, 6);
+ priv->BSSinfo[index].RSSI = rssi;
+ } else {
+ if (rssi > priv->BSSinfo[index].RSSI)
+ priv->BSSinfo[index].RSSI = rssi;
+ if (is_beacon)
+ return;
+ }
+
+ priv->BSSinfo[index].channel = channel;
+ priv->BSSinfo[index].beacon_period = beacon_period;
+ priv->BSSinfo[index].UsingWEP = capability & C80211_MGMT_CAPABILITY_Privacy;
+ memcpy(priv->BSSinfo[index].SSID, ssid, ssid_len);
+ priv->BSSinfo[index].SSIDsize = ssid_len;
+
+ if (capability & C80211_MGMT_CAPABILITY_IBSS)
+ priv->BSSinfo[index].BSStype = IW_MODE_ADHOC;
+ else if (capability & C80211_MGMT_CAPABILITY_ESS)
+ priv->BSSinfo[index].BSStype =IW_MODE_INFRA;
+
+ priv->BSSinfo[index].preamble = capability & C80211_MGMT_CAPABILITY_ShortPreamble ?
+ SHORT_PREAMBLE : LONG_PREAMBLE;
+}
+
+static void authenticate(struct atmel_private *priv, u16 frame_len)
+{
+ struct auth_body *auth = (struct auth_body *)priv->rx_buf;
+ u16 status = le16_to_cpu(auth->status);
+ u16 trans_seq_no = le16_to_cpu(auth->trans_seq);
+
+ if (status == C80211_MGMT_SC_Success && !priv->wep_is_on) {
+ /* no WEP */
+ if (priv->station_was_associated) {
+ atmel_enter_state(priv, STATION_STATE_REASSOCIATING);
+ send_association_request(priv, 1);
+ return;
+ } else {
+ atmel_enter_state(priv, STATION_STATE_ASSOCIATING);
+ send_association_request(priv, 0);
+ return;
+ }
+ }
+
+ if (status == C80211_MGMT_SC_Success && priv->wep_is_on) {
+ /* WEP */
+ if (trans_seq_no != priv->ExpectedAuthentTransactionSeqNum)
+ return;
+
+ if (trans_seq_no == 0x0002 &&
+ auth->el_id == C80211_MGMT_ElementID_ChallengeText) {
+ send_authentication_request(priv, auth->chall_text, auth->chall_text_len);
+ return;
+ }
+
+ if (trans_seq_no == 0x0004) {
+ if(priv->station_was_associated) {
+ atmel_enter_state(priv, STATION_STATE_REASSOCIATING);
+ send_association_request(priv, 1);
+ return;
+ } else {
+ atmel_enter_state(priv, STATION_STATE_ASSOCIATING);
+ send_association_request(priv, 0);
+ return;
+ }
+ }
+ }
+
+ if (status == C80211_MGMT_SC_AuthAlgNotSupported && priv->connect_to_any_BSS) {
+ int bss_index;
+
+ priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80;
+
+ if ((bss_index = retrieve_bss(priv)) != -1) {
+ atmel_join_bss(priv, bss_index);
+ return;
+ }
+ }
+
+
+ priv->AuthenticationRequestRetryCnt = 0;
+ atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
+ priv->station_is_associated = 0;
+}
+
+static void associate(struct atmel_private *priv, u16 frame_len, u16 subtype)
+{
+ struct ass_resp_format {
+ u16 capability;
+ u16 status;
+ u16 ass_id;
+ u8 el_id;
+ u8 length;
+ u8 rates[4];
+ } *ass_resp = (struct ass_resp_format *)priv->rx_buf;
+
+ u16 status = le16_to_cpu(ass_resp->status);
+ u16 ass_id = le16_to_cpu(ass_resp->ass_id);
+ u16 rates_len = ass_resp->length > 4 ? 4 : ass_resp->length;
+
+ if (frame_len < 8 + rates_len)
+ return;
+
+ if (status == C80211_MGMT_SC_Success) {
+ if (subtype == C80211_SUBTYPE_MGMT_ASS_RESPONSE)
+ priv->AssociationRequestRetryCnt = 0;
+ else
+ priv->ReAssociationRequestRetryCnt = 0;
+
+ atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_STATION_ID_POS, ass_id & 0x3fff);
+ atmel_set_mib(priv, Phy_Mib_Type, PHY_MIB_RATE_SET_POS, ass_resp->rates, rates_len);
+ if (priv->power_mode == 0) {
+ priv->listen_interval = 1;
+ atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE);
+ atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1);
+ } else {
+ priv->listen_interval = 2;
+ atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, PS_MODE);
+ atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 2);
+ }
+
+ priv->station_is_associated = 1;
+ priv->station_was_associated = 1;
+ atmel_enter_state(priv, STATION_STATE_READY);
+ return;
+ }
+
+ if (subtype == C80211_SUBTYPE_MGMT_ASS_RESPONSE &&
+ status != C80211_MGMT_SC_AssDeniedBSSRate &&
+ status != C80211_MGMT_SC_SupportCapabilities &&
+ priv->AssociationRequestRetryCnt < MAX_ASSOCIATION_RETRIES) {
+ mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
+ priv->AssociationRequestRetryCnt++;
+ send_association_request(priv, 0);
+ return;
+ }
+
+ if (subtype == C80211_SUBTYPE_MGMT_REASS_RESPONSE &&
+ status != C80211_MGMT_SC_AssDeniedBSSRate &&
+ status != C80211_MGMT_SC_SupportCapabilities &&
+ priv->AssociationRequestRetryCnt < MAX_ASSOCIATION_RETRIES) {
+ mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
+ priv->ReAssociationRequestRetryCnt++;
+ send_association_request(priv, 1);
+ return;
+ }
+
+ atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
+ priv->station_is_associated = 0;
+
+ if(priv->connect_to_any_BSS) {
+ int bss_index;
+ priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80;
+
+ if ((bss_index = retrieve_bss(priv)) != -1)
+ atmel_join_bss(priv, bss_index);
+
+ }
+}
+
+void atmel_join_bss(struct atmel_private *priv, int bss_index)
+{
+ struct bss_info *bss = &priv->BSSinfo[bss_index];
+
+ memcpy(priv->CurrentBSSID, bss->BSSID, 6);
+ memcpy(priv->SSID, bss->SSID, priv->SSID_size = bss->SSIDsize);
+
+ /* The WPA stuff cares about the current AP address */
+ if (priv->use_wpa)
+ build_wpa_mib(priv);
+
+ /* When switching to AdHoc turn OFF Power Save if needed */
+
+ if (bss->BSStype == IW_MODE_ADHOC &&
+ priv->operating_mode != IW_MODE_ADHOC &&
+ priv->power_mode) {
+ priv->power_mode = 0;
+ priv->listen_interval = 1;
+ atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE);
+ atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1);
+ }
+
+ priv->operating_mode = bss->BSStype;
+ priv->channel = bss->channel & 0x7f;
+ priv->beacon_period = bss->beacon_period;
+
+ if (priv->preamble != bss->preamble) {
+ priv->preamble = bss->preamble;
+ atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_PREAMBLE_TYPE, bss->preamble);
+ }
+
+ if (!priv->wep_is_on && bss->UsingWEP) {
+ atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
+ priv->station_is_associated = 0;
+ return;
+ }
+
+ if (priv->wep_is_on && !bss->UsingWEP) {
+ atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
+ priv->station_is_associated = 0;
+ return;
+ }
+
+ atmel_enter_state(priv, STATION_STATE_JOINNING);
+
+ if (priv->operating_mode == IW_MODE_INFRA)
+ join(priv, BSS_TYPE_INFRASTRUCTURE);
+ else
+ join(priv, BSS_TYPE_AD_HOC);
+}
+
+
+static void restart_search(struct atmel_private *priv)
+{
+ int bss_index;
+
+ if (!priv->connect_to_any_BSS) {
+ atmel_scan(priv, 1);
+ } else {
+ priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80;
+
+ if ((bss_index = retrieve_bss(priv)) != -1)
+ atmel_join_bss(priv, bss_index);
+ else
+ atmel_scan(priv, 0);
+
+ }
+}
+
+static void smooth_rssi(struct atmel_private *priv, u8 rssi)
+{
+ u8 old = priv->wstats.qual.level;
+ u8 max_rssi = 42; /* 502-rmfd-revd max by experiment, default for now */
+
+ switch (priv->firmware_type) {
+ case ATMEL_FW_TYPE_502E:
+ max_rssi = 63; /* 502-rmfd-reve max by experiment */
+ break;
+ default:
+ break;
+ }
+
+ rssi = rssi * 100 / max_rssi;
+ if((rssi + old) % 2)
+ priv->wstats.qual.level = ((rssi + old)/2) + 1;
+ else
+ priv->wstats.qual.level = ((rssi + old)/2);
+ priv->wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
+ priv->wstats.qual.updated &= ~IW_QUAL_LEVEL_INVALID;
+}
+
+static void atmel_smooth_qual(struct atmel_private *priv)
+{
+ unsigned long time_diff = (jiffies - priv->last_qual)/HZ;
+ while (time_diff--) {
+ priv->last_qual += HZ;
+ priv->wstats.qual.qual = priv->wstats.qual.qual/2;
+ priv->wstats.qual.qual +=
+ priv->beacons_this_sec * priv->beacon_period * (priv->wstats.qual.level + 100) / 4000;
+ priv->beacons_this_sec = 0;
+ }
+ priv->wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
+ priv->wstats.qual.updated &= ~IW_QUAL_QUAL_INVALID;
+}
+
+/* deals with incoming managment frames. */
+static void atmel_management_frame(struct atmel_private *priv, struct ieee802_11_hdr *header,
+ u16 frame_len, u8 rssi)
+{
+ u16 subtype;
+
+ switch (subtype = le16_to_cpu(header->frame_ctl) & IEEE802_11_FCTL_STYPE) {
+ case C80211_SUBTYPE_MGMT_BEACON :
+ case C80211_SUBTYPE_MGMT_ProbeResponse:
+
+ /* beacon frame has multiple variable-length fields -
+ never let an engineer loose with a data structure design. */
+ {
+ struct beacon_format {
+ u64 timestamp;
+ u16 interval;
+ u16 capability;
+ u8 ssid_el_id;
+ u8 ssid_length;
+ /* ssid here */
+ u8 rates_el_id;
+ u8 rates_length;
+ /* rates here */
+ u8 ds_el_id;
+ u8 ds_length;
+ /* ds here */
+ } *beacon = (struct beacon_format *)priv->rx_buf;
+
+ u8 channel, rates_length, ssid_length;
+ u64 timestamp = le64_to_cpu(beacon->timestamp);
+ u16 beacon_interval = le16_to_cpu(beacon->interval);
+ u16 capability = le16_to_cpu(beacon->capability);
+ u8 *beaconp = priv->rx_buf;
+ ssid_length = beacon->ssid_length;
+ /* this blows chunks. */
+ if (frame_len < 14 || frame_len < ssid_length + 15)
+ return;
+ rates_length = beaconp[beacon->ssid_length + 15];
+ if (frame_len < ssid_length + rates_length + 18)
+ return;
+ if (ssid_length > MAX_SSID_LENGTH)
+ return;
+ channel = beaconp[ssid_length + rates_length + 18];
+
+ if (priv->station_state == STATION_STATE_READY) {
+ smooth_rssi(priv, rssi);
+ if (is_frame_from_current_bss(priv, header)) {
+ priv->beacons_this_sec++;
+ atmel_smooth_qual(priv);
+ if (priv->last_beacon_timestamp) {
+ /* Note truncate this to 32 bits - kernel can't divide a long long */
+ u32 beacon_delay = timestamp - priv->last_beacon_timestamp;
+ int beacons = beacon_delay / (beacon_interval * 1000);
+ if (beacons > 1)
+ priv->wstats.miss.beacon += beacons - 1;
+ }
+ priv->last_beacon_timestamp = timestamp;
+ handle_beacon_probe(priv, capability, channel);
+ }
+ }
+
+ if (priv->station_state == STATION_STATE_SCANNING )
+ store_bss_info(priv, header, capability, beacon_interval, channel,
+ rssi, ssid_length, &beacon->rates_el_id,
+ subtype == C80211_SUBTYPE_MGMT_BEACON) ;
+ }
+ break;
+
+ case C80211_SUBTYPE_MGMT_Authentication:
+
+ if (priv->station_state == STATION_STATE_AUTHENTICATING)
+ authenticate(priv, frame_len);
+
+ break;
+
+ case C80211_SUBTYPE_MGMT_ASS_RESPONSE:
+ case C80211_SUBTYPE_MGMT_REASS_RESPONSE:
+
+ if (priv->station_state == STATION_STATE_ASSOCIATING ||
+ priv->station_state == STATION_STATE_REASSOCIATING)
+ associate(priv, frame_len, subtype);
+
+ break;
+
+ case C80211_SUBTYPE_MGMT_DISASSOSIATION:
+ if (priv->station_is_associated &&
+ priv->operating_mode == IW_MODE_INFRA &&
+ is_frame_from_current_bss(priv, header)) {
+ priv->station_was_associated = 0;
+ priv->station_is_associated = 0;
+
+ atmel_enter_state(priv, STATION_STATE_JOINNING);
+ join(priv, BSS_TYPE_INFRASTRUCTURE);
+ }
+
+ break;
+
+ case C80211_SUBTYPE_MGMT_Deauthentication:
+ if (priv->operating_mode == IW_MODE_INFRA &&
+ is_frame_from_current_bss(priv, header)) {
+ priv->station_was_associated = 0;
+
+ atmel_enter_state(priv, STATION_STATE_JOINNING);
+ join(priv, BSS_TYPE_INFRASTRUCTURE);
+ }
+
+ break;
+ }
+}
+
+/* run when timer expires */
+static void atmel_management_timer(u_long a)
+{
+ struct net_device *dev = (struct net_device *) a;
+ struct atmel_private *priv = netdev_priv(dev);
+ unsigned long flags;
+
+ /* Check if the card has been yanked. */
+ if (priv->card && priv->present_callback &&
+ !(*priv->present_callback)(priv->card))
+ return;
+
+ spin_lock_irqsave(&priv->irqlock, flags);
+
+ switch (priv->station_state) {
+
+ case STATION_STATE_AUTHENTICATING:
+ if (priv->AuthenticationRequestRetryCnt >= MAX_AUTHENTICATION_RETRIES) {
+ atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
+ priv->station_is_associated = 0;
+ priv->AuthenticationRequestRetryCnt = 0;
+ restart_search(priv);
+ } else {
+ priv->AuthenticationRequestRetryCnt++;
+ priv->CurrentAuthentTransactionSeqNum = 0x0001;
+ mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
+ send_authentication_request(priv, NULL, 0);
+ }
+
+ break;
+
+ case STATION_STATE_ASSOCIATING:
+ if (priv->AssociationRequestRetryCnt == MAX_ASSOCIATION_RETRIES) {
+ atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
+ priv->station_is_associated = 0;
+ priv->AssociationRequestRetryCnt = 0;
+ restart_search(priv);
+ } else {
+ priv->AssociationRequestRetryCnt++;
+ mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
+ send_association_request(priv, 0);
+ }
+
+ break;
+
+ case STATION_STATE_REASSOCIATING:
+ if (priv->ReAssociationRequestRetryCnt == MAX_ASSOCIATION_RETRIES) {
+ atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
+ priv->station_is_associated = 0;
+ priv->ReAssociationRequestRetryCnt = 0;
+ restart_search(priv);
+ } else {
+ priv->ReAssociationRequestRetryCnt++;
+ mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
+ send_association_request(priv, 1);
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ spin_unlock_irqrestore(&priv->irqlock, flags);
+}
+
+static void atmel_command_irq(struct atmel_private *priv)
+{
+ u8 status = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET));
+ u8 command = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_COMMAND_OFFSET));
+ int fast_scan;
+
+ if (status == CMD_STATUS_IDLE ||
+ status == CMD_STATUS_IN_PROGRESS)
+ return;
+
+ switch (command){
+
+ case CMD_Start:
+ if (status == CMD_STATUS_COMPLETE) {
+ priv->station_was_associated = priv->station_is_associated;
+ atmel_get_mib(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_CUR_BSSID_POS,
+ (u8 *)priv->CurrentBSSID, 6);
+ atmel_enter_state(priv, STATION_STATE_READY);
+ }
+ break;
+
+ case CMD_Scan:
+ fast_scan = priv->fast_scan;
+ priv->fast_scan = 0;
+
+ if (status != CMD_STATUS_COMPLETE) {
+ atmel_scan(priv, 1);
+ } else {
+ int bss_index = retrieve_bss(priv);
+ if (bss_index != -1) {
+ atmel_join_bss(priv, bss_index);
+ } else if (priv->operating_mode == IW_MODE_ADHOC &&
+ priv->SSID_size != 0) {
+ start(priv, BSS_TYPE_AD_HOC);
+ } else {
+ priv->fast_scan = !fast_scan;
+ atmel_scan(priv, 1);
+ }
+ priv->site_survey_state = SITE_SURVEY_COMPLETED;
+ }
+ break;
+
+ case CMD_SiteSurvey:
+ priv->fast_scan = 0;
+
+ if (status != CMD_STATUS_COMPLETE)
+ return;
+
+ priv->site_survey_state = SITE_SURVEY_COMPLETED;
+ if (priv->station_is_associated) {
+ atmel_enter_state(priv, STATION_STATE_READY);
+ } else {
+ atmel_scan(priv, 1);
+ }
+ break;
+
+ case CMD_Join:
+ if (status == CMD_STATUS_COMPLETE) {
+ if (priv->operating_mode == IW_MODE_ADHOC) {
+ priv->station_was_associated = priv->station_is_associated;
+ atmel_enter_state(priv, STATION_STATE_READY);
+ } else {
+ priv->AuthenticationRequestRetryCnt = 0;
+ atmel_enter_state(priv, STATION_STATE_AUTHENTICATING);
+
+ mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
+ priv->CurrentAuthentTransactionSeqNum = 0x0001;
+ send_authentication_request(priv, NULL, 0);
+ }
+ return;
+ }
+
+ atmel_scan(priv, 1);
+
+ }
+}
+
+static int atmel_wakeup_firmware(struct atmel_private *priv)
+{
+ struct host_info_struct *iface = &priv->host_info;
+ u16 mr1, mr3;
+ int i;
+
+ if (priv->card_type == CARD_TYPE_SPI_FLASH)
+ atmel_set_gcr(priv->dev, GCR_REMAP);
+
+ /* wake up on-board processor */
+ atmel_clear_gcr(priv->dev, 0x0040);
+ atmel_write16(priv->dev, BSR, BSS_SRAM);
+
+ if (priv->card_type == CARD_TYPE_SPI_FLASH)
+ mdelay(100);
+
+ /* and wait for it */
+ for (i = LOOP_RETRY_LIMIT; i; i--) {
+ mr1 = atmel_read16(priv->dev, MR1);
+ mr3 = atmel_read16(priv->dev, MR3);
+
+ if (mr3 & MAC_BOOT_COMPLETE)
+ break;
+ if (mr1 & MAC_BOOT_COMPLETE &&
+ priv->bus_type == BUS_TYPE_PCCARD)
+ break;
+ }
+
+ if (i == 0) {
+ printk(KERN_ALERT "%s: MAC failed to boot.\n", priv->dev->name);
+ return 0;
+ }
+
+ if ((priv->host_info_base = atmel_read16(priv->dev, MR2)) == 0xffff) {
+ printk(KERN_ALERT "%s: card missing.\n", priv->dev->name);
+ return 0;
+ }
+
+ /* now check for completion of MAC initialization through
+ the FunCtrl field of the IFACE, poll MR1 to detect completion of
+ MAC initialization, check completion status, set interrupt mask,
+ enables interrupts and calls Tx and Rx initialization functions */
+
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET), FUNC_CTRL_INIT_COMPLETE);
+
+ for (i = LOOP_RETRY_LIMIT; i; i--) {
+ mr1 = atmel_read16(priv->dev, MR1);
+ mr3 = atmel_read16(priv->dev, MR3);
+
+ if (mr3 & MAC_INIT_COMPLETE)
+ break;
+ if (mr1 & MAC_INIT_COMPLETE &&
+ priv->bus_type == BUS_TYPE_PCCARD)
+ break;
+ }
+
+ if (i == 0) {
+ printk(KERN_ALERT "%s: MAC failed to initialise.\n", priv->dev->name);
+ return 0;
+ }
+
+ /* Check for MAC_INIT_OK only on the register that the MAC_INIT_OK was set */
+ if ((mr3 & MAC_INIT_COMPLETE) &&
+ !(atmel_read16(priv->dev, MR3) & MAC_INIT_OK)) {
+ printk(KERN_ALERT "%s: MAC failed MR3 self-test.\n", priv->dev->name);
+ return 0;
+ }
+ if ((mr1 & MAC_INIT_COMPLETE) &&
+ !(atmel_read16(priv->dev, MR1) & MAC_INIT_OK)) {
+ printk(KERN_ALERT "%s: MAC failed MR1 self-test.\n", priv->dev->name);
+ return 0;
+ }
+
+ atmel_copy_to_host(priv->dev, (unsigned char *)iface,
+ priv->host_info_base, sizeof(*iface));
+
+ iface->tx_buff_pos = le16_to_cpu(iface->tx_buff_pos);
+ iface->tx_buff_size = le16_to_cpu(iface->tx_buff_size);
+ iface->tx_desc_pos = le16_to_cpu(iface->tx_desc_pos);
+ iface->tx_desc_count = le16_to_cpu(iface->tx_desc_count);
+ iface->rx_buff_pos = le16_to_cpu(iface->rx_buff_pos);
+ iface->rx_buff_size = le16_to_cpu(iface->rx_buff_size);
+ iface->rx_desc_pos = le16_to_cpu(iface->rx_desc_pos);
+ iface->rx_desc_count = le16_to_cpu(iface->rx_desc_count);
+ iface->build_version = le16_to_cpu(iface->build_version);
+ iface->command_pos = le16_to_cpu(iface->command_pos);
+ iface->major_version = le16_to_cpu(iface->major_version);
+ iface->minor_version = le16_to_cpu(iface->minor_version);
+ iface->func_ctrl = le16_to_cpu(iface->func_ctrl);
+ iface->mac_status = le16_to_cpu(iface->mac_status);
+
+ return 1;
+}
+
+/* determine type of memory and MAC address */
+static int probe_atmel_card(struct net_device *dev)
+{
+ int rc = 0;
+ struct atmel_private *priv = netdev_priv(dev);
+
+ /* reset pccard */
+ if (priv->bus_type == BUS_TYPE_PCCARD)
+ atmel_write16(dev, GCR, 0x0060);
+
+ atmel_write16(dev, GCR, 0x0040);
+ mdelay(500);
+
+ if (atmel_read16(dev, MR2) == 0) {
+ /* No stored firmware so load a small stub which just
+ tells us the MAC address */
+ int i;
+ priv->card_type = CARD_TYPE_EEPROM;
+ atmel_write16(dev, BSR, BSS_IRAM);
+ atmel_copy_to_card(dev, 0, mac_reader, sizeof(mac_reader));
+ atmel_set_gcr(dev, GCR_REMAP);
+ atmel_clear_gcr(priv->dev, 0x0040);
+ atmel_write16(dev, BSR, BSS_SRAM);
+ for (i = LOOP_RETRY_LIMIT; i; i--)
+ if (atmel_read16(dev, MR3) & MAC_BOOT_COMPLETE)
+ break;
+ if (i == 0) {
+ printk(KERN_ALERT "%s: MAC failed to boot MAC address reader.\n", dev->name);
+ } else {
+ atmel_copy_to_host(dev, dev->dev_addr, atmel_read16(dev, MR2), 6);
+ /* got address, now squash it again until the network
+ interface is opened */
+ if (priv->bus_type == BUS_TYPE_PCCARD)
+ atmel_write16(dev, GCR, 0x0060);
+ atmel_write16(dev, GCR, 0x0040);
+ rc = 1;
+ }
+ } else if (atmel_read16(dev, MR4) == 0) {
+ /* Mac address easy in this case. */
+ priv->card_type = CARD_TYPE_PARALLEL_FLASH;
+ atmel_write16(dev, BSR, 1);
+ atmel_copy_to_host(dev, dev->dev_addr, 0xc000, 6);
+ atmel_write16(dev, BSR, 0x200);
+ rc = 1;
+ } else {
+ /* Standard firmware in flash, boot it up and ask
+ for the Mac Address */
+ priv->card_type = CARD_TYPE_SPI_FLASH;
+ if (atmel_wakeup_firmware(priv)) {
+ atmel_get_mib(priv, Mac_Address_Mib_Type, 0, dev->dev_addr, 6);
+
+ /* got address, now squash it again until the network
+ interface is opened */
+ if (priv->bus_type == BUS_TYPE_PCCARD)
+ atmel_write16(dev, GCR, 0x0060);
+ atmel_write16(dev, GCR, 0x0040);
+ rc = 1;
+ }
+ }
+
+ if (rc) {
+ if (dev->dev_addr[0] == 0xFF) {
+ u8 default_mac[] = {0x00,0x04, 0x25, 0x00, 0x00, 0x00};
+ printk(KERN_ALERT "%s: *** Invalid MAC address. UPGRADE Firmware ****\n", dev->name);
+ memcpy(dev->dev_addr, default_mac, 6);
+ }
+ printk(KERN_INFO "%s: MAC address %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
+ dev->name,
+ dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
+ dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
+
+ }
+
+ return rc;
+}
+
+static void build_wep_mib(struct atmel_private *priv)
+/* Move the encyption information on the MIB structure.
+ This routine is for the pre-WPA firmware: later firmware has
+ a different format MIB and a different routine. */
+{
+ struct { /* NB this is matched to the hardware, don't change. */
+ u8 wep_is_on;
+ u8 default_key; /* 0..3 */
+ u8 reserved;
+ u8 exclude_unencrypted;
+
+ u32 WEPICV_error_count;
+ u32 WEP_excluded_count;
+
+ u8 wep_keys[MAX_ENCRYPTION_KEYS][13];
+ u8 encryption_level; /* 0, 1, 2 */
+ u8 reserved2[3];
+ } mib;
+ int i;
+
+ mib.wep_is_on = priv->wep_is_on;
+ if (priv->wep_is_on) {
+ if (priv->wep_key_len[priv->default_key] > 5)
+ mib.encryption_level = 2;
+ else
+ mib.encryption_level = 1;
+ } else {
+ mib.encryption_level = 0;
+ }
+
+ mib.default_key = priv->default_key;
+ mib.exclude_unencrypted = priv->exclude_unencrypted;
+
+ for(i = 0; i < MAX_ENCRYPTION_KEYS; i++)
+ memcpy(mib.wep_keys[i], priv->wep_keys[i], 13);
+
+ atmel_set_mib(priv, Mac_Wep_Mib_Type, 0, (u8 *)&mib, sizeof(mib));
+}
+
+static void build_wpa_mib(struct atmel_private *priv)
+{
+ /* This is for the later (WPA enabled) firmware. */
+
+ struct { /* NB this is matched to the hardware, don't change. */
+ u8 cipher_default_key_value[MAX_ENCRYPTION_KEYS][MAX_ENCRYPTION_KEY_SIZE];
+ u8 receiver_address[6];
+ u8 wep_is_on;
+ u8 default_key; /* 0..3 */
+ u8 group_key;
+ u8 exclude_unencrypted;
+ u8 encryption_type;
+ u8 reserved;
+
+ u32 WEPICV_error_count;
+ u32 WEP_excluded_count;
+
+ u8 key_RSC[4][8];
+ } mib;
+
+ int i;
+
+ mib.wep_is_on = priv->wep_is_on;
+ mib.exclude_unencrypted = priv->exclude_unencrypted;
+ memcpy(mib.receiver_address, priv->CurrentBSSID, 6);
+
+ /* zero all the keys before adding in valid ones. */
+ memset(mib.cipher_default_key_value, 0, sizeof(mib.cipher_default_key_value));
+
+ if (priv->wep_is_on) {
+ /* There's a comment in the Atmel code to the effect that this is only valid
+ when still using WEP, it may need to be set to something to use WPA */
+ memset(mib.key_RSC, 0, sizeof(mib.key_RSC));
+
+ mib.default_key = mib.group_key = 255;
+ for (i = 0; i < MAX_ENCRYPTION_KEYS; i++) {
+ if (priv->wep_key_len[i] > 0) {
+ memcpy(mib.cipher_default_key_value[i], priv->wep_keys[i], MAX_ENCRYPTION_KEY_SIZE);
+ if (i == priv->default_key) {
+ mib.default_key = i;
+ mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-1] = 7;
+ mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-2] = priv->pairwise_cipher_suite;
+ } else {
+ mib.group_key = i;
+ priv->group_cipher_suite = priv->pairwise_cipher_suite;
+ mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-1] = 1;
+ mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-2] = priv->group_cipher_suite;
+ }
+ }
+ }
+ if (mib.default_key == 255)
+ mib.default_key = mib.group_key != 255 ? mib.group_key : 0;
+ if (mib.group_key == 255)
+ mib.group_key = mib.default_key;
+
+ }
+
+ atmel_set_mib(priv, Mac_Wep_Mib_Type, 0, (u8 *)&mib, sizeof(mib));
+}
+
+static int reset_atmel_card(struct net_device *dev)
+{
+ /* do everything necessary to wake up the hardware, including
+ waiting for the lightning strike and throwing the knife switch....
+
+ set all the Mib values which matter in the card to match
+ their settings in the atmel_private structure. Some of these
+ can be altered on the fly, but many (WEP, infrastucture or ad-hoc)
+ can only be changed by tearing down the world and coming back through
+ here.
+
+ This routine is also responsible for initialising some
+ hardware-specific fields in the atmel_private structure,
+ including a copy of the firmware's hostinfo stucture
+ which is the route into the rest of the firmare datastructures. */
+
+ struct atmel_private *priv = netdev_priv(dev);
+ u8 configuration;
+
+ /* data to add to the firmware names, in priority order
+ this implemenents firmware versioning */
+
+ static char *firmware_modifier[] = {
+ "-wpa",
+ "",
+ NULL
+ };
+
+ /* reset pccard */
+ if (priv->bus_type == BUS_TYPE_PCCARD)
+ atmel_write16(priv->dev, GCR, 0x0060);
+
+ /* stop card , disable interrupts */
+ atmel_write16(priv->dev, GCR, 0x0040);
+
+ if (priv->card_type == CARD_TYPE_EEPROM) {
+ /* copy in firmware if needed */
+ const struct firmware *fw_entry = NULL;
+ unsigned char *fw;
+ int len = priv->firmware_length;
+ if (!(fw = priv->firmware)) {
+ if (priv->firmware_type == ATMEL_FW_TYPE_NONE) {
+ if (strlen(priv->firmware_id) == 0) {
+ printk(KERN_INFO
+ "%s: card type is unknown: assuming at76c502 firmware is OK.\n",
+ dev->name);
+ printk(KERN_INFO
+ "%s: if not, use the firmware= module parameter.\n",
+ dev->name);
+ strcpy(priv->firmware_id, "atmel_at76c502.bin");
+ }
+ if (request_firmware(&fw_entry, priv->firmware_id, priv->sys_dev) != 0) {
+ printk(KERN_ALERT
+ "%s: firmware %s is missing, cannot continue.\n",
+ dev->name, priv->firmware_id);
+ return 0;
+ }
+ } else {
+ int fw_index = 0;
+ int success = 0;
+
+ /* get firmware filename entry based on firmware type ID */
+ while (fw_table[fw_index].fw_type != priv->firmware_type
+ && fw_table[fw_index].fw_type != ATMEL_FW_TYPE_NONE)
+ fw_index++;
+
+ /* construct the actual firmware file name */
+ if (fw_table[fw_index].fw_type != ATMEL_FW_TYPE_NONE) {
+ int i;
+ for (i = 0; firmware_modifier[i]; i++) {
+ snprintf(priv->firmware_id, 32, "%s%s.%s", fw_table[fw_index].fw_file,
+ firmware_modifier[i], fw_table[fw_index].fw_file_ext);
+ priv->firmware_id[31] = '\0';
+ if (request_firmware(&fw_entry, priv->firmware_id, priv->sys_dev) == 0) {
+ success = 1;
+ break;
+ }
+ }
+ }
+ if (!success) {
+ printk(KERN_ALERT
+ "%s: firmware %s is missing, cannot start.\n",
+ dev->name, priv->firmware_id);
+ priv->firmware_id[0] = '\0';
+ return 0;
+ }
+ }
+
+ fw = fw_entry->data;
+ len = fw_entry->size;
+ }
+
+ if (len <= 0x6000) {
+ atmel_write16(priv->dev, BSR, BSS_IRAM);
+ atmel_copy_to_card(priv->dev, 0, fw, len);
+ atmel_set_gcr(priv->dev, GCR_REMAP);
+ } else {
+ /* Remap */
+ atmel_set_gcr(priv->dev, GCR_REMAP);
+ atmel_write16(priv->dev, BSR, BSS_IRAM);
+ atmel_copy_to_card(priv->dev, 0, fw, 0x6000);
+ atmel_write16(priv->dev, BSR, 0x2ff);
+ atmel_copy_to_card(priv->dev, 0x8000, &fw[0x6000], len - 0x6000);
+ }
+
+ if (fw_entry)
+ release_firmware(fw_entry);
+ }
+
+ if (!atmel_wakeup_firmware(priv))
+ return 0;
+
+ /* Check the version and set the correct flag for wpa stuff,
+ old and new firmware is incompatible.
+ The pre-wpa 3com firmware reports major version 5,
+ the wpa 3com firmware is major version 4 and doesn't need
+ the 3com broken-ness filter. */
+ priv->use_wpa = (priv->host_info.major_version == 4);
+ priv->radio_on_broken = (priv->host_info.major_version == 5);
+
+ /* unmask all irq sources */
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_INT_MASK_OFFSET), 0xff);
+
+ /* int Tx system and enable Tx */
+ atmel_wmem8(priv, atmel_tx(priv, TX_DESC_FLAGS_OFFSET, 0), 0);
+ atmel_wmem32(priv, atmel_tx(priv, TX_DESC_NEXT_OFFSET, 0), 0x80000000L);
+ atmel_wmem16(priv, atmel_tx(priv, TX_DESC_POS_OFFSET, 0), 0);
+ atmel_wmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, 0), 0);
+
+ priv->tx_desc_free = priv->host_info.tx_desc_count;
+ priv->tx_desc_head = 0;
+ priv->tx_desc_tail = 0;
+ priv->tx_desc_previous = 0;
+ priv->tx_free_mem = priv->host_info.tx_buff_size;
+ priv->tx_buff_head = 0;
+ priv->tx_buff_tail = 0;
+
+ configuration = atmel_rmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET));
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET),
+ configuration | FUNC_CTRL_TxENABLE);
+
+ /* init Rx system and enable */
+ priv->rx_desc_head = 0;
+
+ configuration = atmel_rmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET));
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET),
+ configuration | FUNC_CTRL_RxENABLE);
+
+ if (!priv->radio_on_broken) {
+ if (atmel_send_command_wait(priv, CMD_EnableRadio, NULL, 0) ==
+ CMD_STATUS_REJECTED_RADIO_OFF) {
+ printk(KERN_INFO
+ "%s: cannot turn the radio on. (Hey radio, you're beautiful!)\n",
+ dev->name);
+ return 0;
+ }
+ }
+
+ /* set up enough MIB values to run. */
+ atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_AUTO_TX_RATE_POS, priv->auto_tx_rate);
+ atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_TX_PROMISCUOUS_POS, PROM_MODE_OFF);
+ atmel_set_mib16(priv, Mac_Mib_Type, MAC_MIB_RTS_THRESHOLD_POS, priv->rts_threshold);
+ atmel_set_mib16(priv, Mac_Mib_Type, MAC_MIB_FRAG_THRESHOLD_POS, priv->frag_threshold);
+ atmel_set_mib8(priv, Mac_Mib_Type, MAC_MIB_SHORT_RETRY_POS, priv->short_retry);
+ atmel_set_mib8(priv, Mac_Mib_Type, MAC_MIB_LONG_RETRY_POS, priv->long_retry);
+ atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_PREAMBLE_TYPE, priv->preamble);
+ atmel_set_mib(priv, Mac_Address_Mib_Type, MAC_ADDR_MIB_MAC_ADDR_POS,
+ priv->dev->dev_addr, 6);
+ atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE);
+ atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1);
+ atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_BEACON_PER_POS, priv->default_beacon_period);
+ atmel_set_mib(priv, Phy_Mib_Type, PHY_MIB_RATE_SET_POS, atmel_basic_rates, 4);
+ atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_CUR_PRIVACY_POS, priv->wep_is_on);
+ if (priv->use_wpa)
+ build_wpa_mib(priv);
+ else
+ build_wep_mib(priv);
+
+ return 1;
+}
+
+static void atmel_send_command(struct atmel_private *priv, int command, void *cmd, int cmd_size)
+{
+ if (cmd)
+ atmel_copy_to_card(priv->dev, atmel_co(priv, CMD_BLOCK_PARAMETERS_OFFSET),
+ cmd, cmd_size);
+
+ atmel_wmem8(priv, atmel_co(priv, CMD_BLOCK_COMMAND_OFFSET), command);
+ atmel_wmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET), 0);
+}
+
+static int atmel_send_command_wait(struct atmel_private *priv, int command, void *cmd, int cmd_size)
+{
+ int i, status;
+
+ atmel_send_command(priv, command, cmd, cmd_size);
+
+ for (i = 5000; i; i--) {
+ status = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET));
+ if (status != CMD_STATUS_IDLE &&
+ status != CMD_STATUS_IN_PROGRESS)
+ break;
+ udelay(20);
+ }
+
+ if (i == 0) {
+ printk(KERN_ALERT "%s: failed to contact MAC.\n", priv->dev->name);
+ status = CMD_STATUS_HOST_ERROR;
+ } else {
+ if (command != CMD_EnableRadio)
+ status = CMD_STATUS_COMPLETE;
+ }
+
+ return status;
+}
+
+static u8 atmel_get_mib8(struct atmel_private *priv, u8 type, u8 index)
+{
+ struct get_set_mib m;
+ m.type = type;
+ m.size = 1;
+ m.index = index;
+
+ atmel_send_command_wait(priv, CMD_Get_MIB_Vars, &m, MIB_HEADER_SIZE + 1);
+ return atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_PARAMETERS_OFFSET + MIB_HEADER_SIZE));
+}
+
+static void atmel_set_mib8(struct atmel_private *priv, u8 type, u8 index, u8 data)
+{
+ struct get_set_mib m;
+ m.type = type;
+ m.size = 1;
+ m.index = index;
+ m.data[0] = data;
+
+ atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + 1);
+}
+
+static void atmel_set_mib16(struct atmel_private *priv, u8 type, u8 index, u16 data)
+{
+ struct get_set_mib m;
+ m.type = type;
+ m.size = 2;
+ m.index = index;
+ m.data[0] = data;
+ m.data[1] = data >> 8;
+
+ atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + 2);
+}
+
+static void atmel_set_mib(struct atmel_private *priv, u8 type, u8 index, u8 *data, int data_len)
+{
+ struct get_set_mib m;
+ m.type = type;
+ m.size = data_len;
+ m.index = index;
+
+ if (data_len > MIB_MAX_DATA_BYTES)
+ printk(KERN_ALERT "%s: MIB buffer too small.\n", priv->dev->name);
+
+ memcpy(m.data, data, data_len);
+ atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + data_len);
+}
+
+static void atmel_get_mib(struct atmel_private *priv, u8 type, u8 index, u8 *data, int data_len)
+{
+ struct get_set_mib m;
+ m.type = type;
+ m.size = data_len;
+ m.index = index;
+
+ if (data_len > MIB_MAX_DATA_BYTES)
+ printk(KERN_ALERT "%s: MIB buffer too small.\n", priv->dev->name);
+
+ atmel_send_command_wait(priv, CMD_Get_MIB_Vars, &m, MIB_HEADER_SIZE + data_len);
+ atmel_copy_to_host(priv->dev, data,
+ atmel_co(priv, CMD_BLOCK_PARAMETERS_OFFSET + MIB_HEADER_SIZE), data_len);
+}
+
+static void atmel_writeAR(struct net_device *dev, u16 data)
+{
+ int i;
+ outw(data, dev->base_addr + AR);
+ /* Address register appears to need some convincing..... */
+ for (i = 0; data != inw(dev->base_addr + AR) && i<10; i++)
+ outw(data, dev->base_addr + AR);
+}
+
+static void atmel_copy_to_card(struct net_device *dev, u16 dest, unsigned char *src, u16 len)
+{
+ int i;
+ atmel_writeAR(dev, dest);
+ if (dest % 2) {
+ atmel_write8(dev, DR, *src);
+ src++; len--;
+ }
+ for (i = len; i > 1 ; i -= 2) {
+ u8 lb = *src++;
+ u8 hb = *src++;
+ atmel_write16(dev, DR, lb | (hb << 8));
+ }
+ if (i)
+ atmel_write8(dev, DR, *src);
+}
+
+static void atmel_copy_to_host(struct net_device *dev, unsigned char *dest, u16 src, u16 len)
+{
+ int i;
+ atmel_writeAR(dev, src);
+ if (src % 2) {
+ *dest = atmel_read8(dev, DR);
+ dest++; len--;
+ }
+ for (i = len; i > 1 ; i -= 2) {
+ u16 hw = atmel_read16(dev, DR);
+ *dest++ = hw;
+ *dest++ = hw >> 8;
+ }
+ if (i)
+ *dest = atmel_read8(dev, DR);
+}
+
+static void atmel_set_gcr(struct net_device *dev, u16 mask)
+{
+ outw(inw(dev->base_addr + GCR) | mask, dev->base_addr + GCR);
+}
+
+static void atmel_clear_gcr(struct net_device *dev, u16 mask)
+{
+ outw(inw(dev->base_addr + GCR) & ~mask, dev->base_addr + GCR);
+}
+
+static int atmel_lock_mac(struct atmel_private *priv)
+{
+ int i, j = 20;
+ retry:
+ for (i = 5000; i; i--) {
+ if (!atmel_rmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_HOST_OFFSET)))
+ break;
+ udelay(20);
+ }
+
+ if (!i) return 0; /* timed out */
+
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 1);
+ if (atmel_rmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_HOST_OFFSET))) {
+ atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0);
+ if (!j--) return 0; /* timed out */
+ goto retry;
+ }
+
+ return 1;
+}
+
+static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data)
+{
+ atmel_writeAR(priv->dev, pos);
+ atmel_write16(priv->dev, DR, data); /* card is little-endian */
+ atmel_write16(priv->dev, DR, data >> 16);
+}
+
+/***************************************************************************/
+/* There follows the source form of the MAC address reading firmware */
+/***************************************************************************/
+#if 0
+
+/* Copyright 2003 Matthew T. Russotto */
+/* But derived from the Atmel 76C502 firmware written by Atmel and */
+/* included in "atmel wireless lan drivers" package */
+/**
+ This file is part of net.russotto.AtmelMACFW, hereto referred to
+ as AtmelMACFW
+
+ AtmelMACFW is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2
+ as published by the Free Software Foundation.
+
+ AtmelMACFW is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with AtmelMACFW; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+****************************************************************************/
+/* This firmware should work on the 76C502 RFMD, RFMD_D, and RFMD_E */
+/* It will probably work on the 76C504 and 76C502 RFMD_3COM */
+/* It only works on SPI EEPROM versions of the card. */
+
+/* This firmware initializes the SPI controller and clock, reads the MAC */
+/* address from the EEPROM into SRAM, and puts the SRAM offset of the MAC */
+/* address in MR2, and sets MR3 to 0x10 to indicate it is done */
+/* It also puts a complete copy of the EEPROM in SRAM with the offset in */
+/* MR4, for investigational purposes (maybe we can determine chip type */
+/* from that?) */
+
+ .org 0
+ .set MRBASE, 0x8000000
+ .set CPSR_INITIAL, 0xD3 /* IRQ/FIQ disabled, ARM mode, Supervisor state */
+ .set CPSR_USER, 0xD1 /* IRQ/FIQ disabled, ARM mode, USER state */
+ .set SRAM_BASE, 0x02000000
+ .set SP_BASE, 0x0F300000
+ .set UNK_BASE, 0x0F000000 /* Some internal device, but which one? */
+ .set SPI_CGEN_BASE, 0x0E000000 /* Some internal device, but which one? */
+ .set UNK3_BASE, 0x02014000 /* Some internal device, but which one? */
+ .set STACK_BASE, 0x5600
+ .set SP_SR, 0x10
+ .set SP_TDRE, 2 /* status register bit -- TDR empty */
+ .set SP_RDRF, 1 /* status register bit -- RDR full */
+ .set SP_SWRST, 0x80
+ .set SP_SPIEN, 0x1
+ .set SP_CR, 0 /* control register */
+ .set SP_MR, 4 /* mode register */
+ .set SP_RDR, 0x08 /* Read Data Register */
+ .set SP_TDR, 0x0C /* Transmit Data Register */
+ .set SP_CSR0, 0x30 /* chip select registers */
+ .set SP_CSR1, 0x34
+ .set SP_CSR2, 0x38
+ .set SP_CSR3, 0x3C
+ .set NVRAM_CMD_RDSR, 5 /* read status register */
+ .set NVRAM_CMD_READ, 3 /* read data */
+ .set NVRAM_SR_RDY, 1 /* RDY bit. This bit is inverted */
+ .set SPI_8CLOCKS, 0xFF /* Writing this to the TDR doesn't do anything to the
+ serial output, since SO is normally high. But it
+ does cause 8 clock cycles and thus 8 bits to be
+ clocked in to the chip. See Atmel's SPI
+ controller (e.g. AT91M55800) timing and 4K
+ SPI EEPROM manuals */
+
+ .set NVRAM_SCRATCH, 0x02000100 /* arbitrary area for scratchpad memory */
+ .set NVRAM_IMAGE, 0x02000200
+ .set NVRAM_LENGTH, 0x0200
+ .set MAC_ADDRESS_MIB, SRAM_BASE
+ .set MAC_ADDRESS_LENGTH, 6
+ .set MAC_BOOT_FLAG, 0x10
+ .set MR1, 0
+ .set MR2, 4
+ .set MR3, 8
+ .set MR4, 0xC
+RESET_VECTOR:
+ b RESET_HANDLER
+UNDEF_VECTOR:
+ b HALT1
+SWI_VECTOR:
+ b HALT1
+IABORT_VECTOR:
+ b HALT1
+DABORT_VECTOR:
+RESERVED_VECTOR:
+ b HALT1
+IRQ_VECTOR:
+ b HALT1
+FIQ_VECTOR:
+ b HALT1
+HALT1: b HALT1
+RESET_HANDLER:
+ mov r0, #CPSR_INITIAL
+ msr CPSR_c, r0 /* This is probably unnecessary */
+
+/* I'm guessing this is initializing clock generator electronics for SPI */
+ ldr r0, =SPI_CGEN_BASE
+ mov r1, #0
+ mov r1, r1, lsl #3
+ orr r1,r1, #0
+ str r1, [r0]
+ ldr r1, [r0, #28]
+ bic r1, r1, #16
+ str r1, [r0, #28]
+ mov r1, #1
+ str r1, [r0, #8]
+
+ ldr r0, =MRBASE
+ mov r1, #0
+ strh r1, [r0, #MR1]
+ strh r1, [r0, #MR2]
+ strh r1, [r0, #MR3]
+ strh r1, [r0, #MR4]
+
+ mov sp, #STACK_BASE
+ bl SP_INIT
+ mov r0, #10
+ bl DELAY9
+ bl GET_MAC_ADDR
+ bl GET_WHOLE_NVRAM
+ ldr r0, =MRBASE
+ ldr r1, =MAC_ADDRESS_MIB
+ strh r1, [r0, #MR2]
+ ldr r1, =NVRAM_IMAGE
+ strh r1, [r0, #MR4]
+ mov r1, #MAC_BOOT_FLAG
+ strh r1, [r0, #MR3]
+HALT2: b HALT2
+.func Get_Whole_NVRAM, GET_WHOLE_NVRAM
+GET_WHOLE_NVRAM:
+ stmdb sp!, {lr}
+ mov r2, #0 /* 0th bytes of NVRAM */
+ mov r3, #NVRAM_LENGTH
+ mov r1, #0 /* not used in routine */
+ ldr r0, =NVRAM_IMAGE
+ bl NVRAM_XFER
+ ldmia sp!, {lr}
+ bx lr
+.endfunc
+
+.func Get_MAC_Addr, GET_MAC_ADDR
+GET_MAC_ADDR:
+ stmdb sp!, {lr}
+ mov r2, #0x120 /* address of MAC Address within NVRAM */
+ mov r3, #MAC_ADDRESS_LENGTH
+ mov r1, #0 /* not used in routine */
+ ldr r0, =MAC_ADDRESS_MIB
+ bl NVRAM_XFER
+ ldmia sp!, {lr}
+ bx lr
+.endfunc
+.ltorg
+.func Delay9, DELAY9
+DELAY9:
+ adds r0, r0, r0, LSL #3 /* r0 = r0 * 9 */
+DELAYLOOP:
+ beq DELAY9_done
+ subs r0, r0, #1
+ b DELAYLOOP
+DELAY9_done:
+ bx lr
+.endfunc
+
+.func SP_Init, SP_INIT
+SP_INIT:
+ mov r1, #SP_SWRST
+ ldr r0, =SP_BASE
+ str r1, [r0, #SP_CR] /* reset the SPI */
+ mov r1, #0
+ str r1, [r0, #SP_CR] /* release SPI from reset state */
+ mov r1, #SP_SPIEN
+ str r1, [r0, #SP_MR] /* set the SPI to MASTER mode*/
+ str r1, [r0, #SP_CR] /* enable the SPI */
+
+/* My guess would be this turns on the SPI clock */
+ ldr r3, =SPI_CGEN_BASE
+ ldr r1, [r3, #28]
+ orr r1, r1, #0x2000
+ str r1, [r3, #28]
+
+ ldr r1, =0x2000c01
+ str r1, [r0, #SP_CSR0]
+ ldr r1, =0x2000201
+ str r1, [r0, #SP_CSR1]
+ str r1, [r0, #SP_CSR2]
+ str r1, [r0, #SP_CSR3]
+ ldr r1, [r0, #SP_SR]
+ ldr r0, [r0, #SP_RDR]
+ bx lr
+.endfunc
+.func NVRAM_Init, NVRAM_INIT
+NVRAM_INIT:
+ ldr r1, =SP_BASE
+ ldr r0, [r1, #SP_RDR]
+ mov r0, #NVRAM_CMD_RDSR
+ str r0, [r1, #SP_TDR]
+SP_loop1:
+ ldr r0, [r1, #SP_SR]
+ tst r0, #SP_TDRE
+ beq SP_loop1
+
+ mov r0, #SPI_8CLOCKS
+ str r0, [r1, #SP_TDR]
+SP_loop2:
+ ldr r0, [r1, #SP_SR]
+ tst r0, #SP_TDRE
+ beq SP_loop2
+
+ ldr r0, [r1, #SP_RDR]
+SP_loop3:
+ ldr r0, [r1, #SP_SR]
+ tst r0, #SP_RDRF
+ beq SP_loop3
+
+ ldr r0, [r1, #SP_RDR]
+ and r0, r0, #255
+ bx lr
+.endfunc
+
+.func NVRAM_Xfer, NVRAM_XFER
+ /* r0 = dest address */
+ /* r1 = not used */
+ /* r2 = src address within NVRAM */
+ /* r3 = length */
+NVRAM_XFER:
+ stmdb sp!, {r4, r5, lr}
+ mov r5, r0 /* save r0 (dest address) */
+ mov r4, r3 /* save r3 (length) */
+ mov r0, r2, LSR #5 /* SPI memories put A8 in the command field */
+ and r0, r0, #8
+ add r0, r0, #NVRAM_CMD_READ
+ ldr r1, =NVRAM_SCRATCH
+ strb r0, [r1, #0] /* save command in NVRAM_SCRATCH[0] */
+ strb r2, [r1, #1] /* save low byte of source address in NVRAM_SCRATCH[1] */
+_local1:
+ bl NVRAM_INIT
+ tst r0, #NVRAM_SR_RDY
+ bne _local1
+ mov r0, #20
+ bl DELAY9
+ mov r2, r4 /* length */
+ mov r1, r5 /* dest address */
+ mov r0, #2 /* bytes to transfer in command */
+ bl NVRAM_XFER2
+ ldmia sp!, {r4, r5, lr}
+ bx lr
+.endfunc
+
+.func NVRAM_Xfer2, NVRAM_XFER2
+NVRAM_XFER2:
+ stmdb sp!, {r4, r5, r6, lr}
+ ldr r4, =SP_BASE
+ mov r3, #0
+ cmp r0, #0
+ bls _local2
+ ldr r5, =NVRAM_SCRATCH
+_local4:
+ ldrb r6, [r5, r3]
+ str r6, [r4, #SP_TDR]
+_local3:
+ ldr r6, [r4, #SP_SR]
+ tst r6, #SP_TDRE
+ beq _local3
+ add r3, r3, #1
+ cmp r3, r0 /* r0 is # of bytes to send out (command+addr) */
+ blo _local4
+_local2:
+ mov r3, #SPI_8CLOCKS
+ str r3, [r4, #SP_TDR]
+ ldr r0, [r4, #SP_RDR]
+_local5:
+ ldr r0, [r4, #SP_SR]
+ tst r0, #SP_RDRF
+ beq _local5
+ ldr r0, [r4, #SP_RDR] /* what's this byte? It's the byte read while writing the TDR -- nonsense, because the NVRAM doesn't read and write at the same time */
+ mov r0, #0
+ cmp r2, #0 /* r2 is # of bytes to copy in */
+ bls _local6
+_local7:
+ ldr r5, [r4, #SP_SR]
+ tst r5, #SP_TDRE
+ beq _local7
+ str r3, [r4, #SP_TDR] /* r3 has SPI_8CLOCKS */
+_local8:
+ ldr r5, [r4, #SP_SR]
+ tst r5, #SP_RDRF
+ beq _local8
+ ldr r5, [r4, #SP_RDR] /* but didn't we read this byte above? */
+ strb r5, [r1], #1 /* postindexed */
+ add r0, r0, #1
+ cmp r0, r2
+ blo _local7 /* since we don't send another address, the NVRAM must be capable of sequential reads */
+_local6:
+ mov r0, #200
+ bl DELAY9
+ ldmia sp!, {r4, r5, r6, lr}
+ bx lr
+#endif
diff --git a/drivers/net/wireless/atmel.h b/drivers/net/wireless/atmel.h
new file mode 100644
index 000000000000..825000edfc2c
--- /dev/null
+++ b/drivers/net/wireless/atmel.h
@@ -0,0 +1,43 @@
+/*** -*- linux-c -*- **********************************************************
+
+ Driver for Atmel at76c502 at76c504 and at76c506 wireless cards.
+
+ Copyright 2005 Dan Williams and Red Hat, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Atmel wireless lan drivers; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+******************************************************************************/
+
+#ifndef _ATMEL_H
+#define _ATMEL_H
+
+typedef enum {
+ ATMEL_FW_TYPE_NONE = 0,
+ ATMEL_FW_TYPE_502,
+ ATMEL_FW_TYPE_502D,
+ ATMEL_FW_TYPE_502E,
+ ATMEL_FW_TYPE_502_3COM,
+ ATMEL_FW_TYPE_504,
+ ATMEL_FW_TYPE_504_2958,
+ ATMEL_FW_TYPE_504A_2958,
+ ATMEL_FW_TYPE_506
+} AtmelFWType;
+
+struct net_device *init_atmel_card(unsigned short, int, const AtmelFWType, struct device *,
+ int (*present_func)(void *), void * );
+void stop_atmel_card( struct net_device *, int );
+int atmel_open( struct net_device * );
+
+#endif
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
new file mode 100644
index 000000000000..a91b507e0a7a
--- /dev/null
+++ b/drivers/net/wireless/atmel_cs.c
@@ -0,0 +1,708 @@
+/*** -*- linux-c -*- **********************************************************
+
+ Driver for Atmel at76c502 at76c504 and at76c506 wireless cards.
+
+ Copyright 2000-2001 ATMEL Corporation.
+ Copyright 2003 Simon Kelley.
+
+ This code was developed from version 2.1.1 of the Atmel drivers,
+ released by Atmel corp. under the GPL in December 2002. It also
+ includes code from the Linux aironet drivers (C) Benjamin Reed,
+ and the Linux PCMCIA package, (C) David Hinds.
+
+ For all queries about this code, please contact the current author,
+ Simon Kelley <simon@thekelleys.org.uk> and not Atmel Corporation.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Atmel wireless lan drivers; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+******************************************************************************/
+
+#include <linux/config.h>
+#ifdef __IN_PCMCIA_PACKAGE__
+#include <pcmcia/k_compat.h>
+#endif
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/netdevice.h>
+#include <linux/moduleparam.h>
+#include <linux/device.h>
+
+#include <pcmcia/version.h>
+#include <pcmcia/cs_types.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/cisreg.h>
+#include <pcmcia/ds.h>
+#include <pcmcia/ciscode.h>
+
+#include <asm/io.h>
+#include <asm/system.h>
+#include <linux/wireless.h>
+
+#include "atmel.h"
+
+/*
+ All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
+ you do not define PCMCIA_DEBUG at all, all the debug code will be
+ left out. If you compile with PCMCIA_DEBUG=0, the debug code will
+ be present but disabled -- but it can then be enabled for specific
+ modules at load time with a 'pc_debug=#' option to insmod.
+*/
+#ifdef PCMCIA_DEBUG
+static int pc_debug = PCMCIA_DEBUG;
+module_param(pc_debug, int, 0);
+static char *version = "$Revision: 1.2 $";
+#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args);
+#else
+#define DEBUG(n, args...)
+#endif
+
+/*====================================================================*/
+
+MODULE_AUTHOR("Simon Kelley");
+MODULE_DESCRIPTION("Support for Atmel at76c50x 802.11 wireless ethernet cards.");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("Atmel at76c50x PCMCIA cards");
+
+/*====================================================================*/
+
+/*
+ The event() function is this driver's Card Services event handler.
+ It will be called by Card Services when an appropriate card status
+ event is received. The config() and release() entry points are
+ used to configure or release a socket, in response to card
+ insertion and ejection events. They are invoked from the atmel_cs
+ event handler.
+*/
+
+static void atmel_config(dev_link_t *link);
+static void atmel_release(dev_link_t *link);
+static int atmel_event(event_t event, int priority,
+ event_callback_args_t *args);
+
+/*
+ The attach() and detach() entry points are used to create and destroy
+ "instances" of the driver, where each instance represents everything
+ needed to manage one actual PCMCIA card.
+*/
+
+static dev_link_t *atmel_attach(void);
+static void atmel_detach(dev_link_t *);
+
+/*
+ You'll also need to prototype all the functions that will actually
+ be used to talk to your device. See 'pcmem_cs' for a good example
+ of a fully self-sufficient driver; the other drivers rely more or
+ less on other parts of the kernel.
+*/
+
+/*
+ The dev_info variable is the "key" that is used to match up this
+ device driver with appropriate cards, through the card configuration
+ database.
+*/
+
+static dev_info_t dev_info = "atmel_cs";
+
+/*
+ A linked list of "instances" of the atmelnet device. Each actual
+ PCMCIA card corresponds to one device instance, and is described
+ by one dev_link_t structure (defined in ds.h).
+
+ You may not want to use a linked list for this -- for example, the
+ memory card driver uses an array of dev_link_t pointers, where minor
+ device numbers are used to derive the corresponding array index.
+*/
+
+static dev_link_t *dev_list = NULL;
+
+/*
+ A dev_link_t structure has fields for most things that are needed
+ to keep track of a socket, but there will usually be some device
+ specific information that also needs to be kept track of. The
+ 'priv' pointer in a dev_link_t structure can be used to point to
+ a device-specific private data structure, like this.
+
+ A driver needs to provide a dev_node_t structure for each device
+ on a card. In some cases, there is only one device per card (for
+ example, ethernet cards, modems). In other cases, there may be
+ many actual or logical devices (SCSI adapters, memory cards with
+ multiple partitions). The dev_node_t structures need to be kept
+ in a linked list starting at the 'dev' field of a dev_link_t
+ structure. We allocate them in the card's private data structure,
+ because they generally shouldn't be allocated dynamically.
+
+ In this case, we also provide a flag to indicate if a device is
+ "stopped" due to a power management event, or card ejection. The
+ device IO routines can use a flag like this to throttle IO to a
+ card that is not ready to accept it.
+*/
+
+typedef struct local_info_t {
+ dev_node_t node;
+ struct net_device *eth_dev;
+} local_info_t;
+
+/*======================================================================
+
+ atmel_attach() creates an "instance" of the driver, allocating
+ local data structures for one device. The device is registered
+ with Card Services.
+
+ The dev_link structure is initialized, but we don't actually
+ configure the card at this point -- we wait until we receive a
+ card insertion event.
+
+ ======================================================================*/
+
+static dev_link_t *atmel_attach(void)
+{
+ client_reg_t client_reg;
+ dev_link_t *link;
+ local_info_t *local;
+ int ret;
+
+ DEBUG(0, "atmel_attach()\n");
+
+ /* Initialize the dev_link_t structure */
+ link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
+ if (!link) {
+ printk(KERN_ERR "atmel_cs: no memory for new device\n");
+ return NULL;
+ }
+ memset(link, 0, sizeof(struct dev_link_t));
+
+ /* Interrupt setup */
+ link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
+ link->irq.IRQInfo1 = IRQ_LEVEL_ID;
+ link->irq.Handler = NULL;
+
+ /*
+ General socket configuration defaults can go here. In this
+ client, we assume very little, and rely on the CIS for almost
+ everything. In most clients, many details (i.e., number, sizes,
+ and attributes of IO windows) are fixed by the nature of the
+ device, and can be hard-wired here.
+ */
+ link->conf.Attributes = 0;
+ link->conf.Vcc = 50;
+ link->conf.IntType = INT_MEMORY_AND_IO;
+
+ /* Allocate space for private device-specific data */
+ local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
+ if (!local) {
+ printk(KERN_ERR "atmel_cs: no memory for new device\n");
+ kfree (link);
+ return NULL;
+ }
+ memset(local, 0, sizeof(local_info_t));
+ link->priv = local;
+
+ /* Register with Card Services */
+ link->next = dev_list;
+ dev_list = link;
+ client_reg.dev_info = &dev_info;
+ client_reg.EventMask =
+ CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
+ CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
+ CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
+ client_reg.event_handler = &atmel_event;
+ client_reg.Version = 0x0210;
+ client_reg.event_callback_args.client_data = link;
+ ret = pcmcia_register_client(&link->handle, &client_reg);
+ if (ret != 0) {
+ cs_error(link->handle, RegisterClient, ret);
+ atmel_detach(link);
+ return NULL;
+ }
+
+ return link;
+} /* atmel_attach */
+
+/*======================================================================
+
+ This deletes a driver "instance". The device is de-registered
+ with Card Services. If it has been released, all local data
+ structures are freed. Otherwise, the structures will be freed
+ when the device is released.
+
+ ======================================================================*/
+
+static void atmel_detach(dev_link_t *link)
+{
+ dev_link_t **linkp;
+
+ DEBUG(0, "atmel_detach(0x%p)\n", link);
+
+ /* Locate device structure */
+ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
+ if (*linkp == link) break;
+ if (*linkp == NULL)
+ return;
+
+ if (link->state & DEV_CONFIG)
+ atmel_release(link);
+
+ /* Break the link with Card Services */
+ if (link->handle)
+ pcmcia_deregister_client(link->handle);
+
+ /* Unlink device structure, free pieces */
+ *linkp = link->next;
+ if (link->priv)
+ kfree(link->priv);
+ kfree(link);
+}
+
+/*======================================================================
+
+ atmel_config() is scheduled to run after a CARD_INSERTION event
+ is received, to configure the PCMCIA socket, and to make the
+ device available to the system.
+
+ ======================================================================*/
+
+#define CS_CHECK(fn, ret) \
+do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
+
+/* Call-back function to interrogate PCMCIA-specific information
+ about the current existance of the card */
+static int card_present(void *arg)
+{
+ dev_link_t *link = (dev_link_t *)arg;
+ if (link->state & DEV_SUSPEND)
+ return 0;
+ else if (link->state & DEV_PRESENT)
+ return 1;
+
+ return 0;
+}
+
+/* list of cards we know about and their firmware requirements.
+ Go either by Manfid or version strings.
+ Cards not in this list will need a firmware parameter to the module
+ in all probability. Note that the SMC 2632 V2 and V3 have the same
+ manfids, so we ignore those and use the version1 strings. */
+
+static struct {
+ int manf, card;
+ char *ver1;
+ AtmelFWType firmware;
+ char *name;
+} card_table[] = {
+ { 0, 0, "WLAN/802.11b PC CARD", ATMEL_FW_TYPE_502D, "Actiontec 802CAT1" },
+ { 0, 0, "ATMEL/AT76C502AR", ATMEL_FW_TYPE_502, "NoName-RFMD" },
+ { 0, 0, "ATMEL/AT76C502AR_D", ATMEL_FW_TYPE_502D, "NoName-revD" },
+ { 0, 0, "ATMEL/AT76C502AR_E", ATMEL_FW_TYPE_502E, "NoName-revE" },
+ { 0, 0, "ATMEL/AT76C504", ATMEL_FW_TYPE_504, "NoName-504" },
+ { 0, 0, "ATMEL/AT76C504A", ATMEL_FW_TYPE_504A_2958, "NoName-504a-2958" },
+ { 0, 0, "ATMEL/AT76C504_R", ATMEL_FW_TYPE_504_2958, "NoName-504-2958" },
+ { MANFID_3COM, 0x0620, NULL, ATMEL_FW_TYPE_502_3COM, "3com 3CRWE62092B" },
+ { MANFID_3COM, 0x0696, NULL, ATMEL_FW_TYPE_502_3COM, "3com 3CRSHPW196" },
+ { 0, 0, "SMC/2632W-V2", ATMEL_FW_TYPE_502, "SMC 2632W-V2" },
+ { 0, 0, "SMC/2632W", ATMEL_FW_TYPE_502D, "SMC 2632W-V3" },
+ { 0xd601, 0x0007, NULL, ATMEL_FW_TYPE_502, "Sitecom WLAN-011" },
+ { 0x01bf, 0x3302, NULL, ATMEL_FW_TYPE_502E, "Belkin F5D6020-V2" },
+ { 0, 0, "BT/Voyager 1020 Laptop Adapter", ATMEL_FW_TYPE_502, "BT Voyager 1020" },
+ { 0, 0, "IEEE 802.11b/Wireless LAN PC Card", ATMEL_FW_TYPE_502, "Siemens Gigaset PC Card II" },
+ { 0, 0, "CNet/CNWLC 11Mbps Wireless PC Card V-5", ATMEL_FW_TYPE_502E, "CNet CNWLC-811ARL" },
+ { 0, 0, "Wireless/PC_CARD", ATMEL_FW_TYPE_502D, "Planet WL-3552" },
+ { 0, 0, "OEM/11Mbps Wireless LAN PC Card V-3", ATMEL_FW_TYPE_502, "OEM 11Mbps WLAN PCMCIA Card" },
+ { 0, 0, "11WAVE/11WP611AL-E", ATMEL_FW_TYPE_502E, "11WAVE WaveBuddy" },
+ { 0, 0, "LG/LW2100N", ATMEL_FW_TYPE_502E, "LG LW2100N 11Mbps WLAN PCMCIA Card" },
+};
+
+static void atmel_config(dev_link_t *link)
+{
+ client_handle_t handle;
+ tuple_t tuple;
+ cisparse_t parse;
+ local_info_t *dev;
+ int last_fn, last_ret;
+ u_char buf[64];
+ int card_index = -1, done = 0;
+
+ handle = link->handle;
+ dev = link->priv;
+
+ DEBUG(0, "atmel_config(0x%p)\n", link);
+
+ tuple.Attributes = 0;
+ tuple.TupleData = buf;
+ tuple.TupleDataMax = sizeof(buf);
+ tuple.TupleOffset = 0;
+
+ tuple.DesiredTuple = CISTPL_MANFID;
+ if (pcmcia_get_first_tuple(handle, &tuple) == 0) {
+ int i;
+ cistpl_manfid_t *manfid;
+ CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
+ CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
+ manfid = &(parse.manfid);
+ for (i = 0; i < sizeof(card_table)/sizeof(card_table[0]); i++) {
+ if (!card_table[i].ver1 &&
+ manfid->manf == card_table[i].manf &&
+ manfid->card == card_table[i].card) {
+ card_index = i;
+ done = 1;
+ }
+ }
+ }
+
+ tuple.DesiredTuple = CISTPL_VERS_1;
+ if (!done && (pcmcia_get_first_tuple(handle, &tuple) == 0)) {
+ int i, j, k;
+ cistpl_vers_1_t *ver1;
+ CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
+ CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
+ ver1 = &(parse.version_1);
+
+ for (i = 0; i < sizeof(card_table)/sizeof(card_table[0]); i++) {
+ for (j = 0; j < ver1->ns; j++) {
+ char *p = card_table[i].ver1;
+ char *q = &ver1->str[ver1->ofs[j]];
+ if (!p)
+ goto mismatch;
+ for (k = 0; k < j; k++) {
+ while ((*p != '\0') && (*p != '/')) p++;
+ if (*p == '\0') {
+ if (*q != '\0')
+ goto mismatch;
+ } else {
+ p++;
+ }
+ }
+ while((*q != '\0') && (*p != '\0') &&
+ (*p != '/') && (*p == *q)) p++, q++;
+ if (((*p != '\0') && *p != '/') || *q != '\0')
+ goto mismatch;
+ }
+ card_index = i;
+ break; /* done */
+
+ mismatch:
+ j = 0; /* dummy stmt to shut up compiler */
+ }
+ }
+
+ /*
+ This reads the card's CONFIG tuple to find its configuration
+ registers.
+ */
+ tuple.DesiredTuple = CISTPL_CONFIG;
+ CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
+ CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
+ CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
+ link->conf.ConfigBase = parse.config.base;
+ link->conf.Present = parse.config.rmask[0];
+
+ /* Configure card */
+ link->state |= DEV_CONFIG;
+
+ /*
+ In this loop, we scan the CIS for configuration table entries,
+ each of which describes a valid card configuration, including
+ voltage, IO window, memory window, and interrupt settings.
+
+ We make no assumptions about the card to be configured: we use
+ just the information available in the CIS. In an ideal world,
+ this would work for any PCMCIA card, but it requires a complete
+ and accurate CIS. In practice, a driver usually "knows" most of
+ these things without consulting the CIS, and most client drivers
+ will only use the CIS to fill in implementation-defined details.
+ */
+ tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
+ CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
+ while (1) {
+ cistpl_cftable_entry_t dflt = { 0 };
+ cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
+ if (pcmcia_get_tuple_data(handle, &tuple) != 0 ||
+ pcmcia_parse_tuple(handle, &tuple, &parse) != 0)
+ goto next_entry;
+
+ if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
+ if (cfg->index == 0) goto next_entry;
+ link->conf.ConfigIndex = cfg->index;
+
+ /* Does this card need audio output? */
+ if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
+ link->conf.Attributes |= CONF_ENABLE_SPKR;
+ link->conf.Status = CCSR_AUDIO_ENA;
+ }
+
+ /* Use power settings for Vcc and Vpp if present */
+ /* Note that the CIS values need to be rescaled */
+ if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM))
+ link->conf.Vcc = cfg->vcc.param[CISTPL_POWER_VNOM]/10000;
+ else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM))
+ link->conf.Vcc = dflt.vcc.param[CISTPL_POWER_VNOM]/10000;
+
+ if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
+ link->conf.Vpp1 = link->conf.Vpp2 =
+ cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
+ else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
+ link->conf.Vpp1 = link->conf.Vpp2 =
+ dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
+
+ /* Do we need to allocate an interrupt? */
+ if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
+ link->conf.Attributes |= CONF_ENABLE_IRQ;
+
+ /* IO window settings */
+ link->io.NumPorts1 = link->io.NumPorts2 = 0;
+ if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
+ cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
+ link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+ if (!(io->flags & CISTPL_IO_8BIT))
+ link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+ if (!(io->flags & CISTPL_IO_16BIT))
+ link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+ link->io.BasePort1 = io->win[0].base;
+ link->io.NumPorts1 = io->win[0].len;
+ if (io->nwin > 1) {
+ link->io.Attributes2 = link->io.Attributes1;
+ link->io.BasePort2 = io->win[1].base;
+ link->io.NumPorts2 = io->win[1].len;
+ }
+ }
+
+ /* This reserves IO space but doesn't actually enable it */
+ if (pcmcia_request_io(link->handle, &link->io) != 0)
+ goto next_entry;
+
+ /* If we got this far, we're cool! */
+ break;
+
+ next_entry:
+ CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
+ }
+
+ /*
+ Allocate an interrupt line. Note that this does not assign a
+ handler to the interrupt, unless the 'Handler' member of the
+ irq structure is initialized.
+ */
+ if (link->conf.Attributes & CONF_ENABLE_IRQ)
+ CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
+
+ /*
+ This actually configures the PCMCIA socket -- setting up
+ the I/O windows and the interrupt mapping, and putting the
+ card and host interface into "Memory and IO" mode.
+ */
+ CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
+
+ if (link->irq.AssignedIRQ == 0) {
+ printk(KERN_ALERT
+ "atmel: cannot assign IRQ: check that CONFIG_ISA is set in kernel config.");
+ goto cs_failed;
+ }
+
+ ((local_info_t*)link->priv)->eth_dev =
+ init_atmel_card(link->irq.AssignedIRQ,
+ link->io.BasePort1,
+ card_index == -1 ? ATMEL_FW_TYPE_NONE : card_table[card_index].firmware,
+ &handle_to_dev(handle),
+ card_present,
+ link);
+ if (!((local_info_t*)link->priv)->eth_dev)
+ goto cs_failed;
+
+ /*
+ At this point, the dev_node_t structure(s) need to be
+ initialized and arranged in a linked list at link->dev.
+ */
+ strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
+ dev->node.major = dev->node.minor = 0;
+ link->dev = &dev->node;
+
+ /* Finally, report what we've done */
+ printk(KERN_INFO "%s: %s%sindex 0x%02x: Vcc %d.%d",
+ dev->node.dev_name,
+ card_index == -1 ? "" : card_table[card_index].name,
+ card_index == -1 ? "" : " ",
+ link->conf.ConfigIndex,
+ link->conf.Vcc/10, link->conf.Vcc%10);
+ if (link->conf.Vpp1)
+ printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
+ if (link->conf.Attributes & CONF_ENABLE_IRQ)
+ printk(", irq %d", link->irq.AssignedIRQ);
+ if (link->io.NumPorts1)
+ printk(", io 0x%04x-0x%04x", link->io.BasePort1,
+ link->io.BasePort1+link->io.NumPorts1-1);
+ if (link->io.NumPorts2)
+ printk(" & 0x%04x-0x%04x", link->io.BasePort2,
+ link->io.BasePort2+link->io.NumPorts2-1);
+ printk("\n");
+
+ link->state &= ~DEV_CONFIG_PENDING;
+ return;
+
+ cs_failed:
+ cs_error(link->handle, last_fn, last_ret);
+ atmel_release(link);
+}
+
+/*======================================================================
+
+ After a card is removed, atmel_release() will unregister the
+ device, and release the PCMCIA configuration. If the device is
+ still open, this will be postponed until it is closed.
+
+ ======================================================================*/
+
+static void atmel_release(dev_link_t *link)
+{
+ struct net_device *dev = ((local_info_t*)link->priv)->eth_dev;
+
+ DEBUG(0, "atmel_release(0x%p)\n", link);
+
+ /* Unlink the device chain */
+ link->dev = NULL;
+
+ if (dev)
+ stop_atmel_card(dev, 0);
+ ((local_info_t*)link->priv)->eth_dev = NULL;
+
+ /* Don't bother checking to see if these succeed or not */
+ pcmcia_release_configuration(link->handle);
+ if (link->io.NumPorts1)
+ pcmcia_release_io(link->handle, &link->io);
+ if (link->irq.AssignedIRQ)
+ pcmcia_release_irq(link->handle, &link->irq);
+ link->state &= ~DEV_CONFIG;
+}
+
+/*======================================================================
+
+ The card status event handler. Mostly, this schedules other
+ stuff to run after an event is received.
+
+ When a CARD_REMOVAL event is received, we immediately set a
+ private flag to block future accesses to this device. All the
+ functions that actually access the device should check this flag
+ to make sure the card is still present.
+
+ ======================================================================*/
+
+static int atmel_event(event_t event, int priority,
+ event_callback_args_t *args)
+{
+ dev_link_t *link = args->client_data;
+ local_info_t *local = link->priv;
+
+ DEBUG(1, "atmel_event(0x%06x)\n", event);
+
+ switch (event) {
+ case CS_EVENT_CARD_REMOVAL:
+ link->state &= ~DEV_PRESENT;
+ if (link->state & DEV_CONFIG) {
+ netif_device_detach(local->eth_dev);
+ atmel_release(link);
+ }
+ break;
+ case CS_EVENT_CARD_INSERTION:
+ link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
+ atmel_config(link);
+ break;
+ case CS_EVENT_PM_SUSPEND:
+ link->state |= DEV_SUSPEND;
+ /* Fall through... */
+ case CS_EVENT_RESET_PHYSICAL:
+ if (link->state & DEV_CONFIG) {
+ netif_device_detach(local->eth_dev);
+ pcmcia_release_configuration(link->handle);
+ }
+ break;
+ case CS_EVENT_PM_RESUME:
+ link->state &= ~DEV_SUSPEND;
+ /* Fall through... */
+ case CS_EVENT_CARD_RESET:
+ if (link->state & DEV_CONFIG) {
+ pcmcia_request_configuration(link->handle, &link->conf);
+ atmel_open(local->eth_dev);
+ netif_device_attach(local->eth_dev);
+ }
+ break;
+ }
+ return 0;
+} /* atmel_event */
+
+/*====================================================================*/
+static struct pcmcia_driver atmel_driver = {
+ .owner = THIS_MODULE,
+ .drv = {
+ .name = "atmel_cs",
+ },
+ .attach = atmel_attach,
+ .detach = atmel_detach,
+};
+
+static int atmel_cs_init(void)
+{
+ return pcmcia_register_driver(&atmel_driver);
+}
+
+static void atmel_cs_cleanup(void)
+{
+ pcmcia_unregister_driver(&atmel_driver);
+ BUG_ON(dev_list != NULL);
+}
+
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ In addition:
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+module_init(atmel_cs_init);
+module_exit(atmel_cs_cleanup);
diff --git a/drivers/net/wireless/atmel_pci.c b/drivers/net/wireless/atmel_pci.c
new file mode 100644
index 000000000000..2eb00a957bbe
--- /dev/null
+++ b/drivers/net/wireless/atmel_pci.c
@@ -0,0 +1,89 @@
+/*** -*- linux-c -*- **********************************************************
+
+ Driver for Atmel at76c502 at76c504 and at76c506 wireless cards.
+
+ Copyright 2004 Simon Kelley.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Atmel wireless lan drivers; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+******************************************************************************/
+#include <linux/config.h>
+#include <linux/pci.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include "atmel.h"
+
+MODULE_AUTHOR("Simon Kelley");
+MODULE_DESCRIPTION("Support for Atmel at76c50x 802.11 wireless ethernet cards.");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("Atmel at76c506 PCI wireless cards");
+
+static struct pci_device_id card_ids[] = {
+ { 0x1114, 0x0506, PCI_ANY_ID, PCI_ANY_ID },
+ { 0, }
+};
+
+MODULE_DEVICE_TABLE(pci, card_ids);
+
+static int atmel_pci_probe(struct pci_dev *, const struct pci_device_id *);
+static void atmel_pci_remove(struct pci_dev *);
+
+static struct pci_driver atmel_driver = {
+ .name = "atmel",
+ .id_table = card_ids,
+ .probe = atmel_pci_probe,
+ .remove = __devexit_p(atmel_pci_remove),
+};
+
+
+static int __devinit atmel_pci_probe(struct pci_dev *pdev,
+ const struct pci_device_id *pent)
+{
+ struct net_device *dev;
+
+ if (pci_enable_device(pdev))
+ return -ENODEV;
+
+ pci_set_master(pdev);
+
+ dev = init_atmel_card(pdev->irq, pdev->resource[1].start,
+ ATMEL_FW_TYPE_506,
+ &pdev->dev, NULL, NULL);
+ if (!dev)
+ return -ENODEV;
+
+ pci_set_drvdata(pdev, dev);
+ return 0;
+}
+
+static void __devexit atmel_pci_remove(struct pci_dev *pdev)
+{
+ stop_atmel_card(pci_get_drvdata(pdev), 1);
+}
+
+static int __init atmel_init_module(void)
+{
+ return pci_module_init(&atmel_driver);
+}
+
+static void __exit atmel_cleanup_module(void)
+{
+ pci_unregister_driver(&atmel_driver);
+}
+
+module_init(atmel_init_module);
+module_exit(atmel_cleanup_module);
diff --git a/drivers/net/wireless/hermes.c b/drivers/net/wireless/hermes.c
new file mode 100644
index 000000000000..21c3d0d227e6
--- /dev/null
+++ b/drivers/net/wireless/hermes.c
@@ -0,0 +1,554 @@
+/* hermes.c
+ *
+ * Driver core for the "Hermes" wireless MAC controller, as used in
+ * the Lucent Orinoco and Cabletron RoamAbout cards. It should also
+ * work on the hfa3841 and hfa3842 MAC controller chips used in the
+ * Prism II chipsets.
+ *
+ * This is not a complete driver, just low-level access routines for
+ * the MAC controller itself.
+ *
+ * Based on the prism2 driver from Absolute Value Systems' linux-wlan
+ * project, the Linux wvlan_cs driver, Lucent's HCF-Light
+ * (wvlan_hcf.c) library, and the NetBSD wireless driver (in no
+ * particular order).
+ *
+ * Copyright (C) 2000, David Gibson, Linuxcare Australia.
+ * (C) Copyright David Gibson, IBM Corp. 2001-2003.
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License
+ * at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License version 2 (the "GPL"), in
+ * which case the provisions of the GPL are applicable instead of the
+ * above. If you wish to allow the use of your version of this file
+ * only under the terms of the GPL and not to allow others to use your
+ * version of this file under the MPL, indicate your decision by
+ * deleting the provisions above and replace them with the notice and
+ * other provisions required by the GPL. If you do not delete the
+ * provisions above, a recipient may use your version of this file
+ * under either the MPL or the GPL.
+ */
+
+#include <linux/config.h>
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/threads.h>
+#include <linux/smp.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/net.h>
+#include <asm/errno.h>
+
+#include "hermes.h"
+
+MODULE_DESCRIPTION("Low-level driver helper for Lucent Hermes chipset and Prism II HFA384x wireless MAC controller");
+MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>"
+ " & David Gibson <hermes@gibson.dropbear.id.au>");
+MODULE_LICENSE("Dual MPL/GPL");
+
+/* These are maximum timeouts. Most often, card wil react much faster */
+#define CMD_BUSY_TIMEOUT (100) /* In iterations of ~1us */
+#define CMD_INIT_TIMEOUT (50000) /* in iterations of ~10us */
+#define CMD_COMPL_TIMEOUT (20000) /* in iterations of ~10us */
+#define ALLOC_COMPL_TIMEOUT (1000) /* in iterations of ~10us */
+
+/*
+ * Debugging helpers
+ */
+
+#define DMSG(stuff...) do {printk(KERN_DEBUG "hermes @ %p: " , hw->iobase); \
+ printk(stuff);} while (0)
+
+#undef HERMES_DEBUG
+#ifdef HERMES_DEBUG
+#include <stdarg.h>
+
+#define DEBUG(lvl, stuff...) if ( (lvl) <= HERMES_DEBUG) DMSG(stuff)
+
+#else /* ! HERMES_DEBUG */
+
+#define DEBUG(lvl, stuff...) do { } while (0)
+
+#endif /* ! HERMES_DEBUG */
+
+
+/*
+ * Internal functions
+ */
+
+/* Issue a command to the chip. Waiting for it to complete is the caller's
+ problem.
+
+ Returns -EBUSY if the command register is busy, 0 on success.
+
+ Callable from any context.
+*/
+static int hermes_issue_cmd(hermes_t *hw, u16 cmd, u16 param0)
+{
+ int k = CMD_BUSY_TIMEOUT;
+ u16 reg;
+
+ /* First wait for the command register to unbusy */
+ reg = hermes_read_regn(hw, CMD);
+ while ( (reg & HERMES_CMD_BUSY) && k ) {
+ k--;
+ udelay(1);
+ reg = hermes_read_regn(hw, CMD);
+ }
+ if (reg & HERMES_CMD_BUSY) {
+ return -EBUSY;
+ }
+
+ hermes_write_regn(hw, PARAM2, 0);
+ hermes_write_regn(hw, PARAM1, 0);
+ hermes_write_regn(hw, PARAM0, param0);
+ hermes_write_regn(hw, CMD, cmd);
+
+ return 0;
+}
+
+/*
+ * Function definitions
+ */
+
+void hermes_struct_init(hermes_t *hw, void __iomem *address, int reg_spacing)
+{
+ hw->iobase = address;
+ hw->reg_spacing = reg_spacing;
+ hw->inten = 0x0;
+
+#ifdef HERMES_DEBUG_BUFFER
+ hw->dbufp = 0;
+ memset(&hw->dbuf, 0xff, sizeof(hw->dbuf));
+ memset(&hw->profile, 0, sizeof(hw->profile));
+#endif
+}
+
+int hermes_init(hermes_t *hw)
+{
+ u16 status, reg;
+ int err = 0;
+ int k;
+
+ /* We don't want to be interrupted while resetting the chipset */
+ hw->inten = 0x0;
+ hermes_write_regn(hw, INTEN, 0);
+ hermes_write_regn(hw, EVACK, 0xffff);
+
+ /* Normally it's a "can't happen" for the command register to
+ be busy when we go to issue a command because we are
+ serializing all commands. However we want to have some
+ chance of resetting the card even if it gets into a stupid
+ state, so we actually wait to see if the command register
+ will unbusy itself here. */
+ k = CMD_BUSY_TIMEOUT;
+ reg = hermes_read_regn(hw, CMD);
+ while (k && (reg & HERMES_CMD_BUSY)) {
+ if (reg == 0xffff) /* Special case - the card has probably been removed,
+ so don't wait for the timeout */
+ return -ENODEV;
+
+ k--;
+ udelay(1);
+ reg = hermes_read_regn(hw, CMD);
+ }
+
+ /* No need to explicitly handle the timeout - if we've timed
+ out hermes_issue_cmd() will probably return -EBUSY below */
+
+ /* According to the documentation, EVSTAT may contain
+ obsolete event occurrence information. We have to acknowledge
+ it by writing EVACK. */
+ reg = hermes_read_regn(hw, EVSTAT);
+ hermes_write_regn(hw, EVACK, reg);
+
+ /* We don't use hermes_docmd_wait here, because the reset wipes
+ the magic constant in SWSUPPORT0 away, and it gets confused */
+ err = hermes_issue_cmd(hw, HERMES_CMD_INIT, 0);
+ if (err)
+ return err;
+
+ reg = hermes_read_regn(hw, EVSTAT);
+ k = CMD_INIT_TIMEOUT;
+ while ( (! (reg & HERMES_EV_CMD)) && k) {
+ k--;
+ udelay(10);
+ reg = hermes_read_regn(hw, EVSTAT);
+ }
+
+ hermes_write_regn(hw, SWSUPPORT0, HERMES_MAGIC);
+
+ if (! hermes_present(hw)) {
+ DEBUG(0, "hermes @ 0x%x: Card removed during reset.\n",
+ hw->iobase);
+ err = -ENODEV;
+ goto out;
+ }
+
+ if (! (reg & HERMES_EV_CMD)) {
+ printk(KERN_ERR "hermes @ %p: "
+ "Timeout waiting for card to reset (reg=0x%04x)!\n",
+ hw->iobase, reg);
+ err = -ETIMEDOUT;
+ goto out;
+ }
+
+ status = hermes_read_regn(hw, STATUS);
+
+ hermes_write_regn(hw, EVACK, HERMES_EV_CMD);
+
+ if (status & HERMES_STATUS_RESULT)
+ err = -EIO;
+
+ out:
+ return err;
+}
+
+/* Issue a command to the chip, and (busy!) wait for it to
+ * complete.
+ *
+ * Returns: < 0 on internal error, 0 on success, > 0 on error returned by the firmware
+ *
+ * Callable from any context, but locking is your problem. */
+int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0,
+ struct hermes_response *resp)
+{
+ int err;
+ int k;
+ u16 reg;
+ u16 status;
+
+ err = hermes_issue_cmd(hw, cmd, parm0);
+ if (err) {
+ if (! hermes_present(hw)) {
+ if (net_ratelimit())
+ printk(KERN_WARNING "hermes @ %p: "
+ "Card removed while issuing command "
+ "0x%04x.\n", hw->iobase, cmd);
+ err = -ENODEV;
+ } else
+ if (net_ratelimit())
+ printk(KERN_ERR "hermes @ %p: "
+ "Error %d issuing command 0x%04x.\n",
+ hw->iobase, err, cmd);
+ goto out;
+ }
+
+ reg = hermes_read_regn(hw, EVSTAT);
+ k = CMD_COMPL_TIMEOUT;
+ while ( (! (reg & HERMES_EV_CMD)) && k) {
+ k--;
+ udelay(10);
+ reg = hermes_read_regn(hw, EVSTAT);
+ }
+
+ if (! hermes_present(hw)) {
+ printk(KERN_WARNING "hermes @ %p: Card removed "
+ "while waiting for command 0x%04x completion.\n",
+ hw->iobase, cmd);
+ err = -ENODEV;
+ goto out;
+ }
+
+ if (! (reg & HERMES_EV_CMD)) {
+ printk(KERN_ERR "hermes @ %p: Timeout waiting for "
+ "command 0x%04x completion.\n", hw->iobase, cmd);
+ err = -ETIMEDOUT;
+ goto out;
+ }
+
+ status = hermes_read_regn(hw, STATUS);
+ if (resp) {
+ resp->status = status;
+ resp->resp0 = hermes_read_regn(hw, RESP0);
+ resp->resp1 = hermes_read_regn(hw, RESP1);
+ resp->resp2 = hermes_read_regn(hw, RESP2);
+ }
+
+ hermes_write_regn(hw, EVACK, HERMES_EV_CMD);
+
+ if (status & HERMES_STATUS_RESULT)
+ err = -EIO;
+
+ out:
+ return err;
+}
+
+int hermes_allocate(hermes_t *hw, u16 size, u16 *fid)
+{
+ int err = 0;
+ int k;
+ u16 reg;
+
+ if ( (size < HERMES_ALLOC_LEN_MIN) || (size > HERMES_ALLOC_LEN_MAX) )
+ return -EINVAL;
+
+ err = hermes_docmd_wait(hw, HERMES_CMD_ALLOC, size, NULL);
+ if (err) {
+ return err;
+ }
+
+ reg = hermes_read_regn(hw, EVSTAT);
+ k = ALLOC_COMPL_TIMEOUT;
+ while ( (! (reg & HERMES_EV_ALLOC)) && k) {
+ k--;
+ udelay(10);
+ reg = hermes_read_regn(hw, EVSTAT);
+ }
+
+ if (! hermes_present(hw)) {
+ printk(KERN_WARNING "hermes @ %p: "
+ "Card removed waiting for frame allocation.\n",
+ hw->iobase);
+ return -ENODEV;
+ }
+
+ if (! (reg & HERMES_EV_ALLOC)) {
+ printk(KERN_ERR "hermes @ %p: "
+ "Timeout waiting for frame allocation\n",
+ hw->iobase);
+ return -ETIMEDOUT;
+ }
+
+ *fid = hermes_read_regn(hw, ALLOCFID);
+ hermes_write_regn(hw, EVACK, HERMES_EV_ALLOC);
+
+ return 0;
+}
+
+
+/* Set up a BAP to read a particular chunk of data from card's internal buffer.
+ *
+ * Returns: < 0 on internal failure (errno), 0 on success, >0 on error
+ * from firmware
+ *
+ * Callable from any context */
+static int hermes_bap_seek(hermes_t *hw, int bap, u16 id, u16 offset)
+{
+ int sreg = bap ? HERMES_SELECT1 : HERMES_SELECT0;
+ int oreg = bap ? HERMES_OFFSET1 : HERMES_OFFSET0;
+ int k;
+ u16 reg;
+
+ /* Paranoia.. */
+ if ( (offset > HERMES_BAP_OFFSET_MAX) || (offset % 2) )
+ return -EINVAL;
+
+ k = HERMES_BAP_BUSY_TIMEOUT;
+ reg = hermes_read_reg(hw, oreg);
+ while ((reg & HERMES_OFFSET_BUSY) && k) {
+ k--;
+ udelay(1);
+ reg = hermes_read_reg(hw, oreg);
+ }
+
+#ifdef HERMES_DEBUG_BUFFER
+ hw->profile[HERMES_BAP_BUSY_TIMEOUT - k]++;
+
+ if (k < HERMES_BAP_BUSY_TIMEOUT) {
+ struct hermes_debug_entry *e =
+ &hw->dbuf[(hw->dbufp++) % HERMES_DEBUG_BUFSIZE];
+ e->bap = bap;
+ e->id = id;
+ e->offset = offset;
+ e->cycles = HERMES_BAP_BUSY_TIMEOUT - k;
+ }
+#endif
+
+ if (reg & HERMES_OFFSET_BUSY)
+ return -ETIMEDOUT;
+
+ /* Now we actually set up the transfer */
+ hermes_write_reg(hw, sreg, id);
+ hermes_write_reg(hw, oreg, offset);
+
+ /* Wait for the BAP to be ready */
+ k = HERMES_BAP_BUSY_TIMEOUT;
+ reg = hermes_read_reg(hw, oreg);
+ while ( (reg & (HERMES_OFFSET_BUSY | HERMES_OFFSET_ERR)) && k) {
+ k--;
+ udelay(1);
+ reg = hermes_read_reg(hw, oreg);
+ }
+
+ if (reg != offset) {
+ printk(KERN_ERR "hermes @ %p: BAP%d offset %s: "
+ "reg=0x%x id=0x%x offset=0x%x\n", hw->iobase, bap,
+ (reg & HERMES_OFFSET_BUSY) ? "timeout" : "error",
+ reg, id, offset);
+
+ if (reg & HERMES_OFFSET_BUSY) {
+ return -ETIMEDOUT;
+ }
+
+ return -EIO; /* error or wrong offset */
+ }
+
+ return 0;
+}
+
+/* Read a block of data from the chip's buffer, via the
+ * BAP. Synchronization/serialization is the caller's problem. len
+ * must be even.
+ *
+ * Returns: < 0 on internal failure (errno), 0 on success, > 0 on error from firmware
+ */
+int hermes_bap_pread(hermes_t *hw, int bap, void *buf, unsigned len,
+ u16 id, u16 offset)
+{
+ int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
+ int err = 0;
+
+ if ( (len < 0) || (len % 2) )
+ return -EINVAL;
+
+ err = hermes_bap_seek(hw, bap, id, offset);
+ if (err)
+ goto out;
+
+ /* Actually do the transfer */
+ hermes_read_words(hw, dreg, buf, len/2);
+
+ out:
+ return err;
+}
+
+/* Write a block of data to the chip's buffer, via the
+ * BAP. Synchronization/serialization is the caller's problem. len
+ * must be even.
+ *
+ * Returns: < 0 on internal failure (errno), 0 on success, > 0 on error from firmware
+ */
+int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, unsigned len,
+ u16 id, u16 offset)
+{
+ int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
+ int err = 0;
+
+ if ( (len < 0) || (len % 2) )
+ return -EINVAL;
+
+ err = hermes_bap_seek(hw, bap, id, offset);
+ if (err)
+ goto out;
+
+ /* Actually do the transfer */
+ hermes_write_words(hw, dreg, buf, len/2);
+
+ out:
+ return err;
+}
+
+/* Read a Length-Type-Value record from the card.
+ *
+ * If length is NULL, we ignore the length read from the card, and
+ * read the entire buffer regardless. This is useful because some of
+ * the configuration records appear to have incorrect lengths in
+ * practice.
+ *
+ * Callable from user or bh context. */
+int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned bufsize,
+ u16 *length, void *buf)
+{
+ int err = 0;
+ int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
+ u16 rlength, rtype;
+ unsigned nwords;
+
+ if ( (bufsize < 0) || (bufsize % 2) )
+ return -EINVAL;
+
+ err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS, rid, NULL);
+ if (err)
+ return err;
+
+ err = hermes_bap_seek(hw, bap, rid, 0);
+ if (err)
+ return err;
+
+ rlength = hermes_read_reg(hw, dreg);
+
+ if (! rlength)
+ return -ENODATA;
+
+ rtype = hermes_read_reg(hw, dreg);
+
+ if (length)
+ *length = rlength;
+
+ if (rtype != rid)
+ printk(KERN_WARNING "hermes @ %p: %s(): "
+ "rid (0x%04x) does not match type (0x%04x)\n",
+ hw->iobase, __FUNCTION__, rid, rtype);
+ if (HERMES_RECLEN_TO_BYTES(rlength) > bufsize)
+ printk(KERN_WARNING "hermes @ %p: "
+ "Truncating LTV record from %d to %d bytes. "
+ "(rid=0x%04x, len=0x%04x)\n", hw->iobase,
+ HERMES_RECLEN_TO_BYTES(rlength), bufsize, rid, rlength);
+
+ nwords = min((unsigned)rlength - 1, bufsize / 2);
+ hermes_read_words(hw, dreg, buf, nwords);
+
+ return 0;
+}
+
+int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
+ u16 length, const void *value)
+{
+ int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
+ int err = 0;
+ unsigned count;
+
+ if (length == 0)
+ return -EINVAL;
+
+ err = hermes_bap_seek(hw, bap, rid, 0);
+ if (err)
+ return err;
+
+ hermes_write_reg(hw, dreg, length);
+ hermes_write_reg(hw, dreg, rid);
+
+ count = length - 1;
+
+ hermes_write_words(hw, dreg, value, count);
+
+ err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS | HERMES_CMD_WRITE,
+ rid, NULL);
+
+ return err;
+}
+
+EXPORT_SYMBOL(hermes_struct_init);
+EXPORT_SYMBOL(hermes_init);
+EXPORT_SYMBOL(hermes_docmd_wait);
+EXPORT_SYMBOL(hermes_allocate);
+
+EXPORT_SYMBOL(hermes_bap_pread);
+EXPORT_SYMBOL(hermes_bap_pwrite);
+EXPORT_SYMBOL(hermes_read_ltv);
+EXPORT_SYMBOL(hermes_write_ltv);
+
+static int __init init_hermes(void)
+{
+ return 0;
+}
+
+static void __exit exit_hermes(void)
+{
+}
+
+module_init(init_hermes);
+module_exit(exit_hermes);
diff --git a/drivers/net/wireless/hermes.h b/drivers/net/wireless/hermes.h
new file mode 100644
index 000000000000..8c9e874c9118
--- /dev/null
+++ b/drivers/net/wireless/hermes.h
@@ -0,0 +1,481 @@
+/* hermes.h
+ *
+ * Driver core for the "Hermes" wireless MAC controller, as used in
+ * the Lucent Orinoco and Cabletron RoamAbout cards. It should also
+ * work on the hfa3841 and hfa3842 MAC controller chips used in the
+ * Prism I & II chipsets.
+ *
+ * This is not a complete driver, just low-level access routines for
+ * the MAC controller itself.
+ *
+ * Based on the prism2 driver from Absolute Value Systems' linux-wlan
+ * project, the Linux wvlan_cs driver, Lucent's HCF-Light
+ * (wvlan_hcf.c) library, and the NetBSD wireless driver.
+ *
+ * Copyright (C) 2000, David Gibson, Linuxcare Australia.
+ * (C) Copyright David Gibson, IBM Corp. 2001-2003.
+ *
+ * Portions taken from hfa384x.h, Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
+ *
+ * This file distributed under the GPL, version 2.
+ */
+
+#ifndef _HERMES_H
+#define _HERMES_H
+
+/* Notes on locking:
+ *
+ * As a module of low level hardware access routines, there is no
+ * locking. Users of this module should ensure that they serialize
+ * access to the hermes_t structure, and to the hardware
+*/
+
+#include <linux/delay.h>
+#include <linux/if_ether.h>
+#include <asm/byteorder.h>
+
+/*
+ * Limits and constants
+ */
+#define HERMES_ALLOC_LEN_MIN (4)
+#define HERMES_ALLOC_LEN_MAX (2400)
+#define HERMES_LTV_LEN_MAX (34)
+#define HERMES_BAP_DATALEN_MAX (4096)
+#define HERMES_BAP_OFFSET_MAX (4096)
+#define HERMES_PORTID_MAX (7)
+#define HERMES_NUMPORTS_MAX (HERMES_PORTID_MAX+1)
+#define HERMES_PDR_LEN_MAX (260) /* in bytes, from EK */
+#define HERMES_PDA_RECS_MAX (200) /* a guess */
+#define HERMES_PDA_LEN_MAX (1024) /* in bytes, from EK */
+#define HERMES_SCANRESULT_MAX (35)
+#define HERMES_CHINFORESULT_MAX (8)
+#define HERMES_MAX_MULTICAST (16)
+#define HERMES_MAGIC (0x7d1f)
+
+/*
+ * Hermes register offsets
+ */
+#define HERMES_CMD (0x00)
+#define HERMES_PARAM0 (0x02)
+#define HERMES_PARAM1 (0x04)
+#define HERMES_PARAM2 (0x06)
+#define HERMES_STATUS (0x08)
+#define HERMES_RESP0 (0x0A)
+#define HERMES_RESP1 (0x0C)
+#define HERMES_RESP2 (0x0E)
+#define HERMES_INFOFID (0x10)
+#define HERMES_RXFID (0x20)
+#define HERMES_ALLOCFID (0x22)
+#define HERMES_TXCOMPLFID (0x24)
+#define HERMES_SELECT0 (0x18)
+#define HERMES_OFFSET0 (0x1C)
+#define HERMES_DATA0 (0x36)
+#define HERMES_SELECT1 (0x1A)
+#define HERMES_OFFSET1 (0x1E)
+#define HERMES_DATA1 (0x38)
+#define HERMES_EVSTAT (0x30)
+#define HERMES_INTEN (0x32)
+#define HERMES_EVACK (0x34)
+#define HERMES_CONTROL (0x14)
+#define HERMES_SWSUPPORT0 (0x28)
+#define HERMES_SWSUPPORT1 (0x2A)
+#define HERMES_SWSUPPORT2 (0x2C)
+#define HERMES_AUXPAGE (0x3A)
+#define HERMES_AUXOFFSET (0x3C)
+#define HERMES_AUXDATA (0x3E)
+
+/*
+ * CMD register bitmasks
+ */
+#define HERMES_CMD_BUSY (0x8000)
+#define HERMES_CMD_AINFO (0x7f00)
+#define HERMES_CMD_MACPORT (0x0700)
+#define HERMES_CMD_RECL (0x0100)
+#define HERMES_CMD_WRITE (0x0100)
+#define HERMES_CMD_PROGMODE (0x0300)
+#define HERMES_CMD_CMDCODE (0x003f)
+
+/*
+ * STATUS register bitmasks
+ */
+#define HERMES_STATUS_RESULT (0x7f00)
+#define HERMES_STATUS_CMDCODE (0x003f)
+
+/*
+ * OFFSET register bitmasks
+ */
+#define HERMES_OFFSET_BUSY (0x8000)
+#define HERMES_OFFSET_ERR (0x4000)
+#define HERMES_OFFSET_DATAOFF (0x0ffe)
+
+/*
+ * Event register bitmasks (INTEN, EVSTAT, EVACK)
+ */
+#define HERMES_EV_TICK (0x8000)
+#define HERMES_EV_WTERR (0x4000)
+#define HERMES_EV_INFDROP (0x2000)
+#define HERMES_EV_INFO (0x0080)
+#define HERMES_EV_DTIM (0x0020)
+#define HERMES_EV_CMD (0x0010)
+#define HERMES_EV_ALLOC (0x0008)
+#define HERMES_EV_TXEXC (0x0004)
+#define HERMES_EV_TX (0x0002)
+#define HERMES_EV_RX (0x0001)
+
+/*
+ * Command codes
+ */
+/*--- Controller Commands ----------------------------*/
+#define HERMES_CMD_INIT (0x0000)
+#define HERMES_CMD_ENABLE (0x0001)
+#define HERMES_CMD_DISABLE (0x0002)
+#define HERMES_CMD_DIAG (0x0003)
+
+/*--- Buffer Mgmt Commands ---------------------------*/
+#define HERMES_CMD_ALLOC (0x000A)
+#define HERMES_CMD_TX (0x000B)
+
+/*--- Regulate Commands ------------------------------*/
+#define HERMES_CMD_NOTIFY (0x0010)
+#define HERMES_CMD_INQUIRE (0x0011)
+
+/*--- Configure Commands -----------------------------*/
+#define HERMES_CMD_ACCESS (0x0021)
+#define HERMES_CMD_DOWNLD (0x0022)
+
+/*--- Serial I/O Commands ----------------------------*/
+#define HERMES_CMD_READMIF (0x0030)
+#define HERMES_CMD_WRITEMIF (0x0031)
+
+/*--- Debugging Commands -----------------------------*/
+#define HERMES_CMD_TEST (0x0038)
+
+
+/* Test command arguments */
+#define HERMES_TEST_SET_CHANNEL 0x0800
+#define HERMES_TEST_MONITOR 0x0b00
+#define HERMES_TEST_STOP 0x0f00
+
+/* Authentication algorithms */
+#define HERMES_AUTH_OPEN 1
+#define HERMES_AUTH_SHARED_KEY 2
+
+/* WEP settings */
+#define HERMES_WEP_PRIVACY_INVOKED 0x0001
+#define HERMES_WEP_EXCL_UNENCRYPTED 0x0002
+#define HERMES_WEP_HOST_ENCRYPT 0x0010
+#define HERMES_WEP_HOST_DECRYPT 0x0080
+
+/* Symbol hostscan options */
+#define HERMES_HOSTSCAN_SYMBOL_5SEC 0x0001
+#define HERMES_HOSTSCAN_SYMBOL_ONCE 0x0002
+#define HERMES_HOSTSCAN_SYMBOL_PASSIVE 0x0040
+#define HERMES_HOSTSCAN_SYMBOL_BCAST 0x0080
+
+/*
+ * Frame structures and constants
+ */
+
+#define HERMES_DESCRIPTOR_OFFSET 0
+#define HERMES_802_11_OFFSET (14)
+#define HERMES_802_3_OFFSET (14+32)
+#define HERMES_802_2_OFFSET (14+32+14)
+
+#define HERMES_RXSTAT_ERR (0x0003)
+#define HERMES_RXSTAT_BADCRC (0x0001)
+#define HERMES_RXSTAT_UNDECRYPTABLE (0x0002)
+#define HERMES_RXSTAT_MACPORT (0x0700)
+#define HERMES_RXSTAT_PCF (0x1000) /* Frame was received in CF period */
+#define HERMES_RXSTAT_MSGTYPE (0xE000)
+#define HERMES_RXSTAT_1042 (0x2000) /* RFC-1042 frame */
+#define HERMES_RXSTAT_TUNNEL (0x4000) /* bridge-tunnel encoded frame */
+#define HERMES_RXSTAT_WMP (0x6000) /* Wavelan-II Management Protocol frame */
+
+struct hermes_tx_descriptor {
+ u16 status;
+ u16 reserved1;
+ u16 reserved2;
+ u32 sw_support;
+ u8 retry_count;
+ u8 tx_rate;
+ u16 tx_control;
+} __attribute__ ((packed));
+
+#define HERMES_TXSTAT_RETRYERR (0x0001)
+#define HERMES_TXSTAT_AGEDERR (0x0002)
+#define HERMES_TXSTAT_DISCON (0x0004)
+#define HERMES_TXSTAT_FORMERR (0x0008)
+
+#define HERMES_TXCTRL_TX_OK (0x0002) /* ?? interrupt on Tx complete */
+#define HERMES_TXCTRL_TX_EX (0x0004) /* ?? interrupt on Tx exception */
+#define HERMES_TXCTRL_802_11 (0x0008) /* We supply 802.11 header */
+#define HERMES_TXCTRL_ALT_RTRY (0x0020)
+
+/* Inquiry constants and data types */
+
+#define HERMES_INQ_TALLIES (0xF100)
+#define HERMES_INQ_SCAN (0xF101)
+#define HERMES_INQ_CHANNELINFO (0xF102)
+#define HERMES_INQ_HOSTSCAN (0xF103)
+#define HERMES_INQ_HOSTSCAN_SYMBOL (0xF104)
+#define HERMES_INQ_LINKSTATUS (0xF200)
+#define HERMES_INQ_SEC_STAT_AGERE (0xF202)
+
+struct hermes_tallies_frame {
+ u16 TxUnicastFrames;
+ u16 TxMulticastFrames;
+ u16 TxFragments;
+ u16 TxUnicastOctets;
+ u16 TxMulticastOctets;
+ u16 TxDeferredTransmissions;
+ u16 TxSingleRetryFrames;
+ u16 TxMultipleRetryFrames;
+ u16 TxRetryLimitExceeded;
+ u16 TxDiscards;
+ u16 RxUnicastFrames;
+ u16 RxMulticastFrames;
+ u16 RxFragments;
+ u16 RxUnicastOctets;
+ u16 RxMulticastOctets;
+ u16 RxFCSErrors;
+ u16 RxDiscards_NoBuffer;
+ u16 TxDiscardsWrongSA;
+ u16 RxWEPUndecryptable;
+ u16 RxMsgInMsgFragments;
+ u16 RxMsgInBadMsgFragments;
+ /* Those last are probably not available in very old firmwares */
+ u16 RxDiscards_WEPICVError;
+ u16 RxDiscards_WEPExcluded;
+} __attribute__ ((packed));
+
+/* Grabbed from wlan-ng - Thanks Mark... - Jean II
+ * This is the result of a scan inquiry command */
+/* Structure describing info about an Access Point */
+struct prism2_scan_apinfo {
+ u16 channel; /* Channel where the AP sits */
+ u16 noise; /* Noise level */
+ u16 level; /* Signal level */
+ u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
+ u16 beacon_interv; /* Beacon interval */
+ u16 capabilities; /* Capabilities */
+ u16 essid_len; /* ESSID length */
+ u8 essid[32]; /* ESSID of the network */
+ u8 rates[10]; /* Bit rate supported */
+ u16 proberesp_rate; /* Data rate of the response frame */
+ u16 atim; /* ATIM window time, Kus (hostscan only) */
+} __attribute__ ((packed));
+
+/* Same stuff for the Lucent/Agere card.
+ * Thanks to h1kari <h1kari AT dachb0den.com> - Jean II */
+struct agere_scan_apinfo {
+ u16 channel; /* Channel where the AP sits */
+ u16 noise; /* Noise level */
+ u16 level; /* Signal level */
+ u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
+ u16 beacon_interv; /* Beacon interval */
+ u16 capabilities; /* Capabilities */
+ /* bits: 0-ess, 1-ibss, 4-privacy [wep] */
+ u16 essid_len; /* ESSID length */
+ u8 essid[32]; /* ESSID of the network */
+} __attribute__ ((packed));
+
+/* Moustafa: Scan structure for Symbol cards */
+struct symbol_scan_apinfo {
+ u8 channel; /* Channel where the AP sits */
+ u8 unknown1; /* 8 in 2.9x and 3.9x f/w, 0 otherwise */
+ u16 noise; /* Noise level */
+ u16 level; /* Signal level */
+ u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
+ u16 beacon_interv; /* Beacon interval */
+ u16 capabilities; /* Capabilities */
+ /* bits: 0-ess, 1-ibss, 4-privacy [wep] */
+ u16 essid_len; /* ESSID length */
+ u8 essid[32]; /* ESSID of the network */
+ u16 rates[5]; /* Bit rate supported */
+ u16 basic_rates; /* Basic rates bitmask */
+ u8 unknown2[6]; /* Always FF:FF:FF:FF:00:00 */
+ u8 unknown3[8]; /* Always 0, appeared in f/w 3.91-68 */
+} __attribute__ ((packed));
+
+union hermes_scan_info {
+ struct agere_scan_apinfo a;
+ struct prism2_scan_apinfo p;
+ struct symbol_scan_apinfo s;
+};
+
+#define HERMES_LINKSTATUS_NOT_CONNECTED (0x0000)
+#define HERMES_LINKSTATUS_CONNECTED (0x0001)
+#define HERMES_LINKSTATUS_DISCONNECTED (0x0002)
+#define HERMES_LINKSTATUS_AP_CHANGE (0x0003)
+#define HERMES_LINKSTATUS_AP_OUT_OF_RANGE (0x0004)
+#define HERMES_LINKSTATUS_AP_IN_RANGE (0x0005)
+#define HERMES_LINKSTATUS_ASSOC_FAILED (0x0006)
+
+struct hermes_linkstatus {
+ u16 linkstatus; /* Link status */
+} __attribute__ ((packed));
+
+struct hermes_response {
+ u16 status, resp0, resp1, resp2;
+};
+
+/* "ID" structure - used for ESSID and station nickname */
+struct hermes_idstring {
+ u16 len;
+ u16 val[16];
+} __attribute__ ((packed));
+
+struct hermes_multicast {
+ u8 addr[HERMES_MAX_MULTICAST][ETH_ALEN];
+} __attribute__ ((packed));
+
+// #define HERMES_DEBUG_BUFFER 1
+#define HERMES_DEBUG_BUFSIZE 4096
+struct hermes_debug_entry {
+ int bap;
+ u16 id, offset;
+ int cycles;
+};
+
+#ifdef __KERNEL__
+
+/* Timeouts */
+#define HERMES_BAP_BUSY_TIMEOUT (10000) /* In iterations of ~1us */
+
+/* Basic control structure */
+typedef struct hermes {
+ void __iomem *iobase;
+ int reg_spacing;
+#define HERMES_16BIT_REGSPACING 0
+#define HERMES_32BIT_REGSPACING 1
+
+ u16 inten; /* Which interrupts should be enabled? */
+
+#ifdef HERMES_DEBUG_BUFFER
+ struct hermes_debug_entry dbuf[HERMES_DEBUG_BUFSIZE];
+ unsigned long dbufp;
+ unsigned long profile[HERMES_BAP_BUSY_TIMEOUT+1];
+#endif
+} hermes_t;
+
+/* Register access convenience macros */
+#define hermes_read_reg(hw, off) \
+ (ioread16((hw)->iobase + ( (off) << (hw)->reg_spacing )))
+#define hermes_write_reg(hw, off, val) \
+ (iowrite16((val), (hw)->iobase + ((off) << (hw)->reg_spacing)))
+#define hermes_read_regn(hw, name) hermes_read_reg((hw), HERMES_##name)
+#define hermes_write_regn(hw, name, val) hermes_write_reg((hw), HERMES_##name, (val))
+
+/* Function prototypes */
+void hermes_struct_init(hermes_t *hw, void __iomem *address, int reg_spacing);
+int hermes_init(hermes_t *hw);
+int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0,
+ struct hermes_response *resp);
+int hermes_allocate(hermes_t *hw, u16 size, u16 *fid);
+
+int hermes_bap_pread(hermes_t *hw, int bap, void *buf, unsigned len,
+ u16 id, u16 offset);
+int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, unsigned len,
+ u16 id, u16 offset);
+int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned buflen,
+ u16 *length, void *buf);
+int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
+ u16 length, const void *value);
+
+/* Inline functions */
+
+static inline int hermes_present(hermes_t *hw)
+{
+ return hermes_read_regn(hw, SWSUPPORT0) == HERMES_MAGIC;
+}
+
+static inline void hermes_set_irqmask(hermes_t *hw, u16 events)
+{
+ hw->inten = events;
+ hermes_write_regn(hw, INTEN, events);
+}
+
+static inline int hermes_enable_port(hermes_t *hw, int port)
+{
+ return hermes_docmd_wait(hw, HERMES_CMD_ENABLE | (port << 8),
+ 0, NULL);
+}
+
+static inline int hermes_disable_port(hermes_t *hw, int port)
+{
+ return hermes_docmd_wait(hw, HERMES_CMD_DISABLE | (port << 8),
+ 0, NULL);
+}
+
+/* Initiate an INQUIRE command (tallies or scan). The result will come as an
+ * information frame in __orinoco_ev_info() */
+static inline int hermes_inquire(hermes_t *hw, u16 rid)
+{
+ return hermes_docmd_wait(hw, HERMES_CMD_INQUIRE, rid, NULL);
+}
+
+#define HERMES_BYTES_TO_RECLEN(n) ( (((n)+1)/2) + 1 )
+#define HERMES_RECLEN_TO_BYTES(n) ( ((n)-1) * 2 )
+
+/* Note that for the next two, the count is in 16-bit words, not bytes */
+static inline void hermes_read_words(struct hermes *hw, int off, void *buf, unsigned count)
+{
+ off = off << hw->reg_spacing;
+ ioread16_rep(hw->iobase + off, buf, count);
+}
+
+static inline void hermes_write_words(struct hermes *hw, int off, const void *buf, unsigned count)
+{
+ off = off << hw->reg_spacing;
+ iowrite16_rep(hw->iobase + off, buf, count);
+}
+
+static inline void hermes_clear_words(struct hermes *hw, int off, unsigned count)
+{
+ unsigned i;
+
+ off = off << hw->reg_spacing;
+
+ for (i = 0; i < count; i++)
+ iowrite16(0, hw->iobase + off);
+}
+
+#define HERMES_READ_RECORD(hw, bap, rid, buf) \
+ (hermes_read_ltv((hw),(bap),(rid), sizeof(*buf), NULL, (buf)))
+#define HERMES_WRITE_RECORD(hw, bap, rid, buf) \
+ (hermes_write_ltv((hw),(bap),(rid),HERMES_BYTES_TO_RECLEN(sizeof(*buf)),(buf)))
+
+static inline int hermes_read_wordrec(hermes_t *hw, int bap, u16 rid, u16 *word)
+{
+ u16 rec;
+ int err;
+
+ err = HERMES_READ_RECORD(hw, bap, rid, &rec);
+ *word = le16_to_cpu(rec);
+ return err;
+}
+
+static inline int hermes_write_wordrec(hermes_t *hw, int bap, u16 rid, u16 word)
+{
+ u16 rec = cpu_to_le16(word);
+ return HERMES_WRITE_RECORD(hw, bap, rid, &rec);
+}
+
+#else /* ! __KERNEL__ */
+
+/* These are provided for the benefit of userspace drivers and testing programs
+ which use ioperm() or iopl() */
+
+#define hermes_read_reg(base, off) (inw((base) + (off)))
+#define hermes_write_reg(base, off, val) (outw((val), (base) + (off)))
+
+#define hermes_read_regn(base, name) (hermes_read_reg((base), HERMES_##name))
+#define hermes_write_regn(base, name, val) (hermes_write_reg((base), HERMES_##name, (val)))
+
+/* Note that for the next two, the count is in 16-bit words, not bytes */
+#define hermes_read_data(base, off, buf, count) (insw((base) + (off), (buf), (count)))
+#define hermes_write_data(base, off, buf, count) (outsw((base) + (off), (buf), (count)))
+
+#endif /* ! __KERNEL__ */
+
+#endif /* _HERMES_H */
diff --git a/drivers/net/wireless/hermes_rid.h b/drivers/net/wireless/hermes_rid.h
new file mode 100644
index 000000000000..4f46b4809e55
--- /dev/null
+++ b/drivers/net/wireless/hermes_rid.h
@@ -0,0 +1,148 @@
+#ifndef _HERMES_RID_H
+#define _HERMES_RID_H
+
+/*
+ * Configuration RIDs
+ */
+#define HERMES_RID_CNFPORTTYPE 0xFC00
+#define HERMES_RID_CNFOWNMACADDR 0xFC01
+#define HERMES_RID_CNFDESIREDSSID 0xFC02
+#define HERMES_RID_CNFOWNCHANNEL 0xFC03
+#define HERMES_RID_CNFOWNSSID 0xFC04
+#define HERMES_RID_CNFOWNATIMWINDOW 0xFC05
+#define HERMES_RID_CNFSYSTEMSCALE 0xFC06
+#define HERMES_RID_CNFMAXDATALEN 0xFC07
+#define HERMES_RID_CNFWDSADDRESS 0xFC08
+#define HERMES_RID_CNFPMENABLED 0xFC09
+#define HERMES_RID_CNFPMEPS 0xFC0A
+#define HERMES_RID_CNFMULTICASTRECEIVE 0xFC0B
+#define HERMES_RID_CNFMAXSLEEPDURATION 0xFC0C
+#define HERMES_RID_CNFPMHOLDOVERDURATION 0xFC0D
+#define HERMES_RID_CNFOWNNAME 0xFC0E
+#define HERMES_RID_CNFOWNDTIMPERIOD 0xFC10
+#define HERMES_RID_CNFWDSADDRESS1 0xFC11
+#define HERMES_RID_CNFWDSADDRESS2 0xFC12
+#define HERMES_RID_CNFWDSADDRESS3 0xFC13
+#define HERMES_RID_CNFWDSADDRESS4 0xFC14
+#define HERMES_RID_CNFWDSADDRESS5 0xFC15
+#define HERMES_RID_CNFWDSADDRESS6 0xFC16
+#define HERMES_RID_CNFMULTICASTPMBUFFERING 0xFC17
+#define HERMES_RID_CNFWEPENABLED_AGERE 0xFC20
+#define HERMES_RID_CNFAUTHENTICATION_AGERE 0xFC21
+#define HERMES_RID_CNFMANDATORYBSSID_SYMBOL 0xFC21
+#define HERMES_RID_CNFWEPDEFAULTKEYID 0xFC23
+#define HERMES_RID_CNFDEFAULTKEY0 0xFC24
+#define HERMES_RID_CNFDEFAULTKEY1 0xFC25
+#define HERMES_RID_CNFMWOROBUST_AGERE 0xFC25
+#define HERMES_RID_CNFDEFAULTKEY2 0xFC26
+#define HERMES_RID_CNFDEFAULTKEY3 0xFC27
+#define HERMES_RID_CNFWEPFLAGS_INTERSIL 0xFC28
+#define HERMES_RID_CNFWEPKEYMAPPINGTABLE 0xFC29
+#define HERMES_RID_CNFAUTHENTICATION 0xFC2A
+#define HERMES_RID_CNFMAXASSOCSTA 0xFC2B
+#define HERMES_RID_CNFKEYLENGTH_SYMBOL 0xFC2B
+#define HERMES_RID_CNFTXCONTROL 0xFC2C
+#define HERMES_RID_CNFROAMINGMODE 0xFC2D
+#define HERMES_RID_CNFHOSTAUTHENTICATION 0xFC2E
+#define HERMES_RID_CNFRCVCRCERROR 0xFC30
+#define HERMES_RID_CNFMMLIFE 0xFC31
+#define HERMES_RID_CNFALTRETRYCOUNT 0xFC32
+#define HERMES_RID_CNFBEACONINT 0xFC33
+#define HERMES_RID_CNFAPPCFINFO 0xFC34
+#define HERMES_RID_CNFSTAPCFINFO 0xFC35
+#define HERMES_RID_CNFPRIORITYQUSAGE 0xFC37
+#define HERMES_RID_CNFTIMCTRL 0xFC40
+#define HERMES_RID_CNFTHIRTY2TALLY 0xFC42
+#define HERMES_RID_CNFENHSECURITY 0xFC43
+#define HERMES_RID_CNFGROUPADDRESSES 0xFC80
+#define HERMES_RID_CNFCREATEIBSS 0xFC81
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD 0xFC82
+#define HERMES_RID_CNFRTSTHRESHOLD 0xFC83
+#define HERMES_RID_CNFTXRATECONTROL 0xFC84
+#define HERMES_RID_CNFPROMISCUOUSMODE 0xFC85
+#define HERMES_RID_CNFBASICRATES_SYMBOL 0xFC8A
+#define HERMES_RID_CNFPREAMBLE_SYMBOL 0xFC8C
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD0 0xFC90
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD1 0xFC91
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD2 0xFC92
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD3 0xFC93
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD4 0xFC94
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD5 0xFC95
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD6 0xFC96
+#define HERMES_RID_CNFRTSTHRESHOLD0 0xFC97
+#define HERMES_RID_CNFRTSTHRESHOLD1 0xFC98
+#define HERMES_RID_CNFRTSTHRESHOLD2 0xFC99
+#define HERMES_RID_CNFRTSTHRESHOLD3 0xFC9A
+#define HERMES_RID_CNFRTSTHRESHOLD4 0xFC9B
+#define HERMES_RID_CNFRTSTHRESHOLD5 0xFC9C
+#define HERMES_RID_CNFRTSTHRESHOLD6 0xFC9D
+#define HERMES_RID_CNFHOSTSCAN_SYMBOL 0xFCAB
+#define HERMES_RID_CNFSHORTPREAMBLE 0xFCB0
+#define HERMES_RID_CNFWEPKEYS_AGERE 0xFCB0
+#define HERMES_RID_CNFEXCLUDELONGPREAMBLE 0xFCB1
+#define HERMES_RID_CNFTXKEY_AGERE 0xFCB1
+#define HERMES_RID_CNFAUTHENTICATIONRSPTO 0xFCB2
+#define HERMES_RID_CNFSCANSSID_AGERE 0xFCB2
+#define HERMES_RID_CNFBASICRATES 0xFCB3
+#define HERMES_RID_CNFSUPPORTEDRATES 0xFCB4
+#define HERMES_RID_CNFTICKTIME 0xFCE0
+#define HERMES_RID_CNFSCANREQUEST 0xFCE1
+#define HERMES_RID_CNFJOINREQUEST 0xFCE2
+#define HERMES_RID_CNFAUTHENTICATESTATION 0xFCE3
+#define HERMES_RID_CNFCHANNELINFOREQUEST 0xFCE4
+#define HERMES_RID_CNFHOSTSCAN 0xFCE5
+
+/*
+ * Information RIDs
+ */
+#define HERMES_RID_MAXLOADTIME 0xFD00
+#define HERMES_RID_DOWNLOADBUFFER 0xFD01
+#define HERMES_RID_PRIID 0xFD02
+#define HERMES_RID_PRISUPRANGE 0xFD03
+#define HERMES_RID_CFIACTRANGES 0xFD04
+#define HERMES_RID_NICSERNUM 0xFD0A
+#define HERMES_RID_NICID 0xFD0B
+#define HERMES_RID_MFISUPRANGE 0xFD0C
+#define HERMES_RID_CFISUPRANGE 0xFD0D
+#define HERMES_RID_CHANNELLIST 0xFD10
+#define HERMES_RID_REGULATORYDOMAINS 0xFD11
+#define HERMES_RID_TEMPTYPE 0xFD12
+#define HERMES_RID_CIS 0xFD13
+#define HERMES_RID_STAID 0xFD20
+#define HERMES_RID_STASUPRANGE 0xFD21
+#define HERMES_RID_MFIACTRANGES 0xFD22
+#define HERMES_RID_CFIACTRANGES2 0xFD23
+#define HERMES_RID_SECONDARYVERSION_SYMBOL 0xFD24
+#define HERMES_RID_PORTSTATUS 0xFD40
+#define HERMES_RID_CURRENTSSID 0xFD41
+#define HERMES_RID_CURRENTBSSID 0xFD42
+#define HERMES_RID_COMMSQUALITY 0xFD43
+#define HERMES_RID_CURRENTTXRATE 0xFD44
+#define HERMES_RID_CURRENTBEACONINTERVAL 0xFD45
+#define HERMES_RID_CURRENTSCALETHRESHOLDS 0xFD46
+#define HERMES_RID_PROTOCOLRSPTIME 0xFD47
+#define HERMES_RID_SHORTRETRYLIMIT 0xFD48
+#define HERMES_RID_LONGRETRYLIMIT 0xFD49
+#define HERMES_RID_MAXTRANSMITLIFETIME 0xFD4A
+#define HERMES_RID_MAXRECEIVELIFETIME 0xFD4B
+#define HERMES_RID_CFPOLLABLE 0xFD4C
+#define HERMES_RID_AUTHENTICATIONALGORITHMS 0xFD4D
+#define HERMES_RID_PRIVACYOPTIONIMPLEMENTED 0xFD4F
+#define HERMES_RID_DBMCOMMSQUALITY_INTERSIL 0xFD51
+#define HERMES_RID_CURRENTTXRATE1 0xFD80
+#define HERMES_RID_CURRENTTXRATE2 0xFD81
+#define HERMES_RID_CURRENTTXRATE3 0xFD82
+#define HERMES_RID_CURRENTTXRATE4 0xFD83
+#define HERMES_RID_CURRENTTXRATE5 0xFD84
+#define HERMES_RID_CURRENTTXRATE6 0xFD85
+#define HERMES_RID_OWNMACADDR 0xFD86
+#define HERMES_RID_SCANRESULTSTABLE 0xFD88
+#define HERMES_RID_PHYTYPE 0xFDC0
+#define HERMES_RID_CURRENTCHANNEL 0xFDC1
+#define HERMES_RID_CURRENTPOWERSTATE 0xFDC2
+#define HERMES_RID_CCAMODE 0xFDC3
+#define HERMES_RID_SUPPORTEDDATARATES 0xFDC6
+#define HERMES_RID_BUILDSEQ 0xFFFE
+#define HERMES_RID_FWID 0xFFFF
+
+#endif
diff --git a/drivers/net/wireless/i82586.h b/drivers/net/wireless/i82586.h
new file mode 100644
index 000000000000..5f65b250646f
--- /dev/null
+++ b/drivers/net/wireless/i82586.h
@@ -0,0 +1,413 @@
+/*
+ * Intel 82586 IEEE 802.3 Ethernet LAN Coprocessor.
+ *
+ * See:
+ * Intel Microcommunications 1991
+ * p1-1 to p1-37
+ * Intel order No. 231658
+ * ISBN 1-55512-119-5
+ *
+ * Unfortunately, the above chapter mentions neither
+ * the System Configuration Pointer (SCP) nor the
+ * Intermediate System Configuration Pointer (ISCP),
+ * so we probably need to look elsewhere for the
+ * whole story -- some recommend the "Intel LAN
+ * Components manual" but I have neither a copy
+ * nor a full reference. But "elsewhere" may be
+ * in the same publication...
+ * The description of a later device, the
+ * "82596CA High-Performance 32-Bit Local Area Network
+ * Coprocessor", (ibid. p1-38 to p1-109) does mention
+ * the SCP and ISCP and also has an i82586 compatibility
+ * mode. Even more useful is "AP-235 An 82586 Data Link
+ * Driver" (ibid. p1-337 to p1-417).
+ */
+
+#define I82586_MEMZ (64 * 1024)
+
+#define I82586_SCP_ADDR (I82586_MEMZ - sizeof(scp_t))
+
+#define ADDR_LEN 6
+#define I82586NULL 0xFFFF
+
+#define toff(t,p,f) (unsigned short)((void *)(&((t *)((void *)0 + (p)))->f) - (void *)0)
+
+/*
+ * System Configuration Pointer (SCP).
+ */
+typedef struct scp_t scp_t;
+struct scp_t
+{
+ unsigned short scp_sysbus; /* 82586 bus width: */
+#define SCP_SY_16BBUS (0x0 << 0) /* 16 bits */
+#define SCP_SY_8BBUS (0x1 << 0) /* 8 bits. */
+ unsigned short scp_junk[2]; /* Unused */
+ unsigned short scp_iscpl; /* lower 16 bits of ISCP_ADDR */
+ unsigned short scp_iscph; /* upper 16 bits of ISCP_ADDR */
+};
+
+/*
+ * Intermediate System Configuration Pointer (ISCP).
+ */
+typedef struct iscp_t iscp_t;
+struct