blob: acd5808b87f45bf2535158e6d4917e3fbd96c8b0 [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 Berg7fee5372009-01-30 11:13:06 +0100176 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
Bruno Randolf566bfe52008-05-08 19:15:40 +0200177 range->max_qual.level = local->hw.max_signal;
178 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
179 range->max_qual.level = -110;
180 else
181 range->max_qual.level = 0;
182
183 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
184 range->max_qual.noise = -110;
185 else
186 range->max_qual.noise = 0;
187
188 range->max_qual.qual = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700189 range->max_qual.updated = local->wstats_flags;
190
Bruno Randolf566bfe52008-05-08 19:15:40 +0200191 range->avg_qual.qual = 50;
192 /* not always true but better than nothing */
193 range->avg_qual.level = range->max_qual.level / 2;
194 range->avg_qual.noise = range->max_qual.noise / 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700195 range->avg_qual.updated = local->wstats_flags;
196
197 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
198 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
199
Hong Liu333af2f2007-07-10 19:32:08 +0200200
Johannes Berg8318d782008-01-24 19:38:38 +0100201 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
202 int i;
203 struct ieee80211_supported_band *sband;
204
205 sband = local->hw.wiphy->bands[band];
206
207 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200208 continue;
209
Johannes Berg8318d782008-01-24 19:38:38 +0100210 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
211 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200212
Johannes Berg8318d782008-01-24 19:38:38 +0100213 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
214 range->freq[c].i =
215 ieee80211_frequency_to_channel(
216 chan->center_freq);
217 range->freq[c].m = chan->center_freq;
218 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200219 c++;
220 }
Hong Liu333af2f2007-07-10 19:32:08 +0200221 }
222 }
223 range->num_channels = c;
224 range->num_frequency = c;
225
Jiri Bencf0706e82007-05-05 11:45:53 -0700226 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700227 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
228 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
229
Dan Williams374fdfb2007-12-12 10:25:07 -0500230 range->scan_capa |= IW_SCAN_CAPA_ESSID;
231
Jiri Bencf0706e82007-05-05 11:45:53 -0700232 return 0;
233}
234
235
Jiri Bencf0706e82007-05-05 11:45:53 -0700236static int ieee80211_ioctl_siwfreq(struct net_device *dev,
237 struct iw_request_info *info,
238 struct iw_freq *freq, char *extra)
239{
Jiri Bencf0706e82007-05-05 11:45:53 -0700240 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
241
Alina Friedrichsenb522ed52009-01-06 03:15:23 +0100242 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
243 sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400244 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700245
246 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
247 if (freq->e == 0) {
248 if (freq->m < 0) {
Alina Friedrichsenb522ed52009-01-06 03:15:23 +0100249 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
250 sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400251 sdata->u.sta.flags |=
252 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700253 return 0;
254 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200255 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100256 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700257 } else {
258 int i, div = 1000000;
259 for (i = 0; i < freq->e; i++)
260 div /= 10;
261 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200262 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700263 else
264 return -EINVAL;
265 }
266}
267
268
269static int ieee80211_ioctl_giwfreq(struct net_device *dev,
270 struct iw_request_info *info,
271 struct iw_freq *freq, char *extra)
272{
273 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
274
Johannes Berg8318d782008-01-24 19:38:38 +0100275 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700276 freq->e = 6;
277
278 return 0;
279}
280
281
282static int ieee80211_ioctl_siwessid(struct net_device *dev,
283 struct iw_request_info *info,
284 struct iw_point *data, char *ssid)
285{
Jiri Bencf0706e82007-05-05 11:45:53 -0700286 struct ieee80211_sub_if_data *sdata;
287 size_t len = data->length;
288
289 /* iwconfig uses nul termination in SSID.. */
290 if (len > 0 && ssid[len - 1] == '\0')
291 len--;
292
293 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200294 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
295 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700296 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200297 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700298 if (len > IEEE80211_MAX_SSID_LEN)
299 return -EINVAL;
300 memcpy(sdata->u.sta.ssid, ssid, len);
301 sdata->u.sta.ssid_len = len;
302 return 0;
303 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400304 if (data->flags)
305 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
306 else
307 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200308 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700309 if (ret)
310 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200311 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700312 return 0;
313 }
314
Jiri Bencf0706e82007-05-05 11:45:53 -0700315 return -EOPNOTSUPP;
316}
317
318
319static int ieee80211_ioctl_giwessid(struct net_device *dev,
320 struct iw_request_info *info,
321 struct iw_point *data, char *ssid)
322{
323 size_t len;
324
325 struct ieee80211_sub_if_data *sdata;
326 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200327 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
328 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200329 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700330 if (res == 0) {
331 data->length = len;
332 data->flags = 1;
333 } else
334 data->flags = 0;
335 return res;
336 }
337
Jiri Bencf0706e82007-05-05 11:45:53 -0700338 return -EOPNOTSUPP;
339}
340
341
342static int ieee80211_ioctl_siwap(struct net_device *dev,
343 struct iw_request_info *info,
344 struct sockaddr *ap_addr, char *extra)
345{
Jiri Bencf0706e82007-05-05 11:45:53 -0700346 struct ieee80211_sub_if_data *sdata;
347
348 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200349 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
350 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700351 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200352 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700353 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
354 ETH_ALEN);
355 return 0;
356 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400357 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
358 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
359 IEEE80211_STA_AUTO_CHANNEL_SEL;
360 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
361 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700362 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400363 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200364 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700365 if (ret)
366 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200367 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700368 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200369 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100370 /*
371 * If it is necessary to update the WDS peer address
372 * while the interface is running, then we need to do
373 * more work here, namely if it is running we need to
374 * add a new and remove the old STA entry, this is
375 * normally handled by _open() and _stop().
376 */
377 if (netif_running(dev))
378 return -EBUSY;
379
380 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
381 ETH_ALEN);
382
383 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700384 }
385
386 return -EOPNOTSUPP;
387}
388
389
390static int ieee80211_ioctl_giwap(struct net_device *dev,
391 struct iw_request_info *info,
392 struct sockaddr *ap_addr, char *extra)
393{
394 struct ieee80211_sub_if_data *sdata;
395
396 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200397 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
398 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300399 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
400 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700401 ap_addr->sa_family = ARPHRD_ETHER;
402 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
403 return 0;
404 } else {
405 memset(&ap_addr->sa_data, 0, ETH_ALEN);
406 return 0;
407 }
Johannes Berg05c914f2008-09-11 00:01:58 +0200408 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700409 ap_addr->sa_family = ARPHRD_ETHER;
410 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
411 return 0;
412 }
413
414 return -EOPNOTSUPP;
415}
416
417
418static int ieee80211_ioctl_siwscan(struct net_device *dev,
419 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400420 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700421{
Jiri Bencf0706e82007-05-05 11:45:53 -0700422 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400423 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700424 u8 *ssid = NULL;
425 size_t ssid_len = 0;
426
427 if (!netif_running(dev))
428 return -ENETDOWN;
429
Johannes Berg05c914f2008-09-11 00:01:58 +0200430 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
431 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Jouni Malinenb7a530d2008-12-10 14:51:47 +0200432 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
John W. Linvilled114f392007-10-17 21:16:16 -0700433 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700434
435 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400436 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
437 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
438 req = (struct iw_scan_req *)extra;
439 ssid = req->essid;
440 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700441 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200442
Johannes Bergc2b13452008-09-11 00:01:55 +0200443 return ieee80211_request_scan(sdata, ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700444}
445
446
447static int ieee80211_ioctl_giwscan(struct net_device *dev,
448 struct iw_request_info *info,
449 struct iw_point *data, char *extra)
450{
451 int res;
452 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200453 struct ieee80211_sub_if_data *sdata;
454
455 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Zhu Yiece8edd2007-11-22 10:53:21 +0800456
Johannes Bergc2b13452008-09-11 00:01:55 +0200457 if (local->sw_scanning || local->hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700458 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800459
Johannes Bergc2b13452008-09-11 00:01:55 +0200460 res = ieee80211_scan_results(local, info, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700461 if (res >= 0) {
462 data->length = res;
463 return 0;
464 }
465 data->length = 0;
466 return res;
467}
468
469
Larry Finger1fd5e582007-07-10 19:32:10 +0200470static int ieee80211_ioctl_siwrate(struct net_device *dev,
471 struct iw_request_info *info,
472 struct iw_param *rate, char *extra)
473{
474 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100475 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200476 u32 target_rate = rate->value / 100000;
477 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100478 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200479
480 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100481
482 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
483
Larry Finger1fd5e582007-07-10 19:32:10 +0200484 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
485 * target_rate = X, rate->fixed = 1 means only rate X
486 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200487 sdata->max_ratectrl_rateidx = -1;
488 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200489 if (rate->value < 0)
490 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100491
492 for (i=0; i< sband->n_bitrates; i++) {
493 struct ieee80211_rate *brate = &sband->bitrates[i];
494 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200495
Larry Finger1fd5e582007-07-10 19:32:10 +0200496 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200497 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200498 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200499 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100500 err = 0;
501 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200502 }
503 }
Johannes Berg8318d782008-01-24 19:38:38 +0100504 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200505}
506
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700507static int ieee80211_ioctl_giwrate(struct net_device *dev,
508 struct iw_request_info *info,
509 struct iw_param *rate, char *extra)
510{
511 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
512 struct sta_info *sta;
513 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100514 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700515
516 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100517
Johannes Berg05c914f2008-09-11 00:01:58 +0200518 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700519 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100520
521 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
522
Johannes Berg380a9422008-04-04 23:40:35 +0200523 rcu_read_lock();
524
525 sta = sta_info_get(local, sdata->u.sta.bssid);
526
Johannes Berge6a98542008-10-21 12:40:02 +0200527 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
528 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700529 else
530 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200531
532 rcu_read_unlock();
533
534 if (!sta)
535 return -ENODEV;
536
Johannes Berg8318d782008-01-24 19:38:38 +0100537 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100538
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700539 return 0;
540}
541
Michael Buesch61609bc2007-09-20 22:06:39 +0200542static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
543 struct iw_request_info *info,
544 union iwreq_data *data, char *extra)
545{
546 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700547 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200548 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100549 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200550
551 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
552 return -EINVAL;
553 if (data->txpower.flags & IW_TXPOW_RANGE)
554 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700555 if (!chan)
556 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200557
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700558 if (data->txpower.fixed)
559 new_power_level = min(data->txpower.value, chan->max_power);
560 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100561 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200562
Johannes Berg2bf30fa2009-01-06 23:23:56 +0100563 local->user_power_level = new_power_level;
Vasanthakumar Thiagarajane3c92df2008-12-24 13:53:11 +0530564 if (local->hw.conf.power_level != new_power_level)
Johannes Berge8975582008-10-09 12:18:51 +0200565 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Mattias Nissler6a432952007-10-24 23:30:36 +0200566
Michael Buesch61609bc2007-09-20 22:06:39 +0200567 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
568 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200569 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100570 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200571 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200572
Johannes Berge8975582008-10-09 12:18:51 +0200573 if (reconf_flags)
574 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200575
576 return 0;
577}
578
Larry Fingerfe6aa302007-08-10 11:23:20 -0500579static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
580 struct iw_request_info *info,
581 union iwreq_data *data, char *extra)
582{
583 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
584
585 data->txpower.fixed = 1;
586 data->txpower.disabled = !(local->hw.conf.radio_enabled);
587 data->txpower.value = local->hw.conf.power_level;
588 data->txpower.flags = IW_TXPOW_DBM;
589
590 return 0;
591}
592
Jiri Bencf0706e82007-05-05 11:45:53 -0700593static int ieee80211_ioctl_siwrts(struct net_device *dev,
594 struct iw_request_info *info,
595 struct iw_param *rts, char *extra)
596{
597 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
598
599 if (rts->disabled)
600 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300601 else if (!rts->fixed)
602 /* if the rts value is not fixed, then take default */
603 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700604 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
605 return -EINVAL;
606 else
607 local->rts_threshold = rts->value;
608
609 /* If the wlan card performs RTS/CTS in hardware/firmware,
610 * configure it here */
611
612 if (local->ops->set_rts_threshold)
613 local->ops->set_rts_threshold(local_to_hw(local),
614 local->rts_threshold);
615
616 return 0;
617}
618
619static int ieee80211_ioctl_giwrts(struct net_device *dev,
620 struct iw_request_info *info,
621 struct iw_param *rts, char *extra)
622{
623 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
624
625 rts->value = local->rts_threshold;
626 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
627 rts->fixed = 1;
628
629 return 0;
630}
631
632
633static int ieee80211_ioctl_siwfrag(struct net_device *dev,
634 struct iw_request_info *info,
635 struct iw_param *frag, char *extra)
636{
637 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
638
639 if (frag->disabled)
640 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300641 else if (!frag->fixed)
642 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700643 else if (frag->value < 256 ||
644 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
645 return -EINVAL;
646 else {
647 /* Fragment length must be even, so strip LSB. */
648 local->fragmentation_threshold = frag->value & ~0x1;
649 }
650
Jiri Bencf0706e82007-05-05 11:45:53 -0700651 return 0;
652}
653
654static int ieee80211_ioctl_giwfrag(struct net_device *dev,
655 struct iw_request_info *info,
656 struct iw_param *frag, char *extra)
657{
658 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
659
660 frag->value = local->fragmentation_threshold;
661 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
662 frag->fixed = 1;
663
664 return 0;
665}
666
667
668static int ieee80211_ioctl_siwretry(struct net_device *dev,
669 struct iw_request_info *info,
670 struct iw_param *retry, char *extra)
671{
672 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
673
674 if (retry->disabled ||
675 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
676 return -EINVAL;
677
Johannes Berg9124b072008-10-14 19:17:54 +0200678 if (retry->flags & IW_RETRY_MAX) {
679 local->hw.conf.long_frame_max_tx_count = retry->value;
680 } else if (retry->flags & IW_RETRY_MIN) {
681 local->hw.conf.short_frame_max_tx_count = retry->value;
682 } else {
683 local->hw.conf.long_frame_max_tx_count = retry->value;
684 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700685 }
686
Johannes Berg9124b072008-10-14 19:17:54 +0200687 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700688
689 return 0;
690}
691
692
693static int ieee80211_ioctl_giwretry(struct net_device *dev,
694 struct iw_request_info *info,
695 struct iw_param *retry, char *extra)
696{
697 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
698
699 retry->disabled = 0;
700 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
701 /* first return min value, iwconfig will ask max value
702 * later if needed */
703 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200704 retry->value = local->hw.conf.short_frame_max_tx_count;
705 if (local->hw.conf.long_frame_max_tx_count !=
706 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700707 retry->flags |= IW_RETRY_MIN;
708 return 0;
709 }
710 if (retry->flags & IW_RETRY_MAX) {
711 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200712 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700713 }
714
715 return 0;
716}
717
Jiri Bencf0706e82007-05-05 11:45:53 -0700718static int ieee80211_ioctl_siwmlme(struct net_device *dev,
719 struct iw_request_info *info,
720 struct iw_point *data, char *extra)
721{
722 struct ieee80211_sub_if_data *sdata;
723 struct iw_mlme *mlme = (struct iw_mlme *) extra;
724
725 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200726 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
727 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700728 return -EINVAL;
729
730 switch (mlme->cmd) {
731 case IW_MLME_DEAUTH:
732 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200733 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700734 case IW_MLME_DISASSOC:
735 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200736 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700737 default:
738 return -EOPNOTSUPP;
739 }
740}
741
742
743static int ieee80211_ioctl_siwencode(struct net_device *dev,
744 struct iw_request_info *info,
745 struct iw_point *erq, char *keybuf)
746{
747 struct ieee80211_sub_if_data *sdata;
748 int idx, i, alg = ALG_WEP;
749 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200750 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700751
752 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
753
754 idx = erq->flags & IW_ENCODE_INDEX;
755 if (idx == 0) {
756 if (sdata->default_key)
757 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
758 if (sdata->default_key == sdata->keys[i]) {
759 idx = i;
760 break;
761 }
762 }
763 } else if (idx < 1 || idx > 4)
764 return -EINVAL;
765 else
766 idx--;
767
768 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200769 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700770 else if (erq->length == 0) {
771 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400772 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700773 return 0;
774 }
775
776 return ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200777 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200778 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700779 !sdata->default_key,
780 keybuf, erq->length);
781}
782
783
784static int ieee80211_ioctl_giwencode(struct net_device *dev,
785 struct iw_request_info *info,
786 struct iw_point *erq, char *key)
787{
788 struct ieee80211_sub_if_data *sdata;
789 int idx, i;
790
791 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
792
793 idx = erq->flags & IW_ENCODE_INDEX;
794 if (idx < 1 || idx > 4) {
795 idx = -1;
796 if (!sdata->default_key)
797 idx = 0;
798 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
799 if (sdata->default_key == sdata->keys[i]) {
800 idx = i;
801 break;
802 }
803 }
804 if (idx < 0)
805 return -EINVAL;
806 } else
807 idx--;
808
809 erq->flags = idx + 1;
810
811 if (!sdata->keys[idx]) {
812 erq->length = 0;
813 erq->flags |= IW_ENCODE_DISABLED;
814 return 0;
815 }
816
Johannes Berg8f20fc22007-08-28 17:01:54 -0400817 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400818 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400819 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700820 erq->flags |= IW_ENCODE_ENABLED;
821
Johannes Berg05c914f2008-09-11 00:01:58 +0200822 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300823 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
824 switch (ifsta->auth_alg) {
825 case WLAN_AUTH_OPEN:
826 case WLAN_AUTH_LEAP:
827 erq->flags |= IW_ENCODE_OPEN;
828 break;
829 case WLAN_AUTH_SHARED_KEY:
830 erq->flags |= IW_ENCODE_RESTRICTED;
831 break;
832 }
833 }
834
Jiri Bencf0706e82007-05-05 11:45:53 -0700835 return 0;
836}
837
Samuel Ortiz49292d52008-07-04 10:49:31 +0200838static int ieee80211_ioctl_siwpower(struct net_device *dev,
839 struct iw_request_info *info,
840 struct iw_param *wrq,
841 char *extra)
842{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200843 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200844 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
845 struct ieee80211_conf *conf = &local->hw.conf;
Kalle Valo520eb822008-12-18 23:35:27 +0200846 int ret = 0, timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200847 bool ps;
848
Johannes Berg4be8c382009-01-07 18:28:20 +0100849 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
850 return -EOPNOTSUPP;
851
Kalle Valoe0cb6862008-12-18 23:35:13 +0200852 if (sdata->vif.type != NL80211_IFTYPE_STATION)
853 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200854
855 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200856 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200857 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200858 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200859 }
860
861 switch (wrq->flags & IW_POWER_MODE) {
862 case IW_POWER_ON: /* If not specified */
863 case IW_POWER_MODE: /* If set all mask */
864 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200865 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200866 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200867 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100868 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200869 }
870
Johannes Berge9aeaba2009-01-06 18:12:35 +0100871 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
872 return -EINVAL;
873
Kalle Valo520eb822008-12-18 23:35:27 +0200874 if (wrq->flags & IW_POWER_TIMEOUT)
875 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200876
Johannes Berg4be8c382009-01-07 18:28:20 +0100877 set:
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100878 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
Kalle Valo520eb822008-12-18 23:35:27 +0200879 return ret;
880
Kalle Valoe0cb6862008-12-18 23:35:13 +0200881 local->powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100882 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200883
Johannes Berg4be8c382009-01-07 18:28:20 +0100884 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100885 ret = ieee80211_hw_config(local,
886 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
Johannes Berg4be8c382009-01-07 18:28:20 +0100887
888 if (!(sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
889 return ret;
890
891 if (conf->dynamic_ps_timeout > 0 &&
892 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
893 mod_timer(&local->dynamic_ps_timer, jiffies +
894 msecs_to_jiffies(conf->dynamic_ps_timeout));
895 } else {
896 if (local->powersave) {
897 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800898 ieee80211_send_nullfunc(local, sdata, 1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100899 conf->flags |= IEEE80211_CONF_PS;
900 ret = ieee80211_hw_config(local,
901 IEEE80211_CONF_CHANGE_PS);
902 } else {
903 conf->flags &= ~IEEE80211_CONF_PS;
904 ret = ieee80211_hw_config(local,
905 IEEE80211_CONF_CHANGE_PS);
906 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800907 ieee80211_send_nullfunc(local, sdata, 0);
Vivek Natarajanb8abde42009-01-27 19:26:28 +0530908 del_timer_sync(&local->dynamic_ps_timer);
909 cancel_work_sync(&local->dynamic_ps_enable_work);
Kalle Valo520eb822008-12-18 23:35:27 +0200910 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200911 }
912
913 return ret;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200914}
915
916static int ieee80211_ioctl_giwpower(struct net_device *dev,
917 struct iw_request_info *info,
918 union iwreq_data *wrqu,
919 char *extra)
920{
921 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200922
Kalle Valoe0cb6862008-12-18 23:35:13 +0200923 wrqu->power.disabled = !local->powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200924
925 return 0;
926}
927
Jiri Bencf0706e82007-05-05 11:45:53 -0700928static int ieee80211_ioctl_siwauth(struct net_device *dev,
929 struct iw_request_info *info,
930 struct iw_param *data, char *extra)
931{
Jiri Bencf0706e82007-05-05 11:45:53 -0700932 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
933 int ret = 0;
934
935 switch (data->flags & IW_AUTH_INDEX) {
936 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700937 case IW_AUTH_CIPHER_GROUP:
938 case IW_AUTH_WPA_ENABLED:
939 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700940 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200941 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000942 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530943 case IW_AUTH_CIPHER_PAIRWISE:
944 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
945 if (data->value & (IW_AUTH_CIPHER_WEP40 |
946 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
947 sdata->u.sta.flags |=
948 IEEE80211_STA_TKIP_WEP_USED;
949 else
950 sdata->u.sta.flags &=
951 ~IEEE80211_STA_TKIP_WEP_USED;
952 }
953 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100954 case IW_AUTH_DROP_UNENCRYPTED:
955 sdata->drop_unencrypted = !!data->value;
956 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000957 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200958 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700959 ret = -EINVAL;
960 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000961 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700962 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000963 * Privacy invoked by wpa_supplicant, store the
964 * value and allow associating to a protected
965 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700966 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000967 if (data->value)
968 sdata->u.sta.flags |=
969 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700970 }
971 break;
972 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +0200973 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
974 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700975 sdata->u.sta.auth_algs = data->value;
976 else
977 ret = -EOPNOTSUPP;
978 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200979 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200980 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
981 ret = -EOPNOTSUPP;
982 break;
983 }
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200984 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100985 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
986 switch (data->value) {
987 case IW_AUTH_MFP_DISABLED:
988 sdata->u.sta.mfp = IEEE80211_MFP_DISABLED;
989 break;
990 case IW_AUTH_MFP_OPTIONAL:
991 sdata->u.sta.mfp = IEEE80211_MFP_OPTIONAL;
992 break;
993 case IW_AUTH_MFP_REQUIRED:
994 sdata->u.sta.mfp = IEEE80211_MFP_REQUIRED;
995 break;
996 default:
997 ret = -EINVAL;
998 }
999 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +02001000 ret = -EOPNOTSUPP;
1001 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001002 default:
1003 ret = -EOPNOTSUPP;
1004 break;
1005 }
1006 return ret;
1007}
1008
1009/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1010static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1011{
1012 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1013 struct iw_statistics *wstats = &local->wstats;
1014 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1015 struct sta_info *sta = NULL;
1016
Johannes Berg98dd6a52008-04-10 15:36:09 +02001017 rcu_read_lock();
1018
Johannes Berg05c914f2008-09-11 00:01:58 +02001019 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1020 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001021 sta = sta_info_get(local, sdata->u.sta.bssid);
1022 if (!sta) {
1023 wstats->discard.fragment = 0;
1024 wstats->discard.misc = 0;
1025 wstats->qual.qual = 0;
1026 wstats->qual.level = 0;
1027 wstats->qual.noise = 0;
1028 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1029 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001030 wstats->qual.level = sta->last_signal;
1031 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001032 wstats->qual.noise = sta->last_noise;
1033 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001034 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001035
1036 rcu_read_unlock();
1037
Jiri Bencf0706e82007-05-05 11:45:53 -07001038 return wstats;
1039}
1040
1041static int ieee80211_ioctl_giwauth(struct net_device *dev,
1042 struct iw_request_info *info,
1043 struct iw_param *data, char *extra)
1044{
1045 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1046 int ret = 0;
1047
1048 switch (data->flags & IW_AUTH_INDEX) {
1049 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +02001050 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1051 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001052 data->value = sdata->u.sta.auth_algs;
1053 else
1054 ret = -EOPNOTSUPP;
1055 break;
1056 default:
1057 ret = -EOPNOTSUPP;
1058 break;
1059 }
1060 return ret;
1061}
1062
1063
1064static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1065 struct iw_request_info *info,
1066 struct iw_point *erq, char *extra)
1067{
1068 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1069 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001070 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001071
1072 switch (ext->alg) {
1073 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001074 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001075 break;
1076 case IW_ENCODE_ALG_WEP:
1077 alg = ALG_WEP;
1078 break;
1079 case IW_ENCODE_ALG_TKIP:
1080 alg = ALG_TKIP;
1081 break;
1082 case IW_ENCODE_ALG_CCMP:
1083 alg = ALG_CCMP;
1084 break;
Jouni Malinen22787dba2009-01-08 13:32:04 +02001085 case IW_ENCODE_ALG_AES_CMAC:
1086 alg = ALG_AES_CMAC;
1087 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001088 default:
1089 return -EOPNOTSUPP;
1090 }
1091
1092 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001093 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001094
1095 idx = erq->flags & IW_ENCODE_INDEX;
Jouni Malinen22787dba2009-01-08 13:32:04 +02001096 if (alg == ALG_AES_CMAC) {
1097 if (idx < NUM_DEFAULT_KEYS + 1 ||
1098 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1099 idx = -1;
1100 if (!sdata->default_mgmt_key)
1101 idx = 0;
1102 else for (i = NUM_DEFAULT_KEYS;
1103 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1104 i++) {
1105 if (sdata->default_mgmt_key == sdata->keys[i])
1106 {
1107 idx = i;
1108 break;
1109 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001110 }
Jouni Malinen22787dba2009-01-08 13:32:04 +02001111 if (idx < 0)
1112 return -EINVAL;
1113 } else
1114 idx--;
1115 } else {
1116 if (idx < 1 || idx > 4) {
1117 idx = -1;
1118 if (!sdata->default_key)
1119 idx = 0;
1120 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1121 if (sdata->default_key == sdata->keys[i]) {
1122 idx = i;
1123 break;
1124 }
1125 }
1126 if (idx < 0)
1127 return -EINVAL;
1128 } else
1129 idx--;
1130 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001131
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001132 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001133 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001134 ext->ext_flags &
1135 IW_ENCODE_EXT_SET_TX_KEY,
1136 ext->key, ext->key_len);
1137}
1138
1139
Jiri Bencf0706e82007-05-05 11:45:53 -07001140/* Structures to export the Wireless Handlers */
1141
1142static const iw_handler ieee80211_handler[] =
1143{
1144 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001145 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001146 (iw_handler) NULL, /* SIOCSIWNWID */
1147 (iw_handler) NULL, /* SIOCGIWNWID */
1148 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1149 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001150 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1151 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001152 (iw_handler) NULL, /* SIOCSIWSENS */
1153 (iw_handler) NULL, /* SIOCGIWSENS */
1154 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1155 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1156 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1157 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1158 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1159 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001160 (iw_handler) NULL, /* SIOCSIWSPY */
1161 (iw_handler) NULL, /* SIOCGIWSPY */
1162 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1163 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001164 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1165 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1166 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1167 (iw_handler) NULL, /* SIOCGIWAPLIST */
1168 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1169 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1170 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1171 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1172 (iw_handler) NULL, /* SIOCSIWNICKN */
1173 (iw_handler) NULL, /* SIOCGIWNICKN */
1174 (iw_handler) NULL, /* -- hole -- */
1175 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001176 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001177 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001178 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1179 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1180 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1181 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001182 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001183 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001184 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1185 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1186 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1187 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001188 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1189 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001190 (iw_handler) NULL, /* -- hole -- */
1191 (iw_handler) NULL, /* -- hole -- */
1192 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1193 (iw_handler) NULL, /* SIOCGIWGENIE */
1194 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1195 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1196 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1197 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1198 (iw_handler) NULL, /* SIOCSIWPMKSA */
1199 (iw_handler) NULL, /* -- hole -- */
1200};
1201
Jiri Bencf0706e82007-05-05 11:45:53 -07001202const struct iw_handler_def ieee80211_iw_handler_def =
1203{
1204 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001205 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001206 .get_wireless_stats = ieee80211_get_wireless_stats,
1207};