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, hostscan;
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 	hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
1972 	for (entry = 0; entry < local->last_scan_results_count; entry++) {
1973 		int found = 0;
1974 		scan = &local->last_scan_results[entry];
1975 
1976 		/* Report every SSID if the AP is using multiple SSIDs. If no
1977 		 * BSS record is found (e.g., when WPA mode is disabled),
1978 		 * report the AP once. */
1979 		list_for_each(ptr, &local->bss_list) {
1980 			struct hostap_bss_info *bss;
1981 			bss = list_entry(ptr, struct hostap_bss_info, list);
1982 			if (ether_addr_equal(bss->bssid, scan->bssid)) {
1983 				bss->included = 1;
1984 				current_ev = __prism2_translate_scan(
1985 					local, info, scan, bss, current_ev,
1986 					end_buf);
1987 				found++;
1988 			}
1989 		}
1990 		if (!found) {
1991 			current_ev = __prism2_translate_scan(
1992 				local, info, scan, NULL, current_ev, end_buf);
1993 		}
1994 		/* Check if there is space for one more entry */
1995 		if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
1996 			/* Ask user space to try again with a bigger buffer */
1997 			spin_unlock_bh(&local->lock);
1998 			return -E2BIG;
1999 		}
2000 	}
2001 
2002 	/* Prism2 firmware has limits (32 at least in some versions) for number
2003 	 * of BSSes in scan results. Extend this limit by using local BSS list.
2004 	 */
2005 	list_for_each(ptr, &local->bss_list) {
2006 		struct hostap_bss_info *bss;
2007 		bss = list_entry(ptr, struct hostap_bss_info, list);
2008 		if (bss->included)
2009 			continue;
2010 		current_ev = __prism2_translate_scan(local, info, NULL, bss,
2011 						     current_ev, end_buf);
2012 		/* Check if there is space for one more entry */
2013 		if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2014 			/* Ask user space to try again with a bigger buffer */
2015 			spin_unlock_bh(&local->lock);
2016 			return -E2BIG;
2017 		}
2018 	}
2019 
2020 	spin_unlock_bh(&local->lock);
2021 
2022 	return current_ev - buffer;
2023 }
2024 #endif /* PRISM2_NO_STATION_MODES */
2025 
2026 
2027 static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2028 					   struct iw_request_info *info,
2029 					   struct iw_point *data, char *extra)
2030 {
2031 #ifdef PRISM2_NO_STATION_MODES
2032 	return -EOPNOTSUPP;
2033 #else /* PRISM2_NO_STATION_MODES */
2034 	struct hostap_interface *iface;
2035 	local_info_t *local;
2036 	int res;
2037 
2038 	iface = netdev_priv(dev);
2039 	local = iface->local;
2040 
2041 	/* Wait until the scan is finished. We can probably do better
2042 	 * than that - Jean II */
2043 	if (local->scan_timestamp &&
2044 	    time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2045 		/* Important note : we don't want to block the caller
2046 		 * until results are ready for various reasons.
2047 		 * First, managing wait queues is complex and racy
2048 		 * (there may be multiple simultaneous callers).
2049 		 * Second, we grab some rtnetlink lock before coming
2050 		 * here (in dev_ioctl()).
2051 		 * Third, the caller can wait on the Wireless Event
2052 		 * - Jean II */
2053 		return -EAGAIN;
2054 	}
2055 	local->scan_timestamp = 0;
2056 
2057 	res = prism2_translate_scan(local, info, extra, data->length);
2058 
2059 	if (res >= 0) {
2060 		data->length = res;
2061 		return 0;
2062 	} else {
2063 		data->length = 0;
2064 		return res;
2065 	}
2066 #endif /* PRISM2_NO_STATION_MODES */
2067 }
2068 
2069 
2070 static int prism2_ioctl_giwscan(struct net_device *dev,
2071 				struct iw_request_info *info,
2072 				struct iw_point *data, char *extra)
2073 {
2074 	struct hostap_interface *iface;
2075 	local_info_t *local;
2076 	int res;
2077 
2078 	iface = netdev_priv(dev);
2079 	local = iface->local;
2080 
2081 	if (local->iw_mode == IW_MODE_MASTER) {
2082 		/* In MASTER mode, it doesn't make sense to go around
2083 		 * scanning the frequencies and make the stations we serve
2084 		 * wait when what the user is really interested about is the
2085 		 * list of stations and access points we are talking to.
2086 		 * So, just extract results from our cache...
2087 		 * Jean II */
2088 
2089 		/* Translate to WE format */
2090 		res = prism2_ap_translate_scan(dev, info, extra);
2091 		if (res >= 0) {
2092 			printk(KERN_DEBUG "Scan result translation succeeded "
2093 			       "(length=%d)\n", res);
2094 			data->length = res;
2095 			return 0;
2096 		} else {
2097 			printk(KERN_DEBUG
2098 			       "Scan result translation failed (res=%d)\n",
2099 			       res);
2100 			data->length = 0;
2101 			return res;
2102 		}
2103 	} else {
2104 		/* Station mode */
2105 		return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2106 	}
2107 }
2108 
2109 
2110 static const struct iw_priv_args prism2_priv[] = {
2111 	{ PRISM2_IOCTL_MONITOR,
2112 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2113 	{ PRISM2_IOCTL_READMIF,
2114 	  IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2115 	  IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2116 	{ PRISM2_IOCTL_WRITEMIF,
2117 	  IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2118 	{ PRISM2_IOCTL_RESET,
2119 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2120 	{ PRISM2_IOCTL_INQUIRE,
2121 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2122 	{ PRISM2_IOCTL_SET_RID_WORD,
2123 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2124 	{ PRISM2_IOCTL_MACCMD,
2125 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2126 	{ PRISM2_IOCTL_WDS_ADD,
2127 	  IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2128 	{ PRISM2_IOCTL_WDS_DEL,
2129 	  IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2130 	{ PRISM2_IOCTL_ADDMAC,
2131 	  IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2132 	{ PRISM2_IOCTL_DELMAC,
2133 	  IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2134 	{ PRISM2_IOCTL_KICKMAC,
2135 	  IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2136 	/* --- raw access to sub-ioctls --- */
2137 	{ PRISM2_IOCTL_PRISM2_PARAM,
2138 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2139 	{ PRISM2_IOCTL_GET_PRISM2_PARAM,
2140 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2141 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2142 	/* --- sub-ioctls handlers --- */
2143 	{ PRISM2_IOCTL_PRISM2_PARAM,
2144 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2145 	{ PRISM2_IOCTL_GET_PRISM2_PARAM,
2146 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2147 	/* --- sub-ioctls definitions --- */
2148 	{ PRISM2_PARAM_TXRATECTRL,
2149 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2150 	{ PRISM2_PARAM_TXRATECTRL,
2151 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2152 	{ PRISM2_PARAM_BEACON_INT,
2153 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2154 	{ PRISM2_PARAM_BEACON_INT,
2155 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2156 #ifndef PRISM2_NO_STATION_MODES
2157 	{ PRISM2_PARAM_PSEUDO_IBSS,
2158 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2159 	{ PRISM2_PARAM_PSEUDO_IBSS,
2160 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2161 #endif /* PRISM2_NO_STATION_MODES */
2162 	{ PRISM2_PARAM_ALC,
2163 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2164 	{ PRISM2_PARAM_ALC,
2165 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2166 	{ PRISM2_PARAM_DUMP,
2167 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2168 	{ PRISM2_PARAM_DUMP,
2169 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2170 	{ PRISM2_PARAM_OTHER_AP_POLICY,
2171 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2172 	{ PRISM2_PARAM_OTHER_AP_POLICY,
2173 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2174 	{ PRISM2_PARAM_AP_MAX_INACTIVITY,
2175 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2176 	{ PRISM2_PARAM_AP_MAX_INACTIVITY,
2177 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2178 	{ PRISM2_PARAM_AP_BRIDGE_PACKETS,
2179 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2180 	{ PRISM2_PARAM_AP_BRIDGE_PACKETS,
2181 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2182 	{ PRISM2_PARAM_DTIM_PERIOD,
2183 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2184 	{ PRISM2_PARAM_DTIM_PERIOD,
2185 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2186 	{ PRISM2_PARAM_AP_NULLFUNC_ACK,
2187 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2188 	{ PRISM2_PARAM_AP_NULLFUNC_ACK,
2189 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2190 	{ PRISM2_PARAM_MAX_WDS,
2191 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2192 	{ PRISM2_PARAM_MAX_WDS,
2193 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2194 	{ PRISM2_PARAM_AP_AUTOM_AP_WDS,
2195 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2196 	{ PRISM2_PARAM_AP_AUTOM_AP_WDS,
2197 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2198 	{ PRISM2_PARAM_AP_AUTH_ALGS,
2199 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2200 	{ PRISM2_PARAM_AP_AUTH_ALGS,
2201 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2202 	{ PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2203 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2204 	{ PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2205 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2206 	{ PRISM2_PARAM_HOST_ENCRYPT,
2207 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2208 	{ PRISM2_PARAM_HOST_ENCRYPT,
2209 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2210 	{ PRISM2_PARAM_HOST_DECRYPT,
2211 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2212 	{ PRISM2_PARAM_HOST_DECRYPT,
2213 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2214 #ifndef PRISM2_NO_STATION_MODES
2215 	{ PRISM2_PARAM_HOST_ROAMING,
2216 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2217 	{ PRISM2_PARAM_HOST_ROAMING,
2218 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2219 #endif /* PRISM2_NO_STATION_MODES */
2220 	{ PRISM2_PARAM_BCRX_STA_KEY,
2221 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2222 	{ PRISM2_PARAM_BCRX_STA_KEY,
2223 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2224 	{ PRISM2_PARAM_IEEE_802_1X,
2225 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2226 	{ PRISM2_PARAM_IEEE_802_1X,
2227 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2228 	{ PRISM2_PARAM_ANTSEL_TX,
2229 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2230 	{ PRISM2_PARAM_ANTSEL_TX,
2231 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2232 	{ PRISM2_PARAM_ANTSEL_RX,
2233 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2234 	{ PRISM2_PARAM_ANTSEL_RX,
2235 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2236 	{ PRISM2_PARAM_MONITOR_TYPE,
2237 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2238 	{ PRISM2_PARAM_MONITOR_TYPE,
2239 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2240 	{ PRISM2_PARAM_WDS_TYPE,
2241 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2242 	{ PRISM2_PARAM_WDS_TYPE,
2243 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2244 	{ PRISM2_PARAM_HOSTSCAN,
2245 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2246 	{ PRISM2_PARAM_HOSTSCAN,
2247 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2248 	{ PRISM2_PARAM_AP_SCAN,
2249 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2250 	{ PRISM2_PARAM_AP_SCAN,
2251 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2252 	{ PRISM2_PARAM_ENH_SEC,
2253 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2254 	{ PRISM2_PARAM_ENH_SEC,
2255 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2256 #ifdef PRISM2_IO_DEBUG
2257 	{ PRISM2_PARAM_IO_DEBUG,
2258 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2259 	{ PRISM2_PARAM_IO_DEBUG,
2260 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2261 #endif /* PRISM2_IO_DEBUG */
2262 	{ PRISM2_PARAM_BASIC_RATES,
2263 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2264 	{ PRISM2_PARAM_BASIC_RATES,
2265 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2266 	{ PRISM2_PARAM_OPER_RATES,
2267 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2268 	{ PRISM2_PARAM_OPER_RATES,
2269 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2270 	{ PRISM2_PARAM_HOSTAPD,
2271 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2272 	{ PRISM2_PARAM_HOSTAPD,
2273 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2274 	{ PRISM2_PARAM_HOSTAPD_STA,
2275 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2276 	{ PRISM2_PARAM_HOSTAPD_STA,
2277 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2278 	{ PRISM2_PARAM_WPA,
2279 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2280 	{ PRISM2_PARAM_WPA,
2281 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2282 	{ PRISM2_PARAM_PRIVACY_INVOKED,
2283 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2284 	{ PRISM2_PARAM_PRIVACY_INVOKED,
2285 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2286 	{ PRISM2_PARAM_TKIP_COUNTERMEASURES,
2287 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2288 	{ PRISM2_PARAM_TKIP_COUNTERMEASURES,
2289 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2290 	{ PRISM2_PARAM_DROP_UNENCRYPTED,
2291 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2292 	{ PRISM2_PARAM_DROP_UNENCRYPTED,
2293 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
2294 	{ PRISM2_PARAM_SCAN_CHANNEL_MASK,
2295 	  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
2296 	{ PRISM2_PARAM_SCAN_CHANNEL_MASK,
2297 	  0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
2298 };
2299 
2300 
2301 static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2302 {
2303 	struct hostap_interface *iface;
2304 	local_info_t *local;
2305 
2306 	iface = netdev_priv(dev);
2307 	local = iface->local;
2308 
2309 	if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2310 		return -EOPNOTSUPP;
2311 
2312 	return 0;
2313 }
2314 
2315 
2316 static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2317 					  struct iw_request_info *info,
2318 					  void *wrqu, char *extra)
2319 {
2320 	struct hostap_interface *iface;
2321 	local_info_t *local;
2322 	int *i = (int *) extra;
2323 	int param = *i;
2324 	int value = *(i + 1);
2325 	int ret = 0;
2326 	u16 val;
2327 
2328 	iface = netdev_priv(dev);
2329 	local = iface->local;
2330 
2331 	switch (param) {
2332 	case PRISM2_PARAM_TXRATECTRL:
2333 		local->fw_tx_rate_control = value;
2334 		break;
2335 
2336 	case PRISM2_PARAM_BEACON_INT:
2337 		if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2338 		    local->func->reset_port(dev))
2339 			ret = -EINVAL;
2340 		else
2341 			local->beacon_int = value;
2342 		break;
2343 
2344 #ifndef PRISM2_NO_STATION_MODES
2345 	case PRISM2_PARAM_PSEUDO_IBSS:
2346 		if (value == local->pseudo_adhoc)
2347 			break;
2348 
2349 		if (value != 0 && value != 1) {
2350 			ret = -EINVAL;
2351 			break;
2352 		}
2353 
2354 		printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2355 		       dev->name, local->pseudo_adhoc, value);
2356 		local->pseudo_adhoc = value;
2357 		if (local->iw_mode != IW_MODE_ADHOC)
2358 			break;
2359 
2360 		if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2361 				    hostap_get_porttype(local))) {
2362 			ret = -EOPNOTSUPP;
2363 			break;
2364 		}
2365 
2366 		if (local->func->reset_port(dev))
2367 			ret = -EINVAL;
2368 		break;
2369 #endif /* PRISM2_NO_STATION_MODES */
2370 
2371 	case PRISM2_PARAM_ALC:
2372 		printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2373 		       value == 0 ? "Disabling" : "Enabling");
2374 		val = HFA384X_TEST_CFG_BIT_ALC;
2375 		local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2376 				 (HFA384X_TEST_CFG_BITS << 8),
2377 				 value == 0 ? 0 : 1, &val, NULL);
2378 		break;
2379 
2380 	case PRISM2_PARAM_DUMP:
2381 		local->frame_dump = value;
2382 		break;
2383 
2384 	case PRISM2_PARAM_OTHER_AP_POLICY:
2385 		if (value < 0 || value > 3) {
2386 			ret = -EINVAL;
2387 			break;
2388 		}
2389 		if (local->ap != NULL)
2390 			local->ap->ap_policy = value;
2391 		break;
2392 
2393 	case PRISM2_PARAM_AP_MAX_INACTIVITY:
2394 		if (value < 0 || value > 7 * 24 * 60 * 60) {
2395 			ret = -EINVAL;
2396 			break;
2397 		}
2398 		if (local->ap != NULL)
2399 			local->ap->max_inactivity = value * HZ;
2400 		break;
2401 
2402 	case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2403 		if (local->ap != NULL)
2404 			local->ap->bridge_packets = value;
2405 		break;
2406 
2407 	case PRISM2_PARAM_DTIM_PERIOD:
2408 		if (value < 0 || value > 65535) {
2409 			ret = -EINVAL;
2410 			break;
2411 		}
2412 		if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2413 		    || local->func->reset_port(dev))
2414 			ret = -EINVAL;
2415 		else
2416 			local->dtim_period = value;
2417 		break;
2418 
2419 	case PRISM2_PARAM_AP_NULLFUNC_ACK:
2420 		if (local->ap != NULL)
2421 			local->ap->nullfunc_ack = value;
2422 		break;
2423 
2424 	case PRISM2_PARAM_MAX_WDS:
2425 		local->wds_max_connections = value;
2426 		break;
2427 
2428 	case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2429 		if (local->ap != NULL) {
2430 			if (!local->ap->autom_ap_wds && value) {
2431 				/* add WDS link to all APs in STA table */
2432 				hostap_add_wds_links(local);
2433 			}
2434 			local->ap->autom_ap_wds = value;
2435 		}
2436 		break;
2437 
2438 	case PRISM2_PARAM_AP_AUTH_ALGS:
2439 		local->auth_algs = value;
2440 		if (hostap_set_auth_algs(local))
2441 			ret = -EINVAL;
2442 		break;
2443 
2444 	case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2445 		local->monitor_allow_fcserr = value;
2446 		break;
2447 
2448 	case PRISM2_PARAM_HOST_ENCRYPT:
2449 		local->host_encrypt = value;
2450 		if (hostap_set_encryption(local) ||
2451 		    local->func->reset_port(dev))
2452 			ret = -EINVAL;
2453 		break;
2454 
2455 	case PRISM2_PARAM_HOST_DECRYPT:
2456 		local->host_decrypt = value;
2457 		if (hostap_set_encryption(local) ||
2458 		    local->func->reset_port(dev))
2459 			ret = -EINVAL;
2460 		break;
2461 
2462 #ifndef PRISM2_NO_STATION_MODES
2463 	case PRISM2_PARAM_HOST_ROAMING:
2464 		if (value < 0 || value > 2) {
2465 			ret = -EINVAL;
2466 			break;
2467 		}
2468 		local->host_roaming = value;
2469 		if (hostap_set_roaming(local) || local->func->reset_port(dev))
2470 			ret = -EINVAL;
2471 		break;
2472 #endif /* PRISM2_NO_STATION_MODES */
2473 
2474 	case PRISM2_PARAM_BCRX_STA_KEY:
2475 		local->bcrx_sta_key = value;
2476 		break;
2477 
2478 	case PRISM2_PARAM_IEEE_802_1X:
2479 		local->ieee_802_1x = value;
2480 		break;
2481 
2482 	case PRISM2_PARAM_ANTSEL_TX:
2483 		if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2484 			ret = -EINVAL;
2485 			break;
2486 		}
2487 		local->antsel_tx = value;
2488 		hostap_set_antsel(local);
2489 		break;
2490 
2491 	case PRISM2_PARAM_ANTSEL_RX:
2492 		if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2493 			ret = -EINVAL;
2494 			break;
2495 		}
2496 		local->antsel_rx = value;
2497 		hostap_set_antsel(local);
2498 		break;
2499 
2500 	case PRISM2_PARAM_MONITOR_TYPE:
2501 		if (value != PRISM2_MONITOR_80211 &&
2502 		    value != PRISM2_MONITOR_CAPHDR &&
2503 		    value != PRISM2_MONITOR_PRISM &&
2504 		    value != PRISM2_MONITOR_RADIOTAP) {
2505 			ret = -EINVAL;
2506 			break;
2507 		}
2508 		local->monitor_type = value;
2509 		if (local->iw_mode == IW_MODE_MONITOR)
2510 			hostap_monitor_set_type(local);
2511 		break;
2512 
2513 	case PRISM2_PARAM_WDS_TYPE:
2514 		local->wds_type = value;
2515 		break;
2516 
2517 	case PRISM2_PARAM_HOSTSCAN:
2518 	{
2519 		struct hfa384x_hostscan_request scan_req;
2520 		u16 rate;
2521 
2522 		memset(&scan_req, 0, sizeof(scan_req));
2523 		scan_req.channel_list = cpu_to_le16(0x3fff);
2524 		switch (value) {
2525 		case 1: rate = HFA384X_RATES_1MBPS; break;
2526 		case 2: rate = HFA384X_RATES_2MBPS; break;
2527 		case 3: rate = HFA384X_RATES_5MBPS; break;
2528 		case 4: rate = HFA384X_RATES_11MBPS; break;
2529 		default: rate = HFA384X_RATES_1MBPS; break;
2530 		}
2531 		scan_req.txrate = cpu_to_le16(rate);
2532 		/* leave SSID empty to accept all SSIDs */
2533 
2534 		if (local->iw_mode == IW_MODE_MASTER) {
2535 			if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2536 					    HFA384X_PORTTYPE_BSS) ||
2537 			    local->func->reset_port(dev))
2538 				printk(KERN_DEBUG "Leaving Host AP mode "
2539 				       "for HostScan failed\n");
2540 		}
2541 
2542 		if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2543 					 sizeof(scan_req))) {
2544 			printk(KERN_DEBUG "HOSTSCAN failed\n");
2545 			ret = -EINVAL;
2546 		}
2547 		if (local->iw_mode == IW_MODE_MASTER) {
2548 			wait_queue_entry_t __wait;
2549 			init_waitqueue_entry(&__wait, current);
2550 			add_wait_queue(&local->hostscan_wq, &__wait);
2551 			set_current_state(TASK_INTERRUPTIBLE);
2552 			schedule_timeout(HZ);
2553 			if (signal_pending(current))
2554 				ret = -EINTR;
2555 			set_current_state(TASK_RUNNING);
2556 			remove_wait_queue(&local->hostscan_wq, &__wait);
2557 
2558 			if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2559 					    HFA384X_PORTTYPE_HOSTAP) ||
2560 			    local->func->reset_port(dev))
2561 				printk(KERN_DEBUG "Returning to Host AP mode "
2562 				       "after HostScan failed\n");
2563 		}
2564 		break;
2565 	}
2566 
2567 	case PRISM2_PARAM_AP_SCAN:
2568 		local->passive_scan_interval = value;
2569 		if (timer_pending(&local->passive_scan_timer))
2570 			del_timer(&local->passive_scan_timer);
2571 		if (value > 0 && value < INT_MAX / HZ) {
2572 			local->passive_scan_timer.expires = jiffies +
2573 				local->passive_scan_interval * HZ;
2574 			add_timer(&local->passive_scan_timer);
2575 		}
2576 		break;
2577 
2578 	case PRISM2_PARAM_ENH_SEC:
2579 		if (value < 0 || value > 3) {
2580 			ret = -EINVAL;
2581 			break;
2582 		}
2583 		local->enh_sec = value;
2584 		if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2585 				    local->enh_sec) ||
2586 		    local->func->reset_port(dev)) {
2587 			printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2588 			       "1.6.3 or newer\n", dev->name);
2589 			ret = -EOPNOTSUPP;
2590 		}
2591 		break;
2592 
2593 #ifdef PRISM2_IO_DEBUG
2594 	case PRISM2_PARAM_IO_DEBUG:
2595 		local->io_debug_enabled = value;
2596 		break;
2597 #endif /* PRISM2_IO_DEBUG */
2598 
2599 	case PRISM2_PARAM_BASIC_RATES:
2600 		if ((value & local->tx_rate_control) != value || value == 0) {
2601 			printk(KERN_INFO "%s: invalid basic rate set - basic "
2602 			       "rates must be in supported rate set\n",
2603 			       dev->name);
2604 			ret = -EINVAL;
2605 			break;
2606 		}
2607 		local->basic_rates = value;
2608 		if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2609 				    local->basic_rates) ||
2610 		    local->func->reset_port(dev))
2611 			ret = -EINVAL;
2612 		break;
2613 
2614 	case PRISM2_PARAM_OPER_RATES:
2615 		local->tx_rate_control = value;
2616 		if (hostap_set_rate(dev))
2617 			ret = -EINVAL;
2618 		break;
2619 
2620 	case PRISM2_PARAM_HOSTAPD:
2621 		ret = hostap_set_hostapd(local, value, 1);
2622 		break;
2623 
2624 	case PRISM2_PARAM_HOSTAPD_STA:
2625 		ret = hostap_set_hostapd_sta(local, value, 1);
2626 		break;
2627 
2628 	case PRISM2_PARAM_WPA:
2629 		local->wpa = value;
2630 		if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2631 			ret = -EOPNOTSUPP;
2632 		else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2633 					 value ? 1 : 0))
2634 			ret = -EINVAL;
2635 		break;
2636 
2637 	case PRISM2_PARAM_PRIVACY_INVOKED:
2638 		local->privacy_invoked = value;
2639 		if (hostap_set_encryption(local) ||
2640 		    local->func->reset_port(dev))
2641 			ret = -EINVAL;
2642 		break;
2643 
2644 	case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2645 		local->tkip_countermeasures = value;
2646 		break;
2647 
2648 	case PRISM2_PARAM_DROP_UNENCRYPTED:
2649 		local->drop_unencrypted = value;
2650 		break;
2651 
2652 	case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2653 		local->scan_channel_mask = value;
2654 		break;
2655 
2656 	default:
2657 		printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2658 		       dev->name, param);
2659 		ret = -EOPNOTSUPP;
2660 		break;
2661 	}
2662 
2663 	return ret;
2664 }
2665 
2666 
2667 static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2668 					      struct iw_request_info *info,
2669 					      void *wrqu, char *extra)
2670 {
2671 	struct hostap_interface *iface;
2672 	local_info_t *local;
2673 	int *param = (int *) extra;
2674 	int ret = 0;
2675 
2676 	iface = netdev_priv(dev);
2677 	local = iface->local;
2678 
2679 	switch (*param) {
2680 	case PRISM2_PARAM_TXRATECTRL:
2681 		*param = local->fw_tx_rate_control;
2682 		break;
2683 
2684 	case PRISM2_PARAM_BEACON_INT:
2685 		*param = local->beacon_int;
2686 		break;
2687 
2688 	case PRISM2_PARAM_PSEUDO_IBSS:
2689 		*param = local->pseudo_adhoc;
2690 		break;
2691 
2692 	case PRISM2_PARAM_ALC:
2693 		ret = -EOPNOTSUPP; /* FIX */
2694 		break;
2695 
2696 	case PRISM2_PARAM_DUMP:
2697 		*param = local->frame_dump;
2698 		break;
2699 
2700 	case PRISM2_PARAM_OTHER_AP_POLICY:
2701 		if (local->ap != NULL)
2702 			*param = local->ap->ap_policy;
2703 		else
2704 			ret = -EOPNOTSUPP;
2705 		break;
2706 
2707 	case PRISM2_PARAM_AP_MAX_INACTIVITY:
2708 		if (local->ap != NULL)
2709 			*param = local->ap->max_inactivity / HZ;
2710 		else
2711 			ret = -EOPNOTSUPP;
2712 		break;
2713 
2714 	case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2715 		if (local->ap != NULL)
2716 			*param = local->ap->bridge_packets;
2717 		else
2718 			ret = -EOPNOTSUPP;
2719 		break;
2720 
2721 	case PRISM2_PARAM_DTIM_PERIOD:
2722 		*param = local->dtim_period;
2723 		break;
2724 
2725 	case PRISM2_PARAM_AP_NULLFUNC_ACK:
2726 		if (local->ap != NULL)
2727 			*param = local->ap->nullfunc_ack;
2728 		else
2729 			ret = -EOPNOTSUPP;
2730 		break;
2731 
2732 	case PRISM2_PARAM_MAX_WDS:
2733 		*param = local->wds_max_connections;
2734 		break;
2735 
2736 	case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2737 		if (local->ap != NULL)
2738 			*param = local->ap->autom_ap_wds;
2739 		else
2740 			ret = -EOPNOTSUPP;
2741 		break;
2742 
2743 	case PRISM2_PARAM_AP_AUTH_ALGS:
2744 		*param = local->auth_algs;
2745 		break;
2746 
2747 	case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2748 		*param = local->monitor_allow_fcserr;
2749 		break;
2750 
2751 	case PRISM2_PARAM_HOST_ENCRYPT:
2752 		*param = local->host_encrypt;
2753 		break;
2754 
2755 	case PRISM2_PARAM_HOST_DECRYPT:
2756 		*param = local->host_decrypt;
2757 		break;
2758 
2759 	case PRISM2_PARAM_HOST_ROAMING:
2760 		*param = local->host_roaming;
2761 		break;
2762 
2763 	case PRISM2_PARAM_BCRX_STA_KEY:
2764 		*param = local->bcrx_sta_key;
2765 		break;
2766 
2767 	case PRISM2_PARAM_IEEE_802_1X:
2768 		*param = local->ieee_802_1x;
2769 		break;
2770 
2771 	case PRISM2_PARAM_ANTSEL_TX:
2772 		*param = local->antsel_tx;
2773 		break;
2774 
2775 	case PRISM2_PARAM_ANTSEL_RX:
2776 		*param = local->antsel_rx;
2777 		break;
2778 
2779 	case PRISM2_PARAM_MONITOR_TYPE:
2780 		*param = local->monitor_type;
2781 		break;
2782 
2783 	case PRISM2_PARAM_WDS_TYPE:
2784 		*param = local->wds_type;
2785 		break;
2786 
2787 	case PRISM2_PARAM_HOSTSCAN:
2788 		ret = -EOPNOTSUPP;
2789 		break;
2790 
2791 	case PRISM2_PARAM_AP_SCAN:
2792 		*param = local->passive_scan_interval;
2793 		break;
2794 
2795 	case PRISM2_PARAM_ENH_SEC:
2796 		*param = local->enh_sec;
2797 		break;
2798 
2799 #ifdef PRISM2_IO_DEBUG
2800 	case PRISM2_PARAM_IO_DEBUG:
2801 		*param = local->io_debug_enabled;
2802 		break;
2803 #endif /* PRISM2_IO_DEBUG */
2804 
2805 	case PRISM2_PARAM_BASIC_RATES:
2806 		*param = local->basic_rates;
2807 		break;
2808 
2809 	case PRISM2_PARAM_OPER_RATES:
2810 		*param = local->tx_rate_control;
2811 		break;
2812 
2813 	case PRISM2_PARAM_HOSTAPD:
2814 		*param = local->hostapd;
2815 		break;
2816 
2817 	case PRISM2_PARAM_HOSTAPD_STA:
2818 		*param = local->hostapd_sta;
2819 		break;
2820 
2821 	case PRISM2_PARAM_WPA:
2822 		if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2823 			ret = -EOPNOTSUPP;
2824 		*param = local->wpa;
2825 		break;
2826 
2827 	case PRISM2_PARAM_PRIVACY_INVOKED:
2828 		*param = local->privacy_invoked;
2829 		break;
2830 
2831 	case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2832 		*param = local->tkip_countermeasures;
2833 		break;
2834 
2835 	case PRISM2_PARAM_DROP_UNENCRYPTED:
2836 		*param = local->drop_unencrypted;
2837 		break;
2838 
2839 	case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2840 		*param = local->scan_channel_mask;
2841 		break;
2842 
2843 	default:
2844 		printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2845 		       dev->name, *param);
2846 		ret = -EOPNOTSUPP;
2847 		break;
2848 	}
2849 
2850 	return ret;
2851 }
2852 
2853 
2854 static int prism2_ioctl_priv_readmif(struct net_device *dev,
2855 				     struct iw_request_info *info,
2856 				     void *wrqu, char *extra)
2857 {
2858 	struct hostap_interface *iface;
2859 	local_info_t *local;
2860 	u16 resp0;
2861 
2862 	iface = netdev_priv(dev);
2863 	local = iface->local;
2864 
2865 	if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2866 			     &resp0))
2867 		return -EOPNOTSUPP;
2868 	else
2869 		*extra = resp0;
2870 
2871 	return 0;
2872 }
2873 
2874 
2875 static int prism2_ioctl_priv_writemif(struct net_device *dev,
2876 				      struct iw_request_info *info,
2877 				      void *wrqu, char *extra)
2878 {
2879 	struct hostap_interface *iface;
2880 	local_info_t *local;
2881 	u16 cr, val;
2882 
2883 	iface = netdev_priv(dev);
2884 	local = iface->local;
2885 
2886 	cr = *extra;
2887 	val = *(extra + 1);
2888 	if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2889 		return -EOPNOTSUPP;
2890 
2891 	return 0;
2892 }
2893 
2894 
2895 static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2896 {
2897 	struct hostap_interface *iface;
2898 	local_info_t *local;
2899 	int ret = 0;
2900 	u32 mode;
2901 
2902 	iface = netdev_priv(dev);
2903 	local = iface->local;
2904 
2905 	printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2906 	       "- update software to use iwconfig mode monitor\n",
2907 	       dev->name, task_pid_nr(current), current->comm);
2908 
2909 	/* Backward compatibility code - this can be removed at some point */
2910 
2911 	if (*i == 0) {
2912 		/* Disable monitor mode - old mode was not saved, so go to
2913 		 * Master mode */
2914 		mode = IW_MODE_MASTER;
2915 		ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2916 	} else if (*i == 1) {
2917 		/* netlink socket mode is not supported anymore since it did
2918 		 * not separate different devices from each other and was not
2919 		 * best method for delivering large amount of packets to
2920 		 * user space */
2921 		ret = -EOPNOTSUPP;
2922 	} else if (*i == 2 || *i == 3) {
2923 		switch (*i) {
2924 		case 2:
2925 			local->monitor_type = PRISM2_MONITOR_80211;
2926 			break;
2927 		case 3:
2928 			local->monitor_type = PRISM2_MONITOR_PRISM;
2929 			break;
2930 		}
2931 		mode = IW_MODE_MONITOR;
2932 		ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2933 		hostap_monitor_mode_enable(local);
2934 	} else
2935 		ret = -EINVAL;
2936 
2937 	return ret;
2938 }
2939 
2940 
2941 static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
2942 {
2943 	struct hostap_interface *iface;
2944 	local_info_t *local;
2945 
2946 	iface = netdev_priv(dev);
2947 	local = iface->local;
2948 
2949 	printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
2950 	switch (*i) {
2951 	case 0:
2952 		/* Disable and enable card */
2953 		local->func->hw_shutdown(dev, 1);
2954 		local->func->hw_config(dev, 0);
2955 		break;
2956 
2957 	case 1:
2958 		/* COR sreset */
2959 		local->func->hw_reset(dev);
2960 		break;
2961 
2962 	case 2:
2963 		/* Disable and enable port 0 */
2964 		local->func->reset_port(dev);
2965 		break;
2966 
2967 	case 3:
2968 		prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
2969 		if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
2970 				     NULL))
2971 			return -EINVAL;
2972 		break;
2973 
2974 	case 4:
2975 		if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
2976 				     NULL))
2977 			return -EINVAL;
2978 		break;
2979 
2980 	default:
2981 		printk(KERN_DEBUG "Unknown reset request %d\n", *i);
2982 		return -EOPNOTSUPP;
2983 	}
2984 
2985 	return 0;
2986 }
2987 
2988 
2989 static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
2990 {
2991 	int rid = *i;
2992 	int value = *(i + 1);
2993 
2994 	printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
2995 
2996 	if (hostap_set_word(dev, rid, value))
2997 		return -EINVAL;
2998 
2999 	return 0;
3000 }
3001 
3002 
3003 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3004 static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3005 {
3006 	int ret = 0;
3007 
3008 	switch (*cmd) {
3009 	case AP_MAC_CMD_POLICY_OPEN:
3010 		local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3011 		break;
3012 	case AP_MAC_CMD_POLICY_ALLOW:
3013 		local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3014 		break;
3015 	case AP_MAC_CMD_POLICY_DENY:
3016 		local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3017 		break;
3018 	case AP_MAC_CMD_FLUSH:
3019 		ap_control_flush_macs(&local->ap->mac_restrictions);
3020 		break;
3021 	case AP_MAC_CMD_KICKALL:
3022 		ap_control_kickall(local->ap);
3023 		hostap_deauth_all_stas(local->dev, local->ap, 0);
3024 		break;
3025 	default:
3026 		ret = -EOPNOTSUPP;
3027 		break;
3028 	}
3029 
3030 	return ret;
3031 }
3032 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3033 
3034 
3035 #ifdef PRISM2_DOWNLOAD_SUPPORT
3036 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3037 {
3038 	struct prism2_download_param *param;
3039 	int ret = 0;
3040 
3041 	if (p->length < sizeof(struct prism2_download_param) ||
3042 	    p->length > 1024 || !p->pointer)
3043 		return -EINVAL;
3044 
3045 	param = memdup_user(p->pointer, p->length);
3046 	if (IS_ERR(param)) {
3047 		return PTR_ERR(param);
3048 	}
3049 
3050 	if (p->length < sizeof(struct prism2_download_param) +
3051 	    param->num_areas * sizeof(struct prism2_download_area)) {
3052 		ret = -EINVAL;
3053 		goto out;
3054 	}
3055 
3056 	ret = local->func->download(local, param);
3057 
3058  out:
3059 	kfree(param);
3060 	return ret;
3061 }
3062 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3063 
3064 
3065 static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
3066 				     size_t len)
3067 {
3068 	struct hostap_interface *iface = netdev_priv(dev);
3069 	local_info_t *local = iface->local;
3070 	u8 *buf;
3071 
3072 	/*
3073 	 * Add 16-bit length in the beginning of the buffer because Prism2 RID
3074 	 * includes it.
3075 	 */
3076 	buf = kmalloc(len + 2, GFP_KERNEL);
3077 	if (buf == NULL)
3078 		return -ENOMEM;
3079 
3080 	*((__le16 *) buf) = cpu_to_le16(len);
3081 	memcpy(buf + 2, elem, len);
3082 
3083 	kfree(local->generic_elem);
3084 	local->generic_elem = buf;
3085 	local->generic_elem_len = len + 2;
3086 
3087 	return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
3088 				    buf, len + 2);
3089 }
3090 
3091 
3092 static int prism2_ioctl_siwauth(struct net_device *dev,
3093 				struct iw_request_info *info,
3094 				struct iw_param *data, char *extra)
3095 {
3096 	struct hostap_interface *iface = netdev_priv(dev);
3097 	local_info_t *local = iface->local;
3098 
3099 	switch (data->flags & IW_AUTH_INDEX) {
3100 	case IW_AUTH_WPA_VERSION:
3101 	case IW_AUTH_CIPHER_PAIRWISE:
3102 	case IW_AUTH_CIPHER_GROUP:
3103 	case IW_AUTH_KEY_MGMT:
3104 		/*
3105 		 * Host AP driver does not use these parameters and allows
3106 		 * wpa_supplicant to control them internally.
3107 		 */
3108 		break;
3109 	case IW_AUTH_TKIP_COUNTERMEASURES:
3110 		local->tkip_countermeasures = data->value;
3111 		break;
3112 	case IW_AUTH_DROP_UNENCRYPTED:
3113 		local->drop_unencrypted = data->value;
3114 		break;
3115 	case IW_AUTH_80211_AUTH_ALG:
3116 		local->auth_algs = data->value;
3117 		break;
3118 	case IW_AUTH_WPA_ENABLED:
3119 		if (data->value == 0) {
3120 			local->wpa = 0;
3121 			if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3122 				break;
3123 			prism2_set_genericelement(dev, "", 0);
3124 			local->host_roaming = 0;
3125 			local->privacy_invoked = 0;
3126 			if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
3127 					    0) ||
3128 			    hostap_set_roaming(local) ||
3129 			    hostap_set_encryption(local) ||
3130 			    local->func->reset_port(dev))
3131 				return -EINVAL;
3132 			break;
3133 		}
3134 		if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3135 			return -EOPNOTSUPP;
3136 		local->host_roaming = 2;
3137 		local->privacy_invoked = 1;
3138 		local->wpa = 1;
3139 		if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
3140 		    hostap_set_roaming(local) ||
3141 		    hostap_set_encryption(local) ||
3142 		    local->func->reset_port(dev))
3143 			return -EINVAL;
3144 		break;
3145 	case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3146 		local->ieee_802_1x = data->value;
3147 		break;
3148 	case IW_AUTH_PRIVACY_INVOKED:
3149 		local->privacy_invoked = data->value;
3150 		break;
3151 	default:
3152 		return -EOPNOTSUPP;
3153 	}
3154 	return 0;
3155 }
3156 
3157 
3158 static int prism2_ioctl_giwauth(struct net_device *dev,
3159 				struct iw_request_info *info,
3160 				struct iw_param *data, char *extra)
3161 {
3162 	struct hostap_interface *iface = netdev_priv(dev);
3163 	local_info_t *local = iface->local;
3164 
3165 	switch (data->flags & IW_AUTH_INDEX) {
3166 	case IW_AUTH_WPA_VERSION:
3167 	case IW_AUTH_CIPHER_PAIRWISE:
3168 	case IW_AUTH_CIPHER_GROUP:
3169 	case IW_AUTH_KEY_MGMT:
3170 		/*
3171 		 * Host AP driver does not use these parameters and allows
3172 		 * wpa_supplicant to control them internally.
3173 		 */
3174 		return -EOPNOTSUPP;
3175 	case IW_AUTH_TKIP_COUNTERMEASURES:
3176 		data->value = local->tkip_countermeasures;
3177 		break;
3178 	case IW_AUTH_DROP_UNENCRYPTED:
3179 		data->value = local->drop_unencrypted;
3180 		break;
3181 	case IW_AUTH_80211_AUTH_ALG:
3182 		data->value = local->auth_algs;
3183 		break;
3184 	case IW_AUTH_WPA_ENABLED:
3185 		data->value = local->wpa;
3186 		break;
3187 	case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3188 		data->value = local->ieee_802_1x;
3189 		break;
3190 	default:
3191 		return -EOPNOTSUPP;
3192 	}
3193 	return 0;
3194 }
3195 
3196 
3197 static int prism2_ioctl_siwencodeext(struct net_device *dev,
3198 				     struct iw_request_info *info,
3199 				     struct iw_point *erq, char *extra)
3200 {
3201 	struct hostap_interface *iface = netdev_priv(dev);
3202 	local_info_t *local = iface->local;
3203 	struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3204 	int i, ret = 0;
3205 	struct lib80211_crypto_ops *ops;
3206 	struct lib80211_crypt_data **crypt;
3207 	void *sta_ptr;
3208 	u8 *addr;
3209 	const char *alg, *module;
3210 
3211 	i = erq->flags & IW_ENCODE_INDEX;
3212 	if (i > WEP_KEYS)
3213 		return -EINVAL;
3214 	if (i < 1 || i > WEP_KEYS)
3215 		i = local->crypt_info.tx_keyidx;
3216 	else
3217 		i--;
3218 	if (i < 0 || i >= WEP_KEYS)
3219 		return -EINVAL;
3220 
3221 	addr = ext->addr.sa_data;
3222 	if (is_broadcast_ether_addr(addr)) {
3223 		sta_ptr = NULL;
3224 		crypt = &local->crypt_info.crypt[i];
3225 	} else {
3226 		if (i != 0)
3227 			return -EINVAL;
3228 		sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3229 		if (sta_ptr == NULL) {
3230 			if (local->iw_mode == IW_MODE_INFRA) {
3231 				/*
3232 				 * TODO: add STA entry for the current AP so
3233 				 * that unicast key can be used. For now, this
3234 				 * is emulated by using default key idx 0.
3235 				 */
3236 				i = 0;
3237 				crypt = &local->crypt_info.crypt[i];
3238 			} else
3239 				return -EINVAL;
3240 		}
3241 	}
3242 
3243 	if ((erq->flags & IW_ENCODE_DISABLED) ||
3244 	    ext->alg == IW_ENCODE_ALG_NONE) {
3245 		if (*crypt)
3246 			lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
3247 		goto done;
3248 	}
3249 
3250 	switch (ext->alg) {
3251 	case IW_ENCODE_ALG_WEP:
3252 		alg = "WEP";
3253 		module = "lib80211_crypt_wep";
3254 		break;
3255 	case IW_ENCODE_ALG_TKIP:
3256 		alg = "TKIP";
3257 		module = "lib80211_crypt_tkip";
3258 		break;
3259 	case IW_ENCODE_ALG_CCMP:
3260 		alg = "CCMP";
3261 		module = "lib80211_crypt_ccmp";
3262 		break;
3263 	default:
3264 		printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
3265 		       local->dev->name, ext->alg);
3266 		ret = -EOPNOTSUPP;
3267 		goto done;
3268 	}
3269 
3270 	ops = lib80211_get_crypto_ops(alg);
3271 	if (ops == NULL) {
3272 		request_module(module);
3273 		ops = lib80211_get_crypto_ops(alg);
3274 	}
3275 	if (ops == NULL) {
3276 		printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3277 		       local->dev->name, alg);
3278 		ret = -EOPNOTSUPP;
3279 		goto done;
3280 	}
3281 
3282 	if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
3283 		/*
3284 		 * Per station encryption and other than WEP algorithms
3285 		 * require host-based encryption, so force them on
3286 		 * automatically.
3287 		 */
3288 		local->host_decrypt = local->host_encrypt = 1;
3289 	}
3290 
3291 	if (*crypt == NULL || (*crypt)->ops != ops) {
3292 		struct lib80211_crypt_data *new_crypt;
3293 
3294 		lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
3295 
3296 		new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
3297 				GFP_KERNEL);
3298 		if (new_crypt == NULL) {
3299 			ret = -ENOMEM;
3300 			goto done;
3301 		}
3302 		new_crypt->ops = ops;
3303 		if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
3304 			new_crypt->priv = new_crypt->ops->init(i);
3305 		if (new_crypt->priv == NULL) {
3306 			kfree(new_crypt);
3307 			ret = -EINVAL;
3308 			goto done;
3309 		}
3310 
3311 		*crypt = new_crypt;
3312 	}
3313 
3314 	/*
3315 	 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
3316 	 * existing seq# should not be changed.
3317 	 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
3318 	 * should be changed to something else than zero.
3319 	 */
3320 	if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
3321 	    && (*crypt)->ops->set_key &&
3322 	    (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
3323 				   (*crypt)->priv) < 0) {
3324 		printk(KERN_DEBUG "%s: key setting failed\n",
3325 		       local->dev->name);
3326 		ret = -EINVAL;
3327 		goto done;
3328 	}
3329 
3330 	if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3331 		if (!sta_ptr)
3332 			local->crypt_info.tx_keyidx = i;
3333 	}
3334 
3335 
3336 	if (sta_ptr == NULL && ext->key_len > 0) {
3337 		int first = 1, j;
3338 		for (j = 0; j < WEP_KEYS; j++) {
3339 			if (j != i && local->crypt_info.crypt[j]) {
3340 				first = 0;
3341 				break;
3342 			}
3343 		}
3344 		if (first)
3345 			local->crypt_info.tx_keyidx = i;
3346 	}
3347 
3348  done:
3349 	if (sta_ptr)
3350 		hostap_handle_sta_release(sta_ptr);
3351 
3352 	local->open_wep = erq->flags & IW_ENCODE_OPEN;
3353 
3354 	/*
3355 	 * Do not reset port0 if card is in Managed mode since resetting will
3356 	 * generate new IEEE 802.11 authentication which may end up in looping
3357 	 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3358 	 * after WEP configuration. However, keys are apparently changed at
3359 	 * least in Managed mode.
3360 	 */
3361 	if (ret == 0 &&
3362 	    (hostap_set_encryption(local) ||
3363 	     (local->iw_mode != IW_MODE_INFRA &&
3364 	      local->func->reset_port(local->dev))))
3365 		ret = -EINVAL;
3366 
3367 	return ret;
3368 }
3369 
3370 
3371 static int prism2_ioctl_giwencodeext(struct net_device *dev,
3372 				     struct iw_request_info *info,
3373 				     struct iw_point *erq, char *extra)
3374 {
3375 	struct hostap_interface *iface = netdev_priv(dev);
3376 	local_info_t *local = iface->local;
3377 	struct lib80211_crypt_data **crypt;
3378 	void *sta_ptr;
3379 	int max_key_len, i;
3380 	struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3381 	u8 *addr;
3382 
3383 	max_key_len = erq->length - sizeof(*ext);
3384 	if (max_key_len < 0)
3385 		return -EINVAL;
3386 
3387 	i = erq->flags & IW_ENCODE_INDEX;
3388 	if (i < 1 || i > WEP_KEYS)
3389 		i = local->crypt_info.tx_keyidx;
3390 	else
3391 		i--;
3392 
3393 	addr = ext->addr.sa_data;
3394 	if (is_broadcast_ether_addr(addr)) {
3395 		sta_ptr = NULL;
3396 		crypt = &local->crypt_info.crypt[i];
3397 	} else {
3398 		i = 0;
3399 		sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3400 		if (sta_ptr == NULL)
3401 			return -EINVAL;
3402 	}
3403 	erq->flags = i + 1;
3404 	memset(ext, 0, sizeof(*ext));
3405 
3406 	if (*crypt == NULL || (*crypt)->ops == NULL) {
3407 		ext->alg = IW_ENCODE_ALG_NONE;
3408 		ext->key_len = 0;
3409 		erq->flags |= IW_ENCODE_DISABLED;
3410 	} else {
3411 		if (strcmp((*crypt)->ops->name, "WEP") == 0)
3412 			ext->alg = IW_ENCODE_ALG_WEP;
3413 		else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
3414 			ext->alg = IW_ENCODE_ALG_TKIP;
3415 		else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
3416 			ext->alg = IW_ENCODE_ALG_CCMP;
3417 		else
3418 			return -EINVAL;
3419 
3420 		if ((*crypt)->ops->get_key) {
3421 			ext->key_len =
3422 				(*crypt)->ops->get_key(ext->key,
3423 						       max_key_len,
3424 						       ext->tx_seq,
3425 						       (*crypt)->priv);
3426 			if (ext->key_len &&
3427 			    (ext->alg == IW_ENCODE_ALG_TKIP ||
3428 			     ext->alg == IW_ENCODE_ALG_CCMP))
3429 				ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
3430 		}
3431 	}
3432 
3433 	if (sta_ptr)
3434 		hostap_handle_sta_release(sta_ptr);
3435 
3436 	return 0;
3437 }
3438 
3439 
3440 static int prism2_ioctl_set_encryption(local_info_t *local,
3441 				       struct prism2_hostapd_param *param,
3442 				       int param_len)
3443 {
3444 	int ret = 0;
3445 	struct lib80211_crypto_ops *ops;
3446 	struct lib80211_crypt_data **crypt;
3447 	void *sta_ptr;
3448 
3449 	param->u.crypt.err = 0;
3450 	param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
3451 
3452 	if (param_len !=
3453 	    (int) ((char *) param->u.crypt.key - (char *) param) +
3454 	    param->u.crypt.key_len)
3455 		return -EINVAL;
3456 
3457 	if (is_broadcast_ether_addr(param->sta_addr)) {
3458 		if (param->u.crypt.idx >= WEP_KEYS)
3459 			return -EINVAL;
3460 		sta_ptr = NULL;
3461 		crypt = &local->crypt_info.crypt[param->u.crypt.idx];
3462 	} else {
3463 		if (param->u.crypt.idx)
3464 			return -EINVAL;
3465 		sta_ptr = ap_crypt_get_ptrs(
3466 			local->ap, param->sta_addr,
3467 			(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
3468 			&crypt);
3469 
3470 		if (sta_ptr == NULL) {
3471 			param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3472 			return -EINVAL;
3473 		}
3474 	}
3475 
3476 	if (strcmp(param->u.crypt.alg, "none") == 0) {
3477 		if (crypt)
3478 			lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
3479 		goto done;
3480 	}
3481 
3482 	ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3483 	if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3484 		request_module("lib80211_crypt_wep");
3485 		ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3486 	} else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3487 		request_module("lib80211_crypt_tkip");
3488 		ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3489 	} else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3490 		request_module("lib80211_crypt_ccmp");
3491 		ops = lib80211_get_crypto_ops(param->u.crypt.alg);
3492 	}
3493 	if (ops == NULL) {
3494 		printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3495 		       local->dev->name, param->u.crypt.alg);
3496 		param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
3497 		ret = -EINVAL;
3498 		goto done;
3499 	}
3500 
3501 	/* station based encryption and other than WEP algorithms require
3502 	 * host-based encryption, so force them on automatically */
3503 	local->host_decrypt = local->host_encrypt = 1;
3504 
3505 	if (*crypt == NULL || (*crypt)->ops != ops) {
3506 		struct lib80211_crypt_data *new_crypt;
3507 
3508 		lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
3509 
3510 		new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
3511 				GFP_KERNEL);
3512 		if (new_crypt == NULL) {
3513 			ret = -ENOMEM;
3514 			goto done;
3515 		}
3516 		new_crypt->ops = ops;
3517 		new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
3518 		if (new_crypt->priv == NULL) {
3519 			kfree(new_crypt);
3520 			param->u.crypt.err =
3521 				HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
3522 			ret = -EINVAL;
3523 			goto done;
3524 		}
3525 
3526 		*crypt = new_crypt;
3527 	}
3528 
3529 	if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
3530 	     param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
3531 	    (*crypt)->ops->set_key(param->u.crypt.key,
3532 				   param->u.crypt.key_len, param->u.crypt.seq,
3533 				   (*crypt)->priv) < 0) {
3534 		printk(KERN_DEBUG "%s: key setting failed\n",
3535 		       local->dev->name);
3536 		param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
3537 		ret = -EINVAL;
3538 		goto done;
3539 	}
3540 
3541 	if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
3542 		if (!sta_ptr)
3543 			local->crypt_info.tx_keyidx = param->u.crypt.idx;
3544 		else if (param->u.crypt.idx) {
3545 			printk(KERN_DEBUG "%s: TX key idx setting failed\n",
3546 			       local->dev->name);
3547 			param->u.crypt.err =
3548 				HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
3549 			ret = -EINVAL;
3550 			goto done;
3551 		}
3552 	}
3553 
3554  done:
3555 	if (sta_ptr)
3556 		hostap_handle_sta_release(sta_ptr);
3557 
3558 	/* Do not reset port0 if card is in Managed mode since resetting will
3559 	 * generate new IEEE 802.11 authentication which may end up in looping
3560 	 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3561 	 * after WEP configuration. However, keys are apparently changed at
3562 	 * least in Managed mode. */
3563 	if (ret == 0 &&
3564 	    (hostap_set_encryption(local) ||
3565 	     (local->iw_mode != IW_MODE_INFRA &&
3566 	      local->func->reset_port(local->dev)))) {
3567 		param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
3568 		return -EINVAL;
3569 	}
3570 
3571 	return ret;
3572 }
3573 
3574 
3575 static int prism2_ioctl_get_encryption(local_info_t *local,
3576 				       struct prism2_hostapd_param *param,
3577 				       int param_len)
3578 {
3579 	struct lib80211_crypt_data **crypt;
3580 	void *sta_ptr;
3581 	int max_key_len;
3582 
3583 	param->u.crypt.err = 0;
3584 
3585 	max_key_len = param_len -
3586 		(int) ((char *) param->u.crypt.key - (char *) param);
3587 	if (max_key_len < 0)
3588 		return -EINVAL;
3589 
3590 	if (is_broadcast_ether_addr(param->sta_addr)) {
3591 		sta_ptr = NULL;
3592 		if (param->u.crypt.idx >= WEP_KEYS)
3593 			param->u.crypt.idx = local->crypt_info.tx_keyidx;
3594 		crypt = &local->crypt_info.crypt[param->u.crypt.idx];
3595 	} else {
3596 		param->u.crypt.idx = 0;
3597 		sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
3598 					    &crypt);
3599 
3600 		if (sta_ptr == NULL) {
3601 			param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3602 			return -EINVAL;
3603 		}
3604 	}
3605 
3606 	if (*crypt == NULL || (*crypt)->ops == NULL) {
3607 		memcpy(param->u.crypt.alg, "none", 5);
3608 		param->u.crypt.key_len = 0;
3609 		param->u.crypt.idx = 0xff;
3610 	} else {
3611 		strncpy(param->u.crypt.alg, (*crypt)->ops->name,
3612 			HOSTAP_CRYPT_ALG_NAME_LEN);
3613 		param->u.crypt.key_len = 0;
3614 
3615 		memset(param->u.crypt.seq, 0, 8);
3616 		if ((*crypt)->ops->get_key) {
3617 			param->u.crypt.key_len =
3618 				(*crypt)->ops->get_key(param->u.crypt.key,
3619 						       max_key_len,
3620 						       param->u.crypt.seq,
3621 						       (*crypt)->priv);
3622 		}
3623 	}
3624 
3625 	if (sta_ptr)
3626 		hostap_handle_sta_release(sta_ptr);
3627 
3628 	return 0;
3629 }
3630 
3631 
3632 static int prism2_ioctl_get_rid(local_info_t *local,
3633 				struct prism2_hostapd_param *param,
3634 				int param_len)
3635 {
3636 	int max_len, res;
3637 
3638 	max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3639 	if (max_len < 0)
3640 		return -EINVAL;
3641 
3642 	res = local->func->get_rid(local->dev, param->u.rid.rid,
3643 				   param->u.rid.data, param->u.rid.len, 0);
3644 	if (res >= 0) {
3645 		param->u.rid.len = res;
3646 		return 0;
3647 	}
3648 
3649 	return res;
3650 }
3651 
3652 
3653 static int prism2_ioctl_set_rid(local_info_t *local,
3654 				struct prism2_hostapd_param *param,
3655 				int param_len)
3656 {
3657 	int max_len;
3658 
3659 	max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3660 	if (max_len < 0 || max_len < param->u.rid.len)
3661 		return -EINVAL;
3662 
3663 	return local->func->set_rid(local->dev, param->u.rid.rid,
3664 				    param->u.rid.data, param->u.rid.len);
3665 }
3666 
3667 
3668 static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
3669 					  struct prism2_hostapd_param *param,
3670 					  int param_len)
3671 {
3672 	printk(KERN_DEBUG "%ssta: associated as client with AP %pM\n",
3673 	       local->dev->name, param->sta_addr);
3674 	memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
3675 	return 0;
3676 }
3677 
3678 
3679 static int prism2_ioctl_siwgenie(struct net_device *dev,
3680 				 struct iw_request_info *info,
3681 				 struct iw_point *data, char *extra)
3682 {
3683 	return prism2_set_genericelement(dev, extra, data->length);
3684 }
3685 
3686 
3687 static int prism2_ioctl_giwgenie(struct net_device *dev,
3688 				 struct iw_request_info *info,
3689 				 struct iw_point *data, char *extra)
3690 {
3691 	struct hostap_interface *iface = netdev_priv(dev);
3692 	local_info_t *local = iface->local;
3693 	int len = local->generic_elem_len - 2;
3694 
3695 	if (len <= 0 || local->generic_elem == NULL) {
3696 		data->length = 0;
3697 		return 0;
3698 	}
3699 
3700 	if (data->length < len)
3701 		return -E2BIG;
3702 
3703 	data->length = len;
3704 	memcpy(extra, local->generic_elem + 2, len);
3705 
3706 	return 0;
3707 }
3708 
3709 
3710 static int prism2_ioctl_set_generic_element(local_info_t *local,
3711 					    struct prism2_hostapd_param *param,
3712 					    int param_len)
3713 {
3714 	int max_len, len;
3715 
3716 	len = param->u.generic_elem.len;
3717 	max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
3718 	if (max_len < 0 || max_len < len)
3719 		return -EINVAL;
3720 
3721 	return prism2_set_genericelement(local->dev,
3722 					 param->u.generic_elem.data, len);
3723 }
3724 
3725 
3726 static int prism2_ioctl_siwmlme(struct net_device *dev,
3727 				struct iw_request_info *info,
3728 				struct iw_point *data, char *extra)
3729 {
3730 	struct hostap_interface *iface = netdev_priv(dev);
3731 	local_info_t *local = iface->local;
3732 	struct iw_mlme *mlme = (struct iw_mlme *) extra;
3733 	__le16 reason;
3734 
3735 	reason = cpu_to_le16(mlme->reason_code);
3736 
3737 	switch (mlme->cmd) {
3738 	case IW_MLME_DEAUTH:
3739 		return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3740 					    IEEE80211_STYPE_DEAUTH,
3741 					    (u8 *) &reason, 2);
3742 	case IW_MLME_DISASSOC:
3743 		return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3744 					    IEEE80211_STYPE_DISASSOC,
3745 					    (u8 *) &reason, 2);
3746 	default:
3747 		return -EOPNOTSUPP;
3748 	}
3749 }
3750 
3751 
3752 static int prism2_ioctl_mlme(local_info_t *local,
3753 			     struct prism2_hostapd_param *param)
3754 {
3755 	__le16 reason;
3756 
3757 	reason = cpu_to_le16(param->u.mlme.reason_code);
3758 	switch (param->u.mlme.cmd) {
3759 	case MLME_STA_DEAUTH:
3760 		return prism2_sta_send_mgmt(local, param->sta_addr,
3761 					    IEEE80211_STYPE_DEAUTH,
3762 					    (u8 *) &reason, 2);
3763 	case MLME_STA_DISASSOC:
3764 		return prism2_sta_send_mgmt(local, param->sta_addr,
3765 					    IEEE80211_STYPE_DISASSOC,
3766 					    (u8 *) &reason, 2);
3767 	default:
3768 		return -EOPNOTSUPP;
3769 	}
3770 }
3771 
3772 
3773 static int prism2_ioctl_scan_req(local_info_t *local,
3774 				 struct prism2_hostapd_param *param)
3775 {
3776 #ifndef PRISM2_NO_STATION_MODES
3777 	if ((local->iw_mode != IW_MODE_INFRA &&
3778 	     local->iw_mode != IW_MODE_ADHOC) ||
3779 	    (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
3780 		return -EOPNOTSUPP;
3781 
3782 	if (!local->dev_enabled)
3783 		return -ENETDOWN;
3784 
3785 	return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
3786 				       param->u.scan_req.ssid_len);
3787 #else /* PRISM2_NO_STATION_MODES */
3788 	return -EOPNOTSUPP;
3789 #endif /* PRISM2_NO_STATION_MODES */
3790 }
3791 
3792 
3793 static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3794 {
3795 	struct prism2_hostapd_param *param;
3796 	int ret = 0;
3797 	int ap_ioctl = 0;
3798 
3799 	if (p->length < sizeof(struct prism2_hostapd_param) ||
3800 	    p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
3801 		return -EINVAL;
3802 
3803 	param = memdup_user(p->pointer, p->length);
3804 	if (IS_ERR(param)) {
3805 		return PTR_ERR(param);
3806 	}
3807 
3808 	switch (param->cmd) {
3809 	case PRISM2_SET_ENCRYPTION:
3810 		ret = prism2_ioctl_set_encryption(local, param, p->length);
3811 		break;
3812 	case PRISM2_GET_ENCRYPTION:
3813 		ret = prism2_ioctl_get_encryption(local, param, p->length);
3814 		break;
3815 	case PRISM2_HOSTAPD_GET_RID:
3816 		ret = prism2_ioctl_get_rid(local, param, p->length);
3817 		break;
3818 	case PRISM2_HOSTAPD_SET_RID:
3819 		ret = prism2_ioctl_set_rid(local, param, p->length);
3820 		break;
3821 	case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
3822 		ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
3823 		break;
3824 	case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
3825 		ret = prism2_ioctl_set_generic_element(local, param,
3826 						       p->length);
3827 		break;
3828 	case PRISM2_HOSTAPD_MLME:
3829 		ret = prism2_ioctl_mlme(local, param);
3830 		break;
3831 	case PRISM2_HOSTAPD_SCAN_REQ:
3832 		ret = prism2_ioctl_scan_req(local, param);
3833 		break;
3834 	default:
3835 		ret = prism2_hostapd(local->ap, param);
3836 		ap_ioctl = 1;
3837 		break;
3838 	}
3839 
3840 	if (ret == 1 || !ap_ioctl) {
3841 		if (copy_to_user(p->pointer, param, p->length)) {
3842 			ret = -EFAULT;
3843 			goto out;
3844 		} else if (ap_ioctl)
3845 			ret = 0;
3846 	}
3847 
3848  out:
3849 	kfree(param);
3850 	return ret;
3851 }
3852 
3853 
3854 static void prism2_get_drvinfo(struct net_device *dev,
3855 			       struct ethtool_drvinfo *info)
3856 {
3857 	struct hostap_interface *iface;
3858 	local_info_t *local;
3859 
3860 	iface = netdev_priv(dev);
3861 	local = iface->local;
3862 
3863 	strlcpy(info->driver, "hostap", sizeof(info->driver));
3864 	snprintf(info->fw_version, sizeof(info->fw_version),
3865 		 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
3866 		 (local->sta_fw_ver >> 8) & 0xff,
3867 		 local->sta_fw_ver & 0xff);
3868 }
3869 
3870 const struct ethtool_ops prism2_ethtool_ops = {
3871 	.get_drvinfo = prism2_get_drvinfo
3872 };
3873 
3874 
3875 /* Structures to export the Wireless Handlers */
3876 
3877 static const iw_handler prism2_handler[] =
3878 {
3879 	(iw_handler) NULL,				/* SIOCSIWCOMMIT */
3880 	(iw_handler) prism2_get_name,			/* SIOCGIWNAME */
3881 	(iw_handler) NULL,				/* SIOCSIWNWID */
3882 	(iw_handler) NULL,				/* SIOCGIWNWID */
3883 	(iw_handler) prism2_ioctl_siwfreq,		/* SIOCSIWFREQ */
3884 	(iw_handler) prism2_ioctl_giwfreq,		/* SIOCGIWFREQ */
3885 	(iw_handler) prism2_ioctl_siwmode,		/* SIOCSIWMODE */
3886 	(iw_handler) prism2_ioctl_giwmode,		/* SIOCGIWMODE */
3887 	(iw_handler) prism2_ioctl_siwsens,		/* SIOCSIWSENS */
3888 	(iw_handler) prism2_ioctl_giwsens,		/* SIOCGIWSENS */
3889 	(iw_handler) NULL /* not used */,		/* SIOCSIWRANGE */
3890 	(iw_handler) prism2_ioctl_giwrange,		/* SIOCGIWRANGE */
3891 	(iw_handler) NULL /* not used */,		/* SIOCSIWPRIV */
3892 	(iw_handler) NULL /* kernel code */,		/* SIOCGIWPRIV */
3893 	(iw_handler) NULL /* not used */,		/* SIOCSIWSTATS */
3894 	(iw_handler) NULL /* kernel code */,		/* SIOCGIWSTATS */
3895 	iw_handler_set_spy,				/* SIOCSIWSPY */
3896 	iw_handler_get_spy,				/* SIOCGIWSPY */
3897 	iw_handler_set_thrspy,				/* SIOCSIWTHRSPY */
3898 	iw_handler_get_thrspy,				/* SIOCGIWTHRSPY */
3899 	(iw_handler) prism2_ioctl_siwap,		/* SIOCSIWAP */
3900 	(iw_handler) prism2_ioctl_giwap,		/* SIOCGIWAP */
3901 	(iw_handler) prism2_ioctl_siwmlme,		/* SIOCSIWMLME */
3902 	(iw_handler) prism2_ioctl_giwaplist,		/* SIOCGIWAPLIST */
3903 	(iw_handler) prism2_ioctl_siwscan,		/* SIOCSIWSCAN */
3904 	(iw_handler) prism2_ioctl_giwscan,		/* SIOCGIWSCAN */
3905 	(iw_handler) prism2_ioctl_siwessid,		/* SIOCSIWESSID */
3906 	(iw_handler) prism2_ioctl_giwessid,		/* SIOCGIWESSID */
3907 	(iw_handler) prism2_ioctl_siwnickn,		/* SIOCSIWNICKN */
3908 	(iw_handler) prism2_ioctl_giwnickn,		/* SIOCGIWNICKN */
3909 	(iw_handler) NULL,				/* -- hole -- */
3910 	(iw_handler) NULL,				/* -- hole -- */
3911 	(iw_handler) prism2_ioctl_siwrate,		/* SIOCSIWRATE */
3912 	(iw_handler) prism2_ioctl_giwrate,		/* SIOCGIWRATE */
3913 	(iw_handler) prism2_ioctl_siwrts,		/* SIOCSIWRTS */
3914 	(iw_handler) prism2_ioctl_giwrts,		/* SIOCGIWRTS */
3915 	(iw_handler) prism2_ioctl_siwfrag,		/* SIOCSIWFRAG */
3916 	(iw_handler) prism2_ioctl_giwfrag,		/* SIOCGIWFRAG */
3917 	(iw_handler) prism2_ioctl_siwtxpow,		/* SIOCSIWTXPOW */
3918 	(iw_handler) prism2_ioctl_giwtxpow,		/* SIOCGIWTXPOW */
3919 	(iw_handler) prism2_ioctl_siwretry,		/* SIOCSIWRETRY */
3920 	(iw_handler) prism2_ioctl_giwretry,		/* SIOCGIWRETRY */
3921 	(iw_handler) prism2_ioctl_siwencode,		/* SIOCSIWENCODE */
3922 	(iw_handler) prism2_ioctl_giwencode,		/* SIOCGIWENCODE */
3923 	(iw_handler) prism2_ioctl_siwpower,		/* SIOCSIWPOWER */
3924 	(iw_handler) prism2_ioctl_giwpower,		/* SIOCGIWPOWER */
3925 	(iw_handler) NULL,				/* -- hole -- */
3926 	(iw_handler) NULL,				/* -- hole -- */
3927 	(iw_handler) prism2_ioctl_siwgenie,		/* SIOCSIWGENIE */
3928 	(iw_handler) prism2_ioctl_giwgenie,		/* SIOCGIWGENIE */
3929 	(iw_handler) prism2_ioctl_siwauth,		/* SIOCSIWAUTH */
3930 	(iw_handler) prism2_ioctl_giwauth,		/* SIOCGIWAUTH */
3931 	(iw_handler) prism2_ioctl_siwencodeext,		/* SIOCSIWENCODEEXT */
3932 	(iw_handler) prism2_ioctl_giwencodeext,		/* SIOCGIWENCODEEXT */
3933 	(iw_handler) NULL,				/* SIOCSIWPMKSA */
3934 	(iw_handler) NULL,				/* -- hole -- */
3935 };
3936 
3937 static const iw_handler prism2_private_handler[] =
3938 {							/* SIOCIWFIRSTPRIV + */
3939 	(iw_handler) prism2_ioctl_priv_prism2_param,	/* 0 */
3940 	(iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
3941 	(iw_handler) prism2_ioctl_priv_writemif,	/* 2 */
3942 	(iw_handler) prism2_ioctl_priv_readmif,		/* 3 */
3943 };
3944 
3945 const struct iw_handler_def hostap_iw_handler_def =
3946 {
3947 	.num_standard	= ARRAY_SIZE(prism2_handler),
3948 	.num_private	= ARRAY_SIZE(prism2_private_handler),
3949 	.num_private_args = ARRAY_SIZE(prism2_priv),
3950 	.standard	= (iw_handler *) prism2_handler,
3951 	.private	= (iw_handler *) prism2_private_handler,
3952 	.private_args	= (struct iw_priv_args *) prism2_priv,
3953 	.get_wireless_stats = hostap_get_wireless_stats,
3954 };
3955 
3956 
3957 int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
3958 {
3959 	struct iwreq *wrq = (struct iwreq *) ifr;
3960 	struct hostap_interface *iface;
3961 	local_info_t *local;
3962 	int ret = 0;
3963 
3964 	iface = netdev_priv(dev);
3965 	local = iface->local;
3966 
3967 	switch (cmd) {
3968 		/* Private ioctls (iwpriv) that have not yet been converted
3969 		 * into new wireless extensions API */
3970 
3971 	case PRISM2_IOCTL_INQUIRE:
3972 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
3973 		else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
3974 		break;
3975 
3976 	case PRISM2_IOCTL_MONITOR:
3977 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
3978 		else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
3979 		break;
3980 
3981 	case PRISM2_IOCTL_RESET:
3982 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
3983 		else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
3984 		break;
3985 
3986 	case PRISM2_IOCTL_WDS_ADD:
3987 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
3988 		else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
3989 		break;
3990 
3991 	case PRISM2_IOCTL_WDS_DEL:
3992 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
3993 		else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
3994 		break;
3995 
3996 	case PRISM2_IOCTL_SET_RID_WORD:
3997 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
3998 		else ret = prism2_ioctl_priv_set_rid_word(dev,
3999 							  (int *) wrq->u.name);
4000 		break;
4001 
4002 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
4003 	case PRISM2_IOCTL_MACCMD:
4004 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4005 		else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
4006 		break;
4007 
4008 	case PRISM2_IOCTL_ADDMAC:
4009 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4010 		else ret = ap_control_add_mac(&local->ap->mac_restrictions,
4011 					      wrq->u.ap_addr.sa_data);
4012 		break;
4013 	case PRISM2_IOCTL_DELMAC:
4014 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4015 		else ret = ap_control_del_mac(&local->ap->mac_restrictions,
4016 					      wrq->u.ap_addr.sa_data);
4017 		break;
4018 	case PRISM2_IOCTL_KICKMAC:
4019 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4020 		else ret = ap_control_kick_mac(local->ap, local->dev,
4021 					       wrq->u.ap_addr.sa_data);
4022 		break;
4023 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
4024 
4025 
4026 		/* Private ioctls that are not used with iwpriv;
4027 		 * in SIOCDEVPRIVATE range */
4028 
4029 #ifdef PRISM2_DOWNLOAD_SUPPORT
4030 	case PRISM2_IOCTL_DOWNLOAD:
4031 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4032 		else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
4033 		break;
4034 #endif /* PRISM2_DOWNLOAD_SUPPORT */
4035 
4036 	case PRISM2_IOCTL_HOSTAPD:
4037 		if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4038 		else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);
4039 		break;
4040 
4041 	default:
4042 		ret = -EOPNOTSUPP;
4043 		break;
4044 	}
4045 
4046 	return ret;
4047 }
4048