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