1 // SPDX-License-Identifier: GPL-2.0 2 /* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */ 3 4 #include <linux/slab.h> 5 #include <linux/types.h> 6 #include <linux/sched/signal.h> 7 #include <linux/ethtool.h> 8 #include <linux/if_arp.h> 9 #include <linux/module.h> 10 #include <linux/etherdevice.h> 11 #include <net/lib80211.h> 12 13 #include "hostap_wlan.h" 14 #include "hostap.h" 15 #include "hostap_ap.h" 16 17 static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev) 18 { 19 struct hostap_interface *iface; 20 local_info_t *local; 21 struct iw_statistics *wstats; 22 23 iface = netdev_priv(dev); 24 local = iface->local; 25 26 /* Why are we doing that ? Jean II */ 27 if (iface->type != HOSTAP_INTERFACE_MAIN) 28 return NULL; 29 30 wstats = &local->wstats; 31 32 wstats->status = 0; 33 wstats->discard.code = 34 local->comm_tallies.rx_discards_wep_undecryptable; 35 wstats->discard.misc = 36 local->comm_tallies.rx_fcs_errors + 37 local->comm_tallies.rx_discards_no_buffer + 38 local->comm_tallies.tx_discards_wrong_sa; 39 40 wstats->discard.retries = 41 local->comm_tallies.tx_retry_limit_exceeded; 42 wstats->discard.fragment = 43 local->comm_tallies.rx_message_in_bad_msg_fragments; 44 45 if (local->iw_mode != IW_MODE_MASTER && 46 local->iw_mode != IW_MODE_REPEAT) { 47 int update = 1; 48 #ifdef in_atomic 49 /* RID reading might sleep and it must not be called in 50 * interrupt context or while atomic. However, this 51 * function seems to be called while atomic (at least in Linux 52 * 2.5.59). Update signal quality values only if in suitable 53 * context. Otherwise, previous values read from tick timer 54 * will be used. */ 55 if (in_atomic()) 56 update = 0; 57 #endif /* in_atomic */ 58 59 if (update && prism2_update_comms_qual(dev) == 0) 60 wstats->qual.updated = IW_QUAL_ALL_UPDATED | 61 IW_QUAL_DBM; 62 63 wstats->qual.qual = local->comms_qual; 64 wstats->qual.level = local->avg_signal; 65 wstats->qual.noise = local->avg_noise; 66 } else { 67 wstats->qual.qual = 0; 68 wstats->qual.level = 0; 69 wstats->qual.noise = 0; 70 wstats->qual.updated = IW_QUAL_ALL_INVALID; 71 } 72 73 return wstats; 74 } 75 76 77 static int prism2_get_datarates(struct net_device *dev, u8 *rates) 78 { 79 struct hostap_interface *iface; 80 local_info_t *local; 81 u8 buf[12]; 82 int len; 83 u16 val; 84 85 iface = netdev_priv(dev); 86 local = iface->local; 87 88 len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf, 89 sizeof(buf), 0); 90 if (len < 2) 91 return 0; 92 93 val = le16_to_cpu(*(__le16 *) buf); /* string length */ 94 95 if (len - 2 < val || val > 10) 96 return 0; 97 98 memcpy(rates, buf + 2, val); 99 return val; 100 } 101 102 103 static int prism2_get_name(struct net_device *dev, 104 struct iw_request_info *info, 105 char *name, char *extra) 106 { 107 u8 rates[10]; 108 int len, i, over2 = 0; 109 110 len = prism2_get_datarates(dev, rates); 111 112 for (i = 0; i < len; i++) { 113 if (rates[i] == 0x0b || rates[i] == 0x16) { 114 over2 = 1; 115 break; 116 } 117 } 118 119 strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS"); 120 121 return 0; 122 } 123 124 125 static int prism2_ioctl_siwencode(struct net_device *dev, 126 struct iw_request_info *info, 127 struct iw_point *erq, char *keybuf) 128 { 129 struct hostap_interface *iface; 130 local_info_t *local; 131 int i; 132 struct lib80211_crypt_data **crypt; 133 134 iface = netdev_priv(dev); 135 local = iface->local; 136 137 i = erq->flags & IW_ENCODE_INDEX; 138 if (i < 1 || i > 4) 139 i = local->crypt_info.tx_keyidx; 140 else 141 i--; 142 if (i < 0 || i >= WEP_KEYS) 143 return -EINVAL; 144 145 crypt = &local->crypt_info.crypt[i]; 146 147 if (erq->flags & IW_ENCODE_DISABLED) { 148 if (*crypt) 149 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt); 150 goto done; 151 } 152 153 if (*crypt != NULL && (*crypt)->ops != NULL && 154 strcmp((*crypt)->ops->name, "WEP") != 0) { 155 /* changing to use WEP; deinit previously used algorithm */ 156 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt); 157 } 158 159 if (*crypt == NULL) { 160 struct lib80211_crypt_data *new_crypt; 161 162 /* take WEP into use */ 163 new_crypt = kzalloc(sizeof(struct lib80211_crypt_data), 164 GFP_KERNEL); 165 if (new_crypt == NULL) 166 return -ENOMEM; 167 new_crypt->ops = lib80211_get_crypto_ops("WEP"); 168 if (!new_crypt->ops) { 169 request_module("lib80211_crypt_wep"); 170 new_crypt->ops = lib80211_get_crypto_ops("WEP"); 171 } 172 if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) 173 new_crypt->priv = new_crypt->ops->init(i); 174 if (!new_crypt->ops || !new_crypt->priv) { 175 kfree(new_crypt); 176 new_crypt = NULL; 177 178 printk(KERN_WARNING "%s: could not initialize WEP: " 179 "load module hostap_crypt_wep.o\n", 180 dev->name); 181 return -EOPNOTSUPP; 182 } 183 *crypt = new_crypt; 184 } 185 186 if (erq->length > 0) { 187 int len = erq->length <= 5 ? 5 : 13; 188 int first = 1, j; 189 if (len > erq->length) 190 memset(keybuf + erq->length, 0, len - erq->length); 191 (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv); 192 for (j = 0; j < WEP_KEYS; j++) { 193 if (j != i && local->crypt_info.crypt[j]) { 194 first = 0; 195 break; 196 } 197 } 198 if (first) 199 local->crypt_info.tx_keyidx = i; 200 } else { 201 /* No key data - just set the default TX key index */ 202 local->crypt_info.tx_keyidx = i; 203 } 204 205 done: 206 local->open_wep = erq->flags & IW_ENCODE_OPEN; 207 208 if (hostap_set_encryption(local)) { 209 printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name); 210 return -EINVAL; 211 } 212 213 /* Do not reset port0 if card is in Managed mode since resetting will 214 * generate new IEEE 802.11 authentication which may end up in looping 215 * with IEEE 802.1X. Prism2 documentation seem to require port reset 216 * after WEP configuration. However, keys are apparently changed at 217 * least in Managed mode. */ 218 if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) { 219 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name); 220 return -EINVAL; 221 } 222 223 return 0; 224 } 225 226 227 static int prism2_ioctl_giwencode(struct net_device *dev, 228 struct iw_request_info *info, 229 struct iw_point *erq, char *key) 230 { 231 struct hostap_interface *iface; 232 local_info_t *local; 233 int i, len; 234 u16 val; 235 struct lib80211_crypt_data *crypt; 236 237 iface = netdev_priv(dev); 238 local = iface->local; 239 240 i = erq->flags & IW_ENCODE_INDEX; 241 if (i < 1 || i > 4) 242 i = local->crypt_info.tx_keyidx; 243 else 244 i--; 245 if (i < 0 || i >= WEP_KEYS) 246 return -EINVAL; 247 248 crypt = local->crypt_info.crypt[i]; 249 erq->flags = i + 1; 250 251 if (crypt == NULL || crypt->ops == NULL) { 252 erq->length = 0; 253 erq->flags |= IW_ENCODE_DISABLED; 254 return 0; 255 } 256 257 if (strcmp(crypt->ops->name, "WEP") != 0) { 258 /* only WEP is supported with wireless extensions, so just 259 * report that encryption is used */ 260 erq->length = 0; 261 erq->flags |= IW_ENCODE_ENABLED; 262 return 0; 263 } 264 265 /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show 266 * the keys from driver buffer */ 267 len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv); 268 erq->length = (len >= 0 ? len : 0); 269 270 if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0) 271 { 272 printk("CNFWEPFLAGS reading failed\n"); 273 return -EOPNOTSUPP; 274 } 275 le16_to_cpus(&val); 276 if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED) 277 erq->flags |= IW_ENCODE_ENABLED; 278 else 279 erq->flags |= IW_ENCODE_DISABLED; 280 if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED) 281 erq->flags |= IW_ENCODE_RESTRICTED; 282 else 283 erq->flags |= IW_ENCODE_OPEN; 284 285 return 0; 286 } 287 288 289 static int hostap_set_rate(struct net_device *dev) 290 { 291 struct hostap_interface *iface; 292 local_info_t *local; 293 int ret, basic_rates; 294 295 iface = netdev_priv(dev); 296 local = iface->local; 297 298 basic_rates = local->basic_rates & local->tx_rate_control; 299 if (!basic_rates || basic_rates != local->basic_rates) { 300 printk(KERN_INFO "%s: updating basic rate set automatically " 301 "to match with the new supported rate set\n", 302 dev->name); 303 if (!basic_rates) 304 basic_rates = local->tx_rate_control; 305 306 local->basic_rates = basic_rates; 307 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES, 308 basic_rates)) 309 printk(KERN_WARNING "%s: failed to set " 310 "cnfBasicRates\n", dev->name); 311 } 312 313 ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL, 314 local->tx_rate_control) || 315 hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES, 316 local->tx_rate_control) || 317 local->func->reset_port(dev)); 318 319 if (ret) { 320 printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates " 321 "setting to 0x%x failed\n", 322 dev->name, local->tx_rate_control); 323 } 324 325 /* Update TX rate configuration for all STAs based on new operational 326 * rate set. */ 327 hostap_update_rates(local); 328 329 return ret; 330 } 331 332 333 static int prism2_ioctl_siwrate(struct net_device *dev, 334 struct iw_request_info *info, 335 struct iw_param *rrq, char *extra) 336 { 337 struct hostap_interface *iface; 338 local_info_t *local; 339 340 iface = netdev_priv(dev); 341 local = iface->local; 342 343 if (rrq->fixed) { 344 switch (rrq->value) { 345 case 11000000: 346 local->tx_rate_control = HFA384X_RATES_11MBPS; 347 break; 348 case 5500000: 349 local->tx_rate_control = HFA384X_RATES_5MBPS; 350 break; 351 case 2000000: 352 local->tx_rate_control = HFA384X_RATES_2MBPS; 353 break; 354 case 1000000: 355 local->tx_rate_control = HFA384X_RATES_1MBPS; 356 break; 357 default: 358 local->tx_rate_control = HFA384X_RATES_1MBPS | 359 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS | 360 HFA384X_RATES_11MBPS; 361 break; 362 } 363 } else { 364 switch (rrq->value) { 365 case 11000000: 366 local->tx_rate_control = HFA384X_RATES_1MBPS | 367 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS | 368 HFA384X_RATES_11MBPS; 369 break; 370 case 5500000: 371 local->tx_rate_control = HFA384X_RATES_1MBPS | 372 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS; 373 break; 374 case 2000000: 375 local->tx_rate_control = HFA384X_RATES_1MBPS | 376 HFA384X_RATES_2MBPS; 377 break; 378 case 1000000: 379 local->tx_rate_control = HFA384X_RATES_1MBPS; 380 break; 381 default: 382 local->tx_rate_control = HFA384X_RATES_1MBPS | 383 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS | 384 HFA384X_RATES_11MBPS; 385 break; 386 } 387 } 388 389 return hostap_set_rate(dev); 390 } 391 392 393 static int prism2_ioctl_giwrate(struct net_device *dev, 394 struct iw_request_info *info, 395 struct iw_param *rrq, char *extra) 396 { 397 u16 val; 398 struct hostap_interface *iface; 399 local_info_t *local; 400 int ret = 0; 401 402 iface = netdev_priv(dev); 403 local = iface->local; 404 405 if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) < 406 0) 407 return -EINVAL; 408 409 if ((val & 0x1) && (val > 1)) 410 rrq->fixed = 0; 411 else 412 rrq->fixed = 1; 413 414 if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL && 415 !local->fw_tx_rate_control) { 416 /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in 417 * Host AP mode, so use the recorded TX rate of the last sent 418 * frame */ 419 rrq->value = local->ap->last_tx_rate > 0 ? 420 local->ap->last_tx_rate * 100000 : 11000000; 421 return 0; 422 } 423 424 if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) < 425 0) 426 return -EINVAL; 427 428 switch (val) { 429 case HFA384X_RATES_1MBPS: 430 rrq->value = 1000000; 431 break; 432 case HFA384X_RATES_2MBPS: 433 rrq->value = 2000000; 434 break; 435 case HFA384X_RATES_5MBPS: 436 rrq->value = 5500000; 437 break; 438 case HFA384X_RATES_11MBPS: 439 rrq->value = 11000000; 440 break; 441 default: 442 /* should not happen */ 443 rrq->value = 11000000; 444 ret = -EINVAL; 445 break; 446 } 447 448 return ret; 449 } 450 451 452 static int prism2_ioctl_siwsens(struct net_device *dev, 453 struct iw_request_info *info, 454 struct iw_param *sens, char *extra) 455 { 456 struct hostap_interface *iface; 457 local_info_t *local; 458 459 iface = netdev_priv(dev); 460 local = iface->local; 461 462 /* Set the desired AP density */ 463 if (sens->value < 1 || sens->value > 3) 464 return -EINVAL; 465 466 if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) || 467 local->func->reset_port(dev)) 468 return -EINVAL; 469 470 return 0; 471 } 472 473 static int prism2_ioctl_giwsens(struct net_device *dev, 474 struct iw_request_info *info, 475 struct iw_param *sens, char *extra) 476 { 477 struct hostap_interface *iface; 478 local_info_t *local; 479 __le16 val; 480 481 iface = netdev_priv(dev); 482 local = iface->local; 483 484 /* Get the current AP density */ 485 if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) < 486 0) 487 return -EINVAL; 488 489 sens->value = le16_to_cpu(val); 490 sens->fixed = 1; 491 492 return 0; 493 } 494 495 496 /* Deprecated in new wireless extension API */ 497 static int prism2_ioctl_giwaplist(struct net_device *dev, 498 struct iw_request_info *info, 499 struct iw_point *data, char *extra) 500 { 501 struct hostap_interface *iface; 502 local_info_t *local; 503 struct sockaddr *addr; 504 struct iw_quality *qual; 505 506 iface = netdev_priv(dev); 507 local = iface->local; 508 509 if (local->iw_mode != IW_MODE_MASTER) { 510 printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported " 511 "in Host AP mode\n"); 512 data->length = 0; 513 return -EOPNOTSUPP; 514 } 515 516 addr = kmalloc_array(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL); 517 qual = kmalloc_array(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL); 518 if (addr == NULL || qual == NULL) { 519 kfree(addr); 520 kfree(qual); 521 data->length = 0; 522 return -ENOMEM; 523 } 524 525 data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1); 526 527 memcpy(extra, addr, sizeof(struct sockaddr) * data->length); 528 data->flags = 1; /* has quality information */ 529 memcpy(extra + sizeof(struct sockaddr) * data->length, qual, 530 sizeof(struct iw_quality) * data->length); 531 532 kfree(addr); 533 kfree(qual); 534 return 0; 535 } 536 537 538 static int prism2_ioctl_siwrts(struct net_device *dev, 539 struct iw_request_info *info, 540 struct iw_param *rts, char *extra) 541 { 542 struct hostap_interface *iface; 543 local_info_t *local; 544 __le16 val; 545 546 iface = netdev_priv(dev); 547 local = iface->local; 548 549 if (rts->disabled) 550 val = cpu_to_le16(2347); 551 else if (rts->value < 0 || rts->value > 2347) 552 return -EINVAL; 553 else 554 val = cpu_to_le16(rts->value); 555 556 if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) || 557 local->func->reset_port(dev)) 558 return -EINVAL; 559 560 local->rts_threshold = rts->value; 561 562 return 0; 563 } 564 565 static int prism2_ioctl_giwrts(struct net_device *dev, 566 struct iw_request_info *info, 567 struct iw_param *rts, char *extra) 568 { 569 struct hostap_interface *iface; 570 local_info_t *local; 571 __le16 val; 572 573 iface = netdev_priv(dev); 574 local = iface->local; 575 576 if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) < 577 0) 578 return -EINVAL; 579 580 rts->value = le16_to_cpu(val); 581 rts->disabled = (rts->value == 2347); 582 rts->fixed = 1; 583 584 return 0; 585 } 586 587 588 static int prism2_ioctl_siwfrag(struct net_device *dev, 589 struct iw_request_info *info, 590 struct iw_param *rts, char *extra) 591 { 592 struct hostap_interface *iface; 593 local_info_t *local; 594 __le16 val; 595 596 iface = netdev_priv(dev); 597 local = iface->local; 598 599 if (rts->disabled) 600 val = cpu_to_le16(2346); 601 else if (rts->value < 256 || rts->value > 2346) 602 return -EINVAL; 603 else 604 val = cpu_to_le16(rts->value & ~0x1); /* even numbers only */ 605 606 local->fragm_threshold = rts->value & ~0x1; 607 if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val, 608 2) 609 || local->func->reset_port(dev)) 610 return -EINVAL; 611 612 return 0; 613 } 614 615 static int prism2_ioctl_giwfrag(struct net_device *dev, 616 struct iw_request_info *info, 617 struct iw_param *rts, char *extra) 618 { 619 struct hostap_interface *iface; 620 local_info_t *local; 621 __le16 val; 622 623 iface = netdev_priv(dev); 624 local = iface->local; 625 626 if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, 627 &val, 2, 1) < 0) 628 return -EINVAL; 629 630 rts->value = le16_to_cpu(val); 631 rts->disabled = (rts->value == 2346); 632 rts->fixed = 1; 633 634 return 0; 635 } 636 637 638 #ifndef PRISM2_NO_STATION_MODES 639 static int hostap_join_ap(struct net_device *dev) 640 { 641 struct hostap_interface *iface; 642 local_info_t *local; 643 struct hfa384x_join_request req; 644 unsigned long flags; 645 int i; 646 struct hfa384x_hostscan_result *entry; 647 648 iface = netdev_priv(dev); 649 local = iface->local; 650 651 memcpy(req.bssid, local->preferred_ap, ETH_ALEN); 652 req.channel = 0; 653 654 spin_lock_irqsave(&local->lock, flags); 655 for (i = 0; i < local->last_scan_results_count; i++) { 656 if (!local->last_scan_results) 657 break; 658 entry = &local->last_scan_results[i]; 659 if (ether_addr_equal(local->preferred_ap, entry->bssid)) { 660 req.channel = entry->chid; 661 break; 662 } 663 } 664 spin_unlock_irqrestore(&local->lock, flags); 665 666 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req, 667 sizeof(req))) { 668 printk(KERN_DEBUG "%s: JoinRequest %pM failed\n", 669 dev->name, local->preferred_ap); 670 return -1; 671 } 672 673 printk(KERN_DEBUG "%s: Trying to join BSSID %pM\n", 674 dev->name, local->preferred_ap); 675 676 return 0; 677 } 678 #endif /* PRISM2_NO_STATION_MODES */ 679 680 681 static int prism2_ioctl_siwap(struct net_device *dev, 682 struct iw_request_info *info, 683 struct sockaddr *ap_addr, char *extra) 684 { 685 #ifdef PRISM2_NO_STATION_MODES 686 return -EOPNOTSUPP; 687 #else /* PRISM2_NO_STATION_MODES */ 688 struct hostap_interface *iface; 689 local_info_t *local; 690 691 iface = netdev_priv(dev); 692 local = iface->local; 693 694 memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN); 695 696 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) { 697 struct hfa384x_scan_request scan_req; 698 memset(&scan_req, 0, sizeof(scan_req)); 699 scan_req.channel_list = cpu_to_le16(0x3fff); 700 scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS); 701 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, 702 &scan_req, sizeof(scan_req))) { 703 printk(KERN_DEBUG "%s: ScanResults request failed - " 704 "preferred AP delayed to next unsolicited " 705 "scan\n", dev->name); 706 } 707 } else if (local->host_roaming == 2 && 708 local->iw_mode == IW_MODE_INFRA) { 709 if (hostap_join_ap(dev)) 710 return -EINVAL; 711 } else { 712 printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only " 713 "in Managed mode when host_roaming is enabled\n", 714 dev->name); 715 } 716 717 return 0; 718 #endif /* PRISM2_NO_STATION_MODES */ 719 } 720 721 static int prism2_ioctl_giwap(struct net_device *dev, 722 struct iw_request_info *info, 723 struct sockaddr *ap_addr, char *extra) 724 { 725 struct hostap_interface *iface; 726 local_info_t *local; 727 728 iface = netdev_priv(dev); 729 local = iface->local; 730 731 ap_addr->sa_family = ARPHRD_ETHER; 732 switch (iface->type) { 733 case HOSTAP_INTERFACE_AP: 734 memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN); 735 break; 736 case HOSTAP_INTERFACE_STA: 737 memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN); 738 break; 739 case HOSTAP_INTERFACE_WDS: 740 memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN); 741 break; 742 default: 743 if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID, 744 &ap_addr->sa_data, ETH_ALEN, 1) < 0) 745 return -EOPNOTSUPP; 746 747 /* local->bssid is also updated in LinkStatus handler when in 748 * station mode */ 749 memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN); 750 break; 751 } 752 753 return 0; 754 } 755 756 757 static int prism2_ioctl_siwnickn(struct net_device *dev, 758 struct iw_request_info *info, 759 struct iw_point *data, char *nickname) 760 { 761 struct hostap_interface *iface; 762 local_info_t *local; 763 764 iface = netdev_priv(dev); 765 local = iface->local; 766 767 memset(local->name, 0, sizeof(local->name)); 768 memcpy(local->name, nickname, data->length); 769 local->name_set = 1; 770 771 if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) || 772 local->func->reset_port(dev)) 773 return -EINVAL; 774 775 return 0; 776 } 777 778 static int prism2_ioctl_giwnickn(struct net_device *dev, 779 struct iw_request_info *info, 780 struct iw_point *data, char *nickname) 781 { 782 struct hostap_interface *iface; 783 local_info_t *local; 784 int len; 785 char name[MAX_NAME_LEN + 3]; 786 u16 val; 787 788 iface = netdev_priv(dev); 789 local = iface->local; 790 791 len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME, 792 &name, MAX_NAME_LEN + 2, 0); 793 val = le16_to_cpu(*(__le16 *) name); 794 if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN) 795 return -EOPNOTSUPP; 796 797 name[val + 2] = '\0'; 798 data->length = val + 1; 799 memcpy(nickname, name + 2, val + 1); 800 801 return 0; 802 } 803 804 805 static int prism2_ioctl_siwfreq(struct net_device *dev, 806 struct iw_request_info *info, 807 struct iw_freq *freq, char *extra) 808 { 809 struct hostap_interface *iface; 810 local_info_t *local; 811 812 iface = netdev_priv(dev); 813 local = iface->local; 814 815 /* freq => chan. */ 816 if (freq->e == 1 && 817 freq->m / 100000 >= freq_list[0] && 818 freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) { 819 int ch; 820 int fr = freq->m / 100000; 821 for (ch = 0; ch < FREQ_COUNT; ch++) { 822 if (fr == freq_list[ch]) { 823 freq->e = 0; 824 freq->m = ch + 1; 825 break; 826 } 827 } 828 } 829 830 if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT || 831 !(local->channel_mask & (1 << (freq->m - 1)))) 832 return -EINVAL; 833 834 local->channel = freq->m; /* channel is used in prism2_setup_rids() */ 835 if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) || 836 local->func->reset_port(dev)) 837 return -EINVAL; 838 839 return 0; 840 } 841 842 static int prism2_ioctl_giwfreq(struct net_device *dev, 843 struct iw_request_info *info, 844 struct iw_freq *freq, char *extra) 845 { 846 struct hostap_interface *iface; 847 local_info_t *local; 848 u16 val; 849 850 iface = netdev_priv(dev); 851 local = iface->local; 852 853 if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) < 854 0) 855 return -EINVAL; 856 857 le16_to_cpus(&val); 858 if (val < 1 || val > FREQ_COUNT) 859 return -EINVAL; 860 861 freq->m = freq_list[val - 1] * 100000; 862 freq->e = 1; 863 864 return 0; 865 } 866 867 868 static void hostap_monitor_set_type(local_info_t *local) 869 { 870 struct net_device *dev = local->ddev; 871 872 if (dev == NULL) 873 return; 874 875 if (local->monitor_type == PRISM2_MONITOR_PRISM || 876 local->monitor_type == PRISM2_MONITOR_CAPHDR) { 877 dev->type = ARPHRD_IEEE80211_PRISM; 878 } else if (local->monitor_type == PRISM2_MONITOR_RADIOTAP) { 879 dev->type = ARPHRD_IEEE80211_RADIOTAP; 880 } else { 881 dev->type = ARPHRD_IEEE80211; 882 } 883 } 884 885 886 static int prism2_ioctl_siwessid(struct net_device *dev, 887 struct iw_request_info *info, 888 struct iw_point *data, char *ssid) 889 { 890 struct hostap_interface *iface; 891 local_info_t *local; 892 893 iface = netdev_priv(dev); 894 local = iface->local; 895 896 if (iface->type == HOSTAP_INTERFACE_WDS) 897 return -EOPNOTSUPP; 898 899 if (data->flags == 0) 900 ssid[0] = '\0'; /* ANY */ 901 902 if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') { 903 /* Setting SSID to empty string seems to kill the card in 904 * Host AP mode */ 905 printk(KERN_DEBUG "%s: Host AP mode does not support " 906 "'Any' essid\n", dev->name); 907 return -EINVAL; 908 } 909 910 memcpy(local->essid, ssid, data->length); 911 local->essid[data->length] = '\0'; 912 913 if ((!local->fw_ap && 914 hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid)) 915 || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) || 916 local->func->reset_port(dev)) 917 return -EINVAL; 918 919 return 0; 920 } 921 922 static int prism2_ioctl_giwessid(struct net_device *dev, 923 struct iw_request_info *info, 924 struct iw_point *data, char *essid) 925 { 926 struct hostap_interface *iface; 927 local_info_t *local; 928 u16 val; 929 930 iface = netdev_priv(dev); 931 local = iface->local; 932 933 if (iface->type == HOSTAP_INTERFACE_WDS) 934 return -EOPNOTSUPP; 935 936 data->flags = 1; /* active */ 937 if (local->iw_mode == IW_MODE_MASTER) { 938 data->length = strlen(local->essid); 939 memcpy(essid, local->essid, IW_ESSID_MAX_SIZE); 940 } else { 941 int len; 942 char ssid[MAX_SSID_LEN + 2]; 943 memset(ssid, 0, sizeof(ssid)); 944 len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID, 945 &ssid, MAX_SSID_LEN + 2, 0); 946 val = le16_to_cpu(*(__le16 *) ssid); 947 if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) { 948 return -EOPNOTSUPP; 949 } 950 data->length = val; 951 memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE); 952 } 953 954 return 0; 955 } 956 957 958 static int prism2_ioctl_giwrange(struct net_device *dev, 959 struct iw_request_info *info, 960 struct iw_point *data, char *extra) 961 { 962 struct hostap_interface *iface; 963 local_info_t *local; 964 struct iw_range *range = (struct iw_range *) extra; 965 u8 rates[10]; 966 u16 val; 967 int i, len, over2; 968 969 iface = netdev_priv(dev); 970 local = iface->local; 971 972 data->length = sizeof(struct iw_range); 973 memset(range, 0, sizeof(struct iw_range)); 974 975 /* TODO: could fill num_txpower and txpower array with 976 * something; however, there are 128 different values.. */ 977 978 range->txpower_capa = IW_TXPOW_DBM; 979 980 if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC) 981 { 982 range->min_pmp = 1 * 1024; 983 range->max_pmp = 65535 * 1024; 984 range->min_pmt = 1 * 1024; 985 range->max_pmt = 1000 * 1024; 986 range->pmp_flags = IW_POWER_PERIOD; 987 range->pmt_flags = IW_POWER_TIMEOUT; 988 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | 989 IW_POWER_UNICAST_R | IW_POWER_ALL_R; 990 } 991 992 range->we_version_compiled = WIRELESS_EXT; 993 range->we_version_source = 18; 994 995 range->retry_capa = IW_RETRY_LIMIT; 996 range->retry_flags = IW_RETRY_LIMIT; 997 range->min_retry = 0; 998 range->max_retry = 255; 999 1000 range->num_channels = FREQ_COUNT; 1001 1002 val = 0; 1003 for (i = 0; i < FREQ_COUNT; i++) { 1004 if (local->channel_mask & (1 << i)) { 1005 range->freq[val].i = i + 1; 1006 range->freq[val].m = freq_list[i] * 100000; 1007 range->freq[val].e = 1; 1008 val++; 1009 } 1010 if (val == IW_MAX_FREQUENCIES) 1011 break; 1012 } 1013 range->num_frequency = val; 1014 1015 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) { 1016 range->max_qual.qual = 70; /* what is correct max? This was not 1017 * documented exactly. At least 1018 * 69 has been observed. */ 1019 range->max_qual.level = 0; /* dB */ 1020 range->max_qual.noise = 0; /* dB */ 1021 1022 /* What would be suitable values for "average/typical" qual? */ 1023 range->avg_qual.qual = 20; 1024 range->avg_qual.level = -60; 1025 range->avg_qual.noise = -95; 1026 } else { 1027 range->max_qual.qual = 92; /* 0 .. 92 */ 1028 range->max_qual.level = 154; /* 27 .. 154 */ 1029 range->max_qual.noise = 154; /* 27 .. 154 */ 1030 } 1031 range->sensitivity = 3; 1032 1033 range->max_encoding_tokens = WEP_KEYS; 1034 range->num_encoding_sizes = 2; 1035 range->encoding_size[0] = 5; 1036 range->encoding_size[1] = 13; 1037 1038 over2 = 0; 1039 len = prism2_get_datarates(dev, rates); 1040 range->num_bitrates = 0; 1041 for (i = 0; i < len; i++) { 1042 if (range->num_bitrates < IW_MAX_BITRATES) { 1043 range->bitrate[range->num_bitrates] = 1044 rates[i] * 500000; 1045 range->num_bitrates++; 1046 } 1047 if (rates[i] == 0x0b || rates[i] == 0x16) 1048 over2 = 1; 1049 } 1050 /* estimated maximum TCP throughput values (bps) */ 1051 range->throughput = over2 ? 5500000 : 1500000; 1052 1053 range->min_rts = 0; 1054 range->max_rts = 2347; 1055 range->min_frag = 256; 1056 range->max_frag = 2346; 1057 1058 /* Event capability (kernel + driver) */ 1059 range->event_capa[0] = (IW_EVENT_CAPA_K_0 | 1060 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | 1061 IW_EVENT_CAPA_MASK(SIOCGIWAP) | 1062 IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); 1063 range->event_capa[1] = IW_EVENT_CAPA_K_1; 1064 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) | 1065 IW_EVENT_CAPA_MASK(IWEVCUSTOM) | 1066 IW_EVENT_CAPA_MASK(IWEVREGISTERED) | 1067 IW_EVENT_CAPA_MASK(IWEVEXPIRED)); 1068 1069 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | 1070 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; 1071 1072 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) 1073 range->scan_capa = IW_SCAN_CAPA_ESSID; 1074 1075 return 0; 1076 } 1077 1078 1079 static int hostap_monitor_mode_enable(local_info_t *local) 1080 { 1081 struct net_device *dev = local->dev; 1082 1083 printk(KERN_DEBUG "Enabling monitor mode\n"); 1084 hostap_monitor_set_type(local); 1085 1086 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, 1087 HFA384X_PORTTYPE_PSEUDO_IBSS)) { 1088 printk(KERN_DEBUG "Port type setting for monitor mode " 1089 "failed\n"); 1090 return -EOPNOTSUPP; 1091 } 1092 1093 /* Host decrypt is needed to get the IV and ICV fields; 1094 * however, monitor mode seems to remove WEP flag from frame 1095 * control field */ 1096 if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS, 1097 HFA384X_WEPFLAGS_HOSTENCRYPT | 1098 HFA384X_WEPFLAGS_HOSTDECRYPT)) { 1099 printk(KERN_DEBUG "WEP flags setting failed\n"); 1100 return -EOPNOTSUPP; 1101 } 1102 1103 if (local->func->reset_port(dev) || 1104 local->func->cmd(dev, HFA384X_CMDCODE_TEST | 1105 (HFA384X_TEST_MONITOR << 8), 1106 0, NULL, NULL)) { 1107 printk(KERN_DEBUG "Setting monitor mode failed\n"); 1108 return -EOPNOTSUPP; 1109 } 1110 1111 return 0; 1112 } 1113 1114 1115 static int hostap_monitor_mode_disable(local_info_t *local) 1116 { 1117 struct net_device *dev = local->ddev; 1118 1119 if (dev == NULL) 1120 return -1; 1121 1122 printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name); 1123 dev->type = ARPHRD_ETHER; 1124 1125 if (local->func->cmd(dev, HFA384X_CMDCODE_TEST | 1126 (HFA384X_TEST_STOP << 8), 1127 0, NULL, NULL)) 1128 return -1; 1129 return hostap_set_encryption(local); 1130 } 1131 1132 1133 static int prism2_ioctl_siwmode(struct net_device *dev, 1134 struct iw_request_info *info, 1135 __u32 *mode, char *extra) 1136 { 1137 struct hostap_interface *iface; 1138 local_info_t *local; 1139 int double_reset = 0; 1140 1141 iface = netdev_priv(dev); 1142 local = iface->local; 1143 1144 if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA && 1145 *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT && 1146 *mode != IW_MODE_MONITOR) 1147 return -EOPNOTSUPP; 1148 1149 #ifdef PRISM2_NO_STATION_MODES 1150 if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA) 1151 return -EOPNOTSUPP; 1152 #endif /* PRISM2_NO_STATION_MODES */ 1153 1154 if (*mode == local->iw_mode) 1155 return 0; 1156 1157 if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') { 1158 printk(KERN_WARNING "%s: empty SSID not allowed in Master " 1159 "mode\n", dev->name); 1160 return -EINVAL; 1161 } 1162 1163 if (local->iw_mode == IW_MODE_MONITOR) 1164 hostap_monitor_mode_disable(local); 1165 1166 if ((local->iw_mode == IW_MODE_ADHOC || 1167 local->iw_mode == IW_MODE_MONITOR) && *mode == IW_MODE_MASTER) { 1168 /* There seems to be a firmware bug in at least STA f/w v1.5.6 1169 * that leaves beacon frames to use IBSS type when moving from 1170 * IBSS to Host AP mode. Doing double Port0 reset seems to be 1171 * enough to workaround this. */ 1172 double_reset = 1; 1173 } 1174 1175 printk(KERN_DEBUG "prism2: %s: operating mode changed " 1176 "%d -> %d\n", dev->name, local->iw_mode, *mode); 1177 local->iw_mode = *mode; 1178 1179 if (local->iw_mode == IW_MODE_MONITOR) 1180 hostap_monitor_mode_enable(local); 1181 else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt && 1182 !local->fw_encrypt_ok) { 1183 printk(KERN_DEBUG "%s: defaulting to host-based encryption as " 1184 "a workaround for firmware bug in Host AP mode WEP\n", 1185 dev->name); 1186 local->host_encrypt = 1; 1187 } 1188 1189 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, 1190 hostap_get_porttype(local))) 1191 return -EOPNOTSUPP; 1192 1193 if (local->func->reset_port(dev)) 1194 return -EINVAL; 1195 if (double_reset && local->func->reset_port(dev)) 1196 return -EINVAL; 1197 1198 if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC) 1199 { 1200 /* netif_carrier is used only in client modes for now, so make 1201 * sure carrier is on when moving to non-client modes. */ 1202 netif_carrier_on(local->dev); 1203 netif_carrier_on(local->ddev); 1204 } 1205 return 0; 1206 } 1207 1208 1209 static int prism2_ioctl_giwmode(struct net_device *dev, 1210 struct iw_request_info *info, 1211 __u32 *mode, char *extra) 1212 { 1213 struct hostap_interface *iface; 1214 local_info_t *local; 1215 1216 iface = netdev_priv(dev); 1217 local = iface->local; 1218 1219 switch (iface->type) { 1220 case HOSTAP_INTERFACE_STA: 1221 *mode = IW_MODE_INFRA; 1222 break; 1223 case HOSTAP_INTERFACE_WDS: 1224 *mode = IW_MODE_REPEAT; 1225 break; 1226 default: 1227 *mode = local->iw_mode; 1228 break; 1229 } 1230 return 0; 1231 } 1232 1233 1234 static int prism2_ioctl_siwpower(struct net_device *dev, 1235 struct iw_request_info *info, 1236 struct iw_param *wrq, char *extra) 1237 { 1238 #ifdef PRISM2_NO_STATION_MODES 1239 return -EOPNOTSUPP; 1240 #else /* PRISM2_NO_STATION_MODES */ 1241 int ret = 0; 1242 1243 if (wrq->disabled) 1244 return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0); 1245 1246 switch (wrq->flags & IW_POWER_MODE) { 1247 case IW_POWER_UNICAST_R: 1248 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0); 1249 if (ret) 1250 return ret; 1251 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1); 1252 if (ret) 1253 return ret; 1254 break; 1255 case IW_POWER_ALL_R: 1256 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1); 1257 if (ret) 1258 return ret; 1259 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1); 1260 if (ret) 1261 return ret; 1262 break; 1263 case IW_POWER_ON: 1264 break; 1265 default: 1266 return -EINVAL; 1267 } 1268 1269 if (wrq->flags & IW_POWER_TIMEOUT) { 1270 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1); 1271 if (ret) 1272 return ret; 1273 ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION, 1274 wrq->value / 1024); 1275 if (ret) 1276 return ret; 1277 } 1278 if (wrq->flags & IW_POWER_PERIOD) { 1279 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1); 1280 if (ret) 1281 return ret; 1282 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION, 1283 wrq->value / 1024); 1284 if (ret) 1285 return ret; 1286 } 1287 1288 return ret; 1289 #endif /* PRISM2_NO_STATION_MODES */ 1290 } 1291 1292 1293 static int prism2_ioctl_giwpower(struct net_device *dev, 1294 struct iw_request_info *info, 1295 struct iw_param *rrq, char *extra) 1296 { 1297 #ifdef PRISM2_NO_STATION_MODES 1298 return -EOPNOTSUPP; 1299 #else /* PRISM2_NO_STATION_MODES */ 1300 struct hostap_interface *iface; 1301 local_info_t *local; 1302 __le16 enable, mcast; 1303 1304 iface = netdev_priv(dev); 1305 local = iface->local; 1306 1307 if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1) 1308 < 0) 1309 return -EINVAL; 1310 1311 if (!le16_to_cpu(enable)) { 1312 rrq->disabled = 1; 1313 return 0; 1314 } 1315 1316 rrq->disabled = 0; 1317 1318 if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { 1319 __le16 timeout; 1320 if (local->func->get_rid(dev, 1321 HFA384X_RID_CNFPMHOLDOVERDURATION, 1322 &timeout, 2, 1) < 0) 1323 return -EINVAL; 1324 1325 rrq->flags = IW_POWER_TIMEOUT; 1326 rrq->value = le16_to_cpu(timeout) * 1024; 1327 } else { 1328 __le16 period; 1329 if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION, 1330 &period, 2, 1) < 0) 1331 return -EINVAL; 1332 1333 rrq->flags = IW_POWER_PERIOD; 1334 rrq->value = le16_to_cpu(period) * 1024; 1335 } 1336 1337 if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast, 1338 2, 1) < 0) 1339 return -EINVAL; 1340 1341 if (le16_to_cpu(mcast)) 1342 rrq->flags |= IW_POWER_ALL_R; 1343 else 1344 rrq->flags |= IW_POWER_UNICAST_R; 1345 1346 return 0; 1347 #endif /* PRISM2_NO_STATION_MODES */ 1348 } 1349 1350 1351 static int prism2_ioctl_siwretry(struct net_device *dev, 1352 struct iw_request_info *info, 1353 struct iw_param *rrq, char *extra) 1354 { 1355 struct hostap_interface *iface; 1356 local_info_t *local; 1357 1358 iface = netdev_priv(dev); 1359 local = iface->local; 1360 1361 if (rrq->disabled) 1362 return -EINVAL; 1363 1364 /* setting retry limits is not supported with the current station 1365 * firmware code; simulate this with alternative retry count for now */ 1366 if (rrq->flags == IW_RETRY_LIMIT) { 1367 if (rrq->value < 0) { 1368 /* disable manual retry count setting and use firmware 1369 * defaults */ 1370 local->manual_retry_count = -1; 1371 local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY; 1372 } else { 1373 if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT, 1374 rrq->value)) { 1375 printk(KERN_DEBUG "%s: Alternate retry count " 1376 "setting to %d failed\n", 1377 dev->name, rrq->value); 1378 return -EOPNOTSUPP; 1379 } 1380 1381 local->manual_retry_count = rrq->value; 1382 local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY; 1383 } 1384 return 0; 1385 } 1386 1387 return -EOPNOTSUPP; 1388 1389 #if 0 1390 /* what could be done, if firmware would support this.. */ 1391 1392 if (rrq->flags & IW_RETRY_LIMIT) { 1393 if (rrq->flags & IW_RETRY_LONG) 1394 HFA384X_RID_LONGRETRYLIMIT = rrq->value; 1395 else if (rrq->flags & IW_RETRY_SHORT) 1396 HFA384X_RID_SHORTRETRYLIMIT = rrq->value; 1397 else { 1398 HFA384X_RID_LONGRETRYLIMIT = rrq->value; 1399 HFA384X_RID_SHORTRETRYLIMIT = rrq->value; 1400 } 1401 1402 } 1403 1404 if (rrq->flags & IW_RETRY_LIFETIME) { 1405 HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024; 1406 } 1407 1408 return 0; 1409 #endif /* 0 */ 1410 } 1411 1412 static int prism2_ioctl_giwretry(struct net_device *dev, 1413 struct iw_request_info *info, 1414 struct iw_param *rrq, char *extra) 1415 { 1416 struct hostap_interface *iface; 1417 local_info_t *local; 1418 __le16 shortretry, longretry, lifetime, altretry; 1419 1420 iface = netdev_priv(dev); 1421 local = iface->local; 1422 1423 if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry, 1424 2, 1) < 0 || 1425 local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry, 1426 2, 1) < 0 || 1427 local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME, 1428 &lifetime, 2, 1) < 0) 1429 return -EINVAL; 1430 1431 rrq->disabled = 0; 1432 1433 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { 1434 rrq->flags = IW_RETRY_LIFETIME; 1435 rrq->value = le16_to_cpu(lifetime) * 1024; 1436 } else { 1437 if (local->manual_retry_count >= 0) { 1438 rrq->flags = IW_RETRY_LIMIT; 1439 if (local->func->get_rid(dev, 1440 HFA384X_RID_CNFALTRETRYCOUNT, 1441 &altretry, 2, 1) >= 0) 1442 rrq->value = le16_to_cpu(altretry); 1443 else 1444 rrq->value = local->manual_retry_count; 1445 } else if ((rrq->flags & IW_RETRY_LONG)) { 1446 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; 1447 rrq->value = le16_to_cpu(longretry); 1448 } else { 1449 rrq->flags = IW_RETRY_LIMIT; 1450 rrq->value = le16_to_cpu(shortretry); 1451 if (shortretry != longretry) 1452 rrq->flags |= IW_RETRY_SHORT; 1453 } 1454 } 1455 return 0; 1456 } 1457 1458 1459 /* Note! This TX power controlling is experimental and should not be used in 1460 * production use. It just sets raw power register and does not use any kind of 1461 * feedback information from the measured TX power (CR58). This is now 1462 * commented out to make sure that it is not used by accident. TX power 1463 * configuration will be enabled again after proper algorithm using feedback 1464 * has been implemented. */ 1465 1466 #ifdef RAW_TXPOWER_SETTING 1467 /* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping.. 1468 * This version assumes following mapping: 1469 * CR31 is 7-bit value with -64 to +63 range. 1470 * -64 is mapped into +20dBm and +63 into -43dBm. 1471 * This is certainly not an exact mapping for every card, but at least 1472 * increasing dBm value should correspond to increasing TX power. 1473 */ 1474 1475 static int prism2_txpower_hfa386x_to_dBm(u16 val) 1476 { 1477 signed char tmp; 1478 1479 if (val > 255) 1480 val = 255; 1481 1482 tmp = val; 1483 tmp >>= 2; 1484 1485 return -12 - tmp; 1486 } 1487 1488 static u16 prism2_txpower_dBm_to_hfa386x(int val) 1489 { 1490 signed char tmp; 1491 1492 if (val > 20) 1493 return 128; 1494 else if (val < -43) 1495 return 127; 1496 1497 tmp = val; 1498 tmp = -12 - tmp; 1499 tmp <<= 2; 1500 1501 return (unsigned char) tmp; 1502 } 1503 #endif /* RAW_TXPOWER_SETTING */ 1504 1505 1506 static int prism2_ioctl_siwtxpow(struct net_device *dev, 1507 struct iw_request_info *info, 1508 struct iw_param *rrq, char *extra) 1509 { 1510 struct hostap_interface *iface; 1511 local_info_t *local; 1512 #ifdef RAW_TXPOWER_SETTING 1513 char *tmp; 1514 #endif 1515 u16 val; 1516 int ret = 0; 1517 1518 iface = netdev_priv(dev); 1519 local = iface->local; 1520 1521 if (rrq->disabled) { 1522 if (local->txpower_type != PRISM2_TXPOWER_OFF) { 1523 val = 0xff; /* use all standby and sleep modes */ 1524 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, 1525 HFA386X_CR_A_D_TEST_MODES2, 1526 &val, NULL); 1527 printk(KERN_DEBUG "%s: Turning radio off: %s\n", 1528 dev->name, ret ? "failed" : "OK"); 1529 local->txpower_type = PRISM2_TXPOWER_OFF; 1530 } 1531 return (ret ? -EOPNOTSUPP : 0); 1532 } 1533 1534 if (local->txpower_type == PRISM2_TXPOWER_OFF) { 1535 val = 0; /* disable all standby and sleep modes */ 1536 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, 1537 HFA386X_CR_A_D_TEST_MODES2, &val, NULL); 1538 printk(KERN_DEBUG "%s: Turning radio on: %s\n", 1539 dev->name, ret ? "failed" : "OK"); 1540 local->txpower_type = PRISM2_TXPOWER_UNKNOWN; 1541 } 1542 1543 #ifdef RAW_TXPOWER_SETTING 1544 if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) { 1545 printk(KERN_DEBUG "Setting ALC on\n"); 1546 val = HFA384X_TEST_CFG_BIT_ALC; 1547 local->func->cmd(dev, HFA384X_CMDCODE_TEST | 1548 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL); 1549 local->txpower_type = PRISM2_TXPOWER_AUTO; 1550 return 0; 1551 } 1552 1553 if (local->txpower_type != PRISM2_TXPOWER_FIXED) { 1554 printk(KERN_DEBUG "Setting ALC off\n"); 1555 val = HFA384X_TEST_CFG_BIT_ALC; 1556 local->func->cmd(dev, HFA384X_CMDCODE_TEST | 1557 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL); 1558 local->txpower_type = PRISM2_TXPOWER_FIXED; 1559 } 1560 1561 if (rrq->flags == IW_TXPOW_DBM) 1562 tmp = "dBm"; 1563 else if (rrq->flags == IW_TXPOW_MWATT) 1564 tmp = "mW"; 1565 else 1566 tmp = "UNKNOWN"; 1567 printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp); 1568 1569 if (rrq->flags != IW_TXPOW_DBM) { 1570 printk("SIOCSIWTXPOW with mW is not supported; use dBm\n"); 1571 return -EOPNOTSUPP; 1572 } 1573 1574 local->txpower = rrq->value; 1575 val = prism2_txpower_dBm_to_hfa386x(local->txpower); 1576 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, 1577 HFA386X_CR_MANUAL_TX_POWER, &val, NULL)) 1578 ret = -EOPNOTSUPP; 1579 #else /* RAW_TXPOWER_SETTING */ 1580 if (rrq->fixed) 1581 ret = -EOPNOTSUPP; 1582 #endif /* RAW_TXPOWER_SETTING */ 1583 1584 return ret; 1585 } 1586 1587 static int prism2_ioctl_giwtxpow(struct net_device *dev, 1588 struct iw_request_info *info, 1589 struct iw_param *rrq, char *extra) 1590 { 1591 #ifdef RAW_TXPOWER_SETTING 1592 struct hostap_interface *iface; 1593 local_info_t *local; 1594 u16 resp0; 1595 1596 iface = netdev_priv(dev); 1597 local = iface->local; 1598 1599 rrq->flags = IW_TXPOW_DBM; 1600 rrq->disabled = 0; 1601 rrq->fixed = 0; 1602 1603 if (local->txpower_type == PRISM2_TXPOWER_AUTO) { 1604 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, 1605 HFA386X_CR_MANUAL_TX_POWER, 1606 NULL, &resp0) == 0) { 1607 rrq->value = prism2_txpower_hfa386x_to_dBm(resp0); 1608 } else { 1609 /* Could not get real txpower; guess 15 dBm */ 1610 rrq->value = 15; 1611 } 1612 } else if (local->txpower_type == PRISM2_TXPOWER_OFF) { 1613 rrq->value = 0; 1614 rrq->disabled = 1; 1615 } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) { 1616 rrq->value = local->txpower; 1617 rrq->fixed = 1; 1618 } else { 1619 printk("SIOCGIWTXPOW - unknown txpower_type=%d\n", 1620 local->txpower_type); 1621 } 1622 return 0; 1623 #else /* RAW_TXPOWER_SETTING */ 1624 return -EOPNOTSUPP; 1625 #endif /* RAW_TXPOWER_SETTING */ 1626 } 1627 1628 1629 #ifndef PRISM2_NO_STATION_MODES 1630 1631 /* HostScan request works with and without host_roaming mode. In addition, it 1632 * does not break current association. However, it requires newer station 1633 * firmware version (>= 1.3.1) than scan request. */ 1634 static int prism2_request_hostscan(struct net_device *dev, 1635 u8 *ssid, u8 ssid_len) 1636 { 1637 struct hostap_interface *iface; 1638 local_info_t *local; 1639 struct hfa384x_hostscan_request scan_req; 1640 1641 iface = netdev_priv(dev); 1642 local = iface->local; 1643 1644 memset(&scan_req, 0, sizeof(scan_req)); 1645 scan_req.channel_list = cpu_to_le16(local->channel_mask & 1646 local->scan_channel_mask); 1647 scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS); 1648 if (ssid) { 1649 if (ssid_len > 32) 1650 return -EINVAL; 1651 scan_req.target_ssid_len = cpu_to_le16(ssid_len); 1652 memcpy(scan_req.target_ssid, ssid, ssid_len); 1653 } 1654 1655 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req, 1656 sizeof(scan_req))) { 1657 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name); 1658 return -EINVAL; 1659 } 1660 return 0; 1661 } 1662 1663 1664 static int prism2_request_scan(struct net_device *dev) 1665 { 1666 struct hostap_interface *iface; 1667 local_info_t *local; 1668 struct hfa384x_scan_request scan_req; 1669 int ret = 0; 1670 1671 iface = netdev_priv(dev); 1672 local = iface->local; 1673 1674 memset(&scan_req, 0, sizeof(scan_req)); 1675 scan_req.channel_list = cpu_to_le16(local->channel_mask & 1676 local->scan_channel_mask); 1677 scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS); 1678 1679 /* FIX: 1680 * It seems to be enough to set roaming mode for a short moment to 1681 * host-based and then setup scanrequest data and return the mode to 1682 * firmware-based. 1683 * 1684 * Master mode would need to drop to Managed mode for a short while 1685 * to make scanning work.. Or sweep through the different channels and 1686 * use passive scan based on beacons. */ 1687 1688 if (!local->host_roaming) 1689 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE, 1690 HFA384X_ROAMING_HOST); 1691 1692 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req, 1693 sizeof(scan_req))) { 1694 printk(KERN_DEBUG "SCANREQUEST failed\n"); 1695 ret = -EINVAL; 1696 } 1697 1698 if (!local->host_roaming) 1699 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE, 1700 HFA384X_ROAMING_FIRMWARE); 1701 1702 return ret; 1703 } 1704 1705 #else /* !PRISM2_NO_STATION_MODES */ 1706 1707 static inline int prism2_request_hostscan(struct net_device *dev, 1708 u8 *ssid, u8 ssid_len) 1709 { 1710 return -EOPNOTSUPP; 1711 } 1712 1713 1714 static inline int prism2_request_scan(struct net_device *dev) 1715 { 1716 return -EOPNOTSUPP; 1717 } 1718 1719 #endif /* !PRISM2_NO_STATION_MODES */ 1720 1721 1722 static int prism2_ioctl_siwscan(struct net_device *dev, 1723 struct iw_request_info *info, 1724 struct iw_point *data, char *extra) 1725 { 1726 struct hostap_interface *iface; 1727 local_info_t *local; 1728 int ret; 1729 u8 *ssid = NULL, ssid_len = 0; 1730 struct iw_scan_req *req = (struct iw_scan_req *) extra; 1731 1732 iface = netdev_priv(dev); 1733 local = iface->local; 1734 1735 if (data->length < sizeof(struct iw_scan_req)) 1736 req = NULL; 1737 1738 if (local->iw_mode == IW_MODE_MASTER) { 1739 /* In master mode, we just return the results of our local 1740 * tables, so we don't need to start anything... 1741 * Jean II */ 1742 data->length = 0; 1743 return 0; 1744 } 1745 1746 if (!local->dev_enabled) 1747 return -ENETDOWN; 1748 1749 if (req && data->flags & IW_SCAN_THIS_ESSID) { 1750 ssid = req->essid; 1751 ssid_len = req->essid_len; 1752 1753 if (ssid_len && 1754 ((local->iw_mode != IW_MODE_INFRA && 1755 local->iw_mode != IW_MODE_ADHOC) || 1756 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))) 1757 return -EOPNOTSUPP; 1758 } 1759 1760 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) 1761 ret = prism2_request_hostscan(dev, ssid, ssid_len); 1762 else 1763 ret = prism2_request_scan(dev); 1764 1765 if (ret == 0) 1766 local->scan_timestamp = jiffies; 1767 1768 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */ 1769 1770 return ret; 1771 } 1772 1773 1774 #ifndef PRISM2_NO_STATION_MODES 1775 static char * __prism2_translate_scan(local_info_t *local, 1776 struct iw_request_info *info, 1777 struct hfa384x_hostscan_result *scan, 1778 struct hostap_bss_info *bss, 1779 char *current_ev, char *end_buf) 1780 { 1781 int i, chan; 1782 struct iw_event iwe; 1783 char *current_val; 1784 u16 capabilities; 1785 u8 *pos; 1786 u8 *ssid, *bssid; 1787 size_t ssid_len; 1788 char *buf; 1789 1790 if (bss) { 1791 ssid = bss->ssid; 1792 ssid_len = bss->ssid_len; 1793 bssid = bss->bssid; 1794 } else { 1795 ssid = scan->ssid; 1796 ssid_len = le16_to_cpu(scan->ssid_len); 1797 bssid = scan->bssid; 1798 } 1799 if (ssid_len > 32) 1800 ssid_len = 32; 1801 1802 /* First entry *MUST* be the AP MAC address */ 1803 memset(&iwe, 0, sizeof(iwe)); 1804 iwe.cmd = SIOCGIWAP; 1805 iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 1806 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN); 1807 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, 1808 IW_EV_ADDR_LEN); 1809 1810 /* Other entries will be displayed in the order we give them */ 1811 1812 memset(&iwe, 0, sizeof(iwe)); 1813 iwe.cmd = SIOCGIWESSID; 1814 iwe.u.data.length = ssid_len; 1815 iwe.u.data.flags = 1; 1816 current_ev = iwe_stream_add_point(info, current_ev, end_buf, 1817 &iwe, ssid); 1818 1819 memset(&iwe, 0, sizeof(iwe)); 1820 iwe.cmd = SIOCGIWMODE; 1821 if (bss) { 1822 capabilities = bss->capab_info; 1823 } else { 1824 capabilities = le16_to_cpu(scan->capability); 1825 } 1826 if (capabilities & (WLAN_CAPABILITY_ESS | 1827 WLAN_CAPABILITY_IBSS)) { 1828 if (capabilities & WLAN_CAPABILITY_ESS) 1829 iwe.u.mode = IW_MODE_MASTER; 1830 else 1831 iwe.u.mode = IW_MODE_ADHOC; 1832 current_ev = iwe_stream_add_event(info, current_ev, end_buf, 1833 &iwe, IW_EV_UINT_LEN); 1834 } 1835 1836 memset(&iwe, 0, sizeof(iwe)); 1837 iwe.cmd = SIOCGIWFREQ; 1838 if (scan) { 1839 chan = le16_to_cpu(scan->chid); 1840 } else if (bss) { 1841 chan = bss->chan; 1842 } else { 1843 chan = 0; 1844 } 1845 1846 if (chan > 0) { 1847 iwe.u.freq.m = freq_list[chan - 1] * 100000; 1848 iwe.u.freq.e = 1; 1849 current_ev = iwe_stream_add_event(info, current_ev, end_buf, 1850 &iwe, IW_EV_FREQ_LEN); 1851 } 1852 1853 if (scan) { 1854 memset(&iwe, 0, sizeof(iwe)); 1855 iwe.cmd = IWEVQUAL; 1856 if (local->last_scan_type == PRISM2_HOSTSCAN) { 1857 iwe.u.qual.level = le16_to_cpu(scan->sl); 1858 iwe.u.qual.noise = le16_to_cpu(scan->anl); 1859 } else { 1860 iwe.u.qual.level = 1861 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl)); 1862 iwe.u.qual.noise = 1863 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl)); 1864 } 1865 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED 1866 | IW_QUAL_NOISE_UPDATED 1867 | IW_QUAL_QUAL_INVALID 1868 | IW_QUAL_DBM; 1869 current_ev = iwe_stream_add_event(info, current_ev, end_buf, 1870 &iwe, IW_EV_QUAL_LEN); 1871 } 1872 1873 memset(&iwe, 0, sizeof(iwe)); 1874 iwe.cmd = SIOCGIWENCODE; 1875 if (capabilities & WLAN_CAPABILITY_PRIVACY) 1876 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; 1877 else 1878 iwe.u.data.flags = IW_ENCODE_DISABLED; 1879 iwe.u.data.length = 0; 1880 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, ""); 1881 1882 /* TODO: add SuppRates into BSS table */ 1883 if (scan) { 1884 memset(&iwe, 0, sizeof(iwe)); 1885 iwe.cmd = SIOCGIWRATE; 1886 current_val = current_ev + iwe_stream_lcp_len(info); 1887 pos = scan->sup_rates; 1888 for (i = 0; i < sizeof(scan->sup_rates); i++) { 1889 if (pos[i] == 0) 1890 break; 1891 /* Bit rate given in 500 kb/s units (+ 0x80) */ 1892 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000); 1893 current_val = iwe_stream_add_value( 1894 info, current_ev, current_val, end_buf, &iwe, 1895 IW_EV_PARAM_LEN); 1896 } 1897 /* Check if we added any event */ 1898 if ((current_val - current_ev) > iwe_stream_lcp_len(info)) 1899 current_ev = current_val; 1900 } 1901 1902 /* TODO: add BeaconInt,resp_rate,atim into BSS table */ 1903 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_ATOMIC); 1904 if (buf && scan) { 1905 memset(&iwe, 0, sizeof(iwe)); 1906 iwe.cmd = IWEVCUSTOM; 1907 sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval)); 1908 iwe.u.data.length = strlen(buf); 1909 current_ev = iwe_stream_add_point(info, current_ev, end_buf, 1910 &iwe, buf); 1911 1912 memset(&iwe, 0, sizeof(iwe)); 1913 iwe.cmd = IWEVCUSTOM; 1914 sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate)); 1915 iwe.u.data.length = strlen(buf); 1916 current_ev = iwe_stream_add_point(info, current_ev, end_buf, 1917 &iwe, buf); 1918 1919 if (local->last_scan_type == PRISM2_HOSTSCAN && 1920 (capabilities & WLAN_CAPABILITY_IBSS)) { 1921 memset(&iwe, 0, sizeof(iwe)); 1922 iwe.cmd = IWEVCUSTOM; 1923 sprintf(buf, "atim=%d", le16_to_cpu(scan->atim)); 1924 iwe.u.data.length = strlen(buf); 1925 current_ev = iwe_stream_add_point(info, current_ev, 1926 end_buf, &iwe, buf); 1927 } 1928 } 1929 kfree(buf); 1930 1931 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) { 1932 memset(&iwe, 0, sizeof(iwe)); 1933 iwe.cmd = IWEVGENIE; 1934 iwe.u.data.length = bss->wpa_ie_len; 1935 current_ev = iwe_stream_add_point(info, current_ev, end_buf, 1936 &iwe, bss->wpa_ie); 1937 } 1938 1939 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) { 1940 memset(&iwe, 0, sizeof(iwe)); 1941 iwe.cmd = IWEVGENIE; 1942 iwe.u.data.length = bss->rsn_ie_len; 1943 current_ev = iwe_stream_add_point(info, current_ev, end_buf, 1944 &iwe, bss->rsn_ie); 1945 } 1946 1947 return current_ev; 1948 } 1949 1950 1951 /* Translate scan data returned from the card to a card independent 1952 * format that the Wireless Tools will understand - Jean II */ 1953 static inline int prism2_translate_scan(local_info_t *local, 1954 struct iw_request_info *info, 1955 char *buffer, int buflen) 1956 { 1957 struct hfa384x_hostscan_result *scan; 1958 int entry; 1959 char *current_ev = buffer; 1960 char *end_buf = buffer + buflen; 1961 struct list_head *ptr; 1962 1963 spin_lock_bh(&local->lock); 1964 1965 list_for_each(ptr, &local->bss_list) { 1966 struct hostap_bss_info *bss; 1967 bss = list_entry(ptr, struct hostap_bss_info, list); 1968 bss->included = 0; 1969 } 1970 1971 for (entry = 0; entry < local->last_scan_results_count; entry++) { 1972 int found = 0; 1973 scan = &local->last_scan_results[entry]; 1974 1975 /* Report every SSID if the AP is using multiple SSIDs. If no 1976 * BSS record is found (e.g., when WPA mode is disabled), 1977 * report the AP once. */ 1978 list_for_each(ptr, &local->bss_list) { 1979 struct hostap_bss_info *bss; 1980 bss = list_entry(ptr, struct hostap_bss_info, list); 1981 if (ether_addr_equal(bss->bssid, scan->bssid)) { 1982 bss->included = 1; 1983 current_ev = __prism2_translate_scan( 1984 local, info, scan, bss, current_ev, 1985 end_buf); 1986 found++; 1987 } 1988 } 1989 if (!found) { 1990 current_ev = __prism2_translate_scan( 1991 local, info, scan, NULL, current_ev, end_buf); 1992 } 1993 /* Check if there is space for one more entry */ 1994 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) { 1995 /* Ask user space to try again with a bigger buffer */ 1996 spin_unlock_bh(&local->lock); 1997 return -E2BIG; 1998 } 1999 } 2000 2001 /* Prism2 firmware has limits (32 at least in some versions) for number 2002 * of BSSes in scan results. Extend this limit by using local BSS list. 2003 */ 2004 list_for_each(ptr, &local->bss_list) { 2005 struct hostap_bss_info *bss; 2006 bss = list_entry(ptr, struct hostap_bss_info, list); 2007 if (bss->included) 2008 continue; 2009 current_ev = __prism2_translate_scan(local, info, NULL, bss, 2010 current_ev, end_buf); 2011 /* Check if there is space for one more entry */ 2012 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) { 2013 /* Ask user space to try again with a bigger buffer */ 2014 spin_unlock_bh(&local->lock); 2015 return -E2BIG; 2016 } 2017 } 2018 2019 spin_unlock_bh(&local->lock); 2020 2021 return current_ev - buffer; 2022 } 2023 #endif /* PRISM2_NO_STATION_MODES */ 2024 2025 2026 static inline int prism2_ioctl_giwscan_sta(struct net_device *dev, 2027 struct iw_request_info *info, 2028 struct iw_point *data, char *extra) 2029 { 2030 #ifdef PRISM2_NO_STATION_MODES 2031 return -EOPNOTSUPP; 2032 #else /* PRISM2_NO_STATION_MODES */ 2033 struct hostap_interface *iface; 2034 local_info_t *local; 2035 int res; 2036 2037 iface = netdev_priv(dev); 2038 local = iface->local; 2039 2040 /* Wait until the scan is finished. We can probably do better 2041 * than that - Jean II */ 2042 if (local->scan_timestamp && 2043 time_before(jiffies, local->scan_timestamp + 3 * HZ)) { 2044 /* Important note : we don't want to block the caller 2045 * until results are ready for various reasons. 2046 * First, managing wait queues is complex and racy 2047 * (there may be multiple simultaneous callers). 2048 * Second, we grab some rtnetlink lock before coming 2049 * here (in dev_ioctl()). 2050 * Third, the caller can wait on the Wireless Event 2051 * - Jean II */ 2052 return -EAGAIN; 2053 } 2054 local->scan_timestamp = 0; 2055 2056 res = prism2_translate_scan(local, info, extra, data->length); 2057 2058 if (res >= 0) { 2059 data->length = res; 2060 return 0; 2061 } else { 2062 data->length = 0; 2063 return res; 2064 } 2065 #endif /* PRISM2_NO_STATION_MODES */ 2066 } 2067 2068 2069 static int prism2_ioctl_giwscan(struct net_device *dev, 2070 struct iw_request_info *info, 2071 struct iw_point *data, char *extra) 2072 { 2073 struct hostap_interface *iface; 2074 local_info_t *local; 2075 int res; 2076 2077 iface = netdev_priv(dev); 2078 local = iface->local; 2079 2080 if (local->iw_mode == IW_MODE_MASTER) { 2081 /* In MASTER mode, it doesn't make sense to go around 2082 * scanning the frequencies and make the stations we serve 2083 * wait when what the user is really interested about is the 2084 * list of stations and access points we are talking to. 2085 * So, just extract results from our cache... 2086 * Jean II */ 2087 2088 /* Translate to WE format */ 2089 res = prism2_ap_translate_scan(dev, info, extra); 2090 if (res >= 0) { 2091 printk(KERN_DEBUG "Scan result translation succeeded " 2092 "(length=%d)\n", res); 2093 data->length = res; 2094 return 0; 2095 } else { 2096 printk(KERN_DEBUG 2097 "Scan result translation failed (res=%d)\n", 2098 res); 2099 data->length = 0; 2100 return res; 2101 } 2102 } else { 2103 /* Station mode */ 2104 return prism2_ioctl_giwscan_sta(dev, info, data, extra); 2105 } 2106 } 2107 2108 2109 static const struct iw_priv_args prism2_priv[] = { 2110 { PRISM2_IOCTL_MONITOR, 2111 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" }, 2112 { PRISM2_IOCTL_READMIF, 2113 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 2114 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" }, 2115 { PRISM2_IOCTL_WRITEMIF, 2116 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" }, 2117 { PRISM2_IOCTL_RESET, 2118 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" }, 2119 { PRISM2_IOCTL_INQUIRE, 2120 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" }, 2121 { PRISM2_IOCTL_SET_RID_WORD, 2122 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" }, 2123 { PRISM2_IOCTL_MACCMD, 2124 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" }, 2125 { PRISM2_IOCTL_WDS_ADD, 2126 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" }, 2127 { PRISM2_IOCTL_WDS_DEL, 2128 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" }, 2129 { PRISM2_IOCTL_ADDMAC, 2130 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" }, 2131 { PRISM2_IOCTL_DELMAC, 2132 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" }, 2133 { PRISM2_IOCTL_KICKMAC, 2134 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" }, 2135 /* --- raw access to sub-ioctls --- */ 2136 { PRISM2_IOCTL_PRISM2_PARAM, 2137 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" }, 2138 { PRISM2_IOCTL_GET_PRISM2_PARAM, 2139 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 2140 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" }, 2141 /* --- sub-ioctls handlers --- */ 2142 { PRISM2_IOCTL_PRISM2_PARAM, 2143 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" }, 2144 { PRISM2_IOCTL_GET_PRISM2_PARAM, 2145 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" }, 2146 /* --- sub-ioctls definitions --- */ 2147 { PRISM2_PARAM_TXRATECTRL, 2148 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" }, 2149 { PRISM2_PARAM_TXRATECTRL, 2150 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" }, 2151 { PRISM2_PARAM_BEACON_INT, 2152 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" }, 2153 { PRISM2_PARAM_BEACON_INT, 2154 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" }, 2155 #ifndef PRISM2_NO_STATION_MODES 2156 { PRISM2_PARAM_PSEUDO_IBSS, 2157 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" }, 2158 { PRISM2_PARAM_PSEUDO_IBSS, 2159 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" }, 2160 #endif /* PRISM2_NO_STATION_MODES */ 2161 { PRISM2_PARAM_ALC, 2162 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" }, 2163 { PRISM2_PARAM_ALC, 2164 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" }, 2165 { PRISM2_PARAM_DUMP, 2166 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" }, 2167 { PRISM2_PARAM_DUMP, 2168 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" }, 2169 { PRISM2_PARAM_OTHER_AP_POLICY, 2170 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" }, 2171 { PRISM2_PARAM_OTHER_AP_POLICY, 2172 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" }, 2173 { PRISM2_PARAM_AP_MAX_INACTIVITY, 2174 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" }, 2175 { PRISM2_PARAM_AP_MAX_INACTIVITY, 2176 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" }, 2177 { PRISM2_PARAM_AP_BRIDGE_PACKETS, 2178 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" }, 2179 { PRISM2_PARAM_AP_BRIDGE_PACKETS, 2180 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" }, 2181 { PRISM2_PARAM_DTIM_PERIOD, 2182 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" }, 2183 { PRISM2_PARAM_DTIM_PERIOD, 2184 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" }, 2185 { PRISM2_PARAM_AP_NULLFUNC_ACK, 2186 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" }, 2187 { PRISM2_PARAM_AP_NULLFUNC_ACK, 2188 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" }, 2189 { PRISM2_PARAM_MAX_WDS, 2190 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" }, 2191 { PRISM2_PARAM_MAX_WDS, 2192 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" }, 2193 { PRISM2_PARAM_AP_AUTOM_AP_WDS, 2194 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" }, 2195 { PRISM2_PARAM_AP_AUTOM_AP_WDS, 2196 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" }, 2197 { PRISM2_PARAM_AP_AUTH_ALGS, 2198 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" }, 2199 { PRISM2_PARAM_AP_AUTH_ALGS, 2200 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" }, 2201 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR, 2202 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" }, 2203 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR, 2204 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" }, 2205 { PRISM2_PARAM_HOST_ENCRYPT, 2206 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" }, 2207 { PRISM2_PARAM_HOST_ENCRYPT, 2208 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" }, 2209 { PRISM2_PARAM_HOST_DECRYPT, 2210 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" }, 2211 { PRISM2_PARAM_HOST_DECRYPT, 2212 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" }, 2213 #ifndef PRISM2_NO_STATION_MODES 2214 { PRISM2_PARAM_HOST_ROAMING, 2215 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" }, 2216 { PRISM2_PARAM_HOST_ROAMING, 2217 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" }, 2218 #endif /* PRISM2_NO_STATION_MODES */ 2219 { PRISM2_PARAM_BCRX_STA_KEY, 2220 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" }, 2221 { PRISM2_PARAM_BCRX_STA_KEY, 2222 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" }, 2223 { PRISM2_PARAM_IEEE_802_1X, 2224 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" }, 2225 { PRISM2_PARAM_IEEE_802_1X, 2226 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" }, 2227 { PRISM2_PARAM_ANTSEL_TX, 2228 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" }, 2229 { PRISM2_PARAM_ANTSEL_TX, 2230 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" }, 2231 { PRISM2_PARAM_ANTSEL_RX, 2232 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" }, 2233 { PRISM2_PARAM_ANTSEL_RX, 2234 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" }, 2235 { PRISM2_PARAM_MONITOR_TYPE, 2236 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" }, 2237 { PRISM2_PARAM_MONITOR_TYPE, 2238 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" }, 2239 { PRISM2_PARAM_WDS_TYPE, 2240 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" }, 2241 { PRISM2_PARAM_WDS_TYPE, 2242 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" }, 2243 { PRISM2_PARAM_HOSTSCAN, 2244 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" }, 2245 { PRISM2_PARAM_HOSTSCAN, 2246 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" }, 2247 { PRISM2_PARAM_AP_SCAN, 2248 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" }, 2249 { PRISM2_PARAM_AP_SCAN, 2250 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" }, 2251 { PRISM2_PARAM_ENH_SEC, 2252 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" }, 2253 { PRISM2_PARAM_ENH_SEC, 2254 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" }, 2255 #ifdef PRISM2_IO_DEBUG 2256 { PRISM2_PARAM_IO_DEBUG, 2257 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" }, 2258 { PRISM2_PARAM_IO_DEBUG, 2259 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" }, 2260 #endif /* PRISM2_IO_DEBUG */ 2261 { PRISM2_PARAM_BASIC_RATES, 2262 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" }, 2263 { PRISM2_PARAM_BASIC_RATES, 2264 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" }, 2265 { PRISM2_PARAM_OPER_RATES, 2266 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" }, 2267 { PRISM2_PARAM_OPER_RATES, 2268 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" }, 2269 { PRISM2_PARAM_HOSTAPD, 2270 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" }, 2271 { PRISM2_PARAM_HOSTAPD, 2272 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" }, 2273 { PRISM2_PARAM_HOSTAPD_STA, 2274 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" }, 2275 { PRISM2_PARAM_HOSTAPD_STA, 2276 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" }, 2277 { PRISM2_PARAM_WPA, 2278 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" }, 2279 { PRISM2_PARAM_WPA, 2280 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" }, 2281 { PRISM2_PARAM_PRIVACY_INVOKED, 2282 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" }, 2283 { PRISM2_PARAM_PRIVACY_INVOKED, 2284 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" }, 2285 { PRISM2_PARAM_TKIP_COUNTERMEASURES, 2286 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" }, 2287 { PRISM2_PARAM_TKIP_COUNTERMEASURES, 2288 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" }, 2289 { PRISM2_PARAM_DROP_UNENCRYPTED, 2290 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" }, 2291 { PRISM2_PARAM_DROP_UNENCRYPTED, 2292 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" }, 2293 { PRISM2_PARAM_SCAN_CHANNEL_MASK, 2294 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" }, 2295 { PRISM2_PARAM_SCAN_CHANNEL_MASK, 2296 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" }, 2297 }; 2298 2299 2300 static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i) 2301 { 2302 struct hostap_interface *iface; 2303 local_info_t *local; 2304 2305 iface = netdev_priv(dev); 2306 local = iface->local; 2307 2308 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL)) 2309 return -EOPNOTSUPP; 2310 2311 return 0; 2312 } 2313 2314 2315 static int prism2_ioctl_priv_prism2_param(struct net_device *dev, 2316 struct iw_request_info *info, 2317 void *wrqu, char *extra) 2318 { 2319 struct hostap_interface *iface; 2320 local_info_t *local; 2321 int *i = (int *) extra; 2322 int param = *i; 2323 int value = *(i + 1); 2324 int ret = 0; 2325 u16 val; 2326 2327 iface = netdev_priv(dev); 2328 local = iface->local; 2329 2330 switch (param) { 2331 case PRISM2_PARAM_TXRATECTRL: 2332 local->fw_tx_rate_control = value; 2333 break; 2334 2335 case PRISM2_PARAM_BEACON_INT: 2336 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) || 2337 local->func->reset_port(dev)) 2338 ret = -EINVAL; 2339 else 2340 local->beacon_int = value; 2341 break; 2342 2343 #ifndef PRISM2_NO_STATION_MODES 2344 case PRISM2_PARAM_PSEUDO_IBSS: 2345 if (value == local->pseudo_adhoc) 2346 break; 2347 2348 if (value != 0 && value != 1) { 2349 ret = -EINVAL; 2350 break; 2351 } 2352 2353 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n", 2354 dev->name, local->pseudo_adhoc, value); 2355 local->pseudo_adhoc = value; 2356 if (local->iw_mode != IW_MODE_ADHOC) 2357 break; 2358 2359 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, 2360 hostap_get_porttype(local))) { 2361 ret = -EOPNOTSUPP; 2362 break; 2363 } 2364 2365 if (local->func->reset_port(dev)) 2366 ret = -EINVAL; 2367 break; 2368 #endif /* PRISM2_NO_STATION_MODES */ 2369 2370 case PRISM2_PARAM_ALC: 2371 printk(KERN_DEBUG "%s: %s ALC\n", dev->name, 2372 value == 0 ? "Disabling" : "Enabling"); 2373 val = HFA384X_TEST_CFG_BIT_ALC; 2374 local->func->cmd(dev, HFA384X_CMDCODE_TEST | 2375 (HFA384X_TEST_CFG_BITS << 8), 2376 value == 0 ? 0 : 1, &val, NULL); 2377 break; 2378 2379 case PRISM2_PARAM_DUMP: 2380 local->frame_dump = value; 2381 break; 2382 2383 case PRISM2_PARAM_OTHER_AP_POLICY: 2384 if (value < 0 || value > 3) { 2385 ret = -EINVAL; 2386 break; 2387 } 2388 if (local->ap != NULL) 2389 local->ap->ap_policy = value; 2390 break; 2391 2392 case PRISM2_PARAM_AP_MAX_INACTIVITY: 2393 if (value < 0 || value > 7 * 24 * 60 * 60) { 2394 ret = -EINVAL; 2395 break; 2396 } 2397 if (local->ap != NULL) 2398 local->ap->max_inactivity = value * HZ; 2399 break; 2400 2401 case PRISM2_PARAM_AP_BRIDGE_PACKETS: 2402 if (local->ap != NULL) 2403 local->ap->bridge_packets = value; 2404 break; 2405 2406 case PRISM2_PARAM_DTIM_PERIOD: 2407 if (value < 0 || value > 65535) { 2408 ret = -EINVAL; 2409 break; 2410 } 2411 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value) 2412 || local->func->reset_port(dev)) 2413 ret = -EINVAL; 2414 else 2415 local->dtim_period = value; 2416 break; 2417 2418 case PRISM2_PARAM_AP_NULLFUNC_ACK: 2419 if (local->ap != NULL) 2420 local->ap->nullfunc_ack = value; 2421 break; 2422 2423 case PRISM2_PARAM_MAX_WDS: 2424 local->wds_max_connections = value; 2425 break; 2426 2427 case PRISM2_PARAM_AP_AUTOM_AP_WDS: 2428 if (local->ap != NULL) { 2429 if (!local->ap->autom_ap_wds && value) { 2430 /* add WDS link to all APs in STA table */ 2431 hostap_add_wds_links(local); 2432 } 2433 local->ap->autom_ap_wds = value; 2434 } 2435 break; 2436 2437 case PRISM2_PARAM_AP_AUTH_ALGS: 2438 local->auth_algs = value; 2439 if (hostap_set_auth_algs(local)) 2440 ret = -EINVAL; 2441 break; 2442 2443 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR: 2444 local->monitor_allow_fcserr = value; 2445 break; 2446 2447 case PRISM2_PARAM_HOST_ENCRYPT: 2448 local->host_encrypt = value; 2449 if (hostap_set_encryption(local) || 2450 local->func->reset_port(dev)) 2451 ret = -EINVAL; 2452 break; 2453 2454 case PRISM2_PARAM_HOST_DECRYPT: 2455 local->host_decrypt = value; 2456 if (hostap_set_encryption(local) || 2457 local->func->reset_port(dev)) 2458 ret = -EINVAL; 2459 break; 2460 2461 #ifndef PRISM2_NO_STATION_MODES 2462 case PRISM2_PARAM_HOST_ROAMING: 2463 if (value < 0 || value > 2) { 2464 ret = -EINVAL; 2465 break; 2466 } 2467 local->host_roaming = value; 2468 if (hostap_set_roaming(local) || local->func->reset_port(dev)) 2469 ret = -EINVAL; 2470 break; 2471 #endif /* PRISM2_NO_STATION_MODES */ 2472 2473 case PRISM2_PARAM_BCRX_STA_KEY: 2474 local->bcrx_sta_key = value; 2475 break; 2476 2477 case PRISM2_PARAM_IEEE_802_1X: 2478 local->ieee_802_1x = value; 2479 break; 2480 2481 case PRISM2_PARAM_ANTSEL_TX: 2482 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) { 2483 ret = -EINVAL; 2484 break; 2485 } 2486 local->antsel_tx = value; 2487 hostap_set_antsel(local); 2488 break; 2489 2490 case PRISM2_PARAM_ANTSEL_RX: 2491 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) { 2492 ret = -EINVAL; 2493 break; 2494 } 2495 local->antsel_rx = value; 2496 hostap_set_antsel(local); 2497 break; 2498 2499 case PRISM2_PARAM_MONITOR_TYPE: 2500 if (value != PRISM2_MONITOR_80211 && 2501 value != PRISM2_MONITOR_CAPHDR && 2502 value != PRISM2_MONITOR_PRISM && 2503 value != PRISM2_MONITOR_RADIOTAP) { 2504 ret = -EINVAL; 2505 break; 2506 } 2507 local->monitor_type = value; 2508 if (local->iw_mode == IW_MODE_MONITOR) 2509 hostap_monitor_set_type(local); 2510 break; 2511 2512 case PRISM2_PARAM_WDS_TYPE: 2513 local->wds_type = value; 2514 break; 2515 2516 case PRISM2_PARAM_HOSTSCAN: 2517 { 2518 struct hfa384x_hostscan_request scan_req; 2519 u16 rate; 2520 2521 memset(&scan_req, 0, sizeof(scan_req)); 2522 scan_req.channel_list = cpu_to_le16(0x3fff); 2523 switch (value) { 2524 case 1: rate = HFA384X_RATES_1MBPS; break; 2525 case 2: rate = HFA384X_RATES_2MBPS; break; 2526 case 3: rate = HFA384X_RATES_5MBPS; break; 2527 case 4: rate = HFA384X_RATES_11MBPS; break; 2528 default: rate = HFA384X_RATES_1MBPS; break; 2529 } 2530 scan_req.txrate = cpu_to_le16(rate); 2531 /* leave SSID empty to accept all SSIDs */ 2532 2533 if (local->iw_mode == IW_MODE_MASTER) { 2534 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, 2535 HFA384X_PORTTYPE_BSS) || 2536 local->func->reset_port(dev)) 2537 printk(KERN_DEBUG "Leaving Host AP mode " 2538 "for HostScan failed\n"); 2539 } 2540 2541 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req, 2542 sizeof(scan_req))) { 2543 printk(KERN_DEBUG "HOSTSCAN failed\n"); 2544 ret = -EINVAL; 2545 } 2546 if (local->iw_mode == IW_MODE_MASTER) { 2547 wait_queue_entry_t __wait; 2548 init_waitqueue_entry(&__wait, current); 2549 add_wait_queue(&local->hostscan_wq, &__wait); 2550 set_current_state(TASK_INTERRUPTIBLE); 2551 schedule_timeout(HZ); 2552 if (signal_pending(current)) 2553 ret = -EINTR; 2554 set_current_state(TASK_RUNNING); 2555 remove_wait_queue(&local->hostscan_wq, &__wait); 2556 2557 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, 2558 HFA384X_PORTTYPE_HOSTAP) || 2559 local->func->reset_port(dev)) 2560 printk(KERN_DEBUG "Returning to Host AP mode " 2561 "after HostScan failed\n"); 2562 } 2563 break; 2564 } 2565 2566 case PRISM2_PARAM_AP_SCAN: 2567 local->passive_scan_interval = value; 2568 if (timer_pending(&local->passive_scan_timer)) 2569 del_timer(&local->passive_scan_timer); 2570 if (value > 0 && value < INT_MAX / HZ) { 2571 local->passive_scan_timer.expires = jiffies + 2572 local->passive_scan_interval * HZ; 2573 add_timer(&local->passive_scan_timer); 2574 } 2575 break; 2576 2577 case PRISM2_PARAM_ENH_SEC: 2578 if (value < 0 || value > 3) { 2579 ret = -EINVAL; 2580 break; 2581 } 2582 local->enh_sec = value; 2583 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, 2584 local->enh_sec) || 2585 local->func->reset_port(dev)) { 2586 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w " 2587 "1.6.3 or newer\n", dev->name); 2588 ret = -EOPNOTSUPP; 2589 } 2590 break; 2591 2592 #ifdef PRISM2_IO_DEBUG 2593 case PRISM2_PARAM_IO_DEBUG: 2594 local->io_debug_enabled = value; 2595 break; 2596 #endif /* PRISM2_IO_DEBUG */ 2597 2598 case PRISM2_PARAM_BASIC_RATES: 2599 if ((value & local->tx_rate_control) != value || value == 0) { 2600 printk(KERN_INFO "%s: invalid basic rate set - basic " 2601 "rates must be in supported rate set\n", 2602 dev->name); 2603 ret = -EINVAL; 2604 break; 2605 } 2606 local->basic_rates = value; 2607 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES, 2608 local->basic_rates) || 2609 local->func->reset_port(dev)) 2610 ret = -EINVAL; 2611 break; 2612 2613 case PRISM2_PARAM_OPER_RATES: 2614 local->tx_rate_control = value; 2615 if (hostap_set_rate(dev)) 2616 ret = -EINVAL; 2617 break; 2618 2619 case PRISM2_PARAM_HOSTAPD: 2620 ret = hostap_set_hostapd(local, value, 1); 2621 break; 2622 2623 case PRISM2_PARAM_HOSTAPD_STA: 2624 ret = hostap_set_hostapd_sta(local, value, 1); 2625 break; 2626 2627 case PRISM2_PARAM_WPA: 2628 local->wpa = value; 2629 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0)) 2630 ret = -EOPNOTSUPP; 2631 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 2632 value ? 1 : 0)) 2633 ret = -EINVAL; 2634 break; 2635 2636 case PRISM2_PARAM_PRIVACY_INVOKED: 2637 local->privacy_invoked = value; 2638 if (hostap_set_encryption(local) || 2639 local->func->reset_port(dev)) 2640 ret = -EINVAL; 2641 break; 2642 2643 case PRISM2_PARAM_TKIP_COUNTERMEASURES: 2644 local->tkip_countermeasures = value; 2645 break; 2646 2647 case PRISM2_PARAM_DROP_UNENCRYPTED: 2648 local->drop_unencrypted = value; 2649 break; 2650 2651 case PRISM2_PARAM_SCAN_CHANNEL_MASK: 2652 local->scan_channel_mask = value; 2653 break; 2654 2655 default: 2656 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n", 2657 dev->name, param); 2658 ret = -EOPNOTSUPP; 2659 break; 2660 } 2661 2662 return ret; 2663 } 2664 2665 2666 static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev, 2667 struct iw_request_info *info, 2668 void *wrqu, char *extra) 2669 { 2670 struct hostap_interface *iface; 2671 local_info_t *local; 2672 int *param = (int *) extra; 2673 int ret = 0; 2674 2675 iface = netdev_priv(dev); 2676 local = iface->local; 2677 2678 switch (*param) { 2679 case PRISM2_PARAM_TXRATECTRL: 2680 *param = local->fw_tx_rate_control; 2681 break; 2682 2683 case PRISM2_PARAM_BEACON_INT: 2684 *param = local->beacon_int; 2685 break; 2686 2687 case PRISM2_PARAM_PSEUDO_IBSS: 2688 *param = local->pseudo_adhoc; 2689 break; 2690 2691 case PRISM2_PARAM_ALC: 2692 ret = -EOPNOTSUPP; /* FIX */ 2693 break; 2694 2695 case PRISM2_PARAM_DUMP: 2696 *param = local->frame_dump; 2697 break; 2698 2699 case PRISM2_PARAM_OTHER_AP_POLICY: 2700 if (local->ap != NULL) 2701 *param = local->ap->ap_policy; 2702 else 2703 ret = -EOPNOTSUPP; 2704 break; 2705 2706 case PRISM2_PARAM_AP_MAX_INACTIVITY: 2707 if (local->ap != NULL) 2708 *param = local->ap->max_inactivity / HZ; 2709 else 2710 ret = -EOPNOTSUPP; 2711 break; 2712 2713 case PRISM2_PARAM_AP_BRIDGE_PACKETS: 2714 if (local->ap != NULL) 2715 *param = local->ap->bridge_packets; 2716 else 2717 ret = -EOPNOTSUPP; 2718 break; 2719 2720 case PRISM2_PARAM_DTIM_PERIOD: 2721 *param = local->dtim_period; 2722 break; 2723 2724 case PRISM2_PARAM_AP_NULLFUNC_ACK: 2725 if (local->ap != NULL) 2726 *param = local->ap->nullfunc_ack; 2727 else 2728 ret = -EOPNOTSUPP; 2729 break; 2730 2731 case PRISM2_PARAM_MAX_WDS: 2732 *param = local->wds_max_connections; 2733 break; 2734 2735 case PRISM2_PARAM_AP_AUTOM_AP_WDS: 2736 if (local->ap != NULL) 2737 *param = local->ap->autom_ap_wds; 2738 else 2739 ret = -EOPNOTSUPP; 2740 break; 2741 2742 case PRISM2_PARAM_AP_AUTH_ALGS: 2743 *param = local->auth_algs; 2744 break; 2745 2746 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR: 2747 *param = local->monitor_allow_fcserr; 2748 break; 2749 2750 case PRISM2_PARAM_HOST_ENCRYPT: 2751 *param = local->host_encrypt; 2752 break; 2753 2754 case PRISM2_PARAM_HOST_DECRYPT: 2755 *param = local->host_decrypt; 2756 break; 2757 2758 case PRISM2_PARAM_HOST_ROAMING: 2759 *param = local->host_roaming; 2760 break; 2761 2762 case PRISM2_PARAM_BCRX_STA_KEY: 2763 *param = local->bcrx_sta_key; 2764 break; 2765 2766 case PRISM2_PARAM_IEEE_802_1X: 2767 *param = local->ieee_802_1x; 2768 break; 2769 2770 case PRISM2_PARAM_ANTSEL_TX: 2771 *param = local->antsel_tx; 2772 break; 2773 2774 case PRISM2_PARAM_ANTSEL_RX: 2775 *param = local->antsel_rx; 2776 break; 2777 2778 case PRISM2_PARAM_MONITOR_TYPE: 2779 *param = local->monitor_type; 2780 break; 2781 2782 case PRISM2_PARAM_WDS_TYPE: 2783 *param = local->wds_type; 2784 break; 2785 2786 case PRISM2_PARAM_HOSTSCAN: 2787 ret = -EOPNOTSUPP; 2788 break; 2789 2790 case PRISM2_PARAM_AP_SCAN: 2791 *param = local->passive_scan_interval; 2792 break; 2793 2794 case PRISM2_PARAM_ENH_SEC: 2795 *param = local->enh_sec; 2796 break; 2797 2798 #ifdef PRISM2_IO_DEBUG 2799 case PRISM2_PARAM_IO_DEBUG: 2800 *param = local->io_debug_enabled; 2801 break; 2802 #endif /* PRISM2_IO_DEBUG */ 2803 2804 case PRISM2_PARAM_BASIC_RATES: 2805 *param = local->basic_rates; 2806 break; 2807 2808 case PRISM2_PARAM_OPER_RATES: 2809 *param = local->tx_rate_control; 2810 break; 2811 2812 case PRISM2_PARAM_HOSTAPD: 2813 *param = local->hostapd; 2814 break; 2815 2816 case PRISM2_PARAM_HOSTAPD_STA: 2817 *param = local->hostapd_sta; 2818 break; 2819 2820 case PRISM2_PARAM_WPA: 2821 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0)) 2822 ret = -EOPNOTSUPP; 2823 *param = local->wpa; 2824 break; 2825 2826 case PRISM2_PARAM_PRIVACY_INVOKED: 2827 *param = local->privacy_invoked; 2828 break; 2829 2830 case PRISM2_PARAM_TKIP_COUNTERMEASURES: 2831 *param = local->tkip_countermeasures; 2832 break; 2833 2834 case PRISM2_PARAM_DROP_UNENCRYPTED: 2835 *param = local->drop_unencrypted; 2836 break; 2837 2838 case PRISM2_PARAM_SCAN_CHANNEL_MASK: 2839 *param = local->scan_channel_mask; 2840 break; 2841 2842 default: 2843 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n", 2844 dev->name, *param); 2845 ret = -EOPNOTSUPP; 2846 break; 2847 } 2848 2849 return ret; 2850 } 2851 2852 2853 static int prism2_ioctl_priv_readmif(struct net_device *dev, 2854 struct iw_request_info *info, 2855 void *wrqu, char *extra) 2856 { 2857 struct hostap_interface *iface; 2858 local_info_t *local; 2859 u16 resp0; 2860 2861 iface = netdev_priv(dev); 2862 local = iface->local; 2863 2864 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL, 2865 &resp0)) 2866 return -EOPNOTSUPP; 2867 else 2868 *extra = resp0; 2869 2870 return 0; 2871 } 2872 2873 2874 static int prism2_ioctl_priv_writemif(struct net_device *dev, 2875 struct iw_request_info *info, 2876 void *wrqu, char *extra) 2877 { 2878 struct hostap_interface *iface; 2879 local_info_t *local; 2880 u16 cr, val; 2881 2882 iface = netdev_priv(dev); 2883 local = iface->local; 2884 2885 cr = *extra; 2886 val = *(extra + 1); 2887 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL)) 2888 return -EOPNOTSUPP; 2889 2890 return 0; 2891 } 2892 2893 2894 static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i) 2895 { 2896 struct hostap_interface *iface; 2897 local_info_t *local; 2898 int ret = 0; 2899 u32 mode; 2900 2901 iface = netdev_priv(dev); 2902 local = iface->local; 2903 2904 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor " 2905 "- update software to use iwconfig mode monitor\n", 2906 dev->name, task_pid_nr(current), current->comm); 2907 2908 /* Backward compatibility code - this can be removed at some point */ 2909 2910 if (*i == 0) { 2911 /* Disable monitor mode - old mode was not saved, so go to 2912 * Master mode */ 2913 mode = IW_MODE_MASTER; 2914 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL); 2915 } else if (*i == 1) { 2916 /* netlink socket mode is not supported anymore since it did 2917 * not separate different devices from each other and was not 2918 * best method for delivering large amount of packets to 2919 * user space */ 2920 ret = -EOPNOTSUPP; 2921 } else if (*i == 2 || *i == 3) { 2922 switch (*i) { 2923 case 2: 2924 local->monitor_type = PRISM2_MONITOR_80211; 2925 break; 2926 case 3: 2927 local->monitor_type = PRISM2_MONITOR_PRISM; 2928 break; 2929 } 2930 mode = IW_MODE_MONITOR; 2931 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL); 2932 hostap_monitor_mode_enable(local); 2933 } else 2934 ret = -EINVAL; 2935 2936 return ret; 2937 } 2938 2939 2940 static int prism2_ioctl_priv_reset(struct net_device *dev, int *i) 2941 { 2942 struct hostap_interface *iface; 2943 local_info_t *local; 2944 2945 iface = netdev_priv(dev); 2946 local = iface->local; 2947 2948 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i); 2949 switch (*i) { 2950 case 0: 2951 /* Disable and enable card */ 2952 local->func->hw_shutdown(dev, 1); 2953 local->func->hw_config(dev, 0); 2954 break; 2955 2956 case 1: 2957 /* COR sreset */ 2958 local->func->hw_reset(dev); 2959 break; 2960 2961 case 2: 2962 /* Disable and enable port 0 */ 2963 local->func->reset_port(dev); 2964 break; 2965 2966 case 3: 2967 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING); 2968 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, 2969 NULL)) 2970 return -EINVAL; 2971 break; 2972 2973 case 4: 2974 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, 2975 NULL)) 2976 return -EINVAL; 2977 break; 2978 2979 default: 2980 printk(KERN_DEBUG "Unknown reset request %d\n", *i); 2981 return -EOPNOTSUPP; 2982 } 2983 2984 return 0; 2985 } 2986 2987 2988 static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i) 2989 { 2990 int rid = *i; 2991 int value = *(i + 1); 2992 2993 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value); 2994 2995 if (hostap_set_word(dev, rid, value)) 2996 return -EINVAL; 2997 2998 return 0; 2999 } 3000 3001 3002 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT 3003 static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd) 3004 { 3005 int ret = 0; 3006 3007 switch (*cmd) { 3008 case AP_MAC_CMD_POLICY_OPEN: 3009 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN; 3010 break; 3011 case AP_MAC_CMD_POLICY_ALLOW: 3012 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW; 3013 break; 3014 case AP_MAC_CMD_POLICY_DENY: 3015 local->ap->mac_restrictions.policy = MAC_POLICY_DENY; 3016 break; 3017 case AP_MAC_CMD_FLUSH: 3018 ap_control_flush_macs(&local->ap->mac_restrictions); 3019 break; 3020 case AP_MAC_CMD_KICKALL: 3021 ap_control_kickall(local->ap); 3022 hostap_deauth_all_stas(local->dev, local->ap, 0); 3023 break; 3024 default: 3025 ret = -EOPNOTSUPP; 3026 break; 3027 } 3028 3029 return ret; 3030 } 3031 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 3032 3033 3034 #ifdef PRISM2_DOWNLOAD_SUPPORT 3035 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p) 3036 { 3037 struct prism2_download_param *param; 3038 int ret = 0; 3039 3040 if (p->length < sizeof(struct prism2_download_param) || 3041 p->length > 1024 || !p->pointer) 3042 return -EINVAL; 3043 3044 param = memdup_user(p->pointer, p->length); 3045 if (IS_ERR(param)) { 3046 return PTR_ERR(param); 3047 } 3048 3049 if (p->length < sizeof(struct prism2_download_param) + 3050 param->num_areas * sizeof(struct prism2_download_area)) { 3051 ret = -EINVAL; 3052 goto out; 3053 } 3054 3055 ret = local->func->download(local, param); 3056 3057 out: 3058 kfree(param); 3059 return ret; 3060 } 3061 #endif /* PRISM2_DOWNLOAD_SUPPORT */ 3062 3063 3064 static int prism2_set_genericelement(struct net_device *dev, u8 *elem, 3065 size_t len) 3066 { 3067 struct hostap_interface *iface = netdev_priv(dev); 3068 local_info_t *local = iface->local; 3069 u8 *buf; 3070 3071 /* 3072 * Add 16-bit length in the beginning of the buffer because Prism2 RID 3073 * includes it. 3074 */ 3075 buf = kmalloc(len + 2, GFP_KERNEL); 3076 if (buf == NULL) 3077 return -ENOMEM; 3078 3079 *((__le16 *) buf) = cpu_to_le16(len); 3080 memcpy(buf + 2, elem, len); 3081 3082 kfree(local->generic_elem); 3083 local->generic_elem = buf; 3084 local->generic_elem_len = len + 2; 3085 3086 return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT, 3087 buf, len + 2); 3088 } 3089 3090 3091 static int prism2_ioctl_siwauth(struct net_device *dev, 3092 struct iw_request_info *info, 3093 struct iw_param *data, char *extra) 3094 { 3095 struct hostap_interface *iface = netdev_priv(dev); 3096 local_info_t *local = iface->local; 3097 3098 switch (data->flags & IW_AUTH_INDEX) { 3099 case IW_AUTH_WPA_VERSION: 3100 case IW_AUTH_CIPHER_PAIRWISE: 3101 case IW_AUTH_CIPHER_GROUP: 3102 case IW_AUTH_KEY_MGMT: 3103 /* 3104 * Host AP driver does not use these parameters and allows 3105 * wpa_supplicant to control them internally. 3106 */ 3107 break; 3108 case IW_AUTH_TKIP_COUNTERMEASURES: 3109 local->tkip_countermeasures = data->value; 3110 break; 3111 case IW_AUTH_DROP_UNENCRYPTED: 3112 local->drop_unencrypted = data->value; 3113 break; 3114 case IW_AUTH_80211_AUTH_ALG: 3115 local->auth_algs = data->value; 3116 break; 3117 case IW_AUTH_WPA_ENABLED: 3118 if (data->value == 0) { 3119 local->wpa = 0; 3120 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0)) 3121 break; 3122 prism2_set_genericelement(dev, "", 0); 3123 local->host_roaming = 0; 3124 local->privacy_invoked = 0; 3125 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 3126 0) || 3127 hostap_set_roaming(local) || 3128 hostap_set_encryption(local) || 3129 local->func->reset_port(dev)) 3130 return -EINVAL; 3131 break; 3132 } 3133 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0)) 3134 return -EOPNOTSUPP; 3135 local->host_roaming = 2; 3136 local->privacy_invoked = 1; 3137 local->wpa = 1; 3138 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) || 3139 hostap_set_roaming(local) || 3140 hostap_set_encryption(local) || 3141 local->func->reset_port(dev)) 3142 return -EINVAL; 3143 break; 3144 case IW_AUTH_RX_UNENCRYPTED_EAPOL: 3145 local->ieee_802_1x = data->value; 3146 break; 3147 case IW_AUTH_PRIVACY_INVOKED: 3148 local->privacy_invoked = data->value; 3149 break; 3150 default: 3151 return -EOPNOTSUPP; 3152 } 3153 return 0; 3154 } 3155 3156 3157 static int prism2_ioctl_giwauth(struct net_device *dev, 3158 struct iw_request_info *info, 3159 struct iw_param *data, char *extra) 3160 { 3161 struct hostap_interface *iface = netdev_priv(dev); 3162 local_info_t *local = iface->local; 3163 3164 switch (data->flags & IW_AUTH_INDEX) { 3165 case IW_AUTH_WPA_VERSION: 3166 case IW_AUTH_CIPHER_PAIRWISE: 3167 case IW_AUTH_CIPHER_GROUP: 3168 case IW_AUTH_KEY_MGMT: 3169 /* 3170 * Host AP driver does not use these parameters and allows 3171 * wpa_supplicant to control them internally. 3172 */ 3173 return -EOPNOTSUPP; 3174 case IW_AUTH_TKIP_COUNTERMEASURES: 3175 data->value = local->tkip_countermeasures; 3176 break; 3177 case IW_AUTH_DROP_UNENCRYPTED: 3178 data->value = local->drop_unencrypted; 3179 break; 3180 case IW_AUTH_80211_AUTH_ALG: 3181 data->value = local->auth_algs; 3182 break; 3183 case IW_AUTH_WPA_ENABLED: 3184 data->value = local->wpa; 3185 break; 3186 case IW_AUTH_RX_UNENCRYPTED_EAPOL: 3187 data->value = local->ieee_802_1x; 3188 break; 3189 default: 3190 return -EOPNOTSUPP; 3191 } 3192 return 0; 3193 } 3194 3195 3196 static int prism2_ioctl_siwencodeext(struct net_device *dev, 3197 struct iw_request_info *info, 3198 struct iw_point *erq, char *extra) 3199 { 3200 struct hostap_interface *iface = netdev_priv(dev); 3201 local_info_t *local = iface->local; 3202 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; 3203 int i, ret = 0; 3204 struct lib80211_crypto_ops *ops; 3205 struct lib80211_crypt_data **crypt; 3206 void *sta_ptr; 3207 u8 *addr; 3208 const char *alg, *module; 3209 3210 i = erq->flags & IW_ENCODE_INDEX; 3211 if (i > WEP_KEYS) 3212 return -EINVAL; 3213 if (i < 1 || i > WEP_KEYS) 3214 i = local->crypt_info.tx_keyidx; 3215 else 3216 i--; 3217 if (i < 0 || i >= WEP_KEYS) 3218 return -EINVAL; 3219 3220 addr = ext->addr.sa_data; 3221 if (is_broadcast_ether_addr(addr)) { 3222 sta_ptr = NULL; 3223 crypt = &local->crypt_info.crypt[i]; 3224 } else { 3225 if (i != 0) 3226 return -EINVAL; 3227 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt); 3228 if (sta_ptr == NULL) { 3229 if (local->iw_mode == IW_MODE_INFRA) { 3230 /* 3231 * TODO: add STA entry for the current AP so 3232 * that unicast key can be used. For now, this 3233 * is emulated by using default key idx 0. 3234 */ 3235 i = 0; 3236 crypt = &local->crypt_info.crypt[i]; 3237 } else 3238 return -EINVAL; 3239 } 3240 } 3241 3242 if ((erq->flags & IW_ENCODE_DISABLED) || 3243 ext->alg == IW_ENCODE_ALG_NONE) { 3244 if (*crypt) 3245 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt); 3246 goto done; 3247 } 3248 3249 switch (ext->alg) { 3250 case IW_ENCODE_ALG_WEP: 3251 alg = "WEP"; 3252 module = "lib80211_crypt_wep"; 3253 break; 3254 case IW_ENCODE_ALG_TKIP: 3255 alg = "TKIP"; 3256 module = "lib80211_crypt_tkip"; 3257 break; 3258 case IW_ENCODE_ALG_CCMP: 3259 alg = "CCMP"; 3260 module = "lib80211_crypt_ccmp"; 3261 break; 3262 default: 3263 printk(KERN_DEBUG "%s: unsupported algorithm %d\n", 3264 local->dev->name, ext->alg); 3265 ret = -EOPNOTSUPP; 3266 goto done; 3267 } 3268 3269 ops = lib80211_get_crypto_ops(alg); 3270 if (ops == NULL) { 3271 request_module(module); 3272 ops = lib80211_get_crypto_ops(alg); 3273 } 3274 if (ops == NULL) { 3275 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n", 3276 local->dev->name, alg); 3277 ret = -EOPNOTSUPP; 3278 goto done; 3279 } 3280 3281 if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) { 3282 /* 3283 * Per station encryption and other than WEP algorithms 3284 * require host-based encryption, so force them on 3285 * automatically. 3286 */ 3287 local->host_decrypt = local->host_encrypt = 1; 3288 } 3289 3290 if (*crypt == NULL || (*crypt)->ops != ops) { 3291 struct lib80211_crypt_data *new_crypt; 3292 3293 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt); 3294 3295 new_crypt = kzalloc(sizeof(struct lib80211_crypt_data), 3296 GFP_KERNEL); 3297 if (new_crypt == NULL) { 3298 ret = -ENOMEM; 3299 goto done; 3300 } 3301 new_crypt->ops = ops; 3302 if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) 3303 new_crypt->priv = new_crypt->ops->init(i); 3304 if (new_crypt->priv == NULL) { 3305 kfree(new_crypt); 3306 ret = -EINVAL; 3307 goto done; 3308 } 3309 3310 *crypt = new_crypt; 3311 } 3312 3313 /* 3314 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the 3315 * existing seq# should not be changed. 3316 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq# 3317 * should be changed to something else than zero. 3318 */ 3319 if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0) 3320 && (*crypt)->ops->set_key && 3321 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq, 3322 (*crypt)->priv) < 0) { 3323 printk(KERN_DEBUG "%s: key setting failed\n", 3324 local->dev->name); 3325 ret = -EINVAL; 3326 goto done; 3327 } 3328 3329 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { 3330 if (!sta_ptr) 3331 local->crypt_info.tx_keyidx = i; 3332 } 3333 3334 3335 if (sta_ptr == NULL && ext->key_len > 0) { 3336 int first = 1, j; 3337 for (j = 0; j < WEP_KEYS; j++) { 3338 if (j != i && local->crypt_info.crypt[j]) { 3339 first = 0; 3340 break; 3341 } 3342 } 3343 if (first) 3344 local->crypt_info.tx_keyidx = i; 3345 } 3346 3347 done: 3348 if (sta_ptr) 3349 hostap_handle_sta_release(sta_ptr); 3350 3351 local->open_wep = erq->flags & IW_ENCODE_OPEN; 3352 3353 /* 3354 * Do not reset port0 if card is in Managed mode since resetting will 3355 * generate new IEEE 802.11 authentication which may end up in looping 3356 * with IEEE 802.1X. Prism2 documentation seem to require port reset 3357 * after WEP configuration. However, keys are apparently changed at 3358 * least in Managed mode. 3359 */ 3360 if (ret == 0 && 3361 (hostap_set_encryption(local) || 3362 (local->iw_mode != IW_MODE_INFRA && 3363 local->func->reset_port(local->dev)))) 3364 ret = -EINVAL; 3365 3366 return ret; 3367 } 3368 3369 3370 static int prism2_ioctl_giwencodeext(struct net_device *dev, 3371 struct iw_request_info *info, 3372 struct iw_point *erq, char *extra) 3373 { 3374 struct hostap_interface *iface = netdev_priv(dev); 3375 local_info_t *local = iface->local; 3376 struct lib80211_crypt_data **crypt; 3377 void *sta_ptr; 3378 int max_key_len, i; 3379 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; 3380 u8 *addr; 3381 3382 max_key_len = erq->length - sizeof(*ext); 3383 if (max_key_len < 0) 3384 return -EINVAL; 3385 3386 i = erq->flags & IW_ENCODE_INDEX; 3387 if (i < 1 || i > WEP_KEYS) 3388 i = local->crypt_info.tx_keyidx; 3389 else 3390 i--; 3391 3392 addr = ext->addr.sa_data; 3393 if (is_broadcast_ether_addr(addr)) { 3394 sta_ptr = NULL; 3395 crypt = &local->crypt_info.crypt[i]; 3396 } else { 3397 i = 0; 3398 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt); 3399 if (sta_ptr == NULL) 3400 return -EINVAL; 3401 } 3402 erq->flags = i + 1; 3403 memset(ext, 0, sizeof(*ext)); 3404 3405 if (*crypt == NULL || (*crypt)->ops == NULL) { 3406 ext->alg = IW_ENCODE_ALG_NONE; 3407 ext->key_len = 0; 3408 erq->flags |= IW_ENCODE_DISABLED; 3409 } else { 3410 if (strcmp((*crypt)->ops->name, "WEP") == 0) 3411 ext->alg = IW_ENCODE_ALG_WEP; 3412 else if (strcmp((*crypt)->ops->name, "TKIP") == 0) 3413 ext->alg = IW_ENCODE_ALG_TKIP; 3414 else if (strcmp((*crypt)->ops->name, "CCMP") == 0) 3415 ext->alg = IW_ENCODE_ALG_CCMP; 3416 else 3417 return -EINVAL; 3418 3419 if ((*crypt)->ops->get_key) { 3420 ext->key_len = 3421 (*crypt)->ops->get_key(ext->key, 3422 max_key_len, 3423 ext->tx_seq, 3424 (*crypt)->priv); 3425 if (ext->key_len && 3426 (ext->alg == IW_ENCODE_ALG_TKIP || 3427 ext->alg == IW_ENCODE_ALG_CCMP)) 3428 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID; 3429 } 3430 } 3431 3432 if (sta_ptr) 3433 hostap_handle_sta_release(sta_ptr); 3434 3435 return 0; 3436 } 3437 3438 3439 static int prism2_ioctl_set_encryption(local_info_t *local, 3440 struct prism2_hostapd_param *param, 3441 int param_len) 3442 { 3443 int ret = 0; 3444 struct lib80211_crypto_ops *ops; 3445 struct lib80211_crypt_data **crypt; 3446 void *sta_ptr; 3447 3448 param->u.crypt.err = 0; 3449 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0'; 3450 3451 if (param_len != 3452 (int) ((char *) param->u.crypt.key - (char *) param) + 3453 param->u.crypt.key_len) 3454 return -EINVAL; 3455 3456 if (is_broadcast_ether_addr(param->sta_addr)) { 3457 if (param->u.crypt.idx >= WEP_KEYS) 3458 return -EINVAL; 3459 sta_ptr = NULL; 3460 crypt = &local->crypt_info.crypt[param->u.crypt.idx]; 3461 } else { 3462 if (param->u.crypt.idx) 3463 return -EINVAL; 3464 sta_ptr = ap_crypt_get_ptrs( 3465 local->ap, param->sta_addr, 3466 (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT), 3467 &crypt); 3468 3469 if (sta_ptr == NULL) { 3470 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; 3471 return -EINVAL; 3472 } 3473 } 3474 3475 if (strcmp(param->u.crypt.alg, "none") == 0) { 3476 if (crypt) 3477 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt); 3478 goto done; 3479 } 3480 3481 ops = lib80211_get_crypto_ops(param->u.crypt.alg); 3482 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) { 3483 request_module("lib80211_crypt_wep"); 3484 ops = lib80211_get_crypto_ops(param->u.crypt.alg); 3485 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) { 3486 request_module("lib80211_crypt_tkip"); 3487 ops = lib80211_get_crypto_ops(param->u.crypt.alg); 3488 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) { 3489 request_module("lib80211_crypt_ccmp"); 3490 ops = lib80211_get_crypto_ops(param->u.crypt.alg); 3491 } 3492 if (ops == NULL) { 3493 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n", 3494 local->dev->name, param->u.crypt.alg); 3495 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG; 3496 ret = -EINVAL; 3497 goto done; 3498 } 3499 3500 /* station based encryption and other than WEP algorithms require 3501 * host-based encryption, so force them on automatically */ 3502 local->host_decrypt = local->host_encrypt = 1; 3503 3504 if (*crypt == NULL || (*crypt)->ops != ops) { 3505 struct lib80211_crypt_data *new_crypt; 3506 3507 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt); 3508 3509 new_crypt = kzalloc(sizeof(struct lib80211_crypt_data), 3510 GFP_KERNEL); 3511 if (new_crypt == NULL) { 3512 ret = -ENOMEM; 3513 goto done; 3514 } 3515 new_crypt->ops = ops; 3516 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx); 3517 if (new_crypt->priv == NULL) { 3518 kfree(new_crypt); 3519 param->u.crypt.err = 3520 HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED; 3521 ret = -EINVAL; 3522 goto done; 3523 } 3524 3525 *crypt = new_crypt; 3526 } 3527 3528 if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) || 3529 param->u.crypt.key_len > 0) && (*crypt)->ops->set_key && 3530 (*crypt)->ops->set_key(param->u.crypt.key, 3531 param->u.crypt.key_len, param->u.crypt.seq, 3532 (*crypt)->priv) < 0) { 3533 printk(KERN_DEBUG "%s: key setting failed\n", 3534 local->dev->name); 3535 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED; 3536 ret = -EINVAL; 3537 goto done; 3538 } 3539 3540 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) { 3541 if (!sta_ptr) 3542 local->crypt_info.tx_keyidx = param->u.crypt.idx; 3543 else if (param->u.crypt.idx) { 3544 printk(KERN_DEBUG "%s: TX key idx setting failed\n", 3545 local->dev->name); 3546 param->u.crypt.err = 3547 HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED; 3548 ret = -EINVAL; 3549 goto done; 3550 } 3551 } 3552 3553 done: 3554 if (sta_ptr) 3555 hostap_handle_sta_release(sta_ptr); 3556 3557 /* Do not reset port0 if card is in Managed mode since resetting will 3558 * generate new IEEE 802.11 authentication which may end up in looping 3559 * with IEEE 802.1X. Prism2 documentation seem to require port reset 3560 * after WEP configuration. However, keys are apparently changed at 3561 * least in Managed mode. */ 3562 if (ret == 0 && 3563 (hostap_set_encryption(local) || 3564 (local->iw_mode != IW_MODE_INFRA && 3565 local->func->reset_port(local->dev)))) { 3566 param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED; 3567 return -EINVAL; 3568 } 3569 3570 return ret; 3571 } 3572 3573 3574 static int prism2_ioctl_get_encryption(local_info_t *local, 3575 struct prism2_hostapd_param *param, 3576 int param_len) 3577 { 3578 struct lib80211_crypt_data **crypt; 3579 void *sta_ptr; 3580 int max_key_len; 3581 3582 param->u.crypt.err = 0; 3583 3584 max_key_len = param_len - 3585 (int) ((char *) param->u.crypt.key - (char *) param); 3586 if (max_key_len < 0) 3587 return -EINVAL; 3588 3589 if (is_broadcast_ether_addr(param->sta_addr)) { 3590 sta_ptr = NULL; 3591 if (param->u.crypt.idx >= WEP_KEYS) 3592 param->u.crypt.idx = local->crypt_info.tx_keyidx; 3593 crypt = &local->crypt_info.crypt[param->u.crypt.idx]; 3594 } else { 3595 param->u.crypt.idx = 0; 3596 sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0, 3597 &crypt); 3598 3599 if (sta_ptr == NULL) { 3600 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; 3601 return -EINVAL; 3602 } 3603 } 3604 3605 if (*crypt == NULL || (*crypt)->ops == NULL) { 3606 memcpy(param->u.crypt.alg, "none", 5); 3607 param->u.crypt.key_len = 0; 3608 param->u.crypt.idx = 0xff; 3609 } else { 3610 strncpy(param->u.crypt.alg, (*crypt)->ops->name, 3611 HOSTAP_CRYPT_ALG_NAME_LEN); 3612 param->u.crypt.key_len = 0; 3613 3614 memset(param->u.crypt.seq, 0, 8); 3615 if ((*crypt)->ops->get_key) { 3616 param->u.crypt.key_len = 3617 (*crypt)->ops->get_key(param->u.crypt.key, 3618 max_key_len, 3619 param->u.crypt.seq, 3620 (*crypt)->priv); 3621 } 3622 } 3623 3624 if (sta_ptr) 3625 hostap_handle_sta_release(sta_ptr); 3626 3627 return 0; 3628 } 3629 3630 3631 static int prism2_ioctl_get_rid(local_info_t *local, 3632 struct prism2_hostapd_param *param, 3633 int param_len) 3634 { 3635 int max_len, res; 3636 3637 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN; 3638 if (max_len < 0) 3639 return -EINVAL; 3640 3641 res = local->func->get_rid(local->dev, param->u.rid.rid, 3642 param->u.rid.data, param->u.rid.len, 0); 3643 if (res >= 0) { 3644 param->u.rid.len = res; 3645 return 0; 3646 } 3647 3648 return res; 3649 } 3650 3651 3652 static int prism2_ioctl_set_rid(local_info_t *local, 3653 struct prism2_hostapd_param *param, 3654 int param_len) 3655 { 3656 int max_len; 3657 3658 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN; 3659 if (max_len < 0 || max_len < param->u.rid.len) 3660 return -EINVAL; 3661 3662 return local->func->set_rid(local->dev, param->u.rid.rid, 3663 param->u.rid.data, param->u.rid.len); 3664 } 3665 3666 3667 static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local, 3668 struct prism2_hostapd_param *param, 3669 int param_len) 3670 { 3671 printk(KERN_DEBUG "%ssta: associated as client with AP %pM\n", 3672 local->dev->name, param->sta_addr); 3673 memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN); 3674 return 0; 3675 } 3676 3677 3678 static int prism2_ioctl_siwgenie(struct net_device *dev, 3679 struct iw_request_info *info, 3680 struct iw_point *data, char *extra) 3681 { 3682 return prism2_set_genericelement(dev, extra, data->length); 3683 } 3684 3685 3686 static int prism2_ioctl_giwgenie(struct net_device *dev, 3687 struct iw_request_info *info, 3688 struct iw_point *data, char *extra) 3689 { 3690 struct hostap_interface *iface = netdev_priv(dev); 3691 local_info_t *local = iface->local; 3692 int len = local->generic_elem_len - 2; 3693 3694 if (len <= 0 || local->generic_elem == NULL) { 3695 data->length = 0; 3696 return 0; 3697 } 3698 3699 if (data->length < len) 3700 return -E2BIG; 3701 3702 data->length = len; 3703 memcpy(extra, local->generic_elem + 2, len); 3704 3705 return 0; 3706 } 3707 3708 3709 static int prism2_ioctl_set_generic_element(local_info_t *local, 3710 struct prism2_hostapd_param *param, 3711 int param_len) 3712 { 3713 int max_len, len; 3714 3715 len = param->u.generic_elem.len; 3716 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN; 3717 if (max_len < 0 || max_len < len) 3718 return -EINVAL; 3719 3720 return prism2_set_genericelement(local->dev, 3721 param->u.generic_elem.data, len); 3722 } 3723 3724 3725 static int prism2_ioctl_siwmlme(struct net_device *dev, 3726 struct iw_request_info *info, 3727 struct iw_point *data, char *extra) 3728 { 3729 struct hostap_interface *iface = netdev_priv(dev); 3730 local_info_t *local = iface->local; 3731 struct iw_mlme *mlme = (struct iw_mlme *) extra; 3732 __le16 reason; 3733 3734 reason = cpu_to_le16(mlme->reason_code); 3735 3736 switch (mlme->cmd) { 3737 case IW_MLME_DEAUTH: 3738 return prism2_sta_send_mgmt(local, mlme->addr.sa_data, 3739 IEEE80211_STYPE_DEAUTH, 3740 (u8 *) &reason, 2); 3741 case IW_MLME_DISASSOC: 3742 return prism2_sta_send_mgmt(local, mlme->addr.sa_data, 3743 IEEE80211_STYPE_DISASSOC, 3744 (u8 *) &reason, 2); 3745 default: 3746 return -EOPNOTSUPP; 3747 } 3748 } 3749 3750 3751 static int prism2_ioctl_mlme(local_info_t *local, 3752 struct prism2_hostapd_param *param) 3753 { 3754 __le16 reason; 3755 3756 reason = cpu_to_le16(param->u.mlme.reason_code); 3757 switch (param->u.mlme.cmd) { 3758 case MLME_STA_DEAUTH: 3759 return prism2_sta_send_mgmt(local, param->sta_addr, 3760 IEEE80211_STYPE_DEAUTH, 3761 (u8 *) &reason, 2); 3762 case MLME_STA_DISASSOC: 3763 return prism2_sta_send_mgmt(local, param->sta_addr, 3764 IEEE80211_STYPE_DISASSOC, 3765 (u8 *) &reason, 2); 3766 default: 3767 return -EOPNOTSUPP; 3768 } 3769 } 3770 3771 3772 static int prism2_ioctl_scan_req(local_info_t *local, 3773 struct prism2_hostapd_param *param) 3774 { 3775 #ifndef PRISM2_NO_STATION_MODES 3776 if ((local->iw_mode != IW_MODE_INFRA && 3777 local->iw_mode != IW_MODE_ADHOC) || 3778 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))) 3779 return -EOPNOTSUPP; 3780 3781 if (!local->dev_enabled) 3782 return -ENETDOWN; 3783 3784 return prism2_request_hostscan(local->dev, param->u.scan_req.ssid, 3785 param->u.scan_req.ssid_len); 3786 #else /* PRISM2_NO_STATION_MODES */ 3787 return -EOPNOTSUPP; 3788 #endif /* PRISM2_NO_STATION_MODES */ 3789 } 3790 3791 3792 static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p) 3793 { 3794 struct prism2_hostapd_param *param; 3795 int ret = 0; 3796 int ap_ioctl = 0; 3797 3798 if (p->length < sizeof(struct prism2_hostapd_param) || 3799 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) 3800 return -EINVAL; 3801 3802 param = memdup_user(p->pointer, p->length); 3803 if (IS_ERR(param)) { 3804 return PTR_ERR(param); 3805 } 3806 3807 switch (param->cmd) { 3808 case PRISM2_SET_ENCRYPTION: 3809 ret = prism2_ioctl_set_encryption(local, param, p->length); 3810 break; 3811 case PRISM2_GET_ENCRYPTION: 3812 ret = prism2_ioctl_get_encryption(local, param, p->length); 3813 break; 3814 case PRISM2_HOSTAPD_GET_RID: 3815 ret = prism2_ioctl_get_rid(local, param, p->length); 3816 break; 3817 case PRISM2_HOSTAPD_SET_RID: 3818 ret = prism2_ioctl_set_rid(local, param, p->length); 3819 break; 3820 case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR: 3821 ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length); 3822 break; 3823 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT: 3824 ret = prism2_ioctl_set_generic_element(local, param, 3825 p->length); 3826 break; 3827 case PRISM2_HOSTAPD_MLME: 3828 ret = prism2_ioctl_mlme(local, param); 3829 break; 3830 case PRISM2_HOSTAPD_SCAN_REQ: 3831 ret = prism2_ioctl_scan_req(local, param); 3832 break; 3833 default: 3834 ret = prism2_hostapd(local->ap, param); 3835 ap_ioctl = 1; 3836 break; 3837 } 3838 3839 if (ret == 1 || !ap_ioctl) { 3840 if (copy_to_user(p->pointer, param, p->length)) { 3841 ret = -EFAULT; 3842 goto out; 3843 } else if (ap_ioctl) 3844 ret = 0; 3845 } 3846 3847 out: 3848 kfree(param); 3849 return ret; 3850 } 3851 3852 3853 static void prism2_get_drvinfo(struct net_device *dev, 3854 struct ethtool_drvinfo *info) 3855 { 3856 struct hostap_interface *iface; 3857 local_info_t *local; 3858 3859 iface = netdev_priv(dev); 3860 local = iface->local; 3861 3862 strlcpy(info->driver, "hostap", sizeof(info->driver)); 3863 snprintf(info->fw_version, sizeof(info->fw_version), 3864 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff, 3865 (local->sta_fw_ver >> 8) & 0xff, 3866 local->sta_fw_ver & 0xff); 3867 } 3868 3869 const struct ethtool_ops prism2_ethtool_ops = { 3870 .get_drvinfo = prism2_get_drvinfo 3871 }; 3872 3873 3874 /* Structures to export the Wireless Handlers */ 3875 3876 static const iw_handler prism2_handler[] = 3877 { 3878 (iw_handler) NULL, /* SIOCSIWCOMMIT */ 3879 (iw_handler) prism2_get_name, /* SIOCGIWNAME */ 3880 (iw_handler) NULL, /* SIOCSIWNWID */ 3881 (iw_handler) NULL, /* SIOCGIWNWID */ 3882 (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */ 3883 (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */ 3884 (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */ 3885 (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */ 3886 (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */ 3887 (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */ 3888 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ 3889 (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */ 3890 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ 3891 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ 3892 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ 3893 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ 3894 iw_handler_set_spy, /* SIOCSIWSPY */ 3895 iw_handler_get_spy, /* SIOCGIWSPY */ 3896 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ 3897 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ 3898 (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */ 3899 (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */ 3900 (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */ 3901 (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */ 3902 (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */ 3903 (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */ 3904 (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */ 3905 (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */ 3906 (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */ 3907 (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */ 3908 (iw_handler) NULL, /* -- hole -- */ 3909 (iw_handler) NULL, /* -- hole -- */ 3910 (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */ 3911 (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */ 3912 (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */ 3913 (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */ 3914 (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */ 3915 (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */ 3916 (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */ 3917 (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */ 3918 (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */ 3919 (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */ 3920 (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */ 3921 (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */ 3922 (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */ 3923 (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */ 3924 (iw_handler) NULL, /* -- hole -- */ 3925 (iw_handler) NULL, /* -- hole -- */ 3926 (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */ 3927 (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */ 3928 (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */ 3929 (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */ 3930 (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ 3931 (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */ 3932 (iw_handler) NULL, /* SIOCSIWPMKSA */ 3933 (iw_handler) NULL, /* -- hole -- */ 3934 }; 3935 3936 static const iw_handler prism2_private_handler[] = 3937 { /* SIOCIWFIRSTPRIV + */ 3938 (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */ 3939 (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */ 3940 (iw_handler) prism2_ioctl_priv_writemif, /* 2 */ 3941 (iw_handler) prism2_ioctl_priv_readmif, /* 3 */ 3942 }; 3943 3944 const struct iw_handler_def hostap_iw_handler_def = 3945 { 3946 .num_standard = ARRAY_SIZE(prism2_handler), 3947 .num_private = ARRAY_SIZE(prism2_private_handler), 3948 .num_private_args = ARRAY_SIZE(prism2_priv), 3949 .standard = (iw_handler *) prism2_handler, 3950 .private = (iw_handler *) prism2_private_handler, 3951 .private_args = (struct iw_priv_args *) prism2_priv, 3952 .get_wireless_stats = hostap_get_wireless_stats, 3953 }; 3954 3955 3956 int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 3957 { 3958 struct iwreq *wrq = (struct iwreq *) ifr; 3959 struct hostap_interface *iface; 3960 local_info_t *local; 3961 int ret = 0; 3962 3963 iface = netdev_priv(dev); 3964 local = iface->local; 3965 3966 switch (cmd) { 3967 /* Private ioctls (iwpriv) that have not yet been converted 3968 * into new wireless extensions API */ 3969 3970 case PRISM2_IOCTL_INQUIRE: 3971 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 3972 else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name); 3973 break; 3974 3975 case PRISM2_IOCTL_MONITOR: 3976 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 3977 else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name); 3978 break; 3979 3980 case PRISM2_IOCTL_RESET: 3981 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 3982 else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name); 3983 break; 3984 3985 case PRISM2_IOCTL_WDS_ADD: 3986 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 3987 else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1); 3988 break; 3989 3990 case PRISM2_IOCTL_WDS_DEL: 3991 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 3992 else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0); 3993 break; 3994 3995 case PRISM2_IOCTL_SET_RID_WORD: 3996 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 3997 else ret = prism2_ioctl_priv_set_rid_word(dev, 3998 (int *) wrq->u.name); 3999 break; 4000 4001 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT 4002 case PRISM2_IOCTL_MACCMD: 4003 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 4004 else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name); 4005 break; 4006 4007 case PRISM2_IOCTL_ADDMAC: 4008 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 4009 else ret = ap_control_add_mac(&local->ap->mac_restrictions, 4010 wrq->u.ap_addr.sa_data); 4011 break; 4012 case PRISM2_IOCTL_DELMAC: 4013 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 4014 else ret = ap_control_del_mac(&local->ap->mac_restrictions, 4015 wrq->u.ap_addr.sa_data); 4016 break; 4017 case PRISM2_IOCTL_KICKMAC: 4018 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 4019 else ret = ap_control_kick_mac(local->ap, local->dev, 4020 wrq->u.ap_addr.sa_data); 4021 break; 4022 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 4023 4024 4025 /* Private ioctls that are not used with iwpriv; 4026 * in SIOCDEVPRIVATE range */ 4027 4028 #ifdef PRISM2_DOWNLOAD_SUPPORT 4029 case PRISM2_IOCTL_DOWNLOAD: 4030 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 4031 else ret = prism2_ioctl_priv_download(local, &wrq->u.data); 4032 break; 4033 #endif /* PRISM2_DOWNLOAD_SUPPORT */ 4034 4035 case PRISM2_IOCTL_HOSTAPD: 4036 if (!capable(CAP_NET_ADMIN)) ret = -EPERM; 4037 else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data); 4038 break; 4039 4040 default: 4041 ret = -EOPNOTSUPP; 4042 break; 4043 } 4044 4045 return ret; 4046 } 4047