]>
Commit | Line | Data |
---|---|---|
cb1576a8 DK |
1 | /* Wireless extensions support. |
2 | * | |
3 | * See copyright notice in main.c | |
4 | */ | |
5a0e3ad6 | 5 | #include <linux/slab.h> |
cb1576a8 DK |
6 | #include <linux/kernel.h> |
7 | #include <linux/if_arp.h> | |
8 | #include <linux/wireless.h> | |
9 | #include <linux/ieee80211.h> | |
10 | #include <net/iw_handler.h> | |
ea60a6aa | 11 | #include <net/cfg80211.h> |
cb1576a8 DK |
12 | |
13 | #include "hermes.h" | |
14 | #include "hermes_rid.h" | |
15 | #include "orinoco.h" | |
16 | ||
17 | #include "hw.h" | |
18 | #include "mic.h" | |
19 | #include "scan.h" | |
20 | #include "main.h" | |
21 | ||
22 | #include "wext.h" | |
23 | ||
24 | #define MAX_RID_LEN 1024 | |
25 | ||
4af198fb | 26 | /* Helper routine to record keys |
5b069150 | 27 | * It is called under orinoco_lock so it may not sleep */ |
4af198fb DK |
28 | static int orinoco_set_key(struct orinoco_private *priv, int index, |
29 | enum orinoco_alg alg, const u8 *key, int key_len, | |
30 | const u8 *seq, int seq_len) | |
31 | { | |
32 | kzfree(priv->keys[index].key); | |
33 | kzfree(priv->keys[index].seq); | |
34 | ||
35 | if (key_len) { | |
5b069150 | 36 | priv->keys[index].key = kzalloc(key_len, GFP_ATOMIC); |
4af198fb DK |
37 | if (!priv->keys[index].key) |
38 | goto nomem; | |
39 | } else | |
40 | priv->keys[index].key = NULL; | |
41 | ||
42 | if (seq_len) { | |
5b069150 | 43 | priv->keys[index].seq = kzalloc(seq_len, GFP_ATOMIC); |
4af198fb DK |
44 | if (!priv->keys[index].seq) |
45 | goto free_key; | |
46 | } else | |
47 | priv->keys[index].seq = NULL; | |
48 | ||
49 | priv->keys[index].key_len = key_len; | |
50 | priv->keys[index].seq_len = seq_len; | |
51 | ||
52 | if (key_len) | |
53 | memcpy(priv->keys[index].key, key, key_len); | |
54 | if (seq_len) | |
55 | memcpy(priv->keys[index].seq, seq, seq_len); | |
56 | ||
57 | switch (alg) { | |
58 | case ORINOCO_ALG_TKIP: | |
59 | priv->keys[index].cipher = WLAN_CIPHER_SUITE_TKIP; | |
60 | break; | |
61 | ||
62 | case ORINOCO_ALG_WEP: | |
63 | priv->keys[index].cipher = (key_len > SMALL_KEY_SIZE) ? | |
64 | WLAN_CIPHER_SUITE_WEP104 : WLAN_CIPHER_SUITE_WEP40; | |
65 | break; | |
66 | ||
67 | case ORINOCO_ALG_NONE: | |
68 | default: | |
69 | priv->keys[index].cipher = 0; | |
70 | break; | |
71 | } | |
72 | ||
73 | return 0; | |
74 | ||
75 | free_key: | |
76 | kfree(priv->keys[index].key); | |
77 | priv->keys[index].key = NULL; | |
78 | ||
79 | nomem: | |
80 | priv->keys[index].key_len = 0; | |
81 | priv->keys[index].seq_len = 0; | |
82 | priv->keys[index].cipher = 0; | |
83 | ||
84 | return -ENOMEM; | |
85 | } | |
86 | ||
cb1576a8 DK |
87 | static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev) |
88 | { | |
ea60a6aa | 89 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
90 | hermes_t *hw = &priv->hw; |
91 | struct iw_statistics *wstats = &priv->wstats; | |
92 | int err; | |
93 | unsigned long flags; | |
94 | ||
95 | if (!netif_device_present(dev)) { | |
96 | printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n", | |
97 | dev->name); | |
98 | return NULL; /* FIXME: Can we do better than this? */ | |
99 | } | |
100 | ||
101 | /* If busy, return the old stats. Returning NULL may cause | |
102 | * the interface to disappear from /proc/net/wireless */ | |
103 | if (orinoco_lock(priv, &flags) != 0) | |
104 | return wstats; | |
105 | ||
106 | /* We can't really wait for the tallies inquiry command to | |
107 | * complete, so we just use the previous results and trigger | |
108 | * a new tallies inquiry command for next time - Jean II */ | |
109 | /* FIXME: Really we should wait for the inquiry to come back - | |
110 | * as it is the stats we give don't make a whole lot of sense. | |
111 | * Unfortunately, it's not clear how to do that within the | |
112 | * wireless extensions framework: I think we're in user | |
113 | * context, but a lock seems to be held by the time we get in | |
114 | * here so we're not safe to sleep here. */ | |
115 | hermes_inquire(hw, HERMES_INQ_TALLIES); | |
116 | ||
5217c571 | 117 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) { |
cb1576a8 DK |
118 | memset(&wstats->qual, 0, sizeof(wstats->qual)); |
119 | /* If a spy address is defined, we report stats of the | |
120 | * first spy address - Jean II */ | |
121 | if (SPY_NUMBER(priv)) { | |
122 | wstats->qual.qual = priv->spy_data.spy_stat[0].qual; | |
123 | wstats->qual.level = priv->spy_data.spy_stat[0].level; | |
124 | wstats->qual.noise = priv->spy_data.spy_stat[0].noise; | |
125 | wstats->qual.updated = | |
126 | priv->spy_data.spy_stat[0].updated; | |
127 | } | |
128 | } else { | |
129 | struct { | |
130 | __le16 qual, signal, noise, unused; | |
131 | } __attribute__ ((packed)) cq; | |
132 | ||
133 | err = HERMES_READ_RECORD(hw, USER_BAP, | |
134 | HERMES_RID_COMMSQUALITY, &cq); | |
135 | ||
136 | if (!err) { | |
137 | wstats->qual.qual = (int)le16_to_cpu(cq.qual); | |
138 | wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95; | |
139 | wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95; | |
140 | wstats->qual.updated = | |
141 | IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; | |
142 | } | |
143 | } | |
144 | ||
145 | orinoco_unlock(priv, &flags); | |
146 | return wstats; | |
147 | } | |
148 | ||
149 | /********************************************************************/ | |
150 | /* Wireless extensions */ | |
151 | /********************************************************************/ | |
152 | ||
cb1576a8 DK |
153 | static int orinoco_ioctl_setwap(struct net_device *dev, |
154 | struct iw_request_info *info, | |
155 | struct sockaddr *ap_addr, | |
156 | char *extra) | |
157 | { | |
ea60a6aa | 158 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
159 | int err = -EINPROGRESS; /* Call commit handler */ |
160 | unsigned long flags; | |
161 | static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | |
162 | static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
163 | ||
164 | if (orinoco_lock(priv, &flags) != 0) | |
165 | return -EBUSY; | |
166 | ||
167 | /* Enable automatic roaming - no sanity checks are needed */ | |
168 | if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 || | |
169 | memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) { | |
170 | priv->bssid_fixed = 0; | |
171 | memset(priv->desired_bssid, 0, ETH_ALEN); | |
172 | ||
173 | /* "off" means keep existing connection */ | |
174 | if (ap_addr->sa_data[0] == 0) { | |
175 | __orinoco_hw_set_wap(priv); | |
176 | err = 0; | |
177 | } | |
178 | goto out; | |
179 | } | |
180 | ||
181 | if (priv->firmware_type == FIRMWARE_TYPE_AGERE) { | |
182 | printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't " | |
183 | "support manual roaming\n", | |
184 | dev->name); | |
185 | err = -EOPNOTSUPP; | |
186 | goto out; | |
187 | } | |
188 | ||
5217c571 | 189 | if (priv->iw_mode != NL80211_IFTYPE_STATION) { |
cb1576a8 DK |
190 | printk(KERN_WARNING "%s: Manual roaming supported only in " |
191 | "managed mode\n", dev->name); | |
192 | err = -EOPNOTSUPP; | |
193 | goto out; | |
194 | } | |
195 | ||
196 | /* Intersil firmware hangs without Desired ESSID */ | |
197 | if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL && | |
198 | strlen(priv->desired_essid) == 0) { | |
199 | printk(KERN_WARNING "%s: Desired ESSID must be set for " | |
200 | "manual roaming\n", dev->name); | |
201 | err = -EOPNOTSUPP; | |
202 | goto out; | |
203 | } | |
204 | ||
205 | /* Finally, enable manual roaming */ | |
206 | priv->bssid_fixed = 1; | |
207 | memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN); | |
208 | ||
209 | out: | |
210 | orinoco_unlock(priv, &flags); | |
211 | return err; | |
212 | } | |
213 | ||
214 | static int orinoco_ioctl_getwap(struct net_device *dev, | |
215 | struct iw_request_info *info, | |
216 | struct sockaddr *ap_addr, | |
217 | char *extra) | |
218 | { | |
ea60a6aa | 219 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 | 220 | |
cb1576a8 DK |
221 | int err = 0; |
222 | unsigned long flags; | |
223 | ||
224 | if (orinoco_lock(priv, &flags) != 0) | |
225 | return -EBUSY; | |
226 | ||
227 | ap_addr->sa_family = ARPHRD_ETHER; | |
2b260351 | 228 | err = orinoco_hw_get_current_bssid(priv, ap_addr->sa_data); |
cb1576a8 DK |
229 | |
230 | orinoco_unlock(priv, &flags); | |
231 | ||
232 | return err; | |
233 | } | |
234 | ||
cb1576a8 DK |
235 | static int orinoco_ioctl_setiwencode(struct net_device *dev, |
236 | struct iw_request_info *info, | |
237 | struct iw_point *erq, | |
238 | char *keybuf) | |
239 | { | |
ea60a6aa | 240 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
241 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; |
242 | int setindex = priv->tx_key; | |
5c9f41e2 | 243 | enum orinoco_alg encode_alg = priv->encode_alg; |
cb1576a8 | 244 | int restricted = priv->wep_restrict; |
cb1576a8 DK |
245 | int err = -EINPROGRESS; /* Call commit handler */ |
246 | unsigned long flags; | |
247 | ||
248 | if (!priv->has_wep) | |
249 | return -EOPNOTSUPP; | |
250 | ||
251 | if (erq->pointer) { | |
252 | /* We actually have a key to set - check its length */ | |
253 | if (erq->length > LARGE_KEY_SIZE) | |
254 | return -E2BIG; | |
255 | ||
256 | if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep) | |
257 | return -E2BIG; | |
258 | } | |
259 | ||
260 | if (orinoco_lock(priv, &flags) != 0) | |
261 | return -EBUSY; | |
262 | ||
263 | /* Clear any TKIP key we have */ | |
5c9f41e2 | 264 | if ((priv->has_wpa) && (priv->encode_alg == ORINOCO_ALG_TKIP)) |
cb1576a8 DK |
265 | (void) orinoco_clear_tkip_key(priv, setindex); |
266 | ||
267 | if (erq->length > 0) { | |
268 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) | |
269 | index = priv->tx_key; | |
270 | ||
cb1576a8 | 271 | /* Switch on WEP if off */ |
5c9f41e2 | 272 | if (encode_alg != ORINOCO_ALG_WEP) { |
cb1576a8 | 273 | setindex = index; |
5c9f41e2 | 274 | encode_alg = ORINOCO_ALG_WEP; |
cb1576a8 DK |
275 | } |
276 | } else { | |
277 | /* Important note : if the user do "iwconfig eth0 enc off", | |
278 | * we will arrive there with an index of -1. This is valid | |
279 | * but need to be taken care off... Jean II */ | |
280 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) { | |
281 | if ((index != -1) || (erq->flags == 0)) { | |
282 | err = -EINVAL; | |
283 | goto out; | |
284 | } | |
285 | } else { | |
286 | /* Set the index : Check that the key is valid */ | |
4af198fb | 287 | if (priv->keys[index].key_len == 0) { |
cb1576a8 DK |
288 | err = -EINVAL; |
289 | goto out; | |
290 | } | |
291 | setindex = index; | |
292 | } | |
293 | } | |
294 | ||
295 | if (erq->flags & IW_ENCODE_DISABLED) | |
5c9f41e2 | 296 | encode_alg = ORINOCO_ALG_NONE; |
cb1576a8 DK |
297 | if (erq->flags & IW_ENCODE_OPEN) |
298 | restricted = 0; | |
299 | if (erq->flags & IW_ENCODE_RESTRICTED) | |
300 | restricted = 1; | |
301 | ||
302 | if (erq->pointer && erq->length > 0) { | |
4af198fb DK |
303 | err = orinoco_set_key(priv, index, ORINOCO_ALG_WEP, keybuf, |
304 | erq->length, NULL, 0); | |
cb1576a8 DK |
305 | } |
306 | priv->tx_key = setindex; | |
307 | ||
308 | /* Try fast key change if connected and only keys are changed */ | |
309 | if ((priv->encode_alg == encode_alg) && | |
310 | (priv->wep_restrict == restricted) && | |
311 | netif_carrier_ok(dev)) { | |
312 | err = __orinoco_hw_setup_wepkeys(priv); | |
313 | /* No need to commit if successful */ | |
314 | goto out; | |
315 | } | |
316 | ||
317 | priv->encode_alg = encode_alg; | |
318 | priv->wep_restrict = restricted; | |
319 | ||
320 | out: | |
321 | orinoco_unlock(priv, &flags); | |
322 | ||
323 | return err; | |
324 | } | |
325 | ||
326 | static int orinoco_ioctl_getiwencode(struct net_device *dev, | |
327 | struct iw_request_info *info, | |
328 | struct iw_point *erq, | |
329 | char *keybuf) | |
330 | { | |
ea60a6aa | 331 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 | 332 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; |
cb1576a8 DK |
333 | unsigned long flags; |
334 | ||
335 | if (!priv->has_wep) | |
336 | return -EOPNOTSUPP; | |
337 | ||
338 | if (orinoco_lock(priv, &flags) != 0) | |
339 | return -EBUSY; | |
340 | ||
341 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) | |
342 | index = priv->tx_key; | |
343 | ||
344 | erq->flags = 0; | |
345 | if (!priv->encode_alg) | |
346 | erq->flags |= IW_ENCODE_DISABLED; | |
347 | erq->flags |= index + 1; | |
348 | ||
349 | if (priv->wep_restrict) | |
350 | erq->flags |= IW_ENCODE_RESTRICTED; | |
351 | else | |
352 | erq->flags |= IW_ENCODE_OPEN; | |
353 | ||
4af198fb | 354 | erq->length = priv->keys[index].key_len; |
cb1576a8 | 355 | |
4af198fb | 356 | memcpy(keybuf, priv->keys[index].key, erq->length); |
cb1576a8 DK |
357 | |
358 | orinoco_unlock(priv, &flags); | |
359 | return 0; | |
360 | } | |
361 | ||
362 | static int orinoco_ioctl_setessid(struct net_device *dev, | |
363 | struct iw_request_info *info, | |
364 | struct iw_point *erq, | |
365 | char *essidbuf) | |
366 | { | |
ea60a6aa | 367 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
368 | unsigned long flags; |
369 | ||
370 | /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it | |
371 | * anyway... - Jean II */ | |
372 | ||
373 | /* Hum... Should not use Wireless Extension constant (may change), | |
374 | * should use our own... - Jean II */ | |
375 | if (erq->length > IW_ESSID_MAX_SIZE) | |
376 | return -E2BIG; | |
377 | ||
378 | if (orinoco_lock(priv, &flags) != 0) | |
379 | return -EBUSY; | |
380 | ||
381 | /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */ | |
382 | memset(priv->desired_essid, 0, sizeof(priv->desired_essid)); | |
383 | ||
384 | /* If not ANY, get the new ESSID */ | |
385 | if (erq->flags) | |
386 | memcpy(priv->desired_essid, essidbuf, erq->length); | |
387 | ||
388 | orinoco_unlock(priv, &flags); | |
389 | ||
390 | return -EINPROGRESS; /* Call commit handler */ | |
391 | } | |
392 | ||
393 | static int orinoco_ioctl_getessid(struct net_device *dev, | |
394 | struct iw_request_info *info, | |
395 | struct iw_point *erq, | |
396 | char *essidbuf) | |
397 | { | |
ea60a6aa | 398 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
399 | int active; |
400 | int err = 0; | |
401 | unsigned long flags; | |
402 | ||
403 | if (netif_running(dev)) { | |
404 | err = orinoco_hw_get_essid(priv, &active, essidbuf); | |
405 | if (err < 0) | |
406 | return err; | |
407 | erq->length = err; | |
408 | } else { | |
409 | if (orinoco_lock(priv, &flags) != 0) | |
410 | return -EBUSY; | |
411 | memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE); | |
412 | erq->length = strlen(priv->desired_essid); | |
413 | orinoco_unlock(priv, &flags); | |
414 | } | |
415 | ||
416 | erq->flags = 1; | |
417 | ||
418 | return 0; | |
419 | } | |
420 | ||
cb1576a8 DK |
421 | static int orinoco_ioctl_setfreq(struct net_device *dev, |
422 | struct iw_request_info *info, | |
423 | struct iw_freq *frq, | |
424 | char *extra) | |
425 | { | |
ea60a6aa | 426 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
427 | int chan = -1; |
428 | unsigned long flags; | |
429 | int err = -EINPROGRESS; /* Call commit handler */ | |
430 | ||
431 | /* In infrastructure mode the AP sets the channel */ | |
5217c571 | 432 | if (priv->iw_mode == NL80211_IFTYPE_STATION) |
cb1576a8 DK |
433 | return -EBUSY; |
434 | ||
435 | if ((frq->e == 0) && (frq->m <= 1000)) { | |
436 | /* Setting by channel number */ | |
437 | chan = frq->m; | |
438 | } else { | |
439 | /* Setting by frequency */ | |
440 | int denom = 1; | |
441 | int i; | |
442 | ||
443 | /* Calculate denominator to rescale to MHz */ | |
444 | for (i = 0; i < (6 - frq->e); i++) | |
445 | denom *= 10; | |
446 | ||
447 | chan = ieee80211_freq_to_dsss_chan(frq->m / denom); | |
448 | } | |
449 | ||
450 | if ((chan < 1) || (chan > NUM_CHANNELS) || | |
451 | !(priv->channel_mask & (1 << (chan-1)))) | |
452 | return -EINVAL; | |
453 | ||
454 | if (orinoco_lock(priv, &flags) != 0) | |
455 | return -EBUSY; | |
456 | ||
457 | priv->channel = chan; | |
5217c571 | 458 | if (priv->iw_mode == NL80211_IFTYPE_MONITOR) { |
cb1576a8 DK |
459 | /* Fast channel change - no commit if successful */ |
460 | hermes_t *hw = &priv->hw; | |
461 | err = hermes_docmd_wait(hw, HERMES_CMD_TEST | | |
462 | HERMES_TEST_SET_CHANNEL, | |
463 | chan, NULL); | |
464 | } | |
465 | orinoco_unlock(priv, &flags); | |
466 | ||
467 | return err; | |
468 | } | |
469 | ||
470 | static int orinoco_ioctl_getfreq(struct net_device *dev, | |
471 | struct iw_request_info *info, | |
472 | struct iw_freq *frq, | |
473 | char *extra) | |
474 | { | |
ea60a6aa | 475 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
476 | int tmp; |
477 | ||
478 | /* Locking done in there */ | |
479 | tmp = orinoco_hw_get_freq(priv); | |
480 | if (tmp < 0) | |
481 | return tmp; | |
482 | ||
483 | frq->m = tmp * 100000; | |
484 | frq->e = 1; | |
485 | ||
486 | return 0; | |
487 | } | |
488 | ||
489 | static int orinoco_ioctl_getsens(struct net_device *dev, | |
490 | struct iw_request_info *info, | |
491 | struct iw_param *srq, | |
492 | char *extra) | |
493 | { | |
ea60a6aa | 494 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
495 | hermes_t *hw = &priv->hw; |
496 | u16 val; | |
497 | int err; | |
498 | unsigned long flags; | |
499 | ||
500 | if (!priv->has_sensitivity) | |
501 | return -EOPNOTSUPP; | |
502 | ||
503 | if (orinoco_lock(priv, &flags) != 0) | |
504 | return -EBUSY; | |
505 | err = hermes_read_wordrec(hw, USER_BAP, | |
506 | HERMES_RID_CNFSYSTEMSCALE, &val); | |
507 | orinoco_unlock(priv, &flags); | |
508 | ||
509 | if (err) | |
510 | return err; | |
511 | ||
512 | srq->value = val; | |
513 | srq->fixed = 0; /* auto */ | |
514 | ||
515 | return 0; | |
516 | } | |
517 | ||
518 | static int orinoco_ioctl_setsens(struct net_device *dev, | |
519 | struct iw_request_info *info, | |
520 | struct iw_param *srq, | |
521 | char *extra) | |
522 | { | |
ea60a6aa | 523 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
524 | int val = srq->value; |
525 | unsigned long flags; | |
526 | ||
527 | if (!priv->has_sensitivity) | |
528 | return -EOPNOTSUPP; | |
529 | ||
530 | if ((val < 1) || (val > 3)) | |
531 | return -EINVAL; | |
532 | ||
533 | if (orinoco_lock(priv, &flags) != 0) | |
534 | return -EBUSY; | |
535 | priv->ap_density = val; | |
536 | orinoco_unlock(priv, &flags); | |
537 | ||
538 | return -EINPROGRESS; /* Call commit handler */ | |
539 | } | |
540 | ||
541 | static int orinoco_ioctl_setrts(struct net_device *dev, | |
542 | struct iw_request_info *info, | |
543 | struct iw_param *rrq, | |
544 | char *extra) | |
545 | { | |
ea60a6aa | 546 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
547 | int val = rrq->value; |
548 | unsigned long flags; | |
549 | ||
550 | if (rrq->disabled) | |
551 | val = 2347; | |
552 | ||
553 | if ((val < 0) || (val > 2347)) | |
554 | return -EINVAL; | |
555 | ||
556 | if (orinoco_lock(priv, &flags) != 0) | |
557 | return -EBUSY; | |
558 | ||
559 | priv->rts_thresh = val; | |
560 | orinoco_unlock(priv, &flags); | |
561 | ||
562 | return -EINPROGRESS; /* Call commit handler */ | |
563 | } | |
564 | ||
565 | static int orinoco_ioctl_getrts(struct net_device *dev, | |
566 | struct iw_request_info *info, | |
567 | struct iw_param *rrq, | |
568 | char *extra) | |
569 | { | |
ea60a6aa | 570 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
571 | |
572 | rrq->value = priv->rts_thresh; | |
573 | rrq->disabled = (rrq->value == 2347); | |
574 | rrq->fixed = 1; | |
575 | ||
576 | return 0; | |
577 | } | |
578 | ||
579 | static int orinoco_ioctl_setfrag(struct net_device *dev, | |
580 | struct iw_request_info *info, | |
581 | struct iw_param *frq, | |
582 | char *extra) | |
583 | { | |
ea60a6aa | 584 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
585 | int err = -EINPROGRESS; /* Call commit handler */ |
586 | unsigned long flags; | |
587 | ||
588 | if (orinoco_lock(priv, &flags) != 0) | |
589 | return -EBUSY; | |
590 | ||
591 | if (priv->has_mwo) { | |
592 | if (frq->disabled) | |
593 | priv->mwo_robust = 0; | |
594 | else { | |
595 | if (frq->fixed) | |
596 | printk(KERN_WARNING "%s: Fixed fragmentation " | |
597 | "is not supported on this firmware. " | |
598 | "Using MWO robust instead.\n", | |
599 | dev->name); | |
600 | priv->mwo_robust = 1; | |
601 | } | |
602 | } else { | |
603 | if (frq->disabled) | |
604 | priv->frag_thresh = 2346; | |
605 | else { | |
606 | if ((frq->value < 256) || (frq->value > 2346)) | |
607 | err = -EINVAL; | |
608 | else | |
609 | /* must be even */ | |
610 | priv->frag_thresh = frq->value & ~0x1; | |
611 | } | |
612 | } | |
613 | ||
614 | orinoco_unlock(priv, &flags); | |
615 | ||
616 | return err; | |
617 | } | |
618 | ||
619 | static int orinoco_ioctl_getfrag(struct net_device *dev, | |
620 | struct iw_request_info *info, | |
621 | struct iw_param *frq, | |
622 | char *extra) | |
623 | { | |
ea60a6aa | 624 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
625 | hermes_t *hw = &priv->hw; |
626 | int err; | |
627 | u16 val; | |
628 | unsigned long flags; | |
629 | ||
630 | if (orinoco_lock(priv, &flags) != 0) | |
631 | return -EBUSY; | |
632 | ||
633 | if (priv->has_mwo) { | |
634 | err = hermes_read_wordrec(hw, USER_BAP, | |
635 | HERMES_RID_CNFMWOROBUST_AGERE, | |
636 | &val); | |
637 | if (err) | |
638 | val = 0; | |
639 | ||
640 | frq->value = val ? 2347 : 0; | |
641 | frq->disabled = !val; | |
642 | frq->fixed = 0; | |
643 | } else { | |
644 | err = hermes_read_wordrec(hw, USER_BAP, | |
645 | HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, | |
646 | &val); | |
647 | if (err) | |
648 | val = 0; | |
649 | ||
650 | frq->value = val; | |
651 | frq->disabled = (val >= 2346); | |
652 | frq->fixed = 1; | |
653 | } | |
654 | ||
655 | orinoco_unlock(priv, &flags); | |
656 | ||
657 | return err; | |
658 | } | |
659 | ||
660 | static int orinoco_ioctl_setrate(struct net_device *dev, | |
661 | struct iw_request_info *info, | |
662 | struct iw_param *rrq, | |
663 | char *extra) | |
664 | { | |
ea60a6aa | 665 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
666 | int ratemode; |
667 | int bitrate; /* 100s of kilobits */ | |
668 | unsigned long flags; | |
669 | ||
670 | /* As the user space doesn't know our highest rate, it uses -1 | |
671 | * to ask us to set the highest rate. Test it using "iwconfig | |
672 | * ethX rate auto" - Jean II */ | |
673 | if (rrq->value == -1) | |
674 | bitrate = 110; | |
675 | else { | |
676 | if (rrq->value % 100000) | |
677 | return -EINVAL; | |
678 | bitrate = rrq->value / 100000; | |
679 | } | |
680 | ||
681 | ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed); | |
682 | ||
683 | if (ratemode == -1) | |
684 | return -EINVAL; | |
685 | ||
686 | if (orinoco_lock(priv, &flags) != 0) | |
687 | return -EBUSY; | |
688 | priv->bitratemode = ratemode; | |
689 | orinoco_unlock(priv, &flags); | |
690 | ||
691 | return -EINPROGRESS; | |
692 | } | |
693 | ||
694 | static int orinoco_ioctl_getrate(struct net_device *dev, | |
695 | struct iw_request_info *info, | |
696 | struct iw_param *rrq, | |
697 | char *extra) | |
698 | { | |
ea60a6aa | 699 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
700 | int err = 0; |
701 | int bitrate, automatic; | |
702 | unsigned long flags; | |
703 | ||
704 | if (orinoco_lock(priv, &flags) != 0) | |
705 | return -EBUSY; | |
706 | ||
707 | orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic); | |
708 | ||
709 | /* If the interface is running we try to find more about the | |
710 | current mode */ | |
711 | if (netif_running(dev)) | |
712 | err = orinoco_hw_get_act_bitrate(priv, &bitrate); | |
713 | ||
714 | orinoco_unlock(priv, &flags); | |
715 | ||
716 | rrq->value = bitrate; | |
717 | rrq->fixed = !automatic; | |
718 | rrq->disabled = 0; | |
719 | ||
720 | return err; | |
721 | } | |
722 | ||
723 | static int orinoco_ioctl_setpower(struct net_device *dev, | |
724 | struct iw_request_info *info, | |
725 | struct iw_param *prq, | |
726 | char *extra) | |
727 | { | |
ea60a6aa | 728 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
729 | int err = -EINPROGRESS; /* Call commit handler */ |
730 | unsigned long flags; | |
731 | ||
732 | if (orinoco_lock(priv, &flags) != 0) | |
733 | return -EBUSY; | |
734 | ||
735 | if (prq->disabled) { | |
736 | priv->pm_on = 0; | |
737 | } else { | |
738 | switch (prq->flags & IW_POWER_MODE) { | |
739 | case IW_POWER_UNICAST_R: | |
740 | priv->pm_mcast = 0; | |
741 | priv->pm_on = 1; | |
742 | break; | |
743 | case IW_POWER_ALL_R: | |
744 | priv->pm_mcast = 1; | |
745 | priv->pm_on = 1; | |
746 | break; | |
747 | case IW_POWER_ON: | |
748 | /* No flags : but we may have a value - Jean II */ | |
749 | break; | |
750 | default: | |
751 | err = -EINVAL; | |
752 | goto out; | |
753 | } | |
754 | ||
755 | if (prq->flags & IW_POWER_TIMEOUT) { | |
756 | priv->pm_on = 1; | |
757 | priv->pm_timeout = prq->value / 1000; | |
758 | } | |
759 | if (prq->flags & IW_POWER_PERIOD) { | |
760 | priv->pm_on = 1; | |
761 | priv->pm_period = prq->value / 1000; | |
762 | } | |
763 | /* It's valid to not have a value if we are just toggling | |
764 | * the flags... Jean II */ | |
765 | if (!priv->pm_on) { | |
766 | err = -EINVAL; | |
767 | goto out; | |
768 | } | |
769 | } | |
770 | ||
771 | out: | |
772 | orinoco_unlock(priv, &flags); | |
773 | ||
774 | return err; | |
775 | } | |
776 | ||
777 | static int orinoco_ioctl_getpower(struct net_device *dev, | |
778 | struct iw_request_info *info, | |
779 | struct iw_param *prq, | |
780 | char *extra) | |
781 | { | |
ea60a6aa | 782 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
783 | hermes_t *hw = &priv->hw; |
784 | int err = 0; | |
785 | u16 enable, period, timeout, mcast; | |
786 | unsigned long flags; | |
787 | ||
788 | if (orinoco_lock(priv, &flags) != 0) | |
789 | return -EBUSY; | |
790 | ||
791 | err = hermes_read_wordrec(hw, USER_BAP, | |
792 | HERMES_RID_CNFPMENABLED, &enable); | |
793 | if (err) | |
794 | goto out; | |
795 | ||
796 | err = hermes_read_wordrec(hw, USER_BAP, | |
797 | HERMES_RID_CNFMAXSLEEPDURATION, &period); | |
798 | if (err) | |
799 | goto out; | |
800 | ||
801 | err = hermes_read_wordrec(hw, USER_BAP, | |
802 | HERMES_RID_CNFPMHOLDOVERDURATION, &timeout); | |
803 | if (err) | |
804 | goto out; | |
805 | ||
806 | err = hermes_read_wordrec(hw, USER_BAP, | |
807 | HERMES_RID_CNFMULTICASTRECEIVE, &mcast); | |
808 | if (err) | |
809 | goto out; | |
810 | ||
811 | prq->disabled = !enable; | |
812 | /* Note : by default, display the period */ | |
813 | if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { | |
814 | prq->flags = IW_POWER_TIMEOUT; | |
815 | prq->value = timeout * 1000; | |
816 | } else { | |
817 | prq->flags = IW_POWER_PERIOD; | |
818 | prq->value = period * 1000; | |
819 | } | |
820 | if (mcast) | |
821 | prq->flags |= IW_POWER_ALL_R; | |
822 | else | |
823 | prq->flags |= IW_POWER_UNICAST_R; | |
824 | ||
825 | out: | |
826 | orinoco_unlock(priv, &flags); | |
827 | ||
828 | return err; | |
829 | } | |
830 | ||
831 | static int orinoco_ioctl_set_encodeext(struct net_device *dev, | |
832 | struct iw_request_info *info, | |
833 | union iwreq_data *wrqu, | |
834 | char *extra) | |
835 | { | |
ea60a6aa | 836 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
837 | struct iw_point *encoding = &wrqu->encoding; |
838 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
839 | int idx, alg = ext->alg, set_key = 1; | |
840 | unsigned long flags; | |
841 | int err = -EINVAL; | |
cb1576a8 DK |
842 | |
843 | if (orinoco_lock(priv, &flags) != 0) | |
844 | return -EBUSY; | |
845 | ||
846 | /* Determine and validate the key index */ | |
847 | idx = encoding->flags & IW_ENCODE_INDEX; | |
848 | if (idx) { | |
849 | if ((idx < 1) || (idx > 4)) | |
850 | goto out; | |
851 | idx--; | |
852 | } else | |
853 | idx = priv->tx_key; | |
854 | ||
855 | if (encoding->flags & IW_ENCODE_DISABLED) | |
856 | alg = IW_ENCODE_ALG_NONE; | |
857 | ||
858 | if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) { | |
859 | /* Clear any TKIP TX key we had */ | |
860 | (void) orinoco_clear_tkip_key(priv, priv->tx_key); | |
861 | } | |
862 | ||
863 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { | |
864 | priv->tx_key = idx; | |
865 | set_key = ((alg == IW_ENCODE_ALG_TKIP) || | |
866 | (ext->key_len > 0)) ? 1 : 0; | |
867 | } | |
868 | ||
869 | if (set_key) { | |
870 | /* Set the requested key first */ | |
871 | switch (alg) { | |
872 | case IW_ENCODE_ALG_NONE: | |
5c9f41e2 | 873 | priv->encode_alg = ORINOCO_ALG_NONE; |
4af198fb DK |
874 | err = orinoco_set_key(priv, idx, ORINOCO_ALG_NONE, |
875 | NULL, 0, NULL, 0); | |
cb1576a8 DK |
876 | break; |
877 | ||
878 | case IW_ENCODE_ALG_WEP: | |
4af198fb | 879 | if (ext->key_len <= 0) |
cb1576a8 DK |
880 | goto out; |
881 | ||
5c9f41e2 | 882 | priv->encode_alg = ORINOCO_ALG_WEP; |
4af198fb DK |
883 | err = orinoco_set_key(priv, idx, ORINOCO_ALG_WEP, |
884 | ext->key, ext->key_len, NULL, 0); | |
cb1576a8 DK |
885 | break; |
886 | ||
887 | case IW_ENCODE_ALG_TKIP: | |
888 | { | |
cb1576a8 DK |
889 | u8 *tkip_iv = NULL; |
890 | ||
891 | if (!priv->has_wpa || | |
4af198fb | 892 | (ext->key_len > sizeof(struct orinoco_tkip_key))) |
cb1576a8 DK |
893 | goto out; |
894 | ||
5c9f41e2 | 895 | priv->encode_alg = ORINOCO_ALG_TKIP; |
cb1576a8 DK |
896 | |
897 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) | |
898 | tkip_iv = &ext->rx_seq[0]; | |
899 | ||
4af198fb DK |
900 | err = orinoco_set_key(priv, idx, ORINOCO_ALG_TKIP, |
901 | ext->key, ext->key_len, tkip_iv, | |
902 | ORINOCO_SEQ_LEN); | |
903 | ||
98e5f404 | 904 | err = __orinoco_hw_set_tkip_key(priv, idx, |
cb1576a8 | 905 | ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, |
4af198fb | 906 | priv->keys[idx].key, |
16e15848 | 907 | tkip_iv, ORINOCO_SEQ_LEN, NULL, 0); |
cb1576a8 DK |
908 | if (err) |
909 | printk(KERN_ERR "%s: Error %d setting TKIP key" | |
910 | "\n", dev->name, err); | |
911 | ||
912 | goto out; | |
913 | } | |
914 | default: | |
915 | goto out; | |
916 | } | |
917 | } | |
918 | err = -EINPROGRESS; | |
919 | out: | |
920 | orinoco_unlock(priv, &flags); | |
921 | ||
922 | return err; | |
923 | } | |
924 | ||
925 | static int orinoco_ioctl_get_encodeext(struct net_device *dev, | |
926 | struct iw_request_info *info, | |
927 | union iwreq_data *wrqu, | |
928 | char *extra) | |
929 | { | |
ea60a6aa | 930 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
931 | struct iw_point *encoding = &wrqu->encoding; |
932 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
933 | int idx, max_key_len; | |
934 | unsigned long flags; | |
935 | int err; | |
936 | ||
937 | if (orinoco_lock(priv, &flags) != 0) | |
938 | return -EBUSY; | |
939 | ||
940 | err = -EINVAL; | |
941 | max_key_len = encoding->length - sizeof(*ext); | |
942 | if (max_key_len < 0) | |
943 | goto out; | |
944 | ||
945 | idx = encoding->flags & IW_ENCODE_INDEX; | |
946 | if (idx) { | |
947 | if ((idx < 1) || (idx > 4)) | |
948 | goto out; | |
949 | idx--; | |
950 | } else | |
951 | idx = priv->tx_key; | |
952 | ||
953 | encoding->flags = idx + 1; | |
954 | memset(ext, 0, sizeof(*ext)); | |
955 | ||
cb1576a8 | 956 | switch (priv->encode_alg) { |
5c9f41e2 DK |
957 | case ORINOCO_ALG_NONE: |
958 | ext->alg = IW_ENCODE_ALG_NONE; | |
cb1576a8 DK |
959 | ext->key_len = 0; |
960 | encoding->flags |= IW_ENCODE_DISABLED; | |
961 | break; | |
5c9f41e2 DK |
962 | case ORINOCO_ALG_WEP: |
963 | ext->alg = IW_ENCODE_ALG_WEP; | |
4af198fb DK |
964 | ext->key_len = min(priv->keys[idx].key_len, max_key_len); |
965 | memcpy(ext->key, priv->keys[idx].key, ext->key_len); | |
cb1576a8 DK |
966 | encoding->flags |= IW_ENCODE_ENABLED; |
967 | break; | |
5c9f41e2 DK |
968 | case ORINOCO_ALG_TKIP: |
969 | ext->alg = IW_ENCODE_ALG_TKIP; | |
4af198fb DK |
970 | ext->key_len = min(priv->keys[idx].key_len, max_key_len); |
971 | memcpy(ext->key, priv->keys[idx].key, ext->key_len); | |
cb1576a8 DK |
972 | encoding->flags |= IW_ENCODE_ENABLED; |
973 | break; | |
974 | } | |
975 | ||
976 | err = 0; | |
977 | out: | |
978 | orinoco_unlock(priv, &flags); | |
979 | ||
980 | return err; | |
981 | } | |
982 | ||
983 | static int orinoco_ioctl_set_auth(struct net_device *dev, | |
984 | struct iw_request_info *info, | |
985 | union iwreq_data *wrqu, char *extra) | |
986 | { | |
ea60a6aa | 987 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
988 | hermes_t *hw = &priv->hw; |
989 | struct iw_param *param = &wrqu->param; | |
990 | unsigned long flags; | |
991 | int ret = -EINPROGRESS; | |
992 | ||
993 | if (orinoco_lock(priv, &flags) != 0) | |
994 | return -EBUSY; | |
995 | ||
996 | switch (param->flags & IW_AUTH_INDEX) { | |
997 | case IW_AUTH_WPA_VERSION: | |
998 | case IW_AUTH_CIPHER_PAIRWISE: | |
999 | case IW_AUTH_CIPHER_GROUP: | |
1000 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
1001 | case IW_AUTH_PRIVACY_INVOKED: | |
1002 | case IW_AUTH_DROP_UNENCRYPTED: | |
1003 | /* | |
1004 | * orinoco does not use these parameters | |
1005 | */ | |
1006 | break; | |
1007 | ||
1008 | case IW_AUTH_KEY_MGMT: | |
1009 | /* wl_lkm implies value 2 == PSK for Hermes I | |
1010 | * which ties in with WEXT | |
1011 | * no other hints tho :( | |
1012 | */ | |
1013 | priv->key_mgmt = param->value; | |
1014 | break; | |
1015 | ||
1016 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
1017 | /* When countermeasures are enabled, shut down the | |
1018 | * card; when disabled, re-enable the card. This must | |
1019 | * take effect immediately. | |
1020 | * | |
1021 | * TODO: Make sure that the EAPOL message is getting | |
1022 | * out before card disabled | |
1023 | */ | |
1024 | if (param->value) { | |
1025 | priv->tkip_cm_active = 1; | |
1026 | ret = hermes_enable_port(hw, 0); | |
1027 | } else { | |
1028 | priv->tkip_cm_active = 0; | |
1029 | ret = hermes_disable_port(hw, 0); | |
1030 | } | |
1031 | break; | |
1032 | ||
1033 | case IW_AUTH_80211_AUTH_ALG: | |
1034 | if (param->value & IW_AUTH_ALG_SHARED_KEY) | |
1035 | priv->wep_restrict = 1; | |
1036 | else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) | |
1037 | priv->wep_restrict = 0; | |
1038 | else | |
1039 | ret = -EINVAL; | |
1040 | break; | |
1041 | ||
1042 | case IW_AUTH_WPA_ENABLED: | |
1043 | if (priv->has_wpa) { | |
1044 | priv->wpa_enabled = param->value ? 1 : 0; | |
1045 | } else { | |
1046 | if (param->value) | |
1047 | ret = -EOPNOTSUPP; | |
1048 | /* else silently accept disable of WPA */ | |
1049 | priv->wpa_enabled = 0; | |
1050 | } | |
1051 | break; | |
1052 | ||
1053 | default: | |
1054 | ret = -EOPNOTSUPP; | |
1055 | } | |
1056 | ||
1057 | orinoco_unlock(priv, &flags); | |
1058 | return ret; | |
1059 | } | |
1060 | ||
1061 | static int orinoco_ioctl_get_auth(struct net_device *dev, | |
1062 | struct iw_request_info *info, | |
1063 | union iwreq_data *wrqu, char *extra) | |
1064 | { | |
ea60a6aa | 1065 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1066 | struct iw_param *param = &wrqu->param; |
1067 | unsigned long flags; | |
1068 | int ret = 0; | |
1069 | ||
1070 | if (orinoco_lock(priv, &flags) != 0) | |
1071 | return -EBUSY; | |
1072 | ||
1073 | switch (param->flags & IW_AUTH_INDEX) { | |
1074 | case IW_AUTH_KEY_MGMT: | |
1075 | param->value = priv->key_mgmt; | |
1076 | break; | |
1077 | ||
1078 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
1079 | param->value = priv->tkip_cm_active; | |
1080 | break; | |
1081 | ||
1082 | case IW_AUTH_80211_AUTH_ALG: | |
1083 | if (priv->wep_restrict) | |
1084 | param->value = IW_AUTH_ALG_SHARED_KEY; | |
1085 | else | |
1086 | param->value = IW_AUTH_ALG_OPEN_SYSTEM; | |
1087 | break; | |
1088 | ||
1089 | case IW_AUTH_WPA_ENABLED: | |
1090 | param->value = priv->wpa_enabled; | |
1091 | break; | |
1092 | ||
1093 | default: | |
1094 | ret = -EOPNOTSUPP; | |
1095 | } | |
1096 | ||
1097 | orinoco_unlock(priv, &flags); | |
1098 | return ret; | |
1099 | } | |
1100 | ||
1101 | static int orinoco_ioctl_set_genie(struct net_device *dev, | |
1102 | struct iw_request_info *info, | |
1103 | union iwreq_data *wrqu, char *extra) | |
1104 | { | |
ea60a6aa | 1105 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1106 | u8 *buf; |
1107 | unsigned long flags; | |
1108 | ||
1109 | /* cut off at IEEE80211_MAX_DATA_LEN */ | |
1110 | if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) || | |
1111 | (wrqu->data.length && (extra == NULL))) | |
1112 | return -EINVAL; | |
1113 | ||
1114 | if (wrqu->data.length) { | |
1115 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); | |
1116 | if (buf == NULL) | |
1117 | return -ENOMEM; | |
1118 | ||
1119 | memcpy(buf, extra, wrqu->data.length); | |
1120 | } else | |
1121 | buf = NULL; | |
1122 | ||
1123 | if (orinoco_lock(priv, &flags) != 0) { | |
1124 | kfree(buf); | |
1125 | return -EBUSY; | |
1126 | } | |
1127 | ||
1128 | kfree(priv->wpa_ie); | |
1129 | priv->wpa_ie = buf; | |
1130 | priv->wpa_ie_len = wrqu->data.length; | |
1131 | ||
1132 | if (priv->wpa_ie) { | |
1133 | /* Looks like wl_lkm wants to check the auth alg, and | |
1134 | * somehow pass it to the firmware. | |
1135 | * Instead it just calls the key mgmt rid | |
1136 | * - we do this in set auth. | |
1137 | */ | |
1138 | } | |
1139 | ||
1140 | orinoco_unlock(priv, &flags); | |
1141 | return 0; | |
1142 | } | |
1143 | ||
1144 | static int orinoco_ioctl_get_genie(struct net_device *dev, | |
1145 | struct iw_request_info *info, | |
1146 | union iwreq_data *wrqu, char *extra) | |
1147 | { | |
ea60a6aa | 1148 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1149 | unsigned long flags; |
1150 | int err = 0; | |
1151 | ||
1152 | if (orinoco_lock(priv, &flags) != 0) | |
1153 | return -EBUSY; | |
1154 | ||
1155 | if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) { | |
1156 | wrqu->data.length = 0; | |
1157 | goto out; | |
1158 | } | |
1159 | ||
1160 | if (wrqu->data.length < priv->wpa_ie_len) { | |
1161 | err = -E2BIG; | |
1162 | goto out; | |
1163 | } | |
1164 | ||
1165 | wrqu->data.length = priv->wpa_ie_len; | |
1166 | memcpy(extra, priv->wpa_ie, priv->wpa_ie_len); | |
1167 | ||
1168 | out: | |
1169 | orinoco_unlock(priv, &flags); | |
1170 | return err; | |
1171 | } | |
1172 | ||
1173 | static int orinoco_ioctl_set_mlme(struct net_device *dev, | |
1174 | struct iw_request_info *info, | |
1175 | union iwreq_data *wrqu, char *extra) | |
1176 | { | |
ea60a6aa | 1177 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1178 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
1179 | unsigned long flags; | |
1180 | int ret = 0; | |
1181 | ||
1182 | if (orinoco_lock(priv, &flags) != 0) | |
1183 | return -EBUSY; | |
1184 | ||
1185 | switch (mlme->cmd) { | |
1186 | case IW_MLME_DEAUTH: | |
1187 | /* silently ignore */ | |
1188 | break; | |
1189 | ||
1190 | case IW_MLME_DISASSOC: | |
07542d08 DK |
1191 | |
1192 | ret = orinoco_hw_disassociate(priv, mlme->addr.sa_data, | |
1193 | mlme->reason_code); | |
cb1576a8 | 1194 | break; |
07542d08 | 1195 | |
cb1576a8 DK |
1196 | default: |
1197 | ret = -EOPNOTSUPP; | |
1198 | } | |
1199 | ||
1200 | orinoco_unlock(priv, &flags); | |
1201 | return ret; | |
1202 | } | |
1203 | ||
1204 | static int orinoco_ioctl_getretry(struct net_device *dev, | |
1205 | struct iw_request_info *info, | |
1206 | struct iw_param *rrq, | |
1207 | char *extra) | |
1208 | { | |
ea60a6aa | 1209 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1210 | hermes_t *hw = &priv->hw; |
1211 | int err = 0; | |
1212 | u16 short_limit, long_limit, lifetime; | |
1213 | unsigned long flags; | |
1214 | ||
1215 | if (orinoco_lock(priv, &flags) != 0) | |
1216 | return -EBUSY; | |
1217 | ||
1218 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT, | |
1219 | &short_limit); | |
1220 | if (err) | |
1221 | goto out; | |
1222 | ||
1223 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT, | |
1224 | &long_limit); | |
1225 | if (err) | |
1226 | goto out; | |
1227 | ||
1228 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME, | |
1229 | &lifetime); | |
1230 | if (err) | |
1231 | goto out; | |
1232 | ||
1233 | rrq->disabled = 0; /* Can't be disabled */ | |
1234 | ||
1235 | /* Note : by default, display the retry number */ | |
1236 | if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | |
1237 | rrq->flags = IW_RETRY_LIFETIME; | |
1238 | rrq->value = lifetime * 1000; /* ??? */ | |
1239 | } else { | |
1240 | /* By default, display the min number */ | |
1241 | if ((rrq->flags & IW_RETRY_LONG)) { | |
1242 | rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; | |
1243 | rrq->value = long_limit; | |
1244 | } else { | |
1245 | rrq->flags = IW_RETRY_LIMIT; | |
1246 | rrq->value = short_limit; | |
1247 | if (short_limit != long_limit) | |
1248 | rrq->flags |= IW_RETRY_SHORT; | |
1249 | } | |
1250 | } | |
1251 | ||
1252 | out: | |
1253 | orinoco_unlock(priv, &flags); | |
1254 | ||
1255 | return err; | |
1256 | } | |
1257 | ||
1258 | static int orinoco_ioctl_reset(struct net_device *dev, | |
1259 | struct iw_request_info *info, | |
1260 | void *wrqu, | |
1261 | char *extra) | |
1262 | { | |
ea60a6aa | 1263 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1264 | |
1265 | if (!capable(CAP_NET_ADMIN)) | |
1266 | return -EPERM; | |
1267 | ||
1268 | if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) { | |
1269 | printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name); | |
1270 | ||
1271 | /* Firmware reset */ | |
1272 | orinoco_reset(&priv->reset_work); | |
1273 | } else { | |
1274 | printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name); | |
1275 | ||
1276 | schedule_work(&priv->reset_work); | |
1277 | } | |
1278 | ||
1279 | return 0; | |
1280 | } | |
1281 | ||
1282 | static int orinoco_ioctl_setibssport(struct net_device *dev, | |
1283 | struct iw_request_info *info, | |
1284 | void *wrqu, | |
1285 | char *extra) | |
1286 | ||
1287 | { | |
ea60a6aa | 1288 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1289 | int val = *((int *) extra); |
1290 | unsigned long flags; | |
1291 | ||
1292 | if (orinoco_lock(priv, &flags) != 0) | |
1293 | return -EBUSY; | |
1294 | ||
30fab9e0 | 1295 | priv->ibss_port = val; |
cb1576a8 DK |
1296 | |
1297 | /* Actually update the mode we are using */ | |
1298 | set_port_type(priv); | |
1299 | ||
1300 | orinoco_unlock(priv, &flags); | |
1301 | return -EINPROGRESS; /* Call commit handler */ | |
1302 | } | |
1303 | ||
1304 | static int orinoco_ioctl_getibssport(struct net_device *dev, | |
1305 | struct iw_request_info *info, | |
1306 | void *wrqu, | |
1307 | char *extra) | |
1308 | { | |
ea60a6aa | 1309 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1310 | int *val = (int *) extra; |
1311 | ||
1312 | *val = priv->ibss_port; | |
1313 | return 0; | |
1314 | } | |
1315 | ||
1316 | static int orinoco_ioctl_setport3(struct net_device *dev, | |
1317 | struct iw_request_info *info, | |
1318 | void *wrqu, | |
1319 | char *extra) | |
1320 | { | |
ea60a6aa | 1321 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1322 | int val = *((int *) extra); |
1323 | int err = 0; | |
1324 | unsigned long flags; | |
1325 | ||
1326 | if (orinoco_lock(priv, &flags) != 0) | |
1327 | return -EBUSY; | |
1328 | ||
1329 | switch (val) { | |
1330 | case 0: /* Try to do IEEE ad-hoc mode */ | |
1331 | if (!priv->has_ibss) { | |
1332 | err = -EINVAL; | |
1333 | break; | |
1334 | } | |
1335 | priv->prefer_port3 = 0; | |
1336 | ||
1337 | break; | |
1338 | ||
1339 | case 1: /* Try to do Lucent proprietary ad-hoc mode */ | |
1340 | if (!priv->has_port3) { | |
1341 | err = -EINVAL; | |
1342 | break; | |
1343 | } | |
1344 | priv->prefer_port3 = 1; | |
1345 | break; | |
1346 | ||
1347 | default: | |
1348 | err = -EINVAL; | |
1349 | } | |
1350 | ||
1351 | if (!err) { | |
1352 | /* Actually update the mode we are using */ | |
1353 | set_port_type(priv); | |
1354 | err = -EINPROGRESS; | |
1355 | } | |
1356 | ||
1357 | orinoco_unlock(priv, &flags); | |
1358 | ||
1359 | return err; | |
1360 | } | |
1361 | ||
1362 | static int orinoco_ioctl_getport3(struct net_device *dev, | |
1363 | struct iw_request_info *info, | |
1364 | void *wrqu, | |
1365 | char *extra) | |
1366 | { | |
ea60a6aa | 1367 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1368 | int *val = (int *) extra; |
1369 | ||
1370 | *val = priv->prefer_port3; | |
1371 | return 0; | |
1372 | } | |
1373 | ||
1374 | static int orinoco_ioctl_setpreamble(struct net_device *dev, | |
1375 | struct iw_request_info *info, | |
1376 | void *wrqu, | |
1377 | char *extra) | |
1378 | { | |
ea60a6aa | 1379 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1380 | unsigned long flags; |
1381 | int val; | |
1382 | ||
1383 | if (!priv->has_preamble) | |
1384 | return -EOPNOTSUPP; | |
1385 | ||
1386 | /* 802.11b has recently defined some short preamble. | |
1387 | * Basically, the Phy header has been reduced in size. | |
1388 | * This increase performance, especially at high rates | |
1389 | * (the preamble is transmitted at 1Mb/s), unfortunately | |
1390 | * this give compatibility troubles... - Jean II */ | |
1391 | val = *((int *) extra); | |
1392 | ||
1393 | if (orinoco_lock(priv, &flags) != 0) | |
1394 | return -EBUSY; | |
1395 | ||
1396 | if (val) | |
1397 | priv->preamble = 1; | |
1398 | else | |
1399 | priv->preamble = 0; | |
1400 | ||
1401 | orinoco_unlock(priv, &flags); | |
1402 | ||
1403 | return -EINPROGRESS; /* Call commit handler */ | |
1404 | } | |
1405 | ||
1406 | static int orinoco_ioctl_getpreamble(struct net_device *dev, | |
1407 | struct iw_request_info *info, | |
1408 | void *wrqu, | |
1409 | char *extra) | |
1410 | { | |
ea60a6aa | 1411 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1412 | int *val = (int *) extra; |
1413 | ||
1414 | if (!priv->has_preamble) | |
1415 | return -EOPNOTSUPP; | |
1416 | ||
1417 | *val = priv->preamble; | |
1418 | return 0; | |
1419 | } | |
1420 | ||
1421 | /* ioctl interface to hermes_read_ltv() | |
1422 | * To use with iwpriv, pass the RID as the token argument, e.g. | |
1423 | * iwpriv get_rid [0xfc00] | |
1424 | * At least Wireless Tools 25 is required to use iwpriv. | |
1425 | * For Wireless Tools 25 and 26 append "dummy" are the end. */ | |
1426 | static int orinoco_ioctl_getrid(struct net_device *dev, | |
1427 | struct iw_request_info *info, | |
1428 | struct iw_point *data, | |
1429 | char *extra) | |
1430 | { | |
ea60a6aa | 1431 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1432 | hermes_t *hw = &priv->hw; |
1433 | int rid = data->flags; | |
1434 | u16 length; | |
1435 | int err; | |
1436 | unsigned long flags; | |
1437 | ||
1438 | /* It's a "get" function, but we don't want users to access the | |
1439 | * WEP key and other raw firmware data */ | |
1440 | if (!capable(CAP_NET_ADMIN)) | |
1441 | return -EPERM; | |
1442 | ||
1443 | if (rid < 0xfc00 || rid > 0xffff) | |
1444 | return -EINVAL; | |
1445 | ||
1446 | if (orinoco_lock(priv, &flags) != 0) | |
1447 | return -EBUSY; | |
1448 | ||
1449 | err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length, | |
1450 | extra); | |
1451 | if (err) | |
1452 | goto out; | |
1453 | ||
1454 | data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length), | |
1455 | MAX_RID_LEN); | |
1456 | ||
1457 | out: | |
1458 | orinoco_unlock(priv, &flags); | |
1459 | return err; | |
1460 | } | |
1461 | ||
cb1576a8 DK |
1462 | |
1463 | /* Commit handler, called after set operations */ | |
1464 | static int orinoco_ioctl_commit(struct net_device *dev, | |
1465 | struct iw_request_info *info, | |
1466 | void *wrqu, | |
1467 | char *extra) | |
1468 | { | |
ea60a6aa | 1469 | struct orinoco_private *priv = ndev_priv(dev); |
cb1576a8 DK |
1470 | unsigned long flags; |
1471 | int err = 0; | |
1472 | ||
1473 | if (!priv->open) | |
1474 | return 0; | |
1475 | ||
cb1576a8 DK |
1476 | if (orinoco_lock(priv, &flags) != 0) |
1477 | return err; | |
1478 | ||
721aa2f7 | 1479 | err = orinoco_commit(priv); |
cb1576a8 DK |
1480 | |
1481 | orinoco_unlock(priv, &flags); | |
1482 | return err; | |
1483 | } | |
1484 | ||
1485 | static const struct iw_priv_args orinoco_privtab[] = { | |
1486 | { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" }, | |
1487 | { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" }, | |
1488 | { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
1489 | 0, "set_port3" }, | |
1490 | { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
1491 | "get_port3" }, | |
1492 | { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
1493 | 0, "set_preamble" }, | |
1494 | { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
1495 | "get_preamble" }, | |
1496 | { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
1497 | 0, "set_ibssport" }, | |
1498 | { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
1499 | "get_ibssport" }, | |
1500 | { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN, | |
1501 | "get_rid" }, | |
1502 | }; | |
1503 | ||
1504 | ||
1505 | /* | |
1506 | * Structures to export the Wireless Handlers | |
1507 | */ | |
1508 | ||
1509 | #define STD_IW_HANDLER(id, func) \ | |
1510 | [IW_IOCTL_IDX(id)] = (iw_handler) func | |
1511 | static const iw_handler orinoco_handler[] = { | |
1512 | STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit), | |
ea60a6aa | 1513 | STD_IW_HANDLER(SIOCGIWNAME, cfg80211_wext_giwname), |
cb1576a8 DK |
1514 | STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq), |
1515 | STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq), | |
5217c571 DK |
1516 | STD_IW_HANDLER(SIOCSIWMODE, cfg80211_wext_siwmode), |
1517 | STD_IW_HANDLER(SIOCGIWMODE, cfg80211_wext_giwmode), | |
cb1576a8 DK |
1518 | STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens), |
1519 | STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens), | |
934fd51a | 1520 | STD_IW_HANDLER(SIOCGIWRANGE, cfg80211_wext_giwrange), |
cb1576a8 DK |
1521 | STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy), |
1522 | STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy), | |
1523 | STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy), | |
1524 | STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy), | |
1525 | STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap), | |
1526 | STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap), | |
c63cdbe8 DK |
1527 | STD_IW_HANDLER(SIOCSIWSCAN, cfg80211_wext_siwscan), |
1528 | STD_IW_HANDLER(SIOCGIWSCAN, cfg80211_wext_giwscan), | |
cb1576a8 DK |
1529 | STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid), |
1530 | STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid), | |
cb1576a8 DK |
1531 | STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate), |
1532 | STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate), | |
1533 | STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts), | |
1534 | STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts), | |
1535 | STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag), | |
1536 | STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag), | |
1537 | STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry), | |
1538 | STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode), | |
1539 | STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode), | |
1540 | STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower), | |
1541 | STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower), | |
1542 | STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie), | |
1543 | STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie), | |
1544 | STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme), | |
1545 | STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth), | |
1546 | STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth), | |
1547 | STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext), | |
1548 | STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext), | |
1549 | }; | |
1550 | ||
1551 | ||
1552 | /* | |
1553 | Added typecasting since we no longer use iwreq_data -- Moustafa | |
1554 | */ | |
1555 | static const iw_handler orinoco_private_handler[] = { | |
1556 | [0] = (iw_handler) orinoco_ioctl_reset, | |
1557 | [1] = (iw_handler) orinoco_ioctl_reset, | |
1558 | [2] = (iw_handler) orinoco_ioctl_setport3, | |
1559 | [3] = (iw_handler) orinoco_ioctl_getport3, | |
1560 | [4] = (iw_handler) orinoco_ioctl_setpreamble, | |
1561 | [5] = (iw_handler) orinoco_ioctl_getpreamble, | |
1562 | [6] = (iw_handler) orinoco_ioctl_setibssport, | |
1563 | [7] = (iw_handler) orinoco_ioctl_getibssport, | |
1564 | [9] = (iw_handler) orinoco_ioctl_getrid, | |
1565 | }; | |
1566 | ||
1567 | const struct iw_handler_def orinoco_handler_def = { | |
1568 | .num_standard = ARRAY_SIZE(orinoco_handler), | |
1569 | .num_private = ARRAY_SIZE(orinoco_private_handler), | |
1570 | .num_private_args = ARRAY_SIZE(orinoco_privtab), | |
1571 | .standard = orinoco_handler, | |
1572 | .private = orinoco_private_handler, | |
1573 | .private_args = orinoco_privtab, | |
1574 | .get_wireless_stats = orinoco_get_wireless_stats, | |
1575 | }; |