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