blob: 8311bb24f9f34adf35c08db9937c648097f2980a [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
172 range->max_qual.qual = local->hw.max_signal;
173 range->max_qual.level = local->hw.max_rssi;
174 range->max_qual.noise = local->hw.max_noise;
175 range->max_qual.updated = local->wstats_flags;
176
177 range->avg_qual.qual = local->hw.max_signal/2;
178 range->avg_qual.level = 0;
179 range->avg_qual.noise = 0;
180 range->avg_qual.updated = local->wstats_flags;
181
182 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
183 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
184
Hong Liu333af2f2007-07-10 19:32:08 +0200185
Johannes Berg8318d782008-01-24 19:38:38 +0100186 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
187 int i;
188 struct ieee80211_supported_band *sband;
189
190 sband = local->hw.wiphy->bands[band];
191
192 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200193 continue;
194
Johannes Berg8318d782008-01-24 19:38:38 +0100195 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
196 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200197
Johannes Berg8318d782008-01-24 19:38:38 +0100198 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
199 range->freq[c].i =
200 ieee80211_frequency_to_channel(
201 chan->center_freq);
202 range->freq[c].m = chan->center_freq;
203 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200204 c++;
205 }
Hong Liu333af2f2007-07-10 19:32:08 +0200206 }
207 }
208 range->num_channels = c;
209 range->num_frequency = c;
210
Jiri Bencf0706e82007-05-05 11:45:53 -0700211 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700212 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
213 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
214
Dan Williams374fdfb2007-12-12 10:25:07 -0500215 range->scan_capa |= IW_SCAN_CAPA_ESSID;
216
Jiri Bencf0706e82007-05-05 11:45:53 -0700217 return 0;
218}
219
220
Jiri Bencf0706e82007-05-05 11:45:53 -0700221static int ieee80211_ioctl_siwmode(struct net_device *dev,
222 struct iw_request_info *info,
223 __u32 *mode, char *extra)
224{
225 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
226 int type;
227
Johannes Berg51fb61e2007-12-19 01:31:27 +0100228 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700229 return -EOPNOTSUPP;
230
231 switch (*mode) {
232 case IW_MODE_INFRA:
233 type = IEEE80211_IF_TYPE_STA;
234 break;
235 case IW_MODE_ADHOC:
236 type = IEEE80211_IF_TYPE_IBSS;
237 break;
Johannes Bergb4540482008-04-14 15:37:03 +0200238 case IW_MODE_REPEAT:
239 type = IEEE80211_IF_TYPE_WDS;
240 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700241 case IW_MODE_MONITOR:
242 type = IEEE80211_IF_TYPE_MNTR;
243 break;
244 default:
245 return -EINVAL;
246 }
247
Johannes Berg51fb61e2007-12-19 01:31:27 +0100248 if (type == sdata->vif.type)
Jiri Bencf0706e82007-05-05 11:45:53 -0700249 return 0;
250 if (netif_running(dev))
251 return -EBUSY;
252
253 ieee80211_if_reinit(dev);
254 ieee80211_if_set_type(dev, type);
255
256 return 0;
257}
258
259
260static int ieee80211_ioctl_giwmode(struct net_device *dev,
261 struct iw_request_info *info,
262 __u32 *mode, char *extra)
263{
264 struct ieee80211_sub_if_data *sdata;
265
266 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100267 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700268 case IEEE80211_IF_TYPE_AP:
269 *mode = IW_MODE_MASTER;
270 break;
271 case IEEE80211_IF_TYPE_STA:
272 *mode = IW_MODE_INFRA;
273 break;
274 case IEEE80211_IF_TYPE_IBSS:
275 *mode = IW_MODE_ADHOC;
276 break;
277 case IEEE80211_IF_TYPE_MNTR:
278 *mode = IW_MODE_MONITOR;
279 break;
280 case IEEE80211_IF_TYPE_WDS:
281 *mode = IW_MODE_REPEAT;
282 break;
283 case IEEE80211_IF_TYPE_VLAN:
284 *mode = IW_MODE_SECOND; /* FIXME */
285 break;
286 default:
287 *mode = IW_MODE_AUTO;
288 break;
289 }
290 return 0;
291}
292
Johannes Berg8318d782008-01-24 19:38:38 +0100293int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700294{
Jiri Bencf0706e82007-05-05 11:45:53 -0700295 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100296 struct ieee80211_channel *chan;
Jiri Bencf0706e82007-05-05 11:45:53 -0700297
Johannes Berge048c6e2008-03-16 18:35:56 +0100298 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100299
Johannes Berge048c6e2008-03-16 18:35:56 +0100300 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
301 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100302
Mohamed Abbas675ef582008-03-20 08:14:29 -0700303 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700304 ret = 0;
305 else
306 ret = ieee80211_hw_config(local);
307
308 rate_control_clear(local);
309 }
310
311 return ret;
312}
313
314static int ieee80211_ioctl_siwfreq(struct net_device *dev,
315 struct iw_request_info *info,
316 struct iw_freq *freq, char *extra)
317{
318 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
319 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
320
Johannes Berg51fb61e2007-12-19 01:31:27 +0100321 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400322 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700323
324 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
325 if (freq->e == 0) {
326 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100327 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400328 sdata->u.sta.flags |=
329 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700330 return 0;
331 } else
Johannes Berg8318d782008-01-24 19:38:38 +0100332 return ieee80211_set_freq(local,
333 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700334 } else {
335 int i, div = 1000000;
336 for (i = 0; i < freq->e; i++)
337 div /= 10;
338 if (div > 0)
Johannes Berg8318d782008-01-24 19:38:38 +0100339 return ieee80211_set_freq(local, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700340 else
341 return -EINVAL;
342 }
343}
344
345
346static int ieee80211_ioctl_giwfreq(struct net_device *dev,
347 struct iw_request_info *info,
348 struct iw_freq *freq, char *extra)
349{
350 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
351
Johannes Berg8318d782008-01-24 19:38:38 +0100352 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700353 freq->e = 6;
354
355 return 0;
356}
357
358
359static int ieee80211_ioctl_siwessid(struct net_device *dev,
360 struct iw_request_info *info,
361 struct iw_point *data, char *ssid)
362{
Jiri Bencf0706e82007-05-05 11:45:53 -0700363 struct ieee80211_sub_if_data *sdata;
364 size_t len = data->length;
365
366 /* iwconfig uses nul termination in SSID.. */
367 if (len > 0 && ssid[len - 1] == '\0')
368 len--;
369
370 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100371 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
372 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700373 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200374 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700375 if (len > IEEE80211_MAX_SSID_LEN)
376 return -EINVAL;
377 memcpy(sdata->u.sta.ssid, ssid, len);
378 sdata->u.sta.ssid_len = len;
379 return 0;
380 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400381 if (data->flags)
382 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
383 else
384 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700385 ret = ieee80211_sta_set_ssid(dev, ssid, len);
386 if (ret)
387 return ret;
388 ieee80211_sta_req_auth(dev, &sdata->u.sta);
389 return 0;
390 }
391
Johannes Berg51fb61e2007-12-19 01:31:27 +0100392 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700393 memcpy(sdata->u.ap.ssid, ssid, len);
394 memset(sdata->u.ap.ssid + len, 0,
395 IEEE80211_MAX_SSID_LEN - len);
396 sdata->u.ap.ssid_len = len;
397 return ieee80211_if_config(dev);
398 }
399 return -EOPNOTSUPP;
400}
401
402
403static int ieee80211_ioctl_giwessid(struct net_device *dev,
404 struct iw_request_info *info,
405 struct iw_point *data, char *ssid)
406{
407 size_t len;
408
409 struct ieee80211_sub_if_data *sdata;
410 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100411 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
412 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700413 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
414 if (res == 0) {
415 data->length = len;
416 data->flags = 1;
417 } else
418 data->flags = 0;
419 return res;
420 }
421
Johannes Berg51fb61e2007-12-19 01:31:27 +0100422 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700423 len = sdata->u.ap.ssid_len;
424 if (len > IW_ESSID_MAX_SIZE)
425 len = IW_ESSID_MAX_SIZE;
426 memcpy(ssid, sdata->u.ap.ssid, len);
427 data->length = len;
428 data->flags = 1;
429 return 0;
430 }
431 return -EOPNOTSUPP;
432}
433
434
435static int ieee80211_ioctl_siwap(struct net_device *dev,
436 struct iw_request_info *info,
437 struct sockaddr *ap_addr, char *extra)
438{
Jiri Bencf0706e82007-05-05 11:45:53 -0700439 struct ieee80211_sub_if_data *sdata;
440
441 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100442 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
443 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700444 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200445 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700446 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
447 ETH_ALEN);
448 return 0;
449 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400450 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
451 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
452 IEEE80211_STA_AUTO_CHANNEL_SEL;
453 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
454 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700455 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400456 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700457 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
458 if (ret)
459 return ret;
460 ieee80211_sta_req_auth(dev, &sdata->u.sta);
461 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100462 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100463 /*
464 * If it is necessary to update the WDS peer address
465 * while the interface is running, then we need to do
466 * more work here, namely if it is running we need to
467 * add a new and remove the old STA entry, this is
468 * normally handled by _open() and _stop().
469 */
470 if (netif_running(dev))
471 return -EBUSY;
472
473 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
474 ETH_ALEN);
475
476 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700477 }
478
479 return -EOPNOTSUPP;
480}
481
482
483static int ieee80211_ioctl_giwap(struct net_device *dev,
484 struct iw_request_info *info,
485 struct sockaddr *ap_addr, char *extra)
486{
487 struct ieee80211_sub_if_data *sdata;
488
489 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100490 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
491 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700492 if (sdata->u.sta.state == IEEE80211_ASSOCIATED) {
493 ap_addr->sa_family = ARPHRD_ETHER;
494 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
495 return 0;
496 } else {
497 memset(&ap_addr->sa_data, 0, ETH_ALEN);
498 return 0;
499 }
Johannes Berg51fb61e2007-12-19 01:31:27 +0100500 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700501 ap_addr->sa_family = ARPHRD_ETHER;
502 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
503 return 0;
504 }
505
506 return -EOPNOTSUPP;
507}
508
509
510static int ieee80211_ioctl_siwscan(struct net_device *dev,
511 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400512 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700513{
Jiri Bencf0706e82007-05-05 11:45:53 -0700514 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400515 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700516 u8 *ssid = NULL;
517 size_t ssid_len = 0;
518
519 if (!netif_running(dev))
520 return -ENETDOWN;
521
Johannes Berg51fb61e2007-12-19 01:31:27 +0100522 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
523 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100524 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100525 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700526 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700527
528 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400529 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
530 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
531 req = (struct iw_scan_req *)extra;
532 ssid = req->essid;
533 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700534 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200535
Jiri Bencf0706e82007-05-05 11:45:53 -0700536 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
537}
538
539
540static int ieee80211_ioctl_giwscan(struct net_device *dev,
541 struct iw_request_info *info,
542 struct iw_point *data, char *extra)
543{
544 int res;
545 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800546
547 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700548 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800549
Jiri Bencf0706e82007-05-05 11:45:53 -0700550 res = ieee80211_sta_scan_results(dev, extra, data->length);
551 if (res >= 0) {
552 data->length = res;
553 return 0;
554 }
555 data->length = 0;
556 return res;
557}
558
559
Larry Finger1fd5e582007-07-10 19:32:10 +0200560static int ieee80211_ioctl_siwrate(struct net_device *dev,
561 struct iw_request_info *info,
562 struct iw_param *rate, char *extra)
563{
564 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100565 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200566 u32 target_rate = rate->value / 100000;
567 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100568 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200569
570 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
571 if (!sdata->bss)
572 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100573
574 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
575
Larry Finger1fd5e582007-07-10 19:32:10 +0200576 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
577 * target_rate = X, rate->fixed = 1 means only rate X
578 * target_rate = X, rate->fixed = 0 means all rates <= X */
579 sdata->bss->max_ratectrl_rateidx = -1;
580 sdata->bss->force_unicast_rateidx = -1;
581 if (rate->value < 0)
582 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100583
584 for (i=0; i< sband->n_bitrates; i++) {
585 struct ieee80211_rate *brate = &sband->bitrates[i];
586 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200587
Larry Finger1fd5e582007-07-10 19:32:10 +0200588 if (target_rate == this_rate) {
589 sdata->bss->max_ratectrl_rateidx = i;
590 if (rate->fixed)
591 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100592 err = 0;
593 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200594 }
595 }
Johannes Berg8318d782008-01-24 19:38:38 +0100596 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200597}
598
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700599static int ieee80211_ioctl_giwrate(struct net_device *dev,
600 struct iw_request_info *info,
601 struct iw_param *rate, char *extra)
602{
603 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
604 struct sta_info *sta;
605 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100606 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700607
608 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100609
Johannes Berg380a9422008-04-04 23:40:35 +0200610 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700611 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100612
613 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
614
Johannes Berg380a9422008-04-04 23:40:35 +0200615 rcu_read_lock();
616
617 sta = sta_info_get(local, sdata->u.sta.bssid);
618
619 if (sta && sta->txrate_idx < sband->n_bitrates)
Johannes Berg8318d782008-01-24 19:38:38 +0100620 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700621 else
622 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200623
624 rcu_read_unlock();
625
626 if (!sta)
627 return -ENODEV;
628
Johannes Berg8318d782008-01-24 19:38:38 +0100629 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100630
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700631 return 0;
632}
633
Michael Buesch61609bc2007-09-20 22:06:39 +0200634static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
635 struct iw_request_info *info,
636 union iwreq_data *data, char *extra)
637{
638 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
639 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100640 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200641
642 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
643 return -EINVAL;
644 if (data->txpower.flags & IW_TXPOW_RANGE)
645 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200646
Mattias Nissler6a432952007-10-24 23:30:36 +0200647 if (data->txpower.fixed) {
648 new_power_level = data->txpower.value;
649 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100650 /*
651 * Automatic power level. Use maximum power for the current
652 * channel. Should be part of rate control.
653 */
654 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200655 if (!chan)
656 return -EINVAL;
657
Johannes Berg8318d782008-01-24 19:38:38 +0100658 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200659 }
660
661 if (local->hw.conf.power_level != new_power_level) {
662 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200663 need_reconfig = 1;
664 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200665
Michael Buesch61609bc2007-09-20 22:06:39 +0200666 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
667 local->hw.conf.radio_enabled = !(data->txpower.disabled);
668 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100669 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200670 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200671
Michael Buesch61609bc2007-09-20 22:06:39 +0200672 if (need_reconfig) {
673 ieee80211_hw_config(local);
674 /* The return value of hw_config is not of big interest here,
675 * as it doesn't say that it failed because of _this_ config
676 * change or something else. Ignore it. */
677 }
678
679 return 0;
680}
681
Larry Fingerfe6aa302007-08-10 11:23:20 -0500682static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
683 struct iw_request_info *info,
684 union iwreq_data *data, char *extra)
685{
686 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
687
688 data->txpower.fixed = 1;
689 data->txpower.disabled = !(local->hw.conf.radio_enabled);
690 data->txpower.value = local->hw.conf.power_level;
691 data->txpower.flags = IW_TXPOW_DBM;
692
693 return 0;
694}
695
Jiri Bencf0706e82007-05-05 11:45:53 -0700696static int ieee80211_ioctl_siwrts(struct net_device *dev,
697 struct iw_request_info *info,
698 struct iw_param *rts, char *extra)
699{
700 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
701
702 if (rts->disabled)
703 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
704 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
705 return -EINVAL;
706 else
707 local->rts_threshold = rts->value;
708
709 /* If the wlan card performs RTS/CTS in hardware/firmware,
710 * configure it here */
711
712 if (local->ops->set_rts_threshold)
713 local->ops->set_rts_threshold(local_to_hw(local),
714 local->rts_threshold);
715
716 return 0;
717}
718
719static int ieee80211_ioctl_giwrts(struct net_device *dev,
720 struct iw_request_info *info,
721 struct iw_param *rts, char *extra)
722{
723 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
724
725 rts->value = local->rts_threshold;
726 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
727 rts->fixed = 1;
728
729 return 0;
730}
731
732
733static int ieee80211_ioctl_siwfrag(struct net_device *dev,
734 struct iw_request_info *info,
735 struct iw_param *frag, char *extra)
736{
737 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
738
739 if (frag->disabled)
740 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
741 else if (frag->value < 256 ||
742 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
743 return -EINVAL;
744 else {
745 /* Fragment length must be even, so strip LSB. */
746 local->fragmentation_threshold = frag->value & ~0x1;
747 }
748
749 /* If the wlan card performs fragmentation in hardware/firmware,
750 * configure it here */
751
752 if (local->ops->set_frag_threshold)
753 local->ops->set_frag_threshold(
754 local_to_hw(local),
755 local->fragmentation_threshold);
756
757 return 0;
758}
759
760static int ieee80211_ioctl_giwfrag(struct net_device *dev,
761 struct iw_request_info *info,
762 struct iw_param *frag, char *extra)
763{
764 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
765
766 frag->value = local->fragmentation_threshold;
767 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
768 frag->fixed = 1;
769
770 return 0;
771}
772
773
774static int ieee80211_ioctl_siwretry(struct net_device *dev,
775 struct iw_request_info *info,
776 struct iw_param *retry, char *extra)
777{
778 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
779
780 if (retry->disabled ||
781 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
782 return -EINVAL;
783
784 if (retry->flags & IW_RETRY_MAX)
785 local->long_retry_limit = retry->value;
786 else if (retry->flags & IW_RETRY_MIN)
787 local->short_retry_limit = retry->value;
788 else {
789 local->long_retry_limit = retry->value;
790 local->short_retry_limit = retry->value;
791 }
792
793 if (local->ops->set_retry_limit) {
794 return local->ops->set_retry_limit(
795 local_to_hw(local),
796 local->short_retry_limit,
797 local->long_retry_limit);
798 }
799
800 return 0;
801}
802
803
804static int ieee80211_ioctl_giwretry(struct net_device *dev,
805 struct iw_request_info *info,
806 struct iw_param *retry, char *extra)
807{
808 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
809
810 retry->disabled = 0;
811 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
812 /* first return min value, iwconfig will ask max value
813 * later if needed */
814 retry->flags |= IW_RETRY_LIMIT;
815 retry->value = local->short_retry_limit;
816 if (local->long_retry_limit != local->short_retry_limit)
817 retry->flags |= IW_RETRY_MIN;
818 return 0;
819 }
820 if (retry->flags & IW_RETRY_MAX) {
821 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
822 retry->value = local->long_retry_limit;
823 }
824
825 return 0;
826}
827
Jiri Bencf0706e82007-05-05 11:45:53 -0700828static int ieee80211_ioctl_siwmlme(struct net_device *dev,
829 struct iw_request_info *info,
830 struct iw_point *data, char *extra)
831{
832 struct ieee80211_sub_if_data *sdata;
833 struct iw_mlme *mlme = (struct iw_mlme *) extra;
834
835 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100836 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
837 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700838 return -EINVAL;
839
840 switch (mlme->cmd) {
841 case IW_MLME_DEAUTH:
842 /* TODO: mlme->addr.sa_data */
843 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
844 case IW_MLME_DISASSOC:
845 /* TODO: mlme->addr.sa_data */
846 return ieee80211_sta_disassociate(dev, mlme->reason_code);
847 default:
848 return -EOPNOTSUPP;
849 }
850}
851
852
853static int ieee80211_ioctl_siwencode(struct net_device *dev,
854 struct iw_request_info *info,
855 struct iw_point *erq, char *keybuf)
856{
857 struct ieee80211_sub_if_data *sdata;
858 int idx, i, alg = ALG_WEP;
859 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200860 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700861
862 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
863
864 idx = erq->flags & IW_ENCODE_INDEX;
865 if (idx == 0) {
866 if (sdata->default_key)
867 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
868 if (sdata->default_key == sdata->keys[i]) {
869 idx = i;
870 break;
871 }
872 }
873 } else if (idx < 1 || idx > 4)
874 return -EINVAL;
875 else
876 idx--;
877
878 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200879 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700880 else if (erq->length == 0) {
881 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400882 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700883 return 0;
884 }
885
886 return ieee80211_set_encryption(
887 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200888 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700889 !sdata->default_key,
890 keybuf, erq->length);
891}
892
893
894static int ieee80211_ioctl_giwencode(struct net_device *dev,
895 struct iw_request_info *info,
896 struct iw_point *erq, char *key)
897{
898 struct ieee80211_sub_if_data *sdata;
899 int idx, i;
900
901 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
902
903 idx = erq->flags & IW_ENCODE_INDEX;
904 if (idx < 1 || idx > 4) {
905 idx = -1;
906 if (!sdata->default_key)
907 idx = 0;
908 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
909 if (sdata->default_key == sdata->keys[i]) {
910 idx = i;
911 break;
912 }
913 }
914 if (idx < 0)
915 return -EINVAL;
916 } else
917 idx--;
918
919 erq->flags = idx + 1;
920
921 if (!sdata->keys[idx]) {
922 erq->length = 0;
923 erq->flags |= IW_ENCODE_DISABLED;
924 return 0;
925 }
926
Johannes Berg8f20fc22007-08-28 17:01:54 -0400927 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400928 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400929 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700930 erq->flags |= IW_ENCODE_ENABLED;
931
932 return 0;
933}
934
935static int ieee80211_ioctl_siwauth(struct net_device *dev,
936 struct iw_request_info *info,
937 struct iw_param *data, char *extra)
938{
Jiri Bencf0706e82007-05-05 11:45:53 -0700939 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
940 int ret = 0;
941
942 switch (data->flags & IW_AUTH_INDEX) {
943 case IW_AUTH_WPA_VERSION:
944 case IW_AUTH_CIPHER_PAIRWISE:
945 case IW_AUTH_CIPHER_GROUP:
946 case IW_AUTH_WPA_ENABLED:
947 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700948 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000949 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100950 case IW_AUTH_DROP_UNENCRYPTED:
951 sdata->drop_unencrypted = !!data->value;
952 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000953 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100954 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700955 ret = -EINVAL;
956 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000957 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700958 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000959 * Privacy invoked by wpa_supplicant, store the
960 * value and allow associating to a protected
961 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700962 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000963 if (data->value)
964 sdata->u.sta.flags |=
965 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700966 }
967 break;
968 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100969 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
970 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700971 sdata->u.sta.auth_algs = data->value;
972 else
973 ret = -EOPNOTSUPP;
974 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700975 default:
976 ret = -EOPNOTSUPP;
977 break;
978 }
979 return ret;
980}
981
982/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
983static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
984{
985 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
986 struct iw_statistics *wstats = &local->wstats;
987 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
988 struct sta_info *sta = NULL;
989
Johannes Berg98dd6a52008-04-10 15:36:09 +0200990 rcu_read_lock();
991
Johannes Berg51fb61e2007-12-19 01:31:27 +0100992 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
993 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700994 sta = sta_info_get(local, sdata->u.sta.bssid);
995 if (!sta) {
996 wstats->discard.fragment = 0;
997 wstats->discard.misc = 0;
998 wstats->qual.qual = 0;
999 wstats->qual.level = 0;
1000 wstats->qual.noise = 0;
1001 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1002 } else {
1003 wstats->qual.level = sta->last_rssi;
1004 wstats->qual.qual = sta->last_signal;
1005 wstats->qual.noise = sta->last_noise;
1006 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001007 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001008
1009 rcu_read_unlock();
1010
Jiri Bencf0706e82007-05-05 11:45:53 -07001011 return wstats;
1012}
1013
1014static int ieee80211_ioctl_giwauth(struct net_device *dev,
1015 struct iw_request_info *info,
1016 struct iw_param *data, char *extra)
1017{
1018 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1019 int ret = 0;
1020
1021 switch (data->flags & IW_AUTH_INDEX) {
1022 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001023 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1024 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001025 data->value = sdata->u.sta.auth_algs;
1026 else
1027 ret = -EOPNOTSUPP;
1028 break;
1029 default:
1030 ret = -EOPNOTSUPP;
1031 break;
1032 }
1033 return ret;
1034}
1035
1036
1037static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1038 struct iw_request_info *info,
1039 struct iw_point *erq, char *extra)
1040{
1041 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1042 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001043 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001044
1045 switch (ext->alg) {
1046 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001047 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001048 break;
1049 case IW_ENCODE_ALG_WEP:
1050 alg = ALG_WEP;
1051 break;
1052 case IW_ENCODE_ALG_TKIP:
1053 alg = ALG_TKIP;
1054 break;
1055 case IW_ENCODE_ALG_CCMP:
1056 alg = ALG_CCMP;
1057 break;
1058 default:
1059 return -EOPNOTSUPP;
1060 }
1061
1062 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001063 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001064
1065 idx = erq->flags & IW_ENCODE_INDEX;
1066 if (idx < 1 || idx > 4) {
1067 idx = -1;
1068 if (!sdata->default_key)
1069 idx = 0;
1070 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1071 if (sdata->default_key == sdata->keys[i]) {
1072 idx = i;
1073 break;
1074 }
1075 }
1076 if (idx < 0)
1077 return -EINVAL;
1078 } else
1079 idx--;
1080
1081 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001082 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001083 ext->ext_flags &
1084 IW_ENCODE_EXT_SET_TX_KEY,
1085 ext->key, ext->key_len);
1086}
1087
1088
Jiri Bencf0706e82007-05-05 11:45:53 -07001089/* Structures to export the Wireless Handlers */
1090
1091static const iw_handler ieee80211_handler[] =
1092{
1093 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1094 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1095 (iw_handler) NULL, /* SIOCSIWNWID */
1096 (iw_handler) NULL, /* SIOCGIWNWID */
1097 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1098 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1099 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1100 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1101 (iw_handler) NULL, /* SIOCSIWSENS */
1102 (iw_handler) NULL, /* SIOCGIWSENS */
1103 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1104 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1105 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1106 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1107 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1108 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001109 (iw_handler) NULL, /* SIOCSIWSPY */
1110 (iw_handler) NULL, /* SIOCGIWSPY */
1111 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1112 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001113 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1114 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1115 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1116 (iw_handler) NULL, /* SIOCGIWAPLIST */
1117 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1118 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1119 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1120 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1121 (iw_handler) NULL, /* SIOCSIWNICKN */
1122 (iw_handler) NULL, /* SIOCGIWNICKN */
1123 (iw_handler) NULL, /* -- hole -- */
1124 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001125 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001126 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001127 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1128 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1129 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1130 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001131 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001132 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001133 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1134 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1135 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1136 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1137 (iw_handler) NULL, /* SIOCSIWPOWER */
1138 (iw_handler) NULL, /* SIOCGIWPOWER */
1139 (iw_handler) NULL, /* -- hole -- */
1140 (iw_handler) NULL, /* -- hole -- */
1141 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1142 (iw_handler) NULL, /* SIOCGIWGENIE */
1143 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1144 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1145 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1146 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1147 (iw_handler) NULL, /* SIOCSIWPMKSA */
1148 (iw_handler) NULL, /* -- hole -- */
1149};
1150
Jiri Bencf0706e82007-05-05 11:45:53 -07001151const struct iw_handler_def ieee80211_iw_handler_def =
1152{
1153 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001154 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001155 .get_wireless_stats = ieee80211_get_wireless_stats,
1156};