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