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_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 Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 35 | |
| 36 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 37 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 38 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 39 | int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 40 | if (ret) |
| 41 | return ret; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 42 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 43 | sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 44 | ieee80211_sta_req_auth(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 48 | return -EOPNOTSUPP; |
| 49 | } |
| 50 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 51 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
| 52 | struct iw_request_info *info, |
| 53 | struct iw_freq *freq, char *extra) |
| 54 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 55 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 56 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 57 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 58 | return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 59 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 60 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 61 | |
| 62 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ |
| 63 | if (freq->e == 0) { |
| 64 | if (freq->m < 0) { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 65 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 66 | sdata->u.mgd.flags |= |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 67 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 68 | return 0; |
| 69 | } else |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 70 | return ieee80211_set_freq(sdata, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 71 | ieee80211_channel_to_frequency(freq->m)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 72 | } else { |
| 73 | int i, div = 1000000; |
| 74 | for (i = 0; i < freq->e; i++) |
| 75 | div /= 10; |
| 76 | if (div > 0) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 77 | return ieee80211_set_freq(sdata, freq->m / div); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 78 | else |
| 79 | return -EINVAL; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | |
| 84 | static 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 Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 89 | 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 Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 93 | |
Johannes Berg | 7738231 | 2009-05-04 17:52:10 +0200 | [diff] [blame] | 94 | freq->m = local->oper_channel->center_freq; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 95 | freq->e = 6; |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | static int ieee80211_ioctl_siwessid(struct net_device *dev, |
| 102 | struct iw_request_info *info, |
| 103 | struct iw_point *data, char *ssid) |
| 104 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 105 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 106 | size_t len = data->length; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 107 | int ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 108 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 109 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 110 | return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); |
| 111 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 112 | /* iwconfig uses nul termination in SSID.. */ |
| 113 | if (len > 0 && ssid[len - 1] == '\0') |
| 114 | len--; |
| 115 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 116 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 117 | if (data->flags) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 118 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 119 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 120 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL; |
| 121 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 122 | ret = ieee80211_sta_set_ssid(sdata, ssid, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 123 | if (ret) |
| 124 | return ret; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 125 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 126 | sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 127 | ieee80211_sta_req_auth(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 128 | return 0; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 129 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 130 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 131 | return -EOPNOTSUPP; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | static 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 Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 140 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 141 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 142 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 143 | |
| 144 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 145 | return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); |
| 146 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 147 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 148 | int res = ieee80211_sta_get_ssid(sdata, ssid, &len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 149 | if (res == 0) { |
| 150 | data->length = len; |
| 151 | data->flags = 1; |
| 152 | } else |
| 153 | data->flags = 0; |
| 154 | return res; |
| 155 | } |
| 156 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 157 | return -EOPNOTSUPP; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | static int ieee80211_ioctl_siwap(struct net_device *dev, |
| 162 | struct iw_request_info *info, |
| 163 | struct sockaddr *ap_addr, char *extra) |
| 164 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 165 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 166 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 167 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 168 | return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); |
| 169 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 170 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 171 | int ret; |
Johannes Berg | 7986cf9 | 2009-03-21 17:08:43 +0100 | [diff] [blame] | 172 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 173 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 174 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 175 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
| 176 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 177 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 178 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 179 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 180 | ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 181 | if (ret) |
| 182 | return ret; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 183 | sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 184 | ieee80211_sta_req_auth(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 185 | return 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 186 | } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 187 | /* |
| 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 Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | return -EOPNOTSUPP; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | static int ieee80211_ioctl_giwap(struct net_device *dev, |
| 208 | struct iw_request_info *info, |
| 209 | struct sockaddr *ap_addr, char *extra) |
| 210 | { |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 211 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 212 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 213 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 214 | return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); |
| 215 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 216 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
| 217 | if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) { |
Abhijeet Kolekar | d4231ca | 2008-05-23 10:15:26 -0700 | [diff] [blame] | 218 | ap_addr->sa_family = ARPHRD_ETHER; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 219 | memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN); |
| 220 | } else |
Abhijeet Kolekar | d4231ca | 2008-05-23 10:15:26 -0700 | [diff] [blame] | 221 | memset(&ap_addr->sa_data, 0, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 222 | return 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 223 | } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 224 | 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 Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 233 | static 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 Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 238 | int i, err = -EINVAL; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 239 | u32 target_rate = rate->value / 100000; |
| 240 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 241 | struct ieee80211_supported_band *sband; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 242 | |
| 243 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 244 | |
| 245 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 246 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 247 | /* 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 Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 250 | sdata->max_ratectrl_rateidx = -1; |
| 251 | sdata->force_unicast_rateidx = -1; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 252 | if (rate->value < 0) |
| 253 | return 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 254 | |
| 255 | for (i=0; i< sband->n_bitrates; i++) { |
| 256 | struct ieee80211_rate *brate = &sband->bitrates[i]; |
| 257 | int this_rate = brate->bitrate; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 258 | |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 259 | if (target_rate == this_rate) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 260 | sdata->max_ratectrl_rateidx = i; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 261 | if (rate->fixed) |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 262 | sdata->force_unicast_rateidx = i; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 263 | err = 0; |
| 264 | break; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 265 | } |
| 266 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 267 | return err; |
Larry Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 268 | } |
| 269 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 270 | static 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 Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 277 | struct ieee80211_supported_band *sband; |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 278 | |
| 279 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 280 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 281 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 282 | return -EOPNOTSUPP; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 283 | |
| 284 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 285 | |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 286 | rcu_read_lock(); |
| 287 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 288 | sta = sta_info_get(local, sdata->u.mgd.bssid); |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 289 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 290 | if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) |
| 291 | rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate; |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 292 | else |
| 293 | rate->value = 0; |
Johannes Berg | 380a942 | 2008-04-04 23:40:35 +0200 | [diff] [blame] | 294 | |
| 295 | rcu_read_unlock(); |
| 296 | |
| 297 | if (!sta) |
| 298 | return -ENODEV; |
| 299 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 300 | rate->value *= 100000; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 301 | |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 305 | static 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. Rodriguez | d9d2925 | 2008-10-22 13:13:53 -0700 | [diff] [blame] | 310 | struct ieee80211_channel* chan = local->hw.conf.channel; |
Johannes Berg | 47afbaf | 2009-04-07 15:22:28 +0200 | [diff] [blame] | 311 | bool reconf = false; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 312 | u32 reconf_flags = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 313 | int new_power_level; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 314 | |
| 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. Rodriguez | d9d2925 | 2008-10-22 13:13:53 -0700 | [diff] [blame] | 319 | if (!chan) |
| 320 | return -EINVAL; |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 321 | |
Johannes Berg | 47afbaf | 2009-04-07 15:22:28 +0200 | [diff] [blame] | 322 | /* 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 Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 345 | |
Johannes Berg | 47afbaf | 2009-04-07 15:22:28 +0200 | [diff] [blame] | 346 | 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 Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 354 | |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 355 | if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { |
| 356 | local->hw.conf.radio_enabled = !(data->txpower.disabled); |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 357 | reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED; |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 358 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 359 | } |
Mattias Nissler | 6a43295 | 2007-10-24 23:30:36 +0200 | [diff] [blame] | 360 | |
Johannes Berg | 47afbaf | 2009-04-07 15:22:28 +0200 | [diff] [blame] | 361 | if (reconf || reconf_flags) |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 362 | ieee80211_hw_config(local, reconf_flags); |
Michael Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 367 | static 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 Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 381 | static int ieee80211_ioctl_siwpower(struct net_device *dev, |
| 382 | struct iw_request_info *info, |
| 383 | struct iw_param *wrq, |
| 384 | char *extra) |
| 385 | { |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 386 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 387 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 388 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 389 | int timeout = 0; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 390 | bool ps; |
| 391 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 392 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) |
| 393 | return -EOPNOTSUPP; |
| 394 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 395 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 396 | return -EINVAL; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 397 | |
| 398 | if (wrq->disabled) { |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 399 | ps = false; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 400 | timeout = 0; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 401 | goto set; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 402 | } |
| 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 Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 408 | ps = true; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 409 | break; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 410 | default: /* Otherwise we ignore */ |
Johannes Berg | e9aeaba | 2009-01-06 18:12:35 +0100 | [diff] [blame] | 411 | return -EINVAL; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 412 | } |
| 413 | |
Johannes Berg | e9aeaba | 2009-01-06 18:12:35 +0100 | [diff] [blame] | 414 | if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT)) |
| 415 | return -EINVAL; |
| 416 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 417 | if (wrq->flags & IW_POWER_TIMEOUT) |
| 418 | timeout = wrq->value / 1000; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 419 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 420 | set: |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 421 | if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout) |
| 422 | return 0; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 423 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 424 | sdata->u.mgd.powersave = ps; |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 425 | conf->dynamic_ps_timeout = timeout; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 426 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 427 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
Johannes Berg | e255d5e | 2009-04-22 12:40:07 +0200 | [diff] [blame] | 428 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 429 | |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 430 | ieee80211_recalc_ps(local, -1); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 431 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 432 | return 0; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static int ieee80211_ioctl_giwpower(struct net_device *dev, |
| 436 | struct iw_request_info *info, |
| 437 | union iwreq_data *wrqu, |
| 438 | char *extra) |
| 439 | { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 440 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 441 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 442 | wrqu->power.disabled = !sdata->u.mgd.powersave; |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 447 | static int ieee80211_ioctl_siwauth(struct net_device *dev, |
| 448 | struct iw_request_info *info, |
| 449 | struct iw_param *data, char *extra) |
| 450 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 451 | 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 Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 456 | case IW_AUTH_CIPHER_GROUP: |
| 457 | case IW_AUTH_WPA_ENABLED: |
| 458 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 459 | case IW_AUTH_KEY_MGMT: |
Jouni Malinen | 54604d3 | 2009-01-08 13:32:03 +0200 | [diff] [blame] | 460 | case IW_AUTH_CIPHER_GROUP_MGMT: |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 461 | break; |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 462 | 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 Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 466 | sdata->u.mgd.flags |= |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 467 | IEEE80211_STA_TKIP_WEP_USED; |
| 468 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 469 | sdata->u.mgd.flags &= |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 470 | ~IEEE80211_STA_TKIP_WEP_USED; |
| 471 | } |
| 472 | break; |
Johannes Berg | b1357a8 | 2007-11-28 11:04:21 +0100 | [diff] [blame] | 473 | case IW_AUTH_DROP_UNENCRYPTED: |
| 474 | sdata->drop_unencrypted = !!data->value; |
| 475 | break; |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 476 | case IW_AUTH_PRIVACY_INVOKED: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 477 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 478 | ret = -EINVAL; |
| 479 | else { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 480 | sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 481 | /* |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 482 | * Privacy invoked by wpa_supplicant, store the |
| 483 | * value and allow associating to a protected |
| 484 | * network without having a key up front. |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 485 | */ |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 486 | if (data->value) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 487 | sdata->u.mgd.flags |= |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 488 | IEEE80211_STA_PRIVACY_INVOKED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 489 | } |
| 490 | break; |
| 491 | case IW_AUTH_80211_AUTH_ALG: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 492 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 493 | sdata->u.mgd.auth_algs = data->value; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 494 | else |
| 495 | ret = -EOPNOTSUPP; |
| 496 | break; |
Jouni Malinen | fdfacf0 | 2009-01-08 13:32:05 +0200 | [diff] [blame] | 497 | case IW_AUTH_MFP: |
Jouni Malinen | 4375d08 | 2009-01-08 13:32:11 +0200 | [diff] [blame] | 498 | if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) { |
| 499 | ret = -EOPNOTSUPP; |
| 500 | break; |
| 501 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 502 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | e4e5e2b | 2009-02-10 21:25:40 +0100 | [diff] [blame] | 503 | switch (data->value) { |
| 504 | case IW_AUTH_MFP_DISABLED: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 505 | sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED; |
Johannes Berg | e4e5e2b | 2009-02-10 21:25:40 +0100 | [diff] [blame] | 506 | break; |
| 507 | case IW_AUTH_MFP_OPTIONAL: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 508 | sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL; |
Johannes Berg | e4e5e2b | 2009-02-10 21:25:40 +0100 | [diff] [blame] | 509 | break; |
| 510 | case IW_AUTH_MFP_REQUIRED: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 511 | sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED; |
Johannes Berg | e4e5e2b | 2009-02-10 21:25:40 +0100 | [diff] [blame] | 512 | break; |
| 513 | default: |
| 514 | ret = -EINVAL; |
| 515 | } |
| 516 | } else |
Jouni Malinen | fdfacf0 | 2009-01-08 13:32:05 +0200 | [diff] [blame] | 517 | ret = -EOPNOTSUPP; |
| 518 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 519 | default: |
| 520 | ret = -EOPNOTSUPP; |
| 521 | break; |
| 522 | } |
| 523 | return ret; |
| 524 | } |
| 525 | |
| 526 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
| 527 | static 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 Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 534 | rcu_read_lock(); |
| 535 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 536 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 537 | sta = sta_info_get(local, sdata->u.mgd.bssid); |
| 538 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 539 | 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 Berg | 24776cf | 2009-02-27 16:33:55 -0600 | [diff] [blame] | 547 | 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 Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 586 | } |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 587 | |
| 588 | rcu_read_unlock(); |
| 589 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 590 | return wstats; |
| 591 | } |
| 592 | |
| 593 | static 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 Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 602 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 603 | data->value = sdata->u.mgd.auth_algs; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 604 | else |
| 605 | ret = -EOPNOTSUPP; |
| 606 | break; |
| 607 | default: |
| 608 | ret = -EOPNOTSUPP; |
| 609 | break; |
| 610 | } |
| 611 | return ret; |
| 612 | } |
| 613 | |
| 614 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 615 | /* Structures to export the Wireless Handlers */ |
| 616 | |
| 617 | static const iw_handler ieee80211_handler[] = |
| 618 | { |
| 619 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 620 | (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 621 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 622 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 623 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ |
| 624 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 625 | (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */ |
| 626 | (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 627 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 628 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 629 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 630 | (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 631 | (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 Berg | 5d4ecd9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 635 | (iw_handler) NULL, /* SIOCSIWSPY */ |
| 636 | (iw_handler) NULL, /* SIOCGIWSPY */ |
| 637 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ |
| 638 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 639 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
| 640 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 641 | (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 642 | (iw_handler) NULL, /* SIOCGIWAPLIST */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 643 | (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */ |
| 644 | (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 645 | (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 Finger | 1fd5e58 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 651 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
Larry Finger | b3d88ad | 2007-06-10 17:57:33 -0700 | [diff] [blame] | 652 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 653 | (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 Buesch | 61609bc | 2007-09-20 22:06:39 +0200 | [diff] [blame] | 657 | (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ |
Larry Finger | fe6aa30 | 2007-08-10 11:23:20 -0500 | [diff] [blame] | 658 | (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 659 | (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */ |
| 660 | (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */ |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame^] | 661 | (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */ |
| 662 | (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */ |
Samuel Ortiz | 49292d5 | 2008-07-04 10:49:31 +0200 | [diff] [blame] | 663 | (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ |
| 664 | (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 665 | (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 Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame^] | 671 | (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 672 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ |
| 673 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 674 | (iw_handler) NULL, /* -- hole -- */ |
| 675 | }; |
| 676 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 677 | const struct iw_handler_def ieee80211_iw_handler_def = |
| 678 | { |
| 679 | .num_standard = ARRAY_SIZE(ieee80211_handler), |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 680 | .standard = (iw_handler *) ieee80211_handler, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 681 | .get_wireless_stats = ieee80211_get_wireless_stats, |
| 682 | }; |