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