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