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