blob: e8e4a6215e89c074a9ea0465bdcadb51c730a7aa [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
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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -0700134 ieee80211_sta_req_auth(dev, &sdata->u.sta);
135 return 0;
136 }
137
Jiri Bencf0706e82007-05-05 11:45:53 -0700138 return -EOPNOTSUPP;
139}
140
Jiri Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -0700262 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -0700268 return 0;
269}
270
271
Jiri Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -0700300 return 0;
301 if (netif_running(dev))
302 return -EBUSY;
303
304 ieee80211_if_reinit(dev);
305 ieee80211_if_set_type(dev, type);
306
307 return 0;
308}
309
310
311static int ieee80211_ioctl_giwmode(struct net_device *dev,
312 struct iw_request_info *info,
313 __u32 *mode, char *extra)
314{
315 struct ieee80211_sub_if_data *sdata;
316
317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100318 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700319 case IEEE80211_IF_TYPE_AP:
320 *mode = IW_MODE_MASTER;
321 break;
322 case IEEE80211_IF_TYPE_STA:
323 *mode = IW_MODE_INFRA;
324 break;
325 case IEEE80211_IF_TYPE_IBSS:
326 *mode = IW_MODE_ADHOC;
327 break;
328 case IEEE80211_IF_TYPE_MNTR:
329 *mode = IW_MODE_MONITOR;
330 break;
331 case IEEE80211_IF_TYPE_WDS:
332 *mode = IW_MODE_REPEAT;
333 break;
334 case IEEE80211_IF_TYPE_VLAN:
335 *mode = IW_MODE_SECOND; /* FIXME */
336 break;
337 default:
338 *mode = IW_MODE_AUTO;
339 break;
340 }
341 return 0;
342}
343
Assaf Kraussbe038b32008-06-05 19:55:21 +0300344int ieee80211_set_freq(struct net_device *dev, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700345{
Jiri Bencf0706e82007-05-05 11:45:53 -0700346 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100347 struct ieee80211_channel *chan;
Assaf Kraussbe038b32008-06-05 19:55:21 +0300348 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
349 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700350
Johannes Berge048c6e2008-03-16 18:35:56 +0100351 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100352
Johannes Berge048c6e2008-03-16 18:35:56 +0100353 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Assaf Kraussbe038b32008-06-05 19:55:21 +0300354 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
355 chan->flags & IEEE80211_CHAN_NO_IBSS) {
356 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
357 "%d MHz\n", dev->name, chan->center_freq);
358 return ret;
359 }
Johannes Berge048c6e2008-03-16 18:35:56 +0100360 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100361
Mohamed Abbas675ef582008-03-20 08:14:29 -0700362 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700363 ret = 0;
364 else
365 ret = ieee80211_hw_config(local);
366
367 rate_control_clear(local);
368 }
369
370 return ret;
371}
372
373static int ieee80211_ioctl_siwfreq(struct net_device *dev,
374 struct iw_request_info *info,
375 struct iw_freq *freq, char *extra)
376{
Jiri Bencf0706e82007-05-05 11:45:53 -0700377 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
378
Johannes Berg51fb61e2007-12-19 01:31:27 +0100379 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400380 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700381
382 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
383 if (freq->e == 0) {
384 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100385 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400386 sdata->u.sta.flags |=
387 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700388 return 0;
389 } else
Assaf Kraussbe038b32008-06-05 19:55:21 +0300390 return ieee80211_set_freq(dev,
Johannes Berg8318d782008-01-24 19:38:38 +0100391 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700392 } else {
393 int i, div = 1000000;
394 for (i = 0; i < freq->e; i++)
395 div /= 10;
396 if (div > 0)
Assaf Kraussbe038b32008-06-05 19:55:21 +0300397 return ieee80211_set_freq(dev, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700398 else
399 return -EINVAL;
400 }
401}
402
403
404static int ieee80211_ioctl_giwfreq(struct net_device *dev,
405 struct iw_request_info *info,
406 struct iw_freq *freq, char *extra)
407{
408 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
409
Johannes Berg8318d782008-01-24 19:38:38 +0100410 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700411 freq->e = 6;
412
413 return 0;
414}
415
416
417static int ieee80211_ioctl_siwessid(struct net_device *dev,
418 struct iw_request_info *info,
419 struct iw_point *data, char *ssid)
420{
Jiri Bencf0706e82007-05-05 11:45:53 -0700421 struct ieee80211_sub_if_data *sdata;
422 size_t len = data->length;
423
424 /* iwconfig uses nul termination in SSID.. */
425 if (len > 0 && ssid[len - 1] == '\0')
426 len--;
427
428 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100429 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
430 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700431 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200432 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700433 if (len > IEEE80211_MAX_SSID_LEN)
434 return -EINVAL;
435 memcpy(sdata->u.sta.ssid, ssid, len);
436 sdata->u.sta.ssid_len = len;
437 return 0;
438 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400439 if (data->flags)
440 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
441 else
442 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700443 ret = ieee80211_sta_set_ssid(dev, ssid, len);
444 if (ret)
445 return ret;
446 ieee80211_sta_req_auth(dev, &sdata->u.sta);
447 return 0;
448 }
449
Johannes Berg51fb61e2007-12-19 01:31:27 +0100450 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700451 memcpy(sdata->u.ap.ssid, ssid, len);
452 memset(sdata->u.ap.ssid + len, 0,
453 IEEE80211_MAX_SSID_LEN - len);
454 sdata->u.ap.ssid_len = len;
455 return ieee80211_if_config(dev);
456 }
457 return -EOPNOTSUPP;
458}
459
460
461static int ieee80211_ioctl_giwessid(struct net_device *dev,
462 struct iw_request_info *info,
463 struct iw_point *data, char *ssid)
464{
465 size_t len;
466
467 struct ieee80211_sub_if_data *sdata;
468 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100469 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
470 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700471 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
472 if (res == 0) {
473 data->length = len;
474 data->flags = 1;
475 } else
476 data->flags = 0;
477 return res;
478 }
479
Johannes Berg51fb61e2007-12-19 01:31:27 +0100480 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700481 len = sdata->u.ap.ssid_len;
482 if (len > IW_ESSID_MAX_SIZE)
483 len = IW_ESSID_MAX_SIZE;
484 memcpy(ssid, sdata->u.ap.ssid, len);
485 data->length = len;
486 data->flags = 1;
487 return 0;
488 }
489 return -EOPNOTSUPP;
490}
491
492
493static int ieee80211_ioctl_siwap(struct net_device *dev,
494 struct iw_request_info *info,
495 struct sockaddr *ap_addr, char *extra)
496{
Jiri Bencf0706e82007-05-05 11:45:53 -0700497 struct ieee80211_sub_if_data *sdata;
498
499 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100500 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
501 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700502 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200503 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700504 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
505 ETH_ALEN);
506 return 0;
507 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400508 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
509 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
510 IEEE80211_STA_AUTO_CHANNEL_SEL;
511 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
512 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700513 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400514 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700515 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
516 if (ret)
517 return ret;
518 ieee80211_sta_req_auth(dev, &sdata->u.sta);
519 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100520 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100521 /*
522 * If it is necessary to update the WDS peer address
523 * while the interface is running, then we need to do
524 * more work here, namely if it is running we need to
525 * add a new and remove the old STA entry, this is
526 * normally handled by _open() and _stop().
527 */
528 if (netif_running(dev))
529 return -EBUSY;
530
531 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
532 ETH_ALEN);
533
534 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700535 }
536
537 return -EOPNOTSUPP;
538}
539
540
541static int ieee80211_ioctl_giwap(struct net_device *dev,
542 struct iw_request_info *info,
543 struct sockaddr *ap_addr, char *extra)
544{
545 struct ieee80211_sub_if_data *sdata;
546
547 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100548 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
549 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Abhijeet Kolekar5c5f9662008-06-12 09:47:16 +0800550 if (sdata->u.sta.state == IEEE80211_ASSOCIATED ||
551 sdata->u.sta.state == IEEE80211_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700552 ap_addr->sa_family = ARPHRD_ETHER;
553 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
554 return 0;
555 } else {
556 memset(&ap_addr->sa_data, 0, ETH_ALEN);
557 return 0;
558 }
Johannes Berg51fb61e2007-12-19 01:31:27 +0100559 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700560 ap_addr->sa_family = ARPHRD_ETHER;
561 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
562 return 0;
563 }
564
565 return -EOPNOTSUPP;
566}
567
568
569static int ieee80211_ioctl_siwscan(struct net_device *dev,
570 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400571 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700572{
Jiri Bencf0706e82007-05-05 11:45:53 -0700573 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400574 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700575 u8 *ssid = NULL;
576 size_t ssid_len = 0;
577
578 if (!netif_running(dev))
579 return -ENETDOWN;
580
Johannes Berg51fb61e2007-12-19 01:31:27 +0100581 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
582 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100583 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100584 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700585 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700586
587 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400588 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
589 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
590 req = (struct iw_scan_req *)extra;
591 ssid = req->essid;
592 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700593 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200594
Jiri Bencf0706e82007-05-05 11:45:53 -0700595 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
596}
597
598
599static int ieee80211_ioctl_giwscan(struct net_device *dev,
600 struct iw_request_info *info,
601 struct iw_point *data, char *extra)
602{
603 int res;
604 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800605
606 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700607 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800608
David S. Millerccc58052008-06-16 18:50:49 -0700609 res = ieee80211_sta_scan_results(dev, info, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700610 if (res >= 0) {
611 data->length = res;
612 return 0;
613 }
614 data->length = 0;
615 return res;
616}
617
618
Larry Finger1fd5e582007-07-10 19:32:10 +0200619static int ieee80211_ioctl_siwrate(struct net_device *dev,
620 struct iw_request_info *info,
621 struct iw_param *rate, char *extra)
622{
623 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100624 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200625 u32 target_rate = rate->value / 100000;
626 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100627 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200628
629 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100630
631 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
632
Larry Finger1fd5e582007-07-10 19:32:10 +0200633 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
634 * target_rate = X, rate->fixed = 1 means only rate X
635 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200636 sdata->max_ratectrl_rateidx = -1;
637 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200638 if (rate->value < 0)
639 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100640
641 for (i=0; i< sband->n_bitrates; i++) {
642 struct ieee80211_rate *brate = &sband->bitrates[i];
643 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200644
Larry Finger1fd5e582007-07-10 19:32:10 +0200645 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200646 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200647 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200648 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100649 err = 0;
650 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200651 }
652 }
Johannes Berg8318d782008-01-24 19:38:38 +0100653 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200654}
655
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700656static int ieee80211_ioctl_giwrate(struct net_device *dev,
657 struct iw_request_info *info,
658 struct iw_param *rate, char *extra)
659{
660 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
661 struct sta_info *sta;
662 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100663 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700664
665 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100666
Johannes Berg380a9422008-04-04 23:40:35 +0200667 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700668 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100669
670 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
671
Johannes Berg380a9422008-04-04 23:40:35 +0200672 rcu_read_lock();
673
674 sta = sta_info_get(local, sdata->u.sta.bssid);
675
676 if (sta && sta->txrate_idx < sband->n_bitrates)
Johannes Berg8318d782008-01-24 19:38:38 +0100677 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700678 else
679 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200680
681 rcu_read_unlock();
682
683 if (!sta)
684 return -ENODEV;
685
Johannes Berg8318d782008-01-24 19:38:38 +0100686 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100687
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700688 return 0;
689}
690
Michael Buesch61609bc2007-09-20 22:06:39 +0200691static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
692 struct iw_request_info *info,
693 union iwreq_data *data, char *extra)
694{
695 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
696 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100697 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200698
699 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
700 return -EINVAL;
701 if (data->txpower.flags & IW_TXPOW_RANGE)
702 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200703
Mattias Nissler6a432952007-10-24 23:30:36 +0200704 if (data->txpower.fixed) {
705 new_power_level = data->txpower.value;
706 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100707 /*
708 * Automatic power level. Use maximum power for the current
709 * channel. Should be part of rate control.
710 */
711 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200712 if (!chan)
713 return -EINVAL;
714
Johannes Berg8318d782008-01-24 19:38:38 +0100715 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200716 }
717
718 if (local->hw.conf.power_level != new_power_level) {
719 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200720 need_reconfig = 1;
721 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200722
Michael Buesch61609bc2007-09-20 22:06:39 +0200723 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
724 local->hw.conf.radio_enabled = !(data->txpower.disabled);
725 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100726 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200727 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200728
Michael Buesch61609bc2007-09-20 22:06:39 +0200729 if (need_reconfig) {
730 ieee80211_hw_config(local);
731 /* The return value of hw_config is not of big interest here,
732 * as it doesn't say that it failed because of _this_ config
733 * change or something else. Ignore it. */
734 }
735
736 return 0;
737}
738
Larry Fingerfe6aa302007-08-10 11:23:20 -0500739static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
740 struct iw_request_info *info,
741 union iwreq_data *data, char *extra)
742{
743 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
744
745 data->txpower.fixed = 1;
746 data->txpower.disabled = !(local->hw.conf.radio_enabled);
747 data->txpower.value = local->hw.conf.power_level;
748 data->txpower.flags = IW_TXPOW_DBM;
749
750 return 0;
751}
752
Jiri Bencf0706e82007-05-05 11:45:53 -0700753static int ieee80211_ioctl_siwrts(struct net_device *dev,
754 struct iw_request_info *info,
755 struct iw_param *rts, char *extra)
756{
757 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
758
759 if (rts->disabled)
760 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300761 else if (!rts->fixed)
762 /* if the rts value is not fixed, then take default */
763 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700764 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
765 return -EINVAL;
766 else
767 local->rts_threshold = rts->value;
768
769 /* If the wlan card performs RTS/CTS in hardware/firmware,
770 * configure it here */
771
772 if (local->ops->set_rts_threshold)
773 local->ops->set_rts_threshold(local_to_hw(local),
774 local->rts_threshold);
775
776 return 0;
777}
778
779static int ieee80211_ioctl_giwrts(struct net_device *dev,
780 struct iw_request_info *info,
781 struct iw_param *rts, char *extra)
782{
783 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
784
785 rts->value = local->rts_threshold;
786 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
787 rts->fixed = 1;
788
789 return 0;
790}
791
792
793static int ieee80211_ioctl_siwfrag(struct net_device *dev,
794 struct iw_request_info *info,
795 struct iw_param *frag, char *extra)
796{
797 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
798
799 if (frag->disabled)
800 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300801 else if (!frag->fixed)
802 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700803 else if (frag->value < 256 ||
804 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
805 return -EINVAL;
806 else {
807 /* Fragment length must be even, so strip LSB. */
808 local->fragmentation_threshold = frag->value & ~0x1;
809 }
810
811 /* If the wlan card performs fragmentation in hardware/firmware,
812 * configure it here */
813
814 if (local->ops->set_frag_threshold)
815 local->ops->set_frag_threshold(
816 local_to_hw(local),
817 local->fragmentation_threshold);
818
819 return 0;
820}
821
822static int ieee80211_ioctl_giwfrag(struct net_device *dev,
823 struct iw_request_info *info,
824 struct iw_param *frag, char *extra)
825{
826 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
827
828 frag->value = local->fragmentation_threshold;
829 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
830 frag->fixed = 1;
831
832 return 0;
833}
834
835
836static int ieee80211_ioctl_siwretry(struct net_device *dev,
837 struct iw_request_info *info,
838 struct iw_param *retry, char *extra)
839{
840 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
841
842 if (retry->disabled ||
843 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
844 return -EINVAL;
845
846 if (retry->flags & IW_RETRY_MAX)
847 local->long_retry_limit = retry->value;
848 else if (retry->flags & IW_RETRY_MIN)
849 local->short_retry_limit = retry->value;
850 else {
851 local->long_retry_limit = retry->value;
852 local->short_retry_limit = retry->value;
853 }
854
855 if (local->ops->set_retry_limit) {
856 return local->ops->set_retry_limit(
857 local_to_hw(local),
858 local->short_retry_limit,
859 local->long_retry_limit);
860 }
861
862 return 0;
863}
864
865
866static int ieee80211_ioctl_giwretry(struct net_device *dev,
867 struct iw_request_info *info,
868 struct iw_param *retry, char *extra)
869{
870 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
871
872 retry->disabled = 0;
873 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
874 /* first return min value, iwconfig will ask max value
875 * later if needed */
876 retry->flags |= IW_RETRY_LIMIT;
877 retry->value = local->short_retry_limit;
878 if (local->long_retry_limit != local->short_retry_limit)
879 retry->flags |= IW_RETRY_MIN;
880 return 0;
881 }
882 if (retry->flags & IW_RETRY_MAX) {
883 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
884 retry->value = local->long_retry_limit;
885 }
886
887 return 0;
888}
889
Jiri Bencf0706e82007-05-05 11:45:53 -0700890static int ieee80211_ioctl_siwmlme(struct net_device *dev,
891 struct iw_request_info *info,
892 struct iw_point *data, char *extra)
893{
894 struct ieee80211_sub_if_data *sdata;
895 struct iw_mlme *mlme = (struct iw_mlme *) extra;
896
897 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100898 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
899 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700900 return -EINVAL;
901
902 switch (mlme->cmd) {
903 case IW_MLME_DEAUTH:
904 /* TODO: mlme->addr.sa_data */
905 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
906 case IW_MLME_DISASSOC:
907 /* TODO: mlme->addr.sa_data */
908 return ieee80211_sta_disassociate(dev, mlme->reason_code);
909 default:
910 return -EOPNOTSUPP;
911 }
912}
913
914
915static int ieee80211_ioctl_siwencode(struct net_device *dev,
916 struct iw_request_info *info,
917 struct iw_point *erq, char *keybuf)
918{
919 struct ieee80211_sub_if_data *sdata;
920 int idx, i, alg = ALG_WEP;
921 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200922 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700923
924 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
925
926 idx = erq->flags & IW_ENCODE_INDEX;
927 if (idx == 0) {
928 if (sdata->default_key)
929 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
930 if (sdata->default_key == sdata->keys[i]) {
931 idx = i;
932 break;
933 }
934 }
935 } else if (idx < 1 || idx > 4)
936 return -EINVAL;
937 else
938 idx--;
939
940 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200941 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700942 else if (erq->length == 0) {
943 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400944 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700945 return 0;
946 }
947
948 return ieee80211_set_encryption(
949 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200950 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700951 !sdata->default_key,
952 keybuf, erq->length);
953}
954
955
956static int ieee80211_ioctl_giwencode(struct net_device *dev,
957 struct iw_request_info *info,
958 struct iw_point *erq, char *key)
959{
960 struct ieee80211_sub_if_data *sdata;
961 int idx, i;
962
963 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
964
965 idx = erq->flags & IW_ENCODE_INDEX;
966 if (idx < 1 || idx > 4) {
967 idx = -1;
968 if (!sdata->default_key)
969 idx = 0;
970 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
971 if (sdata->default_key == sdata->keys[i]) {
972 idx = i;
973 break;
974 }
975 }
976 if (idx < 0)
977 return -EINVAL;
978 } else
979 idx--;
980
981 erq->flags = idx + 1;
982
983 if (!sdata->keys[idx]) {
984 erq->length = 0;
985 erq->flags |= IW_ENCODE_DISABLED;
986 return 0;
987 }
988
Johannes Berg8f20fc22007-08-28 17:01:54 -0400989 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400990 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400991 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700992 erq->flags |= IW_ENCODE_ENABLED;
993
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300994 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
995 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
996 switch (ifsta->auth_alg) {
997 case WLAN_AUTH_OPEN:
998 case WLAN_AUTH_LEAP:
999 erq->flags |= IW_ENCODE_OPEN;
1000 break;
1001 case WLAN_AUTH_SHARED_KEY:
1002 erq->flags |= IW_ENCODE_RESTRICTED;
1003 break;
1004 }
1005 }
1006
Jiri Bencf0706e82007-05-05 11:45:53 -07001007 return 0;
1008}
1009
Samuel Ortiz49292d52008-07-04 10:49:31 +02001010static int ieee80211_ioctl_siwpower(struct net_device *dev,
1011 struct iw_request_info *info,
1012 struct iw_param *wrq,
1013 char *extra)
1014{
1015 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1016 struct ieee80211_conf *conf = &local->hw.conf;
1017
1018 if (wrq->disabled) {
1019 conf->flags &= ~IEEE80211_CONF_PS;
1020 return ieee80211_hw_config(local);
1021 }
1022
1023 switch (wrq->flags & IW_POWER_MODE) {
1024 case IW_POWER_ON: /* If not specified */
1025 case IW_POWER_MODE: /* If set all mask */
1026 case IW_POWER_ALL_R: /* If explicitely state all */
1027 conf->flags |= IEEE80211_CONF_PS;
1028 break;
1029 default: /* Otherwise we don't support it */
1030 return -EINVAL;
1031 }
1032
1033 return ieee80211_hw_config(local);
1034}
1035
1036static int ieee80211_ioctl_giwpower(struct net_device *dev,
1037 struct iw_request_info *info,
1038 union iwreq_data *wrqu,
1039 char *extra)
1040{
1041 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1042 struct ieee80211_conf *conf = &local->hw.conf;
1043
1044 wrqu->power.disabled = !(conf->flags & IEEE80211_CONF_PS);
1045
1046 return 0;
1047}
1048
Jiri Bencf0706e82007-05-05 11:45:53 -07001049static int ieee80211_ioctl_siwauth(struct net_device *dev,
1050 struct iw_request_info *info,
1051 struct iw_param *data, char *extra)
1052{
Jiri Bencf0706e82007-05-05 11:45:53 -07001053 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1054 int ret = 0;
1055
1056 switch (data->flags & IW_AUTH_INDEX) {
1057 case IW_AUTH_WPA_VERSION:
1058 case IW_AUTH_CIPHER_PAIRWISE:
1059 case IW_AUTH_CIPHER_GROUP:
1060 case IW_AUTH_WPA_ENABLED:
1061 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -07001062 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001063 break;
Johannes Bergb1357a82007-11-28 11:04:21 +01001064 case IW_AUTH_DROP_UNENCRYPTED:
1065 sdata->drop_unencrypted = !!data->value;
1066 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001067 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001068 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07001069 ret = -EINVAL;
1070 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001071 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001072 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001073 * Privacy invoked by wpa_supplicant, store the
1074 * value and allow associating to a protected
1075 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -07001076 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001077 if (data->value)
1078 sdata->u.sta.flags |=
1079 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001080 }
1081 break;
1082 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001083 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1084 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001085 sdata->u.sta.auth_algs = data->value;
1086 else
1087 ret = -EOPNOTSUPP;
1088 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001089 default:
1090 ret = -EOPNOTSUPP;
1091 break;
1092 }
1093 return ret;
1094}
1095
1096/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1097static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1098{
1099 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1100 struct iw_statistics *wstats = &local->wstats;
1101 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1102 struct sta_info *sta = NULL;
1103
Johannes Berg98dd6a52008-04-10 15:36:09 +02001104 rcu_read_lock();
1105
Johannes Berg51fb61e2007-12-19 01:31:27 +01001106 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1107 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001108 sta = sta_info_get(local, sdata->u.sta.bssid);
1109 if (!sta) {
1110 wstats->discard.fragment = 0;
1111 wstats->discard.misc = 0;
1112 wstats->qual.qual = 0;
1113 wstats->qual.level = 0;
1114 wstats->qual.noise = 0;
1115 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1116 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001117 wstats->qual.level = sta->last_signal;
1118 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001119 wstats->qual.noise = sta->last_noise;
1120 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001121 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001122
1123 rcu_read_unlock();
1124
Jiri Bencf0706e82007-05-05 11:45:53 -07001125 return wstats;
1126}
1127
1128static int ieee80211_ioctl_giwauth(struct net_device *dev,
1129 struct iw_request_info *info,
1130 struct iw_param *data, char *extra)
1131{
1132 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1133 int ret = 0;
1134
1135 switch (data->flags & IW_AUTH_INDEX) {
1136 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001137 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1138 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001139 data->value = sdata->u.sta.auth_algs;
1140 else
1141 ret = -EOPNOTSUPP;
1142 break;
1143 default:
1144 ret = -EOPNOTSUPP;
1145 break;
1146 }
1147 return ret;
1148}
1149
1150
1151static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1152 struct iw_request_info *info,
1153 struct iw_point *erq, char *extra)
1154{
1155 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1156 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001157 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001158
1159 switch (ext->alg) {
1160 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001161 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001162 break;
1163 case IW_ENCODE_ALG_WEP:
1164 alg = ALG_WEP;
1165 break;
1166 case IW_ENCODE_ALG_TKIP:
1167 alg = ALG_TKIP;
1168 break;
1169 case IW_ENCODE_ALG_CCMP:
1170 alg = ALG_CCMP;
1171 break;
1172 default:
1173 return -EOPNOTSUPP;
1174 }
1175
1176 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001177 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001178
1179 idx = erq->flags & IW_ENCODE_INDEX;
1180 if (idx < 1 || idx > 4) {
1181 idx = -1;
1182 if (!sdata->default_key)
1183 idx = 0;
1184 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1185 if (sdata->default_key == sdata->keys[i]) {
1186 idx = i;
1187 break;
1188 }
1189 }
1190 if (idx < 0)
1191 return -EINVAL;
1192 } else
1193 idx--;
1194
1195 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001196 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001197 ext->ext_flags &
1198 IW_ENCODE_EXT_SET_TX_KEY,
1199 ext->key, ext->key_len);
1200}
1201
1202
Jiri Bencf0706e82007-05-05 11:45:53 -07001203/* Structures to export the Wireless Handlers */
1204
1205static const iw_handler ieee80211_handler[] =
1206{
1207 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1208 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1209 (iw_handler) NULL, /* SIOCSIWNWID */
1210 (iw_handler) NULL, /* SIOCGIWNWID */
1211 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1212 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1213 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1214 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1215 (iw_handler) NULL, /* SIOCSIWSENS */
1216 (iw_handler) NULL, /* SIOCGIWSENS */
1217 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1218 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1219 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1220 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1221 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1222 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001223 (iw_handler) NULL, /* SIOCSIWSPY */
1224 (iw_handler) NULL, /* SIOCGIWSPY */
1225 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1226 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001227 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1228 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1229 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1230 (iw_handler) NULL, /* SIOCGIWAPLIST */
1231 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1232 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1233 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1234 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1235 (iw_handler) NULL, /* SIOCSIWNICKN */
1236 (iw_handler) NULL, /* SIOCGIWNICKN */
1237 (iw_handler) NULL, /* -- hole -- */
1238 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001239 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001240 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001241 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1242 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1243 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1244 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001245 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001246 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001247 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1248 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1249 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1250 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001251 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1252 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001253 (iw_handler) NULL, /* -- hole -- */
1254 (iw_handler) NULL, /* -- hole -- */
1255 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1256 (iw_handler) NULL, /* SIOCGIWGENIE */
1257 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1258 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1259 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1260 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1261 (iw_handler) NULL, /* SIOCSIWPMKSA */
1262 (iw_handler) NULL, /* -- hole -- */
1263};
1264
Jiri Bencf0706e82007-05-05 11:45:53 -07001265const struct iw_handler_def ieee80211_iw_handler_def =
1266{
1267 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001268 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001269 .get_wireless_stats = ieee80211_get_wireless_stats,
1270};