blob: 6a342a9a40cd805609277d309b0b51bd46daee16 [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
Jiri Bencf0706e82007-05-05 11:45:53 -070030static int ieee80211_set_encryption(struct net_device *dev, 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{
35 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergd0709a62008-02-25 16:27:46 +010036 struct sta_info *sta;
Johannes Berg11a843b2007-08-28 17:01:55 -040037 struct ieee80211_key *key;
Jiri Bencf0706e82007-05-05 11:45:53 -070038 struct ieee80211_sub_if_data *sdata;
Johannes Berg3b967662008-04-08 17:56:52 +020039 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070040
41 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
42
Volker Braun139c3a02007-09-14 11:10:25 -040043 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
44 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
45 dev->name, idx);
46 return -EINVAL;
47 }
48
Johannes Berg628a1402007-09-26 17:53:17 +020049 if (remove) {
Johannes Berg3b967662008-04-08 17:56:52 +020050 rcu_read_lock();
51
52 err = 0;
53
Johannes Bergdb4d1162008-02-25 16:27:45 +010054 if (is_broadcast_ether_addr(sta_addr)) {
55 key = sdata->keys[idx];
56 } else {
57 sta = sta_info_get(local, sta_addr);
Johannes Berg3b967662008-04-08 17:56:52 +020058 if (!sta) {
59 err = -ENOENT;
60 goto out_unlock;
61 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010062 key = sta->key;
Jiri Bencf0706e82007-05-05 11:45:53 -070063 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010064
Johannes Bergd0709a62008-02-25 16:27:46 +010065 ieee80211_key_free(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +010066 } else {
67 key = ieee80211_key_alloc(alg, idx, key_len, _key);
68 if (!key)
69 return -ENOMEM;
70
Johannes Bergd0709a62008-02-25 16:27:46 +010071 sta = NULL;
Johannes Berg3b967662008-04-08 17:56:52 +020072 err = 0;
73
74 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +010075
Johannes Bergdb4d1162008-02-25 16:27:45 +010076 if (!is_broadcast_ether_addr(sta_addr)) {
77 set_tx_key = 0;
78 /*
79 * According to the standard, the key index of a
80 * pairwise key must be zero. However, some AP are
81 * broken when it comes to WEP key indices, so we
82 * work around this.
83 */
84 if (idx != 0 && alg != ALG_WEP) {
Johannes Bergd0709a62008-02-25 16:27:46 +010085 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020086 err = -EINVAL;
87 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010088 }
89
90 sta = sta_info_get(local, sta_addr);
91 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +010092 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020093 err = -ENOENT;
94 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010095 }
96 }
97
98 ieee80211_key_link(key, sdata, sta);
99
100 if (set_tx_key || (!sta && !sdata->default_key && key))
101 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700102 }
103
Johannes Berg3b967662008-04-08 17:56:52 +0200104 out_unlock:
105 rcu_read_unlock();
106
107 return err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700108}
109
110static int ieee80211_ioctl_siwgenie(struct net_device *dev,
111 struct iw_request_info *info,
112 struct iw_point *data, char *extra)
113{
114 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -0700115
116 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200117
118 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
119 return -EOPNOTSUPP;
120
Johannes Berg51fb61e2007-12-19 01:31:27 +0100121 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
122 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700123 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
124 if (ret)
125 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400126 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700127 ieee80211_sta_req_auth(dev, &sdata->u.sta);
128 return 0;
129 }
130
Jiri Bencf0706e82007-05-05 11:45:53 -0700131 return -EOPNOTSUPP;
132}
133
Jiri Bencf0706e82007-05-05 11:45:53 -0700134static int ieee80211_ioctl_giwname(struct net_device *dev,
135 struct iw_request_info *info,
136 char *name, char *extra)
137{
Johannes Berg8318d782008-01-24 19:38:38 +0100138 strcpy(name, "IEEE 802.11");
Jiri Bencf0706e82007-05-05 11:45:53 -0700139
140 return 0;
141}
142
143
144static int ieee80211_ioctl_giwrange(struct net_device *dev,
145 struct iw_request_info *info,
146 struct iw_point *data, char *extra)
147{
148 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
149 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100150 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200151 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700152
153 data->length = sizeof(struct iw_range);
154 memset(range, 0, sizeof(struct iw_range));
155
156 range->we_version_compiled = WIRELESS_EXT;
157 range->we_version_source = 21;
158 range->retry_capa = IW_RETRY_LIMIT;
159 range->retry_flags = IW_RETRY_LIMIT;
160 range->min_retry = 0;
161 range->max_retry = 255;
162 range->min_rts = 0;
163 range->max_rts = 2347;
164 range->min_frag = 256;
165 range->max_frag = 2346;
166
167 range->encoding_size[0] = 5;
168 range->encoding_size[1] = 13;
169 range->num_encoding_sizes = 2;
170 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
171
Bruno Randolf566bfe52008-05-08 19:15:40 +0200172 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
173 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
174 range->max_qual.level = local->hw.max_signal;
175 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
176 range->max_qual.level = -110;
177 else
178 range->max_qual.level = 0;
179
180 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
181 range->max_qual.noise = -110;
182 else
183 range->max_qual.noise = 0;
184
185 range->max_qual.qual = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700186 range->max_qual.updated = local->wstats_flags;
187
Bruno Randolf566bfe52008-05-08 19:15:40 +0200188 range->avg_qual.qual = 50;
189 /* not always true but better than nothing */
190 range->avg_qual.level = range->max_qual.level / 2;
191 range->avg_qual.noise = range->max_qual.noise / 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700192 range->avg_qual.updated = local->wstats_flags;
193
194 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
195 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
196
Hong Liu333af2f2007-07-10 19:32:08 +0200197
Johannes Berg8318d782008-01-24 19:38:38 +0100198 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
199 int i;
200 struct ieee80211_supported_band *sband;
201
202 sband = local->hw.wiphy->bands[band];
203
204 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200205 continue;
206
Johannes Berg8318d782008-01-24 19:38:38 +0100207 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
208 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200209
Johannes Berg8318d782008-01-24 19:38:38 +0100210 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
211 range->freq[c].i =
212 ieee80211_frequency_to_channel(
213 chan->center_freq);
214 range->freq[c].m = chan->center_freq;
215 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200216 c++;
217 }
Hong Liu333af2f2007-07-10 19:32:08 +0200218 }
219 }
220 range->num_channels = c;
221 range->num_frequency = c;
222
Jiri Bencf0706e82007-05-05 11:45:53 -0700223 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
224 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
225 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
226 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
227
Dan Williams374fdfb2007-12-12 10:25:07 -0500228 range->scan_capa |= IW_SCAN_CAPA_ESSID;
229
Jiri Bencf0706e82007-05-05 11:45:53 -0700230 return 0;
231}
232
233
Jiri Bencf0706e82007-05-05 11:45:53 -0700234static int ieee80211_ioctl_siwmode(struct net_device *dev,
235 struct iw_request_info *info,
236 __u32 *mode, char *extra)
237{
238 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
239 int type;
240
Johannes Berg51fb61e2007-12-19 01:31:27 +0100241 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700242 return -EOPNOTSUPP;
243
244 switch (*mode) {
245 case IW_MODE_INFRA:
246 type = IEEE80211_IF_TYPE_STA;
247 break;
248 case IW_MODE_ADHOC:
249 type = IEEE80211_IF_TYPE_IBSS;
250 break;
Johannes Bergb4540482008-04-14 15:37:03 +0200251 case IW_MODE_REPEAT:
252 type = IEEE80211_IF_TYPE_WDS;
253 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700254 case IW_MODE_MONITOR:
255 type = IEEE80211_IF_TYPE_MNTR;
256 break;
257 default:
258 return -EINVAL;
259 }
260
Johannes Berg51fb61e2007-12-19 01:31:27 +0100261 if (type == sdata->vif.type)
Jiri Bencf0706e82007-05-05 11:45:53 -0700262 return 0;
263 if (netif_running(dev))
264 return -EBUSY;
265
266 ieee80211_if_reinit(dev);
267 ieee80211_if_set_type(dev, type);
268
269 return 0;
270}
271
272
273static int ieee80211_ioctl_giwmode(struct net_device *dev,
274 struct iw_request_info *info,
275 __u32 *mode, char *extra)
276{
277 struct ieee80211_sub_if_data *sdata;
278
279 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100280 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700281 case IEEE80211_IF_TYPE_AP:
282 *mode = IW_MODE_MASTER;
283 break;
284 case IEEE80211_IF_TYPE_STA:
285 *mode = IW_MODE_INFRA;
286 break;
287 case IEEE80211_IF_TYPE_IBSS:
288 *mode = IW_MODE_ADHOC;
289 break;
290 case IEEE80211_IF_TYPE_MNTR:
291 *mode = IW_MODE_MONITOR;
292 break;
293 case IEEE80211_IF_TYPE_WDS:
294 *mode = IW_MODE_REPEAT;
295 break;
296 case IEEE80211_IF_TYPE_VLAN:
297 *mode = IW_MODE_SECOND; /* FIXME */
298 break;
299 default:
300 *mode = IW_MODE_AUTO;
301 break;
302 }
303 return 0;
304}
305
Johannes Berg8318d782008-01-24 19:38:38 +0100306int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700307{
Jiri Bencf0706e82007-05-05 11:45:53 -0700308 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100309 struct ieee80211_channel *chan;
Jiri Bencf0706e82007-05-05 11:45:53 -0700310
Johannes Berge048c6e2008-03-16 18:35:56 +0100311 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100312
Johannes Berge048c6e2008-03-16 18:35:56 +0100313 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
314 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100315
Mohamed Abbas675ef582008-03-20 08:14:29 -0700316 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700317 ret = 0;
318 else
319 ret = ieee80211_hw_config(local);
320
321 rate_control_clear(local);
322 }
323
324 return ret;
325}
326
327static int ieee80211_ioctl_siwfreq(struct net_device *dev,
328 struct iw_request_info *info,
329 struct iw_freq *freq, char *extra)
330{
331 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
332 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
333
Johannes Berg51fb61e2007-12-19 01:31:27 +0100334 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400335 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700336
337 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
338 if (freq->e == 0) {
339 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100340 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400341 sdata->u.sta.flags |=
342 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700343 return 0;
344 } else
Johannes Berg8318d782008-01-24 19:38:38 +0100345 return ieee80211_set_freq(local,
346 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700347 } else {
348 int i, div = 1000000;
349 for (i = 0; i < freq->e; i++)
350 div /= 10;
351 if (div > 0)
Johannes Berg8318d782008-01-24 19:38:38 +0100352 return ieee80211_set_freq(local, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700353 else
354 return -EINVAL;
355 }
356}
357
358
359static int ieee80211_ioctl_giwfreq(struct net_device *dev,
360 struct iw_request_info *info,
361 struct iw_freq *freq, char *extra)
362{
363 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
364
Johannes Berg8318d782008-01-24 19:38:38 +0100365 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700366 freq->e = 6;
367
368 return 0;
369}
370
371
372static int ieee80211_ioctl_siwessid(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_point *data, char *ssid)
375{
Jiri Bencf0706e82007-05-05 11:45:53 -0700376 struct ieee80211_sub_if_data *sdata;
377 size_t len = data->length;
378
379 /* iwconfig uses nul termination in SSID.. */
380 if (len > 0 && ssid[len - 1] == '\0')
381 len--;
382
383 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100384 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
385 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700386 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200387 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700388 if (len > IEEE80211_MAX_SSID_LEN)
389 return -EINVAL;
390 memcpy(sdata->u.sta.ssid, ssid, len);
391 sdata->u.sta.ssid_len = len;
392 return 0;
393 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400394 if (data->flags)
395 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
396 else
397 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700398 ret = ieee80211_sta_set_ssid(dev, ssid, len);
399 if (ret)
400 return ret;
401 ieee80211_sta_req_auth(dev, &sdata->u.sta);
402 return 0;
403 }
404
Johannes Berg51fb61e2007-12-19 01:31:27 +0100405 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700406 memcpy(sdata->u.ap.ssid, ssid, len);
407 memset(sdata->u.ap.ssid + len, 0,
408 IEEE80211_MAX_SSID_LEN - len);
409 sdata->u.ap.ssid_len = len;
410 return ieee80211_if_config(dev);
411 }
412 return -EOPNOTSUPP;
413}
414
415
416static int ieee80211_ioctl_giwessid(struct net_device *dev,
417 struct iw_request_info *info,
418 struct iw_point *data, char *ssid)
419{
420 size_t len;
421
422 struct ieee80211_sub_if_data *sdata;
423 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100424 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
425 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700426 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
427 if (res == 0) {
428 data->length = len;
429 data->flags = 1;
430 } else
431 data->flags = 0;
432 return res;
433 }
434
Johannes Berg51fb61e2007-12-19 01:31:27 +0100435 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700436 len = sdata->u.ap.ssid_len;
437 if (len > IW_ESSID_MAX_SIZE)
438 len = IW_ESSID_MAX_SIZE;
439 memcpy(ssid, sdata->u.ap.ssid, len);
440 data->length = len;
441 data->flags = 1;
442 return 0;
443 }
444 return -EOPNOTSUPP;
445}
446
447
448static int ieee80211_ioctl_siwap(struct net_device *dev,
449 struct iw_request_info *info,
450 struct sockaddr *ap_addr, char *extra)
451{
Jiri Bencf0706e82007-05-05 11:45:53 -0700452 struct ieee80211_sub_if_data *sdata;
453
454 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100455 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
456 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700457 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200458 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700459 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
460 ETH_ALEN);
461 return 0;
462 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400463 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
464 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
465 IEEE80211_STA_AUTO_CHANNEL_SEL;
466 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
467 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700468 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400469 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700470 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
471 if (ret)
472 return ret;
473 ieee80211_sta_req_auth(dev, &sdata->u.sta);
474 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100475 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100476 /*
477 * If it is necessary to update the WDS peer address
478 * while the interface is running, then we need to do
479 * more work here, namely if it is running we need to
480 * add a new and remove the old STA entry, this is
481 * normally handled by _open() and _stop().
482 */
483 if (netif_running(dev))
484 return -EBUSY;
485
486 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
487 ETH_ALEN);
488
489 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700490 }
491
492 return -EOPNOTSUPP;
493}
494
495
496static int ieee80211_ioctl_giwap(struct net_device *dev,
497 struct iw_request_info *info,
498 struct sockaddr *ap_addr, char *extra)
499{
500 struct ieee80211_sub_if_data *sdata;
501
502 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100503 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
504 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700505 ap_addr->sa_family = ARPHRD_ETHER;
506 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
507 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100508 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700509 ap_addr->sa_family = ARPHRD_ETHER;
510 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
511 return 0;
512 }
513
514 return -EOPNOTSUPP;
515}
516
517
518static int ieee80211_ioctl_siwscan(struct net_device *dev,
519 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400520 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700521{
Jiri Bencf0706e82007-05-05 11:45:53 -0700522 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400523 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700524 u8 *ssid = NULL;
525 size_t ssid_len = 0;
526
527 if (!netif_running(dev))
528 return -ENETDOWN;
529
Johannes Berg51fb61e2007-12-19 01:31:27 +0100530 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
531 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100532 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100533 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700534 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700535
536 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400537 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
538 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
539 req = (struct iw_scan_req *)extra;
540 ssid = req->essid;
541 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700542 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200543
Jiri Bencf0706e82007-05-05 11:45:53 -0700544 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
545}
546
547
548static int ieee80211_ioctl_giwscan(struct net_device *dev,
549 struct iw_request_info *info,
550 struct iw_point *data, char *extra)
551{
552 int res;
553 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800554
555 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700556 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800557
Jiri Bencf0706e82007-05-05 11:45:53 -0700558 res = ieee80211_sta_scan_results(dev, extra, data->length);
559 if (res >= 0) {
560 data->length = res;
561 return 0;
562 }
563 data->length = 0;
564 return res;
565}
566
567
Larry Finger1fd5e582007-07-10 19:32:10 +0200568static int ieee80211_ioctl_siwrate(struct net_device *dev,
569 struct iw_request_info *info,
570 struct iw_param *rate, char *extra)
571{
572 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100573 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200574 u32 target_rate = rate->value / 100000;
575 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100576 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200577
578 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
579 if (!sdata->bss)
580 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100581
582 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
583
Larry Finger1fd5e582007-07-10 19:32:10 +0200584 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
585 * target_rate = X, rate->fixed = 1 means only rate X
586 * target_rate = X, rate->fixed = 0 means all rates <= X */
587 sdata->bss->max_ratectrl_rateidx = -1;
588 sdata->bss->force_unicast_rateidx = -1;
589 if (rate->value < 0)
590 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100591
592 for (i=0; i< sband->n_bitrates; i++) {
593 struct ieee80211_rate *brate = &sband->bitrates[i];
594 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200595
Larry Finger1fd5e582007-07-10 19:32:10 +0200596 if (target_rate == this_rate) {
597 sdata->bss->max_ratectrl_rateidx = i;
598 if (rate->fixed)
599 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100600 err = 0;
601 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200602 }
603 }
Johannes Berg8318d782008-01-24 19:38:38 +0100604 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200605}
606
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700607static int ieee80211_ioctl_giwrate(struct net_device *dev,
608 struct iw_request_info *info,
609 struct iw_param *rate, char *extra)
610{
611 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
612 struct sta_info *sta;
613 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100614 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700615
616 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100617
Johannes Berg380a9422008-04-04 23:40:35 +0200618 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700619 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100620
621 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
622
Johannes Berg380a9422008-04-04 23:40:35 +0200623 rcu_read_lock();
624
625 sta = sta_info_get(local, sdata->u.sta.bssid);
626
627 if (sta && sta->txrate_idx < sband->n_bitrates)
Johannes Berg8318d782008-01-24 19:38:38 +0100628 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700629 else
630 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200631
632 rcu_read_unlock();
633
634 if (!sta)
635 return -ENODEV;
636
Johannes Berg8318d782008-01-24 19:38:38 +0100637 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100638
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700639 return 0;
640}
641
Michael Buesch61609bc2007-09-20 22:06:39 +0200642static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
643 struct iw_request_info *info,
644 union iwreq_data *data, char *extra)
645{
646 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
647 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100648 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200649
650 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
651 return -EINVAL;
652 if (data->txpower.flags & IW_TXPOW_RANGE)
653 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200654
Mattias Nissler6a432952007-10-24 23:30:36 +0200655 if (data->txpower.fixed) {
656 new_power_level = data->txpower.value;
657 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100658 /*
659 * Automatic power level. Use maximum power for the current
660 * channel. Should be part of rate control.
661 */
662 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200663 if (!chan)
664 return -EINVAL;
665
Johannes Berg8318d782008-01-24 19:38:38 +0100666 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200667 }
668
669 if (local->hw.conf.power_level != new_power_level) {
670 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200671 need_reconfig = 1;
672 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200673
Michael Buesch61609bc2007-09-20 22:06:39 +0200674 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
675 local->hw.conf.radio_enabled = !(data->txpower.disabled);
676 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100677 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200678 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200679
Michael Buesch61609bc2007-09-20 22:06:39 +0200680 if (need_reconfig) {
681 ieee80211_hw_config(local);
682 /* The return value of hw_config is not of big interest here,
683 * as it doesn't say that it failed because of _this_ config
684 * change or something else. Ignore it. */
685 }
686
687 return 0;
688}
689
Larry Fingerfe6aa302007-08-10 11:23:20 -0500690static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
691 struct iw_request_info *info,
692 union iwreq_data *data, char *extra)
693{
694 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
695
696 data->txpower.fixed = 1;
697 data->txpower.disabled = !(local->hw.conf.radio_enabled);
698 data->txpower.value = local->hw.conf.power_level;
699 data->txpower.flags = IW_TXPOW_DBM;
700
701 return 0;
702}
703
Jiri Bencf0706e82007-05-05 11:45:53 -0700704static int ieee80211_ioctl_siwrts(struct net_device *dev,
705 struct iw_request_info *info,
706 struct iw_param *rts, char *extra)
707{
708 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
709
710 if (rts->disabled)
711 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
712 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
713 return -EINVAL;
714 else
715 local->rts_threshold = rts->value;
716
717 /* If the wlan card performs RTS/CTS in hardware/firmware,
718 * configure it here */
719
720 if (local->ops->set_rts_threshold)
721 local->ops->set_rts_threshold(local_to_hw(local),
722 local->rts_threshold);
723
724 return 0;
725}
726
727static int ieee80211_ioctl_giwrts(struct net_device *dev,
728 struct iw_request_info *info,
729 struct iw_param *rts, char *extra)
730{
731 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
732
733 rts->value = local->rts_threshold;
734 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
735 rts->fixed = 1;
736
737 return 0;
738}
739
740
741static int ieee80211_ioctl_siwfrag(struct net_device *dev,
742 struct iw_request_info *info,
743 struct iw_param *frag, char *extra)
744{
745 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
746
747 if (frag->disabled)
748 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
749 else if (frag->value < 256 ||
750 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
751 return -EINVAL;
752 else {
753 /* Fragment length must be even, so strip LSB. */
754 local->fragmentation_threshold = frag->value & ~0x1;
755 }
756
757 /* If the wlan card performs fragmentation in hardware/firmware,
758 * configure it here */
759
760 if (local->ops->set_frag_threshold)
761 local->ops->set_frag_threshold(
762 local_to_hw(local),
763 local->fragmentation_threshold);
764
765 return 0;
766}
767
768static int ieee80211_ioctl_giwfrag(struct net_device *dev,
769 struct iw_request_info *info,
770 struct iw_param *frag, char *extra)
771{
772 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
773
774 frag->value = local->fragmentation_threshold;
775 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
776 frag->fixed = 1;
777
778 return 0;
779}
780
781
782static int ieee80211_ioctl_siwretry(struct net_device *dev,
783 struct iw_request_info *info,
784 struct iw_param *retry, char *extra)
785{
786 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
787
788 if (retry->disabled ||
789 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
790 return -EINVAL;
791
792 if (retry->flags & IW_RETRY_MAX)
793 local->long_retry_limit = retry->value;
794 else if (retry->flags & IW_RETRY_MIN)
795 local->short_retry_limit = retry->value;
796 else {
797 local->long_retry_limit = retry->value;
798 local->short_retry_limit = retry->value;
799 }
800
801 if (local->ops->set_retry_limit) {
802 return local->ops->set_retry_limit(
803 local_to_hw(local),
804 local->short_retry_limit,
805 local->long_retry_limit);
806 }
807
808 return 0;
809}
810
811
812static int ieee80211_ioctl_giwretry(struct net_device *dev,
813 struct iw_request_info *info,
814 struct iw_param *retry, char *extra)
815{
816 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
817
818 retry->disabled = 0;
819 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
820 /* first return min value, iwconfig will ask max value
821 * later if needed */
822 retry->flags |= IW_RETRY_LIMIT;
823 retry->value = local->short_retry_limit;
824 if (local->long_retry_limit != local->short_retry_limit)
825 retry->flags |= IW_RETRY_MIN;
826 return 0;
827 }
828 if (retry->flags & IW_RETRY_MAX) {
829 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
830 retry->value = local->long_retry_limit;
831 }
832
833 return 0;
834}
835
Jiri Bencf0706e82007-05-05 11:45:53 -0700836static int ieee80211_ioctl_siwmlme(struct net_device *dev,
837 struct iw_request_info *info,
838 struct iw_point *data, char *extra)
839{
840 struct ieee80211_sub_if_data *sdata;
841 struct iw_mlme *mlme = (struct iw_mlme *) extra;
842
843 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100844 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
845 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700846 return -EINVAL;
847
848 switch (mlme->cmd) {
849 case IW_MLME_DEAUTH:
850 /* TODO: mlme->addr.sa_data */
851 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
852 case IW_MLME_DISASSOC:
853 /* TODO: mlme->addr.sa_data */
854 return ieee80211_sta_disassociate(dev, mlme->reason_code);
855 default:
856 return -EOPNOTSUPP;
857 }
858}
859
860
861static int ieee80211_ioctl_siwencode(struct net_device *dev,
862 struct iw_request_info *info,
863 struct iw_point *erq, char *keybuf)
864{
865 struct ieee80211_sub_if_data *sdata;
866 int idx, i, alg = ALG_WEP;
867 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200868 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700869
870 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
871
872 idx = erq->flags & IW_ENCODE_INDEX;
873 if (idx == 0) {
874 if (sdata->default_key)
875 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
876 if (sdata->default_key == sdata->keys[i]) {
877 idx = i;
878 break;
879 }
880 }
881 } else if (idx < 1 || idx > 4)
882 return -EINVAL;
883 else
884 idx--;
885
886 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200887 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700888 else if (erq->length == 0) {
889 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400890 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700891 return 0;
892 }
893
894 return ieee80211_set_encryption(
895 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200896 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700897 !sdata->default_key,
898 keybuf, erq->length);
899}
900
901
902static int ieee80211_ioctl_giwencode(struct net_device *dev,
903 struct iw_request_info *info,
904 struct iw_point *erq, char *key)
905{
906 struct ieee80211_sub_if_data *sdata;
907 int idx, i;
908
909 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
910
911 idx = erq->flags & IW_ENCODE_INDEX;
912 if (idx < 1 || idx > 4) {
913 idx = -1;
914 if (!sdata->default_key)
915 idx = 0;
916 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
917 if (sdata->default_key == sdata->keys[i]) {
918 idx = i;
919 break;
920 }
921 }
922 if (idx < 0)
923 return -EINVAL;
924 } else
925 idx--;
926
927 erq->flags = idx + 1;
928
929 if (!sdata->keys[idx]) {
930 erq->length = 0;
931 erq->flags |= IW_ENCODE_DISABLED;
932 return 0;
933 }
934
Johannes Berg8f20fc22007-08-28 17:01:54 -0400935 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400936 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400937 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700938 erq->flags |= IW_ENCODE_ENABLED;
939
940 return 0;
941}
942
943static int ieee80211_ioctl_siwauth(struct net_device *dev,
944 struct iw_request_info *info,
945 struct iw_param *data, char *extra)
946{
Jiri Bencf0706e82007-05-05 11:45:53 -0700947 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
948 int ret = 0;
949
950 switch (data->flags & IW_AUTH_INDEX) {
951 case IW_AUTH_WPA_VERSION:
952 case IW_AUTH_CIPHER_PAIRWISE:
953 case IW_AUTH_CIPHER_GROUP:
954 case IW_AUTH_WPA_ENABLED:
955 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700956 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000957 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100958 case IW_AUTH_DROP_UNENCRYPTED:
959 sdata->drop_unencrypted = !!data->value;
960 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000961 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100962 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700963 ret = -EINVAL;
964 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000965 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700966 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000967 * Privacy invoked by wpa_supplicant, store the
968 * value and allow associating to a protected
969 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700970 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000971 if (data->value)
972 sdata->u.sta.flags |=
973 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700974 }
975 break;
976 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100977 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
978 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700979 sdata->u.sta.auth_algs = data->value;
980 else
981 ret = -EOPNOTSUPP;
982 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700983 default:
984 ret = -EOPNOTSUPP;
985 break;
986 }
987 return ret;
988}
989
990/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
991static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
992{
993 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
994 struct iw_statistics *wstats = &local->wstats;
995 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
996 struct sta_info *sta = NULL;
997
Johannes Berg98dd6a52008-04-10 15:36:09 +0200998 rcu_read_lock();
999
Johannes Berg51fb61e2007-12-19 01:31:27 +01001000 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1001 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001002 sta = sta_info_get(local, sdata->u.sta.bssid);
1003 if (!sta) {
1004 wstats->discard.fragment = 0;
1005 wstats->discard.misc = 0;
1006 wstats->qual.qual = 0;
1007 wstats->qual.level = 0;
1008 wstats->qual.noise = 0;
1009 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1010 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001011 wstats->qual.level = sta->last_signal;
1012 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001013 wstats->qual.noise = sta->last_noise;
1014 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001015 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001016
1017 rcu_read_unlock();
1018
Jiri Bencf0706e82007-05-05 11:45:53 -07001019 return wstats;
1020}
1021
1022static int ieee80211_ioctl_giwauth(struct net_device *dev,
1023 struct iw_request_info *info,
1024 struct iw_param *data, char *extra)
1025{
1026 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1027 int ret = 0;
1028
1029 switch (data->flags & IW_AUTH_INDEX) {
1030 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001031 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1032 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001033 data->value = sdata->u.sta.auth_algs;
1034 else
1035 ret = -EOPNOTSUPP;
1036 break;
1037 default:
1038 ret = -EOPNOTSUPP;
1039 break;
1040 }
1041 return ret;
1042}
1043
1044
1045static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1046 struct iw_request_info *info,
1047 struct iw_point *erq, char *extra)
1048{
1049 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1050 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001051 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001052
1053 switch (ext->alg) {
1054 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001055 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001056 break;
1057 case IW_ENCODE_ALG_WEP:
1058 alg = ALG_WEP;
1059 break;
1060 case IW_ENCODE_ALG_TKIP:
1061 alg = ALG_TKIP;
1062 break;
1063 case IW_ENCODE_ALG_CCMP:
1064 alg = ALG_CCMP;
1065 break;
1066 default:
1067 return -EOPNOTSUPP;
1068 }
1069
1070 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001071 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001072
1073 idx = erq->flags & IW_ENCODE_INDEX;
1074 if (idx < 1 || idx > 4) {
1075 idx = -1;
1076 if (!sdata->default_key)
1077 idx = 0;
1078 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1079 if (sdata->default_key == sdata->keys[i]) {
1080 idx = i;
1081 break;
1082 }
1083 }
1084 if (idx < 0)
1085 return -EINVAL;
1086 } else
1087 idx--;
1088
1089 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001090 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001091 ext->ext_flags &
1092 IW_ENCODE_EXT_SET_TX_KEY,
1093 ext->key, ext->key_len);
1094}
1095
1096
Jiri Bencf0706e82007-05-05 11:45:53 -07001097/* Structures to export the Wireless Handlers */
1098
1099static const iw_handler ieee80211_handler[] =
1100{
1101 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1102 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1103 (iw_handler) NULL, /* SIOCSIWNWID */
1104 (iw_handler) NULL, /* SIOCGIWNWID */
1105 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1106 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1107 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1108 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1109 (iw_handler) NULL, /* SIOCSIWSENS */
1110 (iw_handler) NULL, /* SIOCGIWSENS */
1111 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1112 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1113 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1114 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1115 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1116 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001117 (iw_handler) NULL, /* SIOCSIWSPY */
1118 (iw_handler) NULL, /* SIOCGIWSPY */
1119 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1120 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001121 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1122 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1123 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1124 (iw_handler) NULL, /* SIOCGIWAPLIST */
1125 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1126 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1127 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1128 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1129 (iw_handler) NULL, /* SIOCSIWNICKN */
1130 (iw_handler) NULL, /* SIOCGIWNICKN */
1131 (iw_handler) NULL, /* -- hole -- */
1132 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001133 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001134 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001135 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1136 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1137 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1138 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001139 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001140 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001141 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1142 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1143 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1144 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1145 (iw_handler) NULL, /* SIOCSIWPOWER */
1146 (iw_handler) NULL, /* SIOCGIWPOWER */
1147 (iw_handler) NULL, /* -- hole -- */
1148 (iw_handler) NULL, /* -- hole -- */
1149 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1150 (iw_handler) NULL, /* SIOCGIWGENIE */
1151 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1152 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1153 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1154 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1155 (iw_handler) NULL, /* SIOCSIWPMKSA */
1156 (iw_handler) NULL, /* -- hole -- */
1157};
1158
Jiri Bencf0706e82007-05-05 11:45:53 -07001159const struct iw_handler_def ieee80211_iw_handler_def =
1160{
1161 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001162 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001163 .get_wireless_stats = ieee80211_get_wireless_stats,
1164};