blob: f2fdd334219525582b2d83c636824ef172c078fc [file] [log] [blame]
Jiri Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070026#include "wpa.h"
27#include "aes_ccm.h"
Jiri Bencf0706e822007-05-05 11:45:53 -070028
Johannes Bergb708e612007-09-14 11:10:25 -040029
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070038 struct ieee80211_sub_if_data *sdata;
Johannes Berg3b967662008-04-08 17:56:52 +020039 int err;
Jiri Bencf0706e822007-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 Bencf0706e822007-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
Emmanuel Grumbach23976ef2008-06-28 02:50:13 +030098 if (alg == ALG_WEP &&
99 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
100 ieee80211_key_free(key);
101 err = -EINVAL;
102 goto out_unlock;
103 }
104
Johannes Bergdb4d1162008-02-25 16:27:45 +0100105 ieee80211_key_link(key, sdata, sta);
106
107 if (set_tx_key || (!sta && !sdata->default_key && key))
108 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e822007-05-05 11:45:53 -0700109 }
110
Johannes Berg3b967662008-04-08 17:56:52 +0200111 out_unlock:
112 rcu_read_unlock();
113
114 return err;
Jiri Bencf0706e822007-05-05 11:45:53 -0700115}
116
117static int ieee80211_ioctl_siwgenie(struct net_device *dev,
118 struct iw_request_info *info,
119 struct iw_point *data, char *extra)
120{
121 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e822007-05-05 11:45:53 -0700122
123 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200124
125 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
126 return -EOPNOTSUPP;
127
Johannes Berg51fb61e2007-12-19 01:31:27 +0100128 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
129 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700130 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
131 if (ret)
132 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400133 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700134 ieee80211_sta_req_auth(dev, &sdata->u.sta);
135 return 0;
136 }
137
Jiri Bencf0706e822007-05-05 11:45:53 -0700138 return -EOPNOTSUPP;
139}
140
Jiri Bencf0706e822007-05-05 11:45:53 -0700141static int ieee80211_ioctl_giwname(struct net_device *dev,
142 struct iw_request_info *info,
143 char *name, char *extra)
144{
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300145 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
146 struct ieee80211_supported_band *sband;
147 u8 is_ht = 0, is_a = 0, is_b = 0, is_g = 0;
148
149
150 sband = local->hw.wiphy->bands[IEEE80211_BAND_5GHZ];
151 if (sband) {
152 is_a = 1;
153 is_ht |= sband->ht_info.ht_supported;
154 }
155
156 sband = local->hw.wiphy->bands[IEEE80211_BAND_2GHZ];
157 if (sband) {
158 int i;
159 /* Check for mandatory rates */
160 for (i = 0; i < sband->n_bitrates; i++) {
161 if (sband->bitrates[i].bitrate == 10)
162 is_b = 1;
163 if (sband->bitrates[i].bitrate == 60)
164 is_g = 1;
165 }
166 is_ht |= sband->ht_info.ht_supported;
167 }
168
Johannes Berg8318d782008-01-24 19:38:38 +0100169 strcpy(name, "IEEE 802.11");
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300170 if (is_a)
171 strcat(name, "a");
172 if (is_b)
173 strcat(name, "b");
174 if (is_g)
175 strcat(name, "g");
176 if (is_ht)
177 strcat(name, "n");
Jiri Bencf0706e822007-05-05 11:45:53 -0700178
179 return 0;
180}
181
182
183static int ieee80211_ioctl_giwrange(struct net_device *dev,
184 struct iw_request_info *info,
185 struct iw_point *data, char *extra)
186{
187 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
188 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100189 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200190 int c = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700191
192 data->length = sizeof(struct iw_range);
193 memset(range, 0, sizeof(struct iw_range));
194
195 range->we_version_compiled = WIRELESS_EXT;
196 range->we_version_source = 21;
197 range->retry_capa = IW_RETRY_LIMIT;
198 range->retry_flags = IW_RETRY_LIMIT;
199 range->min_retry = 0;
200 range->max_retry = 255;
201 range->min_rts = 0;
202 range->max_rts = 2347;
203 range->min_frag = 256;
204 range->max_frag = 2346;
205
206 range->encoding_size[0] = 5;
207 range->encoding_size[1] = 13;
208 range->num_encoding_sizes = 2;
209 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
210
Bruno Randolf566bfe52008-05-08 19:15:40 +0200211 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
212 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
213 range->max_qual.level = local->hw.max_signal;
214 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
215 range->max_qual.level = -110;
216 else
217 range->max_qual.level = 0;
218
219 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
220 range->max_qual.noise = -110;
221 else
222 range->max_qual.noise = 0;
223
224 range->max_qual.qual = 100;
Jiri Bencf0706e822007-05-05 11:45:53 -0700225 range->max_qual.updated = local->wstats_flags;
226
Bruno Randolf566bfe52008-05-08 19:15:40 +0200227 range->avg_qual.qual = 50;
228 /* not always true but better than nothing */
229 range->avg_qual.level = range->max_qual.level / 2;
230 range->avg_qual.noise = range->max_qual.noise / 2;
Jiri Bencf0706e822007-05-05 11:45:53 -0700231 range->avg_qual.updated = local->wstats_flags;
232
233 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
234 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
235
Hong Liu333af2f2007-07-10 19:32:08 +0200236
Johannes Berg8318d782008-01-24 19:38:38 +0100237 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
238 int i;
239 struct ieee80211_supported_band *sband;
240
241 sband = local->hw.wiphy->bands[band];
242
243 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200244 continue;
245
Johannes Berg8318d782008-01-24 19:38:38 +0100246 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
247 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200248
Johannes Berg8318d782008-01-24 19:38:38 +0100249 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
250 range->freq[c].i =
251 ieee80211_frequency_to_channel(
252 chan->center_freq);
253 range->freq[c].m = chan->center_freq;
254 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200255 c++;
256 }
Hong Liu333af2f2007-07-10 19:32:08 +0200257 }
258 }
259 range->num_channels = c;
260 range->num_frequency = c;
261
Jiri Bencf0706e822007-05-05 11:45:53 -0700262 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e822007-05-05 11:45:53 -0700263 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
264 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
265
Dan Williams374fdfb2007-12-12 10:25:07 -0500266 range->scan_capa |= IW_SCAN_CAPA_ESSID;
267
Jiri Bencf0706e822007-05-05 11:45:53 -0700268 return 0;
269}
270
271
Jiri Bencf0706e822007-05-05 11:45:53 -0700272static int ieee80211_ioctl_siwmode(struct net_device *dev,
273 struct iw_request_info *info,
274 __u32 *mode, char *extra)
275{
276 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
277 int type;
278
Johannes Berg51fb61e2007-12-19 01:31:27 +0100279 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e822007-05-05 11:45:53 -0700280 return -EOPNOTSUPP;
281
282 switch (*mode) {
283 case IW_MODE_INFRA:
284 type = IEEE80211_IF_TYPE_STA;
285 break;
286 case IW_MODE_ADHOC:
287 type = IEEE80211_IF_TYPE_IBSS;
288 break;
Johannes Bergb4540482008-04-14 15:37:03 +0200289 case IW_MODE_REPEAT:
290 type = IEEE80211_IF_TYPE_WDS;
291 break;
Jiri Bencf0706e822007-05-05 11:45:53 -0700292 case IW_MODE_MONITOR:
293 type = IEEE80211_IF_TYPE_MNTR;
294 break;
295 default:
296 return -EINVAL;
297 }
298
Johannes Berg51fb61e2007-12-19 01:31:27 +0100299 if (type == sdata->vif.type)
Jiri Bencf0706e822007-05-05 11:45:53 -0700300 return 0;
301 if (netif_running(dev))
302 return -EBUSY;
303
Johannes Berg75636522008-07-09 14:40:35 +0200304 ieee80211_if_change_type(sdata, type);
Jiri Bencf0706e822007-05-05 11:45:53 -0700305
306 return 0;
307}
308
309
310static int ieee80211_ioctl_giwmode(struct net_device *dev,
311 struct iw_request_info *info,
312 __u32 *mode, char *extra)
313{
314 struct ieee80211_sub_if_data *sdata;
315
316 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100317 switch (sdata->vif.type) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700318 case IEEE80211_IF_TYPE_AP:
319 *mode = IW_MODE_MASTER;
320 break;
321 case IEEE80211_IF_TYPE_STA:
322 *mode = IW_MODE_INFRA;
323 break;
324 case IEEE80211_IF_TYPE_IBSS:
325 *mode = IW_MODE_ADHOC;
326 break;
327 case IEEE80211_IF_TYPE_MNTR:
328 *mode = IW_MODE_MONITOR;
329 break;
330 case IEEE80211_IF_TYPE_WDS:
331 *mode = IW_MODE_REPEAT;
332 break;
333 case IEEE80211_IF_TYPE_VLAN:
334 *mode = IW_MODE_SECOND; /* FIXME */
335 break;
336 default:
337 *mode = IW_MODE_AUTO;
338 break;
339 }
340 return 0;
341}
342
Assaf Kraussbe038b32008-06-05 19:55:21 +0300343int ieee80211_set_freq(struct net_device *dev, int freqMHz)
Jiri Bencf0706e822007-05-05 11:45:53 -0700344{
Jiri Bencf0706e822007-05-05 11:45:53 -0700345 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100346 struct ieee80211_channel *chan;
Assaf Kraussbe038b32008-06-05 19:55:21 +0300347 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
348 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -0700349
Johannes Berge048c6e2008-03-16 18:35:56 +0100350 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100351
Johannes Berge048c6e2008-03-16 18:35:56 +0100352 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Assaf Kraussbe038b32008-06-05 19:55:21 +0300353 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
354 chan->flags & IEEE80211_CHAN_NO_IBSS) {
355 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
356 "%d MHz\n", dev->name, chan->center_freq);
357 return ret;
358 }
Johannes Berge048c6e2008-03-16 18:35:56 +0100359 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100360
Mohamed Abbas675ef582008-03-20 08:14:29 -0700361 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e822007-05-05 11:45:53 -0700362 ret = 0;
363 else
364 ret = ieee80211_hw_config(local);
365
366 rate_control_clear(local);
367 }
368
369 return ret;
370}
371
372static int ieee80211_ioctl_siwfreq(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_freq *freq, char *extra)
375{
Jiri Bencf0706e822007-05-05 11:45:53 -0700376 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
377
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 &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700380
381 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
382 if (freq->e == 0) {
383 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100384 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400385 sdata->u.sta.flags |=
386 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700387 return 0;
388 } else
Assaf Kraussbe038b32008-06-05 19:55:21 +0300389 return ieee80211_set_freq(dev,
Johannes Berg8318d782008-01-24 19:38:38 +0100390 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e822007-05-05 11:45:53 -0700391 } else {
392 int i, div = 1000000;
393 for (i = 0; i < freq->e; i++)
394 div /= 10;
395 if (div > 0)
Assaf Kraussbe038b32008-06-05 19:55:21 +0300396 return ieee80211_set_freq(dev, freq->m / div);
Jiri Bencf0706e822007-05-05 11:45:53 -0700397 else
398 return -EINVAL;
399 }
400}
401
402
403static int ieee80211_ioctl_giwfreq(struct net_device *dev,
404 struct iw_request_info *info,
405 struct iw_freq *freq, char *extra)
406{
407 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
408
Johannes Berg8318d782008-01-24 19:38:38 +0100409 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e822007-05-05 11:45:53 -0700410 freq->e = 6;
411
412 return 0;
413}
414
415
416static int ieee80211_ioctl_siwessid(struct net_device *dev,
417 struct iw_request_info *info,
418 struct iw_point *data, char *ssid)
419{
Jiri Bencf0706e822007-05-05 11:45:53 -0700420 struct ieee80211_sub_if_data *sdata;
421 size_t len = data->length;
422
423 /* iwconfig uses nul termination in SSID.. */
424 if (len > 0 && ssid[len - 1] == '\0')
425 len--;
426
427 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100428 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
429 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700430 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200431 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700432 if (len > IEEE80211_MAX_SSID_LEN)
433 return -EINVAL;
434 memcpy(sdata->u.sta.ssid, ssid, len);
435 sdata->u.sta.ssid_len = len;
436 return 0;
437 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400438 if (data->flags)
439 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
440 else
441 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700442 ret = ieee80211_sta_set_ssid(dev, ssid, len);
443 if (ret)
444 return ret;
445 ieee80211_sta_req_auth(dev, &sdata->u.sta);
446 return 0;
447 }
448
Johannes Berg51fb61e2007-12-19 01:31:27 +0100449 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700450 memcpy(sdata->u.ap.ssid, ssid, len);
451 memset(sdata->u.ap.ssid + len, 0,
452 IEEE80211_MAX_SSID_LEN - len);
453 sdata->u.ap.ssid_len = len;
454 return ieee80211_if_config(dev);
455 }
456 return -EOPNOTSUPP;
457}
458
459
460static int ieee80211_ioctl_giwessid(struct net_device *dev,
461 struct iw_request_info *info,
462 struct iw_point *data, char *ssid)
463{
464 size_t len;
465
466 struct ieee80211_sub_if_data *sdata;
467 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100468 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
469 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700470 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
471 if (res == 0) {
472 data->length = len;
473 data->flags = 1;
474 } else
475 data->flags = 0;
476 return res;
477 }
478
Johannes Berg51fb61e2007-12-19 01:31:27 +0100479 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700480 len = sdata->u.ap.ssid_len;
481 if (len > IW_ESSID_MAX_SIZE)
482 len = IW_ESSID_MAX_SIZE;
483 memcpy(ssid, sdata->u.ap.ssid, len);
484 data->length = len;
485 data->flags = 1;
486 return 0;
487 }
488 return -EOPNOTSUPP;
489}
490
491
492static int ieee80211_ioctl_siwap(struct net_device *dev,
493 struct iw_request_info *info,
494 struct sockaddr *ap_addr, char *extra)
495{
Jiri Bencf0706e822007-05-05 11:45:53 -0700496 struct ieee80211_sub_if_data *sdata;
497
498 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100499 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
500 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700501 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200502 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700503 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
504 ETH_ALEN);
505 return 0;
506 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400507 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
508 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
509 IEEE80211_STA_AUTO_CHANNEL_SEL;
510 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
511 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700512 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400513 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700514 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
515 if (ret)
516 return ret;
517 ieee80211_sta_req_auth(dev, &sdata->u.sta);
518 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100519 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100520 /*
521 * If it is necessary to update the WDS peer address
522 * while the interface is running, then we need to do
523 * more work here, namely if it is running we need to
524 * add a new and remove the old STA entry, this is
525 * normally handled by _open() and _stop().
526 */
527 if (netif_running(dev))
528 return -EBUSY;
529
530 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
531 ETH_ALEN);
532
533 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700534 }
535
536 return -EOPNOTSUPP;
537}
538
539
540static int ieee80211_ioctl_giwap(struct net_device *dev,
541 struct iw_request_info *info,
542 struct sockaddr *ap_addr, char *extra)
543{
544 struct ieee80211_sub_if_data *sdata;
545
546 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100547 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
548 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Abhijeet Kolekar5c5f9662008-06-12 09:47:16 +0800549 if (sdata->u.sta.state == IEEE80211_ASSOCIATED ||
550 sdata->u.sta.state == IEEE80211_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700551 ap_addr->sa_family = ARPHRD_ETHER;
552 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
553 return 0;
554 } else {
555 memset(&ap_addr->sa_data, 0, ETH_ALEN);
556 return 0;
557 }
Johannes Berg51fb61e2007-12-19 01:31:27 +0100558 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700559 ap_addr->sa_family = ARPHRD_ETHER;
560 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
561 return 0;
562 }
563
564 return -EOPNOTSUPP;
565}
566
567
568static int ieee80211_ioctl_siwscan(struct net_device *dev,
569 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400570 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e822007-05-05 11:45:53 -0700571{
Jiri Bencf0706e822007-05-05 11:45:53 -0700572 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400573 struct iw_scan_req *req = NULL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700574 u8 *ssid = NULL;
575 size_t ssid_len = 0;
576
577 if (!netif_running(dev))
578 return -ENETDOWN;
579
Johannes Berg51fb61e2007-12-19 01:31:27 +0100580 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
581 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100582 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100583 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700584 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700585
586 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400587 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
588 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
589 req = (struct iw_scan_req *)extra;
590 ssid = req->essid;
591 ssid_len = req->essid_len;
Jiri Bencf0706e822007-05-05 11:45:53 -0700592 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200593
Jiri Bencf0706e822007-05-05 11:45:53 -0700594 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
595}
596
597
598static int ieee80211_ioctl_giwscan(struct net_device *dev,
599 struct iw_request_info *info,
600 struct iw_point *data, char *extra)
601{
602 int res;
603 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800604
605 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e822007-05-05 11:45:53 -0700606 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800607
David S. Millerccc58052008-06-16 18:50:49 -0700608 res = ieee80211_sta_scan_results(dev, info, extra, data->length);
Jiri Bencf0706e822007-05-05 11:45:53 -0700609 if (res >= 0) {
610 data->length = res;
611 return 0;
612 }
613 data->length = 0;
614 return res;
615}
616
617
Larry Finger1fd5e582007-07-10 19:32:10 +0200618static int ieee80211_ioctl_siwrate(struct net_device *dev,
619 struct iw_request_info *info,
620 struct iw_param *rate, char *extra)
621{
622 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100623 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200624 u32 target_rate = rate->value / 100000;
625 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100626 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200627
628 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100629
630 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
631
Larry Finger1fd5e582007-07-10 19:32:10 +0200632 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
633 * target_rate = X, rate->fixed = 1 means only rate X
634 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200635 sdata->max_ratectrl_rateidx = -1;
636 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200637 if (rate->value < 0)
638 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100639
640 for (i=0; i< sband->n_bitrates; i++) {
641 struct ieee80211_rate *brate = &sband->bitrates[i];
642 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200643
Larry Finger1fd5e582007-07-10 19:32:10 +0200644 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200645 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200646 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200647 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100648 err = 0;
649 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200650 }
651 }
Johannes Berg8318d782008-01-24 19:38:38 +0100652 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200653}
654
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700655static int ieee80211_ioctl_giwrate(struct net_device *dev,
656 struct iw_request_info *info,
657 struct iw_param *rate, char *extra)
658{
659 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
660 struct sta_info *sta;
661 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100662 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700663
664 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100665
Johannes Berg380a9422008-04-04 23:40:35 +0200666 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700667 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100668
669 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
670
Johannes Berg380a9422008-04-04 23:40:35 +0200671 rcu_read_lock();
672
673 sta = sta_info_get(local, sdata->u.sta.bssid);
674
675 if (sta && sta->txrate_idx < sband->n_bitrates)
Johannes Berg8318d782008-01-24 19:38:38 +0100676 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700677 else
678 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200679
680 rcu_read_unlock();
681
682 if (!sta)
683 return -ENODEV;
684
Johannes Berg8318d782008-01-24 19:38:38 +0100685 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100686
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700687 return 0;
688}
689
Michael Buesch61609bc2007-09-20 22:06:39 +0200690static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
691 struct iw_request_info *info,
692 union iwreq_data *data, char *extra)
693{
694 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
695 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100696 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200697
698 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
699 return -EINVAL;
700 if (data->txpower.flags & IW_TXPOW_RANGE)
701 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200702
Mattias Nissler6a432952007-10-24 23:30:36 +0200703 if (data->txpower.fixed) {
704 new_power_level = data->txpower.value;
705 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100706 /*
707 * Automatic power level. Use maximum power for the current
708 * channel. Should be part of rate control.
709 */
710 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200711 if (!chan)
712 return -EINVAL;
713
Johannes Berg8318d782008-01-24 19:38:38 +0100714 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200715 }
716
717 if (local->hw.conf.power_level != new_power_level) {
718 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200719 need_reconfig = 1;
720 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200721
Michael Buesch61609bc2007-09-20 22:06:39 +0200722 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
723 local->hw.conf.radio_enabled = !(data->txpower.disabled);
724 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100725 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200726 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200727
Michael Buesch61609bc2007-09-20 22:06:39 +0200728 if (need_reconfig) {
729 ieee80211_hw_config(local);
730 /* The return value of hw_config is not of big interest here,
731 * as it doesn't say that it failed because of _this_ config
732 * change or something else. Ignore it. */
733 }
734
735 return 0;
736}
737
Larry Fingerfe6aa302007-08-10 11:23:20 -0500738static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
739 struct iw_request_info *info,
740 union iwreq_data *data, char *extra)
741{
742 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
743
744 data->txpower.fixed = 1;
745 data->txpower.disabled = !(local->hw.conf.radio_enabled);
746 data->txpower.value = local->hw.conf.power_level;
747 data->txpower.flags = IW_TXPOW_DBM;
748
749 return 0;
750}
751
Jiri Bencf0706e822007-05-05 11:45:53 -0700752static int ieee80211_ioctl_siwrts(struct net_device *dev,
753 struct iw_request_info *info,
754 struct iw_param *rts, char *extra)
755{
756 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
757
758 if (rts->disabled)
759 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300760 else if (!rts->fixed)
761 /* if the rts value is not fixed, then take default */
762 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e822007-05-05 11:45:53 -0700763 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
764 return -EINVAL;
765 else
766 local->rts_threshold = rts->value;
767
768 /* If the wlan card performs RTS/CTS in hardware/firmware,
769 * configure it here */
770
771 if (local->ops->set_rts_threshold)
772 local->ops->set_rts_threshold(local_to_hw(local),
773 local->rts_threshold);
774
775 return 0;
776}
777
778static int ieee80211_ioctl_giwrts(struct net_device *dev,
779 struct iw_request_info *info,
780 struct iw_param *rts, char *extra)
781{
782 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
783
784 rts->value = local->rts_threshold;
785 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
786 rts->fixed = 1;
787
788 return 0;
789}
790
791
792static int ieee80211_ioctl_siwfrag(struct net_device *dev,
793 struct iw_request_info *info,
794 struct iw_param *frag, char *extra)
795{
796 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
797
798 if (frag->disabled)
799 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300800 else if (!frag->fixed)
801 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e822007-05-05 11:45:53 -0700802 else if (frag->value < 256 ||
803 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
804 return -EINVAL;
805 else {
806 /* Fragment length must be even, so strip LSB. */
807 local->fragmentation_threshold = frag->value & ~0x1;
808 }
809
810 /* If the wlan card performs fragmentation in hardware/firmware,
811 * configure it here */
812
813 if (local->ops->set_frag_threshold)
814 local->ops->set_frag_threshold(
815 local_to_hw(local),
816 local->fragmentation_threshold);
817
818 return 0;
819}
820
821static int ieee80211_ioctl_giwfrag(struct net_device *dev,
822 struct iw_request_info *info,
823 struct iw_param *frag, char *extra)
824{
825 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
826
827 frag->value = local->fragmentation_threshold;
828 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
829 frag->fixed = 1;
830
831 return 0;
832}
833
834
835static int ieee80211_ioctl_siwretry(struct net_device *dev,
836 struct iw_request_info *info,
837 struct iw_param *retry, char *extra)
838{
839 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
840
841 if (retry->disabled ||
842 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
843 return -EINVAL;
844
845 if (retry->flags & IW_RETRY_MAX)
846 local->long_retry_limit = retry->value;
847 else if (retry->flags & IW_RETRY_MIN)
848 local->short_retry_limit = retry->value;
849 else {
850 local->long_retry_limit = retry->value;
851 local->short_retry_limit = retry->value;
852 }
853
854 if (local->ops->set_retry_limit) {
855 return local->ops->set_retry_limit(
856 local_to_hw(local),
857 local->short_retry_limit,
858 local->long_retry_limit);
859 }
860
861 return 0;
862}
863
864
865static int ieee80211_ioctl_giwretry(struct net_device *dev,
866 struct iw_request_info *info,
867 struct iw_param *retry, char *extra)
868{
869 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
870
871 retry->disabled = 0;
872 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
873 /* first return min value, iwconfig will ask max value
874 * later if needed */
875 retry->flags |= IW_RETRY_LIMIT;
876 retry->value = local->short_retry_limit;
877 if (local->long_retry_limit != local->short_retry_limit)
878 retry->flags |= IW_RETRY_MIN;
879 return 0;
880 }
881 if (retry->flags & IW_RETRY_MAX) {
882 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
883 retry->value = local->long_retry_limit;
884 }
885
886 return 0;
887}
888
Jiri Bencf0706e822007-05-05 11:45:53 -0700889static int ieee80211_ioctl_siwmlme(struct net_device *dev,
890 struct iw_request_info *info,
891 struct iw_point *data, char *extra)
892{
893 struct ieee80211_sub_if_data *sdata;
894 struct iw_mlme *mlme = (struct iw_mlme *) extra;
895
896 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100897 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
898 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e822007-05-05 11:45:53 -0700899 return -EINVAL;
900
901 switch (mlme->cmd) {
902 case IW_MLME_DEAUTH:
903 /* TODO: mlme->addr.sa_data */
904 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
905 case IW_MLME_DISASSOC:
906 /* TODO: mlme->addr.sa_data */
907 return ieee80211_sta_disassociate(dev, mlme->reason_code);
908 default:
909 return -EOPNOTSUPP;
910 }
911}
912
913
914static int ieee80211_ioctl_siwencode(struct net_device *dev,
915 struct iw_request_info *info,
916 struct iw_point *erq, char *keybuf)
917{
918 struct ieee80211_sub_if_data *sdata;
919 int idx, i, alg = ALG_WEP;
920 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200921 int remove = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700922
923 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
924
925 idx = erq->flags & IW_ENCODE_INDEX;
926 if (idx == 0) {
927 if (sdata->default_key)
928 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
929 if (sdata->default_key == sdata->keys[i]) {
930 idx = i;
931 break;
932 }
933 }
934 } else if (idx < 1 || idx > 4)
935 return -EINVAL;
936 else
937 idx--;
938
939 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200940 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -0700941 else if (erq->length == 0) {
942 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400943 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e822007-05-05 11:45:53 -0700944 return 0;
945 }
946
947 return ieee80211_set_encryption(
948 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200949 idx, alg, remove,
Jiri Bencf0706e822007-05-05 11:45:53 -0700950 !sdata->default_key,
951 keybuf, erq->length);
952}
953
954
955static int ieee80211_ioctl_giwencode(struct net_device *dev,
956 struct iw_request_info *info,
957 struct iw_point *erq, char *key)
958{
959 struct ieee80211_sub_if_data *sdata;
960 int idx, i;
961
962 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
963
964 idx = erq->flags & IW_ENCODE_INDEX;
965 if (idx < 1 || idx > 4) {
966 idx = -1;
967 if (!sdata->default_key)
968 idx = 0;
969 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
970 if (sdata->default_key == sdata->keys[i]) {
971 idx = i;
972 break;
973 }
974 }
975 if (idx < 0)
976 return -EINVAL;
977 } else
978 idx--;
979
980 erq->flags = idx + 1;
981
982 if (!sdata->keys[idx]) {
983 erq->length = 0;
984 erq->flags |= IW_ENCODE_DISABLED;
985 return 0;
986 }
987
Johannes Berg8f20fc22007-08-28 17:01:54 -0400988 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400989 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400990 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e822007-05-05 11:45:53 -0700991 erq->flags |= IW_ENCODE_ENABLED;
992
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300993 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
994 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
995 switch (ifsta->auth_alg) {
996 case WLAN_AUTH_OPEN:
997 case WLAN_AUTH_LEAP:
998 erq->flags |= IW_ENCODE_OPEN;
999 break;
1000 case WLAN_AUTH_SHARED_KEY:
1001 erq->flags |= IW_ENCODE_RESTRICTED;
1002 break;
1003 }
1004 }
1005
Jiri Bencf0706e822007-05-05 11:45:53 -07001006 return 0;
1007}
1008
Samuel Ortiz49292d52008-07-04 10:49:31 +02001009static int ieee80211_ioctl_siwpower(struct net_device *dev,
1010 struct iw_request_info *info,
1011 struct iw_param *wrq,
1012 char *extra)
1013{
1014 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1015 struct ieee80211_conf *conf = &local->hw.conf;
1016
1017 if (wrq->disabled) {
1018 conf->flags &= ~IEEE80211_CONF_PS;
1019 return ieee80211_hw_config(local);
1020 }
1021
1022 switch (wrq->flags & IW_POWER_MODE) {
1023 case IW_POWER_ON: /* If not specified */
1024 case IW_POWER_MODE: /* If set all mask */
1025 case IW_POWER_ALL_R: /* If explicitely state all */
1026 conf->flags |= IEEE80211_CONF_PS;
1027 break;
1028 default: /* Otherwise we don't support it */
1029 return -EINVAL;
1030 }
1031
1032 return ieee80211_hw_config(local);
1033}
1034
1035static int ieee80211_ioctl_giwpower(struct net_device *dev,
1036 struct iw_request_info *info,
1037 union iwreq_data *wrqu,
1038 char *extra)
1039{
1040 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1041 struct ieee80211_conf *conf = &local->hw.conf;
1042
1043 wrqu->power.disabled = !(conf->flags & IEEE80211_CONF_PS);
1044
1045 return 0;
1046}
1047
Jiri Bencf0706e822007-05-05 11:45:53 -07001048static int ieee80211_ioctl_siwauth(struct net_device *dev,
1049 struct iw_request_info *info,
1050 struct iw_param *data, char *extra)
1051{
Jiri Bencf0706e822007-05-05 11:45:53 -07001052 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1053 int ret = 0;
1054
1055 switch (data->flags & IW_AUTH_INDEX) {
1056 case IW_AUTH_WPA_VERSION:
1057 case IW_AUTH_CIPHER_PAIRWISE:
1058 case IW_AUTH_CIPHER_GROUP:
1059 case IW_AUTH_WPA_ENABLED:
1060 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e822007-05-05 11:45:53 -07001061 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001062 break;
Johannes Bergb1357a82007-11-28 11:04:21 +01001063 case IW_AUTH_DROP_UNENCRYPTED:
1064 sdata->drop_unencrypted = !!data->value;
1065 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001066 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001067 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e822007-05-05 11:45:53 -07001068 ret = -EINVAL;
1069 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001070 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e822007-05-05 11:45:53 -07001071 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001072 * Privacy invoked by wpa_supplicant, store the
1073 * value and allow associating to a protected
1074 * network without having a key up front.
Jiri Bencf0706e822007-05-05 11:45:53 -07001075 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001076 if (data->value)
1077 sdata->u.sta.flags |=
1078 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e822007-05-05 11:45:53 -07001079 }
1080 break;
1081 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001082 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1083 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e822007-05-05 11:45:53 -07001084 sdata->u.sta.auth_algs = data->value;
1085 else
1086 ret = -EOPNOTSUPP;
1087 break;
Jiri Bencf0706e822007-05-05 11:45:53 -07001088 default:
1089 ret = -EOPNOTSUPP;
1090 break;
1091 }
1092 return ret;
1093}
1094
1095/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1096static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1097{
1098 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1099 struct iw_statistics *wstats = &local->wstats;
1100 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1101 struct sta_info *sta = NULL;
1102
Johannes Berg98dd6a52008-04-10 15:36:09 +02001103 rcu_read_lock();
1104
Johannes Berg51fb61e2007-12-19 01:31:27 +01001105 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1106 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e822007-05-05 11:45:53 -07001107 sta = sta_info_get(local, sdata->u.sta.bssid);
1108 if (!sta) {
1109 wstats->discard.fragment = 0;
1110 wstats->discard.misc = 0;
1111 wstats->qual.qual = 0;
1112 wstats->qual.level = 0;
1113 wstats->qual.noise = 0;
1114 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1115 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001116 wstats->qual.level = sta->last_signal;
1117 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e822007-05-05 11:45:53 -07001118 wstats->qual.noise = sta->last_noise;
1119 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e822007-05-05 11:45:53 -07001120 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001121
1122 rcu_read_unlock();
1123
Jiri Bencf0706e822007-05-05 11:45:53 -07001124 return wstats;
1125}
1126
1127static int ieee80211_ioctl_giwauth(struct net_device *dev,
1128 struct iw_request_info *info,
1129 struct iw_param *data, char *extra)
1130{
1131 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1132 int ret = 0;
1133
1134 switch (data->flags & IW_AUTH_INDEX) {
1135 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001136 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1137 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e822007-05-05 11:45:53 -07001138 data->value = sdata->u.sta.auth_algs;
1139 else
1140 ret = -EOPNOTSUPP;
1141 break;
1142 default:
1143 ret = -EOPNOTSUPP;
1144 break;
1145 }
1146 return ret;
1147}
1148
1149
1150static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1151 struct iw_request_info *info,
1152 struct iw_point *erq, char *extra)
1153{
1154 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1155 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001156 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07001157
1158 switch (ext->alg) {
1159 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001160 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -07001161 break;
1162 case IW_ENCODE_ALG_WEP:
1163 alg = ALG_WEP;
1164 break;
1165 case IW_ENCODE_ALG_TKIP:
1166 alg = ALG_TKIP;
1167 break;
1168 case IW_ENCODE_ALG_CCMP:
1169 alg = ALG_CCMP;
1170 break;
1171 default:
1172 return -EOPNOTSUPP;
1173 }
1174
1175 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001176 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -07001177
1178 idx = erq->flags & IW_ENCODE_INDEX;
1179 if (idx < 1 || idx > 4) {
1180 idx = -1;
1181 if (!sdata->default_key)
1182 idx = 0;
1183 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1184 if (sdata->default_key == sdata->keys[i]) {
1185 idx = i;
1186 break;
1187 }
1188 }
1189 if (idx < 0)
1190 return -EINVAL;
1191 } else
1192 idx--;
1193
1194 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001195 remove,
Jiri Bencf0706e822007-05-05 11:45:53 -07001196 ext->ext_flags &
1197 IW_ENCODE_EXT_SET_TX_KEY,
1198 ext->key, ext->key_len);
1199}
1200
1201
Jiri Bencf0706e822007-05-05 11:45:53 -07001202/* Structures to export the Wireless Handlers */
1203
1204static const iw_handler ieee80211_handler[] =
1205{
1206 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1207 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1208 (iw_handler) NULL, /* SIOCSIWNWID */
1209 (iw_handler) NULL, /* SIOCGIWNWID */
1210 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1211 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1212 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1213 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1214 (iw_handler) NULL, /* SIOCSIWSENS */
1215 (iw_handler) NULL, /* SIOCGIWSENS */
1216 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1217 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1218 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1219 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1220 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1221 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001222 (iw_handler) NULL, /* SIOCSIWSPY */
1223 (iw_handler) NULL, /* SIOCGIWSPY */
1224 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1225 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e822007-05-05 11:45:53 -07001226 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1227 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1228 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1229 (iw_handler) NULL, /* SIOCGIWAPLIST */
1230 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1231 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1232 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1233 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1234 (iw_handler) NULL, /* SIOCSIWNICKN */
1235 (iw_handler) NULL, /* SIOCGIWNICKN */
1236 (iw_handler) NULL, /* -- hole -- */
1237 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001238 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001239 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e822007-05-05 11:45:53 -07001240 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1241 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1242 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1243 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001244 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001245 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e822007-05-05 11:45:53 -07001246 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1247 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1248 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1249 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001250 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1251 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e822007-05-05 11:45:53 -07001252 (iw_handler) NULL, /* -- hole -- */
1253 (iw_handler) NULL, /* -- hole -- */
1254 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1255 (iw_handler) NULL, /* SIOCGIWGENIE */
1256 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1257 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1258 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1259 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1260 (iw_handler) NULL, /* SIOCSIWPMKSA */
1261 (iw_handler) NULL, /* -- hole -- */
1262};
1263
Jiri Bencf0706e822007-05-05 11:45:53 -07001264const struct iw_handler_def ieee80211_iw_handler_def =
1265{
1266 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e822007-05-05 11:45:53 -07001267 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e822007-05-05 11:45:53 -07001268 .get_wireless_stats = ieee80211_get_wireless_stats,
1269};