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