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/module.h>
34 #include <linux/kernel.h>
35 #include <linux/proc_fs.h>
36 #include <linux/ptrace.h>
37 #include <linux/seq_file.h>
38 #include <linux/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>
48 #include <linux/ieee80211.h>
50 #include <pcmcia/cs_types.h>
51 #include <pcmcia/cs.h>
52 #include <pcmcia/cistpl.h>
53 #include <pcmcia/cisreg.h>
54 #include <pcmcia/ds.h>
55 #include <pcmcia/mem_op.h>
57 #include <linux/wireless.h>
58 #include <net/iw_handler.h>
61 #include <asm/system.h>
62 #include <asm/byteorder.h>
63 #include <asm/uaccess.h>
65 /* Warning : these stuff will slow down the driver... */
66 #define WIRELESS_SPY /* Enable spying addresses */
67 /* Definitions we need for spy */
68 typedef struct iw_statistics iw_stats;
69 typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
74 /* All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
75 you do not define PCMCIA_DEBUG at all, all the debug code will be
76 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
77 be present but disabled -- but it can then be enabled for specific
78 modules at load time with a 'pc_debug=#' option to insmod.
82 #define PCMCIA_DEBUG RAYLINK_DEBUG
86 static int pc_debug = PCMCIA_DEBUG;
87 module_param(pc_debug, int, 0);
88 /* #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); */
89 #define DEBUG(n, args...) if (pc_debug>(n)) printk(args);
91 #define DEBUG(n, args...)
93 /** Prototypes based on PCMCIA skeleton driver *******************************/
94 static int ray_config(struct pcmcia_device *link);
95 static void ray_release(struct pcmcia_device *link);
96 static void ray_detach(struct pcmcia_device *p_dev);
98 /***** Prototypes indicated by device structure ******************************/
99 static int ray_dev_close(struct net_device *dev);
100 static int ray_dev_config(struct net_device *dev, struct ifmap *map);
101 static struct net_device_stats *ray_get_stats(struct net_device *dev);
102 static int ray_dev_init(struct net_device *dev);
104 static const struct ethtool_ops netdev_ethtool_ops;
106 static int ray_open(struct net_device *dev);
107 static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev);
108 static void set_multicast_list(struct net_device *dev);
109 static void ray_update_multi_list(struct net_device *dev, int all);
110 static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
111 unsigned char *data, int len);
112 static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, UCHAR msg_type,
113 unsigned char *data);
114 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
115 static iw_stats * ray_get_wireless_stats(struct net_device * dev);
116 static const struct iw_handler_def ray_handler_def;
118 /***** Prototypes for raylink functions **************************************/
119 static int asc_to_int(char a);
120 static void authenticate(ray_dev_t *local);
121 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
122 static void authenticate_timeout(u_long);
123 static int get_free_ccs(ray_dev_t *local);
124 static int get_free_tx_ccs(ray_dev_t *local);
125 static void init_startup_params(ray_dev_t *local);
126 static int parse_addr(char *in_str, UCHAR *out);
127 static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev, UCHAR type);
128 static int ray_init(struct net_device *dev);
129 static int interrupt_ecf(ray_dev_t *local, int ccs);
130 static void ray_reset(struct net_device *dev);
131 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
132 static void verify_dl_startup(u_long);
134 /* Prototypes for interrpt time functions **********************************/
135 static irqreturn_t ray_interrupt (int reg, void *dev_id);
136 static void clear_interrupt(ray_dev_t *local);
137 static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
138 unsigned int pkt_addr, int rx_len);
139 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
140 static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
141 static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
142 static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
143 unsigned int pkt_addr, int rx_len);
144 static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, unsigned int pkt_addr,
146 static void associate(ray_dev_t *local);
148 /* Card command functions */
149 static int dl_startup_params(struct net_device *dev);
150 static void join_net(u_long local);
151 static void start_net(u_long local);
152 /* void start_net(ray_dev_t *local); */
154 /*===========================================================================*/
155 /* Parameters that can be set with 'insmod' */
157 /* ADHOC=0, Infrastructure=1 */
158 static int net_type = ADHOC;
160 /* Hop dwell time in Kus (1024 us units defined by 802.11) */
161 static int hop_dwell = 128;
163 /* Beacon period in Kus */
164 static int beacon_period = 256;
166 /* power save mode (0 = off, 1 = save power) */
169 /* String for network's Extended Service Set ID. 32 Characters max */
172 /* Default to encapsulation unless translation requested */
173 static int translate = 1;
175 static int country = USA;
181 /* 48 bit physical card address if overriding card's real physical
182 * address is required. Since IEEE 802.11 addresses are 48 bits
183 * like ethernet, an int can't be used, so a string is used. To
184 * allow use of addresses starting with a decimal digit, the first
185 * character must be a letter and will be ignored. This letter is
186 * followed by up to 12 hex digits which are the address. If less
187 * than 12 digits are used, the address will be left filled with 0's.
188 * Note that bit 0 of the first byte is the broadcast bit, and evil
189 * things will happen if it is not 0 in a card address.
191 static char *phy_addr = NULL;
194 /* A struct pcmcia_device structure has fields for most things that are needed
195 to keep track of a socket, but there will usually be some device
196 specific information that also needs to be kept track of. The
197 'priv' pointer in a struct pcmcia_device structure can be used to point to
198 a device-specific private data structure, like this.
200 static unsigned int ray_mem_speed = 500;
202 /* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
203 static struct pcmcia_device *this_device = NULL;
205 MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
206 MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
207 MODULE_LICENSE("GPL");
209 module_param(net_type, int, 0);
210 module_param(hop_dwell, int, 0);
211 module_param(beacon_period, int, 0);
212 module_param(psm, int, 0);
213 module_param(essid, charp, 0);
214 module_param(translate, int, 0);
215 module_param(country, int, 0);
216 module_param(sniffer, int, 0);
217 module_param(bc, int, 0);
218 module_param(phy_addr, charp, 0);
219 module_param(ray_mem_speed, int, 0);
221 static UCHAR b5_default_startup_parms[] = {
222 0, 0, /* Adhoc station */
223 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
224 0, 0, 0, 0, 0, 0, 0, 0,
225 0, 0, 0, 0, 0, 0, 0, 0,
226 0, 0, 0, 0, 0, 0, 0, 0,
227 1, 0, /* Active scan, CA Mode */
228 0, 0, 0, 0, 0, 0, /* No default MAC addr */
229 0x7f, 0xff, /* Frag threshold */
230 0x00, 0x80, /* Hop time 128 Kus*/
231 0x01, 0x00, /* Beacon period 256 Kus */
232 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
233 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
234 0x7f, 0xff, /* RTS threshold */
235 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
236 0x05, /* assoc resp timeout thresh */
237 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max*/
238 0, /* Promiscuous mode */
239 0x0c, 0x0bd, /* Unique word */
240 0x32, /* Slot time */
241 0xff, 0xff, /* roam-low snr, low snr count */
242 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
243 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
244 /* b4 - b5 differences start here */
245 0x00, 0x3f, /* CW max */
246 0x00, 0x0f, /* CW min */
247 0x04, 0x08, /* Noise gain, limit offset */
248 0x28, 0x28, /* det rssi, med busy offsets */
249 7, /* det sync thresh */
250 0, 2, 2, /* test mode, min, max */
251 0, /* allow broadcast SSID probe resp */
252 0, 0, /* privacy must start, can join */
253 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
256 static UCHAR b4_default_startup_parms[] = {
257 0, 0, /* Adhoc station */
258 'L','I','N','U','X', 0, 0, 0, /* 32 char ESSID */
259 0, 0, 0, 0, 0, 0, 0, 0,
260 0, 0, 0, 0, 0, 0, 0, 0,
261 0, 0, 0, 0, 0, 0, 0, 0,
262 1, 0, /* Active scan, CA Mode */
263 0, 0, 0, 0, 0, 0, /* No default MAC addr */
264 0x7f, 0xff, /* Frag threshold */
265 0x02, 0x00, /* Hop time */
266 0x00, 0x01, /* Beacon period */
267 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout*/
268 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
269 0x7f, 0xff, /* RTS threshold */
270 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
271 0x05, /* assoc resp timeout thresh */
272 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max*/
273 0, /* Promiscuous mode */
274 0x0c, 0x0bd, /* Unique word */
275 0x4e, /* Slot time (TBD seems wrong)*/
276 0xff, 0xff, /* roam-low snr, low snr count */
277 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
278 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
279 /* b4 - b5 differences start here */
280 0x3f, 0x0f, /* CW max, min */
281 0x04, 0x08, /* Noise gain, limit offset */
282 0x28, 0x28, /* det rssi, med busy offsets */
283 7, /* det sync thresh */
284 0, 2, 2 /* test mode, min, max*/
286 /*===========================================================================*/
287 static unsigned char eth2_llc[] = {0xaa, 0xaa, 3, 0, 0, 0};
289 static char hop_pattern_length[] = { 1,
290 USA_HOP_MOD, EUROPE_HOP_MOD,
291 JAPAN_HOP_MOD, KOREA_HOP_MOD,
292 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
293 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
297 static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
299 /*=============================================================================
300 ray_attach() creates an "instance" of the driver, allocating
301 local data structures for one device. The device is registered
303 The dev_link structure is initialized, but we don't actually
304 configure the card at this point -- we wait until we receive a
305 card insertion event.
306 =============================================================================*/
307 static int ray_probe(struct pcmcia_device *p_dev)
310 struct net_device *dev;
312 DEBUG(1, "ray_attach()\n");
314 /* Allocate space for private device-specific data */
315 dev = alloc_etherdev(sizeof(ray_dev_t));
319 local = netdev_priv(dev);
320 local->finder = p_dev;
322 /* The io structure describes IO port mapping. None used here */
323 p_dev->io.NumPorts1 = 0;
324 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
325 p_dev->io.IOAddrLines = 5;
327 /* Interrupt setup. For PCMCIA, driver takes what's given */
328 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
329 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
330 p_dev->irq.Handler = &ray_interrupt;
332 /* General socket configuration */
333 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
334 p_dev->conf.IntType = INT_MEMORY_AND_IO;
335 p_dev->conf.ConfigIndex = 1;
338 p_dev->irq.Instance = dev;
340 local->finder = p_dev;
341 local->card_status = CARD_INSERTED;
342 local->authentication_state = UNAUTHENTICATED;
343 local->num_multi = 0;
344 DEBUG(2,"ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
345 p_dev,dev,local,&ray_interrupt);
347 /* Raylink entries in the device structure */
348 dev->hard_start_xmit = &ray_dev_start_xmit;
349 dev->set_config = &ray_dev_config;
350 dev->get_stats = &ray_get_stats;
351 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
352 dev->wireless_handlers = &ray_handler_def;
354 local->wireless_data.spy_data = &local->spy_data;
355 dev->wireless_data = &local->wireless_data;
356 #endif /* WIRELESS_SPY */
358 dev->set_multicast_list = &set_multicast_list;
360 DEBUG(2,"ray_cs ray_attach calling ether_setup.)\n");
361 dev->init = &ray_dev_init;
362 dev->open = &ray_open;
363 dev->stop = &ray_dev_close;
364 netif_stop_queue(dev);
366 init_timer(&local->timer);
369 return ray_config(p_dev);
374 /*=============================================================================
375 This deletes a driver "instance". The device is de-registered
376 with Card Services. If it has been released, all local data
377 structures are freed. Otherwise, the structures will be freed
378 when the device is released.
379 =============================================================================*/
380 static void ray_detach(struct pcmcia_device *link)
382 struct net_device *dev;
385 DEBUG(1, "ray_detach(0x%p)\n", link);
392 local = netdev_priv(dev);
393 del_timer(&local->timer);
396 if (link->dev_node) unregister_netdev(dev);
399 DEBUG(2,"ray_cs ray_detach ending\n");
401 /*=============================================================================
402 ray_config() is run after a CARD_INSERTION event
403 is received, to configure the PCMCIA socket, and to make the
404 ethernet device available to the system.
405 =============================================================================*/
406 #define CS_CHECK(fn, ret) \
407 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
408 #define MAX_TUPLE_SIZE 128
409 static int ray_config(struct pcmcia_device *link)
411 int last_fn = 0, last_ret = 0;
415 struct net_device *dev = (struct net_device *)link->priv;
416 ray_dev_t *local = netdev_priv(dev);
418 DEBUG(1, "ray_config(0x%p)\n", link);
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] : " ");
427 /* Now allocate an interrupt line. Note that this does not
428 actually assign a handler to the interrupt.
430 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
431 dev->irq = link->irq.AssignedIRQ;
433 /* This actually configures the PCMCIA socket -- setting up
434 the I/O windows and the interrupt mapping.
436 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
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;
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);
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;
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);
458 /*** Set up window for attribute memory ***********************************/
459 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
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);
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) {
476 SET_NETDEV_DEV(dev, &handle_to_dev(link));
477 i = register_netdev(dev);
479 printk("ray_config register_netdev() failed\n");
484 strcpy(local->node.dev_name, dev->name);
485 link->dev_node = &local->node;
487 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
488 dev->name, dev->irq, dev->dev_addr);
493 cs_error(link, last_fn, last_ret);
499 static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
501 return dev->sram + CCS_BASE;
504 static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
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
513 return dev->sram + CCS_BASE;
516 /*===========================================================================*/
517 static int ray_init(struct net_device *dev)
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");
530 local->net_type = net_type;
531 local->sta_type = TYPE_STA;
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));
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;
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);
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);
559 init_startup_params(local);
561 /* copy mac address to startup parameters */
562 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr))
564 p = local->sparm.b4.a_mac_addr;
568 memcpy(&local->sparm.b4.a_mac_addr,
569 &local->startup_res.station_addr, ADDRLEN);
570 p = local->sparm.b4.a_mac_addr;
573 clear_interrupt(local); /* Clear any interrupt from the card */
574 local->card_status = CARD_AWAITING_PARAM;
575 DEBUG(2,"ray_init ending\n");
578 /*===========================================================================*/
579 /* Download startup parameters to the card and command it to read them */
580 static int dl_startup_params(struct net_device *dev)
583 ray_dev_t *local = netdev_priv(dev);
584 struct ccs __iomem *pccs;
585 struct pcmcia_device *link = local->finder;
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");
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));
598 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
599 sizeof(struct b5_startup_params));
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);
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");
624 } /* dl_startup_params */
625 /*===========================================================================*/
626 static void init_startup_params(ray_dev_t *local)
630 if (country > JAPAN_TEST) country = USA;
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
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
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;
661 local->sparm.b4.a_ack_timeout = 0x50;
662 local->sparm.b4.a_sifs = 0x3f;
665 else { /* Version 5 uses real kus values */
666 memcpy((UCHAR *)&local->sparm.b5, b5_default_startup_parms,
667 sizeof(struct b5_startup_params));
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;
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];
680 local->sparm.b4.a_network_type = net_type & 0x01;
681 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
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)
689 ray_dev_t *local = (ray_dev_t *)data;
690 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
692 struct pcmcia_device *link = local->finder;
694 if (!(pcmcia_dev_present(link))) {
695 DEBUG(2,"ray_cs verify_dl_startup - device not present\n");
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));
710 status = readb(&pccs->buffer_status);
711 if (status!= CCS_BUFFER_FREE)
713 printk(KERN_INFO "Download startup params failed. Status = %d\n",
715 local->card_status = CARD_DL_PARAM_ERROR;
718 if (local->sparm.b4.a_network_type == ADHOC)
719 start_net((u_long)local);
721 join_net((u_long)local);
724 } /* end verify_dl_startup */
725 /*===========================================================================*/
726 /* Command card to start a network */
727 static void start_net(u_long data)
729 ray_dev_t *local = (ray_dev_t *)data;
730 struct ccs __iomem *pccs;
732 struct pcmcia_device *link = local->finder;
733 if (!(pcmcia_dev_present(link))) {
734 DEBUG(2,"ray_cs start_net - device not present\n");
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);
748 local->card_status = CARD_DOING_ACQ;
750 } /* end start_net */
751 /*===========================================================================*/
752 /* Command card to join a network */
753 static void join_net(u_long data)
755 ray_dev_t *local = (ray_dev_t *)data;
757 struct ccs __iomem *pccs;
759 struct pcmcia_device *link = local->finder;
761 if (!(pcmcia_dev_present(link))) {
762 DEBUG(2,"ray_cs join_net - device not present\n");
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);
777 local->card_status = CARD_DOING_ACQ;
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)
787 struct net_device *dev = link->priv;
788 ray_dev_t *local = netdev_priv(dev);
791 DEBUG(1, "ray_release(0x%p)\n", link);
793 del_timer(&local->timer);
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 != 0 ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
801 i = pcmcia_release_window(local->rmem_handle);
802 if ( i != 0 ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
803 pcmcia_disable_device(link);
805 DEBUG(2,"ray_release ending\n");
808 static int ray_suspend(struct pcmcia_device *link)
810 struct net_device *dev = link->priv;
813 netif_device_detach(dev);
818 static int ray_resume(struct pcmcia_device *link)
820 struct net_device *dev = link->priv;
824 netif_device_attach(dev);
830 /*===========================================================================*/
831 int ray_dev_init(struct net_device *dev)
833 #ifdef RAY_IMMEDIATE_INIT
835 #endif /* RAY_IMMEDIATE_INIT */
836 ray_dev_t *local = netdev_priv(dev);
837 struct pcmcia_device *link = local->finder;
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");
844 #ifdef RAY_IMMEDIATE_INIT
845 /* Download startup parameters */
846 if ( (i = dl_startup_params(dev)) < 0)
848 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
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",
858 #endif /* RAY_IMMEDIATE_INIT */
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);
864 DEBUG(2,"ray_dev_init ending\n");
867 /*===========================================================================*/
868 static int ray_dev_config(struct net_device *dev, struct ifmap *map)
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");
881 /*===========================================================================*/
882 static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
884 ray_dev_t *local = netdev_priv(dev);
885 struct pcmcia_device *link = local->finder;
886 short length = skb->len;
888 if (!(pcmcia_dev_present(link))) {
889 DEBUG(2,"ray_dev_start_xmit - device not present\n");
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);
902 if (length < ETH_ZLEN)
904 if (skb_padto(skb, ETH_ZLEN))
908 switch (ray_hw_xmit( skb->data, length, dev, DATA_TYPE)) {
911 netif_stop_queue(dev);
917 dev->trans_start = jiffies;
922 } /* ray_dev_start_xmit */
923 /*===========================================================================*/
924 static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev,
927 ray_dev_t *local = netdev_priv(dev);
928 struct ccs __iomem *pccs;
931 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
932 short int addr; /* Address of xmit buffer in card space */
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)
937 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",len);
940 switch (ccsindex = get_free_tx_ccs(local)) {
942 DEBUG(2,"ray_hw_xmit tx_ccs table busy\n");
944 DEBUG(2,"ray_hw_xmit No free tx ccs\n");
946 netif_stop_queue(dev);
951 addr = TX_BUF_BASE + (ccsindex << 11);
953 if (msg_type == DATA_TYPE) {
954 local->stats.tx_bytes += len;
955 local->stats.tx_packets++;
958 ptx = local->sram + addr;
960 ray_build_header(local, ptx, msg_type, data);
962 offset = translate_frame(local, ptx, data, len);
964 else { /* Encapsulate frame */
965 /* TBD TIB length will move address of ptx->var */
966 memcpy_toio(&ptx->var, data, len);
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);
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?
992 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
996 } /* end ray_hw_xmit */
997 /*===========================================================================*/
998 static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, unsigned char *data,
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]);
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;
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;
1023 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1024 return 0 - ETH_HLEN;
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)
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);
1045 else /* infrastructure */
1047 if (local->sparm.b4.a_acting_as_ap_status)
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);
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);
1062 } /* end encapsulate_frame */
1065 /*===========================================================================*/
1067 static void netdev_get_drvinfo(struct net_device *dev,
1068 struct ethtool_drvinfo *info)
1070 strcpy(info->driver, "ray_cs");
1073 static const struct ethtool_ops netdev_ethtool_ops = {
1074 .get_drvinfo = netdev_get_drvinfo,
1077 /*====================================================================*/
1079 /*------------------------------------------------------------------*/
1081 * Wireless Handler : get protocol name
1083 static int ray_get_name(struct net_device *dev,
1084 struct iw_request_info *info,
1088 strcpy(cwrq, "IEEE 802.11-FH");
1092 /*------------------------------------------------------------------*/
1094 * Wireless Handler : set frequency
1096 static int ray_set_freq(struct net_device *dev,
1097 struct iw_request_info *info,
1098 struct iw_freq *fwrq,
1101 ray_dev_t *local = netdev_priv(dev);
1102 int err = -EINPROGRESS; /* Call commit handler */
1104 /* Reject if card is already initialised */
1105 if(local->card_status != CARD_AWAITING_PARAM)
1108 /* Setting by channel number */
1109 if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0))
1112 local->sparm.b5.a_hop_pattern = fwrq->m;
1117 /*------------------------------------------------------------------*/
1119 * Wireless Handler : get frequency
1121 static int ray_get_freq(struct net_device *dev,
1122 struct iw_request_info *info,
1123 struct iw_freq *fwrq,
1126 ray_dev_t *local = netdev_priv(dev);
1128 fwrq->m = local->sparm.b5.a_hop_pattern;
1133 /*------------------------------------------------------------------*/
1135 * Wireless Handler : set ESSID
1137 static int ray_set_essid(struct net_device *dev,
1138 struct iw_request_info *info,
1139 struct iw_point *dwrq,
1142 ray_dev_t *local = netdev_priv(dev);
1144 /* Reject if card is already initialised */
1145 if(local->card_status != CARD_AWAITING_PARAM)
1148 /* Check if we asked for `any' */
1149 if(dwrq->flags == 0) {
1150 /* Corey : can you do that ? */
1153 /* Check the size of the string */
1154 if(dwrq->length > IW_ESSID_MAX_SIZE) {
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);
1163 return -EINPROGRESS; /* Call commit handler */
1166 /*------------------------------------------------------------------*/
1168 * Wireless Handler : get ESSID
1170 static int ray_get_essid(struct net_device *dev,
1171 struct iw_request_info *info,
1172 struct iw_point *dwrq,
1175 ray_dev_t *local = netdev_priv(dev);
1177 /* Get the essid that was set */
1178 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
1181 dwrq->length = strlen(extra);
1182 dwrq->flags = 1; /* active */
1187 /*------------------------------------------------------------------*/
1189 * Wireless Handler : get AP address
1191 static int ray_get_wap(struct net_device *dev,
1192 struct iw_request_info *info,
1193 struct sockaddr *awrq,
1196 ray_dev_t *local = netdev_priv(dev);
1198 memcpy(awrq->sa_data, local->bss_id, ETH_ALEN);
1199 awrq->sa_family = ARPHRD_ETHER;
1204 /*------------------------------------------------------------------*/
1206 * Wireless Handler : set Bit-Rate
1208 static int ray_set_rate(struct net_device *dev,
1209 struct iw_request_info *info,
1210 struct iw_param *vwrq,
1213 ray_dev_t *local = netdev_priv(dev);
1215 /* Reject if card is already initialised */
1216 if(local->card_status != CARD_AWAITING_PARAM)
1219 /* Check if rate is in range */
1220 if((vwrq->value != 1000000) && (vwrq->value != 2000000))
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;
1228 local->net_default_tx_rate = vwrq->value/500000;
1233 /*------------------------------------------------------------------*/
1235 * Wireless Handler : get Bit-Rate
1237 static int ray_get_rate(struct net_device *dev,
1238 struct iw_request_info *info,
1239 struct iw_param *vwrq,
1242 ray_dev_t *local = netdev_priv(dev);
1244 if(local->net_default_tx_rate == 3)
1245 vwrq->value = 2000000; /* Hum... */
1247 vwrq->value = local->net_default_tx_rate * 500000;
1248 vwrq->fixed = 0; /* We are in auto mode */
1253 /*------------------------------------------------------------------*/
1255 * Wireless Handler : set RTS threshold
1257 static int ray_set_rts(struct net_device *dev,
1258 struct iw_request_info *info,
1259 struct iw_param *vwrq,
1262 ray_dev_t *local = netdev_priv(dev);
1263 int rthr = vwrq->value;
1265 /* Reject if card is already initialised */
1266 if(local->card_status != CARD_AWAITING_PARAM)
1269 /* if(wrq->u.rts.fixed == 0) we should complain */
1273 if((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
1276 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1277 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
1279 return -EINPROGRESS; /* Call commit handler */
1283 /*------------------------------------------------------------------*/
1285 * Wireless Handler : get RTS threshold
1287 static int ray_get_rts(struct net_device *dev,
1288 struct iw_request_info *info,
1289 struct iw_param *vwrq,
1292 ray_dev_t *local = netdev_priv(dev);
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);
1302 /*------------------------------------------------------------------*/
1304 * Wireless Handler : set Fragmentation threshold
1306 static int ray_set_frag(struct net_device *dev,
1307 struct iw_request_info *info,
1308 struct iw_param *vwrq,
1311 ray_dev_t *local = netdev_priv(dev);
1312 int fthr = vwrq->value;
1314 /* Reject if card is already initialised */
1315 if(local->card_status != CARD_AWAITING_PARAM)
1318 /* if(wrq->u.frag.fixed == 0) should complain */
1322 if((fthr < 256) || (fthr > 2347)) /* To check out ! */
1325 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1326 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
1328 return -EINPROGRESS; /* Call commit handler */
1331 /*------------------------------------------------------------------*/
1333 * Wireless Handler : get Fragmentation threshold
1335 static int ray_get_frag(struct net_device *dev,
1336 struct iw_request_info *info,
1337 struct iw_param *vwrq,
1340 ray_dev_t *local = netdev_priv(dev);
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);
1350 /*------------------------------------------------------------------*/
1352 * Wireless Handler : set Mode of Operation
1354 static int ray_set_mode(struct net_device *dev,
1355 struct iw_request_info *info,
1359 ray_dev_t *local = netdev_priv(dev);
1360 int err = -EINPROGRESS; /* Call commit handler */
1363 /* Reject if card is already initialised */
1364 if(local->card_status != CARD_AWAITING_PARAM)
1373 local->sparm.b5.a_network_type = card_mode;
1382 /*------------------------------------------------------------------*/
1384 * Wireless Handler : get Mode of Operation
1386 static int ray_get_mode(struct net_device *dev,
1387 struct iw_request_info *info,
1391 ray_dev_t *local = netdev_priv(dev);
1393 if(local->sparm.b5.a_network_type)
1394 *uwrq = IW_MODE_INFRA;
1396 *uwrq = IW_MODE_ADHOC;
1401 /*------------------------------------------------------------------*/
1403 * Wireless Handler : get range info
1405 static int ray_get_range(struct net_device *dev,
1406 struct iw_request_info *info,
1407 struct iw_point *dwrq,
1410 struct iw_range *range = (struct iw_range *) extra;
1412 memset((char *) range, 0, sizeof(struct iw_range));
1414 /* Set the length (very important for backward compatibility) */
1415 dwrq->length = sizeof(struct iw_range);
1417 /* Set the Wireless Extension versions */
1418 range->we_version_compiled = WIRELESS_EXT;
1419 range->we_version_source = 9;
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 */
1434 /*------------------------------------------------------------------*/
1436 * Wireless Private Handler : set framing mode
1438 static int ray_set_framing(struct net_device *dev,
1439 struct iw_request_info *info,
1440 union iwreq_data *wrqu,
1443 translate = *(extra); /* Set framing mode */
1448 /*------------------------------------------------------------------*/
1450 * Wireless Private Handler : get framing mode
1452 static int ray_get_framing(struct net_device *dev,
1453 struct iw_request_info *info,
1454 union iwreq_data *wrqu,
1457 *(extra) = translate;
1462 /*------------------------------------------------------------------*/
1464 * Wireless Private Handler : get country
1466 static int ray_get_country(struct net_device *dev,
1467 struct iw_request_info *info,
1468 union iwreq_data *wrqu,
1476 /*------------------------------------------------------------------*/
1478 * Commit handler : called after a bunch of SET operations
1480 static int ray_commit(struct net_device *dev,
1481 struct iw_request_info *info, /* NULL */
1482 void *zwrq, /* NULL */
1483 char *extra) /* NULL */
1488 /*------------------------------------------------------------------*/
1490 * Stats handler : return Wireless Stats
1492 static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1494 ray_dev_t * local = netdev_priv(dev);
1495 struct pcmcia_device *link = local->finder;
1496 struct status __iomem *p = local->sram + STATUS_BASE;
1498 if(local == (ray_dev_t *) NULL)
1499 return (iw_stats *) NULL;
1501 local->wstats.status = local->card_status;
1503 if((local->spy_data.spy_number > 0) && (local->sparm.b5.a_network_type == 0))
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;
1511 #endif /* WIRELESS_SPY */
1513 if(pcmcia_dev_present(link)) {
1514 local->wstats.qual.noise = readb(&p->rxnoise);
1515 local->wstats.qual.updated |= 4;
1518 return &local->wstats;
1519 } /* end ray_get_wireless_stats */
1521 /*------------------------------------------------------------------*/
1523 * Structures to export the Wireless Handlers
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,
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,
1551 #define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
1552 #define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1553 #define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
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,
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" },
1568 static const struct iw_handler_def ray_handler_def =
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,
1579 /*===========================================================================*/
1580 static int ray_open(struct net_device *dev)
1582 ray_dev_t *local = netdev_priv(dev);
1583 struct pcmcia_device *link;
1584 link = local->finder;
1586 DEBUG(1, "ray_open('%s')\n", dev->name);
1588 if (link->open == 0)
1589 local->num_multi = 0;
1592 /* If the card is not started, time to start it ! - Jean II */
1593 if(local->card_status == CARD_AWAITING_PARAM) {
1596 DEBUG(1,"ray_open: doing init now !\n");
1598 /* Download startup parameters */
1599 if ( (i = dl_startup_params(dev)) < 0)
1601 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
1602 "returns 0x%x\n",i);
1607 if (sniffer) netif_stop_queue(dev);
1608 else netif_start_queue(dev);
1610 DEBUG(2,"ray_open ending\n");
1612 } /* end ray_open */
1613 /*===========================================================================*/
1614 static int ray_dev_close(struct net_device *dev)
1616 ray_dev_t *local = netdev_priv(dev);
1617 struct pcmcia_device *link;
1618 link = local->finder;
1620 DEBUG(1, "ray_dev_close('%s')\n", dev->name);
1623 netif_stop_queue(dev);
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 */
1631 } /* end ray_dev_close */
1632 /*===========================================================================*/
1633 static void ray_reset(struct net_device *dev) {
1634 DEBUG(1,"ray_reset entered\n");
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)
1643 struct pcmcia_device *link = local->finder;
1645 if (!(pcmcia_dev_present(link))) {
1646 DEBUG(2,"ray_cs interrupt_ecf - device not present\n");
1649 DEBUG(2,"interrupt_ecf(local=%p, ccs = 0x%x\n",local,ccs);
1652 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & ECF_INTR_SET))
1655 DEBUG(2,"ray_cs interrupt_ecf card not ready for interrupt\n");
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);
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)
1669 struct ccs __iomem *pccs = ccs_base(local);
1670 struct pcmcia_device *link = local->finder;
1672 if (!(pcmcia_dev_present(link))) {
1673 DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n");
1677 if (test_and_set_bit(0,&local->tx_ccs_lock)) {
1678 DEBUG(1,"ray_cs tx_ccs_lock busy\n");
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;
1690 local->tx_ccs_lock = 0;
1691 DEBUG(2,"ray_cs ERROR no free tx CCS for raylink card\n");
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)
1700 struct ccs __iomem *pccs = ccs_base(local);
1701 struct pcmcia_device *link = local->finder;
1703 if (!(pcmcia_dev_present(link))) {
1704 DEBUG(2,"ray_cs get_free_ccs - device not present\n");
1707 if (test_and_set_bit(0,&local->ccs_lock)) {
1708 DEBUG(1,"ray_cs ccs_lock busy\n");
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;
1720 local->ccs_lock = 0;
1721 DEBUG(1,"ray_cs ERROR no free CCS for raylink card\n");
1723 } /* get_free_ccs */
1724 /*===========================================================================*/
1725 static void authenticate_timeout(u_long data)
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"
1731 join_net((u_long)local);
1733 /*===========================================================================*/
1734 static int asc_to_int(char a)
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');
1744 /*===========================================================================*/
1745 static int parse_addr(char *in_str, UCHAR *out)
1751 if (in_str == NULL) return 0;
1752 if ((len = strlen(in_str)) < 2) return 0;
1753 memset(out, 0, ADDRLEN);
1762 if ((k = asc_to_int(in_str[j--])) != -1) out[i] = k;
1766 if ((k = asc_to_int(in_str[j--])) != -1) out[i] += k << 4;
1772 /*===========================================================================*/
1773 static struct net_device_stats *ray_get_stats(struct net_device *dev)
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;
1782 if (readb(&p->mrx_overflow_for_host))
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);
1788 if (readb(&p->mrx_checksum_error_for_host))
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);
1794 if (readb(&p->rx_hec_error_for_host))
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);
1800 return &local->stats;
1802 /*===========================================================================*/
1803 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len)
1805 ray_dev_t *local = netdev_priv(dev);
1806 struct pcmcia_device *link = local->finder;
1809 struct ccs __iomem *pccs;
1811 if (!(pcmcia_dev_present(link))) {
1812 DEBUG(2,"ray_update_parm - device not present\n");
1816 if ((ccsindex = get_free_ccs(local)) < 0)
1818 DEBUG(0,"ray_update_parm - No free ccs\n");
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);
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);
1835 /*===========================================================================*/
1836 static void ray_update_multi_list(struct net_device *dev, int all)
1838 struct dev_mc_list *dmi, **dmip;
1840 struct ccs __iomem *pccs;
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;
1846 if (!(pcmcia_dev_present(link))) {
1847 DEBUG(2,"ray_update_multi_list - device not present\n");
1851 DEBUG(2,"ray_update_multi_list(%p)\n",dev);
1852 if ((ccsindex = get_free_ccs(local)) < 0)
1854 DEBUG(1,"ray_update_multi - No free ccs\n");
1857 pccs = ccs_base(local) + ccsindex;
1858 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
1861 writeb(0xff, &pccs->var);
1862 local->num_multi = 0xff;
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]);
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;
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);
1882 } /* end ray_update_multi_list */
1883 /*===========================================================================*/
1884 static void set_multicast_list(struct net_device *dev)
1886 ray_dev_t *local = netdev_priv(dev);
1889 DEBUG(2,"ray_cs set_multicast_list(%p)\n",dev);
1891 if (dev->flags & IFF_PROMISC)
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;
1897 ray_update_parm(dev, OBJID_promiscuous_mode, \
1898 &promisc, sizeof(promisc));
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;
1906 ray_update_parm(dev, OBJID_promiscuous_mode, \
1907 &promisc, sizeof(promisc));
1911 if (dev->flags & IFF_ALLMULTI) ray_update_multi_list(dev, 1);
1914 if (local->num_multi != dev->mc_count) ray_update_multi_list(dev, 0);
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)
1922 struct net_device *dev = (struct net_device *)dev_id;
1923 struct pcmcia_device *link;
1925 struct ccs __iomem *pccs;
1926 struct rcs __iomem *prcs;
1932 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1935 DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev);
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");
1943 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
1945 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS))
1947 DEBUG(1,"ray_cs interrupt bad rcsindex = 0x%x\n",rcsindex);
1948 clear_interrupt(local);
1951 if (rcsindex < NUMBER_OF_CCS) /* If it's a returned CCS */
1953 pccs = ccs_base(local) + rcsindex;
1954 cmd = readb(&pccs->cmd);
1955 status = readb(&pccs->buffer_status);
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");
1964 DEBUG(1,"ray_cs interrupt download_startup_parameters fail\n");
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);
1974 case CCS_REPORT_PARAMS:
1975 DEBUG(1,"ray_cs interrupt report params done\n");
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");
1980 case CCS_UPDATE_POWER_SAVINGS_MODE:
1981 DEBUG(1,"ray_cs interrupt update power save mode done\n");
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);
1991 DEBUG(0,"ray_cs interrupt network \"%s\" joined\n",\
1992 local->sparm.b4.a_current_ess_id);
1994 memcpy_fromio(&local->bss_id,pccs->var.start_network.bssid,ADDRLEN);
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);
2004 local->card_status = CARD_ACQ_COMPLETE;
2007 local->card_status = CARD_ACQ_FAILED;
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;
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;
2022 add_timer(&local->timer);
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");
2032 DEBUG(0,"ray_cs association failed,\n");
2033 local->card_status = CARD_ASSOC_FAILED;
2034 join_net((u_long)local);
2037 case CCS_TX_REQUEST:
2038 if (status == CCS_COMMAND_COMPLETE) {
2039 DEBUG(3,"ray_cs interrupt tx request complete\n");
2042 DEBUG(1,"ray_cs interrupt tx request failed\n");
2044 if (!sniffer) netif_start_queue(dev);
2045 netif_wake_queue(dev);
2047 case CCS_TEST_MEMORY:
2048 DEBUG(1,"ray_cs interrupt mem test done\n");
2051 DEBUG(1,"ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2053 case CCS_DUMP_MEMORY:
2054 DEBUG(1,"ray_cs interrupt dump memory done\n");
2056 case CCS_START_TIMER:
2057 DEBUG(2,"ray_cs interrupt DING - raylink timer expired\n");
2060 DEBUG(1,"ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",\
2063 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2065 else /* It's an RCS */
2067 prcs = rcs_base(local) + rcsindex;
2069 switch (readb(&prcs->interrupt_id))
2071 case PROCESS_RX_PACKET:
2072 ray_rx(dev, local, prcs);
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);
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);
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;
2094 case JAPAN_CALL_SIGN_RXD:
2095 DEBUG(1,"ray_cs interrupt japan call sign rx\n");
2098 DEBUG(1,"ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",\
2099 rcsindex, (unsigned int) readb(&prcs->interrupt_id));
2102 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2104 clear_interrupt(local);
2106 } /* ray_interrupt */
2107 /*===========================================================================*/
2108 static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs)
2111 unsigned int pkt_addr;
2113 DEBUG(4,"ray_rx process rx packet\n");
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]);
2122 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2123 pmsg = local->rmem + pkt_addr;
2127 DEBUG(4,"ray_rx data type\n");
2128 rx_data(dev, prcs, pkt_addr, rx_len);
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);
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);
2141 DEBUG(3,"ray_cs rx NULL msg\n");
2144 DEBUG(4,"ray_rx beacon type\n");
2145 if (sniffer) rx_data(dev, prcs, pkt_addr, rx_len);
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));
2151 local->beacon_rxed = 1;
2152 /* Get the statistics so the card counters never overflow */
2156 DEBUG(0,"ray_cs unknown pkt type %2x\n", (unsigned int) readb(pmsg));
2161 /*===========================================================================*/
2162 static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, unsigned int pkt_addr,
2165 struct sk_buff *skb = NULL;
2166 struct rcs __iomem *prcslink = prcs;
2167 ray_dev_t *local = netdev_priv(dev);
2172 int siglev = local->last_rsl;
2173 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
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))
2182 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
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))
2190 DEBUG(0,"ray_cs invalid packet length %d received \n",rx_len);
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]);
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
2208 prcslink = rcs_base(local)
2209 + readb(&prcslink->link_field);
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);
2220 else { /* Single unfragmented packet */
2224 skb = dev_alloc_skb( total_len+5 );
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);
2233 skb_reserve( skb, 2); /* Align IP on 16 byte (TBD check this)*/
2235 DEBUG(4,"ray_cs rx_data total_len = %x, rx_len = %x\n",total_len,rx_len);
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 */
2244 skb_copy_from_linear_data_offset(skb, offsetof(struct mac_header, addr_2),
2245 linksrcaddr, ETH_ALEN);
2247 /* Now, deal with encapsulation/translation/sniffer */
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);
2255 /* Do translation */
2256 untranslate(local, skb, total_len);
2260 { /* sniffer mode, so just pass whole packet */ };
2262 /************************/
2263 /* Now pick up the rest of the fragments if any */
2265 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2267 DEBUG(1,"ray_cs rx_data in fragment loop\n");
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]))
2274 pkt_addr = (( readb(&prcslink->var.rx_packet.rx_data_ptr[0]) << 8)
2275 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2278 rx_ptr += copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
2281 readb(&prcslink->var.rx_packet.next_frag_rcs_index) != 0xFF);
2282 release_frag_chain(local, prcs);
2285 skb->protocol = eth_type_trans(skb,dev);
2287 dev->last_rx = jiffies;
2288 local->stats.rx_packets++;
2289 local->stats.rx_bytes += total_len;
2291 /* Gather signal strength per address */
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))
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;
2304 /* Now, update the spy stuff */
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);
2314 #endif /* WIRELESS_SPY */
2316 /*===========================================================================*/
2317 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
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;
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};
2329 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2330 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
2335 printk(KERN_DEBUG "skb->data before untranslate");
2337 printk("%02x ",skb->data[i]);
2338 printk("\n" KERN_DEBUG "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
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);
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);
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);
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)) {
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);
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;
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;
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);
2394 printk(KERN_DEBUG "skb->data after untranslate:");
2396 printk("%02x ",skb->data[i]);
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
2407 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int length)
2409 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2410 if (wrap_bytes <= 0)
2412 memcpy_fromio(dest,local->rmem + pkt_addr,length);
2414 else /* Packet wrapped in circular buffer */
2416 memcpy_fromio(dest,local->rmem+pkt_addr,length - wrap_bytes);
2417 memcpy_fromio(dest + length - wrap_bytes, local->rmem, wrap_bytes);
2421 /*===========================================================================*/
2422 static void release_frag_chain(ray_dev_t *local, struct rcs __iomem * prcs)
2424 struct rcs __iomem *prcslink = prcs;
2426 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
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);
2434 prcslink = rcs_base(local) + rcsindex;
2435 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2437 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2439 /*===========================================================================*/
2440 static void authenticate(ray_dev_t *local)
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");
2449 del_timer(&local->timer);
2450 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2451 local->timer.function = &join_net;
2454 local->timer.function = &authenticate_timeout;
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)
2466 struct rx_msg *msg = (struct rx_msg *)buff;
2468 del_timer(&local->timer);
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);
2482 else /* Infrastructure network */
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;
2491 local->authentication_state = AUTHENTICATED;
2494 DEBUG(0,"Authentication refused\n");
2495 local->card_status = CARD_AUTH_REFUSED;
2496 join_net((u_long)local);
2497 local->authentication_state = UNAUTHENTICATED;
2503 } /* end rx_authenticate */
2504 /*===========================================================================*/
2505 static void associate(ray_dev_t *local)
2507 struct ccs __iomem *pccs;
2508 struct pcmcia_device *link = local->finder;
2509 struct net_device *dev = link->priv;
2511 if (!(pcmcia_dev_present(link))) {
2512 DEBUG(2,"ray_cs associate - device not present\n");
2515 /* If no tx buffers available, return*/
2516 if ((ccsindex = get_free_ccs(local)) < 0)
2518 /* TBD should never be here but... what if we are? */
2519 DEBUG(1,"ray_cs associate - No free ccs\n");
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);
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;
2539 if (!sniffer) netif_start_queue(dev);
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)
2547 struct rx_msg *msg = (struct rx_msg *)buff;
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);
2555 /*===========================================================================*/
2556 static void clear_interrupt(ray_dev_t *local)
2558 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
2560 /*===========================================================================*/
2561 #ifdef CONFIG_PROC_FS
2562 #define MAXDATA (PAGE_SIZE - 80)
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 */
2576 "Acquisition failed", /* 14 */
2577 "Authentication refused", /* 15 */
2578 "Association failed" /* 16 */
2581 static char *nettype[] = {"Adhoc", "Infra "};
2582 static char *framing[] = {"Encapsulation", "Translation"}
2584 /*===========================================================================*/
2585 static int ray_cs_proc_show(struct seq_file *m, void *v)
2587 /* Print current values which are not available via other means
2591 struct pcmcia_device *link;
2592 struct net_device *dev;
2595 struct freq_hop_element *pfh;
2601 dev = (struct net_device *)link->priv;
2604 local = netdev_priv(dev);
2608 seq_puts(m, "Raylink Wireless LAN driver status\n");
2609 seq_printf(m, "%s\n", rcsid);
2610 /* build 4 does not report version, and field is 0x55 after memtest */
2611 seq_puts(m, "Firmware version = ");
2612 if (local->fw_ver == 0x55)
2613 seq_puts(m, "4 - Use dump_cis for more details\n");
2615 seq_printf(m, "%2d.%02d.%02d\n",
2616 local->fw_ver, local->fw_bld, local->fw_var);
2618 for (i=0; i<32; i++) c[i] = local->sparm.b5.a_current_ess_id[i];
2620 seq_printf(m, "%s network ESSID = \"%s\"\n",
2621 nettype[local->sparm.b5.a_network_type], c);
2624 seq_printf(m, "BSSID = %pM\n", p);
2626 seq_printf(m, "Country code = %d\n",
2627 local->sparm.b5.a_curr_country_code);
2629 i = local->card_status;
2632 seq_printf(m, "Card status = %s\n", card_status[i]);
2634 seq_printf(m, "Framing mode = %s\n",framing[translate]);
2636 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
2638 if (local->beacon_rxed) {
2639 /* Pull some fields out of last beacon received */
2640 seq_printf(m, "Beacon Interval = %d Kus\n",
2641 local->last_bcn.beacon_intvl[0]
2642 + 256 * local->last_bcn.beacon_intvl[1]);
2644 p = local->last_bcn.elements;
2645 if (p[0] == C_ESSID_ELEMENT_ID) p += p[1] + 2;
2647 seq_printf(m, "Parse beacon failed at essid element id = %d\n",p[0]);
2651 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2652 seq_puts(m, "Supported rate codes = ");
2653 for (i=2; i<p[1] + 2; i++)
2654 seq_printf(m, "0x%02x ", p[i]);
2659 seq_puts(m, "Parse beacon failed at rates element\n");
2663 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2664 pfh = (struct freq_hop_element *)p;
2665 seq_printf(m, "Hop dwell = %d Kus\n",
2666 pfh->dwell_time[0] + 256 * pfh->dwell_time[1]);
2667 seq_printf(m, "Hop set = %d \n", pfh->hop_set);
2668 seq_printf(m, "Hop pattern = %d \n", pfh->hop_pattern);
2669 seq_printf(m, "Hop index = %d \n", pfh->hop_index);
2673 seq_puts(m, "Parse beacon failed at FH param element\n");
2677 seq_puts(m, "No beacons received\n");
2682 static int ray_cs_proc_open(struct inode *inode, struct file *file)
2684 return single_open(file, ray_cs_proc_show, NULL);
2687 static const struct file_operations ray_cs_proc_fops = {
2688 .owner = THIS_MODULE,
2689 .open = ray_cs_proc_open,
2691 .llseek = seq_lseek,
2692 .release = single_release,
2695 /*===========================================================================*/
2696 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2699 struct ccs __iomem *pccs;
2700 struct tx_msg __iomem *ptx;
2703 /* If no tx buffers available, return */
2704 if ((ccsindex = get_free_tx_ccs(local)) < 0)
2706 DEBUG(1,"ray_cs send authenticate - No free tx ccs\n");
2710 pccs = ccs_base(local) + ccsindex;
2712 /* Address in card space */
2713 addr = TX_BUF_BASE + (ccsindex << 11);
2714 /* fill in the CCS */
2715 writeb(CCS_TX_REQUEST, &pccs->cmd);
2716 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2717 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2718 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2719 writeb(TX_AUTHENTICATE_LENGTH_LSB,pccs->var.tx_request.tx_data_length + 1);
2720 writeb(0, &pccs->var.tx_request.pow_sav_mode);
2722 ptx = local->sram + addr;
2723 /* fill in the mac header */
2724 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2725 writeb(0, &ptx->mac.frame_ctl_2);
2727 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2728 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2729 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
2731 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2732 memset_io(ptx->var, 0, 6);
2733 writeb(auth_type & 0xff, ptx->var + 2);
2735 /* Interrupt the firmware to process the command */
2736 if (interrupt_ecf(local, ccsindex)) {
2737 DEBUG(1,"ray_cs send authentication request failed - ECF not ready for intr\n");
2738 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2742 } /* End build_auth_frame */
2744 /*===========================================================================*/
2745 #ifdef CONFIG_PROC_FS
2746 static void raycs_write(const char *name, write_proc_t *w, void *data)
2748 struct proc_dir_entry * entry = create_proc_entry(name, S_IFREG | S_IWUSR, NULL);
2750 entry->write_proc = w;
2755 static int write_essid(struct file *file, const char __user *buffer, unsigned long count, void *data)
2757 static char proc_essid[33];
2762 memset(proc_essid, 0, 33);
2763 if (copy_from_user(proc_essid, buffer, len))
2769 static int write_int(struct file *file, const char __user *buffer, unsigned long count, void *data)
2771 static char proc_number[10];
2780 if (copy_from_user(proc_number, buffer, count))
2786 unsigned int c = *p - '0';
2797 static struct pcmcia_device_id ray_ids[] = {
2798 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2801 MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2803 static struct pcmcia_driver ray_driver = {
2804 .owner = THIS_MODULE,
2809 .remove = ray_detach,
2810 .id_table = ray_ids,
2811 .suspend = ray_suspend,
2812 .resume = ray_resume,
2815 static int __init init_ray_cs(void)
2819 DEBUG(1, "%s\n", rcsid);
2820 rc = pcmcia_register_driver(&ray_driver);
2821 DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n",rc);
2823 #ifdef CONFIG_PROC_FS
2824 proc_mkdir("driver/ray_cs", NULL);
2826 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
2827 raycs_write("driver/ray_cs/essid", write_essid, NULL);
2828 raycs_write("driver/ray_cs/net_type", write_int, &net_type);
2829 raycs_write("driver/ray_cs/translate", write_int, &translate);
2831 if (translate != 0) translate = 1;
2835 /*===========================================================================*/
2837 static void __exit exit_ray_cs(void)
2839 DEBUG(0, "ray_cs: cleanup_module\n");
2841 #ifdef CONFIG_PROC_FS
2842 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2843 remove_proc_entry("driver/ray_cs/essid", NULL);
2844 remove_proc_entry("driver/ray_cs/net_type", NULL);
2845 remove_proc_entry("driver/ray_cs/translate", NULL);
2846 remove_proc_entry("driver/ray_cs", NULL);
2849 pcmcia_unregister_driver(&ray_driver);
2852 module_init(init_ray_cs);
2853 module_exit(exit_ray_cs);
2855 /*===========================================================================*/