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" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 24 | #include "ieee80211_rate.h" |
| 25 | #include "wpa.h" |
| 26 | #include "aes_ccm.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 27 | |
Johannes Berg | b708e61 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 28 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 29 | static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 30 | int idx, int alg, int remove, |
| 31 | int set_tx_key, const u8 *_key, |
| 32 | size_t key_len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 33 | { |
| 34 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 35 | int ret = 0; |
| 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; |
| 39 | |
| 40 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 41 | |
Volker Braun | 139c3a0 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 42 | if (idx < 0 || idx >= NUM_DEFAULT_KEYS) { |
| 43 | printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n", |
| 44 | dev->name, idx); |
| 45 | return -EINVAL; |
| 46 | } |
| 47 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 48 | if (is_broadcast_ether_addr(sta_addr)) { |
| 49 | sta = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 50 | key = sdata->keys[idx]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 51 | } else { |
| 52 | set_tx_key = 0; |
Volker Braun | 139c3a0 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 53 | /* |
| 54 | * According to the standard, the key index of a pairwise |
| 55 | * key must be zero. However, some AP are broken when it |
| 56 | * comes to WEP key indices, so we work around this. |
| 57 | */ |
| 58 | if (idx != 0 && alg != ALG_WEP) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 59 | printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for " |
| 60 | "individual key\n", dev->name); |
| 61 | return -EINVAL; |
| 62 | } |
| 63 | |
| 64 | sta = sta_info_get(local, sta_addr); |
| 65 | if (!sta) { |
| 66 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 67 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 68 | printk(KERN_DEBUG "%s: set_encrypt - unknown addr " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 69 | "%s\n", |
| 70 | dev->name, print_mac(mac, sta_addr)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 71 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 72 | |
| 73 | return -ENOENT; |
| 74 | } |
| 75 | |
| 76 | key = sta->key; |
| 77 | } |
| 78 | |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 79 | if (remove) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 80 | ieee80211_key_free(key); |
| 81 | key = NULL; |
| 82 | } else { |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 83 | /* |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 84 | * Automatically frees any old key if present. |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 85 | */ |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 86 | key = ieee80211_key_alloc(sdata, sta, alg, idx, key_len, _key); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 87 | if (!key) { |
| 88 | ret = -ENOMEM; |
| 89 | goto err_out; |
| 90 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 93 | if (set_tx_key || (!sta && !sdata->default_key && key)) |
| 94 | ieee80211_set_default_key(sdata, idx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 95 | |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 96 | ret = 0; |
| 97 | err_out: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 98 | if (sta) |
| 99 | sta_info_put(sta); |
| 100 | return ret; |
| 101 | } |
| 102 | |
| 103 | static int ieee80211_ioctl_siwgenie(struct net_device *dev, |
| 104 | struct iw_request_info *info, |
| 105 | struct iw_point *data, char *extra) |
| 106 | { |
| 107 | struct ieee80211_sub_if_data *sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 108 | |
| 109 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame^] | 110 | |
| 111 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) |
| 112 | return -EOPNOTSUPP; |
| 113 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 114 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 115 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 116 | int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length); |
| 117 | if (ret) |
| 118 | return ret; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 119 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 120 | ieee80211_sta_req_auth(dev, &sdata->u.sta); |
| 121 | return 0; |
| 122 | } |
| 123 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 124 | return -EOPNOTSUPP; |
| 125 | } |
| 126 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 127 | static int ieee80211_ioctl_giwname(struct net_device *dev, |
| 128 | struct iw_request_info *info, |
| 129 | char *name, char *extra) |
| 130 | { |
| 131 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 132 | |
| 133 | switch (local->hw.conf.phymode) { |
| 134 | case MODE_IEEE80211A: |
| 135 | strcpy(name, "IEEE 802.11a"); |
| 136 | break; |
| 137 | case MODE_IEEE80211B: |
| 138 | strcpy(name, "IEEE 802.11b"); |
| 139 | break; |
| 140 | case MODE_IEEE80211G: |
| 141 | strcpy(name, "IEEE 802.11g"); |
| 142 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 143 | default: |
| 144 | strcpy(name, "IEEE 802.11"); |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | static int ieee80211_ioctl_giwrange(struct net_device *dev, |
| 153 | struct iw_request_info *info, |
| 154 | struct iw_point *data, char *extra) |
| 155 | { |
| 156 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 157 | struct iw_range *range = (struct iw_range *) extra; |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 158 | struct ieee80211_hw_mode *mode = NULL; |
| 159 | int c = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 160 | |
| 161 | data->length = sizeof(struct iw_range); |
| 162 | memset(range, 0, sizeof(struct iw_range)); |
| 163 | |
| 164 | range->we_version_compiled = WIRELESS_EXT; |
| 165 | range->we_version_source = 21; |
| 166 | range->retry_capa = IW_RETRY_LIMIT; |
| 167 | range->retry_flags = IW_RETRY_LIMIT; |
| 168 | range->min_retry = 0; |
| 169 | range->max_retry = 255; |
| 170 | range->min_rts = 0; |
| 171 | range->max_rts = 2347; |
| 172 | range->min_frag = 256; |
| 173 | range->max_frag = 2346; |
| 174 | |
| 175 | range->encoding_size[0] = 5; |
| 176 | range->encoding_size[1] = 13; |
| 177 | range->num_encoding_sizes = 2; |
| 178 | range->max_encoding_tokens = NUM_DEFAULT_KEYS; |
| 179 | |
| 180 | range->max_qual.qual = local->hw.max_signal; |
| 181 | range->max_qual.level = local->hw.max_rssi; |
| 182 | range->max_qual.noise = local->hw.max_noise; |
| 183 | range->max_qual.updated = local->wstats_flags; |
| 184 | |
| 185 | range->avg_qual.qual = local->hw.max_signal/2; |
| 186 | range->avg_qual.level = 0; |
| 187 | range->avg_qual.noise = 0; |
| 188 | range->avg_qual.updated = local->wstats_flags; |
| 189 | |
| 190 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 191 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 192 | |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 193 | list_for_each_entry(mode, &local->modes_list, list) { |
| 194 | int i = 0; |
| 195 | |
| 196 | if (!(local->enabled_modes & (1 << mode->mode)) || |
| 197 | (local->hw_modes & local->enabled_modes & |
| 198 | (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B)) |
| 199 | continue; |
| 200 | |
| 201 | while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) { |
| 202 | struct ieee80211_channel *chan = &mode->channels[i]; |
| 203 | |
| 204 | if (chan->flag & IEEE80211_CHAN_W_SCAN) { |
| 205 | range->freq[c].i = chan->chan; |
| 206 | range->freq[c].m = chan->freq * 100000; |
| 207 | range->freq[c].e = 1; |
| 208 | c++; |
| 209 | } |
| 210 | i++; |
| 211 | } |
| 212 | } |
| 213 | range->num_channels = c; |
| 214 | range->num_frequency = c; |
| 215 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 216 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); |
| 217 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY); |
| 218 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
| 219 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 225 | static int ieee80211_ioctl_siwmode(struct net_device *dev, |
| 226 | struct iw_request_info *info, |
| 227 | __u32 *mode, char *extra) |
| 228 | { |
| 229 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 230 | int type; |
| 231 | |
| 232 | if (sdata->type == IEEE80211_IF_TYPE_VLAN) |
| 233 | return -EOPNOTSUPP; |
| 234 | |
| 235 | switch (*mode) { |
| 236 | case IW_MODE_INFRA: |
| 237 | type = IEEE80211_IF_TYPE_STA; |
| 238 | break; |
| 239 | case IW_MODE_ADHOC: |
| 240 | type = IEEE80211_IF_TYPE_IBSS; |
| 241 | break; |
| 242 | case IW_MODE_MONITOR: |
| 243 | type = IEEE80211_IF_TYPE_MNTR; |
| 244 | break; |
| 245 | default: |
| 246 | return -EINVAL; |
| 247 | } |
| 248 | |
| 249 | if (type == sdata->type) |
| 250 | return 0; |
| 251 | if (netif_running(dev)) |
| 252 | return -EBUSY; |
| 253 | |
| 254 | ieee80211_if_reinit(dev); |
| 255 | ieee80211_if_set_type(dev, type); |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | |
| 261 | static int ieee80211_ioctl_giwmode(struct net_device *dev, |
| 262 | struct iw_request_info *info, |
| 263 | __u32 *mode, char *extra) |
| 264 | { |
| 265 | struct ieee80211_sub_if_data *sdata; |
| 266 | |
| 267 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 268 | switch (sdata->type) { |
| 269 | case IEEE80211_IF_TYPE_AP: |
| 270 | *mode = IW_MODE_MASTER; |
| 271 | break; |
| 272 | case IEEE80211_IF_TYPE_STA: |
| 273 | *mode = IW_MODE_INFRA; |
| 274 | break; |
| 275 | case IEEE80211_IF_TYPE_IBSS: |
| 276 | *mode = IW_MODE_ADHOC; |
| 277 | break; |
| 278 | case IEEE80211_IF_TYPE_MNTR: |
| 279 | *mode = IW_MODE_MONITOR; |
| 280 | break; |
| 281 | case IEEE80211_IF_TYPE_WDS: |
| 282 | *mode = IW_MODE_REPEAT; |
| 283 | break; |
| 284 | case IEEE80211_IF_TYPE_VLAN: |
| 285 | *mode = IW_MODE_SECOND; /* FIXME */ |
| 286 | break; |
| 287 | default: |
| 288 | *mode = IW_MODE_AUTO; |
| 289 | break; |
| 290 | } |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq) |
| 295 | { |
| 296 | struct ieee80211_hw_mode *mode; |
| 297 | int c, set = 0; |
| 298 | int ret = -EINVAL; |
| 299 | |
| 300 | list_for_each_entry(mode, &local->modes_list, list) { |
| 301 | if (!(local->enabled_modes & (1 << mode->mode))) |
| 302 | continue; |
| 303 | for (c = 0; c < mode->num_channels; c++) { |
| 304 | struct ieee80211_channel *chan = &mode->channels[c]; |
| 305 | if (chan->flag & IEEE80211_CHAN_W_SCAN && |
| 306 | ((chan->chan == channel) || (chan->freq == freq))) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 307 | local->oper_channel = chan; |
| 308 | local->oper_hw_mode = mode; |
| 309 | set++; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | if (set) { |
| 315 | if (local->sta_scanning) |
| 316 | ret = 0; |
| 317 | else |
| 318 | ret = ieee80211_hw_config(local); |
| 319 | |
| 320 | rate_control_clear(local); |
| 321 | } |
| 322 | |
| 323 | return ret; |
| 324 | } |
| 325 | |
| 326 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
| 327 | struct iw_request_info *info, |
| 328 | struct iw_freq *freq, char *extra) |
| 329 | { |
| 330 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 331 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 332 | |
| 333 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 334 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 335 | |
| 336 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ |
| 337 | if (freq->e == 0) { |
| 338 | if (freq->m < 0) { |
| 339 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 340 | sdata->u.sta.flags |= |
| 341 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 342 | return 0; |
| 343 | } else |
| 344 | return ieee80211_set_channel(local, freq->m, -1); |
| 345 | } else { |
| 346 | int i, div = 1000000; |
| 347 | for (i = 0; i < freq->e; i++) |
| 348 | div /= 10; |
| 349 | if (div > 0) |
| 350 | return ieee80211_set_channel(local, -1, freq->m / div); |
| 351 | else |
| 352 | return -EINVAL; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | |
| 357 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, |
| 358 | struct iw_request_info *info, |
| 359 | struct iw_freq *freq, char *extra) |
| 360 | { |
| 361 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 362 | |
| 363 | /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level |
| 364 | * driver for the current channel with firmware-based management */ |
| 365 | |
| 366 | freq->m = local->hw.conf.freq; |
| 367 | freq->e = 6; |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | static int ieee80211_ioctl_siwessid(struct net_device *dev, |
| 374 | struct iw_request_info *info, |
| 375 | struct iw_point *data, char *ssid) |
| 376 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 377 | struct ieee80211_sub_if_data *sdata; |
| 378 | size_t len = data->length; |
| 379 | |
| 380 | /* iwconfig uses nul termination in SSID.. */ |
| 381 | if (len > 0 && ssid[len - 1] == '\0') |
| 382 | len--; |
| 383 | |
| 384 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 385 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 386 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 387 | int ret; |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame^] | 388 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 389 | if (len > IEEE80211_MAX_SSID_LEN) |
| 390 | return -EINVAL; |
| 391 | memcpy(sdata->u.sta.ssid, ssid, len); |
| 392 | sdata->u.sta.ssid_len = len; |
| 393 | return 0; |
| 394 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 395 | if (data->flags) |
| 396 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; |
| 397 | else |
| 398 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 399 | ret = ieee80211_sta_set_ssid(dev, ssid, len); |
| 400 | if (ret) |
| 401 | return ret; |
| 402 | ieee80211_sta_req_auth(dev, &sdata->u.sta); |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
| 407 | memcpy(sdata->u.ap.ssid, ssid, len); |
| 408 | memset(sdata->u.ap.ssid + len, 0, |
| 409 | IEEE80211_MAX_SSID_LEN - len); |
| 410 | sdata->u.ap.ssid_len = len; |
| 411 | return ieee80211_if_config(dev); |
| 412 | } |
| 413 | return -EOPNOTSUPP; |
| 414 | } |
| 415 | |
| 416 | |
| 417 | static int ieee80211_ioctl_giwessid(struct net_device *dev, |
| 418 | struct iw_request_info *info, |
| 419 | struct iw_point *data, char *ssid) |
| 420 | { |
| 421 | size_t len; |
| 422 | |
| 423 | struct ieee80211_sub_if_data *sdata; |
| 424 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 425 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 426 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 427 | int res = ieee80211_sta_get_ssid(dev, ssid, &len); |
| 428 | if (res == 0) { |
| 429 | data->length = len; |
| 430 | data->flags = 1; |
| 431 | } else |
| 432 | data->flags = 0; |
| 433 | return res; |
| 434 | } |
| 435 | |
| 436 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
| 437 | len = sdata->u.ap.ssid_len; |
| 438 | if (len > IW_ESSID_MAX_SIZE) |
| 439 | len = IW_ESSID_MAX_SIZE; |
| 440 | memcpy(ssid, sdata->u.ap.ssid, len); |
| 441 | data->length = len; |
| 442 | data->flags = 1; |
| 443 | return 0; |
| 444 | } |
| 445 | return -EOPNOTSUPP; |
| 446 | } |
| 447 | |
| 448 | |
| 449 | static int ieee80211_ioctl_siwap(struct net_device *dev, |
| 450 | struct iw_request_info *info, |
| 451 | struct sockaddr *ap_addr, char *extra) |
| 452 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 453 | struct ieee80211_sub_if_data *sdata; |
| 454 | |
| 455 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 456 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 457 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 458 | int ret; |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame^] | 459 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 460 | memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data, |
| 461 | ETH_ALEN); |
| 462 | return 0; |
| 463 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 464 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
| 465 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL | |
| 466 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
| 467 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) |
| 468 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 469 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 470 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 471 | ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data); |
| 472 | if (ret) |
| 473 | return ret; |
| 474 | ieee80211_sta_req_auth(dev, &sdata->u.sta); |
| 475 | return 0; |
| 476 | } else if (sdata->type == IEEE80211_IF_TYPE_WDS) { |
| 477 | if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, |
| 478 | ETH_ALEN) == 0) |
| 479 | return 0; |
| 480 | return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data); |
| 481 | } |
| 482 | |
| 483 | return -EOPNOTSUPP; |
| 484 | } |
| 485 | |
| 486 | |
| 487 | static int ieee80211_ioctl_giwap(struct net_device *dev, |
| 488 | struct iw_request_info *info, |
| 489 | struct sockaddr *ap_addr, char *extra) |
| 490 | { |
| 491 | struct ieee80211_sub_if_data *sdata; |
| 492 | |
| 493 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 494 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 495 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 496 | ap_addr->sa_family = ARPHRD_ETHER; |
| 497 | memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN); |
| 498 | return 0; |
| 499 | } else if (sdata->type == IEEE80211_IF_TYPE_WDS) { |
| 500 | ap_addr->sa_family = ARPHRD_ETHER; |
| 501 | memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | return -EOPNOTSUPP; |
| 506 | } |
| 507 | |
| 508 | |
| 509 | static int ieee80211_ioctl_siwscan(struct net_device *dev, |
| 510 | struct iw_request_info *info, |
| 511 | struct iw_point *data, char *extra) |
| 512 | { |
| 513 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 514 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 515 | u8 *ssid = NULL; |
| 516 | size_t ssid_len = 0; |
| 517 | |
| 518 | if (!netif_running(dev)) |
| 519 | return -ENETDOWN; |
| 520 | |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 521 | switch (sdata->type) { |
| 522 | case IEEE80211_IF_TYPE_STA: |
| 523 | case IEEE80211_IF_TYPE_IBSS: |
| 524 | if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 525 | ssid = sdata->u.sta.ssid; |
| 526 | ssid_len = sdata->u.sta.ssid_len; |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 527 | } |
| 528 | break; |
| 529 | case IEEE80211_IF_TYPE_AP: |
| 530 | if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 531 | ssid = sdata->u.ap.ssid; |
| 532 | ssid_len = sdata->u.ap.ssid_len; |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 533 | } |
| 534 | break; |
| 535 | default: |
| 536 | return -EOPNOTSUPP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 537 | } |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 538 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 539 | return ieee80211_sta_req_scan(dev, ssid, ssid_len); |
| 540 | } |
| 541 | |
| 542 | |
| 543 | static int ieee80211_ioctl_giwscan(struct net_device *dev, |
| 544 | struct iw_request_info *info, |
| 545 | struct iw_point *data, char *extra) |
| 546 | { |
| 547 | int res; |
| 548 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 549 | if (local->sta_scanning) |
| 550 | return -EAGAIN; |
| 551 | res = ieee80211_sta_scan_results(dev, extra, data->length); |
| 552 | if (res >= 0) { |
| 553 | data->length = res; |
| 554 | return 0; |
| 555 | } |
| 556 | data->length = 0; |
| 557 | return res; |
| 558 | } |
| 559 | |
| 560 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 561 | static int ieee80211_ioctl_siwrate(struct net_device *dev, |
| 562 | struct iw_request_info *info, |
| 563 | struct iw_param *rate, char *extra) |
| 564 | { |
| 565 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 566 | struct ieee80211_hw_mode *mode; |
| 567 | int i; |
| 568 | u32 target_rate = rate->value / 100000; |
| 569 | struct ieee80211_sub_if_data *sdata; |
| 570 | |
| 571 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 572 | if (!sdata->bss) |
| 573 | return -ENODEV; |
| 574 | mode = local->oper_hw_mode; |
| 575 | /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates |
| 576 | * target_rate = X, rate->fixed = 1 means only rate X |
| 577 | * target_rate = X, rate->fixed = 0 means all rates <= X */ |
| 578 | sdata->bss->max_ratectrl_rateidx = -1; |
| 579 | sdata->bss->force_unicast_rateidx = -1; |
| 580 | if (rate->value < 0) |
| 581 | return 0; |
| 582 | for (i=0; i< mode->num_rates; i++) { |
| 583 | struct ieee80211_rate *rates = &mode->rates[i]; |
| 584 | int this_rate = rates->rate; |
| 585 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 586 | if (target_rate == this_rate) { |
| 587 | sdata->bss->max_ratectrl_rateidx = i; |
| 588 | if (rate->fixed) |
| 589 | sdata->bss->force_unicast_rateidx = i; |
| 590 | break; |
| 591 | } |
| 592 | } |
| 593 | return 0; |
| 594 | } |
| 595 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 596 | static int ieee80211_ioctl_giwrate(struct net_device *dev, |
| 597 | struct iw_request_info *info, |
| 598 | struct iw_param *rate, char *extra) |
| 599 | { |
| 600 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 601 | struct sta_info *sta; |
| 602 | struct ieee80211_sub_if_data *sdata; |
| 603 | |
| 604 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 605 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
| 606 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 607 | else |
| 608 | return -EOPNOTSUPP; |
| 609 | if (!sta) |
| 610 | return -ENODEV; |
| 611 | if (sta->txrate < local->oper_hw_mode->num_rates) |
| 612 | rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000; |
| 613 | else |
| 614 | rate->value = 0; |
| 615 | sta_info_put(sta); |
| 616 | return 0; |
| 617 | } |
| 618 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 619 | static int ieee80211_ioctl_siwtxpower(struct net_device *dev, |
| 620 | struct iw_request_info *info, |
| 621 | union iwreq_data *data, char *extra) |
| 622 | { |
| 623 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 624 | bool need_reconfig = 0; |
| 625 | |
| 626 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 627 | return -EINVAL; |
| 628 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 629 | return -EINVAL; |
| 630 | if (!data->txpower.fixed) |
| 631 | return -EINVAL; |
| 632 | |
| 633 | if (local->hw.conf.power_level != data->txpower.value) { |
| 634 | local->hw.conf.power_level = data->txpower.value; |
| 635 | need_reconfig = 1; |
| 636 | } |
| 637 | if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { |
| 638 | local->hw.conf.radio_enabled = !(data->txpower.disabled); |
| 639 | need_reconfig = 1; |
| 640 | } |
| 641 | if (need_reconfig) { |
| 642 | ieee80211_hw_config(local); |
| 643 | /* The return value of hw_config is not of big interest here, |
| 644 | * as it doesn't say that it failed because of _this_ config |
| 645 | * change or something else. Ignore it. */ |
| 646 | } |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 651 | static int ieee80211_ioctl_giwtxpower(struct net_device *dev, |
| 652 | struct iw_request_info *info, |
| 653 | union iwreq_data *data, char *extra) |
| 654 | { |
| 655 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 656 | |
| 657 | data->txpower.fixed = 1; |
| 658 | data->txpower.disabled = !(local->hw.conf.radio_enabled); |
| 659 | data->txpower.value = local->hw.conf.power_level; |
| 660 | data->txpower.flags = IW_TXPOW_DBM; |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 665 | static int ieee80211_ioctl_siwrts(struct net_device *dev, |
| 666 | struct iw_request_info *info, |
| 667 | struct iw_param *rts, char *extra) |
| 668 | { |
| 669 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 670 | |
| 671 | if (rts->disabled) |
| 672 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
| 673 | else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD) |
| 674 | return -EINVAL; |
| 675 | else |
| 676 | local->rts_threshold = rts->value; |
| 677 | |
| 678 | /* If the wlan card performs RTS/CTS in hardware/firmware, |
| 679 | * configure it here */ |
| 680 | |
| 681 | if (local->ops->set_rts_threshold) |
| 682 | local->ops->set_rts_threshold(local_to_hw(local), |
| 683 | local->rts_threshold); |
| 684 | |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | static int ieee80211_ioctl_giwrts(struct net_device *dev, |
| 689 | struct iw_request_info *info, |
| 690 | struct iw_param *rts, char *extra) |
| 691 | { |
| 692 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 693 | |
| 694 | rts->value = local->rts_threshold; |
| 695 | rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 696 | rts->fixed = 1; |
| 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | |
| 702 | static int ieee80211_ioctl_siwfrag(struct net_device *dev, |
| 703 | struct iw_request_info *info, |
| 704 | struct iw_param *frag, char *extra) |
| 705 | { |
| 706 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 707 | |
| 708 | if (frag->disabled) |
| 709 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; |
| 710 | else if (frag->value < 256 || |
| 711 | frag->value > IEEE80211_MAX_FRAG_THRESHOLD) |
| 712 | return -EINVAL; |
| 713 | else { |
| 714 | /* Fragment length must be even, so strip LSB. */ |
| 715 | local->fragmentation_threshold = frag->value & ~0x1; |
| 716 | } |
| 717 | |
| 718 | /* If the wlan card performs fragmentation in hardware/firmware, |
| 719 | * configure it here */ |
| 720 | |
| 721 | if (local->ops->set_frag_threshold) |
| 722 | local->ops->set_frag_threshold( |
| 723 | local_to_hw(local), |
| 724 | local->fragmentation_threshold); |
| 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | static int ieee80211_ioctl_giwfrag(struct net_device *dev, |
| 730 | struct iw_request_info *info, |
| 731 | struct iw_param *frag, char *extra) |
| 732 | { |
| 733 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 734 | |
| 735 | frag->value = local->fragmentation_threshold; |
| 736 | frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 737 | frag->fixed = 1; |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | |
| 743 | static int ieee80211_ioctl_siwretry(struct net_device *dev, |
| 744 | struct iw_request_info *info, |
| 745 | struct iw_param *retry, char *extra) |
| 746 | { |
| 747 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 748 | |
| 749 | if (retry->disabled || |
| 750 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) |
| 751 | return -EINVAL; |
| 752 | |
| 753 | if (retry->flags & IW_RETRY_MAX) |
| 754 | local->long_retry_limit = retry->value; |
| 755 | else if (retry->flags & IW_RETRY_MIN) |
| 756 | local->short_retry_limit = retry->value; |
| 757 | else { |
| 758 | local->long_retry_limit = retry->value; |
| 759 | local->short_retry_limit = retry->value; |
| 760 | } |
| 761 | |
| 762 | if (local->ops->set_retry_limit) { |
| 763 | return local->ops->set_retry_limit( |
| 764 | local_to_hw(local), |
| 765 | local->short_retry_limit, |
| 766 | local->long_retry_limit); |
| 767 | } |
| 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | |
| 773 | static int ieee80211_ioctl_giwretry(struct net_device *dev, |
| 774 | struct iw_request_info *info, |
| 775 | struct iw_param *retry, char *extra) |
| 776 | { |
| 777 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 778 | |
| 779 | retry->disabled = 0; |
| 780 | if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) { |
| 781 | /* first return min value, iwconfig will ask max value |
| 782 | * later if needed */ |
| 783 | retry->flags |= IW_RETRY_LIMIT; |
| 784 | retry->value = local->short_retry_limit; |
| 785 | if (local->long_retry_limit != local->short_retry_limit) |
| 786 | retry->flags |= IW_RETRY_MIN; |
| 787 | return 0; |
| 788 | } |
| 789 | if (retry->flags & IW_RETRY_MAX) { |
| 790 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 791 | retry->value = local->long_retry_limit; |
| 792 | } |
| 793 | |
| 794 | return 0; |
| 795 | } |
| 796 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 797 | static int ieee80211_ioctl_siwmlme(struct net_device *dev, |
| 798 | struct iw_request_info *info, |
| 799 | struct iw_point *data, char *extra) |
| 800 | { |
| 801 | struct ieee80211_sub_if_data *sdata; |
| 802 | struct iw_mlme *mlme = (struct iw_mlme *) extra; |
| 803 | |
| 804 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 805 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 806 | sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 807 | return -EINVAL; |
| 808 | |
| 809 | switch (mlme->cmd) { |
| 810 | case IW_MLME_DEAUTH: |
| 811 | /* TODO: mlme->addr.sa_data */ |
| 812 | return ieee80211_sta_deauthenticate(dev, mlme->reason_code); |
| 813 | case IW_MLME_DISASSOC: |
| 814 | /* TODO: mlme->addr.sa_data */ |
| 815 | return ieee80211_sta_disassociate(dev, mlme->reason_code); |
| 816 | default: |
| 817 | return -EOPNOTSUPP; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | |
| 822 | static int ieee80211_ioctl_siwencode(struct net_device *dev, |
| 823 | struct iw_request_info *info, |
| 824 | struct iw_point *erq, char *keybuf) |
| 825 | { |
| 826 | struct ieee80211_sub_if_data *sdata; |
| 827 | int idx, i, alg = ALG_WEP; |
| 828 | u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 829 | int remove = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 830 | |
| 831 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 832 | |
| 833 | idx = erq->flags & IW_ENCODE_INDEX; |
| 834 | if (idx == 0) { |
| 835 | if (sdata->default_key) |
| 836 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 837 | if (sdata->default_key == sdata->keys[i]) { |
| 838 | idx = i; |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | } else if (idx < 1 || idx > 4) |
| 843 | return -EINVAL; |
| 844 | else |
| 845 | idx--; |
| 846 | |
| 847 | if (erq->flags & IW_ENCODE_DISABLED) |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 848 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 849 | else if (erq->length == 0) { |
| 850 | /* No key data - just set the default TX key index */ |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 851 | ieee80211_set_default_key(sdata, idx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | return ieee80211_set_encryption( |
| 856 | dev, bcaddr, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 857 | idx, alg, remove, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 858 | !sdata->default_key, |
| 859 | keybuf, erq->length); |
| 860 | } |
| 861 | |
| 862 | |
| 863 | static int ieee80211_ioctl_giwencode(struct net_device *dev, |
| 864 | struct iw_request_info *info, |
| 865 | struct iw_point *erq, char *key) |
| 866 | { |
| 867 | struct ieee80211_sub_if_data *sdata; |
| 868 | int idx, i; |
| 869 | |
| 870 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 871 | |
| 872 | idx = erq->flags & IW_ENCODE_INDEX; |
| 873 | if (idx < 1 || idx > 4) { |
| 874 | idx = -1; |
| 875 | if (!sdata->default_key) |
| 876 | idx = 0; |
| 877 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 878 | if (sdata->default_key == sdata->keys[i]) { |
| 879 | idx = i; |
| 880 | break; |
| 881 | } |
| 882 | } |
| 883 | if (idx < 0) |
| 884 | return -EINVAL; |
| 885 | } else |
| 886 | idx--; |
| 887 | |
| 888 | erq->flags = idx + 1; |
| 889 | |
| 890 | if (!sdata->keys[idx]) { |
| 891 | erq->length = 0; |
| 892 | erq->flags |= IW_ENCODE_DISABLED; |
| 893 | return 0; |
| 894 | } |
| 895 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 896 | memcpy(key, sdata->keys[idx]->conf.key, |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 897 | min_t(int, erq->length, sdata->keys[idx]->conf.keylen)); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 898 | erq->length = sdata->keys[idx]->conf.keylen; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 899 | erq->flags |= IW_ENCODE_ENABLED; |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | static int ieee80211_ioctl_siwauth(struct net_device *dev, |
| 905 | struct iw_request_info *info, |
| 906 | struct iw_param *data, char *extra) |
| 907 | { |
| 908 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 909 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 910 | int ret = 0; |
| 911 | |
| 912 | switch (data->flags & IW_AUTH_INDEX) { |
| 913 | case IW_AUTH_WPA_VERSION: |
| 914 | case IW_AUTH_CIPHER_PAIRWISE: |
| 915 | case IW_AUTH_CIPHER_GROUP: |
| 916 | case IW_AUTH_WPA_ENABLED: |
| 917 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 918 | break; |
| 919 | case IW_AUTH_KEY_MGMT: |
| 920 | if (sdata->type != IEEE80211_IF_TYPE_STA) |
| 921 | ret = -EINVAL; |
| 922 | else { |
| 923 | /* |
Johannes Berg | 808718c | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 924 | * Key management was set by wpa_supplicant, |
| 925 | * we only need this to associate to a network |
| 926 | * that has privacy enabled regardless of not |
| 927 | * having a key. |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 928 | */ |
Johannes Berg | 808718c | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 929 | sdata->u.sta.key_management_enabled = !!data->value; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 930 | } |
| 931 | break; |
| 932 | case IW_AUTH_80211_AUTH_ALG: |
| 933 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 934 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 935 | sdata->u.sta.auth_algs = data->value; |
| 936 | else |
| 937 | ret = -EOPNOTSUPP; |
| 938 | break; |
| 939 | case IW_AUTH_PRIVACY_INVOKED: |
| 940 | if (local->ops->set_privacy_invoked) |
| 941 | ret = local->ops->set_privacy_invoked( |
| 942 | local_to_hw(local), data->value); |
| 943 | break; |
| 944 | default: |
| 945 | ret = -EOPNOTSUPP; |
| 946 | break; |
| 947 | } |
| 948 | return ret; |
| 949 | } |
| 950 | |
| 951 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
| 952 | static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev) |
| 953 | { |
| 954 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 955 | struct iw_statistics *wstats = &local->wstats; |
| 956 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 957 | struct sta_info *sta = NULL; |
| 958 | |
| 959 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 960 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 961 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 962 | if (!sta) { |
| 963 | wstats->discard.fragment = 0; |
| 964 | wstats->discard.misc = 0; |
| 965 | wstats->qual.qual = 0; |
| 966 | wstats->qual.level = 0; |
| 967 | wstats->qual.noise = 0; |
| 968 | wstats->qual.updated = IW_QUAL_ALL_INVALID; |
| 969 | } else { |
| 970 | wstats->qual.level = sta->last_rssi; |
| 971 | wstats->qual.qual = sta->last_signal; |
| 972 | wstats->qual.noise = sta->last_noise; |
| 973 | wstats->qual.updated = local->wstats_flags; |
| 974 | sta_info_put(sta); |
| 975 | } |
| 976 | return wstats; |
| 977 | } |
| 978 | |
| 979 | static int ieee80211_ioctl_giwauth(struct net_device *dev, |
| 980 | struct iw_request_info *info, |
| 981 | struct iw_param *data, char *extra) |
| 982 | { |
| 983 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 984 | int ret = 0; |
| 985 | |
| 986 | switch (data->flags & IW_AUTH_INDEX) { |
| 987 | case IW_AUTH_80211_AUTH_ALG: |
| 988 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 989 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 990 | data->value = sdata->u.sta.auth_algs; |
| 991 | else |
| 992 | ret = -EOPNOTSUPP; |
| 993 | break; |
| 994 | default: |
| 995 | ret = -EOPNOTSUPP; |
| 996 | break; |
| 997 | } |
| 998 | return ret; |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | static int ieee80211_ioctl_siwencodeext(struct net_device *dev, |
| 1003 | struct iw_request_info *info, |
| 1004 | struct iw_point *erq, char *extra) |
| 1005 | { |
| 1006 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1007 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1008 | int uninitialized_var(alg), idx, i, remove = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1009 | |
| 1010 | switch (ext->alg) { |
| 1011 | case IW_ENCODE_ALG_NONE: |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1012 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1013 | break; |
| 1014 | case IW_ENCODE_ALG_WEP: |
| 1015 | alg = ALG_WEP; |
| 1016 | break; |
| 1017 | case IW_ENCODE_ALG_TKIP: |
| 1018 | alg = ALG_TKIP; |
| 1019 | break; |
| 1020 | case IW_ENCODE_ALG_CCMP: |
| 1021 | alg = ALG_CCMP; |
| 1022 | break; |
| 1023 | default: |
| 1024 | return -EOPNOTSUPP; |
| 1025 | } |
| 1026 | |
| 1027 | if (erq->flags & IW_ENCODE_DISABLED) |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1028 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1029 | |
| 1030 | idx = erq->flags & IW_ENCODE_INDEX; |
| 1031 | if (idx < 1 || idx > 4) { |
| 1032 | idx = -1; |
| 1033 | if (!sdata->default_key) |
| 1034 | idx = 0; |
| 1035 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1036 | if (sdata->default_key == sdata->keys[i]) { |
| 1037 | idx = i; |
| 1038 | break; |
| 1039 | } |
| 1040 | } |
| 1041 | if (idx < 0) |
| 1042 | return -EINVAL; |
| 1043 | } else |
| 1044 | idx--; |
| 1045 | |
| 1046 | return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1047 | remove, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1048 | ext->ext_flags & |
| 1049 | IW_ENCODE_EXT_SET_TX_KEY, |
| 1050 | ext->key, ext->key_len); |
| 1051 | } |
| 1052 | |
| 1053 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1054 | /* Structures to export the Wireless Handlers */ |
| 1055 | |
| 1056 | static const iw_handler ieee80211_handler[] = |
| 1057 | { |
| 1058 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
| 1059 | (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */ |
| 1060 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 1061 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 1062 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ |
| 1063 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ |
| 1064 | (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */ |
| 1065 | (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */ |
| 1066 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 1067 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 1068 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ |
| 1069 | (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */ |
| 1070 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ |
| 1071 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ |
| 1072 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ |
| 1073 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ |
Johannes Berg | 5d4ecd9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 1074 | (iw_handler) NULL, /* SIOCSIWSPY */ |
| 1075 | (iw_handler) NULL, /* SIOCGIWSPY */ |
| 1076 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ |
| 1077 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1078 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
| 1079 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ |
| 1080 | (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ |
| 1081 | (iw_handler) NULL, /* SIOCGIWAPLIST */ |
| 1082 | (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */ |
| 1083 | (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */ |
| 1084 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ |
| 1085 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ |
| 1086 | (iw_handler) NULL, /* SIOCSIWNICKN */ |
| 1087 | (iw_handler) NULL, /* SIOCGIWNICKN */ |
| 1088 | (iw_handler) NULL, /* -- hole -- */ |
| 1089 | (iw_handler) NULL, /* -- hole -- */ |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1090 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 1091 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1092 | (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ |
| 1093 | (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ |
| 1094 | (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ |
| 1095 | (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 1096 | (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 1097 | (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1098 | (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ |
| 1099 | (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ |
| 1100 | (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ |
| 1101 | (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ |
| 1102 | (iw_handler) NULL, /* SIOCSIWPOWER */ |
| 1103 | (iw_handler) NULL, /* SIOCGIWPOWER */ |
| 1104 | (iw_handler) NULL, /* -- hole -- */ |
| 1105 | (iw_handler) NULL, /* -- hole -- */ |
| 1106 | (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */ |
| 1107 | (iw_handler) NULL, /* SIOCGIWGENIE */ |
| 1108 | (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ |
| 1109 | (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ |
| 1110 | (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ |
| 1111 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ |
| 1112 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 1113 | (iw_handler) NULL, /* -- hole -- */ |
| 1114 | }; |
| 1115 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1116 | const struct iw_handler_def ieee80211_iw_handler_def = |
| 1117 | { |
| 1118 | .num_standard = ARRAY_SIZE(ieee80211_handler), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1119 | .standard = (iw_handler *) ieee80211_handler, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1120 | .get_wireless_stats = ieee80211_get_wireless_stats, |
| 1121 | }; |