Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 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 Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 24 | #include "led.h" |
| 25 | #include "rate.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 26 | #include "wpa.h" |
| 27 | #include "aes_ccm.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | |
Johannes Berg | b708e61 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 29 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
| 31 | struct iw_request_info *info, |
| 32 | struct iw_freq *freq, char *extra) |
| 33 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 34 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 35 | struct ieee80211_local *local = sdata->local; |
| 36 | struct ieee80211_channel *chan; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 37 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 38 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 39 | return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 40 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 41 | return cfg80211_mgd_wext_siwfreq(dev, info, freq, extra); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 42 | |
| 43 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ |
| 44 | if (freq->e == 0) { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 45 | if (freq->m < 0) |
| 46 | return -EINVAL; |
| 47 | else |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 48 | chan = ieee80211_get_channel(local->hw.wiphy, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 49 | ieee80211_channel_to_frequency(freq->m)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 50 | } else { |
| 51 | int i, div = 1000000; |
| 52 | for (i = 0; i < freq->e; i++) |
| 53 | div /= 10; |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 54 | if (div <= 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 55 | return -EINVAL; |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 56 | chan = ieee80211_get_channel(local->hw.wiphy, freq->m / div); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 57 | } |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 58 | |
| 59 | if (!chan) |
| 60 | return -EINVAL; |
| 61 | |
| 62 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 63 | return -EINVAL; |
| 64 | |
| 65 | /* |
| 66 | * no change except maybe auto -> fixed, ignore the HT |
| 67 | * setting so you can fix a channel you're on already |
| 68 | */ |
| 69 | if (local->oper_channel == chan) |
| 70 | return 0; |
| 71 | |
Johannes Berg | 7e9debe | 2009-06-15 13:42:25 +0200 | [diff] [blame] | 72 | local->oper_channel = chan; |
| 73 | local->oper_channel_type = NL80211_CHAN_NO_HT; |
| 74 | ieee80211_hw_config(local, 0); |
| 75 | |
| 76 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
| 80 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, |
| 81 | struct iw_request_info *info, |
| 82 | struct iw_freq *freq, char *extra) |
| 83 | { |
| 84 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 85 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 86 | |
| 87 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 88 | return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 89 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 90 | return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 91 | |
Johannes Berg | 7738231 | 2009-05-04 17:52:10 +0200 | [diff] [blame] | 92 | freq->m = local->oper_channel->center_freq; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 93 | freq->e = 6; |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | static int ieee80211_ioctl_siwessid(struct net_device *dev, |
| 100 | struct iw_request_info *info, |
| 101 | struct iw_point *data, char *ssid) |
| 102 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 103 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 104 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 105 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 106 | return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 107 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 108 | return cfg80211_mgd_wext_siwessid(dev, info, data, ssid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 109 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 110 | return -EOPNOTSUPP; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | static int ieee80211_ioctl_giwessid(struct net_device *dev, |
| 115 | struct iw_request_info *info, |
| 116 | struct iw_point *data, char *ssid) |
| 117 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 118 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 119 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 120 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 121 | |
| 122 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 123 | return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 124 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 125 | return cfg80211_mgd_wext_giwessid(dev, info, data, ssid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 126 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 127 | return -EOPNOTSUPP; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | static int ieee80211_ioctl_siwap(struct net_device *dev, |
| 132 | struct iw_request_info *info, |
| 133 | struct sockaddr *ap_addr, char *extra) |
| 134 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 135 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 136 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 137 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 138 | return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); |
| 139 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 140 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 141 | return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra); |
Johannes Berg | 7986cf9 | 2009-03-21 17:08:43 +0100 | [diff] [blame] | 142 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 143 | if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 144 | /* |
| 145 | * If it is necessary to update the WDS peer address |
| 146 | * while the interface is running, then we need to do |
| 147 | * more work here, namely if it is running we need to |
| 148 | * add a new and remove the old STA entry, this is |
| 149 | * normally handled by _open() and _stop(). |
| 150 | */ |
| 151 | if (netif_running(dev)) |
| 152 | return -EBUSY; |
| 153 | |
| 154 | memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, |
| 155 | ETH_ALEN); |
| 156 | |
| 157 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | return -EOPNOTSUPP; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | static int ieee80211_ioctl_giwap(struct net_device *dev, |
| 165 | struct iw_request_info *info, |
| 166 | struct sockaddr *ap_addr, char *extra) |
| 167 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 168 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 169 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 170 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 171 | return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); |
| 172 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 173 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 174 | return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra); |
| 175 | |
| 176 | if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 177 | ap_addr->sa_family = ARPHRD_ETHER; |
| 178 | memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | return -EOPNOTSUPP; |
| 183 | } |
| 184 | |
| 185 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 186 | static int ieee80211_ioctl_siwrate(struct net_device *dev, |
| 187 | struct iw_request_info *info, |
| 188 | struct iw_param *rate, char *extra) |
| 189 | { |
| 190 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 191 | int i, err = -EINVAL; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 192 | u32 target_rate = rate->value / 100000; |
| 193 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 194 | struct ieee80211_supported_band *sband; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 195 | |
| 196 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 197 | |
| 198 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 199 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 200 | /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates |
| 201 | * target_rate = X, rate->fixed = 1 means only rate X |
| 202 | * target_rate = X, rate->fixed = 0 means all rates <= X */ |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 203 | sdata->max_ratectrl_rateidx = -1; |
| 204 | sdata->force_unicast_rateidx = -1; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 205 | if (rate->value < 0) |
| 206 | return 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 207 | |
| 208 | for (i=0; i< sband->n_bitrates; i++) { |
| 209 | struct ieee80211_rate *brate = &sband->bitrates[i]; |
| 210 | int this_rate = brate->bitrate; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 211 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 212 | if (target_rate == this_rate) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 213 | sdata->max_ratectrl_rateidx = i; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 214 | if (rate->fixed) |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 215 | sdata->force_unicast_rateidx = i; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 216 | err = 0; |
| 217 | break; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 218 | } |
| 219 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 220 | return err; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 223 | static int ieee80211_ioctl_giwrate(struct net_device *dev, |
| 224 | struct iw_request_info *info, |
| 225 | struct iw_param *rate, char *extra) |
| 226 | { |
| 227 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 228 | struct sta_info *sta; |
| 229 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 230 | struct ieee80211_supported_band *sband; |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 231 | |
| 232 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 233 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 234 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 235 | return -EOPNOTSUPP; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 236 | |
| 237 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 238 | |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 239 | rcu_read_lock(); |
| 240 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 241 | sta = sta_info_get(local, sdata->u.mgd.bssid); |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 242 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 243 | if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) |
| 244 | rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate; |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 245 | else |
| 246 | rate->value = 0; |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 247 | |
| 248 | rcu_read_unlock(); |
| 249 | |
| 250 | if (!sta) |
| 251 | return -ENODEV; |
| 252 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 253 | rate->value *= 100000; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 254 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 258 | static int ieee80211_ioctl_siwpower(struct net_device *dev, |
| 259 | struct iw_request_info *info, |
| 260 | struct iw_param *wrq, |
| 261 | char *extra) |
| 262 | { |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 263 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 264 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 265 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 266 | int timeout = 0; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 267 | bool ps; |
| 268 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 269 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) |
| 270 | return -EOPNOTSUPP; |
| 271 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 272 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 273 | return -EINVAL; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 274 | |
| 275 | if (wrq->disabled) { |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 276 | ps = false; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 277 | timeout = 0; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 278 | goto set; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | switch (wrq->flags & IW_POWER_MODE) { |
| 282 | case IW_POWER_ON: /* If not specified */ |
| 283 | case IW_POWER_MODE: /* If set all mask */ |
| 284 | case IW_POWER_ALL_R: /* If explicitely state all */ |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 285 | ps = true; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 286 | break; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 287 | default: /* Otherwise we ignore */ |
Johannes Berg | e9aeaba | 2009-01-06 18:12:35 +0100 | [diff] [blame] | 288 | return -EINVAL; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Johannes Berg | e9aeaba | 2009-01-06 18:12:35 +0100 | [diff] [blame] | 291 | if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT)) |
| 292 | return -EINVAL; |
| 293 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 294 | if (wrq->flags & IW_POWER_TIMEOUT) |
| 295 | timeout = wrq->value / 1000; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 296 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 297 | set: |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 298 | if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout) |
| 299 | return 0; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 300 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 301 | sdata->u.mgd.powersave = ps; |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 302 | conf->dynamic_ps_timeout = timeout; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 303 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 304 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
Johannes Berg | e255d5e | 2009-04-22 12:40:07 +0200 | [diff] [blame] | 305 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 306 | |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 307 | ieee80211_recalc_ps(local, -1); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 308 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 309 | return 0; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static int ieee80211_ioctl_giwpower(struct net_device *dev, |
| 313 | struct iw_request_info *info, |
| 314 | union iwreq_data *wrqu, |
| 315 | char *extra) |
| 316 | { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 317 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 318 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 319 | wrqu->power.disabled = !sdata->u.mgd.powersave; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 324 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
| 325 | static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev) |
| 326 | { |
| 327 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 328 | struct iw_statistics *wstats = &local->wstats; |
| 329 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 330 | struct sta_info *sta = NULL; |
| 331 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 332 | rcu_read_lock(); |
| 333 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 334 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 335 | sta = sta_info_get(local, sdata->u.mgd.bssid); |
| 336 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 337 | if (!sta) { |
| 338 | wstats->discard.fragment = 0; |
| 339 | wstats->discard.misc = 0; |
| 340 | wstats->qual.qual = 0; |
| 341 | wstats->qual.level = 0; |
| 342 | wstats->qual.noise = 0; |
| 343 | wstats->qual.updated = IW_QUAL_ALL_INVALID; |
| 344 | } else { |
Johannes Berg | 24776cf | 2009-02-27 16:33:55 -0600 | [diff] [blame] | 345 | wstats->qual.updated = 0; |
| 346 | /* |
| 347 | * mirror what cfg80211 does for iwrange/scan results, |
| 348 | * otherwise userspace gets confused. |
| 349 | */ |
| 350 | if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC | |
| 351 | IEEE80211_HW_SIGNAL_DBM)) { |
| 352 | wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 353 | wstats->qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 354 | } else { |
| 355 | wstats->qual.updated |= IW_QUAL_LEVEL_INVALID; |
| 356 | wstats->qual.updated |= IW_QUAL_QUAL_INVALID; |
| 357 | } |
| 358 | |
| 359 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) { |
| 360 | wstats->qual.level = sta->last_signal; |
| 361 | wstats->qual.qual = sta->last_signal; |
| 362 | } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) { |
| 363 | int sig = sta->last_signal; |
| 364 | |
| 365 | wstats->qual.updated |= IW_QUAL_DBM; |
| 366 | wstats->qual.level = sig; |
| 367 | if (sig < -110) |
| 368 | sig = -110; |
| 369 | else if (sig > -40) |
| 370 | sig = -40; |
| 371 | wstats->qual.qual = sig + 110; |
| 372 | } |
| 373 | |
| 374 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) { |
| 375 | /* |
| 376 | * This assumes that if driver reports noise, it also |
| 377 | * reports signal in dBm. |
| 378 | */ |
| 379 | wstats->qual.noise = sta->last_noise; |
| 380 | wstats->qual.updated |= IW_QUAL_NOISE_UPDATED; |
| 381 | } else { |
| 382 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID; |
| 383 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 384 | } |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 385 | |
| 386 | rcu_read_unlock(); |
| 387 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 388 | return wstats; |
| 389 | } |
| 390 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 391 | /* Structures to export the Wireless Handlers */ |
| 392 | |
| 393 | static const iw_handler ieee80211_handler[] = |
| 394 | { |
| 395 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 396 | (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 397 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 398 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 399 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ |
| 400 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 401 | (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */ |
| 402 | (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 403 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 404 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 405 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 406 | (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 407 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ |
| 408 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ |
| 409 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ |
| 410 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ |
Johannes Berg | 5d4ecd9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 411 | (iw_handler) NULL, /* SIOCSIWSPY */ |
| 412 | (iw_handler) NULL, /* SIOCGIWSPY */ |
| 413 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ |
| 414 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 415 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
| 416 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 417 | (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 418 | (iw_handler) NULL, /* SIOCGIWAPLIST */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 419 | (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */ |
| 420 | (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 421 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ |
| 422 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ |
| 423 | (iw_handler) NULL, /* SIOCSIWNICKN */ |
| 424 | (iw_handler) NULL, /* SIOCGIWNICKN */ |
| 425 | (iw_handler) NULL, /* -- hole -- */ |
| 426 | (iw_handler) NULL, /* -- hole -- */ |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 427 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 428 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 429 | (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */ |
| 430 | (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */ |
| 431 | (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */ |
| 432 | (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */ |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 433 | (iw_handler) cfg80211_wext_siwtxpower, /* SIOCSIWTXPOW */ |
| 434 | (iw_handler) cfg80211_wext_giwtxpower, /* SIOCGIWTXPOW */ |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 435 | (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */ |
| 436 | (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */ |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 437 | (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */ |
| 438 | (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */ |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 439 | (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ |
| 440 | (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 441 | (iw_handler) NULL, /* -- hole -- */ |
| 442 | (iw_handler) NULL, /* -- hole -- */ |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 443 | (iw_handler) cfg80211_wext_siwgenie, /* SIOCSIWGENIE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 444 | (iw_handler) NULL, /* SIOCGIWGENIE */ |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame^] | 445 | (iw_handler) cfg80211_wext_siwauth, /* SIOCSIWAUTH */ |
| 446 | (iw_handler) cfg80211_wext_giwauth, /* SIOCGIWAUTH */ |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 447 | (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 448 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ |
| 449 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 450 | (iw_handler) NULL, /* -- hole -- */ |
| 451 | }; |
| 452 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 453 | const struct iw_handler_def ieee80211_iw_handler_def = |
| 454 | { |
| 455 | .num_standard = ARRAY_SIZE(ieee80211_handler), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 456 | .standard = (iw_handler *) ieee80211_handler, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 457 | .get_wireless_stats = ieee80211_get_wireless_stats, |
| 458 | }; |