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