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