blob: d845026446863f404d5fe88dfe955ecb9437c77c [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;
Johannes Berg46900292009-02-15 12:44:28 +010044 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -070045 return 0;
46 }
47
Jiri Bencf0706e82007-05-05 11:45:53 -070048 return -EOPNOTSUPP;
49}
50
Jiri Bencf0706e82007-05-05 11:45:53 -070051static int ieee80211_ioctl_siwfreq(struct net_device *dev,
52 struct iw_request_info *info,
53 struct iw_freq *freq, char *extra)
54{
Jiri Bencf0706e82007-05-05 11:45:53 -070055 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
56
Johannes Berg46900292009-02-15 12:44:28 +010057 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020058 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
Johannes Berg46900292009-02-15 12:44:28 +010059 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
60 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -070061
62 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
63 if (freq->e == 0) {
64 if (freq->m < 0) {
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020065 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Johannes Berg46900292009-02-15 12:44:28 +010066 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -040067 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -070068 return 0;
69 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120070 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +010071 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -070072 } else {
73 int i, div = 1000000;
74 for (i = 0; i < freq->e; i++)
75 div /= 10;
76 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120077 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -070078 else
79 return -EINVAL;
80 }
81}
82
83
84static int ieee80211_ioctl_giwfreq(struct net_device *dev,
85 struct iw_request_info *info,
86 struct iw_freq *freq, char *extra)
87{
88 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020089 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
90
91 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
92 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
Jiri Bencf0706e82007-05-05 11:45:53 -070093
Johannes Berg77382312009-05-04 17:52:10 +020094 freq->m = local->oper_channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -070095 freq->e = 6;
96
97 return 0;
98}
99
100
101static int ieee80211_ioctl_siwessid(struct net_device *dev,
102 struct iw_request_info *info,
103 struct iw_point *data, char *ssid)
104{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200105 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700106 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100107 int ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700108
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200109 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
110 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
111
Jiri Bencf0706e82007-05-05 11:45:53 -0700112 /* iwconfig uses nul termination in SSID.. */
113 if (len > 0 && ssid[len - 1] == '\0')
114 len--;
115
Johannes Berg46900292009-02-15 12:44:28 +0100116 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400117 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100118 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400119 else
Johannes Berg46900292009-02-15 12:44:28 +0100120 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
121
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200122 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700123 if (ret)
124 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100125
Jouni Malinen636a5d32009-03-19 13:39:22 +0200126 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100127 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700128 return 0;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200129 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700130
Jiri Bencf0706e82007-05-05 11:45:53 -0700131 return -EOPNOTSUPP;
132}
133
134
135static int ieee80211_ioctl_giwessid(struct net_device *dev,
136 struct iw_request_info *info,
137 struct iw_point *data, char *ssid)
138{
139 size_t len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700140 struct ieee80211_sub_if_data *sdata;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200141
Jiri Bencf0706e82007-05-05 11:45:53 -0700142 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200143
144 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
145 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
146
Johannes Berg46900292009-02-15 12:44:28 +0100147 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200148 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700149 if (res == 0) {
150 data->length = len;
151 data->flags = 1;
152 } else
153 data->flags = 0;
154 return res;
155 }
156
Jiri Bencf0706e82007-05-05 11:45:53 -0700157 return -EOPNOTSUPP;
158}
159
160
161static int ieee80211_ioctl_siwap(struct net_device *dev,
162 struct iw_request_info *info,
163 struct sockaddr *ap_addr, char *extra)
164{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200165 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700166
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200167 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
168 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
169
Johannes Berg46900292009-02-15 12:44:28 +0100170 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700171 int ret;
Johannes Berg7986cf92009-03-21 17:08:43 +0100172
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400173 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100174 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400175 IEEE80211_STA_AUTO_CHANNEL_SEL;
176 else if (is_broadcast_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 Bencf0706e82007-05-05 11:45:53 -0700178 else
Johannes Berg46900292009-02-15 12:44:28 +0100179 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200180 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700181 if (ret)
182 return ret;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200183 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Johannes Berg46900292009-02-15 12:44:28 +0100184 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700185 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200186 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100187 /*
188 * If it is necessary to update the WDS peer address
189 * while the interface is running, then we need to do
190 * more work here, namely if it is running we need to
191 * add a new and remove the old STA entry, this is
192 * normally handled by _open() and _stop().
193 */
194 if (netif_running(dev))
195 return -EBUSY;
196
197 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
198 ETH_ALEN);
199
200 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700201 }
202
203 return -EOPNOTSUPP;
204}
205
206
207static int ieee80211_ioctl_giwap(struct net_device *dev,
208 struct iw_request_info *info,
209 struct sockaddr *ap_addr, char *extra)
210{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200211 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700212
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200213 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
214 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
215
Johannes Berg46900292009-02-15 12:44:28 +0100216 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
217 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700218 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100219 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
220 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700221 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100222 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200223 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700224 ap_addr->sa_family = ARPHRD_ETHER;
225 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
226 return 0;
227 }
228
229 return -EOPNOTSUPP;
230}
231
232
Larry Finger1fd5e582007-07-10 19:32:10 +0200233static int ieee80211_ioctl_siwrate(struct net_device *dev,
234 struct iw_request_info *info,
235 struct iw_param *rate, char *extra)
236{
237 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100238 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200239 u32 target_rate = rate->value / 100000;
240 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100241 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200242
243 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100244
245 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
246
Larry Finger1fd5e582007-07-10 19:32:10 +0200247 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
248 * target_rate = X, rate->fixed = 1 means only rate X
249 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200250 sdata->max_ratectrl_rateidx = -1;
251 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200252 if (rate->value < 0)
253 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100254
255 for (i=0; i< sband->n_bitrates; i++) {
256 struct ieee80211_rate *brate = &sband->bitrates[i];
257 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200258
Larry Finger1fd5e582007-07-10 19:32:10 +0200259 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200260 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200261 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200262 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100263 err = 0;
264 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200265 }
266 }
Johannes Berg8318d782008-01-24 19:38:38 +0100267 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200268}
269
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700270static int ieee80211_ioctl_giwrate(struct net_device *dev,
271 struct iw_request_info *info,
272 struct iw_param *rate, char *extra)
273{
274 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
275 struct sta_info *sta;
276 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100277 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700278
279 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100280
Johannes Berg05c914f2008-09-11 00:01:58 +0200281 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700282 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100283
284 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
285
Johannes Berg380a9422008-04-04 23:40:35 +0200286 rcu_read_lock();
287
Johannes Berg46900292009-02-15 12:44:28 +0100288 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200289
Johannes Berge6a98542008-10-21 12:40:02 +0200290 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
291 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700292 else
293 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200294
295 rcu_read_unlock();
296
297 if (!sta)
298 return -ENODEV;
299
Johannes Berg8318d782008-01-24 19:38:38 +0100300 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100301
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700302 return 0;
303}
304
Michael Buesch61609bc2007-09-20 22:06:39 +0200305static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
306 struct iw_request_info *info,
307 union iwreq_data *data, char *extra)
308{
309 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700310 struct ieee80211_channel* chan = local->hw.conf.channel;
Johannes Berg47afbaf2009-04-07 15:22:28 +0200311 bool reconf = false;
Johannes Berge8975582008-10-09 12:18:51 +0200312 u32 reconf_flags = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100313 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200314
315 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
316 return -EINVAL;
317 if (data->txpower.flags & IW_TXPOW_RANGE)
318 return -EINVAL;
Luis R. Rodriguezd9d29252008-10-22 13:13:53 -0700319 if (!chan)
320 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200321
Johannes Berg47afbaf2009-04-07 15:22:28 +0200322 /* only change when not disabling */
323 if (!data->txpower.disabled) {
324 if (data->txpower.fixed) {
325 if (data->txpower.value < 0)
326 return -EINVAL;
327 new_power_level = data->txpower.value;
328 /*
329 * Debatable, but we cannot do a fixed power
330 * level above the regulatory constraint.
331 * Use "iwconfig wlan0 txpower 15dBm" instead.
332 */
333 if (new_power_level > chan->max_power)
334 return -EINVAL;
335 } else {
336 /*
337 * Automatic power level setting, max being the value
338 * passed in from userland.
339 */
340 if (data->txpower.value < 0)
341 new_power_level = -1;
342 else
343 new_power_level = data->txpower.value;
344 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200345
Johannes Berg47afbaf2009-04-07 15:22:28 +0200346 reconf = true;
347
348 /*
349 * ieee80211_hw_config() will limit to the channel's
350 * max power and possibly power constraint from AP.
351 */
352 local->user_power_level = new_power_level;
353 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200354
Michael Buesch61609bc2007-09-20 22:06:39 +0200355 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
356 local->hw.conf.radio_enabled = !(data->txpower.disabled);
Johannes Berge8975582008-10-09 12:18:51 +0200357 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100358 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200359 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200360
Johannes Berg47afbaf2009-04-07 15:22:28 +0200361 if (reconf || reconf_flags)
Johannes Berge8975582008-10-09 12:18:51 +0200362 ieee80211_hw_config(local, reconf_flags);
Michael Buesch61609bc2007-09-20 22:06:39 +0200363
364 return 0;
365}
366
Larry Fingerfe6aa302007-08-10 11:23:20 -0500367static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
368 struct iw_request_info *info,
369 union iwreq_data *data, char *extra)
370{
371 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
372
373 data->txpower.fixed = 1;
374 data->txpower.disabled = !(local->hw.conf.radio_enabled);
375 data->txpower.value = local->hw.conf.power_level;
376 data->txpower.flags = IW_TXPOW_DBM;
377
378 return 0;
379}
380
Samuel Ortiz49292d52008-07-04 10:49:31 +0200381static int ieee80211_ioctl_siwpower(struct net_device *dev,
382 struct iw_request_info *info,
383 struct iw_param *wrq,
384 char *extra)
385{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200386 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200387 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
388 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg965beda2009-04-16 13:17:24 +0200389 int timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200390 bool ps;
391
Johannes Berg4be8c382009-01-07 18:28:20 +0100392 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
393 return -EOPNOTSUPP;
394
Kalle Valoe0cb6862008-12-18 23:35:13 +0200395 if (sdata->vif.type != NL80211_IFTYPE_STATION)
396 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200397
398 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200399 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200400 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200401 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200402 }
403
404 switch (wrq->flags & IW_POWER_MODE) {
405 case IW_POWER_ON: /* If not specified */
406 case IW_POWER_MODE: /* If set all mask */
407 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200408 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200409 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200410 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100411 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200412 }
413
Johannes Berge9aeaba2009-01-06 18:12:35 +0100414 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
415 return -EINVAL;
416
Kalle Valo520eb822008-12-18 23:35:27 +0200417 if (wrq->flags & IW_POWER_TIMEOUT)
418 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200419
Johannes Berg4be8c382009-01-07 18:28:20 +0100420 set:
Johannes Berg965beda2009-04-16 13:17:24 +0200421 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
422 return 0;
Kalle Valo520eb822008-12-18 23:35:27 +0200423
Johannes Berg965beda2009-04-16 13:17:24 +0200424 sdata->u.mgd.powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100425 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200426
Johannes Berg4be8c382009-01-07 18:28:20 +0100427 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berge255d5e2009-04-22 12:40:07 +0200428 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg4be8c382009-01-07 18:28:20 +0100429
Johannes Berg10f644a2009-04-16 13:17:25 +0200430 ieee80211_recalc_ps(local, -1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100431
Johannes Berg965beda2009-04-16 13:17:24 +0200432 return 0;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200433}
434
435static int ieee80211_ioctl_giwpower(struct net_device *dev,
436 struct iw_request_info *info,
437 union iwreq_data *wrqu,
438 char *extra)
439{
Johannes Berg965beda2009-04-16 13:17:24 +0200440 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200441
Johannes Berg965beda2009-04-16 13:17:24 +0200442 wrqu->power.disabled = !sdata->u.mgd.powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200443
444 return 0;
445}
446
Jiri Bencf0706e82007-05-05 11:45:53 -0700447static int ieee80211_ioctl_siwauth(struct net_device *dev,
448 struct iw_request_info *info,
449 struct iw_param *data, char *extra)
450{
Jiri Bencf0706e82007-05-05 11:45:53 -0700451 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
452 int ret = 0;
453
454 switch (data->flags & IW_AUTH_INDEX) {
455 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700456 case IW_AUTH_CIPHER_GROUP:
457 case IW_AUTH_WPA_ENABLED:
458 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700459 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200460 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000461 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530462 case IW_AUTH_CIPHER_PAIRWISE:
463 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
464 if (data->value & (IW_AUTH_CIPHER_WEP40 |
465 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100466 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530467 IEEE80211_STA_TKIP_WEP_USED;
468 else
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 }
472 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100473 case IW_AUTH_DROP_UNENCRYPTED:
474 sdata->drop_unencrypted = !!data->value;
475 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000476 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200477 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700478 ret = -EINVAL;
479 else {
Johannes Berg46900292009-02-15 12:44:28 +0100480 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700481 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000482 * Privacy invoked by wpa_supplicant, store the
483 * value and allow associating to a protected
484 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700485 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000486 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100487 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000488 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700489 }
490 break;
491 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100492 if (sdata->vif.type == NL80211_IFTYPE_STATION)
493 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700494 else
495 ret = -EOPNOTSUPP;
496 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200497 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200498 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
499 ret = -EOPNOTSUPP;
500 break;
501 }
Johannes Berg46900292009-02-15 12:44:28 +0100502 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100503 switch (data->value) {
504 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100505 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100506 break;
507 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100508 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100509 break;
510 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100511 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100512 break;
513 default:
514 ret = -EINVAL;
515 }
516 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200517 ret = -EOPNOTSUPP;
518 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700519 default:
520 ret = -EOPNOTSUPP;
521 break;
522 }
523 return ret;
524}
525
526/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
527static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
528{
529 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
530 struct iw_statistics *wstats = &local->wstats;
531 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
532 struct sta_info *sta = NULL;
533
Johannes Berg98dd6a52008-04-10 15:36:09 +0200534 rcu_read_lock();
535
Johannes Berg46900292009-02-15 12:44:28 +0100536 if (sdata->vif.type == NL80211_IFTYPE_STATION)
537 sta = sta_info_get(local, sdata->u.mgd.bssid);
538
Jiri Bencf0706e82007-05-05 11:45:53 -0700539 if (!sta) {
540 wstats->discard.fragment = 0;
541 wstats->discard.misc = 0;
542 wstats->qual.qual = 0;
543 wstats->qual.level = 0;
544 wstats->qual.noise = 0;
545 wstats->qual.updated = IW_QUAL_ALL_INVALID;
546 } else {
Johannes Berg24776cf2009-02-27 16:33:55 -0600547 wstats->qual.updated = 0;
548 /*
549 * mirror what cfg80211 does for iwrange/scan results,
550 * otherwise userspace gets confused.
551 */
552 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
553 IEEE80211_HW_SIGNAL_DBM)) {
554 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
555 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
556 } else {
557 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
558 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
559 }
560
561 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
562 wstats->qual.level = sta->last_signal;
563 wstats->qual.qual = sta->last_signal;
564 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
565 int sig = sta->last_signal;
566
567 wstats->qual.updated |= IW_QUAL_DBM;
568 wstats->qual.level = sig;
569 if (sig < -110)
570 sig = -110;
571 else if (sig > -40)
572 sig = -40;
573 wstats->qual.qual = sig + 110;
574 }
575
576 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
577 /*
578 * This assumes that if driver reports noise, it also
579 * reports signal in dBm.
580 */
581 wstats->qual.noise = sta->last_noise;
582 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
583 } else {
584 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
585 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700586 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200587
588 rcu_read_unlock();
589
Jiri Bencf0706e82007-05-05 11:45:53 -0700590 return wstats;
591}
592
593static int ieee80211_ioctl_giwauth(struct net_device *dev,
594 struct iw_request_info *info,
595 struct iw_param *data, char *extra)
596{
597 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
598 int ret = 0;
599
600 switch (data->flags & IW_AUTH_INDEX) {
601 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100602 if (sdata->vif.type == NL80211_IFTYPE_STATION)
603 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e82007-05-05 11:45:53 -0700604 else
605 ret = -EOPNOTSUPP;
606 break;
607 default:
608 ret = -EOPNOTSUPP;
609 break;
610 }
611 return ret;
612}
613
614
Jiri Bencf0706e82007-05-05 11:45:53 -0700615/* Structures to export the Wireless Handlers */
616
617static const iw_handler ieee80211_handler[] =
618{
619 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +0100620 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -0700621 (iw_handler) NULL, /* SIOCSIWNWID */
622 (iw_handler) NULL, /* SIOCGIWNWID */
623 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
624 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +0100625 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
626 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700627 (iw_handler) NULL, /* SIOCSIWSENS */
628 (iw_handler) NULL, /* SIOCGIWSENS */
629 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
Johannes Berg4aa188e2009-02-18 19:32:08 +0100630 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700631 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
632 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
633 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
634 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -0400635 (iw_handler) NULL, /* SIOCSIWSPY */
636 (iw_handler) NULL, /* SIOCGIWSPY */
637 (iw_handler) NULL, /* SIOCSIWTHRSPY */
638 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -0700639 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
640 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
Johannes Berg691597c2009-04-19 19:57:45 +0200641 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
Jiri Bencf0706e82007-05-05 11:45:53 -0700642 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +0100643 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
644 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e82007-05-05 11:45:53 -0700645 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
646 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
647 (iw_handler) NULL, /* SIOCSIWNICKN */
648 (iw_handler) NULL, /* SIOCGIWNICKN */
649 (iw_handler) NULL, /* -- hole -- */
650 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +0200651 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700652 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200653 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
654 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
655 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
656 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +0200657 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -0500658 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200659 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
660 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
Johannes Berg08645122009-05-11 13:54:58 +0200661 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
662 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +0200663 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
664 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -0700665 (iw_handler) NULL, /* -- hole -- */
666 (iw_handler) NULL, /* -- hole -- */
667 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
668 (iw_handler) NULL, /* SIOCGIWGENIE */
669 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
670 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
Johannes Berg08645122009-05-11 13:54:58 +0200671 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
Jiri Bencf0706e82007-05-05 11:45:53 -0700672 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
673 (iw_handler) NULL, /* SIOCSIWPMKSA */
674 (iw_handler) NULL, /* -- hole -- */
675};
676
Jiri Bencf0706e82007-05-05 11:45:53 -0700677const struct iw_handler_def ieee80211_iw_handler_def =
678{
679 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -0700680 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -0700681 .get_wireless_stats = ieee80211_get_wireless_stats,
682};