1 /* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
3 #include <linux/types.h>
4 #include <linux/ethtool.h>
5 #include <net/ieee80211_crypt.h>
7 #include "hostap_wlan.h"
11 static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
13 struct hostap_interface *iface;
15 struct iw_statistics *wstats;
17 iface = netdev_priv(dev);
20 /* Why are we doing that ? Jean II */
21 if (iface->type != HOSTAP_INTERFACE_MAIN)
24 wstats = &local->wstats;
27 wstats->discard.code =
28 local->comm_tallies.rx_discards_wep_undecryptable;
29 wstats->discard.misc =
30 local->comm_tallies.rx_fcs_errors +
31 local->comm_tallies.rx_discards_no_buffer +
32 local->comm_tallies.tx_discards_wrong_sa;
34 wstats->discard.retries =
35 local->comm_tallies.tx_retry_limit_exceeded;
36 wstats->discard.fragment =
37 local->comm_tallies.rx_message_in_bad_msg_fragments;
39 if (local->iw_mode != IW_MODE_MASTER &&
40 local->iw_mode != IW_MODE_REPEAT) {
43 /* RID reading might sleep and it must not be called in
44 * interrupt context or while atomic. However, this
45 * function seems to be called while atomic (at least in Linux
46 * 2.5.59). Update signal quality values only if in suitable
47 * context. Otherwise, previous values read from tick timer
51 #endif /* in_atomic */
53 if (update && prism2_update_comms_qual(dev) == 0)
54 wstats->qual.updated = IW_QUAL_ALL_UPDATED |
57 wstats->qual.qual = local->comms_qual;
58 wstats->qual.level = local->avg_signal;
59 wstats->qual.noise = local->avg_noise;
61 wstats->qual.qual = 0;
62 wstats->qual.level = 0;
63 wstats->qual.noise = 0;
64 wstats->qual.updated = IW_QUAL_ALL_INVALID;
71 static int prism2_get_datarates(struct net_device *dev, u8 *rates)
73 struct hostap_interface *iface;
79 iface = netdev_priv(dev);
82 len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
87 val = le16_to_cpu(*(u16 *) buf); /* string length */
89 if (len - 2 < val || val > 10)
92 memcpy(rates, buf + 2, val);
97 static int prism2_get_name(struct net_device *dev,
98 struct iw_request_info *info,
99 char *name, char *extra)
102 int len, i, over2 = 0;
104 len = prism2_get_datarates(dev, rates);
106 for (i = 0; i < len; i++) {
107 if (rates[i] == 0x0b || rates[i] == 0x16) {
113 strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
119 static void prism2_crypt_delayed_deinit(local_info_t *local,
120 struct ieee80211_crypt_data **crypt)
122 struct ieee80211_crypt_data *tmp;
131 /* must not run ops->deinit() while there may be pending encrypt or
132 * decrypt operations. Use a list of delayed deinits to avoid needing
135 spin_lock_irqsave(&local->lock, flags);
136 list_add(&tmp->list, &local->crypt_deinit_list);
137 if (!timer_pending(&local->crypt_deinit_timer)) {
138 local->crypt_deinit_timer.expires = jiffies + HZ;
139 add_timer(&local->crypt_deinit_timer);
141 spin_unlock_irqrestore(&local->lock, flags);
145 static int prism2_ioctl_siwencode(struct net_device *dev,
146 struct iw_request_info *info,
147 struct iw_point *erq, char *keybuf)
149 struct hostap_interface *iface;
152 struct ieee80211_crypt_data **crypt;
154 iface = netdev_priv(dev);
155 local = iface->local;
157 i = erq->flags & IW_ENCODE_INDEX;
159 i = local->tx_keyidx;
162 if (i < 0 || i >= WEP_KEYS)
165 crypt = &local->crypt[i];
167 if (erq->flags & IW_ENCODE_DISABLED) {
169 prism2_crypt_delayed_deinit(local, crypt);
173 if (*crypt != NULL && (*crypt)->ops != NULL &&
174 strcmp((*crypt)->ops->name, "WEP") != 0) {
175 /* changing to use WEP; deinit previously used algorithm */
176 prism2_crypt_delayed_deinit(local, crypt);
179 if (*crypt == NULL) {
180 struct ieee80211_crypt_data *new_crypt;
182 /* take WEP into use */
183 new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
185 if (new_crypt == NULL)
187 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
188 if (!new_crypt->ops) {
189 request_module("ieee80211_crypt_wep");
190 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
193 new_crypt->priv = new_crypt->ops->init(i);
194 if (!new_crypt->ops || !new_crypt->priv) {
198 printk(KERN_WARNING "%s: could not initialize WEP: "
199 "load module hostap_crypt_wep.o\n",
206 if (erq->length > 0) {
207 int len = erq->length <= 5 ? 5 : 13;
209 if (len > erq->length)
210 memset(keybuf + erq->length, 0, len - erq->length);
211 (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
212 for (j = 0; j < WEP_KEYS; j++) {
213 if (j != i && local->crypt[j]) {
219 local->tx_keyidx = i;
221 /* No key data - just set the default TX key index */
222 local->tx_keyidx = i;
226 local->open_wep = erq->flags & IW_ENCODE_OPEN;
228 if (hostap_set_encryption(local)) {
229 printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
233 /* Do not reset port0 if card is in Managed mode since resetting will
234 * generate new IEEE 802.11 authentication which may end up in looping
235 * with IEEE 802.1X. Prism2 documentation seem to require port reset
236 * after WEP configuration. However, keys are apparently changed at
237 * least in Managed mode. */
238 if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
239 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
247 static int prism2_ioctl_giwencode(struct net_device *dev,
248 struct iw_request_info *info,
249 struct iw_point *erq, char *key)
251 struct hostap_interface *iface;
255 struct ieee80211_crypt_data *crypt;
257 iface = netdev_priv(dev);
258 local = iface->local;
260 i = erq->flags & IW_ENCODE_INDEX;
262 i = local->tx_keyidx;
265 if (i < 0 || i >= WEP_KEYS)
268 crypt = local->crypt[i];
271 if (crypt == NULL || crypt->ops == NULL) {
273 erq->flags |= IW_ENCODE_DISABLED;
277 if (strcmp(crypt->ops->name, "WEP") != 0) {
278 /* only WEP is supported with wireless extensions, so just
279 * report that encryption is used */
281 erq->flags |= IW_ENCODE_ENABLED;
285 /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
286 * the keys from driver buffer */
287 len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
288 erq->length = (len >= 0 ? len : 0);
290 if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
292 printk("CNFWEPFLAGS reading failed\n");
296 if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
297 erq->flags |= IW_ENCODE_ENABLED;
299 erq->flags |= IW_ENCODE_DISABLED;
300 if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
301 erq->flags |= IW_ENCODE_RESTRICTED;
303 erq->flags |= IW_ENCODE_OPEN;
309 static int hostap_set_rate(struct net_device *dev)
311 struct hostap_interface *iface;
313 int ret, basic_rates;
315 iface = netdev_priv(dev);
316 local = iface->local;
318 basic_rates = local->basic_rates & local->tx_rate_control;
319 if (!basic_rates || basic_rates != local->basic_rates) {
320 printk(KERN_INFO "%s: updating basic rate set automatically "
321 "to match with the new supported rate set\n",
324 basic_rates = local->tx_rate_control;
326 local->basic_rates = basic_rates;
327 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
329 printk(KERN_WARNING "%s: failed to set "
330 "cnfBasicRates\n", dev->name);
333 ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
334 local->tx_rate_control) ||
335 hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
336 local->tx_rate_control) ||
337 local->func->reset_port(dev));
340 printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
341 "setting to 0x%x failed\n",
342 dev->name, local->tx_rate_control);
345 /* Update TX rate configuration for all STAs based on new operational
347 hostap_update_rates(local);
353 static int prism2_ioctl_siwrate(struct net_device *dev,
354 struct iw_request_info *info,
355 struct iw_param *rrq, char *extra)
357 struct hostap_interface *iface;
360 iface = netdev_priv(dev);
361 local = iface->local;
364 switch (rrq->value) {
366 local->tx_rate_control = HFA384X_RATES_11MBPS;
369 local->tx_rate_control = HFA384X_RATES_5MBPS;
372 local->tx_rate_control = HFA384X_RATES_2MBPS;
375 local->tx_rate_control = HFA384X_RATES_1MBPS;
378 local->tx_rate_control = HFA384X_RATES_1MBPS |
379 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
380 HFA384X_RATES_11MBPS;
384 switch (rrq->value) {
386 local->tx_rate_control = HFA384X_RATES_1MBPS |
387 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
388 HFA384X_RATES_11MBPS;
391 local->tx_rate_control = HFA384X_RATES_1MBPS |
392 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
395 local->tx_rate_control = HFA384X_RATES_1MBPS |
399 local->tx_rate_control = HFA384X_RATES_1MBPS;
402 local->tx_rate_control = HFA384X_RATES_1MBPS |
403 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
404 HFA384X_RATES_11MBPS;
409 return hostap_set_rate(dev);
413 static int prism2_ioctl_giwrate(struct net_device *dev,
414 struct iw_request_info *info,
415 struct iw_param *rrq, char *extra)
418 struct hostap_interface *iface;
422 iface = netdev_priv(dev);
423 local = iface->local;
425 if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
429 if ((val & 0x1) && (val > 1))
434 if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
435 !local->fw_tx_rate_control) {
436 /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
437 * Host AP mode, so use the recorded TX rate of the last sent
439 rrq->value = local->ap->last_tx_rate > 0 ?
440 local->ap->last_tx_rate * 100000 : 11000000;
444 if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
449 case HFA384X_RATES_1MBPS:
450 rrq->value = 1000000;
452 case HFA384X_RATES_2MBPS:
453 rrq->value = 2000000;
455 case HFA384X_RATES_5MBPS:
456 rrq->value = 5500000;
458 case HFA384X_RATES_11MBPS:
459 rrq->value = 11000000;
462 /* should not happen */
463 rrq->value = 11000000;
472 static int prism2_ioctl_siwsens(struct net_device *dev,
473 struct iw_request_info *info,
474 struct iw_param *sens, char *extra)
476 struct hostap_interface *iface;
479 iface = netdev_priv(dev);
480 local = iface->local;
482 /* Set the desired AP density */
483 if (sens->value < 1 || sens->value > 3)
486 if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
487 local->func->reset_port(dev))
493 static int prism2_ioctl_giwsens(struct net_device *dev,
494 struct iw_request_info *info,
495 struct iw_param *sens, char *extra)
497 struct hostap_interface *iface;
501 iface = netdev_priv(dev);
502 local = iface->local;
504 /* Get the current AP density */
505 if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
509 sens->value = __le16_to_cpu(val);
516 /* Deprecated in new wireless extension API */
517 static int prism2_ioctl_giwaplist(struct net_device *dev,
518 struct iw_request_info *info,
519 struct iw_point *data, char *extra)
521 struct hostap_interface *iface;
523 struct sockaddr *addr;
524 struct iw_quality *qual;
526 iface = netdev_priv(dev);
527 local = iface->local;
529 if (local->iw_mode != IW_MODE_MASTER) {
530 printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
531 "in Host AP mode\n");
536 addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
537 qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
538 if (addr == NULL || qual == NULL) {
545 data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
547 memcpy(extra, &addr, sizeof(struct sockaddr) * data->length);
548 data->flags = 1; /* has quality information */
549 memcpy(extra + sizeof(struct sockaddr) * data->length, &qual,
550 sizeof(struct iw_quality) * data->length);
558 static int prism2_ioctl_siwrts(struct net_device *dev,
559 struct iw_request_info *info,
560 struct iw_param *rts, char *extra)
562 struct hostap_interface *iface;
566 iface = netdev_priv(dev);
567 local = iface->local;
570 val = __constant_cpu_to_le16(2347);
571 else if (rts->value < 0 || rts->value > 2347)
574 val = __cpu_to_le16(rts->value);
576 if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) ||
577 local->func->reset_port(dev))
580 local->rts_threshold = rts->value;
585 static int prism2_ioctl_giwrts(struct net_device *dev,
586 struct iw_request_info *info,
587 struct iw_param *rts, char *extra)
589 struct hostap_interface *iface;
593 iface = netdev_priv(dev);
594 local = iface->local;
596 if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) <
600 rts->value = __le16_to_cpu(val);
601 rts->disabled = (rts->value == 2347);
608 static int prism2_ioctl_siwfrag(struct net_device *dev,
609 struct iw_request_info *info,
610 struct iw_param *rts, char *extra)
612 struct hostap_interface *iface;
616 iface = netdev_priv(dev);
617 local = iface->local;
620 val = __constant_cpu_to_le16(2346);
621 else if (rts->value < 256 || rts->value > 2346)
624 val = __cpu_to_le16(rts->value & ~0x1); /* even numbers only */
626 local->fragm_threshold = rts->value & ~0x1;
627 if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val,
629 || local->func->reset_port(dev))
635 static int prism2_ioctl_giwfrag(struct net_device *dev,
636 struct iw_request_info *info,
637 struct iw_param *rts, char *extra)
639 struct hostap_interface *iface;
643 iface = netdev_priv(dev);
644 local = iface->local;
646 if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
650 rts->value = __le16_to_cpu(val);
651 rts->disabled = (rts->value == 2346);
658 #ifndef PRISM2_NO_STATION_MODES
659 static int hostap_join_ap(struct net_device *dev)
661 struct hostap_interface *iface;
663 struct hfa384x_join_request req;
666 struct hfa384x_hostscan_result *entry;
668 iface = netdev_priv(dev);
669 local = iface->local;
671 memcpy(req.bssid, local->preferred_ap, ETH_ALEN);
674 spin_lock_irqsave(&local->lock, flags);
675 for (i = 0; i < local->last_scan_results_count; i++) {
676 if (!local->last_scan_results)
678 entry = &local->last_scan_results[i];
679 if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) {
680 req.channel = entry->chid;
684 spin_unlock_irqrestore(&local->lock, flags);
686 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
688 printk(KERN_DEBUG "%s: JoinRequest " MACSTR
690 dev->name, MAC2STR(local->preferred_ap));
694 printk(KERN_DEBUG "%s: Trying to join BSSID " MACSTR "\n",
695 dev->name, MAC2STR(local->preferred_ap));
699 #endif /* PRISM2_NO_STATION_MODES */
702 static int prism2_ioctl_siwap(struct net_device *dev,
703 struct iw_request_info *info,
704 struct sockaddr *ap_addr, char *extra)
706 #ifdef PRISM2_NO_STATION_MODES
708 #else /* PRISM2_NO_STATION_MODES */
709 struct hostap_interface *iface;
712 iface = netdev_priv(dev);
713 local = iface->local;
715 memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN);
717 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) {
718 struct hfa384x_scan_request scan_req;
719 memset(&scan_req, 0, sizeof(scan_req));
720 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
721 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
722 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST,
723 &scan_req, sizeof(scan_req))) {
724 printk(KERN_DEBUG "%s: ScanResults request failed - "
725 "preferred AP delayed to next unsolicited "
726 "scan\n", dev->name);
728 } else if (local->host_roaming == 2 &&
729 local->iw_mode == IW_MODE_INFRA) {
730 if (hostap_join_ap(dev))
733 printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only "
734 "in Managed mode when host_roaming is enabled\n",
739 #endif /* PRISM2_NO_STATION_MODES */
742 static int prism2_ioctl_giwap(struct net_device *dev,
743 struct iw_request_info *info,
744 struct sockaddr *ap_addr, char *extra)
746 struct hostap_interface *iface;
749 iface = netdev_priv(dev);
750 local = iface->local;
752 ap_addr->sa_family = ARPHRD_ETHER;
753 switch (iface->type) {
754 case HOSTAP_INTERFACE_AP:
755 memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN);
757 case HOSTAP_INTERFACE_STA:
758 memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN);
760 case HOSTAP_INTERFACE_WDS:
761 memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN);
764 if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID,
765 &ap_addr->sa_data, ETH_ALEN, 1) < 0)
768 /* local->bssid is also updated in LinkStatus handler when in
770 memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN);
778 static int prism2_ioctl_siwnickn(struct net_device *dev,
779 struct iw_request_info *info,
780 struct iw_point *data, char *nickname)
782 struct hostap_interface *iface;
785 iface = netdev_priv(dev);
786 local = iface->local;
788 memset(local->name, 0, sizeof(local->name));
789 memcpy(local->name, nickname, data->length);
792 if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) ||
793 local->func->reset_port(dev))
799 static int prism2_ioctl_giwnickn(struct net_device *dev,
800 struct iw_request_info *info,
801 struct iw_point *data, char *nickname)
803 struct hostap_interface *iface;
806 char name[MAX_NAME_LEN + 3];
809 iface = netdev_priv(dev);
810 local = iface->local;
812 len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME,
813 &name, MAX_NAME_LEN + 2, 0);
814 val = __le16_to_cpu(*(u16 *) name);
815 if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN)
818 name[val + 2] = '\0';
819 data->length = val + 1;
820 memcpy(nickname, name + 2, val + 1);
826 static int prism2_ioctl_siwfreq(struct net_device *dev,
827 struct iw_request_info *info,
828 struct iw_freq *freq, char *extra)
830 struct hostap_interface *iface;
833 iface = netdev_priv(dev);
834 local = iface->local;
838 freq->m / 100000 >= freq_list[0] &&
839 freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) {
841 int fr = freq->m / 100000;
842 for (ch = 0; ch < FREQ_COUNT; ch++) {
843 if (fr == freq_list[ch]) {
851 if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT ||
852 !(local->channel_mask & (1 << (freq->m - 1))))
855 local->channel = freq->m; /* channel is used in prism2_setup_rids() */
856 if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) ||
857 local->func->reset_port(dev))
863 static int prism2_ioctl_giwfreq(struct net_device *dev,
864 struct iw_request_info *info,
865 struct iw_freq *freq, char *extra)
867 struct hostap_interface *iface;
871 iface = netdev_priv(dev);
872 local = iface->local;
874 if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) <
879 if (val < 1 || val > FREQ_COUNT)
882 freq->m = freq_list[val - 1] * 100000;
889 static void hostap_monitor_set_type(local_info_t *local)
891 struct net_device *dev = local->ddev;
896 if (local->monitor_type == PRISM2_MONITOR_PRISM ||
897 local->monitor_type == PRISM2_MONITOR_CAPHDR) {
898 dev->type = ARPHRD_IEEE80211_PRISM;
899 dev->hard_header_parse =
900 hostap_80211_prism_header_parse;
902 dev->type = ARPHRD_IEEE80211;
903 dev->hard_header_parse = hostap_80211_header_parse;
908 static int prism2_ioctl_siwessid(struct net_device *dev,
909 struct iw_request_info *info,
910 struct iw_point *data, char *ssid)
912 struct hostap_interface *iface;
915 iface = netdev_priv(dev);
916 local = iface->local;
918 if (iface->type == HOSTAP_INTERFACE_WDS)
921 if (data->flags == 0)
922 ssid[0] = '\0'; /* ANY */
924 if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') {
925 /* Setting SSID to empty string seems to kill the card in
927 printk(KERN_DEBUG "%s: Host AP mode does not support "
928 "'Any' essid\n", dev->name);
932 memcpy(local->essid, ssid, data->length);
933 local->essid[data->length] = '\0';
935 if ((!local->fw_ap &&
936 hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid))
937 || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) ||
938 local->func->reset_port(dev))
944 static int prism2_ioctl_giwessid(struct net_device *dev,
945 struct iw_request_info *info,
946 struct iw_point *data, char *essid)
948 struct hostap_interface *iface;
952 iface = netdev_priv(dev);
953 local = iface->local;
955 if (iface->type == HOSTAP_INTERFACE_WDS)
958 data->flags = 1; /* active */
959 if (local->iw_mode == IW_MODE_MASTER) {
960 data->length = strlen(local->essid);
961 memcpy(essid, local->essid, IW_ESSID_MAX_SIZE);
964 char ssid[MAX_SSID_LEN + 2];
965 memset(ssid, 0, sizeof(ssid));
966 len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID,
967 &ssid, MAX_SSID_LEN + 2, 0);
968 val = __le16_to_cpu(*(u16 *) ssid);
969 if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) {
973 memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE);
980 static int prism2_ioctl_giwrange(struct net_device *dev,
981 struct iw_request_info *info,
982 struct iw_point *data, char *extra)
984 struct hostap_interface *iface;
986 struct iw_range *range = (struct iw_range *) extra;
991 iface = netdev_priv(dev);
992 local = iface->local;
994 data->length = sizeof(struct iw_range);
995 memset(range, 0, sizeof(struct iw_range));
997 /* TODO: could fill num_txpower and txpower array with
998 * something; however, there are 128 different values.. */
1000 range->txpower_capa = IW_TXPOW_DBM;
1002 if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC)
1004 range->min_pmp = 1 * 1024;
1005 range->max_pmp = 65535 * 1024;
1006 range->min_pmt = 1 * 1024;
1007 range->max_pmt = 1000 * 1024;
1008 range->pmp_flags = IW_POWER_PERIOD;
1009 range->pmt_flags = IW_POWER_TIMEOUT;
1010 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
1011 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
1014 range->we_version_compiled = WIRELESS_EXT;
1015 range->we_version_source = 18;
1017 range->retry_capa = IW_RETRY_LIMIT;
1018 range->retry_flags = IW_RETRY_LIMIT;
1019 range->min_retry = 0;
1020 range->max_retry = 255;
1022 range->num_channels = FREQ_COUNT;
1025 for (i = 0; i < FREQ_COUNT; i++) {
1026 if (local->channel_mask & (1 << i)) {
1027 range->freq[val].i = i + 1;
1028 range->freq[val].m = freq_list[i] * 100000;
1029 range->freq[val].e = 1;
1032 if (val == IW_MAX_FREQUENCIES)
1035 range->num_frequency = val;
1037 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1038 range->max_qual.qual = 70; /* what is correct max? This was not
1039 * documented exactly. At least
1040 * 69 has been observed. */
1041 range->max_qual.level = 0; /* dB */
1042 range->max_qual.noise = 0; /* dB */
1044 /* What would be suitable values for "average/typical" qual? */
1045 range->avg_qual.qual = 20;
1046 range->avg_qual.level = -60;
1047 range->avg_qual.noise = -95;
1049 range->max_qual.qual = 92; /* 0 .. 92 */
1050 range->max_qual.level = 154; /* 27 .. 154 */
1051 range->max_qual.noise = 154; /* 27 .. 154 */
1053 range->sensitivity = 3;
1055 range->max_encoding_tokens = WEP_KEYS;
1056 range->num_encoding_sizes = 2;
1057 range->encoding_size[0] = 5;
1058 range->encoding_size[1] = 13;
1061 len = prism2_get_datarates(dev, rates);
1062 range->num_bitrates = 0;
1063 for (i = 0; i < len; i++) {
1064 if (range->num_bitrates < IW_MAX_BITRATES) {
1065 range->bitrate[range->num_bitrates] =
1067 range->num_bitrates++;
1069 if (rates[i] == 0x0b || rates[i] == 0x16)
1072 /* estimated maximum TCP throughput values (bps) */
1073 range->throughput = over2 ? 5500000 : 1500000;
1076 range->max_rts = 2347;
1077 range->min_frag = 256;
1078 range->max_frag = 2346;
1080 /* Event capability (kernel + driver) */
1081 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1082 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
1083 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1084 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1085 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1086 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
1087 IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1088 IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
1089 IW_EVENT_CAPA_MASK(IWEVEXPIRED));
1091 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1092 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1098 static int hostap_monitor_mode_enable(local_info_t *local)
1100 struct net_device *dev = local->dev;
1102 printk(KERN_DEBUG "Enabling monitor mode\n");
1103 hostap_monitor_set_type(local);
1105 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1106 HFA384X_PORTTYPE_PSEUDO_IBSS)) {
1107 printk(KERN_DEBUG "Port type setting for monitor mode "
1112 /* Host decrypt is needed to get the IV and ICV fields;
1113 * however, monitor mode seems to remove WEP flag from frame
1115 if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS,
1116 HFA384X_WEPFLAGS_HOSTENCRYPT |
1117 HFA384X_WEPFLAGS_HOSTDECRYPT)) {
1118 printk(KERN_DEBUG "WEP flags setting failed\n");
1122 if (local->func->reset_port(dev) ||
1123 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1124 (HFA384X_TEST_MONITOR << 8),
1126 printk(KERN_DEBUG "Setting monitor mode failed\n");
1134 static int hostap_monitor_mode_disable(local_info_t *local)
1136 struct net_device *dev = local->ddev;
1141 printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name);
1142 dev->type = ARPHRD_ETHER;
1143 dev->hard_header_parse = local->saved_eth_header_parse;
1144 if (local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1145 (HFA384X_TEST_STOP << 8),
1148 return hostap_set_encryption(local);
1152 static int prism2_ioctl_siwmode(struct net_device *dev,
1153 struct iw_request_info *info,
1154 __u32 *mode, char *extra)
1156 struct hostap_interface *iface;
1157 local_info_t *local;
1158 int double_reset = 0;
1160 iface = netdev_priv(dev);
1161 local = iface->local;
1163 if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA &&
1164 *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT &&
1165 *mode != IW_MODE_MONITOR)
1168 #ifdef PRISM2_NO_STATION_MODES
1169 if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA)
1171 #endif /* PRISM2_NO_STATION_MODES */
1173 if (*mode == local->iw_mode)
1176 if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') {
1177 printk(KERN_WARNING "%s: empty SSID not allowed in Master "
1178 "mode\n", dev->name);
1182 if (local->iw_mode == IW_MODE_MONITOR)
1183 hostap_monitor_mode_disable(local);
1185 if ((local->iw_mode == IW_MODE_ADHOC ||
1186 local->iw_mode == IW_MODE_MONITOR) && *mode == IW_MODE_MASTER) {
1187 /* There seems to be a firmware bug in at least STA f/w v1.5.6
1188 * that leaves beacon frames to use IBSS type when moving from
1189 * IBSS to Host AP mode. Doing double Port0 reset seems to be
1190 * enough to workaround this. */
1194 printk(KERN_DEBUG "prism2: %s: operating mode changed "
1195 "%d -> %d\n", dev->name, local->iw_mode, *mode);
1196 local->iw_mode = *mode;
1198 if (local->iw_mode == IW_MODE_MONITOR)
1199 hostap_monitor_mode_enable(local);
1200 else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
1201 !local->fw_encrypt_ok) {
1202 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
1203 "a workaround for firmware bug in Host AP mode WEP\n",
1205 local->host_encrypt = 1;
1208 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1209 hostap_get_porttype(local)))
1212 if (local->func->reset_port(dev))
1214 if (double_reset && local->func->reset_port(dev))
1217 if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
1219 /* netif_carrier is used only in client modes for now, so make
1220 * sure carrier is on when moving to non-client modes. */
1221 netif_carrier_on(local->dev);
1222 netif_carrier_on(local->ddev);
1228 static int prism2_ioctl_giwmode(struct net_device *dev,
1229 struct iw_request_info *info,
1230 __u32 *mode, char *extra)
1232 struct hostap_interface *iface;
1233 local_info_t *local;
1235 iface = netdev_priv(dev);
1236 local = iface->local;
1238 switch (iface->type) {
1239 case HOSTAP_INTERFACE_STA:
1240 *mode = IW_MODE_INFRA;
1242 case HOSTAP_INTERFACE_WDS:
1243 *mode = IW_MODE_REPEAT;
1246 *mode = local->iw_mode;
1253 static int prism2_ioctl_siwpower(struct net_device *dev,
1254 struct iw_request_info *info,
1255 struct iw_param *wrq, char *extra)
1257 #ifdef PRISM2_NO_STATION_MODES
1259 #else /* PRISM2_NO_STATION_MODES */
1263 return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
1265 switch (wrq->flags & IW_POWER_MODE) {
1266 case IW_POWER_UNICAST_R:
1267 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
1270 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1274 case IW_POWER_ALL_R:
1275 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
1278 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1288 if (wrq->flags & IW_POWER_TIMEOUT) {
1289 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1292 ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
1297 if (wrq->flags & IW_POWER_PERIOD) {
1298 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1301 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1308 #endif /* PRISM2_NO_STATION_MODES */
1312 static int prism2_ioctl_giwpower(struct net_device *dev,
1313 struct iw_request_info *info,
1314 struct iw_param *rrq, char *extra)
1316 #ifdef PRISM2_NO_STATION_MODES
1318 #else /* PRISM2_NO_STATION_MODES */
1319 struct hostap_interface *iface;
1320 local_info_t *local;
1323 iface = netdev_priv(dev);
1324 local = iface->local;
1326 if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
1330 if (!__le16_to_cpu(enable)) {
1337 if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1339 if (local->func->get_rid(dev,
1340 HFA384X_RID_CNFPMHOLDOVERDURATION,
1341 &timeout, 2, 1) < 0)
1344 rrq->flags = IW_POWER_TIMEOUT;
1345 rrq->value = __le16_to_cpu(timeout) * 1024;
1348 if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1352 rrq->flags = IW_POWER_PERIOD;
1353 rrq->value = __le16_to_cpu(period) * 1024;
1356 if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
1360 if (__le16_to_cpu(mcast))
1361 rrq->flags |= IW_POWER_ALL_R;
1363 rrq->flags |= IW_POWER_UNICAST_R;
1366 #endif /* PRISM2_NO_STATION_MODES */
1370 static int prism2_ioctl_siwretry(struct net_device *dev,
1371 struct iw_request_info *info,
1372 struct iw_param *rrq, char *extra)
1374 struct hostap_interface *iface;
1375 local_info_t *local;
1377 iface = netdev_priv(dev);
1378 local = iface->local;
1383 /* setting retry limits is not supported with the current station
1384 * firmware code; simulate this with alternative retry count for now */
1385 if (rrq->flags == IW_RETRY_LIMIT) {
1386 if (rrq->value < 0) {
1387 /* disable manual retry count setting and use firmware
1389 local->manual_retry_count = -1;
1390 local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
1392 if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1394 printk(KERN_DEBUG "%s: Alternate retry count "
1395 "setting to %d failed\n",
1396 dev->name, rrq->value);
1400 local->manual_retry_count = rrq->value;
1401 local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
1409 /* what could be done, if firmware would support this.. */
1411 if (rrq->flags & IW_RETRY_LIMIT) {
1412 if (rrq->flags & IW_RETRY_LONG)
1413 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1414 else if (rrq->flags & IW_RETRY_SHORT)
1415 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1417 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1418 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1423 if (rrq->flags & IW_RETRY_LIFETIME) {
1424 HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
1431 static int prism2_ioctl_giwretry(struct net_device *dev,
1432 struct iw_request_info *info,
1433 struct iw_param *rrq, char *extra)
1435 struct hostap_interface *iface;
1436 local_info_t *local;
1437 u16 shortretry, longretry, lifetime, altretry;
1439 iface = netdev_priv(dev);
1440 local = iface->local;
1442 if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
1444 local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
1446 local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
1447 &lifetime, 2, 1) < 0)
1450 le16_to_cpus(&shortretry);
1451 le16_to_cpus(&longretry);
1452 le16_to_cpus(&lifetime);
1456 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1457 rrq->flags = IW_RETRY_LIFETIME;
1458 rrq->value = lifetime * 1024;
1460 if (local->manual_retry_count >= 0) {
1461 rrq->flags = IW_RETRY_LIMIT;
1462 if (local->func->get_rid(dev,
1463 HFA384X_RID_CNFALTRETRYCOUNT,
1464 &altretry, 2, 1) >= 0)
1465 rrq->value = le16_to_cpu(altretry);
1467 rrq->value = local->manual_retry_count;
1468 } else if ((rrq->flags & IW_RETRY_LONG)) {
1469 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1470 rrq->value = longretry;
1472 rrq->flags = IW_RETRY_LIMIT;
1473 rrq->value = shortretry;
1474 if (shortretry != longretry)
1475 rrq->flags |= IW_RETRY_SHORT;
1482 /* Note! This TX power controlling is experimental and should not be used in
1483 * production use. It just sets raw power register and does not use any kind of
1484 * feedback information from the measured TX power (CR58). This is now
1485 * commented out to make sure that it is not used by accident. TX power
1486 * configuration will be enabled again after proper algorithm using feedback
1487 * has been implemented. */
1489 #ifdef RAW_TXPOWER_SETTING
1490 /* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
1491 * This version assumes following mapping:
1492 * CR31 is 7-bit value with -64 to +63 range.
1493 * -64 is mapped into +20dBm and +63 into -43dBm.
1494 * This is certainly not an exact mapping for every card, but at least
1495 * increasing dBm value should correspond to increasing TX power.
1498 static int prism2_txpower_hfa386x_to_dBm(u16 val)
1511 static u16 prism2_txpower_dBm_to_hfa386x(int val)
1524 return (unsigned char) tmp;
1526 #endif /* RAW_TXPOWER_SETTING */
1529 static int prism2_ioctl_siwtxpow(struct net_device *dev,
1530 struct iw_request_info *info,
1531 struct iw_param *rrq, char *extra)
1533 struct hostap_interface *iface;
1534 local_info_t *local;
1535 #ifdef RAW_TXPOWER_SETTING
1541 iface = netdev_priv(dev);
1542 local = iface->local;
1544 if (rrq->disabled) {
1545 if (local->txpower_type != PRISM2_TXPOWER_OFF) {
1546 val = 0xff; /* use all standby and sleep modes */
1547 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1548 HFA386X_CR_A_D_TEST_MODES2,
1550 printk(KERN_DEBUG "%s: Turning radio off: %s\n",
1551 dev->name, ret ? "failed" : "OK");
1552 local->txpower_type = PRISM2_TXPOWER_OFF;
1554 return (ret ? -EOPNOTSUPP : 0);
1557 if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1558 val = 0; /* disable all standby and sleep modes */
1559 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1560 HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
1561 printk(KERN_DEBUG "%s: Turning radio on: %s\n",
1562 dev->name, ret ? "failed" : "OK");
1563 local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
1566 #ifdef RAW_TXPOWER_SETTING
1567 if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
1568 printk(KERN_DEBUG "Setting ALC on\n");
1569 val = HFA384X_TEST_CFG_BIT_ALC;
1570 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1571 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
1572 local->txpower_type = PRISM2_TXPOWER_AUTO;
1576 if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
1577 printk(KERN_DEBUG "Setting ALC off\n");
1578 val = HFA384X_TEST_CFG_BIT_ALC;
1579 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1580 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
1581 local->txpower_type = PRISM2_TXPOWER_FIXED;
1584 if (rrq->flags == IW_TXPOW_DBM)
1586 else if (rrq->flags == IW_TXPOW_MWATT)
1590 printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
1592 if (rrq->flags != IW_TXPOW_DBM) {
1593 printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
1597 local->txpower = rrq->value;
1598 val = prism2_txpower_dBm_to_hfa386x(local->txpower);
1599 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1600 HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
1602 #else /* RAW_TXPOWER_SETTING */
1605 #endif /* RAW_TXPOWER_SETTING */
1610 static int prism2_ioctl_giwtxpow(struct net_device *dev,
1611 struct iw_request_info *info,
1612 struct iw_param *rrq, char *extra)
1614 #ifdef RAW_TXPOWER_SETTING
1615 struct hostap_interface *iface;
1616 local_info_t *local;
1619 iface = netdev_priv(dev);
1620 local = iface->local;
1622 rrq->flags = IW_TXPOW_DBM;
1626 if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
1627 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
1628 HFA386X_CR_MANUAL_TX_POWER,
1629 NULL, &resp0) == 0) {
1630 rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
1632 /* Could not get real txpower; guess 15 dBm */
1635 } else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1638 } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
1639 rrq->value = local->txpower;
1642 printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
1643 local->txpower_type);
1646 #else /* RAW_TXPOWER_SETTING */
1648 #endif /* RAW_TXPOWER_SETTING */
1652 #ifndef PRISM2_NO_STATION_MODES
1654 /* HostScan request works with and without host_roaming mode. In addition, it
1655 * does not break current association. However, it requires newer station
1656 * firmware version (>= 1.3.1) than scan request. */
1657 static int prism2_request_hostscan(struct net_device *dev,
1658 u8 *ssid, u8 ssid_len)
1660 struct hostap_interface *iface;
1661 local_info_t *local;
1662 struct hfa384x_hostscan_request scan_req;
1664 iface = netdev_priv(dev);
1665 local = iface->local;
1667 memset(&scan_req, 0, sizeof(scan_req));
1668 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1669 local->scan_channel_mask);
1670 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1674 scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1675 memcpy(scan_req.target_ssid, ssid, ssid_len);
1678 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1679 sizeof(scan_req))) {
1680 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1687 static int prism2_request_scan(struct net_device *dev)
1689 struct hostap_interface *iface;
1690 local_info_t *local;
1691 struct hfa384x_scan_request scan_req;
1694 iface = netdev_priv(dev);
1695 local = iface->local;
1697 memset(&scan_req, 0, sizeof(scan_req));
1698 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1699 local->scan_channel_mask);
1700 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1703 * It seems to be enough to set roaming mode for a short moment to
1704 * host-based and then setup scanrequest data and return the mode to
1707 * Master mode would need to drop to Managed mode for a short while
1708 * to make scanning work.. Or sweep through the different channels and
1709 * use passive scan based on beacons. */
1711 if (!local->host_roaming)
1712 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1713 HFA384X_ROAMING_HOST);
1715 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1716 sizeof(scan_req))) {
1717 printk(KERN_DEBUG "SCANREQUEST failed\n");
1721 if (!local->host_roaming)
1722 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1723 HFA384X_ROAMING_FIRMWARE);
1728 #else /* !PRISM2_NO_STATION_MODES */
1730 static inline int prism2_request_hostscan(struct net_device *dev,
1731 u8 *ssid, u8 ssid_len)
1737 static inline int prism2_request_scan(struct net_device *dev)
1742 #endif /* !PRISM2_NO_STATION_MODES */
1745 static int prism2_ioctl_siwscan(struct net_device *dev,
1746 struct iw_request_info *info,
1747 struct iw_point *data, char *extra)
1749 struct hostap_interface *iface;
1750 local_info_t *local;
1752 u8 *ssid = NULL, ssid_len = 0;
1753 struct iw_scan_req *req = (struct iw_scan_req *) extra;
1755 iface = netdev_priv(dev);
1756 local = iface->local;
1758 if (data->length < sizeof(struct iw_scan_req))
1761 if (local->iw_mode == IW_MODE_MASTER) {
1762 /* In master mode, we just return the results of our local
1763 * tables, so we don't need to start anything...
1769 if (!local->dev_enabled)
1772 if (req && data->flags & IW_SCAN_THIS_ESSID) {
1774 ssid_len = req->essid_len;
1777 ((local->iw_mode != IW_MODE_INFRA &&
1778 local->iw_mode != IW_MODE_ADHOC) ||
1779 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1783 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1784 ret = prism2_request_hostscan(dev, ssid, ssid_len);
1786 ret = prism2_request_scan(dev);
1789 local->scan_timestamp = jiffies;
1791 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1797 #ifndef PRISM2_NO_STATION_MODES
1798 static char * __prism2_translate_scan(local_info_t *local,
1799 struct hfa384x_hostscan_result *scan,
1800 struct hostap_bss_info *bss,
1801 char *current_ev, char *end_buf)
1804 struct iw_event iwe;
1814 ssid_len = bss->ssid_len;
1818 ssid_len = le16_to_cpu(scan->ssid_len);
1819 bssid = scan->bssid;
1824 /* First entry *MUST* be the AP MAC address */
1825 memset(&iwe, 0, sizeof(iwe));
1826 iwe.cmd = SIOCGIWAP;
1827 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1828 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1829 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1832 /* Other entries will be displayed in the order we give them */
1834 memset(&iwe, 0, sizeof(iwe));
1835 iwe.cmd = SIOCGIWESSID;
1836 iwe.u.data.length = ssid_len;
1837 iwe.u.data.flags = 1;
1838 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid);
1840 memset(&iwe, 0, sizeof(iwe));
1841 iwe.cmd = SIOCGIWMODE;
1843 capabilities = bss->capab_info;
1845 capabilities = le16_to_cpu(scan->capability);
1847 if (capabilities & (WLAN_CAPABILITY_ESS |
1848 WLAN_CAPABILITY_IBSS)) {
1849 if (capabilities & WLAN_CAPABILITY_ESS)
1850 iwe.u.mode = IW_MODE_MASTER;
1852 iwe.u.mode = IW_MODE_ADHOC;
1853 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1857 memset(&iwe, 0, sizeof(iwe));
1858 iwe.cmd = SIOCGIWFREQ;
1860 chan = le16_to_cpu(scan->chid);
1868 iwe.u.freq.m = freq_list[chan - 1] * 100000;
1870 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1875 memset(&iwe, 0, sizeof(iwe));
1877 if (local->last_scan_type == PRISM2_HOSTSCAN) {
1878 iwe.u.qual.level = le16_to_cpu(scan->sl);
1879 iwe.u.qual.noise = le16_to_cpu(scan->anl);
1882 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1884 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1886 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
1887 | IW_QUAL_NOISE_UPDATED
1888 | IW_QUAL_QUAL_INVALID
1890 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1894 memset(&iwe, 0, sizeof(iwe));
1895 iwe.cmd = SIOCGIWENCODE;
1896 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1897 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1899 iwe.u.data.flags = IW_ENCODE_DISABLED;
1900 iwe.u.data.length = 0;
1901 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
1903 /* TODO: add SuppRates into BSS table */
1905 memset(&iwe, 0, sizeof(iwe));
1906 iwe.cmd = SIOCGIWRATE;
1907 current_val = current_ev + IW_EV_LCP_LEN;
1908 pos = scan->sup_rates;
1909 for (i = 0; i < sizeof(scan->sup_rates); i++) {
1912 /* Bit rate given in 500 kb/s units (+ 0x80) */
1913 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1914 current_val = iwe_stream_add_value(
1915 current_ev, current_val, end_buf, &iwe,
1918 /* Check if we added any event */
1919 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1920 current_ev = current_val;
1923 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1924 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_ATOMIC);
1926 memset(&iwe, 0, sizeof(iwe));
1927 iwe.cmd = IWEVCUSTOM;
1928 sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval));
1929 iwe.u.data.length = strlen(buf);
1930 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1933 memset(&iwe, 0, sizeof(iwe));
1934 iwe.cmd = IWEVCUSTOM;
1935 sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate));
1936 iwe.u.data.length = strlen(buf);
1937 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1940 if (local->last_scan_type == PRISM2_HOSTSCAN &&
1941 (capabilities & WLAN_CAPABILITY_IBSS)) {
1942 memset(&iwe, 0, sizeof(iwe));
1943 iwe.cmd = IWEVCUSTOM;
1944 sprintf(buf, "atim=%d", le16_to_cpu(scan->atim));
1945 iwe.u.data.length = strlen(buf);
1946 current_ev = iwe_stream_add_point(current_ev, end_buf,
1952 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1953 memset(&iwe, 0, sizeof(iwe));
1954 iwe.cmd = IWEVGENIE;
1955 iwe.u.data.length = bss->wpa_ie_len;
1956 current_ev = iwe_stream_add_point(
1957 current_ev, end_buf, &iwe, bss->wpa_ie);
1960 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1961 memset(&iwe, 0, sizeof(iwe));
1962 iwe.cmd = IWEVGENIE;
1963 iwe.u.data.length = bss->rsn_ie_len;
1964 current_ev = iwe_stream_add_point(
1965 current_ev, end_buf, &iwe, bss->rsn_ie);
1972 /* Translate scan data returned from the card to a card independant
1973 * format that the Wireless Tools will understand - Jean II */
1974 static inline int prism2_translate_scan(local_info_t *local,
1975 char *buffer, int buflen)
1977 struct hfa384x_hostscan_result *scan;
1978 int entry, hostscan;
1979 char *current_ev = buffer;
1980 char *end_buf = buffer + buflen;
1981 struct list_head *ptr;
1983 spin_lock_bh(&local->lock);
1985 list_for_each(ptr, &local->bss_list) {
1986 struct hostap_bss_info *bss;
1987 bss = list_entry(ptr, struct hostap_bss_info, list);
1991 hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
1992 for (entry = 0; entry < local->last_scan_results_count; entry++) {
1994 scan = &local->last_scan_results[entry];
1996 /* Report every SSID if the AP is using multiple SSIDs. If no
1997 * BSS record is found (e.g., when WPA mode is disabled),
1998 * report the AP once. */
1999 list_for_each(ptr, &local->bss_list) {
2000 struct hostap_bss_info *bss;
2001 bss = list_entry(ptr, struct hostap_bss_info, list);
2002 if (memcmp(bss->bssid, scan->bssid, ETH_ALEN) == 0) {
2004 current_ev = __prism2_translate_scan(
2005 local, scan, bss, current_ev, end_buf);
2010 current_ev = __prism2_translate_scan(
2011 local, scan, NULL, current_ev, end_buf);
2013 /* Check if there is space for one more entry */
2014 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2015 /* Ask user space to try again with a bigger buffer */
2016 spin_unlock_bh(&local->lock);
2021 /* Prism2 firmware has limits (32 at least in some versions) for number
2022 * of BSSes in scan results. Extend this limit by using local BSS list.
2024 list_for_each(ptr, &local->bss_list) {
2025 struct hostap_bss_info *bss;
2026 bss = list_entry(ptr, struct hostap_bss_info, list);
2029 current_ev = __prism2_translate_scan(local, NULL, bss,
2030 current_ev, end_buf);
2031 /* Check if there is space for one more entry */
2032 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2033 /* Ask user space to try again with a bigger buffer */
2034 spin_unlock_bh(&local->lock);
2039 spin_unlock_bh(&local->lock);
2041 return current_ev - buffer;
2043 #endif /* PRISM2_NO_STATION_MODES */
2046 static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2047 struct iw_request_info *info,
2048 struct iw_point *data, char *extra)
2050 #ifdef PRISM2_NO_STATION_MODES
2052 #else /* PRISM2_NO_STATION_MODES */
2053 struct hostap_interface *iface;
2054 local_info_t *local;
2057 iface = netdev_priv(dev);
2058 local = iface->local;
2060 /* Wait until the scan is finished. We can probably do better
2061 * than that - Jean II */
2062 if (local->scan_timestamp &&
2063 time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2064 /* Important note : we don't want to block the caller
2065 * until results are ready for various reasons.
2066 * First, managing wait queues is complex and racy
2067 * (there may be multiple simultaneous callers).
2068 * Second, we grab some rtnetlink lock before comming
2069 * here (in dev_ioctl()).
2070 * Third, the caller can wait on the Wireless Event
2074 local->scan_timestamp = 0;
2076 res = prism2_translate_scan(local, extra, data->length);
2085 #endif /* PRISM2_NO_STATION_MODES */
2089 static int prism2_ioctl_giwscan(struct net_device *dev,
2090 struct iw_request_info *info,
2091 struct iw_point *data, char *extra)
2093 struct hostap_interface *iface;
2094 local_info_t *local;
2097 iface = netdev_priv(dev);
2098 local = iface->local;
2100 if (local->iw_mode == IW_MODE_MASTER) {
2101 /* In MASTER mode, it doesn't make sense to go around
2102 * scanning the frequencies and make the stations we serve
2103 * wait when what the user is really interested about is the
2104 * list of stations and access points we are talking to.
2105 * So, just extract results from our cache...
2108 /* Translate to WE format */
2109 res = prism2_ap_translate_scan(dev, extra);
2111 printk(KERN_DEBUG "Scan result translation succeeded "
2112 "(length=%d)\n", res);
2117 "Scan result translation failed (res=%d)\n",
2124 return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2129 static const struct iw_priv_args prism2_priv[] = {
2130 { PRISM2_IOCTL_MONITOR,
2131 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2132 { PRISM2_IOCTL_READMIF,
2133 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2134 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2135 { PRISM2_IOCTL_WRITEMIF,
2136 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2137 { PRISM2_IOCTL_RESET,
2138 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2139 { PRISM2_IOCTL_INQUIRE,
2140 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2141 { PRISM2_IOCTL_SET_RID_WORD,
2142 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2143 { PRISM2_IOCTL_MACCMD,
2144 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2145 { PRISM2_IOCTL_WDS_ADD,
2146 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2147 { PRISM2_IOCTL_WDS_DEL,
2148 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2149 { PRISM2_IOCTL_ADDMAC,
2150 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2151 { PRISM2_IOCTL_DELMAC,
2152 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2153 { PRISM2_IOCTL_KICKMAC,
2154 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2155 /* --- raw access to sub-ioctls --- */
2156 { PRISM2_IOCTL_PRISM2_PARAM,
2157 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2158 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2159 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2160 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2161 /* --- sub-ioctls handlers --- */
2162 { PRISM2_IOCTL_PRISM2_PARAM,
2163 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2164 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2165 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2166 /* --- sub-ioctls definitions --- */
2167 { PRISM2_PARAM_TXRATECTRL,
2168 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2169 { PRISM2_PARAM_TXRATECTRL,
2170 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2171 { PRISM2_PARAM_BEACON_INT,
2172 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2173 { PRISM2_PARAM_BEACON_INT,
2174 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2175 #ifndef PRISM2_NO_STATION_MODES
2176 { PRISM2_PARAM_PSEUDO_IBSS,
2177 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2178 { PRISM2_PARAM_PSEUDO_IBSS,
2179 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2180 #endif /* PRISM2_NO_STATION_MODES */
2182 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2184 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2185 { PRISM2_PARAM_DUMP,
2186 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2187 { PRISM2_PARAM_DUMP,
2188 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2189 { PRISM2_PARAM_OTHER_AP_POLICY,
2190 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2191 { PRISM2_PARAM_OTHER_AP_POLICY,
2192 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2193 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2194 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2195 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2196 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2197 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2198 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2199 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2200 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2201 { PRISM2_PARAM_DTIM_PERIOD,
2202 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2203 { PRISM2_PARAM_DTIM_PERIOD,
2204 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2205 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2206 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2207 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2208 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2209 { PRISM2_PARAM_MAX_WDS,
2210 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2211 { PRISM2_PARAM_MAX_WDS,
2212 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2213 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2214 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2215 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2216 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2217 { PRISM2_PARAM_AP_AUTH_ALGS,
2218 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2219 { PRISM2_PARAM_AP_AUTH_ALGS,
2220 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2221 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2222 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2223 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2224 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2225 { PRISM2_PARAM_HOST_ENCRYPT,
2226 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2227 { PRISM2_PARAM_HOST_ENCRYPT,
2228 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2229 { PRISM2_PARAM_HOST_DECRYPT,
2230 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2231 { PRISM2_PARAM_HOST_DECRYPT,
2232 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2233 #ifndef PRISM2_NO_STATION_MODES
2234 { PRISM2_PARAM_HOST_ROAMING,
2235 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2236 { PRISM2_PARAM_HOST_ROAMING,
2237 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2238 #endif /* PRISM2_NO_STATION_MODES */
2239 { PRISM2_PARAM_BCRX_STA_KEY,
2240 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2241 { PRISM2_PARAM_BCRX_STA_KEY,
2242 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2243 { PRISM2_PARAM_IEEE_802_1X,
2244 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2245 { PRISM2_PARAM_IEEE_802_1X,
2246 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2247 { PRISM2_PARAM_ANTSEL_TX,
2248 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2249 { PRISM2_PARAM_ANTSEL_TX,
2250 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2251 { PRISM2_PARAM_ANTSEL_RX,
2252 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2253 { PRISM2_PARAM_ANTSEL_RX,
2254 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2255 { PRISM2_PARAM_MONITOR_TYPE,
2256 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2257 { PRISM2_PARAM_MONITOR_TYPE,
2258 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2259 { PRISM2_PARAM_WDS_TYPE,
2260 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2261 { PRISM2_PARAM_WDS_TYPE,
2262 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2263 { PRISM2_PARAM_HOSTSCAN,
2264 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2265 { PRISM2_PARAM_HOSTSCAN,
2266 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2267 { PRISM2_PARAM_AP_SCAN,
2268 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2269 { PRISM2_PARAM_AP_SCAN,
2270 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2271 { PRISM2_PARAM_ENH_SEC,
2272 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2273 { PRISM2_PARAM_ENH_SEC,
2274 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2275 #ifdef PRISM2_IO_DEBUG
2276 { PRISM2_PARAM_IO_DEBUG,
2277 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2278 { PRISM2_PARAM_IO_DEBUG,
2279 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2280 #endif /* PRISM2_IO_DEBUG */
2281 { PRISM2_PARAM_BASIC_RATES,
2282 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2283 { PRISM2_PARAM_BASIC_RATES,
2284 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2285 { PRISM2_PARAM_OPER_RATES,
2286 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2287 { PRISM2_PARAM_OPER_RATES,
2288 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2289 { PRISM2_PARAM_HOSTAPD,
2290 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2291 { PRISM2_PARAM_HOSTAPD,
2292 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2293 { PRISM2_PARAM_HOSTAPD_STA,
2294 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2295 { PRISM2_PARAM_HOSTAPD_STA,
2296 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2298 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2300 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2301 { PRISM2_PARAM_PRIVACY_INVOKED,
2302 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2303 { PRISM2_PARAM_PRIVACY_INVOKED,
2304 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2305 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2306 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2307 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2308 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2309 { PRISM2_PARAM_DROP_UNENCRYPTED,
2310 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2311 { PRISM2_PARAM_DROP_UNENCRYPTED,
2312 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
2313 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2314 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
2315 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2316 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
2320 static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2322 struct hostap_interface *iface;
2323 local_info_t *local;
2325 iface = netdev_priv(dev);
2326 local = iface->local;
2328 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2335 static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2336 struct iw_request_info *info,
2337 void *wrqu, char *extra)
2339 struct hostap_interface *iface;
2340 local_info_t *local;
2341 int *i = (int *) extra;
2343 int value = *(i + 1);
2347 iface = netdev_priv(dev);
2348 local = iface->local;
2351 case PRISM2_PARAM_TXRATECTRL:
2352 local->fw_tx_rate_control = value;
2355 case PRISM2_PARAM_BEACON_INT:
2356 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2357 local->func->reset_port(dev))
2360 local->beacon_int = value;
2363 #ifndef PRISM2_NO_STATION_MODES
2364 case PRISM2_PARAM_PSEUDO_IBSS:
2365 if (value == local->pseudo_adhoc)
2368 if (value != 0 && value != 1) {
2373 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2374 dev->name, local->pseudo_adhoc, value);
2375 local->pseudo_adhoc = value;
2376 if (local->iw_mode != IW_MODE_ADHOC)
2379 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2380 hostap_get_porttype(local))) {
2385 if (local->func->reset_port(dev))
2388 #endif /* PRISM2_NO_STATION_MODES */
2390 case PRISM2_PARAM_ALC:
2391 printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2392 value == 0 ? "Disabling" : "Enabling");
2393 val = HFA384X_TEST_CFG_BIT_ALC;
2394 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2395 (HFA384X_TEST_CFG_BITS << 8),
2396 value == 0 ? 0 : 1, &val, NULL);
2399 case PRISM2_PARAM_DUMP:
2400 local->frame_dump = value;
2403 case PRISM2_PARAM_OTHER_AP_POLICY:
2404 if (value < 0 || value > 3) {
2408 if (local->ap != NULL)
2409 local->ap->ap_policy = value;
2412 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2413 if (value < 0 || value > 7 * 24 * 60 * 60) {
2417 if (local->ap != NULL)
2418 local->ap->max_inactivity = value * HZ;
2421 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2422 if (local->ap != NULL)
2423 local->ap->bridge_packets = value;
2426 case PRISM2_PARAM_DTIM_PERIOD:
2427 if (value < 0 || value > 65535) {
2431 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2432 || local->func->reset_port(dev))
2435 local->dtim_period = value;
2438 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2439 if (local->ap != NULL)
2440 local->ap->nullfunc_ack = value;
2443 case PRISM2_PARAM_MAX_WDS:
2444 local->wds_max_connections = value;
2447 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2448 if (local->ap != NULL) {
2449 if (!local->ap->autom_ap_wds && value) {
2450 /* add WDS link to all APs in STA table */
2451 hostap_add_wds_links(local);
2453 local->ap->autom_ap_wds = value;
2457 case PRISM2_PARAM_AP_AUTH_ALGS:
2458 local->auth_algs = value;
2459 if (hostap_set_auth_algs(local))
2463 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2464 local->monitor_allow_fcserr = value;
2467 case PRISM2_PARAM_HOST_ENCRYPT:
2468 local->host_encrypt = value;
2469 if (hostap_set_encryption(local) ||
2470 local->func->reset_port(dev))
2474 case PRISM2_PARAM_HOST_DECRYPT:
2475 local->host_decrypt = value;
2476 if (hostap_set_encryption(local) ||
2477 local->func->reset_port(dev))
2481 #ifndef PRISM2_NO_STATION_MODES
2482 case PRISM2_PARAM_HOST_ROAMING:
2483 if (value < 0 || value > 2) {
2487 local->host_roaming = value;
2488 if (hostap_set_roaming(local) || local->func->reset_port(dev))
2491 #endif /* PRISM2_NO_STATION_MODES */
2493 case PRISM2_PARAM_BCRX_STA_KEY:
2494 local->bcrx_sta_key = value;
2497 case PRISM2_PARAM_IEEE_802_1X:
2498 local->ieee_802_1x = value;
2501 case PRISM2_PARAM_ANTSEL_TX:
2502 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2506 local->antsel_tx = value;
2507 hostap_set_antsel(local);
2510 case PRISM2_PARAM_ANTSEL_RX:
2511 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2515 local->antsel_rx = value;
2516 hostap_set_antsel(local);
2519 case PRISM2_PARAM_MONITOR_TYPE:
2520 if (value != PRISM2_MONITOR_80211 &&
2521 value != PRISM2_MONITOR_CAPHDR &&
2522 value != PRISM2_MONITOR_PRISM) {
2526 local->monitor_type = value;
2527 if (local->iw_mode == IW_MODE_MONITOR)
2528 hostap_monitor_set_type(local);
2531 case PRISM2_PARAM_WDS_TYPE:
2532 local->wds_type = value;
2535 case PRISM2_PARAM_HOSTSCAN:
2537 struct hfa384x_hostscan_request scan_req;
2540 memset(&scan_req, 0, sizeof(scan_req));
2541 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
2543 case 1: rate = HFA384X_RATES_1MBPS; break;
2544 case 2: rate = HFA384X_RATES_2MBPS; break;
2545 case 3: rate = HFA384X_RATES_5MBPS; break;
2546 case 4: rate = HFA384X_RATES_11MBPS; break;
2547 default: rate = HFA384X_RATES_1MBPS; break;
2549 scan_req.txrate = cpu_to_le16(rate);
2550 /* leave SSID empty to accept all SSIDs */
2552 if (local->iw_mode == IW_MODE_MASTER) {
2553 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2554 HFA384X_PORTTYPE_BSS) ||
2555 local->func->reset_port(dev))
2556 printk(KERN_DEBUG "Leaving Host AP mode "
2557 "for HostScan failed\n");
2560 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2561 sizeof(scan_req))) {
2562 printk(KERN_DEBUG "HOSTSCAN failed\n");
2565 if (local->iw_mode == IW_MODE_MASTER) {
2566 wait_queue_t __wait;
2567 init_waitqueue_entry(&__wait, current);
2568 add_wait_queue(&local->hostscan_wq, &__wait);
2569 set_current_state(TASK_INTERRUPTIBLE);
2570 schedule_timeout(HZ);
2571 if (signal_pending(current))
2573 set_current_state(TASK_RUNNING);
2574 remove_wait_queue(&local->hostscan_wq, &__wait);
2576 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2577 HFA384X_PORTTYPE_HOSTAP) ||
2578 local->func->reset_port(dev))
2579 printk(KERN_DEBUG "Returning to Host AP mode "
2580 "after HostScan failed\n");
2585 case PRISM2_PARAM_AP_SCAN:
2586 local->passive_scan_interval = value;
2587 if (timer_pending(&local->passive_scan_timer))
2588 del_timer(&local->passive_scan_timer);
2590 local->passive_scan_timer.expires = jiffies +
2591 local->passive_scan_interval * HZ;
2592 add_timer(&local->passive_scan_timer);
2596 case PRISM2_PARAM_ENH_SEC:
2597 if (value < 0 || value > 3) {
2601 local->enh_sec = value;
2602 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2604 local->func->reset_port(dev)) {
2605 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2606 "1.6.3 or newer\n", dev->name);
2611 #ifdef PRISM2_IO_DEBUG
2612 case PRISM2_PARAM_IO_DEBUG:
2613 local->io_debug_enabled = value;
2615 #endif /* PRISM2_IO_DEBUG */
2617 case PRISM2_PARAM_BASIC_RATES:
2618 if ((value & local->tx_rate_control) != value || value == 0) {
2619 printk(KERN_INFO "%s: invalid basic rate set - basic "
2620 "rates must be in supported rate set\n",
2625 local->basic_rates = value;
2626 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2627 local->basic_rates) ||
2628 local->func->reset_port(dev))
2632 case PRISM2_PARAM_OPER_RATES:
2633 local->tx_rate_control = value;
2634 if (hostap_set_rate(dev))
2638 case PRISM2_PARAM_HOSTAPD:
2639 ret = hostap_set_hostapd(local, value, 1);
2642 case PRISM2_PARAM_HOSTAPD_STA:
2643 ret = hostap_set_hostapd_sta(local, value, 1);
2646 case PRISM2_PARAM_WPA:
2648 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2650 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2655 case PRISM2_PARAM_PRIVACY_INVOKED:
2656 local->privacy_invoked = value;
2657 if (hostap_set_encryption(local) ||
2658 local->func->reset_port(dev))
2662 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2663 local->tkip_countermeasures = value;
2666 case PRISM2_PARAM_DROP_UNENCRYPTED:
2667 local->drop_unencrypted = value;
2670 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2671 local->scan_channel_mask = value;
2675 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2685 static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2686 struct iw_request_info *info,
2687 void *wrqu, char *extra)
2689 struct hostap_interface *iface;
2690 local_info_t *local;
2691 int *param = (int *) extra;
2694 iface = netdev_priv(dev);
2695 local = iface->local;
2698 case PRISM2_PARAM_TXRATECTRL:
2699 *param = local->fw_tx_rate_control;
2702 case PRISM2_PARAM_BEACON_INT:
2703 *param = local->beacon_int;
2706 case PRISM2_PARAM_PSEUDO_IBSS:
2707 *param = local->pseudo_adhoc;
2710 case PRISM2_PARAM_ALC:
2711 ret = -EOPNOTSUPP; /* FIX */
2714 case PRISM2_PARAM_DUMP:
2715 *param = local->frame_dump;
2718 case PRISM2_PARAM_OTHER_AP_POLICY:
2719 if (local->ap != NULL)
2720 *param = local->ap->ap_policy;
2725 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2726 if (local->ap != NULL)
2727 *param = local->ap->max_inactivity / HZ;
2732 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2733 if (local->ap != NULL)
2734 *param = local->ap->bridge_packets;
2739 case PRISM2_PARAM_DTIM_PERIOD:
2740 *param = local->dtim_period;
2743 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2744 if (local->ap != NULL)
2745 *param = local->ap->nullfunc_ack;
2750 case PRISM2_PARAM_MAX_WDS:
2751 *param = local->wds_max_connections;
2754 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2755 if (local->ap != NULL)
2756 *param = local->ap->autom_ap_wds;
2761 case PRISM2_PARAM_AP_AUTH_ALGS:
2762 *param = local->auth_algs;
2765 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2766 *param = local->monitor_allow_fcserr;
2769 case PRISM2_PARAM_HOST_ENCRYPT:
2770 *param = local->host_encrypt;
2773 case PRISM2_PARAM_HOST_DECRYPT:
2774 *param = local->host_decrypt;
2777 case PRISM2_PARAM_HOST_ROAMING:
2778 *param = local->host_roaming;
2781 case PRISM2_PARAM_BCRX_STA_KEY:
2782 *param = local->bcrx_sta_key;
2785 case PRISM2_PARAM_IEEE_802_1X:
2786 *param = local->ieee_802_1x;
2789 case PRISM2_PARAM_ANTSEL_TX:
2790 *param = local->antsel_tx;
2793 case PRISM2_PARAM_ANTSEL_RX:
2794 *param = local->antsel_rx;
2797 case PRISM2_PARAM_MONITOR_TYPE:
2798 *param = local->monitor_type;
2801 case PRISM2_PARAM_WDS_TYPE:
2802 *param = local->wds_type;
2805 case PRISM2_PARAM_HOSTSCAN:
2809 case PRISM2_PARAM_AP_SCAN:
2810 *param = local->passive_scan_interval;
2813 case PRISM2_PARAM_ENH_SEC:
2814 *param = local->enh_sec;
2817 #ifdef PRISM2_IO_DEBUG
2818 case PRISM2_PARAM_IO_DEBUG:
2819 *param = local->io_debug_enabled;
2821 #endif /* PRISM2_IO_DEBUG */
2823 case PRISM2_PARAM_BASIC_RATES:
2824 *param = local->basic_rates;
2827 case PRISM2_PARAM_OPER_RATES:
2828 *param = local->tx_rate_control;
2831 case PRISM2_PARAM_HOSTAPD:
2832 *param = local->hostapd;
2835 case PRISM2_PARAM_HOSTAPD_STA:
2836 *param = local->hostapd_sta;
2839 case PRISM2_PARAM_WPA:
2840 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2842 *param = local->wpa;
2845 case PRISM2_PARAM_PRIVACY_INVOKED:
2846 *param = local->privacy_invoked;
2849 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2850 *param = local->tkip_countermeasures;
2853 case PRISM2_PARAM_DROP_UNENCRYPTED:
2854 *param = local->drop_unencrypted;
2857 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2858 *param = local->scan_channel_mask;
2862 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2872 static int prism2_ioctl_priv_readmif(struct net_device *dev,
2873 struct iw_request_info *info,
2874 void *wrqu, char *extra)
2876 struct hostap_interface *iface;
2877 local_info_t *local;
2880 iface = netdev_priv(dev);
2881 local = iface->local;
2883 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2893 static int prism2_ioctl_priv_writemif(struct net_device *dev,
2894 struct iw_request_info *info,
2895 void *wrqu, char *extra)
2897 struct hostap_interface *iface;
2898 local_info_t *local;
2901 iface = netdev_priv(dev);
2902 local = iface->local;
2906 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2913 static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2915 struct hostap_interface *iface;
2916 local_info_t *local;
2920 iface = netdev_priv(dev);
2921 local = iface->local;
2923 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2924 "- update software to use iwconfig mode monitor\n",
2925 dev->name, current->pid, current->comm);
2927 /* Backward compatibility code - this can be removed at some point */
2930 /* Disable monitor mode - old mode was not saved, so go to
2932 mode = IW_MODE_MASTER;
2933 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2934 } else if (*i == 1) {
2935 /* netlink socket mode is not supported anymore since it did
2936 * not separate different devices from each other and was not
2937 * best method for delivering large amount of packets to
2940 } else if (*i == 2 || *i == 3) {
2943 local->monitor_type = PRISM2_MONITOR_80211;
2946 local->monitor_type = PRISM2_MONITOR_PRISM;
2949 mode = IW_MODE_MONITOR;
2950 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2951 hostap_monitor_mode_enable(local);
2959 static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
2961 struct hostap_interface *iface;
2962 local_info_t *local;
2964 iface = netdev_priv(dev);
2965 local = iface->local;
2967 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
2970 /* Disable and enable card */
2971 local->func->hw_shutdown(dev, 1);
2972 local->func->hw_config(dev, 0);
2977 local->func->hw_reset(dev);
2981 /* Disable and enable port 0 */
2982 local->func->reset_port(dev);
2986 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
2987 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
2993 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
2999 printk(KERN_DEBUG "Unknown reset request %d\n", *i);
3007 static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
3010 int value = *(i + 1);
3012 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
3014 if (hostap_set_word(dev, rid, value))
3021 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3022 static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3027 case AP_MAC_CMD_POLICY_OPEN:
3028 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3030 case AP_MAC_CMD_POLICY_ALLOW:
3031 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3033 case AP_MAC_CMD_POLICY_DENY:
3034 local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3036 case AP_MAC_CMD_FLUSH:
3037 ap_control_flush_macs(&local->ap->mac_restrictions);
3039 case AP_MAC_CMD_KICKALL:
3040 ap_control_kickall(local->ap);
3041 hostap_deauth_all_stas(local->dev, local->ap, 0);
3050 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3053 #ifdef PRISM2_DOWNLOAD_SUPPORT
3054 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3056 struct prism2_download_param *param;
3059 if (p->length < sizeof(struct prism2_download_param) ||
3060 p->length > 1024 || !p->pointer)
3063 param = (struct prism2_download_param *)
3064 kmalloc(p->length, GFP_KERNEL);
3068 if (copy_from_user(param, p->pointer, p->length)) {
3073 if (p->length < sizeof(struct prism2_download_param) +
3074 param->num_areas * sizeof(struct prism2_download_area)) {
3079 ret = local->func->download(local, param);
3085 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3088 static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
3091 struct hostap_interface *iface = dev->priv;
3092 local_info_t *local = iface->local;
3096 * Add 16-bit length in the beginning of the buffer because Prism2 RID
3099 buf = kmalloc(len + 2, GFP_KERNEL);
3103 *((u16 *) buf) = cpu_to_le16(len);
3104 memcpy(buf + 2, elem, len);
3106 kfree(local->generic_elem);
3107 local->generic_elem = buf;
3108 local->generic_elem_len = len + 2;
3110 return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
3115 static int prism2_ioctl_siwauth(struct net_device *dev,
3116 struct iw_request_info *info,
3117 struct iw_param *data, char *extra)
3119 struct hostap_interface *iface = dev->priv;
3120 local_info_t *local = iface->local;
3122 switch (data->flags & IW_AUTH_INDEX) {
3123 case IW_AUTH_WPA_VERSION:
3124 case IW_AUTH_CIPHER_PAIRWISE:
3125 case IW_AUTH_CIPHER_GROUP:
3126 case IW_AUTH_KEY_MGMT:
3128 * Host AP driver does not use these parameters and allows
3129 * wpa_supplicant to control them internally.
3132 case IW_AUTH_TKIP_COUNTERMEASURES:
3133 local->tkip_countermeasures = data->value;
3135 case IW_AUTH_DROP_UNENCRYPTED:
3136 local->drop_unencrypted = data->value;
3138 case IW_AUTH_80211_AUTH_ALG:
3139 local->auth_algs = data->value;
3141 case IW_AUTH_WPA_ENABLED:
3142 if (data->value == 0) {
3144 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3146 prism2_set_genericelement(dev, "", 0);
3147 local->host_roaming = 0;
3148 local->privacy_invoked = 0;
3149 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
3151 hostap_set_roaming(local) ||
3152 hostap_set_encryption(local) ||
3153 local->func->reset_port(dev))
3157 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3159 local->host_roaming = 2;
3160 local->privacy_invoked = 1;
3162 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
3163 hostap_set_roaming(local) ||
3164 hostap_set_encryption(local) ||
3165 local->func->reset_port(dev))
3168 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3169 local->ieee_802_1x = data->value;
3171 case IW_AUTH_PRIVACY_INVOKED:
3172 local->privacy_invoked = data->value;
3181 static int prism2_ioctl_giwauth(struct net_device *dev,
3182 struct iw_request_info *info,
3183 struct iw_param *data, char *extra)
3185 struct hostap_interface *iface = dev->priv;
3186 local_info_t *local = iface->local;
3188 switch (data->flags & IW_AUTH_INDEX) {
3189 case IW_AUTH_WPA_VERSION:
3190 case IW_AUTH_CIPHER_PAIRWISE:
3191 case IW_AUTH_CIPHER_GROUP:
3192 case IW_AUTH_KEY_MGMT:
3194 * Host AP driver does not use these parameters and allows
3195 * wpa_supplicant to control them internally.
3198 case IW_AUTH_TKIP_COUNTERMEASURES:
3199 data->value = local->tkip_countermeasures;
3201 case IW_AUTH_DROP_UNENCRYPTED:
3202 data->value = local->drop_unencrypted;
3204 case IW_AUTH_80211_AUTH_ALG:
3205 data->value = local->auth_algs;
3207 case IW_AUTH_WPA_ENABLED:
3208 data->value = local->wpa;
3210 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3211 data->value = local->ieee_802_1x;
3220 static int prism2_ioctl_siwencodeext(struct net_device *dev,
3221 struct iw_request_info *info,
3222 struct iw_point *erq, char *extra)
3224 struct hostap_interface *iface = dev->priv;
3225 local_info_t *local = iface->local;
3226 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3228 struct ieee80211_crypto_ops *ops;
3229 struct ieee80211_crypt_data **crypt;
3232 const char *alg, *module;
3234 i = erq->flags & IW_ENCODE_INDEX;
3237 if (i < 1 || i > WEP_KEYS)
3238 i = local->tx_keyidx;
3241 if (i < 0 || i >= WEP_KEYS)
3244 addr = ext->addr.sa_data;
3245 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3246 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3248 crypt = &local->crypt[i];
3252 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3253 if (sta_ptr == NULL) {
3254 if (local->iw_mode == IW_MODE_INFRA) {
3256 * TODO: add STA entry for the current AP so
3257 * that unicast key can be used. For now, this
3258 * is emulated by using default key idx 0.
3261 crypt = &local->crypt[i];
3267 if ((erq->flags & IW_ENCODE_DISABLED) ||
3268 ext->alg == IW_ENCODE_ALG_NONE) {
3270 prism2_crypt_delayed_deinit(local, crypt);
3275 case IW_ENCODE_ALG_WEP:
3277 module = "ieee80211_crypt_wep";
3279 case IW_ENCODE_ALG_TKIP:
3281 module = "ieee80211_crypt_tkip";
3283 case IW_ENCODE_ALG_CCMP:
3285 module = "ieee80211_crypt_ccmp";
3288 printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
3289 local->dev->name, ext->alg);
3294 ops = ieee80211_get_crypto_ops(alg);
3296 request_module(module);
3297 ops = ieee80211_get_crypto_ops(alg);
3300 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3301 local->dev->name, alg);
3306 if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
3308 * Per station encryption and other than WEP algorithms
3309 * require host-based encryption, so force them on
3312 local->host_decrypt = local->host_encrypt = 1;
3315 if (*crypt == NULL || (*crypt)->ops != ops) {
3316 struct ieee80211_crypt_data *new_crypt;
3318 prism2_crypt_delayed_deinit(local, crypt);
3320 new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
3322 if (new_crypt == NULL) {
3326 new_crypt->ops = ops;
3327 new_crypt->priv = new_crypt->ops->init(i);
3328 if (new_crypt->priv == NULL) {
3338 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
3339 * existing seq# should not be changed.
3340 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
3341 * should be changed to something else than zero.
3343 if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
3344 && (*crypt)->ops->set_key &&
3345 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
3346 (*crypt)->priv) < 0) {
3347 printk(KERN_DEBUG "%s: key setting failed\n",
3353 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3355 local->tx_keyidx = i;
3359 if (sta_ptr == NULL && ext->key_len > 0) {
3361 for (j = 0; j < WEP_KEYS; j++) {
3362 if (j != i && local->crypt[j]) {
3368 local->tx_keyidx = i;
3373 hostap_handle_sta_release(sta_ptr);
3375 local->open_wep = erq->flags & IW_ENCODE_OPEN;
3378 * Do not reset port0 if card is in Managed mode since resetting will
3379 * generate new IEEE 802.11 authentication which may end up in looping
3380 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3381 * after WEP configuration. However, keys are apparently changed at
3382 * least in Managed mode.
3385 (hostap_set_encryption(local) ||
3386 (local->iw_mode != IW_MODE_INFRA &&
3387 local->func->reset_port(local->dev))))
3394 static int prism2_ioctl_giwencodeext(struct net_device *dev,
3395 struct iw_request_info *info,
3396 struct iw_point *erq, char *extra)
3398 struct hostap_interface *iface = dev->priv;
3399 local_info_t *local = iface->local;
3400 struct ieee80211_crypt_data **crypt;
3403 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3406 max_key_len = erq->length - sizeof(*ext);
3407 if (max_key_len < 0)
3410 i = erq->flags & IW_ENCODE_INDEX;
3411 if (i < 1 || i > WEP_KEYS)
3412 i = local->tx_keyidx;
3416 addr = ext->addr.sa_data;
3417 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3418 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3420 crypt = &local->crypt[i];
3423 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3424 if (sta_ptr == NULL)
3428 memset(ext, 0, sizeof(*ext));
3430 if (*crypt == NULL || (*crypt)->ops == NULL) {
3431 ext->alg = IW_ENCODE_ALG_NONE;
3433 erq->flags |= IW_ENCODE_DISABLED;
3435 if (strcmp((*crypt)->ops->name, "WEP") == 0)
3436 ext->alg = IW_ENCODE_ALG_WEP;
3437 else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
3438 ext->alg = IW_ENCODE_ALG_TKIP;
3439 else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
3440 ext->alg = IW_ENCODE_ALG_CCMP;
3444 if ((*crypt)->ops->get_key) {
3446 (*crypt)->ops->get_key(ext->key,
3451 (ext->alg == IW_ENCODE_ALG_TKIP ||
3452 ext->alg == IW_ENCODE_ALG_CCMP))
3453 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
3458 hostap_handle_sta_release(sta_ptr);
3464 static int prism2_ioctl_set_encryption(local_info_t *local,
3465 struct prism2_hostapd_param *param,
3469 struct ieee80211_crypto_ops *ops;
3470 struct ieee80211_crypt_data **crypt;
3473 param->u.crypt.err = 0;
3474 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
3477 (int) ((char *) param->u.crypt.key - (char *) param) +
3478 param->u.crypt.key_len)
3481 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3482 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3483 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3484 if (param->u.crypt.idx >= WEP_KEYS)
3487 crypt = &local->crypt[param->u.crypt.idx];
3489 if (param->u.crypt.idx)
3491 sta_ptr = ap_crypt_get_ptrs(
3492 local->ap, param->sta_addr,
3493 (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
3496 if (sta_ptr == NULL) {
3497 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3502 if (strcmp(param->u.crypt.alg, "none") == 0) {
3504 prism2_crypt_delayed_deinit(local, crypt);
3508 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3509 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3510 request_module("ieee80211_crypt_wep");
3511 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3512 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3513 request_module("ieee80211_crypt_tkip");
3514 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3515 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3516 request_module("ieee80211_crypt_ccmp");
3517 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3520 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3521 local->dev->name, param->u.crypt.alg);
3522 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
3527 /* station based encryption and other than WEP algorithms require
3528 * host-based encryption, so force them on automatically */
3529 local->host_decrypt = local->host_encrypt = 1;
3531 if (*crypt == NULL || (*crypt)->ops != ops) {
3532 struct ieee80211_crypt_data *new_crypt;
3534 prism2_crypt_delayed_deinit(local, crypt);
3536 new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
3538 if (new_crypt == NULL) {
3542 new_crypt->ops = ops;
3543 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
3544 if (new_crypt->priv == NULL) {
3546 param->u.crypt.err =
3547 HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
3555 if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
3556 param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
3557 (*crypt)->ops->set_key(param->u.crypt.key,
3558 param->u.crypt.key_len, param->u.crypt.seq,
3559 (*crypt)->priv) < 0) {
3560 printk(KERN_DEBUG "%s: key setting failed\n",
3562 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
3567 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
3569 local->tx_keyidx = param->u.crypt.idx;
3570 else if (param->u.crypt.idx) {
3571 printk(KERN_DEBUG "%s: TX key idx setting failed\n",
3573 param->u.crypt.err =
3574 HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
3582 hostap_handle_sta_release(sta_ptr);
3584 /* Do not reset port0 if card is in Managed mode since resetting will
3585 * generate new IEEE 802.11 authentication which may end up in looping
3586 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3587 * after WEP configuration. However, keys are apparently changed at
3588 * least in Managed mode. */
3590 (hostap_set_encryption(local) ||
3591 (local->iw_mode != IW_MODE_INFRA &&
3592 local->func->reset_port(local->dev)))) {
3593 param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
3601 static int prism2_ioctl_get_encryption(local_info_t *local,
3602 struct prism2_hostapd_param *param,
3605 struct ieee80211_crypt_data **crypt;
3609 param->u.crypt.err = 0;
3611 max_key_len = param_len -
3612 (int) ((char *) param->u.crypt.key - (char *) param);
3613 if (max_key_len < 0)
3616 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3617 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3618 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3620 if (param->u.crypt.idx >= WEP_KEYS)
3621 param->u.crypt.idx = local->tx_keyidx;
3622 crypt = &local->crypt[param->u.crypt.idx];
3624 param->u.crypt.idx = 0;
3625 sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
3628 if (sta_ptr == NULL) {
3629 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3634 if (*crypt == NULL || (*crypt)->ops == NULL) {
3635 memcpy(param->u.crypt.alg, "none", 5);
3636 param->u.crypt.key_len = 0;
3637 param->u.crypt.idx = 0xff;
3639 strncpy(param->u.crypt.alg, (*crypt)->ops->name,
3640 HOSTAP_CRYPT_ALG_NAME_LEN);
3641 param->u.crypt.key_len = 0;
3643 memset(param->u.crypt.seq, 0, 8);
3644 if ((*crypt)->ops->get_key) {
3645 param->u.crypt.key_len =
3646 (*crypt)->ops->get_key(param->u.crypt.key,
3654 hostap_handle_sta_release(sta_ptr);
3660 static int prism2_ioctl_get_rid(local_info_t *local,
3661 struct prism2_hostapd_param *param,
3666 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3670 res = local->func->get_rid(local->dev, param->u.rid.rid,
3671 param->u.rid.data, param->u.rid.len, 0);
3673 param->u.rid.len = res;
3681 static int prism2_ioctl_set_rid(local_info_t *local,
3682 struct prism2_hostapd_param *param,
3687 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3688 if (max_len < 0 || max_len < param->u.rid.len)
3691 return local->func->set_rid(local->dev, param->u.rid.rid,
3692 param->u.rid.data, param->u.rid.len);
3696 static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
3697 struct prism2_hostapd_param *param,
3700 printk(KERN_DEBUG "%ssta: associated as client with AP " MACSTR "\n",
3701 local->dev->name, MAC2STR(param->sta_addr));
3702 memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
3707 static int prism2_ioctl_siwgenie(struct net_device *dev,
3708 struct iw_request_info *info,
3709 struct iw_point *data, char *extra)
3711 return prism2_set_genericelement(dev, extra, data->length);
3715 static int prism2_ioctl_giwgenie(struct net_device *dev,
3716 struct iw_request_info *info,
3717 struct iw_point *data, char *extra)
3719 struct hostap_interface *iface = dev->priv;
3720 local_info_t *local = iface->local;
3721 int len = local->generic_elem_len - 2;
3723 if (len <= 0 || local->generic_elem == NULL) {
3728 if (data->length < len)
3732 memcpy(extra, local->generic_elem + 2, len);
3738 static int prism2_ioctl_set_generic_element(local_info_t *local,
3739 struct prism2_hostapd_param *param,
3744 len = param->u.generic_elem.len;
3745 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
3746 if (max_len < 0 || max_len < len)
3749 return prism2_set_genericelement(local->dev,
3750 param->u.generic_elem.data, len);
3754 static int prism2_ioctl_siwmlme(struct net_device *dev,
3755 struct iw_request_info *info,
3756 struct iw_point *data, char *extra)
3758 struct hostap_interface *iface = dev->priv;
3759 local_info_t *local = iface->local;
3760 struct iw_mlme *mlme = (struct iw_mlme *) extra;
3763 reason = cpu_to_le16(mlme->reason_code);
3765 switch (mlme->cmd) {
3766 case IW_MLME_DEAUTH:
3767 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3768 IEEE80211_STYPE_DEAUTH,
3770 case IW_MLME_DISASSOC:
3771 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3772 IEEE80211_STYPE_DISASSOC,
3780 static int prism2_ioctl_mlme(local_info_t *local,
3781 struct prism2_hostapd_param *param)
3785 reason = cpu_to_le16(param->u.mlme.reason_code);
3786 switch (param->u.mlme.cmd) {
3787 case MLME_STA_DEAUTH:
3788 return prism2_sta_send_mgmt(local, param->sta_addr,
3789 IEEE80211_STYPE_DEAUTH,
3791 case MLME_STA_DISASSOC:
3792 return prism2_sta_send_mgmt(local, param->sta_addr,
3793 IEEE80211_STYPE_DISASSOC,
3801 static int prism2_ioctl_scan_req(local_info_t *local,
3802 struct prism2_hostapd_param *param)
3804 #ifndef PRISM2_NO_STATION_MODES
3805 if ((local->iw_mode != IW_MODE_INFRA &&
3806 local->iw_mode != IW_MODE_ADHOC) ||
3807 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
3810 if (!local->dev_enabled)
3813 return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
3814 param->u.scan_req.ssid_len);
3815 #else /* PRISM2_NO_STATION_MODES */
3817 #endif /* PRISM2_NO_STATION_MODES */
3821 static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3823 struct prism2_hostapd_param *param;
3827 if (p->length < sizeof(struct prism2_hostapd_param) ||
3828 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
3831 param = kmalloc(p->length, GFP_KERNEL);
3835 if (copy_from_user(param, p->pointer, p->length)) {
3840 switch (param->cmd) {
3841 case PRISM2_SET_ENCRYPTION:
3842 ret = prism2_ioctl_set_encryption(local, param, p->length);
3844 case PRISM2_GET_ENCRYPTION:
3845 ret = prism2_ioctl_get_encryption(local, param, p->length);
3847 case PRISM2_HOSTAPD_GET_RID:
3848 ret = prism2_ioctl_get_rid(local, param, p->length);
3850 case PRISM2_HOSTAPD_SET_RID:
3851 ret = prism2_ioctl_set_rid(local, param, p->length);
3853 case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
3854 ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
3856 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
3857 ret = prism2_ioctl_set_generic_element(local, param,
3860 case PRISM2_HOSTAPD_MLME:
3861 ret = prism2_ioctl_mlme(local, param);
3863 case PRISM2_HOSTAPD_SCAN_REQ:
3864 ret = prism2_ioctl_scan_req(local, param);
3867 ret = prism2_hostapd(local->ap, param);
3872 if (ret == 1 || !ap_ioctl) {
3873 if (copy_to_user(p->pointer, param, p->length)) {
3876 } else if (ap_ioctl)
3886 static void prism2_get_drvinfo(struct net_device *dev,
3887 struct ethtool_drvinfo *info)
3889 struct hostap_interface *iface;
3890 local_info_t *local;
3892 iface = netdev_priv(dev);
3893 local = iface->local;
3895 strncpy(info->driver, "hostap", sizeof(info->driver) - 1);
3896 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
3897 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
3898 (local->sta_fw_ver >> 8) & 0xff,
3899 local->sta_fw_ver & 0xff);
3902 const struct ethtool_ops prism2_ethtool_ops = {
3903 .get_drvinfo = prism2_get_drvinfo
3907 /* Structures to export the Wireless Handlers */
3909 static const iw_handler prism2_handler[] =
3911 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3912 (iw_handler) prism2_get_name, /* SIOCGIWNAME */
3913 (iw_handler) NULL, /* SIOCSIWNWID */
3914 (iw_handler) NULL, /* SIOCGIWNWID */
3915 (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */
3916 (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */
3917 (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */
3918 (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */
3919 (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */
3920 (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */
3921 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3922 (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */
3923 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3924 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3925 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3926 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
3927 iw_handler_set_spy, /* SIOCSIWSPY */
3928 iw_handler_get_spy, /* SIOCGIWSPY */
3929 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
3930 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
3931 (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */
3932 (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */
3933 (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */
3934 (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */
3935 (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */
3936 (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */
3937 (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */
3938 (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */
3939 (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */
3940 (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */
3941 (iw_handler) NULL, /* -- hole -- */
3942 (iw_handler) NULL, /* -- hole -- */
3943 (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */
3944 (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */
3945 (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */
3946 (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */
3947 (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */
3948 (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */
3949 (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */
3950 (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */
3951 (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */
3952 (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */
3953 (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */
3954 (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */
3955 (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */
3956 (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */
3957 (iw_handler) NULL, /* -- hole -- */
3958 (iw_handler) NULL, /* -- hole -- */
3959 (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */
3960 (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */
3961 (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */
3962 (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */
3963 (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3964 (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3965 (iw_handler) NULL, /* SIOCSIWPMKSA */
3966 (iw_handler) NULL, /* -- hole -- */
3969 static const iw_handler prism2_private_handler[] =
3970 { /* SIOCIWFIRSTPRIV + */
3971 (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */
3972 (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
3973 (iw_handler) prism2_ioctl_priv_writemif, /* 2 */
3974 (iw_handler) prism2_ioctl_priv_readmif, /* 3 */
3977 const struct iw_handler_def hostap_iw_handler_def =
3979 .num_standard = sizeof(prism2_handler) / sizeof(iw_handler),
3980 .num_private = sizeof(prism2_private_handler) / sizeof(iw_handler),
3981 .num_private_args = sizeof(prism2_priv) / sizeof(struct iw_priv_args),
3982 .standard = (iw_handler *) prism2_handler,
3983 .private = (iw_handler *) prism2_private_handler,
3984 .private_args = (struct iw_priv_args *) prism2_priv,
3985 .get_wireless_stats = hostap_get_wireless_stats,
3989 int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
3991 struct iwreq *wrq = (struct iwreq *) ifr;
3992 struct hostap_interface *iface;
3993 local_info_t *local;
3996 iface = netdev_priv(dev);
3997 local = iface->local;
4000 /* Private ioctls (iwpriv) that have not yet been converted
4001 * into new wireless extensions API */
4003 case PRISM2_IOCTL_INQUIRE:
4004 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4005 else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
4008 case PRISM2_IOCTL_MONITOR:
4009 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4010 else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
4013 case PRISM2_IOCTL_RESET:
4014 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4015 else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
4018 case PRISM2_IOCTL_WDS_ADD:
4019 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4020 else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
4023 case PRISM2_IOCTL_WDS_DEL:
4024 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4025 else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
4028 case PRISM2_IOCTL_SET_RID_WORD:
4029 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4030 else ret = prism2_ioctl_priv_set_rid_word(dev,
4031 (int *) wrq->u.name);
4034 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
4035 case PRISM2_IOCTL_MACCMD:
4036 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4037 else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
4040 case PRISM2_IOCTL_ADDMAC:
4041 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4042 else ret = ap_control_add_mac(&local->ap->mac_restrictions,
4043 wrq->u.ap_addr.sa_data);
4045 case PRISM2_IOCTL_DELMAC:
4046 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4047 else ret = ap_control_del_mac(&local->ap->mac_restrictions,
4048 wrq->u.ap_addr.sa_data);
4050 case PRISM2_IOCTL_KICKMAC:
4051 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4052 else ret = ap_control_kick_mac(local->ap, local->dev,
4053 wrq->u.ap_addr.sa_data);
4055 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
4058 /* Private ioctls that are not used with iwpriv;
4059 * in SIOCDEVPRIVATE range */
4061 #ifdef PRISM2_DOWNLOAD_SUPPORT
4062 case PRISM2_IOCTL_DOWNLOAD:
4063 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4064 else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
4066 #endif /* PRISM2_DOWNLOAD_SUPPORT */
4068 case PRISM2_IOCTL_HOSTAPD:
4069 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4070 else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);