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