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