blob: 1da81f4567446f049139875aa64e772affe521e1 [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);
Johannes Berg175427c2009-05-19 22:16:25 +020040 if (ret && ret != -EALREADY)
Jiri Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -070047 return 0;
48 }
49
Jiri Bencf0706e82007-05-05 11:45:53 -070050 return -EOPNOTSUPP;
51}
52
Jiri Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -070057 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7e9debe2009-06-15 13:42:25 +020058 struct ieee80211_local *local = sdata->local;
59 struct ieee80211_channel *chan;
Jiri Bencf0706e82007-05-05 11:45:53 -070060
Johannes Berg46900292009-02-15 12:44:28 +010061 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020062 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
Johannes Berg46900292009-02-15 12:44:28 +010063 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
64 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -070065
66 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
67 if (freq->e == 0) {
68 if (freq->m < 0) {
Johannes Bergaf8cdcd2009-04-19 21:25:43 +020069 if (sdata->vif.type == NL80211_IFTYPE_STATION)
Johannes Berg46900292009-02-15 12:44:28 +010070 sdata->u.mgd.flags |=
Jiri Slabyd6f2da52007-08-28 17:01:54 -040071 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -070072 return 0;
73 } else
Johannes Berg7e9debe2009-06-15 13:42:25 +020074 chan = ieee80211_get_channel(local->hw.wiphy,
Johannes Berg8318d782008-01-24 19:38:38 +010075 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -070076 } else {
77 int i, div = 1000000;
78 for (i = 0; i < freq->e; i++)
79 div /= 10;
Johannes Berg7e9debe2009-06-15 13:42:25 +020080 if (div <= 0)
Jiri Bencf0706e82007-05-05 11:45:53 -070081 return -EINVAL;
Johannes Berg7e9debe2009-06-15 13:42:25 +020082 chan = ieee80211_get_channel(local->hw.wiphy, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -070083 }
Johannes Berg7e9debe2009-06-15 13:42:25 +020084
85 if (!chan)
86 return -EINVAL;
87
88 if (chan->flags & IEEE80211_CHAN_DISABLED)
89 return -EINVAL;
90
91 /*
92 * no change except maybe auto -> fixed, ignore the HT
93 * setting so you can fix a channel you're on already
94 */
95 if (local->oper_channel == chan)
96 return 0;
97
98 if (sdata->vif.type == NL80211_IFTYPE_STATION)
99 ieee80211_sta_req_auth(sdata);
100
101 local->oper_channel = chan;
102 local->oper_channel_type = NL80211_CHAN_NO_HT;
103 ieee80211_hw_config(local, 0);
104
105 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700106}
107
108
109static int ieee80211_ioctl_giwfreq(struct net_device *dev,
110 struct iw_request_info *info,
111 struct iw_freq *freq, char *extra)
112{
113 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200114 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
115
116 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
117 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
Jiri Bencf0706e82007-05-05 11:45:53 -0700118
Johannes Berg77382312009-05-04 17:52:10 +0200119 freq->m = local->oper_channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700120 freq->e = 6;
121
122 return 0;
123}
124
125
126static int ieee80211_ioctl_siwessid(struct net_device *dev,
127 struct iw_request_info *info,
128 struct iw_point *data, char *ssid)
129{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200130 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700131 size_t len = data->length;
Johannes Berg46900292009-02-15 12:44:28 +0100132 int ret;
Jiri Bencf0706e82007-05-05 11:45:53 -0700133
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200134 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
135 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
136
Jiri Bencf0706e82007-05-05 11:45:53 -0700137 /* iwconfig uses nul termination in SSID.. */
138 if (len > 0 && ssid[len - 1] == '\0')
139 len--;
140
Johannes Berg46900292009-02-15 12:44:28 +0100141 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400142 if (data->flags)
Johannes Berg46900292009-02-15 12:44:28 +0100143 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400144 else
Johannes Berg46900292009-02-15 12:44:28 +0100145 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
146
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200147 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700148 if (ret)
149 return ret;
Johannes Berg46900292009-02-15 12:44:28 +0100150
Jouni Malinen636a5d32009-03-19 13:39:22 +0200151 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300152 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
Johannes Berg46900292009-02-15 12:44:28 +0100153 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700154 return 0;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200155 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700156
Jiri Bencf0706e82007-05-05 11:45:53 -0700157 return -EOPNOTSUPP;
158}
159
160
161static int ieee80211_ioctl_giwessid(struct net_device *dev,
162 struct iw_request_info *info,
163 struct iw_point *data, char *ssid)
164{
165 size_t len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700166 struct ieee80211_sub_if_data *sdata;
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200167
Jiri Bencf0706e82007-05-05 11:45:53 -0700168 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200169
170 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
171 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
172
Johannes Berg46900292009-02-15 12:44:28 +0100173 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200174 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700175 if (res == 0) {
176 data->length = len;
177 data->flags = 1;
178 } else
179 data->flags = 0;
180 return res;
181 }
182
Jiri Bencf0706e82007-05-05 11:45:53 -0700183 return -EOPNOTSUPP;
184}
185
186
187static int ieee80211_ioctl_siwap(struct net_device *dev,
188 struct iw_request_info *info,
189 struct sockaddr *ap_addr, char *extra)
190{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200191 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700192
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200193 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
194 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
195
Johannes Berg46900292009-02-15 12:44:28 +0100196 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700197 int ret;
Johannes Berg7986cf92009-03-21 17:08:43 +0100198
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400199 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100200 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400201 IEEE80211_STA_AUTO_CHANNEL_SEL;
202 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
Johannes Berg46900292009-02-15 12:44:28 +0100203 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700204 else
Johannes Berg46900292009-02-15 12:44:28 +0100205 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200206 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700207 if (ret)
208 return ret;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200209 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300210 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
Johannes Berg46900292009-02-15 12:44:28 +0100211 ieee80211_sta_req_auth(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700212 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200213 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100214 /*
215 * If it is necessary to update the WDS peer address
216 * while the interface is running, then we need to do
217 * more work here, namely if it is running we need to
218 * add a new and remove the old STA entry, this is
219 * normally handled by _open() and _stop().
220 */
221 if (netif_running(dev))
222 return -EBUSY;
223
224 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
225 ETH_ALEN);
226
227 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700228 }
229
230 return -EOPNOTSUPP;
231}
232
233
234static int ieee80211_ioctl_giwap(struct net_device *dev,
235 struct iw_request_info *info,
236 struct sockaddr *ap_addr, char *extra)
237{
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200238 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700239
Johannes Bergaf8cdcd2009-04-19 21:25:43 +0200240 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
241 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
242
Johannes Berg46900292009-02-15 12:44:28 +0100243 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
244 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700245 ap_addr->sa_family = ARPHRD_ETHER;
Johannes Berg46900292009-02-15 12:44:28 +0100246 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
247 } else
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700248 memset(&ap_addr->sa_data, 0, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100249 return 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200250 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700251 ap_addr->sa_family = ARPHRD_ETHER;
252 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
253 return 0;
254 }
255
256 return -EOPNOTSUPP;
257}
258
259
Larry Finger1fd5e582007-07-10 19:32:10 +0200260static int ieee80211_ioctl_siwrate(struct net_device *dev,
261 struct iw_request_info *info,
262 struct iw_param *rate, char *extra)
263{
264 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100265 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200266 u32 target_rate = rate->value / 100000;
267 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100268 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200269
270 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100271
272 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
273
Larry Finger1fd5e582007-07-10 19:32:10 +0200274 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
275 * target_rate = X, rate->fixed = 1 means only rate X
276 * target_rate = X, rate->fixed = 0 means all rates <= X */
Johannes Berg3e122be2008-07-09 14:40:34 +0200277 sdata->max_ratectrl_rateidx = -1;
278 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200279 if (rate->value < 0)
280 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100281
282 for (i=0; i< sband->n_bitrates; i++) {
283 struct ieee80211_rate *brate = &sband->bitrates[i];
284 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200285
Larry Finger1fd5e582007-07-10 19:32:10 +0200286 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200287 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200288 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200289 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100290 err = 0;
291 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200292 }
293 }
Johannes Berg8318d782008-01-24 19:38:38 +0100294 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200295}
296
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700297static int ieee80211_ioctl_giwrate(struct net_device *dev,
298 struct iw_request_info *info,
299 struct iw_param *rate, char *extra)
300{
301 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
302 struct sta_info *sta;
303 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100304 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700305
306 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100307
Johannes Berg05c914f2008-09-11 00:01:58 +0200308 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700309 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100310
311 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
312
Johannes Berg380a9422008-04-04 23:40:35 +0200313 rcu_read_lock();
314
Johannes Berg46900292009-02-15 12:44:28 +0100315 sta = sta_info_get(local, sdata->u.mgd.bssid);
Johannes Berg380a9422008-04-04 23:40:35 +0200316
Johannes Berge6a98542008-10-21 12:40:02 +0200317 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
318 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700319 else
320 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200321
322 rcu_read_unlock();
323
324 if (!sta)
325 return -ENODEV;
326
Johannes Berg8318d782008-01-24 19:38:38 +0100327 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100328
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700329 return 0;
330}
331
Samuel Ortiz49292d52008-07-04 10:49:31 +0200332static int ieee80211_ioctl_siwpower(struct net_device *dev,
333 struct iw_request_info *info,
334 struct iw_param *wrq,
335 char *extra)
336{
Kalle Valoe0cb6862008-12-18 23:35:13 +0200337 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200338 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
339 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg965beda2009-04-16 13:17:24 +0200340 int timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200341 bool ps;
342
Johannes Berg4be8c382009-01-07 18:28:20 +0100343 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
344 return -EOPNOTSUPP;
345
Kalle Valoe0cb6862008-12-18 23:35:13 +0200346 if (sdata->vif.type != NL80211_IFTYPE_STATION)
347 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200348
349 if (wrq->disabled) {
Kalle Valoe0cb6862008-12-18 23:35:13 +0200350 ps = false;
Kalle Valo520eb822008-12-18 23:35:27 +0200351 timeout = 0;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200352 goto set;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200353 }
354
355 switch (wrq->flags & IW_POWER_MODE) {
356 case IW_POWER_ON: /* If not specified */
357 case IW_POWER_MODE: /* If set all mask */
358 case IW_POWER_ALL_R: /* If explicitely state all */
Kalle Valoe0cb6862008-12-18 23:35:13 +0200359 ps = true;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200360 break;
Kalle Valo520eb822008-12-18 23:35:27 +0200361 default: /* Otherwise we ignore */
Johannes Berge9aeaba2009-01-06 18:12:35 +0100362 return -EINVAL;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200363 }
364
Johannes Berge9aeaba2009-01-06 18:12:35 +0100365 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
366 return -EINVAL;
367
Kalle Valo520eb822008-12-18 23:35:27 +0200368 if (wrq->flags & IW_POWER_TIMEOUT)
369 timeout = wrq->value / 1000;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200370
Johannes Berg4be8c382009-01-07 18:28:20 +0100371 set:
Johannes Berg965beda2009-04-16 13:17:24 +0200372 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
373 return 0;
Kalle Valo520eb822008-12-18 23:35:27 +0200374
Johannes Berg965beda2009-04-16 13:17:24 +0200375 sdata->u.mgd.powersave = ps;
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100376 conf->dynamic_ps_timeout = timeout;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200377
Johannes Berg4be8c382009-01-07 18:28:20 +0100378 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
Johannes Berge255d5e2009-04-22 12:40:07 +0200379 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg4be8c382009-01-07 18:28:20 +0100380
Johannes Berg10f644a2009-04-16 13:17:25 +0200381 ieee80211_recalc_ps(local, -1);
Johannes Berg4be8c382009-01-07 18:28:20 +0100382
Johannes Berg965beda2009-04-16 13:17:24 +0200383 return 0;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200384}
385
386static int ieee80211_ioctl_giwpower(struct net_device *dev,
387 struct iw_request_info *info,
388 union iwreq_data *wrqu,
389 char *extra)
390{
Johannes Berg965beda2009-04-16 13:17:24 +0200391 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Samuel Ortiz49292d52008-07-04 10:49:31 +0200392
Johannes Berg965beda2009-04-16 13:17:24 +0200393 wrqu->power.disabled = !sdata->u.mgd.powersave;
Samuel Ortiz49292d52008-07-04 10:49:31 +0200394
395 return 0;
396}
397
Jiri Bencf0706e82007-05-05 11:45:53 -0700398static int ieee80211_ioctl_siwauth(struct net_device *dev,
399 struct iw_request_info *info,
400 struct iw_param *data, char *extra)
401{
Jiri Bencf0706e82007-05-05 11:45:53 -0700402 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
403 int ret = 0;
404
405 switch (data->flags & IW_AUTH_INDEX) {
406 case IW_AUTH_WPA_VERSION:
Jiri Bencf0706e82007-05-05 11:45:53 -0700407 case IW_AUTH_CIPHER_GROUP:
408 case IW_AUTH_WPA_ENABLED:
409 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700410 case IW_AUTH_KEY_MGMT:
Jouni Malinen54604d32009-01-08 13:32:03 +0200411 case IW_AUTH_CIPHER_GROUP_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000412 break;
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530413 case IW_AUTH_CIPHER_PAIRWISE:
414 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
415 if (data->value & (IW_AUTH_CIPHER_WEP40 |
416 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
Johannes Berg46900292009-02-15 12:44:28 +0100417 sdata->u.mgd.flags |=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530418 IEEE80211_STA_TKIP_WEP_USED;
419 else
Johannes Berg46900292009-02-15 12:44:28 +0100420 sdata->u.mgd.flags &=
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530421 ~IEEE80211_STA_TKIP_WEP_USED;
422 }
423 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100424 case IW_AUTH_DROP_UNENCRYPTED:
425 sdata->drop_unencrypted = !!data->value;
426 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000427 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg05c914f2008-09-11 00:01:58 +0200428 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -0700429 ret = -EINVAL;
430 else {
Johannes Berg46900292009-02-15 12:44:28 +0100431 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700432 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000433 * Privacy invoked by wpa_supplicant, store the
434 * value and allow associating to a protected
435 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700436 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000437 if (data->value)
Johannes Berg46900292009-02-15 12:44:28 +0100438 sdata->u.mgd.flags |=
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000439 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700440 }
441 break;
442 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100443 if (sdata->vif.type == NL80211_IFTYPE_STATION)
444 sdata->u.mgd.auth_algs = data->value;
Jiri Bencf0706e82007-05-05 11:45:53 -0700445 else
446 ret = -EOPNOTSUPP;
447 break;
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200448 case IW_AUTH_MFP:
Jouni Malinen4375d082009-01-08 13:32:11 +0200449 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
450 ret = -EOPNOTSUPP;
451 break;
452 }
Johannes Berg46900292009-02-15 12:44:28 +0100453 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100454 switch (data->value) {
455 case IW_AUTH_MFP_DISABLED:
Johannes Berg46900292009-02-15 12:44:28 +0100456 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100457 break;
458 case IW_AUTH_MFP_OPTIONAL:
Johannes Berg46900292009-02-15 12:44:28 +0100459 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100460 break;
461 case IW_AUTH_MFP_REQUIRED:
Johannes Berg46900292009-02-15 12:44:28 +0100462 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
Johannes Berge4e5e2b2009-02-10 21:25:40 +0100463 break;
464 default:
465 ret = -EINVAL;
466 }
467 } else
Jouni Malinenfdfacf02009-01-08 13:32:05 +0200468 ret = -EOPNOTSUPP;
469 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700470 default:
471 ret = -EOPNOTSUPP;
472 break;
473 }
474 return ret;
475}
476
477/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
478static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
479{
480 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
481 struct iw_statistics *wstats = &local->wstats;
482 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
483 struct sta_info *sta = NULL;
484
Johannes Berg98dd6a52008-04-10 15:36:09 +0200485 rcu_read_lock();
486
Johannes Berg46900292009-02-15 12:44:28 +0100487 if (sdata->vif.type == NL80211_IFTYPE_STATION)
488 sta = sta_info_get(local, sdata->u.mgd.bssid);
489
Jiri Bencf0706e82007-05-05 11:45:53 -0700490 if (!sta) {
491 wstats->discard.fragment = 0;
492 wstats->discard.misc = 0;
493 wstats->qual.qual = 0;
494 wstats->qual.level = 0;
495 wstats->qual.noise = 0;
496 wstats->qual.updated = IW_QUAL_ALL_INVALID;
497 } else {
Johannes Berg24776cf2009-02-27 16:33:55 -0600498 wstats->qual.updated = 0;
499 /*
500 * mirror what cfg80211 does for iwrange/scan results,
501 * otherwise userspace gets confused.
502 */
503 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
504 IEEE80211_HW_SIGNAL_DBM)) {
505 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
506 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
507 } else {
508 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
509 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
510 }
511
512 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
513 wstats->qual.level = sta->last_signal;
514 wstats->qual.qual = sta->last_signal;
515 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
516 int sig = sta->last_signal;
517
518 wstats->qual.updated |= IW_QUAL_DBM;
519 wstats->qual.level = sig;
520 if (sig < -110)
521 sig = -110;
522 else if (sig > -40)
523 sig = -40;
524 wstats->qual.qual = sig + 110;
525 }
526
527 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
528 /*
529 * This assumes that if driver reports noise, it also
530 * reports signal in dBm.
531 */
532 wstats->qual.noise = sta->last_noise;
533 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
534 } else {
535 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
536 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700537 }
Johannes Berg98dd6a52008-04-10 15:36:09 +0200538
539 rcu_read_unlock();
540
Jiri Bencf0706e82007-05-05 11:45:53 -0700541 return wstats;
542}
543
544static int ieee80211_ioctl_giwauth(struct net_device *dev,
545 struct iw_request_info *info,
546 struct iw_param *data, char *extra)
547{
548 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
549 int ret = 0;
550
551 switch (data->flags & IW_AUTH_INDEX) {
552 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg46900292009-02-15 12:44:28 +0100553 if (sdata->vif.type == NL80211_IFTYPE_STATION)
554 data->value = sdata->u.mgd.auth_algs;
Jiri Bencf0706e82007-05-05 11:45:53 -0700555 else
556 ret = -EOPNOTSUPP;
557 break;
558 default:
559 ret = -EOPNOTSUPP;
560 break;
561 }
562 return ret;
563}
564
565
Jiri Bencf0706e82007-05-05 11:45:53 -0700566/* Structures to export the Wireless Handlers */
567
568static const iw_handler ieee80211_handler[] =
569{
570 (iw_handler) NULL, /* SIOCSIWCOMMIT */
Johannes Bergfee52672008-11-26 22:36:31 +0100571 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
Jiri Bencf0706e82007-05-05 11:45:53 -0700572 (iw_handler) NULL, /* SIOCSIWNWID */
573 (iw_handler) NULL, /* SIOCGIWNWID */
574 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
575 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
Johannes Berge60c7742008-11-26 23:31:40 +0100576 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
577 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700578 (iw_handler) NULL, /* SIOCSIWSENS */
579 (iw_handler) NULL, /* SIOCGIWSENS */
580 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
Johannes Berg4aa188e2009-02-18 19:32:08 +0100581 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700582 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
583 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
584 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
585 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -0400586 (iw_handler) NULL, /* SIOCSIWSPY */
587 (iw_handler) NULL, /* SIOCGIWSPY */
588 (iw_handler) NULL, /* SIOCSIWTHRSPY */
589 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -0700590 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
591 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
Johannes Berg691597c2009-04-19 19:57:45 +0200592 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
Jiri Bencf0706e82007-05-05 11:45:53 -0700593 (iw_handler) NULL, /* SIOCGIWAPLIST */
Johannes Berg2a519312009-02-10 21:25:55 +0100594 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
595 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
Jiri Bencf0706e82007-05-05 11:45:53 -0700596 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
597 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
598 (iw_handler) NULL, /* SIOCSIWNICKN */
599 (iw_handler) NULL, /* SIOCGIWNICKN */
600 (iw_handler) NULL, /* -- hole -- */
601 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +0200602 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700603 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200604 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
605 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
606 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
607 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
Johannes Berg7643a2c2009-06-02 13:01:39 +0200608 (iw_handler) cfg80211_wext_siwtxpower, /* SIOCSIWTXPOW */
609 (iw_handler) cfg80211_wext_giwtxpower, /* SIOCGIWTXPOW */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200610 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
611 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
Johannes Berg08645122009-05-11 13:54:58 +0200612 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
613 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
Samuel Ortiz49292d52008-07-04 10:49:31 +0200614 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
615 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -0700616 (iw_handler) NULL, /* -- hole -- */
617 (iw_handler) NULL, /* -- hole -- */
618 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
619 (iw_handler) NULL, /* SIOCGIWGENIE */
620 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
621 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
Johannes Berg08645122009-05-11 13:54:58 +0200622 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
Jiri Bencf0706e82007-05-05 11:45:53 -0700623 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
624 (iw_handler) NULL, /* SIOCSIWPMKSA */
625 (iw_handler) NULL, /* -- hole -- */
626};
627
Jiri Bencf0706e82007-05-05 11:45:53 -0700628const struct iw_handler_def ieee80211_iw_handler_def =
629{
630 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -0700631 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -0700632 .get_wireless_stats = ieee80211_get_wireless_stats,
633};