| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*============================================================================= | 
 | 2 |  * | 
 | 3 |  * A  PCMCIA client driver for the Raylink wireless LAN card. | 
 | 4 |  * The starting point for this module was the skeleton.c in the | 
 | 5 |  * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net | 
 | 6 |  * | 
 | 7 |  * | 
 | 8 |  * Copyright (c) 1998  Corey Thomas (corey@world.std.com) | 
 | 9 |  * | 
 | 10 |  * This driver is free software; you can redistribute it and/or modify | 
 | 11 |  * it under the terms of version 2 only of the GNU General Public License as  | 
 | 12 |  * published by the Free Software Foundation. | 
 | 13 |  * | 
 | 14 |  * It is distributed in the hope that it will be useful, | 
 | 15 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 16 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 17 |  * GNU General Public License for more details. | 
 | 18 |  * | 
 | 19 |  * You should have received a copy of the GNU General Public License | 
 | 20 |  * along with this program; if not, write to the Free Software | 
 | 21 |  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | 
 | 22 |  * | 
 | 23 |  * Changes: | 
 | 24 |  * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000 | 
 | 25 |  * - reorganize kmallocs in ray_attach, checking all for failure | 
 | 26 |  *   and releasing the previous allocations if one fails | 
 | 27 |  * | 
 | 28 |  * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003 | 
 | 29 |  * - Audit copy_to_user in ioctl(SIOCGIWESSID) | 
 | 30 |  *  | 
 | 31 | =============================================================================*/ | 
 | 32 |  | 
 | 33 | #include <linux/config.h> | 
 | 34 | #include <linux/module.h> | 
 | 35 | #include <linux/kernel.h> | 
 | 36 | #include <linux/proc_fs.h> | 
 | 37 | #include <linux/ptrace.h> | 
 | 38 | #include <linux/slab.h> | 
 | 39 | #include <linux/string.h> | 
 | 40 | #include <linux/timer.h> | 
 | 41 | #include <linux/init.h> | 
 | 42 | #include <linux/netdevice.h> | 
 | 43 | #include <linux/etherdevice.h> | 
 | 44 | #include <linux/if_arp.h> | 
 | 45 | #include <linux/ioport.h> | 
 | 46 | #include <linux/skbuff.h> | 
 | 47 | #include <linux/ethtool.h> | 
 | 48 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <pcmcia/cs_types.h> | 
 | 50 | #include <pcmcia/cs.h> | 
 | 51 | #include <pcmcia/cistpl.h> | 
 | 52 | #include <pcmcia/cisreg.h> | 
 | 53 | #include <pcmcia/ds.h> | 
 | 54 | #include <pcmcia/mem_op.h> | 
 | 55 |  | 
| Jeff Garzik | bbeec90 | 2005-09-07 00:27:54 -0400 | [diff] [blame] | 56 | #include <net/ieee80211.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <linux/wireless.h> | 
 | 58 |  | 
 | 59 | #include <asm/io.h> | 
 | 60 | #include <asm/system.h> | 
 | 61 | #include <asm/byteorder.h> | 
 | 62 | #include <asm/uaccess.h> | 
 | 63 |  | 
 | 64 | /* Warning : these stuff will slow down the driver... */ | 
 | 65 | #define WIRELESS_SPY		/* Enable spying addresses */ | 
 | 66 | /* Definitions we need for spy */ | 
 | 67 | typedef struct iw_statistics	iw_stats; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | typedef u_char	mac_addr[ETH_ALEN];	/* Hardware address */ | 
 | 69 |  | 
 | 70 | #include "rayctl.h" | 
 | 71 | #include "ray_cs.h" | 
 | 72 |  | 
 | 73 | /* All the PCMCIA modules use PCMCIA_DEBUG to control debugging.  If | 
 | 74 |    you do not define PCMCIA_DEBUG at all, all the debug code will be | 
 | 75 |    left out.  If you compile with PCMCIA_DEBUG=0, the debug code will | 
 | 76 |    be present but disabled -- but it can then be enabled for specific | 
 | 77 |    modules at load time with a 'pc_debug=#' option to insmod. | 
 | 78 | */ | 
 | 79 |  | 
 | 80 | #ifdef RAYLINK_DEBUG | 
 | 81 | #define PCMCIA_DEBUG RAYLINK_DEBUG | 
 | 82 | #endif | 
 | 83 | #ifdef PCMCIA_DEBUG | 
 | 84 | static int ray_debug; | 
 | 85 | static int pc_debug = PCMCIA_DEBUG; | 
 | 86 | module_param(pc_debug, int, 0); | 
 | 87 | /* #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); */ | 
 | 88 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(args); | 
 | 89 | #else | 
 | 90 | #define DEBUG(n, args...) | 
 | 91 | #endif | 
 | 92 | /** Prototypes based on PCMCIA skeleton driver *******************************/ | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 93 | static int ray_config(struct pcmcia_device *link); | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 94 | static void ray_release(struct pcmcia_device *link); | 
| Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 95 | static void ray_detach(struct pcmcia_device *p_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 |  | 
 | 97 | /***** Prototypes indicated by device structure ******************************/ | 
 | 98 | static int ray_dev_close(struct net_device *dev); | 
 | 99 | static int ray_dev_config(struct net_device *dev, struct ifmap *map); | 
 | 100 | static struct net_device_stats *ray_get_stats(struct net_device *dev); | 
 | 101 | static int ray_dev_init(struct net_device *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 |  | 
 | 103 | static struct ethtool_ops netdev_ethtool_ops; | 
 | 104 |  | 
 | 105 | static int ray_open(struct net_device *dev); | 
 | 106 | static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev); | 
 | 107 | static void set_multicast_list(struct net_device *dev); | 
 | 108 | static void ray_update_multi_list(struct net_device *dev, int all); | 
 | 109 | static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, | 
 | 110 |                 unsigned char *data, int len); | 
 | 111 | static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, UCHAR msg_type, | 
 | 112 |                 unsigned char *data); | 
 | 113 | static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static iw_stats * ray_get_wireless_stats(struct net_device *	dev); | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 115 | static const struct iw_handler_def	ray_handler_def; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 |  | 
 | 117 | /***** Prototypes for raylink functions **************************************/ | 
 | 118 | static int asc_to_int(char a); | 
 | 119 | static void authenticate(ray_dev_t *local); | 
 | 120 | static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type); | 
 | 121 | static void authenticate_timeout(u_long); | 
 | 122 | static int get_free_ccs(ray_dev_t *local); | 
 | 123 | static int get_free_tx_ccs(ray_dev_t *local); | 
 | 124 | static void init_startup_params(ray_dev_t *local); | 
 | 125 | static int parse_addr(char *in_str, UCHAR *out); | 
 | 126 | static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev, UCHAR type); | 
 | 127 | static int ray_init(struct net_device *dev); | 
 | 128 | static int interrupt_ecf(ray_dev_t *local, int ccs); | 
 | 129 | static void ray_reset(struct net_device *dev); | 
 | 130 | static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len); | 
 | 131 | static void verify_dl_startup(u_long); | 
 | 132 |  | 
 | 133 | /* Prototypes for interrpt time functions **********************************/ | 
 | 134 | static irqreturn_t ray_interrupt (int reg, void *dev_id, struct pt_regs *regs); | 
 | 135 | static void clear_interrupt(ray_dev_t *local); | 
 | 136 | static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,  | 
 | 137 |                        unsigned int pkt_addr, int rx_len); | 
 | 138 | static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len); | 
 | 139 | static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs); | 
 | 140 | static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs); | 
 | 141 | static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs, | 
 | 142 |                      unsigned int pkt_addr, int rx_len); | 
 | 143 | static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, unsigned int pkt_addr,  | 
 | 144 |              int rx_len); | 
 | 145 | static void associate(ray_dev_t *local); | 
 | 146 |  | 
 | 147 | /* Card command functions */ | 
 | 148 | static int dl_startup_params(struct net_device *dev); | 
 | 149 | static void join_net(u_long local); | 
 | 150 | static void start_net(u_long local); | 
 | 151 | /* void start_net(ray_dev_t *local); */ | 
 | 152 |  | 
 | 153 | /*===========================================================================*/ | 
 | 154 | /* Parameters that can be set with 'insmod' */ | 
 | 155 |  | 
 | 156 | /* ADHOC=0, Infrastructure=1 */ | 
 | 157 | static int net_type = ADHOC; | 
 | 158 |  | 
 | 159 | /* Hop dwell time in Kus (1024 us units defined by 802.11) */ | 
 | 160 | static int hop_dwell = 128; | 
 | 161 |  | 
 | 162 | /* Beacon period in Kus */ | 
 | 163 | static int beacon_period = 256; | 
 | 164 |  | 
 | 165 | /* power save mode (0 = off, 1 = save power) */ | 
 | 166 | static int psm; | 
 | 167 |  | 
 | 168 | /* String for network's Extended Service Set ID. 32 Characters max */ | 
 | 169 | static char *essid; | 
 | 170 |  | 
 | 171 | /* Default to encapsulation unless translation requested */ | 
 | 172 | static int translate = 1; | 
 | 173 |  | 
 | 174 | static int country = USA; | 
 | 175 |  | 
 | 176 | static int sniffer; | 
 | 177 |  | 
 | 178 | static int bc; | 
 | 179 |  | 
 | 180 | /* 48 bit physical card address if overriding card's real physical | 
 | 181 |  * address is required.  Since IEEE 802.11 addresses are 48 bits | 
 | 182 |  * like ethernet, an int can't be used, so a string is used. To | 
 | 183 |  * allow use of addresses starting with a decimal digit, the first | 
 | 184 |  * character must be a letter and will be ignored. This letter is | 
 | 185 |  * followed by up to 12 hex digits which are the address.  If less | 
 | 186 |  * than 12 digits are used, the address will be left filled with 0's. | 
 | 187 |  * Note that bit 0 of the first byte is the broadcast bit, and evil | 
 | 188 |  * things will happen if it is not 0 in a card address. | 
 | 189 |  */ | 
 | 190 | static char *phy_addr = NULL; | 
 | 191 |  | 
 | 192 |  | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 193 | /* A struct pcmcia_device structure has fields for most things that are needed | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 |    to keep track of a socket, but there will usually be some device | 
 | 195 |    specific information that also needs to be kept track of.  The | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 196 |    'priv' pointer in a struct pcmcia_device structure can be used to point to | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 |    a device-specific private data structure, like this. | 
 | 198 | */ | 
 | 199 | static unsigned int ray_mem_speed = 500; | 
 | 200 |  | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 201 | /* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */ | 
 | 202 | static struct pcmcia_device *this_device = NULL; | 
 | 203 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | MODULE_AUTHOR("Corey Thomas <corey@world.std.com>"); | 
 | 205 | MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver"); | 
 | 206 | MODULE_LICENSE("GPL"); | 
 | 207 |  | 
 | 208 | module_param(net_type, int, 0); | 
 | 209 | module_param(hop_dwell, int, 0); | 
 | 210 | module_param(beacon_period, int, 0); | 
 | 211 | module_param(psm, int, 0); | 
 | 212 | module_param(essid, charp, 0); | 
 | 213 | module_param(translate, int, 0); | 
 | 214 | module_param(country, int, 0); | 
 | 215 | module_param(sniffer, int, 0); | 
 | 216 | module_param(bc, int, 0); | 
 | 217 | module_param(phy_addr, charp, 0); | 
 | 218 | module_param(ray_mem_speed, int, 0); | 
 | 219 |  | 
 | 220 | static UCHAR b5_default_startup_parms[] = { | 
 | 221 |     0,   0,                         /* Adhoc station */ | 
 | 222 |    'L','I','N','U','X', 0,  0,  0,  /* 32 char ESSID */ | 
 | 223 |     0,  0,  0,  0,  0,  0,  0,  0, | 
 | 224 |     0,  0,  0,  0,  0,  0,  0,  0, | 
 | 225 |     0,  0,  0,  0,  0,  0,  0,  0, | 
 | 226 |     1,  0,                          /* Active scan, CA Mode */ | 
 | 227 |     0,  0,  0,  0,  0,  0,          /* No default MAC addr  */ | 
 | 228 |     0x7f, 0xff,                     /* Frag threshold */ | 
 | 229 |     0x00, 0x80,                     /* Hop time 128 Kus*/ | 
 | 230 |     0x01, 0x00,                     /* Beacon period 256 Kus */ | 
 | 231 |     0x01, 0x07, 0xa3,               /* DTIM, retries, ack timeout*/ | 
 | 232 |     0x1d, 0x82, 0x4e,               /* SIFS, DIFS, PIFS */ | 
 | 233 |     0x7f, 0xff,                     /* RTS threshold */ | 
 | 234 |     0x04, 0xe2, 0x38, 0xA4,         /* scan_dwell, max_scan_dwell */ | 
 | 235 |     0x05,                           /* assoc resp timeout thresh */ | 
 | 236 |     0x08, 0x02, 0x08,               /* adhoc, infra, super cycle max*/ | 
 | 237 |     0,                              /* Promiscuous mode */ | 
 | 238 |     0x0c, 0x0bd,                    /* Unique word */ | 
 | 239 |     0x32,                           /* Slot time */ | 
 | 240 |     0xff, 0xff,                     /* roam-low snr, low snr count */ | 
 | 241 |     0x05, 0xff,                     /* Infra, adhoc missed bcn thresh */ | 
 | 242 |     0x01, 0x0b, 0x4f,               /* USA, hop pattern, hop pat length */ | 
 | 243 | /* b4 - b5 differences start here */ | 
 | 244 |     0x00, 0x3f,                     /* CW max */ | 
 | 245 |     0x00, 0x0f,                     /* CW min */ | 
 | 246 |     0x04, 0x08,                     /* Noise gain, limit offset */ | 
 | 247 |     0x28, 0x28,                     /* det rssi, med busy offsets */ | 
 | 248 |     7,                              /* det sync thresh */ | 
 | 249 |     0, 2, 2,                        /* test mode, min, max */ | 
 | 250 |     0,                              /* allow broadcast SSID probe resp */ | 
 | 251 |     0, 0,                           /* privacy must start, can join */ | 
 | 252 |     2, 0, 0, 0, 0, 0, 0, 0          /* basic rate set */ | 
 | 253 | }; | 
 | 254 |  | 
 | 255 | static UCHAR b4_default_startup_parms[] = { | 
 | 256 |     0,   0,                         /* Adhoc station */ | 
 | 257 |    'L','I','N','U','X', 0,  0,  0,  /* 32 char ESSID */ | 
 | 258 |     0,  0,  0,  0,  0,  0,  0,  0, | 
 | 259 |     0,  0,  0,  0,  0,  0,  0,  0, | 
 | 260 |     0,  0,  0,  0,  0,  0,  0,  0, | 
 | 261 |     1,  0,                          /* Active scan, CA Mode */ | 
 | 262 |     0,  0,  0,  0,  0,  0,          /* No default MAC addr  */ | 
 | 263 |     0x7f, 0xff,                     /* Frag threshold */ | 
 | 264 |     0x02, 0x00,                     /* Hop time */ | 
 | 265 |     0x00, 0x01,                     /* Beacon period */ | 
 | 266 |     0x01, 0x07, 0xa3,               /* DTIM, retries, ack timeout*/ | 
 | 267 |     0x1d, 0x82, 0xce,               /* SIFS, DIFS, PIFS */ | 
 | 268 |     0x7f, 0xff,                     /* RTS threshold */ | 
 | 269 |     0xfb, 0x1e, 0xc7, 0x5c,         /* scan_dwell, max_scan_dwell */ | 
 | 270 |     0x05,                           /* assoc resp timeout thresh */ | 
 | 271 |     0x04, 0x02, 0x4,                /* adhoc, infra, super cycle max*/ | 
 | 272 |     0,                              /* Promiscuous mode */ | 
 | 273 |     0x0c, 0x0bd,                    /* Unique word */ | 
 | 274 |     0x4e,                           /* Slot time (TBD seems wrong)*/ | 
 | 275 |     0xff, 0xff,                     /* roam-low snr, low snr count */ | 
 | 276 |     0x05, 0xff,                     /* Infra, adhoc missed bcn thresh */ | 
 | 277 |     0x01, 0x0b, 0x4e,               /* USA, hop pattern, hop pat length */ | 
 | 278 | /* b4 - b5 differences start here */ | 
 | 279 |     0x3f, 0x0f,                     /* CW max, min */ | 
 | 280 |     0x04, 0x08,                     /* Noise gain, limit offset */ | 
 | 281 |     0x28, 0x28,                     /* det rssi, med busy offsets */ | 
 | 282 |     7,                              /* det sync thresh */ | 
 | 283 |     0, 2, 2                         /* test mode, min, max*/ | 
 | 284 | }; | 
 | 285 | /*===========================================================================*/ | 
 | 286 | static unsigned char eth2_llc[] = {0xaa, 0xaa, 3, 0, 0, 0}; | 
 | 287 |  | 
 | 288 | static char hop_pattern_length[] = { 1, | 
 | 289 | 	     USA_HOP_MOD,             EUROPE_HOP_MOD, | 
 | 290 | 	     JAPAN_HOP_MOD,           KOREA_HOP_MOD, | 
 | 291 | 	     SPAIN_HOP_MOD,           FRANCE_HOP_MOD, | 
 | 292 | 	     ISRAEL_HOP_MOD,          AUSTRALIA_HOP_MOD, | 
 | 293 | 	     JAPAN_TEST_HOP_MOD | 
 | 294 | }; | 
 | 295 |  | 
 | 296 | static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>"; | 
 | 297 |  | 
 | 298 | /*============================================================================= | 
 | 299 |     ray_attach() creates an "instance" of the driver, allocating | 
 | 300 |     local data structures for one device.  The device is registered | 
 | 301 |     with Card Services. | 
 | 302 |     The dev_link structure is initialized, but we don't actually | 
 | 303 |     configure the card at this point -- we wait until we receive a | 
 | 304 |     card insertion event. | 
 | 305 | =============================================================================*/ | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 306 | static int ray_probe(struct pcmcia_device *p_dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 |     ray_dev_t *local; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 |     struct net_device *dev; | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 310 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 |     DEBUG(1, "ray_attach()\n"); | 
 | 312 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 |     /* Allocate space for private device-specific data */ | 
 | 314 |     dev = alloc_etherdev(sizeof(ray_dev_t)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 |     if (!dev) | 
 | 316 | 	    goto fail_alloc_dev; | 
 | 317 |  | 
 | 318 |     local = dev->priv; | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 319 |     local->finder = p_dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 |  | 
 | 321 |     /* The io structure describes IO port mapping. None used here */ | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 322 |     p_dev->io.NumPorts1 = 0; | 
 | 323 |     p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8; | 
 | 324 |     p_dev->io.IOAddrLines = 5; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 |  | 
 | 326 |     /* Interrupt setup. For PCMCIA, driver takes what's given */ | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 327 |     p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; | 
 | 328 |     p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID; | 
 | 329 |     p_dev->irq.Handler = &ray_interrupt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 |  | 
 | 331 |     /* General socket configuration */ | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 332 |     p_dev->conf.Attributes = CONF_ENABLE_IRQ; | 
 | 333 |     p_dev->conf.IntType = INT_MEMORY_AND_IO; | 
 | 334 |     p_dev->conf.ConfigIndex = 1; | 
 | 335 |     p_dev->conf.Present = PRESENT_OPTION; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 |  | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 337 |     p_dev->priv = dev; | 
 | 338 |     p_dev->irq.Instance = dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 |      | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 340 |     local->finder = p_dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 |     local->card_status = CARD_INSERTED; | 
 | 342 |     local->authentication_state = UNAUTHENTICATED; | 
 | 343 |     local->num_multi = 0; | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 344 |     DEBUG(2,"ray_attach p_dev = %p,  dev = %p,  local = %p, intr = %p\n", | 
 | 345 |           p_dev,dev,local,&ray_interrupt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 |  | 
 | 347 |     /* Raylink entries in the device structure */ | 
 | 348 |     dev->hard_start_xmit = &ray_dev_start_xmit; | 
 | 349 |     dev->set_config = &ray_dev_config; | 
 | 350 |     dev->get_stats  = &ray_get_stats; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 |     SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 352 |     dev->wireless_handlers = &ray_handler_def; | 
 | 353 | #ifdef WIRELESS_SPY | 
 | 354 |     local->wireless_data.spy_data = &local->spy_data; | 
 | 355 |     dev->wireless_data = &local->wireless_data; | 
 | 356 | #endif	/* WIRELESS_SPY */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 |  | 
 | 358 |     dev->set_multicast_list = &set_multicast_list; | 
 | 359 |  | 
 | 360 |     DEBUG(2,"ray_cs ray_attach calling ether_setup.)\n"); | 
 | 361 |     SET_MODULE_OWNER(dev); | 
 | 362 |     dev->init = &ray_dev_init; | 
 | 363 |     dev->open = &ray_open; | 
 | 364 |     dev->stop = &ray_dev_close; | 
 | 365 |     netif_stop_queue(dev); | 
 | 366 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 |     init_timer(&local->timer); | 
 | 368 |  | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 369 |     this_device = p_dev; | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 370 |     return ray_config(p_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 |  | 
 | 372 | fail_alloc_dev: | 
| Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 373 |     return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } /* ray_attach */ | 
 | 375 | /*============================================================================= | 
 | 376 |     This deletes a driver "instance".  The device is de-registered | 
 | 377 |     with Card Services.  If it has been released, all local data | 
 | 378 |     structures are freed.  Otherwise, the structures will be freed | 
 | 379 |     when the device is released. | 
 | 380 | =============================================================================*/ | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 381 | static void ray_detach(struct pcmcia_device *link) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { | 
| Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 383 |     struct net_device *dev; | 
 | 384 |     ray_dev_t *local; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 |  | 
 | 386 |     DEBUG(1, "ray_detach(0x%p)\n", link); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 |  | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 388 |     this_device = NULL; | 
| Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 389 |     dev = link->priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 391 |     ray_release(link); | 
| Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 392 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 393 |     local = (ray_dev_t *)dev->priv; | 
 | 394 |     del_timer(&local->timer); | 
| Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 395 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 |     if (link->priv) { | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 397 | 	if (link->dev_node) unregister_netdev(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 |         free_netdev(dev); | 
 | 399 |     } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 |     DEBUG(2,"ray_cs ray_detach ending\n"); | 
 | 401 | } /* ray_detach */ | 
 | 402 | /*============================================================================= | 
 | 403 |     ray_config() is run after a CARD_INSERTION event | 
 | 404 |     is received, to configure the PCMCIA socket, and to make the | 
 | 405 |     ethernet device available to the system. | 
 | 406 | =============================================================================*/ | 
 | 407 | #define CS_CHECK(fn, ret) \ | 
 | 408 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | 
 | 409 | #define MAX_TUPLE_SIZE 128 | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 410 | static int ray_config(struct pcmcia_device *link) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 |     tuple_t tuple; | 
 | 413 |     cisparse_t parse; | 
 | 414 |     int last_fn = 0, last_ret = 0; | 
 | 415 |     int i; | 
 | 416 |     u_char buf[MAX_TUPLE_SIZE]; | 
 | 417 |     win_req_t req; | 
 | 418 |     memreq_t mem; | 
 | 419 |     struct net_device *dev = (struct net_device *)link->priv; | 
 | 420 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 421 |  | 
 | 422 |     DEBUG(1, "ray_config(0x%p)\n", link); | 
 | 423 |  | 
 | 424 |     /* This reads the card's CONFIG tuple to find its configuration regs */ | 
 | 425 |     tuple.DesiredTuple = CISTPL_CONFIG; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 426 |     CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 |     tuple.TupleData = buf; | 
 | 428 |     tuple.TupleDataMax = MAX_TUPLE_SIZE; | 
 | 429 |     tuple.TupleOffset = 0; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 430 |     CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); | 
 | 431 |     CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 |     link->conf.ConfigBase = parse.config.base; | 
 | 433 |     link->conf.Present = parse.config.rmask[0]; | 
 | 434 |  | 
 | 435 |     /* Determine card type and firmware version */ | 
 | 436 |     buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0; | 
 | 437 |     tuple.DesiredTuple = CISTPL_VERS_1; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 438 |     CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 |     tuple.TupleData = buf; | 
 | 440 |     tuple.TupleDataMax = MAX_TUPLE_SIZE; | 
 | 441 |     tuple.TupleOffset = 2; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 442 |     CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 |  | 
 | 444 |     for (i=0; i<tuple.TupleDataLen - 4; i++)  | 
 | 445 |         if (buf[i] == 0) buf[i] = ' '; | 
 | 446 |     printk(KERN_INFO "ray_cs Detected: %s\n",buf); | 
 | 447 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 |     /* Now allocate an interrupt line.  Note that this does not | 
 | 449 |        actually assign a handler to the interrupt. | 
 | 450 |     */ | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 451 |     CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 |     dev->irq = link->irq.AssignedIRQ; | 
 | 453 |      | 
 | 454 |     /* This actually configures the PCMCIA socket -- setting up | 
 | 455 |        the I/O windows and the interrupt mapping. | 
 | 456 |     */ | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 457 |     CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 |  | 
 | 459 | /*** Set up 32k window for shared memory (transmit and control) ************/ | 
 | 460 |     req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; | 
 | 461 |     req.Base = 0; | 
 | 462 |     req.Size = 0x8000; | 
 | 463 |     req.AccessSpeed = ray_mem_speed; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 464 |     CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 |     mem.CardOffset = 0x0000; mem.Page = 0; | 
 | 466 |     CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); | 
 | 467 |     local->sram = ioremap(req.Base,req.Size); | 
 | 468 |  | 
 | 469 | /*** Set up 16k window for shared memory (receive buffer) ***************/ | 
 | 470 |     req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; | 
 | 471 |     req.Base = 0; | 
 | 472 |     req.Size = 0x4000; | 
 | 473 |     req.AccessSpeed = ray_mem_speed; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 474 |     CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &local->rmem_handle)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 |     mem.CardOffset = 0x8000; mem.Page = 0; | 
 | 476 |     CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem)); | 
 | 477 |     local->rmem = ioremap(req.Base,req.Size); | 
 | 478 |  | 
 | 479 | /*** Set up window for attribute memory ***********************************/ | 
 | 480 |     req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT; | 
 | 481 |     req.Base = 0; | 
 | 482 |     req.Size = 0x1000; | 
 | 483 |     req.AccessSpeed = ray_mem_speed; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 484 |     CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &local->amem_handle)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 |     mem.CardOffset = 0x0000; mem.Page = 0; | 
 | 486 |     CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem)); | 
 | 487 |     local->amem = ioremap(req.Base,req.Size); | 
 | 488 |  | 
 | 489 |     DEBUG(3,"ray_config sram=%p\n",local->sram); | 
 | 490 |     DEBUG(3,"ray_config rmem=%p\n",local->rmem); | 
 | 491 |     DEBUG(3,"ray_config amem=%p\n",local->amem); | 
 | 492 |     if (ray_init(dev) < 0) { | 
 | 493 |         ray_release(link); | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 494 |         return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 |     } | 
 | 496 |  | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 497 |     SET_NETDEV_DEV(dev, &handle_to_dev(link)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 |     i = register_netdev(dev); | 
 | 499 |     if (i != 0) { | 
 | 500 |         printk("ray_config register_netdev() failed\n"); | 
 | 501 |         ray_release(link); | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 502 |         return i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 |     } | 
 | 504 |  | 
 | 505 |     strcpy(local->node.dev_name, dev->name); | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 506 |     link->dev_node = &local->node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 |     printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ", | 
 | 509 |        dev->name, dev->irq); | 
 | 510 |     for (i = 0; i < 6; i++) | 
 | 511 |     printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); | 
 | 512 |  | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 513 |     return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 |  | 
 | 515 | cs_failed: | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 516 |     cs_error(link, last_fn, last_ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 |  | 
 | 518 |     ray_release(link); | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 519 |     return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } /* ray_config */ | 
 | 521 |  | 
 | 522 | static inline struct ccs __iomem *ccs_base(ray_dev_t *dev) | 
 | 523 | { | 
 | 524 | 	return dev->sram + CCS_BASE; | 
 | 525 | } | 
 | 526 |  | 
 | 527 | static inline struct rcs __iomem *rcs_base(ray_dev_t *dev) | 
 | 528 | { | 
 | 529 | 	/* | 
 | 530 | 	 * This looks nonsensical, since there is a separate | 
 | 531 | 	 * RCS_BASE. But the difference between a "struct rcs" | 
 | 532 | 	 * and a "struct ccs" ends up being in the _index_ off | 
 | 533 | 	 * the base, so the base pointer is the same for both | 
 | 534 | 	 * ccs/rcs. | 
 | 535 | 	 */ | 
 | 536 | 	return dev->sram + CCS_BASE; | 
 | 537 | } | 
 | 538 |  | 
 | 539 | /*===========================================================================*/ | 
 | 540 | static int ray_init(struct net_device *dev) | 
 | 541 | { | 
 | 542 |     int i; | 
 | 543 |     UCHAR *p; | 
 | 544 |     struct ccs __iomem *pccs; | 
 | 545 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 546 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 |     DEBUG(1, "ray_init(0x%p)\n", dev); | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 548 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 |         DEBUG(0,"ray_init - device not present\n"); | 
 | 550 |         return -1; | 
 | 551 |     } | 
 | 552 |  | 
 | 553 |     local->net_type = net_type; | 
 | 554 |     local->sta_type = TYPE_STA; | 
 | 555 |  | 
 | 556 |     /* Copy the startup results to local memory */ | 
 | 557 |     memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,\ | 
 | 558 |            sizeof(struct startup_res_6)); | 
 | 559 |  | 
 | 560 |     /* Check Power up test status and get mac address from card */ | 
 | 561 |     if (local->startup_res.startup_word != 0x80) { | 
 | 562 |     printk(KERN_INFO "ray_init ERROR card status = %2x\n", | 
 | 563 |            local->startup_res.startup_word); | 
 | 564 |         local->card_status = CARD_INIT_ERROR; | 
 | 565 |         return -1; | 
 | 566 |     } | 
 | 567 |  | 
 | 568 |     local->fw_ver = local->startup_res.firmware_version[0]; | 
 | 569 |     local->fw_bld = local->startup_res.firmware_version[1]; | 
 | 570 |     local->fw_var = local->startup_res.firmware_version[2]; | 
 | 571 |     DEBUG(1,"ray_init firmware version %d.%d \n",local->fw_ver, local->fw_bld); | 
 | 572 |  | 
 | 573 |     local->tib_length = 0x20; | 
 | 574 |     if ((local->fw_ver == 5) && (local->fw_bld >= 30)) | 
 | 575 |         local->tib_length = local->startup_res.tib_length; | 
 | 576 |     DEBUG(2,"ray_init tib_length = 0x%02x\n", local->tib_length); | 
 | 577 |     /* Initialize CCS's to buffer free state */ | 
 | 578 |     pccs = ccs_base(local); | 
 | 579 |     for (i=0;  i<NUMBER_OF_CCS;  i++) { | 
 | 580 |         writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); | 
 | 581 |     } | 
 | 582 |     init_startup_params(local); | 
 | 583 |  | 
 | 584 |     /* copy mac address to startup parameters */ | 
 | 585 |     if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) | 
 | 586 |     { | 
 | 587 |         p = local->sparm.b4.a_mac_addr; | 
 | 588 |     } | 
 | 589 |     else | 
 | 590 |     { | 
 | 591 |         memcpy(&local->sparm.b4.a_mac_addr, | 
 | 592 |                &local->startup_res.station_addr, ADDRLEN); | 
 | 593 |         p = local->sparm.b4.a_mac_addr; | 
 | 594 |     } | 
 | 595 |  | 
 | 596 |     clear_interrupt(local); /* Clear any interrupt from the card */ | 
 | 597 |     local->card_status = CARD_AWAITING_PARAM; | 
 | 598 |     DEBUG(2,"ray_init ending\n"); | 
 | 599 |     return 0; | 
 | 600 | } /* ray_init */ | 
 | 601 | /*===========================================================================*/ | 
 | 602 | /* Download startup parameters to the card and command it to read them       */ | 
 | 603 | static int dl_startup_params(struct net_device *dev) | 
 | 604 | { | 
 | 605 |     int ccsindex; | 
 | 606 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 607 |     struct ccs __iomem *pccs; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 608 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 |  | 
 | 610 |     DEBUG(1,"dl_startup_params entered\n"); | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 611 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 |         DEBUG(2,"ray_cs dl_startup_params - device not present\n"); | 
 | 613 |         return -1; | 
 | 614 |     } | 
 | 615 |      | 
 | 616 |     /* Copy parameters to host to ECF area */ | 
 | 617 |     if (local->fw_ver == 0x55)  | 
 | 618 |         memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4, | 
 | 619 |                sizeof(struct b4_startup_params)); | 
 | 620 |     else | 
 | 621 |         memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5, | 
 | 622 |                sizeof(struct b5_startup_params)); | 
 | 623 |  | 
 | 624 |      | 
 | 625 |     /* Fill in the CCS fields for the ECF */ | 
 | 626 |     if ((ccsindex = get_free_ccs(local)) < 0) return -1; | 
 | 627 |     local->dl_param_ccs = ccsindex; | 
 | 628 |     pccs = ccs_base(local) + ccsindex; | 
 | 629 |     writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd); | 
 | 630 |     DEBUG(2,"dl_startup_params start ccsindex = %d\n", local->dl_param_ccs); | 
 | 631 |     /* Interrupt the firmware to process the command */ | 
 | 632 |     if (interrupt_ecf(local, ccsindex)) { | 
 | 633 |         printk(KERN_INFO "ray dl_startup_params failed - " | 
 | 634 |            "ECF not ready for intr\n"); | 
 | 635 |         local->card_status = CARD_DL_PARAM_ERROR; | 
 | 636 |         writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); | 
 | 637 |         return -2; | 
 | 638 |     } | 
 | 639 |     local->card_status = CARD_DL_PARAM; | 
 | 640 |     /* Start kernel timer to wait for dl startup to complete. */ | 
 | 641 |     local->timer.expires = jiffies + HZ/2; | 
 | 642 |     local->timer.data = (long)local; | 
 | 643 |     local->timer.function = &verify_dl_startup; | 
 | 644 |     add_timer(&local->timer); | 
 | 645 |     DEBUG(2,"ray_cs dl_startup_params started timer for verify_dl_startup\n"); | 
 | 646 |     return 0; | 
 | 647 | } /* dl_startup_params */ | 
 | 648 | /*===========================================================================*/ | 
 | 649 | static void init_startup_params(ray_dev_t *local) | 
 | 650 | { | 
 | 651 |     int i;  | 
 | 652 |  | 
 | 653 |     if (country > JAPAN_TEST) country = USA; | 
 | 654 |     else | 
 | 655 |         if (country < USA) country = USA; | 
 | 656 |     /* structure for hop time and beacon period is defined here using  | 
 | 657 |      * New 802.11D6.1 format.  Card firmware is still using old format | 
 | 658 |      * until version 6. | 
 | 659 |      *    Before                    After | 
 | 660 |      *    a_hop_time ms byte        a_hop_time ms byte | 
 | 661 |      *    a_hop_time 2s byte        a_hop_time ls byte | 
 | 662 |      *    a_hop_time ls byte        a_beacon_period ms byte | 
 | 663 |      *    a_beacon_period           a_beacon_period ls byte | 
 | 664 |      * | 
 | 665 |      *    a_hop_time = uS           a_hop_time = KuS | 
 | 666 |      *    a_beacon_period = hops    a_beacon_period = KuS | 
 | 667 |      */                             /* 64ms = 010000 */ | 
 | 668 |     if (local->fw_ver == 0x55)  { | 
 | 669 |         memcpy((UCHAR *)&local->sparm.b4, b4_default_startup_parms,  | 
 | 670 |                sizeof(struct b4_startup_params)); | 
 | 671 |         /* Translate sane kus input values to old build 4/5 format */ | 
 | 672 |         /* i = hop time in uS truncated to 3 bytes */ | 
 | 673 |         i = (hop_dwell * 1024) & 0xffffff; | 
 | 674 |         local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff; | 
 | 675 |         local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff; | 
 | 676 |         local->sparm.b4.a_beacon_period[0] = 0; | 
 | 677 |         local->sparm.b4.a_beacon_period[1] = | 
 | 678 |             ((beacon_period/hop_dwell) - 1) & 0xff; | 
 | 679 |         local->sparm.b4.a_curr_country_code = country; | 
 | 680 |         local->sparm.b4.a_hop_pattern_length =  | 
 | 681 |             hop_pattern_length[(int)country] - 1; | 
 | 682 |         if (bc) | 
 | 683 |         { | 
 | 684 |             local->sparm.b4.a_ack_timeout = 0x50; | 
 | 685 |             local->sparm.b4.a_sifs = 0x3f; | 
 | 686 |         } | 
 | 687 |     } | 
 | 688 |     else {    /* Version 5 uses real kus values */ | 
 | 689 |         memcpy((UCHAR *)&local->sparm.b5, b5_default_startup_parms,  | 
 | 690 |                sizeof(struct b5_startup_params)); | 
 | 691 |  | 
 | 692 |         local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff; | 
 | 693 |         local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff; | 
 | 694 |         local->sparm.b5.a_beacon_period[0] = (beacon_period >> 8) & 0xff; | 
 | 695 |         local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff; | 
 | 696 |         if (psm) | 
 | 697 |             local->sparm.b5.a_power_mgt_state = 1; | 
 | 698 |         local->sparm.b5.a_curr_country_code = country; | 
 | 699 |         local->sparm.b5.a_hop_pattern_length =  | 
 | 700 |             hop_pattern_length[(int)country]; | 
 | 701 |     } | 
 | 702 |      | 
 | 703 |     local->sparm.b4.a_network_type = net_type & 0x01; | 
 | 704 |     local->sparm.b4.a_acting_as_ap_status = TYPE_STA; | 
 | 705 |  | 
 | 706 |     if (essid != NULL) | 
 | 707 |         strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE); | 
 | 708 | } /* init_startup_params */  | 
 | 709 | /*===========================================================================*/ | 
 | 710 | static void verify_dl_startup(u_long data) | 
 | 711 | { | 
 | 712 |     ray_dev_t *local = (ray_dev_t *)data; | 
 | 713 |     struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs; | 
 | 714 |     UCHAR status; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 715 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 717 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 |         DEBUG(2,"ray_cs verify_dl_startup - device not present\n"); | 
 | 719 |         return; | 
 | 720 |     } | 
 | 721 | #ifdef PCMCIA_DEBUG | 
 | 722 |     if (pc_debug > 2) { | 
 | 723 |     int i; | 
 | 724 |     printk(KERN_DEBUG "verify_dl_startup parameters sent via ccs %d:\n", | 
 | 725 |            local->dl_param_ccs); | 
 | 726 |         for (i=0; i<sizeof(struct b5_startup_params); i++) { | 
 | 727 |             printk(" %2x", (unsigned int) readb(local->sram + HOST_TO_ECF_BASE + i)); | 
 | 728 |         } | 
 | 729 |     printk("\n"); | 
 | 730 |     } | 
 | 731 | #endif | 
 | 732 |  | 
 | 733 |     status = readb(&pccs->buffer_status); | 
 | 734 |     if (status!= CCS_BUFFER_FREE) | 
 | 735 |     { | 
 | 736 |         printk(KERN_INFO "Download startup params failed.  Status = %d\n", | 
 | 737 |            status); | 
 | 738 |         local->card_status = CARD_DL_PARAM_ERROR; | 
 | 739 |         return; | 
 | 740 |     } | 
 | 741 |     if (local->sparm.b4.a_network_type == ADHOC) | 
 | 742 |         start_net((u_long)local); | 
 | 743 |     else | 
 | 744 |         join_net((u_long)local); | 
 | 745 |  | 
 | 746 |     return; | 
 | 747 | } /* end verify_dl_startup */ | 
 | 748 | /*===========================================================================*/ | 
 | 749 | /* Command card to start a network */ | 
 | 750 | static void start_net(u_long data) | 
 | 751 | { | 
 | 752 |     ray_dev_t *local = (ray_dev_t *)data; | 
 | 753 |     struct ccs __iomem *pccs; | 
 | 754 |     int ccsindex; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 755 |     struct pcmcia_device *link = local->finder; | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 756 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 |         DEBUG(2,"ray_cs start_net - device not present\n"); | 
 | 758 |         return; | 
 | 759 |     } | 
 | 760 |     /* Fill in the CCS fields for the ECF */ | 
 | 761 |     if ((ccsindex = get_free_ccs(local)) < 0) return; | 
 | 762 |     pccs = ccs_base(local) + ccsindex; | 
 | 763 |     writeb(CCS_START_NETWORK, &pccs->cmd); | 
 | 764 |     writeb(0, &pccs->var.start_network.update_param); | 
 | 765 |     /* Interrupt the firmware to process the command */ | 
 | 766 |     if (interrupt_ecf(local, ccsindex)) { | 
 | 767 |         DEBUG(1,"ray start net failed - card not ready for intr\n"); | 
 | 768 |         writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); | 
 | 769 |         return; | 
 | 770 |     } | 
 | 771 |     local->card_status = CARD_DOING_ACQ; | 
 | 772 |     return; | 
 | 773 | } /* end start_net */ | 
 | 774 | /*===========================================================================*/ | 
 | 775 | /* Command card to join a network */ | 
 | 776 | static void join_net(u_long data) | 
 | 777 | { | 
 | 778 |     ray_dev_t *local = (ray_dev_t *)data; | 
 | 779 |  | 
 | 780 |     struct ccs __iomem *pccs; | 
 | 781 |     int ccsindex; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 782 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 |      | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 784 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 |         DEBUG(2,"ray_cs join_net - device not present\n"); | 
 | 786 |         return; | 
 | 787 |     } | 
 | 788 |     /* Fill in the CCS fields for the ECF */ | 
 | 789 |     if ((ccsindex = get_free_ccs(local)) < 0) return; | 
 | 790 |     pccs = ccs_base(local) + ccsindex; | 
 | 791 |     writeb(CCS_JOIN_NETWORK, &pccs->cmd); | 
 | 792 |     writeb(0, &pccs->var.join_network.update_param); | 
 | 793 |     writeb(0, &pccs->var.join_network.net_initiated); | 
 | 794 |     /* Interrupt the firmware to process the command */ | 
 | 795 |     if (interrupt_ecf(local, ccsindex)) { | 
 | 796 |         DEBUG(1,"ray join net failed - card not ready for intr\n"); | 
 | 797 |         writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); | 
 | 798 |         return; | 
 | 799 |     } | 
 | 800 |     local->card_status = CARD_DOING_ACQ; | 
 | 801 |     return; | 
 | 802 | } | 
 | 803 | /*============================================================================ | 
 | 804 |     After a card is removed, ray_release() will unregister the net | 
 | 805 |     device, and release the PCMCIA configuration.  If the device is | 
 | 806 |     still open, this will be postponed until it is closed. | 
 | 807 | =============================================================================*/ | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 808 | static void ray_release(struct pcmcia_device *link) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { | 
 | 810 |     struct net_device *dev = link->priv;  | 
 | 811 |     ray_dev_t *local = dev->priv; | 
 | 812 |     int i; | 
 | 813 |      | 
 | 814 |     DEBUG(1, "ray_release(0x%p)\n", link); | 
 | 815 |  | 
 | 816 |     del_timer(&local->timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 |  | 
 | 818 |     iounmap(local->sram); | 
 | 819 |     iounmap(local->rmem); | 
 | 820 |     iounmap(local->amem); | 
 | 821 |     /* Do bother checking to see if these succeed or not */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 |     i = pcmcia_release_window(local->amem_handle); | 
 | 823 |     if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i); | 
 | 824 |     i = pcmcia_release_window(local->rmem_handle); | 
 | 825 |     if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i); | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 826 |     pcmcia_disable_device(link); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 |  | 
 | 828 |     DEBUG(2,"ray_release ending\n"); | 
 | 829 | } | 
 | 830 |  | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 831 | static int ray_suspend(struct pcmcia_device *link) | 
| Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 832 | { | 
| Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 833 | 	struct net_device *dev = link->priv; | 
 | 834 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 835 | 	if (link->open) | 
| Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 836 | 		netif_device_detach(dev); | 
| Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 837 |  | 
 | 838 | 	return 0; | 
 | 839 | } | 
 | 840 |  | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 841 | static int ray_resume(struct pcmcia_device *link) | 
| Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 842 | { | 
| Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 843 | 	struct net_device *dev = link->priv; | 
 | 844 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 845 | 	if (link->open) { | 
| Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 846 | 		ray_reset(dev); | 
 | 847 | 		netif_device_attach(dev); | 
 | 848 | 	} | 
| Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 849 |  | 
 | 850 | 	return 0; | 
 | 851 | } | 
 | 852 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | /*===========================================================================*/ | 
 | 854 | int ray_dev_init(struct net_device *dev) | 
 | 855 | { | 
 | 856 | #ifdef RAY_IMMEDIATE_INIT | 
 | 857 |     int i; | 
 | 858 | #endif	/* RAY_IMMEDIATE_INIT */ | 
 | 859 |     ray_dev_t *local = dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 860 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 |  | 
 | 862 |     DEBUG(1,"ray_dev_init(dev=%p)\n",dev); | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 863 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 |         DEBUG(2,"ray_dev_init - device not present\n"); | 
 | 865 |         return -1; | 
 | 866 |     } | 
 | 867 | #ifdef RAY_IMMEDIATE_INIT | 
 | 868 |     /* Download startup parameters */ | 
 | 869 |     if ( (i = dl_startup_params(dev)) < 0) | 
 | 870 |     { | 
 | 871 |         printk(KERN_INFO "ray_dev_init dl_startup_params failed - " | 
 | 872 |            "returns 0x%x\n",i); | 
 | 873 |         return -1; | 
 | 874 |     } | 
 | 875 | #else	/* RAY_IMMEDIATE_INIT */ | 
 | 876 |     /* Postpone the card init so that we can still configure the card, | 
 | 877 |      * for example using the Wireless Extensions. The init will happen | 
 | 878 |      * in ray_open() - Jean II */ | 
 | 879 |     DEBUG(1,"ray_dev_init: postponing card init to ray_open() ; Status = %d\n", | 
 | 880 | 	  local->card_status); | 
 | 881 | #endif	/* RAY_IMMEDIATE_INIT */ | 
 | 882 |  | 
 | 883 |     /* copy mac and broadcast addresses to linux device */ | 
 | 884 |     memcpy(&dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN); | 
 | 885 |     memset(dev->broadcast, 0xff, ETH_ALEN); | 
 | 886 |  | 
 | 887 |     DEBUG(2,"ray_dev_init ending\n"); | 
 | 888 |     return 0; | 
 | 889 | } | 
 | 890 | /*===========================================================================*/ | 
 | 891 | static int ray_dev_config(struct net_device *dev, struct ifmap *map) | 
 | 892 | { | 
 | 893 |     ray_dev_t *local = dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 894 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 |     /* Dummy routine to satisfy device structure */ | 
 | 896 |     DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map); | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 897 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 |         DEBUG(2,"ray_dev_config - device not present\n"); | 
 | 899 |         return -1; | 
 | 900 |     } | 
 | 901 |  | 
 | 902 |     return 0; | 
 | 903 | } | 
 | 904 | /*===========================================================================*/ | 
 | 905 | static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev) | 
 | 906 | { | 
 | 907 |     ray_dev_t *local = dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 908 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 |     short length = skb->len; | 
 | 910 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 911 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 |         DEBUG(2,"ray_dev_start_xmit - device not present\n"); | 
 | 913 |         return -1; | 
 | 914 |     } | 
 | 915 |     DEBUG(3,"ray_dev_start_xmit(skb=%p, dev=%p)\n",skb,dev); | 
 | 916 |     if (local->authentication_state == NEED_TO_AUTH) { | 
 | 917 |         DEBUG(0,"ray_cs Sending authentication request.\n"); | 
 | 918 |         if (!build_auth_frame (local, local->auth_id, OPEN_AUTH_REQUEST)) { | 
 | 919 |             local->authentication_state = AUTHENTICATED; | 
 | 920 |             netif_stop_queue(dev); | 
 | 921 |             return 1; | 
 | 922 |         } | 
 | 923 |     } | 
 | 924 |  | 
 | 925 |     if (length < ETH_ZLEN) | 
 | 926 |     { | 
 | 927 |     	skb = skb_padto(skb, ETH_ZLEN); | 
 | 928 |     	if (skb == NULL) | 
 | 929 |     		return 0; | 
 | 930 |     	length = ETH_ZLEN; | 
 | 931 |     } | 
 | 932 |     switch (ray_hw_xmit( skb->data, length, dev, DATA_TYPE)) { | 
 | 933 |         case XMIT_NO_CCS: | 
 | 934 |         case XMIT_NEED_AUTH: | 
 | 935 | 	    netif_stop_queue(dev); | 
 | 936 |             return 1; | 
 | 937 |         case XMIT_NO_INTR: | 
 | 938 |         case XMIT_MSG_BAD: | 
 | 939 |         case XMIT_OK: | 
 | 940 |         default: | 
 | 941 |             dev->trans_start = jiffies; | 
 | 942 |             dev_kfree_skb(skb); | 
 | 943 |             return 0; | 
 | 944 |     } | 
 | 945 |     return 0; | 
 | 946 | } /* ray_dev_start_xmit */ | 
 | 947 | /*===========================================================================*/ | 
 | 948 | static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev,  | 
 | 949 |                 UCHAR msg_type) | 
 | 950 | { | 
 | 951 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 952 |     struct ccs __iomem *pccs; | 
 | 953 |     int ccsindex; | 
 | 954 |     int offset; | 
 | 955 |     struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */ | 
 | 956 |     short int addr;     /* Address of xmit buffer in card space */ | 
 | 957 |      | 
 | 958 |     DEBUG(3,"ray_hw_xmit(data=%p, len=%d, dev=%p)\n",data,len,dev); | 
 | 959 |     if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) | 
 | 960 |     { | 
 | 961 |         printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",len); | 
 | 962 |         return XMIT_MSG_BAD; | 
 | 963 |     } | 
 | 964 | 	switch (ccsindex = get_free_tx_ccs(local)) { | 
 | 965 | 	case ECCSBUSY: | 
 | 966 | 		DEBUG(2,"ray_hw_xmit tx_ccs table busy\n"); | 
 | 967 | 	case ECCSFULL: | 
 | 968 |         DEBUG(2,"ray_hw_xmit No free tx ccs\n"); | 
 | 969 | 	case ECARDGONE: | 
 | 970 | 	netif_stop_queue(dev); | 
 | 971 |         return XMIT_NO_CCS; | 
 | 972 | 	default: | 
 | 973 | 		break; | 
 | 974 | 	} | 
 | 975 |     addr = TX_BUF_BASE + (ccsindex << 11); | 
 | 976 |  | 
 | 977 |     if (msg_type == DATA_TYPE) { | 
 | 978 |         local->stats.tx_bytes += len; | 
 | 979 |         local->stats.tx_packets++; | 
 | 980 |     } | 
 | 981 |  | 
 | 982 |     ptx = local->sram + addr; | 
 | 983 |  | 
 | 984 |     ray_build_header(local, ptx, msg_type, data); | 
 | 985 |     if (translate) { | 
 | 986 |         offset = translate_frame(local, ptx, data, len); | 
 | 987 |     } | 
 | 988 |     else { /* Encapsulate frame */ | 
 | 989 |         /* TBD TIB length will move address of ptx->var */ | 
 | 990 |         memcpy_toio(&ptx->var, data, len); | 
 | 991 |         offset = 0; | 
 | 992 |     } | 
 | 993 |  | 
 | 994 |     /* fill in the CCS */ | 
 | 995 |     pccs = ccs_base(local) + ccsindex; | 
 | 996 |     len += TX_HEADER_LENGTH + offset; | 
 | 997 |     writeb(CCS_TX_REQUEST, &pccs->cmd); | 
 | 998 |     writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]); | 
 | 999 |     writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]); | 
 | 1000 |     writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]); | 
 | 1001 |     writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]); | 
 | 1002 | /* TBD still need psm_cam? */ | 
 | 1003 |     writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode); | 
 | 1004 |     writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate); | 
 | 1005 |     writeb(0, &pccs->var.tx_request.antenna); | 
 | 1006 |     DEBUG(3,"ray_hw_xmit default_tx_rate = 0x%x\n",\ | 
 | 1007 |           local->net_default_tx_rate); | 
 | 1008 |  | 
 | 1009 |     /* Interrupt the firmware to process the command */ | 
 | 1010 |     if (interrupt_ecf(local, ccsindex)) { | 
 | 1011 |         DEBUG(2,"ray_hw_xmit failed - ECF not ready for intr\n"); | 
 | 1012 | /* TBD very inefficient to copy packet to buffer, and then not | 
 | 1013 |    send it, but the alternative is to queue the messages and that | 
 | 1014 |    won't be done for a while.  Maybe set tbusy until a CCS is free? | 
 | 1015 | */ | 
 | 1016 |         writeb(CCS_BUFFER_FREE, &pccs->buffer_status); | 
 | 1017 |         return XMIT_NO_INTR; | 
 | 1018 |     } | 
 | 1019 |     return XMIT_OK; | 
 | 1020 | } /* end ray_hw_xmit */ | 
 | 1021 | /*===========================================================================*/ | 
 | 1022 | static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, unsigned char *data, | 
 | 1023 |                     int len) | 
 | 1024 | { | 
 | 1025 |     unsigned short int proto = ((struct ethhdr *)data)->h_proto; | 
 | 1026 |     if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */ | 
 | 1027 |         DEBUG(3,"ray_cs translate_frame DIX II\n"); | 
 | 1028 |         /* Copy LLC header to card buffer */ | 
 | 1029 |         memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc)); | 
 | 1030 |         memcpy_toio( ((void __iomem *)&ptx->var) + sizeof(eth2_llc), (UCHAR *)&proto, 2); | 
 | 1031 |         if ((proto == 0xf380) || (proto == 0x3781)) { | 
 | 1032 |             /* This is the selective translation table, only 2 entries */ | 
 | 1033 |             writeb(0xf8, &((struct snaphdr_t __iomem *)ptx->var)->org[3]); | 
 | 1034 |         } | 
 | 1035 |         /* Copy body of ethernet packet without ethernet header */ | 
 | 1036 |         memcpy_toio((void __iomem *)&ptx->var + sizeof(struct snaphdr_t), \ | 
 | 1037 |                     data + ETH_HLEN,  len - ETH_HLEN); | 
 | 1038 |         return (int) sizeof(struct snaphdr_t) - ETH_HLEN; | 
 | 1039 |     } | 
 | 1040 |     else { /* already  802 type, and proto is length */ | 
 | 1041 |         DEBUG(3,"ray_cs translate_frame 802\n"); | 
 | 1042 |         if (proto == 0xffff) { /* evil netware IPX 802.3 without LLC */ | 
 | 1043 |         DEBUG(3,"ray_cs translate_frame evil IPX\n"); | 
 | 1044 |             memcpy_toio(&ptx->var, data + ETH_HLEN,  len - ETH_HLEN); | 
 | 1045 |             return 0 - ETH_HLEN; | 
 | 1046 |         } | 
 | 1047 |         memcpy_toio(&ptx->var, data + ETH_HLEN,  len - ETH_HLEN); | 
 | 1048 |         return 0 - ETH_HLEN; | 
 | 1049 |     } | 
 | 1050 |     /* TBD do other frame types */ | 
 | 1051 | } /* end translate_frame */ | 
 | 1052 | /*===========================================================================*/ | 
 | 1053 | static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, UCHAR msg_type, | 
 | 1054 |                 unsigned char *data) | 
 | 1055 | { | 
 | 1056 |     writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1); | 
 | 1057 | /*** IEEE 802.11 Address field assignments ************* | 
 | 1058 |                 TODS FROMDS   addr_1     addr_2          addr_3   addr_4 | 
 | 1059 | Adhoc           0    0        dest       src (terminal)  BSSID    N/A | 
 | 1060 | AP to Terminal  0    1        dest       AP(BSSID)       source   N/A | 
 | 1061 | Terminal to AP  1    0        AP(BSSID)  src (terminal)  dest     N/A | 
 | 1062 | AP to AP        1    1        dest AP    src AP          dest     source       | 
 | 1063 | *******************************************************/ | 
 | 1064 |     if (local->net_type == ADHOC) {    | 
 | 1065 |         writeb(0, &ptx->mac.frame_ctl_2); | 
 | 1066 |         memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, 2 * ADDRLEN); | 
 | 1067 |         memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN); | 
 | 1068 |     } | 
 | 1069 |     else /* infrastructure */ | 
 | 1070 |     { | 
 | 1071 |         if (local->sparm.b4.a_acting_as_ap_status) | 
 | 1072 |         { | 
 | 1073 |             writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2); | 
 | 1074 |             memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, ADDRLEN); | 
 | 1075 |             memcpy_toio(ptx->mac.addr_2, local->bss_id, 6); | 
 | 1076 |             memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_source, ADDRLEN); | 
 | 1077 |         } | 
 | 1078 |         else /* Terminal */ | 
 | 1079 |         { | 
 | 1080 |             writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2); | 
 | 1081 |             memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN); | 
 | 1082 |             memcpy_toio(ptx->mac.addr_2, ((struct ethhdr *)data)->h_source, ADDRLEN); | 
 | 1083 |             memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_dest, ADDRLEN); | 
 | 1084 |         } | 
 | 1085 |     } | 
 | 1086 | } /* end encapsulate_frame */ | 
 | 1087 |  | 
 | 1088 |  | 
 | 1089 | /*===========================================================================*/ | 
 | 1090 |  | 
 | 1091 | static void netdev_get_drvinfo(struct net_device *dev, | 
 | 1092 | 			       struct ethtool_drvinfo *info) | 
 | 1093 | { | 
 | 1094 | 	strcpy(info->driver, "ray_cs"); | 
 | 1095 | } | 
 | 1096 |  | 
 | 1097 | static struct ethtool_ops netdev_ethtool_ops = { | 
 | 1098 | 	.get_drvinfo		= netdev_get_drvinfo, | 
 | 1099 | }; | 
 | 1100 |  | 
 | 1101 | /*====================================================================*/ | 
 | 1102 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1103 | /*------------------------------------------------------------------*/ | 
 | 1104 | /* | 
 | 1105 |  * Wireless Handler : get protocol name | 
 | 1106 |  */ | 
 | 1107 | static int ray_get_name(struct net_device *dev, | 
 | 1108 | 			struct iw_request_info *info, | 
 | 1109 | 			char *cwrq, | 
 | 1110 | 			char *extra) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | { | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1112 | 	strcpy(cwrq, "IEEE 802.11-FH"); | 
 | 1113 | 	return 0; | 
 | 1114 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1116 | /*------------------------------------------------------------------*/ | 
 | 1117 | /* | 
 | 1118 |  * Wireless Handler : set frequency | 
 | 1119 |  */ | 
 | 1120 | static int ray_set_freq(struct net_device *dev, | 
 | 1121 | 			struct iw_request_info *info, | 
 | 1122 | 			struct iw_freq *fwrq, | 
 | 1123 | 			char *extra) | 
 | 1124 | { | 
 | 1125 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1126 | 	int err = -EINPROGRESS;		/* Call commit handler */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1128 | 	/* Reject if card is already initialised */ | 
 | 1129 | 	if(local->card_status != CARD_AWAITING_PARAM) | 
 | 1130 | 		return -EBUSY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1132 | 	/* Setting by channel number */ | 
 | 1133 | 	if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | 		err = -EOPNOTSUPP; | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1135 | 	else | 
 | 1136 | 		local->sparm.b5.a_hop_pattern = fwrq->m; | 
 | 1137 |  | 
 | 1138 | 	return err; | 
 | 1139 | } | 
 | 1140 |   | 
 | 1141 | /*------------------------------------------------------------------*/ | 
 | 1142 | /* | 
 | 1143 |  * Wireless Handler : get frequency | 
 | 1144 |  */ | 
 | 1145 | static int ray_get_freq(struct net_device *dev, | 
 | 1146 | 			struct iw_request_info *info, | 
 | 1147 | 			struct iw_freq *fwrq, | 
 | 1148 | 			char *extra) | 
 | 1149 | { | 
 | 1150 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1151 |  | 
 | 1152 | 	fwrq->m = local->sparm.b5.a_hop_pattern; | 
 | 1153 | 	fwrq->e = 0; | 
 | 1154 | 	return 0; | 
 | 1155 | } | 
 | 1156 |  | 
 | 1157 | /*------------------------------------------------------------------*/ | 
 | 1158 | /* | 
 | 1159 |  * Wireless Handler : set ESSID | 
 | 1160 |  */ | 
 | 1161 | static int ray_set_essid(struct net_device *dev, | 
 | 1162 | 			 struct iw_request_info *info, | 
 | 1163 | 			 struct iw_point *dwrq, | 
 | 1164 | 			 char *extra) | 
 | 1165 | { | 
 | 1166 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1167 |  | 
 | 1168 | 	/* Reject if card is already initialised */ | 
 | 1169 | 	if(local->card_status != CARD_AWAITING_PARAM) | 
 | 1170 | 		return -EBUSY; | 
 | 1171 |  | 
 | 1172 | 	/* Check if we asked for `any' */ | 
 | 1173 | 	if(dwrq->flags == 0) { | 
 | 1174 | 		/* Corey : can you do that ? */ | 
 | 1175 | 		return -EOPNOTSUPP; | 
 | 1176 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | 		/* Check the size of the string */ | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1178 | 		if(dwrq->length > IW_ESSID_MAX_SIZE + 1) { | 
 | 1179 | 			return -E2BIG; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 |  | 
 | 1182 | 		/* Set the ESSID in the card */ | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1183 | 		memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE); | 
 | 1184 | 		memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1187 | 	return -EINPROGRESS;		/* Call commit handler */ | 
 | 1188 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1190 | /*------------------------------------------------------------------*/ | 
 | 1191 | /* | 
 | 1192 |  * Wireless Handler : get ESSID | 
 | 1193 |  */ | 
 | 1194 | static int ray_get_essid(struct net_device *dev, | 
 | 1195 | 			 struct iw_request_info *info, | 
 | 1196 | 			 struct iw_point *dwrq, | 
 | 1197 | 			 char *extra) | 
 | 1198 | { | 
 | 1199 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1201 | 	/* Get the essid that was set */ | 
 | 1202 | 	memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE); | 
 | 1203 | 	extra[IW_ESSID_MAX_SIZE] = '\0'; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1205 | 	/* Push it out ! */ | 
| Dan Williams | d6a13a2 | 2006-01-12 15:00:58 -0500 | [diff] [blame] | 1206 | 	dwrq->length = strlen(extra); | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1207 | 	dwrq->flags = 1; /* active */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1209 | 	return 0; | 
 | 1210 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1212 | /*------------------------------------------------------------------*/ | 
 | 1213 | /* | 
 | 1214 |  * Wireless Handler : get AP address | 
 | 1215 |  */ | 
 | 1216 | static int ray_get_wap(struct net_device *dev, | 
 | 1217 | 			struct iw_request_info *info, | 
 | 1218 | 			struct sockaddr *awrq, | 
 | 1219 | 			char *extra) | 
 | 1220 | { | 
 | 1221 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1222 |  | 
 | 1223 | 	memcpy(awrq->sa_data, local->bss_id, ETH_ALEN); | 
 | 1224 | 	awrq->sa_family = ARPHRD_ETHER; | 
 | 1225 |  | 
 | 1226 | 	return 0; | 
 | 1227 | } | 
 | 1228 |  | 
 | 1229 | /*------------------------------------------------------------------*/ | 
 | 1230 | /* | 
 | 1231 |  * Wireless Handler : set Bit-Rate | 
 | 1232 |  */ | 
 | 1233 | static int ray_set_rate(struct net_device *dev, | 
 | 1234 | 			struct iw_request_info *info, | 
 | 1235 | 			struct iw_param *vwrq, | 
 | 1236 | 			char *extra) | 
 | 1237 | { | 
 | 1238 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1239 |  | 
 | 1240 | 	/* Reject if card is already initialised */ | 
 | 1241 | 	if(local->card_status != CARD_AWAITING_PARAM) | 
 | 1242 | 		return -EBUSY; | 
 | 1243 |  | 
 | 1244 | 	/* Check if rate is in range */ | 
 | 1245 | 	if((vwrq->value != 1000000) && (vwrq->value != 2000000)) | 
 | 1246 | 		return -EINVAL; | 
 | 1247 |  | 
 | 1248 | 	/* Hack for 1.5 Mb/s instead of 2 Mb/s */ | 
 | 1249 | 	if((local->fw_ver == 0x55) &&		/* Please check */ | 
 | 1250 | 	   (vwrq->value == 2000000)) | 
 | 1251 | 		local->net_default_tx_rate = 3; | 
 | 1252 | 	else | 
 | 1253 | 		local->net_default_tx_rate = vwrq->value/500000; | 
 | 1254 |  | 
 | 1255 | 	return 0; | 
 | 1256 | } | 
 | 1257 |  | 
 | 1258 | /*------------------------------------------------------------------*/ | 
 | 1259 | /* | 
 | 1260 |  * Wireless Handler : get Bit-Rate | 
 | 1261 |  */ | 
 | 1262 | static int ray_get_rate(struct net_device *dev, | 
 | 1263 | 			struct iw_request_info *info, | 
 | 1264 | 			struct iw_param *vwrq, | 
 | 1265 | 			char *extra) | 
 | 1266 | { | 
 | 1267 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1268 |  | 
 | 1269 | 	if(local->net_default_tx_rate == 3) | 
 | 1270 | 		vwrq->value = 2000000;		/* Hum... */ | 
 | 1271 | 	else | 
 | 1272 | 		vwrq->value = local->net_default_tx_rate * 500000; | 
 | 1273 | 	vwrq->fixed = 0;		/* We are in auto mode */ | 
 | 1274 |  | 
 | 1275 | 	return 0; | 
 | 1276 | } | 
 | 1277 |  | 
 | 1278 | /*------------------------------------------------------------------*/ | 
 | 1279 | /* | 
 | 1280 |  * Wireless Handler : set RTS threshold | 
 | 1281 |  */ | 
 | 1282 | static int ray_set_rts(struct net_device *dev, | 
 | 1283 | 		       struct iw_request_info *info, | 
 | 1284 | 		       struct iw_param *vwrq, | 
 | 1285 | 		       char *extra) | 
 | 1286 | { | 
 | 1287 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1288 | 	int rthr = vwrq->value; | 
 | 1289 |  | 
 | 1290 | 	/* Reject if card is already initialised */ | 
 | 1291 | 	if(local->card_status != CARD_AWAITING_PARAM) | 
 | 1292 | 		return -EBUSY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 |  | 
 | 1294 | 	/* if(wrq->u.rts.fixed == 0) we should complain */ | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1295 | 	if(vwrq->disabled) | 
 | 1296 | 		rthr = 32767; | 
 | 1297 | 	else { | 
 | 1298 | 		if((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */ | 
 | 1299 | 			return -EINVAL; | 
 | 1300 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | 	local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF; | 
 | 1302 | 	local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1304 | 	return -EINPROGRESS;		/* Call commit handler */ | 
 | 1305 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1308 | /*------------------------------------------------------------------*/ | 
 | 1309 | /* | 
 | 1310 |  * Wireless Handler : get RTS threshold | 
 | 1311 |  */ | 
 | 1312 | static int ray_get_rts(struct net_device *dev, | 
 | 1313 | 		       struct iw_request_info *info, | 
 | 1314 | 		       struct iw_param *vwrq, | 
 | 1315 | 		       char *extra) | 
 | 1316 | { | 
 | 1317 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1318 |  | 
 | 1319 | 	vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8) | 
 | 1320 | 		+ local->sparm.b5.a_rts_threshold[1]; | 
 | 1321 | 	vwrq->disabled = (vwrq->value == 32767); | 
 | 1322 | 	vwrq->fixed = 1; | 
 | 1323 |  | 
 | 1324 | 	return 0; | 
 | 1325 | } | 
 | 1326 |  | 
 | 1327 | /*------------------------------------------------------------------*/ | 
 | 1328 | /* | 
 | 1329 |  * Wireless Handler : set Fragmentation threshold | 
 | 1330 |  */ | 
 | 1331 | static int ray_set_frag(struct net_device *dev, | 
 | 1332 | 			struct iw_request_info *info, | 
 | 1333 | 			struct iw_param *vwrq, | 
 | 1334 | 			char *extra) | 
 | 1335 | { | 
 | 1336 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1337 | 	int fthr = vwrq->value; | 
 | 1338 |  | 
 | 1339 | 	/* Reject if card is already initialised */ | 
 | 1340 | 	if(local->card_status != CARD_AWAITING_PARAM) | 
 | 1341 | 		return -EBUSY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 |  | 
 | 1343 | 	/* if(wrq->u.frag.fixed == 0) should complain */ | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1344 | 	if(vwrq->disabled) | 
 | 1345 | 		fthr = 32767; | 
 | 1346 | 	else { | 
 | 1347 | 		if((fthr < 256) || (fthr > 2347)) /* To check out ! */ | 
 | 1348 | 			return -EINVAL; | 
 | 1349 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | 	local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF; | 
 | 1351 | 	local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1353 | 	return -EINPROGRESS;		/* Call commit handler */ | 
 | 1354 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1356 | /*------------------------------------------------------------------*/ | 
 | 1357 | /* | 
 | 1358 |  * Wireless Handler : get Fragmentation threshold | 
 | 1359 |  */ | 
 | 1360 | static int ray_get_frag(struct net_device *dev, | 
 | 1361 | 			struct iw_request_info *info, | 
 | 1362 | 			struct iw_param *vwrq, | 
 | 1363 | 			char *extra) | 
 | 1364 | { | 
 | 1365 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1367 | 	vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8) | 
 | 1368 | 		+ local->sparm.b5.a_frag_threshold[1]; | 
 | 1369 | 	vwrq->disabled = (vwrq->value == 32767); | 
 | 1370 | 	vwrq->fixed = 1; | 
 | 1371 |  | 
 | 1372 | 	return 0; | 
 | 1373 | } | 
 | 1374 |  | 
 | 1375 | /*------------------------------------------------------------------*/ | 
 | 1376 | /* | 
 | 1377 |  * Wireless Handler : set Mode of Operation | 
 | 1378 |  */ | 
 | 1379 | static int ray_set_mode(struct net_device *dev, | 
 | 1380 | 			struct iw_request_info *info, | 
 | 1381 | 			__u32 *uwrq, | 
 | 1382 | 			char *extra) | 
 | 1383 | { | 
 | 1384 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1385 | 	int err = -EINPROGRESS;		/* Call commit handler */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | 	char card_mode = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1388 | 	/* Reject if card is already initialised */ | 
 | 1389 | 	if(local->card_status != CARD_AWAITING_PARAM) | 
 | 1390 | 		return -EBUSY; | 
 | 1391 |  | 
 | 1392 | 	switch (*uwrq) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | 	{ | 
 | 1394 | 	case IW_MODE_ADHOC: | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1395 | 		card_mode = 0; | 
 | 1396 | 		// Fall through | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | 	case IW_MODE_INFRA: | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1398 | 		local->sparm.b5.a_network_type = card_mode; | 
 | 1399 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | 	default: | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1401 | 		err = -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1404 | 	return err; | 
 | 1405 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1407 | /*------------------------------------------------------------------*/ | 
 | 1408 | /* | 
 | 1409 |  * Wireless Handler : get Mode of Operation | 
 | 1410 |  */ | 
 | 1411 | static int ray_get_mode(struct net_device *dev, | 
 | 1412 | 			struct iw_request_info *info, | 
 | 1413 | 			__u32 *uwrq, | 
 | 1414 | 			char *extra) | 
 | 1415 | { | 
 | 1416 | 	ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1418 | 	if(local->sparm.b5.a_network_type) | 
 | 1419 | 		*uwrq = IW_MODE_INFRA; | 
 | 1420 | 	else | 
 | 1421 | 		*uwrq = IW_MODE_ADHOC; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1423 | 	return 0; | 
 | 1424 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1426 | /*------------------------------------------------------------------*/ | 
 | 1427 | /* | 
 | 1428 |  * Wireless Handler : get range info | 
 | 1429 |  */ | 
 | 1430 | static int ray_get_range(struct net_device *dev, | 
 | 1431 | 			 struct iw_request_info *info, | 
 | 1432 | 			 struct iw_point *dwrq, | 
 | 1433 | 			 char *extra) | 
 | 1434 | { | 
 | 1435 | 	struct iw_range *range = (struct iw_range *) extra; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1437 | 	memset((char *) range, 0, sizeof(struct iw_range)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1439 | 	/* Set the length (very important for backward compatibility) */ | 
 | 1440 | 	dwrq->length = sizeof(struct iw_range); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1442 | 	/* Set the Wireless Extension versions */ | 
 | 1443 | 	range->we_version_compiled = WIRELESS_EXT; | 
 | 1444 | 	range->we_version_source = 9; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1446 | 	/* Set information in the range struct */ | 
 | 1447 | 	range->throughput = 1.1 * 1000 * 1000;	/* Put the right number here */ | 
 | 1448 | 	range->num_channels = hop_pattern_length[(int)country];  | 
 | 1449 | 	range->num_frequency = 0; | 
 | 1450 | 	range->max_qual.qual = 0; | 
 | 1451 | 	range->max_qual.level = 255;	/* What's the correct value ? */ | 
 | 1452 | 	range->max_qual.noise = 255;	/* Idem */ | 
 | 1453 | 	range->num_bitrates = 2; | 
 | 1454 | 	range->bitrate[0] = 1000000;	/* 1 Mb/s */ | 
 | 1455 | 	range->bitrate[1] = 2000000;	/* 2 Mb/s */ | 
 | 1456 | 	return 0; | 
 | 1457 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1459 | /*------------------------------------------------------------------*/ | 
 | 1460 | /* | 
 | 1461 |  * Wireless Private Handler : set framing mode | 
 | 1462 |  */ | 
 | 1463 | static int ray_set_framing(struct net_device *dev, | 
 | 1464 | 			   struct iw_request_info *info, | 
 | 1465 | 			   union iwreq_data *wrqu, | 
 | 1466 | 			   char *extra) | 
 | 1467 | { | 
 | 1468 | 	translate = *(extra);	/* Set framing mode */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1470 | 	return 0; | 
 | 1471 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1473 | /*------------------------------------------------------------------*/ | 
 | 1474 | /* | 
 | 1475 |  * Wireless Private Handler : get framing mode | 
 | 1476 |  */ | 
 | 1477 | static int ray_get_framing(struct net_device *dev, | 
 | 1478 | 			   struct iw_request_info *info, | 
 | 1479 | 			   union iwreq_data *wrqu, | 
 | 1480 | 			   char *extra) | 
 | 1481 | { | 
 | 1482 | 	*(extra) = translate; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1484 | 	return 0; | 
 | 1485 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1487 | /*------------------------------------------------------------------*/ | 
 | 1488 | /* | 
 | 1489 |  * Wireless Private Handler : get country | 
 | 1490 |  */ | 
 | 1491 | static int ray_get_country(struct net_device *dev, | 
 | 1492 | 			   struct iw_request_info *info, | 
 | 1493 | 			   union iwreq_data *wrqu, | 
 | 1494 | 			   char *extra) | 
 | 1495 | { | 
 | 1496 | 	*(extra) = country; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1498 | 	return 0; | 
 | 1499 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1501 | /*------------------------------------------------------------------*/ | 
 | 1502 | /* | 
 | 1503 |  * Commit handler : called after a bunch of SET operations | 
 | 1504 |  */ | 
 | 1505 | static int ray_commit(struct net_device *dev, | 
 | 1506 | 		      struct iw_request_info *info,	/* NULL */ | 
 | 1507 | 		      void *zwrq,			/* NULL */ | 
 | 1508 | 		      char *extra)			/* NULL */ | 
 | 1509 | { | 
 | 1510 | 	return 0; | 
 | 1511 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 |  | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1513 | /*------------------------------------------------------------------*/ | 
 | 1514 | /* | 
 | 1515 |  * Stats handler : return Wireless Stats | 
 | 1516 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | static iw_stats * ray_get_wireless_stats(struct net_device *	dev) | 
 | 1518 | { | 
 | 1519 |   ray_dev_t *	local = (ray_dev_t *) dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1520 |   struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 |   struct status __iomem *p = local->sram + STATUS_BASE; | 
 | 1522 |  | 
 | 1523 |   if(local == (ray_dev_t *) NULL) | 
 | 1524 |     return (iw_stats *) NULL; | 
 | 1525 |  | 
 | 1526 |   local->wstats.status = local->card_status; | 
 | 1527 | #ifdef WIRELESS_SPY | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1528 |   if((local->spy_data.spy_number > 0) && (local->sparm.b5.a_network_type == 0)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 |     { | 
 | 1530 |       /* Get it from the first node in spy list */ | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1531 |       local->wstats.qual.qual = local->spy_data.spy_stat[0].qual; | 
 | 1532 |       local->wstats.qual.level = local->spy_data.spy_stat[0].level; | 
 | 1533 |       local->wstats.qual.noise = local->spy_data.spy_stat[0].noise; | 
 | 1534 |       local->wstats.qual.updated = local->spy_data.spy_stat[0].updated; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 |     } | 
 | 1536 | #endif /* WIRELESS_SPY */ | 
 | 1537 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1538 |   if(pcmcia_dev_present(link)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 |     local->wstats.qual.noise = readb(&p->rxnoise); | 
 | 1540 |     local->wstats.qual.updated |= 4; | 
 | 1541 |   } | 
 | 1542 |  | 
 | 1543 |   return &local->wstats; | 
 | 1544 | } /* end ray_get_wireless_stats */ | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1545 |  | 
 | 1546 | /*------------------------------------------------------------------*/ | 
 | 1547 | /* | 
 | 1548 |  * Structures to export the Wireless Handlers | 
 | 1549 |  */ | 
 | 1550 |  | 
 | 1551 | static const iw_handler	ray_handler[] = { | 
| viro@ZenIV.linux.org.uk | 7a700fa | 2005-09-09 20:40:23 +0100 | [diff] [blame] | 1552 | 	[SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) ray_commit, | 
 | 1553 | 	[SIOCGIWNAME  -SIOCIWFIRST] = (iw_handler) ray_get_name, | 
 | 1554 | 	[SIOCSIWFREQ  -SIOCIWFIRST] = (iw_handler) ray_set_freq, | 
 | 1555 | 	[SIOCGIWFREQ  -SIOCIWFIRST] = (iw_handler) ray_get_freq, | 
 | 1556 | 	[SIOCSIWMODE  -SIOCIWFIRST] = (iw_handler) ray_set_mode, | 
 | 1557 | 	[SIOCGIWMODE  -SIOCIWFIRST] = (iw_handler) ray_get_mode, | 
 | 1558 | 	[SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) ray_get_range, | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1559 | #ifdef WIRELESS_SPY | 
| viro@ZenIV.linux.org.uk | 7a700fa | 2005-09-09 20:40:23 +0100 | [diff] [blame] | 1560 |  	[SIOCSIWSPY   -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy, | 
 | 1561 | 	[SIOCGIWSPY   -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy, | 
 | 1562 | 	[SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy, | 
 | 1563 | 	[SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy, | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1564 | #endif	/* WIRELESS_SPY */ | 
| viro@ZenIV.linux.org.uk | 7a700fa | 2005-09-09 20:40:23 +0100 | [diff] [blame] | 1565 | 	[SIOCGIWAP    -SIOCIWFIRST] = (iw_handler) ray_get_wap, | 
 | 1566 | 	[SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) ray_set_essid, | 
 | 1567 | 	[SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) ray_get_essid, | 
 | 1568 | 	[SIOCSIWRATE  -SIOCIWFIRST] = (iw_handler) ray_set_rate, | 
 | 1569 | 	[SIOCGIWRATE  -SIOCIWFIRST] = (iw_handler) ray_get_rate, | 
 | 1570 | 	[SIOCSIWRTS   -SIOCIWFIRST] = (iw_handler) ray_set_rts, | 
 | 1571 | 	[SIOCGIWRTS   -SIOCIWFIRST] = (iw_handler) ray_get_rts, | 
 | 1572 | 	[SIOCSIWFRAG  -SIOCIWFIRST] = (iw_handler) ray_set_frag, | 
 | 1573 | 	[SIOCGIWFRAG  -SIOCIWFIRST] = (iw_handler) ray_get_frag, | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1574 | }; | 
 | 1575 |  | 
 | 1576 | #define SIOCSIPFRAMING	SIOCIWFIRSTPRIV		/* Set framing mode */ | 
 | 1577 | #define SIOCGIPFRAMING	SIOCIWFIRSTPRIV + 1	/* Get framing mode */ | 
 | 1578 | #define SIOCGIPCOUNTRY	SIOCIWFIRSTPRIV + 3	/* Get country code */ | 
 | 1579 |  | 
 | 1580 | static const iw_handler	ray_private_handler[] = { | 
| viro@ZenIV.linux.org.uk | 7a700fa | 2005-09-09 20:40:23 +0100 | [diff] [blame] | 1581 | 	[0] = (iw_handler) ray_set_framing, | 
 | 1582 | 	[1] = (iw_handler) ray_get_framing, | 
 | 1583 | 	[3] = (iw_handler) ray_get_country, | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1584 | }; | 
 | 1585 |  | 
 | 1586 | static const struct iw_priv_args	ray_private_args[] = { | 
 | 1587 | /* cmd,		set_args,	get_args,	name */ | 
 | 1588 | { SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "set_framing" }, | 
 | 1589 | { SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_framing" }, | 
 | 1590 | { SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_country" }, | 
 | 1591 | }; | 
 | 1592 |  | 
 | 1593 | static const struct iw_handler_def	ray_handler_def = | 
 | 1594 | { | 
 | 1595 | 	.num_standard	= sizeof(ray_handler)/sizeof(iw_handler), | 
 | 1596 | 	.num_private	= sizeof(ray_private_handler)/sizeof(iw_handler), | 
 | 1597 | 	.num_private_args = sizeof(ray_private_args)/sizeof(struct iw_priv_args), | 
 | 1598 | 	.standard	= ray_handler, | 
 | 1599 | 	.private	= ray_private_handler, | 
 | 1600 | 	.private_args	= ray_private_args, | 
 | 1601 | 	.get_wireless_stats = ray_get_wireless_stats, | 
 | 1602 | }; | 
 | 1603 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | /*===========================================================================*/ | 
 | 1605 | static int ray_open(struct net_device *dev) | 
 | 1606 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1608 |     struct pcmcia_device *link; | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 1609 |     link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 |      | 
 | 1611 |     DEBUG(1, "ray_open('%s')\n", dev->name); | 
 | 1612 |  | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 1613 |     if (link->open == 0) | 
 | 1614 | 	    local->num_multi = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 |     link->open++; | 
 | 1616 |  | 
 | 1617 |     /* If the card is not started, time to start it ! - Jean II */ | 
 | 1618 |     if(local->card_status == CARD_AWAITING_PARAM) { | 
 | 1619 | 	int i; | 
 | 1620 |  | 
 | 1621 | 	DEBUG(1,"ray_open: doing init now !\n"); | 
 | 1622 |  | 
 | 1623 | 	/* Download startup parameters */ | 
 | 1624 | 	if ( (i = dl_startup_params(dev)) < 0) | 
 | 1625 | 	  { | 
 | 1626 | 	    printk(KERN_INFO "ray_dev_init dl_startup_params failed - " | 
 | 1627 | 		   "returns 0x%x\n",i); | 
 | 1628 | 	    return -1; | 
 | 1629 | 	  } | 
 | 1630 |      } | 
 | 1631 |  | 
 | 1632 |     if (sniffer) netif_stop_queue(dev); | 
 | 1633 |     else         netif_start_queue(dev); | 
 | 1634 |  | 
 | 1635 |     DEBUG(2,"ray_open ending\n"); | 
 | 1636 |     return 0; | 
 | 1637 | } /* end ray_open */ | 
 | 1638 | /*===========================================================================*/ | 
 | 1639 | static int ray_dev_close(struct net_device *dev) | 
 | 1640 | { | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 1641 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1642 |     struct pcmcia_device *link; | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 1643 |     link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 |  | 
 | 1645 |     DEBUG(1, "ray_dev_close('%s')\n", dev->name); | 
 | 1646 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 |     link->open--; | 
 | 1648 |     netif_stop_queue(dev); | 
 | 1649 |  | 
 | 1650 |     /* In here, we should stop the hardware (stop card from beeing active) | 
 | 1651 |      * and set local->card_status to CARD_AWAITING_PARAM, so that while the | 
 | 1652 |      * card is closed we can chage its configuration. | 
 | 1653 |      * Probably also need a COR reset to get sane state - Jean II */ | 
 | 1654 |  | 
 | 1655 |     return 0; | 
 | 1656 | } /* end ray_dev_close */ | 
 | 1657 | /*===========================================================================*/ | 
 | 1658 | static void ray_reset(struct net_device *dev) { | 
 | 1659 |     DEBUG(1,"ray_reset entered\n"); | 
 | 1660 |     return; | 
 | 1661 | } | 
 | 1662 | /*===========================================================================*/ | 
 | 1663 | /* Cause a firmware interrupt if it is ready for one                         */ | 
 | 1664 | /* Return nonzero if not ready                                               */ | 
 | 1665 | static int interrupt_ecf(ray_dev_t *local, int ccs) | 
 | 1666 | { | 
 | 1667 |     int i = 50; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1668 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1670 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 |         DEBUG(2,"ray_cs interrupt_ecf - device not present\n"); | 
 | 1672 |         return -1; | 
 | 1673 |     } | 
 | 1674 |     DEBUG(2,"interrupt_ecf(local=%p, ccs = 0x%x\n",local,ccs); | 
 | 1675 |  | 
 | 1676 |     while ( i &&  | 
 | 1677 |             (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & ECF_INTR_SET)) | 
 | 1678 |         i--; | 
 | 1679 |     if (i == 0) { | 
 | 1680 |         DEBUG(2,"ray_cs interrupt_ecf card not ready for interrupt\n"); | 
 | 1681 |         return -1; | 
 | 1682 |     } | 
 | 1683 | 	/* Fill the mailbox, then kick the card */ | 
 | 1684 |     writeb(ccs, local->sram + SCB_BASE); | 
 | 1685 |     writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET); | 
 | 1686 |     return 0; | 
 | 1687 | } /* interrupt_ecf */ | 
 | 1688 | /*===========================================================================*/ | 
 | 1689 | /* Get next free transmit CCS                                                */ | 
 | 1690 | /* Return - index of current tx ccs                                          */ | 
 | 1691 | static int get_free_tx_ccs(ray_dev_t *local) | 
 | 1692 | { | 
 | 1693 |     int i; | 
 | 1694 |     struct ccs __iomem *pccs = ccs_base(local); | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1695 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1697 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 |         DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n"); | 
 | 1699 |         return ECARDGONE; | 
 | 1700 |     } | 
 | 1701 |  | 
 | 1702 |     if (test_and_set_bit(0,&local->tx_ccs_lock)) { | 
 | 1703 |         DEBUG(1,"ray_cs tx_ccs_lock busy\n"); | 
 | 1704 |         return ECCSBUSY; | 
 | 1705 |     }  | 
 | 1706 |  | 
 | 1707 |     for (i=0; i < NUMBER_OF_TX_CCS; i++) { | 
 | 1708 |         if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) { | 
 | 1709 |             writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status); | 
 | 1710 |             writeb(CCS_END_LIST, &(pccs+i)->link); | 
 | 1711 | 			local->tx_ccs_lock = 0; | 
 | 1712 |             return i; | 
 | 1713 |         } | 
 | 1714 |     } | 
 | 1715 | 	local->tx_ccs_lock = 0; | 
 | 1716 |     DEBUG(2,"ray_cs ERROR no free tx CCS for raylink card\n"); | 
 | 1717 |     return ECCSFULL; | 
 | 1718 | } /* get_free_tx_ccs */ | 
 | 1719 | /*===========================================================================*/ | 
 | 1720 | /* Get next free CCS                                                         */ | 
 | 1721 | /* Return - index of current ccs                                             */ | 
 | 1722 | static int get_free_ccs(ray_dev_t *local) | 
 | 1723 | { | 
 | 1724 |     int i; | 
 | 1725 |     struct ccs __iomem *pccs = ccs_base(local); | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1726 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1728 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 |         DEBUG(2,"ray_cs get_free_ccs - device not present\n"); | 
 | 1730 |         return ECARDGONE; | 
 | 1731 |     } | 
 | 1732 |     if (test_and_set_bit(0,&local->ccs_lock)) { | 
 | 1733 |         DEBUG(1,"ray_cs ccs_lock busy\n"); | 
 | 1734 |         return ECCSBUSY; | 
 | 1735 |     }  | 
 | 1736 |  | 
 | 1737 |     for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) { | 
 | 1738 |         if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) { | 
 | 1739 |             writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status); | 
 | 1740 |             writeb(CCS_END_LIST, &(pccs+i)->link); | 
 | 1741 | 			local->ccs_lock = 0; | 
 | 1742 |             return i; | 
 | 1743 |         } | 
 | 1744 |     } | 
 | 1745 | 	local->ccs_lock = 0; | 
 | 1746 |     DEBUG(1,"ray_cs ERROR no free CCS for raylink card\n"); | 
 | 1747 |     return ECCSFULL; | 
 | 1748 | } /* get_free_ccs */ | 
 | 1749 | /*===========================================================================*/ | 
 | 1750 | static void authenticate_timeout(u_long data) | 
 | 1751 | { | 
 | 1752 |     ray_dev_t *local = (ray_dev_t *)data; | 
 | 1753 |     del_timer(&local->timer); | 
 | 1754 |     printk(KERN_INFO "ray_cs Authentication with access point failed" | 
 | 1755 |        " - timeout\n"); | 
 | 1756 |     join_net((u_long)local); | 
 | 1757 | } | 
 | 1758 | /*===========================================================================*/ | 
 | 1759 | static int asc_to_int(char a) | 
 | 1760 | { | 
 | 1761 |     if (a < '0') return -1; | 
 | 1762 |     if (a <= '9') return (a - '0'); | 
 | 1763 |     if (a < 'A') return -1; | 
 | 1764 |     if (a <= 'F') return (10 + a - 'A'); | 
 | 1765 |     if (a < 'a') return -1; | 
 | 1766 |     if (a <= 'f') return (10 + a - 'a'); | 
 | 1767 |     return -1; | 
 | 1768 | } | 
 | 1769 | /*===========================================================================*/ | 
 | 1770 | static int parse_addr(char *in_str, UCHAR *out) | 
 | 1771 | { | 
 | 1772 |     int len; | 
 | 1773 |     int i,j,k; | 
 | 1774 |     int status; | 
 | 1775 |      | 
 | 1776 |     if (in_str == NULL) return 0; | 
 | 1777 |     if ((len = strlen(in_str)) < 2) return 0; | 
 | 1778 |     memset(out, 0, ADDRLEN); | 
 | 1779 |  | 
 | 1780 |     status = 1; | 
 | 1781 |     j = len - 1; | 
 | 1782 |     if (j > 12) j = 12; | 
 | 1783 |     i = 5; | 
 | 1784 |      | 
 | 1785 |     while (j > 0) | 
 | 1786 |     { | 
 | 1787 |         if ((k = asc_to_int(in_str[j--])) != -1) out[i] = k; | 
 | 1788 |         else return 0; | 
 | 1789 |  | 
 | 1790 |         if (j == 0) break; | 
 | 1791 |         if ((k = asc_to_int(in_str[j--])) != -1) out[i] += k << 4; | 
 | 1792 |         else return 0; | 
 | 1793 |         if (!i--) break; | 
 | 1794 |     } | 
 | 1795 |     return status; | 
 | 1796 | } | 
 | 1797 | /*===========================================================================*/ | 
 | 1798 | static struct net_device_stats *ray_get_stats(struct net_device *dev) | 
 | 1799 | { | 
 | 1800 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1801 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 |     struct status __iomem *p = local->sram + STATUS_BASE; | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1803 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 |         DEBUG(2,"ray_cs net_device_stats - device not present\n"); | 
 | 1805 |         return &local->stats; | 
 | 1806 |     } | 
 | 1807 |     if (readb(&p->mrx_overflow_for_host)) | 
 | 1808 |     { | 
 | 1809 |         local->stats.rx_over_errors += ntohs(readb(&p->mrx_overflow)); | 
 | 1810 |         writeb(0,&p->mrx_overflow); | 
 | 1811 |         writeb(0,&p->mrx_overflow_for_host); | 
 | 1812 |     } | 
 | 1813 |     if (readb(&p->mrx_checksum_error_for_host)) | 
 | 1814 |     { | 
 | 1815 |         local->stats.rx_crc_errors += ntohs(readb(&p->mrx_checksum_error)); | 
 | 1816 |         writeb(0,&p->mrx_checksum_error); | 
 | 1817 |         writeb(0,&p->mrx_checksum_error_for_host); | 
 | 1818 |     } | 
 | 1819 |     if (readb(&p->rx_hec_error_for_host)) | 
 | 1820 |     { | 
 | 1821 |         local->stats.rx_frame_errors += ntohs(readb(&p->rx_hec_error)); | 
 | 1822 |         writeb(0,&p->rx_hec_error); | 
 | 1823 |         writeb(0,&p->rx_hec_error_for_host); | 
 | 1824 |     } | 
 | 1825 |     return &local->stats; | 
 | 1826 | } | 
 | 1827 | /*===========================================================================*/ | 
 | 1828 | static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len) | 
 | 1829 | { | 
 | 1830 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1831 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 |     int ccsindex; | 
 | 1833 |     int i; | 
 | 1834 |     struct ccs __iomem *pccs; | 
 | 1835 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1836 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 |         DEBUG(2,"ray_update_parm - device not present\n"); | 
 | 1838 |         return; | 
 | 1839 |     } | 
 | 1840 |  | 
 | 1841 |     if ((ccsindex = get_free_ccs(local)) < 0) | 
 | 1842 |     { | 
 | 1843 |         DEBUG(0,"ray_update_parm - No free ccs\n"); | 
 | 1844 |         return; | 
 | 1845 |     } | 
 | 1846 |     pccs = ccs_base(local) + ccsindex; | 
 | 1847 |     writeb(CCS_UPDATE_PARAMS, &pccs->cmd); | 
 | 1848 |     writeb(objid, &pccs->var.update_param.object_id); | 
 | 1849 |     writeb(1, &pccs->var.update_param.number_objects); | 
 | 1850 |     writeb(0, &pccs->var.update_param.failure_cause); | 
 | 1851 |     for (i=0; i<len; i++) { | 
 | 1852 |         writeb(value[i], local->sram + HOST_TO_ECF_BASE); | 
 | 1853 |     } | 
 | 1854 |     /* Interrupt the firmware to process the command */ | 
 | 1855 |     if (interrupt_ecf(local, ccsindex)) { | 
 | 1856 |         DEBUG(0,"ray_cs associate failed - ECF not ready for intr\n"); | 
 | 1857 |         writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); | 
 | 1858 |     } | 
 | 1859 | } | 
 | 1860 | /*===========================================================================*/ | 
 | 1861 | static void ray_update_multi_list(struct net_device *dev, int all) | 
 | 1862 | { | 
 | 1863 |     struct dev_mc_list *dmi, **dmip; | 
 | 1864 |     int ccsindex; | 
 | 1865 |     struct ccs __iomem *pccs; | 
 | 1866 |     int i = 0; | 
 | 1867 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1868 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 |     void __iomem *p = local->sram + HOST_TO_ECF_BASE; | 
 | 1870 |  | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 1871 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 |         DEBUG(2,"ray_update_multi_list - device not present\n"); | 
 | 1873 |         return; | 
 | 1874 |     } | 
 | 1875 |     else  | 
 | 1876 |         DEBUG(2,"ray_update_multi_list(%p)\n",dev); | 
 | 1877 |     if ((ccsindex = get_free_ccs(local)) < 0) | 
 | 1878 |     { | 
 | 1879 |         DEBUG(1,"ray_update_multi - No free ccs\n"); | 
 | 1880 |         return; | 
 | 1881 |     } | 
 | 1882 |     pccs = ccs_base(local) + ccsindex; | 
 | 1883 |     writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd); | 
 | 1884 |  | 
 | 1885 |     if (all) { | 
 | 1886 |         writeb(0xff, &pccs->var); | 
 | 1887 |         local->num_multi = 0xff; | 
 | 1888 |     } | 
 | 1889 |     else { | 
 | 1890 |         /* Copy the kernel's list of MC addresses to card */ | 
 | 1891 |         for (dmip=&dev->mc_list; (dmi=*dmip)!=NULL; dmip=&dmi->next) { | 
 | 1892 |             memcpy_toio(p, dmi->dmi_addr, ETH_ALEN); | 
 | 1893 |             DEBUG(1,"ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",dmi->dmi_addr[0],dmi->dmi_addr[1],dmi->dmi_addr[2],dmi->dmi_addr[3],dmi->dmi_addr[4],dmi->dmi_addr[5]); | 
 | 1894 |             p += ETH_ALEN; | 
 | 1895 |             i++; | 
 | 1896 |         } | 
 | 1897 |         if (i > 256/ADDRLEN) i = 256/ADDRLEN; | 
 | 1898 |         writeb((UCHAR)i, &pccs->var); | 
 | 1899 |         DEBUG(1,"ray_cs update_multi %d addresses in list\n", i); | 
 | 1900 |         /* Interrupt the firmware to process the command */ | 
 | 1901 |         local->num_multi = i; | 
 | 1902 |     } | 
 | 1903 |     if (interrupt_ecf(local, ccsindex)) { | 
 | 1904 |         DEBUG(1,"ray_cs update_multi failed - ECF not ready for intr\n"); | 
 | 1905 |         writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); | 
 | 1906 |     } | 
 | 1907 | } /* end ray_update_multi_list */ | 
 | 1908 | /*===========================================================================*/ | 
 | 1909 | static void set_multicast_list(struct net_device *dev) | 
 | 1910 | { | 
 | 1911 |     ray_dev_t *local = (ray_dev_t *)dev->priv; | 
 | 1912 |     UCHAR promisc; | 
 | 1913 |  | 
 | 1914 |     DEBUG(2,"ray_cs set_multicast_list(%p)\n",dev); | 
 | 1915 |  | 
 | 1916 |     if (dev->flags & IFF_PROMISC) | 
 | 1917 |     { | 
 | 1918 |         if (local->sparm.b5.a_promiscuous_mode == 0) { | 
 | 1919 |             DEBUG(1,"ray_cs set_multicast_list promisc on\n"); | 
 | 1920 |             local->sparm.b5.a_promiscuous_mode = 1; | 
 | 1921 |             promisc = 1; | 
 | 1922 |             ray_update_parm(dev,  OBJID_promiscuous_mode, \ | 
 | 1923 |                             &promisc, sizeof(promisc)); | 
 | 1924 |         } | 
 | 1925 |     } | 
 | 1926 |     else { | 
 | 1927 |         if (local->sparm.b5.a_promiscuous_mode == 1) { | 
 | 1928 |             DEBUG(1,"ray_cs set_multicast_list promisc off\n"); | 
 | 1929 |             local->sparm.b5.a_promiscuous_mode = 0; | 
 | 1930 |             promisc = 0; | 
 | 1931 |             ray_update_parm(dev,  OBJID_promiscuous_mode, \ | 
 | 1932 |                             &promisc, sizeof(promisc)); | 
 | 1933 |         } | 
 | 1934 |     } | 
 | 1935 |  | 
 | 1936 |     if (dev->flags & IFF_ALLMULTI) ray_update_multi_list(dev, 1); | 
 | 1937 |     else | 
 | 1938 |     { | 
 | 1939 |         if (local->num_multi != dev->mc_count) ray_update_multi_list(dev, 0); | 
 | 1940 |     } | 
 | 1941 | } /* end set_multicast_list */ | 
 | 1942 | /*============================================================================= | 
 | 1943 |  * All routines below here are run at interrupt time. | 
 | 1944 | =============================================================================*/ | 
 | 1945 | static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs) | 
 | 1946 | { | 
 | 1947 |     struct net_device *dev = (struct net_device *)dev_id; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1948 |     struct pcmcia_device *link; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 |     ray_dev_t *local; | 
 | 1950 |     struct ccs __iomem *pccs; | 
 | 1951 |     struct rcs __iomem *prcs; | 
 | 1952 |     UCHAR rcsindex; | 
 | 1953 |     UCHAR tmp; | 
 | 1954 |     UCHAR cmd; | 
 | 1955 |     UCHAR status; | 
 | 1956 |  | 
 | 1957 |     if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */ | 
 | 1958 | 	return IRQ_NONE; | 
 | 1959 |  | 
 | 1960 |     DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev); | 
 | 1961 |  | 
 | 1962 |     local = (ray_dev_t *)dev->priv; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 1963 |     link = (struct pcmcia_device *)local->finder; | 
| Dominik Brodowski | 9940ec3 | 2006-03-05 11:04:33 +0100 | [diff] [blame] | 1964 |     if (!pcmcia_dev_present(link)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 |         DEBUG(2,"ray_cs interrupt from device not present or suspended.\n"); | 
 | 1966 |         return IRQ_NONE; | 
 | 1967 |     } | 
 | 1968 |     rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index); | 
 | 1969 |  | 
 | 1970 |     if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) | 
 | 1971 |     { | 
 | 1972 |         DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex); | 
 | 1973 |         clear_interrupt(local); | 
 | 1974 |         return IRQ_HANDLED; | 
 | 1975 |     } | 
 | 1976 |     if (rcsindex < NUMBER_OF_CCS) /* If it's a returned CCS */ | 
 | 1977 |     { | 
 | 1978 |         pccs = ccs_base(local) + rcsindex; | 
 | 1979 |         cmd = readb(&pccs->cmd); | 
 | 1980 |         status = readb(&pccs->buffer_status); | 
 | 1981 |         switch (cmd) | 
 | 1982 |         { | 
 | 1983 |         case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */ | 
 | 1984 |             del_timer(&local->timer); | 
 | 1985 |             if (status == CCS_COMMAND_COMPLETE) { | 
 | 1986 |                 DEBUG(1,"ray_cs interrupt download_startup_parameters OK\n"); | 
 | 1987 |             } | 
 | 1988 |             else { | 
 | 1989 |                 DEBUG(1,"ray_cs interrupt download_startup_parameters fail\n"); | 
 | 1990 |             } | 
 | 1991 |             break; | 
 | 1992 |         case CCS_UPDATE_PARAMS: | 
 | 1993 |             DEBUG(1,"ray_cs interrupt update params done\n"); | 
 | 1994 |             if (status != CCS_COMMAND_COMPLETE) { | 
 | 1995 |                 tmp = readb(&pccs->var.update_param.failure_cause); | 
 | 1996 |             DEBUG(0,"ray_cs interrupt update params failed - reason %d\n",tmp); | 
 | 1997 |             } | 
 | 1998 |             break; | 
 | 1999 |         case CCS_REPORT_PARAMS: | 
 | 2000 |             DEBUG(1,"ray_cs interrupt report params done\n"); | 
 | 2001 |             break; | 
 | 2002 |         case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */ | 
 | 2003 |             DEBUG(1,"ray_cs interrupt CCS Update Multicast List done\n"); | 
 | 2004 |             break; | 
 | 2005 |         case CCS_UPDATE_POWER_SAVINGS_MODE: | 
 | 2006 |             DEBUG(1,"ray_cs interrupt update power save mode done\n"); | 
 | 2007 |             break; | 
 | 2008 |         case CCS_START_NETWORK: | 
 | 2009 |         case CCS_JOIN_NETWORK: | 
 | 2010 |             if (status == CCS_COMMAND_COMPLETE) { | 
 | 2011 |                 if (readb(&pccs->var.start_network.net_initiated) == 1) { | 
 | 2012 |                     DEBUG(0,"ray_cs interrupt network \"%s\" started\n",\ | 
 | 2013 |                           local->sparm.b4.a_current_ess_id); | 
 | 2014 |                 } | 
 | 2015 |                 else { | 
 | 2016 |                     DEBUG(0,"ray_cs interrupt network \"%s\" joined\n",\ | 
 | 2017 |                           local->sparm.b4.a_current_ess_id); | 
 | 2018 |                 } | 
 | 2019 |                 memcpy_fromio(&local->bss_id,pccs->var.start_network.bssid,ADDRLEN); | 
 | 2020 |  | 
 | 2021 |                 if (local->fw_ver == 0x55) local->net_default_tx_rate = 3; | 
 | 2022 |                 else local->net_default_tx_rate =  | 
 | 2023 |                          readb(&pccs->var.start_network.net_default_tx_rate); | 
 | 2024 |                 local->encryption = readb(&pccs->var.start_network.encryption); | 
 | 2025 |                 if (!sniffer && (local->net_type == INFRA) | 
 | 2026 |                     && !(local->sparm.b4.a_acting_as_ap_status)) { | 
 | 2027 |                     authenticate(local); | 
 | 2028 |                 } | 
 | 2029 |                 local->card_status = CARD_ACQ_COMPLETE; | 
 | 2030 |             } | 
 | 2031 |             else { | 
 | 2032 |                 local->card_status = CARD_ACQ_FAILED; | 
 | 2033 |  | 
 | 2034 |                 del_timer(&local->timer); | 
 | 2035 |                 local->timer.expires = jiffies + HZ*5; | 
 | 2036 |                 local->timer.data = (long)local; | 
 | 2037 |                 if (status == CCS_START_NETWORK) { | 
 | 2038 |                     DEBUG(0,"ray_cs interrupt network \"%s\" start failed\n",\ | 
 | 2039 |                           local->sparm.b4.a_current_ess_id); | 
 | 2040 |                     local->timer.function = &start_net; | 
 | 2041 |                 } | 
 | 2042 |                 else { | 
 | 2043 |                     DEBUG(0,"ray_cs interrupt network \"%s\" join failed\n",\ | 
 | 2044 |                           local->sparm.b4.a_current_ess_id); | 
 | 2045 |                     local->timer.function = &join_net; | 
 | 2046 |                 } | 
 | 2047 |                 add_timer(&local->timer); | 
 | 2048 |             } | 
 | 2049 |             break; | 
 | 2050 |         case CCS_START_ASSOCIATION: | 
 | 2051 |             if (status == CCS_COMMAND_COMPLETE) { | 
 | 2052 |                 local->card_status = CARD_ASSOC_COMPLETE; | 
 | 2053 |                 DEBUG(0,"ray_cs association successful\n"); | 
 | 2054 |             } | 
 | 2055 |             else | 
 | 2056 |             { | 
 | 2057 |                 DEBUG(0,"ray_cs association failed,\n"); | 
 | 2058 |                 local->card_status = CARD_ASSOC_FAILED; | 
 | 2059 |                 join_net((u_long)local); | 
 | 2060 |             } | 
 | 2061 |             break; | 
 | 2062 |         case CCS_TX_REQUEST: | 
 | 2063 |             if (status == CCS_COMMAND_COMPLETE) { | 
 | 2064 |                 DEBUG(3,"ray_cs interrupt tx request complete\n"); | 
 | 2065 |             } | 
 | 2066 |             else { | 
 | 2067 |                 DEBUG(1,"ray_cs interrupt tx request failed\n"); | 
 | 2068 |             } | 
 | 2069 |             if (!sniffer) netif_start_queue(dev); | 
 | 2070 |             netif_wake_queue(dev); | 
 | 2071 |             break; | 
 | 2072 |         case CCS_TEST_MEMORY: | 
 | 2073 |             DEBUG(1,"ray_cs interrupt mem test done\n"); | 
 | 2074 |             break; | 
 | 2075 |         case CCS_SHUTDOWN: | 
 | 2076 |             DEBUG(1,"ray_cs interrupt Unexpected CCS returned - Shutdown\n"); | 
 | 2077 |             break; | 
 | 2078 |         case CCS_DUMP_MEMORY: | 
 | 2079 |             DEBUG(1,"ray_cs interrupt dump memory done\n"); | 
 | 2080 |             break; | 
 | 2081 |         case CCS_START_TIMER: | 
 | 2082 |             DEBUG(2,"ray_cs interrupt DING - raylink timer expired\n"); | 
 | 2083 |             break; | 
 | 2084 |         default: | 
 | 2085 |             DEBUG(1,"ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",\ | 
 | 2086 |                   rcsindex, cmd); | 
 | 2087 |         } | 
 | 2088 |         writeb(CCS_BUFFER_FREE, &pccs->buffer_status); | 
 | 2089 |     } | 
 | 2090 |     else /* It's an RCS */ | 
 | 2091 |     { | 
 | 2092 |         prcs = rcs_base(local) + rcsindex; | 
 | 2093 |      | 
 | 2094 |         switch (readb(&prcs->interrupt_id)) | 
 | 2095 |         { | 
 | 2096 |         case PROCESS_RX_PACKET: | 
 | 2097 |             ray_rx(dev, local, prcs); | 
 | 2098 |             break; | 
 | 2099 |         case REJOIN_NET_COMPLETE: | 
 | 2100 |             DEBUG(1,"ray_cs interrupt rejoin net complete\n"); | 
 | 2101 |             local->card_status = CARD_ACQ_COMPLETE; | 
 | 2102 |             /* do we need to clear tx buffers CCS's? */ | 
 | 2103 |             if (local->sparm.b4.a_network_type == ADHOC) { | 
 | 2104 |                 if (!sniffer) netif_start_queue(dev); | 
 | 2105 |             } | 
 | 2106 |             else { | 
 | 2107 |                 memcpy_fromio(&local->bss_id, prcs->var.rejoin_net_complete.bssid, ADDRLEN); | 
 | 2108 |                 DEBUG(1,"ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",\ | 
 | 2109 |                       local->bss_id[0], local->bss_id[1], local->bss_id[2],\ | 
 | 2110 |                       local->bss_id[3], local->bss_id[4], local->bss_id[5]); | 
 | 2111 |                 if (!sniffer) authenticate(local); | 
 | 2112 |             } | 
 | 2113 |             break; | 
 | 2114 |         case ROAMING_INITIATED: | 
 | 2115 |             DEBUG(1,"ray_cs interrupt roaming initiated\n");  | 
 | 2116 |             netif_stop_queue(dev); | 
 | 2117 |             local->card_status = CARD_DOING_ACQ; | 
 | 2118 |             break; | 
 | 2119 |         case JAPAN_CALL_SIGN_RXD: | 
 | 2120 |             DEBUG(1,"ray_cs interrupt japan call sign rx\n"); | 
 | 2121 |             break; | 
 | 2122 |         default: | 
 | 2123 |             DEBUG(1,"ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",\ | 
 | 2124 |                   rcsindex, (unsigned int) readb(&prcs->interrupt_id)); | 
 | 2125 |             break; | 
 | 2126 |         } | 
 | 2127 |         writeb(CCS_BUFFER_FREE, &prcs->buffer_status); | 
 | 2128 |     } | 
 | 2129 |     clear_interrupt(local); | 
 | 2130 |     return IRQ_HANDLED; | 
 | 2131 | } /* ray_interrupt */ | 
 | 2132 | /*===========================================================================*/ | 
 | 2133 | static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs) | 
 | 2134 | { | 
 | 2135 |     int rx_len; | 
 | 2136 |     unsigned int pkt_addr; | 
 | 2137 |     void __iomem *pmsg; | 
 | 2138 |     DEBUG(4,"ray_rx process rx packet\n"); | 
 | 2139 |  | 
 | 2140 |     /* Calculate address of packet within Rx buffer */ | 
 | 2141 |     pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8) | 
 | 2142 |                 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END; | 
 | 2143 |     /* Length of first packet fragment */ | 
 | 2144 |     rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8) | 
 | 2145 |         + readb(&prcs->var.rx_packet.rx_data_length[1]); | 
 | 2146 |  | 
 | 2147 |     local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev); | 
 | 2148 |     pmsg = local->rmem + pkt_addr; | 
 | 2149 |     switch(readb(pmsg)) | 
 | 2150 |     { | 
 | 2151 |     case DATA_TYPE: | 
 | 2152 |         DEBUG(4,"ray_rx data type\n"); | 
 | 2153 |         rx_data(dev, prcs, pkt_addr, rx_len); | 
 | 2154 |         break; | 
 | 2155 |     case AUTHENTIC_TYPE: | 
 | 2156 |         DEBUG(4,"ray_rx authentic type\n"); | 
 | 2157 |         if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len); | 
 | 2158 |         else rx_authenticate(local, prcs, pkt_addr, rx_len); | 
 | 2159 |         break; | 
 | 2160 |     case DEAUTHENTIC_TYPE: | 
 | 2161 |         DEBUG(4,"ray_rx deauth type\n"); | 
 | 2162 |         if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len); | 
 | 2163 |         else rx_deauthenticate(local, prcs, pkt_addr, rx_len); | 
 | 2164 |         break; | 
 | 2165 |     case NULL_MSG_TYPE: | 
 | 2166 |         DEBUG(3,"ray_cs rx NULL msg\n"); | 
 | 2167 |         break; | 
 | 2168 |     case BEACON_TYPE: | 
 | 2169 |         DEBUG(4,"ray_rx beacon type\n"); | 
 | 2170 |         if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len); | 
 | 2171 |  | 
 | 2172 |         copy_from_rx_buff(local, (UCHAR *)&local->last_bcn, pkt_addr,  | 
 | 2173 |                           rx_len < sizeof(struct beacon_rx) ?  | 
 | 2174 |                           rx_len : sizeof(struct beacon_rx)); | 
 | 2175 |  | 
 | 2176 | 	local->beacon_rxed = 1; | 
 | 2177 |         /* Get the statistics so the card counters never overflow */ | 
 | 2178 |         ray_get_stats(dev); | 
 | 2179 |             break; | 
 | 2180 |     default: | 
 | 2181 |         DEBUG(0,"ray_cs unknown pkt type %2x\n", (unsigned int) readb(pmsg)); | 
 | 2182 |         break; | 
 | 2183 |     } | 
 | 2184 |  | 
 | 2185 | } /* end ray_rx */ | 
 | 2186 | /*===========================================================================*/ | 
 | 2187 | static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, unsigned int pkt_addr,  | 
 | 2188 |              int rx_len) | 
 | 2189 | { | 
 | 2190 |     struct sk_buff *skb = NULL; | 
 | 2191 |     struct rcs __iomem *prcslink = prcs; | 
 | 2192 |     ray_dev_t *local = dev->priv; | 
 | 2193 |     UCHAR *rx_ptr; | 
 | 2194 |     int total_len; | 
 | 2195 |     int tmp; | 
 | 2196 | #ifdef WIRELESS_SPY | 
 | 2197 |     int siglev = local->last_rsl; | 
 | 2198 |     u_char linksrcaddr[ETH_ALEN];	/* Other end of the wireless link */ | 
 | 2199 | #endif | 
 | 2200 |  | 
 | 2201 |     if (!sniffer) { | 
 | 2202 |         if (translate) { | 
 | 2203 | /* TBD length needs fixing for translated header */ | 
 | 2204 |             if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) || | 
 | 2205 |                 rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))  | 
 | 2206 |             { | 
 | 2207 |                 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len); | 
 | 2208 |                 return; | 
 | 2209 |             } | 
 | 2210 |         } | 
 | 2211 |         else /* encapsulated ethernet */ { | 
 | 2212 |             if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) || | 
 | 2213 |                 rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN)) | 
 | 2214 |             { | 
 | 2215 |                 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len); | 
 | 2216 |                 return; | 
 | 2217 |             } | 
 | 2218 |         } | 
 | 2219 |     } | 
 | 2220 |     DEBUG(4,"ray_cs rx_data packet\n"); | 
 | 2221 |     /* If fragmented packet, verify sizes of fragments add up */ | 
 | 2222 |     if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) { | 
 | 2223 |         DEBUG(1,"ray_cs rx'ed fragment\n"); | 
 | 2224 |         tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8) | 
 | 2225 |             +  readb(&prcs->var.rx_packet.totalpacketlength[1]); | 
 | 2226 |         total_len = tmp; | 
 | 2227 |         prcslink = prcs; | 
 | 2228 |         do { | 
 | 2229 |             tmp -= (readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8) | 
 | 2230 |                 +   readb(&prcslink->var.rx_packet.rx_data_length[1]); | 
 | 2231 |             if (readb(&prcslink->var.rx_packet.next_frag_rcs_index) == 0xFF | 
 | 2232 |                 || tmp < 0) break; | 
 | 2233 |             prcslink = rcs_base(local) | 
 | 2234 |                 + readb(&prcslink->link_field); | 
 | 2235 |         } while (1); | 
 | 2236 |  | 
 | 2237 |         if (tmp < 0) | 
 | 2238 |         { | 
 | 2239 |             DEBUG(0,"ray_cs rx_data fragment lengths don't add up\n"); | 
 | 2240 |             local->stats.rx_dropped++;  | 
 | 2241 |             release_frag_chain(local, prcs); | 
 | 2242 |             return; | 
 | 2243 |         } | 
 | 2244 |     } | 
 | 2245 |     else { /* Single unfragmented packet */ | 
 | 2246 |         total_len = rx_len; | 
 | 2247 |     } | 
 | 2248 |  | 
 | 2249 |     skb = dev_alloc_skb( total_len+5 ); | 
 | 2250 |     if (skb == NULL) | 
 | 2251 |     { | 
 | 2252 |         DEBUG(0,"ray_cs rx_data could not allocate skb\n"); | 
 | 2253 |         local->stats.rx_dropped++;  | 
 | 2254 |         if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) | 
 | 2255 |             release_frag_chain(local, prcs); | 
 | 2256 |         return; | 
 | 2257 |     } | 
 | 2258 |     skb_reserve( skb, 2);   /* Align IP on 16 byte (TBD check this)*/ | 
 | 2259 |     skb->dev = dev; | 
 | 2260 |  | 
 | 2261 |     DEBUG(4,"ray_cs rx_data total_len = %x, rx_len = %x\n",total_len,rx_len); | 
 | 2262 |  | 
 | 2263 | /************************/ | 
 | 2264 |     /* Reserve enough room for the whole damn packet. */ | 
 | 2265 |     rx_ptr = skb_put( skb, total_len); | 
 | 2266 |     /* Copy the whole packet to sk_buff */ | 
 | 2267 |     rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len); | 
 | 2268 |     /* Get source address */ | 
 | 2269 | #ifdef WIRELESS_SPY | 
 | 2270 |     memcpy(linksrcaddr, ((struct mac_header *)skb->data)->addr_2, ETH_ALEN); | 
 | 2271 | #endif | 
 | 2272 |     /* Now, deal with encapsulation/translation/sniffer */ | 
 | 2273 |     if (!sniffer) { | 
 | 2274 |         if (!translate) {  | 
 | 2275 |             /* Encapsulated ethernet, so just lop off 802.11 MAC header */ | 
 | 2276 | /* TBD reserve            skb_reserve( skb, RX_MAC_HEADER_LENGTH); */ | 
 | 2277 |             skb_pull( skb, RX_MAC_HEADER_LENGTH); | 
 | 2278 |         } | 
 | 2279 |         else { | 
 | 2280 |             /* Do translation */ | 
 | 2281 |             untranslate(local, skb, total_len); | 
 | 2282 |         } | 
 | 2283 |     } | 
 | 2284 |     else  | 
 | 2285 |     {  /* sniffer mode, so just pass whole packet */  }; | 
 | 2286 |  | 
 | 2287 | /************************/ | 
 | 2288 |     /* Now pick up the rest of the fragments if any */ | 
 | 2289 |     tmp = 17;  | 
 | 2290 |     if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) { | 
 | 2291 |         prcslink = prcs; | 
 | 2292 |         DEBUG(1,"ray_cs rx_data in fragment loop\n"); | 
 | 2293 |         do { | 
 | 2294 |             prcslink = rcs_base(local) | 
 | 2295 |                 + readb(&prcslink->var.rx_packet.next_frag_rcs_index); | 
 | 2296 |             rx_len = (( readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8) | 
 | 2297 |                       + readb(&prcslink->var.rx_packet.rx_data_length[1])) | 
 | 2298 |                 & RX_BUFF_END; | 
 | 2299 |             pkt_addr = (( readb(&prcslink->var.rx_packet.rx_data_ptr[0]) << 8) | 
 | 2300 |                         + readb(&prcslink->var.rx_packet.rx_data_ptr[1])) | 
 | 2301 |                 & RX_BUFF_END; | 
 | 2302 |  | 
 | 2303 |             rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len); | 
 | 2304 |  | 
 | 2305 |         } while (tmp-- &&  | 
 | 2306 |                  readb(&prcslink->var.rx_packet.next_frag_rcs_index) != 0xFF); | 
 | 2307 |         release_frag_chain(local, prcs); | 
 | 2308 |     } | 
 | 2309 |  | 
 | 2310 |     skb->protocol = eth_type_trans(skb,dev); | 
 | 2311 |     netif_rx(skb); | 
 | 2312 |     dev->last_rx = jiffies; | 
 | 2313 |     local->stats.rx_packets++; | 
 | 2314 |     local->stats.rx_bytes += total_len; | 
 | 2315 |  | 
 | 2316 |     /* Gather signal strength per address */ | 
 | 2317 | #ifdef WIRELESS_SPY | 
 | 2318 |     /* For the Access Point or the node having started the ad-hoc net | 
 | 2319 |      * note : ad-hoc work only in some specific configurations, but we | 
 | 2320 |      * kludge in ray_get_wireless_stats... */ | 
 | 2321 |     if(!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) | 
 | 2322 |       { | 
 | 2323 | 	/* Update statistics */ | 
 | 2324 | 	/*local->wstats.qual.qual = none ? */ | 
 | 2325 | 	local->wstats.qual.level = siglev; | 
 | 2326 | 	/*local->wstats.qual.noise = none ? */ | 
 | 2327 | 	local->wstats.qual.updated = 0x2; | 
 | 2328 |       } | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 2329 |     /* Now, update the spy stuff */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 |     { | 
| Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 2331 | 	struct iw_quality wstats; | 
 | 2332 | 	wstats.level = siglev; | 
 | 2333 | 	/* wstats.noise = none ? */ | 
 | 2334 | 	/* wstats.qual = none ? */ | 
 | 2335 | 	wstats.updated = 0x2; | 
 | 2336 | 	/* Update spy records */ | 
 | 2337 | 	wireless_spy_update(dev, linksrcaddr, &wstats); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 |     } | 
 | 2339 | #endif	/* WIRELESS_SPY */ | 
 | 2340 | } /* end rx_data */ | 
 | 2341 | /*===========================================================================*/ | 
 | 2342 | static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len) | 
 | 2343 | { | 
 | 2344 |     snaphdr_t *psnap = (snaphdr_t *)(skb->data + RX_MAC_HEADER_LENGTH); | 
 | 2345 |     struct mac_header *pmac = (struct mac_header *)skb->data; | 
 | 2346 |     unsigned short type = *(unsigned short *)psnap->ethertype; | 
 | 2347 |     unsigned int xsap = *(unsigned int *)psnap & 0x00ffffff; | 
 | 2348 |     unsigned int org = (*(unsigned int *)psnap->org) & 0x00ffffff; | 
 | 2349 |     int delta; | 
 | 2350 |     struct ethhdr *peth; | 
 | 2351 |     UCHAR srcaddr[ADDRLEN]; | 
 | 2352 |     UCHAR destaddr[ADDRLEN]; | 
 | 2353 |  | 
 | 2354 |     if (pmac->frame_ctl_2 & FC2_FROM_DS) { | 
 | 2355 | 	if (pmac->frame_ctl_2 & FC2_TO_DS) { /* AP to AP */ | 
 | 2356 | 	    memcpy(destaddr, pmac->addr_3, ADDRLEN); | 
 | 2357 | 	    memcpy(srcaddr, ((unsigned char *)pmac->addr_3) + ADDRLEN, ADDRLEN); | 
 | 2358 | 	} else { /* AP to terminal */ | 
 | 2359 | 	    memcpy(destaddr, pmac->addr_1, ADDRLEN); | 
 | 2360 | 	    memcpy(srcaddr, pmac->addr_3, ADDRLEN);  | 
 | 2361 | 	} | 
 | 2362 |     } else { /* Terminal to AP */ | 
 | 2363 | 	if (pmac->frame_ctl_2 & FC2_TO_DS) { | 
 | 2364 | 	    memcpy(destaddr, pmac->addr_3, ADDRLEN); | 
 | 2365 | 	    memcpy(srcaddr, pmac->addr_2, ADDRLEN);  | 
 | 2366 | 	} else { /* Adhoc */ | 
 | 2367 | 	    memcpy(destaddr, pmac->addr_1, ADDRLEN); | 
 | 2368 | 	    memcpy(srcaddr, pmac->addr_2, ADDRLEN);  | 
 | 2369 | 	} | 
 | 2370 |     } | 
 | 2371 |  | 
 | 2372 | #ifdef PCMCIA_DEBUG | 
 | 2373 |     if (pc_debug > 3) { | 
 | 2374 |     int i; | 
 | 2375 |     printk(KERN_DEBUG "skb->data before untranslate"); | 
 | 2376 |     for (i=0;i<64;i++)  | 
 | 2377 |         printk("%02x ",skb->data[i]); | 
 | 2378 |     printk("\n" KERN_DEBUG "type = %08x, xsap = %08x, org = %08x\n", | 
 | 2379 |            type,xsap,org); | 
 | 2380 |     printk(KERN_DEBUG "untranslate skb->data = %p\n",skb->data); | 
 | 2381 |     } | 
 | 2382 | #endif | 
 | 2383 |  | 
 | 2384 |     if ( xsap != SNAP_ID) { | 
 | 2385 |         /* not a snap type so leave it alone */ | 
 | 2386 |         DEBUG(3,"ray_cs untranslate NOT SNAP %x\n", *(unsigned int *)psnap & 0x00ffffff); | 
 | 2387 |  | 
 | 2388 |         delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; | 
 | 2389 |         peth = (struct ethhdr *)(skb->data + delta); | 
 | 2390 |         peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH); | 
 | 2391 |     } | 
 | 2392 |     else { /* Its a SNAP */ | 
 | 2393 |         if (org == BRIDGE_ENCAP) { /* EtherII and nuke the LLC  */ | 
 | 2394 |         DEBUG(3,"ray_cs untranslate Bridge encap\n"); | 
 | 2395 |             delta = RX_MAC_HEADER_LENGTH  | 
 | 2396 |                 + sizeof(struct snaphdr_t) - ETH_HLEN; | 
 | 2397 |             peth = (struct ethhdr *)(skb->data + delta); | 
 | 2398 |             peth->h_proto = type; | 
 | 2399 |         } | 
 | 2400 |         else { | 
 | 2401 |             if (org == RFC1042_ENCAP) { | 
 | 2402 |                 switch (type) { | 
 | 2403 |                 case RAY_IPX_TYPE: | 
 | 2404 |                 case APPLEARP_TYPE: | 
 | 2405 |                     DEBUG(3,"ray_cs untranslate RFC IPX/AARP\n"); | 
 | 2406 |                     delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; | 
 | 2407 |                     peth = (struct ethhdr *)(skb->data + delta); | 
 | 2408 |                     peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH); | 
 | 2409 |                     break; | 
 | 2410 |                 default: | 
 | 2411 |                     DEBUG(3,"ray_cs untranslate RFC default\n"); | 
 | 2412 |                     delta = RX_MAC_HEADER_LENGTH +  | 
 | 2413 |                         sizeof(struct snaphdr_t) - ETH_HLEN; | 
 | 2414 |                     peth = (struct ethhdr *)(skb->data + delta); | 
 | 2415 |                     peth->h_proto = type; | 
 | 2416 |                     break; | 
 | 2417 |                 } | 
 | 2418 |             } | 
 | 2419 |             else { | 
 | 2420 |                 printk("ray_cs untranslate very confused by packet\n"); | 
 | 2421 |                 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; | 
 | 2422 |                 peth = (struct ethhdr *)(skb->data + delta); | 
 | 2423 |                 peth->h_proto = type; | 
 | 2424 |             } | 
 | 2425 |         } | 
 | 2426 |     } | 
 | 2427 | /* TBD reserve  skb_reserve(skb, delta); */ | 
 | 2428 |     skb_pull(skb, delta); | 
 | 2429 |     DEBUG(3,"untranslate after skb_pull(%d), skb->data = %p\n",delta,skb->data); | 
 | 2430 |     memcpy(peth->h_dest, destaddr, ADDRLEN); | 
 | 2431 |     memcpy(peth->h_source, srcaddr, ADDRLEN); | 
 | 2432 | #ifdef PCMCIA_DEBUG | 
 | 2433 |     if (pc_debug > 3) { | 
 | 2434 |     int i; | 
 | 2435 |     printk(KERN_DEBUG "skb->data after untranslate:"); | 
 | 2436 |     for (i=0;i<64;i++) | 
 | 2437 |         printk("%02x ",skb->data[i]); | 
 | 2438 |     printk("\n"); | 
 | 2439 |     } | 
 | 2440 | #endif | 
 | 2441 | } /* end untranslate */ | 
 | 2442 | /*===========================================================================*/ | 
 | 2443 | /* Copy data from circular receive buffer to PC memory. | 
 | 2444 |  * dest     = destination address in PC memory | 
 | 2445 |  * pkt_addr = source address in receive buffer | 
 | 2446 |  * len      = length of packet to copy | 
 | 2447 |  */ | 
 | 2448 | static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int length) | 
 | 2449 | { | 
 | 2450 |     int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1); | 
 | 2451 |     if (wrap_bytes <= 0) | 
 | 2452 |     { | 
 | 2453 |         memcpy_fromio(dest,local->rmem + pkt_addr,length); | 
 | 2454 |     } | 
 | 2455 |     else /* Packet wrapped in circular buffer */ | 
 | 2456 |     { | 
 | 2457 |         memcpy_fromio(dest,local->rmem+pkt_addr,length - wrap_bytes); | 
 | 2458 |         memcpy_fromio(dest + length - wrap_bytes, local->rmem, wrap_bytes); | 
 | 2459 |     } | 
 | 2460 |     return length; | 
 | 2461 | } | 
 | 2462 | /*===========================================================================*/ | 
 | 2463 | static void release_frag_chain(ray_dev_t *local, struct rcs __iomem * prcs) | 
 | 2464 | { | 
 | 2465 |     struct rcs __iomem *prcslink = prcs; | 
 | 2466 |     int tmp = 17; | 
 | 2467 |     unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index); | 
 | 2468 |  | 
 | 2469 |     while (tmp--) { | 
 | 2470 |         writeb(CCS_BUFFER_FREE, &prcslink->buffer_status); | 
 | 2471 |         if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) { | 
 | 2472 |             DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex); | 
 | 2473 |             break;       | 
 | 2474 |         }    | 
 | 2475 |         prcslink = rcs_base(local) + rcsindex; | 
 | 2476 |         rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index); | 
 | 2477 |     } | 
 | 2478 |     writeb(CCS_BUFFER_FREE, &prcslink->buffer_status); | 
 | 2479 | } | 
 | 2480 | /*===========================================================================*/ | 
 | 2481 | static void authenticate(ray_dev_t *local) | 
 | 2482 | { | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 2483 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 |     DEBUG(0,"ray_cs Starting authentication.\n"); | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 2485 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 |         DEBUG(2,"ray_cs authenticate - device not present\n"); | 
 | 2487 |         return; | 
 | 2488 |     } | 
 | 2489 |  | 
 | 2490 |     del_timer(&local->timer); | 
 | 2491 |     if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) { | 
 | 2492 |         local->timer.function = &join_net; | 
 | 2493 |     } | 
 | 2494 |     else { | 
 | 2495 |         local->timer.function = &authenticate_timeout; | 
 | 2496 |     } | 
 | 2497 |     local->timer.expires = jiffies + HZ*2; | 
 | 2498 |     local->timer.data = (long)local; | 
 | 2499 |     add_timer(&local->timer); | 
 | 2500 |     local->authentication_state = AWAITING_RESPONSE; | 
 | 2501 | } /* end authenticate */ | 
 | 2502 | /*===========================================================================*/ | 
 | 2503 | static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs, | 
 | 2504 |                      unsigned int pkt_addr, int rx_len) | 
 | 2505 | { | 
 | 2506 |     UCHAR buff[256]; | 
 | 2507 |     struct rx_msg *msg = (struct rx_msg *)buff; | 
 | 2508 |      | 
 | 2509 |     del_timer(&local->timer); | 
 | 2510 |  | 
 | 2511 |     copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff); | 
 | 2512 |     /* if we are trying to get authenticated */ | 
 | 2513 |     if (local->sparm.b4.a_network_type == ADHOC) { | 
 | 2514 |         DEBUG(1,"ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n", msg->var[0],msg->var[1],msg->var[2],msg->var[3],msg->var[4],msg->var[5]); | 
 | 2515 |         if (msg->var[2] == 1) { | 
 | 2516 |                     DEBUG(0,"ray_cs Sending authentication response.\n"); | 
 | 2517 |                     if (!build_auth_frame (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) { | 
 | 2518 |                         local->authentication_state = NEED_TO_AUTH; | 
 | 2519 |                         memcpy(local->auth_id, msg->mac.addr_2, ADDRLEN); | 
 | 2520 |                     } | 
 | 2521 |         } | 
 | 2522 |     } | 
 | 2523 |     else /* Infrastructure network */ | 
 | 2524 |     { | 
 | 2525 |         if (local->authentication_state == AWAITING_RESPONSE) { | 
 | 2526 |             /* Verify authentication sequence #2 and success */ | 
 | 2527 |             if (msg->var[2] == 2) { | 
 | 2528 |                 if ((msg->var[3] | msg->var[4]) == 0) { | 
 | 2529 |                     DEBUG(1,"Authentication successful\n"); | 
 | 2530 |                     local->card_status = CARD_AUTH_COMPLETE; | 
 | 2531 |                     associate(local); | 
 | 2532 |                     local->authentication_state = AUTHENTICATED; | 
 | 2533 |                 } | 
 | 2534 |                 else { | 
 | 2535 |                     DEBUG(0,"Authentication refused\n"); | 
 | 2536 |                     local->card_status = CARD_AUTH_REFUSED; | 
 | 2537 |                     join_net((u_long)local); | 
 | 2538 |                     local->authentication_state = UNAUTHENTICATED; | 
 | 2539 |                 } | 
 | 2540 |             } | 
 | 2541 |         } | 
 | 2542 |     } | 
 | 2543 |  | 
 | 2544 | } /* end rx_authenticate */ | 
 | 2545 | /*===========================================================================*/ | 
 | 2546 | static void associate(ray_dev_t *local) | 
 | 2547 | { | 
 | 2548 |     struct ccs __iomem *pccs; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 2549 |     struct pcmcia_device *link = local->finder; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 |     struct net_device *dev = link->priv; | 
 | 2551 |     int ccsindex; | 
| Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 2552 |     if (!(pcmcia_dev_present(link))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 |         DEBUG(2,"ray_cs associate - device not present\n"); | 
 | 2554 |         return; | 
 | 2555 |     } | 
 | 2556 |     /* If no tx buffers available, return*/ | 
 | 2557 |     if ((ccsindex = get_free_ccs(local)) < 0) | 
 | 2558 |     { | 
 | 2559 | /* TBD should never be here but... what if we are? */ | 
 | 2560 |         DEBUG(1,"ray_cs associate - No free ccs\n"); | 
 | 2561 |         return; | 
 | 2562 |     } | 
 | 2563 |     DEBUG(1,"ray_cs Starting association with access point\n"); | 
 | 2564 |     pccs = ccs_base(local) + ccsindex; | 
 | 2565 |     /* fill in the CCS */ | 
 | 2566 |     writeb(CCS_START_ASSOCIATION, &pccs->cmd); | 
 | 2567 |     /* Interrupt the firmware to process the command */ | 
 | 2568 |     if (interrupt_ecf(local, ccsindex)) { | 
 | 2569 |         DEBUG(1,"ray_cs associate failed - ECF not ready for intr\n"); | 
 | 2570 |         writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); | 
 | 2571 |  | 
 | 2572 |         del_timer(&local->timer); | 
 | 2573 |         local->timer.expires = jiffies + HZ*2; | 
 | 2574 |         local->timer.data = (long)local; | 
 | 2575 |         local->timer.function = &join_net; | 
 | 2576 |         add_timer(&local->timer); | 
 | 2577 |         local->card_status = CARD_ASSOC_FAILED; | 
 | 2578 |         return; | 
 | 2579 |     } | 
 | 2580 |     if (!sniffer) netif_start_queue(dev); | 
 | 2581 |  | 
 | 2582 | } /* end associate */ | 
 | 2583 | /*===========================================================================*/ | 
 | 2584 | static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,  | 
 | 2585 |                        unsigned int pkt_addr, int rx_len) | 
 | 2586 | { | 
 | 2587 | /*  UCHAR buff[256]; | 
 | 2588 |     struct rx_msg *msg = (struct rx_msg *)buff; | 
 | 2589 | */ | 
 | 2590 |     DEBUG(0,"Deauthentication frame received\n"); | 
 | 2591 |     local->authentication_state = UNAUTHENTICATED; | 
 | 2592 |     /* Need to reauthenticate or rejoin depending on reason code */ | 
 | 2593 | /*  copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff); | 
 | 2594 |  */ | 
 | 2595 | } | 
 | 2596 | /*===========================================================================*/ | 
 | 2597 | static void clear_interrupt(ray_dev_t *local) | 
 | 2598 | { | 
 | 2599 |     writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET); | 
 | 2600 | } | 
 | 2601 | /*===========================================================================*/ | 
 | 2602 | #ifdef CONFIG_PROC_FS | 
 | 2603 | #define MAXDATA (PAGE_SIZE - 80) | 
 | 2604 |  | 
 | 2605 | static char *card_status[] = { | 
 | 2606 |     "Card inserted - uninitialized",     /* 0 */ | 
 | 2607 |     "Card not downloaded",               /* 1 */ | 
 | 2608 |     "Waiting for download parameters",   /* 2 */ | 
 | 2609 |     "Card doing acquisition",            /* 3 */ | 
 | 2610 |     "Acquisition complete",              /* 4 */ | 
 | 2611 |     "Authentication complete",           /* 5 */ | 
 | 2612 |     "Association complete",              /* 6 */ | 
 | 2613 |     "???", "???", "???", "???",          /* 7 8 9 10 undefined */ | 
 | 2614 |     "Card init error",                   /* 11 */ | 
 | 2615 |     "Download parameters error",         /* 12 */ | 
 | 2616 |     "???",                               /* 13 */ | 
 | 2617 |     "Acquisition failed",                /* 14 */ | 
 | 2618 |     "Authentication refused",            /* 15 */ | 
 | 2619 |     "Association failed"                 /* 16 */ | 
 | 2620 | }; | 
 | 2621 |  | 
 | 2622 | static char *nettype[] = {"Adhoc", "Infra "}; | 
 | 2623 | static char *framing[] = {"Encapsulation", "Translation"} | 
 | 2624 | ; | 
 | 2625 | /*===========================================================================*/ | 
 | 2626 | static int ray_cs_proc_read(char *buf, char **start, off_t offset, int len) | 
 | 2627 | { | 
 | 2628 | /* Print current values which are not available via other means | 
 | 2629 |  * eg ifconfig  | 
 | 2630 |  */ | 
 | 2631 |     int i; | 
| Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 2632 |     struct pcmcia_device *link; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 |     struct net_device *dev; | 
 | 2634 |     ray_dev_t *local; | 
 | 2635 |     UCHAR *p; | 
 | 2636 |     struct freq_hop_element *pfh; | 
 | 2637 |     UCHAR c[33]; | 
 | 2638 |  | 
| Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 2639 |     link = this_device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 |     if (!link) | 
 | 2641 |     	return 0; | 
 | 2642 |     dev = (struct net_device *)link->priv; | 
 | 2643 |     if (!dev) | 
 | 2644 |     	return 0; | 
 | 2645 |     local = (ray_dev_t *)dev->priv; | 
 | 2646 |     if (!local) | 
 | 2647 |     	return 0; | 
 | 2648 |  | 
 | 2649 |     len = 0; | 
 | 2650 |  | 
 | 2651 |     len += sprintf(buf + len, "Raylink Wireless LAN driver status\n"); | 
 | 2652 |     len += sprintf(buf + len, "%s\n", rcsid); | 
 | 2653 |     /* build 4 does not report version, and field is 0x55 after memtest */ | 
 | 2654 |     len += sprintf(buf + len, "Firmware version     = "); | 
 | 2655 |     if (local->fw_ver == 0x55) | 
 | 2656 |         len += sprintf(buf + len, "4 - Use dump_cis for more details\n"); | 
 | 2657 |     else | 
 | 2658 |         len += sprintf(buf + len, "%2d.%02d.%02d\n", | 
 | 2659 |                    local->fw_ver, local->fw_bld, local->fw_var); | 
 | 2660 |  | 
 | 2661 |     for (i=0; i<32; i++) c[i] = local->sparm.b5.a_current_ess_id[i]; | 
 | 2662 |     c[32] = 0; | 
 | 2663 |     len += sprintf(buf + len, "%s network ESSID = \"%s\"\n",  | 
 | 2664 |                    nettype[local->sparm.b5.a_network_type], c); | 
 | 2665 |  | 
 | 2666 |     p = local->bss_id; | 
 | 2667 |     len += sprintf(buf + len,  | 
 | 2668 |                    "BSSID                = %02x:%02x:%02x:%02x:%02x:%02x\n", | 
 | 2669 |                    p[0],p[1],p[2],p[3],p[4],p[5]); | 
 | 2670 |  | 
 | 2671 |     len += sprintf(buf + len, "Country code         = %d\n",  | 
 | 2672 |                    local->sparm.b5.a_curr_country_code); | 
 | 2673 |  | 
 | 2674 |     i = local->card_status; | 
 | 2675 |     if (i < 0) i = 10; | 
 | 2676 |     if (i > 16) i = 10; | 
 | 2677 |     len += sprintf(buf + len, "Card status          = %s\n", card_status[i]); | 
 | 2678 |  | 
 | 2679 |     len += sprintf(buf + len, "Framing mode         = %s\n",framing[translate]); | 
 | 2680 |  | 
 | 2681 |     len += sprintf(buf + len, "Last pkt signal lvl  = %d\n", local->last_rsl); | 
 | 2682 |  | 
 | 2683 |     if (local->beacon_rxed) { | 
 | 2684 | 	/* Pull some fields out of last beacon received */ | 
 | 2685 | 	len += sprintf(buf + len, "Beacon Interval      = %d Kus\n",  | 
 | 2686 | 		       local->last_bcn.beacon_intvl[0] | 
 | 2687 | 		       + 256 * local->last_bcn.beacon_intvl[1]); | 
 | 2688 |      | 
 | 2689 |     p = local->last_bcn.elements; | 
 | 2690 |     if (p[0] == C_ESSID_ELEMENT_ID) p += p[1] + 2; | 
 | 2691 |     else { | 
 | 2692 |         len += sprintf(buf + len, "Parse beacon failed at essid element id = %d\n",p[0]); | 
 | 2693 |         return len; | 
 | 2694 |     } | 
 | 2695 |  | 
 | 2696 |     if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) { | 
 | 2697 |         len += sprintf(buf + len, "Supported rate codes = "); | 
 | 2698 |         for (i=2; i<p[1] + 2; i++)  | 
 | 2699 |             len += sprintf(buf + len, "0x%02x ", p[i]); | 
 | 2700 |         len += sprintf(buf + len, "\n"); | 
 | 2701 |         p += p[1] + 2; | 
 | 2702 |     } | 
 | 2703 |     else { | 
 | 2704 |         len += sprintf(buf + len, "Parse beacon failed at rates element\n"); | 
 | 2705 |         return len; | 
 | 2706 |     } | 
 | 2707 |  | 
 | 2708 | 	if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) { | 
 | 2709 | 	    pfh = (struct freq_hop_element *)p; | 
 | 2710 | 	    len += sprintf(buf + len, "Hop dwell            = %d Kus\n", | 
 | 2711 | 			   pfh->dwell_time[0] + 256 * pfh->dwell_time[1]); | 
 | 2712 | 	    len += sprintf(buf + len, "Hop set              = %d \n", pfh->hop_set); | 
 | 2713 | 	    len += sprintf(buf + len, "Hop pattern          = %d \n", pfh->hop_pattern); | 
 | 2714 | 	    len += sprintf(buf + len, "Hop index            = %d \n", pfh->hop_index); | 
 | 2715 | 	    p += p[1] + 2; | 
 | 2716 | 	} | 
 | 2717 | 	else { | 
 | 2718 | 	    len += sprintf(buf + len, "Parse beacon failed at FH param element\n"); | 
 | 2719 | 	    return len; | 
 | 2720 | 	} | 
 | 2721 |     } else { | 
 | 2722 | 	len += sprintf(buf + len, "No beacons received\n"); | 
 | 2723 |     } | 
 | 2724 |     return len; | 
 | 2725 | } | 
 | 2726 |  | 
 | 2727 | #endif | 
 | 2728 | /*===========================================================================*/ | 
 | 2729 | static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type) | 
 | 2730 | { | 
 | 2731 |     int addr; | 
 | 2732 |     struct ccs __iomem *pccs; | 
 | 2733 |     struct tx_msg __iomem *ptx; | 
 | 2734 |     int ccsindex; | 
 | 2735 |  | 
 | 2736 |     /* If no tx buffers available, return */ | 
 | 2737 |     if ((ccsindex = get_free_tx_ccs(local)) < 0) | 
 | 2738 |     { | 
 | 2739 |         DEBUG(1,"ray_cs send authenticate - No free tx ccs\n"); | 
 | 2740 |         return -1; | 
 | 2741 |     } | 
 | 2742 |  | 
 | 2743 |     pccs = ccs_base(local) + ccsindex; | 
 | 2744 |  | 
 | 2745 |     /* Address in card space */ | 
 | 2746 |     addr = TX_BUF_BASE + (ccsindex << 11); | 
 | 2747 |     /* fill in the CCS */ | 
 | 2748 |     writeb(CCS_TX_REQUEST, &pccs->cmd); | 
 | 2749 |     writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr); | 
 | 2750 |     writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1); | 
 | 2751 |     writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length); | 
 | 2752 |     writeb(TX_AUTHENTICATE_LENGTH_LSB,pccs->var.tx_request.tx_data_length + 1); | 
 | 2753 |     writeb(0, &pccs->var.tx_request.pow_sav_mode); | 
 | 2754 |  | 
 | 2755 |     ptx = local->sram + addr; | 
 | 2756 |     /* fill in the mac header */ | 
 | 2757 |     writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1); | 
 | 2758 |     writeb(0, &ptx->mac.frame_ctl_2); | 
 | 2759 |  | 
 | 2760 |     memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN); | 
 | 2761 |     memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN); | 
 | 2762 |     memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN); | 
 | 2763 |  | 
 | 2764 |     /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */ | 
 | 2765 |     memset_io(ptx->var, 0, 6); | 
 | 2766 |     writeb(auth_type & 0xff, ptx->var + 2); | 
 | 2767 |  | 
 | 2768 |     /* Interrupt the firmware to process the command */ | 
 | 2769 |     if (interrupt_ecf(local, ccsindex)) { | 
 | 2770 |         DEBUG(1,"ray_cs send authentication request failed - ECF not ready for intr\n"); | 
 | 2771 |         writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); | 
 | 2772 |         return -1; | 
 | 2773 |     } | 
 | 2774 |     return 0; | 
 | 2775 | } /* End build_auth_frame */ | 
 | 2776 |  | 
 | 2777 | /*===========================================================================*/ | 
 | 2778 | #ifdef CONFIG_PROC_FS | 
 | 2779 | static void raycs_write(const char *name, write_proc_t *w, void *data) | 
 | 2780 | { | 
 | 2781 | 	struct proc_dir_entry * entry = create_proc_entry(name, S_IFREG | S_IWUSR, NULL); | 
 | 2782 | 	if (entry) { | 
 | 2783 | 		entry->write_proc = w; | 
 | 2784 | 		entry->data = data; | 
 | 2785 | 	} | 
 | 2786 | } | 
 | 2787 |  | 
 | 2788 | static int write_essid(struct file *file, const char __user *buffer, unsigned long count, void *data) | 
 | 2789 | { | 
 | 2790 | 	static char proc_essid[33]; | 
 | 2791 | 	int len = count; | 
 | 2792 |  | 
 | 2793 | 	if (len > 32) | 
 | 2794 | 		len = 32; | 
 | 2795 | 	memset(proc_essid, 0, 33); | 
 | 2796 | 	if (copy_from_user(proc_essid, buffer, len)) | 
 | 2797 | 		return -EFAULT; | 
 | 2798 | 	essid = proc_essid; | 
 | 2799 | 	return count; | 
 | 2800 | } | 
 | 2801 |  | 
 | 2802 | static int write_int(struct file *file, const char __user *buffer, unsigned long count, void *data) | 
 | 2803 | { | 
 | 2804 | 	static char proc_number[10]; | 
 | 2805 | 	char *p; | 
 | 2806 | 	int nr, len; | 
 | 2807 |  | 
 | 2808 | 	if (!count) | 
 | 2809 | 		return 0; | 
 | 2810 |  | 
 | 2811 | 	if (count > 9) | 
 | 2812 | 		return -EINVAL; | 
 | 2813 | 	if (copy_from_user(proc_number, buffer, count)) | 
 | 2814 | 		return -EFAULT; | 
 | 2815 | 	p = proc_number; | 
 | 2816 | 	nr = 0; | 
 | 2817 | 	len = count; | 
 | 2818 | 	do { | 
 | 2819 | 		unsigned int c = *p - '0'; | 
 | 2820 | 		if (c > 9) | 
 | 2821 | 			return -EINVAL; | 
 | 2822 | 		nr = nr*10 + c; | 
 | 2823 | 		p++; | 
 | 2824 | 	} while (--len); | 
 | 2825 | 	*(int *)data = nr; | 
 | 2826 | 	return count; | 
 | 2827 | } | 
 | 2828 | #endif | 
 | 2829 |  | 
