Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * cfg80211 - wext compat code |
| 3 | * |
| 4 | * This is temporary code until all wireless functionality is migrated |
| 5 | * into cfg80211, when that happens all the exports here go away and |
| 6 | * we directly assign the wireless handlers of wireless interfaces. |
| 7 | * |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 8 | * Copyright 2008-2009 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 12 | #include <linux/wireless.h> |
| 13 | #include <linux/nl80211.h> |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 14 | #include <linux/if_arp.h> |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 15 | #include <linux/etherdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 17 | #include <net/iw_handler.h> |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 18 | #include <net/cfg80211.h> |
Johannes Berg | 262eb9b2 | 2011-07-13 10:39:09 +0200 | [diff] [blame] | 19 | #include <net/cfg80211-wext.h> |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 20 | #include "wext-compat.h" |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 21 | #include "core.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 22 | #include "rdev-ops.h" |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 23 | |
| 24 | int cfg80211_wext_giwname(struct net_device *dev, |
| 25 | struct iw_request_info *info, |
| 26 | char *name, char *extra) |
| 27 | { |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 28 | strcpy(name, "IEEE 802.11"); |
Johannes Berg | fee5267 | 2008-11-26 22:36:31 +0100 | [diff] [blame] | 29 | return 0; |
| 30 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 31 | EXPORT_WEXT_HANDLER(cfg80211_wext_giwname); |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 32 | |
| 33 | int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info, |
| 34 | u32 *mode, char *extra) |
| 35 | { |
| 36 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 37 | struct cfg80211_registered_device *rdev; |
| 38 | struct vif_params vifparams; |
| 39 | enum nl80211_iftype type; |
| 40 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 41 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 42 | |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 43 | switch (*mode) { |
| 44 | case IW_MODE_INFRA: |
| 45 | type = NL80211_IFTYPE_STATION; |
| 46 | break; |
| 47 | case IW_MODE_ADHOC: |
| 48 | type = NL80211_IFTYPE_ADHOC; |
| 49 | break; |
| 50 | case IW_MODE_REPEAT: |
| 51 | type = NL80211_IFTYPE_WDS; |
| 52 | break; |
| 53 | case IW_MODE_MONITOR: |
| 54 | type = NL80211_IFTYPE_MONITOR; |
| 55 | break; |
| 56 | default: |
| 57 | return -EINVAL; |
| 58 | } |
| 59 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 60 | if (type == wdev->iftype) |
| 61 | return 0; |
| 62 | |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 63 | memset(&vifparams, 0, sizeof(vifparams)); |
| 64 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 65 | return cfg80211_change_iface(rdev, dev, type, NULL, &vifparams); |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 66 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 67 | EXPORT_WEXT_HANDLER(cfg80211_wext_siwmode); |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 68 | |
| 69 | int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info, |
| 70 | u32 *mode, char *extra) |
| 71 | { |
| 72 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 73 | |
| 74 | if (!wdev) |
| 75 | return -EOPNOTSUPP; |
| 76 | |
| 77 | switch (wdev->iftype) { |
| 78 | case NL80211_IFTYPE_AP: |
| 79 | *mode = IW_MODE_MASTER; |
| 80 | break; |
| 81 | case NL80211_IFTYPE_STATION: |
| 82 | *mode = IW_MODE_INFRA; |
| 83 | break; |
| 84 | case NL80211_IFTYPE_ADHOC: |
| 85 | *mode = IW_MODE_ADHOC; |
| 86 | break; |
| 87 | case NL80211_IFTYPE_MONITOR: |
| 88 | *mode = IW_MODE_MONITOR; |
| 89 | break; |
| 90 | case NL80211_IFTYPE_WDS: |
| 91 | *mode = IW_MODE_REPEAT; |
| 92 | break; |
| 93 | case NL80211_IFTYPE_AP_VLAN: |
| 94 | *mode = IW_MODE_SECOND; /* FIXME */ |
| 95 | break; |
| 96 | default: |
| 97 | *mode = IW_MODE_AUTO; |
| 98 | break; |
| 99 | } |
| 100 | return 0; |
| 101 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 102 | EXPORT_WEXT_HANDLER(cfg80211_wext_giwmode); |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 103 | |
| 104 | |
| 105 | int cfg80211_wext_giwrange(struct net_device *dev, |
| 106 | struct iw_request_info *info, |
| 107 | struct iw_point *data, char *extra) |
| 108 | { |
| 109 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 110 | struct iw_range *range = (struct iw_range *) extra; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 111 | enum nl80211_band band; |
Johannes Berg | 9834c07 | 2009-07-06 19:40:51 +0200 | [diff] [blame] | 112 | int i, c = 0; |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 113 | |
| 114 | if (!wdev) |
| 115 | return -EOPNOTSUPP; |
| 116 | |
| 117 | data->length = sizeof(struct iw_range); |
| 118 | memset(range, 0, sizeof(struct iw_range)); |
| 119 | |
| 120 | range->we_version_compiled = WIRELESS_EXT; |
| 121 | range->we_version_source = 21; |
| 122 | range->retry_capa = IW_RETRY_LIMIT; |
| 123 | range->retry_flags = IW_RETRY_LIMIT; |
| 124 | range->min_retry = 0; |
| 125 | range->max_retry = 255; |
| 126 | range->min_rts = 0; |
| 127 | range->max_rts = 2347; |
| 128 | range->min_frag = 256; |
| 129 | range->max_frag = 2346; |
| 130 | |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 131 | range->max_encoding_tokens = 4; |
| 132 | |
| 133 | range->max_qual.updated = IW_QUAL_NOISE_INVALID; |
| 134 | |
| 135 | switch (wdev->wiphy->signal_type) { |
| 136 | case CFG80211_SIGNAL_TYPE_NONE: |
| 137 | break; |
| 138 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | e7d83ed | 2012-12-07 11:58:26 +0100 | [diff] [blame] | 139 | range->max_qual.level = (u8)-110; |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 140 | range->max_qual.qual = 70; |
| 141 | range->avg_qual.qual = 35; |
| 142 | range->max_qual.updated |= IW_QUAL_DBM; |
| 143 | range->max_qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 144 | range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 145 | break; |
| 146 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 147 | range->max_qual.level = 100; |
| 148 | range->max_qual.qual = 100; |
| 149 | range->avg_qual.qual = 50; |
| 150 | range->max_qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 151 | range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | range->avg_qual.level = range->max_qual.level / 2; |
| 156 | range->avg_qual.noise = range->max_qual.noise / 2; |
| 157 | range->avg_qual.updated = range->max_qual.updated; |
| 158 | |
Johannes Berg | 9834c07 | 2009-07-06 19:40:51 +0200 | [diff] [blame] | 159 | for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) { |
| 160 | switch (wdev->wiphy->cipher_suites[i]) { |
David Kilroy | 3daf097 | 2009-06-18 23:21:14 +0100 | [diff] [blame] | 161 | case WLAN_CIPHER_SUITE_TKIP: |
David Kilroy | 27bea66 | 2009-06-18 23:21:17 +0100 | [diff] [blame] | 162 | range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP | |
| 163 | IW_ENC_CAPA_WPA); |
David Kilroy | 3daf097 | 2009-06-18 23:21:14 +0100 | [diff] [blame] | 164 | break; |
| 165 | |
| 166 | case WLAN_CIPHER_SUITE_CCMP: |
David Kilroy | 27bea66 | 2009-06-18 23:21:17 +0100 | [diff] [blame] | 167 | range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP | |
| 168 | IW_ENC_CAPA_WPA2); |
David Kilroy | 3daf097 | 2009-06-18 23:21:14 +0100 | [diff] [blame] | 169 | break; |
David Kilroy | 2ab658f | 2009-06-18 23:21:16 +0100 | [diff] [blame] | 170 | |
| 171 | case WLAN_CIPHER_SUITE_WEP40: |
| 172 | range->encoding_size[range->num_encoding_sizes++] = |
| 173 | WLAN_KEY_LEN_WEP40; |
| 174 | break; |
| 175 | |
| 176 | case WLAN_CIPHER_SUITE_WEP104: |
| 177 | range->encoding_size[range->num_encoding_sizes++] = |
| 178 | WLAN_KEY_LEN_WEP104; |
| 179 | break; |
David Kilroy | 3daf097 | 2009-06-18 23:21:14 +0100 | [diff] [blame] | 180 | } |
| 181 | } |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 182 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 183 | for (band = 0; band < NUM_NL80211_BANDS; band ++) { |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 184 | struct ieee80211_supported_band *sband; |
| 185 | |
| 186 | sband = wdev->wiphy->bands[band]; |
| 187 | |
| 188 | if (!sband) |
| 189 | continue; |
| 190 | |
| 191 | for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) { |
| 192 | struct ieee80211_channel *chan = &sband->channels[i]; |
| 193 | |
| 194 | if (!(chan->flags & IEEE80211_CHAN_DISABLED)) { |
| 195 | range->freq[c].i = |
| 196 | ieee80211_frequency_to_channel( |
| 197 | chan->center_freq); |
| 198 | range->freq[c].m = chan->center_freq; |
| 199 | range->freq[c].e = 6; |
| 200 | c++; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | range->num_channels = c; |
| 205 | range->num_frequency = c; |
| 206 | |
| 207 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); |
| 208 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
| 209 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); |
| 210 | |
David Kilroy | 51cd4aa | 2009-06-18 23:21:15 +0100 | [diff] [blame] | 211 | if (wdev->wiphy->max_scan_ssids > 0) |
| 212 | range->scan_capa |= IW_SCAN_CAPA_ESSID; |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 213 | |
| 214 | return 0; |
| 215 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 216 | EXPORT_WEXT_HANDLER(cfg80211_wext_giwrange); |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 217 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * cfg80211_wext_freq - get wext frequency for non-"auto" |
Zhao, Gang | 96998e3 | 2014-04-09 09:28:06 +0800 | [diff] [blame] | 221 | * @dev: the net device |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 222 | * @freq: the wext freq encoding |
| 223 | * |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 224 | * Returns a frequency, or a negative error code, or 0 for auto. |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 225 | */ |
Zhao, Gang | 96998e3 | 2014-04-09 09:28:06 +0800 | [diff] [blame] | 226 | int cfg80211_wext_freq(struct iw_freq *freq) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 227 | { |
Johannes Berg | 0b25858 | 2009-05-08 09:42:33 +0200 | [diff] [blame] | 228 | /* |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 229 | * Parse frequency - return 0 for auto and |
Johannes Berg | 0b25858 | 2009-05-08 09:42:33 +0200 | [diff] [blame] | 230 | * -EINVAL for impossible things. |
| 231 | */ |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 232 | if (freq->e == 0) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 233 | enum nl80211_band band = NL80211_BAND_2GHZ; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 234 | if (freq->m < 0) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 235 | return 0; |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 236 | if (freq->m > 14) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 237 | band = NL80211_BAND_5GHZ; |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 238 | return ieee80211_channel_to_frequency(freq->m, band); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 239 | } else { |
| 240 | int i, div = 1000000; |
| 241 | for (i = 0; i < freq->e; i++) |
| 242 | div /= 10; |
Johannes Berg | 0b25858 | 2009-05-08 09:42:33 +0200 | [diff] [blame] | 243 | if (div <= 0) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 244 | return -EINVAL; |
| 245 | return freq->m / div; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 246 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 247 | } |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 248 | |
| 249 | int cfg80211_wext_siwrts(struct net_device *dev, |
| 250 | struct iw_request_info *info, |
| 251 | struct iw_param *rts, char *extra) |
| 252 | { |
| 253 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 254 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 255 | u32 orts = wdev->wiphy->rts_threshold; |
| 256 | int err; |
| 257 | |
| 258 | if (rts->disabled || !rts->fixed) |
| 259 | wdev->wiphy->rts_threshold = (u32) -1; |
| 260 | else if (rts->value < 0) |
| 261 | return -EINVAL; |
| 262 | else |
| 263 | wdev->wiphy->rts_threshold = rts->value; |
| 264 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 265 | err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_RTS_THRESHOLD); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 266 | if (err) |
| 267 | wdev->wiphy->rts_threshold = orts; |
| 268 | |
| 269 | return err; |
| 270 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 271 | EXPORT_WEXT_HANDLER(cfg80211_wext_siwrts); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 272 | |
| 273 | int cfg80211_wext_giwrts(struct net_device *dev, |
| 274 | struct iw_request_info *info, |
| 275 | struct iw_param *rts, char *extra) |
| 276 | { |
| 277 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 278 | |
| 279 | rts->value = wdev->wiphy->rts_threshold; |
| 280 | rts->disabled = rts->value == (u32) -1; |
| 281 | rts->fixed = 1; |
| 282 | |
| 283 | return 0; |
| 284 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 285 | EXPORT_WEXT_HANDLER(cfg80211_wext_giwrts); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 286 | |
| 287 | int cfg80211_wext_siwfrag(struct net_device *dev, |
| 288 | struct iw_request_info *info, |
| 289 | struct iw_param *frag, char *extra) |
| 290 | { |
| 291 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 292 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 293 | u32 ofrag = wdev->wiphy->frag_threshold; |
| 294 | int err; |
| 295 | |
| 296 | if (frag->disabled || !frag->fixed) |
| 297 | wdev->wiphy->frag_threshold = (u32) -1; |
| 298 | else if (frag->value < 256) |
| 299 | return -EINVAL; |
| 300 | else { |
| 301 | /* Fragment length must be even, so strip LSB. */ |
| 302 | wdev->wiphy->frag_threshold = frag->value & ~0x1; |
| 303 | } |
| 304 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 305 | err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_FRAG_THRESHOLD); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 306 | if (err) |
| 307 | wdev->wiphy->frag_threshold = ofrag; |
| 308 | |
| 309 | return err; |
| 310 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 311 | EXPORT_WEXT_HANDLER(cfg80211_wext_siwfrag); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 312 | |
| 313 | int cfg80211_wext_giwfrag(struct net_device *dev, |
| 314 | struct iw_request_info *info, |
| 315 | struct iw_param *frag, char *extra) |
| 316 | { |
| 317 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 318 | |
| 319 | frag->value = wdev->wiphy->frag_threshold; |
| 320 | frag->disabled = frag->value == (u32) -1; |
| 321 | frag->fixed = 1; |
| 322 | |
| 323 | return 0; |
| 324 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 325 | EXPORT_WEXT_HANDLER(cfg80211_wext_giwfrag); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 326 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 327 | static int cfg80211_wext_siwretry(struct net_device *dev, |
| 328 | struct iw_request_info *info, |
| 329 | struct iw_param *retry, char *extra) |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 330 | { |
| 331 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 332 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 333 | u32 changed = 0; |
| 334 | u8 olong = wdev->wiphy->retry_long; |
| 335 | u8 oshort = wdev->wiphy->retry_short; |
| 336 | int err; |
| 337 | |
Ujjal Roy | f5aa0d2 | 2014-01-09 21:16:14 +0530 | [diff] [blame] | 338 | if (retry->disabled || retry->value < 1 || retry->value > 255 || |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 339 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) |
| 340 | return -EINVAL; |
| 341 | |
| 342 | if (retry->flags & IW_RETRY_LONG) { |
| 343 | wdev->wiphy->retry_long = retry->value; |
| 344 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 345 | } else if (retry->flags & IW_RETRY_SHORT) { |
| 346 | wdev->wiphy->retry_short = retry->value; |
| 347 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 348 | } else { |
| 349 | wdev->wiphy->retry_short = retry->value; |
| 350 | wdev->wiphy->retry_long = retry->value; |
| 351 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 352 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 353 | } |
| 354 | |
| 355 | if (!changed) |
| 356 | return 0; |
| 357 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 358 | err = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 359 | if (err) { |
| 360 | wdev->wiphy->retry_short = oshort; |
| 361 | wdev->wiphy->retry_long = olong; |
| 362 | } |
| 363 | |
| 364 | return err; |
| 365 | } |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 366 | |
| 367 | int cfg80211_wext_giwretry(struct net_device *dev, |
| 368 | struct iw_request_info *info, |
| 369 | struct iw_param *retry, char *extra) |
| 370 | { |
| 371 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 372 | |
| 373 | retry->disabled = 0; |
| 374 | |
| 375 | if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) { |
| 376 | /* |
| 377 | * First return short value, iwconfig will ask long value |
| 378 | * later if needed |
| 379 | */ |
Ujjal Roy | 60a4fe0 | 2014-01-06 21:56:11 +0530 | [diff] [blame] | 380 | retry->flags |= IW_RETRY_LIMIT | IW_RETRY_SHORT; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 381 | retry->value = wdev->wiphy->retry_short; |
Ujjal Roy | 60a4fe0 | 2014-01-06 21:56:11 +0530 | [diff] [blame] | 382 | if (wdev->wiphy->retry_long == wdev->wiphy->retry_short) |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 383 | retry->flags |= IW_RETRY_LONG; |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | if (retry->flags & IW_RETRY_LONG) { |
| 389 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; |
| 390 | retry->value = wdev->wiphy->retry_long; |
| 391 | } |
| 392 | |
| 393 | return 0; |
| 394 | } |
Johannes Berg | 2afe38d | 2015-01-06 14:00:53 +0100 | [diff] [blame] | 395 | EXPORT_WEXT_HANDLER(cfg80211_wext_giwretry); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 396 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 397 | static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 398 | struct net_device *dev, bool pairwise, |
| 399 | const u8 *addr, bool remove, bool tx_key, |
| 400 | int idx, struct key_params *params) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 401 | { |
| 402 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 403 | int err, i; |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 404 | bool rejoin = false; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 405 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 406 | if (pairwise && !addr) |
| 407 | return -EINVAL; |
| 408 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 409 | if (!wdev->wext.keys) { |
| 410 | wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys), |
Johannes Berg | 89b706f | 2016-09-13 16:39:38 +0200 | [diff] [blame] | 411 | GFP_KERNEL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 412 | if (!wdev->wext.keys) |
| 413 | return -ENOMEM; |
Johannes Berg | 89b706f | 2016-09-13 16:39:38 +0200 | [diff] [blame] | 414 | for (i = 0; i < 4; i++) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 415 | wdev->wext.keys->params[i].key = |
| 416 | wdev->wext.keys->data[i]; |
| 417 | } |
| 418 | |
| 419 | if (wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 420 | wdev->iftype != NL80211_IFTYPE_STATION) |
| 421 | return -EOPNOTSUPP; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 422 | |
| 423 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 424 | if (!wdev->current_bss) |
| 425 | return -ENOLINK; |
| 426 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 427 | if (!rdev->ops->set_default_mgmt_key) |
| 428 | return -EOPNOTSUPP; |
| 429 | |
| 430 | if (idx < 4 || idx > 5) |
| 431 | return -EINVAL; |
| 432 | } else if (idx < 0 || idx > 3) |
| 433 | return -EINVAL; |
| 434 | |
| 435 | if (remove) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 436 | err = 0; |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 437 | if (wdev->current_bss) { |
| 438 | /* |
| 439 | * If removing the current TX key, we will need to |
| 440 | * join a new IBSS without the privacy bit clear. |
| 441 | */ |
| 442 | if (idx == wdev->wext.default_key && |
| 443 | wdev->iftype == NL80211_IFTYPE_ADHOC) { |
| 444 | __cfg80211_leave_ibss(rdev, wdev->netdev, true); |
| 445 | rejoin = true; |
| 446 | } |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 447 | |
| 448 | if (!pairwise && addr && |
| 449 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 450 | err = -ENOENT; |
| 451 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 452 | err = rdev_del_key(rdev, dev, idx, pairwise, |
| 453 | addr); |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 454 | } |
Vivek Natarajan | d55fb89 | 2009-11-24 11:54:10 -0500 | [diff] [blame] | 455 | wdev->wext.connect.privacy = false; |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 456 | /* |
| 457 | * Applications using wireless extensions expect to be |
| 458 | * able to delete keys that don't exist, so allow that. |
| 459 | */ |
| 460 | if (err == -ENOENT) |
| 461 | err = 0; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 462 | if (!err) { |
Johannes Berg | 89b706f | 2016-09-13 16:39:38 +0200 | [diff] [blame] | 463 | if (!addr && idx < 4) { |
Johannes Berg | 538c9eb | 2014-09-10 13:39:56 +0300 | [diff] [blame] | 464 | memset(wdev->wext.keys->data[idx], 0, |
| 465 | sizeof(wdev->wext.keys->data[idx])); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 466 | wdev->wext.keys->params[idx].key_len = 0; |
| 467 | wdev->wext.keys->params[idx].cipher = 0; |
| 468 | } |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 469 | if (idx == wdev->wext.default_key) |
| 470 | wdev->wext.default_key = -1; |
| 471 | else if (idx == wdev->wext.default_mgmt_key) |
| 472 | wdev->wext.default_mgmt_key = -1; |
| 473 | } |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 474 | |
| 475 | if (!err && rejoin) |
| 476 | err = cfg80211_ibss_wext_join(rdev, wdev); |
Johannes Berg | e3da574 | 2009-05-18 19:56:36 +0200 | [diff] [blame] | 477 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 478 | return err; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 479 | } |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 480 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 481 | if (addr) |
| 482 | tx_key = false; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 483 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 484 | if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr)) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 485 | return -EINVAL; |
| 486 | |
| 487 | err = 0; |
| 488 | if (wdev->current_bss) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 489 | err = rdev_add_key(rdev, dev, idx, pairwise, addr, params); |
Johannes Berg | 9381e26 | 2016-09-13 16:11:32 +0200 | [diff] [blame] | 490 | else if (params->cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 491 | params->cipher != WLAN_CIPHER_SUITE_WEP104) |
| 492 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 493 | if (err) |
| 494 | return err; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 495 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 496 | if (!addr) { |
| 497 | wdev->wext.keys->params[idx] = *params; |
| 498 | memcpy(wdev->wext.keys->data[idx], |
| 499 | params->key, params->key_len); |
| 500 | wdev->wext.keys->params[idx].key = |
| 501 | wdev->wext.keys->data[idx]; |
| 502 | } |
| 503 | |
Zhu Yi | 1f00fca | 2009-07-20 11:47:43 +0800 | [diff] [blame] | 504 | if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 505 | params->cipher == WLAN_CIPHER_SUITE_WEP104) && |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 506 | (tx_key || (!addr && wdev->wext.default_key == -1))) { |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 507 | if (wdev->current_bss) { |
| 508 | /* |
| 509 | * If we are getting a new TX key from not having |
| 510 | * had one before we need to join a new IBSS with |
| 511 | * the privacy bit set. |
| 512 | */ |
| 513 | if (wdev->iftype == NL80211_IFTYPE_ADHOC && |
| 514 | wdev->wext.default_key == -1) { |
| 515 | __cfg80211_leave_ibss(rdev, wdev->netdev, true); |
| 516 | rejoin = true; |
| 517 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 518 | err = rdev_set_default_key(rdev, dev, idx, true, true); |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 519 | } |
| 520 | if (!err) { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 521 | wdev->wext.default_key = idx; |
Johannes Berg | 98d3a7c | 2009-11-18 13:03:43 +0100 | [diff] [blame] | 522 | if (rejoin) |
| 523 | err = cfg80211_ibss_wext_join(rdev, wdev); |
| 524 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 525 | return err; |
| 526 | } |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 527 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 528 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC && |
| 529 | (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) { |
| 530 | if (wdev->current_bss) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 531 | err = rdev_set_default_mgmt_key(rdev, dev, idx); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 532 | if (!err) |
| 533 | wdev->wext.default_mgmt_key = idx; |
| 534 | return err; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 535 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 541 | struct net_device *dev, bool pairwise, |
| 542 | const u8 *addr, bool remove, bool tx_key, |
| 543 | int idx, struct key_params *params) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 544 | { |
| 545 | int err; |
| 546 | |
| 547 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 548 | err = __cfg80211_set_encryption(rdev, dev, pairwise, addr, |
| 549 | remove, tx_key, idx, params); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 550 | wdev_unlock(dev->ieee80211_ptr); |
| 551 | |
| 552 | return err; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 553 | } |
| 554 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 555 | static int cfg80211_wext_siwencode(struct net_device *dev, |
| 556 | struct iw_request_info *info, |
| 557 | struct iw_point *erq, char *keybuf) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 558 | { |
| 559 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 560 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 561 | int idx, err; |
| 562 | bool remove = false; |
| 563 | struct key_params params; |
| 564 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 565 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 566 | wdev->iftype != NL80211_IFTYPE_ADHOC) |
| 567 | return -EOPNOTSUPP; |
| 568 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 569 | /* no use -- only MFP (set_default_mgmt_key) is optional */ |
| 570 | if (!rdev->ops->del_key || |
| 571 | !rdev->ops->add_key || |
| 572 | !rdev->ops->set_default_key) |
| 573 | return -EOPNOTSUPP; |
| 574 | |
| 575 | idx = erq->flags & IW_ENCODE_INDEX; |
| 576 | if (idx == 0) { |
| 577 | idx = wdev->wext.default_key; |
| 578 | if (idx < 0) |
| 579 | idx = 0; |
| 580 | } else if (idx < 1 || idx > 4) |
| 581 | return -EINVAL; |
| 582 | else |
| 583 | idx--; |
| 584 | |
| 585 | if (erq->flags & IW_ENCODE_DISABLED) |
| 586 | remove = true; |
| 587 | else if (erq->length == 0) { |
| 588 | /* No key data - just set the default TX key index */ |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 589 | err = 0; |
| 590 | wdev_lock(wdev); |
| 591 | if (wdev->current_bss) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 592 | err = rdev_set_default_key(rdev, dev, idx, true, |
| 593 | true); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 594 | if (!err) |
| 595 | wdev->wext.default_key = idx; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 596 | wdev_unlock(wdev); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 597 | return err; |
| 598 | } |
| 599 | |
| 600 | memset(¶ms, 0, sizeof(params)); |
| 601 | params.key = keybuf; |
| 602 | params.key_len = erq->length; |
| 603 | if (erq->length == 5) |
| 604 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
| 605 | else if (erq->length == 13) |
| 606 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
| 607 | else if (!remove) |
| 608 | return -EINVAL; |
| 609 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 610 | return cfg80211_set_encryption(rdev, dev, false, NULL, remove, |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 611 | wdev->wext.default_key == -1, |
| 612 | idx, ¶ms); |
| 613 | } |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 614 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 615 | static int cfg80211_wext_siwencodeext(struct net_device *dev, |
| 616 | struct iw_request_info *info, |
| 617 | struct iw_point *erq, char *extra) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 618 | { |
| 619 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 620 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 621 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; |
| 622 | const u8 *addr; |
| 623 | int idx; |
| 624 | bool remove = false; |
| 625 | struct key_params params; |
| 626 | u32 cipher; |
| 627 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 628 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 629 | wdev->iftype != NL80211_IFTYPE_ADHOC) |
| 630 | return -EOPNOTSUPP; |
| 631 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 632 | /* no use -- only MFP (set_default_mgmt_key) is optional */ |
| 633 | if (!rdev->ops->del_key || |
| 634 | !rdev->ops->add_key || |
| 635 | !rdev->ops->set_default_key) |
| 636 | return -EOPNOTSUPP; |
| 637 | |
| 638 | switch (ext->alg) { |
| 639 | case IW_ENCODE_ALG_NONE: |
| 640 | remove = true; |
| 641 | cipher = 0; |
| 642 | break; |
| 643 | case IW_ENCODE_ALG_WEP: |
| 644 | if (ext->key_len == 5) |
| 645 | cipher = WLAN_CIPHER_SUITE_WEP40; |
| 646 | else if (ext->key_len == 13) |
| 647 | cipher = WLAN_CIPHER_SUITE_WEP104; |
| 648 | else |
| 649 | return -EINVAL; |
| 650 | break; |
| 651 | case IW_ENCODE_ALG_TKIP: |
| 652 | cipher = WLAN_CIPHER_SUITE_TKIP; |
| 653 | break; |
| 654 | case IW_ENCODE_ALG_CCMP: |
| 655 | cipher = WLAN_CIPHER_SUITE_CCMP; |
| 656 | break; |
| 657 | case IW_ENCODE_ALG_AES_CMAC: |
| 658 | cipher = WLAN_CIPHER_SUITE_AES_CMAC; |
| 659 | break; |
| 660 | default: |
| 661 | return -EOPNOTSUPP; |
| 662 | } |
| 663 | |
| 664 | if (erq->flags & IW_ENCODE_DISABLED) |
| 665 | remove = true; |
| 666 | |
| 667 | idx = erq->flags & IW_ENCODE_INDEX; |
| 668 | if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
| 669 | if (idx < 4 || idx > 5) { |
| 670 | idx = wdev->wext.default_mgmt_key; |
| 671 | if (idx < 0) |
| 672 | return -EINVAL; |
| 673 | } else |
| 674 | idx--; |
| 675 | } else { |
| 676 | if (idx < 1 || idx > 4) { |
| 677 | idx = wdev->wext.default_key; |
| 678 | if (idx < 0) |
| 679 | return -EINVAL; |
| 680 | } else |
| 681 | idx--; |
| 682 | } |
| 683 | |
| 684 | addr = ext->addr.sa_data; |
| 685 | if (is_broadcast_ether_addr(addr)) |
| 686 | addr = NULL; |
| 687 | |
| 688 | memset(¶ms, 0, sizeof(params)); |
| 689 | params.key = ext->key; |
| 690 | params.key_len = ext->key_len; |
| 691 | params.cipher = cipher; |
| 692 | |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 693 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { |
| 694 | params.seq = ext->rx_seq; |
| 695 | params.seq_len = 6; |
| 696 | } |
| 697 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 698 | return cfg80211_set_encryption( |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 699 | rdev, dev, |
| 700 | !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY), |
| 701 | addr, remove, |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 702 | ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, |
| 703 | idx, ¶ms); |
| 704 | } |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 705 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 706 | static int cfg80211_wext_giwencode(struct net_device *dev, |
| 707 | struct iw_request_info *info, |
| 708 | struct iw_point *erq, char *keybuf) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 709 | { |
| 710 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 711 | int idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 712 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 713 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 714 | wdev->iftype != NL80211_IFTYPE_ADHOC) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 715 | return -EOPNOTSUPP; |
| 716 | |
| 717 | idx = erq->flags & IW_ENCODE_INDEX; |
| 718 | if (idx == 0) { |
| 719 | idx = wdev->wext.default_key; |
| 720 | if (idx < 0) |
| 721 | idx = 0; |
| 722 | } else if (idx < 1 || idx > 4) |
| 723 | return -EINVAL; |
| 724 | else |
| 725 | idx--; |
| 726 | |
| 727 | erq->flags = idx + 1; |
| 728 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 729 | if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) { |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 730 | erq->flags |= IW_ENCODE_DISABLED; |
| 731 | erq->length = 0; |
| 732 | return 0; |
| 733 | } |
| 734 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 735 | erq->length = min_t(size_t, erq->length, |
| 736 | wdev->wext.keys->params[idx].key_len); |
| 737 | memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length); |
| 738 | erq->flags |= IW_ENCODE_ENABLED; |
| 739 | |
| 740 | return 0; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 741 | } |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 742 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 743 | static int cfg80211_wext_siwfreq(struct net_device *dev, |
| 744 | struct iw_request_info *info, |
| 745 | struct iw_freq *wextfreq, char *extra) |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 746 | { |
| 747 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 748 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 749 | struct cfg80211_chan_def chandef = { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 750 | .width = NL80211_CHAN_WIDTH_20_NOHT, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 751 | }; |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 752 | int freq; |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 753 | |
| 754 | switch (wdev->iftype) { |
| 755 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 756 | return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra); |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 757 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 758 | return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 759 | case NL80211_IFTYPE_MONITOR: |
Zhao, Gang | 96998e3 | 2014-04-09 09:28:06 +0800 | [diff] [blame] | 760 | freq = cfg80211_wext_freq(wextfreq); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 761 | if (freq < 0) |
| 762 | return freq; |
| 763 | if (freq == 0) |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 764 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 765 | chandef.center_freq1 = freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 766 | chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq); |
| 767 | if (!chandef.chan) |
| 768 | return -EINVAL; |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 769 | return cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 770 | case NL80211_IFTYPE_MESH_POINT: |
Zhao, Gang | 96998e3 | 2014-04-09 09:28:06 +0800 | [diff] [blame] | 771 | freq = cfg80211_wext_freq(wextfreq); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 772 | if (freq < 0) |
| 773 | return freq; |
| 774 | if (freq == 0) |
| 775 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 776 | chandef.center_freq1 = freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 777 | chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq); |
| 778 | if (!chandef.chan) |
| 779 | return -EINVAL; |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 780 | return cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 781 | default: |
| 782 | return -EOPNOTSUPP; |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 783 | } |
| 784 | } |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 785 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 786 | static int cfg80211_wext_giwfreq(struct net_device *dev, |
| 787 | struct iw_request_info *info, |
| 788 | struct iw_freq *freq, char *extra) |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 789 | { |
| 790 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 791 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 792 | struct cfg80211_chan_def chandef; |
| 793 | int ret; |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 794 | |
| 795 | switch (wdev->iftype) { |
| 796 | case NL80211_IFTYPE_STATION: |
| 797 | return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra); |
| 798 | case NL80211_IFTYPE_ADHOC: |
| 799 | return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); |
Johannes Berg | e999882 | 2011-11-09 10:30:21 +0100 | [diff] [blame] | 800 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 801 | if (!rdev->ops->get_channel) |
Johannes Berg | e999882 | 2011-11-09 10:30:21 +0100 | [diff] [blame] | 802 | return -EINVAL; |
| 803 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 804 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 805 | if (ret) |
| 806 | return ret; |
| 807 | freq->m = chandef.chan->center_freq; |
Johannes Berg | e999882 | 2011-11-09 10:30:21 +0100 | [diff] [blame] | 808 | freq->e = 6; |
| 809 | return 0; |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 810 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 811 | return -EINVAL; |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 812 | } |
| 813 | } |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 814 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 815 | static int cfg80211_wext_siwtxpower(struct net_device *dev, |
| 816 | struct iw_request_info *info, |
| 817 | union iwreq_data *data, char *extra) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 818 | { |
| 819 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 820 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 821 | enum nl80211_tx_power_setting type; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 822 | int dbm = 0; |
| 823 | |
| 824 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 825 | return -EINVAL; |
| 826 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 827 | return -EINVAL; |
| 828 | |
| 829 | if (!rdev->ops->set_tx_power) |
| 830 | return -EOPNOTSUPP; |
| 831 | |
| 832 | /* only change when not disabling */ |
| 833 | if (!data->txpower.disabled) { |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 834 | rfkill_set_sw_state(rdev->rfkill, false); |
| 835 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 836 | if (data->txpower.fixed) { |
| 837 | /* |
| 838 | * wext doesn't support negative values, see |
| 839 | * below where it's for automatic |
| 840 | */ |
| 841 | if (data->txpower.value < 0) |
| 842 | return -EINVAL; |
| 843 | dbm = data->txpower.value; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 844 | type = NL80211_TX_POWER_FIXED; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 845 | /* TODO: do regulatory check! */ |
| 846 | } else { |
| 847 | /* |
| 848 | * Automatic power level setting, max being the value |
| 849 | * passed in from userland. |
| 850 | */ |
| 851 | if (data->txpower.value < 0) { |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 852 | type = NL80211_TX_POWER_AUTOMATIC; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 853 | } else { |
| 854 | dbm = data->txpower.value; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 855 | type = NL80211_TX_POWER_LIMITED; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | } else { |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 859 | rfkill_set_sw_state(rdev->rfkill, true); |
| 860 | schedule_work(&rdev->rfkill_sync); |
| 861 | return 0; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 862 | } |
| 863 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 864 | return rdev_set_tx_power(rdev, wdev, type, DBM_TO_MBM(dbm)); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 865 | } |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 866 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 867 | static int cfg80211_wext_giwtxpower(struct net_device *dev, |
| 868 | struct iw_request_info *info, |
| 869 | union iwreq_data *data, char *extra) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 870 | { |
| 871 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 872 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 873 | int err, val; |
| 874 | |
| 875 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 876 | return -EINVAL; |
| 877 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 878 | return -EINVAL; |
| 879 | |
| 880 | if (!rdev->ops->get_tx_power) |
| 881 | return -EOPNOTSUPP; |
| 882 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 883 | err = rdev_get_tx_power(rdev, wdev, &val); |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 884 | if (err) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 885 | return err; |
| 886 | |
| 887 | /* well... oh well */ |
| 888 | data->txpower.fixed = 1; |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 889 | data->txpower.disabled = rfkill_blocked(rdev->rfkill); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 890 | data->txpower.value = val; |
| 891 | data->txpower.flags = IW_TXPOW_DBM; |
| 892 | |
| 893 | return 0; |
| 894 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 895 | |
| 896 | static int cfg80211_set_auth_alg(struct wireless_dev *wdev, |
| 897 | s32 auth_alg) |
| 898 | { |
| 899 | int nr_alg = 0; |
| 900 | |
| 901 | if (!auth_alg) |
| 902 | return -EINVAL; |
| 903 | |
| 904 | if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM | |
| 905 | IW_AUTH_ALG_SHARED_KEY | |
| 906 | IW_AUTH_ALG_LEAP)) |
| 907 | return -EINVAL; |
| 908 | |
| 909 | if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) { |
| 910 | nr_alg++; |
| 911 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 912 | } |
| 913 | |
| 914 | if (auth_alg & IW_AUTH_ALG_SHARED_KEY) { |
| 915 | nr_alg++; |
| 916 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY; |
| 917 | } |
| 918 | |
| 919 | if (auth_alg & IW_AUTH_ALG_LEAP) { |
| 920 | nr_alg++; |
| 921 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 922 | } |
| 923 | |
| 924 | if (nr_alg > 1) |
| 925 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 926 | |
| 927 | return 0; |
| 928 | } |
| 929 | |
| 930 | static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions) |
| 931 | { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 932 | if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA | |
Gábor Stefanik | 323d566 | 2009-07-12 02:03:48 +0200 | [diff] [blame] | 933 | IW_AUTH_WPA_VERSION_WPA2| |
| 934 | IW_AUTH_WPA_VERSION_DISABLED)) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 935 | return -EINVAL; |
| 936 | |
Gábor Stefanik | 323d566 | 2009-07-12 02:03:48 +0200 | [diff] [blame] | 937 | if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) && |
| 938 | (wpa_versions & (IW_AUTH_WPA_VERSION_WPA| |
| 939 | IW_AUTH_WPA_VERSION_WPA2))) |
| 940 | return -EINVAL; |
| 941 | |
| 942 | if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) |
| 943 | wdev->wext.connect.crypto.wpa_versions &= |
| 944 | ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2); |
| 945 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 946 | if (wpa_versions & IW_AUTH_WPA_VERSION_WPA) |
| 947 | wdev->wext.connect.crypto.wpa_versions |= |
| 948 | NL80211_WPA_VERSION_1; |
| 949 | |
| 950 | if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2) |
| 951 | wdev->wext.connect.crypto.wpa_versions |= |
| 952 | NL80211_WPA_VERSION_2; |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 957 | static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 958 | { |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 959 | if (cipher & IW_AUTH_CIPHER_WEP40) |
| 960 | wdev->wext.connect.crypto.cipher_group = |
| 961 | WLAN_CIPHER_SUITE_WEP40; |
| 962 | else if (cipher & IW_AUTH_CIPHER_WEP104) |
| 963 | wdev->wext.connect.crypto.cipher_group = |
| 964 | WLAN_CIPHER_SUITE_WEP104; |
| 965 | else if (cipher & IW_AUTH_CIPHER_TKIP) |
| 966 | wdev->wext.connect.crypto.cipher_group = |
| 967 | WLAN_CIPHER_SUITE_TKIP; |
| 968 | else if (cipher & IW_AUTH_CIPHER_CCMP) |
| 969 | wdev->wext.connect.crypto.cipher_group = |
| 970 | WLAN_CIPHER_SUITE_CCMP; |
| 971 | else if (cipher & IW_AUTH_CIPHER_AES_CMAC) |
| 972 | wdev->wext.connect.crypto.cipher_group = |
| 973 | WLAN_CIPHER_SUITE_AES_CMAC; |
Jouni Malinen | c5f8289 | 2009-11-01 11:18:49 +0200 | [diff] [blame] | 974 | else if (cipher & IW_AUTH_CIPHER_NONE) |
| 975 | wdev->wext.connect.crypto.cipher_group = 0; |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 976 | else |
| 977 | return -EINVAL; |
| 978 | |
| 979 | return 0; |
| 980 | } |
| 981 | |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 982 | static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 983 | { |
| 984 | int nr_ciphers = 0; |
| 985 | u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise; |
| 986 | |
| 987 | if (cipher & IW_AUTH_CIPHER_WEP40) { |
| 988 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40; |
| 989 | nr_ciphers++; |
| 990 | } |
| 991 | |
| 992 | if (cipher & IW_AUTH_CIPHER_WEP104) { |
| 993 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104; |
| 994 | nr_ciphers++; |
| 995 | } |
| 996 | |
| 997 | if (cipher & IW_AUTH_CIPHER_TKIP) { |
| 998 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP; |
| 999 | nr_ciphers++; |
| 1000 | } |
| 1001 | |
| 1002 | if (cipher & IW_AUTH_CIPHER_CCMP) { |
| 1003 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP; |
| 1004 | nr_ciphers++; |
| 1005 | } |
| 1006 | |
| 1007 | if (cipher & IW_AUTH_CIPHER_AES_CMAC) { |
| 1008 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC; |
| 1009 | nr_ciphers++; |
| 1010 | } |
| 1011 | |
| 1012 | BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5); |
| 1013 | |
| 1014 | wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers; |
| 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 1020 | static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 1021 | { |
| 1022 | int nr_akm_suites = 0; |
| 1023 | |
| 1024 | if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X | |
| 1025 | IW_AUTH_KEY_MGMT_PSK)) |
| 1026 | return -EINVAL; |
| 1027 | |
| 1028 | if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) { |
| 1029 | wdev->wext.connect.crypto.akm_suites[nr_akm_suites] = |
| 1030 | WLAN_AKM_SUITE_8021X; |
| 1031 | nr_akm_suites++; |
| 1032 | } |
| 1033 | |
| 1034 | if (key_mgt & IW_AUTH_KEY_MGMT_PSK) { |
| 1035 | wdev->wext.connect.crypto.akm_suites[nr_akm_suites] = |
| 1036 | WLAN_AKM_SUITE_PSK; |
| 1037 | nr_akm_suites++; |
| 1038 | } |
| 1039 | |
| 1040 | wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites; |
| 1041 | |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1045 | static int cfg80211_wext_siwauth(struct net_device *dev, |
| 1046 | struct iw_request_info *info, |
| 1047 | struct iw_param *data, char *extra) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 1048 | { |
| 1049 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1050 | |
| 1051 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 1052 | return -EOPNOTSUPP; |
| 1053 | |
| 1054 | switch (data->flags & IW_AUTH_INDEX) { |
| 1055 | case IW_AUTH_PRIVACY_INVOKED: |
| 1056 | wdev->wext.connect.privacy = data->value; |
| 1057 | return 0; |
| 1058 | case IW_AUTH_WPA_VERSION: |
| 1059 | return cfg80211_set_wpa_version(wdev, data->value); |
| 1060 | case IW_AUTH_CIPHER_GROUP: |
| 1061 | return cfg80211_set_cipher_group(wdev, data->value); |
| 1062 | case IW_AUTH_KEY_MGMT: |
| 1063 | return cfg80211_set_key_mgt(wdev, data->value); |
| 1064 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1065 | return cfg80211_set_cipher_pairwise(wdev, data->value); |
| 1066 | case IW_AUTH_80211_AUTH_ALG: |
| 1067 | return cfg80211_set_auth_alg(wdev, data->value); |
| 1068 | case IW_AUTH_WPA_ENABLED: |
| 1069 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 1070 | case IW_AUTH_DROP_UNENCRYPTED: |
| 1071 | case IW_AUTH_MFP: |
| 1072 | return 0; |
| 1073 | default: |
| 1074 | return -EOPNOTSUPP; |
| 1075 | } |
| 1076 | } |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 1077 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1078 | static int cfg80211_wext_giwauth(struct net_device *dev, |
| 1079 | struct iw_request_info *info, |
| 1080 | struct iw_param *data, char *extra) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 1081 | { |
| 1082 | /* XXX: what do we need? */ |
| 1083 | |
| 1084 | return -EOPNOTSUPP; |
| 1085 | } |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1086 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1087 | static int cfg80211_wext_siwpower(struct net_device *dev, |
| 1088 | struct iw_request_info *info, |
| 1089 | struct iw_param *wrq, char *extra) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1090 | { |
| 1091 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1092 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 1093 | bool ps = wdev->ps; |
| 1094 | int timeout = wdev->ps_timeout; |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1095 | int err; |
| 1096 | |
| 1097 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 1098 | return -EINVAL; |
| 1099 | |
| 1100 | if (!rdev->ops->set_power_mgmt) |
| 1101 | return -EOPNOTSUPP; |
| 1102 | |
| 1103 | if (wrq->disabled) { |
| 1104 | ps = false; |
| 1105 | } else { |
| 1106 | switch (wrq->flags & IW_POWER_MODE) { |
| 1107 | case IW_POWER_ON: /* If not specified */ |
| 1108 | case IW_POWER_MODE: /* If set all mask */ |
| 1109 | case IW_POWER_ALL_R: /* If explicitely state all */ |
| 1110 | ps = true; |
| 1111 | break; |
| 1112 | default: /* Otherwise we ignore */ |
| 1113 | return -EINVAL; |
| 1114 | } |
| 1115 | |
| 1116 | if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT)) |
| 1117 | return -EINVAL; |
| 1118 | |
| 1119 | if (wrq->flags & IW_POWER_TIMEOUT) |
| 1120 | timeout = wrq->value / 1000; |
| 1121 | } |
| 1122 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1123 | err = rdev_set_power_mgmt(rdev, dev, ps, timeout); |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1124 | if (err) |
| 1125 | return err; |
| 1126 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 1127 | wdev->ps = ps; |
| 1128 | wdev->ps_timeout = timeout; |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1129 | |
| 1130 | return 0; |
| 1131 | |
| 1132 | } |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1133 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1134 | static int cfg80211_wext_giwpower(struct net_device *dev, |
| 1135 | struct iw_request_info *info, |
| 1136 | struct iw_param *wrq, char *extra) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1137 | { |
| 1138 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1139 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 1140 | wrq->disabled = !wdev->ps; |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1141 | |
| 1142 | return 0; |
| 1143 | } |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1144 | |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1145 | static int cfg80211_wds_wext_siwap(struct net_device *dev, |
| 1146 | struct iw_request_info *info, |
| 1147 | struct sockaddr *addr, char *extra) |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1148 | { |
| 1149 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1150 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1151 | int err; |
| 1152 | |
| 1153 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS)) |
| 1154 | return -EINVAL; |
| 1155 | |
| 1156 | if (addr->sa_family != ARPHRD_ETHER) |
| 1157 | return -EINVAL; |
| 1158 | |
| 1159 | if (netif_running(dev)) |
| 1160 | return -EBUSY; |
| 1161 | |
| 1162 | if (!rdev->ops->set_wds_peer) |
| 1163 | return -EOPNOTSUPP; |
| 1164 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1165 | err = rdev_set_wds_peer(rdev, dev, (u8 *)&addr->sa_data); |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1166 | if (err) |
| 1167 | return err; |
| 1168 | |
| 1169 | memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN); |
| 1170 | |
| 1171 | return 0; |
| 1172 | } |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1173 | |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1174 | static int cfg80211_wds_wext_giwap(struct net_device *dev, |
| 1175 | struct iw_request_info *info, |
| 1176 | struct sockaddr *addr, char *extra) |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1177 | { |
| 1178 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1179 | |
| 1180 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS)) |
| 1181 | return -EINVAL; |
| 1182 | |
| 1183 | addr->sa_family = ARPHRD_ETHER; |
| 1184 | memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN); |
| 1185 | |
| 1186 | return 0; |
| 1187 | } |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1188 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1189 | static int cfg80211_wext_siwrate(struct net_device *dev, |
| 1190 | struct iw_request_info *info, |
| 1191 | struct iw_param *rate, char *extra) |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1192 | { |
| 1193 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1194 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1195 | struct cfg80211_bitrate_mask mask; |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 1196 | u32 fixed, maxrate; |
| 1197 | struct ieee80211_supported_band *sband; |
| 1198 | int band, ridx; |
| 1199 | bool match = false; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1200 | |
| 1201 | if (!rdev->ops->set_bitrate_mask) |
| 1202 | return -EOPNOTSUPP; |
| 1203 | |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 1204 | memset(&mask, 0, sizeof(mask)); |
| 1205 | fixed = 0; |
John W. Linville | 5423326 | 2010-01-27 09:44:48 -0500 | [diff] [blame] | 1206 | maxrate = (u32)-1; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1207 | |
| 1208 | if (rate->value < 0) { |
| 1209 | /* nothing */ |
| 1210 | } else if (rate->fixed) { |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 1211 | fixed = rate->value / 100000; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1212 | } else { |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 1213 | maxrate = rate->value / 100000; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1214 | } |
| 1215 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1216 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 1217 | sband = wdev->wiphy->bands[band]; |
| 1218 | if (sband == NULL) |
| 1219 | continue; |
| 1220 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 1221 | struct ieee80211_rate *srate = &sband->bitrates[ridx]; |
| 1222 | if (fixed == srate->bitrate) { |
| 1223 | mask.control[band].legacy = 1 << ridx; |
| 1224 | match = true; |
| 1225 | break; |
| 1226 | } |
| 1227 | if (srate->bitrate <= maxrate) { |
| 1228 | mask.control[band].legacy |= 1 << ridx; |
| 1229 | match = true; |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | if (!match) |
| 1235 | return -EINVAL; |
| 1236 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1237 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1238 | } |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1239 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1240 | static int cfg80211_wext_giwrate(struct net_device *dev, |
| 1241 | struct iw_request_info *info, |
| 1242 | struct iw_param *rate, char *extra) |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1243 | { |
| 1244 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1245 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1246 | /* we are under RTNL - globally locked - so can use a static struct */ |
| 1247 | static struct station_info sinfo; |
Johannes Berg | a71d62d | 2009-07-07 23:41:27 +0200 | [diff] [blame] | 1248 | u8 addr[ETH_ALEN]; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1249 | int err; |
| 1250 | |
| 1251 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 1252 | return -EOPNOTSUPP; |
| 1253 | |
| 1254 | if (!rdev->ops->get_station) |
| 1255 | return -EOPNOTSUPP; |
| 1256 | |
Johannes Berg | a71d62d | 2009-07-07 23:41:27 +0200 | [diff] [blame] | 1257 | err = 0; |
| 1258 | wdev_lock(wdev); |
Samuel Ortiz | 6c230c0 | 2009-07-03 02:00:48 +0200 | [diff] [blame] | 1259 | if (wdev->current_bss) |
Johannes Berg | a71d62d | 2009-07-07 23:41:27 +0200 | [diff] [blame] | 1260 | memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN); |
Samuel Ortiz | 6c230c0 | 2009-07-03 02:00:48 +0200 | [diff] [blame] | 1261 | else |
Johannes Berg | a71d62d | 2009-07-07 23:41:27 +0200 | [diff] [blame] | 1262 | err = -EOPNOTSUPP; |
| 1263 | wdev_unlock(wdev); |
| 1264 | if (err) |
| 1265 | return err; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1266 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1267 | err = rdev_get_station(rdev, dev, addr, &sinfo); |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1268 | if (err) |
| 1269 | return err; |
| 1270 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 1271 | if (!(sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE))) |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1272 | return -EOPNOTSUPP; |
| 1273 | |
John W. Linville | 254416a | 2009-12-09 16:43:52 -0500 | [diff] [blame] | 1274 | rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate); |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1275 | |
| 1276 | return 0; |
| 1277 | } |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1278 | |
| 1279 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1280 | static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev) |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1281 | { |
| 1282 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1283 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1284 | /* we are under RTNL - globally locked - so can use static structs */ |
| 1285 | static struct iw_statistics wstats; |
| 1286 | static struct station_info sinfo; |
Johannes Berg | c56c571 | 2009-07-10 16:54:07 +0200 | [diff] [blame] | 1287 | u8 bssid[ETH_ALEN]; |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1288 | |
| 1289 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) |
| 1290 | return NULL; |
| 1291 | |
| 1292 | if (!rdev->ops->get_station) |
| 1293 | return NULL; |
| 1294 | |
Johannes Berg | c56c571 | 2009-07-10 16:54:07 +0200 | [diff] [blame] | 1295 | /* Grab BSSID of current BSS, if any */ |
| 1296 | wdev_lock(wdev); |
| 1297 | if (!wdev->current_bss) { |
| 1298 | wdev_unlock(wdev); |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1299 | return NULL; |
Johannes Berg | c56c571 | 2009-07-10 16:54:07 +0200 | [diff] [blame] | 1300 | } |
| 1301 | memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN); |
| 1302 | wdev_unlock(wdev); |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1303 | |
Johannes Berg | 9c5a18a | 2015-06-09 21:35:44 +0200 | [diff] [blame] | 1304 | memset(&sinfo, 0, sizeof(sinfo)); |
| 1305 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1306 | if (rdev_get_station(rdev, dev, bssid, &sinfo)) |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1307 | return NULL; |
| 1308 | |
| 1309 | memset(&wstats, 0, sizeof(wstats)); |
| 1310 | |
| 1311 | switch (rdev->wiphy.signal_type) { |
| 1312 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 1313 | if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) { |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1314 | int sig = sinfo.signal; |
| 1315 | wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 1316 | wstats.qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 1317 | wstats.qual.updated |= IW_QUAL_DBM; |
| 1318 | wstats.qual.level = sig; |
| 1319 | if (sig < -110) |
| 1320 | sig = -110; |
| 1321 | else if (sig > -40) |
| 1322 | sig = -40; |
| 1323 | wstats.qual.qual = sig + 110; |
| 1324 | break; |
| 1325 | } |
| 1326 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 1327 | if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) { |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1328 | wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 1329 | wstats.qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 1330 | wstats.qual.level = sinfo.signal; |
| 1331 | wstats.qual.qual = sinfo.signal; |
| 1332 | break; |
| 1333 | } |
| 1334 | default: |
| 1335 | wstats.qual.updated |= IW_QUAL_LEVEL_INVALID; |
| 1336 | wstats.qual.updated |= IW_QUAL_QUAL_INVALID; |
| 1337 | } |
| 1338 | |
| 1339 | wstats.qual.updated |= IW_QUAL_NOISE_INVALID; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 1340 | if (sinfo.filled & BIT(NL80211_STA_INFO_RX_DROP_MISC)) |
Ben Greear | 5a5c731 | 2010-10-07 16:39:20 -0700 | [diff] [blame] | 1341 | wstats.discard.misc = sinfo.rx_dropped_misc; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 1342 | if (sinfo.filled & BIT(NL80211_STA_INFO_TX_FAILED)) |
Ben Greear | 5a5c731 | 2010-10-07 16:39:20 -0700 | [diff] [blame] | 1343 | wstats.discard.retries = sinfo.tx_failed; |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1344 | |
| 1345 | return &wstats; |
| 1346 | } |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1347 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1348 | static int cfg80211_wext_siwap(struct net_device *dev, |
| 1349 | struct iw_request_info *info, |
| 1350 | struct sockaddr *ap_addr, char *extra) |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1351 | { |
| 1352 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1353 | |
| 1354 | switch (wdev->iftype) { |
| 1355 | case NL80211_IFTYPE_ADHOC: |
| 1356 | return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); |
| 1357 | case NL80211_IFTYPE_STATION: |
| 1358 | return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra); |
| 1359 | case NL80211_IFTYPE_WDS: |
| 1360 | return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra); |
| 1361 | default: |
| 1362 | return -EOPNOTSUPP; |
| 1363 | } |
| 1364 | } |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1365 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1366 | static int cfg80211_wext_giwap(struct net_device *dev, |
| 1367 | struct iw_request_info *info, |
| 1368 | struct sockaddr *ap_addr, char *extra) |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1369 | { |
| 1370 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1371 | |
| 1372 | switch (wdev->iftype) { |
| 1373 | case NL80211_IFTYPE_ADHOC: |
| 1374 | return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); |
| 1375 | case NL80211_IFTYPE_STATION: |
| 1376 | return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra); |
| 1377 | case NL80211_IFTYPE_WDS: |
| 1378 | return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra); |
| 1379 | default: |
| 1380 | return -EOPNOTSUPP; |
| 1381 | } |
| 1382 | } |
Johannes Berg | 1f9298f | 2009-07-27 12:01:52 +0200 | [diff] [blame] | 1383 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1384 | static int cfg80211_wext_siwessid(struct net_device *dev, |
| 1385 | struct iw_request_info *info, |
| 1386 | struct iw_point *data, char *ssid) |
Johannes Berg | 1f9298f | 2009-07-27 12:01:52 +0200 | [diff] [blame] | 1387 | { |
| 1388 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1389 | |
| 1390 | switch (wdev->iftype) { |
| 1391 | case NL80211_IFTYPE_ADHOC: |
| 1392 | return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); |
| 1393 | case NL80211_IFTYPE_STATION: |
| 1394 | return cfg80211_mgd_wext_siwessid(dev, info, data, ssid); |
| 1395 | default: |
| 1396 | return -EOPNOTSUPP; |
| 1397 | } |
| 1398 | } |
Johannes Berg | 1f9298f | 2009-07-27 12:01:52 +0200 | [diff] [blame] | 1399 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1400 | static int cfg80211_wext_giwessid(struct net_device *dev, |
| 1401 | struct iw_request_info *info, |
| 1402 | struct iw_point *data, char *ssid) |
Johannes Berg | 1f9298f | 2009-07-27 12:01:52 +0200 | [diff] [blame] | 1403 | { |
| 1404 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1405 | |
Johannes Berg | 42da2f9 | 2010-08-30 12:24:54 +0200 | [diff] [blame] | 1406 | data->flags = 0; |
| 1407 | data->length = 0; |
| 1408 | |
Johannes Berg | 1f9298f | 2009-07-27 12:01:52 +0200 | [diff] [blame] | 1409 | switch (wdev->iftype) { |
| 1410 | case NL80211_IFTYPE_ADHOC: |
| 1411 | return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); |
| 1412 | case NL80211_IFTYPE_STATION: |
| 1413 | return cfg80211_mgd_wext_giwessid(dev, info, data, ssid); |
| 1414 | default: |
| 1415 | return -EOPNOTSUPP; |
| 1416 | } |
| 1417 | } |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 1418 | |
Johannes Berg | 04b0c5c | 2011-07-15 13:01:38 +0200 | [diff] [blame] | 1419 | static int cfg80211_wext_siwpmksa(struct net_device *dev, |
| 1420 | struct iw_request_info *info, |
| 1421 | struct iw_point *data, char *extra) |
Samuel Ortiz | 2944b2c | 2009-11-25 00:01:01 +0100 | [diff] [blame] | 1422 | { |
| 1423 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1424 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Samuel Ortiz | 2944b2c | 2009-11-25 00:01:01 +0100 | [diff] [blame] | 1425 | struct cfg80211_pmksa cfg_pmksa; |
| 1426 | struct iw_pmksa *pmksa = (struct iw_pmksa *)extra; |
| 1427 | |
| 1428 | memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 1429 | |
| 1430 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 1431 | return -EINVAL; |
| 1432 | |
| 1433 | cfg_pmksa.bssid = pmksa->bssid.sa_data; |
| 1434 | cfg_pmksa.pmkid = pmksa->pmkid; |
| 1435 | |
| 1436 | switch (pmksa->cmd) { |
| 1437 | case IW_PMKSA_ADD: |
| 1438 | if (!rdev->ops->set_pmksa) |
| 1439 | return -EOPNOTSUPP; |
| 1440 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1441 | return rdev_set_pmksa(rdev, dev, &cfg_pmksa); |
Samuel Ortiz | 2944b2c | 2009-11-25 00:01:01 +0100 | [diff] [blame] | 1442 | |
| 1443 | case IW_PMKSA_REMOVE: |
| 1444 | if (!rdev->ops->del_pmksa) |
| 1445 | return -EOPNOTSUPP; |
| 1446 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1447 | return rdev_del_pmksa(rdev, dev, &cfg_pmksa); |
Samuel Ortiz | 2944b2c | 2009-11-25 00:01:01 +0100 | [diff] [blame] | 1448 | |
| 1449 | case IW_PMKSA_FLUSH: |
| 1450 | if (!rdev->ops->flush_pmksa) |
| 1451 | return -EOPNOTSUPP; |
| 1452 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1453 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 2944b2c | 2009-11-25 00:01:01 +0100 | [diff] [blame] | 1454 | |
| 1455 | default: |
| 1456 | return -EOPNOTSUPP; |
| 1457 | } |
| 1458 | } |
| 1459 | |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 1460 | static const iw_handler cfg80211_handlers[] = { |
| 1461 | [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname, |
| 1462 | [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq, |
| 1463 | [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq, |
| 1464 | [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode, |
| 1465 | [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode, |
| 1466 | [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange, |
| 1467 | [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap, |
| 1468 | [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap, |
| 1469 | [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme, |
| 1470 | [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan, |
| 1471 | [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan, |
| 1472 | [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid, |
| 1473 | [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid, |
| 1474 | [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate, |
| 1475 | [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate, |
| 1476 | [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts, |
| 1477 | [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts, |
| 1478 | [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag, |
| 1479 | [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag, |
| 1480 | [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower, |
| 1481 | [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower, |
| 1482 | [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry, |
| 1483 | [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry, |
| 1484 | [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode, |
| 1485 | [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode, |
| 1486 | [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower, |
| 1487 | [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower, |
| 1488 | [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie, |
| 1489 | [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth, |
| 1490 | [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth, |
| 1491 | [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext, |
Samuel Ortiz | 2944b2c | 2009-11-25 00:01:01 +0100 | [diff] [blame] | 1492 | [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa, |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 1493 | }; |
| 1494 | |
| 1495 | const struct iw_handler_def cfg80211_wext_handler = { |
| 1496 | .num_standard = ARRAY_SIZE(cfg80211_handlers), |
| 1497 | .standard = cfg80211_handlers, |
| 1498 | .get_wireless_stats = cfg80211_wireless_stats, |
| 1499 | }; |