15 #include <linux/module.h>
17 #include <linux/slab.h>
19 #include <linux/if_arp.h>
21 #include <linux/random.h>
24 #include <linux/rtnetlink.h>
25 #include <linux/wireless.h>
30 #include <asm/uaccess.h>
41 #define TX_TIMEOUT (2 * HZ)
43 #define PRISM2_MAX_FRAME_SIZE 2304
44 #define PRISM2_MIN_MTU 256
46 #define PRISM2_MAX_MTU (PRISM2_MAX_FRAME_SIZE - (6 + 8 ))
50 int type,
int rtnl_locked,
55 struct hostap_interface *iface;
58 dev = alloc_etherdev(
sizeof(
struct hostap_interface));
62 iface = netdev_priv(dev);
66 list_add(&iface->list, &local->hostap_interfaces);
103 int remove_from_list)
105 struct hostap_interface *iface;
110 iface = netdev_priv(dev);
112 if (remove_from_list) {
116 if (dev == iface->local->ddev)
117 iface->local->ddev =
NULL;
118 else if (dev == iface->local->apdev)
119 iface->local->apdev =
NULL;
120 else if (dev == iface->local->stadev)
121 iface->local->stadev =
NULL;
124 unregister_netdevice(dev);
133 static inline int prism2_wds_special_addr(
u8 *
addr)
135 if (addr[0] || addr[1] || addr[2] || addr[3] || addr[4] || addr[5])
147 struct hostap_interface *iface, *
empty, *
match;
149 empty = match =
NULL;
153 if (iface->type != HOSTAP_INTERFACE_WDS)
156 if (prism2_wds_special_addr(iface->u.wds.remote_addr))
158 else if (
memcmp(iface->u.wds.remote_addr, remote_addr,
164 if (!match && empty && !prism2_wds_special_addr(remote_addr)) {
169 local->
dev->name, empty->dev->name);
174 if (!prism2_wds_special_addr(remote_addr)) {
180 if (local->wds_connections >= local->wds_max_connections)
191 local->ddev->name,
"wds%d");
195 iface = netdev_priv(dev);
198 local->wds_connections++;
205 int rtnl_locked,
int do_not_remove)
209 struct hostap_interface *iface, *selected =
NULL;
214 if (iface->type != HOSTAP_INTERFACE_WDS)
217 if (
memcmp(iface->u.wds.remote_addr, remote_addr,
223 if (selected && !do_not_remove)
232 local->wds_connections--;
236 return selected ? 0 : -
ENODEV;
245 struct hostap_tx_callback_info *
entry;
255 entry->idx = local->tx_callback ? local->tx_callback->idx + 1 : 1;
256 entry->next = local->tx_callback;
257 local->tx_callback =
entry;
258 spin_unlock_irqrestore(&local->lock, flags);
267 struct hostap_tx_callback_info *
cb, *
prev =
NULL;
270 cb = local->tx_callback;
271 while (cb !=
NULL && cb->idx != idx) {
277 local->tx_callback = cb->next;
279 prev->next = cb->next;
282 spin_unlock_irqrestore(&local->lock, flags);
291 struct hostap_interface *iface;
293 iface = netdev_priv(dev);
294 return iface->local->func->set_rid(dev, rid, &tmp, 2);
300 struct hostap_interface *iface;
301 char buf[MAX_SSID_LEN + 2];
304 iface = netdev_priv(dev);
306 if (len > MAX_SSID_LEN)
308 memset(buf, 0,
sizeof(buf));
310 memcpy(buf + 2, val, len);
312 return iface->local->func->set_rid(dev, rid, &buf, MAX_SSID_LEN + 2);
339 idx = local->crypt_info.tx_keyidx;
340 if (local->crypt_info.crypt[idx] ==
NULL ||
341 local->crypt_info.crypt[idx]->ops ==
NULL)
343 else if (
strcmp(local->crypt_info.crypt[idx]->ops->name,
"WEP") == 0)
346 encrypt_type =
OTHER;
356 if (encrypt_type !=
NONE || local->privacy_invoked)
361 if (local->open_wep || encrypt_type ==
NONE ||
362 ((local->ieee_802_1x || local->wpa) && local->host_decrypt))
367 if ((encrypt_type !=
NONE || local->privacy_invoked) &&
368 (encrypt_type ==
OTHER || local->host_encrypt))
372 if ((encrypt_type !=
NONE || local->privacy_invoked) &&
373 (encrypt_type ==
OTHER || local->host_decrypt))
378 if (val != old_val &&
385 if (encrypt_type != WEP)
391 len = local->crypt_info.crypt[
idx]->ops->get_key(keybuf,
sizeof(keybuf),
NULL,
392 local->crypt_info.crypt[idx]->priv);
393 if (idx >= 0 && idx < WEP_KEYS && len > 5)
397 memset(keybuf, 0,
sizeof(keybuf));
398 if (local->crypt_info.crypt[i]) {
399 (
void) local->crypt_info.crypt[i]->ops->get_key(
400 keybuf,
sizeof(keybuf),
401 NULL, local->crypt_info.crypt[i]->priv);
403 if (local->func->set_rid(local->
dev,
433 val &= ~(
BIT(2) |
BIT(1));
434 switch (local->antsel_tx) {
457 val &= ~(
BIT(1) |
BIT(0));
458 switch (local->antsel_rx) {
485 switch (local->host_roaming) {
504 int val = local->auth_algs;
510 if (local->sta_fw_ver < PRISM2_FW_VER(0,7,0) &&
516 "failed\n", local->
dev->name, local->auth_algs);
531 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
533 name, status, (status >> 8) & 0x07, status >> 13, status & 1,
560 "tx_control=0x%04x; jiffies=%ld\n",
583 static int hostap_80211_header_parse(
const struct sk_buff *
skb,
584 unsigned char *haddr)
593 if (ieee80211_is_data(fc) && ieee80211_has_a4 (fc))
595 else if (ieee80211_is_cts(fc) || ieee80211_is_ack(fc))
597 else if (ieee80211_is_ctl(fc))
606 struct hostap_interface *iface;
609 PDEBUG(DEBUG_FLOW,
"%s: prism2_close\n", dev->
name);
611 iface = netdev_priv(dev);
612 local = iface->local;
614 if (dev == local->ddev) {
617 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
618 if (!local->hostapd && dev == local->
dev &&
619 (!local->func->card_present || local->func->card_present(local)) &&
624 if (dev == local->
dev) {
625 local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL);
628 if (netif_running(dev)) {
629 netif_stop_queue(dev);
636 #ifndef PRISM2_NO_STATION_MODES
641 module_put(local->hw_module);
643 local->num_dev_open--;
646 local->master_dev_auto_open && local->num_dev_open == 1) {
657 static int prism2_open(
struct net_device *dev)
659 struct hostap_interface *iface;
662 PDEBUG(DEBUG_FLOW,
"%s: prism2_open\n", dev->
name);
664 iface = netdev_priv(dev);
665 local = iface->local;
673 if ((local->func->card_present && !local->func->card_present(local)) ||
674 local->hw_downloading)
677 if (!try_module_get(local->hw_module))
679 local->num_dev_open++;
681 if (!local->dev_enabled && local->func->hw_enable(dev, 1)) {
687 if (!local->dev_enabled)
688 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
689 local->dev_enabled = 1;
691 if (dev != local->
dev && !(local->
dev->flags &
IFF_UP)) {
694 local->master_dev_auto_open = 1;
699 netif_start_queue(dev);
705 static int prism2_set_mac_address(
struct net_device *dev,
void *
p)
707 struct hostap_interface *iface;
712 iface = netdev_priv(dev);
713 local = iface->local;
716 ETH_ALEN) < 0 || local->func->reset_port(dev))
740 local->is_promisc)) {
742 dev->
name, local->is_promisc ?
"en" :
"dis");
747 static void hostap_set_multicast_list(
struct net_device *dev)
754 struct hostap_interface *iface;
757 iface = netdev_priv(dev);
758 local = iface->local;
760 local->is_promisc = 1;
762 local->is_promisc = 0;
770 static int prism2_change_mtu(
struct net_device *dev,
int new_mtu)
780 static void prism2_tx_timeout(
struct net_device *dev)
782 struct hostap_interface *iface;
786 iface = netdev_priv(dev);
787 local = iface->local;
790 netif_stop_queue(local->
dev);
792 local->func->read_regs(dev, &
regs);
794 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
798 local->func->schedule_reset(local);
806 .parse = hostap_80211_header_parse,
814 .ndo_open = prism2_open,
815 .ndo_stop = prism2_close,
817 .ndo_set_mac_address = prism2_set_mac_address,
818 .ndo_set_rx_mode = hostap_set_multicast_list,
819 .ndo_change_mtu = prism2_change_mtu,
820 .ndo_tx_timeout = prism2_tx_timeout,
827 .ndo_open = prism2_open,
828 .ndo_stop = prism2_close,
830 .ndo_set_mac_address = prism2_set_mac_address,
831 .ndo_set_rx_mode = hostap_set_multicast_list,
832 .ndo_change_mtu = prism2_change_mtu,
833 .ndo_tx_timeout = prism2_tx_timeout,
840 .ndo_open = prism2_open,
841 .ndo_stop = prism2_close,
843 .ndo_set_mac_address = prism2_set_mac_address,
844 .ndo_set_rx_mode = hostap_set_multicast_list,
845 .ndo_change_mtu = prism2_change_mtu,
846 .ndo_tx_timeout = prism2_tx_timeout,
853 struct hostap_interface *iface;
855 iface = netdev_priv(dev);
863 iface->wireless_data.spy_data = &iface->spy_data;
864 dev->wireless_data = &iface->wireless_data;
870 case HOSTAP_INTERFACE_AP:
876 case HOSTAP_INTERFACE_MASTER:
884 dev->
mtu = local->mtu;
891 static int hostap_enable_hostapd(
local_info_t *local,
int rtnl_locked)
901 rtnl_locked, local->ddev->name,
903 if (local->apdev ==
NULL)
910 static int hostap_disable_hostapd(
local_info_t *local,
int rtnl_locked)
923 static int hostap_enable_hostapd_sta(
local_info_t *local,
int rtnl_locked)
933 rtnl_locked, local->ddev->name,
935 if (local->stadev ==
NULL)
942 static int hostap_disable_hostapd_sta(
local_info_t *local,
int rtnl_locked)
949 local->stadev =
NULL;
959 if (val < 0 || val > 1)
962 if (local->hostapd == val)
966 ret = hostap_enable_hostapd(local, rtnl_locked);
971 ret = hostap_disable_hostapd(local, rtnl_locked);
984 if (val < 0 || val > 1)
987 if (local->hostapd_sta == val)
991 ret = hostap_enable_hostapd_sta(local, rtnl_locked);
993 local->hostapd_sta = 1;
995 local->hostapd_sta = 0;
996 ret = hostap_disable_hostapd_sta(local, rtnl_locked);
998 local->hostapd_sta = 1;
1008 struct hostap_interface *iface;
1013 iface = netdev_priv(dev);
1014 local = iface->local;
1015 if (!local->sta_fw_ver)
1017 else if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1018 if (local->func->get_rid(local->
dev,
1020 &sq,
sizeof(sq), 1) >= 0) {
1024 local->last_comms_qual_update =
jiffies;
1029 &sq,
sizeof(sq), 1) >= 0) {
1035 local->last_comms_qual_update =
jiffies;
1045 u8 *
body,
size_t bodylen)
1049 struct hostap_skb_tx_data *
meta;
1066 meta = (
struct hostap_skb_tx_data *) skb->cb;
1067 memset(meta, 0,
sizeof(*meta));
1068 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
1069 meta->iface = netdev_priv(dev);
1072 skb_reset_mac_header(skb);
1073 skb_reset_network_header(skb);
1087 is_zero_ether_addr(local->bssid) ||
1101 static int __init hostap_init(
void)
1107 "/proc/net/hostap\n");
1115 static void __exit hostap_exit(
void)
1117 if (hostap_proc !=
NULL) {