blob: e55d2834764c5f528ca10ea0626a019316074ba4 [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;
140 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700141 return 0;
142 }
143
Jiri Bencf0706e82007-05-05 11:45:53 -0700144 return -EOPNOTSUPP;
145}
146
Jiri Bencf0706e82007-05-05 11:45:53 -0700147static int ieee80211_ioctl_siwfreq(struct net_device *dev,
148 struct iw_request_info *info,
149 struct iw_freq *freq, char *extra)
150{
Jiri Bencf0706e82007-05-05 11:45:53 -0700151 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
152
Johannes Berg46900292009-02-15 12:44:28 +0100153 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
154 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL;
155 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
156 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700157
158 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
159 if (freq->e == 0) {
160 if (freq->m < 0) {
Johannes Berg46900292009-02-15 12:44:28 +0100161 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
162 sdata->u.ibss.flags |=
163 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
164 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
165 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400166 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700167 return 0;
168 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200169 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100170 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700171 } else {
172 int i, div = 1000000;
173 for (i = 0; i < freq->e; i++)
174 div /= 10;
175 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200176 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700177 else
178 return -EINVAL;
179 }
180}
181
182
183static int ieee80211_ioctl_giwfreq(struct net_device *dev,
184 struct iw_request_info *info,
185 struct iw_freq *freq, char *extra)
186{
187 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
188
Johannes Berg8318d782008-01-24 19:38:38 +0100189 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700190 freq->e = 6;
191
192 return 0;
193}
194
195
196static int ieee80211_ioctl_siwessid(struct net_device *dev,
197 struct iw_request_info *info,
198 struct iw_point *data, char *ssid)
199{
Jiri Bencf0706e82007-05-05 11:45:53 -0700200 struct ieee80211_sub_if_data *sdata;
201 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100202 int ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700203
204 /* iwconfig uses nul termination in SSID.. */
205 if (len > 0 && ssid[len - 1] == '\0')
206 len--;
207
208 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100209 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200210 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700211 if (len > IEEE80211_MAX_SSID_LEN)
212 return -EINVAL;
Johannes Berg46900292009-02-15 12:44:28 +0100213 memcpy(sdata->u.mgd.ssid, ssid, len);
214 sdata->u.mgd.ssid_len = len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700215 return 0;
216 }
Johannes Berg46900292009-02-15 12:44:28 +0100217
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400218 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100219 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400220 else
Johannes Berg46900292009-02-15 12:44:28 +0100221 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
222
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200223 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700224 if (ret)
225 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100226
227 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700228 return 0;
Johannes Berg46900292009-02-15 12:44:28 +0100229 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
230 return ieee80211_ibss_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700231
Jiri Bencf0706e82007-05-05 11:45:53 -0700232 return -EOPNOTSUPP;
233}
234
235
236static int ieee80211_ioctl_giwessid(struct net_device *dev,
237 struct iw_request_info *info,
238 struct iw_point *data, char *ssid)
239{
240 size_t len;
241
242 struct ieee80211_sub_if_data *sdata;
243 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100244 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200245 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700246 if (res == 0) {
247 data->length = len;
248 data->flags = 1;
249 } else
250 data->flags = 0;
251 return res;
Johannes Berg46900292009-02-15 12:44:28 +0100252 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
253 int res = ieee80211_ibss_get_ssid(sdata, ssid, &len);
254 if (res == 0) {
255 data->length = len;
256 data->flags = 1;
257 } else
258 data->flags = 0;
259 return res;
Jiri Bencf0706e82007-05-05 11:45:53 -0700260 }
261
Jiri Bencf0706e82007-05-05 11:45:53 -0700262 return -EOPNOTSUPP;
263}
264
265
266static int ieee80211_ioctl_siwap(struct net_device *dev,
267 struct iw_request_info *info,
268 struct sockaddr *ap_addr, char *extra)
269{
Jiri Bencf0706e82007-05-05 11:45:53 -0700270 struct ieee80211_sub_if_data *sdata;
271
272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100273 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700274 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200275 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Johannes Berg46900292009-02-15 12:44:28 +0100276 memcpy(sdata->u.mgd.bssid, (u8 *) &ap_addr->sa_data,
Jiri Bencf0706e82007-05-05 11:45:53 -0700277 ETH_ALEN);
278 return 0;
279 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400280 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100281 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400282 IEEE80211_STA_AUTO_CHANNEL_SEL;
283 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100284 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700285 else
Johannes Berg46900292009-02-15 12:44:28 +0100286 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200287 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700288 if (ret)
289 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100290 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700291 return 0;
Johannes Berg46900292009-02-15 12:44:28 +0100292 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
293 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
294 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
295 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
296 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
297 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL;
298 else
299 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL;
300
301 return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Johannes Berg05c914f2008-09-11 00:01:58 +0200302 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100303 /*
304 * If it is necessary to update the WDS peer address
305 * while the interface is running, then we need to do
306 * more work here, namely if it is running we need to
307 * add a new and remove the old STA entry, this is
308 * normally handled by _open() and _stop().
309 */
310 if (netif_running(dev))
311 return -EBUSY;
312
313 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
314 ETH_ALEN);
315
316 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700317 }
318
319 return -EOPNOTSUPP;
320}
321
322
323static int ieee80211_ioctl_giwap(struct net_device *dev,
324 struct iw_request_info *info,
325 struct sockaddr *ap_addr, char *extra)
326{
327 struct ieee80211_sub_if_data *sdata;
328
329 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100330 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
331 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700332 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100333 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
334 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700335 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100336 return 0;
337 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
338 if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) {
339 ap_addr->sa_family = ARPHRD_ETHER;
340 memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN);
341 } else
342 memset(&ap_addr->sa_data, 0, ETH_ALEN);
343 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200344 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700345 ap_addr->sa_family = ARPHRD_ETHER;
346 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
347 return 0;
348 }
349
350 return -EOPNOTSUPP;
351}
352
353
Larry Finger1fd5e582007-07-10 19:32:10 +0200354static int ieee80211_ioctl_siwrate(struct net_device *dev,
355 struct iw_request_info *info,
356 struct iw_param *rate, char *extra)
357{
358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100359 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200360 u32 target_rate = rate->value / 100000;
361 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100362 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200363
364 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100365
366 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
367
Larry Finger1fd5e582007-07-10 19:32:10 +0200368 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
369 * target_rate = X, rate->fixed = 1 means only rate X
370 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200371 sdata->max_ratectrl_rateidx = -1;
372 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200373 if (rate->value < 0)
374 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100375
376 for (i=0; i< sband->n_bitrates; i++) {
377 struct ieee80211_rate *brate = &sband->bitrates[i];
378 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200379
Larry Finger1fd5e582007-07-10 19:32:10 +0200380 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200381 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200382 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200383 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100384 err = 0;
385 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200386 }
387 }
Johannes Berg8318d782008-01-24 19:38:38 +0100388 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200389}
390
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700391static int ieee80211_ioctl_giwrate(struct net_device *dev,
392 struct iw_request_info *info,
393 struct iw_param *rate, char *extra)
394{
395 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
396 struct sta_info *sta;
397 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100398 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700399
400 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100401
Johannes Berg05c914f2008-09-11 00:01:58 +0200402 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700403 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100404
405 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
406
Johannes Berg380a9422008-04-04 23:40:35 +0200407 rcu_read_lock();
408
Johannes Berg46900292009-02-15 12:44:28 +0100409 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200410
Johannes Berge6a98542008-10-21 12:40:02 +0200411 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
412 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700413 else
414 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200415
416 rcu_read_unlock();
417
418 if (!sta)
419 return -ENODEV;
420
Johannes Berg8318d782008-01-24 19:38:38 +0100421 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100422
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700423 return 0;
424}
425
Michael Buesch61609bc2007-09-20 22:06:39 +0200426static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
427 struct iw_request_info *info,
428 union iwreq_data *data, char *extra)
429{
430 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700431 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200432 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100433 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200434
435 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
436 return -EINVAL;
437 if (data->txpower.flags & IW_TXPOW_RANGE)
438 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700439 if (!chan)
440 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200441
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700442 if (data->txpower.fixed)
443 new_power_level = min(data->txpower.value, chan->max_power);
444 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100445 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200446
Johannes Berg2bf30fa2009-01-06 23:23:56 +0100447 local->user_power_level = new_power_level;
Vasanthakumar Thiagarajane3c92df2008-12-24 13:53:11 +0530448 if (local->hw.conf.power_level != new_power_level)
Johannes Berge8975582008-10-09 12:18:51 +0200449 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Mattias Nissler6a432952007-10-24 23:30:36 +0200450
Michael Buesch61609bc2007-09-20 22:06:39 +0200451 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
452 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200453 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100454 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200455 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200456
Johannes Berge8975582008-10-09 12:18:51 +0200457 if (reconf_flags)
458 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200459
460 return 0;
461}
462
Larry Fingerfe6aa302007-08-10 11:23:20 -0500463static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
464 struct iw_request_info *info,
465 union iwreq_data *data, char *extra)
466{
467 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
468
469 data->txpower.fixed = 1;
470 data->txpower.disabled = !(local->hw.conf.radio_enabled);
471 data->txpower.value = local->hw.conf.power_level;
472 data->txpower.flags = IW_TXPOW_DBM;
473
474 return 0;
475}
476
Jiri Bencf0706e82007-05-05 11:45:53 -0700477static int ieee80211_ioctl_siwrts(struct net_device *dev,
478 struct iw_request_info *info,
479 struct iw_param *rts, char *extra)
480{
481 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
482
483 if (rts->disabled)
484 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300485 else if (!rts->fixed)
486 /* if the rts value is not fixed, then take default */
487 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700488 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
489 return -EINVAL;
490 else
491 local->rts_threshold = rts->value;
492
493 /* If the wlan card performs RTS/CTS in hardware/firmware,
494 * configure it here */
495
496 if (local->ops->set_rts_threshold)
497 local->ops->set_rts_threshold(local_to_hw(local),
498 local->rts_threshold);
499
500 return 0;
501}
502
503static int ieee80211_ioctl_giwrts(struct net_device *dev,
504 struct iw_request_info *info,
505 struct iw_param *rts, char *extra)
506{
507 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
508
509 rts->value = local->rts_threshold;
510 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
511 rts->fixed = 1;
512
513 return 0;
514}
515
516
517static int ieee80211_ioctl_siwfrag(struct net_device *dev,
518 struct iw_request_info *info,
519 struct iw_param *frag, char *extra)
520{
521 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
522
523 if (frag->disabled)
524 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300525 else if (!frag->fixed)
526 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700527 else if (frag->value < 256 ||
528 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
529 return -EINVAL;
530 else {
531 /* Fragment length must be even, so strip LSB. */
532 local->fragmentation_threshold = frag->value & ~0x1;
533 }
534
Jiri Bencf0706e82007-05-05 11:45:53 -0700535 return 0;
536}
537
538static int ieee80211_ioctl_giwfrag(struct net_device *dev,
539 struct iw_request_info *info,
540 struct iw_param *frag, char *extra)
541{
542 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
543
544 frag->value = local->fragmentation_threshold;
545 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
546 frag->fixed = 1;
547
548 return 0;
549}
550
551
552static int ieee80211_ioctl_siwretry(struct net_device *dev,
553 struct iw_request_info *info,
554 struct iw_param *retry, char *extra)
555{
556 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
557
558 if (retry->disabled ||
559 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
560 return -EINVAL;
561
Johannes Berg9124b072008-10-14 19:17:54 +0200562 if (retry->flags & IW_RETRY_MAX) {
563 local->hw.conf.long_frame_max_tx_count = retry->value;
564 } else if (retry->flags & IW_RETRY_MIN) {
565 local->hw.conf.short_frame_max_tx_count = retry->value;
566 } else {
567 local->hw.conf.long_frame_max_tx_count = retry->value;
568 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700569 }
570
Johannes Berg9124b072008-10-14 19:17:54 +0200571 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700572
573 return 0;
574}
575
576
577static int ieee80211_ioctl_giwretry(struct net_device *dev,
578 struct iw_request_info *info,
579 struct iw_param *retry, char *extra)
580{
581 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
582
583 retry->disabled = 0;
584 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
585 /* first return min value, iwconfig will ask max value
586 * later if needed */
587 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200588 retry->value = local->hw.conf.short_frame_max_tx_count;
589 if (local->hw.conf.long_frame_max_tx_count !=
590 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700591 retry->flags |= IW_RETRY_MIN;
592 return 0;
593 }
594 if (retry->flags & IW_RETRY_MAX) {
595 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200596 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700597 }
598
599 return 0;
600}
601
Jiri Bencf0706e82007-05-05 11:45:53 -0700602static int ieee80211_ioctl_siwmlme(struct net_device *dev,
603 struct iw_request_info *info,
604 struct iw_point *data, char *extra)
605{
606 struct ieee80211_sub_if_data *sdata;
607 struct iw_mlme *mlme = (struct iw_mlme *) extra;
608
609 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100610 if (!(sdata->vif.type == NL80211_IFTYPE_STATION))
Jiri Bencf0706e82007-05-05 11:45:53 -0700611 return -EINVAL;
612
613 switch (mlme->cmd) {
614 case IW_MLME_DEAUTH:
615 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200616 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700617 case IW_MLME_DISASSOC:
618 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200619 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700620 default:
621 return -EOPNOTSUPP;
622 }
623}
624
625
626static int ieee80211_ioctl_siwencode(struct net_device *dev,
627 struct iw_request_info *info,
628 struct iw_point *erq, char *keybuf)
629{
630 struct ieee80211_sub_if_data *sdata;
631 int idx, i, alg = ALG_WEP;
632 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530633 int remove = 0, ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700634
635 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
636
637 idx = erq->flags & IW_ENCODE_INDEX;
638 if (idx == 0) {
639 if (sdata->default_key)
640 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
641 if (sdata->default_key == sdata->keys[i]) {
642 idx = i;
643 break;
644 }
645 }
646 } else if (idx < 1 || idx > 4)
647 return -EINVAL;
648 else
649 idx--;
650
651 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200652 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700653 else if (erq->length == 0) {
654 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400655 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700656 return 0;
657 }
658
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530659 ret = ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200660 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200661 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700662 !sdata->default_key,
663 keybuf, erq->length);
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530664
665 if (!ret) {
666 if (remove)
667 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
668 else
669 sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
670 }
671
672 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700673}
674
675
676static int ieee80211_ioctl_giwencode(struct net_device *dev,
677 struct iw_request_info *info,
678 struct iw_point *erq, char *key)
679{
680 struct ieee80211_sub_if_data *sdata;
681 int idx, i;
682
683 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
684
685 idx = erq->flags & IW_ENCODE_INDEX;
686 if (idx < 1 || idx > 4) {
687 idx = -1;
688 if (!sdata->default_key)
689 idx = 0;
690 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
691 if (sdata->default_key == sdata->keys[i]) {
692 idx = i;
693 break;
694 }
695 }
696 if (idx < 0)
697 return -EINVAL;
698 } else
699 idx--;
700
701 erq->flags = idx + 1;
702
703 if (!sdata->keys[idx]) {
704 erq->length = 0;
705 erq->flags |= IW_ENCODE_DISABLED;
706 return 0;
707 }
708
Johannes Berg8f20fc22007-08-28 17:01:54 -0400709 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400710 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400711 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700712 erq->flags |= IW_ENCODE_ENABLED;
713
Johannes Berg05c914f2008-09-11 00:01:58 +0200714 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berg46900292009-02-15 12:44:28 +0100715 switch (sdata->u.mgd.auth_alg) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300716 case WLAN_AUTH_OPEN:
717 case WLAN_AUTH_LEAP:
718 erq->flags |= IW_ENCODE_OPEN;
719 break;
720 case WLAN_AUTH_SHARED_KEY:
721 erq->flags |= IW_ENCODE_RESTRICTED;
722 break;
723 }
724 }
725
Jiri Bencf0706e82007-05-05 11:45:53 -0700726 return 0;
727}
728
Samuel Ortiz49292d52008-07-04 10:49:31 +0200729static int ieee80211_ioctl_siwpower(struct net_device *dev,
730 struct iw_request_info *info,
731 struct iw_param *wrq,
732 char *extra)
733{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200734 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200735 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
736 struct ieee80211_conf *conf = &local->hw.conf;
Kalle Valo520eb822008-12-18 23:35:27 +0200737 int ret = 0, timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200738 bool ps;
739
Johannes Berg4be8c382009-01-07 18:28:20 +0100740 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
741 return -EOPNOTSUPP;
742
Kalle Valoe0cb6862008-12-18 23:35:13 +0200743 if (sdata->vif.type != NL80211_IFTYPE_STATION)
744 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200745
746 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200747 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200748 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200749 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200750 }
751
752 switch (wrq->flags & IW_POWER_MODE) {
753 case IW_POWER_ON: /* If not specified */
754 case IW_POWER_MODE: /* If set all mask */
755 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200756 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200757 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200758 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100759 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200760 }
761
Johannes Berge9aeaba2009-01-06 18:12:35 +0100762 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
763 return -EINVAL;
764
Kalle Valo520eb822008-12-18 23:35:27 +0200765 if (wrq->flags & IW_POWER_TIMEOUT)
766 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200767
Johannes Berg4be8c382009-01-07 18:28:20 +0100768 set:
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100769 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
Kalle Valo520eb822008-12-18 23:35:27 +0200770 return ret;
771
Kalle Valoe0cb6862008-12-18 23:35:13 +0200772 local->powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100773 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200774
Johannes Berg4be8c382009-01-07 18:28:20 +0100775 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100776 ret = ieee80211_hw_config(local,
777 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
Johannes Berg4be8c382009-01-07 18:28:20 +0100778
Johannes Berg46900292009-02-15 12:44:28 +0100779 if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
Johannes Berg4be8c382009-01-07 18:28:20 +0100780 return ret;
781
782 if (conf->dynamic_ps_timeout > 0 &&
783 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
784 mod_timer(&local->dynamic_ps_timer, jiffies +
785 msecs_to_jiffies(conf->dynamic_ps_timeout));
786 } else {
787 if (local->powersave) {
788 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800789 ieee80211_send_nullfunc(local, sdata, 1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100790 conf->flags |= IEEE80211_CONF_PS;
791 ret = ieee80211_hw_config(local,
792 IEEE80211_CONF_CHANGE_PS);
793 } else {
794 conf->flags &= ~IEEE80211_CONF_PS;
795 ret = ieee80211_hw_config(local,
796 IEEE80211_CONF_CHANGE_PS);
797 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800798 ieee80211_send_nullfunc(local, sdata, 0);
Vivek Natarajanb8abde42009-01-27 19:26:28 +0530799 del_timer_sync(&local->dynamic_ps_timer);
800 cancel_work_sync(&local->dynamic_ps_enable_work);
Kalle Valo520eb822008-12-18 23:35:27 +0200801 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200802 }
803
804 return ret;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200805}
806
807static int ieee80211_ioctl_giwpower(struct net_device *dev,
808 struct iw_request_info *info,
809 union iwreq_data *wrqu,
810 char *extra)
811{
812 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200813
Kalle Valoe0cb6862008-12-18 23:35:13 +0200814 wrqu->power.disabled = !local->powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200815
816 return 0;
817}
818
Jiri Bencf0706e82007-05-05 11:45:53 -0700819static int ieee80211_ioctl_siwauth(struct net_device *dev,
820 struct iw_request_info *info,
821 struct iw_param *data, char *extra)
822{
Jiri Bencf0706e82007-05-05 11:45:53 -0700823 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
824 int ret = 0;
825
826 switch (data->flags & IW_AUTH_INDEX) {
827 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700828 case IW_AUTH_CIPHER_GROUP:
829 case IW_AUTH_WPA_ENABLED:
830 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700831 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200832 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000833 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530834 case IW_AUTH_CIPHER_PAIRWISE:
835 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
836 if (data->value & (IW_AUTH_CIPHER_WEP40 |
837 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100838 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530839 IEEE80211_STA_TKIP_WEP_USED;
840 else
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 }
844 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100845 case IW_AUTH_DROP_UNENCRYPTED:
846 sdata->drop_unencrypted = !!data->value;
847 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000848 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200849 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700850 ret = -EINVAL;
851 else {
Johannes Berg46900292009-02-15 12:44:28 +0100852 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700853 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000854 * Privacy invoked by wpa_supplicant, store the
855 * value and allow associating to a protected
856 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700857 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000858 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100859 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000860 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700861 }
862 break;
863 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100864 if (sdata->vif.type == NL80211_IFTYPE_STATION)
865 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700866 else
867 ret = -EOPNOTSUPP;
868 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200869 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200870 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
871 ret = -EOPNOTSUPP;
872 break;
873 }
Johannes Berg46900292009-02-15 12:44:28 +0100874 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100875 switch (data->value) {
876 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100877 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100878 break;
879 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100880 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100881 break;
882 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100883 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100884 break;
885 default:
886 ret = -EINVAL;
887 }
888 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200889 ret = -EOPNOTSUPP;
890 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700891 default:
892 ret = -EOPNOTSUPP;
893 break;
894 }
895 return ret;
896}
897
898/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
899static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
900{
901 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
902 struct iw_statistics *wstats = &local->wstats;
903 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
904 struct sta_info *sta = NULL;
905
Johannes Berg98dd6a52008-04-10 15:36:09 +0200906 rcu_read_lock();
907
Johannes Berg46900292009-02-15 12:44:28 +0100908 if (sdata->vif.type == NL80211_IFTYPE_STATION)
909 sta = sta_info_get(local, sdata->u.mgd.bssid);
910
Jiri Bencf0706e82007-05-05 11:45:53 -0700911 if (!sta) {
912 wstats->discard.fragment = 0;
913 wstats->discard.misc = 0;
914 wstats->qual.qual = 0;
915 wstats->qual.level = 0;
916 wstats->qual.noise = 0;
917 wstats->qual.updated = IW_QUAL_ALL_INVALID;
918 } else {
Johannes Berg24776cf2009-02-27 16:33:55 -0600919 wstats->qual.updated = 0;
920 /*
921 * mirror what cfg80211 does for iwrange/scan results,
922 * otherwise userspace gets confused.
923 */
924 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
925 IEEE80211_HW_SIGNAL_DBM)) {
926 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
927 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
928 } else {
929 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
930 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
931 }
932
933 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
934 wstats->qual.level = sta->last_signal;
935 wstats->qual.qual = sta->last_signal;
936 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
937 int sig = sta->last_signal;
938
939 wstats->qual.updated |= IW_QUAL_DBM;
940 wstats->qual.level = sig;
941 if (sig < -110)
942 sig = -110;
943 else if (sig > -40)
944 sig = -40;
945 wstats->qual.qual = sig + 110;
946 }
947
948 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
949 /*
950 * This assumes that if driver reports noise, it also
951 * reports signal in dBm.
952 */
953 wstats->qual.noise = sta->last_noise;
954 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
955 } else {
956 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
957 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700958 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200959
960 rcu_read_unlock();
961
Jiri Bencf0706e82007-05-05 11:45:53 -0700962 return wstats;
963}
964
965static int ieee80211_ioctl_giwauth(struct net_device *dev,
966 struct iw_request_info *info,
967 struct iw_param *data, char *extra)
968{
969 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
970 int ret = 0;
971
972 switch (data->flags & IW_AUTH_INDEX) {
973 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100974 if (sdata->vif.type == NL80211_IFTYPE_STATION)
975 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e82007-05-05 11:45:53 -0700976 else
977 ret = -EOPNOTSUPP;
978 break;
979 default:
980 ret = -EOPNOTSUPP;
981 break;
982 }
983 return ret;
984}
985
986
987static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
988 struct iw_request_info *info,
989 struct iw_point *erq, char *extra)
990{
991 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
992 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +0200993 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700994
995 switch (ext->alg) {
996 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +0200997 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700998 break;
999 case IW_ENCODE_ALG_WEP:
1000 alg = ALG_WEP;
1001 break;
1002 case IW_ENCODE_ALG_TKIP:
1003 alg = ALG_TKIP;
1004 break;
1005 case IW_ENCODE_ALG_CCMP:
1006 alg = ALG_CCMP;
1007 break;
Jouni Malinen22787db2009-01-08 13:32:04 +02001008 case IW_ENCODE_ALG_AES_CMAC:
1009 alg = ALG_AES_CMAC;
1010 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001011 default:
1012 return -EOPNOTSUPP;
1013 }
1014
1015 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001016 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001017
1018 idx = erq->flags & IW_ENCODE_INDEX;
Jouni Malinen22787db2009-01-08 13:32:04 +02001019 if (alg == ALG_AES_CMAC) {
1020 if (idx < NUM_DEFAULT_KEYS + 1 ||
1021 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1022 idx = -1;
1023 if (!sdata->default_mgmt_key)
1024 idx = 0;
1025 else for (i = NUM_DEFAULT_KEYS;
1026 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1027 i++) {
1028 if (sdata->default_mgmt_key == sdata->keys[i])
1029 {
1030 idx = i;
1031 break;
1032 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001033 }
Jouni Malinen22787db2009-01-08 13:32:04 +02001034 if (idx < 0)
1035 return -EINVAL;
1036 } else
1037 idx--;
1038 } else {
1039 if (idx < 1 || idx > 4) {
1040 idx = -1;
1041 if (!sdata->default_key)
1042 idx = 0;
1043 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1044 if (sdata->default_key == sdata->keys[i]) {
1045 idx = i;
1046 break;
1047 }
1048 }
1049 if (idx < 0)
1050 return -EINVAL;
1051 } else
1052 idx--;
1053 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001054
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001055 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001056 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001057 ext->ext_flags &
1058 IW_ENCODE_EXT_SET_TX_KEY,
1059 ext->key, ext->key_len);
1060}
1061
1062
Jiri Bencf0706e82007-05-05 11:45:53 -07001063/* Structures to export the Wireless Handlers */
1064
1065static const iw_handler ieee80211_handler[] =
1066{
1067 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001068 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001069 (iw_handler) NULL, /* SIOCSIWNWID */
1070 (iw_handler) NULL, /* SIOCGIWNWID */
1071 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1072 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001073 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1074 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001075 (iw_handler) NULL, /* SIOCSIWSENS */
1076 (iw_handler) NULL, /* SIOCGIWSENS */
1077 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
Johannes Berg4aa188e2009-02-18 19:32:08 +01001078 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001079 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1080 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1081 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1082 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001083 (iw_handler) NULL, /* SIOCSIWSPY */
1084 (iw_handler) NULL, /* SIOCGIWSPY */
1085 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1086 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001087 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1088 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1089 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1090 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +01001091 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1092 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e82007-05-05 11:45:53 -07001093 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1094 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1095 (iw_handler) NULL, /* SIOCSIWNICKN */
1096 (iw_handler) NULL, /* SIOCGIWNICKN */
1097 (iw_handler) NULL, /* -- hole -- */
1098 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001099 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001100 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001101 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1102 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1103 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1104 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001105 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001106 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001107 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1108 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1109 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1110 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001111 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1112 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001113 (iw_handler) NULL, /* -- hole -- */
1114 (iw_handler) NULL, /* -- hole -- */
1115 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1116 (iw_handler) NULL, /* SIOCGIWGENIE */
1117 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1118 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1119 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1120 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1121 (iw_handler) NULL, /* SIOCSIWPMKSA */
1122 (iw_handler) NULL, /* -- hole -- */
1123};
1124
Jiri Bencf0706e82007-05-05 11:45:53 -07001125const struct iw_handler_def ieee80211_iw_handler_def =
1126{
1127 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001128 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001129 .get_wireless_stats = ieee80211_get_wireless_stats,
1130};