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