blob: 2b023dce8b24618a2130df07a072df1c08d1f4a9 [file] [log] [blame]
Jiri Bencf0706e822007-05-05 11:45:53 -07001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/netdevice.h>
13#include <linux/types.h>
14#include <linux/slab.h>
15#include <linux/skbuff.h>
16#include <linux/etherdevice.h>
17#include <linux/if_arp.h>
18#include <linux/wireless.h>
19#include <net/iw_handler.h>
20#include <asm/uaccess.h>
21
22#include <net/mac80211.h>
23#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040024#include "led.h"
25#include "rate.h"
Jiri Bencf0706e822007-05-05 11:45:53 -070026#include "wpa.h"
27#include "aes_ccm.h"
Jiri Bencf0706e822007-05-05 11:45:53 -070028
Johannes Bergb708e612007-09-14 11:10:25 -040029
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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070039
Jouni Malinen22787db2009-01-08 13:32:04 +020040 if (alg == ALG_AES_CMAC) {
41 if (idx < NUM_DEFAULT_KEYS ||
42 idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
43 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d "
44 "(BIP)\n", sdata->dev->name, idx);
45 return -EINVAL;
46 }
47 } else if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
Volker Braun139c3a02007-09-14 11:10:25 -040048 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120049 sdata->dev->name, idx);
Volker Braun139c3a02007-09-14 11:10:25 -040050 return -EINVAL;
51 }
52
Johannes Berg628a1402007-09-26 17:53:17 +020053 if (remove) {
Johannes Berg3b967662008-04-08 17:56:52 +020054 rcu_read_lock();
55
56 err = 0;
57
Johannes Bergdb4d1162008-02-25 16:27:45 +010058 if (is_broadcast_ether_addr(sta_addr)) {
59 key = sdata->keys[idx];
60 } else {
61 sta = sta_info_get(local, sta_addr);
Johannes Berg3b967662008-04-08 17:56:52 +020062 if (!sta) {
63 err = -ENOENT;
64 goto out_unlock;
65 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010066 key = sta->key;
Jiri Bencf0706e822007-05-05 11:45:53 -070067 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010068
Johannes Bergd0709a62008-02-25 16:27:46 +010069 ieee80211_key_free(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +010070 } else {
71 key = ieee80211_key_alloc(alg, idx, key_len, _key);
72 if (!key)
73 return -ENOMEM;
74
Johannes Bergd0709a62008-02-25 16:27:46 +010075 sta = NULL;
Johannes Berg3b967662008-04-08 17:56:52 +020076 err = 0;
77
78 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +010079
Johannes Bergdb4d1162008-02-25 16:27:45 +010080 if (!is_broadcast_ether_addr(sta_addr)) {
81 set_tx_key = 0;
82 /*
83 * According to the standard, the key index of a
84 * pairwise key must be zero. However, some AP are
85 * broken when it comes to WEP key indices, so we
86 * work around this.
87 */
88 if (idx != 0 && alg != ALG_WEP) {
Johannes Bergd0709a62008-02-25 16:27:46 +010089 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020090 err = -EINVAL;
91 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010092 }
93
94 sta = sta_info_get(local, sta_addr);
95 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +010096 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020097 err = -ENOENT;
98 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010099 }
100 }
101
Emmanuel Grumbach23976ef2008-06-28 02:50:13 +0300102 if (alg == ALG_WEP &&
103 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
104 ieee80211_key_free(key);
105 err = -EINVAL;
106 goto out_unlock;
107 }
108
Johannes Bergdb4d1162008-02-25 16:27:45 +0100109 ieee80211_key_link(key, sdata, sta);
110
111 if (set_tx_key || (!sta && !sdata->default_key && key))
112 ieee80211_set_default_key(sdata, idx);
Jouni Malinen22787db2009-01-08 13:32:04 +0200113 if (alg == ALG_AES_CMAC &&
114 (set_tx_key || (!sta && !sdata->default_mgmt_key && key)))
115 ieee80211_set_default_mgmt_key(sdata, idx);
Jiri Bencf0706e822007-05-05 11:45:53 -0700116 }
117
Johannes Berg3b967662008-04-08 17:56:52 +0200118 out_unlock:
119 rcu_read_unlock();
120
121 return err;
Jiri Bencf0706e822007-05-05 11:45:53 -0700122}
123
124static int ieee80211_ioctl_siwgenie(struct net_device *dev,
125 struct iw_request_info *info,
126 struct iw_point *data, char *extra)
127{
128 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e822007-05-05 11:45:53 -0700129
130 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200131
132 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
133 return -EOPNOTSUPP;
134
Johannes Berg05c914f2008-09-11 00:01:58 +0200135 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
136 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200137 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e822007-05-05 11:45:53 -0700138 if (ret)
139 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400140 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200141 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e822007-05-05 11:45:53 -0700142 return 0;
143 }
144
Jiri Bencf0706e822007-05-05 11:45:53 -0700145 return -EOPNOTSUPP;
146}
147
Johannes Berg9a03d6d2009-02-10 21:26:01 +0100148static u8 ieee80211_get_wstats_flags(struct ieee80211_local *local)
149{
150 u8 wstats_flags = 0;
151
152 wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
153 IEEE80211_HW_SIGNAL_DBM) ?
154 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
155 wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ?
156 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
157 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
158 wstats_flags |= IW_QUAL_DBM;
159
160 return wstats_flags;
161}
162
Jiri Bencf0706e822007-05-05 11:45:53 -0700163static int ieee80211_ioctl_giwrange(struct net_device *dev,
164 struct iw_request_info *info,
165 struct iw_point *data, char *extra)
166{
167 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
168 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100169 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200170 int c = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700171
172 data->length = sizeof(struct iw_range);
173 memset(range, 0, sizeof(struct iw_range));
174
175 range->we_version_compiled = WIRELESS_EXT;
176 range->we_version_source = 21;
177 range->retry_capa = IW_RETRY_LIMIT;
178 range->retry_flags = IW_RETRY_LIMIT;
179 range->min_retry = 0;
180 range->max_retry = 255;
181 range->min_rts = 0;
182 range->max_rts = 2347;
183 range->min_frag = 256;
184 range->max_frag = 2346;
185
186 range->encoding_size[0] = 5;
187 range->encoding_size[1] = 13;
188 range->num_encoding_sizes = 2;
189 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
190
Johannes Berg2a519312009-02-10 21:25:55 +0100191 /* cfg80211 requires this, and enforces 0..100 */
Johannes Berg7fee5372009-01-30 11:13:06 +0100192 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
Johannes Berg2a519312009-02-10 21:25:55 +0100193 range->max_qual.level = 100;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200194 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
195 range->max_qual.level = -110;
196 else
197 range->max_qual.level = 0;
198
199 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
200 range->max_qual.noise = -110;
201 else
202 range->max_qual.noise = 0;
203
204 range->max_qual.qual = 100;
Johannes Berg9a03d6d2009-02-10 21:26:01 +0100205 range->max_qual.updated = ieee80211_get_wstats_flags(local);
Jiri Bencf0706e822007-05-05 11:45:53 -0700206
Bruno Randolf566bfe52008-05-08 19:15:40 +0200207 range->avg_qual.qual = 50;
208 /* not always true but better than nothing */
209 range->avg_qual.level = range->max_qual.level / 2;
210 range->avg_qual.noise = range->max_qual.noise / 2;
Johannes Berg9a03d6d2009-02-10 21:26:01 +0100211 range->avg_qual.updated = ieee80211_get_wstats_flags(local);
Jiri Bencf0706e822007-05-05 11:45:53 -0700212
213 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
214 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
215
Hong Liu333af2f2007-07-10 19:32:08 +0200216
Johannes Berg8318d782008-01-24 19:38:38 +0100217 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
218 int i;
219 struct ieee80211_supported_band *sband;
220
221 sband = local->hw.wiphy->bands[band];
222
223 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200224 continue;
225
Johannes Berg8318d782008-01-24 19:38:38 +0100226 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
227 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200228
Johannes Berg8318d782008-01-24 19:38:38 +0100229 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
230 range->freq[c].i =
231 ieee80211_frequency_to_channel(
232 chan->center_freq);
233 range->freq[c].m = chan->center_freq;
234 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200235 c++;
236 }
Hong Liu333af2f2007-07-10 19:32:08 +0200237 }
238 }
239 range->num_channels = c;
240 range->num_frequency = c;
241
Jiri Bencf0706e822007-05-05 11:45:53 -0700242 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e822007-05-05 11:45:53 -0700243 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
244 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
245
Dan Williams374fdfb2007-12-12 10:25:07 -0500246 range->scan_capa |= IW_SCAN_CAPA_ESSID;
247
Jiri Bencf0706e822007-05-05 11:45:53 -0700248 return 0;
249}
250
251
Jiri Bencf0706e822007-05-05 11:45:53 -0700252static int ieee80211_ioctl_siwfreq(struct net_device *dev,
253 struct iw_request_info *info,
254 struct iw_freq *freq, char *extra)
255{
Jiri Bencf0706e822007-05-05 11:45:53 -0700256 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
257
Alina Friedrichsenb522ed52009-01-06 03:15:23 +0100258 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
259 sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400260 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700261
262 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
263 if (freq->e == 0) {
264 if (freq->m < 0) {
Alina Friedrichsenb522ed52009-01-06 03:15:23 +0100265 if (sdata->vif.type == NL80211_IFTYPE_ADHOC ||
266 sdata->vif.type == NL80211_IFTYPE_STATION)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400267 sdata->u.sta.flags |=
268 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700269 return 0;
270 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200271 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100272 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e822007-05-05 11:45:53 -0700273 } else {
274 int i, div = 1000000;
275 for (i = 0; i < freq->e; i++)
276 div /= 10;
277 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200278 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e822007-05-05 11:45:53 -0700279 else
280 return -EINVAL;
281 }
282}
283
284
285static int ieee80211_ioctl_giwfreq(struct net_device *dev,
286 struct iw_request_info *info,
287 struct iw_freq *freq, char *extra)
288{
289 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
290
Johannes Berg8318d782008-01-24 19:38:38 +0100291 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e822007-05-05 11:45:53 -0700292 freq->e = 6;
293
294 return 0;
295}
296
297
298static int ieee80211_ioctl_siwessid(struct net_device *dev,
299 struct iw_request_info *info,
300 struct iw_point *data, char *ssid)
301{
Jiri Bencf0706e822007-05-05 11:45:53 -0700302 struct ieee80211_sub_if_data *sdata;
303 size_t len = data->length;
304
305 /* iwconfig uses nul termination in SSID.. */
306 if (len > 0 && ssid[len - 1] == '\0')
307 len--;
308
309 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200310 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
311 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700312 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200313 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700314 if (len > IEEE80211_MAX_SSID_LEN)
315 return -EINVAL;
316 memcpy(sdata->u.sta.ssid, ssid, len);
317 sdata->u.sta.ssid_len = len;
318 return 0;
319 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400320 if (data->flags)
321 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
322 else
323 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200324 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700325 if (ret)
326 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200327 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e822007-05-05 11:45:53 -0700328 return 0;
329 }
330
Jiri Bencf0706e822007-05-05 11:45:53 -0700331 return -EOPNOTSUPP;
332}
333
334
335static int ieee80211_ioctl_giwessid(struct net_device *dev,
336 struct iw_request_info *info,
337 struct iw_point *data, char *ssid)
338{
339 size_t len;
340
341 struct ieee80211_sub_if_data *sdata;
342 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200343 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
344 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200345 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700346 if (res == 0) {
347 data->length = len;
348 data->flags = 1;
349 } else
350 data->flags = 0;
351 return res;
352 }
353
Jiri Bencf0706e822007-05-05 11:45:53 -0700354 return -EOPNOTSUPP;
355}
356
357
358static int ieee80211_ioctl_siwap(struct net_device *dev,
359 struct iw_request_info *info,
360 struct sockaddr *ap_addr, char *extra)
361{
Jiri Bencf0706e822007-05-05 11:45:53 -0700362 struct ieee80211_sub_if_data *sdata;
363
364 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200365 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
366 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700367 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200368 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700369 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
370 ETH_ALEN);
371 return 0;
372 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400373 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
374 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
375 IEEE80211_STA_AUTO_CHANNEL_SEL;
376 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
377 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700378 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400379 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200380 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e822007-05-05 11:45:53 -0700381 if (ret)
382 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200383 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e822007-05-05 11:45:53 -0700384 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200385 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100386 /*
387 * If it is necessary to update the WDS peer address
388 * while the interface is running, then we need to do
389 * more work here, namely if it is running we need to
390 * add a new and remove the old STA entry, this is
391 * normally handled by _open() and _stop().
392 */
393 if (netif_running(dev))
394 return -EBUSY;
395
396 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
397 ETH_ALEN);
398
399 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700400 }
401
402 return -EOPNOTSUPP;
403}
404
405
406static int ieee80211_ioctl_giwap(struct net_device *dev,
407 struct iw_request_info *info,
408 struct sockaddr *ap_addr, char *extra)
409{
410 struct ieee80211_sub_if_data *sdata;
411
412 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200413 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
414 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300415 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
416 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700417 ap_addr->sa_family = ARPHRD_ETHER;
418 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
419 return 0;
420 } else {
421 memset(&ap_addr->sa_data, 0, ETH_ALEN);
422 return 0;
423 }
Johannes Berg05c914f2008-09-11 00:01:58 +0200424 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700425 ap_addr->sa_family = ARPHRD_ETHER;
426 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
427 return 0;
428 }
429
430 return -EOPNOTSUPP;
431}
432
433
Larry Finger1fd5e582007-07-10 19:32:10 +0200434static int ieee80211_ioctl_siwrate(struct net_device *dev,
435 struct iw_request_info *info,
436 struct iw_param *rate, char *extra)
437{
438 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100439 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200440 u32 target_rate = rate->value / 100000;
441 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100442 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200443
444 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100445
446 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
447
Larry Finger1fd5e582007-07-10 19:32:10 +0200448 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
449 * target_rate = X, rate->fixed = 1 means only rate X
450 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200451 sdata->max_ratectrl_rateidx = -1;
452 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200453 if (rate->value < 0)
454 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100455
456 for (i=0; i< sband->n_bitrates; i++) {
457 struct ieee80211_rate *brate = &sband->bitrates[i];
458 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200459
Larry Finger1fd5e582007-07-10 19:32:10 +0200460 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200461 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200462 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200463 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100464 err = 0;
465 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200466 }
467 }
Johannes Berg8318d782008-01-24 19:38:38 +0100468 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200469}
470
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700471static int ieee80211_ioctl_giwrate(struct net_device *dev,
472 struct iw_request_info *info,
473 struct iw_param *rate, char *extra)
474{
475 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
476 struct sta_info *sta;
477 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100478 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700479
480 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100481
Johannes Berg05c914f2008-09-11 00:01:58 +0200482 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700483 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100484
485 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
486
Johannes Berg380a9422008-04-04 23:40:35 +0200487 rcu_read_lock();
488
489 sta = sta_info_get(local, sdata->u.sta.bssid);
490
Johannes Berge6a98542008-10-21 12:40:02 +0200491 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
492 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700493 else
494 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200495
496 rcu_read_unlock();
497
498 if (!sta)
499 return -ENODEV;
500
Johannes Berg8318d782008-01-24 19:38:38 +0100501 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100502
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700503 return 0;
504}
505
Michael Buesch61609bc2007-09-20 22:06:39 +0200506static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
507 struct iw_request_info *info,
508 union iwreq_data *data, char *extra)
509{
510 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700511 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200512 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100513 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200514
515 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
516 return -EINVAL;
517 if (data->txpower.flags & IW_TXPOW_RANGE)
518 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700519 if (!chan)
520 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200521
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700522 if (data->txpower.fixed)
523 new_power_level = min(data->txpower.value, chan->max_power);
524 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100525 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200526
Johannes Berg2bf30fa2009-01-06 23:23:56 +0100527 local->user_power_level = new_power_level;
Vasanthakumar Thiagarajane3c92df2008-12-24 13:53:11 +0530528 if (local->hw.conf.power_level != new_power_level)
Johannes Berge8975582008-10-09 12:18:51 +0200529 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Mattias Nissler6a432952007-10-24 23:30:36 +0200530
Michael Buesch61609bc2007-09-20 22:06:39 +0200531 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
532 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200533 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100534 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200535 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200536
Johannes Berge8975582008-10-09 12:18:51 +0200537 if (reconf_flags)
538 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200539
540 return 0;
541}
542
Larry Fingerfe6aa302007-08-10 11:23:20 -0500543static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
544 struct iw_request_info *info,
545 union iwreq_data *data, char *extra)
546{
547 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
548
549 data->txpower.fixed = 1;
550 data->txpower.disabled = !(local->hw.conf.radio_enabled);
551 data->txpower.value = local->hw.conf.power_level;
552 data->txpower.flags = IW_TXPOW_DBM;
553
554 return 0;
555}
556
Jiri Bencf0706e822007-05-05 11:45:53 -0700557static int ieee80211_ioctl_siwrts(struct net_device *dev,
558 struct iw_request_info *info,
559 struct iw_param *rts, char *extra)
560{
561 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
562
563 if (rts->disabled)
564 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300565 else if (!rts->fixed)
566 /* if the rts value is not fixed, then take default */
567 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e822007-05-05 11:45:53 -0700568 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
569 return -EINVAL;
570 else
571 local->rts_threshold = rts->value;
572
573 /* If the wlan card performs RTS/CTS in hardware/firmware,
574 * configure it here */
575
576 if (local->ops->set_rts_threshold)
577 local->ops->set_rts_threshold(local_to_hw(local),
578 local->rts_threshold);
579
580 return 0;
581}
582
583static int ieee80211_ioctl_giwrts(struct net_device *dev,
584 struct iw_request_info *info,
585 struct iw_param *rts, char *extra)
586{
587 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
588
589 rts->value = local->rts_threshold;
590 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
591 rts->fixed = 1;
592
593 return 0;
594}
595
596
597static int ieee80211_ioctl_siwfrag(struct net_device *dev,
598 struct iw_request_info *info,
599 struct iw_param *frag, char *extra)
600{
601 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
602
603 if (frag->disabled)
604 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300605 else if (!frag->fixed)
606 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e822007-05-05 11:45:53 -0700607 else if (frag->value < 256 ||
608 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
609 return -EINVAL;
610 else {
611 /* Fragment length must be even, so strip LSB. */
612 local->fragmentation_threshold = frag->value & ~0x1;
613 }
614
Jiri Bencf0706e822007-05-05 11:45:53 -0700615 return 0;
616}
617
618static int ieee80211_ioctl_giwfrag(struct net_device *dev,
619 struct iw_request_info *info,
620 struct iw_param *frag, char *extra)
621{
622 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
623
624 frag->value = local->fragmentation_threshold;
625 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
626 frag->fixed = 1;
627
628 return 0;
629}
630
631
632static int ieee80211_ioctl_siwretry(struct net_device *dev,
633 struct iw_request_info *info,
634 struct iw_param *retry, char *extra)
635{
636 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
637
638 if (retry->disabled ||
639 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
640 return -EINVAL;
641
Johannes Berg9124b072008-10-14 19:17:54 +0200642 if (retry->flags & IW_RETRY_MAX) {
643 local->hw.conf.long_frame_max_tx_count = retry->value;
644 } else if (retry->flags & IW_RETRY_MIN) {
645 local->hw.conf.short_frame_max_tx_count = retry->value;
646 } else {
647 local->hw.conf.long_frame_max_tx_count = retry->value;
648 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e822007-05-05 11:45:53 -0700649 }
650
Johannes Berg9124b072008-10-14 19:17:54 +0200651 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e822007-05-05 11:45:53 -0700652
653 return 0;
654}
655
656
657static int ieee80211_ioctl_giwretry(struct net_device *dev,
658 struct iw_request_info *info,
659 struct iw_param *retry, char *extra)
660{
661 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
662
663 retry->disabled = 0;
664 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
665 /* first return min value, iwconfig will ask max value
666 * later if needed */
667 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200668 retry->value = local->hw.conf.short_frame_max_tx_count;
669 if (local->hw.conf.long_frame_max_tx_count !=
670 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e822007-05-05 11:45:53 -0700671 retry->flags |= IW_RETRY_MIN;
672 return 0;
673 }
674 if (retry->flags & IW_RETRY_MAX) {
675 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200676 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e822007-05-05 11:45:53 -0700677 }
678
679 return 0;
680}
681
Jiri Bencf0706e822007-05-05 11:45:53 -0700682static int ieee80211_ioctl_siwmlme(struct net_device *dev,
683 struct iw_request_info *info,
684 struct iw_point *data, char *extra)
685{
686 struct ieee80211_sub_if_data *sdata;
687 struct iw_mlme *mlme = (struct iw_mlme *) extra;
688
689 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg05c914f2008-09-11 00:01:58 +0200690 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
691 sdata->vif.type != NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e822007-05-05 11:45:53 -0700692 return -EINVAL;
693
694 switch (mlme->cmd) {
695 case IW_MLME_DEAUTH:
696 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200697 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -0700698 case IW_MLME_DISASSOC:
699 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200700 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -0700701 default:
702 return -EOPNOTSUPP;
703 }
704}
705
706
707static int ieee80211_ioctl_siwencode(struct net_device *dev,
708 struct iw_request_info *info,
709 struct iw_point *erq, char *keybuf)
710{
711 struct ieee80211_sub_if_data *sdata;
712 int idx, i, alg = ALG_WEP;
713 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200714 int remove = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700715
716 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
717
718 idx = erq->flags & IW_ENCODE_INDEX;
719 if (idx == 0) {
720 if (sdata->default_key)
721 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
722 if (sdata->default_key == sdata->keys[i]) {
723 idx = i;
724 break;
725 }
726 }
727 } else if (idx < 1 || idx > 4)
728 return -EINVAL;
729 else
730 idx--;
731
732 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200733 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -0700734 else if (erq->length == 0) {
735 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400736 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e822007-05-05 11:45:53 -0700737 return 0;
738 }
739
740 return ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200741 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200742 idx, alg, remove,
Jiri Bencf0706e822007-05-05 11:45:53 -0700743 !sdata->default_key,
744 keybuf, erq->length);
745}
746
747
748static int ieee80211_ioctl_giwencode(struct net_device *dev,
749 struct iw_request_info *info,
750 struct iw_point *erq, char *key)
751{
752 struct ieee80211_sub_if_data *sdata;
753 int idx, i;
754
755 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
756
757 idx = erq->flags & IW_ENCODE_INDEX;
758 if (idx < 1 || idx > 4) {
759 idx = -1;
760 if (!sdata->default_key)
761 idx = 0;
762 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
763 if (sdata->default_key == sdata->keys[i]) {
764 idx = i;
765 break;
766 }
767 }
768 if (idx < 0)
769 return -EINVAL;
770 } else
771 idx--;
772
773 erq->flags = idx + 1;
774
775 if (!sdata->keys[idx]) {
776 erq->length = 0;
777 erq->flags |= IW_ENCODE_DISABLED;
778 return 0;
779 }
780
Johannes Berg8f20fc22007-08-28 17:01:54 -0400781 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400782 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400783 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e822007-05-05 11:45:53 -0700784 erq->flags |= IW_ENCODE_ENABLED;
785
Johannes Berg05c914f2008-09-11 00:01:58 +0200786 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300787 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
788 switch (ifsta->auth_alg) {
789 case WLAN_AUTH_OPEN:
790 case WLAN_AUTH_LEAP:
791 erq->flags |= IW_ENCODE_OPEN;
792 break;
793 case WLAN_AUTH_SHARED_KEY:
794 erq->flags |= IW_ENCODE_RESTRICTED;
795 break;
796 }
797 }
798
Jiri Bencf0706e822007-05-05 11:45:53 -0700799 return 0;
800}
801
Samuel Ortiz49292d52008-07-04 10:49:31 +0200802static int ieee80211_ioctl_siwpower(struct net_device *dev,
803 struct iw_request_info *info,
804 struct iw_param *wrq,
805 char *extra)
806{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200807 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200808 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
809 struct ieee80211_conf *conf = &local->hw.conf;
Kalle Valo520eb822008-12-18 23:35:27 +0200810 int ret = 0, timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200811 bool ps;
812
Johannes Berg4be8c382009-01-07 18:28:20 +0100813 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
814 return -EOPNOTSUPP;
815
Kalle Valoe0cb6862008-12-18 23:35:13 +0200816 if (sdata->vif.type != NL80211_IFTYPE_STATION)
817 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200818
819 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200820 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200821 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200822 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200823 }
824
825 switch (wrq->flags & IW_POWER_MODE) {
826 case IW_POWER_ON: /* If not specified */
827 case IW_POWER_MODE: /* If set all mask */
828 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200829 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200830 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200831 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100832 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200833 }
834
Johannes Berge9aeaba2009-01-06 18:12:35 +0100835 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
836 return -EINVAL;
837
Kalle Valo520eb822008-12-18 23:35:27 +0200838 if (wrq->flags & IW_POWER_TIMEOUT)
839 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200840
Johannes Berg4be8c382009-01-07 18:28:20 +0100841 set:
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100842 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
Kalle Valo520eb822008-12-18 23:35:27 +0200843 return ret;
844
Kalle Valoe0cb6862008-12-18 23:35:13 +0200845 local->powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100846 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200847
Johannes Berg4be8c382009-01-07 18:28:20 +0100848 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100849 ret = ieee80211_hw_config(local,
850 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
Johannes Berg4be8c382009-01-07 18:28:20 +0100851
852 if (!(sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
853 return ret;
854
855 if (conf->dynamic_ps_timeout > 0 &&
856 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
857 mod_timer(&local->dynamic_ps_timer, jiffies +
858 msecs_to_jiffies(conf->dynamic_ps_timeout));
859 } else {
860 if (local->powersave) {
861 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800862 ieee80211_send_nullfunc(local, sdata, 1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100863 conf->flags |= IEEE80211_CONF_PS;
864 ret = ieee80211_hw_config(local,
865 IEEE80211_CONF_CHANGE_PS);
866 } else {
867 conf->flags &= ~IEEE80211_CONF_PS;
868 ret = ieee80211_hw_config(local,
869 IEEE80211_CONF_CHANGE_PS);
870 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800871 ieee80211_send_nullfunc(local, sdata, 0);
Vivek Natarajanb8abde42009-01-27 19:26:28 +0530872 del_timer_sync(&local->dynamic_ps_timer);
873 cancel_work_sync(&local->dynamic_ps_enable_work);
Kalle Valo520eb822008-12-18 23:35:27 +0200874 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200875 }
876
877 return ret;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200878}
879
880static int ieee80211_ioctl_giwpower(struct net_device *dev,
881 struct iw_request_info *info,
882 union iwreq_data *wrqu,
883 char *extra)
884{
885 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200886
Kalle Valoe0cb6862008-12-18 23:35:13 +0200887 wrqu->power.disabled = !local->powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200888
889 return 0;
890}
891
Jiri Bencf0706e822007-05-05 11:45:53 -0700892static int ieee80211_ioctl_siwauth(struct net_device *dev,
893 struct iw_request_info *info,
894 struct iw_param *data, char *extra)
895{
Jiri Bencf0706e822007-05-05 11:45:53 -0700896 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
897 int ret = 0;
898
899 switch (data->flags & IW_AUTH_INDEX) {
900 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e822007-05-05 11:45:53 -0700901 case IW_AUTH_CIPHER_GROUP:
902 case IW_AUTH_WPA_ENABLED:
903 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e822007-05-05 11:45:53 -0700904 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200905 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000906 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530907 case IW_AUTH_CIPHER_PAIRWISE:
908 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
909 if (data->value & (IW_AUTH_CIPHER_WEP40 |
910 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
911 sdata->u.sta.flags |=
912 IEEE80211_STA_TKIP_WEP_USED;
913 else
914 sdata->u.sta.flags &=
915 ~IEEE80211_STA_TKIP_WEP_USED;
916 }
917 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100918 case IW_AUTH_DROP_UNENCRYPTED:
919 sdata->drop_unencrypted = !!data->value;
920 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000921 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200922 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e822007-05-05 11:45:53 -0700923 ret = -EINVAL;
924 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000925 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e822007-05-05 11:45:53 -0700926 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000927 * Privacy invoked by wpa_supplicant, store the
928 * value and allow associating to a protected
929 * network without having a key up front.
Jiri Bencf0706e822007-05-05 11:45:53 -0700930 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000931 if (data->value)
932 sdata->u.sta.flags |=
933 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e822007-05-05 11:45:53 -0700934 }
935 break;
936 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +0200937 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
938 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e822007-05-05 11:45:53 -0700939 sdata->u.sta.auth_algs = data->value;
940 else
941 ret = -EOPNOTSUPP;
942 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200943 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200944 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
945 ret = -EOPNOTSUPP;
946 break;
947 }
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200948 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100949 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
950 switch (data->value) {
951 case IW_AUTH_MFP_DISABLED:
952 sdata->u.sta.mfp = IEEE80211_MFP_DISABLED;
953 break;
954 case IW_AUTH_MFP_OPTIONAL:
955 sdata->u.sta.mfp = IEEE80211_MFP_OPTIONAL;
956 break;
957 case IW_AUTH_MFP_REQUIRED:
958 sdata->u.sta.mfp = IEEE80211_MFP_REQUIRED;
959 break;
960 default:
961 ret = -EINVAL;
962 }
963 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200964 ret = -EOPNOTSUPP;
965 break;
Jiri Bencf0706e822007-05-05 11:45:53 -0700966 default:
967 ret = -EOPNOTSUPP;
968 break;
969 }
970 return ret;
971}
972
973/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
974static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
975{
976 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
977 struct iw_statistics *wstats = &local->wstats;
978 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
979 struct sta_info *sta = NULL;
980
Johannes Berg98dd6a52008-04-10 15:36:09 +0200981 rcu_read_lock();
982
Johannes Berg05c914f2008-09-11 00:01:58 +0200983 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
984 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e822007-05-05 11:45:53 -0700985 sta = sta_info_get(local, sdata->u.sta.bssid);
986 if (!sta) {
987 wstats->discard.fragment = 0;
988 wstats->discard.misc = 0;
989 wstats->qual.qual = 0;
990 wstats->qual.level = 0;
991 wstats->qual.noise = 0;
992 wstats->qual.updated = IW_QUAL_ALL_INVALID;
993 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +0200994 wstats->qual.level = sta->last_signal;
995 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e822007-05-05 11:45:53 -0700996 wstats->qual.noise = sta->last_noise;
Johannes Berg9a03d6d2009-02-10 21:26:01 +0100997 wstats->qual.updated = ieee80211_get_wstats_flags(local);
Jiri Bencf0706e822007-05-05 11:45:53 -0700998 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200999
1000 rcu_read_unlock();
1001
Jiri Bencf0706e822007-05-05 11:45:53 -07001002 return wstats;
1003}
1004
1005static int ieee80211_ioctl_giwauth(struct net_device *dev,
1006 struct iw_request_info *info,
1007 struct iw_param *data, char *extra)
1008{
1009 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1010 int ret = 0;
1011
1012 switch (data->flags & IW_AUTH_INDEX) {
1013 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg05c914f2008-09-11 00:01:58 +02001014 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1015 sdata->vif.type == NL80211_IFTYPE_ADHOC)
Jiri Bencf0706e822007-05-05 11:45:53 -07001016 data->value = sdata->u.sta.auth_algs;
1017 else
1018 ret = -EOPNOTSUPP;
1019 break;
1020 default:
1021 ret = -EOPNOTSUPP;
1022 break;
1023 }
1024 return ret;
1025}
1026
1027
1028static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1029 struct iw_request_info *info,
1030 struct iw_point *erq, char *extra)
1031{
1032 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1033 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001034 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07001035
1036 switch (ext->alg) {
1037 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001038 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -07001039 break;
1040 case IW_ENCODE_ALG_WEP:
1041 alg = ALG_WEP;
1042 break;
1043 case IW_ENCODE_ALG_TKIP:
1044 alg = ALG_TKIP;
1045 break;
1046 case IW_ENCODE_ALG_CCMP:
1047 alg = ALG_CCMP;
1048 break;
Jouni Malinen22787db2009-01-08 13:32:04 +02001049 case IW_ENCODE_ALG_AES_CMAC:
1050 alg = ALG_AES_CMAC;
1051 break;
Jiri Bencf0706e822007-05-05 11:45:53 -07001052 default:
1053 return -EOPNOTSUPP;
1054 }
1055
1056 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001057 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -07001058
1059 idx = erq->flags & IW_ENCODE_INDEX;
Jouni Malinen22787db2009-01-08 13:32:04 +02001060 if (alg == ALG_AES_CMAC) {
1061 if (idx < NUM_DEFAULT_KEYS + 1 ||
1062 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1063 idx = -1;
1064 if (!sdata->default_mgmt_key)
1065 idx = 0;
1066 else for (i = NUM_DEFAULT_KEYS;
1067 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1068 i++) {
1069 if (sdata->default_mgmt_key == sdata->keys[i])
1070 {
1071 idx = i;
1072 break;
1073 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001074 }
Jouni Malinen22787db2009-01-08 13:32:04 +02001075 if (idx < 0)
1076 return -EINVAL;
1077 } else
1078 idx--;
1079 } else {
1080 if (idx < 1 || idx > 4) {
1081 idx = -1;
1082 if (!sdata->default_key)
1083 idx = 0;
1084 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1085 if (sdata->default_key == sdata->keys[i]) {
1086 idx = i;
1087 break;
1088 }
1089 }
1090 if (idx < 0)
1091 return -EINVAL;
1092 } else
1093 idx--;
1094 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001095
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001096 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001097 remove,
Jiri Bencf0706e822007-05-05 11:45:53 -07001098 ext->ext_flags &
1099 IW_ENCODE_EXT_SET_TX_KEY,
1100 ext->key, ext->key_len);
1101}
1102
1103
Jiri Bencf0706e822007-05-05 11:45:53 -07001104/* Structures to export the Wireless Handlers */
1105
1106static const iw_handler ieee80211_handler[] =
1107{
1108 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001109 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e822007-05-05 11:45:53 -07001110 (iw_handler) NULL, /* SIOCSIWNWID */
1111 (iw_handler) NULL, /* SIOCGIWNWID */
1112 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1113 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001114 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1115 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e822007-05-05 11:45:53 -07001116 (iw_handler) NULL, /* SIOCSIWSENS */
1117 (iw_handler) NULL, /* SIOCGIWSENS */
1118 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1119 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1120 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1121 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1122 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1123 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001124 (iw_handler) NULL, /* SIOCSIWSPY */
1125 (iw_handler) NULL, /* SIOCGIWSPY */
1126 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1127 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e822007-05-05 11:45:53 -07001128 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1129 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1130 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1131 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +01001132 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1133 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e822007-05-05 11:45:53 -07001134 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1135 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1136 (iw_handler) NULL, /* SIOCSIWNICKN */
1137 (iw_handler) NULL, /* SIOCGIWNICKN */
1138 (iw_handler) NULL, /* -- hole -- */
1139 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001140 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001141 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e822007-05-05 11:45:53 -07001142 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1143 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1144 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1145 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001146 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001147 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e822007-05-05 11:45:53 -07001148 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1149 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1150 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1151 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001152 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1153 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e822007-05-05 11:45:53 -07001154 (iw_handler) NULL, /* -- hole -- */
1155 (iw_handler) NULL, /* -- hole -- */
1156 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1157 (iw_handler) NULL, /* SIOCGIWGENIE */
1158 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1159 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1160 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1161 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1162 (iw_handler) NULL, /* SIOCSIWPMKSA */
1163 (iw_handler) NULL, /* -- hole -- */
1164};
1165
Jiri Bencf0706e822007-05-05 11:45:53 -07001166const struct iw_handler_def ieee80211_iw_handler_def =
1167{
1168 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e822007-05-05 11:45:53 -07001169 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e822007-05-05 11:45:53 -07001170 .get_wireless_stats = ieee80211_get_wireless_stats,
1171};