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 (alg == ALG_AES_CMAC) {
41 if (idx < NUM_DEFAULT_KEYS ||
42 idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
43 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d "
44 "(BIP)\n", sdata->dev->name, idx);
47 } else if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
48 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
49 sdata->dev->name, idx);
58 if (is_broadcast_ether_addr(sta_addr)) {
59 key = sdata->keys[idx];
61 sta = sta_info_get(local, sta_addr);
69 ieee80211_key_free(key);
71 key = ieee80211_key_alloc(alg, idx, key_len, _key);
80 if (!is_broadcast_ether_addr(sta_addr)) {
83 * According to the standard, the key index of a
84 * pairwise key must be zero. However, some AP are
85 * broken when it comes to WEP key indices, so we
88 if (idx != 0 && alg != ALG_WEP) {
89 ieee80211_key_free(key);
94 sta = sta_info_get(local, sta_addr);
96 ieee80211_key_free(key);
102 if (alg == ALG_WEP &&
103 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
104 ieee80211_key_free(key);
109 ieee80211_key_link(key, sdata, sta);
111 if (set_tx_key || (!sta && !sdata->default_key && key))
112 ieee80211_set_default_key(sdata, idx);
113 if (alg == ALG_AES_CMAC &&
114 (set_tx_key || (!sta && !sdata->default_mgmt_key && key)))
115 ieee80211_set_default_mgmt_key(sdata, idx);
124 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
125 struct iw_request_info *info,
126 struct iw_point *data, char *extra)
128 struct ieee80211_sub_if_data *sdata;
130 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
132 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
135 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
136 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
137 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
140 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
141 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
148 static u8 ieee80211_get_wstats_flags(struct ieee80211_local *local)
152 wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
153 IEEE80211_HW_SIGNAL_DBM) ?
154 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
155 wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ?
156 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
157 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
158 wstats_flags |= IW_QUAL_DBM;
163 static int ieee80211_ioctl_giwrange(struct net_device *dev,
164 struct iw_request_info *info,
165 struct iw_point *data, char *extra)
167 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
168 struct iw_range *range = (struct iw_range *) extra;
169 enum ieee80211_band band;
172 data->length = sizeof(struct iw_range);
173 memset(range, 0, sizeof(struct iw_range));
175 range->we_version_compiled = WIRELESS_EXT;
176 range->we_version_source = 21;
177 range->retry_capa = IW_RETRY_LIMIT;
178 range->retry_flags = IW_RETRY_LIMIT;
179 range->min_retry = 0;
180 range->max_retry = 255;
182 range->max_rts = 2347;
183 range->min_frag = 256;
184 range->max_frag = 2346;
186 range->encoding_size[0] = 5;
187 range->encoding_size[1] = 13;
188 range->num_encoding_sizes = 2;
189 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
191 /* cfg80211 requires this, and enforces 0..100 */
192 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
193 range->max_qual.level = 100;
194 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
195 range->max_qual.level = -110;
197 range->max_qual.level = 0;
199 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
200 range->max_qual.noise = -110;
202 range->max_qual.noise = 0;
204 range->max_qual.qual = 100;
205 range->max_qual.updated = ieee80211_get_wstats_flags(local);
207 range->avg_qual.qual = 50;
208 /* not always true but better than nothing */
209 range->avg_qual.level = range->max_qual.level / 2;
210 range->avg_qual.noise = range->max_qual.noise / 2;
211 range->avg_qual.updated = ieee80211_get_wstats_flags(local);
213 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
214 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
217 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
219 struct ieee80211_supported_band *sband;
221 sband = local->hw.wiphy->bands[band];
226 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
227 struct ieee80211_channel *chan = &sband->channels[i];
229 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
231 ieee80211_frequency_to_channel(
233 range->freq[c].m = chan->center_freq;
234 range->freq[c].e = 6;
239 range->num_channels = c;
240 range->num_frequency = c;
242 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
243 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
244 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
246 range->scan_capa |= IW_SCAN_CAPA_ESSID;
252 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
253 struct iw_request_info *info,
254 struct iw_freq *freq, char *extra)
256 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
258 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
259 sdata->vif.type == NL80211_IFTYPE_STATION)
260 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
262 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
265 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
266 sdata->vif.type == NL80211_IFTYPE_STATION)
267 sdata->u.sta.flags |=
268 IEEE80211_STA_AUTO_CHANNEL_SEL;
271 return ieee80211_set_freq(sdata,
272 ieee80211_channel_to_frequency(freq->m));
274 int i, div = 1000000;
275 for (i = 0; i < freq->e; i++)
278 return ieee80211_set_freq(sdata, freq->m / div);
285 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
286 struct iw_request_info *info,
287 struct iw_freq *freq, char *extra)
289 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
291 freq->m = local->hw.conf.channel->center_freq;
298 static int ieee80211_ioctl_siwessid(struct net_device *dev,
299 struct iw_request_info *info,
300 struct iw_point *data, char *ssid)
302 struct ieee80211_sub_if_data *sdata;
303 size_t len = data->length;
305 /* iwconfig uses nul termination in SSID.. */
306 if (len > 0 && ssid[len - 1] == '\0')
309 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
310 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
311 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
313 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
314 if (len > IEEE80211_MAX_SSID_LEN)
316 memcpy(sdata->u.sta.ssid, ssid, len);
317 sdata->u.sta.ssid_len = len;
321 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
323 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
324 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
327 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
335 static int ieee80211_ioctl_giwessid(struct net_device *dev,
336 struct iw_request_info *info,
337 struct iw_point *data, char *ssid)
341 struct ieee80211_sub_if_data *sdata;
342 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
343 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
344 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
345 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
358 static int ieee80211_ioctl_siwap(struct net_device *dev,
359 struct iw_request_info *info,
360 struct sockaddr *ap_addr, char *extra)
362 struct ieee80211_sub_if_data *sdata;
364 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
365 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
366 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
368 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
369 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
373 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
374 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
375 IEEE80211_STA_AUTO_CHANNEL_SEL;
376 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
377 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
379 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
380 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
383 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
385 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
387 * If it is necessary to update the WDS peer address
388 * while the interface is running, then we need to do
389 * more work here, namely if it is running we need to
390 * add a new and remove the old STA entry, this is
391 * normally handled by _open() and _stop().
393 if (netif_running(dev))
396 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
406 static int ieee80211_ioctl_giwap(struct net_device *dev,
407 struct iw_request_info *info,
408 struct sockaddr *ap_addr, char *extra)
410 struct ieee80211_sub_if_data *sdata;
412 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
413 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
414 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
415 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
416 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
417 ap_addr->sa_family = ARPHRD_ETHER;
418 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
421 memset(&ap_addr->sa_data, 0, ETH_ALEN);
424 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
425 ap_addr->sa_family = ARPHRD_ETHER;
426 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
434 static int ieee80211_ioctl_siwrate(struct net_device *dev,
435 struct iw_request_info *info,
436 struct iw_param *rate, char *extra)
438 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
439 int i, err = -EINVAL;
440 u32 target_rate = rate->value / 100000;
441 struct ieee80211_sub_if_data *sdata;
442 struct ieee80211_supported_band *sband;
444 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
446 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
448 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
449 * target_rate = X, rate->fixed = 1 means only rate X
450 * target_rate = X, rate->fixed = 0 means all rates <= X */
451 sdata->max_ratectrl_rateidx = -1;
452 sdata->force_unicast_rateidx = -1;
456 for (i=0; i< sband->n_bitrates; i++) {
457 struct ieee80211_rate *brate = &sband->bitrates[i];
458 int this_rate = brate->bitrate;
460 if (target_rate == this_rate) {
461 sdata->max_ratectrl_rateidx = i;
463 sdata->force_unicast_rateidx = i;
471 static int ieee80211_ioctl_giwrate(struct net_device *dev,
472 struct iw_request_info *info,
473 struct iw_param *rate, char *extra)
475 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
476 struct sta_info *sta;
477 struct ieee80211_sub_if_data *sdata;
478 struct ieee80211_supported_band *sband;
480 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
482 if (sdata->vif.type != NL80211_IFTYPE_STATION)
485 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
489 sta = sta_info_get(local, sdata->u.sta.bssid);
491 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
492 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
501 rate->value *= 100000;
506 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
507 struct iw_request_info *info,
508 union iwreq_data *data, char *extra)
510 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
511 struct ieee80211_channel* chan = local->hw.conf.channel;
512 u32 reconf_flags = 0;
515 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
517 if (data->txpower.flags & IW_TXPOW_RANGE)
522 if (data->txpower.fixed)
523 new_power_level = min(data->txpower.value, chan->max_power);
524 else /* Automatic power level setting */
525 new_power_level = chan->max_power;
527 local->user_power_level = new_power_level;
528 if (local->hw.conf.power_level != new_power_level)
529 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
531 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
532 local->hw.conf.radio_enabled = !(data->txpower.disabled);
533 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
534 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
538 ieee80211_hw_config(local, reconf_flags);
543 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
544 struct iw_request_info *info,
545 union iwreq_data *data, char *extra)
547 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
549 data->txpower.fixed = 1;
550 data->txpower.disabled = !(local->hw.conf.radio_enabled);
551 data->txpower.value = local->hw.conf.power_level;
552 data->txpower.flags = IW_TXPOW_DBM;
557 static int ieee80211_ioctl_siwrts(struct net_device *dev,
558 struct iw_request_info *info,
559 struct iw_param *rts, char *extra)
561 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
564 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
565 else if (!rts->fixed)
566 /* if the rts value is not fixed, then take default */
567 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
568 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
571 local->rts_threshold = rts->value;
573 /* If the wlan card performs RTS/CTS in hardware/firmware,
574 * configure it here */
576 if (local->ops->set_rts_threshold)
577 local->ops->set_rts_threshold(local_to_hw(local),
578 local->rts_threshold);
583 static int ieee80211_ioctl_giwrts(struct net_device *dev,
584 struct iw_request_info *info,
585 struct iw_param *rts, char *extra)
587 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
589 rts->value = local->rts_threshold;
590 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
597 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
598 struct iw_request_info *info,
599 struct iw_param *frag, char *extra)
601 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
604 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
605 else if (!frag->fixed)
606 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
607 else if (frag->value < 256 ||
608 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
611 /* Fragment length must be even, so strip LSB. */
612 local->fragmentation_threshold = frag->value & ~0x1;
618 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
619 struct iw_request_info *info,
620 struct iw_param *frag, char *extra)
622 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
624 frag->value = local->fragmentation_threshold;
625 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
632 static int ieee80211_ioctl_siwretry(struct net_device *dev,
633 struct iw_request_info *info,
634 struct iw_param *retry, char *extra)
636 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
638 if (retry->disabled ||
639 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
642 if (retry->flags & IW_RETRY_MAX) {
643 local->hw.conf.long_frame_max_tx_count = retry->value;
644 } else if (retry->flags & IW_RETRY_MIN) {
645 local->hw.conf.short_frame_max_tx_count = retry->value;
647 local->hw.conf.long_frame_max_tx_count = retry->value;
648 local->hw.conf.short_frame_max_tx_count = retry->value;
651 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
657 static int ieee80211_ioctl_giwretry(struct net_device *dev,
658 struct iw_request_info *info,
659 struct iw_param *retry, char *extra)
661 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
664 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
665 /* first return min value, iwconfig will ask max value
667 retry->flags |= IW_RETRY_LIMIT;
668 retry->value = local->hw.conf.short_frame_max_tx_count;
669 if (local->hw.conf.long_frame_max_tx_count !=
670 local->hw.conf.short_frame_max_tx_count)
671 retry->flags |= IW_RETRY_MIN;
674 if (retry->flags & IW_RETRY_MAX) {
675 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
676 retry->value = local->hw.conf.long_frame_max_tx_count;
682 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
683 struct iw_request_info *info,
684 struct iw_point *data, char *extra)
686 struct ieee80211_sub_if_data *sdata;
687 struct iw_mlme *mlme = (struct iw_mlme *) extra;
689 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
690 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
691 sdata->vif.type != NL80211_IFTYPE_ADHOC)
696 /* TODO: mlme->addr.sa_data */
697 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
698 case IW_MLME_DISASSOC:
699 /* TODO: mlme->addr.sa_data */
700 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
707 static int ieee80211_ioctl_siwencode(struct net_device *dev,
708 struct iw_request_info *info,
709 struct iw_point *erq, char *keybuf)
711 struct ieee80211_sub_if_data *sdata;
712 int idx, i, alg = ALG_WEP;
713 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
716 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
718 idx = erq->flags & IW_ENCODE_INDEX;
720 if (sdata->default_key)
721 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
722 if (sdata->default_key == sdata->keys[i]) {
727 } else if (idx < 1 || idx > 4)
732 if (erq->flags & IW_ENCODE_DISABLED)
734 else if (erq->length == 0) {
735 /* No key data - just set the default TX key index */
736 ieee80211_set_default_key(sdata, idx);
740 return ieee80211_set_encryption(
744 keybuf, erq->length);
748 static int ieee80211_ioctl_giwencode(struct net_device *dev,
749 struct iw_request_info *info,
750 struct iw_point *erq, char *key)
752 struct ieee80211_sub_if_data *sdata;
755 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
757 idx = erq->flags & IW_ENCODE_INDEX;
758 if (idx < 1 || idx > 4) {
760 if (!sdata->default_key)
762 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
763 if (sdata->default_key == sdata->keys[i]) {
773 erq->flags = idx + 1;
775 if (!sdata->keys[idx]) {
777 erq->flags |= IW_ENCODE_DISABLED;
781 memcpy(key, sdata->keys[idx]->conf.key,
782 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
783 erq->length = sdata->keys[idx]->conf.keylen;
784 erq->flags |= IW_ENCODE_ENABLED;
786 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
787 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
788 switch (ifsta->auth_alg) {
791 erq->flags |= IW_ENCODE_OPEN;
793 case WLAN_AUTH_SHARED_KEY:
794 erq->flags |= IW_ENCODE_RESTRICTED;
802 static int ieee80211_ioctl_siwpower(struct net_device *dev,
803 struct iw_request_info *info,
804 struct iw_param *wrq,
807 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
808 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
809 struct ieee80211_conf *conf = &local->hw.conf;
810 int ret = 0, timeout = 0;
813 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
816 if (sdata->vif.type != NL80211_IFTYPE_STATION)
825 switch (wrq->flags & IW_POWER_MODE) {
826 case IW_POWER_ON: /* If not specified */
827 case IW_POWER_MODE: /* If set all mask */
828 case IW_POWER_ALL_R: /* If explicitely state all */
831 default: /* Otherwise we ignore */
835 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
838 if (wrq->flags & IW_POWER_TIMEOUT)
839 timeout = wrq->value / 1000;
842 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
845 local->powersave = ps;
846 conf->dynamic_ps_timeout = timeout;
848 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
849 ret = ieee80211_hw_config(local,
850 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
852 if (!(sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
855 if (conf->dynamic_ps_timeout > 0 &&
856 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
857 mod_timer(&local->dynamic_ps_timer, jiffies +
858 msecs_to_jiffies(conf->dynamic_ps_timeout));
860 if (local->powersave) {
861 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
862 ieee80211_send_nullfunc(local, sdata, 1);
863 conf->flags |= IEEE80211_CONF_PS;
864 ret = ieee80211_hw_config(local,
865 IEEE80211_CONF_CHANGE_PS);
867 conf->flags &= ~IEEE80211_CONF_PS;
868 ret = ieee80211_hw_config(local,
869 IEEE80211_CONF_CHANGE_PS);
870 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
871 ieee80211_send_nullfunc(local, sdata, 0);
872 del_timer_sync(&local->dynamic_ps_timer);
873 cancel_work_sync(&local->dynamic_ps_enable_work);
880 static int ieee80211_ioctl_giwpower(struct net_device *dev,
881 struct iw_request_info *info,
882 union iwreq_data *wrqu,
885 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
887 wrqu->power.disabled = !local->powersave;
892 static int ieee80211_ioctl_siwauth(struct net_device *dev,
893 struct iw_request_info *info,
894 struct iw_param *data, char *extra)
896 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
899 switch (data->flags & IW_AUTH_INDEX) {
900 case IW_AUTH_WPA_VERSION:
901 case IW_AUTH_CIPHER_GROUP:
902 case IW_AUTH_WPA_ENABLED:
903 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
904 case IW_AUTH_KEY_MGMT:
905 case IW_AUTH_CIPHER_GROUP_MGMT:
907 case IW_AUTH_CIPHER_PAIRWISE:
908 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
909 if (data->value & (IW_AUTH_CIPHER_WEP40 |
910 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
911 sdata->u.sta.flags |=
912 IEEE80211_STA_TKIP_WEP_USED;
914 sdata->u.sta.flags &=
915 ~IEEE80211_STA_TKIP_WEP_USED;
918 case IW_AUTH_DROP_UNENCRYPTED:
919 sdata->drop_unencrypted = !!data->value;
921 case IW_AUTH_PRIVACY_INVOKED:
922 if (sdata->vif.type != NL80211_IFTYPE_STATION)
925 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
927 * Privacy invoked by wpa_supplicant, store the
928 * value and allow associating to a protected
929 * network without having a key up front.
932 sdata->u.sta.flags |=
933 IEEE80211_STA_PRIVACY_INVOKED;
936 case IW_AUTH_80211_AUTH_ALG:
937 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
938 sdata->vif.type == NL80211_IFTYPE_ADHOC)
939 sdata->u.sta.auth_algs = data->value;
944 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
948 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
949 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
950 switch (data->value) {
951 case IW_AUTH_MFP_DISABLED:
952 sdata->u.sta.mfp = IEEE80211_MFP_DISABLED;
954 case IW_AUTH_MFP_OPTIONAL:
955 sdata->u.sta.mfp = IEEE80211_MFP_OPTIONAL;
957 case IW_AUTH_MFP_REQUIRED:
958 sdata->u.sta.mfp = IEEE80211_MFP_REQUIRED;
973 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
974 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
976 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
977 struct iw_statistics *wstats = &local->wstats;
978 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
979 struct sta_info *sta = NULL;
983 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
984 sdata->vif.type == NL80211_IFTYPE_ADHOC)
985 sta = sta_info_get(local, sdata->u.sta.bssid);
987 wstats->discard.fragment = 0;
988 wstats->discard.misc = 0;
989 wstats->qual.qual = 0;
990 wstats->qual.level = 0;
991 wstats->qual.noise = 0;
992 wstats->qual.updated = IW_QUAL_ALL_INVALID;
994 wstats->qual.level = sta->last_signal;
995 wstats->qual.qual = sta->last_qual;
996 wstats->qual.noise = sta->last_noise;
997 wstats->qual.updated = ieee80211_get_wstats_flags(local);
1005 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1006 struct iw_request_info *info,
1007 struct iw_param *data, char *extra)
1009 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1012 switch (data->flags & IW_AUTH_INDEX) {
1013 case IW_AUTH_80211_AUTH_ALG:
1014 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1015 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1016 data->value = sdata->u.sta.auth_algs;
1028 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1029 struct iw_request_info *info,
1030 struct iw_point *erq, char *extra)
1032 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1033 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1034 int uninitialized_var(alg), idx, i, remove = 0;
1037 case IW_ENCODE_ALG_NONE:
1040 case IW_ENCODE_ALG_WEP:
1043 case IW_ENCODE_ALG_TKIP:
1046 case IW_ENCODE_ALG_CCMP:
1049 case IW_ENCODE_ALG_AES_CMAC:
1056 if (erq->flags & IW_ENCODE_DISABLED)
1059 idx = erq->flags & IW_ENCODE_INDEX;
1060 if (alg == ALG_AES_CMAC) {
1061 if (idx < NUM_DEFAULT_KEYS + 1 ||
1062 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1064 if (!sdata->default_mgmt_key)
1066 else for (i = NUM_DEFAULT_KEYS;
1067 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1069 if (sdata->default_mgmt_key == sdata->keys[i])
1080 if (idx < 1 || idx > 4) {
1082 if (!sdata->default_key)
1084 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1085 if (sdata->default_key == sdata->keys[i]) {
1096 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1099 IW_ENCODE_EXT_SET_TX_KEY,
1100 ext->key, ext->key_len);
1104 /* Structures to export the Wireless Handlers */
1106 static const iw_handler ieee80211_handler[] =
1108 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1109 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1110 (iw_handler) NULL, /* SIOCSIWNWID */
1111 (iw_handler) NULL, /* SIOCGIWNWID */
1112 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1113 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1114 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1115 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
1116 (iw_handler) NULL, /* SIOCSIWSENS */
1117 (iw_handler) NULL, /* SIOCGIWSENS */
1118 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1119 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1120 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1121 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1122 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1123 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1124 (iw_handler) NULL, /* SIOCSIWSPY */
1125 (iw_handler) NULL, /* SIOCGIWSPY */
1126 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1127 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1128 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1129 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1130 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1131 (iw_handler) NULL, /* SIOCGIWAPLIST */
1132 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1133 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
1134 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1135 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1136 (iw_handler) NULL, /* SIOCSIWNICKN */
1137 (iw_handler) NULL, /* SIOCGIWNICKN */
1138 (iw_handler) NULL, /* -- hole -- */
1139 (iw_handler) NULL, /* -- hole -- */
1140 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1141 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1142 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1143 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1144 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1145 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1146 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1147 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1148 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1149 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1150 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1151 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1152 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1153 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1154 (iw_handler) NULL, /* -- hole -- */
1155 (iw_handler) NULL, /* -- hole -- */
1156 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1157 (iw_handler) NULL, /* SIOCGIWGENIE */
1158 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1159 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1160 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1161 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1162 (iw_handler) NULL, /* SIOCSIWPMKSA */
1163 (iw_handler) NULL, /* -- hole -- */
1166 const struct iw_handler_def ieee80211_iw_handler_def =
1168 .num_standard = ARRAY_SIZE(ieee80211_handler),
1169 .standard = (iw_handler *) ieee80211_handler,
1170 .get_wireless_stats = ieee80211_get_wireless_stats,