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