* add p cc
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / net / pcmcia / ray_cs.c
blob81bba9e60b8ffe759c8e619d4eba31ed9ce92946
1 /*=============================================================================
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, dhinds@allegro.stanford.edu
8 * Copyright (c) 1998 Corey Thomas (corey@world.std.com)
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.
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.
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
23 =============================================================================*/
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/sched.h>
28 #include <linux/proc_fs.h>
29 #include <linux/ptrace.h>
30 #include <linux/malloc.h>
31 #include <linux/string.h>
32 #include <linux/timer.h>
33 #include <linux/init.h>
35 #include <asm/io.h>
36 #include <asm/system.h>
37 #include <asm/byteorder.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/ioport.h>
42 #include <linux/skbuff.h>
44 #include <pcmcia/version.h>
45 #include <pcmcia/cs_types.h>
46 #include <pcmcia/cs.h>
47 #include <pcmcia/cistpl.h>
48 #include <pcmcia/cisreg.h>
49 #include <pcmcia/ds.h>
50 #include <pcmcia/mem_op.h>
52 #include "rayctl.h"
53 #include "ray_cs.h"
55 /* All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
56 you do not define PCMCIA_DEBUG at all, all the debug code will be
57 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
58 be present but disabled -- but it can then be enabled for specific
59 modules at load time with a 'pc_debug=#' option to insmod.
62 #ifdef RAYLINK_DEBUG
63 #define PCMCIA_DEBUG RAYLINK_DEBUG
64 #endif
65 #ifdef PCMCIA_DEBUG
66 static int ray_debug = 0;
67 static int pc_debug = PCMCIA_DEBUG;
68 MODULE_PARM(pc_debug, "i");
69 /* #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); */
70 #define DEBUG(n, args...) if (pc_debug>(n)) printk(args);
71 #else
72 #define DEBUG(n, args...)
73 #endif
74 /** Prototypes based on PCMCIA skeleton driver *******************************/
75 void ray_config(dev_link_t *link);
76 void ray_release(u_long arg);
77 int ray_event(event_t event, int priority, event_callback_args_t *args);
78 dev_link_t *ray_attach(void);
79 void ray_detach(dev_link_t *);
81 /***** Prototypes indicated by device structure ******************************/
82 int ray_dev_close(struct net_device *dev);
83 int ray_dev_config(struct net_device *dev, struct ifmap *map);
84 struct enet_statistics *ray_get_stats(struct net_device *dev);
85 int ray_dev_init(struct net_device *dev);
86 int ray_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
87 int ray_open(struct net_device *dev);
88 int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev);
89 static void set_multicast_list(struct net_device *dev);
90 static void ray_update_multi_list(struct net_device *dev, int all);
91 int encapsulate_frame(ray_dev_t *local, struct tx_msg *ptx, UCHAR msg_type,
92 unsigned char *data, int len);
93 int translate_frame(ray_dev_t *local, struct tx_msg *ptx,
94 unsigned char *data, int len);
95 void ray_build_header(ray_dev_t *local, struct tx_msg *ptx, UCHAR msg_type,
96 unsigned char *data);
97 void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
99 /***** Prototypes for raylink functions **************************************/
100 int asc_to_int(char a);
101 void authenticate(ray_dev_t *local);
102 int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
103 void authenticate_timeout(u_long);
104 int get_free_ccs(ray_dev_t *local);
105 int get_free_tx_ccs(ray_dev_t *local);
106 void init_startup_params(ray_dev_t *local);
107 int parse_addr(char *in_str, UCHAR *out);
108 int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev, UCHAR type);
109 int ray_init(struct net_device *dev);
110 int interrupt_ecf(ray_dev_t *local, int ccs);
111 void ray_reset(struct net_device *dev);
112 void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
113 void verify_dl_startup(u_long);
115 /* Prototypes for interrpt time functions **********************************/
116 void ray_interrupt(int reg, void *dev_id, struct pt_regs *regs);
117 void clear_interrupt(ray_dev_t *local);
118 void rx_deauthenticate(ray_dev_t *local, struct rcs *prcs,
119 unsigned int pkt_addr, int rx_len);
120 int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
121 void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs *prcs);
122 void release_frag_chain(ray_dev_t *local, struct rcs *prcs);
123 void rx_authenticate(ray_dev_t *local, struct rcs *prcs,
124 unsigned int pkt_addr, int rx_len);
125 void rx_data(struct net_device *dev, struct rcs *prcs, unsigned int pkt_addr,
126 int rx_len);
127 void associate(ray_dev_t *local);
129 /* Card command functions */
130 int dl_startup_params(struct net_device *dev);
131 void join_net(u_long local);
132 void start_net(u_long local);
133 /* void start_net(ray_dev_t *local); */
135 int ray_cs_proc_read(char *buf, char **start, off_t off, int len, int spare);
136 /* Create symbol table for registering with kernel in init_module */
137 EXPORT_SYMBOL(ray_dev_ioctl);
138 EXPORT_SYMBOL(ray_rx);
140 /*===========================================================================*/
141 /* Parameters that can be set with 'insmod' */
142 /* Bit map of interrupts to choose from */
143 /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
144 static u_long irq_mask = 0xdeb8;
146 /* ADHOC=0, Infrastructure=1 */
147 static int net_type = ADHOC;
149 /* Hop dwell time in Kus (1024 us units defined by 802.11) */
150 static int hop_dwell = 128;
152 /* Beacon period in Kus */
153 static int beacon_period = 256;
155 /* power save mode (0 = off, 1 = save power) */
156 static int psm = 0;
158 /* String for network's Extended Service Set ID. 32 Characters max */
159 static char *essid = NULL;
161 /* Default to encapsulation unless translation requested */
162 static int translate = 1;
164 static int country = USA;
166 static int sniffer = 0;
168 static int bc = 0;
170 /* 48 bit physical card address if overriding card's real physical
171 * address is required. Since IEEE 802.11 addresses are 48 bits
172 * like ethernet, an int can't be used, so a string is used. To
173 * allow use of addresses starting with a decimal digit, the first
174 * character must be a letter and will be ignored. This letter is
175 * followed by up to 12 hex digits which are the address. If less
176 * than 12 digits are used, the address will be left filled with 0's.
177 * Note that bit 0 of the first byte is the broadcast bit, and evil
178 * things will happen if it is not 0 in a card address.
180 static char *phy_addr = NULL;
183 /* The dev_info variable is the "key" that is used to match up this
184 device driver with appropriate cards, through the card configuration
185 database.
187 static dev_info_t dev_info = "ray_cs";
189 /* A linked list of "instances" of the ray device. Each actual
190 PCMCIA card corresponds to one device instance, and is described
191 by one dev_link_t structure (defined in ds.h).
193 static dev_link_t *dev_list = NULL;
195 /* A dev_link_t structure has fields for most things that are needed
196 to keep track of a socket, but there will usually be some device
197 specific information that also needs to be kept track of. The
198 'priv' pointer in a dev_link_t structure can be used to point to
199 a device-specific private data structure, like this.
201 static unsigned int ray_mem_speed = 0x2A;
203 MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
204 MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
205 MODULE_PARM(irq_mask,"i");
206 MODULE_PARM(net_type,"i");
207 MODULE_PARM(hop_dwell,"i");
208 MODULE_PARM(beacon_period,"i");
209 MODULE_PARM(psm,"i");
210 MODULE_PARM(essid,"s");
211 MODULE_PARM(translate,"i");
212 MODULE_PARM(country,"i");
213 MODULE_PARM(sniffer,"i");
214 MODULE_PARM(bc,"i");
215 MODULE_PARM(phy_addr,"s");
216 MODULE_PARM(ray_mem_speed, "i");
218 static UCHAR b5_default_startup_parms[] = {
219 0, 0, /* Adhoc station */
220 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
221 0, 0, 0, 0, 0, 0, 0, 0,
222 0, 0, 0, 0, 0, 0, 0, 0,
223 0, 0, 0, 0, 0, 0, 0, 0,
224 1, 0, /* Active scan, CA Mode */
225 0, 0, 0, 0, 0, 0, /* No default MAC addr */
226 0x7f, 0xff, /* Frag threshold */
227 0x00, 0x80, /* Hop time 128 Kus*/
228 0x01, 0x00, /* Beacon period 256 Kus */
229 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
230 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
231 0x7f, 0xff, /* RTS threshold */
232 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
233 0x05, /* assoc resp timeout thresh */
234 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max*/
235 0, /* Promiscuous mode */
236 0x0c, 0x0bd, /* Unique word */
237 0x32, /* Slot time */
238 0xff, 0xff, /* roam-low snr, low snr count */
239 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
240 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
241 /* b4 - b5 differences start here */
242 0x00, 0x3f, /* CW max */
243 0x00, 0x0f, /* CW min */
244 0x04, 0x08, /* Noise gain, limit offset */
245 0x28, 0x28, /* det rssi, med busy offsets */
246 7, /* det sync thresh */
247 0, 2, 2, /* test mode, min, max */
248 0, /* allow broadcast SSID probe resp */
249 0, 0, /* privacy must start, can join */
250 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
253 static UCHAR b4_default_startup_parms[] = {
254 0, 0, /* Adhoc station */
255 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
256 0, 0, 0, 0, 0, 0, 0, 0,
257 0, 0, 0, 0, 0, 0, 0, 0,
258 0, 0, 0, 0, 0, 0, 0, 0,
259 1, 0, /* Active scan, CA Mode */
260 0, 0, 0, 0, 0, 0, /* No default MAC addr */
261 0x7f, 0xff, /* Frag threshold */
262 0x02, 0x00, /* Hop time */
263 0x00, 0x01, /* Beacon period */
264 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
265 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
266 0x7f, 0xff, /* RTS threshold */
267 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
268 0x05, /* assoc resp timeout thresh */
269 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max*/
270 0, /* Promiscuous mode */
271 0x0c, 0x0bd, /* Unique word */
272 0x4e, /* Slot time (TBD seems wrong)*/
273 0xff, 0xff, /* roam-low snr, low snr count */
274 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
275 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
276 /* b4 - b5 differences start here */
277 0x3f, 0x0f, /* CW max, min */
278 0x04, 0x08, /* Noise gain, limit offset */
279 0x28, 0x28, /* det rssi, med busy offsets */
280 7, /* det sync thresh */
281 0, 2, 2 /* test mode, min, max*/
283 /*===========================================================================*/
284 static unsigned char eth2_llc[] = {0xaa, 0xaa, 3, 0, 0, 0};
286 static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
288 #ifdef CONFIG_PROC_FS
289 struct proc_dir_entry ray_cs_proc_entry = {
290 0, /* Dynamic inode # */
291 6,"ray_cs", /* name length and name */
292 S_IFREG | S_IRUGO, /* mode */
293 1, 0, 0, /* nlinks, owner, group */
294 0, /* size (unused) */
295 NULL, /* operations (default) */
296 &ray_cs_proc_read, /* function to read data */
297 /* The end ?? */
299 #endif
300 /*===========================================================================*/
301 void cs_error(client_handle_t handle, int func, int ret)
303 error_info_t err = { func, ret };
304 CardServices(ReportError, handle, &err);
306 /*=============================================================================
307 ray_attach() creates an "instance" of the driver, allocating
308 local data structures for one device. The device is registered
309 with Card Services.
310 The dev_link structure is initialized, but we don't actually
311 configure the card at this point -- we wait until we receive a
312 card insertion event.
313 =============================================================================*/
314 dev_link_t *ray_attach(void)
316 client_reg_t client_reg;
317 dev_link_t *link;
318 ray_dev_t *local;
319 int ret;
320 struct net_device *dev;
322 DEBUG(1, "ray_attach()\n");
324 /* Initialize the dev_link_t structure */
325 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
326 memset(link, 0, sizeof(struct dev_link_t));
327 link->release.function = &ray_release;
328 link->release.data = (u_long)link;
330 /* The io structure describes IO port mapping. None used here */
331 link->io.NumPorts1 = 0;
332 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
333 link->io.IOAddrLines = 5;
335 /* Interrupt setup. For PCMCIA, driver takes what's given */
336 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
337 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
338 link->irq.IRQInfo2 = irq_mask;
339 link->irq.Handler = &ray_interrupt;
341 /* General socket configuration */
342 link->conf.Attributes = CONF_ENABLE_IRQ;
343 link->conf.Vcc = 50;
344 link->conf.IntType = INT_MEMORY_AND_IO;
345 link->conf.ConfigIndex = 1;
346 link->conf.Present = PRESENT_OPTION;
348 /* Allocate space for private device-specific data */
349 dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
350 memset(dev, 0, sizeof(struct net_device));
351 link->priv = dev;
352 link->irq.Instance = dev;
354 local = kmalloc(sizeof(ray_dev_t), GFP_KERNEL);
355 memset(local, 0, sizeof(ray_dev_t));
356 dev->priv = local;
357 local->finder = link;
358 link->dev = &local->node;
359 local->card_status = CARD_INSERTED;
360 local->authentication_state = UNAUTHENTICATED;
361 local->num_multi = 0;
362 DEBUG(2,"ray_attach link = %p, dev = %p, local = %p, intr = %p\n",
363 link,dev,local,&ray_interrupt);
365 /* Raylink entries in the device structure */
366 dev->hard_start_xmit = &ray_dev_start_xmit;
367 dev->set_config = &ray_dev_config;
368 dev->get_stats = &ray_get_stats;
369 dev->do_ioctl = &ray_dev_ioctl;
371 dev->set_multicast_list = &set_multicast_list;
373 DEBUG(2,"ray_cs ray_attach calling ether_setup.)\n");
374 ether_setup(dev);
375 dev->name = local->node.dev_name;
376 dev->init = &ray_dev_init;
377 dev->open = &ray_open;
378 dev->stop = &ray_dev_close;
379 dev->tbusy = 1;
381 /* Register with Card Services */
382 link->next = dev_list;
383 dev_list = link;
384 client_reg.dev_info = &dev_info;
385 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
386 client_reg.EventMask =
387 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
388 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
389 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
390 client_reg.event_handler = &ray_event;
391 client_reg.Version = 0x0210;
392 client_reg.event_callback_args.client_data = link;
394 DEBUG(2,"ray_cs ray_attach calling CardServices(RegisterClient...)\n");
396 init_timer(&local->timer);
398 ret = CardServices(RegisterClient, &link->handle, &client_reg);
399 if (ret != 0) {
400 printk("ray_cs ray_attach RegisterClient unhappy - detaching\n");
401 cs_error(link->handle, RegisterClient, ret);
402 ray_detach(link);
403 return NULL;
405 DEBUG(2,"ray_cs ray_attach ending\n");
406 return link;
407 } /* ray_attach */
408 /*=============================================================================
409 This deletes a driver "instance". The device is de-registered
410 with Card Services. If it has been released, all local data
411 structures are freed. Otherwise, the structures will be freed
412 when the device is released.
413 =============================================================================*/
414 void ray_detach(dev_link_t *link)
416 dev_link_t **linkp;
417 struct net_device *dev;
418 long flags;
420 DEBUG(1, "ray_detach(0x%p)\n", link);
422 /* Locate device structure */
423 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
424 if (*linkp == link) break;
425 if (*linkp == NULL)
426 return;
428 save_flags(flags);
429 cli();
430 if (link->state & DEV_RELEASE_PENDING) {
431 del_timer(&link->release);
432 link->state &= ~DEV_RELEASE_PENDING;
434 restore_flags(flags);
436 /* If the device is currently configured and active, we won't
437 actually delete it yet. Instead, it is marked so that when
438 the release() function is called, that will trigger a proper
439 detach().
441 if (link->state & DEV_CONFIG) {
442 ray_release((u_long)link);
443 if(link->state & DEV_STALE_CONFIG) {
444 link->state |= DEV_STALE_LINK;
445 return;
449 /* Break the link with Card Services */
450 if (link->handle)
451 CardServices(DeregisterClient, link->handle);
453 /* Unlink device structure, free pieces */
454 *linkp = link->next;
455 if (link->priv) {
456 dev = link->priv;
457 if (dev->priv)
458 kfree_s(dev->priv, sizeof(ray_dev_t));
460 kfree_s(link->priv, sizeof(struct net_device));
462 kfree_s(link, sizeof(struct dev_link_t));
463 DEBUG(2,"ray_cs ray_detach ending\n");
464 } /* ray_detach */
465 /*=============================================================================
466 ray_config() is run after a CARD_INSERTION event
467 is received, to configure the PCMCIA socket, and to make the
468 ethernet device available to the system.
469 =============================================================================*/
470 #define CS_CHECK(fn, args...) \
471 while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
472 #define MAX_TUPLE_SIZE 128
473 void ray_config(dev_link_t *link)
475 client_handle_t handle = link->handle;
476 tuple_t tuple;
477 cisparse_t parse;
478 int last_fn, last_ret;
479 int i;
480 u_char buf[MAX_TUPLE_SIZE];
481 win_req_t req;
482 memreq_t mem;
483 struct net_device *dev = (struct net_device *)link->priv;
484 ray_dev_t *local = (ray_dev_t *)dev->priv;
486 DEBUG(1, "ray_config(0x%p)\n", link);
488 /* This reads the card's CONFIG tuple to find its configuration regs */
489 tuple.DesiredTuple = CISTPL_CONFIG;
490 CS_CHECK(GetFirstTuple, handle, &tuple);
491 tuple.TupleData = buf;
492 tuple.TupleDataMax = MAX_TUPLE_SIZE;
493 tuple.TupleOffset = 0;
494 CS_CHECK(GetTupleData, handle, &tuple);
495 CS_CHECK(ParseTuple, handle, &tuple, &parse);
496 link->conf.ConfigBase = parse.config.base;
497 link->conf.Present = parse.config.rmask[0];
499 /* Determine card type and firmware version */
500 buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0;
501 tuple.DesiredTuple = CISTPL_VERS_1;
502 CS_CHECK(GetFirstTuple, handle, &tuple);
503 tuple.TupleData = buf;
504 tuple.TupleDataMax = MAX_TUPLE_SIZE;
505 tuple.TupleOffset = 2;
506 CS_CHECK(GetTupleData, handle, &tuple);
508 for (i=0; i<tuple.TupleDataLen - 4; i++)
509 if (buf[i] == 0) buf[i] = ' ';
510 printk(KERN_INFO "ray_cs Detected: %s\n",buf);
512 /* Configure card */
513 link->state |= DEV_CONFIG;
515 /* Now allocate an interrupt line. Note that this does not
516 actually assign a handler to the interrupt.
518 CS_CHECK(RequestIRQ, link->handle, &link->irq);
519 dev->irq = link->irq.AssignedIRQ;
521 /* This actually configures the PCMCIA socket -- setting up
522 the I/O windows and the interrupt mapping.
524 CS_CHECK(RequestConfiguration, link->handle, &link->conf);
526 /*** Set up 32k window for shared memory (transmit and control) ************/
527 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
528 req.Base = 0;
529 req.Size = 0x8000;
530 req.AccessSpeed = ray_mem_speed;
531 link->win = (window_handle_t)link->handle;
532 CS_CHECK(RequestWindow, &link->win, &req);
533 mem.CardOffset = 0x0000; mem.Page = 0;
534 CS_CHECK(MapMemPage, link->win, &mem);
535 local->sram = (UCHAR *)(ioremap(req.Base,req.Size));
537 /*** Set up 16k window for shared memory (receive buffer) ***************/
538 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
539 req.Base = 0;
540 req.Size = 0x4000;
541 req.AccessSpeed = ray_mem_speed;
542 local->rmem_handle = (window_handle_t)link->handle;
543 CS_CHECK(RequestWindow, &local->rmem_handle, &req);
544 mem.CardOffset = 0x8000; mem.Page = 0;
545 CS_CHECK(MapMemPage, local->rmem_handle, &mem);
546 local->rmem = (UCHAR *)(ioremap(req.Base,req.Size));
548 /*** Set up window for attribute memory ***********************************/
549 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
550 req.Base = 0;
551 req.Size = 0x1000;
552 req.AccessSpeed = ray_mem_speed;
553 local->amem_handle = (window_handle_t)link->handle;
554 CS_CHECK(RequestWindow, &local->amem_handle, &req);
555 mem.CardOffset = 0x0000; mem.Page = 0;
556 CS_CHECK(MapMemPage, local->amem_handle, &mem);
557 local->amem = (UCHAR *)(ioremap(req.Base,req.Size));
559 DEBUG(3,"ray_config sram=%p\n",local->sram);
560 DEBUG(3,"ray_config rmem=%p\n",local->rmem);
561 DEBUG(3,"ray_config amem=%p\n",local->amem);
562 if (ray_init(dev) < 0) {
563 ray_release((u_long)link);
564 return;
567 i = register_netdev(dev);
568 if (i != 0) {
569 printk("ray_config register_netdev() failed\n");
570 ray_release((u_long)link);
571 return;
574 link->state &= ~DEV_CONFIG_PENDING;
575 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ",
576 dev->name, dev->irq);
577 for (i = 0; i < 6; i++)
578 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
580 return;
582 cs_failed:
583 cs_error(link->handle, last_fn, last_ret);
585 ray_release((u_long)link);
586 } /* ray_config */
587 /*===========================================================================*/
588 int ray_init(struct net_device *dev)
590 int i;
591 UCHAR *p;
592 struct ccs *pccs;
593 ray_dev_t *local = (ray_dev_t *)dev->priv;
594 dev_link_t *link = local->finder;
595 DEBUG(1, "ray_init(0x%p)\n", dev);
596 if (!(link->state & DEV_PRESENT)) {
597 DEBUG(0,"ray_init - device not present\n");
598 return -1;
601 local->net_type = net_type;
602 local->sta_type = TYPE_STA;
604 /* Copy the startup results to local memory */
605 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,\
606 sizeof(struct startup_res_6));
608 /* Check Power up test status and get mac address from card */
609 if (local->startup_res.startup_word != 0x80) {
610 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
611 local->startup_res.startup_word);
612 local->card_status = CARD_INIT_ERROR;
613 return -1;
616 local->fw_ver = local->startup_res.firmware_version[0];
617 local->fw_bld = local->startup_res.firmware_version[1];
618 local->fw_var = local->startup_res.firmware_version[2];
619 DEBUG(1,"ray_init firmware version %d.%d \n",local->fw_ver, local->fw_bld);
621 local->tib_length = 0x20;
622 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
623 local->tib_length = local->startup_res.tib_length;
624 DEBUG(2,"ray_init tib_length = 0x%02x\n", local->tib_length);
625 /* Initialize CCS's to buffer free state */
626 pccs = (struct ccs *)(local->sram + CCS_BASE);
627 for (i=0; i<NUMBER_OF_CCS; i++) {
628 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
630 init_startup_params(local);
632 /* copy mac address to startup parameters */
633 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr))
635 p = local->sparm.b4.a_mac_addr;
637 else
639 memcpy(&local->sparm.b4.a_mac_addr,
640 &local->startup_res.station_addr, ADDRLEN);
641 p = local->sparm.b4.a_mac_addr;
644 clear_interrupt(local); /* Clear any interrupt from the card */
645 local->card_status = CARD_AWAITING_PARAM;
646 DEBUG(2,"ray_init ending\n");
647 return 0;
648 } /* ray_init */
649 /*===========================================================================*/
650 /* Download startup parameters to the card and command it to read them */
651 int dl_startup_params(struct net_device *dev)
653 int ccsindex;
654 ray_dev_t *local = (ray_dev_t *)dev->priv;
655 struct ccs *pccs;
656 dev_link_t *link = local->finder;
658 DEBUG(1,"dl_startup_params entered\n");
659 if (!(link->state & DEV_PRESENT)) {
660 DEBUG(2,"ray_cs dl_startup_params - device not present\n");
661 return -1;
664 /* Copy parameters to host to ECF area */
665 if (local->fw_ver == 0x55)
666 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
667 sizeof(struct b4_startup_params));
668 else
669 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
670 sizeof(struct b5_startup_params));
673 /* Fill in the CCS fields for the ECF */
674 if ((ccsindex = get_free_ccs(local)) < 0) return -1;
675 local->dl_param_ccs = ccsindex;
676 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
677 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
678 DEBUG(2,"dl_startup_params start ccsindex = %d\n", local->dl_param_ccs);
679 /* Interrupt the firmware to process the command */
680 if (interrupt_ecf(local, ccsindex)) {
681 printk(KERN_INFO "ray dl_startup_params failed - "
682 "ECF not ready for intr\n");
683 local->card_status = CARD_DL_PARAM_ERROR;
684 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
685 return -2;
687 local->card_status = CARD_DL_PARAM;
688 /* Start kernel timer to wait for dl startup to complete. */
689 local->timer.expires = jiffies + HZ/2;
690 local->timer.data = (long)local;
691 local->timer.function = &verify_dl_startup;
692 add_timer(&local->timer);
693 DEBUG(2,"ray_cs dl_startup_params started timer for verify_dl_startup\n");
694 return 0;
695 } /* dl_startup_params */
696 /*===========================================================================*/
697 void init_startup_params(ray_dev_t *local)
699 int i;
700 static char hop_pattern_length[] = { 1,
701 USA_HOP_MOD, EUROPE_HOP_MOD,
702 JAPAN_HOP_MOD, KOREA_HOP_MOD,
703 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
704 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
705 JAPAN_TEST_HOP_MOD
708 if (country > JAPAN_TEST) country = USA;
709 else
710 if (country < USA) country = USA;
711 /* structure for hop time and beacon period is defined here using
712 * New 802.11D6.1 format. Card firmware is still using old format
713 * until version 6.
714 * Before After
715 * a_hop_time ms byte a_hop_time ms byte
716 * a_hop_time 2s byte a_hop_time ls byte
717 * a_hop_time ls byte a_beacon_period ms byte
718 * a_beacon_period a_beacon_period ls byte
720 * a_hop_time = uS a_hop_time = KuS
721 * a_beacon_period = hops a_beacon_period = KuS
722 */ /* 64ms = 010000 */
723 if (local->fw_ver == 0x55) {
724 memcpy((UCHAR *)&local->sparm.b4, b4_default_startup_parms,
725 sizeof(struct b4_startup_params));
726 /* Translate sane kus input values to old build 4/5 format */
727 /* i = hop time in uS truncated to 3 bytes */
728 i = (hop_dwell * 1024) & 0xffffff;
729 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
730 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
731 local->sparm.b4.a_beacon_period[0] = 0;
732 local->sparm.b4.a_beacon_period[1] =
733 ((beacon_period/hop_dwell) - 1) & 0xff;
734 local->sparm.b4.a_curr_country_code = country;
735 local->sparm.b4.a_hop_pattern_length =
736 hop_pattern_length[(int)country] - 1;
737 if (bc)
739 local->sparm.b4.a_ack_timeout = 0x50;
740 local->sparm.b4.a_sifs = 0x3f;
743 else { /* Version 5 uses real kus values */
744 memcpy((UCHAR *)&local->sparm.b5, b5_default_startup_parms,
745 sizeof(struct b5_startup_params));
747 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
748 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
749 local->sparm.b5.a_beacon_period[0] = (beacon_period >> 8) & 0xff;
750 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
751 if (psm)
752 local->sparm.b5.a_power_mgt_state = 1;
753 local->sparm.b5.a_curr_country_code = country;
754 local->sparm.b5.a_hop_pattern_length =
755 hop_pattern_length[(int)country];
758 local->sparm.b4.a_network_type = net_type & 0x01;
759 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
761 if (essid != NULL)
762 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
763 } /* init_startup_params */
764 /*===========================================================================*/
765 void verify_dl_startup(u_long data)
767 ray_dev_t *local = (ray_dev_t *)data;
768 struct ccs *pccs = ((struct ccs *)(local->sram + CCS_BASE)) + local->dl_param_ccs;
769 UCHAR status;
770 dev_link_t *link = local->finder;
772 if (!(link->state & DEV_PRESENT)) {
773 DEBUG(2,"ray_cs verify_dl_startup - device not present\n");
774 return;
776 #ifdef PCMCIA_DEBUG
777 if (pc_debug > 2) {
778 int i;
779 printk(KERN_DEBUG "verify_dl_startup parameters sent via ccs %d:\n",
780 local->dl_param_ccs);
781 for (i=0; i<sizeof(struct b5_startup_params); i++) {
782 printk(" %2x", readb(local->sram + HOST_TO_ECF_BASE + i));
784 printk("\n");
786 #endif
788 status = readb(&pccs->buffer_status);
789 if (status!= CCS_BUFFER_FREE)
791 printk(KERN_INFO "Download startup params failed. Status = %d\n",
792 status);
793 local->card_status = CARD_DL_PARAM_ERROR;
794 return;
796 if (local->sparm.b4.a_network_type == ADHOC)
797 start_net((u_long)local);
798 else
799 join_net((u_long)local);
801 return;
802 } /* end verify_dl_startup */
803 /*===========================================================================*/
804 /* Command card to start a network */
805 void start_net(u_long data)
807 ray_dev_t *local = (ray_dev_t *)data;
808 struct ccs *pccs;
809 int ccsindex;
810 dev_link_t *link = local->finder;
811 if (!(link->state & DEV_PRESENT)) {
812 DEBUG(2,"ray_cs start_net - device not present\n");
813 return;
815 /* Fill in the CCS fields for the ECF */
816 if ((ccsindex = get_free_ccs(local)) < 0) return;
817 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
818 writeb(CCS_START_NETWORK, &pccs->cmd);
819 writeb(0, &pccs->var.start_network.update_param);
820 /* Interrupt the firmware to process the command */
821 if (interrupt_ecf(local, ccsindex)) {
822 DEBUG(1,"ray start net failed - card not ready for intr\n");
823 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
824 return;
826 local->card_status = CARD_DOING_ACQ;
827 return;
828 } /* end start_net */
829 /*===========================================================================*/
830 /* Command card to join a network */
831 void join_net(u_long data)
833 ray_dev_t *local = (ray_dev_t *)data;
835 struct ccs *pccs;
836 int ccsindex;
837 dev_link_t *link = local->finder;
839 if (!(link->state & DEV_PRESENT)) {
840 DEBUG(2,"ray_cs join_net - device not present\n");
841 return;
843 /* Fill in the CCS fields for the ECF */
844 if ((ccsindex = get_free_ccs(local)) < 0) return;
845 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
846 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
847 writeb(0, &pccs->var.join_network.update_param);
848 writeb(0, &pccs->var.join_network.net_initiated);
849 /* Interrupt the firmware to process the command */
850 if (interrupt_ecf(local, ccsindex)) {
851 DEBUG(1,"ray join net failed - card not ready for intr\n");
852 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
853 return;
855 local->card_status = CARD_DOING_ACQ;
856 return;
858 /*============================================================================
859 After a card is removed, ray_release() will unregister the net
860 device, and release the PCMCIA configuration. If the device is
861 still open, this will be postponed until it is closed.
862 =============================================================================*/
863 void ray_release(u_long arg)
865 dev_link_t *link = (dev_link_t *)arg;
866 struct net_device *dev = link->priv;
867 ray_dev_t *local = dev->priv;
868 int i;
870 DEBUG(1, "ray_release(0x%p)\n", link);
871 /* If the device is currently in use, we won't release until it
872 is actually closed.
874 if (link->open) {
875 DEBUG(1, "ray_cs: release postponed, '%s' still open\n",
876 link->dev->dev_name);
877 link->state |= DEV_STALE_CONFIG;
878 return;
880 del_timer(&local->timer);
881 if (link->dev != '\0') unregister_netdev(dev);
882 /* Unlink the device chain */
883 link->dev = NULL;
885 iounmap(local->sram);
886 iounmap(local->rmem);
887 iounmap(local->amem);
888 /* Do bother checking to see if these succeed or not */
889 i = CardServices(ReleaseWindow, link->win);
890 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(link->win) ret = %x\n",i);
891 i = CardServices(ReleaseWindow, local->amem_handle);
892 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
893 i = CardServices(ReleaseWindow, local->rmem_handle);
894 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
895 i = CardServices(ReleaseConfiguration, link->handle);
896 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseConfiguration ret = %x\n",i);
897 i = CardServices(ReleaseIRQ, link->handle, &link->irq);
898 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseIRQ ret = %x\n",i);
900 link->state &= ~DEV_CONFIG;
901 if (link->state & DEV_STALE_LINK) ray_detach(link);
902 DEBUG(2,"ray_release ending\n");
903 } /* ray_release */
904 /*=============================================================================
905 The card status event handler. Mostly, this schedules other
906 stuff to run after an event is received. A CARD_REMOVAL event
907 also sets some flags to discourage the net drivers from trying
908 to talk to the card any more.
910 When a CARD_REMOVAL event is received, we immediately set a flag
911 to block future accesses to this device. All the functions that
912 actually access the device should check this flag to make sure
913 the card is still present.
914 =============================================================================*/
915 int ray_event(event_t event, int priority,
916 event_callback_args_t *args)
918 dev_link_t *link = args->client_data;
919 struct net_device *dev = link->priv;
920 ray_dev_t *local = (ray_dev_t *)dev->priv;
921 DEBUG(1, "ray_event(0x%06x)\n", event);
923 switch (event) {
924 case CS_EVENT_CARD_REMOVAL:
925 link->state &= ~DEV_PRESENT;
926 dev->tbusy = 1; dev->start = 0;
927 if (link->state & DEV_CONFIG) {
928 link->release.expires = jiffies + HZ/20;
929 add_timer(&link->release);
930 del_timer(&local->timer);
932 break;
933 case CS_EVENT_CARD_INSERTION:
934 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
935 ray_config(link);
936 break;
937 case CS_EVENT_PM_SUSPEND:
938 link->state |= DEV_SUSPEND;
939 /* Fall through... */
940 case CS_EVENT_RESET_PHYSICAL:
941 if (link->state & DEV_CONFIG) {
942 if (link->open) {
943 dev->tbusy = 1;
944 dev->start = 0;
946 CardServices(ReleaseConfiguration, link->handle);
948 break;
949 case CS_EVENT_PM_RESUME:
950 link->state &= ~DEV_SUSPEND;
951 /* Fall through... */
952 case CS_EVENT_CARD_RESET:
953 if (link->state & DEV_CONFIG) {
954 CardServices(RequestConfiguration, link->handle, &link->conf);
955 if (link->open) {
956 ray_reset(dev);
957 dev->tbusy = 0;
958 dev->start = 1;
961 break;
963 return 0;
964 DEBUG(2,"ray_event ending\n");
965 } /* ray_event */
966 /*===========================================================================*/
967 int ray_dev_init(struct net_device *dev)
969 int i;
970 ray_dev_t *local = dev->priv;
971 dev_link_t *link = local->finder;
973 DEBUG(1,"ray_dev_init(dev=%p)\n",dev);
974 if (!(link->state & DEV_PRESENT)) {
975 DEBUG(2,"ray_dev_init - device not present\n");
976 return -1;
978 /* Download startup parameters */
979 if ( (i = dl_startup_params(dev)) < 0)
981 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
982 "returns 0x%x/n",i);
983 return -1;
986 /* copy mac and broadcast addresses to linux device */
987 memcpy(&dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
988 memset(dev->broadcast, 0xff, ETH_ALEN);
990 DEBUG(2,"ray_dev_init ending\n");
991 return 0;
993 /*===========================================================================*/
994 int ray_dev_config(struct net_device *dev, struct ifmap *map)
996 ray_dev_t *local = dev->priv;
997 dev_link_t *link = local->finder;
998 /* Dummy routine to satisfy device structure */
999 DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map);
1000 if (!(link->state & DEV_PRESENT)) {
1001 DEBUG(2,"ray_dev_config - device not present\n");
1002 return -1;
1005 return 0;
1007 /*===========================================================================*/
1008 int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
1010 ray_dev_t *local = dev->priv;
1011 dev_link_t *link = local->finder;
1012 short length;
1014 if (!(link->state & DEV_PRESENT)) {
1015 DEBUG(2,"ray_dev_start_xmit - device not present\n");
1016 return -1;
1018 DEBUG(3,"ray_dev_start_xmit(skb=%p, dev=%p)\n",skb,dev);
1019 if (dev->tbusy)
1021 printk(KERN_NOTICE "ray_dev_start_xmit busy\n");
1022 return 1;
1024 if (local->authentication_state == NEED_TO_AUTH) {
1025 DEBUG(0,"ray_cs Sending authentication request.\n");
1026 if (!build_auth_frame (local, local->auth_id, OPEN_AUTH_REQUEST)) {
1027 local->authentication_state = AUTHENTICATED;
1028 dev->tbusy = 1;
1029 return 1;
1033 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1034 switch (ray_hw_xmit( skb->data, length, dev, DATA_TYPE)) {
1035 case XMIT_NO_CCS:
1036 case XMIT_NEED_AUTH:
1037 dev->tbusy = 1;
1038 return 1;
1039 case XMIT_NO_INTR:
1040 case XMIT_MSG_BAD:
1041 case XMIT_OK:
1042 default:
1043 dev->trans_start = jiffies;
1044 dev_kfree_skb(skb);
1045 return 0;
1047 return 0;
1048 } /* ray_dev_start_xmit */
1049 /*===========================================================================*/
1050 int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev,
1051 UCHAR msg_type)
1053 ray_dev_t *local = (ray_dev_t *)dev->priv;
1054 struct ccs *pccs;
1055 int ccsindex;
1056 int offset;
1057 struct tx_msg *ptx; /* Address of xmit buffer in PC space */
1058 short int addr; /* Address of xmit buffer in card space */
1060 DEBUG(3,"ray_hw_xmit(data=%p, len=%d, dev=%p)\n",data,len,dev);
1061 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE)
1063 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",len);
1064 return XMIT_MSG_BAD;
1066 switch (ccsindex = get_free_tx_ccs(local)) {
1067 case ECCSBUSY:
1068 DEBUG(2,"ray_hw_xmit tx_ccs table busy\n");
1069 case ECCSFULL:
1070 DEBUG(2,"ray_hw_xmit No free tx ccs\n");
1071 case ECARDGONE:
1072 dev->tbusy = 1;
1073 return XMIT_NO_CCS;
1074 default:
1075 break;
1077 addr = TX_BUF_BASE + (ccsindex << 11);
1079 if (msg_type == DATA_TYPE) {
1080 local->stats.tx_bytes += len;
1081 local->stats.tx_packets++;
1084 ptx = (struct tx_msg *)(local->sram + addr);
1086 ray_build_header(local, ptx, msg_type, data);
1087 if (translate) {
1088 offset = translate_frame(local, ptx, data, len);
1090 else { /* Encapsulate frame */
1091 /* TBD TIB length will move address of ptx->var */
1092 memcpy( (UCHAR *)&ptx->var, data, len);
1093 offset = 0;
1096 /* fill in the CCS */
1097 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
1098 len += TX_HEADER_LENGTH + offset;
1099 writeb(CCS_TX_REQUEST, &pccs->cmd);
1100 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
1101 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
1102 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
1103 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
1104 /* TBD still need psm_cam? */
1105 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
1106 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1107 writeb(0, &pccs->var.tx_request.antenna);
1108 DEBUG(3,"ray_hw_xmit default_tx_rate = 0x%x\n",\
1109 local->net_default_tx_rate);
1111 /* Interrupt the firmware to process the command */
1112 if (interrupt_ecf(local, ccsindex)) {
1113 DEBUG(2,"ray_hw_xmit failed - ECF not ready for intr\n");
1114 /* TBD very inefficient to copy packet to buffer, and then not
1115 send it, but the alternative is to queue the messages and that
1116 won't be done for a while. Maybe set tbusy until a CCS is free?
1118 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1119 return XMIT_NO_INTR;
1121 return XMIT_OK;
1122 } /* end ray_hw_xmit */
1123 /*===========================================================================*/
1124 int translate_frame(ray_dev_t *local, struct tx_msg *ptx, unsigned char *data,
1125 int len)
1127 unsigned short int proto = ((struct ethhdr *)data)->h_proto;
1128 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
1129 DEBUG(3,"ray_cs translate_frame DIX II\n");
1130 /* Copy LLC header to card buffer */
1131 memcpy_toio((UCHAR *)&ptx->var, eth2_llc, sizeof(eth2_llc));
1132 memcpy_toio( ((UCHAR *)&ptx->var) + sizeof(eth2_llc), (UCHAR *)&proto, 2);
1133 if ((proto == 0xf380) || (proto == 0x3781)) {
1134 /* This is the selective translation table, only 2 entries */
1135 writeb(0xf8, (UCHAR *) &((struct snaphdr_t *)ptx->var)->org[3]);
1137 /* Copy body of ethernet packet without ethernet header */
1138 memcpy_toio((UCHAR *)&ptx->var + sizeof(struct snaphdr_t), \
1139 data + ETH_HLEN, len - ETH_HLEN);
1140 return sizeof(struct snaphdr_t) - ETH_HLEN;
1142 else { /* already 802 type, and proto is length */
1143 DEBUG(3,"ray_cs translate_frame 802\n");
1144 if (proto == 0xffff) { /* evil netware IPX 802.3 without LLC */
1145 DEBUG(3,"ray_cs translate_frame evil IPX\n");
1146 memcpy_toio((UCHAR *)&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1147 return 0 - ETH_HLEN;
1149 memcpy_toio((UCHAR *)&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1150 return 0 - ETH_HLEN;
1152 /* TBD do other frame types */
1153 } /* end translate_frame */
1154 /*===========================================================================*/
1155 void ray_build_header(ray_dev_t *local, struct tx_msg *ptx, UCHAR msg_type,
1156 unsigned char *data)
1158 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1159 /*** IEEE 802.11 Address field assignments *************
1160 addr_1 addr_2 addr_3
1161 AP destination AP(BSSID) source
1162 Infra Terminal AP terminal destination
1163 Adhoc destination terminal BSSID
1164 *******************************************************/
1165 if (local->net_type == ADHOC) {
1166 writeb(0, &ptx->mac.frame_ctl_2);
1167 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, 2 * ADDRLEN);
1168 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1170 else /* infrastructure */
1172 if (local->sparm.b4.a_acting_as_ap_status)
1174 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);;
1175 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, ADDRLEN);
1176 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1177 memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_source, ADDRLEN);
1179 else /* Terminal */
1181 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1182 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1183 memcpy_toio(ptx->mac.addr_2, ((struct ethhdr *)data)->h_source, ADDRLEN);
1184 memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_dest, ADDRLEN);
1187 } /* end encapsulate_frame */
1188 /*===========================================================================*/
1189 int ray_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1191 ray_dev_t *local = (ray_dev_t *)dev->priv;
1192 dev_link_t *link = local->finder;
1193 int err = 0;
1195 if (!(link->state & DEV_PRESENT)) {
1196 DEBUG(2,"ray_dev_ioctl - device not present\n");
1197 return -1;
1199 DEBUG(2,"ray_cs IOCTL dev=%p, ifr=%p, cmd = 0x%x\n",dev,ifr,cmd);
1200 /* Validate the command */
1201 switch (cmd)
1203 default:
1204 DEBUG(0,"ray_dev_ioctl cmd = 0x%x\n", cmd);
1205 err = -EOPNOTSUPP;
1207 return err;
1208 } /* end ray_dev_ioctl */
1209 /*===========================================================================*/
1210 int ray_open(struct net_device *dev)
1212 dev_link_t *link;
1213 ray_dev_t *local = (ray_dev_t *)dev->priv;
1215 DEBUG(1, "ray_open('%s')\n", dev->name);
1217 for (link = dev_list; link; link = link->next)
1218 if (link->priv == dev) break;
1219 if (!DEV_OK(link))
1220 return -ENODEV;
1222 if (link->open == 0) local->num_multi = 0;
1223 link->open++;
1224 MOD_INC_USE_COUNT;
1226 dev->interrupt = 0;
1227 if (sniffer) dev->tbusy = 1;
1228 else dev->tbusy = 0;
1229 dev->start = 1;
1231 DEBUG(2,"ray_open ending\n");
1232 return 0;
1233 } /* end ray_open */
1234 /*===========================================================================*/
1235 int ray_dev_close(struct net_device *dev)
1237 dev_link_t *link;
1239 DEBUG(1, "ray_dev_close('%s')\n", dev->name);
1241 for (link = dev_list; link; link = link->next)
1242 if (link->priv == dev) break;
1243 if (link == NULL)
1244 return -ENODEV;
1246 link->open--; dev->start = 0;
1247 if (link->state & DEV_STALE_CONFIG) {
1248 link->release.expires = jiffies + HZ/20;
1249 link->state |= DEV_RELEASE_PENDING;
1250 add_timer(&link->release);
1253 MOD_DEC_USE_COUNT;
1255 return 0;
1256 } /* end ray_dev_close */
1257 /*===========================================================================*/
1258 void ray_reset(struct net_device *dev) {
1259 DEBUG(1,"ray_reset entered\n");
1260 return;
1262 /*===========================================================================*/
1263 /* Cause a firmware interrupt if it is ready for one */
1264 /* Return nonzero if not ready */
1265 int interrupt_ecf(ray_dev_t *local, int ccs)
1267 int i = 50;
1268 dev_link_t *link = local->finder;
1270 if (!(link->state & DEV_PRESENT)) {
1271 DEBUG(2,"ray_cs interrupt_ecf - device not present\n");
1272 return -1;
1274 DEBUG(2,"interrupt_ecf(local=%p, ccs = 0x%x\n",local,ccs);
1276 while ( i &&
1277 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & ECF_INTR_SET))
1278 i--;
1279 if (i == 0) {
1280 DEBUG(2,"ray_cs interrupt_ecf card not ready for interrupt\n");
1281 return -1;
1283 /* Fill the mailbox, then kick the card */
1284 writeb(ccs, local->sram + SCB_BASE);
1285 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1286 return 0;
1287 } /* interrupt_ecf */
1288 /*===========================================================================*/
1289 /* Get next free transmit CCS */
1290 /* Return - index of current tx ccs */
1291 int get_free_tx_ccs(ray_dev_t *local)
1293 int i;
1294 struct ccs *pccs = (struct ccs *)(local->sram + CCS_BASE);
1295 dev_link_t *link = local->finder;
1297 if (!(link->state & DEV_PRESENT)) {
1298 DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n");
1299 return ECARDGONE;
1302 if (test_and_set_bit(0,&local->tx_ccs_lock)) {
1303 DEBUG(1,"ray_cs tx_ccs_lock busy\n");
1304 return ECCSBUSY;
1307 for (i=0; i < NUMBER_OF_TX_CCS; i++) {
1308 if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) {
1309 writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status);
1310 writeb(CCS_END_LIST, &(pccs+i)->link);
1311 local->tx_ccs_lock = 0;
1312 return i;
1315 local->tx_ccs_lock = 0;
1316 DEBUG(2,"ray_cs ERROR no free tx CCS for raylink card\n");
1317 return ECCSFULL;
1318 } /* get_free_tx_ccs */
1319 /*===========================================================================*/
1320 /* Get next free CCS */
1321 /* Return - index of current ccs */
1322 int get_free_ccs(ray_dev_t *local)
1324 int i;
1325 struct ccs *pccs = (struct ccs *)(local->sram + CCS_BASE);
1326 dev_link_t *link = local->finder;
1328 if (!(link->state & DEV_PRESENT)) {
1329 DEBUG(2,"ray_cs get_free_ccs - device not present\n");
1330 return ECARDGONE;
1332 if (test_and_set_bit(0,&local->ccs_lock)) {
1333 DEBUG(1,"ray_cs ccs_lock busy\n");
1334 return ECCSBUSY;
1337 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1338 if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) {
1339 writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status);
1340 writeb(CCS_END_LIST, &(pccs+i)->link);
1341 local->ccs_lock = 0;
1342 return i;
1345 local->ccs_lock = 0;
1346 DEBUG(1,"ray_cs ERROR no free CCS for raylink card\n");
1347 return ECCSFULL;
1348 } /* get_free_ccs */
1349 /*===========================================================================*/
1350 void authenticate_timeout(u_long data)
1352 ray_dev_t *local = (ray_dev_t *)data;
1353 del_timer(&local->timer);
1354 printk(KERN_INFO "ray_cs Authentication with access point failed"
1355 " - timeout\n");
1356 join_net((u_long)local);
1358 /*===========================================================================*/
1359 int asc_to_int(char a)
1361 if (a < '0') return -1;
1362 if (a <= '9') return (a - '0');
1363 if (a < 'A') return -1;
1364 if (a <= 'F') return (10 + a - 'A');
1365 if (a < 'a') return -1;
1366 if (a <= 'f') return (10 + a - 'a');
1367 return -1;
1369 /*===========================================================================*/
1370 int parse_addr(char *in_str, UCHAR *out)
1372 int len;
1373 int i,j,k;
1374 int status;
1376 if (in_str == NULL) return 0;
1377 if ((len = strlen(in_str)) < 2) return 0;
1378 memset(out, 0, ADDRLEN);
1380 status = 1;
1381 j = len - 1;
1382 if (j > 12) j = 12;
1383 i = 5;
1385 while (j > 0)
1387 if ((k = asc_to_int(in_str[j--])) != -1) out[i] = k;
1388 else return 0;
1390 if (j == 0) break;
1391 if ((k = asc_to_int(in_str[j--])) != -1) out[i] += k << 4;
1392 else return 0;
1393 if (!i--) break;
1395 return status;
1397 /*===========================================================================*/
1398 struct enet_statistics *ray_get_stats(struct net_device *dev)
1400 ray_dev_t *local = (ray_dev_t *)dev->priv;
1401 dev_link_t *link = local->finder;
1402 struct status *p = (struct status *)(local->sram + STATUS_BASE);
1403 if (!(link->state & DEV_PRESENT)) {
1404 DEBUG(2,"ray_cs enet_statistics - device not present\n");
1405 return &local->stats;
1407 if (readb(&p->mrx_overflow_for_host))
1409 local->stats.rx_over_errors += ntohs(readb(&p->mrx_overflow));
1410 writeb(0,&p->mrx_overflow);
1411 writeb(0,&p->mrx_overflow_for_host);
1413 if (readb(&p->mrx_checksum_error_for_host))
1415 local->stats.rx_crc_errors += ntohs(readb(&p->mrx_checksum_error));
1416 writeb(0,&p->mrx_checksum_error);
1417 writeb(0,&p->mrx_checksum_error_for_host);
1419 if (readb(&p->rx_hec_error_for_host))
1421 local->stats.rx_frame_errors += ntohs(readb(&p->rx_hec_error));
1422 writeb(0,&p->rx_hec_error);
1423 writeb(0,&p->rx_hec_error_for_host);
1425 return &local->stats;
1427 /*===========================================================================*/
1428 void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len)
1430 ray_dev_t *local = (ray_dev_t *)dev->priv;
1431 dev_link_t *link = local->finder;
1432 int ccsindex;
1433 int i;
1434 struct ccs *pccs;
1436 if (!(link->state & DEV_PRESENT)) {
1437 DEBUG(2,"ray_update_parm - device not present\n");
1438 return;
1441 if ((ccsindex = get_free_ccs(local)) < 0)
1443 DEBUG(0,"ray_update_parm - No free ccs\n");
1444 return;
1446 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
1447 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1448 writeb(objid, &pccs->var.update_param.object_id);
1449 writeb(1, &pccs->var.update_param.number_objects);
1450 writeb(0, &pccs->var.update_param.failure_cause);
1451 for (i=0; i<len; i++) {
1452 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1454 /* Interrupt the firmware to process the command */
1455 if (interrupt_ecf(local, ccsindex)) {
1456 DEBUG(0,"ray_cs associate failed - ECF not ready for intr\n");
1457 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1460 /*===========================================================================*/
1461 static void ray_update_multi_list(struct net_device *dev, int all)
1463 struct dev_mc_list *dmi, **dmip;
1464 int ccsindex;
1465 struct ccs *pccs;
1466 int i = 0;
1467 ray_dev_t *local = (ray_dev_t *)dev->priv;
1468 dev_link_t *link = local->finder;
1469 UCHAR *p = local->sram + HOST_TO_ECF_BASE;
1471 if (!(link->state & DEV_PRESENT)) {
1472 DEBUG(2,"ray_update_multi_list - device not present\n");
1473 return;
1475 else
1476 DEBUG(2,"ray_update_multi_list(%p)\n",dev);
1477 if ((ccsindex = get_free_ccs(local)) < 0)
1479 DEBUG(1,"ray_update_multi - No free ccs\n");
1480 return;
1482 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
1483 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
1485 if (all) {
1486 writeb(0xff, &pccs->var);
1487 local->num_multi = 0xff;
1489 else {
1490 /* Copy the kernel's list of MC addresses to card */
1491 for (dmip=&dev->mc_list; (dmi=*dmip)!=NULL; dmip=&dmi->next) {
1492 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
1493 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]);
1494 p += ETH_ALEN;
1495 i++;
1497 if (i > 256/ADDRLEN) i = 256/ADDRLEN;
1498 writeb((UCHAR)i, &pccs->var);
1499 DEBUG(1,"ray_cs update_multi %d addresses in list\n", i);
1500 /* Interrupt the firmware to process the command */
1501 local->num_multi = i;
1503 if (interrupt_ecf(local, ccsindex)) {
1504 DEBUG(1,"ray_cs update_multi failed - ECF not ready for intr\n");
1505 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1507 } /* end ray_update_multi_list */
1508 /*===========================================================================*/
1509 static void set_multicast_list(struct net_device *dev)
1511 ray_dev_t *local = (ray_dev_t *)dev->priv;
1512 UCHAR promisc;
1514 DEBUG(2,"ray_cs set_multicast_list(%p)\n",dev);
1516 if (dev->flags & IFF_PROMISC)
1518 if (local->sparm.b5.a_promiscuous_mode == 0) {
1519 DEBUG(1,"ray_cs set_multicast_list promisc on\n");
1520 local->sparm.b5.a_promiscuous_mode = 1;
1521 promisc = 1;
1522 ray_update_parm(dev, OBJID_promiscuous_mode, \
1523 &promisc, sizeof(promisc));
1526 else {
1527 if (local->sparm.b5.a_promiscuous_mode == 1) {
1528 DEBUG(1,"ray_cs set_multicast_list promisc off\n");
1529 local->sparm.b5.a_promiscuous_mode = 0;
1530 promisc = 0;
1531 ray_update_parm(dev, OBJID_promiscuous_mode, \
1532 &promisc, sizeof(promisc));
1536 if (dev->flags & IFF_ALLMULTI) ray_update_multi_list(dev, 1);
1537 else
1539 if (local->num_multi != dev->mc_count) ray_update_multi_list(dev, 0);
1541 } /* end set_multicast_list */
1542 /*=============================================================================
1543 * All routines below here are run at interrupt time.
1544 =============================================================================*/
1545 void ray_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1547 struct net_device *dev = (struct net_device *)dev_id;
1548 dev_link_t *link;
1549 ray_dev_t *local;
1550 struct ccs *pccs;
1551 struct rcs *prcs;
1552 UCHAR rcsindex;
1553 UCHAR tmp;
1554 UCHAR cmd;
1555 UCHAR status;
1557 if ((dev == NULL) || !dev->start)
1558 return;
1560 DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev);
1562 if (test_and_set_bit(0,&dev->interrupt)) {
1563 printk("ray_cs Reentering interrupt handler not allowed\n");
1564 return;
1567 local = (ray_dev_t *)dev->priv;
1568 link = (dev_link_t *)local->finder;
1569 if ( ! (link->state & DEV_PRESENT) || link->state & DEV_SUSPEND ) {
1570 DEBUG(2,"ray_cs interrupt from device not present or suspended.\n");
1571 return;
1573 rcsindex = readb(&((struct scb *)(local->sram))->rcs_index);
1575 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS))
1577 DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
1578 clear_interrupt(local);
1579 dev->interrupt = 0;
1580 return;
1582 if (rcsindex < NUMBER_OF_CCS) /* If it's a returned CCS */
1584 pccs = ((struct ccs *) (local->sram + CCS_BASE)) + rcsindex;
1585 cmd = readb(&pccs->cmd);
1586 status = readb(&pccs->buffer_status);
1587 switch (cmd)
1589 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1590 del_timer(&local->timer);
1591 if (status == CCS_COMMAND_COMPLETE) {
1592 DEBUG(1,"ray_cs interrupt download_startup_parameters OK\n");
1594 else {
1595 DEBUG(1,"ray_cs interrupt download_startup_parameters fail\n");
1597 break;
1598 case CCS_UPDATE_PARAMS:
1599 DEBUG(1,"ray_cs interrupt update params done\n");
1600 if (status != CCS_COMMAND_COMPLETE) {
1601 tmp = readb(&pccs->var.update_param.failure_cause);
1602 DEBUG(0,"ray_cs interrupt update params failed - reason %d\n",tmp);
1604 break;
1605 case CCS_REPORT_PARAMS:
1606 DEBUG(1,"ray_cs interrupt report params done\n");
1607 break;
1608 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
1609 DEBUG(1,"ray_cs interrupt CCS Update Multicast List done\n");
1610 break;
1611 case CCS_UPDATE_POWER_SAVINGS_MODE:
1612 DEBUG(1,"ray_cs interrupt update power save mode done\n");
1613 break;
1614 case CCS_START_NETWORK:
1615 case CCS_JOIN_NETWORK:
1616 if (status == CCS_COMMAND_COMPLETE) {
1617 if (readb(&pccs->var.start_network.net_initiated) == 1) {
1618 DEBUG(0,"ray_cs interrupt network \"%s\" started\n",\
1619 local->sparm.b4.a_current_ess_id);
1621 else {
1622 DEBUG(0,"ray_cs interrupt network \"%s\" joined\n",\
1623 local->sparm.b4.a_current_ess_id);
1625 memcpy_fromio(&local->bss_id,pccs->var.start_network.bssid,ADDRLEN);
1627 if (local->fw_ver == 0x55) local->net_default_tx_rate = 3;
1628 else local->net_default_tx_rate =
1629 readb(&pccs->var.start_network.net_default_tx_rate);
1630 local->encryption = readb(&pccs->var.start_network.encryption);
1631 if (!sniffer && (local->net_type == INFRA)
1632 && !(local->sparm.b4.a_acting_as_ap_status)) {
1633 authenticate(local);
1635 local->card_status = CARD_ACQ_COMPLETE;
1637 else {
1638 local->card_status = CARD_ACQ_FAILED;
1640 del_timer(&local->timer);
1641 local->timer.expires = jiffies + HZ*5;
1642 local->timer.data = (long)local;
1643 if (status == CCS_START_NETWORK) {
1644 DEBUG(0,"ray_cs interrupt network \"%s\" start failed\n",\
1645 local->sparm.b4.a_current_ess_id);
1646 local->timer.function = &start_net;
1648 else {
1649 DEBUG(0,"ray_cs interrupt network \"%s\" join failed\n",\
1650 local->sparm.b4.a_current_ess_id);
1651 local->timer.function = &join_net;
1653 add_timer(&local->timer);
1655 break;
1656 case CCS_START_ASSOCIATION:
1657 if (status == CCS_COMMAND_COMPLETE) {
1658 local->card_status = CARD_ASSOC_COMPLETE;
1659 DEBUG(0,"ray_cs association successful\n");
1661 else
1663 DEBUG(0,"ray_cs association failed,\n");
1664 local->card_status = CARD_ASSOC_FAILED;
1665 join_net((u_long)local);
1667 break;
1668 case CCS_TX_REQUEST:
1669 if (status == CCS_COMMAND_COMPLETE) {
1670 DEBUG(3,"ray_cs interrupt tx request complete\n");
1672 else {
1673 DEBUG(1,"ray_cs interrupt tx request failed\n");
1675 if (!sniffer) dev->tbusy = 0;
1676 mark_bh(NET_BH);
1677 break;
1678 case CCS_TEST_MEMORY:
1679 DEBUG(1,"ray_cs interrupt mem test done\n");
1680 break;
1681 case CCS_SHUTDOWN:
1682 DEBUG(1,"ray_cs interrupt Unexpected CCS returned - Shutdown\n");
1683 break;
1684 case CCS_DUMP_MEMORY:
1685 DEBUG(1,"ray_cs interrupt dump memory done\n");
1686 break;
1687 case CCS_START_TIMER:
1688 DEBUG(2,"ray_cs interrupt DING - raylink timer expired\n");
1689 break;
1690 default:
1691 DEBUG(1,"ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",\
1692 rcsindex, cmd);
1694 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1696 else /* It's an RCS */
1698 prcs = ((struct rcs *)(local->sram + CCS_BASE)) + rcsindex;
1700 switch (readb(&prcs->interrupt_id))
1702 case PROCESS_RX_PACKET:
1703 ray_rx(dev, local, prcs);
1704 break;
1705 case REJOIN_NET_COMPLETE:
1706 DEBUG(1,"ray_cs interrupt rejoin net complete\n");
1707 local->card_status = CARD_ACQ_COMPLETE;
1708 /* do we need to clear tx buffers CCS's? */
1709 if (local->sparm.b4.a_network_type == ADHOC) {
1710 if (!sniffer) dev->tbusy = 0;
1712 else {
1713 memcpy_fromio(&local->bss_id, prcs->var.rejoin_net_complete.bssid, ADDRLEN);
1714 DEBUG(1,"ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",\
1715 local->bss_id[0], local->bss_id[1], local->bss_id[2],\
1716 local->bss_id[3], local->bss_id[4], local->bss_id[5]);
1717 if (!sniffer) authenticate(local);
1719 break;
1720 case ROAMING_INITIATED:
1721 DEBUG(1,"ray_cs interrupt roaming initiated\n");
1722 dev->tbusy = 1;
1723 local->card_status = CARD_DOING_ACQ;
1724 break;
1725 case JAPAN_CALL_SIGN_RXD:
1726 DEBUG(1,"ray_cs interrupt japan call sign rx\n");
1727 break;
1728 default:
1729 DEBUG(1,"ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",\
1730 rcsindex, readb(&prcs->interrupt_id));
1731 break;
1733 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
1735 clear_interrupt(local);
1736 dev->interrupt = 0;
1737 } /* ray_interrupt */
1738 /*===========================================================================*/
1739 void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs *prcs)
1741 int rx_len;
1742 unsigned int pkt_addr;
1743 UCHAR *pmsg;
1744 DEBUG(4,"ray_rx process rx packet\n");
1746 /* Calculate address of packet within Rx buffer */
1747 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
1748 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
1749 /* Length of first packet fragment */
1750 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
1751 + readb(&prcs->var.rx_packet.rx_data_length[1]);
1753 pmsg = local->rmem + pkt_addr;
1754 switch(readb(pmsg))
1756 case DATA_TYPE:
1757 DEBUG(4,"ray_rx data type\n");
1758 rx_data(dev, prcs, pkt_addr, rx_len);
1759 break;
1760 case AUTHENTIC_TYPE:
1761 DEBUG(4,"ray_rx authentic type\n");
1762 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
1763 else rx_authenticate(local, prcs, pkt_addr, rx_len);
1764 break;
1765 case DEAUTHENTIC_TYPE:
1766 DEBUG(4,"ray_rx deauth type\n");
1767 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
1768 else rx_deauthenticate(local, prcs, pkt_addr, rx_len);
1769 break;
1770 case NULL_MSG_TYPE:
1771 DEBUG(3,"ray_cs rx NULL msg\n");
1772 break;
1773 case BEACON_TYPE:
1774 DEBUG(4,"ray_rx beacon type\n");
1775 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
1777 copy_from_rx_buff(local, (UCHAR *)&local->last_bcn, pkt_addr,
1778 rx_len < sizeof(struct beacon_rx) ?
1779 rx_len : sizeof(struct beacon_rx));
1781 /* Get the statistics so the card counters never overflow */
1782 ray_get_stats(dev);
1783 break;
1784 default:
1785 DEBUG(0,"ray_cs unknown pkt type %2x\n", readb(pmsg));
1786 break;
1789 } /* end ray_rx */
1790 /*===========================================================================*/
1791 void rx_data(struct net_device *dev, struct rcs *prcs, unsigned int pkt_addr,
1792 int rx_len)
1794 struct sk_buff *skb = NULL;
1795 struct rcs *prcslink = prcs;
1796 ray_dev_t *local = dev->priv;
1797 UCHAR *rx_ptr;
1798 int total_len;
1799 int tmp;
1801 if (!sniffer) {
1802 if (translate) {
1803 /* TBD length needs fixing for translated header */
1804 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
1805 rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))
1807 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
1808 return;
1811 else /* encapsulated ethernet */ {
1812 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
1813 rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))
1815 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
1816 return;
1820 DEBUG(4,"ray_cs rx_data packet\n");
1821 /* If fragmented packet, verify sizes of fragments add up */
1822 if (prcs->var.rx_packet.next_frag_rcs_index != 0xFF) {
1823 DEBUG(1,"ray_cs rx'ed fragment\n");
1824 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
1825 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
1826 total_len = tmp;
1827 prcslink = prcs;
1828 do {
1829 tmp -= (readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8)
1830 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
1831 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index) == 0xFF
1832 || tmp < 0) break;
1833 prcslink = ((struct rcs *)(local->sram + CCS_BASE))
1834 + readb(&prcslink->link_field);
1835 } while (1);
1837 if (tmp < 0)
1839 DEBUG(0,"ray_cs rx_data fragment lengths don't add up\n");
1840 local->stats.rx_dropped++;
1841 release_frag_chain(local, prcs);
1842 return;
1845 else { /* Single unfragmented packet */
1846 total_len = rx_len;
1849 skb = dev_alloc_skb( total_len+5 );
1850 if (skb == NULL)
1852 DEBUG(0,"ray_cs rx_data could not allocate skb\n");
1853 local->stats.rx_dropped++;
1854 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
1855 release_frag_chain(local, prcs);
1856 return;
1858 skb_reserve( skb, 2); /* Align IP on 16 byte (TBD check this)*/
1859 skb->dev = dev;
1861 DEBUG(4,"ray_cs rx_data total_len = %x, rx_len = %x\n",total_len,rx_len);
1863 /************************/
1864 /* Reserve enough room for the whole damn packet. */
1865 rx_ptr = skb_put( skb, total_len);
1866 /* Copy the whole packet to sk_buff */
1867 rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
1869 /* Now, deal with encapsulation/translation/sniffer */
1870 if (!sniffer) {
1871 if (!translate) {
1872 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
1873 /* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
1874 skb_pull( skb, RX_MAC_HEADER_LENGTH);
1876 else {
1877 /* Do translation */
1878 untranslate(local, skb, total_len);
1881 else
1882 { /* sniffer mode, so just pass whole packet */ };
1884 /************************/
1885 /* Now pick up the rest of the fragments if any */
1886 tmp = 17;
1887 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
1888 prcslink = prcs;
1889 DEBUG(1,"ray_cs rx_data in fragment loop\n");
1890 do {
1891 prcslink = ((struct rcs *)(local->sram + CCS_BASE))
1892 + readb(&prcslink->var.rx_packet.next_frag_rcs_index);
1893 rx_len = (( readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8)
1894 + readb(&prcslink->var.rx_packet.rx_data_length[1]))
1895 & RX_BUFF_END;
1896 pkt_addr = (( readb(&prcslink->var.rx_packet.rx_data_ptr[0]) << 8)
1897 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
1898 & RX_BUFF_END;
1900 rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
1902 } while (tmp-- &&
1903 readb(&prcslink->var.rx_packet.next_frag_rcs_index) != 0xFF);
1904 release_frag_chain(local, prcs);
1907 skb->protocol = eth_type_trans(skb,dev);
1908 netif_rx(skb);
1910 local->stats.rx_packets++;
1911 local->stats.rx_bytes += skb->len;
1912 } /* end rx_data */
1913 /*===========================================================================*/
1914 void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
1916 snaphdr_t *psnap = (snaphdr_t *)(skb->data + RX_MAC_HEADER_LENGTH);
1917 struct mac_header *pmac = (struct mac_header *)skb->data;
1918 unsigned short type = *(unsigned short *)psnap->ethertype;
1919 unsigned int xsap = *(unsigned int *)psnap & 0x00ffffff;
1920 unsigned int org = (*(unsigned int *)psnap->org) & 0x00ffffff;
1921 int delta;
1922 struct ethhdr *peth;
1923 UCHAR srcaddr[ADDRLEN];
1924 UCHAR destaddr[ADDRLEN];
1926 if (local->sparm.b5.a_acting_as_ap_status != TYPE_STA)
1927 memcpy(destaddr, pmac->addr_3, ADDRLEN);
1928 else
1929 memcpy(destaddr, pmac->addr_1, ADDRLEN);
1930 memcpy(srcaddr, pmac->addr_2, ADDRLEN);
1932 #ifdef PCMCIA_DEBUG
1933 if (pc_debug > 3) {
1934 int i;
1935 printk(KERN_DEBUG "skb->data before untranslate");
1936 for (i=0;i<64;i++)
1937 printk("%02x ",skb->data[i]);
1938 printk("\n" KERN_DEBUG "type = %08x, xsap = %08x, org = %08x\n",
1939 type,xsap,org);
1940 printk(KERN_DEBUG "untranslate skb->data = %p\n",skb->data);
1942 #endif
1944 if ( xsap != SNAP_ID) {
1945 /* not a snap type so leave it alone */
1946 DEBUG(3,"ray_cs untranslate NOT SNAP %x\n", *(unsigned int *)psnap & 0x00ffffff);
1948 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
1949 peth = (struct ethhdr *)(skb->data + delta);
1950 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
1952 else { /* Its a SNAP */
1953 if (org == BRIDGE_ENCAP) { /* EtherII and nuke the LLC */
1954 DEBUG(3,"ray_cs untranslate Bridge encap\n");
1955 delta = RX_MAC_HEADER_LENGTH
1956 + sizeof(struct snaphdr_t) - ETH_HLEN;
1957 peth = (struct ethhdr *)(skb->data + delta);
1958 peth->h_proto = type;
1960 else {
1961 if (org == RFC1042_ENCAP) {
1962 switch (type) {
1963 case RAY_IPX_TYPE:
1964 case APPLEARP_TYPE:
1965 DEBUG(3,"ray_cs untranslate RFC IPX/AARP\n");
1966 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
1967 peth = (struct ethhdr *)(skb->data + delta);
1968 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
1969 break;
1970 default:
1971 DEBUG(3,"ray_cs untranslate RFC default\n");
1972 delta = RX_MAC_HEADER_LENGTH +
1973 sizeof(struct snaphdr_t) - ETH_HLEN;
1974 peth = (struct ethhdr *)(skb->data + delta);
1975 peth->h_proto = type;
1976 break;
1979 else {
1980 printk("ray_cs untranslate very confused by packet\n");
1981 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
1982 peth = (struct ethhdr *)(skb->data + delta);
1983 peth->h_proto = type;
1987 /* TBD reserve skb_reserve(skb, delta); */
1988 skb_pull(skb, delta);
1989 DEBUG(3,"untranslate after skb_pull(%d), skb->data = %p\n",delta,skb->data);
1990 memcpy(peth->h_dest, destaddr, ADDRLEN);
1991 memcpy(peth->h_source, srcaddr, ADDRLEN);
1992 #ifdef PCMCIA_DEBUG
1993 if (pc_debug > 3) {
1994 int i;
1995 printk(KERN_DEBUG "skb->data after untranslate:");
1996 for (i=0;i<64;i++)
1997 printk("%02x ",skb->data[i]);
1998 printk("\n");
2000 #endif
2001 } /* end untranslate */
2002 /*===========================================================================*/
2003 /* Copy data from circular receive buffer to PC memory.
2004 * dest = destination address in PC memory
2005 * pkt_addr = source address in receive buffer
2006 * len = length of packet to copy
2008 int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int length)
2010 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2011 if (wrap_bytes <= 0)
2013 memcpy_fromio(dest,local->rmem + pkt_addr,length);
2015 else /* Packet wrapped in circular buffer */
2017 memcpy_fromio(dest,local->rmem+pkt_addr,length - wrap_bytes);
2018 memcpy_fromio(dest + length - wrap_bytes, local->rmem, wrap_bytes);
2020 return length;
2022 /*===========================================================================*/
2023 void release_frag_chain(ray_dev_t *local, struct rcs* prcs)
2025 struct rcs *prcslink = prcs;
2026 int tmp = 17;
2027 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2029 while (tmp--) {
2030 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2031 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
2032 DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
2033 break;
2035 prcslink = ((struct rcs *)(local->sram + CCS_BASE)) + rcsindex;
2036 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2038 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2040 /*===========================================================================*/
2041 void authenticate(ray_dev_t *local)
2043 dev_link_t *link = local->finder;
2044 DEBUG(0,"ray_cs Starting authentication.\n");
2045 if (!(link->state & DEV_PRESENT)) {
2046 DEBUG(2,"ray_cs authenticate - device not present\n");
2047 return;
2050 del_timer(&local->timer);
2051 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2052 local->timer.function = &join_net;
2054 else {
2055 local->timer.function = &authenticate_timeout;
2057 local->timer.expires = jiffies + HZ*2;
2058 local->timer.data = (long)local;
2059 add_timer(&local->timer);
2060 local->authentication_state = AWAITING_RESPONSE;
2061 } /* end authenticate */
2062 /*===========================================================================*/
2063 void rx_authenticate(ray_dev_t *local, struct rcs *prcs,
2064 unsigned int pkt_addr, int rx_len)
2066 UCHAR buff[256];
2067 struct rx_msg *msg = (struct rx_msg *)buff;
2069 del_timer(&local->timer);
2071 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2072 /* if we are trying to get authenticated */
2073 if (local->sparm.b4.a_network_type == ADHOC) {
2074 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]);
2075 if (msg->var[2] == 1) {
2076 DEBUG(0,"ray_cs Sending authentication response.\n");
2077 if (!build_auth_frame (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2078 local->authentication_state = NEED_TO_AUTH;
2079 memcpy(local->auth_id, msg->mac.addr_2, ADDRLEN);
2083 else /* Infrastructure network */
2085 if (local->authentication_state == AWAITING_RESPONSE) {
2086 /* Verify authentication sequence #2 and success */
2087 if (msg->var[2] == 2) {
2088 if ((msg->var[3] | msg->var[4]) == 0) {
2089 DEBUG(1,"Authentication successful\n");
2090 local->card_status = CARD_AUTH_COMPLETE;
2091 associate(local);
2092 local->authentication_state = AUTHENTICATED;
2094 else {
2095 DEBUG(0,"Authentication refused\n");
2096 local->card_status = CARD_AUTH_REFUSED;
2097 join_net((u_long)local);
2098 local->authentication_state = UNAUTHENTICATED;
2104 } /* end rx_authenticate */
2105 /*===========================================================================*/
2106 void associate(ray_dev_t *local)
2108 struct ccs *pccs;
2109 dev_link_t *link = local->finder;
2110 struct net_device *dev = link->priv;
2111 int ccsindex;
2112 if (!(link->state & DEV_PRESENT)) {
2113 DEBUG(2,"ray_cs associate - device not present\n");
2114 return;
2116 /* If no tx buffers available, return*/
2117 if ((ccsindex = get_free_ccs(local)) < 0)
2119 /* TBD should never be here but... what if we are? */
2120 DEBUG(1,"ray_cs associate - No free ccs\n");
2121 return;
2123 DEBUG(1,"ray_cs Starting association with access point\n");
2124 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
2125 /* fill in the CCS */
2126 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2127 /* Interrupt the firmware to process the command */
2128 if (interrupt_ecf(local, ccsindex)) {
2129 DEBUG(1,"ray_cs associate failed - ECF not ready for intr\n");
2130 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2132 del_timer(&local->timer);
2133 local->timer.expires = jiffies + HZ*2;
2134 local->timer.data = (long)local;
2135 local->timer.function = &join_net;
2136 add_timer(&local->timer);
2137 local->card_status = CARD_ASSOC_FAILED;
2138 return;
2140 if (!sniffer) dev->tbusy = 0;
2142 } /* end associate */
2143 /*===========================================================================*/
2144 void rx_deauthenticate(ray_dev_t *local, struct rcs *prcs,
2145 unsigned int pkt_addr, int rx_len)
2147 /* UCHAR buff[256];
2148 struct rx_msg *msg = (struct rx_msg *)buff;
2150 DEBUG(0,"Deauthentication frame received\n");
2151 local->authentication_state = UNAUTHENTICATED;
2152 /* Need to reauthenticate or rejoin depending on reason code */
2153 /* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2156 /*===========================================================================*/
2157 void clear_interrupt(ray_dev_t *local)
2159 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
2161 /*===========================================================================*/
2162 #ifdef CONFIG_PROC_FS
2163 #define MAXDATA (PAGE_SIZE - 80)
2165 static char *card_status[] = {
2166 "Card inserted - uninitialized", /* 0 */
2167 "Card not downloaded", /* 1 */
2168 "Waiting for download parameters", /* 2 */
2169 "Card doing acquisition", /* 3 */
2170 "Acquisition complete", /* 4 */
2171 "Authentication complete", /* 5 */
2172 "Association complete", /* 6 */
2173 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2174 "Card init error", /* 11 */
2175 "Download parameters error", /* 12 */
2176 "???", /* 13 */
2177 "Acquisition failed", /* 14 */
2178 "Authentication refused", /* 15 */
2179 "Association failed" /* 16 */
2182 static char *nettype[] = {"Adhoc", "Infra "};
2183 static char *framing[] = {"Encapsulation", "Translation"}
2185 /*===========================================================================*/
2186 int ray_cs_proc_read(char *buf, char **start, off_t offset,
2187 int len, int unused)
2189 /* Print current values which are not available via other means
2190 * eg ifconfig
2192 int i;
2193 dev_link_t *link = dev_list;
2194 struct net_device *dev = (struct net_device *)link->priv;
2195 ray_dev_t *local = (ray_dev_t *)dev->priv;
2196 UCHAR *p;
2197 struct freq_hop_element *pfh;
2198 UCHAR c[33];
2200 len = 0;
2202 len += sprintf(buf + len, "Raylink Wireless LAN driver status\n");
2203 len += sprintf(buf + len, "%s\n", rcsid);
2204 /* build 4 does not report version, and field is 0x55 after memtest */
2205 len += sprintf(buf + len, "Firmware version = ");
2206 if (local->fw_ver == 0x55)
2207 len += sprintf(buf + len, "4 - Use dump_cis for more details\n");
2208 else
2209 len += sprintf(buf + len, "%2d.%02d.%02d\n",
2210 local->fw_ver, local->fw_bld, local->fw_var);
2212 for (i=0; i<32; i++) c[i] = local->sparm.b5.a_current_ess_id[i];
2213 c[32] = 0;
2214 len += sprintf(buf + len, "%s network ESSID = \"%s\"\n",
2215 nettype[local->sparm.b5.a_network_type], c);
2217 p = local->bss_id;
2218 len += sprintf(buf + len,
2219 "BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
2220 p[0],p[1],p[2],p[3],p[4],p[5]);
2222 len += sprintf(buf + len, "Country code = %d\n",
2223 local->sparm.b5.a_curr_country_code);
2225 i = local->card_status;
2226 if (i < 0) i = 10;
2227 if (i > 16) i = 10;
2228 len += sprintf(buf + len, "Card status = %s\n", card_status[i]);
2230 len += sprintf(buf + len, "Framing mode = %s\n",framing[translate]);
2232 /* Pull some fields out of last beacon received */
2233 len += sprintf(buf + len, "Beacon Interval = %d Kus\n",
2234 local->last_bcn.beacon_intvl[0]
2235 + 256 * local->last_bcn.beacon_intvl[1]);
2237 p = local->last_bcn.elements;
2238 if (p[0] == C_ESSID_ELEMENT_ID) p += p[1] + 2;
2239 else {
2240 len += sprintf(buf + len, "Parse beacon failed at essid element id = %d\n",p[0]);
2241 return len;
2244 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2245 len += sprintf(buf + len, "Supported rate codes = ");
2246 for (i=2; i<p[1] + 2; i++)
2247 len += sprintf(buf + len, "0x%02x ", p[i]);
2248 len += sprintf(buf + len, "\n");
2249 p += p[1] + 2;
2251 else {
2252 len += sprintf(buf + len, "Parse beacon failed at rates element\n");
2253 return len;
2256 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2257 pfh = (struct freq_hop_element *)p;
2258 len += sprintf(buf + len, "Hop dwell = %d Kus\n",
2259 pfh->dwell_time[0] + 256 * pfh->dwell_time[1]);
2260 len += sprintf(buf + len, "Hop set = %d \n", pfh->hop_set);
2261 len += sprintf(buf + len, "Hop pattern = %d \n", pfh->hop_pattern);
2262 len += sprintf(buf + len, "Hop index = %d \n", pfh->hop_index);
2263 p += p[1] + 2;
2265 else {
2266 len += sprintf(buf + len, "Parse beacon failed at FH param element\n");
2267 return len;
2269 return len;
2272 #endif
2273 /*===========================================================================*/
2274 int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2276 int addr;
2277 struct ccs *pccs;
2278 struct tx_msg *ptx;
2279 int ccsindex;
2281 /* If no tx buffers available, return */
2282 if ((ccsindex = get_free_tx_ccs(local)) < 0)
2284 DEBUG(1,"ray_cs send authenticate - No free tx ccs\n");
2285 return -1;
2288 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
2290 /* Address in card space */
2291 addr = TX_BUF_BASE + (ccsindex << 11);
2292 /* fill in the CCS */
2293 writeb(CCS_TX_REQUEST, &pccs->cmd);
2294 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2295 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2296 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2297 writeb(TX_AUTHENTICATE_LENGTH_LSB,pccs->var.tx_request.tx_data_length + 1);
2298 writeb(0, &pccs->var.tx_request.pow_sav_mode);
2300 ptx = (struct tx_msg *)(local->sram + addr);
2301 /* fill in the mac header */
2302 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2303 writeb(0, &ptx->mac.frame_ctl_2);
2305 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2306 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2307 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
2309 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2310 memset_io(ptx->var, 0, 6);
2311 writeb(auth_type & 0xff, ptx->var + 2);
2313 /* Interrupt the firmware to process the command */
2314 if (interrupt_ecf(local, ccsindex)) {
2315 DEBUG(1,"ray_cs send authentication request failed - ECF not ready for intr\n");
2316 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2317 return -1;
2319 return 0;
2320 } /* End build_auth_frame */
2321 /*===========================================================================*/
2322 static int __init init_ray_cs(void)
2324 int rc;
2325 servinfo_t serv;
2327 DEBUG(1, "%s\n", rcsid);
2328 CardServices(GetCardServicesInfo, &serv);
2329 if (serv.Revision != CS_RELEASE_CODE) {
2330 printk(KERN_NOTICE "ray: Card Services release does not match!\n");
2331 return -1;
2333 rc = register_pcmcia_driver(&dev_info, &ray_attach, &ray_detach);
2334 DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n",rc);
2335 #ifdef CONFIG_PROC_FS
2336 proc_register(&proc_root, &ray_cs_proc_entry);
2337 #endif
2338 if (translate != 0) translate = 1;
2339 return 0;
2340 } /* init_ray_cs */
2342 #ifndef MODULE
2344 static char init_ess_id[ESSID_SIZE];
2345 static int __init essid_setup(char *str)
2347 strncpy(init_ess_id, str, ESSID_SIZE);
2348 essid = init_ess_id;
2349 return 1;
2351 __setup("essid=", essid_setup);
2353 #endif
2355 /*===========================================================================*/
2357 static void __exit exit_ray_cs(void)
2359 DEBUG(0, "ray_cs: cleanup_module\n");
2361 unregister_pcmcia_driver(&dev_info);
2362 while (dev_list != NULL) {
2363 if (dev_list->state & DEV_CONFIG) ray_release((u_long)dev_list);
2364 ray_detach(dev_list);
2366 #ifdef CONFIG_PROC_FS
2367 proc_unregister(&proc_root, ray_cs_proc_entry.low_ino);
2368 #endif
2369 } /* exit_ray_cs */
2371 module_init(init_ray_cs);
2372 module_exit(exit_ray_cs);
2374 /*===========================================================================*/