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_siwmode(struct net_device *dev,
228 struct iw_request_info *info,
229 __u32 *mode, char *extra)
231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
232 struct ieee80211_local *local = sdata->local;
235 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
240 type = NL80211_IFTYPE_STATION;
243 /* Setting ad-hoc mode on non ibss channel is not
246 if (local->oper_channel &&
247 (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS))
250 type = NL80211_IFTYPE_ADHOC;
253 type = NL80211_IFTYPE_WDS;
255 case IW_MODE_MONITOR:
256 type = NL80211_IFTYPE_MONITOR;
262 return ieee80211_if_change_type(sdata, type);
266 static int ieee80211_ioctl_giwmode(struct net_device *dev,
267 struct iw_request_info *info,
268 __u32 *mode, char *extra)
270 struct ieee80211_sub_if_data *sdata;
272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
273 switch (sdata->vif.type) {
274 case NL80211_IFTYPE_AP:
275 *mode = IW_MODE_MASTER;
277 case NL80211_IFTYPE_STATION:
278 *mode = IW_MODE_INFRA;
280 case NL80211_IFTYPE_ADHOC:
281 *mode = IW_MODE_ADHOC;
283 case NL80211_IFTYPE_MONITOR:
284 *mode = IW_MODE_MONITOR;
286 case NL80211_IFTYPE_WDS:
287 *mode = IW_MODE_REPEAT;
289 case NL80211_IFTYPE_AP_VLAN:
290 *mode = IW_MODE_SECOND; /* FIXME */
293 *mode = IW_MODE_AUTO;
299 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
300 struct iw_request_info *info,
301 struct iw_freq *freq, char *extra)
303 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
305 if (sdata->vif.type == NL80211_IFTYPE_STATION)
306 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
308 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
311 if (sdata->vif.type == NL80211_IFTYPE_STATION)
312 sdata->u.sta.flags |=
313 IEEE80211_STA_AUTO_CHANNEL_SEL;
316 return ieee80211_set_freq(sdata,
317 ieee80211_channel_to_frequency(freq->m));
319 int i, div = 1000000;
320 for (i = 0; i < freq->e; i++)
323 return ieee80211_set_freq(sdata, freq->m / div);
330 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
331 struct iw_request_info *info,
332 struct iw_freq *freq, char *extra)
334 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
336 freq->m = local->hw.conf.channel->center_freq;
343 static int ieee80211_ioctl_siwessid(struct net_device *dev,
344 struct iw_request_info *info,
345 struct iw_point *data, char *ssid)
347 struct ieee80211_sub_if_data *sdata;
348 size_t len = data->length;
350 /* iwconfig uses nul termination in SSID.. */
351 if (len > 0 && ssid[len - 1] == '\0')
354 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
355 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
356 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
358 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
359 if (len > IEEE80211_MAX_SSID_LEN)
361 memcpy(sdata->u.sta.ssid, ssid, len);
362 sdata->u.sta.ssid_len = len;
366 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
368 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
369 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
372 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
380 static int ieee80211_ioctl_giwessid(struct net_device *dev,
381 struct iw_request_info *info,
382 struct iw_point *data, char *ssid)
386 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 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
403 static int ieee80211_ioctl_siwap(struct net_device *dev,
404 struct iw_request_info *info,
405 struct sockaddr *ap_addr, char *extra)
407 struct ieee80211_sub_if_data *sdata;
409 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
410 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
411 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
413 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
414 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
418 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
419 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
420 IEEE80211_STA_AUTO_CHANNEL_SEL;
421 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
422 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
424 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
425 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
428 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
430 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
432 * If it is necessary to update the WDS peer address
433 * while the interface is running, then we need to do
434 * more work here, namely if it is running we need to
435 * add a new and remove the old STA entry, this is
436 * normally handled by _open() and _stop().
438 if (netif_running(dev))
441 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
451 static int ieee80211_ioctl_giwap(struct net_device *dev,
452 struct iw_request_info *info,
453 struct sockaddr *ap_addr, char *extra)
455 struct ieee80211_sub_if_data *sdata;
457 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
458 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
459 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
460 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
461 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
462 ap_addr->sa_family = ARPHRD_ETHER;
463 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
466 memset(&ap_addr->sa_data, 0, ETH_ALEN);
469 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
470 ap_addr->sa_family = ARPHRD_ETHER;
471 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
479 static int ieee80211_ioctl_siwscan(struct net_device *dev,
480 struct iw_request_info *info,
481 union iwreq_data *wrqu, char *extra)
483 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
484 struct iw_scan_req *req = NULL;
488 if (!netif_running(dev))
491 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
492 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
493 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
494 sdata->vif.type != NL80211_IFTYPE_AP)
497 /* if SSID was specified explicitly then use that */
498 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
499 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
500 req = (struct iw_scan_req *)extra;
502 ssid_len = req->essid_len;
505 return ieee80211_request_scan(sdata, ssid, ssid_len);
509 static int ieee80211_ioctl_giwscan(struct net_device *dev,
510 struct iw_request_info *info,
511 struct iw_point *data, char *extra)
514 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
515 struct ieee80211_sub_if_data *sdata;
517 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
519 if (local->sw_scanning || local->hw_scanning)
522 res = ieee80211_scan_results(local, info, extra, data->length);
532 static int ieee80211_ioctl_siwrate(struct net_device *dev,
533 struct iw_request_info *info,
534 struct iw_param *rate, char *extra)
536 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
537 int i, err = -EINVAL;
538 u32 target_rate = rate->value / 100000;
539 struct ieee80211_sub_if_data *sdata;
540 struct ieee80211_supported_band *sband;
542 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
544 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
546 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
547 * target_rate = X, rate->fixed = 1 means only rate X
548 * target_rate = X, rate->fixed = 0 means all rates <= X */
549 sdata->max_ratectrl_rateidx = -1;
550 sdata->force_unicast_rateidx = -1;
554 for (i=0; i< sband->n_bitrates; i++) {
555 struct ieee80211_rate *brate = &sband->bitrates[i];
556 int this_rate = brate->bitrate;
558 if (target_rate == this_rate) {
559 sdata->max_ratectrl_rateidx = i;
561 sdata->force_unicast_rateidx = i;
569 static int ieee80211_ioctl_giwrate(struct net_device *dev,
570 struct iw_request_info *info,
571 struct iw_param *rate, char *extra)
573 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
574 struct sta_info *sta;
575 struct ieee80211_sub_if_data *sdata;
576 struct ieee80211_supported_band *sband;
578 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
580 if (sdata->vif.type != NL80211_IFTYPE_STATION)
583 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
587 sta = sta_info_get(local, sdata->u.sta.bssid);
589 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
590 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
599 rate->value *= 100000;
604 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
605 struct iw_request_info *info,
606 union iwreq_data *data, char *extra)
608 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
609 struct ieee80211_channel* chan = local->hw.conf.channel;
610 u32 reconf_flags = 0;
613 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
615 if (data->txpower.flags & IW_TXPOW_RANGE)
620 if (data->txpower.fixed)
621 new_power_level = min(data->txpower.value, chan->max_power);
622 else /* Automatic power level setting */
623 new_power_level = chan->max_power;
625 if (local->hw.conf.power_level != new_power_level) {
626 local->hw.conf.power_level = new_power_level;
627 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
630 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
631 local->hw.conf.radio_enabled = !(data->txpower.disabled);
632 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
633 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
637 ieee80211_hw_config(local, reconf_flags);
642 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
643 struct iw_request_info *info,
644 union iwreq_data *data, char *extra)
646 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
648 data->txpower.fixed = 1;
649 data->txpower.disabled = !(local->hw.conf.radio_enabled);
650 data->txpower.value = local->hw.conf.power_level;
651 data->txpower.flags = IW_TXPOW_DBM;
656 static int ieee80211_ioctl_siwrts(struct net_device *dev,
657 struct iw_request_info *info,
658 struct iw_param *rts, char *extra)
660 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
663 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
664 else if (!rts->fixed)
665 /* if the rts value is not fixed, then take default */
666 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
667 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
670 local->rts_threshold = rts->value;
672 /* If the wlan card performs RTS/CTS in hardware/firmware,
673 * configure it here */
675 if (local->ops->set_rts_threshold)
676 local->ops->set_rts_threshold(local_to_hw(local),
677 local->rts_threshold);
682 static int ieee80211_ioctl_giwrts(struct net_device *dev,
683 struct iw_request_info *info,
684 struct iw_param *rts, char *extra)
686 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
688 rts->value = local->rts_threshold;
689 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
696 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
697 struct iw_request_info *info,
698 struct iw_param *frag, char *extra)
700 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
703 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
704 else if (!frag->fixed)
705 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
706 else if (frag->value < 256 ||
707 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
710 /* Fragment length must be even, so strip LSB. */
711 local->fragmentation_threshold = frag->value & ~0x1;
714 /* If the wlan card performs fragmentation in hardware/firmware,
715 * configure it here */
717 if (local->ops->set_frag_threshold)
718 return local->ops->set_frag_threshold(
720 local->fragmentation_threshold);
725 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
726 struct iw_request_info *info,
727 struct iw_param *frag, char *extra)
729 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
731 frag->value = local->fragmentation_threshold;
732 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
739 static int ieee80211_ioctl_siwretry(struct net_device *dev,
740 struct iw_request_info *info,
741 struct iw_param *retry, char *extra)
743 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
745 if (retry->disabled ||
746 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
749 if (retry->flags & IW_RETRY_MAX) {
750 local->hw.conf.long_frame_max_tx_count = retry->value;
751 } else if (retry->flags & IW_RETRY_MIN) {
752 local->hw.conf.short_frame_max_tx_count = retry->value;
754 local->hw.conf.long_frame_max_tx_count = retry->value;
755 local->hw.conf.short_frame_max_tx_count = retry->value;
758 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
764 static int ieee80211_ioctl_giwretry(struct net_device *dev,
765 struct iw_request_info *info,
766 struct iw_param *retry, char *extra)
768 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
771 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
772 /* first return min value, iwconfig will ask max value
774 retry->flags |= IW_RETRY_LIMIT;
775 retry->value = local->hw.conf.short_frame_max_tx_count;
776 if (local->hw.conf.long_frame_max_tx_count !=
777 local->hw.conf.short_frame_max_tx_count)
778 retry->flags |= IW_RETRY_MIN;
781 if (retry->flags & IW_RETRY_MAX) {
782 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
783 retry->value = local->hw.conf.long_frame_max_tx_count;
789 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
790 struct iw_request_info *info,
791 struct iw_point *data, char *extra)
793 struct ieee80211_sub_if_data *sdata;
794 struct iw_mlme *mlme = (struct iw_mlme *) extra;
796 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
797 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
798 sdata->vif.type != NL80211_IFTYPE_ADHOC)
803 /* TODO: mlme->addr.sa_data */
804 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
805 case IW_MLME_DISASSOC:
806 /* TODO: mlme->addr.sa_data */
807 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
814 static int ieee80211_ioctl_siwencode(struct net_device *dev,
815 struct iw_request_info *info,
816 struct iw_point *erq, char *keybuf)
818 struct ieee80211_sub_if_data *sdata;
819 int idx, i, alg = ALG_WEP;
820 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
823 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
825 idx = erq->flags & IW_ENCODE_INDEX;
827 if (sdata->default_key)
828 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
829 if (sdata->default_key == sdata->keys[i]) {
834 } else if (idx < 1 || idx > 4)
839 if (erq->flags & IW_ENCODE_DISABLED)
841 else if (erq->length == 0) {
842 /* No key data - just set the default TX key index */
843 ieee80211_set_default_key(sdata, idx);
847 return ieee80211_set_encryption(
851 keybuf, erq->length);
855 static int ieee80211_ioctl_giwencode(struct net_device *dev,
856 struct iw_request_info *info,
857 struct iw_point *erq, char *key)
859 struct ieee80211_sub_if_data *sdata;
862 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
864 idx = erq->flags & IW_ENCODE_INDEX;
865 if (idx < 1 || idx > 4) {
867 if (!sdata->default_key)
869 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
870 if (sdata->default_key == sdata->keys[i]) {
880 erq->flags = idx + 1;
882 if (!sdata->keys[idx]) {
884 erq->flags |= IW_ENCODE_DISABLED;
888 memcpy(key, sdata->keys[idx]->conf.key,
889 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
890 erq->length = sdata->keys[idx]->conf.keylen;
891 erq->flags |= IW_ENCODE_ENABLED;
893 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
894 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
895 switch (ifsta->auth_alg) {
898 erq->flags |= IW_ENCODE_OPEN;
900 case WLAN_AUTH_SHARED_KEY:
901 erq->flags |= IW_ENCODE_RESTRICTED;
909 static int ieee80211_ioctl_siwpower(struct net_device *dev,
910 struct iw_request_info *info,
911 struct iw_param *wrq,
914 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
915 struct ieee80211_conf *conf = &local->hw.conf;
918 conf->flags &= ~IEEE80211_CONF_PS;
919 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
922 switch (wrq->flags & IW_POWER_MODE) {
923 case IW_POWER_ON: /* If not specified */
924 case IW_POWER_MODE: /* If set all mask */
925 case IW_POWER_ALL_R: /* If explicitely state all */
926 conf->flags |= IEEE80211_CONF_PS;
928 default: /* Otherwise we don't support it */
932 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
935 static int ieee80211_ioctl_giwpower(struct net_device *dev,
936 struct iw_request_info *info,
937 union iwreq_data *wrqu,
940 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
941 struct ieee80211_conf *conf = &local->hw.conf;
943 wrqu->power.disabled = !(conf->flags & IEEE80211_CONF_PS);
948 static int ieee80211_ioctl_siwauth(struct net_device *dev,
949 struct iw_request_info *info,
950 struct iw_param *data, char *extra)
952 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
955 switch (data->flags & IW_AUTH_INDEX) {
956 case IW_AUTH_WPA_VERSION:
957 case IW_AUTH_CIPHER_PAIRWISE:
958 case IW_AUTH_CIPHER_GROUP:
959 case IW_AUTH_WPA_ENABLED:
960 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
961 case IW_AUTH_KEY_MGMT:
963 case IW_AUTH_DROP_UNENCRYPTED:
964 sdata->drop_unencrypted = !!data->value;
966 case IW_AUTH_PRIVACY_INVOKED:
967 if (sdata->vif.type != NL80211_IFTYPE_STATION)
970 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
972 * Privacy invoked by wpa_supplicant, store the
973 * value and allow associating to a protected
974 * network without having a key up front.
977 sdata->u.sta.flags |=
978 IEEE80211_STA_PRIVACY_INVOKED;
981 case IW_AUTH_80211_AUTH_ALG:
982 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
983 sdata->vif.type == NL80211_IFTYPE_ADHOC)
984 sdata->u.sta.auth_algs = data->value;
995 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
996 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
998 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
999 struct iw_statistics *wstats = &local->wstats;
1000 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1001 struct sta_info *sta = NULL;
1005 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1006 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1007 sta = sta_info_get(local, sdata->u.sta.bssid);
1009 wstats->discard.fragment = 0;
1010 wstats->discard.misc = 0;
1011 wstats->qual.qual = 0;
1012 wstats->qual.level = 0;
1013 wstats->qual.noise = 0;
1014 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1016 wstats->qual.level = sta->last_signal;
1017 wstats->qual.qual = sta->last_qual;
1018 wstats->qual.noise = sta->last_noise;
1019 wstats->qual.updated = local->wstats_flags;
1027 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1028 struct iw_request_info *info,
1029 struct iw_param *data, char *extra)
1031 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1034 switch (data->flags & IW_AUTH_INDEX) {
1035 case IW_AUTH_80211_AUTH_ALG:
1036 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1037 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1038 data->value = sdata->u.sta.auth_algs;
1050 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1051 struct iw_request_info *info,
1052 struct iw_point *erq, char *extra)
1054 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1055 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1056 int uninitialized_var(alg), idx, i, remove = 0;
1059 case IW_ENCODE_ALG_NONE:
1062 case IW_ENCODE_ALG_WEP:
1065 case IW_ENCODE_ALG_TKIP:
1068 case IW_ENCODE_ALG_CCMP:
1075 if (erq->flags & IW_ENCODE_DISABLED)
1078 idx = erq->flags & IW_ENCODE_INDEX;
1079 if (idx < 1 || idx > 4) {
1081 if (!sdata->default_key)
1083 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1084 if (sdata->default_key == sdata->keys[i]) {
1094 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1097 IW_ENCODE_EXT_SET_TX_KEY,
1098 ext->key, ext->key_len);
1102 /* Structures to export the Wireless Handlers */
1104 static const iw_handler ieee80211_handler[] =
1106 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1107 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1108 (iw_handler) NULL, /* SIOCSIWNWID */
1109 (iw_handler) NULL, /* SIOCGIWNWID */
1110 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1111 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1112 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1113 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1114 (iw_handler) NULL, /* SIOCSIWSENS */
1115 (iw_handler) NULL, /* SIOCGIWSENS */
1116 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1117 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1118 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1119 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1120 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1121 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1122 (iw_handler) NULL, /* SIOCSIWSPY */
1123 (iw_handler) NULL, /* SIOCGIWSPY */
1124 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1125 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1126 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1127 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1128 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1129 (iw_handler) NULL, /* SIOCGIWAPLIST */
1130 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1131 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1132 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1133 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1134 (iw_handler) NULL, /* SIOCSIWNICKN */
1135 (iw_handler) NULL, /* SIOCGIWNICKN */
1136 (iw_handler) NULL, /* -- hole -- */
1137 (iw_handler) NULL, /* -- hole -- */
1138 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1139 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1140 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1141 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1142 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1143 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1144 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1145 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1146 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1147 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1148 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1149 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1150 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1151 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1152 (iw_handler) NULL, /* -- hole -- */
1153 (iw_handler) NULL, /* -- hole -- */
1154 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1155 (iw_handler) NULL, /* SIOCGIWGENIE */
1156 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1157 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1158 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1159 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1160 (iw_handler) NULL, /* SIOCSIWPMKSA */
1161 (iw_handler) NULL, /* -- hole -- */
1164 const struct iw_handler_def ieee80211_iw_handler_def =
1166 .num_standard = ARRAY_SIZE(ieee80211_handler),
1167 .standard = (iw_handler *) ieee80211_handler,
1168 .get_wireless_stats = ieee80211_get_wireless_stats,