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 ieee80211_sub_if_data *sdata, u8 *sta_addr,
31 int idx, int alg, int remove,
32 int set_tx_key, const u8 *_key,
35 struct ieee80211_local *local = sdata->local;
37 struct ieee80211_key *key;
40 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
41 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
42 sdata->dev->name, idx);
51 if (is_broadcast_ether_addr(sta_addr)) {
52 key = sdata->keys[idx];
54 sta = sta_info_get(local, sta_addr);
62 ieee80211_key_free(key);
64 key = ieee80211_key_alloc(alg, idx, key_len, _key);
73 if (!is_broadcast_ether_addr(sta_addr)) {
76 * According to the standard, the key index of a
77 * pairwise key must be zero. However, some AP are
78 * broken when it comes to WEP key indices, so we
81 if (idx != 0 && alg != ALG_WEP) {
82 ieee80211_key_free(key);
87 sta = sta_info_get(local, sta_addr);
89 ieee80211_key_free(key);
96 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
97 ieee80211_key_free(key);
102 ieee80211_key_link(key, sdata, sta);
104 if (set_tx_key || (!sta && !sdata->default_key && key))
105 ieee80211_set_default_key(sdata, idx);
114 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
115 struct iw_request_info *info,
116 struct iw_point *data, char *extra)
118 struct ieee80211_sub_if_data *sdata;
120 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
122 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
125 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
126 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
127 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
130 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
131 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
138 static int ieee80211_ioctl_giwrange(struct net_device *dev,
139 struct iw_request_info *info,
140 struct iw_point *data, char *extra)
142 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
143 struct iw_range *range = (struct iw_range *) extra;
144 enum ieee80211_band band;
147 data->length = sizeof(struct iw_range);
148 memset(range, 0, sizeof(struct iw_range));
150 range->we_version_compiled = WIRELESS_EXT;
151 range->we_version_source = 21;
152 range->retry_capa = IW_RETRY_LIMIT;
153 range->retry_flags = IW_RETRY_LIMIT;
154 range->min_retry = 0;
155 range->max_retry = 255;
157 range->max_rts = 2347;
158 range->min_frag = 256;
159 range->max_frag = 2346;
161 range->encoding_size[0] = 5;
162 range->encoding_size[1] = 13;
163 range->num_encoding_sizes = 2;
164 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
166 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
167 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
168 range->max_qual.level = local->hw.max_signal;
169 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
170 range->max_qual.level = -110;
172 range->max_qual.level = 0;
174 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
175 range->max_qual.noise = -110;
177 range->max_qual.noise = 0;
179 range->max_qual.qual = 100;
180 range->max_qual.updated = local->wstats_flags;
182 range->avg_qual.qual = 50;
183 /* not always true but better than nothing */
184 range->avg_qual.level = range->max_qual.level / 2;
185 range->avg_qual.noise = range->max_qual.noise / 2;
186 range->avg_qual.updated = local->wstats_flags;
188 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
189 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
192 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
194 struct ieee80211_supported_band *sband;
196 sband = local->hw.wiphy->bands[band];
201 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
202 struct ieee80211_channel *chan = &sband->channels[i];
204 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
206 ieee80211_frequency_to_channel(
208 range->freq[c].m = chan->center_freq;
209 range->freq[c].e = 6;
214 range->num_channels = c;
215 range->num_frequency = c;
217 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
218 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
219 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
221 range->scan_capa |= IW_SCAN_CAPA_ESSID;
227 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
228 struct iw_request_info *info,
229 struct iw_freq *freq, char *extra)
231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
233 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
234 sdata->vif.type == NL80211_IFTYPE_STATION)
235 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
237 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
240 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
241 sdata->vif.type == NL80211_IFTYPE_STATION)
242 sdata->u.sta.flags |=
243 IEEE80211_STA_AUTO_CHANNEL_SEL;
246 return ieee80211_set_freq(sdata,
247 ieee80211_channel_to_frequency(freq->m));
249 int i, div = 1000000;
250 for (i = 0; i < freq->e; i++)
253 return ieee80211_set_freq(sdata, freq->m / div);
260 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
261 struct iw_request_info *info,
262 struct iw_freq *freq, char *extra)
264 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
266 freq->m = local->hw.conf.channel->center_freq;
273 static int ieee80211_ioctl_siwessid(struct net_device *dev,
274 struct iw_request_info *info,
275 struct iw_point *data, char *ssid)
277 struct ieee80211_sub_if_data *sdata;
278 size_t len = data->length;
280 /* iwconfig uses nul termination in SSID.. */
281 if (len > 0 && ssid[len - 1] == '\0')
284 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
285 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
286 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
288 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
289 if (len > IEEE80211_MAX_SSID_LEN)
291 memcpy(sdata->u.sta.ssid, ssid, len);
292 sdata->u.sta.ssid_len = len;
296 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
298 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
299 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
302 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
310 static int ieee80211_ioctl_giwessid(struct net_device *dev,
311 struct iw_request_info *info,
312 struct iw_point *data, char *ssid)
316 struct ieee80211_sub_if_data *sdata;
317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
318 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
319 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
320 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
333 static int ieee80211_ioctl_siwap(struct net_device *dev,
334 struct iw_request_info *info,
335 struct sockaddr *ap_addr, char *extra)
337 struct ieee80211_sub_if_data *sdata;
339 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
340 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
341 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
343 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
344 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
348 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
349 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
350 IEEE80211_STA_AUTO_CHANNEL_SEL;
351 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
352 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
354 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
355 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
358 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
360 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
362 * If it is necessary to update the WDS peer address
363 * while the interface is running, then we need to do
364 * more work here, namely if it is running we need to
365 * add a new and remove the old STA entry, this is
366 * normally handled by _open() and _stop().
368 if (netif_running(dev))
371 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
381 static int ieee80211_ioctl_giwap(struct net_device *dev,
382 struct iw_request_info *info,
383 struct sockaddr *ap_addr, char *extra)
385 struct ieee80211_sub_if_data *sdata;
387 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
388 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
389 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
390 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
391 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
392 ap_addr->sa_family = ARPHRD_ETHER;
393 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
396 memset(&ap_addr->sa_data, 0, ETH_ALEN);
399 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
400 ap_addr->sa_family = ARPHRD_ETHER;
401 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
409 static int ieee80211_ioctl_siwscan(struct net_device *dev,
410 struct iw_request_info *info,
411 union iwreq_data *wrqu, char *extra)
413 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
414 struct iw_scan_req *req = NULL;
418 if (!netif_running(dev))
421 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
422 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
423 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
426 /* if SSID was specified explicitly then use that */
427 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
428 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
429 req = (struct iw_scan_req *)extra;
431 ssid_len = req->essid_len;
434 return ieee80211_request_scan(sdata, ssid, ssid_len);
438 static int ieee80211_ioctl_giwscan(struct net_device *dev,
439 struct iw_request_info *info,
440 struct iw_point *data, char *extra)
443 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
444 struct ieee80211_sub_if_data *sdata;
446 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
448 if (local->sw_scanning || local->hw_scanning)
451 res = ieee80211_scan_results(local, info, extra, data->length);
461 static int ieee80211_ioctl_siwrate(struct net_device *dev,
462 struct iw_request_info *info,
463 struct iw_param *rate, char *extra)
465 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
466 int i, err = -EINVAL;
467 u32 target_rate = rate->value / 100000;
468 struct ieee80211_sub_if_data *sdata;
469 struct ieee80211_supported_band *sband;
471 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
473 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
475 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
476 * target_rate = X, rate->fixed = 1 means only rate X
477 * target_rate = X, rate->fixed = 0 means all rates <= X */
478 sdata->max_ratectrl_rateidx = -1;
479 sdata->force_unicast_rateidx = -1;
483 for (i=0; i< sband->n_bitrates; i++) {
484 struct ieee80211_rate *brate = &sband->bitrates[i];
485 int this_rate = brate->bitrate;
487 if (target_rate == this_rate) {
488 sdata->max_ratectrl_rateidx = i;
490 sdata->force_unicast_rateidx = i;
498 static int ieee80211_ioctl_giwrate(struct net_device *dev,
499 struct iw_request_info *info,
500 struct iw_param *rate, char *extra)
502 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
503 struct sta_info *sta;
504 struct ieee80211_sub_if_data *sdata;
505 struct ieee80211_supported_band *sband;
507 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
509 if (sdata->vif.type != NL80211_IFTYPE_STATION)
512 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
516 sta = sta_info_get(local, sdata->u.sta.bssid);
518 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
519 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
528 rate->value *= 100000;
533 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
534 struct iw_request_info *info,
535 union iwreq_data *data, char *extra)
537 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
538 struct ieee80211_channel* chan = local->hw.conf.channel;
539 u32 reconf_flags = 0;
542 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
544 if (data->txpower.flags & IW_TXPOW_RANGE)
549 if (data->txpower.fixed)
550 new_power_level = min(data->txpower.value, chan->max_power);
551 else /* Automatic power level setting */
552 new_power_level = chan->max_power;
554 local->user_power_level = new_power_level;
555 if (local->hw.conf.power_level != new_power_level)
556 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
558 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
559 local->hw.conf.radio_enabled = !(data->txpower.disabled);
560 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
561 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
565 ieee80211_hw_config(local, reconf_flags);
570 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
571 struct iw_request_info *info,
572 union iwreq_data *data, char *extra)
574 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
576 data->txpower.fixed = 1;
577 data->txpower.disabled = !(local->hw.conf.radio_enabled);
578 data->txpower.value = local->hw.conf.power_level;
579 data->txpower.flags = IW_TXPOW_DBM;
584 static int ieee80211_ioctl_siwrts(struct net_device *dev,
585 struct iw_request_info *info,
586 struct iw_param *rts, char *extra)
588 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
591 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
592 else if (!rts->fixed)
593 /* if the rts value is not fixed, then take default */
594 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
595 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
598 local->rts_threshold = rts->value;
600 /* If the wlan card performs RTS/CTS in hardware/firmware,
601 * configure it here */
603 if (local->ops->set_rts_threshold)
604 local->ops->set_rts_threshold(local_to_hw(local),
605 local->rts_threshold);
610 static int ieee80211_ioctl_giwrts(struct net_device *dev,
611 struct iw_request_info *info,
612 struct iw_param *rts, char *extra)
614 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
616 rts->value = local->rts_threshold;
617 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
624 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
625 struct iw_request_info *info,
626 struct iw_param *frag, char *extra)
628 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
631 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
632 else if (!frag->fixed)
633 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
634 else if (frag->value < 256 ||
635 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
638 /* Fragment length must be even, so strip LSB. */
639 local->fragmentation_threshold = frag->value & ~0x1;
645 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
646 struct iw_request_info *info,
647 struct iw_param *frag, char *extra)
649 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
651 frag->value = local->fragmentation_threshold;
652 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
659 static int ieee80211_ioctl_siwretry(struct net_device *dev,
660 struct iw_request_info *info,
661 struct iw_param *retry, char *extra)
663 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
665 if (retry->disabled ||
666 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
669 if (retry->flags & IW_RETRY_MAX) {
670 local->hw.conf.long_frame_max_tx_count = retry->value;
671 } else if (retry->flags & IW_RETRY_MIN) {
672 local->hw.conf.short_frame_max_tx_count = retry->value;
674 local->hw.conf.long_frame_max_tx_count = retry->value;
675 local->hw.conf.short_frame_max_tx_count = retry->value;
678 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
684 static int ieee80211_ioctl_giwretry(struct net_device *dev,
685 struct iw_request_info *info,
686 struct iw_param *retry, char *extra)
688 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
691 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
692 /* first return min value, iwconfig will ask max value
694 retry->flags |= IW_RETRY_LIMIT;
695 retry->value = local->hw.conf.short_frame_max_tx_count;
696 if (local->hw.conf.long_frame_max_tx_count !=
697 local->hw.conf.short_frame_max_tx_count)
698 retry->flags |= IW_RETRY_MIN;
701 if (retry->flags & IW_RETRY_MAX) {
702 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
703 retry->value = local->hw.conf.long_frame_max_tx_count;
709 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
710 struct iw_request_info *info,
711 struct iw_point *data, char *extra)
713 struct ieee80211_sub_if_data *sdata;
714 struct iw_mlme *mlme = (struct iw_mlme *) extra;
716 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
717 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
718 sdata->vif.type != NL80211_IFTYPE_ADHOC)
723 /* TODO: mlme->addr.sa_data */
724 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
725 case IW_MLME_DISASSOC:
726 /* TODO: mlme->addr.sa_data */
727 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
734 static int ieee80211_ioctl_siwencode(struct net_device *dev,
735 struct iw_request_info *info,
736 struct iw_point *erq, char *keybuf)
738 struct ieee80211_sub_if_data *sdata;
739 int idx, i, alg = ALG_WEP;
740 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
743 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
745 idx = erq->flags & IW_ENCODE_INDEX;
747 if (sdata->default_key)
748 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
749 if (sdata->default_key == sdata->keys[i]) {
754 } else if (idx < 1 || idx > 4)
759 if (erq->flags & IW_ENCODE_DISABLED)
761 else if (erq->length == 0) {
762 /* No key data - just set the default TX key index */
763 ieee80211_set_default_key(sdata, idx);
767 return ieee80211_set_encryption(
771 keybuf, erq->length);
775 static int ieee80211_ioctl_giwencode(struct net_device *dev,
776 struct iw_request_info *info,
777 struct iw_point *erq, char *key)
779 struct ieee80211_sub_if_data *sdata;
782 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
784 idx = erq->flags & IW_ENCODE_INDEX;
785 if (idx < 1 || idx > 4) {
787 if (!sdata->default_key)
789 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
790 if (sdata->default_key == sdata->keys[i]) {
800 erq->flags = idx + 1;
802 if (!sdata->keys[idx]) {
804 erq->flags |= IW_ENCODE_DISABLED;
808 memcpy(key, sdata->keys[idx]->conf.key,
809 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
810 erq->length = sdata->keys[idx]->conf.keylen;
811 erq->flags |= IW_ENCODE_ENABLED;
813 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
814 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
815 switch (ifsta->auth_alg) {
818 erq->flags |= IW_ENCODE_OPEN;
820 case WLAN_AUTH_SHARED_KEY:
821 erq->flags |= IW_ENCODE_RESTRICTED;
829 static int ieee80211_ioctl_siwpower(struct net_device *dev,
830 struct iw_request_info *info,
831 struct iw_param *wrq,
834 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
835 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
836 struct ieee80211_conf *conf = &local->hw.conf;
837 int ret = 0, timeout = 0;
840 if (sdata->vif.type != NL80211_IFTYPE_STATION)
849 switch (wrq->flags & IW_POWER_MODE) {
850 case IW_POWER_ON: /* If not specified */
851 case IW_POWER_MODE: /* If set all mask */
852 case IW_POWER_ALL_R: /* If explicitely state all */
855 default: /* Otherwise we ignore */
859 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
862 if (wrq->flags & IW_POWER_TIMEOUT)
863 timeout = wrq->value / 1000;
866 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
869 local->powersave = ps;
870 conf->dynamic_ps_timeout = timeout;
872 if (local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS) {
873 ret = ieee80211_hw_config(local,
874 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
875 } else if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
876 if (conf->dynamic_ps_timeout > 0)
877 mod_timer(&local->dynamic_ps_timer, jiffies +
878 msecs_to_jiffies(conf->dynamic_ps_timeout));
880 if (local->powersave) {
881 ieee80211_send_nullfunc(local, sdata, 1);
882 conf->flags |= IEEE80211_CONF_PS;
883 ret = ieee80211_hw_config(local,
884 IEEE80211_CONF_CHANGE_PS);
886 conf->flags &= ~IEEE80211_CONF_PS;
887 ret = ieee80211_hw_config(local,
888 IEEE80211_CONF_CHANGE_PS);
889 ieee80211_send_nullfunc(local, sdata, 0);
897 static int ieee80211_ioctl_giwpower(struct net_device *dev,
898 struct iw_request_info *info,
899 union iwreq_data *wrqu,
902 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
904 wrqu->power.disabled = !local->powersave;
909 static int ieee80211_ioctl_siwauth(struct net_device *dev,
910 struct iw_request_info *info,
911 struct iw_param *data, char *extra)
913 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
916 switch (data->flags & IW_AUTH_INDEX) {
917 case IW_AUTH_WPA_VERSION:
918 case IW_AUTH_CIPHER_GROUP:
919 case IW_AUTH_WPA_ENABLED:
920 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
921 case IW_AUTH_KEY_MGMT:
923 case IW_AUTH_CIPHER_PAIRWISE:
924 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
925 if (data->value & (IW_AUTH_CIPHER_WEP40 |
926 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
927 sdata->u.sta.flags |=
928 IEEE80211_STA_TKIP_WEP_USED;
930 sdata->u.sta.flags &=
931 ~IEEE80211_STA_TKIP_WEP_USED;
934 case IW_AUTH_DROP_UNENCRYPTED:
935 sdata->drop_unencrypted = !!data->value;
937 case IW_AUTH_PRIVACY_INVOKED:
938 if (sdata->vif.type != NL80211_IFTYPE_STATION)
941 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
943 * Privacy invoked by wpa_supplicant, store the
944 * value and allow associating to a protected
945 * network without having a key up front.
948 sdata->u.sta.flags |=
949 IEEE80211_STA_PRIVACY_INVOKED;
952 case IW_AUTH_80211_AUTH_ALG:
953 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
954 sdata->vif.type == NL80211_IFTYPE_ADHOC)
955 sdata->u.sta.auth_algs = data->value;
966 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
967 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
969 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
970 struct iw_statistics *wstats = &local->wstats;
971 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
972 struct sta_info *sta = NULL;
976 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
977 sdata->vif.type == NL80211_IFTYPE_ADHOC)
978 sta = sta_info_get(local, sdata->u.sta.bssid);
980 wstats->discard.fragment = 0;
981 wstats->discard.misc = 0;
982 wstats->qual.qual = 0;
983 wstats->qual.level = 0;
984 wstats->qual.noise = 0;
985 wstats->qual.updated = IW_QUAL_ALL_INVALID;
987 wstats->qual.level = sta->last_signal;
988 wstats->qual.qual = sta->last_qual;
989 wstats->qual.noise = sta->last_noise;
990 wstats->qual.updated = local->wstats_flags;
998 static int ieee80211_ioctl_giwauth(struct net_device *dev,
999 struct iw_request_info *info,
1000 struct iw_param *data, char *extra)
1002 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1005 switch (data->flags & IW_AUTH_INDEX) {
1006 case IW_AUTH_80211_AUTH_ALG:
1007 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1008 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1009 data->value = sdata->u.sta.auth_algs;
1021 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1022 struct iw_request_info *info,
1023 struct iw_point *erq, char *extra)
1025 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1026 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1027 int uninitialized_var(alg), idx, i, remove = 0;
1030 case IW_ENCODE_ALG_NONE:
1033 case IW_ENCODE_ALG_WEP:
1036 case IW_ENCODE_ALG_TKIP:
1039 case IW_ENCODE_ALG_CCMP:
1046 if (erq->flags & IW_ENCODE_DISABLED)
1049 idx = erq->flags & IW_ENCODE_INDEX;
1050 if (idx < 1 || idx > 4) {
1052 if (!sdata->default_key)
1054 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1055 if (sdata->default_key == sdata->keys[i]) {
1065 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1068 IW_ENCODE_EXT_SET_TX_KEY,
1069 ext->key, ext->key_len);
1073 /* Structures to export the Wireless Handlers */
1075 static const iw_handler ieee80211_handler[] =
1077 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1078 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1079 (iw_handler) NULL, /* SIOCSIWNWID */
1080 (iw_handler) NULL, /* SIOCGIWNWID */
1081 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1082 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1083 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1084 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
1085 (iw_handler) NULL, /* SIOCSIWSENS */
1086 (iw_handler) NULL, /* SIOCGIWSENS */
1087 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1088 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1089 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1090 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1091 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1092 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1093 (iw_handler) NULL, /* SIOCSIWSPY */
1094 (iw_handler) NULL, /* SIOCGIWSPY */
1095 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1096 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1097 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1098 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1099 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1100 (iw_handler) NULL, /* SIOCGIWAPLIST */
1101 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1102 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1103 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1104 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1105 (iw_handler) NULL, /* SIOCSIWNICKN */
1106 (iw_handler) NULL, /* SIOCGIWNICKN */
1107 (iw_handler) NULL, /* -- hole -- */
1108 (iw_handler) NULL, /* -- hole -- */
1109 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1110 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1111 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1112 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1113 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1114 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1115 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1116 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1117 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1118 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1119 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1120 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1121 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1122 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1123 (iw_handler) NULL, /* -- hole -- */
1124 (iw_handler) NULL, /* -- hole -- */
1125 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1126 (iw_handler) NULL, /* SIOCGIWGENIE */
1127 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1128 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1129 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1130 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1131 (iw_handler) NULL, /* SIOCSIWPMKSA */
1132 (iw_handler) NULL, /* -- hole -- */
1135 const struct iw_handler_def ieee80211_iw_handler_def =
1137 .num_standard = ARRAY_SIZE(ieee80211_handler),
1138 .standard = (iw_handler *) ieee80211_handler,
1139 .get_wireless_stats = ieee80211_get_wireless_stats,