blob: ef74a91e02a5afb26b466e914bcf7af304d57870 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/netdevice.h>
13#include <linux/types.h>
14#include <linux/slab.h>
15#include <linux/skbuff.h>
16#include <linux/etherdevice.h>
17#include <linux/if_arp.h>
18#include <linux/wireless.h>
19#include <net/iw_handler.h>
20#include <asm/uaccess.h>
21
22#include <net/mac80211.h>
23#include "ieee80211_i.h"
24#include "hostapd_ioctl.h"
25#include "ieee80211_rate.h"
26#include "wpa.h"
27#include "aes_ccm.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070028#include "debugfs_key.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070029
30static int ieee80211_regdom = 0x10; /* FCC */
31module_param(ieee80211_regdom, int, 0444);
32MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
33
34/*
35 * If firmware is upgraded by the vendor, additional channels can be used based
36 * on the new Japanese regulatory rules. This is indicated by setting
37 * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
38 * module.
39 */
40static int ieee80211_japan_5ghz /* = 0 */;
41module_param(ieee80211_japan_5ghz, int, 0444);
42MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
43
44static void ieee80211_set_hw_encryption(struct net_device *dev,
45 struct sta_info *sta, u8 addr[ETH_ALEN],
46 struct ieee80211_key *key)
47{
48 struct ieee80211_key_conf *keyconf = NULL;
49 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
50
51 /* default to sw encryption; this will be cleared by low-level
52 * driver if the hw supports requested encryption */
53 if (key)
54 key->force_sw_encrypt = 1;
55
56 if (key && local->ops->set_key &&
57 (keyconf = ieee80211_key_data2conf(local, key))) {
58 if (local->ops->set_key(local_to_hw(local), SET_KEY, addr,
59 keyconf, sta ? sta->aid : 0)) {
60 key->force_sw_encrypt = 1;
61 key->hw_key_idx = HW_KEY_IDX_INVALID;
62 } else {
63 key->force_sw_encrypt =
64 !!(keyconf->flags & IEEE80211_KEY_FORCE_SW_ENCRYPT);
65 key->hw_key_idx =
66 keyconf->hw_key_idx;
67
68 }
69 }
70 kfree(keyconf);
71}
72
73
74static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
75 int idx, int alg, int set_tx_key,
76 const u8 *_key, size_t key_len)
77{
78 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
79 int ret = 0;
80 struct sta_info *sta;
81 struct ieee80211_key *key, *old_key;
82 int try_hwaccel = 1;
83 struct ieee80211_key_conf *keyconf;
84 struct ieee80211_sub_if_data *sdata;
85
86 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
87
88 if (is_broadcast_ether_addr(sta_addr)) {
89 sta = NULL;
90 if (idx >= NUM_DEFAULT_KEYS) {
91 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
92 dev->name, idx);
93 return -EINVAL;
94 }
95 key = sdata->keys[idx];
96
97 /* TODO: consider adding hwaccel support for these; at least
98 * Atheros key cache should be able to handle this since AP is
99 * only transmitting frames with default keys. */
100 /* FIX: hw key cache can be used when only one virtual
101 * STA is associated with each AP. If more than one STA
102 * is associated to the same AP, software encryption
103 * must be used. This should be done automatically
104 * based on configured station devices. For the time
105 * being, this can be only set at compile time. */
106 } else {
107 set_tx_key = 0;
108 if (idx != 0) {
109 printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
110 "individual key\n", dev->name);
111 return -EINVAL;
112 }
113
114 sta = sta_info_get(local, sta_addr);
115 if (!sta) {
116#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
117 printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
118 MAC_FMT "\n",
119 dev->name, MAC_ARG(sta_addr));
120#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
121
122 return -ENOENT;
123 }
124
125 key = sta->key;
126 }
127
128 /* FIX:
129 * Cannot configure default hwaccel keys with WEP algorithm, if
130 * any of the virtual interfaces is using static WEP
131 * configuration because hwaccel would otherwise try to decrypt
132 * these frames.
133 *
134 * For now, just disable WEP hwaccel for broadcast when there is
135 * possibility of conflict with default keys. This can maybe later be
136 * optimized by using non-default keys (at least with Atheros ar521x).
137 */
138 if (!sta && alg == ALG_WEP && !local->default_wep_only &&
139 sdata->type != IEEE80211_IF_TYPE_IBSS &&
140 sdata->type != IEEE80211_IF_TYPE_AP) {
141 try_hwaccel = 0;
142 }
143
144 if (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) {
145 /* Software encryption cannot be used with devices that hide
146 * encryption from the host system, so always try to use
147 * hardware acceleration with such devices. */
148 try_hwaccel = 1;
149 }
150
151 if ((local->hw.flags & IEEE80211_HW_NO_TKIP_WMM_HWACCEL) &&
152 alg == ALG_TKIP) {
153 if (sta && (sta->flags & WLAN_STA_WME)) {
154 /* Hardware does not support hwaccel with TKIP when using WMM.
155 */
156 try_hwaccel = 0;
157 }
158 else if (sdata->type == IEEE80211_IF_TYPE_STA) {
159 sta = sta_info_get(local, sdata->u.sta.bssid);
160 if (sta) {
161 if (sta->flags & WLAN_STA_WME) {
162 try_hwaccel = 0;
163 }
164 sta_info_put(sta);
165 sta = NULL;
166 }
167 }
168 }
169
170 if (alg == ALG_NONE) {
171 keyconf = NULL;
172 if (try_hwaccel && key &&
173 key->hw_key_idx != HW_KEY_IDX_INVALID &&
174 local->ops->set_key &&
175 (keyconf = ieee80211_key_data2conf(local, key)) != NULL &&
176 local->ops->set_key(local_to_hw(local), DISABLE_KEY,
177 sta_addr, keyconf, sta ? sta->aid : 0)) {
178 printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
179 " failed\n", dev->name);
180 ret = -EINVAL;
181 }
182 kfree(keyconf);
183
Jiri Bence9f207f2007-05-05 11:46:38 -0700184 if (set_tx_key || sdata->default_key == key) {
185 ieee80211_debugfs_key_remove_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700186 sdata->default_key = NULL;
Jiri Bence9f207f2007-05-05 11:46:38 -0700187 }
188 ieee80211_debugfs_key_remove(key);
Jiri Bencf0706e82007-05-05 11:45:53 -0700189 if (sta)
190 sta->key = NULL;
191 else
192 sdata->keys[idx] = NULL;
193 ieee80211_key_free(key);
194 key = NULL;
195 } else {
196 old_key = key;
197 key = ieee80211_key_alloc(sta ? NULL : sdata, idx, key_len,
198 GFP_KERNEL);
199 if (!key) {
200 ret = -ENOMEM;
201 goto err_out;
202 }
203
204 /* default to sw encryption; low-level driver sets these if the
205 * requested encryption is supported */
206 key->hw_key_idx = HW_KEY_IDX_INVALID;
207 key->force_sw_encrypt = 1;
208
209 key->alg = alg;
210 key->keyidx = idx;
211 key->keylen = key_len;
212 memcpy(key->key, _key, key_len);
213 if (set_tx_key)
214 key->default_tx_key = 1;
215
216 if (alg == ALG_CCMP) {
217 /* Initialize AES key state here as an optimization
218 * so that it does not need to be initialized for every
219 * packet. */
220 key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(
221 key->key);
222 if (!key->u.ccmp.tfm) {
223 ret = -ENOMEM;
224 goto err_free;
225 }
226 }
227
Jiri Bence9f207f2007-05-05 11:46:38 -0700228 if (set_tx_key || sdata->default_key == old_key) {
229 ieee80211_debugfs_key_remove_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700230 sdata->default_key = NULL;
Jiri Bence9f207f2007-05-05 11:46:38 -0700231 }
232 ieee80211_debugfs_key_remove(old_key);
Jiri Bencf0706e82007-05-05 11:45:53 -0700233 if (sta)
234 sta->key = key;
235 else
236 sdata->keys[idx] = key;
237 ieee80211_key_free(old_key);
Jiri Bence9f207f2007-05-05 11:46:38 -0700238 ieee80211_debugfs_key_add(local, key);
239 if (sta)
240 ieee80211_debugfs_key_sta_link(key, sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700241
242 if (try_hwaccel &&
243 (alg == ALG_WEP || alg == ALG_TKIP || alg == ALG_CCMP))
244 ieee80211_set_hw_encryption(dev, sta, sta_addr, key);
245 }
246
247 if (set_tx_key || (!sta && !sdata->default_key && key)) {
248 sdata->default_key = key;
Jiri Bence9f207f2007-05-05 11:46:38 -0700249 if (key)
250 ieee80211_debugfs_key_add_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700251
252 if (local->ops->set_key_idx &&
253 local->ops->set_key_idx(local_to_hw(local), idx))
254 printk(KERN_DEBUG "%s: failed to set TX key idx for "
255 "low-level driver\n", dev->name);
256 }
257
258 if (sta)
259 sta_info_put(sta);
260
261 return 0;
262
263err_free:
264 ieee80211_key_free(key);
265err_out:
266 if (sta)
267 sta_info_put(sta);
268 return ret;
269}
270
271static int ieee80211_ioctl_siwgenie(struct net_device *dev,
272 struct iw_request_info *info,
273 struct iw_point *data, char *extra)
274{
275 struct ieee80211_sub_if_data *sdata;
276 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
277
278 if (local->user_space_mlme)
279 return -EOPNOTSUPP;
280
281 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
282 if (sdata->type == IEEE80211_IF_TYPE_STA ||
283 sdata->type == IEEE80211_IF_TYPE_IBSS) {
284 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
285 if (ret)
286 return ret;
287 sdata->u.sta.auto_bssid_sel = 0;
288 ieee80211_sta_req_auth(dev, &sdata->u.sta);
289 return 0;
290 }
291
292 if (sdata->type == IEEE80211_IF_TYPE_AP) {
293 kfree(sdata->u.ap.generic_elem);
294 sdata->u.ap.generic_elem = kmalloc(data->length, GFP_KERNEL);
295 if (!sdata->u.ap.generic_elem)
296 return -ENOMEM;
297 memcpy(sdata->u.ap.generic_elem, extra, data->length);
298 sdata->u.ap.generic_elem_len = data->length;
299 return ieee80211_if_config(dev);
300 }
301 return -EOPNOTSUPP;
302}
303
304static int ieee80211_ioctl_set_radio_enabled(struct net_device *dev,
305 int val)
306{
307 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
308 struct ieee80211_conf *conf = &local->hw.conf;
309
310 conf->radio_enabled = val;
311 return ieee80211_hw_config(wdev_priv(dev->ieee80211_ptr));
312}
313
314static int ieee80211_ioctl_giwname(struct net_device *dev,
315 struct iw_request_info *info,
316 char *name, char *extra)
317{
318 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
319
320 switch (local->hw.conf.phymode) {
321 case MODE_IEEE80211A:
322 strcpy(name, "IEEE 802.11a");
323 break;
324 case MODE_IEEE80211B:
325 strcpy(name, "IEEE 802.11b");
326 break;
327 case MODE_IEEE80211G:
328 strcpy(name, "IEEE 802.11g");
329 break;
330 case MODE_ATHEROS_TURBO:
331 strcpy(name, "5GHz Turbo");
332 break;
333 default:
334 strcpy(name, "IEEE 802.11");
335 break;
336 }
337
338 return 0;
339}
340
341
342static int ieee80211_ioctl_giwrange(struct net_device *dev,
343 struct iw_request_info *info,
344 struct iw_point *data, char *extra)
345{
346 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
347 struct iw_range *range = (struct iw_range *) extra;
Hong Liu333af2f2007-07-10 19:32:08 +0200348 struct ieee80211_hw_mode *mode = NULL;
349 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700350
351 data->length = sizeof(struct iw_range);
352 memset(range, 0, sizeof(struct iw_range));
353
354 range->we_version_compiled = WIRELESS_EXT;
355 range->we_version_source = 21;
356 range->retry_capa = IW_RETRY_LIMIT;
357 range->retry_flags = IW_RETRY_LIMIT;
358 range->min_retry = 0;
359 range->max_retry = 255;
360 range->min_rts = 0;
361 range->max_rts = 2347;
362 range->min_frag = 256;
363 range->max_frag = 2346;
364
365 range->encoding_size[0] = 5;
366 range->encoding_size[1] = 13;
367 range->num_encoding_sizes = 2;
368 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
369
370 range->max_qual.qual = local->hw.max_signal;
371 range->max_qual.level = local->hw.max_rssi;
372 range->max_qual.noise = local->hw.max_noise;
373 range->max_qual.updated = local->wstats_flags;
374
375 range->avg_qual.qual = local->hw.max_signal/2;
376 range->avg_qual.level = 0;
377 range->avg_qual.noise = 0;
378 range->avg_qual.updated = local->wstats_flags;
379
380 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
381 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
382
Hong Liu333af2f2007-07-10 19:32:08 +0200383 list_for_each_entry(mode, &local->modes_list, list) {
384 int i = 0;
385
386 if (!(local->enabled_modes & (1 << mode->mode)) ||
387 (local->hw_modes & local->enabled_modes &
388 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
389 continue;
390
391 while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) {
392 struct ieee80211_channel *chan = &mode->channels[i];
393
394 if (chan->flag & IEEE80211_CHAN_W_SCAN) {
395 range->freq[c].i = chan->chan;
396 range->freq[c].m = chan->freq * 100000;
397 range->freq[c].e = 1;
398 c++;
399 }
400 i++;
401 }
402 }
403 range->num_channels = c;
404 range->num_frequency = c;
405
Jiri Bencf0706e82007-05-05 11:45:53 -0700406 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
407 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
408 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
409 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
410
411 return 0;
412}
413
414
415struct ieee80211_channel_range {
416 short start_freq;
417 short end_freq;
418 unsigned char power_level;
419 unsigned char antenna_max;
420};
421
422static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
423 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
424 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
425 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
426 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
427 { 0 }
428};
429
430static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
431 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
432 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
433 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
434 { 0 }
435};
436
437
438static const struct ieee80211_channel_range *channel_range =
439 ieee80211_fcc_channels;
440
441
442static void ieee80211_unmask_channel(struct net_device *dev, int mode,
443 struct ieee80211_channel *chan)
444{
445 int i;
446
447 chan->flag = 0;
448
449 if (ieee80211_regdom == 64 &&
450 (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
451 /* Do not allow Turbo modes in Japan. */
452 return;
453 }
454
455 for (i = 0; channel_range[i].start_freq; i++) {
456 const struct ieee80211_channel_range *r = &channel_range[i];
457 if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
458 if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
459 chan->freq >= 5260 && chan->freq <= 5320) {
460 /*
461 * Skip new channels in Japan since the
462 * firmware was not marked having been upgraded
463 * by the vendor.
464 */
465 continue;
466 }
467
468 if (ieee80211_regdom == 0x10 &&
469 (chan->freq == 5190 || chan->freq == 5210 ||
470 chan->freq == 5230)) {
471 /* Skip MKK channels when in FCC domain. */
472 continue;
473 }
474
475 chan->flag |= IEEE80211_CHAN_W_SCAN |
476 IEEE80211_CHAN_W_ACTIVE_SCAN |
477 IEEE80211_CHAN_W_IBSS;
478 chan->power_level = r->power_level;
479 chan->antenna_max = r->antenna_max;
480
481 if (ieee80211_regdom == 64 &&
482 (chan->freq == 5170 || chan->freq == 5190 ||
483 chan->freq == 5210 || chan->freq == 5230)) {
484 /*
485 * New regulatory rules in Japan have backwards
486 * compatibility with old channels in 5.15-5.25
487 * GHz band, but the station is not allowed to
488 * use active scan on these old channels.
489 */
490 chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
491 }
492
493 if (ieee80211_regdom == 64 &&
494 (chan->freq == 5260 || chan->freq == 5280 ||
495 chan->freq == 5300 || chan->freq == 5320)) {
496 /*
497 * IBSS is not allowed on 5.25-5.35 GHz band
498 * due to radar detection requirements.
499 */
500 chan->flag &= ~IEEE80211_CHAN_W_IBSS;
501 }
502
503 break;
504 }
505 }
506}
507
508
509static int ieee80211_unmask_channels(struct net_device *dev)
510{
511 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
512 struct ieee80211_hw_mode *mode;
513 int c;
514
515 list_for_each_entry(mode, &local->modes_list, list) {
516 for (c = 0; c < mode->num_channels; c++) {
517 ieee80211_unmask_channel(dev, mode->mode,
518 &mode->channels[c]);
519 }
520 }
521 return 0;
522}
523
524
525int ieee80211_init_client(struct net_device *dev)
526{
527 if (ieee80211_regdom == 0x40)
528 channel_range = ieee80211_mkk_channels;
529 ieee80211_unmask_channels(dev);
530 return 0;
531}
532
533
534static int ieee80211_ioctl_siwmode(struct net_device *dev,
535 struct iw_request_info *info,
536 __u32 *mode, char *extra)
537{
538 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
539 int type;
540
541 if (sdata->type == IEEE80211_IF_TYPE_VLAN)
542 return -EOPNOTSUPP;
543
544 switch (*mode) {
545 case IW_MODE_INFRA:
546 type = IEEE80211_IF_TYPE_STA;
547 break;
548 case IW_MODE_ADHOC:
549 type = IEEE80211_IF_TYPE_IBSS;
550 break;
551 case IW_MODE_MONITOR:
552 type = IEEE80211_IF_TYPE_MNTR;
553 break;
554 default:
555 return -EINVAL;
556 }
557
558 if (type == sdata->type)
559 return 0;
560 if (netif_running(dev))
561 return -EBUSY;
562
563 ieee80211_if_reinit(dev);
564 ieee80211_if_set_type(dev, type);
565
566 return 0;
567}
568
569
570static int ieee80211_ioctl_giwmode(struct net_device *dev,
571 struct iw_request_info *info,
572 __u32 *mode, char *extra)
573{
574 struct ieee80211_sub_if_data *sdata;
575
576 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
577 switch (sdata->type) {
578 case IEEE80211_IF_TYPE_AP:
579 *mode = IW_MODE_MASTER;
580 break;
581 case IEEE80211_IF_TYPE_STA:
582 *mode = IW_MODE_INFRA;
583 break;
584 case IEEE80211_IF_TYPE_IBSS:
585 *mode = IW_MODE_ADHOC;
586 break;
587 case IEEE80211_IF_TYPE_MNTR:
588 *mode = IW_MODE_MONITOR;
589 break;
590 case IEEE80211_IF_TYPE_WDS:
591 *mode = IW_MODE_REPEAT;
592 break;
593 case IEEE80211_IF_TYPE_VLAN:
594 *mode = IW_MODE_SECOND; /* FIXME */
595 break;
596 default:
597 *mode = IW_MODE_AUTO;
598 break;
599 }
600 return 0;
601}
602
603int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq)
604{
605 struct ieee80211_hw_mode *mode;
606 int c, set = 0;
607 int ret = -EINVAL;
608
609 list_for_each_entry(mode, &local->modes_list, list) {
610 if (!(local->enabled_modes & (1 << mode->mode)))
611 continue;
612 for (c = 0; c < mode->num_channels; c++) {
613 struct ieee80211_channel *chan = &mode->channels[c];
614 if (chan->flag & IEEE80211_CHAN_W_SCAN &&
615 ((chan->chan == channel) || (chan->freq == freq))) {
616 /* Use next_mode as the mode preference to
617 * resolve non-unique channel numbers. */
618 if (set && mode->mode != local->next_mode)
619 continue;
620
621 local->oper_channel = chan;
622 local->oper_hw_mode = mode;
623 set++;
624 }
625 }
626 }
627
628 if (set) {
629 if (local->sta_scanning)
630 ret = 0;
631 else
632 ret = ieee80211_hw_config(local);
633
634 rate_control_clear(local);
635 }
636
637 return ret;
638}
639
640static int ieee80211_ioctl_siwfreq(struct net_device *dev,
641 struct iw_request_info *info,
642 struct iw_freq *freq, char *extra)
643{
644 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
645 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
646
647 if (sdata->type == IEEE80211_IF_TYPE_STA)
648 sdata->u.sta.auto_channel_sel = 0;
649
650 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
651 if (freq->e == 0) {
652 if (freq->m < 0) {
653 if (sdata->type == IEEE80211_IF_TYPE_STA)
654 sdata->u.sta.auto_channel_sel = 1;
655 return 0;
656 } else
657 return ieee80211_set_channel(local, freq->m, -1);
658 } else {
659 int i, div = 1000000;
660 for (i = 0; i < freq->e; i++)
661 div /= 10;
662 if (div > 0)
663 return ieee80211_set_channel(local, -1, freq->m / div);
664 else
665 return -EINVAL;
666 }
667}
668
669
670static int ieee80211_ioctl_giwfreq(struct net_device *dev,
671 struct iw_request_info *info,
672 struct iw_freq *freq, char *extra)
673{
674 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
675
676 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
677 * driver for the current channel with firmware-based management */
678
679 freq->m = local->hw.conf.freq;
680 freq->e = 6;
681
682 return 0;
683}
684
685
686static int ieee80211_ioctl_siwessid(struct net_device *dev,
687 struct iw_request_info *info,
688 struct iw_point *data, char *ssid)
689{
690 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
691 struct ieee80211_sub_if_data *sdata;
692 size_t len = data->length;
693
694 /* iwconfig uses nul termination in SSID.. */
695 if (len > 0 && ssid[len - 1] == '\0')
696 len--;
697
698 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
699 if (sdata->type == IEEE80211_IF_TYPE_STA ||
700 sdata->type == IEEE80211_IF_TYPE_IBSS) {
701 int ret;
702 if (local->user_space_mlme) {
703 if (len > IEEE80211_MAX_SSID_LEN)
704 return -EINVAL;
705 memcpy(sdata->u.sta.ssid, ssid, len);
706 sdata->u.sta.ssid_len = len;
707 return 0;
708 }
709 sdata->u.sta.auto_ssid_sel = !data->flags;
710 ret = ieee80211_sta_set_ssid(dev, ssid, len);
711 if (ret)
712 return ret;
713 ieee80211_sta_req_auth(dev, &sdata->u.sta);
714 return 0;
715 }
716
717 if (sdata->type == IEEE80211_IF_TYPE_AP) {
718 memcpy(sdata->u.ap.ssid, ssid, len);
719 memset(sdata->u.ap.ssid + len, 0,
720 IEEE80211_MAX_SSID_LEN - len);
721 sdata->u.ap.ssid_len = len;
722 return ieee80211_if_config(dev);
723 }
724 return -EOPNOTSUPP;
725}
726
727
728static int ieee80211_ioctl_giwessid(struct net_device *dev,
729 struct iw_request_info *info,
730 struct iw_point *data, char *ssid)
731{
732 size_t len;
733
734 struct ieee80211_sub_if_data *sdata;
735 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
736 if (sdata->type == IEEE80211_IF_TYPE_STA ||
737 sdata->type == IEEE80211_IF_TYPE_IBSS) {
738 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
739 if (res == 0) {
740 data->length = len;
741 data->flags = 1;
742 } else
743 data->flags = 0;
744 return res;
745 }
746
747 if (sdata->type == IEEE80211_IF_TYPE_AP) {
748 len = sdata->u.ap.ssid_len;
749 if (len > IW_ESSID_MAX_SIZE)
750 len = IW_ESSID_MAX_SIZE;
751 memcpy(ssid, sdata->u.ap.ssid, len);
752 data->length = len;
753 data->flags = 1;
754 return 0;
755 }
756 return -EOPNOTSUPP;
757}
758
759
760static int ieee80211_ioctl_siwap(struct net_device *dev,
761 struct iw_request_info *info,
762 struct sockaddr *ap_addr, char *extra)
763{
764 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
765 struct ieee80211_sub_if_data *sdata;
766
767 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
768 if (sdata->type == IEEE80211_IF_TYPE_STA ||
769 sdata->type == IEEE80211_IF_TYPE_IBSS) {
770 int ret;
771 if (local->user_space_mlme) {
772 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
773 ETH_ALEN);
774 return 0;
775 }
776 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) {
777 sdata->u.sta.auto_bssid_sel = 1;
778 sdata->u.sta.auto_channel_sel = 1;
779 } else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
780 sdata->u.sta.auto_bssid_sel = 1;
781 else
782 sdata->u.sta.auto_bssid_sel = 0;
783 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
784 if (ret)
785 return ret;
786 ieee80211_sta_req_auth(dev, &sdata->u.sta);
787 return 0;
788 } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
789 if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
790 ETH_ALEN) == 0)
791 return 0;
792 return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data);
793 }
794
795 return -EOPNOTSUPP;
796}
797
798
799static int ieee80211_ioctl_giwap(struct net_device *dev,
800 struct iw_request_info *info,
801 struct sockaddr *ap_addr, char *extra)
802{
803 struct ieee80211_sub_if_data *sdata;
804
805 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
806 if (sdata->type == IEEE80211_IF_TYPE_STA ||
807 sdata->type == IEEE80211_IF_TYPE_IBSS) {
808 ap_addr->sa_family = ARPHRD_ETHER;
809 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
810 return 0;
811 } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
812 ap_addr->sa_family = ARPHRD_ETHER;
813 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
814 return 0;
815 }
816
817 return -EOPNOTSUPP;
818}
819
820
821static int ieee80211_ioctl_siwscan(struct net_device *dev,
822 struct iw_request_info *info,
823 struct iw_point *data, char *extra)
824{
825 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
826 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
827 u8 *ssid = NULL;
828 size_t ssid_len = 0;
829
830 if (!netif_running(dev))
831 return -ENETDOWN;
832
833 if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
834 if (sdata->type == IEEE80211_IF_TYPE_STA ||
835 sdata->type == IEEE80211_IF_TYPE_IBSS) {
836 ssid = sdata->u.sta.ssid;
837 ssid_len = sdata->u.sta.ssid_len;
838 } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
839 ssid = sdata->u.ap.ssid;
840 ssid_len = sdata->u.ap.ssid_len;
841 } else
842 return -EINVAL;
843 }
844 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
845}
846
847
848static int ieee80211_ioctl_giwscan(struct net_device *dev,
849 struct iw_request_info *info,
850 struct iw_point *data, char *extra)
851{
852 int res;
853 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
854 if (local->sta_scanning)
855 return -EAGAIN;
856 res = ieee80211_sta_scan_results(dev, extra, data->length);
857 if (res >= 0) {
858 data->length = res;
859 return 0;
860 }
861 data->length = 0;
862 return res;
863}
864
865
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700866static int ieee80211_ioctl_giwrate(struct net_device *dev,
867 struct iw_request_info *info,
868 struct iw_param *rate, char *extra)
869{
870 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
871 struct sta_info *sta;
872 struct ieee80211_sub_if_data *sdata;
873
874 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
875 if (sdata->type == IEEE80211_IF_TYPE_STA)
876 sta = sta_info_get(local, sdata->u.sta.bssid);
877 else
878 return -EOPNOTSUPP;
879 if (!sta)
880 return -ENODEV;
881 if (sta->txrate < local->oper_hw_mode->num_rates)
882 rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000;
883 else
884 rate->value = 0;
885 sta_info_put(sta);
886 return 0;
887}
888
Jiri Bencf0706e82007-05-05 11:45:53 -0700889static int ieee80211_ioctl_siwrts(struct net_device *dev,
890 struct iw_request_info *info,
891 struct iw_param *rts, char *extra)
892{
893 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
894
895 if (rts->disabled)
896 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
897 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
898 return -EINVAL;
899 else
900 local->rts_threshold = rts->value;
901
902 /* If the wlan card performs RTS/CTS in hardware/firmware,
903 * configure it here */
904
905 if (local->ops->set_rts_threshold)
906 local->ops->set_rts_threshold(local_to_hw(local),
907 local->rts_threshold);
908
909 return 0;
910}
911
912static int ieee80211_ioctl_giwrts(struct net_device *dev,
913 struct iw_request_info *info,
914 struct iw_param *rts, char *extra)
915{
916 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
917
918 rts->value = local->rts_threshold;
919 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
920 rts->fixed = 1;
921
922 return 0;
923}
924
925
926static int ieee80211_ioctl_siwfrag(struct net_device *dev,
927 struct iw_request_info *info,
928 struct iw_param *frag, char *extra)
929{
930 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
931
932 if (frag->disabled)
933 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
934 else if (frag->value < 256 ||
935 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
936 return -EINVAL;
937 else {
938 /* Fragment length must be even, so strip LSB. */
939 local->fragmentation_threshold = frag->value & ~0x1;
940 }
941
942 /* If the wlan card performs fragmentation in hardware/firmware,
943 * configure it here */
944
945 if (local->ops->set_frag_threshold)
946 local->ops->set_frag_threshold(
947 local_to_hw(local),
948 local->fragmentation_threshold);
949
950 return 0;
951}
952
953static int ieee80211_ioctl_giwfrag(struct net_device *dev,
954 struct iw_request_info *info,
955 struct iw_param *frag, char *extra)
956{
957 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
958
959 frag->value = local->fragmentation_threshold;
960 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
961 frag->fixed = 1;
962
963 return 0;
964}
965
966
967static int ieee80211_ioctl_siwretry(struct net_device *dev,
968 struct iw_request_info *info,
969 struct iw_param *retry, char *extra)
970{
971 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
972
973 if (retry->disabled ||
974 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
975 return -EINVAL;
976
977 if (retry->flags & IW_RETRY_MAX)
978 local->long_retry_limit = retry->value;
979 else if (retry->flags & IW_RETRY_MIN)
980 local->short_retry_limit = retry->value;
981 else {
982 local->long_retry_limit = retry->value;
983 local->short_retry_limit = retry->value;
984 }
985
986 if (local->ops->set_retry_limit) {
987 return local->ops->set_retry_limit(
988 local_to_hw(local),
989 local->short_retry_limit,
990 local->long_retry_limit);
991 }
992
993 return 0;
994}
995
996
997static int ieee80211_ioctl_giwretry(struct net_device *dev,
998 struct iw_request_info *info,
999 struct iw_param *retry, char *extra)
1000{
1001 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1002
1003 retry->disabled = 0;
1004 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
1005 /* first return min value, iwconfig will ask max value
1006 * later if needed */
1007 retry->flags |= IW_RETRY_LIMIT;
1008 retry->value = local->short_retry_limit;
1009 if (local->long_retry_limit != local->short_retry_limit)
1010 retry->flags |= IW_RETRY_MIN;
1011 return 0;
1012 }
1013 if (retry->flags & IW_RETRY_MAX) {
1014 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1015 retry->value = local->long_retry_limit;
1016 }
1017
1018 return 0;
1019}
1020
1021static int ieee80211_ioctl_clear_keys(struct net_device *dev)
1022{
1023 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1024 struct ieee80211_key_conf key;
1025 int i;
1026 u8 addr[ETH_ALEN];
1027 struct ieee80211_key_conf *keyconf;
1028 struct ieee80211_sub_if_data *sdata;
1029 struct sta_info *sta;
1030
1031 memset(addr, 0xff, ETH_ALEN);
1032 read_lock(&local->sub_if_lock);
1033 list_for_each_entry(sdata, &local->sub_if_list, list) {
1034 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1035 keyconf = NULL;
1036 if (sdata->keys[i] &&
1037 !sdata->keys[i]->force_sw_encrypt &&
1038 local->ops->set_key &&
1039 (keyconf = ieee80211_key_data2conf(local,
1040 sdata->keys[i])))
1041 local->ops->set_key(local_to_hw(local),
1042 DISABLE_KEY, addr,
1043 keyconf, 0);
1044 kfree(keyconf);
1045 ieee80211_key_free(sdata->keys[i]);
1046 sdata->keys[i] = NULL;
1047 }
1048 sdata->default_key = NULL;
1049 }
1050 read_unlock(&local->sub_if_lock);
1051
1052 spin_lock_bh(&local->sta_lock);
1053 list_for_each_entry(sta, &local->sta_list, list) {
1054 keyconf = NULL;
1055 if (sta->key && !sta->key->force_sw_encrypt &&
1056 local->ops->set_key &&
1057 (keyconf = ieee80211_key_data2conf(local, sta->key)))
1058 local->ops->set_key(local_to_hw(local), DISABLE_KEY,
1059 sta->addr, keyconf, sta->aid);
1060 kfree(keyconf);
1061 ieee80211_key_free(sta->key);
1062 sta->key = NULL;
1063 }
1064 spin_unlock_bh(&local->sta_lock);
1065
1066 memset(&key, 0, sizeof(key));
1067 if (local->ops->set_key &&
1068 local->ops->set_key(local_to_hw(local), REMOVE_ALL_KEYS,
1069 NULL, &key, 0))
1070 printk(KERN_DEBUG "%s: failed to remove hwaccel keys\n",
1071 dev->name);
1072
1073 return 0;
1074}
1075
1076
1077static int
1078ieee80211_ioctl_force_unicast_rate(struct net_device *dev,
1079 struct ieee80211_sub_if_data *sdata,
1080 int rate)
1081{
1082 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1083 struct ieee80211_hw_mode *mode;
1084 int i;
1085
1086 if (sdata->type != IEEE80211_IF_TYPE_AP)
1087 return -ENOENT;
1088
1089 if (rate == 0) {
1090 sdata->u.ap.force_unicast_rateidx = -1;
1091 return 0;
1092 }
1093
1094 mode = local->oper_hw_mode;
1095 for (i = 0; i < mode->num_rates; i++) {
1096 if (mode->rates[i].rate == rate) {
1097 sdata->u.ap.force_unicast_rateidx = i;
1098 return 0;
1099 }
1100 }
1101 return -EINVAL;
1102}
1103
1104
1105static int
1106ieee80211_ioctl_max_ratectrl_rate(struct net_device *dev,
1107 struct ieee80211_sub_if_data *sdata,
1108 int rate)
1109{
1110 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1111 struct ieee80211_hw_mode *mode;
1112 int i;
1113
1114 if (sdata->type != IEEE80211_IF_TYPE_AP)
1115 return -ENOENT;
1116
1117 if (rate == 0) {
1118 sdata->u.ap.max_ratectrl_rateidx = -1;
1119 return 0;
1120 }
1121
1122 mode = local->oper_hw_mode;
1123 for (i = 0; i < mode->num_rates; i++) {
1124 if (mode->rates[i].rate == rate) {
1125 sdata->u.ap.max_ratectrl_rateidx = i;
1126 return 0;
1127 }
1128 }
1129 return -EINVAL;
1130}
1131
1132
1133static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
1134 struct ieee80211_key *key)
1135{
1136 struct ieee80211_key_conf *keyconf;
1137 u8 addr[ETH_ALEN];
1138
1139 if (!key || key->alg != ALG_WEP || !key->force_sw_encrypt ||
1140 (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP))
1141 return;
1142
1143 memset(addr, 0xff, ETH_ALEN);
1144 keyconf = ieee80211_key_data2conf(local, key);
1145 if (keyconf && local->ops->set_key &&
1146 local->ops->set_key(local_to_hw(local),
1147 SET_KEY, addr, keyconf, 0) == 0) {
1148 key->force_sw_encrypt =
1149 !!(keyconf->flags & IEEE80211_KEY_FORCE_SW_ENCRYPT);
1150 key->hw_key_idx = keyconf->hw_key_idx;
1151 }
1152 kfree(keyconf);
1153}
1154
1155
1156static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
1157 struct ieee80211_key *key)
1158{
1159 struct ieee80211_key_conf *keyconf;
1160 u8 addr[ETH_ALEN];
1161
1162 if (!key || key->alg != ALG_WEP || key->force_sw_encrypt ||
1163 (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP))
1164 return;
1165
1166 memset(addr, 0xff, ETH_ALEN);
1167 keyconf = ieee80211_key_data2conf(local, key);
1168 if (keyconf && local->ops->set_key)
1169 local->ops->set_key(local_to_hw(local), DISABLE_KEY,
1170 addr, keyconf, 0);
1171 kfree(keyconf);
1172 key->force_sw_encrypt = 1;
1173}
1174
1175
1176static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
1177 int value)
1178{
1179 int i;
1180 struct ieee80211_sub_if_data *sdata;
1181
1182 local->default_wep_only = value;
1183 read_lock(&local->sub_if_lock);
1184 list_for_each_entry(sdata, &local->sub_if_list, list)
1185 for (i = 0; i < NUM_DEFAULT_KEYS; i++)
1186 if (value)
1187 ieee80211_key_enable_hwaccel(local,
1188 sdata->keys[i]);
1189 else
1190 ieee80211_key_disable_hwaccel(local,
1191 sdata->keys[i]);
1192 read_unlock(&local->sub_if_lock);
1193
1194 return 0;
1195}
1196
1197
1198void ieee80211_update_default_wep_only(struct ieee80211_local *local)
1199{
1200 int i = 0;
1201 struct ieee80211_sub_if_data *sdata;
1202
1203 read_lock(&local->sub_if_lock);
1204 list_for_each_entry(sdata, &local->sub_if_list, list) {
1205
1206 if (sdata->dev == local->mdev)
1207 continue;
1208
1209 /* If there is an AP interface then depend on userspace to
1210 set default_wep_only correctly. */
1211 if (sdata->type == IEEE80211_IF_TYPE_AP) {
1212 read_unlock(&local->sub_if_lock);
1213 return;
1214 }
1215
1216 i++;
1217 }
1218
1219 read_unlock(&local->sub_if_lock);
1220
1221 if (i <= 1)
1222 ieee80211_ioctl_default_wep_only(local, 1);
1223 else
1224 ieee80211_ioctl_default_wep_only(local, 0);
1225}
1226
1227
1228static int ieee80211_ioctl_prism2_param(struct net_device *dev,
1229 struct iw_request_info *info,
1230 void *wrqu, char *extra)
1231{
1232 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1233 struct ieee80211_sub_if_data *sdata;
1234 int *i = (int *) extra;
1235 int param = *i;
1236 int value = *(i + 1);
1237 int ret = 0;
1238
1239 if (!capable(CAP_NET_ADMIN))
1240 return -EPERM;
1241
1242 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1243
1244 switch (param) {
1245 case PRISM2_PARAM_IEEE_802_1X:
1246 if (local->ops->set_ieee8021x)
1247 ret = local->ops->set_ieee8021x(local_to_hw(local),
1248 value);
1249 if (ret)
1250 printk(KERN_DEBUG "%s: failed to set IEEE 802.1X (%d) "
1251 "for low-level driver\n", dev->name, value);
1252 else
1253 sdata->ieee802_1x = value;
1254 break;
1255
1256 case PRISM2_PARAM_ANTSEL_TX:
1257 local->hw.conf.antenna_sel_tx = value;
1258 if (ieee80211_hw_config(local))
1259 ret = -EINVAL;
1260 break;
1261
1262 case PRISM2_PARAM_ANTSEL_RX:
1263 local->hw.conf.antenna_sel_rx = value;
1264 if (ieee80211_hw_config(local))
1265 ret = -EINVAL;
1266 break;
1267
1268 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
1269 local->cts_protect_erp_frames = value;
1270 break;
1271
1272 case PRISM2_PARAM_DROP_UNENCRYPTED:
1273 sdata->drop_unencrypted = value;
1274 break;
1275
1276 case PRISM2_PARAM_PREAMBLE:
1277 local->short_preamble = value;
1278 break;
1279
1280 case PRISM2_PARAM_STAT_TIME:
1281 if (!local->stat_time && value) {
1282 local->stat_timer.expires = jiffies + HZ * value / 100;
1283 add_timer(&local->stat_timer);
1284 } else if (local->stat_time && !value) {
1285 del_timer_sync(&local->stat_timer);
1286 }
1287 local->stat_time = value;
1288 break;
1289 case PRISM2_PARAM_SHORT_SLOT_TIME:
1290 if (value)
1291 local->hw.conf.flags |= IEEE80211_CONF_SHORT_SLOT_TIME;
1292 else
1293 local->hw.conf.flags &= ~IEEE80211_CONF_SHORT_SLOT_TIME;
1294 if (ieee80211_hw_config(local))
1295 ret = -EINVAL;
1296 break;
1297
1298 case PRISM2_PARAM_NEXT_MODE:
1299 local->next_mode = value;
1300 break;
1301
1302 case PRISM2_PARAM_CLEAR_KEYS:
1303 ret = ieee80211_ioctl_clear_keys(dev);
1304 break;
1305
1306 case PRISM2_PARAM_RADIO_ENABLED:
1307 ret = ieee80211_ioctl_set_radio_enabled(dev, value);
1308 break;
1309
1310 case PRISM2_PARAM_ANTENNA_MODE:
1311 local->hw.conf.antenna_mode = value;
1312 if (ieee80211_hw_config(local))
1313 ret = -EINVAL;
1314 break;
1315
1316 case PRISM2_PARAM_STA_ANTENNA_SEL:
1317 local->sta_antenna_sel = value;
1318 break;
1319
1320 case PRISM2_PARAM_FORCE_UNICAST_RATE:
1321 ret = ieee80211_ioctl_force_unicast_rate(dev, sdata, value);
1322 break;
1323
1324 case PRISM2_PARAM_MAX_RATECTRL_RATE:
1325 ret = ieee80211_ioctl_max_ratectrl_rate(dev, sdata, value);
1326 break;
1327
1328 case PRISM2_PARAM_RATE_CTRL_NUM_UP:
1329 local->rate_ctrl_num_up = value;
1330 break;
1331
1332 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
1333 local->rate_ctrl_num_down = value;
1334 break;
1335
1336 case PRISM2_PARAM_TX_POWER_REDUCTION:
1337 if (value < 0)
1338 ret = -EINVAL;
1339 else
1340 local->hw.conf.tx_power_reduction = value;
1341 break;
1342
1343 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
1344 local->key_tx_rx_threshold = value;
1345 break;
1346
1347 case PRISM2_PARAM_DEFAULT_WEP_ONLY:
1348 ret = ieee80211_ioctl_default_wep_only(local, value);
1349 break;
1350
1351 case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
1352 local->wifi_wme_noack_test = value;
1353 break;
1354
1355 case PRISM2_PARAM_SCAN_FLAGS:
1356 local->scan_flags = value;
1357 break;
1358
1359 case PRISM2_PARAM_MIXED_CELL:
1360 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1361 sdata->type != IEEE80211_IF_TYPE_IBSS)
1362 ret = -EINVAL;
1363 else
1364 sdata->u.sta.mixed_cell = !!value;
1365 break;
1366
1367 case PRISM2_PARAM_HW_MODES:
1368 local->enabled_modes = value;
1369 break;
1370
1371 case PRISM2_PARAM_CREATE_IBSS:
1372 if (sdata->type != IEEE80211_IF_TYPE_IBSS)
1373 ret = -EINVAL;
1374 else
1375 sdata->u.sta.create_ibss = !!value;
1376 break;
1377 case PRISM2_PARAM_WMM_ENABLED:
1378 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1379 sdata->type != IEEE80211_IF_TYPE_IBSS)
1380 ret = -EINVAL;
1381 else
1382 sdata->u.sta.wmm_enabled = !!value;
1383 break;
1384 case PRISM2_PARAM_RADAR_DETECT:
1385 local->hw.conf.radar_detect = value;
1386 break;
1387 case PRISM2_PARAM_SPECTRUM_MGMT:
1388 local->hw.conf.spect_mgmt = value;
1389 break;
1390 default:
1391 ret = -EOPNOTSUPP;
1392 break;
1393 }
1394
1395 return ret;
1396}
1397
1398
1399static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
1400 struct iw_request_info *info,
1401 void *wrqu, char *extra)
1402{
1403 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1404 struct ieee80211_sub_if_data *sdata;
1405 int *param = (int *) extra;
1406 int ret = 0;
1407
1408 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1409
1410 switch (*param) {
1411 case PRISM2_PARAM_IEEE_802_1X:
1412 *param = sdata->ieee802_1x;
1413 break;
1414
1415 case PRISM2_PARAM_ANTSEL_TX:
1416 *param = local->hw.conf.antenna_sel_tx;
1417 break;
1418
1419 case PRISM2_PARAM_ANTSEL_RX:
1420 *param = local->hw.conf.antenna_sel_rx;
1421 break;
1422
1423 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
1424 *param = local->cts_protect_erp_frames;
1425 break;
1426
1427 case PRISM2_PARAM_DROP_UNENCRYPTED:
1428 *param = sdata->drop_unencrypted;
1429 break;
1430
1431 case PRISM2_PARAM_PREAMBLE:
1432 *param = local->short_preamble;
1433 break;
1434
1435 case PRISM2_PARAM_STAT_TIME:
1436 *param = local->stat_time;
1437 break;
1438 case PRISM2_PARAM_SHORT_SLOT_TIME:
1439 *param = !!(local->hw.conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME);
1440 break;
1441
1442 case PRISM2_PARAM_NEXT_MODE:
1443 *param = local->next_mode;
1444 break;
1445
1446 case PRISM2_PARAM_ANTENNA_MODE:
1447 *param = local->hw.conf.antenna_mode;
1448 break;
1449
1450 case PRISM2_PARAM_STA_ANTENNA_SEL:
1451 *param = local->sta_antenna_sel;
1452 break;
1453
1454 case PRISM2_PARAM_RATE_CTRL_NUM_UP:
1455 *param = local->rate_ctrl_num_up;
1456 break;
1457
1458 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
1459 *param = local->rate_ctrl_num_down;
1460 break;
1461
1462 case PRISM2_PARAM_TX_POWER_REDUCTION:
1463 *param = local->hw.conf.tx_power_reduction;
1464 break;
1465
1466 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
1467 *param = local->key_tx_rx_threshold;
1468 break;
1469
1470 case PRISM2_PARAM_DEFAULT_WEP_ONLY:
1471 *param = local->default_wep_only;
1472 break;
1473
1474 case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
1475 *param = local->wifi_wme_noack_test;
1476 break;
1477
1478 case PRISM2_PARAM_SCAN_FLAGS:
1479 *param = local->scan_flags;
1480 break;
1481
1482 case PRISM2_PARAM_HW_MODES:
1483 *param = local->enabled_modes;
1484 break;
1485
1486 case PRISM2_PARAM_CREATE_IBSS:
1487 if (sdata->type != IEEE80211_IF_TYPE_IBSS)
1488 ret = -EINVAL;
1489 else
1490 *param = !!sdata->u.sta.create_ibss;
1491 break;
1492
1493 case PRISM2_PARAM_MIXED_CELL:
1494 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1495 sdata->type != IEEE80211_IF_TYPE_IBSS)
1496 ret = -EINVAL;
1497 else
1498 *param = !!sdata->u.sta.mixed_cell;
1499 break;
1500 case PRISM2_PARAM_WMM_ENABLED:
1501 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1502 sdata->type != IEEE80211_IF_TYPE_IBSS)
1503 ret = -EINVAL;
1504 else
1505 *param = !!sdata->u.sta.wmm_enabled;
1506 break;
1507 default:
1508 ret = -EOPNOTSUPP;
1509 break;
1510 }
1511
1512 return ret;
1513}
1514
1515static int ieee80211_ioctl_siwmlme(struct net_device *dev,
1516 struct iw_request_info *info,
1517 struct iw_point *data, char *extra)
1518{
1519 struct ieee80211_sub_if_data *sdata;
1520 struct iw_mlme *mlme = (struct iw_mlme *) extra;
1521
1522 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1523 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1524 sdata->type != IEEE80211_IF_TYPE_IBSS)
1525 return -EINVAL;
1526
1527 switch (mlme->cmd) {
1528 case IW_MLME_DEAUTH:
1529 /* TODO: mlme->addr.sa_data */
1530 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
1531 case IW_MLME_DISASSOC:
1532 /* TODO: mlme->addr.sa_data */
1533 return ieee80211_sta_disassociate(dev, mlme->reason_code);
1534 default:
1535 return -EOPNOTSUPP;
1536 }
1537}
1538
1539
1540static int ieee80211_ioctl_siwencode(struct net_device *dev,
1541 struct iw_request_info *info,
1542 struct iw_point *erq, char *keybuf)
1543{
1544 struct ieee80211_sub_if_data *sdata;
1545 int idx, i, alg = ALG_WEP;
1546 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1547
1548 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1549
1550 idx = erq->flags & IW_ENCODE_INDEX;
1551 if (idx == 0) {
1552 if (sdata->default_key)
1553 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1554 if (sdata->default_key == sdata->keys[i]) {
1555 idx = i;
1556 break;
1557 }
1558 }
1559 } else if (idx < 1 || idx > 4)
1560 return -EINVAL;
1561 else
1562 idx--;
1563
1564 if (erq->flags & IW_ENCODE_DISABLED)
1565 alg = ALG_NONE;
1566 else if (erq->length == 0) {
1567 /* No key data - just set the default TX key index */
Jiri Bence9f207f2007-05-05 11:46:38 -07001568 if (sdata->default_key != sdata->keys[idx]) {
1569 ieee80211_debugfs_key_remove_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001570 sdata->default_key = sdata->keys[idx];
Jiri Bence9f207f2007-05-05 11:46:38 -07001571 if (sdata->default_key)
1572 ieee80211_debugfs_key_add_default(sdata);
1573 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001574 return 0;
1575 }
1576
1577 return ieee80211_set_encryption(
1578 dev, bcaddr,
1579 idx, alg,
1580 !sdata->default_key,
1581 keybuf, erq->length);
1582}
1583
1584
1585static int ieee80211_ioctl_giwencode(struct net_device *dev,
1586 struct iw_request_info *info,
1587 struct iw_point *erq, char *key)
1588{
1589 struct ieee80211_sub_if_data *sdata;
1590 int idx, i;
1591
1592 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1593
1594 idx = erq->flags & IW_ENCODE_INDEX;
1595 if (idx < 1 || idx > 4) {
1596 idx = -1;
1597 if (!sdata->default_key)
1598 idx = 0;
1599 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1600 if (sdata->default_key == sdata->keys[i]) {
1601 idx = i;
1602 break;
1603 }
1604 }
1605 if (idx < 0)
1606 return -EINVAL;
1607 } else
1608 idx--;
1609
1610 erq->flags = idx + 1;
1611
1612 if (!sdata->keys[idx]) {
1613 erq->length = 0;
1614 erq->flags |= IW_ENCODE_DISABLED;
1615 return 0;
1616 }
1617
1618 memcpy(key, sdata->keys[idx]->key,
1619 min((int)erq->length, sdata->keys[idx]->keylen));
1620 erq->length = sdata->keys[idx]->keylen;
1621 erq->flags |= IW_ENCODE_ENABLED;
1622
1623 return 0;
1624}
1625
1626static int ieee80211_ioctl_siwauth(struct net_device *dev,
1627 struct iw_request_info *info,
1628 struct iw_param *data, char *extra)
1629{
1630 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1631 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1632 int ret = 0;
1633
1634 switch (data->flags & IW_AUTH_INDEX) {
1635 case IW_AUTH_WPA_VERSION:
1636 case IW_AUTH_CIPHER_PAIRWISE:
1637 case IW_AUTH_CIPHER_GROUP:
1638 case IW_AUTH_WPA_ENABLED:
1639 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1640 break;
1641 case IW_AUTH_KEY_MGMT:
1642 if (sdata->type != IEEE80211_IF_TYPE_STA)
1643 ret = -EINVAL;
1644 else {
1645 /*
1646 * TODO: sdata->u.sta.key_mgmt does not match with WE18
1647 * value completely; could consider modifying this to
1648 * be closer to WE18. For now, this value is not really
1649 * used for anything else than Privacy matching, so the
1650 * current code here should be more or less OK.
1651 */
1652 if (data->value & IW_AUTH_KEY_MGMT_802_1X) {
1653 sdata->u.sta.key_mgmt =
1654 IEEE80211_KEY_MGMT_WPA_EAP;
1655 } else if (data->value & IW_AUTH_KEY_MGMT_PSK) {
1656 sdata->u.sta.key_mgmt =
1657 IEEE80211_KEY_MGMT_WPA_PSK;
1658 } else {
1659 sdata->u.sta.key_mgmt =
1660 IEEE80211_KEY_MGMT_NONE;
1661 }
1662 }
1663 break;
1664 case IW_AUTH_80211_AUTH_ALG:
1665 if (sdata->type == IEEE80211_IF_TYPE_STA ||
1666 sdata->type == IEEE80211_IF_TYPE_IBSS)
1667 sdata->u.sta.auth_algs = data->value;
1668 else
1669 ret = -EOPNOTSUPP;
1670 break;
1671 case IW_AUTH_PRIVACY_INVOKED:
1672 if (local->ops->set_privacy_invoked)
1673 ret = local->ops->set_privacy_invoked(
1674 local_to_hw(local), data->value);
1675 break;
1676 default:
1677 ret = -EOPNOTSUPP;
1678 break;
1679 }
1680 return ret;
1681}
1682
1683/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1684static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1685{
1686 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1687 struct iw_statistics *wstats = &local->wstats;
1688 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1689 struct sta_info *sta = NULL;
1690
1691 if (sdata->type == IEEE80211_IF_TYPE_STA ||
1692 sdata->type == IEEE80211_IF_TYPE_IBSS)
1693 sta = sta_info_get(local, sdata->u.sta.bssid);
1694 if (!sta) {
1695 wstats->discard.fragment = 0;
1696 wstats->discard.misc = 0;
1697 wstats->qual.qual = 0;
1698 wstats->qual.level = 0;
1699 wstats->qual.noise = 0;
1700 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1701 } else {
1702 wstats->qual.level = sta->last_rssi;
1703 wstats->qual.qual = sta->last_signal;
1704 wstats->qual.noise = sta->last_noise;
1705 wstats->qual.updated = local->wstats_flags;
1706 sta_info_put(sta);
1707 }
1708 return wstats;
1709}
1710
1711static int ieee80211_ioctl_giwauth(struct net_device *dev,
1712 struct iw_request_info *info,
1713 struct iw_param *data, char *extra)
1714{
1715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1716 int ret = 0;
1717
1718 switch (data->flags & IW_AUTH_INDEX) {
1719 case IW_AUTH_80211_AUTH_ALG:
1720 if (sdata->type == IEEE80211_IF_TYPE_STA ||
1721 sdata->type == IEEE80211_IF_TYPE_IBSS)
1722 data->value = sdata->u.sta.auth_algs;
1723 else
1724 ret = -EOPNOTSUPP;
1725 break;
1726 default:
1727 ret = -EOPNOTSUPP;
1728 break;
1729 }
1730 return ret;
1731}
1732
1733
1734static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1735 struct iw_request_info *info,
1736 struct iw_point *erq, char *extra)
1737{
1738 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1739 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1740 int alg, idx, i;
1741
1742 switch (ext->alg) {
1743 case IW_ENCODE_ALG_NONE:
1744 alg = ALG_NONE;
1745 break;
1746 case IW_ENCODE_ALG_WEP:
1747 alg = ALG_WEP;
1748 break;
1749 case IW_ENCODE_ALG_TKIP:
1750 alg = ALG_TKIP;
1751 break;
1752 case IW_ENCODE_ALG_CCMP:
1753 alg = ALG_CCMP;
1754 break;
1755 default:
1756 return -EOPNOTSUPP;
1757 }
1758
1759 if (erq->flags & IW_ENCODE_DISABLED)
1760 alg = ALG_NONE;
1761
1762 idx = erq->flags & IW_ENCODE_INDEX;
1763 if (idx < 1 || idx > 4) {
1764 idx = -1;
1765 if (!sdata->default_key)
1766 idx = 0;
1767 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1768 if (sdata->default_key == sdata->keys[i]) {
1769 idx = i;
1770 break;
1771 }
1772 }
1773 if (idx < 0)
1774 return -EINVAL;
1775 } else
1776 idx--;
1777
1778 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
1779 ext->ext_flags &
1780 IW_ENCODE_EXT_SET_TX_KEY,
1781 ext->key, ext->key_len);
1782}
1783
1784
1785static const struct iw_priv_args ieee80211_ioctl_priv[] = {
1786 { PRISM2_IOCTL_PRISM2_PARAM,
1787 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "param" },
1788 { PRISM2_IOCTL_GET_PRISM2_PARAM,
1789 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1790 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param" },
1791};
1792
1793/* Structures to export the Wireless Handlers */
1794
1795static const iw_handler ieee80211_handler[] =
1796{
1797 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1798 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1799 (iw_handler) NULL, /* SIOCSIWNWID */
1800 (iw_handler) NULL, /* SIOCGIWNWID */
1801 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1802 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1803 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1804 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1805 (iw_handler) NULL, /* SIOCSIWSENS */
1806 (iw_handler) NULL, /* SIOCGIWSENS */
1807 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1808 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1809 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1810 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1811 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1812 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1813 iw_handler_set_spy, /* SIOCSIWSPY */
1814 iw_handler_get_spy, /* SIOCGIWSPY */
1815 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
1816 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
1817 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1818 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1819 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1820 (iw_handler) NULL, /* SIOCGIWAPLIST */
1821 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1822 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1823 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1824 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1825 (iw_handler) NULL, /* SIOCSIWNICKN */
1826 (iw_handler) NULL, /* SIOCGIWNICKN */
1827 (iw_handler) NULL, /* -- hole -- */
1828 (iw_handler) NULL, /* -- hole -- */
1829 (iw_handler) NULL, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001830 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001831 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1832 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1833 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1834 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1835 (iw_handler) NULL, /* SIOCSIWTXPOW */
1836 (iw_handler) NULL, /* SIOCGIWTXPOW */
1837 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1838 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1839 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1840 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1841 (iw_handler) NULL, /* SIOCSIWPOWER */
1842 (iw_handler) NULL, /* SIOCGIWPOWER */
1843 (iw_handler) NULL, /* -- hole -- */
1844 (iw_handler) NULL, /* -- hole -- */
1845 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1846 (iw_handler) NULL, /* SIOCGIWGENIE */
1847 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1848 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1849 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1850 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1851 (iw_handler) NULL, /* SIOCSIWPMKSA */
1852 (iw_handler) NULL, /* -- hole -- */
1853};
1854
1855static const iw_handler ieee80211_private_handler[] =
1856{ /* SIOCIWFIRSTPRIV + */
1857 (iw_handler) ieee80211_ioctl_prism2_param, /* 0 */
1858 (iw_handler) ieee80211_ioctl_get_prism2_param, /* 1 */
1859};
1860
1861const struct iw_handler_def ieee80211_iw_handler_def =
1862{
1863 .num_standard = ARRAY_SIZE(ieee80211_handler),
1864 .num_private = ARRAY_SIZE(ieee80211_private_handler),
1865 .num_private_args = ARRAY_SIZE(ieee80211_ioctl_priv),
1866 .standard = (iw_handler *) ieee80211_handler,
1867 .private = (iw_handler *) ieee80211_private_handler,
1868 .private_args = (struct iw_priv_args *) ieee80211_ioctl_priv,
1869 .get_wireless_stats = ieee80211_get_wireless_stats,
1870};