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