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