Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/netdevice.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/skbuff.h> |
| 16 | #include <linux/etherdevice.h> |
| 17 | #include <linux/if_arp.h> |
| 18 | #include <linux/wireless.h> |
| 19 | #include <net/iw_handler.h> |
| 20 | #include <asm/uaccess.h> |
| 21 | |
| 22 | #include <net/mac80211.h> |
| 23 | #include "ieee80211_i.h" |
| 24 | #include "hostapd_ioctl.h" |
| 25 | #include "ieee80211_rate.h" |
| 26 | #include "wpa.h" |
| 27 | #include "aes_ccm.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 28 | #include "debugfs_key.h" |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 29 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | static void ieee80211_set_hw_encryption(struct net_device *dev, |
| 31 | struct sta_info *sta, u8 addr[ETH_ALEN], |
| 32 | struct ieee80211_key *key) |
| 33 | { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 34 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 35 | |
| 36 | /* default to sw encryption; this will be cleared by low-level |
| 37 | * driver if the hw supports requested encryption */ |
| 38 | if (key) |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 39 | key->conf.flags |= IEEE80211_KEY_FORCE_SW_ENCRYPT; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 40 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 41 | if (key && local->ops->set_key) { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 42 | if (local->ops->set_key(local_to_hw(local), SET_KEY, addr, |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 43 | &key->conf, local->default_wep_only)) { |
| 44 | key->conf.flags |= IEEE80211_KEY_FORCE_SW_ENCRYPT; |
| 45 | key->conf.hw_key_idx = HW_KEY_IDX_INVALID; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | |
| 51 | static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr, |
| 52 | int idx, int alg, int set_tx_key, |
| 53 | const u8 *_key, size_t key_len) |
| 54 | { |
| 55 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 56 | int ret = 0; |
| 57 | struct sta_info *sta; |
| 58 | struct ieee80211_key *key, *old_key; |
| 59 | int try_hwaccel = 1; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 60 | struct ieee80211_sub_if_data *sdata; |
| 61 | |
| 62 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 63 | |
| 64 | if (is_broadcast_ether_addr(sta_addr)) { |
| 65 | sta = NULL; |
| 66 | if (idx >= NUM_DEFAULT_KEYS) { |
| 67 | printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n", |
| 68 | dev->name, idx); |
| 69 | return -EINVAL; |
| 70 | } |
| 71 | key = sdata->keys[idx]; |
| 72 | |
| 73 | /* TODO: consider adding hwaccel support for these; at least |
| 74 | * Atheros key cache should be able to handle this since AP is |
| 75 | * only transmitting frames with default keys. */ |
| 76 | /* FIX: hw key cache can be used when only one virtual |
| 77 | * STA is associated with each AP. If more than one STA |
| 78 | * is associated to the same AP, software encryption |
| 79 | * must be used. This should be done automatically |
| 80 | * based on configured station devices. For the time |
| 81 | * being, this can be only set at compile time. */ |
| 82 | } else { |
| 83 | set_tx_key = 0; |
| 84 | if (idx != 0) { |
| 85 | printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for " |
| 86 | "individual key\n", dev->name); |
| 87 | return -EINVAL; |
| 88 | } |
| 89 | |
| 90 | sta = sta_info_get(local, sta_addr); |
| 91 | if (!sta) { |
| 92 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 93 | printk(KERN_DEBUG "%s: set_encrypt - unknown addr " |
| 94 | MAC_FMT "\n", |
| 95 | dev->name, MAC_ARG(sta_addr)); |
| 96 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 97 | |
| 98 | return -ENOENT; |
| 99 | } |
| 100 | |
| 101 | key = sta->key; |
| 102 | } |
| 103 | |
| 104 | /* FIX: |
| 105 | * Cannot configure default hwaccel keys with WEP algorithm, if |
| 106 | * any of the virtual interfaces is using static WEP |
| 107 | * configuration because hwaccel would otherwise try to decrypt |
| 108 | * these frames. |
| 109 | * |
| 110 | * For now, just disable WEP hwaccel for broadcast when there is |
| 111 | * possibility of conflict with default keys. This can maybe later be |
| 112 | * optimized by using non-default keys (at least with Atheros ar521x). |
| 113 | */ |
| 114 | if (!sta && alg == ALG_WEP && !local->default_wep_only && |
| 115 | sdata->type != IEEE80211_IF_TYPE_IBSS && |
| 116 | sdata->type != IEEE80211_IF_TYPE_AP) { |
| 117 | try_hwaccel = 0; |
| 118 | } |
| 119 | |
| 120 | if (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) { |
| 121 | /* Software encryption cannot be used with devices that hide |
| 122 | * encryption from the host system, so always try to use |
| 123 | * hardware acceleration with such devices. */ |
| 124 | try_hwaccel = 1; |
| 125 | } |
| 126 | |
| 127 | if ((local->hw.flags & IEEE80211_HW_NO_TKIP_WMM_HWACCEL) && |
| 128 | alg == ALG_TKIP) { |
| 129 | if (sta && (sta->flags & WLAN_STA_WME)) { |
| 130 | /* Hardware does not support hwaccel with TKIP when using WMM. |
| 131 | */ |
| 132 | try_hwaccel = 0; |
| 133 | } |
| 134 | else if (sdata->type == IEEE80211_IF_TYPE_STA) { |
| 135 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 136 | if (sta) { |
| 137 | if (sta->flags & WLAN_STA_WME) { |
| 138 | try_hwaccel = 0; |
| 139 | } |
| 140 | sta_info_put(sta); |
| 141 | sta = NULL; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (alg == ALG_NONE) { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 147 | if (try_hwaccel && key && |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 148 | key->conf.hw_key_idx != HW_KEY_IDX_INVALID && |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 149 | local->ops->set_key && |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 150 | local->ops->set_key(local_to_hw(local), DISABLE_KEY, |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 151 | sta_addr, &key->conf, |
| 152 | local->default_wep_only)) { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 153 | printk(KERN_DEBUG "%s: set_encrypt - low-level disable" |
| 154 | " failed\n", dev->name); |
| 155 | ret = -EINVAL; |
| 156 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 157 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 158 | if (set_tx_key || sdata->default_key == key) { |
| 159 | ieee80211_debugfs_key_remove_default(sdata); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 160 | sdata->default_key = NULL; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 161 | } |
| 162 | ieee80211_debugfs_key_remove(key); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 163 | if (sta) |
| 164 | sta->key = NULL; |
| 165 | else |
| 166 | sdata->keys[idx] = NULL; |
| 167 | ieee80211_key_free(key); |
| 168 | key = NULL; |
| 169 | } else { |
| 170 | old_key = key; |
| 171 | key = ieee80211_key_alloc(sta ? NULL : sdata, idx, key_len, |
| 172 | GFP_KERNEL); |
| 173 | if (!key) { |
| 174 | ret = -ENOMEM; |
| 175 | goto err_out; |
| 176 | } |
| 177 | |
| 178 | /* default to sw encryption; low-level driver sets these if the |
| 179 | * requested encryption is supported */ |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 180 | key->conf.hw_key_idx = HW_KEY_IDX_INVALID; |
| 181 | key->conf.flags |= IEEE80211_KEY_FORCE_SW_ENCRYPT; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 182 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 183 | key->conf.alg = alg; |
| 184 | key->conf.keyidx = idx; |
| 185 | key->conf.keylen = key_len; |
| 186 | memcpy(key->conf.key, _key, key_len); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 187 | |
| 188 | if (alg == ALG_CCMP) { |
| 189 | /* Initialize AES key state here as an optimization |
| 190 | * so that it does not need to be initialized for every |
| 191 | * packet. */ |
| 192 | key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt( |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 193 | key->conf.key); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 194 | if (!key->u.ccmp.tfm) { |
| 195 | ret = -ENOMEM; |
| 196 | goto err_free; |
| 197 | } |
| 198 | } |
| 199 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 200 | if (set_tx_key || sdata->default_key == old_key) { |
| 201 | ieee80211_debugfs_key_remove_default(sdata); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 202 | sdata->default_key = NULL; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 203 | } |
| 204 | ieee80211_debugfs_key_remove(old_key); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 205 | if (sta) |
| 206 | sta->key = key; |
| 207 | else |
| 208 | sdata->keys[idx] = key; |
| 209 | ieee80211_key_free(old_key); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 210 | ieee80211_debugfs_key_add(local, key); |
| 211 | if (sta) |
| 212 | ieee80211_debugfs_key_sta_link(key, sta); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 213 | |
| 214 | if (try_hwaccel && |
| 215 | (alg == ALG_WEP || alg == ALG_TKIP || alg == ALG_CCMP)) |
| 216 | ieee80211_set_hw_encryption(dev, sta, sta_addr, key); |
| 217 | } |
| 218 | |
| 219 | if (set_tx_key || (!sta && !sdata->default_key && key)) { |
| 220 | sdata->default_key = key; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 221 | if (key) |
| 222 | ieee80211_debugfs_key_add_default(sdata); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 223 | |
| 224 | if (local->ops->set_key_idx && |
| 225 | local->ops->set_key_idx(local_to_hw(local), idx)) |
| 226 | printk(KERN_DEBUG "%s: failed to set TX key idx for " |
| 227 | "low-level driver\n", dev->name); |
| 228 | } |
| 229 | |
| 230 | if (sta) |
| 231 | sta_info_put(sta); |
| 232 | |
| 233 | return 0; |
| 234 | |
| 235 | err_free: |
| 236 | ieee80211_key_free(key); |
| 237 | err_out: |
| 238 | if (sta) |
| 239 | sta_info_put(sta); |
| 240 | return ret; |
| 241 | } |
| 242 | |
| 243 | static int ieee80211_ioctl_siwgenie(struct net_device *dev, |
| 244 | struct iw_request_info *info, |
| 245 | struct iw_point *data, char *extra) |
| 246 | { |
| 247 | struct ieee80211_sub_if_data *sdata; |
| 248 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 249 | |
| 250 | if (local->user_space_mlme) |
| 251 | return -EOPNOTSUPP; |
| 252 | |
| 253 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 254 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 255 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 256 | int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length); |
| 257 | if (ret) |
| 258 | return ret; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 259 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 260 | ieee80211_sta_req_auth(dev, &sdata->u.sta); |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
| 265 | kfree(sdata->u.ap.generic_elem); |
| 266 | sdata->u.ap.generic_elem = kmalloc(data->length, GFP_KERNEL); |
| 267 | if (!sdata->u.ap.generic_elem) |
| 268 | return -ENOMEM; |
| 269 | memcpy(sdata->u.ap.generic_elem, extra, data->length); |
| 270 | sdata->u.ap.generic_elem_len = data->length; |
| 271 | return ieee80211_if_config(dev); |
| 272 | } |
| 273 | return -EOPNOTSUPP; |
| 274 | } |
| 275 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 276 | static int ieee80211_ioctl_giwname(struct net_device *dev, |
| 277 | struct iw_request_info *info, |
| 278 | char *name, char *extra) |
| 279 | { |
| 280 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 281 | |
| 282 | switch (local->hw.conf.phymode) { |
| 283 | case MODE_IEEE80211A: |
| 284 | strcpy(name, "IEEE 802.11a"); |
| 285 | break; |
| 286 | case MODE_IEEE80211B: |
| 287 | strcpy(name, "IEEE 802.11b"); |
| 288 | break; |
| 289 | case MODE_IEEE80211G: |
| 290 | strcpy(name, "IEEE 802.11g"); |
| 291 | break; |
| 292 | case MODE_ATHEROS_TURBO: |
| 293 | strcpy(name, "5GHz Turbo"); |
| 294 | break; |
| 295 | default: |
| 296 | strcpy(name, "IEEE 802.11"); |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | |
| 304 | static int ieee80211_ioctl_giwrange(struct net_device *dev, |
| 305 | struct iw_request_info *info, |
| 306 | struct iw_point *data, char *extra) |
| 307 | { |
| 308 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 309 | struct iw_range *range = (struct iw_range *) extra; |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 310 | struct ieee80211_hw_mode *mode = NULL; |
| 311 | int c = 0; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 312 | |
| 313 | data->length = sizeof(struct iw_range); |
| 314 | memset(range, 0, sizeof(struct iw_range)); |
| 315 | |
| 316 | range->we_version_compiled = WIRELESS_EXT; |
| 317 | range->we_version_source = 21; |
| 318 | range->retry_capa = IW_RETRY_LIMIT; |
| 319 | range->retry_flags = IW_RETRY_LIMIT; |
| 320 | range->min_retry = 0; |
| 321 | range->max_retry = 255; |
| 322 | range->min_rts = 0; |
| 323 | range->max_rts = 2347; |
| 324 | range->min_frag = 256; |
| 325 | range->max_frag = 2346; |
| 326 | |
| 327 | range->encoding_size[0] = 5; |
| 328 | range->encoding_size[1] = 13; |
| 329 | range->num_encoding_sizes = 2; |
| 330 | range->max_encoding_tokens = NUM_DEFAULT_KEYS; |
| 331 | |
| 332 | range->max_qual.qual = local->hw.max_signal; |
| 333 | range->max_qual.level = local->hw.max_rssi; |
| 334 | range->max_qual.noise = local->hw.max_noise; |
| 335 | range->max_qual.updated = local->wstats_flags; |
| 336 | |
| 337 | range->avg_qual.qual = local->hw.max_signal/2; |
| 338 | range->avg_qual.level = 0; |
| 339 | range->avg_qual.noise = 0; |
| 340 | range->avg_qual.updated = local->wstats_flags; |
| 341 | |
| 342 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 343 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 344 | |
Hong Liu | 333af2f | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 345 | list_for_each_entry(mode, &local->modes_list, list) { |
| 346 | int i = 0; |
| 347 | |
| 348 | if (!(local->enabled_modes & (1 << mode->mode)) || |
| 349 | (local->hw_modes & local->enabled_modes & |
| 350 | (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B)) |
| 351 | continue; |
| 352 | |
| 353 | while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) { |
| 354 | struct ieee80211_channel *chan = &mode->channels[i]; |
| 355 | |
| 356 | if (chan->flag & IEEE80211_CHAN_W_SCAN) { |
| 357 | range->freq[c].i = chan->chan; |
| 358 | range->freq[c].m = chan->freq * 100000; |
| 359 | range->freq[c].e = 1; |
| 360 | c++; |
| 361 | } |
| 362 | i++; |
| 363 | } |
| 364 | } |
| 365 | range->num_channels = c; |
| 366 | range->num_frequency = c; |
| 367 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 368 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); |
| 369 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY); |
| 370 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
| 371 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 377 | static int ieee80211_ioctl_siwmode(struct net_device *dev, |
| 378 | struct iw_request_info *info, |
| 379 | __u32 *mode, char *extra) |
| 380 | { |
| 381 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 382 | int type; |
| 383 | |
| 384 | if (sdata->type == IEEE80211_IF_TYPE_VLAN) |
| 385 | return -EOPNOTSUPP; |
| 386 | |
| 387 | switch (*mode) { |
| 388 | case IW_MODE_INFRA: |
| 389 | type = IEEE80211_IF_TYPE_STA; |
| 390 | break; |
| 391 | case IW_MODE_ADHOC: |
| 392 | type = IEEE80211_IF_TYPE_IBSS; |
| 393 | break; |
| 394 | case IW_MODE_MONITOR: |
| 395 | type = IEEE80211_IF_TYPE_MNTR; |
| 396 | break; |
| 397 | default: |
| 398 | return -EINVAL; |
| 399 | } |
| 400 | |
| 401 | if (type == sdata->type) |
| 402 | return 0; |
| 403 | if (netif_running(dev)) |
| 404 | return -EBUSY; |
| 405 | |
| 406 | ieee80211_if_reinit(dev); |
| 407 | ieee80211_if_set_type(dev, type); |
| 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | static int ieee80211_ioctl_giwmode(struct net_device *dev, |
| 414 | struct iw_request_info *info, |
| 415 | __u32 *mode, char *extra) |
| 416 | { |
| 417 | struct ieee80211_sub_if_data *sdata; |
| 418 | |
| 419 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 420 | switch (sdata->type) { |
| 421 | case IEEE80211_IF_TYPE_AP: |
| 422 | *mode = IW_MODE_MASTER; |
| 423 | break; |
| 424 | case IEEE80211_IF_TYPE_STA: |
| 425 | *mode = IW_MODE_INFRA; |
| 426 | break; |
| 427 | case IEEE80211_IF_TYPE_IBSS: |
| 428 | *mode = IW_MODE_ADHOC; |
| 429 | break; |
| 430 | case IEEE80211_IF_TYPE_MNTR: |
| 431 | *mode = IW_MODE_MONITOR; |
| 432 | break; |
| 433 | case IEEE80211_IF_TYPE_WDS: |
| 434 | *mode = IW_MODE_REPEAT; |
| 435 | break; |
| 436 | case IEEE80211_IF_TYPE_VLAN: |
| 437 | *mode = IW_MODE_SECOND; /* FIXME */ |
| 438 | break; |
| 439 | default: |
| 440 | *mode = IW_MODE_AUTO; |
| 441 | break; |
| 442 | } |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq) |
| 447 | { |
| 448 | struct ieee80211_hw_mode *mode; |
| 449 | int c, set = 0; |
| 450 | int ret = -EINVAL; |
| 451 | |
| 452 | list_for_each_entry(mode, &local->modes_list, list) { |
| 453 | if (!(local->enabled_modes & (1 << mode->mode))) |
| 454 | continue; |
| 455 | for (c = 0; c < mode->num_channels; c++) { |
| 456 | struct ieee80211_channel *chan = &mode->channels[c]; |
| 457 | if (chan->flag & IEEE80211_CHAN_W_SCAN && |
| 458 | ((chan->chan == channel) || (chan->freq == freq))) { |
| 459 | /* Use next_mode as the mode preference to |
| 460 | * resolve non-unique channel numbers. */ |
| 461 | if (set && mode->mode != local->next_mode) |
| 462 | continue; |
| 463 | |
| 464 | local->oper_channel = chan; |
| 465 | local->oper_hw_mode = mode; |
| 466 | set++; |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (set) { |
| 472 | if (local->sta_scanning) |
| 473 | ret = 0; |
| 474 | else |
| 475 | ret = ieee80211_hw_config(local); |
| 476 | |
| 477 | rate_control_clear(local); |
| 478 | } |
| 479 | |
| 480 | return ret; |
| 481 | } |
| 482 | |
| 483 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
| 484 | struct iw_request_info *info, |
| 485 | struct iw_freq *freq, char *extra) |
| 486 | { |
| 487 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 488 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 489 | |
| 490 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 491 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 492 | |
| 493 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ |
| 494 | if (freq->e == 0) { |
| 495 | if (freq->m < 0) { |
| 496 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 497 | sdata->u.sta.flags |= |
| 498 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 499 | return 0; |
| 500 | } else |
| 501 | return ieee80211_set_channel(local, freq->m, -1); |
| 502 | } else { |
| 503 | int i, div = 1000000; |
| 504 | for (i = 0; i < freq->e; i++) |
| 505 | div /= 10; |
| 506 | if (div > 0) |
| 507 | return ieee80211_set_channel(local, -1, freq->m / div); |
| 508 | else |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | |
| 514 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, |
| 515 | struct iw_request_info *info, |
| 516 | struct iw_freq *freq, char *extra) |
| 517 | { |
| 518 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 519 | |
| 520 | /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level |
| 521 | * driver for the current channel with firmware-based management */ |
| 522 | |
| 523 | freq->m = local->hw.conf.freq; |
| 524 | freq->e = 6; |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | |
| 530 | static int ieee80211_ioctl_siwessid(struct net_device *dev, |
| 531 | struct iw_request_info *info, |
| 532 | struct iw_point *data, char *ssid) |
| 533 | { |
| 534 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 535 | struct ieee80211_sub_if_data *sdata; |
| 536 | size_t len = data->length; |
| 537 | |
| 538 | /* iwconfig uses nul termination in SSID.. */ |
| 539 | if (len > 0 && ssid[len - 1] == '\0') |
| 540 | len--; |
| 541 | |
| 542 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 543 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 544 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 545 | int ret; |
| 546 | if (local->user_space_mlme) { |
| 547 | if (len > IEEE80211_MAX_SSID_LEN) |
| 548 | return -EINVAL; |
| 549 | memcpy(sdata->u.sta.ssid, ssid, len); |
| 550 | sdata->u.sta.ssid_len = len; |
| 551 | return 0; |
| 552 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 553 | if (data->flags) |
| 554 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; |
| 555 | else |
| 556 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 557 | ret = ieee80211_sta_set_ssid(dev, ssid, len); |
| 558 | if (ret) |
| 559 | return ret; |
| 560 | ieee80211_sta_req_auth(dev, &sdata->u.sta); |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
| 565 | memcpy(sdata->u.ap.ssid, ssid, len); |
| 566 | memset(sdata->u.ap.ssid + len, 0, |
| 567 | IEEE80211_MAX_SSID_LEN - len); |
| 568 | sdata->u.ap.ssid_len = len; |
| 569 | return ieee80211_if_config(dev); |
| 570 | } |
| 571 | return -EOPNOTSUPP; |
| 572 | } |
| 573 | |
| 574 | |
| 575 | static int ieee80211_ioctl_giwessid(struct net_device *dev, |
| 576 | struct iw_request_info *info, |
| 577 | struct iw_point *data, char *ssid) |
| 578 | { |
| 579 | size_t len; |
| 580 | |
| 581 | struct ieee80211_sub_if_data *sdata; |
| 582 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 583 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 584 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 585 | int res = ieee80211_sta_get_ssid(dev, ssid, &len); |
| 586 | if (res == 0) { |
| 587 | data->length = len; |
| 588 | data->flags = 1; |
| 589 | } else |
| 590 | data->flags = 0; |
| 591 | return res; |
| 592 | } |
| 593 | |
| 594 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
| 595 | len = sdata->u.ap.ssid_len; |
| 596 | if (len > IW_ESSID_MAX_SIZE) |
| 597 | len = IW_ESSID_MAX_SIZE; |
| 598 | memcpy(ssid, sdata->u.ap.ssid, len); |
| 599 | data->length = len; |
| 600 | data->flags = 1; |
| 601 | return 0; |
| 602 | } |
| 603 | return -EOPNOTSUPP; |
| 604 | } |
| 605 | |
| 606 | |
| 607 | static int ieee80211_ioctl_siwap(struct net_device *dev, |
| 608 | struct iw_request_info *info, |
| 609 | struct sockaddr *ap_addr, char *extra) |
| 610 | { |
| 611 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 612 | struct ieee80211_sub_if_data *sdata; |
| 613 | |
| 614 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 615 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 616 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 617 | int ret; |
| 618 | if (local->user_space_mlme) { |
| 619 | memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data, |
| 620 | ETH_ALEN); |
| 621 | return 0; |
| 622 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 623 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
| 624 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL | |
| 625 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
| 626 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) |
| 627 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 628 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 629 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 630 | ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data); |
| 631 | if (ret) |
| 632 | return ret; |
| 633 | ieee80211_sta_req_auth(dev, &sdata->u.sta); |
| 634 | return 0; |
| 635 | } else if (sdata->type == IEEE80211_IF_TYPE_WDS) { |
| 636 | if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, |
| 637 | ETH_ALEN) == 0) |
| 638 | return 0; |
| 639 | return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data); |
| 640 | } |
| 641 | |
| 642 | return -EOPNOTSUPP; |
| 643 | } |
| 644 | |
| 645 | |
| 646 | static int ieee80211_ioctl_giwap(struct net_device *dev, |
| 647 | struct iw_request_info *info, |
| 648 | struct sockaddr *ap_addr, char *extra) |
| 649 | { |
| 650 | struct ieee80211_sub_if_data *sdata; |
| 651 | |
| 652 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 653 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 654 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 655 | ap_addr->sa_family = ARPHRD_ETHER; |
| 656 | memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN); |
| 657 | return 0; |
| 658 | } else if (sdata->type == IEEE80211_IF_TYPE_WDS) { |
| 659 | ap_addr->sa_family = ARPHRD_ETHER; |
| 660 | memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); |
| 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | return -EOPNOTSUPP; |
| 665 | } |
| 666 | |
| 667 | |
| 668 | static int ieee80211_ioctl_siwscan(struct net_device *dev, |
| 669 | struct iw_request_info *info, |
| 670 | struct iw_point *data, char *extra) |
| 671 | { |
| 672 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 673 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 674 | u8 *ssid = NULL; |
| 675 | size_t ssid_len = 0; |
| 676 | |
| 677 | if (!netif_running(dev)) |
| 678 | return -ENETDOWN; |
| 679 | |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 680 | switch (sdata->type) { |
| 681 | case IEEE80211_IF_TYPE_STA: |
| 682 | case IEEE80211_IF_TYPE_IBSS: |
| 683 | if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 684 | ssid = sdata->u.sta.ssid; |
| 685 | ssid_len = sdata->u.sta.ssid_len; |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 686 | } |
| 687 | break; |
| 688 | case IEEE80211_IF_TYPE_AP: |
| 689 | if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 690 | ssid = sdata->u.ap.ssid; |
| 691 | ssid_len = sdata->u.ap.ssid_len; |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 692 | } |
| 693 | break; |
| 694 | default: |
| 695 | return -EOPNOTSUPP; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 696 | } |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 697 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 698 | return ieee80211_sta_req_scan(dev, ssid, ssid_len); |
| 699 | } |
| 700 | |
| 701 | |
| 702 | static int ieee80211_ioctl_giwscan(struct net_device *dev, |
| 703 | struct iw_request_info *info, |
| 704 | struct iw_point *data, char *extra) |
| 705 | { |
| 706 | int res; |
| 707 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 708 | if (local->sta_scanning) |
| 709 | return -EAGAIN; |
| 710 | res = ieee80211_sta_scan_results(dev, extra, data->length); |
| 711 | if (res >= 0) { |
| 712 | data->length = res; |
| 713 | return 0; |
| 714 | } |
| 715 | data->length = 0; |
| 716 | return res; |
| 717 | } |
| 718 | |
| 719 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 720 | static int ieee80211_ioctl_siwrate(struct net_device *dev, |
| 721 | struct iw_request_info *info, |
| 722 | struct iw_param *rate, char *extra) |
| 723 | { |
| 724 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 725 | struct ieee80211_hw_mode *mode; |
| 726 | int i; |
| 727 | u32 target_rate = rate->value / 100000; |
| 728 | struct ieee80211_sub_if_data *sdata; |
| 729 | |
| 730 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 731 | if (!sdata->bss) |
| 732 | return -ENODEV; |
| 733 | mode = local->oper_hw_mode; |
| 734 | /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates |
| 735 | * target_rate = X, rate->fixed = 1 means only rate X |
| 736 | * target_rate = X, rate->fixed = 0 means all rates <= X */ |
| 737 | sdata->bss->max_ratectrl_rateidx = -1; |
| 738 | sdata->bss->force_unicast_rateidx = -1; |
| 739 | if (rate->value < 0) |
| 740 | return 0; |
| 741 | for (i=0; i< mode->num_rates; i++) { |
| 742 | struct ieee80211_rate *rates = &mode->rates[i]; |
| 743 | int this_rate = rates->rate; |
| 744 | |
| 745 | if (mode->mode == MODE_ATHEROS_TURBO || |
| 746 | mode->mode == MODE_ATHEROS_TURBOG) |
| 747 | this_rate *= 2; |
| 748 | if (target_rate == this_rate) { |
| 749 | sdata->bss->max_ratectrl_rateidx = i; |
| 750 | if (rate->fixed) |
| 751 | sdata->bss->force_unicast_rateidx = i; |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | return 0; |
| 756 | } |
| 757 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 758 | static int ieee80211_ioctl_giwrate(struct net_device *dev, |
| 759 | struct iw_request_info *info, |
| 760 | struct iw_param *rate, char *extra) |
| 761 | { |
| 762 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 763 | struct sta_info *sta; |
| 764 | struct ieee80211_sub_if_data *sdata; |
| 765 | |
| 766 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 767 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
| 768 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 769 | else |
| 770 | return -EOPNOTSUPP; |
| 771 | if (!sta) |
| 772 | return -ENODEV; |
| 773 | if (sta->txrate < local->oper_hw_mode->num_rates) |
| 774 | rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000; |
| 775 | else |
| 776 | rate->value = 0; |
| 777 | sta_info_put(sta); |
| 778 | return 0; |
| 779 | } |
| 780 | |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 781 | static int ieee80211_ioctl_giwtxpower(struct net_device *dev, |
| 782 | struct iw_request_info *info, |
| 783 | union iwreq_data *data, char *extra) |
| 784 | { |
| 785 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 786 | |
| 787 | data->txpower.fixed = 1; |
| 788 | data->txpower.disabled = !(local->hw.conf.radio_enabled); |
| 789 | data->txpower.value = local->hw.conf.power_level; |
| 790 | data->txpower.flags = IW_TXPOW_DBM; |
| 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 795 | static int ieee80211_ioctl_siwrts(struct net_device *dev, |
| 796 | struct iw_request_info *info, |
| 797 | struct iw_param *rts, char *extra) |
| 798 | { |
| 799 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 800 | |
| 801 | if (rts->disabled) |
| 802 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
| 803 | else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD) |
| 804 | return -EINVAL; |
| 805 | else |
| 806 | local->rts_threshold = rts->value; |
| 807 | |
| 808 | /* If the wlan card performs RTS/CTS in hardware/firmware, |
| 809 | * configure it here */ |
| 810 | |
| 811 | if (local->ops->set_rts_threshold) |
| 812 | local->ops->set_rts_threshold(local_to_hw(local), |
| 813 | local->rts_threshold); |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | static int ieee80211_ioctl_giwrts(struct net_device *dev, |
| 819 | struct iw_request_info *info, |
| 820 | struct iw_param *rts, char *extra) |
| 821 | { |
| 822 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 823 | |
| 824 | rts->value = local->rts_threshold; |
| 825 | rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 826 | rts->fixed = 1; |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | |
| 832 | static int ieee80211_ioctl_siwfrag(struct net_device *dev, |
| 833 | struct iw_request_info *info, |
| 834 | struct iw_param *frag, char *extra) |
| 835 | { |
| 836 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 837 | |
| 838 | if (frag->disabled) |
| 839 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; |
| 840 | else if (frag->value < 256 || |
| 841 | frag->value > IEEE80211_MAX_FRAG_THRESHOLD) |
| 842 | return -EINVAL; |
| 843 | else { |
| 844 | /* Fragment length must be even, so strip LSB. */ |
| 845 | local->fragmentation_threshold = frag->value & ~0x1; |
| 846 | } |
| 847 | |
| 848 | /* If the wlan card performs fragmentation in hardware/firmware, |
| 849 | * configure it here */ |
| 850 | |
| 851 | if (local->ops->set_frag_threshold) |
| 852 | local->ops->set_frag_threshold( |
| 853 | local_to_hw(local), |
| 854 | local->fragmentation_threshold); |
| 855 | |
| 856 | return 0; |
| 857 | } |
| 858 | |
| 859 | static int ieee80211_ioctl_giwfrag(struct net_device *dev, |
| 860 | struct iw_request_info *info, |
| 861 | struct iw_param *frag, char *extra) |
| 862 | { |
| 863 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 864 | |
| 865 | frag->value = local->fragmentation_threshold; |
| 866 | frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 867 | frag->fixed = 1; |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | |
| 873 | static int ieee80211_ioctl_siwretry(struct net_device *dev, |
| 874 | struct iw_request_info *info, |
| 875 | struct iw_param *retry, char *extra) |
| 876 | { |
| 877 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 878 | |
| 879 | if (retry->disabled || |
| 880 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) |
| 881 | return -EINVAL; |
| 882 | |
| 883 | if (retry->flags & IW_RETRY_MAX) |
| 884 | local->long_retry_limit = retry->value; |
| 885 | else if (retry->flags & IW_RETRY_MIN) |
| 886 | local->short_retry_limit = retry->value; |
| 887 | else { |
| 888 | local->long_retry_limit = retry->value; |
| 889 | local->short_retry_limit = retry->value; |
| 890 | } |
| 891 | |
| 892 | if (local->ops->set_retry_limit) { |
| 893 | return local->ops->set_retry_limit( |
| 894 | local_to_hw(local), |
| 895 | local->short_retry_limit, |
| 896 | local->long_retry_limit); |
| 897 | } |
| 898 | |
| 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | |
| 903 | static int ieee80211_ioctl_giwretry(struct net_device *dev, |
| 904 | struct iw_request_info *info, |
| 905 | struct iw_param *retry, char *extra) |
| 906 | { |
| 907 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 908 | |
| 909 | retry->disabled = 0; |
| 910 | if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) { |
| 911 | /* first return min value, iwconfig will ask max value |
| 912 | * later if needed */ |
| 913 | retry->flags |= IW_RETRY_LIMIT; |
| 914 | retry->value = local->short_retry_limit; |
| 915 | if (local->long_retry_limit != local->short_retry_limit) |
| 916 | retry->flags |= IW_RETRY_MIN; |
| 917 | return 0; |
| 918 | } |
| 919 | if (retry->flags & IW_RETRY_MAX) { |
| 920 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 921 | retry->value = local->long_retry_limit; |
| 922 | } |
| 923 | |
| 924 | return 0; |
| 925 | } |
| 926 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 927 | static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local, |
| 928 | struct ieee80211_key *key) |
| 929 | { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 930 | u8 addr[ETH_ALEN]; |
| 931 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 932 | if (!key || key->conf.alg != ALG_WEP || |
| 933 | !(key->conf.flags & IEEE80211_KEY_FORCE_SW_ENCRYPT) || |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 934 | (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP)) |
| 935 | return; |
| 936 | |
| 937 | memset(addr, 0xff, ETH_ALEN); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 938 | |
| 939 | if (local->ops->set_key) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 940 | local->ops->set_key(local_to_hw(local), |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 941 | SET_KEY, addr, &key->conf, |
| 942 | local->default_wep_only); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | |
| 946 | static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local, |
| 947 | struct ieee80211_key *key) |
| 948 | { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 949 | u8 addr[ETH_ALEN]; |
| 950 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 951 | if (!key || key->conf.alg != ALG_WEP || |
| 952 | (key->conf.flags & IEEE80211_KEY_FORCE_SW_ENCRYPT) || |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 953 | (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP)) |
| 954 | return; |
| 955 | |
| 956 | memset(addr, 0xff, ETH_ALEN); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 957 | if (local->ops->set_key) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 958 | local->ops->set_key(local_to_hw(local), DISABLE_KEY, |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 959 | addr, &key->conf, |
| 960 | local->default_wep_only); |
| 961 | key->conf.flags |= IEEE80211_KEY_FORCE_SW_ENCRYPT; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | |
| 965 | static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local, |
| 966 | int value) |
| 967 | { |
| 968 | int i; |
| 969 | struct ieee80211_sub_if_data *sdata; |
| 970 | |
| 971 | local->default_wep_only = value; |
| 972 | read_lock(&local->sub_if_lock); |
| 973 | list_for_each_entry(sdata, &local->sub_if_list, list) |
| 974 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) |
| 975 | if (value) |
| 976 | ieee80211_key_enable_hwaccel(local, |
| 977 | sdata->keys[i]); |
| 978 | else |
| 979 | ieee80211_key_disable_hwaccel(local, |
| 980 | sdata->keys[i]); |
| 981 | read_unlock(&local->sub_if_lock); |
| 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | |
| 987 | void ieee80211_update_default_wep_only(struct ieee80211_local *local) |
| 988 | { |
| 989 | int i = 0; |
| 990 | struct ieee80211_sub_if_data *sdata; |
| 991 | |
| 992 | read_lock(&local->sub_if_lock); |
| 993 | list_for_each_entry(sdata, &local->sub_if_list, list) { |
| 994 | |
| 995 | if (sdata->dev == local->mdev) |
| 996 | continue; |
| 997 | |
| 998 | /* If there is an AP interface then depend on userspace to |
| 999 | set default_wep_only correctly. */ |
| 1000 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
| 1001 | read_unlock(&local->sub_if_lock); |
| 1002 | return; |
| 1003 | } |
| 1004 | |
| 1005 | i++; |
| 1006 | } |
| 1007 | |
| 1008 | read_unlock(&local->sub_if_lock); |
| 1009 | |
| 1010 | if (i <= 1) |
| 1011 | ieee80211_ioctl_default_wep_only(local, 1); |
| 1012 | else |
| 1013 | ieee80211_ioctl_default_wep_only(local, 0); |
| 1014 | } |
| 1015 | |
| 1016 | |
| 1017 | static int ieee80211_ioctl_prism2_param(struct net_device *dev, |
| 1018 | struct iw_request_info *info, |
| 1019 | void *wrqu, char *extra) |
| 1020 | { |
| 1021 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1022 | struct ieee80211_sub_if_data *sdata; |
| 1023 | int *i = (int *) extra; |
| 1024 | int param = *i; |
| 1025 | int value = *(i + 1); |
| 1026 | int ret = 0; |
| 1027 | |
| 1028 | if (!capable(CAP_NET_ADMIN)) |
| 1029 | return -EPERM; |
| 1030 | |
| 1031 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1032 | |
| 1033 | switch (param) { |
| 1034 | case PRISM2_PARAM_IEEE_802_1X: |
| 1035 | if (local->ops->set_ieee8021x) |
| 1036 | ret = local->ops->set_ieee8021x(local_to_hw(local), |
| 1037 | value); |
| 1038 | if (ret) |
| 1039 | printk(KERN_DEBUG "%s: failed to set IEEE 802.1X (%d) " |
| 1040 | "for low-level driver\n", dev->name, value); |
| 1041 | else |
| 1042 | sdata->ieee802_1x = value; |
| 1043 | break; |
| 1044 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1045 | case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES: |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1046 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1047 | if (value) |
| 1048 | sdata->flags |= IEEE80211_SDATA_USE_PROTECTION; |
| 1049 | else |
| 1050 | sdata->flags &= ~IEEE80211_SDATA_USE_PROTECTION; |
| 1051 | ieee80211_erp_info_change_notify(dev, |
| 1052 | IEEE80211_ERP_CHANGE_PROTECTION); |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1053 | } else { |
Daniel Drake | 63fc33c | 2007-07-10 19:32:11 +0200 | [diff] [blame] | 1054 | ret = -ENOENT; |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1055 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1056 | break; |
| 1057 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1058 | case PRISM2_PARAM_PREAMBLE: |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1059 | if (sdata->type != IEEE80211_IF_TYPE_AP) { |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1060 | if (value) |
| 1061 | sdata->flags |= IEEE80211_SDATA_SHORT_PREAMBLE; |
| 1062 | else |
| 1063 | sdata->flags &= ~IEEE80211_SDATA_SHORT_PREAMBLE; |
| 1064 | ieee80211_erp_info_change_notify(dev, |
| 1065 | IEEE80211_ERP_CHANGE_PREAMBLE); |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1066 | } else { |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1067 | ret = -ENOENT; |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1068 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1069 | break; |
| 1070 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1071 | case PRISM2_PARAM_SHORT_SLOT_TIME: |
| 1072 | if (value) |
| 1073 | local->hw.conf.flags |= IEEE80211_CONF_SHORT_SLOT_TIME; |
| 1074 | else |
| 1075 | local->hw.conf.flags &= ~IEEE80211_CONF_SHORT_SLOT_TIME; |
| 1076 | if (ieee80211_hw_config(local)) |
| 1077 | ret = -EINVAL; |
| 1078 | break; |
| 1079 | |
| 1080 | case PRISM2_PARAM_NEXT_MODE: |
| 1081 | local->next_mode = value; |
| 1082 | break; |
| 1083 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1084 | case PRISM2_PARAM_KEY_TX_RX_THRESHOLD: |
| 1085 | local->key_tx_rx_threshold = value; |
| 1086 | break; |
| 1087 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1088 | case PRISM2_PARAM_WIFI_WME_NOACK_TEST: |
| 1089 | local->wifi_wme_noack_test = value; |
| 1090 | break; |
| 1091 | |
| 1092 | case PRISM2_PARAM_SCAN_FLAGS: |
| 1093 | local->scan_flags = value; |
| 1094 | break; |
| 1095 | |
| 1096 | case PRISM2_PARAM_MIXED_CELL: |
| 1097 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 1098 | sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 1099 | ret = -EINVAL; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1100 | else { |
| 1101 | if (value) |
| 1102 | sdata->u.sta.flags |= IEEE80211_STA_MIXED_CELL; |
| 1103 | else |
| 1104 | sdata->u.sta.flags &= ~IEEE80211_STA_MIXED_CELL; |
| 1105 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1106 | break; |
| 1107 | |
| 1108 | case PRISM2_PARAM_HW_MODES: |
| 1109 | local->enabled_modes = value; |
| 1110 | break; |
| 1111 | |
| 1112 | case PRISM2_PARAM_CREATE_IBSS: |
| 1113 | if (sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 1114 | ret = -EINVAL; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1115 | else { |
| 1116 | if (value) |
| 1117 | sdata->u.sta.flags |= IEEE80211_STA_CREATE_IBSS; |
| 1118 | else |
| 1119 | sdata->u.sta.flags &= ~IEEE80211_STA_CREATE_IBSS; |
| 1120 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1121 | break; |
| 1122 | case PRISM2_PARAM_WMM_ENABLED: |
| 1123 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 1124 | sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 1125 | ret = -EINVAL; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1126 | else { |
| 1127 | if (value) |
| 1128 | sdata->u.sta.flags |= IEEE80211_STA_WMM_ENABLED; |
| 1129 | else |
| 1130 | sdata->u.sta.flags &= ~IEEE80211_STA_WMM_ENABLED; |
| 1131 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1132 | break; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1133 | default: |
| 1134 | ret = -EOPNOTSUPP; |
| 1135 | break; |
| 1136 | } |
| 1137 | |
| 1138 | return ret; |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | static int ieee80211_ioctl_get_prism2_param(struct net_device *dev, |
| 1143 | struct iw_request_info *info, |
| 1144 | void *wrqu, char *extra) |
| 1145 | { |
| 1146 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1147 | struct ieee80211_sub_if_data *sdata; |
| 1148 | int *param = (int *) extra; |
| 1149 | int ret = 0; |
| 1150 | |
| 1151 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1152 | |
| 1153 | switch (*param) { |
| 1154 | case PRISM2_PARAM_IEEE_802_1X: |
| 1155 | *param = sdata->ieee802_1x; |
| 1156 | break; |
| 1157 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1158 | case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES: |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1159 | *param = !!(sdata->flags & IEEE80211_SDATA_USE_PROTECTION); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1160 | break; |
| 1161 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1162 | case PRISM2_PARAM_PREAMBLE: |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1163 | *param = !!(sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1164 | break; |
| 1165 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1166 | case PRISM2_PARAM_SHORT_SLOT_TIME: |
| 1167 | *param = !!(local->hw.conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME); |
| 1168 | break; |
| 1169 | |
| 1170 | case PRISM2_PARAM_NEXT_MODE: |
| 1171 | *param = local->next_mode; |
| 1172 | break; |
| 1173 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1174 | case PRISM2_PARAM_KEY_TX_RX_THRESHOLD: |
| 1175 | *param = local->key_tx_rx_threshold; |
| 1176 | break; |
| 1177 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1178 | case PRISM2_PARAM_WIFI_WME_NOACK_TEST: |
| 1179 | *param = local->wifi_wme_noack_test; |
| 1180 | break; |
| 1181 | |
| 1182 | case PRISM2_PARAM_SCAN_FLAGS: |
| 1183 | *param = local->scan_flags; |
| 1184 | break; |
| 1185 | |
| 1186 | case PRISM2_PARAM_HW_MODES: |
| 1187 | *param = local->enabled_modes; |
| 1188 | break; |
| 1189 | |
| 1190 | case PRISM2_PARAM_CREATE_IBSS: |
| 1191 | if (sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 1192 | ret = -EINVAL; |
| 1193 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1194 | *param = !!(sdata->u.sta.flags & |
| 1195 | IEEE80211_STA_CREATE_IBSS); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1196 | break; |
| 1197 | |
| 1198 | case PRISM2_PARAM_MIXED_CELL: |
| 1199 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 1200 | sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 1201 | ret = -EINVAL; |
| 1202 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1203 | *param = !!(sdata->u.sta.flags & |
| 1204 | IEEE80211_STA_MIXED_CELL); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1205 | break; |
| 1206 | case PRISM2_PARAM_WMM_ENABLED: |
| 1207 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 1208 | sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 1209 | ret = -EINVAL; |
| 1210 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1211 | *param = !!(sdata->u.sta.flags & |
| 1212 | IEEE80211_STA_WMM_ENABLED); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1213 | break; |
| 1214 | default: |
| 1215 | ret = -EOPNOTSUPP; |
| 1216 | break; |
| 1217 | } |
| 1218 | |
| 1219 | return ret; |
| 1220 | } |
| 1221 | |
| 1222 | static int ieee80211_ioctl_siwmlme(struct net_device *dev, |
| 1223 | struct iw_request_info *info, |
| 1224 | struct iw_point *data, char *extra) |
| 1225 | { |
| 1226 | struct ieee80211_sub_if_data *sdata; |
| 1227 | struct iw_mlme *mlme = (struct iw_mlme *) extra; |
| 1228 | |
| 1229 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1230 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 1231 | sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 1232 | return -EINVAL; |
| 1233 | |
| 1234 | switch (mlme->cmd) { |
| 1235 | case IW_MLME_DEAUTH: |
| 1236 | /* TODO: mlme->addr.sa_data */ |
| 1237 | return ieee80211_sta_deauthenticate(dev, mlme->reason_code); |
| 1238 | case IW_MLME_DISASSOC: |
| 1239 | /* TODO: mlme->addr.sa_data */ |
| 1240 | return ieee80211_sta_disassociate(dev, mlme->reason_code); |
| 1241 | default: |
| 1242 | return -EOPNOTSUPP; |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | |
| 1247 | static int ieee80211_ioctl_siwencode(struct net_device *dev, |
| 1248 | struct iw_request_info *info, |
| 1249 | struct iw_point *erq, char *keybuf) |
| 1250 | { |
| 1251 | struct ieee80211_sub_if_data *sdata; |
| 1252 | int idx, i, alg = ALG_WEP; |
| 1253 | u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 1254 | |
| 1255 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1256 | |
| 1257 | idx = erq->flags & IW_ENCODE_INDEX; |
| 1258 | if (idx == 0) { |
| 1259 | if (sdata->default_key) |
| 1260 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1261 | if (sdata->default_key == sdata->keys[i]) { |
| 1262 | idx = i; |
| 1263 | break; |
| 1264 | } |
| 1265 | } |
| 1266 | } else if (idx < 1 || idx > 4) |
| 1267 | return -EINVAL; |
| 1268 | else |
| 1269 | idx--; |
| 1270 | |
| 1271 | if (erq->flags & IW_ENCODE_DISABLED) |
| 1272 | alg = ALG_NONE; |
| 1273 | else if (erq->length == 0) { |
| 1274 | /* No key data - just set the default TX key index */ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1275 | if (sdata->default_key != sdata->keys[idx]) { |
| 1276 | ieee80211_debugfs_key_remove_default(sdata); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1277 | sdata->default_key = sdata->keys[idx]; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1278 | if (sdata->default_key) |
| 1279 | ieee80211_debugfs_key_add_default(sdata); |
| 1280 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | return ieee80211_set_encryption( |
| 1285 | dev, bcaddr, |
| 1286 | idx, alg, |
| 1287 | !sdata->default_key, |
| 1288 | keybuf, erq->length); |
| 1289 | } |
| 1290 | |
| 1291 | |
| 1292 | static int ieee80211_ioctl_giwencode(struct net_device *dev, |
| 1293 | struct iw_request_info *info, |
| 1294 | struct iw_point *erq, char *key) |
| 1295 | { |
| 1296 | struct ieee80211_sub_if_data *sdata; |
| 1297 | int idx, i; |
| 1298 | |
| 1299 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1300 | |
| 1301 | idx = erq->flags & IW_ENCODE_INDEX; |
| 1302 | if (idx < 1 || idx > 4) { |
| 1303 | idx = -1; |
| 1304 | if (!sdata->default_key) |
| 1305 | idx = 0; |
| 1306 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1307 | if (sdata->default_key == sdata->keys[i]) { |
| 1308 | idx = i; |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | if (idx < 0) |
| 1313 | return -EINVAL; |
| 1314 | } else |
| 1315 | idx--; |
| 1316 | |
| 1317 | erq->flags = idx + 1; |
| 1318 | |
| 1319 | if (!sdata->keys[idx]) { |
| 1320 | erq->length = 0; |
| 1321 | erq->flags |= IW_ENCODE_DISABLED; |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame^] | 1325 | memcpy(key, sdata->keys[idx]->conf.key, |
| 1326 | min((int)erq->length, sdata->keys[idx]->conf.keylen)); |
| 1327 | erq->length = sdata->keys[idx]->conf.keylen; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1328 | erq->flags |= IW_ENCODE_ENABLED; |
| 1329 | |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
| 1333 | static int ieee80211_ioctl_siwauth(struct net_device *dev, |
| 1334 | struct iw_request_info *info, |
| 1335 | struct iw_param *data, char *extra) |
| 1336 | { |
| 1337 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1338 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1339 | int ret = 0; |
| 1340 | |
| 1341 | switch (data->flags & IW_AUTH_INDEX) { |
| 1342 | case IW_AUTH_WPA_VERSION: |
| 1343 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1344 | case IW_AUTH_CIPHER_GROUP: |
| 1345 | case IW_AUTH_WPA_ENABLED: |
| 1346 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 1347 | break; |
| 1348 | case IW_AUTH_KEY_MGMT: |
| 1349 | if (sdata->type != IEEE80211_IF_TYPE_STA) |
| 1350 | ret = -EINVAL; |
| 1351 | else { |
| 1352 | /* |
Johannes Berg | 808718c | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1353 | * Key management was set by wpa_supplicant, |
| 1354 | * we only need this to associate to a network |
| 1355 | * that has privacy enabled regardless of not |
| 1356 | * having a key. |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1357 | */ |
Johannes Berg | 808718c | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1358 | sdata->u.sta.key_management_enabled = !!data->value; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1359 | } |
| 1360 | break; |
| 1361 | case IW_AUTH_80211_AUTH_ALG: |
| 1362 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 1363 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 1364 | sdata->u.sta.auth_algs = data->value; |
| 1365 | else |
| 1366 | ret = -EOPNOTSUPP; |
| 1367 | break; |
| 1368 | case IW_AUTH_PRIVACY_INVOKED: |
| 1369 | if (local->ops->set_privacy_invoked) |
| 1370 | ret = local->ops->set_privacy_invoked( |
| 1371 | local_to_hw(local), data->value); |
| 1372 | break; |
| 1373 | default: |
| 1374 | ret = -EOPNOTSUPP; |
| 1375 | break; |
| 1376 | } |
| 1377 | return ret; |
| 1378 | } |
| 1379 | |
| 1380 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
| 1381 | static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev) |
| 1382 | { |
| 1383 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1384 | struct iw_statistics *wstats = &local->wstats; |
| 1385 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1386 | struct sta_info *sta = NULL; |
| 1387 | |
| 1388 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 1389 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 1390 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 1391 | if (!sta) { |
| 1392 | wstats->discard.fragment = 0; |
| 1393 | wstats->discard.misc = 0; |
| 1394 | wstats->qual.qual = 0; |
| 1395 | wstats->qual.level = 0; |
| 1396 | wstats->qual.noise = 0; |
| 1397 | wstats->qual.updated = IW_QUAL_ALL_INVALID; |
| 1398 | } else { |
| 1399 | wstats->qual.level = sta->last_rssi; |
| 1400 | wstats->qual.qual = sta->last_signal; |
| 1401 | wstats->qual.noise = sta->last_noise; |
| 1402 | wstats->qual.updated = local->wstats_flags; |
| 1403 | sta_info_put(sta); |
| 1404 | } |
| 1405 | return wstats; |
| 1406 | } |
| 1407 | |
| 1408 | static int ieee80211_ioctl_giwauth(struct net_device *dev, |
| 1409 | struct iw_request_info *info, |
| 1410 | struct iw_param *data, char *extra) |
| 1411 | { |
| 1412 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1413 | int ret = 0; |
| 1414 | |
| 1415 | switch (data->flags & IW_AUTH_INDEX) { |
| 1416 | case IW_AUTH_80211_AUTH_ALG: |
| 1417 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 1418 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 1419 | data->value = sdata->u.sta.auth_algs; |
| 1420 | else |
| 1421 | ret = -EOPNOTSUPP; |
| 1422 | break; |
| 1423 | default: |
| 1424 | ret = -EOPNOTSUPP; |
| 1425 | break; |
| 1426 | } |
| 1427 | return ret; |
| 1428 | } |
| 1429 | |
| 1430 | |
| 1431 | static int ieee80211_ioctl_siwencodeext(struct net_device *dev, |
| 1432 | struct iw_request_info *info, |
| 1433 | struct iw_point *erq, char *extra) |
| 1434 | { |
| 1435 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1436 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; |
| 1437 | int alg, idx, i; |
| 1438 | |
| 1439 | switch (ext->alg) { |
| 1440 | case IW_ENCODE_ALG_NONE: |
| 1441 | alg = ALG_NONE; |
| 1442 | break; |
| 1443 | case IW_ENCODE_ALG_WEP: |
| 1444 | alg = ALG_WEP; |
| 1445 | break; |
| 1446 | case IW_ENCODE_ALG_TKIP: |
| 1447 | alg = ALG_TKIP; |
| 1448 | break; |
| 1449 | case IW_ENCODE_ALG_CCMP: |
| 1450 | alg = ALG_CCMP; |
| 1451 | break; |
| 1452 | default: |
| 1453 | return -EOPNOTSUPP; |
| 1454 | } |
| 1455 | |
| 1456 | if (erq->flags & IW_ENCODE_DISABLED) |
| 1457 | alg = ALG_NONE; |
| 1458 | |
| 1459 | idx = erq->flags & IW_ENCODE_INDEX; |
| 1460 | if (idx < 1 || idx > 4) { |
| 1461 | idx = -1; |
| 1462 | if (!sdata->default_key) |
| 1463 | idx = 0; |
| 1464 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1465 | if (sdata->default_key == sdata->keys[i]) { |
| 1466 | idx = i; |
| 1467 | break; |
| 1468 | } |
| 1469 | } |
| 1470 | if (idx < 0) |
| 1471 | return -EINVAL; |
| 1472 | } else |
| 1473 | idx--; |
| 1474 | |
| 1475 | return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg, |
| 1476 | ext->ext_flags & |
| 1477 | IW_ENCODE_EXT_SET_TX_KEY, |
| 1478 | ext->key, ext->key_len); |
| 1479 | } |
| 1480 | |
| 1481 | |
| 1482 | static const struct iw_priv_args ieee80211_ioctl_priv[] = { |
| 1483 | { PRISM2_IOCTL_PRISM2_PARAM, |
| 1484 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "param" }, |
| 1485 | { PRISM2_IOCTL_GET_PRISM2_PARAM, |
| 1486 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1487 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param" }, |
| 1488 | }; |
| 1489 | |
| 1490 | /* Structures to export the Wireless Handlers */ |
| 1491 | |
| 1492 | static const iw_handler ieee80211_handler[] = |
| 1493 | { |
| 1494 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
| 1495 | (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */ |
| 1496 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 1497 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 1498 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ |
| 1499 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ |
| 1500 | (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */ |
| 1501 | (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */ |
| 1502 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 1503 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 1504 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ |
| 1505 | (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */ |
| 1506 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ |
| 1507 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ |
| 1508 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ |
| 1509 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ |
| 1510 | iw_handler_set_spy, /* SIOCSIWSPY */ |
| 1511 | iw_handler_get_spy, /* SIOCGIWSPY */ |
| 1512 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ |
| 1513 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ |
| 1514 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
| 1515 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ |
| 1516 | (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ |
| 1517 | (iw_handler) NULL, /* SIOCGIWAPLIST */ |
| 1518 | (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */ |
| 1519 | (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */ |
| 1520 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ |
| 1521 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ |
| 1522 | (iw_handler) NULL, /* SIOCSIWNICKN */ |
| 1523 | (iw_handler) NULL, /* SIOCGIWNICKN */ |
| 1524 | (iw_handler) NULL, /* -- hole -- */ |
| 1525 | (iw_handler) NULL, /* -- hole -- */ |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1526 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 1527 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1528 | (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ |
| 1529 | (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ |
| 1530 | (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ |
| 1531 | (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ |
| 1532 | (iw_handler) NULL, /* SIOCSIWTXPOW */ |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 1533 | (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1534 | (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ |
| 1535 | (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ |
| 1536 | (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ |
| 1537 | (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ |
| 1538 | (iw_handler) NULL, /* SIOCSIWPOWER */ |
| 1539 | (iw_handler) NULL, /* SIOCGIWPOWER */ |
| 1540 | (iw_handler) NULL, /* -- hole -- */ |
| 1541 | (iw_handler) NULL, /* -- hole -- */ |
| 1542 | (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */ |
| 1543 | (iw_handler) NULL, /* SIOCGIWGENIE */ |
| 1544 | (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ |
| 1545 | (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ |
| 1546 | (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ |
| 1547 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ |
| 1548 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 1549 | (iw_handler) NULL, /* -- hole -- */ |
| 1550 | }; |
| 1551 | |
| 1552 | static const iw_handler ieee80211_private_handler[] = |
| 1553 | { /* SIOCIWFIRSTPRIV + */ |
| 1554 | (iw_handler) ieee80211_ioctl_prism2_param, /* 0 */ |
| 1555 | (iw_handler) ieee80211_ioctl_get_prism2_param, /* 1 */ |
| 1556 | }; |
| 1557 | |
| 1558 | const struct iw_handler_def ieee80211_iw_handler_def = |
| 1559 | { |
| 1560 | .num_standard = ARRAY_SIZE(ieee80211_handler), |
| 1561 | .num_private = ARRAY_SIZE(ieee80211_private_handler), |
| 1562 | .num_private_args = ARRAY_SIZE(ieee80211_ioctl_priv), |
| 1563 | .standard = (iw_handler *) ieee80211_handler, |
| 1564 | .private = (iw_handler *) ieee80211_private_handler, |
| 1565 | .private_args = (struct iw_priv_args *) ieee80211_ioctl_priv, |
| 1566 | .get_wireless_stats = ieee80211_get_wireless_stats, |
| 1567 | }; |