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 "ieee80211_rate.h"
29 static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
30 int idx, int alg, int set_tx_key,
31 const u8 *_key, size_t key_len)
33 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
36 struct ieee80211_key *key;
37 struct ieee80211_sub_if_data *sdata;
39 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
41 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
42 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
47 if (is_broadcast_ether_addr(sta_addr)) {
49 key = sdata->keys[idx];
53 * According to the standard, the key index of a pairwise
54 * key must be zero. However, some AP are broken when it
55 * comes to WEP key indices, so we work around this.
57 if (idx != 0 && alg != ALG_WEP) {
58 printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
59 "individual key\n", dev->name);
63 sta = sta_info_get(local, sta_addr);
65 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
67 printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
69 dev->name, print_mac(mac, sta_addr));
70 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
78 if (alg == ALG_NONE) {
79 ieee80211_key_free(key);
83 * Automatically frees any old key if present.
85 key = ieee80211_key_alloc(sdata, sta, alg, idx, key_len, _key);
92 if (set_tx_key || (!sta && !sdata->default_key && key))
93 ieee80211_set_default_key(sdata, idx);
102 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
103 struct iw_request_info *info,
104 struct iw_point *data, char *extra)
106 struct ieee80211_sub_if_data *sdata;
107 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
109 if (local->user_space_mlme)
112 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
113 if (sdata->type == IEEE80211_IF_TYPE_STA ||
114 sdata->type == IEEE80211_IF_TYPE_IBSS) {
115 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
118 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
119 ieee80211_sta_req_auth(dev, &sdata->u.sta);
126 static int ieee80211_ioctl_giwname(struct net_device *dev,
127 struct iw_request_info *info,
128 char *name, char *extra)
130 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
132 switch (local->hw.conf.phymode) {
133 case MODE_IEEE80211A:
134 strcpy(name, "IEEE 802.11a");
136 case MODE_IEEE80211B:
137 strcpy(name, "IEEE 802.11b");
139 case MODE_IEEE80211G:
140 strcpy(name, "IEEE 802.11g");
143 strcpy(name, "IEEE 802.11");
151 static int ieee80211_ioctl_giwrange(struct net_device *dev,
152 struct iw_request_info *info,
153 struct iw_point *data, char *extra)
155 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
156 struct iw_range *range = (struct iw_range *) extra;
157 struct ieee80211_hw_mode *mode = NULL;
160 data->length = sizeof(struct iw_range);
161 memset(range, 0, sizeof(struct iw_range));
163 range->we_version_compiled = WIRELESS_EXT;
164 range->we_version_source = 21;
165 range->retry_capa = IW_RETRY_LIMIT;
166 range->retry_flags = IW_RETRY_LIMIT;
167 range->min_retry = 0;
168 range->max_retry = 255;
170 range->max_rts = 2347;
171 range->min_frag = 256;
172 range->max_frag = 2346;
174 range->encoding_size[0] = 5;
175 range->encoding_size[1] = 13;
176 range->num_encoding_sizes = 2;
177 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
179 range->max_qual.qual = local->hw.max_signal;
180 range->max_qual.level = local->hw.max_rssi;
181 range->max_qual.noise = local->hw.max_noise;
182 range->max_qual.updated = local->wstats_flags;
184 range->avg_qual.qual = local->hw.max_signal/2;
185 range->avg_qual.level = 0;
186 range->avg_qual.noise = 0;
187 range->avg_qual.updated = local->wstats_flags;
189 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
190 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
192 list_for_each_entry(mode, &local->modes_list, list) {
195 if (!(local->enabled_modes & (1 << mode->mode)) ||
196 (local->hw_modes & local->enabled_modes &
197 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
200 while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) {
201 struct ieee80211_channel *chan = &mode->channels[i];
203 if (chan->flag & IEEE80211_CHAN_W_SCAN) {
204 range->freq[c].i = chan->chan;
205 range->freq[c].m = chan->freq * 100000;
206 range->freq[c].e = 1;
212 range->num_channels = c;
213 range->num_frequency = c;
215 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
216 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
217 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
218 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
224 static int ieee80211_ioctl_siwmode(struct net_device *dev,
225 struct iw_request_info *info,
226 __u32 *mode, char *extra)
228 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
231 if (sdata->type == IEEE80211_IF_TYPE_VLAN)
236 type = IEEE80211_IF_TYPE_STA;
239 type = IEEE80211_IF_TYPE_IBSS;
241 case IW_MODE_MONITOR:
242 type = IEEE80211_IF_TYPE_MNTR;
248 if (type == sdata->type)
250 if (netif_running(dev))
253 ieee80211_if_reinit(dev);
254 ieee80211_if_set_type(dev, type);
260 static int ieee80211_ioctl_giwmode(struct net_device *dev,
261 struct iw_request_info *info,
262 __u32 *mode, char *extra)
264 struct ieee80211_sub_if_data *sdata;
266 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
267 switch (sdata->type) {
268 case IEEE80211_IF_TYPE_AP:
269 *mode = IW_MODE_MASTER;
271 case IEEE80211_IF_TYPE_STA:
272 *mode = IW_MODE_INFRA;
274 case IEEE80211_IF_TYPE_IBSS:
275 *mode = IW_MODE_ADHOC;
277 case IEEE80211_IF_TYPE_MNTR:
278 *mode = IW_MODE_MONITOR;
280 case IEEE80211_IF_TYPE_WDS:
281 *mode = IW_MODE_REPEAT;
283 case IEEE80211_IF_TYPE_VLAN:
284 *mode = IW_MODE_SECOND; /* FIXME */
287 *mode = IW_MODE_AUTO;
293 int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq)
295 struct ieee80211_hw_mode *mode;
299 list_for_each_entry(mode, &local->modes_list, list) {
300 if (!(local->enabled_modes & (1 << mode->mode)))
302 for (c = 0; c < mode->num_channels; c++) {
303 struct ieee80211_channel *chan = &mode->channels[c];
304 if (chan->flag & IEEE80211_CHAN_W_SCAN &&
305 ((chan->chan == channel) || (chan->freq == freq))) {
306 local->oper_channel = chan;
307 local->oper_hw_mode = mode;
314 if (local->sta_scanning)
317 ret = ieee80211_hw_config(local);
319 rate_control_clear(local);
325 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
326 struct iw_request_info *info,
327 struct iw_freq *freq, char *extra)
329 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
330 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
332 if (sdata->type == IEEE80211_IF_TYPE_STA)
333 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
335 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
338 if (sdata->type == IEEE80211_IF_TYPE_STA)
339 sdata->u.sta.flags |=
340 IEEE80211_STA_AUTO_CHANNEL_SEL;
343 return ieee80211_set_channel(local, freq->m, -1);
345 int i, div = 1000000;
346 for (i = 0; i < freq->e; i++)
349 return ieee80211_set_channel(local, -1, freq->m / div);
356 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
357 struct iw_request_info *info,
358 struct iw_freq *freq, char *extra)
360 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
362 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
363 * driver for the current channel with firmware-based management */
365 freq->m = local->hw.conf.freq;
372 static int ieee80211_ioctl_siwessid(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_point *data, char *ssid)
376 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
377 struct ieee80211_sub_if_data *sdata;
378 size_t len = data->length;
380 /* iwconfig uses nul termination in SSID.. */
381 if (len > 0 && ssid[len - 1] == '\0')
384 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
385 if (sdata->type == IEEE80211_IF_TYPE_STA ||
386 sdata->type == IEEE80211_IF_TYPE_IBSS) {
388 if (local->user_space_mlme) {
389 if (len > IEEE80211_MAX_SSID_LEN)
391 memcpy(sdata->u.sta.ssid, ssid, len);
392 sdata->u.sta.ssid_len = len;
396 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
398 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
399 ret = ieee80211_sta_set_ssid(dev, ssid, len);
402 ieee80211_sta_req_auth(dev, &sdata->u.sta);
406 if (sdata->type == IEEE80211_IF_TYPE_AP) {
407 memcpy(sdata->u.ap.ssid, ssid, len);
408 memset(sdata->u.ap.ssid + len, 0,
409 IEEE80211_MAX_SSID_LEN - len);
410 sdata->u.ap.ssid_len = len;
411 return ieee80211_if_config(dev);
417 static int ieee80211_ioctl_giwessid(struct net_device *dev,
418 struct iw_request_info *info,
419 struct iw_point *data, char *ssid)
423 struct ieee80211_sub_if_data *sdata;
424 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
425 if (sdata->type == IEEE80211_IF_TYPE_STA ||
426 sdata->type == IEEE80211_IF_TYPE_IBSS) {
427 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
436 if (sdata->type == IEEE80211_IF_TYPE_AP) {
437 len = sdata->u.ap.ssid_len;
438 if (len > IW_ESSID_MAX_SIZE)
439 len = IW_ESSID_MAX_SIZE;
440 memcpy(ssid, sdata->u.ap.ssid, len);
449 static int ieee80211_ioctl_siwap(struct net_device *dev,
450 struct iw_request_info *info,
451 struct sockaddr *ap_addr, char *extra)
453 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
454 struct ieee80211_sub_if_data *sdata;
456 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
457 if (sdata->type == IEEE80211_IF_TYPE_STA ||
458 sdata->type == IEEE80211_IF_TYPE_IBSS) {
460 if (local->user_space_mlme) {
461 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
465 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
466 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
467 IEEE80211_STA_AUTO_CHANNEL_SEL;
468 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
469 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
471 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
472 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
475 ieee80211_sta_req_auth(dev, &sdata->u.sta);
477 } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
478 if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
481 return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data);
488 static int ieee80211_ioctl_giwap(struct net_device *dev,
489 struct iw_request_info *info,
490 struct sockaddr *ap_addr, char *extra)
492 struct ieee80211_sub_if_data *sdata;
494 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
495 if (sdata->type == IEEE80211_IF_TYPE_STA ||
496 sdata->type == IEEE80211_IF_TYPE_IBSS) {
497 ap_addr->sa_family = ARPHRD_ETHER;
498 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
500 } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
501 ap_addr->sa_family = ARPHRD_ETHER;
502 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
510 static int ieee80211_ioctl_siwscan(struct net_device *dev,
511 struct iw_request_info *info,
512 struct iw_point *data, char *extra)
514 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
515 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
519 if (!netif_running(dev))
522 switch (sdata->type) {
523 case IEEE80211_IF_TYPE_STA:
524 case IEEE80211_IF_TYPE_IBSS:
525 if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
526 ssid = sdata->u.sta.ssid;
527 ssid_len = sdata->u.sta.ssid_len;
530 case IEEE80211_IF_TYPE_AP:
531 if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
532 ssid = sdata->u.ap.ssid;
533 ssid_len = sdata->u.ap.ssid_len;
540 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
544 static int ieee80211_ioctl_giwscan(struct net_device *dev,
545 struct iw_request_info *info,
546 struct iw_point *data, char *extra)
549 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
550 if (local->sta_scanning)
552 res = ieee80211_sta_scan_results(dev, extra, data->length);
562 static int ieee80211_ioctl_siwrate(struct net_device *dev,
563 struct iw_request_info *info,
564 struct iw_param *rate, char *extra)
566 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
567 struct ieee80211_hw_mode *mode;
569 u32 target_rate = rate->value / 100000;
570 struct ieee80211_sub_if_data *sdata;
572 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
575 mode = local->oper_hw_mode;
576 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
577 * target_rate = X, rate->fixed = 1 means only rate X
578 * target_rate = X, rate->fixed = 0 means all rates <= X */
579 sdata->bss->max_ratectrl_rateidx = -1;
580 sdata->bss->force_unicast_rateidx = -1;
583 for (i=0; i< mode->num_rates; i++) {
584 struct ieee80211_rate *rates = &mode->rates[i];
585 int this_rate = rates->rate;
587 if (target_rate == this_rate) {
588 sdata->bss->max_ratectrl_rateidx = i;
590 sdata->bss->force_unicast_rateidx = i;
597 static int ieee80211_ioctl_giwrate(struct net_device *dev,
598 struct iw_request_info *info,
599 struct iw_param *rate, char *extra)
601 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
602 struct sta_info *sta;
603 struct ieee80211_sub_if_data *sdata;
605 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
606 if (sdata->type == IEEE80211_IF_TYPE_STA)
607 sta = sta_info_get(local, sdata->u.sta.bssid);
612 if (sta->txrate < local->oper_hw_mode->num_rates)
613 rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000;
620 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
621 struct iw_request_info *info,
622 union iwreq_data *data, char *extra)
624 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
625 bool need_reconfig = 0;
627 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
629 if (data->txpower.flags & IW_TXPOW_RANGE)
631 if (!data->txpower.fixed)
634 if (local->hw.conf.power_level != data->txpower.value) {
635 local->hw.conf.power_level = data->txpower.value;
638 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
639 local->hw.conf.radio_enabled = !(data->txpower.disabled);
643 ieee80211_hw_config(local);
644 /* The return value of hw_config is not of big interest here,
645 * as it doesn't say that it failed because of _this_ config
646 * change or something else. Ignore it. */
652 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
653 struct iw_request_info *info,
654 union iwreq_data *data, char *extra)
656 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
658 data->txpower.fixed = 1;
659 data->txpower.disabled = !(local->hw.conf.radio_enabled);
660 data->txpower.value = local->hw.conf.power_level;
661 data->txpower.flags = IW_TXPOW_DBM;
666 static int ieee80211_ioctl_siwrts(struct net_device *dev,
667 struct iw_request_info *info,
668 struct iw_param *rts, char *extra)
670 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
673 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
674 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
677 local->rts_threshold = rts->value;
679 /* If the wlan card performs RTS/CTS in hardware/firmware,
680 * configure it here */
682 if (local->ops->set_rts_threshold)
683 local->ops->set_rts_threshold(local_to_hw(local),
684 local->rts_threshold);
689 static int ieee80211_ioctl_giwrts(struct net_device *dev,
690 struct iw_request_info *info,
691 struct iw_param *rts, char *extra)
693 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
695 rts->value = local->rts_threshold;
696 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
703 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
704 struct iw_request_info *info,
705 struct iw_param *frag, char *extra)
707 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
710 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
711 else if (frag->value < 256 ||
712 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
715 /* Fragment length must be even, so strip LSB. */
716 local->fragmentation_threshold = frag->value & ~0x1;
719 /* If the wlan card performs fragmentation in hardware/firmware,
720 * configure it here */
722 if (local->ops->set_frag_threshold)
723 local->ops->set_frag_threshold(
725 local->fragmentation_threshold);
730 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
731 struct iw_request_info *info,
732 struct iw_param *frag, char *extra)
734 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
736 frag->value = local->fragmentation_threshold;
737 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
744 static int ieee80211_ioctl_siwretry(struct net_device *dev,
745 struct iw_request_info *info,
746 struct iw_param *retry, char *extra)
748 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
750 if (retry->disabled ||
751 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
754 if (retry->flags & IW_RETRY_MAX)
755 local->long_retry_limit = retry->value;
756 else if (retry->flags & IW_RETRY_MIN)
757 local->short_retry_limit = retry->value;
759 local->long_retry_limit = retry->value;
760 local->short_retry_limit = retry->value;
763 if (local->ops->set_retry_limit) {
764 return local->ops->set_retry_limit(
766 local->short_retry_limit,
767 local->long_retry_limit);
774 static int ieee80211_ioctl_giwretry(struct net_device *dev,
775 struct iw_request_info *info,
776 struct iw_param *retry, char *extra)
778 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
781 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
782 /* first return min value, iwconfig will ask max value
784 retry->flags |= IW_RETRY_LIMIT;
785 retry->value = local->short_retry_limit;
786 if (local->long_retry_limit != local->short_retry_limit)
787 retry->flags |= IW_RETRY_MIN;
790 if (retry->flags & IW_RETRY_MAX) {
791 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
792 retry->value = local->long_retry_limit;
798 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
799 struct iw_request_info *info,
800 struct iw_point *data, char *extra)
802 struct ieee80211_sub_if_data *sdata;
803 struct iw_mlme *mlme = (struct iw_mlme *) extra;
805 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
806 if (sdata->type != IEEE80211_IF_TYPE_STA &&
807 sdata->type != IEEE80211_IF_TYPE_IBSS)
812 /* TODO: mlme->addr.sa_data */
813 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
814 case IW_MLME_DISASSOC:
815 /* TODO: mlme->addr.sa_data */
816 return ieee80211_sta_disassociate(dev, mlme->reason_code);
823 static int ieee80211_ioctl_siwencode(struct net_device *dev,
824 struct iw_request_info *info,
825 struct iw_point *erq, char *keybuf)
827 struct ieee80211_sub_if_data *sdata;
828 int idx, i, alg = ALG_WEP;
829 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
831 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
833 idx = erq->flags & IW_ENCODE_INDEX;
835 if (sdata->default_key)
836 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
837 if (sdata->default_key == sdata->keys[i]) {
842 } else if (idx < 1 || idx > 4)
847 if (erq->flags & IW_ENCODE_DISABLED)
849 else if (erq->length == 0) {
850 /* No key data - just set the default TX key index */
851 ieee80211_set_default_key(sdata, idx);
855 return ieee80211_set_encryption(
859 keybuf, erq->length);
863 static int ieee80211_ioctl_giwencode(struct net_device *dev,
864 struct iw_request_info *info,
865 struct iw_point *erq, char *key)
867 struct ieee80211_sub_if_data *sdata;
870 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
872 idx = erq->flags & IW_ENCODE_INDEX;
873 if (idx < 1 || idx > 4) {
875 if (!sdata->default_key)
877 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
878 if (sdata->default_key == sdata->keys[i]) {
888 erq->flags = idx + 1;
890 if (!sdata->keys[idx]) {
892 erq->flags |= IW_ENCODE_DISABLED;
896 memcpy(key, sdata->keys[idx]->conf.key,
897 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
898 erq->length = sdata->keys[idx]->conf.keylen;
899 erq->flags |= IW_ENCODE_ENABLED;
904 static int ieee80211_ioctl_siwauth(struct net_device *dev,
905 struct iw_request_info *info,
906 struct iw_param *data, char *extra)
908 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
909 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
912 switch (data->flags & IW_AUTH_INDEX) {
913 case IW_AUTH_WPA_VERSION:
914 case IW_AUTH_CIPHER_PAIRWISE:
915 case IW_AUTH_CIPHER_GROUP:
916 case IW_AUTH_WPA_ENABLED:
917 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
919 case IW_AUTH_KEY_MGMT:
920 if (sdata->type != IEEE80211_IF_TYPE_STA)
924 * Key management was set by wpa_supplicant,
925 * we only need this to associate to a network
926 * that has privacy enabled regardless of not
929 sdata->u.sta.key_management_enabled = !!data->value;
932 case IW_AUTH_80211_AUTH_ALG:
933 if (sdata->type == IEEE80211_IF_TYPE_STA ||
934 sdata->type == IEEE80211_IF_TYPE_IBSS)
935 sdata->u.sta.auth_algs = data->value;
939 case IW_AUTH_PRIVACY_INVOKED:
940 if (local->ops->set_privacy_invoked)
941 ret = local->ops->set_privacy_invoked(
942 local_to_hw(local), data->value);
951 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
952 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
954 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
955 struct iw_statistics *wstats = &local->wstats;
956 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
957 struct sta_info *sta = NULL;
959 if (sdata->type == IEEE80211_IF_TYPE_STA ||
960 sdata->type == IEEE80211_IF_TYPE_IBSS)
961 sta = sta_info_get(local, sdata->u.sta.bssid);
963 wstats->discard.fragment = 0;
964 wstats->discard.misc = 0;
965 wstats->qual.qual = 0;
966 wstats->qual.level = 0;
967 wstats->qual.noise = 0;
968 wstats->qual.updated = IW_QUAL_ALL_INVALID;
970 wstats->qual.level = sta->last_rssi;
971 wstats->qual.qual = sta->last_signal;
972 wstats->qual.noise = sta->last_noise;
973 wstats->qual.updated = local->wstats_flags;
979 static int ieee80211_ioctl_giwauth(struct net_device *dev,
980 struct iw_request_info *info,
981 struct iw_param *data, char *extra)
983 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
986 switch (data->flags & IW_AUTH_INDEX) {
987 case IW_AUTH_80211_AUTH_ALG:
988 if (sdata->type == IEEE80211_IF_TYPE_STA ||
989 sdata->type == IEEE80211_IF_TYPE_IBSS)
990 data->value = sdata->u.sta.auth_algs;
1002 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1003 struct iw_request_info *info,
1004 struct iw_point *erq, char *extra)
1006 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1007 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1011 case IW_ENCODE_ALG_NONE:
1014 case IW_ENCODE_ALG_WEP:
1017 case IW_ENCODE_ALG_TKIP:
1020 case IW_ENCODE_ALG_CCMP:
1027 if (erq->flags & IW_ENCODE_DISABLED)
1030 idx = erq->flags & IW_ENCODE_INDEX;
1031 if (idx < 1 || idx > 4) {
1033 if (!sdata->default_key)
1035 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1036 if (sdata->default_key == sdata->keys[i]) {
1046 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
1048 IW_ENCODE_EXT_SET_TX_KEY,
1049 ext->key, ext->key_len);
1053 /* Structures to export the Wireless Handlers */
1055 static const iw_handler ieee80211_handler[] =
1057 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1058 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1059 (iw_handler) NULL, /* SIOCSIWNWID */
1060 (iw_handler) NULL, /* SIOCGIWNWID */
1061 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1062 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1063 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1064 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1065 (iw_handler) NULL, /* SIOCSIWSENS */
1066 (iw_handler) NULL, /* SIOCGIWSENS */
1067 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1068 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1069 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1070 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1071 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1072 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1073 (iw_handler) NULL, /* SIOCSIWSPY */
1074 (iw_handler) NULL, /* SIOCGIWSPY */
1075 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1076 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1077 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1078 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1079 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1080 (iw_handler) NULL, /* SIOCGIWAPLIST */
1081 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1082 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1083 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1084 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1085 (iw_handler) NULL, /* SIOCSIWNICKN */
1086 (iw_handler) NULL, /* SIOCGIWNICKN */
1087 (iw_handler) NULL, /* -- hole -- */
1088 (iw_handler) NULL, /* -- hole -- */
1089 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1090 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1091 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1092 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1093 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1094 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1095 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1096 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1097 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1098 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1099 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1100 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1101 (iw_handler) NULL, /* SIOCSIWPOWER */
1102 (iw_handler) NULL, /* SIOCGIWPOWER */
1103 (iw_handler) NULL, /* -- hole -- */
1104 (iw_handler) NULL, /* -- hole -- */
1105 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1106 (iw_handler) NULL, /* SIOCGIWGENIE */
1107 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1108 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1109 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1110 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1111 (iw_handler) NULL, /* SIOCSIWPMKSA */
1112 (iw_handler) NULL, /* -- hole -- */
1115 const struct iw_handler_def ieee80211_iw_handler_def =
1117 .num_standard = ARRAY_SIZE(ieee80211_handler),
1118 .standard = (iw_handler *) ieee80211_handler,
1119 .get_wireless_stats = ieee80211_get_wireless_stats,