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