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