[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / net / wireless / hostap / hostap_ioctl.c
blob9419cebca8a582f8d9dab12bc442a67409ddebea
1 /* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
3 #include <linux/types.h>
4 #include <linux/sched.h>
5 #include <linux/ethtool.h>
6 #include <linux/if_arp.h>
7 #include <net/lib80211.h>
9 #include "hostap_wlan.h"
10 #include "hostap.h"
11 #include "hostap_ap.h"
13 static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
15 struct hostap_interface *iface;
16 local_info_t *local;
17 struct iw_statistics *wstats;
19 iface = netdev_priv(dev);
20 local = iface->local;
22 /* Why are we doing that ? Jean II */
23 if (iface->type != HOSTAP_INTERFACE_MAIN)
24 return NULL;
26 wstats = &local->wstats;
28 wstats->status = 0;
29 wstats->discard.code =
30 local->comm_tallies.rx_discards_wep_undecryptable;
31 wstats->discard.misc =
32 local->comm_tallies.rx_fcs_errors +
33 local->comm_tallies.rx_discards_no_buffer +
34 local->comm_tallies.tx_discards_wrong_sa;
36 wstats->discard.retries =
37 local->comm_tallies.tx_retry_limit_exceeded;
38 wstats->discard.fragment =
39 local->comm_tallies.rx_message_in_bad_msg_fragments;
41 if (local->iw_mode != IW_MODE_MASTER &&
42 local->iw_mode != IW_MODE_REPEAT) {
43 int update = 1;
44 #ifdef in_atomic
45 /* RID reading might sleep and it must not be called in
46 * interrupt context or while atomic. However, this
47 * function seems to be called while atomic (at least in Linux
48 * 2.5.59). Update signal quality values only if in suitable
49 * context. Otherwise, previous values read from tick timer
50 * will be used. */
51 if (in_atomic())
52 update = 0;
53 #endif /* in_atomic */
55 if (update && prism2_update_comms_qual(dev) == 0)
56 wstats->qual.updated = IW_QUAL_ALL_UPDATED |
57 IW_QUAL_DBM;
59 wstats->qual.qual = local->comms_qual;
60 wstats->qual.level = local->avg_signal;
61 wstats->qual.noise = local->avg_noise;
62 } else {
63 wstats->qual.qual = 0;
64 wstats->qual.level = 0;
65 wstats->qual.noise = 0;
66 wstats->qual.updated = IW_QUAL_ALL_INVALID;
69 return wstats;
73 static int prism2_get_datarates(struct net_device *dev, u8 *rates)
75 struct hostap_interface *iface;
76 local_info_t *local;
77 u8 buf[12];
78 int len;
79 u16 val;
81 iface = netdev_priv(dev);
82 local = iface->local;
84 len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
85 sizeof(buf), 0);
86 if (len < 2)
87 return 0;
89 val = le16_to_cpu(*(__le16 *) buf); /* string length */
91 if (len - 2 < val || val > 10)
92 return 0;
94 memcpy(rates, buf + 2, val);
95 return val;
99 static int prism2_get_name(struct net_device *dev,
100 struct iw_request_info *info,
101 char *name, char *extra)
103 u8 rates[10];
104 int len, i, over2 = 0;
106 len = prism2_get_datarates(dev, rates);
108 for (i = 0; i < len; i++) {
109 if (rates[i] == 0x0b || rates[i] == 0x16) {
110 over2 = 1;
111 break;
115 strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
117 return 0;
121 static int prism2_ioctl_siwencode(struct net_device *dev,
122 struct iw_request_info *info,
123 struct iw_point *erq, char *keybuf)
125 struct hostap_interface *iface;
126 local_info_t *local;
127 int i;
128 struct lib80211_crypt_data **crypt;
130 iface = netdev_priv(dev);
131 local = iface->local;
133 i = erq->flags & IW_ENCODE_INDEX;
134 if (i < 1 || i > 4)
135 i = local->crypt_info.tx_keyidx;
136 else
137 i--;
138 if (i < 0 || i >= WEP_KEYS)
139 return -EINVAL;
141 crypt = &local->crypt_info.crypt[i];
143 if (erq->flags & IW_ENCODE_DISABLED) {
144 if (*crypt)
145 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
146 goto done;
149 if (*crypt != NULL && (*crypt)->ops != NULL &&
150 strcmp((*crypt)->ops->name, "WEP") != 0) {
151 /* changing to use WEP; deinit previously used algorithm */
152 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
155 if (*crypt == NULL) {
156 struct lib80211_crypt_data *new_crypt;
158 /* take WEP into use */
159 new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
160 GFP_KERNEL);
161 if (new_crypt == NULL)
162 return -ENOMEM;
163 new_crypt->ops = lib80211_get_crypto_ops("WEP");
164 if (!new_crypt->ops) {
165 request_module("lib80211_crypt_wep");
166 new_crypt->ops = lib80211_get_crypto_ops("WEP");
168 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
169 new_crypt->priv = new_crypt->ops->init(i);
170 if (!new_crypt->ops || !new_crypt->priv) {
171 kfree(new_crypt);
172 new_crypt = NULL;
174 printk(KERN_WARNING "%s: could not initialize WEP: "
175 "load module hostap_crypt_wep.o\n",
176 dev->name);
177 return -EOPNOTSUPP;
179 *crypt = new_crypt;
182 if (erq->length > 0) {
183 int len = erq->length <= 5 ? 5 : 13;
184 int first = 1, j;
185 if (len > erq->length)
186 memset(keybuf + erq->length, 0, len - erq->length);
187 (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
188 for (j = 0; j < WEP_KEYS; j++) {
189 if (j != i && local->crypt_info.crypt[j]) {
190 first = 0;
191 break;
194 if (first)
195 local->crypt_info.tx_keyidx = i;
196 } else {
197 /* No key data - just set the default TX key index */
198 local->crypt_info.tx_keyidx = i;
201 done:
202 local->open_wep = erq->flags & IW_ENCODE_OPEN;
204 if (hostap_set_encryption(local)) {
205 printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
206 return -EINVAL;
209 /* Do not reset port0 if card is in Managed mode since resetting will
210 * generate new IEEE 802.11 authentication which may end up in looping
211 * with IEEE 802.1X. Prism2 documentation seem to require port reset
212 * after WEP configuration. However, keys are apparently changed at
213 * least in Managed mode. */
214 if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
215 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
216 return -EINVAL;
219 return 0;
223 static int prism2_ioctl_giwencode(struct net_device *dev,
224 struct iw_request_info *info,
225 struct iw_point *erq, char *key)
227 struct hostap_interface *iface;
228 local_info_t *local;
229 int i, len;
230 u16 val;
231 struct lib80211_crypt_data *crypt;
233 iface = netdev_priv(dev);
234 local = iface->local;
236 i = erq->flags & IW_ENCODE_INDEX;
237 if (i < 1 || i > 4)
238 i = local->crypt_info.tx_keyidx;
239 else
240 i--;
241 if (i < 0 || i >= WEP_KEYS)
242 return -EINVAL;
244 crypt = local->crypt_info.crypt[i];
245 erq->flags = i + 1;
247 if (crypt == NULL || crypt->ops == NULL) {
248 erq->length = 0;
249 erq->flags |= IW_ENCODE_DISABLED;
250 return 0;
253 if (strcmp(crypt->ops->name, "WEP") != 0) {
254 /* only WEP is supported with wireless extensions, so just
255 * report that encryption is used */
256 erq->length = 0;
257 erq->flags |= IW_ENCODE_ENABLED;
258 return 0;
261 /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
262 * the keys from driver buffer */
263 len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
264 erq->length = (len >= 0 ? len : 0);
266 if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
268 printk("CNFWEPFLAGS reading failed\n");
269 return -EOPNOTSUPP;
271 le16_to_cpus(&val);
272 if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
273 erq->flags |= IW_ENCODE_ENABLED;
274 else
275 erq->flags |= IW_ENCODE_DISABLED;
276 if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
277 erq->flags |= IW_ENCODE_RESTRICTED;
278 else
279 erq->flags |= IW_ENCODE_OPEN;
281 return 0;
285 static int hostap_set_rate(struct net_device *dev)
287 struct hostap_interface *iface;
288 local_info_t *local;
289 int ret, basic_rates;
291 iface = netdev_priv(dev);
292 local = iface->local;
294 basic_rates = local->basic_rates & local->tx_rate_control;
295 if (!basic_rates || basic_rates != local->basic_rates) {
296 printk(KERN_INFO "%s: updating basic rate set automatically "
297 "to match with the new supported rate set\n",
298 dev->name);
299 if (!basic_rates)
300 basic_rates = local->tx_rate_control;
302 local->basic_rates = basic_rates;
303 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
304 basic_rates))
305 printk(KERN_WARNING "%s: failed to set "
306 "cnfBasicRates\n", dev->name);
309 ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
310 local->tx_rate_control) ||
311 hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
312 local->tx_rate_control) ||
313 local->func->reset_port(dev));
315 if (ret) {
316 printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
317 "setting to 0x%x failed\n",
318 dev->name, local->tx_rate_control);
321 /* Update TX rate configuration for all STAs based on new operational
322 * rate set. */
323 hostap_update_rates(local);
325 return ret;
329 static int prism2_ioctl_siwrate(struct net_device *dev,
330 struct iw_request_info *info,
331 struct iw_param *rrq, char *extra)
333 struct hostap_interface *iface;
334 local_info_t *local;
336 iface = netdev_priv(dev);
337 local = iface->local;
339 if (rrq->fixed) {
340 switch (rrq->value) {
341 case 11000000:
342 local->tx_rate_control = HFA384X_RATES_11MBPS;
343 break;
344 case 5500000:
345 local->tx_rate_control = HFA384X_RATES_5MBPS;
346 break;
347 case 2000000:
348 local->tx_rate_control = HFA384X_RATES_2MBPS;
349 break;
350 case 1000000:
351 local->tx_rate_control = HFA384X_RATES_1MBPS;
352 break;
353 default:
354 local->tx_rate_control = HFA384X_RATES_1MBPS |
355 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
356 HFA384X_RATES_11MBPS;
357 break;
359 } else {
360 switch (rrq->value) {
361 case 11000000:
362 local->tx_rate_control = HFA384X_RATES_1MBPS |
363 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
364 HFA384X_RATES_11MBPS;
365 break;
366 case 5500000:
367 local->tx_rate_control = HFA384X_RATES_1MBPS |
368 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
369 break;
370 case 2000000:
371 local->tx_rate_control = HFA384X_RATES_1MBPS |
372 HFA384X_RATES_2MBPS;
373 break;
374 case 1000000:
375 local->tx_rate_control = HFA384X_RATES_1MBPS;
376 break;
377 default:
378 local->tx_rate_control = HFA384X_RATES_1MBPS |
379 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
380 HFA384X_RATES_11MBPS;
381 break;
385 return hostap_set_rate(dev);
389 static int prism2_ioctl_giwrate(struct net_device *dev,
390 struct iw_request_info *info,
391 struct iw_param *rrq, char *extra)
393 u16 val;
394 struct hostap_interface *iface;
395 local_info_t *local;
396 int ret = 0;
398 iface = netdev_priv(dev);
399 local = iface->local;
401 if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
403 return -EINVAL;
405 if ((val & 0x1) && (val > 1))
406 rrq->fixed = 0;
407 else
408 rrq->fixed = 1;
410 if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
411 !local->fw_tx_rate_control) {
412 /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
413 * Host AP mode, so use the recorded TX rate of the last sent
414 * frame */
415 rrq->value = local->ap->last_tx_rate > 0 ?
416 local->ap->last_tx_rate * 100000 : 11000000;
417 return 0;
420 if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
422 return -EINVAL;
424 switch (val) {
425 case HFA384X_RATES_1MBPS:
426 rrq->value = 1000000;
427 break;
428 case HFA384X_RATES_2MBPS:
429 rrq->value = 2000000;
430 break;
431 case HFA384X_RATES_5MBPS:
432 rrq->value = 5500000;
433 break;
434 case HFA384X_RATES_11MBPS:
435 rrq->value = 11000000;
436 break;
437 default:
438 /* should not happen */
439 rrq->value = 11000000;
440 ret = -EINVAL;
441 break;
444 return ret;
448 static int prism2_ioctl_siwsens(struct net_device *dev,
449 struct iw_request_info *info,
450 struct iw_param *sens, char *extra)
452 struct hostap_interface *iface;
453 local_info_t *local;
455 iface = netdev_priv(dev);
456 local = iface->local;
458 /* Set the desired AP density */
459 if (sens->value < 1 || sens->value > 3)
460 return -EINVAL;
462 if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
463 local->func->reset_port(dev))
464 return -EINVAL;
466 return 0;
469 static int prism2_ioctl_giwsens(struct net_device *dev,
470 struct iw_request_info *info,
471 struct iw_param *sens, char *extra)
473 struct hostap_interface *iface;
474 local_info_t *local;
475 __le16 val;
477 iface = netdev_priv(dev);
478 local = iface->local;
480 /* Get the current AP density */
481 if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
483 return -EINVAL;
485 sens->value = le16_to_cpu(val);
486 sens->fixed = 1;
488 return 0;
492 /* Deprecated in new wireless extension API */
493 static int prism2_ioctl_giwaplist(struct net_device *dev,
494 struct iw_request_info *info,
495 struct iw_point *data, char *extra)
497 struct hostap_interface *iface;
498 local_info_t *local;
499 struct sockaddr *addr;
500 struct iw_quality *qual;
502 iface = netdev_priv(dev);
503 local = iface->local;
505 if (local->iw_mode != IW_MODE_MASTER) {
506 printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
507 "in Host AP mode\n");
508 data->length = 0;
509 return -EOPNOTSUPP;
512 addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
513 qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
514 if (addr == NULL || qual == NULL) {
515 kfree(addr);
516 kfree(qual);
517 data->length = 0;
518 return -ENOMEM;
521 data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
523 memcpy(extra, &addr, sizeof(struct sockaddr) * data->length);
524 data->flags = 1; /* has quality information */
525 memcpy(extra + sizeof(struct sockaddr) * data->length, &qual,
526 sizeof(struct iw_quality) * data->length);
528 kfree(addr);
529 kfree(qual);
530 return 0;
534 static int prism2_ioctl_siwrts(struct net_device *dev,
535 struct iw_request_info *info,
536 struct iw_param *rts, char *extra)
538 struct hostap_interface *iface;
539 local_info_t *local;
540 __le16 val;
542 iface = netdev_priv(dev);
543 local = iface->local;
545 if (rts->disabled)
546 val = cpu_to_le16(2347);
547 else if (rts->value < 0 || rts->value > 2347)
548 return -EINVAL;
549 else
550 val = cpu_to_le16(rts->value);
552 if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) ||
553 local->func->reset_port(dev))
554 return -EINVAL;
556 local->rts_threshold = rts->value;
558 return 0;
561 static int prism2_ioctl_giwrts(struct net_device *dev,
562 struct iw_request_info *info,
563 struct iw_param *rts, char *extra)
565 struct hostap_interface *iface;
566 local_info_t *local;
567 __le16 val;
569 iface = netdev_priv(dev);
570 local = iface->local;
572 if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) <
574 return -EINVAL;
576 rts->value = le16_to_cpu(val);
577 rts->disabled = (rts->value == 2347);
578 rts->fixed = 1;
580 return 0;
584 static int prism2_ioctl_siwfrag(struct net_device *dev,
585 struct iw_request_info *info,
586 struct iw_param *rts, char *extra)
588 struct hostap_interface *iface;
589 local_info_t *local;
590 __le16 val;
592 iface = netdev_priv(dev);
593 local = iface->local;
595 if (rts->disabled)
596 val = cpu_to_le16(2346);
597 else if (rts->value < 256 || rts->value > 2346)
598 return -EINVAL;
599 else
600 val = cpu_to_le16(rts->value & ~0x1); /* even numbers only */
602 local->fragm_threshold = rts->value & ~0x1;
603 if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val,
605 || local->func->reset_port(dev))
606 return -EINVAL;
608 return 0;
611 static int prism2_ioctl_giwfrag(struct net_device *dev,
612 struct iw_request_info *info,
613 struct iw_param *rts, char *extra)
615 struct hostap_interface *iface;
616 local_info_t *local;
617 __le16 val;
619 iface = netdev_priv(dev);
620 local = iface->local;
622 if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
623 &val, 2, 1) < 0)
624 return -EINVAL;
626 rts->value = le16_to_cpu(val);
627 rts->disabled = (rts->value == 2346);
628 rts->fixed = 1;
630 return 0;
634 #ifndef PRISM2_NO_STATION_MODES
635 static int hostap_join_ap(struct net_device *dev)
637 struct hostap_interface *iface;
638 local_info_t *local;
639 struct hfa384x_join_request req;
640 unsigned long flags;
641 int i;
642 struct hfa384x_hostscan_result *entry;
644 iface = netdev_priv(dev);
645 local = iface->local;
647 memcpy(req.bssid, local->preferred_ap, ETH_ALEN);
648 req.channel = 0;
650 spin_lock_irqsave(&local->lock, flags);
651 for (i = 0; i < local->last_scan_results_count; i++) {
652 if (!local->last_scan_results)
653 break;
654 entry = &local->last_scan_results[i];
655 if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) {
656 req.channel = entry->chid;
657 break;
660 spin_unlock_irqrestore(&local->lock, flags);
662 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
663 sizeof(req))) {
664 printk(KERN_DEBUG "%s: JoinRequest %pM failed\n",
665 dev->name, local->preferred_ap);
666 return -1;
669 printk(KERN_DEBUG "%s: Trying to join BSSID %pM\n",
670 dev->name, local->preferred_ap);
672 return 0;
674 #endif /* PRISM2_NO_STATION_MODES */
677 static int prism2_ioctl_siwap(struct net_device *dev,
678 struct iw_request_info *info,
679 struct sockaddr *ap_addr, char *extra)
681 #ifdef PRISM2_NO_STATION_MODES
682 return -EOPNOTSUPP;
683 #else /* PRISM2_NO_STATION_MODES */
684 struct hostap_interface *iface;
685 local_info_t *local;
687 iface = netdev_priv(dev);
688 local = iface->local;
690 memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN);
692 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) {
693 struct hfa384x_scan_request scan_req;
694 memset(&scan_req, 0, sizeof(scan_req));
695 scan_req.channel_list = cpu_to_le16(0x3fff);
696 scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
697 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST,
698 &scan_req, sizeof(scan_req))) {
699 printk(KERN_DEBUG "%s: ScanResults request failed - "
700 "preferred AP delayed to next unsolicited "
701 "scan\n", dev->name);
703 } else if (local->host_roaming == 2 &&
704 local->iw_mode == IW_MODE_INFRA) {
705 if (hostap_join_ap(dev))
706 return -EINVAL;
707 } else {
708 printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only "
709 "in Managed mode when host_roaming is enabled\n",
710 dev->name);
713 return 0;
714 #endif /* PRISM2_NO_STATION_MODES */
717 static int prism2_ioctl_giwap(struct net_device *dev,
718 struct iw_request_info *info,
719 struct sockaddr *ap_addr, char *extra)
721 struct hostap_interface *iface;
722 local_info_t *local;
724 iface = netdev_priv(dev);
725 local = iface->local;
727 ap_addr->sa_family = ARPHRD_ETHER;
728 switch (iface->type) {
729 case HOSTAP_INTERFACE_AP:
730 memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN);
731 break;
732 case HOSTAP_INTERFACE_STA:
733 memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN);
734 break;
735 case HOSTAP_INTERFACE_WDS:
736 memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN);
737 break;
738 default:
739 if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID,
740 &ap_addr->sa_data, ETH_ALEN, 1) < 0)
741 return -EOPNOTSUPP;
743 /* local->bssid is also updated in LinkStatus handler when in
744 * station mode */
745 memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN);
746 break;
749 return 0;
753 static int prism2_ioctl_siwnickn(struct net_device *dev,
754 struct iw_request_info *info,
755 struct iw_point *data, char *nickname)
757 struct hostap_interface *iface;
758 local_info_t *local;
760 iface = netdev_priv(dev);
761 local = iface->local;
763 memset(local->name, 0, sizeof(local->name));
764 memcpy(local->name, nickname, data->length);
765 local->name_set = 1;
767 if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) ||
768 local->func->reset_port(dev))
769 return -EINVAL;
771 return 0;
774 static int prism2_ioctl_giwnickn(struct net_device *dev,
775 struct iw_request_info *info,
776 struct iw_point *data, char *nickname)
778 struct hostap_interface *iface;
779 local_info_t *local;
780 int len;
781 char name[MAX_NAME_LEN + 3];
782 u16 val;
784 iface = netdev_priv(dev);
785 local = iface->local;
787 len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME,
788 &name, MAX_NAME_LEN + 2, 0);
789 val = le16_to_cpu(*(__le16 *) name);
790 if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN)
791 return -EOPNOTSUPP;
793 name[val + 2] = '\0';
794 data->length = val + 1;
795 memcpy(nickname, name + 2, val + 1);
797 return 0;
801 static int prism2_ioctl_siwfreq(struct net_device *dev,
802 struct iw_request_info *info,
803 struct iw_freq *freq, char *extra)
805 struct hostap_interface *iface;
806 local_info_t *local;
808 iface = netdev_priv(dev);
809 local = iface->local;
811 /* freq => chan. */
812 if (freq->e == 1 &&
813 freq->m / 100000 >= freq_list[0] &&
814 freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) {
815 int ch;
816 int fr = freq->m / 100000;
817 for (ch = 0; ch < FREQ_COUNT; ch++) {
818 if (fr == freq_list[ch]) {
819 freq->e = 0;
820 freq->m = ch + 1;
821 break;
826 if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT ||
827 !(local->channel_mask & (1 << (freq->m - 1))))
828 return -EINVAL;
830 local->channel = freq->m; /* channel is used in prism2_setup_rids() */
831 if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) ||
832 local->func->reset_port(dev))
833 return -EINVAL;
835 return 0;
838 static int prism2_ioctl_giwfreq(struct net_device *dev,
839 struct iw_request_info *info,
840 struct iw_freq *freq, char *extra)
842 struct hostap_interface *iface;
843 local_info_t *local;
844 u16 val;
846 iface = netdev_priv(dev);
847 local = iface->local;
849 if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) <
851 return -EINVAL;
853 le16_to_cpus(&val);
854 if (val < 1 || val > FREQ_COUNT)
855 return -EINVAL;
857 freq->m = freq_list[val - 1] * 100000;
858 freq->e = 1;
860 return 0;
864 static void hostap_monitor_set_type(local_info_t *local)
866 struct net_device *dev = local->ddev;
868 if (dev == NULL)
869 return;
871 if (local->monitor_type == PRISM2_MONITOR_PRISM ||
872 local->monitor_type == PRISM2_MONITOR_CAPHDR) {
873 dev->type = ARPHRD_IEEE80211_PRISM;
874 } else if (local->monitor_type == PRISM2_MONITOR_RADIOTAP) {
875 dev->type = ARPHRD_IEEE80211_RADIOTAP;
876 } else {
877 dev->type = ARPHRD_IEEE80211;
882 static int prism2_ioctl_siwessid(struct net_device *dev,
883 struct iw_request_info *info,
884 struct iw_point *data, char *ssid)
886 struct hostap_interface *iface;
887 local_info_t *local;
889 iface = netdev_priv(dev);
890 local = iface->local;
892 if (iface->type == HOSTAP_INTERFACE_WDS)
893 return -EOPNOTSUPP;
895 if (data->flags == 0)
896 ssid[0] = '\0'; /* ANY */
898 if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') {
899 /* Setting SSID to empty string seems to kill the card in
900 * Host AP mode */
901 printk(KERN_DEBUG "%s: Host AP mode does not support "
902 "'Any' essid\n", dev->name);
903 return -EINVAL;
906 memcpy(local->essid, ssid, data->length);
907 local->essid[data->length] = '\0';
909 if ((!local->fw_ap &&
910 hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid))
911 || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) ||
912 local->func->reset_port(dev))
913 return -EINVAL;
915 return 0;
918 static int prism2_ioctl_giwessid(struct net_device *dev,
919 struct iw_request_info *info,
920 struct iw_point *data, char *essid)
922 struct hostap_interface *iface;
923 local_info_t *local;
924 u16 val;
926 iface = netdev_priv(dev);
927 local = iface->local;
929 if (iface->type == HOSTAP_INTERFACE_WDS)
930 return -EOPNOTSUPP;
932 data->flags = 1; /* active */
933 if (local->iw_mode == IW_MODE_MASTER) {
934 data->length = strlen(local->essid);
935 memcpy(essid, local->essid, IW_ESSID_MAX_SIZE);
936 } else {
937 int len;
938 char ssid[MAX_SSID_LEN + 2];
939 memset(ssid, 0, sizeof(ssid));
940 len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID,
941 &ssid, MAX_SSID_LEN + 2, 0);
942 val = le16_to_cpu(*(__le16 *) ssid);
943 if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) {
944 return -EOPNOTSUPP;
946 data->length = val;
947 memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE);
950 return 0;
954 static int prism2_ioctl_giwrange(struct net_device *dev,
955 struct iw_request_info *info,
956 struct iw_point *data, char *extra)
958 struct hostap_interface *iface;
959 local_info_t *local;
960 struct iw_range *range = (struct iw_range *) extra;
961 u8 rates[10];
962 u16 val;
963 int i, len, over2;
965 iface = netdev_priv(dev);
966 local = iface->local;
968 data->length = sizeof(struct iw_range);
969 memset(range, 0, sizeof(struct iw_range));
971 /* TODO: could fill num_txpower and txpower array with
972 * something; however, there are 128 different values.. */
974 range->txpower_capa = IW_TXPOW_DBM;
976 if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC)
978 range->min_pmp = 1 * 1024;
979 range->max_pmp = 65535 * 1024;
980 range->min_pmt = 1 * 1024;
981 range->max_pmt = 1000 * 1024;
982 range->pmp_flags = IW_POWER_PERIOD;
983 range->pmt_flags = IW_POWER_TIMEOUT;
984 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
985 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
988 range->we_version_compiled = WIRELESS_EXT;
989 range->we_version_source = 18;
991 range->retry_capa = IW_RETRY_LIMIT;
992 range->retry_flags = IW_RETRY_LIMIT;
993 range->min_retry = 0;
994 range->max_retry = 255;
996 range->num_channels = FREQ_COUNT;
998 val = 0;
999 for (i = 0; i < FREQ_COUNT; i++) {
1000 if (local->channel_mask & (1 << i)) {
1001 range->freq[val].i = i + 1;
1002 range->freq[val].m = freq_list[i] * 100000;
1003 range->freq[val].e = 1;
1004 val++;
1006 if (val == IW_MAX_FREQUENCIES)
1007 break;
1009 range->num_frequency = val;
1011 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1012 range->max_qual.qual = 70; /* what is correct max? This was not
1013 * documented exactly. At least
1014 * 69 has been observed. */
1015 range->max_qual.level = 0; /* dB */
1016 range->max_qual.noise = 0; /* dB */
1018 /* What would be suitable values for "average/typical" qual? */
1019 range->avg_qual.qual = 20;
1020 range->avg_qual.level = -60;
1021 range->avg_qual.noise = -95;
1022 } else {
1023 range->max_qual.qual = 92; /* 0 .. 92 */
1024 range->max_qual.level = 154; /* 27 .. 154 */
1025 range->max_qual.noise = 154; /* 27 .. 154 */
1027 range->sensitivity = 3;
1029 range->max_encoding_tokens = WEP_KEYS;
1030 range->num_encoding_sizes = 2;
1031 range->encoding_size[0] = 5;
1032 range->encoding_size[1] = 13;
1034 over2 = 0;
1035 len = prism2_get_datarates(dev, rates);
1036 range->num_bitrates = 0;
1037 for (i = 0; i < len; i++) {
1038 if (range->num_bitrates < IW_MAX_BITRATES) {
1039 range->bitrate[range->num_bitrates] =
1040 rates[i] * 500000;
1041 range->num_bitrates++;
1043 if (rates[i] == 0x0b || rates[i] == 0x16)
1044 over2 = 1;
1046 /* estimated maximum TCP throughput values (bps) */
1047 range->throughput = over2 ? 5500000 : 1500000;
1049 range->min_rts = 0;
1050 range->max_rts = 2347;
1051 range->min_frag = 256;
1052 range->max_frag = 2346;
1054 /* Event capability (kernel + driver) */
1055 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1056 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
1057 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1058 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1059 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1060 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
1061 IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1062 IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
1063 IW_EVENT_CAPA_MASK(IWEVEXPIRED));
1065 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1066 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1068 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1069 range->scan_capa = IW_SCAN_CAPA_ESSID;
1071 return 0;
1075 static int hostap_monitor_mode_enable(local_info_t *local)
1077 struct net_device *dev = local->dev;
1079 printk(KERN_DEBUG "Enabling monitor mode\n");
1080 hostap_monitor_set_type(local);
1082 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1083 HFA384X_PORTTYPE_PSEUDO_IBSS)) {
1084 printk(KERN_DEBUG "Port type setting for monitor mode "
1085 "failed\n");
1086 return -EOPNOTSUPP;
1089 /* Host decrypt is needed to get the IV and ICV fields;
1090 * however, monitor mode seems to remove WEP flag from frame
1091 * control field */
1092 if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS,
1093 HFA384X_WEPFLAGS_HOSTENCRYPT |
1094 HFA384X_WEPFLAGS_HOSTDECRYPT)) {
1095 printk(KERN_DEBUG "WEP flags setting failed\n");
1096 return -EOPNOTSUPP;
1099 if (local->func->reset_port(dev) ||
1100 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1101 (HFA384X_TEST_MONITOR << 8),
1102 0, NULL, NULL)) {
1103 printk(KERN_DEBUG "Setting monitor mode failed\n");
1104 return -EOPNOTSUPP;
1107 return 0;
1111 static int hostap_monitor_mode_disable(local_info_t *local)
1113 struct net_device *dev = local->ddev;
1115 if (dev == NULL)
1116 return -1;
1118 printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name);
1119 dev->type = ARPHRD_ETHER;
1121 if (local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1122 (HFA384X_TEST_STOP << 8),
1123 0, NULL, NULL))
1124 return -1;
1125 return hostap_set_encryption(local);
1129 static int prism2_ioctl_siwmode(struct net_device *dev,
1130 struct iw_request_info *info,
1131 __u32 *mode, char *extra)
1133 struct hostap_interface *iface;
1134 local_info_t *local;
1135 int double_reset = 0;
1137 iface = netdev_priv(dev);
1138 local = iface->local;
1140 if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA &&
1141 *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT &&
1142 *mode != IW_MODE_MONITOR)
1143 return -EOPNOTSUPP;
1145 #ifdef PRISM2_NO_STATION_MODES
1146 if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA)
1147 return -EOPNOTSUPP;
1148 #endif /* PRISM2_NO_STATION_MODES */
1150 if (*mode == local->iw_mode)
1151 return 0;
1153 if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') {
1154 printk(KERN_WARNING "%s: empty SSID not allowed in Master "
1155 "mode\n", dev->name);
1156 return -EINVAL;
1159 if (local->iw_mode == IW_MODE_MONITOR)
1160 hostap_monitor_mode_disable(local);
1162 if ((local->iw_mode == IW_MODE_ADHOC ||
1163 local->iw_mode == IW_MODE_MONITOR) && *mode == IW_MODE_MASTER) {
1164 /* There seems to be a firmware bug in at least STA f/w v1.5.6
1165 * that leaves beacon frames to use IBSS type when moving from
1166 * IBSS to Host AP mode. Doing double Port0 reset seems to be
1167 * enough to workaround this. */
1168 double_reset = 1;
1171 printk(KERN_DEBUG "prism2: %s: operating mode changed "
1172 "%d -> %d\n", dev->name, local->iw_mode, *mode);
1173 local->iw_mode = *mode;
1175 if (local->iw_mode == IW_MODE_MONITOR)
1176 hostap_monitor_mode_enable(local);
1177 else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
1178 !local->fw_encrypt_ok) {
1179 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
1180 "a workaround for firmware bug in Host AP mode WEP\n",
1181 dev->name);
1182 local->host_encrypt = 1;
1185 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1186 hostap_get_porttype(local)))
1187 return -EOPNOTSUPP;
1189 if (local->func->reset_port(dev))
1190 return -EINVAL;
1191 if (double_reset && local->func->reset_port(dev))
1192 return -EINVAL;
1194 if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
1196 /* netif_carrier is used only in client modes for now, so make
1197 * sure carrier is on when moving to non-client modes. */
1198 netif_carrier_on(local->dev);
1199 netif_carrier_on(local->ddev);
1201 return 0;
1205 static int prism2_ioctl_giwmode(struct net_device *dev,
1206 struct iw_request_info *info,
1207 __u32 *mode, char *extra)
1209 struct hostap_interface *iface;
1210 local_info_t *local;
1212 iface = netdev_priv(dev);
1213 local = iface->local;
1215 switch (iface->type) {
1216 case HOSTAP_INTERFACE_STA:
1217 *mode = IW_MODE_INFRA;
1218 break;
1219 case HOSTAP_INTERFACE_WDS:
1220 *mode = IW_MODE_REPEAT;
1221 break;
1222 default:
1223 *mode = local->iw_mode;
1224 break;
1226 return 0;
1230 static int prism2_ioctl_siwpower(struct net_device *dev,
1231 struct iw_request_info *info,
1232 struct iw_param *wrq, char *extra)
1234 #ifdef PRISM2_NO_STATION_MODES
1235 return -EOPNOTSUPP;
1236 #else /* PRISM2_NO_STATION_MODES */
1237 int ret = 0;
1239 if (wrq->disabled)
1240 return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
1242 switch (wrq->flags & IW_POWER_MODE) {
1243 case IW_POWER_UNICAST_R:
1244 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
1245 if (ret)
1246 return ret;
1247 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1248 if (ret)
1249 return ret;
1250 break;
1251 case IW_POWER_ALL_R:
1252 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
1253 if (ret)
1254 return ret;
1255 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1256 if (ret)
1257 return ret;
1258 break;
1259 case IW_POWER_ON:
1260 break;
1261 default:
1262 return -EINVAL;
1265 if (wrq->flags & IW_POWER_TIMEOUT) {
1266 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1267 if (ret)
1268 return ret;
1269 ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
1270 wrq->value / 1024);
1271 if (ret)
1272 return ret;
1274 if (wrq->flags & IW_POWER_PERIOD) {
1275 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1276 if (ret)
1277 return ret;
1278 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1279 wrq->value / 1024);
1280 if (ret)
1281 return ret;
1284 return ret;
1285 #endif /* PRISM2_NO_STATION_MODES */
1289 static int prism2_ioctl_giwpower(struct net_device *dev,
1290 struct iw_request_info *info,
1291 struct iw_param *rrq, char *extra)
1293 #ifdef PRISM2_NO_STATION_MODES
1294 return -EOPNOTSUPP;
1295 #else /* PRISM2_NO_STATION_MODES */
1296 struct hostap_interface *iface;
1297 local_info_t *local;
1298 __le16 enable, mcast;
1300 iface = netdev_priv(dev);
1301 local = iface->local;
1303 if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
1304 < 0)
1305 return -EINVAL;
1307 if (!le16_to_cpu(enable)) {
1308 rrq->disabled = 1;
1309 return 0;
1312 rrq->disabled = 0;
1314 if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1315 __le16 timeout;
1316 if (local->func->get_rid(dev,
1317 HFA384X_RID_CNFPMHOLDOVERDURATION,
1318 &timeout, 2, 1) < 0)
1319 return -EINVAL;
1321 rrq->flags = IW_POWER_TIMEOUT;
1322 rrq->value = le16_to_cpu(timeout) * 1024;
1323 } else {
1324 __le16 period;
1325 if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1326 &period, 2, 1) < 0)
1327 return -EINVAL;
1329 rrq->flags = IW_POWER_PERIOD;
1330 rrq->value = le16_to_cpu(period) * 1024;
1333 if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
1334 2, 1) < 0)
1335 return -EINVAL;
1337 if (le16_to_cpu(mcast))
1338 rrq->flags |= IW_POWER_ALL_R;
1339 else
1340 rrq->flags |= IW_POWER_UNICAST_R;
1342 return 0;
1343 #endif /* PRISM2_NO_STATION_MODES */
1347 static int prism2_ioctl_siwretry(struct net_device *dev,
1348 struct iw_request_info *info,
1349 struct iw_param *rrq, char *extra)
1351 struct hostap_interface *iface;
1352 local_info_t *local;
1354 iface = netdev_priv(dev);
1355 local = iface->local;
1357 if (rrq->disabled)
1358 return -EINVAL;
1360 /* setting retry limits is not supported with the current station
1361 * firmware code; simulate this with alternative retry count for now */
1362 if (rrq->flags == IW_RETRY_LIMIT) {
1363 if (rrq->value < 0) {
1364 /* disable manual retry count setting and use firmware
1365 * defaults */
1366 local->manual_retry_count = -1;
1367 local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
1368 } else {
1369 if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1370 rrq->value)) {
1371 printk(KERN_DEBUG "%s: Alternate retry count "
1372 "setting to %d failed\n",
1373 dev->name, rrq->value);
1374 return -EOPNOTSUPP;
1377 local->manual_retry_count = rrq->value;
1378 local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
1380 return 0;
1383 return -EOPNOTSUPP;
1385 #if 0
1386 /* what could be done, if firmware would support this.. */
1388 if (rrq->flags & IW_RETRY_LIMIT) {
1389 if (rrq->flags & IW_RETRY_LONG)
1390 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1391 else if (rrq->flags & IW_RETRY_SHORT)
1392 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1393 else {
1394 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1395 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1400 if (rrq->flags & IW_RETRY_LIFETIME) {
1401 HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
1404 return 0;
1405 #endif /* 0 */
1408 static int prism2_ioctl_giwretry(struct net_device *dev,
1409 struct iw_request_info *info,
1410 struct iw_param *rrq, char *extra)
1412 struct hostap_interface *iface;
1413 local_info_t *local;
1414 __le16 shortretry, longretry, lifetime, altretry;
1416 iface = netdev_priv(dev);
1417 local = iface->local;
1419 if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
1420 2, 1) < 0 ||
1421 local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
1422 2, 1) < 0 ||
1423 local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
1424 &lifetime, 2, 1) < 0)
1425 return -EINVAL;
1427 rrq->disabled = 0;
1429 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1430 rrq->flags = IW_RETRY_LIFETIME;
1431 rrq->value = le16_to_cpu(lifetime) * 1024;
1432 } else {
1433 if (local->manual_retry_count >= 0) {
1434 rrq->flags = IW_RETRY_LIMIT;
1435 if (local->func->get_rid(dev,
1436 HFA384X_RID_CNFALTRETRYCOUNT,
1437 &altretry, 2, 1) >= 0)
1438 rrq->value = le16_to_cpu(altretry);
1439 else
1440 rrq->value = local->manual_retry_count;
1441 } else if ((rrq->flags & IW_RETRY_LONG)) {
1442 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1443 rrq->value = le16_to_cpu(longretry);
1444 } else {
1445 rrq->flags = IW_RETRY_LIMIT;
1446 rrq->value = le16_to_cpu(shortretry);
1447 if (shortretry != longretry)
1448 rrq->flags |= IW_RETRY_SHORT;
1451 return 0;
1455 /* Note! This TX power controlling is experimental and should not be used in
1456 * production use. It just sets raw power register and does not use any kind of
1457 * feedback information from the measured TX power (CR58). This is now
1458 * commented out to make sure that it is not used by accident. TX power
1459 * configuration will be enabled again after proper algorithm using feedback
1460 * has been implemented. */
1462 #ifdef RAW_TXPOWER_SETTING
1463 /* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
1464 * This version assumes following mapping:
1465 * CR31 is 7-bit value with -64 to +63 range.
1466 * -64 is mapped into +20dBm and +63 into -43dBm.
1467 * This is certainly not an exact mapping for every card, but at least
1468 * increasing dBm value should correspond to increasing TX power.
1471 static int prism2_txpower_hfa386x_to_dBm(u16 val)
1473 signed char tmp;
1475 if (val > 255)
1476 val = 255;
1478 tmp = val;
1479 tmp >>= 2;
1481 return -12 - tmp;
1484 static u16 prism2_txpower_dBm_to_hfa386x(int val)
1486 signed char tmp;
1488 if (val > 20)
1489 return 128;
1490 else if (val < -43)
1491 return 127;
1493 tmp = val;
1494 tmp = -12 - tmp;
1495 tmp <<= 2;
1497 return (unsigned char) tmp;
1499 #endif /* RAW_TXPOWER_SETTING */
1502 static int prism2_ioctl_siwtxpow(struct net_device *dev,
1503 struct iw_request_info *info,
1504 struct iw_param *rrq, char *extra)
1506 struct hostap_interface *iface;
1507 local_info_t *local;
1508 #ifdef RAW_TXPOWER_SETTING
1509 char *tmp;
1510 #endif
1511 u16 val;
1512 int ret = 0;
1514 iface = netdev_priv(dev);
1515 local = iface->local;
1517 if (rrq->disabled) {
1518 if (local->txpower_type != PRISM2_TXPOWER_OFF) {
1519 val = 0xff; /* use all standby and sleep modes */
1520 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1521 HFA386X_CR_A_D_TEST_MODES2,
1522 &val, NULL);
1523 printk(KERN_DEBUG "%s: Turning radio off: %s\n",
1524 dev->name, ret ? "failed" : "OK");
1525 local->txpower_type = PRISM2_TXPOWER_OFF;
1527 return (ret ? -EOPNOTSUPP : 0);
1530 if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1531 val = 0; /* disable all standby and sleep modes */
1532 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1533 HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
1534 printk(KERN_DEBUG "%s: Turning radio on: %s\n",
1535 dev->name, ret ? "failed" : "OK");
1536 local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
1539 #ifdef RAW_TXPOWER_SETTING
1540 if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
1541 printk(KERN_DEBUG "Setting ALC on\n");
1542 val = HFA384X_TEST_CFG_BIT_ALC;
1543 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1544 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
1545 local->txpower_type = PRISM2_TXPOWER_AUTO;
1546 return 0;
1549 if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
1550 printk(KERN_DEBUG "Setting ALC off\n");
1551 val = HFA384X_TEST_CFG_BIT_ALC;
1552 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1553 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
1554 local->txpower_type = PRISM2_TXPOWER_FIXED;
1557 if (rrq->flags == IW_TXPOW_DBM)
1558 tmp = "dBm";
1559 else if (rrq->flags == IW_TXPOW_MWATT)
1560 tmp = "mW";
1561 else
1562 tmp = "UNKNOWN";
1563 printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
1565 if (rrq->flags != IW_TXPOW_DBM) {
1566 printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
1567 return -EOPNOTSUPP;
1570 local->txpower = rrq->value;
1571 val = prism2_txpower_dBm_to_hfa386x(local->txpower);
1572 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1573 HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
1574 ret = -EOPNOTSUPP;
1575 #else /* RAW_TXPOWER_SETTING */
1576 if (rrq->fixed)
1577 ret = -EOPNOTSUPP;
1578 #endif /* RAW_TXPOWER_SETTING */
1580 return ret;
1583 static int prism2_ioctl_giwtxpow(struct net_device *dev,
1584 struct iw_request_info *info,
1585 struct iw_param *rrq, char *extra)
1587 #ifdef RAW_TXPOWER_SETTING
1588 struct hostap_interface *iface;
1589 local_info_t *local;
1590 u16 resp0;
1592 iface = netdev_priv(dev);
1593 local = iface->local;
1595 rrq->flags = IW_TXPOW_DBM;
1596 rrq->disabled = 0;
1597 rrq->fixed = 0;
1599 if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
1600 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
1601 HFA386X_CR_MANUAL_TX_POWER,
1602 NULL, &resp0) == 0) {
1603 rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
1604 } else {
1605 /* Could not get real txpower; guess 15 dBm */
1606 rrq->value = 15;
1608 } else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1609 rrq->value = 0;
1610 rrq->disabled = 1;
1611 } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
1612 rrq->value = local->txpower;
1613 rrq->fixed = 1;
1614 } else {
1615 printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
1616 local->txpower_type);
1618 return 0;
1619 #else /* RAW_TXPOWER_SETTING */
1620 return -EOPNOTSUPP;
1621 #endif /* RAW_TXPOWER_SETTING */
1625 #ifndef PRISM2_NO_STATION_MODES
1627 /* HostScan request works with and without host_roaming mode. In addition, it
1628 * does not break current association. However, it requires newer station
1629 * firmware version (>= 1.3.1) than scan request. */
1630 static int prism2_request_hostscan(struct net_device *dev,
1631 u8 *ssid, u8 ssid_len)
1633 struct hostap_interface *iface;
1634 local_info_t *local;
1635 struct hfa384x_hostscan_request scan_req;
1637 iface = netdev_priv(dev);
1638 local = iface->local;
1640 memset(&scan_req, 0, sizeof(scan_req));
1641 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1642 local->scan_channel_mask);
1643 scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
1644 if (ssid) {
1645 if (ssid_len > 32)
1646 return -EINVAL;
1647 scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1648 memcpy(scan_req.target_ssid, ssid, ssid_len);
1651 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1652 sizeof(scan_req))) {
1653 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1654 return -EINVAL;
1656 return 0;
1660 static int prism2_request_scan(struct net_device *dev)
1662 struct hostap_interface *iface;
1663 local_info_t *local;
1664 struct hfa384x_scan_request scan_req;
1665 int ret = 0;
1667 iface = netdev_priv(dev);
1668 local = iface->local;
1670 memset(&scan_req, 0, sizeof(scan_req));
1671 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1672 local->scan_channel_mask);
1673 scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
1675 /* FIX:
1676 * It seems to be enough to set roaming mode for a short moment to
1677 * host-based and then setup scanrequest data and return the mode to
1678 * firmware-based.
1680 * Master mode would need to drop to Managed mode for a short while
1681 * to make scanning work.. Or sweep through the different channels and
1682 * use passive scan based on beacons. */
1684 if (!local->host_roaming)
1685 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1686 HFA384X_ROAMING_HOST);
1688 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1689 sizeof(scan_req))) {
1690 printk(KERN_DEBUG "SCANREQUEST failed\n");
1691 ret = -EINVAL;
1694 if (!local->host_roaming)
1695 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1696 HFA384X_ROAMING_FIRMWARE);
1698 return 0;
1701 #else /* !PRISM2_NO_STATION_MODES */
1703 static inline int prism2_request_hostscan(struct net_device *dev,
1704 u8 *ssid, u8 ssid_len)
1706 return -EOPNOTSUPP;
1710 static inline int prism2_request_scan(struct net_device *dev)
1712 return -EOPNOTSUPP;
1715 #endif /* !PRISM2_NO_STATION_MODES */
1718 static int prism2_ioctl_siwscan(struct net_device *dev,
1719 struct iw_request_info *info,
1720 struct iw_point *data, char *extra)
1722 struct hostap_interface *iface;
1723 local_info_t *local;
1724 int ret;
1725 u8 *ssid = NULL, ssid_len = 0;
1726 struct iw_scan_req *req = (struct iw_scan_req *) extra;
1728 iface = netdev_priv(dev);
1729 local = iface->local;
1731 if (data->length < sizeof(struct iw_scan_req))
1732 req = NULL;
1734 if (local->iw_mode == IW_MODE_MASTER) {
1735 /* In master mode, we just return the results of our local
1736 * tables, so we don't need to start anything...
1737 * Jean II */
1738 data->length = 0;
1739 return 0;
1742 if (!local->dev_enabled)
1743 return -ENETDOWN;
1745 if (req && data->flags & IW_SCAN_THIS_ESSID) {
1746 ssid = req->essid;
1747 ssid_len = req->essid_len;
1749 if (ssid_len &&
1750 ((local->iw_mode != IW_MODE_INFRA &&
1751 local->iw_mode != IW_MODE_ADHOC) ||
1752 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1753 return -EOPNOTSUPP;
1756 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1757 ret = prism2_request_hostscan(dev, ssid, ssid_len);
1758 else
1759 ret = prism2_request_scan(dev);
1761 if (ret == 0)
1762 local->scan_timestamp = jiffies;
1764 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1766 return ret;
1770 #ifndef PRISM2_NO_STATION_MODES
1771 static char * __prism2_translate_scan(local_info_t *local,
1772 struct iw_request_info *info,
1773 struct hfa384x_hostscan_result *scan,
1774 struct hostap_bss_info *bss,
1775 char *current_ev, char *end_buf)
1777 int i, chan;
1778 struct iw_event iwe;
1779 char *current_val;
1780 u16 capabilities;
1781 u8 *pos;
1782 u8 *ssid, *bssid;
1783 size_t ssid_len;
1784 char *buf;
1786 if (bss) {
1787 ssid = bss->ssid;
1788 ssid_len = bss->ssid_len;
1789 bssid = bss->bssid;
1790 } else {
1791 ssid = scan->ssid;
1792 ssid_len = le16_to_cpu(scan->ssid_len);
1793 bssid = scan->bssid;
1795 if (ssid_len > 32)
1796 ssid_len = 32;
1798 /* First entry *MUST* be the AP MAC address */
1799 memset(&iwe, 0, sizeof(iwe));
1800 iwe.cmd = SIOCGIWAP;
1801 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1802 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1803 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1804 IW_EV_ADDR_LEN);
1806 /* Other entries will be displayed in the order we give them */
1808 memset(&iwe, 0, sizeof(iwe));
1809 iwe.cmd = SIOCGIWESSID;
1810 iwe.u.data.length = ssid_len;
1811 iwe.u.data.flags = 1;
1812 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1813 &iwe, ssid);
1815 memset(&iwe, 0, sizeof(iwe));
1816 iwe.cmd = SIOCGIWMODE;
1817 if (bss) {
1818 capabilities = bss->capab_info;
1819 } else {
1820 capabilities = le16_to_cpu(scan->capability);
1822 if (capabilities & (WLAN_CAPABILITY_ESS |
1823 WLAN_CAPABILITY_IBSS)) {
1824 if (capabilities & WLAN_CAPABILITY_ESS)
1825 iwe.u.mode = IW_MODE_MASTER;
1826 else
1827 iwe.u.mode = IW_MODE_ADHOC;
1828 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1829 &iwe, IW_EV_UINT_LEN);
1832 memset(&iwe, 0, sizeof(iwe));
1833 iwe.cmd = SIOCGIWFREQ;
1834 if (scan) {
1835 chan = le16_to_cpu(scan->chid);
1836 } else if (bss) {
1837 chan = bss->chan;
1838 } else {
1839 chan = 0;
1842 if (chan > 0) {
1843 iwe.u.freq.m = freq_list[chan - 1] * 100000;
1844 iwe.u.freq.e = 1;
1845 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1846 &iwe, IW_EV_FREQ_LEN);
1849 if (scan) {
1850 memset(&iwe, 0, sizeof(iwe));
1851 iwe.cmd = IWEVQUAL;
1852 if (local->last_scan_type == PRISM2_HOSTSCAN) {
1853 iwe.u.qual.level = le16_to_cpu(scan->sl);
1854 iwe.u.qual.noise = le16_to_cpu(scan->anl);
1855 } else {
1856 iwe.u.qual.level =
1857 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1858 iwe.u.qual.noise =
1859 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1861 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
1862 | IW_QUAL_NOISE_UPDATED
1863 | IW_QUAL_QUAL_INVALID
1864 | IW_QUAL_DBM;
1865 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1866 &iwe, IW_EV_QUAL_LEN);
1869 memset(&iwe, 0, sizeof(iwe));
1870 iwe.cmd = SIOCGIWENCODE;
1871 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1872 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1873 else
1874 iwe.u.data.flags = IW_ENCODE_DISABLED;
1875 iwe.u.data.length = 0;
1876 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, "");
1878 /* TODO: add SuppRates into BSS table */
1879 if (scan) {
1880 memset(&iwe, 0, sizeof(iwe));
1881 iwe.cmd = SIOCGIWRATE;
1882 current_val = current_ev + iwe_stream_lcp_len(info);
1883 pos = scan->sup_rates;
1884 for (i = 0; i < sizeof(scan->sup_rates); i++) {
1885 if (pos[i] == 0)
1886 break;
1887 /* Bit rate given in 500 kb/s units (+ 0x80) */
1888 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1889 current_val = iwe_stream_add_value(
1890 info, current_ev, current_val, end_buf, &iwe,
1891 IW_EV_PARAM_LEN);
1893 /* Check if we added any event */
1894 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
1895 current_ev = current_val;
1898 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1899 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_ATOMIC);
1900 if (buf && scan) {
1901 memset(&iwe, 0, sizeof(iwe));
1902 iwe.cmd = IWEVCUSTOM;
1903 sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval));
1904 iwe.u.data.length = strlen(buf);
1905 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1906 &iwe, buf);
1908 memset(&iwe, 0, sizeof(iwe));
1909 iwe.cmd = IWEVCUSTOM;
1910 sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate));
1911 iwe.u.data.length = strlen(buf);
1912 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1913 &iwe, buf);
1915 if (local->last_scan_type == PRISM2_HOSTSCAN &&
1916 (capabilities & WLAN_CAPABILITY_IBSS)) {
1917 memset(&iwe, 0, sizeof(iwe));
1918 iwe.cmd = IWEVCUSTOM;
1919 sprintf(buf, "atim=%d", le16_to_cpu(scan->atim));
1920 iwe.u.data.length = strlen(buf);
1921 current_ev = iwe_stream_add_point(info, current_ev,
1922 end_buf, &iwe, buf);
1925 kfree(buf);
1927 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1928 memset(&iwe, 0, sizeof(iwe));
1929 iwe.cmd = IWEVGENIE;
1930 iwe.u.data.length = bss->wpa_ie_len;
1931 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1932 &iwe, bss->wpa_ie);
1935 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1936 memset(&iwe, 0, sizeof(iwe));
1937 iwe.cmd = IWEVGENIE;
1938 iwe.u.data.length = bss->rsn_ie_len;
1939 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1940 &iwe, bss->rsn_ie);
1943 return current_ev;
1947 /* Translate scan data returned from the card to a card independant
1948 * format that the Wireless Tools will understand - Jean II */
1949 static inline int prism2_translate_scan(local_info_t *local,
1950 struct iw_request_info *info,
1951 char *buffer, int buflen)
1953 struct hfa384x_hostscan_result *scan;
1954 int entry, hostscan;
1955 char *current_ev = buffer;
1956 char *end_buf = buffer + buflen;
1957 struct list_head *ptr;
1959 spin_lock_bh(&local->lock);
1961 list_for_each(ptr, &local->bss_list) {
1962 struct hostap_bss_info *bss;
1963 bss = list_entry(ptr, struct hostap_bss_info, list);
1964 bss->included = 0;
1967 hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
1968 for (entry = 0; entry < local->last_scan_results_count; entry++) {
1969 int found = 0;
1970 scan = &local->last_scan_results[entry];
1972 /* Report every SSID if the AP is using multiple SSIDs. If no
1973 * BSS record is found (e.g., when WPA mode is disabled),
1974 * report the AP once. */
1975 list_for_each(ptr, &local->bss_list) {
1976 struct hostap_bss_info *bss;
1977 bss = list_entry(ptr, struct hostap_bss_info, list);
1978 if (memcmp(bss->bssid, scan->bssid, ETH_ALEN) == 0) {
1979 bss->included = 1;
1980 current_ev = __prism2_translate_scan(
1981 local, info, scan, bss, current_ev,
1982 end_buf);
1983 found++;
1986 if (!found) {
1987 current_ev = __prism2_translate_scan(
1988 local, info, scan, NULL, current_ev, end_buf);
1990 /* Check if there is space for one more entry */
1991 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
1992 /* Ask user space to try again with a bigger buffer */
1993 spin_unlock_bh(&local->lock);
1994 return -E2BIG;
1998 /* Prism2 firmware has limits (32 at least in some versions) for number
1999 * of BSSes in scan results. Extend this limit by using local BSS list.
2001 list_for_each(ptr, &local->bss_list) {
2002 struct hostap_bss_info *bss;
2003 bss = list_entry(ptr, struct hostap_bss_info, list);
2004 if (bss->included)
2005 continue;
2006 current_ev = __prism2_translate_scan(local, info, NULL, bss,
2007 current_ev, end_buf);
2008 /* Check if there is space for one more entry */
2009 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2010 /* Ask user space to try again with a bigger buffer */
2011 spin_unlock_bh(&local->lock);
2012 return -E2BIG;
2016 spin_unlock_bh(&local->lock);
2018 return current_ev - buffer;
2020 #endif /* PRISM2_NO_STATION_MODES */
2023 static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2024 struct iw_request_info *info,
2025 struct iw_point *data, char *extra)
2027 #ifdef PRISM2_NO_STATION_MODES
2028 return -EOPNOTSUPP;
2029 #else /* PRISM2_NO_STATION_MODES */
2030 struct hostap_interface *iface;
2031 local_info_t *local;
2032 int res;
2034 iface = netdev_priv(dev);
2035 local = iface->local;
2037 /* Wait until the scan is finished. We can probably do better
2038 * than that - Jean II */
2039 if (local->scan_timestamp &&
2040 time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2041 /* Important note : we don't want to block the caller
2042 * until results are ready for various reasons.
2043 * First, managing wait queues is complex and racy
2044 * (there may be multiple simultaneous callers).
2045 * Second, we grab some rtnetlink lock before comming
2046 * here (in dev_ioctl()).
2047 * Third, the caller can wait on the Wireless Event
2048 * - Jean II */
2049 return -EAGAIN;
2051 local->scan_timestamp = 0;
2053 res = prism2_translate_scan(local, info, extra, data->length);
2055 if (res >= 0) {
2056 data->length = res;
2057 return 0;
2058 } else {
2059 data->length = 0;
2060 return res;
2062 #endif /* PRISM2_NO_STATION_MODES */
2066 static int prism2_ioctl_giwscan(struct net_device *dev,
2067 struct iw_request_info *info,
2068 struct iw_point *data, char *extra)
2070 struct hostap_interface *iface;
2071 local_info_t *local;
2072 int res;
2074 iface = netdev_priv(dev);
2075 local = iface->local;
2077 if (local->iw_mode == IW_MODE_MASTER) {
2078 /* In MASTER mode, it doesn't make sense to go around
2079 * scanning the frequencies and make the stations we serve
2080 * wait when what the user is really interested about is the
2081 * list of stations and access points we are talking to.
2082 * So, just extract results from our cache...
2083 * Jean II */
2085 /* Translate to WE format */
2086 res = prism2_ap_translate_scan(dev, info, extra);
2087 if (res >= 0) {
2088 printk(KERN_DEBUG "Scan result translation succeeded "
2089 "(length=%d)\n", res);
2090 data->length = res;
2091 return 0;
2092 } else {
2093 printk(KERN_DEBUG
2094 "Scan result translation failed (res=%d)\n",
2095 res);
2096 data->length = 0;
2097 return res;
2099 } else {
2100 /* Station mode */
2101 return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2106 static const struct iw_priv_args prism2_priv[] = {
2107 { PRISM2_IOCTL_MONITOR,
2108 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2109 { PRISM2_IOCTL_READMIF,
2110 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2111 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2112 { PRISM2_IOCTL_WRITEMIF,
2113 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2114 { PRISM2_IOCTL_RESET,
2115 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2116 { PRISM2_IOCTL_INQUIRE,
2117 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2118 { PRISM2_IOCTL_SET_RID_WORD,
2119 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2120 { PRISM2_IOCTL_MACCMD,
2121 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2122 { PRISM2_IOCTL_WDS_ADD,
2123 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2124 { PRISM2_IOCTL_WDS_DEL,
2125 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2126 { PRISM2_IOCTL_ADDMAC,
2127 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2128 { PRISM2_IOCTL_DELMAC,
2129 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2130 { PRISM2_IOCTL_KICKMAC,
2131 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2132 /* --- raw access to sub-ioctls --- */
2133 { PRISM2_IOCTL_PRISM2_PARAM,
2134 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2135 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2136 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2137 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2138 /* --- sub-ioctls handlers --- */
2139 { PRISM2_IOCTL_PRISM2_PARAM,
2140 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2141 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2142 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2143 /* --- sub-ioctls definitions --- */
2144 { PRISM2_PARAM_TXRATECTRL,
2145 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2146 { PRISM2_PARAM_TXRATECTRL,
2147 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2148 { PRISM2_PARAM_BEACON_INT,
2149 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2150 { PRISM2_PARAM_BEACON_INT,
2151 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2152 #ifndef PRISM2_NO_STATION_MODES
2153 { PRISM2_PARAM_PSEUDO_IBSS,
2154 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2155 { PRISM2_PARAM_PSEUDO_IBSS,
2156 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2157 #endif /* PRISM2_NO_STATION_MODES */
2158 { PRISM2_PARAM_ALC,
2159 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2160 { PRISM2_PARAM_ALC,
2161 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2162 { PRISM2_PARAM_DUMP,
2163 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2164 { PRISM2_PARAM_DUMP,
2165 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2166 { PRISM2_PARAM_OTHER_AP_POLICY,
2167 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2168 { PRISM2_PARAM_OTHER_AP_POLICY,
2169 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2170 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2171 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2172 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2173 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2174 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2175 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2176 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2177 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2178 { PRISM2_PARAM_DTIM_PERIOD,
2179 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2180 { PRISM2_PARAM_DTIM_PERIOD,
2181 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2182 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2183 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2184 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2185 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2186 { PRISM2_PARAM_MAX_WDS,
2187 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2188 { PRISM2_PARAM_MAX_WDS,
2189 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2190 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2191 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2192 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2193 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2194 { PRISM2_PARAM_AP_AUTH_ALGS,
2195 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2196 { PRISM2_PARAM_AP_AUTH_ALGS,
2197 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2198 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2199 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2200 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2201 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2202 { PRISM2_PARAM_HOST_ENCRYPT,
2203 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2204 { PRISM2_PARAM_HOST_ENCRYPT,
2205 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2206 { PRISM2_PARAM_HOST_DECRYPT,
2207 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2208 { PRISM2_PARAM_HOST_DECRYPT,
2209 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2210 #ifndef PRISM2_NO_STATION_MODES
2211 { PRISM2_PARAM_HOST_ROAMING,
2212 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2213 { PRISM2_PARAM_HOST_ROAMING,
2214 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2215 #endif /* PRISM2_NO_STATION_MODES */
2216 { PRISM2_PARAM_BCRX_STA_KEY,
2217 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2218 { PRISM2_PARAM_BCRX_STA_KEY,
2219 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2220 { PRISM2_PARAM_IEEE_802_1X,
2221 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2222 { PRISM2_PARAM_IEEE_802_1X,
2223 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2224 { PRISM2_PARAM_ANTSEL_TX,
2225 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2226 { PRISM2_PARAM_ANTSEL_TX,
2227 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2228 { PRISM2_PARAM_ANTSEL_RX,
2229 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2230 { PRISM2_PARAM_ANTSEL_RX,
2231 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2232 { PRISM2_PARAM_MONITOR_TYPE,
2233 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2234 { PRISM2_PARAM_MONITOR_TYPE,
2235 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2236 { PRISM2_PARAM_WDS_TYPE,
2237 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2238 { PRISM2_PARAM_WDS_TYPE,
2239 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2240 { PRISM2_PARAM_HOSTSCAN,
2241 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2242 { PRISM2_PARAM_HOSTSCAN,
2243 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2244 { PRISM2_PARAM_AP_SCAN,
2245 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2246 { PRISM2_PARAM_AP_SCAN,
2247 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2248 { PRISM2_PARAM_ENH_SEC,
2249 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2250 { PRISM2_PARAM_ENH_SEC,
2251 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2252 #ifdef PRISM2_IO_DEBUG
2253 { PRISM2_PARAM_IO_DEBUG,
2254 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2255 { PRISM2_PARAM_IO_DEBUG,
2256 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2257 #endif /* PRISM2_IO_DEBUG */
2258 { PRISM2_PARAM_BASIC_RATES,
2259 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2260 { PRISM2_PARAM_BASIC_RATES,
2261 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2262 { PRISM2_PARAM_OPER_RATES,
2263 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2264 { PRISM2_PARAM_OPER_RATES,
2265 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2266 { PRISM2_PARAM_HOSTAPD,
2267 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2268 { PRISM2_PARAM_HOSTAPD,
2269 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2270 { PRISM2_PARAM_HOSTAPD_STA,
2271 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2272 { PRISM2_PARAM_HOSTAPD_STA,
2273 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2274 { PRISM2_PARAM_WPA,
2275 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2276 { PRISM2_PARAM_WPA,
2277 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2278 { PRISM2_PARAM_PRIVACY_INVOKED,
2279 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2280 { PRISM2_PARAM_PRIVACY_INVOKED,
2281 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2282 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2283 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2284 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2285 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2286 { PRISM2_PARAM_DROP_UNENCRYPTED,
2287 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2288 { PRISM2_PARAM_DROP_UNENCRYPTED,
2289 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
2290 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2291 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
2292 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2293 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
2297 static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2299 struct hostap_interface *iface;
2300 local_info_t *local;
2302 iface = netdev_priv(dev);
2303 local = iface->local;
2305 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2306 return -EOPNOTSUPP;
2308 return 0;
2312 static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2313 struct iw_request_info *info,
2314 void *wrqu, char *extra)
2316 struct hostap_interface *iface;
2317 local_info_t *local;
2318 int *i = (int *) extra;
2319 int param = *i;
2320 int value = *(i + 1);
2321 int ret = 0;
2322 u16 val;
2324 iface = netdev_priv(dev);
2325 local = iface->local;
2327 switch (param) {
2328 case PRISM2_PARAM_TXRATECTRL:
2329 local->fw_tx_rate_control = value;
2330 break;
2332 case PRISM2_PARAM_BEACON_INT:
2333 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2334 local->func->reset_port(dev))
2335 ret = -EINVAL;
2336 else
2337 local->beacon_int = value;
2338 break;
2340 #ifndef PRISM2_NO_STATION_MODES
2341 case PRISM2_PARAM_PSEUDO_IBSS:
2342 if (value == local->pseudo_adhoc)
2343 break;
2345 if (value != 0 && value != 1) {
2346 ret = -EINVAL;
2347 break;
2350 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2351 dev->name, local->pseudo_adhoc, value);
2352 local->pseudo_adhoc = value;
2353 if (local->iw_mode != IW_MODE_ADHOC)
2354 break;
2356 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2357 hostap_get_porttype(local))) {
2358 ret = -EOPNOTSUPP;
2359 break;
2362 if (local->func->reset_port(dev))
2363 ret = -EINVAL;
2364 break;
2365 #endif /* PRISM2_NO_STATION_MODES */
2367 case PRISM2_PARAM_ALC:
2368 printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2369 value == 0 ? "Disabling" : "Enabling");
2370 val = HFA384X_TEST_CFG_BIT_ALC;
2371 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2372 (HFA384X_TEST_CFG_BITS << 8),
2373 value == 0 ? 0 : 1, &val, NULL);
2374 break;
2376 case PRISM2_PARAM_DUMP:
2377 local->frame_dump = value;
2378 break;
2380 case PRISM2_PARAM_OTHER_AP_POLICY:
2381 if (value < 0 || value > 3) {
2382 ret = -EINVAL;
2383 break;
2385 if (local->ap != NULL)
2386 local->ap->ap_policy = value;
2387 break;
2389 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2390 if (value < 0 || value > 7 * 24 * 60 * 60) {
2391 ret = -EINVAL;
2392 break;
2394 if (local->ap != NULL)
2395 local->ap->max_inactivity = value * HZ;
2396 break;
2398 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2399 if (local->ap != NULL)
2400 local->ap->bridge_packets = value;
2401 break;
2403 case PRISM2_PARAM_DTIM_PERIOD:
2404 if (value < 0 || value > 65535) {
2405 ret = -EINVAL;
2406 break;
2408 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2409 || local->func->reset_port(dev))
2410 ret = -EINVAL;
2411 else
2412 local->dtim_period = value;
2413 break;
2415 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2416 if (local->ap != NULL)
2417 local->ap->nullfunc_ack = value;
2418 break;
2420 case PRISM2_PARAM_MAX_WDS:
2421 local->wds_max_connections = value;
2422 break;
2424 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2425 if (local->ap != NULL) {
2426 if (!local->ap->autom_ap_wds && value) {
2427 /* add WDS link to all APs in STA table */
2428 hostap_add_wds_links(local);
2430 local->ap->autom_ap_wds = value;
2432 break;
2434 case PRISM2_PARAM_AP_AUTH_ALGS:
2435 local->auth_algs = value;
2436 if (hostap_set_auth_algs(local))
2437 ret = -EINVAL;
2438 break;
2440 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2441 local->monitor_allow_fcserr = value;
2442 break;
2444 case PRISM2_PARAM_HOST_ENCRYPT:
2445 local->host_encrypt = value;
2446 if (hostap_set_encryption(local) ||
2447 local->func->reset_port(dev))
2448 ret = -EINVAL;
2449 break;
2451 case PRISM2_PARAM_HOST_DECRYPT:
2452 local->host_decrypt = value;
2453 if (hostap_set_encryption(local) ||
2454 local->func->reset_port(dev))
2455 ret = -EINVAL;
2456 break;
2458 #ifndef PRISM2_NO_STATION_MODES
2459 case PRISM2_PARAM_HOST_ROAMING:
2460 if (value < 0 || value > 2) {
2461 ret = -EINVAL;
2462 break;
2464 local->host_roaming = value;
2465 if (hostap_set_roaming(local) || local->func->reset_port(dev))
2466 ret = -EINVAL;
2467 break;
2468 #endif /* PRISM2_NO_STATION_MODES */
2470 case PRISM2_PARAM_BCRX_STA_KEY:
2471 local->bcrx_sta_key = value;
2472 break;
2474 case PRISM2_PARAM_IEEE_802_1X:
2475 local->ieee_802_1x = value;
2476 break;
2478 case PRISM2_PARAM_ANTSEL_TX:
2479 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2480 ret = -EINVAL;
2481 break;
2483 local->antsel_tx = value;
2484 hostap_set_antsel(local);
2485 break;
2487 case PRISM2_PARAM_ANTSEL_RX:
2488 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2489 ret = -EINVAL;
2490 break;
2492 local->antsel_rx = value;
2493 hostap_set_antsel(local);
2494 break;
2496 case PRISM2_PARAM_MONITOR_TYPE:
2497 if (value != PRISM2_MONITOR_80211 &&
2498 value != PRISM2_MONITOR_CAPHDR &&
2499 value != PRISM2_MONITOR_PRISM &&
2500 value != PRISM2_MONITOR_RADIOTAP) {
2501 ret = -EINVAL;
2502 break;
2504 local->monitor_type = value;
2505 if (local->iw_mode == IW_MODE_MONITOR)
2506 hostap_monitor_set_type(local);
2507 break;
2509 case PRISM2_PARAM_WDS_TYPE:
2510 local->wds_type = value;
2511 break;
2513 case PRISM2_PARAM_HOSTSCAN:
2515 struct hfa384x_hostscan_request scan_req;
2516 u16 rate;
2518 memset(&scan_req, 0, sizeof(scan_req));
2519 scan_req.channel_list = cpu_to_le16(0x3fff);
2520 switch (value) {
2521 case 1: rate = HFA384X_RATES_1MBPS; break;
2522 case 2: rate = HFA384X_RATES_2MBPS; break;
2523 case 3: rate = HFA384X_RATES_5MBPS; break;
2524 case 4: rate = HFA384X_RATES_11MBPS; break;
2525 default: rate = HFA384X_RATES_1MBPS; break;
2527 scan_req.txrate = cpu_to_le16(rate);
2528 /* leave SSID empty to accept all SSIDs */
2530 if (local->iw_mode == IW_MODE_MASTER) {
2531 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2532 HFA384X_PORTTYPE_BSS) ||
2533 local->func->reset_port(dev))
2534 printk(KERN_DEBUG "Leaving Host AP mode "
2535 "for HostScan failed\n");
2538 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2539 sizeof(scan_req))) {
2540 printk(KERN_DEBUG "HOSTSCAN failed\n");
2541 ret = -EINVAL;
2543 if (local->iw_mode == IW_MODE_MASTER) {
2544 wait_queue_t __wait;
2545 init_waitqueue_entry(&__wait, current);
2546 add_wait_queue(&local->hostscan_wq, &__wait);
2547 set_current_state(TASK_INTERRUPTIBLE);
2548 schedule_timeout(HZ);
2549 if (signal_pending(current))
2550 ret = -EINTR;
2551 set_current_state(TASK_RUNNING);
2552 remove_wait_queue(&local->hostscan_wq, &__wait);
2554 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2555 HFA384X_PORTTYPE_HOSTAP) ||
2556 local->func->reset_port(dev))
2557 printk(KERN_DEBUG "Returning to Host AP mode "
2558 "after HostScan failed\n");
2560 break;
2563 case PRISM2_PARAM_AP_SCAN:
2564 local->passive_scan_interval = value;
2565 if (timer_pending(&local->passive_scan_timer))
2566 del_timer(&local->passive_scan_timer);
2567 if (value > 0) {
2568 local->passive_scan_timer.expires = jiffies +
2569 local->passive_scan_interval * HZ;
2570 add_timer(&local->passive_scan_timer);
2572 break;
2574 case PRISM2_PARAM_ENH_SEC:
2575 if (value < 0 || value > 3) {
2576 ret = -EINVAL;
2577 break;
2579 local->enh_sec = value;
2580 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2581 local->enh_sec) ||
2582 local->func->reset_port(dev)) {
2583 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2584 "1.6.3 or newer\n", dev->name);
2585 ret = -EOPNOTSUPP;
2587 break;
2589 #ifdef PRISM2_IO_DEBUG
2590 case PRISM2_PARAM_IO_DEBUG:
2591 local->io_debug_enabled = value;
2592 break;
2593 #endif /* PRISM2_IO_DEBUG */
2595 case PRISM2_PARAM_BASIC_RATES:
2596 if ((value & local->tx_rate_control) != value || value == 0) {
2597 printk(KERN_INFO "%s: invalid basic rate set - basic "
2598 "rates must be in supported rate set\n",
2599 dev->name);
2600 ret = -EINVAL;
2601 break;
2603 local->basic_rates = value;
2604 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2605 local->basic_rates) ||
2606 local->func->reset_port(dev))
2607 ret = -EINVAL;
2608 break;
2610 case PRISM2_PARAM_OPER_RATES:
2611 local->tx_rate_control = value;
2612 if (hostap_set_rate(dev))
2613 ret = -EINVAL;
2614 break;
2616 case PRISM2_PARAM_HOSTAPD:
2617 ret = hostap_set_hostapd(local, value, 1);
2618 break;
2620 case PRISM2_PARAM_HOSTAPD_STA:
2621 ret = hostap_set_hostapd_sta(local, value, 1);
2622 break;
2624 case PRISM2_PARAM_WPA:
2625 local->wpa = value;
2626 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2627 ret = -EOPNOTSUPP;
2628 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2629 value ? 1 : 0))
2630 ret = -EINVAL;
2631 break;
2633 case PRISM2_PARAM_PRIVACY_INVOKED:
2634 local->privacy_invoked = value;
2635 if (hostap_set_encryption(local) ||
2636 local->func->reset_port(dev))
2637 ret = -EINVAL;
2638 break;
2640 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2641 local->tkip_countermeasures = value;
2642 break;
2644 case PRISM2_PARAM_DROP_UNENCRYPTED:
2645 local->drop_unencrypted = value;
2646 break;
2648 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2649 local->scan_channel_mask = value;
2650 break;
2652 default:
2653 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2654 dev->name, param);
2655 ret = -EOPNOTSUPP;
2656 break;
2659 return ret;
2663 static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2664 struct iw_request_info *info,
2665 void *wrqu, char *extra)
2667 struct hostap_interface *iface;
2668 local_info_t *local;
2669 int *param = (int *) extra;
2670 int ret = 0;
2672 iface = netdev_priv(dev);
2673 local = iface->local;
2675 switch (*param) {
2676 case PRISM2_PARAM_TXRATECTRL:
2677 *param = local->fw_tx_rate_control;
2678 break;
2680 case PRISM2_PARAM_BEACON_INT:
2681 *param = local->beacon_int;
2682 break;
2684 case PRISM2_PARAM_PSEUDO_IBSS:
2685 *param = local->pseudo_adhoc;
2686 break;
2688 case PRISM2_PARAM_ALC:
2689 ret = -EOPNOTSUPP; /* FIX */
2690 break;
2692 case PRISM2_PARAM_DUMP:
2693 *param = local->frame_dump;
2694 break;
2696 case PRISM2_PARAM_OTHER_AP_POLICY:
2697 if (local->ap != NULL)
2698 *param = local->ap->ap_policy;
2699 else
2700 ret = -EOPNOTSUPP;
2701 break;
2703 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2704 if (local->ap != NULL)
2705 *param = local->ap->max_inactivity / HZ;
2706 else
2707 ret = -EOPNOTSUPP;
2708 break;
2710 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2711 if (local->ap != NULL)
2712 *param = local->ap->bridge_packets;
2713 else
2714 ret = -EOPNOTSUPP;
2715 break;
2717 case PRISM2_PARAM_DTIM_PERIOD:
2718 *param = local->dtim_period;
2719 break;
2721 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2722 if (local->ap != NULL)
2723 *param = local->ap->nullfunc_ack;
2724 else
2725 ret = -EOPNOTSUPP;
2726 break;
2728 case PRISM2_PARAM_MAX_WDS:
2729 *param = local->wds_max_connections;
2730 break;
2732 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2733 if (local->ap != NULL)
2734 *param = local->ap->autom_ap_wds;
2735 else
2736 ret = -EOPNOTSUPP;
2737 break;
2739 case PRISM2_PARAM_AP_AUTH_ALGS:
2740 *param = local->auth_algs;
2741 break;
2743 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2744 *param = local->monitor_allow_fcserr;
2745 break;
2747 case PRISM2_PARAM_HOST_ENCRYPT:
2748 *param = local->host_encrypt;
2749 break;
2751 case PRISM2_PARAM_HOST_DECRYPT:
2752 *param = local->host_decrypt;
2753 break;
2755 case PRISM2_PARAM_HOST_ROAMING:
2756 *param = local->host_roaming;
2757 break;
2759 case PRISM2_PARAM_BCRX_STA_KEY:
2760 *param = local->bcrx_sta_key;
2761 break;
2763 case PRISM2_PARAM_IEEE_802_1X:
2764 *param = local->ieee_802_1x;
2765 break;
2767 case PRISM2_PARAM_ANTSEL_TX:
2768 *param = local->antsel_tx;
2769 break;
2771 case PRISM2_PARAM_ANTSEL_RX:
2772 *param = local->antsel_rx;
2773 break;
2775 case PRISM2_PARAM_MONITOR_TYPE:
2776 *param = local->monitor_type;
2777 break;
2779 case PRISM2_PARAM_WDS_TYPE:
2780 *param = local->wds_type;
2781 break;
2783 case PRISM2_PARAM_HOSTSCAN:
2784 ret = -EOPNOTSUPP;
2785 break;
2787 case PRISM2_PARAM_AP_SCAN:
2788 *param = local->passive_scan_interval;
2789 break;
2791 case PRISM2_PARAM_ENH_SEC:
2792 *param = local->enh_sec;
2793 break;
2795 #ifdef PRISM2_IO_DEBUG
2796 case PRISM2_PARAM_IO_DEBUG:
2797 *param = local->io_debug_enabled;
2798 break;
2799 #endif /* PRISM2_IO_DEBUG */
2801 case PRISM2_PARAM_BASIC_RATES:
2802 *param = local->basic_rates;
2803 break;
2805 case PRISM2_PARAM_OPER_RATES:
2806 *param = local->tx_rate_control;
2807 break;
2809 case PRISM2_PARAM_HOSTAPD:
2810 *param = local->hostapd;
2811 break;
2813 case PRISM2_PARAM_HOSTAPD_STA:
2814 *param = local->hostapd_sta;
2815 break;
2817 case PRISM2_PARAM_WPA:
2818 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2819 ret = -EOPNOTSUPP;
2820 *param = local->wpa;
2821 break;
2823 case PRISM2_PARAM_PRIVACY_INVOKED:
2824 *param = local->privacy_invoked;
2825 break;
2827 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2828 *param = local->tkip_countermeasures;
2829 break;
2831 case PRISM2_PARAM_DROP_UNENCRYPTED:
2832 *param = local->drop_unencrypted;
2833 break;
2835 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2836 *param = local->scan_channel_mask;
2837 break;
2839 default:
2840 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2841 dev->name, *param);
2842 ret = -EOPNOTSUPP;
2843 break;
2846 return ret;
2850 static int prism2_ioctl_priv_readmif(struct net_device *dev,
2851 struct iw_request_info *info,
2852 void *wrqu, char *extra)
2854 struct hostap_interface *iface;
2855 local_info_t *local;
2856 u16 resp0;
2858 iface = netdev_priv(dev);
2859 local = iface->local;
2861 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2862 &resp0))
2863 return -EOPNOTSUPP;
2864 else
2865 *extra = resp0;
2867 return 0;
2871 static int prism2_ioctl_priv_writemif(struct net_device *dev,
2872 struct iw_request_info *info,
2873 void *wrqu, char *extra)
2875 struct hostap_interface *iface;
2876 local_info_t *local;
2877 u16 cr, val;
2879 iface = netdev_priv(dev);
2880 local = iface->local;
2882 cr = *extra;
2883 val = *(extra + 1);
2884 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2885 return -EOPNOTSUPP;
2887 return 0;
2891 static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2893 struct hostap_interface *iface;
2894 local_info_t *local;
2895 int ret = 0;
2896 u32 mode;
2898 iface = netdev_priv(dev);
2899 local = iface->local;
2901 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2902 "- update software to use iwconfig mode monitor\n",
2903 dev->name, task_pid_nr(current), current->comm);
2905 /* Backward compatibility code - this can be removed at some point */
2907 if (*i == 0) {
2908 /* Disable monitor mode - old mode was not saved, so go to
2909 * Master mode */
2910 mode = IW_MODE_MASTER;
2911 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2912 } else if (*i == 1) {
2913 /* netlink socket mode is not supported anymore since it did
2914 * not separate different devices from each other and was not
2915 * best method for delivering large amount of packets to
2916 * user space */
2917 ret = -EOPNOTSUPP;
2918 } else if (*i == 2 || *i == 3) {
2919 switch (*i) {
2920 case 2:
2921 local->monitor_type = PRISM2_MONITOR_80211;
2922 break;
2923 case 3:
2924 local->monitor_type = PRISM2_MONITOR_PRISM;
2925 break;
2927 mode = IW_MODE_MONITOR;
2928 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2929 hostap_monitor_mode_enable(local);
2930 } else
2931 ret = -EINVAL;
2933 return ret;
2937 static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
2939 struct hostap_interface *iface;
2940 local_info_t *local;
2942 iface = netdev_priv(dev);
2943 local = iface->local;
2945 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
2946 switch (*i) {
2947 case 0:
2948 /* Disable and enable card */
2949 local->func->hw_shutdown(dev, 1);
2950 local->func->hw_config(dev, 0);
2951 break;
2953 case 1:
2954 /* COR sreset */
2955 local->func->hw_reset(dev);
2956 break;
2958 case 2:
2959 /* Disable and enable port 0 */
2960 local->func->reset_port(dev);
2961 break;
2963 case 3:
2964 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
2965 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
2966 NULL))
2967 return -EINVAL;
2968 break;
2970 case 4:
2971 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
2972 NULL))
2973 return -EINVAL;
2974 break;
2976 default:
2977 printk(KERN_DEBUG "Unknown reset request %d\n", *i);
2978 return -EOPNOTSUPP;
2981 return 0;
2985 static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
2987 int rid = *i;
2988 int value = *(i + 1);
2990 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
2992 if (hostap_set_word(dev, rid, value))
2993 return -EINVAL;
2995 return 0;
2999 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3000 static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3002 int ret = 0;
3004 switch (*cmd) {
3005 case AP_MAC_CMD_POLICY_OPEN:
3006 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3007 break;
3008 case AP_MAC_CMD_POLICY_ALLOW:
3009 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3010 break;
3011 case AP_MAC_CMD_POLICY_DENY:
3012 local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3013 break;
3014 case AP_MAC_CMD_FLUSH:
3015 ap_control_flush_macs(&local->ap->mac_restrictions);
3016 break;
3017 case AP_MAC_CMD_KICKALL:
3018 ap_control_kickall(local->ap);
3019 hostap_deauth_all_stas(local->dev, local->ap, 0);
3020 break;
3021 default:
3022 ret = -EOPNOTSUPP;
3023 break;
3026 return ret;
3028 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3031 #ifdef PRISM2_DOWNLOAD_SUPPORT
3032 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3034 struct prism2_download_param *param;
3035 int ret = 0;
3037 if (p->length < sizeof(struct prism2_download_param) ||
3038 p->length > 1024 || !p->pointer)
3039 return -EINVAL;
3041 param = (struct prism2_download_param *)
3042 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;