blob: eb63fc148019a6a59b143a18823513462d65bdb2 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
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 Berg2c8dccc2008-04-08 15:14:40 -040024#include "led.h"
25#include "rate.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070026#include "wpa.h"
27#include "aes_ccm.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070028
Johannes Bergb708e612007-09-14 11:10:25 -040029
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120030static int ieee80211_set_encryption(struct ieee80211_sub_if_data *sdata, u8 *sta_addr,
Johannes Berg628a1402007-09-26 17:53:17 +020031 int idx, int alg, int remove,
32 int set_tx_key, const u8 *_key,
33 size_t key_len)
Jiri Bencf0706e82007-05-05 11:45:53 -070034{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120035 struct ieee80211_local *local = sdata->local;
Johannes Bergd0709a62008-02-25 16:27:46 +010036 struct sta_info *sta;
Johannes Berg11a843b2007-08-28 17:01:55 -040037 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +020038 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070039
Jouni Malinen22787db2009-01-08 13:32:04 +020040 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 Braun139c3a02007-09-14 11:10:25 -040048 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120049 sdata->dev->name, idx);
Volker Braun139c3a02007-09-14 11:10:25 -040050 return -EINVAL;
51 }
52
Johannes Berg628a1402007-09-26 17:53:17 +020053 if (remove) {
Johannes Berg3b967662008-04-08 17:56:52 +020054 rcu_read_lock();
55
56 err = 0;
57
Johannes Bergdb4d1162008-02-25 16:27:45 +010058 if (is_broadcast_ether_addr(sta_addr)) {
59 key = sdata->keys[idx];
60 } else {
61 sta = sta_info_get(local, sta_addr);
Johannes Berg3b967662008-04-08 17:56:52 +020062 if (!sta) {
63 err = -ENOENT;
64 goto out_unlock;
65 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010066 key = sta->key;
Jiri Bencf0706e82007-05-05 11:45:53 -070067 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010068
Johannes Bergd0709a62008-02-25 16:27:46 +010069 ieee80211_key_free(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +010070 } else {
71 key = ieee80211_key_alloc(alg, idx, key_len, _key);
72 if (!key)
73 return -ENOMEM;
74
Johannes Bergd0709a62008-02-25 16:27:46 +010075 sta = NULL;
Johannes Berg3b967662008-04-08 17:56:52 +020076 err = 0;
77
78 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +010079
Johannes Bergdb4d1162008-02-25 16:27:45 +010080 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 Bergd0709a62008-02-25 16:27:46 +010089 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020090 err = -EINVAL;
91 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010092 }
93
94 sta = sta_info_get(local, sta_addr);
95 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +010096 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020097 err = -ENOENT;
98 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010099 }
100 }
101
Emmanuel Grumbach23976ef2008-06-28 02:50:13 +0300102 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 Bergdb4d1162008-02-25 16:27:45 +0100109 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 Malinen22787db2009-01-08 13:32:04 +0200113 if (alg == ALG_AES_CMAC &&
114 (set_tx_key || (!sta && !sdata->default_mgmt_key && key)))
115 ieee80211_set_default_mgmt_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700116 }
117
Johannes Berg3b967662008-04-08 17:56:52 +0200118 out_unlock:
119 rcu_read_unlock();
120
121 return err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700122}
123
124static 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 Bencf0706e82007-05-05 11:45:53 -0700129
130 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200131
Johannes Berg46900292009-02-15 12:44:28 +0100132 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200133 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700134 if (ret)
135 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100136 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200137 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100138 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700139 return 0;
140 }
141
Jiri Bencf0706e82007-05-05 11:45:53 -0700142 return -EOPNOTSUPP;
143}
144
Jiri Bencf0706e82007-05-05 11:45:53 -0700145static int ieee80211_ioctl_siwfreq(struct net_device *dev,
146 struct iw_request_info *info,
147 struct iw_freq *freq, char *extra)
148{
Jiri Bencf0706e82007-05-05 11:45:53 -0700149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
150
Johannes Berg46900292009-02-15 12:44:28 +0100151 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200152 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
Johannes Berg46900292009-02-15 12:44:28 +0100153 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
154 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700155
156 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
157 if (freq->e == 0) {
158 if (freq->m < 0) {
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200159 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Johannes Berg46900292009-02-15 12:44:28 +0100160 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400161 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700162 return 0;
163 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200164 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100165 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700166 } else {
167 int i, div = 1000000;
168 for (i = 0; i < freq->e; i++)
169 div /= 10;
170 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200171 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700172 else
173 return -EINVAL;
174 }
175}
176
177
178static int ieee80211_ioctl_giwfreq(struct net_device *dev,
179 struct iw_request_info *info,
180 struct iw_freq *freq, char *extra)
181{
182 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200183 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
184
185 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
186 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
Jiri Bencf0706e82007-05-05 11:45:53 -0700187
Johannes Berg8318d782008-01-24 19:38:38 +0100188 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700189 freq->e = 6;
190
191 return 0;
192}
193
194
195static int ieee80211_ioctl_siwessid(struct net_device *dev,
196 struct iw_request_info *info,
197 struct iw_point *data, char *ssid)
198{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200199 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700200 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100201 int ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700202
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200203 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
204 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
205
Jiri Bencf0706e82007-05-05 11:45:53 -0700206 /* iwconfig uses nul termination in SSID.. */
207 if (len > 0 && ssid[len - 1] == '\0')
208 len--;
209
Johannes Berg46900292009-02-15 12:44:28 +0100210 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400211 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100212 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400213 else
Johannes Berg46900292009-02-15 12:44:28 +0100214 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
215
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200216 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700217 if (ret)
218 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100219
Jouni Malinen636a5d32009-03-19 13:39:22 +0200220 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100221 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700222 return 0;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200223 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700224
Jiri Bencf0706e82007-05-05 11:45:53 -0700225 return -EOPNOTSUPP;
226}
227
228
229static int ieee80211_ioctl_giwessid(struct net_device *dev,
230 struct iw_request_info *info,
231 struct iw_point *data, char *ssid)
232{
233 size_t len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700234 struct ieee80211_sub_if_data *sdata;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200235
Jiri Bencf0706e82007-05-05 11:45:53 -0700236 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200237
238 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
239 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
240
Johannes Berg46900292009-02-15 12:44:28 +0100241 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200242 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700243 if (res == 0) {
244 data->length = len;
245 data->flags = 1;
246 } else
247 data->flags = 0;
248 return res;
249 }
250
Jiri Bencf0706e82007-05-05 11:45:53 -0700251 return -EOPNOTSUPP;
252}
253
254
255static int ieee80211_ioctl_siwap(struct net_device *dev,
256 struct iw_request_info *info,
257 struct sockaddr *ap_addr, char *extra)
258{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200259 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700260
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200261 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
262 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
263
Johannes Berg46900292009-02-15 12:44:28 +0100264 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700265 int ret;
Johannes Berg7986cf92009-03-21 17:08:43 +0100266
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400267 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100268 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400269 IEEE80211_STA_AUTO_CHANNEL_SEL;
270 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100271 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700272 else
Johannes Berg46900292009-02-15 12:44:28 +0100273 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200274 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700275 if (ret)
276 return ret;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200277 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100278 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700279 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200280 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100281 /*
282 * If it is necessary to update the WDS peer address
283 * while the interface is running, then we need to do
284 * more work here, namely if it is running we need to
285 * add a new and remove the old STA entry, this is
286 * normally handled by _open() and _stop().
287 */
288 if (netif_running(dev))
289 return -EBUSY;
290
291 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
292 ETH_ALEN);
293
294 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700295 }
296
297 return -EOPNOTSUPP;
298}
299
300
301static int ieee80211_ioctl_giwap(struct net_device *dev,
302 struct iw_request_info *info,
303 struct sockaddr *ap_addr, char *extra)
304{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700306
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200307 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
308 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
309
Johannes Berg46900292009-02-15 12:44:28 +0100310 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
311 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700312 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100313 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
314 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700315 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100316 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200317 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700318 ap_addr->sa_family = ARPHRD_ETHER;
319 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
320 return 0;
321 }
322
323 return -EOPNOTSUPP;
324}
325
326
Larry Finger1fd5e582007-07-10 19:32:10 +0200327static int ieee80211_ioctl_siwrate(struct net_device *dev,
328 struct iw_request_info *info,
329 struct iw_param *rate, char *extra)
330{
331 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100332 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200333 u32 target_rate = rate->value / 100000;
334 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100335 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200336
337 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100338
339 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
340
Larry Finger1fd5e582007-07-10 19:32:10 +0200341 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
342 * target_rate = X, rate->fixed = 1 means only rate X
343 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200344 sdata->max_ratectrl_rateidx = -1;
345 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200346 if (rate->value < 0)
347 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100348
349 for (i=0; i< sband->n_bitrates; i++) {
350 struct ieee80211_rate *brate = &sband->bitrates[i];
351 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200352
Larry Finger1fd5e582007-07-10 19:32:10 +0200353 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200354 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200355 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200356 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100357 err = 0;
358 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200359 }
360 }
Johannes Berg8318d782008-01-24 19:38:38 +0100361 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200362}
363
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700364static int ieee80211_ioctl_giwrate(struct net_device *dev,
365 struct iw_request_info *info,
366 struct iw_param *rate, char *extra)
367{
368 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
369 struct sta_info *sta;
370 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100371 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700372
373 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100374
Johannes Berg05c914f2008-09-11 00:01:58 +0200375 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700376 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100377
378 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
379
Johannes Berg380a9422008-04-04 23:40:35 +0200380 rcu_read_lock();
381
Johannes Berg46900292009-02-15 12:44:28 +0100382 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200383
Johannes Berge6a98542008-10-21 12:40:02 +0200384 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
385 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700386 else
387 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200388
389 rcu_read_unlock();
390
391 if (!sta)
392 return -ENODEV;
393
Johannes Berg8318d782008-01-24 19:38:38 +0100394 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100395
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700396 return 0;
397}
398
Michael Buesch61609bc2007-09-20 22:06:39 +0200399static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
400 struct iw_request_info *info,
401 union iwreq_data *data, char *extra)
402{
403 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700404 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berg47afbaf2009-04-07 15:22:28 +0200405 bool reconf = false;
Johannes Berge8975582008-10-09 12:18:51 +0200406 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100407 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200408
409 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
410 return -EINVAL;
411 if (data->txpower.flags & IW_TXPOW_RANGE)
412 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700413 if (!chan)
414 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200415
Johannes Berg47afbaf2009-04-07 15:22:28 +0200416 /* only change when not disabling */
417 if (!data->txpower.disabled) {
418 if (data->txpower.fixed) {
419 if (data->txpower.value < 0)
420 return -EINVAL;
421 new_power_level = data->txpower.value;
422 /*
423 * Debatable, but we cannot do a fixed power
424 * level above the regulatory constraint.
425 * Use "iwconfig wlan0 txpower 15dBm" instead.
426 */
427 if (new_power_level > chan->max_power)
428 return -EINVAL;
429 } else {
430 /*
431 * Automatic power level setting, max being the value
432 * passed in from userland.
433 */
434 if (data->txpower.value < 0)
435 new_power_level = -1;
436 else
437 new_power_level = data->txpower.value;
438 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200439
Johannes Berg47afbaf2009-04-07 15:22:28 +0200440 reconf = true;
441
442 /*
443 * ieee80211_hw_config() will limit to the channel's
444 * max power and possibly power constraint from AP.
445 */
446 local->user_power_level = new_power_level;
447 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200448
Michael Buesch61609bc2007-09-20 22:06:39 +0200449 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
450 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200451 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100452 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200453 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200454
Johannes Berg47afbaf2009-04-07 15:22:28 +0200455 if (reconf || reconf_flags)
Johannes Berge8975582008-10-09 12:18:51 +0200456 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200457
458 return 0;
459}
460
Larry Fingerfe6aa302007-08-10 11:23:20 -0500461static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
462 struct iw_request_info *info,
463 union iwreq_data *data, char *extra)
464{
465 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
466
467 data->txpower.fixed = 1;
468 data->txpower.disabled = !(local->hw.conf.radio_enabled);
469 data->txpower.value = local->hw.conf.power_level;
470 data->txpower.flags = IW_TXPOW_DBM;
471
472 return 0;
473}
474
Jiri Bencf0706e82007-05-05 11:45:53 -0700475static int ieee80211_ioctl_siwrts(struct net_device *dev,
476 struct iw_request_info *info,
477 struct iw_param *rts, char *extra)
478{
479 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
480
481 if (rts->disabled)
482 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300483 else if (!rts->fixed)
484 /* if the rts value is not fixed, then take default */
485 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700486 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
487 return -EINVAL;
488 else
489 local->rts_threshold = rts->value;
490
491 /* If the wlan card performs RTS/CTS in hardware/firmware,
492 * configure it here */
493
494 if (local->ops->set_rts_threshold)
495 local->ops->set_rts_threshold(local_to_hw(local),
496 local->rts_threshold);
497
498 return 0;
499}
500
501static int ieee80211_ioctl_giwrts(struct net_device *dev,
502 struct iw_request_info *info,
503 struct iw_param *rts, char *extra)
504{
505 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
506
507 rts->value = local->rts_threshold;
508 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
509 rts->fixed = 1;
510
511 return 0;
512}
513
514
515static int ieee80211_ioctl_siwfrag(struct net_device *dev,
516 struct iw_request_info *info,
517 struct iw_param *frag, char *extra)
518{
519 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
520
521 if (frag->disabled)
522 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300523 else if (!frag->fixed)
524 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700525 else if (frag->value < 256 ||
526 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
527 return -EINVAL;
528 else {
529 /* Fragment length must be even, so strip LSB. */
530 local->fragmentation_threshold = frag->value & ~0x1;
531 }
532
Jiri Bencf0706e82007-05-05 11:45:53 -0700533 return 0;
534}
535
536static int ieee80211_ioctl_giwfrag(struct net_device *dev,
537 struct iw_request_info *info,
538 struct iw_param *frag, char *extra)
539{
540 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
541
542 frag->value = local->fragmentation_threshold;
Gerrit Renker23a99842009-04-14 06:32:56 +0200543 frag->disabled = (frag->value >= IEEE80211_MAX_FRAG_THRESHOLD);
Jiri Bencf0706e82007-05-05 11:45:53 -0700544 frag->fixed = 1;
545
546 return 0;
547}
548
549
550static int ieee80211_ioctl_siwretry(struct net_device *dev,
551 struct iw_request_info *info,
552 struct iw_param *retry, char *extra)
553{
554 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
555
556 if (retry->disabled ||
557 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
558 return -EINVAL;
559
Johannes Berg9124b072008-10-14 19:17:54 +0200560 if (retry->flags & IW_RETRY_MAX) {
561 local->hw.conf.long_frame_max_tx_count = retry->value;
562 } else if (retry->flags & IW_RETRY_MIN) {
563 local->hw.conf.short_frame_max_tx_count = retry->value;
564 } else {
565 local->hw.conf.long_frame_max_tx_count = retry->value;
566 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700567 }
568
Johannes Berg9124b072008-10-14 19:17:54 +0200569 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700570
571 return 0;
572}
573
574
575static int ieee80211_ioctl_giwretry(struct net_device *dev,
576 struct iw_request_info *info,
577 struct iw_param *retry, char *extra)
578{
579 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
580
581 retry->disabled = 0;
582 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
583 /* first return min value, iwconfig will ask max value
584 * later if needed */
585 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200586 retry->value = local->hw.conf.short_frame_max_tx_count;
587 if (local->hw.conf.long_frame_max_tx_count !=
588 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700589 retry->flags |= IW_RETRY_MIN;
590 return 0;
591 }
592 if (retry->flags & IW_RETRY_MAX) {
593 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200594 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700595 }
596
597 return 0;
598}
599
Jiri Bencf0706e82007-05-05 11:45:53 -0700600
601static int ieee80211_ioctl_siwencode(struct net_device *dev,
602 struct iw_request_info *info,
603 struct iw_point *erq, char *keybuf)
604{
605 struct ieee80211_sub_if_data *sdata;
606 int idx, i, alg = ALG_WEP;
607 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530608 int remove = 0, ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700609
610 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
611
612 idx = erq->flags & IW_ENCODE_INDEX;
613 if (idx == 0) {
614 if (sdata->default_key)
615 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
616 if (sdata->default_key == sdata->keys[i]) {
617 idx = i;
618 break;
619 }
620 }
621 } else if (idx < 1 || idx > 4)
622 return -EINVAL;
623 else
624 idx--;
625
626 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200627 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700628 else if (erq->length == 0) {
629 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400630 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700631 return 0;
632 }
633
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530634 ret = ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200635 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200636 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700637 !sdata->default_key,
638 keybuf, erq->length);
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530639
Vasanthakumar Thiagarajanb0741a12009-03-27 13:08:45 +0530640 if (!ret && sdata->vif.type == NL80211_IFTYPE_STATION) {
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530641 if (remove)
642 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
643 else
644 sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
645 }
646
647 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700648}
649
650
651static int ieee80211_ioctl_giwencode(struct net_device *dev,
652 struct iw_request_info *info,
653 struct iw_point *erq, char *key)
654{
655 struct ieee80211_sub_if_data *sdata;
656 int idx, i;
657
658 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
659
660 idx = erq->flags & IW_ENCODE_INDEX;
661 if (idx < 1 || idx > 4) {
662 idx = -1;
663 if (!sdata->default_key)
664 idx = 0;
665 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
666 if (sdata->default_key == sdata->keys[i]) {
667 idx = i;
668 break;
669 }
670 }
671 if (idx < 0)
672 return -EINVAL;
673 } else
674 idx--;
675
676 erq->flags = idx + 1;
677
678 if (!sdata->keys[idx]) {
679 erq->length = 0;
680 erq->flags |= IW_ENCODE_DISABLED;
681 return 0;
682 }
683
Johannes Berg8f20fc22007-08-28 17:01:54 -0400684 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400685 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400686 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700687 erq->flags |= IW_ENCODE_ENABLED;
688
Johannes Berg05c914f2008-09-11 00:01:58 +0200689 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berg46900292009-02-15 12:44:28 +0100690 switch (sdata->u.mgd.auth_alg) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300691 case WLAN_AUTH_OPEN:
692 case WLAN_AUTH_LEAP:
693 erq->flags |= IW_ENCODE_OPEN;
694 break;
695 case WLAN_AUTH_SHARED_KEY:
696 erq->flags |= IW_ENCODE_RESTRICTED;
697 break;
698 }
699 }
700
Jiri Bencf0706e82007-05-05 11:45:53 -0700701 return 0;
702}
703
Samuel Ortiz49292d52008-07-04 10:49:31 +0200704static int ieee80211_ioctl_siwpower(struct net_device *dev,
705 struct iw_request_info *info,
706 struct iw_param *wrq,
707 char *extra)
708{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200709 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200710 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
711 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg965beda2009-04-16 13:17:24 +0200712 int timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200713 bool ps;
714
Johannes Berg4be8c382009-01-07 18:28:20 +0100715 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
716 return -EOPNOTSUPP;
717
Kalle Valoe0cb6862008-12-18 23:35:13 +0200718 if (sdata->vif.type != NL80211_IFTYPE_STATION)
719 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200720
721 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200722 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200723 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200724 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200725 }
726
727 switch (wrq->flags & IW_POWER_MODE) {
728 case IW_POWER_ON: /* If not specified */
729 case IW_POWER_MODE: /* If set all mask */
730 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200731 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200732 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200733 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100734 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200735 }
736
Johannes Berge9aeaba2009-01-06 18:12:35 +0100737 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
738 return -EINVAL;
739
Kalle Valo520eb822008-12-18 23:35:27 +0200740 if (wrq->flags & IW_POWER_TIMEOUT)
741 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200742
Johannes Berg4be8c382009-01-07 18:28:20 +0100743 set:
Johannes Berg965beda2009-04-16 13:17:24 +0200744 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
745 return 0;
Kalle Valo520eb822008-12-18 23:35:27 +0200746
Johannes Berg965beda2009-04-16 13:17:24 +0200747 sdata->u.mgd.powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100748 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200749
Johannes Berg4be8c382009-01-07 18:28:20 +0100750 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berg965beda2009-04-16 13:17:24 +0200751 ieee80211_hw_config(local,
752 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
Johannes Berg4be8c382009-01-07 18:28:20 +0100753
Johannes Berg10f644a2009-04-16 13:17:25 +0200754 ieee80211_recalc_ps(local, -1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100755
Johannes Berg965beda2009-04-16 13:17:24 +0200756 return 0;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200757}
758
759static int ieee80211_ioctl_giwpower(struct net_device *dev,
760 struct iw_request_info *info,
761 union iwreq_data *wrqu,
762 char *extra)
763{
Johannes Berg965beda2009-04-16 13:17:24 +0200764 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200765
Johannes Berg965beda2009-04-16 13:17:24 +0200766 wrqu->power.disabled = !sdata->u.mgd.powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200767
768 return 0;
769}
770
Jiri Bencf0706e82007-05-05 11:45:53 -0700771static int ieee80211_ioctl_siwauth(struct net_device *dev,
772 struct iw_request_info *info,
773 struct iw_param *data, char *extra)
774{
Jiri Bencf0706e82007-05-05 11:45:53 -0700775 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
776 int ret = 0;
777
778 switch (data->flags & IW_AUTH_INDEX) {
779 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700780 case IW_AUTH_CIPHER_GROUP:
781 case IW_AUTH_WPA_ENABLED:
782 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700783 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200784 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000785 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530786 case IW_AUTH_CIPHER_PAIRWISE:
787 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
788 if (data->value & (IW_AUTH_CIPHER_WEP40 |
789 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100790 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530791 IEEE80211_STA_TKIP_WEP_USED;
792 else
Johannes Berg46900292009-02-15 12:44:28 +0100793 sdata->u.mgd.flags &=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530794 ~IEEE80211_STA_TKIP_WEP_USED;
795 }
796 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100797 case IW_AUTH_DROP_UNENCRYPTED:
798 sdata->drop_unencrypted = !!data->value;
799 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000800 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200801 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700802 ret = -EINVAL;
803 else {
Johannes Berg46900292009-02-15 12:44:28 +0100804 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700805 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000806 * Privacy invoked by wpa_supplicant, store the
807 * value and allow associating to a protected
808 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700809 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000810 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100811 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000812 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700813 }
814 break;
815 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100816 if (sdata->vif.type == NL80211_IFTYPE_STATION)
817 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700818 else
819 ret = -EOPNOTSUPP;
820 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200821 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200822 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
823 ret = -EOPNOTSUPP;
824 break;
825 }
Johannes Berg46900292009-02-15 12:44:28 +0100826 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100827 switch (data->value) {
828 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100829 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100830 break;
831 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100832 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100833 break;
834 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100835 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100836 break;
837 default:
838 ret = -EINVAL;
839 }
840 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200841 ret = -EOPNOTSUPP;
842 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700843 default:
844 ret = -EOPNOTSUPP;
845 break;
846 }
847 return ret;
848}
849
850/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
851static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
852{
853 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
854 struct iw_statistics *wstats = &local->wstats;
855 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
856 struct sta_info *sta = NULL;
857
Johannes Berg98dd6a52008-04-10 15:36:09 +0200858 rcu_read_lock();
859
Johannes Berg46900292009-02-15 12:44:28 +0100860 if (sdata->vif.type == NL80211_IFTYPE_STATION)
861 sta = sta_info_get(local, sdata->u.mgd.bssid);
862
Jiri Bencf0706e82007-05-05 11:45:53 -0700863 if (!sta) {
864 wstats->discard.fragment = 0;
865 wstats->discard.misc = 0;
866 wstats->qual.qual = 0;
867 wstats->qual.level = 0;
868 wstats->qual.noise = 0;
869 wstats->qual.updated = IW_QUAL_ALL_INVALID;
870 } else {
Johannes Berg24776cf2009-02-27 16:33:55 -0600871 wstats->qual.updated = 0;
872 /*
873 * mirror what cfg80211 does for iwrange/scan results,
874 * otherwise userspace gets confused.
875 */
876 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
877 IEEE80211_HW_SIGNAL_DBM)) {
878 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
879 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
880 } else {
881 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
882 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
883 }
884
885 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
886 wstats->qual.level = sta->last_signal;
887 wstats->qual.qual = sta->last_signal;
888 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
889 int sig = sta->last_signal;
890
891 wstats->qual.updated |= IW_QUAL_DBM;
892 wstats->qual.level = sig;
893 if (sig < -110)
894 sig = -110;
895 else if (sig > -40)
896 sig = -40;
897 wstats->qual.qual = sig + 110;
898 }
899
900 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
901 /*
902 * This assumes that if driver reports noise, it also
903 * reports signal in dBm.
904 */
905 wstats->qual.noise = sta->last_noise;
906 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
907 } else {
908 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
909 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700910 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200911
912 rcu_read_unlock();
913
Jiri Bencf0706e82007-05-05 11:45:53 -0700914 return wstats;
915}
916
917static int ieee80211_ioctl_giwauth(struct net_device *dev,
918 struct iw_request_info *info,
919 struct iw_param *data, char *extra)
920{
921 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
922 int ret = 0;
923
924 switch (data->flags & IW_AUTH_INDEX) {
925 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100926 if (sdata->vif.type == NL80211_IFTYPE_STATION)
927 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e82007-05-05 11:45:53 -0700928 else
929 ret = -EOPNOTSUPP;
930 break;
931 default:
932 ret = -EOPNOTSUPP;
933 break;
934 }
935 return ret;
936}
937
938
939static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
940 struct iw_request_info *info,
941 struct iw_point *erq, char *extra)
942{
943 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
944 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +0200945 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700946
947 switch (ext->alg) {
948 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +0200949 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700950 break;
951 case IW_ENCODE_ALG_WEP:
952 alg = ALG_WEP;
953 break;
954 case IW_ENCODE_ALG_TKIP:
955 alg = ALG_TKIP;
956 break;
957 case IW_ENCODE_ALG_CCMP:
958 alg = ALG_CCMP;
959 break;
Jouni Malinen22787db2009-01-08 13:32:04 +0200960 case IW_ENCODE_ALG_AES_CMAC:
961 alg = ALG_AES_CMAC;
962 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700963 default:
964 return -EOPNOTSUPP;
965 }
966
967 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200968 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700969
970 idx = erq->flags & IW_ENCODE_INDEX;
Jouni Malinen22787db2009-01-08 13:32:04 +0200971 if (alg == ALG_AES_CMAC) {
972 if (idx < NUM_DEFAULT_KEYS + 1 ||
973 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
974 idx = -1;
975 if (!sdata->default_mgmt_key)
976 idx = 0;
977 else for (i = NUM_DEFAULT_KEYS;
978 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
979 i++) {
980 if (sdata->default_mgmt_key == sdata->keys[i])
981 {
982 idx = i;
983 break;
984 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700985 }
Jouni Malinen22787db2009-01-08 13:32:04 +0200986 if (idx < 0)
987 return -EINVAL;
988 } else
989 idx--;
990 } else {
991 if (idx < 1 || idx > 4) {
992 idx = -1;
993 if (!sdata->default_key)
994 idx = 0;
995 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
996 if (sdata->default_key == sdata->keys[i]) {
997 idx = i;
998 break;
999 }
1000 }
1001 if (idx < 0)
1002 return -EINVAL;
1003 } else
1004 idx--;
1005 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001006
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001007 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001008 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001009 ext->ext_flags &
1010 IW_ENCODE_EXT_SET_TX_KEY,
1011 ext->key, ext->key_len);
1012}
1013
1014
Jiri Bencf0706e82007-05-05 11:45:53 -07001015/* Structures to export the Wireless Handlers */
1016
1017static const iw_handler ieee80211_handler[] =
1018{
1019 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001020 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001021 (iw_handler) NULL, /* SIOCSIWNWID */
1022 (iw_handler) NULL, /* SIOCGIWNWID */
1023 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1024 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001025 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1026 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001027 (iw_handler) NULL, /* SIOCSIWSENS */
1028 (iw_handler) NULL, /* SIOCGIWSENS */
1029 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
Johannes Berg4aa188e2009-02-18 19:32:08 +01001030 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001031 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1032 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1033 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1034 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001035 (iw_handler) NULL, /* SIOCSIWSPY */
1036 (iw_handler) NULL, /* SIOCGIWSPY */
1037 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1038 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001039 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1040 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
Johannes Berg691597c2009-04-19 19:57:45 +02001041 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001042 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +01001043 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1044 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e82007-05-05 11:45:53 -07001045 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1046 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1047 (iw_handler) NULL, /* SIOCSIWNICKN */
1048 (iw_handler) NULL, /* SIOCGIWNICKN */
1049 (iw_handler) NULL, /* -- hole -- */
1050 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001051 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001052 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001053 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1054 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1055 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1056 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001057 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001058 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001059 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1060 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1061 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1062 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001063 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1064 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001065 (iw_handler) NULL, /* -- hole -- */
1066 (iw_handler) NULL, /* -- hole -- */
1067 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1068 (iw_handler) NULL, /* SIOCGIWGENIE */
1069 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1070 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1071 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1072 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1073 (iw_handler) NULL, /* SIOCSIWPMKSA */
1074 (iw_handler) NULL, /* -- hole -- */
1075};
1076
Jiri Bencf0706e82007-05-05 11:45:53 -07001077const struct iw_handler_def ieee80211_iw_handler_def =
1078{
1079 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001080 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001081 .get_wireless_stats = ieee80211_get_wireless_stats,
1082};