blob: df0531c28141e99fcfb33f0f9362295e9eb22f6a [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{
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300138 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
139 struct ieee80211_supported_band *sband;
140 u8 is_ht = 0, is_a = 0, is_b = 0, is_g = 0;
141
142
143 sband = local->hw.wiphy->bands[IEEE80211_BAND_5GHZ];
144 if (sband) {
145 is_a = 1;
146 is_ht |= sband->ht_info.ht_supported;
147 }
148
149 sband = local->hw.wiphy->bands[IEEE80211_BAND_2GHZ];
150 if (sband) {
151 int i;
152 /* Check for mandatory rates */
153 for (i = 0; i < sband->n_bitrates; i++) {
154 if (sband->bitrates[i].bitrate == 10)
155 is_b = 1;
156 if (sband->bitrates[i].bitrate == 60)
157 is_g = 1;
158 }
159 is_ht |= sband->ht_info.ht_supported;
160 }
161
Johannes Berg8318d782008-01-24 19:38:38 +0100162 strcpy(name, "IEEE 802.11");
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300163 if (is_a)
164 strcat(name, "a");
165 if (is_b)
166 strcat(name, "b");
167 if (is_g)
168 strcat(name, "g");
169 if (is_ht)
170 strcat(name, "n");
Jiri Bencf0706e82007-05-05 11:45:53 -0700171
172 return 0;
173}
174
175
176static int ieee80211_ioctl_giwrange(struct net_device *dev,
177 struct iw_request_info *info,
178 struct iw_point *data, char *extra)
179{
180 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
181 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100182 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200183 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700184
185 data->length = sizeof(struct iw_range);
186 memset(range, 0, sizeof(struct iw_range));
187
188 range->we_version_compiled = WIRELESS_EXT;
189 range->we_version_source = 21;
190 range->retry_capa = IW_RETRY_LIMIT;
191 range->retry_flags = IW_RETRY_LIMIT;
192 range->min_retry = 0;
193 range->max_retry = 255;
194 range->min_rts = 0;
195 range->max_rts = 2347;
196 range->min_frag = 256;
197 range->max_frag = 2346;
198
199 range->encoding_size[0] = 5;
200 range->encoding_size[1] = 13;
201 range->num_encoding_sizes = 2;
202 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
203
Bruno Randolf566bfe52008-05-08 19:15:40 +0200204 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
205 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
206 range->max_qual.level = local->hw.max_signal;
207 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
208 range->max_qual.level = -110;
209 else
210 range->max_qual.level = 0;
211
212 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
213 range->max_qual.noise = -110;
214 else
215 range->max_qual.noise = 0;
216
217 range->max_qual.qual = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700218 range->max_qual.updated = local->wstats_flags;
219
Bruno Randolf566bfe52008-05-08 19:15:40 +0200220 range->avg_qual.qual = 50;
221 /* not always true but better than nothing */
222 range->avg_qual.level = range->max_qual.level / 2;
223 range->avg_qual.noise = range->max_qual.noise / 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700224 range->avg_qual.updated = local->wstats_flags;
225
226 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
227 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
228
Hong Liu333af2f2007-07-10 19:32:08 +0200229
Johannes Berg8318d782008-01-24 19:38:38 +0100230 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
231 int i;
232 struct ieee80211_supported_band *sband;
233
234 sband = local->hw.wiphy->bands[band];
235
236 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200237 continue;
238
Johannes Berg8318d782008-01-24 19:38:38 +0100239 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
240 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200241
Johannes Berg8318d782008-01-24 19:38:38 +0100242 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
243 range->freq[c].i =
244 ieee80211_frequency_to_channel(
245 chan->center_freq);
246 range->freq[c].m = chan->center_freq;
247 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200248 c++;
249 }
Hong Liu333af2f2007-07-10 19:32:08 +0200250 }
251 }
252 range->num_channels = c;
253 range->num_frequency = c;
254
Jiri Bencf0706e82007-05-05 11:45:53 -0700255 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700256 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
257 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
258
Dan Williams374fdfb2007-12-12 10:25:07 -0500259 range->scan_capa |= IW_SCAN_CAPA_ESSID;
260
Jiri Bencf0706e82007-05-05 11:45:53 -0700261 return 0;
262}
263
264
Jiri Bencf0706e82007-05-05 11:45:53 -0700265static int ieee80211_ioctl_siwmode(struct net_device *dev,
266 struct iw_request_info *info,
267 __u32 *mode, char *extra)
268{
269 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
270 int type;
271
Johannes Berg51fb61e2007-12-19 01:31:27 +0100272 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700273 return -EOPNOTSUPP;
274
275 switch (*mode) {
276 case IW_MODE_INFRA:
277 type = IEEE80211_IF_TYPE_STA;
278 break;
279 case IW_MODE_ADHOC:
280 type = IEEE80211_IF_TYPE_IBSS;
281 break;
Johannes Bergb4540482008-04-14 15:37:03 +0200282 case IW_MODE_REPEAT:
283 type = IEEE80211_IF_TYPE_WDS;
284 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700285 case IW_MODE_MONITOR:
286 type = IEEE80211_IF_TYPE_MNTR;
287 break;
288 default:
289 return -EINVAL;
290 }
291
Johannes Berg51fb61e2007-12-19 01:31:27 +0100292 if (type == sdata->vif.type)
Jiri Bencf0706e82007-05-05 11:45:53 -0700293 return 0;
294 if (netif_running(dev))
295 return -EBUSY;
296
297 ieee80211_if_reinit(dev);
298 ieee80211_if_set_type(dev, type);
299
300 return 0;
301}
302
303
304static int ieee80211_ioctl_giwmode(struct net_device *dev,
305 struct iw_request_info *info,
306 __u32 *mode, char *extra)
307{
308 struct ieee80211_sub_if_data *sdata;
309
310 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100311 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700312 case IEEE80211_IF_TYPE_AP:
313 *mode = IW_MODE_MASTER;
314 break;
315 case IEEE80211_IF_TYPE_STA:
316 *mode = IW_MODE_INFRA;
317 break;
318 case IEEE80211_IF_TYPE_IBSS:
319 *mode = IW_MODE_ADHOC;
320 break;
321 case IEEE80211_IF_TYPE_MNTR:
322 *mode = IW_MODE_MONITOR;
323 break;
324 case IEEE80211_IF_TYPE_WDS:
325 *mode = IW_MODE_REPEAT;
326 break;
327 case IEEE80211_IF_TYPE_VLAN:
328 *mode = IW_MODE_SECOND; /* FIXME */
329 break;
330 default:
331 *mode = IW_MODE_AUTO;
332 break;
333 }
334 return 0;
335}
336
Assaf Kraussbe038b32008-06-05 19:55:21 +0300337int ieee80211_set_freq(struct net_device *dev, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700338{
Jiri Bencf0706e82007-05-05 11:45:53 -0700339 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100340 struct ieee80211_channel *chan;
Assaf Kraussbe038b32008-06-05 19:55:21 +0300341 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
342 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700343
Johannes Berge048c6e2008-03-16 18:35:56 +0100344 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100345
Johannes Berge048c6e2008-03-16 18:35:56 +0100346 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Assaf Kraussbe038b32008-06-05 19:55:21 +0300347 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
348 chan->flags & IEEE80211_CHAN_NO_IBSS) {
349 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
350 "%d MHz\n", dev->name, chan->center_freq);
351 return ret;
352 }
Johannes Berge048c6e2008-03-16 18:35:56 +0100353 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100354
Mohamed Abbas675ef582008-03-20 08:14:29 -0700355 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700356 ret = 0;
357 else
358 ret = ieee80211_hw_config(local);
359
360 rate_control_clear(local);
361 }
362
363 return ret;
364}
365
366static int ieee80211_ioctl_siwfreq(struct net_device *dev,
367 struct iw_request_info *info,
368 struct iw_freq *freq, char *extra)
369{
Jiri Bencf0706e82007-05-05 11:45:53 -0700370 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
371
Johannes Berg51fb61e2007-12-19 01:31:27 +0100372 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400373 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700374
375 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
376 if (freq->e == 0) {
377 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100378 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400379 sdata->u.sta.flags |=
380 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700381 return 0;
382 } else
Assaf Kraussbe038b32008-06-05 19:55:21 +0300383 return ieee80211_set_freq(dev,
Johannes Berg8318d782008-01-24 19:38:38 +0100384 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700385 } else {
386 int i, div = 1000000;
387 for (i = 0; i < freq->e; i++)
388 div /= 10;
389 if (div > 0)
Assaf Kraussbe038b32008-06-05 19:55:21 +0300390 return ieee80211_set_freq(dev, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700391 else
392 return -EINVAL;
393 }
394}
395
396
397static int ieee80211_ioctl_giwfreq(struct net_device *dev,
398 struct iw_request_info *info,
399 struct iw_freq *freq, char *extra)
400{
401 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
402
Johannes Berg8318d782008-01-24 19:38:38 +0100403 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700404 freq->e = 6;
405
406 return 0;
407}
408
409
410static int ieee80211_ioctl_siwessid(struct net_device *dev,
411 struct iw_request_info *info,
412 struct iw_point *data, char *ssid)
413{
Jiri Bencf0706e82007-05-05 11:45:53 -0700414 struct ieee80211_sub_if_data *sdata;
415 size_t len = data->length;
416
417 /* iwconfig uses nul termination in SSID.. */
418 if (len > 0 && ssid[len - 1] == '\0')
419 len--;
420
421 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100422 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
423 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700424 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200425 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700426 if (len > IEEE80211_MAX_SSID_LEN)
427 return -EINVAL;
428 memcpy(sdata->u.sta.ssid, ssid, len);
429 sdata->u.sta.ssid_len = len;
430 return 0;
431 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400432 if (data->flags)
433 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
434 else
435 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700436 ret = ieee80211_sta_set_ssid(dev, ssid, len);
437 if (ret)
438 return ret;
439 ieee80211_sta_req_auth(dev, &sdata->u.sta);
440 return 0;
441 }
442
Johannes Berg51fb61e2007-12-19 01:31:27 +0100443 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700444 memcpy(sdata->u.ap.ssid, ssid, len);
445 memset(sdata->u.ap.ssid + len, 0,
446 IEEE80211_MAX_SSID_LEN - len);
447 sdata->u.ap.ssid_len = len;
448 return ieee80211_if_config(dev);
449 }
450 return -EOPNOTSUPP;
451}
452
453
454static int ieee80211_ioctl_giwessid(struct net_device *dev,
455 struct iw_request_info *info,
456 struct iw_point *data, char *ssid)
457{
458 size_t len;
459
460 struct ieee80211_sub_if_data *sdata;
461 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100462 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
463 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700464 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
465 if (res == 0) {
466 data->length = len;
467 data->flags = 1;
468 } else
469 data->flags = 0;
470 return res;
471 }
472
Johannes Berg51fb61e2007-12-19 01:31:27 +0100473 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700474 len = sdata->u.ap.ssid_len;
475 if (len > IW_ESSID_MAX_SIZE)
476 len = IW_ESSID_MAX_SIZE;
477 memcpy(ssid, sdata->u.ap.ssid, len);
478 data->length = len;
479 data->flags = 1;
480 return 0;
481 }
482 return -EOPNOTSUPP;
483}
484
485
486static int ieee80211_ioctl_siwap(struct net_device *dev,
487 struct iw_request_info *info,
488 struct sockaddr *ap_addr, char *extra)
489{
Jiri Bencf0706e82007-05-05 11:45:53 -0700490 struct ieee80211_sub_if_data *sdata;
491
492 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100493 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
494 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700495 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200496 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700497 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
498 ETH_ALEN);
499 return 0;
500 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400501 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
502 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
503 IEEE80211_STA_AUTO_CHANNEL_SEL;
504 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
505 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700506 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400507 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700508 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
509 if (ret)
510 return ret;
511 ieee80211_sta_req_auth(dev, &sdata->u.sta);
512 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100513 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100514 /*
515 * If it is necessary to update the WDS peer address
516 * while the interface is running, then we need to do
517 * more work here, namely if it is running we need to
518 * add a new and remove the old STA entry, this is
519 * normally handled by _open() and _stop().
520 */
521 if (netif_running(dev))
522 return -EBUSY;
523
524 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
525 ETH_ALEN);
526
527 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700528 }
529
530 return -EOPNOTSUPP;
531}
532
533
534static int ieee80211_ioctl_giwap(struct net_device *dev,
535 struct iw_request_info *info,
536 struct sockaddr *ap_addr, char *extra)
537{
538 struct ieee80211_sub_if_data *sdata;
539
540 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100541 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
542 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Abhijeet Kolekar5c5f9662008-06-12 09:47:16 +0800543 if (sdata->u.sta.state == IEEE80211_ASSOCIATED ||
544 sdata->u.sta.state == IEEE80211_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700545 ap_addr->sa_family = ARPHRD_ETHER;
546 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
547 return 0;
548 } else {
549 memset(&ap_addr->sa_data, 0, ETH_ALEN);
550 return 0;
551 }
Johannes Berg51fb61e2007-12-19 01:31:27 +0100552 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700553 ap_addr->sa_family = ARPHRD_ETHER;
554 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
555 return 0;
556 }
557
558 return -EOPNOTSUPP;
559}
560
561
562static int ieee80211_ioctl_siwscan(struct net_device *dev,
563 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400564 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700565{
Jiri Bencf0706e82007-05-05 11:45:53 -0700566 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400567 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700568 u8 *ssid = NULL;
569 size_t ssid_len = 0;
570
571 if (!netif_running(dev))
572 return -ENETDOWN;
573
Johannes Berg51fb61e2007-12-19 01:31:27 +0100574 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
575 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100576 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100577 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700578 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700579
580 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400581 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
582 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
583 req = (struct iw_scan_req *)extra;
584 ssid = req->essid;
585 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700586 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200587
Jiri Bencf0706e82007-05-05 11:45:53 -0700588 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
589}
590
591
592static int ieee80211_ioctl_giwscan(struct net_device *dev,
593 struct iw_request_info *info,
594 struct iw_point *data, char *extra)
595{
596 int res;
597 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800598
599 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700600 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800601
David S. Millerccc58052008-06-16 18:50:49 -0700602 res = ieee80211_sta_scan_results(dev, info, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700603 if (res >= 0) {
604 data->length = res;
605 return 0;
606 }
607 data->length = 0;
608 return res;
609}
610
611
Larry Finger1fd5e582007-07-10 19:32:10 +0200612static int ieee80211_ioctl_siwrate(struct net_device *dev,
613 struct iw_request_info *info,
614 struct iw_param *rate, char *extra)
615{
616 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100617 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200618 u32 target_rate = rate->value / 100000;
619 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100620 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200621
622 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
623 if (!sdata->bss)
624 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100625
626 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
627
Larry Finger1fd5e582007-07-10 19:32:10 +0200628 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
629 * target_rate = X, rate->fixed = 1 means only rate X
630 * target_rate = X, rate->fixed = 0 means all rates <= X */
631 sdata->bss->max_ratectrl_rateidx = -1;
632 sdata->bss->force_unicast_rateidx = -1;
633 if (rate->value < 0)
634 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100635
636 for (i=0; i< sband->n_bitrates; i++) {
637 struct ieee80211_rate *brate = &sband->bitrates[i];
638 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200639
Larry Finger1fd5e582007-07-10 19:32:10 +0200640 if (target_rate == this_rate) {
641 sdata->bss->max_ratectrl_rateidx = i;
642 if (rate->fixed)
643 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100644 err = 0;
645 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200646 }
647 }
Johannes Berg8318d782008-01-24 19:38:38 +0100648 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200649}
650
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700651static int ieee80211_ioctl_giwrate(struct net_device *dev,
652 struct iw_request_info *info,
653 struct iw_param *rate, char *extra)
654{
655 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
656 struct sta_info *sta;
657 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100658 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700659
660 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100661
Johannes Berg380a9422008-04-04 23:40:35 +0200662 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700663 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100664
665 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
666
Johannes Berg380a9422008-04-04 23:40:35 +0200667 rcu_read_lock();
668
669 sta = sta_info_get(local, sdata->u.sta.bssid);
670
671 if (sta && sta->txrate_idx < sband->n_bitrates)
Johannes Berg8318d782008-01-24 19:38:38 +0100672 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700673 else
674 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200675
676 rcu_read_unlock();
677
678 if (!sta)
679 return -ENODEV;
680
Johannes Berg8318d782008-01-24 19:38:38 +0100681 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100682
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700683 return 0;
684}
685
Michael Buesch61609bc2007-09-20 22:06:39 +0200686static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
687 struct iw_request_info *info,
688 union iwreq_data *data, char *extra)
689{
690 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
691 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100692 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200693
694 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
695 return -EINVAL;
696 if (data->txpower.flags & IW_TXPOW_RANGE)
697 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200698
Mattias Nissler6a432952007-10-24 23:30:36 +0200699 if (data->txpower.fixed) {
700 new_power_level = data->txpower.value;
701 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100702 /*
703 * Automatic power level. Use maximum power for the current
704 * channel. Should be part of rate control.
705 */
706 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200707 if (!chan)
708 return -EINVAL;
709
Johannes Berg8318d782008-01-24 19:38:38 +0100710 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200711 }
712
713 if (local->hw.conf.power_level != new_power_level) {
714 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200715 need_reconfig = 1;
716 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200717
Michael Buesch61609bc2007-09-20 22:06:39 +0200718 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
719 local->hw.conf.radio_enabled = !(data->txpower.disabled);
720 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100721 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200722 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200723
Michael Buesch61609bc2007-09-20 22:06:39 +0200724 if (need_reconfig) {
725 ieee80211_hw_config(local);
726 /* The return value of hw_config is not of big interest here,
727 * as it doesn't say that it failed because of _this_ config
728 * change or something else. Ignore it. */
729 }
730
731 return 0;
732}
733
Larry Fingerfe6aa302007-08-10 11:23:20 -0500734static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
735 struct iw_request_info *info,
736 union iwreq_data *data, char *extra)
737{
738 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
739
740 data->txpower.fixed = 1;
741 data->txpower.disabled = !(local->hw.conf.radio_enabled);
742 data->txpower.value = local->hw.conf.power_level;
743 data->txpower.flags = IW_TXPOW_DBM;
744
745 return 0;
746}
747
Jiri Bencf0706e82007-05-05 11:45:53 -0700748static int ieee80211_ioctl_siwrts(struct net_device *dev,
749 struct iw_request_info *info,
750 struct iw_param *rts, char *extra)
751{
752 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
753
754 if (rts->disabled)
755 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300756 else if (!rts->fixed)
757 /* if the rts value is not fixed, then take default */
758 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700759 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
760 return -EINVAL;
761 else
762 local->rts_threshold = rts->value;
763
764 /* If the wlan card performs RTS/CTS in hardware/firmware,
765 * configure it here */
766
767 if (local->ops->set_rts_threshold)
768 local->ops->set_rts_threshold(local_to_hw(local),
769 local->rts_threshold);
770
771 return 0;
772}
773
774static int ieee80211_ioctl_giwrts(struct net_device *dev,
775 struct iw_request_info *info,
776 struct iw_param *rts, char *extra)
777{
778 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
779
780 rts->value = local->rts_threshold;
781 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
782 rts->fixed = 1;
783
784 return 0;
785}
786
787
788static int ieee80211_ioctl_siwfrag(struct net_device *dev,
789 struct iw_request_info *info,
790 struct iw_param *frag, char *extra)
791{
792 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
793
794 if (frag->disabled)
795 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
796 else if (frag->value < 256 ||
797 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
798 return -EINVAL;
799 else {
800 /* Fragment length must be even, so strip LSB. */
801 local->fragmentation_threshold = frag->value & ~0x1;
802 }
803
804 /* If the wlan card performs fragmentation in hardware/firmware,
805 * configure it here */
806
807 if (local->ops->set_frag_threshold)
808 local->ops->set_frag_threshold(
809 local_to_hw(local),
810 local->fragmentation_threshold);
811
812 return 0;
813}
814
815static int ieee80211_ioctl_giwfrag(struct net_device *dev,
816 struct iw_request_info *info,
817 struct iw_param *frag, char *extra)
818{
819 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
820
821 frag->value = local->fragmentation_threshold;
822 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
823 frag->fixed = 1;
824
825 return 0;
826}
827
828
829static int ieee80211_ioctl_siwretry(struct net_device *dev,
830 struct iw_request_info *info,
831 struct iw_param *retry, char *extra)
832{
833 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
834
835 if (retry->disabled ||
836 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
837 return -EINVAL;
838
839 if (retry->flags & IW_RETRY_MAX)
840 local->long_retry_limit = retry->value;
841 else if (retry->flags & IW_RETRY_MIN)
842 local->short_retry_limit = retry->value;
843 else {
844 local->long_retry_limit = retry->value;
845 local->short_retry_limit = retry->value;
846 }
847
848 if (local->ops->set_retry_limit) {
849 return local->ops->set_retry_limit(
850 local_to_hw(local),
851 local->short_retry_limit,
852 local->long_retry_limit);
853 }
854
855 return 0;
856}
857
858
859static int ieee80211_ioctl_giwretry(struct net_device *dev,
860 struct iw_request_info *info,
861 struct iw_param *retry, char *extra)
862{
863 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
864
865 retry->disabled = 0;
866 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
867 /* first return min value, iwconfig will ask max value
868 * later if needed */
869 retry->flags |= IW_RETRY_LIMIT;
870 retry->value = local->short_retry_limit;
871 if (local->long_retry_limit != local->short_retry_limit)
872 retry->flags |= IW_RETRY_MIN;
873 return 0;
874 }
875 if (retry->flags & IW_RETRY_MAX) {
876 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
877 retry->value = local->long_retry_limit;
878 }
879
880 return 0;
881}
882
Jiri Bencf0706e82007-05-05 11:45:53 -0700883static int ieee80211_ioctl_siwmlme(struct net_device *dev,
884 struct iw_request_info *info,
885 struct iw_point *data, char *extra)
886{
887 struct ieee80211_sub_if_data *sdata;
888 struct iw_mlme *mlme = (struct iw_mlme *) extra;
889
890 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100891 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
892 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700893 return -EINVAL;
894
895 switch (mlme->cmd) {
896 case IW_MLME_DEAUTH:
897 /* TODO: mlme->addr.sa_data */
898 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
899 case IW_MLME_DISASSOC:
900 /* TODO: mlme->addr.sa_data */
901 return ieee80211_sta_disassociate(dev, mlme->reason_code);
902 default:
903 return -EOPNOTSUPP;
904 }
905}
906
907
908static int ieee80211_ioctl_siwencode(struct net_device *dev,
909 struct iw_request_info *info,
910 struct iw_point *erq, char *keybuf)
911{
912 struct ieee80211_sub_if_data *sdata;
913 int idx, i, alg = ALG_WEP;
914 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200915 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700916
917 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
918
919 idx = erq->flags & IW_ENCODE_INDEX;
920 if (idx == 0) {
921 if (sdata->default_key)
922 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
923 if (sdata->default_key == sdata->keys[i]) {
924 idx = i;
925 break;
926 }
927 }
928 } else if (idx < 1 || idx > 4)
929 return -EINVAL;
930 else
931 idx--;
932
933 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200934 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700935 else if (erq->length == 0) {
936 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400937 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700938 return 0;
939 }
940
941 return ieee80211_set_encryption(
942 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200943 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700944 !sdata->default_key,
945 keybuf, erq->length);
946}
947
948
949static int ieee80211_ioctl_giwencode(struct net_device *dev,
950 struct iw_request_info *info,
951 struct iw_point *erq, char *key)
952{
953 struct ieee80211_sub_if_data *sdata;
954 int idx, i;
955
956 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
957
958 idx = erq->flags & IW_ENCODE_INDEX;
959 if (idx < 1 || idx > 4) {
960 idx = -1;
961 if (!sdata->default_key)
962 idx = 0;
963 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
964 if (sdata->default_key == sdata->keys[i]) {
965 idx = i;
966 break;
967 }
968 }
969 if (idx < 0)
970 return -EINVAL;
971 } else
972 idx--;
973
974 erq->flags = idx + 1;
975
976 if (!sdata->keys[idx]) {
977 erq->length = 0;
978 erq->flags |= IW_ENCODE_DISABLED;
979 return 0;
980 }
981
Johannes Berg8f20fc22007-08-28 17:01:54 -0400982 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400983 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400984 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700985 erq->flags |= IW_ENCODE_ENABLED;
986
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300987 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
988 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
989 switch (ifsta->auth_alg) {
990 case WLAN_AUTH_OPEN:
991 case WLAN_AUTH_LEAP:
992 erq->flags |= IW_ENCODE_OPEN;
993 break;
994 case WLAN_AUTH_SHARED_KEY:
995 erq->flags |= IW_ENCODE_RESTRICTED;
996 break;
997 }
998 }
999
Jiri Bencf0706e82007-05-05 11:45:53 -07001000 return 0;
1001}
1002
1003static int ieee80211_ioctl_siwauth(struct net_device *dev,
1004 struct iw_request_info *info,
1005 struct iw_param *data, char *extra)
1006{
Jiri Bencf0706e82007-05-05 11:45:53 -07001007 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1008 int ret = 0;
1009
1010 switch (data->flags & IW_AUTH_INDEX) {
1011 case IW_AUTH_WPA_VERSION:
1012 case IW_AUTH_CIPHER_PAIRWISE:
1013 case IW_AUTH_CIPHER_GROUP:
1014 case IW_AUTH_WPA_ENABLED:
1015 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -07001016 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001017 break;
Johannes Bergb1357a82007-11-28 11:04:21 +01001018 case IW_AUTH_DROP_UNENCRYPTED:
1019 sdata->drop_unencrypted = !!data->value;
1020 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001021 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001022 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07001023 ret = -EINVAL;
1024 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001025 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001026 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001027 * Privacy invoked by wpa_supplicant, store the
1028 * value and allow associating to a protected
1029 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -07001030 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001031 if (data->value)
1032 sdata->u.sta.flags |=
1033 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001034 }
1035 break;
1036 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001037 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1038 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001039 sdata->u.sta.auth_algs = data->value;
1040 else
1041 ret = -EOPNOTSUPP;
1042 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001043 default:
1044 ret = -EOPNOTSUPP;
1045 break;
1046 }
1047 return ret;
1048}
1049
1050/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1051static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1052{
1053 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1054 struct iw_statistics *wstats = &local->wstats;
1055 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1056 struct sta_info *sta = NULL;
1057
Johannes Berg98dd6a52008-04-10 15:36:09 +02001058 rcu_read_lock();
1059
Johannes Berg51fb61e2007-12-19 01:31:27 +01001060 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1061 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001062 sta = sta_info_get(local, sdata->u.sta.bssid);
1063 if (!sta) {
1064 wstats->discard.fragment = 0;
1065 wstats->discard.misc = 0;
1066 wstats->qual.qual = 0;
1067 wstats->qual.level = 0;
1068 wstats->qual.noise = 0;
1069 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1070 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001071 wstats->qual.level = sta->last_signal;
1072 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001073 wstats->qual.noise = sta->last_noise;
1074 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001075 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001076
1077 rcu_read_unlock();
1078
Jiri Bencf0706e82007-05-05 11:45:53 -07001079 return wstats;
1080}
1081
1082static int ieee80211_ioctl_giwauth(struct net_device *dev,
1083 struct iw_request_info *info,
1084 struct iw_param *data, char *extra)
1085{
1086 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1087 int ret = 0;
1088
1089 switch (data->flags & IW_AUTH_INDEX) {
1090 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001091 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1092 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001093 data->value = sdata->u.sta.auth_algs;
1094 else
1095 ret = -EOPNOTSUPP;
1096 break;
1097 default:
1098 ret = -EOPNOTSUPP;
1099 break;
1100 }
1101 return ret;
1102}
1103
1104
1105static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1106 struct iw_request_info *info,
1107 struct iw_point *erq, char *extra)
1108{
1109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1110 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001111 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001112
1113 switch (ext->alg) {
1114 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001115 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001116 break;
1117 case IW_ENCODE_ALG_WEP:
1118 alg = ALG_WEP;
1119 break;
1120 case IW_ENCODE_ALG_TKIP:
1121 alg = ALG_TKIP;
1122 break;
1123 case IW_ENCODE_ALG_CCMP:
1124 alg = ALG_CCMP;
1125 break;
1126 default:
1127 return -EOPNOTSUPP;
1128 }
1129
1130 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001131 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001132
1133 idx = erq->flags & IW_ENCODE_INDEX;
1134 if (idx < 1 || idx > 4) {
1135 idx = -1;
1136 if (!sdata->default_key)
1137 idx = 0;
1138 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1139 if (sdata->default_key == sdata->keys[i]) {
1140 idx = i;
1141 break;
1142 }
1143 }
1144 if (idx < 0)
1145 return -EINVAL;
1146 } else
1147 idx--;
1148
1149 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001150 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001151 ext->ext_flags &
1152 IW_ENCODE_EXT_SET_TX_KEY,
1153 ext->key, ext->key_len);
1154}
1155
1156
Jiri Bencf0706e82007-05-05 11:45:53 -07001157/* Structures to export the Wireless Handlers */
1158
1159static const iw_handler ieee80211_handler[] =
1160{
1161 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1162 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1163 (iw_handler) NULL, /* SIOCSIWNWID */
1164 (iw_handler) NULL, /* SIOCGIWNWID */
1165 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1166 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1167 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1168 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1169 (iw_handler) NULL, /* SIOCSIWSENS */
1170 (iw_handler) NULL, /* SIOCGIWSENS */
1171 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1172 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1173 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1174 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1175 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1176 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001177 (iw_handler) NULL, /* SIOCSIWSPY */
1178 (iw_handler) NULL, /* SIOCGIWSPY */
1179 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1180 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001181 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1182 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1183 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1184 (iw_handler) NULL, /* SIOCGIWAPLIST */
1185 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1186 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1187 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1188 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1189 (iw_handler) NULL, /* SIOCSIWNICKN */
1190 (iw_handler) NULL, /* SIOCGIWNICKN */
1191 (iw_handler) NULL, /* -- hole -- */
1192 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001193 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001194 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001195 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1196 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1197 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1198 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001199 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001200 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001201 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1202 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1203 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1204 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1205 (iw_handler) NULL, /* SIOCSIWPOWER */
1206 (iw_handler) NULL, /* SIOCGIWPOWER */
1207 (iw_handler) NULL, /* -- hole -- */
1208 (iw_handler) NULL, /* -- hole -- */
1209 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1210 (iw_handler) NULL, /* SIOCGIWGENIE */
1211 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1212 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1213 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1214 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1215 (iw_handler) NULL, /* SIOCSIWPMKSA */
1216 (iw_handler) NULL, /* -- hole -- */
1217};
1218
Jiri Bencf0706e82007-05-05 11:45:53 -07001219const struct iw_handler_def ieee80211_iw_handler_def =
1220{
1221 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001222 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001223 .get_wireless_stats = ieee80211_get_wireless_stats,
1224};