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 = cpu_to_le16(local->channel_mask &
1668 local->scan_channel_mask);
1669 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1673 scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1674 memcpy(scan_req.target_ssid, ssid, ssid_len);
1677 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1678 sizeof(scan_req))) {
1679 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1686 static int prism2_request_scan(struct net_device *dev)
1688 struct hostap_interface *iface;
1689 local_info_t *local;
1690 struct hfa384x_scan_request scan_req;
1693 iface = netdev_priv(dev);
1694 local = iface->local;
1696 memset(&scan_req, 0, sizeof(scan_req));
1697 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1698 local->scan_channel_mask);
1699 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1702 * It seems to be enough to set roaming mode for a short moment to
1703 * host-based and then setup scanrequest data and return the mode to
1706 * Master mode would need to drop to Managed mode for a short while
1707 * to make scanning work.. Or sweep through the different channels and
1708 * use passive scan based on beacons. */
1710 if (!local->host_roaming)
1711 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1712 HFA384X_ROAMING_HOST);
1714 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1715 sizeof(scan_req))) {
1716 printk(KERN_DEBUG "SCANREQUEST failed\n");
1720 if (!local->host_roaming)
1721 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1722 HFA384X_ROAMING_FIRMWARE);
1727 #else /* !PRISM2_NO_STATION_MODES */
1729 static inline int prism2_request_hostscan(struct net_device *dev,
1730 u8 *ssid, u8 ssid_len)
1736 static inline int prism2_request_scan(struct net_device *dev)
1741 #endif /* !PRISM2_NO_STATION_MODES */
1744 static int prism2_ioctl_siwscan(struct net_device *dev,
1745 struct iw_request_info *info,
1746 struct iw_point *data, char *extra)
1748 struct hostap_interface *iface;
1749 local_info_t *local;
1751 u8 *ssid = NULL, ssid_len = 0;
1752 struct iw_scan_req *req = (struct iw_scan_req *) extra;
1754 iface = netdev_priv(dev);
1755 local = iface->local;
1757 if (data->length < sizeof(struct iw_scan_req))
1760 if (local->iw_mode == IW_MODE_MASTER) {
1761 /* In master mode, we just return the results of our local
1762 * tables, so we don't need to start anything...
1768 if (!local->dev_enabled)
1771 if (req && data->flags & IW_SCAN_THIS_ESSID) {
1773 ssid_len = req->essid_len;
1776 ((local->iw_mode != IW_MODE_INFRA &&
1777 local->iw_mode != IW_MODE_ADHOC) ||
1778 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1782 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1783 ret = prism2_request_hostscan(dev, ssid, ssid_len);
1785 ret = prism2_request_scan(dev);
1788 local->scan_timestamp = jiffies;
1790 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1796 #ifndef PRISM2_NO_STATION_MODES
1797 static char * __prism2_translate_scan(local_info_t *local,
1798 struct hfa384x_scan_result *scan,
1799 struct hfa384x_hostscan_result *hscan,
1801 struct hostap_bss_info *bss, u8 *bssid,
1802 char *current_ev, char *end_buf)
1805 struct iw_event iwe;
1815 ssid_len = bss->ssid_len;
1817 ssid = hostscan ? hscan->ssid : scan->ssid;
1818 ssid_len = le16_to_cpu(hostscan ? hscan->ssid_len :
1824 /* First entry *MUST* be the AP MAC address */
1825 memset(&iwe, 0, sizeof(iwe));
1826 iwe.cmd = SIOCGIWAP;
1827 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1828 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1830 * I do not know how this is possible, but iwe_stream_add_event
1831 * seems to re-order memcpy execution so that len is set only
1832 * after copying.. Pre-setting len here "fixes" this, but real
1833 * problems should be solved (after which these iwe.len
1834 * settings could be removed from this function). */
1835 iwe.len = IW_EV_ADDR_LEN;
1836 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1839 /* Other entries will be displayed in the order we give them */
1841 memset(&iwe, 0, sizeof(iwe));
1842 iwe.cmd = SIOCGIWESSID;
1843 iwe.u.data.length = ssid_len;
1844 iwe.u.data.flags = 1;
1845 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1846 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid);
1848 memset(&iwe, 0, sizeof(iwe));
1849 iwe.cmd = SIOCGIWMODE;
1851 capabilities = bss->capab_info;
1853 capabilities = le16_to_cpu(hostscan ? hscan->capability :
1856 if (capabilities & (WLAN_CAPABILITY_ESS |
1857 WLAN_CAPABILITY_IBSS)) {
1858 if (capabilities & WLAN_CAPABILITY_ESS)
1859 iwe.u.mode = IW_MODE_MASTER;
1861 iwe.u.mode = IW_MODE_ADHOC;
1862 iwe.len = IW_EV_UINT_LEN;
1863 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1867 memset(&iwe, 0, sizeof(iwe));
1868 iwe.cmd = SIOCGIWFREQ;
1869 if (hscan || scan) {
1870 chan = hostscan ? hscan->chid : scan->chid;
1878 iwe.u.freq.m = freq_list[le16_to_cpu(chan - 1)] * 100000;
1880 iwe.len = IW_EV_FREQ_LEN;
1881 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1885 if (scan || hscan) {
1886 memset(&iwe, 0, sizeof(iwe));
1889 iwe.u.qual.level = le16_to_cpu(hscan->sl);
1890 iwe.u.qual.noise = le16_to_cpu(hscan->anl);
1893 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1895 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1897 iwe.len = IW_EV_QUAL_LEN;
1898 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1902 memset(&iwe, 0, sizeof(iwe));
1903 iwe.cmd = SIOCGIWENCODE;
1904 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1905 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1907 iwe.u.data.flags = IW_ENCODE_DISABLED;
1908 iwe.u.data.length = 0;
1909 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1910 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
1912 /* TODO: add SuppRates into BSS table */
1913 if (scan || hscan) {
1914 memset(&iwe, 0, sizeof(iwe));
1915 iwe.cmd = SIOCGIWRATE;
1916 current_val = current_ev + IW_EV_LCP_LEN;
1917 pos = hostscan ? hscan->sup_rates : scan->sup_rates;
1918 for (i = 0; i < sizeof(scan->sup_rates); i++) {
1921 /* Bit rate given in 500 kb/s units (+ 0x80) */
1922 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1923 current_val = iwe_stream_add_value(
1924 current_ev, current_val, end_buf, &iwe,
1927 /* Check if we added any event */
1928 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1929 current_ev = current_val;
1932 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1933 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_KERNEL);
1934 if (buf && (scan || hscan)) {
1935 memset(&iwe, 0, sizeof(iwe));
1936 iwe.cmd = IWEVCUSTOM;
1937 sprintf(buf, "bcn_int=%d",
1938 le16_to_cpu(hostscan ? hscan->beacon_interval :
1939 scan->beacon_interval));
1940 iwe.u.data.length = strlen(buf);
1941 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1944 memset(&iwe, 0, sizeof(iwe));
1945 iwe.cmd = IWEVCUSTOM;
1946 sprintf(buf, "resp_rate=%d", le16_to_cpu(hostscan ?
1949 iwe.u.data.length = strlen(buf);
1950 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1953 if (hostscan && (capabilities & WLAN_CAPABILITY_IBSS)) {
1954 memset(&iwe, 0, sizeof(iwe));
1955 iwe.cmd = IWEVCUSTOM;
1956 sprintf(buf, "atim=%d", le16_to_cpu(hscan->atim));
1957 iwe.u.data.length = strlen(buf);
1958 current_ev = iwe_stream_add_point(current_ev, end_buf,
1964 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1965 memset(&iwe, 0, sizeof(iwe));
1966 iwe.cmd = IWEVGENIE;
1967 iwe.u.data.length = bss->wpa_ie_len;
1968 current_ev = iwe_stream_add_point(
1969 current_ev, end_buf, &iwe, bss->wpa_ie);
1972 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1973 memset(&iwe, 0, sizeof(iwe));
1974 iwe.cmd = IWEVGENIE;
1975 iwe.u.data.length = bss->rsn_ie_len;
1976 current_ev = iwe_stream_add_point(
1977 current_ev, end_buf, &iwe, bss->rsn_ie);
1984 /* Translate scan data returned from the card to a card independant
1985 * format that the Wireless Tools will understand - Jean II */
1986 static inline int prism2_translate_scan(local_info_t *local,
1987 char *buffer, int buflen)
1989 struct hfa384x_scan_result *scan;
1990 struct hfa384x_hostscan_result *hscan;
1991 int entries, entry, hostscan;
1992 char *current_ev = buffer;
1993 char *end_buf = buffer + buflen;
1995 struct list_head *ptr;
1997 spin_lock_bh(&local->lock);
1999 list_for_each(ptr, &local->bss_list) {
2000 struct hostap_bss_info *bss;
2001 bss = list_entry(ptr, struct hostap_bss_info, list);
2005 hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
2006 entries = hostscan ? local->last_hostscan_results_count :
2007 local->last_scan_results_count;
2008 for (entry = 0; entry < entries; entry++) {
2010 scan = &local->last_scan_results[entry];
2011 hscan = &local->last_hostscan_results[entry];
2013 bssid = hostscan ? hscan->bssid : scan->bssid;
2015 /* Report every SSID if the AP is using multiple SSIDs. If no
2016 * BSS record is found (e.g., when WPA mode is disabled),
2017 * report the AP once. */
2018 list_for_each(ptr, &local->bss_list) {
2019 struct hostap_bss_info *bss;
2020 bss = list_entry(ptr, struct hostap_bss_info, list);
2021 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
2023 current_ev = __prism2_translate_scan(
2024 local, scan, hscan, hostscan, bss,
2025 bssid, current_ev, end_buf);
2030 current_ev = __prism2_translate_scan(
2031 local, scan, hscan, hostscan, NULL, bssid,
2032 current_ev, end_buf);
2034 /* Check if there is space for one more entry */
2035 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2036 /* Ask user space to try again with a bigger buffer */
2037 spin_unlock_bh(&local->lock);
2042 /* Prism2 firmware has limits (32 at least in some versions) for number
2043 * of BSSes in scan results. Extend this limit by using local BSS list.
2045 list_for_each(ptr, &local->bss_list) {
2046 struct hostap_bss_info *bss;
2047 bss = list_entry(ptr, struct hostap_bss_info, list);
2050 current_ev = __prism2_translate_scan(local, NULL, NULL, 0, bss,
2051 bss->bssid, current_ev,
2053 /* Check if there is space for one more entry */
2054 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2055 /* Ask user space to try again with a bigger buffer */
2056 spin_unlock_bh(&local->lock);
2061 spin_unlock_bh(&local->lock);
2063 return current_ev - buffer;
2065 #endif /* PRISM2_NO_STATION_MODES */
2068 static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2069 struct iw_request_info *info,
2070 struct iw_point *data, char *extra)
2072 #ifdef PRISM2_NO_STATION_MODES
2074 #else /* PRISM2_NO_STATION_MODES */
2075 struct hostap_interface *iface;
2076 local_info_t *local;
2079 iface = netdev_priv(dev);
2080 local = iface->local;
2082 /* Wait until the scan is finished. We can probably do better
2083 * than that - Jean II */
2084 if (local->scan_timestamp &&
2085 time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2086 /* Important note : we don't want to block the caller
2087 * until results are ready for various reasons.
2088 * First, managing wait queues is complex and racy
2089 * (there may be multiple simultaneous callers).
2090 * Second, we grab some rtnetlink lock before comming
2091 * here (in dev_ioctl()).
2092 * Third, the caller can wait on the Wireless Event
2096 local->scan_timestamp = 0;
2098 res = prism2_translate_scan(local, extra, data->length);
2107 #endif /* PRISM2_NO_STATION_MODES */
2111 static int prism2_ioctl_giwscan(struct net_device *dev,
2112 struct iw_request_info *info,
2113 struct iw_point *data, char *extra)
2115 struct hostap_interface *iface;
2116 local_info_t *local;
2119 iface = netdev_priv(dev);
2120 local = iface->local;
2122 if (local->iw_mode == IW_MODE_MASTER) {
2123 /* In MASTER mode, it doesn't make sense to go around
2124 * scanning the frequencies and make the stations we serve
2125 * wait when what the user is really interested about is the
2126 * list of stations and access points we are talking to.
2127 * So, just extract results from our cache...
2130 /* Translate to WE format */
2131 res = prism2_ap_translate_scan(dev, extra);
2133 printk(KERN_DEBUG "Scan result translation succeeded "
2134 "(length=%d)\n", res);
2139 "Scan result translation failed (res=%d)\n",
2146 return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2151 static const struct iw_priv_args prism2_priv[] = {
2152 { PRISM2_IOCTL_MONITOR,
2153 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2154 { PRISM2_IOCTL_READMIF,
2155 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2156 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2157 { PRISM2_IOCTL_WRITEMIF,
2158 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2159 { PRISM2_IOCTL_RESET,
2160 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2161 { PRISM2_IOCTL_INQUIRE,
2162 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2163 { PRISM2_IOCTL_SET_RID_WORD,
2164 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2165 { PRISM2_IOCTL_MACCMD,
2166 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2167 { PRISM2_IOCTL_WDS_ADD,
2168 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2169 { PRISM2_IOCTL_WDS_DEL,
2170 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2171 { PRISM2_IOCTL_ADDMAC,
2172 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2173 { PRISM2_IOCTL_DELMAC,
2174 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2175 { PRISM2_IOCTL_KICKMAC,
2176 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2177 /* --- raw access to sub-ioctls --- */
2178 { PRISM2_IOCTL_PRISM2_PARAM,
2179 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2180 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2181 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2182 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2183 /* --- sub-ioctls handlers --- */
2184 { PRISM2_IOCTL_PRISM2_PARAM,
2185 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2186 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2187 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2188 /* --- sub-ioctls definitions --- */
2189 { PRISM2_PARAM_TXRATECTRL,
2190 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2191 { PRISM2_PARAM_TXRATECTRL,
2192 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2193 { PRISM2_PARAM_BEACON_INT,
2194 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2195 { PRISM2_PARAM_BEACON_INT,
2196 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2197 #ifndef PRISM2_NO_STATION_MODES
2198 { PRISM2_PARAM_PSEUDO_IBSS,
2199 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2200 { PRISM2_PARAM_PSEUDO_IBSS,
2201 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2202 #endif /* PRISM2_NO_STATION_MODES */
2204 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2206 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2207 { PRISM2_PARAM_DUMP,
2208 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2209 { PRISM2_PARAM_DUMP,
2210 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2211 { PRISM2_PARAM_OTHER_AP_POLICY,
2212 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2213 { PRISM2_PARAM_OTHER_AP_POLICY,
2214 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2215 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2216 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2217 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2218 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2219 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2220 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2221 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2222 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2223 { PRISM2_PARAM_DTIM_PERIOD,
2224 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2225 { PRISM2_PARAM_DTIM_PERIOD,
2226 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2227 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2228 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2229 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2230 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2231 { PRISM2_PARAM_MAX_WDS,
2232 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2233 { PRISM2_PARAM_MAX_WDS,
2234 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2235 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2236 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2237 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2238 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2239 { PRISM2_PARAM_AP_AUTH_ALGS,
2240 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2241 { PRISM2_PARAM_AP_AUTH_ALGS,
2242 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2243 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2244 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2245 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2246 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2247 { PRISM2_PARAM_HOST_ENCRYPT,
2248 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2249 { PRISM2_PARAM_HOST_ENCRYPT,
2250 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2251 { PRISM2_PARAM_HOST_DECRYPT,
2252 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2253 { PRISM2_PARAM_HOST_DECRYPT,
2254 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2255 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX,
2256 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "busmaster_rx" },
2257 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX,
2258 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbusmaster_rx" },
2259 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX,
2260 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "busmaster_tx" },
2261 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX,
2262 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbusmaster_tx" },
2263 #ifndef PRISM2_NO_STATION_MODES
2264 { PRISM2_PARAM_HOST_ROAMING,
2265 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2266 { PRISM2_PARAM_HOST_ROAMING,
2267 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2268 #endif /* PRISM2_NO_STATION_MODES */
2269 { PRISM2_PARAM_BCRX_STA_KEY,
2270 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2271 { PRISM2_PARAM_BCRX_STA_KEY,
2272 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2273 { PRISM2_PARAM_IEEE_802_1X,
2274 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2275 { PRISM2_PARAM_IEEE_802_1X,
2276 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2277 { PRISM2_PARAM_ANTSEL_TX,
2278 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2279 { PRISM2_PARAM_ANTSEL_TX,
2280 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2281 { PRISM2_PARAM_ANTSEL_RX,
2282 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2283 { PRISM2_PARAM_ANTSEL_RX,
2284 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2285 { PRISM2_PARAM_MONITOR_TYPE,
2286 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2287 { PRISM2_PARAM_MONITOR_TYPE,
2288 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2289 { PRISM2_PARAM_WDS_TYPE,
2290 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2291 { PRISM2_PARAM_WDS_TYPE,
2292 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2293 { PRISM2_PARAM_HOSTSCAN,
2294 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2295 { PRISM2_PARAM_HOSTSCAN,
2296 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2297 { PRISM2_PARAM_AP_SCAN,
2298 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2299 { PRISM2_PARAM_AP_SCAN,
2300 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2301 { PRISM2_PARAM_ENH_SEC,
2302 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2303 { PRISM2_PARAM_ENH_SEC,
2304 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2305 #ifdef PRISM2_IO_DEBUG
2306 { PRISM2_PARAM_IO_DEBUG,
2307 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2308 { PRISM2_PARAM_IO_DEBUG,
2309 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2310 #endif /* PRISM2_IO_DEBUG */
2311 { PRISM2_PARAM_BASIC_RATES,
2312 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2313 { PRISM2_PARAM_BASIC_RATES,
2314 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2315 { PRISM2_PARAM_OPER_RATES,
2316 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2317 { PRISM2_PARAM_OPER_RATES,
2318 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2319 { PRISM2_PARAM_HOSTAPD,
2320 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2321 { PRISM2_PARAM_HOSTAPD,
2322 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2323 { PRISM2_PARAM_HOSTAPD_STA,
2324 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2325 { PRISM2_PARAM_HOSTAPD_STA,
2326 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2328 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2330 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2331 { PRISM2_PARAM_PRIVACY_INVOKED,
2332 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2333 { PRISM2_PARAM_PRIVACY_INVOKED,
2334 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2335 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2336 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2337 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2338 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2339 { PRISM2_PARAM_DROP_UNENCRYPTED,
2340 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2341 { PRISM2_PARAM_DROP_UNENCRYPTED,
2342 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
2343 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2344 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
2345 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2346 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
2350 static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2352 struct hostap_interface *iface;
2353 local_info_t *local;
2355 iface = netdev_priv(dev);
2356 local = iface->local;
2358 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2365 static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2366 struct iw_request_info *info,
2367 void *wrqu, char *extra)
2369 struct hostap_interface *iface;
2370 local_info_t *local;
2371 int *i = (int *) extra;
2373 int value = *(i + 1);
2377 iface = netdev_priv(dev);
2378 local = iface->local;
2381 case PRISM2_PARAM_TXRATECTRL:
2382 local->fw_tx_rate_control = value;
2385 case PRISM2_PARAM_BEACON_INT:
2386 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2387 local->func->reset_port(dev))
2390 local->beacon_int = value;
2393 #ifndef PRISM2_NO_STATION_MODES
2394 case PRISM2_PARAM_PSEUDO_IBSS:
2395 if (value == local->pseudo_adhoc)
2398 if (value != 0 && value != 1) {
2403 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2404 dev->name, local->pseudo_adhoc, value);
2405 local->pseudo_adhoc = value;
2406 if (local->iw_mode != IW_MODE_ADHOC)
2409 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2410 hostap_get_porttype(local))) {
2415 if (local->func->reset_port(dev))
2418 #endif /* PRISM2_NO_STATION_MODES */
2420 case PRISM2_PARAM_ALC:
2421 printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2422 value == 0 ? "Disabling" : "Enabling");
2423 val = HFA384X_TEST_CFG_BIT_ALC;
2424 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2425 (HFA384X_TEST_CFG_BITS << 8),
2426 value == 0 ? 0 : 1, &val, NULL);
2429 case PRISM2_PARAM_DUMP:
2430 local->frame_dump = value;
2433 case PRISM2_PARAM_OTHER_AP_POLICY:
2434 if (value < 0 || value > 3) {
2438 if (local->ap != NULL)
2439 local->ap->ap_policy = value;
2442 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2443 if (value < 0 || value > 7 * 24 * 60 * 60) {
2447 if (local->ap != NULL)
2448 local->ap->max_inactivity = value * HZ;
2451 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2452 if (local->ap != NULL)
2453 local->ap->bridge_packets = value;
2456 case PRISM2_PARAM_DTIM_PERIOD:
2457 if (value < 0 || value > 65535) {
2461 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2462 || local->func->reset_port(dev))
2465 local->dtim_period = value;
2468 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2469 if (local->ap != NULL)
2470 local->ap->nullfunc_ack = value;
2473 case PRISM2_PARAM_MAX_WDS:
2474 local->wds_max_connections = value;
2477 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2478 if (local->ap != NULL) {
2479 if (!local->ap->autom_ap_wds && value) {
2480 /* add WDS link to all APs in STA table */
2481 hostap_add_wds_links(local);
2483 local->ap->autom_ap_wds = value;
2487 case PRISM2_PARAM_AP_AUTH_ALGS:
2488 local->auth_algs = value;
2489 if (hostap_set_auth_algs(local))
2493 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2494 local->monitor_allow_fcserr = value;
2497 case PRISM2_PARAM_HOST_ENCRYPT:
2498 local->host_encrypt = value;
2499 if (hostap_set_encryption(local) ||
2500 local->func->reset_port(dev))
2504 case PRISM2_PARAM_HOST_DECRYPT:
2505 local->host_decrypt = value;
2506 if (hostap_set_encryption(local) ||
2507 local->func->reset_port(dev))
2511 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX:
2512 local->bus_master_threshold_rx = value;
2515 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX:
2516 local->bus_master_threshold_tx = value;
2519 #ifndef PRISM2_NO_STATION_MODES
2520 case PRISM2_PARAM_HOST_ROAMING:
2521 if (value < 0 || value > 2) {
2525 local->host_roaming = value;
2526 if (hostap_set_roaming(local) || local->func->reset_port(dev))
2529 #endif /* PRISM2_NO_STATION_MODES */
2531 case PRISM2_PARAM_BCRX_STA_KEY:
2532 local->bcrx_sta_key = value;
2535 case PRISM2_PARAM_IEEE_802_1X:
2536 local->ieee_802_1x = value;
2539 case PRISM2_PARAM_ANTSEL_TX:
2540 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2544 local->antsel_tx = value;
2545 hostap_set_antsel(local);
2548 case PRISM2_PARAM_ANTSEL_RX:
2549 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2553 local->antsel_rx = value;
2554 hostap_set_antsel(local);
2557 case PRISM2_PARAM_MONITOR_TYPE:
2558 if (value != PRISM2_MONITOR_80211 &&
2559 value != PRISM2_MONITOR_CAPHDR &&
2560 value != PRISM2_MONITOR_PRISM) {
2564 local->monitor_type = value;
2565 if (local->iw_mode == IW_MODE_MONITOR)
2566 hostap_monitor_set_type(local);
2569 case PRISM2_PARAM_WDS_TYPE:
2570 local->wds_type = value;
2573 case PRISM2_PARAM_HOSTSCAN:
2575 struct hfa384x_hostscan_request scan_req;
2578 memset(&scan_req, 0, sizeof(scan_req));
2579 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
2581 case 1: rate = HFA384X_RATES_1MBPS; break;
2582 case 2: rate = HFA384X_RATES_2MBPS; break;
2583 case 3: rate = HFA384X_RATES_5MBPS; break;
2584 case 4: rate = HFA384X_RATES_11MBPS; break;
2585 default: rate = HFA384X_RATES_1MBPS; break;
2587 scan_req.txrate = cpu_to_le16(rate);
2588 /* leave SSID empty to accept all SSIDs */
2590 if (local->iw_mode == IW_MODE_MASTER) {
2591 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2592 HFA384X_PORTTYPE_BSS) ||
2593 local->func->reset_port(dev))
2594 printk(KERN_DEBUG "Leaving Host AP mode "
2595 "for HostScan failed\n");
2598 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2599 sizeof(scan_req))) {
2600 printk(KERN_DEBUG "HOSTSCAN failed\n");
2603 if (local->iw_mode == IW_MODE_MASTER) {
2604 wait_queue_t __wait;
2605 init_waitqueue_entry(&__wait, current);
2606 add_wait_queue(&local->hostscan_wq, &__wait);
2607 set_current_state(TASK_INTERRUPTIBLE);
2608 schedule_timeout(HZ);
2609 if (signal_pending(current))
2611 set_current_state(TASK_RUNNING);
2612 remove_wait_queue(&local->hostscan_wq, &__wait);
2614 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2615 HFA384X_PORTTYPE_HOSTAP) ||
2616 local->func->reset_port(dev))
2617 printk(KERN_DEBUG "Returning to Host AP mode "
2618 "after HostScan failed\n");
2623 case PRISM2_PARAM_AP_SCAN:
2624 local->passive_scan_interval = value;
2625 if (timer_pending(&local->passive_scan_timer))
2626 del_timer(&local->passive_scan_timer);
2628 local->passive_scan_timer.expires = jiffies +
2629 local->passive_scan_interval * HZ;
2630 add_timer(&local->passive_scan_timer);
2634 case PRISM2_PARAM_ENH_SEC:
2635 if (value < 0 || value > 3) {
2639 local->enh_sec = value;
2640 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2642 local->func->reset_port(dev)) {
2643 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2644 "1.6.3 or newer\n", dev->name);
2649 #ifdef PRISM2_IO_DEBUG
2650 case PRISM2_PARAM_IO_DEBUG:
2651 local->io_debug_enabled = value;
2653 #endif /* PRISM2_IO_DEBUG */
2655 case PRISM2_PARAM_BASIC_RATES:
2656 if ((value & local->tx_rate_control) != value || value == 0) {
2657 printk(KERN_INFO "%s: invalid basic rate set - basic "
2658 "rates must be in supported rate set\n",
2663 local->basic_rates = value;
2664 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2665 local->basic_rates) ||
2666 local->func->reset_port(dev))
2670 case PRISM2_PARAM_OPER_RATES:
2671 local->tx_rate_control = value;
2672 if (hostap_set_rate(dev))
2676 case PRISM2_PARAM_HOSTAPD:
2677 ret = hostap_set_hostapd(local, value, 1);
2680 case PRISM2_PARAM_HOSTAPD_STA:
2681 ret = hostap_set_hostapd_sta(local, value, 1);
2684 case PRISM2_PARAM_WPA:
2686 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2688 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2693 case PRISM2_PARAM_PRIVACY_INVOKED:
2694 local->privacy_invoked = value;
2695 if (hostap_set_encryption(local) ||
2696 local->func->reset_port(dev))
2700 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2701 local->tkip_countermeasures = value;
2704 case PRISM2_PARAM_DROP_UNENCRYPTED:
2705 local->drop_unencrypted = value;
2708 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2709 local->scan_channel_mask = value;
2713 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2723 static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2724 struct iw_request_info *info,
2725 void *wrqu, char *extra)
2727 struct hostap_interface *iface;
2728 local_info_t *local;
2729 int *param = (int *) extra;
2732 iface = netdev_priv(dev);
2733 local = iface->local;
2736 case PRISM2_PARAM_TXRATECTRL:
2737 *param = local->fw_tx_rate_control;
2740 case PRISM2_PARAM_BEACON_INT:
2741 *param = local->beacon_int;
2744 case PRISM2_PARAM_PSEUDO_IBSS:
2745 *param = local->pseudo_adhoc;
2748 case PRISM2_PARAM_ALC:
2749 ret = -EOPNOTSUPP; /* FIX */
2752 case PRISM2_PARAM_DUMP:
2753 *param = local->frame_dump;
2756 case PRISM2_PARAM_OTHER_AP_POLICY:
2757 if (local->ap != NULL)
2758 *param = local->ap->ap_policy;
2763 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2764 if (local->ap != NULL)
2765 *param = local->ap->max_inactivity / HZ;
2770 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2771 if (local->ap != NULL)
2772 *param = local->ap->bridge_packets;
2777 case PRISM2_PARAM_DTIM_PERIOD:
2778 *param = local->dtim_period;
2781 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2782 if (local->ap != NULL)
2783 *param = local->ap->nullfunc_ack;
2788 case PRISM2_PARAM_MAX_WDS:
2789 *param = local->wds_max_connections;
2792 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2793 if (local->ap != NULL)
2794 *param = local->ap->autom_ap_wds;
2799 case PRISM2_PARAM_AP_AUTH_ALGS:
2800 *param = local->auth_algs;
2803 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2804 *param = local->monitor_allow_fcserr;
2807 case PRISM2_PARAM_HOST_ENCRYPT:
2808 *param = local->host_encrypt;
2811 case PRISM2_PARAM_HOST_DECRYPT:
2812 *param = local->host_decrypt;
2815 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX:
2816 *param = local->bus_master_threshold_rx;
2819 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX:
2820 *param = local->bus_master_threshold_tx;
2823 case PRISM2_PARAM_HOST_ROAMING:
2824 *param = local->host_roaming;
2827 case PRISM2_PARAM_BCRX_STA_KEY:
2828 *param = local->bcrx_sta_key;
2831 case PRISM2_PARAM_IEEE_802_1X:
2832 *param = local->ieee_802_1x;
2835 case PRISM2_PARAM_ANTSEL_TX:
2836 *param = local->antsel_tx;
2839 case PRISM2_PARAM_ANTSEL_RX:
2840 *param = local->antsel_rx;
2843 case PRISM2_PARAM_MONITOR_TYPE:
2844 *param = local->monitor_type;
2847 case PRISM2_PARAM_WDS_TYPE:
2848 *param = local->wds_type;
2851 case PRISM2_PARAM_HOSTSCAN:
2855 case PRISM2_PARAM_AP_SCAN:
2856 *param = local->passive_scan_interval;
2859 case PRISM2_PARAM_ENH_SEC:
2860 *param = local->enh_sec;
2863 #ifdef PRISM2_IO_DEBUG
2864 case PRISM2_PARAM_IO_DEBUG:
2865 *param = local->io_debug_enabled;
2867 #endif /* PRISM2_IO_DEBUG */
2869 case PRISM2_PARAM_BASIC_RATES:
2870 *param = local->basic_rates;
2873 case PRISM2_PARAM_OPER_RATES:
2874 *param = local->tx_rate_control;
2877 case PRISM2_PARAM_HOSTAPD:
2878 *param = local->hostapd;
2881 case PRISM2_PARAM_HOSTAPD_STA:
2882 *param = local->hostapd_sta;
2885 case PRISM2_PARAM_WPA:
2886 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2888 *param = local->wpa;
2891 case PRISM2_PARAM_PRIVACY_INVOKED:
2892 *param = local->privacy_invoked;
2895 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2896 *param = local->tkip_countermeasures;
2899 case PRISM2_PARAM_DROP_UNENCRYPTED:
2900 *param = local->drop_unencrypted;
2903 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2904 *param = local->scan_channel_mask;
2908 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2918 static int prism2_ioctl_priv_readmif(struct net_device *dev,
2919 struct iw_request_info *info,
2920 void *wrqu, char *extra)
2922 struct hostap_interface *iface;
2923 local_info_t *local;
2926 iface = netdev_priv(dev);
2927 local = iface->local;
2929 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2939 static int prism2_ioctl_priv_writemif(struct net_device *dev,
2940 struct iw_request_info *info,
2941 void *wrqu, char *extra)
2943 struct hostap_interface *iface;
2944 local_info_t *local;
2947 iface = netdev_priv(dev);
2948 local = iface->local;
2952 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2959 static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2961 struct hostap_interface *iface;
2962 local_info_t *local;
2966 iface = netdev_priv(dev);
2967 local = iface->local;
2969 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2970 "- update software to use iwconfig mode monitor\n",
2971 dev->name, current->pid, current->comm);
2973 /* Backward compatibility code - this can be removed at some point */
2976 /* Disable monitor mode - old mode was not saved, so go to
2978 mode = IW_MODE_MASTER;
2979 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2980 } else if (*i == 1) {
2981 /* netlink socket mode is not supported anymore since it did
2982 * not separate different devices from each other and was not
2983 * best method for delivering large amount of packets to
2986 } else if (*i == 2 || *i == 3) {
2989 local->monitor_type = PRISM2_MONITOR_80211;
2992 local->monitor_type = PRISM2_MONITOR_PRISM;
2995 mode = IW_MODE_MONITOR;
2996 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2997 hostap_monitor_mode_enable(local);
3005 static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
3007 struct hostap_interface *iface;
3008 local_info_t *local;
3010 iface = netdev_priv(dev);
3011 local = iface->local;
3013 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
3016 /* Disable and enable card */
3017 local->func->hw_shutdown(dev, 1);
3018 local->func->hw_config(dev, 0);
3023 local->func->hw_reset(dev);
3027 /* Disable and enable port 0 */
3028 local->func->reset_port(dev);
3032 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
3033 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
3039 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
3045 printk(KERN_DEBUG "Unknown reset request %d\n", *i);
3053 static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
3056 int value = *(i + 1);
3058 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
3060 if (hostap_set_word(dev, rid, value))
3067 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3068 static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3073 case AP_MAC_CMD_POLICY_OPEN:
3074 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3076 case AP_MAC_CMD_POLICY_ALLOW:
3077 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3079 case AP_MAC_CMD_POLICY_DENY:
3080 local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3082 case AP_MAC_CMD_FLUSH:
3083 ap_control_flush_macs(&local->ap->mac_restrictions);
3085 case AP_MAC_CMD_KICKALL:
3086 ap_control_kickall(local->ap);
3087 hostap_deauth_all_stas(local->dev, local->ap, 0);
3096 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3099 #ifdef PRISM2_DOWNLOAD_SUPPORT
3100 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3102 struct prism2_download_param *param;
3105 if (p->length < sizeof(struct prism2_download_param) ||
3106 p->length > 1024 || !p->pointer)
3109 param = (struct prism2_download_param *)
3110 kmalloc(p->length, GFP_KERNEL);
3114 if (copy_from_user(param, p->pointer, p->length)) {
3119 if (p->length < sizeof(struct prism2_download_param) +
3120 param->num_areas * sizeof(struct prism2_download_area)) {
3125 ret = local->func->download(local, param);
3133 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3136 static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
3139 struct hostap_interface *iface = dev->priv;
3140 local_info_t *local = iface->local;
3144 * Add 16-bit length in the beginning of the buffer because Prism2 RID
3147 buf = kmalloc(len + 2, GFP_KERNEL);
3151 *((u16 *) buf) = cpu_to_le16(len);
3152 memcpy(buf + 2, elem, len);
3154 kfree(local->generic_elem);
3155 local->generic_elem = buf;
3156 local->generic_elem_len = len + 2;
3158 return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
3163 static int prism2_ioctl_siwauth(struct net_device *dev,
3164 struct iw_request_info *info,
3165 struct iw_param *data, char *extra)
3167 struct hostap_interface *iface = dev->priv;
3168 local_info_t *local = iface->local;
3170 switch (data->flags & IW_AUTH_INDEX) {
3171 case IW_AUTH_WPA_VERSION:
3172 case IW_AUTH_CIPHER_PAIRWISE:
3173 case IW_AUTH_CIPHER_GROUP:
3174 case IW_AUTH_KEY_MGMT:
3176 * Host AP driver does not use these parameters and allows
3177 * wpa_supplicant to control them internally.
3180 case IW_AUTH_TKIP_COUNTERMEASURES:
3181 local->tkip_countermeasures = data->value;
3183 case IW_AUTH_DROP_UNENCRYPTED:
3184 local->drop_unencrypted = data->value;
3186 case IW_AUTH_80211_AUTH_ALG:
3187 local->auth_algs = data->value;
3189 case IW_AUTH_WPA_ENABLED:
3190 if (data->value == 0) {
3192 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3194 prism2_set_genericelement(dev, "", 0);
3195 local->host_roaming = 0;
3196 local->privacy_invoked = 0;
3197 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
3199 hostap_set_roaming(local) ||
3200 hostap_set_encryption(local) ||
3201 local->func->reset_port(dev))
3205 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3207 local->host_roaming = 2;
3208 local->privacy_invoked = 1;
3210 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
3211 hostap_set_roaming(local) ||
3212 hostap_set_encryption(local) ||
3213 local->func->reset_port(dev))
3216 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3217 local->ieee_802_1x = data->value;
3219 case IW_AUTH_PRIVACY_INVOKED:
3220 local->privacy_invoked = data->value;
3229 static int prism2_ioctl_giwauth(struct net_device *dev,
3230 struct iw_request_info *info,
3231 struct iw_param *data, char *extra)
3233 struct hostap_interface *iface = dev->priv;
3234 local_info_t *local = iface->local;
3236 switch (data->flags & IW_AUTH_INDEX) {
3237 case IW_AUTH_WPA_VERSION:
3238 case IW_AUTH_CIPHER_PAIRWISE:
3239 case IW_AUTH_CIPHER_GROUP:
3240 case IW_AUTH_KEY_MGMT:
3242 * Host AP driver does not use these parameters and allows
3243 * wpa_supplicant to control them internally.
3246 case IW_AUTH_TKIP_COUNTERMEASURES:
3247 data->value = local->tkip_countermeasures;
3249 case IW_AUTH_DROP_UNENCRYPTED:
3250 data->value = local->drop_unencrypted;
3252 case IW_AUTH_80211_AUTH_ALG:
3253 data->value = local->auth_algs;
3255 case IW_AUTH_WPA_ENABLED:
3256 data->value = local->wpa;
3258 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3259 data->value = local->ieee_802_1x;
3268 static int prism2_ioctl_siwencodeext(struct net_device *dev,
3269 struct iw_request_info *info,
3270 struct iw_point *erq, char *extra)
3272 struct hostap_interface *iface = dev->priv;
3273 local_info_t *local = iface->local;
3274 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3276 struct hostap_crypto_ops *ops;
3277 struct prism2_crypt_data **crypt;
3280 const char *alg, *module;
3282 i = erq->flags & IW_ENCODE_INDEX;
3285 if (i < 1 || i > WEP_KEYS)
3286 i = local->tx_keyidx;
3289 if (i < 0 || i >= WEP_KEYS)
3292 addr = ext->addr.sa_data;
3293 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3294 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3296 crypt = &local->crypt[i];
3300 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3301 if (sta_ptr == NULL) {
3302 if (local->iw_mode == IW_MODE_INFRA) {
3304 * TODO: add STA entry for the current AP so
3305 * that unicast key can be used. For now, this
3306 * is emulated by using default key idx 0.
3309 crypt = &local->crypt[i];
3315 if ((erq->flags & IW_ENCODE_DISABLED) ||
3316 ext->alg == IW_ENCODE_ALG_NONE) {
3318 prism2_crypt_delayed_deinit(local, crypt);
3323 case IW_ENCODE_ALG_WEP:
3325 module = "hostap_crypt_wep";
3327 case IW_ENCODE_ALG_TKIP:
3329 module = "hostap_crypt_tkip";
3331 case IW_ENCODE_ALG_CCMP:
3333 module = "hostap_crypt_ccmp";
3336 printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
3337 local->dev->name, ext->alg);
3342 ops = hostap_get_crypto_ops(alg);
3344 request_module(module);
3345 ops = hostap_get_crypto_ops(alg);
3348 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3349 local->dev->name, alg);
3354 if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
3356 * Per station encryption and other than WEP algorithms
3357 * require host-based encryption, so force them on
3360 local->host_decrypt = local->host_encrypt = 1;
3363 if (*crypt == NULL || (*crypt)->ops != ops) {
3364 struct prism2_crypt_data *new_crypt;
3366 prism2_crypt_delayed_deinit(local, crypt);
3368 new_crypt = (struct prism2_crypt_data *)
3369 kmalloc(sizeof(struct prism2_crypt_data), GFP_KERNEL);
3370 if (new_crypt == NULL) {
3374 memset(new_crypt, 0, sizeof(struct prism2_crypt_data));
3375 new_crypt->ops = ops;
3376 new_crypt->priv = new_crypt->ops->init(i);
3377 if (new_crypt->priv == NULL) {
3387 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
3388 * existing seq# should not be changed.
3389 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
3390 * should be changed to something else than zero.
3392 if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
3393 && (*crypt)->ops->set_key &&
3394 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
3395 (*crypt)->priv) < 0) {
3396 printk(KERN_DEBUG "%s: key setting failed\n",
3402 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3404 local->tx_keyidx = i;
3412 if (sta_ptr == NULL && ext->key_len > 0) {
3414 for (j = 0; j < WEP_KEYS; j++) {
3415 if (j != i && local->crypt[j]) {
3421 local->tx_keyidx = i;
3426 hostap_handle_sta_release(sta_ptr);
3428 local->open_wep = erq->flags & IW_ENCODE_OPEN;
3431 * Do not reset port0 if card is in Managed mode since resetting will
3432 * generate new IEEE 802.11 authentication which may end up in looping
3433 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3434 * after WEP configuration. However, keys are apparently changed at
3435 * least in Managed mode.
3438 (hostap_set_encryption(local) ||
3439 (local->iw_mode != IW_MODE_INFRA &&
3440 local->func->reset_port(local->dev))))
3447 static int prism2_ioctl_giwencodeext(struct net_device *dev,
3448 struct iw_request_info *info,
3449 struct iw_point *erq, char *extra)
3451 struct hostap_interface *iface = dev->priv;
3452 local_info_t *local = iface->local;
3453 struct prism2_crypt_data **crypt;
3456 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3459 max_key_len = erq->length - sizeof(*ext);
3460 if (max_key_len < 0)
3463 i = erq->flags & IW_ENCODE_INDEX;
3464 if (i < 1 || i > WEP_KEYS)
3465 i = local->tx_keyidx;
3469 addr = ext->addr.sa_data;
3470 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3471 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3473 crypt = &local->crypt[i];
3476 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3477 if (sta_ptr == NULL)
3481 memset(ext, 0, sizeof(*ext));
3483 if (*crypt == NULL || (*crypt)->ops == NULL) {
3484 ext->alg = IW_ENCODE_ALG_NONE;
3486 erq->flags |= IW_ENCODE_DISABLED;
3488 if (strcmp((*crypt)->ops->name, "WEP") == 0)
3489 ext->alg = IW_ENCODE_ALG_WEP;
3490 else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
3491 ext->alg = IW_ENCODE_ALG_TKIP;
3492 else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
3493 ext->alg = IW_ENCODE_ALG_CCMP;
3497 if ((*crypt)->ops->get_key) {
3499 (*crypt)->ops->get_key(ext->key,
3504 (ext->alg == IW_ENCODE_ALG_TKIP ||
3505 ext->alg == IW_ENCODE_ALG_CCMP))
3506 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
3511 hostap_handle_sta_release(sta_ptr);
3517 static int prism2_ioctl_set_encryption(local_info_t *local,
3518 struct prism2_hostapd_param *param,
3522 struct hostap_crypto_ops *ops;
3523 struct prism2_crypt_data **crypt;
3526 param->u.crypt.err = 0;
3527 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
3530 (int) ((char *) param->u.crypt.key - (char *) param) +
3531 param->u.crypt.key_len)
3534 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3535 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3536 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3537 if (param->u.crypt.idx >= WEP_KEYS)
3540 crypt = &local->crypt[param->u.crypt.idx];
3542 if (param->u.crypt.idx)
3544 sta_ptr = ap_crypt_get_ptrs(
3545 local->ap, param->sta_addr,
3546 (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
3549 if (sta_ptr == NULL) {
3550 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3555 if (strcmp(param->u.crypt.alg, "none") == 0) {
3557 prism2_crypt_delayed_deinit(local, crypt);
3561 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3562 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3563 request_module("hostap_crypt_wep");
3564 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3565 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3566 request_module("hostap_crypt_tkip");
3567 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3568 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3569 request_module("hostap_crypt_ccmp");
3570 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3573 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3574 local->dev->name, param->u.crypt.alg);
3575 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
3580 /* station based encryption and other than WEP algorithms require
3581 * host-based encryption, so force them on automatically */
3582 local->host_decrypt = local->host_encrypt = 1;
3584 if (*crypt == NULL || (*crypt)->ops != ops) {
3585 struct prism2_crypt_data *new_crypt;
3587 prism2_crypt_delayed_deinit(local, crypt);
3589 new_crypt = (struct prism2_crypt_data *)
3590 kmalloc(sizeof(struct prism2_crypt_data), GFP_KERNEL);
3591 if (new_crypt == NULL) {
3595 memset(new_crypt, 0, sizeof(struct prism2_crypt_data));
3596 new_crypt->ops = ops;
3597 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
3598 if (new_crypt->priv == NULL) {
3600 param->u.crypt.err =
3601 HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
3609 if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
3610 param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
3611 (*crypt)->ops->set_key(param->u.crypt.key,
3612 param->u.crypt.key_len, param->u.crypt.seq,
3613 (*crypt)->priv) < 0) {
3614 printk(KERN_DEBUG "%s: key setting failed\n",
3616 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
3621 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
3623 local->tx_keyidx = param->u.crypt.idx;
3624 else if (param->u.crypt.idx) {
3625 printk(KERN_DEBUG "%s: TX key idx setting failed\n",
3627 param->u.crypt.err =
3628 HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
3636 hostap_handle_sta_release(sta_ptr);
3638 /* Do not reset port0 if card is in Managed mode since resetting will
3639 * generate new IEEE 802.11 authentication which may end up in looping
3640 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3641 * after WEP configuration. However, keys are apparently changed at
3642 * least in Managed mode. */
3644 (hostap_set_encryption(local) ||
3645 (local->iw_mode != IW_MODE_INFRA &&
3646 local->func->reset_port(local->dev)))) {
3647 param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
3655 static int prism2_ioctl_get_encryption(local_info_t *local,
3656 struct prism2_hostapd_param *param,
3659 struct prism2_crypt_data **crypt;
3663 param->u.crypt.err = 0;
3665 max_key_len = param_len -
3666 (int) ((char *) param->u.crypt.key - (char *) param);
3667 if (max_key_len < 0)
3670 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3671 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3672 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3674 if (param->u.crypt.idx >= WEP_KEYS)
3675 param->u.crypt.idx = local->tx_keyidx;
3676 crypt = &local->crypt[param->u.crypt.idx];
3678 param->u.crypt.idx = 0;
3679 sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
3682 if (sta_ptr == NULL) {
3683 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3688 if (*crypt == NULL || (*crypt)->ops == NULL) {
3689 memcpy(param->u.crypt.alg, "none", 5);
3690 param->u.crypt.key_len = 0;
3691 param->u.crypt.idx = 0xff;
3693 strncpy(param->u.crypt.alg, (*crypt)->ops->name,
3694 HOSTAP_CRYPT_ALG_NAME_LEN);
3695 param->u.crypt.key_len = 0;
3697 memset(param->u.crypt.seq, 0, 8);
3698 if ((*crypt)->ops->get_key) {
3699 param->u.crypt.key_len =
3700 (*crypt)->ops->get_key(param->u.crypt.key,
3708 hostap_handle_sta_release(sta_ptr);
3714 static int prism2_ioctl_get_rid(local_info_t *local,
3715 struct prism2_hostapd_param *param,
3720 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3724 res = local->func->get_rid(local->dev, param->u.rid.rid,
3725 param->u.rid.data, param->u.rid.len, 0);
3727 param->u.rid.len = res;
3735 static int prism2_ioctl_set_rid(local_info_t *local,
3736 struct prism2_hostapd_param *param,
3741 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3742 if (max_len < 0 || max_len < param->u.rid.len)
3745 return local->func->set_rid(local->dev, param->u.rid.rid,
3746 param->u.rid.data, param->u.rid.len);
3750 static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
3751 struct prism2_hostapd_param *param,
3754 printk(KERN_DEBUG "%ssta: associated as client with AP " MACSTR "\n",
3755 local->dev->name, MAC2STR(param->sta_addr));
3756 memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
3761 static int prism2_ioctl_siwgenie(struct net_device *dev,
3762 struct iw_request_info *info,
3763 struct iw_point *data, char *extra)
3765 return prism2_set_genericelement(dev, extra, data->length);
3769 static int prism2_ioctl_giwgenie(struct net_device *dev,
3770 struct iw_request_info *info,
3771 struct iw_point *data, char *extra)
3773 struct hostap_interface *iface = dev->priv;
3774 local_info_t *local = iface->local;
3775 int len = local->generic_elem_len - 2;
3777 if (len <= 0 || local->generic_elem == NULL) {
3782 if (data->length < len)
3786 memcpy(extra, local->generic_elem + 2, len);
3792 static int prism2_ioctl_set_generic_element(local_info_t *local,
3793 struct prism2_hostapd_param *param,
3798 len = param->u.generic_elem.len;
3799 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
3800 if (max_len < 0 || max_len < len)
3803 return prism2_set_genericelement(local->dev,
3804 param->u.generic_elem.data, len);
3808 static int prism2_ioctl_siwmlme(struct net_device *dev,
3809 struct iw_request_info *info,
3810 struct iw_point *data, char *extra)
3812 struct hostap_interface *iface = dev->priv;
3813 local_info_t *local = iface->local;
3814 struct iw_mlme *mlme = (struct iw_mlme *) extra;
3817 reason = cpu_to_le16(mlme->reason_code);
3819 switch (mlme->cmd) {
3820 case IW_MLME_DEAUTH:
3821 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3822 WLAN_FC_STYPE_DEAUTH,
3824 case IW_MLME_DISASSOC:
3825 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3826 WLAN_FC_STYPE_DISASSOC,
3834 static int prism2_ioctl_mlme(local_info_t *local,
3835 struct prism2_hostapd_param *param)
3839 reason = cpu_to_le16(param->u.mlme.reason_code);
3840 switch (param->u.mlme.cmd) {
3841 case MLME_STA_DEAUTH:
3842 return prism2_sta_send_mgmt(local, param->sta_addr,
3843 WLAN_FC_STYPE_DEAUTH,
3845 case MLME_STA_DISASSOC:
3846 return prism2_sta_send_mgmt(local, param->sta_addr,
3847 WLAN_FC_STYPE_DISASSOC,
3855 static int prism2_ioctl_scan_req(local_info_t *local,
3856 struct prism2_hostapd_param *param)
3858 #ifndef PRISM2_NO_STATION_MODES
3859 if ((local->iw_mode != IW_MODE_INFRA &&
3860 local->iw_mode != IW_MODE_ADHOC) ||
3861 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
3864 if (!local->dev_enabled)
3867 return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
3868 param->u.scan_req.ssid_len);
3869 #else /* PRISM2_NO_STATION_MODES */
3871 #endif /* PRISM2_NO_STATION_MODES */
3875 static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3877 struct prism2_hostapd_param *param;
3881 if (p->length < sizeof(struct prism2_hostapd_param) ||
3882 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
3885 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
3889 if (copy_from_user(param, p->pointer, p->length)) {
3894 switch (param->cmd) {
3895 case PRISM2_SET_ENCRYPTION:
3896 ret = prism2_ioctl_set_encryption(local, param, p->length);
3898 case PRISM2_GET_ENCRYPTION:
3899 ret = prism2_ioctl_get_encryption(local, param, p->length);
3901 case PRISM2_HOSTAPD_GET_RID:
3902 ret = prism2_ioctl_get_rid(local, param, p->length);
3904 case PRISM2_HOSTAPD_SET_RID:
3905 ret = prism2_ioctl_set_rid(local, param, p->length);
3907 case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
3908 ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
3910 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
3911 ret = prism2_ioctl_set_generic_element(local, param,
3914 case PRISM2_HOSTAPD_MLME:
3915 ret = prism2_ioctl_mlme(local, param);
3917 case PRISM2_HOSTAPD_SCAN_REQ:
3918 ret = prism2_ioctl_scan_req(local, param);
3921 ret = prism2_hostapd(local->ap, param);
3926 if (ret == 1 || !ap_ioctl) {
3927 if (copy_to_user(p->pointer, param, p->length)) {
3930 } else if (ap_ioctl)
3942 static void prism2_get_drvinfo(struct net_device *dev,
3943 struct ethtool_drvinfo *info)
3945 struct hostap_interface *iface;
3946 local_info_t *local;
3948 iface = netdev_priv(dev);
3949 local = iface->local;
3951 strncpy(info->driver, "hostap", sizeof(info->driver) - 1);
3952 strncpy(info->version, PRISM2_VERSION,
3953 sizeof(info->version) - 1);
3954 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
3955 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
3956 (local->sta_fw_ver >> 8) & 0xff,
3957 local->sta_fw_ver & 0xff);
3960 static struct ethtool_ops prism2_ethtool_ops = {
3961 .get_drvinfo = prism2_get_drvinfo
3965 /* Structures to export the Wireless Handlers */
3967 static const iw_handler prism2_handler[] =
3969 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3970 (iw_handler) prism2_get_name, /* SIOCGIWNAME */
3971 (iw_handler) NULL, /* SIOCSIWNWID */
3972 (iw_handler) NULL, /* SIOCGIWNWID */
3973 (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */
3974 (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */
3975 (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */
3976 (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */
3977 (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */
3978 (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */
3979 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3980 (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */
3981 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3982 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3983 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3984 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
3985 iw_handler_set_spy, /* SIOCSIWSPY */
3986 iw_handler_get_spy, /* SIOCGIWSPY */
3987 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
3988 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
3989 (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */
3990 (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */
3991 (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */
3992 (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */
3993 (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */
3994 (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */
3995 (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */
3996 (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */
3997 (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */
3998 (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */
3999 (iw_handler) NULL, /* -- hole -- */
4000 (iw_handler) NULL, /* -- hole -- */
4001 (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */
4002 (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */
4003 (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */
4004 (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */
4005 (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */
4006 (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */
4007 (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */
4008 (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */
4009 (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */
4010 (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */
4011 (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */
4012 (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */
4013 (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */
4014 (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */
4015 (iw_handler) NULL, /* -- hole -- */
4016 (iw_handler) NULL, /* -- hole -- */
4017 (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */
4018 (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */
4019 (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */
4020 (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */
4021 (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
4022 (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
4023 (iw_handler) NULL, /* SIOCSIWPMKSA */
4024 (iw_handler) NULL, /* -- hole -- */
4027 static const iw_handler prism2_private_handler[] =
4028 { /* SIOCIWFIRSTPRIV + */
4029 (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */
4030 (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
4031 (iw_handler) prism2_ioctl_priv_writemif, /* 2 */
4032 (iw_handler) prism2_ioctl_priv_readmif, /* 3 */
4035 static const struct iw_handler_def hostap_iw_handler_def =
4037 .num_standard = sizeof(prism2_handler) / sizeof(iw_handler),
4038 .num_private = sizeof(prism2_private_handler) / sizeof(iw_handler),
4039 .num_private_args = sizeof(prism2_priv) / sizeof(struct iw_priv_args),
4040 .standard = (iw_handler *) prism2_handler,
4041 .private = (iw_handler *) prism2_private_handler,
4042 .private_args = (struct iw_priv_args *) prism2_priv,
4043 .get_wireless_stats = hostap_get_wireless_stats,
4047 int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4049 struct iwreq *wrq = (struct iwreq *) ifr;
4050 struct hostap_interface *iface;
4051 local_info_t *local;
4054 iface = netdev_priv(dev);
4055 local = iface->local;
4058 /* Private ioctls (iwpriv) that have not yet been converted
4059 * into new wireless extensions API */
4061 case PRISM2_IOCTL_INQUIRE:
4062 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4063 else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
4066 case PRISM2_IOCTL_MONITOR:
4067 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4068 else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
4071 case PRISM2_IOCTL_RESET:
4072 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4073 else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
4076 case PRISM2_IOCTL_WDS_ADD:
4077 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4078 else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
4081 case PRISM2_IOCTL_WDS_DEL:
4082 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4083 else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
4086 case PRISM2_IOCTL_SET_RID_WORD:
4087 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4088 else ret = prism2_ioctl_priv_set_rid_word(dev,
4089 (int *) wrq->u.name);
4092 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
4093 case PRISM2_IOCTL_MACCMD:
4094 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4095 else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
4098 case PRISM2_IOCTL_ADDMAC:
4099 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4100 else ret = ap_control_add_mac(&local->ap->mac_restrictions,
4101 wrq->u.ap_addr.sa_data);
4103 case PRISM2_IOCTL_DELMAC:
4104 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4105 else ret = ap_control_del_mac(&local->ap->mac_restrictions,
4106 wrq->u.ap_addr.sa_data);
4108 case PRISM2_IOCTL_KICKMAC:
4109 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4110 else ret = ap_control_kick_mac(local->ap, local->dev,
4111 wrq->u.ap_addr.sa_data);
4113 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
4116 /* Private ioctls that are not used with iwpriv;
4117 * in SIOCDEVPRIVATE range */
4119 #ifdef PRISM2_DOWNLOAD_SUPPORT
4120 case PRISM2_IOCTL_DOWNLOAD:
4121 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4122 else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
4124 #endif /* PRISM2_DOWNLOAD_SUPPORT */
4126 case PRISM2_IOCTL_HOSTAPD:
4127 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4128 else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);