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"
24 #include "ieee80211_led.h"
25 #include "ieee80211_rate.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;
40 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
42 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
43 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
49 if (is_broadcast_ether_addr(sta_addr)) {
50 key = sdata->keys[idx];
52 sta = sta_info_get(local, sta_addr);
61 ieee80211_key_free(key);
64 key = ieee80211_key_alloc(alg, idx, key_len, _key);
70 if (!is_broadcast_ether_addr(sta_addr)) {
73 * According to the standard, the key index of a
74 * pairwise key must be zero. However, some AP are
75 * broken when it comes to WEP key indices, so we
78 if (idx != 0 && alg != ALG_WEP) {
79 ieee80211_key_free(key);
83 sta = sta_info_get(local, sta_addr);
85 ieee80211_key_free(key);
90 ieee80211_key_link(key, sdata, sta);
92 if (set_tx_key || (!sta && !sdata->default_key && key))
93 ieee80211_set_default_key(sdata, idx);
99 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
100 struct iw_request_info *info,
101 struct iw_point *data, char *extra)
103 struct ieee80211_sub_if_data *sdata;
105 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
107 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
110 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
111 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
112 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
115 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
116 ieee80211_sta_req_auth(dev, &sdata->u.sta);
123 static int ieee80211_ioctl_giwname(struct net_device *dev,
124 struct iw_request_info *info,
125 char *name, char *extra)
127 strcpy(name, "IEEE 802.11");
133 static int ieee80211_ioctl_giwrange(struct net_device *dev,
134 struct iw_request_info *info,
135 struct iw_point *data, char *extra)
137 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
138 struct iw_range *range = (struct iw_range *) extra;
139 enum ieee80211_band band;
142 data->length = sizeof(struct iw_range);
143 memset(range, 0, sizeof(struct iw_range));
145 range->we_version_compiled = WIRELESS_EXT;
146 range->we_version_source = 21;
147 range->retry_capa = IW_RETRY_LIMIT;
148 range->retry_flags = IW_RETRY_LIMIT;
149 range->min_retry = 0;
150 range->max_retry = 255;
152 range->max_rts = 2347;
153 range->min_frag = 256;
154 range->max_frag = 2346;
156 range->encoding_size[0] = 5;
157 range->encoding_size[1] = 13;
158 range->num_encoding_sizes = 2;
159 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
161 range->max_qual.qual = local->hw.max_signal;
162 range->max_qual.level = local->hw.max_rssi;
163 range->max_qual.noise = local->hw.max_noise;
164 range->max_qual.updated = local->wstats_flags;
166 range->avg_qual.qual = local->hw.max_signal/2;
167 range->avg_qual.level = 0;
168 range->avg_qual.noise = 0;
169 range->avg_qual.updated = local->wstats_flags;
171 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
172 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
175 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
177 struct ieee80211_supported_band *sband;
179 sband = local->hw.wiphy->bands[band];
184 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
185 struct ieee80211_channel *chan = &sband->channels[i];
187 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
189 ieee80211_frequency_to_channel(
191 range->freq[c].m = chan->center_freq;
192 range->freq[c].e = 6;
197 range->num_channels = c;
198 range->num_frequency = c;
200 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
201 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
202 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
203 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
205 range->scan_capa |= IW_SCAN_CAPA_ESSID;
211 static int ieee80211_ioctl_siwmode(struct net_device *dev,
212 struct iw_request_info *info,
213 __u32 *mode, char *extra)
215 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
218 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
223 type = IEEE80211_IF_TYPE_STA;
226 type = IEEE80211_IF_TYPE_IBSS;
228 case IW_MODE_MONITOR:
229 type = IEEE80211_IF_TYPE_MNTR;
235 if (type == sdata->vif.type)
237 if (netif_running(dev))
240 ieee80211_if_reinit(dev);
241 ieee80211_if_set_type(dev, type);
247 static int ieee80211_ioctl_giwmode(struct net_device *dev,
248 struct iw_request_info *info,
249 __u32 *mode, char *extra)
251 struct ieee80211_sub_if_data *sdata;
253 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
254 switch (sdata->vif.type) {
255 case IEEE80211_IF_TYPE_AP:
256 *mode = IW_MODE_MASTER;
258 case IEEE80211_IF_TYPE_STA:
259 *mode = IW_MODE_INFRA;
261 case IEEE80211_IF_TYPE_IBSS:
262 *mode = IW_MODE_ADHOC;
264 case IEEE80211_IF_TYPE_MNTR:
265 *mode = IW_MODE_MONITOR;
267 case IEEE80211_IF_TYPE_WDS:
268 *mode = IW_MODE_REPEAT;
270 case IEEE80211_IF_TYPE_VLAN:
271 *mode = IW_MODE_SECOND; /* FIXME */
274 *mode = IW_MODE_AUTO;
280 int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
284 enum ieee80211_band band;
285 struct ieee80211_supported_band *sband;
288 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
289 sband = local->hw.wiphy->bands[band];
294 for (i = 0; i < sband->n_channels; i++) {
295 struct ieee80211_channel *chan = &sband->channels[i];
297 if (chan->flags & IEEE80211_CHAN_DISABLED)
300 if (chan->center_freq == freqMHz) {
302 local->oper_channel = chan;
311 if (local->sta_sw_scanning)
314 ret = ieee80211_hw_config(local);
316 rate_control_clear(local);
322 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
323 struct iw_request_info *info,
324 struct iw_freq *freq, char *extra)
326 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
327 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
329 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
330 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
332 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
335 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
336 sdata->u.sta.flags |=
337 IEEE80211_STA_AUTO_CHANNEL_SEL;
340 return ieee80211_set_freq(local,
341 ieee80211_channel_to_frequency(freq->m));
343 int i, div = 1000000;
344 for (i = 0; i < freq->e; i++)
347 return ieee80211_set_freq(local, freq->m / div);
354 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
355 struct iw_request_info *info,
356 struct iw_freq *freq, char *extra)
358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
360 freq->m = local->hw.conf.channel->center_freq;
367 static int ieee80211_ioctl_siwessid(struct net_device *dev,
368 struct iw_request_info *info,
369 struct iw_point *data, char *ssid)
371 struct ieee80211_sub_if_data *sdata;
372 size_t len = data->length;
374 /* iwconfig uses nul termination in SSID.. */
375 if (len > 0 && ssid[len - 1] == '\0')
378 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
379 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
380 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
382 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
383 if (len > IEEE80211_MAX_SSID_LEN)
385 memcpy(sdata->u.sta.ssid, ssid, len);
386 sdata->u.sta.ssid_len = len;
390 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
392 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
393 ret = ieee80211_sta_set_ssid(dev, ssid, len);
396 ieee80211_sta_req_auth(dev, &sdata->u.sta);
400 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
401 memcpy(sdata->u.ap.ssid, ssid, len);
402 memset(sdata->u.ap.ssid + len, 0,
403 IEEE80211_MAX_SSID_LEN - len);
404 sdata->u.ap.ssid_len = len;
405 return ieee80211_if_config(dev);
411 static int ieee80211_ioctl_giwessid(struct net_device *dev,
412 struct iw_request_info *info,
413 struct iw_point *data, char *ssid)
417 struct ieee80211_sub_if_data *sdata;
418 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
419 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
420 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
421 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
430 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
431 len = sdata->u.ap.ssid_len;
432 if (len > IW_ESSID_MAX_SIZE)
433 len = IW_ESSID_MAX_SIZE;
434 memcpy(ssid, sdata->u.ap.ssid, len);
443 static int ieee80211_ioctl_siwap(struct net_device *dev,
444 struct iw_request_info *info,
445 struct sockaddr *ap_addr, char *extra)
447 struct ieee80211_sub_if_data *sdata;
449 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
450 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
451 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
453 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
454 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
458 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
459 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
460 IEEE80211_STA_AUTO_CHANNEL_SEL;
461 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
462 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
464 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
465 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
468 ieee80211_sta_req_auth(dev, &sdata->u.sta);
470 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
472 * If it is necessary to update the WDS peer address
473 * while the interface is running, then we need to do
474 * more work here, namely if it is running we need to
475 * add a new and remove the old STA entry, this is
476 * normally handled by _open() and _stop().
478 if (netif_running(dev))
481 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
491 static int ieee80211_ioctl_giwap(struct net_device *dev,
492 struct iw_request_info *info,
493 struct sockaddr *ap_addr, char *extra)
495 struct ieee80211_sub_if_data *sdata;
497 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
498 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
499 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
500 ap_addr->sa_family = ARPHRD_ETHER;
501 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
503 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
504 ap_addr->sa_family = ARPHRD_ETHER;
505 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
513 static int ieee80211_ioctl_siwscan(struct net_device *dev,
514 struct iw_request_info *info,
515 union iwreq_data *wrqu, char *extra)
517 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
518 struct iw_scan_req *req = NULL;
522 if (!netif_running(dev))
525 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
526 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
527 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
528 sdata->vif.type != IEEE80211_IF_TYPE_AP)
531 /* if SSID was specified explicitly then use that */
532 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
533 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
534 req = (struct iw_scan_req *)extra;
536 ssid_len = req->essid_len;
539 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
543 static int ieee80211_ioctl_giwscan(struct net_device *dev,
544 struct iw_request_info *info,
545 struct iw_point *data, char *extra)
548 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
550 if (local->sta_sw_scanning || local->sta_hw_scanning)
553 res = ieee80211_sta_scan_results(dev, extra, data->length);
563 static int ieee80211_ioctl_siwrate(struct net_device *dev,
564 struct iw_request_info *info,
565 struct iw_param *rate, char *extra)
567 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
568 int i, err = -EINVAL;
569 u32 target_rate = rate->value / 100000;
570 struct ieee80211_sub_if_data *sdata;
571 struct ieee80211_supported_band *sband;
573 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
577 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
579 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
580 * target_rate = X, rate->fixed = 1 means only rate X
581 * target_rate = X, rate->fixed = 0 means all rates <= X */
582 sdata->bss->max_ratectrl_rateidx = -1;
583 sdata->bss->force_unicast_rateidx = -1;
587 for (i=0; i< sband->n_bitrates; i++) {
588 struct ieee80211_rate *brate = &sband->bitrates[i];
589 int this_rate = brate->bitrate;
591 if (target_rate == this_rate) {
592 sdata->bss->max_ratectrl_rateidx = i;
594 sdata->bss->force_unicast_rateidx = i;
602 static int ieee80211_ioctl_giwrate(struct net_device *dev,
603 struct iw_request_info *info,
604 struct iw_param *rate, char *extra)
606 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
607 struct sta_info *sta;
608 struct ieee80211_sub_if_data *sdata;
609 struct ieee80211_supported_band *sband;
611 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
613 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
614 sta = sta_info_get(local, sdata->u.sta.bssid);
620 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
622 if (sta->txrate_idx < sband->n_bitrates)
623 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
626 rate->value *= 100000;
631 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
632 struct iw_request_info *info,
633 union iwreq_data *data, char *extra)
635 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
636 bool need_reconfig = 0;
639 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
641 if (data->txpower.flags & IW_TXPOW_RANGE)
644 if (data->txpower.fixed) {
645 new_power_level = data->txpower.value;
648 * Automatic power level. Use maximum power for the current
649 * channel. Should be part of rate control.
651 struct ieee80211_channel* chan = local->hw.conf.channel;
655 new_power_level = chan->max_power;
658 if (local->hw.conf.power_level != new_power_level) {
659 local->hw.conf.power_level = new_power_level;
663 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
664 local->hw.conf.radio_enabled = !(data->txpower.disabled);
666 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
670 ieee80211_hw_config(local);
671 /* The return value of hw_config is not of big interest here,
672 * as it doesn't say that it failed because of _this_ config
673 * change or something else. Ignore it. */
679 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
680 struct iw_request_info *info,
681 union iwreq_data *data, char *extra)
683 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
685 data->txpower.fixed = 1;
686 data->txpower.disabled = !(local->hw.conf.radio_enabled);
687 data->txpower.value = local->hw.conf.power_level;
688 data->txpower.flags = IW_TXPOW_DBM;
693 static int ieee80211_ioctl_siwrts(struct net_device *dev,
694 struct iw_request_info *info,
695 struct iw_param *rts, char *extra)
697 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
700 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
701 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
704 local->rts_threshold = rts->value;
706 /* If the wlan card performs RTS/CTS in hardware/firmware,
707 * configure it here */
709 if (local->ops->set_rts_threshold)
710 local->ops->set_rts_threshold(local_to_hw(local),
711 local->rts_threshold);
716 static int ieee80211_ioctl_giwrts(struct net_device *dev,
717 struct iw_request_info *info,
718 struct iw_param *rts, char *extra)
720 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
722 rts->value = local->rts_threshold;
723 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
730 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
731 struct iw_request_info *info,
732 struct iw_param *frag, char *extra)
734 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
737 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
738 else if (frag->value < 256 ||
739 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
742 /* Fragment length must be even, so strip LSB. */
743 local->fragmentation_threshold = frag->value & ~0x1;
746 /* If the wlan card performs fragmentation in hardware/firmware,
747 * configure it here */
749 if (local->ops->set_frag_threshold)
750 local->ops->set_frag_threshold(
752 local->fragmentation_threshold);
757 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
758 struct iw_request_info *info,
759 struct iw_param *frag, char *extra)
761 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
763 frag->value = local->fragmentation_threshold;
764 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
771 static int ieee80211_ioctl_siwretry(struct net_device *dev,
772 struct iw_request_info *info,
773 struct iw_param *retry, char *extra)
775 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
777 if (retry->disabled ||
778 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
781 if (retry->flags & IW_RETRY_MAX)
782 local->long_retry_limit = retry->value;
783 else if (retry->flags & IW_RETRY_MIN)
784 local->short_retry_limit = retry->value;
786 local->long_retry_limit = retry->value;
787 local->short_retry_limit = retry->value;
790 if (local->ops->set_retry_limit) {
791 return local->ops->set_retry_limit(
793 local->short_retry_limit,
794 local->long_retry_limit);
801 static int ieee80211_ioctl_giwretry(struct net_device *dev,
802 struct iw_request_info *info,
803 struct iw_param *retry, char *extra)
805 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
808 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
809 /* first return min value, iwconfig will ask max value
811 retry->flags |= IW_RETRY_LIMIT;
812 retry->value = local->short_retry_limit;
813 if (local->long_retry_limit != local->short_retry_limit)
814 retry->flags |= IW_RETRY_MIN;
817 if (retry->flags & IW_RETRY_MAX) {
818 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
819 retry->value = local->long_retry_limit;
825 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
826 struct iw_request_info *info,
827 struct iw_point *data, char *extra)
829 struct ieee80211_sub_if_data *sdata;
830 struct iw_mlme *mlme = (struct iw_mlme *) extra;
832 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
833 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
834 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
839 /* TODO: mlme->addr.sa_data */
840 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
841 case IW_MLME_DISASSOC:
842 /* TODO: mlme->addr.sa_data */
843 return ieee80211_sta_disassociate(dev, mlme->reason_code);
850 static int ieee80211_ioctl_siwencode(struct net_device *dev,
851 struct iw_request_info *info,
852 struct iw_point *erq, char *keybuf)
854 struct ieee80211_sub_if_data *sdata;
855 int idx, i, alg = ALG_WEP;
856 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
859 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
861 idx = erq->flags & IW_ENCODE_INDEX;
863 if (sdata->default_key)
864 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
865 if (sdata->default_key == sdata->keys[i]) {
870 } else if (idx < 1 || idx > 4)
875 if (erq->flags & IW_ENCODE_DISABLED)
877 else if (erq->length == 0) {
878 /* No key data - just set the default TX key index */
879 ieee80211_set_default_key(sdata, idx);
883 return ieee80211_set_encryption(
887 keybuf, erq->length);
891 static int ieee80211_ioctl_giwencode(struct net_device *dev,
892 struct iw_request_info *info,
893 struct iw_point *erq, char *key)
895 struct ieee80211_sub_if_data *sdata;
898 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
900 idx = erq->flags & IW_ENCODE_INDEX;
901 if (idx < 1 || idx > 4) {
903 if (!sdata->default_key)
905 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
906 if (sdata->default_key == sdata->keys[i]) {
916 erq->flags = idx + 1;
918 if (!sdata->keys[idx]) {
920 erq->flags |= IW_ENCODE_DISABLED;
924 memcpy(key, sdata->keys[idx]->conf.key,
925 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
926 erq->length = sdata->keys[idx]->conf.keylen;
927 erq->flags |= IW_ENCODE_ENABLED;
932 static int ieee80211_ioctl_siwauth(struct net_device *dev,
933 struct iw_request_info *info,
934 struct iw_param *data, char *extra)
936 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
939 switch (data->flags & IW_AUTH_INDEX) {
940 case IW_AUTH_WPA_VERSION:
941 case IW_AUTH_CIPHER_PAIRWISE:
942 case IW_AUTH_CIPHER_GROUP:
943 case IW_AUTH_WPA_ENABLED:
944 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
945 case IW_AUTH_KEY_MGMT:
947 case IW_AUTH_DROP_UNENCRYPTED:
948 sdata->drop_unencrypted = !!data->value;
950 case IW_AUTH_PRIVACY_INVOKED:
951 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
954 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
956 * Privacy invoked by wpa_supplicant, store the
957 * value and allow associating to a protected
958 * network without having a key up front.
961 sdata->u.sta.flags |=
962 IEEE80211_STA_PRIVACY_INVOKED;
965 case IW_AUTH_80211_AUTH_ALG:
966 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
967 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
968 sdata->u.sta.auth_algs = data->value;
979 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
980 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
982 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
983 struct iw_statistics *wstats = &local->wstats;
984 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
985 struct sta_info *sta = NULL;
987 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
988 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
989 sta = sta_info_get(local, sdata->u.sta.bssid);
991 wstats->discard.fragment = 0;
992 wstats->discard.misc = 0;
993 wstats->qual.qual = 0;
994 wstats->qual.level = 0;
995 wstats->qual.noise = 0;
996 wstats->qual.updated = IW_QUAL_ALL_INVALID;
998 wstats->qual.level = sta->last_rssi;
999 wstats->qual.qual = sta->last_signal;
1000 wstats->qual.noise = sta->last_noise;
1001 wstats->qual.updated = local->wstats_flags;
1006 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1007 struct iw_request_info *info,
1008 struct iw_param *data, char *extra)
1010 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1013 switch (data->flags & IW_AUTH_INDEX) {
1014 case IW_AUTH_80211_AUTH_ALG:
1015 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1016 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
1017 data->value = sdata->u.sta.auth_algs;
1029 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1030 struct iw_request_info *info,
1031 struct iw_point *erq, char *extra)
1033 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1034 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1035 int uninitialized_var(alg), idx, i, remove = 0;
1038 case IW_ENCODE_ALG_NONE:
1041 case IW_ENCODE_ALG_WEP:
1044 case IW_ENCODE_ALG_TKIP:
1047 case IW_ENCODE_ALG_CCMP:
1054 if (erq->flags & IW_ENCODE_DISABLED)
1057 idx = erq->flags & IW_ENCODE_INDEX;
1058 if (idx < 1 || idx > 4) {
1060 if (!sdata->default_key)
1062 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1063 if (sdata->default_key == sdata->keys[i]) {
1073 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
1076 IW_ENCODE_EXT_SET_TX_KEY,
1077 ext->key, ext->key_len);
1081 /* Structures to export the Wireless Handlers */
1083 static const iw_handler ieee80211_handler[] =
1085 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1086 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1087 (iw_handler) NULL, /* SIOCSIWNWID */
1088 (iw_handler) NULL, /* SIOCGIWNWID */
1089 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1090 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1091 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1092 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1093 (iw_handler) NULL, /* SIOCSIWSENS */
1094 (iw_handler) NULL, /* SIOCGIWSENS */
1095 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1096 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1097 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1098 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1099 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1100 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1101 (iw_handler) NULL, /* SIOCSIWSPY */
1102 (iw_handler) NULL, /* SIOCGIWSPY */
1103 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1104 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1105 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1106 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1107 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1108 (iw_handler) NULL, /* SIOCGIWAPLIST */
1109 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1110 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1111 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1112 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1113 (iw_handler) NULL, /* SIOCSIWNICKN */
1114 (iw_handler) NULL, /* SIOCGIWNICKN */
1115 (iw_handler) NULL, /* -- hole -- */
1116 (iw_handler) NULL, /* -- hole -- */
1117 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1118 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1119 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1120 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1121 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1122 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1123 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1124 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1125 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1126 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1127 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1128 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1129 (iw_handler) NULL, /* SIOCSIWPOWER */
1130 (iw_handler) NULL, /* SIOCGIWPOWER */
1131 (iw_handler) NULL, /* -- hole -- */
1132 (iw_handler) NULL, /* -- hole -- */
1133 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1134 (iw_handler) NULL, /* SIOCGIWGENIE */
1135 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1136 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1137 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1138 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1139 (iw_handler) NULL, /* SIOCSIWPMKSA */
1140 (iw_handler) NULL, /* -- hole -- */
1143 const struct iw_handler_def ieee80211_iw_handler_def =
1145 .num_standard = ARRAY_SIZE(ieee80211_handler),
1146 .standard = (iw_handler *) ieee80211_handler,
1147 .get_wireless_stats = ieee80211_get_wireless_stats,