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