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> |
| 17 | #include "core.h" |
| 18 | |
| 19 | int cfg80211_wext_giwname(struct net_device *dev, |
| 20 | struct iw_request_info *info, |
| 21 | char *name, char *extra) |
| 22 | { |
| 23 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 24 | struct ieee80211_supported_band *sband; |
| 25 | bool is_ht = false, is_a = false, is_b = false, is_g = false; |
| 26 | |
| 27 | if (!wdev) |
| 28 | return -EOPNOTSUPP; |
| 29 | |
| 30 | sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 31 | if (sband) { |
| 32 | is_a = true; |
| 33 | is_ht |= sband->ht_cap.ht_supported; |
| 34 | } |
| 35 | |
| 36 | sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 37 | if (sband) { |
| 38 | int i; |
| 39 | /* Check for mandatory rates */ |
| 40 | for (i = 0; i < sband->n_bitrates; i++) { |
| 41 | if (sband->bitrates[i].bitrate == 10) |
| 42 | is_b = true; |
| 43 | if (sband->bitrates[i].bitrate == 60) |
| 44 | is_g = true; |
| 45 | } |
| 46 | is_ht |= sband->ht_cap.ht_supported; |
| 47 | } |
| 48 | |
| 49 | strcpy(name, "IEEE 802.11"); |
| 50 | if (is_a) |
| 51 | strcat(name, "a"); |
| 52 | if (is_b) |
| 53 | strcat(name, "b"); |
| 54 | if (is_g) |
| 55 | strcat(name, "g"); |
| 56 | if (is_ht) |
| 57 | strcat(name, "n"); |
| 58 | |
| 59 | return 0; |
| 60 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 61 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwname); |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 62 | |
| 63 | int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info, |
| 64 | u32 *mode, char *extra) |
| 65 | { |
| 66 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 67 | struct cfg80211_registered_device *rdev; |
| 68 | struct vif_params vifparams; |
| 69 | enum nl80211_iftype type; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 70 | int ret; |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 71 | |
| 72 | if (!wdev) |
| 73 | return -EOPNOTSUPP; |
| 74 | |
| 75 | rdev = wiphy_to_dev(wdev->wiphy); |
| 76 | |
| 77 | if (!rdev->ops->change_virtual_intf) |
| 78 | return -EOPNOTSUPP; |
| 79 | |
| 80 | /* don't support changing VLANs, you just re-create them */ |
| 81 | if (wdev->iftype == NL80211_IFTYPE_AP_VLAN) |
| 82 | return -EOPNOTSUPP; |
| 83 | |
| 84 | switch (*mode) { |
| 85 | case IW_MODE_INFRA: |
| 86 | type = NL80211_IFTYPE_STATION; |
| 87 | break; |
| 88 | case IW_MODE_ADHOC: |
| 89 | type = NL80211_IFTYPE_ADHOC; |
| 90 | break; |
| 91 | case IW_MODE_REPEAT: |
| 92 | type = NL80211_IFTYPE_WDS; |
| 93 | break; |
| 94 | case IW_MODE_MONITOR: |
| 95 | type = NL80211_IFTYPE_MONITOR; |
| 96 | break; |
| 97 | default: |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 101 | if (type == wdev->iftype) |
| 102 | return 0; |
| 103 | |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 104 | memset(&vifparams, 0, sizeof(vifparams)); |
| 105 | |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 106 | ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev, type, |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 107 | NULL, &vifparams); |
| 108 | WARN_ON(!ret && wdev->iftype != type); |
| 109 | |
| 110 | return ret; |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 111 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 112 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode); |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 113 | |
| 114 | int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info, |
| 115 | u32 *mode, char *extra) |
| 116 | { |
| 117 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 118 | |
| 119 | if (!wdev) |
| 120 | return -EOPNOTSUPP; |
| 121 | |
| 122 | switch (wdev->iftype) { |
| 123 | case NL80211_IFTYPE_AP: |
| 124 | *mode = IW_MODE_MASTER; |
| 125 | break; |
| 126 | case NL80211_IFTYPE_STATION: |
| 127 | *mode = IW_MODE_INFRA; |
| 128 | break; |
| 129 | case NL80211_IFTYPE_ADHOC: |
| 130 | *mode = IW_MODE_ADHOC; |
| 131 | break; |
| 132 | case NL80211_IFTYPE_MONITOR: |
| 133 | *mode = IW_MODE_MONITOR; |
| 134 | break; |
| 135 | case NL80211_IFTYPE_WDS: |
| 136 | *mode = IW_MODE_REPEAT; |
| 137 | break; |
| 138 | case NL80211_IFTYPE_AP_VLAN: |
| 139 | *mode = IW_MODE_SECOND; /* FIXME */ |
| 140 | break; |
| 141 | default: |
| 142 | *mode = IW_MODE_AUTO; |
| 143 | break; |
| 144 | } |
| 145 | return 0; |
| 146 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 147 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode); |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 148 | |
| 149 | |
| 150 | int cfg80211_wext_giwrange(struct net_device *dev, |
| 151 | struct iw_request_info *info, |
| 152 | struct iw_point *data, char *extra) |
| 153 | { |
| 154 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 155 | struct iw_range *range = (struct iw_range *) extra; |
| 156 | enum ieee80211_band band; |
| 157 | int c = 0; |
| 158 | |
| 159 | if (!wdev) |
| 160 | return -EOPNOTSUPP; |
| 161 | |
| 162 | data->length = sizeof(struct iw_range); |
| 163 | memset(range, 0, sizeof(struct iw_range)); |
| 164 | |
| 165 | range->we_version_compiled = WIRELESS_EXT; |
| 166 | range->we_version_source = 21; |
| 167 | range->retry_capa = IW_RETRY_LIMIT; |
| 168 | range->retry_flags = IW_RETRY_LIMIT; |
| 169 | range->min_retry = 0; |
| 170 | range->max_retry = 255; |
| 171 | range->min_rts = 0; |
| 172 | range->max_rts = 2347; |
| 173 | range->min_frag = 256; |
| 174 | range->max_frag = 2346; |
| 175 | |
| 176 | range->encoding_size[0] = 5; |
| 177 | range->encoding_size[1] = 13; |
| 178 | range->num_encoding_sizes = 2; |
| 179 | range->max_encoding_tokens = 4; |
| 180 | |
| 181 | range->max_qual.updated = IW_QUAL_NOISE_INVALID; |
| 182 | |
| 183 | switch (wdev->wiphy->signal_type) { |
| 184 | case CFG80211_SIGNAL_TYPE_NONE: |
| 185 | break; |
| 186 | case CFG80211_SIGNAL_TYPE_MBM: |
| 187 | range->max_qual.level = -110; |
| 188 | range->max_qual.qual = 70; |
| 189 | range->avg_qual.qual = 35; |
| 190 | range->max_qual.updated |= IW_QUAL_DBM; |
| 191 | range->max_qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 192 | range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 193 | break; |
| 194 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 195 | range->max_qual.level = 100; |
| 196 | range->max_qual.qual = 100; |
| 197 | range->avg_qual.qual = 50; |
| 198 | range->max_qual.updated |= IW_QUAL_QUAL_UPDATED; |
| 199 | range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED; |
| 200 | break; |
| 201 | } |
| 202 | |
| 203 | range->avg_qual.level = range->max_qual.level / 2; |
| 204 | range->avg_qual.noise = range->max_qual.noise / 2; |
| 205 | range->avg_qual.updated = range->max_qual.updated; |
| 206 | |
David Kilroy | 3daf097 | 2009-06-18 23:21:14 +0100 | [diff] [blame] | 207 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2; |
| 208 | |
| 209 | for (c = 0; c < wdev->wiphy->n_cipher_suites; c++) { |
| 210 | switch (wdev->wiphy->cipher_suites[c]) { |
| 211 | case WLAN_CIPHER_SUITE_TKIP: |
| 212 | range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP; |
| 213 | break; |
| 214 | |
| 215 | case WLAN_CIPHER_SUITE_CCMP: |
| 216 | range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP; |
| 217 | break; |
| 218 | } |
| 219 | } |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 220 | |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 221 | for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { |
| 222 | int i; |
| 223 | struct ieee80211_supported_band *sband; |
| 224 | |
| 225 | sband = wdev->wiphy->bands[band]; |
| 226 | |
| 227 | if (!sband) |
| 228 | continue; |
| 229 | |
| 230 | for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) { |
| 231 | struct ieee80211_channel *chan = &sband->channels[i]; |
| 232 | |
| 233 | if (!(chan->flags & IEEE80211_CHAN_DISABLED)) { |
| 234 | range->freq[c].i = |
| 235 | ieee80211_frequency_to_channel( |
| 236 | chan->center_freq); |
| 237 | range->freq[c].m = chan->center_freq; |
| 238 | range->freq[c].e = 6; |
| 239 | c++; |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | range->num_channels = c; |
| 244 | range->num_frequency = c; |
| 245 | |
| 246 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); |
| 247 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
| 248 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); |
| 249 | |
David Kilroy | 51cd4aa | 2009-06-18 23:21:15 +0100 | [diff] [blame^] | 250 | if (wdev->wiphy->max_scan_ssids > 0) |
| 251 | range->scan_capa |= IW_SCAN_CAPA_ESSID; |
Johannes Berg | 4aa188e | 2009-02-18 19:32:08 +0100 | [diff] [blame] | 252 | |
| 253 | return 0; |
| 254 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 255 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange); |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 256 | |
| 257 | int cfg80211_wext_siwmlme(struct net_device *dev, |
| 258 | struct iw_request_info *info, |
| 259 | struct iw_point *data, char *extra) |
| 260 | { |
| 261 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 262 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 263 | struct cfg80211_registered_device *rdev; |
| 264 | union { |
| 265 | struct cfg80211_disassoc_request disassoc; |
| 266 | struct cfg80211_deauth_request deauth; |
| 267 | } cmd; |
| 268 | |
| 269 | if (!wdev) |
| 270 | return -EOPNOTSUPP; |
| 271 | |
| 272 | rdev = wiphy_to_dev(wdev->wiphy); |
| 273 | |
| 274 | if (wdev->iftype != NL80211_IFTYPE_STATION) |
| 275 | return -EINVAL; |
| 276 | |
| 277 | if (mlme->addr.sa_family != ARPHRD_ETHER) |
| 278 | return -EINVAL; |
| 279 | |
| 280 | memset(&cmd, 0, sizeof(cmd)); |
| 281 | |
| 282 | switch (mlme->cmd) { |
| 283 | case IW_MLME_DEAUTH: |
| 284 | if (!rdev->ops->deauth) |
| 285 | return -EOPNOTSUPP; |
| 286 | cmd.deauth.peer_addr = mlme->addr.sa_data; |
| 287 | cmd.deauth.reason_code = mlme->reason_code; |
| 288 | return rdev->ops->deauth(wdev->wiphy, dev, &cmd.deauth); |
| 289 | case IW_MLME_DISASSOC: |
| 290 | if (!rdev->ops->disassoc) |
| 291 | return -EOPNOTSUPP; |
| 292 | cmd.disassoc.peer_addr = mlme->addr.sa_data; |
| 293 | cmd.disassoc.reason_code = mlme->reason_code; |
| 294 | return rdev->ops->disassoc(wdev->wiphy, dev, &cmd.disassoc); |
| 295 | default: |
| 296 | return -EOPNOTSUPP; |
| 297 | } |
| 298 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 299 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 300 | |
| 301 | |
| 302 | /** |
| 303 | * cfg80211_wext_freq - get wext frequency for non-"auto" |
| 304 | * @wiphy: the wiphy |
| 305 | * @freq: the wext freq encoding |
| 306 | * |
| 307 | * Returns a channel, %NULL for auto, or an ERR_PTR for errors! |
| 308 | */ |
| 309 | struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy, |
| 310 | struct iw_freq *freq) |
| 311 | { |
Johannes Berg | 0b25858 | 2009-05-08 09:42:33 +0200 | [diff] [blame] | 312 | struct ieee80211_channel *chan; |
| 313 | int f; |
| 314 | |
| 315 | /* |
| 316 | * Parse frequency - return NULL for auto and |
| 317 | * -EINVAL for impossible things. |
| 318 | */ |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 319 | if (freq->e == 0) { |
| 320 | if (freq->m < 0) |
| 321 | return NULL; |
Johannes Berg | 0b25858 | 2009-05-08 09:42:33 +0200 | [diff] [blame] | 322 | f = ieee80211_channel_to_frequency(freq->m); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 323 | } else { |
| 324 | int i, div = 1000000; |
| 325 | for (i = 0; i < freq->e; i++) |
| 326 | div /= 10; |
Johannes Berg | 0b25858 | 2009-05-08 09:42:33 +0200 | [diff] [blame] | 327 | if (div <= 0) |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 328 | return ERR_PTR(-EINVAL); |
Johannes Berg | 0b25858 | 2009-05-08 09:42:33 +0200 | [diff] [blame] | 329 | f = freq->m / div; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 330 | } |
| 331 | |
Johannes Berg | 0b25858 | 2009-05-08 09:42:33 +0200 | [diff] [blame] | 332 | /* |
| 333 | * Look up channel struct and return -EINVAL when |
| 334 | * it cannot be found. |
| 335 | */ |
| 336 | chan = ieee80211_get_channel(wiphy, f); |
| 337 | if (!chan) |
| 338 | return ERR_PTR(-EINVAL); |
| 339 | return chan; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 340 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 341 | EXPORT_SYMBOL_GPL(cfg80211_wext_freq); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 342 | |
| 343 | int cfg80211_wext_siwrts(struct net_device *dev, |
| 344 | struct iw_request_info *info, |
| 345 | struct iw_param *rts, char *extra) |
| 346 | { |
| 347 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 348 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 349 | u32 orts = wdev->wiphy->rts_threshold; |
| 350 | int err; |
| 351 | |
| 352 | if (rts->disabled || !rts->fixed) |
| 353 | wdev->wiphy->rts_threshold = (u32) -1; |
| 354 | else if (rts->value < 0) |
| 355 | return -EINVAL; |
| 356 | else |
| 357 | wdev->wiphy->rts_threshold = rts->value; |
| 358 | |
| 359 | err = rdev->ops->set_wiphy_params(wdev->wiphy, |
| 360 | WIPHY_PARAM_RTS_THRESHOLD); |
| 361 | if (err) |
| 362 | wdev->wiphy->rts_threshold = orts; |
| 363 | |
| 364 | return err; |
| 365 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 366 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 367 | |
| 368 | int cfg80211_wext_giwrts(struct net_device *dev, |
| 369 | struct iw_request_info *info, |
| 370 | struct iw_param *rts, char *extra) |
| 371 | { |
| 372 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 373 | |
| 374 | rts->value = wdev->wiphy->rts_threshold; |
| 375 | rts->disabled = rts->value == (u32) -1; |
| 376 | rts->fixed = 1; |
| 377 | |
| 378 | return 0; |
| 379 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 380 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 381 | |
| 382 | int cfg80211_wext_siwfrag(struct net_device *dev, |
| 383 | struct iw_request_info *info, |
| 384 | struct iw_param *frag, char *extra) |
| 385 | { |
| 386 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 387 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 388 | u32 ofrag = wdev->wiphy->frag_threshold; |
| 389 | int err; |
| 390 | |
| 391 | if (frag->disabled || !frag->fixed) |
| 392 | wdev->wiphy->frag_threshold = (u32) -1; |
| 393 | else if (frag->value < 256) |
| 394 | return -EINVAL; |
| 395 | else { |
| 396 | /* Fragment length must be even, so strip LSB. */ |
| 397 | wdev->wiphy->frag_threshold = frag->value & ~0x1; |
| 398 | } |
| 399 | |
| 400 | err = rdev->ops->set_wiphy_params(wdev->wiphy, |
| 401 | WIPHY_PARAM_FRAG_THRESHOLD); |
| 402 | if (err) |
| 403 | wdev->wiphy->frag_threshold = ofrag; |
| 404 | |
| 405 | return err; |
| 406 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 407 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 408 | |
| 409 | int cfg80211_wext_giwfrag(struct net_device *dev, |
| 410 | struct iw_request_info *info, |
| 411 | struct iw_param *frag, char *extra) |
| 412 | { |
| 413 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 414 | |
| 415 | frag->value = wdev->wiphy->frag_threshold; |
| 416 | frag->disabled = frag->value == (u32) -1; |
| 417 | frag->fixed = 1; |
| 418 | |
| 419 | return 0; |
| 420 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 421 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 422 | |
| 423 | int cfg80211_wext_siwretry(struct net_device *dev, |
| 424 | struct iw_request_info *info, |
| 425 | struct iw_param *retry, char *extra) |
| 426 | { |
| 427 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 428 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 429 | u32 changed = 0; |
| 430 | u8 olong = wdev->wiphy->retry_long; |
| 431 | u8 oshort = wdev->wiphy->retry_short; |
| 432 | int err; |
| 433 | |
| 434 | if (retry->disabled || |
| 435 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) |
| 436 | return -EINVAL; |
| 437 | |
| 438 | if (retry->flags & IW_RETRY_LONG) { |
| 439 | wdev->wiphy->retry_long = retry->value; |
| 440 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 441 | } else if (retry->flags & IW_RETRY_SHORT) { |
| 442 | wdev->wiphy->retry_short = retry->value; |
| 443 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 444 | } else { |
| 445 | wdev->wiphy->retry_short = retry->value; |
| 446 | wdev->wiphy->retry_long = retry->value; |
| 447 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 448 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 449 | } |
| 450 | |
| 451 | if (!changed) |
| 452 | return 0; |
| 453 | |
| 454 | err = rdev->ops->set_wiphy_params(wdev->wiphy, changed); |
| 455 | if (err) { |
| 456 | wdev->wiphy->retry_short = oshort; |
| 457 | wdev->wiphy->retry_long = olong; |
| 458 | } |
| 459 | |
| 460 | return err; |
| 461 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 462 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 463 | |
| 464 | int cfg80211_wext_giwretry(struct net_device *dev, |
| 465 | struct iw_request_info *info, |
| 466 | struct iw_param *retry, char *extra) |
| 467 | { |
| 468 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 469 | |
| 470 | retry->disabled = 0; |
| 471 | |
| 472 | if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) { |
| 473 | /* |
| 474 | * First return short value, iwconfig will ask long value |
| 475 | * later if needed |
| 476 | */ |
| 477 | retry->flags |= IW_RETRY_LIMIT; |
| 478 | retry->value = wdev->wiphy->retry_short; |
| 479 | if (wdev->wiphy->retry_long != wdev->wiphy->retry_short) |
| 480 | retry->flags |= IW_RETRY_LONG; |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | if (retry->flags & IW_RETRY_LONG) { |
| 486 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; |
| 487 | retry->value = wdev->wiphy->retry_long; |
| 488 | } |
| 489 | |
| 490 | return 0; |
| 491 | } |
Johannes Berg | ba44cb7 | 2009-04-20 18:49:39 +0200 | [diff] [blame] | 492 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 493 | |
| 494 | static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev, |
| 495 | struct net_device *dev, const u8 *addr, |
| 496 | bool remove, bool tx_key, int idx, |
| 497 | struct key_params *params) |
| 498 | { |
| 499 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 500 | int err; |
| 501 | |
| 502 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
| 503 | if (!rdev->ops->set_default_mgmt_key) |
| 504 | return -EOPNOTSUPP; |
| 505 | |
| 506 | if (idx < 4 || idx > 5) |
| 507 | return -EINVAL; |
| 508 | } else if (idx < 0 || idx > 3) |
| 509 | return -EINVAL; |
| 510 | |
| 511 | if (remove) { |
| 512 | err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr); |
| 513 | if (!err) { |
| 514 | if (idx == wdev->wext.default_key) |
| 515 | wdev->wext.default_key = -1; |
| 516 | else if (idx == wdev->wext.default_mgmt_key) |
| 517 | wdev->wext.default_mgmt_key = -1; |
| 518 | } |
Johannes Berg | e3da574 | 2009-05-18 19:56:36 +0200 | [diff] [blame] | 519 | /* |
| 520 | * Applications using wireless extensions expect to be |
| 521 | * able to delete keys that don't exist, so allow that. |
| 522 | */ |
| 523 | if (err == -ENOENT) |
| 524 | return 0; |
| 525 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 526 | return err; |
| 527 | } else { |
| 528 | if (addr) |
| 529 | tx_key = false; |
| 530 | |
| 531 | if (cfg80211_validate_key_settings(params, idx, addr)) |
| 532 | return -EINVAL; |
| 533 | |
| 534 | err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params); |
| 535 | if (err) |
| 536 | return err; |
| 537 | |
| 538 | if (tx_key || (!addr && wdev->wext.default_key == -1)) { |
| 539 | err = rdev->ops->set_default_key(&rdev->wiphy, |
| 540 | dev, idx); |
| 541 | if (!err) |
| 542 | wdev->wext.default_key = idx; |
| 543 | return err; |
| 544 | } |
| 545 | |
| 546 | if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC && |
| 547 | (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) { |
| 548 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 549 | dev, idx); |
| 550 | if (!err) |
| 551 | wdev->wext.default_mgmt_key = idx; |
| 552 | return err; |
| 553 | } |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | int cfg80211_wext_siwencode(struct net_device *dev, |
| 560 | struct iw_request_info *info, |
| 561 | struct iw_point *erq, char *keybuf) |
| 562 | { |
| 563 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 564 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 565 | int idx, err; |
| 566 | bool remove = false; |
| 567 | struct key_params params; |
| 568 | |
| 569 | /* no use -- only MFP (set_default_mgmt_key) is optional */ |
| 570 | if (!rdev->ops->del_key || |
| 571 | !rdev->ops->add_key || |
| 572 | !rdev->ops->set_default_key) |
| 573 | return -EOPNOTSUPP; |
| 574 | |
| 575 | idx = erq->flags & IW_ENCODE_INDEX; |
| 576 | if (idx == 0) { |
| 577 | idx = wdev->wext.default_key; |
| 578 | if (idx < 0) |
| 579 | idx = 0; |
| 580 | } else if (idx < 1 || idx > 4) |
| 581 | return -EINVAL; |
| 582 | else |
| 583 | idx--; |
| 584 | |
| 585 | if (erq->flags & IW_ENCODE_DISABLED) |
| 586 | remove = true; |
| 587 | else if (erq->length == 0) { |
| 588 | /* No key data - just set the default TX key index */ |
| 589 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, idx); |
| 590 | if (!err) |
| 591 | wdev->wext.default_key = idx; |
| 592 | return err; |
| 593 | } |
| 594 | |
| 595 | memset(¶ms, 0, sizeof(params)); |
| 596 | params.key = keybuf; |
| 597 | params.key_len = erq->length; |
| 598 | if (erq->length == 5) |
| 599 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
| 600 | else if (erq->length == 13) |
| 601 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
| 602 | else if (!remove) |
| 603 | return -EINVAL; |
| 604 | |
| 605 | return cfg80211_set_encryption(rdev, dev, NULL, remove, |
| 606 | wdev->wext.default_key == -1, |
| 607 | idx, ¶ms); |
| 608 | } |
| 609 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode); |
| 610 | |
| 611 | int cfg80211_wext_siwencodeext(struct net_device *dev, |
| 612 | struct iw_request_info *info, |
| 613 | struct iw_point *erq, char *extra) |
| 614 | { |
| 615 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 616 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 617 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; |
| 618 | const u8 *addr; |
| 619 | int idx; |
| 620 | bool remove = false; |
| 621 | struct key_params params; |
| 622 | u32 cipher; |
| 623 | |
| 624 | /* no use -- only MFP (set_default_mgmt_key) is optional */ |
| 625 | if (!rdev->ops->del_key || |
| 626 | !rdev->ops->add_key || |
| 627 | !rdev->ops->set_default_key) |
| 628 | return -EOPNOTSUPP; |
| 629 | |
| 630 | switch (ext->alg) { |
| 631 | case IW_ENCODE_ALG_NONE: |
| 632 | remove = true; |
| 633 | cipher = 0; |
| 634 | break; |
| 635 | case IW_ENCODE_ALG_WEP: |
| 636 | if (ext->key_len == 5) |
| 637 | cipher = WLAN_CIPHER_SUITE_WEP40; |
| 638 | else if (ext->key_len == 13) |
| 639 | cipher = WLAN_CIPHER_SUITE_WEP104; |
| 640 | else |
| 641 | return -EINVAL; |
| 642 | break; |
| 643 | case IW_ENCODE_ALG_TKIP: |
| 644 | cipher = WLAN_CIPHER_SUITE_TKIP; |
| 645 | break; |
| 646 | case IW_ENCODE_ALG_CCMP: |
| 647 | cipher = WLAN_CIPHER_SUITE_CCMP; |
| 648 | break; |
| 649 | case IW_ENCODE_ALG_AES_CMAC: |
| 650 | cipher = WLAN_CIPHER_SUITE_AES_CMAC; |
| 651 | break; |
| 652 | default: |
| 653 | return -EOPNOTSUPP; |
| 654 | } |
| 655 | |
| 656 | if (erq->flags & IW_ENCODE_DISABLED) |
| 657 | remove = true; |
| 658 | |
| 659 | idx = erq->flags & IW_ENCODE_INDEX; |
| 660 | if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
| 661 | if (idx < 4 || idx > 5) { |
| 662 | idx = wdev->wext.default_mgmt_key; |
| 663 | if (idx < 0) |
| 664 | return -EINVAL; |
| 665 | } else |
| 666 | idx--; |
| 667 | } else { |
| 668 | if (idx < 1 || idx > 4) { |
| 669 | idx = wdev->wext.default_key; |
| 670 | if (idx < 0) |
| 671 | return -EINVAL; |
| 672 | } else |
| 673 | idx--; |
| 674 | } |
| 675 | |
| 676 | addr = ext->addr.sa_data; |
| 677 | if (is_broadcast_ether_addr(addr)) |
| 678 | addr = NULL; |
| 679 | |
| 680 | memset(¶ms, 0, sizeof(params)); |
| 681 | params.key = ext->key; |
| 682 | params.key_len = ext->key_len; |
| 683 | params.cipher = cipher; |
| 684 | |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 685 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { |
| 686 | params.seq = ext->rx_seq; |
| 687 | params.seq_len = 6; |
| 688 | } |
| 689 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 690 | return cfg80211_set_encryption( |
| 691 | rdev, dev, addr, remove, |
| 692 | ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, |
| 693 | idx, ¶ms); |
| 694 | } |
| 695 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext); |
| 696 | |
| 697 | struct giwencode_cookie { |
| 698 | size_t buflen; |
| 699 | char *keybuf; |
| 700 | }; |
| 701 | |
| 702 | static void giwencode_get_key_cb(void *cookie, struct key_params *params) |
| 703 | { |
| 704 | struct giwencode_cookie *data = cookie; |
| 705 | |
| 706 | if (!params->key) { |
| 707 | data->buflen = 0; |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | data->buflen = min_t(size_t, data->buflen, params->key_len); |
| 712 | memcpy(data->keybuf, params->key, data->buflen); |
| 713 | } |
| 714 | |
| 715 | int cfg80211_wext_giwencode(struct net_device *dev, |
| 716 | struct iw_request_info *info, |
| 717 | struct iw_point *erq, char *keybuf) |
| 718 | { |
| 719 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 720 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 721 | int idx, err; |
| 722 | struct giwencode_cookie data = { |
| 723 | .keybuf = keybuf, |
| 724 | .buflen = erq->length, |
| 725 | }; |
| 726 | |
| 727 | if (!rdev->ops->get_key) |
| 728 | return -EOPNOTSUPP; |
| 729 | |
| 730 | idx = erq->flags & IW_ENCODE_INDEX; |
| 731 | if (idx == 0) { |
| 732 | idx = wdev->wext.default_key; |
| 733 | if (idx < 0) |
| 734 | idx = 0; |
| 735 | } else if (idx < 1 || idx > 4) |
| 736 | return -EINVAL; |
| 737 | else |
| 738 | idx--; |
| 739 | |
| 740 | erq->flags = idx + 1; |
| 741 | |
| 742 | err = rdev->ops->get_key(&rdev->wiphy, dev, idx, NULL, &data, |
| 743 | giwencode_get_key_cb); |
| 744 | if (!err) { |
| 745 | erq->length = data.buflen; |
| 746 | erq->flags |= IW_ENCODE_ENABLED; |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | if (err == -ENOENT) { |
| 751 | erq->flags |= IW_ENCODE_DISABLED; |
| 752 | erq->length = 0; |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | return err; |
| 757 | } |
| 758 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 759 | |
| 760 | int cfg80211_wext_siwtxpower(struct net_device *dev, |
| 761 | struct iw_request_info *info, |
| 762 | union iwreq_data *data, char *extra) |
| 763 | { |
| 764 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 765 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 766 | enum tx_power_setting type; |
| 767 | int dbm = 0; |
| 768 | |
| 769 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 770 | return -EINVAL; |
| 771 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 772 | return -EINVAL; |
| 773 | |
| 774 | if (!rdev->ops->set_tx_power) |
| 775 | return -EOPNOTSUPP; |
| 776 | |
| 777 | /* only change when not disabling */ |
| 778 | if (!data->txpower.disabled) { |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 779 | rfkill_set_sw_state(rdev->rfkill, false); |
| 780 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 781 | if (data->txpower.fixed) { |
| 782 | /* |
| 783 | * wext doesn't support negative values, see |
| 784 | * below where it's for automatic |
| 785 | */ |
| 786 | if (data->txpower.value < 0) |
| 787 | return -EINVAL; |
| 788 | dbm = data->txpower.value; |
| 789 | type = TX_POWER_FIXED; |
| 790 | /* TODO: do regulatory check! */ |
| 791 | } else { |
| 792 | /* |
| 793 | * Automatic power level setting, max being the value |
| 794 | * passed in from userland. |
| 795 | */ |
| 796 | if (data->txpower.value < 0) { |
| 797 | type = TX_POWER_AUTOMATIC; |
| 798 | } else { |
| 799 | dbm = data->txpower.value; |
| 800 | type = TX_POWER_LIMITED; |
| 801 | } |
| 802 | } |
| 803 | } else { |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 804 | rfkill_set_sw_state(rdev->rfkill, true); |
| 805 | schedule_work(&rdev->rfkill_sync); |
| 806 | return 0; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);; |
| 810 | } |
| 811 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower); |
| 812 | |
| 813 | int cfg80211_wext_giwtxpower(struct net_device *dev, |
| 814 | struct iw_request_info *info, |
| 815 | union iwreq_data *data, char *extra) |
| 816 | { |
| 817 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 818 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 819 | int err, val; |
| 820 | |
| 821 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) |
| 822 | return -EINVAL; |
| 823 | if (data->txpower.flags & IW_TXPOW_RANGE) |
| 824 | return -EINVAL; |
| 825 | |
| 826 | if (!rdev->ops->get_tx_power) |
| 827 | return -EOPNOTSUPP; |
| 828 | |
| 829 | err = rdev->ops->get_tx_power(wdev->wiphy, &val); |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 830 | if (err) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 831 | return err; |
| 832 | |
| 833 | /* well... oh well */ |
| 834 | data->txpower.fixed = 1; |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 835 | data->txpower.disabled = rfkill_blocked(rdev->rfkill); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 836 | data->txpower.value = val; |
| 837 | data->txpower.flags = IW_TXPOW_DBM; |
| 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower); |