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