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