1 /*=============================================================================
3 * A PCMCIA client driver for the Raylink wireless LAN card.
4 * The starting point for this module was the skeleton.c in the
5 * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net
8 * Copyright (c) 1998 Corey Thomas (corey@world.std.com)
10 * This driver is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 only of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * It is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
25 * - reorganize kmallocs in ray_attach, checking all for failure
26 * and releasing the previous allocations if one fails
28 * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003
29 * - Audit copy_to_user in ioctl(SIOCGIWESSID)
31 =============================================================================*/
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/proc_fs.h>
36 #include <linux/ptrace.h>
37 #include <linux/seq_file.h>
38 #include <linux/string.h>
39 #include <linux/timer.h>
40 #include <linux/init.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/if_arp.h>
44 #include <linux/ioport.h>
45 #include <linux/skbuff.h>
46 #include <linux/ethtool.h>
47 #include <linux/ieee80211.h>
49 #include <pcmcia/cs_types.h>
50 #include <pcmcia/cs.h>
51 #include <pcmcia/cistpl.h>
52 #include <pcmcia/cisreg.h>
53 #include <pcmcia/ds.h>
54 #include <pcmcia/mem_op.h>
56 #include <linux/wireless.h>
57 #include <net/iw_handler.h>
60 #include <asm/system.h>
61 #include <asm/byteorder.h>
62 #include <asm/uaccess.h>
64 /* Warning : these stuff will slow down the driver... */
65 #define WIRELESS_SPY /* Enable spying addresses */
66 /* Definitions we need for spy */
67 typedef struct iw_statistics iw_stats
;
68 typedef u_char mac_addr
[ETH_ALEN
]; /* Hardware address */
74 /** Prototypes based on PCMCIA skeleton driver *******************************/
75 static int ray_config(struct pcmcia_device
*link
);
76 static void ray_release(struct pcmcia_device
*link
);
77 static void ray_detach(struct pcmcia_device
*p_dev
);
79 /***** Prototypes indicated by device structure ******************************/
80 static int ray_dev_close(struct net_device
*dev
);
81 static int ray_dev_config(struct net_device
*dev
, struct ifmap
*map
);
82 static struct net_device_stats
*ray_get_stats(struct net_device
*dev
);
83 static int ray_dev_init(struct net_device
*dev
);
85 static const struct ethtool_ops netdev_ethtool_ops
;
87 static int ray_open(struct net_device
*dev
);
88 static netdev_tx_t
ray_dev_start_xmit(struct sk_buff
*skb
,
89 struct net_device
*dev
);
90 static void set_multicast_list(struct net_device
*dev
);
91 static void ray_update_multi_list(struct net_device
*dev
, int all
);
92 static int translate_frame(ray_dev_t
*local
, struct tx_msg __iomem
*ptx
,
93 unsigned char *data
, int len
);
94 static void ray_build_header(ray_dev_t
*local
, struct tx_msg __iomem
*ptx
,
95 UCHAR msg_type
, unsigned char *data
);
96 static void untranslate(ray_dev_t
*local
, struct sk_buff
*skb
, int len
);
97 static iw_stats
*ray_get_wireless_stats(struct net_device
*dev
);
98 static const struct iw_handler_def ray_handler_def
;
100 /***** Prototypes for raylink functions **************************************/
101 static int asc_to_int(char a
);
102 static void authenticate(ray_dev_t
*local
);
103 static int build_auth_frame(ray_dev_t
*local
, UCHAR
*dest
, int auth_type
);
104 static void authenticate_timeout(u_long
);
105 static int get_free_ccs(ray_dev_t
*local
);
106 static int get_free_tx_ccs(ray_dev_t
*local
);
107 static void init_startup_params(ray_dev_t
*local
);
108 static int parse_addr(char *in_str
, UCHAR
*out
);
109 static int ray_hw_xmit(unsigned char *data
, int len
, struct net_device
*dev
, UCHAR type
);
110 static int ray_init(struct net_device
*dev
);
111 static int interrupt_ecf(ray_dev_t
*local
, int ccs
);
112 static void ray_reset(struct net_device
*dev
);
113 static void ray_update_parm(struct net_device
*dev
, UCHAR objid
, UCHAR
*value
, int len
);
114 static void verify_dl_startup(u_long
);
116 /* Prototypes for interrpt time functions **********************************/
117 static irqreturn_t
ray_interrupt(int reg
, void *dev_id
);
118 static void clear_interrupt(ray_dev_t
*local
);
119 static void rx_deauthenticate(ray_dev_t
*local
, struct rcs __iomem
*prcs
,
120 unsigned int pkt_addr
, int rx_len
);
121 static int copy_from_rx_buff(ray_dev_t
*local
, UCHAR
*dest
, int pkt_addr
, int len
);
122 static void ray_rx(struct net_device
*dev
, ray_dev_t
*local
, struct rcs __iomem
*prcs
);
123 static void release_frag_chain(ray_dev_t
*local
, struct rcs __iomem
*prcs
);
124 static void rx_authenticate(ray_dev_t
*local
, struct rcs __iomem
*prcs
,
125 unsigned int pkt_addr
, int rx_len
);
126 static void rx_data(struct net_device
*dev
, struct rcs __iomem
*prcs
,
127 unsigned int pkt_addr
, int rx_len
);
128 static void associate(ray_dev_t
*local
);
130 /* Card command functions */
131 static int dl_startup_params(struct net_device
*dev
);
132 static void join_net(u_long local
);
133 static void start_net(u_long local
);
134 /* void start_net(ray_dev_t *local); */
136 /*===========================================================================*/
137 /* Parameters that can be set with 'insmod' */
139 /* ADHOC=0, Infrastructure=1 */
140 static int net_type
= ADHOC
;
142 /* Hop dwell time in Kus (1024 us units defined by 802.11) */
143 static int hop_dwell
= 128;
145 /* Beacon period in Kus */
146 static int beacon_period
= 256;
148 /* power save mode (0 = off, 1 = save power) */
151 /* String for network's Extended Service Set ID. 32 Characters max */
154 /* Default to encapsulation unless translation requested */
155 static int translate
= 1;
157 static int country
= USA
;
163 /* 48 bit physical card address if overriding card's real physical
164 * address is required. Since IEEE 802.11 addresses are 48 bits
165 * like ethernet, an int can't be used, so a string is used. To
166 * allow use of addresses starting with a decimal digit, the first
167 * character must be a letter and will be ignored. This letter is
168 * followed by up to 12 hex digits which are the address. If less
169 * than 12 digits are used, the address will be left filled with 0's.
170 * Note that bit 0 of the first byte is the broadcast bit, and evil
171 * things will happen if it is not 0 in a card address.
173 static char *phy_addr
= NULL
;
176 /* A struct pcmcia_device structure has fields for most things that are needed
177 to keep track of a socket, but there will usually be some device
178 specific information that also needs to be kept track of. The
179 'priv' pointer in a struct pcmcia_device structure can be used to point to
180 a device-specific private data structure, like this.
182 static unsigned int ray_mem_speed
= 500;
184 /* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
185 static struct pcmcia_device
*this_device
= NULL
;
187 MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
188 MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
189 MODULE_LICENSE("GPL");
191 module_param(net_type
, int, 0);
192 module_param(hop_dwell
, int, 0);
193 module_param(beacon_period
, int, 0);
194 module_param(psm
, int, 0);
195 module_param(essid
, charp
, 0);
196 module_param(translate
, int, 0);
197 module_param(country
, int, 0);
198 module_param(sniffer
, int, 0);
199 module_param(bc
, int, 0);
200 module_param(phy_addr
, charp
, 0);
201 module_param(ray_mem_speed
, int, 0);
203 static UCHAR b5_default_startup_parms
[] = {
204 0, 0, /* Adhoc station */
205 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
206 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0,
209 1, 0, /* Active scan, CA Mode */
210 0, 0, 0, 0, 0, 0, /* No default MAC addr */
211 0x7f, 0xff, /* Frag threshold */
212 0x00, 0x80, /* Hop time 128 Kus */
213 0x01, 0x00, /* Beacon period 256 Kus */
214 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
215 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
216 0x7f, 0xff, /* RTS threshold */
217 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
218 0x05, /* assoc resp timeout thresh */
219 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
220 0, /* Promiscuous mode */
221 0x0c, 0x0bd, /* Unique word */
222 0x32, /* Slot time */
223 0xff, 0xff, /* roam-low snr, low snr count */
224 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
225 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
226 /* b4 - b5 differences start here */
227 0x00, 0x3f, /* CW max */
228 0x00, 0x0f, /* CW min */
229 0x04, 0x08, /* Noise gain, limit offset */
230 0x28, 0x28, /* det rssi, med busy offsets */
231 7, /* det sync thresh */
232 0, 2, 2, /* test mode, min, max */
233 0, /* allow broadcast SSID probe resp */
234 0, 0, /* privacy must start, can join */
235 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
238 static UCHAR b4_default_startup_parms
[] = {
239 0, 0, /* Adhoc station */
240 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
241 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0,
244 1, 0, /* Active scan, CA Mode */
245 0, 0, 0, 0, 0, 0, /* No default MAC addr */
246 0x7f, 0xff, /* Frag threshold */
247 0x02, 0x00, /* Hop time */
248 0x00, 0x01, /* Beacon period */
249 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
250 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
251 0x7f, 0xff, /* RTS threshold */
252 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
253 0x05, /* assoc resp timeout thresh */
254 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
255 0, /* Promiscuous mode */
256 0x0c, 0x0bd, /* Unique word */
257 0x4e, /* Slot time (TBD seems wrong) */
258 0xff, 0xff, /* roam-low snr, low snr count */
259 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
260 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
261 /* b4 - b5 differences start here */
262 0x3f, 0x0f, /* CW max, min */
263 0x04, 0x08, /* Noise gain, limit offset */
264 0x28, 0x28, /* det rssi, med busy offsets */
265 7, /* det sync thresh */
266 0, 2, 2 /* test mode, min, max */
269 /*===========================================================================*/
270 static unsigned char eth2_llc
[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
272 static char hop_pattern_length
[] = { 1,
273 USA_HOP_MOD
, EUROPE_HOP_MOD
,
274 JAPAN_HOP_MOD
, KOREA_HOP_MOD
,
275 SPAIN_HOP_MOD
, FRANCE_HOP_MOD
,
276 ISRAEL_HOP_MOD
, AUSTRALIA_HOP_MOD
,
280 static char rcsid
[] =
281 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
283 static const struct net_device_ops ray_netdev_ops
= {
284 .ndo_init
= ray_dev_init
,
285 .ndo_open
= ray_open
,
286 .ndo_stop
= ray_dev_close
,
287 .ndo_start_xmit
= ray_dev_start_xmit
,
288 .ndo_set_config
= ray_dev_config
,
289 .ndo_get_stats
= ray_get_stats
,
290 .ndo_set_multicast_list
= set_multicast_list
,
291 .ndo_change_mtu
= eth_change_mtu
,
292 .ndo_set_mac_address
= eth_mac_addr
,
293 .ndo_validate_addr
= eth_validate_addr
,
296 /*=============================================================================
297 ray_attach() creates an "instance" of the driver, allocating
298 local data structures for one device. The device is registered
300 The dev_link structure is initialized, but we don't actually
301 configure the card at this point -- we wait until we receive a
302 card insertion event.
303 =============================================================================*/
304 static int ray_probe(struct pcmcia_device
*p_dev
)
307 struct net_device
*dev
;
309 dev_dbg(&p_dev
->dev
, "ray_attach()\n");
311 /* Allocate space for private device-specific data */
312 dev
= alloc_etherdev(sizeof(ray_dev_t
));
316 local
= netdev_priv(dev
);
317 local
->finder
= p_dev
;
319 /* The io structure describes IO port mapping. None used here */
320 p_dev
->io
.NumPorts1
= 0;
321 p_dev
->io
.Attributes1
= IO_DATA_PATH_WIDTH_8
;
322 p_dev
->io
.IOAddrLines
= 5;
324 /* General socket configuration */
325 p_dev
->conf
.Attributes
= CONF_ENABLE_IRQ
;
326 p_dev
->conf
.IntType
= INT_MEMORY_AND_IO
;
327 p_dev
->conf
.ConfigIndex
= 1;
331 local
->finder
= p_dev
;
332 local
->card_status
= CARD_INSERTED
;
333 local
->authentication_state
= UNAUTHENTICATED
;
334 local
->num_multi
= 0;
335 dev_dbg(&p_dev
->dev
, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
336 p_dev
, dev
, local
, &ray_interrupt
);
338 /* Raylink entries in the device structure */
339 dev
->netdev_ops
= &ray_netdev_ops
;
340 SET_ETHTOOL_OPS(dev
, &netdev_ethtool_ops
);
341 dev
->wireless_handlers
= &ray_handler_def
;
343 local
->wireless_data
.spy_data
= &local
->spy_data
;
344 dev
->wireless_data
= &local
->wireless_data
;
345 #endif /* WIRELESS_SPY */
348 dev_dbg(&p_dev
->dev
, "ray_cs ray_attach calling ether_setup.)\n");
349 netif_stop_queue(dev
);
351 init_timer(&local
->timer
);
354 return ray_config(p_dev
);
360 /*=============================================================================
361 This deletes a driver "instance". The device is de-registered
362 with Card Services. If it has been released, all local data
363 structures are freed. Otherwise, the structures will be freed
364 when the device is released.
365 =============================================================================*/
366 static void ray_detach(struct pcmcia_device
*link
)
368 struct net_device
*dev
;
371 dev_dbg(&link
->dev
, "ray_detach\n");
378 local
= netdev_priv(dev
);
379 del_timer(&local
->timer
);
383 unregister_netdev(dev
);
386 dev_dbg(&link
->dev
, "ray_cs ray_detach ending\n");
389 /*=============================================================================
390 ray_config() is run after a CARD_INSERTION event
391 is received, to configure the PCMCIA socket, and to make the
392 ethernet device available to the system.
393 =============================================================================*/
394 #define MAX_TUPLE_SIZE 128
395 static int ray_config(struct pcmcia_device
*link
)
401 struct net_device
*dev
= (struct net_device
*)link
->priv
;
402 ray_dev_t
*local
= netdev_priv(dev
);
404 dev_dbg(&link
->dev
, "ray_config\n");
406 /* Determine card type and firmware version */
407 printk(KERN_INFO
"ray_cs Detected: %s%s%s%s\n",
408 link
->prod_id
[0] ? link
->prod_id
[0] : " ",
409 link
->prod_id
[1] ? link
->prod_id
[1] : " ",
410 link
->prod_id
[2] ? link
->prod_id
[2] : " ",
411 link
->prod_id
[3] ? link
->prod_id
[3] : " ");
413 /* Now allocate an interrupt line. Note that this does not
414 actually assign a handler to the interrupt.
416 ret
= pcmcia_request_irq(link
, ray_interrupt
);
419 dev
->irq
= link
->irq
;
421 /* This actually configures the PCMCIA socket -- setting up
422 the I/O windows and the interrupt mapping.
424 ret
= pcmcia_request_configuration(link
, &link
->conf
);
428 /*** Set up 32k window for shared memory (transmit and control) ************/
430 WIN_DATA_WIDTH_8
| WIN_MEMORY_TYPE_CM
| WIN_ENABLE
| WIN_USE_WAIT
;
433 req
.AccessSpeed
= ray_mem_speed
;
434 ret
= pcmcia_request_window(link
, &req
, &link
->win
);
437 mem
.CardOffset
= 0x0000;
439 ret
= pcmcia_map_mem_page(link
, link
->win
, &mem
);
442 local
->sram
= ioremap(req
.Base
, req
.Size
);
444 /*** Set up 16k window for shared memory (receive buffer) ***************/
446 WIN_DATA_WIDTH_8
| WIN_MEMORY_TYPE_CM
| WIN_ENABLE
| WIN_USE_WAIT
;
449 req
.AccessSpeed
= ray_mem_speed
;
450 ret
= pcmcia_request_window(link
, &req
, &local
->rmem_handle
);
453 mem
.CardOffset
= 0x8000;
455 ret
= pcmcia_map_mem_page(link
, local
->rmem_handle
, &mem
);
458 local
->rmem
= ioremap(req
.Base
, req
.Size
);
460 /*** Set up window for attribute memory ***********************************/
462 WIN_DATA_WIDTH_8
| WIN_MEMORY_TYPE_AM
| WIN_ENABLE
| WIN_USE_WAIT
;
465 req
.AccessSpeed
= ray_mem_speed
;
466 ret
= pcmcia_request_window(link
, &req
, &local
->amem_handle
);
469 mem
.CardOffset
= 0x0000;
471 ret
= pcmcia_map_mem_page(link
, local
->amem_handle
, &mem
);
474 local
->amem
= ioremap(req
.Base
, req
.Size
);
476 dev_dbg(&link
->dev
, "ray_config sram=%p\n", local
->sram
);
477 dev_dbg(&link
->dev
, "ray_config rmem=%p\n", local
->rmem
);
478 dev_dbg(&link
->dev
, "ray_config amem=%p\n", local
->amem
);
479 if (ray_init(dev
) < 0) {
484 SET_NETDEV_DEV(dev
, &link
->dev
);
485 i
= register_netdev(dev
);
487 printk("ray_config register_netdev() failed\n");
492 strcpy(local
->node
.dev_name
, dev
->name
);
493 link
->dev_node
= &local
->node
;
495 printk(KERN_INFO
"%s: RayLink, irq %d, hw_addr %pM\n",
496 dev
->name
, dev
->irq
, dev
->dev_addr
);
505 static inline struct ccs __iomem
*ccs_base(ray_dev_t
*dev
)
507 return dev
->sram
+ CCS_BASE
;
510 static inline struct rcs __iomem
*rcs_base(ray_dev_t
*dev
)
513 * This looks nonsensical, since there is a separate
514 * RCS_BASE. But the difference between a "struct rcs"
515 * and a "struct ccs" ends up being in the _index_ off
516 * the base, so the base pointer is the same for both
519 return dev
->sram
+ CCS_BASE
;
522 /*===========================================================================*/
523 static int ray_init(struct net_device
*dev
)
527 struct ccs __iomem
*pccs
;
528 ray_dev_t
*local
= netdev_priv(dev
);
529 struct pcmcia_device
*link
= local
->finder
;
530 dev_dbg(&link
->dev
, "ray_init(0x%p)\n", dev
);
531 if (!(pcmcia_dev_present(link
))) {
532 dev_dbg(&link
->dev
, "ray_init - device not present\n");
536 local
->net_type
= net_type
;
537 local
->sta_type
= TYPE_STA
;
539 /* Copy the startup results to local memory */
540 memcpy_fromio(&local
->startup_res
, local
->sram
+ ECF_TO_HOST_BASE
,
541 sizeof(struct startup_res_6
));
543 /* Check Power up test status and get mac address from card */
544 if (local
->startup_res
.startup_word
!= 0x80) {
545 printk(KERN_INFO
"ray_init ERROR card status = %2x\n",
546 local
->startup_res
.startup_word
);
547 local
->card_status
= CARD_INIT_ERROR
;
551 local
->fw_ver
= local
->startup_res
.firmware_version
[0];
552 local
->fw_bld
= local
->startup_res
.firmware_version
[1];
553 local
->fw_var
= local
->startup_res
.firmware_version
[2];
554 dev_dbg(&link
->dev
, "ray_init firmware version %d.%d \n", local
->fw_ver
,
557 local
->tib_length
= 0x20;
558 if ((local
->fw_ver
== 5) && (local
->fw_bld
>= 30))
559 local
->tib_length
= local
->startup_res
.tib_length
;
560 dev_dbg(&link
->dev
, "ray_init tib_length = 0x%02x\n", local
->tib_length
);
561 /* Initialize CCS's to buffer free state */
562 pccs
= ccs_base(local
);
563 for (i
= 0; i
< NUMBER_OF_CCS
; i
++) {
564 writeb(CCS_BUFFER_FREE
, &(pccs
++)->buffer_status
);
566 init_startup_params(local
);
568 /* copy mac address to startup parameters */
569 if (parse_addr(phy_addr
, local
->sparm
.b4
.a_mac_addr
)) {
570 p
= local
->sparm
.b4
.a_mac_addr
;
572 memcpy(&local
->sparm
.b4
.a_mac_addr
,
573 &local
->startup_res
.station_addr
, ADDRLEN
);
574 p
= local
->sparm
.b4
.a_mac_addr
;
577 clear_interrupt(local
); /* Clear any interrupt from the card */
578 local
->card_status
= CARD_AWAITING_PARAM
;
579 dev_dbg(&link
->dev
, "ray_init ending\n");
583 /*===========================================================================*/
584 /* Download startup parameters to the card and command it to read them */
585 static int dl_startup_params(struct net_device
*dev
)
588 ray_dev_t
*local
= netdev_priv(dev
);
589 struct ccs __iomem
*pccs
;
590 struct pcmcia_device
*link
= local
->finder
;
592 dev_dbg(&link
->dev
, "dl_startup_params entered\n");
593 if (!(pcmcia_dev_present(link
))) {
594 dev_dbg(&link
->dev
, "ray_cs dl_startup_params - device not present\n");
598 /* Copy parameters to host to ECF area */
599 if (local
->fw_ver
== 0x55)
600 memcpy_toio(local
->sram
+ HOST_TO_ECF_BASE
, &local
->sparm
.b4
,
601 sizeof(struct b4_startup_params
));
603 memcpy_toio(local
->sram
+ HOST_TO_ECF_BASE
, &local
->sparm
.b5
,
604 sizeof(struct b5_startup_params
));
606 /* Fill in the CCS fields for the ECF */
607 if ((ccsindex
= get_free_ccs(local
)) < 0)
609 local
->dl_param_ccs
= ccsindex
;
610 pccs
= ccs_base(local
) + ccsindex
;
611 writeb(CCS_DOWNLOAD_STARTUP_PARAMS
, &pccs
->cmd
);
612 dev_dbg(&link
->dev
, "dl_startup_params start ccsindex = %d\n",
613 local
->dl_param_ccs
);
614 /* Interrupt the firmware to process the command */
615 if (interrupt_ecf(local
, ccsindex
)) {
616 printk(KERN_INFO
"ray dl_startup_params failed - "
617 "ECF not ready for intr\n");
618 local
->card_status
= CARD_DL_PARAM_ERROR
;
619 writeb(CCS_BUFFER_FREE
, &(pccs
++)->buffer_status
);
622 local
->card_status
= CARD_DL_PARAM
;
623 /* Start kernel timer to wait for dl startup to complete. */
624 local
->timer
.expires
= jiffies
+ HZ
/ 2;
625 local
->timer
.data
= (long)local
;
626 local
->timer
.function
= &verify_dl_startup
;
627 add_timer(&local
->timer
);
629 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
631 } /* dl_startup_params */
633 /*===========================================================================*/
634 static void init_startup_params(ray_dev_t
*local
)
638 if (country
> JAPAN_TEST
)
640 else if (country
< USA
)
642 /* structure for hop time and beacon period is defined here using
643 * New 802.11D6.1 format. Card firmware is still using old format
646 * a_hop_time ms byte a_hop_time ms byte
647 * a_hop_time 2s byte a_hop_time ls byte
648 * a_hop_time ls byte a_beacon_period ms byte
649 * a_beacon_period a_beacon_period ls byte
651 * a_hop_time = uS a_hop_time = KuS
652 * a_beacon_period = hops a_beacon_period = KuS
653 *//* 64ms = 010000 */
654 if (local
->fw_ver
== 0x55) {
655 memcpy((UCHAR
*) &local
->sparm
.b4
, b4_default_startup_parms
,
656 sizeof(struct b4_startup_params
));
657 /* Translate sane kus input values to old build 4/5 format */
658 /* i = hop time in uS truncated to 3 bytes */
659 i
= (hop_dwell
* 1024) & 0xffffff;
660 local
->sparm
.b4
.a_hop_time
[0] = (i
>> 16) & 0xff;
661 local
->sparm
.b4
.a_hop_time
[1] = (i
>> 8) & 0xff;
662 local
->sparm
.b4
.a_beacon_period
[0] = 0;
663 local
->sparm
.b4
.a_beacon_period
[1] =
664 ((beacon_period
/ hop_dwell
) - 1) & 0xff;
665 local
->sparm
.b4
.a_curr_country_code
= country
;
666 local
->sparm
.b4
.a_hop_pattern_length
=
667 hop_pattern_length
[(int)country
] - 1;
669 local
->sparm
.b4
.a_ack_timeout
= 0x50;
670 local
->sparm
.b4
.a_sifs
= 0x3f;
672 } else { /* Version 5 uses real kus values */
673 memcpy((UCHAR
*) &local
->sparm
.b5
, b5_default_startup_parms
,
674 sizeof(struct b5_startup_params
));
676 local
->sparm
.b5
.a_hop_time
[0] = (hop_dwell
>> 8) & 0xff;
677 local
->sparm
.b5
.a_hop_time
[1] = hop_dwell
& 0xff;
678 local
->sparm
.b5
.a_beacon_period
[0] =
679 (beacon_period
>> 8) & 0xff;
680 local
->sparm
.b5
.a_beacon_period
[1] = beacon_period
& 0xff;
682 local
->sparm
.b5
.a_power_mgt_state
= 1;
683 local
->sparm
.b5
.a_curr_country_code
= country
;
684 local
->sparm
.b5
.a_hop_pattern_length
=
685 hop_pattern_length
[(int)country
];
688 local
->sparm
.b4
.a_network_type
= net_type
& 0x01;
689 local
->sparm
.b4
.a_acting_as_ap_status
= TYPE_STA
;
692 strncpy(local
->sparm
.b4
.a_current_ess_id
, essid
, ESSID_SIZE
);
693 } /* init_startup_params */
695 /*===========================================================================*/
696 static void verify_dl_startup(u_long data
)
698 ray_dev_t
*local
= (ray_dev_t
*) data
;
699 struct ccs __iomem
*pccs
= ccs_base(local
) + local
->dl_param_ccs
;
701 struct pcmcia_device
*link
= local
->finder
;
703 if (!(pcmcia_dev_present(link
))) {
704 dev_dbg(&link
->dev
, "ray_cs verify_dl_startup - device not present\n");
711 "verify_dl_startup parameters sent via ccs %d:\n",
712 local
->dl_param_ccs
);
713 for (i
= 0; i
< sizeof(struct b5_startup_params
); i
++) {
715 (unsigned int)readb(local
->sram
+
716 HOST_TO_ECF_BASE
+ i
));
722 status
= readb(&pccs
->buffer_status
);
723 if (status
!= CCS_BUFFER_FREE
) {
725 "Download startup params failed. Status = %d\n",
727 local
->card_status
= CARD_DL_PARAM_ERROR
;
730 if (local
->sparm
.b4
.a_network_type
== ADHOC
)
731 start_net((u_long
) local
);
733 join_net((u_long
) local
);
736 } /* end verify_dl_startup */
738 /*===========================================================================*/
739 /* Command card to start a network */
740 static void start_net(u_long data
)
742 ray_dev_t
*local
= (ray_dev_t
*) data
;
743 struct ccs __iomem
*pccs
;
745 struct pcmcia_device
*link
= local
->finder
;
746 if (!(pcmcia_dev_present(link
))) {
747 dev_dbg(&link
->dev
, "ray_cs start_net - device not present\n");
750 /* Fill in the CCS fields for the ECF */
751 if ((ccsindex
= get_free_ccs(local
)) < 0)
753 pccs
= ccs_base(local
) + ccsindex
;
754 writeb(CCS_START_NETWORK
, &pccs
->cmd
);
755 writeb(0, &pccs
->var
.start_network
.update_param
);
756 /* Interrupt the firmware to process the command */
757 if (interrupt_ecf(local
, ccsindex
)) {
758 dev_dbg(&link
->dev
, "ray start net failed - card not ready for intr\n");
759 writeb(CCS_BUFFER_FREE
, &(pccs
++)->buffer_status
);
762 local
->card_status
= CARD_DOING_ACQ
;
764 } /* end start_net */
766 /*===========================================================================*/
767 /* Command card to join a network */
768 static void join_net(u_long data
)
770 ray_dev_t
*local
= (ray_dev_t
*) data
;
772 struct ccs __iomem
*pccs
;
774 struct pcmcia_device
*link
= local
->finder
;
776 if (!(pcmcia_dev_present(link
))) {
777 dev_dbg(&link
->dev
, "ray_cs join_net - device not present\n");
780 /* Fill in the CCS fields for the ECF */
781 if ((ccsindex
= get_free_ccs(local
)) < 0)
783 pccs
= ccs_base(local
) + ccsindex
;
784 writeb(CCS_JOIN_NETWORK
, &pccs
->cmd
);
785 writeb(0, &pccs
->var
.join_network
.update_param
);
786 writeb(0, &pccs
->var
.join_network
.net_initiated
);
787 /* Interrupt the firmware to process the command */
788 if (interrupt_ecf(local
, ccsindex
)) {
789 dev_dbg(&link
->dev
, "ray join net failed - card not ready for intr\n");
790 writeb(CCS_BUFFER_FREE
, &(pccs
++)->buffer_status
);
793 local
->card_status
= CARD_DOING_ACQ
;
797 /*============================================================================
798 After a card is removed, ray_release() will unregister the net
799 device, and release the PCMCIA configuration. If the device is
800 still open, this will be postponed until it is closed.
801 =============================================================================*/
802 static void ray_release(struct pcmcia_device
*link
)
804 struct net_device
*dev
= link
->priv
;
805 ray_dev_t
*local
= netdev_priv(dev
);
808 dev_dbg(&link
->dev
, "ray_release\n");
810 del_timer(&local
->timer
);
812 iounmap(local
->sram
);
813 iounmap(local
->rmem
);
814 iounmap(local
->amem
);
815 /* Do bother checking to see if these succeed or not */
816 i
= pcmcia_release_window(link
, local
->amem_handle
);
818 dev_dbg(&link
->dev
, "ReleaseWindow(local->amem) ret = %x\n", i
);
819 i
= pcmcia_release_window(link
, local
->rmem_handle
);
821 dev_dbg(&link
->dev
, "ReleaseWindow(local->rmem) ret = %x\n", i
);
822 pcmcia_disable_device(link
);
824 dev_dbg(&link
->dev
, "ray_release ending\n");
827 static int ray_suspend(struct pcmcia_device
*link
)
829 struct net_device
*dev
= link
->priv
;
832 netif_device_detach(dev
);
837 static int ray_resume(struct pcmcia_device
*link
)
839 struct net_device
*dev
= link
->priv
;
843 netif_device_attach(dev
);
849 /*===========================================================================*/
850 static int ray_dev_init(struct net_device
*dev
)
852 #ifdef RAY_IMMEDIATE_INIT
854 #endif /* RAY_IMMEDIATE_INIT */
855 ray_dev_t
*local
= netdev_priv(dev
);
856 struct pcmcia_device
*link
= local
->finder
;
858 dev_dbg(&link
->dev
, "ray_dev_init(dev=%p)\n", dev
);
859 if (!(pcmcia_dev_present(link
))) {
860 dev_dbg(&link
->dev
, "ray_dev_init - device not present\n");
863 #ifdef RAY_IMMEDIATE_INIT
864 /* Download startup parameters */
865 if ((i
= dl_startup_params(dev
)) < 0) {
866 printk(KERN_INFO
"ray_dev_init dl_startup_params failed - "
867 "returns 0x%x\n", i
);
870 #else /* RAY_IMMEDIATE_INIT */
871 /* Postpone the card init so that we can still configure the card,
872 * for example using the Wireless Extensions. The init will happen
873 * in ray_open() - Jean II */
875 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
877 #endif /* RAY_IMMEDIATE_INIT */
879 /* copy mac and broadcast addresses to linux device */
880 memcpy(dev
->dev_addr
, &local
->sparm
.b4
.a_mac_addr
, ADDRLEN
);
881 memset(dev
->broadcast
, 0xff, ETH_ALEN
);
883 dev_dbg(&link
->dev
, "ray_dev_init ending\n");
887 /*===========================================================================*/
888 static int ray_dev_config(struct net_device
*dev
, struct ifmap
*map
)
890 ray_dev_t
*local
= netdev_priv(dev
);
891 struct pcmcia_device
*link
= local
->finder
;
892 /* Dummy routine to satisfy device structure */
893 dev_dbg(&link
->dev
, "ray_dev_config(dev=%p,ifmap=%p)\n", dev
, map
);
894 if (!(pcmcia_dev_present(link
))) {
895 dev_dbg(&link
->dev
, "ray_dev_config - device not present\n");
902 /*===========================================================================*/
903 static netdev_tx_t
ray_dev_start_xmit(struct sk_buff
*skb
,
904 struct net_device
*dev
)
906 ray_dev_t
*local
= netdev_priv(dev
);
907 struct pcmcia_device
*link
= local
->finder
;
908 short length
= skb
->len
;
910 if (!pcmcia_dev_present(link
)) {
911 dev_dbg(&link
->dev
, "ray_dev_start_xmit - device not present\n");
916 dev_dbg(&link
->dev
, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb
, dev
);
917 if (local
->authentication_state
== NEED_TO_AUTH
) {
918 dev_dbg(&link
->dev
, "ray_cs Sending authentication request.\n");
919 if (!build_auth_frame(local
, local
->auth_id
, OPEN_AUTH_REQUEST
)) {
920 local
->authentication_state
= AUTHENTICATED
;
921 netif_stop_queue(dev
);
922 return NETDEV_TX_BUSY
;
926 if (length
< ETH_ZLEN
) {
927 if (skb_padto(skb
, ETH_ZLEN
))
931 switch (ray_hw_xmit(skb
->data
, length
, dev
, DATA_TYPE
)) {
934 netif_stop_queue(dev
);
935 return NETDEV_TX_BUSY
;
940 dev
->trans_start
= jiffies
;
945 } /* ray_dev_start_xmit */
947 /*===========================================================================*/
948 static int ray_hw_xmit(unsigned char *data
, int len
, struct net_device
*dev
,
951 ray_dev_t
*local
= netdev_priv(dev
);
952 struct ccs __iomem
*pccs
;
955 struct tx_msg __iomem
*ptx
; /* Address of xmit buffer in PC space */
956 short int addr
; /* Address of xmit buffer in card space */
958 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data
, len
, dev
);
959 if (len
+ TX_HEADER_LENGTH
> TX_BUF_SIZE
) {
960 printk(KERN_INFO
"ray_hw_xmit packet too large: %d bytes\n",
964 switch (ccsindex
= get_free_tx_ccs(local
)) {
966 pr_debug("ray_hw_xmit tx_ccs table busy\n");
968 pr_debug("ray_hw_xmit No free tx ccs\n");
970 netif_stop_queue(dev
);
975 addr
= TX_BUF_BASE
+ (ccsindex
<< 11);
977 if (msg_type
== DATA_TYPE
) {
978 local
->stats
.tx_bytes
+= len
;
979 local
->stats
.tx_packets
++;
982 ptx
= local
->sram
+ addr
;
984 ray_build_header(local
, ptx
, msg_type
, data
);
986 offset
= translate_frame(local
, ptx
, data
, len
);
987 } else { /* Encapsulate frame */
988 /* TBD TIB length will move address of ptx->var */
989 memcpy_toio(&ptx
->var
, data
, len
);
993 /* fill in the CCS */
994 pccs
= ccs_base(local
) + ccsindex
;
995 len
+= TX_HEADER_LENGTH
+ offset
;
996 writeb(CCS_TX_REQUEST
, &pccs
->cmd
);
997 writeb(addr
>> 8, &pccs
->var
.tx_request
.tx_data_ptr
[0]);
998 writeb(local
->tib_length
, &pccs
->var
.tx_request
.tx_data_ptr
[1]);
999 writeb(len
>> 8, &pccs
->var
.tx_request
.tx_data_length
[0]);
1000 writeb(len
& 0xff, &pccs
->var
.tx_request
.tx_data_length
[1]);
1001 /* TBD still need psm_cam? */
1002 writeb(PSM_CAM
, &pccs
->var
.tx_request
.pow_sav_mode
);
1003 writeb(local
->net_default_tx_rate
, &pccs
->var
.tx_request
.tx_rate
);
1004 writeb(0, &pccs
->var
.tx_request
.antenna
);
1005 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
1006 local
->net_default_tx_rate
);
1008 /* Interrupt the firmware to process the command */
1009 if (interrupt_ecf(local
, ccsindex
)) {
1010 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
1011 /* TBD very inefficient to copy packet to buffer, and then not
1012 send it, but the alternative is to queue the messages and that
1013 won't be done for a while. Maybe set tbusy until a CCS is free?
1015 writeb(CCS_BUFFER_FREE
, &pccs
->buffer_status
);
1016 return XMIT_NO_INTR
;
1019 } /* end ray_hw_xmit */
1021 /*===========================================================================*/
1022 static int translate_frame(ray_dev_t
*local
, struct tx_msg __iomem
*ptx
,
1023 unsigned char *data
, int len
)
1025 __be16 proto
= ((struct ethhdr
*)data
)->h_proto
;
1026 if (ntohs(proto
) >= 1536) { /* DIX II ethernet frame */
1027 pr_debug("ray_cs translate_frame DIX II\n");
1028 /* Copy LLC header to card buffer */
1029 memcpy_toio(&ptx
->var
, eth2_llc
, sizeof(eth2_llc
));
1030 memcpy_toio(((void __iomem
*)&ptx
->var
) + sizeof(eth2_llc
),
1031 (UCHAR
*) &proto
, 2);
1032 if (proto
== htons(ETH_P_AARP
) || proto
== htons(ETH_P_IPX
)) {
1033 /* This is the selective translation table, only 2 entries */
1035 &((struct snaphdr_t __iomem
*)ptx
->var
)->org
[3]);
1037 /* Copy body of ethernet packet without ethernet header */
1038 memcpy_toio((void __iomem
*)&ptx
->var
+
1039 sizeof(struct snaphdr_t
), data
+ ETH_HLEN
,
1041 return (int)sizeof(struct snaphdr_t
) - ETH_HLEN
;
1042 } else { /* already 802 type, and proto is length */
1043 pr_debug("ray_cs translate_frame 802\n");
1044 if (proto
== htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
1045 pr_debug("ray_cs translate_frame evil IPX\n");
1046 memcpy_toio(&ptx
->var
, data
+ ETH_HLEN
, len
- ETH_HLEN
);
1047 return 0 - ETH_HLEN
;
1049 memcpy_toio(&ptx
->var
, data
+ ETH_HLEN
, len
- ETH_HLEN
);
1050 return 0 - ETH_HLEN
;
1052 /* TBD do other frame types */
1053 } /* end translate_frame */
1055 /*===========================================================================*/
1056 static void ray_build_header(ray_dev_t
*local
, struct tx_msg __iomem
*ptx
,
1057 UCHAR msg_type
, unsigned char *data
)
1059 writeb(PROTOCOL_VER
| msg_type
, &ptx
->mac
.frame_ctl_1
);
1060 /*** IEEE 802.11 Address field assignments *************
1061 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1062 Adhoc 0 0 dest src (terminal) BSSID N/A
1063 AP to Terminal 0 1 dest AP(BSSID) source N/A
1064 Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1065 AP to AP 1 1 dest AP src AP dest source
1066 *******************************************************/
1067 if (local
->net_type
== ADHOC
) {
1068 writeb(0, &ptx
->mac
.frame_ctl_2
);
1069 memcpy_toio(ptx
->mac
.addr_1
, ((struct ethhdr
*)data
)->h_dest
,
1071 memcpy_toio(ptx
->mac
.addr_3
, local
->bss_id
, ADDRLEN
);
1072 } else { /* infrastructure */
1074 if (local
->sparm
.b4
.a_acting_as_ap_status
) {
1075 writeb(FC2_FROM_DS
, &ptx
->mac
.frame_ctl_2
);
1076 memcpy_toio(ptx
->mac
.addr_1
,
1077 ((struct ethhdr
*)data
)->h_dest
, ADDRLEN
);
1078 memcpy_toio(ptx
->mac
.addr_2
, local
->bss_id
, 6);
1079 memcpy_toio(ptx
->mac
.addr_3
,
1080 ((struct ethhdr
*)data
)->h_source
, ADDRLEN
);
1081 } else { /* Terminal */
1083 writeb(FC2_TO_DS
, &ptx
->mac
.frame_ctl_2
);
1084 memcpy_toio(ptx
->mac
.addr_1
, local
->bss_id
, ADDRLEN
);
1085 memcpy_toio(ptx
->mac
.addr_2
,
1086 ((struct ethhdr
*)data
)->h_source
, ADDRLEN
);
1087 memcpy_toio(ptx
->mac
.addr_3
,
1088 ((struct ethhdr
*)data
)->h_dest
, ADDRLEN
);
1091 } /* end encapsulate_frame */
1093 /*===========================================================================*/
1095 static void netdev_get_drvinfo(struct net_device
*dev
,
1096 struct ethtool_drvinfo
*info
)
1098 strcpy(info
->driver
, "ray_cs");
1101 static const struct ethtool_ops netdev_ethtool_ops
= {
1102 .get_drvinfo
= netdev_get_drvinfo
,
1105 /*====================================================================*/
1107 /*------------------------------------------------------------------*/
1109 * Wireless Handler : get protocol name
1111 static int ray_get_name(struct net_device
*dev
,
1112 struct iw_request_info
*info
, char *cwrq
, char *extra
)
1114 strcpy(cwrq
, "IEEE 802.11-FH");
1118 /*------------------------------------------------------------------*/
1120 * Wireless Handler : set frequency
1122 static int ray_set_freq(struct net_device
*dev
,
1123 struct iw_request_info
*info
,
1124 struct iw_freq
*fwrq
, char *extra
)
1126 ray_dev_t
*local
= netdev_priv(dev
);
1127 int err
= -EINPROGRESS
; /* Call commit handler */
1129 /* Reject if card is already initialised */
1130 if (local
->card_status
!= CARD_AWAITING_PARAM
)
1133 /* Setting by channel number */
1134 if ((fwrq
->m
> USA_HOP_MOD
) || (fwrq
->e
> 0))
1137 local
->sparm
.b5
.a_hop_pattern
= fwrq
->m
;
1142 /*------------------------------------------------------------------*/
1144 * Wireless Handler : get frequency
1146 static int ray_get_freq(struct net_device
*dev
,
1147 struct iw_request_info
*info
,
1148 struct iw_freq
*fwrq
, char *extra
)
1150 ray_dev_t
*local
= netdev_priv(dev
);
1152 fwrq
->m
= local
->sparm
.b5
.a_hop_pattern
;
1157 /*------------------------------------------------------------------*/
1159 * Wireless Handler : set ESSID
1161 static int ray_set_essid(struct net_device
*dev
,
1162 struct iw_request_info
*info
,
1163 struct iw_point
*dwrq
, char *extra
)
1165 ray_dev_t
*local
= netdev_priv(dev
);
1167 /* Reject if card is already initialised */
1168 if (local
->card_status
!= CARD_AWAITING_PARAM
)
1171 /* Check if we asked for `any' */
1172 if (dwrq
->flags
== 0) {
1173 /* Corey : can you do that ? */
1176 /* Check the size of the string */
1177 if (dwrq
->length
> IW_ESSID_MAX_SIZE
) {
1181 /* Set the ESSID in the card */
1182 memset(local
->sparm
.b5
.a_current_ess_id
, 0, IW_ESSID_MAX_SIZE
);
1183 memcpy(local
->sparm
.b5
.a_current_ess_id
, extra
, dwrq
->length
);
1186 return -EINPROGRESS
; /* Call commit handler */
1189 /*------------------------------------------------------------------*/
1191 * Wireless Handler : get ESSID
1193 static int ray_get_essid(struct net_device
*dev
,
1194 struct iw_request_info
*info
,
1195 struct iw_point
*dwrq
, char *extra
)
1197 ray_dev_t
*local
= netdev_priv(dev
);
1199 /* Get the essid that was set */
1200 memcpy(extra
, local
->sparm
.b5
.a_current_ess_id
, IW_ESSID_MAX_SIZE
);
1203 dwrq
->length
= strlen(extra
);
1204 dwrq
->flags
= 1; /* active */
1209 /*------------------------------------------------------------------*/
1211 * Wireless Handler : get AP address
1213 static int ray_get_wap(struct net_device
*dev
,
1214 struct iw_request_info
*info
,
1215 struct sockaddr
*awrq
, char *extra
)
1217 ray_dev_t
*local
= netdev_priv(dev
);
1219 memcpy(awrq
->sa_data
, local
->bss_id
, ETH_ALEN
);
1220 awrq
->sa_family
= ARPHRD_ETHER
;
1225 /*------------------------------------------------------------------*/
1227 * Wireless Handler : set Bit-Rate
1229 static int ray_set_rate(struct net_device
*dev
,
1230 struct iw_request_info
*info
,
1231 struct iw_param
*vwrq
, char *extra
)
1233 ray_dev_t
*local
= netdev_priv(dev
);
1235 /* Reject if card is already initialised */
1236 if (local
->card_status
!= CARD_AWAITING_PARAM
)
1239 /* Check if rate is in range */
1240 if ((vwrq
->value
!= 1000000) && (vwrq
->value
!= 2000000))
1243 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
1244 if ((local
->fw_ver
== 0x55) && /* Please check */
1245 (vwrq
->value
== 2000000))
1246 local
->net_default_tx_rate
= 3;
1248 local
->net_default_tx_rate
= vwrq
->value
/ 500000;
1253 /*------------------------------------------------------------------*/
1255 * Wireless Handler : get Bit-Rate
1257 static int ray_get_rate(struct net_device
*dev
,
1258 struct iw_request_info
*info
,
1259 struct iw_param
*vwrq
, char *extra
)
1261 ray_dev_t
*local
= netdev_priv(dev
);
1263 if (local
->net_default_tx_rate
== 3)
1264 vwrq
->value
= 2000000; /* Hum... */
1266 vwrq
->value
= local
->net_default_tx_rate
* 500000;
1267 vwrq
->fixed
= 0; /* We are in auto mode */
1272 /*------------------------------------------------------------------*/
1274 * Wireless Handler : set RTS threshold
1276 static int ray_set_rts(struct net_device
*dev
,
1277 struct iw_request_info
*info
,
1278 struct iw_param
*vwrq
, char *extra
)
1280 ray_dev_t
*local
= netdev_priv(dev
);
1281 int rthr
= vwrq
->value
;
1283 /* Reject if card is already initialised */
1284 if (local
->card_status
!= CARD_AWAITING_PARAM
)
1287 /* if(wrq->u.rts.fixed == 0) we should complain */
1291 if ((rthr
< 0) || (rthr
> 2347)) /* What's the max packet size ??? */
1294 local
->sparm
.b5
.a_rts_threshold
[0] = (rthr
>> 8) & 0xFF;
1295 local
->sparm
.b5
.a_rts_threshold
[1] = rthr
& 0xFF;
1297 return -EINPROGRESS
; /* Call commit handler */
1300 /*------------------------------------------------------------------*/
1302 * Wireless Handler : get RTS threshold
1304 static int ray_get_rts(struct net_device
*dev
,
1305 struct iw_request_info
*info
,
1306 struct iw_param
*vwrq
, char *extra
)
1308 ray_dev_t
*local
= netdev_priv(dev
);
1310 vwrq
->value
= (local
->sparm
.b5
.a_rts_threshold
[0] << 8)
1311 + local
->sparm
.b5
.a_rts_threshold
[1];
1312 vwrq
->disabled
= (vwrq
->value
== 32767);
1318 /*------------------------------------------------------------------*/
1320 * Wireless Handler : set Fragmentation threshold
1322 static int ray_set_frag(struct net_device
*dev
,
1323 struct iw_request_info
*info
,
1324 struct iw_param
*vwrq
, char *extra
)
1326 ray_dev_t
*local
= netdev_priv(dev
);
1327 int fthr
= vwrq
->value
;
1329 /* Reject if card is already initialised */
1330 if (local
->card_status
!= CARD_AWAITING_PARAM
)
1333 /* if(wrq->u.frag.fixed == 0) should complain */
1337 if ((fthr
< 256) || (fthr
> 2347)) /* To check out ! */
1340 local
->sparm
.b5
.a_frag_threshold
[0] = (fthr
>> 8) & 0xFF;
1341 local
->sparm
.b5
.a_frag_threshold
[1] = fthr
& 0xFF;
1343 return -EINPROGRESS
; /* Call commit handler */
1346 /*------------------------------------------------------------------*/
1348 * Wireless Handler : get Fragmentation threshold
1350 static int ray_get_frag(struct net_device
*dev
,
1351 struct iw_request_info
*info
,
1352 struct iw_param
*vwrq
, char *extra
)
1354 ray_dev_t
*local
= netdev_priv(dev
);
1356 vwrq
->value
= (local
->sparm
.b5
.a_frag_threshold
[0] << 8)
1357 + local
->sparm
.b5
.a_frag_threshold
[1];
1358 vwrq
->disabled
= (vwrq
->value
== 32767);
1364 /*------------------------------------------------------------------*/
1366 * Wireless Handler : set Mode of Operation
1368 static int ray_set_mode(struct net_device
*dev
,
1369 struct iw_request_info
*info
, __u32
*uwrq
, char *extra
)
1371 ray_dev_t
*local
= netdev_priv(dev
);
1372 int err
= -EINPROGRESS
; /* Call commit handler */
1375 /* Reject if card is already initialised */
1376 if (local
->card_status
!= CARD_AWAITING_PARAM
)
1384 local
->sparm
.b5
.a_network_type
= card_mode
;
1393 /*------------------------------------------------------------------*/
1395 * Wireless Handler : get Mode of Operation
1397 static int ray_get_mode(struct net_device
*dev
,
1398 struct iw_request_info
*info
, __u32
*uwrq
, char *extra
)
1400 ray_dev_t
*local
= netdev_priv(dev
);
1402 if (local
->sparm
.b5
.a_network_type
)
1403 *uwrq
= IW_MODE_INFRA
;
1405 *uwrq
= IW_MODE_ADHOC
;
1410 /*------------------------------------------------------------------*/
1412 * Wireless Handler : get range info
1414 static int ray_get_range(struct net_device
*dev
,
1415 struct iw_request_info
*info
,
1416 struct iw_point
*dwrq
, char *extra
)
1418 struct iw_range
*range
= (struct iw_range
*)extra
;
1420 memset((char *)range
, 0, sizeof(struct iw_range
));
1422 /* Set the length (very important for backward compatibility) */
1423 dwrq
->length
= sizeof(struct iw_range
);
1425 /* Set the Wireless Extension versions */
1426 range
->we_version_compiled
= WIRELESS_EXT
;
1427 range
->we_version_source
= 9;
1429 /* Set information in the range struct */
1430 range
->throughput
= 1.1 * 1000 * 1000; /* Put the right number here */
1431 range
->num_channels
= hop_pattern_length
[(int)country
];
1432 range
->num_frequency
= 0;
1433 range
->max_qual
.qual
= 0;
1434 range
->max_qual
.level
= 255; /* What's the correct value ? */
1435 range
->max_qual
.noise
= 255; /* Idem */
1436 range
->num_bitrates
= 2;
1437 range
->bitrate
[0] = 1000000; /* 1 Mb/s */
1438 range
->bitrate
[1] = 2000000; /* 2 Mb/s */
1442 /*------------------------------------------------------------------*/
1444 * Wireless Private Handler : set framing mode
1446 static int ray_set_framing(struct net_device
*dev
,
1447 struct iw_request_info
*info
,
1448 union iwreq_data
*wrqu
, char *extra
)
1450 translate
= *(extra
); /* Set framing mode */
1455 /*------------------------------------------------------------------*/
1457 * Wireless Private Handler : get framing mode
1459 static int ray_get_framing(struct net_device
*dev
,
1460 struct iw_request_info
*info
,
1461 union iwreq_data
*wrqu
, char *extra
)
1463 *(extra
) = translate
;
1468 /*------------------------------------------------------------------*/
1470 * Wireless Private Handler : get country
1472 static int ray_get_country(struct net_device
*dev
,
1473 struct iw_request_info
*info
,
1474 union iwreq_data
*wrqu
, char *extra
)
1481 /*------------------------------------------------------------------*/
1483 * Commit handler : called after a bunch of SET operations
1485 static int ray_commit(struct net_device
*dev
, struct iw_request_info
*info
, /* NULL */
1486 void *zwrq
, /* NULL */
1492 /*------------------------------------------------------------------*/
1494 * Stats handler : return Wireless Stats
1496 static iw_stats
*ray_get_wireless_stats(struct net_device
*dev
)
1498 ray_dev_t
*local
= netdev_priv(dev
);
1499 struct pcmcia_device
*link
= local
->finder
;
1500 struct status __iomem
*p
= local
->sram
+ STATUS_BASE
;
1502 local
->wstats
.status
= local
->card_status
;
1504 if ((local
->spy_data
.spy_number
> 0)
1505 && (local
->sparm
.b5
.a_network_type
== 0)) {
1506 /* Get it from the first node in spy list */
1507 local
->wstats
.qual
.qual
= local
->spy_data
.spy_stat
[0].qual
;
1508 local
->wstats
.qual
.level
= local
->spy_data
.spy_stat
[0].level
;
1509 local
->wstats
.qual
.noise
= local
->spy_data
.spy_stat
[0].noise
;
1510 local
->wstats
.qual
.updated
=
1511 local
->spy_data
.spy_stat
[0].updated
;
1513 #endif /* WIRELESS_SPY */
1515 if (pcmcia_dev_present(link
)) {
1516 local
->wstats
.qual
.noise
= readb(&p
->rxnoise
);
1517 local
->wstats
.qual
.updated
|= 4;
1520 return &local
->wstats
;
1521 } /* end ray_get_wireless_stats */
1523 /*------------------------------------------------------------------*/
1525 * Structures to export the Wireless Handlers
1528 static const iw_handler ray_handler
[] = {
1529 [SIOCSIWCOMMIT
- SIOCIWFIRST
] = (iw_handler
) ray_commit
,
1530 [SIOCGIWNAME
- SIOCIWFIRST
] = (iw_handler
) ray_get_name
,
1531 [SIOCSIWFREQ
- SIOCIWFIRST
] = (iw_handler
) ray_set_freq
,
1532 [SIOCGIWFREQ
- SIOCIWFIRST
] = (iw_handler
) ray_get_freq
,
1533 [SIOCSIWMODE
- SIOCIWFIRST
] = (iw_handler
) ray_set_mode
,
1534 [SIOCGIWMODE
- SIOCIWFIRST
] = (iw_handler
) ray_get_mode
,
1535 [SIOCGIWRANGE
- SIOCIWFIRST
] = (iw_handler
) ray_get_range
,
1537 [SIOCSIWSPY
- SIOCIWFIRST
] = (iw_handler
) iw_handler_set_spy
,
1538 [SIOCGIWSPY
- SIOCIWFIRST
] = (iw_handler
) iw_handler_get_spy
,
1539 [SIOCSIWTHRSPY
- SIOCIWFIRST
] = (iw_handler
) iw_handler_set_thrspy
,
1540 [SIOCGIWTHRSPY
- SIOCIWFIRST
] = (iw_handler
) iw_handler_get_thrspy
,
1541 #endif /* WIRELESS_SPY */
1542 [SIOCGIWAP
- SIOCIWFIRST
] = (iw_handler
) ray_get_wap
,
1543 [SIOCSIWESSID
- SIOCIWFIRST
] = (iw_handler
) ray_set_essid
,
1544 [SIOCGIWESSID
- SIOCIWFIRST
] = (iw_handler
) ray_get_essid
,
1545 [SIOCSIWRATE
- SIOCIWFIRST
] = (iw_handler
) ray_set_rate
,
1546 [SIOCGIWRATE
- SIOCIWFIRST
] = (iw_handler
) ray_get_rate
,
1547 [SIOCSIWRTS
- SIOCIWFIRST
] = (iw_handler
) ray_set_rts
,
1548 [SIOCGIWRTS
- SIOCIWFIRST
] = (iw_handler
) ray_get_rts
,
1549 [SIOCSIWFRAG
- SIOCIWFIRST
] = (iw_handler
) ray_set_frag
,
1550 [SIOCGIWFRAG
- SIOCIWFIRST
] = (iw_handler
) ray_get_frag
,
1553 #define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
1554 #define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1555 #define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1557 static const iw_handler ray_private_handler
[] = {
1558 [0] = (iw_handler
) ray_set_framing
,
1559 [1] = (iw_handler
) ray_get_framing
,
1560 [3] = (iw_handler
) ray_get_country
,
1563 static const struct iw_priv_args ray_private_args
[] = {
1564 /* cmd, set_args, get_args, name */
1565 {SIOCSIPFRAMING
, IW_PRIV_TYPE_BYTE
| IW_PRIV_SIZE_FIXED
| 1, 0,
1567 {SIOCGIPFRAMING
, 0, IW_PRIV_TYPE_BYTE
| IW_PRIV_SIZE_FIXED
| 1,
1569 {SIOCGIPCOUNTRY
, 0, IW_PRIV_TYPE_BYTE
| IW_PRIV_SIZE_FIXED
| 1,
1573 static const struct iw_handler_def ray_handler_def
= {
1574 .num_standard
= ARRAY_SIZE(ray_handler
),
1575 .num_private
= ARRAY_SIZE(ray_private_handler
),
1576 .num_private_args
= ARRAY_SIZE(ray_private_args
),
1577 .standard
= ray_handler
,
1578 .private = ray_private_handler
,
1579 .private_args
= ray_private_args
,
1580 .get_wireless_stats
= ray_get_wireless_stats
,
1583 /*===========================================================================*/
1584 static int ray_open(struct net_device
*dev
)
1586 ray_dev_t
*local
= netdev_priv(dev
);
1587 struct pcmcia_device
*link
;
1588 link
= local
->finder
;
1590 dev_dbg(&link
->dev
, "ray_open('%s')\n", dev
->name
);
1592 if (link
->open
== 0)
1593 local
->num_multi
= 0;
1596 /* If the card is not started, time to start it ! - Jean II */
1597 if (local
->card_status
== CARD_AWAITING_PARAM
) {
1600 dev_dbg(&link
->dev
, "ray_open: doing init now !\n");
1602 /* Download startup parameters */
1603 if ((i
= dl_startup_params(dev
)) < 0) {
1605 "ray_dev_init dl_startup_params failed - "
1606 "returns 0x%x\n", i
);
1612 netif_stop_queue(dev
);
1614 netif_start_queue(dev
);
1616 dev_dbg(&link
->dev
, "ray_open ending\n");
1618 } /* end ray_open */
1620 /*===========================================================================*/
1621 static int ray_dev_close(struct net_device
*dev
)
1623 ray_dev_t
*local
= netdev_priv(dev
);
1624 struct pcmcia_device
*link
;
1625 link
= local
->finder
;
1627 dev_dbg(&link
->dev
, "ray_dev_close('%s')\n", dev
->name
);
1630 netif_stop_queue(dev
);
1632 /* In here, we should stop the hardware (stop card from beeing active)
1633 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1634 * card is closed we can chage its configuration.
1635 * Probably also need a COR reset to get sane state - Jean II */
1638 } /* end ray_dev_close */
1640 /*===========================================================================*/
1641 static void ray_reset(struct net_device
*dev
)
1643 pr_debug("ray_reset entered\n");
1647 /*===========================================================================*/
1648 /* Cause a firmware interrupt if it is ready for one */
1649 /* Return nonzero if not ready */
1650 static int interrupt_ecf(ray_dev_t
*local
, int ccs
)
1653 struct pcmcia_device
*link
= local
->finder
;
1655 if (!(pcmcia_dev_present(link
))) {
1656 dev_dbg(&link
->dev
, "ray_cs interrupt_ecf - device not present\n");
1659 dev_dbg(&link
->dev
, "interrupt_ecf(local=%p, ccs = 0x%x\n", local
, ccs
);
1662 (readb(local
->amem
+ CIS_OFFSET
+ ECF_INTR_OFFSET
) &
1666 dev_dbg(&link
->dev
, "ray_cs interrupt_ecf card not ready for interrupt\n");
1669 /* Fill the mailbox, then kick the card */
1670 writeb(ccs
, local
->sram
+ SCB_BASE
);
1671 writeb(ECF_INTR_SET
, local
->amem
+ CIS_OFFSET
+ ECF_INTR_OFFSET
);
1673 } /* interrupt_ecf */
1675 /*===========================================================================*/
1676 /* Get next free transmit CCS */
1677 /* Return - index of current tx ccs */
1678 static int get_free_tx_ccs(ray_dev_t
*local
)
1681 struct ccs __iomem
*pccs
= ccs_base(local
);
1682 struct pcmcia_device
*link
= local
->finder
;
1684 if (!(pcmcia_dev_present(link
))) {
1685 dev_dbg(&link
->dev
, "ray_cs get_free_tx_ccs - device not present\n");
1689 if (test_and_set_bit(0, &local
->tx_ccs_lock
)) {
1690 dev_dbg(&link
->dev
, "ray_cs tx_ccs_lock busy\n");
1694 for (i
= 0; i
< NUMBER_OF_TX_CCS
; i
++) {
1695 if (readb(&(pccs
+ i
)->buffer_status
) == CCS_BUFFER_FREE
) {
1696 writeb(CCS_BUFFER_BUSY
, &(pccs
+ i
)->buffer_status
);
1697 writeb(CCS_END_LIST
, &(pccs
+ i
)->link
);
1698 local
->tx_ccs_lock
= 0;
1702 local
->tx_ccs_lock
= 0;
1703 dev_dbg(&link
->dev
, "ray_cs ERROR no free tx CCS for raylink card\n");
1705 } /* get_free_tx_ccs */
1707 /*===========================================================================*/
1708 /* Get next free CCS */
1709 /* Return - index of current ccs */
1710 static int get_free_ccs(ray_dev_t
*local
)
1713 struct ccs __iomem
*pccs
= ccs_base(local
);
1714 struct pcmcia_device
*link
= local
->finder
;
1716 if (!(pcmcia_dev_present(link
))) {
1717 dev_dbg(&link
->dev
, "ray_cs get_free_ccs - device not present\n");
1720 if (test_and_set_bit(0, &local
->ccs_lock
)) {
1721 dev_dbg(&link
->dev
, "ray_cs ccs_lock busy\n");
1725 for (i
= NUMBER_OF_TX_CCS
; i
< NUMBER_OF_CCS
; i
++) {
1726 if (readb(&(pccs
+ i
)->buffer_status
) == CCS_BUFFER_FREE
) {
1727 writeb(CCS_BUFFER_BUSY
, &(pccs
+ i
)->buffer_status
);
1728 writeb(CCS_END_LIST
, &(pccs
+ i
)->link
);
1729 local
->ccs_lock
= 0;
1733 local
->ccs_lock
= 0;
1734 dev_dbg(&link
->dev
, "ray_cs ERROR no free CCS for raylink card\n");
1736 } /* get_free_ccs */
1738 /*===========================================================================*/
1739 static void authenticate_timeout(u_long data
)
1741 ray_dev_t
*local
= (ray_dev_t
*) data
;
1742 del_timer(&local
->timer
);
1743 printk(KERN_INFO
"ray_cs Authentication with access point failed"
1745 join_net((u_long
) local
);
1748 /*===========================================================================*/
1749 static int asc_to_int(char a
)
1758 return (10 + a
- 'A');
1762 return (10 + a
- 'a');
1766 /*===========================================================================*/
1767 static int parse_addr(char *in_str
, UCHAR
*out
)
1775 if ((len
= strlen(in_str
)) < 2)
1777 memset(out
, 0, ADDRLEN
);
1786 if ((k
= asc_to_int(in_str
[j
--])) != -1)
1793 if ((k
= asc_to_int(in_str
[j
--])) != -1)
1803 /*===========================================================================*/
1804 static struct net_device_stats
*ray_get_stats(struct net_device
*dev
)
1806 ray_dev_t
*local
= netdev_priv(dev
);
1807 struct pcmcia_device
*link
= local
->finder
;
1808 struct status __iomem
*p
= local
->sram
+ STATUS_BASE
;
1809 if (!(pcmcia_dev_present(link
))) {
1810 dev_dbg(&link
->dev
, "ray_cs net_device_stats - device not present\n");
1811 return &local
->stats
;
1813 if (readb(&p
->mrx_overflow_for_host
)) {
1814 local
->stats
.rx_over_errors
+= swab16(readw(&p
->mrx_overflow
));
1815 writeb(0, &p
->mrx_overflow
);
1816 writeb(0, &p
->mrx_overflow_for_host
);
1818 if (readb(&p
->mrx_checksum_error_for_host
)) {
1819 local
->stats
.rx_crc_errors
+=
1820 swab16(readw(&p
->mrx_checksum_error
));
1821 writeb(0, &p
->mrx_checksum_error
);
1822 writeb(0, &p
->mrx_checksum_error_for_host
);
1824 if (readb(&p
->rx_hec_error_for_host
)) {
1825 local
->stats
.rx_frame_errors
+= swab16(readw(&p
->rx_hec_error
));
1826 writeb(0, &p
->rx_hec_error
);
1827 writeb(0, &p
->rx_hec_error_for_host
);
1829 return &local
->stats
;
1832 /*===========================================================================*/
1833 static void ray_update_parm(struct net_device
*dev
, UCHAR objid
, UCHAR
*value
,
1836 ray_dev_t
*local
= netdev_priv(dev
);
1837 struct pcmcia_device
*link
= local
->finder
;
1840 struct ccs __iomem
*pccs
;
1842 if (!(pcmcia_dev_present(link
))) {
1843 dev_dbg(&link
->dev
, "ray_update_parm - device not present\n");
1847 if ((ccsindex
= get_free_ccs(local
)) < 0) {
1848 dev_dbg(&link
->dev
, "ray_update_parm - No free ccs\n");
1851 pccs
= ccs_base(local
) + ccsindex
;
1852 writeb(CCS_UPDATE_PARAMS
, &pccs
->cmd
);
1853 writeb(objid
, &pccs
->var
.update_param
.object_id
);
1854 writeb(1, &pccs
->var
.update_param
.number_objects
);
1855 writeb(0, &pccs
->var
.update_param
.failure_cause
);
1856 for (i
= 0; i
< len
; i
++) {
1857 writeb(value
[i
], local
->sram
+ HOST_TO_ECF_BASE
);
1859 /* Interrupt the firmware to process the command */
1860 if (interrupt_ecf(local
, ccsindex
)) {
1861 dev_dbg(&link
->dev
, "ray_cs associate failed - ECF not ready for intr\n");
1862 writeb(CCS_BUFFER_FREE
, &(pccs
++)->buffer_status
);
1866 /*===========================================================================*/
1867 static void ray_update_multi_list(struct net_device
*dev
, int all
)
1870 struct ccs __iomem
*pccs
;
1871 ray_dev_t
*local
= netdev_priv(dev
);
1872 struct pcmcia_device
*link
= local
->finder
;
1873 void __iomem
*p
= local
->sram
+ HOST_TO_ECF_BASE
;
1875 if (!(pcmcia_dev_present(link
))) {
1876 dev_dbg(&link
->dev
, "ray_update_multi_list - device not present\n");
1879 dev_dbg(&link
->dev
, "ray_update_multi_list(%p)\n", dev
);
1880 if ((ccsindex
= get_free_ccs(local
)) < 0) {
1881 dev_dbg(&link
->dev
, "ray_update_multi - No free ccs\n");
1884 pccs
= ccs_base(local
) + ccsindex
;
1885 writeb(CCS_UPDATE_MULTICAST_LIST
, &pccs
->cmd
);
1888 writeb(0xff, &pccs
->var
);
1889 local
->num_multi
= 0xff;
1891 struct dev_mc_list
*dmi
;
1894 /* Copy the kernel's list of MC addresses to card */
1895 netdev_for_each_mc_addr(dmi
, dev
) {
1896 memcpy_toio(p
, dmi
->dmi_addr
, ETH_ALEN
);
1898 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
1899 dmi
->dmi_addr
[0], dmi
->dmi_addr
[1],
1900 dmi
->dmi_addr
[2], dmi
->dmi_addr
[3],
1901 dmi
->dmi_addr
[4], dmi
->dmi_addr
[5]);
1905 if (i
> 256 / ADDRLEN
)
1907 writeb((UCHAR
) i
, &pccs
->var
);
1908 dev_dbg(&link
->dev
, "ray_cs update_multi %d addresses in list\n", i
);
1909 /* Interrupt the firmware to process the command */
1910 local
->num_multi
= i
;
1912 if (interrupt_ecf(local
, ccsindex
)) {
1914 "ray_cs update_multi failed - ECF not ready for intr\n");
1915 writeb(CCS_BUFFER_FREE
, &(pccs
++)->buffer_status
);
1917 } /* end ray_update_multi_list */
1919 /*===========================================================================*/
1920 static void set_multicast_list(struct net_device
*dev
)
1922 ray_dev_t
*local
= netdev_priv(dev
);
1925 pr_debug("ray_cs set_multicast_list(%p)\n", dev
);
1927 if (dev
->flags
& IFF_PROMISC
) {
1928 if (local
->sparm
.b5
.a_promiscuous_mode
== 0) {
1929 pr_debug("ray_cs set_multicast_list promisc on\n");
1930 local
->sparm
.b5
.a_promiscuous_mode
= 1;
1932 ray_update_parm(dev
, OBJID_promiscuous_mode
,
1933 &promisc
, sizeof(promisc
));
1936 if (local
->sparm
.b5
.a_promiscuous_mode
== 1) {
1937 pr_debug("ray_cs set_multicast_list promisc off\n");
1938 local
->sparm
.b5
.a_promiscuous_mode
= 0;
1940 ray_update_parm(dev
, OBJID_promiscuous_mode
,
1941 &promisc
, sizeof(promisc
));
1945 if (dev
->flags
& IFF_ALLMULTI
)
1946 ray_update_multi_list(dev
, 1);
1948 if (local
->num_multi
!= netdev_mc_count(dev
))
1949 ray_update_multi_list(dev
, 0);
1951 } /* end set_multicast_list */
1953 /*=============================================================================
1954 * All routines below here are run at interrupt time.
1955 =============================================================================*/
1956 static irqreturn_t
ray_interrupt(int irq
, void *dev_id
)
1958 struct net_device
*dev
= (struct net_device
*)dev_id
;
1959 struct pcmcia_device
*link
;
1961 struct ccs __iomem
*pccs
;
1962 struct rcs __iomem
*prcs
;
1968 if (dev
== NULL
) /* Note that we want interrupts with dev->start == 0 */
1971 pr_debug("ray_cs: interrupt for *dev=%p\n", dev
);
1973 local
= netdev_priv(dev
);
1974 link
= (struct pcmcia_device
*)local
->finder
;
1975 if (!pcmcia_dev_present(link
)) {
1977 "ray_cs interrupt from device not present or suspended.\n");
1980 rcsindex
= readb(&((struct scb __iomem
*)(local
->sram
))->rcs_index
);
1982 if (rcsindex
>= (NUMBER_OF_CCS
+ NUMBER_OF_RCS
)) {
1983 dev_dbg(&link
->dev
, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex
);
1984 clear_interrupt(local
);
1987 if (rcsindex
< NUMBER_OF_CCS
) { /* If it's a returned CCS */
1988 pccs
= ccs_base(local
) + rcsindex
;
1989 cmd
= readb(&pccs
->cmd
);
1990 status
= readb(&pccs
->buffer_status
);
1992 case CCS_DOWNLOAD_STARTUP_PARAMS
: /* Happens in firmware someday */
1993 del_timer(&local
->timer
);
1994 if (status
== CCS_COMMAND_COMPLETE
) {
1996 "ray_cs interrupt download_startup_parameters OK\n");
1999 "ray_cs interrupt download_startup_parameters fail\n");
2002 case CCS_UPDATE_PARAMS
:
2003 dev_dbg(&link
->dev
, "ray_cs interrupt update params done\n");
2004 if (status
!= CCS_COMMAND_COMPLETE
) {
2006 readb(&pccs
->var
.update_param
.
2009 "ray_cs interrupt update params failed - reason %d\n",
2013 case CCS_REPORT_PARAMS
:
2014 dev_dbg(&link
->dev
, "ray_cs interrupt report params done\n");
2016 case CCS_UPDATE_MULTICAST_LIST
: /* Note that this CCS isn't returned */
2018 "ray_cs interrupt CCS Update Multicast List done\n");
2020 case CCS_UPDATE_POWER_SAVINGS_MODE
:
2022 "ray_cs interrupt update power save mode done\n");
2024 case CCS_START_NETWORK
:
2025 case CCS_JOIN_NETWORK
:
2026 if (status
== CCS_COMMAND_COMPLETE
) {
2028 (&pccs
->var
.start_network
.net_initiated
) ==
2031 "ray_cs interrupt network \"%s\" started\n",
2032 local
->sparm
.b4
.a_current_ess_id
);
2035 "ray_cs interrupt network \"%s\" joined\n",
2036 local
->sparm
.b4
.a_current_ess_id
);
2038 memcpy_fromio(&local
->bss_id
,
2039 pccs
->var
.start_network
.bssid
,
2042 if (local
->fw_ver
== 0x55)
2043 local
->net_default_tx_rate
= 3;
2045 local
->net_default_tx_rate
=
2046 readb(&pccs
->var
.start_network
.
2047 net_default_tx_rate
);
2049 readb(&pccs
->var
.start_network
.encryption
);
2050 if (!sniffer
&& (local
->net_type
== INFRA
)
2051 && !(local
->sparm
.b4
.a_acting_as_ap_status
)) {
2052 authenticate(local
);
2054 local
->card_status
= CARD_ACQ_COMPLETE
;
2056 local
->card_status
= CARD_ACQ_FAILED
;
2058 del_timer(&local
->timer
);
2059 local
->timer
.expires
= jiffies
+ HZ
* 5;
2060 local
->timer
.data
= (long)local
;
2061 if (status
== CCS_START_NETWORK
) {
2063 "ray_cs interrupt network \"%s\" start failed\n",
2064 local
->sparm
.b4
.a_current_ess_id
);
2065 local
->timer
.function
= &start_net
;
2068 "ray_cs interrupt network \"%s\" join failed\n",
2069 local
->sparm
.b4
.a_current_ess_id
);
2070 local
->timer
.function
= &join_net
;
2072 add_timer(&local
->timer
);
2075 case CCS_START_ASSOCIATION
:
2076 if (status
== CCS_COMMAND_COMPLETE
) {
2077 local
->card_status
= CARD_ASSOC_COMPLETE
;
2078 dev_dbg(&link
->dev
, "ray_cs association successful\n");
2080 dev_dbg(&link
->dev
, "ray_cs association failed,\n");
2081 local
->card_status
= CARD_ASSOC_FAILED
;
2082 join_net((u_long
) local
);
2085 case CCS_TX_REQUEST
:
2086 if (status
== CCS_COMMAND_COMPLETE
) {
2088 "ray_cs interrupt tx request complete\n");
2091 "ray_cs interrupt tx request failed\n");
2094 netif_start_queue(dev
);
2095 netif_wake_queue(dev
);
2097 case CCS_TEST_MEMORY
:
2098 dev_dbg(&link
->dev
, "ray_cs interrupt mem test done\n");
2102 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2104 case CCS_DUMP_MEMORY
:
2105 dev_dbg(&link
->dev
, "ray_cs interrupt dump memory done\n");
2107 case CCS_START_TIMER
:
2109 "ray_cs interrupt DING - raylink timer expired\n");
2113 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2116 writeb(CCS_BUFFER_FREE
, &pccs
->buffer_status
);
2117 } else { /* It's an RCS */
2119 prcs
= rcs_base(local
) + rcsindex
;
2121 switch (readb(&prcs
->interrupt_id
)) {
2122 case PROCESS_RX_PACKET
:
2123 ray_rx(dev
, local
, prcs
);
2125 case REJOIN_NET_COMPLETE
:
2126 dev_dbg(&link
->dev
, "ray_cs interrupt rejoin net complete\n");
2127 local
->card_status
= CARD_ACQ_COMPLETE
;
2128 /* do we need to clear tx buffers CCS's? */
2129 if (local
->sparm
.b4
.a_network_type
== ADHOC
) {
2131 netif_start_queue(dev
);
2133 memcpy_fromio(&local
->bss_id
,
2134 prcs
->var
.rejoin_net_complete
.
2137 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2138 local
->bss_id
[0], local
->bss_id
[1],
2139 local
->bss_id
[2], local
->bss_id
[3],
2140 local
->bss_id
[4], local
->bss_id
[5]);
2142 authenticate(local
);
2145 case ROAMING_INITIATED
:
2146 dev_dbg(&link
->dev
, "ray_cs interrupt roaming initiated\n");
2147 netif_stop_queue(dev
);
2148 local
->card_status
= CARD_DOING_ACQ
;
2150 case JAPAN_CALL_SIGN_RXD
:
2151 dev_dbg(&link
->dev
, "ray_cs interrupt japan call sign rx\n");
2155 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2157 (unsigned int)readb(&prcs
->interrupt_id
));
2160 writeb(CCS_BUFFER_FREE
, &prcs
->buffer_status
);
2162 clear_interrupt(local
);
2164 } /* ray_interrupt */
2166 /*===========================================================================*/
2167 static void ray_rx(struct net_device
*dev
, ray_dev_t
*local
,
2168 struct rcs __iomem
*prcs
)
2171 unsigned int pkt_addr
;
2173 pr_debug("ray_rx process rx packet\n");
2175 /* Calculate address of packet within Rx buffer */
2176 pkt_addr
= ((readb(&prcs
->var
.rx_packet
.rx_data_ptr
[0]) << 8)
2177 + readb(&prcs
->var
.rx_packet
.rx_data_ptr
[1])) & RX_BUFF_END
;
2178 /* Length of first packet fragment */
2179 rx_len
= (readb(&prcs
->var
.rx_packet
.rx_data_length
[0]) << 8)
2180 + readb(&prcs
->var
.rx_packet
.rx_data_length
[1]);
2182 local
->last_rsl
= readb(&prcs
->var
.rx_packet
.rx_sig_lev
);
2183 pmsg
= local
->rmem
+ pkt_addr
;
2184 switch (readb(pmsg
)) {
2186 pr_debug("ray_rx data type\n");
2187 rx_data(dev
, prcs
, pkt_addr
, rx_len
);
2189 case AUTHENTIC_TYPE
:
2190 pr_debug("ray_rx authentic type\n");
2192 rx_data(dev
, prcs
, pkt_addr
, rx_len
);
2194 rx_authenticate(local
, prcs
, pkt_addr
, rx_len
);
2196 case DEAUTHENTIC_TYPE
:
2197 pr_debug("ray_rx deauth type\n");
2199 rx_data(dev
, prcs
, pkt_addr
, rx_len
);
2201 rx_deauthenticate(local
, prcs
, pkt_addr
, rx_len
);
2204 pr_debug("ray_cs rx NULL msg\n");
2207 pr_debug("ray_rx beacon type\n");
2209 rx_data(dev
, prcs
, pkt_addr
, rx_len
);
2211 copy_from_rx_buff(local
, (UCHAR
*) &local
->last_bcn
, pkt_addr
,
2212 rx_len
< sizeof(struct beacon_rx
) ?
2213 rx_len
: sizeof(struct beacon_rx
));
2215 local
->beacon_rxed
= 1;
2216 /* Get the statistics so the card counters never overflow */
2220 pr_debug("ray_cs unknown pkt type %2x\n",
2221 (unsigned int)readb(pmsg
));
2227 /*===========================================================================*/
2228 static void rx_data(struct net_device
*dev
, struct rcs __iomem
*prcs
,
2229 unsigned int pkt_addr
, int rx_len
)
2231 struct sk_buff
*skb
= NULL
;
2232 struct rcs __iomem
*prcslink
= prcs
;
2233 ray_dev_t
*local
= netdev_priv(dev
);
2238 int siglev
= local
->last_rsl
;
2239 u_char linksrcaddr
[ETH_ALEN
]; /* Other end of the wireless link */
2244 /* TBD length needs fixing for translated header */
2245 if (rx_len
< (ETH_HLEN
+ RX_MAC_HEADER_LENGTH
) ||
2247 (dev
->mtu
+ RX_MAC_HEADER_LENGTH
+ ETH_HLEN
+
2250 "ray_cs invalid packet length %d received \n",
2254 } else { /* encapsulated ethernet */
2256 if (rx_len
< (ETH_HLEN
+ RX_MAC_HEADER_LENGTH
) ||
2258 (dev
->mtu
+ RX_MAC_HEADER_LENGTH
+ ETH_HLEN
+
2261 "ray_cs invalid packet length %d received \n",
2267 pr_debug("ray_cs rx_data packet\n");
2268 /* If fragmented packet, verify sizes of fragments add up */
2269 if (readb(&prcs
->var
.rx_packet
.next_frag_rcs_index
) != 0xFF) {
2270 pr_debug("ray_cs rx'ed fragment\n");
2271 tmp
= (readb(&prcs
->var
.rx_packet
.totalpacketlength
[0]) << 8)
2272 + readb(&prcs
->var
.rx_packet
.totalpacketlength
[1]);
2277 (readb(&prcslink
->var
.rx_packet
.rx_data_length
[0])
2279 + readb(&prcslink
->var
.rx_packet
.rx_data_length
[1]);
2280 if (readb(&prcslink
->var
.rx_packet
.next_frag_rcs_index
)
2283 prcslink
= rcs_base(local
)
2284 + readb(&prcslink
->link_field
);
2289 "ray_cs rx_data fragment lengths don't add up\n");
2290 local
->stats
.rx_dropped
++;
2291 release_frag_chain(local
, prcs
);
2294 } else { /* Single unfragmented packet */
2298 skb
= dev_alloc_skb(total_len
+ 5);
2300 pr_debug("ray_cs rx_data could not allocate skb\n");
2301 local
->stats
.rx_dropped
++;
2302 if (readb(&prcs
->var
.rx_packet
.next_frag_rcs_index
) != 0xFF)
2303 release_frag_chain(local
, prcs
);
2306 skb_reserve(skb
, 2); /* Align IP on 16 byte (TBD check this) */
2308 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len
,
2311 /************************/
2312 /* Reserve enough room for the whole damn packet. */
2313 rx_ptr
= skb_put(skb
, total_len
);
2314 /* Copy the whole packet to sk_buff */
2316 copy_from_rx_buff(local
, rx_ptr
, pkt_addr
& RX_BUFF_END
, rx_len
);
2317 /* Get source address */
2319 skb_copy_from_linear_data_offset(skb
,
2320 offsetof(struct mac_header
, addr_2
),
2321 linksrcaddr
, ETH_ALEN
);
2323 /* Now, deal with encapsulation/translation/sniffer */
2326 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
2327 /* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
2328 skb_pull(skb
, RX_MAC_HEADER_LENGTH
);
2330 /* Do translation */
2331 untranslate(local
, skb
, total_len
);
2333 } else { /* sniffer mode, so just pass whole packet */
2336 /************************/
2337 /* Now pick up the rest of the fragments if any */
2339 if (readb(&prcs
->var
.rx_packet
.next_frag_rcs_index
) != 0xFF) {
2341 pr_debug("ray_cs rx_data in fragment loop\n");
2343 prcslink
= rcs_base(local
)
2345 readb(&prcslink
->var
.rx_packet
.next_frag_rcs_index
);
2347 ((readb(&prcslink
->var
.rx_packet
.rx_data_length
[0])
2350 readb(&prcslink
->var
.rx_packet
.rx_data_length
[1]))
2353 ((readb(&prcslink
->var
.rx_packet
.rx_data_ptr
[0]) <<
2355 + readb(&prcslink
->var
.rx_packet
.rx_data_ptr
[1]))
2359 copy_from_rx_buff(local
, rx_ptr
, pkt_addr
, rx_len
);
2362 readb(&prcslink
->var
.rx_packet
.next_frag_rcs_index
) !=
2364 release_frag_chain(local
, prcs
);
2367 skb
->protocol
= eth_type_trans(skb
, dev
);
2369 local
->stats
.rx_packets
++;
2370 local
->stats
.rx_bytes
+= total_len
;
2372 /* Gather signal strength per address */
2374 /* For the Access Point or the node having started the ad-hoc net
2375 * note : ad-hoc work only in some specific configurations, but we
2376 * kludge in ray_get_wireless_stats... */
2377 if (!memcmp(linksrcaddr
, local
->bss_id
, ETH_ALEN
)) {
2378 /* Update statistics */
2379 /*local->wstats.qual.qual = none ? */
2380 local
->wstats
.qual
.level
= siglev
;
2381 /*local->wstats.qual.noise = none ? */
2382 local
->wstats
.qual
.updated
= 0x2;
2384 /* Now, update the spy stuff */
2386 struct iw_quality wstats
;
2387 wstats
.level
= siglev
;
2388 /* wstats.noise = none ? */
2389 /* wstats.qual = none ? */
2390 wstats
.updated
= 0x2;
2391 /* Update spy records */
2392 wireless_spy_update(dev
, linksrcaddr
, &wstats
);
2394 #endif /* WIRELESS_SPY */
2397 /*===========================================================================*/
2398 static void untranslate(ray_dev_t
*local
, struct sk_buff
*skb
, int len
)
2400 snaphdr_t
*psnap
= (snaphdr_t
*) (skb
->data
+ RX_MAC_HEADER_LENGTH
);
2401 struct ieee80211_hdr
*pmac
= (struct ieee80211_hdr
*)skb
->data
;
2402 __be16 type
= *(__be16
*) psnap
->ethertype
;
2404 struct ethhdr
*peth
;
2405 UCHAR srcaddr
[ADDRLEN
];
2406 UCHAR destaddr
[ADDRLEN
];
2407 static UCHAR org_bridge
[3] = { 0, 0, 0xf8 };
2408 static UCHAR org_1042
[3] = { 0, 0, 0 };
2410 memcpy(destaddr
, ieee80211_get_DA(pmac
), ADDRLEN
);
2411 memcpy(srcaddr
, ieee80211_get_SA(pmac
), ADDRLEN
);
2415 print_hex_dump(KERN_DEBUG
, "skb->data before untranslate: ",
2416 DUMP_PREFIX_NONE
, 16, 1,
2417 skb
->data
, 64, true);
2419 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2420 ntohs(type
), psnap
->dsap
, psnap
->ssap
, psnap
->ctrl
,
2421 psnap
->org
[0], psnap
->org
[1], psnap
->org
[2]);
2422 printk(KERN_DEBUG
"untranslate skb->data = %p\n", skb
->data
);
2426 if (psnap
->dsap
!= 0xaa || psnap
->ssap
!= 0xaa || psnap
->ctrl
!= 3) {
2427 /* not a snap type so leave it alone */
2428 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
2429 psnap
->dsap
, psnap
->ssap
, psnap
->ctrl
);
2431 delta
= RX_MAC_HEADER_LENGTH
- ETH_HLEN
;
2432 peth
= (struct ethhdr
*)(skb
->data
+ delta
);
2433 peth
->h_proto
= htons(len
- RX_MAC_HEADER_LENGTH
);
2434 } else { /* Its a SNAP */
2435 if (memcmp(psnap
->org
, org_bridge
, 3) == 0) {
2436 /* EtherII and nuke the LLC */
2437 pr_debug("ray_cs untranslate Bridge encap\n");
2438 delta
= RX_MAC_HEADER_LENGTH
2439 + sizeof(struct snaphdr_t
) - ETH_HLEN
;
2440 peth
= (struct ethhdr
*)(skb
->data
+ delta
);
2441 peth
->h_proto
= type
;
2442 } else if (memcmp(psnap
->org
, org_1042
, 3) == 0) {
2443 switch (ntohs(type
)) {
2446 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
2447 delta
= RX_MAC_HEADER_LENGTH
- ETH_HLEN
;
2448 peth
= (struct ethhdr
*)(skb
->data
+ delta
);
2450 htons(len
- RX_MAC_HEADER_LENGTH
);
2453 pr_debug("ray_cs untranslate RFC default\n");
2454 delta
= RX_MAC_HEADER_LENGTH
+
2455 sizeof(struct snaphdr_t
) - ETH_HLEN
;
2456 peth
= (struct ethhdr
*)(skb
->data
+ delta
);
2457 peth
->h_proto
= type
;
2461 printk("ray_cs untranslate very confused by packet\n");
2462 delta
= RX_MAC_HEADER_LENGTH
- ETH_HLEN
;
2463 peth
= (struct ethhdr
*)(skb
->data
+ delta
);
2464 peth
->h_proto
= type
;
2467 /* TBD reserve skb_reserve(skb, delta); */
2468 skb_pull(skb
, delta
);
2469 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta
,
2471 memcpy(peth
->h_dest
, destaddr
, ADDRLEN
);
2472 memcpy(peth
->h_source
, srcaddr
, ADDRLEN
);
2476 printk(KERN_DEBUG
"skb->data after untranslate:");
2477 for (i
= 0; i
< 64; i
++)
2478 printk("%02x ", skb
->data
[i
]);
2482 } /* end untranslate */
2484 /*===========================================================================*/
2485 /* Copy data from circular receive buffer to PC memory.
2486 * dest = destination address in PC memory
2487 * pkt_addr = source address in receive buffer
2488 * len = length of packet to copy
2490 static int copy_from_rx_buff(ray_dev_t
*local
, UCHAR
*dest
, int pkt_addr
,
2493 int wrap_bytes
= (pkt_addr
+ length
) - (RX_BUFF_END
+ 1);
2494 if (wrap_bytes
<= 0) {
2495 memcpy_fromio(dest
, local
->rmem
+ pkt_addr
, length
);
2496 } else { /* Packet wrapped in circular buffer */
2498 memcpy_fromio(dest
, local
->rmem
+ pkt_addr
,
2499 length
- wrap_bytes
);
2500 memcpy_fromio(dest
+ length
- wrap_bytes
, local
->rmem
,
2506 /*===========================================================================*/
2507 static void release_frag_chain(ray_dev_t
*local
, struct rcs __iomem
*prcs
)
2509 struct rcs __iomem
*prcslink
= prcs
;
2511 unsigned rcsindex
= readb(&prcs
->var
.rx_packet
.next_frag_rcs_index
);
2514 writeb(CCS_BUFFER_FREE
, &prcslink
->buffer_status
);
2515 if (rcsindex
>= (NUMBER_OF_CCS
+ NUMBER_OF_RCS
)) {
2516 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
2520 prcslink
= rcs_base(local
) + rcsindex
;
2521 rcsindex
= readb(&prcslink
->var
.rx_packet
.next_frag_rcs_index
);
2523 writeb(CCS_BUFFER_FREE
, &prcslink
->buffer_status
);
2526 /*===========================================================================*/
2527 static void authenticate(ray_dev_t
*local
)
2529 struct pcmcia_device
*link
= local
->finder
;
2530 dev_dbg(&link
->dev
, "ray_cs Starting authentication.\n");
2531 if (!(pcmcia_dev_present(link
))) {
2532 dev_dbg(&link
->dev
, "ray_cs authenticate - device not present\n");
2536 del_timer(&local
->timer
);
2537 if (build_auth_frame(local
, local
->bss_id
, OPEN_AUTH_REQUEST
)) {
2538 local
->timer
.function
= &join_net
;
2540 local
->timer
.function
= &authenticate_timeout
;
2542 local
->timer
.expires
= jiffies
+ HZ
* 2;
2543 local
->timer
.data
= (long)local
;
2544 add_timer(&local
->timer
);
2545 local
->authentication_state
= AWAITING_RESPONSE
;
2546 } /* end authenticate */
2548 /*===========================================================================*/
2549 static void rx_authenticate(ray_dev_t
*local
, struct rcs __iomem
*prcs
,
2550 unsigned int pkt_addr
, int rx_len
)
2553 struct rx_msg
*msg
= (struct rx_msg
*)buff
;
2555 del_timer(&local
->timer
);
2557 copy_from_rx_buff(local
, buff
, pkt_addr
, rx_len
& 0xff);
2558 /* if we are trying to get authenticated */
2559 if (local
->sparm
.b4
.a_network_type
== ADHOC
) {
2560 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
2561 msg
->var
[0], msg
->var
[1], msg
->var
[2], msg
->var
[3],
2562 msg
->var
[4], msg
->var
[5]);
2563 if (msg
->var
[2] == 1) {
2564 pr_debug("ray_cs Sending authentication response.\n");
2565 if (!build_auth_frame
2566 (local
, msg
->mac
.addr_2
, OPEN_AUTH_RESPONSE
)) {
2567 local
->authentication_state
= NEED_TO_AUTH
;
2568 memcpy(local
->auth_id
, msg
->mac
.addr_2
,
2572 } else { /* Infrastructure network */
2574 if (local
->authentication_state
== AWAITING_RESPONSE
) {
2575 /* Verify authentication sequence #2 and success */
2576 if (msg
->var
[2] == 2) {
2577 if ((msg
->var
[3] | msg
->var
[4]) == 0) {
2578 pr_debug("Authentication successful\n");
2579 local
->card_status
= CARD_AUTH_COMPLETE
;
2581 local
->authentication_state
=
2584 pr_debug("Authentication refused\n");
2585 local
->card_status
= CARD_AUTH_REFUSED
;
2586 join_net((u_long
) local
);
2587 local
->authentication_state
=
2594 } /* end rx_authenticate */
2596 /*===========================================================================*/
2597 static void associate(ray_dev_t
*local
)
2599 struct ccs __iomem
*pccs
;
2600 struct pcmcia_device
*link
= local
->finder
;
2601 struct net_device
*dev
= link
->priv
;
2603 if (!(pcmcia_dev_present(link
))) {
2604 dev_dbg(&link
->dev
, "ray_cs associate - device not present\n");
2607 /* If no tx buffers available, return */
2608 if ((ccsindex
= get_free_ccs(local
)) < 0) {
2609 /* TBD should never be here but... what if we are? */
2610 dev_dbg(&link
->dev
, "ray_cs associate - No free ccs\n");
2613 dev_dbg(&link
->dev
, "ray_cs Starting association with access point\n");
2614 pccs
= ccs_base(local
) + ccsindex
;
2615 /* fill in the CCS */
2616 writeb(CCS_START_ASSOCIATION
, &pccs
->cmd
);
2617 /* Interrupt the firmware to process the command */
2618 if (interrupt_ecf(local
, ccsindex
)) {
2619 dev_dbg(&link
->dev
, "ray_cs associate failed - ECF not ready for intr\n");
2620 writeb(CCS_BUFFER_FREE
, &(pccs
++)->buffer_status
);
2622 del_timer(&local
->timer
);
2623 local
->timer
.expires
= jiffies
+ HZ
* 2;
2624 local
->timer
.data
= (long)local
;
2625 local
->timer
.function
= &join_net
;
2626 add_timer(&local
->timer
);
2627 local
->card_status
= CARD_ASSOC_FAILED
;
2631 netif_start_queue(dev
);
2633 } /* end associate */
2635 /*===========================================================================*/
2636 static void rx_deauthenticate(ray_dev_t
*local
, struct rcs __iomem
*prcs
,
2637 unsigned int pkt_addr
, int rx_len
)
2640 struct rx_msg *msg = (struct rx_msg *)buff;
2642 pr_debug("Deauthentication frame received\n");
2643 local
->authentication_state
= UNAUTHENTICATED
;
2644 /* Need to reauthenticate or rejoin depending on reason code */
2645 /* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2649 /*===========================================================================*/
2650 static void clear_interrupt(ray_dev_t
*local
)
2652 writeb(0, local
->amem
+ CIS_OFFSET
+ HCS_INTR_OFFSET
);
2655 /*===========================================================================*/
2656 #ifdef CONFIG_PROC_FS
2657 #define MAXDATA (PAGE_SIZE - 80)
2659 static char *card_status
[] = {
2660 "Card inserted - uninitialized", /* 0 */
2661 "Card not downloaded", /* 1 */
2662 "Waiting for download parameters", /* 2 */
2663 "Card doing acquisition", /* 3 */
2664 "Acquisition complete", /* 4 */
2665 "Authentication complete", /* 5 */
2666 "Association complete", /* 6 */
2667 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2668 "Card init error", /* 11 */
2669 "Download parameters error", /* 12 */
2671 "Acquisition failed", /* 14 */
2672 "Authentication refused", /* 15 */
2673 "Association failed" /* 16 */
2676 static char *nettype
[] = { "Adhoc", "Infra " };
2677 static char *framing
[] = { "Encapsulation", "Translation" }
2680 /*===========================================================================*/
2681 static int ray_cs_proc_show(struct seq_file
*m
, void *v
)
2683 /* Print current values which are not available via other means
2687 struct pcmcia_device
*link
;
2688 struct net_device
*dev
;
2691 struct freq_hop_element
*pfh
;
2697 dev
= (struct net_device
*)link
->priv
;
2700 local
= netdev_priv(dev
);
2704 seq_puts(m
, "Raylink Wireless LAN driver status\n");
2705 seq_printf(m
, "%s\n", rcsid
);
2706 /* build 4 does not report version, and field is 0x55 after memtest */
2707 seq_puts(m
, "Firmware version = ");
2708 if (local
->fw_ver
== 0x55)
2709 seq_puts(m
, "4 - Use dump_cis for more details\n");
2711 seq_printf(m
, "%2d.%02d.%02d\n",
2712 local
->fw_ver
, local
->fw_bld
, local
->fw_var
);
2714 for (i
= 0; i
< 32; i
++)
2715 c
[i
] = local
->sparm
.b5
.a_current_ess_id
[i
];
2717 seq_printf(m
, "%s network ESSID = \"%s\"\n",
2718 nettype
[local
->sparm
.b5
.a_network_type
], c
);
2721 seq_printf(m
, "BSSID = %pM\n", p
);
2723 seq_printf(m
, "Country code = %d\n",
2724 local
->sparm
.b5
.a_curr_country_code
);
2726 i
= local
->card_status
;
2731 seq_printf(m
, "Card status = %s\n", card_status
[i
]);
2733 seq_printf(m
, "Framing mode = %s\n", framing
[translate
]);
2735 seq_printf(m
, "Last pkt signal lvl = %d\n", local
->last_rsl
);
2737 if (local
->beacon_rxed
) {
2738 /* Pull some fields out of last beacon received */
2739 seq_printf(m
, "Beacon Interval = %d Kus\n",
2740 local
->last_bcn
.beacon_intvl
[0]
2741 + 256 * local
->last_bcn
.beacon_intvl
[1]);
2743 p
= local
->last_bcn
.elements
;
2744 if (p
[0] == C_ESSID_ELEMENT_ID
)
2748 "Parse beacon failed at essid element id = %d\n",
2753 if (p
[0] == C_SUPPORTED_RATES_ELEMENT_ID
) {
2754 seq_puts(m
, "Supported rate codes = ");
2755 for (i
= 2; i
< p
[1] + 2; i
++)
2756 seq_printf(m
, "0x%02x ", p
[i
]);
2760 seq_puts(m
, "Parse beacon failed at rates element\n");
2764 if (p
[0] == C_FH_PARAM_SET_ELEMENT_ID
) {
2765 pfh
= (struct freq_hop_element
*)p
;
2766 seq_printf(m
, "Hop dwell = %d Kus\n",
2767 pfh
->dwell_time
[0] +
2768 256 * pfh
->dwell_time
[1]);
2769 seq_printf(m
, "Hop set = %d \n",
2771 seq_printf(m
, "Hop pattern = %d \n",
2773 seq_printf(m
, "Hop index = %d \n",
2778 "Parse beacon failed at FH param element\n");
2782 seq_puts(m
, "No beacons received\n");
2787 static int ray_cs_proc_open(struct inode
*inode
, struct file
*file
)
2789 return single_open(file
, ray_cs_proc_show
, NULL
);
2792 static const struct file_operations ray_cs_proc_fops
= {
2793 .owner
= THIS_MODULE
,
2794 .open
= ray_cs_proc_open
,
2796 .llseek
= seq_lseek
,
2797 .release
= single_release
,
2800 /*===========================================================================*/
2801 static int build_auth_frame(ray_dev_t
*local
, UCHAR
*dest
, int auth_type
)
2804 struct ccs __iomem
*pccs
;
2805 struct tx_msg __iomem
*ptx
;
2808 /* If no tx buffers available, return */
2809 if ((ccsindex
= get_free_tx_ccs(local
)) < 0) {
2810 pr_debug("ray_cs send authenticate - No free tx ccs\n");
2814 pccs
= ccs_base(local
) + ccsindex
;
2816 /* Address in card space */
2817 addr
= TX_BUF_BASE
+ (ccsindex
<< 11);
2818 /* fill in the CCS */
2819 writeb(CCS_TX_REQUEST
, &pccs
->cmd
);
2820 writeb(addr
>> 8, pccs
->var
.tx_request
.tx_data_ptr
);
2821 writeb(0x20, pccs
->var
.tx_request
.tx_data_ptr
+ 1);
2822 writeb(TX_AUTHENTICATE_LENGTH_MSB
, pccs
->var
.tx_request
.tx_data_length
);
2823 writeb(TX_AUTHENTICATE_LENGTH_LSB
,
2824 pccs
->var
.tx_request
.tx_data_length
+ 1);
2825 writeb(0, &pccs
->var
.tx_request
.pow_sav_mode
);
2827 ptx
= local
->sram
+ addr
;
2828 /* fill in the mac header */
2829 writeb(PROTOCOL_VER
| AUTHENTIC_TYPE
, &ptx
->mac
.frame_ctl_1
);
2830 writeb(0, &ptx
->mac
.frame_ctl_2
);
2832 memcpy_toio(ptx
->mac
.addr_1
, dest
, ADDRLEN
);
2833 memcpy_toio(ptx
->mac
.addr_2
, local
->sparm
.b4
.a_mac_addr
, ADDRLEN
);
2834 memcpy_toio(ptx
->mac
.addr_3
, local
->bss_id
, ADDRLEN
);
2836 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2837 memset_io(ptx
->var
, 0, 6);
2838 writeb(auth_type
& 0xff, ptx
->var
+ 2);
2840 /* Interrupt the firmware to process the command */
2841 if (interrupt_ecf(local
, ccsindex
)) {
2843 "ray_cs send authentication request failed - ECF not ready for intr\n");
2844 writeb(CCS_BUFFER_FREE
, &(pccs
++)->buffer_status
);
2848 } /* End build_auth_frame */
2850 /*===========================================================================*/
2851 #ifdef CONFIG_PROC_FS
2852 static ssize_t
ray_cs_essid_proc_write(struct file
*file
,
2853 const char __user
*buffer
, size_t count
, loff_t
*pos
)
2855 static char proc_essid
[33];
2856 unsigned int len
= count
;
2860 memset(proc_essid
, 0, 33);
2861 if (copy_from_user(proc_essid
, buffer
, len
))
2867 static const struct file_operations ray_cs_essid_proc_fops
= {
2868 .owner
= THIS_MODULE
,
2869 .write
= ray_cs_essid_proc_write
,
2872 static ssize_t
int_proc_write(struct file
*file
, const char __user
*buffer
,
2873 size_t count
, loff_t
*pos
)
2875 static char proc_number
[10];
2884 if (copy_from_user(proc_number
, buffer
, count
))
2890 unsigned int c
= *p
- '0';
2896 *(int *)PDE(file
->f_path
.dentry
->d_inode
)->data
= nr
;
2900 static const struct file_operations int_proc_fops
= {
2901 .owner
= THIS_MODULE
,
2902 .write
= int_proc_write
,
2906 static struct pcmcia_device_id ray_ids
[] = {
2907 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2911 MODULE_DEVICE_TABLE(pcmcia
, ray_ids
);
2913 static struct pcmcia_driver ray_driver
= {
2914 .owner
= THIS_MODULE
,
2919 .remove
= ray_detach
,
2920 .id_table
= ray_ids
,
2921 .suspend
= ray_suspend
,
2922 .resume
= ray_resume
,
2925 static int __init
init_ray_cs(void)
2929 pr_debug("%s\n", rcsid
);
2930 rc
= pcmcia_register_driver(&ray_driver
);
2931 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
2934 #ifdef CONFIG_PROC_FS
2935 proc_mkdir("driver/ray_cs", NULL
);
2937 proc_create("driver/ray_cs/ray_cs", 0, NULL
, &ray_cs_proc_fops
);
2938 proc_create("driver/ray_cs/essid", S_IWUSR
, NULL
, &ray_cs_essid_proc_fops
);
2939 proc_create_data("driver/ray_cs/net_type", S_IWUSR
, NULL
, &int_proc_fops
, &net_type
);
2940 proc_create_data("driver/ray_cs/translate", S_IWUSR
, NULL
, &int_proc_fops
, &translate
);
2947 /*===========================================================================*/
2949 static void __exit
exit_ray_cs(void)
2951 pr_debug("ray_cs: cleanup_module\n");
2953 #ifdef CONFIG_PROC_FS
2954 remove_proc_entry("driver/ray_cs/ray_cs", NULL
);
2955 remove_proc_entry("driver/ray_cs/essid", NULL
);
2956 remove_proc_entry("driver/ray_cs/net_type", NULL
);
2957 remove_proc_entry("driver/ray_cs/translate", NULL
);
2958 remove_proc_entry("driver/ray_cs", NULL
);
2961 pcmcia_unregister_driver(&ray_driver
);
2964 module_init(init_ray_cs
);
2965 module_exit(exit_ray_cs
);
2967 /*===========================================================================*/