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