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 int ieee80211_ioctl_giwrange(struct net_device *dev,
149 struct iw_request_info *info,
150 struct iw_point *data, char *extra)
152 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
153 struct iw_range *range = (struct iw_range *) extra;
154 enum ieee80211_band band;
157 data->length = sizeof(struct iw_range);
158 memset(range, 0, sizeof(struct iw_range));
160 range->we_version_compiled = WIRELESS_EXT;
161 range->we_version_source = 21;
162 range->retry_capa = IW_RETRY_LIMIT;
163 range->retry_flags = IW_RETRY_LIMIT;
164 range->min_retry = 0;
165 range->max_retry = 255;
167 range->max_rts = 2347;
168 range->min_frag = 256;
169 range->max_frag = 2346;
171 range->encoding_size[0] = 5;
172 range->encoding_size[1] = 13;
173 range->num_encoding_sizes = 2;
174 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
176 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
177 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
178 range->max_qual.level = local->hw.max_signal;
179 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
180 range->max_qual.level = -110;
182 range->max_qual.level = 0;
184 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
185 range->max_qual.noise = -110;
187 range->max_qual.noise = 0;
189 range->max_qual.qual = 100;
190 range->max_qual.updated = local->wstats_flags;
192 range->avg_qual.qual = 50;
193 /* not always true but better than nothing */
194 range->avg_qual.level = range->max_qual.level / 2;
195 range->avg_qual.noise = range->max_qual.noise / 2;
196 range->avg_qual.updated = local->wstats_flags;
198 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
199 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
202 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
204 struct ieee80211_supported_band *sband;
206 sband = local->hw.wiphy->bands[band];
211 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
212 struct ieee80211_channel *chan = &sband->channels[i];
214 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
216 ieee80211_frequency_to_channel(
218 range->freq[c].m = chan->center_freq;
219 range->freq[c].e = 6;
224 range->num_channels = c;
225 range->num_frequency = c;
227 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
228 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
229 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
231 range->scan_capa |= IW_SCAN_CAPA_ESSID;
237 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
238 struct iw_request_info *info,
239 struct iw_freq *freq, char *extra)
241 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
243 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
244 sdata->vif.type == NL80211_IFTYPE_STATION)
245 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
247 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
250 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
251 sdata->vif.type == NL80211_IFTYPE_STATION)
252 sdata->u.sta.flags |=
253 IEEE80211_STA_AUTO_CHANNEL_SEL;
256 return ieee80211_set_freq(sdata,
257 ieee80211_channel_to_frequency(freq->m));
259 int i, div = 1000000;
260 for (i = 0; i < freq->e; i++)
263 return ieee80211_set_freq(sdata, freq->m / div);
270 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
271 struct iw_request_info *info,
272 struct iw_freq *freq, char *extra)
274 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
276 freq->m = local->hw.conf.channel->center_freq;
283 static int ieee80211_ioctl_siwessid(struct net_device *dev,
284 struct iw_request_info *info,
285 struct iw_point *data, char *ssid)
287 struct ieee80211_sub_if_data *sdata;
288 size_t len = data->length;
290 /* iwconfig uses nul termination in SSID.. */
291 if (len > 0 && ssid[len - 1] == '\0')
294 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
295 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
296 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
298 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
299 if (len > IEEE80211_MAX_SSID_LEN)
301 memcpy(sdata->u.sta.ssid, ssid, len);
302 sdata->u.sta.ssid_len = len;
306 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
308 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
309 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
312 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
320 static int ieee80211_ioctl_giwessid(struct net_device *dev,
321 struct iw_request_info *info,
322 struct iw_point *data, char *ssid)
326 struct ieee80211_sub_if_data *sdata;
327 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
328 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
329 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
330 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
343 static int ieee80211_ioctl_siwap(struct net_device *dev,
344 struct iw_request_info *info,
345 struct sockaddr *ap_addr, char *extra)
347 struct ieee80211_sub_if_data *sdata;
349 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
350 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
351 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
353 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
354 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
358 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
359 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
360 IEEE80211_STA_AUTO_CHANNEL_SEL;
361 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
362 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
364 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
365 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
368 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
370 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
372 * If it is necessary to update the WDS peer address
373 * while the interface is running, then we need to do
374 * more work here, namely if it is running we need to
375 * add a new and remove the old STA entry, this is
376 * normally handled by _open() and _stop().
378 if (netif_running(dev))
381 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
391 static int ieee80211_ioctl_giwap(struct net_device *dev,
392 struct iw_request_info *info,
393 struct sockaddr *ap_addr, char *extra)
395 struct ieee80211_sub_if_data *sdata;
397 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
398 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
399 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
400 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
401 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
402 ap_addr->sa_family = ARPHRD_ETHER;
403 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
406 memset(&ap_addr->sa_data, 0, ETH_ALEN);
409 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
410 ap_addr->sa_family = ARPHRD_ETHER;
411 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
419 static int ieee80211_ioctl_siwscan(struct net_device *dev,
420 struct iw_request_info *info,
421 union iwreq_data *wrqu, char *extra)
423 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
424 struct iw_scan_req *req = NULL;
428 if (!netif_running(dev))
431 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
432 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
433 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
436 /* if SSID was specified explicitly then use that */
437 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
438 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
439 req = (struct iw_scan_req *)extra;
441 ssid_len = req->essid_len;
444 return ieee80211_request_scan(sdata, ssid, ssid_len);
448 static int ieee80211_ioctl_giwscan(struct net_device *dev,
449 struct iw_request_info *info,
450 struct iw_point *data, 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);
458 if (local->sw_scanning || local->hw_scanning)
461 res = ieee80211_scan_results(local, info, extra, data->length);
471 static int ieee80211_ioctl_siwrate(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 int i, err = -EINVAL;
477 u32 target_rate = rate->value / 100000;
478 struct ieee80211_sub_if_data *sdata;
479 struct ieee80211_supported_band *sband;
481 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
483 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
485 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
486 * target_rate = X, rate->fixed = 1 means only rate X
487 * target_rate = X, rate->fixed = 0 means all rates <= X */
488 sdata->max_ratectrl_rateidx = -1;
489 sdata->force_unicast_rateidx = -1;
493 for (i=0; i< sband->n_bitrates; i++) {
494 struct ieee80211_rate *brate = &sband->bitrates[i];
495 int this_rate = brate->bitrate;
497 if (target_rate == this_rate) {
498 sdata->max_ratectrl_rateidx = i;
500 sdata->force_unicast_rateidx = i;
508 static int ieee80211_ioctl_giwrate(struct net_device *dev,
509 struct iw_request_info *info,
510 struct iw_param *rate, char *extra)
512 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
513 struct sta_info *sta;
514 struct ieee80211_sub_if_data *sdata;
515 struct ieee80211_supported_band *sband;
517 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
519 if (sdata->vif.type != NL80211_IFTYPE_STATION)
522 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
526 sta = sta_info_get(local, sdata->u.sta.bssid);
528 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
529 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
538 rate->value *= 100000;
543 static int ieee80211_ioctl_siwtxpower(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);
548 struct ieee80211_channel* chan = local->hw.conf.channel;
549 u32 reconf_flags = 0;
552 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
554 if (data->txpower.flags & IW_TXPOW_RANGE)
559 if (data->txpower.fixed)
560 new_power_level = min(data->txpower.value, chan->max_power);
561 else /* Automatic power level setting */
562 new_power_level = chan->max_power;
564 local->user_power_level = new_power_level;
565 if (local->hw.conf.power_level != new_power_level)
566 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
568 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
569 local->hw.conf.radio_enabled = !(data->txpower.disabled);
570 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
571 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
575 ieee80211_hw_config(local, reconf_flags);
580 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
581 struct iw_request_info *info,
582 union iwreq_data *data, char *extra)
584 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
586 data->txpower.fixed = 1;
587 data->txpower.disabled = !(local->hw.conf.radio_enabled);
588 data->txpower.value = local->hw.conf.power_level;
589 data->txpower.flags = IW_TXPOW_DBM;
594 static int ieee80211_ioctl_siwrts(struct net_device *dev,
595 struct iw_request_info *info,
596 struct iw_param *rts, char *extra)
598 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
601 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
602 else if (!rts->fixed)
603 /* if the rts value is not fixed, then take default */
604 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
605 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
608 local->rts_threshold = rts->value;
610 /* If the wlan card performs RTS/CTS in hardware/firmware,
611 * configure it here */
613 if (local->ops->set_rts_threshold)
614 local->ops->set_rts_threshold(local_to_hw(local),
615 local->rts_threshold);
620 static int ieee80211_ioctl_giwrts(struct net_device *dev,
621 struct iw_request_info *info,
622 struct iw_param *rts, char *extra)
624 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
626 rts->value = local->rts_threshold;
627 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
634 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
635 struct iw_request_info *info,
636 struct iw_param *frag, char *extra)
638 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
641 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
642 else if (!frag->fixed)
643 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
644 else if (frag->value < 256 ||
645 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
648 /* Fragment length must be even, so strip LSB. */
649 local->fragmentation_threshold = frag->value & ~0x1;
655 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
656 struct iw_request_info *info,
657 struct iw_param *frag, char *extra)
659 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
661 frag->value = local->fragmentation_threshold;
662 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
669 static int ieee80211_ioctl_siwretry(struct net_device *dev,
670 struct iw_request_info *info,
671 struct iw_param *retry, char *extra)
673 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
675 if (retry->disabled ||
676 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
679 if (retry->flags & IW_RETRY_MAX) {
680 local->hw.conf.long_frame_max_tx_count = retry->value;
681 } else if (retry->flags & IW_RETRY_MIN) {
682 local->hw.conf.short_frame_max_tx_count = retry->value;
684 local->hw.conf.long_frame_max_tx_count = retry->value;
685 local->hw.conf.short_frame_max_tx_count = retry->value;
688 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
694 static int ieee80211_ioctl_giwretry(struct net_device *dev,
695 struct iw_request_info *info,
696 struct iw_param *retry, char *extra)
698 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
701 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
702 /* first return min value, iwconfig will ask max value
704 retry->flags |= IW_RETRY_LIMIT;
705 retry->value = local->hw.conf.short_frame_max_tx_count;
706 if (local->hw.conf.long_frame_max_tx_count !=
707 local->hw.conf.short_frame_max_tx_count)
708 retry->flags |= IW_RETRY_MIN;
711 if (retry->flags & IW_RETRY_MAX) {
712 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
713 retry->value = local->hw.conf.long_frame_max_tx_count;
719 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
720 struct iw_request_info *info,
721 struct iw_point *data, char *extra)
723 struct ieee80211_sub_if_data *sdata;
724 struct iw_mlme *mlme = (struct iw_mlme *) extra;
726 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
727 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
728 sdata->vif.type != NL80211_IFTYPE_ADHOC)
733 /* TODO: mlme->addr.sa_data */
734 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
735 case IW_MLME_DISASSOC:
736 /* TODO: mlme->addr.sa_data */
737 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
744 static int ieee80211_ioctl_siwencode(struct net_device *dev,
745 struct iw_request_info *info,
746 struct iw_point *erq, char *keybuf)
748 struct ieee80211_sub_if_data *sdata;
749 int idx, i, alg = ALG_WEP;
750 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
753 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
755 idx = erq->flags & IW_ENCODE_INDEX;
757 if (sdata->default_key)
758 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
759 if (sdata->default_key == sdata->keys[i]) {
764 } else if (idx < 1 || idx > 4)
769 if (erq->flags & IW_ENCODE_DISABLED)
771 else if (erq->length == 0) {
772 /* No key data - just set the default TX key index */
773 ieee80211_set_default_key(sdata, idx);
777 return ieee80211_set_encryption(
781 keybuf, erq->length);
785 static int ieee80211_ioctl_giwencode(struct net_device *dev,
786 struct iw_request_info *info,
787 struct iw_point *erq, char *key)
789 struct ieee80211_sub_if_data *sdata;
792 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
794 idx = erq->flags & IW_ENCODE_INDEX;
795 if (idx < 1 || idx > 4) {
797 if (!sdata->default_key)
799 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
800 if (sdata->default_key == sdata->keys[i]) {
810 erq->flags = idx + 1;
812 if (!sdata->keys[idx]) {
814 erq->flags |= IW_ENCODE_DISABLED;
818 memcpy(key, sdata->keys[idx]->conf.key,
819 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
820 erq->length = sdata->keys[idx]->conf.keylen;
821 erq->flags |= IW_ENCODE_ENABLED;
823 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
824 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
825 switch (ifsta->auth_alg) {
828 erq->flags |= IW_ENCODE_OPEN;
830 case WLAN_AUTH_SHARED_KEY:
831 erq->flags |= IW_ENCODE_RESTRICTED;
839 static int ieee80211_ioctl_siwpower(struct net_device *dev,
840 struct iw_request_info *info,
841 struct iw_param *wrq,
844 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
845 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
846 struct ieee80211_conf *conf = &local->hw.conf;
847 int ret = 0, timeout = 0;
850 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
853 if (sdata->vif.type != NL80211_IFTYPE_STATION)
862 switch (wrq->flags & IW_POWER_MODE) {
863 case IW_POWER_ON: /* If not specified */
864 case IW_POWER_MODE: /* If set all mask */
865 case IW_POWER_ALL_R: /* If explicitely state all */
868 default: /* Otherwise we ignore */
872 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
875 if (wrq->flags & IW_POWER_TIMEOUT)
876 timeout = wrq->value / 1000;
879 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
882 local->powersave = ps;
883 conf->dynamic_ps_timeout = timeout;
885 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
886 ret = ieee80211_hw_config(local,
887 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
889 if (!(sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
892 if (conf->dynamic_ps_timeout > 0 &&
893 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
894 mod_timer(&local->dynamic_ps_timer, jiffies +
895 msecs_to_jiffies(conf->dynamic_ps_timeout));
897 if (local->powersave) {
898 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
899 ieee80211_send_nullfunc(local, sdata, 1);
900 conf->flags |= IEEE80211_CONF_PS;
901 ret = ieee80211_hw_config(local,
902 IEEE80211_CONF_CHANGE_PS);
904 conf->flags &= ~IEEE80211_CONF_PS;
905 ret = ieee80211_hw_config(local,
906 IEEE80211_CONF_CHANGE_PS);
907 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
908 ieee80211_send_nullfunc(local, sdata, 0);
915 static int ieee80211_ioctl_giwpower(struct net_device *dev,
916 struct iw_request_info *info,
917 union iwreq_data *wrqu,
920 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
922 wrqu->power.disabled = !local->powersave;
927 static int ieee80211_ioctl_siwauth(struct net_device *dev,
928 struct iw_request_info *info,
929 struct iw_param *data, char *extra)
931 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
934 switch (data->flags & IW_AUTH_INDEX) {
935 case IW_AUTH_WPA_VERSION:
936 case IW_AUTH_CIPHER_GROUP:
937 case IW_AUTH_WPA_ENABLED:
938 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
939 case IW_AUTH_KEY_MGMT:
940 case IW_AUTH_CIPHER_GROUP_MGMT:
942 case IW_AUTH_CIPHER_PAIRWISE:
943 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
944 if (data->value & (IW_AUTH_CIPHER_WEP40 |
945 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
946 sdata->u.sta.flags |=
947 IEEE80211_STA_TKIP_WEP_USED;
949 sdata->u.sta.flags &=
950 ~IEEE80211_STA_TKIP_WEP_USED;
953 case IW_AUTH_DROP_UNENCRYPTED:
954 sdata->drop_unencrypted = !!data->value;
956 case IW_AUTH_PRIVACY_INVOKED:
957 if (sdata->vif.type != NL80211_IFTYPE_STATION)
960 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
962 * Privacy invoked by wpa_supplicant, store the
963 * value and allow associating to a protected
964 * network without having a key up front.
967 sdata->u.sta.flags |=
968 IEEE80211_STA_PRIVACY_INVOKED;
971 case IW_AUTH_80211_AUTH_ALG:
972 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
973 sdata->vif.type == NL80211_IFTYPE_ADHOC)
974 sdata->u.sta.auth_algs = data->value;
979 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
983 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
984 sdata->vif.type == NL80211_IFTYPE_ADHOC)
985 sdata->u.sta.mfp = data->value;
996 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
997 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
999 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1000 struct iw_statistics *wstats = &local->wstats;
1001 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1002 struct sta_info *sta = NULL;
1006 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1007 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1008 sta = sta_info_get(local, sdata->u.sta.bssid);
1010 wstats->discard.fragment = 0;
1011 wstats->discard.misc = 0;
1012 wstats->qual.qual = 0;
1013 wstats->qual.level = 0;
1014 wstats->qual.noise = 0;
1015 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1017 wstats->qual.level = sta->last_signal;
1018 wstats->qual.qual = sta->last_qual;
1019 wstats->qual.noise = sta->last_noise;
1020 wstats->qual.updated = local->wstats_flags;
1028 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1029 struct iw_request_info *info,
1030 struct iw_param *data, char *extra)
1032 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1035 switch (data->flags & IW_AUTH_INDEX) {
1036 case IW_AUTH_80211_AUTH_ALG:
1037 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1038 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1039 data->value = sdata->u.sta.auth_algs;
1051 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1052 struct iw_request_info *info,
1053 struct iw_point *erq, char *extra)
1055 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1056 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1057 int uninitialized_var(alg), idx, i, remove = 0;
1060 case IW_ENCODE_ALG_NONE:
1063 case IW_ENCODE_ALG_WEP:
1066 case IW_ENCODE_ALG_TKIP:
1069 case IW_ENCODE_ALG_CCMP:
1072 case IW_ENCODE_ALG_AES_CMAC:
1079 if (erq->flags & IW_ENCODE_DISABLED)
1082 idx = erq->flags & IW_ENCODE_INDEX;
1083 if (alg == ALG_AES_CMAC) {
1084 if (idx < NUM_DEFAULT_KEYS + 1 ||
1085 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1087 if (!sdata->default_mgmt_key)
1089 else for (i = NUM_DEFAULT_KEYS;
1090 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1092 if (sdata->default_mgmt_key == sdata->keys[i])
1103 if (idx < 1 || idx > 4) {
1105 if (!sdata->default_key)
1107 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1108 if (sdata->default_key == sdata->keys[i]) {
1119 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1122 IW_ENCODE_EXT_SET_TX_KEY,
1123 ext->key, ext->key_len);
1127 /* Structures to export the Wireless Handlers */
1129 static const iw_handler ieee80211_handler[] =
1131 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1132 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1133 (iw_handler) NULL, /* SIOCSIWNWID */
1134 (iw_handler) NULL, /* SIOCGIWNWID */
1135 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1136 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1137 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1138 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
1139 (iw_handler) NULL, /* SIOCSIWSENS */
1140 (iw_handler) NULL, /* SIOCGIWSENS */
1141 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1142 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1143 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1144 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1145 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1146 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1147 (iw_handler) NULL, /* SIOCSIWSPY */
1148 (iw_handler) NULL, /* SIOCGIWSPY */
1149 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1150 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1151 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1152 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1153 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1154 (iw_handler) NULL, /* SIOCGIWAPLIST */
1155 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1156 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1157 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1158 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1159 (iw_handler) NULL, /* SIOCSIWNICKN */
1160 (iw_handler) NULL, /* SIOCGIWNICKN */
1161 (iw_handler) NULL, /* -- hole -- */
1162 (iw_handler) NULL, /* -- hole -- */
1163 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1164 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1165 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1166 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1167 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1168 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1169 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1170 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1171 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1172 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1173 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1174 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1175 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1176 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1177 (iw_handler) NULL, /* -- hole -- */
1178 (iw_handler) NULL, /* -- hole -- */
1179 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1180 (iw_handler) NULL, /* SIOCGIWGENIE */
1181 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1182 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1183 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1184 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1185 (iw_handler) NULL, /* SIOCSIWPMKSA */
1186 (iw_handler) NULL, /* -- hole -- */
1189 const struct iw_handler_def ieee80211_iw_handler_def =
1191 .num_standard = ARRAY_SIZE(ieee80211_handler),
1192 .standard = (iw_handler *) ieee80211_handler,
1193 .get_wireless_stats = ieee80211_get_wireless_stats,