blob: 654041b93736e03f57164114815ebaac27f39918 [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
Volker Braun139c3a02007-09-14 11:10:25 -040040 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
41 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120042 sdata->dev->name, idx);
Volker Braun139c3a02007-09-14 11:10:25 -040043 return -EINVAL;
44 }
45
Johannes Berg628a1402007-09-26 17:53:17 +020046 if (remove) {
Johannes Berg3b967662008-04-08 17:56:52 +020047 rcu_read_lock();
48
49 err = 0;
50
Johannes Bergdb4d1162008-02-25 16:27:45 +010051 if (is_broadcast_ether_addr(sta_addr)) {
52 key = sdata->keys[idx];
53 } else {
54 sta = sta_info_get(local, sta_addr);
Johannes Berg3b967662008-04-08 17:56:52 +020055 if (!sta) {
56 err = -ENOENT;
57 goto out_unlock;
58 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010059 key = sta->key;
Jiri Bencf0706e82007-05-05 11:45:53 -070060 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010061
Johannes Bergd0709a62008-02-25 16:27:46 +010062 ieee80211_key_free(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +010063 } else {
64 key = ieee80211_key_alloc(alg, idx, key_len, _key);
65 if (!key)
66 return -ENOMEM;
67
Johannes Bergd0709a62008-02-25 16:27:46 +010068 sta = NULL;
Johannes Berg3b967662008-04-08 17:56:52 +020069 err = 0;
70
71 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +010072
Johannes Bergdb4d1162008-02-25 16:27:45 +010073 if (!is_broadcast_ether_addr(sta_addr)) {
74 set_tx_key = 0;
75 /*
76 * According to the standard, the key index of a
77 * pairwise key must be zero. However, some AP are
78 * broken when it comes to WEP key indices, so we
79 * work around this.
80 */
81 if (idx != 0 && alg != ALG_WEP) {
Johannes Bergd0709a62008-02-25 16:27:46 +010082 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020083 err = -EINVAL;
84 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010085 }
86
87 sta = sta_info_get(local, sta_addr);
88 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +010089 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020090 err = -ENOENT;
91 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010092 }
93 }
94
Emmanuel Grumbach23976ef2008-06-28 02:50:13 +030095 if (alg == ALG_WEP &&
96 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
97 ieee80211_key_free(key);
98 err = -EINVAL;
99 goto out_unlock;
100 }
101
Johannes Bergdb4d1162008-02-25 16:27:45 +0100102 ieee80211_key_link(key, sdata, sta);
103
104 if (set_tx_key || (!sta && !sdata->default_key && key))
105 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700106 }
107
Johannes Berg3b967662008-04-08 17:56:52 +0200108 out_unlock:
109 rcu_read_unlock();
110
111 return err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700112}
113
114static int ieee80211_ioctl_siwgenie(struct net_device *dev,
115 struct iw_request_info *info,
116 struct iw_point *data, char *extra)
117{
118 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -0700119
120 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200121
122 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
123 return -EOPNOTSUPP;
124
Johannes Berg05c914f2008-09-11 00:01:58 +0200125 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
126 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200127 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700128 if (ret)
129 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400130 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200131 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700132 return 0;
133 }
134
Jiri Bencf0706e82007-05-05 11:45:53 -0700135 return -EOPNOTSUPP;
136}
137
Jiri Bencf0706e82007-05-05 11:45:53 -0700138static int ieee80211_ioctl_giwrange(struct net_device *dev,
139 struct iw_request_info *info,
140 struct iw_point *data, char *extra)
141{
142 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
143 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100144 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200145 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700146
147 data->length = sizeof(struct iw_range);
148 memset(range, 0, sizeof(struct iw_range));
149
150 range->we_version_compiled = WIRELESS_EXT;
151 range->we_version_source = 21;
152 range->retry_capa = IW_RETRY_LIMIT;
153 range->retry_flags = IW_RETRY_LIMIT;
154 range->min_retry = 0;
155 range->max_retry = 255;
156 range->min_rts = 0;
157 range->max_rts = 2347;
158 range->min_frag = 256;
159 range->max_frag = 2346;
160
161 range->encoding_size[0] = 5;
162 range->encoding_size[1] = 13;
163 range->num_encoding_sizes = 2;
164 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
165
Bruno Randolf566bfe52008-05-08 19:15:40 +0200166 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
167 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
168 range->max_qual.level = local->hw.max_signal;
169 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
170 range->max_qual.level = -110;
171 else
172 range->max_qual.level = 0;
173
174 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
175 range->max_qual.noise = -110;
176 else
177 range->max_qual.noise = 0;
178
179 range->max_qual.qual = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700180 range->max_qual.updated = local->wstats_flags;
181
Bruno Randolf566bfe52008-05-08 19:15:40 +0200182 range->avg_qual.qual = 50;
183 /* not always true but better than nothing */
184 range->avg_qual.level = range->max_qual.level / 2;
185 range->avg_qual.noise = range->max_qual.noise / 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700186 range->avg_qual.updated = local->wstats_flags;
187
188 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
189 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
190
Hong Liu333af2f2007-07-10 19:32:08 +0200191
Johannes Berg8318d782008-01-24 19:38:38 +0100192 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
193 int i;
194 struct ieee80211_supported_band *sband;
195
196 sband = local->hw.wiphy->bands[band];
197
198 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200199 continue;
200
Johannes Berg8318d782008-01-24 19:38:38 +0100201 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
202 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200203
Johannes Berg8318d782008-01-24 19:38:38 +0100204 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
205 range->freq[c].i =
206 ieee80211_frequency_to_channel(
207 chan->center_freq);
208 range->freq[c].m = chan->center_freq;
209 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200210 c++;
211 }
Hong Liu333af2f2007-07-10 19:32:08 +0200212 }
213 }
214 range->num_channels = c;
215 range->num_frequency = c;
216
Jiri Bencf0706e82007-05-05 11:45:53 -0700217 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700218 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
219 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
220
Dan Williams374fdfb2007-12-12 10:25:07 -0500221 range->scan_capa |= IW_SCAN_CAPA_ESSID;
222
Jiri Bencf0706e82007-05-05 11:45:53 -0700223 return 0;
224}
225
226
Jiri Bencf0706e82007-05-05 11:45:53 -0700227static int ieee80211_ioctl_siwfreq(struct net_device *dev,
228 struct iw_request_info *info,
229 struct iw_freq *freq, char *extra)
230{
Jiri Bencf0706e82007-05-05 11:45:53 -0700231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
232
Johannes Berg05c914f2008-09-11 00:01:58 +0200233 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400234 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700235
236 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
237 if (freq->e == 0) {
238 if (freq->m < 0) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200239 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400240 sdata->u.sta.flags |=
241 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700242 return 0;
243 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200244 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100245 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700246 } else {
247 int i, div = 1000000;
248 for (i = 0; i < freq->e; i++)
249 div /= 10;
250 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200251 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700252 else
253 return -EINVAL;
254 }
255}
256
257
258static int ieee80211_ioctl_giwfreq(struct net_device *dev,
259 struct iw_request_info *info,
260 struct iw_freq *freq, char *extra)
261{
262 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
263
Johannes Berg8318d782008-01-24 19:38:38 +0100264 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700265 freq->e = 6;
266
267 return 0;
268}
269
270
271static int ieee80211_ioctl_siwessid(struct net_device *dev,
272 struct iw_request_info *info,
273 struct iw_point *data, char *ssid)
274{
Jiri Bencf0706e82007-05-05 11:45:53 -0700275 struct ieee80211_sub_if_data *sdata;
276 size_t len = data->length;
277
278 /* iwconfig uses nul termination in SSID.. */
279 if (len > 0 && ssid[len - 1] == '\0')
280 len--;
281
282 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200283 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
284 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700285 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200286 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700287 if (len > IEEE80211_MAX_SSID_LEN)
288 return -EINVAL;
289 memcpy(sdata->u.sta.ssid, ssid, len);
290 sdata->u.sta.ssid_len = len;
291 return 0;
292 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400293 if (data->flags)
294 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
295 else
296 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200297 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700298 if (ret)
299 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200300 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700301 return 0;
302 }
303
Jiri Bencf0706e82007-05-05 11:45:53 -0700304 return -EOPNOTSUPP;
305}
306
307
308static int ieee80211_ioctl_giwessid(struct net_device *dev,
309 struct iw_request_info *info,
310 struct iw_point *data, char *ssid)
311{
312 size_t len;
313
314 struct ieee80211_sub_if_data *sdata;
315 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200316 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
317 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200318 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700319 if (res == 0) {
320 data->length = len;
321 data->flags = 1;
322 } else
323 data->flags = 0;
324 return res;
325 }
326
Jiri Bencf0706e82007-05-05 11:45:53 -0700327 return -EOPNOTSUPP;
328}
329
330
331static int ieee80211_ioctl_siwap(struct net_device *dev,
332 struct iw_request_info *info,
333 struct sockaddr *ap_addr, char *extra)
334{
Jiri Bencf0706e82007-05-05 11:45:53 -0700335 struct ieee80211_sub_if_data *sdata;
336
337 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200338 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
339 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700340 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200341 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700342 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
343 ETH_ALEN);
344 return 0;
345 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400346 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
347 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
348 IEEE80211_STA_AUTO_CHANNEL_SEL;
349 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
350 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700351 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400352 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200353 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700354 if (ret)
355 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200356 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700357 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200358 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100359 /*
360 * If it is necessary to update the WDS peer address
361 * while the interface is running, then we need to do
362 * more work here, namely if it is running we need to
363 * add a new and remove the old STA entry, this is
364 * normally handled by _open() and _stop().
365 */
366 if (netif_running(dev))
367 return -EBUSY;
368
369 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
370 ETH_ALEN);
371
372 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700373 }
374
375 return -EOPNOTSUPP;
376}
377
378
379static int ieee80211_ioctl_giwap(struct net_device *dev,
380 struct iw_request_info *info,
381 struct sockaddr *ap_addr, char *extra)
382{
383 struct ieee80211_sub_if_data *sdata;
384
385 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200386 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
387 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300388 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
389 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700390 ap_addr->sa_family = ARPHRD_ETHER;
391 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
392 return 0;
393 } else {
394 memset(&ap_addr->sa_data, 0, ETH_ALEN);
395 return 0;
396 }
Johannes Berg05c914f2008-09-11 00:01:58 +0200397 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700398 ap_addr->sa_family = ARPHRD_ETHER;
399 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
400 return 0;
401 }
402
403 return -EOPNOTSUPP;
404}
405
406
407static int ieee80211_ioctl_siwscan(struct net_device *dev,
408 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400409 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700410{
Jiri Bencf0706e82007-05-05 11:45:53 -0700411 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400412 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700413 u8 *ssid = NULL;
414 size_t ssid_len = 0;
415
416 if (!netif_running(dev))
417 return -ENETDOWN;
418
Johannes Berg05c914f2008-09-11 00:01:58 +0200419 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
420 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Jouni Malinenb7a530d2008-12-10 14:51:47 +0200421 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
John W. Linvilled114f392007-10-17 21:16:16 -0700422 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700423
424 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400425 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
426 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
427 req = (struct iw_scan_req *)extra;
428 ssid = req->essid;
429 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700430 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200431
Johannes Bergc2b13452008-09-11 00:01:55 +0200432 return ieee80211_request_scan(sdata, ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700433}
434
435
436static int ieee80211_ioctl_giwscan(struct net_device *dev,
437 struct iw_request_info *info,
438 struct iw_point *data, char *extra)
439{
440 int res;
441 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200442 struct ieee80211_sub_if_data *sdata;
443
444 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Zhu Yiece8edd2007-11-22 10:53:21 +0800445
Johannes Bergc2b13452008-09-11 00:01:55 +0200446 if (local->sw_scanning || local->hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700447 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800448
Johannes Bergc2b13452008-09-11 00:01:55 +0200449 res = ieee80211_scan_results(local, info, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700450 if (res >= 0) {
451 data->length = res;
452 return 0;
453 }
454 data->length = 0;
455 return res;
456}
457
458
Larry Finger1fd5e582007-07-10 19:32:10 +0200459static int ieee80211_ioctl_siwrate(struct net_device *dev,
460 struct iw_request_info *info,
461 struct iw_param *rate, char *extra)
462{
463 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100464 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200465 u32 target_rate = rate->value / 100000;
466 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100467 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200468
469 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100470
471 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
472
Larry Finger1fd5e582007-07-10 19:32:10 +0200473 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
474 * target_rate = X, rate->fixed = 1 means only rate X
475 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200476 sdata->max_ratectrl_rateidx = -1;
477 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200478 if (rate->value < 0)
479 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100480
481 for (i=0; i< sband->n_bitrates; i++) {
482 struct ieee80211_rate *brate = &sband->bitrates[i];
483 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200484
Larry Finger1fd5e582007-07-10 19:32:10 +0200485 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200486 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200487 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200488 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100489 err = 0;
490 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200491 }
492 }
Johannes Berg8318d782008-01-24 19:38:38 +0100493 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200494}
495
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700496static int ieee80211_ioctl_giwrate(struct net_device *dev,
497 struct iw_request_info *info,
498 struct iw_param *rate, char *extra)
499{
500 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
501 struct sta_info *sta;
502 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100503 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700504
505 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100506
Johannes Berg05c914f2008-09-11 00:01:58 +0200507 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700508 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100509
510 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
511
Johannes Berg380a9422008-04-04 23:40:35 +0200512 rcu_read_lock();
513
514 sta = sta_info_get(local, sdata->u.sta.bssid);
515
Johannes Berge6a98542008-10-21 12:40:02 +0200516 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
517 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700518 else
519 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200520
521 rcu_read_unlock();
522
523 if (!sta)
524 return -ENODEV;
525
Johannes Berg8318d782008-01-24 19:38:38 +0100526 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100527
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700528 return 0;
529}
530
Michael Buesch61609bc2007-09-20 22:06:39 +0200531static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
532 struct iw_request_info *info,
533 union iwreq_data *data, char *extra)
534{
535 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700536 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200537 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100538 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200539
540 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
541 return -EINVAL;
542 if (data->txpower.flags & IW_TXPOW_RANGE)
543 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700544 if (!chan)
545 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200546
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700547 if (data->txpower.fixed)
548 new_power_level = min(data->txpower.value, chan->max_power);
549 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100550 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200551
Vasanthakumar Thiagarajane3c92df2008-12-24 13:53:11 +0530552 local->hw.conf.user_power_level = new_power_level;
553 if (local->hw.conf.power_level != new_power_level)
Johannes Berge8975582008-10-09 12:18:51 +0200554 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Mattias Nissler6a432952007-10-24 23:30:36 +0200555
Michael Buesch61609bc2007-09-20 22:06:39 +0200556 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
557 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200558 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100559 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200560 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200561
Johannes Berge8975582008-10-09 12:18:51 +0200562 if (reconf_flags)
563 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200564
565 return 0;
566}
567
Larry Fingerfe6aa302007-08-10 11:23:20 -0500568static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
569 struct iw_request_info *info,
570 union iwreq_data *data, char *extra)
571{
572 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
573
574 data->txpower.fixed = 1;
575 data->txpower.disabled = !(local->hw.conf.radio_enabled);
576 data->txpower.value = local->hw.conf.power_level;
577 data->txpower.flags = IW_TXPOW_DBM;
578
579 return 0;
580}
581
Jiri Bencf0706e82007-05-05 11:45:53 -0700582static int ieee80211_ioctl_siwrts(struct net_device *dev,
583 struct iw_request_info *info,
584 struct iw_param *rts, char *extra)
585{
586 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
587
588 if (rts->disabled)
589 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300590 else if (!rts->fixed)
591 /* if the rts value is not fixed, then take default */
592 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700593 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
594 return -EINVAL;
595 else
596 local->rts_threshold = rts->value;
597
598 /* If the wlan card performs RTS/CTS in hardware/firmware,
599 * configure it here */
600
601 if (local->ops->set_rts_threshold)
602 local->ops->set_rts_threshold(local_to_hw(local),
603 local->rts_threshold);
604
605 return 0;
606}
607
608static int ieee80211_ioctl_giwrts(struct net_device *dev,
609 struct iw_request_info *info,
610 struct iw_param *rts, char *extra)
611{
612 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
613
614 rts->value = local->rts_threshold;
615 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
616 rts->fixed = 1;
617
618 return 0;
619}
620
621
622static int ieee80211_ioctl_siwfrag(struct net_device *dev,
623 struct iw_request_info *info,
624 struct iw_param *frag, char *extra)
625{
626 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
627
628 if (frag->disabled)
629 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300630 else if (!frag->fixed)
631 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700632 else if (frag->value < 256 ||
633 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
634 return -EINVAL;
635 else {
636 /* Fragment length must be even, so strip LSB. */
637 local->fragmentation_threshold = frag->value & ~0x1;
638 }
639
Jiri Bencf0706e82007-05-05 11:45:53 -0700640 return 0;
641}
642
643static int ieee80211_ioctl_giwfrag(struct net_device *dev,
644 struct iw_request_info *info,
645 struct iw_param *frag, char *extra)
646{
647 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
648
649 frag->value = local->fragmentation_threshold;
650 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
651 frag->fixed = 1;
652
653 return 0;
654}
655
656
657static int ieee80211_ioctl_siwretry(struct net_device *dev,
658 struct iw_request_info *info,
659 struct iw_param *retry, char *extra)
660{
661 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
662
663 if (retry->disabled ||
664 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
665 return -EINVAL;
666
Johannes Berg9124b072008-10-14 19:17:54 +0200667 if (retry->flags & IW_RETRY_MAX) {
668 local->hw.conf.long_frame_max_tx_count = retry->value;
669 } else if (retry->flags & IW_RETRY_MIN) {
670 local->hw.conf.short_frame_max_tx_count = retry->value;
671 } else {
672 local->hw.conf.long_frame_max_tx_count = retry->value;
673 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700674 }
675
Johannes Berg9124b072008-10-14 19:17:54 +0200676 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700677
678 return 0;
679}
680
681
682static int ieee80211_ioctl_giwretry(struct net_device *dev,
683 struct iw_request_info *info,
684 struct iw_param *retry, char *extra)
685{
686 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
687
688 retry->disabled = 0;
689 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
690 /* first return min value, iwconfig will ask max value
691 * later if needed */
692 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200693 retry->value = local->hw.conf.short_frame_max_tx_count;
694 if (local->hw.conf.long_frame_max_tx_count !=
695 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700696 retry->flags |= IW_RETRY_MIN;
697 return 0;
698 }
699 if (retry->flags & IW_RETRY_MAX) {
700 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200701 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700702 }
703
704 return 0;
705}
706
Jiri Bencf0706e82007-05-05 11:45:53 -0700707static int ieee80211_ioctl_siwmlme(struct net_device *dev,
708 struct iw_request_info *info,
709 struct iw_point *data, char *extra)
710{
711 struct ieee80211_sub_if_data *sdata;
712 struct iw_mlme *mlme = (struct iw_mlme *) extra;
713
714 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200715 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
716 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700717 return -EINVAL;
718
719 switch (mlme->cmd) {
720 case IW_MLME_DEAUTH:
721 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200722 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700723 case IW_MLME_DISASSOC:
724 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200725 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700726 default:
727 return -EOPNOTSUPP;
728 }
729}
730
731
732static int ieee80211_ioctl_siwencode(struct net_device *dev,
733 struct iw_request_info *info,
734 struct iw_point *erq, char *keybuf)
735{
736 struct ieee80211_sub_if_data *sdata;
737 int idx, i, alg = ALG_WEP;
738 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200739 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700740
741 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
742
743 idx = erq->flags & IW_ENCODE_INDEX;
744 if (idx == 0) {
745 if (sdata->default_key)
746 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
747 if (sdata->default_key == sdata->keys[i]) {
748 idx = i;
749 break;
750 }
751 }
752 } else if (idx < 1 || idx > 4)
753 return -EINVAL;
754 else
755 idx--;
756
757 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200758 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700759 else if (erq->length == 0) {
760 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400761 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700762 return 0;
763 }
764
765 return ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200766 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200767 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700768 !sdata->default_key,
769 keybuf, erq->length);
770}
771
772
773static int ieee80211_ioctl_giwencode(struct net_device *dev,
774 struct iw_request_info *info,
775 struct iw_point *erq, char *key)
776{
777 struct ieee80211_sub_if_data *sdata;
778 int idx, i;
779
780 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
781
782 idx = erq->flags & IW_ENCODE_INDEX;
783 if (idx < 1 || idx > 4) {
784 idx = -1;
785 if (!sdata->default_key)
786 idx = 0;
787 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
788 if (sdata->default_key == sdata->keys[i]) {
789 idx = i;
790 break;
791 }
792 }
793 if (idx < 0)
794 return -EINVAL;
795 } else
796 idx--;
797
798 erq->flags = idx + 1;
799
800 if (!sdata->keys[idx]) {
801 erq->length = 0;
802 erq->flags |= IW_ENCODE_DISABLED;
803 return 0;
804 }
805
Johannes Berg8f20fc22007-08-28 17:01:54 -0400806 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400807 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400808 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700809 erq->flags |= IW_ENCODE_ENABLED;
810
Johannes Berg05c914f2008-09-11 00:01:58 +0200811 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300812 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
813 switch (ifsta->auth_alg) {
814 case WLAN_AUTH_OPEN:
815 case WLAN_AUTH_LEAP:
816 erq->flags |= IW_ENCODE_OPEN;
817 break;
818 case WLAN_AUTH_SHARED_KEY:
819 erq->flags |= IW_ENCODE_RESTRICTED;
820 break;
821 }
822 }
823
Jiri Bencf0706e82007-05-05 11:45:53 -0700824 return 0;
825}
826
Samuel Ortiz49292d52008-07-04 10:49:31 +0200827static int ieee80211_ioctl_siwpower(struct net_device *dev,
828 struct iw_request_info *info,
829 struct iw_param *wrq,
830 char *extra)
831{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200832 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200833 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
834 struct ieee80211_conf *conf = &local->hw.conf;
Kalle Valo520eb822008-12-18 23:35:27 +0200835 int ret = 0, timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200836 bool ps;
837
838 if (sdata->vif.type != NL80211_IFTYPE_STATION)
839 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200840
841 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200842 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200843 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200844 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200845 }
846
847 switch (wrq->flags & IW_POWER_MODE) {
848 case IW_POWER_ON: /* If not specified */
849 case IW_POWER_MODE: /* If set all mask */
850 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200851 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200852 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200853 default: /* Otherwise we ignore */
854 break;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200855 }
856
Kalle Valo520eb822008-12-18 23:35:27 +0200857 if (wrq->flags & IW_POWER_TIMEOUT)
858 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200859
860set:
Kalle Valo520eb822008-12-18 23:35:27 +0200861 if (ps == local->powersave && timeout == local->dynamic_ps_timeout)
862 return ret;
863
Kalle Valoe0cb6862008-12-18 23:35:13 +0200864 local->powersave = ps;
Kalle Valo520eb822008-12-18 23:35:27 +0200865 local->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200866
Vivek Natarajan869717f2008-12-23 18:28:34 -0800867 if (!(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS) &&
868 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)) {
869 if (local->dynamic_ps_timeout > 0)
Kalle Valo520eb822008-12-18 23:35:27 +0200870 mod_timer(&local->dynamic_ps_timer, jiffies +
871 msecs_to_jiffies(local->dynamic_ps_timeout));
872 else {
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800873 if (local->powersave) {
874 ieee80211_send_nullfunc(local, sdata, 1);
Kalle Valo520eb822008-12-18 23:35:27 +0200875 conf->flags |= IEEE80211_CONF_PS;
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800876 ret = ieee80211_hw_config(local,
877 IEEE80211_CONF_CHANGE_PS);
878 } else {
Kalle Valo520eb822008-12-18 23:35:27 +0200879 conf->flags &= ~IEEE80211_CONF_PS;
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800880 ret = ieee80211_hw_config(local,
881 IEEE80211_CONF_CHANGE_PS);
882 ieee80211_send_nullfunc(local, sdata, 0);
883 }
Kalle Valo520eb822008-12-18 23:35:27 +0200884 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200885 }
886
887 return ret;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200888}
889
890static int ieee80211_ioctl_giwpower(struct net_device *dev,
891 struct iw_request_info *info,
892 union iwreq_data *wrqu,
893 char *extra)
894{
895 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200896
Kalle Valoe0cb6862008-12-18 23:35:13 +0200897 wrqu->power.disabled = !local->powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200898
899 return 0;
900}
901
Jiri Bencf0706e82007-05-05 11:45:53 -0700902static int ieee80211_ioctl_siwauth(struct net_device *dev,
903 struct iw_request_info *info,
904 struct iw_param *data, char *extra)
905{
Jiri Bencf0706e82007-05-05 11:45:53 -0700906 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
907 int ret = 0;
908
909 switch (data->flags & IW_AUTH_INDEX) {
910 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700911 case IW_AUTH_CIPHER_GROUP:
912 case IW_AUTH_WPA_ENABLED:
913 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700914 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000915 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530916 case IW_AUTH_CIPHER_PAIRWISE:
917 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
918 if (data->value & (IW_AUTH_CIPHER_WEP40 |
919 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
920 sdata->u.sta.flags |=
921 IEEE80211_STA_TKIP_WEP_USED;
922 else
923 sdata->u.sta.flags &=
924 ~IEEE80211_STA_TKIP_WEP_USED;
925 }
926 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100927 case IW_AUTH_DROP_UNENCRYPTED:
928 sdata->drop_unencrypted = !!data->value;
929 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000930 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200931 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700932 ret = -EINVAL;
933 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000934 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700935 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000936 * Privacy invoked by wpa_supplicant, store the
937 * value and allow associating to a protected
938 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700939 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000940 if (data->value)
941 sdata->u.sta.flags |=
942 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700943 }
944 break;
945 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +0200946 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
947 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700948 sdata->u.sta.auth_algs = data->value;
949 else
950 ret = -EOPNOTSUPP;
951 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700952 default:
953 ret = -EOPNOTSUPP;
954 break;
955 }
956 return ret;
957}
958
959/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
960static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
961{
962 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
963 struct iw_statistics *wstats = &local->wstats;
964 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
965 struct sta_info *sta = NULL;
966
Johannes Berg98dd6a52008-04-10 15:36:09 +0200967 rcu_read_lock();
968
Johannes Berg05c914f2008-09-11 00:01:58 +0200969 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
970 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700971 sta = sta_info_get(local, sdata->u.sta.bssid);
972 if (!sta) {
973 wstats->discard.fragment = 0;
974 wstats->discard.misc = 0;
975 wstats->qual.qual = 0;
976 wstats->qual.level = 0;
977 wstats->qual.noise = 0;
978 wstats->qual.updated = IW_QUAL_ALL_INVALID;
979 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +0200980 wstats->qual.level = sta->last_signal;
981 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -0700982 wstats->qual.noise = sta->last_noise;
983 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -0700984 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200985
986 rcu_read_unlock();
987
Jiri Bencf0706e82007-05-05 11:45:53 -0700988 return wstats;
989}
990
991static int ieee80211_ioctl_giwauth(struct net_device *dev,
992 struct iw_request_info *info,
993 struct iw_param *data, char *extra)
994{
995 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
996 int ret = 0;
997
998 switch (data->flags & IW_AUTH_INDEX) {
999 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +02001000 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1001 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001002 data->value = sdata->u.sta.auth_algs;
1003 else
1004 ret = -EOPNOTSUPP;
1005 break;
1006 default:
1007 ret = -EOPNOTSUPP;
1008 break;
1009 }
1010 return ret;
1011}
1012
1013
1014static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1015 struct iw_request_info *info,
1016 struct iw_point *erq, char *extra)
1017{
1018 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1019 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001020 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001021
1022 switch (ext->alg) {
1023 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001024 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001025 break;
1026 case IW_ENCODE_ALG_WEP:
1027 alg = ALG_WEP;
1028 break;
1029 case IW_ENCODE_ALG_TKIP:
1030 alg = ALG_TKIP;
1031 break;
1032 case IW_ENCODE_ALG_CCMP:
1033 alg = ALG_CCMP;
1034 break;
1035 default:
1036 return -EOPNOTSUPP;
1037 }
1038
1039 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001040 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001041
1042 idx = erq->flags & IW_ENCODE_INDEX;
1043 if (idx < 1 || idx > 4) {
1044 idx = -1;
1045 if (!sdata->default_key)
1046 idx = 0;
1047 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1048 if (sdata->default_key == sdata->keys[i]) {
1049 idx = i;
1050 break;
1051 }
1052 }
1053 if (idx < 0)
1054 return -EINVAL;
1055 } else
1056 idx--;
1057
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001058 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001059 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001060 ext->ext_flags &
1061 IW_ENCODE_EXT_SET_TX_KEY,
1062 ext->key, ext->key_len);
1063}
1064
1065
Jiri Bencf0706e82007-05-05 11:45:53 -07001066/* Structures to export the Wireless Handlers */
1067
1068static const iw_handler ieee80211_handler[] =
1069{
1070 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001071 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001072 (iw_handler) NULL, /* SIOCSIWNWID */
1073 (iw_handler) NULL, /* SIOCGIWNWID */
1074 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1075 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001076 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1077 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001078 (iw_handler) NULL, /* SIOCSIWSENS */
1079 (iw_handler) NULL, /* SIOCGIWSENS */
1080 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1081 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1082 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1083 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1084 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1085 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001086 (iw_handler) NULL, /* SIOCSIWSPY */
1087 (iw_handler) NULL, /* SIOCGIWSPY */
1088 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1089 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001090 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1091 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1092 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1093 (iw_handler) NULL, /* SIOCGIWAPLIST */
1094 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1095 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1096 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1097 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1098 (iw_handler) NULL, /* SIOCSIWNICKN */
1099 (iw_handler) NULL, /* SIOCGIWNICKN */
1100 (iw_handler) NULL, /* -- hole -- */
1101 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001102 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001103 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001104 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1105 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1106 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1107 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001108 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001109 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001110 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1111 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1112 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1113 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001114 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1115 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001116 (iw_handler) NULL, /* -- hole -- */
1117 (iw_handler) NULL, /* -- hole -- */
1118 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1119 (iw_handler) NULL, /* SIOCGIWGENIE */
1120 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1121 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1122 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1123 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1124 (iw_handler) NULL, /* SIOCSIWPMKSA */
1125 (iw_handler) NULL, /* -- hole -- */
1126};
1127
Jiri Bencf0706e82007-05-05 11:45:53 -07001128const struct iw_handler_def ieee80211_iw_handler_def =
1129{
1130 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001131 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001132 .get_wireless_stats = ieee80211_get_wireless_stats,
1133};