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 | |
Dan Williams | 374fdfb | 2007-12-12 10:25:07 -0500 | [diff] [blame^] | 221 | range->scan_capa |= IW_SCAN_CAPA_ESSID; |
| 222 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 227 | static int ieee80211_ioctl_siwmode(struct net_device *dev, |
| 228 | struct iw_request_info *info, |
| 229 | __u32 *mode, char *extra) |
| 230 | { |
| 231 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 232 | int type; |
| 233 | |
| 234 | if (sdata->type == IEEE80211_IF_TYPE_VLAN) |
| 235 | return -EOPNOTSUPP; |
| 236 | |
| 237 | switch (*mode) { |
| 238 | case IW_MODE_INFRA: |
| 239 | type = IEEE80211_IF_TYPE_STA; |
| 240 | break; |
| 241 | case IW_MODE_ADHOC: |
| 242 | type = IEEE80211_IF_TYPE_IBSS; |
| 243 | break; |
| 244 | case IW_MODE_MONITOR: |
| 245 | type = IEEE80211_IF_TYPE_MNTR; |
| 246 | break; |
| 247 | default: |
| 248 | return -EINVAL; |
| 249 | } |
| 250 | |
| 251 | if (type == sdata->type) |
| 252 | return 0; |
| 253 | if (netif_running(dev)) |
| 254 | return -EBUSY; |
| 255 | |
| 256 | ieee80211_if_reinit(dev); |
| 257 | ieee80211_if_set_type(dev, type); |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | |
| 263 | static int ieee80211_ioctl_giwmode(struct net_device *dev, |
| 264 | struct iw_request_info *info, |
| 265 | __u32 *mode, char *extra) |
| 266 | { |
| 267 | struct ieee80211_sub_if_data *sdata; |
| 268 | |
| 269 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 270 | switch (sdata->type) { |
| 271 | case IEEE80211_IF_TYPE_AP: |
| 272 | *mode = IW_MODE_MASTER; |
| 273 | break; |
| 274 | case IEEE80211_IF_TYPE_STA: |
| 275 | *mode = IW_MODE_INFRA; |
| 276 | break; |
| 277 | case IEEE80211_IF_TYPE_IBSS: |
| 278 | *mode = IW_MODE_ADHOC; |
| 279 | break; |
| 280 | case IEEE80211_IF_TYPE_MNTR: |
| 281 | *mode = IW_MODE_MONITOR; |
| 282 | break; |
| 283 | case IEEE80211_IF_TYPE_WDS: |
| 284 | *mode = IW_MODE_REPEAT; |
| 285 | break; |
| 286 | case IEEE80211_IF_TYPE_VLAN: |
| 287 | *mode = IW_MODE_SECOND; /* FIXME */ |
| 288 | break; |
| 289 | default: |
| 290 | *mode = IW_MODE_AUTO; |
| 291 | break; |
| 292 | } |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq) |
| 297 | { |
| 298 | struct ieee80211_hw_mode *mode; |
| 299 | int c, set = 0; |
| 300 | int ret = -EINVAL; |
| 301 | |
| 302 | list_for_each_entry(mode, &local->modes_list, list) { |
| 303 | if (!(local->enabled_modes & (1 << mode->mode))) |
| 304 | continue; |
| 305 | for (c = 0; c < mode->num_channels; c++) { |
| 306 | struct ieee80211_channel *chan = &mode->channels[c]; |
| 307 | if (chan->flag & IEEE80211_CHAN_W_SCAN && |
| 308 | ((chan->chan == channel) || (chan->freq == freq))) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 309 | local->oper_channel = chan; |
| 310 | local->oper_hw_mode = mode; |
Johannes Berg | 58a9ac1 | 2007-10-12 21:24:07 +0200 | [diff] [blame] | 311 | set = 1; |
| 312 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 313 | } |
| 314 | } |
Johannes Berg | 58a9ac1 | 2007-10-12 21:24:07 +0200 | [diff] [blame] | 315 | if (set) |
| 316 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | if (set) { |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 320 | if (local->sta_sw_scanning) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 321 | ret = 0; |
| 322 | else |
| 323 | ret = ieee80211_hw_config(local); |
| 324 | |
| 325 | rate_control_clear(local); |
| 326 | } |
| 327 | |
| 328 | return ret; |
| 329 | } |
| 330 | |
| 331 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
| 332 | struct iw_request_info *info, |
| 333 | struct iw_freq *freq, char *extra) |
| 334 | { |
| 335 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 336 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 337 | |
| 338 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 339 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 340 | |
| 341 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ |
| 342 | if (freq->e == 0) { |
| 343 | if (freq->m < 0) { |
| 344 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 345 | sdata->u.sta.flags |= |
| 346 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 347 | return 0; |
| 348 | } else |
| 349 | return ieee80211_set_channel(local, freq->m, -1); |
| 350 | } else { |
| 351 | int i, div = 1000000; |
| 352 | for (i = 0; i < freq->e; i++) |
| 353 | div /= 10; |
| 354 | if (div > 0) |
| 355 | return ieee80211_set_channel(local, -1, freq->m / div); |
| 356 | else |
| 357 | return -EINVAL; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | |
| 362 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, |
| 363 | struct iw_request_info *info, |
| 364 | struct iw_freq *freq, char *extra) |
| 365 | { |
| 366 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 367 | |
| 368 | /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level |
| 369 | * driver for the current channel with firmware-based management */ |
| 370 | |
| 371 | freq->m = local->hw.conf.freq; |
| 372 | freq->e = 6; |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | static int ieee80211_ioctl_siwessid(struct net_device *dev, |
| 379 | struct iw_request_info *info, |
| 380 | struct iw_point *data, char *ssid) |
| 381 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 382 | struct ieee80211_sub_if_data *sdata; |
| 383 | size_t len = data->length; |
| 384 | |
| 385 | /* iwconfig uses nul termination in SSID.. */ |
| 386 | if (len > 0 && ssid[len - 1] == '\0') |
| 387 | len--; |
| 388 | |
| 389 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 390 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 391 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 392 | int ret; |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 393 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 394 | if (len > IEEE80211_MAX_SSID_LEN) |
| 395 | return -EINVAL; |
| 396 | memcpy(sdata->u.sta.ssid, ssid, len); |
| 397 | sdata->u.sta.ssid_len = len; |
| 398 | return 0; |
| 399 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 400 | if (data->flags) |
| 401 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; |
| 402 | else |
| 403 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 404 | ret = ieee80211_sta_set_ssid(dev, ssid, len); |
| 405 | if (ret) |
| 406 | return ret; |
| 407 | ieee80211_sta_req_auth(dev, &sdata->u.sta); |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
| 412 | memcpy(sdata->u.ap.ssid, ssid, len); |
| 413 | memset(sdata->u.ap.ssid + len, 0, |
| 414 | IEEE80211_MAX_SSID_LEN - len); |
| 415 | sdata->u.ap.ssid_len = len; |
| 416 | return ieee80211_if_config(dev); |
| 417 | } |
| 418 | return -EOPNOTSUPP; |
| 419 | } |
| 420 | |
| 421 | |
| 422 | static int ieee80211_ioctl_giwessid(struct net_device *dev, |
| 423 | struct iw_request_info *info, |
| 424 | struct iw_point *data, char *ssid) |
| 425 | { |
| 426 | size_t len; |
| 427 | |
| 428 | struct ieee80211_sub_if_data *sdata; |
| 429 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 430 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 431 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 432 | int res = ieee80211_sta_get_ssid(dev, ssid, &len); |
| 433 | if (res == 0) { |
| 434 | data->length = len; |
| 435 | data->flags = 1; |
| 436 | } else |
| 437 | data->flags = 0; |
| 438 | return res; |
| 439 | } |
| 440 | |
| 441 | if (sdata->type == IEEE80211_IF_TYPE_AP) { |
| 442 | len = sdata->u.ap.ssid_len; |
| 443 | if (len > IW_ESSID_MAX_SIZE) |
| 444 | len = IW_ESSID_MAX_SIZE; |
| 445 | memcpy(ssid, sdata->u.ap.ssid, len); |
| 446 | data->length = len; |
| 447 | data->flags = 1; |
| 448 | return 0; |
| 449 | } |
| 450 | return -EOPNOTSUPP; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | static int ieee80211_ioctl_siwap(struct net_device *dev, |
| 455 | struct iw_request_info *info, |
| 456 | struct sockaddr *ap_addr, char *extra) |
| 457 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 458 | struct ieee80211_sub_if_data *sdata; |
| 459 | |
| 460 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 461 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 462 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 463 | int ret; |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 464 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 465 | memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data, |
| 466 | ETH_ALEN); |
| 467 | return 0; |
| 468 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 469 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
| 470 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL | |
| 471 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
| 472 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) |
| 473 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 474 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 475 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 476 | ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data); |
| 477 | if (ret) |
| 478 | return ret; |
| 479 | ieee80211_sta_req_auth(dev, &sdata->u.sta); |
| 480 | return 0; |
| 481 | } else if (sdata->type == IEEE80211_IF_TYPE_WDS) { |
| 482 | if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, |
| 483 | ETH_ALEN) == 0) |
| 484 | return 0; |
| 485 | return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data); |
| 486 | } |
| 487 | |
| 488 | return -EOPNOTSUPP; |
| 489 | } |
| 490 | |
| 491 | |
| 492 | static int ieee80211_ioctl_giwap(struct net_device *dev, |
| 493 | struct iw_request_info *info, |
| 494 | struct sockaddr *ap_addr, char *extra) |
| 495 | { |
| 496 | struct ieee80211_sub_if_data *sdata; |
| 497 | |
| 498 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 499 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 500 | sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 501 | ap_addr->sa_family = ARPHRD_ETHER; |
| 502 | memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN); |
| 503 | return 0; |
| 504 | } else if (sdata->type == IEEE80211_IF_TYPE_WDS) { |
| 505 | ap_addr->sa_family = ARPHRD_ETHER; |
| 506 | memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | return -EOPNOTSUPP; |
| 511 | } |
| 512 | |
| 513 | |
| 514 | static int ieee80211_ioctl_siwscan(struct net_device *dev, |
| 515 | struct iw_request_info *info, |
Bill Moss | 107acb2 | 2007-10-10 16:23:55 -0400 | [diff] [blame] | 516 | union iwreq_data *wrqu, char *extra) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 517 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 518 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Bill Moss | 107acb2 | 2007-10-10 16:23:55 -0400 | [diff] [blame] | 519 | struct iw_scan_req *req = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 520 | u8 *ssid = NULL; |
| 521 | size_t ssid_len = 0; |
| 522 | |
| 523 | if (!netif_running(dev)) |
| 524 | return -ENETDOWN; |
| 525 | |
Helmut Schaa | 48933dea | 2007-11-09 16:26:09 +0100 | [diff] [blame] | 526 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 527 | sdata->type != IEEE80211_IF_TYPE_IBSS && |
| 528 | sdata->type != IEEE80211_IF_TYPE_AP) { |
John W. Linville | d114f39 | 2007-10-17 21:16:16 -0700 | [diff] [blame] | 529 | return -EOPNOTSUPP; |
| 530 | } |
| 531 | |
| 532 | /* if SSID was specified explicitly then use that */ |
Bill Moss | 107acb2 | 2007-10-10 16:23:55 -0400 | [diff] [blame] | 533 | if (wrqu->data.length == sizeof(struct iw_scan_req) && |
| 534 | wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
| 535 | req = (struct iw_scan_req *)extra; |
| 536 | ssid = req->essid; |
| 537 | ssid_len = req->essid_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 538 | } |
Daniel Drake | f27b62d | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 539 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 540 | return ieee80211_sta_req_scan(dev, ssid, ssid_len); |
| 541 | } |
| 542 | |
| 543 | |
| 544 | static int ieee80211_ioctl_giwscan(struct net_device *dev, |
| 545 | struct iw_request_info *info, |
| 546 | struct iw_point *data, char *extra) |
| 547 | { |
| 548 | int res; |
| 549 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 550 | |
| 551 | if (local->sta_sw_scanning || local->sta_hw_scanning) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 552 | return -EAGAIN; |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 553 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 554 | res = ieee80211_sta_scan_results(dev, extra, data->length); |
| 555 | if (res >= 0) { |
| 556 | data->length = res; |
| 557 | return 0; |
| 558 | } |
| 559 | data->length = 0; |
| 560 | return res; |
| 561 | } |
| 562 | |
| 563 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 564 | static int ieee80211_ioctl_siwrate(struct net_device *dev, |
| 565 | struct iw_request_info *info, |
| 566 | struct iw_param *rate, char *extra) |
| 567 | { |
| 568 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 569 | struct ieee80211_hw_mode *mode; |
| 570 | int i; |
| 571 | u32 target_rate = rate->value / 100000; |
| 572 | struct ieee80211_sub_if_data *sdata; |
| 573 | |
| 574 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 575 | if (!sdata->bss) |
| 576 | return -ENODEV; |
| 577 | mode = local->oper_hw_mode; |
| 578 | /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates |
| 579 | * target_rate = X, rate->fixed = 1 means only rate X |
| 580 | * target_rate = X, rate->fixed = 0 means all rates <= X */ |
| 581 | sdata->bss->max_ratectrl_rateidx = -1; |
| 582 | sdata->bss->force_unicast_rateidx = -1; |
| 583 | if (rate->value < 0) |
| 584 | return 0; |
Andrew Lutomirski | 5cdfed5 | 2008-01-03 21:03:19 -0800 | [diff] [blame] | 585 | for (i=0; i < mode->num_rates; i++) { |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 586 | struct ieee80211_rate *rates = &mode->rates[i]; |
| 587 | int this_rate = rates->rate; |
| 588 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 589 | if (target_rate == this_rate) { |
| 590 | sdata->bss->max_ratectrl_rateidx = i; |
| 591 | if (rate->fixed) |
| 592 | sdata->bss->force_unicast_rateidx = i; |
Andrew Lutomirski | 5cdfed5 | 2008-01-03 21:03:19 -0800 | [diff] [blame] | 593 | return 0; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 594 | } |
| 595 | } |
Andrew Lutomirski | 5cdfed5 | 2008-01-03 21:03:19 -0800 | [diff] [blame] | 596 | return -EINVAL; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 597 | } |
| 598 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 599 | static int ieee80211_ioctl_giwrate(struct net_device *dev, |
| 600 | struct iw_request_info *info, |
| 601 | struct iw_param *rate, char *extra) |
| 602 | { |
| 603 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 604 | struct sta_info *sta; |
| 605 | struct ieee80211_sub_if_data *sdata; |
| 606 | |
| 607 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 608 | if (sdata->type == IEEE80211_IF_TYPE_STA) |
| 609 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 610 | else |
| 611 | return -EOPNOTSUPP; |
| 612 | if (!sta) |
| 613 | return -ENODEV; |
| 614 | if (sta->txrate < local->oper_hw_mode->num_rates) |
| 615 | rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000; |
| 616 | else |
| 617 | rate->value = 0; |
| 618 | sta_info_put(sta); |
| 619 | return 0; |
| 620 | } |
| 621 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 622 | static int ieee80211_ioctl_siwtxpower(struct net_device *dev, |
| 623 | struct iw_request_info *info, |
| 624 | union iwreq_data *data, char *extra) |
| 625 | { |
| 626 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 627 | bool need_reconfig = 0; |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 628 | u8 new_power_level; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 629 | |
| 630 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 631 | return -EINVAL; |
| 632 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 633 | return -EINVAL; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 634 | |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 635 | if (data->txpower.fixed) { |
| 636 | new_power_level = data->txpower.value; |
| 637 | } else { |
| 638 | /* Automatic power level. Get the px power from the current |
| 639 | * channel. */ |
| 640 | struct ieee80211_channel* chan = local->oper_channel; |
| 641 | if (!chan) |
| 642 | return -EINVAL; |
| 643 | |
| 644 | new_power_level = chan->power_level; |
| 645 | } |
| 646 | |
| 647 | if (local->hw.conf.power_level != new_power_level) { |
| 648 | local->hw.conf.power_level = new_power_level; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 649 | need_reconfig = 1; |
| 650 | } |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 651 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 652 | if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { |
| 653 | local->hw.conf.radio_enabled = !(data->txpower.disabled); |
| 654 | need_reconfig = 1; |
| 655 | } |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 656 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 657 | if (need_reconfig) { |
| 658 | ieee80211_hw_config(local); |
| 659 | /* The return value of hw_config is not of big interest here, |
| 660 | * as it doesn't say that it failed because of _this_ config |
| 661 | * change or something else. Ignore it. */ |
| 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 667 | static int ieee80211_ioctl_giwtxpower(struct net_device *dev, |
| 668 | struct iw_request_info *info, |
| 669 | union iwreq_data *data, char *extra) |
| 670 | { |
| 671 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 672 | |
| 673 | data->txpower.fixed = 1; |
| 674 | data->txpower.disabled = !(local->hw.conf.radio_enabled); |
| 675 | data->txpower.value = local->hw.conf.power_level; |
| 676 | data->txpower.flags = IW_TXPOW_DBM; |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 681 | static int ieee80211_ioctl_siwrts(struct net_device *dev, |
| 682 | struct iw_request_info *info, |
| 683 | struct iw_param *rts, char *extra) |
| 684 | { |
| 685 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 686 | |
| 687 | if (rts->disabled) |
| 688 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
| 689 | else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD) |
| 690 | return -EINVAL; |
| 691 | else |
| 692 | local->rts_threshold = rts->value; |
| 693 | |
| 694 | /* If the wlan card performs RTS/CTS in hardware/firmware, |
| 695 | * configure it here */ |
| 696 | |
| 697 | if (local->ops->set_rts_threshold) |
| 698 | local->ops->set_rts_threshold(local_to_hw(local), |
| 699 | local->rts_threshold); |
| 700 | |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | static int ieee80211_ioctl_giwrts(struct net_device *dev, |
| 705 | struct iw_request_info *info, |
| 706 | struct iw_param *rts, char *extra) |
| 707 | { |
| 708 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 709 | |
| 710 | rts->value = local->rts_threshold; |
| 711 | rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 712 | rts->fixed = 1; |
| 713 | |
| 714 | return 0; |
| 715 | } |
| 716 | |
| 717 | |
| 718 | static int ieee80211_ioctl_siwfrag(struct net_device *dev, |
| 719 | struct iw_request_info *info, |
| 720 | struct iw_param *frag, char *extra) |
| 721 | { |
| 722 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 723 | |
| 724 | if (frag->disabled) |
| 725 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; |
| 726 | else if (frag->value < 256 || |
| 727 | frag->value > IEEE80211_MAX_FRAG_THRESHOLD) |
| 728 | return -EINVAL; |
| 729 | else { |
| 730 | /* Fragment length must be even, so strip LSB. */ |
| 731 | local->fragmentation_threshold = frag->value & ~0x1; |
| 732 | } |
| 733 | |
| 734 | /* If the wlan card performs fragmentation in hardware/firmware, |
| 735 | * configure it here */ |
| 736 | |
| 737 | if (local->ops->set_frag_threshold) |
| 738 | local->ops->set_frag_threshold( |
| 739 | local_to_hw(local), |
| 740 | local->fragmentation_threshold); |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | static int ieee80211_ioctl_giwfrag(struct net_device *dev, |
| 746 | struct iw_request_info *info, |
| 747 | struct iw_param *frag, char *extra) |
| 748 | { |
| 749 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 750 | |
| 751 | frag->value = local->fragmentation_threshold; |
| 752 | frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 753 | frag->fixed = 1; |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | |
| 759 | static int ieee80211_ioctl_siwretry(struct net_device *dev, |
| 760 | struct iw_request_info *info, |
| 761 | struct iw_param *retry, char *extra) |
| 762 | { |
| 763 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 764 | |
| 765 | if (retry->disabled || |
| 766 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) |
| 767 | return -EINVAL; |
| 768 | |
| 769 | if (retry->flags & IW_RETRY_MAX) |
| 770 | local->long_retry_limit = retry->value; |
| 771 | else if (retry->flags & IW_RETRY_MIN) |
| 772 | local->short_retry_limit = retry->value; |
| 773 | else { |
| 774 | local->long_retry_limit = retry->value; |
| 775 | local->short_retry_limit = retry->value; |
| 776 | } |
| 777 | |
| 778 | if (local->ops->set_retry_limit) { |
| 779 | return local->ops->set_retry_limit( |
| 780 | local_to_hw(local), |
| 781 | local->short_retry_limit, |
| 782 | local->long_retry_limit); |
| 783 | } |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | |
| 789 | static int ieee80211_ioctl_giwretry(struct net_device *dev, |
| 790 | struct iw_request_info *info, |
| 791 | struct iw_param *retry, char *extra) |
| 792 | { |
| 793 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 794 | |
| 795 | retry->disabled = 0; |
| 796 | if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) { |
| 797 | /* first return min value, iwconfig will ask max value |
| 798 | * later if needed */ |
| 799 | retry->flags |= IW_RETRY_LIMIT; |
| 800 | retry->value = local->short_retry_limit; |
| 801 | if (local->long_retry_limit != local->short_retry_limit) |
| 802 | retry->flags |= IW_RETRY_MIN; |
| 803 | return 0; |
| 804 | } |
| 805 | if (retry->flags & IW_RETRY_MAX) { |
| 806 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 807 | retry->value = local->long_retry_limit; |
| 808 | } |
| 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 813 | static int ieee80211_ioctl_siwmlme(struct net_device *dev, |
| 814 | struct iw_request_info *info, |
| 815 | struct iw_point *data, char *extra) |
| 816 | { |
| 817 | struct ieee80211_sub_if_data *sdata; |
| 818 | struct iw_mlme *mlme = (struct iw_mlme *) extra; |
| 819 | |
| 820 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 821 | if (sdata->type != IEEE80211_IF_TYPE_STA && |
| 822 | sdata->type != IEEE80211_IF_TYPE_IBSS) |
| 823 | return -EINVAL; |
| 824 | |
| 825 | switch (mlme->cmd) { |
| 826 | case IW_MLME_DEAUTH: |
| 827 | /* TODO: mlme->addr.sa_data */ |
| 828 | return ieee80211_sta_deauthenticate(dev, mlme->reason_code); |
| 829 | case IW_MLME_DISASSOC: |
| 830 | /* TODO: mlme->addr.sa_data */ |
| 831 | return ieee80211_sta_disassociate(dev, mlme->reason_code); |
| 832 | default: |
| 833 | return -EOPNOTSUPP; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | |
| 838 | static int ieee80211_ioctl_siwencode(struct net_device *dev, |
| 839 | struct iw_request_info *info, |
| 840 | struct iw_point *erq, char *keybuf) |
| 841 | { |
| 842 | struct ieee80211_sub_if_data *sdata; |
| 843 | int idx, i, alg = ALG_WEP; |
| 844 | u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 845 | int remove = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 846 | |
| 847 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 848 | |
| 849 | idx = erq->flags & IW_ENCODE_INDEX; |
| 850 | if (idx == 0) { |
| 851 | if (sdata->default_key) |
| 852 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 853 | if (sdata->default_key == sdata->keys[i]) { |
| 854 | idx = i; |
| 855 | break; |
| 856 | } |
| 857 | } |
| 858 | } else if (idx < 1 || idx > 4) |
| 859 | return -EINVAL; |
| 860 | else |
| 861 | idx--; |
| 862 | |
| 863 | if (erq->flags & IW_ENCODE_DISABLED) |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 864 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 865 | else if (erq->length == 0) { |
| 866 | /* No key data - just set the default TX key index */ |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 867 | ieee80211_set_default_key(sdata, idx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | return ieee80211_set_encryption( |
| 872 | dev, bcaddr, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 873 | idx, alg, remove, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 874 | !sdata->default_key, |
| 875 | keybuf, erq->length); |
| 876 | } |
| 877 | |
| 878 | |
| 879 | static int ieee80211_ioctl_giwencode(struct net_device *dev, |
| 880 | struct iw_request_info *info, |
| 881 | struct iw_point *erq, char *key) |
| 882 | { |
| 883 | struct ieee80211_sub_if_data *sdata; |
| 884 | int idx, i; |
| 885 | |
| 886 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 887 | |
| 888 | idx = erq->flags & IW_ENCODE_INDEX; |
| 889 | if (idx < 1 || idx > 4) { |
| 890 | idx = -1; |
| 891 | if (!sdata->default_key) |
| 892 | idx = 0; |
| 893 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 894 | if (sdata->default_key == sdata->keys[i]) { |
| 895 | idx = i; |
| 896 | break; |
| 897 | } |
| 898 | } |
| 899 | if (idx < 0) |
| 900 | return -EINVAL; |
| 901 | } else |
| 902 | idx--; |
| 903 | |
| 904 | erq->flags = idx + 1; |
| 905 | |
| 906 | if (!sdata->keys[idx]) { |
| 907 | erq->length = 0; |
| 908 | erq->flags |= IW_ENCODE_DISABLED; |
| 909 | return 0; |
| 910 | } |
| 911 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 912 | memcpy(key, sdata->keys[idx]->conf.key, |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 913 | min_t(int, erq->length, sdata->keys[idx]->conf.keylen)); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 914 | erq->length = sdata->keys[idx]->conf.keylen; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 915 | erq->flags |= IW_ENCODE_ENABLED; |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static int ieee80211_ioctl_siwauth(struct net_device *dev, |
| 921 | struct iw_request_info *info, |
| 922 | struct iw_param *data, char *extra) |
| 923 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 924 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 925 | int ret = 0; |
| 926 | |
| 927 | switch (data->flags & IW_AUTH_INDEX) { |
| 928 | case IW_AUTH_WPA_VERSION: |
| 929 | case IW_AUTH_CIPHER_PAIRWISE: |
| 930 | case IW_AUTH_CIPHER_GROUP: |
| 931 | case IW_AUTH_WPA_ENABLED: |
| 932 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 933 | case IW_AUTH_KEY_MGMT: |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 934 | break; |
Johannes Berg | b1357a8 | 2007-11-28 11:04:21 +0100 | [diff] [blame] | 935 | case IW_AUTH_DROP_UNENCRYPTED: |
| 936 | sdata->drop_unencrypted = !!data->value; |
| 937 | break; |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 938 | case IW_AUTH_PRIVACY_INVOKED: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 939 | if (sdata->type != IEEE80211_IF_TYPE_STA) |
| 940 | ret = -EINVAL; |
| 941 | else { |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 942 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 943 | /* |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 944 | * Privacy invoked by wpa_supplicant, store the |
| 945 | * value and allow associating to a protected |
| 946 | * network without having a key up front. |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 947 | */ |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 948 | if (data->value) |
| 949 | sdata->u.sta.flags |= |
| 950 | IEEE80211_STA_PRIVACY_INVOKED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 951 | } |
| 952 | break; |
| 953 | case IW_AUTH_80211_AUTH_ALG: |
| 954 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 955 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 956 | sdata->u.sta.auth_algs = data->value; |
| 957 | else |
| 958 | ret = -EOPNOTSUPP; |
| 959 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 960 | default: |
| 961 | ret = -EOPNOTSUPP; |
| 962 | break; |
| 963 | } |
| 964 | return ret; |
| 965 | } |
| 966 | |
| 967 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
| 968 | static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev) |
| 969 | { |
| 970 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 971 | struct iw_statistics *wstats = &local->wstats; |
| 972 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 973 | struct sta_info *sta = NULL; |
| 974 | |
| 975 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 976 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 977 | sta = sta_info_get(local, sdata->u.sta.bssid); |
| 978 | if (!sta) { |
| 979 | wstats->discard.fragment = 0; |
| 980 | wstats->discard.misc = 0; |
| 981 | wstats->qual.qual = 0; |
| 982 | wstats->qual.level = 0; |
| 983 | wstats->qual.noise = 0; |
| 984 | wstats->qual.updated = IW_QUAL_ALL_INVALID; |
| 985 | } else { |
| 986 | wstats->qual.level = sta->last_rssi; |
| 987 | wstats->qual.qual = sta->last_signal; |
| 988 | wstats->qual.noise = sta->last_noise; |
| 989 | wstats->qual.updated = local->wstats_flags; |
| 990 | sta_info_put(sta); |
| 991 | } |
| 992 | return wstats; |
| 993 | } |
| 994 | |
| 995 | static int ieee80211_ioctl_giwauth(struct net_device *dev, |
| 996 | struct iw_request_info *info, |
| 997 | struct iw_param *data, char *extra) |
| 998 | { |
| 999 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1000 | int ret = 0; |
| 1001 | |
| 1002 | switch (data->flags & IW_AUTH_INDEX) { |
| 1003 | case IW_AUTH_80211_AUTH_ALG: |
| 1004 | if (sdata->type == IEEE80211_IF_TYPE_STA || |
| 1005 | sdata->type == IEEE80211_IF_TYPE_IBSS) |
| 1006 | data->value = sdata->u.sta.auth_algs; |
| 1007 | else |
| 1008 | ret = -EOPNOTSUPP; |
| 1009 | break; |
| 1010 | default: |
| 1011 | ret = -EOPNOTSUPP; |
| 1012 | break; |
| 1013 | } |
| 1014 | return ret; |
| 1015 | } |
| 1016 | |
| 1017 | |
| 1018 | static int ieee80211_ioctl_siwencodeext(struct net_device *dev, |
| 1019 | struct iw_request_info *info, |
| 1020 | struct iw_point *erq, char *extra) |
| 1021 | { |
| 1022 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1023 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1024 | int uninitialized_var(alg), idx, i, remove = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1025 | |
| 1026 | switch (ext->alg) { |
| 1027 | case IW_ENCODE_ALG_NONE: |
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 | break; |
| 1030 | case IW_ENCODE_ALG_WEP: |
| 1031 | alg = ALG_WEP; |
| 1032 | break; |
| 1033 | case IW_ENCODE_ALG_TKIP: |
| 1034 | alg = ALG_TKIP; |
| 1035 | break; |
| 1036 | case IW_ENCODE_ALG_CCMP: |
| 1037 | alg = ALG_CCMP; |
| 1038 | break; |
| 1039 | default: |
| 1040 | return -EOPNOTSUPP; |
| 1041 | } |
| 1042 | |
| 1043 | if (erq->flags & IW_ENCODE_DISABLED) |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1044 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1045 | |
| 1046 | idx = erq->flags & IW_ENCODE_INDEX; |
| 1047 | if (idx < 1 || idx > 4) { |
| 1048 | idx = -1; |
| 1049 | if (!sdata->default_key) |
| 1050 | idx = 0; |
| 1051 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1052 | if (sdata->default_key == sdata->keys[i]) { |
| 1053 | idx = i; |
| 1054 | break; |
| 1055 | } |
| 1056 | } |
| 1057 | if (idx < 0) |
| 1058 | return -EINVAL; |
| 1059 | } else |
| 1060 | idx--; |
| 1061 | |
| 1062 | return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1063 | remove, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1064 | ext->ext_flags & |
| 1065 | IW_ENCODE_EXT_SET_TX_KEY, |
| 1066 | ext->key, ext->key_len); |
| 1067 | } |
| 1068 | |
| 1069 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1070 | /* Structures to export the Wireless Handlers */ |
| 1071 | |
| 1072 | static const iw_handler ieee80211_handler[] = |
| 1073 | { |
| 1074 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
| 1075 | (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */ |
| 1076 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 1077 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 1078 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ |
| 1079 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ |
| 1080 | (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */ |
| 1081 | (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */ |
| 1082 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 1083 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 1084 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ |
| 1085 | (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */ |
| 1086 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ |
| 1087 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ |
| 1088 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ |
| 1089 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ |
Johannes Berg | 5d4ecd9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 1090 | (iw_handler) NULL, /* SIOCSIWSPY */ |
| 1091 | (iw_handler) NULL, /* SIOCGIWSPY */ |
| 1092 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ |
| 1093 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1094 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
| 1095 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ |
| 1096 | (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ |
| 1097 | (iw_handler) NULL, /* SIOCGIWAPLIST */ |
| 1098 | (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */ |
| 1099 | (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */ |
| 1100 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ |
| 1101 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ |
| 1102 | (iw_handler) NULL, /* SIOCSIWNICKN */ |
| 1103 | (iw_handler) NULL, /* SIOCGIWNICKN */ |
| 1104 | (iw_handler) NULL, /* -- hole -- */ |
| 1105 | (iw_handler) NULL, /* -- hole -- */ |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1106 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 1107 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1108 | (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ |
| 1109 | (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ |
| 1110 | (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ |
| 1111 | (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 1112 | (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 1113 | (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1114 | (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ |
| 1115 | (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ |
| 1116 | (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ |
| 1117 | (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ |
| 1118 | (iw_handler) NULL, /* SIOCSIWPOWER */ |
| 1119 | (iw_handler) NULL, /* SIOCGIWPOWER */ |
| 1120 | (iw_handler) NULL, /* -- hole -- */ |
| 1121 | (iw_handler) NULL, /* -- hole -- */ |
| 1122 | (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */ |
| 1123 | (iw_handler) NULL, /* SIOCGIWGENIE */ |
| 1124 | (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ |
| 1125 | (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ |
| 1126 | (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ |
| 1127 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ |
| 1128 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 1129 | (iw_handler) NULL, /* -- hole -- */ |
| 1130 | }; |
| 1131 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1132 | const struct iw_handler_def ieee80211_iw_handler_def = |
| 1133 | { |
| 1134 | .num_standard = ARRAY_SIZE(ieee80211_handler), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1135 | .standard = (iw_handler *) ieee80211_handler, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1136 | .get_wireless_stats = ieee80211_get_wireless_stats, |
| 1137 | }; |