| Dominik Brodowski | f57ea2a | 2005-06-27 16:28:24 -0700 | [diff] [blame] | 2830 | static struct pcmcia_device_id ray_ids[] = { | 
 | 2831 | 	PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000), | 
 | 2832 | 	PCMCIA_DEVICE_NULL, | 
 | 2833 | }; | 
 | 2834 | MODULE_DEVICE_TABLE(pcmcia, ray_ids); | 
 | 2835 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | static struct pcmcia_driver ray_driver = { | 
 | 2837 | 	.owner		= THIS_MODULE, | 
 | 2838 | 	.drv		= { | 
 | 2839 | 		.name	= "ray_cs", | 
 | 2840 | 	}, | 
| Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 2841 | 	.probe		= ray_probe, | 
| Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 2842 | 	.remove		= ray_detach, | 
| Dominik Brodowski | f57ea2a | 2005-06-27 16:28:24 -0700 | [diff] [blame] | 2843 | 	.id_table       = ray_ids, | 
| Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 2844 | 	.suspend	= ray_suspend, | 
 | 2845 | 	.resume		= ray_resume, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | }; | 
 | 2847 |  | 
 | 2848 | static int __init init_ray_cs(void) | 
 | 2849 | { | 
 | 2850 |     int rc; | 
 | 2851 |      | 
 | 2852 |     DEBUG(1, "%s\n", rcsid); | 
 | 2853 |     rc = pcmcia_register_driver(&ray_driver); | 
 | 2854 |     DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n",rc); | 
 | 2855 |  | 
 | 2856 | #ifdef CONFIG_PROC_FS | 
 | 2857 |     proc_mkdir("driver/ray_cs", NULL); | 
 | 2858 |  | 
 | 2859 |     create_proc_info_entry("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_read); | 
 | 2860 |     raycs_write("driver/ray_cs/essid", write_essid, NULL); | 
 | 2861 |     raycs_write("driver/ray_cs/net_type", write_int, &net_type); | 
 | 2862 |     raycs_write("driver/ray_cs/translate", write_int, &translate); | 
 | 2863 | #endif | 
 | 2864 |     if (translate != 0) translate = 1; | 
 | 2865 |     return 0; | 
 | 2866 | } /* init_ray_cs */ | 
 | 2867 |  | 
 | 2868 | /*===========================================================================*/ | 
 | 2869 |  | 
 | 2870 | static void __exit exit_ray_cs(void) | 
 | 2871 | { | 
 | 2872 |     DEBUG(0, "ray_cs: cleanup_module\n"); | 
 | 2873 |  | 
 | 2874 | #ifdef CONFIG_PROC_FS | 
 | 2875 |     remove_proc_entry("driver/ray_cs/ray_cs", NULL); | 
 | 2876 |     remove_proc_entry("driver/ray_cs/essid", NULL); | 
 | 2877 |     remove_proc_entry("driver/ray_cs/net_type", NULL); | 
 | 2878 |     remove_proc_entry("driver/ray_cs/translate", NULL); | 
 | 2879 |     remove_proc_entry("driver/ray_cs", NULL); | 
 | 2880 | #endif | 
 | 2881 |  | 
 | 2882 |     pcmcia_unregister_driver(&ray_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | } /* exit_ray_cs */ | 
 | 2884 |  | 
 | 2885 | module_init(init_ray_cs); | 
 | 2886 | module_exit(exit_ray_cs); | 
 | 2887 |  | 
 | 2888 | /*===========================================================================*/ |