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