blob: a01154e127f07b0ae6d949177f4dd06c49806667 [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
Jiri Bencf0706e822007-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 Bencf0706e822007-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);
Johannes Berg175427c2009-05-19 22:16:25 +020040 if (ret && ret != -EALREADY)
Jiri Bencf0706e822007-05-05 11:45:53 -070041 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 Berg175427c2009-05-19 22:16:25 +020045 if (ret != -EALREADY)
46 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -070047 return 0;
48 }
49
Jiri Bencf0706e822007-05-05 11:45:53 -070050 return -EOPNOTSUPP;
51}
52
Jiri Bencf0706e822007-05-05 11:45:53 -070053static int ieee80211_ioctl_siwfreq(struct net_device *dev,
54 struct iw_request_info *info,
55 struct iw_freq *freq, char *extra)
56{
Jiri Bencf0706e822007-05-05 11:45:53 -070057 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
58
Johannes Berg46900292009-02-15 12:44:28 +010059 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020060 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
Johannes Berg46900292009-02-15 12:44:28 +010061 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
62 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -070063
64 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
65 if (freq->e == 0) {
66 if (freq->m < 0) {
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020067 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Johannes Berg46900292009-02-15 12:44:28 +010068 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -040069 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -070070 return 0;
71 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120072 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +010073 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e822007-05-05 11:45:53 -070074 } else {
75 int i, div = 1000000;
76 for (i = 0; i < freq->e; i++)
77 div /= 10;
78 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120079 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e822007-05-05 11:45:53 -070080 else
81 return -EINVAL;
82 }
83}
84
85
86static int ieee80211_ioctl_giwfreq(struct net_device *dev,
87 struct iw_request_info *info,
88 struct iw_freq *freq, char *extra)
89{
90 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020091 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
92
93 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
94 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
Jiri Bencf0706e822007-05-05 11:45:53 -070095
Johannes Berg77382312009-05-04 17:52:10 +020096 freq->m = local->oper_channel->center_freq;
Jiri Bencf0706e822007-05-05 11:45:53 -070097 freq->e = 6;
98
99 return 0;
100}
101
102
103static int ieee80211_ioctl_siwessid(struct net_device *dev,
104 struct iw_request_info *info,
105 struct iw_point *data, char *ssid)
106{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200107 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -0700108 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100109 int ret;
Jiri Bencf0706e822007-05-05 11:45:53 -0700110
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200111 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
112 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
113
Jiri Bencf0706e822007-05-05 11:45:53 -0700114 /* iwconfig uses nul termination in SSID.. */
115 if (len > 0 && ssid[len - 1] == '\0')
116 len--;
117
Johannes Berg46900292009-02-15 12:44:28 +0100118 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400119 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100120 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400121 else
Johannes Berg46900292009-02-15 12:44:28 +0100122 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
123
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200124 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700125 if (ret)
126 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100127
Jouni Malinen636a5d32009-03-19 13:39:22 +0200128 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300129 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
Johannes Berg46900292009-02-15 12:44:28 +0100130 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -0700131 return 0;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200132 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700133
Jiri Bencf0706e822007-05-05 11:45:53 -0700134 return -EOPNOTSUPP;
135}
136
137
138static int ieee80211_ioctl_giwessid(struct net_device *dev,
139 struct iw_request_info *info,
140 struct iw_point *data, char *ssid)
141{
142 size_t len;
Jiri Bencf0706e822007-05-05 11:45:53 -0700143 struct ieee80211_sub_if_data *sdata;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200144
Jiri Bencf0706e822007-05-05 11:45:53 -0700145 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200146
147 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
148 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
149
Johannes Berg46900292009-02-15 12:44:28 +0100150 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200151 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e822007-05-05 11:45:53 -0700152 if (res == 0) {
153 data->length = len;
154 data->flags = 1;
155 } else
156 data->flags = 0;
157 return res;
158 }
159
Jiri Bencf0706e822007-05-05 11:45:53 -0700160 return -EOPNOTSUPP;
161}
162
163
164static int ieee80211_ioctl_siwap(struct net_device *dev,
165 struct iw_request_info *info,
166 struct sockaddr *ap_addr, char *extra)
167{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200168 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -0700169
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200170 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
171 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
172
Johannes Berg46900292009-02-15 12:44:28 +0100173 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700174 int ret;
Johannes Berg7986cf92009-03-21 17:08:43 +0100175
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400176 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100177 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400178 IEEE80211_STA_AUTO_CHANNEL_SEL;
179 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100180 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e822007-05-05 11:45:53 -0700181 else
Johannes Berg46900292009-02-15 12:44:28 +0100182 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200183 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e822007-05-05 11:45:53 -0700184 if (ret)
185 return ret;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200186 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300187 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
Johannes Berg46900292009-02-15 12:44:28 +0100188 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -0700189 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200190 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100191 /*
192 * If it is necessary to update the WDS peer address
193 * while the interface is running, then we need to do
194 * more work here, namely if it is running we need to
195 * add a new and remove the old STA entry, this is
196 * normally handled by _open() and _stop().
197 */
198 if (netif_running(dev))
199 return -EBUSY;
200
201 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
202 ETH_ALEN);
203
204 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700205 }
206
207 return -EOPNOTSUPP;
208}
209
210
211static int ieee80211_ioctl_giwap(struct net_device *dev,
212 struct iw_request_info *info,
213 struct sockaddr *ap_addr, char *extra)
214{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200215 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -0700216
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200217 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
218 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
219
Johannes Berg46900292009-02-15 12:44:28 +0100220 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
221 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700222 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100223 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
224 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700225 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100226 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200227 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e822007-05-05 11:45:53 -0700228 ap_addr->sa_family = ARPHRD_ETHER;
229 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
230 return 0;
231 }
232
233 return -EOPNOTSUPP;
234}
235
236
Larry Finger1fd5e582007-07-10 19:32:10 +0200237static int ieee80211_ioctl_siwrate(struct net_device *dev,
238 struct iw_request_info *info,
239 struct iw_param *rate, char *extra)
240{
241 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100242 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200243 u32 target_rate = rate->value / 100000;
244 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100245 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200246
247 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100248
249 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
250
Larry Finger1fd5e582007-07-10 19:32:10 +0200251 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
252 * target_rate = X, rate->fixed = 1 means only rate X
253 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200254 sdata->max_ratectrl_rateidx = -1;
255 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200256 if (rate->value < 0)
257 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100258
259 for (i=0; i< sband->n_bitrates; i++) {
260 struct ieee80211_rate *brate = &sband->bitrates[i];
261 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200262
Larry Finger1fd5e582007-07-10 19:32:10 +0200263 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200264 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200265 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200266 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100267 err = 0;
268 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200269 }
270 }
Johannes Berg8318d782008-01-24 19:38:38 +0100271 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200272}
273
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700274static int ieee80211_ioctl_giwrate(struct net_device *dev,
275 struct iw_request_info *info,
276 struct iw_param *rate, char *extra)
277{
278 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
279 struct sta_info *sta;
280 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100281 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700282
283 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100284
Johannes Berg05c914f2008-09-11 00:01:58 +0200285 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700286 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100287
288 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
289
Johannes Berg380a9422008-04-04 23:40:35 +0200290 rcu_read_lock();
291
Johannes Berg46900292009-02-15 12:44:28 +0100292 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200293
Johannes Berge6a98542008-10-21 12:40:02 +0200294 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
295 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700296 else
297 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200298
299 rcu_read_unlock();
300
301 if (!sta)
302 return -ENODEV;
303
Johannes Berg8318d782008-01-24 19:38:38 +0100304 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100305
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700306 return 0;
307}
308
Michael Buesch61609bc2007-09-20 22:06:39 +0200309static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
310 struct iw_request_info *info,
311 union iwreq_data *data, char *extra)
312{
313 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700314 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berg47afbaf2009-04-07 15:22:28 +0200315 bool reconf = false;
Johannes Berge8975582008-10-09 12:18:51 +0200316 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100317 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200318
319 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
320 return -EINVAL;
321 if (data->txpower.flags & IW_TXPOW_RANGE)
322 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700323 if (!chan)
324 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200325
Johannes Berg47afbaf2009-04-07 15:22:28 +0200326 /* only change when not disabling */
327 if (!data->txpower.disabled) {
328 if (data->txpower.fixed) {
329 if (data->txpower.value < 0)
330 return -EINVAL;
331 new_power_level = data->txpower.value;
332 /*
333 * Debatable, but we cannot do a fixed power
334 * level above the regulatory constraint.
335 * Use "iwconfig wlan0 txpower 15dBm" instead.
336 */
337 if (new_power_level > chan->max_power)
338 return -EINVAL;
339 } else {
340 /*
341 * Automatic power level setting, max being the value
342 * passed in from userland.
343 */
344 if (data->txpower.value < 0)
345 new_power_level = -1;
346 else
347 new_power_level = data->txpower.value;
348 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200349
Johannes Berg47afbaf2009-04-07 15:22:28 +0200350 reconf = true;
351
352 /*
353 * ieee80211_hw_config() will limit to the channel's
354 * max power and possibly power constraint from AP.
355 */
356 local->user_power_level = new_power_level;
357 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200358
Michael Buesch61609bc2007-09-20 22:06:39 +0200359 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
360 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200361 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100362 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200363 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200364
Johannes Berg47afbaf2009-04-07 15:22:28 +0200365 if (reconf || reconf_flags)
Johannes Berge8975582008-10-09 12:18:51 +0200366 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200367
368 return 0;
369}
370
Larry Fingerfe6aa302007-08-10 11:23:20 -0500371static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
372 struct iw_request_info *info,
373 union iwreq_data *data, char *extra)
374{
375 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
376
377 data->txpower.fixed = 1;
378 data->txpower.disabled = !(local->hw.conf.radio_enabled);
379 data->txpower.value = local->hw.conf.power_level;
380 data->txpower.flags = IW_TXPOW_DBM;
381
382 return 0;
383}
384
Samuel Ortiz49292d52008-07-04 10:49:31 +0200385static int ieee80211_ioctl_siwpower(struct net_device *dev,
386 struct iw_request_info *info,
387 struct iw_param *wrq,
388 char *extra)
389{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200390 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200391 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
392 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg965beda2009-04-16 13:17:24 +0200393 int timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200394 bool ps;
395
Johannes Berg4be8c382009-01-07 18:28:20 +0100396 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
397 return -EOPNOTSUPP;
398
Kalle Valoe0cb6862008-12-18 23:35:13 +0200399 if (sdata->vif.type != NL80211_IFTYPE_STATION)
400 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200401
402 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200403 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200404 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200405 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200406 }
407
408 switch (wrq->flags & IW_POWER_MODE) {
409 case IW_POWER_ON: /* If not specified */
410 case IW_POWER_MODE: /* If set all mask */
411 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200412 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200413 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200414 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100415 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200416 }
417
Johannes Berge9aeaba2009-01-06 18:12:35 +0100418 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
419 return -EINVAL;
420
Kalle Valo520eb822008-12-18 23:35:27 +0200421 if (wrq->flags & IW_POWER_TIMEOUT)
422 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200423
Johannes Berg4be8c382009-01-07 18:28:20 +0100424 set:
Johannes Berg965beda2009-04-16 13:17:24 +0200425 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
426 return 0;
Kalle Valo520eb822008-12-18 23:35:27 +0200427
Johannes Berg965beda2009-04-16 13:17:24 +0200428 sdata->u.mgd.powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100429 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200430
Johannes Berg4be8c382009-01-07 18:28:20 +0100431 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berge255d5e2009-04-22 12:40:07 +0200432 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg4be8c382009-01-07 18:28:20 +0100433
Johannes Berg10f644a2009-04-16 13:17:25 +0200434 ieee80211_recalc_ps(local, -1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100435
Johannes Berg965beda2009-04-16 13:17:24 +0200436 return 0;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200437}
438
439static int ieee80211_ioctl_giwpower(struct net_device *dev,
440 struct iw_request_info *info,
441 union iwreq_data *wrqu,
442 char *extra)
443{
Johannes Berg965beda2009-04-16 13:17:24 +0200444 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200445
Johannes Berg965beda2009-04-16 13:17:24 +0200446 wrqu->power.disabled = !sdata->u.mgd.powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200447
448 return 0;
449}
450
Jiri Bencf0706e822007-05-05 11:45:53 -0700451static int ieee80211_ioctl_siwauth(struct net_device *dev,
452 struct iw_request_info *info,
453 struct iw_param *data, char *extra)
454{
Jiri Bencf0706e822007-05-05 11:45:53 -0700455 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
456 int ret = 0;
457
458 switch (data->flags & IW_AUTH_INDEX) {
459 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e822007-05-05 11:45:53 -0700460 case IW_AUTH_CIPHER_GROUP:
461 case IW_AUTH_WPA_ENABLED:
462 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e822007-05-05 11:45:53 -0700463 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200464 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000465 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530466 case IW_AUTH_CIPHER_PAIRWISE:
467 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
468 if (data->value & (IW_AUTH_CIPHER_WEP40 |
469 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100470 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530471 IEEE80211_STA_TKIP_WEP_USED;
472 else
Johannes Berg46900292009-02-15 12:44:28 +0100473 sdata->u.mgd.flags &=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530474 ~IEEE80211_STA_TKIP_WEP_USED;
475 }
476 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100477 case IW_AUTH_DROP_UNENCRYPTED:
478 sdata->drop_unencrypted = !!data->value;
479 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000480 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200481 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e822007-05-05 11:45:53 -0700482 ret = -EINVAL;
483 else {
Johannes Berg46900292009-02-15 12:44:28 +0100484 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e822007-05-05 11:45:53 -0700485 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000486 * Privacy invoked by wpa_supplicant, store the
487 * value and allow associating to a protected
488 * network without having a key up front.
Jiri Bencf0706e822007-05-05 11:45:53 -0700489 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000490 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100491 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000492 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e822007-05-05 11:45:53 -0700493 }
494 break;
495 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100496 if (sdata->vif.type == NL80211_IFTYPE_STATION)
497 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e822007-05-05 11:45:53 -0700498 else
499 ret = -EOPNOTSUPP;
500 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200501 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200502 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
503 ret = -EOPNOTSUPP;
504 break;
505 }
Johannes Berg46900292009-02-15 12:44:28 +0100506 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100507 switch (data->value) {
508 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100509 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100510 break;
511 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100512 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100513 break;
514 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100515 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100516 break;
517 default:
518 ret = -EINVAL;
519 }
520 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200521 ret = -EOPNOTSUPP;
522 break;
Jiri Bencf0706e822007-05-05 11:45:53 -0700523 default:
524 ret = -EOPNOTSUPP;
525 break;
526 }
527 return ret;
528}
529
530/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
531static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
532{
533 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
534 struct iw_statistics *wstats = &local->wstats;
535 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
536 struct sta_info *sta = NULL;
537
Johannes Berg98dd6a52008-04-10 15:36:09 +0200538 rcu_read_lock();
539
Johannes Berg46900292009-02-15 12:44:28 +0100540 if (sdata->vif.type == NL80211_IFTYPE_STATION)
541 sta = sta_info_get(local, sdata->u.mgd.bssid);
542
Jiri Bencf0706e822007-05-05 11:45:53 -0700543 if (!sta) {
544 wstats->discard.fragment = 0;
545 wstats->discard.misc = 0;
546 wstats->qual.qual = 0;
547 wstats->qual.level = 0;
548 wstats->qual.noise = 0;
549 wstats->qual.updated = IW_QUAL_ALL_INVALID;
550 } else {
Johannes Berg24776cf2009-02-27 16:33:55 -0600551 wstats->qual.updated = 0;
552 /*
553 * mirror what cfg80211 does for iwrange/scan results,
554 * otherwise userspace gets confused.
555 */
556 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
557 IEEE80211_HW_SIGNAL_DBM)) {
558 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
559 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
560 } else {
561 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
562 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
563 }
564
565 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
566 wstats->qual.level = sta->last_signal;
567 wstats->qual.qual = sta->last_signal;
568 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
569 int sig = sta->last_signal;
570
571 wstats->qual.updated |= IW_QUAL_DBM;
572 wstats->qual.level = sig;
573 if (sig < -110)
574 sig = -110;
575 else if (sig > -40)
576 sig = -40;
577 wstats->qual.qual = sig + 110;
578 }
579
580 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
581 /*
582 * This assumes that if driver reports noise, it also
583 * reports signal in dBm.
584 */
585 wstats->qual.noise = sta->last_noise;
586 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
587 } else {
588 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
589 }
Jiri Bencf0706e822007-05-05 11:45:53 -0700590 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200591
592 rcu_read_unlock();
593
Jiri Bencf0706e822007-05-05 11:45:53 -0700594 return wstats;
595}
596
597static int ieee80211_ioctl_giwauth(struct net_device *dev,
598 struct iw_request_info *info,
599 struct iw_param *data, char *extra)
600{
601 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
602 int ret = 0;
603
604 switch (data->flags & IW_AUTH_INDEX) {
605 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100606 if (sdata->vif.type == NL80211_IFTYPE_STATION)
607 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e822007-05-05 11:45:53 -0700608 else
609 ret = -EOPNOTSUPP;
610 break;
611 default:
612 ret = -EOPNOTSUPP;
613 break;
614 }
615 return ret;
616}
617
618
Jiri Bencf0706e822007-05-05 11:45:53 -0700619/* Structures to export the Wireless Handlers */
620
621static const iw_handler ieee80211_handler[] =
622{
623 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +0100624 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e822007-05-05 11:45:53 -0700625 (iw_handler) NULL, /* SIOCSIWNWID */
626 (iw_handler) NULL, /* SIOCGIWNWID */
627 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
628 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +0100629 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
630 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e822007-05-05 11:45:53 -0700631 (iw_handler) NULL, /* SIOCSIWSENS */
632 (iw_handler) NULL, /* SIOCGIWSENS */
633 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
Johannes Berg4aa188e2009-02-18 19:32:08 +0100634 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
Jiri Bencf0706e822007-05-05 11:45:53 -0700635 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
636 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
637 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
638 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -0400639 (iw_handler) NULL, /* SIOCSIWSPY */
640 (iw_handler) NULL, /* SIOCGIWSPY */
641 (iw_handler) NULL, /* SIOCSIWTHRSPY */
642 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e822007-05-05 11:45:53 -0700643 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
644 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
Johannes Berg691597c2009-04-19 19:57:45 +0200645 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
Jiri Bencf0706e822007-05-05 11:45:53 -0700646 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +0100647 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
648 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e822007-05-05 11:45:53 -0700649 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
650 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
651 (iw_handler) NULL, /* SIOCSIWNICKN */
652 (iw_handler) NULL, /* SIOCGIWNICKN */
653 (iw_handler) NULL, /* -- hole -- */
654 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +0200655 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700656 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200657 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
658 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
659 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
660 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +0200661 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -0500662 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200663 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
664 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
Johannes Berg08645122009-05-11 13:54:58 +0200665 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
666 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +0200667 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
668 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e822007-05-05 11:45:53 -0700669 (iw_handler) NULL, /* -- hole -- */
670 (iw_handler) NULL, /* -- hole -- */
671 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
672 (iw_handler) NULL, /* SIOCGIWGENIE */
673 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
674 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
Johannes Berg08645122009-05-11 13:54:58 +0200675 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
Jiri Bencf0706e822007-05-05 11:45:53 -0700676 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
677 (iw_handler) NULL, /* SIOCSIWPMKSA */
678 (iw_handler) NULL, /* -- hole -- */
679};
680
Jiri Bencf0706e822007-05-05 11:45:53 -0700681const struct iw_handler_def ieee80211_iw_handler_def =
682{
683 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e822007-05-05 11:45:53 -0700684 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e822007-05-05 11:45:53 -0700685 .get_wireless_stats = ieee80211_get_wireless_stats,
686};