1 /* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
3 #include <linux/types.h>
4 #include <linux/smp_lock.h>
5 #include <linux/ethtool.h>
6 #include <net/ieee80211_crypt.h>
8 #include "hostap_wlan.h"
10 #include "hostap_ap.h"
12 static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
14 struct hostap_interface *iface;
16 struct iw_statistics *wstats;
18 iface = netdev_priv(dev);
21 /* Why are we doing that ? Jean II */
22 if (iface->type != HOSTAP_INTERFACE_MAIN)
25 wstats = &local->wstats;
28 wstats->discard.code =
29 local->comm_tallies.rx_discards_wep_undecryptable;
30 wstats->discard.misc =
31 local->comm_tallies.rx_fcs_errors +
32 local->comm_tallies.rx_discards_no_buffer +
33 local->comm_tallies.tx_discards_wrong_sa;
35 wstats->discard.retries =
36 local->comm_tallies.tx_retry_limit_exceeded;
37 wstats->discard.fragment =
38 local->comm_tallies.rx_message_in_bad_msg_fragments;
40 if (local->iw_mode != IW_MODE_MASTER &&
41 local->iw_mode != IW_MODE_REPEAT) {
44 /* RID reading might sleep and it must not be called in
45 * interrupt context or while atomic. However, this
46 * function seems to be called while atomic (at least in Linux
47 * 2.5.59). Update signal quality values only if in suitable
48 * context. Otherwise, previous values read from tick timer
52 #endif /* in_atomic */
54 if (update && prism2_update_comms_qual(dev) == 0)
55 wstats->qual.updated = IW_QUAL_ALL_UPDATED |
58 wstats->qual.qual = local->comms_qual;
59 wstats->qual.level = local->avg_signal;
60 wstats->qual.noise = local->avg_noise;
62 wstats->qual.qual = 0;
63 wstats->qual.level = 0;
64 wstats->qual.noise = 0;
65 wstats->qual.updated = IW_QUAL_ALL_INVALID;
72 static int prism2_get_datarates(struct net_device *dev, u8 *rates)
74 struct hostap_interface *iface;
80 iface = netdev_priv(dev);
83 len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
88 val = le16_to_cpu(*(u16 *) buf); /* string length */
90 if (len - 2 < val || val > 10)
93 memcpy(rates, buf + 2, val);
98 static int prism2_get_name(struct net_device *dev,
99 struct iw_request_info *info,
100 char *name, char *extra)
103 int len, i, over2 = 0;
105 len = prism2_get_datarates(dev, rates);
107 for (i = 0; i < len; i++) {
108 if (rates[i] == 0x0b || rates[i] == 0x16) {
114 strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
120 static void prism2_crypt_delayed_deinit(local_info_t *local,
121 struct ieee80211_crypt_data **crypt)
123 struct ieee80211_crypt_data *tmp;
132 /* must not run ops->deinit() while there may be pending encrypt or
133 * decrypt operations. Use a list of delayed deinits to avoid needing
136 spin_lock_irqsave(&local->lock, flags);
137 list_add(&tmp->list, &local->crypt_deinit_list);
138 if (!timer_pending(&local->crypt_deinit_timer)) {
139 local->crypt_deinit_timer.expires = jiffies + HZ;
140 add_timer(&local->crypt_deinit_timer);
142 spin_unlock_irqrestore(&local->lock, flags);
146 static int prism2_ioctl_siwencode(struct net_device *dev,
147 struct iw_request_info *info,
148 struct iw_point *erq, char *keybuf)
150 struct hostap_interface *iface;
153 struct ieee80211_crypt_data **crypt;
155 iface = netdev_priv(dev);
156 local = iface->local;
158 i = erq->flags & IW_ENCODE_INDEX;
160 i = local->tx_keyidx;
163 if (i < 0 || i >= WEP_KEYS)
166 crypt = &local->crypt[i];
168 if (erq->flags & IW_ENCODE_DISABLED) {
170 prism2_crypt_delayed_deinit(local, crypt);
174 if (*crypt != NULL && (*crypt)->ops != NULL &&
175 strcmp((*crypt)->ops->name, "WEP") != 0) {
176 /* changing to use WEP; deinit previously used algorithm */
177 prism2_crypt_delayed_deinit(local, crypt);
180 if (*crypt == NULL) {
181 struct ieee80211_crypt_data *new_crypt;
183 /* take WEP into use */
184 new_crypt = (struct ieee80211_crypt_data *)
185 kmalloc(sizeof(struct ieee80211_crypt_data),
187 if (new_crypt == NULL)
189 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
190 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
191 if (!new_crypt->ops) {
192 request_module("ieee80211_crypt_wep");
193 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
196 new_crypt->priv = new_crypt->ops->init(i);
197 if (!new_crypt->ops || !new_crypt->priv) {
201 printk(KERN_WARNING "%s: could not initialize WEP: "
202 "load module hostap_crypt_wep.o\n",
209 if (erq->length > 0) {
210 int len = erq->length <= 5 ? 5 : 13;
212 if (len > erq->length)
213 memset(keybuf + erq->length, 0, len - erq->length);
214 (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
215 for (j = 0; j < WEP_KEYS; j++) {
216 if (j != i && local->crypt[j]) {
222 local->tx_keyidx = i;
224 /* No key data - just set the default TX key index */
225 local->tx_keyidx = i;
229 local->open_wep = erq->flags & IW_ENCODE_OPEN;
231 if (hostap_set_encryption(local)) {
232 printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
236 /* Do not reset port0 if card is in Managed mode since resetting will
237 * generate new IEEE 802.11 authentication which may end up in looping
238 * with IEEE 802.1X. Prism2 documentation seem to require port reset
239 * after WEP configuration. However, keys are apparently changed at
240 * least in Managed mode. */
241 if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
242 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
250 static int prism2_ioctl_giwencode(struct net_device *dev,
251 struct iw_request_info *info,
252 struct iw_point *erq, char *key)
254 struct hostap_interface *iface;
258 struct ieee80211_crypt_data *crypt;
260 iface = netdev_priv(dev);
261 local = iface->local;
263 i = erq->flags & IW_ENCODE_INDEX;
265 i = local->tx_keyidx;
268 if (i < 0 || i >= WEP_KEYS)
271 crypt = local->crypt[i];
274 if (crypt == NULL || crypt->ops == NULL) {
276 erq->flags |= IW_ENCODE_DISABLED;
280 if (strcmp(crypt->ops->name, "WEP") != 0) {
281 /* only WEP is supported with wireless extensions, so just
282 * report that encryption is used */
284 erq->flags |= IW_ENCODE_ENABLED;
288 /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
289 * the keys from driver buffer */
290 len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
291 erq->length = (len >= 0 ? len : 0);
293 if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
295 printk("CNFWEPFLAGS reading failed\n");
299 if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
300 erq->flags |= IW_ENCODE_ENABLED;
302 erq->flags |= IW_ENCODE_DISABLED;
303 if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
304 erq->flags |= IW_ENCODE_RESTRICTED;
306 erq->flags |= IW_ENCODE_OPEN;
312 static int hostap_set_rate(struct net_device *dev)
314 struct hostap_interface *iface;
316 int ret, basic_rates;
318 iface = netdev_priv(dev);
319 local = iface->local;
321 basic_rates = local->basic_rates & local->tx_rate_control;
322 if (!basic_rates || basic_rates != local->basic_rates) {
323 printk(KERN_INFO "%s: updating basic rate set automatically "
324 "to match with the new supported rate set\n",
327 basic_rates = local->tx_rate_control;
329 local->basic_rates = basic_rates;
330 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
332 printk(KERN_WARNING "%s: failed to set "
333 "cnfBasicRates\n", dev->name);
336 ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
337 local->tx_rate_control) ||
338 hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
339 local->tx_rate_control) ||
340 local->func->reset_port(dev));
343 printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
344 "setting to 0x%x failed\n",
345 dev->name, local->tx_rate_control);
348 /* Update TX rate configuration for all STAs based on new operational
350 hostap_update_rates(local);
356 static int prism2_ioctl_siwrate(struct net_device *dev,
357 struct iw_request_info *info,
358 struct iw_param *rrq, char *extra)
360 struct hostap_interface *iface;
363 iface = netdev_priv(dev);
364 local = iface->local;
367 switch (rrq->value) {
369 local->tx_rate_control = HFA384X_RATES_11MBPS;
372 local->tx_rate_control = HFA384X_RATES_5MBPS;
375 local->tx_rate_control = HFA384X_RATES_2MBPS;
378 local->tx_rate_control = HFA384X_RATES_1MBPS;
381 local->tx_rate_control = HFA384X_RATES_1MBPS |
382 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
383 HFA384X_RATES_11MBPS;
387 switch (rrq->value) {
389 local->tx_rate_control = HFA384X_RATES_1MBPS |
390 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
391 HFA384X_RATES_11MBPS;
394 local->tx_rate_control = HFA384X_RATES_1MBPS |
395 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
398 local->tx_rate_control = HFA384X_RATES_1MBPS |
402 local->tx_rate_control = HFA384X_RATES_1MBPS;
405 local->tx_rate_control = HFA384X_RATES_1MBPS |
406 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
407 HFA384X_RATES_11MBPS;
412 return hostap_set_rate(dev);
416 static int prism2_ioctl_giwrate(struct net_device *dev,
417 struct iw_request_info *info,
418 struct iw_param *rrq, char *extra)
421 struct hostap_interface *iface;
425 iface = netdev_priv(dev);
426 local = iface->local;
428 if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
432 if ((val & 0x1) && (val > 1))
437 if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
438 !local->fw_tx_rate_control) {
439 /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
440 * Host AP mode, so use the recorded TX rate of the last sent
442 rrq->value = local->ap->last_tx_rate > 0 ?
443 local->ap->last_tx_rate * 100000 : 11000000;
447 if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
452 case HFA384X_RATES_1MBPS:
453 rrq->value = 1000000;
455 case HFA384X_RATES_2MBPS:
456 rrq->value = 2000000;
458 case HFA384X_RATES_5MBPS:
459 rrq->value = 5500000;
461 case HFA384X_RATES_11MBPS:
462 rrq->value = 11000000;
465 /* should not happen */
466 rrq->value = 11000000;
475 static int prism2_ioctl_siwsens(struct net_device *dev,
476 struct iw_request_info *info,
477 struct iw_param *sens, char *extra)
479 struct hostap_interface *iface;
482 iface = netdev_priv(dev);
483 local = iface->local;
485 /* Set the desired AP density */
486 if (sens->value < 1 || sens->value > 3)
489 if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
490 local->func->reset_port(dev))
496 static int prism2_ioctl_giwsens(struct net_device *dev,
497 struct iw_request_info *info,
498 struct iw_param *sens, char *extra)
500 struct hostap_interface *iface;
504 iface = netdev_priv(dev);
505 local = iface->local;
507 /* Get the current AP density */
508 if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
512 sens->value = __le16_to_cpu(val);
519 /* Deprecated in new wireless extension API */
520 static int prism2_ioctl_giwaplist(struct net_device *dev,
521 struct iw_request_info *info,
522 struct iw_point *data, char *extra)
524 struct hostap_interface *iface;
526 struct sockaddr *addr;
527 struct iw_quality *qual;
529 iface = netdev_priv(dev);
530 local = iface->local;
532 if (local->iw_mode != IW_MODE_MASTER) {
533 printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
534 "in Host AP mode\n");
539 addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
540 qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
541 if (addr == NULL || qual == NULL) {
548 data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
550 memcpy(extra, &addr, sizeof(struct sockaddr) * data->length);
551 data->flags = 1; /* has quality information */
552 memcpy(extra + sizeof(struct sockaddr) * data->length, &qual,
553 sizeof(struct iw_quality) * data->length);
561 static int prism2_ioctl_siwrts(struct net_device *dev,
562 struct iw_request_info *info,
563 struct iw_param *rts, char *extra)
565 struct hostap_interface *iface;
569 iface = netdev_priv(dev);
570 local = iface->local;
573 val = __constant_cpu_to_le16(2347);
574 else if (rts->value < 0 || rts->value > 2347)
577 val = __cpu_to_le16(rts->value);
579 if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) ||
580 local->func->reset_port(dev))
583 local->rts_threshold = rts->value;
588 static int prism2_ioctl_giwrts(struct net_device *dev,
589 struct iw_request_info *info,
590 struct iw_param *rts, char *extra)
592 struct hostap_interface *iface;
596 iface = netdev_priv(dev);
597 local = iface->local;
599 if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) <
603 rts->value = __le16_to_cpu(val);
604 rts->disabled = (rts->value == 2347);
611 static int prism2_ioctl_siwfrag(struct net_device *dev,
612 struct iw_request_info *info,
613 struct iw_param *rts, char *extra)
615 struct hostap_interface *iface;
619 iface = netdev_priv(dev);
620 local = iface->local;
623 val = __constant_cpu_to_le16(2346);
624 else if (rts->value < 256 || rts->value > 2346)
627 val = __cpu_to_le16(rts->value & ~0x1); /* even numbers only */
629 local->fragm_threshold = rts->value & ~0x1;
630 if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val,
632 || local->func->reset_port(dev))
638 static int prism2_ioctl_giwfrag(struct net_device *dev,
639 struct iw_request_info *info,
640 struct iw_param *rts, char *extra)
642 struct hostap_interface *iface;
646 iface = netdev_priv(dev);
647 local = iface->local;
649 if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
653 rts->value = __le16_to_cpu(val);
654 rts->disabled = (rts->value == 2346);
661 #ifndef PRISM2_NO_STATION_MODES
662 static int hostap_join_ap(struct net_device *dev)
664 struct hostap_interface *iface;
666 struct hfa384x_join_request req;
669 struct hfa384x_hostscan_result *entry;
671 iface = netdev_priv(dev);
672 local = iface->local;
674 memcpy(req.bssid, local->preferred_ap, ETH_ALEN);
677 spin_lock_irqsave(&local->lock, flags);
678 for (i = 0; i < local->last_scan_results_count; i++) {
679 if (!local->last_scan_results)
681 entry = &local->last_scan_results[i];
682 if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) {
683 req.channel = entry->chid;
687 spin_unlock_irqrestore(&local->lock, flags);
689 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
691 printk(KERN_DEBUG "%s: JoinRequest " MACSTR
693 dev->name, MAC2STR(local->preferred_ap));
697 printk(KERN_DEBUG "%s: Trying to join BSSID " MACSTR "\n",
698 dev->name, MAC2STR(local->preferred_ap));
702 #endif /* PRISM2_NO_STATION_MODES */
705 static int prism2_ioctl_siwap(struct net_device *dev,
706 struct iw_request_info *info,
707 struct sockaddr *ap_addr, char *extra)
709 #ifdef PRISM2_NO_STATION_MODES
711 #else /* PRISM2_NO_STATION_MODES */
712 struct hostap_interface *iface;
715 iface = netdev_priv(dev);
716 local = iface->local;
718 memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN);
720 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) {
721 struct hfa384x_scan_request scan_req;
722 memset(&scan_req, 0, sizeof(scan_req));
723 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
724 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
725 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST,
726 &scan_req, sizeof(scan_req))) {
727 printk(KERN_DEBUG "%s: ScanResults request failed - "
728 "preferred AP delayed to next unsolicited "
729 "scan\n", dev->name);
731 } else if (local->host_roaming == 2 &&
732 local->iw_mode == IW_MODE_INFRA) {
733 if (hostap_join_ap(dev))
736 printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only "
737 "in Managed mode when host_roaming is enabled\n",
742 #endif /* PRISM2_NO_STATION_MODES */
745 static int prism2_ioctl_giwap(struct net_device *dev,
746 struct iw_request_info *info,
747 struct sockaddr *ap_addr, char *extra)
749 struct hostap_interface *iface;
752 iface = netdev_priv(dev);
753 local = iface->local;
755 ap_addr->sa_family = ARPHRD_ETHER;
756 switch (iface->type) {
757 case HOSTAP_INTERFACE_AP:
758 memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN);
760 case HOSTAP_INTERFACE_STA:
761 memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN);
763 case HOSTAP_INTERFACE_WDS:
764 memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN);
767 if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID,
768 &ap_addr->sa_data, ETH_ALEN, 1) < 0)
771 /* local->bssid is also updated in LinkStatus handler when in
773 memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN);
781 static int prism2_ioctl_siwnickn(struct net_device *dev,
782 struct iw_request_info *info,
783 struct iw_point *data, char *nickname)
785 struct hostap_interface *iface;
788 iface = netdev_priv(dev);
789 local = iface->local;
791 memset(local->name, 0, sizeof(local->name));
792 memcpy(local->name, nickname, data->length);
795 if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) ||
796 local->func->reset_port(dev))
802 static int prism2_ioctl_giwnickn(struct net_device *dev,
803 struct iw_request_info *info,
804 struct iw_point *data, char *nickname)
806 struct hostap_interface *iface;
809 char name[MAX_NAME_LEN + 3];
812 iface = netdev_priv(dev);
813 local = iface->local;
815 len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME,
816 &name, MAX_NAME_LEN + 2, 0);
817 val = __le16_to_cpu(*(u16 *) name);
818 if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN)
821 name[val + 2] = '\0';
822 data->length = val + 1;
823 memcpy(nickname, name + 2, val + 1);
829 static int prism2_ioctl_siwfreq(struct net_device *dev,
830 struct iw_request_info *info,
831 struct iw_freq *freq, char *extra)
833 struct hostap_interface *iface;
836 iface = netdev_priv(dev);
837 local = iface->local;
841 freq->m / 100000 >= freq_list[0] &&
842 freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) {
844 int fr = freq->m / 100000;
845 for (ch = 0; ch < FREQ_COUNT; ch++) {
846 if (fr == freq_list[ch]) {
854 if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT ||
855 !(local->channel_mask & (1 << (freq->m - 1))))
858 local->channel = freq->m; /* channel is used in prism2_setup_rids() */
859 if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) ||
860 local->func->reset_port(dev))
866 static int prism2_ioctl_giwfreq(struct net_device *dev,
867 struct iw_request_info *info,
868 struct iw_freq *freq, char *extra)
870 struct hostap_interface *iface;
874 iface = netdev_priv(dev);
875 local = iface->local;
877 if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) <
882 if (val < 1 || val > FREQ_COUNT)
885 freq->m = freq_list[val - 1] * 100000;
892 static void hostap_monitor_set_type(local_info_t *local)
894 struct net_device *dev = local->ddev;
899 if (local->monitor_type == PRISM2_MONITOR_PRISM ||
900 local->monitor_type == PRISM2_MONITOR_CAPHDR) {
901 dev->type = ARPHRD_IEEE80211_PRISM;
902 dev->hard_header_parse =
903 hostap_80211_prism_header_parse;
905 dev->type = ARPHRD_IEEE80211;
906 dev->hard_header_parse = hostap_80211_header_parse;
911 static int prism2_ioctl_siwessid(struct net_device *dev,
912 struct iw_request_info *info,
913 struct iw_point *data, char *ssid)
915 struct hostap_interface *iface;
918 iface = netdev_priv(dev);
919 local = iface->local;
921 if (iface->type == HOSTAP_INTERFACE_WDS)
924 if (data->flags == 0)
925 ssid[0] = '\0'; /* ANY */
927 if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') {
928 /* Setting SSID to empty string seems to kill the card in
930 printk(KERN_DEBUG "%s: Host AP mode does not support "
931 "'Any' essid\n", dev->name);
935 memcpy(local->essid, ssid, data->length);
936 local->essid[data->length] = '\0';
938 if ((!local->fw_ap &&
939 hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid))
940 || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) ||
941 local->func->reset_port(dev))
947 static int prism2_ioctl_giwessid(struct net_device *dev,
948 struct iw_request_info *info,
949 struct iw_point *data, char *essid)
951 struct hostap_interface *iface;
955 iface = netdev_priv(dev);
956 local = iface->local;
958 if (iface->type == HOSTAP_INTERFACE_WDS)
961 data->flags = 1; /* active */
962 if (local->iw_mode == IW_MODE_MASTER) {
963 data->length = strlen(local->essid);
964 memcpy(essid, local->essid, IW_ESSID_MAX_SIZE);
967 char ssid[MAX_SSID_LEN + 2];
968 memset(ssid, 0, sizeof(ssid));
969 len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID,
970 &ssid, MAX_SSID_LEN + 2, 0);
971 val = __le16_to_cpu(*(u16 *) ssid);
972 if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) {
976 memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE);
983 static int prism2_ioctl_giwrange(struct net_device *dev,
984 struct iw_request_info *info,
985 struct iw_point *data, char *extra)
987 struct hostap_interface *iface;
989 struct iw_range *range = (struct iw_range *) extra;
994 iface = netdev_priv(dev);
995 local = iface->local;
997 data->length = sizeof(struct iw_range);
998 memset(range, 0, sizeof(struct iw_range));
1000 /* TODO: could fill num_txpower and txpower array with
1001 * something; however, there are 128 different values.. */
1003 range->txpower_capa = IW_TXPOW_DBM;
1005 if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC)
1007 range->min_pmp = 1 * 1024;
1008 range->max_pmp = 65535 * 1024;
1009 range->min_pmt = 1 * 1024;
1010 range->max_pmt = 1000 * 1024;
1011 range->pmp_flags = IW_POWER_PERIOD;
1012 range->pmt_flags = IW_POWER_TIMEOUT;
1013 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
1014 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
1017 range->we_version_compiled = WIRELESS_EXT;
1018 range->we_version_source = 18;
1020 range->retry_capa = IW_RETRY_LIMIT;
1021 range->retry_flags = IW_RETRY_LIMIT;
1022 range->min_retry = 0;
1023 range->max_retry = 255;
1025 range->num_channels = FREQ_COUNT;
1028 for (i = 0; i < FREQ_COUNT; i++) {
1029 if (local->channel_mask & (1 << i)) {
1030 range->freq[val].i = i + 1;
1031 range->freq[val].m = freq_list[i] * 100000;
1032 range->freq[val].e = 1;
1035 if (val == IW_MAX_FREQUENCIES)
1038 range->num_frequency = val;
1040 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1041 range->max_qual.qual = 70; /* what is correct max? This was not
1042 * documented exactly. At least
1043 * 69 has been observed. */
1044 range->max_qual.level = 0; /* dB */
1045 range->max_qual.noise = 0; /* dB */
1047 /* What would be suitable values for "average/typical" qual? */
1048 range->avg_qual.qual = 20;
1049 range->avg_qual.level = -60;
1050 range->avg_qual.noise = -95;
1052 range->max_qual.qual = 92; /* 0 .. 92 */
1053 range->max_qual.level = 154; /* 27 .. 154 */
1054 range->max_qual.noise = 154; /* 27 .. 154 */
1056 range->sensitivity = 3;
1058 range->max_encoding_tokens = WEP_KEYS;
1059 range->num_encoding_sizes = 2;
1060 range->encoding_size[0] = 5;
1061 range->encoding_size[1] = 13;
1064 len = prism2_get_datarates(dev, rates);
1065 range->num_bitrates = 0;
1066 for (i = 0; i < len; i++) {
1067 if (range->num_bitrates < IW_MAX_BITRATES) {
1068 range->bitrate[range->num_bitrates] =
1070 range->num_bitrates++;
1072 if (rates[i] == 0x0b || rates[i] == 0x16)
1075 /* estimated maximum TCP throughput values (bps) */
1076 range->throughput = over2 ? 5500000 : 1500000;
1079 range->max_rts = 2347;
1080 range->min_frag = 256;
1081 range->max_frag = 2346;
1083 /* Event capability (kernel + driver) */
1084 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1085 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
1086 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1087 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1088 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1089 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
1090 IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1091 IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
1092 IW_EVENT_CAPA_MASK(IWEVEXPIRED));
1094 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1095 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1101 static int hostap_monitor_mode_enable(local_info_t *local)
1103 struct net_device *dev = local->dev;
1105 printk(KERN_DEBUG "Enabling monitor mode\n");
1106 hostap_monitor_set_type(local);
1108 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1109 HFA384X_PORTTYPE_PSEUDO_IBSS)) {
1110 printk(KERN_DEBUG "Port type setting for monitor mode "
1115 /* Host decrypt is needed to get the IV and ICV fields;
1116 * however, monitor mode seems to remove WEP flag from frame
1118 if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS,
1119 HFA384X_WEPFLAGS_HOSTENCRYPT |
1120 HFA384X_WEPFLAGS_HOSTDECRYPT)) {
1121 printk(KERN_DEBUG "WEP flags setting failed\n");
1125 if (local->func->reset_port(dev) ||
1126 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1127 (HFA384X_TEST_MONITOR << 8),
1129 printk(KERN_DEBUG "Setting monitor mode failed\n");
1137 static int hostap_monitor_mode_disable(local_info_t *local)
1139 struct net_device *dev = local->ddev;
1144 printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name);
1145 dev->type = ARPHRD_ETHER;
1146 dev->hard_header_parse = local->saved_eth_header_parse;
1147 if (local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1148 (HFA384X_TEST_STOP << 8),
1151 return hostap_set_encryption(local);
1155 static int prism2_ioctl_siwmode(struct net_device *dev,
1156 struct iw_request_info *info,
1157 __u32 *mode, char *extra)
1159 struct hostap_interface *iface;
1160 local_info_t *local;
1161 int double_reset = 0;
1163 iface = netdev_priv(dev);
1164 local = iface->local;
1166 if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA &&
1167 *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT &&
1168 *mode != IW_MODE_MONITOR)
1171 #ifdef PRISM2_NO_STATION_MODES
1172 if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA)
1174 #endif /* PRISM2_NO_STATION_MODES */
1176 if (*mode == local->iw_mode)
1179 if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') {
1180 printk(KERN_WARNING "%s: empty SSID not allowed in Master "
1181 "mode\n", dev->name);
1185 if (local->iw_mode == IW_MODE_MONITOR)
1186 hostap_monitor_mode_disable(local);
1188 if ((local->iw_mode == IW_MODE_ADHOC ||
1189 local->iw_mode == IW_MODE_MONITOR) && *mode == IW_MODE_MASTER) {
1190 /* There seems to be a firmware bug in at least STA f/w v1.5.6
1191 * that leaves beacon frames to use IBSS type when moving from
1192 * IBSS to Host AP mode. Doing double Port0 reset seems to be
1193 * enough to workaround this. */
1197 printk(KERN_DEBUG "prism2: %s: operating mode changed "
1198 "%d -> %d\n", dev->name, local->iw_mode, *mode);
1199 local->iw_mode = *mode;
1201 if (local->iw_mode == IW_MODE_MONITOR)
1202 hostap_monitor_mode_enable(local);
1203 else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
1204 !local->fw_encrypt_ok) {
1205 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
1206 "a workaround for firmware bug in Host AP mode WEP\n",
1208 local->host_encrypt = 1;
1211 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1212 hostap_get_porttype(local)))
1215 if (local->func->reset_port(dev))
1217 if (double_reset && local->func->reset_port(dev))
1220 if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
1222 /* netif_carrier is used only in client modes for now, so make
1223 * sure carrier is on when moving to non-client modes. */
1224 netif_carrier_on(local->dev);
1225 netif_carrier_on(local->ddev);
1231 static int prism2_ioctl_giwmode(struct net_device *dev,
1232 struct iw_request_info *info,
1233 __u32 *mode, char *extra)
1235 struct hostap_interface *iface;
1236 local_info_t *local;
1238 iface = netdev_priv(dev);
1239 local = iface->local;
1241 switch (iface->type) {
1242 case HOSTAP_INTERFACE_STA:
1243 *mode = IW_MODE_INFRA;
1245 case HOSTAP_INTERFACE_WDS:
1246 *mode = IW_MODE_REPEAT;
1249 *mode = local->iw_mode;
1256 static int prism2_ioctl_siwpower(struct net_device *dev,
1257 struct iw_request_info *info,
1258 struct iw_param *wrq, char *extra)
1260 #ifdef PRISM2_NO_STATION_MODES
1262 #else /* PRISM2_NO_STATION_MODES */
1266 return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
1268 switch (wrq->flags & IW_POWER_MODE) {
1269 case IW_POWER_UNICAST_R:
1270 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
1273 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1277 case IW_POWER_ALL_R:
1278 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
1281 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1291 if (wrq->flags & IW_POWER_TIMEOUT) {
1292 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1295 ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
1300 if (wrq->flags & IW_POWER_PERIOD) {
1301 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1304 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1311 #endif /* PRISM2_NO_STATION_MODES */
1315 static int prism2_ioctl_giwpower(struct net_device *dev,
1316 struct iw_request_info *info,
1317 struct iw_param *rrq, char *extra)
1319 #ifdef PRISM2_NO_STATION_MODES
1321 #else /* PRISM2_NO_STATION_MODES */
1322 struct hostap_interface *iface;
1323 local_info_t *local;
1326 iface = netdev_priv(dev);
1327 local = iface->local;
1329 if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
1333 if (!__le16_to_cpu(enable)) {
1340 if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1342 if (local->func->get_rid(dev,
1343 HFA384X_RID_CNFPMHOLDOVERDURATION,
1344 &timeout, 2, 1) < 0)
1347 rrq->flags = IW_POWER_TIMEOUT;
1348 rrq->value = __le16_to_cpu(timeout) * 1024;
1351 if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1355 rrq->flags = IW_POWER_PERIOD;
1356 rrq->value = __le16_to_cpu(period) * 1024;
1359 if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
1363 if (__le16_to_cpu(mcast))
1364 rrq->flags |= IW_POWER_ALL_R;
1366 rrq->flags |= IW_POWER_UNICAST_R;
1369 #endif /* PRISM2_NO_STATION_MODES */
1373 static int prism2_ioctl_siwretry(struct net_device *dev,
1374 struct iw_request_info *info,
1375 struct iw_param *rrq, char *extra)
1377 struct hostap_interface *iface;
1378 local_info_t *local;
1380 iface = netdev_priv(dev);
1381 local = iface->local;
1386 /* setting retry limits is not supported with the current station
1387 * firmware code; simulate this with alternative retry count for now */
1388 if (rrq->flags == IW_RETRY_LIMIT) {
1389 if (rrq->value < 0) {
1390 /* disable manual retry count setting and use firmware
1392 local->manual_retry_count = -1;
1393 local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
1395 if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1397 printk(KERN_DEBUG "%s: Alternate retry count "
1398 "setting to %d failed\n",
1399 dev->name, rrq->value);
1403 local->manual_retry_count = rrq->value;
1404 local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
1412 /* what could be done, if firmware would support this.. */
1414 if (rrq->flags & IW_RETRY_LIMIT) {
1415 if (rrq->flags & IW_RETRY_MAX)
1416 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1417 else if (rrq->flags & IW_RETRY_MIN)
1418 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1420 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1421 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1426 if (rrq->flags & IW_RETRY_LIFETIME) {
1427 HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
1434 static int prism2_ioctl_giwretry(struct net_device *dev,
1435 struct iw_request_info *info,
1436 struct iw_param *rrq, char *extra)
1438 struct hostap_interface *iface;
1439 local_info_t *local;
1440 u16 shortretry, longretry, lifetime, altretry;
1442 iface = netdev_priv(dev);
1443 local = iface->local;
1445 if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
1447 local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
1449 local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
1450 &lifetime, 2, 1) < 0)
1453 le16_to_cpus(&shortretry);
1454 le16_to_cpus(&longretry);
1455 le16_to_cpus(&lifetime);
1459 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1460 rrq->flags = IW_RETRY_LIFETIME;
1461 rrq->value = lifetime * 1024;
1463 if (local->manual_retry_count >= 0) {
1464 rrq->flags = IW_RETRY_LIMIT;
1465 if (local->func->get_rid(dev,
1466 HFA384X_RID_CNFALTRETRYCOUNT,
1467 &altretry, 2, 1) >= 0)
1468 rrq->value = le16_to_cpu(altretry);
1470 rrq->value = local->manual_retry_count;
1471 } else if ((rrq->flags & IW_RETRY_MAX)) {
1472 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1473 rrq->value = longretry;
1475 rrq->flags = IW_RETRY_LIMIT;
1476 rrq->value = shortretry;
1477 if (shortretry != longretry)
1478 rrq->flags |= IW_RETRY_MIN;
1485 /* Note! This TX power controlling is experimental and should not be used in
1486 * production use. It just sets raw power register and does not use any kind of
1487 * feedback information from the measured TX power (CR58). This is now
1488 * commented out to make sure that it is not used by accident. TX power
1489 * configuration will be enabled again after proper algorithm using feedback
1490 * has been implemented. */
1492 #ifdef RAW_TXPOWER_SETTING
1493 /* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
1494 * This version assumes following mapping:
1495 * CR31 is 7-bit value with -64 to +63 range.
1496 * -64 is mapped into +20dBm and +63 into -43dBm.
1497 * This is certainly not an exact mapping for every card, but at least
1498 * increasing dBm value should correspond to increasing TX power.
1501 static int prism2_txpower_hfa386x_to_dBm(u16 val)
1514 static u16 prism2_txpower_dBm_to_hfa386x(int val)
1527 return (unsigned char) tmp;
1529 #endif /* RAW_TXPOWER_SETTING */
1532 static int prism2_ioctl_siwtxpow(struct net_device *dev,
1533 struct iw_request_info *info,
1534 struct iw_param *rrq, char *extra)
1536 struct hostap_interface *iface;
1537 local_info_t *local;
1538 #ifdef RAW_TXPOWER_SETTING
1544 iface = netdev_priv(dev);
1545 local = iface->local;
1547 if (rrq->disabled) {
1548 if (local->txpower_type != PRISM2_TXPOWER_OFF) {
1549 val = 0xff; /* use all standby and sleep modes */
1550 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1551 HFA386X_CR_A_D_TEST_MODES2,
1553 printk(KERN_DEBUG "%s: Turning radio off: %s\n",
1554 dev->name, ret ? "failed" : "OK");
1555 local->txpower_type = PRISM2_TXPOWER_OFF;
1557 return (ret ? -EOPNOTSUPP : 0);
1560 if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1561 val = 0; /* disable all standby and sleep modes */
1562 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1563 HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
1564 printk(KERN_DEBUG "%s: Turning radio on: %s\n",
1565 dev->name, ret ? "failed" : "OK");
1566 local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
1569 #ifdef RAW_TXPOWER_SETTING
1570 if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
1571 printk(KERN_DEBUG "Setting ALC on\n");
1572 val = HFA384X_TEST_CFG_BIT_ALC;
1573 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1574 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
1575 local->txpower_type = PRISM2_TXPOWER_AUTO;
1579 if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
1580 printk(KERN_DEBUG "Setting ALC off\n");
1581 val = HFA384X_TEST_CFG_BIT_ALC;
1582 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1583 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
1584 local->txpower_type = PRISM2_TXPOWER_FIXED;
1587 if (rrq->flags == IW_TXPOW_DBM)
1589 else if (rrq->flags == IW_TXPOW_MWATT)
1593 printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
1595 if (rrq->flags != IW_TXPOW_DBM) {
1596 printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
1600 local->txpower = rrq->value;
1601 val = prism2_txpower_dBm_to_hfa386x(local->txpower);
1602 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1603 HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
1605 #else /* RAW_TXPOWER_SETTING */
1608 #endif /* RAW_TXPOWER_SETTING */
1613 static int prism2_ioctl_giwtxpow(struct net_device *dev,
1614 struct iw_request_info *info,
1615 struct iw_param *rrq, char *extra)
1617 #ifdef RAW_TXPOWER_SETTING
1618 struct hostap_interface *iface;
1619 local_info_t *local;
1622 iface = netdev_priv(dev);
1623 local = iface->local;
1625 rrq->flags = IW_TXPOW_DBM;
1629 if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
1630 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
1631 HFA386X_CR_MANUAL_TX_POWER,
1632 NULL, &resp0) == 0) {
1633 rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
1635 /* Could not get real txpower; guess 15 dBm */
1638 } else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1641 } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
1642 rrq->value = local->txpower;
1645 printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
1646 local->txpower_type);
1649 #else /* RAW_TXPOWER_SETTING */
1651 #endif /* RAW_TXPOWER_SETTING */
1655 #ifndef PRISM2_NO_STATION_MODES
1657 /* HostScan request works with and without host_roaming mode. In addition, it
1658 * does not break current association. However, it requires newer station
1659 * firmware version (>= 1.3.1) than scan request. */
1660 static int prism2_request_hostscan(struct net_device *dev,
1661 u8 *ssid, u8 ssid_len)
1663 struct hostap_interface *iface;
1664 local_info_t *local;
1665 struct hfa384x_hostscan_request scan_req;
1667 iface = netdev_priv(dev);
1668 local = iface->local;
1670 memset(&scan_req, 0, sizeof(scan_req));
1671 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1672 local->scan_channel_mask);
1673 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1677 scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1678 memcpy(scan_req.target_ssid, ssid, ssid_len);
1681 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1682 sizeof(scan_req))) {
1683 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1690 static int prism2_request_scan(struct net_device *dev)
1692 struct hostap_interface *iface;
1693 local_info_t *local;
1694 struct hfa384x_scan_request scan_req;
1697 iface = netdev_priv(dev);
1698 local = iface->local;
1700 memset(&scan_req, 0, sizeof(scan_req));
1701 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1702 local->scan_channel_mask);
1703 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1706 * It seems to be enough to set roaming mode for a short moment to
1707 * host-based and then setup scanrequest data and return the mode to
1710 * Master mode would need to drop to Managed mode for a short while
1711 * to make scanning work.. Or sweep through the different channels and
1712 * use passive scan based on beacons. */
1714 if (!local->host_roaming)
1715 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1716 HFA384X_ROAMING_HOST);
1718 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1719 sizeof(scan_req))) {
1720 printk(KERN_DEBUG "SCANREQUEST failed\n");
1724 if (!local->host_roaming)
1725 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1726 HFA384X_ROAMING_FIRMWARE);
1731 #else /* !PRISM2_NO_STATION_MODES */
1733 static inline int prism2_request_hostscan(struct net_device *dev,
1734 u8 *ssid, u8 ssid_len)
1740 static inline int prism2_request_scan(struct net_device *dev)
1745 #endif /* !PRISM2_NO_STATION_MODES */
1748 static int prism2_ioctl_siwscan(struct net_device *dev,
1749 struct iw_request_info *info,
1750 struct iw_point *data, char *extra)
1752 struct hostap_interface *iface;
1753 local_info_t *local;
1755 u8 *ssid = NULL, ssid_len = 0;
1756 struct iw_scan_req *req = (struct iw_scan_req *) extra;
1758 iface = netdev_priv(dev);
1759 local = iface->local;
1761 if (data->length < sizeof(struct iw_scan_req))
1764 if (local->iw_mode == IW_MODE_MASTER) {
1765 /* In master mode, we just return the results of our local
1766 * tables, so we don't need to start anything...
1772 if (!local->dev_enabled)
1775 if (req && data->flags & IW_SCAN_THIS_ESSID) {
1777 ssid_len = req->essid_len;
1780 ((local->iw_mode != IW_MODE_INFRA &&
1781 local->iw_mode != IW_MODE_ADHOC) ||
1782 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1786 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1787 ret = prism2_request_hostscan(dev, ssid, ssid_len);
1789 ret = prism2_request_scan(dev);
1792 local->scan_timestamp = jiffies;
1794 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1800 #ifndef PRISM2_NO_STATION_MODES
1801 static char * __prism2_translate_scan(local_info_t *local,
1802 struct hfa384x_hostscan_result *scan,
1803 struct hostap_bss_info *bss,
1804 char *current_ev, char *end_buf)
1807 struct iw_event iwe;
1817 ssid_len = bss->ssid_len;
1821 ssid_len = le16_to_cpu(scan->ssid_len);
1822 bssid = scan->bssid;
1827 /* First entry *MUST* be the AP MAC address */
1828 memset(&iwe, 0, sizeof(iwe));
1829 iwe.cmd = SIOCGIWAP;
1830 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1831 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1832 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1835 /* Other entries will be displayed in the order we give them */
1837 memset(&iwe, 0, sizeof(iwe));
1838 iwe.cmd = SIOCGIWESSID;
1839 iwe.u.data.length = ssid_len;
1840 iwe.u.data.flags = 1;
1841 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid);
1843 memset(&iwe, 0, sizeof(iwe));
1844 iwe.cmd = SIOCGIWMODE;
1846 capabilities = bss->capab_info;
1848 capabilities = le16_to_cpu(scan->capability);
1850 if (capabilities & (WLAN_CAPABILITY_ESS |
1851 WLAN_CAPABILITY_IBSS)) {
1852 if (capabilities & WLAN_CAPABILITY_ESS)
1853 iwe.u.mode = IW_MODE_MASTER;
1855 iwe.u.mode = IW_MODE_ADHOC;
1856 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1860 memset(&iwe, 0, sizeof(iwe));
1861 iwe.cmd = SIOCGIWFREQ;
1863 chan = le16_to_cpu(scan->chid);
1871 iwe.u.freq.m = freq_list[chan - 1] * 100000;
1873 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1878 memset(&iwe, 0, sizeof(iwe));
1880 if (local->last_scan_type == PRISM2_HOSTSCAN) {
1881 iwe.u.qual.level = le16_to_cpu(scan->sl);
1882 iwe.u.qual.noise = le16_to_cpu(scan->anl);
1885 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1887 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1889 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
1890 | IW_QUAL_NOISE_UPDATED
1891 | IW_QUAL_QUAL_INVALID
1893 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1897 memset(&iwe, 0, sizeof(iwe));
1898 iwe.cmd = SIOCGIWENCODE;
1899 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1900 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1902 iwe.u.data.flags = IW_ENCODE_DISABLED;
1903 iwe.u.data.length = 0;
1904 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
1906 /* TODO: add SuppRates into BSS table */
1908 memset(&iwe, 0, sizeof(iwe));
1909 iwe.cmd = SIOCGIWRATE;
1910 current_val = current_ev + IW_EV_LCP_LEN;
1911 pos = scan->sup_rates;
1912 for (i = 0; i < sizeof(scan->sup_rates); i++) {
1915 /* Bit rate given in 500 kb/s units (+ 0x80) */
1916 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1917 current_val = iwe_stream_add_value(
1918 current_ev, current_val, end_buf, &iwe,
1921 /* Check if we added any event */
1922 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1923 current_ev = current_val;
1926 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1927 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_ATOMIC);
1929 memset(&iwe, 0, sizeof(iwe));
1930 iwe.cmd = IWEVCUSTOM;
1931 sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval));
1932 iwe.u.data.length = strlen(buf);
1933 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1936 memset(&iwe, 0, sizeof(iwe));
1937 iwe.cmd = IWEVCUSTOM;
1938 sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate));
1939 iwe.u.data.length = strlen(buf);
1940 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1943 if (local->last_scan_type == PRISM2_HOSTSCAN &&
1944 (capabilities & WLAN_CAPABILITY_IBSS)) {
1945 memset(&iwe, 0, sizeof(iwe));
1946 iwe.cmd = IWEVCUSTOM;
1947 sprintf(buf, "atim=%d", le16_to_cpu(scan->atim));
1948 iwe.u.data.length = strlen(buf);
1949 current_ev = iwe_stream_add_point(current_ev, end_buf,
1955 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1956 memset(&iwe, 0, sizeof(iwe));
1957 iwe.cmd = IWEVGENIE;
1958 iwe.u.data.length = bss->wpa_ie_len;
1959 current_ev = iwe_stream_add_point(
1960 current_ev, end_buf, &iwe, bss->wpa_ie);
1963 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1964 memset(&iwe, 0, sizeof(iwe));
1965 iwe.cmd = IWEVGENIE;
1966 iwe.u.data.length = bss->rsn_ie_len;
1967 current_ev = iwe_stream_add_point(
1968 current_ev, end_buf, &iwe, bss->rsn_ie);
1975 /* Translate scan data returned from the card to a card independant
1976 * format that the Wireless Tools will understand - Jean II */
1977 static inline int prism2_translate_scan(local_info_t *local,
1978 char *buffer, int buflen)
1980 struct hfa384x_hostscan_result *scan;
1981 int entry, hostscan;
1982 char *current_ev = buffer;
1983 char *end_buf = buffer + buflen;
1984 struct list_head *ptr;
1986 spin_lock_bh(&local->lock);
1988 list_for_each(ptr, &local->bss_list) {
1989 struct hostap_bss_info *bss;
1990 bss = list_entry(ptr, struct hostap_bss_info, list);
1994 hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
1995 for (entry = 0; entry < local->last_scan_results_count; entry++) {
1997 scan = &local->last_scan_results[entry];
1999 /* Report every SSID if the AP is using multiple SSIDs. If no
2000 * BSS record is found (e.g., when WPA mode is disabled),
2001 * report the AP once. */
2002 list_for_each(ptr, &local->bss_list) {
2003 struct hostap_bss_info *bss;
2004 bss = list_entry(ptr, struct hostap_bss_info, list);
2005 if (memcmp(bss->bssid, scan->bssid, ETH_ALEN) == 0) {
2007 current_ev = __prism2_translate_scan(
2008 local, scan, bss, current_ev, end_buf);
2013 current_ev = __prism2_translate_scan(
2014 local, scan, NULL, current_ev, end_buf);
2016 /* Check if there is space for one more entry */
2017 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2018 /* Ask user space to try again with a bigger buffer */
2019 spin_unlock_bh(&local->lock);
2024 /* Prism2 firmware has limits (32 at least in some versions) for number
2025 * of BSSes in scan results. Extend this limit by using local BSS list.
2027 list_for_each(ptr, &local->bss_list) {
2028 struct hostap_bss_info *bss;
2029 bss = list_entry(ptr, struct hostap_bss_info, list);
2032 current_ev = __prism2_translate_scan(local, NULL, bss,
2033 current_ev, end_buf);
2034 /* Check if there is space for one more entry */
2035 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2036 /* Ask user space to try again with a bigger buffer */
2037 spin_unlock_bh(&local->lock);
2042 spin_unlock_bh(&local->lock);
2044 return current_ev - buffer;
2046 #endif /* PRISM2_NO_STATION_MODES */
2049 static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2050 struct iw_request_info *info,
2051 struct iw_point *data, char *extra)
2053 #ifdef PRISM2_NO_STATION_MODES
2055 #else /* PRISM2_NO_STATION_MODES */
2056 struct hostap_interface *iface;
2057 local_info_t *local;
2060 iface = netdev_priv(dev);
2061 local = iface->local;
2063 /* Wait until the scan is finished. We can probably do better
2064 * than that - Jean II */
2065 if (local->scan_timestamp &&
2066 time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2067 /* Important note : we don't want to block the caller
2068 * until results are ready for various reasons.
2069 * First, managing wait queues is complex and racy
2070 * (there may be multiple simultaneous callers).
2071 * Second, we grab some rtnetlink lock before comming
2072 * here (in dev_ioctl()).
2073 * Third, the caller can wait on the Wireless Event
2077 local->scan_timestamp = 0;
2079 res = prism2_translate_scan(local, extra, data->length);
2088 #endif /* PRISM2_NO_STATION_MODES */
2092 static int prism2_ioctl_giwscan(struct net_device *dev,
2093 struct iw_request_info *info,
2094 struct iw_point *data, char *extra)
2096 struct hostap_interface *iface;
2097 local_info_t *local;
2100 iface = netdev_priv(dev);
2101 local = iface->local;
2103 if (local->iw_mode == IW_MODE_MASTER) {
2104 /* In MASTER mode, it doesn't make sense to go around
2105 * scanning the frequencies and make the stations we serve
2106 * wait when what the user is really interested about is the
2107 * list of stations and access points we are talking to.
2108 * So, just extract results from our cache...
2111 /* Translate to WE format */
2112 res = prism2_ap_translate_scan(dev, extra);
2114 printk(KERN_DEBUG "Scan result translation succeeded "
2115 "(length=%d)\n", res);
2120 "Scan result translation failed (res=%d)\n",
2127 return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2132 static const struct iw_priv_args prism2_priv[] = {
2133 { PRISM2_IOCTL_MONITOR,
2134 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2135 { PRISM2_IOCTL_READMIF,
2136 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2137 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2138 { PRISM2_IOCTL_WRITEMIF,
2139 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2140 { PRISM2_IOCTL_RESET,
2141 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2142 { PRISM2_IOCTL_INQUIRE,
2143 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2144 { PRISM2_IOCTL_SET_RID_WORD,
2145 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2146 { PRISM2_IOCTL_MACCMD,
2147 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2148 { PRISM2_IOCTL_WDS_ADD,
2149 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2150 { PRISM2_IOCTL_WDS_DEL,
2151 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2152 { PRISM2_IOCTL_ADDMAC,
2153 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2154 { PRISM2_IOCTL_DELMAC,
2155 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2156 { PRISM2_IOCTL_KICKMAC,
2157 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2158 /* --- raw access to sub-ioctls --- */
2159 { PRISM2_IOCTL_PRISM2_PARAM,
2160 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2161 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2162 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2163 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2164 /* --- sub-ioctls handlers --- */
2165 { PRISM2_IOCTL_PRISM2_PARAM,
2166 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2167 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2168 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2169 /* --- sub-ioctls definitions --- */
2170 { PRISM2_PARAM_TXRATECTRL,
2171 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2172 { PRISM2_PARAM_TXRATECTRL,
2173 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2174 { PRISM2_PARAM_BEACON_INT,
2175 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2176 { PRISM2_PARAM_BEACON_INT,
2177 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2178 #ifndef PRISM2_NO_STATION_MODES
2179 { PRISM2_PARAM_PSEUDO_IBSS,
2180 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2181 { PRISM2_PARAM_PSEUDO_IBSS,
2182 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2183 #endif /* PRISM2_NO_STATION_MODES */
2185 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2187 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2188 { PRISM2_PARAM_DUMP,
2189 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2190 { PRISM2_PARAM_DUMP,
2191 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2192 { PRISM2_PARAM_OTHER_AP_POLICY,
2193 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2194 { PRISM2_PARAM_OTHER_AP_POLICY,
2195 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2196 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2197 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2198 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2199 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2200 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2201 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2202 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2203 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2204 { PRISM2_PARAM_DTIM_PERIOD,
2205 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2206 { PRISM2_PARAM_DTIM_PERIOD,
2207 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2208 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2209 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2210 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2211 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2212 { PRISM2_PARAM_MAX_WDS,
2213 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2214 { PRISM2_PARAM_MAX_WDS,
2215 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2216 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2217 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2218 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2219 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2220 { PRISM2_PARAM_AP_AUTH_ALGS,
2221 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2222 { PRISM2_PARAM_AP_AUTH_ALGS,
2223 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2224 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2225 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2226 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2227 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2228 { PRISM2_PARAM_HOST_ENCRYPT,
2229 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2230 { PRISM2_PARAM_HOST_ENCRYPT,
2231 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2232 { PRISM2_PARAM_HOST_DECRYPT,
2233 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2234 { PRISM2_PARAM_HOST_DECRYPT,
2235 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2236 #ifndef PRISM2_NO_STATION_MODES
2237 { PRISM2_PARAM_HOST_ROAMING,
2238 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2239 { PRISM2_PARAM_HOST_ROAMING,
2240 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2241 #endif /* PRISM2_NO_STATION_MODES */
2242 { PRISM2_PARAM_BCRX_STA_KEY,
2243 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2244 { PRISM2_PARAM_BCRX_STA_KEY,
2245 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2246 { PRISM2_PARAM_IEEE_802_1X,
2247 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2248 { PRISM2_PARAM_IEEE_802_1X,
2249 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2250 { PRISM2_PARAM_ANTSEL_TX,
2251 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2252 { PRISM2_PARAM_ANTSEL_TX,
2253 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2254 { PRISM2_PARAM_ANTSEL_RX,
2255 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2256 { PRISM2_PARAM_ANTSEL_RX,
2257 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2258 { PRISM2_PARAM_MONITOR_TYPE,
2259 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2260 { PRISM2_PARAM_MONITOR_TYPE,
2261 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2262 { PRISM2_PARAM_WDS_TYPE,
2263 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2264 { PRISM2_PARAM_WDS_TYPE,
2265 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2266 { PRISM2_PARAM_HOSTSCAN,
2267 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2268 { PRISM2_PARAM_HOSTSCAN,
2269 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2270 { PRISM2_PARAM_AP_SCAN,
2271 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2272 { PRISM2_PARAM_AP_SCAN,
2273 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2274 { PRISM2_PARAM_ENH_SEC,
2275 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2276 { PRISM2_PARAM_ENH_SEC,
2277 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2278 #ifdef PRISM2_IO_DEBUG
2279 { PRISM2_PARAM_IO_DEBUG,
2280 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2281 { PRISM2_PARAM_IO_DEBUG,
2282 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2283 #endif /* PRISM2_IO_DEBUG */
2284 { PRISM2_PARAM_BASIC_RATES,
2285 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2286 { PRISM2_PARAM_BASIC_RATES,
2287 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2288 { PRISM2_PARAM_OPER_RATES,
2289 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2290 { PRISM2_PARAM_OPER_RATES,
2291 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2292 { PRISM2_PARAM_HOSTAPD,
2293 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2294 { PRISM2_PARAM_HOSTAPD,
2295 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2296 { PRISM2_PARAM_HOSTAPD_STA,
2297 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2298 { PRISM2_PARAM_HOSTAPD_STA,
2299 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2301 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2303 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2304 { PRISM2_PARAM_PRIVACY_INVOKED,
2305 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2306 { PRISM2_PARAM_PRIVACY_INVOKED,
2307 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2308 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2309 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2310 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2311 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2312 { PRISM2_PARAM_DROP_UNENCRYPTED,
2313 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2314 { PRISM2_PARAM_DROP_UNENCRYPTED,
2315 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
2316 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2317 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
2318 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2319 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
2323 static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2325 struct hostap_interface *iface;
2326 local_info_t *local;
2328 iface = netdev_priv(dev);
2329 local = iface->local;
2331 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2338 static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2339 struct iw_request_info *info,
2340 void *wrqu, char *extra)
2342 struct hostap_interface *iface;
2343 local_info_t *local;
2344 int *i = (int *) extra;
2346 int value = *(i + 1);
2350 iface = netdev_priv(dev);
2351 local = iface->local;
2354 case PRISM2_PARAM_TXRATECTRL:
2355 local->fw_tx_rate_control = value;
2358 case PRISM2_PARAM_BEACON_INT:
2359 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2360 local->func->reset_port(dev))
2363 local->beacon_int = value;
2366 #ifndef PRISM2_NO_STATION_MODES
2367 case PRISM2_PARAM_PSEUDO_IBSS:
2368 if (value == local->pseudo_adhoc)
2371 if (value != 0 && value != 1) {
2376 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2377 dev->name, local->pseudo_adhoc, value);
2378 local->pseudo_adhoc = value;
2379 if (local->iw_mode != IW_MODE_ADHOC)
2382 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2383 hostap_get_porttype(local))) {
2388 if (local->func->reset_port(dev))
2391 #endif /* PRISM2_NO_STATION_MODES */
2393 case PRISM2_PARAM_ALC:
2394 printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2395 value == 0 ? "Disabling" : "Enabling");
2396 val = HFA384X_TEST_CFG_BIT_ALC;
2397 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2398 (HFA384X_TEST_CFG_BITS << 8),
2399 value == 0 ? 0 : 1, &val, NULL);
2402 case PRISM2_PARAM_DUMP:
2403 local->frame_dump = value;
2406 case PRISM2_PARAM_OTHER_AP_POLICY:
2407 if (value < 0 || value > 3) {
2411 if (local->ap != NULL)
2412 local->ap->ap_policy = value;
2415 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2416 if (value < 0 || value > 7 * 24 * 60 * 60) {
2420 if (local->ap != NULL)
2421 local->ap->max_inactivity = value * HZ;
2424 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2425 if (local->ap != NULL)
2426 local->ap->bridge_packets = value;
2429 case PRISM2_PARAM_DTIM_PERIOD:
2430 if (value < 0 || value > 65535) {
2434 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2435 || local->func->reset_port(dev))
2438 local->dtim_period = value;
2441 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2442 if (local->ap != NULL)
2443 local->ap->nullfunc_ack = value;
2446 case PRISM2_PARAM_MAX_WDS:
2447 local->wds_max_connections = value;
2450 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2451 if (local->ap != NULL) {
2452 if (!local->ap->autom_ap_wds && value) {
2453 /* add WDS link to all APs in STA table */
2454 hostap_add_wds_links(local);
2456 local->ap->autom_ap_wds = value;
2460 case PRISM2_PARAM_AP_AUTH_ALGS:
2461 local->auth_algs = value;
2462 if (hostap_set_auth_algs(local))
2466 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2467 local->monitor_allow_fcserr = value;
2470 case PRISM2_PARAM_HOST_ENCRYPT:
2471 local->host_encrypt = value;
2472 if (hostap_set_encryption(local) ||
2473 local->func->reset_port(dev))
2477 case PRISM2_PARAM_HOST_DECRYPT:
2478 local->host_decrypt = value;
2479 if (hostap_set_encryption(local) ||
2480 local->func->reset_port(dev))
2484 #ifndef PRISM2_NO_STATION_MODES
2485 case PRISM2_PARAM_HOST_ROAMING:
2486 if (value < 0 || value > 2) {
2490 local->host_roaming = value;
2491 if (hostap_set_roaming(local) || local->func->reset_port(dev))
2494 #endif /* PRISM2_NO_STATION_MODES */
2496 case PRISM2_PARAM_BCRX_STA_KEY:
2497 local->bcrx_sta_key = value;
2500 case PRISM2_PARAM_IEEE_802_1X:
2501 local->ieee_802_1x = value;
2504 case PRISM2_PARAM_ANTSEL_TX:
2505 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2509 local->antsel_tx = value;
2510 hostap_set_antsel(local);
2513 case PRISM2_PARAM_ANTSEL_RX:
2514 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2518 local->antsel_rx = value;
2519 hostap_set_antsel(local);
2522 case PRISM2_PARAM_MONITOR_TYPE:
2523 if (value != PRISM2_MONITOR_80211 &&
2524 value != PRISM2_MONITOR_CAPHDR &&
2525 value != PRISM2_MONITOR_PRISM) {
2529 local->monitor_type = value;
2530 if (local->iw_mode == IW_MODE_MONITOR)
2531 hostap_monitor_set_type(local);
2534 case PRISM2_PARAM_WDS_TYPE:
2535 local->wds_type = value;
2538 case PRISM2_PARAM_HOSTSCAN:
2540 struct hfa384x_hostscan_request scan_req;
2543 memset(&scan_req, 0, sizeof(scan_req));
2544 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
2546 case 1: rate = HFA384X_RATES_1MBPS; break;
2547 case 2: rate = HFA384X_RATES_2MBPS; break;
2548 case 3: rate = HFA384X_RATES_5MBPS; break;
2549 case 4: rate = HFA384X_RATES_11MBPS; break;
2550 default: rate = HFA384X_RATES_1MBPS; break;
2552 scan_req.txrate = cpu_to_le16(rate);
2553 /* leave SSID empty to accept all SSIDs */
2555 if (local->iw_mode == IW_MODE_MASTER) {
2556 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2557 HFA384X_PORTTYPE_BSS) ||
2558 local->func->reset_port(dev))
2559 printk(KERN_DEBUG "Leaving Host AP mode "
2560 "for HostScan failed\n");
2563 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2564 sizeof(scan_req))) {
2565 printk(KERN_DEBUG "HOSTSCAN failed\n");
2568 if (local->iw_mode == IW_MODE_MASTER) {
2569 wait_queue_t __wait;
2570 init_waitqueue_entry(&__wait, current);
2571 add_wait_queue(&local->hostscan_wq, &__wait);
2572 set_current_state(TASK_INTERRUPTIBLE);
2573 schedule_timeout(HZ);
2574 if (signal_pending(current))
2576 set_current_state(TASK_RUNNING);
2577 remove_wait_queue(&local->hostscan_wq, &__wait);
2579 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2580 HFA384X_PORTTYPE_HOSTAP) ||
2581 local->func->reset_port(dev))
2582 printk(KERN_DEBUG "Returning to Host AP mode "
2583 "after HostScan failed\n");
2588 case PRISM2_PARAM_AP_SCAN:
2589 local->passive_scan_interval = value;
2590 if (timer_pending(&local->passive_scan_timer))
2591 del_timer(&local->passive_scan_timer);
2593 local->passive_scan_timer.expires = jiffies +
2594 local->passive_scan_interval * HZ;
2595 add_timer(&local->passive_scan_timer);
2599 case PRISM2_PARAM_ENH_SEC:
2600 if (value < 0 || value > 3) {
2604 local->enh_sec = value;
2605 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2607 local->func->reset_port(dev)) {
2608 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2609 "1.6.3 or newer\n", dev->name);
2614 #ifdef PRISM2_IO_DEBUG
2615 case PRISM2_PARAM_IO_DEBUG:
2616 local->io_debug_enabled = value;
2618 #endif /* PRISM2_IO_DEBUG */
2620 case PRISM2_PARAM_BASIC_RATES:
2621 if ((value & local->tx_rate_control) != value || value == 0) {
2622 printk(KERN_INFO "%s: invalid basic rate set - basic "
2623 "rates must be in supported rate set\n",
2628 local->basic_rates = value;
2629 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2630 local->basic_rates) ||
2631 local->func->reset_port(dev))
2635 case PRISM2_PARAM_OPER_RATES:
2636 local->tx_rate_control = value;
2637 if (hostap_set_rate(dev))
2641 case PRISM2_PARAM_HOSTAPD:
2642 ret = hostap_set_hostapd(local, value, 1);
2645 case PRISM2_PARAM_HOSTAPD_STA:
2646 ret = hostap_set_hostapd_sta(local, value, 1);
2649 case PRISM2_PARAM_WPA:
2651 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2653 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2658 case PRISM2_PARAM_PRIVACY_INVOKED:
2659 local->privacy_invoked = value;
2660 if (hostap_set_encryption(local) ||
2661 local->func->reset_port(dev))
2665 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2666 local->tkip_countermeasures = value;
2669 case PRISM2_PARAM_DROP_UNENCRYPTED:
2670 local->drop_unencrypted = value;
2673 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2674 local->scan_channel_mask = value;
2678 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2688 static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2689 struct iw_request_info *info,
2690 void *wrqu, char *extra)
2692 struct hostap_interface *iface;
2693 local_info_t *local;
2694 int *param = (int *) extra;
2697 iface = netdev_priv(dev);
2698 local = iface->local;
2701 case PRISM2_PARAM_TXRATECTRL:
2702 *param = local->fw_tx_rate_control;
2705 case PRISM2_PARAM_BEACON_INT:
2706 *param = local->beacon_int;
2709 case PRISM2_PARAM_PSEUDO_IBSS:
2710 *param = local->pseudo_adhoc;
2713 case PRISM2_PARAM_ALC:
2714 ret = -EOPNOTSUPP; /* FIX */
2717 case PRISM2_PARAM_DUMP:
2718 *param = local->frame_dump;
2721 case PRISM2_PARAM_OTHER_AP_POLICY:
2722 if (local->ap != NULL)
2723 *param = local->ap->ap_policy;
2728 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2729 if (local->ap != NULL)
2730 *param = local->ap->max_inactivity / HZ;
2735 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2736 if (local->ap != NULL)
2737 *param = local->ap->bridge_packets;
2742 case PRISM2_PARAM_DTIM_PERIOD:
2743 *param = local->dtim_period;
2746 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2747 if (local->ap != NULL)
2748 *param = local->ap->nullfunc_ack;
2753 case PRISM2_PARAM_MAX_WDS:
2754 *param = local->wds_max_connections;
2757 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2758 if (local->ap != NULL)
2759 *param = local->ap->autom_ap_wds;
2764 case PRISM2_PARAM_AP_AUTH_ALGS:
2765 *param = local->auth_algs;
2768 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2769 *param = local->monitor_allow_fcserr;
2772 case PRISM2_PARAM_HOST_ENCRYPT:
2773 *param = local->host_encrypt;
2776 case PRISM2_PARAM_HOST_DECRYPT:
2777 *param = local->host_decrypt;
2780 case PRISM2_PARAM_HOST_ROAMING:
2781 *param = local->host_roaming;
2784 case PRISM2_PARAM_BCRX_STA_KEY:
2785 *param = local->bcrx_sta_key;
2788 case PRISM2_PARAM_IEEE_802_1X:
2789 *param = local->ieee_802_1x;
2792 case PRISM2_PARAM_ANTSEL_TX:
2793 *param = local->antsel_tx;
2796 case PRISM2_PARAM_ANTSEL_RX:
2797 *param = local->antsel_rx;
2800 case PRISM2_PARAM_MONITOR_TYPE:
2801 *param = local->monitor_type;
2804 case PRISM2_PARAM_WDS_TYPE:
2805 *param = local->wds_type;
2808 case PRISM2_PARAM_HOSTSCAN:
2812 case PRISM2_PARAM_AP_SCAN:
2813 *param = local->passive_scan_interval;
2816 case PRISM2_PARAM_ENH_SEC:
2817 *param = local->enh_sec;
2820 #ifdef PRISM2_IO_DEBUG
2821 case PRISM2_PARAM_IO_DEBUG:
2822 *param = local->io_debug_enabled;
2824 #endif /* PRISM2_IO_DEBUG */
2826 case PRISM2_PARAM_BASIC_RATES:
2827 *param = local->basic_rates;
2830 case PRISM2_PARAM_OPER_RATES:
2831 *param = local->tx_rate_control;
2834 case PRISM2_PARAM_HOSTAPD:
2835 *param = local->hostapd;
2838 case PRISM2_PARAM_HOSTAPD_STA:
2839 *param = local->hostapd_sta;
2842 case PRISM2_PARAM_WPA:
2843 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2845 *param = local->wpa;
2848 case PRISM2_PARAM_PRIVACY_INVOKED:
2849 *param = local->privacy_invoked;
2852 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2853 *param = local->tkip_countermeasures;
2856 case PRISM2_PARAM_DROP_UNENCRYPTED:
2857 *param = local->drop_unencrypted;
2860 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2861 *param = local->scan_channel_mask;
2865 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2875 static int prism2_ioctl_priv_readmif(struct net_device *dev,
2876 struct iw_request_info *info,
2877 void *wrqu, char *extra)
2879 struct hostap_interface *iface;
2880 local_info_t *local;
2883 iface = netdev_priv(dev);
2884 local = iface->local;
2886 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2896 static int prism2_ioctl_priv_writemif(struct net_device *dev,
2897 struct iw_request_info *info,
2898 void *wrqu, char *extra)
2900 struct hostap_interface *iface;
2901 local_info_t *local;
2904 iface = netdev_priv(dev);
2905 local = iface->local;
2909 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2916 static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2918 struct hostap_interface *iface;
2919 local_info_t *local;
2923 iface = netdev_priv(dev);
2924 local = iface->local;
2926 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2927 "- update software to use iwconfig mode monitor\n",
2928 dev->name, current->pid, current->comm);
2930 /* Backward compatibility code - this can be removed at some point */
2933 /* Disable monitor mode - old mode was not saved, so go to
2935 mode = IW_MODE_MASTER;
2936 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2937 } else if (*i == 1) {
2938 /* netlink socket mode is not supported anymore since it did
2939 * not separate different devices from each other and was not
2940 * best method for delivering large amount of packets to
2943 } else if (*i == 2 || *i == 3) {
2946 local->monitor_type = PRISM2_MONITOR_80211;
2949 local->monitor_type = PRISM2_MONITOR_PRISM;
2952 mode = IW_MODE_MONITOR;
2953 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2954 hostap_monitor_mode_enable(local);
2962 static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
2964 struct hostap_interface *iface;
2965 local_info_t *local;
2967 iface = netdev_priv(dev);
2968 local = iface->local;
2970 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
2973 /* Disable and enable card */
2974 local->func->hw_shutdown(dev, 1);
2975 local->func->hw_config(dev, 0);
2980 local->func->hw_reset(dev);
2984 /* Disable and enable port 0 */
2985 local->func->reset_port(dev);
2989 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
2990 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
2996 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
3002 printk(KERN_DEBUG "Unknown reset request %d\n", *i);
3010 static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
3013 int value = *(i + 1);
3015 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
3017 if (hostap_set_word(dev, rid, value))
3024 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3025 static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3030 case AP_MAC_CMD_POLICY_OPEN:
3031 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3033 case AP_MAC_CMD_POLICY_ALLOW:
3034 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3036 case AP_MAC_CMD_POLICY_DENY:
3037 local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3039 case AP_MAC_CMD_FLUSH:
3040 ap_control_flush_macs(&local->ap->mac_restrictions);
3042 case AP_MAC_CMD_KICKALL:
3043 ap_control_kickall(local->ap);
3044 hostap_deauth_all_stas(local->dev, local->ap, 0);
3053 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3056 #ifdef PRISM2_DOWNLOAD_SUPPORT
3057 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3059 struct prism2_download_param *param;
3062 if (p->length < sizeof(struct prism2_download_param) ||
3063 p->length > 1024 || !p->pointer)
3066 param = (struct prism2_download_param *)
3067 kmalloc(p->length, GFP_KERNEL);
3071 if (copy_from_user(param, p->pointer, p->length)) {
3076 if (p->length < sizeof(struct prism2_download_param) +
3077 param->num_areas * sizeof(struct prism2_download_area)) {
3082 ret = local->func->download(local, param);
3088 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3091 static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
3094 struct hostap_interface *iface = dev->priv;
3095 local_info_t *local = iface->local;
3099 * Add 16-bit length in the beginning of the buffer because Prism2 RID
3102 buf = kmalloc(len + 2, GFP_KERNEL);
3106 *((u16 *) buf) = cpu_to_le16(len);
3107 memcpy(buf + 2, elem, len);
3109 kfree(local->generic_elem);
3110 local->generic_elem = buf;
3111 local->generic_elem_len = len + 2;
3113 return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
3118 static int prism2_ioctl_siwauth(struct net_device *dev,
3119 struct iw_request_info *info,
3120 struct iw_param *data, char *extra)
3122 struct hostap_interface *iface = dev->priv;
3123 local_info_t *local = iface->local;
3125 switch (data->flags & IW_AUTH_INDEX) {
3126 case IW_AUTH_WPA_VERSION:
3127 case IW_AUTH_CIPHER_PAIRWISE:
3128 case IW_AUTH_CIPHER_GROUP:
3129 case IW_AUTH_KEY_MGMT:
3131 * Host AP driver does not use these parameters and allows
3132 * wpa_supplicant to control them internally.
3135 case IW_AUTH_TKIP_COUNTERMEASURES:
3136 local->tkip_countermeasures = data->value;
3138 case IW_AUTH_DROP_UNENCRYPTED:
3139 local->drop_unencrypted = data->value;
3141 case IW_AUTH_80211_AUTH_ALG:
3142 local->auth_algs = data->value;
3144 case IW_AUTH_WPA_ENABLED:
3145 if (data->value == 0) {
3147 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3149 prism2_set_genericelement(dev, "", 0);
3150 local->host_roaming = 0;
3151 local->privacy_invoked = 0;
3152 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
3154 hostap_set_roaming(local) ||
3155 hostap_set_encryption(local) ||
3156 local->func->reset_port(dev))
3160 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3162 local->host_roaming = 2;
3163 local->privacy_invoked = 1;
3165 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
3166 hostap_set_roaming(local) ||
3167 hostap_set_encryption(local) ||
3168 local->func->reset_port(dev))
3171 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3172 local->ieee_802_1x = data->value;
3174 case IW_AUTH_PRIVACY_INVOKED:
3175 local->privacy_invoked = data->value;
3184 static int prism2_ioctl_giwauth(struct net_device *dev,
3185 struct iw_request_info *info,
3186 struct iw_param *data, char *extra)
3188 struct hostap_interface *iface = dev->priv;
3189 local_info_t *local = iface->local;
3191 switch (data->flags & IW_AUTH_INDEX) {
3192 case IW_AUTH_WPA_VERSION:
3193 case IW_AUTH_CIPHER_PAIRWISE:
3194 case IW_AUTH_CIPHER_GROUP:
3195 case IW_AUTH_KEY_MGMT:
3197 * Host AP driver does not use these parameters and allows
3198 * wpa_supplicant to control them internally.
3201 case IW_AUTH_TKIP_COUNTERMEASURES:
3202 data->value = local->tkip_countermeasures;
3204 case IW_AUTH_DROP_UNENCRYPTED:
3205 data->value = local->drop_unencrypted;
3207 case IW_AUTH_80211_AUTH_ALG:
3208 data->value = local->auth_algs;
3210 case IW_AUTH_WPA_ENABLED:
3211 data->value = local->wpa;
3213 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3214 data->value = local->ieee_802_1x;
3223 static int prism2_ioctl_siwencodeext(struct net_device *dev,
3224 struct iw_request_info *info,
3225 struct iw_point *erq, char *extra)
3227 struct hostap_interface *iface = dev->priv;
3228 local_info_t *local = iface->local;
3229 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3231 struct ieee80211_crypto_ops *ops;
3232 struct ieee80211_crypt_data **crypt;
3235 const char *alg, *module;
3237 i = erq->flags & IW_ENCODE_INDEX;
3240 if (i < 1 || i > WEP_KEYS)
3241 i = local->tx_keyidx;
3244 if (i < 0 || i >= WEP_KEYS)
3247 addr = ext->addr.sa_data;
3248 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3249 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3251 crypt = &local->crypt[i];
3255 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3256 if (sta_ptr == NULL) {
3257 if (local->iw_mode == IW_MODE_INFRA) {
3259 * TODO: add STA entry for the current AP so
3260 * that unicast key can be used. For now, this
3261 * is emulated by using default key idx 0.
3264 crypt = &local->crypt[i];
3270 if ((erq->flags & IW_ENCODE_DISABLED) ||
3271 ext->alg == IW_ENCODE_ALG_NONE) {
3273 prism2_crypt_delayed_deinit(local, crypt);
3278 case IW_ENCODE_ALG_WEP:
3280 module = "ieee80211_crypt_wep";
3282 case IW_ENCODE_ALG_TKIP:
3284 module = "ieee80211_crypt_tkip";
3286 case IW_ENCODE_ALG_CCMP:
3288 module = "ieee80211_crypt_ccmp";
3291 printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
3292 local->dev->name, ext->alg);
3297 ops = ieee80211_get_crypto_ops(alg);
3299 request_module(module);
3300 ops = ieee80211_get_crypto_ops(alg);
3303 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3304 local->dev->name, alg);
3309 if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
3311 * Per station encryption and other than WEP algorithms
3312 * require host-based encryption, so force them on
3315 local->host_decrypt = local->host_encrypt = 1;
3318 if (*crypt == NULL || (*crypt)->ops != ops) {
3319 struct ieee80211_crypt_data *new_crypt;
3321 prism2_crypt_delayed_deinit(local, crypt);
3323 new_crypt = (struct ieee80211_crypt_data *)
3324 kmalloc(sizeof(struct ieee80211_crypt_data),
3326 if (new_crypt == NULL) {
3330 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3331 new_crypt->ops = ops;
3332 new_crypt->priv = new_crypt->ops->init(i);
3333 if (new_crypt->priv == NULL) {
3343 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
3344 * existing seq# should not be changed.
3345 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
3346 * should be changed to something else than zero.
3348 if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
3349 && (*crypt)->ops->set_key &&
3350 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
3351 (*crypt)->priv) < 0) {
3352 printk(KERN_DEBUG "%s: key setting failed\n",
3358 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3360 local->tx_keyidx = i;
3364 if (sta_ptr == NULL && ext->key_len > 0) {
3366 for (j = 0; j < WEP_KEYS; j++) {
3367 if (j != i && local->crypt[j]) {
3373 local->tx_keyidx = i;
3378 hostap_handle_sta_release(sta_ptr);
3380 local->open_wep = erq->flags & IW_ENCODE_OPEN;
3383 * Do not reset port0 if card is in Managed mode since resetting will
3384 * generate new IEEE 802.11 authentication which may end up in looping
3385 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3386 * after WEP configuration. However, keys are apparently changed at
3387 * least in Managed mode.
3390 (hostap_set_encryption(local) ||
3391 (local->iw_mode != IW_MODE_INFRA &&
3392 local->func->reset_port(local->dev))))
3399 static int prism2_ioctl_giwencodeext(struct net_device *dev,
3400 struct iw_request_info *info,
3401 struct iw_point *erq, char *extra)
3403 struct hostap_interface *iface = dev->priv;
3404 local_info_t *local = iface->local;
3405 struct ieee80211_crypt_data **crypt;
3408 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3411 max_key_len = erq->length - sizeof(*ext);
3412 if (max_key_len < 0)
3415 i = erq->flags & IW_ENCODE_INDEX;
3416 if (i < 1 || i > WEP_KEYS)
3417 i = local->tx_keyidx;
3421 addr = ext->addr.sa_data;
3422 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3423 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3425 crypt = &local->crypt[i];
3428 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3429 if (sta_ptr == NULL)
3433 memset(ext, 0, sizeof(*ext));
3435 if (*crypt == NULL || (*crypt)->ops == NULL) {
3436 ext->alg = IW_ENCODE_ALG_NONE;
3438 erq->flags |= IW_ENCODE_DISABLED;
3440 if (strcmp((*crypt)->ops->name, "WEP") == 0)
3441 ext->alg = IW_ENCODE_ALG_WEP;
3442 else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
3443 ext->alg = IW_ENCODE_ALG_TKIP;
3444 else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
3445 ext->alg = IW_ENCODE_ALG_CCMP;
3449 if ((*crypt)->ops->get_key) {
3451 (*crypt)->ops->get_key(ext->key,
3456 (ext->alg == IW_ENCODE_ALG_TKIP ||
3457 ext->alg == IW_ENCODE_ALG_CCMP))
3458 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
3463 hostap_handle_sta_release(sta_ptr);
3469 static int prism2_ioctl_set_encryption(local_info_t *local,
3470 struct prism2_hostapd_param *param,
3474 struct ieee80211_crypto_ops *ops;
3475 struct ieee80211_crypt_data **crypt;
3478 param->u.crypt.err = 0;
3479 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
3482 (int) ((char *) param->u.crypt.key - (char *) param) +
3483 param->u.crypt.key_len)
3486 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3487 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3488 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3489 if (param->u.crypt.idx >= WEP_KEYS)
3492 crypt = &local->crypt[param->u.crypt.idx];
3494 if (param->u.crypt.idx)
3496 sta_ptr = ap_crypt_get_ptrs(
3497 local->ap, param->sta_addr,
3498 (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
3501 if (sta_ptr == NULL) {
3502 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3507 if (strcmp(param->u.crypt.alg, "none") == 0) {
3509 prism2_crypt_delayed_deinit(local, crypt);
3513 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3514 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3515 request_module("ieee80211_crypt_wep");
3516 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3517 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3518 request_module("ieee80211_crypt_tkip");
3519 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3520 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3521 request_module("ieee80211_crypt_ccmp");
3522 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3525 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3526 local->dev->name, param->u.crypt.alg);
3527 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
3532 /* station based encryption and other than WEP algorithms require
3533 * host-based encryption, so force them on automatically */
3534 local->host_decrypt = local->host_encrypt = 1;
3536 if (*crypt == NULL || (*crypt)->ops != ops) {
3537 struct ieee80211_crypt_data *new_crypt;
3539 prism2_crypt_delayed_deinit(local, crypt);
3541 new_crypt = (struct ieee80211_crypt_data *)
3542 kmalloc(sizeof(struct ieee80211_crypt_data),
3544 if (new_crypt == NULL) {
3548 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3549 new_crypt->ops = ops;
3550 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
3551 if (new_crypt->priv == NULL) {
3553 param->u.crypt.err =
3554 HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
3562 if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
3563 param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
3564 (*crypt)->ops->set_key(param->u.crypt.key,
3565 param->u.crypt.key_len, param->u.crypt.seq,
3566 (*crypt)->priv) < 0) {
3567 printk(KERN_DEBUG "%s: key setting failed\n",
3569 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
3574 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
3576 local->tx_keyidx = param->u.crypt.idx;
3577 else if (param->u.crypt.idx) {
3578 printk(KERN_DEBUG "%s: TX key idx setting failed\n",
3580 param->u.crypt.err =
3581 HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
3589 hostap_handle_sta_release(sta_ptr);
3591 /* Do not reset port0 if card is in Managed mode since resetting will
3592 * generate new IEEE 802.11 authentication which may end up in looping
3593 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3594 * after WEP configuration. However, keys are apparently changed at
3595 * least in Managed mode. */
3597 (hostap_set_encryption(local) ||
3598 (local->iw_mode != IW_MODE_INFRA &&
3599 local->func->reset_port(local->dev)))) {
3600 param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
3608 static int prism2_ioctl_get_encryption(local_info_t *local,
3609 struct prism2_hostapd_param *param,
3612 struct ieee80211_crypt_data **crypt;
3616 param->u.crypt.err = 0;
3618 max_key_len = param_len -
3619 (int) ((char *) param->u.crypt.key - (char *) param);
3620 if (max_key_len < 0)
3623 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3624 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3625 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3627 if (param->u.crypt.idx >= WEP_KEYS)
3628 param->u.crypt.idx = local->tx_keyidx;
3629 crypt = &local->crypt[param->u.crypt.idx];
3631 param->u.crypt.idx = 0;
3632 sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
3635 if (sta_ptr == NULL) {
3636 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3641 if (*crypt == NULL || (*crypt)->ops == NULL) {
3642 memcpy(param->u.crypt.alg, "none", 5);
3643 param->u.crypt.key_len = 0;
3644 param->u.crypt.idx = 0xff;
3646 strncpy(param->u.crypt.alg, (*crypt)->ops->name,
3647 HOSTAP_CRYPT_ALG_NAME_LEN);
3648 param->u.crypt.key_len = 0;
3650 memset(param->u.crypt.seq, 0, 8);
3651 if ((*crypt)->ops->get_key) {
3652 param->u.crypt.key_len =
3653 (*crypt)->ops->get_key(param->u.crypt.key,
3661 hostap_handle_sta_release(sta_ptr);
3667 static int prism2_ioctl_get_rid(local_info_t *local,
3668 struct prism2_hostapd_param *param,
3673 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3677 res = local->func->get_rid(local->dev, param->u.rid.rid,
3678 param->u.rid.data, param->u.rid.len, 0);
3680 param->u.rid.len = res;
3688 static int prism2_ioctl_set_rid(local_info_t *local,
3689 struct prism2_hostapd_param *param,
3694 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3695 if (max_len < 0 || max_len < param->u.rid.len)
3698 return local->func->set_rid(local->dev, param->u.rid.rid,
3699 param->u.rid.data, param->u.rid.len);
3703 static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
3704 struct prism2_hostapd_param *param,
3707 printk(KERN_DEBUG "%ssta: associated as client with AP " MACSTR "\n",
3708 local->dev->name, MAC2STR(param->sta_addr));
3709 memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
3714 static int prism2_ioctl_siwgenie(struct net_device *dev,
3715 struct iw_request_info *info,
3716 struct iw_point *data, char *extra)
3718 return prism2_set_genericelement(dev, extra, data->length);
3722 static int prism2_ioctl_giwgenie(struct net_device *dev,
3723 struct iw_request_info *info,
3724 struct iw_point *data, char *extra)
3726 struct hostap_interface *iface = dev->priv;
3727 local_info_t *local = iface->local;
3728 int len = local->generic_elem_len - 2;
3730 if (len <= 0 || local->generic_elem == NULL) {
3735 if (data->length < len)
3739 memcpy(extra, local->generic_elem + 2, len);
3745 static int prism2_ioctl_set_generic_element(local_info_t *local,
3746 struct prism2_hostapd_param *param,
3751 len = param->u.generic_elem.len;
3752 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
3753 if (max_len < 0 || max_len < len)
3756 return prism2_set_genericelement(local->dev,
3757 param->u.generic_elem.data, len);
3761 static int prism2_ioctl_siwmlme(struct net_device *dev,
3762 struct iw_request_info *info,
3763 struct iw_point *data, char *extra)
3765 struct hostap_interface *iface = dev->priv;
3766 local_info_t *local = iface->local;
3767 struct iw_mlme *mlme = (struct iw_mlme *) extra;
3770 reason = cpu_to_le16(mlme->reason_code);
3772 switch (mlme->cmd) {
3773 case IW_MLME_DEAUTH:
3774 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3775 IEEE80211_STYPE_DEAUTH,
3777 case IW_MLME_DISASSOC:
3778 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3779 IEEE80211_STYPE_DISASSOC,
3787 static int prism2_ioctl_mlme(local_info_t *local,
3788 struct prism2_hostapd_param *param)
3792 reason = cpu_to_le16(param->u.mlme.reason_code);
3793 switch (param->u.mlme.cmd) {
3794 case MLME_STA_DEAUTH:
3795 return prism2_sta_send_mgmt(local, param->sta_addr,
3796 IEEE80211_STYPE_DEAUTH,
3798 case MLME_STA_DISASSOC:
3799 return prism2_sta_send_mgmt(local, param->sta_addr,
3800 IEEE80211_STYPE_DISASSOC,
3808 static int prism2_ioctl_scan_req(local_info_t *local,
3809 struct prism2_hostapd_param *param)
3811 #ifndef PRISM2_NO_STATION_MODES
3812 if ((local->iw_mode != IW_MODE_INFRA &&
3813 local->iw_mode != IW_MODE_ADHOC) ||
3814 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
3817 if (!local->dev_enabled)
3820 return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
3821 param->u.scan_req.ssid_len);
3822 #else /* PRISM2_NO_STATION_MODES */
3824 #endif /* PRISM2_NO_STATION_MODES */
3828 static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3830 struct prism2_hostapd_param *param;
3834 if (p->length < sizeof(struct prism2_hostapd_param) ||
3835 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
3838 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
3842 if (copy_from_user(param, p->pointer, p->length)) {
3847 switch (param->cmd) {
3848 case PRISM2_SET_ENCRYPTION:
3849 ret = prism2_ioctl_set_encryption(local, param, p->length);
3851 case PRISM2_GET_ENCRYPTION:
3852 ret = prism2_ioctl_get_encryption(local, param, p->length);
3854 case PRISM2_HOSTAPD_GET_RID:
3855 ret = prism2_ioctl_get_rid(local, param, p->length);
3857 case PRISM2_HOSTAPD_SET_RID:
3858 ret = prism2_ioctl_set_rid(local, param, p->length);
3860 case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
3861 ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
3863 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
3864 ret = prism2_ioctl_set_generic_element(local, param,
3867 case PRISM2_HOSTAPD_MLME:
3868 ret = prism2_ioctl_mlme(local, param);
3870 case PRISM2_HOSTAPD_SCAN_REQ:
3871 ret = prism2_ioctl_scan_req(local, param);
3874 ret = prism2_hostapd(local->ap, param);
3879 if (ret == 1 || !ap_ioctl) {
3880 if (copy_to_user(p->pointer, param, p->length)) {
3883 } else if (ap_ioctl)
3893 static void prism2_get_drvinfo(struct net_device *dev,
3894 struct ethtool_drvinfo *info)
3896 struct hostap_interface *iface;
3897 local_info_t *local;
3899 iface = netdev_priv(dev);
3900 local = iface->local;
3902 strncpy(info->driver, "hostap", sizeof(info->driver) - 1);
3903 strncpy(info->version, PRISM2_VERSION,
3904 sizeof(info->version) - 1);
3905 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
3906 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
3907 (local->sta_fw_ver >> 8) & 0xff,
3908 local->sta_fw_ver & 0xff);
3911 struct ethtool_ops prism2_ethtool_ops = {
3912 .get_drvinfo = prism2_get_drvinfo
3916 /* Structures to export the Wireless Handlers */
3918 static const iw_handler prism2_handler[] =
3920 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3921 (iw_handler) prism2_get_name, /* SIOCGIWNAME */
3922 (iw_handler) NULL, /* SIOCSIWNWID */
3923 (iw_handler) NULL, /* SIOCGIWNWID */
3924 (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */
3925 (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */
3926 (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */
3927 (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */
3928 (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */
3929 (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */
3930 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3931 (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */
3932 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3933 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3934 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3935 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
3936 iw_handler_set_spy, /* SIOCSIWSPY */
3937 iw_handler_get_spy, /* SIOCGIWSPY */
3938 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
3939 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
3940 (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */
3941 (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */
3942 (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */
3943 (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */
3944 (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */
3945 (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */
3946 (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */
3947 (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */
3948 (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */
3949 (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */
3950 (iw_handler) NULL, /* -- hole -- */
3951 (iw_handler) NULL, /* -- hole -- */
3952 (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */
3953 (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */
3954 (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */
3955 (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */
3956 (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */
3957 (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */
3958 (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */
3959 (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */
3960 (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */
3961 (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */
3962 (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */
3963 (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */
3964 (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */
3965 (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */
3966 (iw_handler) NULL, /* -- hole -- */
3967 (iw_handler) NULL, /* -- hole -- */
3968 (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */
3969 (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */
3970 (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */
3971 (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */
3972 (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3973 (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3974 (iw_handler) NULL, /* SIOCSIWPMKSA */
3975 (iw_handler) NULL, /* -- hole -- */
3978 static const iw_handler prism2_private_handler[] =
3979 { /* SIOCIWFIRSTPRIV + */
3980 (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */
3981 (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
3982 (iw_handler) prism2_ioctl_priv_writemif, /* 2 */
3983 (iw_handler) prism2_ioctl_priv_readmif, /* 3 */
3986 const struct iw_handler_def hostap_iw_handler_def =
3988 .num_standard = sizeof(prism2_handler) / sizeof(iw_handler),
3989 .num_private = sizeof(prism2_private_handler) / sizeof(iw_handler),
3990 .num_private_args = sizeof(prism2_priv) / sizeof(struct iw_priv_args),
3991 .standard = (iw_handler *) prism2_handler,
3992 .private = (iw_handler *) prism2_private_handler,
3993 .private_args = (struct iw_priv_args *) prism2_priv,
3994 .get_wireless_stats = hostap_get_wireless_stats,
3998 int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4000 struct iwreq *wrq = (struct iwreq *) ifr;
4001 struct hostap_interface *iface;
4002 local_info_t *local;
4005 iface = netdev_priv(dev);
4006 local = iface->local;
4009 /* Private ioctls (iwpriv) that have not yet been converted
4010 * into new wireless extensions API */
4012 case PRISM2_IOCTL_INQUIRE:
4013 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4014 else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
4017 case PRISM2_IOCTL_MONITOR:
4018 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4019 else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
4022 case PRISM2_IOCTL_RESET:
4023 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4024 else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
4027 case PRISM2_IOCTL_WDS_ADD:
4028 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4029 else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
4032 case PRISM2_IOCTL_WDS_DEL:
4033 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4034 else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
4037 case PRISM2_IOCTL_SET_RID_WORD:
4038 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4039 else ret = prism2_ioctl_priv_set_rid_word(dev,
4040 (int *) wrq->u.name);
4043 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
4044 case PRISM2_IOCTL_MACCMD:
4045 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4046 else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
4049 case PRISM2_IOCTL_ADDMAC:
4050 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4051 else ret = ap_control_add_mac(&local->ap->mac_restrictions,
4052 wrq->u.ap_addr.sa_data);
4054 case PRISM2_IOCTL_DELMAC:
4055 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4056 else ret = ap_control_del_mac(&local->ap->mac_restrictions,
4057 wrq->u.ap_addr.sa_data);
4059 case PRISM2_IOCTL_KICKMAC:
4060 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4061 else ret = ap_control_kick_mac(local->ap, local->dev,
4062 wrq->u.ap_addr.sa_data);
4064 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
4067 /* Private ioctls that are not used with iwpriv;
4068 * in SIOCDEVPRIVATE range */
4070 #ifdef PRISM2_DOWNLOAD_SUPPORT
4071 case PRISM2_IOCTL_DOWNLOAD:
4072 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4073 else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
4075 #endif /* PRISM2_DOWNLOAD_SUPPORT */
4077 case PRISM2_IOCTL_HOSTAPD:
4078 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4079 else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);