Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * |
| 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. |
| 8 | */ |
| 9 | |
| 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> |
| 21 | |
| 22 | #include <net/mac80211.h> |
| 23 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 24 | #include "led.h" |
| 25 | #include "rate.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 26 | #include "wpa.h" |
| 27 | #include "aes_ccm.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | |
Johannes Berg | b708e61 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 29 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 30 | static int ieee80211_set_encryption(struct ieee80211_sub_if_data *sdata, u8 *sta_addr, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 31 | int idx, int alg, int remove, |
| 32 | int set_tx_key, const u8 *_key, |
| 33 | size_t key_len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 34 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 35 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 36 | struct sta_info *sta; |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 37 | struct ieee80211_key *key; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 38 | int err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 39 | |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 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); |
| 45 | return -EINVAL; |
| 46 | } |
| 47 | } else if (idx < 0 || idx >= NUM_DEFAULT_KEYS) { |
Volker Braun | 139c3a0 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 48 | printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 49 | sdata->dev->name, idx); |
Volker Braun | 139c3a0 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 50 | return -EINVAL; |
| 51 | } |
| 52 | |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 53 | if (remove) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 54 | rcu_read_lock(); |
| 55 | |
| 56 | err = 0; |
| 57 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 58 | if (is_broadcast_ether_addr(sta_addr)) { |
| 59 | key = sdata->keys[idx]; |
| 60 | } else { |
| 61 | sta = sta_info_get(local, sta_addr); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 62 | if (!sta) { |
| 63 | err = -ENOENT; |
| 64 | goto out_unlock; |
| 65 | } |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 66 | key = sta->key; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 67 | } |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 68 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 69 | ieee80211_key_free(key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 70 | } else { |
| 71 | key = ieee80211_key_alloc(alg, idx, key_len, _key); |
| 72 | if (!key) |
| 73 | return -ENOMEM; |
| 74 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 75 | sta = NULL; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 76 | err = 0; |
| 77 | |
| 78 | rcu_read_lock(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 79 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 80 | if (!is_broadcast_ether_addr(sta_addr)) { |
| 81 | set_tx_key = 0; |
| 82 | /* |
| 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 |
| 86 | * work around this. |
| 87 | */ |
| 88 | if (idx != 0 && alg != ALG_WEP) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 89 | ieee80211_key_free(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 90 | err = -EINVAL; |
| 91 | goto out_unlock; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | sta = sta_info_get(local, sta_addr); |
| 95 | if (!sta) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 96 | ieee80211_key_free(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 97 | err = -ENOENT; |
| 98 | goto out_unlock; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Emmanuel Grumbach | 23976ef | 2008-06-28 02:50:13 +0300 | [diff] [blame] | 102 | if (alg == ALG_WEP && |
| 103 | key_len != LEN_WEP40 && key_len != LEN_WEP104) { |
| 104 | ieee80211_key_free(key); |
| 105 | err = -EINVAL; |
| 106 | goto out_unlock; |
| 107 | } |
| 108 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 109 | ieee80211_key_link(key, sdata, sta); |
| 110 | |
| 111 | if (set_tx_key || (!sta && !sdata->default_key && key)) |
| 112 | ieee80211_set_default_key(sdata, idx); |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 113 | if (alg == ALG_AES_CMAC && |
| 114 | (set_tx_key || (!sta && !sdata->default_mgmt_key && key))) |
| 115 | ieee80211_set_default_mgmt_key(sdata, idx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 118 | out_unlock: |
| 119 | rcu_read_unlock(); |
| 120 | |
| 121 | return err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static int ieee80211_ioctl_siwgenie(struct net_device *dev, |
| 125 | struct iw_request_info *info, |
| 126 | struct iw_point *data, char *extra) |
| 127 | { |
| 128 | struct ieee80211_sub_if_data *sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 129 | |
| 130 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 131 | |
| 132 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) |
| 133 | return -EOPNOTSUPP; |
| 134 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 135 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 136 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 137 | int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 138 | if (ret) |
| 139 | return ret; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 140 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 141 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 145 | return -EOPNOTSUPP; |
| 146 | } |
| 147 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 148 | static int ieee80211_ioctl_giwrange(struct net_device *dev, |
| 149 | struct iw_request_info *info, |
| 150 | struct iw_point *data, char *extra) |
| 151 | { |
| 152 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 153 | struct iw_range *range = (struct iw_range *) extra; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 154 | enum ieee80211_band band; |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 155 | int c = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 156 | |
| 157 | data->length = sizeof(struct iw_range); |
| 158 | memset(range, 0, sizeof(struct iw_range)); |
| 159 | |
| 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; |
| 166 | range->min_rts = 0; |
| 167 | range->max_rts = 2347; |
| 168 | range->min_frag = 256; |
| 169 | range->max_frag = 2346; |
| 170 | |
| 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; |
| 175 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 176 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC || |
| 177 | local->hw.flags & IEEE80211_HW_SIGNAL_DB) |
| 178 | range->max_qual.level = local->hw.max_signal; |
| 179 | else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
| 180 | range->max_qual.level = -110; |
| 181 | else |
| 182 | range->max_qual.level = 0; |
| 183 | |
| 184 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) |
| 185 | range->max_qual.noise = -110; |
| 186 | else |
| 187 | range->max_qual.noise = 0; |
| 188 | |
| 189 | range->max_qual.qual = 100; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 190 | range->max_qual.updated = local->wstats_flags; |
| 191 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 192 | range->avg_qual.qual = 50; |
| 193 | /* not always true but better than nothing */ |
| 194 | range->avg_qual.level = range->max_qual.level / 2; |
| 195 | range->avg_qual.noise = range->max_qual.noise / 2; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 196 | range->avg_qual.updated = local->wstats_flags; |
| 197 | |
| 198 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 199 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 200 | |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 201 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 202 | for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { |
| 203 | int i; |
| 204 | struct ieee80211_supported_band *sband; |
| 205 | |
| 206 | sband = local->hw.wiphy->bands[band]; |
| 207 | |
| 208 | if (!sband) |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 209 | continue; |
| 210 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 211 | for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) { |
| 212 | struct ieee80211_channel *chan = &sband->channels[i]; |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 213 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 214 | if (!(chan->flags & IEEE80211_CHAN_DISABLED)) { |
| 215 | range->freq[c].i = |
| 216 | ieee80211_frequency_to_channel( |
| 217 | chan->center_freq); |
| 218 | range->freq[c].m = chan->center_freq; |
| 219 | range->freq[c].e = 6; |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 220 | c++; |
| 221 | } |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | range->num_channels = c; |
| 225 | range->num_frequency = c; |
| 226 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 227 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 228 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
| 229 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); |
| 230 | |
Dan Williams | 374fdfb | 2007-12-12 10:25:07 -0500 | [diff] [blame] | 231 | range->scan_capa |= IW_SCAN_CAPA_ESSID; |
| 232 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 237 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
| 238 | struct iw_request_info *info, |
| 239 | struct iw_freq *freq, char *extra) |
| 240 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 241 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 242 | |
Alina Friedrichsen | b522ed5 | 2009-01-06 03:15:23 +0100 | [diff] [blame] | 243 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 244 | sdata->vif.type == NL80211_IFTYPE_STATION) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 245 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 246 | |
| 247 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ |
| 248 | if (freq->e == 0) { |
| 249 | if (freq->m < 0) { |
Alina Friedrichsen | b522ed5 | 2009-01-06 03:15:23 +0100 | [diff] [blame] | 250 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 251 | sdata->vif.type == NL80211_IFTYPE_STATION) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 252 | sdata->u.sta.flags |= |
| 253 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 254 | return 0; |
| 255 | } else |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 256 | return ieee80211_set_freq(sdata, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 257 | ieee80211_channel_to_frequency(freq->m)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 258 | } else { |
| 259 | int i, div = 1000000; |
| 260 | for (i = 0; i < freq->e; i++) |
| 261 | div /= 10; |
| 262 | if (div > 0) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 263 | return ieee80211_set_freq(sdata, freq->m / div); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 264 | else |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | |
| 270 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, |
| 271 | struct iw_request_info *info, |
| 272 | struct iw_freq *freq, char *extra) |
| 273 | { |
| 274 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 275 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 276 | freq->m = local->hw.conf.channel->center_freq; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 277 | freq->e = 6; |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | static int ieee80211_ioctl_siwessid(struct net_device *dev, |
| 284 | struct iw_request_info *info, |
| 285 | struct iw_point *data, char *ssid) |
| 286 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 287 | struct ieee80211_sub_if_data *sdata; |
| 288 | size_t len = data->length; |
| 289 | |
| 290 | /* iwconfig uses nul termination in SSID.. */ |
| 291 | if (len > 0 && ssid[len - 1] == '\0') |
| 292 | len--; |
| 293 | |
| 294 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 295 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 296 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 297 | int ret; |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 298 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 299 | if (len > IEEE80211_MAX_SSID_LEN) |
| 300 | return -EINVAL; |
| 301 | memcpy(sdata->u.sta.ssid, ssid, len); |
| 302 | sdata->u.sta.ssid_len = len; |
| 303 | return 0; |
| 304 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 305 | if (data->flags) |
| 306 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; |
| 307 | else |
| 308 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 309 | ret = ieee80211_sta_set_ssid(sdata, ssid, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 310 | if (ret) |
| 311 | return ret; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 312 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 316 | return -EOPNOTSUPP; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | static int ieee80211_ioctl_giwessid(struct net_device *dev, |
| 321 | struct iw_request_info *info, |
| 322 | struct iw_point *data, char *ssid) |
| 323 | { |
| 324 | size_t len; |
| 325 | |
| 326 | struct ieee80211_sub_if_data *sdata; |
| 327 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 328 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 329 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 330 | int res = ieee80211_sta_get_ssid(sdata, ssid, &len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 331 | if (res == 0) { |
| 332 | data->length = len; |
| 333 | data->flags = 1; |
| 334 | } else |
| 335 | data->flags = 0; |
| 336 | return res; |
| 337 | } |
| 338 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 339 | return -EOPNOTSUPP; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | static int ieee80211_ioctl_siwap(struct net_device *dev, |
| 344 | struct iw_request_info *info, |
| 345 | struct sockaddr *ap_addr, char *extra) |
| 346 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 347 | struct ieee80211_sub_if_data *sdata; |
| 348 | |
| 349 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 350 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 351 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 352 | int ret; |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 353 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 354 | memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data, |
| 355 | ETH_ALEN); |
| 356 | return 0; |
| 357 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 358 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
| 359 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL | |
| 360 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
| 361 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) |
| 362 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 363 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 364 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 365 | ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 366 | if (ret) |
| 367 | return ret; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 368 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 369 | return 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 370 | } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 371 | /* |
| 372 | * If it is necessary to update the WDS peer address |
| 373 | * while the interface is running, then we need to do |
| 374 | * more work here, namely if it is running we need to |
| 375 | * add a new and remove the old STA entry, this is |
| 376 | * normally handled by _open() and _stop(). |
| 377 | */ |
| 378 | if (netif_running(dev)) |
| 379 | return -EBUSY; |
| 380 | |
| 381 | memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, |
| 382 | ETH_ALEN); |
| 383 | |
| 384 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | return -EOPNOTSUPP; |
| 388 | } |
| 389 | |
| 390 | |
| 391 | static int ieee80211_ioctl_giwap(struct net_device *dev, |
| 392 | struct iw_request_info *info, |
| 393 | struct sockaddr *ap_addr, char *extra) |
| 394 | { |
| 395 | struct ieee80211_sub_if_data *sdata; |
| 396 | |
| 397 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 398 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 399 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 400 | if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED || |
| 401 | sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) { |
Abhijeet Kolekar | d4231ca | 2008-05-23 10:15:26 -0700 | [diff] [blame] | 402 | ap_addr->sa_family = ARPHRD_ETHER; |
| 403 | memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN); |
| 404 | return 0; |
| 405 | } else { |
| 406 | memset(&ap_addr->sa_data, 0, ETH_ALEN); |
| 407 | return 0; |
| 408 | } |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 409 | } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 410 | ap_addr->sa_family = ARPHRD_ETHER; |
| 411 | memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | return -EOPNOTSUPP; |
| 416 | } |
| 417 | |
| 418 | |
| 419 | static int ieee80211_ioctl_siwscan(struct net_device *dev, |
| 420 | struct iw_request_info *info, |
Bill Moss | 107acb2 | 2007-10-10 16:23:55 -0400 | [diff] [blame] | 421 | union iwreq_data *wrqu, char *extra) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 422 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 423 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Bill Moss | 107acb2 | 2007-10-10 16:23:55 -0400 | [diff] [blame] | 424 | struct iw_scan_req *req = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 425 | u8 *ssid = NULL; |
| 426 | size_t ssid_len = 0; |
| 427 | |
| 428 | if (!netif_running(dev)) |
| 429 | return -ENETDOWN; |
| 430 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 431 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
| 432 | sdata->vif.type != NL80211_IFTYPE_ADHOC && |
Jouni Malinen | b7a530d | 2008-12-10 14:51:47 +0200 | [diff] [blame] | 433 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
John W. Linville | d114f39 | 2007-10-17 21:16:16 -0700 | [diff] [blame] | 434 | return -EOPNOTSUPP; |
John W. Linville | d114f39 | 2007-10-17 21:16:16 -0700 | [diff] [blame] | 435 | |
| 436 | /* if SSID was specified explicitly then use that */ |
Bill Moss | 107acb2 | 2007-10-10 16:23:55 -0400 | [diff] [blame] | 437 | if (wrqu->data.length == sizeof(struct iw_scan_req) && |
| 438 | wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 439 | req = (struct iw_scan_req *)extra; |
| 440 | ssid = req->essid; |
| 441 | ssid_len = req->essid_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 442 | } |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 443 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 444 | return ieee80211_request_scan(sdata, ssid, ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | |
| 448 | static int ieee80211_ioctl_giwscan(struct net_device *dev, |
| 449 | struct iw_request_info *info, |
| 450 | struct iw_point *data, char *extra) |
| 451 | { |
| 452 | int res; |
| 453 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 454 | struct ieee80211_sub_if_data *sdata; |
| 455 | |
| 456 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 457 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 458 | if (local->sw_scanning || local->hw_scanning) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 459 | return -EAGAIN; |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 460 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 461 | res = ieee80211_scan_results(local, info, extra, data->length); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 462 | if (res >= 0) { |
| 463 | data->length = res; |
| 464 | return 0; |
| 465 | } |
| 466 | data->length = 0; |
| 467 | return res; |
| 468 | } |
| 469 | |
| 470 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 471 | static int ieee80211_ioctl_siwrate(struct net_device *dev, |
| 472 | struct iw_request_info *info, |
| 473 | struct iw_param *rate, char *extra) |
| 474 | { |
| 475 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 476 | int i, err = -EINVAL; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 477 | u32 target_rate = rate->value / 100000; |
| 478 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 479 | struct ieee80211_supported_band *sband; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 480 | |
| 481 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 482 | |
| 483 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 484 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 485 | /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates |
| 486 | * target_rate = X, rate->fixed = 1 means only rate X |
| 487 | * target_rate = X, rate->fixed = 0 means all rates <= X */ |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 488 | sdata->max_ratectrl_rateidx = -1; |
| 489 | sdata->force_unicast_rateidx = -1; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 490 | if (rate->value < 0) |
| 491 | return 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 492 | |
| 493 | for (i=0; i< sband->n_bitrates; i++) { |
| 494 | struct ieee80211_rate *brate = &sband->bitrates[i]; |
| 495 | int this_rate = brate->bitrate; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 496 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 497 | if (target_rate == this_rate) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 498 | sdata->max_ratectrl_rateidx = i; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 499 | if (rate->fixed) |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 500 | sdata->force_unicast_rateidx = i; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 501 | err = 0; |
| 502 | break; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 503 | } |
| 504 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 505 | return err; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 506 | } |
| 507 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 508 | static int ieee80211_ioctl_giwrate(struct net_device *dev, |
| 509 | struct iw_request_info *info, |
| 510 | struct iw_param *rate, char *extra) |
| 511 | { |
| 512 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 513 | struct sta_info *sta; |
| 514 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 515 | struct ieee80211_supported_band *sband; |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 516 | |
| 517 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 518 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 519 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 520 | return -EOPNOTSUPP; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 521 | |
| 522 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 523 | |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 524 | rcu_read_lock(); |
| 525 | |
| 526 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 527 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 528 | if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) |
| 529 | rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate; |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 530 | else |
| 531 | rate->value = 0; |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 532 | |
| 533 | rcu_read_unlock(); |
| 534 | |
| 535 | if (!sta) |
| 536 | return -ENODEV; |
| 537 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 538 | rate->value *= 100000; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 539 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 543 | static int ieee80211_ioctl_siwtxpower(struct net_device *dev, |
| 544 | struct iw_request_info *info, |
| 545 | union iwreq_data *data, char *extra) |
| 546 | { |
| 547 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Luis R. Rodriguez | d9d2925 | 2008-10-22 13:13:53 -0700 | [diff] [blame] | 548 | struct ieee80211_channel* chan = local->hw.conf.channel; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 549 | u32 reconf_flags = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 550 | int new_power_level; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 551 | |
| 552 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 553 | return -EINVAL; |
| 554 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 555 | return -EINVAL; |
Luis R. Rodriguez | d9d2925 | 2008-10-22 13:13:53 -0700 | [diff] [blame] | 556 | if (!chan) |
| 557 | return -EINVAL; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 558 | |
Luis R. Rodriguez | d9d2925 | 2008-10-22 13:13:53 -0700 | [diff] [blame] | 559 | if (data->txpower.fixed) |
| 560 | new_power_level = min(data->txpower.value, chan->max_power); |
| 561 | else /* Automatic power level setting */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 562 | new_power_level = chan->max_power; |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 563 | |
Johannes Berg | 2bf30fa | 2009-01-06 23:23:56 +0100 | [diff] [blame] | 564 | local->user_power_level = new_power_level; |
Vasanthakumar Thiagarajan | e3c92df | 2008-12-24 13:53:11 +0530 | [diff] [blame] | 565 | if (local->hw.conf.power_level != new_power_level) |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 566 | reconf_flags |= IEEE80211_CONF_CHANGE_POWER; |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 567 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 568 | if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { |
| 569 | local->hw.conf.radio_enabled = !(data->txpower.disabled); |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 570 | reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED; |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 571 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 572 | } |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 573 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 574 | if (reconf_flags) |
| 575 | ieee80211_hw_config(local, reconf_flags); |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 580 | static int ieee80211_ioctl_giwtxpower(struct net_device *dev, |
| 581 | struct iw_request_info *info, |
| 582 | union iwreq_data *data, char *extra) |
| 583 | { |
| 584 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 585 | |
| 586 | data->txpower.fixed = 1; |
| 587 | data->txpower.disabled = !(local->hw.conf.radio_enabled); |
| 588 | data->txpower.value = local->hw.conf.power_level; |
| 589 | data->txpower.flags = IW_TXPOW_DBM; |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 594 | static int ieee80211_ioctl_siwrts(struct net_device *dev, |
| 595 | struct iw_request_info *info, |
| 596 | struct iw_param *rts, char *extra) |
| 597 | { |
| 598 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 599 | |
| 600 | if (rts->disabled) |
| 601 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
Emmanuel Grumbach | fa6adfe | 2008-06-24 13:37:58 +0300 | [diff] [blame] | 602 | else if (!rts->fixed) |
| 603 | /* if the rts value is not fixed, then take default */ |
| 604 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 605 | else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD) |
| 606 | return -EINVAL; |
| 607 | else |
| 608 | local->rts_threshold = rts->value; |
| 609 | |
| 610 | /* If the wlan card performs RTS/CTS in hardware/firmware, |
| 611 | * configure it here */ |
| 612 | |
| 613 | if (local->ops->set_rts_threshold) |
| 614 | local->ops->set_rts_threshold(local_to_hw(local), |
| 615 | local->rts_threshold); |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static int ieee80211_ioctl_giwrts(struct net_device *dev, |
| 621 | struct iw_request_info *info, |
| 622 | struct iw_param *rts, char *extra) |
| 623 | { |
| 624 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 625 | |
| 626 | rts->value = local->rts_threshold; |
| 627 | rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 628 | rts->fixed = 1; |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | |
| 634 | static int ieee80211_ioctl_siwfrag(struct net_device *dev, |
| 635 | struct iw_request_info *info, |
| 636 | struct iw_param *frag, char *extra) |
| 637 | { |
| 638 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 639 | |
| 640 | if (frag->disabled) |
| 641 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; |
Emmanuel Grumbach | e4abd4d | 2008-07-03 18:02:27 +0300 | [diff] [blame] | 642 | else if (!frag->fixed) |
| 643 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 644 | else if (frag->value < 256 || |
| 645 | frag->value > IEEE80211_MAX_FRAG_THRESHOLD) |
| 646 | return -EINVAL; |
| 647 | else { |
| 648 | /* Fragment length must be even, so strip LSB. */ |
| 649 | local->fragmentation_threshold = frag->value & ~0x1; |
| 650 | } |
| 651 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static int ieee80211_ioctl_giwfrag(struct net_device *dev, |
| 656 | struct iw_request_info *info, |
| 657 | struct iw_param *frag, char *extra) |
| 658 | { |
| 659 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 660 | |
| 661 | frag->value = local->fragmentation_threshold; |
| 662 | frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 663 | frag->fixed = 1; |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | |
| 669 | static int ieee80211_ioctl_siwretry(struct net_device *dev, |
| 670 | struct iw_request_info *info, |
| 671 | struct iw_param *retry, char *extra) |
| 672 | { |
| 673 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 674 | |
| 675 | if (retry->disabled || |
| 676 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) |
| 677 | return -EINVAL; |
| 678 | |
Johannes Berg | 9124b07 | 2008-10-14 19:17:54 +0200 | [diff] [blame] | 679 | if (retry->flags & IW_RETRY_MAX) { |
| 680 | local->hw.conf.long_frame_max_tx_count = retry->value; |
| 681 | } else if (retry->flags & IW_RETRY_MIN) { |
| 682 | local->hw.conf.short_frame_max_tx_count = retry->value; |
| 683 | } else { |
| 684 | local->hw.conf.long_frame_max_tx_count = retry->value; |
| 685 | local->hw.conf.short_frame_max_tx_count = retry->value; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Johannes Berg | 9124b07 | 2008-10-14 19:17:54 +0200 | [diff] [blame] | 688 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | |
| 694 | static int ieee80211_ioctl_giwretry(struct net_device *dev, |
| 695 | struct iw_request_info *info, |
| 696 | struct iw_param *retry, char *extra) |
| 697 | { |
| 698 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 699 | |
| 700 | retry->disabled = 0; |
| 701 | if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) { |
| 702 | /* first return min value, iwconfig will ask max value |
| 703 | * later if needed */ |
| 704 | retry->flags |= IW_RETRY_LIMIT; |
Johannes Berg | 9124b07 | 2008-10-14 19:17:54 +0200 | [diff] [blame] | 705 | retry->value = local->hw.conf.short_frame_max_tx_count; |
| 706 | if (local->hw.conf.long_frame_max_tx_count != |
| 707 | local->hw.conf.short_frame_max_tx_count) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 708 | retry->flags |= IW_RETRY_MIN; |
| 709 | return 0; |
| 710 | } |
| 711 | if (retry->flags & IW_RETRY_MAX) { |
| 712 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
Johannes Berg | 9124b07 | 2008-10-14 19:17:54 +0200 | [diff] [blame] | 713 | retry->value = local->hw.conf.long_frame_max_tx_count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 719 | static int ieee80211_ioctl_siwmlme(struct net_device *dev, |
| 720 | struct iw_request_info *info, |
| 721 | struct iw_point *data, char *extra) |
| 722 | { |
| 723 | struct ieee80211_sub_if_data *sdata; |
| 724 | struct iw_mlme *mlme = (struct iw_mlme *) extra; |
| 725 | |
| 726 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 727 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
| 728 | sdata->vif.type != NL80211_IFTYPE_ADHOC) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 729 | return -EINVAL; |
| 730 | |
| 731 | switch (mlme->cmd) { |
| 732 | case IW_MLME_DEAUTH: |
| 733 | /* TODO: mlme->addr.sa_data */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 734 | return ieee80211_sta_deauthenticate(sdata, mlme->reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 735 | case IW_MLME_DISASSOC: |
| 736 | /* TODO: mlme->addr.sa_data */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 737 | return ieee80211_sta_disassociate(sdata, mlme->reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 738 | default: |
| 739 | return -EOPNOTSUPP; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | |
| 744 | static int ieee80211_ioctl_siwencode(struct net_device *dev, |
| 745 | struct iw_request_info *info, |
| 746 | struct iw_point *erq, char *keybuf) |
| 747 | { |
| 748 | struct ieee80211_sub_if_data *sdata; |
| 749 | int idx, i, alg = ALG_WEP; |
| 750 | u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 751 | int remove = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 752 | |
| 753 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 754 | |
| 755 | idx = erq->flags & IW_ENCODE_INDEX; |
| 756 | if (idx == 0) { |
| 757 | if (sdata->default_key) |
| 758 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 759 | if (sdata->default_key == sdata->keys[i]) { |
| 760 | idx = i; |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | } else if (idx < 1 || idx > 4) |
| 765 | return -EINVAL; |
| 766 | else |
| 767 | idx--; |
| 768 | |
| 769 | if (erq->flags & IW_ENCODE_DISABLED) |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 770 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 771 | else if (erq->length == 0) { |
| 772 | /* No key data - just set the default TX key index */ |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 773 | ieee80211_set_default_key(sdata, idx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | return ieee80211_set_encryption( |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 778 | sdata, bcaddr, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 779 | idx, alg, remove, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 780 | !sdata->default_key, |
| 781 | keybuf, erq->length); |
| 782 | } |
| 783 | |
| 784 | |
| 785 | static int ieee80211_ioctl_giwencode(struct net_device *dev, |
| 786 | struct iw_request_info *info, |
| 787 | struct iw_point *erq, char *key) |
| 788 | { |
| 789 | struct ieee80211_sub_if_data *sdata; |
| 790 | int idx, i; |
| 791 | |
| 792 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 793 | |
| 794 | idx = erq->flags & IW_ENCODE_INDEX; |
| 795 | if (idx < 1 || idx > 4) { |
| 796 | idx = -1; |
| 797 | if (!sdata->default_key) |
| 798 | idx = 0; |
| 799 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 800 | if (sdata->default_key == sdata->keys[i]) { |
| 801 | idx = i; |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | if (idx < 0) |
| 806 | return -EINVAL; |
| 807 | } else |
| 808 | idx--; |
| 809 | |
| 810 | erq->flags = idx + 1; |
| 811 | |
| 812 | if (!sdata->keys[idx]) { |
| 813 | erq->length = 0; |
| 814 | erq->flags |= IW_ENCODE_DISABLED; |
| 815 | return 0; |
| 816 | } |
| 817 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 818 | memcpy(key, sdata->keys[idx]->conf.key, |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 819 | min_t(int, erq->length, sdata->keys[idx]->conf.keylen)); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 820 | erq->length = sdata->keys[idx]->conf.keylen; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 821 | erq->flags |= IW_ENCODE_ENABLED; |
| 822 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 823 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Emmanuel Grumbach | b9fcc4f | 2008-06-24 13:37:59 +0300 | [diff] [blame] | 824 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 825 | switch (ifsta->auth_alg) { |
| 826 | case WLAN_AUTH_OPEN: |
| 827 | case WLAN_AUTH_LEAP: |
| 828 | erq->flags |= IW_ENCODE_OPEN; |
| 829 | break; |
| 830 | case WLAN_AUTH_SHARED_KEY: |
| 831 | erq->flags |= IW_ENCODE_RESTRICTED; |
| 832 | break; |
| 833 | } |
| 834 | } |
| 835 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 836 | return 0; |
| 837 | } |
| 838 | |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 839 | static int ieee80211_ioctl_siwpower(struct net_device *dev, |
| 840 | struct iw_request_info *info, |
| 841 | struct iw_param *wrq, |
| 842 | char *extra) |
| 843 | { |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 844 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 845 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 846 | struct ieee80211_conf *conf = &local->hw.conf; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 847 | int ret = 0, timeout = 0; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 848 | bool ps; |
| 849 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 850 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) |
| 851 | return -EOPNOTSUPP; |
| 852 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 853 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 854 | return -EINVAL; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 855 | |
| 856 | if (wrq->disabled) { |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 857 | ps = false; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 858 | timeout = 0; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 859 | goto set; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | switch (wrq->flags & IW_POWER_MODE) { |
| 863 | case IW_POWER_ON: /* If not specified */ |
| 864 | case IW_POWER_MODE: /* If set all mask */ |
| 865 | case IW_POWER_ALL_R: /* If explicitely state all */ |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 866 | ps = true; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 867 | break; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 868 | default: /* Otherwise we ignore */ |
Johannes Berg | e9aeaba | 2009-01-06 18:12:35 +0100 | [diff] [blame] | 869 | return -EINVAL; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 870 | } |
| 871 | |
Johannes Berg | e9aeaba | 2009-01-06 18:12:35 +0100 | [diff] [blame] | 872 | if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT)) |
| 873 | return -EINVAL; |
| 874 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 875 | if (wrq->flags & IW_POWER_TIMEOUT) |
| 876 | timeout = wrq->value / 1000; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 877 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 878 | set: |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 879 | if (ps == local->powersave && timeout == conf->dynamic_ps_timeout) |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 880 | return ret; |
| 881 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 882 | local->powersave = ps; |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 883 | conf->dynamic_ps_timeout = timeout; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 884 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 885 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 886 | ret = ieee80211_hw_config(local, |
| 887 | IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 888 | |
| 889 | if (!(sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)) |
| 890 | return ret; |
| 891 | |
| 892 | if (conf->dynamic_ps_timeout > 0 && |
| 893 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) { |
| 894 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 895 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 896 | } else { |
| 897 | if (local->powersave) { |
| 898 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 899 | ieee80211_send_nullfunc(local, sdata, 1); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 900 | conf->flags |= IEEE80211_CONF_PS; |
| 901 | ret = ieee80211_hw_config(local, |
| 902 | IEEE80211_CONF_CHANGE_PS); |
| 903 | } else { |
| 904 | conf->flags &= ~IEEE80211_CONF_PS; |
| 905 | ret = ieee80211_hw_config(local, |
| 906 | IEEE80211_CONF_CHANGE_PS); |
| 907 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 908 | ieee80211_send_nullfunc(local, sdata, 0); |
Vivek Natarajan | b8abde4 | 2009-01-27 19:26:28 +0530 | [diff] [blame] | 909 | del_timer_sync(&local->dynamic_ps_timer); |
| 910 | cancel_work_sync(&local->dynamic_ps_enable_work); |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 911 | } |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | return ret; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | static int ieee80211_ioctl_giwpower(struct net_device *dev, |
| 918 | struct iw_request_info *info, |
| 919 | union iwreq_data *wrqu, |
| 920 | char *extra) |
| 921 | { |
| 922 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 923 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 924 | wrqu->power.disabled = !local->powersave; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 929 | static int ieee80211_ioctl_siwauth(struct net_device *dev, |
| 930 | struct iw_request_info *info, |
| 931 | struct iw_param *data, char *extra) |
| 932 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 933 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 934 | int ret = 0; |
| 935 | |
| 936 | switch (data->flags & IW_AUTH_INDEX) { |
| 937 | case IW_AUTH_WPA_VERSION: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 938 | case IW_AUTH_CIPHER_GROUP: |
| 939 | case IW_AUTH_WPA_ENABLED: |
| 940 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 941 | case IW_AUTH_KEY_MGMT: |
Jouni Malinen | 54604d3 | 2009-01-08 13:32:03 +0200 | [diff] [blame] | 942 | case IW_AUTH_CIPHER_GROUP_MGMT: |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 943 | break; |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 944 | case IW_AUTH_CIPHER_PAIRWISE: |
| 945 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
| 946 | if (data->value & (IW_AUTH_CIPHER_WEP40 | |
| 947 | IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP)) |
| 948 | sdata->u.sta.flags |= |
| 949 | IEEE80211_STA_TKIP_WEP_USED; |
| 950 | else |
| 951 | sdata->u.sta.flags &= |
| 952 | ~IEEE80211_STA_TKIP_WEP_USED; |
| 953 | } |
| 954 | break; |
Johannes Berg | b1357a8 | 2007-11-28 11:04:21 +0100 | [diff] [blame] | 955 | case IW_AUTH_DROP_UNENCRYPTED: |
| 956 | sdata->drop_unencrypted = !!data->value; |
| 957 | break; |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 958 | case IW_AUTH_PRIVACY_INVOKED: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 959 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 960 | ret = -EINVAL; |
| 961 | else { |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 962 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 963 | /* |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 964 | * Privacy invoked by wpa_supplicant, store the |
| 965 | * value and allow associating to a protected |
| 966 | * network without having a key up front. |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 967 | */ |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 968 | if (data->value) |
| 969 | sdata->u.sta.flags |= |
| 970 | IEEE80211_STA_PRIVACY_INVOKED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 971 | } |
| 972 | break; |
| 973 | case IW_AUTH_80211_AUTH_ALG: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 974 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 975 | sdata->vif.type == NL80211_IFTYPE_ADHOC) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 976 | sdata->u.sta.auth_algs = data->value; |
| 977 | else |
| 978 | ret = -EOPNOTSUPP; |
| 979 | break; |
Jouni Malinen | fdfacf0 | 2009-01-08 13:32:05 +0200 | [diff] [blame] | 980 | case IW_AUTH_MFP: |
Jouni Malinen | 4375d08 | 2009-01-08 13:32:11 +0200 | [diff] [blame] | 981 | if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) { |
| 982 | ret = -EOPNOTSUPP; |
| 983 | break; |
| 984 | } |
Jouni Malinen | fdfacf0 | 2009-01-08 13:32:05 +0200 | [diff] [blame] | 985 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 986 | sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 987 | sdata->u.sta.mfp = data->value; |
| 988 | else |
| 989 | ret = -EOPNOTSUPP; |
| 990 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 991 | default: |
| 992 | ret = -EOPNOTSUPP; |
| 993 | break; |
| 994 | } |
| 995 | return ret; |
| 996 | } |
| 997 | |
| 998 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
| 999 | static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev) |
| 1000 | { |
| 1001 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1002 | struct iw_statistics *wstats = &local->wstats; |
| 1003 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1004 | struct sta_info *sta = NULL; |
| 1005 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1006 | rcu_read_lock(); |
| 1007 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1008 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 1009 | sdata->vif.type == NL80211_IFTYPE_ADHOC) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1010 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 1011 | if (!sta) { |
| 1012 | wstats->discard.fragment = 0; |
| 1013 | wstats->discard.misc = 0; |
| 1014 | wstats->qual.qual = 0; |
| 1015 | wstats->qual.level = 0; |
| 1016 | wstats->qual.noise = 0; |
| 1017 | wstats->qual.updated = IW_QUAL_ALL_INVALID; |
| 1018 | } else { |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 1019 | wstats->qual.level = sta->last_signal; |
| 1020 | wstats->qual.qual = sta->last_qual; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1021 | wstats->qual.noise = sta->last_noise; |
| 1022 | wstats->qual.updated = local->wstats_flags; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1023 | } |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1024 | |
| 1025 | rcu_read_unlock(); |
| 1026 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1027 | return wstats; |
| 1028 | } |
| 1029 | |
| 1030 | static int ieee80211_ioctl_giwauth(struct net_device *dev, |
| 1031 | struct iw_request_info *info, |
| 1032 | struct iw_param *data, char *extra) |
| 1033 | { |
| 1034 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1035 | int ret = 0; |
| 1036 | |
| 1037 | switch (data->flags & IW_AUTH_INDEX) { |
| 1038 | case IW_AUTH_80211_AUTH_ALG: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1039 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 1040 | sdata->vif.type == NL80211_IFTYPE_ADHOC) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1041 | data->value = sdata->u.sta.auth_algs; |
| 1042 | else |
| 1043 | ret = -EOPNOTSUPP; |
| 1044 | break; |
| 1045 | default: |
| 1046 | ret = -EOPNOTSUPP; |
| 1047 | break; |
| 1048 | } |
| 1049 | return ret; |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | static int ieee80211_ioctl_siwencodeext(struct net_device *dev, |
| 1054 | struct iw_request_info *info, |
| 1055 | struct iw_point *erq, char *extra) |
| 1056 | { |
| 1057 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1058 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1059 | int uninitialized_var(alg), idx, i, remove = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1060 | |
| 1061 | switch (ext->alg) { |
| 1062 | case IW_ENCODE_ALG_NONE: |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1063 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1064 | break; |
| 1065 | case IW_ENCODE_ALG_WEP: |
| 1066 | alg = ALG_WEP; |
| 1067 | break; |
| 1068 | case IW_ENCODE_ALG_TKIP: |
| 1069 | alg = ALG_TKIP; |
| 1070 | break; |
| 1071 | case IW_ENCODE_ALG_CCMP: |
| 1072 | alg = ALG_CCMP; |
| 1073 | break; |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 1074 | case IW_ENCODE_ALG_AES_CMAC: |
| 1075 | alg = ALG_AES_CMAC; |
| 1076 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1077 | default: |
| 1078 | return -EOPNOTSUPP; |
| 1079 | } |
| 1080 | |
| 1081 | if (erq->flags & IW_ENCODE_DISABLED) |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1082 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1083 | |
| 1084 | idx = erq->flags & IW_ENCODE_INDEX; |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 1085 | if (alg == ALG_AES_CMAC) { |
| 1086 | if (idx < NUM_DEFAULT_KEYS + 1 || |
| 1087 | idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) { |
| 1088 | idx = -1; |
| 1089 | if (!sdata->default_mgmt_key) |
| 1090 | idx = 0; |
| 1091 | else for (i = NUM_DEFAULT_KEYS; |
| 1092 | i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS; |
| 1093 | i++) { |
| 1094 | if (sdata->default_mgmt_key == sdata->keys[i]) |
| 1095 | { |
| 1096 | idx = i; |
| 1097 | break; |
| 1098 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1099 | } |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 1100 | if (idx < 0) |
| 1101 | return -EINVAL; |
| 1102 | } else |
| 1103 | idx--; |
| 1104 | } else { |
| 1105 | if (idx < 1 || idx > 4) { |
| 1106 | idx = -1; |
| 1107 | if (!sdata->default_key) |
| 1108 | idx = 0; |
| 1109 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1110 | if (sdata->default_key == sdata->keys[i]) { |
| 1111 | idx = i; |
| 1112 | break; |
| 1113 | } |
| 1114 | } |
| 1115 | if (idx < 0) |
| 1116 | return -EINVAL; |
| 1117 | } else |
| 1118 | idx--; |
| 1119 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1120 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1121 | return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1122 | remove, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1123 | ext->ext_flags & |
| 1124 | IW_ENCODE_EXT_SET_TX_KEY, |
| 1125 | ext->key, ext->key_len); |
| 1126 | } |
| 1127 | |
| 1128 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1129 | /* Structures to export the Wireless Handlers */ |
| 1130 | |
| 1131 | static const iw_handler ieee80211_handler[] = |
| 1132 | { |
| 1133 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 1134 | (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1135 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 1136 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 1137 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ |
| 1138 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 1139 | (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */ |
| 1140 | (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1141 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 1142 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 1143 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ |
| 1144 | (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */ |
| 1145 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ |
| 1146 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ |
| 1147 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ |
| 1148 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ |
Johannes Berg | 5d4ecd9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 1149 | (iw_handler) NULL, /* SIOCSIWSPY */ |
| 1150 | (iw_handler) NULL, /* SIOCGIWSPY */ |
| 1151 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ |
| 1152 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1153 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
| 1154 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ |
| 1155 | (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ |
| 1156 | (iw_handler) NULL, /* SIOCGIWAPLIST */ |
| 1157 | (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */ |
| 1158 | (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */ |
| 1159 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ |
| 1160 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ |
| 1161 | (iw_handler) NULL, /* SIOCSIWNICKN */ |
| 1162 | (iw_handler) NULL, /* SIOCGIWNICKN */ |
| 1163 | (iw_handler) NULL, /* -- hole -- */ |
| 1164 | (iw_handler) NULL, /* -- hole -- */ |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1165 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 1166 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1167 | (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ |
| 1168 | (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ |
| 1169 | (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ |
| 1170 | (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 1171 | (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 1172 | (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1173 | (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ |
| 1174 | (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ |
| 1175 | (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ |
| 1176 | (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 1177 | (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ |
| 1178 | (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1179 | (iw_handler) NULL, /* -- hole -- */ |
| 1180 | (iw_handler) NULL, /* -- hole -- */ |
| 1181 | (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */ |
| 1182 | (iw_handler) NULL, /* SIOCGIWGENIE */ |
| 1183 | (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ |
| 1184 | (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ |
| 1185 | (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ |
| 1186 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ |
| 1187 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 1188 | (iw_handler) NULL, /* -- hole -- */ |
| 1189 | }; |
| 1190 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1191 | const struct iw_handler_def ieee80211_iw_handler_def = |
| 1192 | { |
| 1193 | .num_standard = ARRAY_SIZE(ieee80211_handler), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1194 | .standard = (iw_handler *) ieee80211_handler, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1195 | .get_wireless_stats = ieee80211_get_wireless_stats, |
| 1196 | }; |