blob: 8a76a979bc925d94f05173d07372a0c9e59c95c2 [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
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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Berg46900292009-02-15 12:44:28 +0100135 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200136 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700137 if (ret)
138 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100139 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
140 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700141 return 0;
142 }
143
Jiri Bencf0706e82007-05-05 11:45:53 -0700144 return -EOPNOTSUPP;
145}
146
Johannes Berg9a03d6d2009-02-10 21:26:01 +0100147static u8 ieee80211_get_wstats_flags(struct ieee80211_local *local)
148{
149 u8 wstats_flags = 0;
150
151 wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
152 IEEE80211_HW_SIGNAL_DBM) ?
153 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
154 wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ?
155 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
156 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
157 wstats_flags |= IW_QUAL_DBM;
158
159 return wstats_flags;
160}
161
Jiri Bencf0706e82007-05-05 11:45:53 -0700162static int ieee80211_ioctl_giwrange(struct net_device *dev,
163 struct iw_request_info *info,
164 struct iw_point *data, char *extra)
165{
166 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
167 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100168 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200169 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700170
171 data->length = sizeof(struct iw_range);
172 memset(range, 0, sizeof(struct iw_range));
173
174 range->we_version_compiled = WIRELESS_EXT;
175 range->we_version_source = 21;
176 range->retry_capa = IW_RETRY_LIMIT;
177 range->retry_flags = IW_RETRY_LIMIT;
178 range->min_retry = 0;
179 range->max_retry = 255;
180 range->min_rts = 0;
181 range->max_rts = 2347;
182 range->min_frag = 256;
183 range->max_frag = 2346;
184
185 range->encoding_size[0] = 5;
186 range->encoding_size[1] = 13;
187 range->num_encoding_sizes = 2;
188 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
189
Johannes Berg2a519312009-02-10 21:25:55 +0100190 /* cfg80211 requires this, and enforces 0..100 */
Johannes Berg7fee5372009-01-30 11:13:06 +0100191 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
Johannes Berg2a519312009-02-10 21:25:55 +0100192 range->max_qual.level = 100;
Bruno Randolf566bfe52008-05-08 19:15:40 +0200193 else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
194 range->max_qual.level = -110;
195 else
196 range->max_qual.level = 0;
197
198 if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
199 range->max_qual.noise = -110;
200 else
201 range->max_qual.noise = 0;
202
203 range->max_qual.qual = 100;
Johannes Berg9a03d6d2009-02-10 21:26:01 +0100204 range->max_qual.updated = ieee80211_get_wstats_flags(local);
Jiri Bencf0706e82007-05-05 11:45:53 -0700205
Bruno Randolf566bfe52008-05-08 19:15:40 +0200206 range->avg_qual.qual = 50;
207 /* not always true but better than nothing */
208 range->avg_qual.level = range->max_qual.level / 2;
209 range->avg_qual.noise = range->max_qual.noise / 2;
Johannes Berg9a03d6d2009-02-10 21:26:01 +0100210 range->avg_qual.updated = ieee80211_get_wstats_flags(local);
Jiri Bencf0706e82007-05-05 11:45:53 -0700211
212 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
213 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
214
Hong Liu333af2f2007-07-10 19:32:08 +0200215
Johannes Berg8318d782008-01-24 19:38:38 +0100216 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
217 int i;
218 struct ieee80211_supported_band *sband;
219
220 sband = local->hw.wiphy->bands[band];
221
222 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200223 continue;
224
Johannes Berg8318d782008-01-24 19:38:38 +0100225 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
226 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200227
Johannes Berg8318d782008-01-24 19:38:38 +0100228 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
229 range->freq[c].i =
230 ieee80211_frequency_to_channel(
231 chan->center_freq);
232 range->freq[c].m = chan->center_freq;
233 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200234 c++;
235 }
Hong Liu333af2f2007-07-10 19:32:08 +0200236 }
237 }
238 range->num_channels = c;
239 range->num_frequency = c;
240
Jiri Bencf0706e82007-05-05 11:45:53 -0700241 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700242 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
243 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
244
Dan Williams374fdfb2007-12-12 10:25:07 -0500245 range->scan_capa |= IW_SCAN_CAPA_ESSID;
246
Jiri Bencf0706e82007-05-05 11:45:53 -0700247 return 0;
248}
249
250
Jiri Bencf0706e82007-05-05 11:45:53 -0700251static int ieee80211_ioctl_siwfreq(struct net_device *dev,
252 struct iw_request_info *info,
253 struct iw_freq *freq, char *extra)
254{
Jiri Bencf0706e82007-05-05 11:45:53 -0700255 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
256
Johannes Berg46900292009-02-15 12:44:28 +0100257 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
258 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL;
259 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
260 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-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) {
Johannes Berg46900292009-02-15 12:44:28 +0100265 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
266 sdata->u.ibss.flags |=
267 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
268 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
269 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400270 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700271 return 0;
272 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200273 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100274 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700275 } else {
276 int i, div = 1000000;
277 for (i = 0; i < freq->e; i++)
278 div /= 10;
279 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200280 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700281 else
282 return -EINVAL;
283 }
284}
285
286
287static int ieee80211_ioctl_giwfreq(struct net_device *dev,
288 struct iw_request_info *info,
289 struct iw_freq *freq, char *extra)
290{
291 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
292
Johannes Berg8318d782008-01-24 19:38:38 +0100293 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700294 freq->e = 6;
295
296 return 0;
297}
298
299
300static int ieee80211_ioctl_siwessid(struct net_device *dev,
301 struct iw_request_info *info,
302 struct iw_point *data, char *ssid)
303{
Jiri Bencf0706e82007-05-05 11:45:53 -0700304 struct ieee80211_sub_if_data *sdata;
305 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100306 int ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700307
308 /* iwconfig uses nul termination in SSID.. */
309 if (len > 0 && ssid[len - 1] == '\0')
310 len--;
311
312 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100313 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200314 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700315 if (len > IEEE80211_MAX_SSID_LEN)
316 return -EINVAL;
Johannes Berg46900292009-02-15 12:44:28 +0100317 memcpy(sdata->u.mgd.ssid, ssid, len);
318 sdata->u.mgd.ssid_len = len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700319 return 0;
320 }
Johannes Berg46900292009-02-15 12:44:28 +0100321
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400322 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100323 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400324 else
Johannes Berg46900292009-02-15 12:44:28 +0100325 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
326
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200327 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700328 if (ret)
329 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100330
331 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700332 return 0;
Johannes Berg46900292009-02-15 12:44:28 +0100333 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
334 return ieee80211_ibss_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700335
Jiri Bencf0706e82007-05-05 11:45:53 -0700336 return -EOPNOTSUPP;
337}
338
339
340static int ieee80211_ioctl_giwessid(struct net_device *dev,
341 struct iw_request_info *info,
342 struct iw_point *data, char *ssid)
343{
344 size_t len;
345
346 struct ieee80211_sub_if_data *sdata;
347 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100348 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200349 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700350 if (res == 0) {
351 data->length = len;
352 data->flags = 1;
353 } else
354 data->flags = 0;
355 return res;
Johannes Berg46900292009-02-15 12:44:28 +0100356 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
357 int res = ieee80211_ibss_get_ssid(sdata, ssid, &len);
358 if (res == 0) {
359 data->length = len;
360 data->flags = 1;
361 } else
362 data->flags = 0;
363 return res;
Jiri Bencf0706e82007-05-05 11:45:53 -0700364 }
365
Jiri Bencf0706e82007-05-05 11:45:53 -0700366 return -EOPNOTSUPP;
367}
368
369
370static int ieee80211_ioctl_siwap(struct net_device *dev,
371 struct iw_request_info *info,
372 struct sockaddr *ap_addr, char *extra)
373{
Jiri Bencf0706e82007-05-05 11:45:53 -0700374 struct ieee80211_sub_if_data *sdata;
375
376 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100377 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700378 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200379 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Johannes Berg46900292009-02-15 12:44:28 +0100380 memcpy(sdata->u.mgd.bssid, (u8 *) &ap_addr->sa_data,
Jiri Bencf0706e82007-05-05 11:45:53 -0700381 ETH_ALEN);
382 return 0;
383 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400384 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100385 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400386 IEEE80211_STA_AUTO_CHANNEL_SEL;
387 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100388 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700389 else
Johannes Berg46900292009-02-15 12:44:28 +0100390 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200391 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700392 if (ret)
393 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100394 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700395 return 0;
Johannes Berg46900292009-02-15 12:44:28 +0100396 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
397 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
398 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
399 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
400 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
401 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL;
402 else
403 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL;
404
405 return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Johannes Berg05c914f2008-09-11 00:01:58 +0200406 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100407 /*
408 * If it is necessary to update the WDS peer address
409 * while the interface is running, then we need to do
410 * more work here, namely if it is running we need to
411 * add a new and remove the old STA entry, this is
412 * normally handled by _open() and _stop().
413 */
414 if (netif_running(dev))
415 return -EBUSY;
416
417 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
418 ETH_ALEN);
419
420 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700421 }
422
423 return -EOPNOTSUPP;
424}
425
426
427static int ieee80211_ioctl_giwap(struct net_device *dev,
428 struct iw_request_info *info,
429 struct sockaddr *ap_addr, char *extra)
430{
431 struct ieee80211_sub_if_data *sdata;
432
433 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100434 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
435 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700436 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100437 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
438 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700439 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100440 return 0;
441 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
442 if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) {
443 ap_addr->sa_family = ARPHRD_ETHER;
444 memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN);
445 } else
446 memset(&ap_addr->sa_data, 0, ETH_ALEN);
447 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200448 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700449 ap_addr->sa_family = ARPHRD_ETHER;
450 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
451 return 0;
452 }
453
454 return -EOPNOTSUPP;
455}
456
457
Larry Finger1fd5e582007-07-10 19:32:10 +0200458static int ieee80211_ioctl_siwrate(struct net_device *dev,
459 struct iw_request_info *info,
460 struct iw_param *rate, char *extra)
461{
462 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100463 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200464 u32 target_rate = rate->value / 100000;
465 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100466 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200467
468 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100469
470 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
471
Larry Finger1fd5e582007-07-10 19:32:10 +0200472 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
473 * target_rate = X, rate->fixed = 1 means only rate X
474 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200475 sdata->max_ratectrl_rateidx = -1;
476 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200477 if (rate->value < 0)
478 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100479
480 for (i=0; i< sband->n_bitrates; i++) {
481 struct ieee80211_rate *brate = &sband->bitrates[i];
482 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200483
Larry Finger1fd5e582007-07-10 19:32:10 +0200484 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200485 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200486 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200487 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100488 err = 0;
489 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200490 }
491 }
Johannes Berg8318d782008-01-24 19:38:38 +0100492 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200493}
494
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700495static int ieee80211_ioctl_giwrate(struct net_device *dev,
496 struct iw_request_info *info,
497 struct iw_param *rate, char *extra)
498{
499 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
500 struct sta_info *sta;
501 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100502 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700503
504 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100505
Johannes Berg05c914f2008-09-11 00:01:58 +0200506 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700507 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100508
509 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
510
Johannes Berg380a9422008-04-04 23:40:35 +0200511 rcu_read_lock();
512
Johannes Berg46900292009-02-15 12:44:28 +0100513 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200514
Johannes Berge6a98542008-10-21 12:40:02 +0200515 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
516 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700517 else
518 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200519
520 rcu_read_unlock();
521
522 if (!sta)
523 return -ENODEV;
524
Johannes Berg8318d782008-01-24 19:38:38 +0100525 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100526
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700527 return 0;
528}
529
Michael Buesch61609bc2007-09-20 22:06:39 +0200530static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
531 struct iw_request_info *info,
532 union iwreq_data *data, char *extra)
533{
534 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700535 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +0200536 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100537 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200538
539 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
540 return -EINVAL;
541 if (data->txpower.flags & IW_TXPOW_RANGE)
542 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700543 if (!chan)
544 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200545
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700546 if (data->txpower.fixed)
547 new_power_level = min(data->txpower.value, chan->max_power);
548 else /* Automatic power level setting */
Johannes Berg8318d782008-01-24 19:38:38 +0100549 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200550
Johannes Berg2bf30fa2009-01-06 23:23:56 +0100551 local->user_power_level = new_power_level;
Vasanthakumar Thiagarajane3c92df2008-12-24 13:53:11 +0530552 if (local->hw.conf.power_level != new_power_level)
Johannes Berge8975582008-10-09 12:18:51 +0200553 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
Mattias Nissler6a432952007-10-24 23:30:36 +0200554
Michael Buesch61609bc2007-09-20 22:06:39 +0200555 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
556 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200557 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100558 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200559 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200560
Johannes Berge8975582008-10-09 12:18:51 +0200561 if (reconf_flags)
562 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200563
564 return 0;
565}
566
Larry Fingerfe6aa302007-08-10 11:23:20 -0500567static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
568 struct iw_request_info *info,
569 union iwreq_data *data, char *extra)
570{
571 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
572
573 data->txpower.fixed = 1;
574 data->txpower.disabled = !(local->hw.conf.radio_enabled);
575 data->txpower.value = local->hw.conf.power_level;
576 data->txpower.flags = IW_TXPOW_DBM;
577
578 return 0;
579}
580
Jiri Bencf0706e82007-05-05 11:45:53 -0700581static int ieee80211_ioctl_siwrts(struct net_device *dev,
582 struct iw_request_info *info,
583 struct iw_param *rts, char *extra)
584{
585 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
586
587 if (rts->disabled)
588 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300589 else if (!rts->fixed)
590 /* if the rts value is not fixed, then take default */
591 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700592 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
593 return -EINVAL;
594 else
595 local->rts_threshold = rts->value;
596
597 /* If the wlan card performs RTS/CTS in hardware/firmware,
598 * configure it here */
599
600 if (local->ops->set_rts_threshold)
601 local->ops->set_rts_threshold(local_to_hw(local),
602 local->rts_threshold);
603
604 return 0;
605}
606
607static int ieee80211_ioctl_giwrts(struct net_device *dev,
608 struct iw_request_info *info,
609 struct iw_param *rts, char *extra)
610{
611 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
612
613 rts->value = local->rts_threshold;
614 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
615 rts->fixed = 1;
616
617 return 0;
618}
619
620
621static int ieee80211_ioctl_siwfrag(struct net_device *dev,
622 struct iw_request_info *info,
623 struct iw_param *frag, char *extra)
624{
625 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
626
627 if (frag->disabled)
628 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300629 else if (!frag->fixed)
630 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700631 else if (frag->value < 256 ||
632 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
633 return -EINVAL;
634 else {
635 /* Fragment length must be even, so strip LSB. */
636 local->fragmentation_threshold = frag->value & ~0x1;
637 }
638
Jiri Bencf0706e82007-05-05 11:45:53 -0700639 return 0;
640}
641
642static int ieee80211_ioctl_giwfrag(struct net_device *dev,
643 struct iw_request_info *info,
644 struct iw_param *frag, char *extra)
645{
646 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
647
648 frag->value = local->fragmentation_threshold;
649 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
650 frag->fixed = 1;
651
652 return 0;
653}
654
655
656static int ieee80211_ioctl_siwretry(struct net_device *dev,
657 struct iw_request_info *info,
658 struct iw_param *retry, char *extra)
659{
660 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
661
662 if (retry->disabled ||
663 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
664 return -EINVAL;
665
Johannes Berg9124b072008-10-14 19:17:54 +0200666 if (retry->flags & IW_RETRY_MAX) {
667 local->hw.conf.long_frame_max_tx_count = retry->value;
668 } else if (retry->flags & IW_RETRY_MIN) {
669 local->hw.conf.short_frame_max_tx_count = retry->value;
670 } else {
671 local->hw.conf.long_frame_max_tx_count = retry->value;
672 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700673 }
674
Johannes Berg9124b072008-10-14 19:17:54 +0200675 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700676
677 return 0;
678}
679
680
681static int ieee80211_ioctl_giwretry(struct net_device *dev,
682 struct iw_request_info *info,
683 struct iw_param *retry, char *extra)
684{
685 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
686
687 retry->disabled = 0;
688 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
689 /* first return min value, iwconfig will ask max value
690 * later if needed */
691 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200692 retry->value = local->hw.conf.short_frame_max_tx_count;
693 if (local->hw.conf.long_frame_max_tx_count !=
694 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e82007-05-05 11:45:53 -0700695 retry->flags |= IW_RETRY_MIN;
696 return 0;
697 }
698 if (retry->flags & IW_RETRY_MAX) {
699 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200700 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700701 }
702
703 return 0;
704}
705
Jiri Bencf0706e82007-05-05 11:45:53 -0700706static int ieee80211_ioctl_siwmlme(struct net_device *dev,
707 struct iw_request_info *info,
708 struct iw_point *data, char *extra)
709{
710 struct ieee80211_sub_if_data *sdata;
711 struct iw_mlme *mlme = (struct iw_mlme *) extra;
712
713 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100714 if (!(sdata->vif.type == NL80211_IFTYPE_STATION))
Jiri Bencf0706e82007-05-05 11:45:53 -0700715 return -EINVAL;
716
717 switch (mlme->cmd) {
718 case IW_MLME_DEAUTH:
719 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200720 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700721 case IW_MLME_DISASSOC:
722 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200723 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700724 default:
725 return -EOPNOTSUPP;
726 }
727}
728
729
730static int ieee80211_ioctl_siwencode(struct net_device *dev,
731 struct iw_request_info *info,
732 struct iw_point *erq, char *keybuf)
733{
734 struct ieee80211_sub_if_data *sdata;
735 int idx, i, alg = ALG_WEP;
736 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200737 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700738
739 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
740
741 idx = erq->flags & IW_ENCODE_INDEX;
742 if (idx == 0) {
743 if (sdata->default_key)
744 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
745 if (sdata->default_key == sdata->keys[i]) {
746 idx = i;
747 break;
748 }
749 }
750 } else if (idx < 1 || idx > 4)
751 return -EINVAL;
752 else
753 idx--;
754
755 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200756 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700757 else if (erq->length == 0) {
758 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400759 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700760 return 0;
761 }
762
763 return ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200764 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200765 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700766 !sdata->default_key,
767 keybuf, erq->length);
768}
769
770
771static int ieee80211_ioctl_giwencode(struct net_device *dev,
772 struct iw_request_info *info,
773 struct iw_point *erq, char *key)
774{
775 struct ieee80211_sub_if_data *sdata;
776 int idx, i;
777
778 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
779
780 idx = erq->flags & IW_ENCODE_INDEX;
781 if (idx < 1 || idx > 4) {
782 idx = -1;
783 if (!sdata->default_key)
784 idx = 0;
785 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
786 if (sdata->default_key == sdata->keys[i]) {
787 idx = i;
788 break;
789 }
790 }
791 if (idx < 0)
792 return -EINVAL;
793 } else
794 idx--;
795
796 erq->flags = idx + 1;
797
798 if (!sdata->keys[idx]) {
799 erq->length = 0;
800 erq->flags |= IW_ENCODE_DISABLED;
801 return 0;
802 }
803
Johannes Berg8f20fc22007-08-28 17:01:54 -0400804 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400805 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400806 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700807 erq->flags |= IW_ENCODE_ENABLED;
808
Johannes Berg05c914f2008-09-11 00:01:58 +0200809 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berg46900292009-02-15 12:44:28 +0100810 switch (sdata->u.mgd.auth_alg) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300811 case WLAN_AUTH_OPEN:
812 case WLAN_AUTH_LEAP:
813 erq->flags |= IW_ENCODE_OPEN;
814 break;
815 case WLAN_AUTH_SHARED_KEY:
816 erq->flags |= IW_ENCODE_RESTRICTED;
817 break;
818 }
819 }
820
Jiri Bencf0706e82007-05-05 11:45:53 -0700821 return 0;
822}
823
Samuel Ortiz49292d52008-07-04 10:49:31 +0200824static int ieee80211_ioctl_siwpower(struct net_device *dev,
825 struct iw_request_info *info,
826 struct iw_param *wrq,
827 char *extra)
828{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200829 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200830 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
831 struct ieee80211_conf *conf = &local->hw.conf;
Kalle Valo520eb822008-12-18 23:35:27 +0200832 int ret = 0, timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200833 bool ps;
834
Johannes Berg4be8c382009-01-07 18:28:20 +0100835 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
836 return -EOPNOTSUPP;
837
Kalle Valoe0cb6862008-12-18 23:35:13 +0200838 if (sdata->vif.type != NL80211_IFTYPE_STATION)
839 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200840
841 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200842 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200843 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200844 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200845 }
846
847 switch (wrq->flags & IW_POWER_MODE) {
848 case IW_POWER_ON: /* If not specified */
849 case IW_POWER_MODE: /* If set all mask */
850 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200851 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200852 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200853 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100854 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200855 }
856
Johannes Berge9aeaba2009-01-06 18:12:35 +0100857 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
858 return -EINVAL;
859
Kalle Valo520eb822008-12-18 23:35:27 +0200860 if (wrq->flags & IW_POWER_TIMEOUT)
861 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200862
Johannes Berg4be8c382009-01-07 18:28:20 +0100863 set:
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100864 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
Kalle Valo520eb822008-12-18 23:35:27 +0200865 return ret;
866
Kalle Valoe0cb6862008-12-18 23:35:13 +0200867 local->powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100868 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200869
Johannes Berg4be8c382009-01-07 18:28:20 +0100870 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100871 ret = ieee80211_hw_config(local,
872 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
Johannes Berg4be8c382009-01-07 18:28:20 +0100873
Johannes Berg46900292009-02-15 12:44:28 +0100874 if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
Johannes Berg4be8c382009-01-07 18:28:20 +0100875 return ret;
876
877 if (conf->dynamic_ps_timeout > 0 &&
878 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
879 mod_timer(&local->dynamic_ps_timer, jiffies +
880 msecs_to_jiffies(conf->dynamic_ps_timeout));
881 } else {
882 if (local->powersave) {
883 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800884 ieee80211_send_nullfunc(local, sdata, 1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100885 conf->flags |= IEEE80211_CONF_PS;
886 ret = ieee80211_hw_config(local,
887 IEEE80211_CONF_CHANGE_PS);
888 } else {
889 conf->flags &= ~IEEE80211_CONF_PS;
890 ret = ieee80211_hw_config(local,
891 IEEE80211_CONF_CHANGE_PS);
892 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800893 ieee80211_send_nullfunc(local, sdata, 0);
Vivek Natarajanb8abde42009-01-27 19:26:28 +0530894 del_timer_sync(&local->dynamic_ps_timer);
895 cancel_work_sync(&local->dynamic_ps_enable_work);
Kalle Valo520eb822008-12-18 23:35:27 +0200896 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200897 }
898
899 return ret;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200900}
901
902static int ieee80211_ioctl_giwpower(struct net_device *dev,
903 struct iw_request_info *info,
904 union iwreq_data *wrqu,
905 char *extra)
906{
907 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200908
Kalle Valoe0cb6862008-12-18 23:35:13 +0200909 wrqu->power.disabled = !local->powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200910
911 return 0;
912}
913
Jiri Bencf0706e82007-05-05 11:45:53 -0700914static int ieee80211_ioctl_siwauth(struct net_device *dev,
915 struct iw_request_info *info,
916 struct iw_param *data, char *extra)
917{
Jiri Bencf0706e82007-05-05 11:45:53 -0700918 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
919 int ret = 0;
920
921 switch (data->flags & IW_AUTH_INDEX) {
922 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700923 case IW_AUTH_CIPHER_GROUP:
924 case IW_AUTH_WPA_ENABLED:
925 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700926 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200927 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000928 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530929 case IW_AUTH_CIPHER_PAIRWISE:
930 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
931 if (data->value & (IW_AUTH_CIPHER_WEP40 |
932 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100933 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530934 IEEE80211_STA_TKIP_WEP_USED;
935 else
Johannes Berg46900292009-02-15 12:44:28 +0100936 sdata->u.mgd.flags &=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530937 ~IEEE80211_STA_TKIP_WEP_USED;
938 }
939 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100940 case IW_AUTH_DROP_UNENCRYPTED:
941 sdata->drop_unencrypted = !!data->value;
942 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000943 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200944 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700945 ret = -EINVAL;
946 else {
Johannes Berg46900292009-02-15 12:44:28 +0100947 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700948 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000949 * Privacy invoked by wpa_supplicant, store the
950 * value and allow associating to a protected
951 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700952 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000953 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100954 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000955 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700956 }
957 break;
958 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100959 if (sdata->vif.type == NL80211_IFTYPE_STATION)
960 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700961 else
962 ret = -EOPNOTSUPP;
963 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200964 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200965 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
966 ret = -EOPNOTSUPP;
967 break;
968 }
Johannes Berg46900292009-02-15 12:44:28 +0100969 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100970 switch (data->value) {
971 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100972 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100973 break;
974 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100975 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100976 break;
977 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100978 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100979 break;
980 default:
981 ret = -EINVAL;
982 }
983 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200984 ret = -EOPNOTSUPP;
985 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700986 default:
987 ret = -EOPNOTSUPP;
988 break;
989 }
990 return ret;
991}
992
993/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
994static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
995{
996 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
997 struct iw_statistics *wstats = &local->wstats;
998 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
999 struct sta_info *sta = NULL;
1000
Johannes Berg98dd6a52008-04-10 15:36:09 +02001001 rcu_read_lock();
1002
Johannes Berg46900292009-02-15 12:44:28 +01001003 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1004 sta = sta_info_get(local, sdata->u.mgd.bssid);
1005
Jiri Bencf0706e82007-05-05 11:45:53 -07001006 if (!sta) {
1007 wstats->discard.fragment = 0;
1008 wstats->discard.misc = 0;
1009 wstats->qual.qual = 0;
1010 wstats->qual.level = 0;
1011 wstats->qual.noise = 0;
1012 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1013 } else {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001014 wstats->qual.level = sta->last_signal;
1015 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001016 wstats->qual.noise = sta->last_noise;
Johannes Berg9a03d6d2009-02-10 21:26:01 +01001017 wstats->qual.updated = ieee80211_get_wstats_flags(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001018 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001019
1020 rcu_read_unlock();
1021
Jiri Bencf0706e82007-05-05 11:45:53 -07001022 return wstats;
1023}
1024
1025static int ieee80211_ioctl_giwauth(struct net_device *dev,
1026 struct iw_request_info *info,
1027 struct iw_param *data, char *extra)
1028{
1029 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1030 int ret = 0;
1031
1032 switch (data->flags & IW_AUTH_INDEX) {
1033 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +01001034 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1035 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e82007-05-05 11:45:53 -07001036 else
1037 ret = -EOPNOTSUPP;
1038 break;
1039 default:
1040 ret = -EOPNOTSUPP;
1041 break;
1042 }
1043 return ret;
1044}
1045
1046
1047static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1048 struct iw_request_info *info,
1049 struct iw_point *erq, char *extra)
1050{
1051 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1052 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001053 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001054
1055 switch (ext->alg) {
1056 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001057 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001058 break;
1059 case IW_ENCODE_ALG_WEP:
1060 alg = ALG_WEP;
1061 break;
1062 case IW_ENCODE_ALG_TKIP:
1063 alg = ALG_TKIP;
1064 break;
1065 case IW_ENCODE_ALG_CCMP:
1066 alg = ALG_CCMP;
1067 break;
Jouni Malinen22787db2009-01-08 13:32:04 +02001068 case IW_ENCODE_ALG_AES_CMAC:
1069 alg = ALG_AES_CMAC;
1070 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001071 default:
1072 return -EOPNOTSUPP;
1073 }
1074
1075 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001076 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001077
1078 idx = erq->flags & IW_ENCODE_INDEX;
Jouni Malinen22787db2009-01-08 13:32:04 +02001079 if (alg == ALG_AES_CMAC) {
1080 if (idx < NUM_DEFAULT_KEYS + 1 ||
1081 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1082 idx = -1;
1083 if (!sdata->default_mgmt_key)
1084 idx = 0;
1085 else for (i = NUM_DEFAULT_KEYS;
1086 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1087 i++) {
1088 if (sdata->default_mgmt_key == sdata->keys[i])
1089 {
1090 idx = i;
1091 break;
1092 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001093 }
Jouni Malinen22787db2009-01-08 13:32:04 +02001094 if (idx < 0)
1095 return -EINVAL;
1096 } else
1097 idx--;
1098 } else {
1099 if (idx < 1 || idx > 4) {
1100 idx = -1;
1101 if (!sdata->default_key)
1102 idx = 0;
1103 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1104 if (sdata->default_key == sdata->keys[i]) {
1105 idx = i;
1106 break;
1107 }
1108 }
1109 if (idx < 0)
1110 return -EINVAL;
1111 } else
1112 idx--;
1113 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001114
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001115 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001116 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001117 ext->ext_flags &
1118 IW_ENCODE_EXT_SET_TX_KEY,
1119 ext->key, ext->key_len);
1120}
1121
1122
Jiri Bencf0706e82007-05-05 11:45:53 -07001123/* Structures to export the Wireless Handlers */
1124
1125static const iw_handler ieee80211_handler[] =
1126{
1127 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001128 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -07001129 (iw_handler) NULL, /* SIOCSIWNWID */
1130 (iw_handler) NULL, /* SIOCGIWNWID */
1131 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1132 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001133 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1134 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001135 (iw_handler) NULL, /* SIOCSIWSENS */
1136 (iw_handler) NULL, /* SIOCGIWSENS */
1137 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1138 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1139 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1140 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1141 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1142 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001143 (iw_handler) NULL, /* SIOCSIWSPY */
1144 (iw_handler) NULL, /* SIOCGIWSPY */
1145 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1146 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001147 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1148 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1149 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1150 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +01001151 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1152 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e82007-05-05 11:45:53 -07001153 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1154 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1155 (iw_handler) NULL, /* SIOCSIWNICKN */
1156 (iw_handler) NULL, /* SIOCGIWNICKN */
1157 (iw_handler) NULL, /* -- hole -- */
1158 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001159 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001160 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001161 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1162 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1163 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1164 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001165 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001166 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001167 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1168 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1169 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1170 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001171 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1172 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001173 (iw_handler) NULL, /* -- hole -- */
1174 (iw_handler) NULL, /* -- hole -- */
1175 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1176 (iw_handler) NULL, /* SIOCGIWGENIE */
1177 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1178 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1179 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1180 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1181 (iw_handler) NULL, /* SIOCSIWPMKSA */
1182 (iw_handler) NULL, /* -- hole -- */
1183};
1184
Jiri Bencf0706e82007-05-05 11:45:53 -07001185const struct iw_handler_def ieee80211_iw_handler_def =
1186{
1187 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001188 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001189 .get_wireless_stats = ieee80211_get_wireless_stats,
1190};