blob: 21db57815dda77349b6916ea5f581321039863ac [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
159 hermes_t *hw = &priv->hw;
160 int err = 0;
161 unsigned long flags;
162
163 if (orinoco_lock(priv, &flags) != 0)
164 return -EBUSY;
165
166 ap_addr->sa_family = ARPHRD_ETHER;
167 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
168 ETH_ALEN, NULL, ap_addr->sa_data);
169
170 orinoco_unlock(priv, &flags);
171
172 return err;
173}
174
David Kilroycb1576a2009-02-04 23:05:56 +0000175static int orinoco_ioctl_setiwencode(struct net_device *dev,
176 struct iw_request_info *info,
177 struct iw_point *erq,
178 char *keybuf)
179{
David Kilroyea60a6a2009-06-18 23:21:26 +0100180 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000181 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
182 int setindex = priv->tx_key;
183 int encode_alg = priv->encode_alg;
184 int restricted = priv->wep_restrict;
185 u16 xlen = 0;
186 int err = -EINPROGRESS; /* Call commit handler */
187 unsigned long flags;
188
189 if (!priv->has_wep)
190 return -EOPNOTSUPP;
191
192 if (erq->pointer) {
193 /* We actually have a key to set - check its length */
194 if (erq->length > LARGE_KEY_SIZE)
195 return -E2BIG;
196
197 if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
198 return -E2BIG;
199 }
200
201 if (orinoco_lock(priv, &flags) != 0)
202 return -EBUSY;
203
204 /* Clear any TKIP key we have */
205 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
206 (void) orinoco_clear_tkip_key(priv, setindex);
207
208 if (erq->length > 0) {
209 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
210 index = priv->tx_key;
211
212 /* Adjust key length to a supported value */
213 if (erq->length > SMALL_KEY_SIZE)
214 xlen = LARGE_KEY_SIZE;
215 else if (erq->length > 0)
216 xlen = SMALL_KEY_SIZE;
217 else
218 xlen = 0;
219
220 /* Switch on WEP if off */
221 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
222 setindex = index;
223 encode_alg = IW_ENCODE_ALG_WEP;
224 }
225 } else {
226 /* Important note : if the user do "iwconfig eth0 enc off",
227 * we will arrive there with an index of -1. This is valid
228 * but need to be taken care off... Jean II */
229 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
230 if ((index != -1) || (erq->flags == 0)) {
231 err = -EINVAL;
232 goto out;
233 }
234 } else {
235 /* Set the index : Check that the key is valid */
236 if (priv->keys[index].len == 0) {
237 err = -EINVAL;
238 goto out;
239 }
240 setindex = index;
241 }
242 }
243
244 if (erq->flags & IW_ENCODE_DISABLED)
245 encode_alg = IW_ENCODE_ALG_NONE;
246 if (erq->flags & IW_ENCODE_OPEN)
247 restricted = 0;
248 if (erq->flags & IW_ENCODE_RESTRICTED)
249 restricted = 1;
250
251 if (erq->pointer && erq->length > 0) {
252 priv->keys[index].len = cpu_to_le16(xlen);
253 memset(priv->keys[index].data, 0,
254 sizeof(priv->keys[index].data));
255 memcpy(priv->keys[index].data, keybuf, erq->length);
256 }
257 priv->tx_key = setindex;
258
259 /* Try fast key change if connected and only keys are changed */
260 if ((priv->encode_alg == encode_alg) &&
261 (priv->wep_restrict == restricted) &&
262 netif_carrier_ok(dev)) {
263 err = __orinoco_hw_setup_wepkeys(priv);
264 /* No need to commit if successful */
265 goto out;
266 }
267
268 priv->encode_alg = encode_alg;
269 priv->wep_restrict = restricted;
270
271 out:
272 orinoco_unlock(priv, &flags);
273
274 return err;
275}
276
277static int orinoco_ioctl_getiwencode(struct net_device *dev,
278 struct iw_request_info *info,
279 struct iw_point *erq,
280 char *keybuf)
281{
David Kilroyea60a6a2009-06-18 23:21:26 +0100282 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000283 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
284 u16 xlen = 0;
285 unsigned long flags;
286
287 if (!priv->has_wep)
288 return -EOPNOTSUPP;
289
290 if (orinoco_lock(priv, &flags) != 0)
291 return -EBUSY;
292
293 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
294 index = priv->tx_key;
295
296 erq->flags = 0;
297 if (!priv->encode_alg)
298 erq->flags |= IW_ENCODE_DISABLED;
299 erq->flags |= index + 1;
300
301 if (priv->wep_restrict)
302 erq->flags |= IW_ENCODE_RESTRICTED;
303 else
304 erq->flags |= IW_ENCODE_OPEN;
305
306 xlen = le16_to_cpu(priv->keys[index].len);
307
308 erq->length = xlen;
309
310 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
311
312 orinoco_unlock(priv, &flags);
313 return 0;
314}
315
316static int orinoco_ioctl_setessid(struct net_device *dev,
317 struct iw_request_info *info,
318 struct iw_point *erq,
319 char *essidbuf)
320{
David Kilroyea60a6a2009-06-18 23:21:26 +0100321 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000322 unsigned long flags;
323
324 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
325 * anyway... - Jean II */
326
327 /* Hum... Should not use Wireless Extension constant (may change),
328 * should use our own... - Jean II */
329 if (erq->length > IW_ESSID_MAX_SIZE)
330 return -E2BIG;
331
332 if (orinoco_lock(priv, &flags) != 0)
333 return -EBUSY;
334
335 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
336 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
337
338 /* If not ANY, get the new ESSID */
339 if (erq->flags)
340 memcpy(priv->desired_essid, essidbuf, erq->length);
341
342 orinoco_unlock(priv, &flags);
343
344 return -EINPROGRESS; /* Call commit handler */
345}
346
347static int orinoco_ioctl_getessid(struct net_device *dev,
348 struct iw_request_info *info,
349 struct iw_point *erq,
350 char *essidbuf)
351{
David Kilroyea60a6a2009-06-18 23:21:26 +0100352 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000353 int active;
354 int err = 0;
355 unsigned long flags;
356
357 if (netif_running(dev)) {
358 err = orinoco_hw_get_essid(priv, &active, essidbuf);
359 if (err < 0)
360 return err;
361 erq->length = err;
362 } else {
363 if (orinoco_lock(priv, &flags) != 0)
364 return -EBUSY;
365 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
366 erq->length = strlen(priv->desired_essid);
367 orinoco_unlock(priv, &flags);
368 }
369
370 erq->flags = 1;
371
372 return 0;
373}
374
375static int orinoco_ioctl_setnick(struct net_device *dev,
376 struct iw_request_info *info,
377 struct iw_point *nrq,
378 char *nickbuf)
379{
David Kilroyea60a6a2009-06-18 23:21:26 +0100380 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000381 unsigned long flags;
382
383 if (nrq->length > IW_ESSID_MAX_SIZE)
384 return -E2BIG;
385
386 if (orinoco_lock(priv, &flags) != 0)
387 return -EBUSY;
388
389 memset(priv->nick, 0, sizeof(priv->nick));
390 memcpy(priv->nick, nickbuf, nrq->length);
391
392 orinoco_unlock(priv, &flags);
393
394 return -EINPROGRESS; /* Call commit handler */
395}
396
397static int orinoco_ioctl_getnick(struct net_device *dev,
398 struct iw_request_info *info,
399 struct iw_point *nrq,
400 char *nickbuf)
401{
David Kilroyea60a6a2009-06-18 23:21:26 +0100402 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000403 unsigned long flags;
404
405 if (orinoco_lock(priv, &flags) != 0)
406 return -EBUSY;
407
408 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
409 orinoco_unlock(priv, &flags);
410
411 nrq->length = strlen(priv->nick);
412
413 return 0;
414}
415
416static int orinoco_ioctl_setfreq(struct net_device *dev,
417 struct iw_request_info *info,
418 struct iw_freq *frq,
419 char *extra)
420{
David Kilroyea60a6a2009-06-18 23:21:26 +0100421 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000422 int chan = -1;
423 unsigned long flags;
424 int err = -EINPROGRESS; /* Call commit handler */
425
426 /* In infrastructure mode the AP sets the channel */
David Kilroy5217c572009-06-18 23:21:32 +0100427 if (priv->iw_mode == NL80211_IFTYPE_STATION)
David Kilroycb1576a2009-02-04 23:05:56 +0000428 return -EBUSY;
429
430 if ((frq->e == 0) && (frq->m <= 1000)) {
431 /* Setting by channel number */
432 chan = frq->m;
433 } else {
434 /* Setting by frequency */
435 int denom = 1;
436 int i;
437
438 /* Calculate denominator to rescale to MHz */
439 for (i = 0; i < (6 - frq->e); i++)
440 denom *= 10;
441
442 chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
443 }
444
445 if ((chan < 1) || (chan > NUM_CHANNELS) ||
446 !(priv->channel_mask & (1 << (chan-1))))
447 return -EINVAL;
448
449 if (orinoco_lock(priv, &flags) != 0)
450 return -EBUSY;
451
452 priv->channel = chan;
David Kilroy5217c572009-06-18 23:21:32 +0100453 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
David Kilroycb1576a2009-02-04 23:05:56 +0000454 /* Fast channel change - no commit if successful */
455 hermes_t *hw = &priv->hw;
456 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
457 HERMES_TEST_SET_CHANNEL,
458 chan, NULL);
459 }
460 orinoco_unlock(priv, &flags);
461
462 return err;
463}
464
465static int orinoco_ioctl_getfreq(struct net_device *dev,
466 struct iw_request_info *info,
467 struct iw_freq *frq,
468 char *extra)
469{
David Kilroyea60a6a2009-06-18 23:21:26 +0100470 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000471 int tmp;
472
473 /* Locking done in there */
474 tmp = orinoco_hw_get_freq(priv);
475 if (tmp < 0)
476 return tmp;
477
478 frq->m = tmp * 100000;
479 frq->e = 1;
480
481 return 0;
482}
483
484static int orinoco_ioctl_getsens(struct net_device *dev,
485 struct iw_request_info *info,
486 struct iw_param *srq,
487 char *extra)
488{
David Kilroyea60a6a2009-06-18 23:21:26 +0100489 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000490 hermes_t *hw = &priv->hw;
491 u16 val;
492 int err;
493 unsigned long flags;
494
495 if (!priv->has_sensitivity)
496 return -EOPNOTSUPP;
497
498 if (orinoco_lock(priv, &flags) != 0)
499 return -EBUSY;
500 err = hermes_read_wordrec(hw, USER_BAP,
501 HERMES_RID_CNFSYSTEMSCALE, &val);
502 orinoco_unlock(priv, &flags);
503
504 if (err)
505 return err;
506
507 srq->value = val;
508 srq->fixed = 0; /* auto */
509
510 return 0;
511}
512
513static int orinoco_ioctl_setsens(struct net_device *dev,
514 struct iw_request_info *info,
515 struct iw_param *srq,
516 char *extra)
517{
David Kilroyea60a6a2009-06-18 23:21:26 +0100518 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000519 int val = srq->value;
520 unsigned long flags;
521
522 if (!priv->has_sensitivity)
523 return -EOPNOTSUPP;
524
525 if ((val < 1) || (val > 3))
526 return -EINVAL;
527
528 if (orinoco_lock(priv, &flags) != 0)
529 return -EBUSY;
530 priv->ap_density = val;
531 orinoco_unlock(priv, &flags);
532
533 return -EINPROGRESS; /* Call commit handler */
534}
535
536static int orinoco_ioctl_setrts(struct net_device *dev,
537 struct iw_request_info *info,
538 struct iw_param *rrq,
539 char *extra)
540{
David Kilroyea60a6a2009-06-18 23:21:26 +0100541 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000542 int val = rrq->value;
543 unsigned long flags;
544
545 if (rrq->disabled)
546 val = 2347;
547
548 if ((val < 0) || (val > 2347))
549 return -EINVAL;
550
551 if (orinoco_lock(priv, &flags) != 0)
552 return -EBUSY;
553
554 priv->rts_thresh = val;
555 orinoco_unlock(priv, &flags);
556
557 return -EINPROGRESS; /* Call commit handler */
558}
559
560static int orinoco_ioctl_getrts(struct net_device *dev,
561 struct iw_request_info *info,
562 struct iw_param *rrq,
563 char *extra)
564{
David Kilroyea60a6a2009-06-18 23:21:26 +0100565 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000566
567 rrq->value = priv->rts_thresh;
568 rrq->disabled = (rrq->value == 2347);
569 rrq->fixed = 1;
570
571 return 0;
572}
573
574static int orinoco_ioctl_setfrag(struct net_device *dev,
575 struct iw_request_info *info,
576 struct iw_param *frq,
577 char *extra)
578{
David Kilroyea60a6a2009-06-18 23:21:26 +0100579 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000580 int err = -EINPROGRESS; /* Call commit handler */
581 unsigned long flags;
582
583 if (orinoco_lock(priv, &flags) != 0)
584 return -EBUSY;
585
586 if (priv->has_mwo) {
587 if (frq->disabled)
588 priv->mwo_robust = 0;
589 else {
590 if (frq->fixed)
591 printk(KERN_WARNING "%s: Fixed fragmentation "
592 "is not supported on this firmware. "
593 "Using MWO robust instead.\n",
594 dev->name);
595 priv->mwo_robust = 1;
596 }
597 } else {
598 if (frq->disabled)
599 priv->frag_thresh = 2346;
600 else {
601 if ((frq->value < 256) || (frq->value > 2346))
602 err = -EINVAL;
603 else
604 /* must be even */
605 priv->frag_thresh = frq->value & ~0x1;
606 }
607 }
608
609 orinoco_unlock(priv, &flags);
610
611 return err;
612}
613
614static int orinoco_ioctl_getfrag(struct net_device *dev,
615 struct iw_request_info *info,
616 struct iw_param *frq,
617 char *extra)
618{
David Kilroyea60a6a2009-06-18 23:21:26 +0100619 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000620 hermes_t *hw = &priv->hw;
621 int err;
622 u16 val;
623 unsigned long flags;
624
625 if (orinoco_lock(priv, &flags) != 0)
626 return -EBUSY;
627
628 if (priv->has_mwo) {
629 err = hermes_read_wordrec(hw, USER_BAP,
630 HERMES_RID_CNFMWOROBUST_AGERE,
631 &val);
632 if (err)
633 val = 0;
634
635 frq->value = val ? 2347 : 0;
636 frq->disabled = !val;
637 frq->fixed = 0;
638 } else {
639 err = hermes_read_wordrec(hw, USER_BAP,
640 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
641 &val);
642 if (err)
643 val = 0;
644
645 frq->value = val;
646 frq->disabled = (val >= 2346);
647 frq->fixed = 1;
648 }
649
650 orinoco_unlock(priv, &flags);
651
652 return err;
653}
654
655static int orinoco_ioctl_setrate(struct net_device *dev,
656 struct iw_request_info *info,
657 struct iw_param *rrq,
658 char *extra)
659{
David Kilroyea60a6a2009-06-18 23:21:26 +0100660 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000661 int ratemode;
662 int bitrate; /* 100s of kilobits */
663 unsigned long flags;
664
665 /* As the user space doesn't know our highest rate, it uses -1
666 * to ask us to set the highest rate. Test it using "iwconfig
667 * ethX rate auto" - Jean II */
668 if (rrq->value == -1)
669 bitrate = 110;
670 else {
671 if (rrq->value % 100000)
672 return -EINVAL;
673 bitrate = rrq->value / 100000;
674 }
675
676 ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
677
678 if (ratemode == -1)
679 return -EINVAL;
680
681 if (orinoco_lock(priv, &flags) != 0)
682 return -EBUSY;
683 priv->bitratemode = ratemode;
684 orinoco_unlock(priv, &flags);
685
686 return -EINPROGRESS;
687}
688
689static int orinoco_ioctl_getrate(struct net_device *dev,
690 struct iw_request_info *info,
691 struct iw_param *rrq,
692 char *extra)
693{
David Kilroyea60a6a2009-06-18 23:21:26 +0100694 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000695 int err = 0;
696 int bitrate, automatic;
697 unsigned long flags;
698
699 if (orinoco_lock(priv, &flags) != 0)
700 return -EBUSY;
701
702 orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
703
704 /* If the interface is running we try to find more about the
705 current mode */
706 if (netif_running(dev))
707 err = orinoco_hw_get_act_bitrate(priv, &bitrate);
708
709 orinoco_unlock(priv, &flags);
710
711 rrq->value = bitrate;
712 rrq->fixed = !automatic;
713 rrq->disabled = 0;
714
715 return err;
716}
717
718static int orinoco_ioctl_setpower(struct net_device *dev,
719 struct iw_request_info *info,
720 struct iw_param *prq,
721 char *extra)
722{
David Kilroyea60a6a2009-06-18 23:21:26 +0100723 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000724 int err = -EINPROGRESS; /* Call commit handler */
725 unsigned long flags;
726
727 if (orinoco_lock(priv, &flags) != 0)
728 return -EBUSY;
729
730 if (prq->disabled) {
731 priv->pm_on = 0;
732 } else {
733 switch (prq->flags & IW_POWER_MODE) {
734 case IW_POWER_UNICAST_R:
735 priv->pm_mcast = 0;
736 priv->pm_on = 1;
737 break;
738 case IW_POWER_ALL_R:
739 priv->pm_mcast = 1;
740 priv->pm_on = 1;
741 break;
742 case IW_POWER_ON:
743 /* No flags : but we may have a value - Jean II */
744 break;
745 default:
746 err = -EINVAL;
747 goto out;
748 }
749
750 if (prq->flags & IW_POWER_TIMEOUT) {
751 priv->pm_on = 1;
752 priv->pm_timeout = prq->value / 1000;
753 }
754 if (prq->flags & IW_POWER_PERIOD) {
755 priv->pm_on = 1;
756 priv->pm_period = prq->value / 1000;
757 }
758 /* It's valid to not have a value if we are just toggling
759 * the flags... Jean II */
760 if (!priv->pm_on) {
761 err = -EINVAL;
762 goto out;
763 }
764 }
765
766 out:
767 orinoco_unlock(priv, &flags);
768
769 return err;
770}
771
772static int orinoco_ioctl_getpower(struct net_device *dev,
773 struct iw_request_info *info,
774 struct iw_param *prq,
775 char *extra)
776{
David Kilroyea60a6a2009-06-18 23:21:26 +0100777 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000778 hermes_t *hw = &priv->hw;
779 int err = 0;
780 u16 enable, period, timeout, mcast;
781 unsigned long flags;
782
783 if (orinoco_lock(priv, &flags) != 0)
784 return -EBUSY;
785
786 err = hermes_read_wordrec(hw, USER_BAP,
787 HERMES_RID_CNFPMENABLED, &enable);
788 if (err)
789 goto out;
790
791 err = hermes_read_wordrec(hw, USER_BAP,
792 HERMES_RID_CNFMAXSLEEPDURATION, &period);
793 if (err)
794 goto out;
795
796 err = hermes_read_wordrec(hw, USER_BAP,
797 HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
798 if (err)
799 goto out;
800
801 err = hermes_read_wordrec(hw, USER_BAP,
802 HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
803 if (err)
804 goto out;
805
806 prq->disabled = !enable;
807 /* Note : by default, display the period */
808 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
809 prq->flags = IW_POWER_TIMEOUT;
810 prq->value = timeout * 1000;
811 } else {
812 prq->flags = IW_POWER_PERIOD;
813 prq->value = period * 1000;
814 }
815 if (mcast)
816 prq->flags |= IW_POWER_ALL_R;
817 else
818 prq->flags |= IW_POWER_UNICAST_R;
819
820 out:
821 orinoco_unlock(priv, &flags);
822
823 return err;
824}
825
826static int orinoco_ioctl_set_encodeext(struct net_device *dev,
827 struct iw_request_info *info,
828 union iwreq_data *wrqu,
829 char *extra)
830{
David Kilroyea60a6a2009-06-18 23:21:26 +0100831 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000832 struct iw_point *encoding = &wrqu->encoding;
833 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
834 int idx, alg = ext->alg, set_key = 1;
835 unsigned long flags;
836 int err = -EINVAL;
837 u16 key_len;
838
839 if (orinoco_lock(priv, &flags) != 0)
840 return -EBUSY;
841
842 /* Determine and validate the key index */
843 idx = encoding->flags & IW_ENCODE_INDEX;
844 if (idx) {
845 if ((idx < 1) || (idx > 4))
846 goto out;
847 idx--;
848 } else
849 idx = priv->tx_key;
850
851 if (encoding->flags & IW_ENCODE_DISABLED)
852 alg = IW_ENCODE_ALG_NONE;
853
854 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
855 /* Clear any TKIP TX key we had */
856 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
857 }
858
859 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
860 priv->tx_key = idx;
861 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
862 (ext->key_len > 0)) ? 1 : 0;
863 }
864
865 if (set_key) {
866 /* Set the requested key first */
867 switch (alg) {
868 case IW_ENCODE_ALG_NONE:
869 priv->encode_alg = alg;
870 priv->keys[idx].len = 0;
871 break;
872
873 case IW_ENCODE_ALG_WEP:
874 if (ext->key_len > SMALL_KEY_SIZE)
875 key_len = LARGE_KEY_SIZE;
876 else if (ext->key_len > 0)
877 key_len = SMALL_KEY_SIZE;
878 else
879 goto out;
880
881 priv->encode_alg = alg;
882 priv->keys[idx].len = cpu_to_le16(key_len);
883
884 key_len = min(ext->key_len, key_len);
885
886 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
887 memcpy(priv->keys[idx].data, ext->key, key_len);
888 break;
889
890 case IW_ENCODE_ALG_TKIP:
891 {
David Kilroycb1576a2009-02-04 23:05:56 +0000892 u8 *tkip_iv = NULL;
893
894 if (!priv->has_wpa ||
895 (ext->key_len > sizeof(priv->tkip_key[0])))
896 goto out;
897
898 priv->encode_alg = alg;
899 memset(&priv->tkip_key[idx], 0,
900 sizeof(priv->tkip_key[idx]));
901 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
902
903 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
904 tkip_iv = &ext->rx_seq[0];
905
David Kilroy98e5f402009-06-18 23:21:25 +0100906 err = __orinoco_hw_set_tkip_key(priv, idx,
David Kilroycb1576a2009-02-04 23:05:56 +0000907 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
908 (u8 *) &priv->tkip_key[idx],
909 tkip_iv, NULL);
910 if (err)
911 printk(KERN_ERR "%s: Error %d setting TKIP key"
912 "\n", dev->name, err);
913
914 goto out;
915 }
916 default:
917 goto out;
918 }
919 }
920 err = -EINPROGRESS;
921 out:
922 orinoco_unlock(priv, &flags);
923
924 return err;
925}
926
927static int orinoco_ioctl_get_encodeext(struct net_device *dev,
928 struct iw_request_info *info,
929 union iwreq_data *wrqu,
930 char *extra)
931{
David Kilroyea60a6a2009-06-18 23:21:26 +0100932 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000933 struct iw_point *encoding = &wrqu->encoding;
934 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
935 int idx, max_key_len;
936 unsigned long flags;
937 int err;
938
939 if (orinoco_lock(priv, &flags) != 0)
940 return -EBUSY;
941
942 err = -EINVAL;
943 max_key_len = encoding->length - sizeof(*ext);
944 if (max_key_len < 0)
945 goto out;
946
947 idx = encoding->flags & IW_ENCODE_INDEX;
948 if (idx) {
949 if ((idx < 1) || (idx > 4))
950 goto out;
951 idx--;
952 } else
953 idx = priv->tx_key;
954
955 encoding->flags = idx + 1;
956 memset(ext, 0, sizeof(*ext));
957
958 ext->alg = priv->encode_alg;
959 switch (priv->encode_alg) {
960 case IW_ENCODE_ALG_NONE:
961 ext->key_len = 0;
962 encoding->flags |= IW_ENCODE_DISABLED;
963 break;
964 case IW_ENCODE_ALG_WEP:
965 ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
966 max_key_len);
967 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
968 encoding->flags |= IW_ENCODE_ENABLED;
969 break;
970 case IW_ENCODE_ALG_TKIP:
971 ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
972 max_key_len);
973 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
974 encoding->flags |= IW_ENCODE_ENABLED;
975 break;
976 }
977
978 err = 0;
979 out:
980 orinoco_unlock(priv, &flags);
981
982 return err;
983}
984
985static int orinoco_ioctl_set_auth(struct net_device *dev,
986 struct iw_request_info *info,
987 union iwreq_data *wrqu, char *extra)
988{
David Kilroyea60a6a2009-06-18 23:21:26 +0100989 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000990 hermes_t *hw = &priv->hw;
991 struct iw_param *param = &wrqu->param;
992 unsigned long flags;
993 int ret = -EINPROGRESS;
994
995 if (orinoco_lock(priv, &flags) != 0)
996 return -EBUSY;
997
998 switch (param->flags & IW_AUTH_INDEX) {
999 case IW_AUTH_WPA_VERSION:
1000 case IW_AUTH_CIPHER_PAIRWISE:
1001 case IW_AUTH_CIPHER_GROUP:
1002 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1003 case IW_AUTH_PRIVACY_INVOKED:
1004 case IW_AUTH_DROP_UNENCRYPTED:
1005 /*
1006 * orinoco does not use these parameters
1007 */
1008 break;
1009
1010 case IW_AUTH_KEY_MGMT:
1011 /* wl_lkm implies value 2 == PSK for Hermes I
1012 * which ties in with WEXT
1013 * no other hints tho :(
1014 */
1015 priv->key_mgmt = param->value;
1016 break;
1017
1018 case IW_AUTH_TKIP_COUNTERMEASURES:
1019 /* When countermeasures are enabled, shut down the
1020 * card; when disabled, re-enable the card. This must
1021 * take effect immediately.
1022 *
1023 * TODO: Make sure that the EAPOL message is getting
1024 * out before card disabled
1025 */
1026 if (param->value) {
1027 priv->tkip_cm_active = 1;
1028 ret = hermes_enable_port(hw, 0);
1029 } else {
1030 priv->tkip_cm_active = 0;
1031 ret = hermes_disable_port(hw, 0);
1032 }
1033 break;
1034
1035 case IW_AUTH_80211_AUTH_ALG:
1036 if (param->value & IW_AUTH_ALG_SHARED_KEY)
1037 priv->wep_restrict = 1;
1038 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
1039 priv->wep_restrict = 0;
1040 else
1041 ret = -EINVAL;
1042 break;
1043
1044 case IW_AUTH_WPA_ENABLED:
1045 if (priv->has_wpa) {
1046 priv->wpa_enabled = param->value ? 1 : 0;
1047 } else {
1048 if (param->value)
1049 ret = -EOPNOTSUPP;
1050 /* else silently accept disable of WPA */
1051 priv->wpa_enabled = 0;
1052 }
1053 break;
1054
1055 default:
1056 ret = -EOPNOTSUPP;
1057 }
1058
1059 orinoco_unlock(priv, &flags);
1060 return ret;
1061}
1062
1063static int orinoco_ioctl_get_auth(struct net_device *dev,
1064 struct iw_request_info *info,
1065 union iwreq_data *wrqu, char *extra)
1066{
David Kilroyea60a6a2009-06-18 23:21:26 +01001067 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001068 struct iw_param *param = &wrqu->param;
1069 unsigned long flags;
1070 int ret = 0;
1071
1072 if (orinoco_lock(priv, &flags) != 0)
1073 return -EBUSY;
1074
1075 switch (param->flags & IW_AUTH_INDEX) {
1076 case IW_AUTH_KEY_MGMT:
1077 param->value = priv->key_mgmt;
1078 break;
1079
1080 case IW_AUTH_TKIP_COUNTERMEASURES:
1081 param->value = priv->tkip_cm_active;
1082 break;
1083
1084 case IW_AUTH_80211_AUTH_ALG:
1085 if (priv->wep_restrict)
1086 param->value = IW_AUTH_ALG_SHARED_KEY;
1087 else
1088 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
1089 break;
1090
1091 case IW_AUTH_WPA_ENABLED:
1092 param->value = priv->wpa_enabled;
1093 break;
1094
1095 default:
1096 ret = -EOPNOTSUPP;
1097 }
1098
1099 orinoco_unlock(priv, &flags);
1100 return ret;
1101}
1102
1103static int orinoco_ioctl_set_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 u8 *buf;
1109 unsigned long flags;
1110
1111 /* cut off at IEEE80211_MAX_DATA_LEN */
1112 if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
1113 (wrqu->data.length && (extra == NULL)))
1114 return -EINVAL;
1115
1116 if (wrqu->data.length) {
1117 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
1118 if (buf == NULL)
1119 return -ENOMEM;
1120
1121 memcpy(buf, extra, wrqu->data.length);
1122 } else
1123 buf = NULL;
1124
1125 if (orinoco_lock(priv, &flags) != 0) {
1126 kfree(buf);
1127 return -EBUSY;
1128 }
1129
1130 kfree(priv->wpa_ie);
1131 priv->wpa_ie = buf;
1132 priv->wpa_ie_len = wrqu->data.length;
1133
1134 if (priv->wpa_ie) {
1135 /* Looks like wl_lkm wants to check the auth alg, and
1136 * somehow pass it to the firmware.
1137 * Instead it just calls the key mgmt rid
1138 * - we do this in set auth.
1139 */
1140 }
1141
1142 orinoco_unlock(priv, &flags);
1143 return 0;
1144}
1145
1146static int orinoco_ioctl_get_genie(struct net_device *dev,
1147 struct iw_request_info *info,
1148 union iwreq_data *wrqu, char *extra)
1149{
David Kilroyea60a6a2009-06-18 23:21:26 +01001150 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001151 unsigned long flags;
1152 int err = 0;
1153
1154 if (orinoco_lock(priv, &flags) != 0)
1155 return -EBUSY;
1156
1157 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
1158 wrqu->data.length = 0;
1159 goto out;
1160 }
1161
1162 if (wrqu->data.length < priv->wpa_ie_len) {
1163 err = -E2BIG;
1164 goto out;
1165 }
1166
1167 wrqu->data.length = priv->wpa_ie_len;
1168 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
1169
1170out:
1171 orinoco_unlock(priv, &flags);
1172 return err;
1173}
1174
1175static int orinoco_ioctl_set_mlme(struct net_device *dev,
1176 struct iw_request_info *info,
1177 union iwreq_data *wrqu, char *extra)
1178{
David Kilroyea60a6a2009-06-18 23:21:26 +01001179 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001180 hermes_t *hw = &priv->hw;
1181 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1182 unsigned long flags;
1183 int ret = 0;
1184
1185 if (orinoco_lock(priv, &flags) != 0)
1186 return -EBUSY;
1187
1188 switch (mlme->cmd) {
1189 case IW_MLME_DEAUTH:
1190 /* silently ignore */
1191 break;
1192
1193 case IW_MLME_DISASSOC:
1194 {
1195 struct {
1196 u8 addr[ETH_ALEN];
1197 __le16 reason_code;
1198 } __attribute__ ((packed)) buf;
1199
1200 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
1201 buf.reason_code = cpu_to_le16(mlme->reason_code);
1202 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
1203 HERMES_RID_CNFDISASSOCIATE,
1204 &buf);
1205 break;
1206 }
1207 default:
1208 ret = -EOPNOTSUPP;
1209 }
1210
1211 orinoco_unlock(priv, &flags);
1212 return ret;
1213}
1214
1215static int orinoco_ioctl_getretry(struct net_device *dev,
1216 struct iw_request_info *info,
1217 struct iw_param *rrq,
1218 char *extra)
1219{
David Kilroyea60a6a2009-06-18 23:21:26 +01001220 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001221 hermes_t *hw = &priv->hw;
1222 int err = 0;
1223 u16 short_limit, long_limit, lifetime;
1224 unsigned long flags;
1225
1226 if (orinoco_lock(priv, &flags) != 0)
1227 return -EBUSY;
1228
1229 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
1230 &short_limit);
1231 if (err)
1232 goto out;
1233
1234 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
1235 &long_limit);
1236 if (err)
1237 goto out;
1238
1239 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
1240 &lifetime);
1241 if (err)
1242 goto out;
1243
1244 rrq->disabled = 0; /* Can't be disabled */
1245
1246 /* Note : by default, display the retry number */
1247 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1248 rrq->flags = IW_RETRY_LIFETIME;
1249 rrq->value = lifetime * 1000; /* ??? */
1250 } else {
1251 /* By default, display the min number */
1252 if ((rrq->flags & IW_RETRY_LONG)) {
1253 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1254 rrq->value = long_limit;
1255 } else {
1256 rrq->flags = IW_RETRY_LIMIT;
1257 rrq->value = short_limit;
1258 if (short_limit != long_limit)
1259 rrq->flags |= IW_RETRY_SHORT;
1260 }
1261 }
1262
1263 out:
1264 orinoco_unlock(priv, &flags);
1265
1266 return err;
1267}
1268
1269static int orinoco_ioctl_reset(struct net_device *dev,
1270 struct iw_request_info *info,
1271 void *wrqu,
1272 char *extra)
1273{
David Kilroyea60a6a2009-06-18 23:21:26 +01001274 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001275
1276 if (!capable(CAP_NET_ADMIN))
1277 return -EPERM;
1278
1279 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
1280 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
1281
1282 /* Firmware reset */
1283 orinoco_reset(&priv->reset_work);
1284 } else {
1285 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
1286
1287 schedule_work(&priv->reset_work);
1288 }
1289
1290 return 0;
1291}
1292
1293static int orinoco_ioctl_setibssport(struct net_device *dev,
1294 struct iw_request_info *info,
1295 void *wrqu,
1296 char *extra)
1297
1298{
David Kilroyea60a6a2009-06-18 23:21:26 +01001299 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001300 int val = *((int *) extra);
1301 unsigned long flags;
1302
1303 if (orinoco_lock(priv, &flags) != 0)
1304 return -EBUSY;
1305
1306 priv->ibss_port = val ;
1307
1308 /* Actually update the mode we are using */
1309 set_port_type(priv);
1310
1311 orinoco_unlock(priv, &flags);
1312 return -EINPROGRESS; /* Call commit handler */
1313}
1314
1315static int orinoco_ioctl_getibssport(struct net_device *dev,
1316 struct iw_request_info *info,
1317 void *wrqu,
1318 char *extra)
1319{
David Kilroyea60a6a2009-06-18 23:21:26 +01001320 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001321 int *val = (int *) extra;
1322
1323 *val = priv->ibss_port;
1324 return 0;
1325}
1326
1327static int orinoco_ioctl_setport3(struct net_device *dev,
1328 struct iw_request_info *info,
1329 void *wrqu,
1330 char *extra)
1331{
David Kilroyea60a6a2009-06-18 23:21:26 +01001332 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001333 int val = *((int *) extra);
1334 int err = 0;
1335 unsigned long flags;
1336
1337 if (orinoco_lock(priv, &flags) != 0)
1338 return -EBUSY;
1339
1340 switch (val) {
1341 case 0: /* Try to do IEEE ad-hoc mode */
1342 if (!priv->has_ibss) {
1343 err = -EINVAL;
1344 break;
1345 }
1346 priv->prefer_port3 = 0;
1347
1348 break;
1349
1350 case 1: /* Try to do Lucent proprietary ad-hoc mode */
1351 if (!priv->has_port3) {
1352 err = -EINVAL;
1353 break;
1354 }
1355 priv->prefer_port3 = 1;
1356 break;
1357
1358 default:
1359 err = -EINVAL;
1360 }
1361
1362 if (!err) {
1363 /* Actually update the mode we are using */
1364 set_port_type(priv);
1365 err = -EINPROGRESS;
1366 }
1367
1368 orinoco_unlock(priv, &flags);
1369
1370 return err;
1371}
1372
1373static int orinoco_ioctl_getport3(struct net_device *dev,
1374 struct iw_request_info *info,
1375 void *wrqu,
1376 char *extra)
1377{
David Kilroyea60a6a2009-06-18 23:21:26 +01001378 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001379 int *val = (int *) extra;
1380
1381 *val = priv->prefer_port3;
1382 return 0;
1383}
1384
1385static int orinoco_ioctl_setpreamble(struct net_device *dev,
1386 struct iw_request_info *info,
1387 void *wrqu,
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 unsigned long flags;
1392 int val;
1393
1394 if (!priv->has_preamble)
1395 return -EOPNOTSUPP;
1396
1397 /* 802.11b has recently defined some short preamble.
1398 * Basically, the Phy header has been reduced in size.
1399 * This increase performance, especially at high rates
1400 * (the preamble is transmitted at 1Mb/s), unfortunately
1401 * this give compatibility troubles... - Jean II */
1402 val = *((int *) extra);
1403
1404 if (orinoco_lock(priv, &flags) != 0)
1405 return -EBUSY;
1406
1407 if (val)
1408 priv->preamble = 1;
1409 else
1410 priv->preamble = 0;
1411
1412 orinoco_unlock(priv, &flags);
1413
1414 return -EINPROGRESS; /* Call commit handler */
1415}
1416
1417static int orinoco_ioctl_getpreamble(struct net_device *dev,
1418 struct iw_request_info *info,
1419 void *wrqu,
1420 char *extra)
1421{
David Kilroyea60a6a2009-06-18 23:21:26 +01001422 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001423 int *val = (int *) extra;
1424
1425 if (!priv->has_preamble)
1426 return -EOPNOTSUPP;
1427
1428 *val = priv->preamble;
1429 return 0;
1430}
1431
1432/* ioctl interface to hermes_read_ltv()
1433 * To use with iwpriv, pass the RID as the token argument, e.g.
1434 * iwpriv get_rid [0xfc00]
1435 * At least Wireless Tools 25 is required to use iwpriv.
1436 * For Wireless Tools 25 and 26 append "dummy" are the end. */
1437static int orinoco_ioctl_getrid(struct net_device *dev,
1438 struct iw_request_info *info,
1439 struct iw_point *data,
1440 char *extra)
1441{
David Kilroyea60a6a2009-06-18 23:21:26 +01001442 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001443 hermes_t *hw = &priv->hw;
1444 int rid = data->flags;
1445 u16 length;
1446 int err;
1447 unsigned long flags;
1448
1449 /* It's a "get" function, but we don't want users to access the
1450 * WEP key and other raw firmware data */
1451 if (!capable(CAP_NET_ADMIN))
1452 return -EPERM;
1453
1454 if (rid < 0xfc00 || rid > 0xffff)
1455 return -EINVAL;
1456
1457 if (orinoco_lock(priv, &flags) != 0)
1458 return -EBUSY;
1459
1460 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
1461 extra);
1462 if (err)
1463 goto out;
1464
1465 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
1466 MAX_RID_LEN);
1467
1468 out:
1469 orinoco_unlock(priv, &flags);
1470 return err;
1471}
1472
David Kilroycb1576a2009-02-04 23:05:56 +00001473
1474/* Commit handler, called after set operations */
1475static int orinoco_ioctl_commit(struct net_device *dev,
1476 struct iw_request_info *info,
1477 void *wrqu,
1478 char *extra)
1479{
David Kilroyea60a6a2009-06-18 23:21:26 +01001480 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001481 unsigned long flags;
1482 int err = 0;
1483
1484 if (!priv->open)
1485 return 0;
1486
David Kilroycb1576a2009-02-04 23:05:56 +00001487 if (orinoco_lock(priv, &flags) != 0)
1488 return err;
1489
David Kilroy721aa2f2009-06-18 23:21:31 +01001490 err = orinoco_commit(priv);
David Kilroycb1576a2009-02-04 23:05:56 +00001491
1492 orinoco_unlock(priv, &flags);
1493 return err;
1494}
1495
1496static const struct iw_priv_args orinoco_privtab[] = {
1497 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
1498 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
1499 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1500 0, "set_port3" },
1501 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1502 "get_port3" },
1503 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1504 0, "set_preamble" },
1505 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1506 "get_preamble" },
1507 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1508 0, "set_ibssport" },
1509 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1510 "get_ibssport" },
1511 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
1512 "get_rid" },
1513};
1514
1515
1516/*
1517 * Structures to export the Wireless Handlers
1518 */
1519
1520#define STD_IW_HANDLER(id, func) \
1521 [IW_IOCTL_IDX(id)] = (iw_handler) func
1522static const iw_handler orinoco_handler[] = {
1523 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
David Kilroyea60a6a2009-06-18 23:21:26 +01001524 STD_IW_HANDLER(SIOCGIWNAME, cfg80211_wext_giwname),
David Kilroycb1576a2009-02-04 23:05:56 +00001525 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
1526 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
David Kilroy5217c572009-06-18 23:21:32 +01001527 STD_IW_HANDLER(SIOCSIWMODE, cfg80211_wext_siwmode),
1528 STD_IW_HANDLER(SIOCGIWMODE, cfg80211_wext_giwmode),
David Kilroycb1576a2009-02-04 23:05:56 +00001529 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
1530 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
David Kilroy934fd512009-06-18 23:21:34 +01001531 STD_IW_HANDLER(SIOCGIWRANGE, cfg80211_wext_giwrange),
David Kilroycb1576a2009-02-04 23:05:56 +00001532 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1533 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1534 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1535 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
1536 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
1537 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
David Kilroyc63cdbe2009-06-18 23:21:33 +01001538 STD_IW_HANDLER(SIOCSIWSCAN, cfg80211_wext_siwscan),
1539 STD_IW_HANDLER(SIOCGIWSCAN, cfg80211_wext_giwscan),
David Kilroycb1576a2009-02-04 23:05:56 +00001540 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
1541 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
1542 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
1543 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
1544 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
1545 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
1546 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
1547 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
1548 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
1549 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
1550 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
1551 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
1552 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
1553 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
1554 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
1555 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
1556 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
1557 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
1558 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
1559 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
1560 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
1561 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
1562};
1563
1564
1565/*
1566 Added typecasting since we no longer use iwreq_data -- Moustafa
1567 */
1568static const iw_handler orinoco_private_handler[] = {
1569 [0] = (iw_handler) orinoco_ioctl_reset,
1570 [1] = (iw_handler) orinoco_ioctl_reset,
1571 [2] = (iw_handler) orinoco_ioctl_setport3,
1572 [3] = (iw_handler) orinoco_ioctl_getport3,
1573 [4] = (iw_handler) orinoco_ioctl_setpreamble,
1574 [5] = (iw_handler) orinoco_ioctl_getpreamble,
1575 [6] = (iw_handler) orinoco_ioctl_setibssport,
1576 [7] = (iw_handler) orinoco_ioctl_getibssport,
1577 [9] = (iw_handler) orinoco_ioctl_getrid,
1578};
1579
1580const struct iw_handler_def orinoco_handler_def = {
1581 .num_standard = ARRAY_SIZE(orinoco_handler),
1582 .num_private = ARRAY_SIZE(orinoco_private_handler),
1583 .num_private_args = ARRAY_SIZE(orinoco_privtab),
1584 .standard = orinoco_handler,
1585 .private = orinoco_private_handler,
1586 .private_args = orinoco_privtab,
1587 .get_wireless_stats = orinoco_get_wireless_stats,
1588};