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 (alg == ALG_AES_CMAC) {
41 if (idx < NUM_DEFAULT_KEYS ||
42 idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
43 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d "
44 "(BIP)\n", sdata->dev->name, idx);
47 } else if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
48 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
49 sdata->dev->name, idx);
58 if (is_broadcast_ether_addr(sta_addr)) {
59 key = sdata->keys[idx];
61 sta = sta_info_get(local, sta_addr);
69 ieee80211_key_free(key);
71 key = ieee80211_key_alloc(alg, idx, key_len, _key);
80 if (!is_broadcast_ether_addr(sta_addr)) {
83 * According to the standard, the key index of a
84 * pairwise key must be zero. However, some AP are
85 * broken when it comes to WEP key indices, so we
88 if (idx != 0 && alg != ALG_WEP) {
89 ieee80211_key_free(key);
94 sta = sta_info_get(local, sta_addr);
96 ieee80211_key_free(key);
102 if (alg == ALG_WEP &&
103 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
104 ieee80211_key_free(key);
109 ieee80211_key_link(key, sdata, sta);
111 if (set_tx_key || (!sta && !sdata->default_key && key))
112 ieee80211_set_default_key(sdata, idx);
113 if (alg == ALG_AES_CMAC &&
114 (set_tx_key || (!sta && !sdata->default_mgmt_key && key)))
115 ieee80211_set_default_mgmt_key(sdata, idx);
124 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
125 struct iw_request_info *info,
126 struct iw_point *data, char *extra)
128 struct ieee80211_sub_if_data *sdata;
130 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
132 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
135 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
136 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
137 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
140 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
141 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
148 static int ieee80211_ioctl_giwrange(struct net_device *dev,
149 struct iw_request_info *info,
150 struct iw_point *data, char *extra)
152 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
153 struct iw_range *range = (struct iw_range *) extra;
154 enum ieee80211_band band;
157 data->length = sizeof(struct iw_range);
158 memset(range, 0, sizeof(struct iw_range));
160 range->we_version_compiled = WIRELESS_EXT;
161 range->we_version_source = 21;
162 range->retry_capa = IW_RETRY_LIMIT;
163 range->retry_flags = IW_RETRY_LIMIT;
164 range->min_retry = 0;
165 range->max_retry = 255;
167 range->max_rts = 2347;
168 range->min_frag = 256;
169 range->max_frag = 2346;
171 range->encoding_size[0] = 5;
172 range->encoding_size[1] = 13;
173 range->num_encoding_sizes = 2;
174 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
176 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
177 range->max_qual.level = local->hw.max_signal;
178 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
179 range->max_qual.level = -110;
181 range->max_qual.level = 0;
183 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
184 range->max_qual.noise = -110;
186 range->max_qual.noise = 0;
188 range->max_qual.qual = 100;
189 range->max_qual.updated = local->wstats_flags;
191 range->avg_qual.qual = 50;
192 /* not always true but better than nothing */
193 range->avg_qual.level = range->max_qual.level / 2;
194 range->avg_qual.noise = range->max_qual.noise / 2;
195 range->avg_qual.updated = local->wstats_flags;
197 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
198 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
201 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
203 struct ieee80211_supported_band *sband;
205 sband = local->hw.wiphy->bands[band];
210 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
211 struct ieee80211_channel *chan = &sband->channels[i];
213 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
215 ieee80211_frequency_to_channel(
217 range->freq[c].m = chan->center_freq;
218 range->freq[c].e = 6;
223 range->num_channels = c;
224 range->num_frequency = c;
226 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
227 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
228 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
230 range->scan_capa |= IW_SCAN_CAPA_ESSID;
236 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
237 struct iw_request_info *info,
238 struct iw_freq *freq, char *extra)
240 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
242 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
243 sdata->vif.type == NL80211_IFTYPE_STATION)
244 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
246 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
249 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
250 sdata->vif.type == NL80211_IFTYPE_STATION)
251 sdata->u.sta.flags |=
252 IEEE80211_STA_AUTO_CHANNEL_SEL;
255 return ieee80211_set_freq(sdata,
256 ieee80211_channel_to_frequency(freq->m));
258 int i, div = 1000000;
259 for (i = 0; i < freq->e; i++)
262 return ieee80211_set_freq(sdata, freq->m / div);
269 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
270 struct iw_request_info *info,
271 struct iw_freq *freq, char *extra)
273 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
275 freq->m = local->hw.conf.channel->center_freq;
282 static int ieee80211_ioctl_siwessid(struct net_device *dev,
283 struct iw_request_info *info,
284 struct iw_point *data, char *ssid)
286 struct ieee80211_sub_if_data *sdata;
287 size_t len = data->length;
289 /* iwconfig uses nul termination in SSID.. */
290 if (len > 0 && ssid[len - 1] == '\0')
293 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
294 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
295 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
297 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
298 if (len > IEEE80211_MAX_SSID_LEN)
300 memcpy(sdata->u.sta.ssid, ssid, len);
301 sdata->u.sta.ssid_len = len;
305 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
307 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
308 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
311 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
319 static int ieee80211_ioctl_giwessid(struct net_device *dev,
320 struct iw_request_info *info,
321 struct iw_point *data, char *ssid)
325 struct ieee80211_sub_if_data *sdata;
326 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
327 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
328 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
329 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
342 static int ieee80211_ioctl_siwap(struct net_device *dev,
343 struct iw_request_info *info,
344 struct sockaddr *ap_addr, char *extra)
346 struct ieee80211_sub_if_data *sdata;
348 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
349 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
350 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
352 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
353 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
357 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
358 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
359 IEEE80211_STA_AUTO_CHANNEL_SEL;
360 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
361 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
363 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
364 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
367 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
369 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
371 * If it is necessary to update the WDS peer address
372 * while the interface is running, then we need to do
373 * more work here, namely if it is running we need to
374 * add a new and remove the old STA entry, this is
375 * normally handled by _open() and _stop().
377 if (netif_running(dev))
380 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
390 static int ieee80211_ioctl_giwap(struct net_device *dev,
391 struct iw_request_info *info,
392 struct sockaddr *ap_addr, char *extra)
394 struct ieee80211_sub_if_data *sdata;
396 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
397 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
398 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
399 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
400 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
401 ap_addr->sa_family = ARPHRD_ETHER;
402 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
405 memset(&ap_addr->sa_data, 0, ETH_ALEN);
408 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
409 ap_addr->sa_family = ARPHRD_ETHER;
410 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
418 static int ieee80211_ioctl_siwscan(struct net_device *dev,
419 struct iw_request_info *info,
420 union iwreq_data *wrqu, char *extra)
422 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
423 struct iw_scan_req *req = NULL;
427 if (!netif_running(dev))
430 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
431 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
432 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
435 /* if SSID was specified explicitly then use that */
436 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
437 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
438 req = (struct iw_scan_req *)extra;
440 ssid_len = req->essid_len;
443 return ieee80211_request_scan(sdata, ssid, ssid_len);
447 static int ieee80211_ioctl_giwscan(struct net_device *dev,
448 struct iw_request_info *info,
449 struct iw_point *data, char *extra)
452 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
453 struct ieee80211_sub_if_data *sdata;
455 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
457 if (local->sw_scanning || local->hw_scanning)
460 res = ieee80211_scan_results(local, info, extra, data->length);
470 static int ieee80211_ioctl_siwrate(struct net_device *dev,
471 struct iw_request_info *info,
472 struct iw_param *rate, char *extra)
474 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
475 int i, err = -EINVAL;
476 u32 target_rate = rate->value / 100000;
477 struct ieee80211_sub_if_data *sdata;
478 struct ieee80211_supported_band *sband;
480 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
482 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
484 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
485 * target_rate = X, rate->fixed = 1 means only rate X
486 * target_rate = X, rate->fixed = 0 means all rates <= X */
487 sdata->max_ratectrl_rateidx = -1;
488 sdata->force_unicast_rateidx = -1;
492 for (i=0; i< sband->n_bitrates; i++) {
493 struct ieee80211_rate *brate = &sband->bitrates[i];
494 int this_rate = brate->bitrate;
496 if (target_rate == this_rate) {
497 sdata->max_ratectrl_rateidx = i;
499 sdata->force_unicast_rateidx = i;
507 static int ieee80211_ioctl_giwrate(struct net_device *dev,
508 struct iw_request_info *info,
509 struct iw_param *rate, char *extra)
511 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
512 struct sta_info *sta;
513 struct ieee80211_sub_if_data *sdata;
514 struct ieee80211_supported_band *sband;
516 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
518 if (sdata->vif.type != NL80211_IFTYPE_STATION)
521 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
525 sta = sta_info_get(local, sdata->u.sta.bssid);
527 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
528 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
537 rate->value *= 100000;
542 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
543 struct iw_request_info *info,
544 union iwreq_data *data, char *extra)
546 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
547 struct ieee80211_channel* chan = local->hw.conf.channel;
548 u32 reconf_flags = 0;
551 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
553 if (data->txpower.flags & IW_TXPOW_RANGE)
558 if (data->txpower.fixed)
559 new_power_level = min(data->txpower.value, chan->max_power);
560 else /* Automatic power level setting */
561 new_power_level = chan->max_power;
563 local->user_power_level = new_power_level;
564 if (local->hw.conf.power_level != new_power_level)
565 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
567 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
568 local->hw.conf.radio_enabled = !(data->txpower.disabled);
569 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
570 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
574 ieee80211_hw_config(local, reconf_flags);
579 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
580 struct iw_request_info *info,
581 union iwreq_data *data, char *extra)
583 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
585 data->txpower.fixed = 1;
586 data->txpower.disabled = !(local->hw.conf.radio_enabled);
587 data->txpower.value = local->hw.conf.power_level;
588 data->txpower.flags = IW_TXPOW_DBM;
593 static int ieee80211_ioctl_siwrts(struct net_device *dev,
594 struct iw_request_info *info,
595 struct iw_param *rts, char *extra)
597 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
600 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
601 else if (!rts->fixed)
602 /* if the rts value is not fixed, then take default */
603 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
604 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
607 local->rts_threshold = rts->value;
609 /* If the wlan card performs RTS/CTS in hardware/firmware,
610 * configure it here */
612 if (local->ops->set_rts_threshold)
613 local->ops->set_rts_threshold(local_to_hw(local),
614 local->rts_threshold);
619 static int ieee80211_ioctl_giwrts(struct net_device *dev,
620 struct iw_request_info *info,
621 struct iw_param *rts, char *extra)
623 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
625 rts->value = local->rts_threshold;
626 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
633 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
634 struct iw_request_info *info,
635 struct iw_param *frag, char *extra)
637 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
640 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
641 else if (!frag->fixed)
642 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
643 else if (frag->value < 256 ||
644 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
647 /* Fragment length must be even, so strip LSB. */
648 local->fragmentation_threshold = frag->value & ~0x1;
654 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
655 struct iw_request_info *info,
656 struct iw_param *frag, char *extra)
658 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
660 frag->value = local->fragmentation_threshold;
661 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
668 static int ieee80211_ioctl_siwretry(struct net_device *dev,
669 struct iw_request_info *info,
670 struct iw_param *retry, char *extra)
672 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
674 if (retry->disabled ||
675 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
678 if (retry->flags & IW_RETRY_MAX) {
679 local->hw.conf.long_frame_max_tx_count = retry->value;
680 } else if (retry->flags & IW_RETRY_MIN) {
681 local->hw.conf.short_frame_max_tx_count = retry->value;
683 local->hw.conf.long_frame_max_tx_count = retry->value;
684 local->hw.conf.short_frame_max_tx_count = retry->value;
687 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
693 static int ieee80211_ioctl_giwretry(struct net_device *dev,
694 struct iw_request_info *info,
695 struct iw_param *retry, char *extra)
697 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
700 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
701 /* first return min value, iwconfig will ask max value
703 retry->flags |= IW_RETRY_LIMIT;
704 retry->value = local->hw.conf.short_frame_max_tx_count;
705 if (local->hw.conf.long_frame_max_tx_count !=
706 local->hw.conf.short_frame_max_tx_count)
707 retry->flags |= IW_RETRY_MIN;
710 if (retry->flags & IW_RETRY_MAX) {
711 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
712 retry->value = local->hw.conf.long_frame_max_tx_count;
718 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
719 struct iw_request_info *info,
720 struct iw_point *data, char *extra)
722 struct ieee80211_sub_if_data *sdata;
723 struct iw_mlme *mlme = (struct iw_mlme *) extra;
725 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
726 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
727 sdata->vif.type != NL80211_IFTYPE_ADHOC)
732 /* TODO: mlme->addr.sa_data */
733 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
734 case IW_MLME_DISASSOC:
735 /* TODO: mlme->addr.sa_data */
736 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
743 static int ieee80211_ioctl_siwencode(struct net_device *dev,
744 struct iw_request_info *info,
745 struct iw_point *erq, char *keybuf)
747 struct ieee80211_sub_if_data *sdata;
748 int idx, i, alg = ALG_WEP;
749 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
752 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
754 idx = erq->flags & IW_ENCODE_INDEX;
756 if (sdata->default_key)
757 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
758 if (sdata->default_key == sdata->keys[i]) {
763 } else if (idx < 1 || idx > 4)
768 if (erq->flags & IW_ENCODE_DISABLED)
770 else if (erq->length == 0) {
771 /* No key data - just set the default TX key index */
772 ieee80211_set_default_key(sdata, idx);
776 return ieee80211_set_encryption(
780 keybuf, erq->length);
784 static int ieee80211_ioctl_giwencode(struct net_device *dev,
785 struct iw_request_info *info,
786 struct iw_point *erq, char *key)
788 struct ieee80211_sub_if_data *sdata;
791 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
793 idx = erq->flags & IW_ENCODE_INDEX;
794 if (idx < 1 || idx > 4) {
796 if (!sdata->default_key)
798 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
799 if (sdata->default_key == sdata->keys[i]) {
809 erq->flags = idx + 1;
811 if (!sdata->keys[idx]) {
813 erq->flags |= IW_ENCODE_DISABLED;
817 memcpy(key, sdata->keys[idx]->conf.key,
818 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
819 erq->length = sdata->keys[idx]->conf.keylen;
820 erq->flags |= IW_ENCODE_ENABLED;
822 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
823 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
824 switch (ifsta->auth_alg) {
827 erq->flags |= IW_ENCODE_OPEN;
829 case WLAN_AUTH_SHARED_KEY:
830 erq->flags |= IW_ENCODE_RESTRICTED;
838 static int ieee80211_ioctl_siwpower(struct net_device *dev,
839 struct iw_request_info *info,
840 struct iw_param *wrq,
843 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
844 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
845 struct ieee80211_conf *conf = &local->hw.conf;
846 int ret = 0, timeout = 0;
849 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
852 if (sdata->vif.type != NL80211_IFTYPE_STATION)
861 switch (wrq->flags & IW_POWER_MODE) {
862 case IW_POWER_ON: /* If not specified */
863 case IW_POWER_MODE: /* If set all mask */
864 case IW_POWER_ALL_R: /* If explicitely state all */
867 default: /* Otherwise we ignore */
871 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
874 if (wrq->flags & IW_POWER_TIMEOUT)
875 timeout = wrq->value / 1000;
878 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
881 local->powersave = ps;
882 conf->dynamic_ps_timeout = timeout;
884 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
885 ret = ieee80211_hw_config(local,
886 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
888 if (!(sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
891 if (conf->dynamic_ps_timeout > 0 &&
892 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
893 mod_timer(&local->dynamic_ps_timer, jiffies +
894 msecs_to_jiffies(conf->dynamic_ps_timeout));
896 if (local->powersave) {
897 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
898 ieee80211_send_nullfunc(local, sdata, 1);
899 conf->flags |= IEEE80211_CONF_PS;
900 ret = ieee80211_hw_config(local,
901 IEEE80211_CONF_CHANGE_PS);
903 conf->flags &= ~IEEE80211_CONF_PS;
904 ret = ieee80211_hw_config(local,
905 IEEE80211_CONF_CHANGE_PS);
906 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
907 ieee80211_send_nullfunc(local, sdata, 0);
908 del_timer_sync(&local->dynamic_ps_timer);
909 cancel_work_sync(&local->dynamic_ps_enable_work);
916 static int ieee80211_ioctl_giwpower(struct net_device *dev,
917 struct iw_request_info *info,
918 union iwreq_data *wrqu,
921 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
923 wrqu->power.disabled = !local->powersave;
928 static int ieee80211_ioctl_siwauth(struct net_device *dev,
929 struct iw_request_info *info,
930 struct iw_param *data, char *extra)
932 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
935 switch (data->flags & IW_AUTH_INDEX) {
936 case IW_AUTH_WPA_VERSION:
937 case IW_AUTH_CIPHER_GROUP:
938 case IW_AUTH_WPA_ENABLED:
939 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
940 case IW_AUTH_KEY_MGMT:
941 case IW_AUTH_CIPHER_GROUP_MGMT:
943 case IW_AUTH_CIPHER_PAIRWISE:
944 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
945 if (data->value & (IW_AUTH_CIPHER_WEP40 |
946 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
947 sdata->u.sta.flags |=
948 IEEE80211_STA_TKIP_WEP_USED;
950 sdata->u.sta.flags &=
951 ~IEEE80211_STA_TKIP_WEP_USED;
954 case IW_AUTH_DROP_UNENCRYPTED:
955 sdata->drop_unencrypted = !!data->value;
957 case IW_AUTH_PRIVACY_INVOKED:
958 if (sdata->vif.type != NL80211_IFTYPE_STATION)
961 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
963 * Privacy invoked by wpa_supplicant, store the
964 * value and allow associating to a protected
965 * network without having a key up front.
968 sdata->u.sta.flags |=
969 IEEE80211_STA_PRIVACY_INVOKED;
972 case IW_AUTH_80211_AUTH_ALG:
973 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
974 sdata->vif.type == NL80211_IFTYPE_ADHOC)
975 sdata->u.sta.auth_algs = data->value;
980 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
984 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
985 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
986 switch (data->value) {
987 case IW_AUTH_MFP_DISABLED:
988 sdata->u.sta.mfp = IEEE80211_MFP_DISABLED;
990 case IW_AUTH_MFP_OPTIONAL:
991 sdata->u.sta.mfp = IEEE80211_MFP_OPTIONAL;
993 case IW_AUTH_MFP_REQUIRED:
994 sdata->u.sta.mfp = IEEE80211_MFP_REQUIRED;
1009 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1010 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1012 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1013 struct iw_statistics *wstats = &local->wstats;
1014 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1015 struct sta_info *sta = NULL;
1019 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1020 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1021 sta = sta_info_get(local, sdata->u.sta.bssid);
1023 wstats->discard.fragment = 0;
1024 wstats->discard.misc = 0;
1025 wstats->qual.qual = 0;
1026 wstats->qual.level = 0;
1027 wstats->qual.noise = 0;
1028 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1030 wstats->qual.level = sta->last_signal;
1031 wstats->qual.qual = sta->last_qual;
1032 wstats->qual.noise = sta->last_noise;
1033 wstats->qual.updated = local->wstats_flags;
1041 static int ieee80211_ioctl_giwauth(struct net_device *dev,
1042 struct iw_request_info *info,
1043 struct iw_param *data, char *extra)
1045 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1048 switch (data->flags & IW_AUTH_INDEX) {
1049 case IW_AUTH_80211_AUTH_ALG:
1050 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1051 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1052 data->value = sdata->u.sta.auth_algs;
1064 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1065 struct iw_request_info *info,
1066 struct iw_point *erq, char *extra)
1068 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1069 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1070 int uninitialized_var(alg), idx, i, remove = 0;
1073 case IW_ENCODE_ALG_NONE:
1076 case IW_ENCODE_ALG_WEP:
1079 case IW_ENCODE_ALG_TKIP:
1082 case IW_ENCODE_ALG_CCMP:
1085 case IW_ENCODE_ALG_AES_CMAC:
1092 if (erq->flags & IW_ENCODE_DISABLED)
1095 idx = erq->flags & IW_ENCODE_INDEX;
1096 if (alg == ALG_AES_CMAC) {
1097 if (idx < NUM_DEFAULT_KEYS + 1 ||
1098 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1100 if (!sdata->default_mgmt_key)
1102 else for (i = NUM_DEFAULT_KEYS;
1103 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1105 if (sdata->default_mgmt_key == sdata->keys[i])
1116 if (idx < 1 || idx > 4) {
1118 if (!sdata->default_key)
1120 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1121 if (sdata->default_key == sdata->keys[i]) {
1132 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1135 IW_ENCODE_EXT_SET_TX_KEY,
1136 ext->key, ext->key_len);
1140 /* Structures to export the Wireless Handlers */
1142 static const iw_handler ieee80211_handler[] =
1144 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1145 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1146 (iw_handler) NULL, /* SIOCSIWNWID */
1147 (iw_handler) NULL, /* SIOCGIWNWID */
1148 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1149 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1150 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1151 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
1152 (iw_handler) NULL, /* SIOCSIWSENS */
1153 (iw_handler) NULL, /* SIOCGIWSENS */
1154 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1155 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1156 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1157 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1158 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1159 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1160 (iw_handler) NULL, /* SIOCSIWSPY */
1161 (iw_handler) NULL, /* SIOCGIWSPY */
1162 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1163 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1164 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1165 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1166 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1167 (iw_handler) NULL, /* SIOCGIWAPLIST */
1168 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1169 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1170 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1171 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1172 (iw_handler) NULL, /* SIOCSIWNICKN */
1173 (iw_handler) NULL, /* SIOCGIWNICKN */
1174 (iw_handler) NULL, /* -- hole -- */
1175 (iw_handler) NULL, /* -- hole -- */
1176 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1177 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1178 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1179 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1180 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1181 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1182 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1183 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1184 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1185 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1186 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1187 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1188 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1189 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1190 (iw_handler) NULL, /* -- hole -- */
1191 (iw_handler) NULL, /* -- hole -- */
1192 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1193 (iw_handler) NULL, /* SIOCGIWGENIE */
1194 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1195 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1196 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1197 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1198 (iw_handler) NULL, /* SIOCSIWPMKSA */
1199 (iw_handler) NULL, /* -- hole -- */
1202 const struct iw_handler_def ieee80211_iw_handler_def =
1204 .num_standard = ARRAY_SIZE(ieee80211_handler),
1205 .standard = (iw_handler *) ieee80211_handler,
1206 .get_wireless_stats = ieee80211_get_wireless_stats,