PageRenderTime 148ms CodeModel.GetById 17ms app.highlight 115ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/net/wireless/hostap/hostap_ioctl.c

http://github.com/mirrors/linux
C | 4054 lines | 3235 code | 637 blank | 182 comment | 686 complexity | 24c14f8b79eb0d5f2851e0964efeb5a2 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
   2
   3#include <linux/slab.h>
   4#include <linux/types.h>
   5#include <linux/sched.h>
   6#include <linux/ethtool.h>
   7#include <linux/if_arp.h>
   8#include <linux/module.h>
   9#include <linux/etherdevice.h>
  10#include <net/lib80211.h>
  11
  12#include "hostap_wlan.h"
  13#include "hostap.h"
  14#include "hostap_ap.h"
  15
  16static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
  17{
  18	struct hostap_interface *iface;
  19	local_info_t *local;
  20	struct iw_statistics *wstats;
  21
  22	iface = netdev_priv(dev);
  23	local = iface->local;
  24
  25	/* Why are we doing that ? Jean II */
  26	if (iface->type != HOSTAP_INTERFACE_MAIN)
  27		return NULL;
  28
  29	wstats = &local->wstats;
  30
  31	wstats->status = 0;
  32	wstats->discard.code =
  33		local->comm_tallies.rx_discards_wep_undecryptable;
  34	wstats->discard.misc =
  35		local->comm_tallies.rx_fcs_errors +
  36		local->comm_tallies.rx_discards_no_buffer +
  37		local->comm_tallies.tx_discards_wrong_sa;
  38
  39	wstats->discard.retries =
  40		local->comm_tallies.tx_retry_limit_exceeded;
  41	wstats->discard.fragment =
  42		local->comm_tallies.rx_message_in_bad_msg_fragments;
  43
  44	if (local->iw_mode != IW_MODE_MASTER &&
  45	    local->iw_mode != IW_MODE_REPEAT) {
  46		int update = 1;
  47#ifdef in_atomic
  48		/* RID reading might sleep and it must not be called in
  49		 * interrupt context or while atomic. However, this
  50		 * function seems to be called while atomic (at least in Linux
  51		 * 2.5.59). Update signal quality values only if in suitable
  52		 * context. Otherwise, previous values read from tick timer
  53		 * will be used. */
  54		if (in_atomic())
  55			update = 0;
  56#endif /* in_atomic */
  57
  58		if (update && prism2_update_comms_qual(dev) == 0)
  59			wstats->qual.updated = IW_QUAL_ALL_UPDATED |
  60				IW_QUAL_DBM;
  61
  62		wstats->qual.qual = local->comms_qual;
  63		wstats->qual.level = local->avg_signal;
  64		wstats->qual.noise = local->avg_noise;
  65	} else {
  66		wstats->qual.qual = 0;
  67		wstats->qual.level = 0;
  68		wstats->qual.noise = 0;
  69		wstats->qual.updated = IW_QUAL_ALL_INVALID;
  70	}
  71
  72	return wstats;
  73}
  74
  75
  76static int prism2_get_datarates(struct net_device *dev, u8 *rates)
  77{
  78	struct hostap_interface *iface;
  79	local_info_t *local;
  80	u8 buf[12];
  81	int len;
  82	u16 val;
  83
  84	iface = netdev_priv(dev);
  85	local = iface->local;
  86
  87	len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
  88				   sizeof(buf), 0);
  89	if (len < 2)
  90		return 0;
  91
  92	val = le16_to_cpu(*(__le16 *) buf); /* string length */
  93
  94	if (len - 2 < val || val > 10)
  95		return 0;
  96
  97	memcpy(rates, buf + 2, val);
  98	return val;
  99}
 100
 101
 102static int prism2_get_name(struct net_device *dev,
 103			   struct iw_request_info *info,
 104			   char *name, char *extra)
 105{
 106	u8 rates[10];
 107	int len, i, over2 = 0;
 108
 109	len = prism2_get_datarates(dev, rates);
 110
 111	for (i = 0; i < len; i++) {
 112		if (rates[i] == 0x0b || rates[i] == 0x16) {
 113			over2 = 1;
 114			break;
 115		}
 116	}
 117
 118	strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
 119
 120	return 0;
 121}
 122
 123
 124static int prism2_ioctl_siwencode(struct net_device *dev,
 125				  struct iw_request_info *info,
 126				  struct iw_point *erq, char *keybuf)
 127{
 128	struct hostap_interface *iface;
 129	local_info_t *local;
 130	int i;
 131	struct lib80211_crypt_data **crypt;
 132
 133	iface = netdev_priv(dev);
 134	local = iface->local;
 135
 136	i = erq->flags & IW_ENCODE_INDEX;
 137	if (i < 1 || i > 4)
 138		i = local->crypt_info.tx_keyidx;
 139	else
 140		i--;
 141	if (i < 0 || i >= WEP_KEYS)
 142		return -EINVAL;
 143
 144	crypt = &local->crypt_info.crypt[i];
 145
 146	if (erq->flags & IW_ENCODE_DISABLED) {
 147		if (*crypt)
 148			lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
 149		goto done;
 150	}
 151
 152	if (*crypt != NULL && (*crypt)->ops != NULL &&
 153	    strcmp((*crypt)->ops->name, "WEP") != 0) {
 154		/* changing to use WEP; deinit previously used algorithm */
 155		lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
 156	}
 157
 158	if (*crypt == NULL) {
 159		struct lib80211_crypt_data *new_crypt;
 160
 161		/* take WEP into use */
 162		new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
 163				GFP_KERNEL);
 164		if (new_crypt == NULL)
 165			return -ENOMEM;
 166		new_crypt->ops = lib80211_get_crypto_ops("WEP");
 167		if (!new_crypt->ops) {
 168			request_module("lib80211_crypt_wep");
 169			new_crypt->ops = lib80211_get_crypto_ops("WEP");
 170		}
 171		if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
 172			new_crypt->priv = new_crypt->ops->init(i);
 173		if (!new_crypt->ops || !new_crypt->priv) {
 174			kfree(new_crypt);
 175			new_crypt = NULL;
 176
 177			printk(KERN_WARNING "%s: could not initialize WEP: "
 178			       "load module hostap_crypt_wep.o\n",
 179			       dev->name);
 180			return -EOPNOTSUPP;
 181		}
 182		*crypt = new_crypt;
 183	}
 184
 185	if (erq->length > 0) {
 186		int len = erq->length <= 5 ? 5 : 13;
 187		int first = 1, j;
 188		if (len > erq->length)
 189			memset(keybuf + erq->length, 0, len - erq->length);
 190		(*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
 191		for (j = 0; j < WEP_KEYS; j++) {
 192			if (j != i && local->crypt_info.crypt[j]) {
 193				first = 0;
 194				break;
 195			}
 196		}
 197		if (first)
 198			local->crypt_info.tx_keyidx = i;
 199	} else {
 200		/* No key data - just set the default TX key index */
 201		local->crypt_info.tx_keyidx = i;
 202	}
 203
 204 done:
 205	local->open_wep = erq->flags & IW_ENCODE_OPEN;
 206
 207	if (hostap_set_encryption(local)) {
 208		printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
 209		return -EINVAL;
 210	}
 211
 212	/* Do not reset port0 if card is in Managed mode since resetting will
 213	 * generate new IEEE 802.11 authentication which may end up in looping
 214	 * with IEEE 802.1X. Prism2 documentation seem to require port reset
 215	 * after WEP configuration. However, keys are apparently changed at
 216	 * least in Managed mode. */
 217	if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
 218		printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
 219		return -EINVAL;
 220	}
 221
 222	return 0;
 223}
 224
 225
 226static int prism2_ioctl_giwencode(struct net_device *dev,
 227				  struct iw_request_info *info,
 228				  struct iw_point *erq, char *key)
 229{
 230	struct hostap_interface *iface;
 231	local_info_t *local;
 232	int i, len;
 233	u16 val;
 234	struct lib80211_crypt_data *crypt;
 235
 236	iface = netdev_priv(dev);
 237	local = iface->local;
 238
 239	i = erq->flags & IW_ENCODE_INDEX;
 240	if (i < 1 || i > 4)
 241		i = local->crypt_info.tx_keyidx;
 242	else
 243		i--;
 244	if (i < 0 || i >= WEP_KEYS)
 245		return -EINVAL;
 246
 247	crypt = local->crypt_info.crypt[i];
 248	erq->flags = i + 1;
 249
 250	if (crypt == NULL || crypt->ops == NULL) {
 251		erq->length = 0;
 252		erq->flags |= IW_ENCODE_DISABLED;
 253		return 0;
 254	}
 255
 256	if (strcmp(crypt->ops->name, "WEP") != 0) {
 257		/* only WEP is supported with wireless extensions, so just
 258		 * report that encryption is used */
 259		erq->length = 0;
 260		erq->flags |= IW_ENCODE_ENABLED;
 261		return 0;
 262	}
 263
 264	/* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
 265	 * the keys from driver buffer */
 266	len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
 267	erq->length = (len >= 0 ? len : 0);
 268
 269	if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
 270	{
 271		printk("CNFWEPFLAGS reading failed\n");
 272		return -EOPNOTSUPP;
 273	}
 274	le16_to_cpus(&val);
 275	if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
 276		erq->flags |= IW_ENCODE_ENABLED;
 277	else
 278		erq->flags |= IW_ENCODE_DISABLED;
 279	if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
 280		erq->flags |= IW_ENCODE_RESTRICTED;
 281	else
 282		erq->flags |= IW_ENCODE_OPEN;
 283
 284	return 0;
 285}
 286
 287
 288static int hostap_set_rate(struct net_device *dev)
 289{
 290	struct hostap_interface *iface;
 291	local_info_t *local;
 292	int ret, basic_rates;
 293
 294	iface = netdev_priv(dev);
 295	local = iface->local;
 296
 297	basic_rates = local->basic_rates & local->tx_rate_control;
 298	if (!basic_rates || basic_rates != local->basic_rates) {
 299		printk(KERN_INFO "%s: updating basic rate set automatically "
 300		       "to match with the new supported rate set\n",
 301		       dev->name);
 302		if (!basic_rates)
 303			basic_rates = local->tx_rate_control;
 304
 305		local->basic_rates = basic_rates;
 306		if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
 307				    basic_rates))
 308			printk(KERN_WARNING "%s: failed to set "
 309			       "cnfBasicRates\n", dev->name);
 310	}
 311
 312	ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
 313			       local->tx_rate_control) ||
 314	       hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
 315			       local->tx_rate_control) ||
 316	       local->func->reset_port(dev));
 317
 318	if (ret) {
 319		printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
 320		       "setting to 0x%x failed\n",
 321		       dev->name, local->tx_rate_control);
 322	}
 323
 324	/* Update TX rate configuration for all STAs based on new operational
 325	 * rate set. */
 326	hostap_update_rates(local);
 327
 328	return ret;
 329}
 330
 331
 332static int prism2_ioctl_siwrate(struct net_device *dev,
 333				struct iw_request_info *info,
 334				struct iw_param *rrq, char *extra)
 335{
 336	struct hostap_interface *iface;
 337	local_info_t *local;
 338
 339	iface = netdev_priv(dev);
 340	local = iface->local;
 341
 342	if (rrq->fixed) {
 343		switch (rrq->value) {
 344		case 11000000:
 345			local->tx_rate_control = HFA384X_RATES_11MBPS;
 346			break;
 347		case 5500000:
 348			local->tx_rate_control = HFA384X_RATES_5MBPS;
 349			break;
 350		case 2000000:
 351			local->tx_rate_control = HFA384X_RATES_2MBPS;
 352			break;
 353		case 1000000:
 354			local->tx_rate_control = HFA384X_RATES_1MBPS;
 355			break;
 356		default:
 357			local->tx_rate_control = HFA384X_RATES_1MBPS |
 358				HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
 359				HFA384X_RATES_11MBPS;
 360			break;
 361		}
 362	} else {
 363		switch (rrq->value) {
 364		case 11000000:
 365			local->tx_rate_control = HFA384X_RATES_1MBPS |
 366				HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
 367				HFA384X_RATES_11MBPS;
 368			break;
 369		case 5500000:
 370			local->tx_rate_control = HFA384X_RATES_1MBPS |
 371				HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
 372			break;
 373		case 2000000:
 374			local->tx_rate_control = HFA384X_RATES_1MBPS |
 375				HFA384X_RATES_2MBPS;
 376			break;
 377		case 1000000:
 378			local->tx_rate_control = HFA384X_RATES_1MBPS;
 379			break;
 380		default:
 381			local->tx_rate_control = HFA384X_RATES_1MBPS |
 382				HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
 383				HFA384X_RATES_11MBPS;
 384			break;
 385		}
 386	}
 387
 388	return hostap_set_rate(dev);
 389}
 390
 391
 392static int prism2_ioctl_giwrate(struct net_device *dev,
 393				struct iw_request_info *info,
 394				struct iw_param *rrq, char *extra)
 395{
 396	u16 val;
 397	struct hostap_interface *iface;
 398	local_info_t *local;
 399	int ret = 0;
 400
 401	iface = netdev_priv(dev);
 402	local = iface->local;
 403
 404	if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
 405	    0)
 406		return -EINVAL;
 407
 408	if ((val & 0x1) && (val > 1))
 409		rrq->fixed = 0;
 410	else
 411		rrq->fixed = 1;
 412
 413	if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
 414	    !local->fw_tx_rate_control) {
 415		/* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
 416		 * Host AP mode, so use the recorded TX rate of the last sent
 417		 * frame */
 418		rrq->value = local->ap->last_tx_rate > 0 ?
 419			local->ap->last_tx_rate * 100000 : 11000000;
 420		return 0;
 421	}
 422
 423	if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
 424	    0)
 425		return -EINVAL;
 426
 427	switch (val) {
 428	case HFA384X_RATES_1MBPS:
 429		rrq->value = 1000000;
 430		break;
 431	case HFA384X_RATES_2MBPS:
 432		rrq->value = 2000000;
 433		break;
 434	case HFA384X_RATES_5MBPS:
 435		rrq->value = 5500000;
 436		break;
 437	case HFA384X_RATES_11MBPS:
 438		rrq->value = 11000000;
 439		break;
 440	default:
 441		/* should not happen */
 442		rrq->value = 11000000;
 443		ret = -EINVAL;
 444		break;
 445	}
 446
 447	return ret;
 448}
 449
 450
 451static int prism2_ioctl_siwsens(struct net_device *dev,
 452				struct iw_request_info *info,
 453				struct iw_param *sens, char *extra)
 454{
 455	struct hostap_interface *iface;
 456	local_info_t *local;
 457
 458	iface = netdev_priv(dev);
 459	local = iface->local;
 460
 461	/* Set the desired AP density */
 462	if (sens->value < 1 || sens->value > 3)
 463		return -EINVAL;
 464
 465	if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
 466	    local->func->reset_port(dev))
 467		return -EINVAL;
 468
 469	return 0;
 470}
 471
 472static int prism2_ioctl_giwsens(struct net_device *dev,
 473				struct iw_request_info *info,
 474				struct iw_param *sens, char *extra)
 475{
 476	struct hostap_interface *iface;
 477	local_info_t *local;
 478	__le16 val;
 479
 480	iface = netdev_priv(dev);
 481	local = iface->local;
 482
 483	/* Get the current AP density */
 484	if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
 485	    0)
 486		return -EINVAL;
 487
 488	sens->value = le16_to_cpu(val);
 489	sens->fixed = 1;
 490
 491	return 0;
 492}
 493
 494
 495/* Deprecated in new wireless extension API */
 496static int prism2_ioctl_giwaplist(struct net_device *dev,
 497				  struct iw_request_info *info,
 498				  struct iw_point *data, char *extra)
 499{
 500	struct hostap_interface *iface;
 501	local_info_t *local;
 502	struct sockaddr *addr;
 503	struct iw_quality *qual;
 504
 505	iface = netdev_priv(dev);
 506	local = iface->local;
 507
 508	if (local->iw_mode != IW_MODE_MASTER) {
 509		printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
 510		       "in Host AP mode\n");
 511		data->length = 0;
 512		return -EOPNOTSUPP;
 513	}
 514
 515	addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
 516	qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
 517	if (addr == NULL || qual == NULL) {
 518		kfree(addr);
 519		kfree(qual);
 520		data->length = 0;
 521		return -ENOMEM;
 522	}
 523
 524	data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
 525
 526	memcpy(extra, addr, sizeof(struct sockaddr) * data->length);
 527	data->flags = 1; /* has quality information */
 528	memcpy(extra + sizeof(struct sockaddr) * data->length, qual,
 529	       sizeof(struct iw_quality) * data->length);
 530
 531	kfree(addr);
 532	kfree(qual);
 533	return 0;
 534}
 535
 536
 537static int prism2_ioctl_siwrts(struct net_device *dev,
 538			       struct iw_request_info *info,
 539			       struct iw_param *rts, char *extra)
 540{
 541	struct hostap_interface *iface;
 542	local_info_t *local;
 543	__le16 val;
 544
 545	iface = netdev_priv(dev);
 546	local = iface->local;
 547
 548	if (rts->disabled)
 549		val = cpu_to_le16(2347);
 550	else if (rts->value < 0 || rts->value > 2347)
 551		return -EINVAL;
 552	else
 553		val = cpu_to_le16(rts->value);
 554
 555	if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) ||
 556	    local->func->reset_port(dev))
 557		return -EINVAL;
 558
 559	local->rts_threshold = rts->value;
 560
 561	return 0;
 562}
 563
 564static int prism2_ioctl_giwrts(struct net_device *dev,
 565			       struct iw_request_info *info,
 566			       struct iw_param *rts, char *extra)
 567{
 568	struct hostap_interface *iface;
 569	local_info_t *local;
 570	__le16 val;
 571
 572	iface = netdev_priv(dev);
 573	local = iface->local;
 574
 575	if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) <
 576	    0)
 577		return -EINVAL;
 578
 579	rts->value = le16_to_cpu(val);
 580	rts->disabled = (rts->value == 2347);
 581	rts->fixed = 1;
 582
 583	return 0;
 584}
 585
 586
 587static int prism2_ioctl_siwfrag(struct net_device *dev,
 588				struct iw_request_info *info,
 589				struct iw_param *rts, char *extra)
 590{
 591	struct hostap_interface *iface;
 592	local_info_t *local;
 593	__le16 val;
 594
 595	iface = netdev_priv(dev);
 596	local = iface->local;
 597
 598	if (rts->disabled)
 599		val = cpu_to_le16(2346);
 600	else if (rts->value < 256 || rts->value > 2346)
 601		return -EINVAL;
 602	else
 603		val = cpu_to_le16(rts->value & ~0x1); /* even numbers only */
 604
 605	local->fragm_threshold = rts->value & ~0x1;
 606	if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val,
 607				 2)
 608	    || local->func->reset_port(dev))
 609		return -EINVAL;
 610
 611	return 0;
 612}
 613
 614static int prism2_ioctl_giwfrag(struct net_device *dev,
 615				struct iw_request_info *info,
 616				struct iw_param *rts, char *extra)
 617{
 618	struct hostap_interface *iface;
 619	local_info_t *local;
 620	__le16 val;
 621
 622	iface = netdev_priv(dev);
 623	local = iface->local;
 624
 625	if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
 626				 &val, 2, 1) < 0)
 627		return -EINVAL;
 628
 629	rts->value = le16_to_cpu(val);
 630	rts->disabled = (rts->value == 2346);
 631	rts->fixed = 1;
 632
 633	return 0;
 634}
 635
 636
 637#ifndef PRISM2_NO_STATION_MODES
 638static int hostap_join_ap(struct net_device *dev)
 639{
 640	struct hostap_interface *iface;
 641	local_info_t *local;
 642	struct hfa384x_join_request req;
 643	unsigned long flags;
 644	int i;
 645	struct hfa384x_hostscan_result *entry;
 646
 647	iface = netdev_priv(dev);
 648	local = iface->local;
 649
 650	memcpy(req.bssid, local->preferred_ap, ETH_ALEN);
 651	req.channel = 0;
 652
 653	spin_lock_irqsave(&local->lock, flags);
 654	for (i = 0; i < local->last_scan_results_count; i++) {
 655		if (!local->last_scan_results)
 656			break;
 657		entry = &local->last_scan_results[i];
 658		if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) {
 659			req.channel = entry->chid;
 660			break;
 661		}
 662	}
 663	spin_unlock_irqrestore(&local->lock, flags);
 664
 665	if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
 666				 sizeof(req))) {
 667		printk(KERN_DEBUG "%s: JoinRequest %pM failed\n",
 668		       dev->name, local->preferred_ap);
 669		return -1;
 670	}
 671
 672	printk(KERN_DEBUG "%s: Trying to join BSSID %pM\n",
 673	       dev->name, local->preferred_ap);
 674
 675	return 0;
 676}
 677#endif /* PRISM2_NO_STATION_MODES */
 678
 679
 680static int prism2_ioctl_siwap(struct net_device *dev,
 681			      struct iw_request_info *info,
 682			      struct sockaddr *ap_addr, char *extra)
 683{
 684#ifdef PRISM2_NO_STATION_MODES
 685	return -EOPNOTSUPP;
 686#else /* PRISM2_NO_STATION_MODES */
 687	struct hostap_interface *iface;
 688	local_info_t *local;
 689
 690	iface = netdev_priv(dev);
 691	local = iface->local;
 692
 693	memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN);
 694
 695	if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) {
 696		struct hfa384x_scan_request scan_req;
 697		memset(&scan_req, 0, sizeof(scan_req));
 698		scan_req.channel_list = cpu_to_le16(0x3fff);
 699		scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
 700		if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST,
 701					 &scan_req, sizeof(scan_req))) {
 702			printk(KERN_DEBUG "%s: ScanResults request failed - "
 703			       "preferred AP delayed to next unsolicited "
 704			       "scan\n", dev->name);
 705		}
 706	} else if (local->host_roaming == 2 &&
 707		   local->iw_mode == IW_MODE_INFRA) {
 708		if (hostap_join_ap(dev))
 709			return -EINVAL;
 710	} else {
 711		printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only "
 712		       "in Managed mode when host_roaming is enabled\n",
 713		       dev->name);
 714	}
 715
 716	return 0;
 717#endif /* PRISM2_NO_STATION_MODES */
 718}
 719
 720static int prism2_ioctl_giwap(struct net_device *dev,
 721			      struct iw_request_info *info,
 722			      struct sockaddr *ap_addr, char *extra)
 723{
 724	struct hostap_interface *iface;
 725	local_info_t *local;
 726
 727	iface = netdev_priv(dev);
 728	local = iface->local;
 729
 730	ap_addr->sa_family = ARPHRD_ETHER;
 731	switch (iface->type) {
 732	case HOSTAP_INTERFACE_AP:
 733		memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN);
 734		break;
 735	case HOSTAP_INTERFACE_STA:
 736		memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN);
 737		break;
 738	case HOSTAP_INTERFACE_WDS:
 739		memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN);
 740		break;
 741	default:
 742		if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID,
 743					 &ap_addr->sa_data, ETH_ALEN, 1) < 0)
 744			return -EOPNOTSUPP;
 745
 746		/* local->bssid is also updated in LinkStatus handler when in
 747		 * station mode */
 748		memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN);
 749		break;
 750	}
 751
 752	return 0;
 753}
 754
 755
 756static int prism2_ioctl_siwnickn(struct net_device *dev,
 757				 struct iw_request_info *info,
 758				 struct iw_point *data, char *nickname)
 759{
 760	struct hostap_interface *iface;
 761	local_info_t *local;
 762
 763	iface = netdev_priv(dev);
 764	local = iface->local;
 765
 766	memset(local->name, 0, sizeof(local->name));
 767	memcpy(local->name, nickname, data->length);
 768	local->name_set = 1;
 769
 770	if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) ||
 771	    local->func->reset_port(dev))
 772		return -EINVAL;
 773
 774	return 0;
 775}
 776
 777static int prism2_ioctl_giwnickn(struct net_device *dev,
 778				 struct iw_request_info *info,
 779				 struct iw_point *data, char *nickname)
 780{
 781	struct hostap_interface *iface;
 782	local_info_t *local;
 783	int len;
 784	char name[MAX_NAME_LEN + 3];
 785	u16 val;
 786
 787	iface = netdev_priv(dev);
 788	local = iface->local;
 789
 790	len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME,
 791				   &name, MAX_NAME_LEN + 2, 0);
 792	val = le16_to_cpu(*(__le16 *) name);
 793	if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN)
 794		return -EOPNOTSUPP;
 795
 796	name[val + 2] = '\0';
 797	data->length = val + 1;
 798	memcpy(nickname, name + 2, val + 1);
 799
 800	return 0;
 801}
 802
 803
 804static int prism2_ioctl_siwfreq(struct net_device *dev,
 805				struct iw_request_info *info,
 806				struct iw_freq *freq, char *extra)
 807{
 808	struct hostap_interface *iface;
 809	local_info_t *local;
 810
 811	iface = netdev_priv(dev);
 812	local = iface->local;
 813
 814	/* freq => chan. */
 815	if (freq->e == 1 &&
 816	    freq->m / 100000 >= freq_list[0] &&
 817	    freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) {
 818		int ch;
 819		int fr = freq->m / 100000;
 820		for (ch = 0; ch < FREQ_COUNT; ch++) {
 821			if (fr == freq_list[ch]) {
 822				freq->e = 0;
 823				freq->m = ch + 1;
 824				break;
 825			}
 826		}
 827	}
 828
 829	if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT ||
 830	    !(local->channel_mask & (1 << (freq->m - 1))))
 831		return -EINVAL;
 832
 833	local->channel = freq->m; /* channel is used in prism2_setup_rids() */
 834	if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) ||
 835	    local->func->reset_port(dev))
 836		return -EINVAL;
 837
 838	return 0;
 839}
 840
 841static int prism2_ioctl_giwfreq(struct net_device *dev,
 842				struct iw_request_info *info,
 843				struct iw_freq *freq, char *extra)
 844{
 845	struct hostap_interface *iface;
 846	local_info_t *local;
 847	u16 val;
 848
 849	iface = netdev_priv(dev);
 850	local = iface->local;
 851
 852	if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) <
 853	    0)
 854		return -EINVAL;
 855
 856	le16_to_cpus(&val);
 857	if (val < 1 || val > FREQ_COUNT)
 858		return -EINVAL;
 859
 860	freq->m = freq_list[val - 1] * 100000;
 861	freq->e = 1;
 862
 863	return 0;
 864}
 865
 866
 867static void hostap_monitor_set_type(local_info_t *local)
 868{
 869	struct net_device *dev = local->ddev;
 870
 871	if (dev == NULL)
 872		return;
 873
 874	if (local->monitor_type == PRISM2_MONITOR_PRISM ||
 875	    local->monitor_type == PRISM2_MONITOR_CAPHDR) {
 876		dev->type = ARPHRD_IEEE80211_PRISM;
 877	} else if (local->monitor_type == PRISM2_MONITOR_RADIOTAP) {
 878		dev->type = ARPHRD_IEEE80211_RADIOTAP;
 879	} else {
 880		dev->type = ARPHRD_IEEE80211;
 881	}
 882}
 883
 884
 885static int prism2_ioctl_siwessid(struct net_device *dev,
 886				 struct iw_request_info *info,
 887				 struct iw_point *data, char *ssid)
 888{
 889	struct hostap_interface *iface;
 890	local_info_t *local;
 891
 892	iface = netdev_priv(dev);
 893	local = iface->local;
 894
 895	if (iface->type == HOSTAP_INTERFACE_WDS)
 896		return -EOPNOTSUPP;
 897
 898	if (data->flags == 0)
 899		ssid[0] = '\0'; /* ANY */
 900
 901	if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') {
 902		/* Setting SSID to empty string seems to kill the card in
 903		 * Host AP mode */
 904		printk(KERN_DEBUG "%s: Host AP mode does not support "
 905		       "'Any' essid\n", dev->name);
 906		return -EINVAL;
 907	}
 908
 909	memcpy(local->essid, ssid, data->length);
 910	local->essid[data->length] = '\0';
 911
 912	if ((!local->fw_ap &&
 913	     hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid))
 914	    || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) ||
 915	    local->func->reset_port(dev))
 916		return -EINVAL;
 917
 918	return 0;
 919}
 920
 921static int prism2_ioctl_giwessid(struct net_device *dev,
 922				 struct iw_request_info *info,
 923				 struct iw_point *data, char *essid)
 924{
 925	struct hostap_interface *iface;
 926	local_info_t *local;
 927	u16 val;
 928
 929	iface = netdev_priv(dev);
 930	local = iface->local;
 931
 932	if (iface->type == HOSTAP_INTERFACE_WDS)
 933		return -EOPNOTSUPP;
 934
 935	data->flags = 1; /* active */
 936	if (local->iw_mode == IW_MODE_MASTER) {
 937		data->length = strlen(local->essid);
 938		memcpy(essid, local->essid, IW_ESSID_MAX_SIZE);
 939	} else {
 940		int len;
 941		char ssid[MAX_SSID_LEN + 2];
 942		memset(ssid, 0, sizeof(ssid));
 943		len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID,
 944					   &ssid, MAX_SSID_LEN + 2, 0);
 945		val = le16_to_cpu(*(__le16 *) ssid);
 946		if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) {
 947			return -EOPNOTSUPP;
 948		}
 949		data->length = val;
 950		memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE);
 951	}
 952
 953	return 0;
 954}
 955
 956
 957static int prism2_ioctl_giwrange(struct net_device *dev,
 958				 struct iw_request_info *info,
 959				 struct iw_point *data, char *extra)
 960{
 961	struct hostap_interface *iface;
 962	local_info_t *local;
 963	struct iw_range *range = (struct iw_range *) extra;
 964	u8 rates[10];
 965	u16 val;
 966	int i, len, over2;
 967
 968	iface = netdev_priv(dev);
 969	local = iface->local;
 970
 971	data->length = sizeof(struct iw_range);
 972	memset(range, 0, sizeof(struct iw_range));
 973
 974	/* TODO: could fill num_txpower and txpower array with
 975	 * something; however, there are 128 different values.. */
 976
 977	range->txpower_capa = IW_TXPOW_DBM;
 978
 979	if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC)
 980	{
 981		range->min_pmp = 1 * 1024;
 982		range->max_pmp = 65535 * 1024;
 983		range->min_pmt = 1 * 1024;
 984		range->max_pmt = 1000 * 1024;
 985		range->pmp_flags = IW_POWER_PERIOD;
 986		range->pmt_flags = IW_POWER_TIMEOUT;
 987		range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
 988			IW_POWER_UNICAST_R | IW_POWER_ALL_R;
 989	}
 990
 991	range->we_version_compiled = WIRELESS_EXT;
 992	range->we_version_source = 18;
 993
 994	range->retry_capa = IW_RETRY_LIMIT;
 995	range->retry_flags = IW_RETRY_LIMIT;
 996	range->min_retry = 0;
 997	range->max_retry = 255;
 998
 999	range->num_channels = FREQ_COUNT;
