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_giwname(struct net_device *dev,
139 struct iw_request_info *info,
140 char *name, char *extra)
142 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
143 struct ieee80211_supported_band *sband;
144 u8 is_ht = 0, is_a = 0, is_b = 0, is_g = 0;
147 sband = local->hw.wiphy->bands[IEEE80211_BAND_5GHZ];
150 is_ht |= sband->ht_cap.ht_supported;
153 sband = local->hw.wiphy->bands[IEEE80211_BAND_2GHZ];
156 /* Check for mandatory rates */
157 for (i = 0; i < sband->n_bitrates; i++) {
158 if (sband->bitrates[i].bitrate == 10)
160 if (sband->bitrates[i].bitrate == 60)
163 is_ht |= sband->ht_cap.ht_supported;
166 strcpy(name, "IEEE 802.11");
180 static int ieee80211_ioctl_giwrange(struct net_device *dev,
181 struct iw_request_info *info,
182 struct iw_point *data, char *extra)
184 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
185 struct iw_range *range = (struct iw_range *) extra;
186 enum ieee80211_band band;
189 data->length = sizeof(struct iw_range);
190 memset(range, 0, sizeof(struct iw_range));
192 range->we_version_compiled = WIRELESS_EXT;
193 range->we_version_source = 21;
194 range->retry_capa = IW_RETRY_LIMIT;
195 range->retry_flags = IW_RETRY_LIMIT;
196 range->min_retry = 0;
197 range->max_retry = 255;
199 range->max_rts = 2347;
200 range->min_frag = 256;
201 range->max_frag = 2346;
203 range->encoding_size[0] = 5;
204 range->encoding_size[1] = 13;
205 range->num_encoding_sizes = 2;
206 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
208 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
209 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
210 range->max_qual.level = local->hw.max_signal;
211 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
212 range->max_qual.level = -110;
214 range->max_qual.level = 0;
216 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
217 range->max_qual.noise = -110;
219 range->max_qual.noise = 0;
221 range->max_qual.qual = 100;
222 range->max_qual.updated = local->wstats_flags;
224 range->avg_qual.qual = 50;
225 /* not always true but better than nothing */
226 range->avg_qual.level = range->max_qual.level / 2;
227 range->avg_qual.noise = range->max_qual.noise / 2;
228 range->avg_qual.updated = local->wstats_flags;
230 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
231 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
234 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
236 struct ieee80211_supported_band *sband;
238 sband = local->hw.wiphy->bands[band];
243 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
244 struct ieee80211_channel *chan = &sband->channels[i];
246 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
248 ieee80211_frequency_to_channel(
250 range->freq[c].m = chan->center_freq;
251 range->freq[c].e = 6;
256 range->num_channels = c;
257 range->num_frequency = c;
259 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
260 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
261 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
263 range->scan_capa |= IW_SCAN_CAPA_ESSID;
269 static int ieee80211_ioctl_siwmode(struct net_device *dev,
270 struct iw_request_info *info,
271 __u32 *mode, char *extra)
273 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
274 struct ieee80211_local *local = sdata->local;
277 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
282 type = NL80211_IFTYPE_STATION;
285 /* Setting ad-hoc mode on non ibss channel is not
288 if (local->oper_channel &&
289 (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS))
292 type = NL80211_IFTYPE_ADHOC;
295 type = NL80211_IFTYPE_WDS;
297 case IW_MODE_MONITOR:
298 type = NL80211_IFTYPE_MONITOR;
304 return ieee80211_if_change_type(sdata, type);
308 static int ieee80211_ioctl_giwmode(struct net_device *dev,
309 struct iw_request_info *info,
310 __u32 *mode, char *extra)
312 struct ieee80211_sub_if_data *sdata;
314 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
315 switch (sdata->vif.type) {
316 case NL80211_IFTYPE_AP:
317 *mode = IW_MODE_MASTER;
319 case NL80211_IFTYPE_STATION:
320 *mode = IW_MODE_INFRA;
322 case NL80211_IFTYPE_ADHOC:
323 *mode = IW_MODE_ADHOC;
325 case NL80211_IFTYPE_MONITOR:
326 *mode = IW_MODE_MONITOR;
328 case NL80211_IFTYPE_WDS:
329 *mode = IW_MODE_REPEAT;
331 case NL80211_IFTYPE_AP_VLAN:
332 *mode = IW_MODE_SECOND; /* FIXME */
335 *mode = IW_MODE_AUTO;
341 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
342 struct iw_request_info *info,
343 struct iw_freq *freq, char *extra)
345 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
347 if (sdata->vif.type == NL80211_IFTYPE_STATION)
348 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
350 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
353 if (sdata->vif.type == NL80211_IFTYPE_STATION)
354 sdata->u.sta.flags |=
355 IEEE80211_STA_AUTO_CHANNEL_SEL;
358 return ieee80211_set_freq(sdata,
359 ieee80211_channel_to_frequency(freq->m));
361 int i, div = 1000000;
362 for (i = 0; i < freq->e; i++)
365 return ieee80211_set_freq(sdata, freq->m / div);
372 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_freq *freq, char *extra)
376 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
378 freq->m = local->hw.conf.channel->center_freq;
385 static int ieee80211_ioctl_siwessid(struct net_device *dev,
386 struct iw_request_info *info,
387 struct iw_point *data, char *ssid)
389 struct ieee80211_sub_if_data *sdata;
390 size_t len = data->length;
392 /* iwconfig uses nul termination in SSID.. */
393 if (len > 0 && ssid[len - 1] == '\0')
396 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
397 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
398 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
400 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
401 if (len > IEEE80211_MAX_SSID_LEN)
403 memcpy(sdata->u.sta.ssid, ssid, len);
404 sdata->u.sta.ssid_len = len;
408 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
410 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
411 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
414 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
422 static int ieee80211_ioctl_giwessid(struct net_device *dev,
423 struct iw_request_info *info,
424 struct iw_point *data, char *ssid)
428 struct ieee80211_sub_if_data *sdata;
429 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
430 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
431 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
432 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
445 static int ieee80211_ioctl_siwap(struct net_device *dev,
446 struct iw_request_info *info,
447 struct sockaddr *ap_addr, char *extra)
449 struct ieee80211_sub_if_data *sdata;
451 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
452 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
453 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
455 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
456 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
460 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
461 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
462 IEEE80211_STA_AUTO_CHANNEL_SEL;
463 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
464 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
466 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
467 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
470 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
472 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
474 * If it is necessary to update the WDS peer address
475 * while the interface is running, then we need to do
476 * more work here, namely if it is running we need to
477 * add a new and remove the old STA entry, this is
478 * normally handled by _open() and _stop().
480 if (netif_running(dev))
483 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
493 static int ieee80211_ioctl_giwap(struct net_device *dev,
494 struct iw_request_info *info,
495 struct sockaddr *ap_addr, char *extra)
497 struct ieee80211_sub_if_data *sdata;
499 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
500 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
501 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
502 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
503 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
504 ap_addr->sa_family = ARPHRD_ETHER;
505 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
508 memset(&ap_addr->sa_data, 0, ETH_ALEN);
511 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
512 ap_addr->sa_family = ARPHRD_ETHER;
513 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
521 static int ieee80211_ioctl_siwscan(struct net_device *dev,
522 struct iw_request_info *info,
523 union iwreq_data *wrqu, char *extra)
525 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
526 struct iw_scan_req *req = NULL;
530 if (!netif_running(dev))
533 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
534 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
535 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
536 sdata->vif.type != NL80211_IFTYPE_AP)
539 /* if SSID was specified explicitly then use that */
540 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
541 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
542 req = (struct iw_scan_req *)extra;
544 ssid_len = req->essid_len;
547 return ieee80211_request_scan(sdata, ssid, ssid_len);
551 static int ieee80211_ioctl_giwscan(struct net_device *dev,
552 struct iw_request_info *info,
553 struct iw_point *data, char *extra)
556 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
557 struct ieee80211_sub_if_data *sdata;
559 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
561 if (local->sw_scanning || local->hw_scanning)
564 res = ieee80211_scan_results(local, info, extra, data->length);
574 static int ieee80211_ioctl_siwrate(struct net_device *dev,
575 struct iw_request_info *info,
576 struct iw_param *rate, char *extra)
578 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
579 int i, err = -EINVAL;
580 u32 target_rate = rate->value / 100000;
581 struct ieee80211_sub_if_data *sdata;
582 struct ieee80211_supported_band *sband;
584 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
586 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
588 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
589 * target_rate = X, rate->fixed = 1 means only rate X
590 * target_rate = X, rate->fixed = 0 means all rates <= X */
591 sdata->max_ratectrl_rateidx = -1;
592 sdata->force_unicast_rateidx = -1;
596 for (i=0; i< sband->n_bitrates; i++) {
597 struct ieee80211_rate *brate = &sband->bitrates[i];
598 int this_rate = brate->bitrate;
600 if (target_rate == this_rate) {
601 sdata->max_ratectrl_rateidx = i;
603 sdata->force_unicast_rateidx = i;
611 static int ieee80211_ioctl_giwrate(struct net_device *dev,
612 struct iw_request_info *info,
613 struct iw_param *rate, char *extra)
615 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
616 struct sta_info *sta;
617 struct ieee80211_sub_if_data *sdata;
618 struct ieee80211_supported_band *sband;
620 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
622 if (sdata->vif.type != NL80211_IFTYPE_STATION)
625 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
629 sta = sta_info_get(local, sdata->u.sta.bssid);
631 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
632 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
641 rate->value *= 100000;
646 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
647 struct iw_request_info *info,
648 union iwreq_data *data, char *extra)
650 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
651 struct ieee80211_channel* chan = local->hw.conf.channel;
652 u32 reconf_flags = 0;
655 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
657 if (data->txpower.flags & IW_TXPOW_RANGE)
662 if (data->txpower.fixed)
663 new_power_level = min(data->txpower.value, chan->max_power);
664 else /* Automatic power level setting */
665 new_power_level = chan->max_power;
667 if (local->hw.conf.power_level != new_power_level) {
668 local->hw.conf.power_level = new_power_level;
669 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
672 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
673 local->hw.conf.radio_enabled = !(data->txpower.disabled);
674 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
675 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
679 ieee80211_hw_config(local, reconf_flags);
684 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
685 struct iw_request_info *info,
686 union iwreq_data *data, char *extra)
688 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
690 data->txpower.fixed = 1;
691 data->txpower.disabled = !(local->hw.conf.radio_enabled);
692 data->txpower.value = local->hw.conf.power_level;
693 data->txpower.flags = IW_TXPOW_DBM;
698 static int ieee80211_ioctl_siwrts(struct net_device *dev,
699 struct iw_request_info *info,
700 struct iw_param *rts, char *extra)
702 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
705 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
706 else if (!rts->fixed)
707 /* if the rts value is not fixed, then take default */
708 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
709 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
712 local->rts_threshold = rts->value;
714 /* If the wlan card performs RTS/CTS in hardware/firmware,
715 * configure it here */
717 if (local->ops->set_rts_threshold)
718 local->ops->set_rts_threshold(local_to_hw(local),
719 local->rts_threshold);
724 static int ieee80211_ioctl_giwrts(struct net_device *dev,
725 struct iw_request_info *info,
726 struct iw_param *rts, char *extra)
728 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
730 rts->value = local->rts_threshold;
731 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
738 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
739 struct iw_request_info *info,
740 struct iw_param *frag, char *extra)
742 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
745 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
746 else if (!frag->fixed)
747 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
748 else if (frag->value < 256 ||
749 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
752 /* Fragment length must be even, so strip LSB. */
753 local->fragmentation_threshold = frag->value & ~0x1;
756 /* If the wlan card performs fragmentation in hardware/firmware,
757 * configure it here */
759 if (local->ops->set_frag_threshold)
760 return local->ops->set_frag_threshold(
762 local->fragmentation_threshold);
767 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
768 struct iw_request_info *info,
769 struct iw_param *frag, char *extra)
771 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
773 frag->value = local->fragmentation_threshold;
774 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
781 static int ieee80211_ioctl_siwretry(struct net_device *dev,
782 struct iw_request_info *info,
783 struct iw_param *retry, char *extra)
785 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
787 if (retry->disabled ||
788 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
791 if (retry->flags & IW_RETRY_MAX) {
792 local->hw.conf.long_frame_max_tx_count = retry->value;
793 } else if (retry->flags & IW_RETRY_MIN) {
794 local->hw.conf.short_frame_max_tx_count = retry->value;
796 local->hw.conf.long_frame_max_tx_count = retry->value;
797 local->hw.conf.short_frame_max_tx_count = retry->value;
800 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
806 static int ieee80211_ioctl_giwretry(struct net_device *dev,
807 struct iw_request_info *info,
808 struct iw_param *retry, char *extra)
810 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
813 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
814 /* first return min value, iwconfig will ask max value
816 retry->flags |= IW_RETRY_LIMIT;
817 retry->value = local->hw.conf.short_frame_max_tx_count;
818 if (local->hw.conf.long_frame_max_tx_count !=
819 local->hw.conf.short_frame_max_tx_count)
820 retry->flags |= IW_RETRY_MIN;
823 if (retry->flags & IW_RETRY_MAX) {
824 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
825 retry->value = local->hw.conf.long_frame_max_tx_count;
831 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
832 struct iw_request_info *info,
833 struct iw_point *data, char *extra)
835 struct ieee80211_sub_if_data *sdata;
836 struct iw_mlme *mlme = (struct iw_mlme *) extra;
838 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
839 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
840 sdata->vif.type != NL80211_IFTYPE_ADHOC)
845 /* TODO: mlme->addr.sa_data */
846 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
847 case IW_MLME_DISASSOC:
848 /* TODO: mlme->addr.sa_data */
849 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
856 static int ieee80211_ioctl_siwencode(struct net_device *dev,
857 struct iw_request_info *info,
858 struct iw_point *erq, char *keybuf)
860 struct ieee80211_sub_if_data *sdata;
861 int idx, i, alg = ALG_WEP;
862 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
865 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
867 idx = erq->flags & IW_ENCODE_INDEX;
869 if (sdata->default_key)
870 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
871 if (sdata->default_key == sdata->keys[i]) {
876 } else if (idx < 1 || idx > 4)
881 if (erq->flags & IW_ENCODE_DISABLED)
883 else if (erq->length == 0) {
884 /* No key data - just set the default TX key index */
885 ieee80211_set_default_key(sdata, idx);
889 return ieee80211_set_encryption(
893 keybuf, erq->length);
897 static int ieee80211_ioctl_giwencode(struct net_device *dev,
898 struct iw_request_info *info,
899 struct iw_point *erq, char *key)
901 struct ieee80211_sub_if_data *sdata;
904 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
906 idx = erq->flags & IW_ENCODE_INDEX;
907 if (idx < 1 || idx > 4) {
909 if (!sdata->default_key)
911 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
912 if (sdata->default_key == sdata->keys[i]) {
922 erq->flags = idx + 1;
924 if (!sdata->keys[idx]) {
926 erq->flags |= IW_ENCODE_DISABLED;
930 memcpy(key, sdata->keys[idx]->conf.key,
931 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
932 erq->length = sdata->keys[idx]->conf.keylen;
933 erq->flags |= IW_ENCODE_ENABLED;
935 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
936 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
937 switch (ifsta->auth_alg) {
940 erq->flags |= IW_ENCODE_OPEN;
942 case WLAN_AUTH_SHARED_KEY:
943 erq->flags |= IW_ENCODE_RESTRICTED;
951 static int ieee80211_ioctl_siwpower(struct net_device *dev,
952 struct iw_request_info *info,
953 struct iw_param *wrq,
956 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
957 struct ieee80211_conf *conf = &local->hw.conf;
960 conf->flags &= ~IEEE80211_CONF_PS;
961 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
964 switch (wrq->flags & IW_POWER_MODE) {
965 case IW_POWER_ON: /* If not specified */
966 case IW_POWER_MODE: /* If set all mask */
967 case IW_POWER_ALL_R: /* If explicitely state all */
968 conf->flags |= IEEE80211_CONF_PS;
970 default: /* Otherwise we don't support it */
974 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
977 static int ieee80211_ioctl_giwpower(struct net_device *dev,
978 struct iw_request_info *info,
979 union iwreq_data *wrqu,
982 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
983 struct ieee80211_conf *conf = &local->hw.conf;
985 wrqu->power.disabled = !(conf->flags & IEEE80211_CONF_PS);
990 static int ieee80211_ioctl_siwauth(struct net_device *dev,
991 struct iw_request_info *info,
992 struct iw_param *data, char *extra)
994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
997 switch (data->flags & IW_AUTH_INDEX) {
998 case IW_AUTH_WPA_VERSION:
999 case IW_AUTH_CIPHER_PAIRWISE:
1000 case IW_AUTH_CIPHER_GROUP:
1001 case IW_AUTH_WPA_ENABLED:
1002 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1003 case IW_AUTH_KEY_MGMT:
1005 case IW_AUTH_DROP_UNENCRYPTED:
1006 sdata->drop_unencrypted = !!data->value;
1008 case IW_AUTH_PRIVACY_INVOKED:
1009 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1012 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
1014 * Privacy invoked by wpa_supplicant, store the
1015 * value and allow associating to a protected
1016 * network without having a key up front.
1019 sdata->u.sta.flags |=
1020 IEEE80211_STA_PRIVACY_INVOKED;
1023 case IW_AUTH_80211_AUTH_ALG:
1024 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1025 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1026 sdata->u.sta.auth_algs = data->value;
1037 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1038 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1040 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1041 struct iw_statistics *wstats = &local->wstats;
1042 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1043 struct sta_info *sta = NULL;
1047 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1048 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1049 sta = sta_info_get(local, sdata->u.sta.bssid);
1051 wstats->discard.fragment = 0;
1052 wstats->discard.misc = 0;
1053 wstats->qual.qual = 0;
1054 wstats->qual.level = 0;
1055 wstats->qual.noise = 0;
1056 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1058 wstats->qual.level = sta->last_signal;
1059 wstats->qual.qual = sta->last_qual;
1060 wstats->qual.noise = sta->last_noise;
1061 wstats->qual.updated = local->wstats_flags;
1069 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1070 struct iw_request_info *info,
1071 struct iw_param *data, char *extra)
1073 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1076 switch (data->flags & IW_AUTH_INDEX) {
1077 case IW_AUTH_80211_AUTH_ALG:
1078 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1079 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1080 data->value = sdata->u.sta.auth_algs;
1092 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1093 struct iw_request_info *info,
1094 struct iw_point *erq, char *extra)
1096 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1097 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1098 int uninitialized_var(alg), idx, i, remove = 0;
1101 case IW_ENCODE_ALG_NONE:
1104 case IW_ENCODE_ALG_WEP:
1107 case IW_ENCODE_ALG_TKIP:
1110 case IW_ENCODE_ALG_CCMP:
1117 if (erq->flags & IW_ENCODE_DISABLED)
1120 idx = erq->flags & IW_ENCODE_INDEX;
1121 if (idx < 1 || idx > 4) {
1123 if (!sdata->default_key)
1125 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1126 if (sdata->default_key == sdata->keys[i]) {
1136 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1139 IW_ENCODE_EXT_SET_TX_KEY,
1140 ext->key, ext->key_len);
1144 /* Structures to export the Wireless Handlers */
1146 static const iw_handler ieee80211_handler[] =
1148 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1149 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1150 (iw_handler) NULL, /* SIOCSIWNWID */
1151 (iw_handler) NULL, /* SIOCGIWNWID */
1152 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1153 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1154 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1155 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1156 (iw_handler) NULL, /* SIOCSIWSENS */
1157 (iw_handler) NULL, /* SIOCGIWSENS */
1158 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1159 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1160 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1161 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1162 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1163 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1164 (iw_handler) NULL, /* SIOCSIWSPY */
1165 (iw_handler) NULL, /* SIOCGIWSPY */
1166 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1167 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1168 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1169 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1170 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1171 (iw_handler) NULL, /* SIOCGIWAPLIST */
1172 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1173 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1174 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1175 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1176 (iw_handler) NULL, /* SIOCSIWNICKN */
1177 (iw_handler) NULL, /* SIOCGIWNICKN */
1178 (iw_handler) NULL, /* -- hole -- */
1179 (iw_handler) NULL, /* -- hole -- */
1180 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1181 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1182 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1183 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1184 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1185 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1186 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1187 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1188 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1189 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1190 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1191 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1192 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1193 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1194 (iw_handler) NULL, /* -- hole -- */
1195 (iw_handler) NULL, /* -- hole -- */
1196 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1197 (iw_handler) NULL, /* SIOCGIWGENIE */
1198 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1199 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1200 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1201 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1202 (iw_handler) NULL, /* SIOCSIWPMKSA */
1203 (iw_handler) NULL, /* -- hole -- */
1206 const struct iw_handler_def ieee80211_iw_handler_def =
1208 .num_standard = ARRAY_SIZE(ieee80211_handler),
1209 .standard = (iw_handler *) ieee80211_handler,
1210 .get_wireless_stats = ieee80211_get_wireless_stats,