2 * Host AP (software wireless LAN access point) driver for
3 * Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. See README and COPYING for
15 #include <linux/config.h>
16 #include <linux/version.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/proc_fs.h>
21 #include <linux/if_arp.h>
22 #include <linux/delay.h>
23 #include <linux/random.h>
24 #include <linux/workqueue.h>
25 #include <linux/kmod.h>
26 #include <linux/rtnetlink.h>
27 #include <linux/wireless.h>
28 #include <net/iw_handler.h>
29 #include <net/ieee80211.h>
30 #include <net/ieee80211_crypt.h>
31 #include <asm/uaccess.h>
33 #include "hostap_wlan.h"
34 #include "hostap_80211.h"
35 #include "hostap_ap.h"
38 MODULE_AUTHOR("Jouni Malinen");
39 MODULE_DESCRIPTION("Host AP common routines");
40 MODULE_LICENSE("GPL");
41 MODULE_VERSION(PRISM2_VERSION);
43 #define TX_TIMEOUT (2 * HZ)
45 #define PRISM2_MAX_FRAME_SIZE 2304
46 #define PRISM2_MIN_MTU 256
48 #define PRISM2_MAX_MTU (PRISM2_MAX_FRAME_SIZE - (6 /* LLC */ + 8 /* WEP */))
52 static int prism2_wds_add(local_info_t *local, u8 *remote_addr,
54 static int prism2_wds_del(local_info_t *local, u8 *remote_addr,
55 int rtnl_locked, int do_not_remove);
58 static int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
59 struct iw_quality qual[], int buf_size,
61 static int prism2_ap_translate_scan(struct net_device *dev, char *buffer);
62 static int prism2_hostapd(struct ap_data *ap,
63 struct prism2_hostapd_param *param);
64 static void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
65 struct ieee80211_crypt_data ***crypt);
66 static void ap_control_kickall(struct ap_data *ap);
67 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
68 static int ap_control_add_mac(struct mac_restrictions *mac_restrictions,
70 static int ap_control_del_mac(struct mac_restrictions *mac_restrictions,
72 static void ap_control_flush_macs(struct mac_restrictions *mac_restrictions);
73 static int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev,
75 #endif /* !PRISM2_NO_KERNEL_IEEE80211_MGMT */
78 static const long freq_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
79 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
80 #define FREQ_COUNT (sizeof(freq_list) / sizeof(freq_list[0]))
83 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
84 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
85 static unsigned char rfc1042_header[] =
86 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
87 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
88 static unsigned char bridge_tunnel_header[] =
89 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
90 /* No encapsulation header if EtherType < 0x600 (=length) */
93 /* FIX: these could be compiled separately and linked together to hostap.o */
94 #include "hostap_ap.c"
95 #include "hostap_info.c"
96 #include "hostap_ioctl.c"
97 #include "hostap_proc.c"
98 #include "hostap_80211_rx.c"
99 #include "hostap_80211_tx.c"
102 struct net_device * hostap_add_interface(struct local_info *local,
103 int type, int rtnl_locked,
107 struct net_device *dev, *mdev;
108 struct hostap_interface *iface;
111 dev = alloc_etherdev(sizeof(struct hostap_interface));
115 iface = netdev_priv(dev);
117 iface->local = local;
119 list_add(&iface->list, &local->hostap_interfaces);
122 memcpy(dev->dev_addr, mdev->dev_addr, ETH_ALEN);
123 dev->base_addr = mdev->base_addr;
124 dev->irq = mdev->irq;
125 dev->mem_start = mdev->mem_start;
126 dev->mem_end = mdev->mem_end;
128 hostap_setup_dev(dev, local, 0);
129 dev->destructor = free_netdev;
131 sprintf(dev->name, "%s%s", prefix, name);
136 if (strchr(dev->name, '%'))
137 ret = dev_alloc_name(dev, dev->name);
139 SET_NETDEV_DEV(dev, mdev->class_dev.dev);
141 ret = register_netdevice(dev);
147 printk(KERN_WARNING "%s: failed to add new netdevice!\n",
153 printk(KERN_DEBUG "%s: registered netdevice %s\n",
154 mdev->name, dev->name);
160 void hostap_remove_interface(struct net_device *dev, int rtnl_locked,
161 int remove_from_list)
163 struct hostap_interface *iface;
168 iface = netdev_priv(dev);
170 if (remove_from_list) {
171 list_del(&iface->list);
174 if (dev == iface->local->ddev)
175 iface->local->ddev = NULL;
176 else if (dev == iface->local->apdev)
177 iface->local->apdev = NULL;
178 else if (dev == iface->local->stadev)
179 iface->local->stadev = NULL;
182 unregister_netdevice(dev);
184 unregister_netdev(dev);
186 /* dev->destructor = free_netdev() will free the device data, including
187 * private data, when removing the device */
191 static inline int prism2_wds_special_addr(u8 *addr)
193 if (addr[0] || addr[1] || addr[2] || addr[3] || addr[4] || addr[5])
200 static int prism2_wds_add(local_info_t *local, u8 *remote_addr,
203 struct net_device *dev;
204 struct list_head *ptr;
205 struct hostap_interface *iface, *empty, *match;
207 empty = match = NULL;
208 read_lock_bh(&local->iface_lock);
209 list_for_each(ptr, &local->hostap_interfaces) {
210 iface = list_entry(ptr, struct hostap_interface, list);
211 if (iface->type != HOSTAP_INTERFACE_WDS)
214 if (prism2_wds_special_addr(iface->u.wds.remote_addr))
216 else if (memcmp(iface->u.wds.remote_addr, remote_addr,
222 if (!match && empty && !prism2_wds_special_addr(remote_addr)) {
223 /* take pre-allocated entry into use */
224 memcpy(empty->u.wds.remote_addr, remote_addr, ETH_ALEN);
225 read_unlock_bh(&local->iface_lock);
226 printk(KERN_DEBUG "%s: using pre-allocated WDS netdevice %s\n",
227 local->dev->name, empty->dev->name);
230 read_unlock_bh(&local->iface_lock);
232 if (!prism2_wds_special_addr(remote_addr)) {
235 hostap_add_sta(local->ap, remote_addr);
238 if (local->wds_connections >= local->wds_max_connections)
241 /* verify that there is room for wds# postfix in the interface name */
242 if (strlen(local->dev->name) > IFNAMSIZ - 5) {
243 printk(KERN_DEBUG "'%s' too long base device name\n",
248 dev = hostap_add_interface(local, HOSTAP_INTERFACE_WDS, rtnl_locked,
249 local->ddev->name, "wds%d");
253 iface = netdev_priv(dev);
254 memcpy(iface->u.wds.remote_addr, remote_addr, ETH_ALEN);
256 local->wds_connections++;
262 static int prism2_wds_del(local_info_t *local, u8 *remote_addr,
263 int rtnl_locked, int do_not_remove)
266 struct list_head *ptr;
267 struct hostap_interface *iface, *selected = NULL;
269 write_lock_irqsave(&local->iface_lock, flags);
270 list_for_each(ptr, &local->hostap_interfaces) {
271 iface = list_entry(ptr, struct hostap_interface, list);
272 if (iface->type != HOSTAP_INTERFACE_WDS)
275 if (memcmp(iface->u.wds.remote_addr, remote_addr,
281 if (selected && !do_not_remove)
282 list_del(&selected->list);
283 write_unlock_irqrestore(&local->iface_lock, flags);
287 memset(selected->u.wds.remote_addr, 0, ETH_ALEN);
289 hostap_remove_interface(selected->dev, rtnl_locked, 0);
290 local->wds_connections--;
294 return selected ? 0 : -ENODEV;
298 u16 hostap_tx_callback_register(local_info_t *local,
299 void (*func)(struct sk_buff *, int ok, void *),
303 struct hostap_tx_callback_info *entry;
305 entry = (struct hostap_tx_callback_info *) kmalloc(sizeof(*entry),
313 spin_lock_irqsave(&local->lock, flags);
314 entry->idx = local->tx_callback ? local->tx_callback->idx + 1 : 1;
315 entry->next = local->tx_callback;
316 local->tx_callback = entry;
317 spin_unlock_irqrestore(&local->lock, flags);
323 int hostap_tx_callback_unregister(local_info_t *local, u16 idx)
326 struct hostap_tx_callback_info *cb, *prev = NULL;
328 spin_lock_irqsave(&local->lock, flags);
329 cb = local->tx_callback;
330 while (cb != NULL && cb->idx != idx) {
336 local->tx_callback = cb->next;
338 prev->next = cb->next;
341 spin_unlock_irqrestore(&local->lock, flags);
347 /* val is in host byte order */
348 int hostap_set_word(struct net_device *dev, int rid, u16 val)
350 struct hostap_interface *iface;
351 u16 tmp = cpu_to_le16(val);
352 iface = netdev_priv(dev);
353 return iface->local->func->set_rid(dev, rid, &tmp, 2);
357 int hostap_set_string(struct net_device *dev, int rid, const char *val)
359 struct hostap_interface *iface;
360 char buf[MAX_SSID_LEN + 2];
363 iface = netdev_priv(dev);
365 if (len > MAX_SSID_LEN)
367 memset(buf, 0, sizeof(buf));
368 buf[0] = len; /* little endian 16 bit word */
369 memcpy(buf + 2, val, len);
371 return iface->local->func->set_rid(dev, rid, &buf, MAX_SSID_LEN + 2);
375 u16 hostap_get_porttype(local_info_t *local)
377 if (local->iw_mode == IW_MODE_ADHOC && local->pseudo_adhoc)
378 return HFA384X_PORTTYPE_PSEUDO_IBSS;
379 if (local->iw_mode == IW_MODE_ADHOC)
380 return HFA384X_PORTTYPE_IBSS;
381 if (local->iw_mode == IW_MODE_INFRA)
382 return HFA384X_PORTTYPE_BSS;
383 if (local->iw_mode == IW_MODE_REPEAT)
384 return HFA384X_PORTTYPE_WDS;
385 if (local->iw_mode == IW_MODE_MONITOR)
386 return HFA384X_PORTTYPE_PSEUDO_IBSS;
387 return HFA384X_PORTTYPE_HOSTAP;
391 int hostap_set_encryption(local_info_t *local)
394 int i, keylen, len, idx;
395 char keybuf[WEP_KEY_LEN + 1];
396 enum { NONE, WEP, OTHER } encrypt_type;
398 idx = local->tx_keyidx;
399 if (local->crypt[idx] == NULL || local->crypt[idx]->ops == NULL)
401 else if (strcmp(local->crypt[idx]->ops->name, "WEP") == 0)
404 encrypt_type = OTHER;
406 if (local->func->get_rid(local->dev, HFA384X_RID_CNFWEPFLAGS, &val, 2,
408 printk(KERN_DEBUG "Could not read current WEP flags.\n");
414 if (encrypt_type != NONE || local->privacy_invoked)
415 val |= HFA384X_WEPFLAGS_PRIVACYINVOKED;
417 val &= ~HFA384X_WEPFLAGS_PRIVACYINVOKED;
419 if (local->open_wep || encrypt_type == NONE ||
420 ((local->ieee_802_1x || local->wpa) && local->host_decrypt))
421 val &= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
423 val |= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
425 if ((encrypt_type != NONE || local->privacy_invoked) &&
426 (encrypt_type == OTHER || local->host_encrypt))
427 val |= HFA384X_WEPFLAGS_HOSTENCRYPT;
429 val &= ~HFA384X_WEPFLAGS_HOSTENCRYPT;
430 if ((encrypt_type != NONE || local->privacy_invoked) &&
431 (encrypt_type == OTHER || local->host_decrypt))
432 val |= HFA384X_WEPFLAGS_HOSTDECRYPT;
434 val &= ~HFA384X_WEPFLAGS_HOSTDECRYPT;
436 if (val != old_val &&
437 hostap_set_word(local->dev, HFA384X_RID_CNFWEPFLAGS, val)) {
438 printk(KERN_DEBUG "Could not write new WEP flags (0x%x)\n",
443 if (encrypt_type != WEP)
446 /* 104-bit support seems to require that all the keys are set to the
448 keylen = 6; /* first 5 octets */
449 len = local->crypt[idx]->ops->get_key(keybuf, sizeof(keybuf),
450 NULL, local->crypt[idx]->priv);
451 if (idx >= 0 && idx < WEP_KEYS && len > 5)
452 keylen = WEP_KEY_LEN + 1; /* first 13 octets */
454 for (i = 0; i < WEP_KEYS; i++) {
455 memset(keybuf, 0, sizeof(keybuf));
456 if (local->crypt[i]) {
457 (void) local->crypt[i]->ops->get_key(
458 keybuf, sizeof(keybuf),
459 NULL, local->crypt[i]->priv);
461 if (local->func->set_rid(local->dev,
462 HFA384X_RID_CNFDEFAULTKEY0 + i,
464 printk(KERN_DEBUG "Could not set key %d (len=%d)\n",
469 if (hostap_set_word(local->dev, HFA384X_RID_CNFWEPDEFAULTKEYID, idx)) {
470 printk(KERN_DEBUG "Could not set default keyid %d\n", idx);
477 printk(KERN_DEBUG "%s: encryption setup failed\n", local->dev->name);
482 int hostap_set_antsel(local_info_t *local)
487 if (local->antsel_tx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
488 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
489 HFA386X_CR_TX_CONFIGURE,
491 val &= ~(BIT(2) | BIT(1));
492 switch (local->antsel_tx) {
493 case HOSTAP_ANTSEL_DIVERSITY:
496 case HOSTAP_ANTSEL_LOW:
498 case HOSTAP_ANTSEL_HIGH:
503 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
504 HFA386X_CR_TX_CONFIGURE, &val, NULL)) {
505 printk(KERN_INFO "%s: setting TX AntSel failed\n",
511 if (local->antsel_rx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
512 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
513 HFA386X_CR_RX_CONFIGURE,
515 val &= ~(BIT(1) | BIT(0));
516 switch (local->antsel_rx) {
517 case HOSTAP_ANTSEL_DIVERSITY:
519 case HOSTAP_ANTSEL_LOW:
522 case HOSTAP_ANTSEL_HIGH:
523 val |= BIT(0) | BIT(1);
527 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
528 HFA386X_CR_RX_CONFIGURE, &val, NULL)) {
529 printk(KERN_INFO "%s: setting RX AntSel failed\n",
539 int hostap_set_roaming(local_info_t *local)
543 switch (local->host_roaming) {
545 val = HFA384X_ROAMING_HOST;
548 val = HFA384X_ROAMING_DISABLED;
552 val = HFA384X_ROAMING_FIRMWARE;
556 return hostap_set_word(local->dev, HFA384X_RID_CNFROAMINGMODE, val);
560 int hostap_set_auth_algs(local_info_t *local)
562 int val = local->auth_algs;
563 /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication
564 * set to include both Open and Shared Key flags. It tries to use
565 * Shared Key authentication in that case even if WEP keys are not
566 * configured.. STA f/w v0.7.6 is able to handle such configuration,
567 * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */
568 if (local->sta_fw_ver < PRISM2_FW_VER(0,7,0) &&
569 val != PRISM2_AUTH_OPEN && val != PRISM2_AUTH_SHARED_KEY)
570 val = PRISM2_AUTH_OPEN;
572 if (hostap_set_word(local->dev, HFA384X_RID_CNFAUTHENTICATION, val)) {
573 printk(KERN_INFO "%s: cnfAuthentication setting to 0x%x "
574 "failed\n", local->dev->name, local->auth_algs);
582 void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx)
586 status = __le16_to_cpu(rx->status);
588 printk(KERN_DEBUG "%s: RX status=0x%04x (port=%d, type=%d, "
589 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
591 name, status, (status >> 8) & 0x07, status >> 13, status & 1,
592 rx->silence, rx->signal, rx->rate, rx->rxflow, jiffies);
594 fc = __le16_to_cpu(rx->frame_control);
595 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
597 fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4,
598 __le16_to_cpu(rx->duration_id), __le16_to_cpu(rx->seq_ctrl),
599 __le16_to_cpu(rx->data_len),
600 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
601 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
603 printk(KERN_DEBUG " A1=" MACSTR " A2=" MACSTR " A3=" MACSTR " A4="
605 MAC2STR(rx->addr1), MAC2STR(rx->addr2), MAC2STR(rx->addr3),
608 printk(KERN_DEBUG " dst=" MACSTR " src=" MACSTR " len=%d\n",
609 MAC2STR(rx->dst_addr), MAC2STR(rx->src_addr),
610 __be16_to_cpu(rx->len));
614 void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
618 printk(KERN_DEBUG "%s: TX status=0x%04x retry_count=%d tx_rate=%d "
619 "tx_control=0x%04x; jiffies=%ld\n",
620 name, __le16_to_cpu(tx->status), tx->retry_count, tx->tx_rate,
621 __le16_to_cpu(tx->tx_control), jiffies);
623 fc = __le16_to_cpu(tx->frame_control);
624 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
626 fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4,
627 __le16_to_cpu(tx->duration_id), __le16_to_cpu(tx->seq_ctrl),
628 __le16_to_cpu(tx->data_len),
629 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
630 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
632 printk(KERN_DEBUG " A1=" MACSTR " A2=" MACSTR " A3=" MACSTR " A4="
634 MAC2STR(tx->addr1), MAC2STR(tx->addr2), MAC2STR(tx->addr3),
637 printk(KERN_DEBUG " dst=" MACSTR " src=" MACSTR " len=%d\n",
638 MAC2STR(tx->dst_addr), MAC2STR(tx->src_addr),
639 __be16_to_cpu(tx->len));
643 int hostap_80211_header_parse(struct sk_buff *skb, unsigned char *haddr)
645 memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); /* addr2 */
650 int hostap_80211_prism_header_parse(struct sk_buff *skb, unsigned char *haddr)
652 if (*(u32 *)skb->mac.raw == LWNG_CAP_DID_BASE) {
653 memcpy(haddr, skb->mac.raw +
654 sizeof(struct linux_wlan_ng_prism_hdr) + 10,
655 ETH_ALEN); /* addr2 */
656 } else { /* (*(u32 *)skb->mac.raw == htonl(LWNG_CAPHDR_VERSION)) */
657 memcpy(haddr, skb->mac.raw +
658 sizeof(struct linux_wlan_ng_cap_hdr) + 10,
659 ETH_ALEN); /* addr2 */
665 int hostap_80211_get_hdrlen(u16 fc)
669 switch (WLAN_FC_GET_TYPE(fc)) {
670 case IEEE80211_FTYPE_DATA:
671 if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
672 hdrlen = 30; /* Addr4 */
674 case IEEE80211_FTYPE_CTL:
675 switch (WLAN_FC_GET_STYPE(fc)) {
676 case IEEE80211_STYPE_CTS:
677 case IEEE80211_STYPE_ACK:
691 struct net_device_stats *hostap_get_stats(struct net_device *dev)
693 struct hostap_interface *iface;
694 iface = netdev_priv(dev);
695 return &iface->stats;
699 static int prism2_close(struct net_device *dev)
701 struct hostap_interface *iface;
704 PDEBUG(DEBUG_FLOW, "%s: prism2_close\n", dev->name);
706 iface = netdev_priv(dev);
707 local = iface->local;
709 if (dev == local->ddev) {
710 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
712 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
713 if (!local->hostapd && dev == local->dev &&
714 (!local->func->card_present || local->func->card_present(local)) &&
715 local->hw_ready && local->ap && local->iw_mode == IW_MODE_MASTER)
716 hostap_deauth_all_stas(dev, local->ap, 1);
717 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
719 if (dev == local->dev) {
720 local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL);
723 if (netif_running(dev)) {
724 netif_stop_queue(dev);
725 netif_device_detach(dev);
728 flush_scheduled_work();
730 module_put(local->hw_module);
732 local->num_dev_open--;
734 if (dev != local->dev && local->dev->flags & IFF_UP &&
735 local->master_dev_auto_open && local->num_dev_open == 1) {
736 /* Close master radio interface automatically if it was also
737 * opened automatically and we are now closing the last
738 * remaining non-master device. */
739 dev_close(local->dev);
746 static int prism2_open(struct net_device *dev)
748 struct hostap_interface *iface;
751 PDEBUG(DEBUG_FLOW, "%s: prism2_open\n", dev->name);
753 iface = netdev_priv(dev);
754 local = iface->local;
757 printk(KERN_DEBUG "%s: could not set interface UP - no PRI "
762 if ((local->func->card_present && !local->func->card_present(local)) ||
763 local->hw_downloading)
766 if (!try_module_get(local->hw_module))
768 local->num_dev_open++;
770 if (!local->dev_enabled && local->func->hw_enable(dev, 1)) {
771 printk(KERN_WARNING "%s: could not enable MAC port\n",
776 if (!local->dev_enabled)
777 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
778 local->dev_enabled = 1;
780 if (dev != local->dev && !(local->dev->flags & IFF_UP)) {
781 /* Master radio interface is needed for all operation, so open
782 * it automatically when any virtual net_device is opened. */
783 local->master_dev_auto_open = 1;
784 dev_open(local->dev);
787 netif_device_attach(dev);
788 netif_start_queue(dev);
794 static int prism2_set_mac_address(struct net_device *dev, void *p)
796 struct hostap_interface *iface;
798 struct list_head *ptr;
799 struct sockaddr *addr = p;
801 iface = netdev_priv(dev);
802 local = iface->local;
804 if (local->func->set_rid(dev, HFA384X_RID_CNFOWNMACADDR, addr->sa_data,
805 ETH_ALEN) < 0 || local->func->reset_port(dev))
808 read_lock_bh(&local->iface_lock);
809 list_for_each(ptr, &local->hostap_interfaces) {
810 iface = list_entry(ptr, struct hostap_interface, list);
811 memcpy(iface->dev->dev_addr, addr->sa_data, ETH_ALEN);
813 memcpy(local->dev->dev_addr, addr->sa_data, ETH_ALEN);
814 read_unlock_bh(&local->iface_lock);
820 /* TODO: to be further implemented as soon as Prism2 fully supports
821 * GroupAddresses and correct documentation is available */
822 void hostap_set_multicast_list_queue(void *data)
824 struct net_device *dev = (struct net_device *) data;
825 struct hostap_interface *iface;
828 iface = netdev_priv(dev);
829 local = iface->local;
830 if (hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
831 local->is_promisc)) {
832 printk(KERN_INFO "%s: %sabling promiscuous mode failed\n",
833 dev->name, local->is_promisc ? "en" : "dis");
838 static void hostap_set_multicast_list(struct net_device *dev)
841 /* FIX: promiscuous mode seems to be causing a lot of problems with
842 * some station firmware versions (FCSErr frames, invalid MACPort, etc.
843 * corrupted incoming frames). This code is now commented out while the
844 * problems are investigated. */
845 struct hostap_interface *iface;
848 iface = netdev_priv(dev);
849 local = iface->local;
850 if ((dev->flags & IFF_ALLMULTI) || (dev->flags & IFF_PROMISC)) {
851 local->is_promisc = 1;
853 local->is_promisc = 0;
856 schedule_work(&local->set_multicast_list_queue);
861 static int prism2_change_mtu(struct net_device *dev, int new_mtu)
863 if (new_mtu < PRISM2_MIN_MTU || new_mtu > PRISM2_MAX_MTU)
871 static void prism2_tx_timeout(struct net_device *dev)
873 struct hostap_interface *iface;
875 struct hfa384x_regs regs;
877 iface = netdev_priv(dev);
878 local = iface->local;
880 printk(KERN_WARNING "%s Tx timed out! Resetting card\n", dev->name);
881 netif_stop_queue(local->dev);
883 local->func->read_regs(dev, ®s);
884 printk(KERN_DEBUG "%s: CMD=%04x EVSTAT=%04x "
885 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
886 dev->name, regs.cmd, regs.evstat, regs.offset0, regs.offset1,
889 local->func->schedule_reset(local);
893 void hostap_setup_dev(struct net_device *dev, local_info_t *local,
896 struct hostap_interface *iface;
898 iface = netdev_priv(dev);
901 /* kernel callbacks */
902 dev->get_stats = hostap_get_stats;
904 /* Currently, we point to the proper spy_data only on
905 * the main_dev. This could be fixed. Jean II */
906 iface->wireless_data.spy_data = &iface->spy_data;
907 dev->wireless_data = &iface->wireless_data;
909 dev->wireless_handlers =
910 (struct iw_handler_def *) &hostap_iw_handler_def;
911 dev->do_ioctl = hostap_ioctl;
912 dev->open = prism2_open;
913 dev->stop = prism2_close;
914 dev->hard_start_xmit = hostap_data_start_xmit;
915 dev->set_mac_address = prism2_set_mac_address;
916 dev->set_multicast_list = hostap_set_multicast_list;
917 dev->change_mtu = prism2_change_mtu;
918 dev->tx_timeout = prism2_tx_timeout;
919 dev->watchdog_timeo = TX_TIMEOUT;
921 dev->mtu = local->mtu;
923 /* use main radio device queue */
924 dev->tx_queue_len = 0;
927 SET_ETHTOOL_OPS(dev, &prism2_ethtool_ops);
929 netif_stop_queue(dev);
933 static int hostap_enable_hostapd(local_info_t *local, int rtnl_locked)
935 struct net_device *dev = local->dev;
940 printk(KERN_DEBUG "%s: enabling hostapd mode\n", dev->name);
942 local->apdev = hostap_add_interface(local, HOSTAP_INTERFACE_AP,
943 rtnl_locked, local->ddev->name,
945 if (local->apdev == NULL)
948 local->apdev->hard_start_xmit = hostap_mgmt_start_xmit;
949 local->apdev->type = ARPHRD_IEEE80211;
950 local->apdev->hard_header_parse = hostap_80211_header_parse;
956 static int hostap_disable_hostapd(local_info_t *local, int rtnl_locked)
958 struct net_device *dev = local->dev;
960 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
962 hostap_remove_interface(local->apdev, rtnl_locked, 1);
969 static int hostap_enable_hostapd_sta(local_info_t *local, int rtnl_locked)
971 struct net_device *dev = local->dev;
976 printk(KERN_DEBUG "%s: enabling hostapd STA mode\n", dev->name);
978 local->stadev = hostap_add_interface(local, HOSTAP_INTERFACE_STA,
979 rtnl_locked, local->ddev->name,
981 if (local->stadev == NULL)
988 static int hostap_disable_hostapd_sta(local_info_t *local, int rtnl_locked)
990 struct net_device *dev = local->dev;
992 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
994 hostap_remove_interface(local->stadev, rtnl_locked, 1);
995 local->stadev = NULL;
1001 int hostap_set_hostapd(local_info_t *local, int val, int rtnl_locked)
1005 if (val < 0 || val > 1)
1008 if (local->hostapd == val)
1012 ret = hostap_enable_hostapd(local, rtnl_locked);
1017 ret = hostap_disable_hostapd(local, rtnl_locked);
1026 int hostap_set_hostapd_sta(local_info_t *local, int val, int rtnl_locked)
1030 if (val < 0 || val > 1)
1033 if (local->hostapd_sta == val)
1037 ret = hostap_enable_hostapd_sta(local, rtnl_locked);
1039 local->hostapd_sta = 1;
1041 local->hostapd_sta = 0;
1042 ret = hostap_disable_hostapd_sta(local, rtnl_locked);
1044 local->hostapd_sta = 1;
1052 int prism2_update_comms_qual(struct net_device *dev)
1054 struct hostap_interface *iface;
1055 local_info_t *local;
1057 struct hfa384x_comms_quality sq;
1059 iface = netdev_priv(dev);
1060 local = iface->local;
1061 if (!local->sta_fw_ver)
1063 else if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1064 if (local->func->get_rid(local->dev,
1065 HFA384X_RID_DBMCOMMSQUALITY,
1066 &sq, sizeof(sq), 1) >= 0) {
1067 local->comms_qual = (s16) le16_to_cpu(sq.comm_qual);
1068 local->avg_signal = (s16) le16_to_cpu(sq.signal_level);
1069 local->avg_noise = (s16) le16_to_cpu(sq.noise_level);
1070 local->last_comms_qual_update = jiffies;
1074 if (local->func->get_rid(local->dev, HFA384X_RID_COMMSQUALITY,
1075 &sq, sizeof(sq), 1) >= 0) {
1076 local->comms_qual = le16_to_cpu(sq.comm_qual);
1077 local->avg_signal = HFA384X_LEVEL_TO_dBm(
1078 le16_to_cpu(sq.signal_level));
1079 local->avg_noise = HFA384X_LEVEL_TO_dBm(
1080 le16_to_cpu(sq.noise_level));
1081 local->last_comms_qual_update = jiffies;
1090 int prism2_sta_send_mgmt(local_info_t *local, u8 *dst, u16 stype,
1091 u8 *body, size_t bodylen)
1093 struct sk_buff *skb;
1094 struct hostap_ieee80211_mgmt *mgmt;
1095 struct hostap_skb_tx_data *meta;
1096 struct net_device *dev = local->dev;
1098 skb = dev_alloc_skb(IEEE80211_MGMT_HDR_LEN + bodylen);
1102 mgmt = (struct hostap_ieee80211_mgmt *)
1103 skb_put(skb, IEEE80211_MGMT_HDR_LEN);
1104 memset(mgmt, 0, IEEE80211_MGMT_HDR_LEN);
1105 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
1106 memcpy(mgmt->da, dst, ETH_ALEN);
1107 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1108 memcpy(mgmt->bssid, dst, ETH_ALEN);
1110 memcpy(skb_put(skb, bodylen), body, bodylen);
1112 meta = (struct hostap_skb_tx_data *) skb->cb;
1113 memset(meta, 0, sizeof(*meta));
1114 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
1115 meta->iface = netdev_priv(dev);
1118 skb->mac.raw = skb->nh.raw = skb->data;
1119 dev_queue_xmit(skb);
1125 int prism2_sta_deauth(local_info_t *local, u16 reason)
1127 union iwreq_data wrqu;
1130 if (local->iw_mode != IW_MODE_INFRA ||
1131 memcmp(local->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0 ||
1132 memcmp(local->bssid, "\x44\x44\x44\x44\x44\x44", ETH_ALEN) == 0)
1135 reason = cpu_to_le16(reason);
1136 ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH,
1138 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1139 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
1144 struct proc_dir_entry *hostap_proc;
1146 static int __init hostap_init(void)
1148 if (proc_net != NULL) {
1149 hostap_proc = proc_mkdir("hostap", proc_net);
1151 printk(KERN_WARNING "Failed to mkdir "
1152 "/proc/net/hostap\n");
1160 static void __exit hostap_exit(void)
1162 if (hostap_proc != NULL) {
1164 remove_proc_entry("hostap", proc_net);
1169 EXPORT_SYMBOL(hostap_set_word);
1170 EXPORT_SYMBOL(hostap_set_string);
1171 EXPORT_SYMBOL(hostap_get_porttype);
1172 EXPORT_SYMBOL(hostap_set_encryption);
1173 EXPORT_SYMBOL(hostap_set_antsel);
1174 EXPORT_SYMBOL(hostap_set_roaming);
1175 EXPORT_SYMBOL(hostap_set_auth_algs);
1176 EXPORT_SYMBOL(hostap_dump_rx_header);
1177 EXPORT_SYMBOL(hostap_dump_tx_header);
1178 EXPORT_SYMBOL(hostap_80211_header_parse);
1179 EXPORT_SYMBOL(hostap_80211_prism_header_parse);
1180 EXPORT_SYMBOL(hostap_80211_get_hdrlen);
1181 EXPORT_SYMBOL(hostap_get_stats);
1182 EXPORT_SYMBOL(hostap_setup_dev);
1183 EXPORT_SYMBOL(hostap_proc);
1184 EXPORT_SYMBOL(hostap_set_multicast_list_queue);
1185 EXPORT_SYMBOL(hostap_set_hostapd);
1186 EXPORT_SYMBOL(hostap_set_hostapd_sta);
1187 EXPORT_SYMBOL(hostap_add_interface);
1188 EXPORT_SYMBOL(hostap_remove_interface);
1189 EXPORT_SYMBOL(prism2_update_comms_qual);
1191 module_init(hostap_init);
1192 module_exit(hostap_exit);