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