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