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