1 /* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
4 /* Get kernel_locked() for in_atomic() */
5 #include <linux/smp_lock.h>
7 #include <linux/ethtool.h>
10 static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
12 struct hostap_interface *iface;
14 struct iw_statistics *wstats;
16 iface = netdev_priv(dev);
19 /* Why are we doing that ? Jean II */
20 if (iface->type != HOSTAP_INTERFACE_MAIN)
23 wstats = &local->wstats;
26 wstats->discard.code =
27 local->comm_tallies.rx_discards_wep_undecryptable;
28 wstats->discard.misc =
29 local->comm_tallies.rx_fcs_errors +
30 local->comm_tallies.rx_discards_no_buffer +
31 local->comm_tallies.tx_discards_wrong_sa;
33 wstats->discard.retries =
34 local->comm_tallies.tx_retry_limit_exceeded;
35 wstats->discard.fragment =
36 local->comm_tallies.rx_message_in_bad_msg_fragments;
38 if (local->iw_mode != IW_MODE_MASTER &&
39 local->iw_mode != IW_MODE_REPEAT) {
42 /* RID reading might sleep and it must not be called in
43 * interrupt context or while atomic. However, this
44 * function seems to be called while atomic (at least in Linux
45 * 2.5.59). Update signal quality values only if in suitable
46 * context. Otherwise, previous values read from tick timer
50 #endif /* in_atomic */
52 if (update && prism2_update_comms_qual(dev) == 0)
53 wstats->qual.updated = 7;
55 wstats->qual.qual = local->comms_qual;
56 wstats->qual.level = local->avg_signal;
57 wstats->qual.noise = local->avg_noise;
59 wstats->qual.qual = 0;
60 wstats->qual.level = 0;
61 wstats->qual.noise = 0;
62 wstats->qual.updated = 0;
69 static int prism2_get_datarates(struct net_device *dev, u8 *rates)
71 struct hostap_interface *iface;
77 iface = netdev_priv(dev);
80 len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
85 val = le16_to_cpu(*(u16 *) buf); /* string length */
87 if (len - 2 < val || val > 10)
90 memcpy(rates, buf + 2, val);
95 static int prism2_get_name(struct net_device *dev,
96 struct iw_request_info *info,
97 char *name, char *extra)
100 int len, i, over2 = 0;
102 len = prism2_get_datarates(dev, rates);
104 for (i = 0; i < len; i++) {
105 if (rates[i] == 0x0b || rates[i] == 0x16) {
111 strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
117 static void prism2_crypt_delayed_deinit(local_info_t *local,
118 struct prism2_crypt_data **crypt)
120 struct prism2_crypt_data *tmp;
129 /* must not run ops->deinit() while there may be pending encrypt or
130 * decrypt operations. Use a list of delayed deinits to avoid needing
133 spin_lock_irqsave(&local->lock, flags);
134 list_add(&tmp->list, &local->crypt_deinit_list);
135 if (!timer_pending(&local->crypt_deinit_timer)) {
136 local->crypt_deinit_timer.expires = jiffies + HZ;
137 add_timer(&local->crypt_deinit_timer);
139 spin_unlock_irqrestore(&local->lock, flags);
143 static int prism2_ioctl_siwencode(struct net_device *dev,
144 struct iw_request_info *info,
145 struct iw_point *erq, char *keybuf)
147 struct hostap_interface *iface;
150 struct prism2_crypt_data **crypt;
152 iface = netdev_priv(dev);
153 local = iface->local;
155 i = erq->flags & IW_ENCODE_INDEX;
157 i = local->tx_keyidx;
160 if (i < 0 || i >= WEP_KEYS)
163 crypt = &local->crypt[i];
165 if (erq->flags & IW_ENCODE_DISABLED) {
167 prism2_crypt_delayed_deinit(local, crypt);
171 if (*crypt != NULL && (*crypt)->ops != NULL &&
172 strcmp((*crypt)->ops->name, "WEP") != 0) {
173 /* changing to use WEP; deinit previously used algorithm */
174 prism2_crypt_delayed_deinit(local, crypt);
177 if (*crypt == NULL) {
178 struct prism2_crypt_data *new_crypt;
180 /* take WEP into use */
181 new_crypt = (struct prism2_crypt_data *)
182 kmalloc(sizeof(struct prism2_crypt_data), GFP_KERNEL);
183 if (new_crypt == NULL)
185 memset(new_crypt, 0, sizeof(struct prism2_crypt_data));
186 new_crypt->ops = hostap_get_crypto_ops("WEP");
187 if (!new_crypt->ops) {
188 request_module("hostap_crypt_wep");
189 new_crypt->ops = hostap_get_crypto_ops("WEP");
192 new_crypt->priv = new_crypt->ops->init(i);
193 if (!new_crypt->ops || !new_crypt->priv) {
197 printk(KERN_WARNING "%s: could not initialize WEP: "
198 "load module hostap_crypt_wep.o\n",
205 if (erq->length > 0) {
206 int len = erq->length <= 5 ? 5 : 13;
208 if (len > erq->length)
209 memset(keybuf + erq->length, 0, len - erq->length);
210 (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
211 for (j = 0; j < WEP_KEYS; j++) {
212 if (j != i && local->crypt[j]) {
218 local->tx_keyidx = i;
220 /* No key data - just set the default TX key index */
221 local->tx_keyidx = i;
225 local->open_wep = erq->flags & IW_ENCODE_OPEN;
227 if (hostap_set_encryption(local)) {
228 printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
232 /* Do not reset port0 if card is in Managed mode since resetting will
233 * generate new IEEE 802.11 authentication which may end up in looping
234 * with IEEE 802.1X. Prism2 documentation seem to require port reset
235 * after WEP configuration. However, keys are apparently changed at
236 * least in Managed mode. */
237 if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
238 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
246 static int prism2_ioctl_giwencode(struct net_device *dev,
247 struct iw_request_info *info,
248 struct iw_point *erq, char *key)
250 struct hostap_interface *iface;
254 struct prism2_crypt_data *crypt;
256 iface = netdev_priv(dev);
257 local = iface->local;
259 i = erq->flags & IW_ENCODE_INDEX;
261 i = local->tx_keyidx;
264 if (i < 0 || i >= WEP_KEYS)
267 crypt = local->crypt[i];
270 if (crypt == NULL || crypt->ops == NULL) {
272 erq->flags |= IW_ENCODE_DISABLED;
276 if (strcmp(crypt->ops->name, "WEP") != 0) {
277 /* only WEP is supported with wireless extensions, so just
278 * report that encryption is used */
280 erq->flags |= IW_ENCODE_ENABLED;
284 /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
285 * the keys from driver buffer */
286 len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
287 erq->length = (len >= 0 ? len : 0);
289 if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
291 printk("CNFWEPFLAGS reading failed\n");
295 if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
296 erq->flags |= IW_ENCODE_ENABLED;
298 erq->flags |= IW_ENCODE_DISABLED;
299 if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
300 erq->flags |= IW_ENCODE_RESTRICTED;
302 erq->flags |= IW_ENCODE_OPEN;
308 static int hostap_set_rate(struct net_device *dev)
310 struct hostap_interface *iface;
312 int ret, basic_rates;
314 iface = netdev_priv(dev);
315 local = iface->local;
317 basic_rates = local->basic_rates & local->tx_rate_control;
318 if (!basic_rates || basic_rates != local->basic_rates) {
319 printk(KERN_INFO "%s: updating basic rate set automatically "
320 "to match with the new supported rate set\n",
323 basic_rates = local->tx_rate_control;
325 local->basic_rates = basic_rates;
326 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
328 printk(KERN_WARNING "%s: failed to set "
329 "cnfBasicRates\n", dev->name);
332 ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
333 local->tx_rate_control) ||
334 hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
335 local->tx_rate_control) ||
336 local->func->reset_port(dev));
339 printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
340 "setting to 0x%x failed\n",
341 dev->name, local->tx_rate_control);
344 /* Update TX rate configuration for all STAs based on new operational
346 hostap_update_rates(local);
352 static int prism2_ioctl_siwrate(struct net_device *dev,
353 struct iw_request_info *info,
354 struct iw_param *rrq, char *extra)
356 struct hostap_interface *iface;
359 iface = netdev_priv(dev);
360 local = iface->local;
363 switch (rrq->value) {
365 local->tx_rate_control = HFA384X_RATES_11MBPS;
368 local->tx_rate_control = HFA384X_RATES_5MBPS;
371 local->tx_rate_control = HFA384X_RATES_2MBPS;
374 local->tx_rate_control = HFA384X_RATES_1MBPS;
377 local->tx_rate_control = HFA384X_RATES_1MBPS |
378 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
379 HFA384X_RATES_11MBPS;
383 switch (rrq->value) {
385 local->tx_rate_control = HFA384X_RATES_1MBPS |
386 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
387 HFA384X_RATES_11MBPS;
390 local->tx_rate_control = HFA384X_RATES_1MBPS |
391 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
394 local->tx_rate_control = HFA384X_RATES_1MBPS |
398 local->tx_rate_control = HFA384X_RATES_1MBPS;
401 local->tx_rate_control = HFA384X_RATES_1MBPS |
402 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
403 HFA384X_RATES_11MBPS;
408 return hostap_set_rate(dev);
412 static int prism2_ioctl_giwrate(struct net_device *dev,
413 struct iw_request_info *info,
414 struct iw_param *rrq, char *extra)
417 struct hostap_interface *iface;
421 iface = netdev_priv(dev);
422 local = iface->local;
424 if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
428 if ((val & 0x1) && (val > 1))
433 if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
434 !local->fw_tx_rate_control) {
435 /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
436 * Host AP mode, so use the recorded TX rate of the last sent
438 rrq->value = local->ap->last_tx_rate > 0 ?
439 local->ap->last_tx_rate * 100000 : 11000000;
443 if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
448 case HFA384X_RATES_1MBPS:
449 rrq->value = 1000000;
451 case HFA384X_RATES_2MBPS:
452 rrq->value = 2000000;
454 case HFA384X_RATES_5MBPS:
455 rrq->value = 5500000;
457 case HFA384X_RATES_11MBPS:
458 rrq->value = 11000000;
461 /* should not happen */
462 rrq->value = 11000000;
471 static int prism2_ioctl_siwsens(struct net_device *dev,
472 struct iw_request_info *info,
473 struct iw_param *sens, char *extra)
475 struct hostap_interface *iface;
478 iface = netdev_priv(dev);
479 local = iface->local;
481 /* Set the desired AP density */
482 if (sens->value < 1 || sens->value > 3)
485 if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
486 local->func->reset_port(dev))
492 static int prism2_ioctl_giwsens(struct net_device *dev,
493 struct iw_request_info *info,
494 struct iw_param *sens, char *extra)
496 struct hostap_interface *iface;
500 iface = netdev_priv(dev);
501 local = iface->local;
503 /* Get the current AP density */
504 if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
508 sens->value = __le16_to_cpu(val);
515 /* Deprecated in new wireless extension API */
516 static int prism2_ioctl_giwaplist(struct net_device *dev,
517 struct iw_request_info *info,
518 struct iw_point *data, char *extra)
520 struct hostap_interface *iface;
522 struct sockaddr *addr;
523 struct iw_quality *qual;
525 iface = netdev_priv(dev);
526 local = iface->local;
528 if (local->iw_mode != IW_MODE_MASTER) {
529 printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
530 "in Host AP mode\n");
535 addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
536 qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
537 if (addr == NULL || qual == NULL) {
544 data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
546 memcpy(extra, &addr, sizeof(struct sockaddr) * data->length);
547 data->flags = 1; /* has quality information */
548 memcpy(extra + sizeof(struct sockaddr) * data->length, &qual,
549 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_scan_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 && *mode == IW_MODE_MASTER) {
1186 /* There seems to be a firmware bug in at least STA f/w v1.5.6
1187 * that leaves beacon frames to use IBSS type when moving from
1188 * IBSS to Host AP mode. Doing double Port0 reset seems to be
1189 * enough to workaround this. */
1193 printk(KERN_DEBUG "prism2: %s: operating mode changed "
1194 "%d -> %d\n", dev->name, local->iw_mode, *mode);
1195 local->iw_mode = *mode;
1197 if (local->iw_mode == IW_MODE_MONITOR)
1198 hostap_monitor_mode_enable(local);
1199 else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
1200 !local->fw_encrypt_ok) {
1201 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
1202 "a workaround for firmware bug in Host AP mode WEP\n",
1204 local->host_encrypt = 1;
1207 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1208 hostap_get_porttype(local)))
1211 if (local->func->reset_port(dev))
1213 if (double_reset && local->func->reset_port(dev))
1216 if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
1218 /* netif_carrier is used only in client modes for now, so make
1219 * sure carrier is on when moving to non-client modes. */
1220 netif_carrier_on(local->dev);
1221 netif_carrier_on(local->ddev);
1227 static int prism2_ioctl_giwmode(struct net_device *dev,
1228 struct iw_request_info *info,
1229 __u32 *mode, char *extra)
1231 struct hostap_interface *iface;
1232 local_info_t *local;
1234 iface = netdev_priv(dev);
1235 local = iface->local;
1237 switch (iface->type) {
1238 case HOSTAP_INTERFACE_STA:
1239 *mode = IW_MODE_INFRA;
1241 case HOSTAP_INTERFACE_WDS:
1242 *mode = IW_MODE_REPEAT;
1245 *mode = local->iw_mode;
1252 static int prism2_ioctl_siwpower(struct net_device *dev,
1253 struct iw_request_info *info,
1254 struct iw_param *wrq, char *extra)
1256 #ifdef PRISM2_NO_STATION_MODES
1258 #else /* PRISM2_NO_STATION_MODES */
1262 return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
1264 switch (wrq->flags & IW_POWER_MODE) {
1265 case IW_POWER_UNICAST_R:
1266 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
1269 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1273 case IW_POWER_ALL_R:
1274 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
1277 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1287 if (wrq->flags & IW_POWER_TIMEOUT) {
1288 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1291 ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
1296 if (wrq->flags & IW_POWER_PERIOD) {
1297 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1300 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1307 #endif /* PRISM2_NO_STATION_MODES */
1311 static int prism2_ioctl_giwpower(struct net_device *dev,
1312 struct iw_request_info *info,
1313 struct iw_param *rrq, char *extra)
1315 #ifdef PRISM2_NO_STATION_MODES
1317 #else /* PRISM2_NO_STATION_MODES */
1318 struct hostap_interface *iface;
1319 local_info_t *local;
1322 iface = netdev_priv(dev);
1323 local = iface->local;
1325 if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
1329 if (!__le16_to_cpu(enable)) {
1336 if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1338 if (local->func->get_rid(dev,
1339 HFA384X_RID_CNFPMHOLDOVERDURATION,
1340 &timeout, 2, 1) < 0)
1343 rrq->flags = IW_POWER_TIMEOUT;
1344 rrq->value = __le16_to_cpu(timeout) * 1024;
1347 if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1351 rrq->flags = IW_POWER_PERIOD;
1352 rrq->value = __le16_to_cpu(period) * 1024;
1355 if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
1359 if (__le16_to_cpu(mcast))
1360 rrq->flags |= IW_POWER_ALL_R;
1362 rrq->flags |= IW_POWER_UNICAST_R;
1365 #endif /* PRISM2_NO_STATION_MODES */
1369 static int prism2_ioctl_siwretry(struct net_device *dev,
1370 struct iw_request_info *info,
1371 struct iw_param *rrq, char *extra)
1373 struct hostap_interface *iface;
1374 local_info_t *local;
1376 iface = netdev_priv(dev);
1377 local = iface->local;
1382 /* setting retry limits is not supported with the current station
1383 * firmware code; simulate this with alternative retry count for now */
1384 if (rrq->flags == IW_RETRY_LIMIT) {
1385 if (rrq->value < 0) {
1386 /* disable manual retry count setting and use firmware
1388 local->manual_retry_count = -1;
1389 local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
1391 if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1393 printk(KERN_DEBUG "%s: Alternate retry count "
1394 "setting to %d failed\n",
1395 dev->name, rrq->value);
1399 local->manual_retry_count = rrq->value;
1400 local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
1408 /* what could be done, if firmware would support this.. */
1410 if (rrq->flags & IW_RETRY_LIMIT) {
1411 if (rrq->flags & IW_RETRY_MAX)
1412 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1413 else if (rrq->flags & IW_RETRY_MIN)
1414 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1416 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1417 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1422 if (rrq->flags & IW_RETRY_LIFETIME) {
1423 HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
1430 static int prism2_ioctl_giwretry(struct net_device *dev,
1431 struct iw_request_info *info,
1432 struct iw_param *rrq, char *extra)
1434 struct hostap_interface *iface;
1435 local_info_t *local;
1436 u16 shortretry, longretry, lifetime, altretry;
1438 iface = netdev_priv(dev);
1439 local = iface->local;
1441 if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
1443 local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
1445 local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
1446 &lifetime, 2, 1) < 0)
1449 le16_to_cpus(&shortretry);
1450 le16_to_cpus(&longretry);
1451 le16_to_cpus(&lifetime);
1455 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1456 rrq->flags = IW_RETRY_LIFETIME;
1457 rrq->value = lifetime * 1024;
1459 if (local->manual_retry_count >= 0) {
1460 rrq->flags = IW_RETRY_LIMIT;
1461 if (local->func->get_rid(dev,
1462 HFA384X_RID_CNFALTRETRYCOUNT,
1463 &altretry, 2, 1) >= 0)
1464 rrq->value = le16_to_cpu(altretry);
1466 rrq->value = local->manual_retry_count;
1467 } else if ((rrq->flags & IW_RETRY_MAX)) {
1468 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1469 rrq->value = longretry;
1471 rrq->flags = IW_RETRY_LIMIT;
1472 rrq->value = shortretry;
1473 if (shortretry != longretry)
1474 rrq->flags |= IW_RETRY_MIN;
1481 /* Note! This TX power controlling is experimental and should not be used in
1482 * production use. It just sets raw power register and does not use any kind of
1483 * feedback information from the measured TX power (CR58). This is now
1484 * commented out to make sure that it is not used by accident. TX power
1485 * configuration will be enabled again after proper algorithm using feedback
1486 * has been implemented. */
1488 #ifdef RAW_TXPOWER_SETTING
1489 /* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
1490 * This version assumes following mapping:
1491 * CR31 is 7-bit value with -64 to +63 range.
1492 * -64 is mapped into +20dBm and +63 into -43dBm.
1493 * This is certainly not an exact mapping for every card, but at least
1494 * increasing dBm value should correspond to increasing TX power.
1497 static int prism2_txpower_hfa386x_to_dBm(u16 val)
1510 static u16 prism2_txpower_dBm_to_hfa386x(int val)
1523 return (unsigned char) tmp;
1525 #endif /* RAW_TXPOWER_SETTING */
1528 static int prism2_ioctl_siwtxpow(struct net_device *dev,
1529 struct iw_request_info *info,
1530 struct iw_param *rrq, char *extra)
1532 struct hostap_interface *iface;
1533 local_info_t *local;
1534 #ifdef RAW_TXPOWER_SETTING
1540 iface = netdev_priv(dev);
1541 local = iface->local;
1543 if (rrq->disabled) {
1544 if (local->txpower_type != PRISM2_TXPOWER_OFF) {
1545 val = 0xff; /* use all standby and sleep modes */
1546 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1547 HFA386X_CR_A_D_TEST_MODES2,
1549 printk(KERN_DEBUG "%s: Turning radio off: %s\n",
1550 dev->name, ret ? "failed" : "OK");
1551 local->txpower_type = PRISM2_TXPOWER_OFF;
1553 return (ret ? -EOPNOTSUPP : 0);
1556 if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1557 val = 0; /* disable all standby and sleep modes */
1558 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1559 HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
1560 printk(KERN_DEBUG "%s: Turning radio on: %s\n",
1561 dev->name, ret ? "failed" : "OK");
1562 local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
1565 #ifdef RAW_TXPOWER_SETTING
1566 if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
1567 printk(KERN_DEBUG "Setting ALC on\n");
1568 val = HFA384X_TEST_CFG_BIT_ALC;
1569 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1570 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
1571 local->txpower_type = PRISM2_TXPOWER_AUTO;
1575 if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
1576 printk(KERN_DEBUG "Setting ALC off\n");
1577 val = HFA384X_TEST_CFG_BIT_ALC;
1578 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1579 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
1580 local->txpower_type = PRISM2_TXPOWER_FIXED;
1583 if (rrq->flags == IW_TXPOW_DBM)
1585 else if (rrq->flags == IW_TXPOW_MWATT)
1589 printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
1591 if (rrq->flags != IW_TXPOW_DBM) {
1592 printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
1596 local->txpower = rrq->value;
1597 val = prism2_txpower_dBm_to_hfa386x(local->txpower);
1598 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1599 HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
1601 #else /* RAW_TXPOWER_SETTING */
1604 #endif /* RAW_TXPOWER_SETTING */
1609 static int prism2_ioctl_giwtxpow(struct net_device *dev,
1610 struct iw_request_info *info,
1611 struct iw_param *rrq, char *extra)
1613 #ifdef RAW_TXPOWER_SETTING
1614 struct hostap_interface *iface;
1615 local_info_t *local;
1618 iface = netdev_priv(dev);
1619 local = iface->local;
1621 rrq->flags = IW_TXPOW_DBM;
1625 if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
1626 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
1627 HFA386X_CR_MANUAL_TX_POWER,
1628 NULL, &resp0) == 0) {
1629 rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
1631 /* Could not get real txpower; guess 15 dBm */
1634 } else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1637 } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
1638 rrq->value = local->txpower;
1641 printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
1642 local->txpower_type);
1645 #else /* RAW_TXPOWER_SETTING */
1647 #endif /* RAW_TXPOWER_SETTING */
1651 #ifndef PRISM2_NO_STATION_MODES
1653 /* HostScan request works with and without host_roaming mode. In addition, it
1654 * does not break current association. However, it requires newer station
1655 * firmware version (>= 1.3.1) than scan request. */
1656 static int prism2_request_hostscan(struct net_device *dev,
1657 u8 *ssid, u8 ssid_len)
1659 struct hostap_interface *iface;
1660 local_info_t *local;
1661 struct hfa384x_hostscan_request scan_req;
1663 iface = netdev_priv(dev);
1664 local = iface->local;
1666 memset(&scan_req, 0, sizeof(scan_req));
1667 scan_req.channel_list = __constant_cpu_to_le16(local->channel_mask);
1668 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1672 scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1673 memcpy(scan_req.target_ssid, ssid, ssid_len);
1676 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1677 sizeof(scan_req))) {
1678 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1685 static int prism2_request_scan(struct net_device *dev)
1687 struct hostap_interface *iface;
1688 local_info_t *local;
1689 struct hfa384x_scan_request scan_req;
1692 iface = netdev_priv(dev);
1693 local = iface->local;
1695 memset(&scan_req, 0, sizeof(scan_req));
1696 scan_req.channel_list = __constant_cpu_to_le16(local->channel_mask);
1697 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1700 * It seems to be enough to set roaming mode for a short moment to
1701 * host-based and then setup scanrequest data and return the mode to
1704 * Master mode would need to drop to Managed mode for a short while
1705 * to make scanning work.. Or sweep through the different channels and
1706 * use passive scan based on beacons. */
1708 if (!local->host_roaming)
1709 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1710 HFA384X_ROAMING_HOST);
1712 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1713 sizeof(scan_req))) {
1714 printk(KERN_DEBUG "SCANREQUEST failed\n");
1718 if (!local->host_roaming)
1719 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1720 HFA384X_ROAMING_FIRMWARE);
1725 #else /* !PRISM2_NO_STATION_MODES */
1727 static inline int prism2_request_hostscan(struct net_device *dev,
1728 u8 *ssid, u8 ssid_len)
1734 static inline int prism2_request_scan(struct net_device *dev)
1739 #endif /* !PRISM2_NO_STATION_MODES */
1742 static int prism2_ioctl_siwscan(struct net_device *dev,
1743 struct iw_request_info *info,
1744 struct iw_point *data, char *extra)
1746 struct hostap_interface *iface;
1747 local_info_t *local;
1749 u8 *ssid = NULL, ssid_len = 0;
1750 struct iw_scan_req *req = (struct iw_scan_req *) extra;
1752 iface = netdev_priv(dev);
1753 local = iface->local;
1755 if (data->length < sizeof(struct iw_scan_req))
1758 if (local->iw_mode == IW_MODE_MASTER) {
1759 /* In master mode, we just return the results of our local
1760 * tables, so we don't need to start anything...
1766 if (!local->dev_enabled)
1769 if (req && data->flags & IW_SCAN_THIS_ESSID) {
1771 ssid_len = req->essid_len;
1774 ((local->iw_mode != IW_MODE_INFRA &&
1775 local->iw_mode != IW_MODE_ADHOC) ||
1776 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1780 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1781 ret = prism2_request_hostscan(dev, ssid, ssid_len);
1783 ret = prism2_request_scan(dev);
1786 local->scan_timestamp = jiffies;
1788 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1794 #ifndef PRISM2_NO_STATION_MODES
1795 static char * __prism2_translate_scan(local_info_t *local,
1796 struct hfa384x_scan_result *scan,
1797 struct hfa384x_hostscan_result *hscan,
1799 struct hostap_bss_info *bss, u8 *bssid,
1800 char *current_ev, char *end_buf)
1803 struct iw_event iwe;
1813 ssid_len = bss->ssid_len;
1815 ssid = hostscan ? hscan->ssid : scan->ssid;
1816 ssid_len = le16_to_cpu(hostscan ? hscan->ssid_len :
1822 /* First entry *MUST* be the AP MAC address */
1823 memset(&iwe, 0, sizeof(iwe));
1824 iwe.cmd = SIOCGIWAP;
1825 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1826 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1828 * I do not know how this is possible, but iwe_stream_add_event
1829 * seems to re-order memcpy execution so that len is set only
1830 * after copying.. Pre-setting len here "fixes" this, but real
1831 * problems should be solved (after which these iwe.len
1832 * settings could be removed from this function). */
1833 iwe.len = IW_EV_ADDR_LEN;
1834 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1837 /* Other entries will be displayed in the order we give them */
1839 memset(&iwe, 0, sizeof(iwe));
1840 iwe.cmd = SIOCGIWESSID;
1841 iwe.u.data.length = ssid_len;
1842 iwe.u.data.flags = 1;
1843 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1844 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid);
1846 memset(&iwe, 0, sizeof(iwe));
1847 iwe.cmd = SIOCGIWMODE;
1849 capabilities = bss->capab_info;
1851 capabilities = le16_to_cpu(hostscan ? hscan->capability :
1854 if (capabilities & (WLAN_CAPABILITY_ESS |
1855 WLAN_CAPABILITY_IBSS)) {
1856 if (capabilities & WLAN_CAPABILITY_ESS)
1857 iwe.u.mode = IW_MODE_MASTER;
1859 iwe.u.mode = IW_MODE_ADHOC;
1860 iwe.len = IW_EV_UINT_LEN;
1861 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1865 memset(&iwe, 0, sizeof(iwe));
1866 iwe.cmd = SIOCGIWFREQ;
1867 if (hscan || scan) {
1868 chan = hostscan ? hscan->chid : scan->chid;
1876 iwe.u.freq.m = freq_list[le16_to_cpu(chan - 1)] * 100000;
1878 iwe.len = IW_EV_FREQ_LEN;
1879 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1883 if (scan || hscan) {
1884 memset(&iwe, 0, sizeof(iwe));
1887 iwe.u.qual.level = le16_to_cpu(hscan->sl);
1888 iwe.u.qual.noise = le16_to_cpu(hscan->anl);
1891 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1893 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1895 iwe.len = IW_EV_QUAL_LEN;
1896 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1900 memset(&iwe, 0, sizeof(iwe));
1901 iwe.cmd = SIOCGIWENCODE;
1902 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1903 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1905 iwe.u.data.flags = IW_ENCODE_DISABLED;
1906 iwe.u.data.length = 0;
1907 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1908 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
1910 /* TODO: add SuppRates into BSS table */
1911 if (scan || hscan) {
1912 memset(&iwe, 0, sizeof(iwe));
1913 iwe.cmd = SIOCGIWRATE;
1914 current_val = current_ev + IW_EV_LCP_LEN;
1915 pos = hostscan ? hscan->sup_rates : scan->sup_rates;
1916 for (i = 0; i < sizeof(scan->sup_rates); i++) {
1919 /* Bit rate given in 500 kb/s units (+ 0x80) */
1920 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1921 current_val = iwe_stream_add_value(
1922 current_ev, current_val, end_buf, &iwe,
1925 /* Check if we added any event */
1926 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1927 current_ev = current_val;
1930 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1931 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_KERNEL);
1932 if (buf && (scan || hscan)) {
1933 memset(&iwe, 0, sizeof(iwe));
1934 iwe.cmd = IWEVCUSTOM;
1935 sprintf(buf, "bcn_int=%d",
1936 le16_to_cpu(hostscan ? hscan->beacon_interval :
1937 scan->beacon_interval));
1938 iwe.u.data.length = strlen(buf);
1939 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1942 memset(&iwe, 0, sizeof(iwe));
1943 iwe.cmd = IWEVCUSTOM;
1944 sprintf(buf, "resp_rate=%d", le16_to_cpu(hostscan ?
1947 iwe.u.data.length = strlen(buf);
1948 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1951 if (hostscan && (capabilities & WLAN_CAPABILITY_IBSS)) {
1952 memset(&iwe, 0, sizeof(iwe));
1953 iwe.cmd = IWEVCUSTOM;
1954 sprintf(buf, "atim=%d", le16_to_cpu(hscan->atim));
1955 iwe.u.data.length = strlen(buf);
1956 current_ev = iwe_stream_add_point(current_ev, end_buf,
1962 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1963 memset(&iwe, 0, sizeof(iwe));
1964 iwe.cmd = IWEVGENIE;
1965 iwe.u.data.length = bss->wpa_ie_len;
1966 current_ev = iwe_stream_add_point(
1967 current_ev, end_buf, &iwe, bss->wpa_ie);
1970 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1971 memset(&iwe, 0, sizeof(iwe));
1972 iwe.cmd = IWEVGENIE;
1973 iwe.u.data.length = bss->rsn_ie_len;
1974 current_ev = iwe_stream_add_point(
1975 current_ev, end_buf, &iwe, bss->rsn_ie);
1982 /* Translate scan data returned from the card to a card independant
1983 * format that the Wireless Tools will understand - Jean II */
1984 static inline int prism2_translate_scan(local_info_t *local,
1985 char *buffer, int buflen)
1987 struct hfa384x_scan_result *scan;
1988 struct hfa384x_hostscan_result *hscan;
1989 int entries, entry, hostscan;
1990 char *current_ev = buffer;
1991 char *end_buf = buffer + buflen;
1993 struct list_head *ptr;
1995 spin_lock_bh(&local->lock);
1997 list_for_each(ptr, &local->bss_list) {
1998 struct hostap_bss_info *bss;
1999 bss = list_entry(ptr, struct hostap_bss_info, list);
2003 hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
2004 entries = hostscan ? local->last_hostscan_results_count :
2005 local->last_scan_results_count;
2006 for (entry = 0; entry < entries; entry++) {
2008 scan = &local->last_scan_results[entry];
2009 hscan = &local->last_hostscan_results[entry];
2011 bssid = hostscan ? hscan->bssid : scan->bssid;
2013 /* Report every SSID if the AP is using multiple SSIDs. If no
2014 * BSS record is found (e.g., when WPA mode is disabled),
2015 * report the AP once. */
2016 list_for_each(ptr, &local->bss_list) {
2017 struct hostap_bss_info *bss;
2018 bss = list_entry(ptr, struct hostap_bss_info, list);
2019 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
2021 current_ev = __prism2_translate_scan(
2022 local, scan, hscan, hostscan, bss,
2023 bssid, current_ev, end_buf);
2028 current_ev = __prism2_translate_scan(
2029 local, scan, hscan, hostscan, NULL, bssid,
2030 current_ev, end_buf);
2032 /* Check if there is space for one more entry */
2033 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2034 /* Ask user space to try again with a bigger buffer */
2035 spin_unlock_bh(&local->lock);
2040 /* Prism2 firmware has limits (32 at least in some versions) for number
2041 * of BSSes in scan results. Extend this limit by using local BSS list.
2043 list_for_each(ptr, &local->bss_list) {
2044 struct hostap_bss_info *bss;
2045 bss = list_entry(ptr, struct hostap_bss_info, list);
2048 current_ev = __prism2_translate_scan(local, NULL, NULL, 0, bss,
2049 bss->bssid, current_ev,
2051 /* Check if there is space for one more entry */
2052 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2053 /* Ask user space to try again with a bigger buffer */
2054 spin_unlock_bh(&local->lock);
2059 spin_unlock_bh(&local->lock);
2061 return current_ev - buffer;
2063 #endif /* PRISM2_NO_STATION_MODES */
2066 static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2067 struct iw_request_info *info,
2068 struct iw_point *data, char *extra)
2070 #ifdef PRISM2_NO_STATION_MODES
2072 #else /* PRISM2_NO_STATION_MODES */
2073 struct hostap_interface *iface;
2074 local_info_t *local;
2077 iface = netdev_priv(dev);
2078 local = iface->local;
2080 /* Wait until the scan is finished. We can probably do better
2081 * than that - Jean II */
2082 if (local->scan_timestamp &&
2083 time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2084 /* Important note : we don't want to block the caller
2085 * until results are ready for various reasons.
2086 * First, managing wait queues is complex and racy
2087 * (there may be multiple simultaneous callers).
2088 * Second, we grab some rtnetlink lock before comming
2089 * here (in dev_ioctl()).
2090 * Third, the caller can wait on the Wireless Event
2094 local->scan_timestamp = 0;
2096 res = prism2_translate_scan(local, extra, data->length);
2105 #endif /* PRISM2_NO_STATION_MODES */
2109 static int prism2_ioctl_giwscan(struct net_device *dev,
2110 struct iw_request_info *info,
2111 struct iw_point *data, char *extra)
2113 struct hostap_interface *iface;
2114 local_info_t *local;
2117 iface = netdev_priv(dev);
2118 local = iface->local;
2120 if (local->iw_mode == IW_MODE_MASTER) {
2121 /* In MASTER mode, it doesn't make sense to go around
2122 * scanning the frequencies and make the stations we serve
2123 * wait when what the user is really interested about is the
2124 * list of stations and access points we are talking to.
2125 * So, just extract results from our cache...
2128 /* Translate to WE format */
2129 res = prism2_ap_translate_scan(dev, extra);
2131 printk(KERN_DEBUG "Scan result translation succeeded "
2132 "(length=%d)\n", res);
2137 "Scan result translation failed (res=%d)\n",
2144 return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2149 static const struct iw_priv_args prism2_priv[] = {
2150 { PRISM2_IOCTL_MONITOR,
2151 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2152 { PRISM2_IOCTL_READMIF,
2153 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2154 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2155 { PRISM2_IOCTL_WRITEMIF,
2156 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2157 { PRISM2_IOCTL_RESET,
2158 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2159 { PRISM2_IOCTL_INQUIRE,
2160 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2161 { PRISM2_IOCTL_SET_RID_WORD,
2162 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2163 { PRISM2_IOCTL_MACCMD,
2164 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2165 { PRISM2_IOCTL_WDS_ADD,
2166 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2167 { PRISM2_IOCTL_WDS_DEL,
2168 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2169 { PRISM2_IOCTL_ADDMAC,
2170 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2171 { PRISM2_IOCTL_DELMAC,
2172 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2173 { PRISM2_IOCTL_KICKMAC,
2174 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2175 /* --- raw access to sub-ioctls --- */
2176 { PRISM2_IOCTL_PRISM2_PARAM,
2177 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2178 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2179 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2180 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2181 /* --- sub-ioctls handlers --- */
2182 { PRISM2_IOCTL_PRISM2_PARAM,
2183 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2184 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2185 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2186 /* --- sub-ioctls definitions --- */
2187 { PRISM2_PARAM_TXRATECTRL,
2188 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2189 { PRISM2_PARAM_TXRATECTRL,
2190 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2191 { PRISM2_PARAM_BEACON_INT,
2192 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2193 { PRISM2_PARAM_BEACON_INT,
2194 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2195 #ifndef PRISM2_NO_STATION_MODES
2196 { PRISM2_PARAM_PSEUDO_IBSS,
2197 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2198 { PRISM2_PARAM_PSEUDO_IBSS,
2199 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2200 #endif /* PRISM2_NO_STATION_MODES */
2202 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2204 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2205 { PRISM2_PARAM_DUMP,
2206 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2207 { PRISM2_PARAM_DUMP,
2208 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2209 { PRISM2_PARAM_OTHER_AP_POLICY,
2210 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2211 { PRISM2_PARAM_OTHER_AP_POLICY,
2212 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2213 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2214 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2215 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2216 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2217 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2218 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2219 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2220 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2221 { PRISM2_PARAM_DTIM_PERIOD,
2222 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2223 { PRISM2_PARAM_DTIM_PERIOD,
2224 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2225 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2226 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2227 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2228 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2229 { PRISM2_PARAM_MAX_WDS,
2230 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2231 { PRISM2_PARAM_MAX_WDS,
2232 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2233 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2234 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2235 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2236 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2237 { PRISM2_PARAM_AP_AUTH_ALGS,
2238 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2239 { PRISM2_PARAM_AP_AUTH_ALGS,
2240 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2241 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2242 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2243 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2244 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2245 { PRISM2_PARAM_HOST_ENCRYPT,
2246 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2247 { PRISM2_PARAM_HOST_ENCRYPT,
2248 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2249 { PRISM2_PARAM_HOST_DECRYPT,
2250 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2251 { PRISM2_PARAM_HOST_DECRYPT,
2252 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2253 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX,
2254 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "busmaster_rx" },
2255 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX,
2256 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbusmaster_rx" },
2257 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX,
2258 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "busmaster_tx" },
2259 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX,
2260 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbusmaster_tx" },
2261 #ifndef PRISM2_NO_STATION_MODES
2262 { PRISM2_PARAM_HOST_ROAMING,
2263 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2264 { PRISM2_PARAM_HOST_ROAMING,
2265 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2266 #endif /* PRISM2_NO_STATION_MODES */
2267 { PRISM2_PARAM_BCRX_STA_KEY,
2268 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2269 { PRISM2_PARAM_BCRX_STA_KEY,
2270 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2271 { PRISM2_PARAM_IEEE_802_1X,
2272 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2273 { PRISM2_PARAM_IEEE_802_1X,
2274 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2275 { PRISM2_PARAM_ANTSEL_TX,
2276 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2277 { PRISM2_PARAM_ANTSEL_TX,
2278 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2279 { PRISM2_PARAM_ANTSEL_RX,
2280 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2281 { PRISM2_PARAM_ANTSEL_RX,
2282 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2283 { PRISM2_PARAM_MONITOR_TYPE,
2284 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2285 { PRISM2_PARAM_MONITOR_TYPE,
2286 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2287 { PRISM2_PARAM_WDS_TYPE,
2288 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2289 { PRISM2_PARAM_WDS_TYPE,
2290 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2291 { PRISM2_PARAM_HOSTSCAN,
2292 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2293 { PRISM2_PARAM_HOSTSCAN,
2294 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2295 { PRISM2_PARAM_AP_SCAN,
2296 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2297 { PRISM2_PARAM_AP_SCAN,
2298 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2299 { PRISM2_PARAM_ENH_SEC,
2300 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2301 { PRISM2_PARAM_ENH_SEC,
2302 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2303 #ifdef PRISM2_IO_DEBUG
2304 { PRISM2_PARAM_IO_DEBUG,
2305 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2306 { PRISM2_PARAM_IO_DEBUG,
2307 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2308 #endif /* PRISM2_IO_DEBUG */
2309 { PRISM2_PARAM_BASIC_RATES,
2310 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2311 { PRISM2_PARAM_BASIC_RATES,
2312 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2313 { PRISM2_PARAM_OPER_RATES,
2314 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2315 { PRISM2_PARAM_OPER_RATES,
2316 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2317 { PRISM2_PARAM_HOSTAPD,
2318 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2319 { PRISM2_PARAM_HOSTAPD,
2320 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2321 { PRISM2_PARAM_HOSTAPD_STA,
2322 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2323 { PRISM2_PARAM_HOSTAPD_STA,
2324 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2326 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2328 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2329 { PRISM2_PARAM_PRIVACY_INVOKED,
2330 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2331 { PRISM2_PARAM_PRIVACY_INVOKED,
2332 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2333 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2334 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2335 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2336 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2337 { PRISM2_PARAM_DROP_UNENCRYPTED,
2338 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2339 { PRISM2_PARAM_DROP_UNENCRYPTED,
2340 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
2344 static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2346 struct hostap_interface *iface;
2347 local_info_t *local;
2349 iface = netdev_priv(dev);
2350 local = iface->local;
2352 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2359 static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2360 struct iw_request_info *info,
2361 void *wrqu, char *extra)
2363 struct hostap_interface *iface;
2364 local_info_t *local;
2365 int *i = (int *) extra;
2367 int value = *(i + 1);
2371 iface = netdev_priv(dev);
2372 local = iface->local;
2375 case PRISM2_PARAM_TXRATECTRL:
2376 local->fw_tx_rate_control = value;
2379 case PRISM2_PARAM_BEACON_INT:
2380 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2381 local->func->reset_port(dev))
2384 local->beacon_int = value;
2387 #ifndef PRISM2_NO_STATION_MODES
2388 case PRISM2_PARAM_PSEUDO_IBSS:
2389 if (value == local->pseudo_adhoc)
2392 if (value != 0 && value != 1) {
2397 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2398 dev->name, local->pseudo_adhoc, value);
2399 local->pseudo_adhoc = value;
2400 if (local->iw_mode != IW_MODE_ADHOC)
2403 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2404 hostap_get_porttype(local))) {
2409 if (local->func->reset_port(dev))
2412 #endif /* PRISM2_NO_STATION_MODES */
2414 case PRISM2_PARAM_ALC:
2415 printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2416 value == 0 ? "Disabling" : "Enabling");
2417 val = HFA384X_TEST_CFG_BIT_ALC;
2418 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2419 (HFA384X_TEST_CFG_BITS << 8),
2420 value == 0 ? 0 : 1, &val, NULL);
2423 case PRISM2_PARAM_DUMP:
2424 local->frame_dump = value;
2427 case PRISM2_PARAM_OTHER_AP_POLICY:
2428 if (value < 0 || value > 3) {
2432 if (local->ap != NULL)
2433 local->ap->ap_policy = value;
2436 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2437 if (value < 0 || value > 7 * 24 * 60 * 60) {
2441 if (local->ap != NULL)
2442 local->ap->max_inactivity = value * HZ;
2445 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2446 if (local->ap != NULL)
2447 local->ap->bridge_packets = value;
2450 case PRISM2_PARAM_DTIM_PERIOD:
2451 if (value < 0 || value > 65535) {
2455 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2456 || local->func->reset_port(dev))
2459 local->dtim_period = value;
2462 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2463 if (local->ap != NULL)
2464 local->ap->nullfunc_ack = value;
2467 case PRISM2_PARAM_MAX_WDS:
2468 local->wds_max_connections = value;
2471 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2472 if (local->ap != NULL) {
2473 if (!local->ap->autom_ap_wds && value) {
2474 /* add WDS link to all APs in STA table */
2475 hostap_add_wds_links(local);
2477 local->ap->autom_ap_wds = value;
2481 case PRISM2_PARAM_AP_AUTH_ALGS:
2482 local->auth_algs = value;
2483 if (hostap_set_auth_algs(local))
2487 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2488 local->monitor_allow_fcserr = value;
2491 case PRISM2_PARAM_HOST_ENCRYPT:
2492 local->host_encrypt = value;
2493 if (hostap_set_encryption(local) ||
2494 local->func->reset_port(dev))
2498 case PRISM2_PARAM_HOST_DECRYPT:
2499 local->host_decrypt = value;
2500 if (hostap_set_encryption(local) ||
2501 local->func->reset_port(dev))
2505 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX:
2506 local->bus_master_threshold_rx = value;
2509 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX:
2510 local->bus_master_threshold_tx = value;
2513 #ifndef PRISM2_NO_STATION_MODES
2514 case PRISM2_PARAM_HOST_ROAMING:
2515 if (value < 0 || value > 2) {
2519 local->host_roaming = value;
2520 if (hostap_set_roaming(local) || local->func->reset_port(dev))
2523 #endif /* PRISM2_NO_STATION_MODES */
2525 case PRISM2_PARAM_BCRX_STA_KEY:
2526 local->bcrx_sta_key = value;
2529 case PRISM2_PARAM_IEEE_802_1X:
2530 local->ieee_802_1x = value;
2533 case PRISM2_PARAM_ANTSEL_TX:
2534 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2538 local->antsel_tx = value;
2539 hostap_set_antsel(local);
2542 case PRISM2_PARAM_ANTSEL_RX:
2543 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2547 local->antsel_rx = value;
2548 hostap_set_antsel(local);
2551 case PRISM2_PARAM_MONITOR_TYPE:
2552 if (value != PRISM2_MONITOR_80211 &&
2553 value != PRISM2_MONITOR_CAPHDR &&
2554 value != PRISM2_MONITOR_PRISM) {
2558 local->monitor_type = value;
2559 if (local->iw_mode == IW_MODE_MONITOR)
2560 hostap_monitor_set_type(local);
2563 case PRISM2_PARAM_WDS_TYPE:
2564 local->wds_type = value;
2567 case PRISM2_PARAM_HOSTSCAN:
2569 struct hfa384x_hostscan_request scan_req;
2572 memset(&scan_req, 0, sizeof(scan_req));
2573 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
2575 case 1: rate = HFA384X_RATES_1MBPS; break;
2576 case 2: rate = HFA384X_RATES_2MBPS; break;
2577 case 3: rate = HFA384X_RATES_5MBPS; break;
2578 case 4: rate = HFA384X_RATES_11MBPS; break;
2579 default: rate = HFA384X_RATES_1MBPS; break;
2581 scan_req.txrate = cpu_to_le16(rate);
2582 /* leave SSID empty to accept all SSIDs */
2584 if (local->iw_mode == IW_MODE_MASTER) {
2585 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2586 HFA384X_PORTTYPE_BSS) ||
2587 local->func->reset_port(dev))
2588 printk(KERN_DEBUG "Leaving Host AP mode "
2589 "for HostScan failed\n");
2592 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2593 sizeof(scan_req))) {
2594 printk(KERN_DEBUG "HOSTSCAN failed\n");
2597 if (local->iw_mode == IW_MODE_MASTER) {
2598 wait_queue_t __wait;
2599 init_waitqueue_entry(&__wait, current);
2600 add_wait_queue(&local->hostscan_wq, &__wait);
2601 set_current_state(TASK_INTERRUPTIBLE);
2602 schedule_timeout(HZ);
2603 if (signal_pending(current))
2605 set_current_state(TASK_RUNNING);
2606 remove_wait_queue(&local->hostscan_wq, &__wait);
2608 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2609 HFA384X_PORTTYPE_HOSTAP) ||
2610 local->func->reset_port(dev))
2611 printk(KERN_DEBUG "Returning to Host AP mode "
2612 "after HostScan failed\n");
2617 case PRISM2_PARAM_AP_SCAN:
2618 local->passive_scan_interval = value;
2619 if (timer_pending(&local->passive_scan_timer))
2620 del_timer(&local->passive_scan_timer);
2622 local->passive_scan_timer.expires = jiffies +
2623 local->passive_scan_interval * HZ;
2624 add_timer(&local->passive_scan_timer);
2628 case PRISM2_PARAM_ENH_SEC:
2629 if (value < 0 || value > 3) {
2633 local->enh_sec = value;
2634 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2636 local->func->reset_port(dev)) {
2637 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2638 "1.6.3 or newer\n", dev->name);
2643 #ifdef PRISM2_IO_DEBUG
2644 case PRISM2_PARAM_IO_DEBUG:
2645 local->io_debug_enabled = value;
2647 #endif /* PRISM2_IO_DEBUG */
2649 case PRISM2_PARAM_BASIC_RATES:
2650 if ((value & local->tx_rate_control) != value || value == 0) {
2651 printk(KERN_INFO "%s: invalid basic rate set - basic "
2652 "rates must be in supported rate set\n",
2657 local->basic_rates = value;
2658 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2659 local->basic_rates) ||
2660 local->func->reset_port(dev))
2664 case PRISM2_PARAM_OPER_RATES:
2665 local->tx_rate_control = value;
2666 if (hostap_set_rate(dev))
2670 case PRISM2_PARAM_HOSTAPD:
2671 ret = hostap_set_hostapd(local, value, 1);
2674 case PRISM2_PARAM_HOSTAPD_STA:
2675 ret = hostap_set_hostapd_sta(local, value, 1);
2678 case PRISM2_PARAM_WPA:
2680 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2682 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2687 case PRISM2_PARAM_PRIVACY_INVOKED:
2688 local->privacy_invoked = value;
2689 if (hostap_set_encryption(local) ||
2690 local->func->reset_port(dev))
2694 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2695 local->tkip_countermeasures = value;
2698 case PRISM2_PARAM_DROP_UNENCRYPTED:
2699 local->drop_unencrypted = value;
2703 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2713 static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2714 struct iw_request_info *info,
2715 void *wrqu, char *extra)
2717 struct hostap_interface *iface;
2718 local_info_t *local;
2719 int *param = (int *) extra;
2722 iface = netdev_priv(dev);
2723 local = iface->local;
2726 case PRISM2_PARAM_TXRATECTRL:
2727 *param = local->fw_tx_rate_control;
2730 case PRISM2_PARAM_BEACON_INT:
2731 *param = local->beacon_int;
2734 case PRISM2_PARAM_PSEUDO_IBSS:
2735 *param = local->pseudo_adhoc;
2738 case PRISM2_PARAM_ALC:
2739 ret = -EOPNOTSUPP; /* FIX */
2742 case PRISM2_PARAM_DUMP:
2743 *param = local->frame_dump;
2746 case PRISM2_PARAM_OTHER_AP_POLICY:
2747 if (local->ap != NULL)
2748 *param = local->ap->ap_policy;
2753 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2754 if (local->ap != NULL)
2755 *param = local->ap->max_inactivity / HZ;
2760 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2761 if (local->ap != NULL)
2762 *param = local->ap->bridge_packets;
2767 case PRISM2_PARAM_DTIM_PERIOD:
2768 *param = local->dtim_period;
2771 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2772 if (local->ap != NULL)
2773 *param = local->ap->nullfunc_ack;
2778 case PRISM2_PARAM_MAX_WDS:
2779 *param = local->wds_max_connections;
2782 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2783 if (local->ap != NULL)
2784 *param = local->ap->autom_ap_wds;
2789 case PRISM2_PARAM_AP_AUTH_ALGS:
2790 *param = local->auth_algs;
2793 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2794 *param = local->monitor_allow_fcserr;
2797 case PRISM2_PARAM_HOST_ENCRYPT:
2798 *param = local->host_encrypt;
2801 case PRISM2_PARAM_HOST_DECRYPT:
2802 *param = local->host_decrypt;
2805 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX:
2806 *param = local->bus_master_threshold_rx;
2809 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX:
2810 *param = local->bus_master_threshold_tx;
2813 case PRISM2_PARAM_HOST_ROAMING:
2814 *param = local->host_roaming;
2817 case PRISM2_PARAM_BCRX_STA_KEY:
2818 *param = local->bcrx_sta_key;
2821 case PRISM2_PARAM_IEEE_802_1X:
2822 *param = local->ieee_802_1x;
2825 case PRISM2_PARAM_ANTSEL_TX:
2826 *param = local->antsel_tx;
2829 case PRISM2_PARAM_ANTSEL_RX:
2830 *param = local->antsel_rx;
2833 case PRISM2_PARAM_MONITOR_TYPE:
2834 *param = local->monitor_type;
2837 case PRISM2_PARAM_WDS_TYPE:
2838 *param = local->wds_type;
2841 case PRISM2_PARAM_HOSTSCAN:
2845 case PRISM2_PARAM_AP_SCAN:
2846 *param = local->passive_scan_interval;
2849 case PRISM2_PARAM_ENH_SEC:
2850 *param = local->enh_sec;
2853 #ifdef PRISM2_IO_DEBUG
2854 case PRISM2_PARAM_IO_DEBUG:
2855 *param = local->io_debug_enabled;
2857 #endif /* PRISM2_IO_DEBUG */
2859 case PRISM2_PARAM_BASIC_RATES:
2860 *param = local->basic_rates;
2863 case PRISM2_PARAM_OPER_RATES:
2864 *param = local->tx_rate_control;
2867 case PRISM2_PARAM_HOSTAPD:
2868 *param = local->hostapd;
2871 case PRISM2_PARAM_HOSTAPD_STA:
2872 *param = local->hostapd_sta;
2875 case PRISM2_PARAM_WPA:
2876 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2878 *param = local->wpa;
2881 case PRISM2_PARAM_PRIVACY_INVOKED:
2882 *param = local->privacy_invoked;
2885 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2886 *param = local->tkip_countermeasures;
2889 case PRISM2_PARAM_DROP_UNENCRYPTED:
2890 *param = local->drop_unencrypted;
2894 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2904 static int prism2_ioctl_priv_readmif(struct net_device *dev,
2905 struct iw_request_info *info,
2906 void *wrqu, char *extra)
2908 struct hostap_interface *iface;
2909 local_info_t *local;
2912 iface = netdev_priv(dev);
2913 local = iface->local;
2915 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2925 static int prism2_ioctl_priv_writemif(struct net_device *dev,
2926 struct iw_request_info *info,
2927 void *wrqu, char *extra)
2929 struct hostap_interface *iface;
2930 local_info_t *local;
2933 iface = netdev_priv(dev);
2934 local = iface->local;
2938 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2945 static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2947 struct hostap_interface *iface;
2948 local_info_t *local;
2952 iface = netdev_priv(dev);
2953 local = iface->local;
2955 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2956 "- update software to use iwconfig mode monitor\n",
2957 dev->name, current->pid, current->comm);
2959 /* Backward compatibility code - this can be removed at some point */
2962 /* Disable monitor mode - old mode was not saved, so go to
2964 mode = IW_MODE_MASTER;
2965 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2966 } else if (*i == 1) {
2967 /* netlink socket mode is not supported anymore since it did
2968 * not separate different devices from each other and was not
2969 * best method for delivering large amount of packets to
2972 } else if (*i == 2 || *i == 3) {
2975 local->monitor_type = PRISM2_MONITOR_80211;
2978 local->monitor_type = PRISM2_MONITOR_PRISM;
2981 mode = IW_MODE_MONITOR;
2982 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2983 hostap_monitor_mode_enable(local);
2991 static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
2993 struct hostap_interface *iface;
2994 local_info_t *local;
2996 iface = netdev_priv(dev);
2997 local = iface->local;
2999 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
3002 /* Disable and enable card */
3003 local->func->hw_shutdown(dev, 1);
3004 local->func->hw_config(dev, 0);
3009 local->func->hw_reset(dev);
3013 /* Disable and enable port 0 */
3014 local->func->reset_port(dev);
3018 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
3019 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
3025 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
3031 printk(KERN_DEBUG "Unknown reset request %d\n", *i);
3039 static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
3042 int value = *(i + 1);
3044 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
3046 if (hostap_set_word(dev, rid, value))
3053 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3054 static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3059 case AP_MAC_CMD_POLICY_OPEN:
3060 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3062 case AP_MAC_CMD_POLICY_ALLOW:
3063 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3065 case AP_MAC_CMD_POLICY_DENY:
3066 local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3068 case AP_MAC_CMD_FLUSH:
3069 ap_control_flush_macs(&local->ap->mac_restrictions);
3071 case AP_MAC_CMD_KICKALL:
3072 ap_control_kickall(local->ap);
3073 hostap_deauth_all_stas(local->dev, local->ap, 0);
3082 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3085 #ifdef PRISM2_DOWNLOAD_SUPPORT
3086 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3088 struct prism2_download_param *param;
3091 if (p->length < sizeof(struct prism2_download_param) ||
3092 p->length > 1024 || !p->pointer)
3095 param = (struct prism2_download_param *)
3096 kmalloc(p->length, GFP_KERNEL);
3100 if (copy_from_user(param, p->pointer, p->length)) {
3105 if (p->length < sizeof(struct prism2_download_param) +
3106 param->num_areas * sizeof(struct prism2_download_area)) {
3111 ret = local->func->download(local, param);
3119 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3122 static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
3125 struct hostap_interface *iface = dev->priv;
3126 local_info_t *local = iface->local;
3130 * Add 16-bit length in the beginning of the buffer because Prism2 RID
3133 buf = kmalloc(len + 2, GFP_KERNEL);
3137 *((u16 *) buf) = cpu_to_le16(len);
3138 memcpy(buf + 2, elem, len);
3140 kfree(local->generic_elem);
3141 local->generic_elem = buf;
3142 local->generic_elem_len = len + 2;
3144 return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
3149 static int prism2_ioctl_siwauth(struct net_device *dev,
3150 struct iw_request_info *info,
3151 struct iw_param *data, char *extra)
3153 struct hostap_interface *iface = dev->priv;
3154 local_info_t *local = iface->local;
3156 switch (data->flags & IW_AUTH_INDEX) {
3157 case IW_AUTH_WPA_VERSION:
3158 case IW_AUTH_CIPHER_PAIRWISE:
3159 case IW_AUTH_CIPHER_GROUP:
3160 case IW_AUTH_KEY_MGMT:
3162 * Host AP driver does not use these parameters and allows
3163 * wpa_supplicant to control them internally.
3166 case IW_AUTH_TKIP_COUNTERMEASURES:
3167 local->tkip_countermeasures = data->value;
3169 case IW_AUTH_DROP_UNENCRYPTED:
3170 local->drop_unencrypted = data->value;
3172 case IW_AUTH_80211_AUTH_ALG:
3173 local->auth_algs = data->value;
3175 case IW_AUTH_WPA_ENABLED:
3176 if (data->value == 0) {
3178 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3180 prism2_set_genericelement(dev, "", 0);
3181 local->host_roaming = 0;
3182 local->privacy_invoked = 0;
3183 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
3185 hostap_set_roaming(local) ||
3186 hostap_set_encryption(local) ||
3187 local->func->reset_port(dev))
3191 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3193 local->host_roaming = 2;
3194 local->privacy_invoked = 1;
3196 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
3197 hostap_set_roaming(local) ||
3198 hostap_set_encryption(local) ||
3199 local->func->reset_port(dev))
3202 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3203 local->ieee_802_1x = data->value;
3205 case IW_AUTH_PRIVACY_INVOKED:
3206 local->privacy_invoked = data->value;
3215 static int prism2_ioctl_giwauth(struct net_device *dev,
3216 struct iw_request_info *info,
3217 struct iw_param *data, char *extra)
3219 struct hostap_interface *iface = dev->priv;
3220 local_info_t *local = iface->local;
3222 switch (data->flags & IW_AUTH_INDEX) {
3223 case IW_AUTH_WPA_VERSION:
3224 case IW_AUTH_CIPHER_PAIRWISE:
3225 case IW_AUTH_CIPHER_GROUP:
3226 case IW_AUTH_KEY_MGMT:
3228 * Host AP driver does not use these parameters and allows
3229 * wpa_supplicant to control them internally.
3232 case IW_AUTH_TKIP_COUNTERMEASURES:
3233 data->value = local->tkip_countermeasures;
3235 case IW_AUTH_DROP_UNENCRYPTED:
3236 data->value = local->drop_unencrypted;
3238 case IW_AUTH_80211_AUTH_ALG:
3239 data->value = local->auth_algs;
3241 case IW_AUTH_WPA_ENABLED:
3242 data->value = local->wpa;
3244 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3245 data->value = local->ieee_802_1x;
3254 static int prism2_ioctl_siwencodeext(struct net_device *dev,
3255 struct iw_request_info *info,
3256 struct iw_point *erq, char *extra)
3258 struct hostap_interface *iface = dev->priv;
3259 local_info_t *local = iface->local;
3260 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3262 struct hostap_crypto_ops *ops;
3263 struct prism2_crypt_data **crypt;
3266 const char *alg, *module;
3268 i = erq->flags & IW_ENCODE_INDEX;
3271 if (i < 1 || i > WEP_KEYS)
3272 i = local->tx_keyidx;
3275 if (i < 0 || i >= WEP_KEYS)
3278 addr = ext->addr.sa_data;
3279 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3280 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3282 crypt = &local->crypt[i];
3286 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3287 if (sta_ptr == NULL) {
3288 if (local->iw_mode == IW_MODE_INFRA) {
3290 * TODO: add STA entry for the current AP so
3291 * that unicast key can be used. For now, this
3292 * is emulated by using default key idx 0.
3295 crypt = &local->crypt[i];
3301 if ((erq->flags & IW_ENCODE_DISABLED) ||
3302 ext->alg == IW_ENCODE_ALG_NONE) {
3304 prism2_crypt_delayed_deinit(local, crypt);
3309 case IW_ENCODE_ALG_WEP:
3311 module = "hostap_crypt_wep";
3313 case IW_ENCODE_ALG_TKIP:
3315 module = "hostap_crypt_tkip";
3317 case IW_ENCODE_ALG_CCMP:
3319 module = "hostap_crypt_ccmp";
3322 printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
3323 local->dev->name, ext->alg);
3328 ops = hostap_get_crypto_ops(alg);
3330 request_module(module);
3331 ops = hostap_get_crypto_ops(alg);
3334 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3335 local->dev->name, alg);
3340 if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
3342 * Per station encryption and other than WEP algorithms
3343 * require host-based encryption, so force them on
3346 local->host_decrypt = local->host_encrypt = 1;
3349 if (*crypt == NULL || (*crypt)->ops != ops) {
3350 struct prism2_crypt_data *new_crypt;
3352 prism2_crypt_delayed_deinit(local, crypt);
3354 new_crypt = (struct prism2_crypt_data *)
3355 kmalloc(sizeof(struct prism2_crypt_data), GFP_KERNEL);
3356 if (new_crypt == NULL) {
3360 memset(new_crypt, 0, sizeof(struct prism2_crypt_data));
3361 new_crypt->ops = ops;
3362 new_crypt->priv = new_crypt->ops->init(i);
3363 if (new_crypt->priv == NULL) {
3373 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
3374 * existing seq# should not be changed.
3375 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
3376 * should be changed to something else than zero.
3378 if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
3379 && (*crypt)->ops->set_key &&
3380 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
3381 (*crypt)->priv) < 0) {
3382 printk(KERN_DEBUG "%s: key setting failed\n",
3388 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3390 local->tx_keyidx = i;
3398 if (sta_ptr == NULL && ext->key_len > 0) {
3400 for (j = 0; j < WEP_KEYS; j++) {
3401 if (j != i && local->crypt[j]) {
3407 local->tx_keyidx = i;
3412 hostap_handle_sta_release(sta_ptr);
3414 local->open_wep = erq->flags & IW_ENCODE_OPEN;
3417 * Do not reset port0 if card is in Managed mode since resetting will
3418 * generate new IEEE 802.11 authentication which may end up in looping
3419 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3420 * after WEP configuration. However, keys are apparently changed at
3421 * least in Managed mode.
3424 (hostap_set_encryption(local) ||
3425 (local->iw_mode != IW_MODE_INFRA &&
3426 local->func->reset_port(local->dev))))
3433 static int prism2_ioctl_giwencodeext(struct net_device *dev,
3434 struct iw_request_info *info,
3435 struct iw_point *erq, char *extra)
3437 struct hostap_interface *iface = dev->priv;
3438 local_info_t *local = iface->local;
3439 struct prism2_crypt_data **crypt;
3442 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3445 max_key_len = erq->length - sizeof(*ext);
3446 if (max_key_len < 0)
3449 i = erq->flags & IW_ENCODE_INDEX;
3450 if (i < 1 || i > WEP_KEYS)
3451 i = local->tx_keyidx;
3455 addr = ext->addr.sa_data;
3456 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3457 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3459 crypt = &local->crypt[i];
3462 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3463 if (sta_ptr == NULL)
3467 memset(ext, 0, sizeof(*ext));
3469 if (*crypt == NULL || (*crypt)->ops == NULL) {
3470 ext->alg = IW_ENCODE_ALG_NONE;
3472 erq->flags |= IW_ENCODE_DISABLED;
3474 if (strcmp((*crypt)->ops->name, "WEP") == 0)
3475 ext->alg = IW_ENCODE_ALG_WEP;
3476 else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
3477 ext->alg = IW_ENCODE_ALG_TKIP;
3478 else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
3479 ext->alg = IW_ENCODE_ALG_CCMP;
3483 if ((*crypt)->ops->get_key) {
3485 (*crypt)->ops->get_key(ext->key,
3490 (ext->alg == IW_ENCODE_ALG_TKIP ||
3491 ext->alg == IW_ENCODE_ALG_CCMP))
3492 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
3497 hostap_handle_sta_release(sta_ptr);
3503 static int prism2_ioctl_set_encryption(local_info_t *local,
3504 struct prism2_hostapd_param *param,
3508 struct hostap_crypto_ops *ops;
3509 struct prism2_crypt_data **crypt;
3512 param->u.crypt.err = 0;
3513 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
3516 (int) ((char *) param->u.crypt.key - (char *) param) +
3517 param->u.crypt.key_len)
3520 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3521 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3522 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3523 if (param->u.crypt.idx >= WEP_KEYS)
3526 crypt = &local->crypt[param->u.crypt.idx];
3528 if (param->u.crypt.idx)
3530 sta_ptr = ap_crypt_get_ptrs(
3531 local->ap, param->sta_addr,
3532 (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
3535 if (sta_ptr == NULL) {
3536 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3541 if (strcmp(param->u.crypt.alg, "none") == 0) {
3543 prism2_crypt_delayed_deinit(local, crypt);
3547 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3548 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3549 request_module("hostap_crypt_wep");
3550 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3551 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3552 request_module("hostap_crypt_tkip");
3553 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3554 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3555 request_module("hostap_crypt_ccmp");
3556 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3559 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3560 local->dev->name, param->u.crypt.alg);
3561 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
3566 /* station based encryption and other than WEP algorithms require
3567 * host-based encryption, so force them on automatically */
3568 local->host_decrypt = local->host_encrypt = 1;
3570 if (*crypt == NULL || (*crypt)->ops != ops) {
3571 struct prism2_crypt_data *new_crypt;
3573 prism2_crypt_delayed_deinit(local, crypt);
3575 new_crypt = (struct prism2_crypt_data *)
3576 kmalloc(sizeof(struct prism2_crypt_data), GFP_KERNEL);
3577 if (new_crypt == NULL) {
3581 memset(new_crypt, 0, sizeof(struct prism2_crypt_data));
3582 new_crypt->ops = ops;
3583 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
3584 if (new_crypt->priv == NULL) {
3586 param->u.crypt.err =
3587 HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
3595 if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
3596 param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
3597 (*crypt)->ops->set_key(param->u.crypt.key,
3598 param->u.crypt.key_len, param->u.crypt.seq,
3599 (*crypt)->priv) < 0) {
3600 printk(KERN_DEBUG "%s: key setting failed\n",
3602 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
3607 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
3609 local->tx_keyidx = param->u.crypt.idx;
3610 else if (param->u.crypt.idx) {
3611 printk(KERN_DEBUG "%s: TX key idx setting failed\n",
3613 param->u.crypt.err =
3614 HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
3622 hostap_handle_sta_release(sta_ptr);
3624 /* Do not reset port0 if card is in Managed mode since resetting will
3625 * generate new IEEE 802.11 authentication which may end up in looping
3626 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3627 * after WEP configuration. However, keys are apparently changed at
3628 * least in Managed mode. */
3630 (hostap_set_encryption(local) ||
3631 (local->iw_mode != IW_MODE_INFRA &&
3632 local->func->reset_port(local->dev)))) {
3633 param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
3641 static int prism2_ioctl_get_encryption(local_info_t *local,
3642 struct prism2_hostapd_param *param,
3645 struct prism2_crypt_data **crypt;
3649 param->u.crypt.err = 0;
3651 max_key_len = param_len -
3652 (int) ((char *) param->u.crypt.key - (char *) param);
3653 if (max_key_len < 0)
3656 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3657 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3658 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3660 if (param->u.crypt.idx >= WEP_KEYS)
3661 param->u.crypt.idx = local->tx_keyidx;
3662 crypt = &local->crypt[param->u.crypt.idx];
3664 param->u.crypt.idx = 0;
3665 sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
3668 if (sta_ptr == NULL) {
3669 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3674 if (*crypt == NULL || (*crypt)->ops == NULL) {
3675 memcpy(param->u.crypt.alg, "none", 5);
3676 param->u.crypt.key_len = 0;
3677 param->u.crypt.idx = 0xff;
3679 strncpy(param->u.crypt.alg, (*crypt)->ops->name,
3680 HOSTAP_CRYPT_ALG_NAME_LEN);
3681 param->u.crypt.key_len = 0;
3683 memset(param->u.crypt.seq, 0, 8);
3684 if ((*crypt)->ops->get_key) {
3685 param->u.crypt.key_len =
3686 (*crypt)->ops->get_key(param->u.crypt.key,
3694 hostap_handle_sta_release(sta_ptr);
3700 static int prism2_ioctl_get_rid(local_info_t *local,
3701 struct prism2_hostapd_param *param,
3706 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3710 res = local->func->get_rid(local->dev, param->u.rid.rid,
3711 param->u.rid.data, param->u.rid.len, 0);
3713 param->u.rid.len = res;
3721 static int prism2_ioctl_set_rid(local_info_t *local,
3722 struct prism2_hostapd_param *param,
3727 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3728 if (max_len < 0 || max_len < param->u.rid.len)
3731 return local->func->set_rid(local->dev, param->u.rid.rid,
3732 param->u.rid.data, param->u.rid.len);
3736 static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
3737 struct prism2_hostapd_param *param,
3740 printk(KERN_DEBUG "%ssta: associated as client with AP " MACSTR "\n",
3741 local->dev->name, MAC2STR(param->sta_addr));
3742 memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
3747 static int prism2_ioctl_siwgenie(struct net_device *dev,
3748 struct iw_request_info *info,
3749 struct iw_point *data, char *extra)
3751 return prism2_set_genericelement(dev, extra, data->length);
3755 static int prism2_ioctl_giwgenie(struct net_device *dev,
3756 struct iw_request_info *info,
3757 struct iw_point *data, char *extra)
3759 struct hostap_interface *iface = dev->priv;
3760 local_info_t *local = iface->local;
3761 int len = local->generic_elem_len - 2;
3763 if (len <= 0 || local->generic_elem == NULL) {
3768 if (data->length < len)
3772 memcpy(extra, local->generic_elem + 2, len);
3778 static int prism2_ioctl_set_generic_element(local_info_t *local,
3779 struct prism2_hostapd_param *param,
3784 len = param->u.generic_elem.len;
3785 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
3786 if (max_len < 0 || max_len < len)
3789 return prism2_set_genericelement(local->dev,
3790 param->u.generic_elem.data, len);
3794 static int prism2_ioctl_siwmlme(struct net_device *dev,
3795 struct iw_request_info *info,
3796 struct iw_point *data, char *extra)
3798 struct hostap_interface *iface = dev->priv;
3799 local_info_t *local = iface->local;
3800 struct iw_mlme *mlme = (struct iw_mlme *) extra;
3803 reason = cpu_to_le16(mlme->reason_code);
3805 switch (mlme->cmd) {
3806 case IW_MLME_DEAUTH:
3807 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3808 WLAN_FC_STYPE_DEAUTH,
3810 case IW_MLME_DISASSOC:
3811 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3812 WLAN_FC_STYPE_DISASSOC,
3820 static int prism2_ioctl_mlme(local_info_t *local,
3821 struct prism2_hostapd_param *param)
3825 reason = cpu_to_le16(param->u.mlme.reason_code);
3826 switch (param->u.mlme.cmd) {
3827 case MLME_STA_DEAUTH:
3828 return prism2_sta_send_mgmt(local, param->sta_addr,
3829 WLAN_FC_STYPE_DEAUTH,
3831 case MLME_STA_DISASSOC:
3832 return prism2_sta_send_mgmt(local, param->sta_addr,
3833 WLAN_FC_STYPE_DISASSOC,
3841 static int prism2_ioctl_scan_req(local_info_t *local,
3842 struct prism2_hostapd_param *param)
3844 #ifndef PRISM2_NO_STATION_MODES
3845 if ((local->iw_mode != IW_MODE_INFRA &&
3846 local->iw_mode != IW_MODE_ADHOC) ||
3847 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
3850 if (!local->dev_enabled)
3853 return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
3854 param->u.scan_req.ssid_len);
3855 #else /* PRISM2_NO_STATION_MODES */
3857 #endif /* PRISM2_NO_STATION_MODES */
3861 static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3863 struct prism2_hostapd_param *param;
3867 if (p->length < sizeof(struct prism2_hostapd_param) ||
3868 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
3871 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
3875 if (copy_from_user(param, p->pointer, p->length)) {
3880 switch (param->cmd) {
3881 case PRISM2_SET_ENCRYPTION:
3882 ret = prism2_ioctl_set_encryption(local, param, p->length);
3884 case PRISM2_GET_ENCRYPTION:
3885 ret = prism2_ioctl_get_encryption(local, param, p->length);
3887 case PRISM2_HOSTAPD_GET_RID:
3888 ret = prism2_ioctl_get_rid(local, param, p->length);
3890 case PRISM2_HOSTAPD_SET_RID:
3891 ret = prism2_ioctl_set_rid(local, param, p->length);
3893 case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
3894 ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
3896 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
3897 ret = prism2_ioctl_set_generic_element(local, param,
3900 case PRISM2_HOSTAPD_MLME:
3901 ret = prism2_ioctl_mlme(local, param);
3903 case PRISM2_HOSTAPD_SCAN_REQ:
3904 ret = prism2_ioctl_scan_req(local, param);
3907 ret = prism2_hostapd(local->ap, param);
3912 if (ret == 1 || !ap_ioctl) {
3913 if (copy_to_user(p->pointer, param, p->length)) {
3916 } else if (ap_ioctl)
3928 static void prism2_get_drvinfo(struct net_device *dev,
3929 struct ethtool_drvinfo *info)
3931 struct hostap_interface *iface;
3932 local_info_t *local;
3934 iface = netdev_priv(dev);
3935 local = iface->local;
3937 strncpy(info->driver, "hostap", sizeof(info->driver) - 1);
3938 strncpy(info->version, PRISM2_VERSION,
3939 sizeof(info->version) - 1);
3940 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
3941 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
3942 (local->sta_fw_ver >> 8) & 0xff,
3943 local->sta_fw_ver & 0xff);
3946 static struct ethtool_ops prism2_ethtool_ops = {
3947 .get_drvinfo = prism2_get_drvinfo
3951 /* Structures to export the Wireless Handlers */
3953 static const iw_handler prism2_handler[] =
3955 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3956 (iw_handler) prism2_get_name, /* SIOCGIWNAME */
3957 (iw_handler) NULL, /* SIOCSIWNWID */
3958 (iw_handler) NULL, /* SIOCGIWNWID */
3959 (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */
3960 (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */
3961 (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */
3962 (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */
3963 (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */
3964 (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */
3965 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3966 (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */
3967 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3968 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3969 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3970 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
3971 iw_handler_set_spy, /* SIOCSIWSPY */
3972 iw_handler_get_spy, /* SIOCGIWSPY */
3973 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
3974 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
3975 (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */
3976 (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */
3977 (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */
3978 (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */
3979 (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */
3980 (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */
3981 (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */
3982 (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */
3983 (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */
3984 (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */
3985 (iw_handler) NULL, /* -- hole -- */
3986 (iw_handler) NULL, /* -- hole -- */
3987 (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */
3988 (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */
3989 (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */
3990 (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */
3991 (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */
3992 (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */
3993 (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */
3994 (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */
3995 (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */
3996 (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */
3997 (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */
3998 (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */
3999 (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */
4000 (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */
4001 (iw_handler) NULL, /* -- hole -- */
4002 (iw_handler) NULL, /* -- hole -- */
4003 (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */
4004 (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */
4005 (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */
4006 (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */
4007 (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
4008 (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
4009 (iw_handler) NULL, /* SIOCSIWPMKSA */
4010 (iw_handler) NULL, /* -- hole -- */
4013 static const iw_handler prism2_private_handler[] =
4014 { /* SIOCIWFIRSTPRIV + */
4015 (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */
4016 (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
4017 (iw_handler) prism2_ioctl_priv_writemif, /* 2 */
4018 (iw_handler) prism2_ioctl_priv_readmif, /* 3 */
4021 static const struct iw_handler_def hostap_iw_handler_def =
4023 .num_standard = sizeof(prism2_handler) / sizeof(iw_handler),
4024 .num_private = sizeof(prism2_private_handler) / sizeof(iw_handler),
4025 .num_private_args = sizeof(prism2_priv) / sizeof(struct iw_priv_args),
4026 .standard = (iw_handler *) prism2_handler,
4027 .private = (iw_handler *) prism2_private_handler,
4028 .private_args = (struct iw_priv_args *) prism2_priv,
4029 .get_wireless_stats = hostap_get_wireless_stats,
4033 int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4035 struct iwreq *wrq = (struct iwreq *) ifr;
4036 struct hostap_interface *iface;
4037 local_info_t *local;
4040 iface = netdev_priv(dev);
4041 local = iface->local;
4044 /* Private ioctls (iwpriv) that have not yet been converted
4045 * into new wireless extensions API */
4047 case PRISM2_IOCTL_INQUIRE:
4048 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4049 else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
4052 case PRISM2_IOCTL_MONITOR:
4053 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4054 else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
4057 case PRISM2_IOCTL_RESET:
4058 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4059 else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
4062 case PRISM2_IOCTL_WDS_ADD:
4063 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4064 else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
4067 case PRISM2_IOCTL_WDS_DEL:
4068 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4069 else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
4072 case PRISM2_IOCTL_SET_RID_WORD:
4073 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4074 else ret = prism2_ioctl_priv_set_rid_word(dev,
4075 (int *) wrq->u.name);
4078 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
4079 case PRISM2_IOCTL_MACCMD:
4080 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4081 else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
4084 case PRISM2_IOCTL_ADDMAC:
4085 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4086 else ret = ap_control_add_mac(&local->ap->mac_restrictions,
4087 wrq->u.ap_addr.sa_data);
4089 case PRISM2_IOCTL_DELMAC:
4090 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4091 else ret = ap_control_del_mac(&local->ap->mac_restrictions,
4092 wrq->u.ap_addr.sa_data);
4094 case PRISM2_IOCTL_KICKMAC:
4095 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4096 else ret = ap_control_kick_mac(local->ap, local->dev,
4097 wrq->u.ap_addr.sa_data);
4099 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
4102 /* Private ioctls that are not used with iwpriv;
4103 * in SIOCDEVPRIVATE range */
4105 #ifdef PRISM2_DOWNLOAD_SUPPORT
4106 case PRISM2_IOCTL_DOWNLOAD:
4107 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4108 else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
4110 #endif /* PRISM2_DOWNLOAD_SUPPORT */
4112 case PRISM2_IOCTL_HOSTAPD:
4113 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4114 else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);