Merge with Linux 2.4.0-test6-pre2.
[linux-2.6/linux-mips.git] / drivers / net / pcmcia / ray_cs.c
blob36b11f907e049a78208125758cad24bfc4694215
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/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/proc_fs.h>
30 #include <linux/ptrace.h>
31 #include <linux/malloc.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/init.h>
36 #include <asm/io.h>
37 #include <asm/system.h>
38 #include <asm/byteorder.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.h>
42 #include <linux/if_arp.h>
43 #include <linux/ioport.h>
44 #include <linux/skbuff.h>
46 #include <pcmcia/version.h>
47 #include <pcmcia/cs_types.h>
48 #include <pcmcia/cs.h>
49 #include <pcmcia/cistpl.h>
50 #include <pcmcia/cisreg.h>
51 #include <pcmcia/ds.h>
52 #include <pcmcia/mem_op.h>
54 #ifdef CONFIG_NET_PCMCIA_RADIO
55 #include <linux/wireless.h>
57 /* Warning : these stuff will slow down the driver... */
58 #define WIRELESS_SPY /* Enable spying addresses */
59 /* Definitions we need for spy */
60 typedef struct iw_statistics iw_stats;
61 typedef struct iw_quality iw_qual;
62 typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
63 #endif /* CONFIG_NET_PCMCIA_RADIO */
65 #include "rayctl.h"
66 #include "ray_cs.h"
68 /* All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
69 you do not define PCMCIA_DEBUG at all, all the debug code will be
70 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
71 be present but disabled -- but it can then be enabled for specific
72 modules at load time with a 'pc_debug=#' option to insmod.
75 #ifdef RAYLINK_DEBUG
76 #define PCMCIA_DEBUG RAYLINK_DEBUG
77 #endif
78 #ifdef PCMCIA_DEBUG
79 static int ray_debug = 0;
80 static int pc_debug = PCMCIA_DEBUG;
81 MODULE_PARM(pc_debug, "i");
82 /* #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); */
83 #define DEBUG(n, args...) if (pc_debug>(n)) printk(args);
84 #else
85 #define DEBUG(n, args...)
86 #endif
87 /** Prototypes based on PCMCIA skeleton driver *******************************/
88 static void ray_config(dev_link_t *link);
89 static void ray_release(u_long arg);
90 static int ray_event(event_t event, int priority, event_callback_args_t *args);
91 static dev_link_t *ray_attach(void);
92 static void ray_detach(dev_link_t *);
94 /***** Prototypes indicated by device structure ******************************/
95 static int ray_dev_close(struct net_device *dev);
96 static int ray_dev_config(struct net_device *dev, struct ifmap *map);
97 static struct net_device_stats *ray_get_stats(struct net_device *dev);
98 static int ray_dev_init(struct net_device *dev);
99 static int ray_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
100 static int ray_open(struct net_device *dev);
101 static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev);
102 static void set_multicast_list(struct net_device *dev);
103 static void ray_update_multi_list(struct net_device *dev, int all);
104 static int translate_frame(ray_dev_t *local, struct tx_msg *ptx,
105 unsigned char *data, int len);
106 static void ray_build_header(ray_dev_t *local, struct tx_msg *ptx, UCHAR msg_type,
107 unsigned char *data);
108 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
109 #if WIRELESS_EXT > 7 /* If wireless extension exist in the kernel */
110 static iw_stats * ray_get_wireless_stats(struct net_device * dev);
111 #endif /* WIRELESS_EXT > 7 */
113 /***** Prototypes for raylink functions **************************************/
114 static int asc_to_int(char a);
115 static void authenticate(ray_dev_t *local);
116 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
117 static void authenticate_timeout(u_long);
118 static int get_free_ccs(ray_dev_t *local);
119 static int get_free_tx_ccs(ray_dev_t *local);
120 static void init_startup_params(ray_dev_t *local);
121 static int parse_addr(char *in_str, UCHAR *out);
122 static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev, UCHAR type);
123 static int ray_init(struct net_device *dev);
124 static int interrupt_ecf(ray_dev_t *local, int ccs);
125 static void ray_reset(struct net_device *dev);
126 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
127 static void verify_dl_startup(u_long);
129 /* Prototypes for interrpt time functions **********************************/
130 static void ray_interrupt (int reg, void *dev_id, struct pt_regs *regs);
131 static void clear_interrupt(ray_dev_t *local);
132 static void rx_deauthenticate(ray_dev_t *local, struct rcs *prcs,
133 unsigned int pkt_addr, int rx_len);
134 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
135 static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs *prcs);
136 static void release_frag_chain(ray_dev_t *local, struct rcs *prcs);
137 static void rx_authenticate(ray_dev_t *local, struct rcs *prcs,
138 unsigned int pkt_addr, int rx_len);
139 static void rx_data(struct net_device *dev, struct rcs *prcs, unsigned int pkt_addr,
140 int rx_len);
141 static void associate(ray_dev_t *local);
143 /* Card command functions */
144 static int dl_startup_params(struct net_device *dev);
145 static void join_net(u_long local);
146 static void start_net(u_long local);
147 /* void start_net(ray_dev_t *local); */
149 /* Create symbol table for registering with kernel in init_module */
150 EXPORT_SYMBOL(ray_dev_ioctl);
151 EXPORT_SYMBOL(ray_rx);
153 /*===========================================================================*/
154 /* Parameters that can be set with 'insmod' */
155 /* Bit map of interrupts to choose from */
156 /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
157 static u_long irq_mask = 0xdeb8;
159 /* ADHOC=0, Infrastructure=1 */
160 static int net_type = ADHOC;
162 /* Hop dwell time in Kus (1024 us units defined by 802.11) */
163 static int hop_dwell = 128;
165 /* Beacon period in Kus */
166 static int beacon_period = 256;
168 /* power save mode (0 = off, 1 = save power) */
169 static int psm = 0;
171 /* String for network's Extended Service Set ID. 32 Characters max */
172 static char *essid = NULL;
174 /* Default to encapsulation unless translation requested */
175 static int translate = 1;
177 static int country = USA;
179 static int sniffer = 0;
181 static int bc = 0;
183 /* 48 bit physical card address if overriding card's real physical
184 * address is required. Since IEEE 802.11 addresses are 48 bits
185 * like ethernet, an int can't be used, so a string is used. To
186 * allow use of addresses starting with a decimal digit, the first
187 * character must be a letter and will be ignored. This letter is
188 * followed by up to 12 hex digits which are the address. If less
189 * than 12 digits are used, the address will be left filled with 0's.
190 * Note that bit 0 of the first byte is the broadcast bit, and evil
191 * things will happen if it is not 0 in a card address.
193 static char *phy_addr = NULL;
196 /* The dev_info variable is the "key" that is used to match up this
197 device driver with appropriate cards, through the card configuration
198 database.
200 static dev_info_t dev_info = "ray_cs";
202 /* A linked list of "instances" of the ray device. Each actual
203 PCMCIA card corresponds to one device instance, and is described
204 by one dev_link_t structure (defined in ds.h).
206 static dev_link_t *dev_list = NULL;
208 /* A dev_link_t structure has fields for most things that are needed
209 to keep track of a socket, but there will usually be some device
210 specific information that also needs to be kept track of. The
211 'priv' pointer in a dev_link_t structure can be used to point to
212 a device-specific private data structure, like this.
214 static unsigned int ray_mem_speed = 500;
216 MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
217 MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
218 MODULE_PARM(irq_mask,"i");
219 MODULE_PARM(net_type,"i");
220 MODULE_PARM(hop_dwell,"i");
221 MODULE_PARM(beacon_period,"i");
222 MODULE_PARM(psm,"i");
223 MODULE_PARM(essid,"s");
224 MODULE_PARM(translate,"i");
225 MODULE_PARM(country,"i");
226 MODULE_PARM(sniffer,"i");
227 MODULE_PARM(bc,"i");
228 MODULE_PARM(phy_addr,"s");
229 MODULE_PARM(ray_mem_speed, "i");
231 static UCHAR b5_default_startup_parms[] = {
232 0, 0, /* Adhoc station */
233 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
234 0, 0, 0, 0, 0, 0, 0, 0,
235 0, 0, 0, 0, 0, 0, 0, 0,
236 0, 0, 0, 0, 0, 0, 0, 0,
237 1, 0, /* Active scan, CA Mode */
238 0, 0, 0, 0, 0, 0, /* No default MAC addr */
239 0x7f, 0xff, /* Frag threshold */
240 0x00, 0x80, /* Hop time 128 Kus*/
241 0x01, 0x00, /* Beacon period 256 Kus */
242 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
243 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
244 0x7f, 0xff, /* RTS threshold */
245 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
246 0x05, /* assoc resp timeout thresh */
247 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max*/
248 0, /* Promiscuous mode */
249 0x0c, 0x0bd, /* Unique word */
250 0x32, /* Slot time */
251 0xff, 0xff, /* roam-low snr, low snr count */
252 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
253 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
254 /* b4 - b5 differences start here */
255 0x00, 0x3f, /* CW max */
256 0x00, 0x0f, /* CW min */
257 0x04, 0x08, /* Noise gain, limit offset */
258 0x28, 0x28, /* det rssi, med busy offsets */
259 7, /* det sync thresh */
260 0, 2, 2, /* test mode, min, max */
261 0, /* allow broadcast SSID probe resp */
262 0, 0, /* privacy must start, can join */
263 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
266 static UCHAR b4_default_startup_parms[] = {
267 0, 0, /* Adhoc station */
268 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
269 0, 0, 0, 0, 0, 0, 0, 0,
270 0, 0, 0, 0, 0, 0, 0, 0,
271 0, 0, 0, 0, 0, 0, 0, 0,
272 1, 0, /* Active scan, CA Mode */
273 0, 0, 0, 0, 0, 0, /* No default MAC addr */
274 0x7f, 0xff, /* Frag threshold */
275 0x02, 0x00, /* Hop time */
276 0x00, 0x01, /* Beacon period */
277 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
278 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
279 0x7f, 0xff, /* RTS threshold */
280 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
281 0x05, /* assoc resp timeout thresh */
282 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max*/
283 0, /* Promiscuous mode */
284 0x0c, 0x0bd, /* Unique word */
285 0x4e, /* Slot time (TBD seems wrong)*/
286 0xff, 0xff, /* roam-low snr, low snr count */
287 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
288 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
289 /* b4 - b5 differences start here */
290 0x3f, 0x0f, /* CW max, min */
291 0x04, 0x08, /* Noise gain, limit offset */
292 0x28, 0x28, /* det rssi, med busy offsets */
293 7, /* det sync thresh */
294 0, 2, 2 /* test mode, min, max*/
296 /*===========================================================================*/
297 static unsigned char eth2_llc[] = {0xaa, 0xaa, 3, 0, 0, 0};
299 static char hop_pattern_length[] = { 1,
300 USA_HOP_MOD, EUROPE_HOP_MOD,
301 JAPAN_HOP_MOD, KOREA_HOP_MOD,
302 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
303 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
304 JAPAN_TEST_HOP_MOD
307 static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
309 /*===========================================================================*/
310 static void cs_error(client_handle_t handle, int func, int ret)
312 error_info_t err = { func, ret };
313 pcmcia_report_error(handle, &err);
316 /*=============================================================================
317 ray_attach() creates an "instance" of the driver, allocating
318 local data structures for one device. The device is registered
319 with Card Services.
320 The dev_link structure is initialized, but we don't actually
321 configure the card at this point -- we wait until we receive a
322 card insertion event.
323 =============================================================================*/
324 static dev_link_t *ray_attach(void)
326 client_reg_t client_reg;
327 dev_link_t *link;
328 ray_dev_t *local;
329 int ret;
330 struct net_device *dev;
332 DEBUG(1, "ray_attach()\n");
334 /* Initialize the dev_link_t structure */
335 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
336 memset(link, 0, sizeof(struct dev_link_t));
337 link->release.function = &ray_release;
338 link->release.data = (u_long)link;
340 /* The io structure describes IO port mapping. None used here */
341 link->io.NumPorts1 = 0;
342 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
343 link->io.IOAddrLines = 5;
345 /* Interrupt setup. For PCMCIA, driver takes what's given */
346 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
347 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
348 link->irq.IRQInfo2 = irq_mask;
349 link->irq.Handler = &ray_interrupt;
351 /* General socket configuration */
352 link->conf.Attributes = CONF_ENABLE_IRQ;
353 link->conf.Vcc = 50;
354 link->conf.IntType = INT_MEMORY_AND_IO;
355 link->conf.ConfigIndex = 1;
356 link->conf.Present = PRESENT_OPTION;
358 /* Allocate space for private device-specific data */
359 dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
360 memset(dev, 0, sizeof(struct net_device));
361 link->priv = dev;
362 link->irq.Instance = dev;
364 local = kmalloc(sizeof(ray_dev_t), GFP_KERNEL);
365 memset(local, 0, sizeof(ray_dev_t));
366 dev->priv = local;
367 local->finder = link;
368 link->dev = &local->node;
369 local->card_status = CARD_INSERTED;
370 local->authentication_state = UNAUTHENTICATED;
371 local->num_multi = 0;
372 DEBUG(2,"ray_attach link = %p, dev = %p, local = %p, intr = %p\n",
373 link,dev,local,&ray_interrupt);
375 /* Raylink entries in the device structure */
376 dev->hard_start_xmit = &ray_dev_start_xmit;
377 dev->set_config = &ray_dev_config;
378 dev->get_stats = &ray_get_stats;
379 dev->do_ioctl = &ray_dev_ioctl;
380 #if WIRELESS_EXT > 7 /* If wireless extension exist in the kernel */
381 dev->get_wireless_stats = ray_get_wireless_stats;
382 #endif
384 dev->set_multicast_list = &set_multicast_list;
386 DEBUG(2,"ray_cs ray_attach calling ether_setup.)\n");
387 ether_setup(dev);
388 strcpy(dev->name, local->node.dev_name);
389 dev->init = &ray_dev_init;
390 dev->open = &ray_open;
391 dev->stop = &ray_dev_close;
392 netif_stop_queue(dev);
394 /* Register with Card Services */
395 link->next = dev_list;
396 dev_list = link;
397 client_reg.dev_info = &dev_info;
398 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
399 client_reg.EventMask =
400 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
401 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
402 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
403 client_reg.event_handler = &ray_event;
404 client_reg.Version = 0x0210;
405 client_reg.event_callback_args.client_data = link;
407 DEBUG(2,"ray_cs ray_attach calling CardServices(RegisterClient...)\n");
409 init_timer(&local->timer);
411 ret = pcmcia_register_client(&link->handle, &client_reg);
412 if (ret != 0) {
413 printk("ray_cs ray_attach RegisterClient unhappy - detaching\n");
414 cs_error(link->handle, RegisterClient, ret);
415 ray_detach(link);
416 return NULL;
418 DEBUG(2,"ray_cs ray_attach ending\n");
419 return link;
420 } /* ray_attach */
421 /*=============================================================================
422 This deletes a driver "instance". The device is de-registered
423 with Card Services. If it has been released, all local data
424 structures are freed. Otherwise, the structures will be freed
425 when the device is released.
426 =============================================================================*/
427 static void ray_detach(dev_link_t *link)
429 dev_link_t **linkp;
430 struct net_device *dev;
431 long flags;
433 DEBUG(1, "ray_detach(0x%p)\n", link);
435 /* Locate device structure */
436 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
437 if (*linkp == link) break;
438 if (*linkp == NULL)
439 return;
441 save_flags(flags);
442 cli();
443 if (link->state & DEV_RELEASE_PENDING) {
444 del_timer(&link->release);
445 link->state &= ~DEV_RELEASE_PENDING;
447 restore_flags(flags);
449 /* If the device is currently configured and active, we won't
450 actually delete it yet. Instead, it is marked so that when
451 the release() function is called, that will trigger a proper
452 detach().
454 if (link->state & DEV_CONFIG) {
455 ray_release((u_long)link);
456 if(link->state & DEV_STALE_CONFIG) {
457 link->state |= DEV_STALE_LINK;
458 return;
462 /* Break the link with Card Services */
463 if (link->handle)
464 pcmcia_deregister_client(link->handle);
466 /* Unlink device structure, free pieces */
467 *linkp = link->next;
468 if (link->priv) {
469 dev = link->priv;
470 if (dev->priv)
471 kfree(dev->priv);
473 kfree(link->priv);
475 kfree(link);
476 DEBUG(2,"ray_cs ray_detach ending\n");
477 } /* ray_detach */
478 /*=============================================================================
479 ray_config() is run after a CARD_INSERTION event
480 is received, to configure the PCMCIA socket, and to make the
481 ethernet device available to the system.
482 =============================================================================*/
483 #define CS_CHECK(fn, args...) \
484 while ((last_ret=fn(args))!=0) goto cs_failed
485 #define MAX_TUPLE_SIZE 128
486 static void ray_config(dev_link_t *link)
488 client_handle_t handle = link->handle;
489 tuple_t tuple;
490 cisparse_t parse;
491 int last_fn = 0, last_ret = 0;
492 int i;
493 u_char buf[MAX_TUPLE_SIZE];
494 win_req_t req;
495 memreq_t mem;
496 struct net_device *dev = (struct net_device *)link->priv;
497 ray_dev_t *local = (ray_dev_t *)dev->priv;
499 DEBUG(1, "ray_config(0x%p)\n", link);
501 /* This reads the card's CONFIG tuple to find its configuration regs */
502 tuple.DesiredTuple = CISTPL_CONFIG;
503 CS_CHECK(pcmcia_get_first_tuple, handle, &tuple);
504 tuple.TupleData = buf;
505 tuple.TupleDataMax = MAX_TUPLE_SIZE;
506 tuple.TupleOffset = 0;
507 CS_CHECK(pcmcia_get_tuple_data, handle, &tuple);
508 CS_CHECK(pcmcia_parse_tuple, handle, &tuple, &parse);
509 link->conf.ConfigBase = parse.config.base;
510 link->conf.Present = parse.config.rmask[0];
512 /* Determine card type and firmware version */
513 buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0;
514 tuple.DesiredTuple = CISTPL_VERS_1;
515 CS_CHECK(pcmcia_get_first_tuple, handle, &tuple);
516 tuple.TupleData = buf;
517 tuple.TupleDataMax = MAX_TUPLE_SIZE;
518 tuple.TupleOffset = 2;
519 CS_CHECK(pcmcia_get_tuple_data, handle, &tuple);
521 for (i=0; i<tuple.TupleDataLen - 4; i++)
522 if (buf[i] == 0) buf[i] = ' ';
523 printk(KERN_INFO "ray_cs Detected: %s\n",buf);
525 /* Configure card */
526 link->state |= DEV_CONFIG;
528 /* Now allocate an interrupt line. Note that this does not
529 actually assign a handler to the interrupt.
531 CS_CHECK(pcmcia_request_irq, link->handle, &link->irq);
532 dev->irq = link->irq.AssignedIRQ;
534 /* This actually configures the PCMCIA socket -- setting up
535 the I/O windows and the interrupt mapping.
537 CS_CHECK(pcmcia_request_configuration, link->handle, &link->conf);
539 /*** Set up 32k window for shared memory (transmit and control) ************/
540 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
541 req.Base = 0;
542 req.Size = 0x8000;
543 req.AccessSpeed = ray_mem_speed;
544 CS_CHECK(pcmcia_request_window, &link->handle, &req, &link->win);
545 mem.CardOffset = 0x0000; mem.Page = 0;
546 CS_CHECK(pcmcia_map_mem_page, link->win, &mem);
547 local->sram = (UCHAR *)(ioremap(req.Base,req.Size));
549 /*** Set up 16k window for shared memory (receive buffer) ***************/
550 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
551 req.Base = 0;
552 req.Size = 0x4000;
553 req.AccessSpeed = ray_mem_speed;
554 CS_CHECK(pcmcia_request_window, &link->handle, &req, &local->rmem_handle);
555 mem.CardOffset = 0x8000; mem.Page = 0;
556 CS_CHECK(pcmcia_map_mem_page, local->rmem_handle, &mem);
557 local->rmem = (UCHAR *)(ioremap(req.Base,req.Size));
559 /*** Set up window for attribute memory ***********************************/
560 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
561 req.Base = 0;
562 req.Size = 0x1000;
563 req.AccessSpeed = ray_mem_speed;
564 CS_CHECK(pcmcia_request_window, &link->handle, &req, &local->amem_handle);
565 mem.CardOffset = 0x0000; mem.Page = 0;
566 CS_CHECK(pcmcia_map_mem_page, local->amem_handle, &mem);
567 local->amem = (UCHAR *)(ioremap(req.Base,req.Size));
569 DEBUG(3,"ray_config sram=%p\n",local->sram);
570 DEBUG(3,"ray_config rmem=%p\n",local->rmem);
571 DEBUG(3,"ray_config amem=%p\n",local->amem);
572 if (ray_init(dev) < 0) {
573 ray_release((u_long)link);
574 return;
577 i = register_netdev(dev);
578 if (i != 0) {
579 printk("ray_config register_netdev() failed\n");
580 ray_release((u_long)link);
581 return;
584 link->state &= ~DEV_CONFIG_PENDING;
585 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ",
586 dev->name, dev->irq);
587 for (i = 0; i < 6; i++)
588 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
590 return;
592 cs_failed:
593 cs_error(link->handle, last_fn, last_ret);
595 ray_release((u_long)link);
596 } /* ray_config */
597 /*===========================================================================*/
598 static int ray_init(struct net_device *dev)
600 int i;
601 UCHAR *p;
602 struct ccs *pccs;
603 ray_dev_t *local = (ray_dev_t *)dev->priv;
604 dev_link_t *link = local->finder;
605 DEBUG(1, "ray_init(0x%p)\n", dev);
606 if (!(link->state & DEV_PRESENT)) {
607 DEBUG(0,"ray_init - device not present\n");
608 return -1;
611 local->net_type = net_type;
612 local->sta_type = TYPE_STA;
614 /* Copy the startup results to local memory */
615 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,\
616 sizeof(struct startup_res_6));
618 /* Check Power up test status and get mac address from card */
619 if (local->startup_res.startup_word != 0x80) {
620 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
621 local->startup_res.startup_word);
622 local->card_status = CARD_INIT_ERROR;
623 return -1;
626 local->fw_ver = local->startup_res.firmware_version[0];
627 local->fw_bld = local->startup_res.firmware_version[1];
628 local->fw_var = local->startup_res.firmware_version[2];
629 DEBUG(1,"ray_init firmware version %d.%d \n",local->fw_ver, local->fw_bld);
631 local->tib_length = 0x20;
632 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
633 local->tib_length = local->startup_res.tib_length;
634 DEBUG(2,"ray_init tib_length = 0x%02x\n", local->tib_length);
635 /* Initialize CCS's to buffer free state */
636 pccs = (struct ccs *)(local->sram + CCS_BASE);
637 for (i=0; i<NUMBER_OF_CCS; i++) {
638 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
640 init_startup_params(local);
642 /* copy mac address to startup parameters */
643 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr))
645 p = local->sparm.b4.a_mac_addr;
647 else
649 memcpy(&local->sparm.b4.a_mac_addr,
650 &local->startup_res.station_addr, ADDRLEN);
651 p = local->sparm.b4.a_mac_addr;
654 clear_interrupt(local); /* Clear any interrupt from the card */
655 local->card_status = CARD_AWAITING_PARAM;
656 DEBUG(2,"ray_init ending\n");
657 return 0;
658 } /* ray_init */
659 /*===========================================================================*/
660 /* Download startup parameters to the card and command it to read them */
661 static int dl_startup_params(struct net_device *dev)
663 int ccsindex;
664 ray_dev_t *local = (ray_dev_t *)dev->priv;
665 struct ccs *pccs;
666 dev_link_t *link = local->finder;
668 DEBUG(1,"dl_startup_params entered\n");
669 if (!(link->state & DEV_PRESENT)) {
670 DEBUG(2,"ray_cs dl_startup_params - device not present\n");
671 return -1;
674 /* Copy parameters to host to ECF area */
675 if (local->fw_ver == 0x55)
676 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
677 sizeof(struct b4_startup_params));
678 else
679 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
680 sizeof(struct b5_startup_params));
683 /* Fill in the CCS fields for the ECF */
684 if ((ccsindex = get_free_ccs(local)) < 0) return -1;
685 local->dl_param_ccs = ccsindex;
686 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
687 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
688 DEBUG(2,"dl_startup_params start ccsindex = %d\n", local->dl_param_ccs);
689 /* Interrupt the firmware to process the command */
690 if (interrupt_ecf(local, ccsindex)) {
691 printk(KERN_INFO "ray dl_startup_params failed - "
692 "ECF not ready for intr\n");
693 local->card_status = CARD_DL_PARAM_ERROR;
694 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
695 return -2;
697 local->card_status = CARD_DL_PARAM;
698 /* Start kernel timer to wait for dl startup to complete. */
699 local->timer.expires = jiffies + HZ/2;
700 local->timer.data = (long)local;
701 local->timer.function = &verify_dl_startup;
702 add_timer(&local->timer);
703 DEBUG(2,"ray_cs dl_startup_params started timer for verify_dl_startup\n");
704 return 0;
705 } /* dl_startup_params */
706 /*===========================================================================*/
707 static void init_startup_params(ray_dev_t *local)
709 int i;
711 if (country > JAPAN_TEST) country = USA;
712 else
713 if (country < USA) country = USA;
714 /* structure for hop time and beacon period is defined here using
715 * New 802.11D6.1 format. Card firmware is still using old format
716 * until version 6.
717 * Before After
718 * a_hop_time ms byte a_hop_time ms byte
719 * a_hop_time 2s byte a_hop_time ls byte
720 * a_hop_time ls byte a_beacon_period ms byte
721 * a_beacon_period a_beacon_period ls byte
723 * a_hop_time = uS a_hop_time = KuS
724 * a_beacon_period = hops a_beacon_period = KuS
725 */ /* 64ms = 010000 */
726 if (local->fw_ver == 0x55) {
727 memcpy((UCHAR *)&local->sparm.b4, b4_default_startup_parms,
728 sizeof(struct b4_startup_params));
729 /* Translate sane kus input values to old build 4/5 format */
730 /* i = hop time in uS truncated to 3 bytes */
731 i = (hop_dwell * 1024) & 0xffffff;
732 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
733 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
734 local->sparm.b4.a_beacon_period[0] = 0;
735 local->sparm.b4.a_beacon_period[1] =
736 ((beacon_period/hop_dwell) - 1) & 0xff;
737 local->sparm.b4.a_curr_country_code = country;
738 local->sparm.b4.a_hop_pattern_length =
739 hop_pattern_length[(int)country] - 1;
740 if (bc)
742 local->sparm.b4.a_ack_timeout = 0x50;
743 local->sparm.b4.a_sifs = 0x3f;
746 else { /* Version 5 uses real kus values */
747 memcpy((UCHAR *)&local->sparm.b5, b5_default_startup_parms,
748 sizeof(struct b5_startup_params));
750 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
751 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
752 local->sparm.b5.a_beacon_period[0] = (beacon_period >> 8) & 0xff;
753 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
754 if (psm)
755 local->sparm.b5.a_power_mgt_state = 1;
756 local->sparm.b5.a_curr_country_code = country;
757 local->sparm.b5.a_hop_pattern_length =
758 hop_pattern_length[(int)country];
761 local->sparm.b4.a_network_type = net_type & 0x01;
762 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
764 if (essid != NULL)
765 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
766 } /* init_startup_params */
767 /*===========================================================================*/
768 static void verify_dl_startup(u_long data)
770 ray_dev_t *local = (ray_dev_t *)data;
771 struct ccs *pccs = ((struct ccs *)(local->sram + CCS_BASE)) + local->dl_param_ccs;
772 UCHAR status;
773 dev_link_t *link = local->finder;
775 if (!(link->state & DEV_PRESENT)) {
776 DEBUG(2,"ray_cs verify_dl_startup - device not present\n");
777 return;
779 #ifdef PCMCIA_DEBUG
780 if (pc_debug > 2) {
781 int i;
782 printk(KERN_DEBUG "verify_dl_startup parameters sent via ccs %d:\n",
783 local->dl_param_ccs);
784 for (i=0; i<sizeof(struct b5_startup_params); i++) {
785 printk(" %2x", (unsigned int) readb(local->sram + HOST_TO_ECF_BASE + i));
787 printk("\n");
789 #endif
791 status = readb(&pccs->buffer_status);
792 if (status!= CCS_BUFFER_FREE)
794 printk(KERN_INFO "Download startup params failed. Status = %d\n",
795 status);
796 local->card_status = CARD_DL_PARAM_ERROR;
797 return;
799 if (local->sparm.b4.a_network_type == ADHOC)
800 start_net((u_long)local);
801 else
802 join_net((u_long)local);
804 return;
805 } /* end verify_dl_startup */
806 /*===========================================================================*/
807 /* Command card to start a network */
808 static void start_net(u_long data)
810 ray_dev_t *local = (ray_dev_t *)data;
811 struct ccs *pccs;
812 int ccsindex;
813 dev_link_t *link = local->finder;
814 if (!(link->state & DEV_PRESENT)) {
815 DEBUG(2,"ray_cs start_net - device not present\n");
816 return;
818 /* Fill in the CCS fields for the ECF */
819 if ((ccsindex = get_free_ccs(local)) < 0) return;
820 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
821 writeb(CCS_START_NETWORK, &pccs->cmd);
822 writeb(0, &pccs->var.start_network.update_param);
823 /* Interrupt the firmware to process the command */
824 if (interrupt_ecf(local, ccsindex)) {
825 DEBUG(1,"ray start net failed - card not ready for intr\n");
826 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
827 return;
829 local->card_status = CARD_DOING_ACQ;
830 return;
831 } /* end start_net */
832 /*===========================================================================*/
833 /* Command card to join a network */
834 static void join_net(u_long data)
836 ray_dev_t *local = (ray_dev_t *)data;
838 struct ccs *pccs;
839 int ccsindex;
840 dev_link_t *link = local->finder;
842 if (!(link->state & DEV_PRESENT)) {
843 DEBUG(2,"ray_cs join_net - device not present\n");
844 return;
846 /* Fill in the CCS fields for the ECF */
847 if ((ccsindex = get_free_ccs(local)) < 0) return;
848 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
849 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
850 writeb(0, &pccs->var.join_network.update_param);
851 writeb(0, &pccs->var.join_network.net_initiated);
852 /* Interrupt the firmware to process the command */
853 if (interrupt_ecf(local, ccsindex)) {
854 DEBUG(1,"ray join net failed - card not ready for intr\n");
855 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
856 return;
858 local->card_status = CARD_DOING_ACQ;
859 return;
861 /*============================================================================
862 After a card is removed, ray_release() will unregister the net
863 device, and release the PCMCIA configuration. If the device is
864 still open, this will be postponed until it is closed.
865 =============================================================================*/
866 static void ray_release(u_long arg)
868 dev_link_t *link = (dev_link_t *)arg;
869 struct net_device *dev = link->priv;
870 ray_dev_t *local = dev->priv;
871 int i;
873 DEBUG(1, "ray_release(0x%p)\n", link);
874 /* If the device is currently in use, we won't release until it
875 is actually closed.
877 if (link->open) {
878 DEBUG(1, "ray_cs: release postponed, '%s' still open\n",
879 link->dev->dev_name);
880 link->state |= DEV_STALE_CONFIG;
881 return;
883 del_timer(&local->timer);
884 if (link->dev != '\0') unregister_netdev(dev);
885 /* Unlink the device chain */
886 link->dev = NULL;
888 iounmap(local->sram);
889 iounmap(local->rmem);
890 iounmap(local->amem);
891 /* Do bother checking to see if these succeed or not */
892 i = pcmcia_release_window(link->win);
893 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(link->win) ret = %x\n",i);
894 i = pcmcia_release_window(local->amem_handle);
895 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
896 i = pcmcia_release_window(local->rmem_handle);
897 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
898 i = pcmcia_release_configuration(link->handle);
899 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseConfiguration ret = %x\n",i);
900 i = pcmcia_release_irq(link->handle, &link->irq);
901 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseIRQ ret = %x\n",i);
903 link->state &= ~DEV_CONFIG;
904 if (link->state & DEV_STALE_LINK) ray_detach(link);
905 DEBUG(2,"ray_release ending\n");
906 } /* ray_release */
907 /*=============================================================================
908 The card status event handler. Mostly, this schedules other
909 stuff to run after an event is received. A CARD_REMOVAL event
910 also sets some flags to discourage the net drivers from trying
911 to talk to the card any more.
913 When a CARD_REMOVAL event is received, we immediately set a flag
914 to block future accesses to this device. All the functions that
915 actually access the device should check this flag to make sure
916 the card is still present.
917 =============================================================================*/
918 static int ray_event(event_t event, int priority,
919 event_callback_args_t *args)
921 dev_link_t *link = args->client_data;
922 struct net_device *dev = link->priv;
923 ray_dev_t *local = (ray_dev_t *)dev->priv;
924 DEBUG(1, "ray_event(0x%06x)\n", event);
926 switch (event) {
927 case CS_EVENT_CARD_REMOVAL:
928 link->state &= ~DEV_PRESENT;
929 netif_device_detach(dev);
930 if (link->state & DEV_CONFIG) {
931 link->release.expires = jiffies + HZ/20;
932 add_timer(&link->release);
933 del_timer(&local->timer);
935 break;
936 case CS_EVENT_CARD_INSERTION:
937 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
938 ray_config(link);
939 break;
940 case CS_EVENT_PM_SUSPEND:
941 link->state |= DEV_SUSPEND;
942 /* Fall through... */
943 case CS_EVENT_RESET_PHYSICAL:
944 if (link->state & DEV_CONFIG) {
945 if (link->open)
946 netif_device_detach(dev);
948 pcmcia_release_configuration(link->handle);
950 break;
951 case CS_EVENT_PM_RESUME:
952 link->state &= ~DEV_SUSPEND;
953 /* Fall through... */
954 case CS_EVENT_CARD_RESET:
955 if (link->state & DEV_CONFIG) {
956 pcmcia_request_configuration(link->handle, &link->conf);
957 if (link->open) {
958 ray_reset(dev);
959 netif_device_attach(dev);
962 break;
964 return 0;
965 DEBUG(2,"ray_event ending\n");
966 } /* ray_event */
967 /*===========================================================================*/
968 int ray_dev_init(struct net_device *dev)
970 int i;
971 ray_dev_t *local = dev->priv;
972 dev_link_t *link = local->finder;
974 DEBUG(1,"ray_dev_init(dev=%p)\n",dev);
975 if (!(link->state & DEV_PRESENT)) {
976 DEBUG(2,"ray_dev_init - device not present\n");
977 return -1;
979 /* Download startup parameters */
980 if ( (i = dl_startup_params(dev)) < 0)
982 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
983 "returns 0x%x/n",i);
984 return -1;
987 /* copy mac and broadcast addresses to linux device */
988 memcpy(&dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
989 memset(dev->broadcast, 0xff, ETH_ALEN);
991 DEBUG(2,"ray_dev_init ending\n");
992 return 0;
994 /*===========================================================================*/
995 static int ray_dev_config(struct net_device *dev, struct ifmap *map)
997 ray_dev_t *local = dev->priv;
998 dev_link_t *link = local->finder;
999 /* Dummy routine to satisfy device structure */
1000 DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map);
1001 if (!(link->state & DEV_PRESENT)) {
1002 DEBUG(2,"ray_dev_config - device not present\n");
1003 return -1;
1006 return 0;
1008 /*===========================================================================*/
1009 static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
1011 ray_dev_t *local = dev->priv;
1012 dev_link_t *link = local->finder;
1013 short length;
1015 if (!(link->state & DEV_PRESENT)) {
1016 DEBUG(2,"ray_dev_start_xmit - device not present\n");
1017 return -1;
1019 DEBUG(3,"ray_dev_start_xmit(skb=%p, dev=%p)\n",skb,dev);
1020 if (local->authentication_state == NEED_TO_AUTH) {
1021 DEBUG(0,"ray_cs Sending authentication request.\n");
1022 if (!build_auth_frame (local, local->auth_id, OPEN_AUTH_REQUEST)) {
1023 local->authentication_state = AUTHENTICATED;
1024 netif_stop_queue(dev);
1025 return 1;
1029 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1030 switch (ray_hw_xmit( skb->data, length, dev, DATA_TYPE)) {
1031 case XMIT_NO_CCS:
1032 case XMIT_NEED_AUTH:
1033 netif_stop_queue(dev);
1034 return 1;
1035 case XMIT_NO_INTR:
1036 case XMIT_MSG_BAD:
1037 case XMIT_OK:
1038 default:
1039 dev->trans_start = jiffies;
1040 dev_kfree_skb(skb);
1041 return 0;
1043 return 0;
1044 } /* ray_dev_start_xmit */
1045 /*===========================================================================*/
1046 static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev,
1047 UCHAR msg_type)
1049 ray_dev_t *local = (ray_dev_t *)dev->priv;
1050 struct ccs *pccs;
1051 int ccsindex;
1052 int offset;
1053 struct tx_msg *ptx; /* Address of xmit buffer in PC space */
1054 short int addr; /* Address of xmit buffer in card space */
1056 DEBUG(3,"ray_hw_xmit(data=%p, len=%d, dev=%p)\n",data,len,dev);
1057 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE)
1059 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",len);
1060 return XMIT_MSG_BAD;
1062 switch (ccsindex = get_free_tx_ccs(local)) {
1063 case ECCSBUSY:
1064 DEBUG(2,"ray_hw_xmit tx_ccs table busy\n");
1065 case ECCSFULL:
1066 DEBUG(2,"ray_hw_xmit No free tx ccs\n");
1067 case ECARDGONE:
1068 netif_stop_queue(dev);
1069 return XMIT_NO_CCS;
1070 default:
1071 break;
1073 addr = TX_BUF_BASE + (ccsindex << 11);
1075 if (msg_type == DATA_TYPE) {
1076 local->stats.tx_bytes += len;
1077 local->stats.tx_packets++;
1080 ptx = (struct tx_msg *)(local->sram + addr);
1082 ray_build_header(local, ptx, msg_type, data);
1083 if (translate) {
1084 offset = translate_frame(local, ptx, data, len);
1086 else { /* Encapsulate frame */
1087 /* TBD TIB length will move address of ptx->var */
1088 memcpy_toio(&ptx->var, data, len);
1089 offset = 0;
1092 /* fill in the CCS */
1093 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
1094 len += TX_HEADER_LENGTH + offset;
1095 writeb(CCS_TX_REQUEST, &pccs->cmd);
1096 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
1097 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
1098 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
1099 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
1100 /* TBD still need psm_cam? */
1101 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
1102 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1103 writeb(0, &pccs->var.tx_request.antenna);
1104 DEBUG(3,"ray_hw_xmit default_tx_rate = 0x%x\n",\
1105 local->net_default_tx_rate);
1107 /* Interrupt the firmware to process the command */
1108 if (interrupt_ecf(local, ccsindex)) {
1109 DEBUG(2,"ray_hw_xmit failed - ECF not ready for intr\n");
1110 /* TBD very inefficient to copy packet to buffer, and then not
1111 send it, but the alternative is to queue the messages and that
1112 won't be done for a while. Maybe set tbusy until a CCS is free?
1114 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1115 return XMIT_NO_INTR;
1117 return XMIT_OK;
1118 } /* end ray_hw_xmit */
1119 /*===========================================================================*/
1120 static int translate_frame(ray_dev_t *local, struct tx_msg *ptx, unsigned char *data,
1121 int len)
1123 unsigned short int proto = ((struct ethhdr *)data)->h_proto;
1124 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
1125 DEBUG(3,"ray_cs translate_frame DIX II\n");
1126 /* Copy LLC header to card buffer */
1127 memcpy_toio((UCHAR *)&ptx->var, eth2_llc, sizeof(eth2_llc));
1128 memcpy_toio( ((UCHAR *)&ptx->var) + sizeof(eth2_llc), (UCHAR *)&proto, 2);
1129 if ((proto == 0xf380) || (proto == 0x3781)) {
1130 /* This is the selective translation table, only 2 entries */
1131 writeb(0xf8, (UCHAR *) &((struct snaphdr_t *)ptx->var)->org[3]);
1133 /* Copy body of ethernet packet without ethernet header */
1134 memcpy_toio((UCHAR *)&ptx->var + sizeof(struct snaphdr_t), \
1135 data + ETH_HLEN, len - ETH_HLEN);
1136 return (int) sizeof(struct snaphdr_t) - ETH_HLEN;
1138 else { /* already 802 type, and proto is length */
1139 DEBUG(3,"ray_cs translate_frame 802\n");
1140 if (proto == 0xffff) { /* evil netware IPX 802.3 without LLC */
1141 DEBUG(3,"ray_cs translate_frame evil IPX\n");
1142 memcpy_toio((UCHAR *)&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1143 return 0 - ETH_HLEN;
1145 memcpy_toio((UCHAR *)&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1146 return 0 - ETH_HLEN;
1148 /* TBD do other frame types */
1149 } /* end translate_frame */
1150 /*===========================================================================*/
1151 static void ray_build_header(ray_dev_t *local, struct tx_msg *ptx, UCHAR msg_type,
1152 unsigned char *data)
1154 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1155 /*** IEEE 802.11 Address field assignments *************
1156 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1157 Adhoc 0 0 dest src (terminal) BSSID N/A
1158 AP to Terminal 0 1 dest AP(BSSID) source N/A
1159 Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1160 AP to AP 1 1 dest AP src AP dest source
1161 *******************************************************/
1162 if (local->net_type == ADHOC) {
1163 writeb(0, &ptx->mac.frame_ctl_2);
1164 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, 2 * ADDRLEN);
1165 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1167 else /* infrastructure */
1169 if (local->sparm.b4.a_acting_as_ap_status)
1171 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1172 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, ADDRLEN);
1173 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1174 memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_source, ADDRLEN);
1176 else /* Terminal */
1178 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1179 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1180 memcpy_toio(ptx->mac.addr_2, ((struct ethhdr *)data)->h_source, ADDRLEN);
1181 memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_dest, ADDRLEN);
1184 } /* end encapsulate_frame */
1185 /*===========================================================================*/
1186 static int ray_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1188 ray_dev_t *local = (ray_dev_t *)dev->priv;
1189 dev_link_t *link = local->finder;
1190 int err = 0;
1191 #if WIRELESS_EXT > 7
1192 struct iwreq *wrq = (struct iwreq *) ifr;
1193 #endif /* WIRELESS_EXT > 7 */
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 #if WIRELESS_EXT > 7
1204 /* --------------- WIRELESS EXTENSIONS --------------- */
1205 /* Get name */
1206 case SIOCGIWNAME:
1207 strcpy(wrq->u.name, "IEEE 802.11-FH");
1208 break;
1210 /* Get frequency/channel */
1211 case SIOCGIWFREQ:
1212 wrq->u.freq.m = local->sparm.b5.a_hop_pattern;
1213 wrq->u.freq.e = 0;
1214 break;
1216 /* Get current network name (ESSID) */
1217 case SIOCGIWESSID:
1218 if (wrq->u.data.pointer)
1220 char essid[IW_ESSID_MAX_SIZE + 1];
1221 /* Get the essid that was set */
1222 memcpy(essid, local->sparm.b5.a_current_ess_id,
1223 IW_ESSID_MAX_SIZE);
1224 essid[IW_ESSID_MAX_SIZE] = '\0';
1226 /* Push it out ! */
1227 wrq->u.data.length = strlen(essid) + 1;
1228 wrq->u.data.flags = 1; /* active */
1229 copy_to_user(wrq->u.data.pointer, essid, sizeof(essid));
1231 break;
1233 /* Get current Access Point (BSSID in our case) */
1234 case SIOCGIWAP:
1235 memcpy(wrq->u.ap_addr.sa_data, local->bss_id, ETH_ALEN);
1236 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
1237 break;
1239 /* Get the current bit-rate */
1240 case SIOCGIWRATE:
1241 if(local->net_default_tx_rate == 3)
1242 wrq->u.bitrate.value = 2000000; /* Hum... */
1243 else
1244 wrq->u.bitrate.value = local->net_default_tx_rate * 500000;
1245 wrq->u.bitrate.fixed = 0; /* We are in auto mode */
1246 break;
1248 /* Set the desired bit-rate */
1249 case SIOCSIWRATE:
1250 /* Check if rate is in range */
1251 if((wrq->u.bitrate.value != 1000000) &&
1252 (wrq->u.bitrate.value != 2000000))
1254 err = -EINVAL;
1255 break;
1257 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
1258 if((local->fw_ver == 0x55) && /* Please check */
1259 (wrq->u.bitrate.value == 2000000))
1260 local->net_default_tx_rate = 3;
1261 else
1262 local->net_default_tx_rate = wrq->u.bitrate.value/500000;
1263 break;
1265 /* Get the current RTS threshold */
1266 case SIOCGIWRTS:
1267 wrq->u.rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
1268 + local->sparm.b5.a_rts_threshold[1];
1269 #if WIRELESS_EXT > 8
1270 wrq->u.rts.disabled = (wrq->u.rts.value == 32767);
1271 #endif /* WIRELESS_EXT > 8 */
1272 wrq->u.rts.fixed = 1;
1273 break;
1275 /* Get the current fragmentation threshold */
1276 case SIOCGIWFRAG:
1277 wrq->u.frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
1278 + local->sparm.b5.a_frag_threshold[1];
1279 #if WIRELESS_EXT > 8
1280 wrq->u.frag.disabled = (wrq->u.frag.value == 32767);
1281 #endif /* WIRELESS_EXT > 8 */
1282 wrq->u.frag.fixed = 1;
1283 break;
1284 #endif /* WIRELESS_EXT > 7 */
1285 #if WIRELESS_EXT > 8
1287 /* Get the current mode of operation */
1288 case SIOCGIWMODE:
1289 if(local->sparm.b5.a_network_type)
1290 wrq->u.mode = IW_MODE_INFRA;
1291 else
1292 wrq->u.mode = IW_MODE_ADHOC;
1293 break;
1294 #endif /* WIRELESS_EXT > 8 */
1295 #if WIRELESS_EXT > 7
1296 /* ------------------ IWSPY SUPPORT ------------------ */
1297 /* Define the range (variations) of above parameters */
1298 case SIOCGIWRANGE:
1299 /* Basic checking... */
1300 if(wrq->u.data.pointer != (caddr_t) 0)
1302 struct iw_range range;
1303 memset((char *) &range, 0, sizeof(struct iw_range));
1305 /* Set the length (useless : its constant...) */
1306 wrq->u.data.length = sizeof(struct iw_range);
1308 /* Set information in the range struct */
1309 range.throughput = 1.1 * 1000 * 1000; /* Put the right number here */
1310 range.num_channels = hop_pattern_length[(int)country];
1311 range.num_frequency = 0;
1312 range.max_qual.qual = 0;
1313 range.max_qual.level = 255; /* What's the correct value ? */
1314 range.max_qual.noise = 255; /* Idem */
1315 range.num_bitrates = 2;
1316 range.bitrate[0] = 1000000; /* 1 Mb/s */
1317 range.bitrate[1] = 2000000; /* 2 Mb/s */
1319 /* Copy structure to the user buffer */
1320 if(copy_to_user(wrq->u.data.pointer, &range,
1321 sizeof(struct iw_range)))
1322 err = -EFAULT;
1324 break;
1326 #ifdef WIRELESS_SPY
1327 /* Set addresses to spy */
1328 case SIOCSIWSPY:
1329 /* Check the number of addresses */
1330 if(wrq->u.data.length > IW_MAX_SPY)
1332 err = -E2BIG;
1333 break;
1335 local->spy_number = wrq->u.data.length;
1337 /* If there is some addresses to copy */
1338 if(local->spy_number > 0)
1340 struct sockaddr address[IW_MAX_SPY];
1341 int i;
1343 /* Copy addresses to the driver */
1344 if(copy_from_user(address, wrq->u.data.pointer,
1345 sizeof(struct sockaddr) * local->spy_number))
1347 err = -EFAULT;
1348 break;
1351 /* Copy addresses to the lp structure */
1352 for(i = 0; i < local->spy_number; i++)
1353 memcpy(local->spy_address[i], address[i].sa_data, ETH_ALEN);
1355 /* Reset structure... */
1356 memset(local->spy_stat, 0x00, sizeof(iw_qual) * IW_MAX_SPY);
1358 #ifdef DEBUG_IOCTL_INFO
1359 printk(KERN_DEBUG "SetSpy - Set of new addresses is :\n");
1360 for(i = 0; i < local->spy_number; i++)
1361 printk(KERN_DEBUG "%02X:%02X:%02X:%02X:%02X:%02X\n",
1362 local->spy_address[i][0],
1363 local->spy_address[i][1],
1364 local->spy_address[i][2],
1365 local->spy_address[i][3],
1366 local->spy_address[i][4],
1367 local->spy_address[i][5]);
1368 #endif /* DEBUG_IOCTL_INFO */
1370 break;
1372 /* Get the spy list and spy stats */
1373 case SIOCGIWSPY:
1374 /* Set the number of addresses */
1375 wrq->u.data.length = local->spy_number;
1377 /* If the user want to have the addresses back... */
1378 if((local->spy_number > 0) && (wrq->u.data.pointer != (caddr_t) 0))
1380 struct sockaddr address[IW_MAX_SPY];
1381 int i;
1383 /* Copy addresses from the lp structure */
1384 for(i = 0; i < local->spy_number; i++)
1386 memcpy(address[i].sa_data, local->spy_address[i], ETH_ALEN);
1387 address[i].sa_family = ARPHRD_ETHER;
1390 /* Copy addresses to the user buffer */
1391 if(copy_to_user(wrq->u.data.pointer, address,
1392 sizeof(struct sockaddr) * local->spy_number))
1394 err = -EFAULT;
1395 break;
1398 /* Copy stats to the user buffer (just after) */
1399 if(copy_to_user(wrq->u.data.pointer +
1400 (sizeof(struct sockaddr) * local->spy_number),
1401 local->spy_stat, sizeof(iw_qual) * local->spy_number))
1403 err = -EFAULT;
1404 break;
1407 /* Reset updated flags */
1408 for(i = 0; i < local->spy_number; i++)
1409 local->spy_stat[i].updated = 0x0;
1410 } /* if(pointer != NULL) */
1412 break;
1413 #endif /* WIRELESS_SPY */
1415 /* ------------------ PRIVATE IOCTL ------------------ */
1416 #define SIOCSIPFRAMING SIOCDEVPRIVATE /* Set framing mode */
1417 #define SIOCGIPFRAMING SIOCDEVPRIVATE + 1 /* Get framing mode */
1418 #define SIOCGIPCOUNTRY SIOCDEVPRIVATE + 3 /* Get country code */
1419 case SIOCSIPFRAMING:
1420 if(!capable(CAP_NET_ADMIN)) /* For private IOCTLs, we need to check permissions */
1422 err = -EPERM;
1423 break;
1425 translate = *(wrq->u.name); /* Set framing mode */
1426 break;
1427 case SIOCGIPFRAMING:
1428 *(wrq->u.name) = translate;
1429 break;
1430 case SIOCGIPCOUNTRY:
1431 *(wrq->u.name) = country;
1432 break;
1433 case SIOCGIWPRIV:
1434 /* Export our "private" intercace */
1435 if(wrq->u.data.pointer != (caddr_t) 0)
1437 struct iw_priv_args priv[] =
1438 { /* cmd, set_args, get_args, name */
1439 { SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "set_framing" },
1440 { SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_framing" },
1441 { SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_country" },
1443 /* Set the number of ioctl available */
1444 wrq->u.data.length = 3;
1445 /* Copy structure to the user buffer */
1446 if(copy_to_user(wrq->u.data.pointer, (u_char *) priv,
1447 sizeof(priv)))
1448 err = -EFAULT;
1450 break;
1451 #endif /* WIRELESS_EXT > 7 */
1454 default:
1455 DEBUG(0,"ray_dev_ioctl cmd = 0x%x\n", cmd);
1456 err = -EOPNOTSUPP;
1458 return err;
1459 } /* end ray_dev_ioctl */
1460 /*===========================================================================*/
1461 #if WIRELESS_EXT > 7 /* If wireless extension exist in the kernel */
1462 static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1464 ray_dev_t * local = (ray_dev_t *) dev->priv;
1465 dev_link_t *link = local->finder;
1466 struct status *p = (struct status *)(local->sram + STATUS_BASE);
1468 if(local == (ray_dev_t *) NULL)
1469 return (iw_stats *) NULL;
1471 local->wstats.status = local->card_status;
1472 #ifdef WIRELESS_SPY
1473 if((local->spy_number > 0) && (local->sparm.b5.a_network_type == 0))
1475 /* Get it from the first node in spy list */
1476 local->wstats.qual.qual = local->spy_stat[0].qual;
1477 local->wstats.qual.level = local->spy_stat[0].level;
1478 local->wstats.qual.noise = local->spy_stat[0].noise;
1479 local->wstats.qual.updated = local->spy_stat[0].updated;
1481 #endif /* WIRELESS_SPY */
1483 if((link->state & DEV_PRESENT)) {
1484 local->wstats.qual.noise = readb(&p->rxnoise);
1485 local->wstats.qual.updated |= 4;
1488 return &local->wstats;
1489 } /* end ray_get_wireless_stats */
1490 #endif /* WIRELESS_EXT > 7 */
1491 /*===========================================================================*/
1492 static int ray_open(struct net_device *dev)
1494 dev_link_t *link;
1495 ray_dev_t *local = (ray_dev_t *)dev->priv;
1497 MOD_INC_USE_COUNT;
1499 DEBUG(1, "ray_open('%s')\n", dev->name);
1501 for (link = dev_list; link; link = link->next)
1502 if (link->priv == dev) break;
1503 if (!DEV_OK(link)) {
1504 MOD_DEC_USE_COUNT;
1505 return -ENODEV;
1508 if (link->open == 0) local->num_multi = 0;
1509 link->open++;
1511 if (sniffer) netif_stop_queue(dev);
1512 else netif_start_queue(dev);
1514 DEBUG(2,"ray_open ending\n");
1515 return 0;
1516 } /* end ray_open */
1517 /*===========================================================================*/
1518 static int ray_dev_close(struct net_device *dev)
1520 dev_link_t *link;
1522 DEBUG(1, "ray_dev_close('%s')\n", dev->name);
1524 for (link = dev_list; link; link = link->next)
1525 if (link->priv == dev) break;
1526 if (link == NULL)
1527 return -ENODEV;
1529 link->open--;
1530 netif_stop_queue(dev);
1531 if (link->state & DEV_STALE_CONFIG) {
1532 link->release.expires = jiffies + HZ/20;
1533 link->state |= DEV_RELEASE_PENDING;
1534 add_timer(&link->release);
1537 MOD_DEC_USE_COUNT;
1539 return 0;
1540 } /* end ray_dev_close */
1541 /*===========================================================================*/
1542 static void ray_reset(struct net_device *dev) {
1543 DEBUG(1,"ray_reset entered\n");
1544 return;
1546 /*===========================================================================*/
1547 /* Cause a firmware interrupt if it is ready for one */
1548 /* Return nonzero if not ready */
1549 static int interrupt_ecf(ray_dev_t *local, int ccs)
1551 int i = 50;
1552 dev_link_t *link = local->finder;
1554 if (!(link->state & DEV_PRESENT)) {
1555 DEBUG(2,"ray_cs interrupt_ecf - device not present\n");
1556 return -1;
1558 DEBUG(2,"interrupt_ecf(local=%p, ccs = 0x%x\n",local,ccs);
1560 while ( i &&
1561 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & ECF_INTR_SET))
1562 i--;
1563 if (i == 0) {
1564 DEBUG(2,"ray_cs interrupt_ecf card not ready for interrupt\n");
1565 return -1;
1567 /* Fill the mailbox, then kick the card */
1568 writeb(ccs, local->sram + SCB_BASE);
1569 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1570 return 0;
1571 } /* interrupt_ecf */
1572 /*===========================================================================*/
1573 /* Get next free transmit CCS */
1574 /* Return - index of current tx ccs */
1575 static int get_free_tx_ccs(ray_dev_t *local)
1577 int i;
1578 struct ccs *pccs = (struct ccs *)(local->sram + CCS_BASE);
1579 dev_link_t *link = local->finder;
1581 if (!(link->state & DEV_PRESENT)) {
1582 DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n");
1583 return ECARDGONE;
1586 if (test_and_set_bit(0,&local->tx_ccs_lock)) {
1587 DEBUG(1,"ray_cs tx_ccs_lock busy\n");
1588 return ECCSBUSY;
1591 for (i=0; i < NUMBER_OF_TX_CCS; i++) {
1592 if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) {
1593 writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status);
1594 writeb(CCS_END_LIST, &(pccs+i)->link);
1595 local->tx_ccs_lock = 0;
1596 return i;
1599 local->tx_ccs_lock = 0;
1600 DEBUG(2,"ray_cs ERROR no free tx CCS for raylink card\n");
1601 return ECCSFULL;
1602 } /* get_free_tx_ccs */
1603 /*===========================================================================*/
1604 /* Get next free CCS */
1605 /* Return - index of current ccs */
1606 static int get_free_ccs(ray_dev_t *local)
1608 int i;
1609 struct ccs *pccs = (struct ccs *)(local->sram + CCS_BASE);
1610 dev_link_t *link = local->finder;
1612 if (!(link->state & DEV_PRESENT)) {
1613 DEBUG(2,"ray_cs get_free_ccs - device not present\n");
1614 return ECARDGONE;
1616 if (test_and_set_bit(0,&local->ccs_lock)) {
1617 DEBUG(1,"ray_cs ccs_lock busy\n");
1618 return ECCSBUSY;
1621 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1622 if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) {
1623 writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status);
1624 writeb(CCS_END_LIST, &(pccs+i)->link);
1625 local->ccs_lock = 0;
1626 return i;
1629 local->ccs_lock = 0;
1630 DEBUG(1,"ray_cs ERROR no free CCS for raylink card\n");
1631 return ECCSFULL;
1632 } /* get_free_ccs */
1633 /*===========================================================================*/
1634 static void authenticate_timeout(u_long data)
1636 ray_dev_t *local = (ray_dev_t *)data;
1637 del_timer(&local->timer);
1638 printk(KERN_INFO "ray_cs Authentication with access point failed"
1639 " - timeout\n");
1640 join_net((u_long)local);
1642 /*===========================================================================*/
1643 static int asc_to_int(char a)
1645 if (a < '0') return -1;
1646 if (a <= '9') return (a - '0');
1647 if (a < 'A') return -1;
1648 if (a <= 'F') return (10 + a - 'A');
1649 if (a < 'a') return -1;
1650 if (a <= 'f') return (10 + a - 'a');
1651 return -1;
1653 /*===========================================================================*/
1654 static int parse_addr(char *in_str, UCHAR *out)
1656 int len;
1657 int i,j,k;
1658 int status;
1660 if (in_str == NULL) return 0;
1661 if ((len = strlen(in_str)) < 2) return 0;
1662 memset(out, 0, ADDRLEN);
1664 status = 1;
1665 j = len - 1;
1666 if (j > 12) j = 12;
1667 i = 5;
1669 while (j > 0)
1671 if ((k = asc_to_int(in_str[j--])) != -1) out[i] = k;
1672 else return 0;
1674 if (j == 0) break;
1675 if ((k = asc_to_int(in_str[j--])) != -1) out[i] += k << 4;
1676 else return 0;
1677 if (!i--) break;
1679 return status;
1681 /*===========================================================================*/
1682 static struct net_device_stats *ray_get_stats(struct net_device *dev)
1684 ray_dev_t *local = (ray_dev_t *)dev->priv;
1685 dev_link_t *link = local->finder;
1686 struct status *p = (struct status *)(local->sram + STATUS_BASE);
1687 if (!(link->state & DEV_PRESENT)) {
1688 DEBUG(2,"ray_cs net_device_stats - device not present\n");
1689 return &local->stats;
1691 if (readb(&p->mrx_overflow_for_host))
1693 local->stats.rx_over_errors += ntohs(readb(&p->mrx_overflow));
1694 writeb(0,&p->mrx_overflow);
1695 writeb(0,&p->mrx_overflow_for_host);
1697 if (readb(&p->mrx_checksum_error_for_host))
1699 local->stats.rx_crc_errors += ntohs(readb(&p->mrx_checksum_error));
1700 writeb(0,&p->mrx_checksum_error);
1701 writeb(0,&p->mrx_checksum_error_for_host);
1703 if (readb(&p->rx_hec_error_for_host))
1705 local->stats.rx_frame_errors += ntohs(readb(&p->rx_hec_error));
1706 writeb(0,&p->rx_hec_error);
1707 writeb(0,&p->rx_hec_error_for_host);
1709 return &local->stats;
1711 /*===========================================================================*/
1712 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len)
1714 ray_dev_t *local = (ray_dev_t *)dev->priv;
1715 dev_link_t *link = local->finder;
1716 int ccsindex;
1717 int i;
1718 struct ccs *pccs;
1720 if (!(link->state & DEV_PRESENT)) {
1721 DEBUG(2,"ray_update_parm - device not present\n");
1722 return;
1725 if ((ccsindex = get_free_ccs(local)) < 0)
1727 DEBUG(0,"ray_update_parm - No free ccs\n");
1728 return;
1730 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
1731 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1732 writeb(objid, &pccs->var.update_param.object_id);
1733 writeb(1, &pccs->var.update_param.number_objects);
1734 writeb(0, &pccs->var.update_param.failure_cause);
1735 for (i=0; i<len; i++) {
1736 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1738 /* Interrupt the firmware to process the command */
1739 if (interrupt_ecf(local, ccsindex)) {
1740 DEBUG(0,"ray_cs associate failed - ECF not ready for intr\n");
1741 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1744 /*===========================================================================*/
1745 static void ray_update_multi_list(struct net_device *dev, int all)
1747 struct dev_mc_list *dmi, **dmip;
1748 int ccsindex;
1749 struct ccs *pccs;
1750 int i = 0;
1751 ray_dev_t *local = (ray_dev_t *)dev->priv;
1752 dev_link_t *link = local->finder;
1753 UCHAR *p = local->sram + HOST_TO_ECF_BASE;
1755 if (!(link->state & DEV_PRESENT)) {
1756 DEBUG(2,"ray_update_multi_list - device not present\n");
1757 return;
1759 else
1760 DEBUG(2,"ray_update_multi_list(%p)\n",dev);
1761 if ((ccsindex = get_free_ccs(local)) < 0)
1763 DEBUG(1,"ray_update_multi - No free ccs\n");
1764 return;
1766 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
1767 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
1769 if (all) {
1770 writeb(0xff, &pccs->var);
1771 local->num_multi = 0xff;
1773 else {
1774 /* Copy the kernel's list of MC addresses to card */
1775 for (dmip=&dev->mc_list; (dmi=*dmip)!=NULL; dmip=&dmi->next) {
1776 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
1777 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]);
1778 p += ETH_ALEN;
1779 i++;
1781 if (i > 256/ADDRLEN) i = 256/ADDRLEN;
1782 writeb((UCHAR)i, &pccs->var);
1783 DEBUG(1,"ray_cs update_multi %d addresses in list\n", i);
1784 /* Interrupt the firmware to process the command */
1785 local->num_multi = i;
1787 if (interrupt_ecf(local, ccsindex)) {
1788 DEBUG(1,"ray_cs update_multi failed - ECF not ready for intr\n");
1789 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1791 } /* end ray_update_multi_list */
1792 /*===========================================================================*/
1793 static void set_multicast_list(struct net_device *dev)
1795 ray_dev_t *local = (ray_dev_t *)dev->priv;
1796 UCHAR promisc;
1798 DEBUG(2,"ray_cs set_multicast_list(%p)\n",dev);
1800 if (dev->flags & IFF_PROMISC)
1802 if (local->sparm.b5.a_promiscuous_mode == 0) {
1803 DEBUG(1,"ray_cs set_multicast_list promisc on\n");
1804 local->sparm.b5.a_promiscuous_mode = 1;
1805 promisc = 1;
1806 ray_update_parm(dev, OBJID_promiscuous_mode, \
1807 &promisc, sizeof(promisc));
1810 else {
1811 if (local->sparm.b5.a_promiscuous_mode == 1) {
1812 DEBUG(1,"ray_cs set_multicast_list promisc off\n");
1813 local->sparm.b5.a_promiscuous_mode = 0;
1814 promisc = 0;
1815 ray_update_parm(dev, OBJID_promiscuous_mode, \
1816 &promisc, sizeof(promisc));
1820 if (dev->flags & IFF_ALLMULTI) ray_update_multi_list(dev, 1);
1821 else
1823 if (local->num_multi != dev->mc_count) ray_update_multi_list(dev, 0);
1825 } /* end set_multicast_list */
1826 /*=============================================================================
1827 * All routines below here are run at interrupt time.
1828 =============================================================================*/
1829 static void ray_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1831 struct net_device *dev = (struct net_device *)dev_id;
1832 dev_link_t *link;
1833 ray_dev_t *local;
1834 struct ccs *pccs;
1835 struct rcs *prcs;
1836 UCHAR rcsindex;
1837 UCHAR tmp;
1838 UCHAR cmd;
1839 UCHAR status;
1841 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1842 return;
1844 DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev);
1846 local = (ray_dev_t *)dev->priv;
1847 link = (dev_link_t *)local->finder;
1848 if ( ! (link->state & DEV_PRESENT) || link->state & DEV_SUSPEND ) {
1849 DEBUG(2,"ray_cs interrupt from device not present or suspended.\n");
1850 return;
1852 rcsindex = readb(&((struct scb *)(local->sram))->rcs_index);
1854 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS))
1856 DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
1857 clear_interrupt(local);
1858 return;
1860 if (rcsindex < NUMBER_OF_CCS) /* If it's a returned CCS */
1862 pccs = ((struct ccs *) (local->sram + CCS_BASE)) + rcsindex;
1863 cmd = readb(&pccs->cmd);
1864 status = readb(&pccs->buffer_status);
1865 switch (cmd)
1867 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1868 del_timer(&local->timer);
1869 if (status == CCS_COMMAND_COMPLETE) {
1870 DEBUG(1,"ray_cs interrupt download_startup_parameters OK\n");
1872 else {
1873 DEBUG(1,"ray_cs interrupt download_startup_parameters fail\n");
1875 break;
1876 case CCS_UPDATE_PARAMS:
1877 DEBUG(1,"ray_cs interrupt update params done\n");
1878 if (status != CCS_COMMAND_COMPLETE) {
1879 tmp = readb(&pccs->var.update_param.failure_cause);
1880 DEBUG(0,"ray_cs interrupt update params failed - reason %d\n",tmp);
1882 break;
1883 case CCS_REPORT_PARAMS:
1884 DEBUG(1,"ray_cs interrupt report params done\n");
1885 break;
1886 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
1887 DEBUG(1,"ray_cs interrupt CCS Update Multicast List done\n");
1888 break;
1889 case CCS_UPDATE_POWER_SAVINGS_MODE:
1890 DEBUG(1,"ray_cs interrupt update power save mode done\n");
1891 break;
1892 case CCS_START_NETWORK:
1893 case CCS_JOIN_NETWORK:
1894 if (status == CCS_COMMAND_COMPLETE) {
1895 if (readb(&pccs->var.start_network.net_initiated) == 1) {
1896 DEBUG(0,"ray_cs interrupt network \"%s\" started\n",\
1897 local->sparm.b4.a_current_ess_id);
1899 else {
1900 DEBUG(0,"ray_cs interrupt network \"%s\" joined\n",\
1901 local->sparm.b4.a_current_ess_id);
1903 memcpy_fromio(&local->bss_id,pccs->var.start_network.bssid,ADDRLEN);
1905 if (local->fw_ver == 0x55) local->net_default_tx_rate = 3;
1906 else local->net_default_tx_rate =
1907 readb(&pccs->var.start_network.net_default_tx_rate);
1908 local->encryption = readb(&pccs->var.start_network.encryption);
1909 if (!sniffer && (local->net_type == INFRA)
1910 && !(local->sparm.b4.a_acting_as_ap_status)) {
1911 authenticate(local);
1913 local->card_status = CARD_ACQ_COMPLETE;
1915 else {
1916 local->card_status = CARD_ACQ_FAILED;
1918 del_timer(&local->timer);
1919 local->timer.expires = jiffies + HZ*5;
1920 local->timer.data = (long)local;
1921 if (status == CCS_START_NETWORK) {
1922 DEBUG(0,"ray_cs interrupt network \"%s\" start failed\n",\
1923 local->sparm.b4.a_current_ess_id);
1924 local->timer.function = &start_net;
1926 else {
1927 DEBUG(0,"ray_cs interrupt network \"%s\" join failed\n",\
1928 local->sparm.b4.a_current_ess_id);
1929 local->timer.function = &join_net;
1931 add_timer(&local->timer);
1933 break;
1934 case CCS_START_ASSOCIATION:
1935 if (status == CCS_COMMAND_COMPLETE) {
1936 local->card_status = CARD_ASSOC_COMPLETE;
1937 DEBUG(0,"ray_cs association successful\n");
1939 else
1941 DEBUG(0,"ray_cs association failed,\n");
1942 local->card_status = CARD_ASSOC_FAILED;
1943 join_net((u_long)local);
1945 break;
1946 case CCS_TX_REQUEST:
1947 if (status == CCS_COMMAND_COMPLETE) {
1948 DEBUG(3,"ray_cs interrupt tx request complete\n");
1950 else {
1951 DEBUG(1,"ray_cs interrupt tx request failed\n");
1953 if (!sniffer) netif_start_queue(dev);
1954 netif_wake_queue(dev);
1955 break;
1956 case CCS_TEST_MEMORY:
1957 DEBUG(1,"ray_cs interrupt mem test done\n");
1958 break;
1959 case CCS_SHUTDOWN:
1960 DEBUG(1,"ray_cs interrupt Unexpected CCS returned - Shutdown\n");
1961 break;
1962 case CCS_DUMP_MEMORY:
1963 DEBUG(1,"ray_cs interrupt dump memory done\n");
1964 break;
1965 case CCS_START_TIMER:
1966 DEBUG(2,"ray_cs interrupt DING - raylink timer expired\n");
1967 break;
1968 default:
1969 DEBUG(1,"ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",\
1970 rcsindex, cmd);
1972 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1974 else /* It's an RCS */
1976 prcs = ((struct rcs *)(local->sram + CCS_BASE)) + rcsindex;
1978 switch (readb(&prcs->interrupt_id))
1980 case PROCESS_RX_PACKET:
1981 ray_rx(dev, local, prcs);
1982 break;
1983 case REJOIN_NET_COMPLETE:
1984 DEBUG(1,"ray_cs interrupt rejoin net complete\n");
1985 local->card_status = CARD_ACQ_COMPLETE;
1986 /* do we need to clear tx buffers CCS's? */
1987 if (local->sparm.b4.a_network_type == ADHOC) {
1988 if (!sniffer) netif_start_queue(dev);
1990 else {
1991 memcpy_fromio(&local->bss_id, prcs->var.rejoin_net_complete.bssid, ADDRLEN);
1992 DEBUG(1,"ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",\
1993 local->bss_id[0], local->bss_id[1], local->bss_id[2],\
1994 local->bss_id[3], local->bss_id[4], local->bss_id[5]);
1995 if (!sniffer) authenticate(local);
1997 break;
1998 case ROAMING_INITIATED:
1999 DEBUG(1,"ray_cs interrupt roaming initiated\n");
2000 netif_stop_queue(dev);
2001 local->card_status = CARD_DOING_ACQ;
2002 break;
2003 case JAPAN_CALL_SIGN_RXD:
2004 DEBUG(1,"ray_cs interrupt japan call sign rx\n");
2005 break;
2006 default:
2007 DEBUG(1,"ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",\
2008 rcsindex, (unsigned int) readb(&prcs->interrupt_id));
2009 break;
2011 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2013 clear_interrupt(local);
2014 } /* ray_interrupt */
2015 /*===========================================================================*/
2016 static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs *prcs)
2018 int rx_len;
2019 unsigned int pkt_addr;
2020 UCHAR *pmsg;
2021 DEBUG(4,"ray_rx process rx packet\n");
2023 /* Calculate address of packet within Rx buffer */
2024 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2025 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2026 /* Length of first packet fragment */
2027 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2028 + readb(&prcs->var.rx_packet.rx_data_length[1]);
2030 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2031 pmsg = local->rmem + pkt_addr;
2032 switch(readb(pmsg))
2034 case DATA_TYPE:
2035 DEBUG(4,"ray_rx data type\n");
2036 rx_data(dev, prcs, pkt_addr, rx_len);
2037 break;
2038 case AUTHENTIC_TYPE:
2039 DEBUG(4,"ray_rx authentic type\n");
2040 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
2041 else rx_authenticate(local, prcs, pkt_addr, rx_len);
2042 break;
2043 case DEAUTHENTIC_TYPE:
2044 DEBUG(4,"ray_rx deauth type\n");
2045 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
2046 else rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2047 break;
2048 case NULL_MSG_TYPE:
2049 DEBUG(3,"ray_cs rx NULL msg\n");
2050 break;
2051 case BEACON_TYPE:
2052 DEBUG(4,"ray_rx beacon type\n");
2053 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
2055 copy_from_rx_buff(local, (UCHAR *)&local->last_bcn, pkt_addr,
2056 rx_len < sizeof(struct beacon_rx) ?
2057 rx_len : sizeof(struct beacon_rx));
2059 local->beacon_rxed = 1;
2060 /* Get the statistics so the card counters never overflow */
2061 ray_get_stats(dev);
2062 break;
2063 default:
2064 DEBUG(0,"ray_cs unknown pkt type %2x\n", (unsigned int) readb(pmsg));
2065 break;
2068 } /* end ray_rx */
2069 /*===========================================================================*/
2070 static void rx_data(struct net_device *dev, struct rcs *prcs, unsigned int pkt_addr,
2071 int rx_len)
2073 struct sk_buff *skb = NULL;
2074 struct rcs *prcslink = prcs;
2075 ray_dev_t *local = dev->priv;
2076 UCHAR *rx_ptr;
2077 int total_len;
2078 int tmp;
2079 #ifdef WIRELESS_SPY
2080 int siglev = local->last_rsl;
2081 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
2082 #endif
2084 if (!sniffer) {
2085 if (translate) {
2086 /* TBD length needs fixing for translated header */
2087 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2088 rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))
2090 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
2091 return;
2094 else /* encapsulated ethernet */ {
2095 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2096 rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))
2098 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
2099 return;
2103 DEBUG(4,"ray_cs rx_data packet\n");
2104 /* If fragmented packet, verify sizes of fragments add up */
2105 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2106 DEBUG(1,"ray_cs rx'ed fragment\n");
2107 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2108 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2109 total_len = tmp;
2110 prcslink = prcs;
2111 do {
2112 tmp -= (readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8)
2113 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2114 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index) == 0xFF
2115 || tmp < 0) break;
2116 prcslink = ((struct rcs *)(local->sram + CCS_BASE))
2117 + readb(&prcslink->link_field);
2118 } while (1);
2120 if (tmp < 0)
2122 DEBUG(0,"ray_cs rx_data fragment lengths don't add up\n");
2123 local->stats.rx_dropped++;
2124 release_frag_chain(local, prcs);
2125 return;
2128 else { /* Single unfragmented packet */
2129 total_len = rx_len;
2132 skb = dev_alloc_skb( total_len+5 );
2133 if (skb == NULL)
2135 DEBUG(0,"ray_cs rx_data could not allocate skb\n");
2136 local->stats.rx_dropped++;
2137 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2138 release_frag_chain(local, prcs);
2139 return;
2141 skb_reserve( skb, 2); /* Align IP on 16 byte (TBD check this)*/
2142 skb->dev = dev;
2144 DEBUG(4,"ray_cs rx_data total_len = %x, rx_len = %x\n",total_len,rx_len);
2146 /************************/
2147 /* Reserve enough room for the whole damn packet. */
2148 rx_ptr = skb_put( skb, total_len);
2149 /* Copy the whole packet to sk_buff */
2150 rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2151 /* Get source address */
2152 #ifdef WIRELESS_SPY
2153 memcpy(linksrcaddr, ((struct mac_header *)skb->data)->addr_2, ETH_ALEN);
2154 #endif
2155 /* Now, deal with encapsulation/translation/sniffer */
2156 if (!sniffer) {
2157 if (!translate) {
2158 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
2159 /* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
2160 skb_pull( skb, RX_MAC_HEADER_LENGTH);
2162 else {
2163 /* Do translation */
2164 untranslate(local, skb, total_len);
2167 else
2168 { /* sniffer mode, so just pass whole packet */ };
2170 /************************/
2171 /* Now pick up the rest of the fragments if any */
2172 tmp = 17;
2173 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2174 prcslink = prcs;
2175 DEBUG(1,"ray_cs rx_data in fragment loop\n");
2176 do {
2177 prcslink = ((struct rcs *)(local->sram + CCS_BASE))
2178 + readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2179 rx_len = (( readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8)
2180 + readb(&prcslink->var.rx_packet.rx_data_length[1]))
2181 & RX_BUFF_END;
2182 pkt_addr = (( readb(&prcslink->var.rx_packet.rx_data_ptr[0]) << 8)
2183 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2184 & RX_BUFF_END;
2186 rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
2188 } while (tmp-- &&
2189 readb(&prcslink->var.rx_packet.next_frag_rcs_index) != 0xFF);
2190 release_frag_chain(local, prcs);
2193 skb->protocol = eth_type_trans(skb,dev);
2194 netif_rx(skb);
2196 local->stats.rx_packets++;
2197 local->stats.rx_bytes += skb->len;
2199 /* Gather signal strength per address */
2200 #ifdef WIRELESS_SPY
2201 /* For the Access Point or the node having started the ad-hoc net
2202 * note : ad-hoc work only in some specific configurations, but we
2203 * kludge in ray_get_wireless_stats... */
2204 if(!memcmp(linksrcaddr, local->bss_id, ETH_ALEN))
2206 /* Update statistics */
2207 /*local->wstats.qual.qual = none ? */
2208 local->wstats.qual.level = siglev;
2209 /*local->wstats.qual.noise = none ? */
2210 local->wstats.qual.updated = 0x2;
2212 /* Now, for the addresses in the spy list */
2214 int i;
2215 /* Look all addresses */
2216 for(i = 0; i < local->spy_number; i++)
2217 /* If match */
2218 if(!memcmp(linksrcaddr, local->spy_address[i], ETH_ALEN))
2220 /* Update statistics */
2221 /*local->spy_stat[i].qual = none ? */
2222 local->spy_stat[i].level = siglev;
2223 /*local->spy_stat[i].noise = none ? */
2224 local->spy_stat[i].updated = 0x2;
2227 #endif /* WIRELESS_SPY */
2228 } /* end rx_data */
2229 /*===========================================================================*/
2230 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2232 snaphdr_t *psnap = (snaphdr_t *)(skb->data + RX_MAC_HEADER_LENGTH);
2233 struct mac_header *pmac = (struct mac_header *)skb->data;
2234 unsigned short type = *(unsigned short *)psnap->ethertype;
2235 unsigned int xsap = *(unsigned int *)psnap & 0x00ffffff;
2236 unsigned int org = (*(unsigned int *)psnap->org) & 0x00ffffff;
2237 int delta;
2238 struct ethhdr *peth;
2239 UCHAR srcaddr[ADDRLEN];
2240 UCHAR destaddr[ADDRLEN];
2242 if (pmac->frame_ctl_2 & FC2_FROM_DS) {
2243 if (pmac->frame_ctl_2 & FC2_TO_DS) { /* AP to AP */
2244 memcpy(destaddr, pmac->addr_3, ADDRLEN);
2245 memcpy(srcaddr, ((unsigned char *)pmac->addr_3) + ADDRLEN, ADDRLEN);
2246 } else { /* AP to terminal */
2247 memcpy(destaddr, pmac->addr_1, ADDRLEN);
2248 memcpy(srcaddr, pmac->addr_3, ADDRLEN);
2250 } else { /* Terminal to AP */
2251 if (pmac->frame_ctl_2 & FC2_TO_DS) {
2252 memcpy(destaddr, pmac->addr_3, ADDRLEN);
2253 memcpy(srcaddr, pmac->addr_2, ADDRLEN);
2254 } else { /* Adhoc */
2255 memcpy(destaddr, pmac->addr_1, ADDRLEN);
2256 memcpy(srcaddr, pmac->addr_2, ADDRLEN);
2260 #ifdef PCMCIA_DEBUG
2261 if (pc_debug > 3) {
2262 int i;
2263 printk(KERN_DEBUG "skb->data before untranslate");
2264 for (i=0;i<64;i++)
2265 printk("%02x ",skb->data[i]);
2266 printk("\n" KERN_DEBUG "type = %08x, xsap = %08x, org = %08x\n",
2267 type,xsap,org);
2268 printk(KERN_DEBUG "untranslate skb->data = %p\n",skb->data);
2270 #endif
2272 if ( xsap != SNAP_ID) {
2273 /* not a snap type so leave it alone */
2274 DEBUG(3,"ray_cs untranslate NOT SNAP %x\n", *(unsigned int *)psnap & 0x00ffffff);
2276 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2277 peth = (struct ethhdr *)(skb->data + delta);
2278 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2280 else { /* Its a SNAP */
2281 if (org == BRIDGE_ENCAP) { /* EtherII and nuke the LLC */
2282 DEBUG(3,"ray_cs untranslate Bridge encap\n");
2283 delta = RX_MAC_HEADER_LENGTH
2284 + sizeof(struct snaphdr_t) - ETH_HLEN;
2285 peth = (struct ethhdr *)(skb->data + delta);
2286 peth->h_proto = type;
2288 else {
2289 if (org == RFC1042_ENCAP) {
2290 switch (type) {
2291 case RAY_IPX_TYPE:
2292 case APPLEARP_TYPE:
2293 DEBUG(3,"ray_cs untranslate RFC IPX/AARP\n");
2294 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2295 peth = (struct ethhdr *)(skb->data + delta);
2296 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2297 break;
2298 default:
2299 DEBUG(3,"ray_cs untranslate RFC default\n");
2300 delta = RX_MAC_HEADER_LENGTH +
2301 sizeof(struct snaphdr_t) - ETH_HLEN;
2302 peth = (struct ethhdr *)(skb->data + delta);
2303 peth->h_proto = type;
2304 break;
2307 else {
2308 printk("ray_cs untranslate very confused by packet\n");
2309 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2310 peth = (struct ethhdr *)(skb->data + delta);
2311 peth->h_proto = type;
2315 /* TBD reserve skb_reserve(skb, delta); */
2316 skb_pull(skb, delta);
2317 DEBUG(3,"untranslate after skb_pull(%d), skb->data = %p\n",delta,skb->data);
2318 memcpy(peth->h_dest, destaddr, ADDRLEN);
2319 memcpy(peth->h_source, srcaddr, ADDRLEN);
2320 #ifdef PCMCIA_DEBUG
2321 if (pc_debug > 3) {
2322 int i;
2323 printk(KERN_DEBUG "skb->data after untranslate:");
2324 for (i=0;i<64;i++)
2325 printk("%02x ",skb->data[i]);
2326 printk("\n");
2328 #endif
2329 } /* end untranslate */
2330 /*===========================================================================*/
2331 /* Copy data from circular receive buffer to PC memory.
2332 * dest = destination address in PC memory
2333 * pkt_addr = source address in receive buffer
2334 * len = length of packet to copy
2336 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int length)
2338 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2339 if (wrap_bytes <= 0)
2341 memcpy_fromio(dest,local->rmem + pkt_addr,length);
2343 else /* Packet wrapped in circular buffer */
2345 memcpy_fromio(dest,local->rmem+pkt_addr,length - wrap_bytes);
2346 memcpy_fromio(dest + length - wrap_bytes, local->rmem, wrap_bytes);
2348 return length;
2350 /*===========================================================================*/
2351 static void release_frag_chain(ray_dev_t *local, struct rcs* prcs)
2353 struct rcs *prcslink = prcs;
2354 int tmp = 17;
2355 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2357 while (tmp--) {
2358 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2359 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
2360 DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
2361 break;
2363 prcslink = ((struct rcs *)(local->sram + CCS_BASE)) + rcsindex;
2364 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2366 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2368 /*===========================================================================*/
2369 static void authenticate(ray_dev_t *local)
2371 dev_link_t *link = local->finder;
2372 DEBUG(0,"ray_cs Starting authentication.\n");
2373 if (!(link->state & DEV_PRESENT)) {
2374 DEBUG(2,"ray_cs authenticate - device not present\n");
2375 return;
2378 del_timer(&local->timer);
2379 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2380 local->timer.function = &join_net;
2382 else {
2383 local->timer.function = &authenticate_timeout;
2385 local->timer.expires = jiffies + HZ*2;
2386 local->timer.data = (long)local;
2387 add_timer(&local->timer);
2388 local->authentication_state = AWAITING_RESPONSE;
2389 } /* end authenticate */
2390 /*===========================================================================*/
2391 static void rx_authenticate(ray_dev_t *local, struct rcs *prcs,
2392 unsigned int pkt_addr, int rx_len)
2394 UCHAR buff[256];
2395 struct rx_msg *msg = (struct rx_msg *)buff;
2397 del_timer(&local->timer);
2399 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2400 /* if we are trying to get authenticated */
2401 if (local->sparm.b4.a_network_type == ADHOC) {
2402 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]);
2403 if (msg->var[2] == 1) {
2404 DEBUG(0,"ray_cs Sending authentication response.\n");
2405 if (!build_auth_frame (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2406 local->authentication_state = NEED_TO_AUTH;
2407 memcpy(local->auth_id, msg->mac.addr_2, ADDRLEN);
2411 else /* Infrastructure network */
2413 if (local->authentication_state == AWAITING_RESPONSE) {
2414 /* Verify authentication sequence #2 and success */
2415 if (msg->var[2] == 2) {
2416 if ((msg->var[3] | msg->var[4]) == 0) {
2417 DEBUG(1,"Authentication successful\n");
2418 local->card_status = CARD_AUTH_COMPLETE;
2419 associate(local);
2420 local->authentication_state = AUTHENTICATED;
2422 else {
2423 DEBUG(0,"Authentication refused\n");
2424 local->card_status = CARD_AUTH_REFUSED;
2425 join_net((u_long)local);
2426 local->authentication_state = UNAUTHENTICATED;
2432 } /* end rx_authenticate */
2433 /*===========================================================================*/
2434 static void associate(ray_dev_t *local)
2436 struct ccs *pccs;
2437 dev_link_t *link = local->finder;
2438 struct net_device *dev = link->priv;
2439 int ccsindex;
2440 if (!(link->state & DEV_PRESENT)) {
2441 DEBUG(2,"ray_cs associate - device not present\n");
2442 return;
2444 /* If no tx buffers available, return*/
2445 if ((ccsindex = get_free_ccs(local)) < 0)
2447 /* TBD should never be here but... what if we are? */
2448 DEBUG(1,"ray_cs associate - No free ccs\n");
2449 return;
2451 DEBUG(1,"ray_cs Starting association with access point\n");
2452 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
2453 /* fill in the CCS */
2454 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2455 /* Interrupt the firmware to process the command */
2456 if (interrupt_ecf(local, ccsindex)) {
2457 DEBUG(1,"ray_cs associate failed - ECF not ready for intr\n");
2458 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2460 del_timer(&local->timer);
2461 local->timer.expires = jiffies + HZ*2;
2462 local->timer.data = (long)local;
2463 local->timer.function = &join_net;
2464 add_timer(&local->timer);
2465 local->card_status = CARD_ASSOC_FAILED;
2466 return;
2468 if (!sniffer) netif_start_queue(dev);
2470 } /* end associate */
2471 /*===========================================================================*/
2472 static void rx_deauthenticate(ray_dev_t *local, struct rcs *prcs,
2473 unsigned int pkt_addr, int rx_len)
2475 /* UCHAR buff[256];
2476 struct rx_msg *msg = (struct rx_msg *)buff;
2478 DEBUG(0,"Deauthentication frame received\n");
2479 local->authentication_state = UNAUTHENTICATED;
2480 /* Need to reauthenticate or rejoin depending on reason code */
2481 /* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2484 /*===========================================================================*/
2485 static void clear_interrupt(ray_dev_t *local)
2487 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
2489 /*===========================================================================*/
2490 #ifdef CONFIG_PROC_FS
2491 #define MAXDATA (PAGE_SIZE - 80)
2493 static char *card_status[] = {
2494 "Card inserted - uninitialized", /* 0 */
2495 "Card not downloaded", /* 1 */
2496 "Waiting for download parameters", /* 2 */
2497 "Card doing acquisition", /* 3 */
2498 "Acquisition complete", /* 4 */
2499 "Authentication complete", /* 5 */
2500 "Association complete", /* 6 */
2501 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2502 "Card init error", /* 11 */
2503 "Download parameters error", /* 12 */
2504 "???", /* 13 */
2505 "Acquisition failed", /* 14 */
2506 "Authentication refused", /* 15 */
2507 "Association failed" /* 16 */
2510 static char *nettype[] = {"Adhoc", "Infra "};
2511 static char *framing[] = {"Encapsulation", "Translation"}
2513 /*===========================================================================*/
2514 static int ray_cs_proc_read(char *buf, char **start, off_t offset, int len)
2516 /* Print current values which are not available via other means
2517 * eg ifconfig
2519 int i;
2520 dev_link_t *link;
2521 struct net_device *dev;
2522 ray_dev_t *local;
2523 UCHAR *p;
2524 struct freq_hop_element *pfh;
2525 UCHAR c[33];
2527 link = dev_list;
2528 if (!link)
2529 return 0;
2530 dev = (struct net_device *)link->priv;
2531 if (!dev)
2532 return 0;
2533 local = (ray_dev_t *)dev->priv;
2534 if (!local)
2535 return 0;
2537 len = 0;
2539 len += sprintf(buf + len, "Raylink Wireless LAN driver status\n");
2540 len += sprintf(buf + len, "%s\n", rcsid);
2541 /* build 4 does not report version, and field is 0x55 after memtest */
2542 len += sprintf(buf + len, "Firmware version = ");
2543 if (local->fw_ver == 0x55)
2544 len += sprintf(buf + len, "4 - Use dump_cis for more details\n");
2545 else
2546 len += sprintf(buf + len, "%2d.%02d.%02d\n",
2547 local->fw_ver, local->fw_bld, local->fw_var);
2549 for (i=0; i<32; i++) c[i] = local->sparm.b5.a_current_ess_id[i];
2550 c[32] = 0;
2551 len += sprintf(buf + len, "%s network ESSID = \"%s\"\n",
2552 nettype[local->sparm.b5.a_network_type], c);
2554 p = local->bss_id;
2555 len += sprintf(buf + len,
2556 "BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
2557 p[0],p[1],p[2],p[3],p[4],p[5]);
2559 len += sprintf(buf + len, "Country code = %d\n",
2560 local->sparm.b5.a_curr_country_code);
2562 i = local->card_status;
2563 if (i < 0) i = 10;
2564 if (i > 16) i = 10;
2565 len += sprintf(buf + len, "Card status = %s\n", card_status[i]);
2567 len += sprintf(buf + len, "Framing mode = %s\n",framing[translate]);
2569 len += sprintf(buf + len, "Last pkt signal lvl = %d\n", local->last_rsl);
2571 if (local->beacon_rxed) {
2572 /* Pull some fields out of last beacon received */
2573 len += sprintf(buf + len, "Beacon Interval = %d Kus\n",
2574 local->last_bcn.beacon_intvl[0]
2575 + 256 * local->last_bcn.beacon_intvl[1]);
2577 p = local->last_bcn.elements;
2578 if (p[0] == C_ESSID_ELEMENT_ID) p += p[1] + 2;
2579 else {
2580 len += sprintf(buf + len, "Parse beacon failed at essid element id = %d\n",p[0]);
2581 return len;
2584 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2585 len += sprintf(buf + len, "Supported rate codes = ");
2586 for (i=2; i<p[1] + 2; i++)
2587 len += sprintf(buf + len, "0x%02x ", p[i]);
2588 len += sprintf(buf + len, "\n");
2589 p += p[1] + 2;
2591 else {
2592 len += sprintf(buf + len, "Parse beacon failed at rates element\n");
2593 return len;
2596 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2597 pfh = (struct freq_hop_element *)p;
2598 len += sprintf(buf + len, "Hop dwell = %d Kus\n",
2599 pfh->dwell_time[0] + 256 * pfh->dwell_time[1]);
2600 len += sprintf(buf + len, "Hop set = %d \n", pfh->hop_set);
2601 len += sprintf(buf + len, "Hop pattern = %d \n", pfh->hop_pattern);
2602 len += sprintf(buf + len, "Hop index = %d \n", pfh->hop_index);
2603 p += p[1] + 2;
2605 else {
2606 len += sprintf(buf + len, "Parse beacon failed at FH param element\n");
2607 return len;
2609 } else {
2610 len += sprintf(buf + len, "No beacons received\n");
2612 return len;
2615 #endif
2616 /*===========================================================================*/
2617 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2619 int addr;
2620 struct ccs *pccs;
2621 struct tx_msg *ptx;
2622 int ccsindex;
2624 /* If no tx buffers available, return */
2625 if ((ccsindex = get_free_tx_ccs(local)) < 0)
2627 DEBUG(1,"ray_cs send authenticate - No free tx ccs\n");
2628 return -1;
2631 pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;
2633 /* Address in card space */
2634 addr = TX_BUF_BASE + (ccsindex << 11);
2635 /* fill in the CCS */
2636 writeb(CCS_TX_REQUEST, &pccs->cmd);
2637 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2638 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2639 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2640 writeb(TX_AUTHENTICATE_LENGTH_LSB,pccs->var.tx_request.tx_data_length + 1);
2641 writeb(0, &pccs->var.tx_request.pow_sav_mode);
2643 ptx = (struct tx_msg *)(local->sram + addr);
2644 /* fill in the mac header */
2645 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2646 writeb(0, &ptx->mac.frame_ctl_2);
2648 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2649 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2650 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
2652 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2653 memset_io(ptx->var, 0, 6);
2654 writeb(auth_type & 0xff, ptx->var + 2);
2656 /* Interrupt the firmware to process the command */
2657 if (interrupt_ecf(local, ccsindex)) {
2658 DEBUG(1,"ray_cs send authentication request failed - ECF not ready for intr\n");
2659 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2660 return -1;
2662 return 0;
2663 } /* End build_auth_frame */
2665 /*===========================================================================*/
2666 #ifdef CONFIG_PROC_FS
2667 static void raycs_write(const char *name, write_proc_t *w, void *data)
2669 struct proc_dir_entry * entry = create_proc_entry(name, S_IFREG | S_IWUSR, NULL);
2670 if (entry) {
2671 entry->write_proc = w;
2672 entry->data = data;
2676 static int write_essid(struct file *file, const char *buffer, unsigned long count, void *data)
2678 static char proc_essid[33];
2679 int len = count;
2681 if (len > 32)
2682 len = 32;
2683 memset(proc_essid, 0, 33);
2684 if (copy_from_user(proc_essid, buffer, len))
2685 return -EFAULT;
2686 essid = proc_essid;
2687 return count;
2690 static int write_int(struct file *file, const char *buffer, unsigned long count, void *data)
2692 static char proc_number[10];
2693 char *p;
2694 int nr, len;
2696 if (!count)
2697 return 0;
2699 if (count > 9)
2700 return -EINVAL;
2701 if (copy_from_user(proc_number, buffer, count))
2702 return -EFAULT;
2703 p = proc_number;
2704 nr = 0;
2705 len = count;
2706 do {
2707 unsigned int c = *p - '0';
2708 if (c > 9)
2709 return -EINVAL;
2710 nr = nr*10 + c;
2711 p++;
2712 } while (--len);
2713 *(int *)data = nr;
2714 return count;
2716 #endif
2718 static int __init init_ray_cs(void)
2720 int rc;
2722 DEBUG(1, "%s\n", rcsid);
2723 rc = register_pcmcia_driver(&dev_info, &ray_attach, &ray_detach);
2724 DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n",rc);
2726 #ifdef CONFIG_PROC_FS
2727 proc_mkdir("driver/ray_cs", 0);
2729 create_proc_info_entry("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_read);
2730 raycs_write("driver/ray_cs/essid", write_essid, NULL);
2731 raycs_write("driver/ray_cs/net_type", write_int, &net_type);
2732 raycs_write("driver/ray_cs/translate", write_int, &translate);
2733 #endif
2734 if (translate != 0) translate = 1;
2735 return 0;
2736 } /* init_ray_cs */
2738 /*===========================================================================*/
2740 static void __exit exit_ray_cs(void)
2742 DEBUG(0, "ray_cs: cleanup_module\n");
2745 #ifdef CONFIG_PROC_FS
2746 remove_proc_entry("ray_cs", proc_root_driver);
2747 #endif
2749 unregister_pcmcia_driver(&dev_info);
2750 while (dev_list != NULL) {
2751 if (dev_list->state & DEV_CONFIG) ray_release((u_long)dev_list);
2752 ray_detach(dev_list);
2754 #ifdef CONFIG_PROC_FS
2755 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2756 remove_proc_entry("driver/ray_cs/essid", NULL);
2757 remove_proc_entry("driver/ray_cs/net_type", NULL);
2758 remove_proc_entry("driver/ray_cs/translate", NULL);
2759 remove_proc_entry("driver/ray_cs", NULL);
2760 #endif
2761 } /* exit_ray_cs */
2763 module_init(init_ray_cs);
2764 module_exit(exit_ray_cs);
2766 /*===========================================================================*/