blob: ce21d66b1023b4f2fdcb5a3f2e497231e215abed [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
132 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
133 return -EOPNOTSUPP;
134
Johannes Berg46900292009-02-15 12:44:28 +0100135 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200136 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700137 if (ret)
138 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100139 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200140 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100141 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700142 return 0;
143 }
144
Jiri Bencf0706e82007-05-05 11:45:53 -0700145 return -EOPNOTSUPP;
146}
147
Jiri Bencf0706e82007-05-05 11:45:53 -0700148static int ieee80211_ioctl_siwfreq(struct net_device *dev,
149 struct iw_request_info *info,
150 struct iw_freq *freq, char *extra)
151{
Jiri Bencf0706e82007-05-05 11:45:53 -0700152 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
153
Johannes Berg46900292009-02-15 12:44:28 +0100154 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
155 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL;
156 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
157 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700158
159 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
160 if (freq->e == 0) {
161 if (freq->m < 0) {
Johannes Berg46900292009-02-15 12:44:28 +0100162 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
163 sdata->u.ibss.flags |=
164 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
165 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
166 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400167 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700168 return 0;
169 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200170 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100171 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700172 } else {
173 int i, div = 1000000;
174 for (i = 0; i < freq->e; i++)
175 div /= 10;
176 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200177 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700178 else
179 return -EINVAL;
180 }
181}
182
183
184static int ieee80211_ioctl_giwfreq(struct net_device *dev,
185 struct iw_request_info *info,
186 struct iw_freq *freq, char *extra)
187{
188 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
189
Johannes Berg8318d782008-01-24 19:38:38 +0100190 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700191 freq->e = 6;
192
193 return 0;
194}
195
196
197static int ieee80211_ioctl_siwessid(struct net_device *dev,
198 struct iw_request_info *info,
199 struct iw_point *data, char *ssid)
200{
Jiri Bencf0706e82007-05-05 11:45:53 -0700201 struct ieee80211_sub_if_data *sdata;
202 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100203 int ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700204
205 /* iwconfig uses nul termination in SSID.. */
206 if (len > 0 && ssid[len - 1] == '\0')
207 len--;
208
209 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100210 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200211 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700212 if (len > IEEE80211_MAX_SSID_LEN)
213 return -EINVAL;
Johannes Berg46900292009-02-15 12:44:28 +0100214 memcpy(sdata->u.mgd.ssid, ssid, len);
215 sdata->u.mgd.ssid_len = len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700216 return 0;
217 }
Johannes Berg46900292009-02-15 12:44:28 +0100218
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400219 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100220 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400221 else
Johannes Berg46900292009-02-15 12:44:28 +0100222 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
223
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200224 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700225 if (ret)
226 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100227
Jouni Malinen636a5d32009-03-19 13:39:22 +0200228 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100229 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700230 return 0;
Johannes Berg46900292009-02-15 12:44:28 +0100231 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
232 return ieee80211_ibss_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700233
Jiri Bencf0706e82007-05-05 11:45:53 -0700234 return -EOPNOTSUPP;
235}
236
237
238static int ieee80211_ioctl_giwessid(struct net_device *dev,
239 struct iw_request_info *info,
240 struct iw_point *data, char *ssid)
241{
242 size_t len;
243
244 struct ieee80211_sub_if_data *sdata;
245 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100246 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200247 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700248 if (res == 0) {
249 data->length = len;
250 data->flags = 1;
251 } else
252 data->flags = 0;
253 return res;
Johannes Berg46900292009-02-15 12:44:28 +0100254 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
255 int res = ieee80211_ibss_get_ssid(sdata, ssid, &len);
256 if (res == 0) {
257 data->length = len;
258 data->flags = 1;
259 } else
260 data->flags = 0;
261 return res;
Jiri Bencf0706e82007-05-05 11:45:53 -0700262 }
263
Jiri Bencf0706e82007-05-05 11:45:53 -0700264 return -EOPNOTSUPP;
265}
266
267
268static int ieee80211_ioctl_siwap(struct net_device *dev,
269 struct iw_request_info *info,
270 struct sockaddr *ap_addr, char *extra)
271{
Jiri Bencf0706e82007-05-05 11:45:53 -0700272 struct ieee80211_sub_if_data *sdata;
273
274 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100275 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700276 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200277 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Johannes Berg46900292009-02-15 12:44:28 +0100278 memcpy(sdata->u.mgd.bssid, (u8 *) &ap_addr->sa_data,
Jiri Bencf0706e82007-05-05 11:45:53 -0700279 ETH_ALEN);
280 return 0;
281 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400282 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100283 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400284 IEEE80211_STA_AUTO_CHANNEL_SEL;
285 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100286 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700287 else
Johannes Berg46900292009-02-15 12:44:28 +0100288 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200289 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700290 if (ret)
291 return ret;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200292 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100293 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700294 return 0;
Johannes Berg46900292009-02-15 12:44:28 +0100295 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
296 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
297 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
298 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
299 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
300 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL;
301 else
302 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL;
303
304 return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Johannes Berg05c914f2008-09-11 00:01:58 +0200305 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100306 /*
307 * If it is necessary to update the WDS peer address
308 * while the interface is running, then we need to do
309 * more work here, namely if it is running we need to
310 * add a new and remove the old STA entry, this is
311 * normally handled by _open() and _stop().
312 */
313 if (netif_running(dev))
314 return -EBUSY;
315
316 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
317 ETH_ALEN);
318
319 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700320 }
321
322 return -EOPNOTSUPP;
323}
324
325
326static int ieee80211_ioctl_giwap(struct net_device *dev,
327 struct iw_request_info *info,
328 struct sockaddr *ap_addr, char *extra)
329{
330 struct ieee80211_sub_if_data *sdata;
331
332 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100333 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
334 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700335 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100336 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
337 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700338 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100339 return 0;
340 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
341 if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) {
342 ap_addr->sa_family = ARPHRD_ETHER;
343 memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN);
344 } else
345 memset(&ap_addr->sa_data, 0, ETH_ALEN);
346 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200347 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700348 ap_addr->sa_family = ARPHRD_ETHER;
349 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
350 return 0;
351 }
352
353 return -EOPNOTSUPP;
354}
355
356
Larry Finger1fd5e582007-07-10 19:32:10 +0200357static int ieee80211_ioctl_siwrate(struct net_device *dev,
358 struct iw_request_info *info,
359 struct iw_param *rate, char *extra)
360{
361 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100362 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200363 u32 target_rate = rate->value / 100000;
364 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100365 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200366
367 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100368
369 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
370
Larry Finger1fd5e582007-07-10 19:32:10 +0200371 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
372 * target_rate = X, rate->fixed = 1 means only rate X
373 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200374 sdata->max_ratectrl_rateidx = -1;
375 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200376 if (rate->value < 0)
377 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100378
379 for (i=0; i< sband->n_bitrates; i++) {
380 struct ieee80211_rate *brate = &sband->bitrates[i];
381 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200382
Larry Finger1fd5e582007-07-10 19:32:10 +0200383 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200384 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200385 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200386 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100387 err = 0;
388 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200389 }
390 }
Johannes Berg8318d782008-01-24 19:38:38 +0100391 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200392}
393
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700394static int ieee80211_ioctl_giwrate(struct net_device *dev,
395 struct iw_request_info *info,
396 struct iw_param *rate, char *extra)
397{
398 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
399 struct sta_info *sta;
400 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100401 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700402
403 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100404
Johannes Berg05c914f2008-09-11 00:01:58 +0200405 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700406 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100407
408 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
409
Johannes Berg380a9422008-04-04 23:40:35 +0200410 rcu_read_lock();
411
Johannes Berg46900292009-02-15 12:44:28 +0100412 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200413
Johannes Berge6a98542008-10-21 12:40:02 +0200414 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
415 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700416 else
417 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200418
419 rcu_read_unlock();
420
421 if (!sta)
422 return -ENODEV;
423
Johannes Berg8318d782008-01-24 19:38:38 +0100424 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100425
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700426 return 0;
427}
428
Michael Buesch61609bc2007-09-20 22:06:39 +0200429static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
430 struct iw_request_info *info,
431 union iwreq_data *data, char *extra)
432{
433 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700434 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200435 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100436 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200437
438 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
439 return -EINVAL;
440 if (data->txpower.flags & IW_TXPOW_RANGE)
441 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700442 if (!chan)
443 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200444
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700445 if (data->txpower.fixed)
446 new_power_level = min(data->txpower.value, chan->max_power);
447 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100448 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200449
Johannes Berg2bf30fa2009-01-06 23:23:56 +0100450 local->user_power_level = new_power_level;
Vasanthakumar Thiagarajane3c92df2008-12-24 13:53:11 +0530451 if (local->hw.conf.power_level != new_power_level)
Johannes Berge8975582008-10-09 12:18:51 +0200452 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Mattias Nissler6a432952007-10-24 23:30:36 +0200453
Michael Buesch61609bc2007-09-20 22:06:39 +0200454 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
455 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200456 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100457 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200458 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200459
Johannes Berge8975582008-10-09 12:18:51 +0200460 if (reconf_flags)
461 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200462
463 return 0;
464}
465
Larry Fingerfe6aa302007-08-10 11:23:20 -0500466static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
467 struct iw_request_info *info,
468 union iwreq_data *data, char *extra)
469{
470 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
471
472 data->txpower.fixed = 1;
473 data->txpower.disabled = !(local->hw.conf.radio_enabled);
474 data->txpower.value = local->hw.conf.power_level;
475 data->txpower.flags = IW_TXPOW_DBM;
476
477 return 0;
478}
479
Jiri Bencf0706e82007-05-05 11:45:53 -0700480static int ieee80211_ioctl_siwrts(struct net_device *dev,
481 struct iw_request_info *info,
482 struct iw_param *rts, char *extra)
483{
484 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
485
486 if (rts->disabled)
487 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300488 else if (!rts->fixed)
489 /* if the rts value is not fixed, then take default */
490 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700491 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
492 return -EINVAL;
493 else
494 local->rts_threshold = rts->value;
495
496 /* If the wlan card performs RTS/CTS in hardware/firmware,
497 * configure it here */
498
499 if (local->ops->set_rts_threshold)
500 local->ops->set_rts_threshold(local_to_hw(local),
501 local->rts_threshold);
502
503 return 0;
504}
505
506static int ieee80211_ioctl_giwrts(struct net_device *dev,
507 struct iw_request_info *info,
508 struct iw_param *rts, char *extra)
509{
510 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
511
512 rts->value = local->rts_threshold;
513 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
514 rts->fixed = 1;
515
516 return 0;
517}
518
519
520static int ieee80211_ioctl_siwfrag(struct net_device *dev,
521 struct iw_request_info *info,
522 struct iw_param *frag, char *extra)
523{
524 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
525
526 if (frag->disabled)
527 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300528 else if (!frag->fixed)
529 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700530 else if (frag->value < 256 ||
531 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
532 return -EINVAL;
533 else {
534 /* Fragment length must be even, so strip LSB. */
535 local->fragmentation_threshold = frag->value & ~0x1;
536 }
537
Jiri Bencf0706e82007-05-05 11:45:53 -0700538 return 0;
539}
540
541static int ieee80211_ioctl_giwfrag(struct net_device *dev,
542 struct iw_request_info *info,
543 struct iw_param *frag, char *extra)
544{
545 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
546
547 frag->value = local->fragmentation_threshold;
548 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
549 frag->fixed = 1;
550
551 return 0;
552}
553
554
555static int ieee80211_ioctl_siwretry(struct net_device *dev,
556 struct iw_request_info *info,
557 struct iw_param *retry, char *extra)
558{
559 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
560
561 if (retry->disabled ||
562 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
563 return -EINVAL;
564
Johannes Berg9124b072008-10-14 19:17:54 +0200565 if (retry->flags & IW_RETRY_MAX) {
566 local->hw.conf.long_frame_max_tx_count = retry->value;
567 } else if (retry->flags & IW_RETRY_MIN) {
568 local->hw.conf.short_frame_max_tx_count = retry->value;
569 } else {
570 local->hw.conf.long_frame_max_tx_count = retry->value;
571 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700572 }
573
Johannes Berg9124b072008-10-14 19:17:54 +0200574 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700575
576 return 0;
577}
578
579
580static int ieee80211_ioctl_giwretry(struct net_device *dev,
581 struct iw_request_info *info,
582 struct iw_param *retry, char *extra)
583{
584 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
585
586 retry->disabled = 0;
587 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
588 /* first return min value, iwconfig will ask max value
589 * later if needed */
590 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200591 retry->value = local->hw.conf.short_frame_max_tx_count;
592 if (local->hw.conf.long_frame_max_tx_count !=
593 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700594 retry->flags |= IW_RETRY_MIN;
595 return 0;
596 }
597 if (retry->flags & IW_RETRY_MAX) {
598 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200599 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700600 }
601
602 return 0;
603}
604
Jiri Bencf0706e82007-05-05 11:45:53 -0700605static int ieee80211_ioctl_siwmlme(struct net_device *dev,
606 struct iw_request_info *info,
607 struct iw_point *data, char *extra)
608{
609 struct ieee80211_sub_if_data *sdata;
610 struct iw_mlme *mlme = (struct iw_mlme *) extra;
611
612 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100613 if (!(sdata->vif.type == NL80211_IFTYPE_STATION))
Jiri Bencf0706e82007-05-05 11:45:53 -0700614 return -EINVAL;
615
616 switch (mlme->cmd) {
617 case IW_MLME_DEAUTH:
618 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200619 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700620 case IW_MLME_DISASSOC:
621 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200622 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700623 default:
624 return -EOPNOTSUPP;
625 }
626}
627
628
629static int ieee80211_ioctl_siwencode(struct net_device *dev,
630 struct iw_request_info *info,
631 struct iw_point *erq, char *keybuf)
632{
633 struct ieee80211_sub_if_data *sdata;
634 int idx, i, alg = ALG_WEP;
635 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530636 int remove = 0, ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700637
638 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
639
640 idx = erq->flags & IW_ENCODE_INDEX;
641 if (idx == 0) {
642 if (sdata->default_key)
643 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
644 if (sdata->default_key == sdata->keys[i]) {
645 idx = i;
646 break;
647 }
648 }
649 } else if (idx < 1 || idx > 4)
650 return -EINVAL;
651 else
652 idx--;
653
654 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200655 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700656 else if (erq->length == 0) {
657 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400658 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700659 return 0;
660 }
661
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530662 ret = ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200663 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200664 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700665 !sdata->default_key,
666 keybuf, erq->length);
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530667
668 if (!ret) {
669 if (remove)
670 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
671 else
672 sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
673 }
674
675 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700676}
677
678
679static int ieee80211_ioctl_giwencode(struct net_device *dev,
680 struct iw_request_info *info,
681 struct iw_point *erq, char *key)
682{
683 struct ieee80211_sub_if_data *sdata;
684 int idx, i;
685
686 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
687
688 idx = erq->flags & IW_ENCODE_INDEX;
689 if (idx < 1 || idx > 4) {
690 idx = -1;
691 if (!sdata->default_key)
692 idx = 0;
693 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
694 if (sdata->default_key == sdata->keys[i]) {
695 idx = i;
696 break;
697 }
698 }
699 if (idx < 0)
700 return -EINVAL;
701 } else
702 idx--;
703
704 erq->flags = idx + 1;
705
706 if (!sdata->keys[idx]) {
707 erq->length = 0;
708 erq->flags |= IW_ENCODE_DISABLED;
709 return 0;
710 }
711
Johannes Berg8f20fc22007-08-28 17:01:54 -0400712 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400713 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400714 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700715 erq->flags |= IW_ENCODE_ENABLED;
716
Johannes Berg05c914f2008-09-11 00:01:58 +0200717 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berg46900292009-02-15 12:44:28 +0100718 switch (sdata->u.mgd.auth_alg) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300719 case WLAN_AUTH_OPEN:
720 case WLAN_AUTH_LEAP:
721 erq->flags |= IW_ENCODE_OPEN;
722 break;
723 case WLAN_AUTH_SHARED_KEY:
724 erq->flags |= IW_ENCODE_RESTRICTED;
725 break;
726 }
727 }
728
Jiri Bencf0706e82007-05-05 11:45:53 -0700729 return 0;
730}
731
Samuel Ortiz49292d52008-07-04 10:49:31 +0200732static int ieee80211_ioctl_siwpower(struct net_device *dev,
733 struct iw_request_info *info,
734 struct iw_param *wrq,
735 char *extra)
736{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200737 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200738 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
739 struct ieee80211_conf *conf = &local->hw.conf;
Kalle Valo520eb822008-12-18 23:35:27 +0200740 int ret = 0, timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200741 bool ps;
742
Johannes Berg4be8c382009-01-07 18:28:20 +0100743 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
744 return -EOPNOTSUPP;
745
Kalle Valoe0cb6862008-12-18 23:35:13 +0200746 if (sdata->vif.type != NL80211_IFTYPE_STATION)
747 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200748
749 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200750 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200751 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200752 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200753 }
754
755 switch (wrq->flags & IW_POWER_MODE) {
756 case IW_POWER_ON: /* If not specified */
757 case IW_POWER_MODE: /* If set all mask */
758 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200759 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200760 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200761 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100762 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200763 }
764
Johannes Berge9aeaba2009-01-06 18:12:35 +0100765 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
766 return -EINVAL;
767
Kalle Valo520eb822008-12-18 23:35:27 +0200768 if (wrq->flags & IW_POWER_TIMEOUT)
769 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200770
Johannes Berg4be8c382009-01-07 18:28:20 +0100771 set:
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100772 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
Kalle Valo520eb822008-12-18 23:35:27 +0200773 return ret;
774
Kalle Valoe0cb6862008-12-18 23:35:13 +0200775 local->powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100776 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200777
Johannes Berg4be8c382009-01-07 18:28:20 +0100778 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100779 ret = ieee80211_hw_config(local,
780 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
Johannes Berg4be8c382009-01-07 18:28:20 +0100781
Johannes Berg46900292009-02-15 12:44:28 +0100782 if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
Johannes Berg4be8c382009-01-07 18:28:20 +0100783 return ret;
784
785 if (conf->dynamic_ps_timeout > 0 &&
786 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
787 mod_timer(&local->dynamic_ps_timer, jiffies +
788 msecs_to_jiffies(conf->dynamic_ps_timeout));
789 } else {
790 if (local->powersave) {
791 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800792 ieee80211_send_nullfunc(local, sdata, 1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100793 conf->flags |= IEEE80211_CONF_PS;
794 ret = ieee80211_hw_config(local,
795 IEEE80211_CONF_CHANGE_PS);
796 } else {
797 conf->flags &= ~IEEE80211_CONF_PS;
798 ret = ieee80211_hw_config(local,
799 IEEE80211_CONF_CHANGE_PS);
800 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800801 ieee80211_send_nullfunc(local, sdata, 0);
Vivek Natarajanb8abde42009-01-27 19:26:28 +0530802 del_timer_sync(&local->dynamic_ps_timer);
803 cancel_work_sync(&local->dynamic_ps_enable_work);
Kalle Valo520eb822008-12-18 23:35:27 +0200804 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200805 }
806
807 return ret;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200808}
809
810static int ieee80211_ioctl_giwpower(struct net_device *dev,
811 struct iw_request_info *info,
812 union iwreq_data *wrqu,
813 char *extra)
814{
815 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200816
Kalle Valoe0cb6862008-12-18 23:35:13 +0200817 wrqu->power.disabled = !local->powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200818
819 return 0;
820}
821
Jiri Bencf0706e82007-05-05 11:45:53 -0700822static int ieee80211_ioctl_siwauth(struct net_device *dev,
823 struct iw_request_info *info,
824 struct iw_param *data, char *extra)
825{
Jiri Bencf0706e82007-05-05 11:45:53 -0700826 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
827 int ret = 0;
828
829 switch (data->flags & IW_AUTH_INDEX) {
830 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700831 case IW_AUTH_CIPHER_GROUP:
832 case IW_AUTH_WPA_ENABLED:
833 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700834 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200835 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000836 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530837 case IW_AUTH_CIPHER_PAIRWISE:
838 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
839 if (data->value & (IW_AUTH_CIPHER_WEP40 |
840 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100841 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530842 IEEE80211_STA_TKIP_WEP_USED;
843 else
Johannes Berg46900292009-02-15 12:44:28 +0100844 sdata->u.mgd.flags &=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530845 ~IEEE80211_STA_TKIP_WEP_USED;
846 }
847 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100848 case IW_AUTH_DROP_UNENCRYPTED:
849 sdata->drop_unencrypted = !!data->value;
850 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000851 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200852 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700853 ret = -EINVAL;
854 else {
Johannes Berg46900292009-02-15 12:44:28 +0100855 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700856 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000857 * Privacy invoked by wpa_supplicant, store the
858 * value and allow associating to a protected
859 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700860 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000861 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100862 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000863 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700864 }
865 break;
866 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100867 if (sdata->vif.type == NL80211_IFTYPE_STATION)
868 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700869 else
870 ret = -EOPNOTSUPP;
871 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200872 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200873 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
874 ret = -EOPNOTSUPP;
875 break;
876 }
Johannes Berg46900292009-02-15 12:44:28 +0100877 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100878 switch (data->value) {
879 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100880 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100881 break;
882 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100883 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100884 break;
885 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100886 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100887 break;
888 default:
889 ret = -EINVAL;
890 }
891 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200892 ret = -EOPNOTSUPP;
893 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700894 default:
895 ret = -EOPNOTSUPP;
896 break;
897 }
898 return ret;
899}
900
901/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
902static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
903{
904 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
905 struct iw_statistics *wstats = &local->wstats;
906 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
907 struct sta_info *sta = NULL;
908
Johannes Berg98dd6a52008-04-10 15:36:09 +0200909 rcu_read_lock();
910
Johannes Berg46900292009-02-15 12:44:28 +0100911 if (sdata->vif.type == NL80211_IFTYPE_STATION)
912 sta = sta_info_get(local, sdata->u.mgd.bssid);
913
Jiri Bencf0706e82007-05-05 11:45:53 -0700914 if (!sta) {
915 wstats->discard.fragment = 0;
916 wstats->discard.misc = 0;
917 wstats->qual.qual = 0;
918 wstats->qual.level = 0;
919 wstats->qual.noise = 0;
920 wstats->qual.updated = IW_QUAL_ALL_INVALID;
921 } else {
Johannes Berg24776cf2009-02-27 16:33:55 -0600922 wstats->qual.updated = 0;
923 /*
924 * mirror what cfg80211 does for iwrange/scan results,
925 * otherwise userspace gets confused.
926 */
927 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
928 IEEE80211_HW_SIGNAL_DBM)) {
929 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
930 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
931 } else {
932 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
933 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
934 }
935
936 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
937 wstats->qual.level = sta->last_signal;
938 wstats->qual.qual = sta->last_signal;
939 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
940 int sig = sta->last_signal;
941
942 wstats->qual.updated |= IW_QUAL_DBM;
943 wstats->qual.level = sig;
944 if (sig < -110)
945 sig = -110;
946 else if (sig > -40)
947 sig = -40;
948 wstats->qual.qual = sig + 110;
949 }
950
951 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
952 /*
953 * This assumes that if driver reports noise, it also
954 * reports signal in dBm.
955 */
956 wstats->qual.noise = sta->last_noise;
957 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
958 } else {
959 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
960 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700961 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200962
963 rcu_read_unlock();
964
Jiri Bencf0706e82007-05-05 11:45:53 -0700965 return wstats;
966}
967
968static int ieee80211_ioctl_giwauth(struct net_device *dev,
969 struct iw_request_info *info,
970 struct iw_param *data, char *extra)
971{
972 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
973 int ret = 0;
974
975 switch (data->flags & IW_AUTH_INDEX) {
976 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100977 if (sdata->vif.type == NL80211_IFTYPE_STATION)
978 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e82007-05-05 11:45:53 -0700979 else
980 ret = -EOPNOTSUPP;
981 break;
982 default:
983 ret = -EOPNOTSUPP;
984 break;
985 }
986 return ret;
987}
988
989
990static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
991 struct iw_request_info *info,
992 struct iw_point *erq, char *extra)
993{
994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
995 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +0200996 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700997
998 switch (ext->alg) {
999 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001000 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001001 break;
1002 case IW_ENCODE_ALG_WEP:
1003 alg = ALG_WEP;
1004 break;
1005 case IW_ENCODE_ALG_TKIP:
1006 alg = ALG_TKIP;
1007 break;
1008 case IW_ENCODE_ALG_CCMP:
1009 alg = ALG_CCMP;
1010 break;
Jouni Malinen22787db2009-01-08 13:32:04 +02001011 case IW_ENCODE_ALG_AES_CMAC:
1012 alg = ALG_AES_CMAC;
1013 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001014 default:
1015 return -EOPNOTSUPP;
1016 }
1017
1018 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001019 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001020
1021 idx = erq->flags & IW_ENCODE_INDEX;
Jouni Malinen22787db2009-01-08 13:32:04 +02001022 if (alg == ALG_AES_CMAC) {
1023 if (idx < NUM_DEFAULT_KEYS + 1 ||
1024 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1025 idx = -1;
1026 if (!sdata->default_mgmt_key)
1027 idx = 0;
1028 else for (i = NUM_DEFAULT_KEYS;
1029 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1030 i++) {
1031 if (sdata->default_mgmt_key == sdata->keys[i])
1032 {
1033 idx = i;
1034 break;
1035 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001036 }
Jouni Malinen22787db2009-01-08 13:32:04 +02001037 if (idx < 0)
1038 return -EINVAL;
1039 } else
1040 idx--;
1041 } else {
1042 if (idx < 1 || idx > 4) {
1043 idx = -1;
1044 if (!sdata->default_key)
1045 idx = 0;
1046 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1047 if (sdata->default_key == sdata->keys[i]) {
1048 idx = i;
1049 break;
1050 }
1051 }
1052 if (idx < 0)
1053 return -EINVAL;
1054 } else
1055 idx--;
1056 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001057
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001058 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001059 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001060 ext->ext_flags &
1061 IW_ENCODE_EXT_SET_TX_KEY,
1062 ext->key, ext->key_len);
1063}
1064
1065
Jiri Bencf0706e82007-05-05 11:45:53 -07001066/* Structures to export the Wireless Handlers */
1067
1068static const iw_handler ieee80211_handler[] =
1069{
1070 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001071 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001072 (iw_handler) NULL, /* SIOCSIWNWID */
1073 (iw_handler) NULL, /* SIOCGIWNWID */
1074 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1075 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001076 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1077 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001078 (iw_handler) NULL, /* SIOCSIWSENS */
1079 (iw_handler) NULL, /* SIOCGIWSENS */
1080 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
Johannes Berg4aa188e2009-02-18 19:32:08 +01001081 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001082 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1083 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1084 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1085 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001086 (iw_handler) NULL, /* SIOCSIWSPY */
1087 (iw_handler) NULL, /* SIOCGIWSPY */
1088 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1089 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001090 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1091 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1092 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1093 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +01001094 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1095 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e82007-05-05 11:45:53 -07001096 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1097 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1098 (iw_handler) NULL, /* SIOCSIWNICKN */
1099 (iw_handler) NULL, /* SIOCGIWNICKN */
1100 (iw_handler) NULL, /* -- hole -- */
1101 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001102 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001103 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001104 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1105 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1106 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1107 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001108 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001109 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001110 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1111 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1112 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1113 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001114 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1115 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001116 (iw_handler) NULL, /* -- hole -- */
1117 (iw_handler) NULL, /* -- hole -- */
1118 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1119 (iw_handler) NULL, /* SIOCGIWGENIE */
1120 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1121 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1122 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1123 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1124 (iw_handler) NULL, /* SIOCSIWPMKSA */
1125 (iw_handler) NULL, /* -- hole -- */
1126};
1127
Jiri Bencf0706e82007-05-05 11:45:53 -07001128const struct iw_handler_def ieee80211_iw_handler_def =
1129{
1130 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001131 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001132 .get_wireless_stats = ieee80211_get_wireless_stats,
1133};