blob: 3cbaf5301d00e4cc4091178fbf76ad3a344961bb [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);
Jiri Bencf0706e82007-05-05 11:45:53 -0700224 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
225 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
226
Dan Williams374fdfb2007-12-12 10:25:07 -0500227 range->scan_capa |= IW_SCAN_CAPA_ESSID;
228
Jiri Bencf0706e82007-05-05 11:45:53 -0700229 return 0;
230}
231
232
Jiri Bencf0706e82007-05-05 11:45:53 -0700233static int ieee80211_ioctl_siwmode(struct net_device *dev,
234 struct iw_request_info *info,
235 __u32 *mode, char *extra)
236{
237 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
238 int type;
239
Johannes Berg51fb61e2007-12-19 01:31:27 +0100240 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700241 return -EOPNOTSUPP;
242
243 switch (*mode) {
244 case IW_MODE_INFRA:
245 type = IEEE80211_IF_TYPE_STA;
246 break;
247 case IW_MODE_ADHOC:
248 type = IEEE80211_IF_TYPE_IBSS;
249 break;
Johannes Bergb4540482008-04-14 15:37:03 +0200250 case IW_MODE_REPEAT:
251 type = IEEE80211_IF_TYPE_WDS;
252 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700253 case IW_MODE_MONITOR:
254 type = IEEE80211_IF_TYPE_MNTR;
255 break;
256 default:
257 return -EINVAL;
258 }
259
Johannes Berg51fb61e2007-12-19 01:31:27 +0100260 if (type == sdata->vif.type)
Jiri Bencf0706e82007-05-05 11:45:53 -0700261 return 0;
262 if (netif_running(dev))
263 return -EBUSY;
264
265 ieee80211_if_reinit(dev);
266 ieee80211_if_set_type(dev, type);
267
268 return 0;
269}
270
271
272static int ieee80211_ioctl_giwmode(struct net_device *dev,
273 struct iw_request_info *info,
274 __u32 *mode, char *extra)
275{
276 struct ieee80211_sub_if_data *sdata;
277
278 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100279 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700280 case IEEE80211_IF_TYPE_AP:
281 *mode = IW_MODE_MASTER;
282 break;
283 case IEEE80211_IF_TYPE_STA:
284 *mode = IW_MODE_INFRA;
285 break;
286 case IEEE80211_IF_TYPE_IBSS:
287 *mode = IW_MODE_ADHOC;
288 break;
289 case IEEE80211_IF_TYPE_MNTR:
290 *mode = IW_MODE_MONITOR;
291 break;
292 case IEEE80211_IF_TYPE_WDS:
293 *mode = IW_MODE_REPEAT;
294 break;
295 case IEEE80211_IF_TYPE_VLAN:
296 *mode = IW_MODE_SECOND; /* FIXME */
297 break;
298 default:
299 *mode = IW_MODE_AUTO;
300 break;
301 }
302 return 0;
303}
304
Assaf Kraussbe038b32008-06-05 19:55:21 +0300305int ieee80211_set_freq(struct net_device *dev, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700306{
Jiri Bencf0706e82007-05-05 11:45:53 -0700307 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100308 struct ieee80211_channel *chan;
Assaf Kraussbe038b32008-06-05 19:55:21 +0300309 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
310 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700311
Johannes Berge048c6e2008-03-16 18:35:56 +0100312 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100313
Johannes Berge048c6e2008-03-16 18:35:56 +0100314 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Assaf Kraussbe038b32008-06-05 19:55:21 +0300315 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
316 chan->flags & IEEE80211_CHAN_NO_IBSS) {
317 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
318 "%d MHz\n", dev->name, chan->center_freq);
319 return ret;
320 }
Johannes Berge048c6e2008-03-16 18:35:56 +0100321 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100322
Mohamed Abbas675ef582008-03-20 08:14:29 -0700323 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700324 ret = 0;
325 else
326 ret = ieee80211_hw_config(local);
327
328 rate_control_clear(local);
329 }
330
331 return ret;
332}
333
334static int ieee80211_ioctl_siwfreq(struct net_device *dev,
335 struct iw_request_info *info,
336 struct iw_freq *freq, char *extra)
337{
Jiri Bencf0706e82007-05-05 11:45:53 -0700338 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
339
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 &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700342
343 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
344 if (freq->e == 0) {
345 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100346 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400347 sdata->u.sta.flags |=
348 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700349 return 0;
350 } else
Assaf Kraussbe038b32008-06-05 19:55:21 +0300351 return ieee80211_set_freq(dev,
Johannes Berg8318d782008-01-24 19:38:38 +0100352 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700353 } else {
354 int i, div = 1000000;
355 for (i = 0; i < freq->e; i++)
356 div /= 10;
357 if (div > 0)
Assaf Kraussbe038b32008-06-05 19:55:21 +0300358 return ieee80211_set_freq(dev, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700359 else
360 return -EINVAL;
361 }
362}
363
364
365static int ieee80211_ioctl_giwfreq(struct net_device *dev,
366 struct iw_request_info *info,
367 struct iw_freq *freq, char *extra)
368{
369 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
370
Johannes Berg8318d782008-01-24 19:38:38 +0100371 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700372 freq->e = 6;
373
374 return 0;
375}
376
377
378static int ieee80211_ioctl_siwessid(struct net_device *dev,
379 struct iw_request_info *info,
380 struct iw_point *data, char *ssid)
381{
Jiri Bencf0706e82007-05-05 11:45:53 -0700382 struct ieee80211_sub_if_data *sdata;
383 size_t len = data->length;
384
385 /* iwconfig uses nul termination in SSID.. */
386 if (len > 0 && ssid[len - 1] == '\0')
387 len--;
388
389 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100390 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
391 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700392 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200393 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700394 if (len > IEEE80211_MAX_SSID_LEN)
395 return -EINVAL;
396 memcpy(sdata->u.sta.ssid, ssid, len);
397 sdata->u.sta.ssid_len = len;
398 return 0;
399 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400400 if (data->flags)
401 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
402 else
403 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700404 ret = ieee80211_sta_set_ssid(dev, ssid, len);
405 if (ret)
406 return ret;
407 ieee80211_sta_req_auth(dev, &sdata->u.sta);
408 return 0;
409 }
410
Johannes Berg51fb61e2007-12-19 01:31:27 +0100411 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700412 memcpy(sdata->u.ap.ssid, ssid, len);
413 memset(sdata->u.ap.ssid + len, 0,
414 IEEE80211_MAX_SSID_LEN - len);
415 sdata->u.ap.ssid_len = len;
416 return ieee80211_if_config(dev);
417 }
418 return -EOPNOTSUPP;
419}
420
421
422static int ieee80211_ioctl_giwessid(struct net_device *dev,
423 struct iw_request_info *info,
424 struct iw_point *data, char *ssid)
425{
426 size_t len;
427
428 struct ieee80211_sub_if_data *sdata;
429 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100430 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
431 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700432 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
433 if (res == 0) {
434 data->length = len;
435 data->flags = 1;
436 } else
437 data->flags = 0;
438 return res;
439 }
440
Johannes Berg51fb61e2007-12-19 01:31:27 +0100441 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700442 len = sdata->u.ap.ssid_len;
443 if (len > IW_ESSID_MAX_SIZE)
444 len = IW_ESSID_MAX_SIZE;
445 memcpy(ssid, sdata->u.ap.ssid, len);
446 data->length = len;
447 data->flags = 1;
448 return 0;
449 }
450 return -EOPNOTSUPP;
451}
452
453
454static int ieee80211_ioctl_siwap(struct net_device *dev,
455 struct iw_request_info *info,
456 struct sockaddr *ap_addr, char *extra)
457{
Jiri Bencf0706e82007-05-05 11:45:53 -0700458 struct ieee80211_sub_if_data *sdata;
459
460 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100461 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
462 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700463 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200464 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700465 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
466 ETH_ALEN);
467 return 0;
468 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400469 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
470 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
471 IEEE80211_STA_AUTO_CHANNEL_SEL;
472 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
473 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700474 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400475 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700476 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
477 if (ret)
478 return ret;
479 ieee80211_sta_req_auth(dev, &sdata->u.sta);
480 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100481 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100482 /*
483 * If it is necessary to update the WDS peer address
484 * while the interface is running, then we need to do
485 * more work here, namely if it is running we need to
486 * add a new and remove the old STA entry, this is
487 * normally handled by _open() and _stop().
488 */
489 if (netif_running(dev))
490 return -EBUSY;
491
492 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
493 ETH_ALEN);
494
495 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700496 }
497
498 return -EOPNOTSUPP;
499}
500
501
502static int ieee80211_ioctl_giwap(struct net_device *dev,
503 struct iw_request_info *info,
504 struct sockaddr *ap_addr, char *extra)
505{
506 struct ieee80211_sub_if_data *sdata;
507
508 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100509 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
510 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Abhijeet Kolekar5c5f9662008-06-12 09:47:16 +0800511 if (sdata->u.sta.state == IEEE80211_ASSOCIATED ||
512 sdata->u.sta.state == IEEE80211_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700513 ap_addr->sa_family = ARPHRD_ETHER;
514 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
515 return 0;
516 } else {
517 memset(&ap_addr->sa_data, 0, ETH_ALEN);
518 return 0;
519 }
Johannes Berg51fb61e2007-12-19 01:31:27 +0100520 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700521 ap_addr->sa_family = ARPHRD_ETHER;
522 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
523 return 0;
524 }
525
526 return -EOPNOTSUPP;
527}
528
529
530static int ieee80211_ioctl_siwscan(struct net_device *dev,
531 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400532 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700533{
Jiri Bencf0706e82007-05-05 11:45:53 -0700534 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400535 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700536 u8 *ssid = NULL;
537 size_t ssid_len = 0;
538
539 if (!netif_running(dev))
540 return -ENETDOWN;
541
Johannes Berg51fb61e2007-12-19 01:31:27 +0100542 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
543 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100544 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100545 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700546 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700547
548 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400549 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
550 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
551 req = (struct iw_scan_req *)extra;
552 ssid = req->essid;
553 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700554 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200555
Jiri Bencf0706e82007-05-05 11:45:53 -0700556 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
557}
558
559
560static int ieee80211_ioctl_giwscan(struct net_device *dev,
561 struct iw_request_info *info,
562 struct iw_point *data, char *extra)
563{
564 int res;
565 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800566
567 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700568 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800569
David S. Millerccc58052008-06-16 18:50:49 -0700570 res = ieee80211_sta_scan_results(dev, info, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700571 if (res >= 0) {
572 data->length = res;
573 return 0;
574 }
575 data->length = 0;
576 return res;
577}
578
579
Larry Finger1fd5e582007-07-10 19:32:10 +0200580static int ieee80211_ioctl_siwrate(struct net_device *dev,
581 struct iw_request_info *info,
582 struct iw_param *rate, char *extra)
583{
584 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100585 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200586 u32 target_rate = rate->value / 100000;
587 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100588 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200589
590 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
591 if (!sdata->bss)
592 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100593
594 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
595
Larry Finger1fd5e582007-07-10 19:32:10 +0200596 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
597 * target_rate = X, rate->fixed = 1 means only rate X
598 * target_rate = X, rate->fixed = 0 means all rates <= X */
599 sdata->bss->max_ratectrl_rateidx = -1;
600 sdata->bss->force_unicast_rateidx = -1;
601 if (rate->value < 0)
602 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100603
604 for (i=0; i< sband->n_bitrates; i++) {
605 struct ieee80211_rate *brate = &sband->bitrates[i];
606 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200607
Larry Finger1fd5e582007-07-10 19:32:10 +0200608 if (target_rate == this_rate) {
609 sdata->bss->max_ratectrl_rateidx = i;
610 if (rate->fixed)
611 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100612 err = 0;
613 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200614 }
615 }
Johannes Berg8318d782008-01-24 19:38:38 +0100616 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200617}
618
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700619static int ieee80211_ioctl_giwrate(struct net_device *dev,
620 struct iw_request_info *info,
621 struct iw_param *rate, char *extra)
622{
623 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
624 struct sta_info *sta;
625 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100626 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700627
628 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100629
Johannes Berg380a9422008-04-04 23:40:35 +0200630 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700631 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100632
633 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
634
Johannes Berg380a9422008-04-04 23:40:35 +0200635 rcu_read_lock();
636
637 sta = sta_info_get(local, sdata->u.sta.bssid);
638
639 if (sta && sta->txrate_idx < sband->n_bitrates)
Johannes Berg8318d782008-01-24 19:38:38 +0100640 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700641 else
642 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200643
644 rcu_read_unlock();
645
646 if (!sta)
647 return -ENODEV;
648
Johannes Berg8318d782008-01-24 19:38:38 +0100649 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100650
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700651 return 0;
652}
653
Michael Buesch61609bc2007-09-20 22:06:39 +0200654static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
655 struct iw_request_info *info,
656 union iwreq_data *data, char *extra)
657{
658 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
659 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100660 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200661
662 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
663 return -EINVAL;
664 if (data->txpower.flags & IW_TXPOW_RANGE)
665 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200666
Mattias Nissler6a432952007-10-24 23:30:36 +0200667 if (data->txpower.fixed) {
668 new_power_level = data->txpower.value;
669 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100670 /*
671 * Automatic power level. Use maximum power for the current
672 * channel. Should be part of rate control.
673 */
674 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200675 if (!chan)
676 return -EINVAL;
677
Johannes Berg8318d782008-01-24 19:38:38 +0100678 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200679 }
680
681 if (local->hw.conf.power_level != new_power_level) {
682 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200683 need_reconfig = 1;
684 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200685
Michael Buesch61609bc2007-09-20 22:06:39 +0200686 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
687 local->hw.conf.radio_enabled = !(data->txpower.disabled);
688 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100689 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200690 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200691
Michael Buesch61609bc2007-09-20 22:06:39 +0200692 if (need_reconfig) {
693 ieee80211_hw_config(local);
694 /* The return value of hw_config is not of big interest here,
695 * as it doesn't say that it failed because of _this_ config
696 * change or something else. Ignore it. */
697 }
698
699 return 0;
700}
701
Larry Fingerfe6aa302007-08-10 11:23:20 -0500702static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
703 struct iw_request_info *info,
704 union iwreq_data *data, char *extra)
705{
706 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
707
708 data->txpower.fixed = 1;
709 data->txpower.disabled = !(local->hw.conf.radio_enabled);
710 data->txpower.value = local->hw.conf.power_level;
711 data->txpower.flags = IW_TXPOW_DBM;
712
713 return 0;
714}
715
Jiri Bencf0706e82007-05-05 11:45:53 -0700716static int ieee80211_ioctl_siwrts(struct net_device *dev,
717 struct iw_request_info *info,
718 struct iw_param *rts, char *extra)
719{
720 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
721
722 if (rts->disabled)
723 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300724 else if (!rts->fixed)
725 /* if the rts value is not fixed, then take default */
726 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700727 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
728 return -EINVAL;
729 else
730 local->rts_threshold = rts->value;
731
732 /* If the wlan card performs RTS/CTS in hardware/firmware,
733 * configure it here */
734
735 if (local->ops->set_rts_threshold)
736 local->ops->set_rts_threshold(local_to_hw(local),
737 local->rts_threshold);
738
739 return 0;
740}
741
742static int ieee80211_ioctl_giwrts(struct net_device *dev,
743 struct iw_request_info *info,
744 struct iw_param *rts, char *extra)
745{
746 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
747
748 rts->value = local->rts_threshold;
749 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
750 rts->fixed = 1;
751
752 return 0;
753}
754
755
756static int ieee80211_ioctl_siwfrag(struct net_device *dev,
757 struct iw_request_info *info,
758 struct iw_param *frag, char *extra)
759{
760 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
761
762 if (frag->disabled)
763 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
764 else if (frag->value < 256 ||
765 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
766 return -EINVAL;
767 else {
768 /* Fragment length must be even, so strip LSB. */
769 local->fragmentation_threshold = frag->value & ~0x1;
770 }
771
772 /* If the wlan card performs fragmentation in hardware/firmware,
773 * configure it here */
774
775 if (local->ops->set_frag_threshold)
776 local->ops->set_frag_threshold(
777 local_to_hw(local),
778 local->fragmentation_threshold);
779
780 return 0;
781}
782
783static int ieee80211_ioctl_giwfrag(struct net_device *dev,
784 struct iw_request_info *info,
785 struct iw_param *frag, char *extra)
786{
787 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
788
789 frag->value = local->fragmentation_threshold;
790 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
791 frag->fixed = 1;
792
793 return 0;
794}
795
796
797static int ieee80211_ioctl_siwretry(struct net_device *dev,
798 struct iw_request_info *info,
799 struct iw_param *retry, char *extra)
800{
801 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
802
803 if (retry->disabled ||
804 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
805 return -EINVAL;
806
807 if (retry->flags & IW_RETRY_MAX)
808 local->long_retry_limit = retry->value;
809 else if (retry->flags & IW_RETRY_MIN)
810 local->short_retry_limit = retry->value;
811 else {
812 local->long_retry_limit = retry->value;
813 local->short_retry_limit = retry->value;
814 }
815
816 if (local->ops->set_retry_limit) {
817 return local->ops->set_retry_limit(
818 local_to_hw(local),
819 local->short_retry_limit,
820 local->long_retry_limit);
821 }
822
823 return 0;
824}
825
826
827static int ieee80211_ioctl_giwretry(struct net_device *dev,
828 struct iw_request_info *info,
829 struct iw_param *retry, char *extra)
830{
831 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
832
833 retry->disabled = 0;
834 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
835 /* first return min value, iwconfig will ask max value
836 * later if needed */
837 retry->flags |= IW_RETRY_LIMIT;
838 retry->value = local->short_retry_limit;
839 if (local->long_retry_limit != local->short_retry_limit)
840 retry->flags |= IW_RETRY_MIN;
841 return 0;
842 }
843 if (retry->flags & IW_RETRY_MAX) {
844 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
845 retry->value = local->long_retry_limit;
846 }
847
848 return 0;
849}
850
Jiri Bencf0706e82007-05-05 11:45:53 -0700851static int ieee80211_ioctl_siwmlme(struct net_device *dev,
852 struct iw_request_info *info,
853 struct iw_point *data, char *extra)
854{
855 struct ieee80211_sub_if_data *sdata;
856 struct iw_mlme *mlme = (struct iw_mlme *) extra;
857
858 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100859 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
860 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700861 return -EINVAL;
862
863 switch (mlme->cmd) {
864 case IW_MLME_DEAUTH:
865 /* TODO: mlme->addr.sa_data */
866 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
867 case IW_MLME_DISASSOC:
868 /* TODO: mlme->addr.sa_data */
869 return ieee80211_sta_disassociate(dev, mlme->reason_code);
870 default:
871 return -EOPNOTSUPP;
872 }
873}
874
875
876static int ieee80211_ioctl_siwencode(struct net_device *dev,
877 struct iw_request_info *info,
878 struct iw_point *erq, char *keybuf)
879{
880 struct ieee80211_sub_if_data *sdata;
881 int idx, i, alg = ALG_WEP;
882 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200883 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700884
885 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
886
887 idx = erq->flags & IW_ENCODE_INDEX;
888 if (idx == 0) {
889 if (sdata->default_key)
890 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
891 if (sdata->default_key == sdata->keys[i]) {
892 idx = i;
893 break;
894 }
895 }
896 } else if (idx < 1 || idx > 4)
897 return -EINVAL;
898 else
899 idx--;
900
901 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200902 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700903 else if (erq->length == 0) {
904 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400905 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700906 return 0;
907 }
908
909 return ieee80211_set_encryption(
910 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200911 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700912 !sdata->default_key,
913 keybuf, erq->length);
914}
915
916
917static int ieee80211_ioctl_giwencode(struct net_device *dev,
918 struct iw_request_info *info,
919 struct iw_point *erq, char *key)
920{
921 struct ieee80211_sub_if_data *sdata;
922 int idx, i;
923
924 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
925
926 idx = erq->flags & IW_ENCODE_INDEX;
927 if (idx < 1 || idx > 4) {
928 idx = -1;
929 if (!sdata->default_key)
930 idx = 0;
931 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
932 if (sdata->default_key == sdata->keys[i]) {
933 idx = i;
934 break;
935 }
936 }
937 if (idx < 0)
938 return -EINVAL;
939 } else
940 idx--;
941
942 erq->flags = idx + 1;
943
944 if (!sdata->keys[idx]) {
945 erq->length = 0;
946 erq->flags |= IW_ENCODE_DISABLED;
947 return 0;
948 }
949
Johannes Berg8f20fc22007-08-28 17:01:54 -0400950 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400951 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400952 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700953 erq->flags |= IW_ENCODE_ENABLED;
954
955 return 0;
956}
957
958static int ieee80211_ioctl_siwauth(struct net_device *dev,
959 struct iw_request_info *info,
960 struct iw_param *data, char *extra)
961{
Jiri Bencf0706e82007-05-05 11:45:53 -0700962 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
963 int ret = 0;
964
965 switch (data->flags & IW_AUTH_INDEX) {
966 case IW_AUTH_WPA_VERSION:
967 case IW_AUTH_CIPHER_PAIRWISE:
968 case IW_AUTH_CIPHER_GROUP:
969 case IW_AUTH_WPA_ENABLED:
970 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700971 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000972 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100973 case IW_AUTH_DROP_UNENCRYPTED:
974 sdata->drop_unencrypted = !!data->value;
975 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000976 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100977 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700978 ret = -EINVAL;
979 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000980 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700981 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000982 * Privacy invoked by wpa_supplicant, store the
983 * value and allow associating to a protected
984 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700985 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000986 if (data->value)
987 sdata->u.sta.flags |=
988 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700989 }
990 break;
991 case IW_AUTH_80211_AUTH_ALG:
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 sdata->u.sta.auth_algs = data->value;
995 else
996 ret = -EOPNOTSUPP;
997 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700998 default:
999 ret = -EOPNOTSUPP;
1000 break;
1001 }
1002 return ret;
1003}
1004
1005/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1006static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1007{
1008 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1009 struct iw_statistics *wstats = &local->wstats;
1010 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1011 struct sta_info *sta = NULL;
1012
Johannes Berg98dd6a52008-04-10 15:36:09 +02001013 rcu_read_lock();
1014
Johannes Berg51fb61e2007-12-19 01:31:27 +01001015 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1016 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001017 sta = sta_info_get(local, sdata->u.sta.bssid);
1018 if (!sta) {
1019 wstats->discard.fragment = 0;
1020 wstats->discard.misc = 0;
1021 wstats->qual.qual = 0;
1022 wstats->qual.level = 0;
1023 wstats->qual.noise = 0;
1024 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1025 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001026 wstats->qual.level = sta->last_signal;
1027 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001028 wstats->qual.noise = sta->last_noise;
1029 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001030 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001031
1032 rcu_read_unlock();
1033
Jiri Bencf0706e82007-05-05 11:45:53 -07001034 return wstats;
1035}
1036
1037static int ieee80211_ioctl_giwauth(struct net_device *dev,
1038 struct iw_request_info *info,
1039 struct iw_param *data, char *extra)
1040{
1041 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1042 int ret = 0;
1043
1044 switch (data->flags & IW_AUTH_INDEX) {
1045 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001046 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1047 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001048 data->value = sdata->u.sta.auth_algs;
1049 else
1050 ret = -EOPNOTSUPP;
1051 break;
1052 default:
1053 ret = -EOPNOTSUPP;
1054 break;
1055 }
1056 return ret;
1057}
1058
1059
1060static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1061 struct iw_request_info *info,
1062 struct iw_point *erq, char *extra)
1063{
1064 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1065 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001066 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001067
1068 switch (ext->alg) {
1069 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001070 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001071 break;
1072 case IW_ENCODE_ALG_WEP:
1073 alg = ALG_WEP;
1074 break;
1075 case IW_ENCODE_ALG_TKIP:
1076 alg = ALG_TKIP;
1077 break;
1078 case IW_ENCODE_ALG_CCMP:
1079 alg = ALG_CCMP;
1080 break;
1081 default:
1082 return -EOPNOTSUPP;
1083 }
1084
1085 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001086 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001087
1088 idx = erq->flags & IW_ENCODE_INDEX;
1089 if (idx < 1 || idx > 4) {
1090 idx = -1;
1091 if (!sdata->default_key)
1092 idx = 0;
1093 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1094 if (sdata->default_key == sdata->keys[i]) {
1095 idx = i;
1096 break;
1097 }
1098 }
1099 if (idx < 0)
1100 return -EINVAL;
1101 } else
1102 idx--;
1103
1104 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001105 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001106 ext->ext_flags &
1107 IW_ENCODE_EXT_SET_TX_KEY,
1108 ext->key, ext->key_len);
1109}
1110
1111
Jiri Bencf0706e82007-05-05 11:45:53 -07001112/* Structures to export the Wireless Handlers */
1113
1114static const iw_handler ieee80211_handler[] =
1115{
1116 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1117 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1118 (iw_handler) NULL, /* SIOCSIWNWID */
1119 (iw_handler) NULL, /* SIOCGIWNWID */
1120 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1121 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1122 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1123 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1124 (iw_handler) NULL, /* SIOCSIWSENS */
1125 (iw_handler) NULL, /* SIOCGIWSENS */
1126 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1127 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1128 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1129 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1130 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1131 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001132 (iw_handler) NULL, /* SIOCSIWSPY */
1133 (iw_handler) NULL, /* SIOCGIWSPY */
1134 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1135 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001136 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1137 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1138 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1139 (iw_handler) NULL, /* SIOCGIWAPLIST */
1140 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1141 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1142 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1143 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1144 (iw_handler) NULL, /* SIOCSIWNICKN */
1145 (iw_handler) NULL, /* SIOCGIWNICKN */
1146 (iw_handler) NULL, /* -- hole -- */
1147 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001148 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001149 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001150 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1151 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1152 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1153 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001154 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001155 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001156 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1157 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1158 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1159 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1160 (iw_handler) NULL, /* SIOCSIWPOWER */
1161 (iw_handler) NULL, /* SIOCGIWPOWER */
1162 (iw_handler) NULL, /* -- hole -- */
1163 (iw_handler) NULL, /* -- hole -- */
1164 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1165 (iw_handler) NULL, /* SIOCGIWGENIE */
1166 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1167 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1168 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1169 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1170 (iw_handler) NULL, /* SIOCSIWPMKSA */
1171 (iw_handler) NULL, /* -- hole -- */
1172};
1173
Jiri Bencf0706e82007-05-05 11:45:53 -07001174const struct iw_handler_def ieee80211_iw_handler_def =
1175{
1176 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001177 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001178 .get_wireless_stats = ieee80211_get_wireless_stats,
1179};