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