📄 wvlan_cs.c
字号:
/******************************************************************** * WaveLAN/IEEE PCMCIA Linux network device driver * * by Andreas Neuhaus <andy@fasta.fh-dortmund.de> * http://www.fasta.fh-dortmund.de/users/andy/wvlan/ * * This driver is free software; you can redistribute and/or * modify it under the terms of the GNU General Public License; * either version 2 of the license, or (at your option) any * later version. * Please send comments/bugfixes/patches to the above address. * * Based on the Linux PCMCIA Programmer's Guide * and Lucent Technologies' HCF-Light library (wvlan47). * * See 'man 4 wvlan_cs' for more information. * * TODO * We should use multiple Tx buffers to gain performance. * Have a closer look to the endianess (PPC problems). * * HISTORY * v1.0.7 11/01/2000 - Jean II and Anton Blanchard * Dont hold spinlock during copy_{to,from}_user, we might * sleep. (brought to my attention by Dave Gibson) * New Ad-Hoc mode accepts ESSID=any (Jean II) * Support new wireless extension - Transmit Power (Jean II) * Added support for 3.3V cards, fixed IPv6 (David) * * v1.0.6 7/12/2000 - David Hinds, Anton Blanchard, Jean II and others * Endianess fix for PPC users, first try (David) * Fix some ranges (power management, key size, ...) (me) * Auto rate up to a maximum (for ex. up to 5.5) (me) * Remove error on IW_ENCODE_RESTRICTED (me) * Better error messages to catch stupid users (me) * --- * Oups ! Firmware 6.06 *do* support port3 (me) * Oups ! ibss mode is not fully functional in firmware 6.04 (me) * Match Windows driver for selecting Ad-Hoc mode (me) * Get MAC address earlier, so that if module parameters are * invalid, we can still use wireless.opts... (me) * Use ethX and not wvlanX by default (me) * Minimal support for some PrismII cards (me) * Check out of bound in getratelist (Paul Mackerras) * Finish up the endianess fix for PPC and test it * (Paul Mackerras and Hugh Blemings) * Check Cabletron Firmware 4.32 support (Anton) * * v1.0.5 19/10/2000 - David Hinds, Jean II and others * Support for 6.00 firmware (remove fragmentation - ? + me) * Add Microwave Oven Robustness support (me) * Fix a bug preventing RARP from working (?) * --- * Fix SMP support (fix all those spinlocks - me) * Add IBSS support, to enable 802.11 ad-hoc mode (Ross Finlayson) * Integrate IBSS support with Wireless Extensions (me) * Clean-up Wireless Extensions (#define and other stuff - me) * Multi-card support for Wireless Extensions (me) * Firmware madness support - Arghhhhh !!!!!! (me) * --- * Proper firmware detection routines (me) * Aggregate configuration change when closed (me) * wireless.opts now works on old firmware (me) * Integrate MWO robust to frag setting (me) * copy_to/from in ioctl with irq on (me, requested by Alan) * Add a few "static" and "inline" there and there (me) * Update to new module init/cleanup procedures (me) * * v1.0.4 2000/02/26 * Some changes to fit into kernel 2.3.x. * Some changes to better fit into the new net API. * Use of spinlocks for disabling interrupts. * Conditional to allow ignoring tx timeouts. * Disable interrupts during config/shutdown/reset. * Credits go to Jean Tourrilhes for all the following: * Promiscuous mode (tcpdump now work correctly). * Set multicast Rx list (RTP now work correctly). * Hook up watchdog timer in new net API. * Update frag/rts to new W-Ext. * Operating mode support + W-Ext (Neat...). * Power Saving support + W-Ext (useless...). * WEP (Privacy - Silver+Gold) support + W-Ext (yeah !!!). * Disable interupts during reading wireless stats. * (New quality indicator not included, need more work) * Plus a few cleanups, comments and fixes... * * v1.0.3 Skipped to not confuse with kernel 2.3.x driver * * v1.0.2 2000/01/07 * Merged driver into the PCMCIA Card Services package * (thanks to David Hinds). * Removed README, added man page (man 4 wvlan_cs). * * v1.0.1 1999/09/02 * Interrupts are now disabled during ioctl to prevent being * disturbed during our fiddling with the NIC (occurred * when using wireless tools while heavy loaded link). * Fixed a problem with more than 6 spy addresses (thanks to * Thomas Ekstrom). * Hopefully fixed problems with bigger packet sizes than 1500. * When you changed parameters that were specified at module * load time later with wireless_tools and the card was * reset afterward (e.g. by a Tx timeout), all changes * were lost. Changes will stay now after a reset. * Rewrote some parts of this README, added card LEDs description. * Added medium_reservation, ap_density, frag_threshold and * transmit_rate to module parameters. * Applying the patch now also modifies the files SUPPORTED.CARDS * and MAINTAINERS. * Signal/noise levels are now reported in dBm (-102..-10). * Added support for the new wireless extension (get wireless_ * tools 19). Credits go to Jean Tourrilhes for all * the following: * Setting channel by giving frequency value is now available. * Setting/getting ESSID/BSSID/station-name is now possible * via iwconfig. * Support to set/get the desired/current bitrate. * Support to set/get RTS threshold. * Support to set/get fragmentation threshold. * Support to set/get AP density. * Support to set/get port type. * Fixed a problem with ioctl calls when setting station/network * name, where the new name string wasn't in kernel space * (thanks to Danton Nunes). * Driver sucessful tested on AlphaLinux (thanks to Peter Olson). * Driver sucessful tested with WaveLAN Turbo cards. * * v0.2.7 1999/07/20 * Changed release/detach code to fix hotswapping with 2.2/2.3 * kernels (thanks to Derrick J Brashear). * Fixed wrong adjustment of receive buffer length. This was only * a problem when a higher level protocol relies on correct * length information, so it never occurred with IPv4 * (thanks to Henrik Gulbrandsen). * * v0.2.6 1999/05/04 * Added wireless spy and histogram support. Signal levels * are now reported in ad-hoc mode correctly, but you * need to use iwspy for it, because we can 'hear' more * than one remote host in ad-hoc mode (thanks * to Albert K T Hui for the code and to Richard van * Leeuwen for the technical details). * Fixed a bug with wrong tx_bytes count. * Added GPL file wvlan.COPYING. * * v0.2.5 1999/03/12 * Hopefully fixed problems with the Makefile patch. * Changed the interrupt service routine to do never lock up * in an endless loop (if this ever would happen...). * Missed a conditional which made the driver unable to compile * on 2.0.x kernels (thanks to Glenn D. Golden). * * v0.2.4 1999/03/10 * Tested in ad-hoc mode and with access point (many thanks * to Frank Bruegmann, who made some hardware available * to me so that I can now test it myself). * Change the interrupt service routine to repeat on frame * reception and deallocate the NICs receiving frame * buffer correctly (thanks to Glenn D. Golden). * Fixed a problem with checksums where under some circumstances * an incorrect packet wasn't recognized. Switched * on the kernel checksum checking (thanks to Glenn D. Golden). * Setting the channel value is now checked against valid channel * values which are read from the card. * Added private ioctl (iwconfig priv) station_name, network_name * and current_network. It needs an iwconfig capable of * setting and gettings strings (thanks to Justin Seger). * Ioctl (iwconfig) should now return the real current used channel. * Setting the channel value is now only valid using ad-hoc mode. * It's useless when using an access points. * Renamed the ssid parameter to network_name and made it work * correctly for all port_types. It should work now * in ad-hoc networks as well as with access points. * Added entries for the NCR WaveLAN/IEEE and the Cabletron * RoamAbout 802.11 DS card (thanks to Richard van Leeuwen) * Support to count the received and transmitted bytes * if kernel version >2.1.25. * Changed the reset method in case of Tx-timeouts. * PM suspend/resume should work now (thanks to Dave Kristol). * Changed installation and driver package. Read INSTALL in this * file for information how it works now. * * v0.2.3 1999/02/25 * Added support to set the own SSID * Changed standard channel setting to 3 so that it works * with Windows without specifying a channel (the * Windows driver seem to default to channel 3). * Fixed two problems with the Ethernet-II frame de/encapsulation. * * v0.2.2 1999/02/07 * First public beta release. * Added support to get link quality via iwconfig. * Added support to change channel via iwconfig. * Added changeable MTU setting (thanks to Tomasz Motylewski). * Added Ethernet-II frame de/encapsulation, because * HCF-Light doesn't support it. * * v0.2.1 1999/02/03 * Added channel parameter. * Rewrote the driver with information made public * in Lucent's HCF-Light library. The HCF was * slightly modified to get rid of the compiler * warnings. The filenames were prefixed with * wvlan_ to better fit into the pcmcia package. * * v0.1d 1998/12/21 * Fixed a problem where the NIC was crashing during heavy * loaded transmissions. Interrupts are now disabled * during wvlan_tx() function. Seems to work fine now. * * v0.1c 1998/12/20 * Driver works fine with ad-hoc network. * * v0.1b 1998/12/19 * First successful send-tests. * * v0.1a 1998/12/18 * First tests with card functions. */#include <linux/version.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/ptrace.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/init.h>#include <linux/spinlock.h>#include <asm/io.h>#include <asm/system.h>#include <asm/uaccess.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 <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/if_arp.h>#include <linux/ioport.h>#include <linux/fcntl.h>#ifdef MODULE#ifdef MODVERSIONS#include <linux/modversions.h>#endif#include <linux/module.h>#else#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT#endif#include <linux/wireless.h>/* Note : v6 is included in : 2.0.37+ and 2.2.4+, adds ESSID *//* Note : v8 is included in : 2.2.11+ and 2.3.14+, adds frag/rts/rate/nick *//* Note : v9 is included in : 2.2.14+ and 2.3.25+, adds mode/ps/wep */#if WIRELESS_EXT < 6#warning "Wireless extension v8 or newer required - please upgrade your kernel"#undef WIRELESS_EXT#endif#if WIRELESS_EXT < 9#warning "Wireless extension v9 or newer prefered - please upgrade your kernel"#endif#define WIRELESS_SPY // enable iwspy support#undef HISTOGRAM // disable histogram of signal levels// This is needed for station_name, but we may not compile WIRELESS_EXT#ifndef IW_ESSID_MAX_SIZE#define IW_ESSID_MAX_SIZE 32#endif /* IW_ESSID_MAX_SIZE */#include "wvlan_hcf.h"/* #define PCMCIA_DEBUG 1 // For developer only :-) */// Undefine this if you want to ignore Tx timeouts// (i.e. card will not be reset on Tx timeouts)#define WVLAN_RESET_ON_TX_TIMEOUT/******************************************************************** * DEBUG */#ifdef PCMCIA_DEBUGstatic int pc_debug = PCMCIA_DEBUG;MODULE_PARM(pc_debug, "i");#define DEBUG(n, args...) if (pc_debug>=(n)) printk(KERN_DEBUG args);#else#define DEBUG(n, args...) {}#endif#define DEBUG_INFO 1#define DEBUG_NOISY 2#define DEBUG_TXRX 3#define DEBUG_CALLTRACE 4#define DEBUG_INTERRUPT 5/******************************************************************** * MISC */static char *version = "1.0.6";static dev_info_t dev_info = "wvlan_cs";static dev_link_t *dev_list = NULL;// Module parametersstatic u_int irq_mask = 0xdeb8; // Interrupt maskstatic int irq_list[4] = { -1 }; // Interrupt list (alternative)static int eth = 1; // use ethX devnamestatic int mtu = 1500;// Note : the following parameters can be also modified through Wireless// Extension, and additional parameters are also available this way...static int port_type = 1; // Port-type [1]static int allow_ibss = 0; // Allow a IBSS [0]static char network_name[IW_ESSID_MAX_SIZE+1] = "\0"; // Name of network []static int channel = 3; // Channel [3]MODULE_PARM(irq_mask, "i");MODULE_PARM(irq_list, "1-4i");MODULE_PARM(eth, "i");MODULE_PARM(mtu, "i");MODULE_PARM(port_type, "i");MODULE_PARM(allow_ibss, "i");MODULE_PARM(network_name, "c" __MODULE_STRING(IW_ESSID_MAX_SIZE));MODULE_PARM(channel, "i");// Backward compatibility - This one is obsolete and will be removed soonstatic char station_name[IW_ESSID_MAX_SIZE+1] = "\0"; // Name of station []MODULE_PARM(station_name, "c" __MODULE_STRING(IW_ESSID_MAX_SIZE));MODULE_LICENSE("GPL");// Useful macros we have in pcmcia-cs but not in the kernel#ifndef __IN_PCMCIA_PACKAGE__#define DEV_KFREE_SKB(skb) dev_kfree_skb(skb);#define skb_tx_check(dev, skb)#define add_rx_bytes(stats, n) (stats)->rx_bytes += n;#define add_tx_bytes(stats, n) (stats)->tx_bytes += n;#endif// Ethernet timeout is ((400*HZ)/1000), but we should use a higher// value, because wireless transmissions are much slower#define TX_TIMEOUT ((4000*HZ)/1000)// Ethernet-II snap headerstatic char snap_header[] = { 0x00, 0x00, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };// Valid MTU values (HCF_MAX_MSG (2304) is the max hardware frame size)#define WVLAN_MIN_MTU 256#define WVLAN_MAX_MTU (HCF_MAX_MSG - sizeof(snap_header))// Max number of multicast addresses that the filter can accept#define WVLAN_MAX_MULTICAST GROUP_ADDR_SIZE/6// Frequency list (map channels to frequencies)const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484 };// Bit-rate list in 1/2 Mb/s (first is dummy - not for original turbo)const int rate_list[] = { 0, 2, 4, -22, 11, 22, -4, -11, 0, 0, 0, 0 };// A few details needed for WEP (Wireless Equivalent Privacy)#define MAX_KEY_SIZE 13 // 128/104 (?) bits#define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP#define MAX_KEYS 4 // 4 different keys// Keep track of wvlanX devices#define MAX_WVLAN_CARDS 16static struct net_device *wvlandev_index[MAX_WVLAN_CARDS];// Local data for netdevicestruct net_local { dev_node_t node; struct net_device *dev; // backtrack device dev_link_t *link; // backtrack link spinlock_t slock; // spinlock int interrupt; // interrupt IFB_STRCT ifb; // WaveLAN HCF structure struct net_device_stats stats; // device stats u_char promiscuous; // Promiscuous mode u_char allmulticast; // All multicast mode int mc_count; // Number of multicast addrs int need_commit; // Need to set config /* Capabilities : what the firmware do support */ int has_port3; // Ad-Hoc demo mode int has_ibssid; // IBSS Ad-Hoc mode int has_mwo; // MWO robust support int has_wep; // Lucent WEP support int has_pwep; // Prism WEP support int has_pm; // Power Management support /* Configuration : what is the current state of the hardware */ int port_type; // Port-type [1] int allow_ibss; // Allow a IBSS [0] char network_name[IW_ESSID_MAX_SIZE+1]; // Name of network [] int channel; // Channel [3]#ifdef WIRELESS_EXT char station_name[IW_ESSID_MAX_SIZE+1]; // Name of station [] int ap_density; // AP density [1] int medium_reservation; // RTS threshold [2347] int frag_threshold; // Frag. threshold [2346] int mwo_robust; // MWO robustness [0] int transmit_rate; // Transmit rate [3] int wep_on; // WEP enabled int transmit_key; // Key used for transmissions KEY_STRCT key[MAX_KEYS]; // WEP keys & size int pm_on; // Power Management enabled int pm_multi; // Receive multicasts int pm_period; // Power Management period#ifdef WIRELESS_SPY int spy_number; u_char spy_address[IW_MAX_SPY][MAC_ADDR_SIZE]; struct iw_quality spy_stat[IW_MAX_SPY];#endif#ifdef HISTOGRAM int his_number; u_char his_range[16]; u_long his_sum[16];#endif struct iw_statistics wstats; // wireless stats#endif /* WIRELESS_EXT */};// Shortcuts#ifdef WIRELESS_EXTtypedef struct iw_statistics iw_stats;typedef struct iw_quality iw_qual;typedef struct iw_freq iw_freq;#endif /* WIRELESS_EXT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -