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/string.h>
39 #include <linux/timer.h>
40 #include <linux/init.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/if_arp.h>
44 #include <linux/ioport.h>
45 #include <linux/skbuff.h>
46 #include <linux/ethtool.h>
47 #include <linux/ieee80211.h>
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 <linux/wireless.h>
57 #include <net/iw_handler.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 */
74 /** Prototypes based on PCMCIA skeleton driver *******************************/
75 static int ray_config(struct pcmcia_device *link);
76 static void ray_release(struct pcmcia_device *link);
77 static void ray_detach(struct pcmcia_device *p_dev);
79 /***** Prototypes indicated by device structure ******************************/
80 static int ray_dev_close(struct net_device *dev);
81 static int ray_dev_config(struct net_device *dev, struct ifmap *map);
82 static struct net_device_stats *ray_get_stats(struct net_device *dev);
83 static int ray_dev_init(struct net_device *dev);
85 static const struct ethtool_ops netdev_ethtool_ops;
87 static int ray_open(struct net_device *dev);
88 static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
89 struct net_device *dev);
90 static void set_multicast_list(struct net_device *dev);
91 static void ray_update_multi_list(struct net_device *dev, int all);
92 static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
93 unsigned char *data, int len);
94 static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
95 UCHAR msg_type, unsigned char *data);
96 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
97 static iw_stats *ray_get_wireless_stats(struct net_device *dev);
98 static const struct iw_handler_def ray_handler_def;
100 /***** Prototypes for raylink functions **************************************/
101 static int asc_to_int(char a);
102 static void authenticate(ray_dev_t *local);
103 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
104 static void authenticate_timeout(u_long);
105 static int get_free_ccs(ray_dev_t *local);
106 static int get_free_tx_ccs(ray_dev_t *local);
107 static void init_startup_params(ray_dev_t *local);
108 static int parse_addr(char *in_str, UCHAR *out);
109 static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
110 static int ray_init(struct net_device *dev);
111 static int interrupt_ecf(ray_dev_t *local, int ccs);
112 static void ray_reset(struct net_device *dev);
113 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
114 static void verify_dl_startup(u_long);
116 /* Prototypes for interrpt time functions **********************************/
117 static irqreturn_t ray_interrupt(int reg, void *dev_id);
118 static void clear_interrupt(ray_dev_t *local);
119 static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
120 unsigned int pkt_addr, int rx_len);
121 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
122 static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
123 static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
124 static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
125 unsigned int pkt_addr, int rx_len);
126 static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
127 unsigned int pkt_addr, int rx_len);
128 static void associate(ray_dev_t *local);
130 /* Card command functions */
131 static int dl_startup_params(struct net_device *dev);
132 static void join_net(u_long local);
133 static void start_net(u_long local);
134 /* void start_net(ray_dev_t *local); */
136 /*===========================================================================*/
137 /* Parameters that can be set with 'insmod' */
139 /* ADHOC=0, Infrastructure=1 */
140 static int net_type = ADHOC;
142 /* Hop dwell time in Kus (1024 us units defined by 802.11) */
143 static int hop_dwell = 128;
145 /* Beacon period in Kus */
146 static int beacon_period = 256;
148 /* power save mode (0 = off, 1 = save power) */
151 /* String for network's Extended Service Set ID. 32 Characters max */
154 /* Default to encapsulation unless translation requested */
155 static int translate = 1;
157 static int country = USA;
163 /* 48 bit physical card address if overriding card's real physical
164 * address is required. Since IEEE 802.11 addresses are 48 bits
165 * like ethernet, an int can't be used, so a string is used. To
166 * allow use of addresses starting with a decimal digit, the first
167 * character must be a letter and will be ignored. This letter is
168 * followed by up to 12 hex digits which are the address. If less
169 * than 12 digits are used, the address will be left filled with 0's.
170 * Note that bit 0 of the first byte is the broadcast bit, and evil
171 * things will happen if it is not 0 in a card address.
173 static char *phy_addr = NULL;
176 /* A struct pcmcia_device structure has fields for most things that are needed
177 to keep track of a socket, but there will usually be some device
178 specific information that also needs to be kept track of. The
179 'priv' pointer in a struct pcmcia_device structure can be used to point to
180 a device-specific private data structure, like this.
182 static unsigned int ray_mem_speed = 500;
184 /* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
185 static struct pcmcia_device *this_device = NULL;
187 MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
188 MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
189 MODULE_LICENSE("GPL");
191 module_param(net_type, int, 0);
192 module_param(hop_dwell, int, 0);
193 module_param(beacon_period, int, 0);
194 module_param(psm, int, 0);
195 module_param(essid, charp, 0);
196 module_param(translate, int, 0);
197 module_param(country, int, 0);
198 module_param(sniffer, int, 0);
199 module_param(bc, int, 0);
200 module_param(phy_addr, charp, 0);
201 module_param(ray_mem_speed, int, 0);
203 static UCHAR b5_default_startup_parms[] = {
204 0, 0, /* Adhoc station */
205 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
206 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0,
209 1, 0, /* Active scan, CA Mode */
210 0, 0, 0, 0, 0, 0, /* No default MAC addr */
211 0x7f, 0xff, /* Frag threshold */
212 0x00, 0x80, /* Hop time 128 Kus */
213 0x01, 0x00, /* Beacon period 256 Kus */
214 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
215 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
216 0x7f, 0xff, /* RTS threshold */
217 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
218 0x05, /* assoc resp timeout thresh */
219 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
220 0, /* Promiscuous mode */
221 0x0c, 0x0bd, /* Unique word */
222 0x32, /* Slot time */
223 0xff, 0xff, /* roam-low snr, low snr count */
224 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
225 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
226 /* b4 - b5 differences start here */
227 0x00, 0x3f, /* CW max */
228 0x00, 0x0f, /* CW min */
229 0x04, 0x08, /* Noise gain, limit offset */
230 0x28, 0x28, /* det rssi, med busy offsets */
231 7, /* det sync thresh */
232 0, 2, 2, /* test mode, min, max */
233 0, /* allow broadcast SSID probe resp */
234 0, 0, /* privacy must start, can join */
235 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
238 static UCHAR b4_default_startup_parms[] = {
239 0, 0, /* Adhoc station */
240 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
241 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0,
244 1, 0, /* Active scan, CA Mode */
245 0, 0, 0, 0, 0, 0, /* No default MAC addr */
246 0x7f, 0xff, /* Frag threshold */
247 0x02, 0x00, /* Hop time */
248 0x00, 0x01, /* Beacon period */
249 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
250 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
251 0x7f, 0xff, /* RTS threshold */
252 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
253 0x05, /* assoc resp timeout thresh */
254 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
255 0, /* Promiscuous mode */
256 0x0c, 0x0bd, /* Unique word */
257 0x4e, /* Slot time (TBD seems wrong) */
258 0xff, 0xff, /* roam-low snr, low snr count */
259 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
260 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
261 /* b4 - b5 differences start here */
262 0x3f, 0x0f, /* CW max, min */
263 0x04, 0x08, /* Noise gain, limit offset */
264 0x28, 0x28, /* det rssi, med busy offsets */
265 7, /* det sync thresh */
266 0, 2, 2 /* test mode, min, max */
269 /*===========================================================================*/
270 static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
272 static char hop_pattern_length[] = { 1,
273 USA_HOP_MOD, EUROPE_HOP_MOD,
274 JAPAN_HOP_MOD, KOREA_HOP_MOD,
275 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
276 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
280 static char rcsid[] =
281 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
283 static const struct net_device_ops ray_netdev_ops = {
284 .ndo_init = ray_dev_init,
285 .ndo_open = ray_open,
286 .ndo_stop = ray_dev_close,
287 .ndo_start_xmit = ray_dev_start_xmit,
288 .ndo_set_config = ray_dev_config,
289 .ndo_get_stats = ray_get_stats,
290 .ndo_set_multicast_list = set_multicast_list,
291 .ndo_change_mtu = eth_change_mtu,
292 .ndo_set_mac_address = eth_mac_addr,
293 .ndo_validate_addr = eth_validate_addr,
296 /*=============================================================================
297 ray_attach() creates an "instance" of the driver, allocating
298 local data structures for one device. The device is registered
300 The dev_link structure is initialized, but we don't actually
301 configure the card at this point -- we wait until we receive a
302 card insertion event.
303 =============================================================================*/
304 static int ray_probe(struct pcmcia_device *p_dev)
307 struct net_device *dev;
309 dev_dbg(&p_dev->dev, "ray_attach()\n");
311 /* Allocate space for private device-specific data */
312 dev = alloc_etherdev(sizeof(ray_dev_t));
316 local = netdev_priv(dev);
317 local->finder = p_dev;
319 /* The io structure describes IO port mapping. None used here */
320 p_dev->io.NumPorts1 = 0;
321 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
322 p_dev->io.IOAddrLines = 5;
324 /* General socket configuration */
325 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
326 p_dev->conf.IntType = INT_MEMORY_AND_IO;
327 p_dev->conf.ConfigIndex = 1;
331 local->finder = p_dev;
332 local->card_status = CARD_INSERTED;
333 local->authentication_state = UNAUTHENTICATED;
334 local->num_multi = 0;
335 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
336 p_dev, dev, local, &ray_interrupt);
338 /* Raylink entries in the device structure */
339 dev->netdev_ops = &ray_netdev_ops;
340 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
341 dev->wireless_handlers = &ray_handler_def;
343 local->wireless_data.spy_data = &local->spy_data;
344 dev->wireless_data = &local->wireless_data;
345 #endif /* WIRELESS_SPY */
348 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
349 netif_stop_queue(dev);
351 init_timer(&local->timer);
354 return ray_config(p_dev);
360 /*=============================================================================
361 This deletes a driver "instance". The device is de-registered
362 with Card Services. If it has been released, all local data
363 structures are freed. Otherwise, the structures will be freed
364 when the device is released.
365 =============================================================================*/
366 static void ray_detach(struct pcmcia_device *link)
368 struct net_device *dev;
371 dev_dbg(&link->dev, "ray_detach\n");
378 local = netdev_priv(dev);
379 del_timer(&local->timer);
382 unregister_netdev(dev);
385 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
388 /*=============================================================================
389 ray_config() is run after a CARD_INSERTION event
390 is received, to configure the PCMCIA socket, and to make the
391 ethernet device available to the system.
392 =============================================================================*/
393 #define MAX_TUPLE_SIZE 128
394 static int ray_config(struct pcmcia_device *link)
400 struct net_device *dev = (struct net_device *)link->priv;
401 ray_dev_t *local = netdev_priv(dev);
403 dev_dbg(&link->dev, "ray_config\n");
405 /* Determine card type and firmware version */
406 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
407 link->prod_id[0] ? link->prod_id[0] : " ",
408 link->prod_id[1] ? link->prod_id[1] : " ",
409 link->prod_id[2] ? link->prod_id[2] : " ",
410 link->prod_id[3] ? link->prod_id[3] : " ");
412 /* Now allocate an interrupt line. Note that this does not
413 actually assign a handler to the interrupt.
415 ret = pcmcia_request_irq(link, ray_interrupt);
418 dev->irq = link->irq;
420 /* This actually configures the PCMCIA socket -- setting up
421 the I/O windows and the interrupt mapping.
423 ret = pcmcia_request_configuration(link, &link->conf);
427 /*** Set up 32k window for shared memory (transmit and control) ************/
429 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
432 req.AccessSpeed = ray_mem_speed;
433 ret = pcmcia_request_window(link, &req, &link->win);
436 mem.CardOffset = 0x0000;
438 ret = pcmcia_map_mem_page(link, link->win, &mem);
441 local->sram = ioremap(req.Base, req.Size);
443 /*** Set up 16k window for shared memory (receive buffer) ***************/
445 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
448 req.AccessSpeed = ray_mem_speed;
449 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
452 mem.CardOffset = 0x8000;
454 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
457 local->rmem = ioremap(req.Base, req.Size);
459 /*** Set up window for attribute memory ***********************************/
461 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
464 req.AccessSpeed = ray_mem_speed;
465 ret = pcmcia_request_window(link, &req, &local->amem_handle);
468 mem.CardOffset = 0x0000;
470 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
473 local->amem = ioremap(req.Base, req.Size);
475 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
476 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
477 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
478 if (ray_init(dev) < 0) {
483 SET_NETDEV_DEV(dev, &link->dev);
484 i = register_netdev(dev);
486 printk("ray_config register_netdev() failed\n");
491 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
492 dev->name, dev->irq, dev->dev_addr);
501 static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
503 return dev->sram + CCS_BASE;
506 static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
509 * This looks nonsensical, since there is a separate
510 * RCS_BASE. But the difference between a "struct rcs"
511 * and a "struct ccs" ends up being in the _index_ off
512 * the base, so the base pointer is the same for both
515 return dev->sram + CCS_BASE;
518 /*===========================================================================*/
519 static int ray_init(struct net_device *dev)
523 struct ccs __iomem *pccs;
524 ray_dev_t *local = netdev_priv(dev);
525 struct pcmcia_device *link = local->finder;
526 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
527 if (!(pcmcia_dev_present(link))) {
528 dev_dbg(&link->dev, "ray_init - device not present\n");
532 local->net_type = net_type;
533 local->sta_type = TYPE_STA;
535 /* Copy the startup results to local memory */
536 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
537 sizeof(struct startup_res_6));
539 /* Check Power up test status and get mac address from card */
540 if (local->startup_res.startup_word != 0x80) {
541 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
542 local->startup_res.startup_word);
543 local->card_status = CARD_INIT_ERROR;
547 local->fw_ver = local->startup_res.firmware_version[0];
548 local->fw_bld = local->startup_res.firmware_version[1];
549 local->fw_var = local->startup_res.firmware_version[2];
550 dev_dbg(&link->dev, "ray_init firmware version %d.%d \n", local->fw_ver,
553 local->tib_length = 0x20;
554 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
555 local->tib_length = local->startup_res.tib_length;
556 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
557 /* Initialize CCS's to buffer free state */
558 pccs = ccs_base(local);
559 for (i = 0; i < NUMBER_OF_CCS; i++) {
560 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
562 init_startup_params(local);
564 /* copy mac address to startup parameters */
565 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
566 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 dev_dbg(&link->dev, "ray_init ending\n");
579 /*===========================================================================*/
580 /* Download startup parameters to the card and command it to read them */
581 static int dl_startup_params(struct net_device *dev)
584 ray_dev_t *local = netdev_priv(dev);
585 struct ccs __iomem *pccs;
586 struct pcmcia_device *link = local->finder;
588 dev_dbg(&link->dev, "dl_startup_params entered\n");
589 if (!(pcmcia_dev_present(link))) {
590 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
594 /* Copy parameters to host to ECF area */
595 if (local->fw_ver == 0x55)
596 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
597 sizeof(struct b4_startup_params));
599 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
600 sizeof(struct b5_startup_params));
602 /* Fill in the CCS fields for the ECF */
603 if ((ccsindex = get_free_ccs(local)) < 0)
605 local->dl_param_ccs = ccsindex;
606 pccs = ccs_base(local) + ccsindex;
607 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
608 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
609 local->dl_param_ccs);
610 /* Interrupt the firmware to process the command */
611 if (interrupt_ecf(local, ccsindex)) {
612 printk(KERN_INFO "ray dl_startup_params failed - "
613 "ECF not ready for intr\n");
614 local->card_status = CARD_DL_PARAM_ERROR;
615 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
618 local->card_status = CARD_DL_PARAM;
619 /* Start kernel timer to wait for dl startup to complete. */
620 local->timer.expires = jiffies + HZ / 2;
621 local->timer.data = (long)local;
622 local->timer.function = &verify_dl_startup;
623 add_timer(&local->timer);
625 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
627 } /* dl_startup_params */
629 /*===========================================================================*/
630 static void init_startup_params(ray_dev_t *local)
634 if (country > JAPAN_TEST)
636 else if (country < USA)
638 /* structure for hop time and beacon period is defined here using
639 * New 802.11D6.1 format. Card firmware is still using old format
642 * a_hop_time ms byte a_hop_time ms byte
643 * a_hop_time 2s byte a_hop_time ls byte
644 * a_hop_time ls byte a_beacon_period ms byte
645 * a_beacon_period a_beacon_period ls byte
647 * a_hop_time = uS a_hop_time = KuS
648 * a_beacon_period = hops a_beacon_period = KuS
649 *//* 64ms = 010000 */
650 if (local->fw_ver == 0x55) {
651 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
652 sizeof(struct b4_startup_params));
653 /* Translate sane kus input values to old build 4/5 format */
654 /* i = hop time in uS truncated to 3 bytes */
655 i = (hop_dwell * 1024) & 0xffffff;
656 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
657 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
658 local->sparm.b4.a_beacon_period[0] = 0;
659 local->sparm.b4.a_beacon_period[1] =
660 ((beacon_period / hop_dwell) - 1) & 0xff;
661 local->sparm.b4.a_curr_country_code = country;
662 local->sparm.b4.a_hop_pattern_length =
663 hop_pattern_length[(int)country] - 1;
665 local->sparm.b4.a_ack_timeout = 0x50;
666 local->sparm.b4.a_sifs = 0x3f;
668 } else { /* Version 5 uses real kus values */
669 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
670 sizeof(struct b5_startup_params));
672 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
673 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
674 local->sparm.b5.a_beacon_period[0] =
675 (beacon_period >> 8) & 0xff;
676 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
678 local->sparm.b5.a_power_mgt_state = 1;
679 local->sparm.b5.a_curr_country_code = country;
680 local->sparm.b5.a_hop_pattern_length =
681 hop_pattern_length[(int)country];
684 local->sparm.b4.a_network_type = net_type & 0x01;
685 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
688 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
689 } /* init_startup_params */
691 /*===========================================================================*/
692 static void verify_dl_startup(u_long data)
694 ray_dev_t *local = (ray_dev_t *) data;
695 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
697 struct pcmcia_device *link = local->finder;
699 if (!(pcmcia_dev_present(link))) {
700 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
707 "verify_dl_startup parameters sent via ccs %d:\n",
708 local->dl_param_ccs);
709 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
711 (unsigned int)readb(local->sram +
712 HOST_TO_ECF_BASE + i));
718 status = readb(&pccs->buffer_status);
719 if (status != CCS_BUFFER_FREE) {
721 "Download startup params failed. Status = %d\n",
723 local->card_status = CARD_DL_PARAM_ERROR;
726 if (local->sparm.b4.a_network_type == ADHOC)
727 start_net((u_long) local);
729 join_net((u_long) local);
732 } /* end verify_dl_startup */
734 /*===========================================================================*/
735 /* Command card to start a network */
736 static void start_net(u_long data)
738 ray_dev_t *local = (ray_dev_t *) data;
739 struct ccs __iomem *pccs;
741 struct pcmcia_device *link = local->finder;
742 if (!(pcmcia_dev_present(link))) {
743 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
746 /* Fill in the CCS fields for the ECF */
747 if ((ccsindex = get_free_ccs(local)) < 0)
749 pccs = ccs_base(local) + ccsindex;
750 writeb(CCS_START_NETWORK, &pccs->cmd);
751 writeb(0, &pccs->var.start_network.update_param);
752 /* Interrupt the firmware to process the command */
753 if (interrupt_ecf(local, ccsindex)) {
754 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
755 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
758 local->card_status = CARD_DOING_ACQ;
760 } /* end start_net */
762 /*===========================================================================*/
763 /* Command card to join a network */
764 static void join_net(u_long data)
766 ray_dev_t *local = (ray_dev_t *) data;
768 struct ccs __iomem *pccs;
770 struct pcmcia_device *link = local->finder;
772 if (!(pcmcia_dev_present(link))) {
773 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
776 /* Fill in the CCS fields for the ECF */
777 if ((ccsindex = get_free_ccs(local)) < 0)
779 pccs = ccs_base(local) + ccsindex;
780 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
781 writeb(0, &pccs->var.join_network.update_param);
782 writeb(0, &pccs->var.join_network.net_initiated);
783 /* Interrupt the firmware to process the command */
784 if (interrupt_ecf(local, ccsindex)) {
785 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
786 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
789 local->card_status = CARD_DOING_ACQ;
793 /*============================================================================
794 After a card is removed, ray_release() will unregister the net
795 device, and release the PCMCIA configuration. If the device is
796 still open, this will be postponed until it is closed.
797 =============================================================================*/
798 static void ray_release(struct pcmcia_device *link)
800 struct net_device *dev = link->priv;
801 ray_dev_t *local = netdev_priv(dev);
804 dev_dbg(&link->dev, "ray_release\n");
806 del_timer(&local->timer);
808 iounmap(local->sram);
809 iounmap(local->rmem);
810 iounmap(local->amem);
811 /* Do bother checking to see if these succeed or not */
812 i = pcmcia_release_window(link, local->amem_handle);
814 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
815 i = pcmcia_release_window(link, local->rmem_handle);
817 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
818 pcmcia_disable_device(link);
820 dev_dbg(&link->dev, "ray_release ending\n");
823 static int ray_suspend(struct pcmcia_device *link)
825 struct net_device *dev = link->priv;
828 netif_device_detach(dev);
833 static int ray_resume(struct pcmcia_device *link)
835 struct net_device *dev = link->priv;
839 netif_device_attach(dev);
845 /*===========================================================================*/
846 static int ray_dev_init(struct net_device *dev)
848 #ifdef RAY_IMMEDIATE_INIT
850 #endif /* RAY_IMMEDIATE_INIT */
851 ray_dev_t *local = netdev_priv(dev);
852 struct pcmcia_device *link = local->finder;
854 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
855 if (!(pcmcia_dev_present(link))) {
856 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
859 #ifdef RAY_IMMEDIATE_INIT
860 /* Download startup parameters */
861 if ((i = dl_startup_params(dev)) < 0) {
862 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
863 "returns 0x%x\n", i);
866 #else /* RAY_IMMEDIATE_INIT */
867 /* Postpone the card init so that we can still configure the card,
868 * for example using the Wireless Extensions. The init will happen
869 * in ray_open() - Jean II */
871 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
873 #endif /* RAY_IMMEDIATE_INIT */
875 /* copy mac and broadcast addresses to linux device */
876 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
877 memset(dev->broadcast, 0xff, ETH_ALEN);
879 dev_dbg(&link->dev, "ray_dev_init ending\n");
883 /*===========================================================================*/
884 static int ray_dev_config(struct net_device *dev, struct ifmap *map)
886 ray_dev_t *local = netdev_priv(dev);
887 struct pcmcia_device *link = local->finder;
888 /* Dummy routine to satisfy device structure */
889 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
890 if (!(pcmcia_dev_present(link))) {
891 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
898 /*===========================================================================*/
899 static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
900 struct net_device *dev)
902 ray_dev_t *local = netdev_priv(dev);
903 struct pcmcia_device *link = local->finder;
904 short length = skb->len;
906 if (!pcmcia_dev_present(link)) {
907 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
912 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
913 if (local->authentication_state == NEED_TO_AUTH) {
914 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
915 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
916 local->authentication_state = AUTHENTICATED;
917 netif_stop_queue(dev);
918 return NETDEV_TX_BUSY;
922 if (length < ETH_ZLEN) {
923 if (skb_padto(skb, ETH_ZLEN))
927 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
930 netif_stop_queue(dev);
931 return NETDEV_TX_BUSY;
936 dev->trans_start = jiffies;
941 } /* ray_dev_start_xmit */
943 /*===========================================================================*/
944 static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
947 ray_dev_t *local = netdev_priv(dev);
948 struct ccs __iomem *pccs;
951 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
952 short int addr; /* Address of xmit buffer in card space */
954 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
955 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
956 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
960 switch (ccsindex = get_free_tx_ccs(local)) {
962 pr_debug("ray_hw_xmit tx_ccs table busy\n");
964 pr_debug("ray_hw_xmit No free tx ccs\n");
966 netif_stop_queue(dev);
971 addr = TX_BUF_BASE + (ccsindex << 11);
973 if (msg_type == DATA_TYPE) {
974 local->stats.tx_bytes += len;
975 local->stats.tx_packets++;
978 ptx = local->sram + addr;
980 ray_build_header(local, ptx, msg_type, data);
982 offset = translate_frame(local, ptx, data, len);
983 } else { /* Encapsulate frame */
984 /* TBD TIB length will move address of ptx->var */
985 memcpy_toio(&ptx->var, data, len);
989 /* fill in the CCS */
990 pccs = ccs_base(local) + ccsindex;
991 len += TX_HEADER_LENGTH + offset;
992 writeb(CCS_TX_REQUEST, &pccs->cmd);
993 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
994 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
995 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
996 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
997 /* TBD still need psm_cam? */
998 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
999 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1000 writeb(0, &pccs->var.tx_request.antenna);
1001 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
1002 local->net_default_tx_rate);
1004 /* Interrupt the firmware to process the command */
1005 if (interrupt_ecf(local, ccsindex)) {
1006 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
1007 /* TBD very inefficient to copy packet to buffer, and then not
1008 send it, but the alternative is to queue the messages and that
1009 won't be done for a while. Maybe set tbusy until a CCS is free?
1011 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1012 return XMIT_NO_INTR;
1015 } /* end ray_hw_xmit */
1017 /*===========================================================================*/
1018 static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1019 unsigned char *data, int len)
1021 __be16 proto = ((struct ethhdr *)data)->h_proto;
1022 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
1023 pr_debug("ray_cs translate_frame DIX II\n");
1024 /* Copy LLC header to card buffer */
1025 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1026 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1027 (UCHAR *) &proto, 2);
1028 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1029 /* This is the selective translation table, only 2 entries */
1031 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1033 /* Copy body of ethernet packet without ethernet header */
1034 memcpy_toio((void __iomem *)&ptx->var +
1035 sizeof(struct snaphdr_t), data + ETH_HLEN,
1037 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1038 } else { /* already 802 type, and proto is length */
1039 pr_debug("ray_cs translate_frame 802\n");
1040 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
1041 pr_debug("ray_cs translate_frame evil IPX\n");
1042 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1043 return 0 - ETH_HLEN;
1045 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1046 return 0 - ETH_HLEN;
1048 /* TBD do other frame types */
1049 } /* end translate_frame */
1051 /*===========================================================================*/
1052 static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1053 UCHAR msg_type, unsigned char *data)
1055 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1056 /*** IEEE 802.11 Address field assignments *************
1057 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1058 Adhoc 0 0 dest src (terminal) BSSID N/A
1059 AP to Terminal 0 1 dest AP(BSSID) source N/A
1060 Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1061 AP to AP 1 1 dest AP src AP dest source
1062 *******************************************************/
1063 if (local->net_type == ADHOC) {
1064 writeb(0, &ptx->mac.frame_ctl_2);
1065 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1067 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1068 } else { /* infrastructure */
1070 if (local->sparm.b4.a_acting_as_ap_status) {
1071 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1072 memcpy_toio(ptx->mac.addr_1,
1073 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1074 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1075 memcpy_toio(ptx->mac.addr_3,
1076 ((struct ethhdr *)data)->h_source, ADDRLEN);
1077 } else { /* Terminal */
1079 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1080 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1081 memcpy_toio(ptx->mac.addr_2,
1082 ((struct ethhdr *)data)->h_source, ADDRLEN);
1083 memcpy_toio(ptx->mac.addr_3,
1084 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1087 } /* end encapsulate_frame */
1089 /*===========================================================================*/
1091 static void netdev_get_drvinfo(struct net_device *dev,
1092 struct ethtool_drvinfo *info)
1094 strcpy(info->driver, "ray_cs");
1097 static const struct ethtool_ops netdev_ethtool_ops = {
1098 .get_drvinfo = netdev_get_drvinfo,
1101 /*====================================================================*/
1103 /*------------------------------------------------------------------*/
1105 * Wireless Handler : get protocol name
1107 static int ray_get_name(struct net_device *dev,
1108 struct iw_request_info *info, char *cwrq, char *extra)
1110 strcpy(cwrq, "IEEE 802.11-FH");
1114 /*------------------------------------------------------------------*/
1116 * Wireless Handler : set frequency
1118 static int ray_set_freq(struct net_device *dev,
1119 struct iw_request_info *info,
1120 struct iw_freq *fwrq, char *extra)
1122 ray_dev_t *local = netdev_priv(dev);
1123 int err = -EINPROGRESS; /* Call commit handler */
1125 /* Reject if card is already initialised */
1126 if (local->card_status != CARD_AWAITING_PARAM)
1129 /* Setting by channel number */
1130 if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0))
1133 local->sparm.b5.a_hop_pattern = fwrq->m;
1138 /*------------------------------------------------------------------*/
1140 * Wireless Handler : get frequency
1142 static int ray_get_freq(struct net_device *dev,
1143 struct iw_request_info *info,
1144 struct iw_freq *fwrq, char *extra)
1146 ray_dev_t *local = netdev_priv(dev);
1148 fwrq->m = local->sparm.b5.a_hop_pattern;
1153 /*------------------------------------------------------------------*/
1155 * Wireless Handler : set ESSID
1157 static int ray_set_essid(struct net_device *dev,
1158 struct iw_request_info *info,
1159 struct iw_point *dwrq, char *extra)
1161 ray_dev_t *local = netdev_priv(dev);
1163 /* Reject if card is already initialised */
1164 if (local->card_status != CARD_AWAITING_PARAM)
1167 /* Check if we asked for `any' */
1168 if (dwrq->flags == 0) {
1169 /* Corey : can you do that ? */
1172 /* Check the size of the string */
1173 if (dwrq->length > IW_ESSID_MAX_SIZE) {
1177 /* Set the ESSID in the card */
1178 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1179 memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length);
1182 return -EINPROGRESS; /* Call commit handler */
1185 /*------------------------------------------------------------------*/
1187 * Wireless Handler : get ESSID
1189 static int ray_get_essid(struct net_device *dev,
1190 struct iw_request_info *info,
1191 struct iw_point *dwrq, char *extra)
1193 ray_dev_t *local = netdev_priv(dev);
1195 /* Get the essid that was set */
1196 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
1199 dwrq->length = strlen(extra);
1200 dwrq->flags = 1; /* active */
1205 /*------------------------------------------------------------------*/
1207 * Wireless Handler : get AP address
1209 static int ray_get_wap(struct net_device *dev,
1210 struct iw_request_info *info,
1211 struct sockaddr *awrq, char *extra)
1213 ray_dev_t *local = netdev_priv(dev);
1215 memcpy(awrq->sa_data, local->bss_id, ETH_ALEN);
1216 awrq->sa_family = ARPHRD_ETHER;
1221 /*------------------------------------------------------------------*/
1223 * Wireless Handler : set Bit-Rate
1225 static int ray_set_rate(struct net_device *dev,
1226 struct iw_request_info *info,
1227 struct iw_param *vwrq, char *extra)
1229 ray_dev_t *local = netdev_priv(dev);
1231 /* Reject if card is already initialised */
1232 if (local->card_status != CARD_AWAITING_PARAM)
1235 /* Check if rate is in range */
1236 if ((vwrq->value != 1000000) && (vwrq->value != 2000000))
1239 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
1240 if ((local->fw_ver == 0x55) && /* Please check */
1241 (vwrq->value == 2000000))
1242 local->net_default_tx_rate = 3;
1244 local->net_default_tx_rate = vwrq->value / 500000;
1249 /*------------------------------------------------------------------*/
1251 * Wireless Handler : get Bit-Rate
1253 static int ray_get_rate(struct net_device *dev,
1254 struct iw_request_info *info,
1255 struct iw_param *vwrq, char *extra)
1257 ray_dev_t *local = netdev_priv(dev);
1259 if (local->net_default_tx_rate == 3)
1260 vwrq->value = 2000000; /* Hum... */
1262 vwrq->value = local->net_default_tx_rate * 500000;
1263 vwrq->fixed = 0; /* We are in auto mode */
1268 /*------------------------------------------------------------------*/
1270 * Wireless Handler : set RTS threshold
1272 static int ray_set_rts(struct net_device *dev,
1273 struct iw_request_info *info,
1274 struct iw_param *vwrq, char *extra)
1276 ray_dev_t *local = netdev_priv(dev);
1277 int rthr = vwrq->value;
1279 /* Reject if card is already initialised */
1280 if (local->card_status != CARD_AWAITING_PARAM)
1283 /* if(wrq->u.rts.fixed == 0) we should complain */
1287 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
1290 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1291 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
1293 return -EINPROGRESS; /* Call commit handler */
1296 /*------------------------------------------------------------------*/
1298 * Wireless Handler : get RTS threshold
1300 static int ray_get_rts(struct net_device *dev,
1301 struct iw_request_info *info,
1302 struct iw_param *vwrq, char *extra)
1304 ray_dev_t *local = netdev_priv(dev);
1306 vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8)
1307 + local->sparm.b5.a_rts_threshold[1];
1308 vwrq->disabled = (vwrq->value == 32767);
1314 /*------------------------------------------------------------------*/
1316 * Wireless Handler : set Fragmentation threshold
1318 static int ray_set_frag(struct net_device *dev,
1319 struct iw_request_info *info,
1320 struct iw_param *vwrq, char *extra)
1322 ray_dev_t *local = netdev_priv(dev);
1323 int fthr = vwrq->value;
1325 /* Reject if card is already initialised */
1326 if (local->card_status != CARD_AWAITING_PARAM)
1329 /* if(wrq->u.frag.fixed == 0) should complain */
1333 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
1336 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1337 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
1339 return -EINPROGRESS; /* Call commit handler */
1342 /*------------------------------------------------------------------*/
1344 * Wireless Handler : get Fragmentation threshold
1346 static int ray_get_frag(struct net_device *dev,
1347 struct iw_request_info *info,
1348 struct iw_param *vwrq, char *extra)
1350 ray_dev_t *local = netdev_priv(dev);
1352 vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8)
1353 + local->sparm.b5.a_frag_threshold[1];
1354 vwrq->disabled = (vwrq->value == 32767);
1360 /*------------------------------------------------------------------*/
1362 * Wireless Handler : set Mode of Operation
1364 static int ray_set_mode(struct net_device *dev,
1365 struct iw_request_info *info, __u32 *uwrq, char *extra)
1367 ray_dev_t *local = netdev_priv(dev);
1368 int err = -EINPROGRESS; /* Call commit handler */
1371 /* Reject if card is already initialised */
1372 if (local->card_status != CARD_AWAITING_PARAM)
1380 local->sparm.b5.a_network_type = card_mode;
1389 /*------------------------------------------------------------------*/
1391 * Wireless Handler : get Mode of Operation
1393 static int ray_get_mode(struct net_device *dev,
1394 struct iw_request_info *info, __u32 *uwrq, char *extra)
1396 ray_dev_t *local = netdev_priv(dev);
1398 if (local->sparm.b5.a_network_type)
1399 *uwrq = IW_MODE_INFRA;
1401 *uwrq = IW_MODE_ADHOC;
1406 /*------------------------------------------------------------------*/
1408 * Wireless Handler : get range info
1410 static int ray_get_range(struct net_device *dev,
1411 struct iw_request_info *info,
1412 struct iw_point *dwrq, char *extra)
1414 struct iw_range *range = (struct iw_range *)extra;
1416 memset((char *)range, 0, sizeof(struct iw_range));
1418 /* Set the length (very important for backward compatibility) */
1419 dwrq->length = sizeof(struct iw_range);
1421 /* Set the Wireless Extension versions */
1422 range->we_version_compiled = WIRELESS_EXT;
1423 range->we_version_source = 9;
1425 /* Set information in the range struct */
1426 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
1427 range->num_channels = hop_pattern_length[(int)country];
1428 range->num_frequency = 0;
1429 range->max_qual.qual = 0;
1430 range->max_qual.level = 255; /* What's the correct value ? */
1431 range->max_qual.noise = 255; /* Idem */
1432 range->num_bitrates = 2;
1433 range->bitrate[0] = 1000000; /* 1 Mb/s */
1434 range->bitrate[1] = 2000000; /* 2 Mb/s */
1438 /*------------------------------------------------------------------*/
1440 * Wireless Private Handler : set framing mode
1442 static int ray_set_framing(struct net_device *dev,
1443 struct iw_request_info *info,
1444 union iwreq_data *wrqu, char *extra)
1446 translate = *(extra); /* Set framing mode */
1451 /*------------------------------------------------------------------*/
1453 * Wireless Private Handler : get framing mode
1455 static int ray_get_framing(struct net_device *dev,
1456 struct iw_request_info *info,
1457 union iwreq_data *wrqu, char *extra)
1459 *(extra) = translate;
1464 /*------------------------------------------------------------------*/
1466 * Wireless Private Handler : get country
1468 static int ray_get_country(struct net_device *dev,
1469 struct iw_request_info *info,
1470 union iwreq_data *wrqu, char *extra)
1477 /*------------------------------------------------------------------*/
1479 * Commit handler : called after a bunch of SET operations
1481 static int ray_commit(struct net_device *dev, struct iw_request_info *info, /* NULL */
1482 void *zwrq, /* 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 local->wstats.status = local->card_status;
1500 if ((local->spy_data.spy_number > 0)
1501 && (local->sparm.b5.a_network_type == 0)) {
1502 /* Get it from the first node in spy list */
1503 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1504 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1505 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1506 local->wstats.qual.updated =
1507 local->spy_data.spy_stat[0].updated;
1509 #endif /* WIRELESS_SPY */
1511 if (pcmcia_dev_present(link)) {
1512 local->wstats.qual.noise = readb(&p->rxnoise);
1513 local->wstats.qual.updated |= 4;
1516 return &local->wstats;
1517 } /* end ray_get_wireless_stats */
1519 /*------------------------------------------------------------------*/
1521 * Structures to export the Wireless Handlers
1524 static const iw_handler ray_handler[] = {
1525 [SIOCSIWCOMMIT - SIOCIWFIRST] = (iw_handler) ray_commit,
1526 [SIOCGIWNAME - SIOCIWFIRST] = (iw_handler) ray_get_name,
1527 [SIOCSIWFREQ - SIOCIWFIRST] = (iw_handler) ray_set_freq,
1528 [SIOCGIWFREQ - SIOCIWFIRST] = (iw_handler) ray_get_freq,
1529 [SIOCSIWMODE - SIOCIWFIRST] = (iw_handler) ray_set_mode,
1530 [SIOCGIWMODE - SIOCIWFIRST] = (iw_handler) ray_get_mode,
1531 [SIOCGIWRANGE - SIOCIWFIRST] = (iw_handler) ray_get_range,
1533 [SIOCSIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
1534 [SIOCGIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
1535 [SIOCSIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
1536 [SIOCGIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
1537 #endif /* WIRELESS_SPY */
1538 [SIOCGIWAP - SIOCIWFIRST] = (iw_handler) ray_get_wap,
1539 [SIOCSIWESSID - SIOCIWFIRST] = (iw_handler) ray_set_essid,
1540 [SIOCGIWESSID - SIOCIWFIRST] = (iw_handler) ray_get_essid,
1541 [SIOCSIWRATE - SIOCIWFIRST] = (iw_handler) ray_set_rate,
1542 [SIOCGIWRATE - SIOCIWFIRST] = (iw_handler) ray_get_rate,
1543 [SIOCSIWRTS - SIOCIWFIRST] = (iw_handler) ray_set_rts,
1544 [SIOCGIWRTS - SIOCIWFIRST] = (iw_handler) ray_get_rts,
1545 [SIOCSIWFRAG - SIOCIWFIRST] = (iw_handler) ray_set_frag,
1546 [SIOCGIWFRAG - SIOCIWFIRST] = (iw_handler) ray_get_frag,
1549 #define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
1550 #define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1551 #define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1553 static const iw_handler ray_private_handler[] = {
1554 [0] = (iw_handler) ray_set_framing,
1555 [1] = (iw_handler) ray_get_framing,
1556 [3] = (iw_handler) ray_get_country,
1559 static const struct iw_priv_args ray_private_args[] = {
1560 /* cmd, set_args, get_args, name */
1561 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1563 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1565 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1569 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 dev_dbg(&link->dev, "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 dev_dbg(&link->dev, "ray_open: doing init now !\n");
1598 /* Download startup parameters */
1599 if ((i = dl_startup_params(dev)) < 0) {
1601 "ray_dev_init dl_startup_params failed - "
1602 "returns 0x%x\n", i);
1608 netif_stop_queue(dev);
1610 netif_start_queue(dev);
1612 dev_dbg(&link->dev, "ray_open ending\n");
1614 } /* end ray_open */
1616 /*===========================================================================*/
1617 static int ray_dev_close(struct net_device *dev)
1619 ray_dev_t *local = netdev_priv(dev);
1620 struct pcmcia_device *link;
1621 link = local->finder;
1623 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
1626 netif_stop_queue(dev);
1628 /* In here, we should stop the hardware (stop card from beeing active)
1629 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1630 * card is closed we can chage its configuration.
1631 * Probably also need a COR reset to get sane state - Jean II */
1634 } /* end ray_dev_close */
1636 /*===========================================================================*/
1637 static void ray_reset(struct net_device *dev)
1639 pr_debug("ray_reset entered\n");
1643 /*===========================================================================*/
1644 /* Cause a firmware interrupt if it is ready for one */
1645 /* Return nonzero if not ready */
1646 static int interrupt_ecf(ray_dev_t *local, int ccs)
1649 struct pcmcia_device *link = local->finder;
1651 if (!(pcmcia_dev_present(link))) {
1652 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
1655 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
1658 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1662 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
1665 /* Fill the mailbox, then kick the card */
1666 writeb(ccs, local->sram + SCB_BASE);
1667 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1669 } /* interrupt_ecf */
1671 /*===========================================================================*/
1672 /* Get next free transmit CCS */
1673 /* Return - index of current tx ccs */
1674 static int get_free_tx_ccs(ray_dev_t *local)
1677 struct ccs __iomem *pccs = ccs_base(local);
1678 struct pcmcia_device *link = local->finder;
1680 if (!(pcmcia_dev_present(link))) {
1681 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
1685 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
1686 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
1690 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1691 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1692 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1693 writeb(CCS_END_LIST, &(pccs + i)->link);
1694 local->tx_ccs_lock = 0;
1698 local->tx_ccs_lock = 0;
1699 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
1701 } /* get_free_tx_ccs */
1703 /*===========================================================================*/
1704 /* Get next free CCS */
1705 /* Return - index of current ccs */
1706 static int get_free_ccs(ray_dev_t *local)
1709 struct ccs __iomem *pccs = ccs_base(local);
1710 struct pcmcia_device *link = local->finder;
1712 if (!(pcmcia_dev_present(link))) {
1713 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
1716 if (test_and_set_bit(0, &local->ccs_lock)) {
1717 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
1721 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1722 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1723 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1724 writeb(CCS_END_LIST, &(pccs + i)->link);
1725 local->ccs_lock = 0;
1729 local->ccs_lock = 0;
1730 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
1732 } /* get_free_ccs */
1734 /*===========================================================================*/
1735 static void authenticate_timeout(u_long data)
1737 ray_dev_t *local = (ray_dev_t *) data;
1738 del_timer(&local->timer);
1739 printk(KERN_INFO "ray_cs Authentication with access point failed"
1741 join_net((u_long) local);
1744 /*===========================================================================*/
1745 static int asc_to_int(char a)
1754 return (10 + a - 'A');
1758 return (10 + a - 'a');
1762 /*===========================================================================*/
1763 static int parse_addr(char *in_str, UCHAR *out)
1771 if ((len = strlen(in_str)) < 2)
1773 memset(out, 0, ADDRLEN);
1782 if ((k = asc_to_int(in_str[j--])) != -1)
1789 if ((k = asc_to_int(in_str[j--])) != -1)
1799 /*===========================================================================*/
1800 static struct net_device_stats *ray_get_stats(struct net_device *dev)
1802 ray_dev_t *local = netdev_priv(dev);
1803 struct pcmcia_device *link = local->finder;
1804 struct status __iomem *p = local->sram + STATUS_BASE;
1805 if (!(pcmcia_dev_present(link))) {
1806 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
1807 return &local->stats;
1809 if (readb(&p->mrx_overflow_for_host)) {
1810 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1811 writeb(0, &p->mrx_overflow);
1812 writeb(0, &p->mrx_overflow_for_host);
1814 if (readb(&p->mrx_checksum_error_for_host)) {
1815 local->stats.rx_crc_errors +=
1816 swab16(readw(&p->mrx_checksum_error));
1817 writeb(0, &p->mrx_checksum_error);
1818 writeb(0, &p->mrx_checksum_error_for_host);
1820 if (readb(&p->rx_hec_error_for_host)) {
1821 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1822 writeb(0, &p->rx_hec_error);
1823 writeb(0, &p->rx_hec_error_for_host);
1825 return &local->stats;
1828 /*===========================================================================*/
1829 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1832 ray_dev_t *local = netdev_priv(dev);
1833 struct pcmcia_device *link = local->finder;
1836 struct ccs __iomem *pccs;
1838 if (!(pcmcia_dev_present(link))) {
1839 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
1843 if ((ccsindex = get_free_ccs(local)) < 0) {
1844 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
1847 pccs = ccs_base(local) + ccsindex;
1848 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1849 writeb(objid, &pccs->var.update_param.object_id);
1850 writeb(1, &pccs->var.update_param.number_objects);
1851 writeb(0, &pccs->var.update_param.failure_cause);
1852 for (i = 0; i < len; i++) {
1853 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1855 /* Interrupt the firmware to process the command */
1856 if (interrupt_ecf(local, ccsindex)) {
1857 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
1858 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1862 /*===========================================================================*/
1863 static void ray_update_multi_list(struct net_device *dev, int all)
1866 struct ccs __iomem *pccs;
1867 ray_dev_t *local = netdev_priv(dev);
1868 struct pcmcia_device *link = local->finder;
1869 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
1871 if (!(pcmcia_dev_present(link))) {
1872 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
1875 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
1876 if ((ccsindex = get_free_ccs(local)) < 0) {
1877 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
1880 pccs = ccs_base(local) + ccsindex;
1881 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
1884 writeb(0xff, &pccs->var);
1885 local->num_multi = 0xff;
1887 struct dev_mc_list *dmi;
1890 /* Copy the kernel's list of MC addresses to card */
1891 netdev_for_each_mc_addr(dmi, dev) {
1892 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
1894 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
1895 dmi->dmi_addr[0], dmi->dmi_addr[1],
1896 dmi->dmi_addr[2], dmi->dmi_addr[3],
1897 dmi->dmi_addr[4], dmi->dmi_addr[5]);
1901 if (i > 256 / ADDRLEN)
1903 writeb((UCHAR) i, &pccs->var);
1904 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
1905 /* Interrupt the firmware to process the command */
1906 local->num_multi = i;
1908 if (interrupt_ecf(local, ccsindex)) {
1910 "ray_cs update_multi failed - ECF not ready for intr\n");
1911 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1913 } /* end ray_update_multi_list */
1915 /*===========================================================================*/
1916 static void set_multicast_list(struct net_device *dev)
1918 ray_dev_t *local = netdev_priv(dev);
1921 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
1923 if (dev->flags & IFF_PROMISC) {
1924 if (local->sparm.b5.a_promiscuous_mode == 0) {
1925 pr_debug("ray_cs set_multicast_list promisc on\n");
1926 local->sparm.b5.a_promiscuous_mode = 1;
1928 ray_update_parm(dev, OBJID_promiscuous_mode,
1929 &promisc, sizeof(promisc));
1932 if (local->sparm.b5.a_promiscuous_mode == 1) {
1933 pr_debug("ray_cs set_multicast_list promisc off\n");
1934 local->sparm.b5.a_promiscuous_mode = 0;
1936 ray_update_parm(dev, OBJID_promiscuous_mode,
1937 &promisc, sizeof(promisc));
1941 if (dev->flags & IFF_ALLMULTI)
1942 ray_update_multi_list(dev, 1);
1944 if (local->num_multi != netdev_mc_count(dev))
1945 ray_update_multi_list(dev, 0);
1947 } /* end set_multicast_list */
1949 /*=============================================================================
1950 * All routines below here are run at interrupt time.
1951 =============================================================================*/
1952 static irqreturn_t ray_interrupt(int irq, void *dev_id)
1954 struct net_device *dev = (struct net_device *)dev_id;
1955 struct pcmcia_device *link;
1957 struct ccs __iomem *pccs;
1958 struct rcs __iomem *prcs;
1964 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1967 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
1969 local = netdev_priv(dev);
1970 link = (struct pcmcia_device *)local->finder;
1971 if (!pcmcia_dev_present(link)) {
1973 "ray_cs interrupt from device not present or suspended.\n");
1976 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
1978 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
1979 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
1980 clear_interrupt(local);
1983 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1984 pccs = ccs_base(local) + rcsindex;
1985 cmd = readb(&pccs->cmd);
1986 status = readb(&pccs->buffer_status);
1988 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1989 del_timer(&local->timer);
1990 if (status == CCS_COMMAND_COMPLETE) {
1992 "ray_cs interrupt download_startup_parameters OK\n");
1995 "ray_cs interrupt download_startup_parameters fail\n");
1998 case CCS_UPDATE_PARAMS:
1999 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
2000 if (status != CCS_COMMAND_COMPLETE) {
2002 readb(&pccs->var.update_param.
2005 "ray_cs interrupt update params failed - reason %d\n",
2009 case CCS_REPORT_PARAMS:
2010 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
2012 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
2014 "ray_cs interrupt CCS Update Multicast List done\n");
2016 case CCS_UPDATE_POWER_SAVINGS_MODE:
2018 "ray_cs interrupt update power save mode done\n");
2020 case CCS_START_NETWORK:
2021 case CCS_JOIN_NETWORK:
2022 if (status == CCS_COMMAND_COMPLETE) {
2024 (&pccs->var.start_network.net_initiated) ==
2027 "ray_cs interrupt network \"%s\" started\n",
2028 local->sparm.b4.a_current_ess_id);
2031 "ray_cs interrupt network \"%s\" joined\n",
2032 local->sparm.b4.a_current_ess_id);
2034 memcpy_fromio(&local->bss_id,
2035 pccs->var.start_network.bssid,
2038 if (local->fw_ver == 0x55)
2039 local->net_default_tx_rate = 3;
2041 local->net_default_tx_rate =
2042 readb(&pccs->var.start_network.
2043 net_default_tx_rate);
2045 readb(&pccs->var.start_network.encryption);
2046 if (!sniffer && (local->net_type == INFRA)
2047 && !(local->sparm.b4.a_acting_as_ap_status)) {
2048 authenticate(local);
2050 local->card_status = CARD_ACQ_COMPLETE;
2052 local->card_status = CARD_ACQ_FAILED;
2054 del_timer(&local->timer);
2055 local->timer.expires = jiffies + HZ * 5;
2056 local->timer.data = (long)local;
2057 if (status == CCS_START_NETWORK) {
2059 "ray_cs interrupt network \"%s\" start failed\n",
2060 local->sparm.b4.a_current_ess_id);
2061 local->timer.function = &start_net;
2064 "ray_cs interrupt network \"%s\" join failed\n",
2065 local->sparm.b4.a_current_ess_id);
2066 local->timer.function = &join_net;
2068 add_timer(&local->timer);
2071 case CCS_START_ASSOCIATION:
2072 if (status == CCS_COMMAND_COMPLETE) {
2073 local->card_status = CARD_ASSOC_COMPLETE;
2074 dev_dbg(&link->dev, "ray_cs association successful\n");
2076 dev_dbg(&link->dev, "ray_cs association failed,\n");
2077 local->card_status = CARD_ASSOC_FAILED;
2078 join_net((u_long) local);
2081 case CCS_TX_REQUEST:
2082 if (status == CCS_COMMAND_COMPLETE) {
2084 "ray_cs interrupt tx request complete\n");
2087 "ray_cs interrupt tx request failed\n");
2090 netif_start_queue(dev);
2091 netif_wake_queue(dev);
2093 case CCS_TEST_MEMORY:
2094 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
2098 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2100 case CCS_DUMP_MEMORY:
2101 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
2103 case CCS_START_TIMER:
2105 "ray_cs interrupt DING - raylink timer expired\n");
2109 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2112 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2113 } else { /* It's an RCS */
2115 prcs = rcs_base(local) + rcsindex;
2117 switch (readb(&prcs->interrupt_id)) {
2118 case PROCESS_RX_PACKET:
2119 ray_rx(dev, local, prcs);
2121 case REJOIN_NET_COMPLETE:
2122 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
2123 local->card_status = CARD_ACQ_COMPLETE;
2124 /* do we need to clear tx buffers CCS's? */
2125 if (local->sparm.b4.a_network_type == ADHOC) {
2127 netif_start_queue(dev);
2129 memcpy_fromio(&local->bss_id,
2130 prcs->var.rejoin_net_complete.
2133 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2134 local->bss_id[0], local->bss_id[1],
2135 local->bss_id[2], local->bss_id[3],
2136 local->bss_id[4], local->bss_id[5]);
2138 authenticate(local);
2141 case ROAMING_INITIATED:
2142 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
2143 netif_stop_queue(dev);
2144 local->card_status = CARD_DOING_ACQ;
2146 case JAPAN_CALL_SIGN_RXD:
2147 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
2151 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2153 (unsigned int)readb(&prcs->interrupt_id));
2156 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2158 clear_interrupt(local);
2160 } /* ray_interrupt */
2162 /*===========================================================================*/
2163 static void ray_rx(struct net_device *dev, ray_dev_t *local,
2164 struct rcs __iomem *prcs)
2167 unsigned int pkt_addr;
2169 pr_debug("ray_rx process rx packet\n");
2171 /* Calculate address of packet within Rx buffer */
2172 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2173 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2174 /* Length of first packet fragment */
2175 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2176 + readb(&prcs->var.rx_packet.rx_data_length[1]);
2178 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2179 pmsg = local->rmem + pkt_addr;
2180 switch (readb(pmsg)) {
2182 pr_debug("ray_rx data type\n");
2183 rx_data(dev, prcs, pkt_addr, rx_len);
2185 case AUTHENTIC_TYPE:
2186 pr_debug("ray_rx authentic type\n");
2188 rx_data(dev, prcs, pkt_addr, rx_len);
2190 rx_authenticate(local, prcs, pkt_addr, rx_len);
2192 case DEAUTHENTIC_TYPE:
2193 pr_debug("ray_rx deauth type\n");
2195 rx_data(dev, prcs, pkt_addr, rx_len);
2197 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2200 pr_debug("ray_cs rx NULL msg\n");
2203 pr_debug("ray_rx beacon type\n");
2205 rx_data(dev, prcs, pkt_addr, rx_len);
2207 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2208 rx_len < sizeof(struct beacon_rx) ?
2209 rx_len : sizeof(struct beacon_rx));
2211 local->beacon_rxed = 1;
2212 /* Get the statistics so the card counters never overflow */
2216 pr_debug("ray_cs unknown pkt type %2x\n",
2217 (unsigned int)readb(pmsg));
2223 /*===========================================================================*/
2224 static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2225 unsigned int pkt_addr, int rx_len)
2227 struct sk_buff *skb = NULL;
2228 struct rcs __iomem *prcslink = prcs;
2229 ray_dev_t *local = netdev_priv(dev);
2234 int siglev = local->last_rsl;
2235 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
2240 /* TBD length needs fixing for translated header */
2241 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2243 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2246 "ray_cs invalid packet length %d received \n",
2250 } else { /* encapsulated ethernet */
2252 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2254 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2257 "ray_cs invalid packet length %d received \n",
2263 pr_debug("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 pr_debug("ray_cs rx'ed fragment\n");
2267 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2268 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2273 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2275 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2276 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2279 prcslink = rcs_base(local)
2280 + readb(&prcslink->link_field);
2285 "ray_cs rx_data fragment lengths don't add up\n");
2286 local->stats.rx_dropped++;
2287 release_frag_chain(local, prcs);
2290 } else { /* Single unfragmented packet */
2294 skb = dev_alloc_skb(total_len + 5);
2296 pr_debug("ray_cs rx_data could not allocate skb\n");
2297 local->stats.rx_dropped++;
2298 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2299 release_frag_chain(local, prcs);
2302 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2304 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
2307 /************************/
2308 /* Reserve enough room for the whole damn packet. */
2309 rx_ptr = skb_put(skb, total_len);
2310 /* Copy the whole packet to sk_buff */
2312 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2313 /* Get source address */
2315 skb_copy_from_linear_data_offset(skb,
2316 offsetof(struct mac_header, addr_2),
2317 linksrcaddr, ETH_ALEN);
2319 /* Now, deal with encapsulation/translation/sniffer */
2322 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
2323 /* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
2324 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2326 /* Do translation */
2327 untranslate(local, skb, total_len);
2329 } else { /* sniffer mode, so just pass whole packet */
2332 /************************/
2333 /* Now pick up the rest of the fragments if any */
2335 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2337 pr_debug("ray_cs rx_data in fragment loop\n");
2339 prcslink = rcs_base(local)
2341 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2343 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2346 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2349 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2351 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2355 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
2358 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2360 release_frag_chain(local, prcs);
2363 skb->protocol = eth_type_trans(skb, dev);
2365 local->stats.rx_packets++;
2366 local->stats.rx_bytes += total_len;
2368 /* Gather signal strength per address */
2370 /* For the Access Point or the node having started the ad-hoc net
2371 * note : ad-hoc work only in some specific configurations, but we
2372 * kludge in ray_get_wireless_stats... */
2373 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2374 /* Update statistics */
2375 /*local->wstats.qual.qual = none ? */
2376 local->wstats.qual.level = siglev;
2377 /*local->wstats.qual.noise = none ? */
2378 local->wstats.qual.updated = 0x2;
2380 /* Now, update the spy stuff */
2382 struct iw_quality wstats;
2383 wstats.level = siglev;
2384 /* wstats.noise = none ? */
2385 /* wstats.qual = none ? */
2386 wstats.updated = 0x2;
2387 /* Update spy records */
2388 wireless_spy_update(dev, linksrcaddr, &wstats);
2390 #endif /* WIRELESS_SPY */
2393 /*===========================================================================*/
2394 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2396 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2397 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2398 __be16 type = *(__be16 *) psnap->ethertype;
2400 struct ethhdr *peth;
2401 UCHAR srcaddr[ADDRLEN];
2402 UCHAR destaddr[ADDRLEN];
2403 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2404 static UCHAR org_1042[3] = { 0, 0, 0 };
2406 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2407 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
2411 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2412 DUMP_PREFIX_NONE, 16, 1,
2413 skb->data, 64, true);
2415 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2416 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2417 psnap->org[0], psnap->org[1], psnap->org[2]);
2418 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2422 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2423 /* not a snap type so leave it alone */
2424 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
2425 psnap->dsap, psnap->ssap, psnap->ctrl);
2427 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2428 peth = (struct ethhdr *)(skb->data + delta);
2429 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2430 } else { /* Its a SNAP */
2431 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2432 /* EtherII and nuke the LLC */
2433 pr_debug("ray_cs untranslate Bridge encap\n");
2434 delta = RX_MAC_HEADER_LENGTH
2435 + sizeof(struct snaphdr_t) - ETH_HLEN;
2436 peth = (struct ethhdr *)(skb->data + delta);
2437 peth->h_proto = type;
2438 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2439 switch (ntohs(type)) {
2442 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
2443 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2444 peth = (struct ethhdr *)(skb->data + delta);
2446 htons(len - RX_MAC_HEADER_LENGTH);
2449 pr_debug("ray_cs untranslate RFC default\n");
2450 delta = RX_MAC_HEADER_LENGTH +
2451 sizeof(struct snaphdr_t) - ETH_HLEN;
2452 peth = (struct ethhdr *)(skb->data + delta);
2453 peth->h_proto = type;
2457 printk("ray_cs untranslate very confused by packet\n");
2458 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2459 peth = (struct ethhdr *)(skb->data + delta);
2460 peth->h_proto = type;
2463 /* TBD reserve skb_reserve(skb, delta); */
2464 skb_pull(skb, delta);
2465 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
2467 memcpy(peth->h_dest, destaddr, ADDRLEN);
2468 memcpy(peth->h_source, srcaddr, ADDRLEN);
2472 printk(KERN_DEBUG "skb->data after untranslate:");
2473 for (i = 0; i < 64; i++)
2474 printk("%02x ", skb->data[i]);
2478 } /* end untranslate */
2480 /*===========================================================================*/
2481 /* Copy data from circular receive buffer to PC memory.
2482 * dest = destination address in PC memory
2483 * pkt_addr = source address in receive buffer
2484 * len = length of packet to copy
2486 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2489 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2490 if (wrap_bytes <= 0) {
2491 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2492 } else { /* Packet wrapped in circular buffer */
2494 memcpy_fromio(dest, local->rmem + pkt_addr,
2495 length - wrap_bytes);
2496 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2502 /*===========================================================================*/
2503 static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2505 struct rcs __iomem *prcslink = prcs;
2507 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2510 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2511 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
2512 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
2516 prcslink = rcs_base(local) + rcsindex;
2517 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2519 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2522 /*===========================================================================*/
2523 static void authenticate(ray_dev_t *local)
2525 struct pcmcia_device *link = local->finder;
2526 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
2527 if (!(pcmcia_dev_present(link))) {
2528 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
2532 del_timer(&local->timer);
2533 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2534 local->timer.function = &join_net;
2536 local->timer.function = &authenticate_timeout;
2538 local->timer.expires = jiffies + HZ * 2;
2539 local->timer.data = (long)local;
2540 add_timer(&local->timer);
2541 local->authentication_state = AWAITING_RESPONSE;
2542 } /* end authenticate */
2544 /*===========================================================================*/
2545 static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2546 unsigned int pkt_addr, int rx_len)
2549 struct rx_msg *msg = (struct rx_msg *)buff;
2551 del_timer(&local->timer);
2553 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2554 /* if we are trying to get authenticated */
2555 if (local->sparm.b4.a_network_type == ADHOC) {
2556 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
2557 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2558 msg->var[4], msg->var[5]);
2559 if (msg->var[2] == 1) {
2560 pr_debug("ray_cs Sending authentication response.\n");
2561 if (!build_auth_frame
2562 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2563 local->authentication_state = NEED_TO_AUTH;
2564 memcpy(local->auth_id, msg->mac.addr_2,
2568 } else { /* Infrastructure network */
2570 if (local->authentication_state == AWAITING_RESPONSE) {
2571 /* Verify authentication sequence #2 and success */
2572 if (msg->var[2] == 2) {
2573 if ((msg->var[3] | msg->var[4]) == 0) {
2574 pr_debug("Authentication successful\n");
2575 local->card_status = CARD_AUTH_COMPLETE;
2577 local->authentication_state =
2580 pr_debug("Authentication refused\n");
2581 local->card_status = CARD_AUTH_REFUSED;
2582 join_net((u_long) local);
2583 local->authentication_state =
2590 } /* end rx_authenticate */
2592 /*===========================================================================*/
2593 static void associate(ray_dev_t *local)
2595 struct ccs __iomem *pccs;
2596 struct pcmcia_device *link = local->finder;
2597 struct net_device *dev = link->priv;
2599 if (!(pcmcia_dev_present(link))) {
2600 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
2603 /* If no tx buffers available, return */
2604 if ((ccsindex = get_free_ccs(local)) < 0) {
2605 /* TBD should never be here but... what if we are? */
2606 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
2609 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
2610 pccs = ccs_base(local) + ccsindex;
2611 /* fill in the CCS */
2612 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2613 /* Interrupt the firmware to process the command */
2614 if (interrupt_ecf(local, ccsindex)) {
2615 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
2616 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2618 del_timer(&local->timer);
2619 local->timer.expires = jiffies + HZ * 2;
2620 local->timer.data = (long)local;
2621 local->timer.function = &join_net;
2622 add_timer(&local->timer);
2623 local->card_status = CARD_ASSOC_FAILED;
2627 netif_start_queue(dev);
2629 } /* end associate */
2631 /*===========================================================================*/
2632 static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2633 unsigned int pkt_addr, int rx_len)
2636 struct rx_msg *msg = (struct rx_msg *)buff;
2638 pr_debug("Deauthentication frame received\n");
2639 local->authentication_state = UNAUTHENTICATED;
2640 /* Need to reauthenticate or rejoin depending on reason code */
2641 /* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2645 /*===========================================================================*/
2646 static void clear_interrupt(ray_dev_t *local)
2648 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
2651 /*===========================================================================*/
2652 #ifdef CONFIG_PROC_FS
2653 #define MAXDATA (PAGE_SIZE - 80)
2655 static char *card_status[] = {
2656 "Card inserted - uninitialized", /* 0 */
2657 "Card not downloaded", /* 1 */
2658 "Waiting for download parameters", /* 2 */
2659 "Card doing acquisition", /* 3 */
2660 "Acquisition complete", /* 4 */
2661 "Authentication complete", /* 5 */
2662 "Association complete", /* 6 */
2663 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2664 "Card init error", /* 11 */
2665 "Download parameters error", /* 12 */
2667 "Acquisition failed", /* 14 */
2668 "Authentication refused", /* 15 */
2669 "Association failed" /* 16 */
2672 static char *nettype[] = { "Adhoc", "Infra " };
2673 static char *framing[] = { "Encapsulation", "Translation" }
2676 /*===========================================================================*/
2677 static int ray_cs_proc_show(struct seq_file *m, void *v)
2679 /* Print current values which are not available via other means
2683 struct pcmcia_device *link;
2684 struct net_device *dev;
2687 struct freq_hop_element *pfh;
2693 dev = (struct net_device *)link->priv;
2696 local = netdev_priv(dev);
2700 seq_puts(m, "Raylink Wireless LAN driver status\n");
2701 seq_printf(m, "%s\n", rcsid);
2702 /* build 4 does not report version, and field is 0x55 after memtest */
2703 seq_puts(m, "Firmware version = ");
2704 if (local->fw_ver == 0x55)
2705 seq_puts(m, "4 - Use dump_cis for more details\n");
2707 seq_printf(m, "%2d.%02d.%02d\n",
2708 local->fw_ver, local->fw_bld, local->fw_var);
2710 for (i = 0; i < 32; i++)
2711 c[i] = local->sparm.b5.a_current_ess_id[i];
2713 seq_printf(m, "%s network ESSID = \"%s\"\n",
2714 nettype[local->sparm.b5.a_network_type], c);
2717 seq_printf(m, "BSSID = %pM\n", p);
2719 seq_printf(m, "Country code = %d\n",
2720 local->sparm.b5.a_curr_country_code);
2722 i = local->card_status;
2727 seq_printf(m, "Card status = %s\n", card_status[i]);
2729 seq_printf(m, "Framing mode = %s\n", framing[translate]);
2731 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
2733 if (local->beacon_rxed) {
2734 /* Pull some fields out of last beacon received */
2735 seq_printf(m, "Beacon Interval = %d Kus\n",
2736 local->last_bcn.beacon_intvl[0]
2737 + 256 * local->last_bcn.beacon_intvl[1]);
2739 p = local->last_bcn.elements;
2740 if (p[0] == C_ESSID_ELEMENT_ID)
2744 "Parse beacon failed at essid element id = %d\n",
2749 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2750 seq_puts(m, "Supported rate codes = ");
2751 for (i = 2; i < p[1] + 2; i++)
2752 seq_printf(m, "0x%02x ", p[i]);
2756 seq_puts(m, "Parse beacon failed at rates element\n");
2760 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2761 pfh = (struct freq_hop_element *)p;
2762 seq_printf(m, "Hop dwell = %d Kus\n",
2763 pfh->dwell_time[0] +
2764 256 * pfh->dwell_time[1]);
2765 seq_printf(m, "Hop set = %d \n",
2767 seq_printf(m, "Hop pattern = %d \n",
2769 seq_printf(m, "Hop index = %d \n",
2774 "Parse beacon failed at FH param element\n");
2778 seq_puts(m, "No beacons received\n");
2783 static int ray_cs_proc_open(struct inode *inode, struct file *file)
2785 return single_open(file, ray_cs_proc_show, NULL);
2788 static const struct file_operations ray_cs_proc_fops = {
2789 .owner = THIS_MODULE,
2790 .open = ray_cs_proc_open,
2792 .llseek = seq_lseek,
2793 .release = single_release,
2796 /*===========================================================================*/
2797 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2800 struct ccs __iomem *pccs;
2801 struct tx_msg __iomem *ptx;
2804 /* If no tx buffers available, return */
2805 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
2806 pr_debug("ray_cs send authenticate - No free tx ccs\n");
2810 pccs = ccs_base(local) + ccsindex;
2812 /* Address in card space */
2813 addr = TX_BUF_BASE + (ccsindex << 11);
2814 /* fill in the CCS */
2815 writeb(CCS_TX_REQUEST, &pccs->cmd);
2816 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2817 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2818 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2819 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2820 pccs->var.tx_request.tx_data_length + 1);
2821 writeb(0, &pccs->var.tx_request.pow_sav_mode);
2823 ptx = local->sram + addr;
2824 /* fill in the mac header */
2825 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2826 writeb(0, &ptx->mac.frame_ctl_2);
2828 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2829 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2830 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
2832 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2833 memset_io(ptx->var, 0, 6);
2834 writeb(auth_type & 0xff, ptx->var + 2);
2836 /* Interrupt the firmware to process the command */
2837 if (interrupt_ecf(local, ccsindex)) {
2839 "ray_cs send authentication request failed - ECF not ready for intr\n");
2840 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2844 } /* End build_auth_frame */
2846 /*===========================================================================*/
2847 #ifdef CONFIG_PROC_FS
2848 static ssize_t ray_cs_essid_proc_write(struct file *file,
2849 const char __user *buffer, size_t count, loff_t *pos)
2851 static char proc_essid[33];
2852 unsigned int len = count;
2856 memset(proc_essid, 0, 33);
2857 if (copy_from_user(proc_essid, buffer, len))
2863 static const struct file_operations ray_cs_essid_proc_fops = {
2864 .owner = THIS_MODULE,
2865 .write = ray_cs_essid_proc_write,
2868 static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2869 size_t count, loff_t *pos)
2871 static char proc_number[10];
2880 if (copy_from_user(proc_number, buffer, count))
2886 unsigned int c = *p - '0';
2892 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
2896 static const struct file_operations int_proc_fops = {
2897 .owner = THIS_MODULE,
2898 .write = int_proc_write,
2902 static struct pcmcia_device_id ray_ids[] = {
2903 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2907 MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2909 static struct pcmcia_driver ray_driver = {
2910 .owner = THIS_MODULE,
2915 .remove = ray_detach,
2916 .id_table = ray_ids,
2917 .suspend = ray_suspend,
2918 .resume = ray_resume,
2921 static int __init init_ray_cs(void)
2925 pr_debug("%s\n", rcsid);
2926 rc = pcmcia_register_driver(&ray_driver);
2927 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
2930 #ifdef CONFIG_PROC_FS
2931 proc_mkdir("driver/ray_cs", NULL);
2933 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
2934 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2935 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2936 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
2943 /*===========================================================================*/
2945 static void __exit exit_ray_cs(void)
2947 pr_debug("ray_cs: cleanup_module\n");
2949 #ifdef CONFIG_PROC_FS
2950 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2951 remove_proc_entry("driver/ray_cs/essid", NULL);
2952 remove_proc_entry("driver/ray_cs/net_type", NULL);
2953 remove_proc_entry("driver/ray_cs/translate", NULL);
2954 remove_proc_entry("driver/ray_cs", NULL);
2957 pcmcia_unregister_driver(&ray_driver);
2960 module_init(init_ray_cs);
2961 module_exit(exit_ray_cs);
2963 /*===========================================================================*/