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 net_device *dev, u8 *sta_addr,
31 int idx, int alg, int remove,
32 int set_tx_key, const u8 *_key,
35 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
37 struct ieee80211_key *key;
38 struct ieee80211_sub_if_data *sdata;
41 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
43 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
44 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
54 if (is_broadcast_ether_addr(sta_addr)) {
55 key = sdata->keys[idx];
57 sta = sta_info_get(local, sta_addr);
65 ieee80211_key_free(key);
67 key = ieee80211_key_alloc(alg, idx, key_len, _key);
76 if (!is_broadcast_ether_addr(sta_addr)) {
79 * According to the standard, the key index of a
80 * pairwise key must be zero. However, some AP are
81 * broken when it comes to WEP key indices, so we
84 if (idx != 0 && alg != ALG_WEP) {
85 ieee80211_key_free(key);
90 sta = sta_info_get(local, sta_addr);
92 ieee80211_key_free(key);
98 ieee80211_key_link(key, sdata, sta);
100 if (set_tx_key || (!sta && !sdata->default_key && key))
101 ieee80211_set_default_key(sdata, idx);
110 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
111 struct iw_request_info *info,
112 struct iw_point *data, char *extra)
114 struct ieee80211_sub_if_data *sdata;
116 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
118 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
121 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
122 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
123 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
126 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
127 ieee80211_sta_req_auth(dev, &sdata->u.sta);
134 static int ieee80211_ioctl_giwname(struct net_device *dev,
135 struct iw_request_info *info,
136 char *name, char *extra)
138 strcpy(name, "IEEE 802.11");
144 static int ieee80211_ioctl_giwrange(struct net_device *dev,
145 struct iw_request_info *info,
146 struct iw_point *data, char *extra)
148 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
149 struct iw_range *range = (struct iw_range *) extra;
150 enum ieee80211_band band;
153 data->length = sizeof(struct iw_range);
154 memset(range, 0, sizeof(struct iw_range));
156 range->we_version_compiled = WIRELESS_EXT;
157 range->we_version_source = 21;
158 range->retry_capa = IW_RETRY_LIMIT;
159 range->retry_flags = IW_RETRY_LIMIT;
160 range->min_retry = 0;
161 range->max_retry = 255;
163 range->max_rts = 2347;
164 range->min_frag = 256;
165 range->max_frag = 2346;
167 range->encoding_size[0] = 5;
168 range->encoding_size[1] = 13;
169 range->num_encoding_sizes = 2;
170 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
172 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
173 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
174 range->max_qual.level = local->hw.max_signal;
175 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
176 range->max_qual.level = -110;
178 range->max_qual.level = 0;
180 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
181 range->max_qual.noise = -110;
183 range->max_qual.noise = 0;
185 range->max_qual.qual = 100;
186 range->max_qual.updated = local->wstats_flags;
188 range->avg_qual.qual = 50;
189 /* not always true but better than nothing */
190 range->avg_qual.level = range->max_qual.level / 2;
191 range->avg_qual.noise = range->max_qual.noise / 2;
192 range->avg_qual.updated = local->wstats_flags;
194 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
195 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
198 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
200 struct ieee80211_supported_band *sband;
202 sband = local->hw.wiphy->bands[band];
207 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
208 struct ieee80211_channel *chan = &sband->channels[i];
210 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
212 ieee80211_frequency_to_channel(
214 range->freq[c].m = chan->center_freq;
215 range->freq[c].e = 6;
220 range->num_channels = c;
221 range->num_frequency = c;
223 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
224 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
225 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
227 range->scan_capa |= IW_SCAN_CAPA_ESSID;
233 static int ieee80211_ioctl_siwmode(struct net_device *dev,
234 struct iw_request_info *info,
235 __u32 *mode, char *extra)
237 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
240 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
245 type = IEEE80211_IF_TYPE_STA;
248 type = IEEE80211_IF_TYPE_IBSS;
251 type = IEEE80211_IF_TYPE_WDS;
253 case IW_MODE_MONITOR:
254 type = IEEE80211_IF_TYPE_MNTR;
260 if (type == sdata->vif.type)
262 if (netif_running(dev))
265 ieee80211_if_reinit(dev);
266 ieee80211_if_set_type(dev, type);
272 static int ieee80211_ioctl_giwmode(struct net_device *dev,
273 struct iw_request_info *info,
274 __u32 *mode, char *extra)
276 struct ieee80211_sub_if_data *sdata;
278 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
279 switch (sdata->vif.type) {
280 case IEEE80211_IF_TYPE_AP:
281 *mode = IW_MODE_MASTER;
283 case IEEE80211_IF_TYPE_STA:
284 *mode = IW_MODE_INFRA;
286 case IEEE80211_IF_TYPE_IBSS:
287 *mode = IW_MODE_ADHOC;
289 case IEEE80211_IF_TYPE_MNTR:
290 *mode = IW_MODE_MONITOR;
292 case IEEE80211_IF_TYPE_WDS:
293 *mode = IW_MODE_REPEAT;
295 case IEEE80211_IF_TYPE_VLAN:
296 *mode = IW_MODE_SECOND; /* FIXME */
299 *mode = IW_MODE_AUTO;
305 int ieee80211_set_freq(struct net_device *dev, int freqMHz)
308 struct ieee80211_channel *chan;
309 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
310 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
312 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
314 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
315 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
316 chan->flags & IEEE80211_CHAN_NO_IBSS) {
317 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
318 "%d MHz\n", dev->name, chan->center_freq);
321 local->oper_channel = chan;
323 if (local->sta_sw_scanning || local->sta_hw_scanning)
326 ret = ieee80211_hw_config(local);
328 rate_control_clear(local);
334 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
335 struct iw_request_info *info,
336 struct iw_freq *freq, char *extra)
338 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
340 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
341 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
343 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
346 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
347 sdata->u.sta.flags |=
348 IEEE80211_STA_AUTO_CHANNEL_SEL;
351 return ieee80211_set_freq(dev,
352 ieee80211_channel_to_frequency(freq->m));
354 int i, div = 1000000;
355 for (i = 0; i < freq->e; i++)
358 return ieee80211_set_freq(dev, freq->m / div);
365 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
366 struct iw_request_info *info,
367 struct iw_freq *freq, char *extra)
369 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
371 freq->m = local->hw.conf.channel->center_freq;
378 static int ieee80211_ioctl_siwessid(struct net_device *dev,
379 struct iw_request_info *info,
380 struct iw_point *data, char *ssid)
382 struct ieee80211_sub_if_data *sdata;
383 size_t len = data->length;
385 /* iwconfig uses nul termination in SSID.. */
386 if (len > 0 && ssid[len - 1] == '\0')
389 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
390 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
391 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
393 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
394 if (len > IEEE80211_MAX_SSID_LEN)
396 memcpy(sdata->u.sta.ssid, ssid, len);
397 sdata->u.sta.ssid_len = len;
401 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
403 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
404 ret = ieee80211_sta_set_ssid(dev, ssid, len);
407 ieee80211_sta_req_auth(dev, &sdata->u.sta);
411 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
412 memcpy(sdata->u.ap.ssid, ssid, len);
413 memset(sdata->u.ap.ssid + len, 0,
414 IEEE80211_MAX_SSID_LEN - len);
415 sdata->u.ap.ssid_len = len;
416 return ieee80211_if_config(dev);
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 == IEEE80211_IF_TYPE_STA ||
431 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
432 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
441 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
442 len = sdata->u.ap.ssid_len;
443 if (len > IW_ESSID_MAX_SIZE)
444 len = IW_ESSID_MAX_SIZE;
445 memcpy(ssid, sdata->u.ap.ssid, len);
454 static int ieee80211_ioctl_siwap(struct net_device *dev,
455 struct iw_request_info *info,
456 struct sockaddr *ap_addr, char *extra)
458 struct ieee80211_sub_if_data *sdata;
460 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
461 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
462 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
464 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
465 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
469 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
470 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
471 IEEE80211_STA_AUTO_CHANNEL_SEL;
472 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
473 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
475 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
476 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
479 ieee80211_sta_req_auth(dev, &sdata->u.sta);
481 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
483 * If it is necessary to update the WDS peer address
484 * while the interface is running, then we need to do
485 * more work here, namely if it is running we need to
486 * add a new and remove the old STA entry, this is
487 * normally handled by _open() and _stop().
489 if (netif_running(dev))
492 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
502 static int ieee80211_ioctl_giwap(struct net_device *dev,
503 struct iw_request_info *info,
504 struct sockaddr *ap_addr, char *extra)
506 struct ieee80211_sub_if_data *sdata;
508 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
509 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
510 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
511 if (sdata->u.sta.state == IEEE80211_ASSOCIATED) {
512 ap_addr->sa_family = ARPHRD_ETHER;
513 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
516 memset(&ap_addr->sa_data, 0, ETH_ALEN);
519 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
520 ap_addr->sa_family = ARPHRD_ETHER;
521 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
529 static int ieee80211_ioctl_siwscan(struct net_device *dev,
530 struct iw_request_info *info,
531 union iwreq_data *wrqu, char *extra)
533 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
534 struct iw_scan_req *req = NULL;
538 if (!netif_running(dev))
541 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
542 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
543 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
544 sdata->vif.type != IEEE80211_IF_TYPE_AP)
547 /* if SSID was specified explicitly then use that */
548 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
549 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
550 req = (struct iw_scan_req *)extra;
552 ssid_len = req->essid_len;
555 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
559 static int ieee80211_ioctl_giwscan(struct net_device *dev,
560 struct iw_request_info *info,
561 struct iw_point *data, char *extra)
564 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
566 if (local->sta_sw_scanning || local->sta_hw_scanning)
569 res = ieee80211_sta_scan_results(dev, extra, data->length);
579 static int ieee80211_ioctl_siwrate(struct net_device *dev,
580 struct iw_request_info *info,
581 struct iw_param *rate, char *extra)
583 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
584 int i, err = -EINVAL;
585 u32 target_rate = rate->value / 100000;
586 struct ieee80211_sub_if_data *sdata;
587 struct ieee80211_supported_band *sband;
589 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
593 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
595 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
596 * target_rate = X, rate->fixed = 1 means only rate X
597 * target_rate = X, rate->fixed = 0 means all rates <= X */
598 sdata->bss->max_ratectrl_rateidx = -1;
599 sdata->bss->force_unicast_rateidx = -1;
603 for (i=0; i< sband->n_bitrates; i++) {
604 struct ieee80211_rate *brate = &sband->bitrates[i];
605 int this_rate = brate->bitrate;
607 if (target_rate == this_rate) {
608 sdata->bss->max_ratectrl_rateidx = i;
610 sdata->bss->force_unicast_rateidx = i;
618 static int ieee80211_ioctl_giwrate(struct net_device *dev,
619 struct iw_request_info *info,
620 struct iw_param *rate, char *extra)
622 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
623 struct sta_info *sta;
624 struct ieee80211_sub_if_data *sdata;
625 struct ieee80211_supported_band *sband;
627 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
629 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
632 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
636 sta = sta_info_get(local, sdata->u.sta.bssid);
638 if (sta && sta->txrate_idx < sband->n_bitrates)
639 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
648 rate->value *= 100000;
653 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
654 struct iw_request_info *info,
655 union iwreq_data *data, char *extra)
657 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
658 bool need_reconfig = 0;
661 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
663 if (data->txpower.flags & IW_TXPOW_RANGE)
666 if (data->txpower.fixed) {
667 new_power_level = data->txpower.value;
670 * Automatic power level. Use maximum power for the current
671 * channel. Should be part of rate control.
673 struct ieee80211_channel* chan = local->hw.conf.channel;
677 new_power_level = chan->max_power;
680 if (local->hw.conf.power_level != new_power_level) {
681 local->hw.conf.power_level = new_power_level;
685 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
686 local->hw.conf.radio_enabled = !(data->txpower.disabled);
688 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
692 ieee80211_hw_config(local);
693 /* The return value of hw_config is not of big interest here,
694 * as it doesn't say that it failed because of _this_ config
695 * change or something else. Ignore it. */
701 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
702 struct iw_request_info *info,
703 union iwreq_data *data, char *extra)
705 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
707 data->txpower.fixed = 1;
708 data->txpower.disabled = !(local->hw.conf.radio_enabled);
709 data->txpower.value = local->hw.conf.power_level;
710 data->txpower.flags = IW_TXPOW_DBM;
715 static int ieee80211_ioctl_siwrts(struct net_device *dev,
716 struct iw_request_info *info,
717 struct iw_param *rts, char *extra)
719 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
722 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
723 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
726 local->rts_threshold = rts->value;
728 /* If the wlan card performs RTS/CTS in hardware/firmware,
729 * configure it here */
731 if (local->ops->set_rts_threshold)
732 local->ops->set_rts_threshold(local_to_hw(local),
733 local->rts_threshold);
738 static int ieee80211_ioctl_giwrts(struct net_device *dev,
739 struct iw_request_info *info,
740 struct iw_param *rts, char *extra)
742 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
744 rts->value = local->rts_threshold;
745 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
752 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
753 struct iw_request_info *info,
754 struct iw_param *frag, char *extra)
756 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
759 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
760 else if (frag->value < 256 ||
761 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
764 /* Fragment length must be even, so strip LSB. */
765 local->fragmentation_threshold = frag->value & ~0x1;
768 /* If the wlan card performs fragmentation in hardware/firmware,
769 * configure it here */
771 if (local->ops->set_frag_threshold)
772 local->ops->set_frag_threshold(
774 local->fragmentation_threshold);
779 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
780 struct iw_request_info *info,
781 struct iw_param *frag, char *extra)
783 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
785 frag->value = local->fragmentation_threshold;
786 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
793 static int ieee80211_ioctl_siwretry(struct net_device *dev,
794 struct iw_request_info *info,
795 struct iw_param *retry, char *extra)
797 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
799 if (retry->disabled ||
800 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
803 if (retry->flags & IW_RETRY_MAX)
804 local->long_retry_limit = retry->value;
805 else if (retry->flags & IW_RETRY_MIN)
806 local->short_retry_limit = retry->value;
808 local->long_retry_limit = retry->value;
809 local->short_retry_limit = retry->value;
812 if (local->ops->set_retry_limit) {
813 return local->ops->set_retry_limit(
815 local->short_retry_limit,
816 local->long_retry_limit);
823 static int ieee80211_ioctl_giwretry(struct net_device *dev,
824 struct iw_request_info *info,
825 struct iw_param *retry, char *extra)
827 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
830 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
831 /* first return min value, iwconfig will ask max value
833 retry->flags |= IW_RETRY_LIMIT;
834 retry->value = local->short_retry_limit;
835 if (local->long_retry_limit != local->short_retry_limit)
836 retry->flags |= IW_RETRY_MIN;
839 if (retry->flags & IW_RETRY_MAX) {
840 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
841 retry->value = local->long_retry_limit;
847 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
848 struct iw_request_info *info,
849 struct iw_point *data, char *extra)
851 struct ieee80211_sub_if_data *sdata;
852 struct iw_mlme *mlme = (struct iw_mlme *) extra;
854 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
855 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
856 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
861 /* TODO: mlme->addr.sa_data */
862 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
863 case IW_MLME_DISASSOC:
864 /* TODO: mlme->addr.sa_data */
865 return ieee80211_sta_disassociate(dev, mlme->reason_code);
872 static int ieee80211_ioctl_siwencode(struct net_device *dev,
873 struct iw_request_info *info,
874 struct iw_point *erq, char *keybuf)
876 struct ieee80211_sub_if_data *sdata;
877 int idx, i, alg = ALG_WEP;
878 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
881 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
883 idx = erq->flags & IW_ENCODE_INDEX;
885 if (sdata->default_key)
886 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
887 if (sdata->default_key == sdata->keys[i]) {
892 } else if (idx < 1 || idx > 4)
897 if (erq->flags & IW_ENCODE_DISABLED)
899 else if (erq->length == 0) {
900 /* No key data - just set the default TX key index */
901 ieee80211_set_default_key(sdata, idx);
905 return ieee80211_set_encryption(
909 keybuf, erq->length);
913 static int ieee80211_ioctl_giwencode(struct net_device *dev,
914 struct iw_request_info *info,
915 struct iw_point *erq, char *key)
917 struct ieee80211_sub_if_data *sdata;
920 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
922 idx = erq->flags & IW_ENCODE_INDEX;
923 if (idx < 1 || idx > 4) {
925 if (!sdata->default_key)
927 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
928 if (sdata->default_key == sdata->keys[i]) {
938 erq->flags = idx + 1;
940 if (!sdata->keys[idx]) {
942 erq->flags |= IW_ENCODE_DISABLED;
946 memcpy(key, sdata->keys[idx]->conf.key,
947 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
948 erq->length = sdata->keys[idx]->conf.keylen;
949 erq->flags |= IW_ENCODE_ENABLED;
954 static int ieee80211_ioctl_siwauth(struct net_device *dev,
955 struct iw_request_info *info,
956 struct iw_param *data, char *extra)
958 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
961 switch (data->flags & IW_AUTH_INDEX) {
962 case IW_AUTH_WPA_VERSION:
963 case IW_AUTH_CIPHER_PAIRWISE:
964 case IW_AUTH_CIPHER_GROUP:
965 case IW_AUTH_WPA_ENABLED:
966 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
967 case IW_AUTH_KEY_MGMT:
969 case IW_AUTH_DROP_UNENCRYPTED:
970 sdata->drop_unencrypted = !!data->value;
972 case IW_AUTH_PRIVACY_INVOKED:
973 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
976 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
978 * Privacy invoked by wpa_supplicant, store the
979 * value and allow associating to a protected
980 * network without having a key up front.
983 sdata->u.sta.flags |=
984 IEEE80211_STA_PRIVACY_INVOKED;
987 case IW_AUTH_80211_AUTH_ALG:
988 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
989 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
990 sdata->u.sta.auth_algs = data->value;
1001 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1002 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1004 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1005 struct iw_statistics *wstats = &local->wstats;
1006 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1007 struct sta_info *sta = NULL;
1011 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1012 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
1013 sta = sta_info_get(local, sdata->u.sta.bssid);
1015 wstats->discard.fragment = 0;
1016 wstats->discard.misc = 0;
1017 wstats->qual.qual = 0;
1018 wstats->qual.level = 0;
1019 wstats->qual.noise = 0;
1020 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1022 wstats->qual.level = sta->last_signal;
1023 wstats->qual.qual = sta->last_qual;
1024 wstats->qual.noise = sta->last_noise;
1025 wstats->qual.updated = local->wstats_flags;
1033 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1034 struct iw_request_info *info,
1035 struct iw_param *data, char *extra)
1037 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1040 switch (data->flags & IW_AUTH_INDEX) {
1041 case IW_AUTH_80211_AUTH_ALG:
1042 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1043 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
1044 data->value = sdata->u.sta.auth_algs;
1056 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1057 struct iw_request_info *info,
1058 struct iw_point *erq, char *extra)
1060 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1061 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1062 int uninitialized_var(alg), idx, i, remove = 0;
1065 case IW_ENCODE_ALG_NONE:
1068 case IW_ENCODE_ALG_WEP:
1071 case IW_ENCODE_ALG_TKIP:
1074 case IW_ENCODE_ALG_CCMP:
1081 if (erq->flags & IW_ENCODE_DISABLED)
1084 idx = erq->flags & IW_ENCODE_INDEX;
1085 if (idx < 1 || idx > 4) {
1087 if (!sdata->default_key)
1089 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1090 if (sdata->default_key == sdata->keys[i]) {
1100 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
1103 IW_ENCODE_EXT_SET_TX_KEY,
1104 ext->key, ext->key_len);
1108 /* Structures to export the Wireless Handlers */
1110 static const iw_handler ieee80211_handler[] =
1112 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1113 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1114 (iw_handler) NULL, /* SIOCSIWNWID */
1115 (iw_handler) NULL, /* SIOCGIWNWID */
1116 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1117 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1118 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1119 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1120 (iw_handler) NULL, /* SIOCSIWSENS */
1121 (iw_handler) NULL, /* SIOCGIWSENS */
1122 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1123 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1124 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1125 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1126 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1127 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1128 (iw_handler) NULL, /* SIOCSIWSPY */
1129 (iw_handler) NULL, /* SIOCGIWSPY */
1130 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1131 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1132 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1133 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1134 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1135 (iw_handler) NULL, /* SIOCGIWAPLIST */
1136 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1137 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1138 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1139 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1140 (iw_handler) NULL, /* SIOCSIWNICKN */
1141 (iw_handler) NULL, /* SIOCGIWNICKN */
1142 (iw_handler) NULL, /* -- hole -- */
1143 (iw_handler) NULL, /* -- hole -- */
1144 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1145 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1146 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1147 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1148 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1149 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1150 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1151 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1152 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1153 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1154 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1155 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1156 (iw_handler) NULL, /* SIOCSIWPOWER */
1157 (iw_handler) NULL, /* SIOCGIWPOWER */
1158 (iw_handler) NULL, /* -- hole -- */
1159 (iw_handler) NULL, /* -- hole -- */
1160 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1161 (iw_handler) NULL, /* SIOCGIWGENIE */
1162 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1163 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1164 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1165 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1166 (iw_handler) NULL, /* SIOCSIWPMKSA */
1167 (iw_handler) NULL, /* -- hole -- */
1170 const struct iw_handler_def ieee80211_iw_handler_def =
1172 .num_standard = ARRAY_SIZE(ieee80211_handler),
1173 .standard = (iw_handler *) ieee80211_handler,
1174 .get_wireless_stats = ieee80211_get_wireless_stats,