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, SIOCGIWTHRSPY);
225 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
226 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
228 range->scan_capa |= IW_SCAN_CAPA_ESSID;
234 static int ieee80211_ioctl_siwmode(struct net_device *dev,
235 struct iw_request_info *info,
236 __u32 *mode, char *extra)
238 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
241 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
246 type = IEEE80211_IF_TYPE_STA;
249 type = IEEE80211_IF_TYPE_IBSS;
252 type = IEEE80211_IF_TYPE_WDS;
254 case IW_MODE_MONITOR:
255 type = IEEE80211_IF_TYPE_MNTR;
261 if (type == sdata->vif.type)
263 if (netif_running(dev))
266 ieee80211_if_reinit(dev);
267 ieee80211_if_set_type(dev, type);
273 static int ieee80211_ioctl_giwmode(struct net_device *dev,
274 struct iw_request_info *info,
275 __u32 *mode, char *extra)
277 struct ieee80211_sub_if_data *sdata;
279 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
280 switch (sdata->vif.type) {
281 case IEEE80211_IF_TYPE_AP:
282 *mode = IW_MODE_MASTER;
284 case IEEE80211_IF_TYPE_STA:
285 *mode = IW_MODE_INFRA;
287 case IEEE80211_IF_TYPE_IBSS:
288 *mode = IW_MODE_ADHOC;
290 case IEEE80211_IF_TYPE_MNTR:
291 *mode = IW_MODE_MONITOR;
293 case IEEE80211_IF_TYPE_WDS:
294 *mode = IW_MODE_REPEAT;
296 case IEEE80211_IF_TYPE_VLAN:
297 *mode = IW_MODE_SECOND; /* FIXME */
300 *mode = IW_MODE_AUTO;
306 int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
309 struct ieee80211_channel *chan;
311 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
313 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
314 local->oper_channel = chan;
316 if (local->sta_sw_scanning || local->sta_hw_scanning)
319 ret = ieee80211_hw_config(local);
321 rate_control_clear(local);
327 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
328 struct iw_request_info *info,
329 struct iw_freq *freq, char *extra)
331 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
332 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
334 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
335 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
337 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
340 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
341 sdata->u.sta.flags |=
342 IEEE80211_STA_AUTO_CHANNEL_SEL;
345 return ieee80211_set_freq(local,
346 ieee80211_channel_to_frequency(freq->m));
348 int i, div = 1000000;
349 for (i = 0; i < freq->e; i++)
352 return ieee80211_set_freq(local, freq->m / div);
359 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
360 struct iw_request_info *info,
361 struct iw_freq *freq, char *extra)
363 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
365 freq->m = local->hw.conf.channel->center_freq;
372 static int ieee80211_ioctl_siwessid(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_point *data, char *ssid)
376 struct ieee80211_sub_if_data *sdata;
377 size_t len = data->length;
379 /* iwconfig uses nul termination in SSID.. */
380 if (len > 0 && ssid[len - 1] == '\0')
383 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
384 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
385 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
387 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
388 if (len > IEEE80211_MAX_SSID_LEN)
390 memcpy(sdata->u.sta.ssid, ssid, len);
391 sdata->u.sta.ssid_len = len;
395 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
397 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
398 ret = ieee80211_sta_set_ssid(dev, ssid, len);
401 ieee80211_sta_req_auth(dev, &sdata->u.sta);
405 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
406 memcpy(sdata->u.ap.ssid, ssid, len);
407 memset(sdata->u.ap.ssid + len, 0,
408 IEEE80211_MAX_SSID_LEN - len);
409 sdata->u.ap.ssid_len = len;
410 return ieee80211_if_config(dev);
416 static int ieee80211_ioctl_giwessid(struct net_device *dev,
417 struct iw_request_info *info,
418 struct iw_point *data, char *ssid)
422 struct ieee80211_sub_if_data *sdata;
423 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
424 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
425 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
426 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
435 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
436 len = sdata->u.ap.ssid_len;
437 if (len > IW_ESSID_MAX_SIZE)
438 len = IW_ESSID_MAX_SIZE;
439 memcpy(ssid, sdata->u.ap.ssid, len);
448 static int ieee80211_ioctl_siwap(struct net_device *dev,
449 struct iw_request_info *info,
450 struct sockaddr *ap_addr, char *extra)
452 struct ieee80211_sub_if_data *sdata;
454 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
455 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
456 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
458 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
459 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
463 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
464 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
465 IEEE80211_STA_AUTO_CHANNEL_SEL;
466 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
467 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
469 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
470 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
473 ieee80211_sta_req_auth(dev, &sdata->u.sta);
475 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
477 * If it is necessary to update the WDS peer address
478 * while the interface is running, then we need to do
479 * more work here, namely if it is running we need to
480 * add a new and remove the old STA entry, this is
481 * normally handled by _open() and _stop().
483 if (netif_running(dev))
486 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
496 static int ieee80211_ioctl_giwap(struct net_device *dev,
497 struct iw_request_info *info,
498 struct sockaddr *ap_addr, char *extra)
500 struct ieee80211_sub_if_data *sdata;
502 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
503 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
504 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
505 ap_addr->sa_family = ARPHRD_ETHER;
506 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
508 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
509 ap_addr->sa_family = ARPHRD_ETHER;
510 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
518 static int ieee80211_ioctl_siwscan(struct net_device *dev,
519 struct iw_request_info *info,
520 union iwreq_data *wrqu, char *extra)
522 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
523 struct iw_scan_req *req = NULL;
527 if (!netif_running(dev))
530 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
531 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
532 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
533 sdata->vif.type != IEEE80211_IF_TYPE_AP)
536 /* if SSID was specified explicitly then use that */
537 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
538 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
539 req = (struct iw_scan_req *)extra;
541 ssid_len = req->essid_len;
544 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
548 static int ieee80211_ioctl_giwscan(struct net_device *dev,
549 struct iw_request_info *info,
550 struct iw_point *data, char *extra)
553 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
555 if (local->sta_sw_scanning || local->sta_hw_scanning)
558 res = ieee80211_sta_scan_results(dev, extra, data->length);
568 static int ieee80211_ioctl_siwrate(struct net_device *dev,
569 struct iw_request_info *info,
570 struct iw_param *rate, char *extra)
572 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
573 int i, err = -EINVAL;
574 u32 target_rate = rate->value / 100000;
575 struct ieee80211_sub_if_data *sdata;
576 struct ieee80211_supported_band *sband;
578 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
582 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
584 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
585 * target_rate = X, rate->fixed = 1 means only rate X
586 * target_rate = X, rate->fixed = 0 means all rates <= X */
587 sdata->bss->max_ratectrl_rateidx = -1;
588 sdata->bss->force_unicast_rateidx = -1;
592 for (i=0; i< sband->n_bitrates; i++) {
593 struct ieee80211_rate *brate = &sband->bitrates[i];
594 int this_rate = brate->bitrate;
596 if (target_rate == this_rate) {
597 sdata->bss->max_ratectrl_rateidx = i;
599 sdata->bss->force_unicast_rateidx = i;
607 static int ieee80211_ioctl_giwrate(struct net_device *dev,
608 struct iw_request_info *info,
609 struct iw_param *rate, char *extra)
611 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
612 struct sta_info *sta;
613 struct ieee80211_sub_if_data *sdata;
614 struct ieee80211_supported_band *sband;
616 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
618 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
621 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
625 sta = sta_info_get(local, sdata->u.sta.bssid);
627 if (sta && sta->txrate_idx < sband->n_bitrates)
628 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
637 rate->value *= 100000;
642 static int ieee80211_ioctl_siwtxpower(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);
647 bool need_reconfig = 0;
650 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
652 if (data->txpower.flags & IW_TXPOW_RANGE)
655 if (data->txpower.fixed) {
656 new_power_level = data->txpower.value;
659 * Automatic power level. Use maximum power for the current
660 * channel. Should be part of rate control.
662 struct ieee80211_channel* chan = local->hw.conf.channel;
666 new_power_level = chan->max_power;
669 if (local->hw.conf.power_level != new_power_level) {
670 local->hw.conf.power_level = new_power_level;
674 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
675 local->hw.conf.radio_enabled = !(data->txpower.disabled);
677 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
681 ieee80211_hw_config(local);
682 /* The return value of hw_config is not of big interest here,
683 * as it doesn't say that it failed because of _this_ config
684 * change or something else. Ignore it. */
690 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
691 struct iw_request_info *info,
692 union iwreq_data *data, char *extra)
694 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
696 data->txpower.fixed = 1;
697 data->txpower.disabled = !(local->hw.conf.radio_enabled);
698 data->txpower.value = local->hw.conf.power_level;
699 data->txpower.flags = IW_TXPOW_DBM;
704 static int ieee80211_ioctl_siwrts(struct net_device *dev,
705 struct iw_request_info *info,
706 struct iw_param *rts, char *extra)
708 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
711 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
712 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
715 local->rts_threshold = rts->value;
717 /* If the wlan card performs RTS/CTS in hardware/firmware,
718 * configure it here */
720 if (local->ops->set_rts_threshold)
721 local->ops->set_rts_threshold(local_to_hw(local),
722 local->rts_threshold);
727 static int ieee80211_ioctl_giwrts(struct net_device *dev,
728 struct iw_request_info *info,
729 struct iw_param *rts, char *extra)
731 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
733 rts->value = local->rts_threshold;
734 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
741 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
742 struct iw_request_info *info,
743 struct iw_param *frag, char *extra)
745 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
748 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
749 else if (frag->value < 256 ||
750 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
753 /* Fragment length must be even, so strip LSB. */
754 local->fragmentation_threshold = frag->value & ~0x1;
757 /* If the wlan card performs fragmentation in hardware/firmware,
758 * configure it here */
760 if (local->ops->set_frag_threshold)
761 local->ops->set_frag_threshold(
763 local->fragmentation_threshold);
768 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
769 struct iw_request_info *info,
770 struct iw_param *frag, char *extra)
772 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
774 frag->value = local->fragmentation_threshold;
775 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
782 static int ieee80211_ioctl_siwretry(struct net_device *dev,
783 struct iw_request_info *info,
784 struct iw_param *retry, char *extra)
786 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
788 if (retry->disabled ||
789 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
792 if (retry->flags & IW_RETRY_MAX)
793 local->long_retry_limit = retry->value;
794 else if (retry->flags & IW_RETRY_MIN)
795 local->short_retry_limit = retry->value;
797 local->long_retry_limit = retry->value;
798 local->short_retry_limit = retry->value;
801 if (local->ops->set_retry_limit) {
802 return local->ops->set_retry_limit(
804 local->short_retry_limit,
805 local->long_retry_limit);
812 static int ieee80211_ioctl_giwretry(struct net_device *dev,
813 struct iw_request_info *info,
814 struct iw_param *retry, char *extra)
816 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
819 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
820 /* first return min value, iwconfig will ask max value
822 retry->flags |= IW_RETRY_LIMIT;
823 retry->value = local->short_retry_limit;
824 if (local->long_retry_limit != local->short_retry_limit)
825 retry->flags |= IW_RETRY_MIN;
828 if (retry->flags & IW_RETRY_MAX) {
829 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
830 retry->value = local->long_retry_limit;
836 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
837 struct iw_request_info *info,
838 struct iw_point *data, char *extra)
840 struct ieee80211_sub_if_data *sdata;
841 struct iw_mlme *mlme = (struct iw_mlme *) extra;
843 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
844 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
845 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
850 /* TODO: mlme->addr.sa_data */
851 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
852 case IW_MLME_DISASSOC:
853 /* TODO: mlme->addr.sa_data */
854 return ieee80211_sta_disassociate(dev, mlme->reason_code);
861 static int ieee80211_ioctl_siwencode(struct net_device *dev,
862 struct iw_request_info *info,
863 struct iw_point *erq, char *keybuf)
865 struct ieee80211_sub_if_data *sdata;
866 int idx, i, alg = ALG_WEP;
867 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
870 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
872 idx = erq->flags & IW_ENCODE_INDEX;
874 if (sdata->default_key)
875 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
876 if (sdata->default_key == sdata->keys[i]) {
881 } else if (idx < 1 || idx > 4)
886 if (erq->flags & IW_ENCODE_DISABLED)
888 else if (erq->length == 0) {
889 /* No key data - just set the default TX key index */
890 ieee80211_set_default_key(sdata, idx);
894 return ieee80211_set_encryption(
898 keybuf, erq->length);
902 static int ieee80211_ioctl_giwencode(struct net_device *dev,
903 struct iw_request_info *info,
904 struct iw_point *erq, char *key)
906 struct ieee80211_sub_if_data *sdata;
909 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
911 idx = erq->flags & IW_ENCODE_INDEX;
912 if (idx < 1 || idx > 4) {
914 if (!sdata->default_key)
916 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
917 if (sdata->default_key == sdata->keys[i]) {
927 erq->flags = idx + 1;
929 if (!sdata->keys[idx]) {
931 erq->flags |= IW_ENCODE_DISABLED;
935 memcpy(key, sdata->keys[idx]->conf.key,
936 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
937 erq->length = sdata->keys[idx]->conf.keylen;
938 erq->flags |= IW_ENCODE_ENABLED;
943 static int ieee80211_ioctl_siwauth(struct net_device *dev,
944 struct iw_request_info *info,
945 struct iw_param *data, char *extra)
947 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
950 switch (data->flags & IW_AUTH_INDEX) {
951 case IW_AUTH_WPA_VERSION:
952 case IW_AUTH_CIPHER_PAIRWISE:
953 case IW_AUTH_CIPHER_GROUP:
954 case IW_AUTH_WPA_ENABLED:
955 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
956 case IW_AUTH_KEY_MGMT:
958 case IW_AUTH_DROP_UNENCRYPTED:
959 sdata->drop_unencrypted = !!data->value;
961 case IW_AUTH_PRIVACY_INVOKED:
962 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
965 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
967 * Privacy invoked by wpa_supplicant, store the
968 * value and allow associating to a protected
969 * network without having a key up front.
972 sdata->u.sta.flags |=
973 IEEE80211_STA_PRIVACY_INVOKED;
976 case IW_AUTH_80211_AUTH_ALG:
977 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
978 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
979 sdata->u.sta.auth_algs = data->value;
990 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
991 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
993 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
994 struct iw_statistics *wstats = &local->wstats;
995 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
996 struct sta_info *sta = NULL;
1000 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1001 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
1002 sta = sta_info_get(local, sdata->u.sta.bssid);
1004 wstats->discard.fragment = 0;
1005 wstats->discard.misc = 0;
1006 wstats->qual.qual = 0;
1007 wstats->qual.level = 0;
1008 wstats->qual.noise = 0;
1009 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1011 wstats->qual.level = sta->last_signal;
1012 wstats->qual.qual = sta->last_qual;
1013 wstats->qual.noise = sta->last_noise;
1014 wstats->qual.updated = local->wstats_flags;
1022 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1023 struct iw_request_info *info,
1024 struct iw_param *data, char *extra)
1026 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1029 switch (data->flags & IW_AUTH_INDEX) {
1030 case IW_AUTH_80211_AUTH_ALG:
1031 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1032 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
1033 data->value = sdata->u.sta.auth_algs;
1045 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1046 struct iw_request_info *info,
1047 struct iw_point *erq, char *extra)
1049 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1050 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1051 int uninitialized_var(alg), idx, i, remove = 0;
1054 case IW_ENCODE_ALG_NONE:
1057 case IW_ENCODE_ALG_WEP:
1060 case IW_ENCODE_ALG_TKIP:
1063 case IW_ENCODE_ALG_CCMP:
1070 if (erq->flags & IW_ENCODE_DISABLED)
1073 idx = erq->flags & IW_ENCODE_INDEX;
1074 if (idx < 1 || idx > 4) {
1076 if (!sdata->default_key)
1078 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1079 if (sdata->default_key == sdata->keys[i]) {
1089 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
1092 IW_ENCODE_EXT_SET_TX_KEY,
1093 ext->key, ext->key_len);
1097 /* Structures to export the Wireless Handlers */
1099 static const iw_handler ieee80211_handler[] =
1101 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1102 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1103 (iw_handler) NULL, /* SIOCSIWNWID */
1104 (iw_handler) NULL, /* SIOCGIWNWID */
1105 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1106 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1107 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1108 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1109 (iw_handler) NULL, /* SIOCSIWSENS */
1110 (iw_handler) NULL, /* SIOCGIWSENS */
1111 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1112 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1113 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1114 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1115 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1116 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1117 (iw_handler) NULL, /* SIOCSIWSPY */
1118 (iw_handler) NULL, /* SIOCGIWSPY */
1119 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1120 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1121 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1122 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1123 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1124 (iw_handler) NULL, /* SIOCGIWAPLIST */
1125 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1126 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1127 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1128 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1129 (iw_handler) NULL, /* SIOCSIWNICKN */
1130 (iw_handler) NULL, /* SIOCGIWNICKN */
1131 (iw_handler) NULL, /* -- hole -- */
1132 (iw_handler) NULL, /* -- hole -- */
1133 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1134 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1135 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1136 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1137 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1138 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1139 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1140 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1141 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1142 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1143 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1144 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1145 (iw_handler) NULL, /* SIOCSIWPOWER */
1146 (iw_handler) NULL, /* SIOCGIWPOWER */
1147 (iw_handler) NULL, /* -- hole -- */
1148 (iw_handler) NULL, /* -- hole -- */
1149 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1150 (iw_handler) NULL, /* SIOCGIWGENIE */
1151 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1152 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1153 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1154 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1155 (iw_handler) NULL, /* SIOCSIWPMKSA */
1156 (iw_handler) NULL, /* -- hole -- */
1159 const struct iw_handler_def ieee80211_iw_handler_def =
1161 .num_standard = ARRAY_SIZE(ieee80211_handler),
1162 .standard = (iw_handler *) ieee80211_handler,
1163 .get_wireless_stats = ieee80211_get_wireless_stats,