blob: b3ce28d35611f9233ca75bce1969efd3ab6c7b45 [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_giwname(struct net_device *dev,
139 struct iw_request_info *info,
140 char *name, char *extra)
141{
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300142 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
143 struct ieee80211_supported_band *sband;
144 u8 is_ht = 0, is_a = 0, is_b = 0, is_g = 0;
145
146
147 sband = local->hw.wiphy->bands[IEEE80211_BAND_5GHZ];
148 if (sband) {
149 is_a = 1;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200150 is_ht |= sband->ht_cap.ht_supported;
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300151 }
152
153 sband = local->hw.wiphy->bands[IEEE80211_BAND_2GHZ];
154 if (sband) {
155 int i;
156 /* Check for mandatory rates */
157 for (i = 0; i < sband->n_bitrates; i++) {
158 if (sband->bitrates[i].bitrate == 10)
159 is_b = 1;
160 if (sband->bitrates[i].bitrate == 60)
161 is_g = 1;
162 }
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200163 is_ht |= sband->ht_cap.ht_supported;
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300164 }
165
Johannes Berg8318d782008-01-24 19:38:38 +0100166 strcpy(name, "IEEE 802.11");
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300167 if (is_a)
168 strcat(name, "a");
169 if (is_b)
170 strcat(name, "b");
171 if (is_g)
172 strcat(name, "g");
173 if (is_ht)
174 strcat(name, "n");
Jiri Bencf0706e82007-05-05 11:45:53 -0700175
176 return 0;
177}
178
179
180static int ieee80211_ioctl_giwrange(struct net_device *dev,
181 struct iw_request_info *info,
182 struct iw_point *data, char *extra)
183{
184 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
185 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100186 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200187 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700188
189 data->length = sizeof(struct iw_range);
190 memset(range, 0, sizeof(struct iw_range));
191
192 range->we_version_compiled = WIRELESS_EXT;
193 range->we_version_source = 21;
194 range->retry_capa = IW_RETRY_LIMIT;
195 range->retry_flags = IW_RETRY_LIMIT;
196 range->min_retry = 0;
197 range->max_retry = 255;
198 range->min_rts = 0;
199 range->max_rts = 2347;
200 range->min_frag = 256;
201 range->max_frag = 2346;
202
203 range->encoding_size[0] = 5;
204 range->encoding_size[1] = 13;
205 range->num_encoding_sizes = 2;
206 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
207
Bruno Randolf566bfe52008-05-08 19:15:40 +0200208 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
209 local->hw.flags & IEEE80211_HW_SIGNAL_DB)
210 range->max_qual.level = local->hw.max_signal;
211 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
212 range->max_qual.level = -110;
213 else
214 range->max_qual.level = 0;
215
216 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
217 range->max_qual.noise = -110;
218 else
219 range->max_qual.noise = 0;
220
221 range->max_qual.qual = 100;
Jiri Bencf0706e82007-05-05 11:45:53 -0700222 range->max_qual.updated = local->wstats_flags;
223
Bruno Randolf566bfe52008-05-08 19:15:40 +0200224 range->avg_qual.qual = 50;
225 /* not always true but better than nothing */
226 range->avg_qual.level = range->max_qual.level / 2;
227 range->avg_qual.noise = range->max_qual.noise / 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700228 range->avg_qual.updated = local->wstats_flags;
229
230 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
231 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
232
Hong Liu333af2f2007-07-10 19:32:08 +0200233
Johannes Berg8318d782008-01-24 19:38:38 +0100234 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
235 int i;
236 struct ieee80211_supported_band *sband;
237
238 sband = local->hw.wiphy->bands[band];
239
240 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200241 continue;
242
Johannes Berg8318d782008-01-24 19:38:38 +0100243 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
244 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200245
Johannes Berg8318d782008-01-24 19:38:38 +0100246 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
247 range->freq[c].i =
248 ieee80211_frequency_to_channel(
249 chan->center_freq);
250 range->freq[c].m = chan->center_freq;
251 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200252 c++;
253 }
Hong Liu333af2f2007-07-10 19:32:08 +0200254 }
255 }
256 range->num_channels = c;
257 range->num_frequency = c;
258
Jiri Bencf0706e82007-05-05 11:45:53 -0700259 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700260 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
261 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
262
Dan Williams374fdfb2007-12-12 10:25:07 -0500263 range->scan_capa |= IW_SCAN_CAPA_ESSID;
264
Jiri Bencf0706e82007-05-05 11:45:53 -0700265 return 0;
266}
267
268
Jiri Bencf0706e82007-05-05 11:45:53 -0700269static int ieee80211_ioctl_siwmode(struct net_device *dev,
270 struct iw_request_info *info,
271 __u32 *mode, char *extra)
272{
273 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Abhijeet Kolekar3dd3b792008-11-20 10:20:31 -0800274 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700275 int type;
276
Johannes Berg05c914f2008-09-11 00:01:58 +0200277 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700278 return -EOPNOTSUPP;
279
280 switch (*mode) {
281 case IW_MODE_INFRA:
Johannes Berg05c914f2008-09-11 00:01:58 +0200282 type = NL80211_IFTYPE_STATION;
Jiri Bencf0706e82007-05-05 11:45:53 -0700283 break;
284 case IW_MODE_ADHOC:
Abhijeet Kolekar3dd3b792008-11-20 10:20:31 -0800285 /* Setting ad-hoc mode on non ibss channel is not
286 * supported.
287 */
288 if (local->oper_channel &&
289 (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS))
290 return -EOPNOTSUPP;
291
Johannes Berg05c914f2008-09-11 00:01:58 +0200292 type = NL80211_IFTYPE_ADHOC;
Jiri Bencf0706e82007-05-05 11:45:53 -0700293 break;
Johannes Bergb4540482008-04-14 15:37:03 +0200294 case IW_MODE_REPEAT:
Johannes Berg05c914f2008-09-11 00:01:58 +0200295 type = NL80211_IFTYPE_WDS;
Johannes Bergb4540482008-04-14 15:37:03 +0200296 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700297 case IW_MODE_MONITOR:
Johannes Berg05c914f2008-09-11 00:01:58 +0200298 type = NL80211_IFTYPE_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -0700299 break;
300 default:
301 return -EINVAL;
302 }
303
Johannes Bergf3947e22008-07-09 14:40:36 +0200304 return ieee80211_if_change_type(sdata, type);
Jiri Bencf0706e82007-05-05 11:45:53 -0700305}
306
307
308static int ieee80211_ioctl_giwmode(struct net_device *dev,
309 struct iw_request_info *info,
310 __u32 *mode, char *extra)
311{
312 struct ieee80211_sub_if_data *sdata;
313
314 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100315 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200316 case NL80211_IFTYPE_AP:
Jiri Bencf0706e82007-05-05 11:45:53 -0700317 *mode = IW_MODE_MASTER;
318 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200319 case NL80211_IFTYPE_STATION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700320 *mode = IW_MODE_INFRA;
321 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200322 case NL80211_IFTYPE_ADHOC:
Jiri Bencf0706e82007-05-05 11:45:53 -0700323 *mode = IW_MODE_ADHOC;
324 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200325 case NL80211_IFTYPE_MONITOR:
Jiri Bencf0706e82007-05-05 11:45:53 -0700326 *mode = IW_MODE_MONITOR;
327 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200328 case NL80211_IFTYPE_WDS:
Jiri Bencf0706e82007-05-05 11:45:53 -0700329 *mode = IW_MODE_REPEAT;
330 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200331 case NL80211_IFTYPE_AP_VLAN:
Jiri Bencf0706e82007-05-05 11:45:53 -0700332 *mode = IW_MODE_SECOND; /* FIXME */
333 break;
334 default:
335 *mode = IW_MODE_AUTO;
336 break;
337 }
338 return 0;
339}
340
Jiri Bencf0706e82007-05-05 11:45:53 -0700341static int ieee80211_ioctl_siwfreq(struct net_device *dev,
342 struct iw_request_info *info,
343 struct iw_freq *freq, char *extra)
344{
Jiri Bencf0706e82007-05-05 11:45:53 -0700345 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
346
Johannes Berg05c914f2008-09-11 00:01:58 +0200347 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400348 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700349
350 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
351 if (freq->e == 0) {
352 if (freq->m < 0) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200353 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400354 sdata->u.sta.flags |=
355 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700356 return 0;
357 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200358 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100359 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700360 } else {
361 int i, div = 1000000;
362 for (i = 0; i < freq->e; i++)
363 div /= 10;
364 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200365 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700366 else
367 return -EINVAL;
368 }
369}
370
371
372static int ieee80211_ioctl_giwfreq(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_freq *freq, char *extra)
375{
376 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
377
Johannes Berg8318d782008-01-24 19:38:38 +0100378 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700379 freq->e = 6;
380
381 return 0;
382}
383
384
385static int ieee80211_ioctl_siwessid(struct net_device *dev,
386 struct iw_request_info *info,
387 struct iw_point *data, char *ssid)
388{
Jiri Bencf0706e82007-05-05 11:45:53 -0700389 struct ieee80211_sub_if_data *sdata;
390 size_t len = data->length;
391
392 /* iwconfig uses nul termination in SSID.. */
393 if (len > 0 && ssid[len - 1] == '\0')
394 len--;
395
396 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200397 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
398 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700399 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200400 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700401 if (len > IEEE80211_MAX_SSID_LEN)
402 return -EINVAL;
403 memcpy(sdata->u.sta.ssid, ssid, len);
404 sdata->u.sta.ssid_len = len;
405 return 0;
406 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400407 if (data->flags)
408 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
409 else
410 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200411 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700412 if (ret)
413 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200414 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700415 return 0;
416 }
417
Jiri Bencf0706e82007-05-05 11:45:53 -0700418 return -EOPNOTSUPP;
419}
420
421
422static int ieee80211_ioctl_giwessid(struct net_device *dev,
423 struct iw_request_info *info,
424 struct iw_point *data, char *ssid)
425{
426 size_t len;
427
428 struct ieee80211_sub_if_data *sdata;
429 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200430 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
431 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200432 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700433 if (res == 0) {
434 data->length = len;
435 data->flags = 1;
436 } else
437 data->flags = 0;
438 return res;
439 }
440
Jiri Bencf0706e82007-05-05 11:45:53 -0700441 return -EOPNOTSUPP;
442}
443
444
445static int ieee80211_ioctl_siwap(struct net_device *dev,
446 struct iw_request_info *info,
447 struct sockaddr *ap_addr, char *extra)
448{
Jiri Bencf0706e82007-05-05 11:45:53 -0700449 struct ieee80211_sub_if_data *sdata;
450
451 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200452 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
453 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700454 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200455 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700456 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
457 ETH_ALEN);
458 return 0;
459 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400460 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
461 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
462 IEEE80211_STA_AUTO_CHANNEL_SEL;
463 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
464 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700465 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400466 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200467 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700468 if (ret)
469 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200470 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700471 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200472 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100473 /*
474 * If it is necessary to update the WDS peer address
475 * while the interface is running, then we need to do
476 * more work here, namely if it is running we need to
477 * add a new and remove the old STA entry, this is
478 * normally handled by _open() and _stop().
479 */
480 if (netif_running(dev))
481 return -EBUSY;
482
483 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
484 ETH_ALEN);
485
486 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700487 }
488
489 return -EOPNOTSUPP;
490}
491
492
493static int ieee80211_ioctl_giwap(struct net_device *dev,
494 struct iw_request_info *info,
495 struct sockaddr *ap_addr, char *extra)
496{
497 struct ieee80211_sub_if_data *sdata;
498
499 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200500 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
501 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300502 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
503 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700504 ap_addr->sa_family = ARPHRD_ETHER;
505 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
506 return 0;
507 } else {
508 memset(&ap_addr->sa_data, 0, ETH_ALEN);
509 return 0;
510 }
Johannes Berg05c914f2008-09-11 00:01:58 +0200511 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700512 ap_addr->sa_family = ARPHRD_ETHER;
513 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
514 return 0;
515 }
516
517 return -EOPNOTSUPP;
518}
519
520
521static int ieee80211_ioctl_siwscan(struct net_device *dev,
522 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400523 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700524{
Jiri Bencf0706e82007-05-05 11:45:53 -0700525 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400526 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700527 u8 *ssid = NULL;
528 size_t ssid_len = 0;
529
530 if (!netif_running(dev))
531 return -ENETDOWN;
532
Johannes Berg05c914f2008-09-11 00:01:58 +0200533 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
534 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
535 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
536 sdata->vif.type != NL80211_IFTYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700537 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700538
539 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400540 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
541 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
542 req = (struct iw_scan_req *)extra;
543 ssid = req->essid;
544 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700545 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200546
Johannes Bergc2b13452008-09-11 00:01:55 +0200547 return ieee80211_request_scan(sdata, ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700548}
549
550
551static int ieee80211_ioctl_giwscan(struct net_device *dev,
552 struct iw_request_info *info,
553 struct iw_point *data, char *extra)
554{
555 int res;
556 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200557 struct ieee80211_sub_if_data *sdata;
558
559 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Zhu Yiece8edd2007-11-22 10:53:21 +0800560
Johannes Bergc2b13452008-09-11 00:01:55 +0200561 if (local->sw_scanning || local->hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700562 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800563
Johannes Bergc2b13452008-09-11 00:01:55 +0200564 res = ieee80211_scan_results(local, info, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700565 if (res >= 0) {
566 data->length = res;
567 return 0;
568 }
569 data->length = 0;
570 return res;
571}
572
573
Larry Finger1fd5e582007-07-10 19:32:10 +0200574static int ieee80211_ioctl_siwrate(struct net_device *dev,
575 struct iw_request_info *info,
576 struct iw_param *rate, char *extra)
577{
578 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100579 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200580 u32 target_rate = rate->value / 100000;
581 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100582 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200583
584 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100585
586 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
587
Larry Finger1fd5e582007-07-10 19:32:10 +0200588 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
589 * target_rate = X, rate->fixed = 1 means only rate X
590 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200591 sdata->max_ratectrl_rateidx = -1;
592 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200593 if (rate->value < 0)
594 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100595
596 for (i=0; i< sband->n_bitrates; i++) {
597 struct ieee80211_rate *brate = &sband->bitrates[i];
598 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200599
Larry Finger1fd5e582007-07-10 19:32:10 +0200600 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200601 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200602 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200603 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100604 err = 0;
605 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200606 }
607 }
Johannes Berg8318d782008-01-24 19:38:38 +0100608 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200609}
610
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700611static int ieee80211_ioctl_giwrate(struct net_device *dev,
612 struct iw_request_info *info,
613 struct iw_param *rate, char *extra)
614{
615 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
616 struct sta_info *sta;
617 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100618 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700619
620 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100621
Johannes Berg05c914f2008-09-11 00:01:58 +0200622 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700623 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100624
625 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
626
Johannes Berg380a9422008-04-04 23:40:35 +0200627 rcu_read_lock();
628
629 sta = sta_info_get(local, sdata->u.sta.bssid);
630
Johannes Berge6a98542008-10-21 12:40:02 +0200631 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
632 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700633 else
634 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200635
636 rcu_read_unlock();
637
638 if (!sta)
639 return -ENODEV;
640
Johannes Berg8318d782008-01-24 19:38:38 +0100641 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100642
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700643 return 0;
644}
645
Michael Buesch61609bc2007-09-20 22:06:39 +0200646static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
647 struct iw_request_info *info,
648 union iwreq_data *data, char *extra)
649{
650 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700651 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200652 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100653 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200654
655 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
656 return -EINVAL;
657 if (data->txpower.flags & IW_TXPOW_RANGE)
658 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700659 if (!chan)
660 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200661
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700662 if (data->txpower.fixed)
663 new_power_level = min(data->txpower.value, chan->max_power);
664 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100665 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200666
667 if (local->hw.conf.power_level != new_power_level) {
668 local->hw.conf.power_level = new_power_level;
Johannes Berge8975582008-10-09 12:18:51 +0200669 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Michael Buesch61609bc2007-09-20 22:06:39 +0200670 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200671
Michael Buesch61609bc2007-09-20 22:06:39 +0200672 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
673 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200674 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100675 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200676 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200677
Johannes Berge8975582008-10-09 12:18:51 +0200678 if (reconf_flags)
679 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200680
681 return 0;
682}
683
Larry Fingerfe6aa302007-08-10 11:23:20 -0500684static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
685 struct iw_request_info *info,
686 union iwreq_data *data, char *extra)
687{
688 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
689
690 data->txpower.fixed = 1;
691 data->txpower.disabled = !(local->hw.conf.radio_enabled);
692 data->txpower.value = local->hw.conf.power_level;
693 data->txpower.flags = IW_TXPOW_DBM;
694
695 return 0;
696}
697
Jiri Bencf0706e82007-05-05 11:45:53 -0700698static int ieee80211_ioctl_siwrts(struct net_device *dev,
699 struct iw_request_info *info,
700 struct iw_param *rts, char *extra)
701{
702 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
703
704 if (rts->disabled)
705 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300706 else if (!rts->fixed)
707 /* if the rts value is not fixed, then take default */
708 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700709 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
710 return -EINVAL;
711 else
712 local->rts_threshold = rts->value;
713
714 /* If the wlan card performs RTS/CTS in hardware/firmware,
715 * configure it here */
716
717 if (local->ops->set_rts_threshold)
718 local->ops->set_rts_threshold(local_to_hw(local),
719 local->rts_threshold);
720
721 return 0;
722}
723
724static int ieee80211_ioctl_giwrts(struct net_device *dev,
725 struct iw_request_info *info,
726 struct iw_param *rts, char *extra)
727{
728 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
729
730 rts->value = local->rts_threshold;
731 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
732 rts->fixed = 1;
733
734 return 0;
735}
736
737
738static int ieee80211_ioctl_siwfrag(struct net_device *dev,
739 struct iw_request_info *info,
740 struct iw_param *frag, char *extra)
741{
742 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
743
744 if (frag->disabled)
745 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300746 else if (!frag->fixed)
747 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700748 else if (frag->value < 256 ||
749 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
750 return -EINVAL;
751 else {
752 /* Fragment length must be even, so strip LSB. */
753 local->fragmentation_threshold = frag->value & ~0x1;
754 }
755
756 /* If the wlan card performs fragmentation in hardware/firmware,
757 * configure it here */
758
759 if (local->ops->set_frag_threshold)
Johannes Berg4233df62008-10-13 13:35:05 +0200760 return local->ops->set_frag_threshold(
Jiri Bencf0706e82007-05-05 11:45:53 -0700761 local_to_hw(local),
762 local->fragmentation_threshold);
763
764 return 0;
765}
766
767static int ieee80211_ioctl_giwfrag(struct net_device *dev,
768 struct iw_request_info *info,
769 struct iw_param *frag, char *extra)
770{
771 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
772
773 frag->value = local->fragmentation_threshold;
774 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
775 frag->fixed = 1;
776
777 return 0;
778}
779
780
781static int ieee80211_ioctl_siwretry(struct net_device *dev,
782 struct iw_request_info *info,
783 struct iw_param *retry, char *extra)
784{
785 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
786
787 if (retry->disabled ||
788 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
789 return -EINVAL;
790
Johannes Berg9124b072008-10-14 19:17:54 +0200791 if (retry->flags & IW_RETRY_MAX) {
792 local->hw.conf.long_frame_max_tx_count = retry->value;
793 } else if (retry->flags & IW_RETRY_MIN) {
794 local->hw.conf.short_frame_max_tx_count = retry->value;
795 } else {
796 local->hw.conf.long_frame_max_tx_count = retry->value;
797 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700798 }
799
Johannes Berg9124b072008-10-14 19:17:54 +0200800 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700801
802 return 0;
803}
804
805
806static int ieee80211_ioctl_giwretry(struct net_device *dev,
807 struct iw_request_info *info,
808 struct iw_param *retry, char *extra)
809{
810 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
811
812 retry->disabled = 0;
813 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
814 /* first return min value, iwconfig will ask max value
815 * later if needed */
816 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200817 retry->value = local->hw.conf.short_frame_max_tx_count;
818 if (local->hw.conf.long_frame_max_tx_count !=
819 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700820 retry->flags |= IW_RETRY_MIN;
821 return 0;
822 }
823 if (retry->flags & IW_RETRY_MAX) {
824 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200825 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700826 }
827
828 return 0;
829}
830
Jiri Bencf0706e82007-05-05 11:45:53 -0700831static int ieee80211_ioctl_siwmlme(struct net_device *dev,
832 struct iw_request_info *info,
833 struct iw_point *data, char *extra)
834{
835 struct ieee80211_sub_if_data *sdata;
836 struct iw_mlme *mlme = (struct iw_mlme *) extra;
837
838 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200839 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
840 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -0700841 return -EINVAL;
842
843 switch (mlme->cmd) {
844 case IW_MLME_DEAUTH:
845 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200846 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700847 case IW_MLME_DISASSOC:
848 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200849 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700850 default:
851 return -EOPNOTSUPP;
852 }
853}
854
855
856static int ieee80211_ioctl_siwencode(struct net_device *dev,
857 struct iw_request_info *info,
858 struct iw_point *erq, char *keybuf)
859{
860 struct ieee80211_sub_if_data *sdata;
861 int idx, i, alg = ALG_WEP;
862 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200863 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700864
865 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
866
867 idx = erq->flags & IW_ENCODE_INDEX;
868 if (idx == 0) {
869 if (sdata->default_key)
870 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
871 if (sdata->default_key == sdata->keys[i]) {
872 idx = i;
873 break;
874 }
875 }
876 } else if (idx < 1 || idx > 4)
877 return -EINVAL;
878 else
879 idx--;
880
881 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200882 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700883 else if (erq->length == 0) {
884 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400885 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700886 return 0;
887 }
888
889 return ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200890 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200891 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700892 !sdata->default_key,
893 keybuf, erq->length);
894}
895
896
897static int ieee80211_ioctl_giwencode(struct net_device *dev,
898 struct iw_request_info *info,
899 struct iw_point *erq, char *key)
900{
901 struct ieee80211_sub_if_data *sdata;
902 int idx, i;
903
904 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
905
906 idx = erq->flags & IW_ENCODE_INDEX;
907 if (idx < 1 || idx > 4) {
908 idx = -1;
909 if (!sdata->default_key)
910 idx = 0;
911 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
912 if (sdata->default_key == sdata->keys[i]) {
913 idx = i;
914 break;
915 }
916 }
917 if (idx < 0)
918 return -EINVAL;
919 } else
920 idx--;
921
922 erq->flags = idx + 1;
923
924 if (!sdata->keys[idx]) {
925 erq->length = 0;
926 erq->flags |= IW_ENCODE_DISABLED;
927 return 0;
928 }
929
Johannes Berg8f20fc22007-08-28 17:01:54 -0400930 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400931 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400932 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700933 erq->flags |= IW_ENCODE_ENABLED;
934
Johannes Berg05c914f2008-09-11 00:01:58 +0200935 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300936 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
937 switch (ifsta->auth_alg) {
938 case WLAN_AUTH_OPEN:
939 case WLAN_AUTH_LEAP:
940 erq->flags |= IW_ENCODE_OPEN;
941 break;
942 case WLAN_AUTH_SHARED_KEY:
943 erq->flags |= IW_ENCODE_RESTRICTED;
944 break;
945 }
946 }
947
Jiri Bencf0706e82007-05-05 11:45:53 -0700948 return 0;
949}
950
Samuel Ortiz49292d52008-07-04 10:49:31 +0200951static int ieee80211_ioctl_siwpower(struct net_device *dev,
952 struct iw_request_info *info,
953 struct iw_param *wrq,
954 char *extra)
955{
956 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
957 struct ieee80211_conf *conf = &local->hw.conf;
958
959 if (wrq->disabled) {
960 conf->flags &= ~IEEE80211_CONF_PS;
Johannes Berge8975582008-10-09 12:18:51 +0200961 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200962 }
963
964 switch (wrq->flags & IW_POWER_MODE) {
965 case IW_POWER_ON: /* If not specified */
966 case IW_POWER_MODE: /* If set all mask */
967 case IW_POWER_ALL_R: /* If explicitely state all */
968 conf->flags |= IEEE80211_CONF_PS;
969 break;
970 default: /* Otherwise we don't support it */
971 return -EINVAL;
972 }
973
Johannes Berge8975582008-10-09 12:18:51 +0200974 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200975}
976
977static int ieee80211_ioctl_giwpower(struct net_device *dev,
978 struct iw_request_info *info,
979 union iwreq_data *wrqu,
980 char *extra)
981{
982 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
983 struct ieee80211_conf *conf = &local->hw.conf;
984
985 wrqu->power.disabled = !(conf->flags & IEEE80211_CONF_PS);
986
987 return 0;
988}
989
Jiri Bencf0706e82007-05-05 11:45:53 -0700990static int ieee80211_ioctl_siwauth(struct net_device *dev,
991 struct iw_request_info *info,
992 struct iw_param *data, char *extra)
993{
Jiri Bencf0706e82007-05-05 11:45:53 -0700994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
995 int ret = 0;
996
997 switch (data->flags & IW_AUTH_INDEX) {
998 case IW_AUTH_WPA_VERSION:
999 case IW_AUTH_CIPHER_PAIRWISE:
1000 case IW_AUTH_CIPHER_GROUP:
1001 case IW_AUTH_WPA_ENABLED:
1002 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -07001003 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001004 break;
Johannes Bergb1357a82007-11-28 11:04:21 +01001005 case IW_AUTH_DROP_UNENCRYPTED:
1006 sdata->drop_unencrypted = !!data->value;
1007 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001008 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +02001009 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -07001010 ret = -EINVAL;
1011 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001012 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001013 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001014 * Privacy invoked by wpa_supplicant, store the
1015 * value and allow associating to a protected
1016 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -07001017 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001018 if (data->value)
1019 sdata->u.sta.flags |=
1020 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001021 }
1022 break;
1023 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +02001024 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1025 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001026 sdata->u.sta.auth_algs = data->value;
1027 else
1028 ret = -EOPNOTSUPP;
1029 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001030 default:
1031 ret = -EOPNOTSUPP;
1032 break;
1033 }
1034 return ret;
1035}
1036
1037/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1038static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
1039{
1040 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1041 struct iw_statistics *wstats = &local->wstats;
1042 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1043 struct sta_info *sta = NULL;
1044
Johannes Berg98dd6a52008-04-10 15:36:09 +02001045 rcu_read_lock();
1046
Johannes Berg05c914f2008-09-11 00:01:58 +02001047 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1048 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001049 sta = sta_info_get(local, sdata->u.sta.bssid);
1050 if (!sta) {
1051 wstats->discard.fragment = 0;
1052 wstats->discard.misc = 0;
1053 wstats->qual.qual = 0;
1054 wstats->qual.level = 0;
1055 wstats->qual.noise = 0;
1056 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1057 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001058 wstats->qual.level = sta->last_signal;
1059 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001060 wstats->qual.noise = sta->last_noise;
1061 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001062 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001063
1064 rcu_read_unlock();
1065
Jiri Bencf0706e82007-05-05 11:45:53 -07001066 return wstats;
1067}
1068
1069static int ieee80211_ioctl_giwauth(struct net_device *dev,
1070 struct iw_request_info *info,
1071 struct iw_param *data, char *extra)
1072{
1073 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1074 int ret = 0;
1075
1076 switch (data->flags & IW_AUTH_INDEX) {
1077 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +02001078 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1079 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e82007-05-05 11:45:53 -07001080 data->value = sdata->u.sta.auth_algs;
1081 else
1082 ret = -EOPNOTSUPP;
1083 break;
1084 default:
1085 ret = -EOPNOTSUPP;
1086 break;
1087 }
1088 return ret;
1089}
1090
1091
1092static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1093 struct iw_request_info *info,
1094 struct iw_point *erq, char *extra)
1095{
1096 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1097 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001098 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001099
1100 switch (ext->alg) {
1101 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001102 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001103 break;
1104 case IW_ENCODE_ALG_WEP:
1105 alg = ALG_WEP;
1106 break;
1107 case IW_ENCODE_ALG_TKIP:
1108 alg = ALG_TKIP;
1109 break;
1110 case IW_ENCODE_ALG_CCMP:
1111 alg = ALG_CCMP;
1112 break;
1113 default:
1114 return -EOPNOTSUPP;
1115 }
1116
1117 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001118 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001119
1120 idx = erq->flags & IW_ENCODE_INDEX;
1121 if (idx < 1 || idx > 4) {
1122 idx = -1;
1123 if (!sdata->default_key)
1124 idx = 0;
1125 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1126 if (sdata->default_key == sdata->keys[i]) {
1127 idx = i;
1128 break;
1129 }
1130 }
1131 if (idx < 0)
1132 return -EINVAL;
1133 } else
1134 idx--;
1135
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001136 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001137 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001138 ext->ext_flags &
1139 IW_ENCODE_EXT_SET_TX_KEY,
1140 ext->key, ext->key_len);
1141}
1142
1143
Jiri Bencf0706e82007-05-05 11:45:53 -07001144/* Structures to export the Wireless Handlers */
1145
1146static const iw_handler ieee80211_handler[] =
1147{
1148 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1149 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1150 (iw_handler) NULL, /* SIOCSIWNWID */
1151 (iw_handler) NULL, /* SIOCGIWNWID */
1152 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1153 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1154 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1155 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1156 (iw_handler) NULL, /* SIOCSIWSENS */
1157 (iw_handler) NULL, /* SIOCGIWSENS */
1158 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1159 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1160 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1161 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1162 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1163 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001164 (iw_handler) NULL, /* SIOCSIWSPY */
1165 (iw_handler) NULL, /* SIOCGIWSPY */
1166 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1167 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001168 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1169 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1170 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1171 (iw_handler) NULL, /* SIOCGIWAPLIST */
1172 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1173 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1174 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1175 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1176 (iw_handler) NULL, /* SIOCSIWNICKN */
1177 (iw_handler) NULL, /* SIOCGIWNICKN */
1178 (iw_handler) NULL, /* -- hole -- */
1179 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001180 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001181 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001182 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1183 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1184 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1185 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001186 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001187 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001188 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1189 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1190 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1191 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001192 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1193 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001194 (iw_handler) NULL, /* -- hole -- */
1195 (iw_handler) NULL, /* -- hole -- */
1196 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1197 (iw_handler) NULL, /* SIOCGIWGENIE */
1198 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1199 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1200 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1201 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1202 (iw_handler) NULL, /* SIOCSIWPMKSA */
1203 (iw_handler) NULL, /* -- hole -- */
1204};
1205
Jiri Bencf0706e82007-05-05 11:45:53 -07001206const struct iw_handler_def ieee80211_iw_handler_def =
1207{
1208 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001209 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001210 .get_wireless_stats = ieee80211_get_wireless_stats,
1211};