2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
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.
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>
22 #include <net/mac80211.h>
23 #include "ieee80211_i.h"
24 #include "hostapd_ioctl.h"
25 #include "ieee80211_rate.h"
29 static int ieee80211_regdom = 0x10; /* FCC */
30 module_param(ieee80211_regdom, int, 0444);
31 MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
34 * If firmware is upgraded by the vendor, additional channels can be used based
35 * on the new Japanese regulatory rules. This is indicated by setting
36 * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
39 static int ieee80211_japan_5ghz /* = 0 */;
40 module_param(ieee80211_japan_5ghz, int, 0444);
41 MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
43 static void ieee80211_set_hw_encryption(struct net_device *dev,
44 struct sta_info *sta, u8 addr[ETH_ALEN],
45 struct ieee80211_key *key)
47 struct ieee80211_key_conf *keyconf = NULL;
48 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
50 /* default to sw encryption; this will be cleared by low-level
51 * driver if the hw supports requested encryption */
53 key->force_sw_encrypt = 1;
55 if (key && local->ops->set_key &&
56 (keyconf = ieee80211_key_data2conf(local, key))) {
57 if (local->ops->set_key(local_to_hw(local), SET_KEY, addr,
58 keyconf, sta ? sta->aid : 0)) {
59 key->force_sw_encrypt = 1;
60 key->hw_key_idx = HW_KEY_IDX_INVALID;
62 key->force_sw_encrypt =
63 !!(keyconf->flags & IEEE80211_KEY_FORCE_SW_ENCRYPT);
73 static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
74 int idx, int alg, int set_tx_key,
75 const u8 *_key, size_t key_len)
77 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
80 struct ieee80211_key *key, *old_key;
82 struct ieee80211_key_conf *keyconf;
83 struct ieee80211_sub_if_data *sdata;
85 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
87 if (is_broadcast_ether_addr(sta_addr)) {
89 if (idx >= NUM_DEFAULT_KEYS) {
90 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
94 key = sdata->keys[idx];
96 /* TODO: consider adding hwaccel support for these; at least
97 * Atheros key cache should be able to handle this since AP is
98 * only transmitting frames with default keys. */
99 /* FIX: hw key cache can be used when only one virtual
100 * STA is associated with each AP. If more than one STA
101 * is associated to the same AP, software encryption
102 * must be used. This should be done automatically
103 * based on configured station devices. For the time
104 * being, this can be only set at compile time. */
108 printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
109 "individual key\n", dev->name);
113 sta = sta_info_get(local, sta_addr);
115 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
116 printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
118 dev->name, MAC_ARG(sta_addr));
119 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
128 * Cannot configure default hwaccel keys with WEP algorithm, if
129 * any of the virtual interfaces is using static WEP
130 * configuration because hwaccel would otherwise try to decrypt
133 * For now, just disable WEP hwaccel for broadcast when there is
134 * possibility of conflict with default keys. This can maybe later be
135 * optimized by using non-default keys (at least with Atheros ar521x).
137 if (!sta && alg == ALG_WEP && !local->default_wep_only &&
138 sdata->type != IEEE80211_IF_TYPE_IBSS &&
139 sdata->type != IEEE80211_IF_TYPE_AP) {
143 if (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) {
144 /* Software encryption cannot be used with devices that hide
145 * encryption from the host system, so always try to use
146 * hardware acceleration with such devices. */
150 if ((local->hw.flags & IEEE80211_HW_NO_TKIP_WMM_HWACCEL) &&
152 if (sta && (sta->flags & WLAN_STA_WME)) {
153 /* Hardware does not support hwaccel with TKIP when using WMM.
157 else if (sdata->type == IEEE80211_IF_TYPE_STA) {
158 sta = sta_info_get(local, sdata->u.sta.bssid);
160 if (sta->flags & WLAN_STA_WME) {
169 if (alg == ALG_NONE) {
171 if (try_hwaccel && key &&
172 key->hw_key_idx != HW_KEY_IDX_INVALID &&
173 local->ops->set_key &&
174 (keyconf = ieee80211_key_data2conf(local, key)) != NULL &&
175 local->ops->set_key(local_to_hw(local), DISABLE_KEY,
176 sta_addr, keyconf, sta ? sta->aid : 0)) {
177 printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
178 " failed\n", dev->name);
183 if (set_tx_key || sdata->default_key == key)
184 sdata->default_key = NULL;
188 sdata->keys[idx] = NULL;
189 ieee80211_key_free(key);
193 key = ieee80211_key_alloc(sta ? NULL : sdata, idx, key_len,
200 /* default to sw encryption; low-level driver sets these if the
201 * requested encryption is supported */
202 key->hw_key_idx = HW_KEY_IDX_INVALID;
203 key->force_sw_encrypt = 1;
207 key->keylen = key_len;
208 memcpy(key->key, _key, key_len);
210 key->default_tx_key = 1;
212 if (alg == ALG_CCMP) {
213 /* Initialize AES key state here as an optimization
214 * so that it does not need to be initialized for every
216 key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(
218 if (!key->u.ccmp.tfm) {
224 if (set_tx_key || sdata->default_key == old_key)
225 sdata->default_key = NULL;
229 sdata->keys[idx] = key;
230 ieee80211_key_free(old_key);
233 (alg == ALG_WEP || alg == ALG_TKIP || alg == ALG_CCMP))
234 ieee80211_set_hw_encryption(dev, sta, sta_addr, key);
237 if (set_tx_key || (!sta && !sdata->default_key && key)) {
238 sdata->default_key = key;
240 if (local->ops->set_key_idx &&
241 local->ops->set_key_idx(local_to_hw(local), idx))
242 printk(KERN_DEBUG "%s: failed to set TX key idx for "
243 "low-level driver\n", dev->name);
252 ieee80211_key_free(key);
259 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
260 struct iw_request_info *info,
261 struct iw_point *data, char *extra)
263 struct ieee80211_sub_if_data *sdata;
264 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
266 if (local->user_space_mlme)
269 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
270 if (sdata->type == IEEE80211_IF_TYPE_STA ||
271 sdata->type == IEEE80211_IF_TYPE_IBSS) {
272 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
275 sdata->u.sta.auto_bssid_sel = 0;
276 ieee80211_sta_req_auth(dev, &sdata->u.sta);
280 if (sdata->type == IEEE80211_IF_TYPE_AP) {
281 kfree(sdata->u.ap.generic_elem);
282 sdata->u.ap.generic_elem = kmalloc(data->length, GFP_KERNEL);
283 if (!sdata->u.ap.generic_elem)
285 memcpy(sdata->u.ap.generic_elem, extra, data->length);
286 sdata->u.ap.generic_elem_len = data->length;
287 return ieee80211_if_config(dev);
292 static int ieee80211_ioctl_set_radio_enabled(struct net_device *dev,
295 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
296 struct ieee80211_conf *conf = &local->hw.conf;
298 conf->radio_enabled = val;
299 return ieee80211_hw_config(wdev_priv(dev->ieee80211_ptr));
302 static int ieee80211_ioctl_giwname(struct net_device *dev,
303 struct iw_request_info *info,
304 char *name, char *extra)
306 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
308 switch (local->hw.conf.phymode) {
309 case MODE_IEEE80211A:
310 strcpy(name, "IEEE 802.11a");
312 case MODE_IEEE80211B:
313 strcpy(name, "IEEE 802.11b");
315 case MODE_IEEE80211G:
316 strcpy(name, "IEEE 802.11g");
318 case MODE_ATHEROS_TURBO:
319 strcpy(name, "5GHz Turbo");
322 strcpy(name, "IEEE 802.11");
330 static int ieee80211_ioctl_giwrange(struct net_device *dev,
331 struct iw_request_info *info,
332 struct iw_point *data, char *extra)
334 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
335 struct iw_range *range = (struct iw_range *) extra;
337 data->length = sizeof(struct iw_range);
338 memset(range, 0, sizeof(struct iw_range));
340 range->we_version_compiled = WIRELESS_EXT;
341 range->we_version_source = 21;
342 range->retry_capa = IW_RETRY_LIMIT;
343 range->retry_flags = IW_RETRY_LIMIT;
344 range->min_retry = 0;
345 range->max_retry = 255;
347 range->max_rts = 2347;
348 range->min_frag = 256;
349 range->max_frag = 2346;
351 range->encoding_size[0] = 5;
352 range->encoding_size[1] = 13;
353 range->num_encoding_sizes = 2;
354 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
356 range->max_qual.qual = local->hw.max_signal;
357 range->max_qual.level = local->hw.max_rssi;
358 range->max_qual.noise = local->hw.max_noise;
359 range->max_qual.updated = local->wstats_flags;
361 range->avg_qual.qual = local->hw.max_signal/2;
362 range->avg_qual.level = 0;
363 range->avg_qual.noise = 0;
364 range->avg_qual.updated = local->wstats_flags;
366 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
367 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
369 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
370 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
371 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
372 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
378 struct ieee80211_channel_range {
381 unsigned char power_level;
382 unsigned char antenna_max;
385 static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
386 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
387 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
388 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
389 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
393 static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
394 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
395 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
396 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
401 static const struct ieee80211_channel_range *channel_range =
402 ieee80211_fcc_channels;
405 static void ieee80211_unmask_channel(struct net_device *dev, int mode,
406 struct ieee80211_channel *chan)
412 if (ieee80211_regdom == 64 &&
413 (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
414 /* Do not allow Turbo modes in Japan. */
418 for (i = 0; channel_range[i].start_freq; i++) {
419 const struct ieee80211_channel_range *r = &channel_range[i];
420 if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
421 if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
422 chan->freq >= 5260 && chan->freq <= 5320) {
424 * Skip new channels in Japan since the
425 * firmware was not marked having been upgraded
431 if (ieee80211_regdom == 0x10 &&
432 (chan->freq == 5190 || chan->freq == 5210 ||
433 chan->freq == 5230)) {
434 /* Skip MKK channels when in FCC domain. */
438 chan->flag |= IEEE80211_CHAN_W_SCAN |
439 IEEE80211_CHAN_W_ACTIVE_SCAN |
440 IEEE80211_CHAN_W_IBSS;
441 chan->power_level = r->power_level;
442 chan->antenna_max = r->antenna_max;
444 if (ieee80211_regdom == 64 &&
445 (chan->freq == 5170 || chan->freq == 5190 ||
446 chan->freq == 5210 || chan->freq == 5230)) {
448 * New regulatory rules in Japan have backwards
449 * compatibility with old channels in 5.15-5.25
450 * GHz band, but the station is not allowed to
451 * use active scan on these old channels.
453 chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
456 if (ieee80211_regdom == 64 &&
457 (chan->freq == 5260 || chan->freq == 5280 ||
458 chan->freq == 5300 || chan->freq == 5320)) {
460 * IBSS is not allowed on 5.25-5.35 GHz band
461 * due to radar detection requirements.
463 chan->flag &= ~IEEE80211_CHAN_W_IBSS;
472 static int ieee80211_unmask_channels(struct net_device *dev)
474 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
475 struct ieee80211_hw_mode *mode;
478 list_for_each_entry(mode, &local->modes_list, list) {
479 for (c = 0; c < mode->num_channels; c++) {
480 ieee80211_unmask_channel(dev, mode->mode,
488 int ieee80211_init_client(struct net_device *dev)
490 if (ieee80211_regdom == 0x40)
491 channel_range = ieee80211_mkk_channels;
492 ieee80211_unmask_channels(dev);
497 static int ieee80211_ioctl_siwmode(struct net_device *dev,
498 struct iw_request_info *info,
499 __u32 *mode, char *extra)
501 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
504 if (sdata->type == IEEE80211_IF_TYPE_VLAN)
509 type = IEEE80211_IF_TYPE_STA;
512 type = IEEE80211_IF_TYPE_IBSS;
514 case IW_MODE_MONITOR:
515 type = IEEE80211_IF_TYPE_MNTR;
521 if (type == sdata->type)
523 if (netif_running(dev))
526 ieee80211_if_reinit(dev);
527 ieee80211_if_set_type(dev, type);
533 static int ieee80211_ioctl_giwmode(struct net_device *dev,
534 struct iw_request_info *info,
535 __u32 *mode, char *extra)
537 struct ieee80211_sub_if_data *sdata;
539 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
540 switch (sdata->type) {
541 case IEEE80211_IF_TYPE_AP:
542 *mode = IW_MODE_MASTER;
544 case IEEE80211_IF_TYPE_STA:
545 *mode = IW_MODE_INFRA;
547 case IEEE80211_IF_TYPE_IBSS:
548 *mode = IW_MODE_ADHOC;
550 case IEEE80211_IF_TYPE_MNTR:
551 *mode = IW_MODE_MONITOR;
553 case IEEE80211_IF_TYPE_WDS:
554 *mode = IW_MODE_REPEAT;
556 case IEEE80211_IF_TYPE_VLAN:
557 *mode = IW_MODE_SECOND; /* FIXME */
560 *mode = IW_MODE_AUTO;
566 int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq)
568 struct ieee80211_hw_mode *mode;
572 list_for_each_entry(mode, &local->modes_list, list) {
573 if (!(local->enabled_modes & (1 << mode->mode)))
575 for (c = 0; c < mode->num_channels; c++) {
576 struct ieee80211_channel *chan = &mode->channels[c];
577 if (chan->flag & IEEE80211_CHAN_W_SCAN &&
578 ((chan->chan == channel) || (chan->freq == freq))) {
579 /* Use next_mode as the mode preference to
580 * resolve non-unique channel numbers. */
581 if (set && mode->mode != local->next_mode)
584 local->oper_channel = chan;
585 local->oper_hw_mode = mode;
592 if (local->sta_scanning)
595 ret = ieee80211_hw_config(local);
597 rate_control_clear(local);
603 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
604 struct iw_request_info *info,
605 struct iw_freq *freq, char *extra)
607 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
608 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
610 if (sdata->type == IEEE80211_IF_TYPE_STA)
611 sdata->u.sta.auto_channel_sel = 0;
613 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
616 if (sdata->type == IEEE80211_IF_TYPE_STA)
617 sdata->u.sta.auto_channel_sel = 1;
620 return ieee80211_set_channel(local, freq->m, -1);
622 int i, div = 1000000;
623 for (i = 0; i < freq->e; i++)
626 return ieee80211_set_channel(local, -1, freq->m / div);
633 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
634 struct iw_request_info *info,
635 struct iw_freq *freq, char *extra)
637 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
639 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
640 * driver for the current channel with firmware-based management */
642 freq->m = local->hw.conf.freq;
649 static int ieee80211_ioctl_siwessid(struct net_device *dev,
650 struct iw_request_info *info,
651 struct iw_point *data, char *ssid)
653 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
654 struct ieee80211_sub_if_data *sdata;
655 size_t len = data->length;
657 /* iwconfig uses nul termination in SSID.. */
658 if (len > 0 && ssid[len - 1] == '\0')
661 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
662 if (sdata->type == IEEE80211_IF_TYPE_STA ||
663 sdata->type == IEEE80211_IF_TYPE_IBSS) {
665 if (local->user_space_mlme) {
666 if (len > IEEE80211_MAX_SSID_LEN)
668 memcpy(sdata->u.sta.ssid, ssid, len);
669 sdata->u.sta.ssid_len = len;
672 sdata->u.sta.auto_ssid_sel = !data->flags;
673 ret = ieee80211_sta_set_ssid(dev, ssid, len);
676 ieee80211_sta_req_auth(dev, &sdata->u.sta);
680 if (sdata->type == IEEE80211_IF_TYPE_AP) {
681 memcpy(sdata->u.ap.ssid, ssid, len);
682 memset(sdata->u.ap.ssid + len, 0,
683 IEEE80211_MAX_SSID_LEN - len);
684 sdata->u.ap.ssid_len = len;
685 return ieee80211_if_config(dev);
691 static int ieee80211_ioctl_giwessid(struct net_device *dev,
692 struct iw_request_info *info,
693 struct iw_point *data, char *ssid)
697 struct ieee80211_sub_if_data *sdata;
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 res = ieee80211_sta_get_ssid(dev, ssid, &len);
710 if (sdata->type == IEEE80211_IF_TYPE_AP) {
711 len = sdata->u.ap.ssid_len;
712 if (len > IW_ESSID_MAX_SIZE)
713 len = IW_ESSID_MAX_SIZE;
714 memcpy(ssid, sdata->u.ap.ssid, len);
723 static int ieee80211_ioctl_siwap(struct net_device *dev,
724 struct iw_request_info *info,
725 struct sockaddr *ap_addr, char *extra)
727 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
728 struct ieee80211_sub_if_data *sdata;
730 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
731 if (sdata->type == IEEE80211_IF_TYPE_STA ||
732 sdata->type == IEEE80211_IF_TYPE_IBSS) {
734 if (local->user_space_mlme) {
735 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
739 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) {
740 sdata->u.sta.auto_bssid_sel = 1;
741 sdata->u.sta.auto_channel_sel = 1;
742 } else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
743 sdata->u.sta.auto_bssid_sel = 1;
745 sdata->u.sta.auto_bssid_sel = 0;
746 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
749 ieee80211_sta_req_auth(dev, &sdata->u.sta);
751 } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
752 if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
755 return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data);
762 static int ieee80211_ioctl_giwap(struct net_device *dev,
763 struct iw_request_info *info,
764 struct sockaddr *ap_addr, char *extra)
766 struct ieee80211_sub_if_data *sdata;
768 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
769 if (sdata->type == IEEE80211_IF_TYPE_STA ||
770 sdata->type == IEEE80211_IF_TYPE_IBSS) {
771 ap_addr->sa_family = ARPHRD_ETHER;
772 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
774 } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
775 ap_addr->sa_family = ARPHRD_ETHER;
776 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
784 static int ieee80211_ioctl_siwscan(struct net_device *dev,
785 struct iw_request_info *info,
786 struct iw_point *data, char *extra)
788 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
789 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
793 if (!netif_running(dev))
796 if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
797 if (sdata->type == IEEE80211_IF_TYPE_STA ||
798 sdata->type == IEEE80211_IF_TYPE_IBSS) {
799 ssid = sdata->u.sta.ssid;
800 ssid_len = sdata->u.sta.ssid_len;
801 } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
802 ssid = sdata->u.ap.ssid;
803 ssid_len = sdata->u.ap.ssid_len;
807 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
811 static int ieee80211_ioctl_giwscan(struct net_device *dev,
812 struct iw_request_info *info,
813 struct iw_point *data, char *extra)
816 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
817 if (local->sta_scanning)
819 res = ieee80211_sta_scan_results(dev, extra, data->length);
829 static int ieee80211_ioctl_siwrts(struct net_device *dev,
830 struct iw_request_info *info,
831 struct iw_param *rts, char *extra)
833 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
836 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
837 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
840 local->rts_threshold = rts->value;
842 /* If the wlan card performs RTS/CTS in hardware/firmware,
843 * configure it here */
845 if (local->ops->set_rts_threshold)
846 local->ops->set_rts_threshold(local_to_hw(local),
847 local->rts_threshold);
852 static int ieee80211_ioctl_giwrts(struct net_device *dev,
853 struct iw_request_info *info,
854 struct iw_param *rts, char *extra)
856 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
858 rts->value = local->rts_threshold;
859 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
866 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
867 struct iw_request_info *info,
868 struct iw_param *frag, char *extra)
870 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
873 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
874 else if (frag->value < 256 ||
875 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
878 /* Fragment length must be even, so strip LSB. */
879 local->fragmentation_threshold = frag->value & ~0x1;
882 /* If the wlan card performs fragmentation in hardware/firmware,
883 * configure it here */
885 if (local->ops->set_frag_threshold)
886 local->ops->set_frag_threshold(
888 local->fragmentation_threshold);
893 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
894 struct iw_request_info *info,
895 struct iw_param *frag, char *extra)
897 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
899 frag->value = local->fragmentation_threshold;
900 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
907 static int ieee80211_ioctl_siwretry(struct net_device *dev,
908 struct iw_request_info *info,
909 struct iw_param *retry, char *extra)
911 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
913 if (retry->disabled ||
914 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
917 if (retry->flags & IW_RETRY_MAX)
918 local->long_retry_limit = retry->value;
919 else if (retry->flags & IW_RETRY_MIN)
920 local->short_retry_limit = retry->value;
922 local->long_retry_limit = retry->value;
923 local->short_retry_limit = retry->value;
926 if (local->ops->set_retry_limit) {
927 return local->ops->set_retry_limit(
929 local->short_retry_limit,
930 local->long_retry_limit);
937 static int ieee80211_ioctl_giwretry(struct net_device *dev,
938 struct iw_request_info *info,
939 struct iw_param *retry, char *extra)
941 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
944 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
945 /* first return min value, iwconfig will ask max value
947 retry->flags |= IW_RETRY_LIMIT;
948 retry->value = local->short_retry_limit;
949 if (local->long_retry_limit != local->short_retry_limit)
950 retry->flags |= IW_RETRY_MIN;
953 if (retry->flags & IW_RETRY_MAX) {
954 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
955 retry->value = local->long_retry_limit;
961 static int ieee80211_ioctl_clear_keys(struct net_device *dev)
963 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
964 struct ieee80211_key_conf key;
967 struct ieee80211_key_conf *keyconf;
968 struct ieee80211_sub_if_data *sdata;
969 struct sta_info *sta;
971 memset(addr, 0xff, ETH_ALEN);
972 read_lock(&local->sub_if_lock);
973 list_for_each_entry(sdata, &local->sub_if_list, list) {
974 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
976 if (sdata->keys[i] &&
977 !sdata->keys[i]->force_sw_encrypt &&
978 local->ops->set_key &&
979 (keyconf = ieee80211_key_data2conf(local,
981 local->ops->set_key(local_to_hw(local),
985 ieee80211_key_free(sdata->keys[i]);
986 sdata->keys[i] = NULL;
988 sdata->default_key = NULL;
990 read_unlock(&local->sub_if_lock);
992 spin_lock_bh(&local->sta_lock);
993 list_for_each_entry(sta, &local->sta_list, list) {
995 if (sta->key && !sta->key->force_sw_encrypt &&
996 local->ops->set_key &&
997 (keyconf = ieee80211_key_data2conf(local, sta->key)))
998 local->ops->set_key(local_to_hw(local), DISABLE_KEY,
999 sta->addr, keyconf, sta->aid);
1001 ieee80211_key_free(sta->key);
1004 spin_unlock_bh(&local->sta_lock);
1006 memset(&key, 0, sizeof(key));
1007 if (local->ops->set_key &&
1008 local->ops->set_key(local_to_hw(local), REMOVE_ALL_KEYS,
1010 printk(KERN_DEBUG "%s: failed to remove hwaccel keys\n",
1018 ieee80211_ioctl_force_unicast_rate(struct net_device *dev,
1019 struct ieee80211_sub_if_data *sdata,
1022 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1023 struct ieee80211_hw_mode *mode;
1026 if (sdata->type != IEEE80211_IF_TYPE_AP)
1030 sdata->u.ap.force_unicast_rateidx = -1;
1034 mode = local->oper_hw_mode;
1035 for (i = 0; i < mode->num_rates; i++) {
1036 if (mode->rates[i].rate == rate) {
1037 sdata->u.ap.force_unicast_rateidx = i;
1046 ieee80211_ioctl_max_ratectrl_rate(struct net_device *dev,
1047 struct ieee80211_sub_if_data *sdata,
1050 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1051 struct ieee80211_hw_mode *mode;
1054 if (sdata->type != IEEE80211_IF_TYPE_AP)
1058 sdata->u.ap.max_ratectrl_rateidx = -1;
1062 mode = local->oper_hw_mode;
1063 for (i = 0; i < mode->num_rates; i++) {
1064 if (mode->rates[i].rate == rate) {
1065 sdata->u.ap.max_ratectrl_rateidx = i;
1073 static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
1074 struct ieee80211_key *key)
1076 struct ieee80211_key_conf *keyconf;
1079 if (!key || key->alg != ALG_WEP || !key->force_sw_encrypt ||
1080 (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP))
1083 memset(addr, 0xff, ETH_ALEN);
1084 keyconf = ieee80211_key_data2conf(local, key);
1085 if (keyconf && local->ops->set_key &&
1086 local->ops->set_key(local_to_hw(local),
1087 SET_KEY, addr, keyconf, 0) == 0) {
1088 key->force_sw_encrypt =
1089 !!(keyconf->flags & IEEE80211_KEY_FORCE_SW_ENCRYPT);
1090 key->hw_key_idx = keyconf->hw_key_idx;
1096 static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
1097 struct ieee80211_key *key)
1099 struct ieee80211_key_conf *keyconf;
1102 if (!key || key->alg != ALG_WEP || key->force_sw_encrypt ||
1103 (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP))
1106 memset(addr, 0xff, ETH_ALEN);
1107 keyconf = ieee80211_key_data2conf(local, key);
1108 if (keyconf && local->ops->set_key)
1109 local->ops->set_key(local_to_hw(local), DISABLE_KEY,
1112 key->force_sw_encrypt = 1;
1116 static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
1120 struct ieee80211_sub_if_data *sdata;
1122 local->default_wep_only = value;
1123 read_lock(&local->sub_if_lock);
1124 list_for_each_entry(sdata, &local->sub_if_list, list)
1125 for (i = 0; i < NUM_DEFAULT_KEYS; i++)
1127 ieee80211_key_enable_hwaccel(local,
1130 ieee80211_key_disable_hwaccel(local,
1132 read_unlock(&local->sub_if_lock);
1138 void ieee80211_update_default_wep_only(struct ieee80211_local *local)
1141 struct ieee80211_sub_if_data *sdata;
1143 read_lock(&local->sub_if_lock);
1144 list_for_each_entry(sdata, &local->sub_if_list, list) {
1146 if (sdata->dev == local->mdev)
1149 /* If there is an AP interface then depend on userspace to
1150 set default_wep_only correctly. */
1151 if (sdata->type == IEEE80211_IF_TYPE_AP) {
1152 read_unlock(&local->sub_if_lock);
1159 read_unlock(&local->sub_if_lock);
1162 ieee80211_ioctl_default_wep_only(local, 1);
1164 ieee80211_ioctl_default_wep_only(local, 0);
1168 static int ieee80211_ioctl_prism2_param(struct net_device *dev,
1169 struct iw_request_info *info,
1170 void *wrqu, char *extra)
1172 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1173 struct ieee80211_sub_if_data *sdata;
1174 int *i = (int *) extra;
1176 int value = *(i + 1);
1179 if (!capable(CAP_NET_ADMIN))
1182 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1185 case PRISM2_PARAM_IEEE_802_1X:
1186 if (local->ops->set_ieee8021x)
1187 ret = local->ops->set_ieee8021x(local_to_hw(local),
1190 printk(KERN_DEBUG "%s: failed to set IEEE 802.1X (%d) "
1191 "for low-level driver\n", dev->name, value);
1193 sdata->ieee802_1x = value;
1196 case PRISM2_PARAM_ANTSEL_TX:
1197 local->hw.conf.antenna_sel_tx = value;
1198 if (ieee80211_hw_config(local))
1202 case PRISM2_PARAM_ANTSEL_RX:
1203 local->hw.conf.antenna_sel_rx = value;
1204 if (ieee80211_hw_config(local))
1208 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
1209 local->cts_protect_erp_frames = value;
1212 case PRISM2_PARAM_DROP_UNENCRYPTED:
1213 sdata->drop_unencrypted = value;
1216 case PRISM2_PARAM_PREAMBLE:
1217 local->short_preamble = value;
1220 case PRISM2_PARAM_STAT_TIME:
1221 if (!local->stat_time && value) {
1222 local->stat_timer.expires = jiffies + HZ * value / 100;
1223 add_timer(&local->stat_timer);
1224 } else if (local->stat_time && !value) {
1225 del_timer_sync(&local->stat_timer);
1227 local->stat_time = value;
1229 case PRISM2_PARAM_SHORT_SLOT_TIME:
1231 local->hw.conf.flags |= IEEE80211_CONF_SHORT_SLOT_TIME;
1233 local->hw.conf.flags &= ~IEEE80211_CONF_SHORT_SLOT_TIME;
1234 if (ieee80211_hw_config(local))
1238 case PRISM2_PARAM_NEXT_MODE:
1239 local->next_mode = value;
1242 case PRISM2_PARAM_CLEAR_KEYS:
1243 ret = ieee80211_ioctl_clear_keys(dev);
1246 case PRISM2_PARAM_RADIO_ENABLED:
1247 ret = ieee80211_ioctl_set_radio_enabled(dev, value);
1250 case PRISM2_PARAM_ANTENNA_MODE:
1251 local->hw.conf.antenna_mode = value;
1252 if (ieee80211_hw_config(local))
1256 case PRISM2_PARAM_STA_ANTENNA_SEL:
1257 local->sta_antenna_sel = value;
1260 case PRISM2_PARAM_FORCE_UNICAST_RATE:
1261 ret = ieee80211_ioctl_force_unicast_rate(dev, sdata, value);
1264 case PRISM2_PARAM_MAX_RATECTRL_RATE:
1265 ret = ieee80211_ioctl_max_ratectrl_rate(dev, sdata, value);
1268 case PRISM2_PARAM_RATE_CTRL_NUM_UP:
1269 local->rate_ctrl_num_up = value;
1272 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
1273 local->rate_ctrl_num_down = value;
1276 case PRISM2_PARAM_TX_POWER_REDUCTION:
1280 local->hw.conf.tx_power_reduction = value;
1283 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
1284 local->key_tx_rx_threshold = value;
1287 case PRISM2_PARAM_DEFAULT_WEP_ONLY:
1288 ret = ieee80211_ioctl_default_wep_only(local, value);
1291 case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
1292 local->wifi_wme_noack_test = value;
1295 case PRISM2_PARAM_SCAN_FLAGS:
1296 local->scan_flags = value;
1299 case PRISM2_PARAM_MIXED_CELL:
1300 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1301 sdata->type != IEEE80211_IF_TYPE_IBSS)
1304 sdata->u.sta.mixed_cell = !!value;
1307 case PRISM2_PARAM_HW_MODES:
1308 local->enabled_modes = value;
1311 case PRISM2_PARAM_CREATE_IBSS:
1312 if (sdata->type != IEEE80211_IF_TYPE_IBSS)
1315 sdata->u.sta.create_ibss = !!value;
1317 case PRISM2_PARAM_WMM_ENABLED:
1318 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1319 sdata->type != IEEE80211_IF_TYPE_IBSS)
1322 sdata->u.sta.wmm_enabled = !!value;
1324 case PRISM2_PARAM_RADAR_DETECT:
1325 local->hw.conf.radar_detect = value;
1327 case PRISM2_PARAM_SPECTRUM_MGMT:
1328 local->hw.conf.spect_mgmt = value;
1339 static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
1340 struct iw_request_info *info,
1341 void *wrqu, char *extra)
1343 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1344 struct ieee80211_sub_if_data *sdata;
1345 int *param = (int *) extra;
1348 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1351 case PRISM2_PARAM_IEEE_802_1X:
1352 *param = sdata->ieee802_1x;
1355 case PRISM2_PARAM_ANTSEL_TX:
1356 *param = local->hw.conf.antenna_sel_tx;
1359 case PRISM2_PARAM_ANTSEL_RX:
1360 *param = local->hw.conf.antenna_sel_rx;
1363 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
1364 *param = local->cts_protect_erp_frames;
1367 case PRISM2_PARAM_DROP_UNENCRYPTED:
1368 *param = sdata->drop_unencrypted;
1371 case PRISM2_PARAM_PREAMBLE:
1372 *param = local->short_preamble;
1375 case PRISM2_PARAM_STAT_TIME:
1376 *param = local->stat_time;
1378 case PRISM2_PARAM_SHORT_SLOT_TIME:
1379 *param = !!(local->hw.conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME);
1382 case PRISM2_PARAM_NEXT_MODE:
1383 *param = local->next_mode;
1386 case PRISM2_PARAM_ANTENNA_MODE:
1387 *param = local->hw.conf.antenna_mode;
1390 case PRISM2_PARAM_STA_ANTENNA_SEL:
1391 *param = local->sta_antenna_sel;
1394 case PRISM2_PARAM_RATE_CTRL_NUM_UP:
1395 *param = local->rate_ctrl_num_up;
1398 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
1399 *param = local->rate_ctrl_num_down;
1402 case PRISM2_PARAM_TX_POWER_REDUCTION:
1403 *param = local->hw.conf.tx_power_reduction;
1406 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
1407 *param = local->key_tx_rx_threshold;
1410 case PRISM2_PARAM_DEFAULT_WEP_ONLY:
1411 *param = local->default_wep_only;
1414 case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
1415 *param = local->wifi_wme_noack_test;
1418 case PRISM2_PARAM_SCAN_FLAGS:
1419 *param = local->scan_flags;
1422 case PRISM2_PARAM_HW_MODES:
1423 *param = local->enabled_modes;
1426 case PRISM2_PARAM_CREATE_IBSS:
1427 if (sdata->type != IEEE80211_IF_TYPE_IBSS)
1430 *param = !!sdata->u.sta.create_ibss;
1433 case PRISM2_PARAM_MIXED_CELL:
1434 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1435 sdata->type != IEEE80211_IF_TYPE_IBSS)
1438 *param = !!sdata->u.sta.mixed_cell;
1440 case PRISM2_PARAM_WMM_ENABLED:
1441 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1442 sdata->type != IEEE80211_IF_TYPE_IBSS)
1445 *param = !!sdata->u.sta.wmm_enabled;
1455 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
1456 struct iw_request_info *info,
1457 struct iw_point *data, char *extra)
1459 struct ieee80211_sub_if_data *sdata;
1460 struct iw_mlme *mlme = (struct iw_mlme *) extra;
1462 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1463 if (sdata->type != IEEE80211_IF_TYPE_STA &&
1464 sdata->type != IEEE80211_IF_TYPE_IBSS)
1467 switch (mlme->cmd) {
1468 case IW_MLME_DEAUTH:
1469 /* TODO: mlme->addr.sa_data */
1470 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
1471 case IW_MLME_DISASSOC:
1472 /* TODO: mlme->addr.sa_data */
1473 return ieee80211_sta_disassociate(dev, mlme->reason_code);
1480 static int ieee80211_ioctl_siwencode(struct net_device *dev,
1481 struct iw_request_info *info,
1482 struct iw_point *erq, char *keybuf)
1484 struct ieee80211_sub_if_data *sdata;
1485 int idx, i, alg = ALG_WEP;
1486 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1488 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1490 idx = erq->flags & IW_ENCODE_INDEX;
1492 if (sdata->default_key)
1493 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1494 if (sdata->default_key == sdata->keys[i]) {
1499 } else if (idx < 1 || idx > 4)
1504 if (erq->flags & IW_ENCODE_DISABLED)
1506 else if (erq->length == 0) {
1507 /* No key data - just set the default TX key index */
1508 if (sdata->default_key != sdata->keys[idx])
1509 sdata->default_key = sdata->keys[idx];
1513 return ieee80211_set_encryption(
1516 !sdata->default_key,
1517 keybuf, erq->length);
1521 static int ieee80211_ioctl_giwencode(struct net_device *dev,
1522 struct iw_request_info *info,
1523 struct iw_point *erq, char *key)
1525 struct ieee80211_sub_if_data *sdata;
1528 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1530 idx = erq->flags & IW_ENCODE_INDEX;
1531 if (idx < 1 || idx > 4) {
1533 if (!sdata->default_key)
1535 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1536 if (sdata->default_key == sdata->keys[i]) {
1546 erq->flags = idx + 1;
1548 if (!sdata->keys[idx]) {
1550 erq->flags |= IW_ENCODE_DISABLED;
1554 memcpy(key, sdata->keys[idx]->key,
1555 min((int)erq->length, sdata->keys[idx]->keylen));
1556 erq->length = sdata->keys[idx]->keylen;
1557 erq->flags |= IW_ENCODE_ENABLED;
1562 static int ieee80211_ioctl_siwauth(struct net_device *dev,
1563 struct iw_request_info *info,
1564 struct iw_param *data, char *extra)
1566 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1567 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1570 switch (data->flags & IW_AUTH_INDEX) {
1571 case IW_AUTH_WPA_VERSION:
1572 case IW_AUTH_CIPHER_PAIRWISE:
1573 case IW_AUTH_CIPHER_GROUP:
1574 case IW_AUTH_WPA_ENABLED:
1575 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1577 case IW_AUTH_KEY_MGMT:
1578 if (sdata->type != IEEE80211_IF_TYPE_STA)
1582 * TODO: sdata->u.sta.key_mgmt does not match with WE18
1583 * value completely; could consider modifying this to
1584 * be closer to WE18. For now, this value is not really
1585 * used for anything else than Privacy matching, so the
1586 * current code here should be more or less OK.
1588 if (data->value & IW_AUTH_KEY_MGMT_802_1X) {
1589 sdata->u.sta.key_mgmt =
1590 IEEE80211_KEY_MGMT_WPA_EAP;
1591 } else if (data->value & IW_AUTH_KEY_MGMT_PSK) {
1592 sdata->u.sta.key_mgmt =
1593 IEEE80211_KEY_MGMT_WPA_PSK;
1595 sdata->u.sta.key_mgmt =
1596 IEEE80211_KEY_MGMT_NONE;
1600 case IW_AUTH_80211_AUTH_ALG:
1601 if (sdata->type == IEEE80211_IF_TYPE_STA ||
1602 sdata->type == IEEE80211_IF_TYPE_IBSS)
1603 sdata->u.sta.auth_algs = data->value;
1607 case IW_AUTH_PRIVACY_INVOKED:
1608 if (local->ops->set_privacy_invoked)
1609 ret = local->ops->set_privacy_invoked(
1610 local_to_hw(local), data->value);
1619 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1620 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1622 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1623 struct iw_statistics *wstats = &local->wstats;
1624 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1625 struct sta_info *sta = NULL;
1627 if (sdata->type == IEEE80211_IF_TYPE_STA ||
1628 sdata->type == IEEE80211_IF_TYPE_IBSS)
1629 sta = sta_info_get(local, sdata->u.sta.bssid);
1631 wstats->discard.fragment = 0;
1632 wstats->discard.misc = 0;
1633 wstats->qual.qual = 0;
1634 wstats->qual.level = 0;
1635 wstats->qual.noise = 0;
1636 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1638 wstats->qual.level = sta->last_rssi;
1639 wstats->qual.qual = sta->last_signal;
1640 wstats->qual.noise = sta->last_noise;
1641 wstats->qual.updated = local->wstats_flags;
1647 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1648 struct iw_request_info *info,
1649 struct iw_param *data, char *extra)
1651 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1654 switch (data->flags & IW_AUTH_INDEX) {
1655 case IW_AUTH_80211_AUTH_ALG:
1656 if (sdata->type == IEEE80211_IF_TYPE_STA ||
1657 sdata->type == IEEE80211_IF_TYPE_IBSS)
1658 data->value = sdata->u.sta.auth_algs;
1670 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1671 struct iw_request_info *info,
1672 struct iw_point *erq, char *extra)
1674 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1675 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1679 case IW_ENCODE_ALG_NONE:
1682 case IW_ENCODE_ALG_WEP:
1685 case IW_ENCODE_ALG_TKIP:
1688 case IW_ENCODE_ALG_CCMP:
1695 if (erq->flags & IW_ENCODE_DISABLED)
1698 idx = erq->flags & IW_ENCODE_INDEX;
1699 if (idx < 1 || idx > 4) {
1701 if (!sdata->default_key)
1703 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1704 if (sdata->default_key == sdata->keys[i]) {
1714 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
1716 IW_ENCODE_EXT_SET_TX_KEY,
1717 ext->key, ext->key_len);
1721 static const struct iw_priv_args ieee80211_ioctl_priv[] = {
1722 { PRISM2_IOCTL_PRISM2_PARAM,
1723 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "param" },
1724 { PRISM2_IOCTL_GET_PRISM2_PARAM,
1725 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1726 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param" },
1729 /* Structures to export the Wireless Handlers */
1731 static const iw_handler ieee80211_handler[] =
1733 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1734 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1735 (iw_handler) NULL, /* SIOCSIWNWID */
1736 (iw_handler) NULL, /* SIOCGIWNWID */
1737 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1738 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1739 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1740 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1741 (iw_handler) NULL, /* SIOCSIWSENS */
1742 (iw_handler) NULL, /* SIOCGIWSENS */
1743 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1744 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1745 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1746 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1747 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1748 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1749 iw_handler_set_spy, /* SIOCSIWSPY */
1750 iw_handler_get_spy, /* SIOCGIWSPY */
1751 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
1752 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
1753 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1754 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1755 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1756 (iw_handler) NULL, /* SIOCGIWAPLIST */
1757 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1758 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1759 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1760 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1761 (iw_handler) NULL, /* SIOCSIWNICKN */
1762 (iw_handler) NULL, /* SIOCGIWNICKN */
1763 (iw_handler) NULL, /* -- hole -- */
1764 (iw_handler) NULL, /* -- hole -- */
1765 (iw_handler) NULL, /* SIOCSIWRATE */
1766 (iw_handler) NULL, /* SIOCGIWRATE */
1767 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1768 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1769 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1770 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1771 (iw_handler) NULL, /* SIOCSIWTXPOW */
1772 (iw_handler) NULL, /* SIOCGIWTXPOW */
1773 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1774 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1775 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1776 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1777 (iw_handler) NULL, /* SIOCSIWPOWER */
1778 (iw_handler) NULL, /* SIOCGIWPOWER */
1779 (iw_handler) NULL, /* -- hole -- */
1780 (iw_handler) NULL, /* -- hole -- */
1781 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1782 (iw_handler) NULL, /* SIOCGIWGENIE */
1783 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1784 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1785 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1786 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1787 (iw_handler) NULL, /* SIOCSIWPMKSA */
1788 (iw_handler) NULL, /* -- hole -- */
1791 static const iw_handler ieee80211_private_handler[] =
1792 { /* SIOCIWFIRSTPRIV + */
1793 (iw_handler) ieee80211_ioctl_prism2_param, /* 0 */
1794 (iw_handler) ieee80211_ioctl_get_prism2_param, /* 1 */
1797 const struct iw_handler_def ieee80211_iw_handler_def =
1799 .num_standard = ARRAY_SIZE(ieee80211_handler),
1800 .num_private = ARRAY_SIZE(ieee80211_private_handler),
1801 .num_private_args = ARRAY_SIZE(ieee80211_ioctl_priv),
1802 .standard = (iw_handler *) ieee80211_handler,
1803 .private = (iw_handler *) ieee80211_private_handler,
1804 .private_args = (struct iw_priv_args *) ieee80211_ioctl_priv,
1805 .get_wireless_stats = ieee80211_get_wireless_stats,