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 | } |
Jussi Kivilinna | a8b875e | 2009-08-13 20:39:31 +0300 | [diff] [blame^] | 774 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwfreq); |
Johannes Berg | 0e82ffe | 2009-07-27 12:01:50 +0200 | [diff] [blame] | 775 | |
| 776 | int cfg80211_wext_giwfreq(struct net_device *dev, |
| 777 | struct iw_request_info *info, |
| 778 | struct iw_freq *freq, char *extra) |
| 779 | { |
| 780 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 781 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 782 | |
| 783 | switch (wdev->iftype) { |
| 784 | case NL80211_IFTYPE_STATION: |
| 785 | return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra); |
| 786 | case NL80211_IFTYPE_ADHOC: |
| 787 | return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra); |
| 788 | default: |
| 789 | if (!rdev->channel) |
| 790 | return -EINVAL; |
| 791 | freq->m = rdev->channel->center_freq; |
| 792 | freq->e = 6; |
| 793 | return 0; |
| 794 | } |
| 795 | } |
| 796 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwfreq); |
| 797 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 798 | int cfg80211_wext_siwtxpower(struct net_device *dev, |
| 799 | struct iw_request_info *info, |
| 800 | union iwreq_data *data, char *extra) |
| 801 | { |
| 802 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 803 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 804 | enum tx_power_setting type; |
| 805 | int dbm = 0; |
| 806 | |
| 807 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 808 | return -EINVAL; |
| 809 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 810 | return -EINVAL; |
| 811 | |
| 812 | if (!rdev->ops->set_tx_power) |
| 813 | return -EOPNOTSUPP; |
| 814 | |
| 815 | /* only change when not disabling */ |
| 816 | if (!data->txpower.disabled) { |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 817 | rfkill_set_sw_state(rdev->rfkill, false); |
| 818 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 819 | if (data->txpower.fixed) { |
| 820 | /* |
| 821 | * wext doesn't support negative values, see |
| 822 | * below where it's for automatic |
| 823 | */ |
| 824 | if (data->txpower.value < 0) |
| 825 | return -EINVAL; |
| 826 | dbm = data->txpower.value; |
| 827 | type = TX_POWER_FIXED; |
| 828 | /* TODO: do regulatory check! */ |
| 829 | } else { |
| 830 | /* |
| 831 | * Automatic power level setting, max being the value |
| 832 | * passed in from userland. |
| 833 | */ |
| 834 | if (data->txpower.value < 0) { |
| 835 | type = TX_POWER_AUTOMATIC; |
| 836 | } else { |
| 837 | dbm = data->txpower.value; |
| 838 | type = TX_POWER_LIMITED; |
| 839 | } |
| 840 | } |
| 841 | } else { |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 842 | rfkill_set_sw_state(rdev->rfkill, true); |
| 843 | schedule_work(&rdev->rfkill_sync); |
| 844 | return 0; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);; |
| 848 | } |
| 849 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower); |
| 850 | |
| 851 | int cfg80211_wext_giwtxpower(struct net_device *dev, |
| 852 | struct iw_request_info *info, |
| 853 | union iwreq_data *data, char *extra) |
| 854 | { |
| 855 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 856 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 857 | int err, val; |
| 858 | |
| 859 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 860 | return -EINVAL; |
| 861 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 862 | return -EINVAL; |
| 863 | |
| 864 | if (!rdev->ops->get_tx_power) |
| 865 | return -EOPNOTSUPP; |
| 866 | |
| 867 | err = rdev->ops->get_tx_power(wdev->wiphy, &val); |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 868 | if (err) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 869 | return err; |
| 870 | |
| 871 | /* well... oh well */ |
| 872 | data->txpower.fixed = 1; |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 873 | data->txpower.disabled = rfkill_blocked(rdev->rfkill); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 874 | data->txpower.value = val; |
| 875 | data->txpower.flags = IW_TXPOW_DBM; |
| 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower); |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 880 | |
| 881 | static int cfg80211_set_auth_alg(struct wireless_dev *wdev, |
| 882 | s32 auth_alg) |
| 883 | { |
| 884 | int nr_alg = 0; |
| 885 | |
| 886 | if (!auth_alg) |
| 887 | return -EINVAL; |
| 888 | |
| 889 | if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM | |
| 890 | IW_AUTH_ALG_SHARED_KEY | |
| 891 | IW_AUTH_ALG_LEAP)) |
| 892 | return -EINVAL; |
| 893 | |
| 894 | if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) { |
| 895 | nr_alg++; |
| 896 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 897 | } |
| 898 | |
| 899 | if (auth_alg & IW_AUTH_ALG_SHARED_KEY) { |
| 900 | nr_alg++; |
| 901 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY; |
| 902 | } |
| 903 | |
| 904 | if (auth_alg & IW_AUTH_ALG_LEAP) { |
| 905 | nr_alg++; |
| 906 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 907 | } |
| 908 | |
| 909 | if (nr_alg > 1) |
| 910 | wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 911 | |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions) |
| 916 | { |
| 917 | wdev->wext.connect.crypto.wpa_versions = 0; |
| 918 | |
| 919 | if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA | |
Gábor Stefanik | 323d566 | 2009-07-12 02:03:48 +0200 | [diff] [blame] | 920 | IW_AUTH_WPA_VERSION_WPA2| |
| 921 | IW_AUTH_WPA_VERSION_DISABLED)) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 922 | return -EINVAL; |
| 923 | |
Gábor Stefanik | 323d566 | 2009-07-12 02:03:48 +0200 | [diff] [blame] | 924 | if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) && |
| 925 | (wpa_versions & (IW_AUTH_WPA_VERSION_WPA| |
| 926 | IW_AUTH_WPA_VERSION_WPA2))) |
| 927 | return -EINVAL; |
| 928 | |
| 929 | if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) |
| 930 | wdev->wext.connect.crypto.wpa_versions &= |
| 931 | ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2); |
| 932 | |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 933 | if (wpa_versions & IW_AUTH_WPA_VERSION_WPA) |
| 934 | wdev->wext.connect.crypto.wpa_versions |= |
| 935 | NL80211_WPA_VERSION_1; |
| 936 | |
| 937 | if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2) |
| 938 | wdev->wext.connect.crypto.wpa_versions |= |
| 939 | NL80211_WPA_VERSION_2; |
| 940 | |
| 941 | return 0; |
| 942 | } |
| 943 | |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 944 | static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 945 | { |
| 946 | wdev->wext.connect.crypto.cipher_group = 0; |
| 947 | |
| 948 | if (cipher & IW_AUTH_CIPHER_WEP40) |
| 949 | wdev->wext.connect.crypto.cipher_group = |
| 950 | WLAN_CIPHER_SUITE_WEP40; |
| 951 | else if (cipher & IW_AUTH_CIPHER_WEP104) |
| 952 | wdev->wext.connect.crypto.cipher_group = |
| 953 | WLAN_CIPHER_SUITE_WEP104; |
| 954 | else if (cipher & IW_AUTH_CIPHER_TKIP) |
| 955 | wdev->wext.connect.crypto.cipher_group = |
| 956 | WLAN_CIPHER_SUITE_TKIP; |
| 957 | else if (cipher & IW_AUTH_CIPHER_CCMP) |
| 958 | wdev->wext.connect.crypto.cipher_group = |
| 959 | WLAN_CIPHER_SUITE_CCMP; |
| 960 | else if (cipher & IW_AUTH_CIPHER_AES_CMAC) |
| 961 | wdev->wext.connect.crypto.cipher_group = |
| 962 | WLAN_CIPHER_SUITE_AES_CMAC; |
| 963 | else |
| 964 | return -EINVAL; |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 969 | static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher) |
Johannes Berg | f212935 | 2009-07-01 21:26:56 +0200 | [diff] [blame] | 970 | { |
| 971 | int nr_ciphers = 0; |
| 972 | u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise; |
| 973 | |
| 974 | if (cipher & IW_AUTH_CIPHER_WEP40) { |
| 975 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40; |
| 976 | nr_ciphers++; |
| 977 | } |
| 978 | |
| 979 | if (cipher & IW_AUTH_CIPHER_WEP104) { |
| 980 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104; |
| 981 | nr_ciphers++; |
| 982 | } |
| 983 | |
| 984 | if (cipher & IW_AUTH_CIPHER_TKIP) { |
| 985 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP; |
| 986 | nr_ciphers++; |
| 987 | } |
| 988 | |
| 989 | if (cipher & IW_AUTH_CIPHER_CCMP) { |
| 990 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP; |
| 991 | nr_ciphers++; |
| 992 | } |
| 993 | |
| 994 | if (cipher & IW_AUTH_CIPHER_AES_CMAC) { |
| 995 | ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC; |
| 996 | nr_ciphers++; |
| 997 | } |
| 998 | |
| 999 | BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5); |
| 1000 | |
| 1001 | wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers; |
| 1002 | |
| 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 1007 | 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] | 1008 | { |
| 1009 | int nr_akm_suites = 0; |
| 1010 | |
| 1011 | if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X | |
| 1012 | IW_AUTH_KEY_MGMT_PSK)) |
| 1013 | return -EINVAL; |
| 1014 | |
| 1015 | if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) { |
| 1016 | wdev->wext.connect.crypto.akm_suites[nr_akm_suites] = |
| 1017 | WLAN_AKM_SUITE_8021X; |
| 1018 | nr_akm_suites++; |
| 1019 | } |
| 1020 | |
| 1021 | if (key_mgt & IW_AUTH_KEY_MGMT_PSK) { |
| 1022 | wdev->wext.connect.crypto.akm_suites[nr_akm_suites] = |
| 1023 | WLAN_AKM_SUITE_PSK; |
| 1024 | nr_akm_suites++; |
| 1025 | } |
| 1026 | |
| 1027 | wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites; |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | int cfg80211_wext_siwauth(struct net_device *dev, |
| 1033 | struct iw_request_info *info, |
| 1034 | struct iw_param *data, char *extra) |
| 1035 | { |
| 1036 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1037 | |
| 1038 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 1039 | return -EOPNOTSUPP; |
| 1040 | |
| 1041 | switch (data->flags & IW_AUTH_INDEX) { |
| 1042 | case IW_AUTH_PRIVACY_INVOKED: |
| 1043 | wdev->wext.connect.privacy = data->value; |
| 1044 | return 0; |
| 1045 | case IW_AUTH_WPA_VERSION: |
| 1046 | return cfg80211_set_wpa_version(wdev, data->value); |
| 1047 | case IW_AUTH_CIPHER_GROUP: |
| 1048 | return cfg80211_set_cipher_group(wdev, data->value); |
| 1049 | case IW_AUTH_KEY_MGMT: |
| 1050 | return cfg80211_set_key_mgt(wdev, data->value); |
| 1051 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1052 | return cfg80211_set_cipher_pairwise(wdev, data->value); |
| 1053 | case IW_AUTH_80211_AUTH_ALG: |
| 1054 | return cfg80211_set_auth_alg(wdev, data->value); |
| 1055 | case IW_AUTH_WPA_ENABLED: |
| 1056 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 1057 | case IW_AUTH_DROP_UNENCRYPTED: |
| 1058 | case IW_AUTH_MFP: |
| 1059 | return 0; |
| 1060 | default: |
| 1061 | return -EOPNOTSUPP; |
| 1062 | } |
| 1063 | } |
| 1064 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth); |
| 1065 | |
| 1066 | int cfg80211_wext_giwauth(struct net_device *dev, |
| 1067 | struct iw_request_info *info, |
| 1068 | struct iw_param *data, char *extra) |
| 1069 | { |
| 1070 | /* XXX: what do we need? */ |
| 1071 | |
| 1072 | return -EOPNOTSUPP; |
| 1073 | } |
| 1074 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth); |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1075 | |
| 1076 | int cfg80211_wext_siwpower(struct net_device *dev, |
| 1077 | struct iw_request_info *info, |
| 1078 | struct iw_param *wrq, char *extra) |
| 1079 | { |
| 1080 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1081 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 1082 | bool ps = wdev->wext.ps; |
| 1083 | int timeout = wdev->wext.ps_timeout; |
| 1084 | int err; |
| 1085 | |
| 1086 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 1087 | return -EINVAL; |
| 1088 | |
| 1089 | if (!rdev->ops->set_power_mgmt) |
| 1090 | return -EOPNOTSUPP; |
| 1091 | |
| 1092 | if (wrq->disabled) { |
| 1093 | ps = false; |
| 1094 | } else { |
| 1095 | switch (wrq->flags & IW_POWER_MODE) { |
| 1096 | case IW_POWER_ON: /* If not specified */ |
| 1097 | case IW_POWER_MODE: /* If set all mask */ |
| 1098 | case IW_POWER_ALL_R: /* If explicitely state all */ |
| 1099 | ps = true; |
| 1100 | break; |
| 1101 | default: /* Otherwise we ignore */ |
| 1102 | return -EINVAL; |
| 1103 | } |
| 1104 | |
| 1105 | if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT)) |
| 1106 | return -EINVAL; |
| 1107 | |
| 1108 | if (wrq->flags & IW_POWER_TIMEOUT) |
| 1109 | timeout = wrq->value / 1000; |
| 1110 | } |
| 1111 | |
| 1112 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout); |
| 1113 | if (err) |
| 1114 | return err; |
| 1115 | |
| 1116 | wdev->wext.ps = ps; |
| 1117 | wdev->wext.ps_timeout = timeout; |
| 1118 | |
| 1119 | return 0; |
| 1120 | |
| 1121 | } |
| 1122 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower); |
| 1123 | |
| 1124 | int cfg80211_wext_giwpower(struct net_device *dev, |
| 1125 | struct iw_request_info *info, |
| 1126 | struct iw_param *wrq, char *extra) |
| 1127 | { |
| 1128 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1129 | |
| 1130 | wrq->disabled = !wdev->wext.ps; |
| 1131 | |
| 1132 | return 0; |
| 1133 | } |
| 1134 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower); |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1135 | |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1136 | static int cfg80211_wds_wext_siwap(struct net_device *dev, |
| 1137 | struct iw_request_info *info, |
| 1138 | struct sockaddr *addr, char *extra) |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1139 | { |
| 1140 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1141 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 1142 | int err; |
| 1143 | |
| 1144 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS)) |
| 1145 | return -EINVAL; |
| 1146 | |
| 1147 | if (addr->sa_family != ARPHRD_ETHER) |
| 1148 | return -EINVAL; |
| 1149 | |
| 1150 | if (netif_running(dev)) |
| 1151 | return -EBUSY; |
| 1152 | |
| 1153 | if (!rdev->ops->set_wds_peer) |
| 1154 | return -EOPNOTSUPP; |
| 1155 | |
| 1156 | err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data); |
| 1157 | if (err) |
| 1158 | return err; |
| 1159 | |
| 1160 | memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN); |
| 1161 | |
| 1162 | return 0; |
| 1163 | } |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1164 | |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1165 | static int cfg80211_wds_wext_giwap(struct net_device *dev, |
| 1166 | struct iw_request_info *info, |
| 1167 | struct sockaddr *addr, char *extra) |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1168 | { |
| 1169 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1170 | |
| 1171 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS)) |
| 1172 | return -EINVAL; |
| 1173 | |
| 1174 | addr->sa_family = ARPHRD_ETHER; |
| 1175 | memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN); |
| 1176 | |
| 1177 | return 0; |
| 1178 | } |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1179 | |
| 1180 | int cfg80211_wext_siwrate(struct net_device *dev, |
| 1181 | struct iw_request_info *info, |
| 1182 | struct iw_param *rate, char *extra) |
| 1183 | { |
| 1184 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1185 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 1186 | struct cfg80211_bitrate_mask mask; |
| 1187 | |
| 1188 | if (!rdev->ops->set_bitrate_mask) |
| 1189 | return -EOPNOTSUPP; |
| 1190 | |
| 1191 | mask.fixed = 0; |
| 1192 | mask.maxrate = 0; |
| 1193 | |
| 1194 | if (rate->value < 0) { |
| 1195 | /* nothing */ |
| 1196 | } else if (rate->fixed) { |
| 1197 | mask.fixed = rate->value / 1000; /* kbps */ |
| 1198 | } else { |
| 1199 | mask.maxrate = rate->value / 1000; /* kbps */ |
| 1200 | } |
| 1201 | |
| 1202 | return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask); |
| 1203 | } |
| 1204 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate); |
| 1205 | |
| 1206 | int cfg80211_wext_giwrate(struct net_device *dev, |
| 1207 | struct iw_request_info *info, |
| 1208 | struct iw_param *rate, char *extra) |
| 1209 | { |
| 1210 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1211 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 1212 | /* we are under RTNL - globally locked - so can use a static struct */ |
| 1213 | static struct station_info sinfo; |
Johannes Berg | a71d62d | 2009-07-07 23:41:27 +0200 | [diff] [blame] | 1214 | u8 addr[ETH_ALEN]; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1215 | int err; |
| 1216 | |
| 1217 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 1218 | return -EOPNOTSUPP; |
| 1219 | |
| 1220 | if (!rdev->ops->get_station) |
| 1221 | return -EOPNOTSUPP; |
| 1222 | |
Johannes Berg | a71d62d | 2009-07-07 23:41:27 +0200 | [diff] [blame] | 1223 | err = 0; |
| 1224 | wdev_lock(wdev); |
Samuel Ortiz | 6c230c0 | 2009-07-03 02:00:48 +0200 | [diff] [blame] | 1225 | if (wdev->current_bss) |
Johannes Berg | a71d62d | 2009-07-07 23:41:27 +0200 | [diff] [blame] | 1226 | memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN); |
Samuel Ortiz | 6c230c0 | 2009-07-03 02:00:48 +0200 | [diff] [blame] | 1227 | else |
Johannes Berg | a71d62d | 2009-07-07 23:41:27 +0200 | [diff] [blame] | 1228 | err = -EOPNOTSUPP; |
| 1229 | wdev_unlock(wdev); |
| 1230 | if (err) |
| 1231 | return err; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1232 | |
| 1233 | err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo); |
| 1234 | if (err) |
| 1235 | return err; |
| 1236 | |
| 1237 | if (!(sinfo.filled & STATION_INFO_TX_BITRATE)) |
| 1238 | return -EOPNOTSUPP; |
| 1239 | |
| 1240 | rate->value = 0; |
| 1241 | |
| 1242 | if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS)) |
| 1243 | rate->value = 100000 * sinfo.txrate.legacy; |
| 1244 | |
| 1245 | return 0; |
| 1246 | } |
| 1247 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate); |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1248 | |
| 1249 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ |
| 1250 | struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev) |
| 1251 | { |
| 1252 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1253 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 1254 | /* we are under RTNL - globally locked - so can use static structs */ |
| 1255 | static struct iw_statistics wstats; |
| 1256 | static struct station_info sinfo; |
Johannes Berg | c56c571 | 2009-07-10 16:54:07 +0200 | [diff] [blame] | 1257 | u8 bssid[ETH_ALEN]; |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1258 | |
| 1259 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) |
| 1260 | return NULL; |
| 1261 | |
| 1262 | if (!rdev->ops->get_station) |
| 1263 | return NULL; |
| 1264 | |
Johannes Berg | c56c571 | 2009-07-10 16:54:07 +0200 | [diff] [blame] | 1265 | /* Grab BSSID of current BSS, if any */ |
| 1266 | wdev_lock(wdev); |
| 1267 | if (!wdev->current_bss) { |
| 1268 | wdev_unlock(wdev); |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1269 | return NULL; |
Johannes Berg | c56c571 | 2009-07-10 16:54:07 +0200 | [diff] [blame] | 1270 | } |
| 1271 | memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN); |
| 1272 | wdev_unlock(wdev); |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1273 | |
Johannes Berg | c56c571 | 2009-07-10 16:54:07 +0200 | [diff] [blame] | 1274 | if (rdev->ops->get_station(&rdev->wiphy, dev, bssid, &sinfo)) |
Johannes Berg | 8990646 | 2009-07-01 21:27:00 +0200 | [diff] [blame] | 1275 | return NULL; |
| 1276 | |
| 1277 | memset(&wstats, 0, sizeof(wstats)); |
| 1278 | |
| 1279 | switch (rdev->wiphy.signal_type) { |
| 1280 | case CFG80211_SIGNAL_TYPE_MBM: |
| 1281 | if (sinfo.filled & STATION_INFO_SIGNAL) { |
| 1282 | int sig = sinfo.signal; |
| 1283 | wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 1284 | wstats.qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 1285 | wstats.qual.updated |= IW_QUAL_DBM; |
| 1286 | wstats.qual.level = sig; |
| 1287 | if (sig < -110) |
| 1288 | sig = -110; |
| 1289 | else if (sig > -40) |
| 1290 | sig = -40; |
| 1291 | wstats.qual.qual = sig + 110; |
| 1292 | break; |
| 1293 | } |
| 1294 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 1295 | if (sinfo.filled & STATION_INFO_SIGNAL) { |
| 1296 | wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 1297 | wstats.qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 1298 | wstats.qual.level = sinfo.signal; |
| 1299 | wstats.qual.qual = sinfo.signal; |
| 1300 | break; |
| 1301 | } |
| 1302 | default: |
| 1303 | wstats.qual.updated |= IW_QUAL_LEVEL_INVALID; |
| 1304 | wstats.qual.updated |= IW_QUAL_QUAL_INVALID; |
| 1305 | } |
| 1306 | |
| 1307 | wstats.qual.updated |= IW_QUAL_NOISE_INVALID; |
| 1308 | |
| 1309 | return &wstats; |
| 1310 | } |
| 1311 | EXPORT_SYMBOL_GPL(cfg80211_wireless_stats); |
Johannes Berg | 562e482 | 2009-07-27 12:01:51 +0200 | [diff] [blame] | 1312 | |
| 1313 | int cfg80211_wext_siwap(struct net_device *dev, |
| 1314 | struct iw_request_info *info, |
| 1315 | struct sockaddr *ap_addr, char *extra) |
| 1316 | { |
| 1317 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1318 | |
| 1319 | switch (wdev->iftype) { |
| 1320 | case NL80211_IFTYPE_ADHOC: |
| 1321 | return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra); |
| 1322 | case NL80211_IFTYPE_STATION: |
| 1323 | return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra); |
| 1324 | case NL80211_IFTYPE_WDS: |
| 1325 | return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra); |
| 1326 | default: |
| 1327 | return -EOPNOTSUPP; |
| 1328 | } |
| 1329 | } |
| 1330 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwap); |
| 1331 | |
| 1332 | int cfg80211_wext_giwap(struct net_device *dev, |
| 1333 | struct iw_request_info *info, |
| 1334 | struct sockaddr *ap_addr, char *extra) |
| 1335 | { |
| 1336 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1337 | |
| 1338 | switch (wdev->iftype) { |
| 1339 | case NL80211_IFTYPE_ADHOC: |
| 1340 | return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra); |
| 1341 | case NL80211_IFTYPE_STATION: |
| 1342 | return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra); |
| 1343 | case NL80211_IFTYPE_WDS: |
| 1344 | return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra); |
| 1345 | default: |
| 1346 | return -EOPNOTSUPP; |
| 1347 | } |
| 1348 | } |
| 1349 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwap); |
Johannes Berg | 1f9298f | 2009-07-27 12:01:52 +0200 | [diff] [blame] | 1350 | |
| 1351 | int cfg80211_wext_siwessid(struct net_device *dev, |
| 1352 | struct iw_request_info *info, |
| 1353 | struct iw_point *data, char *ssid) |
| 1354 | { |
| 1355 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1356 | |
| 1357 | switch (wdev->iftype) { |
| 1358 | case NL80211_IFTYPE_ADHOC: |
| 1359 | return cfg80211_ibss_wext_siwessid(dev, info, data, ssid); |
| 1360 | case NL80211_IFTYPE_STATION: |
| 1361 | return cfg80211_mgd_wext_siwessid(dev, info, data, ssid); |
| 1362 | default: |
| 1363 | return -EOPNOTSUPP; |
| 1364 | } |
| 1365 | } |
| 1366 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwessid); |
| 1367 | |
| 1368 | int cfg80211_wext_giwessid(struct net_device *dev, |
| 1369 | struct iw_request_info *info, |
| 1370 | struct iw_point *data, char *ssid) |
| 1371 | { |
| 1372 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1373 | |
| 1374 | switch (wdev->iftype) { |
| 1375 | case NL80211_IFTYPE_ADHOC: |
| 1376 | return cfg80211_ibss_wext_giwessid(dev, info, data, ssid); |
| 1377 | case NL80211_IFTYPE_STATION: |
| 1378 | return cfg80211_mgd_wext_giwessid(dev, info, data, ssid); |
| 1379 | default: |
| 1380 | return -EOPNOTSUPP; |
| 1381 | } |
| 1382 | } |
| 1383 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid); |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 1384 | |
| 1385 | static const iw_handler cfg80211_handlers[] = { |
| 1386 | [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname, |
| 1387 | [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq, |
| 1388 | [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq, |
| 1389 | [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode, |
| 1390 | [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode, |
| 1391 | [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange, |
| 1392 | [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap, |
| 1393 | [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap, |
| 1394 | [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme, |
| 1395 | [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan, |
| 1396 | [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan, |
| 1397 | [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid, |
| 1398 | [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid, |
| 1399 | [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate, |
| 1400 | [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate, |
| 1401 | [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts, |
| 1402 | [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts, |
| 1403 | [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag, |
| 1404 | [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag, |
| 1405 | [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower, |
| 1406 | [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower, |
| 1407 | [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry, |
| 1408 | [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry, |
| 1409 | [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode, |
| 1410 | [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode, |
| 1411 | [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower, |
| 1412 | [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower, |
| 1413 | [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie, |
| 1414 | [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth, |
| 1415 | [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth, |
| 1416 | [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext, |
| 1417 | }; |
| 1418 | |
| 1419 | const struct iw_handler_def cfg80211_wext_handler = { |
| 1420 | .num_standard = ARRAY_SIZE(cfg80211_handlers), |
| 1421 | .standard = cfg80211_handlers, |
| 1422 | .get_wireless_stats = cfg80211_wireless_stats, |
| 1423 | }; |