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