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 <j@w1.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/module.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/proc_fs.h>
19 #include <linux/if_arp.h>
20 #include <linux/delay.h>
21 #include <linux/random.h>
22 #include <linux/workqueue.h>
23 #include <linux/kmod.h>
24 #include <linux/rtnetlink.h>
25 #include <linux/wireless.h>
26 #include <linux/etherdevice.h>
27 #include <net/net_namespace.h>
28 #include <net/iw_handler.h>
29 #include <net/lib80211.h>
30 #include <asm/uaccess.h>
32 #include "hostap_wlan.h"
33 #include "hostap_80211.h"
34 #include "hostap_ap.h"
37 MODULE_AUTHOR("Jouni Malinen");
38 MODULE_DESCRIPTION("Host AP common routines");
39 MODULE_LICENSE("GPL");
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 /* LLC */ + 8 /* WEP */))
49 struct net_device * hostap_add_interface(struct local_info *local,
50 int type, int rtnl_locked,
54 struct net_device *dev, *mdev;
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);
69 memcpy(dev->dev_addr, mdev->dev_addr, ETH_ALEN);
70 dev->base_addr = mdev->base_addr;
72 dev->mem_start = mdev->mem_start;
73 dev->mem_end = mdev->mem_end;
75 hostap_setup_dev(dev, local, type);
76 dev->destructor = free_netdev;
78 sprintf(dev->name, "%s%s", prefix, name);
83 if (strchr(dev->name, '%'))
84 ret = dev_alloc_name(dev, dev->name);
86 SET_NETDEV_DEV(dev, mdev->dev.parent);
88 ret = register_netdevice(dev);
94 printk(KERN_WARNING "%s: failed to add new netdevice!\n",
100 printk(KERN_DEBUG "%s: registered netdevice %s\n",
101 mdev->name, dev->name);
107 void hostap_remove_interface(struct net_device *dev, int rtnl_locked,
108 int remove_from_list)
110 struct hostap_interface *iface;
115 iface = netdev_priv(dev);
117 if (remove_from_list) {
118 list_del(&iface->list);
121 if (dev == iface->local->ddev)
122 iface->local->ddev = NULL;
123 else if (dev == iface->local->apdev)
124 iface->local->apdev = NULL;
125 else if (dev == iface->local->stadev)
126 iface->local->stadev = NULL;
129 unregister_netdevice(dev);
131 unregister_netdev(dev);
133 /* dev->destructor = free_netdev() will free the device data, including
134 * private data, when removing the device */
138 static inline int prism2_wds_special_addr(u8 *addr)
140 if (addr[0] || addr[1] || addr[2] || addr[3] || addr[4] || addr[5])
147 int prism2_wds_add(local_info_t *local, u8 *remote_addr,
150 struct net_device *dev;
151 struct list_head *ptr;
152 struct hostap_interface *iface, *empty, *match;
154 empty = match = NULL;
155 read_lock_bh(&local->iface_lock);
156 list_for_each(ptr, &local->hostap_interfaces) {
157 iface = list_entry(ptr, struct hostap_interface, list);
158 if (iface->type != HOSTAP_INTERFACE_WDS)
161 if (prism2_wds_special_addr(iface->u.wds.remote_addr))
163 else if (memcmp(iface->u.wds.remote_addr, remote_addr,
169 if (!match && empty && !prism2_wds_special_addr(remote_addr)) {
170 /* take pre-allocated entry into use */
171 memcpy(empty->u.wds.remote_addr, remote_addr, ETH_ALEN);
172 read_unlock_bh(&local->iface_lock);
173 printk(KERN_DEBUG "%s: using pre-allocated WDS netdevice %s\n",
174 local->dev->name, empty->dev->name);
177 read_unlock_bh(&local->iface_lock);
179 if (!prism2_wds_special_addr(remote_addr)) {
182 hostap_add_sta(local->ap, remote_addr);
185 if (local->wds_connections >= local->wds_max_connections)
188 /* verify that there is room for wds# postfix in the interface name */
189 if (strlen(local->dev->name) > IFNAMSIZ - 5) {
190 printk(KERN_DEBUG "'%s' too long base device name\n",
195 dev = hostap_add_interface(local, HOSTAP_INTERFACE_WDS, rtnl_locked,
196 local->ddev->name, "wds%d");
200 iface = netdev_priv(dev);
201 memcpy(iface->u.wds.remote_addr, remote_addr, ETH_ALEN);
203 local->wds_connections++;
209 int prism2_wds_del(local_info_t *local, u8 *remote_addr,
210 int rtnl_locked, int do_not_remove)
213 struct list_head *ptr;
214 struct hostap_interface *iface, *selected = NULL;
216 write_lock_irqsave(&local->iface_lock, flags);
217 list_for_each(ptr, &local->hostap_interfaces) {
218 iface = list_entry(ptr, struct hostap_interface, list);
219 if (iface->type != HOSTAP_INTERFACE_WDS)
222 if (memcmp(iface->u.wds.remote_addr, remote_addr,
228 if (selected && !do_not_remove)
229 list_del(&selected->list);
230 write_unlock_irqrestore(&local->iface_lock, flags);
234 memset(selected->u.wds.remote_addr, 0, ETH_ALEN);
236 hostap_remove_interface(selected->dev, rtnl_locked, 0);
237 local->wds_connections--;
241 return selected ? 0 : -ENODEV;
245 u16 hostap_tx_callback_register(local_info_t *local,
246 void (*func)(struct sk_buff *, int ok, void *),
250 struct hostap_tx_callback_info *entry;
252 entry = kmalloc(sizeof(*entry),
260 spin_lock_irqsave(&local->lock, flags);
261 entry->idx = local->tx_callback ? local->tx_callback->idx + 1 : 1;
262 entry->next = local->tx_callback;
263 local->tx_callback = entry;
264 spin_unlock_irqrestore(&local->lock, flags);
270 int hostap_tx_callback_unregister(local_info_t *local, u16 idx)
273 struct hostap_tx_callback_info *cb, *prev = NULL;
275 spin_lock_irqsave(&local->lock, flags);
276 cb = local->tx_callback;
277 while (cb != NULL && cb->idx != idx) {
283 local->tx_callback = cb->next;
285 prev->next = cb->next;
288 spin_unlock_irqrestore(&local->lock, flags);
294 /* val is in host byte order */
295 int hostap_set_word(struct net_device *dev, int rid, u16 val)
297 struct hostap_interface *iface;
298 __le16 tmp = cpu_to_le16(val);
299 iface = netdev_priv(dev);
300 return iface->local->func->set_rid(dev, rid, &tmp, 2);
304 int hostap_set_string(struct net_device *dev, int rid, const char *val)
306 struct hostap_interface *iface;
307 char buf[MAX_SSID_LEN + 2];
310 iface = netdev_priv(dev);
312 if (len > MAX_SSID_LEN)
314 memset(buf, 0, sizeof(buf));
315 buf[0] = len; /* little endian 16 bit word */
316 memcpy(buf + 2, val, len);
318 return iface->local->func->set_rid(dev, rid, &buf, MAX_SSID_LEN + 2);
322 u16 hostap_get_porttype(local_info_t *local)
324 if (local->iw_mode == IW_MODE_ADHOC && local->pseudo_adhoc)
325 return HFA384X_PORTTYPE_PSEUDO_IBSS;
326 if (local->iw_mode == IW_MODE_ADHOC)
327 return HFA384X_PORTTYPE_IBSS;
328 if (local->iw_mode == IW_MODE_INFRA)
329 return HFA384X_PORTTYPE_BSS;
330 if (local->iw_mode == IW_MODE_REPEAT)
331 return HFA384X_PORTTYPE_WDS;
332 if (local->iw_mode == IW_MODE_MONITOR)
333 return HFA384X_PORTTYPE_PSEUDO_IBSS;
334 return HFA384X_PORTTYPE_HOSTAP;
338 int hostap_set_encryption(local_info_t *local)
341 int i, keylen, len, idx;
342 char keybuf[WEP_KEY_LEN + 1];
343 enum { NONE, WEP, OTHER } encrypt_type;
345 idx = local->crypt_info.tx_keyidx;
346 if (local->crypt_info.crypt[idx] == NULL ||
347 local->crypt_info.crypt[idx]->ops == NULL)
349 else if (strcmp(local->crypt_info.crypt[idx]->ops->name, "WEP") == 0)
352 encrypt_type = OTHER;
354 if (local->func->get_rid(local->dev, HFA384X_RID_CNFWEPFLAGS, &val, 2,
356 printk(KERN_DEBUG "Could not read current WEP flags.\n");
362 if (encrypt_type != NONE || local->privacy_invoked)
363 val |= HFA384X_WEPFLAGS_PRIVACYINVOKED;
365 val &= ~HFA384X_WEPFLAGS_PRIVACYINVOKED;
367 if (local->open_wep || encrypt_type == NONE ||
368 ((local->ieee_802_1x || local->wpa) && local->host_decrypt))
369 val &= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
371 val |= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
373 if ((encrypt_type != NONE || local->privacy_invoked) &&
374 (encrypt_type == OTHER || local->host_encrypt))
375 val |= HFA384X_WEPFLAGS_HOSTENCRYPT;
377 val &= ~HFA384X_WEPFLAGS_HOSTENCRYPT;
378 if ((encrypt_type != NONE || local->privacy_invoked) &&
379 (encrypt_type == OTHER || local->host_decrypt))
380 val |= HFA384X_WEPFLAGS_HOSTDECRYPT;
382 val &= ~HFA384X_WEPFLAGS_HOSTDECRYPT;
384 if (val != old_val &&
385 hostap_set_word(local->dev, HFA384X_RID_CNFWEPFLAGS, val)) {
386 printk(KERN_DEBUG "Could not write new WEP flags (0x%x)\n",
391 if (encrypt_type != WEP)
394 /* 104-bit support seems to require that all the keys are set to the
396 keylen = 6; /* first 5 octets */
397 len = local->crypt_info.crypt[idx]->ops->get_key(keybuf, sizeof(keybuf), NULL,
398 local->crypt_info.crypt[idx]->priv);
399 if (idx >= 0 && idx < WEP_KEYS && len > 5)
400 keylen = WEP_KEY_LEN + 1; /* first 13 octets */
402 for (i = 0; i < WEP_KEYS; i++) {
403 memset(keybuf, 0, sizeof(keybuf));
404 if (local->crypt_info.crypt[i]) {
405 (void) local->crypt_info.crypt[i]->ops->get_key(
406 keybuf, sizeof(keybuf),
407 NULL, local->crypt_info.crypt[i]->priv);
409 if (local->func->set_rid(local->dev,
410 HFA384X_RID_CNFDEFAULTKEY0 + i,
412 printk(KERN_DEBUG "Could not set key %d (len=%d)\n",
417 if (hostap_set_word(local->dev, HFA384X_RID_CNFWEPDEFAULTKEYID, idx)) {
418 printk(KERN_DEBUG "Could not set default keyid %d\n", idx);
425 printk(KERN_DEBUG "%s: encryption setup failed\n", local->dev->name);
430 int hostap_set_antsel(local_info_t *local)
435 if (local->antsel_tx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
436 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
437 HFA386X_CR_TX_CONFIGURE,
439 val &= ~(BIT(2) | BIT(1));
440 switch (local->antsel_tx) {
441 case HOSTAP_ANTSEL_DIVERSITY:
444 case HOSTAP_ANTSEL_LOW:
446 case HOSTAP_ANTSEL_HIGH:
451 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
452 HFA386X_CR_TX_CONFIGURE, &val, NULL)) {
453 printk(KERN_INFO "%s: setting TX AntSel failed\n",
459 if (local->antsel_rx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
460 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
461 HFA386X_CR_RX_CONFIGURE,
463 val &= ~(BIT(1) | BIT(0));
464 switch (local->antsel_rx) {
465 case HOSTAP_ANTSEL_DIVERSITY:
467 case HOSTAP_ANTSEL_LOW:
470 case HOSTAP_ANTSEL_HIGH:
471 val |= BIT(0) | BIT(1);
475 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
476 HFA386X_CR_RX_CONFIGURE, &val, NULL)) {
477 printk(KERN_INFO "%s: setting RX AntSel failed\n",
487 int hostap_set_roaming(local_info_t *local)
491 switch (local->host_roaming) {
493 val = HFA384X_ROAMING_HOST;
496 val = HFA384X_ROAMING_DISABLED;
500 val = HFA384X_ROAMING_FIRMWARE;
504 return hostap_set_word(local->dev, HFA384X_RID_CNFROAMINGMODE, val);
508 int hostap_set_auth_algs(local_info_t *local)
510 int val = local->auth_algs;
511 /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication
512 * set to include both Open and Shared Key flags. It tries to use
513 * Shared Key authentication in that case even if WEP keys are not
514 * configured.. STA f/w v0.7.6 is able to handle such configuration,
515 * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */
516 if (local->sta_fw_ver < PRISM2_FW_VER(0,7,0) &&
517 val != PRISM2_AUTH_OPEN && val != PRISM2_AUTH_SHARED_KEY)
518 val = PRISM2_AUTH_OPEN;
520 if (hostap_set_word(local->dev, HFA384X_RID_CNFAUTHENTICATION, val)) {
521 printk(KERN_INFO "%s: cnfAuthentication setting to 0x%x "
522 "failed\n", local->dev->name, local->auth_algs);
530 void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx)
534 status = __le16_to_cpu(rx->status);
536 printk(KERN_DEBUG "%s: RX status=0x%04x (port=%d, type=%d, "
537 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
539 name, status, (status >> 8) & 0x07, status >> 13, status & 1,
540 rx->silence, rx->signal, rx->rate, rx->rxflow, jiffies);
542 fc = __le16_to_cpu(rx->frame_control);
543 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
545 fc, (fc & IEEE80211_FCTL_FTYPE) >> 2,
546 (fc & IEEE80211_FCTL_STYPE) >> 4,
547 __le16_to_cpu(rx->duration_id), __le16_to_cpu(rx->seq_ctrl),
548 __le16_to_cpu(rx->data_len),
549 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
550 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
552 printk(KERN_DEBUG " A1=%pM A2=%pM A3=%pM A4=%pM\n",
553 rx->addr1, rx->addr2, rx->addr3, rx->addr4);
555 printk(KERN_DEBUG " dst=%pM src=%pM len=%d\n",
556 rx->dst_addr, rx->src_addr,
557 __be16_to_cpu(rx->len));
561 void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
565 printk(KERN_DEBUG "%s: TX status=0x%04x retry_count=%d tx_rate=%d "
566 "tx_control=0x%04x; jiffies=%ld\n",
567 name, __le16_to_cpu(tx->status), tx->retry_count, tx->tx_rate,
568 __le16_to_cpu(tx->tx_control), jiffies);
570 fc = __le16_to_cpu(tx->frame_control);
571 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
573 fc, (fc & IEEE80211_FCTL_FTYPE) >> 2,
574 (fc & IEEE80211_FCTL_STYPE) >> 4,
575 __le16_to_cpu(tx->duration_id), __le16_to_cpu(tx->seq_ctrl),
576 __le16_to_cpu(tx->data_len),
577 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
578 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
580 printk(KERN_DEBUG " A1=%pM A2=%pM A3=%pM A4=%pM\n",
581 tx->addr1, tx->addr2, tx->addr3, tx->addr4);
583 printk(KERN_DEBUG " dst=%pM src=%pM len=%d\n",
584 tx->dst_addr, tx->src_addr,
585 __be16_to_cpu(tx->len));
589 static int hostap_80211_header_parse(const struct sk_buff *skb,
590 unsigned char *haddr)
592 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
597 int hostap_80211_get_hdrlen(__le16 fc)
599 if (ieee80211_is_data(fc) && ieee80211_has_a4 (fc))
600 return 30; /* Addr4 */
601 else if (ieee80211_is_cts(fc) || ieee80211_is_ack(fc))
603 else if (ieee80211_is_ctl(fc))
610 struct net_device_stats *hostap_get_stats(struct net_device *dev)
612 struct hostap_interface *iface;
613 iface = netdev_priv(dev);
614 return &iface->stats;
618 static int prism2_close(struct net_device *dev)
620 struct hostap_interface *iface;
623 PDEBUG(DEBUG_FLOW, "%s: prism2_close\n", dev->name);
625 iface = netdev_priv(dev);
626 local = iface->local;
628 if (dev == local->ddev) {
629 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
631 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
632 if (!local->hostapd && dev == local->dev &&
633 (!local->func->card_present || local->func->card_present(local)) &&
634 local->hw_ready && local->ap && local->iw_mode == IW_MODE_MASTER)
635 hostap_deauth_all_stas(dev, local->ap, 1);
636 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
638 if (dev == local->dev) {
639 local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL);
642 if (netif_running(dev)) {
643 netif_stop_queue(dev);
644 netif_device_detach(dev);
647 cancel_work_sync(&local->reset_queue);
648 cancel_work_sync(&local->set_multicast_list_queue);
649 cancel_work_sync(&local->set_tim_queue);
650 #ifndef PRISM2_NO_STATION_MODES
651 cancel_work_sync(&local->info_queue);
653 cancel_work_sync(&local->comms_qual_update);
655 module_put(local->hw_module);
657 local->num_dev_open--;
659 if (dev != local->dev && local->dev->flags & IFF_UP &&
660 local->master_dev_auto_open && local->num_dev_open == 1) {
661 /* Close master radio interface automatically if it was also
662 * opened automatically and we are now closing the last
663 * remaining non-master device. */
664 dev_close(local->dev);
671 static int prism2_open(struct net_device *dev)
673 struct hostap_interface *iface;
676 PDEBUG(DEBUG_FLOW, "%s: prism2_open\n", dev->name);
678 iface = netdev_priv(dev);
679 local = iface->local;
682 printk(KERN_DEBUG "%s: could not set interface UP - no PRI "
687 if ((local->func->card_present && !local->func->card_present(local)) ||
688 local->hw_downloading)
691 if (!try_module_get(local->hw_module))
693 local->num_dev_open++;
695 if (!local->dev_enabled && local->func->hw_enable(dev, 1)) {
696 printk(KERN_WARNING "%s: could not enable MAC port\n",
701 if (!local->dev_enabled)
702 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
703 local->dev_enabled = 1;
705 if (dev != local->dev && !(local->dev->flags & IFF_UP)) {
706 /* Master radio interface is needed for all operation, so open
707 * it automatically when any virtual net_device is opened. */
708 local->master_dev_auto_open = 1;
709 dev_open(local->dev);
712 netif_device_attach(dev);
713 netif_start_queue(dev);
719 static int prism2_set_mac_address(struct net_device *dev, void *p)
721 struct hostap_interface *iface;
723 struct list_head *ptr;
724 struct sockaddr *addr = p;
726 iface = netdev_priv(dev);
727 local = iface->local;
729 if (local->func->set_rid(dev, HFA384X_RID_CNFOWNMACADDR, addr->sa_data,
730 ETH_ALEN) < 0 || local->func->reset_port(dev))
733 read_lock_bh(&local->iface_lock);
734 list_for_each(ptr, &local->hostap_interfaces) {
735 iface = list_entry(ptr, struct hostap_interface, list);
736 memcpy(iface->dev->dev_addr, addr->sa_data, ETH_ALEN);
738 memcpy(local->dev->dev_addr, addr->sa_data, ETH_ALEN);
739 read_unlock_bh(&local->iface_lock);
745 /* TODO: to be further implemented as soon as Prism2 fully supports
746 * GroupAddresses and correct documentation is available */
747 void hostap_set_multicast_list_queue(struct work_struct *work)
749 local_info_t *local =
750 container_of(work, local_info_t, set_multicast_list_queue);
751 struct net_device *dev = local->dev;
752 struct hostap_interface *iface;
754 iface = netdev_priv(dev);
755 if (hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
756 local->is_promisc)) {
757 printk(KERN_INFO "%s: %sabling promiscuous mode failed\n",
758 dev->name, local->is_promisc ? "en" : "dis");
763 static void hostap_set_multicast_list(struct net_device *dev)
766 /* FIX: promiscuous mode seems to be causing a lot of problems with
767 * some station firmware versions (FCSErr frames, invalid MACPort, etc.
768 * corrupted incoming frames). This code is now commented out while the
769 * problems are investigated. */
770 struct hostap_interface *iface;
773 iface = netdev_priv(dev);
774 local = iface->local;
775 if ((dev->flags & IFF_ALLMULTI) || (dev->flags & IFF_PROMISC)) {
776 local->is_promisc = 1;
778 local->is_promisc = 0;
781 schedule_work(&local->set_multicast_list_queue);
786 static int prism2_change_mtu(struct net_device *dev, int new_mtu)
788 if (new_mtu < PRISM2_MIN_MTU || new_mtu > PRISM2_MAX_MTU)
796 static void prism2_tx_timeout(struct net_device *dev)
798 struct hostap_interface *iface;
800 struct hfa384x_regs regs;
802 iface = netdev_priv(dev);
803 local = iface->local;
805 printk(KERN_WARNING "%s Tx timed out! Resetting card\n", dev->name);
806 netif_stop_queue(local->dev);
808 local->func->read_regs(dev, ®s);
809 printk(KERN_DEBUG "%s: CMD=%04x EVSTAT=%04x "
810 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
811 dev->name, regs.cmd, regs.evstat, regs.offset0, regs.offset1,
814 local->func->schedule_reset(local);
817 const struct header_ops hostap_80211_ops = {
818 .create = eth_header,
819 .rebuild = eth_rebuild_header,
820 .cache = eth_header_cache,
821 .cache_update = eth_header_cache_update,
822 .parse = hostap_80211_header_parse,
824 EXPORT_SYMBOL(hostap_80211_ops);
826 void hostap_setup_dev(struct net_device *dev, local_info_t *local,
829 struct hostap_interface *iface;
831 iface = netdev_priv(dev);
834 /* kernel callbacks */
835 dev->get_stats = hostap_get_stats;
837 /* Currently, we point to the proper spy_data only on
838 * the main_dev. This could be fixed. Jean II */
839 iface->wireless_data.spy_data = &iface->spy_data;
840 dev->wireless_data = &iface->wireless_data;
842 dev->wireless_handlers =
843 (struct iw_handler_def *) &hostap_iw_handler_def;
844 dev->do_ioctl = hostap_ioctl;
845 dev->open = prism2_open;
846 dev->stop = prism2_close;
847 dev->set_mac_address = prism2_set_mac_address;
848 dev->set_multicast_list = hostap_set_multicast_list;
849 dev->change_mtu = prism2_change_mtu;
850 dev->tx_timeout = prism2_tx_timeout;
851 dev->watchdog_timeo = TX_TIMEOUT;
853 if (type == HOSTAP_INTERFACE_AP) {
854 dev->hard_start_xmit = hostap_mgmt_start_xmit;
855 dev->type = ARPHRD_IEEE80211;
856 dev->header_ops = &hostap_80211_ops;
858 dev->hard_start_xmit = hostap_data_start_xmit;
861 dev->mtu = local->mtu;
862 if (type != HOSTAP_INTERFACE_MASTER) {
863 /* use main radio device queue */
864 dev->tx_queue_len = 0;
867 SET_ETHTOOL_OPS(dev, &prism2_ethtool_ops);
869 netif_stop_queue(dev);
872 static int hostap_enable_hostapd(local_info_t *local, int rtnl_locked)
874 struct net_device *dev = local->dev;
879 printk(KERN_DEBUG "%s: enabling hostapd mode\n", dev->name);
881 local->apdev = hostap_add_interface(local, HOSTAP_INTERFACE_AP,
882 rtnl_locked, local->ddev->name,
884 if (local->apdev == NULL)
891 static int hostap_disable_hostapd(local_info_t *local, int rtnl_locked)
893 struct net_device *dev = local->dev;
895 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
897 hostap_remove_interface(local->apdev, rtnl_locked, 1);
904 static int hostap_enable_hostapd_sta(local_info_t *local, int rtnl_locked)
906 struct net_device *dev = local->dev;
911 printk(KERN_DEBUG "%s: enabling hostapd STA mode\n", dev->name);
913 local->stadev = hostap_add_interface(local, HOSTAP_INTERFACE_STA,
914 rtnl_locked, local->ddev->name,
916 if (local->stadev == NULL)
923 static int hostap_disable_hostapd_sta(local_info_t *local, int rtnl_locked)
925 struct net_device *dev = local->dev;
927 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
929 hostap_remove_interface(local->stadev, rtnl_locked, 1);
930 local->stadev = NULL;
936 int hostap_set_hostapd(local_info_t *local, int val, int rtnl_locked)
940 if (val < 0 || val > 1)
943 if (local->hostapd == val)
947 ret = hostap_enable_hostapd(local, rtnl_locked);
952 ret = hostap_disable_hostapd(local, rtnl_locked);
961 int hostap_set_hostapd_sta(local_info_t *local, int val, int rtnl_locked)
965 if (val < 0 || val > 1)
968 if (local->hostapd_sta == val)
972 ret = hostap_enable_hostapd_sta(local, rtnl_locked);
974 local->hostapd_sta = 1;
976 local->hostapd_sta = 0;
977 ret = hostap_disable_hostapd_sta(local, rtnl_locked);
979 local->hostapd_sta = 1;
987 int prism2_update_comms_qual(struct net_device *dev)
989 struct hostap_interface *iface;
992 struct hfa384x_comms_quality sq;
994 iface = netdev_priv(dev);
995 local = iface->local;
996 if (!local->sta_fw_ver)
998 else if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
999 if (local->func->get_rid(local->dev,
1000 HFA384X_RID_DBMCOMMSQUALITY,
1001 &sq, sizeof(sq), 1) >= 0) {
1002 local->comms_qual = (s16) le16_to_cpu(sq.comm_qual);
1003 local->avg_signal = (s16) le16_to_cpu(sq.signal_level);
1004 local->avg_noise = (s16) le16_to_cpu(sq.noise_level);
1005 local->last_comms_qual_update = jiffies;
1009 if (local->func->get_rid(local->dev, HFA384X_RID_COMMSQUALITY,
1010 &sq, sizeof(sq), 1) >= 0) {
1011 local->comms_qual = le16_to_cpu(sq.comm_qual);
1012 local->avg_signal = HFA384X_LEVEL_TO_dBm(
1013 le16_to_cpu(sq.signal_level));
1014 local->avg_noise = HFA384X_LEVEL_TO_dBm(
1015 le16_to_cpu(sq.noise_level));
1016 local->last_comms_qual_update = jiffies;
1025 int prism2_sta_send_mgmt(local_info_t *local, u8 *dst, u16 stype,
1026 u8 *body, size_t bodylen)
1028 struct sk_buff *skb;
1029 struct hostap_ieee80211_mgmt *mgmt;
1030 struct hostap_skb_tx_data *meta;
1031 struct net_device *dev = local->dev;
1033 skb = dev_alloc_skb(IEEE80211_MGMT_HDR_LEN + bodylen);
1037 mgmt = (struct hostap_ieee80211_mgmt *)
1038 skb_put(skb, IEEE80211_MGMT_HDR_LEN);
1039 memset(mgmt, 0, IEEE80211_MGMT_HDR_LEN);
1040 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
1041 memcpy(mgmt->da, dst, ETH_ALEN);
1042 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1043 memcpy(mgmt->bssid, dst, ETH_ALEN);
1045 memcpy(skb_put(skb, bodylen), body, bodylen);
1047 meta = (struct hostap_skb_tx_data *) skb->cb;
1048 memset(meta, 0, sizeof(*meta));
1049 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
1050 meta->iface = netdev_priv(dev);
1053 skb_reset_mac_header(skb);
1054 skb_reset_network_header(skb);
1055 dev_queue_xmit(skb);
1061 int prism2_sta_deauth(local_info_t *local, u16 reason)
1063 union iwreq_data wrqu;
1065 __le16 val = cpu_to_le16(reason);
1067 if (local->iw_mode != IW_MODE_INFRA ||
1068 memcmp(local->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0 ||
1069 memcmp(local->bssid, "\x44\x44\x44\x44\x44\x44", ETH_ALEN) == 0)
1072 ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH,
1074 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1075 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
1080 struct proc_dir_entry *hostap_proc;
1082 static int __init hostap_init(void)
1084 if (init_net.proc_net != NULL) {
1085 hostap_proc = proc_mkdir("hostap", init_net.proc_net);
1087 printk(KERN_WARNING "Failed to mkdir "
1088 "/proc/net/hostap\n");
1096 static void __exit hostap_exit(void)
1098 if (hostap_proc != NULL) {
1100 remove_proc_entry("hostap", init_net.proc_net);
1105 EXPORT_SYMBOL(hostap_set_word);
1106 EXPORT_SYMBOL(hostap_set_string);
1107 EXPORT_SYMBOL(hostap_get_porttype);
1108 EXPORT_SYMBOL(hostap_set_encryption);
1109 EXPORT_SYMBOL(hostap_set_antsel);
1110 EXPORT_SYMBOL(hostap_set_roaming);
1111 EXPORT_SYMBOL(hostap_set_auth_algs);
1112 EXPORT_SYMBOL(hostap_dump_rx_header);
1113 EXPORT_SYMBOL(hostap_dump_tx_header);
1114 EXPORT_SYMBOL(hostap_80211_get_hdrlen);
1115 EXPORT_SYMBOL(hostap_get_stats);
1116 EXPORT_SYMBOL(hostap_setup_dev);
1117 EXPORT_SYMBOL(hostap_set_multicast_list_queue);
1118 EXPORT_SYMBOL(hostap_set_hostapd);
1119 EXPORT_SYMBOL(hostap_set_hostapd_sta);
1120 EXPORT_SYMBOL(hostap_add_interface);
1121 EXPORT_SYMBOL(hostap_remove_interface);
1122 EXPORT_SYMBOL(prism2_update_comms_qual);
1124 module_init(hostap_init);
1125 module_exit(hostap_exit);