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