1 /* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
4 /* Get kernel_locked() for in_atomic() */
5 #include <linux/smp_lock.h>
7 #include <linux/ethtool.h>
10 static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
12 struct hostap_interface *iface;
14 struct iw_statistics *wstats;
16 iface = netdev_priv(dev);
19 /* Why are we doing that ? Jean II */
20 if (iface->type != HOSTAP_INTERFACE_MAIN)
23 wstats = &local->wstats;
26 wstats->discard.code =
27 local->comm_tallies.rx_discards_wep_undecryptable;
28 wstats->discard.misc =
29 local->comm_tallies.rx_fcs_errors +
30 local->comm_tallies.rx_discards_no_buffer +
31 local->comm_tallies.tx_discards_wrong_sa;
33 wstats->discard.retries =
34 local->comm_tallies.tx_retry_limit_exceeded;
35 wstats->discard.fragment =
36 local->comm_tallies.rx_message_in_bad_msg_fragments;
38 if (local->iw_mode != IW_MODE_MASTER &&
39 local->iw_mode != IW_MODE_REPEAT) {
42 /* RID reading might sleep and it must not be called in
43 * interrupt context or while atomic. However, this
44 * function seems to be called while atomic (at least in Linux
45 * 2.5.59). Update signal quality values only if in suitable
46 * context. Otherwise, previous values read from tick timer
50 #endif /* in_atomic */
52 if (update && prism2_update_comms_qual(dev) == 0)
53 wstats->qual.updated = IW_QUAL_ALL_UPDATED |
56 wstats->qual.qual = local->comms_qual;
57 wstats->qual.level = local->avg_signal;
58 wstats->qual.noise = local->avg_noise;
60 wstats->qual.qual = 0;
61 wstats->qual.level = 0;
62 wstats->qual.noise = 0;
63 wstats->qual.updated = IW_QUAL_ALL_INVALID;
70 static int prism2_get_datarates(struct net_device *dev, u8 *rates)
72 struct hostap_interface *iface;
78 iface = netdev_priv(dev);
81 len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
86 val = le16_to_cpu(*(u16 *) buf); /* string length */
88 if (len - 2 < val || val > 10)
91 memcpy(rates, buf + 2, val);
96 static int prism2_get_name(struct net_device *dev,
97 struct iw_request_info *info,
98 char *name, char *extra)
101 int len, i, over2 = 0;
103 len = prism2_get_datarates(dev, rates);
105 for (i = 0; i < len; i++) {
106 if (rates[i] == 0x0b || rates[i] == 0x16) {
112 strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
118 static void prism2_crypt_delayed_deinit(local_info_t *local,
119 struct ieee80211_crypt_data **crypt)
121 struct ieee80211_crypt_data *tmp;
130 /* must not run ops->deinit() while there may be pending encrypt or
131 * decrypt operations. Use a list of delayed deinits to avoid needing
134 spin_lock_irqsave(&local->lock, flags);
135 list_add(&tmp->list, &local->crypt_deinit_list);
136 if (!timer_pending(&local->crypt_deinit_timer)) {
137 local->crypt_deinit_timer.expires = jiffies + HZ;
138 add_timer(&local->crypt_deinit_timer);
140 spin_unlock_irqrestore(&local->lock, flags);
144 static int prism2_ioctl_siwencode(struct net_device *dev,
145 struct iw_request_info *info,
146 struct iw_point *erq, char *keybuf)
148 struct hostap_interface *iface;
151 struct ieee80211_crypt_data **crypt;
153 iface = netdev_priv(dev);
154 local = iface->local;
156 i = erq->flags & IW_ENCODE_INDEX;
158 i = local->tx_keyidx;
161 if (i < 0 || i >= WEP_KEYS)
164 crypt = &local->crypt[i];
166 if (erq->flags & IW_ENCODE_DISABLED) {
168 prism2_crypt_delayed_deinit(local, crypt);
172 if (*crypt != NULL && (*crypt)->ops != NULL &&
173 strcmp((*crypt)->ops->name, "WEP") != 0) {
174 /* changing to use WEP; deinit previously used algorithm */
175 prism2_crypt_delayed_deinit(local, crypt);
178 if (*crypt == NULL) {
179 struct ieee80211_crypt_data *new_crypt;
181 /* take WEP into use */
182 new_crypt = (struct ieee80211_crypt_data *)
183 kmalloc(sizeof(struct ieee80211_crypt_data),
185 if (new_crypt == NULL)
187 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
188 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
189 if (!new_crypt->ops) {
190 request_module("ieee80211_crypt_wep");
191 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
194 new_crypt->priv = new_crypt->ops->init(i);
195 if (!new_crypt->ops || !new_crypt->priv) {
199 printk(KERN_WARNING "%s: could not initialize WEP: "
200 "load module hostap_crypt_wep.o\n",
207 if (erq->length > 0) {
208 int len = erq->length <= 5 ? 5 : 13;
210 if (len > erq->length)
211 memset(keybuf + erq->length, 0, len - erq->length);
212 (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
213 for (j = 0; j < WEP_KEYS; j++) {
214 if (j != i && local->crypt[j]) {
220 local->tx_keyidx = i;
222 /* No key data - just set the default TX key index */
223 local->tx_keyidx = i;
227 local->open_wep = erq->flags & IW_ENCODE_OPEN;
229 if (hostap_set_encryption(local)) {
230 printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
234 /* Do not reset port0 if card is in Managed mode since resetting will
235 * generate new IEEE 802.11 authentication which may end up in looping
236 * with IEEE 802.1X. Prism2 documentation seem to require port reset
237 * after WEP configuration. However, keys are apparently changed at
238 * least in Managed mode. */
239 if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
240 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
248 static int prism2_ioctl_giwencode(struct net_device *dev,
249 struct iw_request_info *info,
250 struct iw_point *erq, char *key)
252 struct hostap_interface *iface;
256 struct ieee80211_crypt_data *crypt;
258 iface = netdev_priv(dev);
259 local = iface->local;
261 i = erq->flags & IW_ENCODE_INDEX;
263 i = local->tx_keyidx;
266 if (i < 0 || i >= WEP_KEYS)
269 crypt = local->crypt[i];
272 if (crypt == NULL || crypt->ops == NULL) {
274 erq->flags |= IW_ENCODE_DISABLED;
278 if (strcmp(crypt->ops->name, "WEP") != 0) {
279 /* only WEP is supported with wireless extensions, so just
280 * report that encryption is used */
282 erq->flags |= IW_ENCODE_ENABLED;
286 /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
287 * the keys from driver buffer */
288 len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
289 erq->length = (len >= 0 ? len : 0);
291 if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
293 printk("CNFWEPFLAGS reading failed\n");
297 if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
298 erq->flags |= IW_ENCODE_ENABLED;
300 erq->flags |= IW_ENCODE_DISABLED;
301 if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
302 erq->flags |= IW_ENCODE_RESTRICTED;
304 erq->flags |= IW_ENCODE_OPEN;
310 static int hostap_set_rate(struct net_device *dev)
312 struct hostap_interface *iface;
314 int ret, basic_rates;
316 iface = netdev_priv(dev);
317 local = iface->local;
319 basic_rates = local->basic_rates & local->tx_rate_control;
320 if (!basic_rates || basic_rates != local->basic_rates) {
321 printk(KERN_INFO "%s: updating basic rate set automatically "
322 "to match with the new supported rate set\n",
325 basic_rates = local->tx_rate_control;
327 local->basic_rates = basic_rates;
328 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
330 printk(KERN_WARNING "%s: failed to set "
331 "cnfBasicRates\n", dev->name);
334 ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
335 local->tx_rate_control) ||
336 hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
337 local->tx_rate_control) ||
338 local->func->reset_port(dev));
341 printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
342 "setting to 0x%x failed\n",
343 dev->name, local->tx_rate_control);
346 /* Update TX rate configuration for all STAs based on new operational
348 hostap_update_rates(local);
354 static int prism2_ioctl_siwrate(struct net_device *dev,
355 struct iw_request_info *info,
356 struct iw_param *rrq, char *extra)
358 struct hostap_interface *iface;
361 iface = netdev_priv(dev);
362 local = iface->local;
365 switch (rrq->value) {
367 local->tx_rate_control = HFA384X_RATES_11MBPS;
370 local->tx_rate_control = HFA384X_RATES_5MBPS;
373 local->tx_rate_control = HFA384X_RATES_2MBPS;
376 local->tx_rate_control = HFA384X_RATES_1MBPS;
379 local->tx_rate_control = HFA384X_RATES_1MBPS |
380 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
381 HFA384X_RATES_11MBPS;
385 switch (rrq->value) {
387 local->tx_rate_control = HFA384X_RATES_1MBPS |
388 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
389 HFA384X_RATES_11MBPS;
392 local->tx_rate_control = HFA384X_RATES_1MBPS |
393 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
396 local->tx_rate_control = HFA384X_RATES_1MBPS |
400 local->tx_rate_control = HFA384X_RATES_1MBPS;
403 local->tx_rate_control = HFA384X_RATES_1MBPS |
404 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
405 HFA384X_RATES_11MBPS;
410 return hostap_set_rate(dev);
414 static int prism2_ioctl_giwrate(struct net_device *dev,
415 struct iw_request_info *info,
416 struct iw_param *rrq, char *extra)
419 struct hostap_interface *iface;
423 iface = netdev_priv(dev);
424 local = iface->local;
426 if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
430 if ((val & 0x1) && (val > 1))
435 if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
436 !local->fw_tx_rate_control) {
437 /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
438 * Host AP mode, so use the recorded TX rate of the last sent
440 rrq->value = local->ap->last_tx_rate > 0 ?
441 local->ap->last_tx_rate * 100000 : 11000000;
445 if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
450 case HFA384X_RATES_1MBPS:
451 rrq->value = 1000000;
453 case HFA384X_RATES_2MBPS:
454 rrq->value = 2000000;
456 case HFA384X_RATES_5MBPS:
457 rrq->value = 5500000;
459 case HFA384X_RATES_11MBPS:
460 rrq->value = 11000000;
463 /* should not happen */
464 rrq->value = 11000000;
473 static int prism2_ioctl_siwsens(struct net_device *dev,
474 struct iw_request_info *info,
475 struct iw_param *sens, char *extra)
477 struct hostap_interface *iface;
480 iface = netdev_priv(dev);
481 local = iface->local;
483 /* Set the desired AP density */
484 if (sens->value < 1 || sens->value > 3)
487 if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
488 local->func->reset_port(dev))
494 static int prism2_ioctl_giwsens(struct net_device *dev,
495 struct iw_request_info *info,
496 struct iw_param *sens, char *extra)
498 struct hostap_interface *iface;
502 iface = netdev_priv(dev);
503 local = iface->local;
505 /* Get the current AP density */
506 if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
510 sens->value = __le16_to_cpu(val);
517 /* Deprecated in new wireless extension API */
518 static int prism2_ioctl_giwaplist(struct net_device *dev,
519 struct iw_request_info *info,
520 struct iw_point *data, char *extra)
522 struct hostap_interface *iface;
524 struct sockaddr *addr;
525 struct iw_quality *qual;
527 iface = netdev_priv(dev);
528 local = iface->local;
530 if (local->iw_mode != IW_MODE_MASTER) {
531 printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
532 "in Host AP mode\n");
537 addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
538 qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
539 if (addr == NULL || qual == NULL) {
546 data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
548 memcpy(extra, &addr, sizeof(struct sockaddr) * data->length);
549 data->flags = 1; /* has quality information */
550 memcpy(extra + sizeof(struct sockaddr) * data->length, &qual,
551 sizeof(struct iw_quality) * data->length);
560 static int prism2_ioctl_siwrts(struct net_device *dev,
561 struct iw_request_info *info,
562 struct iw_param *rts, char *extra)
564 struct hostap_interface *iface;
568 iface = netdev_priv(dev);
569 local = iface->local;
572 val = __constant_cpu_to_le16(2347);
573 else if (rts->value < 0 || rts->value > 2347)
576 val = __cpu_to_le16(rts->value);
578 if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) ||
579 local->func->reset_port(dev))
582 local->rts_threshold = rts->value;
587 static int prism2_ioctl_giwrts(struct net_device *dev,
588 struct iw_request_info *info,
589 struct iw_param *rts, char *extra)
591 struct hostap_interface *iface;
595 iface = netdev_priv(dev);
596 local = iface->local;
598 if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) <
602 rts->value = __le16_to_cpu(val);
603 rts->disabled = (rts->value == 2347);
610 static int prism2_ioctl_siwfrag(struct net_device *dev,
611 struct iw_request_info *info,
612 struct iw_param *rts, char *extra)
614 struct hostap_interface *iface;
618 iface = netdev_priv(dev);
619 local = iface->local;
622 val = __constant_cpu_to_le16(2346);
623 else if (rts->value < 256 || rts->value > 2346)
626 val = __cpu_to_le16(rts->value & ~0x1); /* even numbers only */
628 local->fragm_threshold = rts->value & ~0x1;
629 if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val,
631 || local->func->reset_port(dev))
637 static int prism2_ioctl_giwfrag(struct net_device *dev,
638 struct iw_request_info *info,
639 struct iw_param *rts, char *extra)
641 struct hostap_interface *iface;
645 iface = netdev_priv(dev);
646 local = iface->local;
648 if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
652 rts->value = __le16_to_cpu(val);
653 rts->disabled = (rts->value == 2346);
660 #ifndef PRISM2_NO_STATION_MODES
661 static int hostap_join_ap(struct net_device *dev)
663 struct hostap_interface *iface;
665 struct hfa384x_join_request req;
668 struct hfa384x_hostscan_result *entry;
670 iface = netdev_priv(dev);
671 local = iface->local;
673 memcpy(req.bssid, local->preferred_ap, ETH_ALEN);
676 spin_lock_irqsave(&local->lock, flags);
677 for (i = 0; i < local->last_scan_results_count; i++) {
678 if (!local->last_scan_results)
680 entry = &local->last_scan_results[i];
681 if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) {
682 req.channel = entry->chid;
686 spin_unlock_irqrestore(&local->lock, flags);
688 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
690 printk(KERN_DEBUG "%s: JoinRequest " MACSTR
692 dev->name, MAC2STR(local->preferred_ap));
696 printk(KERN_DEBUG "%s: Trying to join BSSID " MACSTR "\n",
697 dev->name, MAC2STR(local->preferred_ap));
701 #endif /* PRISM2_NO_STATION_MODES */
704 static int prism2_ioctl_siwap(struct net_device *dev,
705 struct iw_request_info *info,
706 struct sockaddr *ap_addr, char *extra)
708 #ifdef PRISM2_NO_STATION_MODES
710 #else /* PRISM2_NO_STATION_MODES */
711 struct hostap_interface *iface;
714 iface = netdev_priv(dev);
715 local = iface->local;
717 memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN);
719 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) {
720 struct hfa384x_scan_request scan_req;
721 memset(&scan_req, 0, sizeof(scan_req));
722 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
723 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
724 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST,
725 &scan_req, sizeof(scan_req))) {
726 printk(KERN_DEBUG "%s: ScanResults request failed - "
727 "preferred AP delayed to next unsolicited "
728 "scan\n", dev->name);
730 } else if (local->host_roaming == 2 &&
731 local->iw_mode == IW_MODE_INFRA) {
732 if (hostap_join_ap(dev))
735 printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only "
736 "in Managed mode when host_roaming is enabled\n",
741 #endif /* PRISM2_NO_STATION_MODES */
744 static int prism2_ioctl_giwap(struct net_device *dev,
745 struct iw_request_info *info,
746 struct sockaddr *ap_addr, char *extra)
748 struct hostap_interface *iface;
751 iface = netdev_priv(dev);
752 local = iface->local;
754 ap_addr->sa_family = ARPHRD_ETHER;
755 switch (iface->type) {
756 case HOSTAP_INTERFACE_AP:
757 memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN);
759 case HOSTAP_INTERFACE_STA:
760 memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN);
762 case HOSTAP_INTERFACE_WDS:
763 memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN);
766 if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID,
767 &ap_addr->sa_data, ETH_ALEN, 1) < 0)
770 /* local->bssid is also updated in LinkStatus handler when in
772 memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN);
780 static int prism2_ioctl_siwnickn(struct net_device *dev,
781 struct iw_request_info *info,
782 struct iw_point *data, char *nickname)
784 struct hostap_interface *iface;
787 iface = netdev_priv(dev);
788 local = iface->local;
790 memset(local->name, 0, sizeof(local->name));
791 memcpy(local->name, nickname, data->length);
794 if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) ||
795 local->func->reset_port(dev))
801 static int prism2_ioctl_giwnickn(struct net_device *dev,
802 struct iw_request_info *info,
803 struct iw_point *data, char *nickname)
805 struct hostap_interface *iface;
808 char name[MAX_NAME_LEN + 3];
811 iface = netdev_priv(dev);
812 local = iface->local;
814 len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME,
815 &name, MAX_NAME_LEN + 2, 0);
816 val = __le16_to_cpu(*(u16 *) name);
817 if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN)
820 name[val + 2] = '\0';
821 data->length = val + 1;
822 memcpy(nickname, name + 2, val + 1);
828 static int prism2_ioctl_siwfreq(struct net_device *dev,
829 struct iw_request_info *info,
830 struct iw_freq *freq, char *extra)
832 struct hostap_interface *iface;
835 iface = netdev_priv(dev);
836 local = iface->local;
840 freq->m / 100000 >= freq_list[0] &&
841 freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) {
843 int fr = freq->m / 100000;
844 for (ch = 0; ch < FREQ_COUNT; ch++) {
845 if (fr == freq_list[ch]) {
853 if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT ||
854 !(local->channel_mask & (1 << (freq->m - 1))))
857 local->channel = freq->m; /* channel is used in prism2_setup_rids() */
858 if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) ||
859 local->func->reset_port(dev))
865 static int prism2_ioctl_giwfreq(struct net_device *dev,
866 struct iw_request_info *info,
867 struct iw_freq *freq, char *extra)
869 struct hostap_interface *iface;
873 iface = netdev_priv(dev);
874 local = iface->local;
876 if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) <
881 if (val < 1 || val > FREQ_COUNT)
884 freq->m = freq_list[val - 1] * 100000;
891 static void hostap_monitor_set_type(local_info_t *local)
893 struct net_device *dev = local->ddev;
898 if (local->monitor_type == PRISM2_MONITOR_PRISM ||
899 local->monitor_type == PRISM2_MONITOR_CAPHDR) {
900 dev->type = ARPHRD_IEEE80211_PRISM;
901 dev->hard_header_parse =
902 hostap_80211_prism_header_parse;
904 dev->type = ARPHRD_IEEE80211;
905 dev->hard_header_parse = hostap_80211_header_parse;
910 static int prism2_ioctl_siwessid(struct net_device *dev,
911 struct iw_request_info *info,
912 struct iw_point *data, char *ssid)
914 struct hostap_interface *iface;
917 iface = netdev_priv(dev);
918 local = iface->local;
920 if (iface->type == HOSTAP_INTERFACE_WDS)
923 if (data->flags == 0)
924 ssid[0] = '\0'; /* ANY */
926 if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') {
927 /* Setting SSID to empty string seems to kill the card in
929 printk(KERN_DEBUG "%s: Host AP mode does not support "
930 "'Any' essid\n", dev->name);
934 memcpy(local->essid, ssid, data->length);
935 local->essid[data->length] = '\0';
937 if ((!local->fw_ap &&
938 hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid))
939 || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) ||
940 local->func->reset_port(dev))
946 static int prism2_ioctl_giwessid(struct net_device *dev,
947 struct iw_request_info *info,
948 struct iw_point *data, char *essid)
950 struct hostap_interface *iface;
954 iface = netdev_priv(dev);
955 local = iface->local;
957 if (iface->type == HOSTAP_INTERFACE_WDS)
960 data->flags = 1; /* active */
961 if (local->iw_mode == IW_MODE_MASTER) {
962 data->length = strlen(local->essid);
963 memcpy(essid, local->essid, IW_ESSID_MAX_SIZE);
966 char ssid[MAX_SSID_LEN + 2];
967 memset(ssid, 0, sizeof(ssid));
968 len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID,
969 &ssid, MAX_SSID_LEN + 2, 0);
970 val = __le16_to_cpu(*(u16 *) ssid);
971 if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) {
975 memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE);
982 static int prism2_ioctl_giwrange(struct net_device *dev,
983 struct iw_request_info *info,
984 struct iw_point *data, char *extra)
986 struct hostap_interface *iface;
988 struct iw_range *range = (struct iw_range *) extra;
993 iface = netdev_priv(dev);
994 local = iface->local;
996 data->length = sizeof(struct iw_range);
997 memset(range, 0, sizeof(struct iw_range));
999 /* TODO: could fill num_txpower and txpower array with
1000 * something; however, there are 128 different values.. */
1002 range->txpower_capa = IW_TXPOW_DBM;
1004 if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC)
1006 range->min_pmp = 1 * 1024;
1007 range->max_pmp = 65535 * 1024;
1008 range->min_pmt = 1 * 1024;
1009 range->max_pmt = 1000 * 1024;
1010 range->pmp_flags = IW_POWER_PERIOD;
1011 range->pmt_flags = IW_POWER_TIMEOUT;
1012 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
1013 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
1016 range->we_version_compiled = WIRELESS_EXT;
1017 range->we_version_source = 18;
1019 range->retry_capa = IW_RETRY_LIMIT;
1020 range->retry_flags = IW_RETRY_LIMIT;
1021 range->min_retry = 0;
1022 range->max_retry = 255;
1024 range->num_channels = FREQ_COUNT;
1027 for (i = 0; i < FREQ_COUNT; i++) {
1028 if (local->channel_mask & (1 << i)) {
1029 range->freq[val].i = i + 1;
1030 range->freq[val].m = freq_list[i] * 100000;
1031 range->freq[val].e = 1;
1034 if (val == IW_MAX_FREQUENCIES)
1037 range->num_frequency = val;
1039 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1040 range->max_qual.qual = 70; /* what is correct max? This was not
1041 * documented exactly. At least
1042 * 69 has been observed. */
1043 range->max_qual.level = 0; /* dB */
1044 range->max_qual.noise = 0; /* dB */
1046 /* What would be suitable values for "average/typical" qual? */
1047 range->avg_qual.qual = 20;
1048 range->avg_qual.level = -60;
1049 range->avg_qual.noise = -95;
1051 range->max_qual.qual = 92; /* 0 .. 92 */
1052 range->max_qual.level = 154; /* 27 .. 154 */
1053 range->max_qual.noise = 154; /* 27 .. 154 */
1055 range->sensitivity = 3;
1057 range->max_encoding_tokens = WEP_KEYS;
1058 range->num_encoding_sizes = 2;
1059 range->encoding_size[0] = 5;
1060 range->encoding_size[1] = 13;
1063 len = prism2_get_datarates(dev, rates);
1064 range->num_bitrates = 0;
1065 for (i = 0; i < len; i++) {
1066 if (range->num_bitrates < IW_MAX_BITRATES) {
1067 range->bitrate[range->num_bitrates] =
1069 range->num_bitrates++;
1071 if (rates[i] == 0x0b || rates[i] == 0x16)
1074 /* estimated maximum TCP throughput values (bps) */
1075 range->throughput = over2 ? 5500000 : 1500000;
1078 range->max_rts = 2347;
1079 range->min_frag = 256;
1080 range->max_frag = 2346;
1082 /* Event capability (kernel + driver) */
1083 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1084 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
1085 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1086 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1087 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1088 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
1089 IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1090 IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
1091 IW_EVENT_CAPA_MASK(IWEVEXPIRED));
1093 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1094 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1100 static int hostap_monitor_mode_enable(local_info_t *local)
1102 struct net_device *dev = local->dev;
1104 printk(KERN_DEBUG "Enabling monitor mode\n");
1105 hostap_monitor_set_type(local);
1107 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1108 HFA384X_PORTTYPE_PSEUDO_IBSS)) {
1109 printk(KERN_DEBUG "Port type setting for monitor mode "
1114 /* Host decrypt is needed to get the IV and ICV fields;
1115 * however, monitor mode seems to remove WEP flag from frame
1117 if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS,
1118 HFA384X_WEPFLAGS_HOSTENCRYPT |
1119 HFA384X_WEPFLAGS_HOSTDECRYPT)) {
1120 printk(KERN_DEBUG "WEP flags setting failed\n");
1124 if (local->func->reset_port(dev) ||
1125 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1126 (HFA384X_TEST_MONITOR << 8),
1128 printk(KERN_DEBUG "Setting monitor mode failed\n");
1136 static int hostap_monitor_mode_disable(local_info_t *local)
1138 struct net_device *dev = local->ddev;
1143 printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name);
1144 dev->type = ARPHRD_ETHER;
1145 dev->hard_header_parse = local->saved_eth_header_parse;
1146 if (local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1147 (HFA384X_TEST_STOP << 8),
1150 return hostap_set_encryption(local);
1154 static int prism2_ioctl_siwmode(struct net_device *dev,
1155 struct iw_request_info *info,
1156 __u32 *mode, char *extra)
1158 struct hostap_interface *iface;
1159 local_info_t *local;
1160 int double_reset = 0;
1162 iface = netdev_priv(dev);
1163 local = iface->local;
1165 if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA &&
1166 *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT &&
1167 *mode != IW_MODE_MONITOR)
1170 #ifdef PRISM2_NO_STATION_MODES
1171 if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA)
1173 #endif /* PRISM2_NO_STATION_MODES */
1175 if (*mode == local->iw_mode)
1178 if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') {
1179 printk(KERN_WARNING "%s: empty SSID not allowed in Master "
1180 "mode\n", dev->name);
1184 if (local->iw_mode == IW_MODE_MONITOR)
1185 hostap_monitor_mode_disable(local);
1187 if ((local->iw_mode == IW_MODE_ADHOC ||
1188 local->iw_mode == IW_MODE_MONITOR) && *mode == IW_MODE_MASTER) {
1189 /* There seems to be a firmware bug in at least STA f/w v1.5.6
1190 * that leaves beacon frames to use IBSS type when moving from
1191 * IBSS to Host AP mode. Doing double Port0 reset seems to be
1192 * enough to workaround this. */
1196 printk(KERN_DEBUG "prism2: %s: operating mode changed "
1197 "%d -> %d\n", dev->name, local->iw_mode, *mode);
1198 local->iw_mode = *mode;
1200 if (local->iw_mode == IW_MODE_MONITOR)
1201 hostap_monitor_mode_enable(local);
1202 else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
1203 !local->fw_encrypt_ok) {
1204 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
1205 "a workaround for firmware bug in Host AP mode WEP\n",
1207 local->host_encrypt = 1;
1210 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1211 hostap_get_porttype(local)))
1214 if (local->func->reset_port(dev))
1216 if (double_reset && local->func->reset_port(dev))
1219 if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
1221 /* netif_carrier is used only in client modes for now, so make
1222 * sure carrier is on when moving to non-client modes. */
1223 netif_carrier_on(local->dev);
1224 netif_carrier_on(local->ddev);
1230 static int prism2_ioctl_giwmode(struct net_device *dev,
1231 struct iw_request_info *info,
1232 __u32 *mode, char *extra)
1234 struct hostap_interface *iface;
1235 local_info_t *local;
1237 iface = netdev_priv(dev);
1238 local = iface->local;
1240 switch (iface->type) {
1241 case HOSTAP_INTERFACE_STA:
1242 *mode = IW_MODE_INFRA;
1244 case HOSTAP_INTERFACE_WDS:
1245 *mode = IW_MODE_REPEAT;
1248 *mode = local->iw_mode;
1255 static int prism2_ioctl_siwpower(struct net_device *dev,
1256 struct iw_request_info *info,
1257 struct iw_param *wrq, char *extra)
1259 #ifdef PRISM2_NO_STATION_MODES
1261 #else /* PRISM2_NO_STATION_MODES */
1265 return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
1267 switch (wrq->flags & IW_POWER_MODE) {
1268 case IW_POWER_UNICAST_R:
1269 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
1272 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1276 case IW_POWER_ALL_R:
1277 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
1280 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1290 if (wrq->flags & IW_POWER_TIMEOUT) {
1291 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1294 ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
1299 if (wrq->flags & IW_POWER_PERIOD) {
1300 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1303 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1310 #endif /* PRISM2_NO_STATION_MODES */
1314 static int prism2_ioctl_giwpower(struct net_device *dev,
1315 struct iw_request_info *info,
1316 struct iw_param *rrq, char *extra)
1318 #ifdef PRISM2_NO_STATION_MODES
1320 #else /* PRISM2_NO_STATION_MODES */
1321 struct hostap_interface *iface;
1322 local_info_t *local;
1325 iface = netdev_priv(dev);
1326 local = iface->local;
1328 if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
1332 if (!__le16_to_cpu(enable)) {
1339 if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1341 if (local->func->get_rid(dev,
1342 HFA384X_RID_CNFPMHOLDOVERDURATION,
1343 &timeout, 2, 1) < 0)
1346 rrq->flags = IW_POWER_TIMEOUT;
1347 rrq->value = __le16_to_cpu(timeout) * 1024;
1350 if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1354 rrq->flags = IW_POWER_PERIOD;
1355 rrq->value = __le16_to_cpu(period) * 1024;
1358 if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
1362 if (__le16_to_cpu(mcast))
1363 rrq->flags |= IW_POWER_ALL_R;
1365 rrq->flags |= IW_POWER_UNICAST_R;
1368 #endif /* PRISM2_NO_STATION_MODES */
1372 static int prism2_ioctl_siwretry(struct net_device *dev,
1373 struct iw_request_info *info,
1374 struct iw_param *rrq, char *extra)
1376 struct hostap_interface *iface;
1377 local_info_t *local;
1379 iface = netdev_priv(dev);
1380 local = iface->local;
1385 /* setting retry limits is not supported with the current station
1386 * firmware code; simulate this with alternative retry count for now */
1387 if (rrq->flags == IW_RETRY_LIMIT) {
1388 if (rrq->value < 0) {
1389 /* disable manual retry count setting and use firmware
1391 local->manual_retry_count = -1;
1392 local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
1394 if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1396 printk(KERN_DEBUG "%s: Alternate retry count "
1397 "setting to %d failed\n",
1398 dev->name, rrq->value);
1402 local->manual_retry_count = rrq->value;
1403 local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
1411 /* what could be done, if firmware would support this.. */
1413 if (rrq->flags & IW_RETRY_LIMIT) {
1414 if (rrq->flags & IW_RETRY_MAX)
1415 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1416 else if (rrq->flags & IW_RETRY_MIN)
1417 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1419 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1420 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1425 if (rrq->flags & IW_RETRY_LIFETIME) {
1426 HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
1433 static int prism2_ioctl_giwretry(struct net_device *dev,
1434 struct iw_request_info *info,
1435 struct iw_param *rrq, char *extra)
1437 struct hostap_interface *iface;
1438 local_info_t *local;
1439 u16 shortretry, longretry, lifetime, altretry;
1441 iface = netdev_priv(dev);
1442 local = iface->local;
1444 if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
1446 local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
1448 local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
1449 &lifetime, 2, 1) < 0)
1452 le16_to_cpus(&shortretry);
1453 le16_to_cpus(&longretry);
1454 le16_to_cpus(&lifetime);
1458 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1459 rrq->flags = IW_RETRY_LIFETIME;
1460 rrq->value = lifetime * 1024;
1462 if (local->manual_retry_count >= 0) {
1463 rrq->flags = IW_RETRY_LIMIT;
1464 if (local->func->get_rid(dev,
1465 HFA384X_RID_CNFALTRETRYCOUNT,
1466 &altretry, 2, 1) >= 0)
1467 rrq->value = le16_to_cpu(altretry);
1469 rrq->value = local->manual_retry_count;
1470 } else if ((rrq->flags & IW_RETRY_MAX)) {
1471 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1472 rrq->value = longretry;
1474 rrq->flags = IW_RETRY_LIMIT;
1475 rrq->value = shortretry;
1476 if (shortretry != longretry)
1477 rrq->flags |= IW_RETRY_MIN;
1484 /* Note! This TX power controlling is experimental and should not be used in
1485 * production use. It just sets raw power register and does not use any kind of
1486 * feedback information from the measured TX power (CR58). This is now
1487 * commented out to make sure that it is not used by accident. TX power
1488 * configuration will be enabled again after proper algorithm using feedback
1489 * has been implemented. */
1491 #ifdef RAW_TXPOWER_SETTING
1492 /* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
1493 * This version assumes following mapping:
1494 * CR31 is 7-bit value with -64 to +63 range.
1495 * -64 is mapped into +20dBm and +63 into -43dBm.
1496 * This is certainly not an exact mapping for every card, but at least
1497 * increasing dBm value should correspond to increasing TX power.
1500 static int prism2_txpower_hfa386x_to_dBm(u16 val)
1513 static u16 prism2_txpower_dBm_to_hfa386x(int val)
1526 return (unsigned char) tmp;
1528 #endif /* RAW_TXPOWER_SETTING */
1531 static int prism2_ioctl_siwtxpow(struct net_device *dev,
1532 struct iw_request_info *info,
1533 struct iw_param *rrq, char *extra)
1535 struct hostap_interface *iface;
1536 local_info_t *local;
1537 #ifdef RAW_TXPOWER_SETTING
1543 iface = netdev_priv(dev);
1544 local = iface->local;
1546 if (rrq->disabled) {
1547 if (local->txpower_type != PRISM2_TXPOWER_OFF) {
1548 val = 0xff; /* use all standby and sleep modes */
1549 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1550 HFA386X_CR_A_D_TEST_MODES2,
1552 printk(KERN_DEBUG "%s: Turning radio off: %s\n",
1553 dev->name, ret ? "failed" : "OK");
1554 local->txpower_type = PRISM2_TXPOWER_OFF;
1556 return (ret ? -EOPNOTSUPP : 0);
1559 if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1560 val = 0; /* disable all standby and sleep modes */
1561 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1562 HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
1563 printk(KERN_DEBUG "%s: Turning radio on: %s\n",
1564 dev->name, ret ? "failed" : "OK");
1565 local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
1568 #ifdef RAW_TXPOWER_SETTING
1569 if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
1570 printk(KERN_DEBUG "Setting ALC on\n");
1571 val = HFA384X_TEST_CFG_BIT_ALC;
1572 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1573 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
1574 local->txpower_type = PRISM2_TXPOWER_AUTO;
1578 if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
1579 printk(KERN_DEBUG "Setting ALC off\n");
1580 val = HFA384X_TEST_CFG_BIT_ALC;
1581 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1582 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
1583 local->txpower_type = PRISM2_TXPOWER_FIXED;
1586 if (rrq->flags == IW_TXPOW_DBM)
1588 else if (rrq->flags == IW_TXPOW_MWATT)
1592 printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
1594 if (rrq->flags != IW_TXPOW_DBM) {
1595 printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
1599 local->txpower = rrq->value;
1600 val = prism2_txpower_dBm_to_hfa386x(local->txpower);
1601 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1602 HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
1604 #else /* RAW_TXPOWER_SETTING */
1607 #endif /* RAW_TXPOWER_SETTING */
1612 static int prism2_ioctl_giwtxpow(struct net_device *dev,
1613 struct iw_request_info *info,
1614 struct iw_param *rrq, char *extra)
1616 #ifdef RAW_TXPOWER_SETTING
1617 struct hostap_interface *iface;
1618 local_info_t *local;
1621 iface = netdev_priv(dev);
1622 local = iface->local;
1624 rrq->flags = IW_TXPOW_DBM;
1628 if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
1629 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
1630 HFA386X_CR_MANUAL_TX_POWER,
1631 NULL, &resp0) == 0) {
1632 rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
1634 /* Could not get real txpower; guess 15 dBm */
1637 } else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1640 } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
1641 rrq->value = local->txpower;
1644 printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
1645 local->txpower_type);
1648 #else /* RAW_TXPOWER_SETTING */
1650 #endif /* RAW_TXPOWER_SETTING */
1654 #ifndef PRISM2_NO_STATION_MODES
1656 /* HostScan request works with and without host_roaming mode. In addition, it
1657 * does not break current association. However, it requires newer station
1658 * firmware version (>= 1.3.1) than scan request. */
1659 static int prism2_request_hostscan(struct net_device *dev,
1660 u8 *ssid, u8 ssid_len)
1662 struct hostap_interface *iface;
1663 local_info_t *local;
1664 struct hfa384x_hostscan_request scan_req;
1666 iface = netdev_priv(dev);
1667 local = iface->local;
1669 memset(&scan_req, 0, sizeof(scan_req));
1670 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1671 local->scan_channel_mask);
1672 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1676 scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1677 memcpy(scan_req.target_ssid, ssid, ssid_len);
1680 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1681 sizeof(scan_req))) {
1682 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1689 static int prism2_request_scan(struct net_device *dev)
1691 struct hostap_interface *iface;
1692 local_info_t *local;
1693 struct hfa384x_scan_request scan_req;
1696 iface = netdev_priv(dev);
1697 local = iface->local;
1699 memset(&scan_req, 0, sizeof(scan_req));
1700 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1701 local->scan_channel_mask);
1702 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1705 * It seems to be enough to set roaming mode for a short moment to
1706 * host-based and then setup scanrequest data and return the mode to
1709 * Master mode would need to drop to Managed mode for a short while
1710 * to make scanning work.. Or sweep through the different channels and
1711 * use passive scan based on beacons. */
1713 if (!local->host_roaming)
1714 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1715 HFA384X_ROAMING_HOST);
1717 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1718 sizeof(scan_req))) {
1719 printk(KERN_DEBUG "SCANREQUEST failed\n");
1723 if (!local->host_roaming)
1724 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1725 HFA384X_ROAMING_FIRMWARE);
1730 #else /* !PRISM2_NO_STATION_MODES */
1732 static inline int prism2_request_hostscan(struct net_device *dev,
1733 u8 *ssid, u8 ssid_len)
1739 static inline int prism2_request_scan(struct net_device *dev)
1744 #endif /* !PRISM2_NO_STATION_MODES */
1747 static int prism2_ioctl_siwscan(struct net_device *dev,
1748 struct iw_request_info *info,
1749 struct iw_point *data, char *extra)
1751 struct hostap_interface *iface;
1752 local_info_t *local;
1754 u8 *ssid = NULL, ssid_len = 0;
1755 struct iw_scan_req *req = (struct iw_scan_req *) extra;
1757 iface = netdev_priv(dev);
1758 local = iface->local;
1760 if (data->length < sizeof(struct iw_scan_req))
1763 if (local->iw_mode == IW_MODE_MASTER) {
1764 /* In master mode, we just return the results of our local
1765 * tables, so we don't need to start anything...
1771 if (!local->dev_enabled)
1774 if (req && data->flags & IW_SCAN_THIS_ESSID) {
1776 ssid_len = req->essid_len;
1779 ((local->iw_mode != IW_MODE_INFRA &&
1780 local->iw_mode != IW_MODE_ADHOC) ||
1781 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1785 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1786 ret = prism2_request_hostscan(dev, ssid, ssid_len);
1788 ret = prism2_request_scan(dev);
1791 local->scan_timestamp = jiffies;
1793 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1799 #ifndef PRISM2_NO_STATION_MODES
1800 static char * __prism2_translate_scan(local_info_t *local,
1801 struct hfa384x_hostscan_result *scan,
1802 struct hostap_bss_info *bss,
1803 char *current_ev, char *end_buf)
1806 struct iw_event iwe;
1816 ssid_len = bss->ssid_len;
1820 ssid_len = le16_to_cpu(scan->ssid_len);
1821 bssid = scan->bssid;
1826 /* First entry *MUST* be the AP MAC address */
1827 memset(&iwe, 0, sizeof(iwe));
1828 iwe.cmd = SIOCGIWAP;
1829 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1830 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1831 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1834 /* Other entries will be displayed in the order we give them */
1836 memset(&iwe, 0, sizeof(iwe));
1837 iwe.cmd = SIOCGIWESSID;
1838 iwe.u.data.length = ssid_len;
1839 iwe.u.data.flags = 1;
1840 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid);
1842 memset(&iwe, 0, sizeof(iwe));
1843 iwe.cmd = SIOCGIWMODE;
1845 capabilities = bss->capab_info;
1847 capabilities = le16_to_cpu(scan->capability);
1849 if (capabilities & (WLAN_CAPABILITY_ESS |
1850 WLAN_CAPABILITY_IBSS)) {
1851 if (capabilities & WLAN_CAPABILITY_ESS)
1852 iwe.u.mode = IW_MODE_MASTER;
1854 iwe.u.mode = IW_MODE_ADHOC;
1855 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1859 memset(&iwe, 0, sizeof(iwe));
1860 iwe.cmd = SIOCGIWFREQ;
1870 iwe.u.freq.m = freq_list[le16_to_cpu(chan - 1)] * 100000;
1872 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1877 memset(&iwe, 0, sizeof(iwe));
1879 if (local->last_scan_type == PRISM2_HOSTSCAN) {
1880 iwe.u.qual.level = le16_to_cpu(scan->sl);
1881 iwe.u.qual.noise = le16_to_cpu(scan->anl);
1884 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1886 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1888 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
1889 | IW_QUAL_NOISE_UPDATED
1890 | IW_QUAL_QUAL_INVALID
1892 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1896 memset(&iwe, 0, sizeof(iwe));
1897 iwe.cmd = SIOCGIWENCODE;
1898 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1899 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1901 iwe.u.data.flags = IW_ENCODE_DISABLED;
1902 iwe.u.data.length = 0;
1903 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
1905 /* TODO: add SuppRates into BSS table */
1907 memset(&iwe, 0, sizeof(iwe));
1908 iwe.cmd = SIOCGIWRATE;
1909 current_val = current_ev + IW_EV_LCP_LEN;
1910 pos = scan->sup_rates;
1911 for (i = 0; i < sizeof(scan->sup_rates); i++) {
1914 /* Bit rate given in 500 kb/s units (+ 0x80) */
1915 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1916 current_val = iwe_stream_add_value(
1917 current_ev, current_val, end_buf, &iwe,
1920 /* Check if we added any event */
1921 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1922 current_ev = current_val;
1925 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1926 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_ATOMIC);
1928 memset(&iwe, 0, sizeof(iwe));
1929 iwe.cmd = IWEVCUSTOM;
1930 sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval));
1931 iwe.u.data.length = strlen(buf);
1932 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1935 memset(&iwe, 0, sizeof(iwe));
1936 iwe.cmd = IWEVCUSTOM;
1937 sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate));
1938 iwe.u.data.length = strlen(buf);
1939 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1942 if (local->last_scan_type == PRISM2_HOSTSCAN &&
1943 (capabilities & WLAN_CAPABILITY_IBSS)) {
1944 memset(&iwe, 0, sizeof(iwe));
1945 iwe.cmd = IWEVCUSTOM;
1946 sprintf(buf, "atim=%d", le16_to_cpu(scan->atim));
1947 iwe.u.data.length = strlen(buf);
1948 current_ev = iwe_stream_add_point(current_ev, end_buf,
1954 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1955 memset(&iwe, 0, sizeof(iwe));
1956 iwe.cmd = IWEVGENIE;
1957 iwe.u.data.length = bss->wpa_ie_len;
1958 current_ev = iwe_stream_add_point(
1959 current_ev, end_buf, &iwe, bss->wpa_ie);
1962 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1963 memset(&iwe, 0, sizeof(iwe));
1964 iwe.cmd = IWEVGENIE;
1965 iwe.u.data.length = bss->rsn_ie_len;
1966 current_ev = iwe_stream_add_point(
1967 current_ev, end_buf, &iwe, bss->rsn_ie);
1974 /* Translate scan data returned from the card to a card independant
1975 * format that the Wireless Tools will understand - Jean II */
1976 static inline int prism2_translate_scan(local_info_t *local,
1977 char *buffer, int buflen)
1979 struct hfa384x_hostscan_result *scan;
1980 int entry, hostscan;
1981 char *current_ev = buffer;
1982 char *end_buf = buffer + buflen;
1983 struct list_head *ptr;
1985 spin_lock_bh(&local->lock);
1987 list_for_each(ptr, &local->bss_list) {
1988 struct hostap_bss_info *bss;
1989 bss = list_entry(ptr, struct hostap_bss_info, list);
1993 hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
1994 for (entry = 0; entry < local->last_scan_results_count; entry++) {
1996 scan = &local->last_scan_results[entry];
1998 /* Report every SSID if the AP is using multiple SSIDs. If no
1999 * BSS record is found (e.g., when WPA mode is disabled),
2000 * report the AP once. */
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 (memcmp(bss->bssid, scan->bssid, ETH_ALEN) == 0) {
2006 current_ev = __prism2_translate_scan(
2007 local, scan, bss, current_ev, end_buf);
2012 current_ev = __prism2_translate_scan(
2013 local, scan, NULL, current_ev, end_buf);
2015 /* Check if there is space for one more entry */
2016 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2017 /* Ask user space to try again with a bigger buffer */
2018 spin_unlock_bh(&local->lock);
2023 /* Prism2 firmware has limits (32 at least in some versions) for number
2024 * of BSSes in scan results. Extend this limit by using local BSS list.
2026 list_for_each(ptr, &local->bss_list) {
2027 struct hostap_bss_info *bss;
2028 bss = list_entry(ptr, struct hostap_bss_info, list);
2031 current_ev = __prism2_translate_scan(local, NULL, bss,
2032 current_ev, end_buf);
2033 /* Check if there is space for one more entry */
2034 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2035 /* Ask user space to try again with a bigger buffer */
2036 spin_unlock_bh(&local->lock);
2041 spin_unlock_bh(&local->lock);
2043 return current_ev - buffer;
2045 #endif /* PRISM2_NO_STATION_MODES */
2048 static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2049 struct iw_request_info *info,
2050 struct iw_point *data, char *extra)
2052 #ifdef PRISM2_NO_STATION_MODES
2054 #else /* PRISM2_NO_STATION_MODES */
2055 struct hostap_interface *iface;
2056 local_info_t *local;
2059 iface = netdev_priv(dev);
2060 local = iface->local;
2062 /* Wait until the scan is finished. We can probably do better
2063 * than that - Jean II */
2064 if (local->scan_timestamp &&
2065 time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2066 /* Important note : we don't want to block the caller
2067 * until results are ready for various reasons.
2068 * First, managing wait queues is complex and racy
2069 * (there may be multiple simultaneous callers).
2070 * Second, we grab some rtnetlink lock before comming
2071 * here (in dev_ioctl()).
2072 * Third, the caller can wait on the Wireless Event
2076 local->scan_timestamp = 0;
2078 res = prism2_translate_scan(local, extra, data->length);
2087 #endif /* PRISM2_NO_STATION_MODES */
2091 static int prism2_ioctl_giwscan(struct net_device *dev,
2092 struct iw_request_info *info,
2093 struct iw_point *data, char *extra)
2095 struct hostap_interface *iface;
2096 local_info_t *local;
2099 iface = netdev_priv(dev);
2100 local = iface->local;
2102 if (local->iw_mode == IW_MODE_MASTER) {
2103 /* In MASTER mode, it doesn't make sense to go around
2104 * scanning the frequencies and make the stations we serve
2105 * wait when what the user is really interested about is the
2106 * list of stations and access points we are talking to.
2107 * So, just extract results from our cache...
2110 /* Translate to WE format */
2111 res = prism2_ap_translate_scan(dev, extra);
2113 printk(KERN_DEBUG "Scan result translation succeeded "
2114 "(length=%d)\n", res);
2119 "Scan result translation failed (res=%d)\n",
2126 return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2131 static const struct iw_priv_args prism2_priv[] = {
2132 { PRISM2_IOCTL_MONITOR,
2133 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2134 { PRISM2_IOCTL_READMIF,
2135 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2136 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2137 { PRISM2_IOCTL_WRITEMIF,
2138 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2139 { PRISM2_IOCTL_RESET,
2140 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2141 { PRISM2_IOCTL_INQUIRE,
2142 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2143 { PRISM2_IOCTL_SET_RID_WORD,
2144 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2145 { PRISM2_IOCTL_MACCMD,
2146 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2147 { PRISM2_IOCTL_WDS_ADD,
2148 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2149 { PRISM2_IOCTL_WDS_DEL,
2150 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2151 { PRISM2_IOCTL_ADDMAC,
2152 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2153 { PRISM2_IOCTL_DELMAC,
2154 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2155 { PRISM2_IOCTL_KICKMAC,
2156 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2157 /* --- raw access to sub-ioctls --- */
2158 { PRISM2_IOCTL_PRISM2_PARAM,
2159 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2160 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2161 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2162 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2163 /* --- sub-ioctls handlers --- */
2164 { PRISM2_IOCTL_PRISM2_PARAM,
2165 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2166 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2167 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2168 /* --- sub-ioctls definitions --- */
2169 { PRISM2_PARAM_TXRATECTRL,
2170 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2171 { PRISM2_PARAM_TXRATECTRL,
2172 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2173 { PRISM2_PARAM_BEACON_INT,
2174 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2175 { PRISM2_PARAM_BEACON_INT,
2176 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2177 #ifndef PRISM2_NO_STATION_MODES
2178 { PRISM2_PARAM_PSEUDO_IBSS,
2179 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2180 { PRISM2_PARAM_PSEUDO_IBSS,
2181 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2182 #endif /* PRISM2_NO_STATION_MODES */
2184 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2186 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2187 { PRISM2_PARAM_DUMP,
2188 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2189 { PRISM2_PARAM_DUMP,
2190 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2191 { PRISM2_PARAM_OTHER_AP_POLICY,
2192 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2193 { PRISM2_PARAM_OTHER_AP_POLICY,
2194 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2195 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2196 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2197 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2198 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2199 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2200 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2201 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2202 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2203 { PRISM2_PARAM_DTIM_PERIOD,
2204 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2205 { PRISM2_PARAM_DTIM_PERIOD,
2206 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2207 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2208 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2209 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2210 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2211 { PRISM2_PARAM_MAX_WDS,
2212 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2213 { PRISM2_PARAM_MAX_WDS,
2214 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2215 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2216 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2217 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2218 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2219 { PRISM2_PARAM_AP_AUTH_ALGS,
2220 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2221 { PRISM2_PARAM_AP_AUTH_ALGS,
2222 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2223 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2224 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2225 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2226 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2227 { PRISM2_PARAM_HOST_ENCRYPT,
2228 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2229 { PRISM2_PARAM_HOST_ENCRYPT,
2230 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2231 { PRISM2_PARAM_HOST_DECRYPT,
2232 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2233 { PRISM2_PARAM_HOST_DECRYPT,
2234 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2235 #ifndef PRISM2_NO_STATION_MODES
2236 { PRISM2_PARAM_HOST_ROAMING,
2237 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2238 { PRISM2_PARAM_HOST_ROAMING,
2239 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2240 #endif /* PRISM2_NO_STATION_MODES */
2241 { PRISM2_PARAM_BCRX_STA_KEY,
2242 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2243 { PRISM2_PARAM_BCRX_STA_KEY,
2244 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2245 { PRISM2_PARAM_IEEE_802_1X,
2246 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2247 { PRISM2_PARAM_IEEE_802_1X,
2248 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2249 { PRISM2_PARAM_ANTSEL_TX,
2250 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2251 { PRISM2_PARAM_ANTSEL_TX,
2252 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2253 { PRISM2_PARAM_ANTSEL_RX,
2254 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2255 { PRISM2_PARAM_ANTSEL_RX,
2256 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2257 { PRISM2_PARAM_MONITOR_TYPE,
2258 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2259 { PRISM2_PARAM_MONITOR_TYPE,
2260 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2261 { PRISM2_PARAM_WDS_TYPE,
2262 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2263 { PRISM2_PARAM_WDS_TYPE,
2264 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2265 { PRISM2_PARAM_HOSTSCAN,
2266 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2267 { PRISM2_PARAM_HOSTSCAN,
2268 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2269 { PRISM2_PARAM_AP_SCAN,
2270 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2271 { PRISM2_PARAM_AP_SCAN,
2272 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2273 { PRISM2_PARAM_ENH_SEC,
2274 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2275 { PRISM2_PARAM_ENH_SEC,
2276 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2277 #ifdef PRISM2_IO_DEBUG
2278 { PRISM2_PARAM_IO_DEBUG,
2279 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2280 { PRISM2_PARAM_IO_DEBUG,
2281 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2282 #endif /* PRISM2_IO_DEBUG */
2283 { PRISM2_PARAM_BASIC_RATES,
2284 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2285 { PRISM2_PARAM_BASIC_RATES,
2286 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2287 { PRISM2_PARAM_OPER_RATES,
2288 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2289 { PRISM2_PARAM_OPER_RATES,
2290 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2291 { PRISM2_PARAM_HOSTAPD,
2292 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2293 { PRISM2_PARAM_HOSTAPD,
2294 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2295 { PRISM2_PARAM_HOSTAPD_STA,
2296 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2297 { PRISM2_PARAM_HOSTAPD_STA,
2298 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2300 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2302 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2303 { PRISM2_PARAM_PRIVACY_INVOKED,
2304 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2305 { PRISM2_PARAM_PRIVACY_INVOKED,
2306 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2307 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2308 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2309 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2310 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2311 { PRISM2_PARAM_DROP_UNENCRYPTED,
2312 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2313 { PRISM2_PARAM_DROP_UNENCRYPTED,
2314 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
2315 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2316 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
2317 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2318 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
2322 static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2324 struct hostap_interface *iface;
2325 local_info_t *local;
2327 iface = netdev_priv(dev);
2328 local = iface->local;
2330 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2337 static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2338 struct iw_request_info *info,
2339 void *wrqu, char *extra)
2341 struct hostap_interface *iface;
2342 local_info_t *local;
2343 int *i = (int *) extra;
2345 int value = *(i + 1);
2349 iface = netdev_priv(dev);
2350 local = iface->local;
2353 case PRISM2_PARAM_TXRATECTRL:
2354 local->fw_tx_rate_control = value;
2357 case PRISM2_PARAM_BEACON_INT:
2358 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2359 local->func->reset_port(dev))
2362 local->beacon_int = value;
2365 #ifndef PRISM2_NO_STATION_MODES
2366 case PRISM2_PARAM_PSEUDO_IBSS:
2367 if (value == local->pseudo_adhoc)
2370 if (value != 0 && value != 1) {
2375 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2376 dev->name, local->pseudo_adhoc, value);
2377 local->pseudo_adhoc = value;
2378 if (local->iw_mode != IW_MODE_ADHOC)
2381 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2382 hostap_get_porttype(local))) {
2387 if (local->func->reset_port(dev))
2390 #endif /* PRISM2_NO_STATION_MODES */
2392 case PRISM2_PARAM_ALC:
2393 printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2394 value == 0 ? "Disabling" : "Enabling");
2395 val = HFA384X_TEST_CFG_BIT_ALC;
2396 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2397 (HFA384X_TEST_CFG_BITS << 8),
2398 value == 0 ? 0 : 1, &val, NULL);
2401 case PRISM2_PARAM_DUMP:
2402 local->frame_dump = value;
2405 case PRISM2_PARAM_OTHER_AP_POLICY:
2406 if (value < 0 || value > 3) {
2410 if (local->ap != NULL)
2411 local->ap->ap_policy = value;
2414 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2415 if (value < 0 || value > 7 * 24 * 60 * 60) {
2419 if (local->ap != NULL)
2420 local->ap->max_inactivity = value * HZ;
2423 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2424 if (local->ap != NULL)
2425 local->ap->bridge_packets = value;
2428 case PRISM2_PARAM_DTIM_PERIOD:
2429 if (value < 0 || value > 65535) {
2433 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2434 || local->func->reset_port(dev))
2437 local->dtim_period = value;
2440 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2441 if (local->ap != NULL)
2442 local->ap->nullfunc_ack = value;
2445 case PRISM2_PARAM_MAX_WDS:
2446 local->wds_max_connections = value;
2449 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2450 if (local->ap != NULL) {
2451 if (!local->ap->autom_ap_wds && value) {
2452 /* add WDS link to all APs in STA table */
2453 hostap_add_wds_links(local);
2455 local->ap->autom_ap_wds = value;
2459 case PRISM2_PARAM_AP_AUTH_ALGS:
2460 local->auth_algs = value;
2461 if (hostap_set_auth_algs(local))
2465 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2466 local->monitor_allow_fcserr = value;
2469 case PRISM2_PARAM_HOST_ENCRYPT:
2470 local->host_encrypt = value;
2471 if (hostap_set_encryption(local) ||
2472 local->func->reset_port(dev))
2476 case PRISM2_PARAM_HOST_DECRYPT:
2477 local->host_decrypt = value;
2478 if (hostap_set_encryption(local) ||
2479 local->func->reset_port(dev))
2483 #ifndef PRISM2_NO_STATION_MODES
2484 case PRISM2_PARAM_HOST_ROAMING:
2485 if (value < 0 || value > 2) {
2489 local->host_roaming = value;
2490 if (hostap_set_roaming(local) || local->func->reset_port(dev))
2493 #endif /* PRISM2_NO_STATION_MODES */
2495 case PRISM2_PARAM_BCRX_STA_KEY:
2496 local->bcrx_sta_key = value;
2499 case PRISM2_PARAM_IEEE_802_1X:
2500 local->ieee_802_1x = value;
2503 case PRISM2_PARAM_ANTSEL_TX:
2504 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2508 local->antsel_tx = value;
2509 hostap_set_antsel(local);
2512 case PRISM2_PARAM_ANTSEL_RX:
2513 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2517 local->antsel_rx = value;
2518 hostap_set_antsel(local);
2521 case PRISM2_PARAM_MONITOR_TYPE:
2522 if (value != PRISM2_MONITOR_80211 &&
2523 value != PRISM2_MONITOR_CAPHDR &&
2524 value != PRISM2_MONITOR_PRISM) {
2528 local->monitor_type = value;
2529 if (local->iw_mode == IW_MODE_MONITOR)
2530 hostap_monitor_set_type(local);
2533 case PRISM2_PARAM_WDS_TYPE:
2534 local->wds_type = value;
2537 case PRISM2_PARAM_HOSTSCAN:
2539 struct hfa384x_hostscan_request scan_req;
2542 memset(&scan_req, 0, sizeof(scan_req));
2543 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
2545 case 1: rate = HFA384X_RATES_1MBPS; break;
2546 case 2: rate = HFA384X_RATES_2MBPS; break;
2547 case 3: rate = HFA384X_RATES_5MBPS; break;
2548 case 4: rate = HFA384X_RATES_11MBPS; break;
2549 default: rate = HFA384X_RATES_1MBPS; break;
2551 scan_req.txrate = cpu_to_le16(rate);
2552 /* leave SSID empty to accept all SSIDs */
2554 if (local->iw_mode == IW_MODE_MASTER) {
2555 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2556 HFA384X_PORTTYPE_BSS) ||
2557 local->func->reset_port(dev))
2558 printk(KERN_DEBUG "Leaving Host AP mode "
2559 "for HostScan failed\n");
2562 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2563 sizeof(scan_req))) {
2564 printk(KERN_DEBUG "HOSTSCAN failed\n");
2567 if (local->iw_mode == IW_MODE_MASTER) {
2568 wait_queue_t __wait;
2569 init_waitqueue_entry(&__wait, current);
2570 add_wait_queue(&local->hostscan_wq, &__wait);
2571 set_current_state(TASK_INTERRUPTIBLE);
2572 schedule_timeout(HZ);
2573 if (signal_pending(current))
2575 set_current_state(TASK_RUNNING);
2576 remove_wait_queue(&local->hostscan_wq, &__wait);
2578 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2579 HFA384X_PORTTYPE_HOSTAP) ||
2580 local->func->reset_port(dev))
2581 printk(KERN_DEBUG "Returning to Host AP mode "
2582 "after HostScan failed\n");
2587 case PRISM2_PARAM_AP_SCAN:
2588 local->passive_scan_interval = value;
2589 if (timer_pending(&local->passive_scan_timer))
2590 del_timer(&local->passive_scan_timer);
2592 local->passive_scan_timer.expires = jiffies +
2593 local->passive_scan_interval * HZ;
2594 add_timer(&local->passive_scan_timer);
2598 case PRISM2_PARAM_ENH_SEC:
2599 if (value < 0 || value > 3) {
2603 local->enh_sec = value;
2604 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2606 local->func->reset_port(dev)) {
2607 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2608 "1.6.3 or newer\n", dev->name);
2613 #ifdef PRISM2_IO_DEBUG
2614 case PRISM2_PARAM_IO_DEBUG:
2615 local->io_debug_enabled = value;
2617 #endif /* PRISM2_IO_DEBUG */
2619 case PRISM2_PARAM_BASIC_RATES:
2620 if ((value & local->tx_rate_control) != value || value == 0) {
2621 printk(KERN_INFO "%s: invalid basic rate set - basic "
2622 "rates must be in supported rate set\n",
2627 local->basic_rates = value;
2628 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2629 local->basic_rates) ||
2630 local->func->reset_port(dev))
2634 case PRISM2_PARAM_OPER_RATES:
2635 local->tx_rate_control = value;
2636 if (hostap_set_rate(dev))
2640 case PRISM2_PARAM_HOSTAPD:
2641 ret = hostap_set_hostapd(local, value, 1);
2644 case PRISM2_PARAM_HOSTAPD_STA:
2645 ret = hostap_set_hostapd_sta(local, value, 1);
2648 case PRISM2_PARAM_WPA:
2650 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2652 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2657 case PRISM2_PARAM_PRIVACY_INVOKED:
2658 local->privacy_invoked = value;
2659 if (hostap_set_encryption(local) ||
2660 local->func->reset_port(dev))
2664 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2665 local->tkip_countermeasures = value;
2668 case PRISM2_PARAM_DROP_UNENCRYPTED:
2669 local->drop_unencrypted = value;
2672 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2673 local->scan_channel_mask = value;
2677 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2687 static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2688 struct iw_request_info *info,
2689 void *wrqu, char *extra)
2691 struct hostap_interface *iface;
2692 local_info_t *local;
2693 int *param = (int *) extra;
2696 iface = netdev_priv(dev);
2697 local = iface->local;
2700 case PRISM2_PARAM_TXRATECTRL:
2701 *param = local->fw_tx_rate_control;
2704 case PRISM2_PARAM_BEACON_INT:
2705 *param = local->beacon_int;
2708 case PRISM2_PARAM_PSEUDO_IBSS:
2709 *param = local->pseudo_adhoc;
2712 case PRISM2_PARAM_ALC:
2713 ret = -EOPNOTSUPP; /* FIX */
2716 case PRISM2_PARAM_DUMP:
2717 *param = local->frame_dump;
2720 case PRISM2_PARAM_OTHER_AP_POLICY:
2721 if (local->ap != NULL)
2722 *param = local->ap->ap_policy;
2727 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2728 if (local->ap != NULL)
2729 *param = local->ap->max_inactivity / HZ;
2734 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2735 if (local->ap != NULL)
2736 *param = local->ap->bridge_packets;
2741 case PRISM2_PARAM_DTIM_PERIOD:
2742 *param = local->dtim_period;
2745 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2746 if (local->ap != NULL)
2747 *param = local->ap->nullfunc_ack;
2752 case PRISM2_PARAM_MAX_WDS:
2753 *param = local->wds_max_connections;
2756 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2757 if (local->ap != NULL)
2758 *param = local->ap->autom_ap_wds;
2763 case PRISM2_PARAM_AP_AUTH_ALGS:
2764 *param = local->auth_algs;
2767 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2768 *param = local->monitor_allow_fcserr;
2771 case PRISM2_PARAM_HOST_ENCRYPT:
2772 *param = local->host_encrypt;
2775 case PRISM2_PARAM_HOST_DECRYPT:
2776 *param = local->host_decrypt;
2779 case PRISM2_PARAM_HOST_ROAMING:
2780 *param = local->host_roaming;
2783 case PRISM2_PARAM_BCRX_STA_KEY:
2784 *param = local->bcrx_sta_key;
2787 case PRISM2_PARAM_IEEE_802_1X:
2788 *param = local->ieee_802_1x;
2791 case PRISM2_PARAM_ANTSEL_TX:
2792 *param = local->antsel_tx;
2795 case PRISM2_PARAM_ANTSEL_RX:
2796 *param = local->antsel_rx;
2799 case PRISM2_PARAM_MONITOR_TYPE:
2800 *param = local->monitor_type;
2803 case PRISM2_PARAM_WDS_TYPE:
2804 *param = local->wds_type;
2807 case PRISM2_PARAM_HOSTSCAN:
2811 case PRISM2_PARAM_AP_SCAN:
2812 *param = local->passive_scan_interval;
2815 case PRISM2_PARAM_ENH_SEC:
2816 *param = local->enh_sec;
2819 #ifdef PRISM2_IO_DEBUG
2820 case PRISM2_PARAM_IO_DEBUG:
2821 *param = local->io_debug_enabled;
2823 #endif /* PRISM2_IO_DEBUG */
2825 case PRISM2_PARAM_BASIC_RATES:
2826 *param = local->basic_rates;
2829 case PRISM2_PARAM_OPER_RATES:
2830 *param = local->tx_rate_control;
2833 case PRISM2_PARAM_HOSTAPD:
2834 *param = local->hostapd;
2837 case PRISM2_PARAM_HOSTAPD_STA:
2838 *param = local->hostapd_sta;
2841 case PRISM2_PARAM_WPA:
2842 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2844 *param = local->wpa;
2847 case PRISM2_PARAM_PRIVACY_INVOKED:
2848 *param = local->privacy_invoked;
2851 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2852 *param = local->tkip_countermeasures;
2855 case PRISM2_PARAM_DROP_UNENCRYPTED:
2856 *param = local->drop_unencrypted;
2859 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2860 *param = local->scan_channel_mask;
2864 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2874 static int prism2_ioctl_priv_readmif(struct net_device *dev,
2875 struct iw_request_info *info,
2876 void *wrqu, char *extra)
2878 struct hostap_interface *iface;
2879 local_info_t *local;
2882 iface = netdev_priv(dev);
2883 local = iface->local;
2885 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2895 static int prism2_ioctl_priv_writemif(struct net_device *dev,
2896 struct iw_request_info *info,
2897 void *wrqu, char *extra)
2899 struct hostap_interface *iface;
2900 local_info_t *local;
2903 iface = netdev_priv(dev);
2904 local = iface->local;
2908 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2915 static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2917 struct hostap_interface *iface;
2918 local_info_t *local;
2922 iface = netdev_priv(dev);
2923 local = iface->local;
2925 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2926 "- update software to use iwconfig mode monitor\n",
2927 dev->name, current->pid, current->comm);
2929 /* Backward compatibility code - this can be removed at some point */
2932 /* Disable monitor mode - old mode was not saved, so go to
2934 mode = IW_MODE_MASTER;
2935 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2936 } else if (*i == 1) {
2937 /* netlink socket mode is not supported anymore since it did
2938 * not separate different devices from each other and was not
2939 * best method for delivering large amount of packets to
2942 } else if (*i == 2 || *i == 3) {
2945 local->monitor_type = PRISM2_MONITOR_80211;
2948 local->monitor_type = PRISM2_MONITOR_PRISM;
2951 mode = IW_MODE_MONITOR;
2952 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2953 hostap_monitor_mode_enable(local);
2961 static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
2963 struct hostap_interface *iface;
2964 local_info_t *local;
2966 iface = netdev_priv(dev);
2967 local = iface->local;
2969 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
2972 /* Disable and enable card */
2973 local->func->hw_shutdown(dev, 1);
2974 local->func->hw_config(dev, 0);
2979 local->func->hw_reset(dev);
2983 /* Disable and enable port 0 */
2984 local->func->reset_port(dev);
2988 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
2989 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
2995 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
3001 printk(KERN_DEBUG "Unknown reset request %d\n", *i);
3009 static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
3012 int value = *(i + 1);
3014 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
3016 if (hostap_set_word(dev, rid, value))
3023 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3024 static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3029 case AP_MAC_CMD_POLICY_OPEN:
3030 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3032 case AP_MAC_CMD_POLICY_ALLOW:
3033 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3035 case AP_MAC_CMD_POLICY_DENY:
3036 local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3038 case AP_MAC_CMD_FLUSH:
3039 ap_control_flush_macs(&local->ap->mac_restrictions);
3041 case AP_MAC_CMD_KICKALL:
3042 ap_control_kickall(local->ap);
3043 hostap_deauth_all_stas(local->dev, local->ap, 0);
3052 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3055 #ifdef PRISM2_DOWNLOAD_SUPPORT
3056 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3058 struct prism2_download_param *param;
3061 if (p->length < sizeof(struct prism2_download_param) ||
3062 p->length > 1024 || !p->pointer)
3065 param = (struct prism2_download_param *)
3066 kmalloc(p->length, GFP_KERNEL);
3070 if (copy_from_user(param, p->pointer, p->length)) {
3075 if (p->length < sizeof(struct prism2_download_param) +
3076 param->num_areas * sizeof(struct prism2_download_area)) {
3081 ret = local->func->download(local, param);
3089 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3092 static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
3095 struct hostap_interface *iface = dev->priv;
3096 local_info_t *local = iface->local;
3100 * Add 16-bit length in the beginning of the buffer because Prism2 RID
3103 buf = kmalloc(len + 2, GFP_KERNEL);
3107 *((u16 *) buf) = cpu_to_le16(len);
3108 memcpy(buf + 2, elem, len);
3110 kfree(local->generic_elem);
3111 local->generic_elem = buf;
3112 local->generic_elem_len = len + 2;
3114 return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
3119 static int prism2_ioctl_siwauth(struct net_device *dev,
3120 struct iw_request_info *info,
3121 struct iw_param *data, char *extra)
3123 struct hostap_interface *iface = dev->priv;
3124 local_info_t *local = iface->local;
3126 switch (data->flags & IW_AUTH_INDEX) {
3127 case IW_AUTH_WPA_VERSION:
3128 case IW_AUTH_CIPHER_PAIRWISE:
3129 case IW_AUTH_CIPHER_GROUP:
3130 case IW_AUTH_KEY_MGMT:
3132 * Host AP driver does not use these parameters and allows
3133 * wpa_supplicant to control them internally.
3136 case IW_AUTH_TKIP_COUNTERMEASURES:
3137 local->tkip_countermeasures = data->value;
3139 case IW_AUTH_DROP_UNENCRYPTED:
3140 local->drop_unencrypted = data->value;
3142 case IW_AUTH_80211_AUTH_ALG:
3143 local->auth_algs = data->value;
3145 case IW_AUTH_WPA_ENABLED:
3146 if (data->value == 0) {
3148 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3150 prism2_set_genericelement(dev, "", 0);
3151 local->host_roaming = 0;
3152 local->privacy_invoked = 0;
3153 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
3155 hostap_set_roaming(local) ||
3156 hostap_set_encryption(local) ||
3157 local->func->reset_port(dev))
3161 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3163 local->host_roaming = 2;
3164 local->privacy_invoked = 1;
3166 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
3167 hostap_set_roaming(local) ||
3168 hostap_set_encryption(local) ||
3169 local->func->reset_port(dev))
3172 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3173 local->ieee_802_1x = data->value;
3175 case IW_AUTH_PRIVACY_INVOKED:
3176 local->privacy_invoked = data->value;
3185 static int prism2_ioctl_giwauth(struct net_device *dev,
3186 struct iw_request_info *info,
3187 struct iw_param *data, char *extra)
3189 struct hostap_interface *iface = dev->priv;
3190 local_info_t *local = iface->local;
3192 switch (data->flags & IW_AUTH_INDEX) {
3193 case IW_AUTH_WPA_VERSION:
3194 case IW_AUTH_CIPHER_PAIRWISE:
3195 case IW_AUTH_CIPHER_GROUP:
3196 case IW_AUTH_KEY_MGMT:
3198 * Host AP driver does not use these parameters and allows
3199 * wpa_supplicant to control them internally.
3202 case IW_AUTH_TKIP_COUNTERMEASURES:
3203 data->value = local->tkip_countermeasures;
3205 case IW_AUTH_DROP_UNENCRYPTED:
3206 data->value = local->drop_unencrypted;
3208 case IW_AUTH_80211_AUTH_ALG:
3209 data->value = local->auth_algs;
3211 case IW_AUTH_WPA_ENABLED:
3212 data->value = local->wpa;
3214 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3215 data->value = local->ieee_802_1x;
3224 static int prism2_ioctl_siwencodeext(struct net_device *dev,
3225 struct iw_request_info *info,
3226 struct iw_point *erq, char *extra)
3228 struct hostap_interface *iface = dev->priv;
3229 local_info_t *local = iface->local;
3230 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3232 struct ieee80211_crypto_ops *ops;
3233 struct ieee80211_crypt_data **crypt;
3236 const char *alg, *module;
3238 i = erq->flags & IW_ENCODE_INDEX;
3241 if (i < 1 || i > WEP_KEYS)
3242 i = local->tx_keyidx;
3245 if (i < 0 || i >= WEP_KEYS)
3248 addr = ext->addr.sa_data;
3249 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3250 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3252 crypt = &local->crypt[i];
3256 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3257 if (sta_ptr == NULL) {
3258 if (local->iw_mode == IW_MODE_INFRA) {
3260 * TODO: add STA entry for the current AP so
3261 * that unicast key can be used. For now, this
3262 * is emulated by using default key idx 0.
3265 crypt = &local->crypt[i];
3271 if ((erq->flags & IW_ENCODE_DISABLED) ||
3272 ext->alg == IW_ENCODE_ALG_NONE) {
3274 prism2_crypt_delayed_deinit(local, crypt);
3279 case IW_ENCODE_ALG_WEP:
3281 module = "ieee80211_crypt_wep";
3283 case IW_ENCODE_ALG_TKIP:
3285 module = "ieee80211_crypt_tkip";
3287 case IW_ENCODE_ALG_CCMP:
3289 module = "ieee80211_crypt_ccmp";
3292 printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
3293 local->dev->name, ext->alg);
3298 ops = ieee80211_get_crypto_ops(alg);
3300 request_module(module);
3301 ops = ieee80211_get_crypto_ops(alg);
3304 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3305 local->dev->name, alg);
3310 if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
3312 * Per station encryption and other than WEP algorithms
3313 * require host-based encryption, so force them on
3316 local->host_decrypt = local->host_encrypt = 1;
3319 if (*crypt == NULL || (*crypt)->ops != ops) {
3320 struct ieee80211_crypt_data *new_crypt;
3322 prism2_crypt_delayed_deinit(local, crypt);
3324 new_crypt = (struct ieee80211_crypt_data *)
3325 kmalloc(sizeof(struct ieee80211_crypt_data),
3327 if (new_crypt == NULL) {
3331 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3332 new_crypt->ops = ops;
3333 new_crypt->priv = new_crypt->ops->init(i);
3334 if (new_crypt->priv == NULL) {
3344 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
3345 * existing seq# should not be changed.
3346 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
3347 * should be changed to something else than zero.
3349 if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
3350 && (*crypt)->ops->set_key &&
3351 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
3352 (*crypt)->priv) < 0) {
3353 printk(KERN_DEBUG "%s: key setting failed\n",
3359 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3361 local->tx_keyidx = i;
3369 if (sta_ptr == NULL && ext->key_len > 0) {
3371 for (j = 0; j < WEP_KEYS; j++) {
3372 if (j != i && local->crypt[j]) {
3378 local->tx_keyidx = i;
3383 hostap_handle_sta_release(sta_ptr);
3385 local->open_wep = erq->flags & IW_ENCODE_OPEN;
3388 * Do not reset port0 if card is in Managed mode since resetting will
3389 * generate new IEEE 802.11 authentication which may end up in looping
3390 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3391 * after WEP configuration. However, keys are apparently changed at
3392 * least in Managed mode.
3395 (hostap_set_encryption(local) ||
3396 (local->iw_mode != IW_MODE_INFRA &&
3397 local->func->reset_port(local->dev))))
3404 static int prism2_ioctl_giwencodeext(struct net_device *dev,
3405 struct iw_request_info *info,
3406 struct iw_point *erq, char *extra)
3408 struct hostap_interface *iface = dev->priv;
3409 local_info_t *local = iface->local;
3410 struct ieee80211_crypt_data **crypt;
3413 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3416 max_key_len = erq->length - sizeof(*ext);
3417 if (max_key_len < 0)
3420 i = erq->flags & IW_ENCODE_INDEX;
3421 if (i < 1 || i > WEP_KEYS)
3422 i = local->tx_keyidx;
3426 addr = ext->addr.sa_data;
3427 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3428 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3430 crypt = &local->crypt[i];
3433 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3434 if (sta_ptr == NULL)
3438 memset(ext, 0, sizeof(*ext));
3440 if (*crypt == NULL || (*crypt)->ops == NULL) {
3441 ext->alg = IW_ENCODE_ALG_NONE;
3443 erq->flags |= IW_ENCODE_DISABLED;
3445 if (strcmp((*crypt)->ops->name, "WEP") == 0)
3446 ext->alg = IW_ENCODE_ALG_WEP;
3447 else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
3448 ext->alg = IW_ENCODE_ALG_TKIP;
3449 else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
3450 ext->alg = IW_ENCODE_ALG_CCMP;
3454 if ((*crypt)->ops->get_key) {
3456 (*crypt)->ops->get_key(ext->key,
3461 (ext->alg == IW_ENCODE_ALG_TKIP ||
3462 ext->alg == IW_ENCODE_ALG_CCMP))
3463 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
3468 hostap_handle_sta_release(sta_ptr);
3474 static int prism2_ioctl_set_encryption(local_info_t *local,
3475 struct prism2_hostapd_param *param,
3479 struct ieee80211_crypto_ops *ops;
3480 struct ieee80211_crypt_data **crypt;
3483 param->u.crypt.err = 0;
3484 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
3487 (int) ((char *) param->u.crypt.key - (char *) param) +
3488 param->u.crypt.key_len)
3491 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3492 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3493 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3494 if (param->u.crypt.idx >= WEP_KEYS)
3497 crypt = &local->crypt[param->u.crypt.idx];
3499 if (param->u.crypt.idx)
3501 sta_ptr = ap_crypt_get_ptrs(
3502 local->ap, param->sta_addr,
3503 (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
3506 if (sta_ptr == NULL) {
3507 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3512 if (strcmp(param->u.crypt.alg, "none") == 0) {
3514 prism2_crypt_delayed_deinit(local, crypt);
3518 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3519 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3520 request_module("ieee80211_crypt_wep");
3521 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3522 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3523 request_module("ieee80211_crypt_tkip");
3524 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3525 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3526 request_module("ieee80211_crypt_ccmp");
3527 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3530 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3531 local->dev->name, param->u.crypt.alg);
3532 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
3537 /* station based encryption and other than WEP algorithms require
3538 * host-based encryption, so force them on automatically */
3539 local->host_decrypt = local->host_encrypt = 1;
3541 if (*crypt == NULL || (*crypt)->ops != ops) {
3542 struct ieee80211_crypt_data *new_crypt;
3544 prism2_crypt_delayed_deinit(local, crypt);
3546 new_crypt = (struct ieee80211_crypt_data *)
3547 kmalloc(sizeof(struct ieee80211_crypt_data),
3549 if (new_crypt == NULL) {
3553 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3554 new_crypt->ops = ops;
3555 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
3556 if (new_crypt->priv == NULL) {
3558 param->u.crypt.err =
3559 HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
3567 if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
3568 param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
3569 (*crypt)->ops->set_key(param->u.crypt.key,
3570 param->u.crypt.key_len, param->u.crypt.seq,
3571 (*crypt)->priv) < 0) {
3572 printk(KERN_DEBUG "%s: key setting failed\n",
3574 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
3579 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
3581 local->tx_keyidx = param->u.crypt.idx;
3582 else if (param->u.crypt.idx) {
3583 printk(KERN_DEBUG "%s: TX key idx setting failed\n",
3585 param->u.crypt.err =
3586 HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
3594 hostap_handle_sta_release(sta_ptr);
3596 /* Do not reset port0 if card is in Managed mode since resetting will
3597 * generate new IEEE 802.11 authentication which may end up in looping
3598 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3599 * after WEP configuration. However, keys are apparently changed at
3600 * least in Managed mode. */
3602 (hostap_set_encryption(local) ||
3603 (local->iw_mode != IW_MODE_INFRA &&
3604 local->func->reset_port(local->dev)))) {
3605 param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
3613 static int prism2_ioctl_get_encryption(local_info_t *local,
3614 struct prism2_hostapd_param *param,
3617 struct ieee80211_crypt_data **crypt;
3621 param->u.crypt.err = 0;
3623 max_key_len = param_len -
3624 (int) ((char *) param->u.crypt.key - (char *) param);
3625 if (max_key_len < 0)
3628 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3629 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3630 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3632 if (param->u.crypt.idx >= WEP_KEYS)
3633 param->u.crypt.idx = local->tx_keyidx;
3634 crypt = &local->crypt[param->u.crypt.idx];
3636 param->u.crypt.idx = 0;
3637 sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
3640 if (sta_ptr == NULL) {
3641 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3646 if (*crypt == NULL || (*crypt)->ops == NULL) {
3647 memcpy(param->u.crypt.alg, "none", 5);
3648 param->u.crypt.key_len = 0;
3649 param->u.crypt.idx = 0xff;
3651 strncpy(param->u.crypt.alg, (*crypt)->ops->name,
3652 HOSTAP_CRYPT_ALG_NAME_LEN);
3653 param->u.crypt.key_len = 0;
3655 memset(param->u.crypt.seq, 0, 8);
3656 if ((*crypt)->ops->get_key) {
3657 param->u.crypt.key_len =
3658 (*crypt)->ops->get_key(param->u.crypt.key,
3666 hostap_handle_sta_release(sta_ptr);
3672 static int prism2_ioctl_get_rid(local_info_t *local,
3673 struct prism2_hostapd_param *param,
3678 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3682 res = local->func->get_rid(local->dev, param->u.rid.rid,
3683 param->u.rid.data, param->u.rid.len, 0);
3685 param->u.rid.len = res;
3693 static int prism2_ioctl_set_rid(local_info_t *local,
3694 struct prism2_hostapd_param *param,
3699 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3700 if (max_len < 0 || max_len < param->u.rid.len)
3703 return local->func->set_rid(local->dev, param->u.rid.rid,
3704 param->u.rid.data, param->u.rid.len);
3708 static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
3709 struct prism2_hostapd_param *param,
3712 printk(KERN_DEBUG "%ssta: associated as client with AP " MACSTR "\n",
3713 local->dev->name, MAC2STR(param->sta_addr));
3714 memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
3719 static int prism2_ioctl_siwgenie(struct net_device *dev,
3720 struct iw_request_info *info,
3721 struct iw_point *data, char *extra)
3723 return prism2_set_genericelement(dev, extra, data->length);
3727 static int prism2_ioctl_giwgenie(struct net_device *dev,
3728 struct iw_request_info *info,
3729 struct iw_point *data, char *extra)
3731 struct hostap_interface *iface = dev->priv;
3732 local_info_t *local = iface->local;
3733 int len = local->generic_elem_len - 2;
3735 if (len <= 0 || local->generic_elem == NULL) {
3740 if (data->length < len)
3744 memcpy(extra, local->generic_elem + 2, len);
3750 static int prism2_ioctl_set_generic_element(local_info_t *local,
3751 struct prism2_hostapd_param *param,
3756 len = param->u.generic_elem.len;
3757 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
3758 if (max_len < 0 || max_len < len)
3761 return prism2_set_genericelement(local->dev,
3762 param->u.generic_elem.data, len);
3766 static int prism2_ioctl_siwmlme(struct net_device *dev,
3767 struct iw_request_info *info,
3768 struct iw_point *data, char *extra)
3770 struct hostap_interface *iface = dev->priv;
3771 local_info_t *local = iface->local;
3772 struct iw_mlme *mlme = (struct iw_mlme *) extra;
3775 reason = cpu_to_le16(mlme->reason_code);
3777 switch (mlme->cmd) {
3778 case IW_MLME_DEAUTH:
3779 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3780 IEEE80211_STYPE_DEAUTH,
3782 case IW_MLME_DISASSOC:
3783 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3784 IEEE80211_STYPE_DISASSOC,
3792 static int prism2_ioctl_mlme(local_info_t *local,
3793 struct prism2_hostapd_param *param)
3797 reason = cpu_to_le16(param->u.mlme.reason_code);
3798 switch (param->u.mlme.cmd) {
3799 case MLME_STA_DEAUTH:
3800 return prism2_sta_send_mgmt(local, param->sta_addr,
3801 IEEE80211_STYPE_DEAUTH,
3803 case MLME_STA_DISASSOC:
3804 return prism2_sta_send_mgmt(local, param->sta_addr,
3805 IEEE80211_STYPE_DISASSOC,
3813 static int prism2_ioctl_scan_req(local_info_t *local,
3814 struct prism2_hostapd_param *param)
3816 #ifndef PRISM2_NO_STATION_MODES
3817 if ((local->iw_mode != IW_MODE_INFRA &&
3818 local->iw_mode != IW_MODE_ADHOC) ||
3819 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
3822 if (!local->dev_enabled)
3825 return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
3826 param->u.scan_req.ssid_len);
3827 #else /* PRISM2_NO_STATION_MODES */
3829 #endif /* PRISM2_NO_STATION_MODES */
3833 static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3835 struct prism2_hostapd_param *param;
3839 if (p->length < sizeof(struct prism2_hostapd_param) ||
3840 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
3843 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
3847 if (copy_from_user(param, p->pointer, p->length)) {
3852 switch (param->cmd) {
3853 case PRISM2_SET_ENCRYPTION:
3854 ret = prism2_ioctl_set_encryption(local, param, p->length);
3856 case PRISM2_GET_ENCRYPTION:
3857 ret = prism2_ioctl_get_encryption(local, param, p->length);
3859 case PRISM2_HOSTAPD_GET_RID:
3860 ret = prism2_ioctl_get_rid(local, param, p->length);
3862 case PRISM2_HOSTAPD_SET_RID:
3863 ret = prism2_ioctl_set_rid(local, param, p->length);
3865 case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
3866 ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
3868 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
3869 ret = prism2_ioctl_set_generic_element(local, param,
3872 case PRISM2_HOSTAPD_MLME:
3873 ret = prism2_ioctl_mlme(local, param);
3875 case PRISM2_HOSTAPD_SCAN_REQ:
3876 ret = prism2_ioctl_scan_req(local, param);
3879 ret = prism2_hostapd(local->ap, param);
3884 if (ret == 1 || !ap_ioctl) {
3885 if (copy_to_user(p->pointer, param, p->length)) {
3888 } else if (ap_ioctl)
3900 static void prism2_get_drvinfo(struct net_device *dev,
3901 struct ethtool_drvinfo *info)
3903 struct hostap_interface *iface;
3904 local_info_t *local;
3906 iface = netdev_priv(dev);
3907 local = iface->local;
3909 strncpy(info->driver, "hostap", sizeof(info->driver) - 1);
3910 strncpy(info->version, PRISM2_VERSION,
3911 sizeof(info->version) - 1);
3912 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
3913 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
3914 (local->sta_fw_ver >> 8) & 0xff,
3915 local->sta_fw_ver & 0xff);
3918 static struct ethtool_ops prism2_ethtool_ops = {
3919 .get_drvinfo = prism2_get_drvinfo
3923 /* Structures to export the Wireless Handlers */
3925 static const iw_handler prism2_handler[] =
3927 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3928 (iw_handler) prism2_get_name, /* SIOCGIWNAME */
3929 (iw_handler) NULL, /* SIOCSIWNWID */
3930 (iw_handler) NULL, /* SIOCGIWNWID */
3931 (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */
3932 (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */
3933 (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */
3934 (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */
3935 (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */
3936 (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */
3937 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3938 (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */
3939 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3940 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3941 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3942 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
3943 iw_handler_set_spy, /* SIOCSIWSPY */
3944 iw_handler_get_spy, /* SIOCGIWSPY */
3945 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
3946 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
3947 (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */
3948 (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */
3949 (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */
3950 (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */
3951 (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */
3952 (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */
3953 (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */
3954 (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */
3955 (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */
3956 (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */
3957 (iw_handler) NULL, /* -- hole -- */
3958 (iw_handler) NULL, /* -- hole -- */
3959 (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */
3960 (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */
3961 (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */
3962 (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */
3963 (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */
3964 (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */
3965 (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */
3966 (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */
3967 (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */
3968 (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */
3969 (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */
3970 (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */
3971 (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */
3972 (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */
3973 (iw_handler) NULL, /* -- hole -- */
3974 (iw_handler) NULL, /* -- hole -- */
3975 (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */
3976 (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */
3977 (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */
3978 (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */
3979 (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3980 (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3981 (iw_handler) NULL, /* SIOCSIWPMKSA */
3982 (iw_handler) NULL, /* -- hole -- */
3985 static const iw_handler prism2_private_handler[] =
3986 { /* SIOCIWFIRSTPRIV + */
3987 (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */
3988 (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
3989 (iw_handler) prism2_ioctl_priv_writemif, /* 2 */
3990 (iw_handler) prism2_ioctl_priv_readmif, /* 3 */
3993 static const struct iw_handler_def hostap_iw_handler_def =
3995 .num_standard = sizeof(prism2_handler) / sizeof(iw_handler),
3996 .num_private = sizeof(prism2_private_handler) / sizeof(iw_handler),
3997 .num_private_args = sizeof(prism2_priv) / sizeof(struct iw_priv_args),
3998 .standard = (iw_handler *) prism2_handler,
3999 .private = (iw_handler *) prism2_private_handler,
4000 .private_args = (struct iw_priv_args *) prism2_priv,
4001 .get_wireless_stats = hostap_get_wireless_stats,
4005 int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4007 struct iwreq *wrq = (struct iwreq *) ifr;
4008 struct hostap_interface *iface;
4009 local_info_t *local;
4012 iface = netdev_priv(dev);
4013 local = iface->local;
4016 /* Private ioctls (iwpriv) that have not yet been converted
4017 * into new wireless extensions API */
4019 case PRISM2_IOCTL_INQUIRE:
4020 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4021 else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
4024 case PRISM2_IOCTL_MONITOR:
4025 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4026 else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
4029 case PRISM2_IOCTL_RESET:
4030 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4031 else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
4034 case PRISM2_IOCTL_WDS_ADD:
4035 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4036 else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
4039 case PRISM2_IOCTL_WDS_DEL:
4040 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4041 else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
4044 case PRISM2_IOCTL_SET_RID_WORD:
4045 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4046 else ret = prism2_ioctl_priv_set_rid_word(dev,
4047 (int *) wrq->u.name);
4050 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
4051 case PRISM2_IOCTL_MACCMD:
4052 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4053 else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
4056 case PRISM2_IOCTL_ADDMAC:
4057 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4058 else ret = ap_control_add_mac(&local->ap->mac_restrictions,
4059 wrq->u.ap_addr.sa_data);
4061 case PRISM2_IOCTL_DELMAC:
4062 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4063 else ret = ap_control_del_mac(&local->ap->mac_restrictions,
4064 wrq->u.ap_addr.sa_data);
4066 case PRISM2_IOCTL_KICKMAC:
4067 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4068 else ret = ap_control_kick_mac(local->ap, local->dev,
4069 wrq->u.ap_addr.sa_data);
4071 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
4074 /* Private ioctls that are not used with iwpriv;
4075 * in SIOCDEVPRIVATE range */
4077 #ifdef PRISM2_DOWNLOAD_SUPPORT
4078 case PRISM2_IOCTL_DOWNLOAD:
4079 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4080 else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
4082 #endif /* PRISM2_DOWNLOAD_SUPPORT */
4084 case PRISM2_IOCTL_HOSTAPD:
4085 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4086 else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);