1000
1001	val = 0;
1002	for (i = 0; i < FREQ_COUNT; i++) {
1003		if (local->channel_mask & (1 << i)) {
1004			range->freq[val].i = i + 1;
1005			range->freq[val].m = freq_list[i] * 100000;
1006			range->freq[val].e = 1;
1007			val++;
1008		}
1009		if (val == IW_MAX_FREQUENCIES)
1010			break;
1011	}
1012	range->num_frequency = val;
1013
1014	if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1015		range->max_qual.qual = 70; /* what is correct max? This was not
1016					    * documented exactly. At least
1017					    * 69 has been observed. */
1018		range->max_qual.level = 0; /* dB */
1019		range->max_qual.noise = 0; /* dB */
1020
1021		/* What would be suitable values for "average/typical" qual? */
1022		range->avg_qual.qual = 20;
1023		range->avg_qual.level = -60;
1024		range->avg_qual.noise = -95;
1025	} else {
1026		range->max_qual.qual = 92; /* 0 .. 92 */
1027		range->max_qual.level = 154; /* 27 .. 154 */
1028		range->max_qual.noise = 154; /* 27 .. 154 */
1029	}
1030	range->sensitivity = 3;
1031
1032	range->max_encoding_tokens = WEP_KEYS;
1033	range->num_encoding_sizes = 2;
1034	range->encoding_size[0] = 5;
1035	range->encoding_size[1] = 13;
1036
1037	over2 = 0;
1038	len = prism2_get_datarates(dev, rates);
1039	range->num_bitrates = 0;
1040	for (i = 0; i < len; i++) {
1041		if (range->num_bitrates < IW_MAX_BITRATES) {
1042			range->bitrate[range->num_bitrates] =
1043				rates[i] * 500000;
1044			range->num_bitrates++;
1045		}
1046		if (rates[i] == 0x0b || rates[i] == 0x16)
1047			over2 = 1;
1048	}
1049	/* estimated maximum TCP throughput values (bps) */
1050	range->throughput = over2 ? 5500000 : 1500000;
1051
1052	range->min_rts = 0;
1053	range->max_rts = 2347;
1054	range->min_frag = 256;
1055	range->max_frag = 2346;
1056
1057	/* Event capability (kernel + driver) */
1058	range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1059				IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
1060				IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1061				IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1062	range->event_capa[1] = IW_EVENT_CAPA_K_1;
1063	range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
1064				IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1065				IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
1066				IW_EVENT_CAPA_MASK(IWEVEXPIRED));
1067
1068	range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1069		IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1070
1071	if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1072		range->scan_capa = IW_SCAN_CAPA_ESSID;
1073
1074	return 0;
1075}
1076
1077
1078static int hostap_monitor_mode_enable(local_info_t *local)
1079{
1080	struct net_device *dev = local->dev;
1081
1082	printk(KERN_DEBUG "Enabling monitor mode\n");
1083	hostap_monitor_set_type(local);
1084
1085	if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1086			    HFA384X_PORTTYPE_PSEUDO_IBSS)) {
1087		printk(KERN_DEBUG "Port type setting for monitor mode "
1088		       "failed\n");
1089		return -EOPNOTSUPP;
1090	}
1091
1092	/* Host decrypt is needed to get the IV and ICV fields;
1093	 * however, monitor mode seems to remove WEP flag from frame
1094	 * control field */
1095	if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS,
1096			    HFA384X_WEPFLAGS_HOSTENCRYPT |
1097			    HFA384X_WEPFLAGS_HOSTDECRYPT)) {
1098		printk(KERN_DEBUG "WEP flags setting failed\n");
1099		return -EOPNOTSUPP;
1100	}
1101
1102	if (local->func->reset_port(dev) ||
1103	    local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1104			     (HFA384X_TEST_MONITOR << 8),
1105			     0, NULL, NULL)) {
1106		printk(KERN_DEBUG "Setting monitor mode failed\n");
1107		return -EOPNOTSUPP;
1108	}
1109
1110	return 0;
1111}
1112
1113
1114static int hostap_monitor_mode_disable(local_info_t *local)
1115{
1116	struct net_device *dev = local->ddev;
1117
1118	if (dev == NULL)
1119		return -1;
1120
1121	printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name);
1122	dev->type = ARPHRD_ETHER;
1123
1124	if (local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1125			     (HFA384X_TEST_STOP << 8),
1126			     0, NULL, NULL))
1127		return -1;
1128	return hostap_set_encryption(local);
1129}
1130
1131
1132static int prism2_ioctl_siwmode(struct net_device *dev,
1133				struct iw_request_info *info,
1134				__u32 *mode, char *extra)
1135{
1136	struct hostap_interface *iface;
1137	local_info_t *local;
1138	int double_reset = 0;
1139
1140	iface = netdev_priv(dev);
1141	local = iface->local;
1142
1143	if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA &&
1144	    *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT &&
1145	    *mode != IW_MODE_MONITOR)
1146		return -EOPNOTSUPP;
1147
1148#ifdef PRISM2_NO_STATION_MODES
1149	if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA)
1150		return -EOPNOTSUPP;
1151#endif /* PRISM2_NO_STATION_MODES */
1152
1153	if (*mode == local->iw_mode)
1154		return 0;
1155
1156	if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') {
1157		printk(KERN_WARNING "%s: empty SSID not allowed in Master "
1158		       "mode\n", dev->name);
1159		return -EINVAL;
1160	}
1161
1162	if (local->iw_mode == IW_MODE_MONITOR)
1163		hostap_monitor_mode_disable(local);
1164
1165	if ((local->iw_mode == IW_MODE_ADHOC ||
1166	     local->iw_mode == IW_MODE_MONITOR) && *mode == IW_MODE_MASTER) {
1167		/* There seems to be a firmware bug in at least STA f/w v1.5.6
1168		 * that leaves beacon frames to use IBSS type when moving from
1169		 * IBSS to Host AP mode. Doing double Port0 reset seems to be
1170		 * enough to workaround this. */
1171		double_reset = 1;
1172	}
1173
1174	printk(KERN_DEBUG "prism2: %s: operating mode changed "
1175	       "%d -> %d\n", dev->name, local->iw_mode, *mode);
1176	local->iw_mode = *mode;
1177
1178	if (local->iw_mode == IW_MODE_MONITOR)
1179		hostap_monitor_mode_enable(local);
1180	else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
1181		 !local->fw_encrypt_ok) {
1182		printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
1183		       "a workaround for firmware bug in Host AP mode WEP\n",
1184		       dev->name);
1185		local->host_encrypt = 1;
1186	}
1187
1188	if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1189			    hostap_get_porttype(local)))
1190		return -EOPNOTSUPP;
1191
1192	if (local->func->reset_port(dev))
1193		return -EINVAL;
1194	if (double_reset && local->func->reset_port(dev))
1195		return -EINVAL;
1196
1197	if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
1198	{
1199		/* netif_carrier is used only in client modes for now, so make
1200		 * sure carrier is on when moving to non-client modes. */
1201		netif_carrier_on(local->dev);
1202		netif_carrier_on(local->ddev);
1203	}
1204	return 0;
1205}
1206
1207
1208static int prism2_ioctl_giwmode(struct net_device *dev,
1209				struct iw_request_info *info,
1210				__u32 *mode, char *extra)
1211{
1212	struct hostap_interface *iface;
1213	local_info_t *local;
1214
1215	iface = netdev_priv(dev);
1216	local = iface->local;
1217
1218	switch (iface->type) {
1219	case HOSTAP_INTERFACE_STA:
1220		*mode = IW_MODE_INFRA;
1221		break;
1222	case HOSTAP_INTERFACE_WDS:
1223		*mode = IW_MODE_REPEAT;
1224		break;
1225	default:
1226		*mode = local->iw_mode;
1227		break;
1228	}
1229	return 0;
1230}
1231
1232
1233static int prism2_ioctl_siwpower(struct net_device *dev,
1234				 struct iw_request_info *info,
1235				 struct iw_param *wrq, char *extra)
1236{
1237#ifdef PRISM2_NO_STATION_MODES
1238	return -EOPNOTSUPP;
1239#else /* PRISM2_NO_STATION_MODES */
1240	int ret = 0;
1241
1242	if (wrq->disabled)
1243		return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
1244
1245	switch (wrq->flags & IW_POWER_MODE) {
1246	case IW_POWER_UNICAST_R:
1247		ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
1248		if (ret)
1249			return ret;
1250		ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1251		if (ret)
1252			return ret;
1253		break;
1254	case IW_POWER_ALL_R:
1255		ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
1256		if (ret)
1257			return ret;
1258		ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1259		if (ret)
1260			return ret;
1261		break;
1262	case IW_POWER_ON:
1263		break;
1264	default:
1265		return -EINVAL;
1266	}
1267
1268	if (wrq->flags & IW_POWER_TIMEOUT) {
1269		ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1270		if (ret)
1271			return ret;
1272		ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
1273				      wrq->value / 1024);
1274		if (ret)
1275			return ret;
1276	}
1277	if (wrq->flags & IW_POWER_PERIOD) {
1278		ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1279		if (ret)
1280			return ret;
1281		ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1282				      wrq->value / 1024);
1283		if (ret)
1284			return ret;
1285	}
1286
1287	return ret;
1288#endif /* PRISM2_NO_STATION_MODES */
1289}
1290
1291
1292static int prism2_ioctl_giwpower(struct net_device *dev,
1293				 struct iw_request_info *info,
1294				 struct iw_param *rrq, char *extra)
1295{
1296#ifdef PRISM2_NO_STATION_MODES
1297	return -EOPNOTSUPP;
1298#else /* PRISM2_NO_STATION_MODES */
1299	struct hostap_interface *iface;
1300	local_info_t *local;
1301	__le16 enable, mcast;
1302
1303	iface = netdev_priv(dev);
1304	local = iface->local;
1305
1306	if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
1307	    < 0)
1308		return -EINVAL;
1309
1310	if (!le16_to_cpu(enable)) {
1311		rrq->disabled = 1;
1312		return 0;
1313	}
1314
1315	rrq->disabled = 0;
1316
1317	if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1318		__le16 timeout;
1319		if (local->func->get_rid(dev,
1320					 HFA384X_RID_CNFPMHOLDOVERDURATION,
1321					 &timeout, 2, 1) < 0)
1322			return -EINVAL;
1323
1324		rrq->flags = IW_POWER_TIMEOUT;
1325		rrq->value = le16_to_cpu(timeout) * 1024;
1326	} else {
1327		__le16 period;
1328		if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1329					 &period, 2, 1) < 0)
1330			return -EINVAL;
1331
1332		rrq->flags = IW_POWER_PERIOD;
1333		rrq->value = le16_to_cpu(period) * 1024;
1334	}
1335
1336	if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
1337				 2, 1) < 0)
1338		return -EINVAL;
1339
1340	if (le16_to_cpu(mcast))
1341		rrq->flags |= IW_POWER_ALL_R;
1342	else
1343		rrq->flags |= IW_POWER_UNICAST_R;
1344
1345	return 0;
1346#endif /* PRISM2_NO_STATION_MODES */
1347}
1348
1349
1350static int prism2_ioctl_siwretry(struct net_device *dev,
1351				 struct iw_request_info *info,
1352				 struct iw_param *rrq, char *extra)
1353{
1354	struct hostap_interface *iface;
1355	local_info_t *local;
1356
1357	iface = netdev_priv(dev);
1358	local = iface->local;
1359
1360	if (rrq->disabled)
1361		return -EINVAL;
1362
1363	/* setting retry limits is not supported with the current station
1364	 * firmware code; simulate this with alternative retry count for now */
1365	if (rrq->flags == IW_RETRY_LIMIT) {
1366		if (rrq->value < 0) {
1367			/* disable manual retry count setting and use firmware
1368			 * defaults */
1369			local->manual_retry_count = -1;
1370			local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
1371		} else {
1372			if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1373					    rrq->value)) {
1374				printk(KERN_DEBUG "%s: Alternate retry count "
1375				       "setting to %d failed\n",
1376				       dev->name, rrq->value);
1377				return -EOPNOTSUPP;
1378			}
1379
1380			local->manual_retry_count = rrq->value;
1381			local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
1382		}
1383		return 0;
1384	}
1385
1386	return -EOPNOTSUPP;
1387
1388#if 0
1389	/* what could be done, if firmware would support this.. */
1390
1391	if (rrq->flags & IW_RETRY_LIMIT) {
1392		if (rrq->flags & IW_RETRY_LONG)
1393			HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1394		else if (rrq->flags & IW_RETRY_SHORT)
1395			HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1396		else {
1397			HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1398			HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1399		}
1400
1401	}
1402
1403	if (rrq->flags & IW_RETRY_LIFETIME) {
1404		HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
1405	}
1406
1407	return 0;
1408#endif /* 0 */
1409}
1410
1411static int prism2_ioctl_giwretry(struct net_device *dev,
1412				 struct iw_request_info *info,
1413				 struct iw_param *rrq, char *extra)
1414{
1415	struct hostap_interface *iface;
1416	local_info_t *local;
1417	__le16 shortretry, longretry, lifetime, altretry;
1418
1419	iface = netdev_priv(dev);
1420	local = iface->local;
1421
1422	if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
1423				 2, 1) < 0 ||
1424	    local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
1425				 2, 1) < 0 ||
1426	    local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
1427				 &lifetime, 2, 1) < 0)
1428		return -EINVAL;
1429
1430	rrq->disabled = 0;
1431
1432	if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1433		rrq->flags = IW_RETRY_LIFETIME;
1434		rrq->value = le16_to_cpu(lifetime) * 1024;
1435	} else {
1436		if (local->manual_retry_count >= 0) {
1437			rrq->flags = IW_RETRY_LIMIT;
1438			if (local->func->get_rid(dev,
1439						 HFA384X_RID_CNFALTRETRYCOUNT,
1440						 &altretry, 2, 1) >= 0)
1441				rrq->value = le16_to_cpu(altretry);
1442			else
1443				rrq->value = local->manual_retry_count;
1444		} else if ((rrq->flags & IW_RETRY_LONG)) {
1445			rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1446			rrq->value = le16_to_cpu(longretry);
1447		} else {
1448			rrq->flags = IW_RETRY_LIMIT;
1449			rrq->value = le16_to_cpu(shortretry);
1450			if (shortretry != longretry)
1451				rrq->flags |= IW_RETRY_SHORT;
1452		}
1453	}
1454	return 0;
1455}
1456
1457
1458/* Note! This TX power controlling is experimental and should not be used in
1459 * production use. It just sets raw power register and does not use any kind of
1460 * feedback information from the measured TX power (CR58). This is now
1461 * commented out to make sure that it is not used by accident. TX power
1462 * configuration will be enabled again after proper algorithm using feedback
1463 * has been implemented. */
1464
1465#ifdef RAW_TXPOWER_SETTING
1466/* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
1467 * This version assumes following mapping:
1468 * CR31 is 7-bit value with -64 to +63 range.
1469 * -64 is mapped into +20dBm and +63 into -43dBm.
1470 * This is certainly not an exact mapping for every card, but at least
1471 * increasing dBm value should correspond to increasing TX power.
1472 */
1473
1474static int prism2_txpower_hfa386x_to_dBm(u16 val)
1475{
1476	signed char tmp;
1477
1478	if (val > 255)
1479		val = 255;
1480
1481	tmp = val;
1482	tmp >>= 2;
1483
1484	return -12 - tmp;
1485}
1486
1487static u16 prism2_txpower_dBm_to_hfa386x(int val)
1488{
1489	signed char tmp;
1490
1491	if (val > 20)
1492		return 128;
1493	else if (val < -43)
1494		return 127;
1495
1496	tmp = val;
1497	tmp = -12 - tmp;
1498	tmp <<= 2;
1499
1500	return (unsigned char) tmp;
1501}
1502#endif /* RAW_TXPOWER_SETTING */
1503
1504
1505static int prism2_ioctl_siwtxpow(struct net_device *dev,
1506				 struct iw_request_info *info,
1507				 struct iw_param *rrq, char *extra)
1508{
1509	struct hostap_interface *iface;
1510	local_info_t *local;
1511#ifdef RAW_TXPOWER_SETTING
1512	char *tmp;
1513#endif
1514	u16 val;
1515	int ret = 0;
1516
1517	iface = netdev_priv(dev);
1518	local = iface->local;
1519
1520	if (rrq->disabled) {
1521		if (local->txpower_type != PRISM2_TXPOWER_OFF) {
1522			val = 0xff; /* use all standby and sleep modes */
1523			ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1524					       HFA386X_CR_A_D_TEST_MODES2,
1525					       &val, NULL);
1526			printk(KERN_DEBUG "%s: Turning radio off: %s\n",
1527			       dev->name, ret ? "failed" : "OK");
1528			local->txpower_type = PRISM2_TXPOWER_OFF;
1529		}
1530		return (ret ? -EOPNOTSUPP : 0);
1531	}
1532
1533	if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1534		val = 0; /* disable all standby and sleep modes */
1535		ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1536				       HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
1537		printk(KERN_DEBUG "%s: Turning radio on: %s\n",
1538		       dev->name, ret ? "failed" : "OK");
1539		local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
1540	}
1541
1542#ifdef RAW_TXPOWER_SETTING
1543	if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
1544		printk(KERN_DEBUG "Setting ALC on\n");
1545		val = HFA384X_TEST_CFG_BIT_ALC;
1546		local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1547				 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
1548		local->txpower_type = PRISM2_TXPOWER_AUTO;
1549		return 0;
1550	}
1551
1552	if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
1553		printk(KERN_DEBUG "Setting ALC off\n");
1554		val = HFA384X_TEST_CFG_BIT_ALC;
1555		local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1556				 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
1557			local->txpower_type = PRISM2_TXPOWER_FIXED;
1558	}
1559
1560	if (rrq->flags == IW_TXPOW_DBM)
1561		tmp = "dBm";
1562	else if (rrq->flags == IW_TXPOW_MWATT)
1563		tmp = "mW";
1564	else
1565		tmp = "UNKNOWN";
1566	printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
1567
1568	if (rrq->flags != IW_TXPOW_DBM) {
1569		printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
1570		return -EOPNOTSUPP;
1571	}
1572
1573	local->txpower = rrq->value;
1574	val = prism2_txpower_dBm_to_hfa386x(local->txpower);
1575	if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1576			     HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
1577		ret = -EOPNOTSUPP;
1578#else /* RAW_TXPOWER_SETTING */
1579	if (rrq->fixed)
1580		ret = -EOPNOTSUPP;
1581#endif /* RAW_TXPOWER_SETTING */
1582
1583	return ret;
1584}
1585
1586static int prism2_ioctl_giwtxpow(struct net_device *dev,
1587				 struct iw_request_info *info,
1588				 struct iw_param *rrq, char *extra)
1589{
1590#ifdef RAW_TXPOWER_SETTING
1591	struct hostap_interface *iface;
1592	local_info_t *local;
1593	u16 resp0;
1594
1595	iface = netdev_priv(dev);
1596	local = iface->local;
1597
1598	rrq->flags = IW_TXPOW_DBM;
1599	rrq->disabled = 0;
1600	rrq->fixed = 0;
1601
1602	if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
1603		if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
1604				     HFA386X_CR_MANUAL_TX_POWER,
1605				     NULL, &resp0) == 0) {
1606			rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
1607		} else {
1608			/* Could not get real txpower; guess 15 dBm */
1609			rrq->value = 15;
1610		}
1611	} else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1612		rrq->value = 0;
1613		rrq->disabled = 1;
1614	} else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
1615		rrq->value = local->txpower;
1616		rrq->fixed = 1;
1617	} else {
1618		printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
1619		       local->txpower_type);
1620	}
1621	return 0;
1622#else /* RAW_TXPOWER_SETTING */
1623	return -EOPNOTSUPP;
1624#endif /* RAW_TXPOWER_SETTING */
1625}
1626
1627
1628#ifndef PRISM2_NO_STATION_MODES
1629
1630/* HostScan request works with and without host_roaming mode. In addition, it
1631 * does not break current association. However, it requires newer station
1632 * firmware version (>= 1.3.1) than scan request. */
1633static int prism2_request_hostscan(struct net_device *dev,
1634				   u8 *ssid, u8 ssid_len)
1635{
1636	struct hostap_interface *iface;
1637	local_info_t *local;
1638	struct hfa384x_hostscan_request scan_req;
1639
1640	iface = netdev_priv(dev);
1641	local = iface->local;
1642
1643	memset(&scan_req, 0, sizeof(scan_req));
1644	scan_req.channel_list = cpu_to_le16(local->channel_mask &
1645					    local->scan_channel_mask);
1646	scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
1647	if (ssid) {
1648		if (ssid_len > 32)
1649			return -EINVAL;
1650		scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1651		memcpy(scan_req.target_ssid, ssid, ssid_len);
1652	}
1653
1654	if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1655				 sizeof(scan_req))) {
1656		printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1657		return -EINVAL;
1658	}
1659	return 0;
1660}
1661
1662
1663static int prism2_request_scan(struct net_device *dev)
1664{
1665	struct hostap_interface *iface;
1666	local_info_t *local;
1667	struct hfa384x_scan_request scan_req;
1668	int ret = 0;
1669
1670	iface = netdev_priv(dev);
1671	local = iface->local;
1672
1673	memset(&scan_req, 0, sizeof(scan_req));
1674	scan_req.channel_list = cpu_to_le16(local->channel_mask &
1675					    local->scan_channel_mask);
1676	scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
1677
1678	/* FIX:
1679	 * It seems to be enough to set roaming mode for a short moment to
1680	 * host-based and then setup scanrequest data and return the mode to
1681	 * firmware-based.
1682	 *
1683	 * Master mode would need to drop to Managed mode for a short while
1684	 * to make scanning work.. Or sweep through the different channels and
1685	 * use passive scan based on beacons. */
1686
1687	if (!local->host_roaming)
1688		hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1689				HFA384X_ROAMING_HOST);
1690
1691	if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1692				 sizeof(scan_req))) {
1693		printk(KERN_DEBUG "SCANREQUEST failed\n");
1694		ret = -EINVAL;
1695	}
1696
1697	if (!local->host_roaming)
1698		hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1699				HFA384X_ROAMING_FIRMWARE);
1700
1701	return ret;
1702}
1703
1704#else /* !PRISM2_NO_STATION_MODES */
1705
1706static inline int prism2_request_hostscan(struct net_device *dev,
1707					  u8 *ssid, u8 ssid_len)
1708{
1709	return -EOPNOTSUPP;
1710}
1711
1712
1713static inline int prism2_request_scan(struct net_device *dev)
1714{
1715	return -EOPNOTSUPP;
1716}
1717
1718#endif /* !PRISM2_NO_STATION_MODES */
1719
1720
1721static int prism2_ioctl_siwscan(struct net_device *dev,
1722				struct iw_request_info *info,
1723				struct iw_point *data, char *extra)
1724{
1725	struct hostap_interface *iface;
1726	local_info_t *local;
1727	int ret;
1728	u8 *ssid = NULL, ssid_len = 0;
1729	struct iw_scan_req *req = (struct iw_scan_req *) extra;
1730
1731	iface = netdev_priv(dev);
1732	local = iface->local;
1733
1734	if (data->length < sizeof(struct iw_scan_req))
1735		req = NULL;
1736
1737	if (local->iw_mode == IW_MODE_MASTER) {
1738		/* In master mode, we just return the results of our local
1739		 * tables, so we don't need to start anything...
1740		 * Jean II */
1741		data->length = 0;
1742		return 0;
1743	}
1744
1745	if (!local->dev_enabled)
1746		return -ENETDOWN;
1747
1748	if (req && data->flags & IW_SCAN_THIS_ESSID) {
1749		ssid = req->essid;
1750		ssid_len = req->essid_len;
1751
1752		if (ssid_len &&
1753		    ((local->iw_mode != IW_MODE_INFRA &&
1754		      local->iw_mode != IW_MODE_ADHOC) ||
1755		     (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1756			return -EOPNOTSUPP;
1757	}
1758
1759	if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1760		ret = prism2_request_hostscan(dev, ssid, ssid_len);
1761	else
1762		ret = prism2_request_scan(dev);
1763
1764	if (ret == 0)
1765		local->scan_timestamp = jiffies;
1766
1767	/* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1768
1769	return ret;
1770}
1771
1772
1773#ifndef PRISM2_NO_STATION_MODES
1774static char * __prism2_translate_scan(local_info_t *local,
1775				      struct iw_request_info *info,
1776				      struct hfa384x_hostscan_result *scan,
1777				      struct hostap_bss_info *bss,
1778				      char *current_ev, char *end_buf)
1779{
1780	int i, chan;
1781	struct iw_event iwe;
1782	char *current_val;
1783	u16 capabilities;
1784	u8 *pos;
1785	u8 *ssid, *bssid;
1786	size_t ssid_len;
1787	char *buf;
1788
1789	if (bss) {
1790		ssid = bss->ssid;
1791		ssid_len = bss->ssid_len;
1792		bssid = bss->bssid;
1793	} else {
1794		ssid = scan->ssid;
1795		ssid_len = le16_to_cpu(scan->ssid_len);
1796		bssid = scan->bssid;
1797	}
1798	if (ssid_len > 32)
1799		ssid_len = 32;
1800
1801	/* First entry *MUST* be the AP MAC address */
1802	memset(&iwe, 0, sizeof(iwe));
1803	iwe.cmd = SIOCGIWAP;
1804	iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1805	memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1806	current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1807					  IW_EV_ADDR_LEN);
1808
1809	/* Other entries will be displayed in the order we give them */
1810
1811	memset(&iwe, 0, sizeof(iwe));
1812	iwe.cmd = SIOCGIWESSID;
1813	iwe.u.data.length = ssid_len;
1814	iwe.u.data.flags = 1;
1815	current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1816					  &iwe, ssid);
1817
1818	memset(&iwe, 0, sizeof(iwe));
1819	iwe.cmd = SIOCGIWMODE;
1820	if (bss) {
1821		capabilities = bss->capab_info;
1822	} else {
1823		capabilities = le16_to_cpu(scan->capability);
1824	}
1825	if (capabilities & (WLAN_CAPABILITY_ESS |
1826			    WLAN_CAPABILITY_IBSS)) {
1827		if (capabilities & WLAN_CAPABILITY_ESS)
1828			iwe.u.mode = IW_MODE_MASTER;
1829		else
1830			iwe.u.mode = IW_MODE_ADHOC;
1831		current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1832						  &iwe, IW_EV_UINT_LEN);
1833	}
1834
1835	memset(&iwe, 0, sizeof(iwe));
1836	iwe.cmd = SIOCGIWFREQ;
1837	if (scan) {
1838		chan = le16_to_cpu(scan->chid);
1839	} else if (bss) {
1840		chan = bss->chan;
1841	} else {
1842		chan = 0;
1843	}
1844
1845	if (chan > 0) {
1846		iwe.u.freq.m = freq_list[chan - 1] * 100000;
1847		iwe.u.freq.e = 1;
1848		current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1849						  &iwe, IW_EV_FREQ_LEN);
1850	}
1851
1852	if (scan) {
1853		memset(&iwe, 0, sizeof(iwe));
1854		iwe.cmd = IWEVQUAL;
1855		if (local->last_scan_type == PRISM2_HOSTSCAN) {
1856			iwe.u.qual.level = le16_to_cpu(scan->sl);
1857			iwe.u.qual.noise = le16_to_cpu(scan->anl);
1858		} else {
1859			iwe.u.qual.level =
1860				HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1861			iwe.u.qual.noise =
1862				HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1863		}
1864		iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
1865			| IW_QUAL_NOISE_UPDATED
1866			| IW_QUAL_QUAL_INVALID
1867			| IW_QUAL_DBM;
1868		current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1869						  &iwe, IW_EV_QUAL_LEN);
1870	}
1871
1872	memset(&iwe, 0, sizeof(iwe));
1873	iwe.cmd = SIOCGIWENCODE;
1874	if (capabilities & WLAN_CAPABILITY_PRIVACY)
1875		iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1876	else
1877		iwe.u.data.flags = IW_ENCODE_DISABLED;
1878	iwe.u.data.length = 0;
1879	current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, "");
1880
1881	/* TODO: add SuppRates into BSS table */
1882	if (scan) {
1883		memset(&iwe, 0, sizeof(iwe));
1884		iwe.cmd = SIOCGIWRATE;
1885		current_val = current_ev + iwe_stream_lcp_len(info);
1886		pos = scan->sup_rates;
1887		for (i = 0; i < sizeof(scan->sup_rates); i++) {
1888			if (pos[i] == 0)
1889				break;
1890			/* Bit rate given in 500 kb/s units (+ 0x80) */
1891			iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1892			current_val = iwe_stream_add_value(
1893				info, current_ev, current_val, end_buf, &iwe,
1894				IW_EV_PARAM_LEN);
1895		}
1896		/* Check if we added any event */
1897		if ((current_val - current_ev) > iwe_stream_lcp_len(info))
1898			current_ev = current_val;
1899	}
1900
1901	/* TODO: add BeaconInt,resp_rate,atim into BSS table */
1902	buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_ATOMIC);
1903	if (buf && scan) {
1904		memset(&iwe, 0, sizeof(iwe));
1905		iwe.cmd = IWEVCUSTOM;
1906		sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval));
1907		iwe.u.data.length = strlen(buf);
1908		current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1909						  &iwe, buf);
1910
1911		memset(&iwe, 0, sizeof(iwe));
1912		iwe.cmd = IWEVCUSTOM;
1913		sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate));
1914		iwe.u.data.length = strlen(buf);
1915		current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1916						  &iwe, buf);
1917
1918		if (local->last_scan_type == PRISM2_HOSTSCAN &&
1919		    (capabilities & WLAN_CAPABILITY_IBSS)) {
1920			memset(&iwe, 0, sizeof(iwe));
1921			iwe.cmd = IWEVCUSTOM;
1922			sprintf(buf, "atim=%d", le16_to_cpu(scan->atim));
1923			iwe.u.data.length = strlen(buf);
1924			current_ev = iwe_stream_add_point(info, current_ev,
1925							  end_buf, &iwe, buf);
1926		}
1927	}
1928	kfree(buf);
1929
1930	if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1931		memset(&iwe, 0, sizeof(iwe));
1932		iwe.cmd = IWEVGENIE;
1933		iwe.u.data.length = bss->wpa_ie_len;
1934		current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1935						  &iwe, bss->wpa_ie);
1936	}
1937
1938	if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1939		memset(&iwe, 0, sizeof(iwe));
1940		iwe.cmd = IWEVGENIE;
1941		iwe.u.data.length = bss->rsn_ie_len;
1942		current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1943						  &iwe, bss->rsn_ie);
1944	}
1945
1946	return current_ev;
1947}
1948
1949
1950/* Translate scan data returned from the card to a card independent
1951 * format that the Wireless Tools will understand - Jean II */
1952static inline int prism2_translate_scan(local_info_t *local,
1953					struct iw_request_info *info,
1954					char *buffer, int buflen)
1955{
1956	struct hfa384x_hostscan_result *scan;
1957	int entry, hostscan;
1958	char *current_ev = buffer;
1959	char *end_buf = buffer + buflen;
1960	struct list_head *ptr;
1961
1962	spin_lock_bh(&local->lock);
1963
1964	list_for_each(ptr, &local->bss_list) {
1965		struct hostap_bss_info *bss;
1966		bss = list_entry(ptr, struct hostap_bss_info, list);
1967		bss->included = 0;
1968	}
1969
1970	hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
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…

Large files files are truncated, but you can click here to view the full file