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