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