1 /*=============================================================================
3 * A PCMCIA client driver for the Raylink wireless LAN card.
4 * The starting point for this module was the skeleton.c in the
5 * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net
8 * Copyright (c) 1998 Corey Thomas (corey@world.std.com)
10 * This driver is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 only of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * It is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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
28 * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003
29 * - Audit copy_to_user in ioctl(SIOCGIWESSID)
31 =============================================================================*/
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/proc_fs.h>
37 #include <linux/ptrace.h>
38 #include <linux/slab.h>
39 #include <linux/string.h>
40 #include <linux/timer.h>
41 #include <linux/init.h>
42 #include <linux/netdevice.h>
43 #include <linux/etherdevice.h>
44 #include <linux/if_arp.h>
45 #include <linux/ioport.h>
46 #include <linux/skbuff.h>
47 #include <linux/ethtool.h>
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>
56 #include <net/ieee80211.h>
57 #include <linux/wireless.h>
60 #include <asm/system.h>
61 #include <asm/byteorder.h>
62 #include <asm/uaccess.h>
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 */
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.
81 #define PCMCIA_DEBUG RAYLINK_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);
90 #define DEBUG(n, args...)
92 /** Prototypes based on PCMCIA skeleton driver *******************************/
93 static void ray_config(dev_link_t *link);
94 static void ray_release(dev_link_t *link);
95 static void ray_detach(struct pcmcia_device *p_dev);
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);
103 static struct ethtool_ops netdev_ethtool_ops;
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;
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);
133 /* Prototypes for interrpt time functions **********************************/
134 static irqreturn_t ray_interrupt (int reg, void *dev_id, struct pt_regs *regs);
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,
145 static void associate(ray_dev_t *local);
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); */
153 /*===========================================================================*/
154 /* Parameters that can be set with 'insmod' */
156 /* ADHOC=0, Infrastructure=1 */
157 static int net_type = ADHOC;
159 /* Hop dwell time in Kus (1024 us units defined by 802.11) */
160 static int hop_dwell = 128;
162 /* Beacon period in Kus */
163 static int beacon_period = 256;
165 /* power save mode (0 = off, 1 = save power) */
168 /* String for network's Extended Service Set ID. 32 Characters max */
171 /* Default to encapsulation unless translation requested */
172 static int translate = 1;
174 static int country = USA;
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.
190 static char *phy_addr = NULL;
193 /* A linked list of "instances" of the ray device. Each actual
194 PCMCIA card corresponds to one device instance, and is described
195 by one dev_link_t structure (defined in ds.h).
197 static dev_link_t *dev_list = NULL;
199 /* A dev_link_t structure has fields for most things that are needed
200 to keep track of a socket, but there will usually be some device
201 specific information that also needs to be kept track of. The
202 'priv' pointer in a dev_link_t structure can be used to point to
203 a device-specific private data structure, like this.
205 static unsigned int ray_mem_speed = 500;
207 MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
208 MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
209 MODULE_LICENSE("GPL");
211 module_param(net_type, int, 0);
212 module_param(hop_dwell, int, 0);
213 module_param(beacon_period, int, 0);
214 module_param(psm, int, 0);
215 module_param(essid, charp, 0);
216 module_param(translate, int, 0);
217 module_param(country, int, 0);
218 module_param(sniffer, int, 0);
219 module_param(bc, int, 0);
220 module_param(phy_addr, charp, 0);
221 module_param(ray_mem_speed, int, 0);
223 static UCHAR b5_default_startup_parms[] = {
224 0, 0, /* Adhoc station */
225 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
226 0, 0, 0, 0, 0, 0, 0, 0,
227 0, 0, 0, 0, 0, 0, 0, 0,
228 0, 0, 0, 0, 0, 0, 0, 0,
229 1, 0, /* Active scan, CA Mode */
230 0, 0, 0, 0, 0, 0, /* No default MAC addr */
231 0x7f, 0xff, /* Frag threshold */
232 0x00, 0x80, /* Hop time 128 Kus*/
233 0x01, 0x00, /* Beacon period 256 Kus */
234 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
235 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
236 0x7f, 0xff, /* RTS threshold */
237 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
238 0x05, /* assoc resp timeout thresh */
239 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max*/
240 0, /* Promiscuous mode */
241 0x0c, 0x0bd, /* Unique word */
242 0x32, /* Slot time */
243 0xff, 0xff, /* roam-low snr, low snr count */
244 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
245 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
246 /* b4 - b5 differences start here */
247 0x00, 0x3f, /* CW max */
248 0x00, 0x0f, /* CW min */
249 0x04, 0x08, /* Noise gain, limit offset */
250 0x28, 0x28, /* det rssi, med busy offsets */
251 7, /* det sync thresh */
252 0, 2, 2, /* test mode, min, max */
253 0, /* allow broadcast SSID probe resp */
254 0, 0, /* privacy must start, can join */
255 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
258 static UCHAR b4_default_startup_parms[] = {
259 0, 0, /* Adhoc station */
260 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
261 0, 0, 0, 0, 0, 0, 0, 0,
262 0, 0, 0, 0, 0, 0, 0, 0,
263 0, 0, 0, 0, 0, 0, 0, 0,
264 1, 0, /* Active scan, CA Mode */
265 0, 0, 0, 0, 0, 0, /* No default MAC addr */
266 0x7f, 0xff, /* Frag threshold */
267 0x02, 0x00, /* Hop time */
268 0x00, 0x01, /* Beacon period */
269 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
270 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
271 0x7f, 0xff, /* RTS threshold */
272 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
273 0x05, /* assoc resp timeout thresh */
274 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max*/
275 0, /* Promiscuous mode */
276 0x0c, 0x0bd, /* Unique word */
277 0x4e, /* Slot time (TBD seems wrong)*/
278 0xff, 0xff, /* roam-low snr, low snr count */
279 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
280 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
281 /* b4 - b5 differences start here */
282 0x3f, 0x0f, /* CW max, min */
283 0x04, 0x08, /* Noise gain, limit offset */
284 0x28, 0x28, /* det rssi, med busy offsets */
285 7, /* det sync thresh */
286 0, 2, 2 /* test mode, min, max*/
288 /*===========================================================================*/
289 static unsigned char eth2_llc[] = {0xaa, 0xaa, 3, 0, 0, 0};
291 static char hop_pattern_length[] = { 1,
292 USA_HOP_MOD, EUROPE_HOP_MOD,
293 JAPAN_HOP_MOD, KOREA_HOP_MOD,
294 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
295 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
299 static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
301 /*=============================================================================
302 ray_attach() creates an "instance" of the driver, allocating
303 local data structures for one device. The device is registered
305 The dev_link structure is initialized, but we don't actually
306 configure the card at this point -- we wait until we receive a
307 card insertion event.
308 =============================================================================*/
309 static int ray_attach(struct pcmcia_device *p_dev)
313 struct net_device *dev;
315 DEBUG(1, "ray_attach()\n");
317 /* Initialize the dev_link_t structure */
318 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
323 /* Allocate space for private device-specific data */
324 dev = alloc_etherdev(sizeof(ray_dev_t));
331 memset(link, 0, sizeof(struct dev_link_t));
333 /* The io structure describes IO port mapping. None used here */
334 link->io.NumPorts1 = 0;
335 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
336 link->io.IOAddrLines = 5;
338 /* Interrupt setup. For PCMCIA, driver takes what's given */
339 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
340 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
341 link->irq.Handler = &ray_interrupt;
343 /* General socket configuration */
344 link->conf.Attributes = CONF_ENABLE_IRQ;
345 link->conf.IntType = INT_MEMORY_AND_IO;
346 link->conf.ConfigIndex = 1;
347 link->conf.Present = PRESENT_OPTION;
350 link->irq.Instance = dev;
352 local->finder = link;
353 local->card_status = CARD_INSERTED;
354 local->authentication_state = UNAUTHENTICATED;
355 local->num_multi = 0;
356 DEBUG(2,"ray_attach link = %p, dev = %p, local = %p, intr = %p\n",
357 link,dev,local,&ray_interrupt);
359 /* Raylink entries in the device structure */
360 dev->hard_start_xmit = &ray_dev_start_xmit;
361 dev->set_config = &ray_dev_config;
362 dev->get_stats = &ray_get_stats;
363 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
364 dev->wireless_handlers = &ray_handler_def;
366 local->wireless_data.spy_data = &local->spy_data;
367 dev->wireless_data = &local->wireless_data;
368 #endif /* WIRELESS_SPY */
370 dev->set_multicast_list = &set_multicast_list;
372 DEBUG(2,"ray_cs ray_attach calling ether_setup.)\n");
373 SET_MODULE_OWNER(dev);
374 dev->init = &ray_dev_init;
375 dev->open = &ray_open;
376 dev->stop = &ray_dev_close;
377 netif_stop_queue(dev);
379 init_timer(&local->timer);
381 link->handle = p_dev;
382 p_dev->instance = link;
384 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
393 /*=============================================================================
394 This deletes a driver "instance". The device is de-registered
395 with Card Services. If it has been released, all local data
396 structures are freed. Otherwise, the structures will be freed
397 when the device is released.
398 =============================================================================*/
399 static void ray_detach(struct pcmcia_device *p_dev)
401 dev_link_t *link = dev_to_instance(p_dev);
403 struct net_device *dev;
406 DEBUG(1, "ray_detach(0x%p)\n", link);
408 /* Locate device structure */
409 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
410 if (*linkp == link) break;
416 if (link->state & DEV_CONFIG) {
419 local = (ray_dev_t *)dev->priv;
420 del_timer(&local->timer);
423 /* Unlink device structure, free pieces */
426 if (link->dev) unregister_netdev(dev);
430 DEBUG(2,"ray_cs ray_detach ending\n");
432 /*=============================================================================
433 ray_config() is run after a CARD_INSERTION event
434 is received, to configure the PCMCIA socket, and to make the
435 ethernet device available to the system.
436 =============================================================================*/
437 #define CS_CHECK(fn, ret) \
438 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
439 #define MAX_TUPLE_SIZE 128
440 static void ray_config(dev_link_t *link)
442 client_handle_t handle = link->handle;
445 int last_fn = 0, last_ret = 0;
447 u_char buf[MAX_TUPLE_SIZE];
450 struct net_device *dev = (struct net_device *)link->priv;
451 ray_dev_t *local = (ray_dev_t *)dev->priv;
453 DEBUG(1, "ray_config(0x%p)\n", link);
455 /* This reads the card's CONFIG tuple to find its configuration regs */
456 tuple.DesiredTuple = CISTPL_CONFIG;
457 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
458 tuple.TupleData = buf;
459 tuple.TupleDataMax = MAX_TUPLE_SIZE;
460 tuple.TupleOffset = 0;
461 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
462 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
463 link->conf.ConfigBase = parse.config.base;
464 link->conf.Present = parse.config.rmask[0];
466 /* Determine card type and firmware version */
467 buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0;
468 tuple.DesiredTuple = CISTPL_VERS_1;
469 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
470 tuple.TupleData = buf;
471 tuple.TupleDataMax = MAX_TUPLE_SIZE;
472 tuple.TupleOffset = 2;
473 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
475 for (i=0; i<tuple.TupleDataLen - 4; i++)
476 if (buf[i] == 0) buf[i] = ' ';
477 printk(KERN_INFO "ray_cs Detected: %s\n",buf);
480 link->state |= DEV_CONFIG;
482 /* Now allocate an interrupt line. Note that this does not
483 actually assign a handler to the interrupt.
485 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
486 dev->irq = link->irq.AssignedIRQ;
488 /* This actually configures the PCMCIA socket -- setting up
489 the I/O windows and the interrupt mapping.
491 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
493 /*** Set up 32k window for shared memory (transmit and control) ************/
494 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
497 req.AccessSpeed = ray_mem_speed;
498 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win));
499 mem.CardOffset = 0x0000; mem.Page = 0;
500 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
501 local->sram = ioremap(req.Base,req.Size);
503 /*** Set up 16k window for shared memory (receive buffer) ***************/
504 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
507 req.AccessSpeed = ray_mem_speed;
508 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &local->rmem_handle));
509 mem.CardOffset = 0x8000; mem.Page = 0;
510 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem));
511 local->rmem = ioremap(req.Base,req.Size);
513 /*** Set up window for attribute memory ***********************************/
514 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
517 req.AccessSpeed = ray_mem_speed;
518 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &local->amem_handle));
519 mem.CardOffset = 0x0000; mem.Page = 0;
520 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem));
521 local->amem = ioremap(req.Base,req.Size);
523 DEBUG(3,"ray_config sram=%p\n",local->sram);
524 DEBUG(3,"ray_config rmem=%p\n",local->rmem);
525 DEBUG(3,"ray_config amem=%p\n",local->amem);
526 if (ray_init(dev) < 0) {
531 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
532 i = register_netdev(dev);
534 printk("ray_config register_netdev() failed\n");
539 strcpy(local->node.dev_name, dev->name);
540 link->dev = &local->node;
542 link->state &= ~DEV_CONFIG_PENDING;
543 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ",
544 dev->name, dev->irq);
545 for (i = 0; i < 6; i++)
546 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
551 cs_error(link->handle, last_fn, last_ret);
556 static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
558 return dev->sram + CCS_BASE;
561 static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
564 * This looks nonsensical, since there is a separate
565 * RCS_BASE. But the difference between a "struct rcs"
566 * and a "struct ccs" ends up being in the _index_ off
567 * the base, so the base pointer is the same for both
570 return dev->sram + CCS_BASE;
573 /*===========================================================================*/
574 static int ray_init(struct net_device *dev)
578 struct ccs __iomem *pccs;
579 ray_dev_t *local = (ray_dev_t *)dev->priv;
580 dev_link_t *link = local->finder;
581 DEBUG(1, "ray_init(0x%p)\n", dev);
582 if (!(link->state & DEV_PRESENT)) {
583 DEBUG(0,"ray_init - device not present\n");
587 local->net_type = net_type;
588 local->sta_type = TYPE_STA;
590 /* Copy the startup results to local memory */
591 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,\
592 sizeof(struct startup_res_6));
594 /* Check Power up test status and get mac address from card */
595 if (local->startup_res.startup_word != 0x80) {
596 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
597 local->startup_res.startup_word);
598 local->card_status = CARD_INIT_ERROR;
602 local->fw_ver = local->startup_res.firmware_version[0];
603 local->fw_bld = local->startup_res.firmware_version[1];
604 local->fw_var = local->startup_res.firmware_version[2];
605 DEBUG(1,"ray_init firmware version %d.%d \n",local->fw_ver, local->fw_bld);
607 local->tib_length = 0x20;
608 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
609 local->tib_length = local->startup_res.tib_length;
610 DEBUG(2,"ray_init tib_length = 0x%02x\n", local->tib_length);
611 /* Initialize CCS's to buffer free state */
612 pccs = ccs_base(local);
613 for (i=0; i<NUMBER_OF_CCS; i++) {
614 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
616 init_startup_params(local);
618 /* copy mac address to startup parameters */
619 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr))
621 p = local->sparm.b4.a_mac_addr;
625 memcpy(&local->sparm.b4.a_mac_addr,
626 &local->startup_res.station_addr, ADDRLEN);
627 p = local->sparm.b4.a_mac_addr;
630 clear_interrupt(local); /* Clear any interrupt from the card */
631 local->card_status = CARD_AWAITING_PARAM;
632 DEBUG(2,"ray_init ending\n");
635 /*===========================================================================*/
636 /* Download startup parameters to the card and command it to read them */
637 static int dl_startup_params(struct net_device *dev)
640 ray_dev_t *local = (ray_dev_t *)dev->priv;
641 struct ccs __iomem *pccs;
642 dev_link_t *link = local->finder;
644 DEBUG(1,"dl_startup_params entered\n");
645 if (!(link->state & DEV_PRESENT)) {
646 DEBUG(2,"ray_cs dl_startup_params - device not present\n");
650 /* Copy parameters to host to ECF area */
651 if (local->fw_ver == 0x55)
652 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
653 sizeof(struct b4_startup_params));
655 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
656 sizeof(struct b5_startup_params));
659 /* Fill in the CCS fields for the ECF */
660 if ((ccsindex = get_free_ccs(local)) < 0) return -1;
661 local->dl_param_ccs = ccsindex;
662 pccs = ccs_base(local) + ccsindex;
663 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
664 DEBUG(2,"dl_startup_params start ccsindex = %d\n", local->dl_param_ccs);
665 /* Interrupt the firmware to process the command */
666 if (interrupt_ecf(local, ccsindex)) {
667 printk(KERN_INFO "ray dl_startup_params failed - "
668 "ECF not ready for intr\n");
669 local->card_status = CARD_DL_PARAM_ERROR;
670 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
673 local->card_status = CARD_DL_PARAM;
674 /* Start kernel timer to wait for dl startup to complete. */
675 local->timer.expires = jiffies + HZ/2;
676 local->timer.data = (long)local;
677 local->timer.function = &verify_dl_startup;
678 add_timer(&local->timer);
679 DEBUG(2,"ray_cs dl_startup_params started timer for verify_dl_startup\n");
681 } /* dl_startup_params */
682 /*===========================================================================*/
683 static void init_startup_params(ray_dev_t *local)
687 if (country > JAPAN_TEST) country = USA;
689 if (country < USA) country = USA;
690 /* structure for hop time and beacon period is defined here using
691 * New 802.11D6.1 format. Card firmware is still using old format
694 * a_hop_time ms byte a_hop_time ms byte
695 * a_hop_time 2s byte a_hop_time ls byte
696 * a_hop_time ls byte a_beacon_period ms byte
697 * a_beacon_period a_beacon_period ls byte
699 * a_hop_time = uS a_hop_time = KuS
700 * a_beacon_period = hops a_beacon_period = KuS
701 */ /* 64ms = 010000 */
702 if (local->fw_ver == 0x55) {
703 memcpy((UCHAR *)&local->sparm.b4, b4_default_startup_parms,
704 sizeof(struct b4_startup_params));
705 /* Translate sane kus input values to old build 4/5 format */
706 /* i = hop time in uS truncated to 3 bytes */
707 i = (hop_dwell * 1024) & 0xffffff;
708 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
709 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
710 local->sparm.b4.a_beacon_period[0] = 0;
711 local->sparm.b4.a_beacon_period[1] =
712 ((beacon_period/hop_dwell) - 1) & 0xff;
713 local->sparm.b4.a_curr_country_code = country;
714 local->sparm.b4.a_hop_pattern_length =
715 hop_pattern_length[(int)country] - 1;
718 local->sparm.b4.a_ack_timeout = 0x50;
719 local->sparm.b4.a_sifs = 0x3f;
722 else { /* Version 5 uses real kus values */
723 memcpy((UCHAR *)&local->sparm.b5, b5_default_startup_parms,
724 sizeof(struct b5_startup_params));
726 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
727 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
728 local->sparm.b5.a_beacon_period[0] = (beacon_period >> 8) & 0xff;
729 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
731 local->sparm.b5.a_power_mgt_state = 1;
732 local->sparm.b5.a_curr_country_code = country;
733 local->sparm.b5.a_hop_pattern_length =
734 hop_pattern_length[(int)country];
737 local->sparm.b4.a_network_type = net_type & 0x01;
738 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
741 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
742 } /* init_startup_params */
743 /*===========================================================================*/
744 static void verify_dl_startup(u_long data)
746 ray_dev_t *local = (ray_dev_t *)data;
747 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
749 dev_link_t *link = local->finder;
751 if (!(link->state & DEV_PRESENT)) {
752 DEBUG(2,"ray_cs verify_dl_startup - device not present\n");
758 printk(KERN_DEBUG "verify_dl_startup parameters sent via ccs %d:\n",
759 local->dl_param_ccs);
760 for (i=0; i<sizeof(struct b5_startup_params); i++) {
761 printk(" %2x", (unsigned int) readb(local->sram + HOST_TO_ECF_BASE + i));
767 status = readb(&pccs->buffer_status);
768 if (status!= CCS_BUFFER_FREE)
770 printk(KERN_INFO "Download startup params failed. Status = %d\n",
772 local->card_status = CARD_DL_PARAM_ERROR;
775 if (local->sparm.b4.a_network_type == ADHOC)
776 start_net((u_long)local);
778 join_net((u_long)local);
781 } /* end verify_dl_startup */
782 /*===========================================================================*/
783 /* Command card to start a network */
784 static void start_net(u_long data)
786 ray_dev_t *local = (ray_dev_t *)data;
787 struct ccs __iomem *pccs;
789 dev_link_t *link = local->finder;
790 if (!(link->state & DEV_PRESENT)) {
791 DEBUG(2,"ray_cs start_net - device not present\n");
794 /* Fill in the CCS fields for the ECF */
795 if ((ccsindex = get_free_ccs(local)) < 0) return;
796 pccs = ccs_base(local) + ccsindex;
797 writeb(CCS_START_NETWORK, &pccs->cmd);
798 writeb(0, &pccs->var.start_network.update_param);
799 /* Interrupt the firmware to process the command */
800 if (interrupt_ecf(local, ccsindex)) {
801 DEBUG(1,"ray start net failed - card not ready for intr\n");
802 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
805 local->card_status = CARD_DOING_ACQ;
807 } /* end start_net */
808 /*===========================================================================*/
809 /* Command card to join a network */
810 static void join_net(u_long data)
812 ray_dev_t *local = (ray_dev_t *)data;
814 struct ccs __iomem *pccs;
816 dev_link_t *link = local->finder;
818 if (!(link->state & DEV_PRESENT)) {
819 DEBUG(2,"ray_cs join_net - device not present\n");
822 /* Fill in the CCS fields for the ECF */
823 if ((ccsindex = get_free_ccs(local)) < 0) return;
824 pccs = ccs_base(local) + ccsindex;
825 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
826 writeb(0, &pccs->var.join_network.update_param);
827 writeb(0, &pccs->var.join_network.net_initiated);
828 /* Interrupt the firmware to process the command */
829 if (interrupt_ecf(local, ccsindex)) {
830 DEBUG(1,"ray join net failed - card not ready for intr\n");
831 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
834 local->card_status = CARD_DOING_ACQ;
837 /*============================================================================
838 After a card is removed, ray_release() will unregister the net
839 device, and release the PCMCIA configuration. If the device is
840 still open, this will be postponed until it is closed.
841 =============================================================================*/
842 static void ray_release(dev_link_t *link)
844 struct net_device *dev = link->priv;
845 ray_dev_t *local = dev->priv;
848 DEBUG(1, "ray_release(0x%p)\n", link);
850 del_timer(&local->timer);
852 iounmap(local->sram);
853 iounmap(local->rmem);
854 iounmap(local->amem);
855 /* Do bother checking to see if these succeed or not */
856 i = pcmcia_release_window(local->amem_handle);
857 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
858 i = pcmcia_release_window(local->rmem_handle);
859 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
860 pcmcia_disable_device(link->handle);
862 DEBUG(2,"ray_release ending\n");
865 static int ray_suspend(struct pcmcia_device *p_dev)
867 dev_link_t *link = dev_to_instance(p_dev);
868 struct net_device *dev = link->priv;
870 if ((link->state & DEV_CONFIG) && (link->open))
871 netif_device_detach(dev);
876 static int ray_resume(struct pcmcia_device *p_dev)
878 dev_link_t *link = dev_to_instance(p_dev);
879 struct net_device *dev = link->priv;
881 if ((link->state & DEV_CONFIG) && (link->open)) {
883 netif_device_attach(dev);
889 /*===========================================================================*/
890 int ray_dev_init(struct net_device *dev)
892 #ifdef RAY_IMMEDIATE_INIT
894 #endif /* RAY_IMMEDIATE_INIT */
895 ray_dev_t *local = dev->priv;
896 dev_link_t *link = local->finder;
898 DEBUG(1,"ray_dev_init(dev=%p)\n",dev);
899 if (!(link->state & DEV_PRESENT)) {
900 DEBUG(2,"ray_dev_init - device not present\n");
903 #ifdef RAY_IMMEDIATE_INIT
904 /* Download startup parameters */
905 if ( (i = dl_startup_params(dev)) < 0)
907 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
911 #else /* RAY_IMMEDIATE_INIT */
912 /* Postpone the card init so that we can still configure the card,
913 * for example using the Wireless Extensions. The init will happen
914 * in ray_open() - Jean II */
915 DEBUG(1,"ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
917 #endif /* RAY_IMMEDIATE_INIT */
919 /* copy mac and broadcast addresses to linux device */
920 memcpy(&dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
921 memset(dev->broadcast, 0xff, ETH_ALEN);
923 DEBUG(2,"ray_dev_init ending\n");
926 /*===========================================================================*/
927 static int ray_dev_config(struct net_device *dev, struct ifmap *map)
929 ray_dev_t *local = dev->priv;
930 dev_link_t *link = local->finder;
931 /* Dummy routine to satisfy device structure */
932 DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map);
933 if (!(link->state & DEV_PRESENT)) {
934 DEBUG(2,"ray_dev_config - device not present\n");
940 /*===========================================================================*/
941 static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
943 ray_dev_t *local = dev->priv;
944 dev_link_t *link = local->finder;
945 short length = skb->len;
947 if (!(link->state & DEV_PRESENT)) {
948 DEBUG(2,"ray_dev_start_xmit - device not present\n");
951 DEBUG(3,"ray_dev_start_xmit(skb=%p, dev=%p)\n",skb,dev);
952 if (local->authentication_state == NEED_TO_AUTH) {
953 DEBUG(0,"ray_cs Sending authentication request.\n");
954 if (!build_auth_frame (local, local->auth_id, OPEN_AUTH_REQUEST)) {
955 local->authentication_state = AUTHENTICATED;
956 netif_stop_queue(dev);
961 if (length < ETH_ZLEN)
963 skb = skb_padto(skb, ETH_ZLEN);
968 switch (ray_hw_xmit( skb->data, length, dev, DATA_TYPE)) {
971 netif_stop_queue(dev);
977 dev->trans_start = jiffies;
982 } /* ray_dev_start_xmit */
983 /*===========================================================================*/
984 static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev,
987 ray_dev_t *local = (ray_dev_t *)dev->priv;
988 struct ccs __iomem *pccs;
991 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
992 short int addr; /* Address of xmit buffer in card space */
994 DEBUG(3,"ray_hw_xmit(data=%p, len=%d, dev=%p)\n",data,len,dev);
995 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE)
997 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",len);
1000 switch (ccsindex = get_free_tx_ccs(local)) {
1002 DEBUG(2,"ray_hw_xmit tx_ccs table busy\n");
1004 DEBUG(2,"ray_hw_xmit No free tx ccs\n");
1006 netif_stop_queue(dev);
1011 addr = TX_BUF_BASE + (ccsindex << 11);
1013 if (msg_type == DATA_TYPE) {
1014 local->stats.tx_bytes += len;
1015 local->stats.tx_packets++;
1018 ptx = local->sram + addr;
1020 ray_build_header(local, ptx, msg_type, data);
1022 offset = translate_frame(local, ptx, data, len);
1024 else { /* Encapsulate frame */
1025 /* TBD TIB length will move address of ptx->var */
1026 memcpy_toio(&ptx->var, data, len);
1030 /* fill in the CCS */
1031 pccs = ccs_base(local) + ccsindex;
1032 len += TX_HEADER_LENGTH + offset;
1033 writeb(CCS_TX_REQUEST, &pccs->cmd);
1034 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
1035 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
1036 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
1037 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
1038 /* TBD still need psm_cam? */
1039 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
1040 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1041 writeb(0, &pccs->var.tx_request.antenna);
1042 DEBUG(3,"ray_hw_xmit default_tx_rate = 0x%x\n",\
1043 local->net_default_tx_rate);
1045 /* Interrupt the firmware to process the command */
1046 if (interrupt_ecf(local, ccsindex)) {
1047 DEBUG(2,"ray_hw_xmit failed - ECF not ready for intr\n");
1048 /* TBD very inefficient to copy packet to buffer, and then not
1049 send it, but the alternative is to queue the messages and that
1050 won't be done for a while. Maybe set tbusy until a CCS is free?
1052 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1053 return XMIT_NO_INTR;
1056 } /* end ray_hw_xmit */
1057 /*===========================================================================*/
1058 static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, unsigned char *data,
1061 unsigned short int proto = ((struct ethhdr *)data)->h_proto;
1062 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
1063 DEBUG(3,"ray_cs translate_frame DIX II\n");
1064 /* Copy LLC header to card buffer */
1065 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1066 memcpy_toio( ((void __iomem *)&ptx->var) + sizeof(eth2_llc), (UCHAR *)&proto, 2);
1067 if ((proto == 0xf380) || (proto == 0x3781)) {
1068 /* This is the selective translation table, only 2 entries */
1069 writeb(0xf8, &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1071 /* Copy body of ethernet packet without ethernet header */
1072 memcpy_toio((void __iomem *)&ptx->var + sizeof(struct snaphdr_t), \
1073 data + ETH_HLEN, len - ETH_HLEN);
1074 return (int) sizeof(struct snaphdr_t) - ETH_HLEN;
1076 else { /* already 802 type, and proto is length */
1077 DEBUG(3,"ray_cs translate_frame 802\n");
1078 if (proto == 0xffff) { /* evil netware IPX 802.3 without LLC */
1079 DEBUG(3,"ray_cs translate_frame evil IPX\n");
1080 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1081 return 0 - ETH_HLEN;
1083 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1084 return 0 - ETH_HLEN;
1086 /* TBD do other frame types */
1087 } /* end translate_frame */
1088 /*===========================================================================*/
1089 static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, UCHAR msg_type,
1090 unsigned char *data)
1092 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1093 /*** IEEE 802.11 Address field assignments *************
1094 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1095 Adhoc 0 0 dest src (terminal) BSSID N/A
1096 AP to Terminal 0 1 dest AP(BSSID) source N/A
1097 Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1098 AP to AP 1 1 dest AP src AP dest source
1099 *******************************************************/
1100 if (local->net_type == ADHOC) {
1101 writeb(0, &ptx->mac.frame_ctl_2);
1102 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, 2 * ADDRLEN);
1103 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1105 else /* infrastructure */
1107 if (local->sparm.b4.a_acting_as_ap_status)
1109 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1110 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, ADDRLEN);
1111 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1112 memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_source, ADDRLEN);
1116 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1117 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1118 memcpy_toio(ptx->mac.addr_2, ((struct ethhdr *)data)->h_source, ADDRLEN);
1119 memcpy_toio(ptx->mac.addr_3, ((struct ethhdr *)data)->h_dest, ADDRLEN);
1122 } /* end encapsulate_frame */
1125 /*===========================================================================*/
1127 static void netdev_get_drvinfo(struct net_device *dev,
1128 struct ethtool_drvinfo *info)
1130 strcpy(info->driver, "ray_cs");
1133 static struct ethtool_ops netdev_ethtool_ops = {
1134 .get_drvinfo = netdev_get_drvinfo,
1137 /*====================================================================*/
1139 /*------------------------------------------------------------------*/
1141 * Wireless Handler : get protocol name
1143 static int ray_get_name(struct net_device *dev,
1144 struct iw_request_info *info,
1148 strcpy(cwrq, "IEEE 802.11-FH");
1152 /*------------------------------------------------------------------*/
1154 * Wireless Handler : set frequency
1156 static int ray_set_freq(struct net_device *dev,
1157 struct iw_request_info *info,
1158 struct iw_freq *fwrq,
1161 ray_dev_t *local = (ray_dev_t *)dev->priv;
1162 int err = -EINPROGRESS; /* Call commit handler */
1164 /* Reject if card is already initialised */
1165 if(local->card_status != CARD_AWAITING_PARAM)
1168 /* Setting by channel number */
1169 if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0))
1172 local->sparm.b5.a_hop_pattern = fwrq->m;
1177 /*------------------------------------------------------------------*/
1179 * Wireless Handler : get frequency
1181 static int ray_get_freq(struct net_device *dev,
1182 struct iw_request_info *info,
1183 struct iw_freq *fwrq,
1186 ray_dev_t *local = (ray_dev_t *)dev->priv;
1188 fwrq->m = local->sparm.b5.a_hop_pattern;
1193 /*------------------------------------------------------------------*/
1195 * Wireless Handler : set ESSID
1197 static int ray_set_essid(struct net_device *dev,
1198 struct iw_request_info *info,
1199 struct iw_point *dwrq,
1202 ray_dev_t *local = (ray_dev_t *)dev->priv;
1204 /* Reject if card is already initialised */
1205 if(local->card_status != CARD_AWAITING_PARAM)
1208 /* Check if we asked for `any' */
1209 if(dwrq->flags == 0) {
1210 /* Corey : can you do that ? */
1213 /* Check the size of the string */
1214 if(dwrq->length > IW_ESSID_MAX_SIZE + 1) {
1218 /* Set the ESSID in the card */
1219 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1220 memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length);
1223 return -EINPROGRESS; /* Call commit handler */
1226 /*------------------------------------------------------------------*/
1228 * Wireless Handler : get ESSID
1230 static int ray_get_essid(struct net_device *dev,
1231 struct iw_request_info *info,
1232 struct iw_point *dwrq,
1235 ray_dev_t *local = (ray_dev_t *)dev->priv;
1237 /* Get the essid that was set */
1238 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
1239 extra[IW_ESSID_MAX_SIZE] = '\0';
1242 dwrq->length = strlen(extra);
1243 dwrq->flags = 1; /* active */
1248 /*------------------------------------------------------------------*/
1250 * Wireless Handler : get AP address
1252 static int ray_get_wap(struct net_device *dev,
1253 struct iw_request_info *info,
1254 struct sockaddr *awrq,
1257 ray_dev_t *local = (ray_dev_t *)dev->priv;
1259 memcpy(awrq->sa_data, local->bss_id, ETH_ALEN);
1260 awrq->sa_family = ARPHRD_ETHER;
1265 /*------------------------------------------------------------------*/
1267 * Wireless Handler : set Bit-Rate
1269 static int ray_set_rate(struct net_device *dev,
1270 struct iw_request_info *info,
1271 struct iw_param *vwrq,
1274 ray_dev_t *local = (ray_dev_t *)dev->priv;
1276 /* Reject if card is already initialised */
1277 if(local->card_status != CARD_AWAITING_PARAM)
1280 /* Check if rate is in range */
1281 if((vwrq->value != 1000000) && (vwrq->value != 2000000))
1284 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
1285 if((local->fw_ver == 0x55) && /* Please check */
1286 (vwrq->value == 2000000))
1287 local->net_default_tx_rate = 3;
1289 local->net_default_tx_rate = vwrq->value/500000;
1294 /*------------------------------------------------------------------*/
1296 * Wireless Handler : get Bit-Rate
1298 static int ray_get_rate(struct net_device *dev,
1299 struct iw_request_info *info,
1300 struct iw_param *vwrq,
1303 ray_dev_t *local = (ray_dev_t *)dev->priv;
1305 if(local->net_default_tx_rate == 3)
1306 vwrq->value = 2000000; /* Hum... */
1308 vwrq->value = local->net_default_tx_rate * 500000;
1309 vwrq->fixed = 0; /* We are in auto mode */
1314 /*------------------------------------------------------------------*/
1316 * Wireless Handler : set RTS threshold
1318 static int ray_set_rts(struct net_device *dev,
1319 struct iw_request_info *info,
1320 struct iw_param *vwrq,
1323 ray_dev_t *local = (ray_dev_t *)dev->priv;
1324 int rthr = vwrq->value;
1326 /* Reject if card is already initialised */
1327 if(local->card_status != CARD_AWAITING_PARAM)
1330 /* if(wrq->u.rts.fixed == 0) we should complain */
1334 if((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
1337 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1338 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
1340 return -EINPROGRESS; /* Call commit handler */
1344 /*------------------------------------------------------------------*/
1346 * Wireless Handler : get RTS threshold
1348 static int ray_get_rts(struct net_device *dev,
1349 struct iw_request_info *info,
1350 struct iw_param *vwrq,
1353 ray_dev_t *local = (ray_dev_t *)dev->priv;
1355 vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8)
1356 + local->sparm.b5.a_rts_threshold[1];
1357 vwrq->disabled = (vwrq->value == 32767);
1363 /*------------------------------------------------------------------*/
1365 * Wireless Handler : set Fragmentation threshold
1367 static int ray_set_frag(struct net_device *dev,
1368 struct iw_request_info *info,
1369 struct iw_param *vwrq,
1372 ray_dev_t *local = (ray_dev_t *)dev->priv;
1373 int fthr = vwrq->value;
1375 /* Reject if card is already initialised */
1376 if(local->card_status != CARD_AWAITING_PARAM)
1379 /* if(wrq->u.frag.fixed == 0) should complain */
1383 if((fthr < 256) || (fthr > 2347)) /* To check out ! */
1386 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1387 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
1389 return -EINPROGRESS; /* Call commit handler */
1392 /*------------------------------------------------------------------*/
1394 * Wireless Handler : get Fragmentation threshold
1396 static int ray_get_frag(struct net_device *dev,
1397 struct iw_request_info *info,
1398 struct iw_param *vwrq,
1401 ray_dev_t *local = (ray_dev_t *)dev->priv;
1403 vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8)
1404 + local->sparm.b5.a_frag_threshold[1];
1405 vwrq->disabled = (vwrq->value == 32767);
1411 /*------------------------------------------------------------------*/
1413 * Wireless Handler : set Mode of Operation
1415 static int ray_set_mode(struct net_device *dev,
1416 struct iw_request_info *info,
1420 ray_dev_t *local = (ray_dev_t *)dev->priv;
1421 int err = -EINPROGRESS; /* Call commit handler */
1424 /* Reject if card is already initialised */
1425 if(local->card_status != CARD_AWAITING_PARAM)
1434 local->sparm.b5.a_network_type = card_mode;
1443 /*------------------------------------------------------------------*/
1445 * Wireless Handler : get Mode of Operation
1447 static int ray_get_mode(struct net_device *dev,
1448 struct iw_request_info *info,
1452 ray_dev_t *local = (ray_dev_t *)dev->priv;
1454 if(local->sparm.b5.a_network_type)
1455 *uwrq = IW_MODE_INFRA;
1457 *uwrq = IW_MODE_ADHOC;
1462 /*------------------------------------------------------------------*/
1464 * Wireless Handler : get range info
1466 static int ray_get_range(struct net_device *dev,
1467 struct iw_request_info *info,
1468 struct iw_point *dwrq,
1471 struct iw_range *range = (struct iw_range *) extra;
1473 memset((char *) range, 0, sizeof(struct iw_range));
1475 /* Set the length (very important for backward compatibility) */
1476 dwrq->length = sizeof(struct iw_range);
1478 /* Set the Wireless Extension versions */
1479 range->we_version_compiled = WIRELESS_EXT;
1480 range->we_version_source = 9;
1482 /* Set information in the range struct */
1483 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
1484 range->num_channels = hop_pattern_length[(int)country];
1485 range->num_frequency = 0;
1486 range->max_qual.qual = 0;
1487 range->max_qual.level = 255; /* What's the correct value ? */
1488 range->max_qual.noise = 255; /* Idem */
1489 range->num_bitrates = 2;
1490 range->bitrate[0] = 1000000; /* 1 Mb/s */
1491 range->bitrate[1] = 2000000; /* 2 Mb/s */
1495 /*------------------------------------------------------------------*/
1497 * Wireless Private Handler : set framing mode
1499 static int ray_set_framing(struct net_device *dev,
1500 struct iw_request_info *info,
1501 union iwreq_data *wrqu,
1504 translate = *(extra); /* Set framing mode */
1509 /*------------------------------------------------------------------*/
1511 * Wireless Private Handler : get framing mode
1513 static int ray_get_framing(struct net_device *dev,
1514 struct iw_request_info *info,
1515 union iwreq_data *wrqu,
1518 *(extra) = translate;
1523 /*------------------------------------------------------------------*/
1525 * Wireless Private Handler : get country
1527 static int ray_get_country(struct net_device *dev,
1528 struct iw_request_info *info,
1529 union iwreq_data *wrqu,
1537 /*------------------------------------------------------------------*/
1539 * Commit handler : called after a bunch of SET operations
1541 static int ray_commit(struct net_device *dev,
1542 struct iw_request_info *info, /* NULL */
1543 void *zwrq, /* NULL */
1544 char *extra) /* NULL */
1549 /*------------------------------------------------------------------*/
1551 * Stats handler : return Wireless Stats
1553 static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1555 ray_dev_t * local = (ray_dev_t *) dev->priv;
1556 dev_link_t *link = local->finder;
1557 struct status __iomem *p = local->sram + STATUS_BASE;
1559 if(local == (ray_dev_t *) NULL)
1560 return (iw_stats *) NULL;
1562 local->wstats.status = local->card_status;
1564 if((local->spy_data.spy_number > 0) && (local->sparm.b5.a_network_type == 0))
1566 /* Get it from the first node in spy list */
1567 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1568 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1569 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1570 local->wstats.qual.updated = local->spy_data.spy_stat[0].updated;
1572 #endif /* WIRELESS_SPY */
1574 if((link->state & DEV_PRESENT)) {
1575 local->wstats.qual.noise = readb(&p->rxnoise);
1576 local->wstats.qual.updated |= 4;
1579 return &local->wstats;
1580 } /* end ray_get_wireless_stats */
1582 /*------------------------------------------------------------------*/
1584 * Structures to export the Wireless Handlers
1587 static const iw_handler ray_handler[] = {
1588 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) ray_commit,
1589 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) ray_get_name,
1590 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) ray_set_freq,
1591 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) ray_get_freq,
1592 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) ray_set_mode,
1593 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) ray_get_mode,
1594 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) ray_get_range,
1596 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
1597 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
1598 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
1599 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
1600 #endif /* WIRELESS_SPY */
1601 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) ray_get_wap,
1602 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) ray_set_essid,
1603 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) ray_get_essid,
1604 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) ray_set_rate,
1605 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) ray_get_rate,
1606 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) ray_set_rts,
1607 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) ray_get_rts,
1608 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) ray_set_frag,
1609 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) ray_get_frag,
1612 #define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
1613 #define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1614 #define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1616 static const iw_handler ray_private_handler[] = {
1617 [0] = (iw_handler) ray_set_framing,
1618 [1] = (iw_handler) ray_get_framing,
1619 [3] = (iw_handler) ray_get_country,
1622 static const struct iw_priv_args ray_private_args[] = {
1623 /* cmd, set_args, get_args, name */
1624 { SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "set_framing" },
1625 { SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_framing" },
1626 { SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_country" },
1629 static const struct iw_handler_def ray_handler_def =
1631 .num_standard = sizeof(ray_handler)/sizeof(iw_handler),
1632 .num_private = sizeof(ray_private_handler)/sizeof(iw_handler),
1633 .num_private_args = sizeof(ray_private_args)/sizeof(struct iw_priv_args),
1634 .standard = ray_handler,
1635 .private = ray_private_handler,
1636 .private_args = ray_private_args,
1637 .get_wireless_stats = ray_get_wireless_stats,
1640 /*===========================================================================*/
1641 static int ray_open(struct net_device *dev)
1644 ray_dev_t *local = (ray_dev_t *)dev->priv;
1646 DEBUG(1, "ray_open('%s')\n", dev->name);
1648 for (link = dev_list; link; link = link->next)
1649 if (link->priv == dev) break;
1650 if (!DEV_OK(link)) {
1654 if (link->open == 0) local->num_multi = 0;
1657 /* If the card is not started, time to start it ! - Jean II */
1658 if(local->card_status == CARD_AWAITING_PARAM) {
1661 DEBUG(1,"ray_open: doing init now !\n");
1663 /* Download startup parameters */
1664 if ( (i = dl_startup_params(dev)) < 0)
1666 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
1667 "returns 0x%x\n",i);
1672 if (sniffer) netif_stop_queue(dev);
1673 else netif_start_queue(dev);
1675 DEBUG(2,"ray_open ending\n");
1677 } /* end ray_open */
1678 /*===========================================================================*/
1679 static int ray_dev_close(struct net_device *dev)
1683 DEBUG(1, "ray_dev_close('%s')\n", dev->name);
1685 for (link = dev_list; link; link = link->next)
1686 if (link->priv == dev) break;
1691 netif_stop_queue(dev);
1693 /* In here, we should stop the hardware (stop card from beeing active)
1694 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1695 * card is closed we can chage its configuration.
1696 * Probably also need a COR reset to get sane state - Jean II */
1699 } /* end ray_dev_close */
1700 /*===========================================================================*/
1701 static void ray_reset(struct net_device *dev) {
1702 DEBUG(1,"ray_reset entered\n");
1705 /*===========================================================================*/
1706 /* Cause a firmware interrupt if it is ready for one */
1707 /* Return nonzero if not ready */
1708 static int interrupt_ecf(ray_dev_t *local, int ccs)
1711 dev_link_t *link = local->finder;
1713 if (!(link->state & DEV_PRESENT)) {
1714 DEBUG(2,"ray_cs interrupt_ecf - device not present\n");
1717 DEBUG(2,"interrupt_ecf(local=%p, ccs = 0x%x\n",local,ccs);
1720 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & ECF_INTR_SET))
1723 DEBUG(2,"ray_cs interrupt_ecf card not ready for interrupt\n");
1726 /* Fill the mailbox, then kick the card */
1727 writeb(ccs, local->sram + SCB_BASE);
1728 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1730 } /* interrupt_ecf */
1731 /*===========================================================================*/
1732 /* Get next free transmit CCS */
1733 /* Return - index of current tx ccs */
1734 static int get_free_tx_ccs(ray_dev_t *local)
1737 struct ccs __iomem *pccs = ccs_base(local);
1738 dev_link_t *link = local->finder;
1740 if (!(link->state & DEV_PRESENT)) {
1741 DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n");
1745 if (test_and_set_bit(0,&local->tx_ccs_lock)) {
1746 DEBUG(1,"ray_cs tx_ccs_lock busy\n");
1750 for (i=0; i < NUMBER_OF_TX_CCS; i++) {
1751 if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) {
1752 writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status);
1753 writeb(CCS_END_LIST, &(pccs+i)->link);
1754 local->tx_ccs_lock = 0;
1758 local->tx_ccs_lock = 0;
1759 DEBUG(2,"ray_cs ERROR no free tx CCS for raylink card\n");
1761 } /* get_free_tx_ccs */
1762 /*===========================================================================*/
1763 /* Get next free CCS */
1764 /* Return - index of current ccs */
1765 static int get_free_ccs(ray_dev_t *local)
1768 struct ccs __iomem *pccs = ccs_base(local);
1769 dev_link_t *link = local->finder;
1771 if (!(link->state & DEV_PRESENT)) {
1772 DEBUG(2,"ray_cs get_free_ccs - device not present\n");
1775 if (test_and_set_bit(0,&local->ccs_lock)) {
1776 DEBUG(1,"ray_cs ccs_lock busy\n");
1780 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1781 if (readb(&(pccs+i)->buffer_status) == CCS_BUFFER_FREE) {
1782 writeb(CCS_BUFFER_BUSY, &(pccs+i)->buffer_status);
1783 writeb(CCS_END_LIST, &(pccs+i)->link);
1784 local->ccs_lock = 0;
1788 local->ccs_lock = 0;
1789 DEBUG(1,"ray_cs ERROR no free CCS for raylink card\n");
1791 } /* get_free_ccs */
1792 /*===========================================================================*/
1793 static void authenticate_timeout(u_long data)
1795 ray_dev_t *local = (ray_dev_t *)data;
1796 del_timer(&local->timer);
1797 printk(KERN_INFO "ray_cs Authentication with access point failed"
1799 join_net((u_long)local);
1801 /*===========================================================================*/
1802 static int asc_to_int(char a)
1804 if (a < '0') return -1;
1805 if (a <= '9') return (a - '0');
1806 if (a < 'A') return -1;
1807 if (a <= 'F') return (10 + a - 'A');
1808 if (a < 'a') return -1;
1809 if (a <= 'f') return (10 + a - 'a');
1812 /*===========================================================================*/
1813 static int parse_addr(char *in_str, UCHAR *out)
1819 if (in_str == NULL) return 0;
1820 if ((len = strlen(in_str)) < 2) return 0;
1821 memset(out, 0, ADDRLEN);
1830 if ((k = asc_to_int(in_str[j--])) != -1) out[i] = k;
1834 if ((k = asc_to_int(in_str[j--])) != -1) out[i] += k << 4;
1840 /*===========================================================================*/
1841 static struct net_device_stats *ray_get_stats(struct net_device *dev)
1843 ray_dev_t *local = (ray_dev_t *)dev->priv;
1844 dev_link_t *link = local->finder;
1845 struct status __iomem *p = local->sram + STATUS_BASE;
1846 if (!(link->state & DEV_PRESENT)) {
1847 DEBUG(2,"ray_cs net_device_stats - device not present\n");
1848 return &local->stats;
1850 if (readb(&p->mrx_overflow_for_host))
1852 local->stats.rx_over_errors += ntohs(readb(&p->mrx_overflow));
1853 writeb(0,&p->mrx_overflow);
1854 writeb(0,&p->mrx_overflow_for_host);
1856 if (readb(&p->mrx_checksum_error_for_host))
1858 local->stats.rx_crc_errors += ntohs(readb(&p->mrx_checksum_error));
1859 writeb(0,&p->mrx_checksum_error);
1860 writeb(0,&p->mrx_checksum_error_for_host);
1862 if (readb(&p->rx_hec_error_for_host))
1864 local->stats.rx_frame_errors += ntohs(readb(&p->rx_hec_error));
1865 writeb(0,&p->rx_hec_error);
1866 writeb(0,&p->rx_hec_error_for_host);
1868 return &local->stats;
1870 /*===========================================================================*/
1871 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len)
1873 ray_dev_t *local = (ray_dev_t *)dev->priv;
1874 dev_link_t *link = local->finder;
1877 struct ccs __iomem *pccs;
1879 if (!(link->state & DEV_PRESENT)) {
1880 DEBUG(2,"ray_update_parm - device not present\n");
1884 if ((ccsindex = get_free_ccs(local)) < 0)
1886 DEBUG(0,"ray_update_parm - No free ccs\n");
1889 pccs = ccs_base(local) + ccsindex;
1890 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1891 writeb(objid, &pccs->var.update_param.object_id);
1892 writeb(1, &pccs->var.update_param.number_objects);
1893 writeb(0, &pccs->var.update_param.failure_cause);
1894 for (i=0; i<len; i++) {
1895 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1897 /* Interrupt the firmware to process the command */
1898 if (interrupt_ecf(local, ccsindex)) {
1899 DEBUG(0,"ray_cs associate failed - ECF not ready for intr\n");
1900 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1903 /*===========================================================================*/
1904 static void ray_update_multi_list(struct net_device *dev, int all)
1906 struct dev_mc_list *dmi, **dmip;
1908 struct ccs __iomem *pccs;
1910 ray_dev_t *local = (ray_dev_t *)dev->priv;
1911 dev_link_t *link = local->finder;
1912 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
1914 if (!(link->state & DEV_PRESENT)) {
1915 DEBUG(2,"ray_update_multi_list - device not present\n");
1919 DEBUG(2,"ray_update_multi_list(%p)\n",dev);
1920 if ((ccsindex = get_free_ccs(local)) < 0)
1922 DEBUG(1,"ray_update_multi - No free ccs\n");
1925 pccs = ccs_base(local) + ccsindex;
1926 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
1929 writeb(0xff, &pccs->var);
1930 local->num_multi = 0xff;
1933 /* Copy the kernel's list of MC addresses to card */
1934 for (dmip=&dev->mc_list; (dmi=*dmip)!=NULL; dmip=&dmi->next) {
1935 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
1936 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]);
1940 if (i > 256/ADDRLEN) i = 256/ADDRLEN;
1941 writeb((UCHAR)i, &pccs->var);
1942 DEBUG(1,"ray_cs update_multi %d addresses in list\n", i);
1943 /* Interrupt the firmware to process the command */
1944 local->num_multi = i;
1946 if (interrupt_ecf(local, ccsindex)) {
1947 DEBUG(1,"ray_cs update_multi failed - ECF not ready for intr\n");
1948 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1950 } /* end ray_update_multi_list */
1951 /*===========================================================================*/
1952 static void set_multicast_list(struct net_device *dev)
1954 ray_dev_t *local = (ray_dev_t *)dev->priv;
1957 DEBUG(2,"ray_cs set_multicast_list(%p)\n",dev);
1959 if (dev->flags & IFF_PROMISC)
1961 if (local->sparm.b5.a_promiscuous_mode == 0) {
1962 DEBUG(1,"ray_cs set_multicast_list promisc on\n");
1963 local->sparm.b5.a_promiscuous_mode = 1;
1965 ray_update_parm(dev, OBJID_promiscuous_mode, \
1966 &promisc, sizeof(promisc));
1970 if (local->sparm.b5.a_promiscuous_mode == 1) {
1971 DEBUG(1,"ray_cs set_multicast_list promisc off\n");
1972 local->sparm.b5.a_promiscuous_mode = 0;
1974 ray_update_parm(dev, OBJID_promiscuous_mode, \
1975 &promisc, sizeof(promisc));
1979 if (dev->flags & IFF_ALLMULTI) ray_update_multi_list(dev, 1);
1982 if (local->num_multi != dev->mc_count) ray_update_multi_list(dev, 0);
1984 } /* end set_multicast_list */
1985 /*=============================================================================
1986 * All routines below here are run at interrupt time.
1987 =============================================================================*/
1988 static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1990 struct net_device *dev = (struct net_device *)dev_id;
1993 struct ccs __iomem *pccs;
1994 struct rcs __iomem *prcs;
2000 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
2003 DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev);
2005 local = (ray_dev_t *)dev->priv;
2006 link = (dev_link_t *)local->finder;
2007 if ( ! (link->state & DEV_PRESENT) || link->state & DEV_SUSPEND ) {
2008 DEBUG(2,"ray_cs interrupt from device not present or suspended.\n");
2011 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
2013 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS))
2015 DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
2016 clear_interrupt(local);
2019 if (rcsindex < NUMBER_OF_CCS) /* If it's a returned CCS */
2021 pccs = ccs_base(local) + rcsindex;
2022 cmd = readb(&pccs->cmd);
2023 status = readb(&pccs->buffer_status);
2026 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
2027 del_timer(&local->timer);
2028 if (status == CCS_COMMAND_COMPLETE) {
2029 DEBUG(1,"ray_cs interrupt download_startup_parameters OK\n");
2032 DEBUG(1,"ray_cs interrupt download_startup_parameters fail\n");
2035 case CCS_UPDATE_PARAMS:
2036 DEBUG(1,"ray_cs interrupt update params done\n");
2037 if (status != CCS_COMMAND_COMPLETE) {
2038 tmp = readb(&pccs->var.update_param.failure_cause);
2039 DEBUG(0,"ray_cs interrupt update params failed - reason %d\n",tmp);
2042 case CCS_REPORT_PARAMS:
2043 DEBUG(1,"ray_cs interrupt report params done\n");
2045 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
2046 DEBUG(1,"ray_cs interrupt CCS Update Multicast List done\n");
2048 case CCS_UPDATE_POWER_SAVINGS_MODE:
2049 DEBUG(1,"ray_cs interrupt update power save mode done\n");
2051 case CCS_START_NETWORK:
2052 case CCS_JOIN_NETWORK:
2053 if (status == CCS_COMMAND_COMPLETE) {
2054 if (readb(&pccs->var.start_network.net_initiated) == 1) {
2055 DEBUG(0,"ray_cs interrupt network \"%s\" started\n",\
2056 local->sparm.b4.a_current_ess_id);
2059 DEBUG(0,"ray_cs interrupt network \"%s\" joined\n",\
2060 local->sparm.b4.a_current_ess_id);
2062 memcpy_fromio(&local->bss_id,pccs->var.start_network.bssid,ADDRLEN);
2064 if (local->fw_ver == 0x55) local->net_default_tx_rate = 3;
2065 else local->net_default_tx_rate =
2066 readb(&pccs->var.start_network.net_default_tx_rate);
2067 local->encryption = readb(&pccs->var.start_network.encryption);
2068 if (!sniffer && (local->net_type == INFRA)
2069 && !(local->sparm.b4.a_acting_as_ap_status)) {
2070 authenticate(local);
2072 local->card_status = CARD_ACQ_COMPLETE;
2075 local->card_status = CARD_ACQ_FAILED;
2077 del_timer(&local->timer);
2078 local->timer.expires = jiffies + HZ*5;
2079 local->timer.data = (long)local;
2080 if (status == CCS_START_NETWORK) {
2081 DEBUG(0,"ray_cs interrupt network \"%s\" start failed\n",\
2082 local->sparm.b4.a_current_ess_id);
2083 local->timer.function = &start_net;
2086 DEBUG(0,"ray_cs interrupt network \"%s\" join failed\n",\
2087 local->sparm.b4.a_current_ess_id);
2088 local->timer.function = &join_net;
2090 add_timer(&local->timer);
2093 case CCS_START_ASSOCIATION:
2094 if (status == CCS_COMMAND_COMPLETE) {
2095 local->card_status = CARD_ASSOC_COMPLETE;
2096 DEBUG(0,"ray_cs association successful\n");
2100 DEBUG(0,"ray_cs association failed,\n");
2101 local->card_status = CARD_ASSOC_FAILED;
2102 join_net((u_long)local);
2105 case CCS_TX_REQUEST:
2106 if (status == CCS_COMMAND_COMPLETE) {
2107 DEBUG(3,"ray_cs interrupt tx request complete\n");
2110 DEBUG(1,"ray_cs interrupt tx request failed\n");
2112 if (!sniffer) netif_start_queue(dev);
2113 netif_wake_queue(dev);
2115 case CCS_TEST_MEMORY:
2116 DEBUG(1,"ray_cs interrupt mem test done\n");
2119 DEBUG(1,"ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2121 case CCS_DUMP_MEMORY:
2122 DEBUG(1,"ray_cs interrupt dump memory done\n");
2124 case CCS_START_TIMER:
2125 DEBUG(2,"ray_cs interrupt DING - raylink timer expired\n");
2128 DEBUG(1,"ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",\
2131 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2133 else /* It's an RCS */
2135 prcs = rcs_base(local) + rcsindex;
2137 switch (readb(&prcs->interrupt_id))
2139 case PROCESS_RX_PACKET:
2140 ray_rx(dev, local, prcs);
2142 case REJOIN_NET_COMPLETE:
2143 DEBUG(1,"ray_cs interrupt rejoin net complete\n");
2144 local->card_status = CARD_ACQ_COMPLETE;
2145 /* do we need to clear tx buffers CCS's? */
2146 if (local->sparm.b4.a_network_type == ADHOC) {
2147 if (!sniffer) netif_start_queue(dev);
2150 memcpy_fromio(&local->bss_id, prcs->var.rejoin_net_complete.bssid, ADDRLEN);
2151 DEBUG(1,"ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",\
2152 local->bss_id[0], local->bss_id[1], local->bss_id[2],\
2153 local->bss_id[3], local->bss_id[4], local->bss_id[5]);
2154 if (!sniffer) authenticate(local);
2157 case ROAMING_INITIATED:
2158 DEBUG(1,"ray_cs interrupt roaming initiated\n");
2159 netif_stop_queue(dev);
2160 local->card_status = CARD_DOING_ACQ;
2162 case JAPAN_CALL_SIGN_RXD:
2163 DEBUG(1,"ray_cs interrupt japan call sign rx\n");
2166 DEBUG(1,"ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",\
2167 rcsindex, (unsigned int) readb(&prcs->interrupt_id));
2170 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2172 clear_interrupt(local);
2174 } /* ray_interrupt */
2175 /*===========================================================================*/
2176 static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs)
2179 unsigned int pkt_addr;
2181 DEBUG(4,"ray_rx process rx packet\n");
2183 /* Calculate address of packet within Rx buffer */
2184 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2185 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2186 /* Length of first packet fragment */
2187 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2188 + readb(&prcs->var.rx_packet.rx_data_length[1]);
2190 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2191 pmsg = local->rmem + pkt_addr;
2195 DEBUG(4,"ray_rx data type\n");
2196 rx_data(dev, prcs, pkt_addr, rx_len);
2198 case AUTHENTIC_TYPE:
2199 DEBUG(4,"ray_rx authentic type\n");
2200 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
2201 else rx_authenticate(local, prcs, pkt_addr, rx_len);
2203 case DEAUTHENTIC_TYPE:
2204 DEBUG(4,"ray_rx deauth type\n");
2205 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
2206 else rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2209 DEBUG(3,"ray_cs rx NULL msg\n");
2212 DEBUG(4,"ray_rx beacon type\n");
2213 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
2215 copy_from_rx_buff(local, (UCHAR *)&local->last_bcn, pkt_addr,
2216 rx_len < sizeof(struct beacon_rx) ?
2217 rx_len : sizeof(struct beacon_rx));
2219 local->beacon_rxed = 1;
2220 /* Get the statistics so the card counters never overflow */
2224 DEBUG(0,"ray_cs unknown pkt type %2x\n", (unsigned int) readb(pmsg));
2229 /*===========================================================================*/
2230 static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, unsigned int pkt_addr,
2233 struct sk_buff *skb = NULL;
2234 struct rcs __iomem *prcslink = prcs;
2235 ray_dev_t *local = dev->priv;
2240 int siglev = local->last_rsl;
2241 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
2246 /* TBD length needs fixing for translated header */
2247 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2248 rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))
2250 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
2254 else /* encapsulated ethernet */ {
2255 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2256 rx_len > (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + FCS_LEN))
2258 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
2263 DEBUG(4,"ray_cs rx_data packet\n");
2264 /* If fragmented packet, verify sizes of fragments add up */
2265 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2266 DEBUG(1,"ray_cs rx'ed fragment\n");
2267 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2268 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2272 tmp -= (readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8)
2273 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2274 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index) == 0xFF
2276 prcslink = rcs_base(local)
2277 + readb(&prcslink->link_field);
2282 DEBUG(0,"ray_cs rx_data fragment lengths don't add up\n");
2283 local->stats.rx_dropped++;
2284 release_frag_chain(local, prcs);
2288 else { /* Single unfragmented packet */
2292 skb = dev_alloc_skb( total_len+5 );
2295 DEBUG(0,"ray_cs rx_data could not allocate skb\n");
2296 local->stats.rx_dropped++;
2297 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2298 release_frag_chain(local, prcs);
2301 skb_reserve( skb, 2); /* Align IP on 16 byte (TBD check this)*/
2304 DEBUG(4,"ray_cs rx_data total_len = %x, rx_len = %x\n",total_len,rx_len);
2306 /************************/
2307 /* Reserve enough room for the whole damn packet. */
2308 rx_ptr = skb_put( skb, total_len);
2309 /* Copy the whole packet to sk_buff */
2310 rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2311 /* Get source address */
2313 memcpy(linksrcaddr, ((struct mac_header *)skb->data)->addr_2, ETH_ALEN);
2315 /* Now, deal with encapsulation/translation/sniffer */
2318 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
2319 /* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
2320 skb_pull( skb, RX_MAC_HEADER_LENGTH);
2323 /* Do translation */
2324 untranslate(local, skb, total_len);
2328 { /* sniffer mode, so just pass whole packet */ };
2330 /************************/
2331 /* Now pick up the rest of the fragments if any */
2333 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2335 DEBUG(1,"ray_cs rx_data in fragment loop\n");
2337 prcslink = rcs_base(local)
2338 + readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2339 rx_len = (( readb(&prcslink->var.rx_packet.rx_data_length[0]) << 8)
2340 + readb(&prcslink->var.rx_packet.rx_data_length[1]))
2342 pkt_addr = (( readb(&prcslink->var.rx_packet.rx_data_ptr[0]) << 8)
2343 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2346 rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
2349 readb(&prcslink->var.rx_packet.next_frag_rcs_index) != 0xFF);
2350 release_frag_chain(local, prcs);
2353 skb->protocol = eth_type_trans(skb,dev);
2355 dev->last_rx = jiffies;
2356 local->stats.rx_packets++;
2357 local->stats.rx_bytes += total_len;
2359 /* Gather signal strength per address */
2361 /* For the Access Point or the node having started the ad-hoc net
2362 * note : ad-hoc work only in some specific configurations, but we
2363 * kludge in ray_get_wireless_stats... */
2364 if(!memcmp(linksrcaddr, local->bss_id, ETH_ALEN))
2366 /* Update statistics */
2367 /*local->wstats.qual.qual = none ? */
2368 local->wstats.qual.level = siglev;
2369 /*local->wstats.qual.noise = none ? */
2370 local->wstats.qual.updated = 0x2;
2372 /* Now, update the spy stuff */
2374 struct iw_quality wstats;
2375 wstats.level = siglev;
2376 /* wstats.noise = none ? */
2377 /* wstats.qual = none ? */
2378 wstats.updated = 0x2;
2379 /* Update spy records */
2380 wireless_spy_update(dev, linksrcaddr, &wstats);
2382 #endif /* WIRELESS_SPY */
2384 /*===========================================================================*/
2385 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2387 snaphdr_t *psnap = (snaphdr_t *)(skb->data + RX_MAC_HEADER_LENGTH);
2388 struct mac_header *pmac = (struct mac_header *)skb->data;
2389 unsigned short type = *(unsigned short *)psnap->ethertype;
2390 unsigned int xsap = *(unsigned int *)psnap & 0x00ffffff;
2391 unsigned int org = (*(unsigned int *)psnap->org) & 0x00ffffff;
2393 struct ethhdr *peth;
2394 UCHAR srcaddr[ADDRLEN];
2395 UCHAR destaddr[ADDRLEN];
2397 if (pmac->frame_ctl_2 & FC2_FROM_DS) {
2398 if (pmac->frame_ctl_2 & FC2_TO_DS) { /* AP to AP */
2399 memcpy(destaddr, pmac->addr_3, ADDRLEN);
2400 memcpy(srcaddr, ((unsigned char *)pmac->addr_3) + ADDRLEN, ADDRLEN);
2401 } else { /* AP to terminal */
2402 memcpy(destaddr, pmac->addr_1, ADDRLEN);
2403 memcpy(srcaddr, pmac->addr_3, ADDRLEN);
2405 } else { /* Terminal to AP */
2406 if (pmac->frame_ctl_2 & FC2_TO_DS) {
2407 memcpy(destaddr, pmac->addr_3, ADDRLEN);
2408 memcpy(srcaddr, pmac->addr_2, ADDRLEN);
2409 } else { /* Adhoc */
2410 memcpy(destaddr, pmac->addr_1, ADDRLEN);
2411 memcpy(srcaddr, pmac->addr_2, ADDRLEN);
2418 printk(KERN_DEBUG "skb->data before untranslate");
2420 printk("%02x ",skb->data[i]);
2421 printk("\n" KERN_DEBUG "type = %08x, xsap = %08x, org = %08x\n",
2423 printk(KERN_DEBUG "untranslate skb->data = %p\n",skb->data);
2427 if ( xsap != SNAP_ID) {
2428 /* not a snap type so leave it alone */
2429 DEBUG(3,"ray_cs untranslate NOT SNAP %x\n", *(unsigned int *)psnap & 0x00ffffff);
2431 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2432 peth = (struct ethhdr *)(skb->data + delta);
2433 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2435 else { /* Its a SNAP */
2436 if (org == BRIDGE_ENCAP) { /* EtherII and nuke the LLC */
2437 DEBUG(3,"ray_cs untranslate Bridge encap\n");
2438 delta = RX_MAC_HEADER_LENGTH
2439 + sizeof(struct snaphdr_t) - ETH_HLEN;
2440 peth = (struct ethhdr *)(skb->data + delta);
2441 peth->h_proto = type;
2444 if (org == RFC1042_ENCAP) {
2448 DEBUG(3,"ray_cs untranslate RFC IPX/AARP\n");
2449 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2450 peth = (struct ethhdr *)(skb->data + delta);
2451 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2454 DEBUG(3,"ray_cs untranslate RFC default\n");
2455 delta = RX_MAC_HEADER_LENGTH +
2456 sizeof(struct snaphdr_t) - ETH_HLEN;
2457 peth = (struct ethhdr *)(skb->data + delta);
2458 peth->h_proto = type;
2463 printk("ray_cs untranslate very confused by packet\n");
2464 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2465 peth = (struct ethhdr *)(skb->data + delta);
2466 peth->h_proto = type;
2470 /* TBD reserve skb_reserve(skb, delta); */
2471 skb_pull(skb, delta);
2472 DEBUG(3,"untranslate after skb_pull(%d), skb->data = %p\n",delta,skb->data);
2473 memcpy(peth->h_dest, destaddr, ADDRLEN);
2474 memcpy(peth->h_source, srcaddr, ADDRLEN);
2478 printk(KERN_DEBUG "skb->data after untranslate:");
2480 printk("%02x ",skb->data[i]);
2484 } /* end untranslate */
2485 /*===========================================================================*/
2486 /* Copy data from circular receive buffer to PC memory.
2487 * dest = destination address in PC memory
2488 * pkt_addr = source address in receive buffer
2489 * len = length of packet to copy
2491 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int length)
2493 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2494 if (wrap_bytes <= 0)
2496 memcpy_fromio(dest,local->rmem + pkt_addr,length);
2498 else /* Packet wrapped in circular buffer */
2500 memcpy_fromio(dest,local->rmem+pkt_addr,length - wrap_bytes);
2501 memcpy_fromio(dest + length - wrap_bytes, local->rmem, wrap_bytes);
2505 /*===========================================================================*/
2506 static void release_frag_chain(ray_dev_t *local, struct rcs __iomem * prcs)
2508 struct rcs __iomem *prcslink = prcs;
2510 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2513 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2514 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
2515 DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
2518 prcslink = rcs_base(local) + rcsindex;
2519 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2521 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2523 /*===========================================================================*/
2524 static void authenticate(ray_dev_t *local)
2526 dev_link_t *link = local->finder;
2527 DEBUG(0,"ray_cs Starting authentication.\n");
2528 if (!(link->state & DEV_PRESENT)) {
2529 DEBUG(2,"ray_cs authenticate - device not present\n");
2533 del_timer(&local->timer);
2534 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2535 local->timer.function = &join_net;
2538 local->timer.function = &authenticate_timeout;
2540 local->timer.expires = jiffies + HZ*2;
2541 local->timer.data = (long)local;
2542 add_timer(&local->timer);
2543 local->authentication_state = AWAITING_RESPONSE;
2544 } /* end authenticate */
2545 /*===========================================================================*/
2546 static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2547 unsigned int pkt_addr, int rx_len)
2550 struct rx_msg *msg = (struct rx_msg *)buff;
2552 del_timer(&local->timer);
2554 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2555 /* if we are trying to get authenticated */
2556 if (local->sparm.b4.a_network_type == ADHOC) {
2557 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]);
2558 if (msg->var[2] == 1) {
2559 DEBUG(0,"ray_cs Sending authentication response.\n");
2560 if (!build_auth_frame (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2561 local->authentication_state = NEED_TO_AUTH;
2562 memcpy(local->auth_id, msg->mac.addr_2, ADDRLEN);
2566 else /* Infrastructure network */
2568 if (local->authentication_state == AWAITING_RESPONSE) {
2569 /* Verify authentication sequence #2 and success */
2570 if (msg->var[2] == 2) {
2571 if ((msg->var[3] | msg->var[4]) == 0) {
2572 DEBUG(1,"Authentication successful\n");
2573 local->card_status = CARD_AUTH_COMPLETE;
2575 local->authentication_state = AUTHENTICATED;
2578 DEBUG(0,"Authentication refused\n");
2579 local->card_status = CARD_AUTH_REFUSED;
2580 join_net((u_long)local);
2581 local->authentication_state = UNAUTHENTICATED;
2587 } /* end rx_authenticate */
2588 /*===========================================================================*/
2589 static void associate(ray_dev_t *local)
2591 struct ccs __iomem *pccs;
2592 dev_link_t *link = local->finder;
2593 struct net_device *dev = link->priv;
2595 if (!(link->state & DEV_PRESENT)) {
2596 DEBUG(2,"ray_cs associate - device not present\n");
2599 /* If no tx buffers available, return*/
2600 if ((ccsindex = get_free_ccs(local)) < 0)
2602 /* TBD should never be here but... what if we are? */
2603 DEBUG(1,"ray_cs associate - No free ccs\n");
2606 DEBUG(1,"ray_cs Starting association with access point\n");
2607 pccs = ccs_base(local) + ccsindex;
2608 /* fill in the CCS */
2609 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2610 /* Interrupt the firmware to process the command */
2611 if (interrupt_ecf(local, ccsindex)) {
2612 DEBUG(1,"ray_cs associate failed - ECF not ready for intr\n");
2613 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2615 del_timer(&local->timer);
2616 local->timer.expires = jiffies + HZ*2;
2617 local->timer.data = (long)local;
2618 local->timer.function = &join_net;
2619 add_timer(&local->timer);
2620 local->card_status = CARD_ASSOC_FAILED;
2623 if (!sniffer) netif_start_queue(dev);
2625 } /* end associate */
2626 /*===========================================================================*/
2627 static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2628 unsigned int pkt_addr, int rx_len)
2631 struct rx_msg *msg = (struct rx_msg *)buff;
2633 DEBUG(0,"Deauthentication frame received\n");
2634 local->authentication_state = UNAUTHENTICATED;
2635 /* Need to reauthenticate or rejoin depending on reason code */
2636 /* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2639 /*===========================================================================*/
2640 static void clear_interrupt(ray_dev_t *local)
2642 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
2644 /*===========================================================================*/
2645 #ifdef CONFIG_PROC_FS
2646 #define MAXDATA (PAGE_SIZE - 80)
2648 static char *card_status[] = {
2649 "Card inserted - uninitialized", /* 0 */
2650 "Card not downloaded", /* 1 */
2651 "Waiting for download parameters", /* 2 */
2652 "Card doing acquisition", /* 3 */
2653 "Acquisition complete", /* 4 */
2654 "Authentication complete", /* 5 */
2655 "Association complete", /* 6 */
2656 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2657 "Card init error", /* 11 */
2658 "Download parameters error", /* 12 */
2660 "Acquisition failed", /* 14 */
2661 "Authentication refused", /* 15 */
2662 "Association failed" /* 16 */
2665 static char *nettype[] = {"Adhoc", "Infra "};
2666 static char *framing[] = {"Encapsulation", "Translation"}
2668 /*===========================================================================*/
2669 static int ray_cs_proc_read(char *buf, char **start, off_t offset, int len)
2671 /* Print current values which are not available via other means
2676 struct net_device *dev;
2679 struct freq_hop_element *pfh;
2685 dev = (struct net_device *)link->priv;
2688 local = (ray_dev_t *)dev->priv;
2694 len += sprintf(buf + len, "Raylink Wireless LAN driver status\n");
2695 len += sprintf(buf + len, "%s\n", rcsid);
2696 /* build 4 does not report version, and field is 0x55 after memtest */
2697 len += sprintf(buf + len, "Firmware version = ");
2698 if (local->fw_ver == 0x55)
2699 len += sprintf(buf + len, "4 - Use dump_cis for more details\n");
2701 len += sprintf(buf + len, "%2d.%02d.%02d\n",
2702 local->fw_ver, local->fw_bld, local->fw_var);
2704 for (i=0; i<32; i++) c[i] = local->sparm.b5.a_current_ess_id[i];
2706 len += sprintf(buf + len, "%s network ESSID = \"%s\"\n",
2707 nettype[local->sparm.b5.a_network_type], c);
2710 len += sprintf(buf + len,
2711 "BSSID = %02x:%02x:%02x:%02x:%02x:%02x\n",
2712 p[0],p[1],p[2],p[3],p[4],p[5]);
2714 len += sprintf(buf + len, "Country code = %d\n",
2715 local->sparm.b5.a_curr_country_code);
2717 i = local->card_status;
2720 len += sprintf(buf + len, "Card status = %s\n", card_status[i]);
2722 len += sprintf(buf + len, "Framing mode = %s\n",framing[translate]);
2724 len += sprintf(buf + len, "Last pkt signal lvl = %d\n", local->last_rsl);
2726 if (local->beacon_rxed) {
2727 /* Pull some fields out of last beacon received */
2728 len += sprintf(buf + len, "Beacon Interval = %d Kus\n",
2729 local->last_bcn.beacon_intvl[0]
2730 + 256 * local->last_bcn.beacon_intvl[1]);
2732 p = local->last_bcn.elements;
2733 if (p[0] == C_ESSID_ELEMENT_ID) p += p[1] + 2;
2735 len += sprintf(buf + len, "Parse beacon failed at essid element id = %d\n",p[0]);
2739 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2740 len += sprintf(buf + len, "Supported rate codes = ");
2741 for (i=2; i<p[1] + 2; i++)
2742 len += sprintf(buf + len, "0x%02x ", p[i]);
2743 len += sprintf(buf + len, "\n");
2747 len += sprintf(buf + len, "Parse beacon failed at rates element\n");
2751 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2752 pfh = (struct freq_hop_element *)p;
2753 len += sprintf(buf + len, "Hop dwell = %d Kus\n",
2754 pfh->dwell_time[0] + 256 * pfh->dwell_time[1]);
2755 len += sprintf(buf + len, "Hop set = %d \n", pfh->hop_set);
2756 len += sprintf(buf + len, "Hop pattern = %d \n", pfh->hop_pattern);
2757 len += sprintf(buf + len, "Hop index = %d \n", pfh->hop_index);
2761 len += sprintf(buf + len, "Parse beacon failed at FH param element\n");
2765 len += sprintf(buf + len, "No beacons received\n");
2771 /*===========================================================================*/
2772 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2775 struct ccs __iomem *pccs;
2776 struct tx_msg __iomem *ptx;
2779 /* If no tx buffers available, return */
2780 if ((ccsindex = get_free_tx_ccs(local)) < 0)
2782 DEBUG(1,"ray_cs send authenticate - No free tx ccs\n");
2786 pccs = ccs_base(local) + ccsindex;
2788 /* Address in card space */
2789 addr = TX_BUF_BASE + (ccsindex << 11);
2790 /* fill in the CCS */
2791 writeb(CCS_TX_REQUEST, &pccs->cmd);
2792 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2793 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2794 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2795 writeb(TX_AUTHENTICATE_LENGTH_LSB,pccs->var.tx_request.tx_data_length + 1);
2796 writeb(0, &pccs->var.tx_request.pow_sav_mode);
2798 ptx = local->sram + addr;
2799 /* fill in the mac header */
2800 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2801 writeb(0, &ptx->mac.frame_ctl_2);
2803 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2804 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2805 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
2807 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2808 memset_io(ptx->var, 0, 6);
2809 writeb(auth_type & 0xff, ptx->var + 2);
2811 /* Interrupt the firmware to process the command */
2812 if (interrupt_ecf(local, ccsindex)) {
2813 DEBUG(1,"ray_cs send authentication request failed - ECF not ready for intr\n");
2814 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2818 } /* End build_auth_frame */
2820 /*===========================================================================*/
2821 #ifdef CONFIG_PROC_FS
2822 static void raycs_write(const char *name, write_proc_t *w, void *data)
2824 struct proc_dir_entry * entry = create_proc_entry(name, S_IFREG | S_IWUSR, NULL);
2826 entry->write_proc = w;
2831 static int write_essid(struct file *file, const char __user *buffer, unsigned long count, void *data)
2833 static char proc_essid[33];
2838 memset(proc_essid, 0, 33);
2839 if (copy_from_user(proc_essid, buffer, len))
2845 static int write_int(struct file *file, const char __user *buffer, unsigned long count, void *data)
2847 static char proc_number[10];
2856 if (copy_from_user(proc_number, buffer, count))
2862 unsigned int c = *p - '0';
2873 static struct pcmcia_device_id ray_ids[] = {
2874 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2877 MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2879 static struct pcmcia_driver ray_driver = {
2880 .owner = THIS_MODULE,
2884 .probe = ray_attach,
2885 .remove = ray_detach,
2886 .id_table = ray_ids,
2887 .suspend = ray_suspend,
2888 .resume = ray_resume,
2891 static int __init init_ray_cs(void)
2895 DEBUG(1, "%s\n", rcsid);
2896 rc = pcmcia_register_driver(&ray_driver);
2897 DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n",rc);
2899 #ifdef CONFIG_PROC_FS
2900 proc_mkdir("driver/ray_cs", NULL);
2902 create_proc_info_entry("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_read);
2903 raycs_write("driver/ray_cs/essid", write_essid, NULL);
2904 raycs_write("driver/ray_cs/net_type", write_int, &net_type);
2905 raycs_write("driver/ray_cs/translate", write_int, &translate);
2907 if (translate != 0) translate = 1;
2911 /*===========================================================================*/
2913 static void __exit exit_ray_cs(void)
2915 DEBUG(0, "ray_cs: cleanup_module\n");
2917 #ifdef CONFIG_PROC_FS
2918 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2919 remove_proc_entry("driver/ray_cs/essid", NULL);
2920 remove_proc_entry("driver/ray_cs/net_type", NULL);
2921 remove_proc_entry("driver/ray_cs/translate", NULL);
2922 remove_proc_entry("driver/ray_cs", NULL);
2925 pcmcia_unregister_driver(&ray_driver);
2926 BUG_ON(dev_list != NULL);
2929 module_init(init_ray_cs);
2930 module_exit(exit_ray_cs);
2932 /*===========================================================================*/