blob: b337d7d5edb3b21dfebb365ac3ae825f77a6ad90 [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 Malinen22787dba2009-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 Malinen22787dba2009-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 Berg05c914f2008-09-11 00:01:58 +0200135 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
136 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200137 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700138 if (ret)
139 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400140 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200141 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
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_giwrange(struct net_device *dev,
149 struct iw_request_info *info,
150 struct iw_point *data, char *extra)
151{
152 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
153 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100154 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200155 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700156
157 data->length = sizeof(struct iw_range);
158 memset(range, 0, sizeof(struct iw_range));
159
160 range->we_version_compiled = WIRELESS_EXT;
161 range->we_version_source = 21;
162 range->retry_capa = IW_RETRY_LIMIT;
163 range->retry_flags = IW_RETRY_LIMIT;
164 range->min_retry = 0;
165 range->max_retry = 255;
166 range->min_rts = 0;
167 range->max_rts = 2347;
168 range->min_frag = 256;
169 range->max_frag = 2346;
170
171 range->encoding_size[0] = 5;
172 range->encoding_size[1] = 13;
173 range->num_encoding_sizes = 2;
174 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
175
Johannes Berg2a519312009-02-10 21:25:55 +0100176 /* cfg80211 requires this, and enforces 0..100 */
Johannes Berg7fee5372009-01-30 11:13:06 +0100177 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
Johannes Berg2a519312009-02-10 21:25:55 +0100178 range->max_qual.level = 100;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200179 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
180 range->max_qual.level = -110;
181 else
182 range->max_qual.level = 0;
183
184 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
185 range->max_qual.noise = -110;
186 else
187 range->max_qual.noise = 0;
188
189 range->max_qual.qual = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700190 range->max_qual.updated = local->wstats_flags;
191
Bruno Randolf566bfe52008-05-08 19:15:40 +0200192 range->avg_qual.qual = 50;
193 /* not always true but better than nothing */
194 range->avg_qual.level = range->max_qual.level / 2;
195 range->avg_qual.noise = range->max_qual.noise / 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700196 range->avg_qual.updated = local->wstats_flags;
197
198 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
199 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
200
Hong Liu333af2f2007-07-10 19:32:08 +0200201
Johannes Berg8318d782008-01-24 19:38:38 +0100202 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
203 int i;
204 struct ieee80211_supported_band *sband;
205
206 sband = local->hw.wiphy->bands[band];
207
208 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200209 continue;
210
Johannes Berg8318d782008-01-24 19:38:38 +0100211 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
212 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200213
Johannes Berg8318d782008-01-24 19:38:38 +0100214 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
215 range->freq[c].i =
216 ieee80211_frequency_to_channel(
217 chan->center_freq);
218 range->freq[c].m = chan->center_freq;
219 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200220 c++;
221 }
Hong Liu333af2f2007-07-10 19:32:08 +0200222 }
223 }
224 range->num_channels = c;
225 range->num_frequency = c;
226
Jiri Bencf0706e82007-05-05 11:45:53 -0700227 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700228 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
229 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
230
Dan Williams374fdfb2007-12-12 10:25:07 -0500231 range->scan_capa |= IW_SCAN_CAPA_ESSID;
232
Jiri Bencf0706e82007-05-05 11:45:53 -0700233 return 0;
234}
235
236
Jiri Bencf0706e82007-05-05 11:45:53 -0700237static int ieee80211_ioctl_siwfreq(struct net_device *dev,
238 struct iw_request_info *info,
239 struct iw_freq *freq, char *extra)
240{
Jiri Bencf0706e82007-05-05 11:45:53 -0700241 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
242
Alina Friedrichsenb522ed52009-01-06 03:15:23 +0100243 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
244 sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400245 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700246
247 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
248 if (freq->e == 0) {
249 if (freq->m < 0) {
Alina Friedrichsenb522ed52009-01-06 03:15:23 +0100250 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
251 sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400252 sdata->u.sta.flags |=
253 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700254 return 0;
255 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200256 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100257 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700258 } else {
259 int i, div = 1000000;
260 for (i = 0; i < freq->e; i++)
261 div /= 10;
262 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200263 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700264 else
265 return -EINVAL;
266 }
267}
268
269
270static int ieee80211_ioctl_giwfreq(struct net_device *dev,
271 struct iw_request_info *info,
272 struct iw_freq *freq, char *extra)
273{
274 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
275
Johannes Berg8318d782008-01-24 19:38:38 +0100276 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700277 freq->e = 6;
278
279 return 0;
280}
281
282
283static int ieee80211_ioctl_siwessid(struct net_device *dev,
284 struct iw_request_info *info,
285 struct iw_point *data, char *ssid)
286{
Jiri Bencf0706e82007-05-05 11:45:53 -0700287 struct ieee80211_sub_if_data *sdata;
288 size_t len = data->length;
289
290 /* iwconfig uses nul termination in SSID.. */
291 if (len > 0 && ssid[len - 1] == '\0')
292 len--;
293
294 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200295 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
296 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700297 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200298 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700299 if (len > IEEE80211_MAX_SSID_LEN)
300 return -EINVAL;
301 memcpy(sdata->u.sta.ssid, ssid, len);
302 sdata->u.sta.ssid_len = len;
303 return 0;
304 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400305 if (data->flags)
306 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
307 else
308 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200309 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700310 if (ret)
311 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200312 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700313 return 0;
314 }
315
Jiri Bencf0706e82007-05-05 11:45:53 -0700316 return -EOPNOTSUPP;
317}
318
319
320static int ieee80211_ioctl_giwessid(struct net_device *dev,
321 struct iw_request_info *info,
322 struct iw_point *data, char *ssid)
323{
324 size_t len;
325
326 struct ieee80211_sub_if_data *sdata;
327 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200328 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
329 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200330 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700331 if (res == 0) {
332 data->length = len;
333 data->flags = 1;
334 } else
335 data->flags = 0;
336 return res;
337 }
338
Jiri Bencf0706e82007-05-05 11:45:53 -0700339 return -EOPNOTSUPP;
340}
341
342
343static int ieee80211_ioctl_siwap(struct net_device *dev,
344 struct iw_request_info *info,
345 struct sockaddr *ap_addr, char *extra)
346{
Jiri Bencf0706e82007-05-05 11:45:53 -0700347 struct ieee80211_sub_if_data *sdata;
348
349 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200350 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
351 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700352 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200353 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700354 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
355 ETH_ALEN);
356 return 0;
357 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400358 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
359 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
360 IEEE80211_STA_AUTO_CHANNEL_SEL;
361 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
362 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700363 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400364 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200365 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700366 if (ret)
367 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200368 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700369 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200370 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100371 /*
372 * If it is necessary to update the WDS peer address
373 * while the interface is running, then we need to do
374 * more work here, namely if it is running we need to
375 * add a new and remove the old STA entry, this is
376 * normally handled by _open() and _stop().
377 */
378 if (netif_running(dev))
379 return -EBUSY;
380
381 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
382 ETH_ALEN);
383
384 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700385 }
386
387 return -EOPNOTSUPP;
388}
389
390
391static int ieee80211_ioctl_giwap(struct net_device *dev,
392 struct iw_request_info *info,
393 struct sockaddr *ap_addr, char *extra)
394{
395 struct ieee80211_sub_if_data *sdata;
396
397 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200398 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
399 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300400 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
401 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700402 ap_addr->sa_family = ARPHRD_ETHER;
403 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
404 return 0;
405 } else {
406 memset(&ap_addr->sa_data, 0, ETH_ALEN);
407 return 0;
408 }
Johannes Berg05c914f2008-09-11 00:01:58 +0200409 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700410 ap_addr->sa_family = ARPHRD_ETHER;
411 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
412 return 0;
413 }
414
415 return -EOPNOTSUPP;
416}
417
418
Larry Finger1fd5e582007-07-10 19:32:10 +0200419static int ieee80211_ioctl_siwrate(struct net_device *dev,
420 struct iw_request_info *info,
421 struct iw_param *rate, char *extra)
422{
423 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100424 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200425 u32 target_rate = rate->value / 100000;
426 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100427 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200428
429 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100430
431 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
432
Larry Finger1fd5e582007-07-10 19:32:10 +0200433 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
434 * target_rate = X, rate->fixed = 1 means only rate X
435 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200436 sdata->max_ratectrl_rateidx = -1;
437 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200438 if (rate->value < 0)
439 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100440
441 for (i=0; i< sband->n_bitrates; i++) {
442 struct ieee80211_rate *brate = &sband->bitrates[i];
443 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200444
Larry Finger1fd5e582007-07-10 19:32:10 +0200445 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200446 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200447 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200448 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100449 err = 0;
450 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200451 }
452 }
Johannes Berg8318d782008-01-24 19:38:38 +0100453 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200454}
455
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700456static int ieee80211_ioctl_giwrate(struct net_device *dev,
457 struct iw_request_info *info,
458 struct iw_param *rate, char *extra)
459{
460 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
461 struct sta_info *sta;
462 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100463 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700464
465 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100466
Johannes Berg05c914f2008-09-11 00:01:58 +0200467 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700468 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100469
470 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
471
Johannes Berg380a9422008-04-04 23:40:35 +0200472 rcu_read_lock();
473
474 sta = sta_info_get(local, sdata->u.sta.bssid);
475
Johannes Berge6a98542008-10-21 12:40:02 +0200476 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
477 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700478 else
479 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200480
481 rcu_read_unlock();
482
483 if (!sta)
484 return -ENODEV;
485
Johannes Berg8318d782008-01-24 19:38:38 +0100486 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100487
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700488 return 0;
489}
490
Michael Buesch61609bc2007-09-20 22:06:39 +0200491static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
492 struct iw_request_info *info,
493 union iwreq_data *data, char *extra)
494{
495 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700496 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200497 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100498 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200499
500 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
501 return -EINVAL;
502 if (data->txpower.flags & IW_TXPOW_RANGE)
503 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700504 if (!chan)
505 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200506
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700507 if (data->txpower.fixed)
508 new_power_level = min(data->txpower.value, chan->max_power);
509 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100510 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200511
Johannes Berg2bf30fa2009-01-06 23:23:56 +0100512 local->user_power_level = new_power_level;
Vasanthakumar Thiagarajane3c92df2008-12-24 13:53:11 +0530513 if (local->hw.conf.power_level != new_power_level)
Johannes Berge8975582008-10-09 12:18:51 +0200514 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Mattias Nissler6a432952007-10-24 23:30:36 +0200515
Michael Buesch61609bc2007-09-20 22:06:39 +0200516 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
517 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200518 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100519 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200520 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200521
Johannes Berge8975582008-10-09 12:18:51 +0200522 if (reconf_flags)
523 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200524
525 return 0;
526}
527
Larry Fingerfe6aa302007-08-10 11:23:20 -0500528static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
529 struct iw_request_info *info,
530 union iwreq_data *data, char *extra)
531{
532 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
533
534 data->txpower.fixed = 1;
535 data->txpower.disabled = !(local->hw.conf.radio_enabled);
536 data->txpower.value = local->hw.conf.power_level;
537 data->txpower.flags = IW_TXPOW_DBM;
538
539 return 0;
540}
541
Jiri Bencf0706e82007-05-05 11:45:53 -0700542static int ieee80211_ioctl_siwrts(struct net_device *dev,
543 struct iw_request_info *info,
544 struct iw_param *rts, char *extra)
545{
546 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
547
548 if (rts->disabled)
549 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300550 else if (!rts->fixed)
551 /* if the rts value is not fixed, then take default */
552 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700553 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
554 return -EINVAL;
555 else
556 local->rts_threshold = rts->value;
557
558 /* If the wlan card performs RTS/CTS in hardware/firmware,
559 * configure it here */
560
561 if (local->ops->set_rts_threshold)
562 local->ops->set_rts_threshold(local_to_hw(local),
563 local->rts_threshold);
564
565 return 0;
566}
567
568static int ieee80211_ioctl_giwrts(struct net_device *dev,
569 struct iw_request_info *info,
570 struct iw_param *rts, char *extra)
571{
572 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
573
574 rts->value = local->rts_threshold;
575 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
576 rts->fixed = 1;
577
578 return 0;
579}
580
581
582static int ieee80211_ioctl_siwfrag(struct net_device *dev,
583 struct iw_request_info *info,
584 struct iw_param *frag, char *extra)
585{
586 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
587
588 if (frag->disabled)
589 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300590 else if (!frag->fixed)
591 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700592 else if (frag->value < 256 ||
593 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
594 return -EINVAL;
595 else {
596 /* Fragment length must be even, so strip LSB. */
597 local->fragmentation_threshold = frag->value & ~0x1;
598 }
599
Jiri Bencf0706e82007-05-05 11:45:53 -0700600 return 0;
601}
602
603static int ieee80211_ioctl_giwfrag(struct net_device *dev,
604 struct iw_request_info *info,
605 struct iw_param *frag, char *extra)
606{
607 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
608
609 frag->value = local->fragmentation_threshold;
610 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
611 frag->fixed = 1;
612
613 return 0;
614}
615
616
617static int ieee80211_ioctl_siwretry(struct net_device *dev,
618 struct iw_request_info *info,
619 struct iw_param *retry, char *extra)
620{
621 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
622
623 if (retry->disabled ||
624 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
625 return -EINVAL;
626
Johannes Berg9124b072008-10-14 19:17:54 +0200627 if (retry->flags & IW_RETRY_MAX) {
628 local->hw.conf.long_frame_max_tx_count = retry->value;
629 } else if (retry->flags & IW_RETRY_MIN) {
630 local->hw.conf.short_frame_max_tx_count = retry->value;
631 } else {
632 local->hw.conf.long_frame_max_tx_count = retry->value;
633 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700634 }
635
Johannes Berg9124b072008-10-14 19:17:54 +0200636 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700637
638 return 0;
639}
640
641
642static int ieee80211_ioctl_giwretry(struct net_device *dev,
643 struct iw_request_info *info,
644 struct iw_param *retry, char *extra)
645{
646 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
647
648 retry->disabled = 0;
649 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
650 /* first return min value, iwconfig will ask max value
651 * later if needed */
652 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200653 retry->value = local->hw.conf.short_frame_max_tx_count;
654 if (local->hw.conf.long_frame_max_tx_count !=
655 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700656 retry->flags |= IW_RETRY_MIN;
657 return 0;
658 }
659 if (retry->flags & IW_RETRY_MAX) {
660 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200661 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700662 }
663
664 return 0;
665}
666
Jiri Bencf0706e82007-05-05 11:45:53 -0700667static int ieee80211_ioctl_siwmlme(struct net_device *dev,
668 struct iw_request_info *info,
669 struct iw_point *data, char *extra)
670{
671 struct ieee80211_sub_if_data *sdata;
672 struct iw_mlme *mlme = (struct iw_mlme *) extra;
673
674 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200675 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
676 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700677 return -EINVAL;
678
679 switch (mlme->cmd) {
680 case IW_MLME_DEAUTH:
681 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200682 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700683 case IW_MLME_DISASSOC:
684 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200685 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700686 default:
687 return -EOPNOTSUPP;
688 }
689}
690
691
692static int ieee80211_ioctl_siwencode(struct net_device *dev,
693 struct iw_request_info *info,
694 struct iw_point *erq, char *keybuf)
695{
696 struct ieee80211_sub_if_data *sdata;
697 int idx, i, alg = ALG_WEP;
698 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200699 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700700
701 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
702
703 idx = erq->flags & IW_ENCODE_INDEX;
704 if (idx == 0) {
705 if (sdata->default_key)
706 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
707 if (sdata->default_key == sdata->keys[i]) {
708 idx = i;
709 break;
710 }
711 }
712 } else if (idx < 1 || idx > 4)
713 return -EINVAL;
714 else
715 idx--;
716
717 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200718 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700719 else if (erq->length == 0) {
720 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400721 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700722 return 0;
723 }
724
725 return ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200726 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200727 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700728 !sdata->default_key,
729 keybuf, erq->length);
730}
731
732
733static int ieee80211_ioctl_giwencode(struct net_device *dev,
734 struct iw_request_info *info,
735 struct iw_point *erq, char *key)
736{
737 struct ieee80211_sub_if_data *sdata;
738 int idx, i;
739
740 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
741
742 idx = erq->flags & IW_ENCODE_INDEX;
743 if (idx < 1 || idx > 4) {
744 idx = -1;
745 if (!sdata->default_key)
746 idx = 0;
747 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
748 if (sdata->default_key == sdata->keys[i]) {
749 idx = i;
750 break;
751 }
752 }
753 if (idx < 0)
754 return -EINVAL;
755 } else
756 idx--;
757
758 erq->flags = idx + 1;
759
760 if (!sdata->keys[idx]) {
761 erq->length = 0;
762 erq->flags |= IW_ENCODE_DISABLED;
763 return 0;
764 }
765
Johannes Berg8f20fc22007-08-28 17:01:54 -0400766 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400767 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400768 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700769 erq->flags |= IW_ENCODE_ENABLED;
770
Johannes Berg05c914f2008-09-11 00:01:58 +0200771 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300772 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
773 switch (ifsta->auth_alg) {
774 case WLAN_AUTH_OPEN:
775 case WLAN_AUTH_LEAP:
776 erq->flags |= IW_ENCODE_OPEN;
777 break;
778 case WLAN_AUTH_SHARED_KEY:
779 erq->flags |= IW_ENCODE_RESTRICTED;
780 break;
781 }
782 }
783
Jiri Bencf0706e82007-05-05 11:45:53 -0700784 return 0;
785}
786
Samuel Ortiz49292d52008-07-04 10:49:31 +0200787static int ieee80211_ioctl_siwpower(struct net_device *dev,
788 struct iw_request_info *info,
789 struct iw_param *wrq,
790 char *extra)
791{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200792 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200793 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
794 struct ieee80211_conf *conf = &local->hw.conf;
Kalle Valo520eb822008-12-18 23:35:27 +0200795 int ret = 0, timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200796 bool ps;
797
Johannes Berg4be8c382009-01-07 18:28:20 +0100798 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
799 return -EOPNOTSUPP;
800
Kalle Valoe0cb6862008-12-18 23:35:13 +0200801 if (sdata->vif.type != NL80211_IFTYPE_STATION)
802 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200803
804 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200805 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200806 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200807 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200808 }
809
810 switch (wrq->flags & IW_POWER_MODE) {
811 case IW_POWER_ON: /* If not specified */
812 case IW_POWER_MODE: /* If set all mask */
813 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200814 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200815 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200816 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100817 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200818 }
819
Johannes Berge9aeaba2009-01-06 18:12:35 +0100820 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
821 return -EINVAL;
822
Kalle Valo520eb822008-12-18 23:35:27 +0200823 if (wrq->flags & IW_POWER_TIMEOUT)
824 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200825
Johannes Berg4be8c382009-01-07 18:28:20 +0100826 set:
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100827 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
Kalle Valo520eb822008-12-18 23:35:27 +0200828 return ret;
829
Kalle Valoe0cb6862008-12-18 23:35:13 +0200830 local->powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100831 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200832
Johannes Berg4be8c382009-01-07 18:28:20 +0100833 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100834 ret = ieee80211_hw_config(local,
835 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
Johannes Berg4be8c382009-01-07 18:28:20 +0100836
837 if (!(sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
838 return ret;
839
840 if (conf->dynamic_ps_timeout > 0 &&
841 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
842 mod_timer(&local->dynamic_ps_timer, jiffies +
843 msecs_to_jiffies(conf->dynamic_ps_timeout));
844 } else {
845 if (local->powersave) {
846 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800847 ieee80211_send_nullfunc(local, sdata, 1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100848 conf->flags |= IEEE80211_CONF_PS;
849 ret = ieee80211_hw_config(local,
850 IEEE80211_CONF_CHANGE_PS);
851 } else {
852 conf->flags &= ~IEEE80211_CONF_PS;
853 ret = ieee80211_hw_config(local,
854 IEEE80211_CONF_CHANGE_PS);
855 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800856 ieee80211_send_nullfunc(local, sdata, 0);
Vivek Natarajanb8abde42009-01-27 19:26:28 +0530857 del_timer_sync(&local->dynamic_ps_timer);
858 cancel_work_sync(&local->dynamic_ps_enable_work);
Kalle Valo520eb822008-12-18 23:35:27 +0200859 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200860 }
861
862 return ret;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200863}
864
865static int ieee80211_ioctl_giwpower(struct net_device *dev,
866 struct iw_request_info *info,
867 union iwreq_data *wrqu,
868 char *extra)
869{
870 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200871
Kalle Valoe0cb6862008-12-18 23:35:13 +0200872 wrqu->power.disabled = !local->powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200873
874 return 0;
875}
876
Jiri Bencf0706e82007-05-05 11:45:53 -0700877static int ieee80211_ioctl_siwauth(struct net_device *dev,
878 struct iw_request_info *info,
879 struct iw_param *data, char *extra)
880{
Jiri Bencf0706e82007-05-05 11:45:53 -0700881 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
882 int ret = 0;
883
884 switch (data->flags & IW_AUTH_INDEX) {
885 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700886 case IW_AUTH_CIPHER_GROUP:
887 case IW_AUTH_WPA_ENABLED:
888 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700889 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200890 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000891 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530892 case IW_AUTH_CIPHER_PAIRWISE:
893 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
894 if (data->value & (IW_AUTH_CIPHER_WEP40 |
895 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
896 sdata->u.sta.flags |=
897 IEEE80211_STA_TKIP_WEP_USED;
898 else
899 sdata->u.sta.flags &=
900 ~IEEE80211_STA_TKIP_WEP_USED;
901 }
902 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100903 case IW_AUTH_DROP_UNENCRYPTED:
904 sdata->drop_unencrypted = !!data->value;
905 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000906 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200907 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700908 ret = -EINVAL;
909 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000910 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700911 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000912 * Privacy invoked by wpa_supplicant, store the
913 * value and allow associating to a protected
914 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700915 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000916 if (data->value)
917 sdata->u.sta.flags |=
918 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700919 }
920 break;
921 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +0200922 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
923 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700924 sdata->u.sta.auth_algs = data->value;
925 else
926 ret = -EOPNOTSUPP;
927 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200928 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200929 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
930 ret = -EOPNOTSUPP;
931 break;
932 }
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200933 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100934 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
935 switch (data->value) {
936 case IW_AUTH_MFP_DISABLED:
937 sdata->u.sta.mfp = IEEE80211_MFP_DISABLED;
938 break;
939 case IW_AUTH_MFP_OPTIONAL:
940 sdata->u.sta.mfp = IEEE80211_MFP_OPTIONAL;
941 break;
942 case IW_AUTH_MFP_REQUIRED:
943 sdata->u.sta.mfp = IEEE80211_MFP_REQUIRED;
944 break;
945 default:
946 ret = -EINVAL;
947 }
948 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200949 ret = -EOPNOTSUPP;
950 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700951 default:
952 ret = -EOPNOTSUPP;
953 break;
954 }
955 return ret;
956}
957
958/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
959static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
960{
961 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
962 struct iw_statistics *wstats = &local->wstats;
963 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
964 struct sta_info *sta = NULL;
965
Johannes Berg98dd6a52008-04-10 15:36:09 +0200966 rcu_read_lock();
967
Johannes Berg05c914f2008-09-11 00:01:58 +0200968 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
969 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700970 sta = sta_info_get(local, sdata->u.sta.bssid);
971 if (!sta) {
972 wstats->discard.fragment = 0;
973 wstats->discard.misc = 0;
974 wstats->qual.qual = 0;
975 wstats->qual.level = 0;
976 wstats->qual.noise = 0;
977 wstats->qual.updated = IW_QUAL_ALL_INVALID;
978 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +0200979 wstats->qual.level = sta->last_signal;
980 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -0700981 wstats->qual.noise = sta->last_noise;
982 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -0700983 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200984
985 rcu_read_unlock();
986
Jiri Bencf0706e82007-05-05 11:45:53 -0700987 return wstats;
988}
989
990static int ieee80211_ioctl_giwauth(struct net_device *dev,
991 struct iw_request_info *info,
992 struct iw_param *data, char *extra)
993{
994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
995 int ret = 0;
996
997 switch (data->flags & IW_AUTH_INDEX) {
998 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +0200999 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1000 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001001 data->value = sdata->u.sta.auth_algs;
1002 else
1003 ret = -EOPNOTSUPP;
1004 break;
1005 default:
1006 ret = -EOPNOTSUPP;
1007 break;
1008 }
1009 return ret;
1010}
1011
1012
1013static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1014 struct iw_request_info *info,
1015 struct iw_point *erq, char *extra)
1016{
1017 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1018 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001019 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001020
1021 switch (ext->alg) {
1022 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001023 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001024 break;
1025 case IW_ENCODE_ALG_WEP:
1026 alg = ALG_WEP;
1027 break;
1028 case IW_ENCODE_ALG_TKIP:
1029 alg = ALG_TKIP;
1030 break;
1031 case IW_ENCODE_ALG_CCMP:
1032 alg = ALG_CCMP;
1033 break;
Jouni Malinen22787dba2009-01-08 13:32:04 +02001034 case IW_ENCODE_ALG_AES_CMAC:
1035 alg = ALG_AES_CMAC;
1036 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001037 default:
1038 return -EOPNOTSUPP;
1039 }
1040
1041 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001042 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001043
1044 idx = erq->flags & IW_ENCODE_INDEX;
Jouni Malinen22787dba2009-01-08 13:32:04 +02001045 if (alg == ALG_AES_CMAC) {
1046 if (idx < NUM_DEFAULT_KEYS + 1 ||
1047 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1048 idx = -1;
1049 if (!sdata->default_mgmt_key)
1050 idx = 0;
1051 else for (i = NUM_DEFAULT_KEYS;
1052 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1053 i++) {
1054 if (sdata->default_mgmt_key == sdata->keys[i])
1055 {
1056 idx = i;
1057 break;
1058 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001059 }
Jouni Malinen22787dba2009-01-08 13:32:04 +02001060 if (idx < 0)
1061 return -EINVAL;
1062 } else
1063 idx--;
1064 } else {
1065 if (idx < 1 || idx > 4) {
1066 idx = -1;
1067 if (!sdata->default_key)
1068 idx = 0;
1069 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1070 if (sdata->default_key == sdata->keys[i]) {
1071 idx = i;
1072 break;
1073 }
1074 }
1075 if (idx < 0)
1076 return -EINVAL;
1077 } else
1078 idx--;
1079 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001080
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001081 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001082 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001083 ext->ext_flags &
1084 IW_ENCODE_EXT_SET_TX_KEY,
1085 ext->key, ext->key_len);
1086}
1087
1088
Jiri Bencf0706e82007-05-05 11:45:53 -07001089/* Structures to export the Wireless Handlers */
1090
1091static const iw_handler ieee80211_handler[] =
1092{
1093 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001094 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001095 (iw_handler) NULL, /* SIOCSIWNWID */
1096 (iw_handler) NULL, /* SIOCGIWNWID */
1097 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1098 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001099 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1100 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001101 (iw_handler) NULL, /* SIOCSIWSENS */
1102 (iw_handler) NULL, /* SIOCGIWSENS */
1103 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1104 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1105 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1106 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1107 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1108 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001109 (iw_handler) NULL, /* SIOCSIWSPY */
1110 (iw_handler) NULL, /* SIOCGIWSPY */
1111 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1112 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001113 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1114 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1115 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1116 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +01001117 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1118 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e82007-05-05 11:45:53 -07001119 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1120 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1121 (iw_handler) NULL, /* SIOCSIWNICKN */
1122 (iw_handler) NULL, /* SIOCGIWNICKN */
1123 (iw_handler) NULL, /* -- hole -- */
1124 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001125 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001126 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001127 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1128 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1129 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1130 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001131 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001132 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001133 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1134 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1135 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1136 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001137 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1138 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001139 (iw_handler) NULL, /* -- hole -- */
1140 (iw_handler) NULL, /* -- hole -- */
1141 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1142 (iw_handler) NULL, /* SIOCGIWGENIE */
1143 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1144 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1145 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1146 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1147 (iw_handler) NULL, /* SIOCSIWPMKSA */
1148 (iw_handler) NULL, /* -- hole -- */
1149};
1150
Jiri Bencf0706e82007-05-05 11:45:53 -07001151const struct iw_handler_def ieee80211_iw_handler_def =
1152{
1153 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001154 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001155 .get_wireless_stats = ieee80211_get_wireless_stats,
1156};