blob: b9eee3c903de1476270ee50e7912c76a9f8af32d [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
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120030static int ieee80211_set_encryption(struct ieee80211_sub_if_data *sdata, 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{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120035 struct ieee80211_local *local = sdata->local;
Johannes Bergd0709a62008-02-25 16:27:46 +010036 struct sta_info *sta;
Johannes Berg11a843b2007-08-28 17:01:55 -040037 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +020038 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070039
Volker Braun139c3a02007-09-14 11:10:25 -040040 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
41 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120042 sdata->dev->name, idx);
Volker Braun139c3a02007-09-14 11:10:25 -040043 return -EINVAL;
44 }
45
Johannes Berg628a1402007-09-26 17:53:17 +020046 if (remove) {
Johannes Berg3b967662008-04-08 17:56:52 +020047 rcu_read_lock();
48
49 err = 0;
50
Johannes Bergdb4d1162008-02-25 16:27:45 +010051 if (is_broadcast_ether_addr(sta_addr)) {
52 key = sdata->keys[idx];
53 } else {
54 sta = sta_info_get(local, sta_addr);
Johannes Berg3b967662008-04-08 17:56:52 +020055 if (!sta) {
56 err = -ENOENT;
57 goto out_unlock;
58 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010059 key = sta->key;
Jiri Bencf0706e82007-05-05 11:45:53 -070060 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010061
Johannes Bergd0709a62008-02-25 16:27:46 +010062 ieee80211_key_free(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +010063 } else {
64 key = ieee80211_key_alloc(alg, idx, key_len, _key);
65 if (!key)
66 return -ENOMEM;
67
Johannes Bergd0709a62008-02-25 16:27:46 +010068 sta = NULL;
Johannes Berg3b967662008-04-08 17:56:52 +020069 err = 0;
70
71 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +010072
Johannes Bergdb4d1162008-02-25 16:27:45 +010073 if (!is_broadcast_ether_addr(sta_addr)) {
74 set_tx_key = 0;
75 /*
76 * According to the standard, the key index of a
77 * pairwise key must be zero. However, some AP are
78 * broken when it comes to WEP key indices, so we
79 * work around this.
80 */
81 if (idx != 0 && alg != ALG_WEP) {
Johannes Bergd0709a62008-02-25 16:27:46 +010082 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020083 err = -EINVAL;
84 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010085 }
86
87 sta = sta_info_get(local, sta_addr);
88 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +010089 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020090 err = -ENOENT;
91 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010092 }
93 }
94
Emmanuel Grumbach23976ef2008-06-28 02:50:13 +030095 if (alg == ALG_WEP &&
96 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
97 ieee80211_key_free(key);
98 err = -EINVAL;
99 goto out_unlock;
100 }
101
Johannes Bergdb4d1162008-02-25 16:27:45 +0100102 ieee80211_key_link(key, sdata, sta);
103
104 if (set_tx_key || (!sta && !sdata->default_key && key))
105 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700106 }
107
Johannes Berg3b967662008-04-08 17:56:52 +0200108 out_unlock:
109 rcu_read_unlock();
110
111 return err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700112}
113
114static int ieee80211_ioctl_siwgenie(struct net_device *dev,
115 struct iw_request_info *info,
116 struct iw_point *data, char *extra)
117{
118 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -0700119
120 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200121
122 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
123 return -EOPNOTSUPP;
124
Johannes Berg05c914f2008-09-11 00:01:58 +0200125 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
126 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200127 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700128 if (ret)
129 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400130 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200131 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700132 return 0;
133 }
134
Jiri Bencf0706e82007-05-05 11:45:53 -0700135 return -EOPNOTSUPP;
136}
137
Jiri Bencf0706e82007-05-05 11:45:53 -0700138static int ieee80211_ioctl_giwrange(struct net_device *dev,
139 struct iw_request_info *info,
140 struct iw_point *data, char *extra)
141{
142 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
143 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100144 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200145 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700146
147 data->length = sizeof(struct iw_range);
148 memset(range, 0, sizeof(struct iw_range));
149
150 range->we_version_compiled = WIRELESS_EXT;
151 range->we_version_source = 21;
152 range->retry_capa = IW_RETRY_LIMIT;
153 range->retry_flags = IW_RETRY_LIMIT;
154 range->min_retry = 0;
155 range->max_retry = 255;
156 range->min_rts = 0;
157 range->max_rts = 2347;
158 range->min_frag = 256;
159 range->max_frag = 2346;
160
161 range->encoding_size[0] = 5;
162 range->encoding_size[1] = 13;
163 range->num_encoding_sizes = 2;
164 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
165
Bruno Randolf566bfe52008-05-08 19:15:40 +0200166 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
167 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
168 range->max_qual.level = local->hw.max_signal;
169 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
170 range->max_qual.level = -110;
171 else
172 range->max_qual.level = 0;
173
174 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
175 range->max_qual.noise = -110;
176 else
177 range->max_qual.noise = 0;
178
179 range->max_qual.qual = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700180 range->max_qual.updated = local->wstats_flags;
181
Bruno Randolf566bfe52008-05-08 19:15:40 +0200182 range->avg_qual.qual = 50;
183 /* not always true but better than nothing */
184 range->avg_qual.level = range->max_qual.level / 2;
185 range->avg_qual.noise = range->max_qual.noise / 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700186 range->avg_qual.updated = local->wstats_flags;
187
188 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
189 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
190
Hong Liu333af2f2007-07-10 19:32:08 +0200191
Johannes Berg8318d782008-01-24 19:38:38 +0100192 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
193 int i;
194 struct ieee80211_supported_band *sband;
195
196 sband = local->hw.wiphy->bands[band];
197
198 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200199 continue;
200
Johannes Berg8318d782008-01-24 19:38:38 +0100201 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
202 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200203
Johannes Berg8318d782008-01-24 19:38:38 +0100204 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
205 range->freq[c].i =
206 ieee80211_frequency_to_channel(
207 chan->center_freq);
208 range->freq[c].m = chan->center_freq;
209 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200210 c++;
211 }
Hong Liu333af2f2007-07-10 19:32:08 +0200212 }
213 }
214 range->num_channels = c;
215 range->num_frequency = c;
216
Jiri Bencf0706e82007-05-05 11:45:53 -0700217 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700218 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
219 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
220
Dan Williams374fdfb2007-12-12 10:25:07 -0500221 range->scan_capa |= IW_SCAN_CAPA_ESSID;
222
Jiri Bencf0706e82007-05-05 11:45:53 -0700223 return 0;
224}
225
226
Jiri Bencf0706e82007-05-05 11:45:53 -0700227static int ieee80211_ioctl_siwmode(struct net_device *dev,
228 struct iw_request_info *info,
229 __u32 *mode, char *extra)
230{
231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Abhijeet Kolekar3dd3b792008-11-20 10:20:31 -0800232 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700233 int type;
234
Johannes Berg05c914f2008-09-11 00:01:58 +0200235 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700236 return -EOPNOTSUPP;
237
238 switch (*mode) {
239 case IW_MODE_INFRA:
Johannes Berg05c914f2008-09-11 00:01:58 +0200240 type = NL80211_IFTYPE_STATION;
Jiri Bencf0706e82007-05-05 11:45:53 -0700241 break;
242 case IW_MODE_ADHOC:
Abhijeet Kolekar3dd3b792008-11-20 10:20:31 -0800243 /* Setting ad-hoc mode on non ibss channel is not
244 * supported.
245 */
246 if (local->oper_channel &&
247 (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS))
248 return -EOPNOTSUPP;
249
Johannes Berg05c914f2008-09-11 00:01:58 +0200250 type = NL80211_IFTYPE_ADHOC;
Jiri Bencf0706e82007-05-05 11:45:53 -0700251 break;
Johannes Bergb4540482008-04-14 15:37:03 +0200252 case IW_MODE_REPEAT:
Johannes Berg05c914f2008-09-11 00:01:58 +0200253 type = NL80211_IFTYPE_WDS;
Johannes Bergb4540482008-04-14 15:37:03 +0200254 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700255 case IW_MODE_MONITOR:
Johannes Berg05c914f2008-09-11 00:01:58 +0200256 type = NL80211_IFTYPE_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -0700257 break;
258 default:
259 return -EINVAL;
260 }
261
Johannes Bergf3947e22008-07-09 14:40:36 +0200262 return ieee80211_if_change_type(sdata, type);
Jiri Bencf0706e82007-05-05 11:45:53 -0700263}
264
265
266static int ieee80211_ioctl_giwmode(struct net_device *dev,
267 struct iw_request_info *info,
268 __u32 *mode, char *extra)
269{
270 struct ieee80211_sub_if_data *sdata;
271
272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100273 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200274 case NL80211_IFTYPE_AP:
Jiri Bencf0706e82007-05-05 11:45:53 -0700275 *mode = IW_MODE_MASTER;
276 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200277 case NL80211_IFTYPE_STATION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700278 *mode = IW_MODE_INFRA;
279 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200280 case NL80211_IFTYPE_ADHOC:
Jiri Bencf0706e82007-05-05 11:45:53 -0700281 *mode = IW_MODE_ADHOC;
282 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200283 case NL80211_IFTYPE_MONITOR:
Jiri Bencf0706e82007-05-05 11:45:53 -0700284 *mode = IW_MODE_MONITOR;
285 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200286 case NL80211_IFTYPE_WDS:
Jiri Bencf0706e82007-05-05 11:45:53 -0700287 *mode = IW_MODE_REPEAT;
288 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200289 case NL80211_IFTYPE_AP_VLAN:
Jiri Bencf0706e82007-05-05 11:45:53 -0700290 *mode = IW_MODE_SECOND; /* FIXME */
291 break;
292 default:
293 *mode = IW_MODE_AUTO;
294 break;
295 }
296 return 0;
297}
298
Jiri Bencf0706e82007-05-05 11:45:53 -0700299static int ieee80211_ioctl_siwfreq(struct net_device *dev,
300 struct iw_request_info *info,
301 struct iw_freq *freq, char *extra)
302{
Jiri Bencf0706e82007-05-05 11:45:53 -0700303 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
304
Johannes Berg05c914f2008-09-11 00:01:58 +0200305 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400306 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700307
308 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
309 if (freq->e == 0) {
310 if (freq->m < 0) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200311 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400312 sdata->u.sta.flags |=
313 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700314 return 0;
315 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200316 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100317 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700318 } else {
319 int i, div = 1000000;
320 for (i = 0; i < freq->e; i++)
321 div /= 10;
322 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200323 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700324 else
325 return -EINVAL;
326 }
327}
328
329
330static int ieee80211_ioctl_giwfreq(struct net_device *dev,
331 struct iw_request_info *info,
332 struct iw_freq *freq, char *extra)
333{
334 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
335
Johannes Berg8318d782008-01-24 19:38:38 +0100336 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700337 freq->e = 6;
338
339 return 0;
340}
341
342
343static int ieee80211_ioctl_siwessid(struct net_device *dev,
344 struct iw_request_info *info,
345 struct iw_point *data, char *ssid)
346{
Jiri Bencf0706e82007-05-05 11:45:53 -0700347 struct ieee80211_sub_if_data *sdata;
348 size_t len = data->length;
349
350 /* iwconfig uses nul termination in SSID.. */
351 if (len > 0 && ssid[len - 1] == '\0')
352 len--;
353
354 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200355 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
356 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700357 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200358 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700359 if (len > IEEE80211_MAX_SSID_LEN)
360 return -EINVAL;
361 memcpy(sdata->u.sta.ssid, ssid, len);
362 sdata->u.sta.ssid_len = len;
363 return 0;
364 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400365 if (data->flags)
366 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
367 else
368 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200369 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700370 if (ret)
371 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200372 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700373 return 0;
374 }
375
Jiri Bencf0706e82007-05-05 11:45:53 -0700376 return -EOPNOTSUPP;
377}
378
379
380static int ieee80211_ioctl_giwessid(struct net_device *dev,
381 struct iw_request_info *info,
382 struct iw_point *data, char *ssid)
383{
384 size_t len;
385
386 struct ieee80211_sub_if_data *sdata;
387 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200388 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
389 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200390 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700391 if (res == 0) {
392 data->length = len;
393 data->flags = 1;
394 } else
395 data->flags = 0;
396 return res;
397 }
398
Jiri Bencf0706e82007-05-05 11:45:53 -0700399 return -EOPNOTSUPP;
400}
401
402
403static int ieee80211_ioctl_siwap(struct net_device *dev,
404 struct iw_request_info *info,
405 struct sockaddr *ap_addr, char *extra)
406{
Jiri Bencf0706e82007-05-05 11:45:53 -0700407 struct ieee80211_sub_if_data *sdata;
408
409 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200410 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
411 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700412 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200413 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700414 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
415 ETH_ALEN);
416 return 0;
417 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400418 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
419 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
420 IEEE80211_STA_AUTO_CHANNEL_SEL;
421 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
422 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700423 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400424 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200425 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700426 if (ret)
427 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200428 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700429 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200430 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100431 /*
432 * If it is necessary to update the WDS peer address
433 * while the interface is running, then we need to do
434 * more work here, namely if it is running we need to
435 * add a new and remove the old STA entry, this is
436 * normally handled by _open() and _stop().
437 */
438 if (netif_running(dev))
439 return -EBUSY;
440
441 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
442 ETH_ALEN);
443
444 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700445 }
446
447 return -EOPNOTSUPP;
448}
449
450
451static int ieee80211_ioctl_giwap(struct net_device *dev,
452 struct iw_request_info *info,
453 struct sockaddr *ap_addr, char *extra)
454{
455 struct ieee80211_sub_if_data *sdata;
456
457 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200458 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
459 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300460 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
461 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700462 ap_addr->sa_family = ARPHRD_ETHER;
463 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
464 return 0;
465 } else {
466 memset(&ap_addr->sa_data, 0, ETH_ALEN);
467 return 0;
468 }
Johannes Berg05c914f2008-09-11 00:01:58 +0200469 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700470 ap_addr->sa_family = ARPHRD_ETHER;
471 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
472 return 0;
473 }
474
475 return -EOPNOTSUPP;
476}
477
478
479static int ieee80211_ioctl_siwscan(struct net_device *dev,
480 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400481 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700482{
Jiri Bencf0706e82007-05-05 11:45:53 -0700483 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400484 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700485 u8 *ssid = NULL;
486 size_t ssid_len = 0;
487
488 if (!netif_running(dev))
489 return -ENETDOWN;
490
Johannes Berg05c914f2008-09-11 00:01:58 +0200491 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
492 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
493 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
494 sdata->vif.type != NL80211_IFTYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700495 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700496
497 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400498 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
499 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
500 req = (struct iw_scan_req *)extra;
501 ssid = req->essid;
502 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700503 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200504
Johannes Bergc2b13452008-09-11 00:01:55 +0200505 return ieee80211_request_scan(sdata, ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700506}
507
508
509static int ieee80211_ioctl_giwscan(struct net_device *dev,
510 struct iw_request_info *info,
511 struct iw_point *data, char *extra)
512{
513 int res;
514 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200515 struct ieee80211_sub_if_data *sdata;
516
517 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Zhu Yiece8edd2007-11-22 10:53:21 +0800518
Johannes Bergc2b13452008-09-11 00:01:55 +0200519 if (local->sw_scanning || local->hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700520 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800521
Johannes Bergc2b13452008-09-11 00:01:55 +0200522 res = ieee80211_scan_results(local, info, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700523 if (res >= 0) {
524 data->length = res;
525 return 0;
526 }
527 data->length = 0;
528 return res;
529}
530
531
Larry Finger1fd5e582007-07-10 19:32:10 +0200532static int ieee80211_ioctl_siwrate(struct net_device *dev,
533 struct iw_request_info *info,
534 struct iw_param *rate, char *extra)
535{
536 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100537 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200538 u32 target_rate = rate->value / 100000;
539 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100540 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200541
542 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100543
544 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
545
Larry Finger1fd5e582007-07-10 19:32:10 +0200546 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
547 * target_rate = X, rate->fixed = 1 means only rate X
548 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200549 sdata->max_ratectrl_rateidx = -1;
550 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200551 if (rate->value < 0)
552 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100553
554 for (i=0; i< sband->n_bitrates; i++) {
555 struct ieee80211_rate *brate = &sband->bitrates[i];
556 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200557
Larry Finger1fd5e582007-07-10 19:32:10 +0200558 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200559 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200560 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200561 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100562 err = 0;
563 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200564 }
565 }
Johannes Berg8318d782008-01-24 19:38:38 +0100566 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200567}
568
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700569static int ieee80211_ioctl_giwrate(struct net_device *dev,
570 struct iw_request_info *info,
571 struct iw_param *rate, char *extra)
572{
573 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
574 struct sta_info *sta;
575 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100576 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700577
578 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100579
Johannes Berg05c914f2008-09-11 00:01:58 +0200580 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700581 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100582
583 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
584
Johannes Berg380a9422008-04-04 23:40:35 +0200585 rcu_read_lock();
586
587 sta = sta_info_get(local, sdata->u.sta.bssid);
588
Johannes Berge6a98542008-10-21 12:40:02 +0200589 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
590 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700591 else
592 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200593
594 rcu_read_unlock();
595
596 if (!sta)
597 return -ENODEV;
598
Johannes Berg8318d782008-01-24 19:38:38 +0100599 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100600
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700601 return 0;
602}
603
Michael Buesch61609bc2007-09-20 22:06:39 +0200604static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
605 struct iw_request_info *info,
606 union iwreq_data *data, char *extra)
607{
608 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700609 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200610 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100611 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200612
613 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
614 return -EINVAL;
615 if (data->txpower.flags & IW_TXPOW_RANGE)
616 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700617 if (!chan)
618 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200619
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700620 if (data->txpower.fixed)
621 new_power_level = min(data->txpower.value, chan->max_power);
622 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100623 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200624
625 if (local->hw.conf.power_level != new_power_level) {
626 local->hw.conf.power_level = new_power_level;
Johannes Berge8975582008-10-09 12:18:51 +0200627 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Michael Buesch61609bc2007-09-20 22:06:39 +0200628 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200629
Michael Buesch61609bc2007-09-20 22:06:39 +0200630 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
631 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200632 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100633 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200634 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200635
Johannes Berge8975582008-10-09 12:18:51 +0200636 if (reconf_flags)
637 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200638
639 return 0;
640}
641
Larry Fingerfe6aa302007-08-10 11:23:20 -0500642static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
643 struct iw_request_info *info,
644 union iwreq_data *data, char *extra)
645{
646 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
647
648 data->txpower.fixed = 1;
649 data->txpower.disabled = !(local->hw.conf.radio_enabled);
650 data->txpower.value = local->hw.conf.power_level;
651 data->txpower.flags = IW_TXPOW_DBM;
652
653 return 0;
654}
655
Jiri Bencf0706e82007-05-05 11:45:53 -0700656static int ieee80211_ioctl_siwrts(struct net_device *dev,
657 struct iw_request_info *info,
658 struct iw_param *rts, char *extra)
659{
660 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
661
662 if (rts->disabled)
663 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300664 else if (!rts->fixed)
665 /* if the rts value is not fixed, then take default */
666 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700667 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
668 return -EINVAL;
669 else
670 local->rts_threshold = rts->value;
671
672 /* If the wlan card performs RTS/CTS in hardware/firmware,
673 * configure it here */
674
675 if (local->ops->set_rts_threshold)
676 local->ops->set_rts_threshold(local_to_hw(local),
677 local->rts_threshold);
678
679 return 0;
680}
681
682static int ieee80211_ioctl_giwrts(struct net_device *dev,
683 struct iw_request_info *info,
684 struct iw_param *rts, char *extra)
685{
686 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
687
688 rts->value = local->rts_threshold;
689 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
690 rts->fixed = 1;
691
692 return 0;
693}
694
695
696static int ieee80211_ioctl_siwfrag(struct net_device *dev,
697 struct iw_request_info *info,
698 struct iw_param *frag, char *extra)
699{
700 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
701
702 if (frag->disabled)
703 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300704 else if (!frag->fixed)
705 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700706 else if (frag->value < 256 ||
707 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
708 return -EINVAL;
709 else {
710 /* Fragment length must be even, so strip LSB. */
711 local->fragmentation_threshold = frag->value & ~0x1;
712 }
713
714 /* If the wlan card performs fragmentation in hardware/firmware,
715 * configure it here */
716
717 if (local->ops->set_frag_threshold)
Johannes Berg4233df62008-10-13 13:35:05 +0200718 return local->ops->set_frag_threshold(
Jiri Bencf0706e82007-05-05 11:45:53 -0700719 local_to_hw(local),
720 local->fragmentation_threshold);
721
722 return 0;
723}
724
725static int ieee80211_ioctl_giwfrag(struct net_device *dev,
726 struct iw_request_info *info,
727 struct iw_param *frag, char *extra)
728{
729 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
730
731 frag->value = local->fragmentation_threshold;
732 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
733 frag->fixed = 1;
734
735 return 0;
736}
737
738
739static int ieee80211_ioctl_siwretry(struct net_device *dev,
740 struct iw_request_info *info,
741 struct iw_param *retry, char *extra)
742{
743 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
744
745 if (retry->disabled ||
746 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
747 return -EINVAL;
748
Johannes Berg9124b072008-10-14 19:17:54 +0200749 if (retry->flags & IW_RETRY_MAX) {
750 local->hw.conf.long_frame_max_tx_count = retry->value;
751 } else if (retry->flags & IW_RETRY_MIN) {
752 local->hw.conf.short_frame_max_tx_count = retry->value;
753 } else {
754 local->hw.conf.long_frame_max_tx_count = retry->value;
755 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700756 }
757
Johannes Berg9124b072008-10-14 19:17:54 +0200758 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700759
760 return 0;
761}
762
763
764static int ieee80211_ioctl_giwretry(struct net_device *dev,
765 struct iw_request_info *info,
766 struct iw_param *retry, char *extra)
767{
768 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
769
770 retry->disabled = 0;
771 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
772 /* first return min value, iwconfig will ask max value
773 * later if needed */
774 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200775 retry->value = local->hw.conf.short_frame_max_tx_count;
776 if (local->hw.conf.long_frame_max_tx_count !=
777 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700778 retry->flags |= IW_RETRY_MIN;
779 return 0;
780 }
781 if (retry->flags & IW_RETRY_MAX) {
782 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200783 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700784 }
785
786 return 0;
787}
788
Jiri Bencf0706e82007-05-05 11:45:53 -0700789static int ieee80211_ioctl_siwmlme(struct net_device *dev,
790 struct iw_request_info *info,
791 struct iw_point *data, char *extra)
792{
793 struct ieee80211_sub_if_data *sdata;
794 struct iw_mlme *mlme = (struct iw_mlme *) extra;
795
796 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200797 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
798 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700799 return -EINVAL;
800
801 switch (mlme->cmd) {
802 case IW_MLME_DEAUTH:
803 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200804 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700805 case IW_MLME_DISASSOC:
806 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200807 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700808 default:
809 return -EOPNOTSUPP;
810 }
811}
812
813
814static int ieee80211_ioctl_siwencode(struct net_device *dev,
815 struct iw_request_info *info,
816 struct iw_point *erq, char *keybuf)
817{
818 struct ieee80211_sub_if_data *sdata;
819 int idx, i, alg = ALG_WEP;
820 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200821 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700822
823 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
824
825 idx = erq->flags & IW_ENCODE_INDEX;
826 if (idx == 0) {
827 if (sdata->default_key)
828 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
829 if (sdata->default_key == sdata->keys[i]) {
830 idx = i;
831 break;
832 }
833 }
834 } else if (idx < 1 || idx > 4)
835 return -EINVAL;
836 else
837 idx--;
838
839 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200840 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700841 else if (erq->length == 0) {
842 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400843 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700844 return 0;
845 }
846
847 return ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200848 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200849 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700850 !sdata->default_key,
851 keybuf, erq->length);
852}
853
854
855static int ieee80211_ioctl_giwencode(struct net_device *dev,
856 struct iw_request_info *info,
857 struct iw_point *erq, char *key)
858{
859 struct ieee80211_sub_if_data *sdata;
860 int idx, i;
861
862 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
863
864 idx = erq->flags & IW_ENCODE_INDEX;
865 if (idx < 1 || idx > 4) {
866 idx = -1;
867 if (!sdata->default_key)
868 idx = 0;
869 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
870 if (sdata->default_key == sdata->keys[i]) {
871 idx = i;
872 break;
873 }
874 }
875 if (idx < 0)
876 return -EINVAL;
877 } else
878 idx--;
879
880 erq->flags = idx + 1;
881
882 if (!sdata->keys[idx]) {
883 erq->length = 0;
884 erq->flags |= IW_ENCODE_DISABLED;
885 return 0;
886 }
887
Johannes Berg8f20fc22007-08-28 17:01:54 -0400888 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400889 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400890 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700891 erq->flags |= IW_ENCODE_ENABLED;
892
Johannes Berg05c914f2008-09-11 00:01:58 +0200893 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300894 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
895 switch (ifsta->auth_alg) {
896 case WLAN_AUTH_OPEN:
897 case WLAN_AUTH_LEAP:
898 erq->flags |= IW_ENCODE_OPEN;
899 break;
900 case WLAN_AUTH_SHARED_KEY:
901 erq->flags |= IW_ENCODE_RESTRICTED;
902 break;
903 }
904 }
905
Jiri Bencf0706e82007-05-05 11:45:53 -0700906 return 0;
907}
908
Samuel Ortiz49292d52008-07-04 10:49:31 +0200909static int ieee80211_ioctl_siwpower(struct net_device *dev,
910 struct iw_request_info *info,
911 struct iw_param *wrq,
912 char *extra)
913{
914 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
915 struct ieee80211_conf *conf = &local->hw.conf;
916
917 if (wrq->disabled) {
918 conf->flags &= ~IEEE80211_CONF_PS;
Johannes Berge8975582008-10-09 12:18:51 +0200919 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200920 }
921
922 switch (wrq->flags & IW_POWER_MODE) {
923 case IW_POWER_ON: /* If not specified */
924 case IW_POWER_MODE: /* If set all mask */
925 case IW_POWER_ALL_R: /* If explicitely state all */
926 conf->flags |= IEEE80211_CONF_PS;
927 break;
928 default: /* Otherwise we don't support it */
929 return -EINVAL;
930 }
931
Johannes Berge8975582008-10-09 12:18:51 +0200932 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200933}
934
935static int ieee80211_ioctl_giwpower(struct net_device *dev,
936 struct iw_request_info *info,
937 union iwreq_data *wrqu,
938 char *extra)
939{
940 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
941 struct ieee80211_conf *conf = &local->hw.conf;
942
943 wrqu->power.disabled = !(conf->flags & IEEE80211_CONF_PS);
944
945 return 0;
946}
947
Jiri Bencf0706e82007-05-05 11:45:53 -0700948static int ieee80211_ioctl_siwauth(struct net_device *dev,
949 struct iw_request_info *info,
950 struct iw_param *data, char *extra)
951{
Jiri Bencf0706e82007-05-05 11:45:53 -0700952 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
953 int ret = 0;
954
955 switch (data->flags & IW_AUTH_INDEX) {
956 case IW_AUTH_WPA_VERSION:
957 case IW_AUTH_CIPHER_PAIRWISE:
958 case IW_AUTH_CIPHER_GROUP:
959 case IW_AUTH_WPA_ENABLED:
960 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700961 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000962 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100963 case IW_AUTH_DROP_UNENCRYPTED:
964 sdata->drop_unencrypted = !!data->value;
965 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000966 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200967 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700968 ret = -EINVAL;
969 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000970 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700971 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000972 * Privacy invoked by wpa_supplicant, store the
973 * value and allow associating to a protected
974 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700975 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000976 if (data->value)
977 sdata->u.sta.flags |=
978 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700979 }
980 break;
981 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +0200982 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
983 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700984 sdata->u.sta.auth_algs = data->value;
985 else
986 ret = -EOPNOTSUPP;
987 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700988 default:
989 ret = -EOPNOTSUPP;
990 break;
991 }
992 return ret;
993}
994
995/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
996static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
997{
998 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
999 struct iw_statistics *wstats = &local->wstats;
1000 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1001 struct sta_info *sta = NULL;
1002
Johannes Berg98dd6a52008-04-10 15:36:09 +02001003 rcu_read_lock();
1004
Johannes Berg05c914f2008-09-11 00:01:58 +02001005 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1006 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001007 sta = sta_info_get(local, sdata->u.sta.bssid);
1008 if (!sta) {
1009 wstats->discard.fragment = 0;
1010 wstats->discard.misc = 0;
1011 wstats->qual.qual = 0;
1012 wstats->qual.level = 0;
1013 wstats->qual.noise = 0;
1014 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1015 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001016 wstats->qual.level = sta->last_signal;
1017 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001018 wstats->qual.noise = sta->last_noise;
1019 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001020 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001021
1022 rcu_read_unlock();
1023
Jiri Bencf0706e82007-05-05 11:45:53 -07001024 return wstats;
1025}
1026
1027static int ieee80211_ioctl_giwauth(struct net_device *dev,
1028 struct iw_request_info *info,
1029 struct iw_param *data, char *extra)
1030{
1031 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1032 int ret = 0;
1033
1034 switch (data->flags & IW_AUTH_INDEX) {
1035 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +02001036 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1037 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001038 data->value = sdata->u.sta.auth_algs;
1039 else
1040 ret = -EOPNOTSUPP;
1041 break;
1042 default:
1043 ret = -EOPNOTSUPP;
1044 break;
1045 }
1046 return ret;
1047}
1048
1049
1050static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1051 struct iw_request_info *info,
1052 struct iw_point *erq, char *extra)
1053{
1054 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1055 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001056 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001057
1058 switch (ext->alg) {
1059 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001060 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001061 break;
1062 case IW_ENCODE_ALG_WEP:
1063 alg = ALG_WEP;
1064 break;
1065 case IW_ENCODE_ALG_TKIP:
1066 alg = ALG_TKIP;
1067 break;
1068 case IW_ENCODE_ALG_CCMP:
1069 alg = ALG_CCMP;
1070 break;
1071 default:
1072 return -EOPNOTSUPP;
1073 }
1074
1075 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001076 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001077
1078 idx = erq->flags & IW_ENCODE_INDEX;
1079 if (idx < 1 || idx > 4) {
1080 idx = -1;
1081 if (!sdata->default_key)
1082 idx = 0;
1083 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1084 if (sdata->default_key == sdata->keys[i]) {
1085 idx = i;
1086 break;
1087 }
1088 }
1089 if (idx < 0)
1090 return -EINVAL;
1091 } else
1092 idx--;
1093
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001094 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001095 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001096 ext->ext_flags &
1097 IW_ENCODE_EXT_SET_TX_KEY,
1098 ext->key, ext->key_len);
1099}
1100
1101
Jiri Bencf0706e82007-05-05 11:45:53 -07001102/* Structures to export the Wireless Handlers */
1103
1104static const iw_handler ieee80211_handler[] =
1105{
1106 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001107 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001108 (iw_handler) NULL, /* SIOCSIWNWID */
1109 (iw_handler) NULL, /* SIOCGIWNWID */
1110 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1111 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1112 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1113 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1114 (iw_handler) NULL, /* SIOCSIWSENS */
1115 (iw_handler) NULL, /* SIOCGIWSENS */
1116 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1117 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1118 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1119 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1120 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1121 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001122 (iw_handler) NULL, /* SIOCSIWSPY */
1123 (iw_handler) NULL, /* SIOCGIWSPY */
1124 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1125 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001126 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1127 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1128 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1129 (iw_handler) NULL, /* SIOCGIWAPLIST */
1130 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1131 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1132 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1133 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1134 (iw_handler) NULL, /* SIOCSIWNICKN */
1135 (iw_handler) NULL, /* SIOCGIWNICKN */
1136 (iw_handler) NULL, /* -- hole -- */
1137 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001138 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001139 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001140 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1141 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1142 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1143 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001144 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001145 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001146 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1147 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1148 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1149 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001150 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1151 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001152 (iw_handler) NULL, /* -- hole -- */
1153 (iw_handler) NULL, /* -- hole -- */
1154 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1155 (iw_handler) NULL, /* SIOCGIWGENIE */
1156 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1157 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1158 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1159 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1160 (iw_handler) NULL, /* SIOCSIWPMKSA */
1161 (iw_handler) NULL, /* -- hole -- */
1162};
1163
Jiri Bencf0706e82007-05-05 11:45:53 -07001164const struct iw_handler_def ieee80211_iw_handler_def =
1165{
1166 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001167 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001168 .get_wireless_stats = ieee80211_get_wireless_stats,
1169};