blob: 896704cf94e13bef7bcd47dbc4fbd117e53f1b97 [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
Johannes Berg46900292009-02-15 12:44:28 +0100132 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200133 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e822007-05-05 11:45:53 -0700134 if (ret)
135 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100136 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200137 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100138 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -0700139 return 0;
140 }
141
Jiri Bencf0706e822007-05-05 11:45:53 -0700142 return -EOPNOTSUPP;
143}
144
Jiri Bencf0706e822007-05-05 11:45:53 -0700145static int ieee80211_ioctl_siwfreq(struct net_device *dev,
146 struct iw_request_info *info,
147 struct iw_freq *freq, char *extra)
148{
Jiri Bencf0706e822007-05-05 11:45:53 -0700149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
150
Johannes Berg46900292009-02-15 12:44:28 +0100151 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
152 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL;
153 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
154 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700155
156 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
157 if (freq->e == 0) {
158 if (freq->m < 0) {
Johannes Berg46900292009-02-15 12:44:28 +0100159 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
160 sdata->u.ibss.flags |=
161 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
162 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
163 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400164 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700165 return 0;
166 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200167 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100168 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e822007-05-05 11:45:53 -0700169 } else {
170 int i, div = 1000000;
171 for (i = 0; i < freq->e; i++)
172 div /= 10;
173 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200174 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e822007-05-05 11:45:53 -0700175 else
176 return -EINVAL;
177 }
178}
179
180
181static int ieee80211_ioctl_giwfreq(struct net_device *dev,
182 struct iw_request_info *info,
183 struct iw_freq *freq, char *extra)
184{
185 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
186
Johannes Berg8318d782008-01-24 19:38:38 +0100187 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e822007-05-05 11:45:53 -0700188 freq->e = 6;
189
190 return 0;
191}
192
193
194static int ieee80211_ioctl_siwessid(struct net_device *dev,
195 struct iw_request_info *info,
196 struct iw_point *data, char *ssid)
197{
Jiri Bencf0706e822007-05-05 11:45:53 -0700198 struct ieee80211_sub_if_data *sdata;
199 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100200 int ret;
Jiri Bencf0706e822007-05-05 11:45:53 -0700201
202 /* iwconfig uses nul termination in SSID.. */
203 if (len > 0 && ssid[len - 1] == '\0')
204 len--;
205
206 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100207 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400208 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100209 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400210 else
Johannes Berg46900292009-02-15 12:44:28 +0100211 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
212
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200213 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700214 if (ret)
215 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100216
Jouni Malinen636a5d32009-03-19 13:39:22 +0200217 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100218 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -0700219 return 0;
Johannes Berg46900292009-02-15 12:44:28 +0100220 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
221 return ieee80211_ibss_set_ssid(sdata, ssid, len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700222
Jiri Bencf0706e822007-05-05 11:45:53 -0700223 return -EOPNOTSUPP;
224}
225
226
227static int ieee80211_ioctl_giwessid(struct net_device *dev,
228 struct iw_request_info *info,
229 struct iw_point *data, char *ssid)
230{
231 size_t len;
232
233 struct ieee80211_sub_if_data *sdata;
234 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100235 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200236 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700237 if (res == 0) {
238 data->length = len;
239 data->flags = 1;
240 } else
241 data->flags = 0;
242 return res;
Johannes Berg46900292009-02-15 12:44:28 +0100243 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
244 int res = ieee80211_ibss_get_ssid(sdata, ssid, &len);
245 if (res == 0) {
246 data->length = len;
247 data->flags = 1;
248 } else
249 data->flags = 0;
250 return res;
Jiri Bencf0706e822007-05-05 11:45:53 -0700251 }
252
Jiri Bencf0706e822007-05-05 11:45:53 -0700253 return -EOPNOTSUPP;
254}
255
256
257static int ieee80211_ioctl_siwap(struct net_device *dev,
258 struct iw_request_info *info,
259 struct sockaddr *ap_addr, char *extra)
260{
Jiri Bencf0706e822007-05-05 11:45:53 -0700261 struct ieee80211_sub_if_data *sdata;
262
263 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100264 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700265 int ret;
Johannes Berg7986cf92009-03-21 17:08:43 +0100266
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400267 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100268 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400269 IEEE80211_STA_AUTO_CHANNEL_SEL;
270 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100271 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700272 else
Johannes Berg46900292009-02-15 12:44:28 +0100273 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200274 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e822007-05-05 11:45:53 -0700275 if (ret)
276 return ret;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200277 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100278 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -0700279 return 0;
Johannes Berg46900292009-02-15 12:44:28 +0100280 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
281 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
282 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
283 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
284 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
285 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL;
286 else
287 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL;
288
289 return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Johannes Berg05c914f2008-09-11 00:01:58 +0200290 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100291 /*
292 * If it is necessary to update the WDS peer address
293 * while the interface is running, then we need to do
294 * more work here, namely if it is running we need to
295 * add a new and remove the old STA entry, this is
296 * normally handled by _open() and _stop().
297 */
298 if (netif_running(dev))
299 return -EBUSY;
300
301 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
302 ETH_ALEN);
303
304 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700305 }
306
307 return -EOPNOTSUPP;
308}
309
310
311static int ieee80211_ioctl_giwap(struct net_device *dev,
312 struct iw_request_info *info,
313 struct sockaddr *ap_addr, char *extra)
314{
315 struct ieee80211_sub_if_data *sdata;
316
317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg46900292009-02-15 12:44:28 +0100318 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
319 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700320 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100321 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
322 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700323 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100324 return 0;
325 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
326 if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) {
327 ap_addr->sa_family = ARPHRD_ETHER;
328 memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN);
329 } else
330 memset(&ap_addr->sa_data, 0, ETH_ALEN);
331 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200332 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700333 ap_addr->sa_family = ARPHRD_ETHER;
334 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
335 return 0;
336 }
337
338 return -EOPNOTSUPP;
339}
340
341
Larry Finger1fd5e582007-07-10 19:32:10 +0200342static int ieee80211_ioctl_siwrate(struct net_device *dev,
343 struct iw_request_info *info,
344 struct iw_param *rate, char *extra)
345{
346 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100347 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200348 u32 target_rate = rate->value / 100000;
349 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100350 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200351
352 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100353
354 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
355
Larry Finger1fd5e582007-07-10 19:32:10 +0200356 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
357 * target_rate = X, rate->fixed = 1 means only rate X
358 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200359 sdata->max_ratectrl_rateidx = -1;
360 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200361 if (rate->value < 0)
362 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100363
364 for (i=0; i< sband->n_bitrates; i++) {
365 struct ieee80211_rate *brate = &sband->bitrates[i];
366 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200367
Larry Finger1fd5e582007-07-10 19:32:10 +0200368 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200369 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200370 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200371 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100372 err = 0;
373 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200374 }
375 }
Johannes Berg8318d782008-01-24 19:38:38 +0100376 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200377}
378
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700379static int ieee80211_ioctl_giwrate(struct net_device *dev,
380 struct iw_request_info *info,
381 struct iw_param *rate, char *extra)
382{
383 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
384 struct sta_info *sta;
385 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100386 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700387
388 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100389
Johannes Berg05c914f2008-09-11 00:01:58 +0200390 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700391 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100392
393 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
394
Johannes Berg380a9422008-04-04 23:40:35 +0200395 rcu_read_lock();
396
Johannes Berg46900292009-02-15 12:44:28 +0100397 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200398
Johannes Berge6a98542008-10-21 12:40:02 +0200399 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
400 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700401 else
402 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200403
404 rcu_read_unlock();
405
406 if (!sta)
407 return -ENODEV;
408
Johannes Berg8318d782008-01-24 19:38:38 +0100409 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100410
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700411 return 0;
412}
413
Michael Buesch61609bc2007-09-20 22:06:39 +0200414static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
415 struct iw_request_info *info,
416 union iwreq_data *data, char *extra)
417{
418 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700419 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berg47afbaf2009-04-07 15:22:28 +0200420 bool reconf = false;
Johannes Berge8975582008-10-09 12:18:51 +0200421 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100422 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200423
424 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
425 return -EINVAL;
426 if (data->txpower.flags & IW_TXPOW_RANGE)
427 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700428 if (!chan)
429 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200430
Johannes Berg47afbaf2009-04-07 15:22:28 +0200431 /* only change when not disabling */
432 if (!data->txpower.disabled) {
433 if (data->txpower.fixed) {
434 if (data->txpower.value < 0)
435 return -EINVAL;
436 new_power_level = data->txpower.value;
437 /*
438 * Debatable, but we cannot do a fixed power
439 * level above the regulatory constraint.
440 * Use "iwconfig wlan0 txpower 15dBm" instead.
441 */
442 if (new_power_level > chan->max_power)
443 return -EINVAL;
444 } else {
445 /*
446 * Automatic power level setting, max being the value
447 * passed in from userland.
448 */
449 if (data->txpower.value < 0)
450 new_power_level = -1;
451 else
452 new_power_level = data->txpower.value;
453 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200454
Johannes Berg47afbaf2009-04-07 15:22:28 +0200455 reconf = true;
456
457 /*
458 * ieee80211_hw_config() will limit to the channel's
459 * max power and possibly power constraint from AP.
460 */
461 local->user_power_level = new_power_level;
462 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200463
Michael Buesch61609bc2007-09-20 22:06:39 +0200464 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
465 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200466 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100467 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200468 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200469
Johannes Berg47afbaf2009-04-07 15:22:28 +0200470 if (reconf || reconf_flags)
Johannes Berge8975582008-10-09 12:18:51 +0200471 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200472
473 return 0;
474}
475
Larry Fingerfe6aa302007-08-10 11:23:20 -0500476static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
477 struct iw_request_info *info,
478 union iwreq_data *data, char *extra)
479{
480 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
481
482 data->txpower.fixed = 1;
483 data->txpower.disabled = !(local->hw.conf.radio_enabled);
484 data->txpower.value = local->hw.conf.power_level;
485 data->txpower.flags = IW_TXPOW_DBM;
486
487 return 0;
488}
489
Jiri Bencf0706e822007-05-05 11:45:53 -0700490static int ieee80211_ioctl_siwrts(struct net_device *dev,
491 struct iw_request_info *info,
492 struct iw_param *rts, char *extra)
493{
494 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
495
496 if (rts->disabled)
497 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300498 else if (!rts->fixed)
499 /* if the rts value is not fixed, then take default */
500 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e822007-05-05 11:45:53 -0700501 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
502 return -EINVAL;
503 else
504 local->rts_threshold = rts->value;
505
506 /* If the wlan card performs RTS/CTS in hardware/firmware,
507 * configure it here */
508
509 if (local->ops->set_rts_threshold)
510 local->ops->set_rts_threshold(local_to_hw(local),
511 local->rts_threshold);
512
513 return 0;
514}
515
516static int ieee80211_ioctl_giwrts(struct net_device *dev,
517 struct iw_request_info *info,
518 struct iw_param *rts, char *extra)
519{
520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
521
522 rts->value = local->rts_threshold;
523 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
524 rts->fixed = 1;
525
526 return 0;
527}
528
529
530static int ieee80211_ioctl_siwfrag(struct net_device *dev,
531 struct iw_request_info *info,
532 struct iw_param *frag, char *extra)
533{
534 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
535
536 if (frag->disabled)
537 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300538 else if (!frag->fixed)
539 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e822007-05-05 11:45:53 -0700540 else if (frag->value < 256 ||
541 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
542 return -EINVAL;
543 else {
544 /* Fragment length must be even, so strip LSB. */
545 local->fragmentation_threshold = frag->value & ~0x1;
546 }
547
Jiri Bencf0706e822007-05-05 11:45:53 -0700548 return 0;
549}
550
551static int ieee80211_ioctl_giwfrag(struct net_device *dev,
552 struct iw_request_info *info,
553 struct iw_param *frag, char *extra)
554{
555 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
556
557 frag->value = local->fragmentation_threshold;
Gerrit Renker23a99842009-04-14 06:32:56 +0200558 frag->disabled = (frag->value >= IEEE80211_MAX_FRAG_THRESHOLD);
Jiri Bencf0706e822007-05-05 11:45:53 -0700559 frag->fixed = 1;
560
561 return 0;
562}
563
564
565static int ieee80211_ioctl_siwretry(struct net_device *dev,
566 struct iw_request_info *info,
567 struct iw_param *retry, char *extra)
568{
569 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
570
571 if (retry->disabled ||
572 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
573 return -EINVAL;
574
Johannes Berg9124b072008-10-14 19:17:54 +0200575 if (retry->flags & IW_RETRY_MAX) {
576 local->hw.conf.long_frame_max_tx_count = retry->value;
577 } else if (retry->flags & IW_RETRY_MIN) {
578 local->hw.conf.short_frame_max_tx_count = retry->value;
579 } else {
580 local->hw.conf.long_frame_max_tx_count = retry->value;
581 local->hw.conf.short_frame_max_tx_count = retry->value;
Jiri Bencf0706e822007-05-05 11:45:53 -0700582 }
583
Johannes Berg9124b072008-10-14 19:17:54 +0200584 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
Jiri Bencf0706e822007-05-05 11:45:53 -0700585
586 return 0;
587}
588
589
590static int ieee80211_ioctl_giwretry(struct net_device *dev,
591 struct iw_request_info *info,
592 struct iw_param *retry, char *extra)
593{
594 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
595
596 retry->disabled = 0;
597 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
598 /* first return min value, iwconfig will ask max value
599 * later if needed */
600 retry->flags |= IW_RETRY_LIMIT;
Johannes Berg9124b072008-10-14 19:17:54 +0200601 retry->value = local->hw.conf.short_frame_max_tx_count;
602 if (local->hw.conf.long_frame_max_tx_count !=
603 local->hw.conf.short_frame_max_tx_count)
Jiri Bencf0706e822007-05-05 11:45:53 -0700604 retry->flags |= IW_RETRY_MIN;
605 return 0;
606 }
607 if (retry->flags & IW_RETRY_MAX) {
608 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
Johannes Berg9124b072008-10-14 19:17:54 +0200609 retry->value = local->hw.conf.long_frame_max_tx_count;
Jiri Bencf0706e822007-05-05 11:45:53 -0700610 }
611
612 return 0;
613}
614
Jiri Bencf0706e822007-05-05 11:45:53 -0700615
616static int ieee80211_ioctl_siwencode(struct net_device *dev,
617 struct iw_request_info *info,
618 struct iw_point *erq, char *keybuf)
619{
620 struct ieee80211_sub_if_data *sdata;
621 int idx, i, alg = ALG_WEP;
622 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530623 int remove = 0, ret;
Jiri Bencf0706e822007-05-05 11:45:53 -0700624
625 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
626
627 idx = erq->flags & IW_ENCODE_INDEX;
628 if (idx == 0) {
629 if (sdata->default_key)
630 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
631 if (sdata->default_key == sdata->keys[i]) {
632 idx = i;
633 break;
634 }
635 }
636 } else if (idx < 1 || idx > 4)
637 return -EINVAL;
638 else
639 idx--;
640
641 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200642 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -0700643 else if (erq->length == 0) {
644 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400645 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e822007-05-05 11:45:53 -0700646 return 0;
647 }
648
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530649 ret = ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200650 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200651 idx, alg, remove,
Jiri Bencf0706e822007-05-05 11:45:53 -0700652 !sdata->default_key,
653 keybuf, erq->length);
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530654
Vasanthakumar Thiagarajanb0741a12009-03-27 13:08:45 +0530655 if (!ret && sdata->vif.type == NL80211_IFTYPE_STATION) {
Vasanthakumar Thiagarajanec304152009-03-13 20:26:52 +0530656 if (remove)
657 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
658 else
659 sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
660 }
661
662 return ret;
Jiri Bencf0706e822007-05-05 11:45:53 -0700663}
664
665
666static int ieee80211_ioctl_giwencode(struct net_device *dev,
667 struct iw_request_info *info,
668 struct iw_point *erq, char *key)
669{
670 struct ieee80211_sub_if_data *sdata;
671 int idx, i;
672
673 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
674
675 idx = erq->flags & IW_ENCODE_INDEX;
676 if (idx < 1 || idx > 4) {
677 idx = -1;
678 if (!sdata->default_key)
679 idx = 0;
680 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
681 if (sdata->default_key == sdata->keys[i]) {
682 idx = i;
683 break;
684 }
685 }
686 if (idx < 0)
687 return -EINVAL;
688 } else
689 idx--;
690
691 erq->flags = idx + 1;
692
693 if (!sdata->keys[idx]) {
694 erq->length = 0;
695 erq->flags |= IW_ENCODE_DISABLED;
696 return 0;
697 }
698
Johannes Berg8f20fc22007-08-28 17:01:54 -0400699 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400700 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400701 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e822007-05-05 11:45:53 -0700702 erq->flags |= IW_ENCODE_ENABLED;
703
Johannes Berg05c914f2008-09-11 00:01:58 +0200704 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berg46900292009-02-15 12:44:28 +0100705 switch (sdata->u.mgd.auth_alg) {
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300706 case WLAN_AUTH_OPEN:
707 case WLAN_AUTH_LEAP:
708 erq->flags |= IW_ENCODE_OPEN;
709 break;
710 case WLAN_AUTH_SHARED_KEY:
711 erq->flags |= IW_ENCODE_RESTRICTED;
712 break;
713 }
714 }
715
Jiri Bencf0706e822007-05-05 11:45:53 -0700716 return 0;
717}
718
Samuel Ortiz49292d52008-07-04 10:49:31 +0200719static int ieee80211_ioctl_siwpower(struct net_device *dev,
720 struct iw_request_info *info,
721 struct iw_param *wrq,
722 char *extra)
723{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200724 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200725 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
726 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg965beda2009-04-16 13:17:24 +0200727 int timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200728 bool ps;
729
Johannes Berg4be8c382009-01-07 18:28:20 +0100730 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
731 return -EOPNOTSUPP;
732
Kalle Valoe0cb6862008-12-18 23:35:13 +0200733 if (sdata->vif.type != NL80211_IFTYPE_STATION)
734 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200735
736 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200737 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200738 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200739 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200740 }
741
742 switch (wrq->flags & IW_POWER_MODE) {
743 case IW_POWER_ON: /* If not specified */
744 case IW_POWER_MODE: /* If set all mask */
745 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200746 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200747 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200748 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100749 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200750 }
751
Johannes Berge9aeaba2009-01-06 18:12:35 +0100752 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
753 return -EINVAL;
754
Kalle Valo520eb822008-12-18 23:35:27 +0200755 if (wrq->flags & IW_POWER_TIMEOUT)
756 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200757
Johannes Berg4be8c382009-01-07 18:28:20 +0100758 set:
Johannes Berg965beda2009-04-16 13:17:24 +0200759 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
760 return 0;
Kalle Valo520eb822008-12-18 23:35:27 +0200761
Johannes Berg965beda2009-04-16 13:17:24 +0200762 sdata->u.mgd.powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100763 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200764
Johannes Berg4be8c382009-01-07 18:28:20 +0100765 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berg965beda2009-04-16 13:17:24 +0200766 ieee80211_hw_config(local,
767 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
Johannes Berg4be8c382009-01-07 18:28:20 +0100768
Johannes Berg10f644a2009-04-16 13:17:25 +0200769 ieee80211_recalc_ps(local, -1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100770
Johannes Berg965beda2009-04-16 13:17:24 +0200771 return 0;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200772}
773
774static int ieee80211_ioctl_giwpower(struct net_device *dev,
775 struct iw_request_info *info,
776 union iwreq_data *wrqu,
777 char *extra)
778{
Johannes Berg965beda2009-04-16 13:17:24 +0200779 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200780
Johannes Berg965beda2009-04-16 13:17:24 +0200781 wrqu->power.disabled = !sdata->u.mgd.powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200782
783 return 0;
784}
785
Jiri Bencf0706e822007-05-05 11:45:53 -0700786static int ieee80211_ioctl_siwauth(struct net_device *dev,
787 struct iw_request_info *info,
788 struct iw_param *data, char *extra)
789{
Jiri Bencf0706e822007-05-05 11:45:53 -0700790 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
791 int ret = 0;
792
793 switch (data->flags & IW_AUTH_INDEX) {
794 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e822007-05-05 11:45:53 -0700795 case IW_AUTH_CIPHER_GROUP:
796 case IW_AUTH_WPA_ENABLED:
797 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e822007-05-05 11:45:53 -0700798 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200799 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000800 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530801 case IW_AUTH_CIPHER_PAIRWISE:
802 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
803 if (data->value & (IW_AUTH_CIPHER_WEP40 |
804 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100805 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530806 IEEE80211_STA_TKIP_WEP_USED;
807 else
Johannes Berg46900292009-02-15 12:44:28 +0100808 sdata->u.mgd.flags &=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530809 ~IEEE80211_STA_TKIP_WEP_USED;
810 }
811 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100812 case IW_AUTH_DROP_UNENCRYPTED:
813 sdata->drop_unencrypted = !!data->value;
814 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000815 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200816 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e822007-05-05 11:45:53 -0700817 ret = -EINVAL;
818 else {
Johannes Berg46900292009-02-15 12:44:28 +0100819 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e822007-05-05 11:45:53 -0700820 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000821 * Privacy invoked by wpa_supplicant, store the
822 * value and allow associating to a protected
823 * network without having a key up front.
Jiri Bencf0706e822007-05-05 11:45:53 -0700824 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000825 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100826 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000827 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e822007-05-05 11:45:53 -0700828 }
829 break;
830 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100831 if (sdata->vif.type == NL80211_IFTYPE_STATION)
832 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e822007-05-05 11:45:53 -0700833 else
834 ret = -EOPNOTSUPP;
835 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200836 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200837 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
838 ret = -EOPNOTSUPP;
839 break;
840 }
Johannes Berg46900292009-02-15 12:44:28 +0100841 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100842 switch (data->value) {
843 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100844 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100845 break;
846 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100847 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100848 break;
849 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100850 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100851 break;
852 default:
853 ret = -EINVAL;
854 }
855 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200856 ret = -EOPNOTSUPP;
857 break;
Jiri Bencf0706e822007-05-05 11:45:53 -0700858 default:
859 ret = -EOPNOTSUPP;
860 break;
861 }
862 return ret;
863}
864
865/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
866static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
867{
868 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
869 struct iw_statistics *wstats = &local->wstats;
870 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
871 struct sta_info *sta = NULL;
872
Johannes Berg98dd6a52008-04-10 15:36:09 +0200873 rcu_read_lock();
874
Johannes Berg46900292009-02-15 12:44:28 +0100875 if (sdata->vif.type == NL80211_IFTYPE_STATION)
876 sta = sta_info_get(local, sdata->u.mgd.bssid);
877
Jiri Bencf0706e822007-05-05 11:45:53 -0700878 if (!sta) {
879 wstats->discard.fragment = 0;
880 wstats->discard.misc = 0;
881 wstats->qual.qual = 0;
882 wstats->qual.level = 0;
883 wstats->qual.noise = 0;
884 wstats->qual.updated = IW_QUAL_ALL_INVALID;
885 } else {
Johannes Berg24776cf2009-02-27 16:33:55 -0600886 wstats->qual.updated = 0;
887 /*
888 * mirror what cfg80211 does for iwrange/scan results,
889 * otherwise userspace gets confused.
890 */
891 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
892 IEEE80211_HW_SIGNAL_DBM)) {
893 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
894 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
895 } else {
896 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
897 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
898 }
899
900 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
901 wstats->qual.level = sta->last_signal;
902 wstats->qual.qual = sta->last_signal;
903 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
904 int sig = sta->last_signal;
905
906 wstats->qual.updated |= IW_QUAL_DBM;
907 wstats->qual.level = sig;
908 if (sig < -110)
909 sig = -110;
910 else if (sig > -40)
911 sig = -40;
912 wstats->qual.qual = sig + 110;
913 }
914
915 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
916 /*
917 * This assumes that if driver reports noise, it also
918 * reports signal in dBm.
919 */
920 wstats->qual.noise = sta->last_noise;
921 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
922 } else {
923 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
924 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700925 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200926
927 rcu_read_unlock();
928
Jiri Bencf0706e822007-05-05 11:45:53 -0700929 return wstats;
930}
931
932static int ieee80211_ioctl_giwauth(struct net_device *dev,
933 struct iw_request_info *info,
934 struct iw_param *data, char *extra)
935{
936 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
937 int ret = 0;
938
939 switch (data->flags & IW_AUTH_INDEX) {
940 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100941 if (sdata->vif.type == NL80211_IFTYPE_STATION)
942 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e822007-05-05 11:45:53 -0700943 else
944 ret = -EOPNOTSUPP;
945 break;
946 default:
947 ret = -EOPNOTSUPP;
948 break;
949 }
950 return ret;
951}
952
953
954static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
955 struct iw_request_info *info,
956 struct iw_point *erq, char *extra)
957{
958 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
959 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +0200960 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700961
962 switch (ext->alg) {
963 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +0200964 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -0700965 break;
966 case IW_ENCODE_ALG_WEP:
967 alg = ALG_WEP;
968 break;
969 case IW_ENCODE_ALG_TKIP:
970 alg = ALG_TKIP;
971 break;
972 case IW_ENCODE_ALG_CCMP:
973 alg = ALG_CCMP;
974 break;
Jouni Malinen22787db2009-01-08 13:32:04 +0200975 case IW_ENCODE_ALG_AES_CMAC:
976 alg = ALG_AES_CMAC;
977 break;
Jiri Bencf0706e822007-05-05 11:45:53 -0700978 default:
979 return -EOPNOTSUPP;
980 }
981
982 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200983 remove = 1;
Jiri Bencf0706e822007-05-05 11:45:53 -0700984
985 idx = erq->flags & IW_ENCODE_INDEX;
Jouni Malinen22787db2009-01-08 13:32:04 +0200986 if (alg == ALG_AES_CMAC) {
987 if (idx < NUM_DEFAULT_KEYS + 1 ||
988 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
989 idx = -1;
990 if (!sdata->default_mgmt_key)
991 idx = 0;
992 else for (i = NUM_DEFAULT_KEYS;
993 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
994 i++) {
995 if (sdata->default_mgmt_key == sdata->keys[i])
996 {
997 idx = i;
998 break;
999 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001000 }
Jouni Malinen22787db2009-01-08 13:32:04 +02001001 if (idx < 0)
1002 return -EINVAL;
1003 } else
1004 idx--;
1005 } else {
1006 if (idx < 1 || idx > 4) {
1007 idx = -1;
1008 if (!sdata->default_key)
1009 idx = 0;
1010 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1011 if (sdata->default_key == sdata->keys[i]) {
1012 idx = i;
1013 break;
1014 }
1015 }
1016 if (idx < 0)
1017 return -EINVAL;
1018 } else
1019 idx--;
1020 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001021
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001022 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001023 remove,
Jiri Bencf0706e822007-05-05 11:45:53 -07001024 ext->ext_flags &
1025 IW_ENCODE_EXT_SET_TX_KEY,
1026 ext->key, ext->key_len);
1027}
1028
1029
Jiri Bencf0706e822007-05-05 11:45:53 -07001030/* Structures to export the Wireless Handlers */
1031
1032static const iw_handler ieee80211_handler[] =
1033{
1034 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +01001035 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e822007-05-05 11:45:53 -07001036 (iw_handler) NULL, /* SIOCSIWNWID */
1037 (iw_handler) NULL, /* SIOCGIWNWID */
1038 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1039 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +01001040 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1041 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e822007-05-05 11:45:53 -07001042 (iw_handler) NULL, /* SIOCSIWSENS */
1043 (iw_handler) NULL, /* SIOCGIWSENS */
1044 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
Johannes Berg4aa188e2009-02-18 19:32:08 +01001045 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
Jiri Bencf0706e822007-05-05 11:45:53 -07001046 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1047 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1048 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1049 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001050 (iw_handler) NULL, /* SIOCSIWSPY */
1051 (iw_handler) NULL, /* SIOCGIWSPY */
1052 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1053 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e822007-05-05 11:45:53 -07001054 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1055 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
Johannes Berg691597c2009-04-19 19:57:45 +02001056 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
Jiri Bencf0706e822007-05-05 11:45:53 -07001057 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +01001058 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1059 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e822007-05-05 11:45:53 -07001060 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1061 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1062 (iw_handler) NULL, /* SIOCSIWNICKN */
1063 (iw_handler) NULL, /* SIOCGIWNICKN */
1064 (iw_handler) NULL, /* -- hole -- */
1065 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001066 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001067 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e822007-05-05 11:45:53 -07001068 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1069 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1070 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1071 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001072 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001073 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e822007-05-05 11:45:53 -07001074 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1075 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1076 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1077 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001078 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1079 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e822007-05-05 11:45:53 -07001080 (iw_handler) NULL, /* -- hole -- */
1081 (iw_handler) NULL, /* -- hole -- */
1082 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1083 (iw_handler) NULL, /* SIOCGIWGENIE */
1084 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1085 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1086 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1087 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1088 (iw_handler) NULL, /* SIOCSIWPMKSA */
1089 (iw_handler) NULL, /* -- hole -- */
1090};
1091
Jiri Bencf0706e822007-05-05 11:45:53 -07001092const struct iw_handler_def ieee80211_iw_handler_def =
1093{
1094 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e822007-05-05 11:45:53 -07001095 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e822007-05-05 11:45:53 -07001096 .get_wireless_stats = ieee80211_get_wireless_stats,
1097};