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