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 | |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 40 | if (alg == ALG_AES_CMAC) { |
| 41 | if (idx < NUM_DEFAULT_KEYS || |
| 42 | idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) { |
| 43 | printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d " |
| 44 | "(BIP)\n", sdata->dev->name, idx); |
| 45 | return -EINVAL; |
| 46 | } |
| 47 | } else if (idx < 0 || idx >= NUM_DEFAULT_KEYS) { |
Volker Braun | 139c3a0 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 48 | printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 49 | sdata->dev->name, idx); |
Volker Braun | 139c3a0 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 50 | return -EINVAL; |
| 51 | } |
| 52 | |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 53 | if (remove) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 54 | rcu_read_lock(); |
| 55 | |
| 56 | err = 0; |
| 57 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 58 | if (is_broadcast_ether_addr(sta_addr)) { |
| 59 | key = sdata->keys[idx]; |
| 60 | } else { |
| 61 | sta = sta_info_get(local, sta_addr); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 62 | if (!sta) { |
| 63 | err = -ENOENT; |
| 64 | goto out_unlock; |
| 65 | } |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 66 | key = sta->key; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 67 | } |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 68 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 69 | ieee80211_key_free(key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 70 | } else { |
| 71 | key = ieee80211_key_alloc(alg, idx, key_len, _key); |
| 72 | if (!key) |
| 73 | return -ENOMEM; |
| 74 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 75 | sta = NULL; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 76 | err = 0; |
| 77 | |
| 78 | rcu_read_lock(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 79 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 80 | if (!is_broadcast_ether_addr(sta_addr)) { |
| 81 | set_tx_key = 0; |
| 82 | /* |
| 83 | * According to the standard, the key index of a |
| 84 | * pairwise key must be zero. However, some AP are |
| 85 | * broken when it comes to WEP key indices, so we |
| 86 | * work around this. |
| 87 | */ |
| 88 | if (idx != 0 && alg != ALG_WEP) { |
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 = -EINVAL; |
| 91 | goto out_unlock; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | sta = sta_info_get(local, sta_addr); |
| 95 | if (!sta) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 96 | ieee80211_key_free(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 97 | err = -ENOENT; |
| 98 | goto out_unlock; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Emmanuel Grumbach | 23976ef | 2008-06-28 02:50:13 +0300 | [diff] [blame] | 102 | if (alg == ALG_WEP && |
| 103 | key_len != LEN_WEP40 && key_len != LEN_WEP104) { |
| 104 | ieee80211_key_free(key); |
| 105 | err = -EINVAL; |
| 106 | goto out_unlock; |
| 107 | } |
| 108 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 109 | ieee80211_key_link(key, sdata, sta); |
| 110 | |
| 111 | if (set_tx_key || (!sta && !sdata->default_key && key)) |
| 112 | ieee80211_set_default_key(sdata, idx); |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 113 | if (alg == ALG_AES_CMAC && |
| 114 | (set_tx_key || (!sta && !sdata->default_mgmt_key && key))) |
| 115 | ieee80211_set_default_mgmt_key(sdata, idx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 118 | out_unlock: |
| 119 | rcu_read_unlock(); |
| 120 | |
| 121 | return err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static int ieee80211_ioctl_siwgenie(struct net_device *dev, |
| 125 | struct iw_request_info *info, |
| 126 | struct iw_point *data, char *extra) |
| 127 | { |
| 128 | struct ieee80211_sub_if_data *sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 129 | |
| 130 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 131 | |
| 132 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) |
| 133 | return -EOPNOTSUPP; |
| 134 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 135 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 136 | int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 137 | if (ret) |
| 138 | return ret; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 139 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
| 140 | ieee80211_sta_req_auth(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 144 | return -EOPNOTSUPP; |
| 145 | } |
| 146 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 147 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
| 148 | struct iw_request_info *info, |
| 149 | struct iw_freq *freq, char *extra) |
| 150 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 151 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 152 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 153 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 154 | sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL; |
| 155 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 156 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 157 | |
| 158 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ |
| 159 | if (freq->e == 0) { |
| 160 | if (freq->m < 0) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 161 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 162 | sdata->u.ibss.flags |= |
| 163 | IEEE80211_IBSS_AUTO_CHANNEL_SEL; |
| 164 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 165 | sdata->u.mgd.flags |= |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 166 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 167 | return 0; |
| 168 | } else |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 169 | return ieee80211_set_freq(sdata, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 170 | ieee80211_channel_to_frequency(freq->m)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 171 | } else { |
| 172 | int i, div = 1000000; |
| 173 | for (i = 0; i < freq->e; i++) |
| 174 | div /= 10; |
| 175 | if (div > 0) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 176 | return ieee80211_set_freq(sdata, freq->m / div); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 177 | else |
| 178 | return -EINVAL; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | |
| 183 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, |
| 184 | struct iw_request_info *info, |
| 185 | struct iw_freq *freq, char *extra) |
| 186 | { |
| 187 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 188 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 189 | freq->m = local->hw.conf.channel->center_freq; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 190 | freq->e = 6; |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | static int ieee80211_ioctl_siwessid(struct net_device *dev, |
| 197 | struct iw_request_info *info, |
| 198 | struct iw_point *data, char *ssid) |
| 199 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 200 | struct ieee80211_sub_if_data *sdata; |
| 201 | size_t len = data->length; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 202 | int ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 203 | |
| 204 | /* iwconfig uses nul termination in SSID.. */ |
| 205 | if (len > 0 && ssid[len - 1] == '\0') |
| 206 | len--; |
| 207 | |
| 208 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 209 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 210 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 211 | if (len > IEEE80211_MAX_SSID_LEN) |
| 212 | return -EINVAL; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 213 | memcpy(sdata->u.mgd.ssid, ssid, len); |
| 214 | sdata->u.mgd.ssid_len = len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 215 | return 0; |
| 216 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 217 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 218 | if (data->flags) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 219 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 220 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 221 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL; |
| 222 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 223 | ret = ieee80211_sta_set_ssid(sdata, ssid, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 224 | if (ret) |
| 225 | return ret; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 226 | |
| 227 | ieee80211_sta_req_auth(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 228 | return 0; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 229 | } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 230 | return ieee80211_ibss_set_ssid(sdata, ssid, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 231 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 232 | return -EOPNOTSUPP; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | static int ieee80211_ioctl_giwessid(struct net_device *dev, |
| 237 | struct iw_request_info *info, |
| 238 | struct iw_point *data, char *ssid) |
| 239 | { |
| 240 | size_t len; |
| 241 | |
| 242 | struct ieee80211_sub_if_data *sdata; |
| 243 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 244 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 245 | int res = ieee80211_sta_get_ssid(sdata, ssid, &len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 246 | if (res == 0) { |
| 247 | data->length = len; |
| 248 | data->flags = 1; |
| 249 | } else |
| 250 | data->flags = 0; |
| 251 | return res; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 252 | } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
| 253 | int res = ieee80211_ibss_get_ssid(sdata, ssid, &len); |
| 254 | if (res == 0) { |
| 255 | data->length = len; |
| 256 | data->flags = 1; |
| 257 | } else |
| 258 | data->flags = 0; |
| 259 | return res; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 262 | return -EOPNOTSUPP; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | static int ieee80211_ioctl_siwap(struct net_device *dev, |
| 267 | struct iw_request_info *info, |
| 268 | struct sockaddr *ap_addr, char *extra) |
| 269 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 270 | struct ieee80211_sub_if_data *sdata; |
| 271 | |
| 272 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 273 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 274 | int ret; |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 275 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 276 | memcpy(sdata->u.mgd.bssid, (u8 *) &ap_addr->sa_data, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 277 | ETH_ALEN); |
| 278 | return 0; |
| 279 | } |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 280 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 281 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 282 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
| 283 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 284 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 285 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 286 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 287 | ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 288 | if (ret) |
| 289 | return ret; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 290 | ieee80211_sta_req_auth(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 291 | return 0; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 292 | } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
| 293 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
| 294 | sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL | |
| 295 | IEEE80211_IBSS_AUTO_CHANNEL_SEL; |
| 296 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) |
| 297 | sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL; |
| 298 | else |
| 299 | sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL; |
| 300 | |
| 301 | return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 302 | } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 303 | /* |
| 304 | * If it is necessary to update the WDS peer address |
| 305 | * while the interface is running, then we need to do |
| 306 | * more work here, namely if it is running we need to |
| 307 | * add a new and remove the old STA entry, this is |
| 308 | * normally handled by _open() and _stop(). |
| 309 | */ |
| 310 | if (netif_running(dev)) |
| 311 | return -EBUSY; |
| 312 | |
| 313 | memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, |
| 314 | ETH_ALEN); |
| 315 | |
| 316 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | return -EOPNOTSUPP; |
| 320 | } |
| 321 | |
| 322 | |
| 323 | static int ieee80211_ioctl_giwap(struct net_device *dev, |
| 324 | struct iw_request_info *info, |
| 325 | struct sockaddr *ap_addr, char *extra) |
| 326 | { |
| 327 | struct ieee80211_sub_if_data *sdata; |
| 328 | |
| 329 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 330 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
| 331 | if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) { |
Abhijeet Kolekar | d4231ca | 2008-05-23 10:15:26 -0700 | [diff] [blame] | 332 | ap_addr->sa_family = ARPHRD_ETHER; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 333 | memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN); |
| 334 | } else |
Abhijeet Kolekar | d4231ca | 2008-05-23 10:15:26 -0700 | [diff] [blame] | 335 | memset(&ap_addr->sa_data, 0, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 336 | return 0; |
| 337 | } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
| 338 | if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) { |
| 339 | ap_addr->sa_family = ARPHRD_ETHER; |
| 340 | memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN); |
| 341 | } else |
| 342 | memset(&ap_addr->sa_data, 0, ETH_ALEN); |
| 343 | return 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 344 | } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 345 | ap_addr->sa_family = ARPHRD_ETHER; |
| 346 | memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | return -EOPNOTSUPP; |
| 351 | } |
| 352 | |
| 353 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 354 | static int ieee80211_ioctl_siwrate(struct net_device *dev, |
| 355 | struct iw_request_info *info, |
| 356 | struct iw_param *rate, char *extra) |
| 357 | { |
| 358 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 359 | int i, err = -EINVAL; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 360 | u32 target_rate = rate->value / 100000; |
| 361 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 362 | struct ieee80211_supported_band *sband; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 363 | |
| 364 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 365 | |
| 366 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 367 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 368 | /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates |
| 369 | * target_rate = X, rate->fixed = 1 means only rate X |
| 370 | * target_rate = X, rate->fixed = 0 means all rates <= X */ |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 371 | sdata->max_ratectrl_rateidx = -1; |
| 372 | sdata->force_unicast_rateidx = -1; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 373 | if (rate->value < 0) |
| 374 | return 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 375 | |
| 376 | for (i=0; i< sband->n_bitrates; i++) { |
| 377 | struct ieee80211_rate *brate = &sband->bitrates[i]; |
| 378 | int this_rate = brate->bitrate; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 379 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 380 | if (target_rate == this_rate) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 381 | sdata->max_ratectrl_rateidx = i; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 382 | if (rate->fixed) |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 383 | sdata->force_unicast_rateidx = i; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 384 | err = 0; |
| 385 | break; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 386 | } |
| 387 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 388 | return err; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 391 | static int ieee80211_ioctl_giwrate(struct net_device *dev, |
| 392 | struct iw_request_info *info, |
| 393 | struct iw_param *rate, char *extra) |
| 394 | { |
| 395 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 396 | struct sta_info *sta; |
| 397 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 398 | struct ieee80211_supported_band *sband; |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 399 | |
| 400 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 401 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 402 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 403 | return -EOPNOTSUPP; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 404 | |
| 405 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 406 | |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 407 | rcu_read_lock(); |
| 408 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 409 | sta = sta_info_get(local, sdata->u.mgd.bssid); |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 410 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 411 | if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) |
| 412 | rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate; |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 413 | else |
| 414 | rate->value = 0; |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 415 | |
| 416 | rcu_read_unlock(); |
| 417 | |
| 418 | if (!sta) |
| 419 | return -ENODEV; |
| 420 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 421 | rate->value *= 100000; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 422 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 423 | return 0; |
| 424 | } |
| 425 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 426 | static int ieee80211_ioctl_siwtxpower(struct net_device *dev, |
| 427 | struct iw_request_info *info, |
| 428 | union iwreq_data *data, char *extra) |
| 429 | { |
| 430 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Luis R. Rodriguez | d9d2925 | 2008-10-22 13:13:53 -0700 | [diff] [blame] | 431 | struct ieee80211_channel* chan = local->hw.conf.channel; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 432 | u32 reconf_flags = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 433 | int new_power_level; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 434 | |
| 435 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 436 | return -EINVAL; |
| 437 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 438 | return -EINVAL; |
Luis R. Rodriguez | d9d2925 | 2008-10-22 13:13:53 -0700 | [diff] [blame] | 439 | if (!chan) |
| 440 | return -EINVAL; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 441 | |
Luis R. Rodriguez | d9d2925 | 2008-10-22 13:13:53 -0700 | [diff] [blame] | 442 | if (data->txpower.fixed) |
| 443 | new_power_level = min(data->txpower.value, chan->max_power); |
| 444 | else /* Automatic power level setting */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 445 | new_power_level = chan->max_power; |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 446 | |
Johannes Berg | 2bf30fa | 2009-01-06 23:23:56 +0100 | [diff] [blame] | 447 | local->user_power_level = new_power_level; |
Vasanthakumar Thiagarajan | e3c92df | 2008-12-24 13:53:11 +0530 | [diff] [blame] | 448 | if (local->hw.conf.power_level != new_power_level) |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 449 | reconf_flags |= IEEE80211_CONF_CHANGE_POWER; |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 450 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 451 | if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { |
| 452 | local->hw.conf.radio_enabled = !(data->txpower.disabled); |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 453 | reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED; |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 454 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 455 | } |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 456 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 457 | if (reconf_flags) |
| 458 | ieee80211_hw_config(local, reconf_flags); |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 463 | static int ieee80211_ioctl_giwtxpower(struct net_device *dev, |
| 464 | struct iw_request_info *info, |
| 465 | union iwreq_data *data, char *extra) |
| 466 | { |
| 467 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 468 | |
| 469 | data->txpower.fixed = 1; |
| 470 | data->txpower.disabled = !(local->hw.conf.radio_enabled); |
| 471 | data->txpower.value = local->hw.conf.power_level; |
| 472 | data->txpower.flags = IW_TXPOW_DBM; |
| 473 | |
| 474 | return 0; |
| 475 | } |
| 476 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 477 | static int ieee80211_ioctl_siwrts(struct net_device *dev, |
| 478 | struct iw_request_info *info, |
| 479 | struct iw_param *rts, char *extra) |
| 480 | { |
| 481 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 482 | |
| 483 | if (rts->disabled) |
| 484 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
Emmanuel Grumbach | fa6adfe | 2008-06-24 13:37:58 +0300 | [diff] [blame] | 485 | else if (!rts->fixed) |
| 486 | /* if the rts value is not fixed, then take default */ |
| 487 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 488 | else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD) |
| 489 | return -EINVAL; |
| 490 | else |
| 491 | local->rts_threshold = rts->value; |
| 492 | |
| 493 | /* If the wlan card performs RTS/CTS in hardware/firmware, |
| 494 | * configure it here */ |
| 495 | |
| 496 | if (local->ops->set_rts_threshold) |
| 497 | local->ops->set_rts_threshold(local_to_hw(local), |
| 498 | local->rts_threshold); |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | static int ieee80211_ioctl_giwrts(struct net_device *dev, |
| 504 | struct iw_request_info *info, |
| 505 | struct iw_param *rts, char *extra) |
| 506 | { |
| 507 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 508 | |
| 509 | rts->value = local->rts_threshold; |
| 510 | rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 511 | rts->fixed = 1; |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | static int ieee80211_ioctl_siwfrag(struct net_device *dev, |
| 518 | struct iw_request_info *info, |
| 519 | struct iw_param *frag, char *extra) |
| 520 | { |
| 521 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 522 | |
| 523 | if (frag->disabled) |
| 524 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; |
Emmanuel Grumbach | e4abd4d | 2008-07-03 18:02:27 +0300 | [diff] [blame] | 525 | else if (!frag->fixed) |
| 526 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 527 | else if (frag->value < 256 || |
| 528 | frag->value > IEEE80211_MAX_FRAG_THRESHOLD) |
| 529 | return -EINVAL; |
| 530 | else { |
| 531 | /* Fragment length must be even, so strip LSB. */ |
| 532 | local->fragmentation_threshold = frag->value & ~0x1; |
| 533 | } |
| 534 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | static int ieee80211_ioctl_giwfrag(struct net_device *dev, |
| 539 | struct iw_request_info *info, |
| 540 | struct iw_param *frag, char *extra) |
| 541 | { |
| 542 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 543 | |
| 544 | frag->value = local->fragmentation_threshold; |
| 545 | frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD); |
| 546 | frag->fixed = 1; |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | |
| 552 | static int ieee80211_ioctl_siwretry(struct net_device *dev, |
| 553 | struct iw_request_info *info, |
| 554 | struct iw_param *retry, char *extra) |
| 555 | { |
| 556 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 557 | |
| 558 | if (retry->disabled || |
| 559 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) |
| 560 | return -EINVAL; |
| 561 | |
Johannes Berg | 9124b07 | 2008-10-14 19:17:54 +0200 | [diff] [blame] | 562 | if (retry->flags & IW_RETRY_MAX) { |
| 563 | local->hw.conf.long_frame_max_tx_count = retry->value; |
| 564 | } else if (retry->flags & IW_RETRY_MIN) { |
| 565 | local->hw.conf.short_frame_max_tx_count = retry->value; |
| 566 | } else { |
| 567 | local->hw.conf.long_frame_max_tx_count = retry->value; |
| 568 | local->hw.conf.short_frame_max_tx_count = retry->value; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Johannes Berg | 9124b07 | 2008-10-14 19:17:54 +0200 | [diff] [blame] | 571 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | |
| 577 | static int ieee80211_ioctl_giwretry(struct net_device *dev, |
| 578 | struct iw_request_info *info, |
| 579 | struct iw_param *retry, char *extra) |
| 580 | { |
| 581 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 582 | |
| 583 | retry->disabled = 0; |
| 584 | if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) { |
| 585 | /* first return min value, iwconfig will ask max value |
| 586 | * later if needed */ |
| 587 | retry->flags |= IW_RETRY_LIMIT; |
Johannes Berg | 9124b07 | 2008-10-14 19:17:54 +0200 | [diff] [blame] | 588 | retry->value = local->hw.conf.short_frame_max_tx_count; |
| 589 | if (local->hw.conf.long_frame_max_tx_count != |
| 590 | local->hw.conf.short_frame_max_tx_count) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 591 | retry->flags |= IW_RETRY_MIN; |
| 592 | return 0; |
| 593 | } |
| 594 | if (retry->flags & IW_RETRY_MAX) { |
| 595 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
Johannes Berg | 9124b07 | 2008-10-14 19:17:54 +0200 | [diff] [blame] | 596 | retry->value = local->hw.conf.long_frame_max_tx_count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 602 | static int ieee80211_ioctl_siwmlme(struct net_device *dev, |
| 603 | struct iw_request_info *info, |
| 604 | struct iw_point *data, char *extra) |
| 605 | { |
| 606 | struct ieee80211_sub_if_data *sdata; |
| 607 | struct iw_mlme *mlme = (struct iw_mlme *) extra; |
| 608 | |
| 609 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 610 | if (!(sdata->vif.type == NL80211_IFTYPE_STATION)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 611 | return -EINVAL; |
| 612 | |
| 613 | switch (mlme->cmd) { |
| 614 | case IW_MLME_DEAUTH: |
| 615 | /* TODO: mlme->addr.sa_data */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 616 | return ieee80211_sta_deauthenticate(sdata, mlme->reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 617 | case IW_MLME_DISASSOC: |
| 618 | /* TODO: mlme->addr.sa_data */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 619 | return ieee80211_sta_disassociate(sdata, mlme->reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 620 | default: |
| 621 | return -EOPNOTSUPP; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | |
| 626 | static int ieee80211_ioctl_siwencode(struct net_device *dev, |
| 627 | struct iw_request_info *info, |
| 628 | struct iw_point *erq, char *keybuf) |
| 629 | { |
| 630 | struct ieee80211_sub_if_data *sdata; |
| 631 | int idx, i, alg = ALG_WEP; |
| 632 | u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 633 | int remove = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 634 | |
| 635 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 636 | |
| 637 | idx = erq->flags & IW_ENCODE_INDEX; |
| 638 | if (idx == 0) { |
| 639 | if (sdata->default_key) |
| 640 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 641 | if (sdata->default_key == sdata->keys[i]) { |
| 642 | idx = i; |
| 643 | break; |
| 644 | } |
| 645 | } |
| 646 | } else if (idx < 1 || idx > 4) |
| 647 | return -EINVAL; |
| 648 | else |
| 649 | idx--; |
| 650 | |
| 651 | if (erq->flags & IW_ENCODE_DISABLED) |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 652 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 653 | else if (erq->length == 0) { |
| 654 | /* No key data - just set the default TX key index */ |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 655 | ieee80211_set_default_key(sdata, idx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | return ieee80211_set_encryption( |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 660 | sdata, bcaddr, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 661 | idx, alg, remove, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 662 | !sdata->default_key, |
| 663 | keybuf, erq->length); |
| 664 | } |
| 665 | |
| 666 | |
| 667 | static int ieee80211_ioctl_giwencode(struct net_device *dev, |
| 668 | struct iw_request_info *info, |
| 669 | struct iw_point *erq, char *key) |
| 670 | { |
| 671 | struct ieee80211_sub_if_data *sdata; |
| 672 | int idx, i; |
| 673 | |
| 674 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 675 | |
| 676 | idx = erq->flags & IW_ENCODE_INDEX; |
| 677 | if (idx < 1 || idx > 4) { |
| 678 | idx = -1; |
| 679 | if (!sdata->default_key) |
| 680 | idx = 0; |
| 681 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 682 | if (sdata->default_key == sdata->keys[i]) { |
| 683 | idx = i; |
| 684 | break; |
| 685 | } |
| 686 | } |
| 687 | if (idx < 0) |
| 688 | return -EINVAL; |
| 689 | } else |
| 690 | idx--; |
| 691 | |
| 692 | erq->flags = idx + 1; |
| 693 | |
| 694 | if (!sdata->keys[idx]) { |
| 695 | erq->length = 0; |
| 696 | erq->flags |= IW_ENCODE_DISABLED; |
| 697 | return 0; |
| 698 | } |
| 699 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 700 | memcpy(key, sdata->keys[idx]->conf.key, |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 701 | min_t(int, erq->length, sdata->keys[idx]->conf.keylen)); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 702 | erq->length = sdata->keys[idx]->conf.keylen; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 703 | erq->flags |= IW_ENCODE_ENABLED; |
| 704 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 705 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 706 | switch (sdata->u.mgd.auth_alg) { |
Emmanuel Grumbach | b9fcc4f | 2008-06-24 13:37:59 +0300 | [diff] [blame] | 707 | case WLAN_AUTH_OPEN: |
| 708 | case WLAN_AUTH_LEAP: |
| 709 | erq->flags |= IW_ENCODE_OPEN; |
| 710 | break; |
| 711 | case WLAN_AUTH_SHARED_KEY: |
| 712 | erq->flags |= IW_ENCODE_RESTRICTED; |
| 713 | break; |
| 714 | } |
| 715 | } |
| 716 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 717 | return 0; |
| 718 | } |
| 719 | |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 720 | static int ieee80211_ioctl_siwpower(struct net_device *dev, |
| 721 | struct iw_request_info *info, |
| 722 | struct iw_param *wrq, |
| 723 | char *extra) |
| 724 | { |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 725 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 726 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 727 | struct ieee80211_conf *conf = &local->hw.conf; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 728 | int ret = 0, timeout = 0; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 729 | bool ps; |
| 730 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 731 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) |
| 732 | return -EOPNOTSUPP; |
| 733 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 734 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 735 | return -EINVAL; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 736 | |
| 737 | if (wrq->disabled) { |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 738 | ps = false; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 739 | timeout = 0; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 740 | goto set; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | switch (wrq->flags & IW_POWER_MODE) { |
| 744 | case IW_POWER_ON: /* If not specified */ |
| 745 | case IW_POWER_MODE: /* If set all mask */ |
| 746 | case IW_POWER_ALL_R: /* If explicitely state all */ |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 747 | ps = true; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 748 | break; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 749 | default: /* Otherwise we ignore */ |
Johannes Berg | e9aeaba | 2009-01-06 18:12:35 +0100 | [diff] [blame] | 750 | return -EINVAL; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 751 | } |
| 752 | |
Johannes Berg | e9aeaba | 2009-01-06 18:12:35 +0100 | [diff] [blame] | 753 | if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT)) |
| 754 | return -EINVAL; |
| 755 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 756 | if (wrq->flags & IW_POWER_TIMEOUT) |
| 757 | timeout = wrq->value / 1000; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 758 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 759 | set: |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 760 | if (ps == local->powersave && timeout == conf->dynamic_ps_timeout) |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 761 | return ret; |
| 762 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 763 | local->powersave = ps; |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 764 | conf->dynamic_ps_timeout = timeout; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 765 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 766 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 767 | ret = ieee80211_hw_config(local, |
| 768 | IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 769 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 770 | if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)) |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 771 | return ret; |
| 772 | |
| 773 | if (conf->dynamic_ps_timeout > 0 && |
| 774 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) { |
| 775 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 776 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 777 | } else { |
| 778 | if (local->powersave) { |
| 779 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 780 | ieee80211_send_nullfunc(local, sdata, 1); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 781 | conf->flags |= IEEE80211_CONF_PS; |
| 782 | ret = ieee80211_hw_config(local, |
| 783 | IEEE80211_CONF_CHANGE_PS); |
| 784 | } else { |
| 785 | conf->flags &= ~IEEE80211_CONF_PS; |
| 786 | ret = ieee80211_hw_config(local, |
| 787 | IEEE80211_CONF_CHANGE_PS); |
| 788 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 789 | ieee80211_send_nullfunc(local, sdata, 0); |
Vivek Natarajan | b8abde4 | 2009-01-27 19:26:28 +0530 | [diff] [blame] | 790 | del_timer_sync(&local->dynamic_ps_timer); |
| 791 | cancel_work_sync(&local->dynamic_ps_enable_work); |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 792 | } |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | return ret; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static int ieee80211_ioctl_giwpower(struct net_device *dev, |
| 799 | struct iw_request_info *info, |
| 800 | union iwreq_data *wrqu, |
| 801 | char *extra) |
| 802 | { |
| 803 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 804 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 805 | wrqu->power.disabled = !local->powersave; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 810 | static int ieee80211_ioctl_siwauth(struct net_device *dev, |
| 811 | struct iw_request_info *info, |
| 812 | struct iw_param *data, char *extra) |
| 813 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 814 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 815 | int ret = 0; |
| 816 | |
| 817 | switch (data->flags & IW_AUTH_INDEX) { |
| 818 | case IW_AUTH_WPA_VERSION: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 819 | case IW_AUTH_CIPHER_GROUP: |
| 820 | case IW_AUTH_WPA_ENABLED: |
| 821 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 822 | case IW_AUTH_KEY_MGMT: |
Jouni Malinen | 54604d3 | 2009-01-08 13:32:03 +0200 | [diff] [blame] | 823 | case IW_AUTH_CIPHER_GROUP_MGMT: |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 824 | break; |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 825 | case IW_AUTH_CIPHER_PAIRWISE: |
| 826 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
| 827 | if (data->value & (IW_AUTH_CIPHER_WEP40 | |
| 828 | IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 829 | sdata->u.mgd.flags |= |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 830 | IEEE80211_STA_TKIP_WEP_USED; |
| 831 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 832 | sdata->u.mgd.flags &= |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 833 | ~IEEE80211_STA_TKIP_WEP_USED; |
| 834 | } |
| 835 | break; |
Johannes Berg | b1357a8 | 2007-11-28 11:04:21 +0100 | [diff] [blame] | 836 | case IW_AUTH_DROP_UNENCRYPTED: |
| 837 | sdata->drop_unencrypted = !!data->value; |
| 838 | break; |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 839 | case IW_AUTH_PRIVACY_INVOKED: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 840 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 841 | ret = -EINVAL; |
| 842 | else { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 843 | sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 844 | /* |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 845 | * Privacy invoked by wpa_supplicant, store the |
| 846 | * value and allow associating to a protected |
| 847 | * network without having a key up front. |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 848 | */ |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 849 | if (data->value) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 850 | sdata->u.mgd.flags |= |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 851 | IEEE80211_STA_PRIVACY_INVOKED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 852 | } |
| 853 | break; |
| 854 | case IW_AUTH_80211_AUTH_ALG: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 855 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 856 | sdata->u.mgd.auth_algs = data->value; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 857 | else |
| 858 | ret = -EOPNOTSUPP; |
| 859 | break; |
Jouni Malinen | fdfacf0 | 2009-01-08 13:32:05 +0200 | [diff] [blame] | 860 | case IW_AUTH_MFP: |
Jouni Malinen | 4375d08 | 2009-01-08 13:32:11 +0200 | [diff] [blame] | 861 | if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) { |
| 862 | ret = -EOPNOTSUPP; |
| 863 | break; |
| 864 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 865 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | e4e5e2b | 2009-02-10 21:25:40 +0100 | [diff] [blame] | 866 | switch (data->value) { |
| 867 | case IW_AUTH_MFP_DISABLED: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 868 | sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED; |
Johannes Berg | e4e5e2b | 2009-02-10 21:25:40 +0100 | [diff] [blame] | 869 | break; |
| 870 | case IW_AUTH_MFP_OPTIONAL: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 871 | sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL; |
Johannes Berg | e4e5e2b | 2009-02-10 21:25:40 +0100 | [diff] [blame] | 872 | break; |
| 873 | case IW_AUTH_MFP_REQUIRED: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 874 | sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED; |
Johannes Berg | e4e5e2b | 2009-02-10 21:25:40 +0100 | [diff] [blame] | 875 | break; |
| 876 | default: |
| 877 | ret = -EINVAL; |
| 878 | } |
| 879 | } else |
Jouni Malinen | fdfacf0 | 2009-01-08 13:32:05 +0200 | [diff] [blame] | 880 | ret = -EOPNOTSUPP; |
| 881 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 882 | default: |
| 883 | ret = -EOPNOTSUPP; |
| 884 | break; |
| 885 | } |
| 886 | return ret; |
| 887 | } |
| 888 | |
| 889 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
| 890 | static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev) |
| 891 | { |
| 892 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 893 | struct iw_statistics *wstats = &local->wstats; |
| 894 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 895 | struct sta_info *sta = NULL; |
| 896 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 897 | rcu_read_lock(); |
| 898 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 899 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 900 | sta = sta_info_get(local, sdata->u.mgd.bssid); |
| 901 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 902 | if (!sta) { |
| 903 | wstats->discard.fragment = 0; |
| 904 | wstats->discard.misc = 0; |
| 905 | wstats->qual.qual = 0; |
| 906 | wstats->qual.level = 0; |
| 907 | wstats->qual.noise = 0; |
| 908 | wstats->qual.updated = IW_QUAL_ALL_INVALID; |
| 909 | } else { |
Johannes Berg | 24776cf | 2009-02-27 16:33:55 -0600 | [diff] [blame] | 910 | wstats->qual.updated = 0; |
| 911 | /* |
| 912 | * mirror what cfg80211 does for iwrange/scan results, |
| 913 | * otherwise userspace gets confused. |
| 914 | */ |
| 915 | if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC | |
| 916 | IEEE80211_HW_SIGNAL_DBM)) { |
| 917 | wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 918 | wstats->qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 919 | } else { |
| 920 | wstats->qual.updated |= IW_QUAL_LEVEL_INVALID; |
| 921 | wstats->qual.updated |= IW_QUAL_QUAL_INVALID; |
| 922 | } |
| 923 | |
| 924 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) { |
| 925 | wstats->qual.level = sta->last_signal; |
| 926 | wstats->qual.qual = sta->last_signal; |
| 927 | } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) { |
| 928 | int sig = sta->last_signal; |
| 929 | |
| 930 | wstats->qual.updated |= IW_QUAL_DBM; |
| 931 | wstats->qual.level = sig; |
| 932 | if (sig < -110) |
| 933 | sig = -110; |
| 934 | else if (sig > -40) |
| 935 | sig = -40; |
| 936 | wstats->qual.qual = sig + 110; |
| 937 | } |
| 938 | |
| 939 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) { |
| 940 | /* |
| 941 | * This assumes that if driver reports noise, it also |
| 942 | * reports signal in dBm. |
| 943 | */ |
| 944 | wstats->qual.noise = sta->last_noise; |
| 945 | wstats->qual.updated |= IW_QUAL_NOISE_UPDATED; |
| 946 | } else { |
| 947 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID; |
| 948 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 949 | } |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 950 | |
| 951 | rcu_read_unlock(); |
| 952 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 953 | return wstats; |
| 954 | } |
| 955 | |
| 956 | static int ieee80211_ioctl_giwauth(struct net_device *dev, |
| 957 | struct iw_request_info *info, |
| 958 | struct iw_param *data, char *extra) |
| 959 | { |
| 960 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 961 | int ret = 0; |
| 962 | |
| 963 | switch (data->flags & IW_AUTH_INDEX) { |
| 964 | case IW_AUTH_80211_AUTH_ALG: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 965 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 966 | data->value = sdata->u.mgd.auth_algs; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 967 | else |
| 968 | ret = -EOPNOTSUPP; |
| 969 | break; |
| 970 | default: |
| 971 | ret = -EOPNOTSUPP; |
| 972 | break; |
| 973 | } |
| 974 | return ret; |
| 975 | } |
| 976 | |
| 977 | |
| 978 | static int ieee80211_ioctl_siwencodeext(struct net_device *dev, |
| 979 | struct iw_request_info *info, |
| 980 | struct iw_point *erq, char *extra) |
| 981 | { |
| 982 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 983 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 984 | int uninitialized_var(alg), idx, i, remove = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 985 | |
| 986 | switch (ext->alg) { |
| 987 | case IW_ENCODE_ALG_NONE: |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 988 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 989 | break; |
| 990 | case IW_ENCODE_ALG_WEP: |
| 991 | alg = ALG_WEP; |
| 992 | break; |
| 993 | case IW_ENCODE_ALG_TKIP: |
| 994 | alg = ALG_TKIP; |
| 995 | break; |
| 996 | case IW_ENCODE_ALG_CCMP: |
| 997 | alg = ALG_CCMP; |
| 998 | break; |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 999 | case IW_ENCODE_ALG_AES_CMAC: |
| 1000 | alg = ALG_AES_CMAC; |
| 1001 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1002 | default: |
| 1003 | return -EOPNOTSUPP; |
| 1004 | } |
| 1005 | |
| 1006 | if (erq->flags & IW_ENCODE_DISABLED) |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1007 | remove = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1008 | |
| 1009 | idx = erq->flags & IW_ENCODE_INDEX; |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 1010 | if (alg == ALG_AES_CMAC) { |
| 1011 | if (idx < NUM_DEFAULT_KEYS + 1 || |
| 1012 | idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) { |
| 1013 | idx = -1; |
| 1014 | if (!sdata->default_mgmt_key) |
| 1015 | idx = 0; |
| 1016 | else for (i = NUM_DEFAULT_KEYS; |
| 1017 | i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS; |
| 1018 | i++) { |
| 1019 | if (sdata->default_mgmt_key == sdata->keys[i]) |
| 1020 | { |
| 1021 | idx = i; |
| 1022 | break; |
| 1023 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1024 | } |
Jouni Malinen | 22787db | 2009-01-08 13:32:04 +0200 | [diff] [blame] | 1025 | if (idx < 0) |
| 1026 | return -EINVAL; |
| 1027 | } else |
| 1028 | idx--; |
| 1029 | } else { |
| 1030 | if (idx < 1 || idx > 4) { |
| 1031 | idx = -1; |
| 1032 | if (!sdata->default_key) |
| 1033 | idx = 0; |
| 1034 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1035 | if (sdata->default_key == sdata->keys[i]) { |
| 1036 | idx = i; |
| 1037 | break; |
| 1038 | } |
| 1039 | } |
| 1040 | if (idx < 0) |
| 1041 | return -EINVAL; |
| 1042 | } else |
| 1043 | idx--; |
| 1044 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1045 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1046 | return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg, |
Johannes Berg | 628a140 | 2007-09-26 17:53:17 +0200 | [diff] [blame] | 1047 | remove, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1048 | ext->ext_flags & |
| 1049 | IW_ENCODE_EXT_SET_TX_KEY, |
| 1050 | ext->key, ext->key_len); |
| 1051 | } |
| 1052 | |
| 1053 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1054 | /* Structures to export the Wireless Handlers */ |
| 1055 | |
| 1056 | static const iw_handler ieee80211_handler[] = |
| 1057 | { |
| 1058 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 1059 | (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1060 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 1061 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 1062 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ |
| 1063 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 1064 | (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */ |
| 1065 | (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1066 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 1067 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 1068 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 1069 | (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1070 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ |
| 1071 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ |
| 1072 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ |
| 1073 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ |
Johannes Berg | 5d4ecd9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 1074 | (iw_handler) NULL, /* SIOCSIWSPY */ |
| 1075 | (iw_handler) NULL, /* SIOCGIWSPY */ |
| 1076 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ |
| 1077 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1078 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
| 1079 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ |
| 1080 | (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ |
| 1081 | (iw_handler) NULL, /* SIOCGIWAPLIST */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1082 | (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */ |
| 1083 | (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1084 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ |
| 1085 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ |
| 1086 | (iw_handler) NULL, /* SIOCSIWNICKN */ |
| 1087 | (iw_handler) NULL, /* SIOCGIWNICKN */ |
| 1088 | (iw_handler) NULL, /* -- hole -- */ |
| 1089 | (iw_handler) NULL, /* -- hole -- */ |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1090 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 1091 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1092 | (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ |
| 1093 | (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ |
| 1094 | (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ |
| 1095 | (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 1096 | (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 1097 | (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1098 | (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ |
| 1099 | (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ |
| 1100 | (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ |
| 1101 | (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 1102 | (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ |
| 1103 | (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1104 | (iw_handler) NULL, /* -- hole -- */ |
| 1105 | (iw_handler) NULL, /* -- hole -- */ |
| 1106 | (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */ |
| 1107 | (iw_handler) NULL, /* SIOCGIWGENIE */ |
| 1108 | (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ |
| 1109 | (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ |
| 1110 | (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ |
| 1111 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ |
| 1112 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 1113 | (iw_handler) NULL, /* -- hole -- */ |
| 1114 | }; |
| 1115 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1116 | const struct iw_handler_def ieee80211_iw_handler_def = |
| 1117 | { |
| 1118 | .num_standard = ARRAY_SIZE(ieee80211_handler), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1119 | .standard = (iw_handler *) ieee80211_handler, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1120 | .get_wireless_stats = ieee80211_get_wireless_stats, |
| 1121 | }; |