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