blob: 74892e1d34ae5c56e4d4b2f7927ffbea1948cdec [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
55 if (priv->iw_mode == IW_MODE_ADHOC) {
56 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
127 if (priv->iw_mode != IW_MODE_INFRA) {
128 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
175static int orinoco_ioctl_setmode(struct net_device *dev,
176 struct iw_request_info *info,
177 u32 *mode,
178 char *extra)
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 err = -EINPROGRESS; /* Call commit handler */
182 unsigned long flags;
183
184 if (priv->iw_mode == *mode)
185 return 0;
186
187 if (orinoco_lock(priv, &flags) != 0)
188 return -EBUSY;
189
190 switch (*mode) {
191 case IW_MODE_ADHOC:
192 if (!priv->has_ibss && !priv->has_port3)
193 err = -EOPNOTSUPP;
194 break;
195
196 case IW_MODE_INFRA:
197 break;
198
199 case IW_MODE_MONITOR:
200 if (priv->broken_monitor && !force_monitor) {
201 printk(KERN_WARNING "%s: Monitor mode support is "
202 "buggy in this firmware, not enabling\n",
203 dev->name);
204 err = -EOPNOTSUPP;
205 }
206 break;
207
208 default:
209 err = -EOPNOTSUPP;
210 break;
211 }
212
213 if (err == -EINPROGRESS) {
214 priv->iw_mode = *mode;
215 set_port_type(priv);
216 }
217
218 orinoco_unlock(priv, &flags);
219
220 return err;
221}
222
223static int orinoco_ioctl_getmode(struct net_device *dev,
224 struct iw_request_info *info,
225 u32 *mode,
226 char *extra)
227{
David Kilroyea60a6a2009-06-18 23:21:26 +0100228 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000229
230 *mode = priv->iw_mode;
231 return 0;
232}
233
234static int orinoco_ioctl_getiwrange(struct net_device *dev,
235 struct iw_request_info *info,
236 struct iw_point *rrq,
237 char *extra)
238{
David Kilroyea60a6a2009-06-18 23:21:26 +0100239 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000240 int err = 0;
241 struct iw_range *range = (struct iw_range *) extra;
242 int numrates;
243 int i, k;
244
245 rrq->length = sizeof(struct iw_range);
246 memset(range, 0, sizeof(struct iw_range));
247
248 range->we_version_compiled = WIRELESS_EXT;
249 range->we_version_source = 22;
250
251 /* Set available channels/frequencies */
252 range->num_channels = NUM_CHANNELS;
253 k = 0;
254 for (i = 0; i < NUM_CHANNELS; i++) {
255 if (priv->channel_mask & (1 << i)) {
256 range->freq[k].i = i + 1;
257 range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
258 100000);
259 range->freq[k].e = 1;
260 k++;
261 }
262
263 if (k >= IW_MAX_FREQUENCIES)
264 break;
265 }
266 range->num_frequency = k;
267 range->sensitivity = 3;
268
269 if (priv->has_wep) {
270 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
271 range->encoding_size[0] = SMALL_KEY_SIZE;
272 range->num_encoding_sizes = 1;
273
274 if (priv->has_big_wep) {
275 range->encoding_size[1] = LARGE_KEY_SIZE;
276 range->num_encoding_sizes = 2;
277 }
278 }
279
280 if (priv->has_wpa)
281 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
282
283 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))) {
284 /* Quality stats meaningless in ad-hoc mode */
285 } else {
286 range->max_qual.qual = 0x8b - 0x2f;
287 range->max_qual.level = 0x2f - 0x95 - 1;
288 range->max_qual.noise = 0x2f - 0x95 - 1;
289 /* Need to get better values */
290 range->avg_qual.qual = 0x24;
291 range->avg_qual.level = 0xC2;
292 range->avg_qual.noise = 0x9E;
293 }
294
295 err = orinoco_hw_get_bitratelist(priv, &numrates,
296 range->bitrate, IW_MAX_BITRATES);
297 if (err)
298 return err;
299 range->num_bitrates = numrates;
300
301 /* Set an indication of the max TCP throughput in bit/s that we can
302 * expect using this interface. May be use for QoS stuff...
303 * Jean II */
304 if (numrates > 2)
305 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
306 else
307 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
308
309 range->min_rts = 0;
310 range->max_rts = 2347;
311 range->min_frag = 256;
312 range->max_frag = 2346;
313
314 range->min_pmp = 0;
315 range->max_pmp = 65535000;
316 range->min_pmt = 0;
317 range->max_pmt = 65535 * 1000; /* ??? */
318 range->pmp_flags = IW_POWER_PERIOD;
319 range->pmt_flags = IW_POWER_TIMEOUT;
320 range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
321 IW_POWER_UNICAST_R);
322
323 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
324 range->retry_flags = IW_RETRY_LIMIT;
325 range->r_time_flags = IW_RETRY_LIFETIME;
326 range->min_retry = 0;
327 range->max_retry = 65535; /* ??? */
328 range->min_r_time = 0;
329 range->max_r_time = 65535 * 1000; /* ??? */
330
331 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
332 range->scan_capa = IW_SCAN_CAPA_ESSID;
333 else
334 range->scan_capa = IW_SCAN_CAPA_NONE;
335
336 /* Event capability (kernel) */
337 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
338 /* Event capability (driver) */
339 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
340 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
341 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
342 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
343
344 return 0;
345}
346
347static int orinoco_ioctl_setiwencode(struct net_device *dev,
348 struct iw_request_info *info,
349 struct iw_point *erq,
350 char *keybuf)
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 index = (erq->flags & IW_ENCODE_INDEX) - 1;
354 int setindex = priv->tx_key;
355 int encode_alg = priv->encode_alg;
356 int restricted = priv->wep_restrict;
357 u16 xlen = 0;
358 int err = -EINPROGRESS; /* Call commit handler */
359 unsigned long flags;
360
361 if (!priv->has_wep)
362 return -EOPNOTSUPP;
363
364 if (erq->pointer) {
365 /* We actually have a key to set - check its length */
366 if (erq->length > LARGE_KEY_SIZE)
367 return -E2BIG;
368
369 if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
370 return -E2BIG;
371 }
372
373 if (orinoco_lock(priv, &flags) != 0)
374 return -EBUSY;
375
376 /* Clear any TKIP key we have */
377 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
378 (void) orinoco_clear_tkip_key(priv, setindex);
379
380 if (erq->length > 0) {
381 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
382 index = priv->tx_key;
383
384 /* Adjust key length to a supported value */
385 if (erq->length > SMALL_KEY_SIZE)
386 xlen = LARGE_KEY_SIZE;
387 else if (erq->length > 0)
388 xlen = SMALL_KEY_SIZE;
389 else
390 xlen = 0;
391
392 /* Switch on WEP if off */
393 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
394 setindex = index;
395 encode_alg = IW_ENCODE_ALG_WEP;
396 }
397 } else {
398 /* Important note : if the user do "iwconfig eth0 enc off",
399 * we will arrive there with an index of -1. This is valid
400 * but need to be taken care off... Jean II */
401 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
402 if ((index != -1) || (erq->flags == 0)) {
403 err = -EINVAL;
404 goto out;
405 }
406 } else {
407 /* Set the index : Check that the key is valid */
408 if (priv->keys[index].len == 0) {
409 err = -EINVAL;
410 goto out;
411 }
412 setindex = index;
413 }
414 }
415
416 if (erq->flags & IW_ENCODE_DISABLED)
417 encode_alg = IW_ENCODE_ALG_NONE;
418 if (erq->flags & IW_ENCODE_OPEN)
419 restricted = 0;
420 if (erq->flags & IW_ENCODE_RESTRICTED)
421 restricted = 1;
422
423 if (erq->pointer && erq->length > 0) {
424 priv->keys[index].len = cpu_to_le16(xlen);
425 memset(priv->keys[index].data, 0,
426 sizeof(priv->keys[index].data));
427 memcpy(priv->keys[index].data, keybuf, erq->length);
428 }
429 priv->tx_key = setindex;
430
431 /* Try fast key change if connected and only keys are changed */
432 if ((priv->encode_alg == encode_alg) &&
433 (priv->wep_restrict == restricted) &&
434 netif_carrier_ok(dev)) {
435 err = __orinoco_hw_setup_wepkeys(priv);
436 /* No need to commit if successful */
437 goto out;
438 }
439
440 priv->encode_alg = encode_alg;
441 priv->wep_restrict = restricted;
442
443 out:
444 orinoco_unlock(priv, &flags);
445
446 return err;
447}
448
449static int orinoco_ioctl_getiwencode(struct net_device *dev,
450 struct iw_request_info *info,
451 struct iw_point *erq,
452 char *keybuf)
453{
David Kilroyea60a6a2009-06-18 23:21:26 +0100454 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000455 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
456 u16 xlen = 0;
457 unsigned long flags;
458
459 if (!priv->has_wep)
460 return -EOPNOTSUPP;
461
462 if (orinoco_lock(priv, &flags) != 0)
463 return -EBUSY;
464
465 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
466 index = priv->tx_key;
467
468 erq->flags = 0;
469 if (!priv->encode_alg)
470 erq->flags |= IW_ENCODE_DISABLED;
471 erq->flags |= index + 1;
472
473 if (priv->wep_restrict)
474 erq->flags |= IW_ENCODE_RESTRICTED;
475 else
476 erq->flags |= IW_ENCODE_OPEN;
477
478 xlen = le16_to_cpu(priv->keys[index].len);
479
480 erq->length = xlen;
481
482 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
483
484 orinoco_unlock(priv, &flags);
485 return 0;
486}
487
488static int orinoco_ioctl_setessid(struct net_device *dev,
489 struct iw_request_info *info,
490 struct iw_point *erq,
491 char *essidbuf)
492{
David Kilroyea60a6a2009-06-18 23:21:26 +0100493 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000494 unsigned long flags;
495
496 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
497 * anyway... - Jean II */
498
499 /* Hum... Should not use Wireless Extension constant (may change),
500 * should use our own... - Jean II */
501 if (erq->length > IW_ESSID_MAX_SIZE)
502 return -E2BIG;
503
504 if (orinoco_lock(priv, &flags) != 0)
505 return -EBUSY;
506
507 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
508 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
509
510 /* If not ANY, get the new ESSID */
511 if (erq->flags)
512 memcpy(priv->desired_essid, essidbuf, erq->length);
513
514 orinoco_unlock(priv, &flags);
515
516 return -EINPROGRESS; /* Call commit handler */
517}
518
519static int orinoco_ioctl_getessid(struct net_device *dev,
520 struct iw_request_info *info,
521 struct iw_point *erq,
522 char *essidbuf)
523{
David Kilroyea60a6a2009-06-18 23:21:26 +0100524 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000525 int active;
526 int err = 0;
527 unsigned long flags;
528
529 if (netif_running(dev)) {
530 err = orinoco_hw_get_essid(priv, &active, essidbuf);
531 if (err < 0)
532 return err;
533 erq->length = err;
534 } else {
535 if (orinoco_lock(priv, &flags) != 0)
536 return -EBUSY;
537 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
538 erq->length = strlen(priv->desired_essid);
539 orinoco_unlock(priv, &flags);
540 }
541
542 erq->flags = 1;
543
544 return 0;
545}
546
547static int orinoco_ioctl_setnick(struct net_device *dev,
548 struct iw_request_info *info,
549 struct iw_point *nrq,
550 char *nickbuf)
551{
David Kilroyea60a6a2009-06-18 23:21:26 +0100552 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000553 unsigned long flags;
554
555 if (nrq->length > IW_ESSID_MAX_SIZE)
556 return -E2BIG;
557
558 if (orinoco_lock(priv, &flags) != 0)
559 return -EBUSY;
560
561 memset(priv->nick, 0, sizeof(priv->nick));
562 memcpy(priv->nick, nickbuf, nrq->length);
563
564 orinoco_unlock(priv, &flags);
565
566 return -EINPROGRESS; /* Call commit handler */
567}
568
569static int orinoco_ioctl_getnick(struct net_device *dev,
570 struct iw_request_info *info,
571 struct iw_point *nrq,
572 char *nickbuf)
573{
David Kilroyea60a6a2009-06-18 23:21:26 +0100574 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000575 unsigned long flags;
576
577 if (orinoco_lock(priv, &flags) != 0)
578 return -EBUSY;
579
580 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
581 orinoco_unlock(priv, &flags);
582
583 nrq->length = strlen(priv->nick);
584
585 return 0;
586}
587
588static int orinoco_ioctl_setfreq(struct net_device *dev,
589 struct iw_request_info *info,
590 struct iw_freq *frq,
591 char *extra)
592{
David Kilroyea60a6a2009-06-18 23:21:26 +0100593 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000594 int chan = -1;
595 unsigned long flags;
596 int err = -EINPROGRESS; /* Call commit handler */
597
598 /* In infrastructure mode the AP sets the channel */
599 if (priv->iw_mode == IW_MODE_INFRA)
600 return -EBUSY;
601
602 if ((frq->e == 0) && (frq->m <= 1000)) {
603 /* Setting by channel number */
604 chan = frq->m;
605 } else {
606 /* Setting by frequency */
607 int denom = 1;
608 int i;
609
610 /* Calculate denominator to rescale to MHz */
611 for (i = 0; i < (6 - frq->e); i++)
612 denom *= 10;
613
614 chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
615 }
616
617 if ((chan < 1) || (chan > NUM_CHANNELS) ||
618 !(priv->channel_mask & (1 << (chan-1))))
619 return -EINVAL;
620
621 if (orinoco_lock(priv, &flags) != 0)
622 return -EBUSY;
623
624 priv->channel = chan;
625 if (priv->iw_mode == IW_MODE_MONITOR) {
626 /* Fast channel change - no commit if successful */
627 hermes_t *hw = &priv->hw;
628 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
629 HERMES_TEST_SET_CHANNEL,
630 chan, NULL);
631 }
632 orinoco_unlock(priv, &flags);
633
634 return err;
635}
636
637static int orinoco_ioctl_getfreq(struct net_device *dev,
638 struct iw_request_info *info,
639 struct iw_freq *frq,
640 char *extra)
641{
David Kilroyea60a6a2009-06-18 23:21:26 +0100642 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000643 int tmp;
644
645 /* Locking done in there */
646 tmp = orinoco_hw_get_freq(priv);
647 if (tmp < 0)
648 return tmp;
649
650 frq->m = tmp * 100000;
651 frq->e = 1;
652
653 return 0;
654}
655
656static int orinoco_ioctl_getsens(struct net_device *dev,
657 struct iw_request_info *info,
658 struct iw_param *srq,
659 char *extra)
660{
David Kilroyea60a6a2009-06-18 23:21:26 +0100661 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000662 hermes_t *hw = &priv->hw;
663 u16 val;
664 int err;
665 unsigned long flags;
666
667 if (!priv->has_sensitivity)
668 return -EOPNOTSUPP;
669
670 if (orinoco_lock(priv, &flags) != 0)
671 return -EBUSY;
672 err = hermes_read_wordrec(hw, USER_BAP,
673 HERMES_RID_CNFSYSTEMSCALE, &val);
674 orinoco_unlock(priv, &flags);
675
676 if (err)
677 return err;
678
679 srq->value = val;
680 srq->fixed = 0; /* auto */
681
682 return 0;
683}
684
685static int orinoco_ioctl_setsens(struct net_device *dev,
686 struct iw_request_info *info,
687 struct iw_param *srq,
688 char *extra)
689{
David Kilroyea60a6a2009-06-18 23:21:26 +0100690 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000691 int val = srq->value;
692 unsigned long flags;
693
694 if (!priv->has_sensitivity)
695 return -EOPNOTSUPP;
696
697 if ((val < 1) || (val > 3))
698 return -EINVAL;
699
700 if (orinoco_lock(priv, &flags) != 0)
701 return -EBUSY;
702 priv->ap_density = val;
703 orinoco_unlock(priv, &flags);
704
705 return -EINPROGRESS; /* Call commit handler */
706}
707
708static int orinoco_ioctl_setrts(struct net_device *dev,
709 struct iw_request_info *info,
710 struct iw_param *rrq,
711 char *extra)
712{
David Kilroyea60a6a2009-06-18 23:21:26 +0100713 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000714 int val = rrq->value;
715 unsigned long flags;
716
717 if (rrq->disabled)
718 val = 2347;
719
720 if ((val < 0) || (val > 2347))
721 return -EINVAL;
722
723 if (orinoco_lock(priv, &flags) != 0)
724 return -EBUSY;
725
726 priv->rts_thresh = val;
727 orinoco_unlock(priv, &flags);
728
729 return -EINPROGRESS; /* Call commit handler */
730}
731
732static int orinoco_ioctl_getrts(struct net_device *dev,
733 struct iw_request_info *info,
734 struct iw_param *rrq,
735 char *extra)
736{
David Kilroyea60a6a2009-06-18 23:21:26 +0100737 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000738
739 rrq->value = priv->rts_thresh;
740 rrq->disabled = (rrq->value == 2347);
741 rrq->fixed = 1;
742
743 return 0;
744}
745
746static int orinoco_ioctl_setfrag(struct net_device *dev,
747 struct iw_request_info *info,
748 struct iw_param *frq,
749 char *extra)
750{
David Kilroyea60a6a2009-06-18 23:21:26 +0100751 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000752 int err = -EINPROGRESS; /* Call commit handler */
753 unsigned long flags;
754
755 if (orinoco_lock(priv, &flags) != 0)
756 return -EBUSY;
757
758 if (priv->has_mwo) {
759 if (frq->disabled)
760 priv->mwo_robust = 0;
761 else {
762 if (frq->fixed)
763 printk(KERN_WARNING "%s: Fixed fragmentation "
764 "is not supported on this firmware. "
765 "Using MWO robust instead.\n",
766 dev->name);
767 priv->mwo_robust = 1;
768 }
769 } else {
770 if (frq->disabled)
771 priv->frag_thresh = 2346;
772 else {
773 if ((frq->value < 256) || (frq->value > 2346))
774 err = -EINVAL;
775 else
776 /* must be even */
777 priv->frag_thresh = frq->value & ~0x1;
778 }
779 }
780
781 orinoco_unlock(priv, &flags);
782
783 return err;
784}
785
786static int orinoco_ioctl_getfrag(struct net_device *dev,
787 struct iw_request_info *info,
788 struct iw_param *frq,
789 char *extra)
790{
David Kilroyea60a6a2009-06-18 23:21:26 +0100791 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000792 hermes_t *hw = &priv->hw;
793 int err;
794 u16 val;
795 unsigned long flags;
796
797 if (orinoco_lock(priv, &flags) != 0)
798 return -EBUSY;
799
800 if (priv->has_mwo) {
801 err = hermes_read_wordrec(hw, USER_BAP,
802 HERMES_RID_CNFMWOROBUST_AGERE,
803 &val);
804 if (err)
805 val = 0;
806
807 frq->value = val ? 2347 : 0;
808 frq->disabled = !val;
809 frq->fixed = 0;
810 } else {
811 err = hermes_read_wordrec(hw, USER_BAP,
812 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
813 &val);
814 if (err)
815 val = 0;
816
817 frq->value = val;
818 frq->disabled = (val >= 2346);
819 frq->fixed = 1;
820 }
821
822 orinoco_unlock(priv, &flags);
823
824 return err;
825}
826
827static int orinoco_ioctl_setrate(struct net_device *dev,
828 struct iw_request_info *info,
829 struct iw_param *rrq,
830 char *extra)
831{
David Kilroyea60a6a2009-06-18 23:21:26 +0100832 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000833 int ratemode;
834 int bitrate; /* 100s of kilobits */
835 unsigned long flags;
836
837 /* As the user space doesn't know our highest rate, it uses -1
838 * to ask us to set the highest rate. Test it using "iwconfig
839 * ethX rate auto" - Jean II */
840 if (rrq->value == -1)
841 bitrate = 110;
842 else {
843 if (rrq->value % 100000)
844 return -EINVAL;
845 bitrate = rrq->value / 100000;
846 }
847
848 ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
849
850 if (ratemode == -1)
851 return -EINVAL;
852
853 if (orinoco_lock(priv, &flags) != 0)
854 return -EBUSY;
855 priv->bitratemode = ratemode;
856 orinoco_unlock(priv, &flags);
857
858 return -EINPROGRESS;
859}
860
861static int orinoco_ioctl_getrate(struct net_device *dev,
862 struct iw_request_info *info,
863 struct iw_param *rrq,
864 char *extra)
865{
David Kilroyea60a6a2009-06-18 23:21:26 +0100866 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000867 int err = 0;
868 int bitrate, automatic;
869 unsigned long flags;
870
871 if (orinoco_lock(priv, &flags) != 0)
872 return -EBUSY;
873
874 orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
875
876 /* If the interface is running we try to find more about the
877 current mode */
878 if (netif_running(dev))
879 err = orinoco_hw_get_act_bitrate(priv, &bitrate);
880
881 orinoco_unlock(priv, &flags);
882
883 rrq->value = bitrate;
884 rrq->fixed = !automatic;
885 rrq->disabled = 0;
886
887 return err;
888}
889
890static int orinoco_ioctl_setpower(struct net_device *dev,
891 struct iw_request_info *info,
892 struct iw_param *prq,
893 char *extra)
894{
David Kilroyea60a6a2009-06-18 23:21:26 +0100895 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000896 int err = -EINPROGRESS; /* Call commit handler */
897 unsigned long flags;
898
899 if (orinoco_lock(priv, &flags) != 0)
900 return -EBUSY;
901
902 if (prq->disabled) {
903 priv->pm_on = 0;
904 } else {
905 switch (prq->flags & IW_POWER_MODE) {
906 case IW_POWER_UNICAST_R:
907 priv->pm_mcast = 0;
908 priv->pm_on = 1;
909 break;
910 case IW_POWER_ALL_R:
911 priv->pm_mcast = 1;
912 priv->pm_on = 1;
913 break;
914 case IW_POWER_ON:
915 /* No flags : but we may have a value - Jean II */
916 break;
917 default:
918 err = -EINVAL;
919 goto out;
920 }
921
922 if (prq->flags & IW_POWER_TIMEOUT) {
923 priv->pm_on = 1;
924 priv->pm_timeout = prq->value / 1000;
925 }
926 if (prq->flags & IW_POWER_PERIOD) {
927 priv->pm_on = 1;
928 priv->pm_period = prq->value / 1000;
929 }
930 /* It's valid to not have a value if we are just toggling
931 * the flags... Jean II */
932 if (!priv->pm_on) {
933 err = -EINVAL;
934 goto out;
935 }
936 }
937
938 out:
939 orinoco_unlock(priv, &flags);
940
941 return err;
942}
943
944static int orinoco_ioctl_getpower(struct net_device *dev,
945 struct iw_request_info *info,
946 struct iw_param *prq,
947 char *extra)
948{
David Kilroyea60a6a2009-06-18 23:21:26 +0100949 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +0000950 hermes_t *hw = &priv->hw;
951 int err = 0;
952 u16 enable, period, timeout, mcast;
953 unsigned long flags;
954
955 if (orinoco_lock(priv, &flags) != 0)
956 return -EBUSY;
957
958 err = hermes_read_wordrec(hw, USER_BAP,
959 HERMES_RID_CNFPMENABLED, &enable);
960 if (err)
961 goto out;
962
963 err = hermes_read_wordrec(hw, USER_BAP,
964 HERMES_RID_CNFMAXSLEEPDURATION, &period);
965 if (err)
966 goto out;
967
968 err = hermes_read_wordrec(hw, USER_BAP,
969 HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
970 if (err)
971 goto out;
972
973 err = hermes_read_wordrec(hw, USER_BAP,
974 HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
975 if (err)
976 goto out;
977
978 prq->disabled = !enable;
979 /* Note : by default, display the period */
980 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
981 prq->flags = IW_POWER_TIMEOUT;
982 prq->value = timeout * 1000;
983 } else {
984 prq->flags = IW_POWER_PERIOD;
985 prq->value = period * 1000;
986 }
987 if (mcast)
988 prq->flags |= IW_POWER_ALL_R;
989 else
990 prq->flags |= IW_POWER_UNICAST_R;
991
992 out:
993 orinoco_unlock(priv, &flags);
994
995 return err;
996}
997
998static int orinoco_ioctl_set_encodeext(struct net_device *dev,
999 struct iw_request_info *info,
1000 union iwreq_data *wrqu,
1001 char *extra)
1002{
David Kilroyea60a6a2009-06-18 23:21:26 +01001003 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001004 struct iw_point *encoding = &wrqu->encoding;
1005 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1006 int idx, alg = ext->alg, set_key = 1;
1007 unsigned long flags;
1008 int err = -EINVAL;
1009 u16 key_len;
1010
1011 if (orinoco_lock(priv, &flags) != 0)
1012 return -EBUSY;
1013
1014 /* Determine and validate the key index */
1015 idx = encoding->flags & IW_ENCODE_INDEX;
1016 if (idx) {
1017 if ((idx < 1) || (idx > 4))
1018 goto out;
1019 idx--;
1020 } else
1021 idx = priv->tx_key;
1022
1023 if (encoding->flags & IW_ENCODE_DISABLED)
1024 alg = IW_ENCODE_ALG_NONE;
1025
1026 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
1027 /* Clear any TKIP TX key we had */
1028 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
1029 }
1030
1031 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1032 priv->tx_key = idx;
1033 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
1034 (ext->key_len > 0)) ? 1 : 0;
1035 }
1036
1037 if (set_key) {
1038 /* Set the requested key first */
1039 switch (alg) {
1040 case IW_ENCODE_ALG_NONE:
1041 priv->encode_alg = alg;
1042 priv->keys[idx].len = 0;
1043 break;
1044
1045 case IW_ENCODE_ALG_WEP:
1046 if (ext->key_len > SMALL_KEY_SIZE)
1047 key_len = LARGE_KEY_SIZE;
1048 else if (ext->key_len > 0)
1049 key_len = SMALL_KEY_SIZE;
1050 else
1051 goto out;
1052
1053 priv->encode_alg = alg;
1054 priv->keys[idx].len = cpu_to_le16(key_len);
1055
1056 key_len = min(ext->key_len, key_len);
1057
1058 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
1059 memcpy(priv->keys[idx].data, ext->key, key_len);
1060 break;
1061
1062 case IW_ENCODE_ALG_TKIP:
1063 {
David Kilroycb1576a2009-02-04 23:05:56 +00001064 u8 *tkip_iv = NULL;
1065
1066 if (!priv->has_wpa ||
1067 (ext->key_len > sizeof(priv->tkip_key[0])))
1068 goto out;
1069
1070 priv->encode_alg = alg;
1071 memset(&priv->tkip_key[idx], 0,
1072 sizeof(priv->tkip_key[idx]));
1073 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
1074
1075 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
1076 tkip_iv = &ext->rx_seq[0];
1077
David Kilroy98e5f402009-06-18 23:21:25 +01001078 err = __orinoco_hw_set_tkip_key(priv, idx,
David Kilroycb1576a2009-02-04 23:05:56 +00001079 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
1080 (u8 *) &priv->tkip_key[idx],
1081 tkip_iv, NULL);
1082 if (err)
1083 printk(KERN_ERR "%s: Error %d setting TKIP key"
1084 "\n", dev->name, err);
1085
1086 goto out;
1087 }
1088 default:
1089 goto out;
1090 }
1091 }
1092 err = -EINPROGRESS;
1093 out:
1094 orinoco_unlock(priv, &flags);
1095
1096 return err;
1097}
1098
1099static int orinoco_ioctl_get_encodeext(struct net_device *dev,
1100 struct iw_request_info *info,
1101 union iwreq_data *wrqu,
1102 char *extra)
1103{
David Kilroyea60a6a2009-06-18 23:21:26 +01001104 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001105 struct iw_point *encoding = &wrqu->encoding;
1106 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1107 int idx, max_key_len;
1108 unsigned long flags;
1109 int err;
1110
1111 if (orinoco_lock(priv, &flags) != 0)
1112 return -EBUSY;
1113
1114 err = -EINVAL;
1115 max_key_len = encoding->length - sizeof(*ext);
1116 if (max_key_len < 0)
1117 goto out;
1118
1119 idx = encoding->flags & IW_ENCODE_INDEX;
1120 if (idx) {
1121 if ((idx < 1) || (idx > 4))
1122 goto out;
1123 idx--;
1124 } else
1125 idx = priv->tx_key;
1126
1127 encoding->flags = idx + 1;
1128 memset(ext, 0, sizeof(*ext));
1129
1130 ext->alg = priv->encode_alg;
1131 switch (priv->encode_alg) {
1132 case IW_ENCODE_ALG_NONE:
1133 ext->key_len = 0;
1134 encoding->flags |= IW_ENCODE_DISABLED;
1135 break;
1136 case IW_ENCODE_ALG_WEP:
1137 ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
1138 max_key_len);
1139 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
1140 encoding->flags |= IW_ENCODE_ENABLED;
1141 break;
1142 case IW_ENCODE_ALG_TKIP:
1143 ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
1144 max_key_len);
1145 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
1146 encoding->flags |= IW_ENCODE_ENABLED;
1147 break;
1148 }
1149
1150 err = 0;
1151 out:
1152 orinoco_unlock(priv, &flags);
1153
1154 return err;
1155}
1156
1157static int orinoco_ioctl_set_auth(struct net_device *dev,
1158 struct iw_request_info *info,
1159 union iwreq_data *wrqu, char *extra)
1160{
David Kilroyea60a6a2009-06-18 23:21:26 +01001161 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001162 hermes_t *hw = &priv->hw;
1163 struct iw_param *param = &wrqu->param;
1164 unsigned long flags;
1165 int ret = -EINPROGRESS;
1166
1167 if (orinoco_lock(priv, &flags) != 0)
1168 return -EBUSY;
1169
1170 switch (param->flags & IW_AUTH_INDEX) {
1171 case IW_AUTH_WPA_VERSION:
1172 case IW_AUTH_CIPHER_PAIRWISE:
1173 case IW_AUTH_CIPHER_GROUP:
1174 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1175 case IW_AUTH_PRIVACY_INVOKED:
1176 case IW_AUTH_DROP_UNENCRYPTED:
1177 /*
1178 * orinoco does not use these parameters
1179 */
1180 break;
1181
1182 case IW_AUTH_KEY_MGMT:
1183 /* wl_lkm implies value 2 == PSK for Hermes I
1184 * which ties in with WEXT
1185 * no other hints tho :(
1186 */
1187 priv->key_mgmt = param->value;
1188 break;
1189
1190 case IW_AUTH_TKIP_COUNTERMEASURES:
1191 /* When countermeasures are enabled, shut down the
1192 * card; when disabled, re-enable the card. This must
1193 * take effect immediately.
1194 *
1195 * TODO: Make sure that the EAPOL message is getting
1196 * out before card disabled
1197 */
1198 if (param->value) {
1199 priv->tkip_cm_active = 1;
1200 ret = hermes_enable_port(hw, 0);
1201 } else {
1202 priv->tkip_cm_active = 0;
1203 ret = hermes_disable_port(hw, 0);
1204 }
1205 break;
1206
1207 case IW_AUTH_80211_AUTH_ALG:
1208 if (param->value & IW_AUTH_ALG_SHARED_KEY)
1209 priv->wep_restrict = 1;
1210 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
1211 priv->wep_restrict = 0;
1212 else
1213 ret = -EINVAL;
1214 break;
1215
1216 case IW_AUTH_WPA_ENABLED:
1217 if (priv->has_wpa) {
1218 priv->wpa_enabled = param->value ? 1 : 0;
1219 } else {
1220 if (param->value)
1221 ret = -EOPNOTSUPP;
1222 /* else silently accept disable of WPA */
1223 priv->wpa_enabled = 0;
1224 }
1225 break;
1226
1227 default:
1228 ret = -EOPNOTSUPP;
1229 }
1230
1231 orinoco_unlock(priv, &flags);
1232 return ret;
1233}
1234
1235static int orinoco_ioctl_get_auth(struct net_device *dev,
1236 struct iw_request_info *info,
1237 union iwreq_data *wrqu, char *extra)
1238{
David Kilroyea60a6a2009-06-18 23:21:26 +01001239 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001240 struct iw_param *param = &wrqu->param;
1241 unsigned long flags;
1242 int ret = 0;
1243
1244 if (orinoco_lock(priv, &flags) != 0)
1245 return -EBUSY;
1246
1247 switch (param->flags & IW_AUTH_INDEX) {
1248 case IW_AUTH_KEY_MGMT:
1249 param->value = priv->key_mgmt;
1250 break;
1251
1252 case IW_AUTH_TKIP_COUNTERMEASURES:
1253 param->value = priv->tkip_cm_active;
1254 break;
1255
1256 case IW_AUTH_80211_AUTH_ALG:
1257 if (priv->wep_restrict)
1258 param->value = IW_AUTH_ALG_SHARED_KEY;
1259 else
1260 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
1261 break;
1262
1263 case IW_AUTH_WPA_ENABLED:
1264 param->value = priv->wpa_enabled;
1265 break;
1266
1267 default:
1268 ret = -EOPNOTSUPP;
1269 }
1270
1271 orinoco_unlock(priv, &flags);
1272 return ret;
1273}
1274
1275static int orinoco_ioctl_set_genie(struct net_device *dev,
1276 struct iw_request_info *info,
1277 union iwreq_data *wrqu, char *extra)
1278{
David Kilroyea60a6a2009-06-18 23:21:26 +01001279 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001280 u8 *buf;
1281 unsigned long flags;
1282
1283 /* cut off at IEEE80211_MAX_DATA_LEN */
1284 if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
1285 (wrqu->data.length && (extra == NULL)))
1286 return -EINVAL;
1287
1288 if (wrqu->data.length) {
1289 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
1290 if (buf == NULL)
1291 return -ENOMEM;
1292
1293 memcpy(buf, extra, wrqu->data.length);
1294 } else
1295 buf = NULL;
1296
1297 if (orinoco_lock(priv, &flags) != 0) {
1298 kfree(buf);
1299 return -EBUSY;
1300 }
1301
1302 kfree(priv->wpa_ie);
1303 priv->wpa_ie = buf;
1304 priv->wpa_ie_len = wrqu->data.length;
1305
1306 if (priv->wpa_ie) {
1307 /* Looks like wl_lkm wants to check the auth alg, and
1308 * somehow pass it to the firmware.
1309 * Instead it just calls the key mgmt rid
1310 * - we do this in set auth.
1311 */
1312 }
1313
1314 orinoco_unlock(priv, &flags);
1315 return 0;
1316}
1317
1318static int orinoco_ioctl_get_genie(struct net_device *dev,
1319 struct iw_request_info *info,
1320 union iwreq_data *wrqu, char *extra)
1321{
David Kilroyea60a6a2009-06-18 23:21:26 +01001322 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001323 unsigned long flags;
1324 int err = 0;
1325
1326 if (orinoco_lock(priv, &flags) != 0)
1327 return -EBUSY;
1328
1329 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
1330 wrqu->data.length = 0;
1331 goto out;
1332 }
1333
1334 if (wrqu->data.length < priv->wpa_ie_len) {
1335 err = -E2BIG;
1336 goto out;
1337 }
1338
1339 wrqu->data.length = priv->wpa_ie_len;
1340 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
1341
1342out:
1343 orinoco_unlock(priv, &flags);
1344 return err;
1345}
1346
1347static int orinoco_ioctl_set_mlme(struct net_device *dev,
1348 struct iw_request_info *info,
1349 union iwreq_data *wrqu, char *extra)
1350{
David Kilroyea60a6a2009-06-18 23:21:26 +01001351 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001352 hermes_t *hw = &priv->hw;
1353 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1354 unsigned long flags;
1355 int ret = 0;
1356
1357 if (orinoco_lock(priv, &flags) != 0)
1358 return -EBUSY;
1359
1360 switch (mlme->cmd) {
1361 case IW_MLME_DEAUTH:
1362 /* silently ignore */
1363 break;
1364
1365 case IW_MLME_DISASSOC:
1366 {
1367 struct {
1368 u8 addr[ETH_ALEN];
1369 __le16 reason_code;
1370 } __attribute__ ((packed)) buf;
1371
1372 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
1373 buf.reason_code = cpu_to_le16(mlme->reason_code);
1374 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
1375 HERMES_RID_CNFDISASSOCIATE,
1376 &buf);
1377 break;
1378 }
1379 default:
1380 ret = -EOPNOTSUPP;
1381 }
1382
1383 orinoco_unlock(priv, &flags);
1384 return ret;
1385}
1386
1387static int orinoco_ioctl_getretry(struct net_device *dev,
1388 struct iw_request_info *info,
1389 struct iw_param *rrq,
1390 char *extra)
1391{
David Kilroyea60a6a2009-06-18 23:21:26 +01001392 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001393 hermes_t *hw = &priv->hw;
1394 int err = 0;
1395 u16 short_limit, long_limit, lifetime;
1396 unsigned long flags;
1397
1398 if (orinoco_lock(priv, &flags) != 0)
1399 return -EBUSY;
1400
1401 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
1402 &short_limit);
1403 if (err)
1404 goto out;
1405
1406 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
1407 &long_limit);
1408 if (err)
1409 goto out;
1410
1411 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
1412 &lifetime);
1413 if (err)
1414 goto out;
1415
1416 rrq->disabled = 0; /* Can't be disabled */
1417
1418 /* Note : by default, display the retry number */
1419 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1420 rrq->flags = IW_RETRY_LIFETIME;
1421 rrq->value = lifetime * 1000; /* ??? */
1422 } else {
1423 /* By default, display the min number */
1424 if ((rrq->flags & IW_RETRY_LONG)) {
1425 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1426 rrq->value = long_limit;
1427 } else {
1428 rrq->flags = IW_RETRY_LIMIT;
1429 rrq->value = short_limit;
1430 if (short_limit != long_limit)
1431 rrq->flags |= IW_RETRY_SHORT;
1432 }
1433 }
1434
1435 out:
1436 orinoco_unlock(priv, &flags);
1437
1438 return err;
1439}
1440
1441static int orinoco_ioctl_reset(struct net_device *dev,
1442 struct iw_request_info *info,
1443 void *wrqu,
1444 char *extra)
1445{
David Kilroyea60a6a2009-06-18 23:21:26 +01001446 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001447
1448 if (!capable(CAP_NET_ADMIN))
1449 return -EPERM;
1450
1451 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
1452 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
1453
1454 /* Firmware reset */
1455 orinoco_reset(&priv->reset_work);
1456 } else {
1457 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
1458
1459 schedule_work(&priv->reset_work);
1460 }
1461
1462 return 0;
1463}
1464
1465static int orinoco_ioctl_setibssport(struct net_device *dev,
1466 struct iw_request_info *info,
1467 void *wrqu,
1468 char *extra)
1469
1470{
David Kilroyea60a6a2009-06-18 23:21:26 +01001471 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001472 int val = *((int *) extra);
1473 unsigned long flags;
1474
1475 if (orinoco_lock(priv, &flags) != 0)
1476 return -EBUSY;
1477
1478 priv->ibss_port = val ;
1479
1480 /* Actually update the mode we are using */
1481 set_port_type(priv);
1482
1483 orinoco_unlock(priv, &flags);
1484 return -EINPROGRESS; /* Call commit handler */
1485}
1486
1487static int orinoco_ioctl_getibssport(struct net_device *dev,
1488 struct iw_request_info *info,
1489 void *wrqu,
1490 char *extra)
1491{
David Kilroyea60a6a2009-06-18 23:21:26 +01001492 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001493 int *val = (int *) extra;
1494
1495 *val = priv->ibss_port;
1496 return 0;
1497}
1498
1499static int orinoco_ioctl_setport3(struct net_device *dev,
1500 struct iw_request_info *info,
1501 void *wrqu,
1502 char *extra)
1503{
David Kilroyea60a6a2009-06-18 23:21:26 +01001504 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001505 int val = *((int *) extra);
1506 int err = 0;
1507 unsigned long flags;
1508
1509 if (orinoco_lock(priv, &flags) != 0)
1510 return -EBUSY;
1511
1512 switch (val) {
1513 case 0: /* Try to do IEEE ad-hoc mode */
1514 if (!priv->has_ibss) {
1515 err = -EINVAL;
1516 break;
1517 }
1518 priv->prefer_port3 = 0;
1519
1520 break;
1521
1522 case 1: /* Try to do Lucent proprietary ad-hoc mode */
1523 if (!priv->has_port3) {
1524 err = -EINVAL;
1525 break;
1526 }
1527 priv->prefer_port3 = 1;
1528 break;
1529
1530 default:
1531 err = -EINVAL;
1532 }
1533
1534 if (!err) {
1535 /* Actually update the mode we are using */
1536 set_port_type(priv);
1537 err = -EINPROGRESS;
1538 }
1539
1540 orinoco_unlock(priv, &flags);
1541
1542 return err;
1543}
1544
1545static int orinoco_ioctl_getport3(struct net_device *dev,
1546 struct iw_request_info *info,
1547 void *wrqu,
1548 char *extra)
1549{
David Kilroyea60a6a2009-06-18 23:21:26 +01001550 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001551 int *val = (int *) extra;
1552
1553 *val = priv->prefer_port3;
1554 return 0;
1555}
1556
1557static int orinoco_ioctl_setpreamble(struct net_device *dev,
1558 struct iw_request_info *info,
1559 void *wrqu,
1560 char *extra)
1561{
David Kilroyea60a6a2009-06-18 23:21:26 +01001562 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001563 unsigned long flags;
1564 int val;
1565
1566 if (!priv->has_preamble)
1567 return -EOPNOTSUPP;
1568
1569 /* 802.11b has recently defined some short preamble.
1570 * Basically, the Phy header has been reduced in size.
1571 * This increase performance, especially at high rates
1572 * (the preamble is transmitted at 1Mb/s), unfortunately
1573 * this give compatibility troubles... - Jean II */
1574 val = *((int *) extra);
1575
1576 if (orinoco_lock(priv, &flags) != 0)
1577 return -EBUSY;
1578
1579 if (val)
1580 priv->preamble = 1;
1581 else
1582 priv->preamble = 0;
1583
1584 orinoco_unlock(priv, &flags);
1585
1586 return -EINPROGRESS; /* Call commit handler */
1587}
1588
1589static int orinoco_ioctl_getpreamble(struct net_device *dev,
1590 struct iw_request_info *info,
1591 void *wrqu,
1592 char *extra)
1593{
David Kilroyea60a6a2009-06-18 23:21:26 +01001594 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001595 int *val = (int *) extra;
1596
1597 if (!priv->has_preamble)
1598 return -EOPNOTSUPP;
1599
1600 *val = priv->preamble;
1601 return 0;
1602}
1603
1604/* ioctl interface to hermes_read_ltv()
1605 * To use with iwpriv, pass the RID as the token argument, e.g.
1606 * iwpriv get_rid [0xfc00]
1607 * At least Wireless Tools 25 is required to use iwpriv.
1608 * For Wireless Tools 25 and 26 append "dummy" are the end. */
1609static int orinoco_ioctl_getrid(struct net_device *dev,
1610 struct iw_request_info *info,
1611 struct iw_point *data,
1612 char *extra)
1613{
David Kilroyea60a6a2009-06-18 23:21:26 +01001614 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001615 hermes_t *hw = &priv->hw;
1616 int rid = data->flags;
1617 u16 length;
1618 int err;
1619 unsigned long flags;
1620
1621 /* It's a "get" function, but we don't want users to access the
1622 * WEP key and other raw firmware data */
1623 if (!capable(CAP_NET_ADMIN))
1624 return -EPERM;
1625
1626 if (rid < 0xfc00 || rid > 0xffff)
1627 return -EINVAL;
1628
1629 if (orinoco_lock(priv, &flags) != 0)
1630 return -EBUSY;
1631
1632 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
1633 extra);
1634 if (err)
1635 goto out;
1636
1637 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
1638 MAX_RID_LEN);
1639
1640 out:
1641 orinoco_unlock(priv, &flags);
1642 return err;
1643}
1644
1645/* Trigger a scan (look for other cells in the vicinity) */
1646static int orinoco_ioctl_setscan(struct net_device *dev,
1647 struct iw_request_info *info,
1648 struct iw_point *srq,
1649 char *extra)
1650{
David Kilroyea60a6a2009-06-18 23:21:26 +01001651 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001652 hermes_t *hw = &priv->hw;
1653 struct iw_scan_req *si = (struct iw_scan_req *) extra;
1654 int err = 0;
1655 unsigned long flags;
1656
1657 /* Note : you may have realised that, as this is a SET operation,
1658 * this is privileged and therefore a normal user can't
1659 * perform scanning.
1660 * This is not an error, while the device perform scanning,
1661 * traffic doesn't flow, so it's a perfect DoS...
1662 * Jean II */
1663
1664 if (orinoco_lock(priv, &flags) != 0)
1665 return -EBUSY;
1666
1667 /* Scanning with port 0 disabled would fail */
1668 if (!netif_running(dev)) {
1669 err = -ENETDOWN;
1670 goto out;
1671 }
1672
1673 /* In monitor mode, the scan results are always empty.
1674 * Probe responses are passed to the driver as received
1675 * frames and could be processed in software. */
1676 if (priv->iw_mode == IW_MODE_MONITOR) {
1677 err = -EOPNOTSUPP;
1678 goto out;
1679 }
1680
1681 /* Note : because we don't lock out the irq handler, the way
1682 * we access scan variables in priv is critical.
1683 * o scan_inprogress : not touched by irq handler
1684 * o scan_mode : not touched by irq handler
1685 * Before modifying anything on those variables, please think hard !
1686 * Jean II */
1687
1688 /* Save flags */
1689 priv->scan_mode = srq->flags;
1690
1691 /* Always trigger scanning, even if it's in progress.
1692 * This way, if the info frame get lost, we will recover somewhat
1693 * gracefully - Jean II */
1694
1695 if (priv->has_hostscan) {
1696 switch (priv->firmware_type) {
1697 case FIRMWARE_TYPE_SYMBOL:
1698 err = hermes_write_wordrec(hw, USER_BAP,
1699 HERMES_RID_CNFHOSTSCAN_SYMBOL,
1700 HERMES_HOSTSCAN_SYMBOL_ONCE |
1701 HERMES_HOSTSCAN_SYMBOL_BCAST);
1702 break;
1703 case FIRMWARE_TYPE_INTERSIL: {
1704 __le16 req[3];
1705
1706 req[0] = cpu_to_le16(0x3fff); /* All channels */
1707 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
1708 req[2] = 0; /* Any ESSID */
1709 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1710 HERMES_RID_CNFHOSTSCAN, &req);
1711 }
1712 break;
1713 case FIRMWARE_TYPE_AGERE:
1714 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
1715 struct hermes_idstring idbuf;
1716 size_t len = min(sizeof(idbuf.val),
1717 (size_t) si->essid_len);
1718 idbuf.len = cpu_to_le16(len);
1719 memcpy(idbuf.val, si->essid, len);
1720
1721 err = hermes_write_ltv(hw, USER_BAP,
1722 HERMES_RID_CNFSCANSSID_AGERE,
1723 HERMES_BYTES_TO_RECLEN(len + 2),
1724 &idbuf);
1725 } else
1726 err = hermes_write_wordrec(hw, USER_BAP,
1727 HERMES_RID_CNFSCANSSID_AGERE,
1728 0); /* Any ESSID */
1729 if (err)
1730 break;
1731
1732 if (priv->has_ext_scan) {
1733 /* Clear scan results at the start of
1734 * an extended scan */
1735 orinoco_clear_scan_results(priv,
1736 msecs_to_jiffies(15000));
1737
1738 /* TODO: Is this available on older firmware?
1739 * Can we use it to scan specific channels
1740 * for IW_SCAN_THIS_FREQ? */
1741 err = hermes_write_wordrec(hw, USER_BAP,
1742 HERMES_RID_CNFSCANCHANNELS2GHZ,
1743 0x7FFF);
1744 if (err)
1745 goto out;
1746
1747 err = hermes_inquire(hw,
1748 HERMES_INQ_CHANNELINFO);
1749 } else
1750 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1751 break;
1752 }
1753 } else
1754 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1755
1756 /* One more client */
1757 if (!err)
1758 priv->scan_inprogress = 1;
1759
1760 out:
1761 orinoco_unlock(priv, &flags);
1762 return err;
1763}
1764
1765#define MAX_CUSTOM_LEN 64
1766
1767/* Translate scan data returned from the card to a card independant
1768 * format that the Wireless Tools will understand - Jean II */
1769static inline char *orinoco_translate_scan(struct net_device *dev,
1770 struct iw_request_info *info,
1771 char *current_ev,
1772 char *end_buf,
1773 union hermes_scan_info *bss,
1774 unsigned long last_scanned)
1775{
David Kilroyea60a6a2009-06-18 23:21:26 +01001776 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00001777 u16 capabilities;
1778 u16 channel;
1779 struct iw_event iwe; /* Temporary buffer */
1780 char custom[MAX_CUSTOM_LEN];
1781
1782 memset(&iwe, 0, sizeof(iwe));
1783
1784 /* First entry *MUST* be the AP MAC address */
1785 iwe.cmd = SIOCGIWAP;
1786 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1787 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
1788 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1789 &iwe, IW_EV_ADDR_LEN);
1790
1791 /* Other entries will be displayed in the order we give them */
1792
1793 /* Add the ESSID */
1794 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
1795 if (iwe.u.data.length > 32)
1796 iwe.u.data.length = 32;
1797 iwe.cmd = SIOCGIWESSID;
1798 iwe.u.data.flags = 1;
1799 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1800 &iwe, bss->a.essid);
1801
1802 /* Add mode */
1803 iwe.cmd = SIOCGIWMODE;
1804 capabilities = le16_to_cpu(bss->a.capabilities);
1805 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
1806 if (capabilities & WLAN_CAPABILITY_ESS)
1807 iwe.u.mode = IW_MODE_MASTER;
1808 else
1809 iwe.u.mode = IW_MODE_ADHOC;
1810 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1811 &iwe, IW_EV_UINT_LEN);
1812 }
1813
1814 channel = bss->s.channel;
1815 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
1816 /* Add channel and frequency */
1817 iwe.cmd = SIOCGIWFREQ;
1818 iwe.u.freq.m = channel;
1819 iwe.u.freq.e = 0;
1820 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1821 &iwe, IW_EV_FREQ_LEN);
1822
1823 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
1824 iwe.u.freq.e = 1;
1825 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1826 &iwe, IW_EV_FREQ_LEN);
1827 }
1828
1829 /* Add quality statistics. level and noise in dB. No link quality */
1830 iwe.cmd = IWEVQUAL;
1831 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
1832 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
1833 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
1834 /* Wireless tools prior to 27.pre22 will show link quality
1835 * anyway, so we provide a reasonable value. */
1836 if (iwe.u.qual.level > iwe.u.qual.noise)
1837 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
1838 else
1839 iwe.u.qual.qual = 0;
1840 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1841 &iwe, IW_EV_QUAL_LEN);
1842
1843 /* Add encryption capability */
1844 iwe.cmd = SIOCGIWENCODE;
1845 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1846 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1847 else
1848 iwe.u.data.flags = IW_ENCODE_DISABLED;
1849 iwe.u.data.length = 0;
1850 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1851 &iwe, NULL);
1852
1853 /* Bit rate is not available in Lucent/Agere firmwares */
1854 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
1855 char *current_val = current_ev + iwe_stream_lcp_len(info);
1856 int i;
1857 int step;
1858
1859 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
1860 step = 2;
1861 else
1862 step = 1;
1863
1864 iwe.cmd = SIOCGIWRATE;
1865 /* Those two flags are ignored... */
1866 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1867 /* Max 10 values */
1868 for (i = 0; i < 10; i += step) {
1869 /* NULL terminated */
1870 if (bss->p.rates[i] == 0x0)
1871 break;
1872 /* Bit rate given in 500 kb/s units (+ 0x80) */
1873 iwe.u.bitrate.value =
1874 ((bss->p.rates[i] & 0x7f) * 500000);
1875 current_val = iwe_stream_add_value(info, current_ev,
1876 current_val,
1877 end_buf, &iwe,
1878 IW_EV_PARAM_LEN);
1879 }
1880 /* Check if we added any event */
1881 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
1882 current_ev = current_val;
1883 }
1884
1885 /* Beacon interval */
1886 iwe.cmd = IWEVCUSTOM;
1887 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
1888 "bcn_int=%d",
1889 le16_to_cpu(bss->a.beacon_interv));
1890 if (iwe.u.data.length)
1891 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1892 &iwe, custom);
1893
1894 /* Capabilites */
1895 iwe.cmd = IWEVCUSTOM;
1896 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
1897 "capab=0x%04x",
1898 capabilities);
1899 if (iwe.u.data.length)
1900 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1901 &iwe, custom);
1902
1903 /* Add EXTRA: Age to display seconds since last beacon/probe response
1904 * for given network. */
1905 iwe.cmd = IWEVCUSTOM;
1906 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
1907 " Last beacon: %dms ago",
1908 jiffies_to_msecs(jiffies - last_scanned));
1909 if (iwe.u.data.length)
1910 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1911 &iwe, custom);
1912
1913 return current_ev;
1914}
1915
1916static inline char *orinoco_translate_ext_scan(struct net_device *dev,
1917 struct iw_request_info *info,
1918 char *current_ev,
1919 char *end_buf,
1920 struct agere_ext_scan_info *bss,
1921 unsigned long last_scanned)
1922{
1923 u16 capabilities;
1924 u16 channel;
1925 struct iw_event iwe; /* Temporary buffer */
1926 char custom[MAX_CUSTOM_LEN];
1927 u8 *ie;
1928
1929 memset(&iwe, 0, sizeof(iwe));
1930
1931 /* First entry *MUST* be the AP MAC address */
1932 iwe.cmd = SIOCGIWAP;
1933 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1934 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
1935 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1936 &iwe, IW_EV_ADDR_LEN);
1937
1938 /* Other entries will be displayed in the order we give them */
1939
1940 /* Add the ESSID */
1941 ie = bss->data;
1942 iwe.u.data.length = ie[1];
1943 if (iwe.u.data.length) {
1944 if (iwe.u.data.length > 32)
1945 iwe.u.data.length = 32;
1946 iwe.cmd = SIOCGIWESSID;
1947 iwe.u.data.flags = 1;
1948 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1949 &iwe, &ie[2]);
1950 }
1951
1952 /* Add mode */
1953 capabilities = le16_to_cpu(bss->capabilities);
1954 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
1955 iwe.cmd = SIOCGIWMODE;
1956 if (capabilities & WLAN_CAPABILITY_ESS)
1957 iwe.u.mode = IW_MODE_MASTER;
1958 else
1959 iwe.u.mode = IW_MODE_ADHOC;
1960 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1961 &iwe, IW_EV_UINT_LEN);
1962 }
1963
1964 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
1965 channel = ie ? ie[2] : 0;
1966 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
1967 /* Add channel and frequency */
1968 iwe.cmd = SIOCGIWFREQ;
1969 iwe.u.freq.m = channel;
1970 iwe.u.freq.e = 0;
1971 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1972 &iwe, IW_EV_FREQ_LEN);
1973
1974 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
1975 iwe.u.freq.e = 1;
1976 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1977 &iwe, IW_EV_FREQ_LEN);
1978 }
1979
1980 /* Add quality statistics. level and noise in dB. No link quality */
1981 iwe.cmd = IWEVQUAL;
1982 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
1983 iwe.u.qual.level = bss->level - 0x95;
1984 iwe.u.qual.noise = bss->noise - 0x95;
1985 /* Wireless tools prior to 27.pre22 will show link quality
1986 * anyway, so we provide a reasonable value. */
1987 if (iwe.u.qual.level > iwe.u.qual.noise)
1988 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
1989 else
1990 iwe.u.qual.qual = 0;
1991 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1992 &iwe, IW_EV_QUAL_LEN);
1993
1994 /* Add encryption capability */
1995 iwe.cmd = SIOCGIWENCODE;
1996 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1997 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1998 else
1999 iwe.u.data.flags = IW_ENCODE_DISABLED;
2000 iwe.u.data.length = 0;
2001 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2002 &iwe, NULL);
2003
2004 /* WPA IE */
2005 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
2006 if (ie) {
2007 iwe.cmd = IWEVGENIE;
2008 iwe.u.data.length = ie[1] + 2;
2009 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2010 &iwe, ie);
2011 }
2012
2013 /* RSN IE */
2014 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
2015 if (ie) {
2016 iwe.cmd = IWEVGENIE;
2017 iwe.u.data.length = ie[1] + 2;
2018 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2019 &iwe, ie);
2020 }
2021
2022 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
2023 if (ie) {
2024 char *p = current_ev + iwe_stream_lcp_len(info);
2025 int i;
2026
2027 iwe.cmd = SIOCGIWRATE;
2028 /* Those two flags are ignored... */
2029 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
2030
2031 for (i = 2; i < (ie[1] + 2); i++) {
2032 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
2033 p = iwe_stream_add_value(info, current_ev, p, end_buf,
2034 &iwe, IW_EV_PARAM_LEN);
2035 }
2036 /* Check if we added any event */
2037 if (p > (current_ev + iwe_stream_lcp_len(info)))
2038 current_ev = p;
2039 }
2040
2041 /* Timestamp */
2042 iwe.cmd = IWEVCUSTOM;
2043 iwe.u.data.length =
2044 snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
2045 (unsigned long long) le64_to_cpu(bss->timestamp));
2046 if (iwe.u.data.length)
2047 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2048 &iwe, custom);
2049
2050 /* Beacon interval */
2051 iwe.cmd = IWEVCUSTOM;
2052 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
2053 "bcn_int=%d",
2054 le16_to_cpu(bss->beacon_interval));
2055 if (iwe.u.data.length)
2056 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2057 &iwe, custom);
2058
2059 /* Capabilites */
2060 iwe.cmd = IWEVCUSTOM;
2061 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
2062 "capab=0x%04x",
2063 capabilities);
2064 if (iwe.u.data.length)
2065 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2066 &iwe, custom);
2067
2068 /* Add EXTRA: Age to display seconds since last beacon/probe response
2069 * for given network. */
2070 iwe.cmd = IWEVCUSTOM;
2071 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
2072 " Last beacon: %dms ago",
2073 jiffies_to_msecs(jiffies - last_scanned));
2074 if (iwe.u.data.length)
2075 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
2076 &iwe, custom);
2077
2078 return current_ev;
2079}
2080
2081/* Return results of a scan */
2082static int orinoco_ioctl_getscan(struct net_device *dev,
2083 struct iw_request_info *info,
2084 struct iw_point *srq,
2085 char *extra)
2086{
David Kilroyea60a6a2009-06-18 23:21:26 +01002087 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00002088 int err = 0;
2089 unsigned long flags;
2090 char *current_ev = extra;
2091
2092 if (orinoco_lock(priv, &flags) != 0)
2093 return -EBUSY;
2094
2095 if (priv->scan_inprogress) {
2096 /* Important note : we don't want to block the caller
2097 * until results are ready for various reasons.
2098 * First, managing wait queues is complex and racy.
2099 * Second, we grab some rtnetlink lock before comming
2100 * here (in dev_ioctl()).
2101 * Third, we generate an Wireless Event, so the
2102 * caller can wait itself on that - Jean II */
2103 err = -EAGAIN;
2104 goto out;
2105 }
2106
2107 if (priv->has_ext_scan) {
2108 struct xbss_element *bss;
2109
2110 list_for_each_entry(bss, &priv->bss_list, list) {
2111 /* Translate this entry to WE format */
2112 current_ev =
2113 orinoco_translate_ext_scan(dev, info,
2114 current_ev,
2115 extra + srq->length,
2116 &bss->bss,
2117 bss->last_scanned);
2118
2119 /* Check if there is space for one more entry */
2120 if ((extra + srq->length - current_ev)
2121 <= IW_EV_ADDR_LEN) {
2122 /* Ask user space to try again with a
2123 * bigger buffer */
2124 err = -E2BIG;
2125 goto out;
2126 }
2127 }
2128
2129 } else {
2130 struct bss_element *bss;
2131
2132 list_for_each_entry(bss, &priv->bss_list, list) {
2133 /* Translate this entry to WE format */
2134 current_ev = orinoco_translate_scan(dev, info,
2135 current_ev,
2136 extra + srq->length,
2137 &bss->bss,
2138 bss->last_scanned);
2139
2140 /* Check if there is space for one more entry */
2141 if ((extra + srq->length - current_ev)
2142 <= IW_EV_ADDR_LEN) {
2143 /* Ask user space to try again with a
2144 * bigger buffer */
2145 err = -E2BIG;
2146 goto out;
2147 }
2148 }
2149 }
2150
2151 srq->length = (current_ev - extra);
2152 srq->flags = (__u16) priv->scan_mode;
2153
2154out:
2155 orinoco_unlock(priv, &flags);
2156 return err;
2157}
2158
2159/* Commit handler, called after set operations */
2160static int orinoco_ioctl_commit(struct net_device *dev,
2161 struct iw_request_info *info,
2162 void *wrqu,
2163 char *extra)
2164{
David Kilroyea60a6a2009-06-18 23:21:26 +01002165 struct orinoco_private *priv = ndev_priv(dev);
David Kilroycb1576a2009-02-04 23:05:56 +00002166 struct hermes *hw = &priv->hw;
2167 unsigned long flags;
2168 int err = 0;
2169
2170 if (!priv->open)
2171 return 0;
2172
2173 if (priv->broken_disableport) {
2174 orinoco_reset(&priv->reset_work);
2175 return 0;
2176 }
2177
2178 if (orinoco_lock(priv, &flags) != 0)
2179 return err;
2180
2181 err = hermes_disable_port(hw, 0);
2182 if (err) {
2183 printk(KERN_WARNING "%s: Unable to disable port "
2184 "while reconfiguring card\n", dev->name);
2185 priv->broken_disableport = 1;
2186 goto out;
2187 }
2188
2189 err = __orinoco_program_rids(dev);
2190 if (err) {
2191 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
2192 dev->name);
2193 goto out;
2194 }
2195
2196 err = hermes_enable_port(hw, 0);
2197 if (err) {
2198 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
2199 dev->name);
2200 goto out;
2201 }
2202
2203 out:
2204 if (err) {
2205 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
2206 schedule_work(&priv->reset_work);
2207 err = 0;
2208 }
2209
2210 orinoco_unlock(priv, &flags);
2211 return err;
2212}
2213
2214static const struct iw_priv_args orinoco_privtab[] = {
2215 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
2216 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
2217 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2218 0, "set_port3" },
2219 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2220 "get_port3" },
2221 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2222 0, "set_preamble" },
2223 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2224 "get_preamble" },
2225 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2226 0, "set_ibssport" },
2227 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2228 "get_ibssport" },
2229 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
2230 "get_rid" },
2231};
2232
2233
2234/*
2235 * Structures to export the Wireless Handlers
2236 */
2237
2238#define STD_IW_HANDLER(id, func) \
2239 [IW_IOCTL_IDX(id)] = (iw_handler) func
2240static const iw_handler orinoco_handler[] = {
2241 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
David Kilroyea60a6a2009-06-18 23:21:26 +01002242 STD_IW_HANDLER(SIOCGIWNAME, cfg80211_wext_giwname),
David Kilroycb1576a2009-02-04 23:05:56 +00002243 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
2244 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
2245 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
2246 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
2247 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
2248 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
2249 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
2250 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
2251 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
2252 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
2253 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
2254 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
2255 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
2256 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
2257 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
2258 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
2259 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
2260 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
2261 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
2262 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
2263 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
2264 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
2265 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
2266 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
2267 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
2268 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
2269 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
2270 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
2271 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
2272 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
2273 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
2274 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
2275 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
2276 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
2277 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
2278 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
2279 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
2280};
2281
2282
2283/*
2284 Added typecasting since we no longer use iwreq_data -- Moustafa
2285 */
2286static const iw_handler orinoco_private_handler[] = {
2287 [0] = (iw_handler) orinoco_ioctl_reset,
2288 [1] = (iw_handler) orinoco_ioctl_reset,
2289 [2] = (iw_handler) orinoco_ioctl_setport3,
2290 [3] = (iw_handler) orinoco_ioctl_getport3,
2291 [4] = (iw_handler) orinoco_ioctl_setpreamble,
2292 [5] = (iw_handler) orinoco_ioctl_getpreamble,
2293 [6] = (iw_handler) orinoco_ioctl_setibssport,
2294 [7] = (iw_handler) orinoco_ioctl_getibssport,
2295 [9] = (iw_handler) orinoco_ioctl_getrid,
2296};
2297
2298const struct iw_handler_def orinoco_handler_def = {
2299 .num_standard = ARRAY_SIZE(orinoco_handler),
2300 .num_private = ARRAY_SIZE(orinoco_private_handler),
2301 .num_private_args = ARRAY_SIZE(orinoco_privtab),
2302 .standard = orinoco_handler,
2303 .private = orinoco_private_handler,
2304 .private_args = orinoco_privtab,
2305 .get_wireless_stats = orinoco_get_wireless_stats,
2306};