blob: c14394744a9c321b3a2b73d26d448c8bd7242361 [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
Jiri Bencf0706e82007-05-05 11:45:53 -070030static int ieee80211_ioctl_siwgenie(struct net_device *dev,
31 struct iw_request_info *info,
32 struct iw_point *data, char *extra)
33{
34 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -070035
36 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +020037
Johannes Berg46900292009-02-15 12:44:28 +010038 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120039 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -070040 if (ret)
41 return ret;
Johannes Berg46900292009-02-15 12:44:28 +010042 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jouni Malinen636a5d32009-03-19 13:39:22 +020043 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Jouni Malinen3f77316c2009-05-11 21:57:57 +030044 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
Johannes Berg46900292009-02-15 12:44:28 +010045 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -070046 return 0;
47 }
48
Jiri Bencf0706e82007-05-05 11:45:53 -070049 return -EOPNOTSUPP;
50}
51
Jiri Bencf0706e82007-05-05 11:45:53 -070052static int ieee80211_ioctl_siwfreq(struct net_device *dev,
53 struct iw_request_info *info,
54 struct iw_freq *freq, char *extra)
55{
Jiri Bencf0706e82007-05-05 11:45:53 -070056 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
57
Johannes Berg46900292009-02-15 12:44:28 +010058 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020059 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
Johannes Berg46900292009-02-15 12:44:28 +010060 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
61 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -070062
63 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
64 if (freq->e == 0) {
65 if (freq->m < 0) {
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020066 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Johannes Berg46900292009-02-15 12:44:28 +010067 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -040068 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -070069 return 0;
70 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120071 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +010072 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -070073 } else {
74 int i, div = 1000000;
75 for (i = 0; i < freq->e; i++)
76 div /= 10;
77 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120078 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -070079 else
80 return -EINVAL;
81 }
82}
83
84
85static int ieee80211_ioctl_giwfreq(struct net_device *dev,
86 struct iw_request_info *info,
87 struct iw_freq *freq, char *extra)
88{
89 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020090 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
91
92 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
93 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
Jiri Bencf0706e82007-05-05 11:45:53 -070094
Johannes Berg77382312009-05-04 17:52:10 +020095 freq->m = local->oper_channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -070096 freq->e = 6;
97
98 return 0;
99}
100
101
102static int ieee80211_ioctl_siwessid(struct net_device *dev,
103 struct iw_request_info *info,
104 struct iw_point *data, char *ssid)
105{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200106 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700107 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100108 int ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700109
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200110 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
111 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
112
Jiri Bencf0706e82007-05-05 11:45:53 -0700113 /* iwconfig uses nul termination in SSID.. */
114 if (len > 0 && ssid[len - 1] == '\0')
115 len--;
116
Johannes Berg46900292009-02-15 12:44:28 +0100117 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400118 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100119 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400120 else
Johannes Berg46900292009-02-15 12:44:28 +0100121 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
122
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200123 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700124 if (ret)
125 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100126
Jouni Malinen636a5d32009-03-19 13:39:22 +0200127 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300128 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
Johannes Berg46900292009-02-15 12:44:28 +0100129 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700130 return 0;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200131 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700132
Jiri Bencf0706e82007-05-05 11:45:53 -0700133 return -EOPNOTSUPP;
134}
135
136
137static int ieee80211_ioctl_giwessid(struct net_device *dev,
138 struct iw_request_info *info,
139 struct iw_point *data, char *ssid)
140{
141 size_t len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700142 struct ieee80211_sub_if_data *sdata;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200143
Jiri Bencf0706e82007-05-05 11:45:53 -0700144 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200145
146 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
147 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
148
Johannes Berg46900292009-02-15 12:44:28 +0100149 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200150 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700151 if (res == 0) {
152 data->length = len;
153 data->flags = 1;
154 } else
155 data->flags = 0;
156 return res;
157 }
158
Jiri Bencf0706e82007-05-05 11:45:53 -0700159 return -EOPNOTSUPP;
160}
161
162
163static int ieee80211_ioctl_siwap(struct net_device *dev,
164 struct iw_request_info *info,
165 struct sockaddr *ap_addr, char *extra)
166{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200167 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700168
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200169 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
170 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
171
Johannes Berg46900292009-02-15 12:44:28 +0100172 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700173 int ret;
Johannes Berg7986cf92009-03-21 17:08:43 +0100174
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400175 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100176 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400177 IEEE80211_STA_AUTO_CHANNEL_SEL;
178 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100179 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700180 else
Johannes Berg46900292009-02-15 12:44:28 +0100181 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200182 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700183 if (ret)
184 return ret;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200185 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300186 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
Johannes Berg46900292009-02-15 12:44:28 +0100187 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700188 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200189 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100190 /*
191 * If it is necessary to update the WDS peer address
192 * while the interface is running, then we need to do
193 * more work here, namely if it is running we need to
194 * add a new and remove the old STA entry, this is
195 * normally handled by _open() and _stop().
196 */
197 if (netif_running(dev))
198 return -EBUSY;
199
200 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
201 ETH_ALEN);
202
203 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700204 }
205
206 return -EOPNOTSUPP;
207}
208
209
210static int ieee80211_ioctl_giwap(struct net_device *dev,
211 struct iw_request_info *info,
212 struct sockaddr *ap_addr, char *extra)
213{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200214 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700215
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200216 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
217 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
218
Johannes Berg46900292009-02-15 12:44:28 +0100219 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
220 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700221 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100222 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
223 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700224 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100225 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200226 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700227 ap_addr->sa_family = ARPHRD_ETHER;
228 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
229 return 0;
230 }
231
232 return -EOPNOTSUPP;
233}
234
235
Larry Finger1fd5e582007-07-10 19:32:10 +0200236static int ieee80211_ioctl_siwrate(struct net_device *dev,
237 struct iw_request_info *info,
238 struct iw_param *rate, char *extra)
239{
240 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100241 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200242 u32 target_rate = rate->value / 100000;
243 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100244 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200245
246 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100247
248 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
249
Larry Finger1fd5e582007-07-10 19:32:10 +0200250 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
251 * target_rate = X, rate->fixed = 1 means only rate X
252 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200253 sdata->max_ratectrl_rateidx = -1;
254 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200255 if (rate->value < 0)
256 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100257
258 for (i=0; i< sband->n_bitrates; i++) {
259 struct ieee80211_rate *brate = &sband->bitrates[i];
260 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200261
Larry Finger1fd5e582007-07-10 19:32:10 +0200262 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200263 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200264 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200265 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100266 err = 0;
267 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200268 }
269 }
Johannes Berg8318d782008-01-24 19:38:38 +0100270 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200271}
272
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700273static int ieee80211_ioctl_giwrate(struct net_device *dev,
274 struct iw_request_info *info,
275 struct iw_param *rate, char *extra)
276{
277 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
278 struct sta_info *sta;
279 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100280 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700281
282 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100283
Johannes Berg05c914f2008-09-11 00:01:58 +0200284 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700285 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100286
287 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
288
Johannes Berg380a9422008-04-04 23:40:35 +0200289 rcu_read_lock();
290
Johannes Berg46900292009-02-15 12:44:28 +0100291 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200292
Johannes Berge6a98542008-10-21 12:40:02 +0200293 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
294 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700295 else
296 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200297
298 rcu_read_unlock();
299
300 if (!sta)
301 return -ENODEV;
302
Johannes Berg8318d782008-01-24 19:38:38 +0100303 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100304
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700305 return 0;
306}
307
Michael Buesch61609bc2007-09-20 22:06:39 +0200308static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
309 struct iw_request_info *info,
310 union iwreq_data *data, char *extra)
311{
312 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700313 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berg47afbaf2009-04-07 15:22:28 +0200314 bool reconf = false;
Johannes Berge8975582008-10-09 12:18:51 +0200315 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100316 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200317
318 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
319 return -EINVAL;
320 if (data->txpower.flags & IW_TXPOW_RANGE)
321 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700322 if (!chan)
323 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200324
Johannes Berg47afbaf2009-04-07 15:22:28 +0200325 /* only change when not disabling */
326 if (!data->txpower.disabled) {
327 if (data->txpower.fixed) {
328 if (data->txpower.value < 0)
329 return -EINVAL;
330 new_power_level = data->txpower.value;
331 /*
332 * Debatable, but we cannot do a fixed power
333 * level above the regulatory constraint.
334 * Use "iwconfig wlan0 txpower 15dBm" instead.
335 */
336 if (new_power_level > chan->max_power)
337 return -EINVAL;
338 } else {
339 /*
340 * Automatic power level setting, max being the value
341 * passed in from userland.
342 */
343 if (data->txpower.value < 0)
344 new_power_level = -1;
345 else
346 new_power_level = data->txpower.value;
347 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200348
Johannes Berg47afbaf2009-04-07 15:22:28 +0200349 reconf = true;
350
351 /*
352 * ieee80211_hw_config() will limit to the channel's
353 * max power and possibly power constraint from AP.
354 */
355 local->user_power_level = new_power_level;
356 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200357
Michael Buesch61609bc2007-09-20 22:06:39 +0200358 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
359 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200360 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100361 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200362 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200363
Johannes Berg47afbaf2009-04-07 15:22:28 +0200364 if (reconf || reconf_flags)
Johannes Berge8975582008-10-09 12:18:51 +0200365 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200366
367 return 0;
368}
369
Larry Fingerfe6aa302007-08-10 11:23:20 -0500370static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
371 struct iw_request_info *info,
372 union iwreq_data *data, char *extra)
373{
374 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
375
376 data->txpower.fixed = 1;
377 data->txpower.disabled = !(local->hw.conf.radio_enabled);
378 data->txpower.value = local->hw.conf.power_level;
379 data->txpower.flags = IW_TXPOW_DBM;
380
381 return 0;
382}
383
Samuel Ortiz49292d52008-07-04 10:49:31 +0200384static int ieee80211_ioctl_siwpower(struct net_device *dev,
385 struct iw_request_info *info,
386 struct iw_param *wrq,
387 char *extra)
388{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200389 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200390 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
391 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg965beda2009-04-16 13:17:24 +0200392 int timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200393 bool ps;
394
Johannes Berg4be8c382009-01-07 18:28:20 +0100395 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
396 return -EOPNOTSUPP;
397
Kalle Valoe0cb6862008-12-18 23:35:13 +0200398 if (sdata->vif.type != NL80211_IFTYPE_STATION)
399 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200400
401 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200402 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200403 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200404 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200405 }
406
407 switch (wrq->flags & IW_POWER_MODE) {
408 case IW_POWER_ON: /* If not specified */
409 case IW_POWER_MODE: /* If set all mask */
410 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200411 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200412 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200413 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100414 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200415 }
416
Johannes Berge9aeaba2009-01-06 18:12:35 +0100417 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
418 return -EINVAL;
419
Kalle Valo520eb822008-12-18 23:35:27 +0200420 if (wrq->flags & IW_POWER_TIMEOUT)
421 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200422
Johannes Berg4be8c382009-01-07 18:28:20 +0100423 set:
Johannes Berg965beda2009-04-16 13:17:24 +0200424 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
425 return 0;
Kalle Valo520eb822008-12-18 23:35:27 +0200426
Johannes Berg965beda2009-04-16 13:17:24 +0200427 sdata->u.mgd.powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100428 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200429
Johannes Berg4be8c382009-01-07 18:28:20 +0100430 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berge255d5e2009-04-22 12:40:07 +0200431 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg4be8c382009-01-07 18:28:20 +0100432
Johannes Berg10f644a2009-04-16 13:17:25 +0200433 ieee80211_recalc_ps(local, -1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100434
Johannes Berg965beda2009-04-16 13:17:24 +0200435 return 0;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200436}
437
438static int ieee80211_ioctl_giwpower(struct net_device *dev,
439 struct iw_request_info *info,
440 union iwreq_data *wrqu,
441 char *extra)
442{
Johannes Berg965beda2009-04-16 13:17:24 +0200443 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200444
Johannes Berg965beda2009-04-16 13:17:24 +0200445 wrqu->power.disabled = !sdata->u.mgd.powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200446
447 return 0;
448}
449
Jiri Bencf0706e82007-05-05 11:45:53 -0700450static int ieee80211_ioctl_siwauth(struct net_device *dev,
451 struct iw_request_info *info,
452 struct iw_param *data, char *extra)
453{
Jiri Bencf0706e82007-05-05 11:45:53 -0700454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
455 int ret = 0;
456
457 switch (data->flags & IW_AUTH_INDEX) {
458 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700459 case IW_AUTH_CIPHER_GROUP:
460 case IW_AUTH_WPA_ENABLED:
461 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700462 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200463 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000464 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530465 case IW_AUTH_CIPHER_PAIRWISE:
466 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
467 if (data->value & (IW_AUTH_CIPHER_WEP40 |
468 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100469 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530470 IEEE80211_STA_TKIP_WEP_USED;
471 else
Johannes Berg46900292009-02-15 12:44:28 +0100472 sdata->u.mgd.flags &=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530473 ~IEEE80211_STA_TKIP_WEP_USED;
474 }
475 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100476 case IW_AUTH_DROP_UNENCRYPTED:
477 sdata->drop_unencrypted = !!data->value;
478 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000479 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200480 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700481 ret = -EINVAL;
482 else {
Johannes Berg46900292009-02-15 12:44:28 +0100483 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700484 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000485 * Privacy invoked by wpa_supplicant, store the
486 * value and allow associating to a protected
487 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700488 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000489 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100490 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000491 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700492 }
493 break;
494 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100495 if (sdata->vif.type == NL80211_IFTYPE_STATION)
496 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700497 else
498 ret = -EOPNOTSUPP;
499 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200500 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200501 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
502 ret = -EOPNOTSUPP;
503 break;
504 }
Johannes Berg46900292009-02-15 12:44:28 +0100505 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100506 switch (data->value) {
507 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100508 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100509 break;
510 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100511 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100512 break;
513 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100514 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100515 break;
516 default:
517 ret = -EINVAL;
518 }
519 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200520 ret = -EOPNOTSUPP;
521 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700522 default:
523 ret = -EOPNOTSUPP;
524 break;
525 }
526 return ret;
527}
528
529/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
530static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
531{
532 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
533 struct iw_statistics *wstats = &local->wstats;
534 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
535 struct sta_info *sta = NULL;
536
Johannes Berg98dd6a52008-04-10 15:36:09 +0200537 rcu_read_lock();
538
Johannes Berg46900292009-02-15 12:44:28 +0100539 if (sdata->vif.type == NL80211_IFTYPE_STATION)
540 sta = sta_info_get(local, sdata->u.mgd.bssid);
541
Jiri Bencf0706e82007-05-05 11:45:53 -0700542 if (!sta) {
543 wstats->discard.fragment = 0;
544 wstats->discard.misc = 0;
545 wstats->qual.qual = 0;
546 wstats->qual.level = 0;
547 wstats->qual.noise = 0;
548 wstats->qual.updated = IW_QUAL_ALL_INVALID;
549 } else {
Johannes Berg24776cf2009-02-27 16:33:55 -0600550 wstats->qual.updated = 0;
551 /*
552 * mirror what cfg80211 does for iwrange/scan results,
553 * otherwise userspace gets confused.
554 */
555 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
556 IEEE80211_HW_SIGNAL_DBM)) {
557 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
558 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
559 } else {
560 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
561 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
562 }
563
564 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
565 wstats->qual.level = sta->last_signal;
566 wstats->qual.qual = sta->last_signal;
567 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
568 int sig = sta->last_signal;
569
570 wstats->qual.updated |= IW_QUAL_DBM;
571 wstats->qual.level = sig;
572 if (sig < -110)
573 sig = -110;
574 else if (sig > -40)
575 sig = -40;
576 wstats->qual.qual = sig + 110;
577 }
578
579 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
580 /*
581 * This assumes that if driver reports noise, it also
582 * reports signal in dBm.
583 */
584 wstats->qual.noise = sta->last_noise;
585 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
586 } else {
587 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
588 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700589 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200590
591 rcu_read_unlock();
592
Jiri Bencf0706e82007-05-05 11:45:53 -0700593 return wstats;
594}
595
596static int ieee80211_ioctl_giwauth(struct net_device *dev,
597 struct iw_request_info *info,
598 struct iw_param *data, char *extra)
599{
600 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
601 int ret = 0;
602
603 switch (data->flags & IW_AUTH_INDEX) {
604 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100605 if (sdata->vif.type == NL80211_IFTYPE_STATION)
606 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e82007-05-05 11:45:53 -0700607 else
608 ret = -EOPNOTSUPP;
609 break;
610 default:
611 ret = -EOPNOTSUPP;
612 break;
613 }
614 return ret;
615}
616
617
Jiri Bencf0706e82007-05-05 11:45:53 -0700618/* Structures to export the Wireless Handlers */
619
620static const iw_handler ieee80211_handler[] =
621{
622 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +0100623 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -0700624 (iw_handler) NULL, /* SIOCSIWNWID */
625 (iw_handler) NULL, /* SIOCGIWNWID */
626 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
627 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +0100628 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
629 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700630 (iw_handler) NULL, /* SIOCSIWSENS */
631 (iw_handler) NULL, /* SIOCGIWSENS */
632 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
Johannes Berg4aa188e2009-02-18 19:32:08 +0100633 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700634 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
635 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
636 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
637 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -0400638 (iw_handler) NULL, /* SIOCSIWSPY */
639 (iw_handler) NULL, /* SIOCGIWSPY */
640 (iw_handler) NULL, /* SIOCSIWTHRSPY */
641 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -0700642 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
643 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
Johannes Berg691597c2009-04-19 19:57:45 +0200644 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
Jiri Bencf0706e82007-05-05 11:45:53 -0700645 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +0100646 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
647 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e82007-05-05 11:45:53 -0700648 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
649 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
650 (iw_handler) NULL, /* SIOCSIWNICKN */
651 (iw_handler) NULL, /* SIOCGIWNICKN */
652 (iw_handler) NULL, /* -- hole -- */
653 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +0200654 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700655 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200656 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
657 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
658 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
659 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +0200660 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -0500661 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200662 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
663 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
Johannes Berg08645122009-05-11 13:54:58 +0200664 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
665 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +0200666 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
667 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -0700668 (iw_handler) NULL, /* -- hole -- */
669 (iw_handler) NULL, /* -- hole -- */
670 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
671 (iw_handler) NULL, /* SIOCGIWGENIE */
672 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
673 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
Johannes Berg08645122009-05-11 13:54:58 +0200674 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
Jiri Bencf0706e82007-05-05 11:45:53 -0700675 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
676 (iw_handler) NULL, /* SIOCSIWPMKSA */
677 (iw_handler) NULL, /* -- hole -- */
678};
679
Jiri Bencf0706e82007-05-05 11:45:53 -0700680const struct iw_handler_def ieee80211_iw_handler_def =
681{
682 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -0700683 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -0700684 .get_wireless_stats = ieee80211_get_wireless_stats,
685};