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