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"
30 static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
31 int idx, int alg, int remove,
32 int set_tx_key, const u8 *_key,
35 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
37 struct ieee80211_key *key;
38 struct ieee80211_sub_if_data *sdata;
41 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
43 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
44 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
54 if (is_broadcast_ether_addr(sta_addr)) {
55 key = sdata->keys[idx];
57 sta = sta_info_get(local, sta_addr);
65 ieee80211_key_free(key);
67 key = ieee80211_key_alloc(alg, idx, key_len, _key);
76 if (!is_broadcast_ether_addr(sta_addr)) {
79 * According to the standard, the key index of a
80 * pairwise key must be zero. However, some AP are
81 * broken when it comes to WEP key indices, so we
84 if (idx != 0 && alg != ALG_WEP) {
85 ieee80211_key_free(key);
90 sta = sta_info_get(local, sta_addr);
92 ieee80211_key_free(key);
98 ieee80211_key_link(key, sdata, sta);
100 if (set_tx_key || (!sta && !sdata->default_key && key))
101 ieee80211_set_default_key(sdata, idx);
110 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
111 struct iw_request_info *info,
112 struct iw_point *data, char *extra)
114 struct ieee80211_sub_if_data *sdata;
116 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
118 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
121 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
122 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
123 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
126 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
127 ieee80211_sta_req_auth(dev, &sdata->u.sta);
134 static int ieee80211_ioctl_giwname(struct net_device *dev,
135 struct iw_request_info *info,
136 char *name, char *extra)
138 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
139 struct ieee80211_supported_band *sband;
140 u8 is_ht = 0, is_a = 0, is_b = 0, is_g = 0;
143 sband = local->hw.wiphy->bands[IEEE80211_BAND_5GHZ];
146 is_ht |= sband->ht_info.ht_supported;
149 sband = local->hw.wiphy->bands[IEEE80211_BAND_2GHZ];
152 /* Check for mandatory rates */
153 for (i = 0; i < sband->n_bitrates; i++) {
154 if (sband->bitrates[i].bitrate == 10)
156 if (sband->bitrates[i].bitrate == 60)
159 is_ht |= sband->ht_info.ht_supported;
162 strcpy(name, "IEEE 802.11");
176 static int ieee80211_ioctl_giwrange(struct net_device *dev,
177 struct iw_request_info *info,
178 struct iw_point *data, char *extra)
180 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
181 struct iw_range *range = (struct iw_range *) extra;
182 enum ieee80211_band band;
185 data->length = sizeof(struct iw_range);
186 memset(range, 0, sizeof(struct iw_range));
188 range->we_version_compiled = WIRELESS_EXT;
189 range->we_version_source = 21;
190 range->retry_capa = IW_RETRY_LIMIT;
191 range->retry_flags = IW_RETRY_LIMIT;
192 range->min_retry = 0;
193 range->max_retry = 255;
195 range->max_rts = 2347;
196 range->min_frag = 256;
197 range->max_frag = 2346;
199 range->encoding_size[0] = 5;
200 range->encoding_size[1] = 13;
201 range->num_encoding_sizes = 2;
202 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
204 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
205 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
206 range->max_qual.level = local->hw.max_signal;
207 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
208 range->max_qual.level = -110;
210 range->max_qual.level = 0;
212 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
213 range->max_qual.noise = -110;
215 range->max_qual.noise = 0;
217 range->max_qual.qual = 100;
218 range->max_qual.updated = local->wstats_flags;
220 range->avg_qual.qual = 50;
221 /* not always true but better than nothing */
222 range->avg_qual.level = range->max_qual.level / 2;
223 range->avg_qual.noise = range->max_qual.noise / 2;
224 range->avg_qual.updated = local->wstats_flags;
226 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
227 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
230 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
232 struct ieee80211_supported_band *sband;
234 sband = local->hw.wiphy->bands[band];
239 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
240 struct ieee80211_channel *chan = &sband->channels[i];
242 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
244 ieee80211_frequency_to_channel(
246 range->freq[c].m = chan->center_freq;
247 range->freq[c].e = 6;
252 range->num_channels = c;
253 range->num_frequency = c;
255 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
256 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
257 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
259 range->scan_capa |= IW_SCAN_CAPA_ESSID;
265 static int ieee80211_ioctl_siwmode(struct net_device *dev,
266 struct iw_request_info *info,
267 __u32 *mode, char *extra)
269 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
272 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
277 type = IEEE80211_IF_TYPE_STA;
280 type = IEEE80211_IF_TYPE_IBSS;
283 type = IEEE80211_IF_TYPE_WDS;
285 case IW_MODE_MONITOR:
286 type = IEEE80211_IF_TYPE_MNTR;
292 if (type == sdata->vif.type)
294 if (netif_running(dev))
297 ieee80211_if_reinit(dev);
298 ieee80211_if_set_type(dev, type);
304 static int ieee80211_ioctl_giwmode(struct net_device *dev,
305 struct iw_request_info *info,
306 __u32 *mode, char *extra)
308 struct ieee80211_sub_if_data *sdata;
310 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
311 switch (sdata->vif.type) {
312 case IEEE80211_IF_TYPE_AP:
313 *mode = IW_MODE_MASTER;
315 case IEEE80211_IF_TYPE_STA:
316 *mode = IW_MODE_INFRA;
318 case IEEE80211_IF_TYPE_IBSS:
319 *mode = IW_MODE_ADHOC;
321 case IEEE80211_IF_TYPE_MNTR:
322 *mode = IW_MODE_MONITOR;
324 case IEEE80211_IF_TYPE_WDS:
325 *mode = IW_MODE_REPEAT;
327 case IEEE80211_IF_TYPE_VLAN:
328 *mode = IW_MODE_SECOND; /* FIXME */
331 *mode = IW_MODE_AUTO;
337 int ieee80211_set_freq(struct net_device *dev, int freqMHz)
340 struct ieee80211_channel *chan;
341 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
342 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
344 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
346 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
347 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
348 chan->flags & IEEE80211_CHAN_NO_IBSS) {
349 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
350 "%d MHz\n", dev->name, chan->center_freq);
353 local->oper_channel = chan;
355 if (local->sta_sw_scanning || local->sta_hw_scanning)
358 ret = ieee80211_hw_config(local);
360 rate_control_clear(local);
366 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
367 struct iw_request_info *info,
368 struct iw_freq *freq, char *extra)
370 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
372 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
373 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
375 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
378 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
379 sdata->u.sta.flags |=
380 IEEE80211_STA_AUTO_CHANNEL_SEL;
383 return ieee80211_set_freq(dev,
384 ieee80211_channel_to_frequency(freq->m));
386 int i, div = 1000000;
387 for (i = 0; i < freq->e; i++)
390 return ieee80211_set_freq(dev, freq->m / div);
397 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
398 struct iw_request_info *info,
399 struct iw_freq *freq, char *extra)
401 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
403 freq->m = local->hw.conf.channel->center_freq;
410 static int ieee80211_ioctl_siwessid(struct net_device *dev,
411 struct iw_request_info *info,
412 struct iw_point *data, char *ssid)
414 struct ieee80211_sub_if_data *sdata;
415 size_t len = data->length;
417 /* iwconfig uses nul termination in SSID.. */
418 if (len > 0 && ssid[len - 1] == '\0')
421 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
422 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
423 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
425 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
426 if (len > IEEE80211_MAX_SSID_LEN)
428 memcpy(sdata->u.sta.ssid, ssid, len);
429 sdata->u.sta.ssid_len = len;
433 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
435 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
436 ret = ieee80211_sta_set_ssid(dev, ssid, len);
439 ieee80211_sta_req_auth(dev, &sdata->u.sta);
443 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
444 memcpy(sdata->u.ap.ssid, ssid, len);
445 memset(sdata->u.ap.ssid + len, 0,
446 IEEE80211_MAX_SSID_LEN - len);
447 sdata->u.ap.ssid_len = len;
448 return ieee80211_if_config(dev);
454 static int ieee80211_ioctl_giwessid(struct net_device *dev,
455 struct iw_request_info *info,
456 struct iw_point *data, char *ssid)
460 struct ieee80211_sub_if_data *sdata;
461 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
462 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
463 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
464 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
473 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
474 len = sdata->u.ap.ssid_len;
475 if (len > IW_ESSID_MAX_SIZE)
476 len = IW_ESSID_MAX_SIZE;
477 memcpy(ssid, sdata->u.ap.ssid, len);
486 static int ieee80211_ioctl_siwap(struct net_device *dev,
487 struct iw_request_info *info,
488 struct sockaddr *ap_addr, char *extra)
490 struct ieee80211_sub_if_data *sdata;
492 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
493 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
494 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
496 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
497 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
501 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
502 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
503 IEEE80211_STA_AUTO_CHANNEL_SEL;
504 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
505 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
507 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
508 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
511 ieee80211_sta_req_auth(dev, &sdata->u.sta);
513 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
515 * If it is necessary to update the WDS peer address
516 * while the interface is running, then we need to do
517 * more work here, namely if it is running we need to
518 * add a new and remove the old STA entry, this is
519 * normally handled by _open() and _stop().
521 if (netif_running(dev))
524 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
534 static int ieee80211_ioctl_giwap(struct net_device *dev,
535 struct iw_request_info *info,
536 struct sockaddr *ap_addr, char *extra)
538 struct ieee80211_sub_if_data *sdata;
540 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
541 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
542 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
543 if (sdata->u.sta.state == IEEE80211_ASSOCIATED ||
544 sdata->u.sta.state == IEEE80211_IBSS_JOINED) {
545 ap_addr->sa_family = ARPHRD_ETHER;
546 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
549 memset(&ap_addr->sa_data, 0, ETH_ALEN);
552 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
553 ap_addr->sa_family = ARPHRD_ETHER;
554 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
562 static int ieee80211_ioctl_siwscan(struct net_device *dev,
563 struct iw_request_info *info,
564 union iwreq_data *wrqu, char *extra)
566 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
567 struct iw_scan_req *req = NULL;
571 if (!netif_running(dev))
574 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
575 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
576 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
577 sdata->vif.type != IEEE80211_IF_TYPE_AP)
580 /* if SSID was specified explicitly then use that */
581 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
582 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
583 req = (struct iw_scan_req *)extra;
585 ssid_len = req->essid_len;
588 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
592 static int ieee80211_ioctl_giwscan(struct net_device *dev,
593 struct iw_request_info *info,
594 struct iw_point *data, char *extra)
597 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
599 if (local->sta_sw_scanning || local->sta_hw_scanning)
602 res = ieee80211_sta_scan_results(dev, info, extra, data->length);
612 static int ieee80211_ioctl_siwrate(struct net_device *dev,
613 struct iw_request_info *info,
614 struct iw_param *rate, char *extra)
616 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
617 int i, err = -EINVAL;
618 u32 target_rate = rate->value / 100000;
619 struct ieee80211_sub_if_data *sdata;
620 struct ieee80211_supported_band *sband;
622 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
626 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
628 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
629 * target_rate = X, rate->fixed = 1 means only rate X
630 * target_rate = X, rate->fixed = 0 means all rates <= X */
631 sdata->bss->max_ratectrl_rateidx = -1;
632 sdata->bss->force_unicast_rateidx = -1;
636 for (i=0; i< sband->n_bitrates; i++) {
637 struct ieee80211_rate *brate = &sband->bitrates[i];
638 int this_rate = brate->bitrate;
640 if (target_rate == this_rate) {
641 sdata->bss->max_ratectrl_rateidx = i;
643 sdata->bss->force_unicast_rateidx = i;
651 static int ieee80211_ioctl_giwrate(struct net_device *dev,
652 struct iw_request_info *info,
653 struct iw_param *rate, char *extra)
655 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
656 struct sta_info *sta;
657 struct ieee80211_sub_if_data *sdata;
658 struct ieee80211_supported_band *sband;
660 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
662 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
665 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
669 sta = sta_info_get(local, sdata->u.sta.bssid);
671 if (sta && sta->txrate_idx < sband->n_bitrates)
672 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
681 rate->value *= 100000;
686 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
687 struct iw_request_info *info,
688 union iwreq_data *data, char *extra)
690 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
691 bool need_reconfig = 0;
694 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
696 if (data->txpower.flags & IW_TXPOW_RANGE)
699 if (data->txpower.fixed) {
700 new_power_level = data->txpower.value;
703 * Automatic power level. Use maximum power for the current
704 * channel. Should be part of rate control.
706 struct ieee80211_channel* chan = local->hw.conf.channel;
710 new_power_level = chan->max_power;
713 if (local->hw.conf.power_level != new_power_level) {
714 local->hw.conf.power_level = new_power_level;
718 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
719 local->hw.conf.radio_enabled = !(data->txpower.disabled);
721 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
725 ieee80211_hw_config(local);
726 /* The return value of hw_config is not of big interest here,
727 * as it doesn't say that it failed because of _this_ config
728 * change or something else. Ignore it. */
734 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
735 struct iw_request_info *info,
736 union iwreq_data *data, char *extra)
738 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
740 data->txpower.fixed = 1;
741 data->txpower.disabled = !(local->hw.conf.radio_enabled);
742 data->txpower.value = local->hw.conf.power_level;
743 data->txpower.flags = IW_TXPOW_DBM;
748 static int ieee80211_ioctl_siwrts(struct net_device *dev,
749 struct iw_request_info *info,
750 struct iw_param *rts, char *extra)
752 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
755 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
756 else if (!rts->fixed)
757 /* if the rts value is not fixed, then take default */
758 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
759 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
762 local->rts_threshold = rts->value;
764 /* If the wlan card performs RTS/CTS in hardware/firmware,
765 * configure it here */
767 if (local->ops->set_rts_threshold)
768 local->ops->set_rts_threshold(local_to_hw(local),
769 local->rts_threshold);
774 static int ieee80211_ioctl_giwrts(struct net_device *dev,
775 struct iw_request_info *info,
776 struct iw_param *rts, char *extra)
778 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
780 rts->value = local->rts_threshold;
781 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
788 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
789 struct iw_request_info *info,
790 struct iw_param *frag, char *extra)
792 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
795 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
796 else if (frag->value < 256 ||
797 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
800 /* Fragment length must be even, so strip LSB. */
801 local->fragmentation_threshold = frag->value & ~0x1;
804 /* If the wlan card performs fragmentation in hardware/firmware,
805 * configure it here */
807 if (local->ops->set_frag_threshold)
808 local->ops->set_frag_threshold(
810 local->fragmentation_threshold);
815 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
816 struct iw_request_info *info,
817 struct iw_param *frag, char *extra)
819 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
821 frag->value = local->fragmentation_threshold;
822 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
829 static int ieee80211_ioctl_siwretry(struct net_device *dev,
830 struct iw_request_info *info,
831 struct iw_param *retry, char *extra)
833 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
835 if (retry->disabled ||
836 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
839 if (retry->flags & IW_RETRY_MAX)
840 local->long_retry_limit = retry->value;
841 else if (retry->flags & IW_RETRY_MIN)
842 local->short_retry_limit = retry->value;
844 local->long_retry_limit = retry->value;
845 local->short_retry_limit = retry->value;
848 if (local->ops->set_retry_limit) {
849 return local->ops->set_retry_limit(
851 local->short_retry_limit,
852 local->long_retry_limit);
859 static int ieee80211_ioctl_giwretry(struct net_device *dev,
860 struct iw_request_info *info,
861 struct iw_param *retry, char *extra)
863 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
866 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
867 /* first return min value, iwconfig will ask max value
869 retry->flags |= IW_RETRY_LIMIT;
870 retry->value = local->short_retry_limit;
871 if (local->long_retry_limit != local->short_retry_limit)
872 retry->flags |= IW_RETRY_MIN;
875 if (retry->flags & IW_RETRY_MAX) {
876 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
877 retry->value = local->long_retry_limit;
883 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
884 struct iw_request_info *info,
885 struct iw_point *data, char *extra)
887 struct ieee80211_sub_if_data *sdata;
888 struct iw_mlme *mlme = (struct iw_mlme *) extra;
890 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
891 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
892 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
897 /* TODO: mlme->addr.sa_data */
898 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
899 case IW_MLME_DISASSOC:
900 /* TODO: mlme->addr.sa_data */
901 return ieee80211_sta_disassociate(dev, mlme->reason_code);
908 static int ieee80211_ioctl_siwencode(struct net_device *dev,
909 struct iw_request_info *info,
910 struct iw_point *erq, char *keybuf)
912 struct ieee80211_sub_if_data *sdata;
913 int idx, i, alg = ALG_WEP;
914 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
917 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
919 idx = erq->flags & IW_ENCODE_INDEX;
921 if (sdata->default_key)
922 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
923 if (sdata->default_key == sdata->keys[i]) {
928 } else if (idx < 1 || idx > 4)
933 if (erq->flags & IW_ENCODE_DISABLED)
935 else if (erq->length == 0) {
936 /* No key data - just set the default TX key index */
937 ieee80211_set_default_key(sdata, idx);
941 return ieee80211_set_encryption(
945 keybuf, erq->length);
949 static int ieee80211_ioctl_giwencode(struct net_device *dev,
950 struct iw_request_info *info,
951 struct iw_point *erq, char *key)
953 struct ieee80211_sub_if_data *sdata;
956 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
958 idx = erq->flags & IW_ENCODE_INDEX;
959 if (idx < 1 || idx > 4) {
961 if (!sdata->default_key)
963 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
964 if (sdata->default_key == sdata->keys[i]) {
974 erq->flags = idx + 1;
976 if (!sdata->keys[idx]) {
978 erq->flags |= IW_ENCODE_DISABLED;
982 memcpy(key, sdata->keys[idx]->conf.key,
983 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
984 erq->length = sdata->keys[idx]->conf.keylen;
985 erq->flags |= IW_ENCODE_ENABLED;
987 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
988 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
989 switch (ifsta->auth_alg) {
992 erq->flags |= IW_ENCODE_OPEN;
994 case WLAN_AUTH_SHARED_KEY:
995 erq->flags |= IW_ENCODE_RESTRICTED;
1003 static int ieee80211_ioctl_siwauth(struct net_device *dev,
1004 struct iw_request_info *info,
1005 struct iw_param *data, char *extra)
1007 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1010 switch (data->flags & IW_AUTH_INDEX) {
1011 case IW_AUTH_WPA_VERSION:
1012 case IW_AUTH_CIPHER_PAIRWISE:
1013 case IW_AUTH_CIPHER_GROUP:
1014 case IW_AUTH_WPA_ENABLED:
1015 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1016 case IW_AUTH_KEY_MGMT:
1018 case IW_AUTH_DROP_UNENCRYPTED:
1019 sdata->drop_unencrypted = !!data->value;
1021 case IW_AUTH_PRIVACY_INVOKED:
1022 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
1025 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
1027 * Privacy invoked by wpa_supplicant, store the
1028 * value and allow associating to a protected
1029 * network without having a key up front.
1032 sdata->u.sta.flags |=
1033 IEEE80211_STA_PRIVACY_INVOKED;
1036 case IW_AUTH_80211_AUTH_ALG:
1037 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1038 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
1039 sdata->u.sta.auth_algs = data->value;
1050 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1051 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1053 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1054 struct iw_statistics *wstats = &local->wstats;
1055 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1056 struct sta_info *sta = NULL;
1060 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1061 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
1062 sta = sta_info_get(local, sdata->u.sta.bssid);
1064 wstats->discard.fragment = 0;
1065 wstats->discard.misc = 0;
1066 wstats->qual.qual = 0;
1067 wstats->qual.level = 0;
1068 wstats->qual.noise = 0;
1069 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1071 wstats->qual.level = sta->last_signal;
1072 wstats->qual.qual = sta->last_qual;
1073 wstats->qual.noise = sta->last_noise;
1074 wstats->qual.updated = local->wstats_flags;
1082 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1083 struct iw_request_info *info,
1084 struct iw_param *data, char *extra)
1086 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1089 switch (data->flags & IW_AUTH_INDEX) {
1090 case IW_AUTH_80211_AUTH_ALG:
1091 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1092 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
1093 data->value = sdata->u.sta.auth_algs;
1105 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1106 struct iw_request_info *info,
1107 struct iw_point *erq, char *extra)
1109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1110 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1111 int uninitialized_var(alg), idx, i, remove = 0;
1114 case IW_ENCODE_ALG_NONE:
1117 case IW_ENCODE_ALG_WEP:
1120 case IW_ENCODE_ALG_TKIP:
1123 case IW_ENCODE_ALG_CCMP:
1130 if (erq->flags & IW_ENCODE_DISABLED)
1133 idx = erq->flags & IW_ENCODE_INDEX;
1134 if (idx < 1 || idx > 4) {
1136 if (!sdata->default_key)
1138 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1139 if (sdata->default_key == sdata->keys[i]) {
1149 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
1152 IW_ENCODE_EXT_SET_TX_KEY,
1153 ext->key, ext->key_len);
1157 /* Structures to export the Wireless Handlers */
1159 static const iw_handler ieee80211_handler[] =
1161 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1162 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1163 (iw_handler) NULL, /* SIOCSIWNWID */
1164 (iw_handler) NULL, /* SIOCGIWNWID */
1165 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1166 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1167 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1168 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1169 (iw_handler) NULL, /* SIOCSIWSENS */
1170 (iw_handler) NULL, /* SIOCGIWSENS */
1171 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1172 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1173 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1174 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1175 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1176 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1177 (iw_handler) NULL, /* SIOCSIWSPY */
1178 (iw_handler) NULL, /* SIOCGIWSPY */
1179 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1180 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1181 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1182 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1183 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1184 (iw_handler) NULL, /* SIOCGIWAPLIST */
1185 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1186 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1187 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1188 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1189 (iw_handler) NULL, /* SIOCSIWNICKN */
1190 (iw_handler) NULL, /* SIOCGIWNICKN */
1191 (iw_handler) NULL, /* -- hole -- */
1192 (iw_handler) NULL, /* -- hole -- */
1193 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1194 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1195 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1196 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1197 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1198 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1199 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1200 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1201 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1202 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1203 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1204 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1205 (iw_handler) NULL, /* SIOCSIWPOWER */
1206 (iw_handler) NULL, /* SIOCGIWPOWER */
1207 (iw_handler) NULL, /* -- hole -- */
1208 (iw_handler) NULL, /* -- hole -- */
1209 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1210 (iw_handler) NULL, /* SIOCGIWGENIE */
1211 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1212 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1213 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1214 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1215 (iw_handler) NULL, /* SIOCSIWPMKSA */
1216 (iw_handler) NULL, /* -- hole -- */
1219 const struct iw_handler_def ieee80211_iw_handler_def =
1221 .num_standard = ARRAY_SIZE(ieee80211_handler),
1222 .standard = (iw_handler *) ieee80211_handler,
1223 .get_wireless_stats = ieee80211_get_wireless_stats,