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