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